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
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import { throwInternalError } from "../../utils/errors.js";
|
|
2
|
-
import { composeIntersection, equality, isDisjoint, isEquality } from "../compose.js";
|
|
3
|
-
import { flattenNode, nodeIntersection } from "../node.js";
|
|
4
|
-
export const objectKindIntersection = composeIntersection((l, r, state)=>{
|
|
5
|
-
if (typeof l === "string") {
|
|
6
|
-
if (typeof r === "string") {
|
|
7
|
-
return l === r ? equality() : state.addDisjoint("objectKind", l, r);
|
|
8
|
-
}
|
|
9
|
-
return l === r[0] ? r : state.addDisjoint("objectKind", l, r[0]);
|
|
10
|
-
}
|
|
11
|
-
if (typeof r === "string") {
|
|
12
|
-
return l[0] === r ? l : state.addDisjoint("objectKind", l[0], r);
|
|
13
|
-
}
|
|
14
|
-
if (l[0] !== r[0]) {
|
|
15
|
-
return state.addDisjoint("objectKind", l[0], r[0]);
|
|
16
|
-
}
|
|
17
|
-
const result = [
|
|
18
|
-
l[0]
|
|
19
|
-
];
|
|
20
|
-
let lImpliesR = true;
|
|
21
|
-
let rImpliesL = true;
|
|
22
|
-
for(let i = 1; i < l.length; i++){
|
|
23
|
-
const lNode = l[i];
|
|
24
|
-
const rNode = r[i];
|
|
25
|
-
state.path.push(objectKindParameterToPathSegment(l[0], i));
|
|
26
|
-
const parameterResult = nodeIntersection(lNode, rNode, state);
|
|
27
|
-
state.path.pop();
|
|
28
|
-
if (isEquality(parameterResult)) {
|
|
29
|
-
result[i] = lNode;
|
|
30
|
-
} else if (parameterResult === l) {
|
|
31
|
-
result[i] = lNode;
|
|
32
|
-
rImpliesL = false;
|
|
33
|
-
} else if (parameterResult === r) {
|
|
34
|
-
result[i] = rNode;
|
|
35
|
-
lImpliesR = false;
|
|
36
|
-
} else if (isDisjoint(parameterResult)) {
|
|
37
|
-
return parameterResult;
|
|
38
|
-
} else {
|
|
39
|
-
result[i] = parameterResult;
|
|
40
|
-
lImpliesR = false;
|
|
41
|
-
rImpliesL = false;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
return lImpliesR ? rImpliesL ? equality() : l : rImpliesL ? r : result;
|
|
45
|
-
});
|
|
46
|
-
const objectKindParameterToPathSegment = (objectKind, i)=>objectKind === "Array" ? "${number}" : objectKind === "Set" ? "${item}" : objectKind === "Map" ? i === 1 ? "${key}" : "${value}" : throwInternalError(`Unexpected parameterized objectKind '${objectKind}'`);
|
|
47
|
-
export const objectKindPathSegments = {
|
|
48
|
-
"${number}": true,
|
|
49
|
-
"${item}": true,
|
|
50
|
-
"${key}": true,
|
|
51
|
-
"${value}": true
|
|
52
|
-
};
|
|
53
|
-
export const flattenObjectKind = (entries, rule, ctx)=>entries.push([
|
|
54
|
-
"objectKind",
|
|
55
|
-
typeof rule === "string" ? rule : rule[0] === "Map" ? [
|
|
56
|
-
rule[0],
|
|
57
|
-
flattenNode(rule[1], ctx),
|
|
58
|
-
flattenNode(rule[2], ctx)
|
|
59
|
-
] : [
|
|
60
|
-
rule[0],
|
|
61
|
-
flattenNode(rule[1], ctx)
|
|
62
|
-
]
|
|
63
|
-
]);
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { resolutionExtendsDomain } from "../../nodes/predicate.js";
|
|
2
|
-
import { throwParseError } from "../../utils/errors.js";
|
|
3
|
-
import { hasKey, listFrom } from "../../utils/generics.js";
|
|
4
|
-
import { parseDefinition } from "../definition.js";
|
|
5
|
-
import { writeImplicitNeverMessage } from "../string/ast.js";
|
|
6
|
-
export const parseKeyOfTuple = (def, ctx)=>{
|
|
7
|
-
const resolution = ctx.type.meta.scope.resolveNode(parseDefinition(def[1], ctx));
|
|
8
|
-
if (!resolutionExtendsDomain(resolution, "object")) {
|
|
9
|
-
return throwParseError(writeImplicitNeverMessage(ctx.path, "keyof"));
|
|
10
|
-
}
|
|
11
|
-
if (resolution.object === true) {
|
|
12
|
-
return writeImplicitNeverMessage(ctx.path, "keyof");
|
|
13
|
-
}
|
|
14
|
-
const branchKeys = [];
|
|
15
|
-
const objectBranches = listFrom(resolution.object);
|
|
16
|
-
const initialKeys = getPropsFromBranch(objectBranches[0]);
|
|
17
|
-
for(let i = 1; i < objectBranches.length; i++){
|
|
18
|
-
const keys = getPropsFromBranch(objectBranches[i]);
|
|
19
|
-
if (!keys.length) {
|
|
20
|
-
return writeImplicitNeverMessage(ctx.path, "keyof");
|
|
21
|
-
}
|
|
22
|
-
branchKeys.push(keys);
|
|
23
|
-
}
|
|
24
|
-
const result = [];
|
|
25
|
-
initialKeys.forEach((key)=>{
|
|
26
|
-
const hasKey = branchKeys.every((keySet)=>keySet.includes(key));
|
|
27
|
-
if (hasKey) {
|
|
28
|
-
result.push({
|
|
29
|
-
value: key
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
return result.length ? {
|
|
34
|
-
string: result
|
|
35
|
-
} : writeImplicitNeverMessage(ctx.path, "keyof");
|
|
36
|
-
};
|
|
37
|
-
const getPropsFromBranch = (branch)=>hasKey(branch, "props") ? Object.keys(branch.props) : [];
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { intersection } from "../../nodes/node.js";
|
|
2
|
-
import { parseDefinition } from "../definition.js";
|
|
3
|
-
import { distributeFunctionToNode } from "./utils.js";
|
|
4
|
-
export const parseNarrowTuple = (def, ctx)=>{
|
|
5
|
-
const inputNode = parseDefinition(def[0], ctx);
|
|
6
|
-
return intersection(inputNode, distributeFunctionToNode(def[2], inputNode, ctx, "narrow"), ctx.type);
|
|
7
|
-
};
|
package/dist/mjs/utils/size.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { List } from "../utils/generics.js";
|
|
2
|
-
import type { IntersectionState } from "./compose.js";
|
|
3
|
-
import type { Branch, PredicateComparison } from "./predicate.js";
|
|
4
|
-
export declare const isBranchComparison: (comparison: PredicateComparison) => comparison is BranchesComparison;
|
|
5
|
-
export type Branches = List<Branch>;
|
|
6
|
-
export type BranchesComparison = {
|
|
7
|
-
lBranches: Branches;
|
|
8
|
-
rBranches: Branches;
|
|
9
|
-
lExtendsR: number[];
|
|
10
|
-
rExtendsL: number[];
|
|
11
|
-
equalities: [lIndex: number, rIndex: number][];
|
|
12
|
-
distinctIntersections: Branches;
|
|
13
|
-
};
|
|
14
|
-
export declare const compareBranches: (lConditions: Branches, rConditions: Branches, state: IntersectionState) => BranchesComparison;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Dict } from "../../utils/generics.js";
|
|
2
|
-
import type { DefaultObjectKind } from "../../utils/objectKinds.js";
|
|
3
|
-
import type { TraversalNode, TypeNode } from "../node.js";
|
|
4
|
-
import type { FlattenAndPushRule } from "./rules.js";
|
|
5
|
-
export type ObjectKindRule<$ = Dict> = DefaultObjectKind | readonly ["Array", TypeNode<$>] | readonly ["Array", TypeNode<$>] | readonly ["Set", TypeNode<$>] | readonly ["Map", TypeNode<$>, TypeNode<$>];
|
|
6
|
-
export type TraversalObjectKindRule = DefaultObjectKind | readonly ["Array", TraversalNode] | readonly ["Array", TraversalNode] | readonly ["Set", TraversalNode] | readonly ["Map", TraversalNode, TraversalNode];
|
|
7
|
-
export declare const objectKindIntersection: import("../compose.js").Intersector<ObjectKindRule<Dict> | undefined>;
|
|
8
|
-
export declare const objectKindPathSegments: {
|
|
9
|
-
readonly "${number}": true;
|
|
10
|
-
readonly "${item}": true;
|
|
11
|
-
readonly "${key}": true;
|
|
12
|
-
readonly "${value}": true;
|
|
13
|
-
};
|
|
14
|
-
export type ObjectKindPathSegment = keyof typeof objectKindPathSegments;
|
|
15
|
-
export declare const flattenObjectKind: FlattenAndPushRule<ObjectKindRule>;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import type { DisjointsByPath } from "../../nodes/compose.js";
|
|
2
|
-
import type { resolve } from "../../scopes/scope.js";
|
|
3
|
-
import type { asIn } from "../../scopes/type.js";
|
|
4
|
-
import type { domainOf } from "../../utils/domains.js";
|
|
5
|
-
import type { asConst, castOnError, Dict, equals, error, evaluate, evaluateObject, extractValues, isAny, List, Literalable, RegexLiteral, requiredKeyOf, stringKeyOf, tryCatch } from "../../utils/generics.js";
|
|
6
|
-
import type { objectKindOf } from "../../utils/objectKinds.js";
|
|
7
|
-
import type { Path, pathToString } from "../../utils/paths.js";
|
|
8
|
-
import type { SizedData } from "../../utils/size.js";
|
|
9
|
-
import type { Out, ParsedMorph } from "../tuple/morph.js";
|
|
10
|
-
import type { StringLiteral } from "./shift/operand/enclosed.js";
|
|
11
|
-
import type { Scanner } from "./shift/scanner.js";
|
|
12
|
-
export type inferAst<ast, $> = 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 number ? inferAst<ast[2], $> : inferAst<ast[0], $> : ast[1] extends "%" ? inferAst<ast[0], $> : never : inferTerminal<ast, $>;
|
|
13
|
-
export type validateAstSemantics<ast, $> = ast extends string ? undefined : ast extends [infer child, unknown] ? validateAstSemantics<child, $> : ast extends [infer l, infer token, infer r] ? token extends "&" ? tryCatch<inferIntersection<inferAst<l, $>, inferAst<r, $>>, validateBinary<l, r, $>> : token extends "|" ? tryCatch<inferUnion<inferAst<l, $>, inferAst<r, $>>, validateBinary<l, r, $>> : token extends Scanner.Comparator ? l extends number ? validateAstSemantics<r, $> : isBoundable<inferAst<l, $>> extends true ? validateAstSemantics<l, $> : error<writeUnboundableMessage<astToString<ast[0]>>> : token extends "%" ? isDivisible<inferAst<l, $>> extends true ? validateAstSemantics<l, $> : error<writeIndivisibleMessage<astToString<ast[0]>>> : validateAstSemantics<l, $> : undefined;
|
|
14
|
-
type validateBinary<l, r, $> = tryCatch<validateAstSemantics<l, $>, tryCatch<validateAstSemantics<r, $>, undefined>>;
|
|
15
|
-
export type inferIntersection<l, r> = inferIntersectionRecurse<l, r, []>;
|
|
16
|
-
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<evaluateObject<{
|
|
17
|
-
[k in stringKeyOf<l>]: k extends keyof r ? inferIntersectionRecurse<l[k], r[k], [...path, k]> : l[k];
|
|
18
|
-
} & Omit<r, keyof l>>> : [l, r] extends [List<infer lItem>, List<infer rItem>] ? inferIntersectionRecurse<lItem, rItem, [
|
|
19
|
-
...path,
|
|
20
|
-
"${number}"
|
|
21
|
-
]> extends infer result ? tryCatch<result, result[]> : never : l & r;
|
|
22
|
-
type bubblePropErrors<o> = extractValues<o, error> extends never ? o : extractValues<o, error>;
|
|
23
|
-
export type inferUnion<l, r> = isAny<l | r> extends true ? any : [l] extends [never] ? r : [r] extends [never] ? l : [asIn<l>, asIn<r>] extends [infer lIn, infer rIn] ? [equals<l, lIn>, equals<r, rIn>] extends [true, true] ? l | r : discriminatable<lIn, rIn> extends true ? l | r : error<undiscriminatableMorphUnionMessage> : never;
|
|
24
|
-
type discriminatable<l, r> = discriminatableRecurse<l, r, []> extends never ? false : true;
|
|
25
|
-
type discriminatableRecurse<l, r, path extends string[]> = path["length"] extends 10 ? never : l & r extends never ? path : domainOf<l> & domainOf<r> extends never ? path : objectKindOf<l> & objectKindOf<r> extends never ? path : [objectKindOf<l>, objectKindOf<r>] extends ["Object", "Object"] ? extractValues<{
|
|
26
|
-
[k in requiredKeyOf<l>]: k extends requiredKeyOf<r> ? discriminatableRecurse<l[k], r[k], [...path, k & string]> : never;
|
|
27
|
-
}, string[]> : never;
|
|
28
|
-
export declare const compileDisjointReasonsMessage: (disjoints: DisjointsByPath) => string;
|
|
29
|
-
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`;
|
|
30
|
-
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`;
|
|
31
|
-
export declare const writeUndiscriminatableMorphUnionMessage: <path extends string>(path: path) => string;
|
|
32
|
-
type undiscriminatableMorphUnionMessage = `A union including one or more morphs must be discriminatable`;
|
|
33
|
-
type isDivisible<data> = isAny<data> extends true ? false : [data] extends [number] ? true : false;
|
|
34
|
-
type isBoundable<data> = isAny<data> extends true ? false : [data] extends [SizedData] ? true : false;
|
|
35
|
-
export type inferTerminal<token, $> = token extends keyof $ ? resolve<token, $> : token extends StringLiteral<infer Text> ? Text : token extends RegexLiteral ? string : token extends number | bigint ? token : never;
|
|
36
|
-
export type astToString<ast> = `'${astToStringRecurse<ast, "">}'`;
|
|
37
|
-
type astToStringRecurse<ast, result extends string> = ast extends [
|
|
38
|
-
infer head,
|
|
39
|
-
...infer tail
|
|
40
|
-
] ? astToStringRecurse<tail, `${result}${astToStringRecurse<head, "">}`> : ast extends Literalable ? `${result}${ast extends bigint ? `${ast}n` : ast}` : "...";
|
|
41
|
-
export declare const writeIndivisibleMessage: <root extends string>(root: root) => `Divisibility operand ${root} must be a number`;
|
|
42
|
-
type writeIndivisibleMessage<root extends string> = `Divisibility operand ${root} must be a number`;
|
|
43
|
-
export declare const writeUnboundableMessage: <root extends string>(root: root) => `Bounded expression ${root} must be a number, string or array`;
|
|
44
|
-
type writeUnboundableMessage<root extends string> = `Bounded expression ${root} must be a number, string or array`;
|
|
45
|
-
export {};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { asIn } from "../../scopes/type.js";
|
|
2
|
-
import type { Problems } from "../../traverse/problems.js";
|
|
3
|
-
import type { inferDefinition, validateDefinition } from "../definition.js";
|
|
4
|
-
import type { PostfixParser, TupleExpression } from "./tuple.js";
|
|
5
|
-
import type { distributable } from "./utils.js";
|
|
6
|
-
export declare const parseNarrowTuple: PostfixParser<":">;
|
|
7
|
-
export type Narrow<data = any> = (data: data, problems: Problems) => boolean;
|
|
8
|
-
export type validateNarrowTuple<def extends TupleExpression, $> = readonly [
|
|
9
|
-
_: validateDefinition<def[0], $>,
|
|
10
|
-
_: ":",
|
|
11
|
-
_: distributable<Narrow<asIn<inferDefinition<def[0], $>>>>,
|
|
12
|
-
_?: validateDefinition<def[3], $>
|
|
13
|
-
];
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { inferNode } from "../../nodes/infer.js";
|
|
2
|
-
import type { ResolvedNode, TypeNode } from "../../nodes/node.js";
|
|
3
|
-
import type { asIn, asOut } from "../../scopes/type.js";
|
|
4
|
-
import type { conform, constructor, error, List, returnOf } from "../../utils/generics.js";
|
|
5
|
-
import type { inferDefinition, ParseContext, validateDefinition } from "../definition.js";
|
|
6
|
-
import type { inferIntersection, inferUnion } from "../string/ast.js";
|
|
7
|
-
import { writeMissingRightOperandMessage } from "../string/shift/operand/unenclosed.js";
|
|
8
|
-
import type { Scanner } from "../string/shift/scanner.js";
|
|
9
|
-
import type { inferKeyOfExpression, validateKeyOfExpression } from "./keyof.js";
|
|
10
|
-
import type { Out, validateMorphTuple } from "./morph.js";
|
|
11
|
-
import type { validateNarrowTuple } from "./narrow.js";
|
|
12
|
-
export declare const parseTuple: (def: List, ctx: ParseContext) => TypeNode;
|
|
13
|
-
export type validateTupleExpression<def extends TupleExpression, $> = def[1] extends "=>" ? validateMorphTuple<def, $> : def[1] extends ":" ? validateNarrowTuple<def, $> : 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 "[]" ? conform<def, readonly [validateDefinition<def[0], $>, "[]"]> : 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" ? validateKeyOfExpression<def[1], $> : never;
|
|
18
|
-
export type inferTuple<def extends List, $> = def extends TupleExpression ? inferTupleExpression<def, $> : {
|
|
19
|
-
[i in keyof def]: inferDefinition<def[i], $>;
|
|
20
|
-
};
|
|
21
|
-
export type inferTupleExpression<def extends TupleExpression, $> = def[1] extends ":" ? "3" extends keyof def ? inferDefinition<def[3], $> : inferDefinition<def[0], $> : def[1] extends "=>" ? (In: asIn<inferDefinition<def[0], $>>) => Out<"3" extends keyof def ? asOut<inferDefinition<def[3], $>> : returnOf<def[2]>> : def[1] extends "&" ? inferIntersection<inferDefinition<def[0], $>, inferDefinition<def[2], $>> : def[1] extends "|" ? inferUnion<inferDefinition<def[0], $>, inferDefinition<def[2], $>> : def[1] extends "[]" ? inferDefinition<def[0], $>[] : 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;
|
|
22
|
-
export type PostfixParser<token extends PostfixToken> = (def: PostfixExpression<token>, ctx: ParseContext) => TypeNode;
|
|
23
|
-
export type PrefixParser<token extends PrefixToken> = (def: PrefixExpression<token>, ctx: ParseContext) => TypeNode;
|
|
24
|
-
export type TupleExpression = PrefixExpression | PostfixExpression;
|
|
25
|
-
export declare const writeMalformedFunctionalExpressionMessage: (operator: "=>" | ":", rightDef: unknown) => string;
|
|
26
|
-
export type TupleExpressionToken = PrefixToken | PostfixToken;
|
|
27
|
-
type PostfixToken = "[]" | "&" | "|" | ":" | "=>";
|
|
28
|
-
export type PostfixExpression<token extends PostfixToken = PostfixToken> = readonly [unknown, token, ...unknown[]];
|
|
29
|
-
type PrefixToken = "keyof" | "instanceof" | "===" | "node";
|
|
30
|
-
export type PrefixExpression<token extends PrefixToken = PrefixToken> = readonly [token, ...unknown[]];
|
|
31
|
-
export {};
|