示例
quick-lru 5.1.1: QuickLRU
已验证示例 — npm quick-lru 5.1.1: QuickLRU. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: new QuickLRU({ maxSize: number }) creates a new QuickLRU cache…
sha256:d933984dd5e340e8e728bc3ddfa3bdae72c5e0d67def59ba84b66715cfc69869
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 2
- 构建过它的签名密钥
- 1
声明的环境
linux 24 · ubuntu · glibc 2.39 x64 npm
验证运行环境
| 环境 | 契约 | 阶段 | 运行日期 |
|---|---|---|---|
| node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5… |
2026-08-26 |
| node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2… |
2026-09-07 |
案例
HOW- 目标
- verify pkg:npm/quick-lru@5.1.1
- 符号
-
- QuickLRU
- 创建时间
- 2026-08-26T08:05:43Z
契约
- new QuickLRU({ maxSize: number }) creates a new QuickLRU cache instance
- new QuickLRU() throws TypeError when maxSize option is omitted or not greater than 0
- set(key, value) inserts a key-value entry and returns the instance
- get(key) returns stored value and updates recency
- peek(key) returns stored value without updating recency
- has(key) returns true for existing key and false for missing key
- delete(key) removes key and returns true if existed
- clear() removes all entries and resets size to 0
- size returns the current number of cached items
- evicts least recently used items when cache exceeds maxSize
- onEviction callback is called when items are evicted
文件
- PROMPT.md
- csx.json
- index.mjs
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
源代码
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify pkg:npm/quick-lru@5.1.1
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/quick-lru@5.1.1
Demonstrate these symbols/APIs:
- QuickLRU
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:5e3408cd8f7fbce815a5e13dcde60c36a9b0074cc06c3995ac36f34bfbcbebfb","contract":["new QuickLRU({ maxSize: number }) creates a new QuickLRU cache instance","new QuickLRU() throws TypeError when maxSize option is omitted or not greater than 0","set(key, value) inserts a key-value entry and returns the instance","get(key) returns stored value and updates recency","peek(key) returns stored value without updating recency","has(key) returns true for existing key and false for missing key","delete(key) removes key and returns true if existed","clear() removes all entries and resets size to 0","size returns the current number of cached items","evicts least recently used items when cache exceeds maxSize","onEviction callback is called when items are evicted"],"goal":"verify pkg:npm/quick-lru@5.1.1","kind":"HOW","packages":["pkg:npm/quick-lru@5.1.1"],"schemaVersion":1,"symbols":["QuickLRU"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/quick-lru@5.1.1"],"schemaVersion":1,"subject":"pkg:npm/quick-lru@5.1.1","symbols":["QuickLRU"],"verifierAdapter":"node-typescript@1"}
import QuickLRU from 'quick-lru';
export function createLRUCache(maxSize = 100, onEviction) {
return new QuickLRU({ maxSize, onEviction });
}
export function demoQuickLRU() {
const lru = new QuickLRU({ maxSize: 2 });
lru.set('first', '1');
lru.set('second', '2');
lru.set('third', '3'); // evicts 'first'
return {
hasFirst: lru.has('first'),
second: lru.get('second'),
third: lru.get('third'),
size: lru.size
};
}
{
"name": "quick-lru-sample",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "quick-lru-sample",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"quick-lru": "5.1.1"
}
},
"node_modules/quick-lru": {
"version": "5.1.1",
"resolved": "https://registry.npmjs.org/quick-lru/-/quick-lru-5.1.1.tgz",
"integrity": "sha512-WuyALRjWPDGtt/wzJiadO5AXY+8hZ80hVpe6MyivgraREW751X3SbhRvG3eLKOYN+8VEvqLcf3wdnt44Z4S4SA==",
"license": "MIT",
"engines": {
"node": ">=10"
},
"funding": {
"url": "https://github.com/sponsors/sindresorhus"
}
}
}
}
{
"name": "quick-lru-sample",
"version": "1.0.0",
"type": "module",
"private": true,
"license": "MIT-0",
"dependencies": {
"quick-lru": "5.1.1"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/quick-lru@5.1.1",
"kind": "HOW",
"packages": [
"pkg:npm/quick-lru@5.1.1"
],
"symbols": [
"QuickLRU"
]
}
import assert from 'node:assert';
import QuickLRU from 'quick-lru';
// 1. Constructor validation
assert.throws(() => new QuickLRU(), {
name: 'TypeError',
message: '`maxSize` must be a number greater than 0'
});
assert.throws(() => new QuickLRU({ maxSize: 0 }), {
name: 'TypeError'
});
assert.throws(() => new QuickLRU({ maxSize: -5 }), {
name: 'TypeError'
});
// 2. Instance creation and basic operations
const lru = new QuickLRU({ maxSize: 3 });
assert.strictEqual(lru.maxSize, 3);
assert.strictEqual(lru.size, 0);
// 3. set and chainability
const setReturn = lru.set('a', 1);
assert.strictEqual(setReturn, lru);
lru.set('b', 2);
assert.strictEqual(lru.size, 2);
// 4. get and has
assert.strictEqual(lru.has('a'), true);
assert.strictEqual(lru.has('b'), true);
assert.strictEqual(lru.has('c'), false);
assert.strictEqual(lru.get('a'), 1);
assert.strictEqual(lru.get('b'), 2);
assert.strictEqual(lru.get('nonexistent'), undefined);
// 5. peek without updating recency
assert.strictEqual(lru.peek('a'), 1);
assert.strictEqual(lru.peek('missing'), undefined);
// 6. delete
assert.strictEqual(lru.delete('a'), true);
assert.strictEqual(lru.delete('a'), false);
assert.strictEqual(lru.has('a'), false);
assert.strictEqual(lru.get('a'), undefined);
assert.strictEqual(lru.size, 1);
// 7. clear
lru.clear();
assert.strictEqual(lru.size, 0);
assert.strictEqual(lru.has('b'), false);
// 8. Eviction and maxSize behavior
const evicted = [];
const cacheWithEviction = new QuickLRU({
maxSize: 2,
onEviction: (key, value) => {
evicted.push({ key, value });
}
});
cacheWithEviction.set('x', 10);
cacheWithEviction.set('y', 20);
assert.strictEqual(cacheWithEviction.size, 2);
// Adding 3rd item triggers internal rotation in QuickLRU
cacheWithEviction.set('z', 30);
assert.strictEqual(cacheWithEviction.has('z'), true);
// Adding 4th item triggers eviction of oldCache items
cacheWithEviction.set('w', 40);
assert.strictEqual(evicted.length > 0, true);
// 9. Iteration
const iterCache = new QuickLRU({ maxSize: 5 });
iterCache.set('k1', 'v1');
iterCache.set('k2', 'v2');
const keys = [...iterCache.keys()];
const values = [...iterCache.values()];
const entries = [...iterCache];
assert.deepStrictEqual(keys.sort(), ['k1', 'k2']);
assert.deepStrictEqual(values.sort(), ['v1', 'v2']);
assert.strictEqual(entries.length, 2);
console.log('All contract assertions passed successfully.');
原始种子者
匿名