CodeSampleX

샘플

@sinclair/typebox 0.27.12: Value.Check

검증된 샘플 — npm @sinclair/typebox 0.27.12: Value.Check. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: Value.Check returns true for primitive…

sha256:b1dded2400f09b0b4630ec0d4c358ea76da6602cb60029b7576e1804147629b9

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

케이스

HOW
목표
verify Value.Check in pkg:npm/%40sinclair/typebox@0.27.12
패키지
심벌
  • Value.Check
생성일
2026-09-02T14:30:39Z

컨트랙트

  1. Value.Check returns true for primitive values matching the schema and false for type mismatches
  2. Value.Check validates numeric constraints including minimum and maximum bounds
  3. Value.Check validates string constraints including minLength, maxLength, and regex patterns
  4. Value.Check returns true for object values having all required conforming properties
  5. Value.Check returns false for objects missing required properties or containing invalid property types
  6. Value.Check validates array elements and rejects non-array values or invalid elements
  7. Value.Check validates union types accepting values matching any branch and rejecting non-matching values
  8. Value.Check supports optional object properties permitting both omission and valid types
  9. Value.Check validates tuple types respecting fixed length and element-specific schemas

파일

  • 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 Value.Check 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:
  - Value.Check

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:29751d89ff307f4cbf0b935d34d24ce39edac44155f0a6aff9e2d18d4fde71bb","contract":["Value.Check returns true for primitive values matching the schema and false for type mismatches","Value.Check validates numeric constraints including minimum and maximum bounds","Value.Check validates string constraints including minLength, maxLength, and regex patterns","Value.Check returns true for object values having all required conforming properties","Value.Check returns false for objects missing required properties or containing invalid property types","Value.Check validates array elements and rejects non-array values or invalid elements","Value.Check validates union types accepting values matching any branch and rejecting non-matching values","Value.Check supports optional object properties permitting both omission and valid types","Value.Check validates tuple types respecting fixed length and element-specific schemas"],"goal":"verify Value.Check in pkg:npm/%40sinclair/typebox@0.27.12","kind":"HOW","packages":["pkg:npm/%40sinclair/typebox@0.27.12"],"schemaVersion":1,"symbols":["Value.Check"]},"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":["Value.Check"],"verifierAdapter":"node-typescript@1"}
index.mjs
import { Type } from '@sinclair/typebox';
import { Value } from '@sinclair/typebox/value';

/**
 * Validates a value against a TypeBox schema.
 *
 * @param {import('@sinclair/typebox').TSchema} schema - TypeBox schema
 * @param {unknown} value - Value to validate
 * @returns {boolean} True if the value satisfies the schema, false otherwise
 */
export function checkValue(schema, value) {
  return Value.Check(schema, value);
}

/**
 * Asserts that a value conforms to a TypeBox schema, throwing if invalid.
 *
 * @param {import('@sinclair/typebox').TSchema} schema - TypeBox schema
 * @param {unknown} value - Value to validate
 * @returns {boolean} True if valid
 * @throws {Error} When value does not conform to the schema
 */
export function assertValue(schema, value) {
  if (!Value.Check(schema, value)) {
    throw new Error('Value does not conform to schema');
  }
  return true;
}

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

// Contract 1: Value.Check returns true for primitive values matching the schema and false for type mismatches
{
  const strSchema = Type.String();
  assert.strictEqual(Value.Check(strSchema, 'hello'), true);
  assert.strictEqual(Value.Check(strSchema, ''), true);
  assert.strictEqual(Value.Check(strSchema, 123), false);
  assert.strictEqual(Value.Check(strSchema, null), false);
  assert.strictEqual(Value.Check(strSchema, undefined), false);

  const numSchema = Type.Number();
  assert.strictEqual(Value.Check(numSchema, 42), true);
  assert.strictEqual(Value.Check(numSchema, 3.14), true);
  assert.strictEqual(Value.Check(numSchema, '42'), false);
  assert.strictEqual(Value.Check(numSchema, NaN), false);

  const boolSchema = Type.Boolean();
  assert.strictEqual(Value.Check(boolSchema, true), true);
  assert.strictEqual(Value.Check(boolSchema, false), true);
  assert.strictEqual(Value.Check(boolSchema, 'true'), false);

  assert.strictEqual(checkValue(strSchema, 'test'), true);
  assert.strictEqual(checkValue(strSchema, 42), false);
}

// Contract 2: Value.Check validates numeric constraints including minimum and maximum bounds
{
  const portSchema = Type.Number({ minimum: 1024, maximum: 65535 });
  assert.strictEqual(Value.Check(portSchema, 1024), true);
  assert.strictEqual(Value.Check(portSchema, 8080), true);
  assert.strictEqual(Value.Check(portSchema, 65535), true);
  assert.strictEqual(Value.Check(portSchema, 1023), false);
  assert.strictEqual(Value.Check(portSchema, 65536), false);
}

// Contract 3: Value.Check validates string constraints including minLength, maxLength, and regex patterns
{
  const codeSchema = Type.String({ minLength: 3, maxLength: 6, pattern: '^[A-Z]+$' });
  assert.strictEqual(Value.Check(codeSchema, 'ABC'), true);
  assert.strictEqual(Value.Check(codeSchema, 'ABCDEF'), true);
  assert.strictEqual(Value.Check(codeSchema, 'AB'), false);
  assert.strictEqual(Value.Check(codeSchema, 'ABCDEFG'), false);
  assert.strictEqual(Value.Check(codeSchema, 'abc'), false);
}

// Contract 4: Value.Check returns true for object values having all required conforming properties
{
  const userSchema = Type.Object({
    id: Type.Number(),
    name: Type.String(),
    active: Type.Boolean(),
  });

  const validUser = { id: 1, name: 'Alice', active: true };
  assert.strictEqual(Value.Check(userSchema, validUser), true);
  assert.strictEqual(assertValue(userSchema, validUser), true);
}

// Contract 5: Value.Check returns false for objects missing required properties or containing invalid property types
{
  const userSchema = Type.Object({
    id: Type.Number(),
    name: Type.String(),
  });

  assert.strictEqual(Value.Check(userSchema, { id: 1 }), false);
  assert.strictEqual(Value.Check(userSchema, { name: 'Bob' }), false);
  assert.strictEqual(Value.Check(userSchema, { id: 'one', name: 'Bob' }), false);
  assert.strictEqual(Value.Check(userSchema, null), false);
  assert.strictEqual(Value.Check(userSchema, 'not-an-object'), false);

  assert.throws(() => assertValue(userSchema, { id: 'invalid' }), /Value does not conform to schema/);
}

// Contract 6: Value.Check validates array elements and rejects non-array values or invalid elements
{
  const tagsSchema = Type.Array(Type.String());
  assert.strictEqual(Value.Check(tagsSchema, ['a', 'b', 'c']), true);
  assert.strictEqual(Value.Check(tagsSchema, []), true);
  assert.strictEqual(Value.Check(tagsSchema, ['a', 123]), false);
  assert.strictEqual(Value.Check(tagsSchema, 'not-an-array'), false);
  assert.strictEqual(Value.Check(tagsSchema, null), false);
}

// Contract 7: Value.Check validates union types accepting values matching any branch and rejecting non-matching values
{
  const statusSchema = Type.Union([
    Type.Literal('pending'),
    Type.Literal('active'),
    Type.Literal('completed'),
  ]);

  assert.strictEqual(Value.Check(statusSchema, 'pending'), true);
  assert.strictEqual(Value.Check(statusSchema, 'active'), true);
  assert.strictEqual(Value.Check(statusSchema, 'completed'), true);
  assert.strictEqual(Value.Check(statusSchema, 'archived'), false);
  assert.strictEqual(Value.Check(statusSchema, 123), false);
}

// Contract 8: Value.Check supports optional object properties permitting both omission and valid types
{
  const profileSchema = Type.Object({
    username: Type.String(),
    bio: Type.Optional(Type.String()),
    age: Type.Optional(Type.Number()),
  });

  assert.strictEqual(Value.Check(profileSchema, { username: 'john' }), true);
  assert.strictEqual(Value.Check(profileSchema, { username: 'john', bio: 'Developer' }), true);
  assert.strictEqual(Value.Check(profileSchema, { username: 'john', bio: 'Developer', age: 30 }), true);
  assert.strictEqual(Value.Check(profileSchema, { username: 'john', bio: 123 }), false);
}

// Contract 9: Value.Check validates tuple types respecting fixed length and element-specific schemas
{
  const coordinateSchema = Type.Tuple([Type.Number(), Type.Number()]);

  assert.strictEqual(Value.Check(coordinateSchema, [10, 20]), true);
  assert.strictEqual(Value.Check(coordinateSchema, [10]), false);
  assert.strictEqual(Value.Check(coordinateSchema, [10, 20, 30]), false);
  assert.strictEqual(Value.Check(coordinateSchema, ['10', 20]), false);
}

console.log('All Value.Check contracts passed.');

오리진 시더

익명