@schema-engine/registry 0.5.1 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/README.md +98 -14
  2. package/dist/bind-registry.d.ts +68 -0
  3. package/dist/bind-registry.js +1 -0
  4. package/dist/bind-registry.js.map +7 -0
  5. package/dist/chunk-24SNVXNP.js +2 -0
  6. package/dist/chunk-24SNVXNP.js.map +7 -0
  7. package/dist/chunk-55J6XMHW.js +0 -0
  8. package/dist/chunk-55J6XMHW.js.map +7 -0
  9. package/dist/chunk-DE7GQKZP.js +3 -0
  10. package/dist/chunk-DE7GQKZP.js.map +7 -0
  11. package/dist/chunk-FMWSZRDV.js +1 -0
  12. package/dist/chunk-FMWSZRDV.js.map +7 -0
  13. package/dist/chunk-GX6PAJLU.js +1 -0
  14. package/dist/chunk-GX6PAJLU.js.map +7 -0
  15. package/dist/chunk-IYIWS4LW.js +1 -0
  16. package/dist/chunk-IYIWS4LW.js.map +7 -0
  17. package/dist/chunk-LG33VSKX.js +1 -0
  18. package/dist/chunk-LG33VSKX.js.map +7 -0
  19. package/dist/chunk-NSLF54GM.js +1 -0
  20. package/dist/chunk-NSLF54GM.js.map +7 -0
  21. package/dist/chunk-O5CRFISG.js +1 -0
  22. package/dist/chunk-O5CRFISG.js.map +7 -0
  23. package/dist/chunk-P3DDHPDA.js +1 -0
  24. package/dist/chunk-P3DDHPDA.js.map +7 -0
  25. package/dist/chunk-QHVQ4S4D.js +1 -0
  26. package/dist/chunk-QHVQ4S4D.js.map +7 -0
  27. package/dist/chunk-RVS7JY2Y.js +1 -0
  28. package/dist/chunk-RVS7JY2Y.js.map +7 -0
  29. package/dist/chunk-UH3CEF45.js +1 -0
  30. package/dist/chunk-UH3CEF45.js.map +7 -0
  31. package/dist/chunk-XG4EZ5VP.js +1 -0
  32. package/dist/chunk-XG4EZ5VP.js.map +7 -0
  33. package/dist/create-registry.d.ts +83 -7
  34. package/dist/create-registry.js +1 -1
  35. package/dist/create-registry.js.map +4 -4
  36. package/dist/export-tree-schema.d.ts +100 -0
  37. package/dist/export-tree-schema.js +1 -0
  38. package/dist/export-tree-schema.js.map +7 -0
  39. package/dist/format-issue-path.d.ts +12 -0
  40. package/dist/format-issue-path.js +1 -0
  41. package/dist/format-issue-path.js.map +7 -0
  42. package/dist/index.d.ts +8 -1
  43. package/dist/index.js +1 -1
  44. package/dist/index.js.map +4 -4
  45. package/dist/json-schema/embedder.d.ts +119 -0
  46. package/dist/json-schema/embedder.js +1 -0
  47. package/dist/json-schema/embedder.js.map +7 -0
  48. package/dist/json-schema/index.d.ts +5 -0
  49. package/dist/json-schema/index.js +1 -0
  50. package/dist/json-schema/index.js.map +7 -0
  51. package/dist/json-schema/slot.d.ts +46 -0
  52. package/dist/json-schema/slot.js +1 -0
  53. package/dist/json-schema/slot.js.map +7 -0
  54. package/dist/json-schema/standard.d.ts +44 -0
  55. package/dist/json-schema/standard.js +1 -0
  56. package/dist/json-schema/standard.js.map +7 -0
  57. package/dist/parse-node.d.ts +131 -0
  58. package/dist/parse-node.js +1 -0
  59. package/dist/parse-node.js.map +7 -0
  60. package/dist/parse-tree.d.ts +131 -0
  61. package/dist/parse-tree.js +1 -0
  62. package/dist/parse-tree.js.map +7 -0
  63. package/dist/registry-error.d.ts +80 -0
  64. package/dist/registry-error.js +1 -0
  65. package/dist/registry-error.js.map +7 -0
  66. package/dist/standard-schema.d.ts +19 -0
  67. package/dist/standard-schema.js +1 -1
  68. package/dist/standard-schema.js.map +4 -4
  69. package/dist/tree-types.d.ts +152 -0
  70. package/dist/tree-types.js +0 -0
  71. package/dist/tree-types.js.map +7 -0
  72. package/dist/types.d.ts +41 -0
  73. package/dist/types.js +1 -0
  74. package/dist/yaml/index.js +1 -4
  75. package/dist/yaml/index.js.map +4 -4
  76. package/dist/yaml/parse.js +1 -2
  77. package/dist/yaml/parse.js.map +4 -4
  78. package/dist/yaml/stringify.js +1 -3
  79. package/dist/yaml/stringify.js.map +4 -4
  80. package/package.json +13 -9
  81. package/skill/SKILL.md +34 -33
  82. package/skill/reference/registry.md +120 -7
  83. package/dist/base-registry.d.ts +0 -73
  84. package/dist/base-registry.js +0 -1
  85. package/dist/base-registry.js.map +0 -7
@@ -1,14 +1,14 @@
1
1
  # @schema-engine/registry
2
2
 
3
- The registration contract and the read-only registry every other package builds on, and the YAML subpath for documents authored as text. The terms are defined in the router (`SKILL.md`). How the forms engine registers elements, recipes, actions and rules is in `forms.md`.
3
+ The registration contract and the registries (read-only, or mutable for runtime registrations) every other package builds on, and the YAML subpath for documents authored as text. The terms are defined in the router (`SKILL.md`). How the forms engine registers elements, recipes, actions and rules is in `forms.md`.
4
4
 
5
5
  ## A registration
6
6
 
7
- Every registration is `{ $type, schema, metadata }`: `$type` is the stable key, `schema` is any Standard Schema (Zod, Zod Mini, Valibot, Effect Schema or a hand-written one) that describes the config, and `metadata` has a `name` and optionally a `description`. A package adds what it needs to the type (`BaseRegistration`): a renderable one is a `ComponentRegistration` with `render`, an action adds `execute`, a validation rule adds `category` and `handler`. The registry has no schema-library dependency: install the provider you prefer.
7
+ Every registration is `{ $type, schema, metadata }`: `$type` is the stable key, `schema` is any Standard Schema (Zod, Zod Mini, Valibot, Effect Schema or a hand-written one) that describes the config, and `metadata` has a `name` and optionally a `description`. A package adds what it needs to the type (`BaseRegistration`; a component's metadata, `ComponentMetadata`, adds optional `icon`, `tags` and `version`): a renderable one is a `ComponentRegistration` with `render`, an action adds `execute`, a validation rule adds `category` and `handler`. The registry has no schema-library dependency: install the provider you prefer.
8
8
 
9
9
  ## createRegistry
10
10
 
11
- `createRegistry(kind, registrations)` builds a frozen registry once, from a list. `kind` is the label in errors.
11
+ `createRegistry(kind, registrations, options?)` builds a frozen registry once, from a list. `kind` is the label in errors.
12
12
 
13
13
  ```ts title="registry/widgets.ts"
14
14
  import * as z from 'zod/mini';
@@ -29,15 +29,128 @@ export const widgets = createRegistry('Widget', [...defaults, custom]);
29
29
  ```
30
30
 
31
31
  - A later registration with the same `$type` replaces the earlier one with no warning, so `[...defaults, custom]` is how you override. The key keeps its first position.
32
- - Each winning `schema` is checked at build: a value without `~standard.validate` throws, naming the `kind` and the `$type`.
32
+ - `createRegistry(kind, registrations, { duplicates: 'error' })` makes a repeated `$type` a build error instead (`Widget 'card' is registered twice.`, thrown before any schema is checked). Use it for a catalog where a repeat is always a mistake, such as component keys; the default is `'override'`.
33
+ - Each winning `schema` is checked at build: a value without `~standard.validate` throws a `RegistryError` with code `'invalid-schema'`, naming the `kind` and the `$type`.
33
34
  - The result has `get`, `has`, `all`, `keys` and `size`, and no `register` or `clear`. It holds a frozen shallow copy of each winner taken at build, so patch a registration before building, or build a new registry from a new list.
34
35
  - Type it with `ReadOnlyRegistry<TRegistration>`.
35
36
 
36
- `safeParseStandardSchema(schema, value)` runs a registration's schema without throwing and returns `{ success: true, data }` or `{ success: false, error: { issues } }` (it throws for a schema that validates asynchronously). Form validation and `parseActions` both go through it; `assertStandardSchema` is the build-time check on its own.
37
+ `bindRegistry(contracts, bindings)` builds a renderer's registry from one registry of contracts (the `$type`, schema and metadata) and one binding per `$type` (a `render`, a tag name: renderer-only data). Two renderers bind the same contracts and share each `schema` by identity:
37
38
 
38
- ## BaseRegistry
39
+ ```ts title="registry/bound-widgets.ts"
40
+ import * as z from 'zod/mini';
41
+ import { bindRegistry, createRegistry } from '@schema-engine/registry';
42
+
43
+ const contracts = createRegistry('Widget', [
44
+ { $type: 'card', schema: z.object({ title: z.string() }), metadata: { name: 'Card' } },
45
+ { $type: 'badge', schema: z.object({ label: z.string() }), metadata: { name: 'Badge' } },
46
+ ]);
47
+
48
+ export const reactWidgets = bindRegistry(contracts, {
49
+ card: { render: (props: { title: string }) => `<h1>${props.title}</h1>` },
50
+ badge: { render: (props: { label: string }) => `<b>${props.label}</b>` },
51
+ });
52
+
53
+ export const radiantWidgets = bindRegistry(contracts, {
54
+ card: { tag: 'se-card' },
55
+ badge: { tag: 'se-badge' },
56
+ });
57
+ ```
58
+
59
+ - The result is a `BoundRegistry`, a frozen registry built with `createRegistry`: the contracts' order, every schema checked again. For contracts typed by literal `$type` (an inline list), `get('card')` returns that registration (a `BoundRegistration`, the contract with its binding) without `undefined`, and a missing binding, an extra one (`crad`) and a binding that sets a contract key (`schema`, `metadata`) are compile errors. `RegistryBindings<typeof contracts, ReactBinding>` with `satisfies` fixes the shape every binding of a renderer takes.
60
+ - Whatever the typing, the build throws a `RegistryError` (codes `'missing-binding'`, `'unknown-binding'` and `'binding-overrides-contract'`) naming the `kind`: `Widget 'badge' has no binding.`, `Widget binding 'crad' names no registration.` and `Widget 'card' binding sets 'schema', which the contract defines.`
61
+
62
+ Errors while building or binding, and a tree parse whose schema contradicts its registration, are a `RegistryError` (`error.code` of type `RegistryErrorCode`, always with `$type`, and `kind` unless a parse went through a lookup that is no registry). Branch on the code, not on the message, which may be reworded:
63
+
64
+ - `'invalid-schema'`: a `schema` without `~standard.validate`.
65
+ - `'invalid-child-paths'`: `childPaths` is not a list, or an entry is not `{ keys, accepts?, list? }` (another property such as `accept`, empty or non-string `keys`, an empty `accepts`, a name that is empty or listed twice, a `list` that is not `true`).
66
+ - `'duplicate-child-path'`: the same child path (`childPath`, the same keys) twice. `'nested-child-path'`: a child path (`childPath`) that runs through another (`outerChildPath`).
67
+ - `'invalid-declaration'`: a domain package refuses a declaration of a registration other than its child paths.
68
+ - `'duplicate-type'`: a repeated `$type` with `duplicates: 'error'`.
69
+ - `'unknown-binding'`: a binding key no contract answers (`$type` is that key). `'missing-binding'`: a contract with no binding. `'binding-overrides-contract'`: a binding that sets a key (`key`) its contract defines.
70
+ - `'unreachable-child-path'` (`childPath`): `exportTreeSchema` found no slot for a child path in a registration's JSON Schema. `'unknown-accepted-type'` (`childPath`, `key`): a child path accepts a `$type` the lookup lacks. `'definition-name-clash'` (`key`): a definition a schema brought along takes the name of a `$type`.
71
+ - `'schema-changes-type'` and `'schema-breaks-child-path'` (`childPath`): `safeParseTree` parsed a node whose schema returned an output without the node's own `$type`, or that does not keep a child path as the document has it. They are bugs of the registration, never issues of the document.
72
+
73
+ `assertStandardSchema` on its own and errors while parsing (`safeParseStandardSchema` and `safeParseNode` with an asynchronous schema) are plain `Error`s, and `parseYaml` throws `YamlDocumentError`.
74
+
75
+ `safeParseStandardSchema(schema, value)` runs a registration's schema without throwing and returns `{ success: true, data }` or `{ success: false, error: { issues } }` (it throws for a schema that validates asynchronously). Form validation and `parseActions` both go through it; `isStandardSchema(value)` is the type guard for a Standard Schema's shape (it never runs the schema), and `assertStandardSchema` is the build-time check on its own. `standardSchema(validate)` builds a Standard Schema from a function that returns `{ value }` or `{ issues }`, for a registration whose check is not a schema library's.
76
+
77
+ `safeParseNode(registry, node, options?)` checks one node of a document: it looks `node.$type` up in the registry (anything with `get(key)`, and optionally `hint`, a sentence added to the message of an unregistered `$type`, such as where to register it), validates the node with the registration's schema and returns `{ success: true, $type, registration, data }` or `{ success: false, issues }`. For a registry typed by its registrations (`createRegistry` keeps the literal `$type` of an inline list), checking `parsed.$type` narrows `registration` and `data` to that registration's schema output with no cast; `data` is `unknown` for a registry typed as `BaseRegistration`. A node that is not an object with a string `$type`, and a `$type` no registration answers, are issues, not throws; the second reads `No registration for $type '<type>'.` and then the hint, and `unregisteredTypeMessage(type, hint?)` writes the same text for a caller that throws instead. Every issue's `path` starts with `options.path`, the position of the node in its document, so a walk over a tree passes each child its own. `options.accepts` is a non-empty list of the `$type`s the node may have: another `$type` is the issue `registry/not-accepted` (with `expected` and `received`), checked before the lookup. The issues the engine creates carry a namespaced `code`: `registry/not-an-object`, `registry/missing-type`, `registry/unregistered-type`, `registry/not-accepted`, `registry/not-a-node` and `registry/contains-itself`; an issue from a schema is its library's own.
78
+
79
+ ```ts title="registry/draw-node.ts"
80
+ import { formatIssuePath, safeParseNode } from '@schema-engine/registry';
81
+ import { widgets } from './widgets';
82
+
83
+ export function nodeIssues(node: unknown, index: number): string[] {
84
+ const parsed = safeParseNode(widgets, node, { path: ['children', index] });
85
+ return parsed.success ? [] : parsed.issues.map((issue) => `${formatIssuePath(issue.path)}: ${issue.message}`);
86
+ }
87
+ ```
88
+
89
+ `safeParseTree(registry, root, options?)` checks a whole document in one call. A registration says where its children are with `childPaths`, a list of `{ keys, accepts?, list? }`: `keys` is the list of keys from the node to the slot (`['sections']`, or `['engine', 'controls']`), relative and without indexes, and `accepts` is a closed, non-empty list of the `$type`s allowed there (leave it out and the slot puts no limit on the `$type`). The slot holds one node or an array of nodes, or only an array when `list: true`: anything else there is `registry/not-a-list` at the path, an open slot is exported as an array, and `data` types the slot as an array. Keep the slot opaque in the parent's schema (`z.array(z.unknown())`) and declare every child key there: `accepts` is the only way to restrict a slot, and `createRegistry` fails to compile a child path whose key the schema output does not declare. `options.accepts` restricts the root and `options.path` is where it sits in a larger document. Every node goes through `safeParseNode` at its full path and the `accepts` of its position, a node whose schema fails is not walked further but its siblings still are, a value at a child path that is no node (`null`, a primitive) is `registry/not-a-node` at that path (`registry/not-a-list` on a path that sets `list`), and a node that contains itself is `registry/contains-itself`, not an overflow. It returns `{ success: true, tree }` or `{ success: false, issues, tree? }` with every issue and the nodes that parsed. `tree.data` is the parsed document, typed per child path, with defaults and transforms of every level applied; a `tree` node is a `ParsedNode`, `{ $type, registration, data, path, children }`, whose `data` is that node's composed data and whose `children` is a list of `{ keys, nodes }`, one per declared path in declaration order (find one with `children.find(({ keys }) => ...)`, never by index). On failure, `tree` is a `PartialNode` when the root's own schema passed (absent when the root failed): every node whose own schema passed and whose parent was kept, `{ $type, registration, output, path, children }`, with `output` the node's own schema output and no `data` (reading `tree.data` there is a type error). A failed node is left out and not walked, as are a rejected `accepts` and a cycle edge; `children` keeps one `{ keys, nodes }` per path with the kept children in document order, each with its own `path`. Read children from `children`, never from a slot of `output`, which holds what the document had there. The parent schema must keep `$type` and the slot the way the document has it, or `safeParseTree` throws a `RegistryError`. The root narrows from a literal `accepts`. Two registries in one parse go through one lookup: `{ get: (type) => a.get(type) ?? b.get(type) }`, and the first that answers wins.
90
+
91
+ ```ts title="registry/check-tree.ts"
92
+ import * as z from 'zod/mini';
93
+ import { createRegistry, formatIssuePath, safeParseTree } from '@schema-engine/registry';
94
+
95
+ const nodes = createRegistry('Node', [
96
+ {
97
+ $type: 'page',
98
+ schema: z.object({ $type: z.literal('page'), sections: z.array(z.unknown()) }),
99
+ metadata: { name: 'Page' },
100
+ childPaths: [{ keys: ['sections'], accepts: ['section'] }],
101
+ },
102
+ {
103
+ $type: 'section',
104
+ schema: z.object({ $type: z.literal('section'), title: z.string() }),
105
+ metadata: { name: 'Section' },
106
+ },
107
+ ]);
108
+
109
+ export function documentIssues(document: unknown): string[] {
110
+ const parsed = safeParseTree(nodes, document, { accepts: ['page'] });
111
+ return parsed.success
112
+ ? []
113
+ : parsed.issues.map((issue) => `${formatIssuePath(issue.path, document)}: ${issue.message}`);
114
+ }
115
+
116
+ export function sectionTitles(document: unknown): string[] {
117
+ const parsed = safeParseTree(nodes, document, { accepts: ['page'] });
118
+ return parsed.success ? parsed.tree.data.sections.map((section) => section.title) : [];
119
+ }
120
+ ```
121
+
122
+ `formatIssuePath(path, source?)` writes the `path` of an issue as text: keys joined by dots and indexes in brackets (`children[1].label`), the empty string for a missing or empty path. A segment may be a key or a Standard Schema `{ key }` object. Given the document as `source`, an array item with a string `id` is followed by it, `children[1] (hero).label`.
123
+
124
+ `exportTreeSchema(lookup, options?)` writes the JSON Schema of the whole tree, composed at the JSON Schema level so it does not depend on the validator. `lookup` is a registry (anything with `all()`) or a list of registries, the first winning a `$type` both list. It returns `{ $schema, $defs, anyOf }`: one definition per `$type` under `$defs` (`definitions` for target `'draft-07'`), referred to by `#/$defs/<$type>` with `~` and `/` escaped as `~0` and `~1`, and the root as the union of `options.accepts`, or of every `$type`. Each schema is read by `options.resolve(schema, { io, target })`, by default its `~standard.jsonSchema`, and a schema it returns `undefined` for is listed by an open object that holds its `$type` and its child paths. `options.io` is `'input'` (the authored shape, the default) or `'output'`, and `options.target` the dialect: `'draft-2020-12'` (the default) or `'draft-07'`, and any other target (`'openapi-3.0'`, a misspelling, Zod's older spelling of draft-07) throws an `Error` before a schema is read. `JSONSchemaTarget`, the closed set of the Standard JSON Schema names `'draft-2020-12'`, `'draft-07'`, `'draft-04'` and `'openapi-3.0'`, is exported from the root. Each child path is then replaced, and only its slot, so `required`, `minItems`, `maxItems` and sibling keys stay: an array slot gets `items: U`, an object slot becomes `U`, an open slot (`{}`) becomes `{ anyOf: [U, { type: 'array', items: U }] }`, where `U` is `{ anyOf: [{ $ref }, ...] }` of the path's `accepts`, or of every `$type` without it. A slot behind `allOf`, a `$ref` or a union, inside a schema with an `$id` (`id` for draft-04) of its own, or one a schema does not declare, throws `RegistryError` `'unreachable-child-path'`. Definitions a schema wrote into its own `$defs` are lifted to the top as `<$type>.<name>` and their pointers follow, with each `.` and `_` of the `$type` written as `_2e_` and `_5f_` (so `a.b` with `c` is `a_2e_b.c`, apart from `a` with `b.c`), and its anchors (`$anchor`, `$dynamicAnchor`, a draft-07 `$id: '#name'`, a draft-04 `id: '#name'`) become `<owner part>.<name>` where the owner part is `o` and the `$type` with every character outside `[A-Za-z0-9-]` written as `_<hex>_` (`ui/button` and `x` give `oui_2f_button.x`, `my-card` gives `omy-card.x`); a name already in the document (a `$type` with that name, say) throws `'definition-name-clash'`. `@schema-engine/registry/json-schema` holds the pieces for code that writes JSON Schema itself: `readStandardJSONSchema(schema)` returns a schema's `~standard.jsonSchema` converter or `undefined` (what the default `resolve` reads, so a custom `resolve` can fall back to it: `readStandardJSONSchema(schema)?.[io]({ target })`), `createJSONSchemaEmbedder(target, placement)` embeds schemas written as documents of their own into one being written, as the forms export does (it takes a `JSONSchemaTarget` and throws for any other string), `assertJSONSchemaTarget(target)` throws unless a string is a `JSONSchemaTarget` and narrows it to one (for the open `target` of a Standard JSON Schema converter's options), `idKeyword(target)` is the keyword a target writes a schema's identifier under (`'id'` for `'draft-04'`, `'$id'` otherwise), `startsResource(schema, target)` is whether a schema sets it to something other than a fragment (`#node`), which makes it a resource that resolves its own references and anchors, `replaceChildSlot(definition, { $type, keys }, union, { target })` replaces, in place, the slot a child path names in a registration's JSON Schema, which is the step `exportTreeSchema` takes per child path (an unreachable slot, or an `$id` (`id` for draft-04) between the definition and the slot, throws `RegistryError` `'unreachable-child-path'`; the `$id` of the definition's own root is the caller's to check; a path with `list: true` writes an open slot as an array instead of a child or a list, and an object slot of it is unreachable), `definitionRef(target, name)` writes the `$ref` to a definition (`#/$defs/<name>` for `'draft-2020-12'`, `#/definitions/<name>` otherwise, the name as a JSON Pointer token percent-encoded only where a URI fragment needs it, so `element:tab` stays as written), and `definitionsKeyword(target)` is the keyword it writes. A schema that is itself a definition or an entry is written in place by the embedder's `embedDefinition(own, name)` (one with an `$id` (`id` for draft-04) of its own is a collection entry that refers to it, so the entry keeps the collection's URI). A registry user needs only `exportTreeSchema`.
125
+
126
+ ```ts title="registry/export-tree.ts"
127
+ import * as z from 'zod/mini';
128
+ import { createRegistry, exportTreeSchema } from '@schema-engine/registry';
129
+
130
+ const nodes = createRegistry('Node', [
131
+ {
132
+ $type: 'page',
133
+ schema: z.object({ $type: z.literal('page'), sections: z.array(z.unknown()) }),
134
+ metadata: { name: 'Page' },
135
+ childPaths: [{ keys: ['sections'], accepts: ['section'] }],
136
+ },
137
+ {
138
+ $type: 'section',
139
+ schema: z.object({ $type: z.literal('section'), title: z.string() }),
140
+ metadata: { name: 'Section' },
141
+ },
142
+ ]);
143
+
144
+ export const documentSchema = exportTreeSchema(nodes, {
145
+ accepts: ['page'],
146
+ resolve: (schema, { io, target }) =>
147
+ schema instanceof z.core.$ZodType ? z.toJSONSchema(schema, { io, target }) : undefined,
148
+ });
149
+ ```
150
+
151
+ ## createMutableRegistry
39
152
 
40
- `BaseRegistry` is the mutable opt-in for registrations that arrive at runtime, such as a plugin system: `register`, `has`, `get`, `getAll`, `getAllKeys`, `size` and `clear`. It warns when `register` overrides a key and does not check schemas. Use `createRegistry` unless the list is not known when the registry is built.
153
+ `createRegistry` and `createMutableRegistry` take `{ hint }`: the sentence that ends the message of an unregistered `$type`, exposed as the registry's optional `hint`, so a registry is a `NodeLookup` with its hint (`parseActions` and `safeParseNode` report it). `createMutableRegistry<MyRegistration>('Plugin')` is the mutable opt-in for registrations that arrive at runtime, such as a plugin system. It returns a `MutableRegistry`: the read side of a `createRegistry` result (`get`, `has`, `all`, `keys`, `size`, `kind`) plus `register` and `clear`, so either kind goes wherever a registry is read. `register` checks a registration as `createRegistry` does (`RegistryError` `'invalid-schema'`, `'invalid-child-paths'`, `'duplicate-child-path'`, `'nested-child-path'`, and the registry is unchanged when it throws), a repeated `$type` replaces the earlier one and keeps its position (or throws `'duplicate-type'` with `{ duplicates: 'error' }`), and nothing is logged. `all()` and `keys()` return the same frozen array until the next change. A function that finds a registration takes a `NodeLookup`, one that lists them takes an `ExportLookup`, and a registry of either kind is both. Use `createRegistry` unless the list is not known when the registry is built.
41
154
 
42
155
  ## YAML documents
43
156
 
@@ -1,73 +0,0 @@
1
- import type { BaseRegistration } from './types.js';
2
- /**
3
- * Base Registry - Abstract class for all registries
4
- *
5
- * Provides common registration, retrieval, and management functionality.
6
- * Each registry extends this to add type-specific behavior.
7
- *
8
- * All registrations must extend BaseRegistration which provides the unified `$type` field.
9
- *
10
- * @template TKey - The key type (typically string)
11
- * @template TValue - The value type (registration object extending BaseRegistration)
12
- */
13
- export declare abstract class BaseRegistry<TKey extends string, TValue extends BaseRegistration> {
14
- protected items: Map<TKey, TValue>;
15
- /**
16
- * Get the registry name for logging purposes.
17
- */
18
- abstract get registryName(): string;
19
- /**
20
- * Extract the key from an item.
21
- * Uses the unified `$type` field from BaseRegistration.
22
- * @param item - The item to extract the key from
23
- */
24
- protected getItemKey(item: TValue): TKey;
25
- /**
26
- * Extract the name from an item for logging.
27
- * Uses the `name` field from metadata.
28
- * @param item - The item to extract the name from
29
- */
30
- protected getItemName(item: TValue): string;
31
- /**
32
- * Register an item.
33
- *
34
- * @param item - The item to register
35
- */
36
- register(item: TValue): void;
37
- /**
38
- * Check if an item is registered.
39
- *
40
- * @param key - The key to check
41
- * @returns True if the item is registered
42
- */
43
- has(key: TKey): boolean;
44
- /**
45
- * Get a registered item.
46
- *
47
- * @param key - The key to retrieve
48
- * @returns The item or undefined if not found
49
- */
50
- get(key: TKey): TValue | undefined;
51
- /**
52
- * Get all registered items.
53
- *
54
- * @returns Array of all registered items
55
- */
56
- getAll(): TValue[];
57
- /**
58
- * Get all registered keys.
59
- *
60
- * @returns Array of all registered keys
61
- */
62
- getAllKeys(): TKey[];
63
- /**
64
- * Get the number of registered items.
65
- *
66
- * @returns The number of items in the registry
67
- */
68
- get size(): number;
69
- /**
70
- * Clear all registered items. Primarily for testing.
71
- */
72
- clear(): void;
73
- }
@@ -1 +0,0 @@
1
- import{Logger as m}from"@ecopages/logger";var s=new m("[@schema-engine/registry]"),a=class{items=new Map;getItemKey(e){return e.$type}getItemName(e){return e.metadata.name}register(e){let t=this.getItemKey(e),r=this.getItemName(e);if(this.items.has(t)){let i=this.items.get(t),n=i?this.getItemName(i):"unknown";s.warn(`Overriding ${this.registryName}: ${t}`,{previousName:n,newName:r})}this.items.set(t,e),s.debug(`Registered ${this.registryName}: ${t}`,{name:r})}has(e){return this.items.has(e)}get(e){return this.items.get(e)}getAll(){return Array.from(this.items.values())}getAllKeys(){return Array.from(this.items.keys())}get size(){return this.items.size}clear(){this.items.clear(),s.debug(`${this.registryName} cleared`)}};export{a as BaseRegistry};
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../src/base-registry.ts"],
4
- "sourcesContent": ["import { Logger } from '@ecopages/logger';\nimport type { BaseRegistration } from './types.js';\n\nconst logger = new Logger('[@schema-engine/registry]');\n\n/**\n * Base Registry - Abstract class for all registries\n *\n * Provides common registration, retrieval, and management functionality.\n * Each registry extends this to add type-specific behavior.\n *\n * All registrations must extend BaseRegistration which provides the unified `$type` field.\n *\n * @template TKey - The key type (typically string)\n * @template TValue - The value type (registration object extending BaseRegistration)\n */\nexport abstract class BaseRegistry<TKey extends string, TValue extends BaseRegistration> {\n\tprotected items = new Map<TKey, TValue>();\n\n\t/**\n\t * Get the registry name for logging purposes.\n\t */\n\tabstract get registryName(): string;\n\n\t/**\n\t * Extract the key from an item.\n\t * Uses the unified `$type` field from BaseRegistration.\n\t * @param item - The item to extract the key from\n\t */\n\tprotected getItemKey(item: TValue): TKey {\n\t\treturn item.$type as TKey;\n\t}\n\n\t/**\n\t * Extract the name from an item for logging.\n\t * Uses the `name` field from metadata.\n\t * @param item - The item to extract the name from\n\t */\n\tprotected getItemName(item: TValue): string {\n\t\treturn item.metadata.name;\n\t}\n\n\t/**\n\t * Register an item.\n\t *\n\t * @param item - The item to register\n\t */\n\tregister(item: TValue): void {\n\t\tconst key = this.getItemKey(item);\n\t\tconst name = this.getItemName(item);\n\n\t\tif (this.items.has(key)) {\n\t\t\tconst existing = this.items.get(key);\n\t\t\tconst existingName = existing ? this.getItemName(existing) : 'unknown';\n\t\t\tlogger.warn(`Overriding ${this.registryName}: ${key}`, {\n\t\t\t\tpreviousName: existingName,\n\t\t\t\tnewName: name,\n\t\t\t});\n\t\t}\n\n\t\tthis.items.set(key, item);\n\t\tlogger.debug(`Registered ${this.registryName}: ${key}`, {\n\t\t\tname,\n\t\t});\n\t}\n\n\t/**\n\t * Check if an item is registered.\n\t *\n\t * @param key - The key to check\n\t * @returns True if the item is registered\n\t */\n\thas(key: TKey): boolean {\n\t\treturn this.items.has(key);\n\t}\n\n\t/**\n\t * Get a registered item.\n\t *\n\t * @param key - The key to retrieve\n\t * @returns The item or undefined if not found\n\t */\n\tget(key: TKey): TValue | undefined {\n\t\treturn this.items.get(key);\n\t}\n\n\t/**\n\t * Get all registered items.\n\t *\n\t * @returns Array of all registered items\n\t */\n\tgetAll(): TValue[] {\n\t\treturn Array.from(this.items.values());\n\t}\n\n\t/**\n\t * Get all registered keys.\n\t *\n\t * @returns Array of all registered keys\n\t */\n\tgetAllKeys(): TKey[] {\n\t\treturn Array.from(this.items.keys());\n\t}\n\n\t/**\n\t * Get the number of registered items.\n\t *\n\t * @returns The number of items in the registry\n\t */\n\tget size(): number {\n\t\treturn this.items.size;\n\t}\n\n\t/**\n\t * Clear all registered items. Primarily for testing.\n\t */\n\tclear(): void {\n\t\tthis.items.clear();\n\t\tlogger.debug(`${this.registryName} cleared`);\n\t}\n}\n"],
5
- "mappings": "AAAA,OAAS,UAAAA,MAAc,mBAGvB,IAAMC,EAAS,IAAID,EAAO,2BAA2B,EAa/BE,EAAf,KAAkF,CAC9E,MAAQ,IAAI,IAYZ,WAAWC,EAAoB,CACxC,OAAOA,EAAK,KACb,CAOU,YAAYA,EAAsB,CAC3C,OAAOA,EAAK,SAAS,IACtB,CAOA,SAASA,EAAoB,CAC5B,IAAMC,EAAM,KAAK,WAAWD,CAAI,EAC1BE,EAAO,KAAK,YAAYF,CAAI,EAElC,GAAI,KAAK,MAAM,IAAIC,CAAG,EAAG,CACxB,IAAME,EAAW,KAAK,MAAM,IAAIF,CAAG,EAC7BG,EAAeD,EAAW,KAAK,YAAYA,CAAQ,EAAI,UAC7DL,EAAO,KAAK,cAAc,KAAK,YAAY,KAAKG,CAAG,GAAI,CACtD,aAAcG,EACd,QAASF,CACV,CAAC,CACF,CAEA,KAAK,MAAM,IAAID,EAAKD,CAAI,EACxBF,EAAO,MAAM,cAAc,KAAK,YAAY,KAAKG,CAAG,GAAI,CACvD,KAAAC,CACD,CAAC,CACF,CAQA,IAAID,EAAoB,CACvB,OAAO,KAAK,MAAM,IAAIA,CAAG,CAC1B,CAQA,IAAIA,EAA+B,CAClC,OAAO,KAAK,MAAM,IAAIA,CAAG,CAC1B,CAOA,QAAmB,CAClB,OAAO,MAAM,KAAK,KAAK,MAAM,OAAO,CAAC,CACtC,CAOA,YAAqB,CACpB,OAAO,MAAM,KAAK,KAAK,MAAM,KAAK,CAAC,CACpC,CAOA,IAAI,MAAe,CAClB,OAAO,KAAK,MAAM,IACnB,CAKA,OAAc,CACb,KAAK,MAAM,MAAM,EACjBH,EAAO,MAAM,GAAG,KAAK,YAAY,UAAU,CAC5C,CACD",
6
- "names": ["Logger", "logger", "BaseRegistry", "item", "key", "name", "existing", "existingName"]
7
- }