arktype 1.0.13-alpha → 1.0.15-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 +68 -11
- package/dist/main.js +29 -0
- package/dist/nodes/branch.js +135 -0
- package/dist/nodes/compose.js +99 -0
- package/dist/{cjs/nodes → nodes}/discriminate.js +100 -92
- package/dist/nodes/node.js +134 -0
- package/dist/nodes/predicate.js +88 -0
- package/dist/nodes/rules/class.js +23 -0
- package/dist/nodes/rules/collapsibleSet.js +34 -0
- package/dist/nodes/rules/divisor.js +19 -0
- package/dist/nodes/rules/props.js +130 -0
- package/dist/nodes/rules/range.js +108 -0
- package/dist/nodes/rules/regex.js +17 -0
- package/dist/nodes/rules/rules.js +102 -0
- package/dist/parse/ast/ast.js +2 -0
- package/dist/{types/parse → parse}/ast/bound.d.ts +4 -1
- package/dist/parse/ast/bound.js +7 -0
- package/dist/parse/ast/config.js +14 -0
- package/dist/parse/ast/distributableFunction.js +40 -0
- package/dist/parse/ast/divisor.js +5 -0
- package/dist/parse/ast/intersection.js +21 -0
- package/dist/parse/ast/keyof.js +107 -0
- package/dist/parse/ast/morph.js +50 -0
- package/dist/parse/ast/narrow.js +17 -0
- package/dist/{types/parse → parse}/ast/node.d.ts +3 -1
- package/dist/parse/ast/node.js +2 -0
- package/dist/parse/ast/tuple.js +72 -0
- package/dist/parse/ast/union.js +5 -0
- package/dist/parse/ast/utils.js +2 -0
- package/dist/parse/definition.js +47 -0
- package/dist/parse/record.js +31 -0
- package/dist/parse/string/reduce/dynamic.js +159 -0
- package/dist/parse/string/reduce/shared.js +13 -0
- package/dist/parse/string/reduce/static.js +2 -0
- package/dist/parse/string/shift/operand/enclosed.js +37 -0
- package/dist/parse/string/shift/operand/operand.js +15 -0
- package/dist/parse/string/shift/operand/unenclosed.js +45 -0
- package/dist/parse/string/shift/operator/bounds.js +83 -0
- package/dist/parse/string/shift/operator/divisor.js +23 -0
- package/dist/parse/string/shift/operator/operator.js +34 -0
- package/dist/parse/string/shift/scanner.js +97 -0
- package/dist/parse/string/string.js +35 -0
- package/dist/scopes/ark.js +27 -0
- package/dist/scopes/cache.js +28 -0
- package/dist/{mjs/scopes → scopes}/expressions.js +20 -9
- package/dist/scopes/jsObjects.js +20 -0
- package/dist/scopes/scope.js +184 -0
- package/dist/scopes/tsKeywords.js +49 -0
- package/dist/scopes/type.js +40 -0
- package/dist/{mjs/scopes → scopes}/validation/creditCard.js +15 -11
- package/dist/{mjs/scopes → scopes}/validation/date.js +21 -16
- package/dist/scopes/validation/validation.js +74 -0
- package/dist/traverse/problems.js +234 -0
- package/dist/traverse/traverse.js +330 -0
- package/dist/tsconfig.temp.tsbuildinfo +1 -1
- package/dist/{mjs/utils → utils}/chainableNoOpProxy.js +6 -2
- package/dist/utils/data.js +39 -0
- package/dist/utils/domains.js +27 -0
- package/dist/utils/errors.js +17 -0
- package/dist/utils/freeze.js +16 -0
- package/dist/utils/generics.js +53 -0
- package/dist/utils/numericLiterals.js +88 -0
- package/dist/utils/objectKinds.js +69 -0
- package/dist/{mjs/utils → utils}/paths.js +8 -3
- package/dist/utils/serialize.js +71 -0
- package/dist/utils/unionToTuple.js +2 -0
- package/package.json +25 -39
- package/dist/cjs/main.js +0 -38
- package/dist/cjs/nodes/branch.js +0 -140
- package/dist/cjs/nodes/compose.js +0 -157
- package/dist/cjs/nodes/node.js +0 -139
- package/dist/cjs/nodes/predicate.js +0 -86
- package/dist/cjs/nodes/rules/class.js +0 -25
- package/dist/cjs/nodes/rules/collapsibleSet.js +0 -48
- package/dist/cjs/nodes/rules/divisor.js +0 -29
- package/dist/cjs/nodes/rules/props.js +0 -160
- package/dist/cjs/nodes/rules/range.js +0 -105
- package/dist/cjs/nodes/rules/regex.js +0 -26
- package/dist/cjs/nodes/rules/rules.js +0 -123
- package/dist/cjs/package.json +0 -3
- package/dist/cjs/parse/ast/ast.js +0 -4
- package/dist/cjs/parse/ast/bound.js +0 -9
- package/dist/cjs/parse/ast/config.js +0 -13
- package/dist/cjs/parse/ast/distributableFunction.js +0 -48
- package/dist/cjs/parse/ast/divisor.js +0 -9
- package/dist/cjs/parse/ast/intersection.js +0 -30
- package/dist/cjs/parse/ast/keyof.js +0 -111
- package/dist/cjs/parse/ast/morph.js +0 -58
- package/dist/cjs/parse/ast/narrow.js +0 -22
- package/dist/cjs/parse/ast/node.js +0 -4
- package/dist/cjs/parse/ast/tuple.js +0 -94
- package/dist/cjs/parse/ast/union.js +0 -9
- package/dist/cjs/parse/ast/utils.js +0 -4
- package/dist/cjs/parse/definition.js +0 -61
- package/dist/cjs/parse/record.js +0 -37
- package/dist/cjs/parse/string/reduce/dynamic.js +0 -167
- package/dist/cjs/parse/string/reduce/shared.js +0 -23
- package/dist/cjs/parse/string/reduce/static.js +0 -4
- package/dist/cjs/parse/string/shift/operand/enclosed.js +0 -54
- package/dist/cjs/parse/string/shift/operand/operand.js +0 -11
- package/dist/cjs/parse/string/shift/operand/unenclosed.js +0 -53
- package/dist/cjs/parse/string/shift/operator/bounds.js +0 -87
- package/dist/cjs/parse/string/shift/operator/divisor.js +0 -35
- package/dist/cjs/parse/string/shift/operator/operator.js +0 -26
- package/dist/cjs/parse/string/shift/scanner.js +0 -114
- package/dist/cjs/parse/string/string.js +0 -43
- package/dist/cjs/scopes/ark.js +0 -45
- package/dist/cjs/scopes/cache.js +0 -52
- package/dist/cjs/scopes/expressions.js +0 -29
- package/dist/cjs/scopes/jsObjects.js +0 -93
- package/dist/cjs/scopes/scope.js +0 -323
- package/dist/cjs/scopes/tsKeywords.js +0 -113
- package/dist/cjs/scopes/type.js +0 -50
- package/dist/cjs/scopes/validation/creditCard.js +0 -47
- package/dist/cjs/scopes/validation/date.js +0 -62
- package/dist/cjs/scopes/validation/validation.js +0 -104
- package/dist/cjs/traverse/problems.js +0 -281
- package/dist/cjs/traverse/traverse.js +0 -387
- package/dist/cjs/utils/chainableNoOpProxy.js +0 -23
- package/dist/cjs/utils/data.js +0 -53
- package/dist/cjs/utils/domains.js +0 -30
- package/dist/cjs/utils/errors.js +0 -26
- package/dist/cjs/utils/freeze.js +0 -15
- package/dist/cjs/utils/generics.js +0 -63
- package/dist/cjs/utils/numericLiterals.js +0 -75
- package/dist/cjs/utils/objectKinds.js +0 -69
- package/dist/cjs/utils/paths.js +0 -32
- package/dist/cjs/utils/serialize.js +0 -74
- package/dist/cjs/utils/unionToTuple.js +0 -4
- package/dist/mjs/main.js +0 -8
- package/dist/mjs/nodes/branch.js +0 -123
- package/dist/mjs/nodes/compose.js +0 -135
- package/dist/mjs/nodes/discriminate.js +0 -247
- package/dist/mjs/nodes/node.js +0 -117
- package/dist/mjs/nodes/predicate.js +0 -69
- package/dist/mjs/nodes/rules/class.js +0 -11
- package/dist/mjs/nodes/rules/collapsibleSet.js +0 -34
- package/dist/mjs/nodes/rules/divisor.js +0 -15
- package/dist/mjs/nodes/rules/props.js +0 -142
- package/dist/mjs/nodes/rules/range.js +0 -86
- package/dist/mjs/nodes/rules/regex.js +0 -11
- package/dist/mjs/nodes/rules/rules.js +0 -106
- package/dist/mjs/package.json +0 -3
- package/dist/mjs/parse/ast/ast.js +0 -1
- package/dist/mjs/parse/ast/bound.js +0 -1
- package/dist/mjs/parse/ast/config.js +0 -9
- package/dist/mjs/parse/ast/distributableFunction.js +0 -34
- package/dist/mjs/parse/ast/divisor.js +0 -1
- package/dist/mjs/parse/ast/intersection.js +0 -16
- package/dist/mjs/parse/ast/keyof.js +0 -103
- package/dist/mjs/parse/ast/morph.js +0 -44
- package/dist/mjs/parse/ast/narrow.js +0 -14
- package/dist/mjs/parse/ast/node.js +0 -1
- package/dist/mjs/parse/ast/tuple.js +0 -80
- package/dist/mjs/parse/ast/union.js +0 -1
- package/dist/mjs/parse/ast/utils.js +0 -1
- package/dist/mjs/parse/definition.js +0 -46
- package/dist/mjs/parse/record.js +0 -29
- package/dist/mjs/parse/string/reduce/dynamic.js +0 -159
- package/dist/mjs/parse/string/reduce/shared.js +0 -6
- package/dist/mjs/parse/string/reduce/static.js +0 -1
- package/dist/mjs/parse/string/shift/operand/enclosed.js +0 -39
- package/dist/mjs/parse/string/shift/operand/operand.js +0 -3
- package/dist/mjs/parse/string/shift/operand/unenclosed.js +0 -36
- package/dist/mjs/parse/string/shift/operator/bounds.js +0 -70
- package/dist/mjs/parse/string/shift/operator/divisor.js +0 -21
- package/dist/mjs/parse/string/shift/operator/operator.js +0 -13
- package/dist/mjs/parse/string/shift/scanner.js +0 -106
- package/dist/mjs/parse/string/string.js +0 -28
- package/dist/mjs/scopes/ark.js +0 -28
- package/dist/mjs/scopes/cache.js +0 -38
- package/dist/mjs/scopes/jsObjects.js +0 -82
- package/dist/mjs/scopes/scope.js +0 -303
- package/dist/mjs/scopes/tsKeywords.js +0 -116
- package/dist/mjs/scopes/type.js +0 -35
- package/dist/mjs/scopes/validation/validation.js +0 -108
- package/dist/mjs/traverse/problems.js +0 -260
- package/dist/mjs/traverse/traverse.js +0 -370
- package/dist/mjs/utils/data.js +0 -38
- package/dist/mjs/utils/domains.js +0 -15
- package/dist/mjs/utils/errors.js +0 -10
- package/dist/mjs/utils/freeze.js +0 -7
- package/dist/mjs/utils/generics.js +0 -38
- package/dist/mjs/utils/numericLiterals.js +0 -72
- package/dist/mjs/utils/objectKinds.js +0 -55
- package/dist/mjs/utils/serialize.js +0 -58
- package/dist/mjs/utils/unionToTuple.js +0 -1
- /package/dist/{types/main.d.ts → main.d.ts} +0 -0
- /package/dist/{types/nodes → nodes}/branch.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/compose.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/discriminate.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/node.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/predicate.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/rules/class.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/rules/collapsibleSet.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/rules/divisor.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/rules/props.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/rules/range.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/rules/regex.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/rules/rules.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/ast.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/config.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/distributableFunction.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/divisor.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/intersection.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/keyof.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/morph.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/narrow.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/tuple.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/union.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/utils.d.ts +0 -0
- /package/dist/{types/parse → parse}/definition.d.ts +0 -0
- /package/dist/{types/parse → parse}/record.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/reduce/dynamic.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/reduce/shared.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/reduce/static.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/shift/operand/enclosed.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/shift/operand/operand.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/shift/operand/unenclosed.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/shift/operator/bounds.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/shift/operator/divisor.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/shift/operator/operator.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/shift/scanner.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/string.d.ts +0 -0
- /package/dist/{types/scopes → scopes}/ark.d.ts +0 -0
- /package/dist/{types/scopes → scopes}/cache.d.ts +0 -0
- /package/dist/{types/scopes → scopes}/expressions.d.ts +0 -0
- /package/dist/{types/scopes → scopes}/jsObjects.d.ts +0 -0
- /package/dist/{types/scopes → scopes}/scope.d.ts +0 -0
- /package/dist/{types/scopes → scopes}/tsKeywords.d.ts +0 -0
- /package/dist/{types/scopes → scopes}/type.d.ts +0 -0
- /package/dist/{types/scopes → scopes}/validation/creditCard.d.ts +0 -0
- /package/dist/{types/scopes → scopes}/validation/date.d.ts +0 -0
- /package/dist/{types/scopes → scopes}/validation/validation.d.ts +0 -0
- /package/dist/{types/traverse → traverse}/problems.d.ts +0 -0
- /package/dist/{types/traverse → traverse}/traverse.d.ts +0 -0
- /package/dist/{types/utils → utils}/chainableNoOpProxy.d.ts +0 -0
- /package/dist/{types/utils → utils}/data.d.ts +0 -0
- /package/dist/{types/utils → utils}/domains.d.ts +0 -0
- /package/dist/{types/utils → utils}/errors.d.ts +0 -0
- /package/dist/{types/utils → utils}/freeze.d.ts +0 -0
- /package/dist/{types/utils → utils}/generics.d.ts +0 -0
- /package/dist/{types/utils → utils}/numericLiterals.d.ts +0 -0
- /package/dist/{types/utils → utils}/objectKinds.d.ts +0 -0
- /package/dist/{types/utils → utils}/paths.d.ts +0 -0
- /package/dist/{types/utils → utils}/serialize.d.ts +0 -0
- /package/dist/{types/utils → utils}/unionToTuple.d.ts +0 -0
package/dist/cjs/nodes/branch.js
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
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
|
-
isBranchComparison: ()=>isBranchComparison,
|
|
13
|
-
compareBranches: ()=>compareBranches,
|
|
14
|
-
isTransformationBranch: ()=>isTransformationBranch,
|
|
15
|
-
flattenBranch: ()=>flattenBranch,
|
|
16
|
-
branchIntersection: ()=>branchIntersection
|
|
17
|
-
});
|
|
18
|
-
const _intersectionJs = require("../parse/ast/intersection.js");
|
|
19
|
-
const _domainsJs = require("../utils/domains.js");
|
|
20
|
-
const _errorsJs = require("../utils/errors.js");
|
|
21
|
-
const _composeJs = require("./compose.js");
|
|
22
|
-
const _rulesJs = require("./rules/rules.js");
|
|
23
|
-
const isBranchComparison = (comparison)=>comparison?.lBranches !== undefined;
|
|
24
|
-
const compareBranches = (lConditions, rConditions, state)=>{
|
|
25
|
-
const result = {
|
|
26
|
-
lBranches: lConditions,
|
|
27
|
-
rBranches: rConditions,
|
|
28
|
-
lExtendsR: [],
|
|
29
|
-
rExtendsL: [],
|
|
30
|
-
equalities: [],
|
|
31
|
-
distinctIntersections: []
|
|
32
|
-
};
|
|
33
|
-
const pairs = rConditions.map((condition)=>({
|
|
34
|
-
condition,
|
|
35
|
-
distinct: []
|
|
36
|
-
}));
|
|
37
|
-
lConditions.forEach((l, lIndex)=>{
|
|
38
|
-
let lImpliesR = false;
|
|
39
|
-
const distinct = pairs.map((rPairs, rIndex)=>{
|
|
40
|
-
if (lImpliesR || !rPairs.distinct) {
|
|
41
|
-
return null;
|
|
42
|
-
}
|
|
43
|
-
const r = rPairs.condition;
|
|
44
|
-
const subresult = branchIntersection(l, r, state);
|
|
45
|
-
if ((0, _composeJs.isDisjoint)(subresult)) {
|
|
46
|
-
// doesn't tell us about any redundancies or add a distinct pair
|
|
47
|
-
return null;
|
|
48
|
-
} else if (subresult === l) {
|
|
49
|
-
result.lExtendsR.push(lIndex);
|
|
50
|
-
// If l is a subtype of the current r branch, intersections
|
|
51
|
-
// with the remaining branches of r won't lead to distinct
|
|
52
|
-
// branches, so we set a flag indicating we can skip them.
|
|
53
|
-
lImpliesR = true;
|
|
54
|
-
return null;
|
|
55
|
-
} else if (subresult === r) {
|
|
56
|
-
result.rExtendsL.push(rIndex);
|
|
57
|
-
// If r is a subtype of the current l branch, it is removed
|
|
58
|
-
// from pairsByR because future intersections won't lead to
|
|
59
|
-
// distinct branches.
|
|
60
|
-
rPairs.distinct = null;
|
|
61
|
-
return null;
|
|
62
|
-
} else if ((0, _composeJs.isEquality)(subresult)) {
|
|
63
|
-
// Combination of l and r subtype cases.
|
|
64
|
-
result.equalities.push([
|
|
65
|
-
lIndex,
|
|
66
|
-
rIndex
|
|
67
|
-
]);
|
|
68
|
-
lImpliesR = true;
|
|
69
|
-
rPairs.distinct = null;
|
|
70
|
-
return null;
|
|
71
|
-
} else if ((0, _domainsJs.hasDomain)(subresult, "object")) {
|
|
72
|
-
// Neither branch is a subtype of the other, return
|
|
73
|
-
// the result of the intersection as a candidate
|
|
74
|
-
// branch for the final union
|
|
75
|
-
return subresult;
|
|
76
|
-
}
|
|
77
|
-
return (0, _errorsJs.throwInternalError)(`Unexpected predicate intersection result of type '${(0, _domainsJs.domainOf)(subresult)}'`);
|
|
78
|
-
});
|
|
79
|
-
if (!lImpliesR) {
|
|
80
|
-
for(let i = 0; i < pairs.length; i++){
|
|
81
|
-
if (distinct[i]) {
|
|
82
|
-
pairs[i].distinct?.push(distinct[i]);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
result.distinctIntersections = pairs.flatMap((pairs)=>pairs.distinct ?? []);
|
|
88
|
-
return result;
|
|
89
|
-
};
|
|
90
|
-
const isTransformationBranch = (branch)=>"rules" in branch;
|
|
91
|
-
const flattenBranch = (branch, ctx)=>{
|
|
92
|
-
if (isTransformationBranch(branch)) {
|
|
93
|
-
const result = (0, _rulesJs.flattenRules)(branch.rules, ctx);
|
|
94
|
-
if (branch.morph) {
|
|
95
|
-
if (typeof branch.morph === "function") {
|
|
96
|
-
result.push([
|
|
97
|
-
"morph",
|
|
98
|
-
branch.morph
|
|
99
|
-
]);
|
|
100
|
-
} else {
|
|
101
|
-
for (const morph of branch.morph){
|
|
102
|
-
result.push([
|
|
103
|
-
"morph",
|
|
104
|
-
morph
|
|
105
|
-
]);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
return result;
|
|
110
|
-
}
|
|
111
|
-
return (0, _rulesJs.flattenRules)(branch, ctx);
|
|
112
|
-
};
|
|
113
|
-
const rulesOf = (branch)=>branch.rules ?? branch;
|
|
114
|
-
const branchIntersection = (l, r, state)=>{
|
|
115
|
-
const lRules = rulesOf(l);
|
|
116
|
-
const rRules = rulesOf(r);
|
|
117
|
-
const rulesResult = (0, _rulesJs.rulesIntersection)(lRules, rRules, state);
|
|
118
|
-
if ("morph" in l) {
|
|
119
|
-
if ("morph" in r) {
|
|
120
|
-
if (l.morph === r.morph) {
|
|
121
|
-
return (0, _composeJs.isEquality)(rulesResult) || (0, _composeJs.isDisjoint)(rulesResult) ? rulesResult : {
|
|
122
|
-
rules: rulesResult,
|
|
123
|
-
morph: l.morph
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
return state.lastOperator === "&" ? (0, _errorsJs.throwParseError)((0, _intersectionJs.writeImplicitNeverMessage)(state.path, "Intersection", "of morphs")) : {};
|
|
127
|
-
}
|
|
128
|
-
return (0, _composeJs.isDisjoint)(rulesResult) ? rulesResult : {
|
|
129
|
-
rules: (0, _composeJs.isEquality)(rulesResult) ? l.rules : rulesResult,
|
|
130
|
-
morph: l.morph
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
if ("morph" in r) {
|
|
134
|
-
return (0, _composeJs.isDisjoint)(rulesResult) ? rulesResult : {
|
|
135
|
-
rules: (0, _composeJs.isEquality)(rulesResult) ? r.rules : rulesResult,
|
|
136
|
-
morph: r.morph
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
return rulesResult;
|
|
140
|
-
};
|
|
@@ -1,157 +0,0 @@
|
|
|
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
|
-
composeIntersection: ()=>composeIntersection,
|
|
13
|
-
undefinedOperandsMessage: ()=>undefinedOperandsMessage,
|
|
14
|
-
disjointDescriptionWriters: ()=>disjointDescriptionWriters,
|
|
15
|
-
stringifyRange: ()=>stringifyRange,
|
|
16
|
-
IntersectionState: ()=>IntersectionState,
|
|
17
|
-
anonymousDisjoint: ()=>anonymousDisjoint,
|
|
18
|
-
isDisjoint: ()=>isDisjoint,
|
|
19
|
-
equality: ()=>equality,
|
|
20
|
-
isEquality: ()=>isEquality,
|
|
21
|
-
composeKeyedIntersection: ()=>composeKeyedIntersection
|
|
22
|
-
});
|
|
23
|
-
const _errorsJs = require("../utils/errors.js");
|
|
24
|
-
const _genericsJs = require("../utils/generics.js");
|
|
25
|
-
const _pathsJs = require("../utils/paths.js");
|
|
26
|
-
const _serializeJs = require("../utils/serialize.js");
|
|
27
|
-
function _checkPrivateRedeclaration(obj, privateCollection) {
|
|
28
|
-
if (privateCollection.has(obj)) {
|
|
29
|
-
throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
function _classApplyDescriptorGet(receiver, descriptor) {
|
|
33
|
-
if (descriptor.get) {
|
|
34
|
-
return descriptor.get.call(receiver);
|
|
35
|
-
}
|
|
36
|
-
return descriptor.value;
|
|
37
|
-
}
|
|
38
|
-
function _classApplyDescriptorSet(receiver, descriptor, value) {
|
|
39
|
-
if (descriptor.set) {
|
|
40
|
-
descriptor.set.call(receiver, value);
|
|
41
|
-
} else {
|
|
42
|
-
if (!descriptor.writable) {
|
|
43
|
-
throw new TypeError("attempted to set read only private field");
|
|
44
|
-
}
|
|
45
|
-
descriptor.value = value;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
function _classExtractFieldDescriptor(receiver, privateMap, action) {
|
|
49
|
-
if (!privateMap.has(receiver)) {
|
|
50
|
-
throw new TypeError("attempted to " + action + " private field on non-instance");
|
|
51
|
-
}
|
|
52
|
-
return privateMap.get(receiver);
|
|
53
|
-
}
|
|
54
|
-
function _classPrivateFieldGet(receiver, privateMap) {
|
|
55
|
-
var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get");
|
|
56
|
-
return _classApplyDescriptorGet(receiver, descriptor);
|
|
57
|
-
}
|
|
58
|
-
function _classPrivateFieldInit(obj, privateMap, value) {
|
|
59
|
-
_checkPrivateRedeclaration(obj, privateMap);
|
|
60
|
-
privateMap.set(obj, value);
|
|
61
|
-
}
|
|
62
|
-
function _classPrivateFieldSet(receiver, privateMap, value) {
|
|
63
|
-
var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set");
|
|
64
|
-
_classApplyDescriptorSet(receiver, descriptor, value);
|
|
65
|
-
return value;
|
|
66
|
-
}
|
|
67
|
-
function _defineProperty(obj, key, value) {
|
|
68
|
-
if (key in obj) {
|
|
69
|
-
Object.defineProperty(obj, key, {
|
|
70
|
-
value: value,
|
|
71
|
-
enumerable: true,
|
|
72
|
-
configurable: true,
|
|
73
|
-
writable: true
|
|
74
|
-
});
|
|
75
|
-
} else {
|
|
76
|
-
obj[key] = value;
|
|
77
|
-
}
|
|
78
|
-
return obj;
|
|
79
|
-
}
|
|
80
|
-
const composeIntersection = (reducer)=>(l, r, state)=>l === undefined ? r === undefined ? (0, _errorsJs.throwInternalError)(undefinedOperandsMessage) : r : r === undefined ? l : reducer(l, r, state);
|
|
81
|
-
const undefinedOperandsMessage = `Unexpected operation two undefined operands`;
|
|
82
|
-
const disjointDescriptionWriters = {
|
|
83
|
-
domain: ({ l , r })=>`${l.join(", ")} and ${r.join(", ")}`,
|
|
84
|
-
range: ({ l , r })=>`${stringifyRange(l)} and ${stringifyRange(r)}`,
|
|
85
|
-
class: ({ l , r })=>`classes ${typeof l === "string" ? l : l.name} and ${typeof r === "string" ? r : r.name}`,
|
|
86
|
-
tupleLength: ({ l , r })=>`tuples of length ${l} and ${r}`,
|
|
87
|
-
value: ({ l , r })=>`literal values ${(0, _serializeJs.stringify)(l)} and ${(0, _serializeJs.stringify)(r)}`,
|
|
88
|
-
leftAssignability: ({ l , r })=>`literal value ${(0, _serializeJs.stringify)(l.value)} and ${(0, _serializeJs.stringify)(r)}`,
|
|
89
|
-
rightAssignability: ({ l , r })=>`literal value ${(0, _serializeJs.stringify)(r.value)} and ${(0, _serializeJs.stringify)(l)}`,
|
|
90
|
-
union: ({ l , r })=>`branches ${(0, _serializeJs.stringify)(l)} and branches ${(0, _serializeJs.stringify)(r)}`
|
|
91
|
-
};
|
|
92
|
-
const stringifyRange = (range)=>"limit" in range ? `the range of exactly ${range.limit}` : range.min ? range.max ? `the range bounded by ${range.min.comparator}${range.min.limit} and ${range.max.comparator}${range.max.limit}` : `${range.min.comparator}${range.min.limit}` : range.max ? `${range.max.comparator}${range.max.limit}` : "the unbounded range";
|
|
93
|
-
var _disjoints = /*#__PURE__*/ new WeakMap();
|
|
94
|
-
class IntersectionState {
|
|
95
|
-
get disjoints() {
|
|
96
|
-
return _classPrivateFieldGet(this, _disjoints);
|
|
97
|
-
}
|
|
98
|
-
addDisjoint(kind, l, r) {
|
|
99
|
-
_classPrivateFieldGet(this, _disjoints)[`${this.path}`] = {
|
|
100
|
-
kind,
|
|
101
|
-
l,
|
|
102
|
-
r
|
|
103
|
-
};
|
|
104
|
-
return empty;
|
|
105
|
-
}
|
|
106
|
-
constructor(type, lastOperator){
|
|
107
|
-
_defineProperty(this, "type", void 0);
|
|
108
|
-
_defineProperty(this, "lastOperator", void 0);
|
|
109
|
-
_defineProperty(this, "path", void 0);
|
|
110
|
-
_defineProperty(this, "domain", void 0);
|
|
111
|
-
_classPrivateFieldInit(this, _disjoints, {
|
|
112
|
-
writable: true,
|
|
113
|
-
value: void 0
|
|
114
|
-
});
|
|
115
|
-
this.type = type;
|
|
116
|
-
this.lastOperator = lastOperator;
|
|
117
|
-
this.path = new _pathsJs.Path();
|
|
118
|
-
_classPrivateFieldSet(this, _disjoints, {});
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
const empty = Symbol("empty");
|
|
122
|
-
const anonymousDisjoint = ()=>empty;
|
|
123
|
-
const isDisjoint = (result)=>result === empty;
|
|
124
|
-
const equal = Symbol("equal");
|
|
125
|
-
const equality = ()=>equal;
|
|
126
|
-
const isEquality = (result)=>result === equal;
|
|
127
|
-
const composeKeyedIntersection = (reducer, config)=>(l, r, state)=>{
|
|
128
|
-
const result = {};
|
|
129
|
-
const keys = (0, _genericsJs.objectKeysOf)({
|
|
130
|
-
...l,
|
|
131
|
-
...r
|
|
132
|
-
});
|
|
133
|
-
let lImpliesR = true;
|
|
134
|
-
let rImpliesL = true;
|
|
135
|
-
for (const k of keys){
|
|
136
|
-
const keyResult = typeof reducer === "function" ? reducer(k, l[k], r[k], state) : reducer[k](l[k], r[k], state);
|
|
137
|
-
if (isEquality(keyResult)) {
|
|
138
|
-
if (l[k] !== undefined) {
|
|
139
|
-
result[k] = l[k];
|
|
140
|
-
}
|
|
141
|
-
} else if (isDisjoint(keyResult)) {
|
|
142
|
-
if (config.onEmpty === "omit") {
|
|
143
|
-
lImpliesR = false;
|
|
144
|
-
rImpliesL = false;
|
|
145
|
-
} else {
|
|
146
|
-
return empty;
|
|
147
|
-
}
|
|
148
|
-
} else {
|
|
149
|
-
if (keyResult !== undefined) {
|
|
150
|
-
result[k] = keyResult;
|
|
151
|
-
}
|
|
152
|
-
lImpliesR && (lImpliesR = keyResult === l[k]);
|
|
153
|
-
rImpliesL && (rImpliesL = keyResult === r[k]);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
return lImpliesR ? rImpliesL ? equality() : l : rImpliesL ? r : result;
|
|
157
|
-
};
|
package/dist/cjs/nodes/node.js
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
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
|
-
isConfigNode: ()=>isConfigNode,
|
|
13
|
-
nodeIntersection: ()=>nodeIntersection,
|
|
14
|
-
rootIntersection: ()=>rootIntersection,
|
|
15
|
-
rootUnion: ()=>rootUnion,
|
|
16
|
-
flattenType: ()=>flattenType,
|
|
17
|
-
flattenNode: ()=>flattenNode,
|
|
18
|
-
flattenTypeNode: ()=>flattenTypeNode,
|
|
19
|
-
isLiteralNode: ()=>isLiteralNode,
|
|
20
|
-
resolutionExtendsDomain: ()=>resolutionExtendsDomain,
|
|
21
|
-
toArrayNode: ()=>toArrayNode
|
|
22
|
-
});
|
|
23
|
-
const _intersectionJs = require("../parse/ast/intersection.js");
|
|
24
|
-
const _errorsJs = require("../utils/errors.js");
|
|
25
|
-
const _genericsJs = require("../utils/generics.js");
|
|
26
|
-
const _pathsJs = require("../utils/paths.js");
|
|
27
|
-
const _composeJs = require("./compose.js");
|
|
28
|
-
const _predicateJs = require("./predicate.js");
|
|
29
|
-
const _propsJs = require("./rules/props.js");
|
|
30
|
-
const isConfigNode = (node)=>"config" in node;
|
|
31
|
-
const nodeIntersection = (l, r, state)=>{
|
|
32
|
-
state.domain = undefined;
|
|
33
|
-
const lDomains = state.type.scope.resolveTypeNode(l);
|
|
34
|
-
const rDomains = state.type.scope.resolveTypeNode(r);
|
|
35
|
-
const result = typeNodeIntersection(lDomains, rDomains, state);
|
|
36
|
-
if (typeof result === "object" && !(0, _genericsJs.hasKeys)(result)) {
|
|
37
|
-
return (0, _genericsJs.hasKeys)(state.disjoints) ? (0, _composeJs.anonymousDisjoint)() : state.addDisjoint("domain", (0, _genericsJs.objectKeysOf)(lDomains), (0, _genericsJs.objectKeysOf)(rDomains));
|
|
38
|
-
}
|
|
39
|
-
return result === lDomains ? l : result === rDomains ? r : result;
|
|
40
|
-
};
|
|
41
|
-
const typeNodeIntersection = (0, _composeJs.composeKeyedIntersection)((domain, l, r, context)=>{
|
|
42
|
-
if (l === undefined) {
|
|
43
|
-
return r === undefined ? (0, _errorsJs.throwInternalError)(_composeJs.undefinedOperandsMessage) : undefined;
|
|
44
|
-
}
|
|
45
|
-
if (r === undefined) {
|
|
46
|
-
return undefined;
|
|
47
|
-
}
|
|
48
|
-
return (0, _predicateJs.predicateIntersection)(domain, l, r, context);
|
|
49
|
-
}, {
|
|
50
|
-
onEmpty: "omit"
|
|
51
|
-
});
|
|
52
|
-
const rootIntersection = (l, r, type)=>{
|
|
53
|
-
const state = new _composeJs.IntersectionState(type, "&");
|
|
54
|
-
const result = nodeIntersection(l, r, state);
|
|
55
|
-
return (0, _composeJs.isDisjoint)(result) ? (0, _errorsJs.throwParseError)((0, _intersectionJs.compileDisjointReasonsMessage)(state.disjoints)) : (0, _composeJs.isEquality)(result) ? l : result;
|
|
56
|
-
};
|
|
57
|
-
const rootUnion = (l, r, type)=>{
|
|
58
|
-
const lDomains = type.scope.resolveTypeNode(l);
|
|
59
|
-
const rDomains = type.scope.resolveTypeNode(r);
|
|
60
|
-
const result = {};
|
|
61
|
-
const domains = (0, _genericsJs.objectKeysOf)({
|
|
62
|
-
...lDomains,
|
|
63
|
-
...rDomains
|
|
64
|
-
});
|
|
65
|
-
for (const domain of domains){
|
|
66
|
-
result[domain] = (0, _genericsJs.hasKey)(lDomains, domain) ? (0, _genericsJs.hasKey)(rDomains, domain) ? (0, _predicateJs.predicateUnion)(domain, lDomains[domain], rDomains[domain], type) : lDomains[domain] : (0, _genericsJs.hasKey)(rDomains, domain) ? rDomains[domain] : (0, _errorsJs.throwInternalError)(_composeJs.undefinedOperandsMessage);
|
|
67
|
-
}
|
|
68
|
-
return result;
|
|
69
|
-
};
|
|
70
|
-
const hasImpliedDomain = (flatPredicate)=>flatPredicate[0] && (flatPredicate[0][0] === "value" || flatPredicate[0][0] === "class");
|
|
71
|
-
const flattenType = (type)=>{
|
|
72
|
-
const ctx = {
|
|
73
|
-
type,
|
|
74
|
-
path: new _pathsJs.Path(),
|
|
75
|
-
lastDomain: "undefined"
|
|
76
|
-
};
|
|
77
|
-
return flattenNode(type.node, ctx);
|
|
78
|
-
};
|
|
79
|
-
const flattenNode = (node, ctx)=>{
|
|
80
|
-
if (typeof node === "string") {
|
|
81
|
-
return ctx.type.scope.resolve(node).flat;
|
|
82
|
-
}
|
|
83
|
-
const hasConfig = isConfigNode(node);
|
|
84
|
-
const flattenedTypeNode = flattenTypeNode(hasConfig ? node.node : node, ctx);
|
|
85
|
-
return hasConfig ? [
|
|
86
|
-
[
|
|
87
|
-
"config",
|
|
88
|
-
{
|
|
89
|
-
config: (0, _genericsJs.entriesOf)(node.config),
|
|
90
|
-
node: flattenedTypeNode
|
|
91
|
-
}
|
|
92
|
-
]
|
|
93
|
-
] : flattenedTypeNode;
|
|
94
|
-
};
|
|
95
|
-
const flattenTypeNode = (node, ctx)=>{
|
|
96
|
-
const domains = (0, _genericsJs.objectKeysOf)(node);
|
|
97
|
-
if (domains.length === 1) {
|
|
98
|
-
const domain = domains[0];
|
|
99
|
-
const predicate = node[domain];
|
|
100
|
-
if (predicate === true) {
|
|
101
|
-
return domain;
|
|
102
|
-
}
|
|
103
|
-
ctx.lastDomain = domain;
|
|
104
|
-
const flatPredicate = (0, _predicateJs.flattenPredicate)(predicate, ctx);
|
|
105
|
-
return hasImpliedDomain(flatPredicate) ? flatPredicate : [
|
|
106
|
-
[
|
|
107
|
-
"domain",
|
|
108
|
-
domain
|
|
109
|
-
],
|
|
110
|
-
...flatPredicate
|
|
111
|
-
];
|
|
112
|
-
}
|
|
113
|
-
const result = {};
|
|
114
|
-
for (const domain of domains){
|
|
115
|
-
ctx.lastDomain = domain;
|
|
116
|
-
result[domain] = (0, _predicateJs.flattenPredicate)(node[domain], ctx);
|
|
117
|
-
}
|
|
118
|
-
return [
|
|
119
|
-
[
|
|
120
|
-
"domains",
|
|
121
|
-
result
|
|
122
|
-
]
|
|
123
|
-
];
|
|
124
|
-
};
|
|
125
|
-
const isLiteralNode = (node, domain)=>{
|
|
126
|
-
return resolutionExtendsDomain(node, domain) && (0, _predicateJs.isLiteralCondition)(node[domain]);
|
|
127
|
-
};
|
|
128
|
-
const resolutionExtendsDomain = (resolution, domain)=>{
|
|
129
|
-
const domains = (0, _genericsJs.objectKeysOf)(resolution);
|
|
130
|
-
return domains.length === 1 && domains[0] === domain;
|
|
131
|
-
};
|
|
132
|
-
const toArrayNode = (node)=>({
|
|
133
|
-
object: {
|
|
134
|
-
class: Array,
|
|
135
|
-
props: {
|
|
136
|
-
[_propsJs.mappedKeys.index]: node
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
});
|
|
@@ -1,86 +0,0 @@
|
|
|
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
|
-
comparePredicates: ()=>comparePredicates,
|
|
13
|
-
predicateIntersection: ()=>predicateIntersection,
|
|
14
|
-
predicateUnion: ()=>predicateUnion,
|
|
15
|
-
flattenPredicate: ()=>flattenPredicate,
|
|
16
|
-
isLiteralCondition: ()=>isLiteralCondition
|
|
17
|
-
});
|
|
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
|
-
const emptyRulesIfTrue = (predicate)=>predicate === true ? {} : predicate;
|
|
24
|
-
const comparePredicates = (l, r, context)=>{
|
|
25
|
-
if (l === true && r === true) {
|
|
26
|
-
return (0, _composeJs.equality)();
|
|
27
|
-
}
|
|
28
|
-
if (!(0, _objectKindsJs.isArray)(l) && !(0, _objectKindsJs.isArray)(r)) {
|
|
29
|
-
const result = (0, _branchJs.branchIntersection)(emptyRulesIfTrue(l), emptyRulesIfTrue(r), context);
|
|
30
|
-
return result === l ? l : result === r ? r : result;
|
|
31
|
-
}
|
|
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
|
-
if (comparison.equalities.length === lBranches.length && comparison.equalities.length === rBranches.length) {
|
|
36
|
-
return (0, _composeJs.equality)();
|
|
37
|
-
}
|
|
38
|
-
if (comparison.lExtendsR.length + comparison.equalities.length === lBranches.length) {
|
|
39
|
-
return l;
|
|
40
|
-
}
|
|
41
|
-
if (comparison.rExtendsL.length + comparison.equalities.length === rBranches.length) {
|
|
42
|
-
return r;
|
|
43
|
-
}
|
|
44
|
-
return comparison;
|
|
45
|
-
};
|
|
46
|
-
const predicateIntersection = (domain, l, r, state)=>{
|
|
47
|
-
state.domain = domain;
|
|
48
|
-
const comparison = comparePredicates(l, r, state);
|
|
49
|
-
if (!(0, _branchJs.isBranchComparison)(comparison)) {
|
|
50
|
-
return comparison;
|
|
51
|
-
}
|
|
52
|
-
const resultBranches = [
|
|
53
|
-
...comparison.distinctIntersections,
|
|
54
|
-
...comparison.equalities.map((indices)=>comparison.lBranches[indices[0]]),
|
|
55
|
-
...comparison.lExtendsR.map((lIndex)=>comparison.lBranches[lIndex]),
|
|
56
|
-
...comparison.rExtendsL.map((rIndex)=>comparison.rBranches[rIndex])
|
|
57
|
-
];
|
|
58
|
-
if (resultBranches.length === 0) {
|
|
59
|
-
state.addDisjoint("union", comparison.lBranches, comparison.rBranches);
|
|
60
|
-
}
|
|
61
|
-
return resultBranches.length === 1 ? resultBranches[0] : resultBranches;
|
|
62
|
-
};
|
|
63
|
-
const predicateUnion = (domain, l, r, type)=>{
|
|
64
|
-
const state = new _composeJs.IntersectionState(type, "|");
|
|
65
|
-
const comparison = comparePredicates(l, r, state);
|
|
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
|
-
// and can be simplified to a non-literal boolean.
|
|
69
|
-
domain === "boolean" ? true : [
|
|
70
|
-
emptyRulesIfTrue(l),
|
|
71
|
-
emptyRulesIfTrue(r)
|
|
72
|
-
];
|
|
73
|
-
}
|
|
74
|
-
const resultBranches = [
|
|
75
|
-
...comparison.lBranches.filter((_, lIndex)=>!comparison.lExtendsR.includes(lIndex) && !comparison.equalities.some((indexPair)=>indexPair[0] === lIndex)),
|
|
76
|
-
...comparison.rBranches.filter((_, rIndex)=>!comparison.rExtendsL.includes(rIndex) && !comparison.equalities.some((indexPair)=>indexPair[1] === rIndex))
|
|
77
|
-
];
|
|
78
|
-
return resultBranches.length === 1 ? resultBranches[0] : resultBranches;
|
|
79
|
-
};
|
|
80
|
-
const flattenPredicate = (predicate, context)=>{
|
|
81
|
-
if (predicate === true) {
|
|
82
|
-
return [];
|
|
83
|
-
}
|
|
84
|
-
return (0, _objectKindsJs.isArray)(predicate) ? (0, _discriminateJs.flattenBranches)(predicate, context) : (0, _branchJs.flattenBranch)(predicate, context);
|
|
85
|
-
};
|
|
86
|
-
const isLiteralCondition = (predicate)=>typeof predicate === "object" && "value" in predicate;
|
|
@@ -1,25 +0,0 @@
|
|
|
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
|
-
classIntersection: ()=>classIntersection,
|
|
13
|
-
checkClass: ()=>checkClass
|
|
14
|
-
});
|
|
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
|
-
});
|
|
20
|
-
const checkClass = (expectedClass, state)=>{
|
|
21
|
-
if (typeof expectedClass === "string") {
|
|
22
|
-
return (0, _objectKindsJs.objectKindOf)(state.data) === expectedClass || !state.problems.add("class", expectedClass);
|
|
23
|
-
}
|
|
24
|
-
return state.data instanceof expectedClass || !state.problems.add("class", expectedClass);
|
|
25
|
-
};
|
|
@@ -1,48 +0,0 @@
|
|
|
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
|
-
collapsibleListUnion: ()=>collapsibleListUnion,
|
|
13
|
-
listUnion: ()=>listUnion
|
|
14
|
-
});
|
|
15
|
-
const _composeJs = require("../compose.js");
|
|
16
|
-
const collapsibleListUnion = (l, r)=>{
|
|
17
|
-
if (Array.isArray(l)) {
|
|
18
|
-
if (Array.isArray(r)) {
|
|
19
|
-
const result = listUnion(l, r);
|
|
20
|
-
return result.length === l.length ? result.length === r.length ? (0, _composeJs.equality)() : l : result.length === r.length ? r : result;
|
|
21
|
-
}
|
|
22
|
-
return l.includes(r) ? l : [
|
|
23
|
-
...l,
|
|
24
|
-
r
|
|
25
|
-
];
|
|
26
|
-
}
|
|
27
|
-
if (Array.isArray(r)) {
|
|
28
|
-
return r.includes(l) ? r : [
|
|
29
|
-
...r,
|
|
30
|
-
l
|
|
31
|
-
];
|
|
32
|
-
}
|
|
33
|
-
return l === r ? (0, _composeJs.equality)() : [
|
|
34
|
-
l,
|
|
35
|
-
r
|
|
36
|
-
];
|
|
37
|
-
};
|
|
38
|
-
const listUnion = (l, r)=>{
|
|
39
|
-
const result = [
|
|
40
|
-
...l
|
|
41
|
-
];
|
|
42
|
-
for (const expression of r){
|
|
43
|
-
if (!l.includes(expression)) {
|
|
44
|
-
result.push(expression);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return result;
|
|
48
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
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
|
-
divisorIntersection: ()=>divisorIntersection,
|
|
13
|
-
checkDivisor: ()=>checkDivisor
|
|
14
|
-
});
|
|
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
|
-
// https://en.wikipedia.org/wiki/Euclidean_algorithm
|
|
18
|
-
const greatestCommonDivisor = (l, r)=>{
|
|
19
|
-
let previous;
|
|
20
|
-
let greatestCommonDivisor = l;
|
|
21
|
-
let current = r;
|
|
22
|
-
while(current !== 0){
|
|
23
|
-
previous = current;
|
|
24
|
-
current = greatestCommonDivisor % current;
|
|
25
|
-
greatestCommonDivisor = previous;
|
|
26
|
-
}
|
|
27
|
-
return greatestCommonDivisor;
|
|
28
|
-
};
|
|
29
|
-
const checkDivisor = (divisor, state)=>state.data % divisor === 0 || !state.problems.add("divisor", divisor);
|