arktype 1.0.10-alpha → 1.0.11-alpha
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/README.md +22 -4
- package/dist/cjs/main.js +26 -24
- package/dist/cjs/nodes/branch.js +18 -18
- package/dist/cjs/nodes/compose.js +28 -11
- package/dist/cjs/nodes/discriminate.js +27 -27
- package/dist/cjs/nodes/node.js +24 -24
- package/dist/cjs/nodes/predicate.js +17 -17
- package/dist/cjs/nodes/rules/class.js +5 -5
- package/dist/cjs/nodes/rules/collapsibleSet.js +3 -3
- package/dist/cjs/nodes/rules/divisor.js +2 -2
- package/dist/cjs/nodes/rules/props.js +19 -19
- package/dist/cjs/nodes/rules/range.js +6 -6
- package/dist/cjs/nodes/rules/regex.js +3 -3
- package/dist/cjs/nodes/rules/rules.js +20 -20
- package/dist/cjs/parse/ast/config.js +2 -2
- package/dist/cjs/parse/ast/distributableFunction.js +9 -9
- package/dist/cjs/parse/ast/intersection.js +5 -5
- package/dist/cjs/parse/ast/keyof.js +31 -30
- package/dist/cjs/parse/ast/morph.js +10 -10
- package/dist/cjs/parse/ast/narrow.js +6 -6
- package/dist/cjs/parse/ast/tuple.js +21 -21
- package/dist/cjs/parse/definition.js +18 -20
- package/dist/cjs/parse/record.js +4 -4
- package/dist/cjs/parse/string/reduce/dynamic.js +44 -26
- package/dist/cjs/parse/string/reduce/shared.js +2 -2
- package/dist/cjs/parse/string/shift/operand/enclosed.js +2 -2
- package/dist/cjs/parse/string/shift/operand/operand.js +3 -3
- package/dist/cjs/parse/string/shift/operand/unenclosed.js +3 -3
- package/dist/cjs/parse/string/shift/operator/bounds.js +18 -18
- package/dist/cjs/parse/string/shift/operator/divisor.js +6 -6
- package/dist/cjs/parse/string/shift/operator/operator.js +6 -6
- package/dist/cjs/parse/string/shift/scanner.js +16 -1
- package/dist/cjs/parse/string/string.js +8 -8
- package/dist/cjs/scopes/ark.js +15 -15
- package/dist/cjs/scopes/cache.js +16 -3
- package/dist/cjs/scopes/expressions.js +9 -9
- package/dist/cjs/scopes/jsObjects.js +2 -42
- package/dist/cjs/scopes/scope.js +59 -31
- package/dist/cjs/scopes/tsKeywords.js +2 -2
- package/dist/cjs/scopes/type.js +6 -6
- package/dist/cjs/scopes/validation/creditCard.js +2 -2
- package/dist/cjs/scopes/validation/date.js +4 -4
- package/dist/cjs/scopes/validation/validation.js +17 -17
- package/dist/cjs/traverse/problems.js +41 -21
- package/dist/cjs/traverse/traverse.js +56 -31
- package/dist/cjs/utils/data.js +18 -4
- package/dist/cjs/utils/generics.js +3 -3
- package/dist/cjs/utils/numericLiterals.js +4 -4
- package/dist/cjs/utils/objectKinds.js +4 -4
- package/dist/cjs/utils/serialize.js +6 -6
- package/dist/mjs/main.js +2 -1
- package/dist/mjs/nodes/compose.js +17 -0
- package/dist/mjs/parse/ast/config.js +5 -1
- package/dist/mjs/parse/ast/keyof.js +2 -1
- package/dist/mjs/parse/definition.js +0 -1
- package/dist/mjs/parse/string/reduce/dynamic.js +18 -0
- package/dist/mjs/parse/string/shift/scanner.js +16 -1
- package/dist/mjs/scopes/cache.js +14 -1
- package/dist/mjs/scopes/expressions.js +88 -8
- package/dist/mjs/scopes/jsObjects.js +2 -41
- package/dist/mjs/scopes/scope.js +30 -2
- package/dist/mjs/scopes/tsKeywords.js +2 -1
- package/dist/mjs/scopes/validation/validation.js +2 -1
- package/dist/mjs/traverse/problems.js +22 -2
- package/dist/mjs/traverse/traverse.js +25 -0
- package/dist/mjs/utils/data.js +14 -0
- package/dist/tsconfig.temp.tsbuildinfo +1 -1
- package/dist/types/main.d.ts +5 -1
- package/dist/types/nodes/node.d.ts +6 -0
- package/dist/types/parse/ast/bound.d.ts +14 -0
- package/dist/types/parse/ast/config.d.ts +5 -0
- package/dist/types/parse/ast/divisor.d.ts +5 -0
- package/dist/types/parse/definition.d.ts +2 -6
- package/dist/types/parse/string/reduce/static.d.ts +12 -2
- package/dist/types/parse/string/shift/operand/operand.d.ts +3 -3
- package/dist/types/parse/string/shift/operand/unenclosed.d.ts +5 -5
- package/dist/types/parse/string/string.d.ts +1 -2
- package/dist/types/scopes/ark.d.ts +10 -22
- package/dist/types/scopes/expressions.d.ts +88 -0
- package/dist/types/scopes/jsObjects.d.ts +2 -11
- package/dist/types/scopes/tsKeywords.d.ts +2 -1
- package/dist/types/scopes/validation/validation.d.ts +2 -1
- package/dist/types/utils/generics.d.ts +1 -1
- package/package.json +15 -16
|
@@ -11,31 +11,30 @@ function _export(target, all) {
|
|
|
11
11
|
_export(exports, {
|
|
12
12
|
parseDefinition: ()=>parseDefinition,
|
|
13
13
|
as: ()=>as,
|
|
14
|
-
unknownDefinitionMessage: ()=>unknownDefinitionMessage,
|
|
15
14
|
writeBadDefinitionTypeMessage: ()=>writeBadDefinitionTypeMessage
|
|
16
15
|
});
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
16
|
+
const _typeJs = require("../scopes/type.js");
|
|
17
|
+
const _domainsJs = require("../utils/domains.js");
|
|
18
|
+
const _errorsJs = require("../utils/errors.js");
|
|
19
|
+
const _objectKindsJs = require("../utils/objectKinds.js");
|
|
20
|
+
const _serializeJs = require("../utils/serialize.js");
|
|
21
|
+
const _tupleJs = require("./ast/tuple.js");
|
|
22
|
+
const _recordJs = require("./record.js");
|
|
23
|
+
const _stringJs = require("./string/string.js");
|
|
25
24
|
const parseDefinition = (def, ctx)=>{
|
|
26
|
-
const domain = (0,
|
|
25
|
+
const domain = (0, _domainsJs.domainOf)(def);
|
|
27
26
|
if (domain === "string") {
|
|
28
|
-
return (0,
|
|
27
|
+
return (0, _stringJs.parseString)(def, ctx);
|
|
29
28
|
}
|
|
30
29
|
if (domain !== "object") {
|
|
31
|
-
return (0,
|
|
30
|
+
return (0, _errorsJs.throwParseError)(writeBadDefinitionTypeMessage(domain));
|
|
32
31
|
}
|
|
33
|
-
const objectKind = (0,
|
|
32
|
+
const objectKind = (0, _objectKindsJs.objectKindOf)(def);
|
|
34
33
|
switch(objectKind){
|
|
35
34
|
case "Object":
|
|
36
|
-
return (0,
|
|
35
|
+
return (0, _recordJs.parseRecord)(def, ctx);
|
|
37
36
|
case "Array":
|
|
38
|
-
return (0,
|
|
37
|
+
return (0, _tupleJs.parseTuple)(def, ctx);
|
|
39
38
|
case "RegExp":
|
|
40
39
|
return {
|
|
41
40
|
string: {
|
|
@@ -43,21 +42,20 @@ const parseDefinition = (def, ctx)=>{
|
|
|
43
42
|
}
|
|
44
43
|
};
|
|
45
44
|
case "Function":
|
|
46
|
-
if ((0,
|
|
45
|
+
if ((0, _typeJs.isType)(def)) {
|
|
47
46
|
return ctx.type.scope.addAnonymousTypeReference(def, ctx);
|
|
48
47
|
}
|
|
49
48
|
if (isThunk(def)) {
|
|
50
49
|
const returned = def();
|
|
51
|
-
if ((0,
|
|
50
|
+
if ((0, _typeJs.isType)(returned)) {
|
|
52
51
|
return ctx.type.scope.addAnonymousTypeReference(returned, ctx);
|
|
53
52
|
}
|
|
54
53
|
}
|
|
55
|
-
return (0,
|
|
54
|
+
return (0, _errorsJs.throwParseError)(writeBadDefinitionTypeMessage("Function"));
|
|
56
55
|
default:
|
|
57
|
-
return (0,
|
|
56
|
+
return (0, _errorsJs.throwParseError)(writeBadDefinitionTypeMessage(objectKind ?? (0, _serializeJs.stringify)(def)));
|
|
58
57
|
}
|
|
59
58
|
};
|
|
60
59
|
const as = Symbol("as");
|
|
61
|
-
const unknownDefinitionMessage = "Cannot statically parse a definition inferred as unknown. Consider using 'as Infer<...>' to cast it.";
|
|
62
60
|
const isThunk = (def)=>typeof def === "function" && def.length === 0;
|
|
63
61
|
const writeBadDefinitionTypeMessage = (actual)=>`Type definitions must be strings or objects (was ${actual})`;
|
package/dist/cjs/parse/record.js
CHANGED
|
@@ -6,15 +6,15 @@ Object.defineProperty(exports, "parseRecord", {
|
|
|
6
6
|
enumerable: true,
|
|
7
7
|
get: ()=>parseRecord
|
|
8
8
|
});
|
|
9
|
-
const
|
|
10
|
-
const
|
|
9
|
+
const _definitionJs = require("./definition.js");
|
|
10
|
+
const _scannerJs = require("./string/shift/scanner.js");
|
|
11
11
|
const parseRecord = (def, ctx)=>{
|
|
12
12
|
const props = {};
|
|
13
13
|
for(const definitionKey in def){
|
|
14
14
|
let keyName = definitionKey;
|
|
15
15
|
let isOptional = false;
|
|
16
16
|
if (definitionKey[definitionKey.length - 1] === "?") {
|
|
17
|
-
if (definitionKey[definitionKey.length - 2] ===
|
|
17
|
+
if (definitionKey[definitionKey.length - 2] === _scannerJs.Scanner.escapeToken) {
|
|
18
18
|
keyName = `${definitionKey.slice(0, -2)}?`;
|
|
19
19
|
} else {
|
|
20
20
|
keyName = definitionKey.slice(0, -1);
|
|
@@ -22,7 +22,7 @@ const parseRecord = (def, ctx)=>{
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
ctx.path.push(keyName);
|
|
25
|
-
const propNode = (0,
|
|
25
|
+
const propNode = (0, _definitionJs.parseDefinition)(def[definitionKey], ctx);
|
|
26
26
|
ctx.path.pop();
|
|
27
27
|
props[keyName] = isOptional ? [
|
|
28
28
|
"?",
|
|
@@ -6,16 +6,29 @@ Object.defineProperty(exports, "DynamicState", {
|
|
|
6
6
|
enumerable: true,
|
|
7
7
|
get: ()=>DynamicState
|
|
8
8
|
});
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
9
|
+
const _nodeJs = require("../../../nodes/node.js");
|
|
10
|
+
const _rangeJs = require("../../../nodes/rules/range.js");
|
|
11
|
+
const _errorsJs = require("../../../utils/errors.js");
|
|
12
|
+
const _genericsJs = require("../../../utils/generics.js");
|
|
13
|
+
const _serializeJs = require("../../../utils/serialize.js");
|
|
14
|
+
const _scannerJs = require("../shift/scanner.js");
|
|
15
|
+
const _sharedJs = require("./shared.js");
|
|
16
|
+
function _defineProperty(obj, key, value) {
|
|
17
|
+
if (key in obj) {
|
|
18
|
+
Object.defineProperty(obj, key, {
|
|
19
|
+
value: value,
|
|
20
|
+
enumerable: true,
|
|
21
|
+
configurable: true,
|
|
22
|
+
writable: true
|
|
23
|
+
});
|
|
24
|
+
} else {
|
|
25
|
+
obj[key] = value;
|
|
26
|
+
}
|
|
27
|
+
return obj;
|
|
28
|
+
}
|
|
16
29
|
class DynamicState {
|
|
17
30
|
error(message) {
|
|
18
|
-
return (0,
|
|
31
|
+
return (0, _errorsJs.throwParseError)(message);
|
|
19
32
|
}
|
|
20
33
|
hasRoot() {
|
|
21
34
|
return this.root !== undefined;
|
|
@@ -26,12 +39,12 @@ class DynamicState {
|
|
|
26
39
|
}
|
|
27
40
|
rootToString() {
|
|
28
41
|
this.assertHasRoot();
|
|
29
|
-
return (0,
|
|
42
|
+
return (0, _serializeJs.stringify)(this.root);
|
|
30
43
|
}
|
|
31
44
|
ejectRootIfLimit() {
|
|
32
45
|
this.assertHasRoot();
|
|
33
46
|
const resolution = typeof this.root === "string" ? this.ctx.type.scope.resolveNode(this.root) : this.root;
|
|
34
|
-
if ((0,
|
|
47
|
+
if ((0, _nodeJs.isLiteralNode)(resolution, "number")) {
|
|
35
48
|
const limit = resolution.number.value;
|
|
36
49
|
this.root = undefined;
|
|
37
50
|
return limit;
|
|
@@ -46,12 +59,12 @@ class DynamicState {
|
|
|
46
59
|
}
|
|
47
60
|
assertHasRoot() {
|
|
48
61
|
if (this.root === undefined) {
|
|
49
|
-
return (0,
|
|
62
|
+
return (0, _errorsJs.throwInternalError)("Unexpected interaction with unset root");
|
|
50
63
|
}
|
|
51
64
|
}
|
|
52
65
|
assertUnsetRoot() {
|
|
53
66
|
if (this.root !== undefined) {
|
|
54
|
-
return (0,
|
|
67
|
+
return (0, _errorsJs.throwInternalError)("Unexpected attempt to overwrite root");
|
|
55
68
|
}
|
|
56
69
|
}
|
|
57
70
|
setRoot(node) {
|
|
@@ -59,10 +72,10 @@ class DynamicState {
|
|
|
59
72
|
this.root = node;
|
|
60
73
|
}
|
|
61
74
|
rootToArray() {
|
|
62
|
-
this.root = (0,
|
|
75
|
+
this.root = (0, _nodeJs.toArrayNode)(this.ejectRoot());
|
|
63
76
|
}
|
|
64
77
|
intersect(node) {
|
|
65
|
-
this.root = (0,
|
|
78
|
+
this.root = (0, _nodeJs.rootIntersection)(this.ejectRoot(), node, this.ctx.type);
|
|
66
79
|
}
|
|
67
80
|
ejectRoot() {
|
|
68
81
|
this.assertHasRoot();
|
|
@@ -78,18 +91,18 @@ class DynamicState {
|
|
|
78
91
|
}
|
|
79
92
|
finalize() {
|
|
80
93
|
if (this.groups.length) {
|
|
81
|
-
return this.error(
|
|
94
|
+
return this.error(_sharedJs.unclosedGroupMessage);
|
|
82
95
|
}
|
|
83
96
|
this.finalizeBranches();
|
|
84
97
|
this.scanner.finalized = true;
|
|
85
98
|
}
|
|
86
99
|
reduceLeftBound(limit, comparator) {
|
|
87
|
-
const invertedComparator =
|
|
88
|
-
if (!(0,
|
|
89
|
-
return this.error((0,
|
|
100
|
+
const invertedComparator = _scannerJs.Scanner.invertedComparators[comparator];
|
|
101
|
+
if (!(0, _genericsJs.isKeyOf)(invertedComparator, _rangeJs.minComparators)) {
|
|
102
|
+
return this.error((0, _sharedJs.writeUnpairableComparatorMessage)(comparator));
|
|
90
103
|
}
|
|
91
104
|
if (this.branches.range) {
|
|
92
|
-
return this.error((0,
|
|
105
|
+
return this.error((0, _sharedJs.writeMultipleLeftBoundsMessage)(`${this.branches.range.limit}`, this.branches.range.comparator, `${limit}`, invertedComparator));
|
|
93
106
|
}
|
|
94
107
|
this.branches.range = {
|
|
95
108
|
limit,
|
|
@@ -102,28 +115,28 @@ class DynamicState {
|
|
|
102
115
|
this.pushRootToBranch("|");
|
|
103
116
|
this.setRoot(this.branches.union);
|
|
104
117
|
} else if (this.branches.intersection) {
|
|
105
|
-
this.setRoot((0,
|
|
118
|
+
this.setRoot((0, _nodeJs.rootIntersection)(this.branches.intersection, this.ejectRoot(), this.ctx.type));
|
|
106
119
|
}
|
|
107
120
|
}
|
|
108
121
|
finalizeGroup() {
|
|
109
122
|
this.finalizeBranches();
|
|
110
123
|
const topBranchState = this.groups.pop();
|
|
111
124
|
if (!topBranchState) {
|
|
112
|
-
return this.error((0,
|
|
125
|
+
return this.error((0, _sharedJs.writeUnmatchedGroupCloseMessage)(this.scanner.unscanned));
|
|
113
126
|
}
|
|
114
127
|
this.branches = topBranchState;
|
|
115
128
|
}
|
|
116
129
|
pushRootToBranch(token) {
|
|
117
130
|
this.assertRangeUnset();
|
|
118
|
-
this.branches.intersection = this.branches.intersection ? (0,
|
|
131
|
+
this.branches.intersection = this.branches.intersection ? (0, _nodeJs.rootIntersection)(this.branches.intersection, this.ejectRoot(), this.ctx.type) : this.ejectRoot();
|
|
119
132
|
if (token === "|") {
|
|
120
|
-
this.branches.union = this.branches.union ? (0,
|
|
133
|
+
this.branches.union = this.branches.union ? (0, _nodeJs.rootUnion)(this.branches.union, this.branches.intersection, this.ctx.type) : this.branches.intersection;
|
|
121
134
|
delete this.branches.intersection;
|
|
122
135
|
}
|
|
123
136
|
}
|
|
124
137
|
assertRangeUnset() {
|
|
125
138
|
if (this.branches.range) {
|
|
126
|
-
return this.error((0,
|
|
139
|
+
return this.error((0, _sharedJs.writeOpenRangeMessage)(`${this.branches.range.limit}`, this.branches.range.comparator));
|
|
127
140
|
}
|
|
128
141
|
}
|
|
129
142
|
reduceGroupOpen() {
|
|
@@ -138,12 +151,17 @@ class DynamicState {
|
|
|
138
151
|
return this;
|
|
139
152
|
}
|
|
140
153
|
constructor(def, ctx){
|
|
154
|
+
_defineProperty(this, "ctx", void 0);
|
|
155
|
+
_defineProperty(this, "scanner", void 0);
|
|
156
|
+
_defineProperty(this, "root", void 0);
|
|
157
|
+
_defineProperty(this, "branches", void 0);
|
|
158
|
+
_defineProperty(this, "groups", void 0);
|
|
141
159
|
this.ctx = ctx;
|
|
142
160
|
this.branches = {};
|
|
143
161
|
this.groups = [];
|
|
144
|
-
this.scanner = new
|
|
162
|
+
this.scanner = new _scannerJs.Scanner(def);
|
|
145
163
|
}
|
|
146
164
|
}
|
|
147
165
|
const ejectedProxy = new Proxy({}, {
|
|
148
|
-
get: ()=>(0,
|
|
166
|
+
get: ()=>(0, _errorsJs.throwInternalError)(`Unexpected attempt to access ejected attributes`)
|
|
149
167
|
});
|
|
@@ -15,9 +15,9 @@ _export(exports, {
|
|
|
15
15
|
writeUnpairableComparatorMessage: ()=>writeUnpairableComparatorMessage,
|
|
16
16
|
writeMultipleLeftBoundsMessage: ()=>writeMultipleLeftBoundsMessage
|
|
17
17
|
});
|
|
18
|
-
const
|
|
18
|
+
const _scannerJs = require("../shift/scanner.js");
|
|
19
19
|
const writeUnmatchedGroupCloseMessage = (unscanned)=>`Unmatched )${unscanned === "" ? "" : ` before ${unscanned}`}`;
|
|
20
20
|
const unclosedGroupMessage = "Missing )";
|
|
21
21
|
const writeOpenRangeMessage = (min, comparator)=>`Left bounds are only valid when paired with right bounds (try ...${comparator}${min})`;
|
|
22
22
|
const writeUnpairableComparatorMessage = (comparator)=>`Left-bounded expressions must specify their limits using < or <= (was ${comparator})`;
|
|
23
|
-
const writeMultipleLeftBoundsMessage = (openLimit, openComparator, limit, comparator)=>`An expression may have at most one left bound (parsed ${openLimit}${
|
|
23
|
+
const writeMultipleLeftBoundsMessage = (openLimit, openComparator, limit, comparator)=>`An expression may have at most one left bound (parsed ${openLimit}${_scannerJs.Scanner.invertedComparators[openComparator]}, ${limit}${_scannerJs.Scanner.invertedComparators[comparator]})`;
|
|
@@ -13,7 +13,7 @@ _export(exports, {
|
|
|
13
13
|
enclosingChar: ()=>enclosingChar,
|
|
14
14
|
writeUnterminatedEnclosedMessage: ()=>writeUnterminatedEnclosedMessage
|
|
15
15
|
});
|
|
16
|
-
const
|
|
16
|
+
const _regexJs = require("../../../../nodes/rules/regex.js");
|
|
17
17
|
const parseEnclosed = (s, enclosing)=>{
|
|
18
18
|
const token = s.scanner.shiftUntil(untilLookaheadIsClosing[enclosing]);
|
|
19
19
|
if (s.scanner.lookahead === "") {
|
|
@@ -22,7 +22,7 @@ const parseEnclosed = (s, enclosing)=>{
|
|
|
22
22
|
// Shift the scanner one additional time for the second enclosing token
|
|
23
23
|
if (s.scanner.shift() === "/") {
|
|
24
24
|
// Cache the regex instance to throw right way if its invalid
|
|
25
|
-
(0,
|
|
25
|
+
(0, _regexJs.getRegex)(token);
|
|
26
26
|
s.setRoot({
|
|
27
27
|
string: {
|
|
28
28
|
regex: token
|
|
@@ -6,6 +6,6 @@ Object.defineProperty(exports, "parseOperand", {
|
|
|
6
6
|
enumerable: true,
|
|
7
7
|
get: ()=>parseOperand
|
|
8
8
|
});
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const parseOperand = (s)=>s.scanner.lookahead === "" ? s.error((0,
|
|
9
|
+
const _enclosedJs = require("./enclosed.js");
|
|
10
|
+
const _unenclosedJs = require("./unenclosed.js");
|
|
11
|
+
const parseOperand = (s)=>s.scanner.lookahead === "" ? s.error((0, _unenclosedJs.writeMissingOperandMessage)(s)) : s.scanner.lookahead === "(" ? s.shiftedByOne().reduceGroupOpen() : s.scanner.lookaheadIsIn(_enclosedJs.enclosingChar) ? (0, _enclosedJs.parseEnclosed)(s, s.scanner.shift()) : s.scanner.lookahead === " " ? parseOperand(s.shiftedByOne()) : (0, _unenclosedJs.parseUnenclosed)(s);
|
|
@@ -15,7 +15,7 @@ _export(exports, {
|
|
|
15
15
|
writeMissingRightOperandMessage: ()=>writeMissingRightOperandMessage,
|
|
16
16
|
writeExpressionExpectedMessage: ()=>writeExpressionExpectedMessage
|
|
17
17
|
});
|
|
18
|
-
const
|
|
18
|
+
const _numericLiteralsJs = require("../../../../utils/numericLiterals.js");
|
|
19
19
|
const parseUnenclosed = (s)=>{
|
|
20
20
|
const token = s.scanner.shiftUntilNextTerminator();
|
|
21
21
|
s.setRoot(unenclosedToNode(s, token));
|
|
@@ -27,7 +27,7 @@ const unenclosedToNode = (s, token)=>{
|
|
|
27
27
|
return maybeParseUnenclosedLiteral(token) ?? s.error(token === "" ? writeMissingOperandMessage(s) : writeUnresolvableMessage(token));
|
|
28
28
|
};
|
|
29
29
|
const maybeParseUnenclosedLiteral = (token)=>{
|
|
30
|
-
const maybeNumber = (0,
|
|
30
|
+
const maybeNumber = (0, _numericLiteralsJs.tryParseWellFormedNumber)(token);
|
|
31
31
|
if (maybeNumber !== undefined) {
|
|
32
32
|
return {
|
|
33
33
|
number: {
|
|
@@ -35,7 +35,7 @@ const maybeParseUnenclosedLiteral = (token)=>{
|
|
|
35
35
|
}
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
|
-
const maybeBigint = (0,
|
|
38
|
+
const maybeBigint = (0, _numericLiteralsJs.tryParseWellFormedBigint)(token);
|
|
39
39
|
if (maybeBigint !== undefined) {
|
|
40
40
|
return {
|
|
41
41
|
bigint: {
|
|
@@ -15,45 +15,45 @@ _export(exports, {
|
|
|
15
15
|
writeInvalidLimitMessage: ()=>writeInvalidLimitMessage,
|
|
16
16
|
writeEmptyRangeMessage: ()=>writeEmptyRangeMessage
|
|
17
17
|
});
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const
|
|
18
|
+
const _composeJs = require("../../../../nodes/compose.js");
|
|
19
|
+
const _rangeJs = require("../../../../nodes/rules/range.js");
|
|
20
|
+
const _errorsJs = require("../../../../utils/errors.js");
|
|
21
|
+
const _genericsJs = require("../../../../utils/generics.js");
|
|
22
|
+
const _numericLiteralsJs = require("../../../../utils/numericLiterals.js");
|
|
23
|
+
const _boundJs = require("../../../ast/bound.js");
|
|
24
|
+
const _sharedJs = require("../../reduce/shared.js");
|
|
25
|
+
const _scannerJs = require("../scanner.js");
|
|
26
26
|
const parseBound = (s, start)=>{
|
|
27
27
|
const comparator = shiftComparator(s, start);
|
|
28
28
|
const maybeMin = s.ejectRootIfLimit();
|
|
29
29
|
return maybeMin === undefined ? parseRightBound(s, comparator) : s.reduceLeftBound(maybeMin, comparator);
|
|
30
30
|
};
|
|
31
|
-
const shiftComparator = (s, start)=>s.scanner.lookaheadIs("=") ? `${start}${s.scanner.shift()}` : (0,
|
|
31
|
+
const shiftComparator = (s, start)=>s.scanner.lookaheadIs("=") ? `${start}${s.scanner.shift()}` : (0, _genericsJs.isKeyOf)(start, _scannerJs.Scanner.oneCharComparators) ? start : s.error(singleEqualsMessage);
|
|
32
32
|
const singleEqualsMessage = `= is not a valid comparator. Use == to check for equality`;
|
|
33
33
|
const parseRightBound = (s, comparator)=>{
|
|
34
34
|
const limitToken = s.scanner.shiftUntilNextTerminator();
|
|
35
|
-
const limit = (0,
|
|
35
|
+
const limit = (0, _numericLiteralsJs.tryParseWellFormedNumber)(limitToken, writeInvalidLimitMessage(comparator, limitToken + s.scanner.unscanned));
|
|
36
36
|
const openRange = s.ejectRangeIfOpen();
|
|
37
37
|
const rightBound = {
|
|
38
38
|
comparator,
|
|
39
39
|
limit
|
|
40
40
|
};
|
|
41
|
-
const range = openRange ? !hasComparatorIn(rightBound,
|
|
41
|
+
const range = openRange ? !hasComparatorIn(rightBound, _rangeJs.maxComparators) ? s.error((0, _sharedJs.writeUnpairableComparatorMessage)(comparator)) : (0, _rangeJs.compareStrictness)("min", openRange, rightBound) === "l" ? s.error(writeEmptyRangeMessage({
|
|
42
42
|
min: openRange,
|
|
43
43
|
max: rightBound
|
|
44
44
|
})) : {
|
|
45
45
|
min: openRange,
|
|
46
46
|
max: rightBound
|
|
47
|
-
} : hasComparator(rightBound, "==") ? rightBound : hasComparatorIn(rightBound,
|
|
47
|
+
} : hasComparator(rightBound, "==") ? rightBound : hasComparatorIn(rightBound, _rangeJs.minComparators) ? {
|
|
48
48
|
min: rightBound
|
|
49
|
-
} : hasComparatorIn(rightBound,
|
|
49
|
+
} : hasComparatorIn(rightBound, _rangeJs.maxComparators) ? {
|
|
50
50
|
max: rightBound
|
|
51
|
-
} : (0,
|
|
51
|
+
} : (0, _errorsJs.throwInternalError)(`Unexpected comparator '${rightBound.comparator}'`);
|
|
52
52
|
s.intersect(distributeRange(range, s));
|
|
53
53
|
};
|
|
54
54
|
const distributeRange = (range, s)=>{
|
|
55
55
|
const resolution = s.resolveRoot();
|
|
56
|
-
const domains = (0,
|
|
56
|
+
const domains = (0, _genericsJs.objectKeysOf)(resolution);
|
|
57
57
|
const distributedRange = {};
|
|
58
58
|
const rangePredicate = {
|
|
59
59
|
range
|
|
@@ -71,17 +71,17 @@ const distributeRange = (range, s)=>{
|
|
|
71
71
|
if (resolution.object === true) {
|
|
72
72
|
return false;
|
|
73
73
|
}
|
|
74
|
-
return (0,
|
|
74
|
+
return (0, _genericsJs.listFrom)(resolution.object).every((branch)=>"class" in branch && branch.class === Array);
|
|
75
75
|
default:
|
|
76
76
|
return false;
|
|
77
77
|
}
|
|
78
78
|
});
|
|
79
79
|
if (!isBoundable) {
|
|
80
|
-
s.error((0,
|
|
80
|
+
s.error((0, _boundJs.writeUnboundableMessage)(s.rootToString()));
|
|
81
81
|
}
|
|
82
82
|
return distributedRange;
|
|
83
83
|
};
|
|
84
84
|
const hasComparator = (bound, comparator)=>bound.comparator === comparator;
|
|
85
85
|
const hasComparatorIn = (bound, comparators)=>bound.comparator in comparators;
|
|
86
86
|
const writeInvalidLimitMessage = (comparator, limit)=>`Comparator ${comparator} must be followed by a number literal (was '${limit}')`;
|
|
87
|
-
const writeEmptyRangeMessage = (range)=>`${(0,
|
|
87
|
+
const writeEmptyRangeMessage = (range)=>`${(0, _composeJs.stringifyRange)(range)} is empty`;
|
|
@@ -12,16 +12,16 @@ _export(exports, {
|
|
|
12
12
|
parseDivisor: ()=>parseDivisor,
|
|
13
13
|
writeInvalidDivisorMessage: ()=>writeInvalidDivisorMessage
|
|
14
14
|
});
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
15
|
+
const _genericsJs = require("../../../../utils/generics.js");
|
|
16
|
+
const _numericLiteralsJs = require("../../../../utils/numericLiterals.js");
|
|
17
|
+
const _divisorJs = require("../../../ast/divisor.js");
|
|
18
18
|
const parseDivisor = (s)=>{
|
|
19
19
|
const divisorToken = s.scanner.shiftUntilNextTerminator();
|
|
20
|
-
const divisor = (0,
|
|
20
|
+
const divisor = (0, _numericLiteralsJs.tryParseWellFormedInteger)(divisorToken, writeInvalidDivisorMessage(divisorToken));
|
|
21
21
|
if (divisor === 0) {
|
|
22
22
|
s.error(writeInvalidDivisorMessage(0));
|
|
23
23
|
}
|
|
24
|
-
const rootDomains = (0,
|
|
24
|
+
const rootDomains = (0, _genericsJs.objectKeysOf)(s.resolveRoot());
|
|
25
25
|
if (rootDomains.length === 1 && rootDomains[0] === "number") {
|
|
26
26
|
s.intersect({
|
|
27
27
|
number: {
|
|
@@ -29,7 +29,7 @@ const parseDivisor = (s)=>{
|
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
31
|
} else {
|
|
32
|
-
s.error((0,
|
|
32
|
+
s.error((0, _divisorJs.writeIndivisibleMessage)(s.rootToString()));
|
|
33
33
|
}
|
|
34
34
|
};
|
|
35
35
|
const writeInvalidDivisorMessage = (divisor)=>`% operator must be followed by a non-zero integer literal (was ${divisor})`;
|
|
@@ -13,14 +13,14 @@ _export(exports, {
|
|
|
13
13
|
writeUnexpectedCharacterMessage: ()=>writeUnexpectedCharacterMessage,
|
|
14
14
|
incompleteArrayTokenMessage: ()=>incompleteArrayTokenMessage
|
|
15
15
|
});
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
16
|
+
const _errorsJs = require("../../../../utils/errors.js");
|
|
17
|
+
const _genericsJs = require("../../../../utils/generics.js");
|
|
18
|
+
const _scannerJs = require("../scanner.js");
|
|
19
|
+
const _boundsJs = require("./bounds.js");
|
|
20
|
+
const _divisorJs = require("./divisor.js");
|
|
21
21
|
const parseOperator = (s)=>{
|
|
22
22
|
const lookahead = s.scanner.shift();
|
|
23
|
-
return lookahead === "" ? s.finalize() : lookahead === "[" ? s.scanner.shift() === "]" ? s.rootToArray() : s.error(incompleteArrayTokenMessage) : (0,
|
|
23
|
+
return lookahead === "" ? s.finalize() : lookahead === "[" ? s.scanner.shift() === "]" ? s.rootToArray() : s.error(incompleteArrayTokenMessage) : (0, _genericsJs.isKeyOf)(lookahead, _scannerJs.Scanner.branchTokens) ? s.pushRootToBranch(lookahead) : lookahead === ")" ? s.finalizeGroup() : (0, _genericsJs.isKeyOf)(lookahead, _scannerJs.Scanner.comparatorStartChars) ? (0, _boundsJs.parseBound)(s, lookahead) : lookahead === "%" ? (0, _divisorJs.parseDivisor)(s) : lookahead === " " ? parseOperator(s) : (0, _errorsJs.throwInternalError)(writeUnexpectedCharacterMessage(lookahead));
|
|
24
24
|
};
|
|
25
25
|
const writeUnexpectedCharacterMessage = (char)=>`Unexpected character '${char}'`;
|
|
26
26
|
const incompleteArrayTokenMessage = `Missing expected ']'`;
|
|
@@ -6,6 +6,19 @@ Object.defineProperty(exports, "Scanner", {
|
|
|
6
6
|
enumerable: true,
|
|
7
7
|
get: ()=>Scanner
|
|
8
8
|
});
|
|
9
|
+
function _defineProperty(obj, key, value) {
|
|
10
|
+
if (key in obj) {
|
|
11
|
+
Object.defineProperty(obj, key, {
|
|
12
|
+
value: value,
|
|
13
|
+
enumerable: true,
|
|
14
|
+
configurable: true,
|
|
15
|
+
writable: true
|
|
16
|
+
});
|
|
17
|
+
} else {
|
|
18
|
+
obj[key] = value;
|
|
19
|
+
}
|
|
20
|
+
return obj;
|
|
21
|
+
}
|
|
9
22
|
class Scanner {
|
|
10
23
|
/** Get lookahead and advance scanner by one */ shift() {
|
|
11
24
|
return this.chars[this.i++] ?? "";
|
|
@@ -41,7 +54,9 @@ class Scanner {
|
|
|
41
54
|
return this.lookahead in tokens;
|
|
42
55
|
}
|
|
43
56
|
constructor(def){
|
|
44
|
-
this
|
|
57
|
+
_defineProperty(this, "chars", void 0);
|
|
58
|
+
_defineProperty(this, "i", void 0);
|
|
59
|
+
_defineProperty(this, "finalized", false);
|
|
45
60
|
this.chars = [
|
|
46
61
|
...def
|
|
47
62
|
];
|
|
@@ -13,10 +13,10 @@ _export(exports, {
|
|
|
13
13
|
maybeNaiveParse: ()=>maybeNaiveParse,
|
|
14
14
|
fullStringParse: ()=>fullStringParse
|
|
15
15
|
});
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
16
|
+
const _nodeJs = require("../../nodes/node.js");
|
|
17
|
+
const _dynamicJs = require("./reduce/dynamic.js");
|
|
18
|
+
const _operandJs = require("./shift/operand/operand.js");
|
|
19
|
+
const _operatorJs = require("./shift/operator/operator.js");
|
|
20
20
|
const parseString = (def, ctx)=>ctx.type.scope.parseCache.get(def) ?? ctx.type.scope.parseCache.set(def, maybeNaiveParse(def, ctx) ?? fullStringParse(def, ctx));
|
|
21
21
|
const maybeNaiveParse = (def, ctx)=>{
|
|
22
22
|
if (ctx.type.scope.addParsedReferenceIfResolvable(def, ctx)) {
|
|
@@ -25,13 +25,13 @@ const maybeNaiveParse = (def, ctx)=>{
|
|
|
25
25
|
if (def.endsWith("[]")) {
|
|
26
26
|
const elementDef = def.slice(0, -2);
|
|
27
27
|
if (ctx.type.scope.addParsedReferenceIfResolvable(def, ctx)) {
|
|
28
|
-
return (0,
|
|
28
|
+
return (0, _nodeJs.toArrayNode)(elementDef);
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
};
|
|
32
32
|
const fullStringParse = (def, ctx)=>{
|
|
33
|
-
const s = new
|
|
34
|
-
(0,
|
|
33
|
+
const s = new _dynamicJs.DynamicState(def, ctx);
|
|
34
|
+
(0, _operandJs.parseOperand)(s);
|
|
35
35
|
return loop(s);
|
|
36
36
|
};
|
|
37
37
|
const loop = (s)=>{
|
|
@@ -40,4 +40,4 @@ const loop = (s)=>{
|
|
|
40
40
|
}
|
|
41
41
|
return s.ejectFinalizedRoot();
|
|
42
42
|
};
|
|
43
|
-
const next = (s)=>s.hasRoot() ? (0,
|
|
43
|
+
const next = (s)=>s.hasRoot() ? (0, _operatorJs.parseOperator)(s) : (0, _operandJs.parseOperand)(s);
|
package/dist/cjs/scopes/ark.js
CHANGED
|
@@ -15,31 +15,31 @@ _export(exports, {
|
|
|
15
15
|
spaces: ()=>spaces,
|
|
16
16
|
type: ()=>type
|
|
17
17
|
});
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const arkScope = (0,
|
|
18
|
+
const _jsObjectsJs = require("./jsObjects.js");
|
|
19
|
+
const _scopeJs = require("./scope.js");
|
|
20
|
+
const _tsKeywordsJs = require("./tsKeywords.js");
|
|
21
|
+
const _validationJs = require("./validation/validation.js");
|
|
22
|
+
const arkScope = (0, _scopeJs.scope)({}, {
|
|
23
23
|
name: "standard",
|
|
24
24
|
includes: [
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
_tsKeywordsJs.tsKeywords,
|
|
26
|
+
_jsObjectsJs.jsObjects,
|
|
27
|
+
_validationJs.validation
|
|
28
28
|
],
|
|
29
29
|
standard: false
|
|
30
30
|
});
|
|
31
31
|
const ark = arkScope.compile();
|
|
32
32
|
const scopes = {
|
|
33
|
-
root:
|
|
34
|
-
tsKeywords:
|
|
35
|
-
jsObjects:
|
|
36
|
-
validation:
|
|
33
|
+
root: _scopeJs.rootScope,
|
|
34
|
+
tsKeywords: _tsKeywordsJs.tsKeywordsScope,
|
|
35
|
+
jsObjects: _jsObjectsJs.jsObjectsScope,
|
|
36
|
+
validation: _validationJs.validationScope,
|
|
37
37
|
ark: arkScope
|
|
38
38
|
};
|
|
39
39
|
const spaces = {
|
|
40
|
-
tsKeywords:
|
|
41
|
-
jsObjects:
|
|
42
|
-
validation:
|
|
40
|
+
tsKeywords: _tsKeywordsJs.tsKeywords,
|
|
41
|
+
jsObjects: _jsObjectsJs.jsObjects,
|
|
42
|
+
validation: _validationJs.validation,
|
|
43
43
|
ark
|
|
44
44
|
};
|
|
45
45
|
const type = arkScope.type;
|
package/dist/cjs/scopes/cache.js
CHANGED
|
@@ -12,7 +12,20 @@ _export(exports, {
|
|
|
12
12
|
Cache: ()=>Cache,
|
|
13
13
|
FreezingCache: ()=>FreezingCache
|
|
14
14
|
});
|
|
15
|
-
const
|
|
15
|
+
const _freezeJs = require("../utils/freeze.js");
|
|
16
|
+
function _defineProperty(obj, key, value) {
|
|
17
|
+
if (key in obj) {
|
|
18
|
+
Object.defineProperty(obj, key, {
|
|
19
|
+
value: value,
|
|
20
|
+
enumerable: true,
|
|
21
|
+
configurable: true,
|
|
22
|
+
writable: true
|
|
23
|
+
});
|
|
24
|
+
} else {
|
|
25
|
+
obj[key] = value;
|
|
26
|
+
}
|
|
27
|
+
return obj;
|
|
28
|
+
}
|
|
16
29
|
class Cache {
|
|
17
30
|
get root() {
|
|
18
31
|
return this.cache;
|
|
@@ -28,12 +41,12 @@ class Cache {
|
|
|
28
41
|
return item;
|
|
29
42
|
}
|
|
30
43
|
constructor(){
|
|
31
|
-
this
|
|
44
|
+
_defineProperty(this, "cache", {});
|
|
32
45
|
}
|
|
33
46
|
}
|
|
34
47
|
class FreezingCache extends Cache {
|
|
35
48
|
set(name, item) {
|
|
36
|
-
this.cache[name] = (0,
|
|
49
|
+
this.cache[name] = (0, _freezeJs.deepFreeze)(item);
|
|
37
50
|
return item;
|
|
38
51
|
}
|
|
39
52
|
}
|