CodeSampleX

Beispiel

js-yaml 4.1.0: Schema

Verifiziertes Beispiel für npm js-yaml 4.1.0: Schema. Der Vertrag lief auf node 22 · linux alpine/x64 · docker und bestand: new yaml.Schema(type)…

sha256:b533e7691f258bb33632b9d30b1c31a8dcda08defc74578051404dd3abc98f92

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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

Fall

HOW
Ziel
verify js-yaml.Schema in pkg:npm/js-yaml@4.1.0
Pakete
Symbole
  • js-yaml.Schema
Umgebung
node 22.23.2
Erstellt
2026-08-28T03:32:13Z

Contract

  1. new yaml.Schema(type) instantiates a custom Schema containing the explicit Type
  2. yaml.DEFAULT_SCHEMA.extend(type) creates a new Schema inheriting default types with added custom explicit Type
  3. yaml.DEFAULT_SCHEMA.extend([type1, type2]) creates a new Schema with multiple custom explicit Types
  4. yaml.DEFAULT_SCHEMA.extend({ implicit: [type] }) extends schema with custom implicit scalar Type
  5. yaml.load with extended Schema deserializes custom explicit tags into instantiated objects
  6. yaml.dump with extended Schema serializes custom objects with custom tag notation
  7. yaml.load with extended Schema resolves custom implicit scalar types automatically
  8. yaml.DEFAULT_SCHEMA.extend throws YAMLException when given invalid type definitions

Dateien

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

Quellartefakt herunterladen (tar.gz)

Quelltext

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 js-yaml.Schema in pkg:npm/js-yaml@4.1.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/js-yaml@4.1.0
Demonstrate these symbols/APIs:
  - js-yaml.Schema
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

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:49e7986e3830f5671e94e65545f4eeb60ad5ba9eae0872ea5f12d5264d5b24c1","constraints":{"executionContext":"node"},"contract":["new yaml.Schema(type) instantiates a custom Schema containing the explicit Type","yaml.DEFAULT_SCHEMA.extend(type) creates a new Schema inheriting default types with added custom explicit Type","yaml.DEFAULT_SCHEMA.extend([type1, type2]) creates a new Schema with multiple custom explicit Types","yaml.DEFAULT_SCHEMA.extend({ implicit: [type] }) extends schema with custom implicit scalar Type","yaml.load with extended Schema deserializes custom explicit tags into instantiated objects","yaml.dump with extended Schema serializes custom objects with custom tag notation","yaml.load with extended Schema resolves custom implicit scalar types automatically","yaml.DEFAULT_SCHEMA.extend throws YAMLException when given invalid type definitions"],"goal":"verify js-yaml.Schema in pkg:npm/js-yaml@4.1.0","kind":"HOW","packages":["pkg:npm/js-yaml@4.1.0"],"schemaVersion":1,"symbols":["js-yaml.Schema"]},"contractCommand":["node","test/contract.cjs"],"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/js-yaml@4.1.0"],"schemaVersion":1,"subject":"pkg:npm/js-yaml@4.1.0","symbols":["js-yaml.Schema"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "js-yaml-schema-verification",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "js-yaml-schema-verification",
      "version": "1.0.0",
      "dependencies": {
        "js-yaml": "4.1.0"
      }
    },
    "node_modules/argparse": {
      "version": "2.0.1",
      "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz",
      "integrity": "sha512-8+9WqebbFzpX9OR+Wa6O29asIogeRMzcGtAINdpMHHyAg10f05aSFVBbcEqGf/PXw1EjAZ+q2/bEBg3DvurK3Q==",
      "license": "Python-2.0"
    },
    "node_modules/js-yaml": {
      "version": "4.1.0",
      "resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-4.1.0.tgz",
      "integrity": "sha512-wpxZs9NoxZaJESJGIZTyDEaYpl0FKSA+FB9aJiyemKhMwkxQg63h4T1KJgUGHpTqPDNRcmmYLugrRjJlBtWvRA==",
      "license": "MIT",
      "dependencies": {
        "argparse": "^2.0.1"
      },
      "bin": {
        "js-yaml": "bin/js-yaml.js"
      }
    }
  }
}
package.json
{
  "name": "js-yaml-schema-verification",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification for js-yaml.Schema",
  "dependencies": {
    "js-yaml": "4.1.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify js-yaml.Schema in pkg:npm/js-yaml@4.1.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/js-yaml@4.1.0"
  ],
  "symbols": [
    "js-yaml.Schema"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.cjs
const assert = require('node:assert');
const yaml = require('js-yaml');

// Helper classes for custom types
class Point {
  constructor(x, y) {
    this.x = x;
    this.y = y;
  }
}

class Person {
  constructor(name, age) {
    this.name = name;
    this.age = age;
  }
}

const PointType = new yaml.Type('!point', {
  kind: 'mapping',
  resolve: function(data) {
    return data !== null && typeof data === 'object' && typeof data.x === 'number' && typeof data.y === 'number';
  },
  construct: function(data) {
    return new Point(data.x, data.y);
  },
  instanceOf: Point,
  represent: function(point) {
    return { x: point.x, y: point.y };
  }
});

const PersonType = new yaml.Type('!person', {
  kind: 'mapping',
  resolve: function(data) {
    return data !== null && typeof data === 'object' && typeof data.name === 'string' && typeof data.age === 'number';
  },
  construct: function(data) {
    return new Person(data.name, data.age);
  },
  instanceOf: Person,
  represent: function(person) {
    return { name: person.name, age: person.age };
  }
});

const HexType = new yaml.Type('!hex', {
  kind: 'scalar',
  resolve: function(data) {
    return typeof data === 'string' && /^0x[0-9a-fA-F]+$/.test(data);
  },
  construct: function(data) {
    return parseInt(data, 16);
  },
  predicate: function(data) {
    return typeof data === 'number';
  },
  represent: function(data) {
    return '0x' + data.toString(16);
  }
});

const RegexType = new yaml.Type('!regex', {
  kind: 'scalar',
  resolve: function(data) {
    return typeof data === 'string' && data.startsWith('/') && data.endsWith('/');
  },
  construct: function(data) {
    return new RegExp(data.slice(1, -1));
  }
});

// 1. new yaml.Schema(type) instantiates a custom Schema containing the explicit Type
const standaloneSchema = new yaml.Schema(PointType);
assert.ok(standaloneSchema instanceof yaml.Schema);
assert.ok(Array.isArray(standaloneSchema.explicit));
assert.ok(standaloneSchema.explicit.includes(PointType));

// 2. yaml.DEFAULT_SCHEMA.extend(type) creates a new Schema inheriting default types with added custom explicit Type
const pointSchema = yaml.DEFAULT_SCHEMA.extend(PointType);
assert.ok(pointSchema instanceof yaml.Schema);
assert.notStrictEqual(pointSchema, yaml.DEFAULT_SCHEMA);

// 3. yaml.DEFAULT_SCHEMA.extend([type1, type2]) creates a new Schema with multiple custom explicit Types
const multiSchema = yaml.DEFAULT_SCHEMA.extend([PointType, PersonType, HexType]);
assert.ok(multiSchema instanceof yaml.Schema);

// 4. yaml.DEFAULT_SCHEMA.extend({ implicit: [type] }) extends schema with custom implicit scalar Type
const implicitSchema = yaml.DEFAULT_SCHEMA.extend({ implicit: [RegexType] });
assert.ok(implicitSchema instanceof yaml.Schema);
assert.ok(implicitSchema.implicit.includes(RegexType));

// 5. yaml.load with extended Schema deserializes custom explicit tags into instantiated objects
const pointYaml = 'location: !point\n  x: 15\n  y: 30';
const loadedPoint = yaml.load(pointYaml, { schema: pointSchema });
assert.ok(loadedPoint.location instanceof Point);
assert.strictEqual(loadedPoint.location.x, 15);
assert.strictEqual(loadedPoint.location.y, 30);

const multiYaml = `
user: !person
  name: Alice
  age: 28
address: !point
  x: 100
  y: 200
flags: !hex 0x2a
`;
const loadedMulti = yaml.load(multiYaml, { schema: multiSchema });
assert.ok(loadedMulti.user instanceof Person);
assert.strictEqual(loadedMulti.user.name, 'Alice');
assert.strictEqual(loadedMulti.user.age, 28);
assert.ok(loadedMulti.address instanceof Point);
assert.strictEqual(loadedMulti.flags, 42);

// 6. yaml.dump with extended Schema serializes custom objects with custom tag notation
const pointDumped = yaml.dump({ location: new Point(15, 30) }, { schema: pointSchema });
assert.ok(pointDumped.includes('!point'));
const reloaded = yaml.load(pointDumped, { schema: pointSchema });
assert.ok(reloaded.location instanceof Point);
assert.strictEqual(reloaded.location.x, 15);
assert.strictEqual(reloaded.location.y, 30);

// 7. yaml.load with extended Schema resolves custom implicit scalar types automatically
const regexYaml = 'pattern: /abc[0-9]+/';
const loadedRegex = yaml.load(regexYaml, { schema: implicitSchema });
assert.ok(loadedRegex.pattern instanceof RegExp);
assert.ok(loadedRegex.pattern.test('abc1234'));

// 8. yaml.DEFAULT_SCHEMA.extend throws YAMLException when given invalid type definitions
assert.throws(() => {
  yaml.DEFAULT_SCHEMA.extend('not-a-type');
}, yaml.YAMLException);

assert.throws(() => {
  yaml.DEFAULT_SCHEMA.extend([{ invalid: true }]);
}, yaml.YAMLException);

console.log('Contract passed');

Ursprungs-Seeder

anonym