サンプル
@sinclair/typebox 0.27.8: Value.Create
検証済みサンプル — npm @sinclair/typebox 0.27.8: Value.Create. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: Value.Create creates default primitive…
sha256:10ce99149d7007b74ebb53da43f8dc1cca808d0f56eb38ce162867dd333db42b
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。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 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-30 |
ケース
HOW- ゴール
- verify Value.Create in pkg:npm/%40sinclair/typebox@0.27.8
- パッケージ
- シンボル
-
- Value.Create
- 環境
- node 22.23.2
- 作成日
- 2026-08-30T13:12:55Z
コントラクト
- Value.Create creates default primitive values for string, number, and boolean schemas
- Value.Create populates schema defaults when default values are explicitly specified
- Value.Create constructs valid default objects with required properties according to schema definitions
- Value.Create generates default values for array, tuple, and record schemas
- Value.Create resolves union and literal schemas to their expected initial values
- Value.Create produces values that satisfy Value.Check validation against the corresponding schema
ファイル
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.mjs
ソース
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.Create in pkg:npm/%40sinclair/typebox@0.27.8
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/%40sinclair/typebox@0.27.8
Demonstrate these symbols/APIs:
- Value.Create
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.
{"case":{"caseId":"case:sha256:e9bdadc00ea27dce59543e75eeccf05ef704888da6fb171947cc6b6f19034999","contract":["Value.Create creates default primitive values for string, number, and boolean schemas","Value.Create populates schema defaults when default values are explicitly specified","Value.Create constructs valid default objects with required properties according to schema definitions","Value.Create generates default values for array, tuple, and record schemas","Value.Create resolves union and literal schemas to their expected initial values","Value.Create produces values that satisfy Value.Check validation against the corresponding schema"],"goal":"verify Value.Create in pkg:npm/%40sinclair/typebox@0.27.8","kind":"HOW","packages":["pkg:npm/%40sinclair/typebox@0.27.8"],"schemaVersion":1,"symbols":["Value.Create"]},"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.8"],"schemaVersion":1,"subject":"pkg:npm/%40sinclair/typebox@0.27.8","symbols":["Value.Create"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-typebox-value-create",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-typebox-value-create",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"@sinclair/typebox": "0.27.8"
}
},
"node_modules/@sinclair/typebox": {
"version": "0.27.8",
"resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.27.8.tgz",
"integrity": "sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA==",
"license": "MIT"
}
}
}
{
"name": "sample-typebox-value-create",
"version": "1.0.0",
"private": true,
"description": "verify Value.Create in pkg:npm/%40sinclair/typebox@0.27.8",
"main": "src/index.js",
"license": "MIT-0",
"dependencies": {
"@sinclair/typebox": "0.27.8"
}
}
{
"schemaVersion": 1,
"goal": "verify Value.Create in pkg:npm/%40sinclair/typebox@0.27.8",
"kind": "HOW",
"packages": [
"pkg:npm/%40sinclair/typebox@0.27.8"
],
"symbols": [
"Value.Create"
]
}
'use strict';
const { Type } = require('@sinclair/typebox');
const { Value } = require('@sinclair/typebox/value');
/**
* Creates default values directly from any TypeBox schema.
*
* @param {object} schema - TypeBox schema
* @returns {*} Default instance conforming to the schema
*/
function createDefaultValue(schema) {
return Value.Create(schema);
}
/**
* Builds a user schema with explicit defaults and generates an initial instance.
*
* @returns {{ schema: object, value: object }} Schema and generated default value
*/
function createUserWithDefaults() {
const schema = Type.Object({
id: Type.Number({ default: 1001 }),
username: Type.String({ default: 'guest' }),
roles: Type.Array(Type.String(), { default: ['viewer'] }),
isActive: Type.Boolean({ default: true })
});
const value = Value.Create(schema);
return { schema, value };
}
/**
* Builds a config schema using primitive types and generates an initial instance.
*
* @returns {{ schema: object, value: object }} Schema and generated default value
*/
function createDefaultConfig() {
const schema = Type.Object({
host: Type.String(),
port: Type.Number(),
ssl: Type.Boolean()
});
const value = Value.Create(schema);
return { schema, value };
}
module.exports = {
Type,
Value,
createDefaultValue,
createUserWithDefaults,
createDefaultConfig
};
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const {
Type,
Value,
createDefaultValue,
createUserWithDefaults,
createDefaultConfig
} = require('../src/index.js');
const tbValue = require('@sinclair/typebox/value');
// 0. Export verification
assert.equal(typeof Value, 'object', 'Value must be exported as an object');
assert.equal(typeof Value.Create, 'function', 'Value.Create must be a function');
assert.equal(Value.Create, tbValue.Value.Create, 'Value.Create must match package export');
assert.equal(typeof createDefaultValue, 'function', 'createDefaultValue helper must be a function');
// 1. Value.Create creates default primitive values for string, number, and boolean schemas
{
const stringDefault = createDefaultValue(Type.String());
assert.equal(stringDefault, '', 'String schema without default should create empty string');
const numberDefault = createDefaultValue(Type.Number());
assert.equal(numberDefault, 0, 'Number schema without default should create 0');
const booleanDefault = createDefaultValue(Type.Boolean());
assert.equal(booleanDefault, false, 'Boolean schema without default should create false');
}
// 2. Value.Create populates schema defaults when default values are explicitly specified
{
const customString = createDefaultValue(Type.String({ default: 'custom-text' }));
assert.equal(customString, 'custom-text', 'String schema should populate custom default');
const customNumber = createDefaultValue(Type.Number({ default: 42 }));
assert.equal(customNumber, 42, 'Number schema should populate custom default');
const customBool = createDefaultValue(Type.Boolean({ default: true }));
assert.equal(customBool, true, 'Boolean schema should populate custom default');
const user = createUserWithDefaults();
assert.equal(user.value.id, 1001, 'Object property id should use schema default');
assert.equal(user.value.username, 'guest', 'Object property username should use schema default');
assert.deepEqual(user.value.roles, ['viewer'], 'Object property roles should use schema default array');
assert.equal(user.value.isActive, true, 'Object property isActive should use schema default');
}
// 3. Value.Create constructs valid default objects with required properties according to schema definitions
{
const config = createDefaultConfig();
assert.equal(typeof config.value, 'object', 'Created config should be an object');
assert.equal(config.value.host, '', 'Config host property should default to empty string');
assert.equal(config.value.port, 0, 'Config port property should default to 0');
assert.equal(config.value.ssl, false, 'Config ssl property should default to false');
const nestedSchema = Type.Object({
meta: Type.Object({
version: Type.String({ default: '1.0.0' }),
code: Type.Number({ default: 200 })
}),
data: Type.Object({
active: Type.Boolean()
})
});
const nestedValue = createDefaultValue(nestedSchema);
assert.deepEqual(nestedValue, {
meta: { version: '1.0.0', code: 200 },
data: { active: false }
}, 'Nested object schemas should recursively create default properties');
}
// 4. Value.Create generates default values for array, tuple, and record schemas
{
const arrayVal = createDefaultValue(Type.Array(Type.String()));
assert.deepEqual(arrayVal, [], 'Array schema without default should create empty array');
const tupleVal = createDefaultValue(Type.Tuple([Type.String({ default: 'tag' }), Type.Number({ default: 1 })]));
assert.deepEqual(tupleVal, ['tag', 1], 'Tuple schema should create array with elements instantiated from element schemas');
const recordVal = createDefaultValue(Type.Record(Type.String(), Type.Number()));
assert.deepEqual(recordVal, {}, 'Record schema should create empty object');
}
// 5. Value.Create resolves union and literal schemas to their expected initial values
{
const literalVal = createDefaultValue(Type.Literal('standard'));
assert.equal(literalVal, 'standard', 'Literal schema should create literal value');
const unionVal = createDefaultValue(Type.Union([
Type.Literal('alpha'),
Type.Literal('beta'),
Type.Literal('gamma')
]));
assert.equal(unionVal, 'alpha', 'Union schema should resolve to default value of first variant');
const unionWithTypes = createDefaultValue(Type.Union([
Type.Number({ default: 100 }),
Type.String({ default: 'fallback' })
]));
assert.equal(unionWithTypes, 100, 'Union schema should instantiate first variant with its default');
}
// 6. Value.Create produces values that satisfy Value.Check validation against the corresponding schema
{
const schemas = [
Type.String(),
Type.Number(),
Type.Boolean(),
Type.Literal('exact'),
Type.Union([Type.String(), Type.Number()]),
Type.Array(Type.Number()),
Type.Tuple([Type.String(), Type.Number()]),
Type.Object({
id: Type.Number({ default: 1 }),
name: Type.String({ default: 'item' })
})
];
for (const schema of schemas) {
const created = Value.Create(schema);
const valid = Value.Check(schema, created);
assert.equal(valid, true, `Created value ${JSON.stringify(created)} must satisfy Value.Check`);
}
}
console.log('Contract assertions passed.');
オリジンシーダー
匿名