Ejemplo
@sinclair/typebox 0.27.12
Muestra verificada para npm @sinclair/typebox 0.27.12. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó: Type.Object constructs valid…
sha256:678978e82f4718430ecd38fd5126bc01ef0e862b8c2bb1c97d103bb1904819a8
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
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-27 |
Caso
HOW- Objetivo
- verify pkg:npm/%40sinclair/typebox@0.27.12
- Paquetes
- Entorno
- node 22.23.2
- Creado
- 2026-08-27T14:22:19Z
Contrato
- Type.Object constructs valid JSON Schema with expected properties and required constraints
- TypeCompiler.Compile creates compiled validator that returns true for valid payloads and false for invalid structures
- TypeCompiler validator Errors iterator yields validation error details for invalid data
- Value.Check validates arbitrary JavaScript values against TypeBox schema definitions
- Value.Create generates default instance structures populated from schema default metadata
- Value.Cast produces a valid instance by applying defaults and casting compliant values
Archivos
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.mjs
Código fuente
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/%40sinclair/typebox@0.27.12
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/%40sinclair/typebox@0.27.12
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.
{"case":{"caseId":"case:sha256:d453a7af01fa8387f503bed52e950b800312270be6bea31c3992f6277620131d","constraints":{"executionContext":"node"},"contract":["Type.Object constructs valid JSON Schema with expected properties and required constraints","TypeCompiler.Compile creates compiled validator that returns true for valid payloads and false for invalid structures","TypeCompiler validator Errors iterator yields validation error details for invalid data","Value.Check validates arbitrary JavaScript values against TypeBox schema definitions","Value.Create generates default instance structures populated from schema default metadata","Value.Cast produces a valid instance by applying defaults and casting compliant values"],"goal":"verify pkg:npm/%40sinclair/typebox@0.27.12","kind":"HOW","packages":["pkg:npm/%40sinclair/typebox@0.27.12"],"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/%40sinclair/typebox@0.27.12"],"schemaVersion":1,"subject":"pkg:npm/%40sinclair/typebox@0.27.12","verifierAdapter":"node-typescript@1"}
{
"name": "sample-typebox",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-typebox",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"@sinclair/typebox": "0.27.12"
}
},
"node_modules/@sinclair/typebox": {
"version": "0.27.12",
"resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.27.12.tgz",
"integrity": "sha512-hhyNJ+nbR6ZR7pToHvllEFun9TL0sbL+tk/ON75lo+Xas054uez98qRbsuNt7MBCyZKK4+8Yli/OAGZhmfBZ/g==",
"license": "MIT"
}
}
}
{
"name": "sample-typebox",
"version": "1.0.0",
"private": true,
"description": "verify pkg:npm/%40sinclair/typebox@0.27.12",
"main": "src/index.js",
"license": "MIT-0",
"dependencies": {
"@sinclair/typebox": "0.27.12"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/%40sinclair/typebox@0.27.12",
"kind": "HOW",
"packages": [
"pkg:npm/%40sinclair/typebox@0.27.12"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
'use strict';
const { Type } = require('@sinclair/typebox');
const { TypeCompiler } = require('@sinclair/typebox/compiler');
const { Value } = require('@sinclair/typebox/value');
/**
* Creates a standard user schema definition with typed properties.
*
* @returns {object} TypeBox object schema
*/
function createUserSchema() {
return Type.Object({
id: Type.Number({ minimum: 1 }),
name: Type.String({ minLength: 1 }),
email: Type.Optional(Type.String()),
roles: Type.Array(Type.String()),
isActive: Type.Boolean({ default: true })
});
}
/**
* Compiles a TypeBox schema into an optimized validator function.
*
* @param {object} schema - TypeBox schema
* @returns {object} Compiled TypeCheck validator
*/
function compileValidator(schema) {
return TypeCompiler.Compile(schema);
}
/**
* Validates a value directly against a TypeBox schema using Value.Check.
*
* @param {object} schema - TypeBox schema
* @param {*} value - Value to validate
* @returns {boolean} True if valid according to schema
*/
function validateValue(schema, value) {
return Value.Check(schema, value);
}
/**
* Creates a default value based on schema defaults.
*
* @param {object} schema - TypeBox schema
* @returns {*} Default object matching schema
*/
function createDefaultValue(schema) {
return Value.Create(schema);
}
/**
* Casts a value to match the schema, filling in defaults and dropping invalid structures where appropriate.
*
* @param {object} schema - TypeBox schema
* @param {*} value - Value to cast
* @returns {*} Cast value conforming to schema
*/
function castValue(schema, value) {
return Value.Cast(schema, value);
}
module.exports = {
Type,
TypeCompiler,
Value,
createUserSchema,
compileValidator,
validateValue,
createDefaultValue,
castValue
};
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const {
Type,
TypeCompiler,
Value,
createUserSchema,
compileValidator,
validateValue,
createDefaultValue,
castValue
} = require('../src/index.js');
const tb = require('@sinclair/typebox');
const compiler = require('@sinclair/typebox/compiler');
const valuePkg = require('@sinclair/typebox/value');
// 1. Export verification
assert.equal(typeof Type, 'object', 'Type must be exported as an object builder');
assert.equal(typeof TypeCompiler, 'object', 'TypeCompiler must be exported as an object');
assert.equal(typeof Value, 'object', 'Value must be exported as an object');
assert.equal(typeof Type.Object, 'function', 'Type.Object must be a function');
assert.equal(typeof Type.String, 'function', 'Type.String must be a function');
assert.equal(typeof Type.Number, 'function', 'Type.Number must be a function');
assert.equal(typeof Type.Boolean, 'function', 'Type.Boolean must be a function');
assert.equal(typeof Type.Array, 'function', 'Type.Array must be a function');
assert.equal(typeof TypeCompiler.Compile, 'function', 'TypeCompiler.Compile must be a function');
assert.equal(typeof Value.Check, 'function', 'Value.Check must be a function');
assert.equal(typeof Value.Create, 'function', 'Value.Create must be a function');
assert.equal(typeof Value.Cast, 'function', 'Value.Cast must be a function');
assert.equal(Type, tb.Type, 'Type should match package export');
assert.equal(TypeCompiler, compiler.TypeCompiler, 'TypeCompiler should match package export');
assert.equal(Value, valuePkg.Value, 'Value should match package export');
// 2. Type.Object constructs valid JSON Schema with expected properties and required constraints
{
const schema = createUserSchema();
assert.equal(schema.type, 'object', 'Schema type should be object');
assert.equal(typeof schema.properties, 'object', 'Schema should define properties');
assert.equal(schema.properties.id.type, 'number', 'id property should be number');
assert.equal(schema.properties.name.type, 'string', 'name property should be string');
assert.equal(schema.properties.roles.type, 'array', 'roles property should be array');
assert.ok(schema.required.includes('id'), 'id should be in required fields');
assert.ok(schema.required.includes('name'), 'name should be in required fields');
assert.ok(!schema.required.includes('email'), 'optional field email should not be required');
}
// 3. TypeCompiler.Compile creates compiled validator that returns true for valid payloads and false for invalid structures
{
const schema = createUserSchema();
const validator = compileValidator(schema);
const validPayload = {
id: 101,
name: 'Sample Tester',
email: 'test@example.com',
roles: ['admin', 'developer'],
isActive: true
};
assert.equal(validator.Check(validPayload), true, 'Valid payload should pass TypeCompiler Check');
const invalidPayload = {
id: 'invalid-id-not-number',
name: 'Sample Tester',
roles: ['admin']
};
assert.equal(validator.Check(invalidPayload), false, 'Invalid payload should fail TypeCompiler Check');
// 4. TypeCompiler validator Errors iterator yields validation error details for invalid data
const errors = [...validator.Errors(invalidPayload)];
assert.ok(errors.length > 0, 'Validator Errors should produce error items for invalid payload');
assert.equal(errors[0].path, '/id', 'First error path should point to /id');
}
// 5. Value.Check validates arbitrary JavaScript values against TypeBox schema definitions
{
const stringSchema = Type.String({ minLength: 3 });
assert.equal(validateValue(stringSchema, 'hello'), true, 'String meeting minLength should be valid');
assert.equal(validateValue(stringSchema, 'hi'), false, 'String below minLength should be invalid');
assert.equal(validateValue(stringSchema, 12345), false, 'Non-string should be invalid');
}
// 6. Value.Create generates default instance structures populated from schema default metadata
{
const configSchema = Type.Object({
port: Type.Number({ default: 3000 }),
host: Type.String({ default: 'localhost' }),
enabled: Type.Boolean({ default: false })
});
const defaults = createDefaultValue(configSchema);
assert.equal(defaults.port, 3000, 'Default port should match schema default');
assert.equal(defaults.host, 'localhost', 'Default host should match schema default');
assert.equal(defaults.enabled, false, 'Default enabled should match schema default');
}
// 7. Value.Cast produces a valid instance by applying defaults and casting compliant values
{
const profileSchema = Type.Object({
name: Type.String({ default: 'Anonymous' }),
age: Type.Number({ default: 18 }),
active: Type.Boolean({ default: true })
});
const partialData = { age: 25 };
const castResult = castValue(profileSchema, partialData);
assert.equal(castResult.name, 'Anonymous', 'Cast should populate default name');
assert.equal(castResult.age, 25, 'Cast should preserve provided age');
assert.equal(castResult.active, true, 'Cast should populate default active');
}
console.log('Contract assertions passed.');
Seeder de origen
anónimo