サンプル
zod 4.1.12: z
検証済みサンプル — npm zod 4.1.12: z. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: z.object validates structured schema with nested primitive…
sha256:8b25af574b39d2d2e49ad18ef57ac04ea78980ff32a57adcbfa4f72cbfa64716
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
MIT-0
実行証拠
宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。
- 証拠の基準
- 署名済みコントラクト合格
- 検証レシート
- 2
- ビルドした署名鍵
- 1
宣言された環境
linux 24 · ubuntu · glibc 2.39 x64 npm
検証実行環境
| 環境 | コントラクト | ステージ | 実行日 |
|---|---|---|---|
| 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-23 |
| 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-07 |
ケース
HOW- ゴール
- verify zod.z in pkg:npm/zod@4.1.12
- パッケージ
- シンボル
-
- zod.z
- 作成日
- 2026-08-23T05:38:36Z
コントラクト
- z.object validates structured schema with nested primitive validators and defaults
- z.string validates constraints including email and min length
- z.number validates integer and non-negative constraints
- z.enum validates allowed string literal choices and defaults
- z.coerce converts string input to typed numbers and booleans
- z.array validates lists of elements
- safeParse returns structured validation issues on invalid payload
ファイル
- PROMPT.md
- csx.json
- index.js
- package-lock.json
- package.json
- spec.json
- test/contract.js
ソース
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 zod.z in pkg:npm/zod@4.1.12
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/zod@4.1.12
Demonstrate these symbols/APIs:
- zod.z
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:9a770d701dbe0d4606a127538f05f507b6ba6e039254d1c022ed0cca3489b505","contract":["z.object validates structured schema with nested primitive validators and defaults","z.string validates constraints including email and min length","z.number validates integer and non-negative constraints","z.enum validates allowed string literal choices and defaults","z.coerce converts string input to typed numbers and booleans","z.array validates lists of elements","safeParse returns structured validation issues on invalid payload"],"goal":"verify zod.z in pkg:npm/zod@4.1.12","kind":"HOW","packages":["pkg:npm/zod@4.1.12"],"schemaVersion":1,"symbols":["zod.z"]},"contractCommand":["node","test/contract.js"],"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/zod@4.1.12"],"schemaVersion":1,"subject":"pkg:npm/zod@4.1.12","symbols":["zod.z"],"verifierAdapter":"node-typescript@1"}
const { z } = require('zod');
// Schema for user profiles demonstrating primitives, object, enum, defaults, and constraints
const userSchema = z.object({
id: z.string().min(1),
name: z.string().min(1),
age: z.number().int().nonnegative(),
email: z.string().email(),
role: z.enum(['admin', 'user', 'guest']).default('user'),
isActive: z.boolean().default(true),
tags: z.array(z.string()).default([]),
});
// Schema demonstrating coercion and range bounds
const configSchema = z.object({
port: z.coerce.number().int().min(1).max(65535),
host: z.string().min(1),
debug: z.coerce.boolean().default(false),
});
function parseUser(input) {
return userSchema.parse(input);
}
function safeParseUser(input) {
return userSchema.safeParse(input);
}
function parseConfig(input) {
return configSchema.parse(input);
}
function safeParseConfig(input) {
return configSchema.safeParse(input);
}
module.exports = {
z,
userSchema,
configSchema,
parseUser,
safeParseUser,
parseConfig,
safeParseConfig,
};
{
"name": "sample-zod",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-zod",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"zod": "4.1.12"
}
},
"node_modules/zod": {
"version": "4.1.12",
"resolved": "https://registry.npmjs.org/zod/-/zod-4.1.12.tgz",
"integrity": "sha512-JInaHOamG8pt5+Ey8kGmdcAcg3OL9reK8ltczgHTAwNhMys/6ThXHityHxVV2p3fkw/c+MAvBHFVYHFZDmjMCQ==",
"license": "MIT",
"funding": {
"url": "https://github.com/sponsors/colinhacks"
}
}
}
}
{
"name": "sample-zod",
"version": "1.0.0",
"private": true,
"description": "Clean-room verification sample for zod.z in zod",
"main": "index.js",
"scripts": {
"test": "node test/contract.js"
},
"license": "MIT-0",
"dependencies": {
"zod": "4.1.12"
}
}
{
"schemaVersion": 1,
"goal": "verify zod.z in pkg:npm/zod@4.1.12",
"kind": "HOW",
"packages": [
"pkg:npm/zod@4.1.12"
],
"symbols": [
"zod.z"
]
}
const assert = require('assert');
const {
z,
userSchema,
configSchema,
parseUser,
safeParseUser,
parseConfig,
safeParseConfig,
} = require('../index.js');
function runTests() {
// 1. z.object validates structured schema with nested primitive validators and defaults
{
const input = {
id: 'usr_123',
name: 'Alice',
age: 28,
email: 'alice@example.com',
};
const user = parseUser(input);
assert.strictEqual(user.id, 'usr_123');
assert.strictEqual(user.name, 'Alice');
assert.strictEqual(user.age, 28);
assert.strictEqual(user.email, 'alice@example.com');
assert.strictEqual(user.role, 'user', 'applies default role');
assert.strictEqual(user.isActive, true, 'applies default isActive');
assert.deepStrictEqual(user.tags, [], 'applies default empty tags array');
}
// 2. z.string validates constraints including email and min length
{
const invalidEmail = safeParseUser({
id: 'usr_123',
name: 'Alice',
age: 28,
email: 'not-a-valid-email',
});
assert.strictEqual(invalidEmail.success, false);
assert.ok(
invalidEmail.error.issues.some((issue) => issue.path.includes('email')),
'reports invalid email issue'
);
const emptyName = safeParseUser({
id: 'usr_123',
name: '',
age: 28,
email: 'alice@example.com',
});
assert.strictEqual(emptyName.success, false);
assert.ok(
emptyName.error.issues.some((issue) => issue.path.includes('name')),
'reports empty name issue'
);
}
// 3. z.number validates integer and non-negative constraints
{
const negativeAge = safeParseUser({
id: 'usr_123',
name: 'Alice',
age: -1,
email: 'alice@example.com',
});
assert.strictEqual(negativeAge.success, false);
assert.ok(
negativeAge.error.issues.some((issue) => issue.path.includes('age')),
'reports negative age issue'
);
const floatAge = safeParseUser({
id: 'usr_123',
name: 'Alice',
age: 28.5,
email: 'alice@example.com',
});
assert.strictEqual(floatAge.success, false);
assert.ok(
floatAge.error.issues.some((issue) => issue.path.includes('age')),
'reports non-integer age issue'
);
}
// 4. z.enum validates allowed string literal choices and defaults
{
const validRole = parseUser({
id: 'usr_456',
name: 'Bob',
age: 35,
email: 'bob@example.com',
role: 'admin',
});
assert.strictEqual(validRole.role, 'admin');
const invalidRole = safeParseUser({
id: 'usr_456',
name: 'Bob',
age: 35,
email: 'bob@example.com',
role: 'superadmin',
});
assert.strictEqual(invalidRole.success, false);
assert.ok(
invalidRole.error.issues.some((issue) => issue.path.includes('role')),
'reports invalid enum value issue'
);
}
// 5. z.coerce converts string input to typed numbers and booleans
{
const config = parseConfig({
port: '8080',
host: 'localhost',
debug: 'true',
});
assert.strictEqual(config.port, 8080);
assert.strictEqual(typeof config.port, 'number');
assert.strictEqual(config.host, 'localhost');
assert.strictEqual(config.debug, true);
assert.strictEqual(typeof config.debug, 'boolean');
const outOfRange = safeParseConfig({
port: '99999',
host: 'localhost',
});
assert.strictEqual(outOfRange.success, false);
assert.ok(
outOfRange.error.issues.some((issue) => issue.path.includes('port')),
'reports port out of range issue'
);
}
// 6. z.array validates lists of elements
{
const userWithTags = parseUser({
id: 'usr_789',
name: 'Charlie',
age: 22,
email: 'charlie@example.com',
tags: ['developer', 'tester'],
});
assert.deepStrictEqual(userWithTags.tags, ['developer', 'tester']);
const invalidTags = safeParseUser({
id: 'usr_789',
name: 'Charlie',
age: 22,
email: 'charlie@example.com',
tags: ['valid', 123],
});
assert.strictEqual(invalidTags.success, false);
}
// 7. safeParse returns structured validation issues on invalid payload
{
const res = safeParseUser({});
assert.strictEqual(res.success, false);
assert.ok(Array.isArray(res.error.issues));
assert.ok(res.error.issues.length >= 3, 'multiple missing field issues reported');
}
// 8. Direct access to zod.z exports
{
assert.strictEqual(typeof z.object, 'function');
assert.strictEqual(typeof z.string, 'function');
assert.strictEqual(typeof z.number, 'function');
assert.strictEqual(typeof z.boolean, 'function');
assert.strictEqual(typeof z.array, 'function');
assert.strictEqual(typeof z.enum, 'function');
assert.strictEqual(typeof z.coerce, 'object');
}
console.log('Contract tests passed successfully.');
}
runTests();
オリジンシーダー
匿名