示例
@keyv/bigmap 1.3.1: BigMap
已验证示例 — npm @keyv/bigmap 1.3.1: BigMap. contract 在 node 22 · linux debian/x64 · docker 上运行并通过: BigMap defaults to storeSize of 4 and implements Map…
sha256:c2c11feea08918e053280227ddec41ba82738f81de064f2c14a92885e069c8fc
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 1
- 构建过它的签名密钥
- 1
声明的环境
linux 24 · ubuntu · glibc 2.39 x64 npm
验证运行环境
| 环境 | 契约 | 阶段 | 运行日期 |
|---|---|---|---|
| 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-05 |
案例
HOW- 目标
- verify pkg:npm/%40keyv/bigmap@1.3.1
- 符号
-
- BigMap
- 创建时间
- 2026-09-05T16:29:54Z
契约
- BigMap defaults to storeSize of 4 and implements Map operations set, get, has, and delete
- BigMap tracks cumulative size across internal store maps and resets size to 0 on clear
- BigMap supports custom storeSize and custom storeHashFunction for key distribution
- BigMap throws an error when constructed with or updated to a storeSize less than 1
- BigMap throws an error when getStoreMap is called with an index out of bounds
- BigMap supports iteration via entries, keys, values, forEach, and Symbol.iterator
文件
- 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/%40keyv/bigmap@1.3.1
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/%40keyv/bigmap@1.3.1
Demonstrate these symbols/APIs:
- BigMap
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:9d92c6266204139b254b86933407ba70b96f176cfc9fb65882b850e724a98cb9","contract":["BigMap defaults to storeSize of 4 and implements Map operations set, get, has, and delete","BigMap tracks cumulative size across internal store maps and resets size to 0 on clear","BigMap supports custom storeSize and custom storeHashFunction for key distribution","BigMap throws an error when constructed with or updated to a storeSize less than 1","BigMap throws an error when getStoreMap is called with an index out of bounds","BigMap supports iteration via entries, keys, values, forEach, and Symbol.iterator"],"goal":"verify pkg:npm/%40keyv/bigmap@1.3.1","kind":"HOW","packages":["pkg:npm/%40keyv/bigmap@1.3.1"],"schemaVersion":1,"symbols":["BigMap"]},"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/%40keyv/bigmap@1.3.1"],"schemaVersion":1,"subject":"pkg:npm/%40keyv/bigmap@1.3.1","symbols":["BigMap"],"verifierAdapter":"node-typescript@1"}
import { BigMap, defaultHashFunction } from '@keyv/bigmap';
/**
* Creates a BigMap instance with optional custom storeSize and custom hash function.
*
* @param {object} [options] - Configuration options for BigMap
* @param {number} [options.storeSize] - Number of internal Map instances
* @param {function} [options.storeHashFunction] - Custom key hash function
* @returns {BigMap}
*/
export function createBigMap(options) {
return new BigMap(options);
}
/**
* Returns default hash calculation for key and storeSize.
*
* @param {string} key
* @param {number} storeSize
* @returns {number}
*/
export function computeDefaultHash(key, storeSize) {
return defaultHashFunction(key, storeSize);
}
export { BigMap, defaultHashFunction };
{
"name": "sample-keyv-bigmap",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-keyv-bigmap",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"@keyv/bigmap": "1.3.1"
}
},
"node_modules/@keyv/bigmap": {
"version": "1.3.1",
"resolved": "https://registry.npmjs.org/@keyv/bigmap/-/bigmap-1.3.1.tgz",
"integrity": "sha512-WbzE9sdmQtKy8vrNPa9BRnwZh5UF4s1KTmSK0KUVLo3eff5BlQNNWDnFOouNpKfPKDnms9xynJjsMYjMaT/aFQ==",
"license": "MIT",
"dependencies": {
"hashery": "^1.4.0",
"hookified": "^1.15.0"
},
"engines": {
"node": ">= 18"
},
"peerDependencies": {
"keyv": "^5.6.0"
}
},
"node_modules/@keyv/serialize": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@keyv/serialize/-/serialize-1.1.1.tgz",
"integrity": "sha512-dXn3FZhPv0US+7dtJsIi2R+c7qWYiReoEh5zUntWCf4oSpMNib8FDhSoed6m3QyZdx5hK7iLFkYk3rNxwt8vTA==",
"license": "MIT",
"peer": true
},
"node_modules/hashery": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/hashery/-/hashery-1.5.1.tgz",
"integrity": "sha512-iZyKG96/JwPz1N55vj2Ie2vXbhu440zfUfJvSwEqEbeLluk7NnapfGqa7LH0mOsnDxTF85Mx8/dyR6HfqcbmbQ==",
"license": "MIT",
"dependencies": {
"hookified": "^1.15.0"
},
"engines": {
"node": ">=20"
}
},
"node_modules/hookified": {
"version": "1.15.1",
"resolved": "https://registry.npmjs.org/hookified/-/hookified-1.15.1.tgz",
"integrity": "sha512-MvG/clsADq1GPM2KGo2nyfaWVyn9naPiXrqIe4jYjXNZQt238kWyOGrsyc/DmRAQ+Re6yeo6yX/yoNCG5KAEVg==",
"license": "MIT"
},
"node_modules/keyv": {
"version": "5.6.0",
"resolved": "https://registry.npmjs.org/keyv/-/keyv-5.6.0.tgz",
"integrity": "sha512-CYDD3SOtsHtyXeEORYRx2qBtpDJFjRTGXUtmNEMGyzYOKj1TE3tycdlho7kA1Ufx9OYWZzg52QFBGALTirzDSw==",
"license": "MIT",
"peer": true,
"dependencies": {
"@keyv/serialize": "^1.1.1"
}
}
}
}
{
"name": "sample-keyv-bigmap",
"version": "1.0.0",
"type": "module",
"private": true,
"license": "MIT-0",
"scripts": {
"test": "node test/contract.mjs"
},
"dependencies": {
"@keyv/bigmap": "1.3.1"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/%40keyv/bigmap@1.3.1",
"kind": "HOW",
"packages": [
"pkg:npm/%40keyv/bigmap@1.3.1"
],
"symbols": [
"BigMap"
]
}
import assert from 'node:assert/strict';
import { BigMap, defaultHashFunction } from '@keyv/bigmap';
import { createBigMap, computeDefaultHash } from '../index.mjs';
// 1. BigMap defaults to storeSize of 4 and implements Map operations set, get, has, and delete
{
const map = new BigMap();
assert.equal(map.storeSize, 4, 'Default storeSize should be 4');
assert.equal(map.store.length, 4, 'Default internal store array length should be 4');
map.set('key1', 'value1');
assert.equal(map.has('key1'), true, 'map.has should return true for existing key');
assert.equal(map.get('key1'), 'value1', 'map.get should return stored value');
assert.equal(map.has('missing'), false, 'map.has should return false for nonexistent key');
assert.equal(map.get('missing'), undefined, 'map.get should return undefined for nonexistent key');
assert.equal(map.delete('key1'), true, 'map.delete should return true when deleting existing key');
assert.equal(map.has('key1'), false, 'key should no longer exist after delete');
assert.equal(map.delete('key1'), false, 'map.delete should return false when deleting nonexistent key');
}
// 2. BigMap tracks cumulative size across internal store maps and resets size to 0 on clear
{
const map = createBigMap();
assert.equal(map.size, 0, 'Initial size should be 0');
map.set('a', 1);
map.set('b', 2);
map.set('c', 3);
assert.equal(map.size, 3, 'Size should be 3 after inserting 3 keys');
map.set('a', 10);
assert.equal(map.size, 3, 'Size should remain 3 after overwriting existing key');
assert.equal(map.get('a'), 10, 'Updated value should be returned');
map.clear();
assert.equal(map.size, 0, 'Size should be 0 after clear()');
assert.equal(map.has('a'), false, 'Keys should be removed after clear()');
}
// 3. BigMap supports custom storeSize and custom storeHashFunction for key distribution
{
let hashCalled = false;
const customHash = (key, storeSize) => {
hashCalled = true;
return 1;
};
const map = new BigMap({
storeSize: 6,
storeHashFunction: customHash,
});
assert.equal(map.storeSize, 6, 'Custom storeSize should be 6');
assert.equal(map.store.length, 6, 'Store array length should match storeSize');
map.set('foo', 'bar');
assert.equal(hashCalled, true, 'Custom storeHashFunction should be called on key operations');
assert.equal(map.get('foo'), 'bar', 'Value should be retrievable with custom hash function');
assert.equal(map.getStoreMap(1).get('foo'), 'bar', 'Entry should be in store at index 1');
// Verify computeDefaultHash helper
const hashVal = computeDefaultHash('testKey', 4);
assert.equal(typeof hashVal, 'number');
assert.ok(hashVal >= 0 && hashVal < 4);
}
// 4. BigMap throws an error when constructed with or updated to a storeSize less than 1
{
assert.throws(
() => new BigMap({ storeSize: 0 }),
/Store size must be at least 1/,
'Constructor should reject storeSize < 1'
);
assert.throws(
() => new BigMap({ storeSize: -2 }),
/Store size must be at least 1/,
'Constructor should reject negative storeSize'
);
const map = new BigMap();
assert.throws(
() => { map.storeSize = 0; },
/Store size must be at least 1/,
'Setting storeSize < 1 should throw error'
);
}
// 5. BigMap throws an error when getStoreMap is called with an index out of bounds
{
const map = new BigMap({ storeSize: 3 });
assert.throws(
() => map.getStoreMap(-1),
/Index out of bounds/,
'getStoreMap should throw for negative index'
);
assert.throws(
() => map.getStoreMap(3),
/Index out of bounds/,
'getStoreMap should throw for index >= storeSize'
);
assert.ok(map.getStoreMap(0) instanceof Map);
assert.ok(map.getStoreMap(1) instanceof Map);
assert.ok(map.getStoreMap(2) instanceof Map);
}
// 6. BigMap supports iteration via entries, keys, values, forEach, and Symbol.iterator
{
const map = new BigMap();
map.set('k1', 'v1');
map.set('k2', 'v2');
const keys = Array.from(map.keys());
assert.equal(keys.length, 2);
assert.ok(keys.includes('k1'));
assert.ok(keys.includes('k2'));
const values = Array.from(map.values());
assert.equal(values.length, 2);
assert.ok(values.includes('v1'));
assert.ok(values.includes('v2'));
const entries = Array.from(map.entries());
assert.equal(entries.length, 2);
const iterated = [];
for (const [k, v] of map) {
iterated.push([k, v]);
}
assert.equal(iterated.length, 2);
const forEachEntries = [];
map.forEach((val, key) => {
forEachEntries.push([key, val]);
});
assert.equal(forEachEntries.length, 2);
}
console.log('Contract assertions passed successfully.');
原始种子者
匿名