arktype 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.cjs +9 -0
- package/dist/api.d.ts +10 -0
- package/dist/api.mjs +1 -0
- package/dist/cjs/nodes/{branches.js → branch.js} +65 -10
- package/dist/cjs/nodes/compose.js +2 -3
- package/dist/cjs/nodes/discriminate.js +9 -15
- package/dist/cjs/nodes/node.js +21 -11
- package/dist/cjs/nodes/predicate.js +8 -10
- package/dist/cjs/nodes/rules/class.js +10 -4
- package/dist/cjs/nodes/rules/divisor.js +1 -5
- package/dist/cjs/nodes/rules/props.js +75 -25
- package/dist/cjs/nodes/rules/range.js +2 -6
- package/dist/cjs/nodes/rules/regex.js +1 -5
- package/dist/cjs/nodes/rules/rules.js +23 -63
- package/dist/cjs/parse/ast/ast.js +4 -0
- package/dist/cjs/parse/ast/bound.js +9 -0
- package/dist/cjs/parse/{tuple/utils.js → ast/distributableFunction.js} +1 -1
- package/dist/cjs/parse/ast/divisor.js +9 -0
- package/dist/cjs/parse/{string/ast.js → ast/intersection.js} +2 -8
- package/dist/cjs/parse/ast/keyof.js +109 -0
- package/dist/cjs/parse/{tuple → ast}/morph.js +2 -2
- package/dist/cjs/parse/{tuple → ast}/narrow.js +2 -2
- package/dist/cjs/parse/{tuple → ast}/tuple.js +23 -16
- package/dist/cjs/parse/ast/union.js +9 -0
- package/dist/cjs/parse/ast/utils.js +4 -0
- package/dist/cjs/parse/definition.js +12 -2
- package/dist/cjs/parse/string/reduce/dynamic.js +7 -8
- package/dist/cjs/parse/string/shift/operator/bounds.js +4 -4
- package/dist/cjs/parse/string/shift/operator/divisor.js +3 -3
- package/dist/cjs/parse/string/string.js +2 -2
- package/dist/cjs/scopes/expressions.js +29 -0
- package/dist/cjs/scopes/jsObjects.js +14 -14
- package/dist/cjs/scopes/scope.js +56 -4
- package/dist/cjs/scopes/type.js +4 -7
- package/dist/cjs/traverse/problems.js +67 -53
- package/dist/cjs/traverse/traverse.js +103 -135
- package/dist/cjs/utils/data.js +39 -0
- package/dist/cjs/utils/generics.js +20 -2
- package/dist/cjs/utils/numericLiterals.js +2 -0
- package/dist/cjs/utils/objectKinds.js +1 -2
- package/dist/mjs/nodes/{branches.js → branch.js} +54 -2
- package/dist/mjs/nodes/compose.js +3 -4
- package/dist/mjs/nodes/discriminate.js +9 -15
- package/dist/mjs/nodes/node.js +17 -8
- package/dist/mjs/nodes/predicate.js +4 -5
- package/dist/mjs/nodes/rules/class.js +10 -4
- package/dist/mjs/nodes/rules/divisor.js +1 -5
- package/dist/mjs/nodes/rules/props.js +74 -27
- package/dist/mjs/nodes/rules/range.js +2 -6
- package/dist/mjs/nodes/rules/regex.js +1 -5
- package/dist/mjs/nodes/rules/rules.js +23 -62
- package/dist/mjs/parse/ast/ast.js +1 -0
- package/dist/mjs/parse/ast/bound.js +1 -0
- package/dist/mjs/parse/{tuple/utils.js → ast/distributableFunction.js} +2 -2
- package/dist/mjs/parse/ast/divisor.js +1 -0
- package/dist/mjs/parse/{string/ast.js → ast/intersection.js} +2 -5
- package/dist/mjs/parse/ast/keyof.js +101 -0
- package/dist/mjs/parse/{tuple → ast}/morph.js +2 -2
- package/dist/mjs/parse/ast/narrow.js +7 -0
- package/dist/mjs/parse/{tuple → ast}/tuple.js +24 -17
- package/dist/mjs/parse/ast/union.js +1 -0
- package/dist/mjs/parse/ast/utils.js +1 -0
- package/dist/mjs/parse/definition.js +12 -2
- package/dist/mjs/parse/string/reduce/dynamic.js +8 -9
- package/dist/mjs/parse/string/shift/operator/bounds.js +4 -4
- package/dist/mjs/parse/string/shift/operator/divisor.js +3 -3
- package/dist/mjs/parse/string/string.js +2 -2
- package/dist/mjs/scopes/expressions.js +9 -0
- package/dist/mjs/scopes/jsObjects.js +14 -14
- package/dist/mjs/scopes/scope.js +55 -3
- package/dist/mjs/scopes/type.js +4 -7
- package/dist/mjs/traverse/problems.js +68 -53
- package/dist/mjs/traverse/traverse.js +107 -139
- package/dist/mjs/utils/data.js +24 -0
- package/dist/mjs/utils/generics.js +18 -1
- package/dist/mjs/utils/numericLiterals.js +1 -0
- package/dist/mjs/utils/objectKinds.js +1 -1
- package/dist/tsconfig.temp.tsbuildinfo +1 -1
- package/dist/types/nodes/branch.d.ts +27 -0
- package/dist/types/nodes/compose.d.ts +5 -10
- package/dist/types/nodes/discriminate.d.ts +3 -3
- package/dist/types/nodes/infer.d.ts +21 -20
- package/dist/types/nodes/node.d.ts +12 -16
- package/dist/types/nodes/predicate.d.ts +4 -59
- package/dist/types/nodes/rules/class.d.ts +3 -2
- package/dist/types/nodes/rules/divisor.d.ts +2 -1
- package/dist/types/nodes/rules/props.d.ts +19 -11
- package/dist/types/nodes/rules/range.d.ts +3 -2
- package/dist/types/nodes/rules/regex.d.ts +2 -1
- package/dist/types/nodes/rules/rules.d.ts +12 -14
- package/dist/types/parse/ast/ast.d.ts +24 -0
- package/dist/types/parse/ast/bound.d.ts +10 -0
- package/dist/types/parse/{tuple/utils.d.ts → ast/distributableFunction.d.ts} +2 -3
- package/dist/types/parse/ast/divisor.d.ts +8 -0
- package/dist/types/parse/ast/intersection.d.ts +17 -0
- package/dist/types/parse/{tuple → ast}/keyof.d.ts +4 -4
- package/dist/types/parse/{tuple → ast}/morph.d.ts +3 -3
- package/dist/types/parse/ast/narrow.d.ts +21 -0
- package/dist/types/parse/ast/tuple.d.ts +40 -0
- package/dist/types/parse/ast/union.d.ts +12 -0
- package/dist/types/parse/ast/utils.d.ts +7 -0
- package/dist/types/parse/definition.d.ts +9 -7
- package/dist/types/parse/record.d.ts +2 -2
- package/dist/types/parse/string/reduce/dynamic.d.ts +1 -1
- package/dist/types/parse/string/reduce/shared.d.ts +6 -5
- package/dist/types/parse/string/reduce/static.d.ts +11 -6
- package/dist/types/parse/string/shift/operand/unenclosed.d.ts +2 -2
- package/dist/types/parse/string/shift/operator/bounds.d.ts +4 -3
- package/dist/types/parse/string/shift/operator/divisor.d.ts +5 -1
- package/dist/types/parse/string/string.d.ts +2 -3
- package/dist/types/scopes/expressions.d.ts +48 -0
- package/dist/types/scopes/scope.d.ts +17 -7
- package/dist/types/scopes/type.d.ts +13 -15
- package/dist/types/traverse/problems.d.ts +17 -41
- package/dist/types/traverse/traverse.d.ts +85 -52
- package/dist/types/utils/data.d.ts +13 -0
- package/dist/types/utils/domains.d.ts +1 -1
- package/dist/types/utils/generics.d.ts +13 -10
- package/dist/types/utils/numericLiterals.d.ts +1 -0
- package/dist/types/utils/objectKinds.d.ts +43 -43
- package/dist/types/utils/paths.d.ts +2 -0
- package/package.json +1 -2
- package/dist/cjs/nodes/functors.js +0 -35
- package/dist/cjs/nodes/rules/objectKind.js +0 -78
- package/dist/cjs/parse/tuple/keyof.js +0 -45
- package/dist/cjs/utils/size.js +0 -16
- package/dist/mjs/nodes/functors.js +0 -27
- package/dist/mjs/nodes/rules/objectKind.js +0 -63
- package/dist/mjs/parse/tuple/keyof.js +0 -37
- package/dist/mjs/parse/tuple/narrow.js +0 -7
- package/dist/mjs/utils/size.js +0 -2
- package/dist/types/nodes/branches.d.ts +0 -14
- package/dist/types/nodes/functors.d.ts +0 -6
- package/dist/types/nodes/rules/objectKind.d.ts +0 -15
- package/dist/types/parse/string/ast.d.ts +0 -45
- package/dist/types/parse/tuple/narrow.d.ts +0 -13
- package/dist/types/parse/tuple/tuple.d.ts +0 -31
- package/dist/types/utils/size.d.ts +0 -3
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Morph } from "../parse/ast/morph.js";
|
|
2
|
+
import type { Domain } from "../utils/domains.js";
|
|
3
|
+
import type { CollapsibleList, Dict, List } from "../utils/generics.js";
|
|
4
|
+
import type { IntersectionState, Intersector } from "./compose.js";
|
|
5
|
+
import type { FlattenContext } from "./node.js";
|
|
6
|
+
import type { PredicateComparison } from "./predicate.js";
|
|
7
|
+
import type { Rules } from "./rules/rules.js";
|
|
8
|
+
export type Branch<domain extends Domain = Domain, $ = Dict> = Rules<domain, $> | MorphBranch<domain, $>;
|
|
9
|
+
export type MorphBranch<domain extends Domain = Domain, $ = Dict> = {
|
|
10
|
+
rules: Rules<domain, $>;
|
|
11
|
+
morph: CollapsibleList<Morph>;
|
|
12
|
+
};
|
|
13
|
+
export type Branches = List<Branch>;
|
|
14
|
+
export type MorphEntry = ["morph", Morph];
|
|
15
|
+
export declare const isBranchComparison: (comparison: PredicateComparison) => comparison is BranchesComparison;
|
|
16
|
+
export type BranchesComparison = {
|
|
17
|
+
lBranches: Branches;
|
|
18
|
+
rBranches: Branches;
|
|
19
|
+
lExtendsR: number[];
|
|
20
|
+
rExtendsL: number[];
|
|
21
|
+
equalities: [lIndex: number, rIndex: number][];
|
|
22
|
+
distinctIntersections: Branches;
|
|
23
|
+
};
|
|
24
|
+
export declare const compareBranches: (lConditions: Branches, rConditions: Branches, state: IntersectionState) => BranchesComparison;
|
|
25
|
+
export declare const isMorphBranch: (branch: Branch) => branch is MorphBranch<Domain, Dict>;
|
|
26
|
+
export declare const flattenBranch: (branch: Branch, ctx: FlattenContext) => import("./node.js").TraversalEntry[];
|
|
27
|
+
export declare const branchIntersection: Intersector<Branch>;
|
|
@@ -3,7 +3,7 @@ import type { Domain } from "../utils/domains.js";
|
|
|
3
3
|
import type { constructor, Dict, extend } from "../utils/generics.js";
|
|
4
4
|
import type { DefaultObjectKind } from "../utils/objectKinds.js";
|
|
5
5
|
import { Path } from "../utils/paths.js";
|
|
6
|
-
import type { Branches } from "./
|
|
6
|
+
import type { Branches } from "./branch.js";
|
|
7
7
|
import type { Range } from "./rules/range.js";
|
|
8
8
|
import type { LiteralRules, NarrowableRules } from "./rules/rules.js";
|
|
9
9
|
export type Intersector<t> = (l: t, r: t, state: IntersectionState) => IntersectionResult<t>;
|
|
@@ -19,22 +19,18 @@ export type DisjointKinds = extend<Record<string, {
|
|
|
19
19
|
l: Domain[];
|
|
20
20
|
r: Domain[];
|
|
21
21
|
};
|
|
22
|
-
objectKind: {
|
|
23
|
-
l: DefaultObjectKind;
|
|
24
|
-
r: DefaultObjectKind;
|
|
25
|
-
};
|
|
26
22
|
range: {
|
|
27
23
|
l: Range;
|
|
28
24
|
r: Range;
|
|
29
25
|
};
|
|
30
|
-
class: {
|
|
31
|
-
l: constructor;
|
|
32
|
-
r: constructor;
|
|
33
|
-
};
|
|
34
26
|
tupleLength: {
|
|
35
27
|
l: number;
|
|
36
28
|
r: number;
|
|
37
29
|
};
|
|
30
|
+
class: {
|
|
31
|
+
l: DefaultObjectKind | constructor;
|
|
32
|
+
r: DefaultObjectKind | constructor;
|
|
33
|
+
};
|
|
38
34
|
value: {
|
|
39
35
|
l: unknown;
|
|
40
36
|
r: unknown;
|
|
@@ -54,7 +50,6 @@ export type DisjointKinds = extend<Record<string, {
|
|
|
54
50
|
}>;
|
|
55
51
|
export declare const disjointDescriptionWriters: {
|
|
56
52
|
domain: ({ l, r }: DisjointContext<"domain">) => string;
|
|
57
|
-
objectKind: ({ l, r }: DisjointContext<"objectKind">) => string;
|
|
58
53
|
range: ({ l, r }: DisjointContext<"range">) => string;
|
|
59
54
|
class: ({ l, r }: DisjointContext<"class">) => string;
|
|
60
55
|
tupleLength: ({ l, r }: DisjointContext<"tupleLength">) => string;
|
|
@@ -4,7 +4,7 @@ import type { NumberLiteral } from "../utils/numericLiterals.js";
|
|
|
4
4
|
import type { DefaultObjectKind } from "../utils/objectKinds.js";
|
|
5
5
|
import { Path } from "../utils/paths.js";
|
|
6
6
|
import type { SerializedPrimitive } from "../utils/serialize.js";
|
|
7
|
-
import type { Branches } from "./
|
|
7
|
+
import type { Branches } from "./branch.js";
|
|
8
8
|
import type { FlattenContext, TraversalEntry } from "./node.js";
|
|
9
9
|
export type DiscriminatedSwitch<kind extends DiscriminantKind = DiscriminantKind> = {
|
|
10
10
|
readonly path: Path;
|
|
@@ -22,7 +22,7 @@ export type DiscriminantKinds = {
|
|
|
22
22
|
value: unknown;
|
|
23
23
|
};
|
|
24
24
|
export type DiscriminantKind = evaluate<keyof DiscriminantKinds>;
|
|
25
|
-
export declare const serializeIfAllowed: <kind extends
|
|
26
|
-
export declare const serializeCase: <kind extends
|
|
25
|
+
export declare const serializeIfAllowed: <kind extends DiscriminantKind>(kind: kind, data: DiscriminantKinds[kind]) => CaseKey<kind> | undefined;
|
|
26
|
+
export declare const serializeCase: <kind extends DiscriminantKind>(kind: kind, data: unknown) => CaseKey<kind>;
|
|
27
27
|
type CaseKey<kind extends DiscriminantKind = DiscriminantKind> = kind extends "value" ? SerializedPrimitive | "default" : kind extends "tupleLength" ? NumberLiteral | "default" : DiscriminantKinds[kind];
|
|
28
28
|
export {};
|
|
@@ -1,36 +1,37 @@
|
|
|
1
|
-
import type { inferTerminal } from "../parse/
|
|
2
|
-
import type { Out } from "../parse/
|
|
1
|
+
import type { inferTerminal } from "../parse/ast/ast.js";
|
|
2
|
+
import type { Out } from "../parse/ast/morph.js";
|
|
3
3
|
import type { Domain, inferDomain } from "../utils/domains.js";
|
|
4
|
-
import type { evaluate,
|
|
4
|
+
import type { constructor, evaluate, evaluateObjectOrFunction, HomogenousTuple, List, returnOf } from "../utils/generics.js";
|
|
5
5
|
import type { BuiltinClass, DefaultObjectKind, inferObjectKind } from "../utils/objectKinds.js";
|
|
6
|
-
import type {
|
|
7
|
-
import type {
|
|
8
|
-
import type {
|
|
9
|
-
import type { OptionalProp, PropsRule } from "./rules/props.js";
|
|
10
|
-
import type { Bound, Range } from "./rules/range.js";
|
|
6
|
+
import type { MorphBranch } from "./branch.js";
|
|
7
|
+
import type { LiteralNode, ResolvedNode, TypeNode } from "./node.js";
|
|
8
|
+
import type { Predicate } from "./predicate.js";
|
|
9
|
+
import type { MappedPropKey, OptionalProp, Prop, PropsRule } from "./rules/props.js";
|
|
11
10
|
import type { LiteralRules, NarrowableRules } from "./rules/rules.js";
|
|
12
|
-
export type inferNode<node extends TypeNode<$>, $ = {}> = node extends string ? inferTerminal<node, $> : node extends ResolvedNode<$> ? inferResolution<node, $> extends infer result ? result extends BuiltinClass ? result :
|
|
11
|
+
export type inferNode<node extends TypeNode<$>, $ = {}> = node extends string ? inferTerminal<node, $> : node extends ResolvedNode<$> ? inferResolution<node, $> extends infer result ? result extends BuiltinClass ? result : evaluateObjectOrFunction<result> : never : never;
|
|
13
12
|
export type inferResolution<node extends ResolvedNode<$>, $> = {
|
|
14
13
|
[domain in keyof node]: inferPredicate<domain, node[domain], $>;
|
|
15
14
|
}[keyof node];
|
|
16
15
|
type inferPredicate<domain extends Domain, predicate extends Predicate, $> = predicate extends true ? inferDomain<domain> : inferBranch<domain, branchFrom<predicate>, $>;
|
|
17
16
|
type branchFrom<predicate extends Predicate> = predicate extends List ? predicate[number] : predicate;
|
|
18
|
-
type inferBranch<domain extends Domain, branch, $> = branch extends
|
|
19
|
-
type inferMorph<domain extends Domain, branch extends
|
|
17
|
+
type inferBranch<domain extends Domain, branch, $> = branch extends MorphBranch ? inferMorph<domain, branch, $> : inferRules<domain, branch, $>;
|
|
18
|
+
type inferMorph<domain extends Domain, branch extends MorphBranch, $> = (In: inferBranch<domain, branch["rules"], $>) => Out<branch["morph"] extends [...unknown[], infer tail] ? returnOf<tail> : returnOf<branch["morph"]>>;
|
|
20
19
|
type inferRules<domain extends Domain, branch, $> = branch extends LiteralRules ? branch["value"] : domain extends "object" ? branch extends NarrowableRules ? inferObjectRules<branch, $> : object : inferDomain<domain>;
|
|
21
|
-
type inferObjectRules<rules extends NarrowableRules, $> = rules["
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
type inferObjectRules<rules extends NarrowableRules, $> = rules["class"] extends DefaultObjectKind ? [rules["class"], rules["props"]] extends [
|
|
21
|
+
"Array",
|
|
22
|
+
{
|
|
23
|
+
"[index]": Prop<$, infer indexNode>;
|
|
24
|
+
length?: Prop<$, infer lengthNode>;
|
|
25
|
+
}
|
|
26
|
+
] ? lengthNode extends LiteralNode<"number", infer value> ? HomogenousTuple<inferNode<indexNode, $>, value> : inferNode<indexNode, $>[] : inferObjectKind<rules["class"]> : rules["class"] extends constructor<infer instance> ? instance : rules["props"] extends PropsRule ? inferProps<rules["props"], $> : object;
|
|
27
|
+
type inferProps<props extends PropsRule, $> = evaluate<{
|
|
28
|
+
[k in requiredKeyOf<props>]: props[k] extends Prop<$, infer node> ? inferNode<node, $> : never;
|
|
29
29
|
} & {
|
|
30
30
|
[k in optionalKeyOf<props>]?: props[k] extends OptionalProp<$> ? inferNode<props[k][1], $> : never;
|
|
31
31
|
}>;
|
|
32
32
|
type optionalKeyOf<props extends PropsRule> = {
|
|
33
33
|
[k in keyof props]: props[k] extends OptionalProp ? k : never;
|
|
34
34
|
}[keyof props];
|
|
35
|
-
type
|
|
35
|
+
type mappedKeyOf<props extends PropsRule> = Extract<keyof props, MappedPropKey>;
|
|
36
|
+
type requiredKeyOf<props extends PropsRule> = Exclude<keyof props, optionalKeyOf<props> | mappedKeyOf<props>>;
|
|
36
37
|
export {};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import type { ParseContext } from "../parse/definition.js";
|
|
2
2
|
import type { Type, TypeConfig } from "../scopes/type.js";
|
|
3
|
-
import type { Domain } from "../utils/domains.js";
|
|
3
|
+
import type { Domain, inferDomain } from "../utils/domains.js";
|
|
4
4
|
import type { Dict, stringKeyOf } from "../utils/generics.js";
|
|
5
|
+
import type { MorphEntry } from "./branch.js";
|
|
5
6
|
import type { Intersector } from "./compose.js";
|
|
6
7
|
import type { DiscriminatedSwitch } from "./discriminate.js";
|
|
7
|
-
import type {
|
|
8
|
+
import type { Predicate } from "./predicate.js";
|
|
8
9
|
import type { LiteralRules, RuleEntry } from "./rules/rules.js";
|
|
9
10
|
export type TypeNode<$ = Dict> = Identifier<$> | ResolvedNode<$>;
|
|
10
11
|
export type Identifier<$ = Dict> = stringKeyOf<$>;
|
|
@@ -12,15 +13,15 @@ export type ResolvedNode<$ = Dict> = {
|
|
|
12
13
|
readonly [domain in Domain]?: Predicate<domain, $>;
|
|
13
14
|
};
|
|
14
15
|
export declare const nodeIntersection: Intersector<TypeNode>;
|
|
15
|
-
export declare const
|
|
16
|
-
export declare const
|
|
16
|
+
export declare const rootIntersection: (l: TypeNode, r: TypeNode, type: Type) => TypeNode;
|
|
17
|
+
export declare const rootUnion: (l: TypeNode, r: TypeNode, type: Type) => ResolvedNode;
|
|
17
18
|
export type TraversalNode = Domain | TraversalEntry[];
|
|
18
|
-
export type TraversalEntry = RuleEntry | MorphEntry | DomainsEntry | CyclicReferenceEntry | DomainEntry | BranchesEntry | SwitchEntry | ConfigEntry;
|
|
19
19
|
export type TraversalKey = TraversalEntry[0];
|
|
20
|
-
export type
|
|
20
|
+
export type TraversalValue<k extends TraversalKey> = Extract<TraversalEntry, [
|
|
21
21
|
k,
|
|
22
22
|
unknown
|
|
23
23
|
]>[1];
|
|
24
|
+
export type TraversalEntry = RuleEntry | DomainsEntry | MorphEntry | CyclicReferenceEntry | DomainEntry | BranchesEntry | SwitchEntry | ConfigEntry;
|
|
24
25
|
export type CyclicReferenceEntry = ["alias", string];
|
|
25
26
|
export type ConfigEntry = [
|
|
26
27
|
"config",
|
|
@@ -43,13 +44,8 @@ export type FlattenContext = ParseContext & {
|
|
|
43
44
|
};
|
|
44
45
|
export declare const flattenType: (type: Type) => TraversalNode;
|
|
45
46
|
export declare const flattenNode: (node: TypeNode, ctx: FlattenContext) => TraversalNode;
|
|
46
|
-
export
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
string: string;
|
|
52
|
-
symbol: symbol;
|
|
53
|
-
undefined: undefined;
|
|
54
|
-
null: null;
|
|
55
|
-
}>(node: ResolvedNode, domain: domain) => node is { [_ in domain]: LiteralRules<domain>; };
|
|
47
|
+
export type LiteralNode<domain extends Domain = Domain, value extends inferDomain<domain> = inferDomain<domain>> = {
|
|
48
|
+
[k in domain]: LiteralRules<domain, value>;
|
|
49
|
+
};
|
|
50
|
+
export declare const isLiteralNode: <domain extends Domain>(node: ResolvedNode, domain: domain) => node is LiteralNode<domain, inferDomain<domain>>;
|
|
51
|
+
export declare const toArrayNode: (node: TypeNode) => ResolvedNode;
|
|
@@ -1,77 +1,22 @@
|
|
|
1
|
-
import type { Morph } from "../parse/tuple/morph.js";
|
|
2
1
|
import type { Type } from "../scopes/type.js";
|
|
3
2
|
import type { Domain } from "../utils/domains.js";
|
|
4
3
|
import type { CollapsibleList, defined, Dict } from "../utils/generics.js";
|
|
5
|
-
import type { BranchesComparison } from "./
|
|
4
|
+
import type { Branch, BranchesComparison } from "./branch.js";
|
|
6
5
|
import type { IntersectionResult, KeyIntersectionFn } from "./compose.js";
|
|
7
6
|
import { IntersectionState } from "./compose.js";
|
|
8
7
|
import type { FlattenContext, ResolvedNode, TraversalEntry } from "./node.js";
|
|
9
|
-
import type {
|
|
8
|
+
import type { LiteralRules } from "./rules/rules.js";
|
|
10
9
|
/** If scope is provided, we also narrow each predicate to match its domain.
|
|
11
10
|
* Otherwise, we use a base predicate for all types, which is easier to
|
|
12
11
|
* manipulate.*/
|
|
13
12
|
export type Predicate<domain extends Domain = Domain, $ = Dict> = string extends keyof $ ? true | CollapsibleList<Branch> : true | CollapsibleList<Branch<domain, $>>;
|
|
14
|
-
export type Branch<domain extends Domain = Domain, $ = Dict> = Rules<domain, $> | TransformationBranch<domain, $>;
|
|
15
|
-
export type TransformationBranch<domain extends Domain = Domain, $ = Dict> = {
|
|
16
|
-
rules: Rules<domain, $>;
|
|
17
|
-
morph?: CollapsibleList<Morph>;
|
|
18
|
-
};
|
|
19
|
-
export declare const branchIsTransformation: (branch: Branch) => branch is TransformationBranch<keyof {
|
|
20
|
-
bigint: bigint;
|
|
21
|
-
boolean: boolean;
|
|
22
|
-
number: number;
|
|
23
|
-
object: object;
|
|
24
|
-
string: string;
|
|
25
|
-
symbol: symbol;
|
|
26
|
-
undefined: undefined;
|
|
27
|
-
null: null;
|
|
28
|
-
}, Dict>;
|
|
29
|
-
export type FlatBranch = FlatRules | FlatTransformationBranch;
|
|
30
|
-
export type FlatTransformationBranch = [...rules: FlatRules, morph: MorphEntry];
|
|
31
|
-
export type MorphEntry = ["morph", CollapsibleList<Morph>];
|
|
32
13
|
export type PredicateComparison = IntersectionResult<Predicate> | BranchesComparison;
|
|
33
14
|
export declare const comparePredicates: (l: Predicate, r: Predicate, context: IntersectionState) => PredicateComparison;
|
|
34
15
|
export declare const predicateIntersection: KeyIntersectionFn<Required<ResolvedNode>>;
|
|
35
|
-
export declare const predicateUnion: (domain: Domain, l: Predicate, r: Predicate, type: Type) => true | import("./rules/rules.js").NarrowableRules<Dict> | LiteralRules<
|
|
36
|
-
bigint: bigint;
|
|
37
|
-
boolean: boolean;
|
|
38
|
-
number: number;
|
|
39
|
-
object: object;
|
|
40
|
-
string: string;
|
|
41
|
-
symbol: symbol;
|
|
42
|
-
undefined: undefined;
|
|
43
|
-
null: null;
|
|
44
|
-
}> | TransformationBranch<keyof {
|
|
45
|
-
bigint: bigint;
|
|
46
|
-
boolean: boolean;
|
|
47
|
-
number: number;
|
|
48
|
-
object: object;
|
|
49
|
-
string: string;
|
|
50
|
-
symbol: symbol;
|
|
51
|
-
undefined: undefined;
|
|
52
|
-
null: null;
|
|
53
|
-
}, Dict> | readonly Branch<keyof {
|
|
54
|
-
bigint: bigint;
|
|
55
|
-
boolean: boolean;
|
|
56
|
-
number: number;
|
|
57
|
-
object: object;
|
|
58
|
-
string: string;
|
|
59
|
-
symbol: symbol;
|
|
60
|
-
undefined: undefined;
|
|
61
|
-
null: null;
|
|
62
|
-
}, Dict>[];
|
|
16
|
+
export declare const predicateUnion: (domain: Domain, l: Predicate, r: Predicate, type: Type) => true | import("./rules/rules.js").NarrowableRules<Dict> | LiteralRules<Domain, unknown> | import("./branch.js").MorphBranch<Domain, Dict> | readonly Branch[];
|
|
63
17
|
export declare const flattenPredicate: (predicate: Predicate, context: FlattenContext) => TraversalEntry[];
|
|
64
18
|
export declare const isLiteralCondition: (predicate: Predicate) => predicate is LiteralRules;
|
|
65
19
|
export type DomainSubtypeResolution<domain extends Domain> = {
|
|
66
20
|
readonly [k in domain]: defined<ResolvedNode[domain]>;
|
|
67
21
|
};
|
|
68
|
-
export declare const resolutionExtendsDomain: <domain extends
|
|
69
|
-
bigint: bigint;
|
|
70
|
-
boolean: boolean;
|
|
71
|
-
number: number;
|
|
72
|
-
object: object;
|
|
73
|
-
string: string;
|
|
74
|
-
symbol: symbol;
|
|
75
|
-
undefined: undefined;
|
|
76
|
-
null: null;
|
|
77
|
-
}>(resolution: ResolvedNode, domain: domain) => resolution is DomainSubtypeResolution<domain>;
|
|
22
|
+
export declare const resolutionExtendsDomain: <domain extends Domain>(resolution: ResolvedNode, domain: domain) => resolution is DomainSubtypeResolution<domain>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { EntryChecker } from "../../traverse/traverse.js";
|
|
1
2
|
import type { constructor } from "../../utils/generics.js";
|
|
2
|
-
export declare const classIntersection: import("../compose.js").Intersector<constructor | undefined>;
|
|
3
|
-
export declare const checkClass:
|
|
3
|
+
export declare const classIntersection: import("../compose.js").Intersector<constructor | "Array" | "Date" | "Error" | "Function" | "Map" | "RegExp" | "Set" | "Object" | "String" | "Number" | "Boolean" | "WeakMap" | "WeakSet" | "Promise" | undefined>;
|
|
4
|
+
export declare const checkClass: EntryChecker<"class">;
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
+
import type { EntryChecker } from "../../traverse/traverse.js";
|
|
1
2
|
export declare const divisorIntersection: import("../compose.js").Intersector<number | undefined>;
|
|
2
|
-
export declare const checkDivisor:
|
|
3
|
+
export declare const checkDivisor: EntryChecker<"divisor">;
|
|
@@ -4,17 +4,25 @@ import type { FlattenAndPushRule } from "./rules.js";
|
|
|
4
4
|
export type PropsRule<$ = Dict> = {
|
|
5
5
|
[propKey in string]: Prop<$>;
|
|
6
6
|
};
|
|
7
|
-
export type Prop<$ = Dict
|
|
8
|
-
export type OptionalProp<$ = Dict
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
readonly TraversalPropEntry[]
|
|
7
|
+
export type Prop<$ = Dict, node extends TypeNode<$> = TypeNode<$>> = node | OptionalProp<$, node> | PrerequisiteProp<$, node>;
|
|
8
|
+
export type OptionalProp<$ = Dict, node extends TypeNode<$> = TypeNode<$>> = [
|
|
9
|
+
"?",
|
|
10
|
+
node
|
|
12
11
|
];
|
|
13
|
-
export type
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
];
|
|
17
|
-
export type
|
|
18
|
-
export
|
|
12
|
+
export type PrerequisiteProp<$ = Dict, node extends TypeNode<$> = TypeNode<$>> = ["!", node];
|
|
13
|
+
export type PropEntry = RequiredPropEntry | OptionalPropEntry | IndexPropEntry | PrerequisitePropEntry;
|
|
14
|
+
export type PrerequisitePropEntry = ["prerequisiteProp", TraversalProp];
|
|
15
|
+
export type RequiredPropEntry = ["requiredProp", TraversalProp];
|
|
16
|
+
export type OptionalPropEntry = ["optionalProp", TraversalProp];
|
|
17
|
+
export type IndexPropEntry = ["indexProp", TraversalNode];
|
|
18
|
+
export type TraversalProp<key extends string = string, node extends TraversalNode = TraversalNode> = [key, node];
|
|
19
|
+
export declare const isOptional: (prop: Prop) => prop is OptionalProp<Dict, TypeNode<Dict>>;
|
|
20
|
+
export declare const isPrerequisite: (prop: Prop) => prop is PrerequisiteProp<Dict, TypeNode<Dict>>;
|
|
21
|
+
export declare const mappedKeys: {
|
|
22
|
+
readonly index: "[index]";
|
|
23
|
+
};
|
|
24
|
+
export type MappedKeys = typeof mappedKeys;
|
|
25
|
+
export type MappedPropKey = MappedKeys[keyof MappedKeys];
|
|
26
|
+
export declare const propToNode: (prop: Prop) => TypeNode<Dict>;
|
|
19
27
|
export declare const propsIntersection: import("../compose.js").Intersector<PropsRule<Dict> | undefined>;
|
|
20
28
|
export declare const flattenProps: FlattenAndPushRule<PropsRule>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Scanner } from "../../parse/string/shift/scanner.js";
|
|
2
|
+
import type { EntryChecker } from "../../traverse/traverse.js";
|
|
2
3
|
import type { evaluate } from "../../utils/generics.js";
|
|
3
4
|
import type { FlattenAndPushRule } from "./rules.js";
|
|
4
5
|
export type Range = DoubleBound | Bound<"==">;
|
|
@@ -29,5 +30,5 @@ export type FlatBound = Bound & {
|
|
|
29
30
|
units?: string;
|
|
30
31
|
};
|
|
31
32
|
export declare const flattenRange: FlattenAndPushRule<Range>;
|
|
32
|
-
export declare const checkBound:
|
|
33
|
-
export declare const compareStrictness: (kind: "min" | "max", l: Bound | undefined, r: Bound | undefined) => "
|
|
33
|
+
export declare const checkBound: EntryChecker<"bound">;
|
|
34
|
+
export declare const compareStrictness: (kind: "min" | "max", l: Bound | undefined, r: Bound | undefined) => "=" | "r" | "l";
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import type { EntryChecker } from "../../traverse/traverse.js";
|
|
1
2
|
import type { CollapsibleList } from "../../utils/generics.js";
|
|
2
3
|
export declare const getRegex: (source: string) => RegExp;
|
|
3
|
-
export declare const checkRegex:
|
|
4
|
+
export declare const checkRegex: EntryChecker<"regex">;
|
|
4
5
|
export declare const regexIntersection: import("../compose.js").Intersector<CollapsibleList<string> | undefined>;
|
|
@@ -1,36 +1,34 @@
|
|
|
1
|
-
import type { Narrow } from "../../parse/
|
|
1
|
+
import type { Narrow } from "../../parse/ast/narrow.js";
|
|
2
2
|
import type { Domain, inferDomain } from "../../utils/domains.js";
|
|
3
3
|
import type { CollapsibleList, constructor, Dict } from "../../utils/generics.js";
|
|
4
|
+
import type { DefaultObjectKind } from "../../utils/objectKinds.js";
|
|
4
5
|
import type { IntersectionState, Intersector } from "../compose.js";
|
|
5
|
-
import type { FlattenContext, TraversalEntry } from "../node.js";
|
|
6
|
-
import type {
|
|
7
|
-
import type { ObjectKindRule, TraversalObjectKindRule } from "./objectKind.js";
|
|
8
|
-
import type { PropsRule, TraversalOptionalProps, TraversalRequiredProps } from "./props.js";
|
|
6
|
+
import type { FlattenContext, TraversalEntry, TraversalKey } from "../node.js";
|
|
7
|
+
import type { PropEntry, PropsRule } from "./props.js";
|
|
9
8
|
import type { FlatBound, Range } from "./range.js";
|
|
10
9
|
export type NarrowableRules<$ = Dict> = {
|
|
11
|
-
readonly objectKind?: ObjectKindRule<$>;
|
|
12
10
|
readonly regex?: CollapsibleList<string>;
|
|
13
11
|
readonly divisor?: number;
|
|
14
12
|
readonly range?: Range;
|
|
15
13
|
readonly props?: PropsRule<$>;
|
|
16
|
-
readonly class?: constructor;
|
|
14
|
+
readonly class?: DefaultObjectKind | constructor;
|
|
17
15
|
readonly narrow?: NarrowRule;
|
|
18
16
|
};
|
|
19
|
-
export type LiteralRules<domain extends Domain = Domain> = {
|
|
20
|
-
readonly value:
|
|
17
|
+
export type LiteralRules<domain extends Domain = Domain, value extends inferDomain<domain> = inferDomain<domain>> = {
|
|
18
|
+
readonly value: value;
|
|
21
19
|
};
|
|
22
20
|
export type NarrowRule = CollapsibleList<Narrow>;
|
|
23
21
|
export type FlatRules = RuleEntry[];
|
|
24
|
-
export type RuleEntry = ["
|
|
25
|
-
export type Rules<domain extends Domain = Domain, $ = Dict> = Domain extends domain ? NarrowableRules | LiteralRules : domain extends "object" ? defineRuleSet<domain, "
|
|
22
|
+
export type RuleEntry = ["regex", string] | ["divisor", number] | ["bound", FlatBound] | ["class", DefaultObjectKind | constructor] | PropEntry | ["narrow", Narrow] | ["value", unknown];
|
|
23
|
+
export type Rules<domain extends Domain = Domain, $ = Dict> = Domain extends domain ? NarrowableRules | LiteralRules : domain extends "object" ? defineRuleSet<domain, "props" | "range" | "narrow" | "class", $> : domain extends "string" ? defineRuleSet<domain, "regex" | "range" | "narrow", $> : domain extends "number" ? defineRuleSet<domain, "divisor" | "range" | "narrow", $> : defineRuleSet<domain, "narrow", $>;
|
|
26
24
|
type defineRuleSet<domain extends Domain, keys extends keyof NarrowableRules, $> = Pick<NarrowableRules<$>, keys> | LiteralRules<domain>;
|
|
27
|
-
export declare const branchIntersection: Intersector<Branch>;
|
|
28
25
|
export declare const rulesIntersection: Intersector<Rules>;
|
|
29
26
|
export declare const narrowableRulesIntersection: Intersector<NarrowableRules<Dict>>;
|
|
27
|
+
export declare const flattenRules: (rules: UnknownRules, ctx: FlattenContext) => TraversalEntry[];
|
|
30
28
|
export type FlattenAndPushRule<t> = (entries: RuleEntry[], rule: t, ctx: FlattenContext) => void;
|
|
29
|
+
type UnknownRules = NarrowableRules & Partial<LiteralRules>;
|
|
31
30
|
export declare const precedenceMap: {
|
|
32
|
-
readonly [k in
|
|
31
|
+
readonly [k in TraversalKey]: number;
|
|
33
32
|
};
|
|
34
|
-
export declare const flattenBranch: (branch: Branch, ctx: FlattenContext) => FlatBranch;
|
|
35
33
|
export declare const literalSatisfiesRules: (data: unknown, rules: NarrowableRules, state: IntersectionState) => boolean;
|
|
36
34
|
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { resolve } from "../../scopes/scope.js";
|
|
2
|
+
import type { castOnError, error, List, RegexLiteral, tryCatch } from "../../utils/generics.js";
|
|
3
|
+
import type { BigintLiteral, NumberLiteral } from "../../utils/numericLiterals.js";
|
|
4
|
+
import type { StringLiteral } from "../string/shift/operand/enclosed.js";
|
|
5
|
+
import type { Scanner } from "../string/shift/scanner.js";
|
|
6
|
+
import type { parseString } from "../string/string.js";
|
|
7
|
+
import type { validateBound } from "./bound.js";
|
|
8
|
+
import type { validateDivisor } from "./divisor.js";
|
|
9
|
+
import type { inferIntersection } from "./intersection.js";
|
|
10
|
+
import type { inferUnion } from "./union.js";
|
|
11
|
+
export type inferAst<ast, $> = ast extends List ? inferExpression<ast, $> : inferTerminal<ast, $>;
|
|
12
|
+
export type inferExpression<ast extends List, $> = ast[1] extends "[]" ? inferAst<ast[0], $>[] : ast[1] extends "|" ? inferUnion<inferAst<ast[0], $>, inferAst<ast[2], $>> extends infer result ? castOnError<result, never> : never : ast[1] extends "&" ? inferIntersection<inferAst<ast[0], $>, inferAst<ast[2], $>> extends infer result ? castOnError<result, never> : never : ast[1] extends Scanner.Comparator ? ast[0] extends NumberLiteral ? inferAst<ast[2], $> : inferAst<ast[0], $> : ast[1] extends "%" ? inferAst<ast[0], $> : never;
|
|
13
|
+
export type validateAst<ast, $> = ast extends List ? validateExpression<ast, $> : ast;
|
|
14
|
+
export type validateExpression<ast extends List, $> = ast extends PostfixExpression<infer operator, infer operand> ? operator extends "[]" ? validateAst<operand, $> : never : ast extends InfixExpression<infer operator, infer l, infer r> ? operator extends "&" ? tryCatch<inferIntersection<inferAst<l, $>, inferAst<r, $>>, validateInfix<ast, $>> : operator extends "|" ? tryCatch<inferUnion<inferAst<l, $>, inferAst<r, $>>, validateInfix<ast, $>> : operator extends Scanner.Comparator ? validateBound<l, r, $> : operator extends "%" ? validateDivisor<l, $> : never : undefined;
|
|
15
|
+
export type validateString<def extends string, $> = parseString<def, $> extends infer ast ? ast extends error<infer message> ? message : validateAst<ast, $> extends error<infer message> ? message : def : never;
|
|
16
|
+
export type PrefixOperator = "keyof" | "instanceof" | "===" | "node";
|
|
17
|
+
export type PrefixExpression<operator extends PrefixOperator = PrefixOperator, operand = unknown> = [operator, operand];
|
|
18
|
+
export type PostfixOperator = "[]";
|
|
19
|
+
export type PostfixExpression<operator extends PostfixOperator = PostfixOperator, operand = unknown> = [operand, operator];
|
|
20
|
+
export type InfixOperator = "|" | "&" | Scanner.Comparator | "%" | ":" | "=>";
|
|
21
|
+
export type InfixExpression<operator extends InfixOperator = InfixOperator, l = unknown, r = unknown> = [l, operator, r];
|
|
22
|
+
type validateInfix<ast extends InfixExpression, $> = tryCatch<validateAst<ast[0], $>, tryCatch<validateAst<ast[2], $>, ast>>;
|
|
23
|
+
export type inferTerminal<token, $> = token extends keyof $ ? resolve<token, $> : token extends StringLiteral<infer Text> ? Text : token extends RegexLiteral ? string : token extends NumberLiteral<infer value> ? value : token extends BigintLiteral<infer value> ? value : never;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { SizedData } from "../../utils/data.js";
|
|
2
|
+
import type { error, isAny } from "../../utils/generics.js";
|
|
3
|
+
import type { NumberLiteral } from "../../utils/numericLiterals.js";
|
|
4
|
+
import type { inferAst, validateAst } from "./ast.js";
|
|
5
|
+
import type { astToString } from "./utils.js";
|
|
6
|
+
export type validateBound<l, r, $> = l extends NumberLiteral ? validateAst<r, $> : isBoundable<inferAst<l, $>> extends true ? validateAst<l, $> : error<writeUnboundableMessage<astToString<l>>>;
|
|
7
|
+
type isBoundable<data> = isAny<data> extends true ? false : [data] extends [SizedData] ? true : false;
|
|
8
|
+
export declare const writeUnboundableMessage: <root extends string>(root: root) => `Bounded expression ${root} must be a number, string or array`;
|
|
9
|
+
type writeUnboundableMessage<root extends string> = `Bounded expression ${root} must be a number, string or array`;
|
|
10
|
+
export {};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { TypeNode } from "../../nodes/node.js";
|
|
2
2
|
import type { NarrowableRules } from "../../nodes/rules/rules.js";
|
|
3
3
|
import type { Domain, domainOf, inferDomain } from "../../utils/domains.js";
|
|
4
|
-
import type {
|
|
4
|
+
import type { evaluate } from "../../utils/generics.js";
|
|
5
5
|
import type { ParseContext } from "../definition.js";
|
|
6
6
|
export type DistributableFunction<input = any, args extends any[] = any[], output = unknown> = (input: input, ...args: args) => output;
|
|
7
7
|
export type distributable<f extends DistributableFunction> = f | distributeFunction<f>;
|
|
8
|
-
type distributeFunction<f extends DistributableFunction> = f extends DistributableFunction<infer input, infer args, infer output> ?
|
|
8
|
+
export type distributeFunction<f extends DistributableFunction> = f extends DistributableFunction<infer input, infer args, infer output> ? evaluate<{
|
|
9
9
|
[domain in domainOf<input>]?: (input: unknown extends input ? unknown : Extract<input, inferDomain<domain>>, ...args: args) => output;
|
|
10
10
|
}> : never;
|
|
11
11
|
export declare const writeMalformedDistributableFunctionMessage: (def: unknown) => string;
|
|
@@ -16,4 +16,3 @@ export type FunctionInDomain<f, ruleKey extends keyof NarrowableRules> = {
|
|
|
16
16
|
[k in ruleKey]: f;
|
|
17
17
|
};
|
|
18
18
|
export declare const distributeFunctionToNode: <f extends DistributableFunction<any, any[], unknown>, ruleKey extends keyof NarrowableRules>(distributableFunction: distributable<f>, inputNode: TypeNode, ctx: ParseContext, ruleKey: ruleKey) => DistributedFunctionNode<f, ruleKey>;
|
|
19
|
-
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { error, isAny } from "../../utils/generics";
|
|
2
|
+
import type { inferAst, validateAst } from "./ast";
|
|
3
|
+
import type { astToString } from "./utils";
|
|
4
|
+
export type validateDivisor<l, $> = isDivisible<inferAst<l, $>> extends true ? validateAst<l, $> : error<writeIndivisibleMessage<astToString<l>>>;
|
|
5
|
+
type isDivisible<data> = isAny<data> extends true ? false : [data] extends [number] ? true : false;
|
|
6
|
+
export declare const writeIndivisibleMessage: <root extends string>(root: root) => `Divisibility operand ${root} must be a number`;
|
|
7
|
+
type writeIndivisibleMessage<root extends string> = `Divisibility operand ${root} must be a number`;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { DisjointsByPath } from "../../nodes/compose.js";
|
|
2
|
+
import type { MappedKeys } from "../../nodes/rules/props.js";
|
|
3
|
+
import type { asConst, Dict, error, evaluate, extractValues, isAny, List, stringKeyOf, tryCatch } from "../../utils/generics.js";
|
|
4
|
+
import type { Path, pathToString } from "../../utils/paths.js";
|
|
5
|
+
import type { Out, ParsedMorph } from "./morph.js";
|
|
6
|
+
export type inferIntersection<l, r> = inferIntersectionRecurse<l, r, []>;
|
|
7
|
+
type inferIntersectionRecurse<l, r, path extends string[]> = path["length"] extends 10 ? l & r : l extends never ? never : r extends never ? never : l & r extends never ? error<writeImplicitNeverMessage<path, "Intersection">> : isAny<l | r> extends true ? any : l extends ParsedMorph<infer lIn, infer lOut> ? r extends ParsedMorph ? error<writeImplicitNeverMessage<path, "Intersection", "of morphs">> : (In: evaluate<lIn & r>) => Out<lOut> : r extends ParsedMorph<infer rIn, infer rOut> ? (In: evaluate<rIn & l>) => Out<rOut> : [l, r] extends [Dict, Dict] ? bubblePropErrors<evaluate<{
|
|
8
|
+
[k in stringKeyOf<l>]: k extends keyof r ? inferIntersectionRecurse<l[k], r[k], [...path, k]> : l[k];
|
|
9
|
+
} & Omit<r, keyof l>>> : [l, r] extends [List<infer lItem>, List<infer rItem>] ? inferIntersectionRecurse<lItem, rItem, [
|
|
10
|
+
...path,
|
|
11
|
+
MappedKeys["index"]
|
|
12
|
+
]> extends infer result ? tryCatch<result, result[]> : never : l & r;
|
|
13
|
+
type bubblePropErrors<o> = extractValues<o, error> extends never ? o : extractValues<o, error>;
|
|
14
|
+
export declare const compileDisjointReasonsMessage: (disjoints: DisjointsByPath) => string;
|
|
15
|
+
export declare const writeImplicitNeverMessage: <path extends [] | Path, operator extends "keyof" | "Intersection", description extends string = "">(path: asConst<path>, operator: operator, description?: description | undefined) => `${path extends [] ? "" : `At ${pathToString<path, "/">}: `}${operator} ${description extends "" ? "" : `${description} `}results in an unsatisfiable type`;
|
|
16
|
+
export type writeImplicitNeverMessage<path extends string[], operator extends "Intersection" | "keyof", description extends string = ""> = `${path extends [] ? "" : `At ${pathToString<path>}: `}${operator} ${description extends "" ? "" : `${description} `}results in an unsatisfiable type`;
|
|
17
|
+
export {};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { evaluate } from "../../utils/generics.js";
|
|
2
2
|
import type { inferDefinition, validateDefinition } from "../definition.js";
|
|
3
|
-
import { writeImplicitNeverMessage } from "
|
|
3
|
+
import { writeImplicitNeverMessage } from "./intersection.js";
|
|
4
4
|
import type { PrefixParser } from "./tuple.js";
|
|
5
5
|
export declare const parseKeyOfTuple: PrefixParser<"keyof">;
|
|
6
|
-
export type inferKeyOfExpression<operandDef, $> =
|
|
7
|
-
export type validateKeyOfExpression<operandDef, $> = [
|
|
6
|
+
export type inferKeyOfExpression<operandDef, $> = evaluate<keyof inferDefinition<operandDef, $>>;
|
|
7
|
+
export type validateKeyOfExpression<operandDef, $> = readonly [
|
|
8
8
|
"keyof",
|
|
9
9
|
inferKeyOfExpression<operandDef, $> extends never ? writeImplicitNeverMessage<[], "keyof"> : validateDefinition<operandDef, $>
|
|
10
10
|
];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { asOut } from "../../scopes/type.js";
|
|
1
|
+
import type { asIn, asOut } from "../../scopes/type.js";
|
|
2
2
|
import type { nominal } from "../../utils/generics.js";
|
|
3
3
|
import type { inferDefinition, validateDefinition } from "../definition.js";
|
|
4
4
|
import type { PostfixParser, TupleExpression } from "./tuple.js";
|
|
@@ -7,9 +7,9 @@ export type Out<t = {}> = nominal<t, "out">;
|
|
|
7
7
|
export type validateMorphTuple<def extends TupleExpression, $> = readonly [
|
|
8
8
|
_: validateDefinition<def[0], $>,
|
|
9
9
|
_: "=>",
|
|
10
|
-
_: Morph<asOut<inferDefinition<def[0], $>>,
|
|
11
|
-
_?: validateDefinition<def[3], $>
|
|
10
|
+
_: Morph<asOut<inferDefinition<def[0], $>>, unknown>
|
|
12
11
|
];
|
|
13
12
|
export type Morph<i = any, o = unknown> = (In: i) => o;
|
|
14
13
|
export type ParsedMorph<i = any, o = unknown> = (In: i) => Out<o>;
|
|
14
|
+
export type inferMorph<inDef, morph, $> = morph extends Morph ? (In: asIn<inferDefinition<inDef, $>>) => Out<ReturnType<morph>> : never;
|
|
15
15
|
export declare const writeMalformedMorphExpressionMessage: (value: unknown) => string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { asIn } from "../../scopes/type.js";
|
|
2
|
+
import type { Problems } from "../../traverse/problems.js";
|
|
3
|
+
import type { Domain, inferDomain } from "../../utils/domains.js";
|
|
4
|
+
import type { inferDefinition, validateDefinition } from "../definition.js";
|
|
5
|
+
import type { distributable } from "./distributableFunction.js";
|
|
6
|
+
import type { PostfixParser, TupleExpression } from "./tuple.js";
|
|
7
|
+
export declare const parseNarrowTuple: PostfixParser<":">;
|
|
8
|
+
export type Narrow<data = any> = (data: data, problems: Problems) => boolean;
|
|
9
|
+
export type NarrowCast<data = any, to extends data = data> = (data: data, problems: Problems) => data is to;
|
|
10
|
+
export type validateNarrowTuple<def extends TupleExpression, $> = readonly [
|
|
11
|
+
_: validateDefinition<def[0], $>,
|
|
12
|
+
_: ":",
|
|
13
|
+
_: distributable<Narrow<asIn<inferDefinition<def[0], $>>>>
|
|
14
|
+
];
|
|
15
|
+
export type inferNarrow<inDef, narrow, $> = narrow extends Narrow ? inferNarrowFunction<inferDefinition<inDef, $>, narrow> : narrow extends {
|
|
16
|
+
[domain in Domain]?: Narrow;
|
|
17
|
+
} ? {
|
|
18
|
+
[domain in keyof narrow & Domain]: inferNarrowFunction<Extract<inferDefinition<inDef, $>, inferDomain<domain>>, narrow[domain]>;
|
|
19
|
+
}[keyof narrow & Domain] : never;
|
|
20
|
+
type inferNarrowFunction<input, narrow> = narrow extends NarrowCast<input, infer to> ? to : narrow extends Narrow<input> ? input : never;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { inferNode } from "../../nodes/infer.js";
|
|
2
|
+
import type { ResolvedNode, TypeNode } from "../../nodes/node.js";
|
|
3
|
+
import type { conform, constructor, Dict, error, evaluate, List } from "../../utils/generics.js";
|
|
4
|
+
import type { inferDefinition, ParseContext, validateDefinition } from "../definition.js";
|
|
5
|
+
import { writeMissingRightOperandMessage } from "../string/shift/operand/unenclosed.js";
|
|
6
|
+
import type { Scanner } from "../string/shift/scanner.js";
|
|
7
|
+
import type { inferIntersection } from "./intersection.js";
|
|
8
|
+
import type { inferKeyOfExpression, validateKeyOfExpression } from "./keyof.js";
|
|
9
|
+
import type { inferMorph, validateMorphTuple } from "./morph.js";
|
|
10
|
+
import type { inferNarrow, validateNarrowTuple } from "./narrow.js";
|
|
11
|
+
import type { inferUnion } from "./union.js";
|
|
12
|
+
export declare const parseTuple: (def: List, ctx: ParseContext) => TypeNode;
|
|
13
|
+
export type validateTupleExpression<def extends TupleExpression, $> = def[1] extends "[]" ? conform<def, readonly [validateDefinition<def[0], $>, "[]"]> : def[1] extends Scanner.BranchToken ? def[2] extends undefined ? [def[0], error<writeMissingRightOperandMessage<def[1], "">>] : conform<def, readonly [
|
|
14
|
+
validateDefinition<def[0], $>,
|
|
15
|
+
def[1],
|
|
16
|
+
validateDefinition<def[2], $>
|
|
17
|
+
]> : def[1] extends "=>" ? validateMorphTuple<def, $> : def[1] extends ":" ? validateNarrowTuple<def, $> : def[0] extends "===" ? conform<def, readonly ["===", unknown]> : def[0] extends "instanceof" ? conform<def, readonly ["instanceof", constructor]> : def[0] extends "node" ? conform<def, readonly ["node", ResolvedNode<$>]> : def[0] extends "keyof" ? conform<def, validateKeyOfExpression<def[1], $>> : never;
|
|
18
|
+
export type UnparsedTupleExpressionInput<$> = {
|
|
19
|
+
instanceof: constructor;
|
|
20
|
+
node: ResolvedNode<$>;
|
|
21
|
+
"===": unknown;
|
|
22
|
+
};
|
|
23
|
+
export type UnparsedTupleOperator = evaluate<keyof UnparsedTupleExpressionInput<Dict>>;
|
|
24
|
+
export type inferTuple<def extends List, $> = def extends TupleExpression ? inferTupleExpression<def, $> : {
|
|
25
|
+
[i in keyof def]: inferDefinition<def[i], $>;
|
|
26
|
+
};
|
|
27
|
+
export type inferTupleExpression<def extends TupleExpression, $> = def[1] extends "[]" ? inferDefinition<def[0], $>[] : def[1] extends "&" ? inferIntersection<inferDefinition<def[0], $>, inferDefinition<def[2], $>> : def[1] extends "|" ? inferUnion<inferDefinition<def[0], $>, inferDefinition<def[2], $>> : def[1] extends ":" ? inferNarrow<def[0], def[2], $> : def[1] extends "=>" ? inferMorph<def[0], def[2], $> : def[0] extends "===" ? def[1] : def[0] extends "instanceof" ? def[1] extends constructor<infer t> ? t : never : def[0] extends "node" ? def[1] extends ResolvedNode<$> ? inferNode<def[1], $> : never : def[0] extends "keyof" ? inferKeyOfExpression<def[1], $> : never;
|
|
28
|
+
export type PostfixParser<token extends IndexOneOperator> = (def: IndexOneExpression<token>, ctx: ParseContext) => TypeNode;
|
|
29
|
+
export type PrefixParser<token extends IndexZeroOperator> = (def: IndexZeroExpression<token>, ctx: ParseContext) => TypeNode;
|
|
30
|
+
export type TupleExpression = IndexZeroExpression | IndexOneExpression;
|
|
31
|
+
export declare const writeMalformedFunctionalExpressionMessage: (operator: "=>" | ":", rightDef: unknown) => string;
|
|
32
|
+
export type TupleExpressionOperator = IndexZeroOperator | IndexOneOperator;
|
|
33
|
+
type IndexOneOperator = TuplePostfixOperator | TupleInfixOperator;
|
|
34
|
+
export type TuplePostfixOperator = "[]";
|
|
35
|
+
export type TupleInfixOperator = "&" | "|" | ":" | "=>";
|
|
36
|
+
export type IndexOneExpression<token extends IndexOneOperator = IndexOneOperator> = readonly [unknown, token, ...unknown[]];
|
|
37
|
+
export type FunctionalTupleOperator = ":" | "=>";
|
|
38
|
+
export type IndexZeroOperator = "keyof" | "instanceof" | "===" | "node";
|
|
39
|
+
export type IndexZeroExpression<token extends IndexZeroOperator = IndexZeroOperator> = readonly [token, ...unknown[]];
|
|
40
|
+
export {};
|