@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.
Files changed (66) hide show
  1. package/CHANGELOG.md +227 -1
  2. package/README.md +29 -11
  3. package/SECURITY.md +5 -4
  4. package/index.d.ts +912 -480
  5. package/package.json +8 -6
  6. package/src/checks.js +72 -107
  7. package/src/codec.js +67 -58
  8. package/src/coerce/index.d.ts +31 -21
  9. package/src/coerce/index.js +64 -47
  10. package/src/compile/code.js +2 -2
  11. package/src/compile/emit.js +20 -31
  12. package/src/compile/index.d.ts +41 -25
  13. package/src/compile/index.js +45 -32
  14. package/src/context.js +10 -10
  15. package/src/definition/index.d.ts +10 -7
  16. package/src/definition/index.js +2 -1
  17. package/src/derive/index.d.ts +25 -17
  18. package/src/derive/index.js +21 -15
  19. package/src/errors.js +84 -59
  20. package/src/formats/index.d.ts +27 -21
  21. package/src/formats/index.js +15 -13
  22. package/src/generators/{fromjsonschema.js → from-json-schema.js} +170 -127
  23. package/src/generators/index.d.ts +23 -15
  24. package/src/generators/index.js +2 -2
  25. package/src/generators/{jsonschema.js → json-schema.js} +37 -43
  26. package/src/generators/typescript.js +9 -6
  27. package/src/index.js +2 -1
  28. package/src/issues.js +41 -42
  29. package/src/kinds.js +31 -10
  30. package/src/lint.js +64 -19
  31. package/src/locales/en.js +7 -7
  32. package/src/locales/uk.js +6 -6
  33. package/src/metadata.js +2 -2
  34. package/src/model/data.js +34 -20
  35. package/src/model/diff.js +29 -24
  36. package/src/model/index.d.ts +51 -35
  37. package/src/model/infer.js +70 -61
  38. package/src/model/merge.js +29 -18
  39. package/src/model/pattern.js +105 -102
  40. package/src/model/restore.js +33 -21
  41. package/src/model/sample.js +90 -100
  42. package/src/model.js +4 -2
  43. package/src/mongodb/bson.js +12 -12
  44. package/src/mongodb/document.js +7 -6
  45. package/src/mongodb/index.d.ts +54 -31
  46. package/src/mongodb/update.js +12 -9
  47. package/src/preprocessor.js +25 -15
  48. package/src/prototypes/abstract.js +8 -8
  49. package/src/prototypes/collections.js +7 -7
  50. package/src/prototypes/flags.js +1 -1
  51. package/src/prototypes/reference.js +3 -4
  52. package/src/prototypes/scalars.js +1 -1
  53. package/src/prototypes/schema.js +5 -6
  54. package/src/prototypes/tuple.js +11 -10
  55. package/src/prototypes/union.js +5 -4
  56. package/src/rules.js +23 -20
  57. package/src/runtime/browser.js +6 -1
  58. package/src/runtime/node.js +19 -2
  59. package/src/schema.js +19 -14
  60. package/src/snapshot.js +14 -12
  61. package/src/stream/index.d.ts +33 -21
  62. package/src/stream/index.js +37 -20
  63. package/src/struct.js +6 -6
  64. package/src/types.js +35 -26
  65. package/src/util.js +70 -64
  66. package/src/validation.js +10 -13
package/src/locales/en.js CHANGED
@@ -3,6 +3,11 @@
3
3
  // message. `field` renders the location prefix of an error line.
4
4
  const { shorten, safeString } = require('../util.js');
5
5
 
6
+ // The first keys of the list and how many more there are: a value with a
7
+ // million keys the schema does not have is one issue, and its message is
8
+ // not the million keys.
9
+ const SHOWN_KEYS = 10;
10
+
6
11
  const field = (path) => `Field "${path}"`;
7
12
 
8
13
  const required = () => 'is required';
@@ -10,16 +15,11 @@ const required = () => 'is required';
10
15
  const type = ({ expected, key }) =>
11
16
  key === undefined ? `not of expected type: ${expected}` : `keys must be of type ${expected}`;
12
17
 
13
- // The first keys of the list and how many more there are: a value with a
14
- // million keys the schema does not have is one issue, and its message is
15
- // not the million keys.
16
- const SHOWN = 10;
17
-
18
18
  const list = (keys) => {
19
- const count = Math.min(keys.length, SHOWN);
19
+ const count = Math.min(keys.length, SHOWN_KEYS);
20
20
  let text = shorten(keys[0]);
21
21
  for (let index = 1; index < count; index += 1) text += `, ${shorten(keys[index])}`;
22
- return keys.length > SHOWN ? `${text} and ${keys.length - SHOWN} more` : text;
22
+ return keys.length > SHOWN_KEYS ? `${text} and ${keys.length - SHOWN_KEYS} more` : text;
23
23
  };
24
24
 
25
25
  const unexpected = ({ keys }) => `has unexpected keys: ${list(keys)}`;
package/src/locales/uk.js CHANGED
@@ -2,6 +2,10 @@
2
2
  // check as `messages`: `schema.check(value, { messages: uk })`.
3
3
  const { shorten, safeString } = require('../util.js');
4
4
 
5
+ // Перші ключі списку і скільки їх ще: значення з мільйоном невідомих ключів
6
+ // є одним issue, і його повідомлення не є цим мільйоном.
7
+ const SHOWN_KEYS = 10;
8
+
5
9
  const field = (path) => `Поле "${path}"`;
6
10
 
7
11
  const required = () => 'є обовʼязковим';
@@ -9,15 +13,11 @@ const required = () => 'є обовʼязковим';
9
13
  const type = ({ expected, key }) =>
10
14
  key === undefined ? `не відповідає типу: ${expected}` : `ключі мають бути типу ${expected}`;
11
15
 
12
- // Перші ключі списку і скільки їх ще: значення з мільйоном невідомих ключів
13
- // є одним issue, і його повідомлення не є цим мільйоном.
14
- const SHOWN = 10;
15
-
16
16
  const list = (keys) => {
17
- const count = Math.min(keys.length, SHOWN);
17
+ const count = Math.min(keys.length, SHOWN_KEYS);
18
18
  let text = shorten(keys[0]);
19
19
  for (let index = 1; index < count; index += 1) text += `, ${shorten(keys[index])}`;
20
- return keys.length > SHOWN ? `${text} і ще ${keys.length - SHOWN}` : text;
20
+ return keys.length > SHOWN_KEYS ? `${text} і ще ${keys.length - SHOWN_KEYS}` : text;
21
21
  };
22
22
 
23
23
  const unexpected = ({ keys }) => `має неочікувані ключі: ${list(keys)}`;
package/src/metadata.js CHANGED
@@ -12,7 +12,7 @@ const unknownOf = (unknown) => {
12
12
  if (unknown === undefined) return 'reject';
13
13
  if (unknown !== 'reject' && unknown !== 'ignore') {
14
14
  const reason = `Schema metadata "unknown" must be "reject" or "ignore", got ${JSON.stringify(unknown)}`;
15
- throw new SchemaDefinitionError('ERR_INVALID_OPTIONS', reason);
15
+ throw new SchemaDefinitionError(reason, { code: 'ALX_ERR_INVALID_OPTIONS' });
16
16
  }
17
17
  return unknown;
18
18
  };
@@ -60,7 +60,7 @@ class SchemaMetadata {
60
60
  const { kind, scope, store, allow, parent, unknown, ...custom } = values;
61
61
  if (custom.coerce !== undefined && typeof custom.coerce !== 'boolean') {
62
62
  const reason = `Schema metadata "coerce" must be a boolean, got ${JSON.stringify(custom.coerce)}`;
63
- throw new SchemaDefinitionError('ERR_INVALID_OPTIONS', reason);
63
+ throw new SchemaDefinitionError(reason, { code: 'ALX_ERR_INVALID_OPTIONS' });
64
64
  }
65
65
  this.kind = kind || this.kind;
66
66
  this.scope = scope || this.scope;
package/src/model/data.js CHANGED
@@ -1,36 +1,34 @@
1
1
  // What the functions of the `./model` subpath share: a snapshot from a Model
2
2
  // or as given, and equality of the JSON values a snapshot is made of. A
3
3
  // snapshot is input (a file, a registry, another program), so what it says
4
- // is checked before it is read, and every error is ERR_INVALID_SNAPSHOT
4
+ // is checked before it is read, and every error is ALX_ERR_INVALID_SNAPSHOT
5
5
  // located in the entity, never a bare SyntaxError or TypeError.
6
6
  const { hasBrand, define, isDate, isRegExp } = require('../util.js');
7
7
  const { FORMAT } = require('../snapshot.js');
8
8
  const { SchemaDefinitionError } = require('../errors.js');
9
9
  const { isStruct } = require('../struct.js');
10
+ const { isKindKey } = require('../kinds.js');
10
11
 
11
12
  // How deep the walks over a snapshot go: a definition nested deeper is not
12
13
  // one a program wrote.
13
- const DEPTH = 128;
14
+ const MAX_DEPTH = 128;
14
15
 
15
- const invalidSnapshot = (reason) => new SchemaDefinitionError('ERR_INVALID_SNAPSHOT', reason);
16
+ const invalidSnapshot = (reason, options) =>
17
+ new SchemaDefinitionError(reason, { ...options, code: 'ALX_ERR_INVALID_SNAPSHOT' });
16
18
 
17
- const tooDeep = () => invalidSnapshot(`A snapshot nested deeper than ${DEPTH} levels`);
19
+ const tooDeep = () => invalidSnapshot(`A snapshot nested deeper than ${MAX_DEPTH} levels`);
18
20
 
19
- // An error of a schema as a whole, which has no field to be located at: the
20
- // schema is the location, written as `locate` writes one.
21
- const atSchema = (error, name) => {
22
- error.schema = name;
23
- error.message = `${error.message} in "${name}"`;
24
- return error;
25
- };
21
+ // An error of another kind met while a snapshot is read (a bigint or a
22
+ // pattern that does not read throws its own): an error of the snapshot,
23
+ // with that error as its cause.
24
+ const unreadable = (error) => invalidSnapshot(error.message, { cause: error });
26
25
 
27
26
  const isObject = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
28
27
 
29
- const isSnapshot = (value) =>
30
- isObject(value) &&
31
- value.format === FORMAT &&
32
- isObject(value.entities) &&
33
- (value.types === undefined || isObject(value.types));
28
+ const isSnapshot = (value) => {
29
+ if (!isObject(value) || value.format !== FORMAT || !isObject(value.entities)) return false;
30
+ return value.types === undefined || isObject(value.types);
31
+ };
34
32
 
35
33
  // The entity a snapshot of one schema is about, when it names one: a key
36
34
  // format 1 gained in 3.4, read by nothing else.
@@ -60,7 +58,7 @@ const readSnapshot = (target) => {
60
58
  const same = (a, b, depth = 0) => {
61
59
  if (a === b) return true;
62
60
  if (typeof a !== 'object' || typeof b !== 'object' || a === null || b === null) return false;
63
- if (depth > DEPTH) throw tooDeep();
61
+ if (depth > MAX_DEPTH) throw tooDeep();
64
62
  // By their shape, which a value of JSON cannot fake: `{ constructor: {
65
63
  // name: 'Date' } }` of a snapshot is data.
66
64
  const regExp = isRegExp(a);
@@ -88,6 +86,16 @@ const isFunctionMarker = (value) => isObject(value) && value.$function === true;
88
86
 
89
87
  const capitalize = (name) => name.charAt(0).toUpperCase() + name.slice(1);
90
88
 
89
+ // The key a kind is written under as the first key of a definition (`entity`
90
+ // is `Entity`), null for a name that key would not be read back as a kind
91
+ // from (`dTO`, `api_config`: `isKindKey` of kinds.js): the fields after it
92
+ // would read as something else.
93
+ const kindKeyOf = (kind) => {
94
+ if (typeof kind !== 'string' || kind === '') return null;
95
+ const key = capitalize(kind);
96
+ return isKindKey(key, {}) ? key : null;
97
+ };
98
+
91
99
  // The definition a built field was made from, with its nested fields as
92
100
  // definitions and its functions kept: what `merge` unifies and `Schema`
93
101
  // takes back.
@@ -128,7 +136,12 @@ const metadataOf = (schema) => {
128
136
  // its first key, so the fields after it read as a struct whatever their names.
129
137
  const structDefinition = (base, metadata, fields) => {
130
138
  const { kind = base.kind, ...rest } = { ...base, ...metadata };
131
- const definition = { [capitalize(kind)]: rest };
139
+ const kindKey = kindKeyOf(kind);
140
+ if (kindKey === null) {
141
+ const reason = `Metadata "kind" must be the name of a kind, got ${JSON.stringify(kind)}`;
142
+ throw new SchemaDefinitionError(reason, { code: 'ALX_ERR_INVALID_OPTIONS' });
143
+ }
144
+ const definition = { [kindKey]: rest };
132
145
  for (const key of Object.keys(fields)) define(definition, key, fields[key]);
133
146
  return definition;
134
147
  };
@@ -160,10 +173,10 @@ const namespacesOf = (schemas) => {
160
173
  };
161
174
 
162
175
  module.exports = {
163
- DEPTH,
176
+ MAX_DEPTH,
164
177
  invalidSnapshot,
165
178
  tooDeep,
166
- atSchema,
179
+ unreadable,
167
180
  isObject,
168
181
  isSnapshot,
169
182
  checkRoot,
@@ -171,6 +184,7 @@ module.exports = {
171
184
  same,
172
185
  isFunctionMarker,
173
186
  capitalize,
187
+ kindKeyOf,
174
188
  definitionOf,
175
189
  structDefinitionOf,
176
190
  metadataOf,
package/src/model/diff.js CHANGED
@@ -13,13 +13,28 @@
13
13
  const { SchemaDefinitionError, invalidTarget } = require('../errors.js');
14
14
  const {
15
15
  invalidSnapshot,
16
- atSchema,
16
+ unreadable,
17
17
  isObject,
18
18
  readSnapshot,
19
19
  same,
20
20
  isFunctionMarker,
21
21
  } = require('./data.js');
22
22
 
23
+ const META = ['kind', 'scope', 'store', 'allow', 'parent', 'unknown', 'custom'];
24
+
25
+ // The keys of an entity whose change leaves no reader compatible.
26
+ const INCOMPATIBLE = new Set(['kind', 'store', 'parent', 'type']);
27
+
28
+ // The classes as bits, so that the class of several changes is the AND of
29
+ // theirs: backward and forward make full, either with its opposite makes
30
+ // none.
31
+ const NONE = 0;
32
+ const BACKWARD = 1;
33
+ const FORWARD = 2;
34
+ const FULL = 3;
35
+
36
+ const NAMES = ['none', 'backward', 'forward', 'full'];
37
+
23
38
  const change = (kind, op, entity, name, from, to, detail) => {
24
39
  const entry = { kind, op, entity, name };
25
40
  if (from !== undefined) entry.from = from;
@@ -34,7 +49,9 @@ const own = (object, key) => (Object.hasOwn(object, key) ? object[key] : undefin
34
49
  const keysOf = (a, b) => {
35
50
  const keys = new Set(Object.keys(a));
36
51
  for (const key of Object.keys(b)) keys.add(key);
37
- return Array.from(keys).sort();
52
+ const sorted = Array.from(keys);
53
+ sorted.sort();
54
+ return sorted;
38
55
  };
39
56
 
40
57
  // The keys whose values differ between two objects, sorted.
@@ -136,8 +153,6 @@ const diffRelations = (entity, old, current, changes) => {
136
153
  }
137
154
  };
138
155
 
139
- const META = ['kind', 'scope', 'store', 'allow', 'parent', 'unknown', 'custom'];
140
-
141
156
  // The metadata of an entity; a schema of one type is its type, so a struct
142
157
  // that became one (or back) differs in `type`.
143
158
  const metaOf = (entity) => {
@@ -157,7 +172,7 @@ const isRelations = (list) => {
157
172
  // object: a definition or a function marker) or a `type`, and the relations
158
173
  // as a list of objects, when there.
159
174
  const checkEntity = (entity, name) => {
160
- const fail = (reason) => atSchema(invalidSnapshot(reason), name);
175
+ const fail = (reason) => invalidSnapshot(reason).locate(name, '');
161
176
  if (!isObject(entity)) throw fail('An entity of a snapshot must be an object');
162
177
  const { fields, type, relations = [] } = entity;
163
178
  if (!isObject(fields === undefined ? type : fields) || !isRelations(relations)) {
@@ -205,16 +220,6 @@ const diff = (prev, next) => {
205
220
  return changes;
206
221
  };
207
222
 
208
- // The classes as bits, so that the class of several changes is the AND of
209
- // theirs: backward and forward make full, either with its opposite makes
210
- // none.
211
- const NONE = 0;
212
- const BACKWARD = 1;
213
- const FORWARD = 2;
214
- const FULL = 3;
215
-
216
- const NAMES = ['none', 'backward', 'forward', 'full'];
217
-
218
223
  // A field a reader may do without: an optional one, or one with a default
219
224
  // the reader fills in.
220
225
  const optional = (field) => field.required === false || field.default !== undefined;
@@ -330,7 +335,8 @@ const keyLevel = (key, from, to, field) => {
330
335
  return boundLevel(from, to, false);
331
336
  case 'pattern':
332
337
  case 'format':
333
- return from === undefined ? FORWARD : to === undefined ? BACKWARD : NONE;
338
+ if (from === undefined) return FORWARD;
339
+ return to === undefined ? BACKWARD : NONE;
334
340
  case 'enum':
335
341
  case 'flags':
336
342
  return Array.isArray(from) && Array.isArray(to) ? enumLevel(from, to) : NONE;
@@ -384,7 +390,7 @@ const entityLevel = (entry) => {
384
390
  if (op === 'removed') return BACKWARD;
385
391
  let level = FULL;
386
392
  for (const key of detail.keys) {
387
- if (key === 'kind' || key === 'store' || key === 'parent' || key === 'type') level &= NONE;
393
+ if (INCOMPATIBLE.has(key)) level &= NONE;
388
394
  else if (key === 'unknown') level &= to.unknown === 'ignore' ? BACKWARD : FORWARD;
389
395
  }
390
396
  return level;
@@ -409,11 +415,10 @@ const levelOf = (entry) => {
409
415
 
410
416
  // What a change carries, as `diff` writes it: a kind and an op, and the
411
417
  // keys that differ for `changed`.
412
- const isChange = (entry) =>
413
- isObject(entry) &&
414
- typeof entry.kind === 'string' &&
415
- typeof entry.op === 'string' &&
416
- (entry.op !== 'changed' || Array.isArray(entry.detail?.keys));
418
+ const isChange = (entry) => {
419
+ const named = isObject(entry) && typeof entry.kind === 'string' && typeof entry.op === 'string';
420
+ return named && (entry.op !== 'changed' || Array.isArray(entry.detail?.keys));
421
+ };
417
422
 
418
423
  // The class of a change as bits. Whatever fails while its definitions are
419
424
  // read (a bigint that does not read, a nesting the stack cannot take) is an
@@ -423,7 +428,7 @@ const classOf = (entry) => {
423
428
  try {
424
429
  return levelOf(entry);
425
430
  } catch (error) {
426
- const located = error instanceof SchemaDefinitionError ? error : invalidSnapshot(error.message);
431
+ const located = error instanceof SchemaDefinitionError ? error : unreadable(error);
427
432
  throw located.locate(entry.entity, entry.name);
428
433
  }
429
434
  };
@@ -439,4 +444,4 @@ const compatibility = (changes) => {
439
444
  return NAMES[level];
440
445
  };
441
446
 
442
- module.exports = { diff, compatibility, compatibilityOf };
447
+ module.exports = { diff, compatibilityOf, compatibility };
@@ -12,57 +12,73 @@ import type {
12
12
  SchemaChange,
13
13
  } from '../../index.js';
14
14
 
15
- // The model of a snapshot (`model.toJSON()`), with placeholders for the
16
- // functions, listed by path in `placeholders`; `options.types` brings the
17
- // real custom types, the registry is 'isolated' unless `options.registry`
18
- // says otherwise (a shared one takes no placeholder type). A snapshot that
19
- // does not read is `ERR_INVALID_SNAPSHOT`, located in its entity.
15
+ /**
16
+ * The model of a snapshot (`model.toJSON()`), with placeholders for the
17
+ * functions, listed by path in `placeholders`; `options.types` brings the
18
+ * real custom types, the registry is 'isolated' unless `options.registry`
19
+ * says otherwise (a shared one takes no placeholder type). A snapshot that
20
+ * does not read is `ALX_ERR_INVALID_SNAPSHOT`, located in its entity.
21
+ */
20
22
  export function fromJSON(snapshot: ModelSnapshot, options?: RestoreOptions): RestoredModel;
21
23
 
22
- // The changes from `prev` to `next`, each a Model or a snapshot: the
23
- // entities of `next` in their order (added, or their changes: fields,
24
- // indexes, relations), the entities that are gone, then the types.
24
+ /**
25
+ * The changes from `prev` to `next`, each a Model or a snapshot: the
26
+ * entities of `next` in their order (added, or their changes: fields,
27
+ * indexes, relations), the entities that are gone, then the types.
28
+ */
25
29
  export function diff(prev: Model | ModelSnapshot, next: Model | ModelSnapshot): SchemaChange[];
26
30
 
27
- // The compatibility class of a list of changes by the rules of the Confluent
28
- // Schema Registry: 'backward' when a reader with the new model reads data
29
- // written with the old one, 'forward' the other way, 'full' when both,
30
- // 'none' when neither.
31
+ /**
32
+ * The compatibility class of a list of changes by the rules of the Confluent
33
+ * Schema Registry: 'backward' when a reader with the new model reads data
34
+ * written with the old one, 'forward' the other way, 'full' when both,
35
+ * 'none' when neither.
36
+ */
31
37
  export function compatibility(changes: SchemaChange[]): Compatibility;
32
38
 
33
- // The compatibility class of one change, by the same rules: what to filter
34
- // a list of changes by.
39
+ /**
40
+ * The compatibility class of one change, by the same rules: what to filter
41
+ * a list of changes by.
42
+ */
35
43
  export function compatibilityOf(change: SchemaChange): Compatibility;
36
44
 
37
- // A value the schema accepts, the same for a seed: every field is drawn
38
- // from its definition and verified with its own check. A definition no
39
- // value satisfies is `ERR_UNSATISFIABLE`, a pattern the sampler cannot read
40
- // `ERR_SAMPLE_PATTERN`, a custom type without `metadata.sample`
41
- // `ERR_SAMPLE_TYPE`.
45
+ /**
46
+ * A value the schema accepts, the same for a seed: every field is drawn
47
+ * from its definition and verified with its own check. A definition no
48
+ * value satisfies is `ALX_ERR_UNSATISFIABLE`, a pattern the sampler cannot read
49
+ * `ALX_ERR_SAMPLE_PATTERN`, a custom type without `metadata.sample`
50
+ * `ALX_ERR_SAMPLE_TYPE`.
51
+ */
42
52
  export function sample<D extends string | object>(
43
53
  schema: Schema<D>,
44
54
  options?: SampleOptions,
45
55
  ): Infer<D>;
46
56
 
47
- // The schema both schemas describe, by unification: a field in both takes
48
- // the constraints of both, a field in one comes as it is, and what no value
49
- // can satisfy (two types, two patterns, bounds with nothing in common, two
50
- // defaults) is `ERR_MERGE_CONFLICT` with the field. The kind, its metadata
51
- // and the name are the first schema's unless the options say otherwise.
57
+ /**
58
+ * The schema both schemas describe, by unification: a field in both takes
59
+ * the constraints of both, a field in one comes as it is, and what no value
60
+ * can satisfy (two types, two patterns, bounds with nothing in common, two
61
+ * defaults) is `ALX_ERR_MERGE_CONFLICT` with the field. The kind, its metadata
62
+ * and the name are the first schema's unless the options say otherwise.
63
+ */
52
64
  export function merge(a: Schema, b: Schema, options?: MergeOptions): Schema;
53
65
 
54
- // A definition (or a Schema, with `as: 'schema'`) that accepts every sample:
55
- // the kinds seen at every place, the records of a place fused into one
56
- // struct with optional keys, a string field of few values as an enum,
57
- // records of many sparse keys as a dictionary, whole numbers as `integer`.
58
- // The samples are input: the walk is bounded (`ERR_INFER_DEPTH`), and the
59
- // definition is checked against every sample before it is returned
60
- // (`ERR_INFER_MISMATCH` is a bug to report). An argument that is not a
61
- // non-empty iterable is a `TypeError` with the code `ERR_INVALID_TARGET`.
66
+ /**
67
+ * A definition (or a Schema, with `as: 'schema'`) that accepts every sample:
68
+ * the kinds seen at every place, the records of a place fused into one
69
+ * struct with optional keys, a string field of few values as an enum,
70
+ * records of many sparse keys as a dictionary, whole numbers as `integer`.
71
+ * The samples are input: the walk is bounded (`ALX_ERR_INFER_DEPTH`), and the
72
+ * definition is checked against every sample before it is returned
73
+ * (`ALX_ERR_INFER_MISMATCH` is a bug to report). An argument that is not a
74
+ * non-empty iterable is a `SchemaUsageError` with the code `ALX_ERR_INVALID_TARGET`.
75
+ */
62
76
  export function infer(samples: Iterable<unknown>, options: InferOptions & { as: 'schema' }): Schema;
63
77
  export function infer(samples: Iterable<unknown>, options?: InferOptions): object | string;
64
78
 
65
- // Installs `Model.fromJSON`, `Model.diff`, `Model.compatibility`,
66
- // `Model.compatibilityOf`, `Schema.merge`, `Schema.infer` and
67
- // `schema.sample`. Once per process; later calls do nothing.
79
+ /**
80
+ * Installs `Model.fromJSON`, `Model.diff`, `Model.compatibility`,
81
+ * `Model.compatibilityOf`, `Schema.merge`, `Schema.infer` and
82
+ * `schema.sample`. Once per process; later calls do nothing.
83
+ */
68
84
  export function register(): void;