示例
@eslint/object-schema 2.1.7: ObjectSchema
已验证示例 — npm @eslint/object-schema 2.1.7: ObjectSchema. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: ObjectSchema validates object properties…
sha256:5af35377f5507a61cd10ccb268c556f0d656dcefcf126539981a838e1b8af6a9
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 1
- 构建过它的签名密钥
- 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-28 |
案例
HOW- 目标
- verify pkg:npm/%40eslint/object-schema@2.1.7
- 符号
-
- ObjectSchema
- 创建时间
- 2026-08-28T05:27:34Z
契约
- ObjectSchema validates object properties against built-in validation strategies and throws errors on unexpected keys, missing required keys, or invalid types
- ObjectSchema enforces dependent property requirements specified by the requires array
- ObjectSchema supports custom validation and merge functions and ignores key updates when merge strategy returns undefined
- ObjectSchema merges multiple objects using built-in merge strategies assign, overwrite, and replace
- ValidationStrategy and MergeStrategy static methods correctly validate primitive and complex types and execute merge algorithms
文件
- PROMPT.md
- csx.json
- index.mjs
- package-lock.json
- package.json
- spec.json
- 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 pkg:npm/%40eslint/object-schema@2.1.7
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/%40eslint/object-schema@2.1.7
Demonstrate these symbols/APIs:
- ObjectSchema
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:f2439122b2c596193cedc713cadd304f39015311aa9e92050043f3d7d7867dfb","contract":["ObjectSchema validates object properties against built-in validation strategies and throws errors on unexpected keys, missing required keys, or invalid types","ObjectSchema enforces dependent property requirements specified by the requires array","ObjectSchema supports custom validation and merge functions and ignores key updates when merge strategy returns undefined","ObjectSchema merges multiple objects using built-in merge strategies assign, overwrite, and replace","ValidationStrategy and MergeStrategy static methods correctly validate primitive and complex types and execute merge algorithms"],"goal":"verify pkg:npm/%40eslint/object-schema@2.1.7","kind":"HOW","packages":["pkg:npm/%40eslint/object-schema@2.1.7"],"schemaVersion":1,"symbols":["ObjectSchema"]},"contractCommand":["node","test/contract.mjs"],"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/%40eslint/object-schema@2.1.7"],"schemaVersion":1,"subject":"pkg:npm/%40eslint/object-schema@2.1.7","symbols":["ObjectSchema"],"verifierAdapter":"node-typescript@1"}
import { ObjectSchema, ValidationStrategy, MergeStrategy } from "@eslint/object-schema";
export function createConfigSchema(definitions) {
return new ObjectSchema(definitions);
}
export { ObjectSchema, ValidationStrategy, MergeStrategy };
{
"name": "sample-eslint-object-schema",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-eslint-object-schema",
"version": "1.0.0",
"dependencies": {
"@eslint/object-schema": "2.1.7"
}
},
"node_modules/@eslint/object-schema": {
"version": "2.1.7",
"resolved": "https://registry.npmjs.org/@eslint/object-schema/-/object-schema-2.1.7.tgz",
"integrity": "sha512-VtAOaymWVfZcmZbp6E2mympDIHvyjXs/12LqWYjVw6qjrfF+VK+fyG33kChz3nnK+SU5/NeHOqrTEHS8sXO3OA==",
"license": "Apache-2.0",
"engines": {
"node": "^18.18.0 || ^20.9.0 || >=21.1.0"
}
}
}
}
{
"name": "sample-eslint-object-schema",
"version": "1.0.0",
"private": true,
"type": "module",
"scripts": {
"test": "node test/contract.mjs"
},
"dependencies": {
"@eslint/object-schema": "2.1.7"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/%40eslint/object-schema@2.1.7",
"kind": "HOW",
"packages": [
"pkg:npm/%40eslint/object-schema@2.1.7"
],
"symbols": [
"ObjectSchema"
]
}
import assert from "node:assert/strict";
import { ObjectSchema, ValidationStrategy, MergeStrategy } from "@eslint/object-schema";
// 1. ObjectSchema validates object properties against built-in validation strategies and throws errors on unexpected keys, missing required keys, or invalid types
const schema = new ObjectSchema({
id: {
required: true,
merge: "replace",
validate: "number"
},
name: {
required: true,
merge: "overwrite",
validate: "string!"
},
tag: {
required: false,
merge: "overwrite",
validate: "string"
},
flags: {
required: false,
merge: "assign",
validate: "object"
},
items: {
required: false,
merge: "overwrite",
validate: "array"
},
metadata: {
required: false,
merge: "replace",
validate: "object?"
},
enabled: {
required: false,
merge: "overwrite",
validate: "boolean"
},
secret: {
required: false,
requires: ["id"],
merge: "overwrite",
validate: "string"
},
custom: {
required: false,
merge(target, source) {
if (source === "ignore") return undefined;
if (target === undefined) return source;
return `${target}:${source}`;
},
validate(value) {
if (typeof value !== "string" || !value.startsWith("valid_")) {
throw new TypeError("custom must start with valid_");
}
}
},
nested: {
required: false,
merge: "assign",
validate: "object",
schema: {
subKey: {
required: false,
merge: "overwrite",
validate: "string"
}
}
}
});
// hasKey checks
assert.equal(schema.hasKey("id"), true);
assert.equal(schema.hasKey("name"), true);
assert.equal(schema.hasKey("nonexistent"), false);
// Valid object validation
assert.doesNotThrow(() => {
schema.validate({
id: 1,
name: "test-object",
tag: "v1",
flags: { a: 1 },
items: [1, 2, 3],
metadata: null,
enabled: true,
secret: "secret-key",
custom: "valid_value",
nested: {
subKey: "sub-value"
}
});
});
// Errors on unexpected keys
assert.throws(() => {
schema.validate({
id: 1,
name: "test-object",
unexpectedProperty: "bad"
});
}, /unexpected/i);
// Errors on missing required keys
assert.throws(() => {
schema.validate({
id: 1
});
}, /Missing required key/i);
// Errors on invalid types
assert.throws(() => {
schema.validate({
id: "not-a-number",
name: "test-object"
});
}, /Expected a number/i);
// Empty string for string! fails
assert.throws(() => {
schema.validate({
id: 1,
name: ""
});
}, /Expected a non-empty string/i);
// 2. ObjectSchema enforces dependent property requirements specified by the requires array
assert.throws(() => {
schema.validate({
name: "test-object",
secret: "secret-key"
});
}, /requires/i);
// 3. ObjectSchema supports custom validation and merge functions and ignores key updates when merge strategy returns undefined
assert.throws(() => {
schema.validate({
id: 1,
name: "test-object",
custom: "invalid_value"
});
}, /custom must start with valid_/);
const mergeSchema = new ObjectSchema({
key: {
required: false,
merge(first, second) {
if (second === "ignore") {
return undefined;
}
return second;
},
validate: "string"
}
});
const m1 = mergeSchema.merge({ key: "val" }, { key: "ignore" });
assert.equal(m1.key, "val");
// 4. ObjectSchema merges multiple objects using built-in merge strategies assign, overwrite, and replace
const obj1 = {
id: 10,
name: "initial",
flags: { x: 1 },
custom: "valid_a",
nested: { subKey: "initial-sub" }
};
const obj2 = {
id: 20,
name: "updated",
flags: { y: 2 },
custom: "valid_b",
tag: "tag2",
nested: { subKey: "updated-sub" }
};
const merged = schema.merge(obj1, obj2);
assert.equal(merged.id, 20);
assert.equal(merged.name, "updated");
assert.deepEqual(merged.flags, { x: 1, y: 2 });
assert.equal(merged.custom, "valid_a:valid_b");
assert.equal(merged.tag, "tag2");
assert.deepEqual(merged.nested, { subKey: "updated-sub" });
// 5. ValidationStrategy and MergeStrategy static methods correctly validate primitive and complex types and execute merge algorithms
assert.doesNotThrow(() => ValidationStrategy.array([]));
assert.doesNotThrow(() => ValidationStrategy.boolean(true));
assert.doesNotThrow(() => ValidationStrategy.number(42));
assert.doesNotThrow(() => ValidationStrategy.object({}));
assert.doesNotThrow(() => ValidationStrategy["object?"](null));
assert.doesNotThrow(() => ValidationStrategy["object?"]({}));
assert.doesNotThrow(() => ValidationStrategy.string("hello"));
assert.doesNotThrow(() => ValidationStrategy["string!"]("hello"));
assert.throws(() => ValidationStrategy.array("not-array"), TypeError);
assert.throws(() => ValidationStrategy.boolean(0), TypeError);
assert.throws(() => ValidationStrategy.number("42"), TypeError);
assert.throws(() => ValidationStrategy.object(null), TypeError);
assert.throws(() => ValidationStrategy.string(123), TypeError);
assert.throws(() => ValidationStrategy["string!"](""), TypeError);
assert.equal(MergeStrategy.overwrite("a", "b"), "b");
assert.equal(MergeStrategy.replace("a", undefined), "a");
assert.equal(MergeStrategy.replace("a", "b"), "b");
assert.deepEqual(MergeStrategy.assign({ a: 1 }, { b: 2 }), { a: 1, b: 2 });
console.log("Contract verified successfully.");
原始种子者
匿名