@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.
- package/CHANGELOG.md +307 -1
- package/README.md +173 -89
- package/SECURITY.md +24 -1
- package/index.d.ts +601 -29
- package/package.json +28 -3
- package/src/checks.js +789 -0
- package/src/codec.js +201 -46
- package/src/coerce/index.d.ts +34 -0
- package/src/coerce/index.js +385 -0
- package/src/compile/emit.js +87 -28
- package/src/compile/index.js +9 -4
- package/src/context.js +6 -1
- package/src/definition/index.d.ts +19 -0
- package/src/definition/index.js +27 -0
- package/src/derive/index.d.ts +86 -0
- package/src/derive/index.js +273 -0
- package/src/errors.js +46 -4
- package/src/formats/index.d.ts +20 -8
- package/src/formats/index.js +450 -39
- package/src/generators/fromjsonschema.js +21 -2
- package/src/generators/index.js +1 -1
- package/src/generators/jsonschema.js +90 -21
- package/src/generators/typescript.js +11 -0
- package/src/index.js +3 -2
- package/src/issues.js +9 -7
- package/src/kinds.js +15 -3
- package/src/lint.js +38 -0
- package/src/locales/en.js +6 -0
- package/src/locales/uk.js +6 -0
- package/src/metadata.js +6 -24
- package/src/model/data.js +67 -10
- package/src/model/diff.js +7 -4
- package/src/model/index.js +1 -1
- package/src/model/infer.js +10 -3
- package/src/model/merge.js +16 -9
- package/src/model/restore.js +52 -7
- package/src/model/sample.js +28 -4
- package/src/model.js +54 -56
- package/src/mongodb/bson.js +130 -0
- package/src/mongodb/document.js +217 -0
- package/src/mongodb/index.d.ts +133 -0
- package/src/mongodb/index.js +24 -0
- package/src/mongodb/indexes.js +79 -0
- package/src/mongodb/update.js +258 -0
- package/src/preprocessor.js +1 -2
- package/src/prototypes/abstract.js +41 -67
- package/src/prototypes/collections.js +3 -90
- package/src/prototypes/flags.js +34 -0
- package/src/prototypes/json.js +0 -11
- package/src/prototypes/reference.js +0 -76
- package/src/prototypes/scalars.js +17 -96
- package/src/prototypes/schema.js +1 -10
- package/src/prototypes/tuple.js +0 -26
- package/src/prototypes/union.js +12 -82
- package/src/rules.js +33 -157
- package/src/schema.js +105 -220
- package/src/snapshot.js +216 -41
- package/src/stream/index.js +1 -1
- package/src/struct.js +6 -91
- package/src/types.js +43 -6
- package/src/util.js +43 -0
- package/src/validation.js +313 -0
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`, `
|
|
67
|
-
`time`, `ipv4`, `
|
|
68
|
-
samples and
|
|
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,
|
|
@@ -84,23 +95,28 @@ event.parse({ name: 'deploy', when: '2026-10-10T12:00:00.000Z' }).value;
|
|
|
84
95
|
LLM structured outputs; `~standard.jsonSchema` is the Standard JSON Schema converter. The
|
|
85
96
|
generators live in the `@alexify/metaschema/generators` subpath, so a program that only
|
|
86
97
|
validates does not carry them.
|
|
87
|
-
- **Fast.** Every check is compiled into a closure
|
|
98
|
+
- **Fast.** Every check is compiled into a closure on its first use and runs in a context
|
|
88
99
|
of its own: about 10 million validations a second of a flat struct on Node 24, and about 30
|
|
89
100
|
million through the JIT backend of `@alexify/metaschema/compile`, which generates the same
|
|
90
101
|
check where `new Function` is allowed and keeps the closures where it is not. Against ten other
|
|
91
102
|
validators see [Benchmarks](#benchmarks); how the core gets there is on the
|
|
92
103
|
[Performance](https://metaschema.vercel.app/guide/performance) page.
|
|
93
104
|
- **The model as data.** `model.toJSON()` is a snapshot other programs read the model through
|
|
94
|
-
(a migration tool, an introspecting service, a committed baseline),
|
|
105
|
+
(a migration tool, an introspecting service, a committed baseline), `schema.toSnapshot()` the
|
|
106
|
+
same document for one schema and the entities it reaches (a codec built from it), with the
|
|
107
|
+
guarantees of format 1 written down, and
|
|
95
108
|
`@alexify/metaschema/model` tells two versions apart (`diff`), classifies the change by the
|
|
96
109
|
Confluent rules (`compatibility`), draws a value every schema accepts (`sample`), unifies two
|
|
97
110
|
schemas (`merge`) and infers a definition from the values that exist (`infer`); `aliases` and
|
|
98
111
|
`deprecated` let a model carry its history, and `fromJSONSchema` of the generators reads a
|
|
99
112
|
JSON Schema document back.
|
|
100
|
-
- **Zero dependencies,
|
|
101
|
-
one package for Node.js and browsers; the generators add 7.
|
|
102
|
-
model tools 12.
|
|
103
|
-
|
|
113
|
+
- **Zero dependencies, 21.3 KB min+gzip.** CommonJS with ESM named imports, no build step,
|
|
114
|
+
one package for Node.js and browsers; the generators add 7.7 KB, the JIT backend 4.3 KB, the
|
|
115
|
+
model tools 12.7 KB, the record tools 0.9 KB, the string formats 3.9 KB, the derive tools
|
|
116
|
+
2.2 KB, the converters of coercion 1.9 KB and the MongoDB tools 3.6 KB (on top of the
|
|
117
|
+
converters, which they require) where they are imported. A program that reads schemas
|
|
118
|
+
without validating them (a client that encodes from their snapshots) imports
|
|
119
|
+
`@alexify/metaschema/definition`, the half of the core that builds them: 10.3 KB.
|
|
104
120
|
|
|
105
121
|
## Benchmarks
|
|
106
122
|
|
|
@@ -144,21 +160,21 @@ only to Ajv, and 6 to 100 times faster than the other TypeScript-first validator
|
|
|
144
160
|
|
|
145
161
|
| 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
162
|
| --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: |
|
|
147
|
-
| **metaschema**<br><sub>check() · compile(), JIT · v3.
|
|
148
|
-
| **metaschema**<br><sub>check() · closures · v3.
|
|
149
|
-
| Metarhia metaschema<br><sub>check() · strict only · v2.2.2</sub> | — |
|
|
150
|
-
| Zod<br><sub>safeParse() · v4.6.6</sub> | 26,
|
|
151
|
-
| Valibot<br><sub>safeParse() · is() · v1.5.0</sub> | 3,
|
|
152
|
-
| ArkType<br><sub>type(value) · allows() · v2.2.8</sub> |
|
|
153
|
-
| Effect Schema<br><sub>decodeUnknownResult() · is() · v4.0.3</sub> | 4,
|
|
154
|
-
| TypeBox<br><sub>Compile(…).Check() · v1.3.36</sub> |
|
|
155
|
-
| TypeBox<br><sub>Value.Check() · v1.3.36</sub> |
|
|
156
|
-
| Ajv<br><sub>compile(…)(value), draft 2020-12 · v8.20.0</sub> |
|
|
157
|
-
| Yup<br><sub>validateSync() · isValidSync(), strict · v1.7.1</sub> |
|
|
158
|
-
| Joi<br><sub>validate(), convert: false · v18.2.9</sub> |
|
|
159
|
-
| Superstruct<br><sub>validate() · is() · v2.0.2</sub> |
|
|
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-
|
|
163
|
+
| **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 |
|
|
164
|
+
| **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 |
|
|
165
|
+
| Metarhia metaschema<br><sub>check() · strict only · v2.2.2</sub> | — | 958,000 | — | 959,000 | — | 550,000 | — | 546,000 | 428,000 | 282,000 |
|
|
166
|
+
| 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 |
|
|
167
|
+
| 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 |
|
|
168
|
+
| 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 |
|
|
169
|
+
| 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 |
|
|
170
|
+
| 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 |
|
|
171
|
+
| 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 |
|
|
172
|
+
| 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 |
|
|
173
|
+
| 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 |
|
|
174
|
+
| 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 |
|
|
175
|
+
| 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 |
|
|
176
|
+
|
|
177
|
+
_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
178
|
|
|
163
179
|
<!-- bench:compare:end -->
|
|
164
180
|
|
|
@@ -175,19 +191,19 @@ interactive.
|
|
|
175
191
|
|
|
176
192
|
| Library | Load | Build | First check | Total |
|
|
177
193
|
| --- | ---: | ---: | ---: | ---: |
|
|
178
|
-
| Superstruct<br><sub>validate() · is() · v2.0.2</sub> | 0.
|
|
179
|
-
| Valibot<br><sub>safeParse() · is() · v1.5.0</sub> | 3.7 ms | 0.1 ms | 0.1 ms |
|
|
180
|
-
| Yup<br><sub>validateSync() · isValidSync(), strict · v1.7.1</sub> | 2.
|
|
181
|
-
| **metaschema**<br><sub>check() · closures · v3.
|
|
182
|
-
| **metaschema**<br><sub>check() · compile(), JIT · v3.
|
|
194
|
+
| Superstruct<br><sub>validate() · is() · v2.0.2</sub> | 0.7 ms | 0.2 ms | 0.3 ms | 1.2 ms |
|
|
195
|
+
| Valibot<br><sub>safeParse() · is() · v1.5.0</sub> | 3.7 ms | 0.1 ms | 0.1 ms | 3.9 ms |
|
|
196
|
+
| Yup<br><sub>validateSync() · isValidSync(), strict · v1.7.1</sub> | 2.4 ms | 1.1 ms | 0.7 ms | 4.2 ms |
|
|
197
|
+
| **metaschema**<br><sub>check() · closures · v3.3.0</sub> | 4.7 ms | 1.0 ms | 0.4 ms | 6.1 ms |
|
|
198
|
+
| **metaschema**<br><sub>check() · compile(), JIT · v3.3.0</sub> | 5.9 ms | 1.7 ms | 0.2 ms | 7.8 ms |
|
|
183
199
|
| 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.
|
|
185
|
-
| Zod<br><sub>safeParse() · v4.6.6</sub> | 27.7 ms | 1.
|
|
186
|
-
| Ajv<br><sub>compile(…)(value), draft 2020-12 · v8.20.0</sub> | 14.
|
|
187
|
-
| Effect Schema<br><sub>decodeUnknownResult() · is() · v4.0.3</sub> |
|
|
188
|
-
| TypeBox<br><sub>Value.Check() · v1.3.36</sub> |
|
|
189
|
-
| TypeBox<br><sub>Compile(…).Check() · v1.3.36</sub> |
|
|
190
|
-
| ArkType<br><sub>type(value) · allows() · v2.2.8</sub> |
|
|
200
|
+
| Joi<br><sub>validate(), convert: false · v18.2.9</sub> | 23.1 ms | 1.2 ms | 0.6 ms | 25.0 ms |
|
|
201
|
+
| Zod<br><sub>safeParse() · v4.6.6</sub> | 27.7 ms | 1.5 ms | 1.2 ms | 30.3 ms |
|
|
202
|
+
| Ajv<br><sub>compile(…)(value), draft 2020-12 · v8.20.0</sub> | 14.6 ms | 24.4 ms | 0.2 ms | 39.3 ms |
|
|
203
|
+
| Effect Schema<br><sub>decodeUnknownResult() · is() · v4.0.3</sub> | 72.4 ms | 0.2 ms | 0.8 ms | 73.4 ms |
|
|
204
|
+
| TypeBox<br><sub>Value.Check() · v1.3.36</sub> | 96.6 ms | 0.1 ms | 1.1 ms | 97.8 ms |
|
|
205
|
+
| TypeBox<br><sub>Compile(…).Check() · v1.3.36</sub> | 96.9 ms | 1.9 ms | 0.0 ms | 98.9 ms |
|
|
206
|
+
| ArkType<br><sub>type(value) · allows() · v2.2.8</sub> | 107.8 ms | 1.4 ms | 0.1 ms | 109.3 ms |
|
|
191
207
|
|
|
192
208
|
<!-- bench:coldstart:end -->
|
|
193
209
|
|
|
@@ -204,8 +220,8 @@ interactive.
|
|
|
204
220
|
| Superstruct<br><sub>validate() · is() · v2.0.2</sub> | 3.5 KB | 1.5 KB | |
|
|
205
221
|
| 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
222
|
| Yup<br><sub>validateSync() · isValidSync(), strict · v1.7.1</sub> | 41.4 KB | 13.2 KB | |
|
|
207
|
-
| **metaschema**<br><sub>check() · closures · v3.
|
|
208
|
-
| **metaschema**<br><sub>check() · compile(), JIT · v3.
|
|
223
|
+
| **metaschema**<br><sub>check() · closures · v3.3.0</sub> | 52.6 KB | 18.9 KB | |
|
|
224
|
+
| **metaschema**<br><sub>check() · compile(), JIT · v3.3.0</sub> | 65.2 KB | 23.1 KB | |
|
|
209
225
|
| Effect Schema<br><sub>decodeUnknownResult() · is() · v4.0.3</sub> | 72.9 KB | 24.4 KB | |
|
|
210
226
|
| Zod<br><sub>safeParse() · v4.6.6</sub> | 88.4 KB | 25.7 KB | |
|
|
211
227
|
| TypeBox<br><sub>Value.Check() · v1.3.36</sub> | 146.7 KB | 37.5 KB | |
|
|
@@ -221,7 +237,7 @@ interactive.
|
|
|
221
237
|
<!-- bench:releases:start -->
|
|
222
238
|
<!-- generated by `pnpm bench:report` from bench/results — edit the results, not this block -->
|
|
223
239
|
|
|
224
|
-
<img src="https://metaschema.vercel.app/benchmarks/speedup.svg" alt="metaschema 3.
|
|
240
|
+
<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
241
|
|
|
226
242
|
<details>
|
|
227
243
|
<summary>Every release, scenario by scenario</summary>
|
|
@@ -240,16 +256,16 @@ interactive.
|
|
|
240
256
|
|
|
241
257
|
</details>
|
|
242
258
|
|
|
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 |
|
|
259
|
+
| 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> |
|
|
260
|
+
| --- | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: | ---: |
|
|
261
|
+
| Schema.from — flat struct | 581,000 | 321,000 | 362,000 | 372,000 | — | 367,000 | — | 356,000 | — | 332,000 | — |
|
|
262
|
+
| Schema.from — nested struct | 156,000 | 95,600 | 104,000 | 99,000 | — | 98,400 | — | 98,600 | — | 91,100 | — |
|
|
263
|
+
| 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 |
|
|
264
|
+
| 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 |
|
|
265
|
+
| 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 |
|
|
266
|
+
| 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
267
|
|
|
252
|
-
_Apple M3 Max · 16 cores · Node v24.14.1 · median of 5 × 1 s samples, each release in a fresh process · 2026-10-
|
|
268
|
+
_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
269
|
|
|
254
270
|
<!-- bench:releases:end -->
|
|
255
271
|
|
|
@@ -305,7 +321,7 @@ pinned.
|
|
|
305
321
|
</thead>
|
|
306
322
|
<tbody>
|
|
307
323
|
<tr class="ms-matrix-group"><td colspan="22"><strong>Package</strong></td></tr>
|
|
308
|
-
<tr><td>Version compared</td><td>3.
|
|
324
|
+
<tr><td>Version compared</td><td>3.4.0</td><td>2.2.2</td><td>4.6.6</td><td>1.5.0</td><td>2.2.8</td><td>4.0.3</td><td>2.0.2<sup>1</sup></td><td>2.2.22</td><td>7.0.5</td><td>1.12.1<sup>2</sup></td><td>0.5.5</td><td>1.7.1</td><td>18.2.9</td><td>4.4.0</td><td>0.15.1</td><td>8.20.0</td><td>1.3.36<sup>3</sup></td><td>15.1.0</td><td>5.7.9</td><td>8.8.1</td><td>9.11.1</td></tr>
|
|
309
325
|
<tr><td>Latest release</td><td>2026-10 (this release)</td><td>2025-05</td><td>2026-10</td><td>2026-09</td><td>2026-10</td><td>2026-10</td><td>2024-07</td><td>2024-12</td><td>2026-08</td><td>2025-02</td><td>2026-10</td><td>2025-09</td><td>2026-09</td><td>2026-04</td><td>2026-02</td><td>2026-04</td><td>2026-10</td><td>2026-10</td><td>2025-07</td><td>2026-10</td><td>2026-10</td></tr>
|
|
310
326
|
<tr><td>Runtime dependencies</td><td>✅ 0</td><td>2: metautil, metavm</td><td>✅ 0</td><td>✅ 0</td><td>3: @ark/schema, @ark/util, arkregex</td><td>✅ 0</td><td>✅ 0</td><td>0 + peer fp-ts</td><td>✅ 0</td><td>✅ 0</td><td>✅ 0</td><td>4: property-expr, tiny-case, toposort, type-fest</td><td>7 (@hapi/*, …)</td><td>10 (validator.js, dayjs, …)</td><td>3 (validator.js, libphonenumber-js, …)</td><td>4</td><td>✅ 0</td><td>3: randexp, @typia/interface, @typia/utils</td><td>✅ 0</td><td>1: long</td><td>7, incl. mongodb driver</td></tr>
|
|
311
327
|
<tr><td>License</td><td>MIT</td><td>MIT</td><td>MIT</td><td>MIT</td><td>MIT</td><td>MIT</td><td>MIT</td><td>MIT</td><td>MIT</td><td>MIT</td><td>MIT</td><td>MIT</td><td>BSD-3-Clause</td><td>MIT</td><td>MIT</td><td>MIT</td><td>MIT</td><td>MIT</td><td>MIT</td><td>BSD-3-Clause</td><td>MIT</td></tr>
|
|
@@ -320,11 +336,11 @@ pinned.
|
|
|
320
336
|
<tr><td>Optional vs nullable</td><td>✅ <code>'?x'</code>, <code>'key?'</code>, <code>nullable: true</code></td><td>⚠️ '?type' = absent/undefined/null</td><td>✅ optional, exactOptional, nullable, nullish</td><td>✅ optional, exactOptional, nullable, nullish, undefinedable</td><td>✅ 'key?' (no undefined), '| null', '| undefined'</td><td>✅ optionalKey, optional, NullOr, UndefinedOr, NullishOr</td><td>✅ optional(), nullable()</td><td>✅ t.partial vs t.union([X, t.null])</td><td>✅ optional(), nullable(), undefinedable()</td><td>✅ optional(), nullable()</td><td>✅ optional(), nullable()</td><td>✅ optional() / nullable() / defined()</td><td>✅ optional default; allow(null); required()</td><td>⚠️ optional() also accepts null<sup>14</sup></td><td>⚠️ IsOptional() skips null and undefined</td><td>✅ <code>required</code> vs type null / <code>nullable</code></td><td>✅ Optional, Union with Null, Undefined</td><td>✅ TS <code>?:</code>, <code>| null</code>, <code>| undefined</code></td><td>⚠️ ['null', T] union; absent needs default</td><td>⚠️ presence only; null = unset</td><td>⚠️ optional = absent/undefined/null</td></tr>
|
|
321
337
|
<tr><td>Unions, discriminated</td><td>✅ <code>union</code>, <code>discriminator</code></td><td>❌ none</td><td>✅ union, discriminatedUnion, xor</td><td>✅ union, variant (discriminated)</td><td>✅ 'a | b', .or(); auto-discriminated</td><td>✅ Union, Literals, TaggedUnion</td><td>⚠️ union(); no discriminated union</td><td>✅ union(), tag detected automatically</td><td>⚠️ Union(...); no discriminator</td><td>⚠️ union([..]) / or(); no discriminator</td><td>✅ union(), auto-discriminated</td><td>❌ no union type</td><td>✅ alternatives(); conditional() switch</td><td>✅ union() with if(), unionOfTypes()</td><td>⚠️ class-transformer discriminator</td><td>✅ anyOf / oneOf; <code>discriminator</code> opt-in</td><td>✅ Type.Union (anyOf); no discriminator</td><td>✅ TS unions; discriminant detected</td><td>✅ unions; wrapped = tagged by name</td><td>✅ oneof (virtual discriminator)</td><td>✅ Schema.Types.Union; discriminators</td></tr>
|
|
322
338
|
<tr><td>Tuples</td><td>✅ <code>['number', 'string']</code></td><td>⚠️ array shorthand, scalars only</td><td>✅ z.tuple with rest</td><td>✅ tuple, strictTuple, tupleWithRest</td><td>✅ ['string', 'number'], variadic '...'</td><td>✅ Tuple, TupleWithRest</td><td>✅ tuple([..])</td><td>⚠️ tuple([..]) strips extra items<sup>15</sup></td><td>✅ Tuple(...), with Spread rest</td><td>✅ tuple([..])</td><td>✅ tuple([..]), variadic via concat<sup>16</sup></td><td>✅ tuple()</td><td>✅ array().ordered()</td><td>✅ vine.tuple()</td><td>❌ none</td><td>✅ prefixItems + items: false</td><td>✅ Type.Tuple</td><td>✅ TS tuples</td><td>❌ none</td><td>❌ none</td><td>❌ none</td></tr>
|
|
323
|
-
<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(() => S)</td><td>✅ t.recursion(name, f)</td><td>✅ Lazy(() => R)</td><td>✅ lazy(() => S)</td><td>✅ lazy(() => T)</td><td>✅ lazy()</td><td>✅ link('#id')</td><td>❌ none</td><td>✅ @ValidateNested + @Type(() => 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>
|
|
339
|
+
<tr><td>Recursive schemas</td><td>✅ by name, a schema its own without a model; 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(() => S)</td><td>✅ t.recursion(name, f)</td><td>✅ Lazy(() => R)</td><td>✅ lazy(() => S)</td><td>✅ lazy(() => T)</td><td>✅ lazy()</td><td>✅ link('#id')</td><td>❌ none</td><td>✅ @ValidateNested + @Type(() => 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
340
|
<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
341
|
<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>✅
|
|
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>
|
|
342
|
+
<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>
|
|
343
|
+
<tr><td>Date, BigInt, Map, Set</td><td>✅ Date, BigInt, Map, Set, Uint8Array; 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
344
|
<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
345
|
<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
346
|
<tr class="ms-matrix-group"><td colspan="22"><strong>Validation results</strong></td></tr>
|
|
@@ -338,37 +354,37 @@ pinned.
|
|
|
338
354
|
<tr class="ms-matrix-group"><td colspan="22"><strong>Parsing</strong></td></tr>
|
|
339
355
|
<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(() => v), nullable(() => 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<V> is metadata only</td><td>✅ field default (clone, decode)</td><td>✅ proto defaults, toObject({ defaults })</td><td>✅ default values and functions</td></tr>
|
|
340
356
|
<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(), '=>'</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
|
|
357
|
+
<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
358
|
<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
359
|
<tr class="ms-matrix-group"><td colspan="22"><strong>TypeScript</strong></td></tr>
|
|
344
360
|
<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<typeof S></td><td>✅ t.TypeOf<typeof C></td><td>✅ Static<typeof R></td><td>✅ Infer<typeof S></td><td>✅ v.Infer<typeof T></td><td>✅ InferType</td><td>❌ none</td><td>✅ Infer<typeof schema></td><td>⚠️ the class is the type</td><td>⚠️ JTDDataType (JTD only)</td><td>✅ Static<T>, 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
361
|
<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>
|
|
362
|
+
<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
363
|
<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>
|
|
364
|
+
<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<T>() (v1)</td><td>❌ no</td><td>❌ no</td><td>✅ Model['~standard'] v1 (9.7+)<sup>61</sup></td></tr>
|
|
349
365
|
<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>
|
|
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>
|
|
366
|
+
<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>
|
|
367
|
+
<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
368
|
<tr class="ms-matrix-group"><td colspan="22"><strong>Domain models</strong></td></tr>
|
|
353
369
|
<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>
|
|
355
|
-
<tr><td>Indexes and unique keys</td><td>✅ <code>index</code>, <code>primary</code>, <code>unique</code
|
|
356
|
-
<tr><td>Relation metadata</td><td>✅ <code>schema.relations</code></td><td>⚠️ schema.relations { to, type }<sup>
|
|
357
|
-
<tr><td>Derive a schema: pick, omit, partial, extend</td><td
|
|
370
|
+
<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>
|
|
371
|
+
<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>
|
|
372
|
+
<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>
|
|
373
|
+
<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
374
|
<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
375
|
<tr class="ms-matrix-group"><td colspan="22"><strong>Evolution</strong></td></tr>
|
|
360
|
-
<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>
|
|
376
|
+
<tr><td>Snapshot of a schema or model</td><td>✅ <code>model.toJSON()</code>, <code>schema.toSnapshot()</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
377
|
<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>
|
|
378
|
+
<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
379
|
<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
380
|
<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
381
|
<tr class="ms-matrix-group"><td colspan="22"><strong>Tooling</strong></td></tr>
|
|
366
382
|
<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<T>() (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>
|
|
383
|
+
<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
384
|
<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 & B)</td><td>⚠️ Type.forTypes (widening)</td><td>❌ none</td><td>✅ schema.add(other), new Schema([a, b])</td></tr>
|
|
369
385
|
<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>
|
|
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>
|
|
386
|
+
<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>
|
|
387
|
+
<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
388
|
<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
389
|
</tbody>
|
|
374
390
|
</table>
|
|
@@ -429,23 +445,24 @@ pinned.
|
|
|
429
445
|
50. The default is a value, not a factory: default([]) hands every parse the same array (script).
|
|
430
446
|
51. Defaults are written into the input object, and not inside anyOf/oneOf/not.
|
|
431
447
|
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.
|
|
433
|
-
54. number()
|
|
434
|
-
55.
|
|
435
|
-
56.
|
|
436
|
-
57.
|
|
437
|
-
58.
|
|
438
|
-
59. ~standard.validate
|
|
439
|
-
60.
|
|
440
|
-
61.
|
|
441
|
-
62.
|
|
442
|
-
63.
|
|
443
|
-
64.
|
|
444
|
-
65.
|
|
445
|
-
66.
|
|
446
|
-
67.
|
|
447
|
-
68.
|
|
448
|
-
69.
|
|
448
|
+
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.
|
|
449
|
+
54. Lenient: number().coerce() turns "1abc" into 1, number() accepts NaN, bigint() accepts true (script).
|
|
450
|
+
55. number() also rejects values beyond Number.MAX_SAFE_INTEGER unless unsafe() (types/number.js:104).
|
|
451
|
+
56. fromObject does not validate: { age: 'abc' } becomes 0 and { name: 42 } "42".
|
|
452
|
+
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 <name>Id: string although check validates the embedded record.
|
|
453
|
+
58. Schemas do not carry ~standard themselves ('~standard' in schema is false); wrap with Schema.toStandardSchemaV1 / toStandardJSONSchemaV1.
|
|
454
|
+
59. ~standard.validate always returns a promise and runs with abortEarly: false; array indexes come back as strings.
|
|
455
|
+
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.
|
|
456
|
+
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.
|
|
457
|
+
62. Its JSDoc calls it semi-experimental.
|
|
458
|
+
63. Marked @stability unstable.
|
|
459
|
+
64. An id is never accepted, while the generated dts names the field companyId: string.
|
|
460
|
+
65. A populated document is not validated with its own schema (an invalid Dog passes).
|
|
461
|
+
66. The labels are reversed: a many field is labelled many-to-one and a single reference one-to-many.
|
|
462
|
+
67. A resolver either builds or throws for one reader/writer pair; there is no backward/forward/full classification.
|
|
463
|
+
68. Any non-integer number below 2^53 is inferred as float (32-bit), which loses precision when encoded (lib/types.js:247-252).
|
|
464
|
+
69. Works on Effect Channels/Streams (unstable), not on Web Streams directly.
|
|
465
|
+
70. Both are @stability unstable; the interpreter is the default.
|
|
449
466
|
|
|
450
467
|
<!-- comparison:end -->
|
|
451
468
|
|
|
@@ -468,20 +485,23 @@ TypeScript 5.0 or newer.
|
|
|
468
485
|
| Optional | `subtitle: '?string'` or `'subtitle?': 'string'` | the key may be absent, `undefined` or `null` |
|
|
469
486
|
| Nullable | `parent: { type: 'string', nullable: true }` | the key is required, the value may be `null` |
|
|
470
487
|
| Long form | `login: { type: 'string', length: [3, 32] }` | a type with options, `type` first |
|
|
471
|
-
| Rules | `{ type: 'integer', min: 18, max: 120 }`, `{ type: 'string', pattern: '^[a-z]+$', length: { max: 32 } }` | `min`/`max` for numbers, `length`/`pattern`/`format` for strings, `length` for collections |
|
|
488
|
+
| Rules | `{ type: 'integer', min: 18, max: 120 }`, `{ type: 'string', pattern: '^[a-z]+$', length: { max: 32 } }`, `{ type: 'number', decimals: 2 }` | `min`/`max` for numbers, `decimals` for a number, `length`/`pattern`/`format` for strings, `length` for collections |
|
|
472
489
|
| Collections | `{ array: 'number' }`, `{ set: 'string' }`, `{ object: { string: 'number' } }`, `{ map: { string: 'string' } }` | |
|
|
473
490
|
| Enum | `{ enum: ['admin', 'user'] }` | one of the values |
|
|
491
|
+
| Flags | `perms: { flags: ['read', 'write'] }` | an object of those names, each `true` or `false` |
|
|
492
|
+
| Bytes | `avatar: 'bytes'` | a `Uint8Array` (a `Buffer` too) |
|
|
474
493
|
| Tuple | `point: ['number', 'number']` | a fixed-length array, each element its own definition |
|
|
475
494
|
| Union | `id: { union: ['string', 'number'] }`, `{ union: [...], discriminator: 'kind' }` | one of several definitions |
|
|
476
495
|
| Nested struct | `name: { first: 'string', last: 'string' }` | an object whose first key is none of the above |
|
|
477
|
-
| Reference | `company: 'Company'`, `{ many: 'Address' }` | another schema in the model: its id for a stored kind, the record for a memory kind |
|
|
496
|
+
| Reference | `company: 'Company'`, `{ many: 'Address' }` | another schema in the model (or the schema itself, by its own name): its id for a stored kind, the record for a memory kind |
|
|
478
497
|
| Any object | `payload: 'json'` | any non-null object |
|
|
479
498
|
| Calculated | `ratio: (file) => file.compressed / file.size` | a function, never validated |
|
|
480
499
|
|
|
481
500
|
The first key of an object decides what it is. Built-in types: `string`, `number`, `integer`,
|
|
482
|
-
`bigint`, `boolean`, `date`, `null`, `any`/`unknown`, `enum`, `
|
|
483
|
-
`tuple`, `union`, `json`. Rules: `length` (with `unicode: true` for code
|
|
484
|
-
`format` for strings, `length` for collections, `min`/`max` for numbers
|
|
501
|
+
`bigint`, `boolean`, `date`, `bytes`, `null`, `any`/`unknown`, `enum`, `flags`, `array`, `set`,
|
|
502
|
+
`object`, `map`, `tuple`, `union`, `json`. Rules: `length` (with `unicode: true` for code
|
|
503
|
+
points), `pattern` and `format` for strings, `length` for collections, `min`/`max` for numbers,
|
|
504
|
+
`decimals` for a number; a rule on a type that does not
|
|
485
505
|
take it is a definition error. Fields can add a `validate(value, path)` function, and a schema
|
|
486
506
|
can have a top-level `validate` for rules across fields. `check(value, options)` takes `root`
|
|
487
507
|
(the label of the error lines), `maxErrors`, `unknown: 'ignore'` (keys the schema does not have;
|
|
@@ -559,7 +579,7 @@ generated types alike. See
|
|
|
559
579
|
|
|
560
580
|
## String formats
|
|
561
581
|
|
|
562
|
-
`format` names a form a string must have; `@alexify/metaschema/formats` registers the
|
|
582
|
+
`format` names a form a string must have; `@alexify/metaschema/formats` registers the 35
|
|
563
583
|
built-in formats and your own, once per process:
|
|
564
584
|
|
|
565
585
|
```js
|
|
@@ -601,6 +621,66 @@ in flight; `maxInvalid` ends an iteration after that many invalid records, and a
|
|
|
601
621
|
without `onInvalid` ends its stream with `ERR_INVALID_RECORD`. See
|
|
602
622
|
[Records and streams](https://metaschema.vercel.app/guide/streaming).
|
|
603
623
|
|
|
624
|
+
## Coercion
|
|
625
|
+
|
|
626
|
+
Text from a query string, a form or a file converts to the types of the fields with
|
|
627
|
+
`coerce: true`, before the check; `check` never converts:
|
|
628
|
+
|
|
629
|
+
```js
|
|
630
|
+
require('@alexify/metaschema/coerce').register();
|
|
631
|
+
|
|
632
|
+
const Query = new Schema('Query', {
|
|
633
|
+
Form: { coerce: true },
|
|
634
|
+
page: { type: 'integer', min: 1 },
|
|
635
|
+
all: 'boolean',
|
|
636
|
+
tags: { array: 'string' },
|
|
637
|
+
});
|
|
638
|
+
Query.parse(Object.fromEntries(new URLSearchParams('page=2&all=1&tags=news'))).value;
|
|
639
|
+
// { page: 2, all: true, tags: [ 'news' ] }
|
|
640
|
+
```
|
|
641
|
+
|
|
642
|
+
The converters are strict (a number written as one, `true`/`false`/`1`/`0`, an ISO date with
|
|
643
|
+
its zone, never the empty string), a union takes a value a branch accepts as it is, and
|
|
644
|
+
`coerce(schema, value)` converts without checking. See
|
|
645
|
+
[Coercion](https://metaschema.vercel.app/guide/coercion).
|
|
646
|
+
|
|
647
|
+
## Deriving schemas
|
|
648
|
+
|
|
649
|
+
```js
|
|
650
|
+
const { omit, partial, pick } = require('@alexify/metaschema/derive');
|
|
651
|
+
|
|
652
|
+
const CreateAccount = omit(Account, ['password'], { name: 'CreateAccount' });
|
|
653
|
+
const UpdateAccount = partial(CreateAccount, { name: 'UpdateAccount' });
|
|
654
|
+
const AccountView = pick(Account, ['accountId', 'login', 'role'], { name: 'AccountView' });
|
|
655
|
+
```
|
|
656
|
+
|
|
657
|
+
A derived schema is built from the definition of its source, every rule of a field included; a
|
|
658
|
+
stored kind becomes a struct without its id, `partial` leaves the defaults out (a patch keeps
|
|
659
|
+
what is stored), `extend` replaces fields where `merge` unifies them, and `register()` makes the
|
|
660
|
+
six methods (`Account.omit(['password']).partial()`). See
|
|
661
|
+
[Deriving schemas](https://metaschema.vercel.app/guide/derive).
|
|
662
|
+
|
|
663
|
+
## MongoDB
|
|
664
|
+
|
|
665
|
+
```js
|
|
666
|
+
const mongodb = require('mongodb');
|
|
667
|
+
const bson = require('@alexify/metaschema/mongodb');
|
|
668
|
+
bson.register({ bson: mongodb });
|
|
669
|
+
|
|
670
|
+
const model = new Model({ ...bson.types }, entities);
|
|
671
|
+
const validators = toJSONSchema(model, { target: 'mongodb', ids: 'objectId' });
|
|
672
|
+
const indexes = bson.indexesOf(model); // for createIndexes
|
|
673
|
+
|
|
674
|
+
const parsed = Account.parse(body);
|
|
675
|
+
if (parsed.valid) await accounts.insertOne(bson.toDocument(Account, parsed.value));
|
|
676
|
+
const { value } = bson.fromDocument(Account, await accounts.findOne({ login: 'ann' }));
|
|
677
|
+
if (bson.checkUpdate(Account, update).valid) await accounts.updateOne(filter, bson.toUpdate(Account, update));
|
|
678
|
+
```
|
|
679
|
+
|
|
680
|
+
The program keeps ids as strings, the database as ObjectIds under `_id`; the subpath does no I/O
|
|
681
|
+
and imports nothing of the driver. Mongoose remains the tool for `populate`, middleware and
|
|
682
|
+
change tracking. See [MongoDB](https://metaschema.vercel.app/guide/mongodb).
|
|
683
|
+
|
|
604
684
|
## Inferring a definition
|
|
605
685
|
|
|
606
686
|
`infer` of `@alexify/metaschema/model` reads a definition out of the values that exist, the
|
|
@@ -742,6 +822,10 @@ const { compile, compiled, canEval } = require('@alexify/metaschema/compile'); /
|
|
|
742
822
|
const { fromJSON, diff, compatibility, compatibilityOf, sample, merge, infer } = require('@alexify/metaschema/model'); // and its own register()
|
|
743
823
|
const { checkEach, parseEach, checkEachAsync, parseEachAsync, transform } = require('@alexify/metaschema/stream'); // and its own register()
|
|
744
824
|
const { FORMATS, register: registerFormats } = require('@alexify/metaschema/formats'); // fills the table the format rule reads
|
|
825
|
+
const { pick, omit, partial, required, extend, keyof } = require('@alexify/metaschema/derive'); // and its own register()
|
|
826
|
+
const { COERCIONS, coerce, register: registerCoercion } = require('@alexify/metaschema/coerce'); // the converters parse runs
|
|
827
|
+
const { types, toDocument, fromDocument, fromDocumentAsync, indexesOf, checkUpdate, toUpdate } = require('@alexify/metaschema/mongodb'); // and register({ bson })
|
|
828
|
+
const { Schema: Definition } = require('@alexify/metaschema/definition'); // the core's Schema and Model, built and read without validation
|
|
745
829
|
|
|
746
830
|
const en = require('@alexify/metaschema/locales/en'); // the built-in messages
|
|
747
831
|
const uk = require('@alexify/metaschema/locales/uk'); // schema.check(value, { messages: uk })
|