CodeSampleX

Ejemplo

ts-api-utils 2.5.0

Muestra verificada para npm ts-api-utils 2.5.0. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó: forEachToken iterates through all AST…

sha256:d3fa43248180460dc5624f8192e3fd3c5c730f7c726ee4547f4194b27fe879d2

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado linux 24 · ubuntu · glibc 2.39 x64 npm

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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

Caso

HOW
Objetivo
verify pkg:npm/ts-api-utils@2.5.0
Paquetes
Creado
2026-08-21T07:20:43Z

Contrato

  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

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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 de origen

anónimo