arktype 0.1.4 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/api.cjs +4 -3
- package/dist/api.d.ts +3 -2
- package/dist/api.mjs +2 -1
- package/dist/cjs/nodes/{branches.js → branch.js} +56 -10
- package/dist/cjs/nodes/compose.js +1 -2
- package/dist/cjs/nodes/discriminate.js +7 -13
- package/dist/cjs/nodes/node.js +32 -4
- package/dist/cjs/nodes/predicate.js +7 -7
- package/dist/cjs/nodes/rules/class.js +10 -4
- package/dist/cjs/nodes/rules/divisor.js +1 -5
- package/dist/cjs/nodes/rules/props.js +75 -25
- package/dist/cjs/nodes/rules/range.js +1 -5
- package/dist/cjs/nodes/rules/regex.js +2 -44
- package/dist/cjs/nodes/rules/rules.js +21 -61
- package/dist/cjs/parse/definition.js +2 -2
- package/dist/cjs/parse/string/reduce/dynamic.js +1 -2
- package/dist/cjs/parse/string/shift/operator/bounds.js +1 -1
- package/dist/cjs/parse/string/string.js +2 -2
- package/dist/cjs/parse/tuple/keyof.js +37 -18
- package/dist/cjs/parse/tuple/morph.js +7 -6
- package/dist/cjs/parse/tuple/tuple.js +16 -9
- package/dist/cjs/scopes/cache.js +39 -0
- package/dist/cjs/scopes/jsObjects.js +133 -0
- package/dist/cjs/{main.js → scopes/scope.js} +31 -364
- package/dist/cjs/scopes/standard.js +44 -0
- package/dist/cjs/scopes/tsKeywords.js +113 -0
- package/dist/cjs/scopes/type.js +67 -0
- package/dist/cjs/scopes/validation.js +64 -0
- package/dist/cjs/traverse/problems.js +55 -95
- package/dist/cjs/traverse/traverse.js +127 -134
- package/dist/cjs/utils/numericLiterals.js +3 -0
- package/dist/cjs/utils/objectKinds.js +1 -2
- package/dist/mjs/nodes/{branches.js → branch.js} +45 -2
- package/dist/mjs/nodes/compose.js +1 -2
- package/dist/mjs/nodes/discriminate.js +6 -12
- package/dist/mjs/nodes/node.js +30 -3
- package/dist/mjs/nodes/predicate.js +2 -2
- package/dist/mjs/nodes/rules/class.js +10 -4
- package/dist/mjs/nodes/rules/divisor.js +1 -5
- package/dist/mjs/nodes/rules/props.js +74 -27
- package/dist/mjs/nodes/rules/range.js +1 -5
- package/dist/mjs/nodes/rules/regex.js +1 -43
- package/dist/mjs/nodes/rules/rules.js +22 -61
- package/dist/mjs/parse/definition.js +1 -1
- package/dist/mjs/parse/string/reduce/dynamic.js +2 -3
- package/dist/mjs/parse/string/shift/operator/bounds.js +1 -1
- package/dist/mjs/parse/string/string.js +2 -2
- package/dist/mjs/parse/tuple/keyof.js +38 -19
- package/dist/mjs/parse/tuple/morph.js +7 -6
- package/dist/mjs/parse/tuple/tuple.js +17 -10
- package/dist/mjs/scopes/cache.js +25 -0
- package/dist/mjs/scopes/jsObjects.js +119 -0
- package/dist/mjs/{main.js → scopes/scope.js} +15 -344
- package/dist/mjs/scopes/standard.js +27 -0
- package/dist/mjs/scopes/tsKeywords.js +99 -0
- package/dist/mjs/scopes/type.js +53 -0
- package/dist/mjs/scopes/validation.js +51 -0
- package/dist/mjs/traverse/problems.js +55 -95
- package/dist/mjs/traverse/traverse.js +129 -135
- package/dist/mjs/utils/numericLiterals.js +2 -1
- package/dist/mjs/utils/objectKinds.js +1 -1
- package/dist/tsconfig.temp.tsbuildinfo +1 -1
- package/dist/types/nodes/branch.d.ts +36 -0
- package/dist/types/nodes/compose.d.ts +6 -11
- package/dist/types/nodes/discriminate.d.ts +1 -1
- package/dist/types/nodes/infer.d.ts +16 -15
- package/dist/types/nodes/node.d.ts +18 -9
- package/dist/types/nodes/predicate.d.ts +18 -57
- package/dist/types/nodes/rules/class.d.ts +3 -2
- package/dist/types/nodes/rules/divisor.d.ts +2 -1
- package/dist/types/nodes/rules/props.d.ts +19 -11
- package/dist/types/nodes/rules/range.d.ts +2 -1
- package/dist/types/nodes/rules/regex.d.ts +2 -11
- package/dist/types/nodes/rules/rules.d.ts +11 -21
- package/dist/types/parse/definition.d.ts +1 -1
- package/dist/types/parse/string/ast.d.ts +4 -2
- package/dist/types/parse/string/reduce/shared.d.ts +1 -1
- package/dist/types/parse/string/reduce/static.d.ts +1 -1
- package/dist/types/parse/string/shift/operator/bounds.d.ts +1 -1
- package/dist/types/parse/string/string.d.ts +1 -1
- package/dist/types/parse/tuple/keyof.d.ts +2 -2
- package/dist/types/parse/tuple/morph.d.ts +1 -1
- package/dist/types/parse/tuple/narrow.d.ts +1 -1
- package/dist/types/parse/tuple/tuple.d.ts +1 -1
- package/dist/types/scopes/cache.d.ts +14 -0
- package/dist/types/scopes/jsObjects.d.ts +36 -0
- package/dist/types/scopes/scope.d.ts +76 -0
- package/dist/types/scopes/standard.d.ts +280 -0
- package/dist/types/scopes/tsKeywords.d.ts +32 -0
- package/dist/types/scopes/type.d.ts +47 -0
- package/dist/types/scopes/validation.d.ts +21 -0
- package/dist/types/traverse/problems.d.ts +35 -53
- package/dist/types/traverse/traverse.d.ts +30 -24
- package/dist/types/utils/generics.d.ts +0 -1
- package/dist/types/utils/numericLiterals.d.ts +2 -0
- package/dist/types/utils/objectKinds.d.ts +43 -43
- package/package.json +2 -3
- package/dist/cjs/nodes/functors.js +0 -35
- package/dist/cjs/nodes/rules/objectKind.js +0 -78
- package/dist/mjs/nodes/functors.js +0 -27
- package/dist/mjs/nodes/rules/objectKind.js +0 -63
- package/dist/types/main.d.ts +0 -324
- package/dist/types/nodes/branches.d.ts +0 -14
- package/dist/types/nodes/functors.d.ts +0 -6
- package/dist/types/nodes/rules/objectKind.d.ts +0 -15
|
@@ -9,56 +9,23 @@ function _export(target, all) {
|
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
-
branchIntersection: ()=>branchIntersection,
|
|
13
12
|
rulesIntersection: ()=>rulesIntersection,
|
|
14
13
|
narrowableRulesIntersection: ()=>narrowableRulesIntersection,
|
|
14
|
+
flattenRules: ()=>flattenRules,
|
|
15
15
|
precedenceMap: ()=>precedenceMap,
|
|
16
|
-
flattenBranch: ()=>flattenBranch,
|
|
17
16
|
literalSatisfiesRules: ()=>literalSatisfiesRules
|
|
18
17
|
});
|
|
19
|
-
const _astTs = require("../../parse/string/ast.js");
|
|
20
|
-
const _errorsTs = require("../../utils/errors.js");
|
|
21
18
|
const _genericsTs = require("../../utils/generics.js");
|
|
22
19
|
const _composeTs = require("../compose.js");
|
|
23
20
|
const _classTs = require("./class.js");
|
|
24
21
|
const _collapsibleSetTs = require("./collapsibleSet.js");
|
|
25
22
|
const _divisorTs = require("./divisor.js");
|
|
26
|
-
const _objectKindTs = require("./objectKind.js");
|
|
27
23
|
const _propsTs = require("./props.js");
|
|
28
24
|
const _rangeTs = require("./range.js");
|
|
29
25
|
const _regexTs = require("./regex.js");
|
|
30
|
-
const rulesOf = (branch)=>branch.input ?? branch;
|
|
31
|
-
const branchIntersection = (l, r, state)=>{
|
|
32
|
-
const lRules = rulesOf(l);
|
|
33
|
-
const rRules = rulesOf(r);
|
|
34
|
-
const rulesResult = rulesIntersection(lRules, rRules, state);
|
|
35
|
-
if ("morph" in l) {
|
|
36
|
-
if ("morph" in r) {
|
|
37
|
-
if (l.morph === r.morph) {
|
|
38
|
-
return (0, _composeTs.isEquality)(rulesResult) || (0, _composeTs.isDisjoint)(rulesResult) ? rulesResult : {
|
|
39
|
-
input: rulesResult,
|
|
40
|
-
morph: l.morph
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
return state.lastOperator === "&" ? (0, _errorsTs.throwParseError)((0, _astTs.writeImplicitNeverMessage)(state.path, "Intersection", "of morphs")) : {};
|
|
44
|
-
}
|
|
45
|
-
return (0, _composeTs.isDisjoint)(rulesResult) ? rulesResult : {
|
|
46
|
-
input: (0, _composeTs.isEquality)(rulesResult) ? l.input : rulesResult,
|
|
47
|
-
morph: l.morph
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
if ("morph" in r) {
|
|
51
|
-
return (0, _composeTs.isDisjoint)(rulesResult) ? rulesResult : {
|
|
52
|
-
input: (0, _composeTs.isEquality)(rulesResult) ? r.input : rulesResult,
|
|
53
|
-
morph: r.morph
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
return rulesResult;
|
|
57
|
-
};
|
|
58
26
|
const rulesIntersection = (l, r, state)=>"value" in l ? "value" in r ? l.value === r.value ? (0, _composeTs.equality)() : state.addDisjoint("value", l.value, r.value) : literalSatisfiesRules(l.value, r, state) ? l : state.addDisjoint("leftAssignability", l, r) : "value" in r ? literalSatisfiesRules(r.value, l, state) ? r : state.addDisjoint("rightAssignability", l, r) : narrowableRulesIntersection(l, r, state);
|
|
59
27
|
const narrowIntersection = (0, _composeTs.composeIntersection)(_collapsibleSetTs.collapsibleListUnion);
|
|
60
28
|
const narrowableRulesIntersection = (0, _composeTs.composeKeyedIntersection)({
|
|
61
|
-
objectKind: _objectKindTs.objectKindIntersection,
|
|
62
29
|
divisor: _divisorTs.divisorIntersection,
|
|
63
30
|
regex: _regexTs.regexIntersection,
|
|
64
31
|
props: _propsTs.propsIntersection,
|
|
@@ -68,13 +35,20 @@ const narrowableRulesIntersection = (0, _composeTs.composeKeyedIntersection)({
|
|
|
68
35
|
}, {
|
|
69
36
|
onEmpty: "bubble"
|
|
70
37
|
});
|
|
38
|
+
const flattenRules = (rules, ctx)=>{
|
|
39
|
+
const entries = [];
|
|
40
|
+
let k;
|
|
41
|
+
for(k in rules){
|
|
42
|
+
ruleFlatteners[k](entries, rules[k], ctx);
|
|
43
|
+
}
|
|
44
|
+
return entries.sort((l, r)=>precedenceMap[l[0]] - precedenceMap[r[0]]);
|
|
45
|
+
};
|
|
71
46
|
const ruleFlatteners = {
|
|
72
|
-
objectKind: _objectKindTs.flattenObjectKind,
|
|
73
47
|
regex: (entries, rule)=>{
|
|
74
48
|
for (const source of (0, _genericsTs.listFrom)(rule)){
|
|
75
49
|
entries.push([
|
|
76
50
|
"regex",
|
|
77
|
-
|
|
51
|
+
source
|
|
78
52
|
]);
|
|
79
53
|
}
|
|
80
54
|
},
|
|
@@ -109,44 +83,30 @@ const ruleFlatteners = {
|
|
|
109
83
|
};
|
|
110
84
|
const precedenceMap = {
|
|
111
85
|
// Critical: No other checks are performed if these fail
|
|
86
|
+
config: 0,
|
|
112
87
|
domain: 0,
|
|
113
88
|
value: 0,
|
|
114
89
|
domains: 0,
|
|
115
90
|
branches: 0,
|
|
116
|
-
objectKind: 0,
|
|
117
91
|
switch: 0,
|
|
118
92
|
alias: 0,
|
|
93
|
+
class: 0,
|
|
119
94
|
// Shallow: All shallow checks will be performed even if one or more fail
|
|
120
|
-
class: 1,
|
|
121
95
|
regex: 1,
|
|
122
96
|
divisor: 1,
|
|
123
97
|
bound: 1,
|
|
98
|
+
// Prerequisite: These are deep checks with special priority, e.g. the
|
|
99
|
+
// length of a tuple, which causes other deep props not to be checked if it
|
|
100
|
+
// is invalid
|
|
101
|
+
prerequisiteProp: 2,
|
|
124
102
|
// Deep: Performed if all shallow checks pass, even if one or more deep checks fail
|
|
125
|
-
|
|
126
|
-
|
|
103
|
+
requiredProp: 3,
|
|
104
|
+
optionalProp: 3,
|
|
105
|
+
indexProp: 3,
|
|
127
106
|
// Narrow: Only performed if all shallow and deep checks pass
|
|
128
|
-
narrow:
|
|
107
|
+
narrow: 4,
|
|
129
108
|
// Morph: Only performed if all validation passes
|
|
130
|
-
morph:
|
|
131
|
-
};
|
|
132
|
-
const flattenBranch = (branch, ctx)=>{
|
|
133
|
-
if ("morph" in branch) {
|
|
134
|
-
const result = flattenRules(branch.input, ctx);
|
|
135
|
-
result.push([
|
|
136
|
-
"morph",
|
|
137
|
-
branch.morph
|
|
138
|
-
]);
|
|
139
|
-
return result;
|
|
140
|
-
}
|
|
141
|
-
return flattenRules(branch, ctx);
|
|
142
|
-
};
|
|
143
|
-
const flattenRules = (rules, ctx)=>{
|
|
144
|
-
const entries = [];
|
|
145
|
-
let k;
|
|
146
|
-
for(k in rules){
|
|
147
|
-
ruleFlatteners[k](entries, rules[k], ctx);
|
|
148
|
-
}
|
|
149
|
-
return entries.sort((l, r)=>precedenceMap[l[0]] - precedenceMap[r[0]]);
|
|
109
|
+
morph: 5
|
|
150
110
|
};
|
|
151
111
|
const literalSatisfiesRules = (data, rules, state)=>!state.type.meta.scope.type([
|
|
152
112
|
"node",
|
|
@@ -14,7 +14,7 @@ _export(exports, {
|
|
|
14
14
|
unknownDefinitionMessage: ()=>unknownDefinitionMessage,
|
|
15
15
|
writeBadDefinitionTypeMessage: ()=>writeBadDefinitionTypeMessage
|
|
16
16
|
});
|
|
17
|
-
const
|
|
17
|
+
const _typeTs = require("../scopes/type.js");
|
|
18
18
|
const _domainsTs = require("../utils/domains.js");
|
|
19
19
|
const _errorsTs = require("../utils/errors.js");
|
|
20
20
|
const _objectKindsTs = require("../utils/objectKinds.js");
|
|
@@ -43,7 +43,7 @@ const parseDefinition = (def, ctx)=>{
|
|
|
43
43
|
}
|
|
44
44
|
};
|
|
45
45
|
case "Function":
|
|
46
|
-
return (0,
|
|
46
|
+
return (0, _typeTs.isType)(def) ? def.node : (0, _errorsTs.throwParseError)(writeBadDefinitionTypeMessage("Function"));
|
|
47
47
|
default:
|
|
48
48
|
return (0, _errorsTs.throwParseError)(writeBadDefinitionTypeMessage(objectKind ?? (0, _serializeTs.stringify)(def)));
|
|
49
49
|
}
|
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "DynamicState", {
|
|
|
6
6
|
enumerable: true,
|
|
7
7
|
get: ()=>DynamicState
|
|
8
8
|
});
|
|
9
|
-
const _functorsTs = require("../../../nodes/functors.js");
|
|
10
9
|
const _nodeTs = require("../../../nodes/node.js");
|
|
11
10
|
const _rangeTs = require("../../../nodes/rules/range.js");
|
|
12
11
|
const _errorsTs = require("../../../utils/errors.js");
|
|
@@ -60,7 +59,7 @@ class DynamicState {
|
|
|
60
59
|
this.root = node;
|
|
61
60
|
}
|
|
62
61
|
rootToArray() {
|
|
63
|
-
this.root =
|
|
62
|
+
this.root = (0, _nodeTs.arrayOf)(this.ejectRoot());
|
|
64
63
|
}
|
|
65
64
|
intersect(node) {
|
|
66
65
|
this.root = (0, _nodeTs.intersection)(this.ejectRoot(), node, this.ctx.type);
|
|
@@ -71,7 +71,7 @@ const distributeRange = (range, s)=>{
|
|
|
71
71
|
if (resolution.object === true) {
|
|
72
72
|
return false;
|
|
73
73
|
}
|
|
74
|
-
return (0, _genericsTs.listFrom)(resolution.object).every((branch)=>(0, _genericsTs.hasKey)(branch, "
|
|
74
|
+
return (0, _genericsTs.listFrom)(resolution.object).every((branch)=>(0, _genericsTs.hasKey)(branch, "class") && branch.class === "Array");
|
|
75
75
|
default:
|
|
76
76
|
return false;
|
|
77
77
|
}
|
|
@@ -13,7 +13,7 @@ _export(exports, {
|
|
|
13
13
|
maybeNaiveParse: ()=>maybeNaiveParse,
|
|
14
14
|
fullStringParse: ()=>fullStringParse
|
|
15
15
|
});
|
|
16
|
-
const
|
|
16
|
+
const _nodeTs = require("../../nodes/node.js");
|
|
17
17
|
const _dynamicTs = require("./reduce/dynamic.js");
|
|
18
18
|
const _operandTs = require("./shift/operand/operand.js");
|
|
19
19
|
const _operatorTs = require("./shift/operator/operator.js");
|
|
@@ -25,7 +25,7 @@ const maybeNaiveParse = (def, ctx)=>{
|
|
|
25
25
|
if (def.endsWith("[]")) {
|
|
26
26
|
const elementDef = def.slice(0, -2);
|
|
27
27
|
if (ctx.type.meta.scope.addReferenceIfResolvable(def, ctx)) {
|
|
28
|
-
return
|
|
28
|
+
return (0, _nodeTs.arrayOf)(elementDef);
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
};
|
|
@@ -7,10 +7,15 @@ Object.defineProperty(exports, "parseKeyOfTuple", {
|
|
|
7
7
|
get: ()=>parseKeyOfTuple
|
|
8
8
|
});
|
|
9
9
|
const _predicateTs = require("../../nodes/predicate.js");
|
|
10
|
+
const _propsTs = require("../../nodes/rules/props.js");
|
|
10
11
|
const _errorsTs = require("../../utils/errors.js");
|
|
11
12
|
const _genericsTs = require("../../utils/generics.js");
|
|
13
|
+
const _numericLiteralsTs = require("../../utils/numericLiterals.js");
|
|
12
14
|
const _definitionTs = require("../definition.js");
|
|
13
15
|
const _astTs = require("../string/ast.js");
|
|
16
|
+
const numericIndexKey = {
|
|
17
|
+
regex: _numericLiteralsTs.wellFormedNonNegativeIntegerMatcher.source
|
|
18
|
+
};
|
|
14
19
|
const parseKeyOfTuple = (def, ctx)=>{
|
|
15
20
|
const resolution = ctx.type.meta.scope.resolveNode((0, _definitionTs.parseDefinition)(def[1], ctx));
|
|
16
21
|
if (!(0, _predicateTs.resolutionExtendsDomain)(resolution, "object")) {
|
|
@@ -19,27 +24,41 @@ const parseKeyOfTuple = (def, ctx)=>{
|
|
|
19
24
|
if (resolution.object === true) {
|
|
20
25
|
return (0, _astTs.writeImplicitNeverMessage)(ctx.path, "keyof");
|
|
21
26
|
}
|
|
22
|
-
const branchKeys = [];
|
|
23
27
|
const objectBranches = (0, _genericsTs.listFrom)(resolution.object);
|
|
24
|
-
|
|
28
|
+
let sharedKeys = keysOfBranch(objectBranches[0]);
|
|
25
29
|
for(let i = 1; i < objectBranches.length; i++){
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
branchKeys.
|
|
30
|
+
const branchKeys = keysOfBranch(objectBranches[i]);
|
|
31
|
+
// we can filter directly by equality here because the RegExp we're
|
|
32
|
+
// using will always be reference equal to
|
|
33
|
+
// wellFormedNonNegativeIntegerMatcher
|
|
34
|
+
sharedKeys = sharedKeys.filter((k)=>branchKeys.includes(k));
|
|
31
35
|
}
|
|
32
|
-
const result =
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
value: key
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
});
|
|
36
|
+
const result = sharedKeys.map((k)=>typeof k === "string" ? {
|
|
37
|
+
value: k
|
|
38
|
+
} : {
|
|
39
|
+
regex: k.source
|
|
40
|
+
});
|
|
41
41
|
return result.length ? {
|
|
42
|
-
string: result
|
|
42
|
+
string: result.length === 1 ? result[0] : result
|
|
43
43
|
} : (0, _astTs.writeImplicitNeverMessage)(ctx.path, "keyof");
|
|
44
44
|
};
|
|
45
|
-
const
|
|
45
|
+
const keysOfBranch = (branch)=>{
|
|
46
|
+
if (!("props" in branch)) {
|
|
47
|
+
return [];
|
|
48
|
+
}
|
|
49
|
+
if (branch.class !== "Array") {
|
|
50
|
+
return Object.keys(branch.props);
|
|
51
|
+
}
|
|
52
|
+
const arrayProps = [];
|
|
53
|
+
for (const key of Object.keys(branch.props)){
|
|
54
|
+
if (key === "length") {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
if (key === _propsTs.mappedKeys.index) {
|
|
58
|
+
arrayProps.push(_numericLiteralsTs.wellFormedNonNegativeIntegerMatcher);
|
|
59
|
+
} else {
|
|
60
|
+
arrayProps.push(key);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return arrayProps;
|
|
64
|
+
};
|
|
@@ -12,6 +12,7 @@ _export(exports, {
|
|
|
12
12
|
parseMorphTuple: ()=>parseMorphTuple,
|
|
13
13
|
writeMalformedMorphExpressionMessage: ()=>writeMalformedMorphExpressionMessage
|
|
14
14
|
});
|
|
15
|
+
const _branchTs = require("../../nodes/branch.js");
|
|
15
16
|
const _errorsTs = require("../../utils/errors.js");
|
|
16
17
|
const _objectKindsTs = require("../../utils/objectKinds.js");
|
|
17
18
|
const _serializeTs = require("../../utils/serialize.js");
|
|
@@ -29,7 +30,7 @@ const parseMorphTuple = (def, ctx)=>{
|
|
|
29
30
|
const predicate = resolution[domain];
|
|
30
31
|
if (predicate === true) {
|
|
31
32
|
result[domain] = {
|
|
32
|
-
|
|
33
|
+
rules: {},
|
|
33
34
|
morph
|
|
34
35
|
};
|
|
35
36
|
} else if (typeof predicate === "object") {
|
|
@@ -40,17 +41,17 @@ const parseMorphTuple = (def, ctx)=>{
|
|
|
40
41
|
}
|
|
41
42
|
return result;
|
|
42
43
|
};
|
|
43
|
-
const applyMorph = (branch, morph)=>branch
|
|
44
|
-
|
|
45
|
-
morph: Array.isArray(branch.morph) ? [
|
|
44
|
+
const applyMorph = (branch, morph)=>(0, _branchTs.isMorphBranch)(branch) ? {
|
|
45
|
+
...branch,
|
|
46
|
+
morph: branch.morph ? Array.isArray(branch.morph) ? [
|
|
46
47
|
...branch.morph,
|
|
47
48
|
morph
|
|
48
49
|
] : [
|
|
49
50
|
branch.morph,
|
|
50
51
|
morph
|
|
51
|
-
]
|
|
52
|
+
] : morph
|
|
52
53
|
} : {
|
|
53
|
-
|
|
54
|
+
rules: branch,
|
|
54
55
|
morph
|
|
55
56
|
};
|
|
56
57
|
const writeMalformedMorphExpressionMessage = (value)=>`Morph expression requires a function following '=>' (was ${typeof value})`;
|
|
@@ -12,7 +12,6 @@ _export(exports, {
|
|
|
12
12
|
parseTuple: ()=>parseTuple,
|
|
13
13
|
writeMalformedFunctionalExpressionMessage: ()=>writeMalformedFunctionalExpressionMessage
|
|
14
14
|
});
|
|
15
|
-
const _functorsTs = require("../../nodes/functors.js");
|
|
16
15
|
const _nodeTs = require("../../nodes/node.js");
|
|
17
16
|
const _domainsTs = require("../../utils/domains.js");
|
|
18
17
|
const _errorsTs = require("../../utils/errors.js");
|
|
@@ -28,7 +27,19 @@ const parseTuple = (def, ctx)=>{
|
|
|
28
27
|
if (isPrefixExpression(def)) {
|
|
29
28
|
return prefixParsers[def[0]](def, ctx);
|
|
30
29
|
}
|
|
31
|
-
const props = {
|
|
30
|
+
const props = {
|
|
31
|
+
// length is created as a prerequisite prop, ensuring if it is invalid,
|
|
32
|
+
// no other props will be checked, which is usually desirable for tuple
|
|
33
|
+
// definitions.
|
|
34
|
+
length: [
|
|
35
|
+
"!",
|
|
36
|
+
{
|
|
37
|
+
number: {
|
|
38
|
+
value: def.length
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
]
|
|
42
|
+
};
|
|
32
43
|
for(let i = 0; i < def.length; i++){
|
|
33
44
|
ctx.path.push(`${i}`);
|
|
34
45
|
props[i] = (0, _definitionTs.parseDefinition)(def[i], ctx);
|
|
@@ -36,12 +47,8 @@ const parseTuple = (def, ctx)=>{
|
|
|
36
47
|
}
|
|
37
48
|
return {
|
|
38
49
|
object: {
|
|
39
|
-
|
|
40
|
-
props
|
|
41
|
-
range: {
|
|
42
|
-
comparator: "==",
|
|
43
|
-
limit: def.length
|
|
44
|
-
}
|
|
50
|
+
class: "Array",
|
|
51
|
+
props
|
|
45
52
|
}
|
|
46
53
|
};
|
|
47
54
|
};
|
|
@@ -53,7 +60,7 @@ const parseBranchTuple = (def, ctx)=>{
|
|
|
53
60
|
const r = (0, _definitionTs.parseDefinition)(def[2], ctx);
|
|
54
61
|
return def[1] === "&" ? (0, _nodeTs.intersection)(l, r, ctx.type) : (0, _nodeTs.union)(l, r, ctx.type);
|
|
55
62
|
};
|
|
56
|
-
const parseArrayTuple = (def, scope)=>
|
|
63
|
+
const parseArrayTuple = (def, scope)=>(0, _nodeTs.arrayOf)((0, _definitionTs.parseDefinition)(def[0], scope));
|
|
57
64
|
const writeMalformedFunctionalExpressionMessage = (operator, rightDef)=>`Expression requires a function following '${operator}' (was ${typeof rightDef})`;
|
|
58
65
|
const isPostfixExpression = (def)=>postfixParsers[def[1]] !== undefined;
|
|
59
66
|
const postfixParsers = {
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
Cache: ()=>Cache,
|
|
13
|
+
FreezingCache: ()=>FreezingCache
|
|
14
|
+
});
|
|
15
|
+
const _freezeTs = require("../utils/freeze.js");
|
|
16
|
+
class Cache {
|
|
17
|
+
get root() {
|
|
18
|
+
return this.cache;
|
|
19
|
+
}
|
|
20
|
+
has(name) {
|
|
21
|
+
return name in this.cache;
|
|
22
|
+
}
|
|
23
|
+
get(name) {
|
|
24
|
+
return this.cache[name];
|
|
25
|
+
}
|
|
26
|
+
set(name, item) {
|
|
27
|
+
this.cache[name] = item;
|
|
28
|
+
return item;
|
|
29
|
+
}
|
|
30
|
+
constructor(){
|
|
31
|
+
this.cache = {};
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
class FreezingCache extends Cache {
|
|
35
|
+
set(name, item) {
|
|
36
|
+
this.cache[name] = (0, _freezeTs.deepFreeze)(item);
|
|
37
|
+
return item;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
function _export(target, all) {
|
|
6
|
+
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: all[name]
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
_export(exports, {
|
|
12
|
+
jsObjectsScope: ()=>jsObjectsScope,
|
|
13
|
+
jsObjects: ()=>jsObjects
|
|
14
|
+
});
|
|
15
|
+
const _scopeTs = require("./scope.js");
|
|
16
|
+
const jsObjectsScope = (0, _scopeTs.scope)({
|
|
17
|
+
Function: [
|
|
18
|
+
"node",
|
|
19
|
+
{
|
|
20
|
+
object: {
|
|
21
|
+
class: "Function"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
],
|
|
25
|
+
Array: [
|
|
26
|
+
"node",
|
|
27
|
+
{
|
|
28
|
+
object: {
|
|
29
|
+
class: "Array"
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
],
|
|
33
|
+
Date: [
|
|
34
|
+
"node",
|
|
35
|
+
{
|
|
36
|
+
object: {
|
|
37
|
+
class: "Date"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
],
|
|
41
|
+
Error: [
|
|
42
|
+
"node",
|
|
43
|
+
{
|
|
44
|
+
object: {
|
|
45
|
+
class: "Error"
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
Map: [
|
|
50
|
+
"node",
|
|
51
|
+
{
|
|
52
|
+
object: {
|
|
53
|
+
class: "Map"
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
],
|
|
57
|
+
RegExp: [
|
|
58
|
+
"node",
|
|
59
|
+
{
|
|
60
|
+
object: {
|
|
61
|
+
class: "RegExp"
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
],
|
|
65
|
+
Set: [
|
|
66
|
+
"node",
|
|
67
|
+
{
|
|
68
|
+
object: {
|
|
69
|
+
class: "Set"
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
],
|
|
73
|
+
Object: [
|
|
74
|
+
"node",
|
|
75
|
+
{
|
|
76
|
+
object: {
|
|
77
|
+
class: "Object"
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
],
|
|
81
|
+
String: [
|
|
82
|
+
"node",
|
|
83
|
+
{
|
|
84
|
+
object: {
|
|
85
|
+
class: "String"
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
],
|
|
89
|
+
Number: [
|
|
90
|
+
"node",
|
|
91
|
+
{
|
|
92
|
+
object: {
|
|
93
|
+
class: "Number"
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
],
|
|
97
|
+
Boolean: [
|
|
98
|
+
"node",
|
|
99
|
+
{
|
|
100
|
+
object: {
|
|
101
|
+
class: "Boolean"
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
],
|
|
105
|
+
WeakMap: [
|
|
106
|
+
"node",
|
|
107
|
+
{
|
|
108
|
+
object: {
|
|
109
|
+
class: "WeakMap"
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
],
|
|
113
|
+
WeakSet: [
|
|
114
|
+
"node",
|
|
115
|
+
{
|
|
116
|
+
object: {
|
|
117
|
+
class: "WeakSet"
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
],
|
|
121
|
+
Promise: [
|
|
122
|
+
"node",
|
|
123
|
+
{
|
|
124
|
+
object: {
|
|
125
|
+
class: "Promise"
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
]
|
|
129
|
+
}, {
|
|
130
|
+
name: "jsObjects",
|
|
131
|
+
standard: false
|
|
132
|
+
});
|
|
133
|
+
const jsObjects = jsObjectsScope.compile();
|