arktype 1.0.15-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/package.json +3 -0
- 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/dist/{utils → types/utils}/generics.d.ts +2 -2
- package/package.json +14 -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/{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}/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/README.md
CHANGED
|
@@ -261,6 +261,6 @@ Otherwise, consider sending me an email (david@arktype.io) or [message me on Dis
|
|
|
261
261
|
|
|
262
262
|
### Current Sponsors 🥰
|
|
263
263
|
|
|
264
|
-
| [tmm](https://github.com/tmm) | [xrexy](https://github.com/xrexy) | [thomasballinger](https://github.com/thomasballinger) | [codeandcats](https://github.com/codeandcats) |
|
|
265
|
-
| ------------------------------------------------------------------------- | -------------------------------------------------------------------------- | ------------------------------------------------------------------------ | ------------------------------------------------------------------------- |
|
|
266
|
-
| <img height="64px" src="https://avatars.githubusercontent.com/u/6759464"> | <img height="64px" src="https://avatars.githubusercontent.com/u/71969236"> | <img height="64px" src="https://avatars.githubusercontent.com/u/458879"> | <img height="64px" src="https://avatars.githubusercontent.com/u/6035934"> |
|
|
264
|
+
| [tmm](https://github.com/tmm) | [xrexy](https://github.com/xrexy) | [thomasballinger](https://github.com/thomasballinger) | [codeandcats](https://github.com/codeandcats) | [jacksteamdev](https://github.com/jacksteamdev) |
|
|
265
|
+
| ------------------------------------------------------------------------- | -------------------------------------------------------------------------- | ------------------------------------------------------------------------ | ------------------------------------------------------------------------- | -------------------------------------------------------------------------- |
|
|
266
|
+
| <img height="64px" src="https://avatars.githubusercontent.com/u/6759464"> | <img height="64px" src="https://avatars.githubusercontent.com/u/71969236"> | <img height="64px" src="https://avatars.githubusercontent.com/u/458879"> | <img height="64px" src="https://avatars.githubusercontent.com/u/6035934"> | <img height="64px" src="https://avatars.githubusercontent.com/u/23390212"> |
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
scope: ()=>_scopeJs.scope,
|
|
13
|
+
type: ()=>_arkJs.type,
|
|
14
|
+
ark: ()=>_arkJs.ark,
|
|
15
|
+
arkScope: ()=>_arkJs.arkScope,
|
|
16
|
+
arrayOf: ()=>_expressionsJs.arrayOf,
|
|
17
|
+
instanceOf: ()=>_expressionsJs.instanceOf,
|
|
18
|
+
intersection: ()=>_expressionsJs.intersection,
|
|
19
|
+
keyOf: ()=>_expressionsJs.keyOf,
|
|
20
|
+
morph: ()=>_expressionsJs.morph,
|
|
21
|
+
narrow: ()=>_expressionsJs.narrow,
|
|
22
|
+
union: ()=>_expressionsJs.union,
|
|
23
|
+
valueOf: ()=>_expressionsJs.valueOf,
|
|
24
|
+
jsObjectsScope: ()=>_jsObjectsJs.jsObjectsScope,
|
|
25
|
+
tsKeywordsScope: ()=>_tsKeywordsJs.tsKeywordsScope,
|
|
26
|
+
validationScope: ()=>_validationJs.validationScope,
|
|
27
|
+
Problems: ()=>_problemsJs.Problems,
|
|
28
|
+
Problem: ()=>_problemsJs.Problem,
|
|
29
|
+
parseConfigTuple: ()=>_configJs.parseConfigTuple
|
|
30
|
+
});
|
|
31
|
+
const _scopeJs = require("./scopes/scope.js");
|
|
32
|
+
const _arkJs = require("./scopes/ark.js");
|
|
33
|
+
const _expressionsJs = require("./scopes/expressions.js");
|
|
34
|
+
const _jsObjectsJs = require("./scopes/jsObjects.js");
|
|
35
|
+
const _tsKeywordsJs = require("./scopes/tsKeywords.js");
|
|
36
|
+
const _validationJs = require("./scopes/validation/validation.js");
|
|
37
|
+
const _problemsJs = require("./traverse/problems.js");
|
|
38
|
+
const _configJs = require("./parse/ast/config.js");
|
|
@@ -0,0 +1,140 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,157 @@
|
|
|
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
|
+
};
|