CodeSampleX

Ejemplo

json-schema-typed 8.0.2

Muestra verificada para npm json-schema-typed 8.0.2. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó: draft and $schema constants match…

sha256:7d0dfe5064d7812ac71bb6ef49480d9880f3c76150ea6273efd2a80295349b16

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 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

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

Caso

HOW
Objetivo
verify pkg:npm/json-schema-typed@8.0.2
Paquetes
Entorno
node 22.23.2
Creado
2026-08-27T21:57:59Z

Contrato

  1. draft and $schema constants match JSON Schema Draft 2020-12 meta-schema URI
  2. TypeName enum exports standard JSON schema primitive types
  3. Format enum exports standard string format specifiers including email, uri, and date-time
  4. ContentEncoding enum exports media content encoding strategies including base64
  5. keywords list contains standard draft-2020-12 validation and applicator keywords
  6. draft-07 and draft-2019-09 subpath exports provide draft-specific meta-schemas and constants
  7. schema builder functions construct structured schema definitions with format and encoding constraints

Archivos

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.mjs
  • 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/json-schema-typed@8.0.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/json-schema-typed@8.0.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:0c4ccdf5467187dced4c9d295064bb2f743adf4f7525f740f0e0167c3152754e","contract":["draft and $schema constants match JSON Schema Draft 2020-12 meta-schema URI","TypeName enum exports standard JSON schema primitive types","Format enum exports standard string format specifiers including email, uri, and date-time","ContentEncoding enum exports media content encoding strategies including base64","keywords list contains standard draft-2020-12 validation and applicator keywords","draft-07 and draft-2019-09 subpath exports provide draft-specific meta-schemas and constants","schema builder functions construct structured schema definitions with format and encoding constraints"],"goal":"verify pkg:npm/json-schema-typed@8.0.2","kind":"HOW","packages":["pkg:npm/json-schema-typed@8.0.2"],"schemaVersion":1},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"esm","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/json-schema-typed@8.0.2"],"schemaVersion":1,"subject":"pkg:npm/json-schema-typed@8.0.2","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-json-schema-typed",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-json-schema-typed",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "json-schema-typed": "8.0.2"
      }
    },
    "node_modules/json-schema-typed": {
      "version": "8.0.2",
      "resolved": "https://registry.npmjs.org/json-schema-typed/-/json-schema-typed-8.0.2.tgz",
      "integrity": "sha512-fQhoXdcvc3V28x7C7BMs4P5+kNlgUURe2jmUT1T//oBRMDrqy1QPelJimwZGo7Hg9VPV3EQV5Bnq4hbFy2vetA==",
      "license": "BSD-2-Clause"
    }
  }
}
package.json
{
  "name": "sample-json-schema-typed",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "json-schema-typed": "8.0.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/json-schema-typed@8.0.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/json-schema-typed@8.0.2"
  ]
}
src/index.mjs
import { draft, $schema, Format, TypeName, ContentEncoding, keywords } from "json-schema-typed";
import * as draft07 from "json-schema-typed/draft-07";
import * as draft201909 from "json-schema-typed/draft-2019-09";
import * as draft202012 from "json-schema-typed/draft-2020-12";

export function createObjectSchema(properties = {}, required = []) {
  return {
    $schema,
    type: TypeName.Object,
    properties,
    required,
  };
}

export function createStringProperty(format = null, minLength = 0, maxLength = undefined) {
  const schema = {
    type: TypeName.String,
    minLength,
  };
  if (format) {
    schema.format = format;
  }
  if (maxLength !== undefined) {
    schema.maxLength = maxLength;
  }
  return schema;
}

export function createMediaSchema(mediaType, encoding = ContentEncoding.Base64) {
  return {
    type: TypeName.String,
    contentMediaType: mediaType,
    contentEncoding: encoding,
  };
}

export function createArraySchema(itemsSchema, minItems = 0, uniqueItems = false) {
  return {
    type: TypeName.Array,
    items: itemsSchema,
    minItems,
    uniqueItems,
  };
}

export function getDraftMeta(version) {
  switch (version) {
    case "draft-07":
      return { draft: draft07.draft, $schema: draft07.$schema };
    case "draft-2019-09":
      return { draft: draft201909.draft, $schema: draft201909.$schema };
    case "draft-2020-12":
    default:
      return { draft: draft202012.draft, $schema: draft202012.$schema };
  }
}

export function isSupportedKeyword(keyword) {
  return keywords.includes(keyword);
}

export { draft, $schema, Format, TypeName, ContentEncoding, keywords };
test/contract.mjs
import assert from "node:assert/strict";
import {
  draft,
  $schema,
  Format,
  TypeName,
  ContentEncoding,
  keywords,
  createObjectSchema,
  createStringProperty,
  createMediaSchema,
  createArraySchema,
  getDraftMeta,
  isSupportedKeyword
} from "../src/index.mjs";

// Test 1: draft and $schema constants match JSON Schema Draft 2020-12 meta-schema URI
{
  assert.equal(draft, "2020-12");
  assert.equal($schema, "https://json-schema.org/draft/2020-12/schema");
}

// Test 2: TypeName enum exports standard JSON schema primitive types
{
  assert.equal(TypeName.Array, "array");
  assert.equal(TypeName.Boolean, "boolean");
  assert.equal(TypeName.Integer, "integer");
  assert.equal(TypeName.Null, "null");
  assert.equal(TypeName.Number, "number");
  assert.equal(TypeName.Object, "object");
  assert.equal(TypeName.String, "string");
}

// Test 3: Format enum exports standard string format specifiers including email, uri, and date-time
{
  assert.equal(Format.Date, "date");
  assert.equal(Format.DateTime, "date-time");
  assert.equal(Format.Duration, "duration");
  assert.equal(Format.Email, "email");
  assert.equal(Format.Hostname, "hostname");
  assert.equal(Format.IDNEmail, "idn-email");
  assert.equal(Format.IDNHostname, "idn-hostname");
  assert.equal(Format.IPv4, "ipv4");
  assert.equal(Format.IPv6, "ipv6");
  assert.equal(Format.IRI, "iri");
  assert.equal(Format.IRIReference, "iri-reference");
  assert.equal(Format.JSONPointer, "json-pointer");
  assert.equal(Format.JSONPointerURIFragment, "json-pointer-uri-fragment");
  assert.equal(Format.RegEx, "regex");
  assert.equal(Format.RelativeJSONPointer, "relative-json-pointer");
  assert.equal(Format.Time, "time");
  assert.equal(Format.URI, "uri");
  assert.equal(Format.URIReference, "uri-reference");
  assert.equal(Format.URITemplate, "uri-template");
  assert.equal(Format.UUID, "uuid");
}

// Test 4: ContentEncoding enum exports media content encoding strategies including base64
{
  assert.equal(ContentEncoding["7bit"], "7bit");
  assert.equal(ContentEncoding["8bit"], "8bit");
  assert.equal(ContentEncoding.Base64, "base64");
  assert.equal(ContentEncoding.Binary, "binary");
  assert.equal(ContentEncoding.IETFToken, "ietf-token");
  assert.equal(ContentEncoding.QuotedPrintable, "quoted-printable");
  assert.equal(ContentEncoding.XToken, "x-token");
}

// Test 5: keywords list contains standard draft-2020-12 validation and applicator keywords
{
  assert.equal(Array.isArray(keywords), true);
  assert.ok(isSupportedKeyword("$anchor"));
  assert.ok(isSupportedKeyword("$comment"));
  assert.ok(isSupportedKeyword("$defs"));
  assert.ok(isSupportedKeyword("$dynamicAnchor"));
  assert.ok(isSupportedKeyword("$dynamicRef"));
  assert.ok(isSupportedKeyword("$id"));
  assert.ok(isSupportedKeyword("$ref"));
  assert.ok(isSupportedKeyword("$schema"));
  assert.ok(isSupportedKeyword("properties"));
  assert.ok(isSupportedKeyword("required"));
  assert.ok(isSupportedKeyword("type"));
  assert.ok(isSupportedKeyword("prefixItems"));
  assert.ok(isSupportedKeyword("unevaluatedProperties"));
  assert.equal(isSupportedKeyword("nonExistentKeyword"), false);
}

// Test 6: draft-07 and draft-2019-09 subpath exports provide draft-specific meta-schemas and constants
{
  const d7 = getDraftMeta("draft-07");
  assert.equal(d7.draft, "7");
  assert.equal(d7.$schema, "https://json-schema.org/draft-07/schema");

  const d19 = getDraftMeta("draft-2019-09");
  assert.equal(d19.draft, "2019-09");
  assert.equal(d19.$schema, "https://json-schema.org/draft/2019-09/schema");

  const d20 = getDraftMeta("draft-2020-12");
  assert.equal(d20.draft, "2020-12");
  assert.equal(d20.$schema, "https://json-schema.org/draft/2020-12/schema");
}

// Test 7: schema builder functions construct structured schema definitions with format and encoding constraints
{
  const userSchema = createObjectSchema({
    id: createStringProperty(Format.UUID),
    email: createStringProperty(Format.Email),
    homepage: createStringProperty(Format.URI),
    createdAt: createStringProperty(Format.DateTime),
    avatar: createMediaSchema("image/png", ContentEncoding.Base64),
    tags: createArraySchema(createStringProperty(), 1, true)
  }, ["id", "email"]);

  assert.equal(userSchema.$schema, "https://json-schema.org/draft/2020-12/schema");
  assert.equal(userSchema.type, "object");
  assert.deepEqual(userSchema.required, ["id", "email"]);
  assert.equal(userSchema.properties.id.type, "string");
  assert.equal(userSchema.properties.id.format, "uuid");
  assert.equal(userSchema.properties.email.type, "string");
  assert.equal(userSchema.properties.email.format, "email");
  assert.equal(userSchema.properties.homepage.type, "string");
  assert.equal(userSchema.properties.homepage.format, "uri");
  assert.equal(userSchema.properties.createdAt.type, "string");
  assert.equal(userSchema.properties.createdAt.format, "date-time");
  assert.equal(userSchema.properties.avatar.type, "string");
  assert.equal(userSchema.properties.avatar.contentMediaType, "image/png");
  assert.equal(userSchema.properties.avatar.contentEncoding, "base64");
  assert.equal(userSchema.properties.tags.type, "array");
  assert.equal(userSchema.properties.tags.items.type, "string");
  assert.equal(userSchema.properties.tags.minItems, 1);
  assert.equal(userSchema.properties.tags.uniqueItems, true);
}

console.log("All json-schema-typed contract tests passed successfully.");

Seeder de origen

anónimo