@alexify/metaschema 0.0.0-stage → 1.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 ADDED
@@ -0,0 +1,452 @@
1
+ # Changelog
2
+
3
+ All notable changes to **`@alexify/metaschema`** are documented in this file.
4
+
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
+
8
+ ## [Unreleased]
9
+
10
+ ## [1.0.0] - 2026-10-09
11
+
12
+ The first release of `@alexify/metaschema`. It is a fork of
13
+ [`metaschema`](https://github.com/metarhia/metaschema) 2.2.2. The schema language and the
14
+ validation semantics are unchanged. The package around them now follows the other Alexis
15
+ libraries: zero runtime dependencies, one package for Node.js and browsers, and typings that match
16
+ the runtime.
17
+
18
+ ### Upgrading from metaschema 2.x
19
+
20
+ Replace `metaschema` with `@alexify/metaschema`, then follow
21
+ [Migrating from metarhia](https://metaschema.vercel.app/guide/migrating-from-metarhia). The
22
+ breaking changes are the removed loader functions, the renamed `detouch`, the `exports` map,
23
+ `SchemaDefinitionError` for every broken definition, and the corrected and more precise
24
+ validation messages listed under Changed and Fixed.
25
+
26
+ ### Added
27
+
28
+ - **`SchemaDefinitionError`.** Every broken definition throws this `TypeError` subclass with a
29
+ `code` (`ERR_UNKNOWN_TYPE`, `ERR_INVALID_DEFINITION`, `ERR_MISSING_SCHEMA`, `ERR_INVALID_ENUM`,
30
+ `ERR_INVALID_LENGTH`, `ERR_INVALID_TUPLE`, `ERR_INVALID_REFERENCE`, `ERR_RESERVED_KEY`,
31
+ `ERR_PROJECTION`, `ERR_INVALID_CUSTOM_TYPE`, `ERR_TYPE_REGISTERED`, `ERR_UNKNOWN_JS_TYPE`,
32
+ `ERR_INVALID_OPTIONS`) and the `schema` and `field` it was found in, and the message says
33
+ where: `Unknown type "strng" in "Order.total"`. Previously a model with many
34
+ entities threw a bare `Error: Unknown type strng` with no hint of the entity or field, and a
35
+ `null` field definition threw `Cannot read properties of null`.
36
+ - **Structured issues.** `result.issues` holds `{ code, path, message }` for every message, with
37
+ the codes `required`, `type`, `unexpected`, `enum`, `length`, `reference`, `circular`,
38
+ `exception` and `custom`, so a form, a logger or an i18n layer need not parse the text. A
39
+ `validate` function may return `{ code, message }` objects of its own.
40
+ - **`check(value, path, { maxErrors })`** stops collecting at that many messages and stops walking
41
+ fields, elements and records as soon as the limit is reached.
42
+ - **An isolated type registry per model.** `new Model(types, entities, database, { registry:
43
+ 'isolated' })` gives the model its own copy of the built-in types to register into, so two
44
+ models with conflicting custom types can live in one process. The default, `'shared'`, is the
45
+ process-wide registry as before.
46
+ - **Readable `console.log`.** A schema or a field printed with `util.inspect` shows its definition
47
+ (`Schema(User) { name: { required: true, type: 'string' } }`) instead of the whole graph with
48
+ `[Circular]` markers.
49
+ - **`ValidationResult`** is exported, so a `validate` function can build the result it returns.
50
+ The typings describe it as the class it is, with `add` and `ValidationResult.format`, instead of
51
+ a two-property interface.
52
+ - **`Schema#detach`**, the correctly spelt replacement for `detouch`.
53
+ - **Exported types** for everything public: `Kind`, `KnownKind`, `Scope`, `Store`, `Allow`,
54
+ `Cardinality`, `Relation`, `Fields`, `FieldType`, `CalculatedField`, `TypeTable`,
55
+ `TypeConstructor`, `TypeEntry`, `KindMetadata`, `SchemaOptions`, `ModelOptions`,
56
+ `CheckOptions`, `Validator`, `ValidationReturn`, `ValidationIssue`, `IssueInput`, `IssueCode`
57
+ and `DefinitionErrorCode`.
58
+ - **Documentation site** at [metaschema.vercel.app](https://metaschema.vercel.app/).
59
+
60
+ ### Changed
61
+
62
+ - **Package name** is `@alexify/metaschema`, published from `Alexis-Technologies/metaschema`.
63
+ - **Browser entry.** `dist.js` is replaced by `browser.js`, which exports the same names as the
64
+ main entry. `saveTypes` lives in `src/runtime/node.js`, and its browser twin rejects. Both the
65
+ `browser` field and the `browser` export condition point bundlers to it.
66
+ - **ESM named imports** work: the root barrel lists every export by name, so
67
+ `import { Schema } from '@alexify/metaschema'` resolves.
68
+ - **`Model`** accepts any iterable of `[name, definition]` pairs, not only a `Map`.
69
+ - **Paths and coverage of messages.** An unexpected key inside a nested struct carries the parent
70
+ path (`Field "nested.field2" is not expected`, was `Field "field2"`); records of a `many`
71
+ reference carry their index (`Person.companies[1].name`, was `Person.companies.name`); every
72
+ element of a tuple and every record of a `many` reference is reported instead of only the
73
+ first; and a wrong key type in an `object` or `map` reads `Field "o" keys must be of type string`
74
+ (was `Field "o" In object "o": type of key must be a string`).
75
+ - **`model.dts` keeps the shape of every field.** Arrays and sets render as `T[]`, an `enum` as
76
+ a union of its values, `bigint` as `bigint`, a tuple as `[number, number]`, `object` as
77
+ `Record<K, V>`, `map` as `Map<K, V>`, a nested struct inline and `json` as `unknown`; before,
78
+ everything but `string`, `number` and `boolean` was rendered as `string`. References still
79
+ become ids and custom scalar types still render as `string`.
80
+ - **Validation is faster.** A field chooses its rule checks once when it is built instead of
81
+ scanning the rule table on every check, arrays are walked in place, and a schema caches the type
82
+ table of its namespaces: `check` runs about 1.7× faster on flat values and 1.5× on nested ones
83
+ than the 2.2.2 code on the same machine (`pnpm bench`).
84
+
85
+ ### Removed
86
+
87
+ - **Loading schemas from files and strings.** `createSchema`, `loadSchema`, `readDirectory` and
88
+ `loadModel` are gone, together with the `metavm` sandbox they ran schema sources in. Pass schema
89
+ objects to `Schema` and `Model` directly.
90
+ - **Runtime dependencies.** `metautil`, `metavm` and `metaskills` are no longer installed. The
91
+ `metautil` helpers metaschema uses are copied into `src/metautil.js`.
92
+ - **Deep imports.** The `exports` map exposes only the package root.
93
+ - **`Schema#detouch`.** It is renamed to `detach`, with no alias for the old spelling.
94
+
95
+ ### Fixed
96
+
97
+ - **Error messages.** Typos and grammar in validation messages are fixed, with no compatibility
98
+ for the old text:
99
+ - `Filed "..." is required` → `Field "..." is required`;
100
+ - `Filed "..." is not a object` (and `is not a map`) →
101
+ `Field "..." not of expected type: object` (and `map`), like every other type error;
102
+ - `more then expected in tuple` → `more than expected in tuple`.
103
+ - **Optional nested structs in collections.** A nested struct marked `required: false` (long form,
104
+ `{ type: 'schema', schema, required: false }`) was still required as an array, set, object or map
105
+ element, so `null` elements were rejected. It is now optional there too, like `{ array: '?string' }`.
106
+ Optional nested struct fields (`'key?'`, `required: false`) already worked and are unchanged.
107
+ - **Silent and misleading type registration.** `{ string: { js: 'number' } }` was ignored without
108
+ a word, and both an unknown alias (`{ js: 'strng' }`) and an alias of a custom type registered
109
+ earlier in the table failed with `Custom type must contain "construct" and "checkType" methods`.
110
+ Redefining a registered name now throws `ERR_TYPE_REGISTERED` (the same definition, or a
111
+ metadata-only entry, is still accepted, so one table can serve every model), an unknown `js`
112
+ throws `ERR_UNKNOWN_JS_TYPE`, and `js` may name any type registered earlier in the table.
113
+ - **Reserved keys in a field definition.** `{ type: 'string', constructor: 'x' }` silently
114
+ switched validation of that field off, `check: 'x'` broke `check` with
115
+ `type.check is not a function`, and a `__proto__` key (as `JSON.parse` produces) failed with
116
+ `typeFormatters[key] is not a function`. A key that names a method of the field (`check`,
117
+ `checkType`, `construct`, `isInstance`, `toJSON`, `constructor`, …) or `__proto__`/`prototype`
118
+ is now rejected when the schema is built (`ERR_RESERVED_KEY`).
119
+ - **A validator returning more than ~110,000 messages lost all of them.** `ValidationResult#add`
120
+ spread them into `push`, which throws past the engine's argument limit, and `check` reported a
121
+ single `validation failed RangeError` instead. Every message is kept.
122
+ - **`JSON.stringify` of a schema whose definition is a single type** (`Schema.from('string')`,
123
+ `Schema.from({ array: 'number' })`) threw `Schema cannot be serialized`. It serializes like a
124
+ field now, and `toString()` is `JSON.stringify(schema)`.
125
+ - **A `Schema` instance passed to `new Schema(name, instance, namespaces)` lost the namespaces**,
126
+ so a prebuilt schema given to a `Model` could not resolve its references through the model. The
127
+ instance is still returned as is, keeping its own name; the namespaces are attached, and a
128
+ different `name` is a definition error.
129
+ - **A huge input key made a huge message.** Key names taken from the value under check are
130
+ truncated to 100 characters in `is not expected` messages and nested paths.
131
+ - **Circular values.** A value that referred back to itself through a reference, a nested struct
132
+ or a collection was walked until the engine threw `RangeError`, reported as
133
+ `validation failed RangeError` at whatever depth the stack ran out, with a path thousands of
134
+ segments long. It is now reported where the cycle closes:
135
+ `Field "Category.parent" is a circular reference`.
136
+ - **Ordinary bad input reported as an internal error.** `null` for a required `object` field
137
+ produced `validation failed TypeError: Cannot convert undefined or null to object`, an array was
138
+ accepted as an `object`, and a number for a `many` reference produced
139
+ `validation failed TypeError: source is not iterable`. They are now type errors like any other:
140
+ `Field "o" not of expected type: object` and
141
+ `Field "Person.companies" not of expected type: array of Company`.
142
+ - **Broken definitions that only failed inside `check`.** `{ type: 'enum' }` without values
143
+ reported `validation failed TypeError: Cannot read properties of undefined` for every value;
144
+ `length: 'abc'` was silently ignored; `length: { max: 0 }` was ignored too because `0` is falsy;
145
+ `{ many: 5 }` was accepted; and a projection naming a field its parent does not have failed with
146
+ `Invalid definition: "undefined" of type undefined`. Each is now a `SchemaDefinitionError` when
147
+ the schema is built (`ERR_INVALID_ENUM`, `ERR_INVALID_LENGTH`, `ERR_INVALID_REFERENCE`,
148
+ `ERR_PROJECTION`), and `length: { max: 0 }` works.
149
+ - **Tuple fields in the short form were never required.** `point: ['number', 'number']` left
150
+ `required` undefined, so a missing `point` passed validation and `model.dts` rendered it as
151
+ optional; only the long form `{ type: 'tuple', value: [...] }` was required. The short form is now
152
+ required by default like every other field, and `'point?': [...]` makes it optional.
153
+ - **Field names `check`, `name`, `constructor` and other `Object.prototype` names.** A struct was a
154
+ class instance used as a dictionary, so a field named `check` replaced the method
155
+ (`this.fields.check is not a function`), a field named `name` corrupted the message for a value
156
+ that is not an object (`Field "[object Object]"`), and input keys such as `constructor`,
157
+ `__proto__` or `check` were silently accepted instead of reported as not expected. Fields now
158
+ live in a null-prototype dictionary. A value that is not an object is reported as
159
+ `Field "<path>" not of expected type: object`, like every other type error (was
160
+ `Value of "<path>" must be an object`).
161
+ - **Bundled and minified builds.** Schemas, fields and validation results were recognised by
162
+ `constructor.name`. esbuild emits `class _Schema` for the self-referencing `Schema` class, so in
163
+ any esbuild bundle (Vite, tsup, serverless builds) a `Schema` instance used as a field, or passed
164
+ to `new Schema`, failed with `Unknown type struct`; with minification the `Type` class was
165
+ renamed too and `check` accepted every value. Identity is now a global symbol brand
166
+ (`Symbol.for`), which also recognises results from a second copy of the package.
167
+ `tests/unit/bundle.test.js` validates through esbuild bundles of both entries, minified and not.
168
+ - **Reference cycles that do not pass through the first entity** (`A → B → C → B`) made `new Model`
169
+ fail with `RangeError: Maximum call stack size exceeded`, and whether a cycle crashed or produced a
170
+ warning depended on the order of the entities. Every cycle is now a warning, in the same format
171
+ as a missing reference: `Warning: "C" depends on "B" recursively` (was
172
+ `Recursive dependency: C.B`).
173
+ `Model#preprocess` and `Model#reorderEntity` are constructor internals and are no longer public.
174
+ - **A schema type without a definition** (`data: 'schema'`, `{ type: 'schema' }`, or an alias
175
+ such as `{ js: 'schema' }` used as `'address'`) failed with
176
+ `Cannot convert undefined or null to object`, and a non-object `schema` with an unrelated
177
+ `Unknown type` error. It now throws `SchemaDefinitionError` (`ERR_MISSING_SCHEMA`):
178
+ `Type "address" needs a schema definition: { type: 'address', schema: { ... } } in "Order.delivery"`.
179
+ - **Typings.** `index.d.ts` matches the runtime:
180
+ - the static `Schema.KIND`, `KIND_STORED`, `KIND_MEMORY`, `SCOPE`, `STORE` and `ALLOW` fields,
181
+ which never existed, are removed;
182
+ - `'system'` is removed from `Scope`;
183
+ - `Schema.from` accepts strings and arrays;
184
+ - `validate`, `findReference` and `Model#database` may be `null`;
185
+ - `fields`, `indexes`, `custom`, the type table and the entries passed to `Model` are typed
186
+ (`Fields`, `FieldType`, `TypeTable`, `TypeEntry`, ...) instead of `object` and `Function`;
187
+ - `Cardinality` is the two values the runtime produces, and `Kind` admits a custom kind.
188
+
189
+ ### Tooling
190
+
191
+ - pnpm, oxlint and oxfmt replace npm, ESLint and Prettier; c8, tsd and TypeScript (7.x) check
192
+ coverage and the typings. oxlint runs with its `correctness` and `suspicious` categories on.
193
+ - Sources move to `src/`, tests to `tests/unit/` (with `tests/types/` for tsd), fixtures to
194
+ `tests/fixtures/`.
195
+ - c8 coverage gate, tsd type tests, an export-parity test and a platform test that keeps Node
196
+ builtins out of everything but `src/runtime/node.js`.
197
+ - CI runs lint, types, tests on Node 18–24 (Ubuntu) and 22–24 (Windows), coverage and the docs
198
+ build, with a single `ci-success` check.
199
+ - `pnpm size` reports bundle sizes and, with `--max-gzip <KB>`, fails over budget (CI gates at
200
+ 8 KB; the bundles are under 8 KB). `pnpm bench` runs the benchmarks and, with `--json`, `--save`
201
+ and `--compare`, snapshots them to `bench/baseline.json` and reports the change. The coverage
202
+ table appears in the CI job summary.
203
+
204
+ ## Upstream history (metarhia/metaschema)
205
+
206
+ Releases of [`metaschema`](https://github.com/metarhia/metaschema) before the fork, kept as
207
+ published.
208
+
209
+ ### [metaschema 2.2.2][upstream-2.2.2] - 2025-05-24
210
+
211
+ - Add node.js 23 and 24 to CI
212
+ - Update dependencies
213
+
214
+ ### [metaschema 2.2.1][upstream-2.2.1] - 2024-08-31
215
+
216
+ - Update eslint to 9.x and prettier with configs
217
+ - Add node.js 22 to CI
218
+
219
+ ### [metaschema 2.2.0][upstream-2.2.0] - 2024-03-27
220
+
221
+ - Add browser support
222
+ - Rename `SchemaError` to `ValidationResult`
223
+ - Update dependencies
224
+
225
+ ### [metaschema 2.1.5][upstream-2.1.5] - 2023-07-15
226
+
227
+ - Fix: remove debug output
228
+ - Update dependencies
229
+ - Package maintenance: AUTHORS, .prettierignore
230
+
231
+ ### [metaschema 2.1.4][upstream-2.1.4] - 2023-05-01
232
+
233
+ - Drop node.js 14 support, add node.js 20
234
+ - Convert package_lock.json to lockfileVersion 2
235
+ - Update dependencies
236
+
237
+ ### [metaschema 2.1.3][upstream-2.1.3] - 2023-03-13
238
+
239
+ - Add `BigInt` to known glabals
240
+ - Add `node:` prefix in require for built-in modules
241
+
242
+ ### [metaschema 2.1.2][upstream-2.1.2] - 2023-02-18
243
+
244
+ - Update dependencies and security issues
245
+ - Package maintenance: json autoformatting, CI, license
246
+
247
+ ### [metaschema 2.1.1][upstream-2.1.1] - 2022-08-16
248
+
249
+ - Non required fields can be `null`
250
+ - Using optional chaining operator
251
+
252
+ ### [metaschema 2.1.0][upstream-2.1.0] - 2022-07-11
253
+
254
+ - Test fixups from <https://github.com/metarhia/metaschema/pull/420/commits/5732714114a14e0f8a71617c779d73eb4b345fb4>
255
+ - toJSON and toString methods implementation for Schema
256
+
257
+ ### [metaschema 2.0.2][upstream-2.0.2] - 2022-06-25
258
+
259
+ - Hotfix: added missed exports to metaschema.js
260
+
261
+ ### [metaschema 2.0.1][upstream-2.0.1] - 2022-06-24
262
+
263
+ - json type for any plain javascript object
264
+ - fix names issue while using built-in prototypes for custom types
265
+
266
+ ### [metaschema 2.0.0][upstream-2.0.0] - 2022-06-22
267
+
268
+ - Struct implementation
269
+ - Refactoring and code quality improvement
270
+ - Metadata handled separetely
271
+ - Error handling improved now errors are chained
272
+ - Custom Kinds support implemented with custom metadata
273
+ `{ CustomKind: { customMetadata: 'meta' } }`
274
+ - Update dependencies: "eslint", "eslint-config-metarhia"
275
+ - Custom types syntax changed. No more hardcoded `pg`.
276
+ Now you must use `metadata` which is static property of Type constructor.
277
+ - Nested schema with relations bugfix
278
+ - Tuple type implementation
279
+ - Properly report error if trying to use `field: 'type'` shorthand for
280
+ `'enum', 'array', 'set', 'map', 'object'` types
281
+ - Rewrite schemas and implement custom types
282
+ - elegant syntax/format for custom types and internal types
283
+ - custom types support
284
+ - preprocessor to reduce Schema preprocess complexity
285
+ - any kind of nested arrays, array of references https://github.com/metarhia/metaschema/issues/378
286
+ - nested schemas with Schema instances support
287
+ - any level of complex nested types support
288
+ - custom validate for field
289
+ - changed validate for schema, simplified for user
290
+ - all user's validate functions support 4 types of syntax: boolean return, throw Error, error message as string return and array of error messages
291
+ - reserved words permitted in schema if kind provided
292
+ - function fields stored in schema
293
+ - shorthand required key for collections support `{ 'array?': 'string' }`
294
+ - many relation now checks in runtime
295
+ - model now loads projections at the end, to fix bug
296
+ - schema kinds moved to separate file and kinds now have logic to remove hardcoded projection from Schema
297
+ - ts interfaces from schema now have relation ids as well
298
+ - deps update metautil
299
+ - nested object support https://github.com/metarhia/metaschema/issues/395
300
+ - syntax for validate function changed
301
+ - Model no more require metavm for browser compatibility: need `impress` update
302
+ - loadModel moved to loader: need `impress` update
303
+ - Model no more writes d.ts file to disk moved to loader as well: need `metasql` update
304
+ - syntax for pg types changed a bit, no more not-working types: need `metasql` update
305
+
306
+ ### [metaschema 1.4.1][upstream-1.4.1] - 2022-03-17
307
+
308
+ - Skip calculated fields in schemas
309
+ - Update dependencies
310
+ - Fix tests after update metatests to 0.8.1
311
+
312
+ ### [metaschema 1.4.0][upstream-1.4.0] - 2022-02-23
313
+
314
+ - Fix nullable field long-form
315
+ - Optional for nested structures
316
+ - Shorthand for optional nested structure
317
+ - Fix paths in validation errors
318
+ - Unify nested schema fields to
319
+ `{ type: 'schema', schema: Schema, /* other fields */ }`
320
+ - Support Schema#validate function
321
+
322
+ ### [metaschema 1.3.4][upstream-1.3.4] - 2021-09-10
323
+
324
+ - Show path to the field in warnings
325
+ - Remove spread operator in `toLongForm`
326
+ - Update dependencies
327
+
328
+ ### [metaschema 1.3.3][upstream-1.3.3] - 2021-07-19
329
+
330
+ - Improve code style
331
+ - Move types to package root
332
+ - Package maintenance: update dependencies, update engines, security
333
+
334
+ ### [metaschema 1.3.2][upstream-1.3.2] - 2021-06-30
335
+
336
+ - Schema projection
337
+ - Schema.prototype.relations: Set<{ to: string, type: string }>
338
+
339
+ ### [metaschema 1.3.1][upstream-1.3.1] - 2021-06-26
340
+
341
+ - Add namespaces to Schema.from factory
342
+ - Fix "not expected" warning
343
+
344
+ ### [metaschema 1.3.0][upstream-1.3.0] - 2021-06-25
345
+
346
+ - Check schemas with references to schemas from attached models
347
+ - Add Schema.prototype.namespaces and attach/detouch methods to add/remove
348
+ - Add types to Schema.prototype.references (in addition to entities)
349
+ - Move Model.prototype.checkReferences to Schema.prototype.checkConsistency
350
+ - Fix lost json subfields checking
351
+ - Improve Schema kinds
352
+
353
+ ### [metaschema 1.2.3][upstream-1.2.3] - 2021-05-22
354
+
355
+ - Restrict 'type' property in db schemas
356
+ - Simplify schema examples
357
+
358
+ ### [metaschema 1.2.2][upstream-1.2.2] - 2021-05-17
359
+
360
+ - Fix unique alternative keys
361
+
362
+ ### [metaschema 1.2.1][upstream-1.2.1] - 2021-05-15
363
+
364
+ - Move Identifier ahead of entity order
365
+ - Collect all references: Schema.prototype.references
366
+ - Improve check references for Model
367
+ - Reorder entities including many-to-many references
368
+ - Fix recursion detection on many-to-many and parent
369
+
370
+ ### [metaschema 1.2.0][upstream-1.2.0] - 2021-05-13
371
+
372
+ - Change Schema metadata `{ kind, scope, store, allow }`
373
+ - Update dependencies and fix security issue
374
+
375
+ ### [metaschema 1.1.2][upstream-1.1.2] - 2021-05-08
376
+
377
+ - Shorthand for optional (not required) fields
378
+ - Nested schema of json type (for pg json fields)
379
+
380
+ ### [metaschema 1.1.1][upstream-1.1.1] - 2021-05-07
381
+
382
+ - Support nested schemas for Model class
383
+
384
+ ### [metaschema 1.1.0][upstream-1.1.0] - 2021-05-06
385
+
386
+ - Move Schema.prototype.toInterface from metasql
387
+ - Move Directory loader from metasql
388
+ - Move Model class from metasql (previous name DomainModel)
389
+ - Move Reference checker from metasql
390
+ - Move Entity reordering algorithm from metasql
391
+ - Improve Model and Schema classes
392
+
393
+ ### [metaschema 1.0.3][upstream-1.0.3] - 2021-04-13
394
+
395
+ - Add .d.ts typings
396
+ - Update metavm (added typings)
397
+
398
+ ### [metaschema 1.0.2][upstream-1.0.2] - 2021-03-11
399
+
400
+ - Support enumerated type
401
+ - Fix single value validation
402
+ - Fix bugs in not required fields checking
403
+
404
+ ### [metaschema 1.0.1][upstream-1.0.1] - 2021-03-06
405
+
406
+ - Fix database schema: index detection
407
+ - Add loaders from string and file
408
+
409
+ ### [metaschema 1.0.0][upstream-1.0.0] - 2021-03-02
410
+
411
+ - See specs: https://github.com/metarhia/Contracts
412
+ - Moved implementation from impress
413
+ - Implement schemas for structures and scalars
414
+ - Schema field shorthand
415
+ - Schema for collections: array, object, set, map
416
+ - Schema custom validation method
417
+
418
+ ### [metaschema 0.x][upstream-0.x] - First generation of metaschema
419
+
420
+ [unreleased]: https://github.com/Alexis-Technologies/metaschema/compare/v1.0.0...HEAD
421
+ [1.0.0]: https://github.com/Alexis-Technologies/metaschema/releases/tag/v1.0.0
422
+ [upstream-2.2.2]: https://github.com/metarhia/metaschema/compare/v2.2.1...v2.2.2
423
+ [upstream-2.2.1]: https://github.com/metarhia/metaschema/compare/v2.2.0...v2.2.1
424
+ [upstream-2.2.0]: https://github.com/metarhia/metaschema/compare/v2.1.5...v2.2.0
425
+ [upstream-2.1.5]: https://github.com/metarhia/metaschema/compare/v2.1.4...v2.1.5
426
+ [upstream-2.1.4]: https://github.com/metarhia/metaschema/compare/v2.1.3...v2.1.4
427
+ [upstream-2.1.3]: https://github.com/metarhia/metaschema/compare/v2.1.2...v2.1.3
428
+ [upstream-2.1.2]: https://github.com/metarhia/metaschema/compare/v2.1.1...v2.1.2
429
+ [upstream-2.1.1]: https://github.com/metarhia/metaschema/compare/v2.1.0...v2.1.1
430
+ [upstream-2.1.0]: https://github.com/metarhia/metaschema/compare/v2.0.2...v2.1.0
431
+ [upstream-2.0.2]: https://github.com/metarhia/metaschema/compare/v2.0.1...v2.0.2
432
+ [upstream-2.0.1]: https://github.com/metarhia/metaschema/compare/v2.0.0...v2.0.1
433
+ [upstream-2.0.0]: https://github.com/metarhia/metaschema/compare/v1.4.1...v2.0.0
434
+ [upstream-1.4.1]: https://github.com/metarhia/metaschema/compare/v1.4.0...v1.4.1
435
+ [upstream-1.4.0]: https://github.com/metarhia/metaschema/compare/v1.3.4...v1.4.0
436
+ [upstream-1.3.4]: https://github.com/metarhia/metaschema/compare/v1.3.3...v1.3.4
437
+ [upstream-1.3.3]: https://github.com/metarhia/metaschema/compare/v1.3.2...v1.3.3
438
+ [upstream-1.3.2]: https://github.com/metarhia/metaschema/compare/v1.3.1...v1.3.2
439
+ [upstream-1.3.1]: https://github.com/metarhia/metaschema/compare/v1.3.0...v1.3.1
440
+ [upstream-1.3.0]: https://github.com/metarhia/metaschema/compare/v1.2.3...v1.3.0
441
+ [upstream-1.2.3]: https://github.com/metarhia/metaschema/compare/v1.2.2...v1.2.3
442
+ [upstream-1.2.2]: https://github.com/metarhia/metaschema/compare/v1.2.1...v1.2.2
443
+ [upstream-1.2.1]: https://github.com/metarhia/metaschema/compare/v1.2.0...v1.2.1
444
+ [upstream-1.2.0]: https://github.com/metarhia/metaschema/compare/v1.1.2...v1.2.0
445
+ [upstream-1.1.2]: https://github.com/metarhia/metaschema/compare/v1.1.1...v1.1.2
446
+ [upstream-1.1.1]: https://github.com/metarhia/metaschema/compare/v1.1.0...v1.1.1
447
+ [upstream-1.1.0]: https://github.com/metarhia/metaschema/compare/v1.0.3...v1.1.0
448
+ [upstream-1.0.3]: https://github.com/metarhia/metaschema/compare/v1.0.2...v1.0.3
449
+ [upstream-1.0.2]: https://github.com/metarhia/metaschema/compare/v1.0.1...v1.0.2
450
+ [upstream-1.0.1]: https://github.com/metarhia/metaschema/compare/v1.0.0...v1.0.1
451
+ [upstream-1.0.0]: https://github.com/metarhia/metaschema/compare/v0.x...v1.0.0
452
+ [upstream-0.x]: https://github.com/metarhia/metaschema/releases/tag/v0.x
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2017-2025 Metarhia contributors
4
+ Copyright (c) 2026 Alexis Technologies
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,179 @@
1
- # Temporary Holding Version
1
+ # metaschema
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [![npm](https://img.shields.io/npm/v/%40alexify%2Fmetaschema)](https://www.npmjs.com/package/@alexify/metaschema)
4
+ [![CI](https://github.com/Alexis-Technologies/metaschema/actions/workflows/ci.yml/badge.svg)](https://github.com/Alexis-Technologies/metaschema/actions/workflows/ci.yml)
5
+ [![node](https://img.shields.io/node/v/%40alexify%2Fmetaschema)](#installation)
6
+ [![dependencies](https://img.shields.io/badge/runtime_dependencies-0-brightgreen)](#why-metaschema)
7
+ [![docs](https://img.shields.io/badge/docs-online-blue)](https://metaschema.vercel.app/)
8
+ [![license](https://img.shields.io/npm/l/%40alexify%2Fmetaschema)](./LICENSE)
9
+
10
+ **Metadata schema and interface definition language for JavaScript.** Declare data structures and
11
+ domain models once as plain objects, validate data against them, and generate TypeScript
12
+ interfaces. Zero dependencies, Node.js and browsers.
13
+
14
+ ```js
15
+ const { Schema } = require('@alexify/metaschema');
16
+
17
+ const user = new Schema('User', {
18
+ name: { first: 'string', last: 'string' },
19
+ email: { type: 'string', length: { min: 5, max: 64 } },
20
+ age: '?number',
21
+ roles: { array: { enum: ['admin', 'editor', 'viewer'] } },
22
+ });
23
+
24
+ user.check({ name: { first: 'Marcus' }, email: 'm@r', roles: ['owner'] }).errors;
25
+ // [
26
+ // 'Field "User.name.last" is required',
27
+ // 'Field "User.email" value is too short',
28
+ // 'Field "User.roles[0]" value is not of enum: admin, editor, viewer'
29
+ // ]
30
+ ```
31
+
32
+ ### 📖 [Read the documentation →](https://metaschema.vercel.app/)
33
+
34
+ ## Why metaschema
35
+
36
+ - **Compact syntax.** `'?string'` is an optional string, `'tags?'` an optional key,
37
+ `{ array: 'number' }` an array, `['number', 'number']` a tuple, `'Company'` a reference. The
38
+ long form (`{ type: 'string', length: [3, 32] }`) is there when a field needs options.
39
+ - **Errors, not exceptions.** `check` walks the whole value and returns every problem with its
40
+ path. Only a broken definition throws.
41
+ - **Domain models.** Entities, registries, dictionaries and projections, with references,
42
+ relations and indexes, ordered by dependency and checked for missing references.
43
+ - **TypeScript.** A model renders its entities as interfaces. The package ships hand-written
44
+ typings for its own API.
45
+ - **Zero dependencies, under 8 KB min+gzip.** CommonJS with ESM named imports, no build step, one
46
+ package for Node.js and browsers.
47
+
48
+ ## Installation
49
+
50
+ ```bash
51
+ pnpm add @alexify/metaschema
52
+ # or
53
+ npm install @alexify/metaschema
54
+ ```
55
+
56
+ Requires Node.js 18 or newer. Works in browsers through any bundler.
57
+
58
+ ## Schema syntax
59
+
60
+ | Form | Example | Meaning |
61
+ | --- | --- | --- |
62
+ | Type name | `title: 'string'` | a required string |
63
+ | Optional | `subtitle: '?string'` or `'subtitle?': 'string'` | `undefined` / `null` allowed |
64
+ | Long form | `login: { type: 'string', length: [3, 32] }` | a type with options |
65
+ | Collections | `{ array: 'number' }`, `{ set: 'string' }`, `{ object: { string: 'number' } }`, `{ map: { string: 'string' } }` | |
66
+ | Enum | `{ enum: ['admin', 'user'] }` | one of the values |
67
+ | Tuple | `point: ['number', 'number']` | a fixed-length array of scalars |
68
+ | Nested struct | `name: { first: 'string', last: 'string' }` | an object with its own fields |
69
+ | Reference | `company: 'Company'`, `{ many: 'Address' }` | another schema in the model |
70
+ | Any object | `payload: 'json'` | any non-null object |
71
+ | Calculated | `ratio: (file) => file.compressed / file.size` | a function, never validated |
72
+
73
+ Built-in types: `string`, `number`, `bigint`, `boolean`, `enum`, `array`, `set`, `object`, `map`,
74
+ `tuple`, `json`. Fields can add a `validate(value, path)` function, and a schema can have a
75
+ top-level `validate` for rules across fields. See
76
+ [Schema Syntax](https://metaschema.vercel.app/guide/schema-syntax) and
77
+ [Validation](https://metaschema.vercel.app/guide/validation).
78
+
79
+ ## Domain models
80
+
81
+ ```js
82
+ const { Model } = require('@alexify/metaschema');
83
+
84
+ const types = {
85
+ string: { metadata: { pg: 'varchar' } },
86
+ number: { metadata: { pg: 'integer' } },
87
+ boolean: { metadata: { pg: 'boolean' } },
88
+ };
89
+
90
+ const entities = new Map([
91
+ ['Company', { Dictionary: {}, name: { type: 'string', unique: true }, addresses: { many: 'Address' } }],
92
+ ['Address', { Entity: {}, city: 'string', street: 'string', building: '?string' }],
93
+ ['User', { Registry: {}, login: { type: 'string', length: { min: 3, max: 32 } }, company: 'Company', active: 'boolean' }],
94
+ ]);
95
+
96
+ const model = new Model(types, entities);
97
+
98
+ model.order; // Set { 'Address', 'Company', 'User' }
99
+ model.warnings; // [] (missing references end up here)
100
+ console.log(model.dts);
101
+ ```
102
+
103
+ ```ts
104
+ interface Address {
105
+ city: string;
106
+ street: string;
107
+ building?: string;
108
+ addressId?: string;
109
+ }
110
+
111
+ interface Company {
112
+ name: string;
113
+ addressesId: string[];
114
+ companyId?: string;
115
+ }
116
+
117
+ interface User {
118
+ login: string;
119
+ companyId: string;
120
+ active: boolean;
121
+ userId?: string;
122
+ }
123
+ ```
124
+
125
+ `saveTypes(outputFile, model)` writes `model.dts` to a file. The first key of a definition sets
126
+ its kind and metadata (`Entity`, `Registry`, `Dictionary`, `Journal`, `Details`, `Relation`,
127
+ `View`, `Struct`, `Form`, `Projection`, or any custom kind). Stored kinds default to
128
+ `scope: 'application'` and `store: 'persistent'`, and they get an id field. See
129
+ [Kinds and Metadata](https://metaschema.vercel.app/guide/kinds-and-metadata),
130
+ [Custom Types](https://metaschema.vercel.app/guide/custom-types) and
131
+ [Domain Models](https://metaschema.vercel.app/guide/model).
132
+
133
+ ## Exports
134
+
135
+ ```js
136
+ const {
137
+ KIND, KIND_STORED, KIND_MEMORY, SCOPE, STORE, ALLOW,
138
+ getKindMetadata, saveTypes, Schema, Model, SchemaDefinitionError, ValidationResult,
139
+ } = require('@alexify/metaschema');
140
+ ```
141
+
142
+ ```js
143
+ import { Schema, Model } from '@alexify/metaschema';
144
+ ```
145
+
146
+ In the browser every export works the same, except `saveTypes`, which rejects because there is no
147
+ file system. The [API reference](https://metaschema.vercel.app/api/exports) lists every member.
148
+
149
+ ## Migrating from `metaschema` (metarhia)
150
+
151
+ `@alexify/metaschema` is a fork of [`metaschema`](https://github.com/metarhia/metaschema) 2.2. The
152
+ schema language and the validation rules are the same. What changed:
153
+
154
+ - **No loader.** `createSchema`, `loadSchema`, `readDirectory` and `loadModel` are removed along
155
+ with the `metavm` sandbox. Use `new Schema(name, require('./schemas/User.js'))` and
156
+ `new Model(types, new Map([...]), database)`. Schema files written as `({ ... })` become modules
157
+ (`module.exports = { ... }`).
158
+ - **No runtime dependencies:** `metautil`, `metavm` and `metaskills` are gone.
159
+ - **Fixed messages, no old text kept:** `Field "..."` instead of `Filed "..."`,
160
+ `not of expected type: object` instead of `is not a object`, and "more than" instead of
161
+ "more then".
162
+ - **`detouch` is renamed to `detach`**, with no alias.
163
+ - **`browser.js`** replaces `dist.js`, and an `exports` map closes deep imports.
164
+
165
+ The full list is in [Migrating from metarhia](https://metaschema.vercel.app/guide/migrating-from-metarhia)
166
+ and the [CHANGELOG](./CHANGELOG.md).
167
+
168
+ ## Changelog
169
+
170
+ See [CHANGELOG.md](./CHANGELOG.md).
171
+
172
+ ## License
173
+
174
+ [MIT](./LICENSE) © Alexis Technologies
175
+
176
+ `@alexify/metaschema` is a fork of [`metaschema`](https://github.com/metarhia/metaschema) by the
177
+ [Metarhia contributors](https://github.com/metarhia/metaschema/graphs/contributors), originally
178
+ part of the [Metarhia](https://github.com/metarhia) technology stack. Their copyright is kept in
179
+ [LICENSE](./LICENSE).