arktype 0.5.1 → 1.0.0-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 +1 -1
- package/dist/api.cjs +4 -2
- package/dist/api.d.ts +1 -1
- package/dist/api.mjs +1 -1
- package/dist/cjs/nodes/branch.js +3 -3
- package/dist/cjs/nodes/compose.js +4 -4
- package/dist/cjs/nodes/discriminate.js +2 -2
- package/dist/cjs/nodes/node.js +33 -30
- package/dist/cjs/nodes/predicate.js +1 -7
- package/dist/cjs/nodes/rules/props.js +39 -0
- package/dist/cjs/nodes/rules/rules.js +5 -2
- package/dist/cjs/parse/ast/config.js +13 -0
- package/dist/cjs/parse/ast/distributableFunction.js +2 -2
- package/dist/cjs/parse/ast/keyof.js +1 -1
- package/dist/cjs/parse/ast/morph.js +4 -3
- package/dist/cjs/parse/ast/narrow.js +8 -1
- package/dist/cjs/{nodes/infer.js → parse/ast/node.js} +0 -0
- package/dist/cjs/parse/ast/tuple.js +2 -1
- package/dist/cjs/parse/definition.js +2 -2
- package/dist/cjs/parse/string/reduce/dynamic.js +2 -2
- package/dist/cjs/parse/string/shift/operand/unenclosed.js +1 -1
- package/dist/cjs/parse/string/string.js +3 -3
- package/dist/cjs/scopes/{standard.js → ark.js} +9 -8
- package/dist/cjs/scopes/expressions.js +9 -9
- package/dist/cjs/scopes/scope.js +73 -75
- package/dist/cjs/scopes/type.js +24 -38
- package/dist/cjs/scopes/validation/creditCard.js +47 -0
- package/dist/cjs/scopes/validation/date.js +63 -0
- package/dist/cjs/scopes/validation/validation.js +95 -0
- package/dist/cjs/traverse/problems.js +48 -19
- package/dist/cjs/traverse/traverse.js +80 -25
- package/dist/cjs/utils/generics.js +16 -0
- package/dist/cjs/utils/serialize.js +29 -53
- package/dist/mjs/nodes/branch.js +2 -2
- package/dist/mjs/nodes/compose.js +5 -5
- package/dist/mjs/nodes/discriminate.js +2 -2
- package/dist/mjs/nodes/node.js +31 -31
- package/dist/mjs/nodes/predicate.js +1 -6
- package/dist/mjs/nodes/rules/props.js +39 -0
- package/dist/mjs/nodes/rules/rules.js +5 -2
- package/dist/mjs/parse/ast/config.js +5 -0
- package/dist/mjs/parse/ast/distributableFunction.js +2 -2
- package/dist/mjs/parse/ast/keyof.js +1 -1
- package/dist/mjs/parse/ast/morph.js +5 -4
- package/dist/mjs/parse/ast/narrow.js +9 -2
- package/dist/mjs/{nodes/infer.js → parse/ast/node.js} +0 -0
- package/dist/mjs/parse/ast/tuple.js +2 -1
- package/dist/mjs/parse/definition.js +2 -2
- package/dist/mjs/parse/string/reduce/dynamic.js +2 -2
- package/dist/mjs/parse/string/shift/operand/unenclosed.js +1 -1
- package/dist/mjs/parse/string/string.js +3 -3
- package/dist/mjs/scopes/{standard.js → ark.js} +8 -7
- package/dist/mjs/scopes/expressions.js +9 -9
- package/dist/mjs/scopes/scope.js +70 -76
- package/dist/mjs/scopes/type.js +22 -38
- package/dist/mjs/scopes/validation/creditCard.js +34 -0
- package/dist/mjs/scopes/validation/date.js +49 -0
- package/dist/mjs/scopes/validation/validation.js +81 -0
- package/dist/mjs/traverse/problems.js +45 -18
- package/dist/mjs/traverse/traverse.js +82 -27
- package/dist/mjs/utils/generics.js +11 -0
- package/dist/mjs/utils/serialize.js +29 -52
- package/dist/tsconfig.temp.tsbuildinfo +1 -1
- package/dist/types/nodes/branch.d.ts +8 -6
- package/dist/types/nodes/node.d.ts +24 -12
- package/dist/types/nodes/predicate.d.ts +4 -8
- package/dist/types/nodes/rules/props.d.ts +23 -8
- package/dist/types/nodes/rules/rules.d.ts +2 -2
- package/dist/types/parse/ast/ast.d.ts +1 -1
- package/dist/types/parse/ast/config.d.ts +10 -0
- package/dist/types/parse/ast/distributableFunction.d.ts +1 -1
- package/dist/types/parse/ast/morph.d.ts +2 -2
- package/dist/types/parse/ast/narrow.d.ts +1 -1
- package/dist/types/{nodes/infer.d.ts → parse/ast/node.d.ts} +14 -14
- package/dist/types/parse/ast/tuple.d.ts +8 -7
- package/dist/types/parse/definition.d.ts +2 -2
- package/dist/types/parse/string/reduce/dynamic.d.ts +5 -5
- package/dist/types/parse/string/string.d.ts +3 -3
- package/dist/types/scopes/{standard.d.ts → ark.d.ts} +15 -86
- package/dist/types/scopes/expressions.d.ts +3 -3
- package/dist/types/scopes/scope.d.ts +24 -11
- package/dist/types/scopes/type.d.ts +37 -20
- package/dist/types/scopes/validation/creditCard.d.ts +2 -0
- package/dist/types/scopes/validation/date.d.ts +23 -0
- package/dist/types/scopes/validation/validation.d.ts +28 -0
- package/dist/types/traverse/problems.d.ts +14 -8
- package/dist/types/traverse/traverse.d.ts +18 -3
- package/dist/types/utils/generics.d.ts +10 -5
- package/dist/types/utils/serialize.d.ts +0 -1
- package/package.json +2 -2
- package/dist/cjs/scopes/validation.js +0 -79
- package/dist/mjs/scopes/validation.js +0 -66
- package/dist/types/scopes/validation.d.ts +0 -25
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ Isomorphic types for TS/JS
|
|
|
14
14
|
|
|
15
15
|
If you're using TypeScript, you'll need at least `4.8`
|
|
16
16
|
|
|
17
|
-
_Note:
|
|
17
|
+
_Note: Our APIs have largely stabilized at this point, but some may still change during the alpha/beta stages of our 1.0 release. If you have feedback that may require a breaking change, now is the time to let us know!_
|
|
18
18
|
|
|
19
19
|
### Your first type
|
|
20
20
|
|
package/dist/api.cjs
CHANGED
|
@@ -10,7 +10,9 @@ function _export(target, all) {
|
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
12
|
scope: ()=>_scopeTs.scope,
|
|
13
|
-
type: ()=>
|
|
13
|
+
type: ()=>_arkTs.type,
|
|
14
|
+
ark: ()=>_arkTs.ark,
|
|
15
|
+
arkscope: ()=>_arkTs.arkscope,
|
|
14
16
|
intersection: ()=>_expressionsTs.intersection,
|
|
15
17
|
union: ()=>_expressionsTs.union,
|
|
16
18
|
arrayOf: ()=>_expressionsTs.arrayOf,
|
|
@@ -23,6 +25,6 @@ _export(exports, {
|
|
|
23
25
|
Problem: ()=>_problemsTs.Problem
|
|
24
26
|
});
|
|
25
27
|
const _scopeTs = require("./cjs/scopes/scope.js");
|
|
26
|
-
const
|
|
28
|
+
const _arkTs = require("./cjs/scopes/ark.js");
|
|
27
29
|
const _expressionsTs = require("./cjs/scopes/expressions.js");
|
|
28
30
|
const _problemsTs = require("./cjs/traverse/problems.js");
|
package/dist/api.d.ts
CHANGED
package/dist/api.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { scope } from "./mjs/scopes/scope.js";
|
|
2
|
-
export { type } from "./mjs/scopes/
|
|
2
|
+
export { type, ark, arkscope } from "./mjs/scopes/ark.js";
|
|
3
3
|
export { intersection, union, arrayOf, instanceOf, valueOf, morph, narrow, keyOf } from "./mjs/scopes/expressions.js";
|
|
4
4
|
export { Problems, Problem } from "./mjs/traverse/problems.js";
|
package/dist/cjs/nodes/branch.js
CHANGED
|
@@ -11,7 +11,7 @@ function _export(target, all) {
|
|
|
11
11
|
_export(exports, {
|
|
12
12
|
isBranchComparison: ()=>isBranchComparison,
|
|
13
13
|
compareBranches: ()=>compareBranches,
|
|
14
|
-
|
|
14
|
+
isTransformationBranch: ()=>isTransformationBranch,
|
|
15
15
|
flattenBranch: ()=>flattenBranch,
|
|
16
16
|
branchIntersection: ()=>branchIntersection
|
|
17
17
|
});
|
|
@@ -87,9 +87,9 @@ const compareBranches = (lConditions, rConditions, state)=>{
|
|
|
87
87
|
result.distinctIntersections = pairs.flatMap((pairs)=>pairs.distinct ?? []);
|
|
88
88
|
return result;
|
|
89
89
|
};
|
|
90
|
-
const
|
|
90
|
+
const isTransformationBranch = (branch)=>"rules" in branch;
|
|
91
91
|
const flattenBranch = (branch, ctx)=>{
|
|
92
|
-
if (
|
|
92
|
+
if (isTransformationBranch(branch)) {
|
|
93
93
|
const result = (0, _rulesTs.flattenRules)(branch.rules, ctx);
|
|
94
94
|
if (branch.morph) {
|
|
95
95
|
if (typeof branch.morph === "function") {
|
|
@@ -71,10 +71,10 @@ const disjointDescriptionWriters = {
|
|
|
71
71
|
range: ({ l , r })=>`${stringifyRange(l)} and ${stringifyRange(r)}`,
|
|
72
72
|
class: ({ l , r })=>`classes ${typeof l === "string" ? l : l.name} and ${typeof r === "string" ? r : r.name}`,
|
|
73
73
|
tupleLength: ({ l , r })=>`tuples of length ${l} and ${r}`,
|
|
74
|
-
value: ({ l , r })=>`literal values ${(0, _serializeTs.
|
|
75
|
-
leftAssignability: ({ l , r })=>`literal value ${(0, _serializeTs.
|
|
76
|
-
rightAssignability: ({ l , r })=>`literal value ${(0, _serializeTs.
|
|
77
|
-
union: ({ l , r })=>`branches ${(0, _serializeTs.
|
|
74
|
+
value: ({ l , r })=>`literal values ${(0, _serializeTs.stringify)(l)} and ${(0, _serializeTs.stringify)(r)}`,
|
|
75
|
+
leftAssignability: ({ l , r })=>`literal value ${(0, _serializeTs.stringify)(l.value)} and ${(0, _serializeTs.stringify)(r)}`,
|
|
76
|
+
rightAssignability: ({ l , r })=>`literal value ${(0, _serializeTs.stringify)(r.value)} and ${(0, _serializeTs.stringify)(l)}`,
|
|
77
|
+
union: ({ l , r })=>`branches ${(0, _serializeTs.stringify)(l)} and branches ${(0, _serializeTs.stringify)(r)}`
|
|
78
78
|
};
|
|
79
79
|
const stringifyRange = (range)=>"limit" in range ? `the range of exactly ${range.limit}` : range.min ? range.max ? `the range bounded by ${range.min.comparator}${range.min.limit} and ${range.max.comparator}${range.max.limit}` : `${range.min.comparator}${range.min.limit}` : range.max ? `${range.max.comparator}${range.max.limit}` : "the unbounded range";
|
|
80
80
|
var _disjoints = /*#__PURE__*/ new WeakMap();
|
|
@@ -37,7 +37,7 @@ const discriminate = (originalBranches, remainingIndices, discriminants, ctx)=>{
|
|
|
37
37
|
return [
|
|
38
38
|
[
|
|
39
39
|
"branches",
|
|
40
|
-
remainingIndices.map((i)=>branchIncludesMorph(originalBranches[i], ctx.type.
|
|
40
|
+
remainingIndices.map((i)=>branchIncludesMorph(originalBranches[i], ctx.type.scope) ? (0, _errorsTs.throwParseError)((0, _unionTs.writeUndiscriminatableMorphUnionMessage)(`${ctx.path}`)) : (0, _branchTs.flattenBranch)(originalBranches[i], ctx))
|
|
41
41
|
]
|
|
42
42
|
];
|
|
43
43
|
}
|
|
@@ -259,4 +259,4 @@ const serializeData = {
|
|
|
259
259
|
};
|
|
260
260
|
const serializeCase = (kind, data)=>serializeData[kind](data);
|
|
261
261
|
const branchIncludesMorph = (branch, $)=>"morph" in branch ? true : "props" in branch ? Object.values(branch.props).some((prop)=>nodeIncludesMorph((0, _propsTs.propToNode)(prop), $)) : false;
|
|
262
|
-
const nodeIncludesMorph = (node, $)=>typeof node === "string" ? $.resolve(node).
|
|
262
|
+
const nodeIncludesMorph = (node, $)=>typeof node === "string" ? $.resolve(node).includesMorph : Object.values($.resolveTypeNode(node)).some((predicate)=>predicate === true ? false : (0, _objectKindsTs.isArray)(predicate) ? predicate.some((branch)=>branchIncludesMorph(branch, $)) : branchIncludesMorph(predicate, $));
|
package/dist/cjs/nodes/node.js
CHANGED
|
@@ -9,12 +9,15 @@ function _export(target, all) {
|
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
+
isConfigNode: ()=>isConfigNode,
|
|
12
13
|
nodeIntersection: ()=>nodeIntersection,
|
|
13
14
|
rootIntersection: ()=>rootIntersection,
|
|
14
15
|
rootUnion: ()=>rootUnion,
|
|
15
16
|
flattenType: ()=>flattenType,
|
|
16
17
|
flattenNode: ()=>flattenNode,
|
|
18
|
+
flattenTypeNode: ()=>flattenTypeNode,
|
|
17
19
|
isLiteralNode: ()=>isLiteralNode,
|
|
20
|
+
resolutionExtendsDomain: ()=>resolutionExtendsDomain,
|
|
18
21
|
toArrayNode: ()=>toArrayNode
|
|
19
22
|
});
|
|
20
23
|
const _intersectionTs = require("../parse/ast/intersection.js");
|
|
@@ -24,17 +27,18 @@ const _pathsTs = require("../utils/paths.js");
|
|
|
24
27
|
const _composeTs = require("./compose.js");
|
|
25
28
|
const _predicateTs = require("./predicate.js");
|
|
26
29
|
const _propsTs = require("./rules/props.js");
|
|
30
|
+
const isConfigNode = (node)=>"config" in node;
|
|
27
31
|
const nodeIntersection = (l, r, state)=>{
|
|
28
32
|
state.domain = undefined;
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
const result =
|
|
33
|
+
const lDomains = state.type.scope.resolveTypeNode(l);
|
|
34
|
+
const rDomains = state.type.scope.resolveTypeNode(r);
|
|
35
|
+
const result = typeNodeIntersection(lDomains, rDomains, state);
|
|
32
36
|
if (typeof result === "object" && !(0, _genericsTs.hasKeys)(result)) {
|
|
33
|
-
return (0, _genericsTs.hasKeys)(state.disjoints) ? (0, _composeTs.anonymousDisjoint)() : state.addDisjoint("domain", (0, _genericsTs.objectKeysOf)(
|
|
37
|
+
return (0, _genericsTs.hasKeys)(state.disjoints) ? (0, _composeTs.anonymousDisjoint)() : state.addDisjoint("domain", (0, _genericsTs.objectKeysOf)(lDomains), (0, _genericsTs.objectKeysOf)(rDomains));
|
|
34
38
|
}
|
|
35
|
-
return result ===
|
|
39
|
+
return result === lDomains ? l : result === rDomains ? r : result;
|
|
36
40
|
};
|
|
37
|
-
const
|
|
41
|
+
const typeNodeIntersection = (0, _composeTs.composeKeyedIntersection)((domain, l, r, context)=>{
|
|
38
42
|
if (l === undefined) {
|
|
39
43
|
return r === undefined ? (0, _composeTs.throwUndefinedOperandsError)() : undefined;
|
|
40
44
|
}
|
|
@@ -51,15 +55,15 @@ const rootIntersection = (l, r, type)=>{
|
|
|
51
55
|
return (0, _composeTs.isDisjoint)(result) ? (0, _errorsTs.throwParseError)((0, _intersectionTs.compileDisjointReasonsMessage)(state.disjoints)) : (0, _composeTs.isEquality)(result) ? l : result;
|
|
52
56
|
};
|
|
53
57
|
const rootUnion = (l, r, type)=>{
|
|
54
|
-
const
|
|
55
|
-
const
|
|
58
|
+
const lDomains = type.scope.resolveTypeNode(l);
|
|
59
|
+
const rDomains = type.scope.resolveTypeNode(r);
|
|
56
60
|
const result = {};
|
|
57
61
|
const domains = (0, _genericsTs.objectKeysOf)({
|
|
58
|
-
...
|
|
59
|
-
...
|
|
62
|
+
...lDomains,
|
|
63
|
+
...rDomains
|
|
60
64
|
});
|
|
61
65
|
for (const domain of domains){
|
|
62
|
-
result[domain] = (0, _genericsTs.hasKey)(
|
|
66
|
+
result[domain] = (0, _genericsTs.hasKey)(lDomains, domain) ? (0, _genericsTs.hasKey)(rDomains, domain) ? (0, _predicateTs.predicateUnion)(domain, lDomains[domain], rDomains[domain], type) : lDomains[domain] : (0, _genericsTs.hasKey)(rDomains, domain) ? rDomains[domain] : (0, _composeTs.throwUndefinedOperandsError)();
|
|
63
67
|
}
|
|
64
68
|
return result;
|
|
65
69
|
};
|
|
@@ -70,30 +74,25 @@ const flattenType = (type)=>{
|
|
|
70
74
|
path: new _pathsTs.Path(),
|
|
71
75
|
lastDomain: "undefined"
|
|
72
76
|
};
|
|
73
|
-
return type.
|
|
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 ? [
|
|
74
86
|
[
|
|
75
87
|
"config",
|
|
76
88
|
{
|
|
77
|
-
config:
|
|
78
|
-
node:
|
|
89
|
+
config: (0, _genericsTs.entriesOf)(node.config),
|
|
90
|
+
node: flattenedTypeNode
|
|
79
91
|
}
|
|
80
92
|
]
|
|
81
|
-
] :
|
|
93
|
+
] : flattenedTypeNode;
|
|
82
94
|
};
|
|
83
|
-
const
|
|
84
|
-
if (typeof node === "string") {
|
|
85
|
-
const resolution = ctx.type.meta.scope.resolve(node);
|
|
86
|
-
const updatedScopeConfig = resolution.meta.scope !== ctx.type.meta.scope && resolution.meta.scope.config;
|
|
87
|
-
return updatedScopeConfig ? [
|
|
88
|
-
[
|
|
89
|
-
"config",
|
|
90
|
-
{
|
|
91
|
-
config: updatedScopeConfig,
|
|
92
|
-
node: resolution.flat
|
|
93
|
-
}
|
|
94
|
-
]
|
|
95
|
-
] : resolution.flat;
|
|
96
|
-
}
|
|
95
|
+
const flattenTypeNode = (node, ctx)=>{
|
|
97
96
|
const domains = (0, _genericsTs.objectKeysOf)(node);
|
|
98
97
|
if (domains.length === 1) {
|
|
99
98
|
const domain = domains[0];
|
|
@@ -124,7 +123,11 @@ const flattenNode = (node, ctx)=>{
|
|
|
124
123
|
];
|
|
125
124
|
};
|
|
126
125
|
const isLiteralNode = (node, domain)=>{
|
|
127
|
-
return
|
|
126
|
+
return resolutionExtendsDomain(node, domain) && (0, _predicateTs.isLiteralCondition)(node[domain]);
|
|
127
|
+
};
|
|
128
|
+
const resolutionExtendsDomain = (resolution, domain)=>{
|
|
129
|
+
const domains = (0, _genericsTs.objectKeysOf)(resolution);
|
|
130
|
+
return domains.length === 1 && domains[0] === domain;
|
|
128
131
|
};
|
|
129
132
|
const toArrayNode = (node)=>({
|
|
130
133
|
object: {
|
|
@@ -13,15 +13,13 @@ _export(exports, {
|
|
|
13
13
|
predicateIntersection: ()=>predicateIntersection,
|
|
14
14
|
predicateUnion: ()=>predicateUnion,
|
|
15
15
|
flattenPredicate: ()=>flattenPredicate,
|
|
16
|
-
isLiteralCondition: ()=>isLiteralCondition
|
|
17
|
-
resolutionExtendsDomain: ()=>resolutionExtendsDomain
|
|
16
|
+
isLiteralCondition: ()=>isLiteralCondition
|
|
18
17
|
});
|
|
19
18
|
const _genericsTs = require("../utils/generics.js");
|
|
20
19
|
const _objectKindsTs = require("../utils/objectKinds.js");
|
|
21
20
|
const _branchTs = require("./branch.js");
|
|
22
21
|
const _composeTs = require("./compose.js");
|
|
23
22
|
const _discriminateTs = require("./discriminate.js");
|
|
24
|
-
require("./rules/rules.js");
|
|
25
23
|
const emptyRulesIfTrue = (predicate)=>predicate === true ? {} : predicate;
|
|
26
24
|
const comparePredicates = (l, r, context)=>{
|
|
27
25
|
if (l === true && r === true) {
|
|
@@ -86,7 +84,3 @@ const flattenPredicate = (predicate, context)=>{
|
|
|
86
84
|
return (0, _objectKindsTs.isArray)(predicate) ? (0, _discriminateTs.flattenBranches)(predicate, context) : (0, _branchTs.flattenBranch)(predicate, context);
|
|
87
85
|
};
|
|
88
86
|
const isLiteralCondition = (predicate)=>typeof predicate === "object" && "value" in predicate;
|
|
89
|
-
const resolutionExtendsDomain = (resolution, domain)=>{
|
|
90
|
-
const domains = (0, _genericsTs.objectKeysOf)(resolution);
|
|
91
|
-
return domains.length === 1 && domains[0] === domain;
|
|
92
|
-
};
|
|
@@ -83,6 +83,11 @@ const propKeysIntersection = (0, _composeTs.composeKeyedIntersection)((propKey,
|
|
|
83
83
|
onEmpty: "bubble"
|
|
84
84
|
});
|
|
85
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
|
|
86
91
|
for(const k in props){
|
|
87
92
|
const prop = props[k];
|
|
88
93
|
ctx.path.push(k);
|
|
@@ -119,3 +124,37 @@ const flattenProps = (entries, props, ctx)=>{
|
|
|
119
124
|
ctx.path.pop();
|
|
120
125
|
}
|
|
121
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, _nodeTs.flattenNode)(propToNode(prop), ctx);
|
|
140
|
+
} else if (isOptional(prop)) {
|
|
141
|
+
result.optional[k] = (0, _nodeTs.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, _nodeTs.flattenNode)(prop[1], ctx)
|
|
149
|
+
]
|
|
150
|
+
]);
|
|
151
|
+
} else {
|
|
152
|
+
result.required[k] = (0, _nodeTs.flattenNode)(prop, ctx);
|
|
153
|
+
}
|
|
154
|
+
ctx.path.pop();
|
|
155
|
+
}
|
|
156
|
+
entries.push([
|
|
157
|
+
`${kind}Props`,
|
|
158
|
+
result
|
|
159
|
+
]);
|
|
160
|
+
};
|
|
@@ -86,8 +86,9 @@ const ruleFlatteners = {
|
|
|
86
86
|
}
|
|
87
87
|
};
|
|
88
88
|
const precedenceMap = {
|
|
89
|
+
// Config: Applies before any checks
|
|
90
|
+
config: -1,
|
|
89
91
|
// Critical: No other checks are performed if these fail
|
|
90
|
-
config: 0,
|
|
91
92
|
domain: 0,
|
|
92
93
|
value: 0,
|
|
93
94
|
domains: 0,
|
|
@@ -104,6 +105,8 @@ const precedenceMap = {
|
|
|
104
105
|
// is invalid
|
|
105
106
|
prerequisiteProp: 2,
|
|
106
107
|
// Deep: Performed if all shallow checks pass, even if one or more deep checks fail
|
|
108
|
+
distilledProps: 3,
|
|
109
|
+
strictProps: 3,
|
|
107
110
|
requiredProp: 3,
|
|
108
111
|
optionalProp: 3,
|
|
109
112
|
indexProp: 3,
|
|
@@ -112,7 +115,7 @@ const precedenceMap = {
|
|
|
112
115
|
// Morph: Only performed if all validation passes
|
|
113
116
|
morph: 5
|
|
114
117
|
};
|
|
115
|
-
const literalSatisfiesRules = (data, rules, state)=>!state.type.
|
|
118
|
+
const literalSatisfiesRules = (data, rules, state)=>!state.type.scope.type([
|
|
116
119
|
"node",
|
|
117
120
|
{
|
|
118
121
|
[state.domain]: rules
|
|
@@ -0,0 +1,13 @@
|
|
|
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 _definitionTs = require("../definition.js");
|
|
10
|
+
const parseConfigTuple = (def, ctx)=>({
|
|
11
|
+
node: ctx.type.scope.resolveTypeNode((0, _definitionTs.parseDefinition)(def[0], ctx)),
|
|
12
|
+
config: def[2]
|
|
13
|
+
});
|
|
@@ -17,8 +17,8 @@ const _errorsTs = require("../../utils/errors.js");
|
|
|
17
17
|
const _genericsTs = require("../../utils/generics.js");
|
|
18
18
|
const _serializeTs = require("../../utils/serialize.js");
|
|
19
19
|
const writeMalformedDistributableFunctionMessage = (def)=>`Expected a Function or Record<Domain, Function> operand (${(0, _serializeTs.stringify)(def)} was invalid)`;
|
|
20
|
-
const distributeFunctionToNode = (distributableFunction,
|
|
21
|
-
const domains = (0, _genericsTs.objectKeysOf)(
|
|
20
|
+
const distributeFunctionToNode = (distributableFunction, node, ctx, ruleKey)=>{
|
|
21
|
+
const domains = (0, _genericsTs.objectKeysOf)(node);
|
|
22
22
|
if (!(0, _domainsTs.hasDomain)(distributableFunction, "object")) {
|
|
23
23
|
return (0, _errorsTs.throwParseError)(writeMalformedDistributableFunctionMessage(distributableFunction));
|
|
24
24
|
}
|
|
@@ -29,7 +29,7 @@ const arrayIndexNumberBranch = (0, _freezeTs.deepFreeze)({
|
|
|
29
29
|
divisor: 1
|
|
30
30
|
});
|
|
31
31
|
const parseKeyOfTuple = (def, ctx)=>{
|
|
32
|
-
const resolution = ctx.type.
|
|
32
|
+
const resolution = ctx.type.scope.resolveNode((0, _definitionTs.parseDefinition)(def[1], ctx));
|
|
33
33
|
const predicateKeys = (0, _genericsTs.objectKeysOf)(resolution).map((domain)=>keysOfPredicate(domain, resolution[domain]));
|
|
34
34
|
const sharedKeys = sharedKeysOf(predicateKeys);
|
|
35
35
|
if (!sharedKeys.length) {
|
|
@@ -21,9 +21,10 @@ const parseMorphTuple = (def, ctx)=>{
|
|
|
21
21
|
if (typeof def[2] !== "function") {
|
|
22
22
|
return (0, _errorsTs.throwParseError)(writeMalformedMorphExpressionMessage(def[2]));
|
|
23
23
|
}
|
|
24
|
-
const
|
|
24
|
+
const node = (0, _definitionTs.parseDefinition)(def[0], ctx);
|
|
25
|
+
const resolution = ctx.type.scope.resolveTypeNode(node);
|
|
25
26
|
const morph = def[2];
|
|
26
|
-
ctx.type.
|
|
27
|
+
ctx.type.includesMorph = true;
|
|
27
28
|
let domain;
|
|
28
29
|
const result = {};
|
|
29
30
|
for(domain in resolution){
|
|
@@ -41,7 +42,7 @@ const parseMorphTuple = (def, ctx)=>{
|
|
|
41
42
|
}
|
|
42
43
|
return result;
|
|
43
44
|
};
|
|
44
|
-
const applyMorph = (branch, morph)=>(0, _branchTs.
|
|
45
|
+
const applyMorph = (branch, morph)=>(0, _branchTs.isTransformationBranch)(branch) ? {
|
|
45
46
|
...branch,
|
|
46
47
|
morph: branch.morph ? Array.isArray(branch.morph) ? [
|
|
47
48
|
...branch.morph,
|
|
@@ -11,5 +11,12 @@ const _definitionTs = require("../definition.js");
|
|
|
11
11
|
const _distributableFunctionTs = require("./distributableFunction.js");
|
|
12
12
|
const parseNarrowTuple = (def, ctx)=>{
|
|
13
13
|
const inputNode = (0, _definitionTs.parseDefinition)(def[0], ctx);
|
|
14
|
-
|
|
14
|
+
const resolution = ctx.type.scope.resolveNode(inputNode);
|
|
15
|
+
const hasConfig = (0, _nodeTs.isConfigNode)(resolution);
|
|
16
|
+
const typeNode = hasConfig ? resolution.node : resolution;
|
|
17
|
+
const result = (0, _nodeTs.rootIntersection)(inputNode, (0, _distributableFunctionTs.distributeFunctionToNode)(def[2], typeNode, ctx, "narrow"), ctx.type);
|
|
18
|
+
return hasConfig ? {
|
|
19
|
+
config: resolution.config,
|
|
20
|
+
node: result
|
|
21
|
+
} : result;
|
|
15
22
|
};
|
|
File without changes
|
|
@@ -17,6 +17,7 @@ const _domainsTs = require("../../utils/domains.js");
|
|
|
17
17
|
const _errorsTs = require("../../utils/errors.js");
|
|
18
18
|
const _definitionTs = require("../definition.js");
|
|
19
19
|
const _unenclosedTs = require("../string/shift/operand/unenclosed.js");
|
|
20
|
+
const _configTs = require("./config.js");
|
|
20
21
|
const _keyofTs = require("./keyof.js");
|
|
21
22
|
const _morphTs = require("./morph.js");
|
|
22
23
|
const _narrowTs = require("./narrow.js");
|
|
@@ -69,7 +70,7 @@ const indexOneParsers = {
|
|
|
69
70
|
"[]": parseArrayTuple,
|
|
70
71
|
"=>": _narrowTs.parseNarrowTuple,
|
|
71
72
|
"|>": _morphTs.parseMorphTuple,
|
|
72
|
-
":":
|
|
73
|
+
":": _configTs.parseConfigTuple
|
|
73
74
|
};
|
|
74
75
|
const prefixParsers = {
|
|
75
76
|
keyof: _keyofTs.parseKeyOfTuple,
|
|
@@ -44,12 +44,12 @@ const parseDefinition = (def, ctx)=>{
|
|
|
44
44
|
};
|
|
45
45
|
case "Function":
|
|
46
46
|
if ((0, _typeTs.isType)(def)) {
|
|
47
|
-
return def
|
|
47
|
+
return ctx.type.scope.addAnonymousTypeReference(def, ctx);
|
|
48
48
|
}
|
|
49
49
|
if (isThunk(def)) {
|
|
50
50
|
const returned = def();
|
|
51
51
|
if ((0, _typeTs.isType)(returned)) {
|
|
52
|
-
return returned
|
|
52
|
+
return ctx.type.scope.addAnonymousTypeReference(returned, ctx);
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
return (0, _errorsTs.throwParseError)(writeBadDefinitionTypeMessage("Function"));
|
|
@@ -22,7 +22,7 @@ class DynamicState {
|
|
|
22
22
|
}
|
|
23
23
|
resolveRoot() {
|
|
24
24
|
this.assertHasRoot();
|
|
25
|
-
return this.ctx.type.
|
|
25
|
+
return this.ctx.type.scope.resolveTypeNode(this.root);
|
|
26
26
|
}
|
|
27
27
|
rootToString() {
|
|
28
28
|
this.assertHasRoot();
|
|
@@ -30,7 +30,7 @@ class DynamicState {
|
|
|
30
30
|
}
|
|
31
31
|
ejectRootIfLimit() {
|
|
32
32
|
this.assertHasRoot();
|
|
33
|
-
const resolution = typeof this.root === "string" ? this.ctx.type.
|
|
33
|
+
const resolution = typeof this.root === "string" ? this.ctx.type.scope.resolveNode(this.root) : this.root;
|
|
34
34
|
if ((0, _nodeTs.isLiteralNode)(resolution, "number")) {
|
|
35
35
|
const limit = resolution.number.value;
|
|
36
36
|
this.root = undefined;
|
|
@@ -21,7 +21,7 @@ const parseUnenclosed = (s)=>{
|
|
|
21
21
|
s.setRoot(unenclosedToNode(s, token));
|
|
22
22
|
};
|
|
23
23
|
const unenclosedToNode = (s, token)=>{
|
|
24
|
-
if (s.ctx.type.
|
|
24
|
+
if (s.ctx.type.scope.addParsedReferenceIfResolvable(token, s.ctx)) {
|
|
25
25
|
return token;
|
|
26
26
|
}
|
|
27
27
|
return maybeParseUnenclosedLiteral(token) ?? s.error(token === "" ? writeMissingOperandMessage(s) : writeUnresolvableMessage(token));
|
|
@@ -17,14 +17,14 @@ const _nodeTs = require("../../nodes/node.js");
|
|
|
17
17
|
const _dynamicTs = require("./reduce/dynamic.js");
|
|
18
18
|
const _operandTs = require("./shift/operand/operand.js");
|
|
19
19
|
const _operatorTs = require("./shift/operator/operator.js");
|
|
20
|
-
const parseString = (def, ctx)=>ctx.type.
|
|
20
|
+
const parseString = (def, ctx)=>ctx.type.scope.parseCache.get(def) ?? ctx.type.scope.parseCache.set(def, maybeNaiveParse(def, ctx) ?? fullStringParse(def, ctx));
|
|
21
21
|
const maybeNaiveParse = (def, ctx)=>{
|
|
22
|
-
if (ctx.type.
|
|
22
|
+
if (ctx.type.scope.addParsedReferenceIfResolvable(def, ctx)) {
|
|
23
23
|
return def;
|
|
24
24
|
}
|
|
25
25
|
if (def.endsWith("[]")) {
|
|
26
26
|
const elementDef = def.slice(0, -2);
|
|
27
|
-
if (ctx.type.
|
|
27
|
+
if (ctx.type.scope.addParsedReferenceIfResolvable(def, ctx)) {
|
|
28
28
|
return (0, _nodeTs.toArrayNode)(elementDef);
|
|
29
29
|
}
|
|
30
30
|
}
|
|
@@ -9,8 +9,8 @@ function _export(target, all) {
|
|
|
9
9
|
});
|
|
10
10
|
}
|
|
11
11
|
_export(exports, {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
arkscope: ()=>arkscope,
|
|
13
|
+
ark: ()=>ark,
|
|
14
14
|
scopes: ()=>scopes,
|
|
15
15
|
spaces: ()=>spaces,
|
|
16
16
|
type: ()=>type
|
|
@@ -18,8 +18,8 @@ _export(exports, {
|
|
|
18
18
|
const _jsObjectsTs = require("./jsObjects.js");
|
|
19
19
|
const _scopeTs = require("./scope.js");
|
|
20
20
|
const _tsKeywordsTs = require("./tsKeywords.js");
|
|
21
|
-
const _validationTs = require("./validation.js");
|
|
22
|
-
const
|
|
21
|
+
const _validationTs = require("./validation/validation.js");
|
|
22
|
+
const arkscope = (0, _scopeTs.scope)({}, {
|
|
23
23
|
name: "standard",
|
|
24
24
|
includes: [
|
|
25
25
|
_tsKeywordsTs.tsKeywords,
|
|
@@ -28,17 +28,18 @@ const standardScope = (0, _scopeTs.scope)({}, {
|
|
|
28
28
|
],
|
|
29
29
|
standard: false
|
|
30
30
|
});
|
|
31
|
-
const
|
|
31
|
+
const ark = arkscope.compile();
|
|
32
32
|
const scopes = {
|
|
33
|
+
root: _scopeTs.rootScope,
|
|
33
34
|
tsKeywords: _tsKeywordsTs.tsKeywordsScope,
|
|
34
35
|
jsObjects: _jsObjectsTs.jsObjectsScope,
|
|
35
36
|
validation: _validationTs.validationScope,
|
|
36
|
-
|
|
37
|
+
ark: arkscope
|
|
37
38
|
};
|
|
38
39
|
const spaces = {
|
|
39
40
|
tsKeywords: _tsKeywordsTs.tsKeywords,
|
|
40
41
|
jsObjects: _jsObjectsTs.jsObjects,
|
|
41
42
|
validation: _validationTs.validation,
|
|
42
|
-
|
|
43
|
+
ark
|
|
43
44
|
};
|
|
44
|
-
const type =
|
|
45
|
+
const type = arkscope.type;
|
|
@@ -18,12 +18,12 @@ _export(exports, {
|
|
|
18
18
|
narrow: ()=>narrow,
|
|
19
19
|
morph: ()=>morph
|
|
20
20
|
});
|
|
21
|
-
const
|
|
22
|
-
const intersection =
|
|
23
|
-
const union =
|
|
24
|
-
const arrayOf =
|
|
25
|
-
const keyOf =
|
|
26
|
-
const instanceOf =
|
|
27
|
-
const valueOf =
|
|
28
|
-
const narrow =
|
|
29
|
-
const morph =
|
|
21
|
+
const _arkTs = require("./ark.js");
|
|
22
|
+
const intersection = _arkTs.scopes.ark.intersection;
|
|
23
|
+
const union = _arkTs.scopes.ark.union;
|
|
24
|
+
const arrayOf = _arkTs.scopes.ark.arrayOf;
|
|
25
|
+
const keyOf = _arkTs.scopes.ark.keyOf;
|
|
26
|
+
const instanceOf = _arkTs.scopes.ark.instanceOf;
|
|
27
|
+
const valueOf = _arkTs.scopes.ark.valueOf;
|
|
28
|
+
const narrow = _arkTs.scopes.ark.narrow;
|
|
29
|
+
const morph = _arkTs.scopes.ark.morph;
|