CodeSampleX

Exemple

ts-api-utils 2.5.0

Échantillon vérifié pour npm ts-api-utils 2.5.0. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi.

sha256:d3fa43248180460dc5624f8192e3fd3c5c730f7c726ee4547f4194b27fe879d2

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré linux 24 · ubuntu · glibc 2.39 x64 npm

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-21

Cas

HOW
Objectif
verify pkg:npm/ts-api-utils@2.5.0
Paquets
Créé
2026-08-21T07:20:43Z

Contrat

  1. forEachToken iterates through all AST tokens of a TypeScript source file
  2. forEachComment extracts leading and trailing comments from AST nodes
  3. collectVariableUsage analyzes identifiers, declarations, and usages across scopes
  4. isFunctionLikeDeclaration and isNodeFlagSet correctly identify function declarations and node flags

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code source

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/ts-api-utils@2.5.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/ts-api-utils@2.5.0

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:ce718eea4691a5dfaab43c2d46da5498e31266e0a3ea41423f84d3b811659a11","contract":["forEachToken iterates through all AST tokens of a TypeScript source file","forEachComment extracts leading and trailing comments from AST nodes","collectVariableUsage analyzes identifiers, declarations, and usages across scopes","isFunctionLikeDeclaration and isNodeFlagSet correctly identify function declarations and node flags"],"goal":"verify pkg:npm/ts-api-utils@2.5.0","kind":"HOW","packages":["pkg:npm/ts-api-utils@2.5.0"],"schemaVersion":1},"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/ts-api-utils@2.5.0"],"schemaVersion":1,"subject":"pkg:npm/ts-api-utils@2.5.0","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-ts-api-utils",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-ts-api-utils",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "ts-api-utils": "2.5.0",
        "typescript": "5.7.3"
      }
    },
    "node_modules/ts-api-utils": {
      "version": "2.5.0",
      "resolved": "https://registry.npmjs.org/ts-api-utils/-/ts-api-utils-2.5.0.tgz",
      "integrity": "sha512-OJ/ibxhPlqrMM0UiNHJ/0CKQkoKF243/AEmplt3qpRgkW8VG7IfOS41h7V8TjITqdByHzrjcS/2si+y4lIh8NA==",
      "license": "MIT",
      "engines": {
        "node": ">=18.12"
      },
      "peerDependencies": {
        "typescript": ">=4.8.4"
      }
    },
    "node_modules/typescript": {
      "version": "5.7.3",
      "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.7.3.tgz",
      "integrity": "sha512-84MVSjMEHP+FQRPy3pX9sTVV/INIex71s9TL2Gm5FG/WG1SqXeKyZ0k7/blY/4FdOzI12CBy1vGc4og/eus0fw==",
      "license": "Apache-2.0",
      "bin": {
        "tsc": "bin/tsc",
        "tsserver": "bin/tsserver"
      },
      "engines": {
        "node": ">=14.17"
      }
    }
  }
}
package.json
{
  "name": "sample-ts-api-utils",
  "version": "1.0.0",
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "ts-api-utils": "2.5.0",
    "typescript": "5.7.3"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/ts-api-utils@2.5.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/ts-api-utils@2.5.0"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import * as tsutils from 'ts-api-utils';
import ts from 'typescript';

// 1. forEachToken iterates through all AST tokens of a TypeScript source file
const sourceCode1 = 'const x: number = 42;';
const sourceFile1 = ts.createSourceFile('example.ts', sourceCode1, ts.ScriptTarget.Latest, true);
const tokens = [];
tsutils.forEachToken(sourceFile1, (token) => {
  tokens.push(ts.tokenToString(token.kind) || token.getText(sourceFile1));
});
assert.ok(tokens.includes('const'), 'tokens should contain const');
assert.ok(tokens.includes('x'), 'tokens should contain x');
assert.ok(tokens.includes('number'), 'tokens should contain number');
assert.ok(tokens.includes('42'), 'tokens should contain 42');

// 2. forEachComment extracts leading and trailing comments from AST nodes
const sourceCode2 = '// leading comment\nconst a = 1; /* trailing block */';
const sourceFile2 = ts.createSourceFile('comment.ts', sourceCode2, ts.ScriptTarget.Latest, true);
const comments = [];
tsutils.forEachComment(sourceFile2, (fullText, comment) => {
  comments.push(fullText.slice(comment.pos, comment.end));
});
assert.equal(comments.length, 2, 'should find exactly two comments');
assert.equal(comments[0], '// leading comment');
assert.equal(comments[1], '/* trailing block */');

// 3. collectVariableUsage analyzes identifiers, declarations, and usages across scopes
const sourceCode3 = 'const val = 10; function compute() { return val + 5; }';
const sourceFile3 = ts.createSourceFile('usage.ts', sourceCode3, ts.ScriptTarget.Latest, true);
const usageMap = tsutils.collectVariableUsage(sourceFile3);
const valEntry = Array.from(usageMap.entries()).find(([ident]) => ident.text === 'val');
assert.ok(valEntry, 'val should be tracked in variable usage map');
assert.equal(valEntry[1].declarations.length, 1, 'val should have 1 declaration');
assert.equal(valEntry[1].uses.length, 1, 'val should have 1 use');

// 4. isFunctionLikeDeclaration and isNodeFlagSet correctly identify function declarations and node flags
const stmtConst = sourceFile3.statements[0];
const stmtFn = sourceFile3.statements[1];
assert.equal(tsutils.isNodeFlagSet(stmtConst.declarationList, ts.NodeFlags.Const), true, 'stmtConst should have Const flag');
assert.equal(tsutils.isFunctionLikeDeclaration(stmtFn), true, 'stmtFn should be function-like declaration');
assert.equal(tsutils.isFunctionLikeDeclaration(stmtConst), false, 'stmtConst should not be function-like declaration');

Seeder d'origine

anonyme