@alexify/metaschema 3.4.0 → 4.0.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 +227 -1
- package/README.md +29 -11
- package/SECURITY.md +5 -4
- package/index.d.ts +912 -480
- package/package.json +8 -6
- package/src/checks.js +72 -107
- package/src/codec.js +67 -58
- package/src/coerce/index.d.ts +31 -21
- package/src/coerce/index.js +64 -47
- package/src/compile/code.js +2 -2
- package/src/compile/emit.js +20 -31
- package/src/compile/index.d.ts +41 -25
- package/src/compile/index.js +45 -32
- package/src/context.js +10 -10
- package/src/definition/index.d.ts +10 -7
- package/src/definition/index.js +2 -1
- package/src/derive/index.d.ts +25 -17
- package/src/derive/index.js +21 -15
- package/src/errors.js +84 -59
- package/src/formats/index.d.ts +27 -21
- package/src/formats/index.js +15 -13
- package/src/generators/{fromjsonschema.js → from-json-schema.js} +170 -127
- package/src/generators/index.d.ts +23 -15
- package/src/generators/index.js +2 -2
- package/src/generators/{jsonschema.js → json-schema.js} +37 -43
- package/src/generators/typescript.js +9 -6
- package/src/index.js +2 -1
- package/src/issues.js +41 -42
- package/src/kinds.js +31 -10
- package/src/lint.js +64 -19
- package/src/locales/en.js +7 -7
- package/src/locales/uk.js +6 -6
- package/src/metadata.js +2 -2
- package/src/model/data.js +34 -20
- package/src/model/diff.js +29 -24
- package/src/model/index.d.ts +51 -35
- package/src/model/infer.js +70 -61
- package/src/model/merge.js +29 -18
- package/src/model/pattern.js +105 -102
- package/src/model/restore.js +33 -21
- package/src/model/sample.js +90 -100
- package/src/model.js +4 -2
- package/src/mongodb/bson.js +12 -12
- package/src/mongodb/document.js +7 -6
- package/src/mongodb/index.d.ts +54 -31
- package/src/mongodb/update.js +12 -9
- package/src/preprocessor.js +25 -15
- package/src/prototypes/abstract.js +8 -8
- package/src/prototypes/collections.js +7 -7
- package/src/prototypes/flags.js +1 -1
- package/src/prototypes/reference.js +3 -4
- package/src/prototypes/scalars.js +1 -1
- package/src/prototypes/schema.js +5 -6
- package/src/prototypes/tuple.js +11 -10
- package/src/prototypes/union.js +5 -4
- package/src/rules.js +23 -20
- package/src/runtime/browser.js +6 -1
- package/src/runtime/node.js +19 -2
- package/src/schema.js +19 -14
- package/src/snapshot.js +14 -12
- package/src/stream/index.d.ts +33 -21
- package/src/stream/index.js +37 -20
- package/src/struct.js +6 -6
- package/src/types.js +35 -26
- package/src/util.js +70 -64
- package/src/validation.js +10 -13
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,230 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [4.0.0] - 2026-11-27
|
|
11
|
+
|
|
12
|
+
4.0 brings the errors of the package to the rules of the Alexis libraries (alexiskills 1.1).
|
|
13
|
+
Every error code carries the `ALX_` prefix, and a wrong call throws a class of the package,
|
|
14
|
+
`SchemaUsageError`, where it threw a plain `TypeError` (or a `SchemaDefinitionError`, for a
|
|
15
|
+
wrong option of some calls). A program that matches on `error.code`, or on the `name` of the
|
|
16
|
+
error of a call, changes; one that checks `instanceof TypeError` does not. A hook no longer
|
|
17
|
+
fails the call it watches, and three defects of the async paths of 3.x are fixed. The schema
|
|
18
|
+
language, `check`, `parse`, the results and their issue codes are what they were.
|
|
19
|
+
|
|
20
|
+
### Upgrading from 3.x
|
|
21
|
+
|
|
22
|
+
The same guide with before-and-after examples is
|
|
23
|
+
[Migrating from 3.x](https://metaschema.vercel.app/guide/migrating-from-3).
|
|
24
|
+
|
|
25
|
+
- **Every code has the `ALX_` prefix**, and what follows it is the name it had:
|
|
26
|
+
`ERR_INVALID_RULE` is `ALX_ERR_INVALID_RULE`, `ERR_NOT_REGISTERED` is
|
|
27
|
+
`ALX_ERR_NOT_REGISTERED`, and so for the 31 codes of `SchemaDefinitionError` and the 5 of a
|
|
28
|
+
wrong call. A search for `'ERR_` finds every comparison to change; `DefinitionErrorCode` and
|
|
29
|
+
`RuntimeErrorCode` hold the new names.
|
|
30
|
+
- **A wrong call throws `SchemaUsageError`** (`ALX_ERR_ASYNC_VALIDATOR`,
|
|
31
|
+
`ALX_ERR_INVALID_TARGET`, `ALX_ERR_INVALID_OPTION`, `ALX_ERR_INVALID_RECORD`,
|
|
32
|
+
`ALX_ERR_NOT_REGISTERED`): `error.name` is `'SchemaUsageError'` where it was `'TypeError'`,
|
|
33
|
+
and `instanceof TypeError` holds as before.
|
|
34
|
+
- **`saveTypes` in a browser rejects with `ALX_ERR_UNSUPPORTED_RUNTIME`**, a
|
|
35
|
+
`SchemaUsageError`, where it rejected with a bare `Error`.
|
|
36
|
+
- **Every option of a call is `ALX_ERR_INVALID_OPTION` of `SchemaUsageError`.** The options of
|
|
37
|
+
`compile` and `register` of the compile subpath, `toJSONSchema`, `fromJSONSchema`, `fromJSON`,
|
|
38
|
+
`merge`, `sample`, `infer`, the `Model` constructor and `register` of the coerce subpath threw
|
|
39
|
+
`SchemaDefinitionError` with `ERR_INVALID_OPTIONS` (`ERR_INVALID_COERCION` for coerce);
|
|
40
|
+
`ALX_ERR_INVALID_OPTIONS` is the code of the metadata of a definition only.
|
|
41
|
+
- **The error classes take `(message, options = {})`**: a program that builds one writes
|
|
42
|
+
`new SchemaDefinitionError(message, { code })` where it wrote `(code, message)`. `error.cause`
|
|
43
|
+
is the standard one, not an own enumerable key (`JSON.stringify(error)` leaves it out).
|
|
44
|
+
|
|
45
|
+
### Changed (breaking)
|
|
46
|
+
|
|
47
|
+
- **Every error code is `ALX_ERR_*`**, as alexiskills 1.1 asks of the Alexis libraries (Fastify's
|
|
48
|
+
are `FST_ERR_*`): the codes of other packages and of Node pass through a program, and the
|
|
49
|
+
prefix tells the package's own apart. The names after it did not change.
|
|
50
|
+
- **`SchemaUsageError`, a `TypeError`, is the error of a wrong call**, beside
|
|
51
|
+
`SchemaDefinitionError` for a broken definition. The core entry and
|
|
52
|
+
`@alexify/metaschema/definition` export it, `index.d.ts` declares it with `code:
|
|
53
|
+
RuntimeErrorCode` and the fields the errors carried in 3.x (`index`, `record` and `result` on
|
|
54
|
+
`ALX_ERR_INVALID_RECORD`, `method` on the `ALX_ERR_NOT_REGISTERED` of the definition entry).
|
|
55
|
+
- **`saveTypes` of the browser build rejects with a code**, `ALX_ERR_UNSUPPORTED_RUNTIME`, new in
|
|
56
|
+
`RuntimeErrorCode`.
|
|
57
|
+
- **An option of a call is a `SchemaUsageError` with `ALX_ERR_INVALID_OPTION` everywhere**, as
|
|
58
|
+
alexiskills asks of a wrong call ("one class per failure the caller handles differently"):
|
|
59
|
+
the options of the compile subpath, of the generators, of `fromJSON`, `merge`, `sample` and
|
|
60
|
+
`infer`, of `Model` and of `register` of the coerce subpath were `SchemaDefinitionError` with
|
|
61
|
+
`ALX_ERR_INVALID_OPTIONS` (`ALX_ERR_INVALID_COERCION`). The metadata of a definition keeps
|
|
62
|
+
`ALX_ERR_INVALID_OPTIONS`.
|
|
63
|
+
- **The error classes take `(message, options = {})`, as `Error` does** (alexiskills 1.2):
|
|
64
|
+
`new SchemaDefinitionError(message, { code, cause, schema, field, index, seed })` and
|
|
65
|
+
`new SchemaUsageError(message, { code, cause, index, record, result, method })`, where
|
|
66
|
+
`SchemaDefinitionError` took `(code, reason)` in 3.x. `options` goes to `Error` whole, so `cause` is the standard one and set
|
|
67
|
+
only when given (the errors that wrapped another assigned it as an own enumerable key, and an
|
|
68
|
+
error of a snapshot that did not read lost the engine's error, which is its cause now). Every
|
|
69
|
+
field is set by the constructor, none afterwards. Without a code a `SchemaDefinitionError` is
|
|
70
|
+
`ALX_ERR_INVALID_DEFINITION` and a `SchemaUsageError` `ALX_ERR_INVALID_TARGET`; `code` is
|
|
71
|
+
`readonly` in the typings, and `DefinitionErrorOptions` and `UsageErrorOptions` type the
|
|
72
|
+
options.
|
|
73
|
+
|
|
74
|
+
### Changed
|
|
75
|
+
|
|
76
|
+
- **A hook never fails the call it watches.** `onFallback` of the compile subpath, `onError` of
|
|
77
|
+
the coerce subpath and `onUnsupported` of `fromJSONSchema` are observers (alexiskills,
|
|
78
|
+
library-errors): what one throws, or a promise of it that rejects, is dropped, where a
|
|
79
|
+
throwing `onFallback` made `new Schema` throw under `register()`. `onInvalid` of a stream
|
|
80
|
+
`transform` stays a step of the stream, and its throw ends it.
|
|
81
|
+
- **`saveTypes` replaces the file whole.** It writes a file of its own beside the target and
|
|
82
|
+
renames it into place, so a reader (`tsc --watch`, an editor) never sees half a declaration
|
|
83
|
+
file and a write that fails leaves the old file as it was; it wrote the target in place.
|
|
84
|
+
|
|
85
|
+
### Fixed
|
|
86
|
+
|
|
87
|
+
- **An async validator that rejects while settle awaits an earlier one no longer ends the
|
|
88
|
+
process.** `checkAsync` and `parseAsync` keep the promises of the validators they meet and
|
|
89
|
+
await them in field order after the walk; a promise that rejected while an earlier one was
|
|
90
|
+
still pending had no handler yet, so Node reported an unhandled rejection and exited (since
|
|
91
|
+
3.2, whose settle overlaps the waits). Every promise is now observed as soon as it is met, and
|
|
92
|
+
its rejection is the `exception` issue of its field, as it always was once awaited.
|
|
93
|
+
- **The `validate` of a merged field no longer leaves a rejecting promise behind.** When the
|
|
94
|
+
first of the two validators `merge` composes returned a promise and the second threw, the
|
|
95
|
+
first's promise rejected unhandled (since 3.1); it is observed before the second runs.
|
|
96
|
+
- **`checkEachAsync` and `parseEachAsync` read a record with a `then` of its own as the record.**
|
|
97
|
+
Over a sync source, `for await` adopted every thenable, so a record with a field named `then`
|
|
98
|
+
holding a function came out as what that function resolved to (since 3.2). The async pair now
|
|
99
|
+
awaits an element of a sync source only when it is a `Promise`, as documented, and a sync
|
|
100
|
+
generator it stops early is still closed.
|
|
101
|
+
|
|
102
|
+
### Documentation
|
|
103
|
+
|
|
104
|
+
- **Each error class has its table.** The API reference has a section for `SchemaUsageError`
|
|
105
|
+
beside the one of `SchemaDefinitionError`, with the fields and the six codes, and a test holds
|
|
106
|
+
the source, the two unions of `index.d.ts` and the two tables to one set of codes, throws every
|
|
107
|
+
code of a wrong call once to see its class, and fails on a code without the prefix.
|
|
108
|
+
- **Migrating from 3.x**, a page of the guide, and "From 3.x" in the README.
|
|
109
|
+
- **The public API is documented as JSDoc in the `.d.ts`**, which an editor shows on hover:
|
|
110
|
+
222 `//` comments over declarations became `/** */` blocks, and `Schema`, `Model`,
|
|
111
|
+
`ValidationResult`, `SchemaDefinitionError` and the options types got the ones they lacked.
|
|
112
|
+
- **"At a trust boundary"** in the guide to parse: the four defaults a boundary sets otherwise
|
|
113
|
+
(`maxErrors`, the async validators a walk starts, a pattern without `length.max`, the text of
|
|
114
|
+
an `exception` issue).
|
|
115
|
+
|
|
116
|
+
### Tooling
|
|
117
|
+
|
|
118
|
+
- **The agent skills are alexiskills.** `@alexify/metaskills` 1.2.0, a devDependency, links its
|
|
119
|
+
37 skills into `.claude/skills` from the `prepare` script (`alexiskills claude`) on every
|
|
120
|
+
`pnpm install`, and `.gitignore` leaves the link out. The seven skills of metarhia/metaskills
|
|
121
|
+
1.0.5 the repository kept there are gone; what two of them said of metaschema alone (the steps
|
|
122
|
+
of a release, the code style) is in CLAUDE.md. Nothing of it ships: the `files` of the package
|
|
123
|
+
are what they were.
|
|
124
|
+
- **The lint rules of alexiskills, and `src/` brought to them.**
|
|
125
|
+
- New rules: `func-style`, `no-nested-ternary`, `max-depth` and a strict `eqeqeq` (`null`
|
|
126
|
+
included) everywhere; in `src/` every array iteration method, the unicorn rules and
|
|
127
|
+
`max-lines-per-function`.
|
|
128
|
+
- The code changed for them: 31 loose comparisons with `null`, 16 nested ternaries,
|
|
129
|
+
3 `Object.entries`, 14 `let` without a value, three membership lists made Sets, three sorts
|
|
130
|
+
written as statements, three long functions split.
|
|
131
|
+
- No behaviour changed: the suites pass on both backends and without eval. The core measures
|
|
132
|
+
22298 bytes (21.8 KB, +74), and `check`, `parse` and the moltar rows are at parity or faster.
|
|
133
|
+
- **alexiskills 1.1.**
|
|
134
|
+
- The lint turns `no-void` off and reports unused disable directives as errors.
|
|
135
|
+
- `src/` follows it: 35 call-then-return pairs are `return void fn()`, 17 `String(value)` of
|
|
136
|
+
values that cannot be symbols are template literals (four stay, where a key or a value may
|
|
137
|
+
be one), and the last `Object.values` and array destructuring are gone.
|
|
138
|
+
- The 55 suites are `describe` and `it('should …')` with `node:assert/strict`: 590 tests,
|
|
139
|
+
the same as before, under new titles, and six more for the error codes.
|
|
140
|
+
- No behaviour changed. The core measures 22319 bytes (+21), and the bench is at parity.
|
|
141
|
+
- **CI tests Node 18.12.0**, the lowest version pnpm 10 runs on, where it tested the latest
|
|
142
|
+
18.x; `engines` stays `>=18.0.0`, and the suite passes on 18.12.0. alexiskills 1.1.1 asks for
|
|
143
|
+
exactly that.
|
|
144
|
+
- **alexiskills 1.1.2.** It allows `for...of` and `for...in` in library code, as `src/` was
|
|
145
|
+
written. It also asks a loop that replaced an array method to skip the holes of a caller's
|
|
146
|
+
array. No loop of these changes replaced one, and a list with holes (an `enum`, a tuple, a
|
|
147
|
+
union, `flags`, `aliases`, an index, an array value, the records of a stream, the keys of
|
|
148
|
+
`pick`, the changes of `compatibility`) gives what it gave in 3.4.1 on both backends.
|
|
149
|
+
- **alexiskills 1.2.0.** Every error class of a library takes `(message, options = {})`, and
|
|
150
|
+
metaschema's do (see Changed (breaking)); the skills describe metaschema 4.0.
|
|
151
|
+
- **The review against alexiskills 1.1.2** (no behaviour changed beyond what Fixed and Changed
|
|
152
|
+
say):
|
|
153
|
+
- `src/` keeps the order of a module (constants, functions, classes, exports in that order),
|
|
154
|
+
`concat` for a concatenation, `{ __proto__: null, ... }` for a fixed table, a `Set` for a
|
|
155
|
+
membership list, a `let` of one kind, named steps where an expression wrapped, tables for
|
|
156
|
+
two dispatchers, names with their units, and kebab-case files (`json-schema.js`,
|
|
157
|
+
`from-json-schema.js`). An A/B of the `check` and `parse` rows against the commit before is
|
|
158
|
+
at parity (median −0.8%); the `checkAsync` rows with promises pay the fix of settle (one
|
|
159
|
+
rejection handler per promise: −8% on four resolved promises, −15% on the JIT).
|
|
160
|
+
- The tests bound linearity relative to an input of an eighth of the size, not in
|
|
161
|
+
milliseconds, wait on `setImmediate` rather than timers, read the entries of
|
|
162
|
+
`export-parity` from the `exports` map and hold every subpath to a size row and a gate.
|
|
163
|
+
- `package.json` says `"type": "commonjs"`, leaves `CLAUDE.md` out of the tarball, and has no
|
|
164
|
+
`release` script: a release runs `pnpm publish`.
|
|
165
|
+
- The coerce subpath's gate is 3 KB: the observer guard took it to 2027 bytes, 21 under the
|
|
166
|
+
2 KB gate (2049 at the end of the review); the core measures 22402 bytes (21.9 KB).
|
|
167
|
+
- **The core gate is 23 KB.** The error classes of alexiskills 1.2 write every code as an
|
|
168
|
+
option, which took the core to 22508 bytes (22.0 KB), 20 under the 22 KB gate.
|
|
169
|
+
|
|
170
|
+
## [3.4.1] - 2026-11-24
|
|
171
|
+
|
|
172
|
+
3.4.1 settles what a capitalized key is. Until now the first key of an object was a kind
|
|
173
|
+
whenever it began with a capital letter, whatever it was called and whatever it held, so a
|
|
174
|
+
struct that began with `DATABASE_URL: 'string'` lost that field without a word (a schema of
|
|
175
|
+
environment variables lost its first variable), and `Infer` took every capitalized key for a
|
|
176
|
+
kind and left it out of the type. A kind is now a **kind name holding its metadata**: a capital
|
|
177
|
+
letter, then letters and digits, at least one of them lowercase (`Entity`, `Settings`), holding
|
|
178
|
+
a plain object. Every other capitalized key is a field, for the runtime and for the types alike,
|
|
179
|
+
and the one case the first key still cannot tell apart is a warning.
|
|
180
|
+
|
|
181
|
+
### Fixed
|
|
182
|
+
|
|
183
|
+
- **A capitalized first key that is no kind is a field.** `Schema.from({ DATABASE_URL: 'string',
|
|
184
|
+
PORT: 'number' })` was the kind `dATABASE_URL` with the string spread into `custom`
|
|
185
|
+
(`{ 0: 's', 1: 't', … }`) over a struct of `PORT` alone, with no warning, and a value that
|
|
186
|
+
carried `DATABASE_URL` was rejected for an unexpected key. It is a struct of both fields now,
|
|
187
|
+
and so is every first key in upper case (`PORT: { type: 'number', default: 3000 }`,
|
|
188
|
+
`NODE_ENV: { enum: […] }`), every name with a character that is no letter or digit
|
|
189
|
+
(`Api_key`), and a kind name that holds no metadata: a type name (`Name: 'string'`), a tuple,
|
|
190
|
+
a function, a `Schema`, a built field. The same holds wherever a definition is read: a nested
|
|
191
|
+
struct, an element of a collection or a tuple, a branch of a union, an entity of a `Model` and
|
|
192
|
+
its snapshot.
|
|
193
|
+
- **`Infer` reads a kind key as the runtime does.** `Infer<{ host: 'string', PORT: 'number' }>`
|
|
194
|
+
was `{ host: string }`, `Infer<{ HOST: 'string' }>` was `{}`, and a struct with a kind and
|
|
195
|
+
capitalized fields (`{ Struct: {}, DATABASE_URL: 'string', PORT: 'number' }`) was a union of
|
|
196
|
+
structs, each without one of its keys. A kind key of the types is a kind name holding an
|
|
197
|
+
object now, the keys are taken as one set instead of one by one, and where several keys could
|
|
198
|
+
be the kind a built-in one is it (`{ Struct: {}, Address: { … }, name: 'string' }` infers with
|
|
199
|
+
`Address`). `InferOutput`, `InferEntity`, a projection and the types of `./derive` read the
|
|
200
|
+
same keys, so `pick(env, ['DATABASE_URL'])` compiles.
|
|
201
|
+
- **`extend` of `./derive` takes capitalized fields.** `extend(schema, { REDIS_URL: 'string' })`
|
|
202
|
+
threw "An extension has fields only"; an extension is refused for a kind only.
|
|
203
|
+
- **A capitalized key holding a type name names a tuple element**: `[{ X: 'number' }, { Y:
|
|
204
|
+
'number' }]` is two numbers named `X` and `Y`, as `{ x: 'number' }` always was (it was an
|
|
205
|
+
empty struct of the kind `x`), for `check` and for `Infer`.
|
|
206
|
+
|
|
207
|
+
### Changed
|
|
208
|
+
|
|
209
|
+
- **A custom kind is a kind name.** `{ DTO: {}, … }`, `{ X: {}, … }` and `{ Api_config: {}, … }`
|
|
210
|
+
were the kinds `dTO`, `x` and `api_config`; they are structs with a field of that name now.
|
|
211
|
+
Name the kind with a lowercase letter and nothing but letters and digits (`Dto`,
|
|
212
|
+
`ApiConfig`). The built-in kinds and the custom kinds of the documentation
|
|
213
|
+
(`{ Settings: { theme: 'dark' }, … }`) read as they did.
|
|
214
|
+
- **A kind that would not read back is refused where it is written**: `fromJSON` of a snapshot
|
|
215
|
+
whose entity has such a kind (`dTO`, or the `dATABASE_URL` that 3.4.0 wrote for the struct
|
|
216
|
+
above) is `ERR_INVALID_SNAPSHOT` located at the entity, and `metadata: { kind }` of `./derive`
|
|
217
|
+
and `merge` and the `kind` option of `infer` are `ERR_INVALID_OPTIONS`. Each writes the kind
|
|
218
|
+
as the first key of a definition, where it would have become a field.
|
|
219
|
+
|
|
220
|
+
### Added
|
|
221
|
+
|
|
222
|
+
- **`ambiguous-kind` in `schema.warnings`.** A field with a name like a kind's that holds a
|
|
223
|
+
nested struct or a long form, first in its struct (`{ Address: { street: 'string' }, name:
|
|
224
|
+
'string' }`), is still read as the custom kind `address`: the first key decides, and such
|
|
225
|
+
metadata is what a custom kind looks like. The warning names every custom kind, at any depth,
|
|
226
|
+
whose metadata names a type or reads as a field definition; a kind before the field settles
|
|
227
|
+
it (`{ Struct: {}, Address: { … }, name: 'string' }`). `{ Settings: { theme: 'dark' } }` has
|
|
228
|
+
no warning.
|
|
229
|
+
|
|
230
|
+
The core measures 21.7 KB (22224 / 22233 bytes, under its 22 KB gate), `./definition` 10.5 KB,
|
|
231
|
+
the model subpath 12.8 KB and the derive subpath 2.3 KB; building a schema and checking with it
|
|
232
|
+
are at parity with 3.4.0.
|
|
233
|
+
|
|
10
234
|
## [3.4.0] - 2026-10-16
|
|
11
235
|
|
|
12
236
|
3.4 makes the snapshot a contract a program can build on and the language complete for the
|
|
@@ -1578,7 +1802,9 @@ published.
|
|
|
1578
1802
|
|
|
1579
1803
|
### [metaschema 0.x][upstream-0.x] - First generation of metaschema
|
|
1580
1804
|
|
|
1581
|
-
[unreleased]: https://github.com/Alexis-Technologies/metaschema/compare/
|
|
1805
|
+
[unreleased]: https://github.com/Alexis-Technologies/metaschema/compare/v4.0.0...HEAD
|
|
1806
|
+
[4.0.0]: https://github.com/Alexis-Technologies/metaschema/compare/v3.4.1...v4.0.0
|
|
1807
|
+
[3.4.1]: https://github.com/Alexis-Technologies/metaschema/compare/v3.4.0...v3.4.1
|
|
1582
1808
|
[3.4.0]: https://github.com/Alexis-Technologies/metaschema/compare/v3.3.0...v3.4.0
|
|
1583
1809
|
[3.3.0]: https://github.com/Alexis-Technologies/metaschema/compare/v3.2.0...v3.3.0
|
|
1584
1810
|
[3.2.0]: https://github.com/Alexis-Technologies/metaschema/compare/v3.1.0...v3.2.0
|
package/README.md
CHANGED
|
@@ -110,13 +110,13 @@ event.parse({ name: 'deploy', when: '2026-10-10T12:00:00.000Z' }).value;
|
|
|
110
110
|
schemas (`merge`) and infers a definition from the values that exist (`infer`); `aliases` and
|
|
111
111
|
`deprecated` let a model carry its history, and `fromJSONSchema` of the generators reads a
|
|
112
112
|
JSON Schema document back.
|
|
113
|
-
- **Zero dependencies,
|
|
114
|
-
one package for Node.js and browsers; the generators add 7.
|
|
115
|
-
model tools 12.
|
|
116
|
-
2.2 KB, the converters of coercion
|
|
113
|
+
- **Zero dependencies, 22.0 KB min+gzip.** CommonJS with ESM named imports, no build step,
|
|
114
|
+
one package for Node.js and browsers; the generators add 7.9 KB, the JIT backend 4.4 KB, the
|
|
115
|
+
model tools 12.9 KB, the record tools 1.1 KB, the string formats 3.8 KB, the derive tools
|
|
116
|
+
2.2 KB, the converters of coercion 2.0 KB and the MongoDB tools 3.6 KB (on top of the
|
|
117
117
|
converters, which they require) where they are imported. A program that reads schemas
|
|
118
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.
|
|
119
|
+
`@alexify/metaschema/definition`, the half of the core that builds them: 10.7 KB.
|
|
120
120
|
|
|
121
121
|
## Benchmarks
|
|
122
122
|
|
|
@@ -225,7 +225,7 @@ interactive.
|
|
|
225
225
|
| Effect Schema<br><sub>decodeUnknownResult() · is() · v4.0.3</sub> | 72.9 KB | 24.4 KB | |
|
|
226
226
|
| Zod<br><sub>safeParse() · v4.6.6</sub> | 88.4 KB | 25.7 KB | |
|
|
227
227
|
| TypeBox<br><sub>Value.Check() · v1.3.36</sub> | 146.7 KB | 37.5 KB | |
|
|
228
|
-
| Ajv<br><sub>compile(…)(value), draft 2020-12 · v8.20.0</sub> |
|
|
228
|
+
| Ajv<br><sub>compile(…)(value), draft 2020-12 · v8.20.0</sub> | 131.0 KB | 39.5 KB | |
|
|
229
229
|
| TypeBox<br><sub>Compile(…).Check() · v1.3.36</sub> | 161.5 KB | 40.8 KB | |
|
|
230
230
|
| ArkType<br><sub>type(value) · allows() · v2.2.8</sub> | 151.9 KB | 46.4 KB | |
|
|
231
231
|
| Joi<br><sub>validate(), convert: false · v18.2.9</sub> | 169.5 KB | 53.3 KB | |
|
|
@@ -497,7 +497,9 @@ TypeScript 5.0 or newer.
|
|
|
497
497
|
| Any object | `payload: 'json'` | any non-null object |
|
|
498
498
|
| Calculated | `ratio: (file) => file.compressed / file.size` | a function, never validated |
|
|
499
499
|
|
|
500
|
-
The first key of an object decides what it is
|
|
500
|
+
The first key of an object decides what it is: a kind when it is a name like `Entity` holding an
|
|
501
|
+
object, so a struct may begin with a capitalized field (`{ DATABASE_URL: 'string', PORT: 'number' }`
|
|
502
|
+
is a struct of two fields). Built-in types: `string`, `number`, `integer`,
|
|
501
503
|
`bigint`, `boolean`, `date`, `bytes`, `null`, `any`/`unknown`, `enum`, `flags`, `array`, `set`,
|
|
502
504
|
`object`, `map`, `tuple`, `union`, `json`. Rules: `length` (with `unicode: true` for code
|
|
503
505
|
points), `pattern` and `format` for strings, `length` for collections, `min`/`max` for numbers,
|
|
@@ -508,7 +510,7 @@ can have a top-level `validate` for rules across fields. `check(value, options)`
|
|
|
508
510
|
`{ Struct: { unknown: 'ignore' } }` makes it the schema's default), `references` (`'kind'`,
|
|
509
511
|
`'embed'` or `'id'`) and `messages` (a locale); the result has `issues`, `errors`, `summary`,
|
|
510
512
|
`flatten()`, `tree()` and `toJSON()`. `schema.warnings` lints the definition (a mistyped option, a `pattern`
|
|
511
|
-
without `length.max
|
|
513
|
+
without `length.max`, a field that was read as a kind). See [Schema Syntax](https://metaschema.vercel.app/guide/schema-syntax),
|
|
512
514
|
[Types](https://metaschema.vercel.app/guide/types),
|
|
513
515
|
[Unions, nullable and null](https://metaschema.vercel.app/guide/unions),
|
|
514
516
|
[References](https://metaschema.vercel.app/guide/references) and
|
|
@@ -569,7 +571,8 @@ interface User {
|
|
|
569
571
|
`register()` adds `model.dts`, `model.toTypeScript` and `schema.toInterface` as methods. The first
|
|
570
572
|
key of a definition sets
|
|
571
573
|
its kind and metadata (`Entity`, `Registry`, `Dictionary`, `Journal`, `Details`, `Relation`,
|
|
572
|
-
`View`, `Struct`, `Form`, `Projection`, or any custom kind
|
|
574
|
+
`View`, `Struct`, `Form`, `Projection`, or any custom kind: a capitalized name with a lowercase
|
|
575
|
+
letter in it, holding the metadata object). Stored kinds default to
|
|
573
576
|
`scope: 'application'` and `store: 'persistent'`, and they get an id field; a reference to a
|
|
574
577
|
stored kind holds its id, a reference to a memory kind embeds the record, in `check` and in the
|
|
575
578
|
generated types alike. See
|
|
@@ -618,7 +621,7 @@ const parsed = ReadableStream.from(rows).pipeThrough(
|
|
|
618
621
|
|
|
619
622
|
`checkEachAsync` and `parseEachAsync` take a sync or async source and keep `concurrency` records
|
|
620
623
|
in flight; `maxInvalid` ends an iteration after that many invalid records, and a `transform`
|
|
621
|
-
without `onInvalid` ends its stream with `
|
|
624
|
+
without `onInvalid` ends its stream with `ALX_ERR_INVALID_RECORD`. See
|
|
622
625
|
[Records and streams](https://metaschema.vercel.app/guide/streaming).
|
|
623
626
|
|
|
624
627
|
## Coercion
|
|
@@ -814,7 +817,7 @@ text. See [The JIT backend](https://metaschema.vercel.app/guide/compile).
|
|
|
814
817
|
```js
|
|
815
818
|
const {
|
|
816
819
|
KIND, KIND_STORED, KIND_MEMORY, SCOPE, STORE, ALLOW,
|
|
817
|
-
getKindMetadata, Schema, Model, SchemaDefinitionError, ValidationResult,
|
|
820
|
+
getKindMetadata, Schema, Model, SchemaDefinitionError, SchemaUsageError, ValidationResult,
|
|
818
821
|
} = require('@alexify/metaschema');
|
|
819
822
|
|
|
820
823
|
const { toJSONSchema, toTypeScript, saveTypes, fromJSONSchema, register } = require('@alexify/metaschema/generators');
|
|
@@ -843,6 +846,21 @@ and every exported type.
|
|
|
843
846
|
|
|
844
847
|
## Migrating
|
|
845
848
|
|
|
849
|
+
### From 3.x
|
|
850
|
+
|
|
851
|
+
4.0 changes the errors and the hooks that watch a call. Every code has the `ALX_` prefix of the Alexis
|
|
852
|
+
libraries (`ERR_INVALID_RULE` is `ALX_ERR_INVALID_RULE`, and so for every code), and a wrong
|
|
853
|
+
call (a target or an option a call does not take, a method before its `register()`, a promise
|
|
854
|
+
where the call is synchronous, an invalid record of a stream) throws `SchemaUsageError`, a
|
|
855
|
+
subclass of `TypeError`, where it threw a plain `TypeError`; the options of the compile
|
|
856
|
+
subpath, the generators, the model subpath, `Model` and coerce's `register`, which threw
|
|
857
|
+
`SchemaDefinitionError` with `ERR_INVALID_OPTIONS`, are among them (`ALX_ERR_INVALID_OPTION`).
|
|
858
|
+
`saveTypes` in a browser rejects with `ALX_ERR_UNSUPPORTED_RUNTIME` of that class, both
|
|
859
|
+
classes take the arguments of `Error` (`new SchemaDefinitionError(message, { code, cause })`),
|
|
860
|
+
and a hook (`onFallback`, `onError`, `onUnsupported`) no longer fails the
|
|
861
|
+
call it watches. The schema language, the results and their issue codes stay as they are. The before-and-after examples are in
|
|
862
|
+
[Migrating from 3.x](https://metaschema.vercel.app/guide/migrating-from-3).
|
|
863
|
+
|
|
846
864
|
### From 2.x
|
|
847
865
|
|
|
848
866
|
3.0 has two breaking changes. The generators left the core entry: `model.dts`,
|
package/SECURITY.md
CHANGED
|
@@ -6,7 +6,8 @@ Only the latest published version receives fixes.
|
|
|
6
6
|
|
|
7
7
|
| Version | Supported |
|
|
8
8
|
|---|---|
|
|
9
|
-
|
|
|
9
|
+
| 4.x | ✅ |
|
|
10
|
+
| 3.x | ❌ (upgrade: [Migrating from 3.x](https://metaschema.vercel.app/guide/migrating-from-3)) |
|
|
10
11
|
| 2.x | ❌ (upgrade: the CHANGELOG has the notes) |
|
|
11
12
|
| 1.x | ❌ |
|
|
12
13
|
| `metaschema` (metarhia) 2.x | ❌ (report upstream) |
|
|
@@ -79,7 +80,7 @@ Some things work as intended and are not vulnerabilities:
|
|
|
79
80
|
a copy (the `custom` metadata of a kind, the indexes and the `database` metadata included):
|
|
80
81
|
no function, no object of the model, a function as `{ $function: true }`. Read back by
|
|
81
82
|
`fromJSON`, a snapshot is untrusted input: its tags (`$date`, `$bigint`, `$bytes`, `$map`,
|
|
82
|
-
`$set`) are read into values and a tag that does not read is `
|
|
83
|
+
`$set`) are read into values and a tag that does not read is `ALX_ERR_INVALID_SNAPSHOT`; a value
|
|
83
84
|
shaped like a `Date` or a `RegExp` (`{ "constructor": { "name": "Date" } }`) is data; its
|
|
84
85
|
`root` names one of its entities; a field key `root` is refused like the methods of a field;
|
|
85
86
|
the walks are bounded (128 levels, and a chain of entities of any length orders without
|
|
@@ -92,7 +93,7 @@ Some things work as intended and are not vulnerabilities:
|
|
|
92
93
|
`length.max` holds one. `fromDocument` of `./mongodb` reads a generic Binary (subtype 0 or
|
|
93
94
|
2) into a copy of its bytes and leaves any other subtype to the check.
|
|
94
95
|
- **The definition entry does not validate.** A schema built through
|
|
95
|
-
`@alexify/metaschema/definition` throws `
|
|
96
|
+
`@alexify/metaschema/definition` throws `ALX_ERR_NOT_REGISTERED` from every way to validate until
|
|
96
97
|
the core entry of the same copy of the package is loaded, and has no `~standard`, so a
|
|
97
98
|
consumer of Standard Schema never takes it for a validator. A schema of another copy (two
|
|
98
99
|
versions of the package installed) does not validate with this copy's core and says so.
|
|
@@ -101,7 +102,7 @@ Some things work as intended and are not vulnerabilities:
|
|
|
101
102
|
keys of the definition, written as own properties), and checks the definition it built
|
|
102
103
|
against every sample before it returns it. A key of a sample that reaches an error message
|
|
103
104
|
is truncated to 100 characters, as a key of a value under check is.
|
|
104
|
-
- **The error a stream ends with carries the record.** `
|
|
105
|
+
- **The error a stream ends with carries the record.** `ALX_ERR_INVALID_RECORD` of the stream
|
|
105
106
|
subpath has `record` and `result` on it, since the stream carries them no further; a logger
|
|
106
107
|
that serializes error objects writes the record.
|
|
107
108
|
- **Validation errors are data.** `check` collects problems as issues (a code, a path and params,
|