@atscript/typescript 0.1.108 → 0.1.110
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/dist/cli.cjs +1703 -223
- package/dist/index.cjs +5 -2
- package/dist/index.d.ts +53 -1
- package/dist/index.mjs +3 -3
- package/dist/{json-schema-BtZ_OIcu.mjs → json-schema-B3iAqkGQ.cjs} +1043 -72
- package/dist/{json-schema-BqpH_eYJ.cjs → json-schema-BG1SEcjI.mjs} +742 -155
- package/dist/{plugin-DpfsG4O7.mjs → plugin-DpzE8aJr.mjs} +964 -122
- package/dist/{plugin-Cv2odCwI.cjs → plugin-mzTvme4k.cjs} +975 -121
- package/dist/test-utils.cjs +4 -4
- package/dist/test-utils.d.ts +53 -0
- package/dist/test-utils.mjs +4 -4
- package/dist/utils.cjs +14 -26
- package/dist/utils.d.ts +84 -3
- package/dist/utils.mjs +13 -27
- package/package.json +5 -5
|
@@ -1,3 +1,545 @@
|
|
|
1
|
+
|
|
2
|
+
//#region packages/typescript/src/runtime/validator-keys.ts
|
|
3
|
+
/**
|
|
4
|
+
* Annotation keys the validator pre-check reads, per kind of checked value — shared by the
|
|
5
|
+
* interpreted pre-check (validator-fast-check.ts) and the compiled checks (compiled-check/).
|
|
6
|
+
*/ /** Annotations of a string node, in check order. */ const STRING_KEYS = [
|
|
7
|
+
"meta.required",
|
|
8
|
+
"expect.minLength",
|
|
9
|
+
"expect.maxLength",
|
|
10
|
+
"expect.pattern"
|
|
11
|
+
];
|
|
12
|
+
/** Annotations of a number node, in check order. */ const NUMBER_KEYS = [
|
|
13
|
+
"expect.int",
|
|
14
|
+
"expect.min",
|
|
15
|
+
"expect.max",
|
|
16
|
+
"expect.exclusiveMin",
|
|
17
|
+
"expect.exclusiveMax"
|
|
18
|
+
];
|
|
19
|
+
/** Annotations of a boolean node. */ const BOOLEAN_KEYS = ["meta.required"];
|
|
20
|
+
/** Annotations of an array node, in check order. */ const ARRAY_KEYS = [
|
|
21
|
+
"expect.minLength",
|
|
22
|
+
"expect.maxLength",
|
|
23
|
+
"expect.array.uniqueItems"
|
|
24
|
+
];
|
|
25
|
+
/**
|
|
26
|
+
* Every annotation key the validator pre-check reads. The order is the bit order of
|
|
27
|
+
* compiled-check layouts: changing it changes the layout format.
|
|
28
|
+
*/ const VALIDATOR_KEYS = [
|
|
29
|
+
"meta.required",
|
|
30
|
+
"expect.minLength",
|
|
31
|
+
"expect.maxLength",
|
|
32
|
+
"expect.pattern",
|
|
33
|
+
"expect.int",
|
|
34
|
+
"expect.min",
|
|
35
|
+
"expect.max",
|
|
36
|
+
"expect.exclusiveMin",
|
|
37
|
+
"expect.exclusiveMax",
|
|
38
|
+
"expect.array.uniqueItems"
|
|
39
|
+
];
|
|
40
|
+
/**
|
|
41
|
+
* The number a length / bound annotation compares with: the annotation is either the number
|
|
42
|
+
* itself or an object carrying it in `field` (`{ length }`, `{ minValue }`, …).
|
|
43
|
+
*/ function boundOf(m, field) {
|
|
44
|
+
return typeof m === "number" ? m : m[field];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region packages/typescript/src/runtime/compiled-check/tracking.ts
|
|
49
|
+
/**
|
|
50
|
+
* Mutation tracking for build-time compiled validator checks.
|
|
51
|
+
*
|
|
52
|
+
* A compiled check is bound to the live type tree before use (see registry.ts): the bind
|
|
53
|
+
* verifies that the tree still has the structure the check was compiled for and snapshots
|
|
54
|
+
* the constraint values the check reads. Every tracked mutation of an object a bind has
|
|
55
|
+
* read bumps one global epoch, which makes every compiled check re-bind on its next use.
|
|
56
|
+
*
|
|
57
|
+
* Tracked: `annotate()`, the metadata / props `Map` methods (`set` / `delete` / `clear`),
|
|
58
|
+
* the `defineAnnotatedType()` handle methods and `cloneRefProp()`. Raw property writes
|
|
59
|
+
* (`node.optional = …`, `type.items.push(…)`, editing a constraint object in place, …)
|
|
60
|
+
* cannot be seen: call {@link invalidateCompiledValidators} after them.
|
|
61
|
+
*/ const VALIDATOR_KEY_SET = new Set(VALIDATOR_KEYS);
|
|
62
|
+
/** Global mutation epoch: compiled checks bound in an older epoch re-bind before use. */ let epoch = 0;
|
|
63
|
+
/** Some bind has watched an object (until then no mutation can affect a compiled check). */ let tracking = false;
|
|
64
|
+
/** Objects (nodes, type defs, metadata / props maps) read by some compiled-check bind. */ const watched = /* @__PURE__ */ new WeakSet();
|
|
65
|
+
/** The current mutation epoch. */ function currentEpoch() {
|
|
66
|
+
return epoch;
|
|
67
|
+
}
|
|
68
|
+
/** Marks `obj` as read by a bind: tracked mutations of it invalidate compiled checks. */ function watch(obj) {
|
|
69
|
+
tracking = true;
|
|
70
|
+
watched.add(obj);
|
|
71
|
+
}
|
|
72
|
+
/** Records a tracked mutation of `obj` (a no-op unless some bind has read it). */ function touched(obj) {
|
|
73
|
+
if (tracking && watched.has(obj)) epoch++;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Makes every compiled validator check re-verify the type tree it was compiled for before
|
|
77
|
+
* its next use.
|
|
78
|
+
*
|
|
79
|
+
* Compiled checks (emitted with `tsPlugin({ compileValidators: true })`) see mutations made
|
|
80
|
+
* through `annotate()`, the metadata / props `Map` methods, the `defineAnnotatedType()`
|
|
81
|
+
* handle methods and `cloneRefProp()` automatically. Call this after changing a type tree
|
|
82
|
+
* any other way:
|
|
83
|
+
* - a raw property write: `node.optional = …`, `node.type = …`, `node.metadata = …`,
|
|
84
|
+
* `type.items.push(…)`, `type.of = …`, `type.propsPatterns.push(…)`;
|
|
85
|
+
* - an in-place edit of an annotation value: mutating a constraint object
|
|
86
|
+
* (`metadata.get('expect.min').minValue = 5`), editing or pushing onto an
|
|
87
|
+
* `@expect.pattern` array directly (use `annotate(metadata, key, value, true)` instead).
|
|
88
|
+
*
|
|
89
|
+
* Without it the compiled check may keep validating against the old shape or values.
|
|
90
|
+
* Types without compiled checks are always read live and never need it.
|
|
91
|
+
*
|
|
92
|
+
* Any mutation of a type a compiled check has bound to (tracked or invalidated) makes every
|
|
93
|
+
* compiled check re-bind once on its next use: cheap during startup / configuration, but
|
|
94
|
+
* avoid mutating validated types per request.
|
|
95
|
+
*/ function invalidateCompiledValidators() {
|
|
96
|
+
epoch++;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Metadata map of runtime type nodes: a `Map` whose writes to validator annotation keys
|
|
100
|
+
* are tracked (see {@link invalidateCompiledValidators}). Reads are the builtin ones.
|
|
101
|
+
*/ var AnnotationMap = class extends Map {
|
|
102
|
+
set(key, value) {
|
|
103
|
+
super.set(key, value);
|
|
104
|
+
if (tracking && VALIDATOR_KEY_SET.has(key)) touched(this);
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
delete(key) {
|
|
108
|
+
const deleted = super.delete(key);
|
|
109
|
+
if (deleted && tracking && VALIDATOR_KEY_SET.has(key)) touched(this);
|
|
110
|
+
return deleted;
|
|
111
|
+
}
|
|
112
|
+
clear() {
|
|
113
|
+
super.clear();
|
|
114
|
+
touched(this);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
/** Props map of runtime object types: a `Map` whose writes are tracked. */ var PropsMap = class extends Map {
|
|
118
|
+
set(key, value) {
|
|
119
|
+
super.set(key, value);
|
|
120
|
+
touched(this);
|
|
121
|
+
return this;
|
|
122
|
+
}
|
|
123
|
+
delete(key) {
|
|
124
|
+
const deleted = super.delete(key);
|
|
125
|
+
if (deleted) touched(this);
|
|
126
|
+
return deleted;
|
|
127
|
+
}
|
|
128
|
+
clear() {
|
|
129
|
+
super.clear();
|
|
130
|
+
touched(this);
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
/** `true` when `key` is an annotation the validator pre-check reads. */ function isValidatorKey(key) {
|
|
134
|
+
return VALIDATOR_KEY_SET.has(key);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
//#endregion
|
|
138
|
+
//#region packages/typescript/src/runtime/compiled-check/layout.ts
|
|
139
|
+
/**
|
|
140
|
+
* Layout of a compiled validator check: the structure a check was compiled for, as plain
|
|
141
|
+
* data. `buildLayout` (build-layout.ts) derives it from a type tree (the build-time model
|
|
142
|
+
* of a generated module, or a live tree in tests); the binder (registry.ts) verifies a
|
|
143
|
+
* live tree against it and collects the constraint values the compiled code reads into
|
|
144
|
+
* the K slots.
|
|
145
|
+
*
|
|
146
|
+
* ```
|
|
147
|
+
* Layout = [defs: Def[], root: Site, slotCount]
|
|
148
|
+
* Site = [optional: 0|1, keyMask, def: number | EXT | INTERP, patternShape, slot]
|
|
149
|
+
* Def = [FINAL, designType] | [FINAL, designType, literal]
|
|
150
|
+
* | [OBJECT, keys, sites] | [OBJECT_PATTERNS]
|
|
151
|
+
* | [ARRAY, of] | [UNION | INTERSECTION | TUPLE, items] | [UNKNOWN, kind]
|
|
152
|
+
* ```
|
|
153
|
+
* - A site is one annotated-type node (a class root, prop, array element, union / tuple /
|
|
154
|
+
* intersection item). A def is one type-def object: sites sharing a def index share the
|
|
155
|
+
* def object (by identity) at runtime, which is how shared and recursive types are
|
|
156
|
+
* compiled once.
|
|
157
|
+
* - `keyMask` has a bit (by {@link VALIDATOR_KEYS} index) per validator annotation that is
|
|
158
|
+
* *effective* on the node and relevant to its def (present; flags: truthy).
|
|
159
|
+
* `patternShape` has one char per `@expect.pattern` entry: `e` (empty, skipped),
|
|
160
|
+
* `n` (checked), `s` (stateful `g` / `y` regex: the check bails to the walk there).
|
|
161
|
+
* - `slot`: the site's first K slot (see {@link siteSlotCount}); `slotCount` is the total.
|
|
162
|
+
* - `EXT`: an anonymous reference into another module's type; bound to that type's own
|
|
163
|
+
* compiled check (as a template, against the referring node) when it has one, else
|
|
164
|
+
* checked by the interpreted pre-check.
|
|
165
|
+
* - `INTERP`: a node only known at runtime (e.g. a chained reference into another module's
|
|
166
|
+
* type): always checked by the interpreted pre-check.
|
|
167
|
+
*/
|
|
168
|
+
/** Layout format version; checks of another version are ignored (interpreted). */ const LAYOUT_VERSION = 2;
|
|
169
|
+
const EXT = -1;
|
|
170
|
+
const INTERP = -2;
|
|
171
|
+
const D_FINAL = 0;
|
|
172
|
+
const D_OBJECT = 1;
|
|
173
|
+
const D_ARRAY = 2;
|
|
174
|
+
const D_UNION = 3;
|
|
175
|
+
const D_INTERSECTION = 4;
|
|
176
|
+
const D_TUPLE = 5;
|
|
177
|
+
const D_UNKNOWN = 6;
|
|
178
|
+
const D_OBJECT_PATTERNS = 7;
|
|
179
|
+
/** Def codes of the kinds with `items`, by kind name. */ const ITEMS_KIND_CODES = {
|
|
180
|
+
union: D_UNION,
|
|
181
|
+
intersection: D_INTERSECTION,
|
|
182
|
+
tuple: D_TUPLE
|
|
183
|
+
};
|
|
184
|
+
/** Kind names of the def codes with `items`. */ const ITEMS_KIND_NAMES = {
|
|
185
|
+
[D_UNION]: "union",
|
|
186
|
+
[D_INTERSECTION]: "intersection",
|
|
187
|
+
[D_TUPLE]: "tuple"
|
|
188
|
+
};
|
|
189
|
+
/** Bits of a compiled check's `flags` argument: the pre-check's TOP / IN_UNION, then options. */ const F_TOP = 1;
|
|
190
|
+
const F_IN_UNION = 2;
|
|
191
|
+
const F_ERROR = 4;
|
|
192
|
+
const F_STRIP = 8;
|
|
193
|
+
const F_PARTIAL_DEEP = 16;
|
|
194
|
+
const F_PARTIAL_TOP = 32;
|
|
195
|
+
/** Key mask bit of a validator annotation. */ function bit(key) {
|
|
196
|
+
return 1 << VALIDATOR_KEYS.indexOf(key);
|
|
197
|
+
}
|
|
198
|
+
function bitsOf(keys) {
|
|
199
|
+
let bits = 0;
|
|
200
|
+
for (const key of keys) bits |= bit(key);
|
|
201
|
+
return bits;
|
|
202
|
+
}
|
|
203
|
+
const B_REQUIRED = bit("meta.required");
|
|
204
|
+
const B_MIN_LENGTH = bit("expect.minLength");
|
|
205
|
+
const B_MAX_LENGTH = bit("expect.maxLength");
|
|
206
|
+
const B_PATTERN = bit("expect.pattern");
|
|
207
|
+
const B_INT = bit("expect.int");
|
|
208
|
+
const B_MIN = bit("expect.min");
|
|
209
|
+
const B_MAX = bit("expect.max");
|
|
210
|
+
const B_EX_MIN = bit("expect.exclusiveMin");
|
|
211
|
+
const B_EX_MAX = bit("expect.exclusiveMax");
|
|
212
|
+
const B_UNIQUE = bit("expect.array.uniqueItems");
|
|
213
|
+
/** Annotations the pre-check reads per kind of value (see validator-keys.ts). */ const STRING_BITS = bitsOf(STRING_KEYS);
|
|
214
|
+
const NUMBER_BITS = bitsOf(NUMBER_KEYS);
|
|
215
|
+
const ARRAY_BITS = bitsOf(ARRAY_KEYS);
|
|
216
|
+
const BOOLEAN_BITS = bitsOf(BOOLEAN_KEYS);
|
|
217
|
+
/** Keys whose value the compiled code reads (one K slot each). */ const VALUE_BITS = B_MIN_LENGTH | B_MAX_LENGTH | B_MIN | B_MAX | B_EX_MIN | B_EX_MAX;
|
|
218
|
+
const FLAG_BITS = B_REQUIRED | B_INT | B_UNIQUE;
|
|
219
|
+
const ALL_BITS = (1 << VALIDATOR_KEYS.length) - 1;
|
|
220
|
+
/** The field holding the bound of each value key's object form. */ const BOUND_FIELDS = {
|
|
221
|
+
[B_MIN_LENGTH]: "length",
|
|
222
|
+
[B_MAX_LENGTH]: "length",
|
|
223
|
+
[B_MIN]: "minValue",
|
|
224
|
+
[B_MAX]: "maxValue",
|
|
225
|
+
[B_EX_MIN]: "exclusiveMinValue",
|
|
226
|
+
[B_EX_MAX]: "exclusiveMaxValue"
|
|
227
|
+
};
|
|
228
|
+
/**
|
|
229
|
+
* Validator annotations the pre-check reads for a node of this type def (the rest of the
|
|
230
|
+
* node's annotations cannot change its outcome, so they are not part of the layout).
|
|
231
|
+
*/ function relevantBits(type) {
|
|
232
|
+
switch (type.kind) {
|
|
233
|
+
case "":
|
|
234
|
+
if (type.designType === "phantom" || type.value !== void 0) return 0;
|
|
235
|
+
switch (type.designType) {
|
|
236
|
+
case "string": return STRING_BITS;
|
|
237
|
+
case "number": return NUMBER_BITS;
|
|
238
|
+
case "boolean": return BOOLEAN_BITS;
|
|
239
|
+
default: return 0;
|
|
240
|
+
}
|
|
241
|
+
case "array": return ARRAY_BITS;
|
|
242
|
+
case "union": return ALL_BITS;
|
|
243
|
+
default: return 0;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* {@link relevantBits} of a site (`undefined`: a type only known at runtime);
|
|
248
|
+
* `meta.required` also matters on any optional node.
|
|
249
|
+
*/ function siteBits(type, optional) {
|
|
250
|
+
return (type === void 0 ? 0 : relevantBits(type)) | (optional ? B_REQUIRED : 0);
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Number of K slots a site takes, from its first slot on:
|
|
254
|
+
* - INTERP: its interpreted check, then whether its type is a literal;
|
|
255
|
+
* - otherwise, for an optional `@meta.required` node ({@link hasRejectSlot}): the node
|
|
256
|
+
* (its `null` is rejected unless its type accepts `null`, decided live);
|
|
257
|
+
* - then EXT: the bound check of the referenced type, and whether that type is a literal;
|
|
258
|
+
* any other site: its annotation values (see {@link keySlots}).
|
|
259
|
+
*/ function siteSlotCount(site) {
|
|
260
|
+
const [, mask, def, shape] = site;
|
|
261
|
+
if (def === INTERP) return 2;
|
|
262
|
+
let n = (hasRejectSlot(site) ? 1 : 0) + (def === EXT ? 2 : 0);
|
|
263
|
+
if (def !== EXT) {
|
|
264
|
+
for (let bits = mask & VALUE_BITS; bits !== 0; bits &= bits - 1) n++;
|
|
265
|
+
for (const c of shape) if (c === "n") n++;
|
|
266
|
+
}
|
|
267
|
+
return n;
|
|
268
|
+
}
|
|
269
|
+
/** An optional node with `@meta.required`: `null` fails unless its type accepts `null`. */ function hasRejectSlot(site) {
|
|
270
|
+
return site[0] === 1 && (site[1] & B_REQUIRED) !== 0;
|
|
271
|
+
}
|
|
272
|
+
/** The K slot of each annotation value of a site whose values start at slot `at`. */ function keySlots(mask, shape, at) {
|
|
273
|
+
let k = at;
|
|
274
|
+
const next = (b) => (mask & b) === 0 ? -1 : k++;
|
|
275
|
+
const minLength = next(B_MIN_LENGTH);
|
|
276
|
+
const maxLength = next(B_MAX_LENGTH);
|
|
277
|
+
const patterns = [];
|
|
278
|
+
for (const c of shape) if (c === "n") patterns.push(k++);
|
|
279
|
+
return {
|
|
280
|
+
minLength,
|
|
281
|
+
maxLength,
|
|
282
|
+
patterns,
|
|
283
|
+
min: next(B_MIN),
|
|
284
|
+
max: next(B_MAX),
|
|
285
|
+
exMin: next(B_EX_MIN),
|
|
286
|
+
exMax: next(B_EX_MAX)
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
/** The child sites of a def. */ function childSites(def) {
|
|
290
|
+
switch (def[0]) {
|
|
291
|
+
case D_OBJECT: return def[2];
|
|
292
|
+
case D_ARRAY: return [def[1]];
|
|
293
|
+
case D_UNION:
|
|
294
|
+
case D_INTERSECTION:
|
|
295
|
+
case D_TUPLE: return def[1];
|
|
296
|
+
default: return [];
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Computes a node's key mask and pattern shape over `relevant` bits, and — when `out` is
|
|
301
|
+
* given — writes the normalised annotation values from `out[at]` on (the K slots).
|
|
302
|
+
* Throws on annotation values the pre-check itself would throw on (the bind then fails
|
|
303
|
+
* and the interpreted pre-check runs, which reproduces that behaviour).
|
|
304
|
+
*/ function readKeys(metadata, relevant, reader, out, at = 0) {
|
|
305
|
+
let mask = 0;
|
|
306
|
+
let shape = "";
|
|
307
|
+
let k = at;
|
|
308
|
+
if (metadata.size === 0) return {
|
|
309
|
+
mask,
|
|
310
|
+
shape
|
|
311
|
+
};
|
|
312
|
+
for (let i = 0; i < VALIDATOR_KEYS.length; i++) {
|
|
313
|
+
const b = 1 << i;
|
|
314
|
+
if ((relevant & b) === 0) continue;
|
|
315
|
+
const raw = metadata.get(VALIDATOR_KEYS[i]);
|
|
316
|
+
if ((b & FLAG_BITS) !== 0) {
|
|
317
|
+
if (raw) mask |= b;
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
if (b === B_PATTERN) {
|
|
321
|
+
if (!raw) continue;
|
|
322
|
+
if (!Array.isArray(raw)) throw new TypeError("expect.pattern is not an array");
|
|
323
|
+
mask |= b;
|
|
324
|
+
for (const entry of raw) {
|
|
325
|
+
const { pattern, flags } = entry;
|
|
326
|
+
if (!pattern) {
|
|
327
|
+
shape += "e";
|
|
328
|
+
continue;
|
|
329
|
+
}
|
|
330
|
+
const re = reader.regex(pattern, flags);
|
|
331
|
+
if (re.global || re.sticky) {
|
|
332
|
+
shape += "s";
|
|
333
|
+
break;
|
|
334
|
+
}
|
|
335
|
+
shape += "n";
|
|
336
|
+
if (out) out[k] = re;
|
|
337
|
+
k++;
|
|
338
|
+
}
|
|
339
|
+
continue;
|
|
340
|
+
}
|
|
341
|
+
if (raw === void 0) continue;
|
|
342
|
+
mask |= b;
|
|
343
|
+
if (out) out[k] = boundOf(raw, BOUND_FIELDS[b]);
|
|
344
|
+
k++;
|
|
345
|
+
}
|
|
346
|
+
return {
|
|
347
|
+
mask,
|
|
348
|
+
shape
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
//#endregion
|
|
353
|
+
//#region packages/typescript/src/runtime/compiled-check/registry.ts
|
|
354
|
+
/**
|
|
355
|
+
* Runtime registry and binder of build-time compiled validator checks.
|
|
356
|
+
*
|
|
357
|
+
* Generated `.as.js` modules (built with `tsPlugin({ compileValidators: true })`) call
|
|
358
|
+
* {@link registerCompiledCheck} once per class with the class's layout and a factory of
|
|
359
|
+
* its check. On first use, and again after each mutation epoch (see tracking.ts), the
|
|
360
|
+
* entry is bound: `bindLayout` verifies the live type tree against the layout and collects
|
|
361
|
+
* the constraint values into `K`; the factory turns `K` into the check function. A tree
|
|
362
|
+
* that no longer matches leaves the entry unbound for that epoch, so the interpreted
|
|
363
|
+
* pre-check runs instead — always correct, never stale.
|
|
364
|
+
*
|
|
365
|
+
* A registered entry is also a template: a node referencing a class of another module
|
|
366
|
+
* (an `EXT` site) binds that class's layout against itself — its own annotations feed `K`
|
|
367
|
+
* — so cross-module references, aliases of imported types and cloned imported props run
|
|
368
|
+
* compiled code whenever their tree matches the referenced type's structure.
|
|
369
|
+
*
|
|
370
|
+
* The registry is module-local: classes registered with another copy of this runtime
|
|
371
|
+
* (dual ESM / CJS loads, duplicate installs) and subclasses of registered classes are
|
|
372
|
+
* simply validated by the interpreted pre-check.
|
|
373
|
+
*/
|
|
374
|
+
/** Entries by class (own registrations only: a subclass is not registered). */ const entries = /* @__PURE__ */ new WeakMap();
|
|
375
|
+
/** Template bindings by referring node. */ const templates = /* @__PURE__ */ new WeakMap();
|
|
376
|
+
/** Some compiled check is registered (until then lookups return at once). */ let anyCompiled = false;
|
|
377
|
+
/** The option bits of `opts` for a compiled check's `flags` argument. */ function optionFlags(opts) {
|
|
378
|
+
const unknownProps = opts.unknownProps;
|
|
379
|
+
const partial = opts.partial;
|
|
380
|
+
return (unknownProps === "error" ? F_ERROR : unknownProps === "strip" ? F_STRIP : 0) | (partial === "deep" ? F_PARTIAL_DEEP : partial === true ? F_PARTIAL_TOP : 0);
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Registers the build-time compiled validator check of a generated class (emitted into
|
|
384
|
+
* `.as.js` by `tsPlugin({ compileValidators: true })`; not meant to be called by hand).
|
|
385
|
+
* A layout of another format version is ignored, so the class stays interpreted.
|
|
386
|
+
*/ function registerCompiledCheck(cls, version, layout, factory) {
|
|
387
|
+
if (version !== LAYOUT_VERSION) return;
|
|
388
|
+
entries.set(cls, {
|
|
389
|
+
layout,
|
|
390
|
+
factory,
|
|
391
|
+
epoch: -1,
|
|
392
|
+
fn: null,
|
|
393
|
+
binding: false
|
|
394
|
+
});
|
|
395
|
+
anyCompiled = true;
|
|
396
|
+
}
|
|
397
|
+
let autoCompile = null;
|
|
398
|
+
/** The compiled check to run for `def` in this call, or `null` (interpreted). */ function compiledCheckFor(def, env) {
|
|
399
|
+
if (!anyCompiled) return null;
|
|
400
|
+
let entry = entries.get(def);
|
|
401
|
+
if (entry === void 0) {
|
|
402
|
+
if (autoCompile === null) return null;
|
|
403
|
+
autoCompile(def);
|
|
404
|
+
entry = entries.get(def);
|
|
405
|
+
if (entry === void 0) return null;
|
|
406
|
+
}
|
|
407
|
+
return entry.epoch === currentEpoch() ? entry.fn : bind(entry, entry, def, env, false);
|
|
408
|
+
}
|
|
409
|
+
/** (Re)binds `entry`'s layout against `node` for the current epoch. */ function bind(binding, entry, node, env, template) {
|
|
410
|
+
binding.epoch = currentEpoch();
|
|
411
|
+
binding.fn = null;
|
|
412
|
+
binding.binding = true;
|
|
413
|
+
try {
|
|
414
|
+
const K = bindLayout(entry.layout, node, env, template);
|
|
415
|
+
if (K !== void 0) binding.fn = entry.factory(K, env);
|
|
416
|
+
} catch {} finally {
|
|
417
|
+
binding.binding = false;
|
|
418
|
+
}
|
|
419
|
+
return binding.fn;
|
|
420
|
+
}
|
|
421
|
+
/**
|
|
422
|
+
* Verifies the live tree of `node` against `layout` and collects the K slots; `undefined`
|
|
423
|
+
* when anything differs. A `template` bind (a node referring to the layout's class) leaves
|
|
424
|
+
* the root's `optional` to the referring site.
|
|
425
|
+
*/ function bindLayout(layout, node, env, template) {
|
|
426
|
+
const [defs, root, slotCount] = layout;
|
|
427
|
+
const bound = [];
|
|
428
|
+
const K = [];
|
|
429
|
+
K.length = slotCount;
|
|
430
|
+
/** An EXT / INTERP site: its check, then whether its type is a literal. */ const bindRuntimeSite = (n, at, ext) => {
|
|
431
|
+
const type = n.type;
|
|
432
|
+
if (typeof type !== "object" || type === null || isPhantomType(n)) return false;
|
|
433
|
+
watch(n);
|
|
434
|
+
watch(type);
|
|
435
|
+
K[at] = ext ? externalCheck(n, env) : interpreted(n, env);
|
|
436
|
+
K[at + 1] = type.value !== void 0;
|
|
437
|
+
return true;
|
|
438
|
+
};
|
|
439
|
+
const bindSite = (site, n) => {
|
|
440
|
+
const [optional, mask, d, shape, at] = site;
|
|
441
|
+
if (d === INTERP) return bindRuntimeSite(n, at, false);
|
|
442
|
+
if (template && site === root ? optional !== 0 : !!n.optional !== (optional === 1)) return false;
|
|
443
|
+
watch(n);
|
|
444
|
+
const metadata = n.metadata;
|
|
445
|
+
if (!(metadata instanceof AnnotationMap)) return false;
|
|
446
|
+
watch(metadata);
|
|
447
|
+
let k = at;
|
|
448
|
+
if (hasRejectSlot(site)) K[k++] = n;
|
|
449
|
+
if (d === EXT) return readKeys(metadata, siteBits(void 0, optional === 1), env).mask === mask && bindRuntimeSite(n, k, true);
|
|
450
|
+
const type = n.type;
|
|
451
|
+
if (bound[d] === void 0) {
|
|
452
|
+
if (typeof type !== "object" || type === null) return false;
|
|
453
|
+
bound[d] = type;
|
|
454
|
+
if (!bindDef(defs[d], type)) return false;
|
|
455
|
+
} else if (bound[d] !== type) return false;
|
|
456
|
+
const read = readKeys(metadata, siteBits(type, optional === 1), env, K, k);
|
|
457
|
+
return read.mask === mask && read.shape === shape;
|
|
458
|
+
};
|
|
459
|
+
const bindSites = (sites, nodes) => {
|
|
460
|
+
if (!Array.isArray(nodes) || nodes.length !== sites.length) return false;
|
|
461
|
+
for (let i = 0; i < sites.length; i++) if (!bindSite(sites[i], nodes[i])) return false;
|
|
462
|
+
return true;
|
|
463
|
+
};
|
|
464
|
+
const bindDef = (def, type) => {
|
|
465
|
+
watch(type);
|
|
466
|
+
switch (def[0]) {
|
|
467
|
+
case D_FINAL: return type.kind === "" && type.designType === def[1] && (def.length === 2 ? type.value === void 0 : type.value === def[2]);
|
|
468
|
+
case D_OBJECT: {
|
|
469
|
+
const props = type.props;
|
|
470
|
+
if (type.kind !== "object" || !(props instanceof PropsMap) || !Array.isArray(type.propsPatterns) || type.propsPatterns.length > 0) return false;
|
|
471
|
+
watch(props);
|
|
472
|
+
const keys = def[1];
|
|
473
|
+
const sites = def[2];
|
|
474
|
+
if (props.size !== keys.length) return false;
|
|
475
|
+
let i = 0;
|
|
476
|
+
for (const [key, prop] of props) {
|
|
477
|
+
if (key !== keys[i] || !bindSite(sites[i], prop)) return false;
|
|
478
|
+
i++;
|
|
479
|
+
}
|
|
480
|
+
return true;
|
|
481
|
+
}
|
|
482
|
+
case D_OBJECT_PATTERNS: return type.kind === "object" && Array.isArray(type.propsPatterns) && type.propsPatterns.length > 0;
|
|
483
|
+
case D_ARRAY: return type.kind === "array" && bindSite(def[1], type.of);
|
|
484
|
+
case D_UNION:
|
|
485
|
+
case D_INTERSECTION:
|
|
486
|
+
case D_TUPLE: return type.kind === ITEMS_KIND_NAMES[def[0]] && bindSites(def[1], type.items);
|
|
487
|
+
case D_UNKNOWN: return type.kind === def[1];
|
|
488
|
+
default: return false;
|
|
489
|
+
}
|
|
490
|
+
};
|
|
491
|
+
return bindSite(root, node) ? K : void 0;
|
|
492
|
+
}
|
|
493
|
+
/** The interpreted pre-check of `node` (its subtree is read live on every call). */ function interpreted(node, env) {
|
|
494
|
+
const interp = env.interp;
|
|
495
|
+
return (value, flags, opts) => interp(node, value, flags, opts);
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* The check of a node referencing another module's type (called for a non-nullish value
|
|
499
|
+
* when the node is optional; the referring site handles `optional`): the referenced class's
|
|
500
|
+
* layout bound against the node when it matches, else the interpreted pre-check.
|
|
501
|
+
*/ function externalCheck(node, env) {
|
|
502
|
+
const entry = templateOf(node);
|
|
503
|
+
if (entry !== void 0) {
|
|
504
|
+
let binding = templates.get(node);
|
|
505
|
+
if (binding === void 0 || binding.entry !== entry) {
|
|
506
|
+
binding = {
|
|
507
|
+
entry,
|
|
508
|
+
epoch: -1,
|
|
509
|
+
fn: null,
|
|
510
|
+
binding: false
|
|
511
|
+
};
|
|
512
|
+
templates.set(node, binding);
|
|
513
|
+
}
|
|
514
|
+
if (binding.binding) {
|
|
515
|
+
const pending = binding;
|
|
516
|
+
const fallback = interpreted(node, env);
|
|
517
|
+
return (value, flags, opts) => (pending.fn ?? fallback)(value, flags, opts);
|
|
518
|
+
}
|
|
519
|
+
const fn = binding.epoch === currentEpoch() ? binding.fn : bind(binding, entry, node, env, true);
|
|
520
|
+
if (fn !== null) return fn;
|
|
521
|
+
}
|
|
522
|
+
return interpreted(node, env);
|
|
523
|
+
}
|
|
524
|
+
/**
|
|
525
|
+
* The registered class whose layout a referring node binds against: the target of its
|
|
526
|
+
* (unchained) reference, through aliases of other modules' types.
|
|
527
|
+
*/ function templateOf(node) {
|
|
528
|
+
let ref = node.ref;
|
|
529
|
+
for (let hops = 0; hops < 16 && ref !== void 0 && ref.field === ""; hops++) {
|
|
530
|
+
let target;
|
|
531
|
+
try {
|
|
532
|
+
target = ref.type();
|
|
533
|
+
} catch {
|
|
534
|
+
return;
|
|
535
|
+
}
|
|
536
|
+
const entry = entries.get(target);
|
|
537
|
+
if (entry === void 0 || entry.layout[1][2] !== EXT) return entry;
|
|
538
|
+
ref = target.ref;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
//#endregion
|
|
1
543
|
//#region packages/typescript/src/runtime/validator-fast-check.ts
|
|
2
544
|
function _define_property$1(obj, key, value) {
|
|
3
545
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
@@ -23,31 +565,78 @@ function _define_property$1(obj, key, value) {
|
|
|
23
565
|
* after a validator was created are always honoured — the same as the full walk.
|
|
24
566
|
*
|
|
25
567
|
* Result contract (relative to the full walk over the same node and value):
|
|
26
|
-
* - `PASS` — the walk returns `true`, collects no errors and has no side effects
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
568
|
+
* - `PASS` — the walk returns `true`, collects no errors and has no side effects other
|
|
569
|
+
* than the strips recorded here (see below).
|
|
570
|
+
* - `FAIL` — the walk returns `false`. Inside a union, every node the walk would visit
|
|
571
|
+
* was visited here too (so a walk that would throw makes this throw first) and the
|
|
572
|
+
* walk's only side effects for this node are the strips recorded here. Outside unions
|
|
573
|
+
* a `FAIL` always ends in the walk, so it may be returned early.
|
|
30
574
|
* - `BAIL` — not decidable here; the caller must run the full walk.
|
|
31
575
|
*
|
|
32
576
|
* Union branches are tried in declared order, continuing past `FAIL` and stopping
|
|
33
577
|
* at `BAIL`, which keeps union results identical to the walk.
|
|
578
|
+
*
|
|
579
|
+
* `unknownProps: 'strip'`: the walk deletes an object's unknown keys right after the object
|
|
580
|
+
* passes (even when an ancestor fails later). This check records those deletions only for
|
|
581
|
+
* the top-level object (`pendingKeys`), whose strip is the walk's last read of the input:
|
|
582
|
+
* deferring an earlier strip past later reads could be observed by them (a prototype, a
|
|
583
|
+
* proxy or an accessor over the stripped object), so a nested object with unknown keys
|
|
584
|
+
* bails, as does any object visit once a strip is pending (a later intersection member).
|
|
585
|
+
* The recorded keys are deleted, in the walk's order, only when the whole value passes —
|
|
586
|
+
* so a `PASS` result still has exactly the walk's side effects, and `FAIL` / `BAIL` leave
|
|
587
|
+
* the value untouched for the walk.
|
|
34
588
|
*/ const FAIL = 0;
|
|
35
589
|
const PASS = 1;
|
|
36
590
|
const BAIL = 2;
|
|
37
591
|
/** Node is at walk depth 0 (only object props / array & tuple items increase depth). */ const TOP = 1;
|
|
38
592
|
/** Node is inside a union branch — failures must be exhaustive (see contract). */ const IN_UNION = 2;
|
|
39
593
|
/** Incremented per {@link fastCheckPasses} call; snapshots verified in older calls re-verify. */ let stamp = 0;
|
|
594
|
+
/** A 'strip' {@link fastCheckPasses} call is in progress (the pending strips below are its own). */ let stripping = false;
|
|
595
|
+
/**
|
|
596
|
+
* Unknown keys of the top-level object the walk would delete (`unknownProps: 'strip'`), in
|
|
597
|
+
* the walk's deletion order. Deleted when the call passes, dropped otherwise.
|
|
598
|
+
*/ const pendingKeys = [];
|
|
40
599
|
/**
|
|
41
|
-
* `true` only when the full walk over `value` is guaranteed to pass with no errors
|
|
42
|
-
*
|
|
600
|
+
* `true` only when the full walk over `value` is guaranteed to pass with no errors and
|
|
601
|
+
* no side effects other than its 'strip' deletions, which are then performed here, as the
|
|
602
|
+
* walk would. Any other outcome (including a throw) leaves `value` untouched and means
|
|
603
|
+
* "run the walk".
|
|
43
604
|
*/ function fastCheckPasses(def, value, opts) {
|
|
605
|
+
if (opts.unknownProps === "strip") return fastCheckStripping(def, value, opts);
|
|
44
606
|
stamp++;
|
|
45
607
|
try {
|
|
46
|
-
return
|
|
608
|
+
return check(def, value, opts) === PASS;
|
|
47
609
|
} catch {
|
|
48
610
|
return false;
|
|
49
611
|
}
|
|
50
612
|
}
|
|
613
|
+
/** {@link fastCheckPasses} for `unknownProps: 'strip'`: performs the recorded strips on a pass. */ function fastCheckStripping(def, value, opts) {
|
|
614
|
+
if (stripping) return false;
|
|
615
|
+
stamp++;
|
|
616
|
+
stripping = true;
|
|
617
|
+
let passed;
|
|
618
|
+
try {
|
|
619
|
+
passed = check(def, value, opts) === PASS;
|
|
620
|
+
} catch {
|
|
621
|
+
passed = false;
|
|
622
|
+
} finally {
|
|
623
|
+
stripping = false;
|
|
624
|
+
}
|
|
625
|
+
try {
|
|
626
|
+
if (passed) for (const key of pendingKeys) delete value[key];
|
|
627
|
+
} finally {
|
|
628
|
+
pendingKeys.length = 0;
|
|
629
|
+
}
|
|
630
|
+
return passed;
|
|
631
|
+
}
|
|
632
|
+
/**
|
|
633
|
+
* The pre-check of the root: the type's build-time compiled check when it has one bound to
|
|
634
|
+
* the live tree (see compiled-check/registry.ts), else the interpreted one. Both share the
|
|
635
|
+
* contract above and the strip state.
|
|
636
|
+
*/ function check(def, value, opts) {
|
|
637
|
+
const compiled = compiledCheckFor(def, COMPILED_ENV);
|
|
638
|
+
return compiled === null ? fastCheck(def, value, TOP, opts) : compiled(value, TOP | optionFlags(opts), opts);
|
|
639
|
+
}
|
|
51
640
|
const DECIMAL_RE = /^[+-]?\d+(\.\d+)?$/;
|
|
52
641
|
const regexCache = /* @__PURE__ */ new Map();
|
|
53
642
|
/** Compiled `@expect.pattern` regex, cached per (pattern, flags). */ function getRegex(pattern, flags) {
|
|
@@ -81,6 +670,14 @@ function acceptsNull(def) {
|
|
|
81
670
|
}
|
|
82
671
|
return false;
|
|
83
672
|
}
|
|
673
|
+
/** What compiled checks share with the interpreted pre-check. */ const COMPILED_ENV = {
|
|
674
|
+
pk: pendingKeys,
|
|
675
|
+
ho: Object.prototype.hasOwnProperty,
|
|
676
|
+
dec: DECIMAL_RE,
|
|
677
|
+
regex: getRegex,
|
|
678
|
+
interp: fastCheck,
|
|
679
|
+
rn: rejectsNullAsRequired
|
|
680
|
+
};
|
|
84
681
|
function fastCheck(def, value, flags, opts) {
|
|
85
682
|
if (def.optional && (value === void 0 || value === null)) return value === null && rejectsNullAsRequired(def) ? FAIL : PASS;
|
|
86
683
|
const type = def.type;
|
|
@@ -93,6 +690,7 @@ function fastCheck(def, value, flags, opts) {
|
|
|
93
690
|
for (const item of type.items) {
|
|
94
691
|
const result = fastCheck(item, value, branchFlags, opts);
|
|
95
692
|
if (result !== FAIL) return unionMatchResult(result, item, def.metadata, value);
|
|
693
|
+
if (pendingKeys.length > 0) return BAIL;
|
|
96
694
|
}
|
|
97
695
|
return FAIL;
|
|
98
696
|
}
|
|
@@ -169,15 +767,17 @@ function fastCheckString(metadata, value) {
|
|
|
169
767
|
}
|
|
170
768
|
function fastCheckNumber(metadata, value) {
|
|
171
769
|
if (metadata.size === 0) return PASS;
|
|
172
|
-
return numberConstraints(value, metadata.get("expect.int"), metadata.get("expect.min"), metadata.get("expect.max"));
|
|
770
|
+
return numberConstraints(value, metadata.get("expect.int"), metadata.get("expect.min"), metadata.get("expect.max"), metadata.get("expect.exclusiveMin"), metadata.get("expect.exclusiveMax"));
|
|
173
771
|
}
|
|
174
772
|
function booleanConstraints(value, required) {
|
|
175
773
|
return required && value !== true ? FAIL : PASS;
|
|
176
774
|
}
|
|
177
|
-
function numberConstraints(value, int, min, max) {
|
|
775
|
+
function numberConstraints(value, int, min, max, exMin, exMax) {
|
|
178
776
|
if (int && value % 1 !== 0) return FAIL;
|
|
179
777
|
if (min !== void 0 && value < (typeof min === "number" ? min : min.minValue)) return FAIL;
|
|
180
778
|
if (max !== void 0 && value > (typeof max === "number" ? max : max.maxValue)) return FAIL;
|
|
779
|
+
if (exMin !== void 0 && value <= (typeof exMin === "number" ? exMin : exMin.exclusiveMinValue)) return FAIL;
|
|
780
|
+
if (exMax !== void 0 && value >= (typeof exMax === "number" ? exMax : exMax.exclusiveMaxValue)) return FAIL;
|
|
181
781
|
return PASS;
|
|
182
782
|
}
|
|
183
783
|
/** `@expect.minLength` / `@expect.maxLength` (strings and arrays). */ function lengthFails(length, minLength, maxLength) {
|
|
@@ -191,9 +791,12 @@ function fastCheckObject(def, value, flags, opts) {
|
|
|
191
791
|
if (typeof value !== "object" || value === null || Array.isArray(value)) return FAIL;
|
|
192
792
|
const type = def.type;
|
|
193
793
|
if (type.propsPatterns.length > 0) return BAIL;
|
|
794
|
+
if (pendingKeys.length > 0) return BAIL;
|
|
795
|
+
const unknownProps = opts.unknownProps;
|
|
796
|
+
const inUnion = (flags & IN_UNION) !== 0;
|
|
797
|
+
if (unknownProps === "error" && !inUnion && hasUnknownKey(type.props, value)) return FAIL;
|
|
194
798
|
const partial = opts.partial;
|
|
195
799
|
const skipUndefined = partial === "deep" || partial === true && (flags & TOP) !== 0;
|
|
196
|
-
const inUnion = (flags & IN_UNION) !== 0;
|
|
197
800
|
const propFlags = flags & IN_UNION;
|
|
198
801
|
let result = PASS;
|
|
199
802
|
for (const [key, item] of type.props) {
|
|
@@ -207,16 +810,28 @@ function fastCheckObject(def, value, flags, opts) {
|
|
|
207
810
|
}
|
|
208
811
|
}
|
|
209
812
|
if (result !== PASS) return result;
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
813
|
+
if (unknownProps === "strip") return pendStrips(type.props, value, flags);
|
|
814
|
+
return unknownProps === "error" && inUnion && hasUnknownKey(type.props, value) ? FAIL : PASS;
|
|
815
|
+
}
|
|
816
|
+
/**
|
|
817
|
+
* Records the unknown keys of a passing top-level object: the walk deletes them at this
|
|
818
|
+
* point, after its last read of the input. A nested object's strip would be followed by
|
|
819
|
+
* more reads, so it is left to the walk.
|
|
820
|
+
*/ function pendStrips(props, value, flags) {
|
|
821
|
+
for (const key of Object.keys(value)) if (isUnknownKey(props, key)) {
|
|
822
|
+
if ((flags & TOP) === 0) return BAIL;
|
|
823
|
+
pendingKeys.push(key);
|
|
217
824
|
}
|
|
218
825
|
return PASS;
|
|
219
826
|
}
|
|
827
|
+
/** `true` when `value` has a key the walk treats as unknown. */ function hasUnknownKey(props, value) {
|
|
828
|
+
for (const key of Object.keys(value)) if (isUnknownKey(props, key)) return true;
|
|
829
|
+
return false;
|
|
830
|
+
}
|
|
831
|
+
/** `true` when the walk treats `key` as unknown (no prop, or a phantom one). */ function isUnknownKey(props, key) {
|
|
832
|
+
const known = props.get(key);
|
|
833
|
+
return known === void 0 || isPhantomType(known);
|
|
834
|
+
}
|
|
220
835
|
function fastCheckArray(def, value, flags, opts) {
|
|
221
836
|
if (!Array.isArray(value)) return FAIL;
|
|
222
837
|
const metadata = def.metadata;
|
|
@@ -260,7 +875,7 @@ const plans = /* @__PURE__ */ new WeakMap();
|
|
|
260
875
|
constructor(def) {
|
|
261
876
|
_define_property$1(this, "def", void 0);
|
|
262
877
|
/** Call in which the node structure was last verified (`-1`: must rebuild). */ _define_property$1(this, "stamp", void 0);
|
|
263
|
-
/** Call in which the annotation values (`m0`–`
|
|
878
|
+
/** Call in which the annotation values (`m0`–`m4`) were last verified. */ _define_property$1(this, "metaStamp", void 0);
|
|
264
879
|
_define_property$1(this, "op", void 0);
|
|
265
880
|
_define_property$1(this, "type", void 0);
|
|
266
881
|
_define_property$1(this, "optional", void 0);
|
|
@@ -272,15 +887,17 @@ const plans = /* @__PURE__ */ new WeakMap();
|
|
|
272
887
|
/**
|
|
273
888
|
* Annotation keys the node's check reads, and their values (`undefined` when absent):
|
|
274
889
|
* string `meta.required, expect.minLength, maxLength, pattern`; number `expect.int, min,
|
|
275
|
-
* max`; boolean `meta.required`; array `expect.minLength, maxLength, array.uniqueItems`.
|
|
890
|
+
* max, exclusiveMin, exclusiveMax`; boolean `meta.required`; array `expect.minLength, maxLength, array.uniqueItems`.
|
|
276
891
|
*/ _define_property$1(this, "k0", void 0);
|
|
277
892
|
_define_property$1(this, "k1", void 0);
|
|
278
893
|
_define_property$1(this, "k2", void 0);
|
|
279
894
|
_define_property$1(this, "k3", void 0);
|
|
895
|
+
_define_property$1(this, "k4", void 0);
|
|
280
896
|
_define_property$1(this, "m0", void 0);
|
|
281
897
|
_define_property$1(this, "m1", void 0);
|
|
282
898
|
_define_property$1(this, "m2", void 0);
|
|
283
899
|
_define_property$1(this, "m3", void 0);
|
|
900
|
+
_define_property$1(this, "m4", void 0);
|
|
284
901
|
_define_property$1(this, "props", void 0);
|
|
285
902
|
_define_property$1(this, "propsPatterns", void 0);
|
|
286
903
|
_define_property$1(this, "keys", void 0);
|
|
@@ -306,10 +923,12 @@ const plans = /* @__PURE__ */ new WeakMap();
|
|
|
306
923
|
this.k1 = void 0;
|
|
307
924
|
this.k2 = void 0;
|
|
308
925
|
this.k3 = void 0;
|
|
926
|
+
this.k4 = void 0;
|
|
309
927
|
this.m0 = void 0;
|
|
310
928
|
this.m1 = void 0;
|
|
311
929
|
this.m2 = void 0;
|
|
312
930
|
this.m3 = void 0;
|
|
931
|
+
this.m4 = void 0;
|
|
313
932
|
this.props = void 0;
|
|
314
933
|
this.propsPatterns = void 0;
|
|
315
934
|
this.keys = EMPTY;
|
|
@@ -359,7 +978,7 @@ function planFor(def) {
|
|
|
359
978
|
}
|
|
360
979
|
/** Brings the annotation values up to date (once per call, when a constraint is read). */ function refreshMeta(plan) {
|
|
361
980
|
const metadata = plan.metadata;
|
|
362
|
-
if (!(metadata.size === 0 ? plan.m0 === void 0 && plan.m1 === void 0 && plan.m2 === void 0 && plan.m3 === void 0 : metadata.get(plan.k0) === plan.m0 && (plan.k1 === void 0 || metadata.get(plan.k1) === plan.m1) && (plan.k2 === void 0 || metadata.get(plan.k2) === plan.m2) && (plan.k3 === void 0 || metadata.get(plan.k3) === plan.m3))) snapshotMeta(plan);
|
|
981
|
+
if (!(metadata.size === 0 ? plan.m0 === void 0 && plan.m1 === void 0 && plan.m2 === void 0 && plan.m3 === void 0 && plan.m4 === void 0 : metadata.get(plan.k0) === plan.m0 && (plan.k1 === void 0 || metadata.get(plan.k1) === plan.m1) && (plan.k2 === void 0 || metadata.get(plan.k2) === plan.m2) && (plan.k3 === void 0 || metadata.get(plan.k3) === plan.m3) && (plan.k4 === void 0 || metadata.get(plan.k4) === plan.m4))) snapshotMeta(plan);
|
|
363
982
|
plan.metaStamp = stamp;
|
|
364
983
|
}
|
|
365
984
|
function snapshotMeta(plan) {
|
|
@@ -368,12 +987,14 @@ function snapshotMeta(plan) {
|
|
|
368
987
|
plan.m1 = metadata.get(plan.k1);
|
|
369
988
|
plan.m2 = metadata.get(plan.k2);
|
|
370
989
|
plan.m3 = metadata.get(plan.k3);
|
|
990
|
+
plan.m4 = metadata.get(plan.k4);
|
|
371
991
|
}
|
|
372
|
-
function setMetaKeys(plan, k0, k1, k2, k3) {
|
|
992
|
+
function setMetaKeys(plan, k0, k1, k2, k3, k4) {
|
|
373
993
|
plan.k0 = k0;
|
|
374
994
|
plan.k1 = k1;
|
|
375
995
|
plan.k2 = k2;
|
|
376
996
|
plan.k3 = k3;
|
|
997
|
+
plan.k4 = k4;
|
|
377
998
|
snapshotMeta(plan);
|
|
378
999
|
plan.metaStamp = stamp;
|
|
379
1000
|
}
|
|
@@ -399,20 +1020,20 @@ function setMetaKeys(plan, k0, k1, k2, k3) {
|
|
|
399
1020
|
plan.of = void 0;
|
|
400
1021
|
plan.ofPlan = void 0;
|
|
401
1022
|
plan.items = void 0;
|
|
402
|
-
setMetaKeys(plan
|
|
1023
|
+
setMetaKeys(plan);
|
|
403
1024
|
switch (type.kind) {
|
|
404
1025
|
case "":
|
|
405
1026
|
if (type.designType === "phantom") plan.op = OP_PHANTOM;
|
|
406
1027
|
else if (type.value !== void 0) plan.op = OP_FINAL;
|
|
407
1028
|
else if (type.designType === "string") {
|
|
408
|
-
setMetaKeys(plan,
|
|
1029
|
+
setMetaKeys(plan, ...STRING_KEYS);
|
|
409
1030
|
plan.regexes = [];
|
|
410
1031
|
plan.op = OP_STRING;
|
|
411
1032
|
} else if (type.designType === "number") {
|
|
412
|
-
setMetaKeys(plan,
|
|
1033
|
+
setMetaKeys(plan, ...NUMBER_KEYS);
|
|
413
1034
|
plan.op = OP_NUMBER;
|
|
414
1035
|
} else if (type.designType === "boolean") {
|
|
415
|
-
setMetaKeys(plan,
|
|
1036
|
+
setMetaKeys(plan, ...BOOLEAN_KEYS);
|
|
416
1037
|
plan.op = OP_BOOLEAN;
|
|
417
1038
|
} else plan.op = OP_FINAL;
|
|
418
1039
|
break;
|
|
@@ -438,7 +1059,7 @@ function setMetaKeys(plan, k0, k1, k2, k3) {
|
|
|
438
1059
|
break;
|
|
439
1060
|
}
|
|
440
1061
|
case "array":
|
|
441
|
-
setMetaKeys(plan,
|
|
1062
|
+
setMetaKeys(plan, ...ARRAY_KEYS);
|
|
442
1063
|
plan.of = type.of;
|
|
443
1064
|
plan.ofPlan = planFor(type.of);
|
|
444
1065
|
plan.op = OP_ARRAY;
|
|
@@ -510,7 +1131,7 @@ function setMetaKeys(plan, k0, k1, k2, k3) {
|
|
|
510
1131
|
}
|
|
511
1132
|
/** Plan counterpart of {@link fastCheckNumber}; constraint objects are read live. */ function checkNumber(plan, value) {
|
|
512
1133
|
if (plan.metaStamp !== stamp) refreshMeta(plan);
|
|
513
|
-
return numberConstraints(value, plan.m0, plan.m1, plan.m2);
|
|
1134
|
+
return numberConstraints(value, plan.m0, plan.m1, plan.m2, plan.m3, plan.m4);
|
|
514
1135
|
}
|
|
515
1136
|
/** Plan counterpart of {@link fastCheckObject}. */ function checkObject(plan, value, flags, opts) {
|
|
516
1137
|
if (typeof value !== "object" || value === null || Array.isArray(value)) return FAIL;
|
|
@@ -1024,7 +1645,7 @@ function _define_property(obj, key, value) {
|
|
|
1024
1645
|
validateNumber(def, value) {
|
|
1025
1646
|
return this.validateNumberConstraints(def.metadata, value);
|
|
1026
1647
|
}
|
|
1027
|
-
/** `@expect.int` / `min` / `max` checks for a number value. */ validateNumberConstraints(metadata, value) {
|
|
1648
|
+
/** `@expect.int` / `min` / `max` / `exclusiveMin` / `exclusiveMax` checks for a number value. */ validateNumberConstraints(metadata, value) {
|
|
1028
1649
|
if (metadata.size === 0) return true;
|
|
1029
1650
|
const int = metadata.get("expect.int");
|
|
1030
1651
|
if (int && value % 1 !== 0) {
|
|
@@ -1035,23 +1656,30 @@ function _define_property(obj, key, value) {
|
|
|
1035
1656
|
const min = metadata.get("expect.min");
|
|
1036
1657
|
if (min !== void 0) {
|
|
1037
1658
|
const minValue = typeof min === "number" ? min : min.minValue;
|
|
1038
|
-
if (value < minValue)
|
|
1039
|
-
const message = typeof min === "object" && min.message ? min.message : `Expected minimum ${minValue}, got ${value}`;
|
|
1040
|
-
this.error(message);
|
|
1041
|
-
return false;
|
|
1042
|
-
}
|
|
1659
|
+
if (value < minValue) return this.numberBoundFailed(min, "minimum", minValue, value);
|
|
1043
1660
|
}
|
|
1044
1661
|
const max = metadata.get("expect.max");
|
|
1045
1662
|
if (max !== void 0) {
|
|
1046
1663
|
const maxValue = typeof max === "number" ? max : max.maxValue;
|
|
1047
|
-
if (value > maxValue)
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1664
|
+
if (value > maxValue) return this.numberBoundFailed(max, "maximum", maxValue, value);
|
|
1665
|
+
}
|
|
1666
|
+
const exMin = metadata.get("expect.exclusiveMin");
|
|
1667
|
+
if (exMin !== void 0) {
|
|
1668
|
+
const bound = typeof exMin === "number" ? exMin : exMin.exclusiveMinValue;
|
|
1669
|
+
if (value <= bound) return this.numberBoundFailed(exMin, "greater than", bound, value);
|
|
1670
|
+
}
|
|
1671
|
+
const exMax = metadata.get("expect.exclusiveMax");
|
|
1672
|
+
if (exMax !== void 0) {
|
|
1673
|
+
const bound = typeof exMax === "number" ? exMax : exMax.exclusiveMaxValue;
|
|
1674
|
+
if (value >= bound) return this.numberBoundFailed(exMax, "less than", bound, value);
|
|
1052
1675
|
}
|
|
1053
1676
|
return true;
|
|
1054
1677
|
}
|
|
1678
|
+
/** Reports a failed number bound: its custom message, else `Expected <label> <bound>, got <value>`. */ numberBoundFailed(annotation, label, bound, value) {
|
|
1679
|
+
const message = typeof annotation === "object" && annotation.message ? annotation.message : `Expected ${label} ${bound}, got ${value}`;
|
|
1680
|
+
this.error(message);
|
|
1681
|
+
return false;
|
|
1682
|
+
}
|
|
1055
1683
|
validateBoolean(def, value) {
|
|
1056
1684
|
return this.validateBooleanConstraints(def.metadata, value);
|
|
1057
1685
|
}
|
|
@@ -1141,7 +1769,12 @@ const NON_PRIMITIVE_KINDS = new Set(["array", "object"]);
|
|
|
1141
1769
|
/**
|
|
1142
1770
|
* Creates a minimal annotated type node from a type def and metadata map.
|
|
1143
1771
|
* Centralises the shape so callers never duplicate the boilerplate.
|
|
1144
|
-
|
|
1772
|
+
*
|
|
1773
|
+
* `metadata` is used as-is (the node keeps the caller's map, so later writes through it
|
|
1774
|
+
* apply). When omitted, the node gets a new, tracked metadata map. Compiled validator
|
|
1775
|
+
* checks only bind to nodes whose metadata is tracked; nodes built over a caller-supplied
|
|
1776
|
+
* `Map` are always validated by the interpreted validator.
|
|
1777
|
+
*/ function createAnnotatedTypeNode(type, metadata = new AnnotationMap(), opts) {
|
|
1145
1778
|
return {
|
|
1146
1779
|
__is_atscript_annotated_type: true,
|
|
1147
1780
|
type,
|
|
@@ -1152,6 +1785,26 @@ const NON_PRIMITIVE_KINDS = new Set(["array", "object"]);
|
|
|
1152
1785
|
ref: opts?.ref
|
|
1153
1786
|
};
|
|
1154
1787
|
}
|
|
1788
|
+
/** A new tracked metadata map holding `entries` (see {@link createAnnotatedTypeNode}). */ function createMetadataMap(entries) {
|
|
1789
|
+
return new AnnotationMap(entries);
|
|
1790
|
+
}
|
|
1791
|
+
/**
|
|
1792
|
+
* The metadata map `defineAnnotatedType()` installs on `base`: `base.metadata` itself, except
|
|
1793
|
+
* that an absent map or an empty plain `Map` (what a generated class starts with:
|
|
1794
|
+
* `static metadata = new Map()`) is replaced by a new tracked map, so the node can bind to a
|
|
1795
|
+
* compiled validator check. A non-empty map or a `Map` subclass is always kept as-is (its
|
|
1796
|
+
* identity and overrides preserved; such a node stays interpreted).
|
|
1797
|
+
*/ function baseMetadata(metadata) {
|
|
1798
|
+
return !metadata || Object.getPrototypeOf(metadata) === Map.prototype && metadata.size === 0 ? createMetadataMap() : metadata;
|
|
1799
|
+
}
|
|
1800
|
+
/** A new object type def (its props map is tracked, see {@link createAnnotatedTypeNode}). */ function createObjectTypeDef(tags = /* @__PURE__ */ new Set(), propsPatterns = []) {
|
|
1801
|
+
return {
|
|
1802
|
+
kind: "object",
|
|
1803
|
+
props: new PropsMap(),
|
|
1804
|
+
propsPatterns,
|
|
1805
|
+
tags
|
|
1806
|
+
};
|
|
1807
|
+
}
|
|
1155
1808
|
/**
|
|
1156
1809
|
* Type Guard to check if a type is atscript-annotated
|
|
1157
1810
|
*/ function isAnnotatedType(type) {
|
|
@@ -1164,8 +1817,10 @@ const NON_PRIMITIVE_KINDS = new Set(["array", "object"]);
|
|
|
1164
1817
|
if (!metadata) return;
|
|
1165
1818
|
if (asArray) if (metadata.has(key)) {
|
|
1166
1819
|
const a = metadata.get(key);
|
|
1167
|
-
if (Array.isArray(a))
|
|
1168
|
-
|
|
1820
|
+
if (Array.isArray(a)) {
|
|
1821
|
+
a.push(value);
|
|
1822
|
+
if (isValidatorKey(key)) touched(metadata);
|
|
1823
|
+
} else metadata.set(key, [a, value]);
|
|
1169
1824
|
} else metadata.set(key, [value]);
|
|
1170
1825
|
else metadata.set(key, value);
|
|
1171
1826
|
}
|
|
@@ -1177,28 +1832,21 @@ const NON_PRIMITIVE_KINDS = new Set(["array", "object"]);
|
|
|
1177
1832
|
const objType = parentType;
|
|
1178
1833
|
const existing = objType.props.get(propName);
|
|
1179
1834
|
if (!existing) return;
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1835
|
+
objType.props.set(propName, cloneNode(existing, cloneTypeDef(existing.type)));
|
|
1836
|
+
}
|
|
1837
|
+
/** A copy of `node` (own metadata map) over `type`. */ function cloneNode(node, type) {
|
|
1838
|
+
return createAnnotatedTypeNode(type, createMetadataMap(node.metadata), {
|
|
1839
|
+
id: node.id,
|
|
1840
|
+
optional: node.optional,
|
|
1841
|
+
ref: node.ref
|
|
1842
|
+
});
|
|
1186
1843
|
}
|
|
1187
1844
|
function cloneTypeDef(type) {
|
|
1188
1845
|
if (type.kind === "object") {
|
|
1189
1846
|
const obj = type;
|
|
1190
|
-
const
|
|
1191
|
-
for (const [k, v] of obj.props) props.set(k,
|
|
1192
|
-
|
|
1193
|
-
optional: v.optional,
|
|
1194
|
-
ref: v.ref
|
|
1195
|
-
}));
|
|
1196
|
-
return {
|
|
1197
|
-
kind: "object",
|
|
1198
|
-
props,
|
|
1199
|
-
propsPatterns: [...obj.propsPatterns],
|
|
1200
|
-
tags: new Set(obj.tags)
|
|
1201
|
-
};
|
|
1847
|
+
const clone = createObjectTypeDef(new Set(obj.tags), [...obj.propsPatterns]);
|
|
1848
|
+
for (const [k, v] of obj.props) clone.props.set(k, cloneNode(v, v.type));
|
|
1849
|
+
return clone;
|
|
1202
1850
|
}
|
|
1203
1851
|
if (type.kind === "array") {
|
|
1204
1852
|
const arr = type;
|
|
@@ -1243,14 +1891,15 @@ function cloneTypeDef(type) {
|
|
|
1243
1891
|
const kind = _kind || "";
|
|
1244
1892
|
const baseProvided = base !== void 0;
|
|
1245
1893
|
const type = base?.type || {};
|
|
1894
|
+
touched(type);
|
|
1246
1895
|
type.kind = kind;
|
|
1247
1896
|
if (COMPLEX_KINDS.has(kind)) type.items = [];
|
|
1248
1897
|
if (kind === "object") {
|
|
1249
|
-
type.props =
|
|
1898
|
+
type.props = new PropsMap();
|
|
1250
1899
|
type.propsPatterns = [];
|
|
1251
1900
|
}
|
|
1252
1901
|
type.tags = /* @__PURE__ */ new Set();
|
|
1253
|
-
const metadata = base?.metadata
|
|
1902
|
+
const metadata = baseMetadata(base?.metadata);
|
|
1254
1903
|
const payload = {
|
|
1255
1904
|
__is_atscript_annotated_type: true,
|
|
1256
1905
|
metadata,
|
|
@@ -1268,18 +1917,22 @@ function cloneTypeDef(type) {
|
|
|
1268
1917
|
},
|
|
1269
1918
|
designType(value) {
|
|
1270
1919
|
this.$def.designType = value;
|
|
1920
|
+
touched(this.$def);
|
|
1271
1921
|
return this;
|
|
1272
1922
|
},
|
|
1273
1923
|
value(value) {
|
|
1274
1924
|
this.$def.value = value;
|
|
1925
|
+
touched(this.$def);
|
|
1275
1926
|
return this;
|
|
1276
1927
|
},
|
|
1277
1928
|
of(value) {
|
|
1278
1929
|
this.$def.of = value;
|
|
1930
|
+
touched(this.$def);
|
|
1279
1931
|
return this;
|
|
1280
1932
|
},
|
|
1281
1933
|
item(value) {
|
|
1282
1934
|
this.$def.items.push(value);
|
|
1935
|
+
touched(this.$def);
|
|
1283
1936
|
return this;
|
|
1284
1937
|
},
|
|
1285
1938
|
prop(name, value) {
|
|
@@ -1291,10 +1944,12 @@ function cloneTypeDef(type) {
|
|
|
1291
1944
|
pattern,
|
|
1292
1945
|
def
|
|
1293
1946
|
});
|
|
1947
|
+
touched(this.$def);
|
|
1294
1948
|
return this;
|
|
1295
1949
|
},
|
|
1296
1950
|
optional(value = true) {
|
|
1297
1951
|
this.$type.optional = value;
|
|
1952
|
+
touched(this.$type);
|
|
1298
1953
|
return this;
|
|
1299
1954
|
},
|
|
1300
1955
|
copyMetadata(fromMetadata, ignore) {
|
|
@@ -1303,6 +1958,7 @@ function cloneTypeDef(type) {
|
|
|
1303
1958
|
},
|
|
1304
1959
|
refTo(type, chain) {
|
|
1305
1960
|
const node = this.$type;
|
|
1961
|
+
touched(node);
|
|
1306
1962
|
const field = chain ? chain.join(".") : "";
|
|
1307
1963
|
if (isAnnotatedType(type)) {
|
|
1308
1964
|
let newBase = type;
|
|
@@ -1574,36 +2230,42 @@ function cloneTypeDef(type) {
|
|
|
1574
2230
|
}
|
|
1575
2231
|
/** `@expect.minLength` / `maxLength` → `minItems` / `maxItems` on an array schema. */ function applyArrayConstraints(schema, meta) {
|
|
1576
2232
|
const minLength = meta.get("expect.minLength");
|
|
1577
|
-
if (minLength !== void 0) schema.minItems =
|
|
2233
|
+
if (minLength !== void 0) schema.minItems = boundOf(minLength, "length");
|
|
1578
2234
|
const maxLength = meta.get("expect.maxLength");
|
|
1579
|
-
if (maxLength !== void 0) schema.maxItems =
|
|
2235
|
+
if (maxLength !== void 0) schema.maxItems = boundOf(maxLength, "length");
|
|
1580
2236
|
}
|
|
1581
2237
|
/** String / number constraints on a scalar schema whose `type` is already set. */ function applyScalarConstraints(schema, meta) {
|
|
1582
2238
|
if (schema.type === "number" && meta.get("expect.int")) schema.type = "integer";
|
|
1583
2239
|
if (schema.type === "string") {
|
|
1584
2240
|
if (meta.get("meta.required")) schema.minLength = 1;
|
|
1585
2241
|
const minLength = meta.get("expect.minLength");
|
|
1586
|
-
if (minLength !== void 0) schema.minLength =
|
|
2242
|
+
if (minLength !== void 0) schema.minLength = boundOf(minLength, "length");
|
|
1587
2243
|
const maxLength = meta.get("expect.maxLength");
|
|
1588
|
-
if (maxLength !== void 0) schema.maxLength =
|
|
2244
|
+
if (maxLength !== void 0) schema.maxLength = boundOf(maxLength, "length");
|
|
1589
2245
|
const patterns = meta.get("expect.pattern");
|
|
1590
2246
|
if (patterns?.length) if (patterns.length === 1) schema.pattern = patterns[0].pattern;
|
|
1591
2247
|
else schema.allOf = (schema.allOf || []).concat(patterns.map((p) => ({ pattern: p.pattern })));
|
|
1592
2248
|
}
|
|
1593
2249
|
if (schema.type === "number" || schema.type === "integer") {
|
|
1594
2250
|
const min = meta.get("expect.min");
|
|
1595
|
-
if (min !== void 0) schema.minimum =
|
|
2251
|
+
if (min !== void 0) schema.minimum = boundOf(min, "minValue");
|
|
1596
2252
|
const max = meta.get("expect.max");
|
|
1597
|
-
if (max !== void 0) schema.maximum =
|
|
2253
|
+
if (max !== void 0) schema.maximum = boundOf(max, "maxValue");
|
|
2254
|
+
const exMin = meta.get("expect.exclusiveMin");
|
|
2255
|
+
if (exMin !== void 0) schema.exclusiveMinimum = boundOf(exMin, "exclusiveMinValue");
|
|
2256
|
+
const exMax = meta.get("expect.exclusiveMax");
|
|
2257
|
+
if (exMax !== void 0) schema.exclusiveMaximum = boundOf(exMax, "exclusiveMaxValue");
|
|
1598
2258
|
}
|
|
1599
2259
|
}
|
|
1600
2260
|
const LOWER_BOUNDS = new Set([
|
|
1601
2261
|
"minimum",
|
|
2262
|
+
"exclusiveMinimum",
|
|
1602
2263
|
"minLength",
|
|
1603
2264
|
"minItems"
|
|
1604
2265
|
]);
|
|
1605
2266
|
const UPPER_BOUNDS = new Set([
|
|
1606
2267
|
"maximum",
|
|
2268
|
+
"exclusiveMaximum",
|
|
1607
2269
|
"maxLength",
|
|
1608
2270
|
"maxItems"
|
|
1609
2271
|
]);
|
|
@@ -1743,14 +2405,12 @@ const UPPER_BOUNDS = new Set([
|
|
|
1743
2405
|
if (s.type === "integer") {
|
|
1744
2406
|
const handle = defineAnnotatedType().designType("number").tags("number");
|
|
1745
2407
|
handle.annotate("expect.int", true);
|
|
1746
|
-
|
|
1747
|
-
if (typeof s.maximum === "number") handle.annotate("expect.max", { maxValue: s.maximum });
|
|
2408
|
+
annotateNumberBounds(handle, s);
|
|
1748
2409
|
return handle.$type;
|
|
1749
2410
|
}
|
|
1750
2411
|
if (s.type === "number") {
|
|
1751
2412
|
const handle = defineAnnotatedType().designType("number").tags("number");
|
|
1752
|
-
|
|
1753
|
-
if (typeof s.maximum === "number") handle.annotate("expect.max", { maxValue: s.maximum });
|
|
2413
|
+
annotateNumberBounds(handle, s);
|
|
1754
2414
|
return handle.$type;
|
|
1755
2415
|
}
|
|
1756
2416
|
if (s.type === "boolean") return defineAnnotatedType().designType("boolean").tags("boolean").$type;
|
|
@@ -1760,6 +2420,18 @@ const UPPER_BOUNDS = new Set([
|
|
|
1760
2420
|
return convert(schema);
|
|
1761
2421
|
}
|
|
1762
2422
|
/**
|
|
2423
|
+
* Maps `minimum` / `maximum` / `exclusiveMinimum` / `exclusiveMaximum` onto
|
|
2424
|
+
* `@expect.min` / `max` / `exclusiveMin` / `exclusiveMax`. Also reads the draft-4 form,
|
|
2425
|
+
* where `exclusiveMinimum: true` makes `minimum` exclusive.
|
|
2426
|
+
*/ function annotateNumberBounds(handle, s) {
|
|
2427
|
+
if (typeof s.minimum === "number") if (s.exclusiveMinimum === true) handle.annotate("expect.exclusiveMin", { exclusiveMinValue: s.minimum });
|
|
2428
|
+
else handle.annotate("expect.min", { minValue: s.minimum });
|
|
2429
|
+
if (typeof s.maximum === "number") if (s.exclusiveMaximum === true) handle.annotate("expect.exclusiveMax", { exclusiveMaxValue: s.maximum });
|
|
2430
|
+
else handle.annotate("expect.max", { maxValue: s.maximum });
|
|
2431
|
+
if (typeof s.exclusiveMinimum === "number") handle.annotate("expect.exclusiveMin", { exclusiveMinValue: s.exclusiveMinimum });
|
|
2432
|
+
if (typeof s.exclusiveMaximum === "number") handle.annotate("expect.exclusiveMax", { exclusiveMaxValue: s.exclusiveMaximum });
|
|
2433
|
+
}
|
|
2434
|
+
/**
|
|
1763
2435
|
* Merges multiple annotated types into a combined schema map with shared `$defs`.
|
|
1764
2436
|
*
|
|
1765
2437
|
* Each type must have an `id`. The returned `schemas` object contains individual
|
|
@@ -1788,4 +2460,303 @@ const UPPER_BOUNDS = new Set([
|
|
|
1788
2460
|
}
|
|
1789
2461
|
|
|
1790
2462
|
//#endregion
|
|
1791
|
-
|
|
2463
|
+
Object.defineProperty(exports, 'ARRAY_BITS', {
|
|
2464
|
+
enumerable: true,
|
|
2465
|
+
get: function () {
|
|
2466
|
+
return ARRAY_BITS;
|
|
2467
|
+
}
|
|
2468
|
+
});
|
|
2469
|
+
Object.defineProperty(exports, 'B_INT', {
|
|
2470
|
+
enumerable: true,
|
|
2471
|
+
get: function () {
|
|
2472
|
+
return B_INT;
|
|
2473
|
+
}
|
|
2474
|
+
});
|
|
2475
|
+
Object.defineProperty(exports, 'B_REQUIRED', {
|
|
2476
|
+
enumerable: true,
|
|
2477
|
+
get: function () {
|
|
2478
|
+
return B_REQUIRED;
|
|
2479
|
+
}
|
|
2480
|
+
});
|
|
2481
|
+
Object.defineProperty(exports, 'B_UNIQUE', {
|
|
2482
|
+
enumerable: true,
|
|
2483
|
+
get: function () {
|
|
2484
|
+
return B_UNIQUE;
|
|
2485
|
+
}
|
|
2486
|
+
});
|
|
2487
|
+
Object.defineProperty(exports, 'D_ARRAY', {
|
|
2488
|
+
enumerable: true,
|
|
2489
|
+
get: function () {
|
|
2490
|
+
return D_ARRAY;
|
|
2491
|
+
}
|
|
2492
|
+
});
|
|
2493
|
+
Object.defineProperty(exports, 'D_FINAL', {
|
|
2494
|
+
enumerable: true,
|
|
2495
|
+
get: function () {
|
|
2496
|
+
return D_FINAL;
|
|
2497
|
+
}
|
|
2498
|
+
});
|
|
2499
|
+
Object.defineProperty(exports, 'D_INTERSECTION', {
|
|
2500
|
+
enumerable: true,
|
|
2501
|
+
get: function () {
|
|
2502
|
+
return D_INTERSECTION;
|
|
2503
|
+
}
|
|
2504
|
+
});
|
|
2505
|
+
Object.defineProperty(exports, 'D_OBJECT', {
|
|
2506
|
+
enumerable: true,
|
|
2507
|
+
get: function () {
|
|
2508
|
+
return D_OBJECT;
|
|
2509
|
+
}
|
|
2510
|
+
});
|
|
2511
|
+
Object.defineProperty(exports, 'D_OBJECT_PATTERNS', {
|
|
2512
|
+
enumerable: true,
|
|
2513
|
+
get: function () {
|
|
2514
|
+
return D_OBJECT_PATTERNS;
|
|
2515
|
+
}
|
|
2516
|
+
});
|
|
2517
|
+
Object.defineProperty(exports, 'D_TUPLE', {
|
|
2518
|
+
enumerable: true,
|
|
2519
|
+
get: function () {
|
|
2520
|
+
return D_TUPLE;
|
|
2521
|
+
}
|
|
2522
|
+
});
|
|
2523
|
+
Object.defineProperty(exports, 'D_UNION', {
|
|
2524
|
+
enumerable: true,
|
|
2525
|
+
get: function () {
|
|
2526
|
+
return D_UNION;
|
|
2527
|
+
}
|
|
2528
|
+
});
|
|
2529
|
+
Object.defineProperty(exports, 'D_UNKNOWN', {
|
|
2530
|
+
enumerable: true,
|
|
2531
|
+
get: function () {
|
|
2532
|
+
return D_UNKNOWN;
|
|
2533
|
+
}
|
|
2534
|
+
});
|
|
2535
|
+
Object.defineProperty(exports, 'EXT', {
|
|
2536
|
+
enumerable: true,
|
|
2537
|
+
get: function () {
|
|
2538
|
+
return EXT;
|
|
2539
|
+
}
|
|
2540
|
+
});
|
|
2541
|
+
Object.defineProperty(exports, 'F_ERROR', {
|
|
2542
|
+
enumerable: true,
|
|
2543
|
+
get: function () {
|
|
2544
|
+
return F_ERROR;
|
|
2545
|
+
}
|
|
2546
|
+
});
|
|
2547
|
+
Object.defineProperty(exports, 'F_IN_UNION', {
|
|
2548
|
+
enumerable: true,
|
|
2549
|
+
get: function () {
|
|
2550
|
+
return F_IN_UNION;
|
|
2551
|
+
}
|
|
2552
|
+
});
|
|
2553
|
+
Object.defineProperty(exports, 'F_PARTIAL_DEEP', {
|
|
2554
|
+
enumerable: true,
|
|
2555
|
+
get: function () {
|
|
2556
|
+
return F_PARTIAL_DEEP;
|
|
2557
|
+
}
|
|
2558
|
+
});
|
|
2559
|
+
Object.defineProperty(exports, 'F_PARTIAL_TOP', {
|
|
2560
|
+
enumerable: true,
|
|
2561
|
+
get: function () {
|
|
2562
|
+
return F_PARTIAL_TOP;
|
|
2563
|
+
}
|
|
2564
|
+
});
|
|
2565
|
+
Object.defineProperty(exports, 'F_STRIP', {
|
|
2566
|
+
enumerable: true,
|
|
2567
|
+
get: function () {
|
|
2568
|
+
return F_STRIP;
|
|
2569
|
+
}
|
|
2570
|
+
});
|
|
2571
|
+
Object.defineProperty(exports, 'F_TOP', {
|
|
2572
|
+
enumerable: true,
|
|
2573
|
+
get: function () {
|
|
2574
|
+
return F_TOP;
|
|
2575
|
+
}
|
|
2576
|
+
});
|
|
2577
|
+
Object.defineProperty(exports, 'INTERP', {
|
|
2578
|
+
enumerable: true,
|
|
2579
|
+
get: function () {
|
|
2580
|
+
return INTERP;
|
|
2581
|
+
}
|
|
2582
|
+
});
|
|
2583
|
+
Object.defineProperty(exports, 'ITEMS_KIND_CODES', {
|
|
2584
|
+
enumerable: true,
|
|
2585
|
+
get: function () {
|
|
2586
|
+
return ITEMS_KIND_CODES;
|
|
2587
|
+
}
|
|
2588
|
+
});
|
|
2589
|
+
Object.defineProperty(exports, 'LAYOUT_VERSION', {
|
|
2590
|
+
enumerable: true,
|
|
2591
|
+
get: function () {
|
|
2592
|
+
return LAYOUT_VERSION;
|
|
2593
|
+
}
|
|
2594
|
+
});
|
|
2595
|
+
Object.defineProperty(exports, 'NUMBER_BITS', {
|
|
2596
|
+
enumerable: true,
|
|
2597
|
+
get: function () {
|
|
2598
|
+
return NUMBER_BITS;
|
|
2599
|
+
}
|
|
2600
|
+
});
|
|
2601
|
+
Object.defineProperty(exports, 'STRING_BITS', {
|
|
2602
|
+
enumerable: true,
|
|
2603
|
+
get: function () {
|
|
2604
|
+
return STRING_BITS;
|
|
2605
|
+
}
|
|
2606
|
+
});
|
|
2607
|
+
Object.defineProperty(exports, 'Validator', {
|
|
2608
|
+
enumerable: true,
|
|
2609
|
+
get: function () {
|
|
2610
|
+
return Validator;
|
|
2611
|
+
}
|
|
2612
|
+
});
|
|
2613
|
+
Object.defineProperty(exports, 'ValidatorError', {
|
|
2614
|
+
enumerable: true,
|
|
2615
|
+
get: function () {
|
|
2616
|
+
return ValidatorError;
|
|
2617
|
+
}
|
|
2618
|
+
});
|
|
2619
|
+
Object.defineProperty(exports, 'annotate', {
|
|
2620
|
+
enumerable: true,
|
|
2621
|
+
get: function () {
|
|
2622
|
+
return annotate;
|
|
2623
|
+
}
|
|
2624
|
+
});
|
|
2625
|
+
Object.defineProperty(exports, 'buildJsonSchema', {
|
|
2626
|
+
enumerable: true,
|
|
2627
|
+
get: function () {
|
|
2628
|
+
return buildJsonSchema;
|
|
2629
|
+
}
|
|
2630
|
+
});
|
|
2631
|
+
Object.defineProperty(exports, 'childSites', {
|
|
2632
|
+
enumerable: true,
|
|
2633
|
+
get: function () {
|
|
2634
|
+
return childSites;
|
|
2635
|
+
}
|
|
2636
|
+
});
|
|
2637
|
+
Object.defineProperty(exports, 'cloneRefProp', {
|
|
2638
|
+
enumerable: true,
|
|
2639
|
+
get: function () {
|
|
2640
|
+
return cloneRefProp;
|
|
2641
|
+
}
|
|
2642
|
+
});
|
|
2643
|
+
Object.defineProperty(exports, 'createAnnotatedTypeNode', {
|
|
2644
|
+
enumerable: true,
|
|
2645
|
+
get: function () {
|
|
2646
|
+
return createAnnotatedTypeNode;
|
|
2647
|
+
}
|
|
2648
|
+
});
|
|
2649
|
+
Object.defineProperty(exports, 'createMetadataMap', {
|
|
2650
|
+
enumerable: true,
|
|
2651
|
+
get: function () {
|
|
2652
|
+
return createMetadataMap;
|
|
2653
|
+
}
|
|
2654
|
+
});
|
|
2655
|
+
Object.defineProperty(exports, 'createObjectTypeDef', {
|
|
2656
|
+
enumerable: true,
|
|
2657
|
+
get: function () {
|
|
2658
|
+
return createObjectTypeDef;
|
|
2659
|
+
}
|
|
2660
|
+
});
|
|
2661
|
+
Object.defineProperty(exports, 'defineAnnotatedType', {
|
|
2662
|
+
enumerable: true,
|
|
2663
|
+
get: function () {
|
|
2664
|
+
return defineAnnotatedType;
|
|
2665
|
+
}
|
|
2666
|
+
});
|
|
2667
|
+
Object.defineProperty(exports, 'detectDiscriminator', {
|
|
2668
|
+
enumerable: true,
|
|
2669
|
+
get: function () {
|
|
2670
|
+
return detectDiscriminator;
|
|
2671
|
+
}
|
|
2672
|
+
});
|
|
2673
|
+
Object.defineProperty(exports, 'forAnnotatedType', {
|
|
2674
|
+
enumerable: true,
|
|
2675
|
+
get: function () {
|
|
2676
|
+
return forAnnotatedType;
|
|
2677
|
+
}
|
|
2678
|
+
});
|
|
2679
|
+
Object.defineProperty(exports, 'fromJsonSchema', {
|
|
2680
|
+
enumerable: true,
|
|
2681
|
+
get: function () {
|
|
2682
|
+
return fromJsonSchema;
|
|
2683
|
+
}
|
|
2684
|
+
});
|
|
2685
|
+
Object.defineProperty(exports, 'getRegex', {
|
|
2686
|
+
enumerable: true,
|
|
2687
|
+
get: function () {
|
|
2688
|
+
return getRegex;
|
|
2689
|
+
}
|
|
2690
|
+
});
|
|
2691
|
+
Object.defineProperty(exports, 'hasRejectSlot', {
|
|
2692
|
+
enumerable: true,
|
|
2693
|
+
get: function () {
|
|
2694
|
+
return hasRejectSlot;
|
|
2695
|
+
}
|
|
2696
|
+
});
|
|
2697
|
+
Object.defineProperty(exports, 'invalidateCompiledValidators', {
|
|
2698
|
+
enumerable: true,
|
|
2699
|
+
get: function () {
|
|
2700
|
+
return invalidateCompiledValidators;
|
|
2701
|
+
}
|
|
2702
|
+
});
|
|
2703
|
+
Object.defineProperty(exports, 'isAnnotatedType', {
|
|
2704
|
+
enumerable: true,
|
|
2705
|
+
get: function () {
|
|
2706
|
+
return isAnnotatedType;
|
|
2707
|
+
}
|
|
2708
|
+
});
|
|
2709
|
+
Object.defineProperty(exports, 'isAnnotatedTypeOfPrimitive', {
|
|
2710
|
+
enumerable: true,
|
|
2711
|
+
get: function () {
|
|
2712
|
+
return isAnnotatedTypeOfPrimitive;
|
|
2713
|
+
}
|
|
2714
|
+
});
|
|
2715
|
+
Object.defineProperty(exports, 'isPhantomType', {
|
|
2716
|
+
enumerable: true,
|
|
2717
|
+
get: function () {
|
|
2718
|
+
return isPhantomType;
|
|
2719
|
+
}
|
|
2720
|
+
});
|
|
2721
|
+
Object.defineProperty(exports, 'isValidatorKey', {
|
|
2722
|
+
enumerable: true,
|
|
2723
|
+
get: function () {
|
|
2724
|
+
return isValidatorKey;
|
|
2725
|
+
}
|
|
2726
|
+
});
|
|
2727
|
+
Object.defineProperty(exports, 'keySlots', {
|
|
2728
|
+
enumerable: true,
|
|
2729
|
+
get: function () {
|
|
2730
|
+
return keySlots;
|
|
2731
|
+
}
|
|
2732
|
+
});
|
|
2733
|
+
Object.defineProperty(exports, 'mergeJsonSchemas', {
|
|
2734
|
+
enumerable: true,
|
|
2735
|
+
get: function () {
|
|
2736
|
+
return mergeJsonSchemas;
|
|
2737
|
+
}
|
|
2738
|
+
});
|
|
2739
|
+
Object.defineProperty(exports, 'readKeys', {
|
|
2740
|
+
enumerable: true,
|
|
2741
|
+
get: function () {
|
|
2742
|
+
return readKeys;
|
|
2743
|
+
}
|
|
2744
|
+
});
|
|
2745
|
+
Object.defineProperty(exports, 'registerCompiledCheck', {
|
|
2746
|
+
enumerable: true,
|
|
2747
|
+
get: function () {
|
|
2748
|
+
return registerCompiledCheck;
|
|
2749
|
+
}
|
|
2750
|
+
});
|
|
2751
|
+
Object.defineProperty(exports, 'siteBits', {
|
|
2752
|
+
enumerable: true,
|
|
2753
|
+
get: function () {
|
|
2754
|
+
return siteBits;
|
|
2755
|
+
}
|
|
2756
|
+
});
|
|
2757
|
+
Object.defineProperty(exports, 'siteSlotCount', {
|
|
2758
|
+
enumerable: true,
|
|
2759
|
+
get: function () {
|
|
2760
|
+
return siteSlotCount;
|
|
2761
|
+
}
|
|
2762
|
+
});
|