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
|
@@ -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;
|
package/dist/parse/ast/config.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseConfigTuple = void 0;
|
|
4
|
-
const definition_js_1 = require("../definition.js");
|
|
5
|
-
/**
|
|
6
|
-
* @operator {@link parseConfigTuple | :}
|
|
7
|
-
* @docgenTable
|
|
8
|
-
* @tuple ["type", ":", config]
|
|
9
|
-
*/
|
|
10
|
-
const parseConfigTuple = (def, ctx) => ({
|
|
11
|
-
node: ctx.type.scope.resolveTypeNode((0, definition_js_1.parseDefinition)(def[0], ctx)),
|
|
12
|
-
config: def[2]
|
|
13
|
-
});
|
|
14
|
-
exports.parseConfigTuple = parseConfigTuple;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.distributeFunctionToNode = exports.writeMalformedDistributableFunctionMessage = void 0;
|
|
4
|
-
const domains_js_1 = require("../../utils/domains.js");
|
|
5
|
-
const errors_js_1 = require("../../utils/errors.js");
|
|
6
|
-
const generics_js_1 = require("../../utils/generics.js");
|
|
7
|
-
const serialize_js_1 = require("../../utils/serialize.js");
|
|
8
|
-
const writeMalformedDistributableFunctionMessage = (def) => `Expected a Function or Record<Domain, Function> operand (${(0, serialize_js_1.stringify)(def)} was invalid)`;
|
|
9
|
-
exports.writeMalformedDistributableFunctionMessage = writeMalformedDistributableFunctionMessage;
|
|
10
|
-
const distributeFunctionToNode = (distributableFunction, node, ctx, ruleKey) => {
|
|
11
|
-
const domains = (0, generics_js_1.objectKeysOf)(node);
|
|
12
|
-
if (!(0, domains_js_1.hasDomain)(distributableFunction, "object")) {
|
|
13
|
-
return (0, errors_js_1.throwParseError)((0, exports.writeMalformedDistributableFunctionMessage)(distributableFunction));
|
|
14
|
-
}
|
|
15
|
-
const distributed = {};
|
|
16
|
-
if (typeof distributableFunction === "function") {
|
|
17
|
-
const domainFunction = {
|
|
18
|
-
[ruleKey]: distributableFunction
|
|
19
|
-
};
|
|
20
|
-
for (const domain of domains) {
|
|
21
|
-
distributed[domain] = domainFunction;
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
for (const domain of domains) {
|
|
26
|
-
if (distributableFunction[domain] === undefined) {
|
|
27
|
-
continue;
|
|
28
|
-
}
|
|
29
|
-
const functionInDomain = {
|
|
30
|
-
[ruleKey]: distributableFunction[domain]
|
|
31
|
-
};
|
|
32
|
-
if (typeof functionInDomain[ruleKey] !== "function") {
|
|
33
|
-
return (0, errors_js_1.throwParseError)((0, exports.writeMalformedDistributableFunctionMessage)(functionInDomain));
|
|
34
|
-
}
|
|
35
|
-
distributed[domain] = functionInDomain;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return distributed;
|
|
39
|
-
};
|
|
40
|
-
exports.distributeFunctionToNode = distributeFunctionToNode;
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.writeIndivisibleMessage = void 0;
|
|
4
|
-
const writeIndivisibleMessage = (root) => `Divisibility operand ${root} must be a number`;
|
|
5
|
-
exports.writeIndivisibleMessage = writeIndivisibleMessage;
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.writeImplicitNeverMessage = exports.compileDisjointReasonsMessage = void 0;
|
|
4
|
-
const compose_js_1 = require("../../nodes/compose.js");
|
|
5
|
-
const generics_js_1 = require("../../utils/generics.js");
|
|
6
|
-
const compileDisjointReasonsMessage = (disjoints) => {
|
|
7
|
-
const paths = (0, generics_js_1.objectKeysOf)(disjoints);
|
|
8
|
-
if (paths.length === 1) {
|
|
9
|
-
const path = paths[0];
|
|
10
|
-
return `${path === "/" ? "" : `At ${path}: `}Intersection of ${compose_js_1.disjointDescriptionWriters[disjoints[path].kind](disjoints[path])} results in an unsatisfiable type`;
|
|
11
|
-
}
|
|
12
|
-
let message = `
|
|
13
|
-
"Intersection results in unsatisfiable types at the following paths:\n`;
|
|
14
|
-
for (const path in disjoints) {
|
|
15
|
-
message += ` ${path}: ${compose_js_1.disjointDescriptionWriters[disjoints[path].kind](disjoints[path])}\n`;
|
|
16
|
-
}
|
|
17
|
-
return message;
|
|
18
|
-
};
|
|
19
|
-
exports.compileDisjointReasonsMessage = compileDisjointReasonsMessage;
|
|
20
|
-
const writeImplicitNeverMessage = (path, operator, description) => `${path.length ? `At ${path}: ` : ""}${operator} ${description ? `${description} ` : ""}results in an unsatisfiable type`;
|
|
21
|
-
exports.writeImplicitNeverMessage = writeImplicitNeverMessage;
|
package/dist/parse/ast/keyof.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseKeyOfTuple = void 0;
|
|
4
|
-
const props_js_1 = require("../../nodes/rules/props.js");
|
|
5
|
-
const errors_js_1 = require("../../utils/errors.js");
|
|
6
|
-
const freeze_js_1 = require("../../utils/freeze.js");
|
|
7
|
-
const generics_js_1 = require("../../utils/generics.js");
|
|
8
|
-
const numericLiterals_js_1 = require("../../utils/numericLiterals.js");
|
|
9
|
-
const objectKinds_js_1 = require("../../utils/objectKinds.js");
|
|
10
|
-
const serialize_js_1 = require("../../utils/serialize.js");
|
|
11
|
-
const definition_js_1 = require("../definition.js");
|
|
12
|
-
const intersection_js_1 = require("./intersection.js");
|
|
13
|
-
const arrayIndexStringBranch = (0, freeze_js_1.deepFreeze)({
|
|
14
|
-
regex: numericLiterals_js_1.wellFormedNonNegativeIntegerMatcher.source
|
|
15
|
-
});
|
|
16
|
-
const arrayIndexNumberBranch = (0, freeze_js_1.deepFreeze)({
|
|
17
|
-
range: { min: { comparator: ">=", limit: 0 } },
|
|
18
|
-
divisor: 1
|
|
19
|
-
});
|
|
20
|
-
const parseKeyOfTuple = (def, ctx) => {
|
|
21
|
-
const resolution = ctx.type.scope.resolveNode((0, definition_js_1.parseDefinition)(def[1], ctx));
|
|
22
|
-
const predicateKeys = (0, generics_js_1.objectKeysOf)(resolution).map((domain) => keysOfPredicate(domain, resolution[domain]));
|
|
23
|
-
const sharedKeys = sharedKeysOf(predicateKeys);
|
|
24
|
-
if (!sharedKeys.length) {
|
|
25
|
-
return (0, intersection_js_1.writeImplicitNeverMessage)(ctx.path, "keyof");
|
|
26
|
-
}
|
|
27
|
-
const keyNode = {};
|
|
28
|
-
for (const key of sharedKeys) {
|
|
29
|
-
const keyType = typeof key;
|
|
30
|
-
if (keyType === "string" ||
|
|
31
|
-
keyType === "number" ||
|
|
32
|
-
keyType === "symbol") {
|
|
33
|
-
keyNode[keyType] ??= [];
|
|
34
|
-
keyNode[keyType].push({ value: key });
|
|
35
|
-
}
|
|
36
|
-
else if (key === numericLiterals_js_1.wellFormedNonNegativeIntegerMatcher) {
|
|
37
|
-
keyNode.string ??= [];
|
|
38
|
-
keyNode.string.push(arrayIndexStringBranch);
|
|
39
|
-
keyNode.number ??= [];
|
|
40
|
-
keyNode.number.push(arrayIndexNumberBranch);
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
return (0, errors_js_1.throwInternalError)(`Unexpected keyof key '${(0, serialize_js_1.stringify)(key)}'`);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return Object.fromEntries(Object.entries(keyNode).map(([domain, branches]) => [
|
|
47
|
-
domain,
|
|
48
|
-
branches.length === 1 ? branches[0] : branches
|
|
49
|
-
]));
|
|
50
|
-
};
|
|
51
|
-
exports.parseKeyOfTuple = parseKeyOfTuple;
|
|
52
|
-
const baseKeysByDomain = {
|
|
53
|
-
bigint: (0, generics_js_1.prototypeKeysOf)(0n),
|
|
54
|
-
boolean: (0, generics_js_1.prototypeKeysOf)(false),
|
|
55
|
-
null: [],
|
|
56
|
-
number: (0, generics_js_1.prototypeKeysOf)(0),
|
|
57
|
-
// TS doesn't include the Object prototype in keyof, so keyof object is never
|
|
58
|
-
object: [],
|
|
59
|
-
string: (0, generics_js_1.prototypeKeysOf)(""),
|
|
60
|
-
symbol: (0, generics_js_1.prototypeKeysOf)(Symbol()),
|
|
61
|
-
undefined: []
|
|
62
|
-
};
|
|
63
|
-
const keysOfPredicate = (domain, predicate) => domain !== "object" || predicate === true
|
|
64
|
-
? baseKeysByDomain[domain]
|
|
65
|
-
: sharedKeysOf((0, generics_js_1.listFrom)(predicate).map((branch) => keysOfObjectBranch(branch)));
|
|
66
|
-
const sharedKeysOf = (keyBranches) => {
|
|
67
|
-
if (!keyBranches.length) {
|
|
68
|
-
return [];
|
|
69
|
-
}
|
|
70
|
-
let sharedKeys = keyBranches[0];
|
|
71
|
-
for (let i = 1; i < keyBranches.length; i++) {
|
|
72
|
-
// we can filter directly by equality here because the RegExp we're
|
|
73
|
-
// using will always be reference equal to
|
|
74
|
-
// wellFormedNonNegativeIntegerMatcher
|
|
75
|
-
sharedKeys = sharedKeys.filter((k) => keyBranches[i].includes(k));
|
|
76
|
-
}
|
|
77
|
-
return sharedKeys;
|
|
78
|
-
};
|
|
79
|
-
const keysOfObjectBranch = (branch) => {
|
|
80
|
-
const result = [];
|
|
81
|
-
if ("props" in branch) {
|
|
82
|
-
for (const key of Object.keys(branch.props)) {
|
|
83
|
-
if (key === props_js_1.mappedKeys.index) {
|
|
84
|
-
// if any number is a valid key push this RegExp
|
|
85
|
-
result.push(numericLiterals_js_1.wellFormedNonNegativeIntegerMatcher);
|
|
86
|
-
}
|
|
87
|
-
else if (!result.includes(key)) {
|
|
88
|
-
result.push(key);
|
|
89
|
-
if (numericLiterals_js_1.wellFormedNonNegativeIntegerMatcher.test(key)) {
|
|
90
|
-
// allow numeric access to keys
|
|
91
|
-
result.push((0, numericLiterals_js_1.tryParseWellFormedInteger)(key, `Unexpectedly failed to parse an integer from key '${key}'`));
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
if ("class" in branch) {
|
|
97
|
-
const constructor = typeof branch.class === "string"
|
|
98
|
-
? objectKinds_js_1.defaultObjectKinds[branch.class]
|
|
99
|
-
: branch.class;
|
|
100
|
-
for (const key of (0, generics_js_1.prototypeKeysOf)(constructor.prototype)) {
|
|
101
|
-
if (!result.includes(key)) {
|
|
102
|
-
result.push(key);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
return result;
|
|
107
|
-
};
|
package/dist/parse/ast/morph.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.writeMalformedMorphExpressionMessage = exports.parseMorphTuple = void 0;
|
|
4
|
-
const branch_js_1 = require("../../nodes/branch.js");
|
|
5
|
-
const errors_js_1 = require("../../utils/errors.js");
|
|
6
|
-
const objectKinds_js_1 = require("../../utils/objectKinds.js");
|
|
7
|
-
const serialize_js_1 = require("../../utils/serialize.js");
|
|
8
|
-
const definition_js_1 = require("../definition.js");
|
|
9
|
-
const parseMorphTuple = (def, ctx) => {
|
|
10
|
-
if (typeof def[2] !== "function") {
|
|
11
|
-
return (0, errors_js_1.throwParseError)((0, exports.writeMalformedMorphExpressionMessage)(def[2]));
|
|
12
|
-
}
|
|
13
|
-
const node = (0, definition_js_1.parseDefinition)(def[0], ctx);
|
|
14
|
-
const resolution = ctx.type.scope.resolveTypeNode(node);
|
|
15
|
-
const morph = def[2];
|
|
16
|
-
ctx.type.includesMorph = true;
|
|
17
|
-
let domain;
|
|
18
|
-
const result = {};
|
|
19
|
-
for (domain in resolution) {
|
|
20
|
-
const predicate = resolution[domain];
|
|
21
|
-
if (predicate === true) {
|
|
22
|
-
result[domain] = { rules: {}, morph };
|
|
23
|
-
}
|
|
24
|
-
else if (typeof predicate === "object") {
|
|
25
|
-
result[domain] = (0, objectKinds_js_1.isArray)(predicate)
|
|
26
|
-
? predicate.map((branch) => applyMorph(branch, morph))
|
|
27
|
-
: applyMorph(predicate, morph);
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
(0, errors_js_1.throwInternalError)(`Unexpected predicate value for domain '${domain}': ${(0, serialize_js_1.stringify)(predicate)}`);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return result;
|
|
34
|
-
};
|
|
35
|
-
exports.parseMorphTuple = parseMorphTuple;
|
|
36
|
-
const applyMorph = (branch, morph) => (0, branch_js_1.isTransformationBranch)(branch)
|
|
37
|
-
? {
|
|
38
|
-
...branch,
|
|
39
|
-
morph: branch.morph
|
|
40
|
-
? Array.isArray(branch.morph)
|
|
41
|
-
? [...branch.morph, morph]
|
|
42
|
-
: [branch.morph, morph]
|
|
43
|
-
: morph
|
|
44
|
-
}
|
|
45
|
-
: {
|
|
46
|
-
rules: branch,
|
|
47
|
-
morph
|
|
48
|
-
};
|
|
49
|
-
const writeMalformedMorphExpressionMessage = (value) => `Morph expression requires a function following '|>' (was ${typeof value})`;
|
|
50
|
-
exports.writeMalformedMorphExpressionMessage = writeMalformedMorphExpressionMessage;
|
package/dist/parse/ast/narrow.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseNarrowTuple = void 0;
|
|
4
|
-
const node_js_1 = require("../../nodes/node.js");
|
|
5
|
-
const definition_js_1 = require("../definition.js");
|
|
6
|
-
const distributableFunction_js_1 = require("./distributableFunction.js");
|
|
7
|
-
const parseNarrowTuple = (def, ctx) => {
|
|
8
|
-
const inputNode = (0, definition_js_1.parseDefinition)(def[0], ctx);
|
|
9
|
-
const resolution = ctx.type.scope.resolveNode(inputNode);
|
|
10
|
-
const hasConfig = (0, node_js_1.isConfigNode)(resolution);
|
|
11
|
-
const typeNode = hasConfig ? resolution.node : resolution;
|
|
12
|
-
const result = (0, node_js_1.rootIntersection)(inputNode, (0, distributableFunction_js_1.distributeFunctionToNode)(def[2], typeNode, ctx, "narrow"), ctx.type);
|
|
13
|
-
return hasConfig
|
|
14
|
-
? { config: resolution.config, node: result }
|
|
15
|
-
: result;
|
|
16
|
-
};
|
|
17
|
-
exports.parseNarrowTuple = parseNarrowTuple;
|
package/dist/parse/ast/node.js
DELETED
package/dist/parse/ast/tuple.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.writeMalformedFunctionalExpressionMessage = exports.parseTuple = void 0;
|
|
4
|
-
const node_js_1 = require("../../nodes/node.js");
|
|
5
|
-
const domains_js_1 = require("../../utils/domains.js");
|
|
6
|
-
const errors_js_1 = require("../../utils/errors.js");
|
|
7
|
-
const definition_js_1 = require("../definition.js");
|
|
8
|
-
const unenclosed_js_1 = require("../string/shift/operand/unenclosed.js");
|
|
9
|
-
const config_js_1 = require("./config.js");
|
|
10
|
-
const keyof_js_1 = require("./keyof.js");
|
|
11
|
-
const morph_js_1 = require("./morph.js");
|
|
12
|
-
const narrow_js_1 = require("./narrow.js");
|
|
13
|
-
const parseTuple = (def, ctx) => {
|
|
14
|
-
if (isIndexOneExpression(def)) {
|
|
15
|
-
return indexOneParsers[def[1]](def, ctx);
|
|
16
|
-
}
|
|
17
|
-
if (isIndexZeroExpression(def)) {
|
|
18
|
-
return prefixParsers[def[0]](def, ctx);
|
|
19
|
-
}
|
|
20
|
-
const props = {
|
|
21
|
-
// length is created as a prerequisite prop, ensuring if it is invalid,
|
|
22
|
-
// no other props will be checked, which is usually desirable for tuple
|
|
23
|
-
// definitions.
|
|
24
|
-
length: ["!", { number: { value: def.length } }]
|
|
25
|
-
};
|
|
26
|
-
for (let i = 0; i < def.length; i++) {
|
|
27
|
-
ctx.path.push(`${i}`);
|
|
28
|
-
props[i] = (0, definition_js_1.parseDefinition)(def[i], ctx);
|
|
29
|
-
ctx.path.pop();
|
|
30
|
-
}
|
|
31
|
-
return {
|
|
32
|
-
object: {
|
|
33
|
-
class: Array,
|
|
34
|
-
props
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
exports.parseTuple = parseTuple;
|
|
39
|
-
const parseBranchTuple = (def, ctx) => {
|
|
40
|
-
if (def[2] === undefined) {
|
|
41
|
-
return (0, errors_js_1.throwParseError)((0, unenclosed_js_1.writeMissingRightOperandMessage)(def[1], ""));
|
|
42
|
-
}
|
|
43
|
-
const l = (0, definition_js_1.parseDefinition)(def[0], ctx);
|
|
44
|
-
const r = (0, definition_js_1.parseDefinition)(def[2], ctx);
|
|
45
|
-
return def[1] === "&"
|
|
46
|
-
? (0, node_js_1.rootIntersection)(l, r, ctx.type)
|
|
47
|
-
: (0, node_js_1.rootUnion)(l, r, ctx.type);
|
|
48
|
-
};
|
|
49
|
-
const parseArrayTuple = (def, scope) => (0, node_js_1.toArrayNode)((0, definition_js_1.parseDefinition)(def[0], scope));
|
|
50
|
-
const writeMalformedFunctionalExpressionMessage = (operator, rightDef) => `Expression requires a function following '${operator}' (was ${typeof rightDef})`;
|
|
51
|
-
exports.writeMalformedFunctionalExpressionMessage = writeMalformedFunctionalExpressionMessage;
|
|
52
|
-
const isIndexOneExpression = (def) => indexOneParsers[def[1]] !== undefined;
|
|
53
|
-
const indexOneParsers = {
|
|
54
|
-
"|": parseBranchTuple,
|
|
55
|
-
"&": parseBranchTuple,
|
|
56
|
-
"[]": parseArrayTuple,
|
|
57
|
-
"=>": narrow_js_1.parseNarrowTuple,
|
|
58
|
-
"|>": morph_js_1.parseMorphTuple,
|
|
59
|
-
":": config_js_1.parseConfigTuple
|
|
60
|
-
};
|
|
61
|
-
const prefixParsers = {
|
|
62
|
-
keyof: keyof_js_1.parseKeyOfTuple,
|
|
63
|
-
instanceof: (def) => {
|
|
64
|
-
if (typeof def[1] !== "function") {
|
|
65
|
-
return (0, errors_js_1.throwParseError)(`Expected a constructor following 'instanceof' operator (was ${typeof def[1]}).`);
|
|
66
|
-
}
|
|
67
|
-
return { object: { class: def[1] } };
|
|
68
|
-
},
|
|
69
|
-
"===": (def) => ({ [(0, domains_js_1.domainOf)(def[1])]: { value: def[1] } }),
|
|
70
|
-
node: (def) => def[1]
|
|
71
|
-
};
|
|
72
|
-
const isIndexZeroExpression = (def) => prefixParsers[def[0]] !== undefined;
|
package/dist/parse/ast/union.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.writeUndiscriminatableMorphUnionMessage = void 0;
|
|
4
|
-
const writeUndiscriminatableMorphUnionMessage = (path) => `${path === "/" ? "A" : `At ${path}, a`} union including one or more morphs must be discriminatable`;
|
|
5
|
-
exports.writeUndiscriminatableMorphUnionMessage = writeUndiscriminatableMorphUnionMessage;
|
package/dist/parse/ast/utils.js
DELETED
package/dist/parse/definition.js
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.writeBadDefinitionTypeMessage = exports.as = exports.parseDefinition = void 0;
|
|
4
|
-
const type_js_1 = require("../scopes/type.js");
|
|
5
|
-
const domains_js_1 = require("../utils/domains.js");
|
|
6
|
-
const errors_js_1 = require("../utils/errors.js");
|
|
7
|
-
const objectKinds_js_1 = require("../utils/objectKinds.js");
|
|
8
|
-
const serialize_js_1 = require("../utils/serialize.js");
|
|
9
|
-
const tuple_js_1 = require("./ast/tuple.js");
|
|
10
|
-
const record_js_1 = require("./record.js");
|
|
11
|
-
const string_js_1 = require("./string/string.js");
|
|
12
|
-
const parseDefinition = (def, ctx) => {
|
|
13
|
-
const domain = (0, domains_js_1.domainOf)(def);
|
|
14
|
-
if (domain === "string") {
|
|
15
|
-
return (0, string_js_1.parseString)(def, ctx);
|
|
16
|
-
}
|
|
17
|
-
if (domain !== "object") {
|
|
18
|
-
return (0, errors_js_1.throwParseError)((0, exports.writeBadDefinitionTypeMessage)(domain));
|
|
19
|
-
}
|
|
20
|
-
const objectKind = (0, objectKinds_js_1.objectKindOf)(def);
|
|
21
|
-
switch (objectKind) {
|
|
22
|
-
case "Object":
|
|
23
|
-
return (0, record_js_1.parseRecord)(def, ctx);
|
|
24
|
-
case "Array":
|
|
25
|
-
return (0, tuple_js_1.parseTuple)(def, ctx);
|
|
26
|
-
case "RegExp":
|
|
27
|
-
return { string: { regex: def.source } };
|
|
28
|
-
case "Function":
|
|
29
|
-
if ((0, type_js_1.isType)(def)) {
|
|
30
|
-
return ctx.type.scope.addAnonymousTypeReference(def, ctx);
|
|
31
|
-
}
|
|
32
|
-
if (isThunk(def)) {
|
|
33
|
-
const returned = def();
|
|
34
|
-
if ((0, type_js_1.isType)(returned)) {
|
|
35
|
-
return ctx.type.scope.addAnonymousTypeReference(returned, ctx);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
return (0, errors_js_1.throwParseError)((0, exports.writeBadDefinitionTypeMessage)("Function"));
|
|
39
|
-
default:
|
|
40
|
-
return (0, errors_js_1.throwParseError)((0, exports.writeBadDefinitionTypeMessage)(objectKind ?? (0, serialize_js_1.stringify)(def)));
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
exports.parseDefinition = parseDefinition;
|
|
44
|
-
exports.as = Symbol("as");
|
|
45
|
-
const isThunk = (def) => typeof def === "function" && def.length === 0;
|
|
46
|
-
const writeBadDefinitionTypeMessage = (actual) => `Type definitions must be strings or objects (was ${actual})`;
|
|
47
|
-
exports.writeBadDefinitionTypeMessage = writeBadDefinitionTypeMessage;
|
package/dist/parse/record.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseRecord = void 0;
|
|
4
|
-
const definition_js_1 = require("./definition.js");
|
|
5
|
-
const scanner_js_1 = require("./string/shift/scanner.js");
|
|
6
|
-
const parseRecord = (def, ctx) => {
|
|
7
|
-
const props = {};
|
|
8
|
-
for (const definitionKey in def) {
|
|
9
|
-
let keyName = definitionKey;
|
|
10
|
-
let isOptional = false;
|
|
11
|
-
if (definitionKey[definitionKey.length - 1] === "?") {
|
|
12
|
-
if (definitionKey[definitionKey.length - 2] === scanner_js_1.Scanner.escapeToken) {
|
|
13
|
-
keyName = `${definitionKey.slice(0, -2)}?`;
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
keyName = definitionKey.slice(0, -1);
|
|
17
|
-
isOptional = true;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
ctx.path.push(keyName);
|
|
21
|
-
const propNode = (0, definition_js_1.parseDefinition)(def[definitionKey], ctx);
|
|
22
|
-
ctx.path.pop();
|
|
23
|
-
props[keyName] = isOptional ? ["?", propNode] : propNode;
|
|
24
|
-
}
|
|
25
|
-
return {
|
|
26
|
-
object: {
|
|
27
|
-
props
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
exports.parseRecord = parseRecord;
|