@atscript/typescript 0.1.107 → 0.1.109
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 +508 -60
- package/dist/index.cjs +2 -1
- package/dist/index.mjs +2 -1
- package/dist/{json-schema-BN0B-fMO.cjs → json-schema-9OBvrg9D.cjs} +503 -48
- package/dist/{json-schema-DKgNpLpU.mjs → json-schema-CioBVi6F.mjs} +503 -48
- package/dist/{plugin-91-z7KE-.cjs → plugin-6r27w6rG.cjs} +10 -7
- package/dist/{plugin-GvSLmYJb.mjs → plugin-D3_BnRrI.mjs} +10 -7
- package/dist/test-utils.cjs +2 -1
- package/dist/test-utils.mjs +2 -1
- package/dist/utils.cjs +1 -1
- package/dist/utils.d.ts +3 -1
- package/dist/utils.mjs +1 -1
- package/package.json +6 -6
package/dist/cli.cjs
CHANGED
|
@@ -36,7 +36,7 @@ let node_readline = require("node:readline");
|
|
|
36
36
|
let node_url = require("node:url");
|
|
37
37
|
|
|
38
38
|
//#region packages/typescript/src/codegen/code-printer.ts
|
|
39
|
-
function _define_property$
|
|
39
|
+
function _define_property$8(obj, key, value) {
|
|
40
40
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
41
41
|
value,
|
|
42
42
|
enumerable: true,
|
|
@@ -129,17 +129,17 @@ var CodePrinter = class {
|
|
|
129
129
|
return " ".repeat(this.indentLevel * this.indentSize);
|
|
130
130
|
}
|
|
131
131
|
constructor() {
|
|
132
|
-
_define_property$
|
|
133
|
-
_define_property$
|
|
134
|
-
_define_property$
|
|
135
|
-
_define_property$
|
|
136
|
-
_define_property$
|
|
132
|
+
_define_property$8(this, "lines", []);
|
|
133
|
+
_define_property$8(this, "currentLine", "");
|
|
134
|
+
_define_property$8(this, "indentLevel", 0);
|
|
135
|
+
_define_property$8(this, "indentSize", 2);
|
|
136
|
+
_define_property$8(this, "blockStack", []);
|
|
137
137
|
}
|
|
138
138
|
};
|
|
139
139
|
|
|
140
140
|
//#endregion
|
|
141
141
|
//#region packages/typescript/src/codegen/base-renderer.ts
|
|
142
|
-
function _define_property$
|
|
142
|
+
function _define_property$7(obj, key, value) {
|
|
143
143
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
144
144
|
value,
|
|
145
145
|
enumerable: true,
|
|
@@ -202,7 +202,7 @@ var BaseRenderer = class extends CodePrinter {
|
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
constructor(doc) {
|
|
205
|
-
super(), _define_property$
|
|
205
|
+
super(), _define_property$7(this, "doc", void 0), _define_property$7(this, "_unused", void 0), this.doc = doc;
|
|
206
206
|
}
|
|
207
207
|
};
|
|
208
208
|
|
|
@@ -225,7 +225,7 @@ function escapeQuotes(str) {
|
|
|
225
225
|
|
|
226
226
|
//#endregion
|
|
227
227
|
//#region packages/typescript/src/codegen/type-renderer.ts
|
|
228
|
-
function _define_property$
|
|
228
|
+
function _define_property$6(obj, key, value) {
|
|
229
229
|
if (key in obj) Object.defineProperty(obj, key, {
|
|
230
230
|
value,
|
|
231
231
|
enumerable: true,
|
|
@@ -649,7 +649,7 @@ var TypeRenderer = class TypeRenderer extends BaseRenderer {
|
|
|
649
649
|
this.writeln(` */`);
|
|
650
650
|
}
|
|
651
651
|
constructor(doc, opts) {
|
|
652
|
-
super(doc), _define_property$
|
|
652
|
+
super(doc), _define_property$6(this, "opts", void 0), this.opts = opts;
|
|
653
653
|
}
|
|
654
654
|
};
|
|
655
655
|
function renderPrimitiveTypeDef(def) {
|
|
@@ -668,38 +668,94 @@ function renderPrimitiveTypeDef(def) {
|
|
|
668
668
|
|
|
669
669
|
//#endregion
|
|
670
670
|
//#region packages/typescript/src/runtime/validator-fast-check.ts
|
|
671
|
+
function _define_property$5(obj, key, value) {
|
|
672
|
+
if (key in obj) Object.defineProperty(obj, key, {
|
|
673
|
+
value,
|
|
674
|
+
enumerable: true,
|
|
675
|
+
configurable: true,
|
|
676
|
+
writable: true
|
|
677
|
+
});
|
|
678
|
+
else obj[key] = value;
|
|
679
|
+
return obj;
|
|
680
|
+
}
|
|
671
681
|
/**
|
|
672
682
|
* Allocation-free boolean pre-check used by {@link Validator.validate} before the
|
|
673
683
|
* error-collecting walk.
|
|
674
684
|
*
|
|
675
|
-
*
|
|
676
|
-
*
|
|
677
|
-
*
|
|
685
|
+
* Nodes are checked by the generic functions below, which read the type tree and metadata
|
|
686
|
+
* LIVE on every visit. Array items — the same type visited many times per call — go
|
|
687
|
+
* through a compiled {@link Plan} of the item type instead (cached per node, shared by every
|
|
688
|
+
* validator and option set). A plan snapshots what its node's check reads and re-verifies
|
|
689
|
+
* every snapshot against the live node lazily, once per call, right before first using it
|
|
690
|
+
* (rebuilding it when anything differs); constraint objects and pattern arrays are read
|
|
691
|
+
* live on every visit. Either way `annotate()` / `metadata.set()` / prop mutations made
|
|
692
|
+
* after a validator was created are always honoured — the same as the full walk.
|
|
678
693
|
*
|
|
679
694
|
* Result contract (relative to the full walk over the same node and value):
|
|
680
|
-
* - `PASS` — the walk returns `true`, collects no errors and has no side effects
|
|
681
|
-
*
|
|
682
|
-
*
|
|
683
|
-
*
|
|
695
|
+
* - `PASS` — the walk returns `true`, collects no errors and has no side effects other
|
|
696
|
+
* than the strips recorded here (see below).
|
|
697
|
+
* - `FAIL` — the walk returns `false`. Inside a union, every node the walk would visit
|
|
698
|
+
* was visited here too (so a walk that would throw makes this throw first) and the
|
|
699
|
+
* walk's only side effects for this node are the strips recorded here. Outside unions
|
|
700
|
+
* a `FAIL` always ends in the walk, so it may be returned early.
|
|
684
701
|
* - `BAIL` — not decidable here; the caller must run the full walk.
|
|
685
702
|
*
|
|
686
703
|
* Union branches are tried in declared order, continuing past `FAIL` and stopping
|
|
687
704
|
* at `BAIL`, which keeps union results identical to the walk.
|
|
705
|
+
*
|
|
706
|
+
* `unknownProps: 'strip'`: the walk deletes an object's unknown keys right after the object
|
|
707
|
+
* passes (even when an ancestor fails later). This check records those deletions only for
|
|
708
|
+
* the top-level object (`pendingKeys`), whose strip is the walk's last read of the input:
|
|
709
|
+
* deferring an earlier strip past later reads could be observed by them (a prototype, a
|
|
710
|
+
* proxy or an accessor over the stripped object), so a nested object with unknown keys
|
|
711
|
+
* bails, as does any object visit once a strip is pending (a later intersection member).
|
|
712
|
+
* The recorded keys are deleted, in the walk's order, only when the whole value passes —
|
|
713
|
+
* so a `PASS` result still has exactly the walk's side effects, and `FAIL` / `BAIL` leave
|
|
714
|
+
* the value untouched for the walk.
|
|
688
715
|
*/ const FAIL = 0;
|
|
689
716
|
const PASS = 1;
|
|
690
717
|
const BAIL = 2;
|
|
691
718
|
/** Node is at walk depth 0 (only object props / array & tuple items increase depth). */ const TOP = 1;
|
|
692
719
|
/** Node is inside a union branch — failures must be exhaustive (see contract). */ const IN_UNION = 2;
|
|
720
|
+
/** Incremented per {@link fastCheckPasses} call; snapshots verified in older calls re-verify. */ let stamp = 0;
|
|
721
|
+
/** A 'strip' {@link fastCheckPasses} call is in progress (the pending strips below are its own). */ let stripping = false;
|
|
722
|
+
/**
|
|
723
|
+
* Unknown keys of the top-level object the walk would delete (`unknownProps: 'strip'`), in
|
|
724
|
+
* the walk's deletion order. Deleted when the call passes, dropped otherwise.
|
|
725
|
+
*/ const pendingKeys = [];
|
|
693
726
|
/**
|
|
694
|
-
* `true` only when the full walk over `value` is guaranteed to pass with no errors
|
|
695
|
-
*
|
|
727
|
+
* `true` only when the full walk over `value` is guaranteed to pass with no errors and
|
|
728
|
+
* no side effects other than its 'strip' deletions, which are then performed here, as the
|
|
729
|
+
* walk would. Any other outcome (including a throw) leaves `value` untouched and means
|
|
730
|
+
* "run the walk".
|
|
696
731
|
*/ function fastCheckPasses(def, value, opts) {
|
|
732
|
+
if (opts.unknownProps === "strip") return fastCheckStripping(def, value, opts);
|
|
733
|
+
stamp++;
|
|
697
734
|
try {
|
|
698
735
|
return fastCheck(def, value, TOP, opts) === PASS;
|
|
699
736
|
} catch {
|
|
700
737
|
return false;
|
|
701
738
|
}
|
|
702
739
|
}
|
|
740
|
+
/** {@link fastCheckPasses} for `unknownProps: 'strip'`: performs the recorded strips on a pass. */ function fastCheckStripping(def, value, opts) {
|
|
741
|
+
if (stripping) return false;
|
|
742
|
+
stamp++;
|
|
743
|
+
stripping = true;
|
|
744
|
+
let passed;
|
|
745
|
+
try {
|
|
746
|
+
passed = fastCheck(def, value, TOP, opts) === PASS;
|
|
747
|
+
} catch {
|
|
748
|
+
passed = false;
|
|
749
|
+
} finally {
|
|
750
|
+
stripping = false;
|
|
751
|
+
}
|
|
752
|
+
try {
|
|
753
|
+
if (passed) for (const key of pendingKeys) delete value[key];
|
|
754
|
+
} finally {
|
|
755
|
+
pendingKeys.length = 0;
|
|
756
|
+
}
|
|
757
|
+
return passed;
|
|
758
|
+
}
|
|
703
759
|
const DECIMAL_RE = /^[+-]?\d+(\.\d+)?$/;
|
|
704
760
|
const regexCache = /* @__PURE__ */ new Map();
|
|
705
761
|
/** Compiled `@expect.pattern` regex, cached per (pattern, flags). */ function getRegex(pattern, flags) {
|
|
@@ -744,7 +800,8 @@ function fastCheck(def, value, flags, opts) {
|
|
|
744
800
|
const branchFlags = flags | IN_UNION;
|
|
745
801
|
for (const item of type.items) {
|
|
746
802
|
const result = fastCheck(item, value, branchFlags, opts);
|
|
747
|
-
if (result !== FAIL) return result
|
|
803
|
+
if (result !== FAIL) return unionMatchResult(result, item, def.metadata, value);
|
|
804
|
+
if (pendingKeys.length > 0) return BAIL;
|
|
748
805
|
}
|
|
749
806
|
return FAIL;
|
|
750
807
|
}
|
|
@@ -784,6 +841,9 @@ function fastCheckFinal(def, value) {
|
|
|
784
841
|
default: return BAIL;
|
|
785
842
|
}
|
|
786
843
|
}
|
|
844
|
+
/** Result of a union whose branch `item` did not fail (`PASS` or `BAIL`). */ function unionMatchResult(result, item, metadata, value) {
|
|
845
|
+
return result === PASS && item.type.value === void 0 ? fastCheckUnionConstraints(metadata, value) : result;
|
|
846
|
+
}
|
|
787
847
|
/**
|
|
788
848
|
* Mirrors Validator.validateUnionConstraints: union-level constraints on the matched value
|
|
789
849
|
* (`null` / objects pass; the caller skips literal branches).
|
|
@@ -798,8 +858,7 @@ function fastCheckFinal(def, value) {
|
|
|
798
858
|
}
|
|
799
859
|
}
|
|
800
860
|
function fastCheckBoolean(metadata, value) {
|
|
801
|
-
|
|
802
|
-
return metadata.get("meta.required") && value !== true ? FAIL : PASS;
|
|
861
|
+
return metadata.size === 0 ? PASS : booleanConstraints(value, metadata.get("meta.required"));
|
|
803
862
|
}
|
|
804
863
|
function fastCheckString(metadata, value) {
|
|
805
864
|
if (metadata.size === 0) return PASS;
|
|
@@ -819,20 +878,36 @@ function fastCheckString(metadata, value) {
|
|
|
819
878
|
}
|
|
820
879
|
function fastCheckNumber(metadata, value) {
|
|
821
880
|
if (metadata.size === 0) return PASS;
|
|
822
|
-
|
|
823
|
-
|
|
881
|
+
return numberConstraints(value, metadata.get("expect.int"), metadata.get("expect.min"), metadata.get("expect.max"), metadata.get("expect.exclusiveMin"), metadata.get("expect.exclusiveMax"));
|
|
882
|
+
}
|
|
883
|
+
function booleanConstraints(value, required) {
|
|
884
|
+
return required && value !== true ? FAIL : PASS;
|
|
885
|
+
}
|
|
886
|
+
function numberConstraints(value, int, min, max, exMin, exMax) {
|
|
887
|
+
if (int && value % 1 !== 0) return FAIL;
|
|
824
888
|
if (min !== void 0 && value < (typeof min === "number" ? min : min.minValue)) return FAIL;
|
|
825
|
-
const max = metadata.get("expect.max");
|
|
826
889
|
if (max !== void 0 && value > (typeof max === "number" ? max : max.maxValue)) return FAIL;
|
|
890
|
+
if (exMin !== void 0 && value <= (typeof exMin === "number" ? exMin : exMin.exclusiveMinValue)) return FAIL;
|
|
891
|
+
if (exMax !== void 0 && value >= (typeof exMax === "number" ? exMax : exMax.exclusiveMaxValue)) return FAIL;
|
|
827
892
|
return PASS;
|
|
828
893
|
}
|
|
894
|
+
/** `@expect.minLength` / `@expect.maxLength` (strings and arrays). */ function lengthFails(length, minLength, maxLength) {
|
|
895
|
+
return minLength !== void 0 && length < (typeof minLength === "number" ? minLength : minLength.length) || maxLength !== void 0 && length > (typeof maxLength === "number" ? maxLength : maxLength.length);
|
|
896
|
+
}
|
|
897
|
+
/** Array constraints; duplicate detection (`uniqueItems`) is left to the walk. */ function arrayConstraints(length, minLength, maxLength, uniqueItems) {
|
|
898
|
+
if (lengthFails(length, minLength, maxLength)) return FAIL;
|
|
899
|
+
return uniqueItems ? BAIL : PASS;
|
|
900
|
+
}
|
|
829
901
|
function fastCheckObject(def, value, flags, opts) {
|
|
830
902
|
if (typeof value !== "object" || value === null || Array.isArray(value)) return FAIL;
|
|
831
903
|
const type = def.type;
|
|
832
904
|
if (type.propsPatterns.length > 0) return BAIL;
|
|
905
|
+
if (pendingKeys.length > 0) return BAIL;
|
|
906
|
+
const unknownProps = opts.unknownProps;
|
|
907
|
+
const inUnion = (flags & IN_UNION) !== 0;
|
|
908
|
+
if (unknownProps === "error" && !inUnion && hasUnknownKey(type.props, value)) return FAIL;
|
|
833
909
|
const partial = opts.partial;
|
|
834
910
|
const skipUndefined = partial === "deep" || partial === true && (flags & TOP) !== 0;
|
|
835
|
-
const inUnion = (flags & IN_UNION) !== 0;
|
|
836
911
|
const propFlags = flags & IN_UNION;
|
|
837
912
|
let result = PASS;
|
|
838
913
|
for (const [key, item] of type.props) {
|
|
@@ -846,16 +921,28 @@ function fastCheckObject(def, value, flags, opts) {
|
|
|
846
921
|
}
|
|
847
922
|
}
|
|
848
923
|
if (result !== PASS) return result;
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
924
|
+
if (unknownProps === "strip") return pendStrips(type.props, value, flags);
|
|
925
|
+
return unknownProps === "error" && inUnion && hasUnknownKey(type.props, value) ? FAIL : PASS;
|
|
926
|
+
}
|
|
927
|
+
/**
|
|
928
|
+
* Records the unknown keys of a passing top-level object: the walk deletes them at this
|
|
929
|
+
* point, after its last read of the input. A nested object's strip would be followed by
|
|
930
|
+
* more reads, so it is left to the walk.
|
|
931
|
+
*/ function pendStrips(props, value, flags) {
|
|
932
|
+
for (const key of Object.keys(value)) if (isUnknownKey(props, key)) {
|
|
933
|
+
if ((flags & TOP) === 0) return BAIL;
|
|
934
|
+
pendingKeys.push(key);
|
|
856
935
|
}
|
|
857
936
|
return PASS;
|
|
858
937
|
}
|
|
938
|
+
/** `true` when `value` has a key the walk treats as unknown. */ function hasUnknownKey(props, value) {
|
|
939
|
+
for (const key of Object.keys(value)) if (isUnknownKey(props, key)) return true;
|
|
940
|
+
return false;
|
|
941
|
+
}
|
|
942
|
+
/** `true` when the walk treats `key` as unknown (no prop, or a phantom one). */ function isUnknownKey(props, key) {
|
|
943
|
+
const known = props.get(key);
|
|
944
|
+
return known === void 0 || isPhantomType(known);
|
|
945
|
+
}
|
|
859
946
|
function fastCheckArray(def, value, flags, opts) {
|
|
860
947
|
if (!Array.isArray(value)) return FAIL;
|
|
861
948
|
const metadata = def.metadata;
|
|
@@ -863,12 +950,14 @@ function fastCheckArray(def, value, flags, opts) {
|
|
|
863
950
|
const result = fastCheckArrayConstraints(metadata, value);
|
|
864
951
|
if (result !== PASS) return result;
|
|
865
952
|
}
|
|
866
|
-
|
|
953
|
+
return checkItems(planFor(def.type.of), value, flags, opts);
|
|
954
|
+
}
|
|
955
|
+
/** Checks every array item against the item type's plan. */ function checkItems(of, value, flags, opts) {
|
|
867
956
|
const inUnion = (flags & IN_UNION) !== 0;
|
|
868
957
|
const itemFlags = flags & IN_UNION;
|
|
869
958
|
let result = PASS;
|
|
870
959
|
for (const item of value) {
|
|
871
|
-
const itemResult =
|
|
960
|
+
const itemResult = checkPlan(of, item, itemFlags, opts);
|
|
872
961
|
if (itemResult !== PASS) {
|
|
873
962
|
if (itemResult === BAIL || !inUnion) return itemResult;
|
|
874
963
|
result = FAIL;
|
|
@@ -877,11 +966,344 @@ function fastCheckArray(def, value, flags, opts) {
|
|
|
877
966
|
return result;
|
|
878
967
|
}
|
|
879
968
|
function fastCheckArrayConstraints(metadata, value) {
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
969
|
+
return arrayConstraints(value.length, metadata.get("expect.minLength"), metadata.get("expect.maxLength"), metadata.get("expect.array.uniqueItems"));
|
|
970
|
+
}
|
|
971
|
+
const OP_GENERIC = 0;
|
|
972
|
+
const OP_PHANTOM = 1;
|
|
973
|
+
const OP_STRING = 2;
|
|
974
|
+
const OP_NUMBER = 3;
|
|
975
|
+
const OP_BOOLEAN = 4;
|
|
976
|
+
/** Any other final node: checked by {@link fastCheckFinal}. */ const OP_FINAL = 5;
|
|
977
|
+
const OP_OBJECT = 6;
|
|
978
|
+
const OP_ARRAY = 7;
|
|
979
|
+
const OP_UNION = 8;
|
|
980
|
+
function isFinalOp(op) {
|
|
981
|
+
return op !== OP_GENERIC && op <= OP_FINAL;
|
|
982
|
+
}
|
|
983
|
+
/** Shared placeholder for the per-kind arrays of plans that don't use them. */ const EMPTY = Object.freeze([]);
|
|
984
|
+
const plans = /* @__PURE__ */ new WeakMap();
|
|
985
|
+
/** One shape for every plan, so plan field access stays monomorphic. */ let Plan = class Plan {
|
|
986
|
+
constructor(def) {
|
|
987
|
+
_define_property$5(this, "def", void 0);
|
|
988
|
+
/** Call in which the node structure was last verified (`-1`: must rebuild). */ _define_property$5(this, "stamp", void 0);
|
|
989
|
+
/** Call in which the annotation values (`m0`–`m4`) were last verified. */ _define_property$5(this, "metaStamp", void 0);
|
|
990
|
+
_define_property$5(this, "op", void 0);
|
|
991
|
+
_define_property$5(this, "type", void 0);
|
|
992
|
+
_define_property$5(this, "optional", void 0);
|
|
993
|
+
_define_property$5(this, "metadata", void 0);
|
|
994
|
+
_define_property$5(this, "kind", void 0);
|
|
995
|
+
_define_property$5(this, "designType", void 0);
|
|
996
|
+
_define_property$5(this, "literal", void 0);
|
|
997
|
+
/** String plans: compiled `@expect.pattern` regexes by position (checked against the live entry). */ _define_property$5(this, "regexes", void 0);
|
|
998
|
+
/**
|
|
999
|
+
* Annotation keys the node's check reads, and their values (`undefined` when absent):
|
|
1000
|
+
* string `meta.required, expect.minLength, maxLength, pattern`; number `expect.int, min,
|
|
1001
|
+
* max, exclusiveMin, exclusiveMax`; boolean `meta.required`; array `expect.minLength, maxLength, array.uniqueItems`.
|
|
1002
|
+
*/ _define_property$5(this, "k0", void 0);
|
|
1003
|
+
_define_property$5(this, "k1", void 0);
|
|
1004
|
+
_define_property$5(this, "k2", void 0);
|
|
1005
|
+
_define_property$5(this, "k3", void 0);
|
|
1006
|
+
_define_property$5(this, "k4", void 0);
|
|
1007
|
+
_define_property$5(this, "m0", void 0);
|
|
1008
|
+
_define_property$5(this, "m1", void 0);
|
|
1009
|
+
_define_property$5(this, "m2", void 0);
|
|
1010
|
+
_define_property$5(this, "m3", void 0);
|
|
1011
|
+
_define_property$5(this, "m4", void 0);
|
|
1012
|
+
_define_property$5(this, "props", void 0);
|
|
1013
|
+
_define_property$5(this, "propsPatterns", void 0);
|
|
1014
|
+
_define_property$5(this, "keys", void 0);
|
|
1015
|
+
/** Call in which `props.get(keys[i]) === nodes[i]` was last verified. */ _define_property$5(this, "edges", void 0);
|
|
1016
|
+
/** Prop plans by key (the entries of `props`, verified per visit via `edges`). */ _define_property$5(this, "byKey", void 0);
|
|
1017
|
+
_define_property$5(this, "nodes", void 0);
|
|
1018
|
+
_define_property$5(this, "children", void 0);
|
|
1019
|
+
_define_property$5(this, "of", void 0);
|
|
1020
|
+
_define_property$5(this, "ofPlan", void 0);
|
|
1021
|
+
_define_property$5(this, "items", void 0);
|
|
1022
|
+
this.def = def;
|
|
1023
|
+
this.stamp = -1;
|
|
1024
|
+
this.metaStamp = -1;
|
|
1025
|
+
this.op = OP_GENERIC;
|
|
1026
|
+
this.type = void 0;
|
|
1027
|
+
this.optional = void 0;
|
|
1028
|
+
this.metadata = void 0;
|
|
1029
|
+
this.kind = void 0;
|
|
1030
|
+
this.designType = void 0;
|
|
1031
|
+
this.literal = void 0;
|
|
1032
|
+
this.regexes = EMPTY;
|
|
1033
|
+
this.k0 = void 0;
|
|
1034
|
+
this.k1 = void 0;
|
|
1035
|
+
this.k2 = void 0;
|
|
1036
|
+
this.k3 = void 0;
|
|
1037
|
+
this.k4 = void 0;
|
|
1038
|
+
this.m0 = void 0;
|
|
1039
|
+
this.m1 = void 0;
|
|
1040
|
+
this.m2 = void 0;
|
|
1041
|
+
this.m3 = void 0;
|
|
1042
|
+
this.m4 = void 0;
|
|
1043
|
+
this.props = void 0;
|
|
1044
|
+
this.propsPatterns = void 0;
|
|
1045
|
+
this.keys = EMPTY;
|
|
1046
|
+
this.edges = EMPTY;
|
|
1047
|
+
this.byKey = void 0;
|
|
1048
|
+
this.nodes = EMPTY;
|
|
1049
|
+
this.children = EMPTY;
|
|
1050
|
+
this.of = void 0;
|
|
1051
|
+
this.ofPlan = void 0;
|
|
1052
|
+
this.items = void 0;
|
|
1053
|
+
}
|
|
1054
|
+
};
|
|
1055
|
+
function planFor(def) {
|
|
1056
|
+
let plan = plans.get(def);
|
|
1057
|
+
if (plan === void 0) {
|
|
1058
|
+
plan = new Plan(def);
|
|
1059
|
+
plans.set(def, plan);
|
|
1060
|
+
}
|
|
1061
|
+
return plan;
|
|
1062
|
+
}
|
|
1063
|
+
/** Brings the plan's structure up to date with its live node (once per call). */ function refresh(plan) {
|
|
1064
|
+
if (!(isFinalOp(plan.op) ? verifyFinal(plan) : verify(plan))) build$2(plan);
|
|
1065
|
+
plan.stamp = stamp;
|
|
1066
|
+
}
|
|
1067
|
+
/** Structure check for final ops; small enough to be inlined into the hot loops. */ function verifyFinal(plan) {
|
|
1068
|
+
const def = plan.def;
|
|
1069
|
+
const type = def.type;
|
|
1070
|
+
return plan.stamp !== -1 && type === plan.type && def.optional === plan.optional && def.metadata === plan.metadata && type.kind === "" && type.designType === plan.designType && type.value === plan.literal;
|
|
1071
|
+
}
|
|
1072
|
+
/** Structure check for objects, arrays, unions and generic nodes. */ function verify(plan) {
|
|
1073
|
+
if (plan.stamp === -1) return false;
|
|
1074
|
+
const def = plan.def;
|
|
1075
|
+
const type = def.type;
|
|
1076
|
+
if (type !== plan.type || def.optional !== plan.optional || def.metadata !== plan.metadata || type.kind !== plan.kind) return false;
|
|
1077
|
+
switch (plan.op) {
|
|
1078
|
+
case OP_OBJECT: return type.props === plan.props && plan.props.size === plan.keys.length && type.propsPatterns === plan.propsPatterns && plan.propsPatterns.length === 0;
|
|
1079
|
+
case OP_ARRAY: return type.of === plan.of;
|
|
1080
|
+
case OP_UNION: {
|
|
1081
|
+
const items = plan.items;
|
|
1082
|
+
const nodes = plan.nodes;
|
|
1083
|
+
if (type.items !== items || items.length !== nodes.length) return false;
|
|
1084
|
+
for (let i = 0; i < nodes.length; i++) if (items[i] !== nodes[i]) return false;
|
|
1085
|
+
return true;
|
|
1086
|
+
}
|
|
1087
|
+
default: return type.kind !== "object" || type.propsPatterns.length > 0;
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
/** Brings the annotation values up to date (once per call, when a constraint is read). */ function refreshMeta(plan) {
|
|
1091
|
+
const metadata = plan.metadata;
|
|
1092
|
+
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);
|
|
1093
|
+
plan.metaStamp = stamp;
|
|
1094
|
+
}
|
|
1095
|
+
function snapshotMeta(plan) {
|
|
1096
|
+
const metadata = plan.metadata;
|
|
1097
|
+
plan.m0 = metadata.get(plan.k0);
|
|
1098
|
+
plan.m1 = metadata.get(plan.k1);
|
|
1099
|
+
plan.m2 = metadata.get(plan.k2);
|
|
1100
|
+
plan.m3 = metadata.get(plan.k3);
|
|
1101
|
+
plan.m4 = metadata.get(plan.k4);
|
|
1102
|
+
}
|
|
1103
|
+
function setMetaKeys(plan, k0, k1, k2, k3, k4) {
|
|
1104
|
+
plan.k0 = k0;
|
|
1105
|
+
plan.k1 = k1;
|
|
1106
|
+
plan.k2 = k2;
|
|
1107
|
+
plan.k3 = k3;
|
|
1108
|
+
plan.k4 = k4;
|
|
1109
|
+
snapshotMeta(plan);
|
|
1110
|
+
plan.metaStamp = stamp;
|
|
1111
|
+
}
|
|
1112
|
+
/** (Re)compiles `plan` from its live node. */ function build$2(plan) {
|
|
1113
|
+
plan.stamp = -1;
|
|
1114
|
+
plan.op = OP_GENERIC;
|
|
1115
|
+
const def = plan.def;
|
|
1116
|
+
const type = def.type;
|
|
1117
|
+
plan.type = type;
|
|
1118
|
+
plan.optional = def.optional;
|
|
1119
|
+
plan.metadata = def.metadata;
|
|
1120
|
+
plan.kind = type.kind;
|
|
1121
|
+
plan.designType = type.designType;
|
|
1122
|
+
plan.literal = type.value;
|
|
1123
|
+
plan.regexes = EMPTY;
|
|
1124
|
+
plan.props = void 0;
|
|
1125
|
+
plan.propsPatterns = void 0;
|
|
1126
|
+
plan.keys = EMPTY;
|
|
1127
|
+
plan.edges = EMPTY;
|
|
1128
|
+
plan.byKey = void 0;
|
|
1129
|
+
plan.nodes = EMPTY;
|
|
1130
|
+
plan.children = EMPTY;
|
|
1131
|
+
plan.of = void 0;
|
|
1132
|
+
plan.ofPlan = void 0;
|
|
1133
|
+
plan.items = void 0;
|
|
1134
|
+
setMetaKeys(plan);
|
|
1135
|
+
switch (type.kind) {
|
|
1136
|
+
case "":
|
|
1137
|
+
if (type.designType === "phantom") plan.op = OP_PHANTOM;
|
|
1138
|
+
else if (type.value !== void 0) plan.op = OP_FINAL;
|
|
1139
|
+
else if (type.designType === "string") {
|
|
1140
|
+
setMetaKeys(plan, "meta.required", "expect.minLength", "expect.maxLength", "expect.pattern");
|
|
1141
|
+
plan.regexes = [];
|
|
1142
|
+
plan.op = OP_STRING;
|
|
1143
|
+
} else if (type.designType === "number") {
|
|
1144
|
+
setMetaKeys(plan, "expect.int", "expect.min", "expect.max", "expect.exclusiveMin", "expect.exclusiveMax");
|
|
1145
|
+
plan.op = OP_NUMBER;
|
|
1146
|
+
} else if (type.designType === "boolean") {
|
|
1147
|
+
setMetaKeys(plan, "meta.required");
|
|
1148
|
+
plan.op = OP_BOOLEAN;
|
|
1149
|
+
} else plan.op = OP_FINAL;
|
|
1150
|
+
break;
|
|
1151
|
+
case "object": {
|
|
1152
|
+
if (type.propsPatterns.length > 0) break;
|
|
1153
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
1154
|
+
plan.keys = [];
|
|
1155
|
+
plan.edges = [];
|
|
1156
|
+
plan.nodes = [];
|
|
1157
|
+
plan.children = [];
|
|
1158
|
+
for (const [key, node] of type.props) {
|
|
1159
|
+
const child = planFor(node);
|
|
1160
|
+
plan.keys.push(key);
|
|
1161
|
+
plan.edges.push(stamp);
|
|
1162
|
+
plan.nodes.push(node);
|
|
1163
|
+
plan.children.push(child);
|
|
1164
|
+
byKey.set(key, child);
|
|
1165
|
+
}
|
|
1166
|
+
plan.byKey = byKey;
|
|
1167
|
+
plan.props = type.props;
|
|
1168
|
+
plan.propsPatterns = type.propsPatterns;
|
|
1169
|
+
plan.op = OP_OBJECT;
|
|
1170
|
+
break;
|
|
1171
|
+
}
|
|
1172
|
+
case "array":
|
|
1173
|
+
setMetaKeys(plan, "expect.minLength", "expect.maxLength", "expect.array.uniqueItems");
|
|
1174
|
+
plan.of = type.of;
|
|
1175
|
+
plan.ofPlan = planFor(type.of);
|
|
1176
|
+
plan.op = OP_ARRAY;
|
|
1177
|
+
break;
|
|
1178
|
+
case "union":
|
|
1179
|
+
plan.nodes = [];
|
|
1180
|
+
plan.children = [];
|
|
1181
|
+
for (const node of type.items) {
|
|
1182
|
+
plan.nodes.push(node);
|
|
1183
|
+
plan.children.push(planFor(node));
|
|
1184
|
+
}
|
|
1185
|
+
plan.items = type.items;
|
|
1186
|
+
plan.op = OP_UNION;
|
|
1187
|
+
break;
|
|
1188
|
+
default:
|
|
1189
|
+
}
|
|
1190
|
+
}
|
|
1191
|
+
/** Plan counterpart of {@link fastCheck}. */ function checkPlan(plan, value, flags, opts) {
|
|
1192
|
+
if (plan.stamp !== stamp) refresh(plan);
|
|
1193
|
+
if (plan.optional && (value === void 0 || value === null)) return value === null && rejectsNullAsRequired(plan.def) ? FAIL : PASS;
|
|
1194
|
+
switch (plan.op) {
|
|
1195
|
+
case OP_STRING: return typeof value === "string" ? checkString(plan, value) : FAIL;
|
|
1196
|
+
case OP_NUMBER: return typeof value === "number" && Number.isFinite(value) ? checkNumber(plan, value) : FAIL;
|
|
1197
|
+
case OP_OBJECT: return checkObject(plan, value, flags, opts);
|
|
1198
|
+
case OP_ARRAY: return checkArray(plan, value, flags, opts);
|
|
1199
|
+
case OP_UNION: {
|
|
1200
|
+
const branchFlags = flags | IN_UNION;
|
|
1201
|
+
for (const child of plan.children) {
|
|
1202
|
+
const result = checkPlan(child, value, branchFlags, opts);
|
|
1203
|
+
if (result !== FAIL) return unionMatchResult(result, child.def, plan.metadata, value);
|
|
1204
|
+
}
|
|
1205
|
+
return FAIL;
|
|
1206
|
+
}
|
|
1207
|
+
case OP_BOOLEAN:
|
|
1208
|
+
if (typeof value !== "boolean") return FAIL;
|
|
1209
|
+
if (plan.metaStamp !== stamp) refreshMeta(plan);
|
|
1210
|
+
return booleanConstraints(value, plan.m0);
|
|
1211
|
+
case OP_PHANTOM:
|
|
1212
|
+
case OP_FINAL: return fastCheckFinal(plan.def, value);
|
|
1213
|
+
default: return fastCheck(plan.def, value, flags, opts);
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
/** Plan counterpart of {@link fastCheckString}; constraint objects are read live. */ function checkString(plan, value) {
|
|
1217
|
+
if (plan.metaStamp !== stamp) refreshMeta(plan);
|
|
1218
|
+
if (plan.m0 && value.trim().length === 0) return FAIL;
|
|
1219
|
+
if (lengthFails(value.length, plan.m1, plan.m2)) return FAIL;
|
|
1220
|
+
const patterns = plan.m3;
|
|
1221
|
+
if (patterns) {
|
|
1222
|
+
if (!Array.isArray(patterns)) return fastCheckString(plan.metadata, value);
|
|
1223
|
+
for (let i = 0; i < patterns.length; i++) {
|
|
1224
|
+
const { pattern, flags } = patterns[i];
|
|
1225
|
+
if (!pattern) continue;
|
|
1226
|
+
let entry = plan.regexes[i];
|
|
1227
|
+
if (entry === void 0 || entry.pattern !== pattern || entry.flags !== flags) {
|
|
1228
|
+
const re = getRegex(pattern, flags);
|
|
1229
|
+
entry = {
|
|
1230
|
+
pattern,
|
|
1231
|
+
flags,
|
|
1232
|
+
re,
|
|
1233
|
+
stateful: re.global || re.sticky
|
|
1234
|
+
};
|
|
1235
|
+
plan.regexes[i] = entry;
|
|
1236
|
+
}
|
|
1237
|
+
if (entry.stateful) return BAIL;
|
|
1238
|
+
if (!entry.re.test(value)) return FAIL;
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
return PASS;
|
|
1242
|
+
}
|
|
1243
|
+
/** Plan counterpart of {@link fastCheckNumber}; constraint objects are read live. */ function checkNumber(plan, value) {
|
|
1244
|
+
if (plan.metaStamp !== stamp) refreshMeta(plan);
|
|
1245
|
+
return numberConstraints(value, plan.m0, plan.m1, plan.m2, plan.m3, plan.m4);
|
|
1246
|
+
}
|
|
1247
|
+
/** Plan counterpart of {@link fastCheckObject}. */ function checkObject(plan, value, flags, opts) {
|
|
1248
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) return FAIL;
|
|
1249
|
+
const partial = opts.partial;
|
|
1250
|
+
const skipUndefined = partial === "deep" || partial === true && (flags & TOP) !== 0;
|
|
1251
|
+
const inUnion = (flags & IN_UNION) !== 0;
|
|
1252
|
+
const propFlags = flags & IN_UNION;
|
|
1253
|
+
const keys = plan.keys;
|
|
1254
|
+
const children = plan.children;
|
|
1255
|
+
const edges = plan.edges;
|
|
1256
|
+
let result = PASS;
|
|
1257
|
+
for (let i = 0; i < keys.length; i++) {
|
|
1258
|
+
if (edges[i] !== stamp) {
|
|
1259
|
+
if (plan.props.get(keys[i]) !== plan.nodes[i]) {
|
|
1260
|
+
plan.stamp = -1;
|
|
1261
|
+
return BAIL;
|
|
1262
|
+
}
|
|
1263
|
+
edges[i] = stamp;
|
|
1264
|
+
}
|
|
1265
|
+
const child = children[i];
|
|
1266
|
+
if (child.stamp !== stamp) refresh(child);
|
|
1267
|
+
const op = child.op;
|
|
1268
|
+
if (op === OP_PHANTOM) continue;
|
|
1269
|
+
const propValue = value[keys[i]];
|
|
1270
|
+
if (propValue === void 0 && skipUndefined) continue;
|
|
1271
|
+
if (typeof propValue === "string" && op === OP_STRING) {
|
|
1272
|
+
const r = checkString(child, propValue);
|
|
1273
|
+
if (r === PASS) continue;
|
|
1274
|
+
if (r === BAIL || !inUnion) return r;
|
|
1275
|
+
result = FAIL;
|
|
1276
|
+
continue;
|
|
1277
|
+
}
|
|
1278
|
+
if (typeof propValue === "number" && op === OP_NUMBER) {
|
|
1279
|
+
if (Number.isFinite(propValue) && checkNumber(child, propValue) === PASS) continue;
|
|
1280
|
+
if (!inUnion) return FAIL;
|
|
1281
|
+
result = FAIL;
|
|
1282
|
+
continue;
|
|
1283
|
+
}
|
|
1284
|
+
const propResult = checkPlan(child, propValue, propFlags, opts);
|
|
1285
|
+
if (propResult !== PASS) {
|
|
1286
|
+
if (propResult === BAIL || !inUnion) return propResult;
|
|
1287
|
+
result = FAIL;
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
if (result !== PASS) return result;
|
|
1291
|
+
const unknownProps = opts.unknownProps;
|
|
1292
|
+
if (unknownProps === "error" || unknownProps === "strip") {
|
|
1293
|
+
const byKey = plan.byKey;
|
|
1294
|
+
for (const key of Object.keys(value)) {
|
|
1295
|
+
const known = byKey.get(key);
|
|
1296
|
+
if (known === void 0 || known.op === OP_PHANTOM) return unknownProps === "error" ? FAIL : BAIL;
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
return PASS;
|
|
1300
|
+
}
|
|
1301
|
+
/** Plan counterpart of {@link fastCheckArray}. */ function checkArray(plan, value, flags, opts) {
|
|
1302
|
+
if (!Array.isArray(value)) return FAIL;
|
|
1303
|
+
if (plan.metaStamp !== stamp) refreshMeta(plan);
|
|
1304
|
+
const result = arrayConstraints(value.length, plan.m0, plan.m1, plan.m2);
|
|
1305
|
+
if (result !== PASS) return result;
|
|
1306
|
+
return checkItems(plan.ofPlan, value, flags, opts);
|
|
885
1307
|
}
|
|
886
1308
|
|
|
887
1309
|
//#endregion
|
|
@@ -1232,7 +1654,7 @@ function _define_property$4(obj, key, value) {
|
|
|
1232
1654
|
validatePrimitive(def, value) {
|
|
1233
1655
|
if (def.type.value !== void 0) {
|
|
1234
1656
|
if (value !== def.type.value) {
|
|
1235
|
-
this.error(`Expected ${def.type.value}, got ${value}`);
|
|
1657
|
+
this.error(`Expected ${def.type.value}, got ${printValue(value)}`);
|
|
1236
1658
|
return false;
|
|
1237
1659
|
}
|
|
1238
1660
|
return true;
|
|
@@ -1334,7 +1756,7 @@ function _define_property$4(obj, key, value) {
|
|
|
1334
1756
|
validateNumber(def, value) {
|
|
1335
1757
|
return this.validateNumberConstraints(def.metadata, value);
|
|
1336
1758
|
}
|
|
1337
|
-
/** `@expect.int` / `min` / `max` checks for a number value. */ validateNumberConstraints(metadata, value) {
|
|
1759
|
+
/** `@expect.int` / `min` / `max` / `exclusiveMin` / `exclusiveMax` checks for a number value. */ validateNumberConstraints(metadata, value) {
|
|
1338
1760
|
if (metadata.size === 0) return true;
|
|
1339
1761
|
const int = metadata.get("expect.int");
|
|
1340
1762
|
if (int && value % 1 !== 0) {
|
|
@@ -1345,23 +1767,30 @@ function _define_property$4(obj, key, value) {
|
|
|
1345
1767
|
const min = metadata.get("expect.min");
|
|
1346
1768
|
if (min !== void 0) {
|
|
1347
1769
|
const minValue = typeof min === "number" ? min : min.minValue;
|
|
1348
|
-
if (value < minValue)
|
|
1349
|
-
const message = typeof min === "object" && min.message ? min.message : `Expected minimum ${minValue}, got ${value}`;
|
|
1350
|
-
this.error(message);
|
|
1351
|
-
return false;
|
|
1352
|
-
}
|
|
1770
|
+
if (value < minValue) return this.numberBoundFailed(min, "minimum", minValue, value);
|
|
1353
1771
|
}
|
|
1354
1772
|
const max = metadata.get("expect.max");
|
|
1355
1773
|
if (max !== void 0) {
|
|
1356
1774
|
const maxValue = typeof max === "number" ? max : max.maxValue;
|
|
1357
|
-
if (value > maxValue)
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1775
|
+
if (value > maxValue) return this.numberBoundFailed(max, "maximum", maxValue, value);
|
|
1776
|
+
}
|
|
1777
|
+
const exMin = metadata.get("expect.exclusiveMin");
|
|
1778
|
+
if (exMin !== void 0) {
|
|
1779
|
+
const bound = typeof exMin === "number" ? exMin : exMin.exclusiveMinValue;
|
|
1780
|
+
if (value <= bound) return this.numberBoundFailed(exMin, "greater than", bound, value);
|
|
1781
|
+
}
|
|
1782
|
+
const exMax = metadata.get("expect.exclusiveMax");
|
|
1783
|
+
if (exMax !== void 0) {
|
|
1784
|
+
const bound = typeof exMax === "number" ? exMax : exMax.exclusiveMaxValue;
|
|
1785
|
+
if (value >= bound) return this.numberBoundFailed(exMax, "less than", bound, value);
|
|
1362
1786
|
}
|
|
1363
1787
|
return true;
|
|
1364
1788
|
}
|
|
1789
|
+
/** Reports a failed number bound: its custom message, else `Expected <label> <bound>, got <value>`. */ numberBoundFailed(annotation, label, bound, value) {
|
|
1790
|
+
const message = typeof annotation === "object" && annotation.message ? annotation.message : `Expected ${label} ${bound}, got ${value}`;
|
|
1791
|
+
this.error(message);
|
|
1792
|
+
return false;
|
|
1793
|
+
}
|
|
1365
1794
|
validateBoolean(def, value) {
|
|
1366
1795
|
return this.validateBooleanConstraints(def.metadata, value);
|
|
1367
1796
|
}
|
|
@@ -1424,6 +1853,13 @@ function _define_property$4(obj, key, value) {
|
|
|
1424
1853
|
if (of) return of;
|
|
1425
1854
|
}
|
|
1426
1855
|
}
|
|
1856
|
+
/** `${value}` throws for symbols and null-prototype objects: `String()` handles symbols, the tag the rest. */ function printValue(value) {
|
|
1857
|
+
try {
|
|
1858
|
+
return String(value);
|
|
1859
|
+
} catch {
|
|
1860
|
+
return Object.prototype.toString.call(value);
|
|
1861
|
+
}
|
|
1862
|
+
}
|
|
1427
1863
|
/** Error thrown by {@link Validator.validate} when validation fails. Contains structured error details. */ var ValidatorError = class extends Error {
|
|
1428
1864
|
constructor(errors) {
|
|
1429
1865
|
super(`${errors[0].path ? errors[0].path + ": " : ""}${errors[0].message}`), _define_property$4(this, "errors", void 0), _define_property$4(this, "name", void 0), this.errors = errors, this.name = "Validation Error";
|
|
@@ -1865,18 +2301,27 @@ function cloneTypeDef(type) {
|
|
|
1865
2301
|
}
|
|
1866
2302
|
if (schema.type === "number" || schema.type === "integer") {
|
|
1867
2303
|
const min = meta.get("expect.min");
|
|
1868
|
-
if (min !== void 0) schema.minimum =
|
|
2304
|
+
if (min !== void 0) schema.minimum = boundOf(min, "minValue");
|
|
1869
2305
|
const max = meta.get("expect.max");
|
|
1870
|
-
if (max !== void 0) schema.maximum =
|
|
2306
|
+
if (max !== void 0) schema.maximum = boundOf(max, "maxValue");
|
|
2307
|
+
const exMin = meta.get("expect.exclusiveMin");
|
|
2308
|
+
if (exMin !== void 0) schema.exclusiveMinimum = boundOf(exMin, "exclusiveMinValue");
|
|
2309
|
+
const exMax = meta.get("expect.exclusiveMax");
|
|
2310
|
+
if (exMax !== void 0) schema.exclusiveMaximum = boundOf(exMax, "exclusiveMaxValue");
|
|
1871
2311
|
}
|
|
1872
2312
|
}
|
|
2313
|
+
/** A number-bound annotation's value: the bare number, or its `field` in the object form. */ function boundOf(m, field) {
|
|
2314
|
+
return typeof m === "number" ? m : m[field];
|
|
2315
|
+
}
|
|
1873
2316
|
const LOWER_BOUNDS = new Set([
|
|
1874
2317
|
"minimum",
|
|
2318
|
+
"exclusiveMinimum",
|
|
1875
2319
|
"minLength",
|
|
1876
2320
|
"minItems"
|
|
1877
2321
|
]);
|
|
1878
2322
|
const UPPER_BOUNDS = new Set([
|
|
1879
2323
|
"maximum",
|
|
2324
|
+
"exclusiveMaximum",
|
|
1880
2325
|
"maxLength",
|
|
1881
2326
|
"maxItems"
|
|
1882
2327
|
]);
|
|
@@ -1935,6 +2380,12 @@ const QUERY_OP_MAP = {
|
|
|
1935
2380
|
"exists": "$exists",
|
|
1936
2381
|
"not exists": "$exists"
|
|
1937
2382
|
};
|
|
2383
|
+
/** Value field of each number-bound annotation's object form. */ const NUMBER_BOUND_FIELDS = {
|
|
2384
|
+
"expect.min": "minValue",
|
|
2385
|
+
"expect.max": "maxValue",
|
|
2386
|
+
"expect.exclusiveMin": "exclusiveMinValue",
|
|
2387
|
+
"expect.exclusiveMax": "exclusiveMaxValue"
|
|
2388
|
+
};
|
|
1938
2389
|
const SYNTH_IMPORTS_MARKER = "/*@@atscript-synth-imports@@*/";
|
|
1939
2390
|
var JsRenderer = class extends BaseRenderer {
|
|
1940
2391
|
/**
|
|
@@ -2358,14 +2809,11 @@ var JsRenderer = class extends BaseRenderer {
|
|
|
2358
2809
|
});
|
|
2359
2810
|
break;
|
|
2360
2811
|
case "expect.min":
|
|
2361
|
-
if (a.args[0]) handle.annotate(a.name, {
|
|
2362
|
-
minValue: Number(a.args[0].text),
|
|
2363
|
-
message: a.args[1]?.text
|
|
2364
|
-
});
|
|
2365
|
-
break;
|
|
2366
2812
|
case "expect.max":
|
|
2813
|
+
case "expect.exclusiveMin":
|
|
2814
|
+
case "expect.exclusiveMax":
|
|
2367
2815
|
if (a.args[0]) handle.annotate(a.name, {
|
|
2368
|
-
|
|
2816
|
+
[NUMBER_BOUND_FIELDS[a.name]]: Number(a.args[0].text),
|
|
2369
2817
|
message: a.args[1]?.text
|
|
2370
2818
|
});
|
|
2371
2819
|
break;
|