arktype 1.0.13-alpha → 1.0.15-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 +68 -11
- package/dist/main.js +29 -0
- package/dist/nodes/branch.js +135 -0
- package/dist/nodes/compose.js +99 -0
- package/dist/{cjs/nodes → nodes}/discriminate.js +100 -92
- package/dist/nodes/node.js +134 -0
- package/dist/nodes/predicate.js +88 -0
- package/dist/nodes/rules/class.js +23 -0
- package/dist/nodes/rules/collapsibleSet.js +34 -0
- package/dist/nodes/rules/divisor.js +19 -0
- package/dist/nodes/rules/props.js +130 -0
- package/dist/nodes/rules/range.js +108 -0
- package/dist/nodes/rules/regex.js +17 -0
- package/dist/nodes/rules/rules.js +102 -0
- package/dist/parse/ast/ast.js +2 -0
- package/dist/{types/parse → parse}/ast/bound.d.ts +4 -1
- package/dist/parse/ast/bound.js +7 -0
- package/dist/parse/ast/config.js +14 -0
- package/dist/parse/ast/distributableFunction.js +40 -0
- package/dist/parse/ast/divisor.js +5 -0
- package/dist/parse/ast/intersection.js +21 -0
- package/dist/parse/ast/keyof.js +107 -0
- package/dist/parse/ast/morph.js +50 -0
- package/dist/parse/ast/narrow.js +17 -0
- package/dist/{types/parse → parse}/ast/node.d.ts +3 -1
- package/dist/parse/ast/node.js +2 -0
- package/dist/parse/ast/tuple.js +72 -0
- package/dist/parse/ast/union.js +5 -0
- package/dist/parse/ast/utils.js +2 -0
- package/dist/parse/definition.js +47 -0
- package/dist/parse/record.js +31 -0
- package/dist/parse/string/reduce/dynamic.js +159 -0
- package/dist/parse/string/reduce/shared.js +13 -0
- package/dist/parse/string/reduce/static.js +2 -0
- package/dist/parse/string/shift/operand/enclosed.js +37 -0
- package/dist/parse/string/shift/operand/operand.js +15 -0
- package/dist/parse/string/shift/operand/unenclosed.js +45 -0
- package/dist/parse/string/shift/operator/bounds.js +83 -0
- package/dist/parse/string/shift/operator/divisor.js +23 -0
- package/dist/parse/string/shift/operator/operator.js +34 -0
- package/dist/parse/string/shift/scanner.js +97 -0
- package/dist/parse/string/string.js +35 -0
- package/dist/scopes/ark.js +27 -0
- package/dist/scopes/cache.js +28 -0
- package/dist/{mjs/scopes → scopes}/expressions.js +20 -9
- package/dist/scopes/jsObjects.js +20 -0
- package/dist/scopes/scope.js +184 -0
- package/dist/scopes/tsKeywords.js +49 -0
- package/dist/scopes/type.js +40 -0
- package/dist/{mjs/scopes → scopes}/validation/creditCard.js +15 -11
- package/dist/{mjs/scopes → scopes}/validation/date.js +21 -16
- package/dist/scopes/validation/validation.js +74 -0
- package/dist/traverse/problems.js +234 -0
- package/dist/traverse/traverse.js +330 -0
- package/dist/tsconfig.temp.tsbuildinfo +1 -1
- package/dist/{mjs/utils → utils}/chainableNoOpProxy.js +6 -2
- package/dist/utils/data.js +39 -0
- package/dist/utils/domains.js +27 -0
- package/dist/utils/errors.js +17 -0
- package/dist/utils/freeze.js +16 -0
- package/dist/utils/generics.js +53 -0
- package/dist/utils/numericLiterals.js +88 -0
- package/dist/utils/objectKinds.js +69 -0
- package/dist/{mjs/utils → utils}/paths.js +8 -3
- package/dist/utils/serialize.js +71 -0
- package/dist/utils/unionToTuple.js +2 -0
- package/package.json +25 -39
- package/dist/cjs/main.js +0 -38
- package/dist/cjs/nodes/branch.js +0 -140
- package/dist/cjs/nodes/compose.js +0 -157
- 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 -160
- 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 -9
- 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 -104
- package/dist/cjs/traverse/problems.js +0 -281
- package/dist/cjs/traverse/traverse.js +0 -387
- 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 -135
- package/dist/mjs/nodes/discriminate.js +0 -247
- 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 -142
- 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 -1
- 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/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 -108
- package/dist/mjs/traverse/problems.js +0 -260
- package/dist/mjs/traverse/traverse.js +0 -370
- 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/serialize.js +0 -58
- package/dist/mjs/utils/unionToTuple.js +0 -1
- /package/dist/{types/main.d.ts → main.d.ts} +0 -0
- /package/dist/{types/nodes → nodes}/branch.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/compose.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/discriminate.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/node.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/predicate.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/rules/class.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/rules/collapsibleSet.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/rules/divisor.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/rules/props.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/rules/range.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/rules/regex.d.ts +0 -0
- /package/dist/{types/nodes → nodes}/rules/rules.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/ast.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/config.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/distributableFunction.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/divisor.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/intersection.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/keyof.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/morph.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/narrow.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/tuple.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/union.d.ts +0 -0
- /package/dist/{types/parse → parse}/ast/utils.d.ts +0 -0
- /package/dist/{types/parse → parse}/definition.d.ts +0 -0
- /package/dist/{types/parse → parse}/record.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/reduce/dynamic.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/reduce/shared.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/reduce/static.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/shift/operand/enclosed.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/shift/operand/operand.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/shift/operand/unenclosed.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/shift/operator/bounds.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/shift/operator/divisor.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/shift/operator/operator.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/shift/scanner.d.ts +0 -0
- /package/dist/{types/parse → parse}/string/string.d.ts +0 -0
- /package/dist/{types/scopes → scopes}/ark.d.ts +0 -0
- /package/dist/{types/scopes → scopes}/cache.d.ts +0 -0
- /package/dist/{types/scopes → scopes}/expressions.d.ts +0 -0
- /package/dist/{types/scopes → scopes}/jsObjects.d.ts +0 -0
- /package/dist/{types/scopes → scopes}/scope.d.ts +0 -0
- /package/dist/{types/scopes → scopes}/tsKeywords.d.ts +0 -0
- /package/dist/{types/scopes → scopes}/type.d.ts +0 -0
- /package/dist/{types/scopes → scopes}/validation/creditCard.d.ts +0 -0
- /package/dist/{types/scopes → scopes}/validation/date.d.ts +0 -0
- /package/dist/{types/scopes → scopes}/validation/validation.d.ts +0 -0
- /package/dist/{types/traverse → traverse}/problems.d.ts +0 -0
- /package/dist/{types/traverse → traverse}/traverse.d.ts +0 -0
- /package/dist/{types/utils → utils}/chainableNoOpProxy.d.ts +0 -0
- /package/dist/{types/utils → utils}/data.d.ts +0 -0
- /package/dist/{types/utils → utils}/domains.d.ts +0 -0
- /package/dist/{types/utils → utils}/errors.d.ts +0 -0
- /package/dist/{types/utils → utils}/freeze.d.ts +0 -0
- /package/dist/{types/utils → utils}/generics.d.ts +0 -0
- /package/dist/{types/utils → utils}/numericLiterals.d.ts +0 -0
- /package/dist/{types/utils → utils}/objectKinds.d.ts +0 -0
- /package/dist/{types/utils → utils}/paths.d.ts +0 -0
- /package/dist/{types/utils → utils}/serialize.d.ts +0 -0
- /package/dist/{types/utils → utils}/unionToTuple.d.ts +0 -0
|
@@ -1,160 +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
|
-
isOptional: ()=>isOptional,
|
|
13
|
-
isPrerequisite: ()=>isPrerequisite,
|
|
14
|
-
mappedKeys: ()=>mappedKeys,
|
|
15
|
-
propToNode: ()=>propToNode,
|
|
16
|
-
propsIntersection: ()=>propsIntersection,
|
|
17
|
-
flattenProps: ()=>flattenProps
|
|
18
|
-
});
|
|
19
|
-
const _composeJs = require("../compose.js");
|
|
20
|
-
const _nodeJs = require("../node.js");
|
|
21
|
-
const isOptional = (prop)=>prop[0] === "?";
|
|
22
|
-
const isPrerequisite = (prop)=>prop[0] === "!";
|
|
23
|
-
const mappedKeys = {
|
|
24
|
-
index: "[index]"
|
|
25
|
-
};
|
|
26
|
-
const propToNode = (prop)=>isOptional(prop) || isPrerequisite(prop) ? prop[1] : prop;
|
|
27
|
-
const getTupleLengthIfPresent = (result)=>{
|
|
28
|
-
if (typeof result.length === "object" && isPrerequisite(result.length) && typeof result.length[1] !== "string" && (0, _nodeJs.isLiteralNode)(result.length[1], "number")) {
|
|
29
|
-
return result.length[1].number.value;
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
const propsIntersection = (0, _composeJs.composeIntersection)((l, r, state)=>{
|
|
33
|
-
const result = propKeysIntersection(l, r, state);
|
|
34
|
-
if (typeof result === "symbol") {
|
|
35
|
-
return result;
|
|
36
|
-
}
|
|
37
|
-
const lengthValue = getTupleLengthIfPresent(result);
|
|
38
|
-
if (lengthValue === undefined || !(mappedKeys.index in result)) {
|
|
39
|
-
return result;
|
|
40
|
-
}
|
|
41
|
-
// if we are at this point, we have an array with an exact length (i.e.
|
|
42
|
-
// a tuple) and an index signature. Intersection each tuple item with
|
|
43
|
-
// the index signature node and remove the index signature via a new
|
|
44
|
-
// updated result, copied from result to avoid mutating existing references.
|
|
45
|
-
const { [mappedKeys.index]: indexProp , ...updatedResult } = result;
|
|
46
|
-
const indexNode = propToNode(indexProp);
|
|
47
|
-
for(let i = 0; i < lengthValue; i++){
|
|
48
|
-
if (!updatedResult[i]) {
|
|
49
|
-
updatedResult[i] = indexNode;
|
|
50
|
-
continue;
|
|
51
|
-
}
|
|
52
|
-
const existingNodeAtIndex = propToNode(updatedResult[i]);
|
|
53
|
-
state.path.push(`${i}`);
|
|
54
|
-
const updatedResultAtIndex = (0, _nodeJs.nodeIntersection)(existingNodeAtIndex, indexNode, state);
|
|
55
|
-
state.path.pop();
|
|
56
|
-
if ((0, _composeJs.isDisjoint)(updatedResultAtIndex)) {
|
|
57
|
-
return updatedResultAtIndex;
|
|
58
|
-
} else if (!(0, _composeJs.isEquality)(updatedResultAtIndex) && updatedResultAtIndex !== existingNodeAtIndex) {
|
|
59
|
-
updatedResult[i] = updatedResultAtIndex;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
return updatedResult;
|
|
63
|
-
});
|
|
64
|
-
const propKeysIntersection = (0, _composeJs.composeKeyedIntersection)((propKey, l, r, context)=>{
|
|
65
|
-
if (l === undefined) {
|
|
66
|
-
return r === undefined ? (0, _composeJs.equality)() : r;
|
|
67
|
-
}
|
|
68
|
-
if (r === undefined) {
|
|
69
|
-
return l;
|
|
70
|
-
}
|
|
71
|
-
context.path.push(propKey);
|
|
72
|
-
const result = (0, _nodeJs.nodeIntersection)(propToNode(l), propToNode(r), context);
|
|
73
|
-
context.path.pop();
|
|
74
|
-
const resultIsOptional = isOptional(l) && isOptional(r);
|
|
75
|
-
if ((0, _composeJs.isDisjoint)(result) && resultIsOptional) {
|
|
76
|
-
// If an optional key has an empty intersection, the type can
|
|
77
|
-
// still be satisfied as long as the key is not included. Set
|
|
78
|
-
// the node to never rather than invalidating the type.
|
|
79
|
-
return {};
|
|
80
|
-
}
|
|
81
|
-
return result;
|
|
82
|
-
}, {
|
|
83
|
-
onEmpty: "bubble"
|
|
84
|
-
});
|
|
85
|
-
const flattenProps = (entries, props, ctx)=>{
|
|
86
|
-
const keyConfig = ctx.type.config?.keys ?? ctx.type.scope.config.keys;
|
|
87
|
-
return keyConfig === "loose" ? flattenLooseProps(entries, props, ctx) : flattenPropsRecord(keyConfig, entries, props, ctx);
|
|
88
|
-
};
|
|
89
|
-
const flattenLooseProps = (entries, props, ctx)=>{
|
|
90
|
-
// if we don't care about extraneous keys, flatten props so we can iterate over the definitions directly
|
|
91
|
-
for(const k in props){
|
|
92
|
-
const prop = props[k];
|
|
93
|
-
ctx.path.push(k);
|
|
94
|
-
if (k === mappedKeys.index) {
|
|
95
|
-
entries.push([
|
|
96
|
-
"indexProp",
|
|
97
|
-
(0, _nodeJs.flattenNode)(propToNode(prop), ctx)
|
|
98
|
-
]);
|
|
99
|
-
} else if (isOptional(prop)) {
|
|
100
|
-
entries.push([
|
|
101
|
-
"optionalProp",
|
|
102
|
-
[
|
|
103
|
-
k,
|
|
104
|
-
(0, _nodeJs.flattenNode)(prop[1], ctx)
|
|
105
|
-
]
|
|
106
|
-
]);
|
|
107
|
-
} else if (isPrerequisite(prop)) {
|
|
108
|
-
entries.push([
|
|
109
|
-
"prerequisiteProp",
|
|
110
|
-
[
|
|
111
|
-
k,
|
|
112
|
-
(0, _nodeJs.flattenNode)(prop[1], ctx)
|
|
113
|
-
]
|
|
114
|
-
]);
|
|
115
|
-
} else {
|
|
116
|
-
entries.push([
|
|
117
|
-
"requiredProp",
|
|
118
|
-
[
|
|
119
|
-
k,
|
|
120
|
-
(0, _nodeJs.flattenNode)(prop, ctx)
|
|
121
|
-
]
|
|
122
|
-
]);
|
|
123
|
-
}
|
|
124
|
-
ctx.path.pop();
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
const flattenPropsRecord = (kind, entries, props, ctx)=>{
|
|
128
|
-
const result = {
|
|
129
|
-
required: {},
|
|
130
|
-
optional: {}
|
|
131
|
-
};
|
|
132
|
-
// if we need to keep track of extraneous keys, either to add problems or
|
|
133
|
-
// remove them, store the props as a Record to optimize for presence
|
|
134
|
-
// checking as we iterate over the data
|
|
135
|
-
for(const k in props){
|
|
136
|
-
const prop = props[k];
|
|
137
|
-
ctx.path.push(k);
|
|
138
|
-
if (k === mappedKeys.index) {
|
|
139
|
-
result.index = (0, _nodeJs.flattenNode)(propToNode(prop), ctx);
|
|
140
|
-
} else if (isOptional(prop)) {
|
|
141
|
-
result.optional[k] = (0, _nodeJs.flattenNode)(prop[1], ctx);
|
|
142
|
-
} else if (isPrerequisite(prop)) {
|
|
143
|
-
// we still have to push prerequisite props as normal entries so they can be checked first
|
|
144
|
-
entries.push([
|
|
145
|
-
"prerequisiteProp",
|
|
146
|
-
[
|
|
147
|
-
k,
|
|
148
|
-
(0, _nodeJs.flattenNode)(prop[1], ctx)
|
|
149
|
-
]
|
|
150
|
-
]);
|
|
151
|
-
} else {
|
|
152
|
-
result.required[k] = (0, _nodeJs.flattenNode)(prop, ctx);
|
|
153
|
-
}
|
|
154
|
-
ctx.path.pop();
|
|
155
|
-
}
|
|
156
|
-
entries.push([
|
|
157
|
-
`${kind}Props`,
|
|
158
|
-
result
|
|
159
|
-
]);
|
|
160
|
-
};
|
|
@@ -1,105 +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
|
-
minComparators: ()=>minComparators,
|
|
13
|
-
maxComparators: ()=>maxComparators,
|
|
14
|
-
isEqualityRange: ()=>isEqualityRange,
|
|
15
|
-
rangeIntersection: ()=>rangeIntersection,
|
|
16
|
-
flattenRange: ()=>flattenRange,
|
|
17
|
-
checkBound: ()=>checkBound,
|
|
18
|
-
compareStrictness: ()=>compareStrictness
|
|
19
|
-
});
|
|
20
|
-
const _dataJs = require("../../utils/data.js");
|
|
21
|
-
const _composeJs = require("../compose.js");
|
|
22
|
-
const minComparators = {
|
|
23
|
-
">": true,
|
|
24
|
-
">=": true
|
|
25
|
-
};
|
|
26
|
-
const maxComparators = {
|
|
27
|
-
"<": true,
|
|
28
|
-
"<=": true
|
|
29
|
-
};
|
|
30
|
-
const isEqualityRange = (range)=>"comparator" in range;
|
|
31
|
-
const rangeIntersection = (0, _composeJs.composeIntersection)((l, r, state)=>{
|
|
32
|
-
if (isEqualityRange(l)) {
|
|
33
|
-
if (isEqualityRange(r)) {
|
|
34
|
-
return l.limit === r.limit ? (0, _composeJs.equality)() : state.addDisjoint("range", l, r);
|
|
35
|
-
}
|
|
36
|
-
return rangeAllows(r, l.limit) ? l : state.addDisjoint("range", l, r);
|
|
37
|
-
}
|
|
38
|
-
if (isEqualityRange(r)) {
|
|
39
|
-
return rangeAllows(l, r.limit) ? r : state.addDisjoint("range", l, r);
|
|
40
|
-
}
|
|
41
|
-
const stricterMin = compareStrictness("min", l.min, r.min);
|
|
42
|
-
const stricterMax = compareStrictness("max", l.max, r.max);
|
|
43
|
-
if (stricterMin === "l") {
|
|
44
|
-
if (stricterMax === "r") {
|
|
45
|
-
return compareStrictness("min", l.min, r.max) === "l" ? state.addDisjoint("range", l, r) : {
|
|
46
|
-
min: l.min,
|
|
47
|
-
max: r.max
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
return l;
|
|
51
|
-
}
|
|
52
|
-
if (stricterMin === "r") {
|
|
53
|
-
if (stricterMax === "l") {
|
|
54
|
-
return compareStrictness("max", l.max, r.min) === "l" ? state.addDisjoint("range", l, r) : {
|
|
55
|
-
min: r.min,
|
|
56
|
-
max: l.max
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
return r;
|
|
60
|
-
}
|
|
61
|
-
return stricterMax === "l" ? l : stricterMax === "r" ? r : (0, _composeJs.equality)();
|
|
62
|
-
});
|
|
63
|
-
const rangeAllows = (range, n)=>isEqualityRange(range) ? n === range.limit : minAllows(range.min, n) && maxAllows(range.max, n);
|
|
64
|
-
const minAllows = (min, n)=>!min || n > min.limit || n === min.limit && !isExclusive(min.comparator);
|
|
65
|
-
const maxAllows = (max, n)=>!max || n < max.limit || n === max.limit && !isExclusive(max.comparator);
|
|
66
|
-
const flattenRange = (entries, range, ctx)=>{
|
|
67
|
-
const units = ctx.lastDomain === "string" ? "characters" : ctx.lastDomain === "object" ? "items long" : undefined;
|
|
68
|
-
if (isEqualityRange(range)) {
|
|
69
|
-
return entries.push([
|
|
70
|
-
"bound",
|
|
71
|
-
units ? {
|
|
72
|
-
...range,
|
|
73
|
-
units
|
|
74
|
-
} : range
|
|
75
|
-
]);
|
|
76
|
-
}
|
|
77
|
-
if (range.min) {
|
|
78
|
-
entries.push([
|
|
79
|
-
"bound",
|
|
80
|
-
units ? {
|
|
81
|
-
...range.min,
|
|
82
|
-
units
|
|
83
|
-
} : range.min
|
|
84
|
-
]);
|
|
85
|
-
}
|
|
86
|
-
if (range.max) {
|
|
87
|
-
entries.push([
|
|
88
|
-
"bound",
|
|
89
|
-
units ? {
|
|
90
|
-
...range.max,
|
|
91
|
-
units
|
|
92
|
-
} : range.max
|
|
93
|
-
]);
|
|
94
|
-
}
|
|
95
|
-
};
|
|
96
|
-
const checkBound = (bound, state)=>comparatorCheckers[bound.comparator]((0, _dataJs.sizeOf)(state.data), bound.limit) || !state.problems.add("bound", bound);
|
|
97
|
-
const comparatorCheckers = {
|
|
98
|
-
"<": (size, limit)=>size < limit,
|
|
99
|
-
">": (size, limit)=>size > limit,
|
|
100
|
-
"<=": (size, limit)=>size <= limit,
|
|
101
|
-
">=": (size, limit)=>size >= limit,
|
|
102
|
-
"==": (size, limit)=>size === limit
|
|
103
|
-
};
|
|
104
|
-
const compareStrictness = (kind, l, r)=>!l ? !r ? "=" : "r" : !r ? "l" : l.limit === r.limit ? isExclusive(l.comparator) ? isExclusive(r.comparator) ? "=" : "l" : isExclusive(r.comparator) ? "r" : "=" : kind === "min" ? l.limit > r.limit ? "l" : "r" : l.limit < r.limit ? "l" : "r";
|
|
105
|
-
const isExclusive = (comparator)=>comparator.length === 1;
|
|
@@ -1,26 +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
|
-
getRegex: ()=>getRegex,
|
|
13
|
-
checkRegex: ()=>checkRegex,
|
|
14
|
-
regexIntersection: ()=>regexIntersection
|
|
15
|
-
});
|
|
16
|
-
const _composeJs = require("../compose.js");
|
|
17
|
-
const _collapsibleSetJs = require("./collapsibleSet.js");
|
|
18
|
-
const regexCache = {};
|
|
19
|
-
const getRegex = (source)=>{
|
|
20
|
-
if (!regexCache[source]) {
|
|
21
|
-
regexCache[source] = new RegExp(source);
|
|
22
|
-
}
|
|
23
|
-
return regexCache[source];
|
|
24
|
-
};
|
|
25
|
-
const checkRegex = (source, state)=>getRegex(source).test(state.data) || !state.problems.add("regex", `/${source}/`);
|
|
26
|
-
const regexIntersection = (0, _composeJs.composeIntersection)(_collapsibleSetJs.collapsibleListUnion);
|
|
@@ -1,123 +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
|
-
rulesIntersection: ()=>rulesIntersection,
|
|
13
|
-
narrowableRulesIntersection: ()=>narrowableRulesIntersection,
|
|
14
|
-
flattenRules: ()=>flattenRules,
|
|
15
|
-
precedenceMap: ()=>precedenceMap,
|
|
16
|
-
literalSatisfiesRules: ()=>literalSatisfiesRules
|
|
17
|
-
});
|
|
18
|
-
const _genericsJs = require("../../utils/generics.js");
|
|
19
|
-
const _composeJs = require("../compose.js");
|
|
20
|
-
const _classJs = require("./class.js");
|
|
21
|
-
const _collapsibleSetJs = require("./collapsibleSet.js");
|
|
22
|
-
const _divisorJs = require("./divisor.js");
|
|
23
|
-
const _propsJs = require("./props.js");
|
|
24
|
-
const _rangeJs = require("./range.js");
|
|
25
|
-
const _regexJs = require("./regex.js");
|
|
26
|
-
const rulesIntersection = (l, r, state)=>"value" in l ? "value" in r ? l.value === r.value ? (0, _composeJs.equality)() : state.addDisjoint("value", l.value, r.value) : literalSatisfiesRules(l.value, r, state) ? l : state.addDisjoint("leftAssignability", l, r) : "value" in r ? literalSatisfiesRules(r.value, l, state) ? r : state.addDisjoint("rightAssignability", l, r) : narrowableRulesIntersection(l, r, state);
|
|
27
|
-
const narrowIntersection = (0, _composeJs.composeIntersection)(_collapsibleSetJs.collapsibleListUnion);
|
|
28
|
-
const narrowableRulesIntersection = (0, _composeJs.composeKeyedIntersection)({
|
|
29
|
-
divisor: _divisorJs.divisorIntersection,
|
|
30
|
-
regex: _regexJs.regexIntersection,
|
|
31
|
-
props: _propsJs.propsIntersection,
|
|
32
|
-
class: _classJs.classIntersection,
|
|
33
|
-
range: _rangeJs.rangeIntersection,
|
|
34
|
-
narrow: narrowIntersection
|
|
35
|
-
}, {
|
|
36
|
-
onEmpty: "bubble"
|
|
37
|
-
});
|
|
38
|
-
const flattenRules = (rules, ctx)=>{
|
|
39
|
-
const entries = [];
|
|
40
|
-
let k;
|
|
41
|
-
for(k in rules){
|
|
42
|
-
ruleFlatteners[k](entries, rules[k], ctx);
|
|
43
|
-
}
|
|
44
|
-
// Some entries with the same precedence, e.g. morphs flattened from a list,
|
|
45
|
-
// rely on the fact that JS's builtin sort is stable to behave as expected
|
|
46
|
-
// when traversed:
|
|
47
|
-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
|
|
48
|
-
return entries.sort((l, r)=>precedenceMap[l[0]] - precedenceMap[r[0]]);
|
|
49
|
-
};
|
|
50
|
-
const ruleFlatteners = {
|
|
51
|
-
regex: (entries, rule)=>{
|
|
52
|
-
for (const source of (0, _genericsJs.listFrom)(rule)){
|
|
53
|
-
entries.push([
|
|
54
|
-
"regex",
|
|
55
|
-
source
|
|
56
|
-
]);
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
divisor: (entries, rule)=>{
|
|
60
|
-
entries.push([
|
|
61
|
-
"divisor",
|
|
62
|
-
rule
|
|
63
|
-
]);
|
|
64
|
-
},
|
|
65
|
-
range: _rangeJs.flattenRange,
|
|
66
|
-
class: (entries, rule)=>{
|
|
67
|
-
entries.push([
|
|
68
|
-
"class",
|
|
69
|
-
rule
|
|
70
|
-
]);
|
|
71
|
-
},
|
|
72
|
-
props: _propsJs.flattenProps,
|
|
73
|
-
narrow: (entries, rule)=>{
|
|
74
|
-
for (const narrow of (0, _genericsJs.listFrom)(rule)){
|
|
75
|
-
entries.push([
|
|
76
|
-
"narrow",
|
|
77
|
-
narrow
|
|
78
|
-
]);
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
value: (entries, rule)=>{
|
|
82
|
-
entries.push([
|
|
83
|
-
"value",
|
|
84
|
-
rule
|
|
85
|
-
]);
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
const precedenceMap = {
|
|
89
|
-
// Config: Applies before any checks
|
|
90
|
-
config: -1,
|
|
91
|
-
// Critical: No other checks are performed if these fail
|
|
92
|
-
domain: 0,
|
|
93
|
-
value: 0,
|
|
94
|
-
domains: 0,
|
|
95
|
-
branches: 0,
|
|
96
|
-
switch: 0,
|
|
97
|
-
alias: 0,
|
|
98
|
-
class: 0,
|
|
99
|
-
// Shallow: All shallow checks will be performed even if one or more fail
|
|
100
|
-
regex: 1,
|
|
101
|
-
divisor: 1,
|
|
102
|
-
bound: 1,
|
|
103
|
-
// Prerequisite: These are deep checks with special priority, e.g. the
|
|
104
|
-
// length of a tuple, which causes other deep props not to be checked if it
|
|
105
|
-
// is invalid
|
|
106
|
-
prerequisiteProp: 2,
|
|
107
|
-
// Deep: Performed if all shallow checks pass, even if one or more deep checks fail
|
|
108
|
-
distilledProps: 3,
|
|
109
|
-
strictProps: 3,
|
|
110
|
-
requiredProp: 3,
|
|
111
|
-
optionalProp: 3,
|
|
112
|
-
indexProp: 3,
|
|
113
|
-
// Narrow: Only performed if all shallow and deep checks pass
|
|
114
|
-
narrow: 4,
|
|
115
|
-
// Morph: Only performed if all validation passes
|
|
116
|
-
morph: 5
|
|
117
|
-
};
|
|
118
|
-
const literalSatisfiesRules = (data, rules, state)=>!state.type.scope.type([
|
|
119
|
-
"node",
|
|
120
|
-
{
|
|
121
|
-
[state.domain]: rules
|
|
122
|
-
}
|
|
123
|
-
])(data).problems;
|
package/dist/cjs/package.json
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "writeUnboundableMessage", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: ()=>writeUnboundableMessage
|
|
8
|
-
});
|
|
9
|
-
const writeUnboundableMessage = (root)=>`Bounded expression ${root} must be a number, string or array`;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "parseConfigTuple", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: ()=>parseConfigTuple
|
|
8
|
-
});
|
|
9
|
-
const _definitionJs = require("../definition.js");
|
|
10
|
-
const parseConfigTuple = (def, ctx)=>({
|
|
11
|
-
node: ctx.type.scope.resolveTypeNode((0, _definitionJs.parseDefinition)(def[0], ctx)),
|
|
12
|
-
config: def[2]
|
|
13
|
-
});
|
|
@@ -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
|
-
writeMalformedDistributableFunctionMessage: ()=>writeMalformedDistributableFunctionMessage,
|
|
13
|
-
distributeFunctionToNode: ()=>distributeFunctionToNode
|
|
14
|
-
});
|
|
15
|
-
const _domainsJs = require("../../utils/domains.js");
|
|
16
|
-
const _errorsJs = require("../../utils/errors.js");
|
|
17
|
-
const _genericsJs = require("../../utils/generics.js");
|
|
18
|
-
const _serializeJs = require("../../utils/serialize.js");
|
|
19
|
-
const writeMalformedDistributableFunctionMessage = (def)=>`Expected a Function or Record<Domain, Function> operand (${(0, _serializeJs.stringify)(def)} was invalid)`;
|
|
20
|
-
const distributeFunctionToNode = (distributableFunction, node, ctx, ruleKey)=>{
|
|
21
|
-
const domains = (0, _genericsJs.objectKeysOf)(node);
|
|
22
|
-
if (!(0, _domainsJs.hasDomain)(distributableFunction, "object")) {
|
|
23
|
-
return (0, _errorsJs.throwParseError)(writeMalformedDistributableFunctionMessage(distributableFunction));
|
|
24
|
-
}
|
|
25
|
-
const distributed = {};
|
|
26
|
-
if (typeof distributableFunction === "function") {
|
|
27
|
-
const domainFunction = {
|
|
28
|
-
[ruleKey]: distributableFunction
|
|
29
|
-
};
|
|
30
|
-
for (const domain of domains){
|
|
31
|
-
distributed[domain] = domainFunction;
|
|
32
|
-
}
|
|
33
|
-
} else {
|
|
34
|
-
for (const domain of domains){
|
|
35
|
-
if (distributableFunction[domain] === undefined) {
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
const functionInDomain = {
|
|
39
|
-
[ruleKey]: distributableFunction[domain]
|
|
40
|
-
};
|
|
41
|
-
if (typeof functionInDomain[ruleKey] !== "function") {
|
|
42
|
-
return (0, _errorsJs.throwParseError)(writeMalformedDistributableFunctionMessage(functionInDomain));
|
|
43
|
-
}
|
|
44
|
-
distributed[domain] = functionInDomain;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return distributed;
|
|
48
|
-
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "writeIndivisibleMessage", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: ()=>writeIndivisibleMessage
|
|
8
|
-
});
|
|
9
|
-
const writeIndivisibleMessage = (root)=>`Divisibility operand ${root} must be a number`;
|
|
@@ -1,30 +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
|
-
compileDisjointReasonsMessage: ()=>compileDisjointReasonsMessage,
|
|
13
|
-
writeImplicitNeverMessage: ()=>writeImplicitNeverMessage
|
|
14
|
-
});
|
|
15
|
-
const _composeJs = require("../../nodes/compose.js");
|
|
16
|
-
const _genericsJs = require("../../utils/generics.js");
|
|
17
|
-
const compileDisjointReasonsMessage = (disjoints)=>{
|
|
18
|
-
const paths = (0, _genericsJs.objectKeysOf)(disjoints);
|
|
19
|
-
if (paths.length === 1) {
|
|
20
|
-
const path = paths[0];
|
|
21
|
-
return `${path === "/" ? "" : `At ${path}: `}Intersection of ${_composeJs.disjointDescriptionWriters[disjoints[path].kind](disjoints[path])} results in an unsatisfiable type`;
|
|
22
|
-
}
|
|
23
|
-
let message = `
|
|
24
|
-
"Intersection results in unsatisfiable types at the following paths:\n`;
|
|
25
|
-
for(const path in disjoints){
|
|
26
|
-
message += ` ${path}: ${_composeJs.disjointDescriptionWriters[disjoints[path].kind](disjoints[path])}\n`;
|
|
27
|
-
}
|
|
28
|
-
return message;
|
|
29
|
-
};
|
|
30
|
-
const writeImplicitNeverMessage = (path, operator, description)=>`${path.length ? `At ${path}: ` : ""}${operator} ${description ? `${description} ` : ""}results in an unsatisfiable type`;
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "parseKeyOfTuple", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: ()=>parseKeyOfTuple
|
|
8
|
-
});
|
|
9
|
-
const _propsJs = require("../../nodes/rules/props.js");
|
|
10
|
-
const _errorsJs = require("../../utils/errors.js");
|
|
11
|
-
const _freezeJs = require("../../utils/freeze.js");
|
|
12
|
-
const _genericsJs = require("../../utils/generics.js");
|
|
13
|
-
const _numericLiteralsJs = require("../../utils/numericLiterals.js");
|
|
14
|
-
const _objectKindsJs = require("../../utils/objectKinds.js");
|
|
15
|
-
const _serializeJs = require("../../utils/serialize.js");
|
|
16
|
-
const _definitionJs = require("../definition.js");
|
|
17
|
-
const _intersectionJs = require("./intersection.js");
|
|
18
|
-
const arrayIndexStringBranch = (0, _freezeJs.deepFreeze)({
|
|
19
|
-
regex: _numericLiteralsJs.wellFormedNonNegativeIntegerMatcher.source
|
|
20
|
-
});
|
|
21
|
-
const arrayIndexNumberBranch = (0, _freezeJs.deepFreeze)({
|
|
22
|
-
range: {
|
|
23
|
-
min: {
|
|
24
|
-
comparator: ">=",
|
|
25
|
-
limit: 0
|
|
26
|
-
}
|
|
27
|
-
},
|
|
28
|
-
divisor: 1
|
|
29
|
-
});
|
|
30
|
-
const parseKeyOfTuple = (def, ctx)=>{
|
|
31
|
-
const resolution = ctx.type.scope.resolveNode((0, _definitionJs.parseDefinition)(def[1], ctx));
|
|
32
|
-
const predicateKeys = (0, _genericsJs.objectKeysOf)(resolution).map((domain)=>keysOfPredicate(domain, resolution[domain]));
|
|
33
|
-
const sharedKeys = sharedKeysOf(predicateKeys);
|
|
34
|
-
if (!sharedKeys.length) {
|
|
35
|
-
return (0, _intersectionJs.writeImplicitNeverMessage)(ctx.path, "keyof");
|
|
36
|
-
}
|
|
37
|
-
const keyNode = {};
|
|
38
|
-
for (const key of sharedKeys){
|
|
39
|
-
const keyType = typeof key;
|
|
40
|
-
if (keyType === "string" || keyType === "number" || keyType === "symbol") {
|
|
41
|
-
var _keyNode, _keyType;
|
|
42
|
-
(_keyNode = keyNode)[_keyType = keyType] ?? (_keyNode[_keyType] = []);
|
|
43
|
-
keyNode[keyType].push({
|
|
44
|
-
value: key
|
|
45
|
-
});
|
|
46
|
-
} else if (key === _numericLiteralsJs.wellFormedNonNegativeIntegerMatcher) {
|
|
47
|
-
var _keyNode1, _keyNode2;
|
|
48
|
-
(_keyNode1 = keyNode).string ?? (_keyNode1.string = []);
|
|
49
|
-
keyNode.string.push(arrayIndexStringBranch);
|
|
50
|
-
(_keyNode2 = keyNode).number ?? (_keyNode2.number = []);
|
|
51
|
-
keyNode.number.push(arrayIndexNumberBranch);
|
|
52
|
-
} else {
|
|
53
|
-
return (0, _errorsJs.throwInternalError)(`Unexpected keyof key '${(0, _serializeJs.stringify)(key)}'`);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
return Object.fromEntries(Object.entries(keyNode).map(([domain, branches])=>[
|
|
57
|
-
domain,
|
|
58
|
-
branches.length === 1 ? branches[0] : branches
|
|
59
|
-
]));
|
|
60
|
-
};
|
|
61
|
-
const baseKeysByDomain = {
|
|
62
|
-
bigint: (0, _genericsJs.prototypeKeysOf)(0n),
|
|
63
|
-
boolean: (0, _genericsJs.prototypeKeysOf)(false),
|
|
64
|
-
null: [],
|
|
65
|
-
number: (0, _genericsJs.prototypeKeysOf)(0),
|
|
66
|
-
// TS doesn't include the Object prototype in keyof, so keyof object is never
|
|
67
|
-
object: [],
|
|
68
|
-
string: (0, _genericsJs.prototypeKeysOf)(""),
|
|
69
|
-
symbol: (0, _genericsJs.prototypeKeysOf)(Symbol()),
|
|
70
|
-
undefined: []
|
|
71
|
-
};
|
|
72
|
-
const keysOfPredicate = (domain, predicate)=>domain !== "object" || predicate === true ? baseKeysByDomain[domain] : sharedKeysOf((0, _genericsJs.listFrom)(predicate).map((branch)=>keysOfObjectBranch(branch)));
|
|
73
|
-
const sharedKeysOf = (keyBranches)=>{
|
|
74
|
-
if (!keyBranches.length) {
|
|
75
|
-
return [];
|
|
76
|
-
}
|
|
77
|
-
let sharedKeys = keyBranches[0];
|
|
78
|
-
for(let i = 1; i < keyBranches.length; i++){
|
|
79
|
-
// we can filter directly by equality here because the RegExp we're
|
|
80
|
-
// using will always be reference equal to
|
|
81
|
-
// wellFormedNonNegativeIntegerMatcher
|
|
82
|
-
sharedKeys = sharedKeys.filter((k)=>keyBranches[i].includes(k));
|
|
83
|
-
}
|
|
84
|
-
return sharedKeys;
|
|
85
|
-
};
|
|
86
|
-
const keysOfObjectBranch = (branch)=>{
|
|
87
|
-
const result = [];
|
|
88
|
-
if ("props" in branch) {
|
|
89
|
-
for (const key of Object.keys(branch.props)){
|
|
90
|
-
if (key === _propsJs.mappedKeys.index) {
|
|
91
|
-
// if any number is a valid key push this RegExp
|
|
92
|
-
result.push(_numericLiteralsJs.wellFormedNonNegativeIntegerMatcher);
|
|
93
|
-
} else if (!result.includes(key)) {
|
|
94
|
-
result.push(key);
|
|
95
|
-
if (_numericLiteralsJs.wellFormedNonNegativeIntegerMatcher.test(key)) {
|
|
96
|
-
// allow numeric access to keys
|
|
97
|
-
result.push((0, _numericLiteralsJs.tryParseWellFormedInteger)(key, `Unexpectedly failed to parse an integer from key '${key}'`));
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
if ("class" in branch) {
|
|
103
|
-
const constructor = typeof branch.class === "string" ? _objectKindsJs.defaultObjectKinds[branch.class] : branch.class;
|
|
104
|
-
for (const key of (0, _genericsJs.prototypeKeysOf)(constructor.prototype)){
|
|
105
|
-
if (!result.includes(key)) {
|
|
106
|
-
result.push(key);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return result;
|
|
111
|
-
};
|