arktype 1.0.16-alpha → 1.0.17-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/src/main.js +38 -0
- package/dist/cjs/src/nodes/branch.js +140 -0
- package/dist/cjs/src/nodes/compose.js +157 -0
- package/dist/{nodes → cjs/src/nodes}/discriminate.js +92 -100
- package/dist/cjs/src/nodes/node.js +139 -0
- package/dist/cjs/src/nodes/predicate.js +86 -0
- package/dist/cjs/src/nodes/rules/class.js +25 -0
- package/dist/cjs/src/nodes/rules/collapsibleSet.js +48 -0
- package/dist/cjs/src/nodes/rules/divisor.js +29 -0
- package/dist/cjs/src/nodes/rules/props.js +160 -0
- package/dist/cjs/src/nodes/rules/range.js +105 -0
- package/dist/cjs/src/nodes/rules/regex.js +26 -0
- package/dist/cjs/src/nodes/rules/rules.js +123 -0
- package/dist/cjs/src/parse/ast/ast.js +4 -0
- package/dist/cjs/src/parse/ast/bound.js +16 -0
- package/dist/cjs/src/parse/ast/config.js +13 -0
- package/dist/cjs/src/parse/ast/distributableFunction.js +48 -0
- package/dist/cjs/src/parse/ast/divisor.js +9 -0
- package/dist/cjs/src/parse/ast/intersection.js +30 -0
- package/dist/cjs/src/parse/ast/keyof.js +111 -0
- package/dist/cjs/src/parse/ast/morph.js +58 -0
- package/dist/cjs/src/parse/ast/narrow.js +22 -0
- package/dist/cjs/src/parse/ast/node.js +4 -0
- package/dist/cjs/src/parse/ast/tuple.js +94 -0
- package/dist/cjs/src/parse/ast/union.js +9 -0
- package/dist/cjs/src/parse/ast/utils.js +4 -0
- package/dist/cjs/src/parse/definition.js +61 -0
- package/dist/cjs/src/parse/record.js +37 -0
- package/dist/cjs/src/parse/string/reduce/dynamic.js +167 -0
- package/dist/cjs/src/parse/string/reduce/shared.js +23 -0
- package/dist/cjs/src/parse/string/reduce/static.js +4 -0
- package/dist/cjs/src/parse/string/shift/operand/enclosed.js +54 -0
- package/dist/cjs/src/parse/string/shift/operand/operand.js +11 -0
- package/dist/cjs/src/parse/string/shift/operand/unenclosed.js +53 -0
- package/dist/cjs/src/parse/string/shift/operator/bounds.js +87 -0
- package/dist/cjs/src/parse/string/shift/operator/divisor.js +35 -0
- package/dist/cjs/src/parse/string/shift/operator/operator.js +26 -0
- package/dist/cjs/src/parse/string/shift/scanner.js +114 -0
- package/dist/cjs/src/parse/string/string.js +43 -0
- package/dist/cjs/src/scopes/ark.js +45 -0
- package/dist/cjs/src/scopes/cache.js +52 -0
- package/dist/cjs/src/scopes/expressions.js +29 -0
- package/dist/cjs/src/scopes/jsObjects.js +93 -0
- package/dist/cjs/src/scopes/scope.js +323 -0
- package/dist/cjs/src/scopes/tsKeywords.js +113 -0
- package/dist/cjs/src/scopes/type.js +50 -0
- package/dist/cjs/src/scopes/validation/creditCard.js +47 -0
- package/dist/cjs/src/scopes/validation/date.js +62 -0
- package/dist/cjs/src/scopes/validation/validation.js +108 -0
- package/dist/cjs/src/traverse/problems.js +281 -0
- package/dist/cjs/src/traverse/traverse.js +390 -0
- package/dist/cjs/src/utils/chainableNoOpProxy.js +23 -0
- package/dist/cjs/src/utils/data.js +53 -0
- package/dist/cjs/src/utils/domains.js +30 -0
- package/dist/cjs/src/utils/errors.js +26 -0
- package/dist/cjs/src/utils/freeze.js +15 -0
- package/dist/cjs/src/utils/generics.js +63 -0
- package/dist/cjs/src/utils/numericLiterals.js +75 -0
- package/dist/cjs/src/utils/objectKinds.js +69 -0
- package/dist/cjs/src/utils/paths.js +32 -0
- package/dist/cjs/src/utils/serialize.js +74 -0
- package/dist/cjs/src/utils/unionToTuple.js +4 -0
- package/dist/mjs/package.json +3 -0
- package/dist/mjs/src/main.js +8 -0
- package/dist/mjs/src/nodes/branch.js +123 -0
- package/dist/mjs/src/nodes/compose.js +135 -0
- package/dist/mjs/src/nodes/discriminate.js +247 -0
- package/dist/mjs/src/nodes/node.js +117 -0
- package/dist/mjs/src/nodes/predicate.js +69 -0
- package/dist/mjs/src/nodes/rules/class.js +11 -0
- package/dist/mjs/src/nodes/rules/collapsibleSet.js +34 -0
- package/dist/mjs/src/nodes/rules/divisor.js +15 -0
- package/dist/mjs/src/nodes/rules/props.js +142 -0
- package/dist/mjs/src/nodes/rules/range.js +86 -0
- package/dist/mjs/src/nodes/rules/regex.js +11 -0
- package/dist/mjs/src/nodes/rules/rules.js +106 -0
- package/dist/mjs/src/parse/ast/ast.js +1 -0
- package/dist/mjs/src/parse/ast/bound.js +2 -0
- package/dist/mjs/src/parse/ast/config.js +9 -0
- package/dist/mjs/src/parse/ast/distributableFunction.js +34 -0
- package/dist/mjs/src/parse/ast/divisor.js +1 -0
- package/dist/mjs/src/parse/ast/intersection.js +16 -0
- package/dist/mjs/src/parse/ast/keyof.js +103 -0
- package/dist/mjs/src/parse/ast/morph.js +44 -0
- package/dist/mjs/src/parse/ast/narrow.js +14 -0
- package/dist/mjs/src/parse/ast/node.js +1 -0
- package/dist/mjs/src/parse/ast/tuple.js +80 -0
- package/dist/mjs/src/parse/ast/union.js +1 -0
- package/dist/mjs/src/parse/ast/utils.js +1 -0
- package/dist/mjs/src/parse/definition.js +46 -0
- package/dist/mjs/src/parse/record.js +29 -0
- package/dist/mjs/src/parse/string/reduce/dynamic.js +159 -0
- package/dist/mjs/src/parse/string/reduce/shared.js +6 -0
- package/dist/mjs/src/parse/string/reduce/static.js +1 -0
- package/dist/mjs/src/parse/string/shift/operand/enclosed.js +39 -0
- package/dist/mjs/src/parse/string/shift/operand/operand.js +3 -0
- package/dist/mjs/src/parse/string/shift/operand/unenclosed.js +36 -0
- package/dist/mjs/src/parse/string/shift/operator/bounds.js +70 -0
- package/dist/mjs/src/parse/string/shift/operator/divisor.js +21 -0
- package/dist/mjs/src/parse/string/shift/operator/operator.js +13 -0
- package/dist/mjs/src/parse/string/shift/scanner.js +106 -0
- package/dist/mjs/src/parse/string/string.js +28 -0
- package/dist/mjs/src/scopes/ark.js +28 -0
- package/dist/mjs/src/scopes/cache.js +38 -0
- package/dist/{scopes → mjs/src/scopes}/expressions.js +9 -20
- package/dist/mjs/src/scopes/jsObjects.js +82 -0
- package/dist/mjs/src/scopes/scope.js +303 -0
- package/dist/mjs/src/scopes/tsKeywords.js +116 -0
- package/dist/mjs/src/scopes/type.js +35 -0
- package/dist/{scopes → mjs/src/scopes}/validation/creditCard.js +11 -15
- package/dist/{scopes → mjs/src/scopes}/validation/date.js +16 -21
- package/dist/mjs/src/scopes/validation/validation.js +112 -0
- package/dist/mjs/src/traverse/problems.js +260 -0
- package/dist/mjs/src/traverse/traverse.js +373 -0
- package/dist/{utils → mjs/src/utils}/chainableNoOpProxy.js +2 -6
- package/dist/mjs/src/utils/data.js +38 -0
- package/dist/mjs/src/utils/domains.js +15 -0
- package/dist/mjs/src/utils/errors.js +10 -0
- package/dist/mjs/src/utils/freeze.js +7 -0
- package/dist/mjs/src/utils/generics.js +38 -0
- package/dist/mjs/src/utils/numericLiterals.js +72 -0
- package/dist/mjs/src/utils/objectKinds.js +55 -0
- package/dist/{utils → mjs/src/utils}/paths.js +3 -8
- package/dist/mjs/src/utils/serialize.js +58 -0
- package/dist/mjs/src/utils/unionToTuple.js +1 -0
- package/dist/tsconfig.temp.tsbuildinfo +1 -1
- package/package.json +13 -5
- 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/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));
|
|
@@ -1,102 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.literalSatisfiesRules = exports.precedenceMap = exports.flattenRules = exports.narrowableRulesIntersection = exports.rulesIntersection = void 0;
|
|
4
|
-
const generics_js_1 = require("../../utils/generics.js");
|
|
5
|
-
const compose_js_1 = require("../compose.js");
|
|
6
|
-
const class_js_1 = require("./class.js");
|
|
7
|
-
const collapsibleSet_js_1 = require("./collapsibleSet.js");
|
|
8
|
-
const divisor_js_1 = require("./divisor.js");
|
|
9
|
-
const props_js_1 = require("./props.js");
|
|
10
|
-
const range_js_1 = require("./range.js");
|
|
11
|
-
const regex_js_1 = require("./regex.js");
|
|
12
|
-
const rulesIntersection = (l, r, state) => "value" in l
|
|
13
|
-
? "value" in r
|
|
14
|
-
? l.value === r.value
|
|
15
|
-
? (0, compose_js_1.equality)()
|
|
16
|
-
: state.addDisjoint("value", l.value, r.value)
|
|
17
|
-
: (0, exports.literalSatisfiesRules)(l.value, r, state)
|
|
18
|
-
? l
|
|
19
|
-
: state.addDisjoint("leftAssignability", l, r)
|
|
20
|
-
: "value" in r
|
|
21
|
-
? (0, exports.literalSatisfiesRules)(r.value, l, state)
|
|
22
|
-
? r
|
|
23
|
-
: state.addDisjoint("rightAssignability", l, r)
|
|
24
|
-
: (0, exports.narrowableRulesIntersection)(l, r, state);
|
|
25
|
-
exports.rulesIntersection = rulesIntersection;
|
|
26
|
-
const narrowIntersection = (0, compose_js_1.composeIntersection)(collapsibleSet_js_1.collapsibleListUnion);
|
|
27
|
-
exports.narrowableRulesIntersection = (0, compose_js_1.composeKeyedIntersection)({
|
|
28
|
-
divisor: divisor_js_1.divisorIntersection,
|
|
29
|
-
regex: regex_js_1.regexIntersection,
|
|
30
|
-
props: props_js_1.propsIntersection,
|
|
31
|
-
class: class_js_1.classIntersection,
|
|
32
|
-
range: range_js_1.rangeIntersection,
|
|
33
|
-
narrow: narrowIntersection
|
|
34
|
-
}, { onEmpty: "bubble" });
|
|
35
|
-
const flattenRules = (rules, ctx) => {
|
|
36
|
-
const entries = [];
|
|
37
|
-
let k;
|
|
38
|
-
for (k in rules) {
|
|
39
|
-
ruleFlatteners[k](entries, rules[k], ctx);
|
|
40
|
-
}
|
|
41
|
-
// Some entries with the same precedence, e.g. morphs flattened from a list,
|
|
42
|
-
// rely on the fact that JS's builtin sort is stable to behave as expected
|
|
43
|
-
// when traversed:
|
|
44
|
-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
|
|
45
|
-
return entries.sort((l, r) => exports.precedenceMap[l[0]] - exports.precedenceMap[r[0]]);
|
|
46
|
-
};
|
|
47
|
-
exports.flattenRules = flattenRules;
|
|
48
|
-
const ruleFlatteners = {
|
|
49
|
-
regex: (entries, rule) => {
|
|
50
|
-
for (const source of (0, generics_js_1.listFrom)(rule)) {
|
|
51
|
-
entries.push(["regex", source]);
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
divisor: (entries, rule) => {
|
|
55
|
-
entries.push(["divisor", rule]);
|
|
56
|
-
},
|
|
57
|
-
range: range_js_1.flattenRange,
|
|
58
|
-
class: (entries, rule) => {
|
|
59
|
-
entries.push(["class", rule]);
|
|
60
|
-
},
|
|
61
|
-
props: props_js_1.flattenProps,
|
|
62
|
-
narrow: (entries, rule) => {
|
|
63
|
-
for (const narrow of (0, generics_js_1.listFrom)(rule)) {
|
|
64
|
-
entries.push(["narrow", narrow]);
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
value: (entries, rule) => {
|
|
68
|
-
entries.push(["value", rule]);
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
exports.precedenceMap = {
|
|
72
|
-
// Config: Applies before any checks
|
|
73
|
-
config: -1,
|
|
74
|
-
// Critical: No other checks are performed if these fail
|
|
75
|
-
domain: 0,
|
|
76
|
-
value: 0,
|
|
77
|
-
domains: 0,
|
|
78
|
-
branches: 0,
|
|
79
|
-
switch: 0,
|
|
80
|
-
alias: 0,
|
|
81
|
-
class: 0,
|
|
82
|
-
// Shallow: All shallow checks will be performed even if one or more fail
|
|
83
|
-
regex: 1,
|
|
84
|
-
divisor: 1,
|
|
85
|
-
bound: 1,
|
|
86
|
-
// Prerequisite: These are deep checks with special priority, e.g. the
|
|
87
|
-
// length of a tuple, which causes other deep props not to be checked if it
|
|
88
|
-
// is invalid
|
|
89
|
-
prerequisiteProp: 2,
|
|
90
|
-
// Deep: Performed if all shallow checks pass, even if one or more deep checks fail
|
|
91
|
-
distilledProps: 3,
|
|
92
|
-
strictProps: 3,
|
|
93
|
-
requiredProp: 3,
|
|
94
|
-
optionalProp: 3,
|
|
95
|
-
indexProp: 3,
|
|
96
|
-
// Narrow: Only performed if all shallow and deep checks pass
|
|
97
|
-
narrow: 4,
|
|
98
|
-
// Morph: Only performed if all validation passes
|
|
99
|
-
morph: 5
|
|
100
|
-
};
|
|
101
|
-
const literalSatisfiesRules = (data, rules, state) => !state.type.scope.type(["node", { [state.domain]: rules }])(data).problems;
|
|
102
|
-
exports.literalSatisfiesRules = literalSatisfiesRules;
|
package/dist/parse/ast/ast.js
DELETED
package/dist/parse/ast/bound.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.writeUnboundableMessage = exports.writeDoubleRightBoundMessage = void 0;
|
|
4
|
-
const writeDoubleRightBoundMessage = (root) => `Expression ${root} must have at most one right bound`;
|
|
5
|
-
exports.writeDoubleRightBoundMessage = writeDoubleRightBoundMessage;
|
|
6
|
-
const writeUnboundableMessage = (root) => `Bounded expression ${root} must be a number, string or array`;
|
|
7
|
-
exports.writeUnboundableMessage = writeUnboundableMessage;
|