@alexify/metaschema 3.2.0 → 3.3.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.
package/README.md CHANGED
@@ -63,9 +63,20 @@ event.parse({ name: 'deploy', when: '2026-10-10T12:00:00.000Z' }).value;
63
63
  value (a date-time string into a `Date`) and `serialize` the way back; `checkAsync` and
64
64
  `parseAsync` await validators and decoders that return promises.
65
65
  - **String formats.** `{ type: 'string', format: 'email' }` is a rule beside `length` and
66
- `pattern`; `@alexify/metaschema/formats` registers `uuid`, `email`, `date-time`, `date`,
67
- `time`, `ipv4`, `ipv6`, `uri`, `hostname` and your own, and the name travels into JSON Schema,
68
- samples and inference.
66
+ `pattern`; `@alexify/metaschema/formats` registers 35 formats (`uuid`, `ulid`, `jwt`,
67
+ `email`, `date-time`, `duration`, `ipv4`, `cidrv6`, `url`, `json-pointer`, `e164`, `iban`,
68
+ `base64`, `semver`, …) and your own, and the name travels into JSON Schema, samples and
69
+ inference.
70
+ - **Coercion.** `parse` with `coerce: true` (a call, a schema or a field) converts the text of a
71
+ query string, a form or a CSV row to the types of the fields before the check (`'42'` to a
72
+ number, an ISO string to a `Date`), strictly and never in `check`; `coerce()` of
73
+ `@alexify/metaschema/coerce` is that step alone.
74
+ - **Deriving schemas.** `pick`, `omit`, `partial` (`deep` too), `required`, `extend` and `keyof`
75
+ of `@alexify/metaschema/derive` make the create and update bodies and the views of an entity
76
+ from the entity, typed by its definition.
77
+ - **MongoDB.** `@alexify/metaschema/mongodb` is the schema side of Mongoose without the driver
78
+ dependency: BSON types, `_id` and ObjectId references written and read back, the indexes and
79
+ the collection validator of a model, and the driver's updates checked against the schema.
69
80
  - **Records and streams.** `checkEach` and `parseEach` of `@alexify/metaschema/stream` run a
70
81
  schema over an iterable of records, lazily and in order, yielding `{ index, record, result }`
71
82
  for each; the async pair keeps `concurrency` records in flight over a sync or async source,
@@ -97,10 +108,11 @@ event.parse({ name: 'deploy', when: '2026-10-10T12:00:00.000Z' }).value;
97
108
  schemas (`merge`) and infers a definition from the values that exist (`infer`); `aliases` and
98
109
  `deprecated` let a model carry its history, and `fromJSONSchema` of the generators reads a
99
110
  JSON Schema document back.
100
- - **Zero dependencies, 17.7 KB min+gzip.** CommonJS with ESM named imports, no build step,
101
- one package for Node.js and browsers; the generators add 7.1 KB, the JIT backend 4.2 KB, the
102
- model tools 12.0 KB, the record tools 1.0 KB and the string formats 1.3 KB where they are
103
- imported.
111
+ - **Zero dependencies, 18.6 KB min+gzip.** CommonJS with ESM named imports, no build step,
112
+ one package for Node.js and browsers; the generators add 7.3 KB, the JIT backend 4.2 KB, the
113
+ model tools 12.0 KB, the record tools 1.0 KB, the string formats 4.0 KB, the derive tools
114
+ 1.9 KB, the converters of coercion 1.7 KB and the MongoDB tools 3.5 KB (on top of the
115
+ converters, which they require) where they are imported.
104
116
 
105
117
  ## Benchmarks
106
118
 
@@ -144,21 +156,21 @@ only to Ajv, and 6 to 100 times faster than the other TypeScript-first validator
144
156
 
145
157
  | Library | Flat object, parseSafe<br><sub>ops/s</sub> | Flat object, parseStrict<br><sub>ops/s</sub> | Flat object, assertLoose<br><sub>ops/s</sub> | Flat object, assertStrict<br><sub>ops/s</sub> | Nested object, parseSafe<br><sub>ops/s</sub> | Nested object, parseStrict<br><sub>ops/s</sub> | Nested object, assertLoose<br><sub>ops/s</sub> | Nested object, assertStrict<br><sub>ops/s</sub> | Every issue of an invalid value<br><sub>ops/s</sub> | Build a schema<br><sub>schemas/s</sub> |
146
158
  | --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: |
147
- | **metaschema**<br><sub>check() · compile(), JIT · v3.2.0</sub> | 47,400,000 | 38,800,000 | 48,400,000 | 40,200,000 | 41,500,000 | 29,500,000 | 43,700,000 | 30,200,000 | 6,600,000 | 32,300 |
148
- | **metaschema**<br><sub>check() · closures · v3.2.0</sub> | 9,690,000 | 8,670,000 | 9,820,000 | 8,980,000 | 4,950,000 | 4,660,000 | 4,980,000 | 4,640,000 | 3,120,000 | 201,000 |
149
- | Metarhia metaschema<br><sub>check() · strict only · v2.2.2</sub> | — | 925,000 | — | 931,000 | — | 534,000 | — | 538,000 | 420,000 | 283,000 |
150
- | Zod<br><sub>safeParse() · v4.6.6</sub> | 26,800,000 | 12,300,000 | 27,100,000 | 12,800,000 | 16,700,000 | 7,200,000 | 16,600,000 | 7,170,000 | 447,000 | 80,600 |
151
- | Valibot<br><sub>safeParse() · is() · v1.5.0</sub> | 3,440,000 | 2,940,000 | 3,570,000 | 2,910,000 | 2,070,000 | 1,740,000 | 2,030,000 | 1,770,000 | 1,130,000 | 2,070,000 |
152
- | ArkType<br><sub>type(value) · allows() · v2.2.8</sub> | 49,700,000 | 7,270,000 | 169,000,000 | 8,560,000 | 37,600,000 | 4,220,000 | 131,000,000 | 4,730,000 | 67,100 | 14,700 |
153
- | Effect Schema<br><sub>decodeUnknownResult() · is() · v4.0.3</sub> | 4,040,000 | 1,930,000 | 4,080,000 | 1,910,000 | 2,270,000 | 993,000 | 2,240,000 | 1,000,000 | 367,000 | 675,000 |
154
- | TypeBox<br><sub>Compile(…).Check() · v1.3.36</sub> | 164,000,000 | 78,200,000 | 186,000,000 | 81,700,000 | 119,000,000 | 42,700,000 | 136,000,000 | 43,600,000 | 90,900 | 36,300 |
155
- | TypeBox<br><sub>Value.Check() · v1.3.36</sub> | 258,000 | 190,000 | 261,000 | 188,000 | 166,000 | 116,000 | 166,000 | 117,000 | 90,600 | 429,000 |
156
- | Ajv<br><sub>compile(…)(value), draft 2020-12 · v8.20.0</sub> | 64,600,000 | 34,100,000 | 69,900,000 | 35,100,000 | 50,700,000 | 23,200,000 | 54,800,000 | 23,900,000 | 14,800,000 | 1,820 |
157
- | Yup<br><sub>validateSync() · isValidSync(), strict · v1.7.1</sub> | 301,000 | 291,000 | 305,000 | 291,000 | 181,000 | 172,000 | 182,000 | 173,000 | 11,500 | 54,600 |
158
- | Joi<br><sub>validate(), convert: false · v18.2.9</sub> | 819,000 | 834,000 | 796,000 | 830,000 | 528,000 | 529,000 | 520,000 | 532,000 | 258,000 | 38,600 |
159
- | Superstruct<br><sub>validate() · is() · v2.0.2</sub> | 480,000 | 436,000 | 486,000 | 431,000 | 293,000 | 260,000 | 298,000 | 260,000 | 102,000 | 1,810,000 |
160
-
161
- _Apple M3 Max · 16 cores · Node v24.14.1 · median of 5 × 1 s samples, each library in a fresh process · 2026-10-11. Medians, rounded to three significant figures; — where the library cannot express the mode._
159
+ | **metaschema**<br><sub>check() · compile(), JIT · v3.3.0</sub> | 48,400,000 | 38,900,000 | 49,700,000 | 40,800,000 | 42,000,000 | 29,900,000 | 44,100,000 | 30,300,000 | 6,650,000 | 32,300 |
160
+ | **metaschema**<br><sub>check() · closures · v3.3.0</sub> | 9,430,000 | 9,020,000 | 10,000,000 | 9,200,000 | 5,100,000 | 4,810,000 | 5,090,000 | 4,750,000 | 3,000,000 | 190,000 |
161
+ | Metarhia metaschema<br><sub>check() · strict only · v2.2.2</sub> | — | 958,000 | — | 959,000 | — | 550,000 | — | 546,000 | 428,000 | 282,000 |
162
+ | Zod<br><sub>safeParse() · v4.6.6</sub> | 26,500,000 | 12,800,000 | 27,800,000 | 12,700,000 | 16,700,000 | 7,340,000 | 16,900,000 | 7,160,000 | 445,000 | 82,100 |
163
+ | Valibot<br><sub>safeParse() · is() · v1.5.0</sub> | 3,570,000 | 2,950,000 | 3,620,000 | 3,010,000 | 2,130,000 | 1,800,000 | 2,080,000 | 1,780,000 | 1,150,000 | 2,050,000 |
164
+ | ArkType<br><sub>type(value) · allows() · v2.2.8</sub> | 50,500,000 | 7,400,000 | 171,000,000 | 8,640,000 | 38,100,000 | 4,020,000 | 134,000,000 | 4,430,000 | 68,000 | 14,600 |
165
+ | Effect Schema<br><sub>decodeUnknownResult() · is() · v4.0.3</sub> | 4,200,000 | 1,970,000 | 4,220,000 | 1,980,000 | 2,310,000 | 1,000,000 | 2,310,000 | 1,000,000 | 359,000 | 672,000 |
166
+ | TypeBox<br><sub>Compile(…).Check() · v1.3.36</sub> | 165,000,000 | 79,900,000 | 188,000,000 | 83,700,000 | 119,000,000 | 43,200,000 | 136,000,000 | 43,800,000 | 90,600 | 36,200 |
167
+ | TypeBox<br><sub>Value.Check() · v1.3.36</sub> | 263,000 | 191,000 | 264,000 | 192,000 | 170,000 | 118,000 | 167,000 | 114,000 | 89,400 | 422,000 |
168
+ | Ajv<br><sub>compile(…)(value), draft 2020-12 · v8.20.0</sub> | 65,700,000 | 34,600,000 | 71,900,000 | 35,300,000 | 51,500,000 | 23,500,000 | 55,400,000 | 24,100,000 | 15,000,000 | 1,840 |
169
+ | Yup<br><sub>validateSync() · isValidSync(), strict · v1.7.1</sub> | 313,000 | 298,000 | 314,000 | 295,000 | 184,000 | 175,000 | 185,000 | 168,000 | 11,800 | 53,900 |
170
+ | Joi<br><sub>validate(), convert: false · v18.2.9</sub> | 851,000 | 843,000 | 834,000 | 855,000 | 534,000 | 543,000 | 535,000 | 525,000 | 257,000 | 37,400 |
171
+ | Superstruct<br><sub>validate() · is() · v2.0.2</sub> | 492,000 | 453,000 | 496,000 | 443,000 | 304,000 | 266,000 | 299,000 | 257,000 | 100,000 | 1,770,000 |
172
+
173
+ _Apple M3 Max · 16 cores · Node v24.14.1 · median of 5 × 1 s samples, each library in a fresh process · 2026-10-13. Medians, rounded to three significant figures; — where the library cannot express the mode._
162
174
 
163
175
  <!-- bench:compare:end -->
164
176
 
@@ -175,19 +187,19 @@ interactive.
175
187
 
176
188
  | Library | Load | Build | First check | Total |
177
189
  | --- | ---: | ---: | ---: | ---: |
178
- | Superstruct<br><sub>validate() · is() · v2.0.2</sub> | 0.8 ms | 0.2 ms | 0.3 ms | 1.3 ms |
179
- | Valibot<br><sub>safeParse() · is() · v1.5.0</sub> | 3.7 ms | 0.1 ms | 0.1 ms | 4.0 ms |
180
- | Yup<br><sub>validateSync() · isValidSync(), strict · v1.7.1</sub> | 2.5 ms | 1.1 ms | 0.7 ms | 4.2 ms |
181
- | **metaschema**<br><sub>check() · closures · v3.2.0</sub> | 4.7 ms | 0.9 ms | 0.1 ms | 5.7 ms |
182
- | **metaschema**<br><sub>check() · compile(), JIT · v3.2.0</sub> | 5.7 ms | 1.6 ms | 0.2 ms | 7.6 ms |
190
+ | Superstruct<br><sub>validate() · is() · v2.0.2</sub> | 0.7 ms | 0.2 ms | 0.3 ms | 1.2 ms |
191
+ | Valibot<br><sub>safeParse() · is() · v1.5.0</sub> | 3.7 ms | 0.1 ms | 0.1 ms | 3.9 ms |
192
+ | Yup<br><sub>validateSync() · isValidSync(), strict · v1.7.1</sub> | 2.4 ms | 1.1 ms | 0.7 ms | 4.2 ms |
193
+ | **metaschema**<br><sub>check() · closures · v3.3.0</sub> | 4.7 ms | 1.0 ms | 0.4 ms | 6.1 ms |
194
+ | **metaschema**<br><sub>check() · compile(), JIT · v3.3.0</sub> | 5.9 ms | 1.7 ms | 0.2 ms | 7.8 ms |
183
195
  | Metarhia metaschema<br><sub>check() · strict only · v2.2.2</sub> | 20.7 ms | 0.6 ms | 0.2 ms | 21.5 ms |
184
- | Joi<br><sub>validate(), convert: false · v18.2.9</sub> | 23.3 ms | 1.2 ms | 0.6 ms | 25.1 ms |
185
- | Zod<br><sub>safeParse() · v4.6.6</sub> | 27.7 ms | 1.4 ms | 1.2 ms | 30.3 ms |
186
- | Ajv<br><sub>compile(…)(value), draft 2020-12 · v8.20.0</sub> | 14.7 ms | 23.9 ms | 0.2 ms | 38.7 ms |
187
- | Effect Schema<br><sub>decodeUnknownResult() · is() · v4.0.3</sub> | 71.0 ms | 0.2 ms | 0.8 ms | 72.0 ms |
188
- | TypeBox<br><sub>Value.Check() · v1.3.36</sub> | 94.7 ms | 0.1 ms | 1.0 ms | 95.9 ms |
189
- | TypeBox<br><sub>Compile(…).Check() · v1.3.36</sub> | 94.8 ms | 1.9 ms | 0.0 ms | 96.7 ms |
190
- | ArkType<br><sub>type(value) · allows() · v2.2.8</sub> | 105.9 ms | 1.4 ms | 0.1 ms | 107.3 ms |
196
+ | Joi<br><sub>validate(), convert: false · v18.2.9</sub> | 23.1 ms | 1.2 ms | 0.6 ms | 25.0 ms |
197
+ | Zod<br><sub>safeParse() · v4.6.6</sub> | 27.7 ms | 1.5 ms | 1.2 ms | 30.3 ms |
198
+ | Ajv<br><sub>compile(…)(value), draft 2020-12 · v8.20.0</sub> | 14.6 ms | 24.4 ms | 0.2 ms | 39.3 ms |
199
+ | Effect Schema<br><sub>decodeUnknownResult() · is() · v4.0.3</sub> | 72.4 ms | 0.2 ms | 0.8 ms | 73.4 ms |
200
+ | TypeBox<br><sub>Value.Check() · v1.3.36</sub> | 96.6 ms | 0.1 ms | 1.1 ms | 97.8 ms |
201
+ | TypeBox<br><sub>Compile(…).Check() · v1.3.36</sub> | 96.9 ms | 1.9 ms | 0.0 ms | 98.9 ms |
202
+ | ArkType<br><sub>type(value) · allows() · v2.2.8</sub> | 107.8 ms | 1.4 ms | 0.1 ms | 109.3 ms |
191
203
 
192
204
  <!-- bench:coldstart:end -->
193
205
 
@@ -204,8 +216,8 @@ interactive.
204
216
  | Superstruct<br><sub>validate() · is() · v2.0.2</sub> | 3.5 KB | 1.5 KB | |
205
217
  | Metarhia metaschema<br><sub>check() · strict only · v2.2.2</sub> | 30.0 KB | 11.0 KB | minified with keepNames: its checks compare constructor names |
206
218
  | Yup<br><sub>validateSync() · isValidSync(), strict · v1.7.1</sub> | 41.4 KB | 13.2 KB | |
207
- | **metaschema**<br><sub>check() · closures · v3.2.0</sub> | 49.9 KB | 18.0 KB | |
208
- | **metaschema**<br><sub>check() · compile(), JIT · v3.2.0</sub> | 62.5 KB | 22.2 KB | |
219
+ | **metaschema**<br><sub>check() · closures · v3.3.0</sub> | 52.6 KB | 18.9 KB | |
220
+ | **metaschema**<br><sub>check() · compile(), JIT · v3.3.0</sub> | 65.2 KB | 23.1 KB | |
209
221
  | Effect Schema<br><sub>decodeUnknownResult() · is() · v4.0.3</sub> | 72.9 KB | 24.4 KB | |
210
222
  | Zod<br><sub>safeParse() · v4.6.6</sub> | 88.4 KB | 25.7 KB | |
211
223
  | TypeBox<br><sub>Value.Check() · v1.3.36</sub> | 146.7 KB | 37.5 KB | |
@@ -221,7 +233,7 @@ interactive.
221
233
  <!-- bench:releases:start -->
222
234
  <!-- generated by `pnpm bench:report` from bench/results — edit the results, not this block -->
223
235
 
224
- <img src="https://metaschema.vercel.app/benchmarks/speedup.svg" alt="metaschema 3.2.0 against Metarhia's metaschema 2.2.2: How many times faster, scenario by scenario (1 = as fast). Higher is better." width="760" />
236
+ <img src="https://metaschema.vercel.app/benchmarks/speedup.svg" alt="metaschema 3.3.0 against Metarhia's metaschema 2.2.2: How many times faster, scenario by scenario (1 = as fast). Higher is better." width="760" />
225
237
 
226
238
  <details>
227
239
  <summary>Every release, scenario by scenario</summary>
@@ -240,16 +252,16 @@ interactive.
240
252
 
241
253
  </details>
242
254
 
243
- | Scenario | Metarhia 2.2.2 | 1.0.0 | 2.0.0 | 3.0.0 | 3.0.0<br><sub>JIT</sub> | 3.1.0 | 3.1.0<br><sub>JIT</sub> | 3.2.0 | 3.2.0<br><sub>JIT</sub> |
244
- | --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: |
245
- | Schema.from — flat struct | 581,000 | 321,000 | 362,000 | 372,000 | — | 367,000 | — | 356,000 | — |
246
- | Schema.from — nested struct | 156,000 | 95,600 | 104,000 | 99,000 | — | 98,400 | — | 98,600 | — |
247
- | check — flat struct, valid | 1,440,000 | 2,180,000 | 10,800,000 | 10,700,000 | 38,600,000 | 11,700,000 | 37,900,000 | 11,600,000 | 37,900,000 |
248
- | check — flat struct, invalid | 1,010,000 | 1,110,000 | 4,020,000 | 3,940,000 | 6,130,000 | 3,880,000 | 6,170,000 | 3,900,000 | 6,160,000 |
249
- | check — nested struct, valid | 238,000 | 368,000 | 2,950,000 | 2,930,000 | 19,700,000 | 2,920,000 | 19,600,000 | 2,910,000 | 19,700,000 |
250
- | check — nested struct, invalid | 222,000 | 300,000 | 1,570,000 | 1,580,000 | 2,140,000 | 1,570,000 | 2,110,000 | 1,570,000 | 2,110,000 |
255
+ | Scenario | Metarhia 2.2.2 | 1.0.0 | 2.0.0 | 3.0.0 | 3.0.0<br><sub>JIT</sub> | 3.1.0 | 3.1.0<br><sub>JIT</sub> | 3.2.0 | 3.2.0<br><sub>JIT</sub> | 3.3.0 | 3.3.0<br><sub>JIT</sub> |
256
+ | --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: |
257
+ | Schema.from — flat struct | 581,000 | 321,000 | 362,000 | 372,000 | — | 367,000 | — | 356,000 | — | 332,000 | — |
258
+ | Schema.from — nested struct | 156,000 | 95,600 | 104,000 | 99,000 | — | 98,400 | — | 98,600 | — | 91,100 | — |
259
+ | check — flat struct, valid | 1,440,000 | 2,180,000 | 10,800,000 | 10,700,000 | 38,600,000 | 11,700,000 | 37,900,000 | 11,600,000 | 37,900,000 | 11,600,000 | 38,200,000 |
260
+ | check — flat struct, invalid | 1,010,000 | 1,110,000 | 4,020,000 | 3,940,000 | 6,130,000 | 3,880,000 | 6,170,000 | 3,900,000 | 6,160,000 | 3,850,000 | 6,240,000 |
261
+ | check — nested struct, valid | 238,000 | 368,000 | 2,950,000 | 2,930,000 | 19,700,000 | 2,920,000 | 19,600,000 | 2,910,000 | 19,700,000 | 2,910,000 | 19,700,000 |
262
+ | check — nested struct, invalid | 222,000 | 300,000 | 1,570,000 | 1,580,000 | 2,140,000 | 1,570,000 | 2,110,000 | 1,570,000 | 2,110,000 | 1,590,000 | 2,120,000 |
251
263
 
252
- _Apple M3 Max · 16 cores · Node v24.14.1 · median of 5 × 1 s samples, each release in a fresh process · 2026-10-11. ops/s (schemas/s for `Schema.from`), medians._
264
+ _Apple M3 Max · 16 cores · Node v24.14.1 · median of 5 × 1 s samples, each release in a fresh process · 2026-10-13. ops/s (schemas/s for `Schema.from`), medians._
253
265
 
254
266
  <!-- bench:releases:end -->
255
267
 
@@ -323,8 +335,8 @@ pinned.
323
335
  <tr><td>Recursive schemas</td><td>✅ by name, cycles tracked</td><td>✅ by entity name in a Model</td><td>✅ getters or z.lazy</td><td>✅ v.lazy</td><td>✅ scope names, 'this'</td><td>✅ Schema.suspend</td><td>✅ lazy(() =&gt; S)</td><td>✅ t.recursion(name, f)</td><td>✅ Lazy(() =&gt; R)</td><td>✅ lazy(() =&gt; S)</td><td>✅ lazy(() =&gt; T)</td><td>✅ lazy()</td><td>✅ link('#id')</td><td>❌ none</td><td>✅ @ValidateNested + @Type(() =&gt; Self)</td><td>✅ $ref, $dynamicRef</td><td>✅ Type.Cyclic, Type.Module</td><td>✅ recursive TS types</td><td>✅ named types</td><td>✅ self-referencing messages</td><td>✅ schema.add({ self: schema })</td></tr>
324
336
  <tr><td>Schemas referenced by name</td><td>✅ capitalized names in a <code>Model</code></td><td>✅ capitalized names via Model</td><td>❌ JS variables only</td><td>❌ JS variables only</td><td>✅ scope({ User, Group }) by name</td><td>❌ JS variables only</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none (ref() is a value ref)</td><td>✅ id() + link('#id'), shared()</td><td>❌ none</td><td>❌ none</td><td>✅ $ref by $id; ajv.addSchema</td><td>✅ Type.Ref + context, Module, $id</td><td>✅ TS type names</td><td>✅ names + namespaces, registry</td><td>✅ full names via Root</td><td>⚠️ ref: 'Model' for populate</td></tr>
325
337
  <tr><td>Custom types registered by name</td><td>✅ registered by name</td><td>✅ Model types: js alias or checkType</td><td>❌ z.custom() values, no name registry</td><td>❌ v.custom() values, no name registry</td><td>✅ scope aliases, generics, keywords</td><td>⚠️ Schema.declare; reviver ids for restore</td><td>⚠️ define(name, fn); no registry</td><td>⚠️ new t.Type(name, is, validate, encode); no registry</td><td>⚠️ withBrand/withConstraint; no registry</td><td>⚠️ withPredicate/map on a base type; no registry</td><td>⚠️ unknown().assert()/chain(); no registry</td><td>⚠️ addMethod(), mixed(check)</td><td>✅ Joi.extend({ type })</td><td>⚠️ createRule(), macro() methods</td><td>✅ registerDecorator(), @ValidatorConstraint</td><td>⚠️ addKeyword / addSchema, not types</td><td>⚠️ Unsafe + Refine; Script/Module names</td><td>✅ custom tags (tags.TagBase)</td><td>✅ logicalTypes classes, typeHook</td><td>❌ messages and enums only</td><td>✅ Schema.Types.Name = class</td></tr>
326
- <tr><td>String formats</td><td>✅ 9 + your own (<code>./formats</code>)</td><td>❌ none</td><td>✅ 30+ (email, uuid, url, ip, iso.datetime…)</td><td>✅ ~37 actions (email, uuid, url, isoDateTime…)</td><td>✅ ~18 string.* (email, uuid, url, ip…)</td><td>✅ uuid, ulid, base64, URL, IP; no email</td><td>❌ none (pattern() only)</td><td>⚠️ io-ts-types: UUID, ISO dates</td><td>❌ none (Template literals)</td><td>❌ none (pattern() only)</td><td>❌ none</td><td>✅ 4: email, url, uuid, datetime<sup>17</sup></td><td>✅ 14: email, uri, uuid, ip, isoDate...</td><td>✅ 18: email, url, uuid, ulid, ip, iban, jwt...</td><td>✅ 50+ via validator.js (IsEmail, IsUUID, IsUrl...)</td><td>✅ ajv-formats: 26<sup>18</sup></td><td>✅ 21 built in<sup>19</sup></td><td>✅ 22 via tags.Format</td><td>❌ none</td><td>❌ none</td><td>❌ none (match: RegExp)</td></tr>
327
- <tr><td>Date, BigInt, Map, Set</td><td>✅ Date, BigInt, Map, Set</td><td>⚠️ BigInt, Map, Set; no Date</td><td>✅ Date, BigInt, Map, Set, Symbol, File</td><td>✅ Date, BigInt, Map, Set, Blob, File</td><td>✅ Date, bigint, Map, Set, symbol, Blob, File…</td><td>✅ Date, BigInt, ReadonlyMap, ReadonlySet, Symbol…</td><td>✅ Date, BigInt, Map, Set</td><td>⚠️ BigInt; Date/Map/Set via io-ts-types</td><td>⚠️ BigInt, Symbol; Date/Map/Set via InstanceOf</td><td>⚠️ Date, BigInt</td><td>⚠️ BigInt only</td><td>⚠️ Date</td><td>⚠️ Date, Buffer, symbol, function</td><td>⚠️ Date (output), File</td><td>⚠️ Date; Set/Map via each</td><td>⚠️ Date via ajv-keywords or JTD</td><td>⚠️ BigInt, Symbol, Undefined; no Date/Map/Set<sup>20</sup></td><td>✅ Date, bigint, Map, Set, typed arrays<sup>21</sup></td><td>⚠️ Buffer; Date, BigInt via custom types<sup>22</sup></td><td>⚠️ Uint8Array, Long; BigInt via fromObject<sup>23</sup></td><td>✅ Date, BigInt, Map, Buffer</td></tr>
338
+ <tr><td>String formats</td><td>✅ 35 + your own (<code>./formats</code>)</td><td>❌ none</td><td>✅ 30+ (email, uuid, url, ip, iso.datetime…)</td><td>✅ ~37 actions (email, uuid, url, isoDateTime…)</td><td>✅ ~18 string.* (email, uuid, url, ip…)</td><td>✅ uuid, ulid, base64, URL, IP; no email</td><td>❌ none (pattern() only)</td><td>⚠️ io-ts-types: UUID, ISO dates</td><td>❌ none (Template literals)</td><td>❌ none (pattern() only)</td><td>❌ none</td><td>✅ 4: email, url, uuid, datetime<sup>17</sup></td><td>✅ 14: email, uri, uuid, ip, isoDate...</td><td>✅ 18: email, url, uuid, ulid, ip, iban, jwt...</td><td>✅ 50+ via validator.js (IsEmail, IsUUID, IsUrl...)</td><td>✅ ajv-formats: 26<sup>18</sup></td><td>✅ 21 built in<sup>19</sup></td><td>✅ 22 via tags.Format</td><td>❌ none</td><td>❌ none</td><td>❌ none (match: RegExp)</td></tr>
339
+ <tr><td>Date, BigInt, Map, Set</td><td>✅ Date, BigInt, Map, Set; BSON (<code>./mongodb</code>)</td><td>⚠️ BigInt, Map, Set; no Date</td><td>✅ Date, BigInt, Map, Set, Symbol, File</td><td>✅ Date, BigInt, Map, Set, Blob, File</td><td>✅ Date, bigint, Map, Set, symbol, Blob, File…</td><td>✅ Date, BigInt, ReadonlyMap, ReadonlySet, Symbol…</td><td>✅ Date, BigInt, Map, Set</td><td>⚠️ BigInt; Date/Map/Set via io-ts-types</td><td>⚠️ BigInt, Symbol; Date/Map/Set via InstanceOf</td><td>⚠️ Date, BigInt</td><td>⚠️ BigInt only</td><td>⚠️ Date</td><td>⚠️ Date, Buffer, symbol, function</td><td>⚠️ Date (output), File</td><td>⚠️ Date; Set/Map via each</td><td>⚠️ Date via ajv-keywords or JTD</td><td>⚠️ BigInt, Symbol, Undefined; no Date/Map/Set<sup>20</sup></td><td>✅ Date, bigint, Map, Set, typed arrays<sup>21</sup></td><td>⚠️ Buffer; Date, BigInt via custom types<sup>22</sup></td><td>⚠️ Uint8Array, Long; BigInt via fromObject<sup>23</sup></td><td>✅ Date, BigInt, Map, Buffer</td></tr>
328
340
  <tr><td>Custom validators</td><td>✅ <code>validate</code> on a field and a schema</td><td>✅ field and schema validate<sup>24</sup></td><td>✅ .refine / .superRefine / .check</td><td>✅ check (field), forward+partialCheck (object)</td><td>✅ .narrow() on fields and objects</td><td>✅ .check(makeFilter), refine</td><td>✅ refine(struct, name, fn)</td><td>✅ refinement(), brand()</td><td>✅ withConstraint, withGuard, withAssertion</td><td>✅ withPredicate(fn, msg)</td><td>✅ assert(fn, msg), chain()</td><td>✅ test() on fields and objects</td><td>✅ custom() on any schema</td><td>✅ createRule() + use(), any level</td><td>⚠️ custom decorators per property</td><td>✅ custom keywords (addKeyword)</td><td>✅ Type.Refine on any type</td><td>⚠️ TagBase validate expressions (strings)</td><td>⚠️ only via a LogicalType</td><td>❌ none</td><td>✅ validate; pre('validate') + invalidate</td></tr>
329
341
  <tr><td>Async validators</td><td>✅ <code>checkAsync</code>, run concurrently</td><td>❌ none</td><td>✅ parseAsync; concurrent</td><td>✅ *Async schemas; concurrent<sup>25</sup></td><td>❌ not supported (by design)<sup>26</sup></td><td>✅ Effect getters; concurrency option</td><td>❌ none</td><td>⚠️ experimental TaskDecoder, concurrent<sup>27</sup></td><td>❌ none</td><td>❌ none<sup>28</sup></td><td>❌ none (non-goal)<sup>29</sup></td><td>✅ async test(), concurrent</td><td>⚠️ external(): sequential, after sync rules<sup>30</sup></td><td>⚠️ async rules, in sequence</td><td>✅ async constraints, concurrent<sup>31</sup></td><td>⚠️ $async schemas; awaited one by one</td><td>❌ sync only<sup>32</sup></td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>✅ async validators, concurrent</td></tr>
330
342
  <tr class="ms-matrix-group"><td colspan="22"><strong>Validation results</strong></td></tr>
@@ -338,37 +350,37 @@ pinned.
338
350
  <tr class="ms-matrix-group"><td colspan="22"><strong>Parsing</strong></td></tr>
339
351
  <tr><td>Defaults</td><td>✅ <code>default</code>, a value or a factory</td><td>❌ kept as metadata only</td><td>✅ .default(), .prefault(), .catch()</td><td>✅ optional(schema, default), fallback</td><td>✅ 'string = "x"', .default()</td><td>✅ withDecodingDefault(Key), withConstructorDefault</td><td>✅ defaulted(), via create()/mask()<sup>49</sup></td><td>⚠️ io-ts-types fromNullable/withFallback</td><td>✅ default(value), parse only<sup>50</sup></td><td>✅ default(value | fn)</td><td>✅ optional(() =&gt; v), nullable(() =&gt; v)</td><td>✅ default(), factories</td><td>✅ default(), factories</td><td>❌ none (parse() can fill)</td><td>✅ field initializers (class-transformer)</td><td>✅ useDefaults: true (in place)<sup>51</sup></td><td>⚠️ Value.Default; Decode pipeline<sup>52</sup></td><td>❌ Default&lt;V&gt; is metadata only</td><td>✅ field default (clone, decode)</td><td>✅ proto defaults, toObject({ defaults })</td><td>✅ default values and functions</td></tr>
340
352
  <tr><td>Transforms and decoders</td><td>✅ a field's <code>parse</code> (decoder)</td><td>❌ none</td><td>✅ .transform, z.pipe, z.preprocess</td><td>✅ transform, rawTransform in pipe</td><td>✅ morphs: .pipe(), .to(), '=&gt;'</td><td>✅ decodeTo + SchemaTransformation</td><td>✅ coerce(struct, from, fn) via create()</td><td>✅ custom Type with validate/encode</td><td>✅ withParser(fn), parse only</td><td>✅ map(fn)</td><td>✅ map(fn), chain(fn)</td><td>✅ transform()</td><td>✅ custom() return value, rename(), trim()...</td><td>✅ transform(), parse()</td><td>✅ @Transform (class-transformer)</td><td>⚠️ ajv-keywords transform (strings only)</td><td>✅ Type.Codec / Decode / Encode</td><td>⚠️ built-in only: http, notations, llm</td><td>✅ logical types (_fromValue)</td><td>⚠️ conversion options only</td><td>✅ set/get, trim, lowercase</td></tr>
341
- <tr><td>Coercion of input types</td><td>❌ a decoder on a string field</td><td>❌ none</td><td>✅ z.coerce.*, z.stringbool</td><td>✅ toNumber, toDate, toBoolean… actions</td><td>✅ string.numeric.parse, string.date.parse…</td><td>✅ NumberFromString, DateFromString…</td><td>❌ none (trimmed() only)</td><td>⚠️ io-ts-types NumberFromString etc.</td><td>❌ none</td><td>✅ number coerce, date, bigint, enum case<sup>53</sup></td><td>❌ none</td><td>✅ on by default; strict() off</td><td>✅ convert: true by default<sup>54</sup></td><td>✅ form semantics by default; { strict: true }</td><td>✅ @Type / implicit (class-transformer)</td><td>✅ coerceTypes: true | "array"</td><td>✅ Value.Convert (also inside Decode)</td><td>⚠️ http.query/headers, llm.coerce</td><td>⚠️ coerceBuffers only</td><td>✅ fromObject casts<sup>55</sup></td><td>✅ casting on by default</td></tr>
353
+ <tr><td>Coercion of input types</td><td>✅ <code>coerce: true</code> (call, kind or field) + <code>./coerce</code><sup>53</sup></td><td>❌ none</td><td>✅ z.coerce.*, z.stringbool</td><td>✅ toNumber, toDate, toBoolean… actions</td><td>✅ string.numeric.parse, string.date.parse…</td><td>✅ NumberFromString, DateFromString…</td><td>❌ none (trimmed() only)</td><td>⚠️ io-ts-types NumberFromString etc.</td><td>❌ none</td><td>✅ number coerce, date, bigint, enum case<sup>54</sup></td><td>❌ none</td><td>✅ on by default; strict() off</td><td>✅ convert: true by default<sup>55</sup></td><td>✅ form semantics by default; { strict: true }</td><td>✅ @Type / implicit (class-transformer)</td><td>✅ coerceTypes: true | "array"</td><td>✅ Value.Convert (also inside Decode)</td><td>⚠️ http.query/headers, llm.coerce</td><td>⚠️ coerceBuffers only</td><td>✅ fromObject casts<sup>56</sup></td><td>✅ casting on by default</td></tr>
342
354
  <tr><td>Encode back (bidirectional codecs)</td><td>✅ <code>serialize</code></td><td>❌ none</td><td>✅ z.codec + z.encode</td><td>🔜 planned for v2 (#658)</td><td>❌ none</td><td>✅ encodeSync / encodeUnknown*</td><td>❌ none</td><td>✅ codec.encode()</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>✅ instanceToPlain (class-transformer)</td><td>⚠️ JTD compileSerializer (to JSON)</td><td>✅ Codec + Value.Encode</td><td>⚠️ protobuf.encode/decode, json.stringify</td><td>✅ toBuffer/fromBuffer; logical _toValue</td><td>✅ binary, toObject, ProtoJSON</td><td>⚠️ getters, toJSON transform</td></tr>
343
355
  <tr class="ms-matrix-group"><td colspan="22"><strong>TypeScript</strong></td></tr>
344
356
  <tr><td>Static type inferred from the schema</td><td>✅ <code>Infer</code>, <code>InferSchema</code></td><td>❌ none</td><td>✅ z.infer</td><td>✅ InferOutput</td><td>✅ typeof T.infer</td><td>✅ typeof S.Type</td><td>✅ Infer&lt;typeof S&gt;</td><td>✅ t.TypeOf&lt;typeof C&gt;</td><td>✅ Static&lt;typeof R&gt;</td><td>✅ Infer&lt;typeof S&gt;</td><td>✅ v.Infer&lt;typeof T&gt;</td><td>✅ InferType</td><td>❌ none</td><td>✅ Infer&lt;typeof schema&gt;</td><td>⚠️ the class is the type</td><td>⚠️ JTDDataType (JTD only)</td><td>✅ Static&lt;T&gt;, also from plain JSON Schema</td><td>✅ the TS type is the schema</td><td>❌ none</td><td>⚠️ via pbjs --dts codegen</td><td>✅ InferSchemaType</td></tr>
345
357
  <tr><td>Separate input and output types</td><td>✅ <code>Infer</code> / <code>InferOutput</code></td><td>❌ none</td><td>✅ z.input / z.output</td><td>✅ InferInput / InferOutput</td><td>✅ T.inferIn / T.inferOut</td><td>✅ S.Type / S.Encoded</td><td>❌ none</td><td>✅ TypeOf, InputOf, OutputOf</td><td>✅ Static vs Parsed</td><td>❌ none</td><td>❌ output only</td><td>⚠️ defaults only, in ~standard types</td><td>❌ none</td><td>✅ InferInput / Infer</td><td>❌ none</td><td>— no transforms</td><td>✅ StaticDecode / StaticEncode</td><td>— no transforms or defaults</td><td>❌ none</td><td>⚠️ $Properties vs class (pbts)</td><td>⚠️ InferRawDocType vs hydrated</td></tr>
346
- <tr><td>Generates TypeScript source</td><td>✅ <code>toTypeScript</code>, <code>saveTypes</code></td><td>⚠️ model.dts, flat scalars only<sup>56</sup></td><td>⚠️ zod-to-ts (third-party)</td><td>❌ none</td><td>❌ .expression is ArkType syntax, not TS</td><td>✅ SchemaRepresentation.toCodeDocument</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>⚠️ joi-to-typescript (3rd party)</td><td>❌ none</td><td>— schemas are TS classes</td><td>⚠️ json-schema-to-typescript (third-party)</td><td>⚠️ json-schema-to-typescript (third-party)</td><td>— the source is TypeScript</td><td>⚠️ third-party: @ovotech/avro-ts</td><td>✅ pbjs --dts / pbts (protobufjs-cli)</td><td>⚠️ third-party: mongoose-tsgen</td></tr>
358
+ <tr><td>Generates TypeScript source</td><td>✅ <code>toTypeScript</code>, <code>saveTypes</code></td><td>⚠️ model.dts, flat scalars only<sup>57</sup></td><td>⚠️ zod-to-ts (third-party)</td><td>❌ none</td><td>❌ .expression is ArkType syntax, not TS</td><td>✅ SchemaRepresentation.toCodeDocument</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>⚠️ joi-to-typescript (3rd party)</td><td>❌ none</td><td>— schemas are TS classes</td><td>⚠️ json-schema-to-typescript (third-party)</td><td>⚠️ json-schema-to-typescript (third-party)</td><td>— the source is TypeScript</td><td>⚠️ third-party: @ovotech/avro-ts</td><td>✅ pbjs --dts / pbts (protobufjs-cli)</td><td>⚠️ third-party: mongoose-tsgen</td></tr>
347
359
  <tr class="ms-matrix-group"><td colspan="22"><strong>Interoperability</strong></td></tr>
348
- <tr><td>Standard Schema</td><td>✅ v1 + JSON Schema converter</td><td>❌ no</td><td>✅ v1 + ~standard.jsonSchema</td><td>✅ v1 on every schema</td><td>✅ v1 + ~standard.jsonSchema</td><td>✅ v1 via toStandardSchemaV1()<sup>57</sup></td><td>❌ no</td><td>❌ no</td><td>❌ no</td><td>❌ no</td><td>✅ v1 (~standard), libraryOptions.mode</td><td>✅ v1, always async<sup>58</sup></td><td>✅ v1, + Standard JSON Schema</td><td>⚠️ v1 on validators; path is a string<sup>59</sup></td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>✅ createValidate&lt;T&gt;() (v1)</td><td>❌ no</td><td>❌ no</td><td>✅ Model['~standard'] v1 (9.7+)<sup>60</sup></td></tr>
360
+ <tr><td>Standard Schema</td><td>✅ v1 + JSON Schema converter</td><td>❌ no</td><td>✅ v1 + ~standard.jsonSchema</td><td>✅ v1 on every schema</td><td>✅ v1 + ~standard.jsonSchema</td><td>✅ v1 via toStandardSchemaV1()<sup>58</sup></td><td>❌ no</td><td>❌ no</td><td>❌ no</td><td>❌ no</td><td>✅ v1 (~standard), libraryOptions.mode</td><td>✅ v1, always async<sup>59</sup></td><td>✅ v1, + Standard JSON Schema</td><td>⚠️ v1 on validators; path is a string<sup>60</sup></td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>✅ createValidate&lt;T&gt;() (v1)</td><td>❌ no</td><td>❌ no</td><td>✅ Model['~standard'] v1 (9.7+)<sup>61</sup></td></tr>
349
361
  <tr><td>JSON Schema export</td><td>✅ 2020-12, draft-07, OpenAPI 3.0, MongoDB</td><td>❌ none</td><td>✅ 2020-12, draft-07, draft-04, OpenAPI 3.0</td><td>✅ draft-07, 2020-12, OpenAPI 3.0 (@valibot/to-json-schema)</td><td>✅ draft 2020-12, draft-07</td><td>✅ 2020-12, draft-07, draft-04, OpenAPI 3.1</td><td>❌ none</td><td>⚠️ io-ts-to-json-schema (third-party)</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>⚠️ @sodaru/yup-to-json-schema (3rd party)</td><td>✅ 2020-12 via ~standard.jsonSchema</td><td>✅ draft-07 via toJSONSchema()</td><td>⚠️ class-validator-jsonschema (3rd party)</td><td>✅ the schema is JSON Schema</td><td>✅ types are JSON Schema (2020-12)</td><td>✅ json.schema(s): OpenAPI 3.0, 3.1</td><td>❌ none</td><td>❌ none</td><td>✅ toJSONSchema(): JSON Schema, $jsonSchema</td></tr>
350
- <tr><td>JSON Schema import</td><td>✅ <code>fromJSONSchema</code> (a subset)</td><td>❌ none</td><td>✅ z.fromJSONSchema<sup>61</sup></td><td>⚠️ json-schema-to-valibot (third-party, codegen)</td><td>⚠️ @ark/json-schema 0.0.12 (no $ref)</td><td>✅ SchemaRepresentation.fromJsonSchemaDocument</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>⚠️ json-schema-to-yup (3rd party)</td><td>⚠️ enjoi (3rd party)</td><td>❌ none</td><td>❌ none</td><td>✅ draft-07, 2019-09, 2020-12, JTD</td><td>✅ Compile/Value accept drafts 3–2020-12</td><td>⚠️ @typia/utils OpenApiValidator (untyped)</td><td>❌ none</td><td>❌ none</td><td>❌ none</td></tr>
351
- <tr><td>LLM structured-output profile</td><td>✅ the strict profile</td><td>❌ none</td><td>⚠️ openai/helpers/zod (third-party)</td><td>⚠️ @ai-sdk/valibot (third-party)</td><td>❌ none</td><td>✅ effect/ai toCodecOpenAI, toCodecAnthropic<sup>62</sup></td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>✅ llm.application/parameters; strict mode</td><td>❌ none</td><td>❌ none</td><td>❌ none</td></tr>
362
+ <tr><td>JSON Schema import</td><td>✅ <code>fromJSONSchema</code> (a subset)</td><td>❌ none</td><td>✅ z.fromJSONSchema<sup>62</sup></td><td>⚠️ json-schema-to-valibot (third-party, codegen)</td><td>⚠️ @ark/json-schema 0.0.12 (no $ref)</td><td>✅ SchemaRepresentation.fromJsonSchemaDocument</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>⚠️ json-schema-to-yup (3rd party)</td><td>⚠️ enjoi (3rd party)</td><td>❌ none</td><td>❌ none</td><td>✅ draft-07, 2019-09, 2020-12, JTD</td><td>✅ Compile/Value accept drafts 3–2020-12</td><td>⚠️ @typia/utils OpenApiValidator (untyped)</td><td>❌ none</td><td>❌ none</td><td>❌ none</td></tr>
363
+ <tr><td>LLM structured-output profile</td><td>✅ the strict profile</td><td>❌ none</td><td>⚠️ openai/helpers/zod (third-party)</td><td>⚠️ @ai-sdk/valibot (third-party)</td><td>❌ none</td><td>✅ effect/ai toCodecOpenAI, toCodecAnthropic<sup>63</sup></td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>✅ llm.application/parameters; strict mode</td><td>❌ none</td><td>❌ none</td><td>❌ none</td></tr>
352
364
  <tr class="ms-matrix-group"><td colspan="22"><strong>Domain models</strong></td></tr>
353
365
  <tr><td>Entities with storage metadata</td><td>✅ kinds: Entity, Registry, …</td><td>✅ 11 kinds: scope, store, id field</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>⚠️ schema/Model variants + SqlModel</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>✅ model(name), collection option</td></tr>
354
- <tr><td>References: an id or the record</td><td>✅ an id or the record, by kind or per call</td><td>⚠️ embedded record only<sup>63</sup></td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none (named types embed)</td><td>❌ none (messages embed)</td><td>⚠️ ref: id or populated doc<sup>64</sup></td></tr>
355
- <tr><td>Indexes and unique keys</td><td>✅ <code>index</code>, <code>primary</code>, <code>unique</code></td><td>✅ index/primary/unique arrays</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>✅ index/unique/sparse, schema.index()</td></tr>
356
- <tr><td>Relation metadata</td><td>✅ <code>schema.relations</code></td><td>⚠️ schema.relations { to, type }<sup>65</sup></td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>⚠️ ref, virtual populate (justOne)</td></tr>
357
- <tr><td>Derive a schema: pick, omit, partial, extend</td><td>⚠️ <code>Projection</code>, <code>merge</code>; no partial</td><td>⚠️ Projection kind (pick fields)</td><td>✅ pick, omit, partial, required, extend, deepPartial</td><td>✅ pick, omit, partial, required</td><td>✅ pick, omit, partial, required, merge</td><td>✅ mapFields + Struct.pick/omit/map</td><td>✅ pick, omit, partial, assign</td><td>⚠️ partial, exact, intersection; no pick/omit</td><td>✅ pick, omit, extend, asPartial</td><td>✅ pick, omit, partial (deep), required</td><td>✅ pick, omit, partial, extend, rest</td><td>✅ pick, omit, partial, shape, concat</td><td>✅ keys, append, fork, tailor, concat</td><td>✅ pick, omit, partial, merge(group)</td><td>⚠️ class extends; @nestjs/mapped-types</td><td>⚠️ allOf; ajv-merge-patch $merge/$patch</td><td>✅ Pick, Omit, Partial, Required, Mapped</td><td>✅ TS Pick, Omit, Partial</td><td>❌ none</td><td>❌ none</td><td>✅ pick, omit, add, clone, discriminator</td></tr>
366
+ <tr><td>References: an id or the record</td><td>✅ an id or the record, by kind or per call</td><td>⚠️ embedded record only<sup>64</sup></td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none (named types embed)</td><td>❌ none (messages embed)</td><td>⚠️ ref: id or populated doc<sup>65</sup></td></tr>
367
+ <tr><td>Indexes and unique keys</td><td>✅ <code>index</code>, <code>primary</code>, <code>unique</code>; driver specs (<code>./mongodb</code>)</td><td>✅ index/primary/unique arrays</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>✅ index/unique/sparse, schema.index()</td></tr>
368
+ <tr><td>Relation metadata</td><td>✅ <code>schema.relations</code></td><td>⚠️ schema.relations { to, type }<sup>66</sup></td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>⚠️ ref, virtual populate (justOne)</td></tr>
369
+ <tr><td>Derive a schema: pick, omit, partial, extend</td><td>✅ pick, omit, partial (deep), required, extend, keyof (<code>./derive</code>)</td><td>⚠️ Projection kind (pick fields)</td><td>✅ pick, omit, partial, required, extend, deepPartial</td><td>✅ pick, omit, partial, required</td><td>✅ pick, omit, partial, required, merge</td><td>✅ mapFields + Struct.pick/omit/map</td><td>✅ pick, omit, partial, assign</td><td>⚠️ partial, exact, intersection; no pick/omit</td><td>✅ pick, omit, extend, asPartial</td><td>✅ pick, omit, partial (deep), required</td><td>✅ pick, omit, partial, extend, rest</td><td>✅ pick, omit, partial, shape, concat</td><td>✅ keys, append, fork, tailor, concat</td><td>✅ pick, omit, partial, merge(group)</td><td>⚠️ class extends; @nestjs/mapped-types</td><td>⚠️ allOf; ajv-merge-patch $merge/$patch</td><td>✅ Pick, Omit, Partial, Required, Mapped</td><td>✅ TS Pick, Omit, Partial</td><td>❌ none</td><td>❌ none</td><td>✅ pick, omit, add, clone, discriminator</td></tr>
358
370
  <tr><td>A model of many schemas</td><td>✅ <code>Model</code>: order, missing references</td><td>✅ Model: order, missing refs</td><td>❌ none</td><td>❌ none</td><td>⚠️ scope(): resolves names, errors on missing</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>⚠️ Ajv instance as $ref registry</td><td>⚠️ Type.Module (named types)</td><td>❌ none</td><td>⚠️ protocols, shared registry</td><td>⚠️ Root: lookup, resolveAll()</td><td>⚠️ mongoose.model() registry</td></tr>
359
371
  <tr class="ms-matrix-group"><td colspan="22"><strong>Evolution</strong></td></tr>
360
372
  <tr><td>Snapshot of a schema or model</td><td>✅ <code>model.toJSON()</code>, <code>fromJSON</code></td><td>⚠️ schema.toJSON(), fields only</td><td>⚠️ via JSON Schema round trip</td><td>❌ export only, no restore</td><td>✅ .json → type.schema()</td><td>✅ SchemaRepresentation toJson / fromJson</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>⚠️ describe(), no restore</td><td>✅ describe() / Joi.build()</td><td>⚠️ toJSON(), no restore</td><td>❌ none</td><td>✅ schemas are JSON</td><td>✅ JSON.stringify; Compile reads it back</td><td>⚠️ export only (json.schema, reflect.schema)</td><td>✅ schema(), JSON.stringify(type)</td><td>✅ root.toJSON() / Root.fromJSON()</td><td>❌ none</td></tr>
361
373
  <tr><td>Diff of two versions</td><td>✅ <code>diff</code></td><td>🔜 issue #251 (migrations)</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>⚠️ Value.Diff (generic JSON edits)</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td></tr>
362
- <tr><td>Compatibility of a change</td><td>✅ backward / forward / full</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>⚠️ via .extends() / .equals()</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>⚠️ Type.Extends (assignability)</td><td>❌ none</td><td>✅ reader/writer resolution<sup>66</sup></td><td>❌ none</td><td>❌ none</td></tr>
374
+ <tr><td>Compatibility of a change</td><td>✅ backward / forward / full</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>⚠️ via .extends() / .equals()</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>⚠️ Type.Extends (assignability)</td><td>❌ none</td><td>✅ reader/writer resolution<sup>67</sup></td><td>❌ none</td><td>❌ none</td></tr>
363
375
  <tr><td>Field aliases (renames)</td><td>✅ <code>aliases</code>, renamed by <code>parse</code></td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>⚠️ Schema.encodeKeys (one encoded name)</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>✅ object.from(old, new, alias)</td><td>✅ rename(old, new, { alias })</td><td>❌ none</td><td>⚠️ @Expose({ name }) (class-transformer)</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>✅ type and field aliases</td><td>⚠️ renames free on the wire</td><td>✅ alias option (virtual)</td></tr>
364
376
  <tr><td>Deprecation markers</td><td>✅ <code>deprecated</code></td><td>❌ none</td><td>✅ .meta({ deprecated: true })</td><td>❌ free-form metadata() only</td><td>✅ .configure({ deprecated: true })</td><td>❌ none</td><td>✅ deprecated(struct, log)</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none (meta() is free-form)</td><td>❌ none (meta(), notes free-form)</td><td>❌ none</td><td>❌ none</td><td>✅ deprecated keyword (annotation)</td><td>⚠️ deprecated: true passes through</td><td>✅ JSDoc @deprecated → schema</td><td>❌ none</td><td>⚠️ [deprecated] kept in options</td><td>❌ none</td></tr>
365
377
  <tr class="ms-matrix-group"><td colspan="22"><strong>Tooling</strong></td></tr>
366
378
  <tr><td>Sample values from a schema</td><td>✅ <code>sample</code>, seeded</td><td>❌ none</td><td>⚠️ zod-schema-faker (third-party)</td><td>⚠️ valimock (third-party)</td><td>✅ @ark/fast-check (arkToArbitrary)</td><td>✅ Arbitrary.schema (own engine)</td><td>❌ none</td><td>⚠️ fast-check-io-ts (third-party)</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none (example() is an annotation)</td><td>❌ none</td><td>❌ none</td><td>⚠️ json-schema-faker (third-party)</td><td>⚠️ Value.Create (zero values)</td><td>✅ typia.random&lt;T&gt;() (randexp)</td><td>✅ type.random()</td><td>❌ none</td><td>❌ none</td></tr>
367
- <tr><td>A schema inferred from data</td><td>✅ <code>infer</code></td><td>❌ none</td><td>⚠️ json-to-zod (third-party, 2022)</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>✅ Type.forValue, Type.forTypes<sup>67</sup></td><td>❌ none</td><td>❌ none</td></tr>
379
+ <tr><td>A schema inferred from data</td><td>✅ <code>infer</code></td><td>❌ none</td><td>⚠️ json-to-zod (third-party, 2022)</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>✅ Type.forValue, Type.forTypes<sup>68</sup></td><td>❌ none</td><td>❌ none</td></tr>
368
380
  <tr><td>Merge or intersect two schemas</td><td>✅ <code>merge</code></td><td>❌ none</td><td>✅ z.intersection, .extend</td><td>✅ intersect</td><td>✅ .merge(), .and()</td><td>⚠️ fieldsAssign (struct fields only)</td><td>✅ assign(), intersection()</td><td>✅ intersection()</td><td>✅ Intersect(...), and()</td><td>✅ and() / intersection()</td><td>⚠️ extend(other.shape); no intersection</td><td>✅ concat()</td><td>✅ concat()</td><td>❌ none</td><td>❌ none</td><td>⚠️ allOf; ajv-merge-patch $merge</td><td>✅ Intersect + Evaluate</td><td>✅ TS intersection (A &amp; B)</td><td>⚠️ Type.forTypes (widening)</td><td>❌ none</td><td>✅ schema.add(other), new Schema([a, b])</td></tr>
369
381
  <tr><td>Warnings about a definition</td><td>✅ <code>schema.warnings</code></td><td>⚠️ model.warnings: refs, recursion</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>✅ strict mode; strictTypes logs</td><td>❌ none</td><td>❌ compile errors only</td><td>❌ none</td><td>❌ none</td><td>⚠️ reserved-key, duplicate-index warnings</td></tr>
370
- <tr><td>Streams and iterables of records</td><td>✅ <code>checkEach</code>, <code>transform</code></td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>✅ ChannelSchema.decode/encode<sup>68</sup></td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>⚠️ Node stream codecs</td><td>❌ none (delimited framing only)</td><td>❌ none</td></tr>
371
- <tr><td>Compiled to code, with a fallback</td><td>✅ <code>compile()</code>, closures fallback</td><td>❌ interpreter only</td><td>✅ z.compile / zod/compile; runtime fallback</td><td>🔜 compiler PR by the author (#1441)</td><td>✅ JIT by default; jitless fallback</td><td>✅ opt-in JIT + AOT; interpreter fallback<sup>69</sup></td><td>❌ interpreter only</td><td>❌ interpreter only</td><td>❌ interpreter only</td><td>❌ interpreter only</td><td>❌ interpreter only</td><td>❌ interpreter only</td><td>❌ interpreter only</td><td>✅ always; no interpreter fallback</td><td>❌ interpreter only</td><td>✅ always compiles; no interpreter</td><td>✅ Compile; interpreter fallback</td><td>✅ AOT at build time; no fallback</td><td>✅ new Function; no fallback</td><td>✅ runtime codegen; static AOT</td><td>❌ interpreter only</td></tr>
382
+ <tr><td>Streams and iterables of records</td><td>✅ <code>checkEach</code>, <code>transform</code></td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>✅ ChannelSchema.decode/encode<sup>69</sup></td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>❌ none</td><td>⚠️ Node stream codecs</td><td>❌ none (delimited framing only)</td><td>❌ none</td></tr>
383
+ <tr><td>Compiled to code, with a fallback</td><td>✅ <code>compile()</code>, closures fallback</td><td>❌ interpreter only</td><td>✅ z.compile / zod/compile; runtime fallback</td><td>🔜 compiler PR by the author (#1441)</td><td>✅ JIT by default; jitless fallback</td><td>✅ opt-in JIT + AOT; interpreter fallback<sup>70</sup></td><td>❌ interpreter only</td><td>❌ interpreter only</td><td>❌ interpreter only</td><td>❌ interpreter only</td><td>❌ interpreter only</td><td>❌ interpreter only</td><td>❌ interpreter only</td><td>✅ always; no interpreter fallback</td><td>❌ interpreter only</td><td>✅ always compiles; no interpreter</td><td>✅ Compile; interpreter fallback</td><td>✅ AOT at build time; no fallback</td><td>✅ new Function; no fallback</td><td>✅ runtime codegen; static AOT</td><td>❌ interpreter only</td></tr>
372
384
  <tr><td>Readable at runtime</td><td>✅ <code>fields</code>, <code>toJSON()</code></td><td>✅ fields, kind, indexes, relations</td><td>✅ .def, .shape, .meta()</td><td>✅ plain schema objects (type, entries, pipe)</td><td>✅ .json, .props, .expression, .select()</td><td>✅ .ast, .fields, annotations</td><td>⚠️ struct.type, struct.schema</td><td>✅ _tag, props, types, name</td><td>✅ tag, fields, alternatives, element</td><td>⚠️ shape(); other parts private</td><td>⚠️ name, shape, options; transforms opaque</td><td>✅ describe(), fields, spec</td><td>✅ describe(), $_terms, _rules</td><td>✅ toJSON() tree, getProperties()</td><td>✅ getMetadataStorage()</td><td>✅ the schema is a plain object</td><td>✅ JSON Schema objects; Type.Is* guards</td><td>✅ reflect.schema / json.schema</td><td>✅ fields, typeName, schema()</td><td>✅ reflection: fields, options</td><td>✅ schema.paths, path(), eachPath</td></tr>
373
385
  </tbody>
374
386
  </table>
@@ -429,23 +441,24 @@ pinned.
429
441
  50. The default is a value, not a factory: default([]) hands every parse the same array (script).
430
442
  51. Defaults are written into the input object, and not inside anyOf/oneOf/not.
431
443
  52. Value.Parse and Compile().Parse never fill defaults (only with the global correctiveParse setting, and only for a value that fails the check); Value.Decode does, and Compile().Decode does only when the type contains a codec.
432
- 53. Lenient: number().coerce() turns "1abc" into 1, number() accepts NaN, bigint() accepts true (script).
433
- 54. number() also rejects values beyond Number.MAX_SAFE_INTEGER unless unsafe() (types/number.js:104).
434
- 55. fromObject does not validate: { age: 'abc' } becomes 0 and { name: 42 } "42".
435
- 56. Only number/string/boolean are typed: a nested struct, enum, array or custom type is rendered as string (profile: string), and a reference as &lt;name&gt;Id: string although check validates the embedded record.
436
- 57. Schemas do not carry ~standard themselves ('~standard' in schema is false); wrap with Schema.toStandardSchemaV1 / toStandardJSONSchemaV1.
437
- 58. ~standard.validate always returns a promise and runs with abortEarly: false; array indexes come back as strings.
438
- 59. ~standard.validate puts the dotted field string in path (the specification wants an array) and, for a valid falsy output (false, 0, ''), returns { issues: undefined } without the value. Schemas themselves have no ~standard; vine.create() validators do.
439
- 60. On models only (a Schema has none), and validate always returns a promise; it casts, so { n: '5' } is valid with value n: 5.
440
- 61. Its JSDoc calls it semi-experimental.
441
- 62. Marked @stability unstable.
442
- 63. An id is never accepted, while the generated dts names the field companyId: string.
443
- 64. A populated document is not validated with its own schema (an invalid Dog passes).
444
- 65. The labels are reversed: a many field is labelled many-to-one and a single reference one-to-many.
445
- 66. A resolver either builds or throws for one reader/writer pair; there is no backward/forward/full classification.
446
- 67. Any non-integer number below 2^53 is inferred as float (32-bit), which loses precision when encoded (lib/types.js:247-252).
447
- 68. Works on Effect Channels/Streams (unstable), not on Web Streams directly.
448
- 69. Both are @stability unstable; the interpreter is the default.
444
+ 53. Opt-in, in parse only (check never converts): strict decimal strings, <code>true</code>/<code>false</code>/<code>1</code>/<code>0</code>, ISO dates with a zone, never the empty string; a value a union branch accepts as it is is not converted; <code>coerce()</code> is the step alone.
445
+ 54. Lenient: number().coerce() turns "1abc" into 1, number() accepts NaN, bigint() accepts true (script).
446
+ 55. number() also rejects values beyond Number.MAX_SAFE_INTEGER unless unsafe() (types/number.js:104).
447
+ 56. fromObject does not validate: { age: 'abc' } becomes 0 and { name: 42 } "42".
448
+ 57. Only number/string/boolean are typed: a nested struct, enum, array or custom type is rendered as string (profile: string), and a reference as &lt;name&gt;Id: string although check validates the embedded record.
449
+ 58. Schemas do not carry ~standard themselves ('~standard' in schema is false); wrap with Schema.toStandardSchemaV1 / toStandardJSONSchemaV1.
450
+ 59. ~standard.validate always returns a promise and runs with abortEarly: false; array indexes come back as strings.
451
+ 60. ~standard.validate puts the dotted field string in path (the specification wants an array) and, for a valid falsy output (false, 0, ''), returns { issues: undefined } without the value. Schemas themselves have no ~standard; vine.create() validators do.
452
+ 61. On models only (a Schema has none), and validate always returns a promise; it casts, so { n: '5' } is valid with value n: 5.
453
+ 62. Its JSDoc calls it semi-experimental.
454
+ 63. Marked @stability unstable.
455
+ 64. An id is never accepted, while the generated dts names the field companyId: string.
456
+ 65. A populated document is not validated with its own schema (an invalid Dog passes).
457
+ 66. The labels are reversed: a many field is labelled many-to-one and a single reference one-to-many.
458
+ 67. A resolver either builds or throws for one reader/writer pair; there is no backward/forward/full classification.
459
+ 68. Any non-integer number below 2^53 is inferred as float (32-bit), which loses precision when encoded (lib/types.js:247-252).
460
+ 69. Works on Effect Channels/Streams (unstable), not on Web Streams directly.
461
+ 70. Both are @stability unstable; the interpreter is the default.
449
462
 
450
463
  <!-- comparison:end -->
451
464
 
@@ -559,7 +572,7 @@ generated types alike. See
559
572
 
560
573
  ## String formats
561
574
 
562
- `format` names a form a string must have; `@alexify/metaschema/formats` registers the nine
575
+ `format` names a form a string must have; `@alexify/metaschema/formats` registers the 35
563
576
  built-in formats and your own, once per process:
564
577
 
565
578
  ```js
@@ -601,6 +614,66 @@ in flight; `maxInvalid` ends an iteration after that many invalid records, and a
601
614
  without `onInvalid` ends its stream with `ERR_INVALID_RECORD`. See
602
615
  [Records and streams](https://metaschema.vercel.app/guide/streaming).
603
616
 
617
+ ## Coercion
618
+
619
+ Text from a query string, a form or a file converts to the types of the fields with
620
+ `coerce: true`, before the check; `check` never converts:
621
+
622
+ ```js
623
+ require('@alexify/metaschema/coerce').register();
624
+
625
+ const Query = new Schema('Query', {
626
+ Form: { coerce: true },
627
+ page: { type: 'integer', min: 1 },
628
+ all: 'boolean',
629
+ tags: { array: 'string' },
630
+ });
631
+ Query.parse(Object.fromEntries(new URLSearchParams('page=2&all=1&tags=news'))).value;
632
+ // { page: 2, all: true, tags: [ 'news' ] }
633
+ ```
634
+
635
+ The converters are strict (a number written as one, `true`/`false`/`1`/`0`, an ISO date with
636
+ its zone, never the empty string), a union takes a value a branch accepts as it is, and
637
+ `coerce(schema, value)` converts without checking. See
638
+ [Coercion](https://metaschema.vercel.app/guide/coercion).
639
+
640
+ ## Deriving schemas
641
+
642
+ ```js
643
+ const { omit, partial, pick } = require('@alexify/metaschema/derive');
644
+
645
+ const CreateAccount = omit(Account, ['password'], { name: 'CreateAccount' });
646
+ const UpdateAccount = partial(CreateAccount, { name: 'UpdateAccount' });
647
+ const AccountView = pick(Account, ['accountId', 'login', 'role'], { name: 'AccountView' });
648
+ ```
649
+
650
+ A derived schema is built from the definition of its source, every rule of a field included; a
651
+ stored kind becomes a struct without its id, `partial` leaves the defaults out (a patch keeps
652
+ what is stored), `extend` replaces fields where `merge` unifies them, and `register()` makes the
653
+ six methods (`Account.omit(['password']).partial()`). See
654
+ [Deriving schemas](https://metaschema.vercel.app/guide/derive).
655
+
656
+ ## MongoDB
657
+
658
+ ```js
659
+ const mongodb = require('mongodb');
660
+ const bson = require('@alexify/metaschema/mongodb');
661
+ bson.register({ bson: mongodb });
662
+
663
+ const model = new Model({ ...bson.types }, entities);
664
+ const validators = toJSONSchema(model, { target: 'mongodb', ids: 'objectId' });
665
+ const indexes = bson.indexesOf(model); // for createIndexes
666
+
667
+ const parsed = Account.parse(body);
668
+ if (parsed.valid) await accounts.insertOne(bson.toDocument(Account, parsed.value));
669
+ const { value } = bson.fromDocument(Account, await accounts.findOne({ login: 'ann' }));
670
+ if (bson.checkUpdate(Account, update).valid) await accounts.updateOne(filter, bson.toUpdate(Account, update));
671
+ ```
672
+
673
+ The program keeps ids as strings, the database as ObjectIds under `_id`; the subpath does no I/O
674
+ and imports nothing of the driver. Mongoose remains the tool for `populate`, middleware and
675
+ change tracking. See [MongoDB](https://metaschema.vercel.app/guide/mongodb).
676
+
604
677
  ## Inferring a definition
605
678
 
606
679
  `infer` of `@alexify/metaschema/model` reads a definition out of the values that exist, the
@@ -742,6 +815,9 @@ const { compile, compiled, canEval } = require('@alexify/metaschema/compile'); /
742
815
  const { fromJSON, diff, compatibility, compatibilityOf, sample, merge, infer } = require('@alexify/metaschema/model'); // and its own register()
743
816
  const { checkEach, parseEach, checkEachAsync, parseEachAsync, transform } = require('@alexify/metaschema/stream'); // and its own register()
744
817
  const { FORMATS, register: registerFormats } = require('@alexify/metaschema/formats'); // fills the table the format rule reads
818
+ const { pick, omit, partial, required, extend, keyof } = require('@alexify/metaschema/derive'); // and its own register()
819
+ const { COERCIONS, coerce, register: registerCoercion } = require('@alexify/metaschema/coerce'); // the converters parse runs
820
+ const { types, toDocument, fromDocument, fromDocumentAsync, indexesOf, checkUpdate, toUpdate } = require('@alexify/metaschema/mongodb'); // and register({ bson })
745
821
 
746
822
  const en = require('@alexify/metaschema/locales/en'); // the built-in messages
747
823
  const uk = require('@alexify/metaschema/locales/uk'); // schema.check(value, { messages: uk })