CodeSampleX

샘플

@eslint/object-schema 2.1.7: ValidationStrategy

검증된 샘플 — npm @eslint/object-schema 2.1.7: ValidationStrategy. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: ValidationStrategy.array accepts…

sha256:a0d51f87ded934cf16d025da99fc82fad59c8ecd76eb5e9275f586b345208d66

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

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 linux 24 · ubuntu · glibc 2.39 x64 npm

검증 실행 환경

환경 컨트랙트 단계 실행일
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-06

케이스

HOW
목표
verify @eslint/object-schema.ValidationStrategy in pkg:npm/%40eslint/object-schema@2.1.7
패키지
심벌
  • @eslint/object-schema.ValidationStrategy
생성일
2026-09-06T10:55:07Z

컨트랙트

  1. ValidationStrategy.array accepts arrays and throws TypeError for non-arrays
  2. ValidationStrategy.boolean accepts booleans and throws TypeError for non-booleans
  3. ValidationStrategy.number accepts numbers and throws TypeError for non-numbers
  4. ValidationStrategy.object accepts non-null objects and throws TypeError for null or non-objects
  5. ValidationStrategy['object?'] accepts null and objects and throws TypeError for non-objects
  6. ValidationStrategy.string accepts strings including empty strings and throws TypeError for non-strings
  7. ValidationStrategy['string!'] accepts non-empty strings and throws TypeError for empty strings or non-strings
  8. ObjectSchema integrates ValidationStrategy validators to validate object properties and wrap validation errors

파일

  • PROMPT.md
  • csx.json
  • index.mjs
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.mjs

소스 아티팩트 내려받기 (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 @eslint/object-schema.ValidationStrategy in 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:
  - @eslint/object-schema.ValidationStrategy

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:db872ccefa6faf04c75d136bc218c74d71a3484c2904339f58be580583ba50f1","contract":["ValidationStrategy.array accepts arrays and throws TypeError for non-arrays","ValidationStrategy.boolean accepts booleans and throws TypeError for non-booleans","ValidationStrategy.number accepts numbers and throws TypeError for non-numbers","ValidationStrategy.object accepts non-null objects and throws TypeError for null or non-objects","ValidationStrategy['object?'] accepts null and objects and throws TypeError for non-objects","ValidationStrategy.string accepts strings including empty strings and throws TypeError for non-strings","ValidationStrategy['string!'] accepts non-empty strings and throws TypeError for empty strings or non-strings","ObjectSchema integrates ValidationStrategy validators to validate object properties and wrap validation errors"],"goal":"verify @eslint/object-schema.ValidationStrategy in pkg:npm/%40eslint/object-schema@2.1.7","kind":"HOW","packages":["pkg:npm/%40eslint/object-schema@2.1.7"],"schemaVersion":1,"symbols":["@eslint/object-schema.ValidationStrategy"]},"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":["@eslint/object-schema.ValidationStrategy"],"verifierAdapter":"node-typescript@1"}
index.mjs
import { ValidationStrategy, ObjectSchema } from "@eslint/object-schema";

export function validateValue(strategy, value) {
  if (typeof ValidationStrategy[strategy] === "function") {
    ValidationStrategy[strategy](value);
    return true;
  }
  throw new TypeError(`Unknown validation strategy: ${strategy}`);
}

export { ValidationStrategy, ObjectSchema };
package-lock.json
{
  "name": "sample-eslint-validation-strategy",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-eslint-validation-strategy",
      "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"
      }
    }
  }
}
package.json
{
  "name": "sample-eslint-validation-strategy",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "scripts": {
    "test": "node test/contract.mjs"
  },
  "dependencies": {
    "@eslint/object-schema": "2.1.7"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @eslint/object-schema.ValidationStrategy in pkg:npm/%40eslint/object-schema@2.1.7",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40eslint/object-schema@2.1.7"
  ],
  "symbols": [
    "@eslint/object-schema.ValidationStrategy"
  ]
}
test/contract.mjs
import assert from "node:assert/strict";
import { ValidationStrategy, ObjectSchema } from "@eslint/object-schema";

// 1. ValidationStrategy.array accepts arrays and throws TypeError for non-arrays
assert.doesNotThrow(() => ValidationStrategy.array([]));
assert.doesNotThrow(() => ValidationStrategy.array([1, "two", {}]));
assert.throws(() => ValidationStrategy.array(null), /^TypeError: Expected an array\.$/);
assert.throws(() => ValidationStrategy.array(undefined), /^TypeError: Expected an array\.$/);
assert.throws(() => ValidationStrategy.array("not an array"), /^TypeError: Expected an array\.$/);
assert.throws(() => ValidationStrategy.array({ length: 0 }), /^TypeError: Expected an array\.$/);
assert.throws(() => ValidationStrategy.array(123), /^TypeError: Expected an array\.$/);

// 2. ValidationStrategy.boolean accepts booleans and throws TypeError for non-booleans
assert.doesNotThrow(() => ValidationStrategy.boolean(true));
assert.doesNotThrow(() => ValidationStrategy.boolean(false));
assert.throws(() => ValidationStrategy.boolean(1), /^TypeError: Expected a Boolean\.$/);
assert.throws(() => ValidationStrategy.boolean(0), /^TypeError: Expected a Boolean\.$/);
assert.throws(() => ValidationStrategy.boolean("true"), /^TypeError: Expected a Boolean\.$/);
assert.throws(() => ValidationStrategy.boolean(null), /^TypeError: Expected a Boolean\.$/);
assert.throws(() => ValidationStrategy.boolean(undefined), /^TypeError: Expected a Boolean\.$/);

// 3. ValidationStrategy.number accepts numbers and throws TypeError for non-numbers
assert.doesNotThrow(() => ValidationStrategy.number(0));
assert.doesNotThrow(() => ValidationStrategy.number(-42.5));
assert.doesNotThrow(() => ValidationStrategy.number(NaN));
assert.doesNotThrow(() => ValidationStrategy.number(Infinity));
assert.throws(() => ValidationStrategy.number("42"), /^TypeError: Expected a number\.$/);
assert.throws(() => ValidationStrategy.number(null), /^TypeError: Expected a number\.$/);
assert.throws(() => ValidationStrategy.number(undefined), /^TypeError: Expected a number\.$/);
assert.throws(() => ValidationStrategy.number(true), /^TypeError: Expected a number\.$/);

// 4. ValidationStrategy.object accepts non-null objects and throws TypeError for null or non-objects
assert.doesNotThrow(() => ValidationStrategy.object({}));
assert.doesNotThrow(() => ValidationStrategy.object({ a: 1 }));
assert.doesNotThrow(() => ValidationStrategy.object(Object.create(null)));
assert.throws(() => ValidationStrategy.object(null), /^TypeError: Expected an object\.$/);
assert.throws(() => ValidationStrategy.object(undefined), /^TypeError: Expected an object\.$/);
assert.throws(() => ValidationStrategy.object("string"), /^TypeError: Expected an object\.$/);
assert.throws(() => ValidationStrategy.object(123), /^TypeError: Expected an object\.$/);
assert.throws(() => ValidationStrategy.object(false), /^TypeError: Expected an object\.$/);

// 5. ValidationStrategy['object?'] accepts null and objects and throws TypeError for non-objects
assert.doesNotThrow(() => ValidationStrategy["object?"](null));
assert.doesNotThrow(() => ValidationStrategy["object?"]({}));
assert.doesNotThrow(() => ValidationStrategy["object?"]({ key: "value" }));
assert.doesNotThrow(() => ValidationStrategy["object?"](Object.create(null)));
assert.throws(() => ValidationStrategy["object?"](undefined), /^TypeError: Expected an object or null\.$/);
assert.throws(() => ValidationStrategy["object?"]("string"), /^TypeError: Expected an object or null\.$/);
assert.throws(() => ValidationStrategy["object?"](123), /^TypeError: Expected an object or null\.$/);
assert.throws(() => ValidationStrategy["object?"](true), /^TypeError: Expected an object or null\.$/);

// 6. ValidationStrategy.string accepts strings including empty strings and throws TypeError for non-strings
assert.doesNotThrow(() => ValidationStrategy.string(""));
assert.doesNotThrow(() => ValidationStrategy.string("hello world"));
assert.throws(() => ValidationStrategy.string(123), /^TypeError: Expected a string\.$/);
assert.throws(() => ValidationStrategy.string(null), /^TypeError: Expected a string\.$/);
assert.throws(() => ValidationStrategy.string(undefined), /^TypeError: Expected a string\.$/);
assert.throws(() => ValidationStrategy.string({}), /^TypeError: Expected a string\.$/);

// 7. ValidationStrategy['string!'] accepts non-empty strings and throws TypeError for empty strings or non-strings
assert.doesNotThrow(() => ValidationStrategy["string!"]("hello"));
assert.doesNotThrow(() => ValidationStrategy["string!"](" "));
assert.throws(() => ValidationStrategy["string!"](""), /^TypeError: Expected a non-empty string\.$/);
assert.throws(() => ValidationStrategy["string!"](123), /^TypeError: Expected a non-empty string\.$/);
assert.throws(() => ValidationStrategy["string!"](null), /^TypeError: Expected a non-empty string\.$/);
assert.throws(() => ValidationStrategy["string!"](undefined), /^TypeError: Expected a non-empty string\.$/);

// 8. ObjectSchema integrates ValidationStrategy validators to validate object properties and wrap validation errors
const schema = new ObjectSchema({
  id: { required: true, merge: "replace", validate: "number" },
  name: { required: true, merge: "overwrite", validate: "string!" },
  optionalDescription: { required: false, merge: "replace", validate: "string" },
  tags: { required: false, merge: "overwrite", validate: "array" },
  config: { required: false, merge: "assign", validate: "object" },
  metadata: { required: false, merge: "replace", validate: "object?" },
  active: { required: false, merge: "replace", validate: "boolean" },
  customValidator: { required: false, merge: "replace", validate: ValidationStrategy.number }
});

assert.doesNotThrow(() => {
  schema.validate({
    id: 1,
    name: "item",
    optionalDescription: "",
    tags: ["tag1"],
    config: { enabled: true },
    metadata: null,
    active: true,
    customValidator: 42
  });
});

assert.throws(() => {
  schema.validate({
    id: "not-a-number",
    name: "item"
  });
}, /Expected a number\./);

assert.throws(() => {
  schema.validate({
    id: 1,
    name: ""
  });
}, /Expected a non-empty string\./);

console.log("ValidationStrategy contract assertions verified successfully.");

오리진 시더

익명