샘플
@sinclair/typebox 0.27.8
검증된 샘플 — npm @sinclair/typebox 0.27.8. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: Value.Create constructs schema default values matching…
sha256:973d51be0473ae5fea1a1fef7916124d7035d9ea38486983e71f28daab32b1cb
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 1
- 빌드한 서명 키
- 1
선언된 환경
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| 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 |
케이스
HOW- 목표
- verify pkg:npm/%40sinclair/typebox@0.27.8
- 환경
- node 22.23.2
- 생성일
- 2026-08-27T14:51:38Z
컨트랙트
- 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
파일
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.mjs
소스
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.');
오리진 시더
익명