CodeSampleX

Ejemplo

json-schema-traverse 0.4.1

Muestra verificada para npm json-schema-traverse 0.4.1. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó: traverse recursively visits…

sha256:724ed455fcbef38e0f40566db0ccc7124ccc9b8e9966afd6ec06c96d1479589c

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
2
Claves de firma que lo compilaron
1
Entorno declarado node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

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@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-23
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-08

Caso

HOW
Objetivo
verify pkg:npm/json-schema-traverse@0.4.1
Paquetes
Entorno
node 22.23.2
Creado
2026-08-23T06:56:05Z

Contrato

  1. traverse recursively visits root and nested schema definitions with standard JSON pointer paths
  2. callback receives schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, and keyIndex
  3. supports separate pre and post traversal callbacks on schema nodes
  4. allKeys option traverses custom keywords while ignoring scalar skip keywords
  5. properly escapes special characters tilde and slash in property JSON pointers

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/json-schema-traverse@0.4.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/json-schema-traverse@0.4.1
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:cf3969bcf5ce492603c6c2e4ca612c755fbb876698db00aeafaf038f34360149","constraints":{"executionContext":"node"},"contract":["traverse recursively visits root and nested schema definitions with standard JSON pointer paths","callback receives schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, and keyIndex","supports separate pre and post traversal callbacks on schema nodes","allKeys option traverses custom keywords while ignoring scalar skip keywords","properly escapes special characters tilde and slash in property JSON pointers"],"goal":"verify pkg:npm/json-schema-traverse@0.4.1","kind":"HOW","packages":["pkg:npm/json-schema-traverse@0.4.1"],"schemaVersion":1},"contractCommand":["node","test/contract.mjs"],"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/json-schema-traverse@0.4.1"],"schemaVersion":1,"subject":"pkg:npm/json-schema-traverse@0.4.1","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-json-schema-traverse",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-json-schema-traverse",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "json-schema-traverse": "0.4.1"
      }
    },
    "node_modules/json-schema-traverse": {
      "version": "0.4.1",
      "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-0.4.1.tgz",
      "integrity": "sha512-xbbCH5dCYU5T8LcEhhuh7HJ88HXuW3qsI3Y0zOZFKfZEHcpWiHU/Jxzk629Brsab/mMiHQti9wMP+845RPe3Vg==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-json-schema-traverse",
  "version": "1.0.0",
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "json-schema-traverse": "0.4.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/json-schema-traverse@0.4.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/json-schema-traverse@0.4.1"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const traverse = require('json-schema-traverse');

// 1. traverse recursively visits root and nested schema definitions with standard JSON pointer paths
const schema = {
  type: 'object',
  properties: {
    name: { type: 'string' },
    tags: {
      type: 'array',
      items: [{ type: 'string' }, { type: 'number' }]
    }
  },
  definitions: {
    custom: { type: 'boolean' }
  },
  allOf: [
    { required: ['name'] }
  ]
};

const visitedPointers = [];
traverse(schema, (subSchema, jsonPtr) => {
  visitedPointers.push(jsonPtr);
});

assert.deepEqual(visitedPointers, [
  '',
  '/properties/name',
  '/properties/tags',
  '/properties/tags/items/0',
  '/properties/tags/items/1',
  '/definitions/custom',
  '/allOf/0'
]);

// 2. callback receives schema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, and keyIndex
const details = [];
traverse(schema, (subSchema, jsonPtr, rootSchema, parentJsonPtr, parentKeyword, parentSchema, keyIndex) => {
  details.push({
    jsonPtr,
    isRoot: rootSchema === schema,
    parentJsonPtr,
    parentKeyword,
    keyIndex
  });
});

assert.deepEqual(details[0], {
  jsonPtr: '',
  isRoot: true,
  parentJsonPtr: undefined,
  parentKeyword: undefined,
  keyIndex: undefined
});

assert.deepEqual(details[1], {
  jsonPtr: '/properties/name',
  isRoot: true,
  parentJsonPtr: '',
  parentKeyword: 'properties',
  keyIndex: 'name'
});

assert.deepEqual(details[3], {
  jsonPtr: '/properties/tags/items/0',
  isRoot: true,
  parentJsonPtr: '/properties/tags',
  parentKeyword: 'items',
  keyIndex: 0
});

// 3. supports separate pre and post traversal callbacks on schema nodes
const prePostLog = [];
const smallSchema = {
  properties: {
    a: { type: 'string' }
  }
};

traverse(smallSchema, {
  cb: {
    pre: (subSchema, jsonPtr) => prePostLog.push(`pre:${jsonPtr}`),
    post: (subSchema, jsonPtr) => prePostLog.push(`post:${jsonPtr}`)
  }
});

assert.deepEqual(prePostLog, [
  'pre:',
  'pre:/properties/a',
  'post:/properties/a',
  'post:'
]);

// 4. allKeys option traverses custom keywords while ignoring scalar skip keywords
const customSchema = {
  customSection: {
    subProperty: { type: 'number' }
  },
  title: 'Sample Title',
  minimum: 10
};

const customVisited = [];
traverse(customSchema, { allKeys: true }, (subSchema, jsonPtr) => {
  customVisited.push(jsonPtr);
});

assert.deepEqual(customVisited, [
  '',
  '/customSection',
  '/customSection/subProperty'
]);

// 5. properly escapes special characters tilde and slash in property JSON pointers
const specialKeysSchema = {
  properties: {
    'a~b': { type: 'string' },
    'c/d': { type: 'number' },
    'e~/f': { type: 'boolean' }
  }
};

const specialPointers = [];
traverse(specialKeysSchema, (subSchema, jsonPtr) => {
  specialPointers.push(jsonPtr);
});

assert.deepEqual(specialPointers, [
  '',
  '/properties/a~0b',
  '/properties/c~1d',
  '/properties/e~0~1f'
]);

Seeder de origen

anónimo