arktype 0.1.3 → 0.2.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/README.md +1 -1
- package/dist/api.cjs +4 -3
- package/dist/api.d.ts +3 -2
- package/dist/api.mjs +2 -1
- package/dist/cjs/nodes/node.js +20 -2
- package/dist/cjs/nodes/predicate.js +2 -0
- package/dist/cjs/nodes/rules/regex.js +4 -42
- package/dist/cjs/nodes/rules/rules.js +16 -12
- package/dist/cjs/parse/definition.js +2 -2
- package/dist/cjs/parse/string/ast.js +1 -1
- package/dist/cjs/parse/tuple/keyof.js +6 -7
- package/dist/cjs/parse/tuple/morph.js +7 -6
- package/dist/cjs/scopes/cache.js +39 -0
- package/dist/cjs/scopes/jsObjects.js +133 -0
- package/dist/cjs/scopes/scope.js +244 -0
- package/dist/cjs/scopes/standard.js +44 -0
- package/dist/cjs/scopes/tsKeywords.js +113 -0
- package/dist/cjs/scopes/type.js +70 -0
- package/dist/cjs/scopes/validation.js +64 -0
- package/dist/cjs/traverse/problems.js +50 -74
- package/dist/cjs/traverse/traverse.js +25 -3
- package/dist/cjs/utils/numericLiterals.js +1 -0
- package/dist/mjs/nodes/node.js +20 -2
- package/dist/mjs/nodes/predicate.js +1 -0
- package/dist/mjs/nodes/rules/regex.js +3 -41
- package/dist/mjs/nodes/rules/rules.js +17 -13
- package/dist/mjs/parse/definition.js +1 -1
- package/dist/mjs/parse/string/ast.js +1 -1
- package/dist/mjs/parse/tuple/keyof.js +6 -7
- package/dist/mjs/parse/tuple/morph.js +7 -6
- package/dist/mjs/scopes/cache.js +25 -0
- package/dist/mjs/scopes/jsObjects.js +119 -0
- package/dist/mjs/{main.js → scopes/scope.js} +23 -349
- package/dist/mjs/scopes/standard.js +27 -0
- package/dist/mjs/scopes/tsKeywords.js +99 -0
- package/dist/mjs/scopes/type.js +56 -0
- package/dist/mjs/scopes/validation.js +51 -0
- package/dist/mjs/traverse/problems.js +49 -73
- package/dist/mjs/traverse/traverse.js +26 -4
- package/dist/mjs/utils/numericLiterals.js +1 -1
- package/dist/tsconfig.temp.tsbuildinfo +1 -1
- package/dist/types/nodes/compose.d.ts +1 -1
- package/dist/types/nodes/infer.d.ts +4 -4
- package/dist/types/nodes/node.d.ts +11 -7
- package/dist/types/nodes/predicate.d.ts +43 -54
- package/dist/types/nodes/rules/range.d.ts +1 -1
- package/dist/types/nodes/rules/regex.d.ts +1 -11
- package/dist/types/nodes/rules/rules.d.ts +2 -10
- package/dist/types/parse/definition.d.ts +1 -1
- package/dist/types/parse/record.d.ts +2 -2
- package/dist/types/parse/string/ast.d.ts +5 -4
- package/dist/types/parse/string/reduce/dynamic.d.ts +1 -1
- package/dist/types/parse/string/reduce/shared.d.ts +1 -1
- package/dist/types/parse/string/reduce/static.d.ts +1 -1
- package/dist/types/parse/string/shift/operand/unenclosed.d.ts +1 -1
- package/dist/types/parse/string/shift/operator/bounds.d.ts +1 -1
- package/dist/types/parse/tuple/keyof.d.ts +8 -0
- package/dist/types/parse/tuple/morph.d.ts +1 -1
- package/dist/types/parse/tuple/narrow.d.ts +1 -1
- package/dist/types/parse/tuple/tuple.d.ts +7 -13
- package/dist/types/scopes/cache.d.ts +14 -0
- package/dist/types/scopes/jsObjects.d.ts +36 -0
- package/dist/types/scopes/scope.d.ts +76 -0
- package/dist/types/scopes/standard.d.ts +280 -0
- package/dist/types/scopes/tsKeywords.d.ts +32 -0
- package/dist/types/scopes/type.d.ts +53 -0
- package/dist/types/scopes/validation.d.ts +21 -0
- package/dist/types/traverse/problems.d.ts +29 -32
- package/dist/types/traverse/traverse.d.ts +10 -8
- package/dist/types/utils/generics.d.ts +2 -1
- package/dist/types/utils/numericLiterals.d.ts +1 -0
- package/package.json +2 -2
- package/dist/cjs/main.js +0 -574
- package/dist/types/main.d.ts +0 -321
package/dist/types/main.d.ts
DELETED
|
@@ -1,321 +0,0 @@
|
|
|
1
|
-
import type { ResolvedNode, TraversalNode, TypeNode } from "./nodes/node.js";
|
|
2
|
-
import type { as, inferDefinition, ParseContext, validateDefinition } from "./parse/definition.js";
|
|
3
|
-
import type { ParsedMorph } from "./parse/tuple/morph.js";
|
|
4
|
-
import type { Problems, ProblemsConfig, ProblemsOptions } from "./traverse/problems.js";
|
|
5
|
-
import type { defer, Dict, error, evaluateObject, isAny, List, nominal } from "./utils/generics.js";
|
|
6
|
-
import type { BuiltinClass, InferredObjectKinds } from "./utils/objectKinds.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> = evaluateObject<{
|
|
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
|
-
createAnonymousTypeName(): string;
|
|
65
|
-
get infer(): exportsOf<context>;
|
|
66
|
-
compile(): Space<exportsOf<context>>;
|
|
67
|
-
addReferenceIfResolvable(name: name<context>, ctx: ParseContext): boolean;
|
|
68
|
-
resolve(name: name<context>): Type<unknown>;
|
|
69
|
-
resolveNode(node: TypeNode): ResolvedNode;
|
|
70
|
-
}
|
|
71
|
-
type TypeRoot<t = unknown> = {
|
|
72
|
-
[as]: t;
|
|
73
|
-
infer: asOut<t>;
|
|
74
|
-
node: TypeNode;
|
|
75
|
-
flat: TraversalNode;
|
|
76
|
-
meta: TypeMeta;
|
|
77
|
-
};
|
|
78
|
-
type TypeMeta = {
|
|
79
|
-
name: string;
|
|
80
|
-
id: QualifiedTypeName;
|
|
81
|
-
definition: unknown;
|
|
82
|
-
scope: Scope;
|
|
83
|
-
problems: ProblemsConfig;
|
|
84
|
-
includesMorph: boolean;
|
|
85
|
-
};
|
|
86
|
-
declare class Cache<item = unknown> {
|
|
87
|
-
protected cache: {
|
|
88
|
-
[name in string]?: item;
|
|
89
|
-
};
|
|
90
|
-
get root(): {
|
|
91
|
-
readonly [name in string]?: item;
|
|
92
|
-
};
|
|
93
|
-
has(name: string): boolean;
|
|
94
|
-
get(name: string): item | undefined;
|
|
95
|
-
set(name: string, item: item): item;
|
|
96
|
-
}
|
|
97
|
-
declare class FreezingCache<item = unknown> extends Cache<item> {
|
|
98
|
-
set(name: string, item: item): item;
|
|
99
|
-
}
|
|
100
|
-
export declare const writeShallowCycleErrorMessage: (name: string, seen: string[]) => string;
|
|
101
|
-
export declare const scope: ScopeParser;
|
|
102
|
-
export declare const scopes: {
|
|
103
|
-
tsKeywords: Scope<[{
|
|
104
|
-
any: any;
|
|
105
|
-
bigint: bigint;
|
|
106
|
-
boolean: boolean;
|
|
107
|
-
false: false;
|
|
108
|
-
never: never;
|
|
109
|
-
null: null;
|
|
110
|
-
number: number;
|
|
111
|
-
object: object;
|
|
112
|
-
string: string;
|
|
113
|
-
symbol: symbol;
|
|
114
|
-
true: true;
|
|
115
|
-
unknown: unknown;
|
|
116
|
-
void: void;
|
|
117
|
-
undefined: undefined;
|
|
118
|
-
}, {}, false]>;
|
|
119
|
-
jsObjects: Scope<[{
|
|
120
|
-
Function: (...args: any[]) => unknown;
|
|
121
|
-
Array: unknown[];
|
|
122
|
-
Date: Date;
|
|
123
|
-
Error: Error;
|
|
124
|
-
Map: Map<unknown, unknown>;
|
|
125
|
-
RegExp: RegExp;
|
|
126
|
-
Set: Set<unknown>;
|
|
127
|
-
Object: {
|
|
128
|
-
[x: string]: unknown;
|
|
129
|
-
};
|
|
130
|
-
String: String;
|
|
131
|
-
Number: Number;
|
|
132
|
-
Boolean: Boolean;
|
|
133
|
-
WeakMap: WeakMap<object, unknown>;
|
|
134
|
-
WeakSet: WeakSet<object>;
|
|
135
|
-
Promise: Promise<unknown>;
|
|
136
|
-
}, {}, false]>;
|
|
137
|
-
validation: Scope<[{
|
|
138
|
-
email: string;
|
|
139
|
-
alphanumeric: string;
|
|
140
|
-
alpha: string;
|
|
141
|
-
lowercase: string;
|
|
142
|
-
uppercase: string;
|
|
143
|
-
integer: number;
|
|
144
|
-
}, {}, false]>;
|
|
145
|
-
standard: Scope<[{
|
|
146
|
-
any: any;
|
|
147
|
-
bigint: bigint;
|
|
148
|
-
boolean: boolean;
|
|
149
|
-
false: false;
|
|
150
|
-
never: never;
|
|
151
|
-
null: null;
|
|
152
|
-
number: number;
|
|
153
|
-
object: object;
|
|
154
|
-
string: string;
|
|
155
|
-
symbol: symbol;
|
|
156
|
-
true: true;
|
|
157
|
-
unknown: unknown;
|
|
158
|
-
void: void;
|
|
159
|
-
undefined: undefined;
|
|
160
|
-
Function: (...args: any[]) => unknown;
|
|
161
|
-
Array: unknown[];
|
|
162
|
-
Date: Date;
|
|
163
|
-
Error: Error;
|
|
164
|
-
Map: Map<unknown, unknown>;
|
|
165
|
-
RegExp: RegExp;
|
|
166
|
-
Set: Set<unknown>;
|
|
167
|
-
Object: {
|
|
168
|
-
[x: string]: unknown;
|
|
169
|
-
};
|
|
170
|
-
String: String;
|
|
171
|
-
Number: Number;
|
|
172
|
-
Boolean: Boolean;
|
|
173
|
-
WeakMap: WeakMap<object, unknown>;
|
|
174
|
-
WeakSet: WeakSet<object>;
|
|
175
|
-
Promise: Promise<unknown>;
|
|
176
|
-
email: string;
|
|
177
|
-
alphanumeric: string;
|
|
178
|
-
alpha: string;
|
|
179
|
-
lowercase: string;
|
|
180
|
-
uppercase: string;
|
|
181
|
-
integer: number;
|
|
182
|
-
}, {}, false]>;
|
|
183
|
-
};
|
|
184
|
-
export declare const spaces: {
|
|
185
|
-
tsKeywords: Space<{
|
|
186
|
-
any: any;
|
|
187
|
-
bigint: bigint;
|
|
188
|
-
boolean: boolean;
|
|
189
|
-
false: false;
|
|
190
|
-
never: never;
|
|
191
|
-
null: null;
|
|
192
|
-
number: number;
|
|
193
|
-
object: object;
|
|
194
|
-
string: string;
|
|
195
|
-
symbol: symbol;
|
|
196
|
-
true: true;
|
|
197
|
-
unknown: unknown;
|
|
198
|
-
void: void;
|
|
199
|
-
undefined: undefined;
|
|
200
|
-
}>;
|
|
201
|
-
jsObjects: Space<{
|
|
202
|
-
Function: (...args: any[]) => unknown;
|
|
203
|
-
Array: unknown[];
|
|
204
|
-
Date: Date;
|
|
205
|
-
Error: Error;
|
|
206
|
-
Map: Map<unknown, unknown>;
|
|
207
|
-
RegExp: RegExp;
|
|
208
|
-
Set: Set<unknown>;
|
|
209
|
-
Object: {
|
|
210
|
-
[x: string]: unknown;
|
|
211
|
-
};
|
|
212
|
-
String: String;
|
|
213
|
-
Number: Number;
|
|
214
|
-
Boolean: Boolean;
|
|
215
|
-
WeakMap: WeakMap<object, unknown>;
|
|
216
|
-
WeakSet: WeakSet<object>;
|
|
217
|
-
Promise: Promise<unknown>;
|
|
218
|
-
}>;
|
|
219
|
-
validation: Space<{
|
|
220
|
-
email: string;
|
|
221
|
-
alphanumeric: string;
|
|
222
|
-
alpha: string;
|
|
223
|
-
lowercase: string;
|
|
224
|
-
uppercase: string;
|
|
225
|
-
integer: number;
|
|
226
|
-
}>;
|
|
227
|
-
standard: Space<{
|
|
228
|
-
any: any;
|
|
229
|
-
bigint: bigint;
|
|
230
|
-
boolean: boolean;
|
|
231
|
-
false: false;
|
|
232
|
-
never: never;
|
|
233
|
-
null: null;
|
|
234
|
-
number: number;
|
|
235
|
-
object: object;
|
|
236
|
-
string: string;
|
|
237
|
-
symbol: symbol;
|
|
238
|
-
true: true;
|
|
239
|
-
unknown: unknown;
|
|
240
|
-
void: void;
|
|
241
|
-
undefined: undefined;
|
|
242
|
-
Function: (...args: any[]) => unknown;
|
|
243
|
-
Array: unknown[];
|
|
244
|
-
Date: Date;
|
|
245
|
-
Error: Error;
|
|
246
|
-
Map: Map<unknown, unknown>;
|
|
247
|
-
RegExp: RegExp;
|
|
248
|
-
Set: Set<unknown>;
|
|
249
|
-
Object: {
|
|
250
|
-
[x: string]: unknown;
|
|
251
|
-
};
|
|
252
|
-
String: String;
|
|
253
|
-
Number: Number;
|
|
254
|
-
Boolean: Boolean;
|
|
255
|
-
WeakMap: WeakMap<object, unknown>;
|
|
256
|
-
WeakSet: WeakSet<object>;
|
|
257
|
-
Promise: Promise<unknown>;
|
|
258
|
-
email: string;
|
|
259
|
-
alphanumeric: string;
|
|
260
|
-
alpha: string;
|
|
261
|
-
lowercase: string;
|
|
262
|
-
uppercase: string;
|
|
263
|
-
integer: number;
|
|
264
|
-
}>;
|
|
265
|
-
};
|
|
266
|
-
export type PrecompiledDefaults = {
|
|
267
|
-
email: string;
|
|
268
|
-
alphanumeric: string;
|
|
269
|
-
alpha: string;
|
|
270
|
-
lowercase: string;
|
|
271
|
-
uppercase: string;
|
|
272
|
-
integer: number;
|
|
273
|
-
any: any;
|
|
274
|
-
bigint: bigint;
|
|
275
|
-
boolean: boolean;
|
|
276
|
-
false: false;
|
|
277
|
-
never: never;
|
|
278
|
-
null: null;
|
|
279
|
-
number: number;
|
|
280
|
-
object: object;
|
|
281
|
-
string: string;
|
|
282
|
-
symbol: symbol;
|
|
283
|
-
true: true;
|
|
284
|
-
unknown: unknown;
|
|
285
|
-
void: void;
|
|
286
|
-
undefined: undefined;
|
|
287
|
-
} & InferredObjectKinds;
|
|
288
|
-
export declare const type: TypeParser<PrecompiledDefaults>;
|
|
289
|
-
export declare const writeDuplicateAliasMessage: <name_1 extends string>(name: name_1) => `Alias '${name_1}' is already defined`;
|
|
290
|
-
type writeDuplicateAliasMessage<name extends string> = `Alias '${name}' is already defined`;
|
|
291
|
-
export declare const isType: (value: unknown) => value is Type<unknown>;
|
|
292
|
-
export type parseType<def, $> = def extends validateDefinition<def, $> ? Type<inferDefinition<def, $>> : never;
|
|
293
|
-
export type CheckResult<t> = ValidCheckResult<t> | InvalidCheckResult;
|
|
294
|
-
type ValidCheckResult<t> = {
|
|
295
|
-
data: asIn<t>;
|
|
296
|
-
out: asOut<t>;
|
|
297
|
-
problems?: never;
|
|
298
|
-
};
|
|
299
|
-
type InvalidCheckResult = {
|
|
300
|
-
data: unknown;
|
|
301
|
-
problems: Problems;
|
|
302
|
-
out?: never;
|
|
303
|
-
};
|
|
304
|
-
type Checker<t> = (data: unknown) => CheckResult<t>;
|
|
305
|
-
export type Type<t = unknown> = defer<Checker<t> & TypeRoot<t>>;
|
|
306
|
-
export type TypeOptions = {
|
|
307
|
-
name?: string;
|
|
308
|
-
problems?: ProblemsOptions;
|
|
309
|
-
};
|
|
310
|
-
export type QualifiedTypeName = `${string}.${string}`;
|
|
311
|
-
export type TypeConfig = {
|
|
312
|
-
name: string;
|
|
313
|
-
id: QualifiedTypeName;
|
|
314
|
-
problems: ProblemsConfig;
|
|
315
|
-
};
|
|
316
|
-
export type asIn<t> = asIo<t, "in">;
|
|
317
|
-
export type asOut<t> = asIo<t, "out">;
|
|
318
|
-
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 | BuiltinClass ? t : {
|
|
319
|
-
[k in keyof t]: asIo<t[k], io>;
|
|
320
|
-
} : t;
|
|
321
|
-
export {};
|