CodeSampleX

샘플

quick-lru 5.1.1: QuickLRU

검증된 샘플 — npm quick-lru 5.1.1: QuickLRU. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: new QuickLRU({ maxSize: number }) creates a new QuickLRU…

sha256:d933984dd5e340e8e728bc3ddfa3bdae72c5e0d67def59ba84b66715cfc69869

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. 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

컨트랙트

  1. new QuickLRU({ maxSize: number }) creates a new QuickLRU cache instance
  2. new QuickLRU() throws TypeError when maxSize option is omitted or not greater than 0
  3. set(key, value) inserts a key-value entry and returns the instance
  4. get(key) returns stored value and updates recency
  5. peek(key) returns stored value without updating recency
  6. has(key) returns true for existing key and false for missing key
  7. delete(key) removes key and returns true if existed
  8. clear() removes all entries and resets size to 0
  9. size returns the current number of cached items
  10. evicts least recently used items when cache exceeds maxSize
  11. onEviction callback is called when items are evicted

파일

  • PROMPT.md
  • csx.json
  • index.mjs
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.mjs

소스 아티팩트 내려받기 (tar.gz)

소스

PROMPT.md
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.
csx.json
{"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"}
index.mjs
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
	};
}
package-lock.json
{
  "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"
      }
    }
  }
}
package.json
{
  "name": "quick-lru-sample",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "license": "MIT-0",
  "dependencies": {
    "quick-lru": "5.1.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/quick-lru@5.1.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/quick-lru@5.1.1"
  ],
  "symbols": [
    "QuickLRU"
  ]
}
test/contract.mjs
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.');

오리진 시더

익명