arktype 1.0.28-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 -18
- 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 -209
- 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,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @keywords keywords: {"any": "any",
|
|
3
|
-
"bigint": "a bigint",
|
|
4
|
-
"boolean": "a boolean",
|
|
5
|
-
"false": "false",
|
|
6
|
-
"never": "never",
|
|
7
|
-
"null": "null",
|
|
8
|
-
"number": "a number",
|
|
9
|
-
"object": "an object",
|
|
10
|
-
"string": "a string",
|
|
11
|
-
"symbol": "a symbol",
|
|
12
|
-
"true": "true",
|
|
13
|
-
"unknown": "unknown",
|
|
14
|
-
"void": "void",
|
|
15
|
-
"undefined": "undefined"}
|
|
16
|
-
* @docgenScope
|
|
17
|
-
* @docgenTable
|
|
18
|
-
*/
|
|
19
|
-
export declare const tsKeywordsScope: import("./scope.js").Scope<[{
|
|
20
|
-
any: any;
|
|
21
|
-
bigint: bigint;
|
|
22
|
-
boolean: boolean;
|
|
23
|
-
false: false;
|
|
24
|
-
never: never;
|
|
25
|
-
null: null;
|
|
26
|
-
number: number;
|
|
27
|
-
object: object;
|
|
28
|
-
string: string;
|
|
29
|
-
symbol: symbol;
|
|
30
|
-
true: true;
|
|
31
|
-
unknown: unknown;
|
|
32
|
-
void: void;
|
|
33
|
-
undefined: undefined;
|
|
34
|
-
}, {}, false]>;
|
|
35
|
-
export declare const tsKeywords: import("./scope.js").Space<{
|
|
36
|
-
any: any;
|
|
37
|
-
bigint: bigint;
|
|
38
|
-
boolean: boolean;
|
|
39
|
-
false: false;
|
|
40
|
-
never: never;
|
|
41
|
-
null: null;
|
|
42
|
-
number: number;
|
|
43
|
-
object: object;
|
|
44
|
-
string: string;
|
|
45
|
-
symbol: symbol;
|
|
46
|
-
true: true;
|
|
47
|
-
unknown: unknown;
|
|
48
|
-
void: void;
|
|
49
|
-
undefined: undefined;
|
|
50
|
-
}>;
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import type { Node, TraversalNode } from "../nodes/node.js";
|
|
2
|
-
import type { ParsedMorph } from "../parse/ast/morph.js";
|
|
3
|
-
import type { as, inferDefinition, validateDefinition } from "../parse/definition.js";
|
|
4
|
-
import type { ProblemOptions } from "../traverse/problems.js";
|
|
5
|
-
import type { CheckResult } from "../traverse/traverse.js";
|
|
6
|
-
import type { defer, evaluate } from "../utils/generics.js";
|
|
7
|
-
import type { BuiltinClass } from "../utils/objectKinds.js";
|
|
8
|
-
import type { Expressions } from "./expressions.js";
|
|
9
|
-
import type { Scope } from "./scope.js";
|
|
10
|
-
export type TypeParser<$> = {
|
|
11
|
-
<def>(def: validateDefinition<def, $>): parseType<def, $>;
|
|
12
|
-
<def>(def: validateDefinition<def, $>, opts: TypeOptions): parseType<def, $>;
|
|
13
|
-
} & TypeParserProps<$>;
|
|
14
|
-
export type TypeParserProps<$> = {
|
|
15
|
-
from: Expressions<$>["node"];
|
|
16
|
-
};
|
|
17
|
-
export type parseType<def, $> = [def] extends [validateDefinition<def, $>] ? Type<inferDefinition<def, $>> : Type<never>;
|
|
18
|
-
type TypeRoot<t = unknown> = evaluate<{
|
|
19
|
-
[as]: t;
|
|
20
|
-
infer: asOut<t>;
|
|
21
|
-
inferIn: asIn<t>;
|
|
22
|
-
allows: (data: unknown) => data is asIn<t>;
|
|
23
|
-
assert: (data: unknown) => asOut<t>;
|
|
24
|
-
node: Node;
|
|
25
|
-
flat: TraversalNode;
|
|
26
|
-
qualifiedName: QualifiedTypeName;
|
|
27
|
-
definition: unknown;
|
|
28
|
-
scope: Scope;
|
|
29
|
-
includesMorph: boolean;
|
|
30
|
-
config: TypeConfig;
|
|
31
|
-
}>;
|
|
32
|
-
export type KeyCheckKind = "loose" | "strict" | "distilled";
|
|
33
|
-
export type TypeOptions = evaluate<{
|
|
34
|
-
keys?: KeyCheckKind;
|
|
35
|
-
} & ProblemOptions>;
|
|
36
|
-
export type TypeConfig = TypeOptions;
|
|
37
|
-
export declare const initializeType: (name: string, definition: unknown, config: TypeConfig, scope: Scope) => ((data: unknown) => CheckResult<unknown>) & {
|
|
38
|
-
infer: unknown;
|
|
39
|
-
inferIn: unknown;
|
|
40
|
-
allows: (data: unknown) => data is unknown;
|
|
41
|
-
assert: (data: unknown) => unknown;
|
|
42
|
-
node: Node;
|
|
43
|
-
flat: TraversalNode;
|
|
44
|
-
qualifiedName: QualifiedTypeName;
|
|
45
|
-
definition: unknown;
|
|
46
|
-
scope: Scope;
|
|
47
|
-
includesMorph: boolean;
|
|
48
|
-
config: {
|
|
49
|
-
keys?: KeyCheckKind;
|
|
50
|
-
mustBe?: import("../traverse/problems.js").MustBeWriter<import("../traverse/problems.js").ProblemCode>;
|
|
51
|
-
writeReason?: import("../traverse/problems.js").ReasonWriter<import("../traverse/problems.js").ProblemCode>;
|
|
52
|
-
addContext?: import("../traverse/problems.js").ContextWriter;
|
|
53
|
-
};
|
|
54
|
-
[as]: unknown;
|
|
55
|
-
};
|
|
56
|
-
export declare const isType: (value: unknown) => value is Type<unknown>;
|
|
57
|
-
export type Type<t = unknown> = defer<Checker<t> & TypeRoot<t>>;
|
|
58
|
-
export type Checker<t> = (data: unknown) => CheckResult<asOut<t>>;
|
|
59
|
-
export type QualifiedTypeName = `${string}.${string}`;
|
|
60
|
-
export type AnonymousTypeName = `λ${string}`;
|
|
61
|
-
export declare const isAnonymousName: (name: string) => name is `\u03BB${string}`;
|
|
62
|
-
export type asIn<t> = [t, asIo<t, "out">] extends [asIo<t, "out">, t] ? t : asIo<t, "in">;
|
|
63
|
-
export type asOut<t> = [t, asIo<t, "out">] extends [asIo<t, "out">, t] ? t : asIo<t, "out">;
|
|
64
|
-
type asIo<t, io extends "in" | "out"> = t extends ParsedMorph<infer i, infer o> ? io extends "in" ? i : o : t extends object ? t extends BuiltinClass | ((...args: any[]) => any) ? t : {
|
|
65
|
-
[k in keyof t]: asIo<t[k], io>;
|
|
66
|
-
} : t;
|
|
67
|
-
export {};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
type DayDelimiter = "." | "/" | "-";
|
|
2
|
-
type DayPart = DayPatterns[PartKey];
|
|
3
|
-
type PartKey = keyof DayPatterns;
|
|
4
|
-
type DayPatterns = {
|
|
5
|
-
y: "yy" | "yyyy";
|
|
6
|
-
m: "mm" | "m";
|
|
7
|
-
d: "dd" | "d";
|
|
8
|
-
};
|
|
9
|
-
type fragment<part extends DayPart, delimiter extends DayDelimiter> = `${delimiter}${part}` | "";
|
|
10
|
-
export type DayPattern<delimiter extends DayDelimiter = DayDelimiter> = {
|
|
11
|
-
[d in delimiter]: {
|
|
12
|
-
[k1 in keyof DayPatterns]: {
|
|
13
|
-
[k2 in Exclude<keyof DayPatterns, k1>]: `${DayPatterns[k1]}${fragment<DayPatterns[k2], d>}${fragment<DayPatterns[Exclude<keyof DayPatterns, k1 | k2>], d>}`;
|
|
14
|
-
}[Exclude<keyof DayPatterns, k1>];
|
|
15
|
-
}[keyof DayPatterns];
|
|
16
|
-
}[delimiter];
|
|
17
|
-
export type DateFormat = "iso8601" | DayPattern;
|
|
18
|
-
export type DateOptions = {
|
|
19
|
-
format?: DateFormat;
|
|
20
|
-
};
|
|
21
|
-
export declare const tryParseDate: (data: string, opts?: DateOptions) => Date | string;
|
|
22
|
-
export declare const parsedDate: import("../type.js").Type<(In: string) => import("../../parse/ast/morph.js").Out<Date>>;
|
|
23
|
-
export {};
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @keywords keywords: {
|
|
3
|
-
"alpha": "only letters",
|
|
4
|
-
"alphanumeric": "only letters and digits",
|
|
5
|
-
"lowercase": "only lowercase letters",
|
|
6
|
-
"uppercase": "only uppercase letters",
|
|
7
|
-
"creditCard": "a valid credit card number",
|
|
8
|
-
"email": "a valid email",
|
|
9
|
-
"uuid": "a valid UUID",
|
|
10
|
-
"parsedNumber": "a well-formed numeric string",
|
|
11
|
-
"parsedInteger": "a well-formed integer string",
|
|
12
|
-
"parsedDate": "a valid date",
|
|
13
|
-
"semver": "a valid semantic version",
|
|
14
|
-
"json": "a JSON-parsable string",
|
|
15
|
-
"integer": "an integer"
|
|
16
|
-
}
|
|
17
|
-
* @docgenScope
|
|
18
|
-
* @docgenTable
|
|
19
|
-
*/
|
|
20
|
-
export declare const validationScope: import("../scope.js").Scope<[{
|
|
21
|
-
alpha: string;
|
|
22
|
-
alphanumeric: string;
|
|
23
|
-
lowercase: string;
|
|
24
|
-
uppercase: string;
|
|
25
|
-
creditCard: string;
|
|
26
|
-
email: string;
|
|
27
|
-
uuid: string;
|
|
28
|
-
parsedNumber: (In: string) => import("../../parse/ast/morph.js").Out<number>;
|
|
29
|
-
parsedInteger: (In: string) => import("../../parse/ast/morph.js").Out<number>;
|
|
30
|
-
parsedDate: (In: string) => import("../../parse/ast/morph.js").Out<Date>;
|
|
31
|
-
semver: string;
|
|
32
|
-
json: (In: string) => import("../../parse/ast/morph.js").Out<unknown>;
|
|
33
|
-
integer: number;
|
|
34
|
-
}, {}, false]>;
|
|
35
|
-
export declare const validation: import("../scope.js").Space<{
|
|
36
|
-
alpha: string;
|
|
37
|
-
alphanumeric: string;
|
|
38
|
-
lowercase: string;
|
|
39
|
-
uppercase: string;
|
|
40
|
-
creditCard: string;
|
|
41
|
-
email: string;
|
|
42
|
-
uuid: string;
|
|
43
|
-
parsedNumber: (In: string) => import("../../parse/ast/morph.js").Out<number>;
|
|
44
|
-
parsedInteger: (In: string) => import("../../parse/ast/morph.js").Out<number>;
|
|
45
|
-
parsedDate: (In: string) => import("../../parse/ast/morph.js").Out<Date>;
|
|
46
|
-
semver: string;
|
|
47
|
-
json: (In: string) => import("../../parse/ast/morph.js").Out<unknown>;
|
|
48
|
-
integer: number;
|
|
49
|
-
}>;
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
import type { FlatBound } from "../nodes/rules/range.js";
|
|
2
|
-
import { DataWrapper } from "../utils/data.js";
|
|
3
|
-
import type { Domain } from "../utils/domains.js";
|
|
4
|
-
import type { arraySubclassToReadonly, constructor, evaluate, RegexLiteral } from "../utils/generics.js";
|
|
5
|
-
import type { DefaultObjectKind } from "../utils/objectKinds.js";
|
|
6
|
-
import { Path } from "../utils/paths.js";
|
|
7
|
-
import type { ConstrainedRuleTraversalData, TraversalState } from "./traverse.js";
|
|
8
|
-
export declare class ArkTypeError extends TypeError {
|
|
9
|
-
cause: Problems;
|
|
10
|
-
constructor(problems: Problems);
|
|
11
|
-
}
|
|
12
|
-
export declare class Problem<code extends ProblemCode = ProblemCode> {
|
|
13
|
-
code: code;
|
|
14
|
-
path: Path;
|
|
15
|
-
private data;
|
|
16
|
-
private source;
|
|
17
|
-
private writers;
|
|
18
|
-
parts?: Problem[];
|
|
19
|
-
constructor(code: code, path: Path, data: ProblemData<code>, source: ProblemSource<code>, writers: ProblemWriters<code>);
|
|
20
|
-
toString(): string;
|
|
21
|
-
get message(): string;
|
|
22
|
-
get reason(): string;
|
|
23
|
-
get mustBe(): string;
|
|
24
|
-
}
|
|
25
|
-
export type AddProblemOptions<data = unknown> = {
|
|
26
|
-
data?: data;
|
|
27
|
-
path?: string[];
|
|
28
|
-
};
|
|
29
|
-
declare class ProblemArray extends Array<Problem> {
|
|
30
|
-
#private;
|
|
31
|
-
byPath: Record<string, Problem>;
|
|
32
|
-
count: number;
|
|
33
|
-
constructor(state: TraversalState);
|
|
34
|
-
mustBe(description: string, opts?: AddProblemOptions): Problem<ProblemCode>;
|
|
35
|
-
add<code extends ProblemCode>(code: code, source: ProblemSource<code>, opts?: AddProblemOptions<ProblemData<code>>): Problem;
|
|
36
|
-
addProblem(problem: Problem): void;
|
|
37
|
-
get summary(): string;
|
|
38
|
-
toString(): string;
|
|
39
|
-
throw(): never;
|
|
40
|
-
}
|
|
41
|
-
export declare const Problems: new (state: TraversalState) => Problems;
|
|
42
|
-
export type Problems = arraySubclassToReadonly<ProblemArray>;
|
|
43
|
-
export declare const domainsToDescriptions: (domains: Domain[]) => ("boolean" | "undefined" | "null" | "a bigint" | "a number" | "an object" | "a string" | "a symbol")[];
|
|
44
|
-
export declare const objectKindsToDescriptions: (kinds: DefaultObjectKind[]) => ("an object" | "an array" | "a function" | "a Date" | "a RegExp" | "an Error" | "a Map" | "a Set" | "a String object" | "a Number object" | "a Boolean object" | "a Promise" | "a WeakMap" | "a WeakSet")[];
|
|
45
|
-
export declare const describeBranches: (descriptions: string[]) => string;
|
|
46
|
-
type ProblemSources = {
|
|
47
|
-
divisor: number;
|
|
48
|
-
class: constructor;
|
|
49
|
-
domain: Domain;
|
|
50
|
-
missing: undefined;
|
|
51
|
-
extraneous: unknown;
|
|
52
|
-
bound: FlatBound;
|
|
53
|
-
regex: RegexLiteral;
|
|
54
|
-
value: unknown;
|
|
55
|
-
multi: Problem[];
|
|
56
|
-
branches: readonly Problem[];
|
|
57
|
-
custom: string;
|
|
58
|
-
cases: string[];
|
|
59
|
-
};
|
|
60
|
-
export type ProblemCode = evaluate<keyof ProblemSources>;
|
|
61
|
-
export type ProblemSource<code extends ProblemCode = ProblemCode> = ProblemSources[code];
|
|
62
|
-
type ProblemDataByCode = {
|
|
63
|
-
[code in ProblemCode]: code extends keyof ConstrainedRuleTraversalData ? ConstrainedRuleTraversalData[code] : unknown;
|
|
64
|
-
};
|
|
65
|
-
export type ProblemData<code extends ProblemCode = ProblemCode> = ProblemDataByCode[code];
|
|
66
|
-
export type MustBeWriter<code extends ProblemCode> = string | ((source: ProblemSources[code]) => string);
|
|
67
|
-
export type ReasonWriter<code extends ProblemCode = ProblemCode> = (mustBe: string, data: DataWrapper<code extends keyof ConstrainedRuleTraversalData ? ConstrainedRuleTraversalData[code] : unknown>) => string;
|
|
68
|
-
export type ContextWriter = (reason: string, path: Path) => string;
|
|
69
|
-
export declare const problemCodes: readonly ProblemCode[];
|
|
70
|
-
export declare const defaultProblemWriters: ProblemWritersByCode;
|
|
71
|
-
export declare const compileProblemWriters: (input: ProblemsConfig | undefined) => ProblemWritersByCode;
|
|
72
|
-
export type ProblemOptions<code extends ProblemCode = ProblemCode> = {
|
|
73
|
-
mustBe?: MustBeWriter<code>;
|
|
74
|
-
writeReason?: ReasonWriter<code>;
|
|
75
|
-
addContext?: ContextWriter;
|
|
76
|
-
};
|
|
77
|
-
export type ProblemsConfig = evaluate<{
|
|
78
|
-
writeReason?: ReasonWriter;
|
|
79
|
-
addContext?: ContextWriter;
|
|
80
|
-
} & ProblemsConfigByCode>;
|
|
81
|
-
export type ProblemsConfigByCode = {
|
|
82
|
-
[code in ProblemCode]?: ProblemOptions<code>;
|
|
83
|
-
};
|
|
84
|
-
export type ProblemWritersByCode = {
|
|
85
|
-
[code in ProblemCode]: ProblemWriters<code>;
|
|
86
|
-
};
|
|
87
|
-
export type ProblemWriters<code extends ProblemCode = ProblemCode> = Required<ProblemOptions<code>>;
|
|
88
|
-
export {};
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import type { ConfigEntry, TraversalEntry, TraversalKey, TraversalNode, TraversalValue } from "../nodes/node.js";
|
|
2
|
-
import type { TraversalProp } from "../nodes/rules/props.js";
|
|
3
|
-
import type { Scope } from "../scopes/scope.js";
|
|
4
|
-
import type { Type, TypeConfig } from "../scopes/type.js";
|
|
5
|
-
import type { SizedData } from "../utils/data.js";
|
|
6
|
-
import type { extend, stringKeyOf, xor } from "../utils/generics.js";
|
|
7
|
-
import { Path } from "../utils/paths.js";
|
|
8
|
-
import type { ProblemCode, ProblemWriters } from "./problems.js";
|
|
9
|
-
import { Problems } from "./problems.js";
|
|
10
|
-
export declare const traverseRoot: (t: Type, data: unknown) => CheckResult<unknown>;
|
|
11
|
-
export type CheckResult<out = unknown> = xor<{
|
|
12
|
-
data: out;
|
|
13
|
-
}, {
|
|
14
|
-
problems: Problems;
|
|
15
|
-
}>;
|
|
16
|
-
export declare class TraversalState<data = unknown> {
|
|
17
|
-
#private;
|
|
18
|
-
data: data;
|
|
19
|
-
type: Type;
|
|
20
|
-
path: Path;
|
|
21
|
-
problems: Problems;
|
|
22
|
-
entriesToPrune: [data: Record<string, unknown>, key: string][];
|
|
23
|
-
failFast: boolean;
|
|
24
|
-
traversalConfig: TraversalConfig;
|
|
25
|
-
readonly rootScope: Scope;
|
|
26
|
-
constructor(data: data, type: Type);
|
|
27
|
-
getProblemConfig<code extends ProblemCode>(code: code): ProblemWriters<code>;
|
|
28
|
-
traverseConfig(configEntries: ConfigEntry[], node: TraversalNode): boolean;
|
|
29
|
-
traverseKey(key: stringKeyOf<this["data"]>, node: TraversalNode): boolean;
|
|
30
|
-
traverseResolution(name: string): boolean;
|
|
31
|
-
traverseBranches(branches: TraversalEntry[][]): boolean;
|
|
32
|
-
}
|
|
33
|
-
export type TraversalConfig = {
|
|
34
|
-
[k in keyof TypeConfig]-?: TypeConfig[k][];
|
|
35
|
-
};
|
|
36
|
-
export declare const traverse: (node: TraversalNode, state: TraversalState) => boolean;
|
|
37
|
-
export declare const checkEntries: (entries: TraversalEntry[], state: TraversalState) => boolean;
|
|
38
|
-
export declare const checkRequiredProp: (prop: TraversalProp, state: TraversalState<TraversableData>) => boolean;
|
|
39
|
-
export type ValidationTraversalKey = Exclude<TraversalKey, "morph">;
|
|
40
|
-
export type EntryChecker<k extends TraversalKey> = (constraint: TraversalValue<k>, state: TraversalState<RuleData<k>>) => boolean;
|
|
41
|
-
export type TraversableData = Record<string | number, unknown>;
|
|
42
|
-
export type ConstrainedRuleTraversalData = extend<{
|
|
43
|
-
[k in TraversalKey]?: unknown;
|
|
44
|
-
}, {
|
|
45
|
-
regex: string;
|
|
46
|
-
divisor: number;
|
|
47
|
-
bound: SizedData;
|
|
48
|
-
prerequisiteProp: TraversableData;
|
|
49
|
-
optionalProp: TraversableData;
|
|
50
|
-
requiredProp: TraversableData;
|
|
51
|
-
indexProp: TraversableData;
|
|
52
|
-
distilledProps: TraversableData;
|
|
53
|
-
strictProps: TraversableData;
|
|
54
|
-
}>;
|
|
55
|
-
export type RuleData<k extends TraversalKey> = k extends keyof ConstrainedRuleTraversalData ? ConstrainedRuleTraversalData[k] : unknown;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Can be used to allow arbitrarily chained property access and function calls.
|
|
3
|
-
* This is useful for expressions whose meaning is not attached to a value,
|
|
4
|
-
* e.g. to allow the extraction of types using typeof without depending on
|
|
5
|
-
* the existence of a real object that conforms to that type's structure:
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* const myType: MyType = chainableNoOpProxy
|
|
9
|
-
*
|
|
10
|
-
* // The following types are equivalent
|
|
11
|
-
* type ExtractedType = typeof myType.a.b.c
|
|
12
|
-
* type DirectlyExtractedType = MyType["a"]["b"]["c"]
|
|
13
|
-
*/
|
|
14
|
-
export declare const chainableNoOpProxy: any;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { domainOf } from "./domains.js";
|
|
2
|
-
export type SizedData = string | number | readonly unknown[];
|
|
3
|
-
export declare const sizeOf: (data: unknown) => number;
|
|
4
|
-
export declare const unitsOf: (data: unknown) => "" | "characters" | "items long";
|
|
5
|
-
export declare class DataWrapper<value = unknown> {
|
|
6
|
-
value: value;
|
|
7
|
-
constructor(value: value);
|
|
8
|
-
toString(): string;
|
|
9
|
-
get domain(): domainOf<value>;
|
|
10
|
-
get size(): number;
|
|
11
|
-
get units(): "" | "characters" | "items long";
|
|
12
|
-
get className(): any;
|
|
13
|
-
}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { evaluate, isTopType } from "./generics.js";
|
|
2
|
-
export declare const hasDomain: <data, domain extends Domain>(data: data, domain: domain) => data is data & inferDomain<domain>;
|
|
3
|
-
type DomainTypes = {
|
|
4
|
-
bigint: bigint;
|
|
5
|
-
boolean: boolean;
|
|
6
|
-
number: number;
|
|
7
|
-
object: object;
|
|
8
|
-
string: string;
|
|
9
|
-
symbol: symbol;
|
|
10
|
-
undefined: undefined;
|
|
11
|
-
null: null;
|
|
12
|
-
};
|
|
13
|
-
export type inferDomain<domain extends Domain> = Domain extends domain ? unknown : DomainTypes[domain];
|
|
14
|
-
export type Domain = evaluate<keyof DomainTypes>;
|
|
15
|
-
export type NullishDomain = "undefined" | "null";
|
|
16
|
-
export type NonNullishDomain = Exclude<Domain, NullishDomain>;
|
|
17
|
-
export type PrimitiveDomain = Exclude<Domain, "object">;
|
|
18
|
-
export type Primitive = inferDomain<PrimitiveDomain>;
|
|
19
|
-
export type domainOf<data> = isTopType<data> extends true ? Domain : data extends object ? "object" : data extends string ? "string" : data extends number ? "number" : data extends boolean ? "boolean" : data extends undefined ? "undefined" : data extends null ? "null" : data extends bigint ? "bigint" : data extends symbol ? "symbol" : never;
|
|
20
|
-
export declare const domainOf: <data>(data: data) => domainOf<data>;
|
|
21
|
-
/** Each domain's completion for the phrase "Must be _____" */
|
|
22
|
-
export declare const domainDescriptions: {
|
|
23
|
-
readonly bigint: "a bigint";
|
|
24
|
-
readonly boolean: "boolean";
|
|
25
|
-
readonly null: "null";
|
|
26
|
-
readonly number: "a number";
|
|
27
|
-
readonly object: "an object";
|
|
28
|
-
readonly string: "a string";
|
|
29
|
-
readonly symbol: "a symbol";
|
|
30
|
-
readonly undefined: "undefined";
|
|
31
|
-
};
|
|
32
|
-
export {};
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
export declare const asConst: <t>(t: { [k in keyof t]: t[k] extends [] | Literalable ? t[k] : t[k] extends infer T ? { [k_1 in keyof T]: t[k][k_1] extends [] | Literalable ? t[k][k_1] : t[k][k_1] extends infer T_1 ? { [k_2 in keyof T_1]: t[k][k_1][k_2] extends [] | Literalable ? t[k][k_1][k_2] : t[k][k_1][k_2] extends infer T_2 ? { [k_3 in keyof T_2]: t[k][k_1][k_2][k_3] extends [] | Literalable ? t[k][k_1][k_2][k_3] : t[k][k_1][k_2][k_3] extends infer T_3 ? { [k_4 in keyof T_3]: t[k][k_1][k_2][k_3][k_4] extends [] | Literalable ? t[k][k_1][k_2][k_3][k_4] : t[k][k_1][k_2][k_3][k_4] extends infer T_4 ? { [k_5 in keyof T_4]: t[k][k_1][k_2][k_3][k_4][k_5] extends [] | Literalable ? t[k][k_1][k_2][k_3][k_4][k_5] : t[k][k_1][k_2][k_3][k_4][k_5] extends infer T_5 ? { [k_6 in keyof T_5]: t[k][k_1][k_2][k_3][k_4][k_5][k_6] extends [] | Literalable ? t[k][k_1][k_2][k_3][k_4][k_5][k_6] : t[k][k_1][k_2][k_3][k_4][k_5][k_6] extends infer T_6 ? { [k_7 in keyof T_6]: t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7] extends [] | Literalable ? t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7] : t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7] extends infer T_7 ? { [k_8 in keyof T_7]: t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7][k_8] extends [] | Literalable ? t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7][k_8] : t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7][k_8] extends infer T_8 ? { [k_9 in keyof T_8]: t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7][k_8][k_9] extends [] | Literalable ? t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7][k_8][k_9] : t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7][k_8][k_9] extends infer T_9 ? { [k_10 in keyof T_9]: t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7][k_8][k_9][k_10] extends [] | Literalable ? t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7][k_8][k_9][k_10] : any; } : never; } : never; } : never; } : never; } : never; } : never; } : never; } : never; } : never; } : never; }) => { [k in keyof t]: t[k] extends [] | Literalable ? t[k] : t[k] extends infer T ? { [k_1 in keyof T]: t[k][k_1] extends [] | Literalable ? t[k][k_1] : t[k][k_1] extends infer T_1 ? { [k_2 in keyof T_1]: t[k][k_1][k_2] extends [] | Literalable ? t[k][k_1][k_2] : t[k][k_1][k_2] extends infer T_2 ? { [k_3 in keyof T_2]: t[k][k_1][k_2][k_3] extends [] | Literalable ? t[k][k_1][k_2][k_3] : t[k][k_1][k_2][k_3] extends infer T_3 ? { [k_4 in keyof T_3]: t[k][k_1][k_2][k_3][k_4] extends [] | Literalable ? t[k][k_1][k_2][k_3][k_4] : t[k][k_1][k_2][k_3][k_4] extends infer T_4 ? { [k_5 in keyof T_4]: t[k][k_1][k_2][k_3][k_4][k_5] extends [] | Literalable ? t[k][k_1][k_2][k_3][k_4][k_5] : t[k][k_1][k_2][k_3][k_4][k_5] extends infer T_5 ? { [k_6 in keyof T_5]: t[k][k_1][k_2][k_3][k_4][k_5][k_6] extends [] | Literalable ? t[k][k_1][k_2][k_3][k_4][k_5][k_6] : t[k][k_1][k_2][k_3][k_4][k_5][k_6] extends infer T_6 ? { [k_7 in keyof T_6]: t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7] extends [] | Literalable ? t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7] : t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7] extends infer T_7 ? { [k_8 in keyof T_7]: t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7][k_8] extends [] | Literalable ? t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7][k_8] : t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7][k_8] extends infer T_8 ? { [k_9 in keyof T_8]: t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7][k_8][k_9] extends [] | Literalable ? t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7][k_8][k_9] : t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7][k_8][k_9] extends infer T_9 ? { [k_10 in keyof T_9]: t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7][k_8][k_9][k_10] extends [] | Literalable ? t[k][k_1][k_2][k_3][k_4][k_5][k_6][k_7][k_8][k_9][k_10] : any; } : never; } : never; } : never; } : never; } : never; } : never; } : never; } : never; } : never; } : never; };
|
|
2
|
-
export type asConst<t> = castWithExclusion<t, asConstRecurse<t>, []>;
|
|
3
|
-
type asConstRecurse<t> = {
|
|
4
|
-
[k in keyof t]: t[k] extends Literalable | [] ? t[k] : asConstRecurse<t[k]>;
|
|
5
|
-
} & unknown;
|
|
6
|
-
export type castWithExclusion<t, castTo, excluded> = t extends excluded ? t : castTo;
|
|
7
|
-
export type Literalable = string | boolean | number | bigint;
|
|
8
|
-
export type evaluateObjectOrFunction<t> = isTopType<t> extends true ? t : t extends (...args: infer args) => infer ret ? (...args: args) => ret : evaluate<t>;
|
|
9
|
-
export type evaluate<t> = {
|
|
10
|
-
[k in keyof t]: t[k];
|
|
11
|
-
} & unknown;
|
|
12
|
-
/** Causes a type that would be eagerly calculated to be displayed as-is.
|
|
13
|
-
* WARNING: Makes t NonNullable as a side effect.
|
|
14
|
-
*/
|
|
15
|
-
export type defer<t> = t & {};
|
|
16
|
-
export type merge<base, merged> = evaluate<Omit<base, keyof merged> & merged>;
|
|
17
|
-
/** Replace existing keys of o without altering readonly or optional modifiers */
|
|
18
|
-
export type replaceProps<o, replacements extends {
|
|
19
|
-
-readonly [k in keyof o]?: unknown;
|
|
20
|
-
}> = evaluate<{
|
|
21
|
-
[k in keyof o]: k extends keyof replacements ? replacements[k] : o[k];
|
|
22
|
-
}>;
|
|
23
|
-
export type isTopType<t> = (any extends t ? true : false) extends true ? true : false;
|
|
24
|
-
export type isAny<t> = (any extends t ? topTypeIsAny<t> : false) extends true ? true : false;
|
|
25
|
-
export type isUnknown<t> = (any extends t ? topTypeIsUnknown<t> : false) extends true ? true : false;
|
|
26
|
-
type topTypeIsAny<t> = (t extends {} ? true : false) extends false ? false : true;
|
|
27
|
-
type topTypeIsUnknown<t> = (t extends {} ? true : false) extends false ? true : false;
|
|
28
|
-
export type extractKeysWithValue<o, filter> = {
|
|
29
|
-
[k in keyof o]: isAny<o[k]> extends true ? never : o[k] extends never ? never : o[k] extends filter ? k : never;
|
|
30
|
-
}[keyof o];
|
|
31
|
-
export type extractValues<o, filter> = o[extractKeysWithValue<o, filter>];
|
|
32
|
-
export type conform<t, base> = t extends base ? t : base;
|
|
33
|
-
export declare const isKeyOf: <k extends string | number, obj extends object>(k: k, obj: obj) => k is Extract<keyof obj, k>;
|
|
34
|
-
export type constructor<instance = unknown> = abstract new (...args: any[]) => instance;
|
|
35
|
-
export type instanceOf<classType extends constructor<any>> = classType extends constructor<infer Instance> ? Instance : never;
|
|
36
|
-
export type entryOf<o> = evaluate<{
|
|
37
|
-
[k in keyof o]-?: [k, defined<o[k]>];
|
|
38
|
-
}[o extends List ? keyof o & number : keyof o]>;
|
|
39
|
-
export type entriesOf<o extends object> = entryOf<o>[];
|
|
40
|
-
export declare const entriesOf: <o extends object>(o: o) => entriesOf<o>;
|
|
41
|
-
/** Mimics the result of Object.keys(...) */
|
|
42
|
-
export type objectKeysOf<o> = [o] extends [object] ? o extends readonly unknown[] ? any[] extends o ? `${number}` : keyof o & `${number}` : keyof o extends number ? `${keyof o}` : Exclude<keyof o, symbol> : never;
|
|
43
|
-
export declare const objectKeysOf: <o extends object>(o: o) => objectKeysOf<o>[];
|
|
44
|
-
export type stringKeyOf<o> = keyof o & string;
|
|
45
|
-
/** Mimics output of TS's keyof operator at runtime */
|
|
46
|
-
export declare const prototypeKeysOf: <t>(value: t) => (keyof t)[];
|
|
47
|
-
export declare const hasKey: <o, k extends string>(o: o, k: k) => o is Extract<o, { [_ in k]: {}; }>;
|
|
48
|
-
export declare const hasSingleKey: <o extends object, k extends string>(o: o, k: k) => o is o & { [_ in k]: {}; };
|
|
49
|
-
export declare const keyCount: (o: object) => number;
|
|
50
|
-
export type keySet<key extends string = string> = {
|
|
51
|
-
readonly [_ in key]?: true;
|
|
52
|
-
};
|
|
53
|
-
export declare const hasKeys: (value: unknown) => boolean;
|
|
54
|
-
export type mutable<o> = {
|
|
55
|
-
-readonly [k in keyof o]: o[k];
|
|
56
|
-
};
|
|
57
|
-
export type immutable<o> = {
|
|
58
|
-
readonly [k in keyof o]: o[k];
|
|
59
|
-
};
|
|
60
|
-
export type deepImmutable<o> = [o] extends [object] ? {
|
|
61
|
-
readonly [k in keyof o]: deepImmutable<o[k]>;
|
|
62
|
-
} : o;
|
|
63
|
-
/** Check for type equality without breaking TS for this repo. Fails on some types like Dict/{} */
|
|
64
|
-
export type equals<t, u> = identity<t> extends identity<u> ? true : false;
|
|
65
|
-
declare const id: unique symbol;
|
|
66
|
-
export declare const nominal: <o extends object, name extends string>(o: o, name: name) => nominal<o, name>;
|
|
67
|
-
export type nominal<t, id extends string> = t & {
|
|
68
|
-
readonly [id]: id;
|
|
69
|
-
};
|
|
70
|
-
export declare const getNominalId: <data>(data: data) => unknown;
|
|
71
|
-
export declare const hasNominalId: <data, name extends string>(data: data, name: name) => data is nominal<data, name>;
|
|
72
|
-
export type assertEqual<t, u> = equals<t, u> extends true ? t : error<`types were not equivalent`>;
|
|
73
|
-
export type identity<in out t> = (_: t) => t;
|
|
74
|
-
export type extend<t, u extends t> = u;
|
|
75
|
-
export type subsume<t extends u, u> = u;
|
|
76
|
-
export type defined<t> = Exclude<t, undefined>;
|
|
77
|
-
export type requireKeys<o, key extends keyof o> = o & {
|
|
78
|
-
[requiredKey in key]-?: o[requiredKey];
|
|
79
|
-
};
|
|
80
|
-
export type optionalizeKeys<o, key extends keyof o> = Omit<o, key> & {
|
|
81
|
-
[requiredKey in key]?: o[requiredKey];
|
|
82
|
-
};
|
|
83
|
-
export type requiredKeyOf<o> = {
|
|
84
|
-
[k in keyof o]-?: o extends {
|
|
85
|
-
[_ in k]-?: o[k];
|
|
86
|
-
} ? k : never;
|
|
87
|
-
}[keyof o];
|
|
88
|
-
export type optionalKeyOf<o> = Exclude<keyof o, requiredKeyOf<o>>;
|
|
89
|
-
/** Type equivalent of ?? */
|
|
90
|
-
export type coalesce<t, fallback> = t extends {} ? t : fallback;
|
|
91
|
-
export type error<message extends string = string> = `!${message}`;
|
|
92
|
-
export type castOnError<t, to> = isTopType<t> extends true ? t : t extends never ? t : t extends error ? to : t;
|
|
93
|
-
export type tryCatch<t, onValid> = isAny<t> extends true ? onValid : t extends never ? onValid : t extends error ? t : onValid;
|
|
94
|
-
export type RegexLiteral<expression extends string = string> = `/${expression}/`;
|
|
95
|
-
export type autocomplete<suggestions extends string> = suggestions | (string & {});
|
|
96
|
-
export type tailOf<t extends List> = t extends readonly [unknown, ...infer tail] ? tail : [];
|
|
97
|
-
export type headOf<t extends List> = t extends readonly [
|
|
98
|
-
infer head,
|
|
99
|
-
...unknown[]
|
|
100
|
-
] ? head : never;
|
|
101
|
-
export type tailOfString<S extends string> = S extends `${string}${infer Tail}` ? Tail : "";
|
|
102
|
-
export type headOfString<S extends string> = S extends `${infer Head}${string}` ? Head : "";
|
|
103
|
-
export type parametersOf<f> = f extends (...args: infer parameters) => unknown ? parameters : never;
|
|
104
|
-
export type returnOf<f> = f extends (...args: never[]) => infer returns ? returns : never;
|
|
105
|
-
export type Dict<k extends string = string, v = unknown> = {
|
|
106
|
-
readonly [_ in k]: v;
|
|
107
|
-
};
|
|
108
|
-
export type List<t = unknown> = readonly t[];
|
|
109
|
-
export type arraySubclassToReadonly<t extends unknown[]> = readonly t[number][] & {
|
|
110
|
-
[k in Exclude<keyof t, keyof unknown[]>]: t[k];
|
|
111
|
-
};
|
|
112
|
-
export type HomogenousTuple<item, length extends number, result extends item[] = []> = result["length"] extends length ? result : HomogenousTuple<item, length, [...result, item]>;
|
|
113
|
-
export declare const listFrom: <t>(data: t) => t extends List<unknown> ? t : readonly t[];
|
|
114
|
-
export type CollapsibleList<t> = t | readonly t[];
|
|
115
|
-
/** Either:
|
|
116
|
-
* A, with all properties of B undefined
|
|
117
|
-
* OR
|
|
118
|
-
* B, with all properties of A undefined
|
|
119
|
-
**/
|
|
120
|
-
export type xor<a, b> = evaluate<a & {
|
|
121
|
-
[k in keyof b]?: undefined;
|
|
122
|
-
}> | evaluate<b & {
|
|
123
|
-
[k in keyof a]?: undefined;
|
|
124
|
-
}>;
|
|
125
|
-
export {};
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
export type BigintLiteral<Value extends bigint = bigint> = `${Value}n`;
|
|
2
|
-
export type NumberLiteral<Value extends number = number> = `${Value}`;
|
|
3
|
-
export type IntegerLiteral<Value extends bigint = bigint> = `${Value}`;
|
|
4
|
-
/**
|
|
5
|
-
* The goal of the number literal and bigint literal regular expressions is to:
|
|
6
|
-
*
|
|
7
|
-
* 1. Ensure definitions form a bijection with the values they represent.
|
|
8
|
-
* 2. Attempt to mirror TypeScript's own format for stringification of numeric
|
|
9
|
-
* values such that the regex should match a given definition if any only if
|
|
10
|
-
* a precise literal type will be inferred (in TS4.8+).
|
|
11
|
-
*/
|
|
12
|
-
/**
|
|
13
|
-
* Matches a well-formatted numeric expression according to the following rules:
|
|
14
|
-
* 1. Must include an integer portion (i.e. '.321' must be written as '0.321')
|
|
15
|
-
* 2. The first digit of the value must not be 0, unless the entire integer portion is 0
|
|
16
|
-
* 3. If the value includes a decimal, its last digit may not be 0
|
|
17
|
-
* 4. The value may not be "-0"
|
|
18
|
-
*/
|
|
19
|
-
export declare const wellFormedNumberMatcher: RegExp;
|
|
20
|
-
/**
|
|
21
|
-
* Matches a well-formatted integer according to the following rules:
|
|
22
|
-
* 1. Must begin with an integer, the first digit of which cannot be 0 unless the entire value is 0
|
|
23
|
-
* 2. The value may not be "-0"
|
|
24
|
-
*/
|
|
25
|
-
export declare const wellFormedIntegerMatcher: RegExp;
|
|
26
|
-
export declare const isWellFormedInteger: (s: string) => boolean;
|
|
27
|
-
export declare const wellFormedNonNegativeIntegerMatcher: RegExp;
|
|
28
|
-
type NumericLiteralKind = "number" | "bigint" | "integer";
|
|
29
|
-
declare const numericLiteralDescriptions: {
|
|
30
|
-
readonly number: "a number";
|
|
31
|
-
readonly bigint: "a bigint";
|
|
32
|
-
readonly integer: "an integer";
|
|
33
|
-
};
|
|
34
|
-
type numericLiteralDescriptions = typeof numericLiteralDescriptions;
|
|
35
|
-
export type writeMalformedNumericLiteralMessage<def extends string, kind extends NumericLiteralKind> = `'${def}' was parsed as ${numericLiteralDescriptions[kind]} but could not be narrowed to a literal value. Avoid unnecessary leading or trailing zeros and other abnormal notation`;
|
|
36
|
-
export declare const writeMalformedNumericLiteralMessage: <def extends string, kind extends NumericLiteralKind>(def: def, kind: kind) => `'${def}' was parsed as ${{
|
|
37
|
-
readonly number: "a number";
|
|
38
|
-
readonly bigint: "a bigint";
|
|
39
|
-
readonly integer: "an integer";
|
|
40
|
-
}[kind]} but could not be narrowed to a literal value. Avoid unnecessary leading or trailing zeros and other abnormal notation`;
|
|
41
|
-
export declare const tryParseWellFormedNumber: <ErrorOnFail extends string | boolean>(token: string, errorOnFail?: ErrorOnFail | undefined) => ErrorOnFail extends string | true ? number : number | undefined;
|
|
42
|
-
export type tryParseWellFormedNumber<token extends string, messageOnFail extends string> = token extends NumberLiteral<infer value> ? value : messageOnFail;
|
|
43
|
-
export declare const tryParseWellFormedInteger: <errorOnFail extends string | boolean>(token: string, errorOnFail?: errorOnFail | undefined) => errorOnFail extends string | true ? number : number | undefined;
|
|
44
|
-
export type tryParseWellFormedInteger<token extends string, messageOnFail extends string> = token extends IntegerLiteral<infer value> ? `${value}` extends NumberLiteral<infer valueAsNumber> ? valueAsNumber : never : messageOnFail;
|
|
45
|
-
export declare const tryParseWellFormedBigint: (def: string) => bigint | undefined;
|
|
46
|
-
export {};
|