arktype 1.0.16-alpha → 1.0.18-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 +3 -3
- package/dist/cjs/main.js +38 -0
- package/dist/cjs/nodes/branch.js +140 -0
- package/dist/cjs/nodes/compose.js +157 -0
- package/dist/{nodes → cjs/nodes}/discriminate.js +92 -100
- package/dist/cjs/nodes/node.js +139 -0
- package/dist/cjs/nodes/predicate.js +86 -0
- package/dist/cjs/nodes/rules/class.js +25 -0
- package/dist/cjs/nodes/rules/collapsibleSet.js +48 -0
- package/dist/cjs/nodes/rules/divisor.js +29 -0
- package/dist/cjs/nodes/rules/props.js +160 -0
- package/dist/cjs/nodes/rules/range.js +105 -0
- package/dist/cjs/nodes/rules/regex.js +26 -0
- package/dist/cjs/nodes/rules/rules.js +123 -0
- package/dist/cjs/parse/ast/ast.js +4 -0
- package/dist/cjs/parse/ast/bound.js +16 -0
- package/dist/cjs/parse/ast/config.js +13 -0
- package/dist/cjs/parse/ast/distributableFunction.js +48 -0
- package/dist/cjs/parse/ast/divisor.js +9 -0
- package/dist/cjs/parse/ast/intersection.js +30 -0
- package/dist/cjs/parse/ast/keyof.js +111 -0
- package/dist/cjs/parse/ast/morph.js +58 -0
- package/dist/cjs/parse/ast/narrow.js +22 -0
- package/dist/cjs/parse/ast/node.js +4 -0
- package/dist/cjs/parse/ast/tuple.js +94 -0
- package/dist/cjs/parse/ast/union.js +9 -0
- package/dist/cjs/parse/ast/utils.js +4 -0
- package/dist/cjs/parse/definition.js +61 -0
- package/dist/cjs/parse/record.js +37 -0
- package/dist/cjs/parse/string/reduce/dynamic.js +167 -0
- package/dist/cjs/parse/string/reduce/shared.js +23 -0
- package/dist/cjs/parse/string/reduce/static.js +4 -0
- package/dist/cjs/parse/string/shift/operand/enclosed.js +54 -0
- package/dist/cjs/parse/string/shift/operand/operand.js +11 -0
- package/dist/cjs/parse/string/shift/operand/unenclosed.js +53 -0
- package/dist/cjs/parse/string/shift/operator/bounds.js +87 -0
- package/dist/cjs/parse/string/shift/operator/divisor.js +35 -0
- package/dist/cjs/parse/string/shift/operator/operator.js +26 -0
- package/dist/cjs/parse/string/shift/scanner.js +114 -0
- package/dist/cjs/parse/string/string.js +43 -0
- package/dist/cjs/scopes/ark.js +45 -0
- package/dist/cjs/scopes/cache.js +52 -0
- package/dist/cjs/scopes/expressions.js +29 -0
- package/dist/cjs/scopes/jsObjects.js +93 -0
- package/dist/cjs/scopes/scope.js +323 -0
- package/dist/cjs/scopes/tsKeywords.js +113 -0
- package/dist/cjs/scopes/type.js +50 -0
- package/dist/cjs/scopes/validation/creditCard.js +47 -0
- package/dist/cjs/scopes/validation/date.js +62 -0
- package/dist/cjs/scopes/validation/validation.js +108 -0
- package/dist/cjs/traverse/problems.js +281 -0
- package/dist/cjs/traverse/traverse.js +390 -0
- package/dist/cjs/utils/chainableNoOpProxy.js +23 -0
- package/dist/cjs/utils/data.js +53 -0
- package/dist/cjs/utils/domains.js +30 -0
- package/dist/cjs/utils/errors.js +26 -0
- package/dist/cjs/utils/freeze.js +15 -0
- package/dist/cjs/utils/generics.js +63 -0
- package/dist/cjs/utils/numericLiterals.js +75 -0
- package/dist/cjs/utils/objectKinds.js +69 -0
- package/dist/cjs/utils/paths.js +32 -0
- package/dist/cjs/utils/serialize.js +74 -0
- package/dist/cjs/utils/unionToTuple.js +4 -0
- package/dist/mjs/main.js +8 -0
- package/dist/mjs/nodes/branch.js +123 -0
- package/dist/mjs/nodes/compose.js +135 -0
- package/dist/mjs/nodes/discriminate.js +247 -0
- package/dist/mjs/nodes/node.js +117 -0
- package/dist/mjs/nodes/predicate.js +69 -0
- package/dist/mjs/nodes/rules/class.js +11 -0
- package/dist/mjs/nodes/rules/collapsibleSet.js +34 -0
- package/dist/mjs/nodes/rules/divisor.js +15 -0
- package/dist/mjs/nodes/rules/props.js +142 -0
- package/dist/mjs/nodes/rules/range.js +86 -0
- package/dist/mjs/nodes/rules/regex.js +11 -0
- package/dist/mjs/nodes/rules/rules.js +106 -0
- package/dist/mjs/package.json +3 -0
- package/dist/mjs/parse/ast/ast.js +1 -0
- package/dist/mjs/parse/ast/bound.js +2 -0
- package/dist/mjs/parse/ast/config.js +9 -0
- package/dist/mjs/parse/ast/distributableFunction.js +34 -0
- package/dist/mjs/parse/ast/divisor.js +1 -0
- package/dist/mjs/parse/ast/intersection.js +16 -0
- package/dist/mjs/parse/ast/keyof.js +103 -0
- package/dist/mjs/parse/ast/morph.js +44 -0
- package/dist/mjs/parse/ast/narrow.js +14 -0
- package/dist/mjs/parse/ast/node.js +1 -0
- package/dist/mjs/parse/ast/tuple.js +80 -0
- package/dist/mjs/parse/ast/union.js +1 -0
- package/dist/mjs/parse/ast/utils.js +1 -0
- package/dist/mjs/parse/definition.js +46 -0
- package/dist/mjs/parse/record.js +29 -0
- package/dist/mjs/parse/string/reduce/dynamic.js +159 -0
- package/dist/mjs/parse/string/reduce/shared.js +6 -0
- package/dist/mjs/parse/string/reduce/static.js +1 -0
- package/dist/mjs/parse/string/shift/operand/enclosed.js +39 -0
- package/dist/mjs/parse/string/shift/operand/operand.js +3 -0
- package/dist/mjs/parse/string/shift/operand/unenclosed.js +36 -0
- package/dist/mjs/parse/string/shift/operator/bounds.js +70 -0
- package/dist/mjs/parse/string/shift/operator/divisor.js +21 -0
- package/dist/mjs/parse/string/shift/operator/operator.js +13 -0
- package/dist/mjs/parse/string/shift/scanner.js +106 -0
- package/dist/mjs/parse/string/string.js +28 -0
- package/dist/mjs/scopes/ark.js +28 -0
- package/dist/mjs/scopes/cache.js +38 -0
- package/dist/{scopes → mjs/scopes}/expressions.js +9 -20
- package/dist/mjs/scopes/jsObjects.js +82 -0
- package/dist/mjs/scopes/scope.js +303 -0
- package/dist/mjs/scopes/tsKeywords.js +116 -0
- package/dist/mjs/scopes/type.js +35 -0
- package/dist/{scopes → mjs/scopes}/validation/creditCard.js +11 -15
- package/dist/{scopes → mjs/scopes}/validation/date.js +16 -21
- package/dist/mjs/scopes/validation/validation.js +112 -0
- package/dist/mjs/traverse/problems.js +260 -0
- package/dist/mjs/traverse/traverse.js +373 -0
- package/dist/{utils → mjs/utils}/chainableNoOpProxy.js +2 -6
- package/dist/mjs/utils/data.js +38 -0
- package/dist/mjs/utils/domains.js +15 -0
- package/dist/mjs/utils/errors.js +10 -0
- package/dist/mjs/utils/freeze.js +7 -0
- package/dist/mjs/utils/generics.js +38 -0
- package/dist/mjs/utils/numericLiterals.js +72 -0
- package/dist/mjs/utils/objectKinds.js +55 -0
- package/dist/{utils → mjs/utils}/paths.js +3 -8
- package/dist/mjs/utils/serialize.js +58 -0
- package/dist/mjs/utils/unionToTuple.js +1 -0
- package/dist/tsconfig.temp.tsbuildinfo +1 -1
- package/package.json +14 -6
- package/dist/main.js +0 -29
- package/dist/nodes/branch.js +0 -135
- package/dist/nodes/compose.js +0 -99
- package/dist/nodes/node.js +0 -134
- package/dist/nodes/predicate.js +0 -88
- package/dist/nodes/rules/class.js +0 -23
- package/dist/nodes/rules/collapsibleSet.js +0 -34
- package/dist/nodes/rules/divisor.js +0 -19
- package/dist/nodes/rules/props.js +0 -130
- package/dist/nodes/rules/range.js +0 -108
- package/dist/nodes/rules/regex.js +0 -17
- package/dist/nodes/rules/rules.js +0 -102
- package/dist/parse/ast/ast.js +0 -2
- package/dist/parse/ast/bound.js +0 -7
- package/dist/parse/ast/config.js +0 -14
- package/dist/parse/ast/distributableFunction.js +0 -40
- package/dist/parse/ast/divisor.js +0 -5
- package/dist/parse/ast/intersection.js +0 -21
- package/dist/parse/ast/keyof.js +0 -107
- package/dist/parse/ast/morph.js +0 -50
- package/dist/parse/ast/narrow.js +0 -17
- package/dist/parse/ast/node.js +0 -2
- package/dist/parse/ast/tuple.js +0 -72
- package/dist/parse/ast/union.js +0 -5
- package/dist/parse/ast/utils.js +0 -2
- package/dist/parse/definition.js +0 -47
- package/dist/parse/record.js +0 -31
- package/dist/parse/string/reduce/dynamic.js +0 -159
- package/dist/parse/string/reduce/shared.js +0 -13
- package/dist/parse/string/reduce/static.js +0 -2
- package/dist/parse/string/shift/operand/enclosed.js +0 -37
- package/dist/parse/string/shift/operand/operand.js +0 -15
- package/dist/parse/string/shift/operand/unenclosed.js +0 -45
- package/dist/parse/string/shift/operator/bounds.js +0 -83
- package/dist/parse/string/shift/operator/divisor.js +0 -23
- package/dist/parse/string/shift/operator/operator.js +0 -34
- package/dist/parse/string/shift/scanner.js +0 -97
- package/dist/parse/string/string.js +0 -35
- package/dist/scopes/ark.js +0 -27
- package/dist/scopes/cache.js +0 -28
- package/dist/scopes/jsObjects.js +0 -20
- package/dist/scopes/scope.js +0 -184
- package/dist/scopes/tsKeywords.js +0 -49
- package/dist/scopes/type.js +0 -40
- package/dist/scopes/validation/validation.js +0 -74
- package/dist/traverse/problems.js +0 -234
- package/dist/traverse/traverse.js +0 -330
- package/dist/utils/data.js +0 -39
- package/dist/utils/domains.js +0 -27
- package/dist/utils/errors.js +0 -17
- package/dist/utils/freeze.js +0 -16
- package/dist/utils/generics.js +0 -53
- package/dist/utils/numericLiterals.js +0 -88
- package/dist/utils/objectKinds.js +0 -69
- package/dist/utils/serialize.js +0 -71
- package/dist/utils/unionToTuple.js +0 -2
- /package/dist/{package.json → cjs/package.json} +0 -0
- /package/dist/{main.d.ts → types/main.d.ts} +0 -0
- /package/dist/{nodes → types/nodes}/branch.d.ts +0 -0
- /package/dist/{nodes → types/nodes}/compose.d.ts +0 -0
- /package/dist/{nodes → types/nodes}/discriminate.d.ts +0 -0
- /package/dist/{nodes → types/nodes}/node.d.ts +0 -0
- /package/dist/{nodes → types/nodes}/predicate.d.ts +0 -0
- /package/dist/{nodes → types/nodes}/rules/class.d.ts +0 -0
- /package/dist/{nodes → types/nodes}/rules/collapsibleSet.d.ts +0 -0
- /package/dist/{nodes → types/nodes}/rules/divisor.d.ts +0 -0
- /package/dist/{nodes → types/nodes}/rules/props.d.ts +0 -0
- /package/dist/{nodes → types/nodes}/rules/range.d.ts +0 -0
- /package/dist/{nodes → types/nodes}/rules/regex.d.ts +0 -0
- /package/dist/{nodes → types/nodes}/rules/rules.d.ts +0 -0
- /package/dist/{parse → types/parse}/ast/ast.d.ts +0 -0
- /package/dist/{parse → types/parse}/ast/bound.d.ts +0 -0
- /package/dist/{parse → types/parse}/ast/config.d.ts +0 -0
- /package/dist/{parse → types/parse}/ast/distributableFunction.d.ts +0 -0
- /package/dist/{parse → types/parse}/ast/divisor.d.ts +0 -0
- /package/dist/{parse → types/parse}/ast/intersection.d.ts +0 -0
- /package/dist/{parse → types/parse}/ast/keyof.d.ts +0 -0
- /package/dist/{parse → types/parse}/ast/morph.d.ts +0 -0
- /package/dist/{parse → types/parse}/ast/narrow.d.ts +0 -0
- /package/dist/{parse → types/parse}/ast/node.d.ts +0 -0
- /package/dist/{parse → types/parse}/ast/tuple.d.ts +0 -0
- /package/dist/{parse → types/parse}/ast/union.d.ts +0 -0
- /package/dist/{parse → types/parse}/ast/utils.d.ts +0 -0
- /package/dist/{parse → types/parse}/definition.d.ts +0 -0
- /package/dist/{parse → types/parse}/record.d.ts +0 -0
- /package/dist/{parse → types/parse}/string/reduce/dynamic.d.ts +0 -0
- /package/dist/{parse → types/parse}/string/reduce/shared.d.ts +0 -0
- /package/dist/{parse → types/parse}/string/reduce/static.d.ts +0 -0
- /package/dist/{parse → types/parse}/string/shift/operand/enclosed.d.ts +0 -0
- /package/dist/{parse → types/parse}/string/shift/operand/operand.d.ts +0 -0
- /package/dist/{parse → types/parse}/string/shift/operand/unenclosed.d.ts +0 -0
- /package/dist/{parse → types/parse}/string/shift/operator/bounds.d.ts +0 -0
- /package/dist/{parse → types/parse}/string/shift/operator/divisor.d.ts +0 -0
- /package/dist/{parse → types/parse}/string/shift/operator/operator.d.ts +0 -0
- /package/dist/{parse → types/parse}/string/shift/scanner.d.ts +0 -0
- /package/dist/{parse → types/parse}/string/string.d.ts +0 -0
- /package/dist/{scopes → types/scopes}/ark.d.ts +0 -0
- /package/dist/{scopes → types/scopes}/cache.d.ts +0 -0
- /package/dist/{scopes → types/scopes}/expressions.d.ts +0 -0
- /package/dist/{scopes → types/scopes}/jsObjects.d.ts +0 -0
- /package/dist/{scopes → types/scopes}/scope.d.ts +0 -0
- /package/dist/{scopes → types/scopes}/tsKeywords.d.ts +0 -0
- /package/dist/{scopes → types/scopes}/type.d.ts +0 -0
- /package/dist/{scopes → types/scopes}/validation/creditCard.d.ts +0 -0
- /package/dist/{scopes → types/scopes}/validation/date.d.ts +0 -0
- /package/dist/{scopes → types/scopes}/validation/validation.d.ts +0 -0
- /package/dist/{traverse → types/traverse}/problems.d.ts +0 -0
- /package/dist/{traverse → types/traverse}/traverse.d.ts +0 -0
- /package/dist/{utils → types/utils}/chainableNoOpProxy.d.ts +0 -0
- /package/dist/{utils → types/utils}/data.d.ts +0 -0
- /package/dist/{utils → types/utils}/domains.d.ts +0 -0
- /package/dist/{utils → types/utils}/errors.d.ts +0 -0
- /package/dist/{utils → types/utils}/freeze.d.ts +0 -0
- /package/dist/{utils → types/utils}/generics.d.ts +0 -0
- /package/dist/{utils → types/utils}/numericLiterals.d.ts +0 -0
- /package/dist/{utils → types/utils}/objectKinds.d.ts +0 -0
- /package/dist/{utils → types/utils}/paths.d.ts +0 -0
- /package/dist/{utils → types/utils}/serialize.d.ts +0 -0
- /package/dist/{utils → types/utils}/unionToTuple.d.ts +0 -0
package/dist/nodes/compose.js
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.composeKeyedIntersection = exports.isEquality = exports.equality = exports.isDisjoint = exports.anonymousDisjoint = exports.IntersectionState = exports.stringifyRange = exports.disjointDescriptionWriters = exports.undefinedOperandsMessage = exports.composeIntersection = void 0;
|
|
4
|
-
const errors_js_1 = require("../utils/errors.js");
|
|
5
|
-
const generics_js_1 = require("../utils/generics.js");
|
|
6
|
-
const paths_js_1 = require("../utils/paths.js");
|
|
7
|
-
const serialize_js_1 = require("../utils/serialize.js");
|
|
8
|
-
const composeIntersection = (reducer) => ((l, r, state) => l === undefined
|
|
9
|
-
? r === undefined
|
|
10
|
-
? (0, errors_js_1.throwInternalError)(exports.undefinedOperandsMessage)
|
|
11
|
-
: r
|
|
12
|
-
: r === undefined
|
|
13
|
-
? l
|
|
14
|
-
: reducer(l, r, state));
|
|
15
|
-
exports.composeIntersection = composeIntersection;
|
|
16
|
-
exports.undefinedOperandsMessage = `Unexpected operation two undefined operands`;
|
|
17
|
-
exports.disjointDescriptionWriters = {
|
|
18
|
-
domain: ({ l, r }) => `${l.join(", ")} and ${r.join(", ")}`,
|
|
19
|
-
range: ({ l, r }) => `${(0, exports.stringifyRange)(l)} and ${(0, exports.stringifyRange)(r)}`,
|
|
20
|
-
class: ({ l, r }) => `classes ${typeof l === "string" ? l : l.name} and ${typeof r === "string" ? r : r.name}`,
|
|
21
|
-
tupleLength: ({ l, r }) => `tuples of length ${l} and ${r}`,
|
|
22
|
-
value: ({ l, r }) => `literal values ${(0, serialize_js_1.stringify)(l)} and ${(0, serialize_js_1.stringify)(r)}`,
|
|
23
|
-
leftAssignability: ({ l, r }) => `literal value ${(0, serialize_js_1.stringify)(l.value)} and ${(0, serialize_js_1.stringify)(r)}`,
|
|
24
|
-
rightAssignability: ({ l, r }) => `literal value ${(0, serialize_js_1.stringify)(r.value)} and ${(0, serialize_js_1.stringify)(l)}`,
|
|
25
|
-
union: ({ l, r }) => `branches ${(0, serialize_js_1.stringify)(l)} and branches ${(0, serialize_js_1.stringify)(r)}`
|
|
26
|
-
};
|
|
27
|
-
const stringifyRange = (range) => "limit" in range
|
|
28
|
-
? `the range of exactly ${range.limit}`
|
|
29
|
-
: range.min
|
|
30
|
-
? range.max
|
|
31
|
-
? `the range bounded by ${range.min.comparator}${range.min.limit} and ${range.max.comparator}${range.max.limit}`
|
|
32
|
-
: `${range.min.comparator}${range.min.limit}`
|
|
33
|
-
: range.max
|
|
34
|
-
? `${range.max.comparator}${range.max.limit}`
|
|
35
|
-
: "the unbounded range";
|
|
36
|
-
exports.stringifyRange = stringifyRange;
|
|
37
|
-
class IntersectionState {
|
|
38
|
-
type;
|
|
39
|
-
lastOperator;
|
|
40
|
-
path = new paths_js_1.Path();
|
|
41
|
-
domain;
|
|
42
|
-
#disjoints = {};
|
|
43
|
-
constructor(type, lastOperator) {
|
|
44
|
-
this.type = type;
|
|
45
|
-
this.lastOperator = lastOperator;
|
|
46
|
-
}
|
|
47
|
-
get disjoints() {
|
|
48
|
-
return this.#disjoints;
|
|
49
|
-
}
|
|
50
|
-
addDisjoint(kind, l, r) {
|
|
51
|
-
this.#disjoints[`${this.path}`] = { kind, l, r };
|
|
52
|
-
return empty;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
exports.IntersectionState = IntersectionState;
|
|
56
|
-
const empty = Symbol("empty");
|
|
57
|
-
const anonymousDisjoint = () => empty;
|
|
58
|
-
exports.anonymousDisjoint = anonymousDisjoint;
|
|
59
|
-
const isDisjoint = (result) => result === empty;
|
|
60
|
-
exports.isDisjoint = isDisjoint;
|
|
61
|
-
const equal = Symbol("equal");
|
|
62
|
-
const equality = () => equal;
|
|
63
|
-
exports.equality = equality;
|
|
64
|
-
const isEquality = (result) => result === equal;
|
|
65
|
-
exports.isEquality = isEquality;
|
|
66
|
-
const composeKeyedIntersection = (reducer, config) => (l, r, state) => {
|
|
67
|
-
const result = {};
|
|
68
|
-
const keys = (0, generics_js_1.objectKeysOf)({ ...l, ...r });
|
|
69
|
-
let lImpliesR = true;
|
|
70
|
-
let rImpliesL = true;
|
|
71
|
-
for (const k of keys) {
|
|
72
|
-
const keyResult = typeof reducer === "function"
|
|
73
|
-
? reducer(k, l[k], r[k], state)
|
|
74
|
-
: reducer[k](l[k], r[k], state);
|
|
75
|
-
if ((0, exports.isEquality)(keyResult)) {
|
|
76
|
-
if (l[k] !== undefined) {
|
|
77
|
-
result[k] = l[k];
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
else if ((0, exports.isDisjoint)(keyResult)) {
|
|
81
|
-
if (config.onEmpty === "omit") {
|
|
82
|
-
lImpliesR = false;
|
|
83
|
-
rImpliesL = false;
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
return empty;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
if (keyResult !== undefined) {
|
|
91
|
-
result[k] = keyResult;
|
|
92
|
-
}
|
|
93
|
-
lImpliesR &&= keyResult === l[k];
|
|
94
|
-
rImpliesL &&= keyResult === r[k];
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return lImpliesR ? (rImpliesL ? (0, exports.equality)() : l) : rImpliesL ? r : result;
|
|
98
|
-
};
|
|
99
|
-
exports.composeKeyedIntersection = composeKeyedIntersection;
|
package/dist/nodes/node.js
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toArrayNode = exports.resolutionExtendsDomain = exports.isLiteralNode = exports.flattenTypeNode = exports.flattenNode = exports.flattenType = exports.rootUnion = exports.rootIntersection = exports.nodeIntersection = exports.isConfigNode = void 0;
|
|
4
|
-
const intersection_js_1 = require("../parse/ast/intersection.js");
|
|
5
|
-
const errors_js_1 = require("../utils/errors.js");
|
|
6
|
-
const generics_js_1 = require("../utils/generics.js");
|
|
7
|
-
const paths_js_1 = require("../utils/paths.js");
|
|
8
|
-
const compose_js_1 = require("./compose.js");
|
|
9
|
-
const predicate_js_1 = require("./predicate.js");
|
|
10
|
-
const props_js_1 = require("./rules/props.js");
|
|
11
|
-
const isConfigNode = (node) => "config" in node;
|
|
12
|
-
exports.isConfigNode = isConfigNode;
|
|
13
|
-
const nodeIntersection = (l, r, state) => {
|
|
14
|
-
state.domain = undefined;
|
|
15
|
-
const lDomains = state.type.scope.resolveTypeNode(l);
|
|
16
|
-
const rDomains = state.type.scope.resolveTypeNode(r);
|
|
17
|
-
const result = typeNodeIntersection(lDomains, rDomains, state);
|
|
18
|
-
if (typeof result === "object" && !(0, generics_js_1.hasKeys)(result)) {
|
|
19
|
-
return (0, generics_js_1.hasKeys)(state.disjoints)
|
|
20
|
-
? (0, compose_js_1.anonymousDisjoint)()
|
|
21
|
-
: state.addDisjoint("domain", (0, generics_js_1.objectKeysOf)(lDomains), (0, generics_js_1.objectKeysOf)(rDomains));
|
|
22
|
-
}
|
|
23
|
-
return result === lDomains ? l : result === rDomains ? r : result;
|
|
24
|
-
};
|
|
25
|
-
exports.nodeIntersection = nodeIntersection;
|
|
26
|
-
const typeNodeIntersection = (0, compose_js_1.composeKeyedIntersection)((domain, l, r, context) => {
|
|
27
|
-
if (l === undefined) {
|
|
28
|
-
return r === undefined
|
|
29
|
-
? (0, errors_js_1.throwInternalError)(compose_js_1.undefinedOperandsMessage)
|
|
30
|
-
: undefined;
|
|
31
|
-
}
|
|
32
|
-
if (r === undefined) {
|
|
33
|
-
return undefined;
|
|
34
|
-
}
|
|
35
|
-
return (0, predicate_js_1.predicateIntersection)(domain, l, r, context);
|
|
36
|
-
}, { onEmpty: "omit" });
|
|
37
|
-
const rootIntersection = (l, r, type) => {
|
|
38
|
-
const state = new compose_js_1.IntersectionState(type, "&");
|
|
39
|
-
const result = (0, exports.nodeIntersection)(l, r, state);
|
|
40
|
-
return (0, compose_js_1.isDisjoint)(result)
|
|
41
|
-
? (0, errors_js_1.throwParseError)((0, intersection_js_1.compileDisjointReasonsMessage)(state.disjoints))
|
|
42
|
-
: (0, compose_js_1.isEquality)(result)
|
|
43
|
-
? l
|
|
44
|
-
: result;
|
|
45
|
-
};
|
|
46
|
-
exports.rootIntersection = rootIntersection;
|
|
47
|
-
const rootUnion = (l, r, type) => {
|
|
48
|
-
const lDomains = type.scope.resolveTypeNode(l);
|
|
49
|
-
const rDomains = type.scope.resolveTypeNode(r);
|
|
50
|
-
const result = {};
|
|
51
|
-
const domains = (0, generics_js_1.objectKeysOf)({ ...lDomains, ...rDomains });
|
|
52
|
-
for (const domain of domains) {
|
|
53
|
-
result[domain] = (0, generics_js_1.hasKey)(lDomains, domain)
|
|
54
|
-
? (0, generics_js_1.hasKey)(rDomains, domain)
|
|
55
|
-
? (0, predicate_js_1.predicateUnion)(domain, lDomains[domain], rDomains[domain], type)
|
|
56
|
-
: lDomains[domain]
|
|
57
|
-
: (0, generics_js_1.hasKey)(rDomains, domain)
|
|
58
|
-
? rDomains[domain]
|
|
59
|
-
: (0, errors_js_1.throwInternalError)(compose_js_1.undefinedOperandsMessage);
|
|
60
|
-
}
|
|
61
|
-
return result;
|
|
62
|
-
};
|
|
63
|
-
exports.rootUnion = rootUnion;
|
|
64
|
-
const hasImpliedDomain = (flatPredicate) => flatPredicate[0] &&
|
|
65
|
-
(flatPredicate[0][0] === "value" || flatPredicate[0][0] === "class");
|
|
66
|
-
const flattenType = (type) => {
|
|
67
|
-
const ctx = {
|
|
68
|
-
type,
|
|
69
|
-
path: new paths_js_1.Path(),
|
|
70
|
-
lastDomain: "undefined"
|
|
71
|
-
};
|
|
72
|
-
return (0, exports.flattenNode)(type.node, ctx);
|
|
73
|
-
};
|
|
74
|
-
exports.flattenType = flattenType;
|
|
75
|
-
const flattenNode = (node, ctx) => {
|
|
76
|
-
if (typeof node === "string") {
|
|
77
|
-
return ctx.type.scope.resolve(node).flat;
|
|
78
|
-
}
|
|
79
|
-
const hasConfig = (0, exports.isConfigNode)(node);
|
|
80
|
-
const flattenedTypeNode = (0, exports.flattenTypeNode)(hasConfig ? node.node : node, ctx);
|
|
81
|
-
return hasConfig
|
|
82
|
-
? [
|
|
83
|
-
[
|
|
84
|
-
"config",
|
|
85
|
-
{
|
|
86
|
-
config: (0, generics_js_1.entriesOf)(node.config),
|
|
87
|
-
node: flattenedTypeNode
|
|
88
|
-
}
|
|
89
|
-
]
|
|
90
|
-
]
|
|
91
|
-
: flattenedTypeNode;
|
|
92
|
-
};
|
|
93
|
-
exports.flattenNode = flattenNode;
|
|
94
|
-
const flattenTypeNode = (node, ctx) => {
|
|
95
|
-
const domains = (0, generics_js_1.objectKeysOf)(node);
|
|
96
|
-
if (domains.length === 1) {
|
|
97
|
-
const domain = domains[0];
|
|
98
|
-
const predicate = node[domain];
|
|
99
|
-
if (predicate === true) {
|
|
100
|
-
return domain;
|
|
101
|
-
}
|
|
102
|
-
ctx.lastDomain = domain;
|
|
103
|
-
const flatPredicate = (0, predicate_js_1.flattenPredicate)(predicate, ctx);
|
|
104
|
-
return hasImpliedDomain(flatPredicate)
|
|
105
|
-
? flatPredicate
|
|
106
|
-
: [["domain", domain], ...flatPredicate];
|
|
107
|
-
}
|
|
108
|
-
const result = {};
|
|
109
|
-
for (const domain of domains) {
|
|
110
|
-
ctx.lastDomain = domain;
|
|
111
|
-
result[domain] = (0, predicate_js_1.flattenPredicate)(node[domain], ctx);
|
|
112
|
-
}
|
|
113
|
-
return [["domains", result]];
|
|
114
|
-
};
|
|
115
|
-
exports.flattenTypeNode = flattenTypeNode;
|
|
116
|
-
const isLiteralNode = (node, domain) => {
|
|
117
|
-
return ((0, exports.resolutionExtendsDomain)(node, domain) &&
|
|
118
|
-
(0, predicate_js_1.isLiteralCondition)(node[domain]));
|
|
119
|
-
};
|
|
120
|
-
exports.isLiteralNode = isLiteralNode;
|
|
121
|
-
const resolutionExtendsDomain = (resolution, domain) => {
|
|
122
|
-
const domains = (0, generics_js_1.objectKeysOf)(resolution);
|
|
123
|
-
return domains.length === 1 && domains[0] === domain;
|
|
124
|
-
};
|
|
125
|
-
exports.resolutionExtendsDomain = resolutionExtendsDomain;
|
|
126
|
-
const toArrayNode = (node) => ({
|
|
127
|
-
object: {
|
|
128
|
-
class: Array,
|
|
129
|
-
props: {
|
|
130
|
-
[props_js_1.mappedKeys.index]: node
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
});
|
|
134
|
-
exports.toArrayNode = toArrayNode;
|
package/dist/nodes/predicate.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isLiteralCondition = exports.flattenPredicate = exports.predicateUnion = exports.predicateIntersection = exports.comparePredicates = void 0;
|
|
4
|
-
const generics_js_1 = require("../utils/generics.js");
|
|
5
|
-
const objectKinds_js_1 = require("../utils/objectKinds.js");
|
|
6
|
-
const branch_js_1 = require("./branch.js");
|
|
7
|
-
const compose_js_1 = require("./compose.js");
|
|
8
|
-
const discriminate_js_1 = require("./discriminate.js");
|
|
9
|
-
const emptyRulesIfTrue = (predicate) => (predicate === true ? {} : predicate);
|
|
10
|
-
const comparePredicates = (l, r, context) => {
|
|
11
|
-
if (l === true && r === true) {
|
|
12
|
-
return (0, compose_js_1.equality)();
|
|
13
|
-
}
|
|
14
|
-
if (!(0, objectKinds_js_1.isArray)(l) && !(0, objectKinds_js_1.isArray)(r)) {
|
|
15
|
-
const result = (0, branch_js_1.branchIntersection)(emptyRulesIfTrue(l), emptyRulesIfTrue(r), context);
|
|
16
|
-
return result === l ? l : result === r ? r : result;
|
|
17
|
-
}
|
|
18
|
-
const lBranches = (0, generics_js_1.listFrom)(emptyRulesIfTrue(l));
|
|
19
|
-
const rBranches = (0, generics_js_1.listFrom)(emptyRulesIfTrue(r));
|
|
20
|
-
const comparison = (0, branch_js_1.compareBranches)(lBranches, rBranches, context);
|
|
21
|
-
if (comparison.equalities.length === lBranches.length &&
|
|
22
|
-
comparison.equalities.length === rBranches.length) {
|
|
23
|
-
return (0, compose_js_1.equality)();
|
|
24
|
-
}
|
|
25
|
-
if (comparison.lExtendsR.length + comparison.equalities.length ===
|
|
26
|
-
lBranches.length) {
|
|
27
|
-
return l;
|
|
28
|
-
}
|
|
29
|
-
if (comparison.rExtendsL.length + comparison.equalities.length ===
|
|
30
|
-
rBranches.length) {
|
|
31
|
-
return r;
|
|
32
|
-
}
|
|
33
|
-
return comparison;
|
|
34
|
-
};
|
|
35
|
-
exports.comparePredicates = comparePredicates;
|
|
36
|
-
const predicateIntersection = (domain, l, r, state) => {
|
|
37
|
-
state.domain = domain;
|
|
38
|
-
const comparison = (0, exports.comparePredicates)(l, r, state);
|
|
39
|
-
if (!(0, branch_js_1.isBranchComparison)(comparison)) {
|
|
40
|
-
return comparison;
|
|
41
|
-
}
|
|
42
|
-
const resultBranches = [
|
|
43
|
-
...comparison.distinctIntersections,
|
|
44
|
-
...comparison.equalities.map((indices) => comparison.lBranches[indices[0]]),
|
|
45
|
-
...comparison.lExtendsR.map((lIndex) => comparison.lBranches[lIndex]),
|
|
46
|
-
...comparison.rExtendsL.map((rIndex) => comparison.rBranches[rIndex])
|
|
47
|
-
];
|
|
48
|
-
if (resultBranches.length === 0) {
|
|
49
|
-
state.addDisjoint("union", comparison.lBranches, comparison.rBranches);
|
|
50
|
-
}
|
|
51
|
-
return resultBranches.length === 1 ? resultBranches[0] : resultBranches;
|
|
52
|
-
};
|
|
53
|
-
exports.predicateIntersection = predicateIntersection;
|
|
54
|
-
const predicateUnion = (domain, l, r, type) => {
|
|
55
|
-
const state = new compose_js_1.IntersectionState(type, "|");
|
|
56
|
-
const comparison = (0, exports.comparePredicates)(l, r, state);
|
|
57
|
-
if (!(0, branch_js_1.isBranchComparison)(comparison)) {
|
|
58
|
-
return (0, compose_js_1.isEquality)(comparison) || comparison === l
|
|
59
|
-
? r
|
|
60
|
-
: comparison === r
|
|
61
|
-
? l
|
|
62
|
-
: // if a boolean has multiple branches, neither of which is a
|
|
63
|
-
// subtype of the other, it consists of two opposite literals
|
|
64
|
-
// and can be simplified to a non-literal boolean.
|
|
65
|
-
domain === "boolean"
|
|
66
|
-
? true
|
|
67
|
-
: [emptyRulesIfTrue(l), emptyRulesIfTrue(r)];
|
|
68
|
-
}
|
|
69
|
-
const resultBranches = [
|
|
70
|
-
...comparison.lBranches.filter((_, lIndex) => !comparison.lExtendsR.includes(lIndex) &&
|
|
71
|
-
!comparison.equalities.some((indexPair) => indexPair[0] === lIndex)),
|
|
72
|
-
...comparison.rBranches.filter((_, rIndex) => !comparison.rExtendsL.includes(rIndex) &&
|
|
73
|
-
!comparison.equalities.some((indexPair) => indexPair[1] === rIndex))
|
|
74
|
-
];
|
|
75
|
-
return resultBranches.length === 1 ? resultBranches[0] : resultBranches;
|
|
76
|
-
};
|
|
77
|
-
exports.predicateUnion = predicateUnion;
|
|
78
|
-
const flattenPredicate = (predicate, context) => {
|
|
79
|
-
if (predicate === true) {
|
|
80
|
-
return [];
|
|
81
|
-
}
|
|
82
|
-
return (0, objectKinds_js_1.isArray)(predicate)
|
|
83
|
-
? (0, discriminate_js_1.flattenBranches)(predicate, context)
|
|
84
|
-
: (0, branch_js_1.flattenBranch)(predicate, context);
|
|
85
|
-
};
|
|
86
|
-
exports.flattenPredicate = flattenPredicate;
|
|
87
|
-
const isLiteralCondition = (predicate) => typeof predicate === "object" && "value" in predicate;
|
|
88
|
-
exports.isLiteralCondition = isLiteralCondition;
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.checkClass = exports.classIntersection = void 0;
|
|
4
|
-
const objectKinds_js_1 = require("../../utils/objectKinds.js");
|
|
5
|
-
const compose_js_1 = require("../compose.js");
|
|
6
|
-
exports.classIntersection = (0, compose_js_1.composeIntersection)((l, r, state) => {
|
|
7
|
-
return l === r
|
|
8
|
-
? (0, compose_js_1.equality)()
|
|
9
|
-
: l instanceof r
|
|
10
|
-
? l
|
|
11
|
-
: r instanceof l
|
|
12
|
-
? r
|
|
13
|
-
: state.addDisjoint("class", l, r);
|
|
14
|
-
});
|
|
15
|
-
const checkClass = (expectedClass, state) => {
|
|
16
|
-
if (typeof expectedClass === "string") {
|
|
17
|
-
return ((0, objectKinds_js_1.objectKindOf)(state.data) === expectedClass ||
|
|
18
|
-
!state.problems.add("class", expectedClass));
|
|
19
|
-
}
|
|
20
|
-
return (state.data instanceof expectedClass ||
|
|
21
|
-
!state.problems.add("class", expectedClass));
|
|
22
|
-
};
|
|
23
|
-
exports.checkClass = checkClass;
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.listUnion = exports.collapsibleListUnion = void 0;
|
|
4
|
-
const compose_js_1 = require("../compose.js");
|
|
5
|
-
const collapsibleListUnion = (l, r) => {
|
|
6
|
-
if (Array.isArray(l)) {
|
|
7
|
-
if (Array.isArray(r)) {
|
|
8
|
-
const result = (0, exports.listUnion)(l, r);
|
|
9
|
-
return result.length === l.length
|
|
10
|
-
? result.length === r.length
|
|
11
|
-
? (0, compose_js_1.equality)()
|
|
12
|
-
: l
|
|
13
|
-
: result.length === r.length
|
|
14
|
-
? r
|
|
15
|
-
: result;
|
|
16
|
-
}
|
|
17
|
-
return l.includes(r) ? l : [...l, r];
|
|
18
|
-
}
|
|
19
|
-
if (Array.isArray(r)) {
|
|
20
|
-
return r.includes(l) ? r : [...r, l];
|
|
21
|
-
}
|
|
22
|
-
return l === r ? (0, compose_js_1.equality)() : [l, r];
|
|
23
|
-
};
|
|
24
|
-
exports.collapsibleListUnion = collapsibleListUnion;
|
|
25
|
-
const listUnion = (l, r) => {
|
|
26
|
-
const result = [...l];
|
|
27
|
-
for (const expression of r) {
|
|
28
|
-
if (!l.includes(expression)) {
|
|
29
|
-
result.push(expression);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
exports.listUnion = listUnion;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.checkDivisor = exports.divisorIntersection = void 0;
|
|
4
|
-
const compose_js_1 = require("../compose.js");
|
|
5
|
-
exports.divisorIntersection = (0, compose_js_1.composeIntersection)((l, r) => l === r ? (0, compose_js_1.equality)() : Math.abs((l * r) / greatestCommonDivisor(l, r)));
|
|
6
|
-
// https://en.wikipedia.org/wiki/Euclidean_algorithm
|
|
7
|
-
const greatestCommonDivisor = (l, r) => {
|
|
8
|
-
let previous;
|
|
9
|
-
let greatestCommonDivisor = l;
|
|
10
|
-
let current = r;
|
|
11
|
-
while (current !== 0) {
|
|
12
|
-
previous = current;
|
|
13
|
-
current = greatestCommonDivisor % current;
|
|
14
|
-
greatestCommonDivisor = previous;
|
|
15
|
-
}
|
|
16
|
-
return greatestCommonDivisor;
|
|
17
|
-
};
|
|
18
|
-
const checkDivisor = (divisor, state) => state.data % divisor === 0 || !state.problems.add("divisor", divisor);
|
|
19
|
-
exports.checkDivisor = checkDivisor;
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.flattenProps = exports.propsIntersection = exports.propToNode = exports.mappedKeys = exports.isPrerequisite = exports.isOptional = void 0;
|
|
4
|
-
const compose_js_1 = require("../compose.js");
|
|
5
|
-
const node_js_1 = require("../node.js");
|
|
6
|
-
const isOptional = (prop) => prop[0] === "?";
|
|
7
|
-
exports.isOptional = isOptional;
|
|
8
|
-
const isPrerequisite = (prop) => prop[0] === "!";
|
|
9
|
-
exports.isPrerequisite = isPrerequisite;
|
|
10
|
-
exports.mappedKeys = {
|
|
11
|
-
index: "[index]"
|
|
12
|
-
};
|
|
13
|
-
const propToNode = (prop) => (0, exports.isOptional)(prop) || (0, exports.isPrerequisite)(prop) ? prop[1] : prop;
|
|
14
|
-
exports.propToNode = propToNode;
|
|
15
|
-
const getTupleLengthIfPresent = (result) => {
|
|
16
|
-
if (typeof result.length === "object" &&
|
|
17
|
-
(0, exports.isPrerequisite)(result.length) &&
|
|
18
|
-
typeof result.length[1] !== "string" &&
|
|
19
|
-
(0, node_js_1.isLiteralNode)(result.length[1], "number")) {
|
|
20
|
-
return result.length[1].number.value;
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
exports.propsIntersection = (0, compose_js_1.composeIntersection)((l, r, state) => {
|
|
24
|
-
const result = propKeysIntersection(l, r, state);
|
|
25
|
-
if (typeof result === "symbol") {
|
|
26
|
-
return result;
|
|
27
|
-
}
|
|
28
|
-
const lengthValue = getTupleLengthIfPresent(result);
|
|
29
|
-
if (lengthValue === undefined || !(exports.mappedKeys.index in result)) {
|
|
30
|
-
return result;
|
|
31
|
-
}
|
|
32
|
-
// if we are at this point, we have an array with an exact length (i.e.
|
|
33
|
-
// a tuple) and an index signature. Intersection each tuple item with
|
|
34
|
-
// the index signature node and remove the index signature via a new
|
|
35
|
-
// updated result, copied from result to avoid mutating existing references.
|
|
36
|
-
const { [exports.mappedKeys.index]: indexProp, ...updatedResult } = result;
|
|
37
|
-
const indexNode = (0, exports.propToNode)(indexProp);
|
|
38
|
-
for (let i = 0; i < lengthValue; i++) {
|
|
39
|
-
if (!updatedResult[i]) {
|
|
40
|
-
updatedResult[i] = indexNode;
|
|
41
|
-
continue;
|
|
42
|
-
}
|
|
43
|
-
const existingNodeAtIndex = (0, exports.propToNode)(updatedResult[i]);
|
|
44
|
-
state.path.push(`${i}`);
|
|
45
|
-
const updatedResultAtIndex = (0, node_js_1.nodeIntersection)(existingNodeAtIndex, indexNode, state);
|
|
46
|
-
state.path.pop();
|
|
47
|
-
if ((0, compose_js_1.isDisjoint)(updatedResultAtIndex)) {
|
|
48
|
-
return updatedResultAtIndex;
|
|
49
|
-
}
|
|
50
|
-
else if (!(0, compose_js_1.isEquality)(updatedResultAtIndex) &&
|
|
51
|
-
updatedResultAtIndex !== existingNodeAtIndex) {
|
|
52
|
-
updatedResult[i] = updatedResultAtIndex;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return updatedResult;
|
|
56
|
-
});
|
|
57
|
-
const propKeysIntersection = (0, compose_js_1.composeKeyedIntersection)((propKey, l, r, context) => {
|
|
58
|
-
if (l === undefined) {
|
|
59
|
-
return r === undefined ? (0, compose_js_1.equality)() : r;
|
|
60
|
-
}
|
|
61
|
-
if (r === undefined) {
|
|
62
|
-
return l;
|
|
63
|
-
}
|
|
64
|
-
context.path.push(propKey);
|
|
65
|
-
const result = (0, node_js_1.nodeIntersection)((0, exports.propToNode)(l), (0, exports.propToNode)(r), context);
|
|
66
|
-
context.path.pop();
|
|
67
|
-
const resultIsOptional = (0, exports.isOptional)(l) && (0, exports.isOptional)(r);
|
|
68
|
-
if ((0, compose_js_1.isDisjoint)(result) && resultIsOptional) {
|
|
69
|
-
// If an optional key has an empty intersection, the type can
|
|
70
|
-
// still be satisfied as long as the key is not included. Set
|
|
71
|
-
// the node to never rather than invalidating the type.
|
|
72
|
-
return {};
|
|
73
|
-
}
|
|
74
|
-
return result;
|
|
75
|
-
}, { onEmpty: "bubble" });
|
|
76
|
-
const flattenProps = (entries, props, ctx) => {
|
|
77
|
-
const keyConfig = ctx.type.config?.keys ?? ctx.type.scope.config.keys;
|
|
78
|
-
return keyConfig === "loose"
|
|
79
|
-
? flattenLooseProps(entries, props, ctx)
|
|
80
|
-
: flattenPropsRecord(keyConfig, entries, props, ctx);
|
|
81
|
-
};
|
|
82
|
-
exports.flattenProps = flattenProps;
|
|
83
|
-
const flattenLooseProps = (entries, props, ctx) => {
|
|
84
|
-
// if we don't care about extraneous keys, flatten props so we can iterate over the definitions directly
|
|
85
|
-
for (const k in props) {
|
|
86
|
-
const prop = props[k];
|
|
87
|
-
ctx.path.push(k);
|
|
88
|
-
if (k === exports.mappedKeys.index) {
|
|
89
|
-
entries.push(["indexProp", (0, node_js_1.flattenNode)((0, exports.propToNode)(prop), ctx)]);
|
|
90
|
-
}
|
|
91
|
-
else if ((0, exports.isOptional)(prop)) {
|
|
92
|
-
entries.push(["optionalProp", [k, (0, node_js_1.flattenNode)(prop[1], ctx)]]);
|
|
93
|
-
}
|
|
94
|
-
else if ((0, exports.isPrerequisite)(prop)) {
|
|
95
|
-
entries.push(["prerequisiteProp", [k, (0, node_js_1.flattenNode)(prop[1], ctx)]]);
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
entries.push(["requiredProp", [k, (0, node_js_1.flattenNode)(prop, ctx)]]);
|
|
99
|
-
}
|
|
100
|
-
ctx.path.pop();
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
const flattenPropsRecord = (kind, entries, props, ctx) => {
|
|
104
|
-
const result = {
|
|
105
|
-
required: {},
|
|
106
|
-
optional: {}
|
|
107
|
-
};
|
|
108
|
-
// if we need to keep track of extraneous keys, either to add problems or
|
|
109
|
-
// remove them, store the props as a Record to optimize for presence
|
|
110
|
-
// checking as we iterate over the data
|
|
111
|
-
for (const k in props) {
|
|
112
|
-
const prop = props[k];
|
|
113
|
-
ctx.path.push(k);
|
|
114
|
-
if (k === exports.mappedKeys.index) {
|
|
115
|
-
result.index = (0, node_js_1.flattenNode)((0, exports.propToNode)(prop), ctx);
|
|
116
|
-
}
|
|
117
|
-
else if ((0, exports.isOptional)(prop)) {
|
|
118
|
-
result.optional[k] = (0, node_js_1.flattenNode)(prop[1], ctx);
|
|
119
|
-
}
|
|
120
|
-
else if ((0, exports.isPrerequisite)(prop)) {
|
|
121
|
-
// we still have to push prerequisite props as normal entries so they can be checked first
|
|
122
|
-
entries.push(["prerequisiteProp", [k, (0, node_js_1.flattenNode)(prop[1], ctx)]]);
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
result.required[k] = (0, node_js_1.flattenNode)(prop, ctx);
|
|
126
|
-
}
|
|
127
|
-
ctx.path.pop();
|
|
128
|
-
}
|
|
129
|
-
entries.push([`${kind}Props`, result]);
|
|
130
|
-
};
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.compareStrictness = exports.checkBound = exports.flattenRange = exports.rangeIntersection = exports.isEqualityRange = exports.maxComparators = exports.minComparators = void 0;
|
|
4
|
-
const data_js_1 = require("../../utils/data.js");
|
|
5
|
-
const compose_js_1 = require("../compose.js");
|
|
6
|
-
exports.minComparators = {
|
|
7
|
-
">": true,
|
|
8
|
-
">=": true
|
|
9
|
-
};
|
|
10
|
-
exports.maxComparators = {
|
|
11
|
-
"<": true,
|
|
12
|
-
"<=": true
|
|
13
|
-
};
|
|
14
|
-
const isEqualityRange = (range) => "comparator" in range;
|
|
15
|
-
exports.isEqualityRange = isEqualityRange;
|
|
16
|
-
exports.rangeIntersection = (0, compose_js_1.composeIntersection)((l, r, state) => {
|
|
17
|
-
if ((0, exports.isEqualityRange)(l)) {
|
|
18
|
-
if ((0, exports.isEqualityRange)(r)) {
|
|
19
|
-
return l.limit === r.limit
|
|
20
|
-
? (0, compose_js_1.equality)()
|
|
21
|
-
: state.addDisjoint("range", l, r);
|
|
22
|
-
}
|
|
23
|
-
return rangeAllows(r, l.limit) ? l : state.addDisjoint("range", l, r);
|
|
24
|
-
}
|
|
25
|
-
if ((0, exports.isEqualityRange)(r)) {
|
|
26
|
-
return rangeAllows(l, r.limit) ? r : state.addDisjoint("range", l, r);
|
|
27
|
-
}
|
|
28
|
-
const stricterMin = (0, exports.compareStrictness)("min", l.min, r.min);
|
|
29
|
-
const stricterMax = (0, exports.compareStrictness)("max", l.max, r.max);
|
|
30
|
-
if (stricterMin === "l") {
|
|
31
|
-
if (stricterMax === "r") {
|
|
32
|
-
return (0, exports.compareStrictness)("min", l.min, r.max) === "l"
|
|
33
|
-
? state.addDisjoint("range", l, r)
|
|
34
|
-
: {
|
|
35
|
-
min: l.min,
|
|
36
|
-
max: r.max
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
return l;
|
|
40
|
-
}
|
|
41
|
-
if (stricterMin === "r") {
|
|
42
|
-
if (stricterMax === "l") {
|
|
43
|
-
return (0, exports.compareStrictness)("max", l.max, r.min) === "l"
|
|
44
|
-
? state.addDisjoint("range", l, r)
|
|
45
|
-
: {
|
|
46
|
-
min: r.min,
|
|
47
|
-
max: l.max
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
return r;
|
|
51
|
-
}
|
|
52
|
-
return stricterMax === "l" ? l : stricterMax === "r" ? r : (0, compose_js_1.equality)();
|
|
53
|
-
});
|
|
54
|
-
const rangeAllows = (range, n) => (0, exports.isEqualityRange)(range)
|
|
55
|
-
? n === range.limit
|
|
56
|
-
: minAllows(range.min, n) && maxAllows(range.max, n);
|
|
57
|
-
const minAllows = (min, n) => !min || n > min.limit || (n === min.limit && !isExclusive(min.comparator));
|
|
58
|
-
const maxAllows = (max, n) => !max || n < max.limit || (n === max.limit && !isExclusive(max.comparator));
|
|
59
|
-
const flattenRange = (entries, range, ctx) => {
|
|
60
|
-
const units = ctx.lastDomain === "string"
|
|
61
|
-
? "characters"
|
|
62
|
-
: ctx.lastDomain === "object"
|
|
63
|
-
? "items long"
|
|
64
|
-
: undefined;
|
|
65
|
-
if ((0, exports.isEqualityRange)(range)) {
|
|
66
|
-
return entries.push(["bound", units ? { ...range, units } : range]);
|
|
67
|
-
}
|
|
68
|
-
if (range.min) {
|
|
69
|
-
entries.push(["bound", units ? { ...range.min, units } : range.min]);
|
|
70
|
-
}
|
|
71
|
-
if (range.max) {
|
|
72
|
-
entries.push(["bound", units ? { ...range.max, units } : range.max]);
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
exports.flattenRange = flattenRange;
|
|
76
|
-
const checkBound = (bound, state) => comparatorCheckers[bound.comparator]((0, data_js_1.sizeOf)(state.data), bound.limit) ||
|
|
77
|
-
!state.problems.add("bound", bound);
|
|
78
|
-
exports.checkBound = checkBound;
|
|
79
|
-
const comparatorCheckers = {
|
|
80
|
-
"<": (size, limit) => size < limit,
|
|
81
|
-
">": (size, limit) => size > limit,
|
|
82
|
-
"<=": (size, limit) => size <= limit,
|
|
83
|
-
">=": (size, limit) => size >= limit,
|
|
84
|
-
"==": (size, limit) => size === limit
|
|
85
|
-
};
|
|
86
|
-
const compareStrictness = (kind, l, r) => !l
|
|
87
|
-
? !r
|
|
88
|
-
? "="
|
|
89
|
-
: "r"
|
|
90
|
-
: !r
|
|
91
|
-
? "l"
|
|
92
|
-
: l.limit === r.limit
|
|
93
|
-
? isExclusive(l.comparator)
|
|
94
|
-
? isExclusive(r.comparator)
|
|
95
|
-
? "="
|
|
96
|
-
: "l"
|
|
97
|
-
: isExclusive(r.comparator)
|
|
98
|
-
? "r"
|
|
99
|
-
: "="
|
|
100
|
-
: kind === "min"
|
|
101
|
-
? l.limit > r.limit
|
|
102
|
-
? "l"
|
|
103
|
-
: "r"
|
|
104
|
-
: l.limit < r.limit
|
|
105
|
-
? "l"
|
|
106
|
-
: "r";
|
|
107
|
-
exports.compareStrictness = compareStrictness;
|
|
108
|
-
const isExclusive = (comparator) => comparator.length === 1;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.regexIntersection = exports.checkRegex = exports.getRegex = void 0;
|
|
4
|
-
const compose_js_1 = require("../compose.js");
|
|
5
|
-
const collapsibleSet_js_1 = require("./collapsibleSet.js");
|
|
6
|
-
const regexCache = {};
|
|
7
|
-
const getRegex = (source) => {
|
|
8
|
-
if (!regexCache[source]) {
|
|
9
|
-
regexCache[source] = new RegExp(source);
|
|
10
|
-
}
|
|
11
|
-
return regexCache[source];
|
|
12
|
-
};
|
|
13
|
-
exports.getRegex = getRegex;
|
|
14
|
-
const checkRegex = (source, state) => (0, exports.getRegex)(source).test(state.data) ||
|
|
15
|
-
!state.problems.add("regex", `/${source}/`);
|
|
16
|
-
exports.checkRegex = checkRegex;
|
|
17
|
-
exports.regexIntersection = (0, compose_js_1.composeIntersection)((collapsibleSet_js_1.collapsibleListUnion));
|