@alexify/metaschema 3.2.0 → 3.4.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 (62) hide show
  1. package/CHANGELOG.md +307 -1
  2. package/README.md +173 -89
  3. package/SECURITY.md +24 -1
  4. package/index.d.ts +601 -29
  5. package/package.json +28 -3
  6. package/src/checks.js +789 -0
  7. package/src/codec.js +201 -46
  8. package/src/coerce/index.d.ts +34 -0
  9. package/src/coerce/index.js +385 -0
  10. package/src/compile/emit.js +87 -28
  11. package/src/compile/index.js +9 -4
  12. package/src/context.js +6 -1
  13. package/src/definition/index.d.ts +19 -0
  14. package/src/definition/index.js +27 -0
  15. package/src/derive/index.d.ts +86 -0
  16. package/src/derive/index.js +273 -0
  17. package/src/errors.js +46 -4
  18. package/src/formats/index.d.ts +20 -8
  19. package/src/formats/index.js +450 -39
  20. package/src/generators/fromjsonschema.js +21 -2
  21. package/src/generators/index.js +1 -1
  22. package/src/generators/jsonschema.js +90 -21
  23. package/src/generators/typescript.js +11 -0
  24. package/src/index.js +3 -2
  25. package/src/issues.js +9 -7
  26. package/src/kinds.js +15 -3
  27. package/src/lint.js +38 -0
  28. package/src/locales/en.js +6 -0
  29. package/src/locales/uk.js +6 -0
  30. package/src/metadata.js +6 -24
  31. package/src/model/data.js +67 -10
  32. package/src/model/diff.js +7 -4
  33. package/src/model/index.js +1 -1
  34. package/src/model/infer.js +10 -3
  35. package/src/model/merge.js +16 -9
  36. package/src/model/restore.js +52 -7
  37. package/src/model/sample.js +28 -4
  38. package/src/model.js +54 -56
  39. package/src/mongodb/bson.js +130 -0
  40. package/src/mongodb/document.js +217 -0
  41. package/src/mongodb/index.d.ts +133 -0
  42. package/src/mongodb/index.js +24 -0
  43. package/src/mongodb/indexes.js +79 -0
  44. package/src/mongodb/update.js +258 -0
  45. package/src/preprocessor.js +1 -2
  46. package/src/prototypes/abstract.js +41 -67
  47. package/src/prototypes/collections.js +3 -90
  48. package/src/prototypes/flags.js +34 -0
  49. package/src/prototypes/json.js +0 -11
  50. package/src/prototypes/reference.js +0 -76
  51. package/src/prototypes/scalars.js +17 -96
  52. package/src/prototypes/schema.js +1 -10
  53. package/src/prototypes/tuple.js +0 -26
  54. package/src/prototypes/union.js +12 -82
  55. package/src/rules.js +33 -157
  56. package/src/schema.js +105 -220
  57. package/src/snapshot.js +216 -41
  58. package/src/stream/index.js +1 -1
  59. package/src/struct.js +6 -91
  60. package/src/types.js +43 -6
  61. package/src/util.js +43 -0
  62. package/src/validation.js +313 -0
package/CHANGELOG.md CHANGED
@@ -7,6 +7,310 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [3.4.0] - 2026-10-16
11
+
12
+ 3.4 makes the snapshot a contract a program can build on and the language complete for the
13
+ programs that encode from it. A schema writes its own snapshot (`schema.toSnapshot()`, with the
14
+ entities it reaches and its name as `root`), the guarantees of format 1 are written down, and
15
+ the typings narrow a field of a snapshot on its type; a schema names itself without a model;
16
+ binary data (`bytes`), named switches (`flags`) and a number of decimals (`decimals`) are built
17
+ in. The checks are compiled on their first use, which makes building a schema 13 to 15% faster,
18
+ and the core is split into two halves over the same classes, so that a client that reads
19
+ schemas without validating them imports `@alexify/metaschema/definition`, 10.3 KB, about half
20
+ of the core. The two new type names change what a struct whose first key is `bytes` or `flags`
21
+ reads as, and a program that registered either as a custom type of its own (protoarray 1.2's
22
+ `types`) drops that entry: see Changed. The review of the release before its tag kept bundlers
23
+ from dropping the import that installs validation, made the snapshot of a schema whole (what a
24
+ reused schema reaches, the values that have no JSON form, copies of the metadata) and its
25
+ restore strict, bounded binary data by a `length`, and moved the gates to 22 KB for the core
26
+ and 11 KB for `./definition`.
27
+
28
+ ### Added
29
+
30
+ - **`schema.toSnapshot()`.** The snapshot of format 1 for one schema: the schema and every
31
+ entity it reaches through its references (the parent of a projection included), each after
32
+ the ones it references in the order a walk from the schema meets them, with the name of the
33
+ schema as the new optional key `root` (`''` for an anonymous schema) and no `database`
34
+ metadata. `fromJSON` restores it (`model.entities.get(snapshot.root)`
35
+ is the schema again, and `toSnapshot()` of it writes the same text), and `fromJSON` and `diff`
36
+ check that `root` names one of its entities (`ERR_INVALID_SNAPSHOT`). Two schemas of one name
37
+ in what a schema reaches (one derived from an entity keeps its name) cannot be one snapshot:
38
+ `ERR_UNREPRESENTABLE`, and so are two custom types of one name from two registries. A Schema
39
+ reused as a field (`{ inner: Inner }`) resolves its references and types through itself, as its
40
+ fields do, and an anonymous schema of a model is the entity of the name the model gives it.
41
+ `snapshot.js` shares the walk between the two writers, a loop rather than a recursion, so a
42
+ chain of entities of any length orders; `model.toJSON()` does not change.
43
+ - **What format 1 guarantees**, written down in the model guide: the fields of a struct in the
44
+ order of the definition, the id field of a stored kind after them, the entities each after the
45
+ ones they reference (`model.order` for a model), the tags as they are, and keys only ever
46
+ added. A change of any of them is a
47
+ major release.
48
+ - **A typed snapshot.** `FieldSnapshot` is a union that narrows on `type`: a string with its
49
+ rules, a number with its bounds and `decimals`, the scalars, an enum with `enum`, `flags`
50
+ with `flags`, a list or a dictionary with `value` (and `key`), a tuple with its elements, a
51
+ nested struct with `schema`, a union with `union` and `discriminator`, a reference by the
52
+ capitalized name of its entity with `one`/`many` and `embed`, a custom type by the names of
53
+ `CustomTypes`, `bytes` with its `length` (`BytesFieldSnapshot`). `SchemaSnapshot` is what
54
+ `toSnapshot()` returns; `BytesSnapshot`, `MapSnapshot` and `SetSnapshot` type the new tags.
55
+ - **Bytes, a Map and a Set are tagged in a snapshot** (`{ $bytes: 'AQL/' }`, `{ $map: [[k, v]] }`,
56
+ `{ $set: [v] }`), beside `$date` and `$bigint`, and `fromJSON` reads them back into their
57
+ values: a `default` or the `examples` of such a field restore as values of the field (a Map
58
+ and a Set were written as `{}`, bytes as an object of indices). A tag that does not read is
59
+ `ERR_INVALID_SNAPSHOT`.
60
+ - **`bytes`**, a built-in type: a `Uint8Array` of any realm, a `Buffer` included, told by the
61
+ name the engine keeps in the view (`isBytes` of `util.js`), never by `instanceof` or a key of
62
+ the value. `length` counts its bytes, on both backends. `Uint8Array` in TypeScript and
63
+ `Infer`; base64 text on the input side of a JSON Schema (`format: 'byte'` for OpenAPI 3.0,
64
+ `length` as `minLength`/`maxLength` of the text; the strict profile keeps the type only),
65
+ unrepresentable on its output side (as a `date`), `binData` for mongodb; random bytes within
66
+ the length in `sample`; `bytes` in `infer` for the views of the samples; canonical base64 read into bytes by `./coerce` (padded, the unused bits at zero;
67
+ `''`, the text of no bytes, as an empty `Uint8Array`, the one exception to the rule that `''`
68
+ is never converted; a scan of the text, linear and without the stack of a repeated group, so
69
+ a valid text of megabytes converts; a text whose bytes would be over `length.max` is left
70
+ undecoded, for the check to reject); a generic Binary of the driver (subtype 0, or 2) read
71
+ back into a copy of its bytes by `fromDocument` of `./mongodb`, any other subtype (a UUID, an
72
+ encrypted value) left for the check, so that it is never written back as generic binary
73
+ data.
74
+ - **`flags`**, a built-in type: `{ flags: ['read', 'write'] }` is an object of those names,
75
+ each a boolean, any left out. A name the list does not have is `unexpected` under the
76
+ unknown-keys policy of the check, ignored under `unknown: 'ignore'`, left out by `parse`
77
+ under `strip`; a list that is not one of distinct names is `ERR_INVALID_DEFINITION`. An
78
+ object of optional booleans in TypeScript and `Infer`, an object of boolean properties in
79
+ JSON Schema (closed with the document; every name required under the strict profile), a
80
+ random set of switches in `sample`; `merge` keeps the names both have, and `compatibility`
81
+ reads them as the values of an enum. The list is a frozen copy of the program's.
82
+ - **`decimals`**, a rule of `number` (0 to 15): the value times 10ⁿ is a whole number to
83
+ within 256 units in the last place, so `0.1 + 0.2` has two decimals and `12345678.123` does
84
+ not; NaN and the infinities have none to count. A new issue code, `decimals` (`{ decimals }`,
85
+ and `received` naming NaN or an infinity), with a renderer in both locales; a new warning,
86
+ `unenforceable-decimals`, where the bounds of the field reach 2⁴³ units of the last decimal,
87
+ past which every number passes (thirteen decimals or more without bounds, two with
88
+ `max: 1e12`); `multipleOf` in JSON Schema (read back by `fromJSONSchema`);
89
+ drawn with its decimals by `sample`; the fewer of the two in `merge`; an upper bound in
90
+ `compatibility`.
91
+ - **`@alexify/metaschema/definition`**, the half of the core that builds schemas and models and
92
+ reads them (fields, metadata, `toJSON`, `toSnapshot`), on its own: 10.3 KB min+gzip, gated at
93
+ 11 KB. Its `Schema` and `Model` are the core's; a schema it builds says `ERR_NOT_REGISTERED`
94
+ (with the `method`) when it is asked to validate (`check`, `parse`, `serialize`, `validate`,
95
+ the async pair, the `check` of a field, the warnings) until the program loads the core entry,
96
+ and validates from then on, the schemas built before and a method taken from them before
97
+ (`const { check } = schema`) included; it has no `~standard` until then. A schema of another
98
+ copy of the package (two versions installed side by side) says that the core loaded is
99
+ another copy. `./derive` and `./formats` work beside it alone; a bundle of it and the core
100
+ carries each module once, and `import '@alexify/metaschema'` for the validation it installs
101
+ survives a bundler (`sideEffects` lists the entries and `src/validation.js`).
102
+ - `pnpm size` measures `./definition` on its own (`--max-gzip-definition`); `graph.test.js`
103
+ pins that the definition half, `./derive` and `./formats` reach no module of the validation
104
+ half. `pnpm run size:gate` is `pnpm size` with the budgets as gates, the one place they are
105
+ written, which CI and `prepublishOnly` run.
106
+
107
+ ### Changed
108
+
109
+ - **The checks are compiled on their first use**: a field on the first read of its `check`, a
110
+ struct on its first check (`checkOf`, kept beside its frozen plan, whose entries no longer
111
+ hold the checks), a schema through a stub of `Schema[RUN]` that takes the closures' place. A
112
+ schema that is only read never compiles them: `Schema.from` is 13 to 15% faster, `new Model`
113
+ 5%, and `check` and `parse` are at parity on both backends. What a definition must reject is
114
+ still found when it is built (a `max` below `min`, a format not registered), and the test of
115
+ a format is the one named when the field was built.
116
+ - **The core is two halves.** The definition half (`schema.js`, `model.js`, `types.js`, the
117
+ prototypes, `struct.js`, `rules.js`, `snapshot.js`) builds; the validation half
118
+ (`validation.js`, `checks.js`, `codec.js`, `context.js`, `issues.js`, `result.js`,
119
+ `lint.js`, the locale) installs `check`, `parse` and their kin, `~standard`, the warnings and
120
+ `checkConsistency` on the classes, and the type check of every built-in on the prototype
121
+ object the classes of the type inherit from. The core entry loads both; nothing changes for a
122
+ program that imports it. The state the validation half keeps on a schema is held under
123
+ symbols, and `fields[STRUCT]` is `{ plan, known, calculated }` (the check is `checkOf`).
124
+ - **`bytes` and `flags` are type names**, so a struct whose first key is one of them
125
+ (`{ flags: ['a'], name: 'string' }`) reads as that type now, as `{ date, place }` reads as a
126
+ date: give it a kind (`{ Struct: {}, flags: … }`). A table of custom types of the program
127
+ under either name (`bytes` and `flags` of protoarray 1.2's `types`, for one) is
128
+ `ERR_TYPE_REGISTERED`: leave those entries out, the built-ins check the same values (only
129
+ `{ metadata }` may still be added). `infer` writes `bytes` for a `Uint8Array` among the
130
+ samples (it wrote a dictionary of its indices).
131
+ - **The core gate is 22 KB** (was 19): `toSnapshot`, the two types and the rule cost the core
132
+ about 1.0 KB, the lazy checks and the split about 0.8 KB, the review about 0.9 KB; the core
133
+ measures 21.3 KB. The generators gate is 8 KB (was 7.5; the two types and the rule took the
134
+ subpath to 7.7 KB); a new gate of 11 KB for `./definition` (10.3 KB).
135
+ - **The `compile` of a custom type of its own runs on the first check** of its field, as every
136
+ check is compiled now (when the schema is built under the JIT): what it throws is
137
+ `ERR_INVALID_CUSTOM_TYPE` located at the schema, with the error as the cause.
138
+ - **What a snapshot holds is a copy.** The `custom` metadata of a kind, the index definitions
139
+ and the `database` metadata were the model's own objects inside the snapshot; they are written
140
+ as any value is now, their functions, bigints and dates tagged.
141
+ - **A discriminator field that is optional or nullable is `ERR_INVALID_UNION`**
142
+ (`'kind?'`, `required: false`, `nullable: true` on the field a `discriminator` names), as a
143
+ `default` on it already was: a value without the tag or with `null` is in no branch, so such a
144
+ branch could never be picked. A definition of that kind built until now and rejected every
145
+ value without the tag; it throws when it is built now, a snapshot that says so does not
146
+ restore, and an OpenAPI document whose branch does not require its discriminator does not
147
+ build. protoarray holds the same rule.
148
+ - **`prepublishOnly` runs both backends and the bundle budgets** (`test:jit`, `test:nojit`,
149
+ `size:gate`) besides the gates it ran, so that a release from a machine is held to what CI
150
+ holds; the release process tags the squash commit on `main`.
151
+ - The warnings of a schema and of a model (`schema.warnings`, `schema.checkConsistency()`,
152
+ `model.warnings`) are computed by the validation half, kept in a WeakMap, and the cycles a
153
+ model meets while ordering its entities are recorded as data; their text is the same.
154
+ - `compiled()` of `./compile` tells a generated check by a set of the functions it built, since
155
+ the closures of a schema may now be compiled after the JIT was turned off.
156
+
157
+ ### Fixed
158
+
159
+ - **A schema resolves its own name without a model.** `new Schema('Category', { name:
160
+ 'string', parent: '?Category' })` checked `parent` as `Entity "Category" is not found`; the
161
+ schema is now the fallback of `findReference` after the attached models (which come first,
162
+ so a schema that shares the name of their entity still reaches the entity). A projection of
163
+ its own name is `ERR_PROJECTION`, not a crash.
164
+ - **A snapshot of a model whose alias type names another alias** (`cents: { js: 'money' }`)
165
+ left out the type it names, so `fromJSON` could not restore it (`ERR_UNKNOWN_JS_TYPE`); the
166
+ custom types down the chain of an alias are written now.
167
+ - `types.md` said the formats subpath registers nine formats; it registers 35.
168
+ - **A Schema reused as a field is consistent.** `checkConsistency()` and `model.warnings`
169
+ resolved the references of a schema reused as a field (`{ inner: Inner }`) through the schema
170
+ that reuses it, and warned that they were missing; a snapshot of a model left out the custom
171
+ types of such a schema from another registry. They resolve as the fields do now.
172
+ - **A snapshot is data where it names a Date or a RegExp.** A value of a snapshot such as
173
+ `{ "constructor": { "name": "Date" } }` passed `fromJSON`, and `toJSON`, `toSnapshot` and
174
+ `diff` then threw a bare `TypeError`; a Date and a RegExp are told by their shape, as the
175
+ checks tell them since 3.2.
176
+ - **`fromJSON` refuses what a model cannot be built from**: a field key `root` (a reserved key of
177
+ a definition now, which replaced the schema of the field and made every later read of it
178
+ throw), a kind that is no lowercase name, an entity named like the ones a model skips (`.x`),
179
+ a parent that is no name; anything else the model cannot build is `ERR_INVALID_SNAPSHOT` with
180
+ the cause. The parent of a kind other than a projection is restored, so such a model reads
181
+ back to the same text.
182
+ - **A model of a chain of a few thousand entities** overflowed the stack while ordering them (a
183
+ bare `RangeError` out of `new Model` and `fromJSON`); the order is a loop.
184
+ - **A schema derived or merged from one that names itself** reaches it: `partial(category)`
185
+ checked the parent as a partial category, `pick()` under another name did not find it, and
186
+ `extend()` and `merge()` lost the self-reference of the second schema.
187
+ - **The JSON Schema of an anonymous schema of a model** was defined under `''`; it is defined
188
+ under the name the model gives it.
189
+ - **The TypeScript of a field with a `flags` option** of another type (`{ type: 'string', flags:
190
+ 'gi' }`) was an object of switches; a field is flags by its type.
191
+ - **The JIT wrote the numbers of `decimals` into the generated source** as they were; they are
192
+ literals of the code builder now, and both backends run one test (`decimalsOff`).
193
+
194
+ ## [3.3.0] - 2026-10-14
195
+
196
+ 3.3 closes the gaps the comparison with the alternatives showed. `parse` converts the text of a
197
+ query string, a form or a file to the types of the fields when asked (coercion), schemas are
198
+ derived from schemas (`pick`, `omit`, `partial`, `required`, `extend`, `keyof`), the string
199
+ formats grow from nine to 35, and the `@alexify/metaschema/mongodb` subpath is the schema side
200
+ of a MongoDB program without a dependency on the driver. The review of the release before its
201
+ tag made the converters and five formats linear in the stack as well as in time on strings of
202
+ megabytes, capped the `regex` format, and closed the ways a document could carry a foreign
203
+ `_id` or throw on `null`. The changes in behaviour (`coerce` is a reserved key, `infer` writes
204
+ the more specific formats, a format of the program under the name of a new built-in takes its
205
+ place) are listed under Changed.
206
+
207
+ ### Added
208
+
209
+ - **Coercion.** `parse(value, { coerce: true })`, the kind metadata
210
+ `{ Form: { coerce: true } }` (so `~standard.validate` too) or a field's `coerce: true|false`
211
+ converts the input to the types of the fields before the check: decimal strings to numbers
212
+ and bigints, `'true'`/`'false'`/`'1'`/`'0'` to booleans, ISO dates with their zone (and epoch
213
+ milliseconds) to `Date`, a single value to a list, an array to a `Set`, an object to a `Map`,
214
+ the written form of an enum member to the member. The converters are strict and never touch
215
+ the empty string; a value a union branch accepts as it is is not converted; `check` never
216
+ converts, and `Infer` does not change. The core has the policy and a step in the pass before
217
+ the check; the converters are the new `@alexify/metaschema/coerce` subpath's
218
+ (`register(custom)` adds the program's own by type name, an alias type converts as its base),
219
+ and `coerce(schema, value)` is that pass alone. A parse that coerces before `register()` is
220
+ `ERR_NOT_REGISTERED` as it enters the schema, whatever the value holds (an empty body does
221
+ not hide a missing `register()`); `register(custom)` checks every entry before it writes
222
+ any; `ERR_INVALID_COERCION` and `ERR_COERCION_REGISTERED` are new codes. The converters are
223
+ linear on hostile strings (a run of a hundred thousand digits that is not a number costs
224
+ nothing), and `toMap` converts a plain object or a list of pairs only.
225
+ `register(custom, { onError })` is told of a converter that threw (the value is left to the
226
+ check either way), the policy is read from own keys only (a `coerce` set on
227
+ `Object.prototype` elsewhere turns nothing on), and `coerce` on a reference checked as an id
228
+ or on a field of `any`, `unknown`, `json` or `null` is a `dead-coerce` warning. The converter
229
+ of a field is resolved once and kept with the field (a JIT parse that coerces is 11% faster
230
+ than with a lookup per value, a parse of enums of 32 members 2.3 times: the members and their
231
+ written forms are indexed once). `pnpm bench` has rows for a nested struct, plain unions,
232
+ enums and a plain and a coercing parse in turn, and for `toDocument`/`fromDocument`.
233
+ `coerce(schema, value, { report })` fills the array given with the path of every key the
234
+ pass changed; `new Model(types, entities, database, { coercions })` gives a model converters
235
+ of its own type names, read before the process-wide table for the fields of its entities
236
+ (what an isolated registry is to the types); the branches of a plain union are prepared
237
+ first and tried only when one of them changes the value, so a parse over a union of records
238
+ that nest unions is linear where nothing applies (4 times faster at a depth of 12).
239
+ - **`@alexify/metaschema/derive`.** `pick`, `omit`, `partial` (`keys`, `deep`, `defaults`),
240
+ `required`, `extend` and `keyof` build a new Schema from the definition a schema was built
241
+ from: a stored kind or a projection becomes a struct without the id of the kind (unless
242
+ named), `partial` leaves the defaults out, `pick`, `omit` and `partial` drop the schema's own
243
+ functions, `extend` replaces fields in place (where `merge` unifies), indexes stay while their
244
+ columns do. `register()` installs them as methods (`schema.omit(['id']).partial()`), typed by
245
+ the definition. `ERR_UNKNOWN_FIELD` names a key the schema has no field of.
246
+ - **26 string formats.** `ulid`, `jwt`, `nanoid`, `cuid2`, `iso-date-time`, `iso-time`,
247
+ `duration`, `cidrv4`, `cidrv6`, `mac`, `url`, `uri-reference`, `uri-template`,
248
+ `json-pointer`, `relative-json-pointer`, `regex`, `e164`, `iban`, `hex-color`, `base64`,
249
+ `base64url`, `hex`, `emoji`, `semver`, `slug` and `credit-card` (the expressions of
250
+ ajv-formats, zod, valibot and semver.org, held to them value by value). A format entry may
251
+ carry a `pattern`, which `toJSONSchema` writes beside a name JSON Schema does not know (the
252
+ one assertion of the mongodb target) and `fromJSONSchema` drops again; OpenAPI's `byte` is
253
+ `base64`. No built-in test overflows the stack of the regex engine on a string of
254
+ megabytes: `email`, `json-pointer`, `relative-json-pointer`, `uri-template`, `slug` and
255
+ `semver` are read by a scanner with the same verdicts, and a `regex` longer than 4096
256
+ characters is not one (compiling it costs memory in proportion). `register()` returns the
257
+ names of the built-in formats the call replaced with the program's own.
258
+ - **`@alexify/metaschema/mongodb`.** The BSON types `objectId`, `decimal128` and `binary`
259
+ (recognized without importing bson), `register({ bson })` with the program's driver,
260
+ `toDocument`/`fromDocument` (the id of a stored record as `_id`, ids of references as
261
+ ObjectIds, and back), `indexesOf` for `createIndexes`, `checkUpdate`/`toUpdate` for the
262
+ driver's updates by dotted path. No I/O and no dependency. An `_id` beside the id field of a
263
+ record is not written (`toDocument` of a body checked with `unknown: 'ignore'` cannot
264
+ choose the `_id`), `fromDocument(schema, null)` is a `type` issue rather than a throw, a
265
+ value of a class at the root is `ERR_INVALID_TARGET`, reading a document and `ids:
266
+ 'string'` need no driver, and `binary` is coerced from text of the base64 shape only. The
267
+ walks of a document stop at `maxDepth` (128, an option of `toDocument` and `toUpdate`) as
268
+ the check does, instead of recursing until the stack ends; `checkUpdate` reports a path with
269
+ an empty segment, into a part a field cannot have or to the `_id` of the document whatever
270
+ the policy for unknown keys says, a path through more records than `maxDepth` as a `depth`
271
+ issue, and names what an operator takes in its issues (`array` for a `$push` on a field
272
+ that is no list, `number` for an `$inc` on a string); `register({ bson })` installs the
273
+ converters of the BSON types the module can build only, `decimal128` is coerced from a
274
+ decimal written as one or a finite number (`fromString` of the driver reads `NaN`, `inf`
275
+ and an exponent), and an element of a list of ids (`partners.0`) is an id in `checkUpdate`
276
+ and `toUpdate`. The subpath is tested against the real `bson` (a devDependency) as well as
277
+ the fakes.
278
+ - **`ids: 'objectId'`** for the mongodb target of `toJSONSchema`: the validator of the
279
+ documents `toDocument` writes.
280
+ - `pnpm size` measures a subpath on top of another it requires (`./mongodb` on `./coerce`).
281
+
282
+ ### Changed
283
+
284
+ - **The core gate is 19 KB** (was 17.75 KB): coercion costs the core about 360 bytes; the core
285
+ measures 18.6 KB. The formats gate is 5 KB (was 2 KB; the scanners of the review took the
286
+ subpath to 4.0 KB), the compile gate 5 KB (was 4.25) and the model gate 13 KB (was 12): a
287
+ gate is raised to the next whole KB when a fix needs it, and never sits a few bytes over a
288
+ subpath. New gates: 2.5 KB for `./derive`, 2 KB for `./coerce`, 4 KB for `./mongodb` (3.5 before the review: the depth limit and the markers of the paths took the subpath over it).
289
+ - **`coerce` is a reserved key** of a field definition and of the kind metadata. A field
290
+ `coerce` that is not a boolean is `ERR_INVALID_DEFINITION` (was an `unknown-option` warning),
291
+ a kind metadata `coerce` that is not a boolean is `ERR_INVALID_OPTIONS` (was an ordinary
292
+ custom key), and a kind metadata `coerce: true` makes every `parse` of the schema need
293
+ `register()` of `./coerce`.
294
+ - **An option of a call that is not what it must be carries `code: 'ERR_INVALID_OPTION'`**
295
+ (a new `RuntimeErrorCode`): the `TypeError` of `maxErrors`, `references`, `root`, the
296
+ `coerce` of a parse, and of the options of `./stream`, `./derive` and `./mongodb` had no
297
+ code. The options of `./derive` are the call's (`keys` that is no list, options that are no
298
+ object are `ERR_INVALID_OPTION`, a `TypeError`; they were `ERR_INVALID_OPTIONS`, a
299
+ `SchemaDefinitionError`); its `metadata` stays a definition (`ERR_INVALID_OPTIONS`), and
300
+ `keyof` with a `metadata` is `ERR_INVALID_OPTIONS` (a schema of an enum has no kind; it was
301
+ ignored).
302
+ - The rule of the id field of a stored kind (`orderId`, `id` for an anonymous schema) is
303
+ `idFieldOf` of `kinds.js`, read by `./derive`, `./mongodb` and `toJSONSchema`; the alias
304
+ chain of a custom type ends in `baseTypeOf` of `types.js`, read by the generators, `sample`
305
+ and `checkUpdate`; the shapes of the walks of `./mongodb` are named once (`SHAPES`) and held
306
+ to the core's by a test.
307
+ - **`infer` writes the more specific formats**: a column of http(s) addresses is `url` (was
308
+ `uri`), local date-times are `iso-date-time`, ULIDs `ulid`, durations `duration`.
309
+ - **A format of the program under the name of a built-in takes its place** instead of throwing
310
+ `ERR_FORMAT_REGISTERED`, so a format a program registered as `ulid` before 3.3 keeps working.
311
+ - `merge` and `derive` share the code that turns a schema back into a definition
312
+ (`model/data.js`).
313
+
10
314
  ## [3.2.0] - 2026-10-12
11
315
 
12
316
  3.2 takes a schema to the records around it. The new `@alexify/metaschema/stream` subpath runs
@@ -1274,7 +1578,9 @@ published.
1274
1578
 
1275
1579
  ### [metaschema 0.x][upstream-0.x] - First generation of metaschema
1276
1580
 
1277
- [unreleased]: https://github.com/Alexis-Technologies/metaschema/compare/v3.2.0...HEAD
1581
+ [unreleased]: https://github.com/Alexis-Technologies/metaschema/compare/v3.4.0...HEAD
1582
+ [3.4.0]: https://github.com/Alexis-Technologies/metaschema/compare/v3.3.0...v3.4.0
1583
+ [3.3.0]: https://github.com/Alexis-Technologies/metaschema/compare/v3.2.0...v3.3.0
1278
1584
  [3.2.0]: https://github.com/Alexis-Technologies/metaschema/compare/v3.1.0...v3.2.0
1279
1585
  [3.1.0]: https://github.com/Alexis-Technologies/metaschema/compare/v3.0.0...v3.1.0
1280
1586
  [3.0.0]: https://github.com/Alexis-Technologies/metaschema/compare/v2.0.0...v3.0.0