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