CodeSampleX

サンプル

keyv 4.5.4

検証済みサンプル — npm keyv 4.5.4. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: Keyv initializes in-memory key-value store and supports set, get, has…

sha256:70ace232043eb9d4d704fe191313515652f2fa57f97e3a5f572cf831485cb3fe

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

検証実行環境

環境 コントラクト ステージ 実行日
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-28

ケース

HOW
ゴール
verify pkg:npm/keyv@4.5.4
パッケージ
環境
node 22.23.2
作成日
2026-08-28T03:22:08Z

コントラクト

  1. Keyv initializes in-memory key-value store and supports set, get, has, delete, and clear methods
  2. Keyv handles structured data including JSON objects, nested arrays, booleans, and numbers
  3. Keyv expires keys accurately when time-to-live (TTL) in milliseconds is specified
  4. Keyv namespaces isolate key-value pairs across separate instances sharing the same store
  5. Keyv delete returns true for existing keys and false when deleting non-existent keys

ファイル

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

ソースアーティファクトをダウンロード (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/keyv@4.5.4
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/keyv@4.5.4
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.
csx.json
{"case":{"caseId":"case:sha256:93d02c91edac97b54b2b193516eaf45df72bac0f720f1584f2234b217c5c28f7","constraints":{"executionContext":"node"},"contract":["Keyv initializes in-memory key-value store and supports set, get, has, delete, and clear methods","Keyv handles structured data including JSON objects, nested arrays, booleans, and numbers","Keyv expires keys accurately when time-to-live (TTL) in milliseconds is specified","Keyv namespaces isolate key-value pairs across separate instances sharing the same store","Keyv delete returns true for existing keys and false when deleting non-existent keys"],"goal":"verify pkg:npm/keyv@4.5.4","kind":"HOW","packages":["pkg:npm/keyv@4.5.4"],"schemaVersion":1},"contractCommand":["node","test/contract.js"],"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/keyv@4.5.4"],"schemaVersion":1,"subject":"pkg:npm/keyv@4.5.4","verifierAdapter":"node-typescript@1"}
index.js
'use strict';

const Keyv = require('keyv');

/**
 * Creates a Keyv store instance with optional configuration.
 * @param {object} [options={}] - Keyv constructor options.
 * @returns {Keyv}
 */
function createStore(options = {}) {
  return new Keyv(options);
}

/**
 * Sets a key-value pair in the store with an optional TTL in milliseconds.
 * @param {Keyv} store - The Keyv instance.
 * @param {string} key - The key name.
 * @param {*} value - The value to store.
 * @param {number} [ttl] - Time-to-live in milliseconds.
 * @returns {Promise<boolean>}
 */
async function setKey(store, key, value, ttl) {
  return store.set(key, value, ttl);
}

/**
 * Retrieves the value associated with a key from the store.
 * @param {Keyv} store - The Keyv instance.
 * @param {string} key - The key name.
 * @returns {Promise<*>}
 */
async function getKey(store, key) {
  return store.get(key);
}

/**
 * Checks whether a key exists in the store.
 * @param {Keyv} store - The Keyv instance.
 * @param {string} key - The key name.
 * @returns {Promise<boolean>}
 */
async function hasKey(store, key) {
  return store.has(key);
}

/**
 * Deletes a key from the store.
 * @param {Keyv} store - The Keyv instance.
 * @param {string} key - The key name.
 * @returns {Promise<boolean>}
 */
async function deleteKey(store, key) {
  return store.delete(key);
}

/**
 * Clears all keys in the store.
 * @param {Keyv} store - The Keyv instance.
 * @returns {Promise<void>}
 */
async function clearStore(store) {
  return store.clear();
}

module.exports = {
  createStore,
  setKey,
  getKey,
  hasKey,
  deleteKey,
  clearStore
};
package-lock.json
{
  "name": "sample-keyv",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-keyv",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "keyv": "4.5.4"
      }
    },
    "node_modules/json-buffer": {
      "version": "3.0.1",
      "resolved": "https://registry.npmjs.org/json-buffer/-/json-buffer-3.0.1.tgz",
      "integrity": "sha512-4bV5BfR2mqfQTJm+V5tPPdf+ZpuhiIvTuAB5g8kcrXOZpTT/QwwVRWBywX1ozr6lEuPdbHxwaJlm9G6mI2sfSQ==",
      "license": "MIT"
    },
    "node_modules/keyv": {
      "version": "4.5.4",
      "resolved": "https://registry.npmjs.org/keyv/-/keyv-4.5.4.tgz",
      "integrity": "sha512-oxVHkHR/EJf2CNXnWxRLW6mg7JyCCUcG0DtEGmL2ctUo1PNTin1PUil+r/+4r5MpVgC/fn1kjsx7mjSujKqIpw==",
      "license": "MIT",
      "dependencies": {
        "json-buffer": "3.0.1"
      }
    }
  }
}
package.json
{
  "name": "sample-keyv",
  "version": "1.0.0",
  "private": true,
  "description": "verify pkg:npm/keyv@4.5.4",
  "main": "index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "dependencies": {
    "keyv": "4.5.4"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/keyv@4.5.4",
  "kind": "HOW",
  "packages": [
    "pkg:npm/keyv@4.5.4"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.js
'use strict';

const assert = require('node:assert');
const Keyv = require('keyv');
const {
  createStore,
  setKey,
  getKey,
  hasKey,
  deleteKey,
  clearStore
} = require('../index.js');

async function testBasicSetAndGet() {
  const store = createStore();
  const setSuccess = await setKey(store, 'hello', 'world');
  assert.strictEqual(setSuccess, true, 'set should return true on success');

  const value = await getKey(store, 'hello');
  assert.strictEqual(value, 'world', 'get should return the stored string');
}

async function testStructuredDataTypes() {
  const store = createStore();
  const payload = {
    id: 101,
    tags: ['database', 'cache'],
    active: true,
    nested: { count: 42 }
  };

  await setKey(store, 'payloadKey', payload);
  const result = await getKey(store, 'payloadKey');
  assert.deepStrictEqual(result, payload, 'get should retrieve deeply equal structured objects and arrays');
}

async function testHasAndDelete() {
  const store = createStore();
  await setKey(store, 'sessionToken', 'abc-123');

  const existsBefore = await hasKey(store, 'sessionToken');
  assert.strictEqual(existsBefore, true, 'has should return true for existing key');

  const deleteSuccess = await deleteKey(store, 'sessionToken');
  assert.strictEqual(deleteSuccess, true, 'delete should return true when key is successfully removed');

  const existsAfter = await hasKey(store, 'sessionToken');
  assert.strictEqual(existsAfter, false, 'has should return false after key is deleted');

  const valueAfter = await getKey(store, 'sessionToken');
  assert.strictEqual(valueAfter, undefined, 'get should return undefined for deleted key');

  const deleteMissing = await deleteKey(store, 'sessionToken');
  assert.strictEqual(deleteMissing, false, 'delete should return false when key does not exist');
}

async function testTtlExpiration() {
  const store = createStore();
  await setKey(store, 'temporaryKey', 'expiresSoon', 50);

  const valueImmediate = await getKey(store, 'temporaryKey');
  assert.strictEqual(valueImmediate, 'expiresSoon', 'get should return value before TTL expiration');

  await new Promise((resolve) => setTimeout(resolve, 60));

  const valueExpired = await getKey(store, 'temporaryKey');
  assert.strictEqual(valueExpired, undefined, 'get should return undefined after TTL expires');
}

async function testNamespaceIsolation() {
  const storeA = createStore({ namespace: 'nsA' });
  const storeB = createStore({ namespace: 'nsB' });

  await setKey(storeA, 'key1', 'valueA');
  await setKey(storeB, 'key1', 'valueB');

  assert.strictEqual(await getKey(storeA, 'key1'), 'valueA', 'storeA retrieves valueA');
  assert.strictEqual(await getKey(storeB, 'key1'), 'valueB', 'storeB retrieves valueB');

  await clearStore(storeA);
  assert.strictEqual(await getKey(storeA, 'key1'), undefined, 'clear on storeA removes storeA keys');
  assert.strictEqual(await getKey(storeB, 'key1'), 'valueB', 'clear on storeA does not affect storeB');
}

async function testDirectKeyvInstance() {
  const keyv = new Keyv();
  await keyv.set('directKey', 9999);
  const val = await keyv.get('directKey');
  assert.strictEqual(val, 9999, 'direct Keyv instance set/get works');
  assert.strictEqual(await keyv.has('directKey'), true, 'direct Keyv has works');
  assert.strictEqual(await keyv.delete('directKey'), true, 'direct Keyv delete works');
  assert.strictEqual(await keyv.has('directKey'), false, 'key no longer exists');
}

async function runAll() {
  await testBasicSetAndGet();
  await testStructuredDataTypes();
  await testHasAndDelete();
  await testTtlExpiration();
  await testNamespaceIsolation();
  await testDirectKeyvInstance();
  console.log('All contract tests passed successfully.');
}

runAll().catch((err) => {
  console.error('Contract test failed:', err);
  process.exit(1);
});

オリジンシーダー

匿名