Beispiel
toad-cache 3.7.4: FifoObject
Verifiziertes Beispiel für npm toad-cache 3.7.4: FifoObject. Der Vertrag lief auf node 22 · linux debian/x64 · docker und bestand.
sha256:fd0380f6744a74e38ac31adea5cd735944b0fea2de5d39ed8540c655c4d2e580
Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen.
Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen.
MIT-0
Ausführungsbelege
Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.
- Beleggrundlage
- Signierter Vertrag bestanden
- Verifizierungsbelege
- 1
- Signaturschlüssel, die es gebaut haben
- 1
Deklarierte Umgebung
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
Umgebungen der Verifizierungsläufe
| Umgebung | Contract | Stufen | Lauf |
|---|---|---|---|
| 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-11-22 |
Fall
HOW- Ziel
- verify toad-cache.FifoObject in pkg:npm/toad-cache@3.7.4
- Pakete
- Symbole
-
- toad-cache.FifoObject
- Umgebung
- node 22.23.2
- Erstellt
- 2026-11-22T16:27:16Z
Contract
- new FifoObject() defaults to max=1000, ttl=0, size=0, first=null, last=null
- constructor rejects negative or non-integer max/ttlInMsecs with Error('Invalid max value') / Error('Invalid ttl value') and allows max=0 for unbounded storage
- set/get/getMany/keys store and retrieve values using a null-prototype object (handling keys like 'toString') and return undefined for missing keys
- capacity eviction follows strict FIFO order: reaching max evicts the oldest inserted entry (first), and neither get() nor overwriting an existing key via set() changes its queue position
- evict(), delete(), deleteMany(), and clear() maintain size/first/last pointers and treat missing keys or evicting an empty cache as no-ops
- with ttlInMsecs > 0, expiresAt() returns the epoch expiry timestamp (0 when ttl=0, undefined when absent), overwriting refreshes expiry, and get() lazily removes expired entries
Dateien
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.cjs
- test/contract.cjs
Quelltext
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 toad-cache.FifoObject in pkg:npm/toad-cache@3.7.4
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/toad-cache@3.7.4
Demonstrate these symbols/APIs:
- toad-cache.FifoObject
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- packageManager: npm@10.9.8
- runtime: node@22.23.2
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:6ccb8b08e73e60bbe2871b97f420d0a4b5e1ab56fd34fb1fac18963570dbde41","constraints":{"executionContext":"node"},"contract":["new FifoObject() defaults to max=1000, ttl=0, size=0, first=null, last=null","constructor rejects negative or non-integer max/ttlInMsecs with Error('Invalid max value') / Error('Invalid ttl value') and allows max=0 for unbounded storage","set/get/getMany/keys store and retrieve values using a null-prototype object (handling keys like 'toString') and return undefined for missing keys","capacity eviction follows strict FIFO order: reaching max evicts the oldest inserted entry (first), and neither get() nor overwriting an existing key via set() changes its queue position","evict(), delete(), deleteMany(), and clear() maintain size/first/last pointers and treat missing keys or evicting an empty cache as no-ops","with ttlInMsecs \u003e 0, expiresAt() returns the epoch expiry timestamp (0 when ttl=0, undefined when absent), overwriting refreshes expiry, and get() lazily removes expired entries"],"goal":"verify toad-cache.FifoObject in pkg:npm/toad-cache@3.7.4","kind":"HOW","packages":["pkg:npm/toad-cache@3.7.4"],"schemaVersion":1,"symbols":["toad-cache.FifoObject"]},"contractCommand":["node","test/contract.cjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/toad-cache@3.7.4"],"schemaVersion":1,"subject":"pkg:npm/toad-cache@3.7.4","symbols":["toad-cache.FifoObject"],"verifierAdapter":"node-typescript@1"}
{
"name": "toad-cache-fifo-object-sample",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "toad-cache-fifo-object-sample",
"version": "1.0.0",
"dependencies": {
"toad-cache": "3.7.4"
}
},
"node_modules/toad-cache": {
"version": "3.7.4",
"resolved": "https://registry.npmjs.org/toad-cache/-/toad-cache-3.7.4.tgz",
"integrity": "sha512-m1TdR/rvT7kgGJZhspNtXdsdYk0fddFpJJFlG5s+UkPFo6lkLoZ3YLOaovPYjq1R75NP5JfeTlSHaOsE09peCg==",
"license": "MIT",
"engines": {
"node": ">=20"
}
}
}
}
{
"name": "toad-cache-fifo-object-sample",
"version": "1.0.0",
"private": true,
"description": "Minimal CJS verification sample for FifoObject in toad-cache@3.7.4",
"main": "src/index.cjs",
"scripts": {
"test": "node test/contract.cjs"
},
"dependencies": {
"toad-cache": "3.7.4"
}
}
{
"schemaVersion": 1,
"goal": "verify toad-cache.FifoObject in pkg:npm/toad-cache@3.7.4",
"kind": "HOW",
"packages": [
"pkg:npm/toad-cache@3.7.4"
],
"symbols": [
"toad-cache.FifoObject"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
'use strict';
const { FifoObject } = require('toad-cache');
function createFifoCache(max, ttlInMsecs) {
return new FifoObject(max, ttlInMsecs);
}
module.exports = {
FifoObject,
createFifoCache,
};
'use strict';
const assert = require('node:assert/strict');
const { FifoObject, createFifoCache } = require('../src/index.cjs');
function waitUntilAfter(epochMs) {
return new Promise((resolve) => {
function check() {
const remaining = epochMs - Date.now() + 2;
if (remaining <= 0) {
resolve();
return;
}
setTimeout(check, remaining);
}
check();
});
}
async function main() {
// 1. Default constructor state
const defaults = new FifoObject();
assert.equal(defaults.max, 1000);
assert.equal(defaults.ttl, 0);
assert.equal(defaults.size, 0);
assert.equal(defaults.first, null);
assert.equal(defaults.last, null);
assert.deepEqual(defaults.keys(), []);
// 2. Constructor parameter validation & unlimited capacity (max = 0)
assert.throws(() => new FifoObject(-1), { message: 'Invalid max value' });
assert.throws(() => new FifoObject(1.5), { message: 'Invalid max value' });
assert.throws(() => new FifoObject('10'), { message: 'Invalid max value' });
assert.throws(() => new FifoObject(10, -1), { message: 'Invalid ttl value' });
assert.throws(() => new FifoObject(10, 0.5), { message: 'Invalid ttl value' });
assert.throws(() => new FifoObject(10, '100'), { message: 'Invalid ttl value' });
const unlimited = createFifoCache(0, 0);
unlimited.set('k1', 1);
unlimited.set('k2', 2);
unlimited.set('toString', 'safe-key');
assert.equal(unlimited.size, 3);
assert.equal(unlimited.get('toString'), 'safe-key');
assert.equal(unlimited.expiresAt('k1'), 0);
assert.equal(unlimited.expiresAt('missing'), undefined);
assert.equal(unlimited.get('missing'), undefined);
// 3. Strict FIFO eviction: get() and overwriting set() do not change queue order
const fifo = createFifoCache(2, 0);
fifo.set('a', 1);
fifo.set('b', 2);
assert.equal(fifo.size, 2);
assert.equal(fifo.first.key, 'a');
assert.equal(fifo.last.key, 'b');
// Reading 'a' must NOT promote it (FIFO, not LRU)
assert.equal(fifo.get('a'), 1);
// Overwriting 'a' updates value in place without changing FIFO order
fifo.set('a', 10);
assert.equal(fifo.get('a'), 10);
assert.equal(fifo.size, 2);
assert.equal(fifo.first.key, 'a');
assert.equal(fifo.last.key, 'b');
// Adding 'c' evicts oldest inserted key ('a')
fifo.set('c', 3);
assert.equal(fifo.size, 2);
assert.equal(fifo.get('a'), undefined);
assert.deepEqual(fifo.getMany(['a', 'b', 'c']), [undefined, 2, 3]);
assert.deepEqual(fifo.keys(), ['b', 'c']);
assert.equal(fifo.first.key, 'b');
assert.equal(fifo.last.key, 'c');
// 4. evict(), delete(), deleteMany(), clear(), and empty/missing no-ops
fifo.evict();
assert.equal(fifo.size, 1);
assert.equal(fifo.get('b'), undefined);
assert.equal(fifo.first.key, 'c');
assert.equal(fifo.last.key, 'c');
fifo.delete('nonexistent');
assert.equal(fifo.size, 1);
fifo.set('d', 4);
fifo.set('e', 5); // evicts 'c', leaves 'd' and 'e'
assert.deepEqual(fifo.keys(), ['d', 'e']);
fifo.deleteMany(['d', 'missing']);
assert.equal(fifo.size, 1);
assert.equal(fifo.first.key, 'e');
assert.equal(fifo.last.key, 'e');
fifo.clear();
assert.equal(fifo.size, 0);
assert.equal(fifo.first, null);
assert.equal(fifo.last, null);
assert.deepEqual(fifo.keys(), []);
// evict on empty cache is a no-op
fifo.evict();
assert.equal(fifo.size, 0);
// 5. TTL tracking via expiresAt() and lazy expiration on get()
const ttlCache = createFifoCache(5, 25);
const beforeSet = Date.now();
ttlCache.set('ephemeral', 'v1');
const firstExpiry = ttlCache.expiresAt('ephemeral');
assert.equal(typeof firstExpiry, 'number');
assert.ok(firstExpiry >= beforeSet + 25);
assert.equal(ttlCache.get('ephemeral'), 'v1');
// Overwriting refreshes expiry
await waitUntilAfter(beforeSet + 10);
ttlCache.set('ephemeral', 'v2');
const refreshedExpiry = ttlCache.expiresAt('ephemeral');
assert.ok(refreshedExpiry >= firstExpiry);
assert.equal(ttlCache.get('ephemeral'), 'v2');
// Once past expiry, get() lazily deletes the entry and returns undefined
await waitUntilAfter(refreshedExpiry);
assert.equal(ttlCache.get('ephemeral'), undefined);
assert.equal(ttlCache.size, 0);
assert.equal(ttlCache.expiresAt('ephemeral'), undefined);
console.log('toad-cache.FifoObject contract passed');
}
main().catch((err) => {
console.error(err);
process.exitCode = 1;
});
Ursprungs-Seeder
anonym