{
  "schema": "leumas.docs.page/1",
  "id": "adapter:domain/schema",
  "slug": "adapters/domain/schema",
  "kind": "capabilities",
  "bucket": "package",
  "title": "schema — JSON-Schema tooling pack",
  "name": "schema",
  "eyebrow": "JSON-Schema tooling pack",
  "chip": null,
  "summary": "JSON-Schema tooling pack (Draft-07 subset, pure JS, zero deps). Infer a JSON Schema from sample data, validate any data value (object/array/scalar) against a schema returning {valid,errors}, generate...",
  "keywords": [
    "schema",
    "draft-07",
    "minlength",
    "maxlength",
    "date-time",
    "schema api",
    "multipleof",
    "minitems"
  ],
  "audience": "both",
  "funnel": {
    "product": null,
    "cta": null
  },
  "body": "# schema — JSON-Schema tooling pack\n\nA pure-JavaScript (zero npm deps, Node built-ins only) toolkit for authoring, analyzing, and\ntransforming **JSON Schema** (a Draft-07 subset). It infers schemas from data, validates data\nagainst schemas, generates mock/example instances, emits TypeScript, and diffs/merges/coerces\nschemas — everything you need to treat data shapes as first-class artifacts.\n\n## Tools\n\n| Tool | Args | Returns |\n|---|---|---|\n| `infer` | `{ data, options? }` | `{ schema }` — a JSON Schema inferred from sample `data`. |\n| `validate` | `{ data, schema }` | `{ valid, errors, errorCount }` — validate one value against a schema. |\n| `mock` | `{ schema, options?, seed? }` | `{ data }` — randomized data (deterministic per `seed`); `options.count` → array. |\n| `example` | `{ schema, options? }` | `{ example }` — one canonical instance (prefers `default`/`examples`/`enum`). |\n| `toTypeScript` | `{ schema \\| data, options? }` | `{ typescript, rootType, interfaces }` — TS interface/type string. |\n| `diff` | `{ from, to }` (or `schemaA`/`schemaB`) | `{ added, removed, changed, identical }`. |\n| `merge` | `{ schemaA, schemaB }` | `{ schema }` — one schema accepting data valid under either. |\n| `coerce` | `{ data, schema }` | `{ data, changes, changed, valid, errors }` — coerce scalar leaves to declared types. |\n\n### Supported JSON-Schema keywords\n`type` (incl. type arrays, integer vs number), `enum`, `const`; strings: `minLength`, `maxLength`,\n`pattern`, `format` (`email`, `uri`, `url`, `uuid`, `date-time`, `date`, `time`, `ipv4`, `hostname`);\nnumbers: `minimum`, `maximum`, `exclusiveMinimum`, `exclusiveMaximum`, `multipleOf`; arrays:\n`minItems`, `maxItems`, `uniqueItems`, `items` (schema **and** tuple); objects: `required`,\n`properties`, `patternProperties`, `additionalProperties`, `minProperties`, `maxProperties`;\ncombinators: `allOf`, `anyOf`, `oneOf`, `not`. (`$ref` is not resolved — inline your schemas.)\n\n## Usage\n\n```js\nimport schema from './index.js';\n\n// infer a schema from a sample record\nconst { schema: s } = schema.adapters.infer({ data: { id: 1, name: 'Ada', tags: ['x'] } });\n\n// validate a value against it\nschema.adapters.validate({ data: { id: 2, name: 'Grace', tags: [] }, schema: s });\n// → { valid: true, errors: [], errorCount: 0 }\n\n// deterministic mock + one example\nschema.adapters.mock({ schema: s, seed: 7 });\nschema.adapters.example({ schema: s });\n\n// TypeScript interface from a schema (or straight from sample data)\nschema.adapters.toTypeScript({ schema: s, options: { name: 'User' } }).typescript;\n\n// diff / merge two schemas\nschema.adapters.diff({ from: s, to: s2 });\nschema.adapters.merge({ schemaA: s, schemaB: s2 });\n\n// coerce loose strings to declared types\nschema.adapters.coerce({ data: { id: '3', active: 'true' }, schema: s });\n// → { data: { id: 3, active: true }, changes: [...], valid: true }\n```\n\nEvery tool takes one args object (a POST body maps 1:1) and returns a plain JSON-serializable\nobject. Schemas and data may be passed as objects or JSON strings.\n\n## DRY boundary (important)\n\nThis pack is **JSON-Schema tooling** — it operates on and with real JSON Schemas. It deliberately\ndoes **not** overlap two neighbouring packs:\n\n- **`domain/validation`** validates a **single scalar string** against a **format/checksum**\n  (email, IBAN, UUID, credit card…). No schema involved. Use it for \"is this one value a valid X\".\n- **`domain/filters` → `schemaValidate`** validates an **array of records** against a lightweight\n  field-rule schema *inside a data pipeline* (bulk row filtering/annotation).\n\n`schema.validate` here validates **one arbitrary value** (object/array/scalar) against a **full\nJSON Schema**. Three different altitudes — keep them separate.\n",
  "source": {
    "path": "shared/engines/adapters/domain/schema/README.md",
    "blobSha": "",
    "commit": "",
    "committedAt": "",
    "provenance": "no-git",
    "bytes": 3994,
    "hash": "de0556fb75916c983a5d9a6e387ae171db289b81"
  },
  "urls": {
    "html": "/p/adapters/domain/schema",
    "json": "/docs/adapters/domain/schema.json",
    "md": "/docs/adapters/domain/schema.md"
  },
  "links": {
    "composes": [],
    "usedBy": [],
    "product": [],
    "howTo": [
      "how-to:dynamic-layer"
    ],
    "skills": []
  }
}
