@alexify/metaschema 3.1.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/CHANGELOG.md +314 -1
- package/README.md +535 -20
- package/SECURITY.md +26 -7
- package/index.d.ts +496 -2
- package/package.json +53 -5
- package/src/codec.js +239 -74
- package/src/coerce/index.d.ts +34 -0
- package/src/coerce/index.js +352 -0
- package/src/compile/code.js +1 -1
- package/src/compile/emit.js +32 -7
- package/src/compile/index.d.ts +6 -0
- package/src/compile/index.js +12 -1
- package/src/context.js +11 -10
- package/src/derive/index.d.ts +86 -0
- package/src/derive/index.js +266 -0
- package/src/errors.js +28 -1
- package/src/formats/index.d.ts +31 -0
- package/src/formats/index.js +557 -0
- package/src/generators/fromjsonschema.js +16 -14
- package/src/generators/index.js +2 -1
- package/src/generators/jsonschema.js +47 -13
- package/src/issues.js +37 -20
- package/src/kinds.js +11 -2
- package/src/lint.js +24 -0
- package/src/locales/en.js +11 -2
- package/src/locales/uk.js +10 -2
- package/src/metadata.js +7 -2
- package/src/model/data.js +17 -0
- package/src/model/diff.js +1 -0
- package/src/model/index.d.ts +14 -2
- package/src/model/index.js +13 -10
- package/src/model/infer.js +483 -0
- package/src/model/merge.js +10 -6
- package/src/model/restore.js +3 -3
- package/src/model/sample.js +8 -5
- package/src/model.js +34 -4
- package/src/mongodb/bson.js +118 -0
- package/src/mongodb/document.js +209 -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 -0
- package/src/prototypes/abstract.js +9 -3
- package/src/prototypes/collections.js +4 -3
- package/src/prototypes/scalars.js +4 -4
- package/src/prototypes/union.js +2 -2
- package/src/result.js +6 -0
- package/src/rules.js +53 -4
- package/src/schema.js +53 -28
- package/src/snapshot.js +1 -1
- package/src/stream/index.d.ts +68 -0
- package/src/stream/index.js +247 -0
- package/src/struct.js +1 -1
- package/src/types.js +33 -1
- package/src/util.js +18 -0
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,317 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [3.3.0] - 2026-10-14
|
|
11
|
+
|
|
12
|
+
3.3 closes the gaps the comparison with the alternatives showed. `parse` converts the text of a
|
|
13
|
+
query string, a form or a file to the types of the fields when asked (coercion), schemas are
|
|
14
|
+
derived from schemas (`pick`, `omit`, `partial`, `required`, `extend`, `keyof`), the string
|
|
15
|
+
formats grow from nine to 35, and the `@alexify/metaschema/mongodb` subpath is the schema side
|
|
16
|
+
of a MongoDB program without a dependency on the driver. The review of the release before its
|
|
17
|
+
tag made the converters and five formats linear in the stack as well as in time on strings of
|
|
18
|
+
megabytes, capped the `regex` format, and closed the ways a document could carry a foreign
|
|
19
|
+
`_id` or throw on `null`. The changes in behaviour (`coerce` is a reserved key, `infer` writes
|
|
20
|
+
the more specific formats, a format of the program under the name of a new built-in takes its
|
|
21
|
+
place) are listed under Changed.
|
|
22
|
+
|
|
23
|
+
### Added
|
|
24
|
+
|
|
25
|
+
- **Coercion.** `parse(value, { coerce: true })`, the kind metadata
|
|
26
|
+
`{ Form: { coerce: true } }` (so `~standard.validate` too) or a field's `coerce: true|false`
|
|
27
|
+
converts the input to the types of the fields before the check: decimal strings to numbers
|
|
28
|
+
and bigints, `'true'`/`'false'`/`'1'`/`'0'` to booleans, ISO dates with their zone (and epoch
|
|
29
|
+
milliseconds) to `Date`, a single value to a list, an array to a `Set`, an object to a `Map`,
|
|
30
|
+
the written form of an enum member to the member. The converters are strict and never touch
|
|
31
|
+
the empty string; a value a union branch accepts as it is is not converted; `check` never
|
|
32
|
+
converts, and `Infer` does not change. The core has the policy and a step in the pass before
|
|
33
|
+
the check; the converters are the new `@alexify/metaschema/coerce` subpath's
|
|
34
|
+
(`register(custom)` adds the program's own by type name, an alias type converts as its base),
|
|
35
|
+
and `coerce(schema, value)` is that pass alone. A parse that coerces before `register()` is
|
|
36
|
+
`ERR_NOT_REGISTERED` as it enters the schema, whatever the value holds (an empty body does
|
|
37
|
+
not hide a missing `register()`); `register(custom)` checks every entry before it writes
|
|
38
|
+
any; `ERR_INVALID_COERCION` and `ERR_COERCION_REGISTERED` are new codes. The converters are
|
|
39
|
+
linear on hostile strings (a run of a hundred thousand digits that is not a number costs
|
|
40
|
+
nothing), and `toMap` converts a plain object or a list of pairs only.
|
|
41
|
+
`register(custom, { onError })` is told of a converter that threw (the value is left to the
|
|
42
|
+
check either way), the policy is read from own keys only (a `coerce` set on
|
|
43
|
+
`Object.prototype` elsewhere turns nothing on), and `coerce` on a reference checked as an id
|
|
44
|
+
or on a field of `any`, `unknown`, `json` or `null` is a `dead-coerce` warning. The converter
|
|
45
|
+
of a field is resolved once and kept with the field (a JIT parse that coerces is 11% faster
|
|
46
|
+
than with a lookup per value, a parse of enums of 32 members 2.3 times: the members and their
|
|
47
|
+
written forms are indexed once). `pnpm bench` has rows for a nested struct, plain unions,
|
|
48
|
+
enums and a plain and a coercing parse in turn, and for `toDocument`/`fromDocument`.
|
|
49
|
+
`coerce(schema, value, { report })` fills the array given with the path of every key the
|
|
50
|
+
pass changed; `new Model(types, entities, database, { coercions })` gives a model converters
|
|
51
|
+
of its own type names, read before the process-wide table for the fields of its entities
|
|
52
|
+
(what an isolated registry is to the types); the branches of a plain union are prepared
|
|
53
|
+
first and tried only when one of them changes the value, so a parse over a union of records
|
|
54
|
+
that nest unions is linear where nothing applies (4 times faster at a depth of 12).
|
|
55
|
+
- **`@alexify/metaschema/derive`.** `pick`, `omit`, `partial` (`keys`, `deep`, `defaults`),
|
|
56
|
+
`required`, `extend` and `keyof` build a new Schema from the definition a schema was built
|
|
57
|
+
from: a stored kind or a projection becomes a struct without the id of the kind (unless
|
|
58
|
+
named), `partial` leaves the defaults out, `pick`, `omit` and `partial` drop the schema's own
|
|
59
|
+
functions, `extend` replaces fields in place (where `merge` unifies), indexes stay while their
|
|
60
|
+
columns do. `register()` installs them as methods (`schema.omit(['id']).partial()`), typed by
|
|
61
|
+
the definition. `ERR_UNKNOWN_FIELD` names a key the schema has no field of.
|
|
62
|
+
- **26 string formats.** `ulid`, `jwt`, `nanoid`, `cuid2`, `iso-date-time`, `iso-time`,
|
|
63
|
+
`duration`, `cidrv4`, `cidrv6`, `mac`, `url`, `uri-reference`, `uri-template`,
|
|
64
|
+
`json-pointer`, `relative-json-pointer`, `regex`, `e164`, `iban`, `hex-color`, `base64`,
|
|
65
|
+
`base64url`, `hex`, `emoji`, `semver`, `slug` and `credit-card` (the expressions of
|
|
66
|
+
ajv-formats, zod, valibot and semver.org, held to them value by value). A format entry may
|
|
67
|
+
carry a `pattern`, which `toJSONSchema` writes beside a name JSON Schema does not know (the
|
|
68
|
+
one assertion of the mongodb target) and `fromJSONSchema` drops again; OpenAPI's `byte` is
|
|
69
|
+
`base64`. No built-in test overflows the stack of the regex engine on a string of
|
|
70
|
+
megabytes: `email`, `json-pointer`, `relative-json-pointer`, `uri-template`, `slug` and
|
|
71
|
+
`semver` are read by a scanner with the same verdicts, and a `regex` longer than 4096
|
|
72
|
+
characters is not one (compiling it costs memory in proportion). `register()` returns the
|
|
73
|
+
names of the built-in formats the call replaced with the program's own.
|
|
74
|
+
- **`@alexify/metaschema/mongodb`.** The BSON types `objectId`, `decimal128` and `binary`
|
|
75
|
+
(recognized without importing bson), `register({ bson })` with the program's driver,
|
|
76
|
+
`toDocument`/`fromDocument` (the id of a stored record as `_id`, ids of references as
|
|
77
|
+
ObjectIds, and back), `indexesOf` for `createIndexes`, `checkUpdate`/`toUpdate` for the
|
|
78
|
+
driver's updates by dotted path. No I/O and no dependency. An `_id` beside the id field of a
|
|
79
|
+
record is not written (`toDocument` of a body checked with `unknown: 'ignore'` cannot
|
|
80
|
+
choose the `_id`), `fromDocument(schema, null)` is a `type` issue rather than a throw, a
|
|
81
|
+
value of a class at the root is `ERR_INVALID_TARGET`, reading a document and `ids:
|
|
82
|
+
'string'` need no driver, and `binary` is coerced from text of the base64 shape only. The
|
|
83
|
+
walks of a document stop at `maxDepth` (128, an option of `toDocument` and `toUpdate`) as
|
|
84
|
+
the check does, instead of recursing until the stack ends; `checkUpdate` reports a path with
|
|
85
|
+
an empty segment, into a part a field cannot have or to the `_id` of the document whatever
|
|
86
|
+
the policy for unknown keys says, a path through more records than `maxDepth` as a `depth`
|
|
87
|
+
issue, and names what an operator takes in its issues (`array` for a `$push` on a field
|
|
88
|
+
that is no list, `number` for an `$inc` on a string); `register({ bson })` installs the
|
|
89
|
+
converters of the BSON types the module can build only, `decimal128` is coerced from a
|
|
90
|
+
decimal written as one or a finite number (`fromString` of the driver reads `NaN`, `inf`
|
|
91
|
+
and an exponent), and an element of a list of ids (`partners.0`) is an id in `checkUpdate`
|
|
92
|
+
and `toUpdate`. The subpath is tested against the real `bson` (a devDependency) as well as
|
|
93
|
+
the fakes.
|
|
94
|
+
- **`ids: 'objectId'`** for the mongodb target of `toJSONSchema`: the validator of the
|
|
95
|
+
documents `toDocument` writes.
|
|
96
|
+
- `pnpm size` measures a subpath on top of another it requires (`./mongodb` on `./coerce`).
|
|
97
|
+
|
|
98
|
+
### Changed
|
|
99
|
+
|
|
100
|
+
- **The core gate is 19 KB** (was 17.75 KB): coercion costs the core about 360 bytes; the core
|
|
101
|
+
measures 18.6 KB. The formats gate is 5 KB (was 2 KB; the scanners of the review took the
|
|
102
|
+
subpath to 4.0 KB), the compile gate 5 KB (was 4.25) and the model gate 13 KB (was 12): a
|
|
103
|
+
gate is raised to the next whole KB when a fix needs it, and never sits a few bytes over a
|
|
104
|
+
subpath. New gates: 2.5 KB for `./derive`, 2 KB for `./coerce`, 4 KB for `./mongodb` (3.5 before the review: the depth limit and the markers of the paths took the subpath over it).
|
|
105
|
+
- **`coerce` is a reserved key** of a field definition and of the kind metadata. A field
|
|
106
|
+
`coerce` that is not a boolean is `ERR_INVALID_DEFINITION` (was an `unknown-option` warning),
|
|
107
|
+
a kind metadata `coerce` that is not a boolean is `ERR_INVALID_OPTIONS` (was an ordinary
|
|
108
|
+
custom key), and a kind metadata `coerce: true` makes every `parse` of the schema need
|
|
109
|
+
`register()` of `./coerce`.
|
|
110
|
+
- **An option of a call that is not what it must be carries `code: 'ERR_INVALID_OPTION'`**
|
|
111
|
+
(a new `RuntimeErrorCode`): the `TypeError` of `maxErrors`, `references`, `root`, the
|
|
112
|
+
`coerce` of a parse, and of the options of `./stream`, `./derive` and `./mongodb` had no
|
|
113
|
+
code. The options of `./derive` are the call's (`keys` that is no list, options that are no
|
|
114
|
+
object are `ERR_INVALID_OPTION`, a `TypeError`; they were `ERR_INVALID_OPTIONS`, a
|
|
115
|
+
`SchemaDefinitionError`); its `metadata` stays a definition (`ERR_INVALID_OPTIONS`), and
|
|
116
|
+
`keyof` with a `metadata` is `ERR_INVALID_OPTIONS` (a schema of an enum has no kind; it was
|
|
117
|
+
ignored).
|
|
118
|
+
- The rule of the id field of a stored kind (`orderId`, `id` for an anonymous schema) is
|
|
119
|
+
`idFieldOf` of `kinds.js`, read by `./derive`, `./mongodb` and `toJSONSchema`; the alias
|
|
120
|
+
chain of a custom type ends in `baseTypeOf` of `types.js`, read by the generators, `sample`
|
|
121
|
+
and `checkUpdate`; the shapes of the walks of `./mongodb` are named once (`SHAPES`) and held
|
|
122
|
+
to the core's by a test.
|
|
123
|
+
- **`infer` writes the more specific formats**: a column of http(s) addresses is `url` (was
|
|
124
|
+
`uri`), local date-times are `iso-date-time`, ULIDs `ulid`, durations `duration`.
|
|
125
|
+
- **A format of the program under the name of a built-in takes its place** instead of throwing
|
|
126
|
+
`ERR_FORMAT_REGISTERED`, so a format a program registered as `ulid` before 3.3 keeps working.
|
|
127
|
+
- `merge` and `derive` share the code that turns a schema back into a definition
|
|
128
|
+
(`model/data.js`).
|
|
129
|
+
|
|
130
|
+
## [3.2.0] - 2026-10-12
|
|
131
|
+
|
|
132
|
+
3.2 takes a schema to the records around it. The new `@alexify/metaschema/stream` subpath runs
|
|
133
|
+
a schema over a sequence of records, lazily and in order, as generators and as a
|
|
134
|
+
`TransformStream`; `infer` in the model subpath reads a definition out of the values that
|
|
135
|
+
exist, the reverse of `sample`; and the two performance candidates the review of 3.0 left were
|
|
136
|
+
measured and done: independent async validators are in flight together, and the passes of
|
|
137
|
+
`parse` allocate nothing per container they visit. The review of the release before its tag
|
|
138
|
+
added the `format` rule of strings with the `@alexify/metaschema/formats` subpath, fixed a value
|
|
139
|
+
parsed from JSON that could throw out of `check`, made the ReDoS note true, and closed two
|
|
140
|
+
unhandled rejections. Nothing breaks; the changes in behaviour (the order of the issues of an
|
|
141
|
+
async check with a sync validator after an unrelated promise, a pattern no longer run past
|
|
142
|
+
`length.max`, the message of `unexpected` capped at ten keys) are listed under Changed.
|
|
143
|
+
|
|
144
|
+
### Added
|
|
145
|
+
|
|
146
|
+
- **The `format` rule of strings and the `@alexify/metaschema/formats` subpath.**
|
|
147
|
+
`{ type: 'string', format: 'email' }` is a rule beside `length` and `pattern`: the core knows
|
|
148
|
+
the rule and keeps an empty table (`FORMATS`), and `register()` of the subpath fills it with
|
|
149
|
+
`uuid`, `email`, `date-time`, `date`, `time`, `ipv4`, `ipv6`, `uri` and `hostname` (the
|
|
150
|
+
expressions of ajv-formats' fast mode, linear and anchored, with the date and time ranges
|
|
151
|
+
checked and the leap second as RFC 3339 has it) and with the program's own
|
|
152
|
+
(`register({ phone: { test, examples, infer } })`), once per name, process-wide; a name the
|
|
153
|
+
table lacks is `ERR_INVALID_RULE` with the hint when the schema is built, an entry that is
|
|
154
|
+
not a format `ERR_INVALID_FORMAT`, a name registered again with another test
|
|
155
|
+
`ERR_FORMAT_REGISTERED`. A failed test is the new `format` issue (`params.format`, rendered
|
|
156
|
+
by both locales); the rule runs after the pattern, under the bound of `length.max`, and the
|
|
157
|
+
JIT reaches the test through its scope. `toJSONSchema` writes `format` (the built-in names
|
|
158
|
+
are JSON Schema's; the strict profile drops it, a `$jsonSchema` has none) and
|
|
159
|
+
`fromJSONSchema` reads a registered one back; `sample` draws one of the format's examples;
|
|
160
|
+
`infer` writes the first registered format every string of a place passes (`formats: false`
|
|
161
|
+
turns it off; `hostname`, which every word passes, is never inferred); `merge` refuses two
|
|
162
|
+
formats and `diff` classifies one as a pattern. A rule, not a type: a type named `email`
|
|
163
|
+
would make `{ email: 'string', name: 'string' }` read as a shorthand. The subpath is 1.3 KB
|
|
164
|
+
min+gzip on top of the core, gated at 2 KB; the typings add `FormatDefinition`, the issue
|
|
165
|
+
code and the two error codes.
|
|
166
|
+
- **`compiled(target)` in the `@alexify/metaschema/compile` subpath**: whether a schema (every
|
|
167
|
+
entity of a model) runs generated code now, in place of the internal symbol the guide pointed
|
|
168
|
+
at.
|
|
169
|
+
- **`result.toJSON()`**: `JSON.stringify(result)` writes `{ valid, issues }` (the verdict was a
|
|
170
|
+
getter and was left out); `util.inspect(model)` prints the snapshot, as a schema prints its
|
|
171
|
+
definition.
|
|
172
|
+
- **`sideEffects: false` in package.json**: nothing registers on import, so a bundler may drop
|
|
173
|
+
a subpath a program imports and never calls.
|
|
174
|
+
- **`tests/unit/graph.test.js`**: the module graph of `src/` has no cycles (CLAUDE.md drew it
|
|
175
|
+
by hand and said nothing checked it).
|
|
176
|
+
- **`infer(samples, options)` in the `@alexify/metaschema/model` subpath, the reverse of
|
|
177
|
+
`sample`.** A definition (or a `Schema`, with `as: 'schema'`) that accepts every sample
|
|
178
|
+
given, to bootstrap a model from the documents that exist: one pass summarizes the kinds of
|
|
179
|
+
every place, the records of a place fuse into one struct with optional keys (absent or
|
|
180
|
+
`undefined`) and nullable keys (`null` beside a type), arrays fuse their elements, values of
|
|
181
|
+
several kinds are a `union` with the record last, whole numbers are `integer`, a string of
|
|
182
|
+
few recurring values an `enum`, records whose keys are not names (or many sparse keys of one
|
|
183
|
+
kind) a dictionary `{ object: { string: T } }`, `Set`, `Map`, `Date` and bigint their types,
|
|
184
|
+
and what no type describes `any`; no bounds, patterns, references or tuples. Every key of the
|
|
185
|
+
data is a key of the definition (`__proto__` through `define`, a struct wrapped as
|
|
186
|
+
`{ schema }` where its first key would read otherwise, the root under its `kind`). The
|
|
187
|
+
samples are input: a sample nested deeper than `maxDepth` (128) is `ERR_INFER_DEPTH` with its
|
|
188
|
+
index and place, and the definition is checked against every sample before it is returned
|
|
189
|
+
(`ERR_INFER_MISMATCH`, with `error.index`, names the id field a stored kind adds over a field
|
|
190
|
+
of that name, or a bug). `register()` installs `Schema.infer`; the typings add
|
|
191
|
+
`InferOptions` (`as`, `name`, `kind`, `enum`, `integer`, `map`, `maxDepth`) and the two codes.
|
|
192
|
+
- **The `@alexify/metaschema/stream` subpath: a schema over a sequence of records.**
|
|
193
|
+
`checkEach(schema, records, options)` and `parseEach` run `check` or `parse` on every record
|
|
194
|
+
of an iterable, lazily, and yield `{ index, record, result }` in the order of the records;
|
|
195
|
+
`checkEachAsync` and `parseEachAsync` do the same over a sync or async iterable with the
|
|
196
|
+
async methods, keeping `options.concurrency` records in flight (one by default), still in
|
|
197
|
+
order, and observing the promises in flight when the iteration ends early; `maxInvalid` ends
|
|
198
|
+
an iteration after that many invalid records. `transform(schema, options)` is a
|
|
199
|
+
`TransformStream` (a global since Node.js 18, and in browsers) that passes every valid record
|
|
200
|
+
on as its parsed value (or as it is with `mode: 'check'`), hands an invalid one to
|
|
201
|
+
`onInvalid(record, result, index)`, or ends the stream with a `TypeError` of the new runtime
|
|
202
|
+
code `ERR_INVALID_RECORD` (with `index`, `record` and `result` on it). `register()` installs
|
|
203
|
+
the five as methods of `Schema`. The subpath is 1.0 KB min+gzip on top of the core, gated at
|
|
204
|
+
1.5 KB; the typings add `EachOptions`, `ParseEachOptions`, `EachAsyncOptions`,
|
|
205
|
+
`TransformOptions` and `RecordEntry<T, R>` (`T` the type of the records of the source:
|
|
206
|
+
`checkEach<T>(schema, records: Iterable<T>)` and its kin).
|
|
207
|
+
- **Bench scenarios for the async path and for `strip`** (`pnpm bench`): `checkAsync` with
|
|
208
|
+
sync, resolved and event-loop-bound validators, `parseAsync` with an async decoder, and
|
|
209
|
+
`parse` under `unknown: 'strip'` over a nested value and a list of 100 records, each on both
|
|
210
|
+
backends, through a `benchAsync` twin of the harness (one `await` per call).
|
|
211
|
+
|
|
212
|
+
### Changed
|
|
213
|
+
|
|
214
|
+
- **Independent async validators are in flight together.** `checkAsync` and `parseAsync` set a
|
|
215
|
+
validator aside uncalled only when a promise is pending under its path (the `validate` of a
|
|
216
|
+
struct whose field is still being checked, the schema's own); every other validator runs
|
|
217
|
+
where `check` runs it, during the walk, and the promises are awaited together after it, so
|
|
218
|
+
the latency of a check is the longest of the waits rather than their sum (`pnpm bench`:
|
|
219
|
+
four independent validators awaiting `setImmediate` went from 18 K to 66 K checks a second,
|
|
220
|
+
32 records with one each from 2.2 K to 45 K, four awaiting `setTimeout(1)` from 190 to
|
|
221
|
+
845; the sync validators and the resolved promises are unchanged). What
|
|
222
|
+
changes besides the latency: a synchronous validator met after an unrelated promise runs
|
|
223
|
+
during the walk, so the issues of the walk come first, in walk order, and the promises after
|
|
224
|
+
them, in field order; under a low `maxErrors`, and in a branch of a plain union that fails, a
|
|
225
|
+
validator may be called whose result is dropped, as in `check`. The issues recorded are the
|
|
226
|
+
same, on both backends.
|
|
227
|
+
- **A `pattern` is never run over a string longer than `length.max`.** The ReDoS note promised
|
|
228
|
+
that the bound keeps a backtracking expression fast, but every rule of a field ran: a string
|
|
229
|
+
past the bound got its length issue and then the pattern (2.5 s for `^(a+)+$` on 27
|
|
230
|
+
characters). Both backends skip the pattern on such a string (twice the bound in UTF-16
|
|
231
|
+
units with `unicode: true`), which is reported for its length alone: one issue where there
|
|
232
|
+
were two. A field without `length.max` is unchanged. A `format` is run under the same bound.
|
|
233
|
+
- **The message of `unexpected` lists the first ten keys** and says how many more; `params.keys`
|
|
234
|
+
keeps them all. The unexpected keys are one issue, so `maxErrors` never bounded the message,
|
|
235
|
+
and a value with a million keys the schema does not have rendered a million of them.
|
|
236
|
+
- **The gate of the `./model` subpath is 12 KB** (was 10): `infer` costs 2.3 KB min+gzip and
|
|
237
|
+
the subpath measures 11.7 KB (12.0 KB with the formats); the subpath is tooling, not the
|
|
238
|
+
validation path, as for the move from 8.5 to 10 KB in 3.1. **The core gate is 17.75 KB**
|
|
239
|
+
(was 17.5): the `format` rule, its issue and the fixes of the review measure 17.7 KB
|
|
240
|
+
together, and a gate the next fix cannot fit under is no gate, as in 3.1.
|
|
241
|
+
|
|
242
|
+
### Performance
|
|
243
|
+
|
|
244
|
+
- **The passes of `parse` and `serialize` allocate nothing per container they visit.** The
|
|
245
|
+
walkers of `codec.js` kept a state object per struct, list, dictionary or tuple whose bits a
|
|
246
|
+
pass wanted (`{ context, key, value, clone, put, out, pending }`), even where nothing
|
|
247
|
+
changed; the output under construction and the parts still decoding are locals of the walker
|
|
248
|
+
now, written through two small helpers. `pnpm bench`: `parse` of 100 records under
|
|
249
|
+
`unknown: 'strip'` from 61 K to 71 K a second on the closures and from 81 K to 100 K on the
|
|
250
|
+
JIT, a nested struct under `strip` from 1.9 M to 2.2 M on the JIT, defaults and a decoder
|
|
251
|
+
about 5% faster on both; the rest within the run-to-run band.
|
|
252
|
+
|
|
253
|
+
### Fixed
|
|
254
|
+
|
|
255
|
+
- **A value parsed from JSON could throw out of `check`.** A built-in was recognised by the
|
|
256
|
+
name of its constructor alone, and `{ "constructor": { "name": "Map" } }` as the value of a
|
|
257
|
+
`map`, `set` or `date` field was iterated, or asked for `getTime`, and threw a `TypeError`
|
|
258
|
+
out of `check`, `parse`, a union branch and both backends, where the contract is that
|
|
259
|
+
nothing in the value makes the check throw. The name is still tested first, then the shape
|
|
260
|
+
(an iterator for a `Map` or a `Set`, `getTime` for a `Date`), which JSON cannot fake; such a
|
|
261
|
+
value is a type issue. Since 2.0.
|
|
262
|
+
- **A walk that threw out of `checkAsync` or `parseAsync` left its promises unhandled.** A
|
|
263
|
+
getter of the value that throws (or, before the fix above, a crafted value) ended the call
|
|
264
|
+
with that error while the promise a validator had returned before it rejected with no
|
|
265
|
+
handler. The walk of an async check releases what it queued on the way out.
|
|
266
|
+
- **A queued record of the async stream pair could reject unhandled.** With a window of
|
|
267
|
+
records in flight, a later record whose parse threw while an earlier one still waited for
|
|
268
|
+
its validator fired `unhandledRejection` before its turn, then rejected the iteration all
|
|
269
|
+
the same; the promise is observed when it is queued.
|
|
270
|
+
- **Keys of untrusted input are shortened in every message.** The place of an `infer` error
|
|
271
|
+
(a key of a sample), of a `fromJSON` error (a key of a snapshot) and of a `fromJSONSchema`
|
|
272
|
+
error (a property name in the pointer) went into the message whole; they are truncated to
|
|
273
|
+
100 characters as a key of a value under check is. A snapshot index named `__proto__` is
|
|
274
|
+
written as a key instead of vanishing, and the `validate` method of a schema reports a
|
|
275
|
+
thrown `null` as an exception instead of throwing on it.
|
|
276
|
+
- **A failed branch of a plain union observed none of the promises it dropped.** A validator
|
|
277
|
+
of the branch that returned a promise was set aside, and when the branch failed on a later
|
|
278
|
+
field the entry was cut from the list without a handler, so its rejection was an
|
|
279
|
+
`unhandledRejection` while the value went on to match the next branch. Both backends now
|
|
280
|
+
release such entries (`release` in `issues.js`, reached by the generated code through the
|
|
281
|
+
scope), as the trial of `parse` and a `settle` stopped by `maxErrors` already did.
|
|
282
|
+
- **An object with no key that starts with a letter is a struct.** `Schema.from({})`,
|
|
283
|
+
`{ _id: 'string' }` and a nested `{ a: {} }` threw a bare `TypeError` from the preprocessor
|
|
284
|
+
(the first key is the first one that starts with a letter, and there was none); they are
|
|
285
|
+
structs of those keys, or of none.
|
|
286
|
+
- **A nested struct may have a field named `required`.** `{ a: { required: 'boolean' } }`
|
|
287
|
+
gave the field `a` the `required` of its nested definition (`'boolean'`), which showed in
|
|
288
|
+
`toJSON()` and in the snapshot; the key and the parsers decide, as everywhere else.
|
|
289
|
+
- **`fromJSONSchema` wraps a nested struct whose first letter-led key reads as a type.** A
|
|
290
|
+
nested object with the properties `_id` and `string` came back bare and was read as a
|
|
291
|
+
`string` field; one with no properties came back as `{}` and could not be built. The rule
|
|
292
|
+
the generator asks (`readsAsStruct` in `types.js`) follows the preprocessor's `firstKey`
|
|
293
|
+
now, and the model subpath shares it.
|
|
294
|
+
|
|
295
|
+
- **`CheckContext` declares `renamed`.** The context has carried the slot (whether the check
|
|
296
|
+
read a field from one of its aliases) since 3.1, and the migration guide says the type declares
|
|
297
|
+
every slot; `tests/types/index.test-d.ts` pins it now.
|
|
298
|
+
|
|
299
|
+
### Tooling
|
|
300
|
+
|
|
301
|
+
- **A cross-library benchmark, charted.** `pnpm bench:compare` replaces `pnpm bench
|
|
302
|
+
--compare-libs` (`bench/libs.js` is gone): metaschema on both backends beside Metarhia's
|
|
303
|
+
metaschema 2.2.2, zod, Valibot, ArkType, Effect Schema, TypeBox (1.x, `Compile` and `Value`),
|
|
304
|
+
Ajv, Yup, Joi and Superstruct, one adapter per library, each pair in a fresh process that
|
|
305
|
+
checks the verdicts before it times anything, median of five one-second samples. The
|
|
306
|
+
scenarios are the moltar object in its four modes, every issue of an invalid value, building
|
|
307
|
+
a schema and a cold start; `pnpm size:compare` bundles the same schema per library and checks
|
|
308
|
+
the bundle; `bench/releases.js` measures every release since Metarhia's 2.2.2 with one
|
|
309
|
+
harness. `pnpm bench:report` turns the results into SVG charts for the README and the tables
|
|
310
|
+
of the README and `docs/guide/benchmarks.md`; the docs render the same models as interactive
|
|
311
|
+
charts. The libraries are devDependencies (`@sinclair/typebox` 0.34 gave way to `typebox`
|
|
312
|
+
1.x).
|
|
313
|
+
- **A feature matrix of twenty alternatives.** `docs/guide/comparison.md` and the README compare
|
|
314
|
+
metaschema with TypeScript-first validators, JSON Schema tools, IDLs and Mongoose in one
|
|
315
|
+
table, every cell checked against the source of the published package; `pnpm docs:comparison`
|
|
316
|
+
renders it from `docs/comparison.json`.
|
|
317
|
+
- **Docs.** New pages: Benchmarks, Compared with alternatives and Architecture (mermaid diagrams
|
|
318
|
+
of the pipeline); the home page and the Why page were rewritten around "fast, zero-dependency";
|
|
319
|
+
the package description says so too.
|
|
320
|
+
|
|
10
321
|
## [3.1.0] - 2026-10-11
|
|
11
322
|
|
|
12
323
|
3.1 makes the model data. `model.toJSON()` writes a snapshot of a model, the contract other
|
|
@@ -1083,7 +1394,9 @@ published.
|
|
|
1083
1394
|
|
|
1084
1395
|
### [metaschema 0.x][upstream-0.x] - First generation of metaschema
|
|
1085
1396
|
|
|
1086
|
-
[unreleased]: https://github.com/Alexis-Technologies/metaschema/compare/v3.
|
|
1397
|
+
[unreleased]: https://github.com/Alexis-Technologies/metaschema/compare/v3.3.0...HEAD
|
|
1398
|
+
[3.3.0]: https://github.com/Alexis-Technologies/metaschema/compare/v3.2.0...v3.3.0
|
|
1399
|
+
[3.2.0]: https://github.com/Alexis-Technologies/metaschema/compare/v3.1.0...v3.2.0
|
|
1087
1400
|
[3.1.0]: https://github.com/Alexis-Technologies/metaschema/compare/v3.0.0...v3.1.0
|
|
1088
1401
|
[3.0.0]: https://github.com/Alexis-Technologies/metaschema/compare/v2.0.0...v3.0.0
|
|
1089
1402
|
[2.0.0]: https://github.com/Alexis-Technologies/metaschema/compare/v1.0.0...v2.0.0
|