CodeSampleX

サンプル

@types/node 22.20.5

検証済みサンプル — npm @types/node 22.20.5. node 22 · linux debian/x64 · docker で contract を実行し、成功しました: @types/node@22.20.5 package.json declares version 22.20.5…

sha256:1d8a675098103a9c9713aef669d0db09f40377810c19db3f5e99d1bdb3128823

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

実行証拠

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

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

検証実行環境

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

ケース

HOW
ゴール
verify pkg:npm/%40types/node@22.20.5
パッケージ
環境
node 22.23.2
作成日
2026-11-28T23:40:20Z

コントラクト

  1. @types/node@22.20.5 package.json declares version 22.20.5, types entry index.d.ts, and typesVersions['<=5.6']
  2. TypeScript 5.9.3 compiles strict Node.js code against @types/node@22.20.5 with skipLibCheck disabled and zero diagnostics
  3. Buffer.from(string, 'utf8') produces Buffer<ArrayBuffer> assignable to Uint8Array<ArrayBuffer>, while Buffer<SharedArrayBuffer> is rejected as Buffer<ArrayBuffer>
  4. Typed EventEmitter generic event maps accept matching emit payloads and reject mismatched payload types
  5. node:sqlite declarations expose DatabaseSync, DatabaseSyncOptions (readBigInts, returnArrays, allowBareNamedParameters, timeout), and SQLOutputValue
  6. Compiled CommonJS output executes on Node.js and matches node:buffer, node:crypto, node:events, node:util parseArgs, node:path, and process.versions declarations

ファイル

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

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

Use EXACTLY these public packages and versions:
  - pkg:npm/%40types/node@22.20.5
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:62eff322e1a9eacecc3f15cec60b11105bc782eaf5594e790a58f8075c095c4f","constraints":{"executionContext":"node"},"contract":["@types/node@22.20.5 package.json declares version 22.20.5, types entry index.d.ts, and typesVersions['\u003c=5.6']","TypeScript 5.9.3 compiles strict Node.js code against @types/node@22.20.5 with skipLibCheck disabled and zero diagnostics","Buffer.from(string, 'utf8') produces Buffer\u003cArrayBuffer\u003e assignable to Uint8Array\u003cArrayBuffer\u003e, while Buffer\u003cSharedArrayBuffer\u003e is rejected as Buffer\u003cArrayBuffer\u003e","Typed EventEmitter generic event maps accept matching emit payloads and reject mismatched payload types","node:sqlite declarations expose DatabaseSync, DatabaseSyncOptions (readBigInts, returnArrays, allowBareNamedParameters, timeout), and SQLOutputValue","Compiled CommonJS output executes on Node.js and matches node:buffer, node:crypto, node:events, node:util parseArgs, node:path, and process.versions declarations"],"goal":"verify pkg:npm/%40types/node@22.20.5","kind":"HOW","packages":["pkg:npm/%40types/node@22.20.5"],"schemaVersion":1},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"typescript","languageVersion":"5.9.3","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/%40types/node@22.20.5"],"schemaVersion":1,"subject":"pkg:npm/%40types/node@22.20.5","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "types-node-22-20-5-sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "types-node-22-20-5-sample",
      "version": "1.0.0",
      "devDependencies": {
        "@types/node": "22.20.5",
        "typescript": "5.9.3"
      }
    },
    "node_modules/@types/node": {
      "version": "22.20.5",
      "resolved": "https://registry.npmjs.org/@types/node/-/node-22.20.5.tgz",
      "integrity": "sha512-U2+DNr+wSjpsTS/wZGYHq7GcwfuSmKiKvoPvK22zwTlRhU91yOniN4qRR5KhIjvif7ysw/dz/hKmfDH0Ris4aA==",
      "dev": true,
      "license": "MIT",
      "dependencies": {
        "undici-types": "~6.21.0"
      }
    },
    "node_modules/typescript": {
      "version": "5.9.3",
      "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.9.3.tgz",
      "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==",
      "dev": true,
      "license": "Apache-2.0",
      "bin": {
        "tsc": "bin/tsc",
        "tsserver": "bin/tsserver"
      },
      "engines": {
        "node": ">=14.17"
      }
    },
    "node_modules/undici-types": {
      "version": "6.21.0",
      "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.21.0.tgz",
      "integrity": "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ==",
      "dev": true,
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "types-node-22-20-5-sample",
  "version": "1.0.0",
  "private": true,
  "scripts": {
    "typecheck": "tsc --noEmit",
    "test": "node test/contract.mjs"
  },
  "devDependencies": {
    "@types/node": "22.20.5",
    "typescript": "5.9.3"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/%40types/node@22.20.5",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40types/node@22.20.5"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
src/index.ts
import { Buffer } from "node:buffer";
import { createHash } from "node:crypto";
import { EventEmitter } from "node:events";
import * as path from "node:path";
import * as process from "node:process";
import type { DatabaseSync, DatabaseSyncOptions, SQLOutputValue } from "node:sqlite";
import { parseArgs } from "node:util";

export interface SampleResult {
  bufferLength: number;
  sha256Hex: string;
  eventSum: number;
  parsedPort: string | undefined;
  parsedVerbose: boolean;
  joinedPath: string;
  nodeVersion: string;
  sqliteOptions: DatabaseSyncOptions;
}

export function verifyTypedBuffer(text: string): Uint8Array<ArrayBuffer> {
  const buf: Buffer<ArrayBuffer> = Buffer.from(text, "utf8");
  const shared = Buffer.from(new SharedArrayBuffer(4));
  // @ts-expect-error Buffer<SharedArrayBuffer> is not assignable to Buffer<ArrayBuffer> in TS 5.7+
  const invalid: Buffer<ArrayBuffer> = shared;
  void invalid;
  return buf;
}

export function verifyTypedEmitter(initial: number): number {
  const emitter = new EventEmitter<{
    add: [delta: number];
    reset: [];
  }>();

  let total = initial;
  emitter.on("add", (delta) => {
    total += delta;
  });
  emitter.on("reset", () => {
    total = 0;
  });

  emitter.emit("add", 7);
  if (false) {
    // @ts-expect-error Event payload for "add" must be a number
    emitter.emit("add", "not-a-number");
  }
  return total;
}

export function runSample(argv: string[]): SampleResult {
  const bytes = verifyTypedBuffer("types-node-22-20-5");
  const sha256Hex: string = createHash("sha256").update(bytes).digest("hex");

  const parsed = parseArgs({
    args: argv,
    strict: true,
    options: {
      port: { type: "string", short: "p" },
      verbose: { type: "boolean", default: false },
    },
  });

  const sqliteOptions: DatabaseSyncOptions = {
    open: true,
    readOnly: false,
    timeout: 500,
    readBigInts: true,
    returnArrays: false,
    allowBareNamedParameters: true,
  };

  // Type-only assertions verifying node:sqlite declarations from @types/node@22.20.5
  type CheckDb = DatabaseSync["close"];
  type CheckOutput = SQLOutputValue;
  const checkDb: CheckDb | null = null;
  const checkOut: CheckOutput = new Uint8Array(new ArrayBuffer(2));
  void checkDb;
  void checkOut;

  const versions: NodeJS.ProcessVersions = process.versions;

  return {
    bufferLength: bytes.byteLength,
    sha256Hex,
    eventSum: verifyTypedEmitter(3),
    parsedPort: parsed.values.port,
    parsedVerbose: parsed.values.verbose,
    joinedPath: path.posix.join("types", "node", "22.20.5"),
    nodeVersion: versions.node,
    sqliteOptions,
  };
}
test/contract.mjs
import assert from "node:assert/strict";
import { execFileSync } from "node:child_process";
import fs from "node:fs";
import os from "node:os";
import path from "node:path";
import { createRequire } from "node:module";
import { fileURLToPath } from "node:url";

const __dirname = path.dirname(fileURLToPath(import.meta.url));
const rootDir = path.resolve(__dirname, "..");
const require = createRequire(import.meta.url);

// 1. Verify exact installed @types/node version and metadata
const typesNodePkgPath = path.join(rootDir, "node_modules", "@types", "node", "package.json");
const typesNodePkg = JSON.parse(fs.readFileSync(typesNodePkgPath, "utf8"));
assert.equal(typesNodePkg.name, "@types/node");
assert.equal(typesNodePkg.version, "22.20.5");
assert.equal(typesNodePkg.types, "index.d.ts");
assert.ok(
  typesNodePkg.typesVersions && typesNodePkg.typesVersions["<=5.6"],
  "expected typesVersions['<=5.6'] entry in @types/node@22.20.5"
);

// 2. Full strict typecheck with skipLibCheck: false against @types/node@22.20.5
const tscPath = require.resolve("typescript/bin/tsc");
const outDir = fs.mkdtempSync(path.join(os.tmpdir(), "types-node-sample-"));

try {
  execFileSync(
    process.execPath,
    [
      tscPath,
      "--project",
      path.join(rootDir, "tsconfig.json"),
      "--noEmit",
      "false",
      "--outDir",
      outDir,
    ],
    {
      cwd: rootDir,
      stdio: "pipe",
      encoding: "utf8",
    }
  );

  // 3. Execute compiled CommonJS output and verify runtime behavior matches declarations
  const compiled = require(path.join(outDir, "index.js"));
  const result = compiled.runSample(["--port", "8080", "--verbose"]);

  assert.equal(result.bufferLength, 18);
  assert.match(result.sha256Hex, /^[0-9a-f]{64}$/);
  assert.equal(result.eventSum, 10);
  assert.equal(result.parsedPort, "8080");
  assert.equal(result.parsedVerbose, true);
  assert.equal(result.joinedPath, "types/node/22.20.5");
  assert.equal(typeof result.nodeVersion, "string");
  assert.ok(result.nodeVersion.length > 0);
  assert.equal(result.sqliteOptions.readBigInts, true);
  assert.equal(result.sqliteOptions.timeout, 500);
} finally {
  fs.rmSync(outDir, { recursive: true, force: true });
}
tsconfig.json
{
  "compilerOptions": {
    "target": "ES2022",
    "module": "CommonJS",
    "moduleResolution": "Node",
    "strict": true,
    "skipLibCheck": false,
    "types": ["node"],
    "noEmit": true
  },
  "include": ["src/**/*.ts"]
}

オリジンシーダー

匿名