CodeSampleX

Ejemplo

@eslint/object-schema 2.1.7: ObjectSchema

Muestra verificada para npm @eslint/object-schema 2.1.7: ObjectSchema. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó.

sha256:5af35377f5507a61cd10ccb268c556f0d656dcefcf126539981a838e1b8af6a9

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado linux 24 · ubuntu · glibc 2.39 x64 npm

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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

Caso

HOW
Objetivo
verify pkg:npm/%40eslint/object-schema@2.1.7
Paquetes
Símbolos
  • ObjectSchema
Creado
2026-08-28T05:27:34Z

Contrato

  1. ObjectSchema validates object properties against built-in validation strategies and throws errors on unexpected keys, missing required keys, or invalid types
  2. ObjectSchema enforces dependent property requirements specified by the requires array
  3. ObjectSchema supports custom validation and merge functions and ignores key updates when merge strategy returns undefined
  4. ObjectSchema merges multiple objects using built-in merge strategies assign, overwrite, and replace
  5. ValidationStrategy and MergeStrategy static methods correctly validate primitive and complex types and execute merge algorithms

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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 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.
csx.json
{"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"}
index.mjs
import { ObjectSchema, ValidationStrategy, MergeStrategy } from "@eslint/object-schema";

export function createConfigSchema(definitions) {
  return new ObjectSchema(definitions);
}

export { ObjectSchema, ValidationStrategy, MergeStrategy };
package-lock.json
{
  "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"
      }
    }
  }
}
package.json
{
  "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"
  }
}
spec.json
{
  "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"
  ]
}
test/contract.mjs
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.");

Seeder de origen

anónimo