CodeSampleX

サンプル

@sinclair/typebox 0.27.12: Value

検証済みサンプル — npm @sinclair/typebox 0.27.12: Value. node 22 · linux debian/x64 · docker で contract を実行し、成功しました: Value.Check verifies conforming values against…

sha256:7e35b504c68c2b4679ad4da11b015c2d1d3b7b059244b7abf0edbb56d3c31b3f

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
1
ビルドした署名鍵
1
宣言された環境 linux 24 · ubuntu · glibc 2.39 x64 npm

検証実行環境

環境 コントラクト ステージ 実行日
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-03

ケース

HOW
ゴール
verify @sinclair/typebox.Value in pkg:npm/%40sinclair/typebox@0.27.12
パッケージ
シンボル
  • @sinclair/typebox.Value
作成日
2026-09-03T07:28:30Z

コントラクト

  1. Value.Check verifies conforming values against schema definitions and rejects mismatches
  2. Value.Cast populates missing default properties and coerces types to satisfy schema
  3. Value.Create generates minimum valid instances matching schema definitions
  4. Value.Convert coerces string representations of primitives into expected schema types
  5. Value.Clone creates independent deep structural copies of objects and arrays
  6. Value.Equal evaluates deep structural equality across objects and collections
  7. Value.Diff and Value.Patch compute and apply structural delta changesets between objects
  8. Value.Mutate updates target object properties in-place to mirror source values
  9. Value.Errors returns detailed error objects with schema paths and messages for invalid data
  10. Value.Hash produces consistent 64-bit BigInt hash invariant to object key ordering

ファイル

  • PROMPT.md
  • csx.json
  • index.mjs
  • package-lock.json
  • package.json
  • spec.json
  • 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 @sinclair/typebox.Value in pkg:npm/%40sinclair/typebox@0.27.12
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40sinclair/typebox@0.27.12
Demonstrate these symbols/APIs:
  - @sinclair/typebox.Value

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:f9fd5c923cdccc078b94e153818bb7e1494fe8b385a63d52348e72caaaa96566","contract":["Value.Check verifies conforming values against schema definitions and rejects mismatches","Value.Cast populates missing default properties and coerces types to satisfy schema","Value.Create generates minimum valid instances matching schema definitions","Value.Convert coerces string representations of primitives into expected schema types","Value.Clone creates independent deep structural copies of objects and arrays","Value.Equal evaluates deep structural equality across objects and collections","Value.Diff and Value.Patch compute and apply structural delta changesets between objects","Value.Mutate updates target object properties in-place to mirror source values","Value.Errors returns detailed error objects with schema paths and messages for invalid data","Value.Hash produces consistent 64-bit BigInt hash invariant to object key ordering"],"goal":"verify @sinclair/typebox.Value in pkg:npm/%40sinclair/typebox@0.27.12","kind":"HOW","packages":["pkg:npm/%40sinclair/typebox@0.27.12"],"schemaVersion":1,"symbols":["@sinclair/typebox.Value"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40sinclair/typebox@0.27.12"],"schemaVersion":1,"subject":"pkg:npm/%40sinclair/typebox@0.27.12","symbols":["@sinclair/typebox.Value"],"verifierAdapter":"node-typescript@1"}
index.mjs
import { Type } from '@sinclair/typebox';
import { Value } from '@sinclair/typebox/value';

export { Type, Value };

export function checkValue(schema, value) {
  return Value.Check(schema, value);
}

export function castValue(schema, value) {
  return Value.Cast(schema, value);
}

export function createValue(schema) {
  return Value.Create(schema);
}

export function convertValue(schema, value) {
  return Value.Convert(schema, value);
}

export function cloneValue(value) {
  return Value.Clone(value);
}

export function equalValues(a, b) {
  return Value.Equal(a, b);
}

export function diffValues(current, next) {
  return Value.Diff(current, next);
}

export function patchValue(current, diff) {
  return Value.Patch(current, diff);
}

export function mutateValue(current, next) {
  Value.Mutate(current, next);
  return current;
}

export function getErrors(schema, value) {
  return [...Value.Errors(schema, value)];
}

export function hashValue(value) {
  return Value.Hash(value);
}

export default {
  Type,
  Value,
  checkValue,
  castValue,
  createValue,
  convertValue,
  cloneValue,
  equalValues,
  diffValues,
  patchValue,
  mutateValue,
  getErrors,
  hashValue,
};
package-lock.json
{
  "name": "sample-typebox-value",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-typebox-value",
      "version": "1.0.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-value",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "dependencies": {
    "@sinclair/typebox": "0.27.12"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @sinclair/typebox.Value in pkg:npm/%40sinclair/typebox@0.27.12",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40sinclair/typebox@0.27.12"
  ],
  "symbols": [
    "@sinclair/typebox.Value"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import {
  Type,
  Value,
  checkValue,
  castValue,
  createValue,
  convertValue,
  cloneValue,
  equalValues,
  diffValues,
  patchValue,
  mutateValue,
  getErrors,
  hashValue,
} from '../index.mjs';

// Contract 1: Value.Check verifies conforming values against schema definitions and rejects mismatches
{
  const schema = Type.Object({
    name: Type.String({ minLength: 1 }),
    count: Type.Number({ minimum: 0 }),
  });

  assert.strictEqual(checkValue(schema, { name: 'sample', count: 5 }), true);
  assert.strictEqual(Value.Check(schema, { name: 'sample', count: 5 }), true);
  assert.strictEqual(checkValue(schema, { name: '', count: 5 }), false);
  assert.strictEqual(checkValue(schema, { name: 'sample', count: -1 }), false);
  assert.strictEqual(checkValue(schema, { name: 'sample' }), false);
  assert.strictEqual(checkValue(schema, null), false);
}

// Contract 2: Value.Cast populates missing default properties and coerces types to satisfy schema
{
  const schema = Type.Object({
    id: Type.Number(),
    active: Type.Boolean({ default: true }),
    tags: Type.Array(Type.String(), { default: [] }),
  });

  const partial = { id: 42 };
  const casted = castValue(schema, partial);
  assert.strictEqual(casted.id, 42);
  assert.strictEqual(casted.active, true);
  assert.deepStrictEqual(casted.tags, []);
  assert.strictEqual(Value.Check(schema, casted), true);
}

// Contract 3: Value.Create generates minimum valid instances matching schema definitions
{
  const schema = Type.Object({
    id: Type.Number(),
    name: Type.String(),
    enabled: Type.Boolean({ default: false }),
    items: Type.Array(Type.String()),
  });

  const created = createValue(schema);
  assert.strictEqual(typeof created, 'object');
  assert.notStrictEqual(created, null);
  assert.strictEqual(typeof created.id, 'number');
  assert.strictEqual(typeof created.name, 'string');
  assert.strictEqual(created.enabled, false);
  assert.deepStrictEqual(created.items, []);
  assert.strictEqual(Value.Check(schema, created), true);
}

// Contract 4: Value.Convert coerces string representations of primitives into expected schema types
{
  const schema = Type.Object({
    port: Type.Number(),
    secure: Type.Boolean(),
  });

  const raw = { port: '8080', secure: 'true' };
  const converted = convertValue(schema, raw);
  assert.strictEqual(typeof converted.port, 'number');
  assert.strictEqual(converted.port, 8080);
  assert.strictEqual(typeof converted.secure, 'boolean');
  assert.strictEqual(converted.secure, true);
  assert.strictEqual(Value.Check(schema, converted), true);
}

// Contract 5: Value.Clone creates independent deep structural copies of objects and arrays
{
  const original = { id: 1, tags: ['alpha', 'beta'], meta: { nested: 100 } };
  const cloned = cloneValue(original);
  assert.deepStrictEqual(cloned, original);
  assert.notStrictEqual(cloned, original);
  assert.notStrictEqual(cloned.tags, original.tags);
  assert.notStrictEqual(cloned.meta, original.meta);

  cloned.tags.push('gamma');
  cloned.meta.nested = 200;
  assert.strictEqual(original.tags.length, 2);
  assert.strictEqual(original.meta.nested, 100);
}

// Contract 6: Value.Equal evaluates deep structural equality across objects and collections
{
  const a = { x: 1, list: [1, 2, 3] };
  const b = { x: 1, list: [1, 2, 3] };
  const c = { x: 1, list: [1, 2, 4] };
  assert.strictEqual(equalValues(a, b), true);
  assert.strictEqual(equalValues(a, c), false);
  assert.strictEqual(Value.Equal(a, b), true);
  assert.strictEqual(Value.Equal(a, c), false);
}

// Contract 7: Value.Diff and Value.Patch compute and apply structural delta changesets between objects
{
  const current = { id: 1, status: 'pending', count: 10 };
  const next = { id: 1, status: 'completed', count: 15, label: 'new' };
  const diff = diffValues(current, next);
  assert.ok(Array.isArray(diff));
  assert.ok(diff.length > 0);

  const patched = patchValue(current, diff);
  assert.deepStrictEqual(patched, next);
}

// Contract 8: Value.Mutate updates target object properties in-place to mirror source values
{
  const target = { id: 10, title: 'before', active: false };
  const source = { id: 10, title: 'after', active: true };
  const res = mutateValue(target, source);
  assert.strictEqual(res, target);
  assert.strictEqual(target.title, 'after');
  assert.strictEqual(target.active, true);
}

// Contract 9: Value.Errors returns detailed error objects with schema paths and messages for invalid data
{
  const schema = Type.Object({
    email: Type.String({ minLength: 3 }),
    age: Type.Number({ minimum: 18 }),
  });

  const invalid = { email: 'ab', age: 10 };
  const errors = getErrors(schema, invalid);
  assert.ok(Array.isArray(errors));
  assert.strictEqual(errors.length, 2);
  assert.ok(errors.some((e) => e.path === '/email'));
  assert.ok(errors.some((e) => e.path === '/age'));
}

// Contract 10: Value.Hash produces consistent 64-bit BigInt hash invariant to object key ordering
{
  const obj1 = { alpha: 'one', beta: 2, gamma: true };
  const obj2 = { gamma: true, beta: 2, alpha: 'one' };
  const hash1 = hashValue(obj1);
  const hash2 = hashValue(obj2);
  assert.strictEqual(typeof hash1, 'bigint');
  assert.strictEqual(typeof hash2, 'bigint');
  assert.strictEqual(hash1, hash2);
}

console.log('All Value contracts verified.');

オリジンシーダー

匿名