@atscript/typescript 0.2.3 → 0.2.4
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 +211 -29
- package/dist/index.cjs +3 -3
- package/dist/index.mjs +2 -2
- package/dist/{plugin-oUSsb3Ri.cjs → plugin-Cqao46Gt.cjs} +62 -23
- package/dist/{plugin-DhesoKce.mjs → plugin-Ct9Ko5JG.mjs} +59 -20
- package/dist/realm-runtime.js +867 -256
- package/dist/test-utils.cjs +3 -3
- package/dist/test-utils.d.ts +179 -4
- package/dist/test-utils.mjs +2 -2
- package/dist/{unique-name-xWd9uO-k.cjs → user-text-BddKk8EU.cjs} +823 -191
- package/dist/{unique-name-hg1CyPIs.mjs → user-text-qL59indq.mjs} +758 -192
- package/dist/utils.cjs +158 -154
- package/dist/utils.d.ts +312 -28
- package/dist/utils.mjs +58 -63
- package/package.json +5 -5
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"expect.maxLength",
|
|
24
24
|
"expect.array.uniqueItems"
|
|
25
25
|
];
|
|
26
|
+
/** Annotations of an object node, in check order (before its props). */ const OBJECT_KEYS = ["expect.minKeys", "expect.maxKeys"];
|
|
26
27
|
/**
|
|
27
28
|
* Every annotation key the validator pre-check reads. The order is the bit order of
|
|
28
29
|
* compiled-check layouts: changing it changes the layout format.
|
|
@@ -36,7 +37,9 @@
|
|
|
36
37
|
"expect.max",
|
|
37
38
|
"expect.exclusiveMin",
|
|
38
39
|
"expect.exclusiveMax",
|
|
39
|
-
"expect.array.uniqueItems"
|
|
40
|
+
"expect.array.uniqueItems",
|
|
41
|
+
"expect.minKeys",
|
|
42
|
+
"expect.maxKeys"
|
|
40
43
|
];
|
|
41
44
|
/**
|
|
42
45
|
* The number a length / bound annotation compares with: the annotation is either the number
|
|
@@ -237,6 +240,32 @@ const notReferred = (key) => ((FLAGS.get(key) ?? 0) & NOT_REFERRED) !== 0;
|
|
|
237
240
|
*/ function moveIntrinsic(from, to) {
|
|
238
241
|
const s = INTRINSIC.get(from);
|
|
239
242
|
if (s) INTRINSIC.set(to, s);
|
|
243
|
+
moveHidden(from, to);
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Keys a map hides from its bases (`@annotate.reset`): read as if no base had them. Kept per map
|
|
247
|
+
* (as `INTRINSIC`), moved with it when a node's map is replaced; `hiding`: some map hides a key
|
|
248
|
+
* (until then the reads skip the lookup).
|
|
249
|
+
*/ const HIDDEN = /* @__PURE__ */ new WeakMap();
|
|
250
|
+
let hiding = false;
|
|
251
|
+
/** Whether map `m` hides `key` from its bases (see {@link HIDDEN}). */ function hides(m, key) {
|
|
252
|
+
return hiding && HIDDEN.get(m)?.has(key) === true;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Hides `key` of map `m`'s bases (`@annotate.reset`): `m` reads as if no base had it — its own
|
|
256
|
+
* value, if any, is what it has. A metadata write (layered views and compiled checks re-read).
|
|
257
|
+
* `metadata.delete(key)` on a layered map ends it: the bases show through again.
|
|
258
|
+
*/ function hideKey(m, key) {
|
|
259
|
+
let s = HIDDEN.get(m);
|
|
260
|
+
if (!s) HIDDEN.set(m, s = /* @__PURE__ */ new Set());
|
|
261
|
+
s.add(key);
|
|
262
|
+
hiding = true;
|
|
263
|
+
touched(m);
|
|
264
|
+
metadataReplaced();
|
|
265
|
+
}
|
|
266
|
+
/** The keys map `m` hides from its bases (see {@link hideKey}), for a map replacing it. */ function moveHidden(from, to) {
|
|
267
|
+
const s = HIDDEN.get(from);
|
|
268
|
+
if (s) HIDDEN.set(to, s);
|
|
240
269
|
}
|
|
241
270
|
const MISS = Symbol("miss");
|
|
242
271
|
/** The view of a layered map without effective entries (never written: views stay internal). */ const NO_ENTRIES = new AnnotationMap();
|
|
@@ -271,6 +300,7 @@ let _Symbol_iterator = Symbol.iterator;
|
|
|
271
300
|
const v = mapGet.call(this, key);
|
|
272
301
|
if (v !== void 0 || mapHas.call(this, key)) return v;
|
|
273
302
|
}
|
|
303
|
+
if (hiding && hides(this, key)) return MISS;
|
|
274
304
|
if (nr && this.r) {
|
|
275
305
|
for (const n of this.b) {
|
|
276
306
|
const x = intrinsicLookup(n.metadata, key);
|
|
@@ -301,10 +331,14 @@ let _Symbol_iterator = Symbol.iterator;
|
|
|
301
331
|
}
|
|
302
332
|
has(key) {
|
|
303
333
|
const view = this.view();
|
|
304
|
-
return view === void 0 ? this.
|
|
334
|
+
return view === void 0 ? this.liveHas(key) : mapHas.call(view, key);
|
|
335
|
+
}
|
|
336
|
+
/** `has` read through the layers (see the file comment). */ liveHas(key) {
|
|
337
|
+
return this.lookup(key, notReferred(key)) !== MISS;
|
|
305
338
|
}
|
|
306
339
|
/** An append key: the bases' values (lowest priority first), then the own ones. */ append(key) {
|
|
307
340
|
const own = mapGet.call(this, key);
|
|
341
|
+
if (hiding && hides(this, key)) return own;
|
|
308
342
|
if (this.r && notReferred(key)) {
|
|
309
343
|
const parts = [];
|
|
310
344
|
const acc = {
|
|
@@ -341,8 +375,20 @@ let _Symbol_iterator = Symbol.iterator;
|
|
|
341
375
|
}
|
|
342
376
|
liveKeys() {
|
|
343
377
|
const out = /* @__PURE__ */ new Set();
|
|
344
|
-
keysOf(this, false, out, /* @__PURE__ */ new Map());
|
|
345
|
-
|
|
378
|
+
return keysOf(this, false, out, /* @__PURE__ */ new Map()) ? [...out].filter((k) => this.liveHas(k)) : [...out];
|
|
379
|
+
}
|
|
380
|
+
/** Deletes the own value of `key`; a key hidden from the bases (`hideKey`) shows them again. */ delete(key) {
|
|
381
|
+
const deleted = super.delete(key);
|
|
382
|
+
if ((hiding ? HIDDEN.get(this) : void 0)?.delete(key)) {
|
|
383
|
+
touched(this);
|
|
384
|
+
metadataReplaced();
|
|
385
|
+
return true;
|
|
386
|
+
}
|
|
387
|
+
return deleted;
|
|
388
|
+
}
|
|
389
|
+
/** Deletes the own values; the keys hidden from the bases (`hideKey`) show them again. */ clear() {
|
|
390
|
+
super.clear();
|
|
391
|
+
HIDDEN.delete(this);
|
|
346
392
|
}
|
|
347
393
|
keys() {
|
|
348
394
|
return this.effectiveKeys()[Symbol.iterator]();
|
|
@@ -393,7 +439,7 @@ Object.defineProperty(LayerMap.prototype, "size", {
|
|
|
393
439
|
if (m instanceof LayerMap ? mapHas.call(m, key) : m.has(key)) return m instanceof LayerMap ? mapGet.call(m, key) : m.get(key);
|
|
394
440
|
}
|
|
395
441
|
const b = m.b;
|
|
396
|
-
if (b !== void 0) for (const n of b) {
|
|
442
|
+
if (b !== void 0 && !hides(m, key)) for (const n of b) {
|
|
397
443
|
const x = intrinsicLookup(n.metadata, key);
|
|
398
444
|
if (x !== MISS) return x;
|
|
399
445
|
}
|
|
@@ -418,7 +464,7 @@ Object.defineProperty(LayerMap.prototype, "size", {
|
|
|
418
464
|
const was = acc.seen.get(m);
|
|
419
465
|
if (!visit(m, filtered, acc.seen)) return;
|
|
420
466
|
const layer = m instanceof LayerMap ? m : void 0;
|
|
421
|
-
if (layer) {
|
|
467
|
+
if (layer && !hides(layer, key)) {
|
|
422
468
|
const below = filtered || layer.r && notReferred(key);
|
|
423
469
|
for (let i = layer.b.length - 1; i >= 0; i--) collect(layer.b[i].metadata, key, acc, below);
|
|
424
470
|
}
|
|
@@ -427,14 +473,16 @@ Object.defineProperty(LayerMap.prototype, "size", {
|
|
|
427
473
|
}
|
|
428
474
|
/**
|
|
429
475
|
* The keys of `m` (own first, then its bases'), each map once (see {@link visit}). `filtered`:
|
|
430
|
-
* reached through a reference layer.
|
|
476
|
+
* reached through a reference layer. Returns whether a map visited hides keys from its bases.
|
|
431
477
|
*/ function keysOf(m, filtered, out, seen) {
|
|
432
|
-
if (!visit(m, filtered, seen)) return;
|
|
478
|
+
if (!visit(m, filtered, seen)) return false;
|
|
479
|
+
let hid = hiding && (HIDDEN.get(m)?.size ?? 0) > 0;
|
|
433
480
|
const layer = m instanceof LayerMap ? m : void 0;
|
|
434
481
|
const own = layer ? Map.prototype.keys.call(m) : m.keys();
|
|
435
482
|
const intrinsic = INTRINSIC.get(m);
|
|
436
483
|
for (const k of own) if (!filtered || !notReferred(k) || intrinsic?.has(k)) out.add(k);
|
|
437
|
-
if (layer) for (const n of layer.b) keysOf(n.metadata, filtered || layer.r, out, seen);
|
|
484
|
+
if (layer) for (const n of layer.b) hid = keysOf(n.metadata, filtered || layer.r, out, seen) || hid;
|
|
485
|
+
return hid;
|
|
438
486
|
}
|
|
439
487
|
/**
|
|
440
488
|
* `m` has no entry (own or through its bases): the validators' `metadata.size === 0` fast path,
|
|
@@ -925,6 +973,51 @@ function caseVariants(ch, unicode) {
|
|
|
925
973
|
};
|
|
926
974
|
}
|
|
927
975
|
|
|
976
|
+
//#endregion
|
|
977
|
+
//#region packages/typescript/src/runtime/discriminator.ts
|
|
978
|
+
/**
|
|
979
|
+
* Detects a discriminator property across union items.
|
|
980
|
+
*
|
|
981
|
+
* Scans all items for object-typed members that share a common property
|
|
982
|
+
* with distinct const/literal values. If exactly one such property exists,
|
|
983
|
+
* it is returned as the discriminator. Returns `null` when no qualifying
|
|
984
|
+
* property exists, or when more than one does (ambiguous).
|
|
985
|
+
*/ function detectDiscriminator(items) {
|
|
986
|
+
if (items.length < 2) return null;
|
|
987
|
+
for (const item of items) if (item.type.kind !== "object") return null;
|
|
988
|
+
const firstObj = items[0].type;
|
|
989
|
+
const candidates = [];
|
|
990
|
+
for (const [propName, propType] of firstObj.props.entries()) if (propType.type.kind === "" && propType.type.value !== void 0) candidates.push(propName);
|
|
991
|
+
let result = null;
|
|
992
|
+
for (const candidate of candidates) {
|
|
993
|
+
const values = /* @__PURE__ */ new Set();
|
|
994
|
+
const indexMapping = {};
|
|
995
|
+
let valid = true;
|
|
996
|
+
for (let i = 0; i < items.length; i++) {
|
|
997
|
+
const prop = items[i].type.props.get(candidate);
|
|
998
|
+
if (!prop || prop.type.kind !== "" || prop.type.value === void 0) {
|
|
999
|
+
valid = false;
|
|
1000
|
+
break;
|
|
1001
|
+
}
|
|
1002
|
+
const val = prop.type.value;
|
|
1003
|
+
if (values.has(val)) {
|
|
1004
|
+
valid = false;
|
|
1005
|
+
break;
|
|
1006
|
+
}
|
|
1007
|
+
values.add(val);
|
|
1008
|
+
indexMapping[String(val)] = i;
|
|
1009
|
+
}
|
|
1010
|
+
if (valid) {
|
|
1011
|
+
if (result) return null;
|
|
1012
|
+
result = {
|
|
1013
|
+
propertyName: candidate,
|
|
1014
|
+
indexMapping
|
|
1015
|
+
};
|
|
1016
|
+
}
|
|
1017
|
+
}
|
|
1018
|
+
return result;
|
|
1019
|
+
}
|
|
1020
|
+
|
|
928
1021
|
//#endregion
|
|
929
1022
|
//#region packages/typescript/src/runtime/compiled-check/layout.ts
|
|
930
1023
|
/**
|
|
@@ -998,11 +1091,14 @@ const B_MAX = bit("expect.max");
|
|
|
998
1091
|
const B_EX_MIN = bit("expect.exclusiveMin");
|
|
999
1092
|
const B_EX_MAX = bit("expect.exclusiveMax");
|
|
1000
1093
|
const B_UNIQUE = bit("expect.array.uniqueItems");
|
|
1094
|
+
const B_MIN_KEYS = bit("expect.minKeys");
|
|
1095
|
+
const B_MAX_KEYS = bit("expect.maxKeys");
|
|
1001
1096
|
/** Annotations the pre-check reads per kind of value (see validator-keys.ts). */ const STRING_BITS = bitsOf(STRING_KEYS);
|
|
1002
1097
|
const NUMBER_BITS = bitsOf(NUMBER_KEYS);
|
|
1003
1098
|
const ARRAY_BITS = bitsOf(ARRAY_KEYS);
|
|
1099
|
+
const OBJECT_BITS = bitsOf(OBJECT_KEYS);
|
|
1004
1100
|
const BOOLEAN_BITS = bitsOf(BOOLEAN_KEYS);
|
|
1005
|
-
/** 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;
|
|
1101
|
+
/** 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 | B_MIN_KEYS | B_MAX_KEYS;
|
|
1006
1102
|
const FLAG_BITS = B_REQUIRED | B_INT | B_UNIQUE;
|
|
1007
1103
|
const ALL_BITS = (1 << VALIDATOR_KEYS.length) - 1;
|
|
1008
1104
|
/** The field holding the bound of each value key's object form. */ const BOUND_FIELDS = {
|
|
@@ -1011,7 +1107,9 @@ const ALL_BITS = (1 << VALIDATOR_KEYS.length) - 1;
|
|
|
1011
1107
|
[B_MIN]: "minValue",
|
|
1012
1108
|
[B_MAX]: "maxValue",
|
|
1013
1109
|
[B_EX_MIN]: "exclusiveMinValue",
|
|
1014
|
-
[B_EX_MAX]: "exclusiveMaxValue"
|
|
1110
|
+
[B_EX_MAX]: "exclusiveMaxValue",
|
|
1111
|
+
[B_MIN_KEYS]: "count",
|
|
1112
|
+
[B_MAX_KEYS]: "count"
|
|
1015
1113
|
};
|
|
1016
1114
|
/**
|
|
1017
1115
|
* Validator annotations the pre-check reads for a node of this type def (the rest of the
|
|
@@ -1027,6 +1125,7 @@ const ALL_BITS = (1 << VALIDATOR_KEYS.length) - 1;
|
|
|
1027
1125
|
default: return 0;
|
|
1028
1126
|
}
|
|
1029
1127
|
case "array": return ARRAY_BITS;
|
|
1128
|
+
case "object": return OBJECT_BITS;
|
|
1030
1129
|
case "union": return ALL_BITS;
|
|
1031
1130
|
default: return 0;
|
|
1032
1131
|
}
|
|
@@ -1518,7 +1617,7 @@ function acceptsNull(def) {
|
|
|
1518
1617
|
for (const item of def.type.items) {
|
|
1519
1618
|
const failures = COMPILED_ENV.n;
|
|
1520
1619
|
const result = fastCheck(item, value, branchFlags, opts);
|
|
1521
|
-
if (result !== FAIL) return unionMatchResult(result, item, def.metadata, value);
|
|
1620
|
+
if (result !== FAIL) return unionMatchResult(result, item, def.metadata, value, opts);
|
|
1522
1621
|
if (COMPILED_ENV.n !== failures) unionWaste();
|
|
1523
1622
|
if (nested) COMPILED_ENV.n++;
|
|
1524
1623
|
if (pendingStrips.length !== kept) pendingStrips.length = kept;
|
|
@@ -1537,7 +1636,7 @@ function acceptsNull(def) {
|
|
|
1537
1636
|
for (const child of plan.children) {
|
|
1538
1637
|
const failures = COMPILED_ENV.n;
|
|
1539
1638
|
const result = checkPlan(child, value, branchFlags, opts);
|
|
1540
|
-
if (result !== FAIL) return unionMatchResult(result, child.def, plan.metadata, value);
|
|
1639
|
+
if (result !== FAIL) return unionMatchResult(result, child.def, plan.metadata, value, opts);
|
|
1541
1640
|
if (COMPILED_ENV.n !== failures) unionWaste();
|
|
1542
1641
|
if (nested) COMPILED_ENV.n++;
|
|
1543
1642
|
if (pendingStrips.length !== kept) pendingStrips.length = kept;
|
|
@@ -1550,7 +1649,7 @@ function acceptsNull(def) {
|
|
|
1550
1649
|
for (const item of def.type.items) {
|
|
1551
1650
|
const failures = COMPILED_ENV.n;
|
|
1552
1651
|
const result = fastCheck(item, value, branchFlags, opts);
|
|
1553
|
-
if (result !== FAIL) return unionMatchResult(result, item, def.metadata, value);
|
|
1652
|
+
if (result !== FAIL) return unionMatchResult(result, item, def.metadata, value, opts);
|
|
1554
1653
|
if (COMPILED_ENV.n !== failures) unionWaste();
|
|
1555
1654
|
if (nested) COMPILED_ENV.n++;
|
|
1556
1655
|
if (pendingStrips.length !== kept) pendingStrips.length = kept;
|
|
@@ -1563,7 +1662,7 @@ function acceptsNull(def) {
|
|
|
1563
1662
|
for (const child of plan.children) {
|
|
1564
1663
|
const failures = COMPILED_ENV.n;
|
|
1565
1664
|
const result = checkPlan(child, value, branchFlags, opts);
|
|
1566
|
-
if (result !== FAIL) return unionMatchResult(result, child.def, plan.metadata, value);
|
|
1665
|
+
if (result !== FAIL) return unionMatchResult(result, child.def, plan.metadata, value, opts);
|
|
1567
1666
|
if (COMPILED_ENV.n !== failures) unionWaste();
|
|
1568
1667
|
if (nested) COMPILED_ENV.n++;
|
|
1569
1668
|
if (pendingStrips.length !== kept) pendingStrips.length = kept;
|
|
@@ -1609,7 +1708,7 @@ function fastCheckFinal(def, value) {
|
|
|
1609
1708
|
case "string": return typeof value === "string" ? fastCheckString(def.metadata, value) : FAIL;
|
|
1610
1709
|
case "number": return typeof value === "number" && Number.isFinite(value) ? fastCheckNumber(def.metadata, value) : FAIL;
|
|
1611
1710
|
case "boolean": return typeof value === "boolean" ? fastCheckBoolean(def.metadata, value) : FAIL;
|
|
1612
|
-
case "any": return PASS;
|
|
1711
|
+
case "any": return value === void 0 ? FAIL : PASS;
|
|
1613
1712
|
case "never": return FAIL;
|
|
1614
1713
|
case "undefined": return value === void 0 ? PASS : FAIL;
|
|
1615
1714
|
case "null": return value === null ? PASS : FAIL;
|
|
@@ -1617,20 +1716,22 @@ function fastCheckFinal(def, value) {
|
|
|
1617
1716
|
default: return BAIL;
|
|
1618
1717
|
}
|
|
1619
1718
|
}
|
|
1620
|
-
/** Result of a union whose branch `item` did not fail (`PASS` or `BAIL`). */ function unionMatchResult(result, item, metadata, value) {
|
|
1621
|
-
return result === PASS && item.type.value === void 0 ? fastCheckUnionConstraints(metadata, value) : result;
|
|
1719
|
+
/** Result of a union whose branch `item` did not fail (`PASS` or `BAIL`). */ function unionMatchResult(result, item, metadata, value, opts) {
|
|
1720
|
+
return result === PASS && item.type.value === void 0 ? fastCheckUnionConstraints(metadata, value, item, opts) : result;
|
|
1622
1721
|
}
|
|
1623
1722
|
/**
|
|
1624
1723
|
* Mirrors Validator.validateUnionConstraints: union-level constraints on the matched value
|
|
1625
1724
|
* (`null` / objects pass; the caller skips literal branches).
|
|
1626
|
-
*/ function fastCheckUnionConstraints(meta, value) {
|
|
1725
|
+
*/ function fastCheckUnionConstraints(meta, value, branch, opts) {
|
|
1627
1726
|
const metadata = filledMeta(meta);
|
|
1628
1727
|
if (metadata === void 0) return PASS;
|
|
1629
1728
|
switch (typeof value) {
|
|
1630
1729
|
case "string": return fastCheckString(metadata, value);
|
|
1631
1730
|
case "number": return fastCheckNumber(metadata, value);
|
|
1632
1731
|
case "boolean": return fastCheckBoolean(metadata, value);
|
|
1633
|
-
case "object":
|
|
1732
|
+
case "object":
|
|
1733
|
+
if (Array.isArray(value)) return fastCheckArrayConstraints(metadata, value);
|
|
1734
|
+
return value === null ? PASS : objectKeyCounts(metadata, value, branch, opts);
|
|
1634
1735
|
default: return PASS;
|
|
1635
1736
|
}
|
|
1636
1737
|
}
|
|
@@ -1672,6 +1773,34 @@ function numberConstraints(value, int, min, max, exMin, exMax) {
|
|
|
1672
1773
|
/** `@expect.minLength` / `@expect.maxLength` (strings and arrays). */ function lengthFails(length, minLength, maxLength) {
|
|
1673
1774
|
return minLength !== void 0 && length < (typeof minLength === "number" ? minLength : minLength.length) || maxLength !== void 0 && length > (typeof maxLength === "number" ? maxLength : maxLength.length);
|
|
1674
1775
|
}
|
|
1776
|
+
/** `@expect.minKeys` / `@expect.maxKeys` of an object keeping `count` keys. */ function countFails(count, minKeys, maxKeys) {
|
|
1777
|
+
return minKeys !== void 0 && count < (typeof minKeys === "number" ? minKeys : minKeys.count) || maxKeys !== void 0 && count > (typeof maxKeys === "number" ? maxKeys : maxKeys.count);
|
|
1778
|
+
}
|
|
1779
|
+
/**
|
|
1780
|
+
* The keys of object `value` the walk's result keeps (`Validator.keptKeyCount`): with
|
|
1781
|
+
* `unknownProps: 'strip'`, the keys `props` declares (not phantom); else every own key (with
|
|
1782
|
+
* 'error' an object with an unknown key fails anyway, whatever its count).
|
|
1783
|
+
*/ function keptKeys(props, value, opts) {
|
|
1784
|
+
const keys = Object.keys(value);
|
|
1785
|
+
if (opts.unknownProps !== "strip") return keys.length;
|
|
1786
|
+
let count = 0;
|
|
1787
|
+
for (const key of keys) if (!isUnknownKey(props, key)) count++;
|
|
1788
|
+
return count;
|
|
1789
|
+
}
|
|
1790
|
+
/**
|
|
1791
|
+
* `@expect.minKeys` / `maxKeys` in `metadata` (an object's or a union's) of object `value`,
|
|
1792
|
+
* matched as `branch` (pattern props: the walk).
|
|
1793
|
+
*/ function objectKeyCounts(metadata, value, branch, opts) {
|
|
1794
|
+
const minKeys = metadata.get("expect.minKeys");
|
|
1795
|
+
const maxKeys = metadata.get("expect.maxKeys");
|
|
1796
|
+
if (minKeys === void 0 && maxKeys === void 0) return PASS;
|
|
1797
|
+
const type = branch.type;
|
|
1798
|
+
let count;
|
|
1799
|
+
if (type.kind !== "object") count = Object.keys(value).length;
|
|
1800
|
+
else if (type.propsPatterns.length > 0 && opts.unknownProps !== "ignore") return BAIL;
|
|
1801
|
+
else count = keptKeys(type.props, value, opts);
|
|
1802
|
+
return countFails(count, minKeys, maxKeys) ? FAIL : PASS;
|
|
1803
|
+
}
|
|
1675
1804
|
/**
|
|
1676
1805
|
* {@link fastCheck} of an intersection (a function of its own: `fastCheck` stays small, so the
|
|
1677
1806
|
* engine inlines it in the hot object and prop checks).
|
|
@@ -1708,6 +1837,8 @@ function fastCheckObject(def, value, flags, opts) {
|
|
|
1708
1837
|
}
|
|
1709
1838
|
}
|
|
1710
1839
|
if (result !== PASS) return result;
|
|
1840
|
+
const metadata = filledMeta(def.metadata);
|
|
1841
|
+
if (metadata !== void 0 && objectKeyCounts(metadata, value, def, opts) === FAIL) return FAIL;
|
|
1711
1842
|
if (unknownProps === "strip") {
|
|
1712
1843
|
pendStrips(type.props, value);
|
|
1713
1844
|
return PASS;
|
|
@@ -1780,7 +1911,8 @@ const plans = /* @__PURE__ */ new WeakMap();
|
|
|
1780
1911
|
/**
|
|
1781
1912
|
* Annotation keys the node's check reads, and their values (`undefined` when absent):
|
|
1782
1913
|
* string `meta.required, expect.minLength, maxLength, pattern`; number `expect.int, min,
|
|
1783
|
-
* max, exclusiveMin, exclusiveMax`; boolean `meta.required`; array `expect.minLength, maxLength, array.uniqueItems
|
|
1914
|
+
* max, exclusiveMin, exclusiveMax`; boolean `meta.required`; array `expect.minLength, maxLength, array.uniqueItems`;
|
|
1915
|
+
* object `expect.minKeys, maxKeys`.
|
|
1784
1916
|
*/ _define_property$1(this, "k0", void 0);
|
|
1785
1917
|
_define_property$1(this, "k1", void 0);
|
|
1786
1918
|
_define_property$1(this, "k2", void 0);
|
|
@@ -1948,6 +2080,7 @@ function setMetaKeys(plan, k0, k1, k2, k3, k4) {
|
|
|
1948
2080
|
plan.byKey = byKey;
|
|
1949
2081
|
plan.props = type.props;
|
|
1950
2082
|
plan.propsPatterns = type.propsPatterns;
|
|
2083
|
+
setMetaKeys(plan, ...OBJECT_KEYS);
|
|
1951
2084
|
plan.op = OP_OBJECT;
|
|
1952
2085
|
break;
|
|
1953
2086
|
}
|
|
@@ -2061,16 +2194,28 @@ function setMetaKeys(plan, k0, k1, k2, k3, k4) {
|
|
|
2061
2194
|
}
|
|
2062
2195
|
if (result !== PASS) return result;
|
|
2063
2196
|
const unknownProps = opts.unknownProps;
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2197
|
+
const byKey = plan.byKey;
|
|
2198
|
+
if (plan.metaStamp !== stamp) refreshMeta(plan);
|
|
2199
|
+
if ((plan.m0 !== void 0 || plan.m1 !== void 0) && planKeyCountFails(plan, byKey, value, opts)) return FAIL;
|
|
2200
|
+
if (unknownProps === "error" || unknownProps === "strip") for (const key of Object.keys(value)) {
|
|
2201
|
+
const known = byKey.get(key);
|
|
2202
|
+
if (known !== void 0 && known.op !== OP_PHANTOM) continue;
|
|
2203
|
+
if (unknownProps === "error") return FAIL;
|
|
2204
|
+
pendingStrips.push(value, key);
|
|
2205
|
+
}
|
|
2206
|
+
return PASS;
|
|
2207
|
+
}
|
|
2208
|
+
/** The key counts of an object plan (see `keptKeys`; `byKey` verified). */ function planKeyCountFails(plan, byKey, value, opts) {
|
|
2209
|
+
const keys = Object.keys(value);
|
|
2210
|
+
let count = keys.length;
|
|
2211
|
+
if (opts.unknownProps === "strip") {
|
|
2212
|
+
count = 0;
|
|
2213
|
+
for (const key of keys) {
|
|
2067
2214
|
const known = byKey.get(key);
|
|
2068
|
-
if (known !== void 0 && known.op !== OP_PHANTOM)
|
|
2069
|
-
if (unknownProps === "error") return FAIL;
|
|
2070
|
-
pendingStrips.push(value, key);
|
|
2215
|
+
if (known !== void 0 && known.op !== OP_PHANTOM) count++;
|
|
2071
2216
|
}
|
|
2072
2217
|
}
|
|
2073
|
-
return
|
|
2218
|
+
return countFails(count, plan.m0, plan.m1);
|
|
2074
2219
|
}
|
|
2075
2220
|
/** Plan counterpart of {@link fastCheckArray}. */ function checkArray(plan, value, flags, opts) {
|
|
2076
2221
|
if (!Array.isArray(value)) return FAIL;
|
|
@@ -2080,6 +2225,147 @@ function setMetaKeys(plan, k0, k1, k2, k3, k4) {
|
|
|
2080
2225
|
return checkItems(plan.ofPlan, value, flags, opts);
|
|
2081
2226
|
}
|
|
2082
2227
|
|
|
2228
|
+
//#endregion
|
|
2229
|
+
//#region packages/typescript/src/runtime/validator-messages.ts
|
|
2230
|
+
/**
|
|
2231
|
+
* Validator error codes, their default English templates and the translation helpers.
|
|
2232
|
+
*
|
|
2233
|
+
* The validator is locale-agnostic: every error it reports carries a stable `code` and the
|
|
2234
|
+
* `params` its message needs, and its `message` is the default English text (the code's
|
|
2235
|
+
* template filled with the params) or the app's own text from an annotation (`custom: true`).
|
|
2236
|
+
* Translate after the fact with {@link localizeErrors}, or per validator with the `translate`
|
|
2237
|
+
* option.
|
|
2238
|
+
*/ /**
|
|
2239
|
+
* Default English templates of the built-in error codes. `{name}` is replaced with
|
|
2240
|
+
* `params.name` (see {@link formatValidatorMessage}).
|
|
2241
|
+
*/ const VALIDATOR_MESSAGES = Object.freeze({
|
|
2242
|
+
REQUIRED: "Must not be empty",
|
|
2243
|
+
REQUIRED_CHECKED: "Must be checked",
|
|
2244
|
+
TYPE: "Expected {expected}, got {actual}",
|
|
2245
|
+
TYPE_ARRAY: "Expected array",
|
|
2246
|
+
TYPE_OBJECT: "Expected object",
|
|
2247
|
+
TYPE_DECIMAL: "Expected string (decimal), got {actual}",
|
|
2248
|
+
NOT_FINITE: "Expected finite number, got {actual}",
|
|
2249
|
+
DECIMAL_FORMAT: "Invalid decimal format: \"{value}\"",
|
|
2250
|
+
NEVER: "This type is impossible, must be an internal problem",
|
|
2251
|
+
LITERAL: "Expected {expected}, got {actual}",
|
|
2252
|
+
UNION: "Value does not match any of the allowed types: {expected}",
|
|
2253
|
+
UNION_DISCRIMINATOR: "Expected one of {allowed}, got {actual}",
|
|
2254
|
+
UNEXPECTED_PROPERTY: "Unexpected property",
|
|
2255
|
+
TUPLE_LENGTH: "Expected array of length {length}",
|
|
2256
|
+
MIN_LENGTH: "Expected minimum length of {min} characters, got {actual} characters",
|
|
2257
|
+
MAX_LENGTH: "Expected maximum length of {max} characters, got {actual} characters",
|
|
2258
|
+
MIN_ITEMS: "Expected minimum length of {min} items, got {actual} items",
|
|
2259
|
+
MAX_ITEMS: "Expected maximum length of {max} items, got {actual} items",
|
|
2260
|
+
UNIQUE_ITEMS: "Duplicate items are not allowed",
|
|
2261
|
+
MIN_KEYS: "Expected at least {min} properties, got {actual}",
|
|
2262
|
+
MAX_KEYS: "Expected at most {max} properties, got {actual}",
|
|
2263
|
+
PATTERN: "Value is expected to match pattern \"{pattern}\"",
|
|
2264
|
+
INT: "Expected integer, got {actual}",
|
|
2265
|
+
MIN: "Expected minimum {min}, got {actual}",
|
|
2266
|
+
MAX: "Expected maximum {max}, got {actual}",
|
|
2267
|
+
EXCLUSIVE_MIN: "Expected greater than {min}, got {actual}",
|
|
2268
|
+
EXCLUSIVE_MAX: "Expected less than {max}, got {actual}",
|
|
2269
|
+
EMAIL: "Invalid email format.",
|
|
2270
|
+
PHONE: "Invalid phone number format.",
|
|
2271
|
+
DATE: "Invalid date format.",
|
|
2272
|
+
ISO_DATE: "Invalid ISO date format.",
|
|
2273
|
+
UUID: "Invalid UUID format.",
|
|
2274
|
+
URL: "Invalid URL format.",
|
|
2275
|
+
IPV4: "Invalid IPv4 address.",
|
|
2276
|
+
IPV6: "Invalid IPv6 address.",
|
|
2277
|
+
IP: "Invalid IP address."
|
|
2278
|
+
});
|
|
2279
|
+
/**
|
|
2280
|
+
* The built-in validator error codes by name (`VALIDATOR_ERROR_CODES.MIN_LENGTH === 'MIN_LENGTH'`).
|
|
2281
|
+
* `CUSTOM` is the code of an error a validator plugin reports without a code of its own.
|
|
2282
|
+
*/ const VALIDATOR_ERROR_CODES = Object.freeze(Object.fromEntries([...Object.keys(VALIDATOR_MESSAGES), "CUSTOM"].map((code) => [code, code])));
|
|
2283
|
+
/**
|
|
2284
|
+
* Codes of the format messages built into the `string.*` primitives, by their English text
|
|
2285
|
+
* (the primitives' `@expect.pattern` message).
|
|
2286
|
+
*/ const FORMAT_CODES = new Map([
|
|
2287
|
+
"EMAIL",
|
|
2288
|
+
"PHONE",
|
|
2289
|
+
"DATE",
|
|
2290
|
+
"ISO_DATE",
|
|
2291
|
+
"UUID",
|
|
2292
|
+
"URL",
|
|
2293
|
+
"IPV4",
|
|
2294
|
+
"IPV6",
|
|
2295
|
+
"IP"
|
|
2296
|
+
].map((code) => [VALIDATOR_MESSAGES[code], code]));
|
|
2297
|
+
/** The code of a primitive's built-in format message (`string.email`'s → `EMAIL`), if it is one. */ function formatCodeOf(message) {
|
|
2298
|
+
return FORMAT_CODES.get(message);
|
|
2299
|
+
}
|
|
2300
|
+
/**
|
|
2301
|
+
* Fills a message template: each `{name}` becomes `params.name` (arrays: their items joined
|
|
2302
|
+
* with `, `). A placeholder without a param stays as it is.
|
|
2303
|
+
*/ function formatValidatorMessage(template, params) {
|
|
2304
|
+
if (params === void 0) return template;
|
|
2305
|
+
const parts = BUILTIN_PARTS.get(template);
|
|
2306
|
+
if (parts === void 0) return template.includes("{") ? template.replaceAll(PLACEHOLDER, fill(params)) : template;
|
|
2307
|
+
let out = parts[0];
|
|
2308
|
+
for (let i = 1; i < parts.length; i += 2) out += paramText(params, parts[i]) + parts[i + 1];
|
|
2309
|
+
return out;
|
|
2310
|
+
}
|
|
2311
|
+
const PLACEHOLDER = /\{(\w+)\}/g;
|
|
2312
|
+
/** The replacer of {@link PLACEHOLDER} over `params`. */ function fill(params) {
|
|
2313
|
+
return (_match, name) => paramText(params, name);
|
|
2314
|
+
}
|
|
2315
|
+
/** The text of placeholder `name` (the placeholder itself without the param). */ function paramText(params, name) {
|
|
2316
|
+
if (!Object.hasOwn(params, name)) return `{${name}}`;
|
|
2317
|
+
const value = params[name];
|
|
2318
|
+
return Array.isArray(value) ? value.map(String).join(", ") : String(value);
|
|
2319
|
+
}
|
|
2320
|
+
/**
|
|
2321
|
+
* The {@link VALIDATOR_MESSAGES} templates with placeholders, split at them: text, name, text,
|
|
2322
|
+
* name, …, text (`'a {b} c'.split(/\{(\w+)\}/)`).
|
|
2323
|
+
*/ const BUILTIN_PARTS = new Map(Object.values(VALIDATOR_MESSAGES).filter((template) => template.includes("{")).map((template) => [template, template.split(/\{(\w+)\}/)]));
|
|
2324
|
+
/**
|
|
2325
|
+
* Returns `errors` with translated messages (new objects; `details` too): `translate` gets
|
|
2326
|
+
* each error's code (or its message text, for app text — see {@link TValidatorTranslate}),
|
|
2327
|
+
* params and the error itself. Errors it returns `undefined` for keep their message.
|
|
2328
|
+
*
|
|
2329
|
+
* @example
|
|
2330
|
+
* ```ts
|
|
2331
|
+
* const errors = localizeErrors(validator.errors, (id, params) =>
|
|
2332
|
+
* i18n.exists(id) ? i18n.t(id, params) : undefined
|
|
2333
|
+
* )
|
|
2334
|
+
* ```
|
|
2335
|
+
*/ function localizeErrors(errors, translate) {
|
|
2336
|
+
return errors.map((error) => {
|
|
2337
|
+
const id = error.custom || error.code === void 0 ? error.message : error.code;
|
|
2338
|
+
const out = { ...error };
|
|
2339
|
+
if (error.params !== void 0) out.params = copyValue(error.params);
|
|
2340
|
+
const message = translate(id, out.params ?? {}, out);
|
|
2341
|
+
if (message !== void 0) out.message = message;
|
|
2342
|
+
if (error.details) out.details = localizeErrors(error.details, translate);
|
|
2343
|
+
return out;
|
|
2344
|
+
});
|
|
2345
|
+
}
|
|
2346
|
+
/** A copy of `value`: plain objects and arrays copied, at any depth (error params). */ function copyValue(value) {
|
|
2347
|
+
if (Array.isArray(value)) return value.map(copyValue);
|
|
2348
|
+
if (typeof value === "object" && value !== null) {
|
|
2349
|
+
const out = {};
|
|
2350
|
+
for (const [key, item] of Object.entries(value)) out[key] = copyValue(item);
|
|
2351
|
+
return out;
|
|
2352
|
+
}
|
|
2353
|
+
return value;
|
|
2354
|
+
}
|
|
2355
|
+
/**
|
|
2356
|
+
* A {@link TValidatorTranslate} over a map of message templates keyed by code (and, for app
|
|
2357
|
+
* text, by the text itself): `{name}` placeholders are filled from the error's params. Ids
|
|
2358
|
+
* missing from the map keep their message.
|
|
2359
|
+
*
|
|
2360
|
+
* @example
|
|
2361
|
+
* ```ts
|
|
2362
|
+
* // templates served per locale, e.g. { MIN_LENGTH: 'Mindestens {min} Zeichen', … }
|
|
2363
|
+
* localizeErrors(errors, messagesTranslator(templates))
|
|
2364
|
+
* ```
|
|
2365
|
+
*/ function messagesTranslator(messages) {
|
|
2366
|
+
return (id, params) => Object.hasOwn(messages, id) ? formatValidatorMessage(messages[id], params) : void 0;
|
|
2367
|
+
}
|
|
2368
|
+
|
|
2083
2369
|
//#endregion
|
|
2084
2370
|
//#region packages/typescript/src/runtime/validator.ts
|
|
2085
2371
|
function _define_property(obj, key, value) {
|
|
@@ -2127,36 +2413,67 @@ function _define_property(obj, key, value) {
|
|
|
2127
2413
|
pop(saveErrors) {
|
|
2128
2414
|
this.depth--;
|
|
2129
2415
|
const popped = this.stackErrors.pop();
|
|
2130
|
-
if (saveErrors && popped
|
|
2416
|
+
if (saveErrors && popped) this.reportAll(popped);
|
|
2131
2417
|
return popped;
|
|
2132
2418
|
}
|
|
2133
2419
|
clear() {
|
|
2134
2420
|
this.stackErrors[this.stackErrors.length - 1] = null;
|
|
2135
2421
|
if (this.limitExceeded) this.limitExceeded = false;
|
|
2136
2422
|
}
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
this.stackErrors[this.stackErrors.length - 1] = errors;
|
|
2142
|
-
} else errors = this.errors;
|
|
2423
|
+
/**
|
|
2424
|
+
* Reports an error at `path` (default: the current path). `info` gives its code and params;
|
|
2425
|
+
* without it the error is app text with code `CUSTOM` (a plugin's own message).
|
|
2426
|
+
*/ error(message, path, details, info) {
|
|
2143
2427
|
const error = {
|
|
2144
2428
|
path: path || this.buildPath(),
|
|
2145
|
-
message
|
|
2429
|
+
message,
|
|
2430
|
+
code: info?.code ?? "CUSTOM",
|
|
2431
|
+
params: info?.params ?? {}
|
|
2146
2432
|
};
|
|
2433
|
+
if (info?.custom ?? info?.code === void 0) error.custom = true;
|
|
2147
2434
|
if (details?.length) error.details = details;
|
|
2148
|
-
|
|
2149
|
-
if (errors.length >= this.opts.errorLimit) this.limitExceeded = true;
|
|
2435
|
+
this.report(error);
|
|
2150
2436
|
return error;
|
|
2151
2437
|
}
|
|
2152
|
-
/**
|
|
2438
|
+
/**
|
|
2439
|
+
* Reports built-in error `code`: `custom` (the app's message from an annotation) when given,
|
|
2440
|
+
* else the code's template filled with `params`.
|
|
2441
|
+
*/ fail(code, params, custom) {
|
|
2442
|
+
this.builtin(code, params, custom);
|
|
2443
|
+
return false;
|
|
2444
|
+
}
|
|
2445
|
+
/** Reports built-in error `code` at `path` (see {@link fail}), with `details` (a union's). */ builtin(code, params, custom, path, details) {
|
|
2446
|
+
return custom ? this.error(custom, path, details, {
|
|
2447
|
+
code,
|
|
2448
|
+
params,
|
|
2449
|
+
custom: true
|
|
2450
|
+
}) : this.error(formatValidatorMessage(VALIDATOR_MESSAGES[code], params), path, details, {
|
|
2451
|
+
code,
|
|
2452
|
+
params
|
|
2453
|
+
});
|
|
2454
|
+
}
|
|
2455
|
+
/** {@link fail} of a type mismatch of `def`: its `@expect.message` replaces the message. */ mismatch(def, code, params) {
|
|
2456
|
+
return this.fail(code, params, expectMessage(def));
|
|
2457
|
+
}
|
|
2458
|
+
/** The `@meta.required` error of `def` (custom message or the type's default). */ required(def) {
|
|
2459
|
+
const isBoolean = def.type.kind === "" && def.type.designType === "boolean";
|
|
2460
|
+
return this.fail(isBoolean ? "REQUIRED_CHECKED" : "REQUIRED", {}, messageOf(def.metadata.get("meta.required")));
|
|
2461
|
+
}
|
|
2462
|
+
/**
|
|
2463
|
+
* Adds `error`, already made, to the errors of the current level (as {@link error} does);
|
|
2464
|
+
* `true` once the level holds as many errors as the limit.
|
|
2465
|
+
*/ report(error) {
|
|
2153
2466
|
let errors = this.stackErrors[this.stackErrors.length - 1];
|
|
2154
2467
|
if (!errors) if (this.stackErrors.length > 0) {
|
|
2155
2468
|
errors = [];
|
|
2156
2469
|
this.stackErrors[this.stackErrors.length - 1] = errors;
|
|
2157
2470
|
} else errors = this.errors;
|
|
2158
2471
|
errors.push(error);
|
|
2159
|
-
if (errors.length >= this.opts.errorLimit)
|
|
2472
|
+
if (errors.length >= this.opts.errorLimit) {
|
|
2473
|
+
this.limitExceeded = true;
|
|
2474
|
+
return true;
|
|
2475
|
+
}
|
|
2476
|
+
return false;
|
|
2160
2477
|
}
|
|
2161
2478
|
throw() {
|
|
2162
2479
|
throw new ValidatorError(this.errors);
|
|
@@ -2186,6 +2503,7 @@ function _define_property(obj, key, value) {
|
|
|
2186
2503
|
if (this.unionMemo !== void 0) this.unionMemo = void 0;
|
|
2187
2504
|
if (this.strips.length > 0) performStrips(this.strips, passed);
|
|
2188
2505
|
if (!passed) {
|
|
2506
|
+
if (this.opts.translate) this.errors = localizeErrors(this.errors, this.opts.translate);
|
|
2189
2507
|
if (safe) return false;
|
|
2190
2508
|
this.throw();
|
|
2191
2509
|
}
|
|
@@ -2203,10 +2521,7 @@ function _define_property(obj, key, value) {
|
|
|
2203
2521
|
if (this.limitExceeded) return false;
|
|
2204
2522
|
if (this.hasReplace) def = this.replaced(def);
|
|
2205
2523
|
if (def.optional && (value === void 0 || value === null)) {
|
|
2206
|
-
if (value === null && rejectsNullAsRequired(def))
|
|
2207
|
-
this.error(requiredMessage(def));
|
|
2208
|
-
return false;
|
|
2209
|
-
}
|
|
2524
|
+
if (value === null && rejectsNullAsRequired(def)) return this.required(def);
|
|
2210
2525
|
return true;
|
|
2211
2526
|
}
|
|
2212
2527
|
if (this.hasPlugins) {
|
|
@@ -2220,10 +2535,7 @@ function _define_property(obj, key, value) {
|
|
|
2220
2535
|
* optional `def` passes `undefined` / `null`, a plugin may decide — `undefined` to go on.
|
|
2221
2536
|
*/ preCheck(def, value) {
|
|
2222
2537
|
if (def.optional && (value === void 0 || value === null)) {
|
|
2223
|
-
if (value === null && rejectsNullAsRequired(def))
|
|
2224
|
-
this.error(requiredMessage(def));
|
|
2225
|
-
return false;
|
|
2226
|
-
}
|
|
2538
|
+
if (value === null && rejectsNullAsRequired(def)) return this.required(def);
|
|
2227
2539
|
return true;
|
|
2228
2540
|
}
|
|
2229
2541
|
if (this.hasPlugins) {
|
|
@@ -2245,7 +2557,7 @@ function _define_property(obj, key, value) {
|
|
|
2245
2557
|
if (!passed && this.strips.length !== kept) this.strips.length = kept;
|
|
2246
2558
|
return passed;
|
|
2247
2559
|
},
|
|
2248
|
-
error: (message, path, details) => this.error(message, path, details)
|
|
2560
|
+
error: (message, path, details, info) => this.error(message, path, details, info)
|
|
2249
2561
|
}, {
|
|
2250
2562
|
opts: {
|
|
2251
2563
|
get: () => this.opts,
|
|
@@ -2310,11 +2622,11 @@ function _define_property(obj, key, value) {
|
|
|
2310
2622
|
path = this.buildPath();
|
|
2311
2623
|
const known = this.decided(def, value, path);
|
|
2312
2624
|
if (known !== void 0) {
|
|
2313
|
-
if (known.
|
|
2625
|
+
if (known.errors === void 0) {
|
|
2314
2626
|
stripAgain(this.strips, known.strips);
|
|
2315
2627
|
return this.validateUnionConstraints(def, known.item, value);
|
|
2316
2628
|
}
|
|
2317
|
-
this.
|
|
2629
|
+
this.reportAll(known.errors);
|
|
2318
2630
|
return false;
|
|
2319
2631
|
}
|
|
2320
2632
|
}
|
|
@@ -2323,6 +2635,11 @@ function _define_property(obj, key, value) {
|
|
|
2323
2635
|
} else this.wasted = 0;
|
|
2324
2636
|
const kept = this.strips.length;
|
|
2325
2637
|
let details;
|
|
2638
|
+
/**
|
|
2639
|
+
* Where each failed branch's errors start in `details` (by branch index): plain object
|
|
2640
|
+
* values only, the ones a discriminator can report (see `discriminatedErrors`).
|
|
2641
|
+
*/ let starts;
|
|
2642
|
+
const plainObject = typeof value === "object" && value !== null && !Array.isArray(value);
|
|
2326
2643
|
for (const item of items) {
|
|
2327
2644
|
this.stackErrors.push(null);
|
|
2328
2645
|
const failures = this.nestedFailures;
|
|
@@ -2339,14 +2656,52 @@ function _define_property(obj, key, value) {
|
|
|
2339
2656
|
if (this.limitExceeded) this.limitExceeded = false;
|
|
2340
2657
|
if (this.nestedFailures !== failures) this.wasteBranch();
|
|
2341
2658
|
if (nested) this.nestedFailures++;
|
|
2659
|
+
if (plainObject) (starts ?? (starts = [])).push(details?.length ?? 0);
|
|
2342
2660
|
if (branchErrors) if (details) for (const err of branchErrors) details.push(err);
|
|
2343
2661
|
else details = branchErrors;
|
|
2344
2662
|
}
|
|
2345
|
-
const
|
|
2346
|
-
|
|
2347
|
-
if (path !== void 0) this.decide(def, value, path, kept, void 0, error);
|
|
2663
|
+
const errors = this.discriminatedErrors(def, value, details, starts ?? []) ?? this.unionError(def, details);
|
|
2664
|
+
if (path !== void 0) this.decide(def, value, path, kept, void 0, errors);
|
|
2348
2665
|
return false;
|
|
2349
2666
|
}
|
|
2667
|
+
/** Reports the error of union `def` no branch matched (`details`: the branches' errors). */ unionError(def, details) {
|
|
2668
|
+
const expected = def.type.items.map((item, i) => `[${item.type.kind || item.type.designType}(${i})]`).join(", ");
|
|
2669
|
+
return [this.builtin("UNION", { expected }, expectMessage(def), void 0, details)];
|
|
2670
|
+
}
|
|
2671
|
+
/**
|
|
2672
|
+
* The errors of an object union over object `value` with a shared literal discriminator (see
|
|
2673
|
+
* {@link unionDiscriminator}), reported in place of the union error: the errors of the branch
|
|
2674
|
+
* the value's discriminator picks, or one `UNION_DISCRIMINATOR` error at the discriminator
|
|
2675
|
+
* when it picks none. `undefined` (nothing reported) for other unions and values.
|
|
2676
|
+
*/ discriminatedErrors(def, value, details, starts) {
|
|
2677
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return;
|
|
2678
|
+
const disc = unionDiscriminator(def.type.items);
|
|
2679
|
+
if (disc === void 0) return;
|
|
2680
|
+
const tag = value[disc.property];
|
|
2681
|
+
if (tag === void 0 && this.partialHere()) return;
|
|
2682
|
+
const picked = disc.branches.findIndex(([, literal]) => literal === tag);
|
|
2683
|
+
if (picked < 0) {
|
|
2684
|
+
const params = {
|
|
2685
|
+
property: disc.property,
|
|
2686
|
+
allowed: disc.branches.map(([, literal]) => literal),
|
|
2687
|
+
actual: clip(printValue(tag))
|
|
2688
|
+
};
|
|
2689
|
+
const at = this.depth > 0 ? `${this.buildPath()}.${disc.property}` : disc.property;
|
|
2690
|
+
return [this.builtin("UNION_DISCRIMINATOR", params, expectMessage(def), at)];
|
|
2691
|
+
}
|
|
2692
|
+
const index = disc.branches[picked][0];
|
|
2693
|
+
const errors = details?.slice(starts[index], starts[index + 1] ?? details.length);
|
|
2694
|
+
if (errors === void 0 || errors.length === 0) return;
|
|
2695
|
+
this.reportAll(errors);
|
|
2696
|
+
return errors;
|
|
2697
|
+
}
|
|
2698
|
+
/** Reports `errors`, made already, until the error limit is reached. */ reportAll(errors) {
|
|
2699
|
+
for (const error of errors) if (this.report(error)) break;
|
|
2700
|
+
}
|
|
2701
|
+
/** Whether missing props are allowed at the current depth (the `partial` option). */ partialHere() {
|
|
2702
|
+
const partial = this.opts.partial;
|
|
2703
|
+
return partial === "deep" || partial === true && this.depth === 0 || typeof partial === "function";
|
|
2704
|
+
}
|
|
2350
2705
|
/** A union branch failed after branches of nested unions over objects did (see `unionMemo`). */ wasteBranch() {
|
|
2351
2706
|
if (++this.wasted === WASTE_BEFORE_MEMO && this.unionMemo === void 0) this.unionMemo = /* @__PURE__ */ new Map();
|
|
2352
2707
|
}
|
|
@@ -2360,13 +2715,13 @@ function _define_property(obj, key, value) {
|
|
|
2360
2715
|
/**
|
|
2361
2716
|
* Records the outcome of union `def` over `value` at `path`, entered with `kept` strips (the
|
|
2362
2717
|
* ones after them are its own).
|
|
2363
|
-
*/ decide(def, value, path, kept, item,
|
|
2718
|
+
*/ decide(def, value, path, kept, item, errors) {
|
|
2364
2719
|
const outcome = {
|
|
2365
2720
|
def,
|
|
2366
2721
|
path,
|
|
2367
2722
|
unknownProps: this.opts.unknownProps,
|
|
2368
2723
|
item,
|
|
2369
|
-
|
|
2724
|
+
errors,
|
|
2370
2725
|
strips: stripsSince(this.strips, kept)
|
|
2371
2726
|
};
|
|
2372
2727
|
const outcomes = this.unionMemo.get(value);
|
|
@@ -2386,7 +2741,7 @@ function _define_property(obj, key, value) {
|
|
|
2386
2741
|
case "boolean": return this.validateBooleanConstraints(metadata, value);
|
|
2387
2742
|
case "object":
|
|
2388
2743
|
if (Array.isArray(value)) return this.validateArrayConstraints(metadata, value, arrayElementType(branch));
|
|
2389
|
-
return
|
|
2744
|
+
return value === null || this.validateObjectConstraints(metadata, value, branch, this.skipListHere());
|
|
2390
2745
|
default: return true;
|
|
2391
2746
|
}
|
|
2392
2747
|
}
|
|
@@ -2400,7 +2755,7 @@ function _define_property(obj, key, value) {
|
|
|
2400
2755
|
*/ unknownKey(key, keysToStrip) {
|
|
2401
2756
|
if (this.opts.unknownProps === "error") {
|
|
2402
2757
|
this.push(key);
|
|
2403
|
-
this.
|
|
2758
|
+
this.fail("UNEXPECTED_PROPERTY", { property: clip(key) });
|
|
2404
2759
|
this.pop(true);
|
|
2405
2760
|
} else if (this.opts.unknownProps === "strip") (keysToStrip ?? (keysToStrip = [])).push(key);
|
|
2406
2761
|
return keysToStrip;
|
|
@@ -2413,10 +2768,7 @@ function _define_property(obj, key, value) {
|
|
|
2413
2768
|
return skipList;
|
|
2414
2769
|
}
|
|
2415
2770
|
validateTuple(def, value) {
|
|
2416
|
-
if (!Array.isArray(value) || value.length !== def.type.items.length) {
|
|
2417
|
-
this.error(`Expected array of length ${def.type.items.length}`);
|
|
2418
|
-
return false;
|
|
2419
|
-
}
|
|
2771
|
+
if (!Array.isArray(value) || value.length !== def.type.items.length) return this.mismatch(def, "TUPLE_LENGTH", { length: def.type.items.length });
|
|
2420
2772
|
let i = 0;
|
|
2421
2773
|
for (const item of def.type.items) {
|
|
2422
2774
|
this.push(String(i));
|
|
@@ -2430,10 +2782,7 @@ function _define_property(obj, key, value) {
|
|
|
2430
2782
|
return true;
|
|
2431
2783
|
}
|
|
2432
2784
|
validateArray(def, value) {
|
|
2433
|
-
if (!Array.isArray(value)) {
|
|
2434
|
-
this.error("Expected array");
|
|
2435
|
-
return false;
|
|
2436
|
-
}
|
|
2785
|
+
if (!Array.isArray(value)) return this.mismatch(def, "TYPE_ARRAY", { actual: typeOf(value) });
|
|
2437
2786
|
if (!metaEmpty(def.metadata) && !this.validateArrayConstraints(def.metadata, value, def.type.of)) return false;
|
|
2438
2787
|
let i = 0;
|
|
2439
2788
|
let passed = true;
|
|
@@ -2452,21 +2801,19 @@ function _define_property(obj, key, value) {
|
|
|
2452
2801
|
const metadata = readable(meta);
|
|
2453
2802
|
const minLength = metadata.get("expect.minLength");
|
|
2454
2803
|
if (minLength !== void 0) {
|
|
2455
|
-
const length =
|
|
2456
|
-
if (value.length < length) {
|
|
2457
|
-
|
|
2458
|
-
|
|
2459
|
-
|
|
2460
|
-
}
|
|
2804
|
+
const length = boundOf(minLength, "length");
|
|
2805
|
+
if (value.length < length) return this.fail("MIN_ITEMS", {
|
|
2806
|
+
min: length,
|
|
2807
|
+
actual: value.length
|
|
2808
|
+
}, messageOf(minLength));
|
|
2461
2809
|
}
|
|
2462
2810
|
const maxLength = metadata.get("expect.maxLength");
|
|
2463
2811
|
if (maxLength !== void 0) {
|
|
2464
|
-
const length =
|
|
2465
|
-
if (value.length > length) {
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
}
|
|
2812
|
+
const length = boundOf(maxLength, "length");
|
|
2813
|
+
if (value.length > length) return this.fail("MAX_ITEMS", {
|
|
2814
|
+
max: length,
|
|
2815
|
+
actual: value.length
|
|
2816
|
+
}, messageOf(maxLength));
|
|
2470
2817
|
}
|
|
2471
2818
|
const uniqueItems = metadata.get("expect.array.uniqueItems");
|
|
2472
2819
|
if (uniqueItems) {
|
|
@@ -2482,7 +2829,7 @@ function _define_property(obj, key, value) {
|
|
|
2482
2829
|
} else key = JSON.stringify(item);
|
|
2483
2830
|
if (seen.has(key)) {
|
|
2484
2831
|
this.push(String(idx));
|
|
2485
|
-
this.
|
|
2832
|
+
this.fail("UNIQUE_ITEMS", {}, messageOf(uniqueItems));
|
|
2486
2833
|
this.pop(true);
|
|
2487
2834
|
return false;
|
|
2488
2835
|
}
|
|
@@ -2492,13 +2839,14 @@ function _define_property(obj, key, value) {
|
|
|
2492
2839
|
return true;
|
|
2493
2840
|
}
|
|
2494
2841
|
validateObject(def, value) {
|
|
2495
|
-
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
2496
|
-
|
|
2497
|
-
return false;
|
|
2498
|
-
}
|
|
2842
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return this.mismatch(def, "TYPE_OBJECT", { actual: typeOf(value) });
|
|
2843
|
+
const skipList = this.opts.skipList ? this.skipListHere() : void 0;
|
|
2499
2844
|
let passed = true;
|
|
2845
|
+
if (!this.validateObjectConstraints(def.metadata, value, def, skipList)) {
|
|
2846
|
+
if (this.limitExceeded) return false;
|
|
2847
|
+
passed = false;
|
|
2848
|
+
}
|
|
2500
2849
|
let keysToStrip;
|
|
2501
|
-
const skipList = this.opts.skipList ? this.skipListHere() : void 0;
|
|
2502
2850
|
let partialFunctionMatched = false;
|
|
2503
2851
|
if (typeof this.opts.partial === "function") partialFunctionMatched = this.opts.partial(def, this.buildPath());
|
|
2504
2852
|
for (const [key, item] of def.type.props.entries()) {
|
|
@@ -2558,63 +2906,58 @@ function _define_property(obj, key, value) {
|
|
|
2558
2906
|
}
|
|
2559
2907
|
validatePrimitive(def, value) {
|
|
2560
2908
|
if (def.type.value !== void 0) {
|
|
2561
|
-
if (value !== def.type.value) {
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
}
|
|
2909
|
+
if (value !== def.type.value) return this.mismatch(def, "LITERAL", {
|
|
2910
|
+
expected: def.type.value,
|
|
2911
|
+
actual: clip(printValue(value))
|
|
2912
|
+
});
|
|
2565
2913
|
return true;
|
|
2566
2914
|
}
|
|
2567
|
-
const typeOfValue =
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2915
|
+
const typeOfValue = typeOf(value);
|
|
2916
|
+
const designType = def.type.designType;
|
|
2917
|
+
switch (designType) {
|
|
2918
|
+
case "never": return this.fail("NEVER", {});
|
|
2919
|
+
case "any":
|
|
2920
|
+
if (value === void 0) return this.mismatch(def, "TYPE", {
|
|
2921
|
+
expected: "unknown",
|
|
2922
|
+
actual: typeOfValue
|
|
2923
|
+
});
|
|
2924
|
+
return true;
|
|
2573
2925
|
case "string":
|
|
2574
|
-
if (typeOfValue !==
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
}
|
|
2926
|
+
if (typeOfValue !== designType) return this.mismatch(def, "TYPE", {
|
|
2927
|
+
expected: designType,
|
|
2928
|
+
actual: typeOfValue
|
|
2929
|
+
});
|
|
2578
2930
|
return this.validateString(def, value);
|
|
2579
2931
|
case "number":
|
|
2580
|
-
if (typeOfValue !==
|
|
2581
|
-
|
|
2582
|
-
|
|
2583
|
-
}
|
|
2584
|
-
if (!Number.isFinite(value)) {
|
|
2585
|
-
this.error(`Expected finite number, got ${value}`);
|
|
2586
|
-
return false;
|
|
2587
|
-
}
|
|
2932
|
+
if (typeOfValue !== designType) return this.mismatch(def, "TYPE", {
|
|
2933
|
+
expected: designType,
|
|
2934
|
+
actual: typeOfValue
|
|
2935
|
+
});
|
|
2936
|
+
if (!Number.isFinite(value)) return this.mismatch(def, "NOT_FINITE", { actual: String(value) });
|
|
2588
2937
|
return this.validateNumber(def, value);
|
|
2589
2938
|
case "boolean":
|
|
2590
|
-
if (typeOfValue !==
|
|
2591
|
-
|
|
2592
|
-
|
|
2593
|
-
}
|
|
2939
|
+
if (typeOfValue !== designType) return this.mismatch(def, "TYPE", {
|
|
2940
|
+
expected: designType,
|
|
2941
|
+
actual: typeOfValue
|
|
2942
|
+
});
|
|
2594
2943
|
return this.validateBoolean(def, value);
|
|
2595
2944
|
case "undefined":
|
|
2596
|
-
if (value !== void 0) {
|
|
2597
|
-
|
|
2598
|
-
|
|
2599
|
-
}
|
|
2945
|
+
if (value !== void 0) return this.mismatch(def, "TYPE", {
|
|
2946
|
+
expected: designType,
|
|
2947
|
+
actual: typeOfValue
|
|
2948
|
+
});
|
|
2600
2949
|
return true;
|
|
2601
2950
|
case "null":
|
|
2602
|
-
if (value !== null) {
|
|
2603
|
-
|
|
2604
|
-
|
|
2605
|
-
}
|
|
2951
|
+
if (value !== null) return this.mismatch(def, "TYPE", {
|
|
2952
|
+
expected: designType,
|
|
2953
|
+
actual: typeOfValue
|
|
2954
|
+
});
|
|
2606
2955
|
return true;
|
|
2607
2956
|
case "decimal":
|
|
2608
|
-
if (typeOfValue !== "string") {
|
|
2609
|
-
|
|
2610
|
-
return false;
|
|
2611
|
-
}
|
|
2612
|
-
if (!DECIMAL_RE.test(value)) {
|
|
2613
|
-
this.error(`Invalid decimal format: ${JSON.stringify(value)}`);
|
|
2614
|
-
return false;
|
|
2615
|
-
}
|
|
2957
|
+
if (typeOfValue !== "string") return this.mismatch(def, "TYPE_DECIMAL", { actual: typeOfValue });
|
|
2958
|
+
if (!DECIMAL_RE.test(value)) return this.mismatch(def, "DECIMAL_FORMAT", { value: clip(value) });
|
|
2616
2959
|
return true;
|
|
2617
|
-
default: throw new Error(`Unknown type "${
|
|
2960
|
+
default: throw new Error(`Unknown type "${designType}"`);
|
|
2618
2961
|
}
|
|
2619
2962
|
}
|
|
2620
2963
|
validateString(def, value) {
|
|
@@ -2625,36 +2968,33 @@ function _define_property(obj, key, value) {
|
|
|
2625
2968
|
if (metadata === void 0) return true;
|
|
2626
2969
|
const filled = metadata.get("meta.required");
|
|
2627
2970
|
if (filled) {
|
|
2628
|
-
if (value.trim().length === 0) {
|
|
2629
|
-
const message = typeof filled === "object" && filled.message ? filled.message : `Must not be empty`;
|
|
2630
|
-
this.error(message);
|
|
2631
|
-
return false;
|
|
2632
|
-
}
|
|
2971
|
+
if (value.trim().length === 0) return this.fail("REQUIRED", {}, messageOf(filled));
|
|
2633
2972
|
}
|
|
2634
2973
|
const minLength = metadata.get("expect.minLength");
|
|
2635
2974
|
if (minLength !== void 0) {
|
|
2636
|
-
const length =
|
|
2637
|
-
if (value.length < length) {
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
}
|
|
2975
|
+
const length = boundOf(minLength, "length");
|
|
2976
|
+
if (value.length < length) return this.fail("MIN_LENGTH", {
|
|
2977
|
+
min: length,
|
|
2978
|
+
actual: value.length
|
|
2979
|
+
}, messageOf(minLength));
|
|
2642
2980
|
}
|
|
2643
2981
|
const maxLength = metadata.get("expect.maxLength");
|
|
2644
2982
|
if (maxLength !== void 0) {
|
|
2645
|
-
const length =
|
|
2646
|
-
if (value.length > length) {
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
}
|
|
2983
|
+
const length = boundOf(maxLength, "length");
|
|
2984
|
+
if (value.length > length) return this.fail("MAX_LENGTH", {
|
|
2985
|
+
max: length,
|
|
2986
|
+
actual: value.length
|
|
2987
|
+
}, messageOf(maxLength));
|
|
2651
2988
|
}
|
|
2652
2989
|
const patterns = metadata.get("expect.pattern");
|
|
2653
2990
|
for (const { pattern, flags, message } of patterns || []) {
|
|
2654
2991
|
if (!pattern) continue;
|
|
2655
2992
|
if (!getRegex(pattern, flags).test(value)) {
|
|
2656
|
-
|
|
2657
|
-
return
|
|
2993
|
+
const format = message ? formatCodeOf(message) : void 0;
|
|
2994
|
+
return format === void 0 ? this.fail("PATTERN", flags ? {
|
|
2995
|
+
pattern,
|
|
2996
|
+
flags
|
|
2997
|
+
} : { pattern }, message) : this.fail(format, {});
|
|
2658
2998
|
}
|
|
2659
2999
|
}
|
|
2660
3000
|
return true;
|
|
@@ -2666,38 +3006,41 @@ function _define_property(obj, key, value) {
|
|
|
2666
3006
|
const metadata = filledMeta(meta);
|
|
2667
3007
|
if (metadata === void 0) return true;
|
|
2668
3008
|
const int = metadata.get("expect.int");
|
|
2669
|
-
if (int && value % 1 !== 0) {
|
|
2670
|
-
const message = typeof int === "object" && int.message ? int.message : `Expected integer, got ${value}`;
|
|
2671
|
-
this.error(message);
|
|
2672
|
-
return false;
|
|
2673
|
-
}
|
|
3009
|
+
if (int && value % 1 !== 0) return this.fail("INT", { actual: value }, messageOf(int));
|
|
2674
3010
|
const min = metadata.get("expect.min");
|
|
2675
3011
|
if (min !== void 0) {
|
|
2676
|
-
const
|
|
2677
|
-
if (value <
|
|
3012
|
+
const bound = boundOf(min, "minValue");
|
|
3013
|
+
if (value < bound) return this.fail("MIN", {
|
|
3014
|
+
min: bound,
|
|
3015
|
+
actual: value
|
|
3016
|
+
}, messageOf(min));
|
|
2678
3017
|
}
|
|
2679
3018
|
const max = metadata.get("expect.max");
|
|
2680
3019
|
if (max !== void 0) {
|
|
2681
|
-
const
|
|
2682
|
-
if (value >
|
|
3020
|
+
const bound = boundOf(max, "maxValue");
|
|
3021
|
+
if (value > bound) return this.fail("MAX", {
|
|
3022
|
+
max: bound,
|
|
3023
|
+
actual: value
|
|
3024
|
+
}, messageOf(max));
|
|
2683
3025
|
}
|
|
2684
3026
|
const exMin = metadata.get("expect.exclusiveMin");
|
|
2685
3027
|
if (exMin !== void 0) {
|
|
2686
|
-
const bound =
|
|
2687
|
-
if (value <= bound) return this.
|
|
3028
|
+
const bound = boundOf(exMin, "exclusiveMinValue");
|
|
3029
|
+
if (value <= bound) return this.fail("EXCLUSIVE_MIN", {
|
|
3030
|
+
min: bound,
|
|
3031
|
+
actual: value
|
|
3032
|
+
}, messageOf(exMin));
|
|
2688
3033
|
}
|
|
2689
3034
|
const exMax = metadata.get("expect.exclusiveMax");
|
|
2690
3035
|
if (exMax !== void 0) {
|
|
2691
|
-
const bound =
|
|
2692
|
-
if (value >= bound) return this.
|
|
3036
|
+
const bound = boundOf(exMax, "exclusiveMaxValue");
|
|
3037
|
+
if (value >= bound) return this.fail("EXCLUSIVE_MAX", {
|
|
3038
|
+
max: bound,
|
|
3039
|
+
actual: value
|
|
3040
|
+
}, messageOf(exMax));
|
|
2693
3041
|
}
|
|
2694
3042
|
return true;
|
|
2695
3043
|
}
|
|
2696
|
-
/** Reports a failed number bound: its custom message, else `Expected <label> <bound>, got <value>`. */ numberBoundFailed(annotation, label, bound, value) {
|
|
2697
|
-
const message = typeof annotation === "object" && annotation.message ? annotation.message : `Expected ${label} ${bound}, got ${value}`;
|
|
2698
|
-
this.error(message);
|
|
2699
|
-
return false;
|
|
2700
|
-
}
|
|
2701
3044
|
validateBoolean(def, value) {
|
|
2702
3045
|
return this.validateBooleanConstraints(def.metadata, value);
|
|
2703
3046
|
}
|
|
@@ -2706,14 +3049,59 @@ function _define_property(obj, key, value) {
|
|
|
2706
3049
|
if (metadata === void 0) return true;
|
|
2707
3050
|
const filled = metadata.get("meta.required");
|
|
2708
3051
|
if (filled) {
|
|
2709
|
-
if (value !== true) {
|
|
2710
|
-
const message = typeof filled === "object" && filled.message ? filled.message : `Must be checked`;
|
|
2711
|
-
this.error(message);
|
|
2712
|
-
return false;
|
|
2713
|
-
}
|
|
3052
|
+
if (value !== true) return this.fail("REQUIRED_CHECKED", {}, messageOf(filled));
|
|
2714
3053
|
}
|
|
2715
3054
|
return true;
|
|
2716
3055
|
}
|
|
3056
|
+
/**
|
|
3057
|
+
* `@expect.minKeys` / `maxKeys` checks for an object value, matched as `shape`: the keys the
|
|
3058
|
+
* result keeps are counted (see {@link keptKeyCount}; `skipList`: the skip list keys here).
|
|
3059
|
+
*/ validateObjectConstraints(meta, value, shape, skipList) {
|
|
3060
|
+
const metadata = filledMeta(meta);
|
|
3061
|
+
if (metadata === void 0) return true;
|
|
3062
|
+
const minKeys = metadata.get("expect.minKeys");
|
|
3063
|
+
const maxKeys = metadata.get("expect.maxKeys");
|
|
3064
|
+
if (minKeys === void 0 && maxKeys === void 0) return true;
|
|
3065
|
+
const count = this.keptKeyCount(shape, value, skipList);
|
|
3066
|
+
if (minKeys !== void 0) {
|
|
3067
|
+
const bound = boundOf(minKeys, "count");
|
|
3068
|
+
if (count < bound) return this.fail("MIN_KEYS", {
|
|
3069
|
+
min: bound,
|
|
3070
|
+
actual: count
|
|
3071
|
+
}, messageOf(minKeys));
|
|
3072
|
+
}
|
|
3073
|
+
if (maxKeys !== void 0) {
|
|
3074
|
+
const bound = boundOf(maxKeys, "count");
|
|
3075
|
+
if (count > bound) return this.fail("MAX_KEYS", {
|
|
3076
|
+
max: bound,
|
|
3077
|
+
actual: count
|
|
3078
|
+
}, messageOf(maxKeys));
|
|
3079
|
+
}
|
|
3080
|
+
return true;
|
|
3081
|
+
}
|
|
3082
|
+
/**
|
|
3083
|
+
* The keys of object `value` (matched as `shape`) the result keeps: every own key with
|
|
3084
|
+
* `unknownProps: 'ignore'`; else (and with 'strip', and 'error', where the others are errors
|
|
3085
|
+
* of their own) the keys `shape` declares, its pattern props match or the skip list names.
|
|
3086
|
+
* Matched as anything other than an object type, every own key.
|
|
3087
|
+
*/ keptKeyCount(shape, value, skipList) {
|
|
3088
|
+
const keys = Object.keys(value);
|
|
3089
|
+
if (this.opts.unknownProps === "ignore" || shape.type.kind !== "object") return keys.length;
|
|
3090
|
+
const type = shape.type;
|
|
3091
|
+
let count = 0;
|
|
3092
|
+
for (const key of keys) {
|
|
3093
|
+
const prop = type.props.get(key);
|
|
3094
|
+
if (prop !== void 0 && !isPhantomType(prop) || skipList?.has(key)) {
|
|
3095
|
+
count++;
|
|
3096
|
+
continue;
|
|
3097
|
+
}
|
|
3098
|
+
for (const { pattern } of type.propsPatterns) if (pattern.test(key)) {
|
|
3099
|
+
count++;
|
|
3100
|
+
break;
|
|
3101
|
+
}
|
|
3102
|
+
}
|
|
3103
|
+
return count;
|
|
3104
|
+
}
|
|
2717
3105
|
constructor(def, opts) {
|
|
2718
3106
|
_define_property(this, "def", void 0);
|
|
2719
3107
|
_define_property(this, "opts", void 0);
|
|
@@ -2768,10 +3156,78 @@ function _define_property(obj, key, value) {
|
|
|
2768
3156
|
if (this.hasReplace) this.replaceCache = /* @__PURE__ */ new WeakMap();
|
|
2769
3157
|
}
|
|
2770
3158
|
};
|
|
2771
|
-
/** The
|
|
2772
|
-
|
|
2773
|
-
|
|
2774
|
-
|
|
3159
|
+
/** The message argument of a constraint annotation (`{ message }`), if any. */ function messageOf(annotation) {
|
|
3160
|
+
return typeof annotation === "object" && annotation !== null ? annotation.message || void 0 : void 0;
|
|
3161
|
+
}
|
|
3162
|
+
/**
|
|
3163
|
+
* Decided discriminators, by union `items` (reported errors only: a union's discriminator is
|
|
3164
|
+
* looked for once its value failed). An entry is reused while the items, their type defs and the
|
|
3165
|
+
* discriminator props are the same objects.
|
|
3166
|
+
*/ const discCache = /* @__PURE__ */ new WeakMap();
|
|
3167
|
+
/**
|
|
3168
|
+
* The discriminator of a union over objects (see {@link detectDiscriminator}), required in every
|
|
3169
|
+
* object branch: the property and, per object branch, its index in `items` and its literal. The
|
|
3170
|
+
* other branches must reject any object (scalars, arrays, tuples), so only the object branches
|
|
3171
|
+
* can match an object value.
|
|
3172
|
+
*/ function unionDiscriminator(items) {
|
|
3173
|
+
const cached = discCache.get(items);
|
|
3174
|
+
if (cached !== void 0 && sameDiscSource(cached, items)) return cached.disc;
|
|
3175
|
+
const entry = {
|
|
3176
|
+
nodes: [...items],
|
|
3177
|
+
types: items.map((item) => item.type),
|
|
3178
|
+
props: [],
|
|
3179
|
+
disc: findDiscriminator(items)
|
|
3180
|
+
};
|
|
3181
|
+
if (entry.disc !== void 0) {
|
|
3182
|
+
const property = entry.disc.property;
|
|
3183
|
+
entry.props = entry.disc.branches.map(([i]) => items[i].type.props.get(property));
|
|
3184
|
+
}
|
|
3185
|
+
discCache.set(items, entry);
|
|
3186
|
+
return entry.disc;
|
|
3187
|
+
}
|
|
3188
|
+
/** Whether `entry` was decided from `items` as they are. */ function sameDiscSource(entry, items) {
|
|
3189
|
+
if (entry.nodes.length !== items.length) return false;
|
|
3190
|
+
for (let i = 0; i < items.length; i++) if (entry.nodes[i] !== items[i] || entry.types[i] !== items[i].type) return false;
|
|
3191
|
+
const disc = entry.disc;
|
|
3192
|
+
if (disc !== void 0) {
|
|
3193
|
+
const branches = disc.branches;
|
|
3194
|
+
for (let j = 0; j < branches.length; j++) if (items[branches[j][0]].type.props.get(disc.property) !== entry.props[j]) return false;
|
|
3195
|
+
}
|
|
3196
|
+
return true;
|
|
3197
|
+
}
|
|
3198
|
+
/** {@link unionDiscriminator}, decided anew. */ function findDiscriminator(items) {
|
|
3199
|
+
const objects = [];
|
|
3200
|
+
const indexes = [];
|
|
3201
|
+
for (const [i, item] of items.entries()) {
|
|
3202
|
+
const type = item.type;
|
|
3203
|
+
if (type.kind === "object") {
|
|
3204
|
+
objects.push(item);
|
|
3205
|
+
indexes.push(i);
|
|
3206
|
+
} else if (type.kind !== "array" && type.kind !== "tuple" && (type.kind !== "" || type.designType === "any" || isPhantomType(item))) return;
|
|
3207
|
+
}
|
|
3208
|
+
const disc = detectDiscriminator(objects);
|
|
3209
|
+
if (!disc) return;
|
|
3210
|
+
const property = disc.propertyName;
|
|
3211
|
+
const branches = [];
|
|
3212
|
+
for (const [j, item] of objects.entries()) {
|
|
3213
|
+
const prop = item.type.props.get(property);
|
|
3214
|
+
if (prop === void 0 || prop.optional) return;
|
|
3215
|
+
branches.push([indexes[j], prop.type.value]);
|
|
3216
|
+
}
|
|
3217
|
+
return {
|
|
3218
|
+
property,
|
|
3219
|
+
branches
|
|
3220
|
+
};
|
|
3221
|
+
}
|
|
3222
|
+
/** The most characters of input copied into params (see {@link clip}). */ const CLIP = 100;
|
|
3223
|
+
/** Input copied into params: at most {@link CLIP} characters (then an ellipsis). */ function clip(text) {
|
|
3224
|
+
return text.length > CLIP ? `${text.slice(0, CLIP)}…` : text;
|
|
3225
|
+
}
|
|
3226
|
+
/** `def`'s `@expect.message` (the message of its type mismatches), if any. */ function expectMessage(def) {
|
|
3227
|
+
return def.metadata.get("expect.message") || void 0;
|
|
3228
|
+
}
|
|
3229
|
+
/** The type name an error reports for `value` (`array` for arrays, else `typeof`). */ function typeOf(value) {
|
|
3230
|
+
return Array.isArray(value) ? "array" : typeof value;
|
|
2775
3231
|
}
|
|
2776
3232
|
/**
|
|
2777
3233
|
* Element type of the array a union branch holds — through nested unions too
|
|
@@ -3322,10 +3778,25 @@ function recordsOf(m) {
|
|
|
3322
3778
|
* A block write of an append key: the own list is the elements written before any block (by
|
|
3323
3779
|
* the builder, or a raw write since), then every block's part by rank.
|
|
3324
3780
|
*/ function appendKey(m, key, values, rank) {
|
|
3781
|
+
const r = appendRecord(m, key);
|
|
3782
|
+
const { parts } = r;
|
|
3783
|
+
let at = 0;
|
|
3784
|
+
while (at < parts.length && compare(parts[at].rank, rank) < 0) at++;
|
|
3785
|
+
if (at < parts.length && compare(parts[at].rank, rank) === 0) parts[at].values = values;
|
|
3786
|
+
else parts.splice(at, 0, {
|
|
3787
|
+
rank,
|
|
3788
|
+
values
|
|
3789
|
+
});
|
|
3790
|
+
writeAppend(m, key, r);
|
|
3791
|
+
}
|
|
3792
|
+
/**
|
|
3793
|
+
* The block record of append key `key` of `m`: a new one when a raw write since changed the own
|
|
3794
|
+
* list (the elements written before any block: the builder's, or that raw write).
|
|
3795
|
+
*/ function appendRecord(m, key) {
|
|
3325
3796
|
const recs = recordsOf(m);
|
|
3326
3797
|
let r = recs.get(key);
|
|
3327
3798
|
const own = ownValue(m, key);
|
|
3328
|
-
if (!r || own !== r.value || r.value.length !== r.length) {
|
|
3799
|
+
if (!r || own !== r.value || r.value !== void 0 && r.value.length !== r.length) {
|
|
3329
3800
|
const before = own === void 0 ? [] : Array.isArray(own) ? [...own] : [own];
|
|
3330
3801
|
r = {
|
|
3331
3802
|
before,
|
|
@@ -3333,28 +3804,59 @@ function recordsOf(m) {
|
|
|
3333
3804
|
value: before,
|
|
3334
3805
|
length: 0
|
|
3335
3806
|
};
|
|
3807
|
+
recs.set(key, r);
|
|
3808
|
+
}
|
|
3809
|
+
return r;
|
|
3810
|
+
}
|
|
3811
|
+
/** Writes append key `key`'s own list from its record: the elements, then the parts by rank. */ function writeAppend(m, key, r) {
|
|
3812
|
+
const reset = r.reset;
|
|
3813
|
+
const value = reset ? [] : [...r.before];
|
|
3814
|
+
for (const p of r.parts) if (!reset || compare(p.rank, reset) >= 0) value.push(...p.values);
|
|
3815
|
+
if (value.length > 0) {
|
|
3816
|
+
m.set(key, value);
|
|
3817
|
+
r.value = value;
|
|
3818
|
+
} else {
|
|
3819
|
+
m.delete(key);
|
|
3820
|
+
r.value = void 0;
|
|
3336
3821
|
}
|
|
3337
|
-
const { parts } = r;
|
|
3338
|
-
let at = 0;
|
|
3339
|
-
while (at < parts.length && compare(parts[at].rank, rank) < 0) at++;
|
|
3340
|
-
if (at < parts.length && compare(parts[at].rank, rank) === 0) parts[at].values = values;
|
|
3341
|
-
else parts.splice(at, 0, {
|
|
3342
|
-
rank,
|
|
3343
|
-
values
|
|
3344
|
-
});
|
|
3345
|
-
const value = [...r.before];
|
|
3346
|
-
for (const p of parts) value.push(...p.values);
|
|
3347
|
-
m.set(key, value);
|
|
3348
|
-
r.value = value;
|
|
3349
3822
|
r.length = value.length;
|
|
3350
|
-
|
|
3823
|
+
if (reset) hideKey(m, key);
|
|
3351
3824
|
}
|
|
3825
|
+
/**
|
|
3826
|
+
* `@annotate.reset 'key'` by a block of rank `rank` at the node of map `m`: the node reads as if
|
|
3827
|
+
* the key had no value below that block — none from its bases (the types it references, the
|
|
3828
|
+
* target of an `as` copy: hidden, see `hideKey`), none written on the node itself (its
|
|
3829
|
+
* declaration, lower-ranked blocks). A block ranked at or above it (the resetting block's own
|
|
3830
|
+
* values included) writes as usual; one ranked below is ignored, whatever the load order.
|
|
3831
|
+
*/ function resetKey(m, key, rank) {
|
|
3832
|
+
if (isAppendKey(key)) {
|
|
3833
|
+
const r = appendRecord(m, key);
|
|
3834
|
+
if (!r.reset || compare(r.reset, rank) < 0) r.reset = rank;
|
|
3835
|
+
writeAppend(m, key, r);
|
|
3836
|
+
return;
|
|
3837
|
+
}
|
|
3838
|
+
const recs = recordsOf(m);
|
|
3839
|
+
const r = recs.get(key);
|
|
3840
|
+
if (!(r && ownValue(m, key) === r.value && compare(r.rank, rank) > 0)) {
|
|
3841
|
+
m.delete(key);
|
|
3842
|
+
recs.set(key, {
|
|
3843
|
+
rank,
|
|
3844
|
+
value: void 0
|
|
3845
|
+
});
|
|
3846
|
+
}
|
|
3847
|
+
hideKey(m, key);
|
|
3848
|
+
}
|
|
3849
|
+
/** The block annotation resetting the annotation it names at its node (`@annotate.reset`). */ const RESET = "annotate.reset";
|
|
3352
3850
|
function writeEntry(m, anns, rank) {
|
|
3851
|
+
for (const [key, value] of anns) if (key === RESET) resetKey(m, value, rank);
|
|
3353
3852
|
const values = /* @__PURE__ */ new Map();
|
|
3354
|
-
for (const [key, value, list] of anns)
|
|
3355
|
-
|
|
3356
|
-
|
|
3357
|
-
|
|
3853
|
+
for (const [key, value, list] of anns) {
|
|
3854
|
+
if (key === RESET) continue;
|
|
3855
|
+
if (list) {
|
|
3856
|
+
const xs = values.get(key);
|
|
3857
|
+
values.set(key, xs ? [...xs, value] : [value]);
|
|
3858
|
+
} else values.set(key, value);
|
|
3859
|
+
}
|
|
3358
3860
|
for (const [key, value] of values) if (isAppendKey(key)) appendKey(m, key, Array.isArray(value) ? value : [value], rank);
|
|
3359
3861
|
else writeKey(m, key, value, rank);
|
|
3360
3862
|
}
|
|
@@ -3448,6 +3950,70 @@ const queue = [];
|
|
|
3448
3950
|
return name;
|
|
3449
3951
|
}
|
|
3450
3952
|
|
|
3953
|
+
//#endregion
|
|
3954
|
+
//#region packages/typescript/src/runtime/user-text.ts
|
|
3955
|
+
/**
|
|
3956
|
+
* The annotations holding user-facing text (labels, descriptions, error messages): the arguments
|
|
3957
|
+
* their specs flag `userText`. Core's are known from the start ({@link CORE_USER_TEXT}); a plugin's
|
|
3958
|
+
* are registered by the generated modules that write them (`$ut`), or by the plugin itself
|
|
3959
|
+
* ({@link registerUserText}), so a translator finds them at runtime without the specs.
|
|
3960
|
+
*/ /** `true`: the value itself is the text; a list: those fields of the value object are. */ /**
|
|
3961
|
+
* The user-facing text of `@atscript/core`'s annotations (its specs' `userText` arguments; a test
|
|
3962
|
+
* keeps them equal).
|
|
3963
|
+
*/ const CORE_USER_TEXT = new Map([
|
|
3964
|
+
["meta.label", true],
|
|
3965
|
+
["meta.description", true],
|
|
3966
|
+
["meta.required", ["message"]],
|
|
3967
|
+
["expect.minLength", ["message"]],
|
|
3968
|
+
["expect.maxLength", ["message"]],
|
|
3969
|
+
["expect.min", ["message"]],
|
|
3970
|
+
["expect.max", ["message"]],
|
|
3971
|
+
["expect.exclusiveMin", ["message"]],
|
|
3972
|
+
["expect.exclusiveMax", ["message"]],
|
|
3973
|
+
["expect.int", ["message"]],
|
|
3974
|
+
["expect.minKeys", ["message"]],
|
|
3975
|
+
["expect.maxKeys", ["message"]],
|
|
3976
|
+
["expect.message", true],
|
|
3977
|
+
["expect.pattern", ["message"]],
|
|
3978
|
+
["expect.array.uniqueItems", ["message"]],
|
|
3979
|
+
["expect.array.key", ["message"]]
|
|
3980
|
+
]);
|
|
3981
|
+
const USER_TEXT = new Map(CORE_USER_TEXT);
|
|
3982
|
+
/**
|
|
3983
|
+
* Registers metadata key `key` as holding user-facing text: `true` (default) — its value is the
|
|
3984
|
+
* text; a list of field names — those fields of its value object are. Fields add up across calls.
|
|
3985
|
+
* For plugins that write such metadata at runtime; generated modules register what they write.
|
|
3986
|
+
*/ function registerUserText(key, fields = true) {
|
|
3987
|
+
const known = USER_TEXT.get(key);
|
|
3988
|
+
if (known === true || fields === true) {
|
|
3989
|
+
USER_TEXT.set(key, true);
|
|
3990
|
+
return;
|
|
3991
|
+
}
|
|
3992
|
+
const added = fields.filter((f) => !known?.includes(f));
|
|
3993
|
+
if (added.length > 0 || !known) USER_TEXT.set(key, [...known ?? [], ...added]);
|
|
3994
|
+
}
|
|
3995
|
+
/**
|
|
3996
|
+
* Registers user-text keys written by a generated module (see {@link registerUserText}): `key` —
|
|
3997
|
+
* the value itself; `key:field` — that field of the value object.
|
|
3998
|
+
*/ function $ut(...entries) {
|
|
3999
|
+
for (const entry of entries) {
|
|
4000
|
+
const at = entry.indexOf(":");
|
|
4001
|
+
if (at === -1) registerUserText(entry);
|
|
4002
|
+
else registerUserText(entry.slice(0, at), [entry.slice(at + 1)]);
|
|
4003
|
+
}
|
|
4004
|
+
}
|
|
4005
|
+
/**
|
|
4006
|
+
* Where metadata key `key` holds user-facing text: `true` — its value is the text (a string; for
|
|
4007
|
+
* a `multiple` annotation, each item of the list); a list of field names — those fields of its
|
|
4008
|
+
* value object (each item's, for a list); `undefined` — no user-facing text. Core keys are known
|
|
4009
|
+
* from the start; a plugin's once a module writing them is loaded (or the plugin registered them).
|
|
4010
|
+
*/ function userTextOf(key) {
|
|
4011
|
+
return USER_TEXT.get(key);
|
|
4012
|
+
}
|
|
4013
|
+
/** Every metadata key holding user-facing text known so far (see {@link userTextOf}). */ function userTextKeys() {
|
|
4014
|
+
return USER_TEXT;
|
|
4015
|
+
}
|
|
4016
|
+
|
|
3451
4017
|
//#endregion
|
|
3452
4018
|
Object.defineProperty(exports, '$ak', {
|
|
3453
4019
|
enumerable: true,
|
|
@@ -3515,6 +4081,18 @@ Object.defineProperty(exports, '$sh', {
|
|
|
3515
4081
|
return $sh;
|
|
3516
4082
|
}
|
|
3517
4083
|
});
|
|
4084
|
+
Object.defineProperty(exports, '$ut', {
|
|
4085
|
+
enumerable: true,
|
|
4086
|
+
get: function () {
|
|
4087
|
+
return $ut;
|
|
4088
|
+
}
|
|
4089
|
+
});
|
|
4090
|
+
Object.defineProperty(exports, 'CORE_USER_TEXT', {
|
|
4091
|
+
enumerable: true,
|
|
4092
|
+
get: function () {
|
|
4093
|
+
return CORE_USER_TEXT;
|
|
4094
|
+
}
|
|
4095
|
+
});
|
|
3518
4096
|
Object.defineProperty(exports, 'DECIMAL_RE', {
|
|
3519
4097
|
enumerable: true,
|
|
3520
4098
|
get: function () {
|
|
@@ -3527,12 +4105,24 @@ Object.defineProperty(exports, 'LayerMap', {
|
|
|
3527
4105
|
return LayerMap;
|
|
3528
4106
|
}
|
|
3529
4107
|
});
|
|
4108
|
+
Object.defineProperty(exports, 'VALIDATOR_ERROR_CODES', {
|
|
4109
|
+
enumerable: true,
|
|
4110
|
+
get: function () {
|
|
4111
|
+
return VALIDATOR_ERROR_CODES;
|
|
4112
|
+
}
|
|
4113
|
+
});
|
|
3530
4114
|
Object.defineProperty(exports, 'VALIDATOR_KEYS', {
|
|
3531
4115
|
enumerable: true,
|
|
3532
4116
|
get: function () {
|
|
3533
4117
|
return VALIDATOR_KEYS;
|
|
3534
4118
|
}
|
|
3535
4119
|
});
|
|
4120
|
+
Object.defineProperty(exports, 'VALIDATOR_MESSAGES', {
|
|
4121
|
+
enumerable: true,
|
|
4122
|
+
get: function () {
|
|
4123
|
+
return VALIDATOR_MESSAGES;
|
|
4124
|
+
}
|
|
4125
|
+
});
|
|
3536
4126
|
Object.defineProperty(exports, 'Validator', {
|
|
3537
4127
|
enumerable: true,
|
|
3538
4128
|
get: function () {
|
|
@@ -3605,12 +4195,24 @@ Object.defineProperty(exports, 'defineAnnotatedType', {
|
|
|
3605
4195
|
return defineAnnotatedType;
|
|
3606
4196
|
}
|
|
3607
4197
|
});
|
|
4198
|
+
Object.defineProperty(exports, 'detectDiscriminator', {
|
|
4199
|
+
enumerable: true,
|
|
4200
|
+
get: function () {
|
|
4201
|
+
return detectDiscriminator;
|
|
4202
|
+
}
|
|
4203
|
+
});
|
|
3608
4204
|
Object.defineProperty(exports, 'enterCut', {
|
|
3609
4205
|
enumerable: true,
|
|
3610
4206
|
get: function () {
|
|
3611
4207
|
return enterCut;
|
|
3612
4208
|
}
|
|
3613
4209
|
});
|
|
4210
|
+
Object.defineProperty(exports, 'formatValidatorMessage', {
|
|
4211
|
+
enumerable: true,
|
|
4212
|
+
get: function () {
|
|
4213
|
+
return formatValidatorMessage;
|
|
4214
|
+
}
|
|
4215
|
+
});
|
|
3614
4216
|
Object.defineProperty(exports, 'invalidateCompiledValidators', {
|
|
3615
4217
|
enumerable: true,
|
|
3616
4218
|
get: function () {
|
|
@@ -3641,6 +4243,18 @@ Object.defineProperty(exports, 'jsonSchemaPattern', {
|
|
|
3641
4243
|
return jsonSchemaPattern;
|
|
3642
4244
|
}
|
|
3643
4245
|
});
|
|
4246
|
+
Object.defineProperty(exports, 'localizeErrors', {
|
|
4247
|
+
enumerable: true,
|
|
4248
|
+
get: function () {
|
|
4249
|
+
return localizeErrors;
|
|
4250
|
+
}
|
|
4251
|
+
});
|
|
4252
|
+
Object.defineProperty(exports, 'messagesTranslator', {
|
|
4253
|
+
enumerable: true,
|
|
4254
|
+
get: function () {
|
|
4255
|
+
return messagesTranslator;
|
|
4256
|
+
}
|
|
4257
|
+
});
|
|
3644
4258
|
Object.defineProperty(exports, 'metaEmpty', {
|
|
3645
4259
|
enumerable: true,
|
|
3646
4260
|
get: function () {
|
|
@@ -3671,6 +4285,12 @@ Object.defineProperty(exports, 'registerCompiledCheck', {
|
|
|
3671
4285
|
return registerCompiledCheck;
|
|
3672
4286
|
}
|
|
3673
4287
|
});
|
|
4288
|
+
Object.defineProperty(exports, 'registerUserText', {
|
|
4289
|
+
enumerable: true,
|
|
4290
|
+
get: function () {
|
|
4291
|
+
return registerUserText;
|
|
4292
|
+
}
|
|
4293
|
+
});
|
|
3674
4294
|
Object.defineProperty(exports, 'stageEnds', {
|
|
3675
4295
|
enumerable: true,
|
|
3676
4296
|
get: function () {
|
|
@@ -3695,6 +4315,18 @@ Object.defineProperty(exports, 'uniqueName', {
|
|
|
3695
4315
|
return uniqueName;
|
|
3696
4316
|
}
|
|
3697
4317
|
});
|
|
4318
|
+
Object.defineProperty(exports, 'userTextKeys', {
|
|
4319
|
+
enumerable: true,
|
|
4320
|
+
get: function () {
|
|
4321
|
+
return userTextKeys;
|
|
4322
|
+
}
|
|
4323
|
+
});
|
|
4324
|
+
Object.defineProperty(exports, 'userTextOf', {
|
|
4325
|
+
enumerable: true,
|
|
4326
|
+
get: function () {
|
|
4327
|
+
return userTextOf;
|
|
4328
|
+
}
|
|
4329
|
+
});
|
|
3698
4330
|
Object.defineProperty(exports, 'watchLayer', {
|
|
3699
4331
|
enumerable: true,
|
|
3700
4332
|
get: function () {
|