arktype 1.0.9-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 +53 -39
- package/dist/cjs/main.js +26 -18
- 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 -5
- 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 +5 -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 +4 -41
- package/dist/mjs/scopes/scope.js +30 -2
- package/dist/mjs/scopes/tsKeywords.js +18 -1
- package/dist/mjs/scopes/type.js +1 -0
- package/dist/mjs/scopes/validation/validation.js +19 -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 +8 -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 -4
- 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 +4 -10
- package/dist/types/scopes/tsKeywords.d.ts +18 -0
- package/dist/types/scopes/type.d.ts +4 -2
- package/dist/types/scopes/validation/validation.d.ts +19 -0
- package/dist/types/utils/generics.d.ts +2 -2
- package/package.json +17 -18
|
@@ -15,25 +15,25 @@ _export(exports, {
|
|
|
15
15
|
flattenPredicate: ()=>flattenPredicate,
|
|
16
16
|
isLiteralCondition: ()=>isLiteralCondition
|
|
17
17
|
});
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
18
|
+
const _genericsJs = require("../utils/generics.js");
|
|
19
|
+
const _objectKindsJs = require("../utils/objectKinds.js");
|
|
20
|
+
const _branchJs = require("./branch.js");
|
|
21
|
+
const _composeJs = require("./compose.js");
|
|
22
|
+
const _discriminateJs = require("./discriminate.js");
|
|
23
23
|
const emptyRulesIfTrue = (predicate)=>predicate === true ? {} : predicate;
|
|
24
24
|
const comparePredicates = (l, r, context)=>{
|
|
25
25
|
if (l === true && r === true) {
|
|
26
|
-
return (0,
|
|
26
|
+
return (0, _composeJs.equality)();
|
|
27
27
|
}
|
|
28
|
-
if (!(0,
|
|
29
|
-
const result = (0,
|
|
28
|
+
if (!(0, _objectKindsJs.isArray)(l) && !(0, _objectKindsJs.isArray)(r)) {
|
|
29
|
+
const result = (0, _branchJs.branchIntersection)(emptyRulesIfTrue(l), emptyRulesIfTrue(r), context);
|
|
30
30
|
return result === l ? l : result === r ? r : result;
|
|
31
31
|
}
|
|
32
|
-
const lBranches = (0,
|
|
33
|
-
const rBranches = (0,
|
|
34
|
-
const comparison = (0,
|
|
32
|
+
const lBranches = (0, _genericsJs.listFrom)(emptyRulesIfTrue(l));
|
|
33
|
+
const rBranches = (0, _genericsJs.listFrom)(emptyRulesIfTrue(r));
|
|
34
|
+
const comparison = (0, _branchJs.compareBranches)(lBranches, rBranches, context);
|
|
35
35
|
if (comparison.equalities.length === lBranches.length && comparison.equalities.length === rBranches.length) {
|
|
36
|
-
return (0,
|
|
36
|
+
return (0, _composeJs.equality)();
|
|
37
37
|
}
|
|
38
38
|
if (comparison.lExtendsR.length + comparison.equalities.length === lBranches.length) {
|
|
39
39
|
return l;
|
|
@@ -46,7 +46,7 @@ const comparePredicates = (l, r, context)=>{
|
|
|
46
46
|
const predicateIntersection = (domain, l, r, state)=>{
|
|
47
47
|
state.domain = domain;
|
|
48
48
|
const comparison = comparePredicates(l, r, state);
|
|
49
|
-
if (!(0,
|
|
49
|
+
if (!(0, _branchJs.isBranchComparison)(comparison)) {
|
|
50
50
|
return comparison;
|
|
51
51
|
}
|
|
52
52
|
const resultBranches = [
|
|
@@ -61,10 +61,10 @@ const predicateIntersection = (domain, l, r, state)=>{
|
|
|
61
61
|
return resultBranches.length === 1 ? resultBranches[0] : resultBranches;
|
|
62
62
|
};
|
|
63
63
|
const predicateUnion = (domain, l, r, type)=>{
|
|
64
|
-
const state = new
|
|
64
|
+
const state = new _composeJs.IntersectionState(type, "|");
|
|
65
65
|
const comparison = comparePredicates(l, r, state);
|
|
66
|
-
if (!(0,
|
|
67
|
-
return (0,
|
|
66
|
+
if (!(0, _branchJs.isBranchComparison)(comparison)) {
|
|
67
|
+
return (0, _composeJs.isEquality)(comparison) || comparison === l ? r : comparison === r ? l : // subtype of the other, it consists of two opposite literals
|
|
68
68
|
// and can be simplified to a non-literal boolean.
|
|
69
69
|
domain === "boolean" ? true : [
|
|
70
70
|
emptyRulesIfTrue(l),
|
|
@@ -81,6 +81,6 @@ const flattenPredicate = (predicate, context)=>{
|
|
|
81
81
|
if (predicate === true) {
|
|
82
82
|
return [];
|
|
83
83
|
}
|
|
84
|
-
return (0,
|
|
84
|
+
return (0, _objectKindsJs.isArray)(predicate) ? (0, _discriminateJs.flattenBranches)(predicate, context) : (0, _branchJs.flattenBranch)(predicate, context);
|
|
85
85
|
};
|
|
86
86
|
const isLiteralCondition = (predicate)=>typeof predicate === "object" && "value" in predicate;
|
|
@@ -12,14 +12,14 @@ _export(exports, {
|
|
|
12
12
|
classIntersection: ()=>classIntersection,
|
|
13
13
|
checkClass: ()=>checkClass
|
|
14
14
|
});
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const classIntersection = (0,
|
|
18
|
-
return l === r ? (0,
|
|
15
|
+
const _objectKindsJs = require("../../utils/objectKinds.js");
|
|
16
|
+
const _composeJs = require("../compose.js");
|
|
17
|
+
const classIntersection = (0, _composeJs.composeIntersection)((l, r, state)=>{
|
|
18
|
+
return l === r ? (0, _composeJs.equality)() : l instanceof r ? l : r instanceof l ? r : state.addDisjoint("class", l, r);
|
|
19
19
|
});
|
|
20
20
|
const checkClass = (expectedClass, state)=>{
|
|
21
21
|
if (typeof expectedClass === "string") {
|
|
22
|
-
return (0,
|
|
22
|
+
return (0, _objectKindsJs.objectKindOf)(state.data) === expectedClass || !state.problems.add("class", expectedClass);
|
|
23
23
|
}
|
|
24
24
|
return state.data instanceof expectedClass || !state.problems.add("class", expectedClass);
|
|
25
25
|
};
|
|
@@ -12,12 +12,12 @@ _export(exports, {
|
|
|
12
12
|
collapsibleListUnion: ()=>collapsibleListUnion,
|
|
13
13
|
listUnion: ()=>listUnion
|
|
14
14
|
});
|
|
15
|
-
const
|
|
15
|
+
const _composeJs = require("../compose.js");
|
|
16
16
|
const collapsibleListUnion = (l, r)=>{
|
|
17
17
|
if (Array.isArray(l)) {
|
|
18
18
|
if (Array.isArray(r)) {
|
|
19
19
|
const result = listUnion(l, r);
|
|
20
|
-
return result.length === l.length ? result.length === r.length ? (0,
|
|
20
|
+
return result.length === l.length ? result.length === r.length ? (0, _composeJs.equality)() : l : result.length === r.length ? r : result;
|
|
21
21
|
}
|
|
22
22
|
return l.includes(r) ? l : [
|
|
23
23
|
...l,
|
|
@@ -30,7 +30,7 @@ const collapsibleListUnion = (l, r)=>{
|
|
|
30
30
|
l
|
|
31
31
|
];
|
|
32
32
|
}
|
|
33
|
-
return l === r ? (0,
|
|
33
|
+
return l === r ? (0, _composeJs.equality)() : [
|
|
34
34
|
l,
|
|
35
35
|
r
|
|
36
36
|
];
|
|
@@ -12,8 +12,8 @@ _export(exports, {
|
|
|
12
12
|
divisorIntersection: ()=>divisorIntersection,
|
|
13
13
|
checkDivisor: ()=>checkDivisor
|
|
14
14
|
});
|
|
15
|
-
const
|
|
16
|
-
const divisorIntersection = (0,
|
|
15
|
+
const _composeJs = require("../compose.js");
|
|
16
|
+
const divisorIntersection = (0, _composeJs.composeIntersection)((l, r)=>l === r ? (0, _composeJs.equality)() : Math.abs(l * r / greatestCommonDivisor(l, r)));
|
|
17
17
|
// https://en.wikipedia.org/wiki/Euclidean_algorithm
|
|
18
18
|
const greatestCommonDivisor = (l, r)=>{
|
|
19
19
|
let previous;
|
|
@@ -16,8 +16,8 @@ _export(exports, {
|
|
|
16
16
|
propsIntersection: ()=>propsIntersection,
|
|
17
17
|
flattenProps: ()=>flattenProps
|
|
18
18
|
});
|
|
19
|
-
const
|
|
20
|
-
const
|
|
19
|
+
const _composeJs = require("../compose.js");
|
|
20
|
+
const _nodeJs = require("../node.js");
|
|
21
21
|
const isOptional = (prop)=>prop[0] === "?";
|
|
22
22
|
const isPrerequisite = (prop)=>prop[0] === "!";
|
|
23
23
|
const mappedKeys = {
|
|
@@ -25,11 +25,11 @@ const mappedKeys = {
|
|
|
25
25
|
};
|
|
26
26
|
const propToNode = (prop)=>isOptional(prop) || isPrerequisite(prop) ? prop[1] : prop;
|
|
27
27
|
const getTupleLengthIfPresent = (result)=>{
|
|
28
|
-
if (typeof result.length === "object" && isPrerequisite(result.length) && typeof result.length[1] !== "string" && (0,
|
|
28
|
+
if (typeof result.length === "object" && isPrerequisite(result.length) && typeof result.length[1] !== "string" && (0, _nodeJs.isLiteralNode)(result.length[1], "number")) {
|
|
29
29
|
return result.length[1].number.value;
|
|
30
30
|
}
|
|
31
31
|
};
|
|
32
|
-
const propsIntersection = (0,
|
|
32
|
+
const propsIntersection = (0, _composeJs.composeIntersection)((l, r, state)=>{
|
|
33
33
|
const result = propKeysIntersection(l, r, state);
|
|
34
34
|
if (typeof result === "symbol") {
|
|
35
35
|
return result;
|
|
@@ -51,28 +51,28 @@ const propsIntersection = (0, _composeTs.composeIntersection)((l, r, state)=>{
|
|
|
51
51
|
}
|
|
52
52
|
const existingNodeAtIndex = propToNode(updatedResult[i]);
|
|
53
53
|
state.path.push(`${i}`);
|
|
54
|
-
const updatedResultAtIndex = (0,
|
|
54
|
+
const updatedResultAtIndex = (0, _nodeJs.nodeIntersection)(existingNodeAtIndex, indexNode, state);
|
|
55
55
|
state.path.pop();
|
|
56
|
-
if ((0,
|
|
56
|
+
if ((0, _composeJs.isDisjoint)(updatedResultAtIndex)) {
|
|
57
57
|
return updatedResultAtIndex;
|
|
58
|
-
} else if (!(0,
|
|
58
|
+
} else if (!(0, _composeJs.isEquality)(updatedResultAtIndex) && updatedResultAtIndex !== existingNodeAtIndex) {
|
|
59
59
|
updatedResult[i] = updatedResultAtIndex;
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
return updatedResult;
|
|
63
63
|
});
|
|
64
|
-
const propKeysIntersection = (0,
|
|
64
|
+
const propKeysIntersection = (0, _composeJs.composeKeyedIntersection)((propKey, l, r, context)=>{
|
|
65
65
|
if (l === undefined) {
|
|
66
|
-
return r === undefined ? (0,
|
|
66
|
+
return r === undefined ? (0, _composeJs.equality)() : r;
|
|
67
67
|
}
|
|
68
68
|
if (r === undefined) {
|
|
69
69
|
return l;
|
|
70
70
|
}
|
|
71
71
|
context.path.push(propKey);
|
|
72
|
-
const result = (0,
|
|
72
|
+
const result = (0, _nodeJs.nodeIntersection)(propToNode(l), propToNode(r), context);
|
|
73
73
|
context.path.pop();
|
|
74
74
|
const resultIsOptional = isOptional(l) && isOptional(r);
|
|
75
|
-
if ((0,
|
|
75
|
+
if ((0, _composeJs.isDisjoint)(result) && resultIsOptional) {
|
|
76
76
|
// If an optional key has an empty intersection, the type can
|
|
77
77
|
// still be satisfied as long as the key is not included. Set
|
|
78
78
|
// the node to never rather than invalidating the type.
|
|
@@ -94,14 +94,14 @@ const flattenLooseProps = (entries, props, ctx)=>{
|
|
|
94
94
|
if (k === mappedKeys.index) {
|
|
95
95
|
entries.push([
|
|
96
96
|
"indexProp",
|
|
97
|
-
(0,
|
|
97
|
+
(0, _nodeJs.flattenNode)(propToNode(prop), ctx)
|
|
98
98
|
]);
|
|
99
99
|
} else if (isOptional(prop)) {
|
|
100
100
|
entries.push([
|
|
101
101
|
"optionalProp",
|
|
102
102
|
[
|
|
103
103
|
k,
|
|
104
|
-
(0,
|
|
104
|
+
(0, _nodeJs.flattenNode)(prop[1], ctx)
|
|
105
105
|
]
|
|
106
106
|
]);
|
|
107
107
|
} else if (isPrerequisite(prop)) {
|
|
@@ -109,7 +109,7 @@ const flattenLooseProps = (entries, props, ctx)=>{
|
|
|
109
109
|
"prerequisiteProp",
|
|
110
110
|
[
|
|
111
111
|
k,
|
|
112
|
-
(0,
|
|
112
|
+
(0, _nodeJs.flattenNode)(prop[1], ctx)
|
|
113
113
|
]
|
|
114
114
|
]);
|
|
115
115
|
} else {
|
|
@@ -117,7 +117,7 @@ const flattenLooseProps = (entries, props, ctx)=>{
|
|
|
117
117
|
"requiredProp",
|
|
118
118
|
[
|
|
119
119
|
k,
|
|
120
|
-
(0,
|
|
120
|
+
(0, _nodeJs.flattenNode)(prop, ctx)
|
|
121
121
|
]
|
|
122
122
|
]);
|
|
123
123
|
}
|
|
@@ -136,20 +136,20 @@ const flattenPropsRecord = (kind, entries, props, ctx)=>{
|
|
|
136
136
|
const prop = props[k];
|
|
137
137
|
ctx.path.push(k);
|
|
138
138
|
if (k === mappedKeys.index) {
|
|
139
|
-
result.index = (0,
|
|
139
|
+
result.index = (0, _nodeJs.flattenNode)(propToNode(prop), ctx);
|
|
140
140
|
} else if (isOptional(prop)) {
|
|
141
|
-
result.optional[k] = (0,
|
|
141
|
+
result.optional[k] = (0, _nodeJs.flattenNode)(prop[1], ctx);
|
|
142
142
|
} else if (isPrerequisite(prop)) {
|
|
143
143
|
// we still have to push prerequisite props as normal entries so they can be checked first
|
|
144
144
|
entries.push([
|
|
145
145
|
"prerequisiteProp",
|
|
146
146
|
[
|
|
147
147
|
k,
|
|
148
|
-
(0,
|
|
148
|
+
(0, _nodeJs.flattenNode)(prop[1], ctx)
|
|
149
149
|
]
|
|
150
150
|
]);
|
|
151
151
|
} else {
|
|
152
|
-
result.required[k] = (0,
|
|
152
|
+
result.required[k] = (0, _nodeJs.flattenNode)(prop, ctx);
|
|
153
153
|
}
|
|
154
154
|
ctx.path.pop();
|
|
155
155
|
}
|
|
@@ -17,8 +17,8 @@ _export(exports, {
|
|
|
17
17
|
checkBound: ()=>checkBound,
|
|
18
18
|
compareStrictness: ()=>compareStrictness
|
|
19
19
|
});
|
|
20
|
-
const
|
|
21
|
-
const
|
|
20
|
+
const _dataJs = require("../../utils/data.js");
|
|
21
|
+
const _composeJs = require("../compose.js");
|
|
22
22
|
const minComparators = {
|
|
23
23
|
">": true,
|
|
24
24
|
">=": true
|
|
@@ -28,10 +28,10 @@ const maxComparators = {
|
|
|
28
28
|
"<=": true
|
|
29
29
|
};
|
|
30
30
|
const isEqualityRange = (range)=>"comparator" in range;
|
|
31
|
-
const rangeIntersection = (0,
|
|
31
|
+
const rangeIntersection = (0, _composeJs.composeIntersection)((l, r, state)=>{
|
|
32
32
|
if (isEqualityRange(l)) {
|
|
33
33
|
if (isEqualityRange(r)) {
|
|
34
|
-
return l.limit === r.limit ? (0,
|
|
34
|
+
return l.limit === r.limit ? (0, _composeJs.equality)() : state.addDisjoint("range", l, r);
|
|
35
35
|
}
|
|
36
36
|
return rangeAllows(r, l.limit) ? l : state.addDisjoint("range", l, r);
|
|
37
37
|
}
|
|
@@ -58,7 +58,7 @@ const rangeIntersection = (0, _composeTs.composeIntersection)((l, r, state)=>{
|
|
|
58
58
|
}
|
|
59
59
|
return r;
|
|
60
60
|
}
|
|
61
|
-
return stricterMax === "l" ? l : stricterMax === "r" ? r : (0,
|
|
61
|
+
return stricterMax === "l" ? l : stricterMax === "r" ? r : (0, _composeJs.equality)();
|
|
62
62
|
});
|
|
63
63
|
const rangeAllows = (range, n)=>isEqualityRange(range) ? n === range.limit : minAllows(range.min, n) && maxAllows(range.max, n);
|
|
64
64
|
const minAllows = (min, n)=>!min || n > min.limit || n === min.limit && !isExclusive(min.comparator);
|
|
@@ -93,7 +93,7 @@ const flattenRange = (entries, range, ctx)=>{
|
|
|
93
93
|
]);
|
|
94
94
|
}
|
|
95
95
|
};
|
|
96
|
-
const checkBound = (bound, state)=>comparatorCheckers[bound.comparator]((0,
|
|
96
|
+
const checkBound = (bound, state)=>comparatorCheckers[bound.comparator]((0, _dataJs.sizeOf)(state.data), bound.limit) || !state.problems.add("bound", bound);
|
|
97
97
|
const comparatorCheckers = {
|
|
98
98
|
"<": (size, limit)=>size < limit,
|
|
99
99
|
">": (size, limit)=>size > limit,
|
|
@@ -13,8 +13,8 @@ _export(exports, {
|
|
|
13
13
|
checkRegex: ()=>checkRegex,
|
|
14
14
|
regexIntersection: ()=>regexIntersection
|
|
15
15
|
});
|
|
16
|
-
const
|
|
17
|
-
const
|
|
16
|
+
const _composeJs = require("../compose.js");
|
|
17
|
+
const _collapsibleSetJs = require("./collapsibleSet.js");
|
|
18
18
|
const regexCache = {};
|
|
19
19
|
const getRegex = (source)=>{
|
|
20
20
|
if (!regexCache[source]) {
|
|
@@ -23,4 +23,4 @@ const getRegex = (source)=>{
|
|
|
23
23
|
return regexCache[source];
|
|
24
24
|
};
|
|
25
25
|
const checkRegex = (source, state)=>getRegex(source).test(state.data) || !state.problems.add("regex", `/${source}/`);
|
|
26
|
-
const regexIntersection = (0,
|
|
26
|
+
const regexIntersection = (0, _composeJs.composeIntersection)(_collapsibleSetJs.collapsibleListUnion);
|
|
@@ -15,22 +15,22 @@ _export(exports, {
|
|
|
15
15
|
precedenceMap: ()=>precedenceMap,
|
|
16
16
|
literalSatisfiesRules: ()=>literalSatisfiesRules
|
|
17
17
|
});
|
|
18
|
-
const
|
|
19
|
-
const
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
const
|
|
26
|
-
const rulesIntersection = (l, r, state)=>"value" in l ? "value" in r ? l.value === r.value ? (0,
|
|
27
|
-
const narrowIntersection = (0,
|
|
28
|
-
const narrowableRulesIntersection = (0,
|
|
29
|
-
divisor:
|
|
30
|
-
regex:
|
|
31
|
-
props:
|
|
32
|
-
class:
|
|
33
|
-
range:
|
|
18
|
+
const _genericsJs = require("../../utils/generics.js");
|
|
19
|
+
const _composeJs = require("../compose.js");
|
|
20
|
+
const _classJs = require("./class.js");
|
|
21
|
+
const _collapsibleSetJs = require("./collapsibleSet.js");
|
|
22
|
+
const _divisorJs = require("./divisor.js");
|
|
23
|
+
const _propsJs = require("./props.js");
|
|
24
|
+
const _rangeJs = require("./range.js");
|
|
25
|
+
const _regexJs = require("./regex.js");
|
|
26
|
+
const rulesIntersection = (l, r, state)=>"value" in l ? "value" in r ? l.value === r.value ? (0, _composeJs.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);
|
|
27
|
+
const narrowIntersection = (0, _composeJs.composeIntersection)(_collapsibleSetJs.collapsibleListUnion);
|
|
28
|
+
const narrowableRulesIntersection = (0, _composeJs.composeKeyedIntersection)({
|
|
29
|
+
divisor: _divisorJs.divisorIntersection,
|
|
30
|
+
regex: _regexJs.regexIntersection,
|
|
31
|
+
props: _propsJs.propsIntersection,
|
|
32
|
+
class: _classJs.classIntersection,
|
|
33
|
+
range: _rangeJs.rangeIntersection,
|
|
34
34
|
narrow: narrowIntersection
|
|
35
35
|
}, {
|
|
36
36
|
onEmpty: "bubble"
|
|
@@ -49,7 +49,7 @@ const flattenRules = (rules, ctx)=>{
|
|
|
49
49
|
};
|
|
50
50
|
const ruleFlatteners = {
|
|
51
51
|
regex: (entries, rule)=>{
|
|
52
|
-
for (const source of (0,
|
|
52
|
+
for (const source of (0, _genericsJs.listFrom)(rule)){
|
|
53
53
|
entries.push([
|
|
54
54
|
"regex",
|
|
55
55
|
source
|
|
@@ -62,16 +62,16 @@ const ruleFlatteners = {
|
|
|
62
62
|
rule
|
|
63
63
|
]);
|
|
64
64
|
},
|
|
65
|
-
range:
|
|
65
|
+
range: _rangeJs.flattenRange,
|
|
66
66
|
class: (entries, rule)=>{
|
|
67
67
|
entries.push([
|
|
68
68
|
"class",
|
|
69
69
|
rule
|
|
70
70
|
]);
|
|
71
71
|
},
|
|
72
|
-
props:
|
|
72
|
+
props: _propsJs.flattenProps,
|
|
73
73
|
narrow: (entries, rule)=>{
|
|
74
|
-
for (const narrow of (0,
|
|
74
|
+
for (const narrow of (0, _genericsJs.listFrom)(rule)){
|
|
75
75
|
entries.push([
|
|
76
76
|
"narrow",
|
|
77
77
|
narrow
|
|
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "parseConfigTuple", {
|
|
|
6
6
|
enumerable: true,
|
|
7
7
|
get: ()=>parseConfigTuple
|
|
8
8
|
});
|
|
9
|
-
const
|
|
9
|
+
const _definitionJs = require("../definition.js");
|
|
10
10
|
const parseConfigTuple = (def, ctx)=>({
|
|
11
|
-
node: ctx.type.scope.resolveTypeNode((0,
|
|
11
|
+
node: ctx.type.scope.resolveTypeNode((0, _definitionJs.parseDefinition)(def[0], ctx)),
|
|
12
12
|
config: def[2]
|
|
13
13
|
});
|
|
@@ -12,15 +12,15 @@ _export(exports, {
|
|
|
12
12
|
writeMalformedDistributableFunctionMessage: ()=>writeMalformedDistributableFunctionMessage,
|
|
13
13
|
distributeFunctionToNode: ()=>distributeFunctionToNode
|
|
14
14
|
});
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const writeMalformedDistributableFunctionMessage = (def)=>`Expected a Function or Record<Domain, Function> operand (${(0,
|
|
15
|
+
const _domainsJs = require("../../utils/domains.js");
|
|
16
|
+
const _errorsJs = require("../../utils/errors.js");
|
|
17
|
+
const _genericsJs = require("../../utils/generics.js");
|
|
18
|
+
const _serializeJs = require("../../utils/serialize.js");
|
|
19
|
+
const writeMalformedDistributableFunctionMessage = (def)=>`Expected a Function or Record<Domain, Function> operand (${(0, _serializeJs.stringify)(def)} was invalid)`;
|
|
20
20
|
const distributeFunctionToNode = (distributableFunction, node, ctx, ruleKey)=>{
|
|
21
|
-
const domains = (0,
|
|
22
|
-
if (!(0,
|
|
23
|
-
return (0,
|
|
21
|
+
const domains = (0, _genericsJs.objectKeysOf)(node);
|
|
22
|
+
if (!(0, _domainsJs.hasDomain)(distributableFunction, "object")) {
|
|
23
|
+
return (0, _errorsJs.throwParseError)(writeMalformedDistributableFunctionMessage(distributableFunction));
|
|
24
24
|
}
|
|
25
25
|
const distributed = {};
|
|
26
26
|
if (typeof distributableFunction === "function") {
|
|
@@ -39,7 +39,7 @@ const distributeFunctionToNode = (distributableFunction, node, ctx, ruleKey)=>{
|
|
|
39
39
|
[ruleKey]: distributableFunction[domain]
|
|
40
40
|
};
|
|
41
41
|
if (typeof functionInDomain[ruleKey] !== "function") {
|
|
42
|
-
return (0,
|
|
42
|
+
return (0, _errorsJs.throwParseError)(writeMalformedDistributableFunctionMessage(functionInDomain));
|
|
43
43
|
}
|
|
44
44
|
distributed[domain] = functionInDomain;
|
|
45
45
|
}
|
|
@@ -12,18 +12,18 @@ _export(exports, {
|
|
|
12
12
|
compileDisjointReasonsMessage: ()=>compileDisjointReasonsMessage,
|
|
13
13
|
writeImplicitNeverMessage: ()=>writeImplicitNeverMessage
|
|
14
14
|
});
|
|
15
|
-
const
|
|
16
|
-
const
|
|
15
|
+
const _composeJs = require("../../nodes/compose.js");
|
|
16
|
+
const _genericsJs = require("../../utils/generics.js");
|
|
17
17
|
const compileDisjointReasonsMessage = (disjoints)=>{
|
|
18
|
-
const paths = (0,
|
|
18
|
+
const paths = (0, _genericsJs.objectKeysOf)(disjoints);
|
|
19
19
|
if (paths.length === 1) {
|
|
20
20
|
const path = paths[0];
|
|
21
|
-
return `${path === "/" ? "" : `At ${path}: `}Intersection of ${
|
|
21
|
+
return `${path === "/" ? "" : `At ${path}: `}Intersection of ${_composeJs.disjointDescriptionWriters[disjoints[path].kind](disjoints[path])} results in an unsatisfiable type`;
|
|
22
22
|
}
|
|
23
23
|
let message = `
|
|
24
24
|
"Intersection results in unsatisfiable types at the following paths:\n`;
|
|
25
25
|
for(const path in disjoints){
|
|
26
|
-
message += ` ${path}: ${
|
|
26
|
+
message += ` ${path}: ${_composeJs.disjointDescriptionWriters[disjoints[path].kind](disjoints[path])}\n`;
|
|
27
27
|
}
|
|
28
28
|
return message;
|
|
29
29
|
};
|
|
@@ -6,20 +6,19 @@ Object.defineProperty(exports, "parseKeyOfTuple", {
|
|
|
6
6
|
enumerable: true,
|
|
7
7
|
get: ()=>parseKeyOfTuple
|
|
8
8
|
});
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
const
|
|
14
|
-
const
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
regex: _numericLiteralsTs.wellFormedNonNegativeIntegerMatcher.source
|
|
9
|
+
const _propsJs = require("../../nodes/rules/props.js");
|
|
10
|
+
const _errorsJs = require("../../utils/errors.js");
|
|
11
|
+
const _freezeJs = require("../../utils/freeze.js");
|
|
12
|
+
const _genericsJs = require("../../utils/generics.js");
|
|
13
|
+
const _numericLiteralsJs = require("../../utils/numericLiterals.js");
|
|
14
|
+
const _objectKindsJs = require("../../utils/objectKinds.js");
|
|
15
|
+
const _serializeJs = require("../../utils/serialize.js");
|
|
16
|
+
const _definitionJs = require("../definition.js");
|
|
17
|
+
const _intersectionJs = require("./intersection.js");
|
|
18
|
+
const arrayIndexStringBranch = (0, _freezeJs.deepFreeze)({
|
|
19
|
+
regex: _numericLiteralsJs.wellFormedNonNegativeIntegerMatcher.source
|
|
21
20
|
});
|
|
22
|
-
const arrayIndexNumberBranch = (0,
|
|
21
|
+
const arrayIndexNumberBranch = (0, _freezeJs.deepFreeze)({
|
|
23
22
|
range: {
|
|
24
23
|
min: {
|
|
25
24
|
comparator: ">=",
|
|
@@ -29,27 +28,29 @@ const arrayIndexNumberBranch = (0, _freezeTs.deepFreeze)({
|
|
|
29
28
|
divisor: 1
|
|
30
29
|
});
|
|
31
30
|
const parseKeyOfTuple = (def, ctx)=>{
|
|
32
|
-
const resolution = ctx.type.scope.resolveNode((0,
|
|
33
|
-
const predicateKeys = (0,
|
|
31
|
+
const resolution = ctx.type.scope.resolveNode((0, _definitionJs.parseDefinition)(def[1], ctx));
|
|
32
|
+
const predicateKeys = (0, _genericsJs.objectKeysOf)(resolution).map((domain)=>keysOfPredicate(domain, resolution[domain]));
|
|
34
33
|
const sharedKeys = sharedKeysOf(predicateKeys);
|
|
35
34
|
if (!sharedKeys.length) {
|
|
36
|
-
return (0,
|
|
35
|
+
return (0, _intersectionJs.writeImplicitNeverMessage)(ctx.path, "keyof");
|
|
37
36
|
}
|
|
38
37
|
const keyNode = {};
|
|
39
38
|
for (const key of sharedKeys){
|
|
40
39
|
const keyType = typeof key;
|
|
41
40
|
if (keyType === "string" || keyType === "number" || keyType === "symbol") {
|
|
41
|
+
var _keyNode, _keyType;
|
|
42
42
|
(_keyNode = keyNode)[_keyType = keyType] ?? (_keyNode[_keyType] = []);
|
|
43
43
|
keyNode[keyType].push({
|
|
44
44
|
value: key
|
|
45
45
|
});
|
|
46
|
-
} else if (key ===
|
|
46
|
+
} else if (key === _numericLiteralsJs.wellFormedNonNegativeIntegerMatcher) {
|
|
47
|
+
var _keyNode1, _keyNode2;
|
|
47
48
|
(_keyNode1 = keyNode).string ?? (_keyNode1.string = []);
|
|
48
49
|
keyNode.string.push(arrayIndexStringBranch);
|
|
49
50
|
(_keyNode2 = keyNode).number ?? (_keyNode2.number = []);
|
|
50
51
|
keyNode.number.push(arrayIndexNumberBranch);
|
|
51
52
|
} else {
|
|
52
|
-
return (0,
|
|
53
|
+
return (0, _errorsJs.throwInternalError)(`Unexpected keyof key '${(0, _serializeJs.stringify)(key)}'`);
|
|
53
54
|
}
|
|
54
55
|
}
|
|
55
56
|
return Object.fromEntries(Object.entries(keyNode).map(([domain, branches])=>[
|
|
@@ -58,17 +59,17 @@ const parseKeyOfTuple = (def, ctx)=>{
|
|
|
58
59
|
]));
|
|
59
60
|
};
|
|
60
61
|
const baseKeysByDomain = {
|
|
61
|
-
bigint: (0,
|
|
62
|
-
boolean: (0,
|
|
62
|
+
bigint: (0, _genericsJs.prototypeKeysOf)(0n),
|
|
63
|
+
boolean: (0, _genericsJs.prototypeKeysOf)(false),
|
|
63
64
|
null: [],
|
|
64
|
-
number: (0,
|
|
65
|
+
number: (0, _genericsJs.prototypeKeysOf)(0),
|
|
65
66
|
// TS doesn't include the Object prototype in keyof, so keyof object is never
|
|
66
67
|
object: [],
|
|
67
|
-
string: (0,
|
|
68
|
-
symbol: (0,
|
|
68
|
+
string: (0, _genericsJs.prototypeKeysOf)(""),
|
|
69
|
+
symbol: (0, _genericsJs.prototypeKeysOf)(Symbol()),
|
|
69
70
|
undefined: []
|
|
70
71
|
};
|
|
71
|
-
const keysOfPredicate = (domain, predicate)=>domain !== "object" || predicate === true ? baseKeysByDomain[domain] : sharedKeysOf((0,
|
|
72
|
+
const keysOfPredicate = (domain, predicate)=>domain !== "object" || predicate === true ? baseKeysByDomain[domain] : sharedKeysOf((0, _genericsJs.listFrom)(predicate).map((branch)=>keysOfObjectBranch(branch)));
|
|
72
73
|
const sharedKeysOf = (keyBranches)=>{
|
|
73
74
|
if (!keyBranches.length) {
|
|
74
75
|
return [];
|
|
@@ -86,21 +87,21 @@ const keysOfObjectBranch = (branch)=>{
|
|
|
86
87
|
const result = [];
|
|
87
88
|
if ("props" in branch) {
|
|
88
89
|
for (const key of Object.keys(branch.props)){
|
|
89
|
-
if (key ===
|
|
90
|
+
if (key === _propsJs.mappedKeys.index) {
|
|
90
91
|
// if any number is a valid key push this RegExp
|
|
91
|
-
result.push(
|
|
92
|
+
result.push(_numericLiteralsJs.wellFormedNonNegativeIntegerMatcher);
|
|
92
93
|
} else if (!result.includes(key)) {
|
|
93
94
|
result.push(key);
|
|
94
|
-
if (
|
|
95
|
+
if (_numericLiteralsJs.wellFormedNonNegativeIntegerMatcher.test(key)) {
|
|
95
96
|
// allow numeric access to keys
|
|
96
|
-
result.push((0,
|
|
97
|
+
result.push((0, _numericLiteralsJs.tryParseWellFormedInteger)(key, `Unexpectedly failed to parse an integer from key '${key}'`));
|
|
97
98
|
}
|
|
98
99
|
}
|
|
99
100
|
}
|
|
100
101
|
}
|
|
101
102
|
if ("class" in branch) {
|
|
102
|
-
const constructor = typeof branch.class === "string" ?
|
|
103
|
-
for (const key of (0,
|
|
103
|
+
const constructor = typeof branch.class === "string" ? _objectKindsJs.defaultObjectKinds[branch.class] : branch.class;
|
|
104
|
+
for (const key of (0, _genericsJs.prototypeKeysOf)(constructor.prototype)){
|
|
104
105
|
if (!result.includes(key)) {
|
|
105
106
|
result.push(key);
|
|
106
107
|
}
|
|
@@ -12,16 +12,16 @@ _export(exports, {
|
|
|
12
12
|
parseMorphTuple: ()=>parseMorphTuple,
|
|
13
13
|
writeMalformedMorphExpressionMessage: ()=>writeMalformedMorphExpressionMessage
|
|
14
14
|
});
|
|
15
|
-
const
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const
|
|
15
|
+
const _branchJs = require("../../nodes/branch.js");
|
|
16
|
+
const _errorsJs = require("../../utils/errors.js");
|
|
17
|
+
const _objectKindsJs = require("../../utils/objectKinds.js");
|
|
18
|
+
const _serializeJs = require("../../utils/serialize.js");
|
|
19
|
+
const _definitionJs = require("../definition.js");
|
|
20
20
|
const parseMorphTuple = (def, ctx)=>{
|
|
21
21
|
if (typeof def[2] !== "function") {
|
|
22
|
-
return (0,
|
|
22
|
+
return (0, _errorsJs.throwParseError)(writeMalformedMorphExpressionMessage(def[2]));
|
|
23
23
|
}
|
|
24
|
-
const node = (0,
|
|
24
|
+
const node = (0, _definitionJs.parseDefinition)(def[0], ctx);
|
|
25
25
|
const resolution = ctx.type.scope.resolveTypeNode(node);
|
|
26
26
|
const morph = def[2];
|
|
27
27
|
ctx.type.includesMorph = true;
|
|
@@ -35,14 +35,14 @@ const parseMorphTuple = (def, ctx)=>{
|
|
|
35
35
|
morph
|
|
36
36
|
};
|
|
37
37
|
} else if (typeof predicate === "object") {
|
|
38
|
-
result[domain] = (0,
|
|
38
|
+
result[domain] = (0, _objectKindsJs.isArray)(predicate) ? predicate.map((branch)=>applyMorph(branch, morph)) : applyMorph(predicate, morph);
|
|
39
39
|
} else {
|
|
40
|
-
(0,
|
|
40
|
+
(0, _errorsJs.throwInternalError)(`Unexpected predicate value for domain '${domain}': ${(0, _serializeJs.stringify)(predicate)}`);
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
return result;
|
|
44
44
|
};
|
|
45
|
-
const applyMorph = (branch, morph)=>(0,
|
|
45
|
+
const applyMorph = (branch, morph)=>(0, _branchJs.isTransformationBranch)(branch) ? {
|
|
46
46
|
...branch,
|
|
47
47
|
morph: branch.morph ? Array.isArray(branch.morph) ? [
|
|
48
48
|
...branch.morph,
|
|
@@ -6,15 +6,15 @@ Object.defineProperty(exports, "parseNarrowTuple", {
|
|
|
6
6
|
enumerable: true,
|
|
7
7
|
get: ()=>parseNarrowTuple
|
|
8
8
|
});
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
9
|
+
const _nodeJs = require("../../nodes/node.js");
|
|
10
|
+
const _definitionJs = require("../definition.js");
|
|
11
|
+
const _distributableFunctionJs = require("./distributableFunction.js");
|
|
12
12
|
const parseNarrowTuple = (def, ctx)=>{
|
|
13
|
-
const inputNode = (0,
|
|
13
|
+
const inputNode = (0, _definitionJs.parseDefinition)(def[0], ctx);
|
|
14
14
|
const resolution = ctx.type.scope.resolveNode(inputNode);
|
|
15
|
-
const hasConfig = (0,
|
|
15
|
+
const hasConfig = (0, _nodeJs.isConfigNode)(resolution);
|
|
16
16
|
const typeNode = hasConfig ? resolution.node : resolution;
|
|
17
|
-
const result = (0,
|
|
17
|
+
const result = (0, _nodeJs.rootIntersection)(inputNode, (0, _distributableFunctionJs.distributeFunctionToNode)(def[2], typeNode, ctx, "narrow"), ctx.type);
|
|
18
18
|
return hasConfig ? {
|
|
19
19
|
config: resolution.config,
|
|
20
20
|
node: result
|