arktype 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +7 -0
- package/README.md +106 -0
- package/dist/api.cjs +17 -0
- package/dist/api.d.ts +2 -0
- package/dist/api.mjs +3 -0
- package/dist/cjs/main.js +435 -0
- package/dist/cjs/nodes/branches.js +87 -0
- package/dist/cjs/nodes/compose.js +142 -0
- package/dist/cjs/nodes/discriminate.js +201 -0
- package/dist/cjs/nodes/functors.js +37 -0
- package/dist/cjs/nodes/infer.js +6 -0
- package/dist/cjs/nodes/node.js +110 -0
- package/dist/cjs/nodes/predicate.js +89 -0
- package/dist/cjs/nodes/rules/class.js +23 -0
- package/dist/cjs/nodes/rules/collapsibleSet.js +51 -0
- package/dist/cjs/nodes/rules/divisor.js +35 -0
- package/dist/cjs/nodes/rules/props.js +74 -0
- package/dist/cjs/nodes/rules/range.js +111 -0
- package/dist/cjs/nodes/rules/regex.js +70 -0
- package/dist/cjs/nodes/rules/rules.js +158 -0
- package/dist/cjs/nodes/rules/subdomain.js +80 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/parse/definition.js +35 -0
- package/dist/cjs/parse/record.js +39 -0
- package/dist/cjs/parse/string/ast.js +38 -0
- package/dist/cjs/parse/string/reduce/dynamic.js +152 -0
- package/dist/cjs/parse/string/reduce/shared.js +25 -0
- package/dist/cjs/parse/string/reduce/static.js +6 -0
- package/dist/cjs/parse/string/shift/operand/enclosed.js +56 -0
- package/dist/cjs/parse/string/shift/operand/operand.js +13 -0
- package/dist/cjs/parse/string/shift/operand/unenclosed.js +55 -0
- package/dist/cjs/parse/string/shift/operator/bounds.js +89 -0
- package/dist/cjs/parse/string/shift/operator/divisor.js +37 -0
- package/dist/cjs/parse/string/shift/operator/operator.js +28 -0
- package/dist/cjs/parse/string/shift/scanner.js +101 -0
- package/dist/cjs/parse/string/string.js +45 -0
- package/dist/cjs/parse/tuple/keyof.js +48 -0
- package/dist/cjs/parse/tuple/morph.js +58 -0
- package/dist/cjs/parse/tuple/narrow.js +17 -0
- package/dist/cjs/parse/tuple/tuple.js +87 -0
- package/dist/cjs/parse/tuple/utils.js +50 -0
- package/dist/cjs/traverse/problems.js +251 -0
- package/dist/cjs/traverse/traverse.js +270 -0
- package/dist/cjs/utils/chainableNoOpProxy.js +25 -0
- package/dist/cjs/utils/domains.js +69 -0
- package/dist/cjs/utils/errors.js +28 -0
- package/dist/cjs/utils/freeze.js +18 -0
- package/dist/cjs/utils/generics.js +38 -0
- package/dist/cjs/utils/numericLiterals.js +86 -0
- package/dist/cjs/utils/paths.js +34 -0
- package/dist/cjs/utils/serialize.js +100 -0
- package/dist/cjs/utils/unionToTuple.js +6 -0
- package/dist/mjs/main.js +415 -0
- package/dist/mjs/nodes/branches.js +73 -0
- package/dist/mjs/nodes/compose.js +120 -0
- package/dist/mjs/nodes/discriminate.js +186 -0
- package/dist/mjs/nodes/functors.js +29 -0
- package/dist/mjs/nodes/infer.js +3 -0
- package/dist/mjs/nodes/node.js +92 -0
- package/dist/mjs/nodes/predicate.js +71 -0
- package/dist/mjs/nodes/rules/class.js +9 -0
- package/dist/mjs/nodes/rules/collapsibleSet.js +37 -0
- package/dist/mjs/nodes/rules/divisor.js +21 -0
- package/dist/mjs/nodes/rules/props.js +59 -0
- package/dist/mjs/nodes/rules/range.js +92 -0
- package/dist/mjs/nodes/rules/regex.js +55 -0
- package/dist/mjs/nodes/rules/rules.js +140 -0
- package/dist/mjs/nodes/rules/subdomain.js +65 -0
- package/dist/mjs/package.json +3 -0
- package/dist/mjs/parse/definition.js +19 -0
- package/dist/mjs/parse/record.js +31 -0
- package/dist/mjs/parse/string/ast.js +21 -0
- package/dist/mjs/parse/string/reduce/dynamic.js +144 -0
- package/dist/mjs/parse/string/reduce/shared.js +8 -0
- package/dist/mjs/parse/string/reduce/static.js +3 -0
- package/dist/mjs/parse/string/shift/operand/enclosed.js +41 -0
- package/dist/mjs/parse/string/shift/operand/operand.js +5 -0
- package/dist/mjs/parse/string/shift/operand/unenclosed.js +38 -0
- package/dist/mjs/parse/string/shift/operator/bounds.js +72 -0
- package/dist/mjs/parse/string/shift/operator/divisor.js +23 -0
- package/dist/mjs/parse/string/shift/operator/operator.js +13 -0
- package/dist/mjs/parse/string/shift/scanner.js +93 -0
- package/dist/mjs/parse/string/string.js +30 -0
- package/dist/mjs/parse/tuple/keyof.js +40 -0
- package/dist/mjs/parse/tuple/morph.js +44 -0
- package/dist/mjs/parse/tuple/narrow.js +9 -0
- package/dist/mjs/parse/tuple/tuple.js +73 -0
- package/dist/mjs/parse/tuple/utils.js +36 -0
- package/dist/mjs/traverse/problems.js +231 -0
- package/dist/mjs/traverse/traverse.js +254 -0
- package/dist/mjs/utils/chainableNoOpProxy.js +17 -0
- package/dist/mjs/utils/domains.js +50 -0
- package/dist/mjs/utils/errors.js +12 -0
- package/dist/mjs/utils/freeze.js +10 -0
- package/dist/mjs/utils/generics.js +17 -0
- package/dist/mjs/utils/numericLiterals.js +73 -0
- package/dist/mjs/utils/paths.js +20 -0
- package/dist/mjs/utils/serialize.js +83 -0
- package/dist/mjs/utils/unionToTuple.js +3 -0
- package/dist/tsconfig.temp.tsbuildinfo +1 -0
- package/dist/types/main.d.ts +247 -0
- package/dist/types/nodes/branches.d.ts +14 -0
- package/dist/types/nodes/compose.d.ts +92 -0
- package/dist/types/nodes/discriminate.d.ts +27 -0
- package/dist/types/nodes/functors.d.ts +6 -0
- package/dist/types/nodes/infer.d.ts +34 -0
- package/dist/types/nodes/node.d.ts +42 -0
- package/dist/types/nodes/predicate.d.ts +52 -0
- package/dist/types/nodes/rules/class.d.ts +3 -0
- package/dist/types/nodes/rules/collapsibleSet.d.ts +4 -0
- package/dist/types/nodes/rules/divisor.d.ts +2 -0
- package/dist/types/nodes/rules/props.d.ts +20 -0
- package/dist/types/nodes/rules/range.d.ts +33 -0
- package/dist/types/nodes/rules/regex.d.ts +14 -0
- package/dist/types/nodes/rules/rules.d.ts +44 -0
- package/dist/types/nodes/rules/subdomain.d.ts +15 -0
- package/dist/types/parse/definition.d.ts +29 -0
- package/dist/types/parse/record.d.ts +24 -0
- package/dist/types/parse/string/ast.d.ts +42 -0
- package/dist/types/parse/string/reduce/dynamic.d.ts +34 -0
- package/dist/types/parse/string/reduce/shared.d.ts +24 -0
- package/dist/types/parse/string/reduce/static.d.ts +115 -0
- package/dist/types/parse/string/shift/operand/enclosed.d.ts +28 -0
- package/dist/types/parse/string/shift/operand/operand.d.ts +9 -0
- package/dist/types/parse/string/shift/operand/unenclosed.d.ts +18 -0
- package/dist/types/parse/string/shift/operator/bounds.d.ts +20 -0
- package/dist/types/parse/string/shift/operator/divisor.d.ts +9 -0
- package/dist/types/parse/string/shift/operator/operator.d.ts +13 -0
- package/dist/types/parse/string/shift/scanner.d.ts +89 -0
- package/dist/types/parse/string/string.d.ts +27 -0
- package/dist/types/parse/tuple/keyof.d.ts +2 -0
- package/dist/types/parse/tuple/morph.d.ts +15 -0
- package/dist/types/parse/tuple/narrow.d.ts +13 -0
- package/dist/types/parse/tuple/tuple.d.ts +37 -0
- package/dist/types/parse/tuple/utils.d.ts +19 -0
- package/dist/types/traverse/problems.d.ts +123 -0
- package/dist/types/traverse/traverse.d.ts +36 -0
- package/dist/types/utils/chainableNoOpProxy.d.ts +14 -0
- package/dist/types/utils/domains.d.ts +58 -0
- package/dist/types/utils/errors.d.ts +6 -0
- package/dist/types/utils/freeze.d.ts +2 -0
- package/dist/types/utils/generics.d.ts +122 -0
- package/dist/types/utils/numericLiterals.d.ts +28 -0
- package/dist/types/utils/paths.d.ts +7 -0
- package/dist/types/utils/serialize.d.ts +38 -0
- package/dist/types/utils/unionToTuple.d.ts +11 -0
- package/package.json +101 -2
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import type { ResolvedNode, TraversalNode, TypeNode } from "./nodes/node.js";
|
|
2
|
+
import type { inferDefinition, ParseContext, validateDefinition } from "./parse/definition.js";
|
|
3
|
+
import { inferred } from "./parse/definition.js";
|
|
4
|
+
import type { ParsedMorph } from "./parse/tuple/morph.js";
|
|
5
|
+
import type { Problems, ProblemsConfig, ProblemsOptions } from "./traverse/problems.js";
|
|
6
|
+
import type { defer, Dict, error, evaluate, isAny, List, nominal, xor } from "./utils/generics.js";
|
|
7
|
+
import type { stringifyUnion } from "./utils/unionToTuple.js";
|
|
8
|
+
type ScopeParser = {
|
|
9
|
+
<aliases>(aliases: validateAliases<aliases, {}>): Scope<parseScope<aliases, {}>>;
|
|
10
|
+
<aliases, opts extends ScopeOptions>(aliases: validateAliases<aliases, opts>, opts: validateOptions<opts>): Scope<parseScope<aliases, opts>>;
|
|
11
|
+
};
|
|
12
|
+
export type TypeParser<$> = {
|
|
13
|
+
<def>(def: validateDefinition<def, $>): parseType<def, $>;
|
|
14
|
+
<def>(def: validateDefinition<def, $>, opts: TypeOptions): parseType<def, $>;
|
|
15
|
+
};
|
|
16
|
+
export type ScopeOptions = {
|
|
17
|
+
imports?: Space[] | [];
|
|
18
|
+
includes?: Space[] | [];
|
|
19
|
+
standard?: boolean;
|
|
20
|
+
name?: string;
|
|
21
|
+
};
|
|
22
|
+
type validateOptions<opts extends ScopeOptions> = {
|
|
23
|
+
[k in keyof opts]: k extends "imports" | "includes" ? mergeSpaces<opts[k]> extends error<infer e> ? e : opts[k] : opts[k];
|
|
24
|
+
};
|
|
25
|
+
export type ScopeContext = Dict | ScopeContextTuple;
|
|
26
|
+
type ScopeContextTuple = [exports: Dict, locals: Dict, standard?: false];
|
|
27
|
+
type parseScope<aliases, opts extends ScopeOptions> = opts["standard"] extends false ? [inferExports<aliases, opts>, importsOf<opts>, false] : opts["imports"] extends Space[] ? [inferExports<aliases, opts>, importsOf<opts>] : inferExports<aliases, opts>;
|
|
28
|
+
type importsOf<opts extends ScopeOptions> = unknown extends opts["imports"] ? {} : mergeSpaces<opts["imports"]>;
|
|
29
|
+
type includesOf<opts extends ScopeOptions> = unknown extends opts["includes"] ? {} : mergeSpaces<opts["includes"]>;
|
|
30
|
+
export type resolve<name extends keyof $, $> = isAny<$[name]> extends true ? any : $[name] extends alias<infer def> ? inferDefinition<def, $> : $[name];
|
|
31
|
+
type exportsOf<context extends ScopeContext> = context extends [
|
|
32
|
+
infer exports,
|
|
33
|
+
...unknown[]
|
|
34
|
+
] ? exports : context;
|
|
35
|
+
type localsOf<context extends ScopeContext> = context extends List ? context["1"] & (context["2"] extends false ? {} : PrecompiledDefaults) : PrecompiledDefaults;
|
|
36
|
+
type mergeSpaces<scopes, base extends Dict = {}> = scopes extends readonly [
|
|
37
|
+
Space<infer head>,
|
|
38
|
+
...infer tail
|
|
39
|
+
] ? keyof base & keyof head extends never ? mergeSpaces<tail, base & head> : error<`Duplicates ${stringifyUnion<keyof base & keyof head & string>}`> : base;
|
|
40
|
+
type validateAliases<aliases, opts extends ScopeOptions> = {
|
|
41
|
+
[name in keyof aliases]: name extends keyof preresolved<opts> ? writeDuplicateAliasMessage<name & string> : validateDefinition<aliases[name], bootstrapScope<aliases, opts>>;
|
|
42
|
+
};
|
|
43
|
+
type preresolved<opts extends ScopeOptions> = includesOf<opts> & importsOf<opts> & (opts["standard"] extends false ? {} : PrecompiledDefaults);
|
|
44
|
+
type alias<def = {}> = nominal<def, "alias">;
|
|
45
|
+
type bootstrapScope<aliases, opts extends ScopeOptions> = {
|
|
46
|
+
[k in keyof aliases]: alias<aliases[k]>;
|
|
47
|
+
} & preresolved<opts>;
|
|
48
|
+
type inferExports<aliases, opts extends ScopeOptions> = evaluate<{
|
|
49
|
+
[k in keyof aliases]: inferDefinition<aliases[k], bootstrapScope<aliases, opts>>;
|
|
50
|
+
} & includesOf<opts>>;
|
|
51
|
+
export type Space<exports = Dict> = {
|
|
52
|
+
[k in keyof exports]: Type<exports[k]>;
|
|
53
|
+
};
|
|
54
|
+
type resolutions<context extends ScopeContext> = localsOf<context> & exportsOf<context>;
|
|
55
|
+
type name<context extends ScopeContext> = keyof resolutions<context> & string;
|
|
56
|
+
export declare class Scope<context extends ScopeContext = any> {
|
|
57
|
+
#private;
|
|
58
|
+
aliases: Dict;
|
|
59
|
+
opts: ScopeOptions;
|
|
60
|
+
name: string;
|
|
61
|
+
parseCache: FreezingCache<TypeNode>;
|
|
62
|
+
constructor(aliases: Dict, opts: ScopeOptions);
|
|
63
|
+
type: TypeParser<resolutions<context>>;
|
|
64
|
+
get infer(): exportsOf<context>;
|
|
65
|
+
compile(): Space<exportsOf<context>>;
|
|
66
|
+
addReferenceIfResolvable(name: name<context>, ctx: ParseContext): boolean;
|
|
67
|
+
resolve(name: name<context>): Type<unknown>;
|
|
68
|
+
resolveNode(node: TypeNode): ResolvedNode;
|
|
69
|
+
}
|
|
70
|
+
declare class TypeRoot<t = unknown> {
|
|
71
|
+
config: TypeConfig;
|
|
72
|
+
scope: Scope;
|
|
73
|
+
[inferred]: t;
|
|
74
|
+
node: TypeNode;
|
|
75
|
+
flat: TraversalNode;
|
|
76
|
+
includesMorph: boolean;
|
|
77
|
+
infer: asOut<t>;
|
|
78
|
+
constructor(config: TypeConfig, scope: Scope);
|
|
79
|
+
}
|
|
80
|
+
declare class Cache<item = unknown> {
|
|
81
|
+
protected cache: {
|
|
82
|
+
[name in string]?: item;
|
|
83
|
+
};
|
|
84
|
+
get root(): {
|
|
85
|
+
readonly [name in string]?: item;
|
|
86
|
+
};
|
|
87
|
+
has(name: string): boolean;
|
|
88
|
+
get(name: string): item | undefined;
|
|
89
|
+
set(name: string, item: item): item;
|
|
90
|
+
}
|
|
91
|
+
declare class FreezingCache<item = unknown> extends Cache<item> {
|
|
92
|
+
set(name: string, item: item): item;
|
|
93
|
+
}
|
|
94
|
+
export declare const writeShallowCycleErrorMessage: (name: string, seen: string[]) => string;
|
|
95
|
+
export declare const scope: ScopeParser;
|
|
96
|
+
export declare const scopes: {
|
|
97
|
+
ts: Scope<[{
|
|
98
|
+
any: any;
|
|
99
|
+
bigint: bigint;
|
|
100
|
+
boolean: boolean;
|
|
101
|
+
false: false;
|
|
102
|
+
never: never;
|
|
103
|
+
null: null;
|
|
104
|
+
number: number;
|
|
105
|
+
object: object;
|
|
106
|
+
string: string;
|
|
107
|
+
symbol: symbol;
|
|
108
|
+
true: true;
|
|
109
|
+
unknown: unknown;
|
|
110
|
+
void: void;
|
|
111
|
+
undefined: undefined;
|
|
112
|
+
Function: Function;
|
|
113
|
+
}, {}, false]>;
|
|
114
|
+
validation: Scope<[{
|
|
115
|
+
email: string;
|
|
116
|
+
alphanumeric: string;
|
|
117
|
+
alpha: string;
|
|
118
|
+
lowercase: string;
|
|
119
|
+
uppercase: string;
|
|
120
|
+
integer: number;
|
|
121
|
+
}, {}, false]>;
|
|
122
|
+
standard: Scope<[{
|
|
123
|
+
any: any;
|
|
124
|
+
bigint: bigint;
|
|
125
|
+
boolean: boolean;
|
|
126
|
+
false: false;
|
|
127
|
+
never: never;
|
|
128
|
+
null: null;
|
|
129
|
+
number: number;
|
|
130
|
+
object: object;
|
|
131
|
+
string: string;
|
|
132
|
+
symbol: symbol;
|
|
133
|
+
true: true;
|
|
134
|
+
unknown: unknown;
|
|
135
|
+
void: void;
|
|
136
|
+
undefined: undefined;
|
|
137
|
+
Function: Function;
|
|
138
|
+
email: string;
|
|
139
|
+
alphanumeric: string;
|
|
140
|
+
alpha: string;
|
|
141
|
+
lowercase: string;
|
|
142
|
+
uppercase: string;
|
|
143
|
+
integer: number;
|
|
144
|
+
}, {}, false]>;
|
|
145
|
+
};
|
|
146
|
+
export declare const spaces: {
|
|
147
|
+
ts: Space<{
|
|
148
|
+
any: any;
|
|
149
|
+
bigint: bigint;
|
|
150
|
+
boolean: boolean;
|
|
151
|
+
false: false;
|
|
152
|
+
never: never;
|
|
153
|
+
null: null;
|
|
154
|
+
number: number;
|
|
155
|
+
object: object;
|
|
156
|
+
string: string;
|
|
157
|
+
symbol: symbol;
|
|
158
|
+
true: true;
|
|
159
|
+
unknown: unknown;
|
|
160
|
+
void: void;
|
|
161
|
+
undefined: undefined;
|
|
162
|
+
Function: Function;
|
|
163
|
+
}>;
|
|
164
|
+
validation: Space<{
|
|
165
|
+
email: string;
|
|
166
|
+
alphanumeric: string;
|
|
167
|
+
alpha: string;
|
|
168
|
+
lowercase: string;
|
|
169
|
+
uppercase: string;
|
|
170
|
+
integer: number;
|
|
171
|
+
}>;
|
|
172
|
+
standard: Space<{
|
|
173
|
+
any: any;
|
|
174
|
+
bigint: bigint;
|
|
175
|
+
boolean: boolean;
|
|
176
|
+
false: false;
|
|
177
|
+
never: never;
|
|
178
|
+
null: null;
|
|
179
|
+
number: number;
|
|
180
|
+
object: object;
|
|
181
|
+
string: string;
|
|
182
|
+
symbol: symbol;
|
|
183
|
+
true: true;
|
|
184
|
+
unknown: unknown;
|
|
185
|
+
void: void;
|
|
186
|
+
undefined: undefined;
|
|
187
|
+
Function: Function;
|
|
188
|
+
email: string;
|
|
189
|
+
alphanumeric: string;
|
|
190
|
+
alpha: string;
|
|
191
|
+
lowercase: string;
|
|
192
|
+
uppercase: string;
|
|
193
|
+
integer: number;
|
|
194
|
+
}>;
|
|
195
|
+
};
|
|
196
|
+
type PrecompiledDefaults = {
|
|
197
|
+
email: string;
|
|
198
|
+
alphanumeric: string;
|
|
199
|
+
alpha: string;
|
|
200
|
+
lowercase: string;
|
|
201
|
+
uppercase: string;
|
|
202
|
+
integer: number;
|
|
203
|
+
any: any;
|
|
204
|
+
bigint: bigint;
|
|
205
|
+
boolean: boolean;
|
|
206
|
+
false: false;
|
|
207
|
+
never: never;
|
|
208
|
+
null: null;
|
|
209
|
+
number: number;
|
|
210
|
+
object: object;
|
|
211
|
+
string: string;
|
|
212
|
+
symbol: symbol;
|
|
213
|
+
true: true;
|
|
214
|
+
unknown: unknown;
|
|
215
|
+
void: void;
|
|
216
|
+
undefined: undefined;
|
|
217
|
+
Function: Function;
|
|
218
|
+
};
|
|
219
|
+
export declare const type: TypeParser<PrecompiledDefaults>;
|
|
220
|
+
export declare const writeDuplicateAliasMessage: <name_1 extends string>(name: name_1) => `Alias '${name_1}' is already defined`;
|
|
221
|
+
type writeDuplicateAliasMessage<name extends string> = `Alias '${name}' is already defined`;
|
|
222
|
+
export declare const isType: (value: unknown) => value is Type<unknown>;
|
|
223
|
+
export type parseType<def, $> = def extends validateDefinition<def, $> ? Type<inferDefinition<def, $>> : never;
|
|
224
|
+
export type Result<t> = xor<{
|
|
225
|
+
data: asIn<t>;
|
|
226
|
+
out: asOut<t>;
|
|
227
|
+
}, {
|
|
228
|
+
problems: Problems;
|
|
229
|
+
}>;
|
|
230
|
+
type Checker<t> = (data: unknown) => Result<t>;
|
|
231
|
+
export type Type<t = unknown> = defer<Checker<t> & TypeRoot<t>>;
|
|
232
|
+
export type TypeOptions = {
|
|
233
|
+
name?: string;
|
|
234
|
+
problems?: ProblemsOptions;
|
|
235
|
+
};
|
|
236
|
+
export type QualifiedTypeName = `${string}.${string}`;
|
|
237
|
+
export type TypeConfig = {
|
|
238
|
+
name: string;
|
|
239
|
+
id: QualifiedTypeName;
|
|
240
|
+
problems: ProblemsConfig;
|
|
241
|
+
};
|
|
242
|
+
export type asIn<t> = asIo<t, "in">;
|
|
243
|
+
export type asOut<t> = asIo<t, "out">;
|
|
244
|
+
type asIo<t, io extends "in" | "out"> = t extends ParsedMorph<infer i, infer o> ? io extends "in" ? i : o : t extends object ? t extends Function ? t : {
|
|
245
|
+
[k in keyof t]: asIo<t[k], io>;
|
|
246
|
+
} : t;
|
|
247
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { List } from "../utils/generics.js";
|
|
2
|
+
import type { IntersectionState } from "./compose.js";
|
|
3
|
+
import type { Branch, PredicateComparison } from "./predicate.js";
|
|
4
|
+
export declare const isBranchComparison: (comparison: PredicateComparison) => comparison is BranchesComparison;
|
|
5
|
+
export type Branches = List<Branch>;
|
|
6
|
+
export type BranchesComparison = {
|
|
7
|
+
lConditions: Branches;
|
|
8
|
+
rConditions: Branches;
|
|
9
|
+
lSubconditionsOfR: number[];
|
|
10
|
+
rSubconditionsOfL: number[];
|
|
11
|
+
equalities: [lIndex: number, rIndex: number][];
|
|
12
|
+
distinctIntersections: Branches;
|
|
13
|
+
};
|
|
14
|
+
export declare const compareBranches: (lConditions: Branches, rConditions: Branches, state: IntersectionState) => BranchesComparison;
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import type { Type } from "../main.js";
|
|
2
|
+
import type { Domain, Subdomain } from "../utils/domains.js";
|
|
3
|
+
import type { constructor, Dict, extend } from "../utils/generics.js";
|
|
4
|
+
import { Path } from "../utils/paths.js";
|
|
5
|
+
import type { Range } from "./rules/range.js";
|
|
6
|
+
import type { LiteralRules, NarrowableRules } from "./rules/rules.js";
|
|
7
|
+
export type Intersector<t> = (l: t, r: t, state: IntersectionState) => IntersectionResult<t>;
|
|
8
|
+
type allowUndefinedOperands<f extends Intersector<any>> = f extends Intersector<infer operand> ? Intersector<operand | undefined> : never;
|
|
9
|
+
export declare const composeIntersection: <t, reducer extends Intersector<t> = Intersector<t>>(reducer: reducer) => allowUndefinedOperands<reducer>;
|
|
10
|
+
export declare const throwUndefinedOperandsError: () => never;
|
|
11
|
+
export type IntersectionResult<t> = t | Empty | Equal;
|
|
12
|
+
export type DisjointKinds = extend<Record<string, {
|
|
13
|
+
l: unknown;
|
|
14
|
+
r: unknown;
|
|
15
|
+
}>, {
|
|
16
|
+
domain: {
|
|
17
|
+
l: Domain[];
|
|
18
|
+
r: Domain[];
|
|
19
|
+
};
|
|
20
|
+
subdomain: {
|
|
21
|
+
l: Subdomain;
|
|
22
|
+
r: Subdomain;
|
|
23
|
+
};
|
|
24
|
+
range: {
|
|
25
|
+
l: Range;
|
|
26
|
+
r: Range;
|
|
27
|
+
};
|
|
28
|
+
class: {
|
|
29
|
+
l: constructor;
|
|
30
|
+
r: constructor;
|
|
31
|
+
};
|
|
32
|
+
tupleLength: {
|
|
33
|
+
l: number;
|
|
34
|
+
r: number;
|
|
35
|
+
};
|
|
36
|
+
value: {
|
|
37
|
+
l: unknown;
|
|
38
|
+
r: unknown;
|
|
39
|
+
};
|
|
40
|
+
leftAssignability: {
|
|
41
|
+
l: LiteralRules;
|
|
42
|
+
r: NarrowableRules;
|
|
43
|
+
};
|
|
44
|
+
rightAssignability: {
|
|
45
|
+
l: NarrowableRules;
|
|
46
|
+
r: LiteralRules;
|
|
47
|
+
};
|
|
48
|
+
}>;
|
|
49
|
+
export declare const disjointDescriptionWriters: {
|
|
50
|
+
domain: ({ l, r }: DisjointContext<"domain">) => string;
|
|
51
|
+
subdomain: ({ l, r }: DisjointContext<"subdomain">) => string;
|
|
52
|
+
range: ({ l, r }: DisjointContext<"range">) => string;
|
|
53
|
+
class: ({ l, r }: DisjointContext<"class">) => string;
|
|
54
|
+
tupleLength: ({ l, r }: DisjointContext<"tupleLength">) => string;
|
|
55
|
+
value: ({ l, r }: DisjointContext<"value">) => string;
|
|
56
|
+
leftAssignability: ({ l, r }: DisjointContext<"leftAssignability">) => string;
|
|
57
|
+
rightAssignability: ({ l, r }: DisjointContext<"rightAssignability">) => string;
|
|
58
|
+
};
|
|
59
|
+
export declare const stringifyRange: (range: Range) => string;
|
|
60
|
+
export type DisjointKind = keyof DisjointKinds;
|
|
61
|
+
export declare class IntersectionState {
|
|
62
|
+
#private;
|
|
63
|
+
type: Type;
|
|
64
|
+
lastOperator: "|" | "&";
|
|
65
|
+
path: Path;
|
|
66
|
+
domain: Domain | undefined;
|
|
67
|
+
constructor(type: Type, lastOperator: "|" | "&");
|
|
68
|
+
get disjoints(): Readonly<DisjointsByPath>;
|
|
69
|
+
addDisjoint<kind extends DisjointKind>(kind: kind, l: DisjointKinds[kind]["l"], r: DisjointKinds[kind]["r"]): Empty;
|
|
70
|
+
}
|
|
71
|
+
export type DisjointsByPath = Record<string, DisjointContext>;
|
|
72
|
+
export type DisjointContext<kind extends DisjointKind = DisjointKind> = {
|
|
73
|
+
kind: kind;
|
|
74
|
+
} & DisjointKinds[kind];
|
|
75
|
+
declare const empty: unique symbol;
|
|
76
|
+
export type Empty = typeof empty;
|
|
77
|
+
export declare const anonymousDisjoint: () => Empty;
|
|
78
|
+
export declare const isDisjoint: (result: unknown) => result is typeof empty;
|
|
79
|
+
declare const equal: unique symbol;
|
|
80
|
+
export type Equal = typeof equal;
|
|
81
|
+
export declare const equality: () => Equal;
|
|
82
|
+
export declare const isEquality: (result: unknown) => result is typeof equal;
|
|
83
|
+
export type IntersectionReducerMap<root extends Dict> = {
|
|
84
|
+
[k in keyof root]-?: Intersector<root[k]>;
|
|
85
|
+
};
|
|
86
|
+
export type KeyIntersectionFn<root extends Dict> = <key extends keyof root>(key: key, l: root[key], r: root[key], state: IntersectionState) => IntersectionResult<root[key]>;
|
|
87
|
+
export type IntersectionReducer<root extends Dict> = KeyIntersectionFn<root> | IntersectionReducerMap<root>;
|
|
88
|
+
export type KeyedOperationConfig = {
|
|
89
|
+
onEmpty: "omit" | "bubble";
|
|
90
|
+
};
|
|
91
|
+
export declare const composeKeyedIntersection: <root extends Dict>(reducer: IntersectionReducer<root>, config: KeyedOperationConfig) => Intersector<root>;
|
|
92
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Domain, Subdomain } from "../utils/domains.js";
|
|
2
|
+
import type { evaluate } from "../utils/generics.js";
|
|
3
|
+
import type { NumberLiteral } from "../utils/numericLiterals.js";
|
|
4
|
+
import { Path } from "../utils/paths.js";
|
|
5
|
+
import type { SerializedPrimitive } from "../utils/serialize.js";
|
|
6
|
+
import type { Branches } from "./branches.js";
|
|
7
|
+
import type { FlattenContext, TraversalEntry } from "./node.js";
|
|
8
|
+
export type DiscriminatedSwitch<kind extends DiscriminantKind = DiscriminantKind> = {
|
|
9
|
+
readonly path: Path;
|
|
10
|
+
readonly kind: kind;
|
|
11
|
+
readonly cases: DiscriminatedCases<kind>;
|
|
12
|
+
};
|
|
13
|
+
export type DiscriminatedCases<kind extends DiscriminantKind = DiscriminantKind> = {
|
|
14
|
+
[caseKey in CaseKey<kind>]?: TraversalEntry[];
|
|
15
|
+
};
|
|
16
|
+
export declare const flattenBranches: (branches: Branches, ctx: FlattenContext) => TraversalEntry[];
|
|
17
|
+
export type QualifiedDisjoint = `${DiscriminantKind}` | `${string}/${DiscriminantKind}`;
|
|
18
|
+
export type DiscriminantKinds = {
|
|
19
|
+
domain: Domain;
|
|
20
|
+
subdomain: Subdomain;
|
|
21
|
+
value: unknown;
|
|
22
|
+
};
|
|
23
|
+
export type DiscriminantKind = evaluate<keyof DiscriminantKinds>;
|
|
24
|
+
export declare const serializeIfAllowed: <kind extends DiscriminantKind>(kind: kind, data: DiscriminantKinds[kind]) => CaseKey<kind> | undefined;
|
|
25
|
+
export declare const serializeCase: <kind extends DiscriminantKind>(kind: kind, data: unknown) => CaseKey<kind>;
|
|
26
|
+
type CaseKey<kind extends DiscriminantKind = DiscriminantKind> = kind extends "value" ? SerializedPrimitive | "default" : kind extends "tupleLength" ? NumberLiteral | "default" : DiscriminantKinds[kind];
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { inferTerminal } from "../parse/string/ast.js";
|
|
2
|
+
import type { Morph, Out } from "../parse/tuple/morph.js";
|
|
3
|
+
import type { Domain, inferDomain, inferSubdomain, Subdomain } from "../utils/domains.js";
|
|
4
|
+
import type { evaluate, HomogenousTuple, List, returnOf } from "../utils/generics.js";
|
|
5
|
+
import type { ResolvedNode, TypeNode } from "./node.js";
|
|
6
|
+
import type { Predicate } from "./predicate.js";
|
|
7
|
+
import type { OptionalProp, PropsRule } from "./rules/props.js";
|
|
8
|
+
import type { Bound, Range } from "./rules/range.js";
|
|
9
|
+
import type { LiteralRules, MorphBranch, NarrowableRules } from "./rules/rules.js";
|
|
10
|
+
import type { SubdomainRule } from "./rules/subdomain.js";
|
|
11
|
+
export type inferNode<node extends TypeNode<$>, $ = {}> = node extends string ? inferTerminal<node, $> : node extends ResolvedNode<$> ? inferResolution<node, $> : never;
|
|
12
|
+
export type inferResolution<node extends ResolvedNode<$>, $> = evaluate<{
|
|
13
|
+
[domain in keyof node]: inferPredicate<domain, node[domain], $>;
|
|
14
|
+
}[keyof node]>;
|
|
15
|
+
type inferPredicate<domain extends Domain, predicate extends Predicate, $> = predicate extends true ? inferDomain<domain> : inferBranch<domain, conditionFrom<predicate>, $>;
|
|
16
|
+
type conditionFrom<predicate extends Predicate> = predicate extends List ? predicate[number] : predicate;
|
|
17
|
+
type inferBranch<domain extends Domain, branch, $> = branch extends MorphBranch ? (In: inferBranch<domain, branch["input"], $>) => Out<branch["morph"] extends [...unknown[], infer tail extends Morph] ? returnOf<tail> : returnOf<branch["morph"]>> : inferRules<domain, branch, $>;
|
|
18
|
+
type inferRules<domain extends Domain, branch, $> = branch extends LiteralRules ? branch["value"] : domain extends "object" ? branch extends NarrowableRules ? inferObjectRules<branch, $> : object : inferDomain<domain>;
|
|
19
|
+
type inferObjectRules<rules extends NarrowableRules, $> = evaluate<(rules["subdomain"] extends SubdomainRule ? inferSubdomainRule<rules["subdomain"], rules["range"], $> : unknown) & (rules["props"] extends PropsRule ? inferProps<rules["props"], $> : unknown)>;
|
|
20
|
+
type inferSubdomainRule<rule extends SubdomainRule, possibleRange extends Range | undefined, $> = rule extends Subdomain ? inferSubdomain<rule> : rule extends readonly ["Array", infer item extends TypeNode<$>] ? possibleRange extends Bound<"=="> ? HomogenousTuple<inferNode<item, $>, possibleRange["limit"]> : inferNode<item, $>[] : rule extends readonly ["Set", infer item extends TypeNode<$>] ? Set<inferNode<item, $>> : rule extends readonly [
|
|
21
|
+
"Map",
|
|
22
|
+
infer k extends TypeNode<$>,
|
|
23
|
+
infer v extends TypeNode<$>
|
|
24
|
+
] ? Map<inferNode<k, $>, inferNode<v, $>> : never;
|
|
25
|
+
type inferProps<props extends PropsRule, $> = {
|
|
26
|
+
[k in requiredKeyOf<props>]: props[k] extends TypeNode<$> ? inferNode<props[k], $> : 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 requiredKeyOf<props extends PropsRule> = Exclude<keyof props, optionalKeyOf<props>>;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Type } from "../main.js";
|
|
2
|
+
import type { ParseContext } from "../parse/definition.js";
|
|
3
|
+
import type { Domain } from "../utils/domains.js";
|
|
4
|
+
import type { Dict, stringKeyOf } from "../utils/generics.js";
|
|
5
|
+
import type { Intersector } from "./compose.js";
|
|
6
|
+
import type { DiscriminatedSwitch } from "./discriminate.js";
|
|
7
|
+
import type { Predicate } from "./predicate.js";
|
|
8
|
+
import type { LiteralRules, MorphEntry, RuleEntry } from "./rules/rules.js";
|
|
9
|
+
export type TypeNode<$ = Dict> = Identifier<$> | ResolvedNode<$>;
|
|
10
|
+
export type Identifier<$ = Dict> = stringKeyOf<$>;
|
|
11
|
+
/** If scope is provided, we also narrow each predicate to match its domain.
|
|
12
|
+
* Otherwise, we use a base predicate for all types, which is easier to
|
|
13
|
+
* manipulate.*/
|
|
14
|
+
export type ResolvedNode<$ = Dict> = {
|
|
15
|
+
readonly [domain in Domain]?: Predicate<domain, $>;
|
|
16
|
+
};
|
|
17
|
+
export declare const nodeIntersection: Intersector<TypeNode>;
|
|
18
|
+
export declare const intersection: (l: TypeNode, r: TypeNode, type: Type) => TypeNode;
|
|
19
|
+
export declare const union: (l: TypeNode, r: TypeNode, type: Type) => ResolvedNode;
|
|
20
|
+
export type TraversalNode = Domain | TraversalEntry[];
|
|
21
|
+
export type TraversalEntry = RuleEntry | MorphEntry | DomainsEntry | CyclicReferenceEntry | DomainEntry | BranchesEntry | SwitchEntry;
|
|
22
|
+
export type TraversalKey = TraversalEntry[0];
|
|
23
|
+
export type TraversalRule<k extends TraversalKey> = Extract<TraversalEntry, [
|
|
24
|
+
k,
|
|
25
|
+
unknown
|
|
26
|
+
]>[1];
|
|
27
|
+
export type CyclicReferenceEntry = ["alias", string];
|
|
28
|
+
export type DomainEntry = ["domain", Domain];
|
|
29
|
+
export type DomainsEntry = [
|
|
30
|
+
"domains",
|
|
31
|
+
{
|
|
32
|
+
readonly [domain in Domain]?: TraversalEntry[];
|
|
33
|
+
}
|
|
34
|
+
];
|
|
35
|
+
export type BranchesEntry = ["branches", TraversalEntry[][]];
|
|
36
|
+
export type SwitchEntry = ["switch", DiscriminatedSwitch];
|
|
37
|
+
export type FlattenContext = ParseContext & {
|
|
38
|
+
lastDomain: Domain;
|
|
39
|
+
};
|
|
40
|
+
export declare const flattenType: (type: Type) => TraversalNode;
|
|
41
|
+
export declare const flattenNode: (node: TypeNode, ctx: FlattenContext) => TraversalNode;
|
|
42
|
+
export declare const isLiteralNode: <domain extends Domain>(node: ResolvedNode, domain: domain) => node is { [_ in domain]: LiteralRules<domain>; };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { Type } from "../main.js";
|
|
2
|
+
import type { Morph } from "../parse/tuple/morph.js";
|
|
3
|
+
import type { Domain } from "../utils/domains.js";
|
|
4
|
+
import type { CollapsibleList, defined, Dict, xor } from "../utils/generics.js";
|
|
5
|
+
import type { BranchesComparison } from "./branches.js";
|
|
6
|
+
import type { IntersectionResult, KeyIntersectionFn } from "./compose.js";
|
|
7
|
+
import { IntersectionState } from "./compose.js";
|
|
8
|
+
import type { FlattenContext, ResolvedNode, TraversalEntry } from "./node.js";
|
|
9
|
+
import type { LiteralRules, Rules } from "./rules/rules.js";
|
|
10
|
+
export type Predicate<domain extends Domain = Domain, $ = Dict> = string extends keyof $ ? true | CollapsibleList<Branch> : true | CollapsibleList<Branch<domain, $>>;
|
|
11
|
+
export type Branch<domain extends Domain = Domain, $ = Dict> = xor<Rules<domain, $>, {
|
|
12
|
+
input: Rules<domain, $>;
|
|
13
|
+
morph: CollapsibleList<Morph>;
|
|
14
|
+
}>;
|
|
15
|
+
export type PredicateComparison = IntersectionResult<Predicate> | BranchesComparison;
|
|
16
|
+
export declare const comparePredicates: (l: Predicate, r: Predicate, context: IntersectionState) => PredicateComparison;
|
|
17
|
+
export declare const predicateIntersection: KeyIntersectionFn<Required<ResolvedNode>>;
|
|
18
|
+
export declare const predicateUnion: (domain: Domain, l: Predicate, r: Predicate, type: Type) => true | {
|
|
19
|
+
readonly subdomain?: import("./rules/subdomain.js").SubdomainRule<Dict>;
|
|
20
|
+
readonly regex?: CollapsibleList<string>;
|
|
21
|
+
readonly divisor?: number;
|
|
22
|
+
readonly range?: import("./rules/range.js").Range;
|
|
23
|
+
readonly props?: import("./rules/props.js").PropsRule<Dict>;
|
|
24
|
+
readonly class?: import("../utils/generics.js").constructor;
|
|
25
|
+
readonly narrow?: import("./rules/rules.js").NarrowRule;
|
|
26
|
+
input?: undefined;
|
|
27
|
+
morph?: undefined;
|
|
28
|
+
} | {
|
|
29
|
+
readonly value: unknown;
|
|
30
|
+
input?: undefined;
|
|
31
|
+
morph?: undefined;
|
|
32
|
+
} | {
|
|
33
|
+
input: import("./rules/rules.js").NarrowableRules<Dict> | LiteralRules<Domain>;
|
|
34
|
+
morph: CollapsibleList<Morph>;
|
|
35
|
+
readonly subdomain?: undefined;
|
|
36
|
+
readonly regex?: undefined;
|
|
37
|
+
readonly divisor?: undefined;
|
|
38
|
+
readonly range?: undefined;
|
|
39
|
+
readonly props?: undefined;
|
|
40
|
+
readonly class?: undefined;
|
|
41
|
+
readonly narrow?: undefined;
|
|
42
|
+
} | {
|
|
43
|
+
input: import("./rules/rules.js").NarrowableRules<Dict> | LiteralRules<Domain>;
|
|
44
|
+
morph: CollapsibleList<Morph>;
|
|
45
|
+
readonly value?: undefined;
|
|
46
|
+
} | readonly Branch<Domain, Dict>[];
|
|
47
|
+
export declare const flattenPredicate: (predicate: Predicate, context: FlattenContext) => TraversalEntry[];
|
|
48
|
+
export declare const isLiteralCondition: (predicate: Predicate) => predicate is LiteralRules;
|
|
49
|
+
export type DomainSubtypeResolution<domain extends Domain> = {
|
|
50
|
+
readonly [k in domain]: defined<ResolvedNode[domain]>;
|
|
51
|
+
};
|
|
52
|
+
export declare const resolutionExtendsDomain: <domain extends Domain>(resolution: ResolvedNode, domain: domain) => resolution is DomainSubtypeResolution<domain>;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { constructor } from "../../utils/generics.js";
|
|
2
|
+
export declare const classIntersection: import("../compose.js").Intersector<constructor | undefined>;
|
|
3
|
+
export declare const checkClass: (data: object, expectedClass: constructor, state: import("../../traverse/traverse.js").TraversalState) => void;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { CollapsibleList, List } from "../../utils/generics.js";
|
|
2
|
+
import type { Equal } from "../compose.js";
|
|
3
|
+
export declare const collapsibleListUnion: <t>(l: CollapsibleList<t>, r: CollapsibleList<t>) => CollapsibleList<t> | Equal;
|
|
4
|
+
export declare const listUnion: <t extends List>(l: t, r: t) => t[number][];
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Dict } from "../../utils/generics.js";
|
|
2
|
+
import type { TraversalNode, TypeNode } from "../node.js";
|
|
3
|
+
import type { FlattenAndPushRule } from "./rules.js";
|
|
4
|
+
export type PropsRule<$ = Dict> = {
|
|
5
|
+
[propKey in string]: Prop<$>;
|
|
6
|
+
};
|
|
7
|
+
export type Prop<$ = Dict> = TypeNode<$> | OptionalProp<$>;
|
|
8
|
+
export type OptionalProp<$ = Dict> = ["?", TypeNode<$>];
|
|
9
|
+
export type TraversalRequiredProps = [
|
|
10
|
+
"requiredProps",
|
|
11
|
+
readonly TraversalPropEntry[]
|
|
12
|
+
];
|
|
13
|
+
export type TraversalOptionalProps = [
|
|
14
|
+
"optionalProps",
|
|
15
|
+
readonly TraversalPropEntry[]
|
|
16
|
+
];
|
|
17
|
+
export type TraversalPropEntry = [propKey: string, node: TraversalNode];
|
|
18
|
+
export declare const isOptional: (prop: Prop) => prop is OptionalProp<Dict>;
|
|
19
|
+
export declare const propsIntersection: import("../compose.js").Intersector<PropsRule<Dict> | undefined>;
|
|
20
|
+
export declare const flattenProps: FlattenAndPushRule<PropsRule>;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { Scanner } from "../../parse/string/shift/scanner.js";
|
|
2
|
+
import type { evaluate } from "../../utils/generics.js";
|
|
3
|
+
import type { FlattenAndPushRule } from "./rules.js";
|
|
4
|
+
export type Range = DoubleBound | Bound<"==">;
|
|
5
|
+
export type DoubleBound = {
|
|
6
|
+
min?: LowerBound;
|
|
7
|
+
max?: UpperBound;
|
|
8
|
+
};
|
|
9
|
+
export type BoundKind = evaluate<keyof DoubleBound>;
|
|
10
|
+
export declare const minComparators: {
|
|
11
|
+
readonly ">": true;
|
|
12
|
+
readonly ">=": true;
|
|
13
|
+
};
|
|
14
|
+
export type MinComparator = keyof typeof minComparators;
|
|
15
|
+
export type LowerBound = Bound<MinComparator>;
|
|
16
|
+
export declare const maxComparators: {
|
|
17
|
+
readonly "<": true;
|
|
18
|
+
readonly "<=": true;
|
|
19
|
+
};
|
|
20
|
+
export type MaxComparator = keyof typeof maxComparators;
|
|
21
|
+
export type UpperBound = Bound<MaxComparator>;
|
|
22
|
+
export type Bound<comparator extends Scanner.Comparator = Scanner.Comparator> = {
|
|
23
|
+
readonly comparator: comparator;
|
|
24
|
+
readonly limit: number;
|
|
25
|
+
};
|
|
26
|
+
export declare const isEqualityRange: (range: Range) => range is Bound<"==">;
|
|
27
|
+
export declare const rangeIntersection: import("../compose.js").Intersector<Range | undefined>;
|
|
28
|
+
export type FlatBound = Bound & {
|
|
29
|
+
units?: string;
|
|
30
|
+
};
|
|
31
|
+
export declare const flattenRange: FlattenAndPushRule<Range>;
|
|
32
|
+
export declare const checkBound: (data: import("../../utils/domains.js").SizedData, bound: FlatBound, state: import("../../traverse/traverse.js").TraversalState) => void;
|
|
33
|
+
export declare const compareStrictness: (kind: "min" | "max", l: Bound | undefined, r: Bound | undefined) => "=" | "r" | "l";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { CollapsibleList } from "../../utils/generics.js";
|
|
2
|
+
export declare const sources: {
|
|
3
|
+
alpha: RegExp;
|
|
4
|
+
alphanumeric: RegExp;
|
|
5
|
+
lowercase: RegExp;
|
|
6
|
+
uppercase: RegExp;
|
|
7
|
+
creditCard: RegExp;
|
|
8
|
+
email: RegExp;
|
|
9
|
+
uuid: RegExp;
|
|
10
|
+
};
|
|
11
|
+
export declare const getRegex: (source: string) => RegExp;
|
|
12
|
+
export declare const checkRegex: (data: string, regex: RegExp, state: import("../../traverse/traverse.js").TraversalState) => void;
|
|
13
|
+
export declare const regexIntersection: import("../compose.js").Intersector<CollapsibleList<string> | undefined>;
|
|
14
|
+
export declare const isLuhnValid: (creditCardInput: string) => boolean;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Morph } from "../../parse/tuple/morph.js";
|
|
2
|
+
import type { Narrow } from "../../parse/tuple/narrow.js";
|
|
3
|
+
import type { Domain, inferDomain } from "../../utils/domains.js";
|
|
4
|
+
import type { CollapsibleList, constructor, Dict } from "../../utils/generics.js";
|
|
5
|
+
import type { IntersectionState, Intersector } from "../compose.js";
|
|
6
|
+
import type { FlattenContext, TraversalEntry } from "../node.js";
|
|
7
|
+
import type { PropsRule, TraversalOptionalProps, TraversalRequiredProps } from "./props.js";
|
|
8
|
+
import type { FlatBound, Range } from "./range.js";
|
|
9
|
+
import type { SubdomainRule, TraversalSubdomainRule } from "./subdomain.js";
|
|
10
|
+
export type NarrowableRules<$ = Dict> = {
|
|
11
|
+
readonly subdomain?: SubdomainRule<$>;
|
|
12
|
+
readonly regex?: CollapsibleList<string>;
|
|
13
|
+
readonly divisor?: number;
|
|
14
|
+
readonly range?: Range;
|
|
15
|
+
readonly props?: PropsRule<$>;
|
|
16
|
+
readonly class?: constructor;
|
|
17
|
+
readonly narrow?: NarrowRule;
|
|
18
|
+
};
|
|
19
|
+
export type LiteralRules<domain extends Domain = Domain> = {
|
|
20
|
+
readonly value: inferDomain<domain>;
|
|
21
|
+
};
|
|
22
|
+
export type NarrowRule = CollapsibleList<Narrow>;
|
|
23
|
+
export type Branch<domain extends Domain = Domain, $ = Dict> = Rules<domain, $> | MorphBranch<domain, $>;
|
|
24
|
+
export type MorphBranch<domain extends Domain = Domain, $ = Dict> = {
|
|
25
|
+
input: Rules<domain, $>;
|
|
26
|
+
morph: CollapsibleList<Morph>;
|
|
27
|
+
};
|
|
28
|
+
export type FlatBranch = FlatRules | FlatMorphedBranch;
|
|
29
|
+
export type FlatRules = RuleEntry[];
|
|
30
|
+
type FlatMorphedBranch = [...rules: FlatRules, morph: MorphEntry];
|
|
31
|
+
export type RuleEntry = ["subdomain", TraversalSubdomainRule] | ["regex", RegExp] | ["divisor", number] | ["bound", FlatBound] | ["class", constructor] | TraversalRequiredProps | TraversalOptionalProps | ["narrow", Narrow] | ["value", unknown];
|
|
32
|
+
export type MorphEntry = ["morph", CollapsibleList<Morph>];
|
|
33
|
+
export type Rules<domain extends Domain = Domain, $ = Dict> = Domain extends domain ? NarrowableRules | LiteralRules : domain extends "object" ? defineRuleSet<domain, "subdomain" | "props" | "range" | "narrow" | "class", $> : domain extends "string" ? defineRuleSet<domain, "regex" | "range" | "narrow", $> : domain extends "number" ? defineRuleSet<domain, "divisor" | "range" | "narrow", $> : defineRuleSet<domain, "narrow", $>;
|
|
34
|
+
type defineRuleSet<domain extends Domain, keys extends keyof NarrowableRules, $> = Pick<NarrowableRules<$>, keys> | LiteralRules<domain>;
|
|
35
|
+
export declare const branchIntersection: Intersector<Branch>;
|
|
36
|
+
export declare const rulesIntersection: Intersector<Rules>;
|
|
37
|
+
export declare const narrowableRulesIntersection: Intersector<NarrowableRules<Dict>>;
|
|
38
|
+
export type FlattenAndPushRule<t> = (entries: RuleEntry[], rule: t, ctx: FlattenContext) => void;
|
|
39
|
+
export declare const precedenceMap: {
|
|
40
|
+
readonly [k in TraversalEntry[0]]: number;
|
|
41
|
+
};
|
|
42
|
+
export declare const flattenBranch: (branch: Branch, ctx: FlattenContext) => FlatBranch;
|
|
43
|
+
export declare const literalSatisfiesRules: (data: unknown, rules: NarrowableRules, state: IntersectionState) => boolean;
|
|
44
|
+
export {};
|