arktype 1.0.28-alpha → 1.1.0-dev-2
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/dist/main.d.ts +11 -0
- package/dist/main.d.ts.map +1 -0
- package/dist/main.js +8 -0
- package/dist/main.js.map +1 -0
- package/dist/match.d.ts +46 -0
- package/dist/match.d.ts.map +1 -0
- package/dist/match.js +23 -0
- package/dist/match.js.map +1 -0
- package/dist/parser/definition.d.ts +32 -0
- package/dist/parser/definition.d.ts.map +1 -0
- package/dist/parser/definition.js +29 -0
- package/dist/parser/definition.js.map +1 -0
- package/dist/parser/generic.d.ts +44 -0
- package/dist/parser/generic.d.ts.map +1 -0
- package/dist/parser/generic.js +46 -0
- package/dist/parser/generic.js.map +1 -0
- package/dist/parser/objectLiteral.d.ts +24 -0
- package/dist/parser/objectLiteral.d.ts.map +1 -0
- package/dist/parser/objectLiteral.js +38 -0
- package/dist/parser/objectLiteral.js.map +1 -0
- package/dist/parser/semantic/bounds.d.ts +13 -0
- package/dist/parser/semantic/bounds.d.ts.map +1 -0
- package/dist/parser/semantic/bounds.js +2 -0
- package/dist/parser/semantic/bounds.js.map +1 -0
- package/dist/parser/semantic/divisor.d.ts +9 -0
- package/dist/parser/semantic/divisor.d.ts.map +1 -0
- package/dist/parser/semantic/divisor.js +2 -0
- package/dist/parser/semantic/divisor.js.map +1 -0
- package/dist/parser/semantic/intersections.d.ts +15 -0
- package/dist/parser/semantic/intersections.d.ts.map +1 -0
- package/dist/parser/semantic/intersections.js +2 -0
- package/dist/parser/semantic/intersections.js.map +1 -0
- package/dist/parser/semantic/semantic.d.ts +22 -0
- package/dist/parser/semantic/semantic.d.ts.map +1 -0
- package/dist/parser/semantic/semantic.js +2 -0
- package/dist/parser/semantic/semantic.js.map +1 -0
- package/dist/parser/semantic/utils.d.ts +8 -0
- package/dist/parser/semantic/utils.d.ts.map +1 -0
- package/dist/parser/semantic/utils.js +2 -0
- package/dist/parser/semantic/utils.js.map +1 -0
- package/dist/parser/semantic/validate.d.ts +24 -0
- package/dist/parser/semantic/validate.d.ts.map +1 -0
- package/dist/parser/semantic/validate.js +2 -0
- package/dist/parser/semantic/validate.js.map +1 -0
- package/dist/parser/shared.d.ts +48 -0
- package/dist/parser/shared.d.ts.map +1 -0
- package/dist/parser/shared.js +41 -0
- package/dist/parser/shared.js.map +1 -0
- package/dist/parser/string/reduce/dynamic.d.ts +40 -0
- package/dist/parser/string/reduce/dynamic.d.ts.map +1 -0
- package/dist/parser/string/reduce/dynamic.js +122 -0
- package/dist/parser/string/reduce/dynamic.js.map +1 -0
- package/dist/parser/string/reduce/shared.d.ts +29 -0
- package/dist/parser/string/reduce/shared.d.ts.map +1 -0
- package/dist/parser/string/reduce/shared.js +7 -0
- package/dist/parser/string/reduce/shared.js.map +1 -0
- package/dist/parser/string/reduce/static.d.ts +177 -0
- package/dist/parser/string/reduce/static.d.ts.map +1 -0
- package/dist/parser/string/reduce/static.js +2 -0
- package/dist/parser/string/reduce/static.js.map +1 -0
- package/dist/parser/string/shift/operand/date.d.ts +11 -0
- package/dist/parser/string/shift/operand/date.d.ts.map +1 -0
- package/dist/parser/string/shift/operand/date.js +26 -0
- package/dist/parser/string/shift/operand/date.js.map +1 -0
- package/dist/parser/string/shift/operand/enclosed.d.ts +49 -0
- package/dist/parser/string/shift/operand/enclosed.d.ts.map +1 -0
- package/dist/parser/string/shift/operand/enclosed.js +50 -0
- package/dist/parser/string/shift/operand/enclosed.js.map +1 -0
- package/dist/parser/string/shift/operand/operand.d.ts +9 -0
- package/dist/parser/string/shift/operand/operand.d.ts.map +1 -0
- package/dist/parser/string/shift/operand/operand.js +17 -0
- package/dist/parser/string/shift/operand/operand.js.map +1 -0
- package/dist/parser/string/shift/operand/unenclosed.d.ts +36 -0
- package/dist/parser/string/shift/operand/unenclosed.d.ts.map +1 -0
- package/dist/parser/string/shift/operand/unenclosed.js +68 -0
- package/dist/parser/string/shift/operand/unenclosed.js.map +1 -0
- package/dist/parser/string/shift/operator/bounds.d.ts +55 -0
- package/dist/parser/string/shift/operator/bounds.d.ts.map +1 -0
- package/dist/parser/string/shift/operator/bounds.js +95 -0
- package/dist/parser/string/shift/operator/bounds.js.map +1 -0
- package/dist/parser/string/shift/operator/divisor.d.ts +9 -0
- package/dist/parser/string/shift/operator/divisor.d.ts.map +1 -0
- package/dist/parser/string/shift/operator/divisor.js +13 -0
- package/dist/parser/string/shift/operator/divisor.js.map +1 -0
- package/dist/parser/string/shift/operator/operator.d.ts +13 -0
- package/dist/parser/string/shift/operator/operator.d.ts.map +1 -0
- package/dist/parser/string/shift/operator/operator.js +29 -0
- package/dist/parser/string/shift/operator/operator.js.map +1 -0
- package/dist/parser/string/shift/scanner.d.ts +71 -0
- package/dist/parser/string/shift/scanner.d.ts.map +1 -0
- package/dist/parser/string/shift/scanner.js +99 -0
- package/dist/parser/string/shift/scanner.js.map +1 -0
- package/dist/parser/string/string.d.ts +26 -0
- package/dist/parser/string/string.d.ts.map +1 -0
- package/dist/parser/string/string.js +31 -0
- package/dist/parser/string/string.js.map +1 -0
- package/dist/parser/tuple.d.ts +73 -0
- package/dist/parser/tuple.d.ts.map +1 -0
- package/dist/parser/tuple.js +134 -0
- package/dist/parser/tuple.js.map +1 -0
- package/dist/scope.d.ts +159 -0
- package/dist/scope.d.ts.map +1 -0
- package/dist/scope.js +248 -0
- package/dist/scope.js.map +1 -0
- package/dist/scopes/ark.d.ts +38 -0
- package/dist/scopes/ark.d.ts.map +1 -0
- package/dist/scopes/ark.js +24 -0
- package/dist/scopes/ark.js.map +1 -0
- package/dist/scopes/jsObjects.d.ts +19 -0
- package/dist/scopes/jsObjects.d.ts.map +1 -0
- package/dist/scopes/jsObjects.js +15 -0
- package/dist/scopes/jsObjects.js.map +1 -0
- package/dist/scopes/parsing.d.ts +18 -0
- package/dist/scopes/parsing.d.ts.map +1 -0
- package/dist/scopes/parsing.js +61 -0
- package/dist/scopes/parsing.js.map +1 -0
- package/dist/scopes/tsGenerics.d.ts +17 -0
- package/dist/scopes/tsGenerics.d.ts.map +1 -0
- package/dist/scopes/tsGenerics.js +13 -0
- package/dist/scopes/tsGenerics.js.map +1 -0
- package/dist/scopes/tsKeywords.d.ts +24 -0
- package/dist/scopes/tsKeywords.d.ts.map +1 -0
- package/dist/scopes/tsKeywords.js +20 -0
- package/dist/scopes/tsKeywords.js.map +1 -0
- package/dist/scopes/utils/creditCard.d.ts +3 -0
- package/dist/scopes/utils/creditCard.d.ts.map +1 -0
- package/dist/{mjs/scopes/validation → scopes/utils}/creditCard.js +14 -12
- package/dist/scopes/utils/creditCard.js.map +1 -0
- package/dist/{types/scopes/validation → scopes/utils}/date.d.ts +3 -2
- package/dist/scopes/utils/date.d.ts.map +1 -0
- package/dist/{mjs/scopes/validation → scopes/utils}/date.js +24 -19
- package/dist/scopes/utils/date.js.map +1 -0
- package/dist/scopes/validation.d.ts +20 -0
- package/dist/scopes/validation.d.ts.map +1 -0
- package/dist/scopes/validation.js +57 -0
- package/dist/scopes/validation.js.map +1 -0
- package/dist/type.d.ts +101 -0
- package/dist/type.d.ts.map +1 -0
- package/dist/type.js +138 -0
- package/dist/type.js.map +1 -0
- package/main.ts +20 -0
- package/match.ts +137 -0
- package/package.json +41 -108
- package/parser/definition.ts +156 -0
- package/parser/generic.ts +208 -0
- package/parser/objectLiteral.ts +120 -0
- package/parser/semantic/bounds.ts +63 -0
- package/parser/semantic/divisor.ts +13 -0
- package/parser/semantic/intersections.ts +47 -0
- package/parser/semantic/semantic.ts +107 -0
- package/parser/semantic/utils.ts +26 -0
- package/parser/semantic/validate.ts +105 -0
- package/parser/shared.ts +141 -0
- package/parser/string/reduce/dynamic.ts +181 -0
- package/parser/string/reduce/shared.ts +73 -0
- package/parser/string/reduce/static.ts +300 -0
- package/parser/string/shift/operand/date.ts +57 -0
- package/parser/string/shift/operand/enclosed.ts +119 -0
- package/parser/string/shift/operand/operand.ts +48 -0
- package/parser/string/shift/operand/unenclosed.ts +282 -0
- package/parser/string/shift/operator/bounds.ts +229 -0
- package/parser/string/shift/operator/divisor.ts +36 -0
- package/parser/string/shift/operator/operator.ts +82 -0
- package/parser/string/shift/scanner.ts +209 -0
- package/parser/string/string.ts +93 -0
- package/parser/tuple.ts +475 -0
- package/scope.ts +573 -0
- package/scopes/ark.ts +64 -0
- package/scopes/jsObjects.ts +29 -0
- package/scopes/parsing.ts +81 -0
- package/scopes/tsGenerics.ts +28 -0
- package/scopes/tsKeywords.ts +39 -0
- package/scopes/utils/creditCard.ts +37 -0
- package/scopes/utils/date.ts +108 -0
- package/scopes/validation.ts +81 -0
- package/type.ts +403 -0
- package/LICENSE +0 -7
- package/README.md +0 -351
- package/dist/cjs/main.js +0 -38
- package/dist/cjs/nodes/branch.js +0 -140
- package/dist/cjs/nodes/compose.js +0 -163
- package/dist/cjs/nodes/discriminate.js +0 -265
- package/dist/cjs/nodes/node.js +0 -139
- package/dist/cjs/nodes/predicate.js +0 -86
- package/dist/cjs/nodes/rules/class.js +0 -25
- package/dist/cjs/nodes/rules/collapsibleSet.js +0 -48
- package/dist/cjs/nodes/rules/divisor.js +0 -29
- package/dist/cjs/nodes/rules/props.js +0 -167
- package/dist/cjs/nodes/rules/range.js +0 -105
- package/dist/cjs/nodes/rules/regex.js +0 -26
- package/dist/cjs/nodes/rules/rules.js +0 -123
- package/dist/cjs/package.json +0 -3
- package/dist/cjs/parse/ast/ast.js +0 -4
- package/dist/cjs/parse/ast/bound.js +0 -16
- package/dist/cjs/parse/ast/config.js +0 -13
- package/dist/cjs/parse/ast/distributableFunction.js +0 -48
- package/dist/cjs/parse/ast/divisor.js +0 -9
- package/dist/cjs/parse/ast/intersection.js +0 -30
- package/dist/cjs/parse/ast/keyof.js +0 -111
- package/dist/cjs/parse/ast/morph.js +0 -58
- package/dist/cjs/parse/ast/narrow.js +0 -22
- package/dist/cjs/parse/ast/node.js +0 -4
- package/dist/cjs/parse/ast/tuple.js +0 -94
- package/dist/cjs/parse/ast/union.js +0 -9
- package/dist/cjs/parse/ast/utils.js +0 -4
- package/dist/cjs/parse/definition.js +0 -61
- package/dist/cjs/parse/record.js +0 -37
- package/dist/cjs/parse/string/reduce/dynamic.js +0 -167
- package/dist/cjs/parse/string/reduce/shared.js +0 -23
- package/dist/cjs/parse/string/reduce/static.js +0 -4
- package/dist/cjs/parse/string/shift/operand/enclosed.js +0 -54
- package/dist/cjs/parse/string/shift/operand/operand.js +0 -11
- package/dist/cjs/parse/string/shift/operand/unenclosed.js +0 -53
- package/dist/cjs/parse/string/shift/operator/bounds.js +0 -87
- package/dist/cjs/parse/string/shift/operator/divisor.js +0 -35
- package/dist/cjs/parse/string/shift/operator/operator.js +0 -26
- package/dist/cjs/parse/string/shift/scanner.js +0 -114
- package/dist/cjs/parse/string/string.js +0 -43
- package/dist/cjs/scopes/ark.js +0 -45
- package/dist/cjs/scopes/cache.js +0 -52
- package/dist/cjs/scopes/expressions.js +0 -29
- package/dist/cjs/scopes/jsObjects.js +0 -93
- package/dist/cjs/scopes/scope.js +0 -323
- package/dist/cjs/scopes/tsKeywords.js +0 -113
- package/dist/cjs/scopes/type.js +0 -50
- package/dist/cjs/scopes/validation/creditCard.js +0 -47
- package/dist/cjs/scopes/validation/date.js +0 -62
- package/dist/cjs/scopes/validation/validation.js +0 -108
- package/dist/cjs/traverse/problems.js +0 -281
- package/dist/cjs/traverse/traverse.js +0 -390
- package/dist/cjs/utils/chainableNoOpProxy.js +0 -23
- package/dist/cjs/utils/data.js +0 -53
- package/dist/cjs/utils/domains.js +0 -30
- package/dist/cjs/utils/errors.js +0 -26
- package/dist/cjs/utils/freeze.js +0 -15
- package/dist/cjs/utils/generics.js +0 -63
- package/dist/cjs/utils/numericLiterals.js +0 -75
- package/dist/cjs/utils/objectKinds.js +0 -69
- package/dist/cjs/utils/paths.js +0 -32
- package/dist/cjs/utils/serialize.js +0 -74
- package/dist/cjs/utils/unionToTuple.js +0 -4
- package/dist/mjs/main.js +0 -8
- package/dist/mjs/nodes/branch.js +0 -123
- package/dist/mjs/nodes/compose.js +0 -141
- package/dist/mjs/nodes/discriminate.js +0 -250
- package/dist/mjs/nodes/node.js +0 -117
- package/dist/mjs/nodes/predicate.js +0 -69
- package/dist/mjs/nodes/rules/class.js +0 -11
- package/dist/mjs/nodes/rules/collapsibleSet.js +0 -34
- package/dist/mjs/nodes/rules/divisor.js +0 -15
- package/dist/mjs/nodes/rules/props.js +0 -149
- package/dist/mjs/nodes/rules/range.js +0 -86
- package/dist/mjs/nodes/rules/regex.js +0 -11
- package/dist/mjs/nodes/rules/rules.js +0 -106
- package/dist/mjs/package.json +0 -3
- package/dist/mjs/parse/ast/ast.js +0 -1
- package/dist/mjs/parse/ast/bound.js +0 -2
- package/dist/mjs/parse/ast/config.js +0 -9
- package/dist/mjs/parse/ast/distributableFunction.js +0 -34
- package/dist/mjs/parse/ast/divisor.js +0 -1
- package/dist/mjs/parse/ast/intersection.js +0 -16
- package/dist/mjs/parse/ast/keyof.js +0 -103
- package/dist/mjs/parse/ast/morph.js +0 -44
- package/dist/mjs/parse/ast/narrow.js +0 -14
- package/dist/mjs/parse/ast/node.js +0 -1
- package/dist/mjs/parse/ast/tuple.js +0 -80
- package/dist/mjs/parse/ast/union.js +0 -1
- package/dist/mjs/parse/ast/utils.js +0 -1
- package/dist/mjs/parse/definition.js +0 -46
- package/dist/mjs/parse/record.js +0 -29
- package/dist/mjs/parse/string/reduce/dynamic.js +0 -159
- package/dist/mjs/parse/string/reduce/shared.js +0 -6
- package/dist/mjs/parse/string/reduce/static.js +0 -1
- package/dist/mjs/parse/string/shift/operand/enclosed.js +0 -39
- package/dist/mjs/parse/string/shift/operand/operand.js +0 -3
- package/dist/mjs/parse/string/shift/operand/unenclosed.js +0 -36
- package/dist/mjs/parse/string/shift/operator/bounds.js +0 -70
- package/dist/mjs/parse/string/shift/operator/divisor.js +0 -21
- package/dist/mjs/parse/string/shift/operator/operator.js +0 -13
- package/dist/mjs/parse/string/shift/scanner.js +0 -106
- package/dist/mjs/parse/string/string.js +0 -28
- package/dist/mjs/scopes/ark.js +0 -28
- package/dist/mjs/scopes/cache.js +0 -38
- package/dist/mjs/scopes/expressions.js +0 -89
- package/dist/mjs/scopes/jsObjects.js +0 -82
- package/dist/mjs/scopes/scope.js +0 -303
- package/dist/mjs/scopes/tsKeywords.js +0 -116
- package/dist/mjs/scopes/type.js +0 -35
- package/dist/mjs/scopes/validation/validation.js +0 -112
- package/dist/mjs/traverse/problems.js +0 -260
- package/dist/mjs/traverse/traverse.js +0 -373
- package/dist/mjs/utils/chainableNoOpProxy.js +0 -15
- package/dist/mjs/utils/data.js +0 -38
- package/dist/mjs/utils/domains.js +0 -15
- package/dist/mjs/utils/errors.js +0 -10
- package/dist/mjs/utils/freeze.js +0 -7
- package/dist/mjs/utils/generics.js +0 -38
- package/dist/mjs/utils/numericLiterals.js +0 -72
- package/dist/mjs/utils/objectKinds.js +0 -55
- package/dist/mjs/utils/paths.js +0 -18
- package/dist/mjs/utils/serialize.js +0 -58
- package/dist/mjs/utils/unionToTuple.js +0 -1
- package/dist/tsconfig.temp.tsbuildinfo +0 -1
- package/dist/types/main.d.ts +0 -15
- package/dist/types/nodes/branch.d.ts +0 -29
- package/dist/types/nodes/compose.d.ts +0 -98
- package/dist/types/nodes/discriminate.d.ts +0 -26
- package/dist/types/nodes/node.d.ts +0 -69
- package/dist/types/nodes/predicate.d.ts +0 -18
- package/dist/types/nodes/rules/class.d.ts +0 -4
- package/dist/types/nodes/rules/collapsibleSet.d.ts +0 -4
- package/dist/types/nodes/rules/divisor.d.ts +0 -3
- package/dist/types/nodes/rules/props.d.ts +0 -43
- package/dist/types/nodes/rules/range.d.ts +0 -34
- package/dist/types/nodes/rules/regex.d.ts +0 -5
- package/dist/types/nodes/rules/rules.d.ts +0 -33
- package/dist/types/parse/ast/ast.d.ts +0 -24
- package/dist/types/parse/ast/bound.d.ts +0 -27
- package/dist/types/parse/ast/config.d.ts +0 -15
- package/dist/types/parse/ast/distributableFunction.d.ts +0 -18
- package/dist/types/parse/ast/divisor.d.ts +0 -13
- package/dist/types/parse/ast/intersection.d.ts +0 -31
- package/dist/types/parse/ast/keyof.d.ts +0 -10
- package/dist/types/parse/ast/morph.d.ts +0 -18
- package/dist/types/parse/ast/narrow.d.ts +0 -21
- package/dist/types/parse/ast/node.d.ts +0 -35
- package/dist/types/parse/ast/tuple.d.ts +0 -41
- package/dist/types/parse/ast/union.d.ts +0 -17
- package/dist/types/parse/ast/utils.d.ts +0 -7
- package/dist/types/parse/definition.d.ts +0 -30
- package/dist/types/parse/record.d.ts +0 -26
- package/dist/types/parse/string/reduce/dynamic.d.ts +0 -34
- package/dist/types/parse/string/reduce/shared.d.ts +0 -25
- package/dist/types/parse/string/reduce/static.d.ts +0 -130
- package/dist/types/parse/string/shift/operand/enclosed.d.ts +0 -28
- package/dist/types/parse/string/shift/operand/operand.d.ts +0 -9
- package/dist/types/parse/string/shift/operand/unenclosed.d.ts +0 -18
- package/dist/types/parse/string/shift/operator/bounds.d.ts +0 -21
- package/dist/types/parse/string/shift/operator/divisor.d.ts +0 -13
- package/dist/types/parse/string/shift/operator/operator.d.ts +0 -13
- package/dist/types/parse/string/shift/scanner.d.ts +0 -89
- package/dist/types/parse/string/string.d.ts +0 -25
- package/dist/types/scopes/ark.d.ts +0 -209
- package/dist/types/scopes/cache.d.ts +0 -14
- package/dist/types/scopes/expressions.d.ts +0 -136
- package/dist/types/scopes/jsObjects.d.ts +0 -26
- package/dist/types/scopes/scope.d.ts +0 -99
- package/dist/types/scopes/tsKeywords.d.ts +0 -50
- package/dist/types/scopes/type.d.ts +0 -67
- package/dist/types/scopes/validation/creditCard.d.ts +0 -2
- package/dist/types/scopes/validation/validation.d.ts +0 -49
- package/dist/types/traverse/problems.d.ts +0 -88
- package/dist/types/traverse/traverse.d.ts +0 -55
- package/dist/types/utils/chainableNoOpProxy.d.ts +0 -14
- package/dist/types/utils/data.d.ts +0 -13
- package/dist/types/utils/domains.d.ts +0 -32
- package/dist/types/utils/errors.d.ts +0 -6
- package/dist/types/utils/freeze.d.ts +0 -2
- package/dist/types/utils/generics.d.ts +0 -125
- package/dist/types/utils/numericLiterals.d.ts +0 -46
- package/dist/types/utils/objectKinds.d.ts +0 -84
- package/dist/types/utils/paths.d.ts +0 -9
- package/dist/types/utils/serialize.d.ts +0 -37
- package/dist/types/utils/unionToTuple.d.ts +0 -11
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
flattenBranches: ()=>flattenBranches,
|
|
13
|
-
serializeDefinitionIfAllowed: ()=>serializeDefinitionIfAllowed,
|
|
14
|
-
serializeCase: ()=>serializeCase
|
|
15
|
-
});
|
|
16
|
-
const _unionJs = require("../parse/ast/union.js");
|
|
17
|
-
const _domainsJs = require("../utils/domains.js");
|
|
18
|
-
const _errorsJs = require("../utils/errors.js");
|
|
19
|
-
const _genericsJs = require("../utils/generics.js");
|
|
20
|
-
const _objectKindsJs = require("../utils/objectKinds.js");
|
|
21
|
-
const _pathsJs = require("../utils/paths.js");
|
|
22
|
-
const _serializeJs = require("../utils/serialize.js");
|
|
23
|
-
const _branchJs = require("./branch.js");
|
|
24
|
-
const _composeJs = require("./compose.js");
|
|
25
|
-
const _propsJs = require("./rules/props.js");
|
|
26
|
-
const flattenBranches = (branches, ctx)=>{
|
|
27
|
-
const discriminants = calculateDiscriminants(branches, ctx);
|
|
28
|
-
const indices = branches.map((_, i)=>i);
|
|
29
|
-
return discriminate(branches, indices, discriminants, ctx);
|
|
30
|
-
};
|
|
31
|
-
const discriminate = (originalBranches, remainingIndices, discriminants, ctx)=>{
|
|
32
|
-
if (remainingIndices.length === 1) {
|
|
33
|
-
return (0, _branchJs.flattenBranch)(originalBranches[remainingIndices[0]], ctx);
|
|
34
|
-
}
|
|
35
|
-
const bestDiscriminant = findBestDiscriminant(remainingIndices, discriminants);
|
|
36
|
-
if (!bestDiscriminant) {
|
|
37
|
-
return [
|
|
38
|
-
[
|
|
39
|
-
"branches",
|
|
40
|
-
remainingIndices.map((i)=>branchIncludesMorph(originalBranches[i], ctx.type.scope) ? (0, _errorsJs.throwParseError)((0, _unionJs.writeUndiscriminatableMorphUnionMessage)(`${ctx.path}`)) : (0, _branchJs.flattenBranch)(originalBranches[i], ctx))
|
|
41
|
-
]
|
|
42
|
-
];
|
|
43
|
-
}
|
|
44
|
-
const cases = {};
|
|
45
|
-
for(const caseKey in bestDiscriminant.indexCases){
|
|
46
|
-
const nextIndices = bestDiscriminant.indexCases[caseKey];
|
|
47
|
-
cases[caseKey] = discriminate(originalBranches, nextIndices, discriminants, ctx);
|
|
48
|
-
if (caseKey !== "default") {
|
|
49
|
-
pruneDiscriminant(cases[caseKey], bestDiscriminant.path, bestDiscriminant, ctx);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return [
|
|
53
|
-
[
|
|
54
|
-
"switch",
|
|
55
|
-
{
|
|
56
|
-
path: bestDiscriminant.path,
|
|
57
|
-
kind: bestDiscriminant.kind,
|
|
58
|
-
cases
|
|
59
|
-
}
|
|
60
|
-
]
|
|
61
|
-
];
|
|
62
|
-
};
|
|
63
|
-
const pruneDiscriminant = (entries, segments, discriminant, ctx)=>{
|
|
64
|
-
for(let i = 0; i < entries.length; i++){
|
|
65
|
-
const [k, v] = entries[i];
|
|
66
|
-
if (!segments.length) {
|
|
67
|
-
if (discriminant.kind === "domain") {
|
|
68
|
-
if (k === "domain" || k === "domains") {
|
|
69
|
-
entries.splice(i, 1);
|
|
70
|
-
return;
|
|
71
|
-
} else if (k === "class" || k === "value") {
|
|
72
|
-
// these keys imply a domain, but also add additional
|
|
73
|
-
// information, so can't be pruned
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
} else if (discriminant.kind === k) {
|
|
77
|
-
entries.splice(i, 1);
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
} else if ((k === "requiredProp" || k === "prerequisiteProp" || k === "optionalProp") && v[0] === segments[0]) {
|
|
81
|
-
if (typeof v[1] === "string") {
|
|
82
|
-
if (discriminant.kind !== "domain") {
|
|
83
|
-
return throwInternalPruneFailure(discriminant);
|
|
84
|
-
}
|
|
85
|
-
entries.splice(i, 1);
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
pruneDiscriminant(v[1], segments.slice(1), discriminant, ctx);
|
|
89
|
-
if (v[1].length === 0) {
|
|
90
|
-
entries.splice(i, 1);
|
|
91
|
-
}
|
|
92
|
-
return;
|
|
93
|
-
}
|
|
94
|
-
// check for branch keys, which must be traversed even if there are no
|
|
95
|
-
// segments left
|
|
96
|
-
if (k === "domains") {
|
|
97
|
-
/* c8 ignore next */ if ((0, _genericsJs.keyCount)(v) !== 1 || !v.object) {
|
|
98
|
-
return throwInternalPruneFailure(discriminant);
|
|
99
|
-
}
|
|
100
|
-
pruneDiscriminant(v.object, segments, discriminant, ctx);
|
|
101
|
-
return;
|
|
102
|
-
} else if (k === "switch") {
|
|
103
|
-
for(const caseKey in v.cases){
|
|
104
|
-
pruneDiscriminant(v.cases[caseKey], segments, discriminant, ctx);
|
|
105
|
-
}
|
|
106
|
-
return;
|
|
107
|
-
} else if (k === "branches") {
|
|
108
|
-
for (const branch of v){
|
|
109
|
-
pruneDiscriminant(branch, segments, discriminant, ctx);
|
|
110
|
-
}
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
return throwInternalPruneFailure(discriminant);
|
|
115
|
-
};
|
|
116
|
-
const throwInternalPruneFailure = (discriminant)=>(0, _errorsJs.throwInternalError)(`Unexpectedly failed to discriminate ${discriminant.kind} at path '${discriminant.path}'`);
|
|
117
|
-
const discriminantKinds = {
|
|
118
|
-
domain: true,
|
|
119
|
-
class: true,
|
|
120
|
-
value: true
|
|
121
|
-
};
|
|
122
|
-
const calculateDiscriminants = (branches, ctx)=>{
|
|
123
|
-
const discriminants = {
|
|
124
|
-
disjointsByPair: {},
|
|
125
|
-
casesByDisjoint: {}
|
|
126
|
-
};
|
|
127
|
-
for(let lIndex = 0; lIndex < branches.length - 1; lIndex++){
|
|
128
|
-
for(let rIndex = lIndex + 1; rIndex < branches.length; rIndex++){
|
|
129
|
-
const pairKey = `${lIndex}/${rIndex}`;
|
|
130
|
-
const pairDisjoints = [];
|
|
131
|
-
discriminants.disjointsByPair[pairKey] = pairDisjoints;
|
|
132
|
-
const intersectionState = new _composeJs.IntersectionState(ctx.type, "|");
|
|
133
|
-
(0, _branchJs.branchIntersection)(branches[lIndex], branches[rIndex], intersectionState);
|
|
134
|
-
for(const path in intersectionState.disjoints){
|
|
135
|
-
if (path.includes(_propsJs.mappedKeys.index)) {
|
|
136
|
-
continue;
|
|
137
|
-
}
|
|
138
|
-
const { l , r , kind , lOptional , rOptional } = intersectionState.disjoints[path];
|
|
139
|
-
if (!(0, _genericsJs.isKeyOf)(kind, discriminantKinds)) {
|
|
140
|
-
continue;
|
|
141
|
-
}
|
|
142
|
-
if (lOptional || rOptional) {
|
|
143
|
-
continue;
|
|
144
|
-
}
|
|
145
|
-
const lSerialized = serializeDefinitionIfAllowed(kind, l);
|
|
146
|
-
const rSerialized = serializeDefinitionIfAllowed(kind, r);
|
|
147
|
-
if (lSerialized === undefined || rSerialized === undefined) {
|
|
148
|
-
continue;
|
|
149
|
-
}
|
|
150
|
-
const qualifiedDisjoint = path === "/" ? kind : `${path}/${kind}`;
|
|
151
|
-
pairDisjoints.push(qualifiedDisjoint);
|
|
152
|
-
if (!discriminants.casesByDisjoint[qualifiedDisjoint]) {
|
|
153
|
-
discriminants.casesByDisjoint[qualifiedDisjoint] = {
|
|
154
|
-
[lSerialized]: [
|
|
155
|
-
lIndex
|
|
156
|
-
],
|
|
157
|
-
[rSerialized]: [
|
|
158
|
-
rIndex
|
|
159
|
-
]
|
|
160
|
-
};
|
|
161
|
-
continue;
|
|
162
|
-
}
|
|
163
|
-
const cases = discriminants.casesByDisjoint[qualifiedDisjoint];
|
|
164
|
-
const existingLBranch = cases[lSerialized];
|
|
165
|
-
if (!existingLBranch) {
|
|
166
|
-
cases[lSerialized] = [
|
|
167
|
-
lIndex
|
|
168
|
-
];
|
|
169
|
-
} else if (!existingLBranch.includes(lIndex)) {
|
|
170
|
-
existingLBranch.push(lIndex);
|
|
171
|
-
}
|
|
172
|
-
const existingRBranch = cases[rSerialized];
|
|
173
|
-
if (!existingRBranch) {
|
|
174
|
-
cases[rSerialized] = [
|
|
175
|
-
rIndex
|
|
176
|
-
];
|
|
177
|
-
} else if (!existingRBranch.includes(rIndex)) {
|
|
178
|
-
existingRBranch.push(rIndex);
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
return discriminants;
|
|
184
|
-
};
|
|
185
|
-
const parseQualifiedDisjoint = (qualifiedDisjoint)=>{
|
|
186
|
-
const path = _pathsJs.Path.fromString(qualifiedDisjoint);
|
|
187
|
-
return [
|
|
188
|
-
path,
|
|
189
|
-
path.pop()
|
|
190
|
-
];
|
|
191
|
-
};
|
|
192
|
-
const findBestDiscriminant = (remainingIndices, discriminants)=>{
|
|
193
|
-
let bestDiscriminant;
|
|
194
|
-
for(let i = 0; i < remainingIndices.length - 1; i++){
|
|
195
|
-
const lIndex = remainingIndices[i];
|
|
196
|
-
for(let j = i + 1; j < remainingIndices.length; j++){
|
|
197
|
-
const rIndex = remainingIndices[j];
|
|
198
|
-
const candidates = discriminants.disjointsByPair[`${lIndex}/${rIndex}`];
|
|
199
|
-
for (const qualifiedDisjoint of candidates){
|
|
200
|
-
const indexCases = discriminants.casesByDisjoint[qualifiedDisjoint];
|
|
201
|
-
const filteredCases = {};
|
|
202
|
-
const defaultCases = [
|
|
203
|
-
...remainingIndices
|
|
204
|
-
];
|
|
205
|
-
let score = 0;
|
|
206
|
-
for(const caseKey in indexCases){
|
|
207
|
-
const filteredIndices = indexCases[caseKey].filter((i)=>{
|
|
208
|
-
const remainingIndex = remainingIndices.indexOf(i);
|
|
209
|
-
if (remainingIndex !== -1) {
|
|
210
|
-
delete defaultCases[remainingIndex];
|
|
211
|
-
return true;
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
if (filteredIndices.length === 0) {
|
|
215
|
-
continue;
|
|
216
|
-
}
|
|
217
|
-
filteredCases[caseKey] = filteredIndices;
|
|
218
|
-
score++;
|
|
219
|
-
}
|
|
220
|
-
const defaultCaseKeys = (0, _genericsJs.objectKeysOf)(defaultCases);
|
|
221
|
-
if (defaultCaseKeys.length) {
|
|
222
|
-
filteredCases["default"] = defaultCaseKeys.map((k)=>parseInt(k));
|
|
223
|
-
}
|
|
224
|
-
if (!bestDiscriminant || score > bestDiscriminant.score) {
|
|
225
|
-
const [path, kind] = parseQualifiedDisjoint(qualifiedDisjoint);
|
|
226
|
-
bestDiscriminant = {
|
|
227
|
-
path,
|
|
228
|
-
kind,
|
|
229
|
-
indexCases: filteredCases,
|
|
230
|
-
score
|
|
231
|
-
};
|
|
232
|
-
if (score === remainingIndices.length) {
|
|
233
|
-
// if we find a candidate that discriminates all branches, return early
|
|
234
|
-
return bestDiscriminant;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
return bestDiscriminant;
|
|
241
|
-
};
|
|
242
|
-
const serializeDefinitionIfAllowed = (kind, definition)=>{
|
|
243
|
-
switch(kind){
|
|
244
|
-
case "value":
|
|
245
|
-
return serializeIfPrimitive(definition);
|
|
246
|
-
case "domain":
|
|
247
|
-
return definition;
|
|
248
|
-
case "class":
|
|
249
|
-
return (0, _objectKindsJs.getExactConstructorObjectKind)(definition);
|
|
250
|
-
default:
|
|
251
|
-
return;
|
|
252
|
-
}
|
|
253
|
-
};
|
|
254
|
-
const serializeIfPrimitive = (data)=>{
|
|
255
|
-
const domain = (0, _domainsJs.domainOf)(data);
|
|
256
|
-
return domain === "object" || domain === "symbol" ? undefined : (0, _serializeJs.serializePrimitive)(data);
|
|
257
|
-
};
|
|
258
|
-
const serializeData = {
|
|
259
|
-
value: (data)=>serializeIfPrimitive(data) ?? "default",
|
|
260
|
-
class: (data)=>(0, _objectKindsJs.objectKindOf)(data) ?? "default",
|
|
261
|
-
domain: _domainsJs.domainOf
|
|
262
|
-
};
|
|
263
|
-
const serializeCase = (kind, data)=>serializeData[kind](data);
|
|
264
|
-
const branchIncludesMorph = (branch, $)=>"morph" in branch ? true : "props" in branch ? Object.values(branch.props).some((prop)=>nodeIncludesMorph((0, _propsJs.propToNode)(prop), $)) : false;
|
|
265
|
-
const nodeIncludesMorph = (node, $)=>typeof node === "string" ? $.resolve(node).includesMorph : Object.values($.resolveTypeNode(node)).some((predicate)=>predicate === true ? false : (0, _objectKindsJs.isArray)(predicate) ? predicate.some((branch)=>branchIncludesMorph(branch, $)) : branchIncludesMorph(predicate, $));
|
package/dist/cjs/nodes/node.js
DELETED
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
isConfigNode: ()=>isConfigNode,
|
|
13
|
-
nodeIntersection: ()=>nodeIntersection,
|
|
14
|
-
rootIntersection: ()=>rootIntersection,
|
|
15
|
-
rootUnion: ()=>rootUnion,
|
|
16
|
-
flattenType: ()=>flattenType,
|
|
17
|
-
flattenNode: ()=>flattenNode,
|
|
18
|
-
flattenTypeNode: ()=>flattenTypeNode,
|
|
19
|
-
isLiteralNode: ()=>isLiteralNode,
|
|
20
|
-
resolutionExtendsDomain: ()=>resolutionExtendsDomain,
|
|
21
|
-
toArrayNode: ()=>toArrayNode
|
|
22
|
-
});
|
|
23
|
-
const _intersectionJs = require("../parse/ast/intersection.js");
|
|
24
|
-
const _errorsJs = require("../utils/errors.js");
|
|
25
|
-
const _genericsJs = require("../utils/generics.js");
|
|
26
|
-
const _pathsJs = require("../utils/paths.js");
|
|
27
|
-
const _composeJs = require("./compose.js");
|
|
28
|
-
const _predicateJs = require("./predicate.js");
|
|
29
|
-
const _propsJs = require("./rules/props.js");
|
|
30
|
-
const isConfigNode = (node)=>"config" in node;
|
|
31
|
-
const nodeIntersection = (l, r, state)=>{
|
|
32
|
-
state.domain = undefined;
|
|
33
|
-
const lDomains = state.type.scope.resolveTypeNode(l);
|
|
34
|
-
const rDomains = state.type.scope.resolveTypeNode(r);
|
|
35
|
-
const result = typeNodeIntersection(lDomains, rDomains, state);
|
|
36
|
-
if (typeof result === "object" && !(0, _genericsJs.hasKeys)(result)) {
|
|
37
|
-
return (0, _genericsJs.hasKeys)(state.disjoints) ? (0, _composeJs.anonymousDisjoint)() : state.addDisjoint("domain", (0, _genericsJs.objectKeysOf)(lDomains), (0, _genericsJs.objectKeysOf)(rDomains));
|
|
38
|
-
}
|
|
39
|
-
return result === lDomains ? l : result === rDomains ? r : result;
|
|
40
|
-
};
|
|
41
|
-
const typeNodeIntersection = (0, _composeJs.composeKeyedIntersection)((domain, l, r, context)=>{
|
|
42
|
-
if (l === undefined) {
|
|
43
|
-
return r === undefined ? (0, _errorsJs.throwInternalError)(_composeJs.undefinedOperandsMessage) : undefined;
|
|
44
|
-
}
|
|
45
|
-
if (r === undefined) {
|
|
46
|
-
return undefined;
|
|
47
|
-
}
|
|
48
|
-
return (0, _predicateJs.predicateIntersection)(domain, l, r, context);
|
|
49
|
-
}, {
|
|
50
|
-
onEmpty: "omit"
|
|
51
|
-
});
|
|
52
|
-
const rootIntersection = (l, r, type)=>{
|
|
53
|
-
const state = new _composeJs.IntersectionState(type, "&");
|
|
54
|
-
const result = nodeIntersection(l, r, state);
|
|
55
|
-
return (0, _composeJs.isDisjoint)(result) ? (0, _errorsJs.throwParseError)((0, _intersectionJs.compileDisjointReasonsMessage)(state.disjoints)) : (0, _composeJs.isEquality)(result) ? l : result;
|
|
56
|
-
};
|
|
57
|
-
const rootUnion = (l, r, type)=>{
|
|
58
|
-
const lDomains = type.scope.resolveTypeNode(l);
|
|
59
|
-
const rDomains = type.scope.resolveTypeNode(r);
|
|
60
|
-
const result = {};
|
|
61
|
-
const domains = (0, _genericsJs.objectKeysOf)({
|
|
62
|
-
...lDomains,
|
|
63
|
-
...rDomains
|
|
64
|
-
});
|
|
65
|
-
for (const domain of domains){
|
|
66
|
-
result[domain] = (0, _genericsJs.hasKey)(lDomains, domain) ? (0, _genericsJs.hasKey)(rDomains, domain) ? (0, _predicateJs.predicateUnion)(domain, lDomains[domain], rDomains[domain], type) : lDomains[domain] : (0, _genericsJs.hasKey)(rDomains, domain) ? rDomains[domain] : (0, _errorsJs.throwInternalError)(_composeJs.undefinedOperandsMessage);
|
|
67
|
-
}
|
|
68
|
-
return result;
|
|
69
|
-
};
|
|
70
|
-
const hasImpliedDomain = (flatPredicate)=>flatPredicate[0] && (flatPredicate[0][0] === "value" || flatPredicate[0][0] === "class");
|
|
71
|
-
const flattenType = (type)=>{
|
|
72
|
-
const ctx = {
|
|
73
|
-
type,
|
|
74
|
-
path: new _pathsJs.Path(),
|
|
75
|
-
lastDomain: "undefined"
|
|
76
|
-
};
|
|
77
|
-
return flattenNode(type.node, ctx);
|
|
78
|
-
};
|
|
79
|
-
const flattenNode = (node, ctx)=>{
|
|
80
|
-
if (typeof node === "string") {
|
|
81
|
-
return ctx.type.scope.resolve(node).flat;
|
|
82
|
-
}
|
|
83
|
-
const hasConfig = isConfigNode(node);
|
|
84
|
-
const flattenedTypeNode = flattenTypeNode(hasConfig ? node.node : node, ctx);
|
|
85
|
-
return hasConfig ? [
|
|
86
|
-
[
|
|
87
|
-
"config",
|
|
88
|
-
{
|
|
89
|
-
config: (0, _genericsJs.entriesOf)(node.config),
|
|
90
|
-
node: flattenedTypeNode
|
|
91
|
-
}
|
|
92
|
-
]
|
|
93
|
-
] : flattenedTypeNode;
|
|
94
|
-
};
|
|
95
|
-
const flattenTypeNode = (node, ctx)=>{
|
|
96
|
-
const domains = (0, _genericsJs.objectKeysOf)(node);
|
|
97
|
-
if (domains.length === 1) {
|
|
98
|
-
const domain = domains[0];
|
|
99
|
-
const predicate = node[domain];
|
|
100
|
-
if (predicate === true) {
|
|
101
|
-
return domain;
|
|
102
|
-
}
|
|
103
|
-
ctx.lastDomain = domain;
|
|
104
|
-
const flatPredicate = (0, _predicateJs.flattenPredicate)(predicate, ctx);
|
|
105
|
-
return hasImpliedDomain(flatPredicate) ? flatPredicate : [
|
|
106
|
-
[
|
|
107
|
-
"domain",
|
|
108
|
-
domain
|
|
109
|
-
],
|
|
110
|
-
...flatPredicate
|
|
111
|
-
];
|
|
112
|
-
}
|
|
113
|
-
const result = {};
|
|
114
|
-
for (const domain of domains){
|
|
115
|
-
ctx.lastDomain = domain;
|
|
116
|
-
result[domain] = (0, _predicateJs.flattenPredicate)(node[domain], ctx);
|
|
117
|
-
}
|
|
118
|
-
return [
|
|
119
|
-
[
|
|
120
|
-
"domains",
|
|
121
|
-
result
|
|
122
|
-
]
|
|
123
|
-
];
|
|
124
|
-
};
|
|
125
|
-
const isLiteralNode = (node, domain)=>{
|
|
126
|
-
return resolutionExtendsDomain(node, domain) && (0, _predicateJs.isLiteralCondition)(node[domain]);
|
|
127
|
-
};
|
|
128
|
-
const resolutionExtendsDomain = (resolution, domain)=>{
|
|
129
|
-
const domains = (0, _genericsJs.objectKeysOf)(resolution);
|
|
130
|
-
return domains.length === 1 && domains[0] === domain;
|
|
131
|
-
};
|
|
132
|
-
const toArrayNode = (node)=>({
|
|
133
|
-
object: {
|
|
134
|
-
class: Array,
|
|
135
|
-
props: {
|
|
136
|
-
[_propsJs.mappedKeys.index]: node
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
});
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
comparePredicates: ()=>comparePredicates,
|
|
13
|
-
predicateIntersection: ()=>predicateIntersection,
|
|
14
|
-
predicateUnion: ()=>predicateUnion,
|
|
15
|
-
flattenPredicate: ()=>flattenPredicate,
|
|
16
|
-
isLiteralCondition: ()=>isLiteralCondition
|
|
17
|
-
});
|
|
18
|
-
const _genericsJs = require("../utils/generics.js");
|
|
19
|
-
const _objectKindsJs = require("../utils/objectKinds.js");
|
|
20
|
-
const _branchJs = require("./branch.js");
|
|
21
|
-
const _composeJs = require("./compose.js");
|
|
22
|
-
const _discriminateJs = require("./discriminate.js");
|
|
23
|
-
const emptyRulesIfTrue = (predicate)=>predicate === true ? {} : predicate;
|
|
24
|
-
const comparePredicates = (l, r, context)=>{
|
|
25
|
-
if (l === true && r === true) {
|
|
26
|
-
return (0, _composeJs.equality)();
|
|
27
|
-
}
|
|
28
|
-
if (!(0, _objectKindsJs.isArray)(l) && !(0, _objectKindsJs.isArray)(r)) {
|
|
29
|
-
const result = (0, _branchJs.branchIntersection)(emptyRulesIfTrue(l), emptyRulesIfTrue(r), context);
|
|
30
|
-
return result === l ? l : result === r ? r : result;
|
|
31
|
-
}
|
|
32
|
-
const lBranches = (0, _genericsJs.listFrom)(emptyRulesIfTrue(l));
|
|
33
|
-
const rBranches = (0, _genericsJs.listFrom)(emptyRulesIfTrue(r));
|
|
34
|
-
const comparison = (0, _branchJs.compareBranches)(lBranches, rBranches, context);
|
|
35
|
-
if (comparison.equalities.length === lBranches.length && comparison.equalities.length === rBranches.length) {
|
|
36
|
-
return (0, _composeJs.equality)();
|
|
37
|
-
}
|
|
38
|
-
if (comparison.lExtendsR.length + comparison.equalities.length === lBranches.length) {
|
|
39
|
-
return l;
|
|
40
|
-
}
|
|
41
|
-
if (comparison.rExtendsL.length + comparison.equalities.length === rBranches.length) {
|
|
42
|
-
return r;
|
|
43
|
-
}
|
|
44
|
-
return comparison;
|
|
45
|
-
};
|
|
46
|
-
const predicateIntersection = (domain, l, r, state)=>{
|
|
47
|
-
state.domain = domain;
|
|
48
|
-
const comparison = comparePredicates(l, r, state);
|
|
49
|
-
if (!(0, _branchJs.isBranchComparison)(comparison)) {
|
|
50
|
-
return comparison;
|
|
51
|
-
}
|
|
52
|
-
const resultBranches = [
|
|
53
|
-
...comparison.distinctIntersections,
|
|
54
|
-
...comparison.equalities.map((indices)=>comparison.lBranches[indices[0]]),
|
|
55
|
-
...comparison.lExtendsR.map((lIndex)=>comparison.lBranches[lIndex]),
|
|
56
|
-
...comparison.rExtendsL.map((rIndex)=>comparison.rBranches[rIndex])
|
|
57
|
-
];
|
|
58
|
-
if (resultBranches.length === 0) {
|
|
59
|
-
state.addDisjoint("union", comparison.lBranches, comparison.rBranches);
|
|
60
|
-
}
|
|
61
|
-
return resultBranches.length === 1 ? resultBranches[0] : resultBranches;
|
|
62
|
-
};
|
|
63
|
-
const predicateUnion = (domain, l, r, type)=>{
|
|
64
|
-
const state = new _composeJs.IntersectionState(type, "|");
|
|
65
|
-
const comparison = comparePredicates(l, r, state);
|
|
66
|
-
if (!(0, _branchJs.isBranchComparison)(comparison)) {
|
|
67
|
-
return (0, _composeJs.isEquality)(comparison) || comparison === l ? r : comparison === r ? l : // subtype of the other, it consists of two opposite literals
|
|
68
|
-
// and can be simplified to a non-literal boolean.
|
|
69
|
-
domain === "boolean" ? true : [
|
|
70
|
-
emptyRulesIfTrue(l),
|
|
71
|
-
emptyRulesIfTrue(r)
|
|
72
|
-
];
|
|
73
|
-
}
|
|
74
|
-
const resultBranches = [
|
|
75
|
-
...comparison.lBranches.filter((_, lIndex)=>!comparison.lExtendsR.includes(lIndex) && !comparison.equalities.some((indexPair)=>indexPair[0] === lIndex)),
|
|
76
|
-
...comparison.rBranches.filter((_, rIndex)=>!comparison.rExtendsL.includes(rIndex) && !comparison.equalities.some((indexPair)=>indexPair[1] === rIndex))
|
|
77
|
-
];
|
|
78
|
-
return resultBranches.length === 1 ? resultBranches[0] : resultBranches;
|
|
79
|
-
};
|
|
80
|
-
const flattenPredicate = (predicate, context)=>{
|
|
81
|
-
if (predicate === true) {
|
|
82
|
-
return [];
|
|
83
|
-
}
|
|
84
|
-
return (0, _objectKindsJs.isArray)(predicate) ? (0, _discriminateJs.flattenBranches)(predicate, context) : (0, _branchJs.flattenBranch)(predicate, context);
|
|
85
|
-
};
|
|
86
|
-
const isLiteralCondition = (predicate)=>typeof predicate === "object" && "value" in predicate;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
classIntersection: ()=>classIntersection,
|
|
13
|
-
checkClass: ()=>checkClass
|
|
14
|
-
});
|
|
15
|
-
const _objectKindsJs = require("../../utils/objectKinds.js");
|
|
16
|
-
const _composeJs = require("../compose.js");
|
|
17
|
-
const classIntersection = (0, _composeJs.composeIntersection)((l, r, state)=>{
|
|
18
|
-
return l === r ? (0, _composeJs.equality)() : l instanceof r ? l : r instanceof l ? r : state.addDisjoint("class", l, r);
|
|
19
|
-
});
|
|
20
|
-
const checkClass = (expectedClass, state)=>{
|
|
21
|
-
if (typeof expectedClass === "string") {
|
|
22
|
-
return (0, _objectKindsJs.objectKindOf)(state.data) === expectedClass || !state.problems.add("class", expectedClass);
|
|
23
|
-
}
|
|
24
|
-
return state.data instanceof expectedClass || !state.problems.add("class", expectedClass);
|
|
25
|
-
};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
collapsibleListUnion: ()=>collapsibleListUnion,
|
|
13
|
-
listUnion: ()=>listUnion
|
|
14
|
-
});
|
|
15
|
-
const _composeJs = require("../compose.js");
|
|
16
|
-
const collapsibleListUnion = (l, r)=>{
|
|
17
|
-
if (Array.isArray(l)) {
|
|
18
|
-
if (Array.isArray(r)) {
|
|
19
|
-
const result = listUnion(l, r);
|
|
20
|
-
return result.length === l.length ? result.length === r.length ? (0, _composeJs.equality)() : l : result.length === r.length ? r : result;
|
|
21
|
-
}
|
|
22
|
-
return l.includes(r) ? l : [
|
|
23
|
-
...l,
|
|
24
|
-
r
|
|
25
|
-
];
|
|
26
|
-
}
|
|
27
|
-
if (Array.isArray(r)) {
|
|
28
|
-
return r.includes(l) ? r : [
|
|
29
|
-
...r,
|
|
30
|
-
l
|
|
31
|
-
];
|
|
32
|
-
}
|
|
33
|
-
return l === r ? (0, _composeJs.equality)() : [
|
|
34
|
-
l,
|
|
35
|
-
r
|
|
36
|
-
];
|
|
37
|
-
};
|
|
38
|
-
const listUnion = (l, r)=>{
|
|
39
|
-
const result = [
|
|
40
|
-
...l
|
|
41
|
-
];
|
|
42
|
-
for (const expression of r){
|
|
43
|
-
if (!l.includes(expression)) {
|
|
44
|
-
result.push(expression);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return result;
|
|
48
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
divisorIntersection: ()=>divisorIntersection,
|
|
13
|
-
checkDivisor: ()=>checkDivisor
|
|
14
|
-
});
|
|
15
|
-
const _composeJs = require("../compose.js");
|
|
16
|
-
const divisorIntersection = (0, _composeJs.composeIntersection)((l, r)=>l === r ? (0, _composeJs.equality)() : Math.abs(l * r / greatestCommonDivisor(l, r)));
|
|
17
|
-
// https://en.wikipedia.org/wiki/Euclidean_algorithm
|
|
18
|
-
const greatestCommonDivisor = (l, r)=>{
|
|
19
|
-
let previous;
|
|
20
|
-
let greatestCommonDivisor = l;
|
|
21
|
-
let current = r;
|
|
22
|
-
while(current !== 0){
|
|
23
|
-
previous = current;
|
|
24
|
-
current = greatestCommonDivisor % current;
|
|
25
|
-
greatestCommonDivisor = previous;
|
|
26
|
-
}
|
|
27
|
-
return greatestCommonDivisor;
|
|
28
|
-
};
|
|
29
|
-
const checkDivisor = (divisor, state)=>state.data % divisor === 0 || !state.problems.add("divisor", divisor);
|