CodeSampleX

샘플

type-check 0.4.0

검증된 샘플 — npm type-check 0.4.0. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: assert typeCheck validates primitive types (Number, String…

sha256:555784bd56fc8718906a8e66847e2bf2a5f2db83af0407deb77a23a0902c087c

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

케이스

HOW
목표
verify pkg:npm/type-check@0.4.0
패키지
환경
node 22.23.2
생성일
2026-08-28T02:23:56Z

컨트랙트

  1. assert typeCheck validates primitive types (Number, String, Boolean, Undefined, Null, Array, Object, RegExp) and rejects mismatched types
  2. assert typeCheck supports union types separated by '|', comment syntax 'label::Type', and wildcard '*'
  3. assert typeCheck validates homogeneous arrays '[Type]' and heterogeneous fixed-length tuples '(Type1, Type2)'
  4. assert typeCheck validates closed object records '{key: Type}', optional fields with 'Maybe', and open records with '...'
  5. assert parseType compiles type expressions into AST objects and parsedTypeCheck evaluates inputs against pre-compiled ASTs
  6. assert typeCheck validates custom type specifications via customTypes option with typeOf and validate functions

파일

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

소스 아티팩트 내려받기 (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/type-check@0.4.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/type-check@0.4.0
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:856d91ecbc8583c4fd8b6b99d859bdc82dee077479a5bd7f7ac0d3b1793a3a32","constraints":{"executionContext":"node"},"contract":["assert typeCheck validates primitive types (Number, String, Boolean, Undefined, Null, Array, Object, RegExp) and rejects mismatched types","assert typeCheck supports union types separated by '|', comment syntax 'label::Type', and wildcard '*'","assert typeCheck validates homogeneous arrays '[Type]' and heterogeneous fixed-length tuples '(Type1, Type2)'","assert typeCheck validates closed object records '{key: Type}', optional fields with 'Maybe', and open records with '...'","assert parseType compiles type expressions into AST objects and parsedTypeCheck evaluates inputs against pre-compiled ASTs","assert typeCheck validates custom type specifications via customTypes option with typeOf and validate functions"],"goal":"verify pkg:npm/type-check@0.4.0","kind":"HOW","packages":["pkg:npm/type-check@0.4.0"],"schemaVersion":1,"symbols":["parseType","parsedTypeCheck","typeCheck"]},"contractCommand":["node","test/contract.js"],"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/type-check@0.4.0"],"schemaVersion":1,"subject":"pkg:npm/type-check@0.4.0","verifierAdapter":"node-typescript@1"}
index.js
const { typeCheck, parseType, parsedTypeCheck, VERSION } = require('type-check');

module.exports = {
  typeCheck,
  parseType,
  parsedTypeCheck,
  VERSION,
};
package-lock.json
{
  "name": "sample-537348838",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-537348838",
      "version": "1.0.0",
      "license": "ISC",
      "dependencies": {
        "type-check": "0.4.0"
      }
    },
    "node_modules/prelude-ls": {
      "version": "1.2.1",
      "resolved": "https://registry.npmjs.org/prelude-ls/-/prelude-ls-1.2.1.tgz",
      "integrity": "sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==",
      "license": "MIT",
      "engines": {
        "node": ">= 0.8.0"
      }
    },
    "node_modules/type-check": {
      "version": "0.4.0",
      "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz",
      "integrity": "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==",
      "license": "MIT",
      "dependencies": {
        "prelude-ls": "^1.2.1"
      },
      "engines": {
        "node": ">= 0.8.0"
      }
    }
  }
}
package.json
{
  "name": "sample-537348838",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "type-check": "0.4.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/type-check@0.4.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/type-check@0.4.0"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.js
const assert = require('node:assert');
const { typeCheck, parseType, parsedTypeCheck, VERSION } = require('type-check');

// 1. Version check
assert.strictEqual(VERSION, '0.4.0', 'VERSION should match 0.4.0');

// 2. Primitive types and basic validation
assert.strictEqual(typeCheck('Number', 42), true, 'Number should match integer 42');
assert.strictEqual(typeCheck('Number', 3.14), true, 'Number should match float 3.14');
assert.strictEqual(typeCheck('Number', '42'), false, 'Number should reject string "42"');
assert.strictEqual(typeCheck('String', 'hello'), true, 'String should match string');
assert.strictEqual(typeCheck('Boolean', false), true, 'Boolean should match boolean');
assert.strictEqual(typeCheck('Undefined', undefined), true, 'Undefined should match undefined');
assert.strictEqual(typeCheck('Null', null), true, 'Null should match null');
assert.strictEqual(typeCheck('Array', [1, 2, 3]), true, 'Array should match array');
assert.strictEqual(typeCheck('Object', { key: 'val' }), true, 'Object should match object');
assert.strictEqual(typeCheck('RegExp', /abc/), true, 'RegExp should match regular expression');

// 3. Union types, comments, and wildcard
assert.strictEqual(typeCheck('Number | String', 10), true, 'Union should match Number');
assert.strictEqual(typeCheck('Number | String', 'text'), true, 'Union should match String');
assert.strictEqual(typeCheck('Number | String', true), false, 'Union should reject Boolean');
assert.strictEqual(typeCheck('count::Number', 5), true, 'Comment syntax should be ignored and pass validation');
assert.strictEqual(typeCheck('*', { any: 'value' }), true, 'Wildcard should match any object');
assert.strictEqual(typeCheck('*', 123), true, 'Wildcard should match any primitive');

// 4. Array and Tuple structures
assert.strictEqual(typeCheck('[Number]', [1, 2, 3]), true, 'Homogeneous array [Number] should pass');
assert.strictEqual(typeCheck('[Number]', [1, '2', 3]), false, 'Homogeneous array [Number] should fail with mixed types');
assert.strictEqual(typeCheck('(String, Number)', ['alice', 30]), true, 'Tuple (String, Number) should match 2 elements');
assert.strictEqual(typeCheck('(String, Number)', ['alice']), false, 'Tuple should fail on missing elements');
assert.strictEqual(typeCheck('(String, Number)', ['alice', 30, true]), false, 'Tuple should fail on extra elements');

// 5. Object structures, optional fields (Maybe), and open records (...)
assert.strictEqual(typeCheck('{x: Number, y: Boolean}', { x: 1, y: true }), true, 'Exact object fields should match');
assert.strictEqual(typeCheck('{x: Number, y: Boolean}', { x: 1 }), false, 'Missing non-maybe field should fail');
assert.strictEqual(typeCheck('{x: Number, y: Maybe Boolean}', { x: 1 }), true, 'Missing maybe field should pass');
assert.strictEqual(typeCheck('{x: Number, y: Maybe Boolean}', { x: 1, y: null }), true, 'Null maybe field should pass');
assert.strictEqual(typeCheck('{x: Number}', { x: 1, z: 99 }), false, 'Closed object should reject extraneous fields');
assert.strictEqual(typeCheck('{x: Number, ...}', { x: 1, z: 99 }), true, 'Open record (...) should accept extraneous fields');

// 6. Pre-parsed type validation via parseType and parsedTypeCheck
const parsedAST = parseType('{id: Number, tags: [String]}');
assert.ok(Array.isArray(parsedAST), 'parseType returns AST structure');
assert.strictEqual(parsedTypeCheck(parsedAST, { id: 101, tags: ['node', 'npm'] }), true, 'parsedTypeCheck passes valid input');
assert.strictEqual(parsedTypeCheck(parsedAST, { id: 101, tags: [1, 2] }), false, 'parsedTypeCheck rejects invalid tag types');

// 7. Custom types validation
const options = {
  customTypes: {
    Even: {
      typeOf: 'Number',
      validate: (x) => x % 2 === 0,
    },
  },
};
assert.strictEqual(typeCheck('Even', 4, options), true, 'Custom type Even matches 4');
assert.strictEqual(typeCheck('Even', 5, options), false, 'Custom type Even rejects 5');
assert.strictEqual(typeCheck('Even', '4', options), false, 'Custom type Even rejects non-Number');

console.log('All contract tests passed successfully.');

오리진 시더

익명