CodeSampleX

Beispiel

ajv-formats 2.1.1

Verifiziertes Beispiel für npm ajv-formats 2.1.1. Der Vertrag lief auf node 22 · linux alpine/x64 · docker und bestand: addFormats registers all default…

sha256:f941d275796e7392f3ca0fb4245fbe1af6c036b69f9fcdb4d9dd41a216913ee3

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-27

Fall

HOW
Ziel
verify pkg:npm/ajv-formats@2.1.1
Pakete
Umgebung
node 22.23.2
Erstellt
2026-08-27T23:38:13Z

Contract

  1. addFormats registers all default format validators including date, time, date-time, email, uri, ipv4, ipv6, and uuid to an Ajv instance
  2. addFormats validates RFC 3339 date and date-time format strings and rejects invalid date or date-time values
  3. addFormats validates RFC 5322 email format strings and rejects malformed email addresses
  4. addFormats validates URI and URI-reference format strings including full URLs and relative paths
  5. addFormats validates IPv4 and IPv6 network address format strings and rejects invalid IP representations
  6. addFormats validates UUID format strings adhering to RFC 4122 standard representation
  7. addFormats accepts an array of specific format names to register only selected formats
  8. addFormats supports fast and full validation modes via configuration options
  9. addFormats with keywords option enables formatMinimum, formatMaximum, formatExclusiveMinimum, and formatExclusiveMaximum range comparison keywords
  10. addFormats.get retrieves format definition objects and regular expressions for specified format names

Dateien

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

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 pkg:npm/ajv-formats@2.1.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/ajv-formats@2.1.1
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:2e09acef237a042277a7d0e70c23313ba3bc047102b8a892f801de361698cff1","constraints":{"executionContext":"node"},"contract":["addFormats registers all default format validators including date, time, date-time, email, uri, ipv4, ipv6, and uuid to an Ajv instance","addFormats validates RFC 3339 date and date-time format strings and rejects invalid date or date-time values","addFormats validates RFC 5322 email format strings and rejects malformed email addresses","addFormats validates URI and URI-reference format strings including full URLs and relative paths","addFormats validates IPv4 and IPv6 network address format strings and rejects invalid IP representations","addFormats validates UUID format strings adhering to RFC 4122 standard representation","addFormats accepts an array of specific format names to register only selected formats","addFormats supports fast and full validation modes via configuration options","addFormats with keywords option enables formatMinimum, formatMaximum, formatExclusiveMinimum, and formatExclusiveMaximum range comparison keywords","addFormats.get retrieves format definition objects and regular expressions for specified format names"],"goal":"verify pkg:npm/ajv-formats@2.1.1","kind":"HOW","packages":["pkg:npm/ajv-formats@2.1.1"],"schemaVersion":1},"contractCommand":["node","test/contract.mjs"],"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/ajv-formats@2.1.1"],"schemaVersion":1,"subject":"pkg:npm/ajv-formats@2.1.1","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-ajv-formats",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-ajv-formats",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "ajv-formats": "2.1.1"
      }
    },
    "node_modules/ajv": {
      "version": "8.20.0",
      "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.20.0.tgz",
      "integrity": "sha512-Thbli+OlOj+iMPYFBVBfJ3OmCAnaSyNn4M1vz9T6Gka5Jt9ba/HIR56joy65tY6kx/FCF5VXNB819Y7/GUrBGA==",
      "license": "MIT",
      "dependencies": {
        "fast-deep-equal": "^3.1.3",
        "fast-uri": "^3.0.1",
        "json-schema-traverse": "^1.0.0",
        "require-from-string": "^2.0.2"
      },
      "funding": {
        "type": "github",
        "url": "https://github.com/sponsors/epoberezkin"
      }
    },
    "node_modules/ajv-formats": {
      "version": "2.1.1",
      "resolved": "https://registry.npmjs.org/ajv-formats/-/ajv-formats-2.1.1.tgz",
      "integrity": "sha512-Wx0Kx52hxE7C18hkMEggYlEifqWZtYaRgouJor+WMdPnQyEK13vgEWyVNup7SoeeoLMsr4kf5h6dOW11I15MUA==",
      "license": "MIT",
      "dependencies": {
        "ajv": "^8.0.0"
      },
      "peerDependencies": {
        "ajv": "^8.0.0"
      },
      "peerDependenciesMeta": {
        "ajv": {
          "optional": true
        }
      }
    },
    "node_modules/fast-deep-equal": {
      "version": "3.1.3",
      "resolved": "https://registry.npmjs.org/fast-deep-equal/-/fast-deep-equal-3.1.3.tgz",
      "integrity": "sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==",
      "license": "MIT"
    },
    "node_modules/fast-uri": {
      "version": "3.1.6",
      "resolved": "https://registry.npmjs.org/fast-uri/-/fast-uri-3.1.6.tgz",
      "integrity": "sha512-7Ical1vFEMr0onbVzEDIreM22I4khW+fzyQPwvAFWBp1iwdshSZRsL4jjRvPG9JP1uiqMHRto+YU6R2/CzDz5Q==",
      "funding": [
        {
          "type": "github",
          "url": "https://github.com/sponsors/fastify"
        },
        {
          "type": "opencollective",
          "url": "https://opencollective.com/fastify"
        }
      ],
      "license": "BSD-3-Clause"
    },
    "node_modules/json-schema-traverse": {
      "version": "1.0.0",
      "resolved": "https://registry.npmjs.org/json-schema-traverse/-/json-schema-traverse-1.0.0.tgz",
      "integrity": "sha512-NM8/P9n3XjXhIZn1lLhkFaACTOURQXjWhV4BA/RnOv8xvgqtqpAX9IO4mRQxSx1Rlo4tqzeqb0sOlruaOy3dug==",
      "license": "MIT"
    },
    "node_modules/require-from-string": {
      "version": "2.0.2",
      "resolved": "https://registry.npmjs.org/require-from-string/-/require-from-string-2.0.2.tgz",
      "integrity": "sha512-Xf0nWe6RseziFMu+Ap9biiUbmplq6S9/p+7w7YXP/JBHhrUDDUhwa+vANyubuqfZWTveU//DYVGsDG7RKL/vEw==",
      "license": "MIT",
      "engines": {
        "node": ">=0.10.0"
      }
    }
  }
}
package.json
{
  "name": "sample-ajv-formats",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "license": "MIT-0",
  "dependencies": {
    "ajv-formats": "2.1.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/ajv-formats@2.1.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/ajv-formats@2.1.1"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.mjs
import assert from 'node:assert/strict';
import Ajv from 'ajv';
import addFormats from 'ajv-formats';

// 1. addFormats registers all default format validators including date, time, date-time, email, uri, ipv4, ipv6, and uuid to an Ajv instance
{
  const ajv = new Ajv();
  addFormats(ajv);

  const schema = {
    type: 'object',
    properties: {
      date: { type: 'string', format: 'date' },
      time: { type: 'string', format: 'time' },
      dateTime: { type: 'string', format: 'date-time' },
      email: { type: 'string', format: 'email' },
      uri: { type: 'string', format: 'uri' },
      ipv4: { type: 'string', format: 'ipv4' },
      ipv6: { type: 'string', format: 'ipv6' },
      uuid: { type: 'string', format: 'uuid' },
    },
    required: ['date', 'time', 'dateTime', 'email', 'uri', 'ipv4', 'ipv6', 'uuid'],
  };

  const validate = ajv.compile(schema);
  const validData = {
    date: '2026-08-26',
    time: '14:30:00Z',
    dateTime: '2026-08-26T14:30:00.000Z',
    email: 'user@example.com',
    uri: 'https://example.com/api/v1?query=1',
    ipv4: '192.168.1.1',
    ipv6: '2001:0db8:85a3:0000:0000:8a2e:0370:7334',
    uuid: '123e4567-e89b-12d3-a456-426614174000',
  };

  assert.equal(validate(validData), true);
}

// 2. addFormats validates RFC 3339 date and date-time format strings and rejects invalid date or date-time values
{
  const ajv = new Ajv();
  addFormats(ajv);

  const dateValidator = ajv.compile({ type: 'string', format: 'date' });
  assert.equal(dateValidator('2026-08-26'), true);
  assert.equal(dateValidator('2026-02-30'), false);
  assert.equal(dateValidator('2026/08/26'), false);
  assert.equal(dateValidator('not-a-date'), false);

  const dateTimeValidator = ajv.compile({ type: 'string', format: 'date-time' });
  assert.equal(dateTimeValidator('2026-08-26T14:30:00Z'), true);
  assert.equal(dateTimeValidator('2026-08-26T14:30:00+09:00'), true);
  assert.equal(dateTimeValidator('2026-02-30T14:30:00Z'), false);
  assert.equal(dateTimeValidator('2026-08-26T25:00:00Z'), false);
  assert.equal(dateTimeValidator('not-a-date-time'), false);
}

// 3. addFormats validates RFC 5322 email format strings and rejects malformed email addresses
{
  const ajv = new Ajv();
  addFormats(ajv);

  const emailValidator = ajv.compile({ type: 'string', format: 'email' });
  assert.equal(emailValidator('user@example.com'), true);
  assert.equal(emailValidator('user+tag@example.com'), true);
  assert.equal(emailValidator('plainaddress'), false);
  assert.equal(emailValidator('@example.com'), false);
  assert.equal(emailValidator('username@'), false);
}

// 4. addFormats validates URI and URI-reference format strings including full URLs and relative paths
{
  const ajv = new Ajv();
  addFormats(ajv);

  const uriValidator = ajv.compile({ type: 'string', format: 'uri' });
  assert.equal(uriValidator('https://example.com/docs?id=10#section'), true);
  assert.equal(uriValidator('ftp://example.com/file.txt'), true);
  assert.equal(uriValidator('relative/path/test'), false);
  assert.equal(uriValidator('://invalid-scheme'), false);

  const uriRefValidator = ajv.compile({ type: 'string', format: 'uri-reference' });
  assert.equal(uriRefValidator('https://example.com/docs'), true);
  assert.equal(uriRefValidator('/path/to/resource'), true);
  assert.equal(uriRefValidator('#anchor-only'), true);
}

// 5. addFormats validates IPv4 and IPv6 network address format strings and rejects invalid IP representations
{
  const ajv = new Ajv();
  addFormats(ajv);

  const ipv4Validator = ajv.compile({ type: 'string', format: 'ipv4' });
  assert.equal(ipv4Validator('127.0.0.1'), true);
  assert.equal(ipv4Validator('255.255.255.255'), true);
  assert.equal(ipv4Validator('256.0.0.1'), false);
  assert.equal(ipv4Validator('192.168.1'), false);

  const ipv6Validator = ajv.compile({ type: 'string', format: 'ipv6' });
  assert.equal(ipv6Validator('::1'), true);
  assert.equal(ipv6Validator('fe80::1ff:fe23:4567:890a'), true);
  assert.equal(ipv6Validator('2001:db8:85a3::8a2e:370:7334'), true);
  assert.equal(ipv6Validator('1200::AB00:1234::2552:7777'), false);
  assert.equal(ipv6Validator('192.168.1.1'), false);
}

// 6. addFormats validates UUID format strings adhering to RFC 4122 standard representation
{
  const ajv = new Ajv();
  addFormats(ajv);

  const uuidValidator = ajv.compile({ type: 'string', format: 'uuid' });
  assert.equal(uuidValidator('123e4567-e89b-12d3-a456-426614174000'), true);
  assert.equal(uuidValidator('c9b4e056-11f8-4e89-9a64-07d066c8913b'), true);
  assert.equal(uuidValidator('123e4567-e89b-12d3-a456'), false);
  assert.equal(uuidValidator('123e4567-e89b-12d3-a456-42661417400g'), false);
}

// 7. addFormats accepts an array of specific format names to register only selected formats
{
  const ajv = new Ajv();
  addFormats(ajv, ['email', 'uuid']);

  const emailValidator = ajv.compile({ type: 'string', format: 'email' });
  assert.equal(emailValidator('test@example.com'), true);
  assert.equal(emailValidator('bad-email'), false);

  const uuidValidator = ajv.compile({ type: 'string', format: 'uuid' });
  assert.equal(uuidValidator('123e4567-e89b-12d3-a456-426614174000'), true);

  // Formats not in list are not registered
  const ajvNonStrict = new Ajv({ strict: false });
  addFormats(ajvNonStrict, ['email']);
  const dateValidator = ajvNonStrict.compile({ type: 'string', format: 'date' });
  assert.equal(dateValidator('not-a-valid-date'), true);
}

// 8. addFormats supports fast and full validation modes via configuration options
{
  const ajvFast = new Ajv();
  addFormats(ajvFast, { mode: 'fast' });
  const validateFast = ajvFast.compile({ type: 'string', format: 'date-time' });
  assert.equal(validateFast('2026-08-26T12:00:00Z'), true);
  assert.equal(validateFast('invalid'), false);

  const ajvFull = new Ajv();
  addFormats(ajvFull, { mode: 'full' });
  const validateFull = ajvFull.compile({ type: 'string', format: 'date-time' });
  assert.equal(validateFull('2026-08-26T12:00:00Z'), true);
  assert.equal(validateFull('invalid'), false);
}

// 9. addFormats with keywords option enables formatMinimum, formatMaximum, formatExclusiveMinimum, and formatExclusiveMaximum range comparison keywords
{
  const ajv = new Ajv();
  addFormats(ajv, { keywords: true });

  const rangeSchema = {
    type: 'string',
    format: 'date',
    formatMinimum: '2026-01-01',
    formatExclusiveMaximum: '2026-12-31',
  };
  const validateRange = ajv.compile(rangeSchema);

  assert.equal(validateRange('2026-06-15'), true);
  assert.equal(validateRange('2026-01-01'), true);
  assert.equal(validateRange('2025-12-31'), false);
  assert.equal(validateRange('2026-12-31'), false);
}

// 10. addFormats.get retrieves format definition objects and regular expressions for specified format names
{
  const emailFormat = addFormats.get('email');
  assert.ok(emailFormat instanceof RegExp);
  assert.equal(emailFormat.test('user@example.com'), true);
  assert.equal(emailFormat.test('invalid-email'), false);

  const dateFormat = addFormats.get('date', 'full');
  assert.equal(typeof dateFormat, 'object');
  assert.equal(typeof dateFormat.validate, 'function');
  assert.equal(typeof dateFormat.compare, 'function');
  assert.equal(dateFormat.validate('2026-08-26'), true);
  assert.equal(dateFormat.validate('2026-02-30'), false);
  assert.equal(dateFormat.compare('2026-08-26', '2026-08-25'), 1);
  assert.equal(dateFormat.compare('2026-08-26', '2026-08-27'), -1);
  assert.equal(dateFormat.compare('2026-08-26', '2026-08-26'), 0);
}

console.log('All contracts passed.');

Ursprungs-Seeder

anonym