CodeSampleX

샘플

@sinclair/typebox 0.27.12

검증된 샘플 — npm @sinclair/typebox 0.27.12. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: Type.Object constructs valid JSON Schema with expected…

sha256:678978e82f4718430ecd38fd5126bc01ef0e862b8c2bb1c97d103bb1904819a8

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. 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.12
패키지
환경
node 22.23.2
생성일
2026-08-27T14:22:19Z

컨트랙트

  1. Type.Object constructs valid JSON Schema with expected properties and required constraints
  2. TypeCompiler.Compile creates compiled validator that returns true for valid payloads and false for invalid structures
  3. TypeCompiler validator Errors iterator yields validation error details for invalid data
  4. Value.Check validates arbitrary JavaScript values against TypeBox schema definitions
  5. Value.Create generates default instance structures populated from schema default metadata
  6. Value.Cast produces a valid instance by applying defaults and casting compliant values

파일

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

소스 아티팩트 내려받기 (tar.gz)

소스

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/%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.
csx.json
{"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"}
package-lock.json
{
  "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"
    }
  }
}
package.json
{
  "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"
  }
}
spec.json
{
  "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"
  }
}
src/index.js
'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
};
test/contract.mjs
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.');

오리진 시더

익명