CodeSampleX

サンプル

type-check 0.4.0: parseType

検証済みサンプル — npm type-check 0.4.0: parseType. node 22 · linux debian/x64 · docker で contract を実行し、成功しました: assert parseType parses primitive types (Number…

sha256:117a25b9d3ef3971b75d42238c52bc47e8d77bff90763f4412fbeaef82b3d457

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

実行証拠

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

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

検証実行環境

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

ケース

HOW
ゴール
verify type-check.parseType in pkg:npm/type-check@0.4.0
パッケージ
シンボル
  • type-check.parseType
環境
node 22.23.2
作成日
2026-09-05T16:50:10Z

コントラクト

  1. assert parseType parses primitive types (Number, String, Boolean) into type AST nodes
  2. assert parseType parses union types into multiple alternative type AST nodes
  3. assert parseType parses array structures '[Type]' and tuple structures '(Type1, Type2)'
  4. assert parseType parses object field records '{key: Type}' into fields structure AST nodes
  5. assert parseType throws an error on invalid type syntax

ファイル

  • 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 type-check.parseType in pkg:npm/type-check@0.4.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/type-check@0.4.0
Demonstrate these symbols/APIs:
  - type-check.parseType

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:296e6f9d11e98bf24240191321a55a8ca89df0928e37028f8cbe66691a409114","contract":["assert parseType parses primitive types (Number, String, Boolean) into type AST nodes","assert parseType parses union types into multiple alternative type AST nodes","assert parseType parses array structures '[Type]' and tuple structures '(Type1, Type2)'","assert parseType parses object field records '{key: Type}' into fields structure AST nodes","assert parseType throws an error on invalid type syntax"],"goal":"verify type-check.parseType in pkg:npm/type-check@0.4.0","kind":"HOW","packages":["pkg:npm/type-check@0.4.0"],"schemaVersion":1,"symbols":["type-check.parseType"]},"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","symbols":["type-check.parseType"],"verifierAdapter":"node-typescript@1"}
index.js
const { parseType } = require('type-check');

module.exports = {
  parseType,
};
package-lock.json
{
  "name": "sample-300142138",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-300142138",
      "version": "1.0.0",
      "license": "MIT-0",
      "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-300142138",
  "version": "1.0.0",
  "description": "verify type-check.parseType in pkg:npm/type-check@0.4.0",
  "main": "index.js",
  "scripts": {
    "test": "node test/contract.js"
  },
  "license": "MIT-0",
  "dependencies": {
    "type-check": "0.4.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify type-check.parseType in pkg:npm/type-check@0.4.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/type-check@0.4.0"
  ],
  "symbols": [
    "type-check.parseType"
  ]
}
test/contract.js
const assert = require('node:assert');
const { parseType } = require('type-check');

// 1. Parse primitive types
const numAst = parseType('Number');
assert.deepStrictEqual(numAst, [{ type: 'Number' }], 'Number type expression should parse to Number AST');

const strAst = parseType('String');
assert.deepStrictEqual(strAst, [{ type: 'String' }], 'String type expression should parse to String AST');

const boolAst = parseType('Boolean');
assert.deepStrictEqual(boolAst, [{ type: 'Boolean' }], 'Boolean type expression should parse to Boolean AST');

// 2. Parse union types
const unionAst = parseType('Number | String');
assert.deepStrictEqual(unionAst, [{ type: 'Number' }, { type: 'String' }], 'Union type expression should parse to multiple alternative AST nodes');

// 3. Parse array and tuple structures
const arrayAst = parseType('[Number]');
assert.deepStrictEqual(arrayAst, [
  {
    structure: 'array',
    of: [{ type: 'Number' }],
  },
], 'Array type expression should parse to array structure AST');

const tupleAst = parseType('(String, Number)');
assert.deepStrictEqual(tupleAst, [
  {
    structure: 'tuple',
    of: [[{ type: 'String' }], [{ type: 'Number' }]],
  },
], 'Tuple type expression should parse to tuple structure AST');

// 4. Parse object field records
const fieldsAst = parseType('{a: Number, b: String}');
assert.deepStrictEqual(fieldsAst, [
  {
    structure: 'fields',
    of: {
      a: [{ type: 'Number' }],
      b: [{ type: 'String' }],
    },
    subset: false,
  },
], 'Object record type expression should parse to fields structure AST');

// 5. Throws on unexpected character or malformed syntax
assert.throws(
  () => parseType('!'),
  /Unexpected character/,
  'Invalid type expression syntax should throw an Error'
);

console.log('All contract assertions for parseType passed successfully.');

オリジンシーダー

匿名