arktype 2.0.0-dev.2 → 2.0.0-dev.20
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/out/api.d.ts +6 -0
- package/out/api.js +5 -0
- package/out/ark.d.ts +15 -39
- package/out/ark.js +9 -18
- package/out/config.d.ts +1 -0
- package/out/config.js +2 -0
- package/out/generic.d.ts +21 -0
- package/out/generic.js +24 -0
- package/out/match.d.ts +18 -24
- package/out/match.js +50 -60
- package/out/module.d.ts +11 -0
- package/out/module.js +2 -0
- package/out/parser/definition.d.ts +13 -15
- package/out/parser/definition.js +10 -13
- package/out/parser/generic.d.ts +5 -7
- package/out/parser/generic.js +7 -11
- package/out/parser/objectLiteral.d.ts +57 -18
- package/out/parser/objectLiteral.js +93 -52
- package/out/parser/semantic/bounds.d.ts +10 -8
- package/out/parser/semantic/bounds.js +0 -1
- package/out/parser/semantic/divisor.d.ts +5 -7
- package/out/parser/semantic/divisor.js +0 -1
- package/out/parser/semantic/infer.d.ts +24 -0
- package/out/parser/semantic/infer.js +1 -0
- package/out/parser/semantic/utils.d.ts +3 -7
- package/out/parser/semantic/utils.js +0 -1
- package/out/parser/semantic/validate.d.ts +16 -13
- package/out/parser/semantic/validate.js +1 -1
- package/out/parser/string/reduce/dynamic.d.ts +13 -13
- package/out/parser/string/reduce/dynamic.js +31 -26
- package/out/parser/string/reduce/shared.d.ts +14 -28
- package/out/parser/string/reduce/shared.js +4 -3
- package/out/parser/string/reduce/static.d.ts +26 -23
- package/out/parser/string/reduce/static.js +0 -1
- package/out/parser/string/shift/operand/date.d.ts +2 -2
- package/out/parser/string/shift/operand/date.js +4 -7
- package/out/parser/string/shift/operand/enclosed.d.ts +3 -4
- package/out/parser/string/shift/operand/enclosed.js +14 -14
- package/out/parser/string/shift/operand/genericArgs.d.ts +9 -10
- package/out/parser/string/shift/operand/genericArgs.js +6 -10
- package/out/parser/string/shift/operand/operand.d.ts +3 -4
- package/out/parser/string/shift/operand/operand.js +9 -13
- package/out/parser/string/shift/operand/unenclosed.d.ts +15 -20
- package/out/parser/string/shift/operand/unenclosed.js +24 -36
- package/out/parser/string/shift/operator/bounds.d.ts +8 -12
- package/out/parser/string/shift/operator/bounds.js +45 -56
- package/out/parser/string/shift/operator/divisor.d.ts +1 -3
- package/out/parser/string/shift/operator/divisor.js +1 -3
- package/out/parser/string/shift/operator/operator.d.ts +1 -2
- package/out/parser/string/shift/operator/operator.js +12 -19
- package/out/parser/string/shift/scanner.d.ts +8 -7
- package/out/parser/string/shift/scanner.js +17 -16
- package/out/parser/string/string.d.ts +9 -7
- package/out/parser/string/string.js +1 -3
- package/out/parser/tuple.d.ts +101 -42
- package/out/parser/tuple.js +107 -86
- package/out/scope.d.ts +44 -115
- package/out/scope.js +39 -188
- package/out/type.d.ts +63 -61
- package/out/type.js +30 -135
- package/package.json +33 -39
- package/__tests__/array.test.ts +0 -310
- package/__tests__/astUtils.test.ts +0 -17
- package/__tests__/badDefinitionType.test.ts +0 -51
- package/__tests__/basis.test.ts +0 -46
- package/__tests__/bounds.test.ts +0 -388
- package/__tests__/cast.test.ts +0 -32
- package/__tests__/completions.test.ts +0 -46
- package/__tests__/config.test.ts +0 -77
- package/__tests__/cyclic.test.ts +0 -144
- package/__tests__/dateLiteral.test.ts +0 -32
- package/__tests__/declared.test.ts +0 -124
- package/__tests__/discrimination.test.ts +0 -74
- package/__tests__/divisor.test.ts +0 -90
- package/__tests__/enclosed.test.ts +0 -93
- package/__tests__/examples.test.ts +0 -56
- package/__tests__/expressions.test.ts +0 -138
- package/__tests__/generateBenchData.ts +0 -89
- package/__tests__/generated/cyclic.ts +0 -3058
- package/__tests__/generic.test.ts +0 -294
- package/__tests__/group.test.ts +0 -72
- package/__tests__/hkt.test.ts +0 -22
- package/__tests__/imports.test.ts +0 -113
- package/__tests__/instanceof.test.ts +0 -102
- package/__tests__/intersection.test.ts +0 -104
- package/__tests__/jsdoc.test.ts +0 -64
- package/__tests__/keyTraversal.test.ts +0 -74
- package/__tests__/keyof.test.ts +0 -134
- package/__tests__/keywords.test.ts +0 -188
- package/__tests__/literal.test.ts +0 -51
- package/__tests__/match.bench.ts +0 -31
- package/__tests__/match.test.ts +0 -224
- package/__tests__/methods.bench.ts +0 -22
- package/__tests__/morph.test.ts +0 -409
- package/__tests__/narrow.test.ts +0 -102
- package/__tests__/nodeDefinitions.test.ts +0 -190
- package/__tests__/object.bench.ts +0 -28
- package/__tests__/objectLiteral.test.ts +0 -301
- package/__tests__/operand.bench.ts +0 -45
- package/__tests__/operator.bench.ts +0 -130
- package/__tests__/regex.test.ts +0 -58
- package/__tests__/scope.bench.ts +0 -39
- package/__tests__/scope.test.ts +0 -140
- package/__tests__/string.test.ts +0 -48
- package/__tests__/submodule.test.ts +0 -99
- package/__tests__/this.test.ts +0 -57
- package/__tests__/thunk.test.ts +0 -80
- package/__tests__/traverse.test.ts +0 -119
- package/__tests__/tsGenerics.test.ts +0 -12
- package/__tests__/typeMethods.test.ts +0 -69
- package/__tests__/typeReference.test.ts +0 -39
- package/__tests__/unenclosed.test.ts +0 -120
- package/__tests__/union.test.ts +0 -147
- package/ark.ts +0 -91
- package/main.ts +0 -18
- package/match.ts +0 -243
- package/out/ark.d.ts.map +0 -1
- package/out/ark.js.map +0 -1
- package/out/arkConfig.d.ts +0 -2
- package/out/arkConfig.d.ts.map +0 -1
- package/out/arkConfig.js +0 -10
- package/out/arkConfig.js.map +0 -1
- package/out/main.d.ts +0 -7
- package/out/main.d.ts.map +0 -1
- package/out/main.js +0 -4
- package/out/main.js.map +0 -1
- package/out/match.d.ts.map +0 -1
- package/out/match.js.map +0 -1
- package/out/parser/definition.d.ts.map +0 -1
- package/out/parser/definition.js.map +0 -1
- package/out/parser/generic.d.ts.map +0 -1
- package/out/parser/generic.js.map +0 -1
- package/out/parser/objectLiteral.d.ts.map +0 -1
- package/out/parser/objectLiteral.js.map +0 -1
- package/out/parser/semantic/bounds.d.ts.map +0 -1
- package/out/parser/semantic/bounds.js.map +0 -1
- package/out/parser/semantic/divisor.d.ts.map +0 -1
- package/out/parser/semantic/divisor.js.map +0 -1
- package/out/parser/semantic/intersections.d.ts +0 -14
- package/out/parser/semantic/intersections.d.ts.map +0 -1
- package/out/parser/semantic/intersections.js +0 -2
- package/out/parser/semantic/intersections.js.map +0 -1
- package/out/parser/semantic/semantic.d.ts +0 -33
- package/out/parser/semantic/semantic.d.ts.map +0 -1
- package/out/parser/semantic/semantic.js +0 -2
- package/out/parser/semantic/semantic.js.map +0 -1
- package/out/parser/semantic/utils.d.ts.map +0 -1
- package/out/parser/semantic/utils.js.map +0 -1
- package/out/parser/semantic/validate.d.ts.map +0 -1
- package/out/parser/semantic/validate.js.map +0 -1
- package/out/parser/shared.d.ts +0 -56
- package/out/parser/shared.d.ts.map +0 -1
- package/out/parser/shared.js +0 -55
- package/out/parser/shared.js.map +0 -1
- package/out/parser/string/reduce/dynamic.d.ts.map +0 -1
- package/out/parser/string/reduce/dynamic.js.map +0 -1
- package/out/parser/string/reduce/shared.d.ts.map +0 -1
- package/out/parser/string/reduce/shared.js.map +0 -1
- package/out/parser/string/reduce/static.d.ts.map +0 -1
- package/out/parser/string/reduce/static.js.map +0 -1
- package/out/parser/string/shift/operand/date.d.ts.map +0 -1
- package/out/parser/string/shift/operand/date.js.map +0 -1
- package/out/parser/string/shift/operand/enclosed.d.ts.map +0 -1
- package/out/parser/string/shift/operand/enclosed.js.map +0 -1
- package/out/parser/string/shift/operand/genericArgs.d.ts.map +0 -1
- package/out/parser/string/shift/operand/genericArgs.js.map +0 -1
- package/out/parser/string/shift/operand/operand.d.ts.map +0 -1
- package/out/parser/string/shift/operand/operand.js.map +0 -1
- package/out/parser/string/shift/operand/unenclosed.d.ts.map +0 -1
- package/out/parser/string/shift/operand/unenclosed.js.map +0 -1
- package/out/parser/string/shift/operator/bounds.d.ts.map +0 -1
- package/out/parser/string/shift/operator/bounds.js.map +0 -1
- package/out/parser/string/shift/operator/divisor.d.ts.map +0 -1
- package/out/parser/string/shift/operator/divisor.js.map +0 -1
- package/out/parser/string/shift/operator/operator.d.ts.map +0 -1
- package/out/parser/string/shift/operator/operator.js.map +0 -1
- package/out/parser/string/shift/scanner.d.ts.map +0 -1
- package/out/parser/string/shift/scanner.js.map +0 -1
- package/out/parser/string/string.d.ts.map +0 -1
- package/out/parser/string/string.js.map +0 -1
- package/out/parser/tuple.d.ts.map +0 -1
- package/out/parser/tuple.js.map +0 -1
- package/out/scope.d.ts.map +0 -1
- package/out/scope.js.map +0 -1
- package/out/test.d.ts +0 -2
- package/out/test.d.ts.map +0 -1
- package/out/test.js +0 -7
- package/out/test.js.map +0 -1
- package/out/tsconfig.build.tsbuildinfo +0 -1
- package/out/type.d.ts.map +0 -1
- package/out/type.js.map +0 -1
- package/out/util.d.ts +0 -19
- package/out/util.d.ts.map +0 -1
- package/out/util.js +0 -7
- package/out/util.js.map +0 -1
- package/parser/definition.ts +0 -159
- package/parser/generic.ts +0 -68
- package/parser/objectLiteral.ts +0 -197
- package/parser/semantic/bounds.ts +0 -61
- package/parser/semantic/divisor.ts +0 -13
- package/parser/semantic/intersections.ts +0 -46
- package/parser/semantic/semantic.ts +0 -143
- package/parser/semantic/utils.ts +0 -26
- package/parser/semantic/validate.ts +0 -109
- package/parser/shared.ts +0 -167
- package/parser/string/reduce/dynamic.ts +0 -196
- package/parser/string/reduce/shared.ts +0 -101
- package/parser/string/reduce/static.ts +0 -298
- package/parser/string/shift/operand/date.ts +0 -54
- package/parser/string/shift/operand/enclosed.ts +0 -118
- package/parser/string/shift/operand/genericArgs.ts +0 -127
- package/parser/string/shift/operand/operand.ts +0 -48
- package/parser/string/shift/operand/unenclosed.ts +0 -268
- package/parser/string/shift/operator/bounds.ts +0 -264
- package/parser/string/shift/operator/divisor.ts +0 -36
- package/parser/string/shift/operator/operator.ts +0 -82
- package/parser/string/shift/scanner.ts +0 -209
- package/parser/string/string.ts +0 -90
- package/parser/tuple.ts +0 -475
- package/scope.ts +0 -548
- package/type.ts +0 -349
- package/util.ts +0 -36
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2023 ArkType
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/out/api.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { ArkError, ArkErrors as ArkErrors } from "@arktype/schema";
|
|
2
|
+
export type { Ark, ArkConfig, Out } from "@arktype/schema";
|
|
3
|
+
export { ambient, ark, declare, define, match, type } from "./ark.js";
|
|
4
|
+
export { Module } from "./module.js";
|
|
5
|
+
export { scope, type Scope } from "./scope.js";
|
|
6
|
+
export { Type, type inferTypeRoot, type validateTypeRoot } from "./type.js";
|
package/out/api.js
ADDED
package/out/ark.d.ts
CHANGED
|
@@ -1,29 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type Ark, type ArkErrors, type inferred } from "@arktype/schema";
|
|
2
|
+
import type { Generic } from "./generic.js";
|
|
2
3
|
import type { MatchParser } from "./match.js";
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
* explicitly typing them can improve responsiveness */
|
|
7
|
-
export type RootScope<exports> = Scope<{
|
|
8
|
-
exports: exports;
|
|
9
|
-
locals: {};
|
|
10
|
-
ambient: {};
|
|
11
|
-
}>;
|
|
12
|
-
export type ArkResolutions = {
|
|
13
|
-
exports: Ark;
|
|
14
|
-
locals: {};
|
|
15
|
-
ambient: Ark;
|
|
16
|
-
};
|
|
17
|
-
export type ParsingResolutions = {
|
|
18
|
-
exports: Parsing.infer;
|
|
19
|
-
locals: {};
|
|
20
|
-
ambient: {};
|
|
21
|
-
};
|
|
22
|
-
export type TsGenericsResolutions<$ = Ark> = {
|
|
23
|
-
exports: TsGenericsExports<$>;
|
|
24
|
-
locals: {};
|
|
25
|
-
ambient: {};
|
|
26
|
-
};
|
|
4
|
+
import type { Module } from "./module.js";
|
|
5
|
+
import { type Scope } from "./scope.js";
|
|
6
|
+
import type { DeclarationParser, DefinitionParser, TypeParser } from "./type.js";
|
|
27
7
|
type TsGenericsExports<$ = Ark> = {
|
|
28
8
|
Record: Generic<[
|
|
29
9
|
"K",
|
|
@@ -32,21 +12,17 @@ type TsGenericsExports<$ = Ark> = {
|
|
|
32
12
|
"[K]": "V";
|
|
33
13
|
}, $>;
|
|
34
14
|
};
|
|
35
|
-
export declare const tsGenerics: Module<
|
|
36
|
-
export declare const
|
|
37
|
-
export declare const
|
|
38
|
-
export
|
|
39
|
-
parse: Module<ParsingResolutions>;
|
|
40
|
-
}
|
|
41
|
-
export declare const scope: ScopeParser<{}, Ark>;
|
|
42
|
-
export declare const type: TypeParser<Ark>;
|
|
43
|
-
export declare const match: MatchParser<Ark>;
|
|
15
|
+
export declare const tsGenerics: Module<TsGenericsExports<Ark>>;
|
|
16
|
+
export declare const ambient: Scope<Ark>;
|
|
17
|
+
export declare const ark: Module<Ark>;
|
|
18
|
+
export declare const type: TypeParser<{}>;
|
|
44
19
|
export declare namespace type {
|
|
45
|
-
type cast<
|
|
46
|
-
[inferred]?:
|
|
20
|
+
type cast<t> = {
|
|
21
|
+
[inferred]?: t;
|
|
47
22
|
};
|
|
23
|
+
type errors = ArkErrors;
|
|
48
24
|
}
|
|
49
|
-
export declare const
|
|
50
|
-
export declare const
|
|
25
|
+
export declare const match: MatchParser<{}>;
|
|
26
|
+
export declare const define: DefinitionParser<{}>;
|
|
27
|
+
export declare const declare: DeclarationParser<{}>;
|
|
51
28
|
export {};
|
|
52
|
-
//# sourceMappingURL=ark.d.ts.map
|
package/out/ark.js
CHANGED
|
@@ -1,19 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { keywordNodes } from "@arktype/schema";
|
|
2
|
+
import { RawScope, scope } from "./scope.js";
|
|
3
3
|
export const tsGenerics = {};
|
|
4
|
-
export const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}).toAmbient();
|
|
12
|
-
export const arktypes = ark.export();
|
|
13
|
-
export const scope = ark.scope;
|
|
14
|
-
export const type = ark.type;
|
|
15
|
-
// TODO: cast needed?
|
|
16
|
-
export const match = ark.match;
|
|
17
|
-
export const define = ark.define;
|
|
18
|
-
export const declare = ark.declare;
|
|
19
|
-
//# sourceMappingURL=ark.js.map
|
|
4
|
+
export const ambient = scope(keywordNodes);
|
|
5
|
+
RawScope.ambient = ambient.raw;
|
|
6
|
+
export const ark = ambient.export();
|
|
7
|
+
export const type = ambient.type;
|
|
8
|
+
export const match = ambient.match;
|
|
9
|
+
export const define = ambient.define;
|
|
10
|
+
export const declare = ambient.declare;
|
package/out/config.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "@arktype/schema/config";
|
package/out/config.js
ADDED
package/out/generic.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { arkKind, type GenericNodeInstantiation, type GenericProps, type RootScope } from "@arktype/schema";
|
|
2
|
+
import { Callable, type conform } from "@arktype/util";
|
|
3
|
+
import type { inferDefinition } from "./parser/definition.js";
|
|
4
|
+
import type { GenericParamsParseError, parseGenericParams } from "./parser/generic.js";
|
|
5
|
+
import type { Type, inferTypeRoot, validateTypeRoot } from "./type.js";
|
|
6
|
+
export type validateParameterString<params extends string> = parseGenericParams<params> extends GenericParamsParseError<infer message> ? message : params;
|
|
7
|
+
export type GenericTypeInstantiation<params extends string[] = string[], def = any, $ = any> = <args>(...args: conform<args, {
|
|
8
|
+
[i in keyof params]: validateTypeRoot<args[i & keyof args], $>;
|
|
9
|
+
}>) => Type<inferDefinition<def, $, bindGenericInstantiation<params, $, args>>, $>;
|
|
10
|
+
export type GenericInstantiation<params extends string[] = string[], def = any, $ = any> = GenericTypeInstantiation<params, def, $> & GenericNodeInstantiation<params, def, $>;
|
|
11
|
+
type bindGenericInstantiation<params extends string[], $, args> = {
|
|
12
|
+
[i in keyof params & `${number}` as params[i]]: inferTypeRoot<args[i & keyof args], $>;
|
|
13
|
+
};
|
|
14
|
+
export declare class Generic<params extends string[] = string[], def = unknown, $ = any> extends Callable<GenericInstantiation<params, def, $>> implements GenericProps<params, def, $> {
|
|
15
|
+
params: params;
|
|
16
|
+
def: def;
|
|
17
|
+
$: RootScope<$>;
|
|
18
|
+
readonly [arkKind] = "generic";
|
|
19
|
+
constructor(params: params, def: def, $: RootScope<$>);
|
|
20
|
+
}
|
|
21
|
+
export {};
|
package/out/generic.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { arkKind } from "@arktype/schema";
|
|
2
|
+
import { Callable } from "@arktype/util";
|
|
3
|
+
export class Generic extends Callable {
|
|
4
|
+
params;
|
|
5
|
+
def;
|
|
6
|
+
$;
|
|
7
|
+
[arkKind] = "generic";
|
|
8
|
+
constructor(params, def,
|
|
9
|
+
// TODO: should be Scope<$>, but breaks inference
|
|
10
|
+
$) {
|
|
11
|
+
super((...args) => {
|
|
12
|
+
// const argNodes = flatMorph(params, (i, param: string) => [
|
|
13
|
+
// param,
|
|
14
|
+
// $.parseRoot(args[i])
|
|
15
|
+
// ])
|
|
16
|
+
// { args: argNodes }
|
|
17
|
+
args;
|
|
18
|
+
return $.parseRoot(def);
|
|
19
|
+
});
|
|
20
|
+
this.params = params;
|
|
21
|
+
this.def = def;
|
|
22
|
+
this.$ = $;
|
|
23
|
+
}
|
|
24
|
+
}
|
package/out/match.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { ErrorMessage,
|
|
1
|
+
import type { Narrowed, distillOut, inferIntersection } from "@arktype/schema";
|
|
2
|
+
import type { ErrorMessage, isDisjoint, numericStringKeyOf, override, propValueOf, unionToTuple } from "@arktype/util";
|
|
3
3
|
import type { Scope } from "./scope.js";
|
|
4
|
-
import {
|
|
4
|
+
import type { inferTypeRoot, validateTypeRoot } from "./type.js";
|
|
5
5
|
type MatchParserContext = {
|
|
6
6
|
thens: readonly ((In: unknown) => unknown)[];
|
|
7
7
|
$: unknown;
|
|
@@ -24,18 +24,15 @@ export type MatchParser<$> = CaseMatchParser<{
|
|
|
24
24
|
}>;
|
|
25
25
|
};
|
|
26
26
|
type matcherInputs<ctx extends MatchParserContext> = Parameters<ctx["thens"][number]>[0];
|
|
27
|
-
type
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
type getHandledBranches<ctx extends MatchParserContext> = Exclude<matcherInputs<ctx>, is<unknown, AnonymouslyRefined>>;
|
|
33
|
-
type getUnhandledBranches<ctx extends MatchParserContext> = Exclude<unknown extends ctx["exhaustiveOver"] ? UnknownUnion : ctx["exhaustiveOver"], getHandledBranches<ctx>>;
|
|
34
|
-
type addBranches<ctx extends MatchParserContext, branches extends unknown[]> = replaceKey<ctx, "thens", [...ctx["thens"], ...branches]>;
|
|
27
|
+
type getHandledBranches<ctx extends MatchParserContext> = Exclude<matcherInputs<ctx>, Narrowed>;
|
|
28
|
+
type getUnhandledBranches<ctx extends MatchParserContext> = distillOut<Exclude<ctx["exhaustiveOver"], getHandledBranches<ctx>>>;
|
|
29
|
+
type addBranches<ctx extends MatchParserContext, branches extends unknown[]> = override<ctx, {
|
|
30
|
+
thens: [...ctx["thens"], ...branches];
|
|
31
|
+
}>;
|
|
35
32
|
type validateWhenDefinition<def, ctx extends MatchParserContext> = def extends validateTypeRoot<def, ctx["$"]> ? inferMatchBranch<def, ctx> extends getHandledBranches<ctx> ? ErrorMessage<"This branch is redundant and will never be reached"> : def : validateTypeRoot<def, ctx["$"]>;
|
|
36
|
-
type inferMatchBranch<def, ctx extends MatchParserContext> =
|
|
33
|
+
type inferMatchBranch<def, ctx extends MatchParserContext> = distillOut<inferIntersection<getUnhandledBranches<ctx>, inferTypeRoot<def, ctx["$"]>>>;
|
|
37
34
|
export type ChainableMatchParser<ctx extends MatchParserContext> = {
|
|
38
|
-
when: <def, ret>(when: validateWhenDefinition<def, ctx>, then: (In:
|
|
35
|
+
when: <def, ret>(when: validateWhenDefinition<def, ctx>, then: (In: inferMatchBranch<def, ctx>) => ret) => ChainableMatchParser<addBranches<ctx, [(In: inferMatchBranch<def, ctx>) => ret]>>;
|
|
39
36
|
cases: CaseMatchParser<ctx>;
|
|
40
37
|
orThrow: () => finalizeMatchParser<addBranches<ctx, [(In: getHandledBranches<ctx>) => never]>>;
|
|
41
38
|
default: MatchParserDefaultInvocation<ctx>;
|
|
@@ -46,20 +43,18 @@ type MatchParserDefaultInvocation<ctx extends MatchParserContext> = {
|
|
|
46
43
|
<const value>(value: value): finalizeWithDefault<ctx, value>;
|
|
47
44
|
};
|
|
48
45
|
type validateCases<cases, ctx extends MatchParserContext> = {
|
|
49
|
-
[def in keyof cases | keyof ctx["$"] | "default"]?: def extends "default" ? (In:
|
|
46
|
+
[def in keyof cases | keyof ctx["$"] | "default"]?: def extends "default" ? (In: getUnhandledBranches<ctx>) => unknown : def extends validateWhenDefinition<def, ctx> ? (In: inferMatchBranch<def, ctx>) => unknown : validateWhenDefinition<def, ctx>;
|
|
50
47
|
};
|
|
51
48
|
type errorCases<cases, ctx extends MatchParserContext> = {
|
|
52
|
-
[def in keyof cases]?: def extends "default" ? (In:
|
|
49
|
+
[def in keyof cases]?: def extends "default" ? (In: getUnhandledBranches<ctx>) => unknown : def extends validateWhenDefinition<def, ctx> ? (In: inferMatchBranch<def, ctx>) => unknown : validateWhenDefinition<def, ctx>;
|
|
53
50
|
} & {
|
|
54
|
-
[k in Exclude<keyof ctx["$"], keyof cases>]?: (In:
|
|
51
|
+
[k in Exclude<keyof ctx["$"], keyof cases>]?: (In: distillOut<inferIntersection<getUnhandledBranches<ctx>, ctx["$"][k]>>) => unknown;
|
|
55
52
|
} & {
|
|
56
|
-
default?: (In:
|
|
57
|
-
};
|
|
58
|
-
export type CaseMatchParser<ctx extends MatchParserContext> = {
|
|
59
|
-
<cases>(def: cases extends validateCases<cases, ctx> ? cases : errorCases<cases, ctx>): cases extends {
|
|
60
|
-
default: (...args: never[]) => infer defaultReturn;
|
|
61
|
-
} ? finalizeWithDefault<addBranches<ctx, unionToTuple<cases[Exclude<keyof cases, "default">]>>, defaultReturn> : ChainableMatchParser<addBranches<ctx, unionToTuple<valueOf<cases>>>>;
|
|
53
|
+
default?: (In: getUnhandledBranches<ctx>) => unknown;
|
|
62
54
|
};
|
|
55
|
+
export type CaseMatchParser<ctx extends MatchParserContext> = <cases>(def: cases extends validateCases<cases, ctx> ? cases : errorCases<cases, ctx>) => cases extends {
|
|
56
|
+
default: (...args: never[]) => infer defaultReturn;
|
|
57
|
+
} ? finalizeWithDefault<addBranches<ctx, unionToTuple<cases[Exclude<keyof cases, "default">]>>, defaultReturn> : ChainableMatchParser<addBranches<ctx, unionToTuple<propValueOf<cases>>>>;
|
|
63
58
|
type finalizeWithDefault<ctx extends MatchParserContext, defaultReturn> = finalizeMatchParser<addBranches<ctx, [(_: getUnhandledBranches<ctx>) => defaultReturn]>>;
|
|
64
59
|
type finalizeMatchParser<ctx extends MatchParserContext> = MatchInvocation<{
|
|
65
60
|
thens: ctx["thens"];
|
|
@@ -72,6 +67,5 @@ type MatchInvocationContext = {
|
|
|
72
67
|
export type MatchInvocation<ctx extends MatchInvocationContext> = <data extends ctx["initialInputs"]>(data: data) => {
|
|
73
68
|
[i in numericStringKeyOf<ctx["thens"]>]: isDisjoint<data, Parameters<ctx["thens"][i]>[0]> extends true ? never : ReturnType<ctx["thens"][i]>;
|
|
74
69
|
}[numericStringKeyOf<ctx["thens"]>];
|
|
75
|
-
export declare const createMatchParser: <$>(
|
|
70
|
+
export declare const createMatchParser: <$>($: Scope) => MatchParser<$>;
|
|
76
71
|
export {};
|
|
77
|
-
//# sourceMappingURL=match.d.ts.map
|
package/out/match.js
CHANGED
|
@@ -1,60 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return parser.finalize();
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
return parser;
|
|
55
|
-
};
|
|
56
|
-
return Object.assign(() => matchParser(false), {
|
|
57
|
-
only: () => matchParser(true)
|
|
58
|
-
});
|
|
59
|
-
};
|
|
60
|
-
//# sourceMappingURL=match.js.map
|
|
1
|
+
export const createMatchParser = ($) => (() => { }).bind($);
|
|
2
|
+
// const matchParser = (isRestricted: boolean) => {
|
|
3
|
+
// const handledCases: { when: RawRoot; then: Morph }[] = []
|
|
4
|
+
// let defaultCase: ((x: unknown) => unknown) | null = null
|
|
5
|
+
// const parser = {
|
|
6
|
+
// when: (when: unknown, then: Morph) => {
|
|
7
|
+
// handledCases.push({ when: $.parseRoot(when, {}), then })
|
|
8
|
+
// return parser
|
|
9
|
+
// },
|
|
10
|
+
// finalize: () => {
|
|
11
|
+
// // TODO: exhaustiveness checking
|
|
12
|
+
// const branches = handledCases.flatMap(({ when, then }) => {
|
|
13
|
+
// if (when.kind === "union") {
|
|
14
|
+
// return when.branches.map((branch) => ({
|
|
15
|
+
// in: branch,
|
|
16
|
+
// morph: then
|
|
17
|
+
// }))
|
|
18
|
+
// }
|
|
19
|
+
// if (when.kind === "morph") {
|
|
20
|
+
// return [{ in: when, morph: [when.morph, then] }]
|
|
21
|
+
// }
|
|
22
|
+
// return [{ in: when, morph: then }]
|
|
23
|
+
// })
|
|
24
|
+
// if (defaultCase) {
|
|
25
|
+
// branches.push({ in: keywordNodes.unknown, morph: defaultCase })
|
|
26
|
+
// }
|
|
27
|
+
// const matchers = $.node("union", {
|
|
28
|
+
// branches,
|
|
29
|
+
// ordered: true
|
|
30
|
+
// })
|
|
31
|
+
// return matchers.assert
|
|
32
|
+
// },
|
|
33
|
+
// orThrow: () => {
|
|
34
|
+
// // implicitly finalize, we don't need to do anything else because we throw either way
|
|
35
|
+
// return parser.finalize()
|
|
36
|
+
// },
|
|
37
|
+
// default: (x: unknown) => {
|
|
38
|
+
// if (x instanceof Function) {
|
|
39
|
+
// defaultCase = x as never
|
|
40
|
+
// } else {
|
|
41
|
+
// defaultCase = () => x
|
|
42
|
+
// }
|
|
43
|
+
// return parser.finalize()
|
|
44
|
+
// }
|
|
45
|
+
// }
|
|
46
|
+
// return parser
|
|
47
|
+
// }
|
|
48
|
+
// return Object.assign(() => matchParser(false), {
|
|
49
|
+
// only: () => matchParser(true)
|
|
50
|
+
// }) as never
|
package/out/module.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { RootModule, type PreparsedNodeResolution } from "@arktype/schema";
|
|
2
|
+
import type { anyOrNever } from "@arktype/util";
|
|
3
|
+
import type { Type } from "./type.js";
|
|
4
|
+
type exportScope<$> = {
|
|
5
|
+
[k in keyof $]: $[k] extends PreparsedNodeResolution ? [
|
|
6
|
+
$[k]
|
|
7
|
+
] extends [anyOrNever] ? Type<$[k], $> : $[k] : Type<$[k], $>;
|
|
8
|
+
};
|
|
9
|
+
export declare const Module: new <$ = {}>(types: exportScope<$>) => Module<$>;
|
|
10
|
+
export type Module<$ = {}> = RootModule<exportScope<$>>;
|
|
11
|
+
export {};
|
package/out/module.js
ADDED
|
@@ -1,26 +1,25 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import { type ErrorMessage, type Primitive, type
|
|
1
|
+
import { type BaseRoot, type string } from "@arktype/schema";
|
|
2
|
+
import { type ErrorMessage, type Primitive, type anyOrNever, type array, type defined, type equals, type isUnknown, type objectKindOrDomainOf, type optionalKeyOf, type requiredKeyOf, type show } from "@arktype/util";
|
|
3
3
|
import type { type } from "../ark.js";
|
|
4
4
|
import type { ParseContext } from "../scope.js";
|
|
5
5
|
import { type inferObjectLiteral, type validateObjectLiteral } from "./objectLiteral.js";
|
|
6
6
|
import type { validateString } from "./semantic/validate.js";
|
|
7
7
|
import type { BaseCompletions, inferString } from "./string/string.js";
|
|
8
8
|
import { type TupleExpression, type inferTuple, type validateTuple } from "./tuple.js";
|
|
9
|
-
export declare const parseObject: (def: object, ctx: ParseContext) =>
|
|
10
|
-
export type inferDefinition<def, $, args> =
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export type validateDefinition<def, $, args> = null extends undefined ? ErrorMessage<`'strict' or 'strictNullChecks' must be set to true in your tsconfig's 'compilerOptions'`> : [def] extends [Terminal] ?
|
|
14
|
-
BaseCompletions<$, args> | {} : validateObjectLiteral<def, $, args>;
|
|
9
|
+
export declare const parseObject: (def: object, ctx: ParseContext) => BaseRoot;
|
|
10
|
+
export type inferDefinition<def, $, args> = [
|
|
11
|
+
def
|
|
12
|
+
] extends [anyOrNever] ? def extends never ? never : any : def extends type.cast<infer t> | ThunkCast<infer t> ? t : def extends string ? inferString<def, $, args> : def extends array ? inferTuple<def, $, args> : def extends RegExp ? string.matching<string> : def extends object ? inferObjectLiteral<def, $, args> : never;
|
|
13
|
+
export type validateDefinition<def, $, args> = null extends undefined ? ErrorMessage<`'strict' or 'strictNullChecks' must be set to true in your tsconfig's 'compilerOptions'`> : [def] extends [Terminal] ? def : def extends string ? validateString<def, $, args> : def extends array ? validateTuple<def, $, args> : def extends BadDefinitionType ? ErrorMessage<writeBadDefinitionTypeMessage<objectKindOrDomainOf<def>>> : isUnknown<def> extends true ? BaseCompletions<$, args> | {} : validateObjectLiteral<def, $, args>;
|
|
15
14
|
export type validateDeclared<declared, def, $, args> = def extends validateDefinition<def, $, args> ? validateInference<def, declared, $, args> : validateDefinition<def, $, args>;
|
|
16
|
-
type validateInference<def, declared, $, args> = def extends RegExp | type.cast<unknown> | ThunkCast | TupleExpression ? validateShallowInference<def, declared, $, args> : def extends
|
|
17
|
-
[i in keyof declared]: i extends keyof def ? validateInference<def[i], declared[i], $, args> :
|
|
18
|
-
} :
|
|
19
|
-
[k in requiredKeyOf<declared>]: k extends keyof def ? validateInference<def[k], declared[k], $, args> :
|
|
15
|
+
type validateInference<def, declared, $, args> = def extends RegExp | type.cast<unknown> | ThunkCast | TupleExpression ? validateShallowInference<def, declared, $, args> : def extends array ? declared extends array ? {
|
|
16
|
+
[i in keyof declared]: i extends keyof def ? validateInference<def[i], declared[i], $, args> : declared[i];
|
|
17
|
+
} : show<declarationMismatch<def, declared, $, args>> : def extends object ? show<{
|
|
18
|
+
[k in requiredKeyOf<declared>]: k extends keyof def ? validateInference<def[k], declared[k], $, args> : declared[k];
|
|
20
19
|
} & {
|
|
21
|
-
[k in optionalKeyOf<declared> & string as `${k}?`]: `${k}?` extends keyof def ? validateInference<def[`${k}?`], defined<declared[k]>, $, args> :
|
|
20
|
+
[k in optionalKeyOf<declared> & string as `${k}?`]: `${k}?` extends (keyof def) ? validateInference<def[`${k}?`], defined<declared[k]>, $, args> : declared[k];
|
|
22
21
|
}> : validateShallowInference<def, declared, $, args>;
|
|
23
|
-
type validateShallowInference<def, declared, $, args> = equals<inferDefinition<def, $, args>, declared> extends true ? def :
|
|
22
|
+
type validateShallowInference<def, declared, $, args> = equals<inferDefinition<def, $, args>, declared> extends true ? def : show<declarationMismatch<def, declared, $, args>>;
|
|
24
23
|
type declarationMismatch<def, declared, $, args> = {
|
|
25
24
|
declared: declared;
|
|
26
25
|
inferred: inferDefinition<def, $, args>;
|
|
@@ -31,4 +30,3 @@ type BadDefinitionType = Exclude<Primitive, string>;
|
|
|
31
30
|
export declare const writeBadDefinitionTypeMessage: <actual extends string>(actual: actual) => `Type definitions must be strings or objects (was ${actual})`;
|
|
32
31
|
type writeBadDefinitionTypeMessage<actual extends string> = `Type definitions must be strings or objects (was ${actual})`;
|
|
33
32
|
export {};
|
|
34
|
-
//# sourceMappingURL=definition.d.ts.map
|
package/out/parser/definition.js
CHANGED
|
@@ -1,32 +1,29 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { hasArkKind } from "@arktype/schema";
|
|
2
2
|
import { isThunk, objectKindOf, printable, throwParseError } from "@arktype/util";
|
|
3
|
-
import { Type } from "../type.js";
|
|
4
3
|
import { parseObjectLiteral } from "./objectLiteral.js";
|
|
5
4
|
import { parseTuple } from "./tuple.js";
|
|
6
5
|
export const parseObject = (def, ctx) => {
|
|
7
6
|
const objectKind = objectKindOf(def);
|
|
8
7
|
switch (objectKind) {
|
|
9
8
|
case undefined:
|
|
10
|
-
if (def
|
|
11
|
-
return def.root;
|
|
12
|
-
}
|
|
13
|
-
if (isNode(def) && def.isType()) {
|
|
9
|
+
if (hasArkKind(def, "root"))
|
|
14
10
|
return def;
|
|
15
|
-
}
|
|
16
11
|
return parseObjectLiteral(def, ctx);
|
|
17
12
|
case "Array":
|
|
18
13
|
return parseTuple(def, ctx);
|
|
19
14
|
case "RegExp":
|
|
20
|
-
return
|
|
21
|
-
|
|
15
|
+
return ctx.$.node("intersection", {
|
|
16
|
+
domain: "string",
|
|
17
|
+
regex: def
|
|
18
|
+
}, { prereduced: true });
|
|
19
|
+
case "Function": {
|
|
22
20
|
const resolvedDef = isThunk(def) ? def() : def;
|
|
23
|
-
if (resolvedDef
|
|
24
|
-
return resolvedDef
|
|
25
|
-
}
|
|
21
|
+
if (hasArkKind(resolvedDef, "root"))
|
|
22
|
+
return resolvedDef;
|
|
26
23
|
return throwParseError(writeBadDefinitionTypeMessage("Function"));
|
|
24
|
+
}
|
|
27
25
|
default:
|
|
28
26
|
return throwParseError(writeBadDefinitionTypeMessage(objectKind ?? printable(def)));
|
|
29
27
|
}
|
|
30
28
|
};
|
|
31
29
|
export const writeBadDefinitionTypeMessage = (actual) => `Type definitions must be strings or objects (was ${actual})`;
|
|
32
|
-
//# sourceMappingURL=definition.js.map
|
package/out/parser/generic.d.ts
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type keyError } from "@arktype/util";
|
|
2
2
|
import { writeUnexpectedCharacterMessage } from "./string/shift/operator/operator.js";
|
|
3
3
|
import { Scanner } from "./string/shift/scanner.js";
|
|
4
4
|
export type GenericDeclaration<name extends string = string, params extends string = string> = `${name}<${params}>`;
|
|
5
5
|
export type GenericParamsParseError<message extends string = string> = [
|
|
6
|
-
|
|
6
|
+
keyError<message>
|
|
7
7
|
];
|
|
8
8
|
export declare const parseGenericParams: (def: string) => string[];
|
|
9
|
-
export type parseGenericParams<def extends string> =
|
|
10
|
-
]> extends infer result extends string[] ? "" extends result[number] ? GenericParamsParseError<emptyGenericParameterMessage> : result : never;
|
|
9
|
+
export type parseGenericParams<def extends string> = _parseParams<def, "", []> extends infer result extends string[] ? "" extends result[number] ? GenericParamsParseError<emptyGenericParameterMessage> : result : never;
|
|
11
10
|
export declare const emptyGenericParameterMessage = "An empty string is not a valid generic parameter name";
|
|
12
11
|
export type emptyGenericParameterMessage = typeof emptyGenericParameterMessage;
|
|
13
|
-
type
|
|
12
|
+
type _parseParams<unscanned extends string, param extends string, result extends string[]> = unscanned extends `${infer lookahead}${infer nextUnscanned}` ? lookahead extends "," ? _parseParams<nextUnscanned, "", [...result, param]> : lookahead extends Scanner.WhiteSpaceToken ? param extends "" ? _parseParams<Scanner.skipWhitespace<nextUnscanned>, "", result> : Scanner.skipWhitespace<nextUnscanned> extends (`${infer nextNonWhitespace}${infer rest}`) ? nextNonWhitespace extends "," ? _parseParams<rest, "", [...result, param]> : GenericParamsParseError<writeUnexpectedCharacterMessage<nextNonWhitespace, ",">> : [
|
|
14
13
|
...result,
|
|
15
14
|
param
|
|
16
|
-
] :
|
|
15
|
+
] : _parseParams<nextUnscanned, `${param}${lookahead}`, result> : param extends "" ? result : [...result, param];
|
|
17
16
|
export {};
|
|
18
|
-
//# sourceMappingURL=generic.d.ts.map
|
package/out/parser/generic.js
CHANGED
|
@@ -1,19 +1,15 @@
|
|
|
1
1
|
import { throwParseError } from "@arktype/util";
|
|
2
2
|
import { writeUnexpectedCharacterMessage } from "./string/shift/operator/operator.js";
|
|
3
3
|
import { Scanner } from "./string/shift/scanner.js";
|
|
4
|
-
export const parseGenericParams = (def) =>
|
|
5
|
-
export const emptyGenericParameterMessage =
|
|
6
|
-
const
|
|
4
|
+
export const parseGenericParams = (def) => _parseGenericParams(new Scanner(def));
|
|
5
|
+
export const emptyGenericParameterMessage = "An empty string is not a valid generic parameter name";
|
|
6
|
+
const _parseGenericParams = (scanner) => {
|
|
7
7
|
const param = scanner.shiftUntilNextTerminator();
|
|
8
|
-
if (param === "")
|
|
8
|
+
if (param === "")
|
|
9
9
|
throwParseError(emptyGenericParameterMessage);
|
|
10
|
-
}
|
|
11
10
|
scanner.shiftUntilNonWhitespace();
|
|
12
11
|
const nextNonWhitespace = scanner.shift();
|
|
13
|
-
return nextNonWhitespace === ""
|
|
14
|
-
? [param]
|
|
15
|
-
|
|
16
|
-
? [param, ...parseGenericParamsRecurse(scanner)]
|
|
17
|
-
: throwParseError(writeUnexpectedCharacterMessage(nextNonWhitespace, ","));
|
|
12
|
+
return (nextNonWhitespace === "" ? [param]
|
|
13
|
+
: nextNonWhitespace === "," ? [param, ..._parseGenericParams(scanner)]
|
|
14
|
+
: throwParseError(writeUnexpectedCharacterMessage(nextNonWhitespace, ",")));
|
|
18
15
|
};
|
|
19
|
-
//# sourceMappingURL=generic.js.map
|