Exemplo
@sinclair/typebox 0.27.8
Amostra verificada para npm @sinclair/typebox 0.27.8. O contrato rodou em node 22 · linux alpine/x64 · docker e passou: Value.Create constructs schema…
sha256:973d51be0473ae5fea1a1fef7916124d7035d9ea38486983e71f28daab32b1cb
Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu.
Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas.
MIT-0
Evidência de execução
O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.
- Base da evidência
- Contrato assinado aprovado
- Recibos de verificação
- 1
- Chaves de assinatura que o compilaram
- 1
Ambiente declarado
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
Ambientes das execuções de verificação
| Ambiente | Contrato | Etapas | Execução |
|---|---|---|---|
| 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.8
- Pacotes
- Ambiente
- node 22.23.2
- Criado
- 2026-08-27T14:51:38Z
Contrato
- Value.Create constructs schema default values matching structural schema definitions
- Value.Cast coerces and fills missing default fields on partial input objects
- Value.Check validates values against schema and returns boolean status
- Value.Clone creates deep clones and Value.Equal compares values by structural equality
- Value.Diff computes structural JSON patch differences and Value.Patch updates targets
- Value.Errors identifies specific validation errors with precise JSON paths and error messages
Arquivos
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.mjs
Código-fonte
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.8
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/%40sinclair/typebox@0.27.8
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:40c4f3f571cc199cc2491ce96f08cc4083f3bbb0d488cc8a61b02e7914fa31ea","constraints":{"executionContext":"node"},"contract":["Value.Create constructs schema default values matching structural schema definitions","Value.Cast coerces and fills missing default fields on partial input objects","Value.Check validates values against schema and returns boolean status","Value.Clone creates deep clones and Value.Equal compares values by structural equality","Value.Diff computes structural JSON patch differences and Value.Patch updates targets","Value.Errors identifies specific validation errors with precise JSON paths and error messages"],"goal":"verify pkg:npm/%40sinclair/typebox@0.27.8","kind":"HOW","packages":["pkg:npm/%40sinclair/typebox@0.27.8"],"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.8"],"schemaVersion":1,"subject":"pkg:npm/%40sinclair/typebox@0.27.8","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.8"
}
},
"node_modules/@sinclair/typebox": {
"version": "0.27.8",
"resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.27.8.tgz",
"integrity": "sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA==",
"license": "MIT"
}
}
}
{
"name": "sample-typebox",
"version": "1.0.0",
"private": true,
"type": "commonjs",
"license": "MIT-0",
"dependencies": {
"@sinclair/typebox": "0.27.8"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/%40sinclair/typebox@0.27.8",
"kind": "HOW",
"packages": [
"pkg:npm/%40sinclair/typebox@0.27.8"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
const { Type } = require('@sinclair/typebox');
const { Value } = require('@sinclair/typebox/value');
/**
* Creates a product configuration schema with various types, defaults, and constraints.
*/
const ProductConfigSchema = Type.Object({
sku: Type.String({ minLength: 3, maxLength: 20 }),
name: Type.String({ default: 'Unnamed Product' }),
price: Type.Number({ minimum: 0, default: 0 }),
inStock: Type.Boolean({ default: true }),
tags: Type.Array(Type.String(), { default: [] }),
metadata: Type.Optional(Type.Record(Type.String(), Type.String()))
}, { additionalProperties: false });
/**
* Generate default value for a schema.
* @param {import('@sinclair/typebox').TSchema} schema
*/
function createDefault(schema) {
return Value.Create(schema);
}
/**
* Casts a value to match schema, filling missing defaults and sanitizing structure.
* @param {import('@sinclair/typebox').TSchema} schema
* @param {unknown} value
*/
function castValue(schema, value) {
return Value.Cast(schema, value);
}
/**
* Validates a value against schema directly.
* @param {import('@sinclair/typebox').TSchema} schema
* @param {unknown} value
*/
function checkValue(schema, value) {
return Value.Check(schema, value);
}
/**
* Clones a value deeply.
* @param {unknown} value
*/
function cloneValue(value) {
return Value.Clone(value);
}
/**
* Checks equality between two values.
* @param {unknown} a
* @param {unknown} b
*/
function areEqual(a, b) {
return Value.Equal(a, b);
}
/**
* Computes structural differences between two values.
* @param {unknown} current
* @param {unknown} next
*/
function computeDiff(current, next) {
return Value.Diff(current, next);
}
/**
* Applies diff patches to a base value.
* @param {unknown} base
* @param {Array<{ type: string, path: string, value?: unknown }>} patch
*/
function applyPatch(base, patch) {
return Value.Patch(base, patch);
}
/**
* Collects all validation errors for a value against schema.
* @param {import('@sinclair/typebox').TSchema} schema
* @param {unknown} value
*/
function collectErrors(schema, value) {
const errors = [];
for (const err of Value.Errors(schema, value)) {
errors.push({
path: err.path,
message: err.message,
value: err.value
});
}
return errors;
}
module.exports = {
Type,
Value,
ProductConfigSchema,
createDefault,
castValue,
checkValue,
cloneValue,
areEqual,
computeDiff,
applyPatch,
collectErrors
};
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const {
Type,
Value,
ProductConfigSchema,
createDefault,
castValue,
checkValue,
cloneValue,
areEqual,
computeDiff,
applyPatch,
collectErrors
} = require('../src/index.js');
// 1. Value.Create constructs schema default values matching structural schema definitions
const defaultValue = createDefault(ProductConfigSchema);
assert.equal(defaultValue.name, 'Unnamed Product', 'Default name should be applied');
assert.equal(defaultValue.price, 0, 'Default price should be 0');
assert.equal(defaultValue.inStock, true, 'Default inStock should be true');
assert.deepEqual(defaultValue.tags, [], 'Default tags should be empty array');
// 2. Value.Cast coerces and fills missing default fields on partial input objects
const partialInput = { sku: 'PROD-001' };
const casted = castValue(ProductConfigSchema, partialInput);
assert.equal(casted.sku, 'PROD-001', 'sku should be preserved');
assert.equal(casted.name, 'Unnamed Product', 'name should be filled from default');
assert.equal(casted.price, 0, 'price should be filled from default');
assert.equal(casted.inStock, true, 'inStock should be filled from default');
assert.deepEqual(casted.tags, [], 'tags should be filled from default');
// 3. Value.Check validates values against schema and returns boolean status
assert.equal(checkValue(ProductConfigSchema, casted), true, 'Casted object should be valid');
assert.equal(checkValue(ProductConfigSchema, { sku: 'OK', price: -5 }), false, 'Negative price should be invalid');
assert.equal(checkValue(ProductConfigSchema, { sku: 123 }), false, 'Non-string sku should be invalid');
// 4. Value.Clone creates deep clones and Value.Equal compares values by structural equality
const original = { sku: 'ITEM-99', name: 'Widget', price: 29.99, inStock: true, tags: ['hardware', 'gadget'] };
const cloned = cloneValue(original);
assert.notEqual(cloned, original, 'Clone should be a new object reference');
assert.notEqual(cloned.tags, original.tags, 'Nested array should be a new array reference');
assert.equal(areEqual(original, cloned), true, 'Original and clone should be deeply equal');
cloned.price = 39.99;
assert.equal(areEqual(original, cloned), false, 'Modified clone should not be equal');
// 5. Value.Diff computes structural JSON patch differences and Value.Patch updates targets
const stateA = { sku: 'ITEM-1', name: 'Original', price: 10, inStock: true, tags: ['a'] };
const stateB = { sku: 'ITEM-1', name: 'Updated', price: 15, inStock: false, tags: ['a', 'b'] };
const diffOps = computeDiff(stateA, stateB);
assert.ok(Array.isArray(diffOps), 'Diff should return an array of operations');
assert.ok(diffOps.length > 0, 'Diff should contain patch operations');
const patched = applyPatch(stateA, diffOps);
assert.deepEqual(patched, stateB, 'Patching stateA with diffOps should produce stateB');
// 6. Value.Errors identifies specific validation errors with precise JSON paths and error messages
const invalidPayload = {
sku: 'X',
price: -10,
tags: [100],
extra: 'bad'
};
const errors = collectErrors(ProductConfigSchema, invalidPayload);
assert.ok(errors.length >= 3, 'Should report at least 3 validation errors');
assert.ok(errors.some(e => e.path === '/sku'), 'Should report error for /sku');
assert.ok(errors.some(e => e.path === '/price'), 'Should report error for /price');
assert.ok(errors.some(e => e.path.startsWith('/tags')), 'Should report error for /tags');
console.log('Contract tests passed successfully.');
Seeder de origem
anônimo