arktype 1.0.27-alpha → 1.1.0-dev-1
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/main.d.ts +1018 -0
- package/dist/main.js +1450 -0
- package/package.json +36 -108
- package/LICENSE +0 -7
- package/README.md +0 -351
- package/dist/cjs/main.js +0 -38
- package/dist/cjs/nodes/branch.js +0 -140
- package/dist/cjs/nodes/compose.js +0 -163
- package/dist/cjs/nodes/discriminate.js +0 -265
- package/dist/cjs/nodes/node.js +0 -139
- package/dist/cjs/nodes/predicate.js +0 -86
- package/dist/cjs/nodes/rules/class.js +0 -25
- package/dist/cjs/nodes/rules/collapsibleSet.js +0 -48
- package/dist/cjs/nodes/rules/divisor.js +0 -29
- package/dist/cjs/nodes/rules/props.js +0 -167
- package/dist/cjs/nodes/rules/range.js +0 -105
- package/dist/cjs/nodes/rules/regex.js +0 -26
- package/dist/cjs/nodes/rules/rules.js +0 -123
- package/dist/cjs/package.json +0 -3
- package/dist/cjs/parse/ast/ast.js +0 -4
- package/dist/cjs/parse/ast/bound.js +0 -16
- package/dist/cjs/parse/ast/config.js +0 -13
- package/dist/cjs/parse/ast/distributableFunction.js +0 -48
- package/dist/cjs/parse/ast/divisor.js +0 -9
- package/dist/cjs/parse/ast/intersection.js +0 -30
- package/dist/cjs/parse/ast/keyof.js +0 -111
- package/dist/cjs/parse/ast/morph.js +0 -58
- package/dist/cjs/parse/ast/narrow.js +0 -22
- package/dist/cjs/parse/ast/node.js +0 -4
- package/dist/cjs/parse/ast/tuple.js +0 -94
- package/dist/cjs/parse/ast/union.js +0 -9
- package/dist/cjs/parse/ast/utils.js +0 -4
- package/dist/cjs/parse/definition.js +0 -61
- package/dist/cjs/parse/record.js +0 -37
- package/dist/cjs/parse/string/reduce/dynamic.js +0 -167
- package/dist/cjs/parse/string/reduce/shared.js +0 -23
- package/dist/cjs/parse/string/reduce/static.js +0 -4
- package/dist/cjs/parse/string/shift/operand/enclosed.js +0 -54
- package/dist/cjs/parse/string/shift/operand/operand.js +0 -11
- package/dist/cjs/parse/string/shift/operand/unenclosed.js +0 -53
- package/dist/cjs/parse/string/shift/operator/bounds.js +0 -87
- package/dist/cjs/parse/string/shift/operator/divisor.js +0 -35
- package/dist/cjs/parse/string/shift/operator/operator.js +0 -26
- package/dist/cjs/parse/string/shift/scanner.js +0 -114
- package/dist/cjs/parse/string/string.js +0 -43
- package/dist/cjs/scopes/ark.js +0 -45
- package/dist/cjs/scopes/cache.js +0 -52
- package/dist/cjs/scopes/expressions.js +0 -29
- package/dist/cjs/scopes/jsObjects.js +0 -93
- package/dist/cjs/scopes/scope.js +0 -323
- package/dist/cjs/scopes/tsKeywords.js +0 -113
- package/dist/cjs/scopes/type.js +0 -50
- package/dist/cjs/scopes/validation/creditCard.js +0 -47
- package/dist/cjs/scopes/validation/date.js +0 -62
- package/dist/cjs/scopes/validation/validation.js +0 -108
- package/dist/cjs/traverse/problems.js +0 -281
- package/dist/cjs/traverse/traverse.js +0 -390
- package/dist/cjs/utils/chainableNoOpProxy.js +0 -23
- package/dist/cjs/utils/data.js +0 -53
- package/dist/cjs/utils/domains.js +0 -30
- package/dist/cjs/utils/errors.js +0 -26
- package/dist/cjs/utils/freeze.js +0 -15
- package/dist/cjs/utils/generics.js +0 -63
- package/dist/cjs/utils/numericLiterals.js +0 -75
- package/dist/cjs/utils/objectKinds.js +0 -69
- package/dist/cjs/utils/paths.js +0 -32
- package/dist/cjs/utils/serialize.js +0 -74
- package/dist/cjs/utils/unionToTuple.js +0 -4
- package/dist/mjs/main.js +0 -8
- package/dist/mjs/nodes/branch.js +0 -123
- package/dist/mjs/nodes/compose.js +0 -141
- package/dist/mjs/nodes/discriminate.js +0 -250
- package/dist/mjs/nodes/node.js +0 -117
- package/dist/mjs/nodes/predicate.js +0 -69
- package/dist/mjs/nodes/rules/class.js +0 -11
- package/dist/mjs/nodes/rules/collapsibleSet.js +0 -34
- package/dist/mjs/nodes/rules/divisor.js +0 -15
- package/dist/mjs/nodes/rules/props.js +0 -149
- package/dist/mjs/nodes/rules/range.js +0 -86
- package/dist/mjs/nodes/rules/regex.js +0 -11
- package/dist/mjs/nodes/rules/rules.js +0 -106
- package/dist/mjs/package.json +0 -3
- package/dist/mjs/parse/ast/ast.js +0 -1
- package/dist/mjs/parse/ast/bound.js +0 -2
- package/dist/mjs/parse/ast/config.js +0 -9
- package/dist/mjs/parse/ast/distributableFunction.js +0 -34
- package/dist/mjs/parse/ast/divisor.js +0 -1
- package/dist/mjs/parse/ast/intersection.js +0 -16
- package/dist/mjs/parse/ast/keyof.js +0 -103
- package/dist/mjs/parse/ast/morph.js +0 -44
- package/dist/mjs/parse/ast/narrow.js +0 -14
- package/dist/mjs/parse/ast/node.js +0 -1
- package/dist/mjs/parse/ast/tuple.js +0 -80
- package/dist/mjs/parse/ast/union.js +0 -1
- package/dist/mjs/parse/ast/utils.js +0 -1
- package/dist/mjs/parse/definition.js +0 -46
- package/dist/mjs/parse/record.js +0 -29
- package/dist/mjs/parse/string/reduce/dynamic.js +0 -159
- package/dist/mjs/parse/string/reduce/shared.js +0 -6
- package/dist/mjs/parse/string/reduce/static.js +0 -1
- package/dist/mjs/parse/string/shift/operand/enclosed.js +0 -39
- package/dist/mjs/parse/string/shift/operand/operand.js +0 -3
- package/dist/mjs/parse/string/shift/operand/unenclosed.js +0 -36
- package/dist/mjs/parse/string/shift/operator/bounds.js +0 -70
- package/dist/mjs/parse/string/shift/operator/divisor.js +0 -21
- package/dist/mjs/parse/string/shift/operator/operator.js +0 -13
- package/dist/mjs/parse/string/shift/scanner.js +0 -106
- package/dist/mjs/parse/string/string.js +0 -28
- package/dist/mjs/scopes/ark.js +0 -28
- package/dist/mjs/scopes/cache.js +0 -38
- package/dist/mjs/scopes/expressions.js +0 -89
- package/dist/mjs/scopes/jsObjects.js +0 -82
- package/dist/mjs/scopes/scope.js +0 -303
- package/dist/mjs/scopes/tsKeywords.js +0 -116
- package/dist/mjs/scopes/type.js +0 -35
- package/dist/mjs/scopes/validation/creditCard.js +0 -34
- package/dist/mjs/scopes/validation/date.js +0 -48
- package/dist/mjs/scopes/validation/validation.js +0 -112
- package/dist/mjs/traverse/problems.js +0 -260
- package/dist/mjs/traverse/traverse.js +0 -373
- package/dist/mjs/utils/chainableNoOpProxy.js +0 -15
- package/dist/mjs/utils/data.js +0 -38
- package/dist/mjs/utils/domains.js +0 -15
- package/dist/mjs/utils/errors.js +0 -10
- package/dist/mjs/utils/freeze.js +0 -7
- package/dist/mjs/utils/generics.js +0 -38
- package/dist/mjs/utils/numericLiterals.js +0 -72
- package/dist/mjs/utils/objectKinds.js +0 -55
- package/dist/mjs/utils/paths.js +0 -18
- package/dist/mjs/utils/serialize.js +0 -58
- package/dist/mjs/utils/unionToTuple.js +0 -1
- package/dist/tsconfig.temp.tsbuildinfo +0 -1
- package/dist/types/main.d.ts +0 -15
- package/dist/types/nodes/branch.d.ts +0 -29
- package/dist/types/nodes/compose.d.ts +0 -98
- package/dist/types/nodes/discriminate.d.ts +0 -26
- package/dist/types/nodes/node.d.ts +0 -69
- package/dist/types/nodes/predicate.d.ts +0 -18
- package/dist/types/nodes/rules/class.d.ts +0 -4
- package/dist/types/nodes/rules/collapsibleSet.d.ts +0 -4
- package/dist/types/nodes/rules/divisor.d.ts +0 -3
- package/dist/types/nodes/rules/props.d.ts +0 -43
- package/dist/types/nodes/rules/range.d.ts +0 -34
- package/dist/types/nodes/rules/regex.d.ts +0 -5
- package/dist/types/nodes/rules/rules.d.ts +0 -33
- package/dist/types/parse/ast/ast.d.ts +0 -24
- package/dist/types/parse/ast/bound.d.ts +0 -27
- package/dist/types/parse/ast/config.d.ts +0 -15
- package/dist/types/parse/ast/distributableFunction.d.ts +0 -18
- package/dist/types/parse/ast/divisor.d.ts +0 -13
- package/dist/types/parse/ast/intersection.d.ts +0 -31
- package/dist/types/parse/ast/keyof.d.ts +0 -10
- package/dist/types/parse/ast/morph.d.ts +0 -17
- package/dist/types/parse/ast/narrow.d.ts +0 -21
- package/dist/types/parse/ast/node.d.ts +0 -35
- package/dist/types/parse/ast/tuple.d.ts +0 -41
- package/dist/types/parse/ast/union.d.ts +0 -17
- package/dist/types/parse/ast/utils.d.ts +0 -7
- package/dist/types/parse/definition.d.ts +0 -30
- package/dist/types/parse/record.d.ts +0 -26
- package/dist/types/parse/string/reduce/dynamic.d.ts +0 -34
- package/dist/types/parse/string/reduce/shared.d.ts +0 -25
- package/dist/types/parse/string/reduce/static.d.ts +0 -130
- package/dist/types/parse/string/shift/operand/enclosed.d.ts +0 -28
- package/dist/types/parse/string/shift/operand/operand.d.ts +0 -9
- package/dist/types/parse/string/shift/operand/unenclosed.d.ts +0 -18
- package/dist/types/parse/string/shift/operator/bounds.d.ts +0 -21
- package/dist/types/parse/string/shift/operator/divisor.d.ts +0 -13
- package/dist/types/parse/string/shift/operator/operator.d.ts +0 -13
- package/dist/types/parse/string/shift/scanner.d.ts +0 -89
- package/dist/types/parse/string/string.d.ts +0 -25
- package/dist/types/scopes/ark.d.ts +0 -208
- package/dist/types/scopes/cache.d.ts +0 -14
- package/dist/types/scopes/expressions.d.ts +0 -136
- package/dist/types/scopes/jsObjects.d.ts +0 -26
- package/dist/types/scopes/scope.d.ts +0 -99
- package/dist/types/scopes/tsKeywords.d.ts +0 -50
- package/dist/types/scopes/type.d.ts +0 -67
- package/dist/types/scopes/validation/creditCard.d.ts +0 -2
- package/dist/types/scopes/validation/date.d.ts +0 -23
- package/dist/types/scopes/validation/validation.d.ts +0 -49
- package/dist/types/traverse/problems.d.ts +0 -88
- package/dist/types/traverse/traverse.d.ts +0 -55
- package/dist/types/utils/chainableNoOpProxy.d.ts +0 -14
- package/dist/types/utils/data.d.ts +0 -13
- package/dist/types/utils/domains.d.ts +0 -32
- package/dist/types/utils/errors.d.ts +0 -6
- package/dist/types/utils/freeze.d.ts +0 -2
- package/dist/types/utils/generics.d.ts +0 -125
- package/dist/types/utils/numericLiterals.d.ts +0 -46
- package/dist/types/utils/objectKinds.d.ts +0 -84
- package/dist/types/utils/paths.d.ts +0 -9
- package/dist/types/utils/serialize.d.ts +0 -37
- package/dist/types/utils/unionToTuple.d.ts +0 -11
|
@@ -1,27 +0,0 @@
|
|
|
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 { Scanner } from "../string/shift/scanner.js";
|
|
5
|
-
import type { inferAst, validateAst } from "./ast.js";
|
|
6
|
-
import type { astToString } from "./utils.js";
|
|
7
|
-
/**
|
|
8
|
-
* @operator {@link validateBound | bound}
|
|
9
|
-
* @docgenTable
|
|
10
|
-
* * @tableRow N number literal
|
|
11
|
-
* @tableRow S sized data (a number, string or array)
|
|
12
|
-
* @tableRow < Comparator (one of <, <=, ==, >=, >)
|
|
13
|
-
* @description
|
|
14
|
-
* Bound operators allow data to be bounded in the format "S<N", or as a Range: "N<S<N", with comparators restricted to < or <=
|
|
15
|
-
* @string "N<S<N", with comparators restricted to < or <=
|
|
16
|
-
* @example string
|
|
17
|
-
* const range = type("2<=number<5")
|
|
18
|
-
* @example string
|
|
19
|
-
* const bound = type("string[]==5")
|
|
20
|
-
*/
|
|
21
|
-
export type validateBound<l, r, $> = l extends NumberLiteral ? validateAst<r, $> : l extends [infer leftAst, Scanner.Comparator, unknown] ? error<writeDoubleRightBoundMessage<astToString<leftAst>>> : isBoundable<inferAst<l, $>> extends true ? validateAst<l, $> : error<writeUnboundableMessage<astToString<l>>>;
|
|
22
|
-
export declare const writeDoubleRightBoundMessage: <root extends string>(root: root) => `Expression ${root} must have at most one right bound`;
|
|
23
|
-
type writeDoubleRightBoundMessage<root extends string> = `Expression ${root} must have at most one right bound`;
|
|
24
|
-
type isBoundable<data> = isAny<data> extends true ? false : [data] extends [SizedData] ? true : false;
|
|
25
|
-
export declare const writeUnboundableMessage: <root extends string>(root: root) => `Bounded expression ${root} must be a number, string or array`;
|
|
26
|
-
type writeUnboundableMessage<root extends string> = `Bounded expression ${root} must be a number, string or array`;
|
|
27
|
-
export {};
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { TypeOptions } from "../../scopes/type.js";
|
|
2
|
-
import type { validateDefinition } from "../definition.js";
|
|
3
|
-
import type { PostfixParser, TupleExpression } from "./tuple.js";
|
|
4
|
-
export type ConfigTuple<def = unknown, config extends TypeOptions = TypeOptions> = readonly [def, ":", config];
|
|
5
|
-
/**
|
|
6
|
-
* @operator {@link parseConfigTuple | :}
|
|
7
|
-
* @docgenTable
|
|
8
|
-
* @tuple ["type", ":", config]
|
|
9
|
-
*/
|
|
10
|
-
export declare const parseConfigTuple: PostfixParser<":">;
|
|
11
|
-
export type validateConfigTuple<def extends TupleExpression, $> = readonly [
|
|
12
|
-
_: validateDefinition<def[0], $>,
|
|
13
|
-
_: ":",
|
|
14
|
-
_: TypeOptions
|
|
15
|
-
];
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { TypeNode } from "../../nodes/node.js";
|
|
2
|
-
import type { NarrowableRules } from "../../nodes/rules/rules.js";
|
|
3
|
-
import type { Domain, domainOf, inferDomain } from "../../utils/domains.js";
|
|
4
|
-
import type { evaluate } from "../../utils/generics.js";
|
|
5
|
-
import type { ParseContext } from "../definition.js";
|
|
6
|
-
export type DistributableFunction<input = any, args extends any[] = any[], output = unknown> = (input: input, ...args: args) => output;
|
|
7
|
-
export type distributable<f extends DistributableFunction> = f | distributeFunction<f>;
|
|
8
|
-
export type distributeFunction<f extends DistributableFunction> = f extends DistributableFunction<infer input, infer args, infer output> ? evaluate<{
|
|
9
|
-
[domain in domainOf<input>]?: (input: unknown extends input ? unknown : Extract<input, inferDomain<domain>>, ...args: args) => output;
|
|
10
|
-
}> : never;
|
|
11
|
-
export declare const writeMalformedDistributableFunctionMessage: (def: unknown) => string;
|
|
12
|
-
export type DistributedFunctionNode<f, ruleKey extends keyof NarrowableRules> = {
|
|
13
|
-
[domain in Domain]?: FunctionInDomain<f, ruleKey>;
|
|
14
|
-
};
|
|
15
|
-
export type FunctionInDomain<f, ruleKey extends keyof NarrowableRules> = {
|
|
16
|
-
[k in ruleKey]: f;
|
|
17
|
-
};
|
|
18
|
-
export declare const distributeFunctionToNode: <f extends DistributableFunction<any, any[], unknown>, ruleKey extends keyof NarrowableRules>(distributableFunction: distributable<f>, node: TypeNode, ctx: ParseContext, ruleKey: ruleKey) => DistributedFunctionNode<f, ruleKey>;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { error, isAny } from "../../utils/generics.js";
|
|
2
|
-
import type { inferAst, validateAst } from "./ast.js";
|
|
3
|
-
import type { astToString } from "./utils.js";
|
|
4
|
-
/**
|
|
5
|
-
* @operator {@link validateDivisor | %}
|
|
6
|
-
* @docgenTable
|
|
7
|
-
* @string "N%D", where "N" is a number and "D" is a non-zero integer
|
|
8
|
-
*/
|
|
9
|
-
export type validateDivisor<l, $> = isDivisible<inferAst<l, $>> extends true ? validateAst<l, $> : error<writeIndivisibleMessage<astToString<l>>>;
|
|
10
|
-
type isDivisible<data> = isAny<data> extends true ? false : [data] extends [number] ? true : false;
|
|
11
|
-
export declare const writeIndivisibleMessage: <root extends string>(root: root) => `Divisibility operand ${root} must be a number`;
|
|
12
|
-
type writeIndivisibleMessage<root extends string> = `Divisibility operand ${root} must be a number`;
|
|
13
|
-
export {};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { DisjointsByPath } from "../../nodes/compose.js";
|
|
2
|
-
import type { asConst, evaluate, isAny, List } from "../../utils/generics.js";
|
|
3
|
-
import type { Path, pathToString } from "../../utils/paths.js";
|
|
4
|
-
import type { ParsedMorph } from "./morph.js";
|
|
5
|
-
export type inferIntersection<l, r> = [l] extends [never] ? never : [r] extends [never] ? never : [l & r] extends [never] ? never : isAny<l | r> extends true ? any : l extends ParsedMorph<infer lIn, infer lOut> ? r extends ParsedMorph ? never : (In: evaluate<lIn & r>) => lOut : r extends ParsedMorph<infer rIn, infer rOut> ? (In: evaluate<rIn & l>) => rOut : intersectObjects<l, r> extends infer result ? result : never;
|
|
6
|
-
type intersectObjects<l, r> = [l, r] extends [object, object] ? [l, r] extends [infer lList extends List, infer rList extends List] ? inferArrayIntersection<lList, rList> : evaluate<{
|
|
7
|
-
[k in keyof l]: k extends keyof r ? inferIntersection<l[k], r[k]> : l[k];
|
|
8
|
-
} & Omit<r, keyof l>> : l & r;
|
|
9
|
-
type inferArrayIntersection<l extends List, r extends List, result extends List = []> = [l, r] extends [
|
|
10
|
-
[
|
|
11
|
-
infer lHead,
|
|
12
|
-
...infer lTail
|
|
13
|
-
],
|
|
14
|
-
[
|
|
15
|
-
infer rHead,
|
|
16
|
-
...infer rTail
|
|
17
|
-
]
|
|
18
|
-
] ? inferArrayIntersection<lTail, rTail, [
|
|
19
|
-
...result,
|
|
20
|
-
inferIntersection<lHead, rHead>
|
|
21
|
-
]> : l extends [infer lHead, ...infer lTail] ? r extends [] ? never : inferArrayIntersection<lTail, r, [
|
|
22
|
-
...result,
|
|
23
|
-
inferIntersection<lHead, r[number]>
|
|
24
|
-
]> : r extends [infer rHead, ...infer rTail] ? l extends [] ? never : inferArrayIntersection<l, rTail, [
|
|
25
|
-
...result,
|
|
26
|
-
inferIntersection<l[number], rHead>
|
|
27
|
-
]> : [number, number] extends [l["length"], r["length"]] ? [...result, ...inferIntersection<l[number], r[number]>[]] : result;
|
|
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 {};
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { evaluate } from "../../utils/generics.js";
|
|
2
|
-
import type { inferDefinition, validateDefinition } from "../definition.js";
|
|
3
|
-
import { writeImplicitNeverMessage } from "./intersection.js";
|
|
4
|
-
import type { PrefixParser } from "./tuple.js";
|
|
5
|
-
export declare const parseKeyOfTuple: PrefixParser<"keyof">;
|
|
6
|
-
export type inferKeyOfExpression<operandDef, $> = evaluate<keyof inferDefinition<operandDef, $>>;
|
|
7
|
-
export type validateKeyOfExpression<operandDef, $> = readonly [
|
|
8
|
-
"keyof",
|
|
9
|
-
inferKeyOfExpression<operandDef, $> extends never ? writeImplicitNeverMessage<[], "keyof"> : validateDefinition<operandDef, $>
|
|
10
|
-
];
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { asIn, asOut } from "../../scopes/type.js";
|
|
2
|
-
import type { Problem, Problems } from "../../traverse/problems.js";
|
|
3
|
-
import type { CheckResult } from "../../traverse/traverse.js";
|
|
4
|
-
import type { inferDefinition, validateDefinition } from "../definition.js";
|
|
5
|
-
import type { PostfixParser, TupleExpression } from "./tuple.js";
|
|
6
|
-
export declare const parseMorphTuple: PostfixParser<"|>">;
|
|
7
|
-
export type validateMorphTuple<def extends TupleExpression, $> = readonly [
|
|
8
|
-
_: validateDefinition<def[0], $>,
|
|
9
|
-
_: "|>",
|
|
10
|
-
_: Morph<asOut<inferDefinition<def[0], $>>, unknown>
|
|
11
|
-
];
|
|
12
|
-
export type Morph<i = any, o = unknown> = (In: i, problems: Problems) => o;
|
|
13
|
-
export type ParsedMorph<i = any, o = unknown> = (In: i) => o;
|
|
14
|
-
export type inferMorph<inDef, morph, $> = morph extends Morph ? (In: asIn<inferDefinition<inDef, $>>) => inferMorphOut<ReturnType<morph>> : never;
|
|
15
|
-
type inferMorphOut<out> = [out] extends [CheckResult<infer t>] ? t : Exclude<out, Problem>;
|
|
16
|
-
export declare const writeMalformedMorphExpressionMessage: (value: unknown) => string;
|
|
17
|
-
export {};
|
|
@@ -1,21 +0,0 @@
|
|
|
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 NarrowPredicate<data = any, narrowed extends data = data> = (data: data, problems: Problems) => data is narrowed;
|
|
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 {
|
|
16
|
-
[domain in Domain]?: any;
|
|
17
|
-
} ? {
|
|
18
|
-
[domain in keyof narrow]: inferNarrowFunction<Extract<asIn<inferDefinition<inDef, $>>, inferDomain<domain & Domain>>, narrow[domain]>;
|
|
19
|
-
}[keyof narrow] : inferNarrowFunction<asIn<inferDefinition<inDef, $>>, narrow>;
|
|
20
|
-
type inferNarrowFunction<input, narrow> = narrow extends (data: any, ...args: any[]) => data is infer narrowed ? narrowed : input;
|
|
21
|
-
export {};
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { MetaBranch } from "../../nodes/branch.js";
|
|
2
|
-
import type { LiteralNode, Node } from "../../nodes/node.js";
|
|
3
|
-
import type { Predicate } from "../../nodes/predicate.js";
|
|
4
|
-
import type { MappedPropKey, OptionalProp, Prop, PropsRule } from "../../nodes/rules/props.js";
|
|
5
|
-
import type { LiteralRules, NarrowableRules } from "../../nodes/rules/rules.js";
|
|
6
|
-
import type { Domain, inferDomain } from "../../utils/domains.js";
|
|
7
|
-
import type { constructor, evaluate, evaluateObjectOrFunction, HomogenousTuple, List, returnOf } from "../../utils/generics.js";
|
|
8
|
-
import type { BuiltinClass, inferObjectKind } from "../../utils/objectKinds.js";
|
|
9
|
-
import type { inferTerminal } from "./ast.js";
|
|
10
|
-
export type inferNode<node extends Node<$>, $ = {}> = node extends string ? inferTerminal<node, $> : node extends Node<$> ? inferResolution<node, $> extends infer result ? result extends BuiltinClass ? result : evaluateObjectOrFunction<result> : never : never;
|
|
11
|
-
export type inferResolution<node extends Node<$>, $> = {
|
|
12
|
-
[domain in keyof node]: inferPredicate<
|
|
13
|
-
/** @ts-expect-error Some very odd inference behavior related to domain I can't resolve */
|
|
14
|
-
domain, node[domain], $>;
|
|
15
|
-
}[keyof node];
|
|
16
|
-
type inferPredicate<domain extends Domain, predicate extends Predicate, $> = predicate extends true ? inferDomain<domain> : inferBranch<domain, branchFrom<predicate>, $>;
|
|
17
|
-
type branchFrom<predicate extends Predicate> = predicate extends List ? predicate[number] : predicate;
|
|
18
|
-
type inferBranch<domain extends Domain, branch, $> = branch extends MetaBranch ? inferMorph<domain, branch, $> : inferRules<domain, branch, $>;
|
|
19
|
-
type inferMorph<domain extends Domain, branch extends MetaBranch, $> = (In: inferBranch<domain, branch["rules"], $>) => branch["morph"] extends [...unknown[], infer tail] ? returnOf<tail> : returnOf<branch["morph"]>;
|
|
20
|
-
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["class"] extends ArrayConstructor ? rules["props"] extends {
|
|
22
|
-
"[index]": Prop<$, infer indexNode>;
|
|
23
|
-
length?: Prop<$, infer lengthNode>;
|
|
24
|
-
} ? lengthNode extends LiteralNode<"number", infer value> ? HomogenousTuple<inferNode<indexNode, $>, value> : inferNode<indexNode, $>[] : unknown[] : rules["class"] extends FunctionConstructor ? inferObjectKind<"Function"> : rules["class"] extends constructor<infer instance> ? instance : rules["props"] extends PropsRule ? inferProps<rules["props"], $> : object;
|
|
25
|
-
type inferProps<props extends PropsRule, $> = evaluate<{
|
|
26
|
-
[k in requiredKeyOf<props>]: props[k] extends Prop<$, infer node> ? inferNode<node, $> : never;
|
|
27
|
-
} & {
|
|
28
|
-
[k in optionalKeyOf<props>]?: props[k] extends OptionalProp<$> ? inferNode<props[k][1], $> : never;
|
|
29
|
-
}>;
|
|
30
|
-
type optionalKeyOf<props extends PropsRule> = {
|
|
31
|
-
[k in keyof props]: props[k] extends OptionalProp ? k : never;
|
|
32
|
-
}[keyof props];
|
|
33
|
-
type mappedKeyOf<props extends PropsRule> = Extract<keyof props, MappedPropKey>;
|
|
34
|
-
type requiredKeyOf<props extends PropsRule> = Exclude<keyof props, optionalKeyOf<props> | mappedKeyOf<props>>;
|
|
35
|
-
export {};
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import type { Node, ResolvedNode } from "../../nodes/node.js";
|
|
2
|
-
import type { conform, constructor, Dict, error, evaluate, List } from "../../utils/generics.js";
|
|
3
|
-
import type { inferDefinition, ParseContext, validateDefinition } from "../definition.js";
|
|
4
|
-
import { writeMissingRightOperandMessage } from "../string/shift/operand/unenclosed.js";
|
|
5
|
-
import type { Scanner } from "../string/shift/scanner.js";
|
|
6
|
-
import type { validateConfigTuple } from "./config.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 { inferNode } from "./node.js";
|
|
12
|
-
import type { inferUnion } from "./union.js";
|
|
13
|
-
export declare const parseTuple: (def: List, ctx: ParseContext) => Node;
|
|
14
|
-
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 [
|
|
15
|
-
validateDefinition<def[0], $>,
|
|
16
|
-
def[1],
|
|
17
|
-
validateDefinition<def[2], $>
|
|
18
|
-
]> : def[1] extends "=>" ? validateNarrowTuple<def, $> : def[1] extends "|>" ? validateMorphTuple<def, $> : def[1] extends ":" ? validateConfigTuple<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;
|
|
19
|
-
export type UnparsedTupleExpressionInput<$> = {
|
|
20
|
-
instanceof: constructor;
|
|
21
|
-
node: ResolvedNode<$>;
|
|
22
|
-
"===": unknown;
|
|
23
|
-
};
|
|
24
|
-
export type UnparsedTupleOperator = evaluate<keyof UnparsedTupleExpressionInput<Dict>>;
|
|
25
|
-
export type inferTuple<def extends List, $> = def extends TupleExpression ? inferTupleExpression<def, $> : {
|
|
26
|
-
[i in keyof def]: inferDefinition<def[i], $>;
|
|
27
|
-
};
|
|
28
|
-
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[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;
|
|
29
|
-
export type PostfixParser<token extends IndexOneOperator> = (def: IndexOneExpression<token>, ctx: ParseContext) => Node;
|
|
30
|
-
export type PrefixParser<token extends IndexZeroOperator> = (def: IndexZeroExpression<token>, ctx: ParseContext) => Node;
|
|
31
|
-
export type TupleExpression = IndexZeroExpression | IndexOneExpression;
|
|
32
|
-
export declare const writeMalformedFunctionalExpressionMessage: (operator: FunctionalTupleOperator, rightDef: unknown) => string;
|
|
33
|
-
export type TupleExpressionOperator = IndexZeroOperator | IndexOneOperator;
|
|
34
|
-
type IndexOneOperator = TuplePostfixOperator | TupleInfixOperator;
|
|
35
|
-
export type TuplePostfixOperator = "[]";
|
|
36
|
-
export type TupleInfixOperator = "&" | "|" | ":" | "=>" | "|>";
|
|
37
|
-
export type IndexOneExpression<token extends IndexOneOperator = IndexOneOperator> = readonly [unknown, token, ...unknown[]];
|
|
38
|
-
export type FunctionalTupleOperator = "=>" | "|>";
|
|
39
|
-
export type IndexZeroOperator = "keyof" | "instanceof" | "===" | "node";
|
|
40
|
-
export type IndexZeroExpression<token extends IndexZeroOperator = IndexZeroOperator> = readonly [token, ...unknown[]];
|
|
41
|
-
export {};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { asIn } from "../../scopes/type.js";
|
|
2
|
-
import type { domainOf } from "../../utils/domains.js";
|
|
3
|
-
import type { equals, error, extractValues, isAny, optionalKeyOf, requiredKeyOf } from "../../utils/generics.js";
|
|
4
|
-
import type { objectKindOf } from "../../utils/objectKinds.js";
|
|
5
|
-
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;
|
|
6
|
-
type discriminatable<l, r> = discriminatableRecurse<l, r, []> extends never ? false : true;
|
|
7
|
-
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<{
|
|
8
|
-
[k in keyof l as k extends optionalKeyOf<l> ? never : k]: k extends requiredKeyOf<r> ? discriminatableRecurse<l[k], r[k], [
|
|
9
|
-
...path,
|
|
10
|
-
k & string
|
|
11
|
-
]> & {
|
|
12
|
-
_: l;
|
|
13
|
-
} : never;
|
|
14
|
-
}, string[]> : never;
|
|
15
|
-
export declare const writeUndiscriminatableMorphUnionMessage: <path extends string>(path: path) => string;
|
|
16
|
-
type undiscriminatableMorphUnionMessage = `A union including one or more morphs must be discriminatable`;
|
|
17
|
-
export {};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { List, Literalable } from "../../utils/generics.js";
|
|
2
|
-
import type { Scanner } from "../string/shift/scanner.js";
|
|
3
|
-
import type { InfixExpression, PostfixExpression } from "./ast.js";
|
|
4
|
-
export type astToString<ast> = `'${astToStringRecurse<ast>}'`;
|
|
5
|
-
type astToStringRecurse<ast> = ast extends PostfixExpression<infer operator, infer operand> ? operator extends "[]" ? `${groupAst<operand>}[]` : never : ast extends InfixExpression<infer operator, infer l, infer r> ? operator extends "&" | "|" | "%" | Scanner.Comparator ? `${groupAst<l>}${operator}${groupAst<r>}` : never : ast extends Literalable ? `${ast extends bigint ? `${ast}n` : ast}` : "...";
|
|
6
|
-
type groupAst<ast> = ast extends List ? ast[1] extends "[]" ? astToStringRecurse<ast> : `(${astToStringRecurse<ast>})` : astToStringRecurse<ast>;
|
|
7
|
-
export {};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { Node } from "../nodes/node.js";
|
|
2
|
-
import type { Type } from "../scopes/type.js";
|
|
3
|
-
import type { Primitive } from "../utils/domains.js";
|
|
4
|
-
import { domainOf } from "../utils/domains.js";
|
|
5
|
-
import type { Dict, evaluate, isAny, isUnknown, List, stringKeyOf } from "../utils/generics.js";
|
|
6
|
-
import { objectKindOf } from "../utils/objectKinds.js";
|
|
7
|
-
import type { Path } from "../utils/paths.js";
|
|
8
|
-
import type { validateString } from "./ast/ast.js";
|
|
9
|
-
import type { inferTuple, TupleExpression, validateTupleExpression } from "./ast/tuple.js";
|
|
10
|
-
import type { inferRecord } from "./record.js";
|
|
11
|
-
import type { inferString } from "./string/string.js";
|
|
12
|
-
export type ParseContext = {
|
|
13
|
-
type: Type;
|
|
14
|
-
path: Path;
|
|
15
|
-
};
|
|
16
|
-
export declare const parseDefinition: (def: unknown, ctx: ParseContext) => Node;
|
|
17
|
-
export type inferDefinition<def, $> = isAny<def> extends true ? never : def extends Infer<infer t> | InferredThunk<infer t> ? t : def extends string ? inferString<def, $> : def extends List ? inferTuple<def, $> : def extends RegExp ? string : def extends Dict ? inferRecord<def, $> : never;
|
|
18
|
-
export type validateDefinition<def, $> = [def] extends [(...args: any[]) => any] ? def : def extends Terminal ? def : def extends string ? validateString<def, $> : def extends TupleExpression ? validateTupleExpression<def, $> : def extends BadDefinitionType ? writeBadDefinitionTypeMessage<objectKindOf<def> extends string ? objectKindOf<def> : domainOf<def>> : isUnknown<def> extends true ? stringKeyOf<$> : evaluate<{
|
|
19
|
-
[k in keyof def]: validateDefinition<def[k], $>;
|
|
20
|
-
}>;
|
|
21
|
-
export declare const as: unique symbol;
|
|
22
|
-
export type Infer<t> = {
|
|
23
|
-
[as]?: t;
|
|
24
|
-
};
|
|
25
|
-
type InferredThunk<t = unknown> = () => Infer<t>;
|
|
26
|
-
type Terminal = RegExp | Infer<unknown> | InferredThunk;
|
|
27
|
-
type BadDefinitionType = Exclude<Primitive, string>;
|
|
28
|
-
export declare const writeBadDefinitionTypeMessage: <actual extends string>(actual: actual) => `Type definitions must be strings or objects (was ${actual})`;
|
|
29
|
-
type writeBadDefinitionTypeMessage<actual extends string> = `Type definitions must be strings or objects (was ${actual})`;
|
|
30
|
-
export {};
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { ResolvedNode } from "../nodes/node.js";
|
|
2
|
-
import type { Dict, evaluate } from "../utils/generics.js";
|
|
3
|
-
import type { inferDefinition, ParseContext } from "./definition.js";
|
|
4
|
-
import { Scanner } from "./string/shift/scanner.js";
|
|
5
|
-
export declare const parseRecord: (def: Dict, ctx: ParseContext) => ResolvedNode;
|
|
6
|
-
type withPossiblePreviousEscapeCharacter<k> = k extends `${infer name}?` ? `${name}${Scanner.EscapeToken}?` : k;
|
|
7
|
-
export type inferRecord<def extends Dict, $> = evaluate<{
|
|
8
|
-
[k in keyof def as k extends requiredKeyOf<def> ? k : never]: inferDefinition<def[withPossiblePreviousEscapeCharacter<k>], $>;
|
|
9
|
-
} & {
|
|
10
|
-
[k in Exclude<requiredKeyOf<def>, keyof def>]: inferDefinition<def[withPossiblePreviousEscapeCharacter<k>], $>;
|
|
11
|
-
} & {
|
|
12
|
-
[optionalKeyName in optionalKeyOf<def>]?: inferDefinition<def[`${optionalKeyName}?`], $>;
|
|
13
|
-
}>;
|
|
14
|
-
type KeyParseResult<name extends string, isOptional extends boolean> = [
|
|
15
|
-
name,
|
|
16
|
-
isOptional
|
|
17
|
-
];
|
|
18
|
-
type parseKey<k> = k extends optionalKeyWithName<infer name> ? name extends `${infer baseName}${Scanner.EscapeToken}` ? [`${baseName}?`, false] : [name, true] : [k, false];
|
|
19
|
-
type optionalKeyWithName<name extends string = string> = `${name}?`;
|
|
20
|
-
type optionalKeyOf<def> = {
|
|
21
|
-
[k in keyof def]: parseKey<k> extends KeyParseResult<infer name, true> ? name : never;
|
|
22
|
-
}[keyof def] & unknown;
|
|
23
|
-
type requiredKeyOf<def> = {
|
|
24
|
-
[k in keyof def]: parseKey<k> extends KeyParseResult<infer name, false> ? name : never;
|
|
25
|
-
}[keyof def] & unknown;
|
|
26
|
-
export {};
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { Node } from "../../../nodes/node.js";
|
|
2
|
-
import type { LowerBound } from "../../../nodes/rules/range.js";
|
|
3
|
-
import type { ParseContext } from "../../definition.js";
|
|
4
|
-
import { Scanner } from "../shift/scanner.js";
|
|
5
|
-
export declare class DynamicState {
|
|
6
|
-
readonly ctx: ParseContext;
|
|
7
|
-
readonly scanner: Scanner;
|
|
8
|
-
private root;
|
|
9
|
-
private branches;
|
|
10
|
-
private groups;
|
|
11
|
-
constructor(def: string, ctx: ParseContext);
|
|
12
|
-
error(message: string): never;
|
|
13
|
-
hasRoot(): boolean;
|
|
14
|
-
resolveRoot(): import("../../../nodes/node.js").TypeNode;
|
|
15
|
-
rootToString(): string;
|
|
16
|
-
ejectRootIfLimit(): number | undefined;
|
|
17
|
-
ejectRangeIfOpen(): LowerBound | undefined;
|
|
18
|
-
private assertHasRoot;
|
|
19
|
-
private assertUnsetRoot;
|
|
20
|
-
setRoot(node: Node): void;
|
|
21
|
-
rootToArray(): void;
|
|
22
|
-
intersect(node: Node): void;
|
|
23
|
-
private ejectRoot;
|
|
24
|
-
ejectFinalizedRoot(): Node;
|
|
25
|
-
finalize(): undefined;
|
|
26
|
-
reduceLeftBound(limit: number, comparator: Scanner.Comparator): undefined;
|
|
27
|
-
finalizeBranches(): void;
|
|
28
|
-
finalizeGroup(): undefined;
|
|
29
|
-
pushRootToBranch(token: Scanner.BranchToken): void;
|
|
30
|
-
private assertRangeUnset;
|
|
31
|
-
reduceGroupOpen(): void;
|
|
32
|
-
previousOperator(): "|" | "&" | undefined;
|
|
33
|
-
shiftedByOne(): this;
|
|
34
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { MinComparator } from "../../../nodes/rules/range.js";
|
|
2
|
-
import type { NumberLiteral } from "../../../utils/numericLiterals.js";
|
|
3
|
-
import { Scanner } from "../shift/scanner.js";
|
|
4
|
-
export declare const writeUnmatchedGroupCloseMessage: <unscanned extends string>(unscanned: unscanned) => `Unmatched )${unscanned extends "" ? "" : ` before ${unscanned}`}`;
|
|
5
|
-
export type writeUnmatchedGroupCloseMessage<unscanned extends string> = `Unmatched )${unscanned extends "" ? "" : ` before ${unscanned}`}`;
|
|
6
|
-
export declare const unclosedGroupMessage = "Missing )";
|
|
7
|
-
export type unclosedGroupMessage = typeof unclosedGroupMessage;
|
|
8
|
-
export declare const writeOpenRangeMessage: <min extends `${number}`, comparator extends ">" | ">=">(min: min, comparator: comparator) => `Left bounds are only valid when paired with right bounds (try ...${comparator}${min})`;
|
|
9
|
-
export type writeOpenRangeMessage<min extends NumberLiteral, comparator extends MinComparator> = `Left bounds are only valid when paired with right bounds (try ...${comparator}${min})`;
|
|
10
|
-
export type writeUnpairableComparatorMessage<comparator extends Scanner.Comparator> = `Left-bounded expressions must specify their limits using < or <= (was ${comparator})`;
|
|
11
|
-
export declare const writeUnpairableComparatorMessage: <comparator extends ">" | "<" | ">=" | "<=" | "==">(comparator: comparator) => `Left-bounded expressions must specify their limits using < or <= (was ${comparator})`;
|
|
12
|
-
export declare const writeMultipleLeftBoundsMessage: <openLimit extends `${number}`, openComparator extends ">" | ">=", limit extends `${number}`, comparator extends ">" | ">=">(openLimit: openLimit, openComparator: openComparator, limit: limit, comparator: comparator) => `An expression may have at most one left bound (parsed ${openLimit}${{
|
|
13
|
-
readonly "<": ">";
|
|
14
|
-
readonly ">": "<";
|
|
15
|
-
readonly "<=": ">=";
|
|
16
|
-
readonly ">=": "<=";
|
|
17
|
-
readonly "==": "==";
|
|
18
|
-
}[openComparator]}, ${limit}${{
|
|
19
|
-
readonly "<": ">";
|
|
20
|
-
readonly ">": "<";
|
|
21
|
-
readonly "<=": ">=";
|
|
22
|
-
readonly ">=": "<=";
|
|
23
|
-
readonly "==": "==";
|
|
24
|
-
}[comparator]})`;
|
|
25
|
-
export type writeMultipleLeftBoundsMessage<openLimit extends NumberLiteral, openComparator extends MinComparator, limit extends NumberLiteral, comparator extends MinComparator> = `An expression may have at most one left bound (parsed ${openLimit}${Scanner.InvertedComparators[openComparator]}, ${limit}${Scanner.InvertedComparators[comparator]})`;
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import type { MaxComparator, MinComparator } from "../../../nodes/rules/range.js";
|
|
2
|
-
import type { defined, error } from "../../../utils/generics.js";
|
|
3
|
-
import type { NumberLiteral } from "../../../utils/numericLiterals.js";
|
|
4
|
-
import type { Scanner } from "../shift/scanner.js";
|
|
5
|
-
import type { unclosedGroupMessage, writeMultipleLeftBoundsMessage, writeOpenRangeMessage, writeUnmatchedGroupCloseMessage, writeUnpairableComparatorMessage } from "./shared.js";
|
|
6
|
-
export type StaticState = {
|
|
7
|
-
root: unknown;
|
|
8
|
-
branches: BranchState;
|
|
9
|
-
groups: BranchState[];
|
|
10
|
-
scanned: string;
|
|
11
|
-
unscanned: string;
|
|
12
|
-
};
|
|
13
|
-
type StaticOpenLeftBound = {
|
|
14
|
-
limit: NumberLiteral;
|
|
15
|
-
comparator: MinComparator;
|
|
16
|
-
};
|
|
17
|
-
type BranchState = {
|
|
18
|
-
range: StaticOpenLeftBound | undefined;
|
|
19
|
-
"&": unknown;
|
|
20
|
-
"|": unknown;
|
|
21
|
-
};
|
|
22
|
-
export declare namespace state {
|
|
23
|
-
export type initialize<def extends string> = from<{
|
|
24
|
-
root: undefined;
|
|
25
|
-
branches: initialBranches;
|
|
26
|
-
groups: [];
|
|
27
|
-
scanned: "";
|
|
28
|
-
unscanned: def;
|
|
29
|
-
}>;
|
|
30
|
-
type initialBranches = branchesFrom<{
|
|
31
|
-
range: undefined;
|
|
32
|
-
"&": undefined;
|
|
33
|
-
"|": undefined;
|
|
34
|
-
}>;
|
|
35
|
-
type updateScanned<previousScanned extends string, previousUnscanned extends string, updatedUnscanned extends string> = previousUnscanned extends `${infer justScanned}${updatedUnscanned}` ? `${previousScanned}${justScanned}` : previousScanned;
|
|
36
|
-
export type setRoot<s extends StaticState, root, unscanned extends string> = from<{
|
|
37
|
-
root: root;
|
|
38
|
-
branches: s["branches"];
|
|
39
|
-
groups: s["groups"];
|
|
40
|
-
scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
|
|
41
|
-
unscanned: unscanned;
|
|
42
|
-
}>;
|
|
43
|
-
export type reduceBranch<s extends StaticState, token extends Scanner.BranchToken, unscanned extends string> = s["branches"]["range"] extends {} ? openRangeError<s["branches"]["range"]> : from<{
|
|
44
|
-
root: undefined;
|
|
45
|
-
branches: {
|
|
46
|
-
range: undefined;
|
|
47
|
-
"&": token extends "&" ? mergeToIntersection<s> : undefined;
|
|
48
|
-
"|": token extends "|" ? mergeToUnion<s> : s["branches"]["|"];
|
|
49
|
-
};
|
|
50
|
-
groups: s["groups"];
|
|
51
|
-
scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
|
|
52
|
-
unscanned: unscanned;
|
|
53
|
-
}>;
|
|
54
|
-
export type reduceLeftBound<s extends StaticState, limit extends NumberLiteral, comparator extends Scanner.Comparator, unscanned extends string> = comparator extends "<" | "<=" ? s["branches"]["range"] extends {} ? error<writeMultipleLeftBoundsMessage<s["branches"]["range"]["limit"], s["branches"]["range"]["comparator"], limit, Scanner.InvertedComparators[comparator]>> : from<{
|
|
55
|
-
root: undefined;
|
|
56
|
-
branches: {
|
|
57
|
-
range: {
|
|
58
|
-
limit: limit;
|
|
59
|
-
comparator: Scanner.InvertedComparators[comparator];
|
|
60
|
-
};
|
|
61
|
-
"&": s["branches"]["&"];
|
|
62
|
-
"|": s["branches"]["|"];
|
|
63
|
-
};
|
|
64
|
-
groups: s["groups"];
|
|
65
|
-
scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
|
|
66
|
-
unscanned: unscanned;
|
|
67
|
-
}> : error<writeUnpairableComparatorMessage<comparator>>;
|
|
68
|
-
export type reduceRange<s extends StaticState, minLimit extends NumberLiteral, minComparator extends MinComparator, maxComparator extends MaxComparator, maxLimit extends NumberLiteral, unscanned extends string> = state.from<{
|
|
69
|
-
root: [minLimit, minComparator, [s["root"], maxComparator, maxLimit]];
|
|
70
|
-
branches: {
|
|
71
|
-
range: undefined;
|
|
72
|
-
"&": s["branches"]["&"];
|
|
73
|
-
"|": s["branches"]["|"];
|
|
74
|
-
};
|
|
75
|
-
groups: s["groups"];
|
|
76
|
-
scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
|
|
77
|
-
unscanned: unscanned;
|
|
78
|
-
}>;
|
|
79
|
-
export type reduceSingleBound<s extends StaticState, comparator extends Scanner.Comparator, limit extends NumberLiteral, unscanned extends string> = state.from<{
|
|
80
|
-
root: [s["root"], comparator, limit];
|
|
81
|
-
branches: {
|
|
82
|
-
range: undefined;
|
|
83
|
-
"&": s["branches"]["&"];
|
|
84
|
-
"|": s["branches"]["|"];
|
|
85
|
-
};
|
|
86
|
-
groups: s["groups"];
|
|
87
|
-
scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
|
|
88
|
-
unscanned: unscanned;
|
|
89
|
-
}>;
|
|
90
|
-
type mergeToUnion<s extends StaticState> = s["branches"]["|"] extends undefined ? mergeToIntersection<s> : [s["branches"]["|"], "|", mergeToIntersection<s>];
|
|
91
|
-
type mergeToIntersection<s extends StaticState> = s["branches"]["&"] extends undefined ? s["root"] : [s["branches"]["&"], "&", s["root"]];
|
|
92
|
-
type popGroup<stack extends BranchState[], top extends BranchState> = [
|
|
93
|
-
...stack,
|
|
94
|
-
top
|
|
95
|
-
];
|
|
96
|
-
export type finalizeGroup<s extends StaticState, unscanned extends string> = s["branches"]["range"] extends {} ? openRangeError<s["branches"]["range"]> : s["groups"] extends popGroup<infer stack, infer top> ? from<{
|
|
97
|
-
groups: stack;
|
|
98
|
-
branches: top;
|
|
99
|
-
root: mergeToUnion<s>;
|
|
100
|
-
scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
|
|
101
|
-
unscanned: unscanned;
|
|
102
|
-
}> : error<writeUnmatchedGroupCloseMessage<unscanned>>;
|
|
103
|
-
export type reduceGroupOpen<s extends StaticState, unscanned extends string> = from<{
|
|
104
|
-
groups: [...s["groups"], s["branches"]];
|
|
105
|
-
branches: initialBranches;
|
|
106
|
-
root: undefined;
|
|
107
|
-
scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
|
|
108
|
-
unscanned: unscanned;
|
|
109
|
-
}>;
|
|
110
|
-
export type finalize<s extends StaticState> = s["groups"] extends [] ? s["branches"]["range"] extends {} ? openRangeError<s["branches"]["range"]> : from<{
|
|
111
|
-
root: mergeToUnion<s>;
|
|
112
|
-
groups: s["groups"];
|
|
113
|
-
branches: initialBranches;
|
|
114
|
-
scanned: s["scanned"];
|
|
115
|
-
unscanned: Scanner.finalized;
|
|
116
|
-
}> : error<unclosedGroupMessage>;
|
|
117
|
-
type openRangeError<range extends defined<BranchState["range"]>> = error<writeOpenRangeMessage<range["limit"], range["comparator"]>>;
|
|
118
|
-
export type previousOperator<s extends StaticState> = s["branches"]["range"] extends {} ? s["branches"]["range"]["comparator"] : s["branches"]["&"] extends {} ? "&" : s["branches"]["|"] extends {} ? "|" : undefined;
|
|
119
|
-
export type scanTo<s extends StaticState, unscanned extends string> = from<{
|
|
120
|
-
root: s["root"];
|
|
121
|
-
branches: s["branches"];
|
|
122
|
-
groups: s["groups"];
|
|
123
|
-
scanned: updateScanned<s["scanned"], s["unscanned"], unscanned>;
|
|
124
|
-
unscanned: unscanned;
|
|
125
|
-
}>;
|
|
126
|
-
export type from<s extends StaticState> = s;
|
|
127
|
-
export type branchesFrom<b extends BranchState> = b;
|
|
128
|
-
export {};
|
|
129
|
-
}
|
|
130
|
-
export {};
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { error, tailOfString } from "../../../../utils/generics.js";
|
|
2
|
-
import type { DynamicState } from "../../reduce/dynamic.js";
|
|
3
|
-
import type { state, StaticState } from "../../reduce/static.js";
|
|
4
|
-
import type { Scanner } from "../scanner.js";
|
|
5
|
-
export type StringLiteral<Text extends string = string> = DoubleQuotedStringLiteral<Text> | SingleQuotedStringLiteral<Text>;
|
|
6
|
-
export type DoubleQuotedStringLiteral<Text extends string = string> = `"${Text}"`;
|
|
7
|
-
export type SingleQuotedStringLiteral<Text extends string = string> = `'${Text}'`;
|
|
8
|
-
export declare const parseEnclosed: (s: DynamicState, enclosing: EnclosingChar) => undefined;
|
|
9
|
-
export type parseEnclosed<s extends StaticState, enclosing extends EnclosingChar, unscanned extends string> = Scanner.shiftUntil<unscanned, enclosing> extends Scanner.shiftResult<infer scanned, infer nextUnscanned> ? nextUnscanned extends "" ? error<writeUnterminatedEnclosedMessage<scanned, enclosing>> : state.setRoot<s, `${enclosing}${scanned}${enclosing}`, tailOfString<nextUnscanned>> : never;
|
|
10
|
-
export declare const enclosingChar: {
|
|
11
|
-
"'": number;
|
|
12
|
-
'"': number;
|
|
13
|
-
"/": number;
|
|
14
|
-
};
|
|
15
|
-
export type EnclosingChar = keyof typeof enclosingChar;
|
|
16
|
-
declare const enclosingCharDescriptions: {
|
|
17
|
-
readonly '"': "double-quote";
|
|
18
|
-
readonly "'": "single-quote";
|
|
19
|
-
readonly "/": "forward slash";
|
|
20
|
-
};
|
|
21
|
-
type enclosingCharDescriptions = typeof enclosingCharDescriptions;
|
|
22
|
-
export declare const writeUnterminatedEnclosedMessage: <fragment extends string, enclosing extends "/" | "'" | "\"">(fragment: fragment, enclosing: enclosing) => `${enclosing}${fragment} requires a closing ${{
|
|
23
|
-
readonly '"': "double-quote";
|
|
24
|
-
readonly "'": "single-quote";
|
|
25
|
-
readonly "/": "forward slash";
|
|
26
|
-
}[enclosing]}`;
|
|
27
|
-
type writeUnterminatedEnclosedMessage<fragment extends string, enclosing extends EnclosingChar> = `${enclosing}${fragment} requires a closing ${enclosingCharDescriptions[enclosing]}`;
|
|
28
|
-
export {};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { error, stringKeyOf } from "../../../../utils/generics.js";
|
|
2
|
-
import type { DynamicState } from "../../reduce/dynamic.js";
|
|
3
|
-
import type { state, StaticState } from "../../reduce/static.js";
|
|
4
|
-
import type { Scanner } from "../scanner.js";
|
|
5
|
-
import type { EnclosingChar } from "./enclosed.js";
|
|
6
|
-
import { parseEnclosed } from "./enclosed.js";
|
|
7
|
-
import { parseUnenclosed } from "./unenclosed.js";
|
|
8
|
-
export declare const parseOperand: (s: DynamicState) => void;
|
|
9
|
-
export type parseOperand<s extends StaticState, $> = s["unscanned"] extends Scanner.shift<infer lookahead, infer unscanned> ? lookahead extends "(" ? state.reduceGroupOpen<s, unscanned> : lookahead extends EnclosingChar ? parseEnclosed<s, lookahead, unscanned> : lookahead extends " " ? parseOperand<state.scanTo<s, unscanned>, $> : parseUnenclosed<s, $> : error<`${s["scanned"]}${stringKeyOf<$>}`>;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { error } from "../../../../utils/generics.js";
|
|
2
|
-
import type { BigintLiteral, NumberLiteral } from "../../../../utils/numericLiterals.js";
|
|
3
|
-
import type { DynamicState } from "../../reduce/dynamic.js";
|
|
4
|
-
import type { state, StaticState } from "../../reduce/static.js";
|
|
5
|
-
import type { Scanner } from "../scanner.js";
|
|
6
|
-
export declare const parseUnenclosed: (s: DynamicState) => void;
|
|
7
|
-
export type parseUnenclosed<s extends StaticState, $> = Scanner.shiftUntilNextTerminator<s["unscanned"]> extends Scanner.shiftResult<infer scanned, infer nextUnscanned> ? tryResolve<s, scanned, $> extends infer result ? result extends error<infer message> ? error<message> : state.setRoot<s, result, nextUnscanned> : never : never;
|
|
8
|
-
type tryResolve<s extends StaticState, token extends string, $> = token extends keyof $ ? token : token extends NumberLiteral ? token : token extends BigintLiteral ? token : possibleCompletions<s, token, $>;
|
|
9
|
-
export type possibleCompletions<s extends StaticState, token extends string, $> = Extract<keyof $, `${token}${string}`> extends never ? error<writeUnresolvableMessage<token>> : error<`${s["scanned"]}${Extract<keyof $, `${token}${string}`>}`>;
|
|
10
|
-
export declare const writeUnresolvableMessage: <token extends string>(token: token) => `'${token}' is unresolvable`;
|
|
11
|
-
type writeUnresolvableMessage<token extends string> = `'${token}' is unresolvable`;
|
|
12
|
-
export declare const writeMissingOperandMessage: <s extends DynamicState>(s: s) => string;
|
|
13
|
-
export type writeMissingOperandMessage<s extends StaticState, operator extends Scanner.InfixToken | undefined = state.previousOperator<s>> = operator extends {} ? writeMissingRightOperandMessage<operator, s["unscanned"]> : writeExpressionExpectedMessage<s["unscanned"]>;
|
|
14
|
-
export type writeMissingRightOperandMessage<token extends Scanner.InfixToken, unscanned extends string> = `Token '${token}' requires a right operand${unscanned extends "" ? "" : ` before '${unscanned}'`}`;
|
|
15
|
-
export declare const writeMissingRightOperandMessage: <token extends Scanner.InfixToken, unscanned extends string>(token: token, unscanned: unscanned) => `Token '${token}' requires a right operand${unscanned extends "" ? "" : ` before '${unscanned}'`}`;
|
|
16
|
-
export declare const writeExpressionExpectedMessage: <unscanned extends string>(unscanned: unscanned) => string;
|
|
17
|
-
export type writeExpressionExpectedMessage<unscanned extends string> = `Expected an expression${unscanned extends "" ? "" : ` before '${unscanned}'`}`;
|
|
18
|
-
export {};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { MaxComparator, Range } from "../../../../nodes/rules/range.js";
|
|
2
|
-
import type { error } from "../../../../utils/generics.js";
|
|
3
|
-
import type { NumberLiteral } from "../../../../utils/numericLiterals.js";
|
|
4
|
-
import { tryParseWellFormedNumber } from "../../../../utils/numericLiterals.js";
|
|
5
|
-
import type { DynamicState } from "../../reduce/dynamic.js";
|
|
6
|
-
import { writeUnpairableComparatorMessage } from "../../reduce/shared.js";
|
|
7
|
-
import type { state, StaticState } from "../../reduce/static.js";
|
|
8
|
-
import { Scanner } from "../scanner.js";
|
|
9
|
-
export declare const parseBound: (s: DynamicState, start: Scanner.ComparatorStartChar) => void;
|
|
10
|
-
export type parseBound<s extends StaticState, start extends Scanner.ComparatorStartChar, unscanned extends string> = shiftComparator<start, unscanned> extends infer shiftResultOrError ? shiftResultOrError extends Scanner.shiftResult<infer comparator extends Scanner.Comparator, infer nextUnscanned> ? s["root"] extends NumberLiteral ? state.reduceLeftBound<s, s["root"], comparator, nextUnscanned> : parseRightBound<s, comparator, nextUnscanned> : shiftResultOrError : never;
|
|
11
|
-
declare const shiftComparator: (s: DynamicState, start: Scanner.ComparatorStartChar) => Scanner.Comparator;
|
|
12
|
-
type shiftComparator<start extends Scanner.ComparatorStartChar, unscanned extends string> = unscanned extends `=${infer nextUnscanned}` ? [`${start}=`, nextUnscanned] : start extends Scanner.OneCharComparator ? [start, unscanned] : error<singleEqualsMessage>;
|
|
13
|
-
export declare const singleEqualsMessage = "= is not a valid comparator. Use == to check for equality";
|
|
14
|
-
type singleEqualsMessage = typeof singleEqualsMessage;
|
|
15
|
-
export declare const parseRightBound: (s: DynamicState, comparator: Scanner.Comparator) => void;
|
|
16
|
-
export type parseRightBound<s extends StaticState, comparator extends Scanner.Comparator, unscanned extends string> = Scanner.shiftUntilNextTerminator<unscanned> extends Scanner.shiftResult<infer scanned, infer nextUnscanned> ? tryParseWellFormedNumber<scanned, writeInvalidLimitMessage<comparator, scanned>> extends infer limit ? limit extends number ? s["branches"]["range"] extends {} ? comparator extends MaxComparator ? state.reduceRange<s, s["branches"]["range"]["limit"], s["branches"]["range"]["comparator"], comparator, `${limit}`, nextUnscanned> : error<writeUnpairableComparatorMessage<comparator>> : state.reduceSingleBound<s, comparator, `${limit}`, nextUnscanned> : error<limit & string> : never : never;
|
|
17
|
-
export declare const writeInvalidLimitMessage: <comparator extends ">" | "<" | ">=" | "<=" | "==", limit extends string>(comparator: comparator, limit: limit) => `Comparator ${comparator} must be followed by a number literal (was '${limit}')`;
|
|
18
|
-
export type writeInvalidLimitMessage<comparator extends Scanner.Comparator, limit extends string> = `Comparator ${comparator} must be followed by a number literal (was '${limit}')`;
|
|
19
|
-
export declare const writeEmptyRangeMessage: (range: Range) => string;
|
|
20
|
-
export type BoundableDomain = "string" | "number" | "object";
|
|
21
|
-
export {};
|