arktype 2.0.0-rc.0 → 2.0.0-rc.10
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/out/config.d.ts +1 -1
- package/out/generic.d.ts +55 -53
- package/out/generic.js +9 -11
- package/out/index.d.ts +5 -5
- package/out/index.js +3 -2
- package/out/keywords/{builtin.d.ts → builtins.d.ts} +9 -5
- package/out/keywords/{builtin.js → builtins.js} +2 -2
- package/out/keywords/constructors/Array.d.ts +12 -8
- package/out/keywords/constructors/Array.js +7 -7
- package/out/keywords/constructors/Date.d.ts +32 -0
- package/out/keywords/constructors/FormData.d.ts +12 -6
- package/out/keywords/constructors/FormData.js +19 -6
- package/out/keywords/constructors/TypedArray.d.ts +18 -14
- package/out/keywords/constructors/TypedArray.js +2 -2
- package/out/keywords/constructors/constructors.d.ts +21 -32
- package/out/keywords/constructors/constructors.js +13 -28
- package/out/keywords/inference.d.ts +227 -0
- package/out/keywords/keywords.d.ts +61 -0
- package/out/keywords/keywords.js +26 -0
- package/out/keywords/number/epoch.d.ts +1 -2
- package/out/keywords/number/epoch.js +2 -2
- package/out/keywords/number/integer.js +2 -2
- package/out/keywords/number/number.d.ts +37 -9
- package/out/keywords/number/number.js +17 -5
- package/out/keywords/string/alpha.d.ts +1 -1
- package/out/keywords/string/alphanumeric.d.ts +1 -1
- package/out/keywords/string/capitalize.d.ts +11 -10
- package/out/keywords/string/capitalize.js +4 -4
- package/out/keywords/string/creditCard.d.ts +1 -1
- package/out/keywords/string/creditCard.js +2 -2
- package/out/keywords/string/date.d.ts +27 -26
- package/out/keywords/string/date.js +16 -16
- package/out/keywords/string/digits.d.ts +1 -1
- package/out/keywords/string/email.d.ts +1 -1
- package/out/keywords/string/integer.d.ts +11 -10
- package/out/keywords/string/integer.js +7 -7
- package/out/keywords/string/ip.d.ts +12 -12
- package/out/keywords/string/ip.js +5 -5
- package/out/keywords/string/json.d.ts +12 -10
- package/out/keywords/string/json.js +24 -16
- package/out/keywords/string/lower.d.ts +11 -10
- package/out/keywords/string/lower.js +4 -4
- package/out/keywords/string/normalize.d.ts +63 -47
- package/out/keywords/string/normalize.js +14 -14
- package/out/keywords/string/numeric.d.ts +11 -10
- package/out/keywords/string/numeric.js +7 -7
- package/out/keywords/string/semver.d.ts +1 -1
- package/out/keywords/string/string.d.ts +78 -26
- package/out/keywords/string/string.js +5 -5
- package/out/keywords/string/trim.d.ts +11 -10
- package/out/keywords/string/trim.js +4 -4
- package/out/keywords/string/upper.d.ts +11 -10
- package/out/keywords/string/upper.js +4 -4
- package/out/keywords/string/url.d.ts +11 -10
- package/out/keywords/string/url.js +8 -8
- package/out/keywords/string/uuid.d.ts +27 -23
- package/out/keywords/string/uuid.js +3 -3
- package/out/keywords/ts.d.ts +44 -22
- package/out/keywords/ts.js +20 -14
- package/out/keywords/utils.d.ts +1 -1
- package/out/keywords/utils.js +1 -1
- package/out/{subtypes → methods}/array.d.ts +6 -6
- package/out/methods/base.d.ts +96 -0
- package/out/{subtypes → methods}/date.d.ts +5 -5
- package/out/{subtypes → methods}/instantiate.d.ts +5 -4
- package/out/methods/morph.d.ts +12 -0
- package/out/{subtypes → methods}/number.d.ts +6 -6
- package/out/methods/object.d.ts +81 -0
- package/out/{subtypes → methods}/string.d.ts +7 -7
- package/out/{subtypes → methods}/validator.d.ts +2 -2
- package/out/module.d.ts +2 -2
- package/out/parser/{semantic → ast}/bounds.d.ts +6 -4
- package/out/parser/ast/default.d.ts +8 -0
- package/out/parser/ast/infer.d.ts +39 -0
- package/out/parser/ast/utils.d.ts +4 -0
- package/out/parser/ast/validate.d.ts +26 -0
- package/out/parser/definition.d.ts +9 -12
- package/out/parser/objectLiteral.d.ts +11 -25
- package/out/parser/objectLiteral.js +6 -24
- package/out/parser/{string/reduce → reduce}/dynamic.d.ts +5 -7
- package/out/parser/{string/reduce → reduce}/dynamic.js +5 -6
- package/out/parser/{string/reduce → reduce}/shared.d.ts +1 -1
- package/out/parser/{string/reduce → reduce}/static.d.ts +1 -1
- package/out/parser/{string/shift → shift}/operand/date.d.ts +3 -1
- package/out/parser/{string/shift → shift}/operand/enclosed.d.ts +4 -1
- package/out/parser/{string/shift → shift}/operand/enclosed.js +7 -3
- package/out/parser/{string/shift → shift}/operand/unenclosed.d.ts +7 -8
- package/out/parser/{string/shift → shift}/operand/unenclosed.js +7 -3
- package/out/parser/{string/shift → shift}/operator/bounds.d.ts +7 -6
- package/out/parser/{string/shift → shift}/operator/default.d.ts +3 -6
- package/out/parser/{string/shift → shift}/operator/default.js +1 -6
- package/out/parser/{string/shift → shift}/operator/operator.js +2 -2
- package/out/parser/{string/shift → shift}/scanner.d.ts +6 -2
- package/out/parser/{string/shift → shift}/scanner.js +7 -5
- package/out/parser/{string/string.d.ts → string.d.ts} +8 -8
- package/out/parser/{string/string.js → string.js} +2 -0
- package/out/parser/tuple.d.ts +54 -43
- package/out/parser/tuple.js +36 -30
- package/out/scope.d.ts +41 -34
- package/out/scope.js +48 -27
- package/out/type.d.ts +25 -20
- package/out/type.js +23 -14
- package/package.json +3 -3
- package/out/intersect.d.ts +0 -28
- package/out/keys.d.ts +0 -16
- package/out/keywords/ark.d.ts +0 -33
- package/out/keywords/ark.js +0 -18
- package/out/keywords/ast.d.ts +0 -193
- package/out/parser/semantic/default.d.ts +0 -8
- package/out/parser/semantic/default.js +0 -1
- package/out/parser/semantic/infer.d.ts +0 -33
- package/out/parser/semantic/utils.d.ts +0 -4
- package/out/parser/semantic/validate.d.ts +0 -29
- package/out/subtypes/base.d.ts +0 -84
- package/out/subtypes/morph.d.ts +0 -13
- package/out/subtypes/object.d.ts +0 -33
- /package/out/{intersect.js → keywords/constructors/Date.js} +0 -0
- /package/out/keywords/{ast.js → inference.js} +0 -0
- /package/out/{subtypes → methods}/array.js +0 -0
- /package/out/{subtypes → methods}/base.js +0 -0
- /package/out/{subtypes → methods}/date.js +0 -0
- /package/out/{subtypes → methods}/instantiate.js +0 -0
- /package/out/{subtypes → methods}/morph.js +0 -0
- /package/out/{subtypes → methods}/number.js +0 -0
- /package/out/{subtypes → methods}/object.js +0 -0
- /package/out/{subtypes → methods}/string.js +0 -0
- /package/out/{subtypes → methods}/validator.js +0 -0
- /package/out/parser/{semantic → ast}/bounds.js +0 -0
- /package/out/{keys.js → parser/ast/default.js} +0 -0
- /package/out/parser/{semantic → ast}/divisor.d.ts +0 -0
- /package/out/parser/{semantic → ast}/divisor.js +0 -0
- /package/out/parser/{semantic → ast}/infer.js +0 -0
- /package/out/parser/{semantic → ast}/keyof.d.ts +0 -0
- /package/out/parser/{semantic → ast}/keyof.js +0 -0
- /package/out/parser/{semantic → ast}/utils.js +0 -0
- /package/out/parser/{semantic → ast}/validate.js +0 -0
- /package/out/parser/{string/reduce → reduce}/shared.js +0 -0
- /package/out/parser/{string/reduce → reduce}/static.js +0 -0
- /package/out/parser/{string/shift → shift}/operand/date.js +0 -0
- /package/out/parser/{string/shift → shift}/operand/genericArgs.d.ts +0 -0
- /package/out/parser/{string/shift → shift}/operand/genericArgs.js +0 -0
- /package/out/parser/{string/shift → shift}/operand/operand.d.ts +0 -0
- /package/out/parser/{string/shift → shift}/operand/operand.js +0 -0
- /package/out/parser/{string/shift → shift}/operator/bounds.js +0 -0
- /package/out/parser/{string/shift → shift}/operator/divisor.d.ts +0 -0
- /package/out/parser/{string/shift → shift}/operator/divisor.js +0 -0
- /package/out/parser/{string/shift → shift}/operator/operator.d.ts +0 -0
package/out/config.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { ArkSchemaRegistry } from "@ark/schema";
|
|
2
|
-
import type { Ark } from "./keywords/
|
|
2
|
+
import type { Ark } from "./keywords/keywords.ts";
|
|
3
3
|
import type { exportScope } from "./module.ts";
|
|
4
4
|
export * from "@ark/schema/config";
|
|
5
5
|
export interface ArkTypeRegistryContents extends ArkSchemaRegistry {
|
package/out/generic.d.ts
CHANGED
|
@@ -1,29 +1,30 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import { type array, type Callable, type conform, type ErrorMessage, type ErrorType, type Hkt, type WhiteSpaceToken } from "@ark/util";
|
|
1
|
+
import { GenericRoot, type arkKind, type BaseParseContext, type GenericAst, type GenericParamAst, type GenericParamDef, type genericParamNames, type LazyGenericBody } from "@ark/schema";
|
|
2
|
+
import { type array, type Callable, type conform, type ErrorMessage, type ErrorType, type Hkt, type Json, type WhiteSpaceToken } from "@ark/util";
|
|
3
|
+
import type { type } from "./keywords/keywords.ts";
|
|
4
|
+
import type { inferAstRoot } from "./parser/ast/infer.ts";
|
|
5
|
+
import type { validateAst } from "./parser/ast/validate.ts";
|
|
3
6
|
import type { inferDefinition, validateDefinition } from "./parser/definition.ts";
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import type { ParseContext, Scope } from "./scope.ts";
|
|
10
|
-
import type { inferTypeRoot, Type, validateTypeRoot } from "./type.ts";
|
|
7
|
+
import type { state, StaticState } from "./parser/reduce/static.ts";
|
|
8
|
+
import type { Scanner } from "./parser/shift/scanner.ts";
|
|
9
|
+
import { parseUntilFinalizer } from "./parser/string.ts";
|
|
10
|
+
import type { Scope } from "./scope.ts";
|
|
11
|
+
import type { Type } from "./type.ts";
|
|
11
12
|
export type ParameterString<params extends string = string> = `<${params}>`;
|
|
12
13
|
export type extractParams<s extends ParameterString> = s extends ParameterString<infer params> ? params : never;
|
|
13
14
|
export type validateParameterString<s extends ParameterString, $> = parseGenericParams<extractParams<s>, $> extends infer e extends ErrorMessage ? e : s;
|
|
14
|
-
export type validateGenericArg<arg, param extends GenericParamAst, $> =
|
|
15
|
+
export type validateGenericArg<arg, param extends GenericParamAst, $> = type.infer<arg, $> extends param[1] ? unknown : ErrorType<`Invalid argument for ${param[0]}`, [expected: param[1]]>;
|
|
15
16
|
export type GenericInstantiator<params extends array<GenericParamAst>, def, $, args$> = params["length"] extends 1 ? {
|
|
16
|
-
<const a, r = instantiateGeneric<def, params, [a], $, args$>>(a:
|
|
17
|
+
<const a, r = instantiateGeneric<def, params, [a], $, args$>>(a: type.validate<a, args$> & validateGenericArg<a, params[0], args$>): r;
|
|
17
18
|
} : params["length"] extends 2 ? {
|
|
18
|
-
<const a, const b, r = instantiateGeneric<def, params, [a, b], $, args$>>(...args: [
|
|
19
|
-
validateGenericArg<a, params[0], args$>,
|
|
20
|
-
validateGenericArg<b, params[1], args$>
|
|
19
|
+
<const a, const b, r = instantiateGeneric<def, params, [a, b], $, args$>>(...args: [
|
|
20
|
+
type.validate<a, args$> & validateGenericArg<a, params[0], args$>,
|
|
21
|
+
type.validate<b, args$> & validateGenericArg<b, params[1], args$>
|
|
21
22
|
]): r;
|
|
22
23
|
} : params["length"] extends 3 ? {
|
|
23
24
|
<const a, const b, const c, r = instantiateGeneric<def, params, [a, b, c], $, args$>>(...args: [
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
type.validate<a, args$>,
|
|
26
|
+
type.validate<b, args$>,
|
|
27
|
+
type.validate<c, args$>
|
|
27
28
|
] & [
|
|
28
29
|
validateGenericArg<a, params[0], args$>,
|
|
29
30
|
validateGenericArg<b, params[1], args$>,
|
|
@@ -31,10 +32,10 @@ export type GenericInstantiator<params extends array<GenericParamAst>, def, $, a
|
|
|
31
32
|
]): r;
|
|
32
33
|
} : params["length"] extends 4 ? {
|
|
33
34
|
<const a, const b, const c, const d, r = instantiateGeneric<def, params, [a, b, c, d], $, args$>>(...args: [
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
type.validate<a, args$>,
|
|
36
|
+
type.validate<b, args$>,
|
|
37
|
+
type.validate<c, args$>,
|
|
38
|
+
type.validate<d, args$>
|
|
38
39
|
] & [
|
|
39
40
|
validateGenericArg<a, params[0], args$>,
|
|
40
41
|
validateGenericArg<b, params[1], args$>,
|
|
@@ -43,11 +44,11 @@ export type GenericInstantiator<params extends array<GenericParamAst>, def, $, a
|
|
|
43
44
|
]): r;
|
|
44
45
|
} : params["length"] extends 4 ? {
|
|
45
46
|
<const a, const b, const c, const d, const e, r = instantiateGeneric<def, params, [a, b, c, d, e], $, args$>>(...args: [
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
47
|
+
type.validate<a, args$>,
|
|
48
|
+
type.validate<b, args$>,
|
|
49
|
+
type.validate<c, args$>,
|
|
50
|
+
type.validate<d, args$>,
|
|
51
|
+
type.validate<e, args$>
|
|
51
52
|
] & [
|
|
52
53
|
validateGenericArg<a, params[0], args$>,
|
|
53
54
|
validateGenericArg<b, params[1], args$>,
|
|
@@ -57,12 +58,12 @@ export type GenericInstantiator<params extends array<GenericParamAst>, def, $, a
|
|
|
57
58
|
]): r;
|
|
58
59
|
} : params["length"] extends 5 ? {
|
|
59
60
|
<const a, const b, const c, const d, const e, const f, r = instantiateGeneric<def, params, [a, b, c, d, e, f], $, args$>>(...args: [
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
type.validate<a, args$>,
|
|
62
|
+
type.validate<b, args$>,
|
|
63
|
+
type.validate<c, args$>,
|
|
64
|
+
type.validate<d, args$>,
|
|
65
|
+
type.validate<e, args$>,
|
|
66
|
+
type.validate<f, args$>
|
|
66
67
|
] & [
|
|
67
68
|
validateGenericArg<a, params[0], args$>,
|
|
68
69
|
validateGenericArg<b, params[1], args$>,
|
|
@@ -73,13 +74,13 @@ export type GenericInstantiator<params extends array<GenericParamAst>, def, $, a
|
|
|
73
74
|
]): r;
|
|
74
75
|
} : params["length"] extends 6 ? {
|
|
75
76
|
<const a, const b, const c, const d, const e, const f, const g, r = instantiateGeneric<def, params, [a, b, c, d, e, f, g], $, args$>>(...args: [
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
77
|
+
type.validate<a, args$>,
|
|
78
|
+
type.validate<b, args$>,
|
|
79
|
+
type.validate<c, args$>,
|
|
80
|
+
type.validate<d, args$>,
|
|
81
|
+
type.validate<e, args$>,
|
|
82
|
+
type.validate<f, args$>,
|
|
83
|
+
type.validate<g, args$>
|
|
83
84
|
] & [
|
|
84
85
|
validateGenericArg<a, params[0], args$>,
|
|
85
86
|
validateGenericArg<b, params[1], args$>,
|
|
@@ -93,10 +94,10 @@ export type GenericInstantiator<params extends array<GenericParamAst>, def, $, a
|
|
|
93
94
|
type instantiateGeneric<def, params extends array<GenericParamAst>, args, $, args$> = Type<[
|
|
94
95
|
def
|
|
95
96
|
] extends [Hkt] ? Hkt.apply<def, {
|
|
96
|
-
[i in keyof args]:
|
|
97
|
+
[i in keyof args]: type.infer<args[i], args$>;
|
|
97
98
|
}> : inferDefinition<def, $, bindGenericArgs<params, args$, args>>, args$>;
|
|
98
99
|
type bindGenericArgs<params extends array<GenericParamAst>, $, args> = {
|
|
99
|
-
[i in keyof params & `${number}` as params[i][0]]:
|
|
100
|
+
[i in keyof params & `${number}` as params[i][0]]: type.infer<args[i & keyof args], $>;
|
|
100
101
|
};
|
|
101
102
|
type baseGenericResolutions<params extends array<GenericParamAst>, $> = baseGenericConstraints<params> extends infer baseConstraints ? {
|
|
102
103
|
[k in keyof baseConstraints]: Type<baseConstraints[k], $>;
|
|
@@ -118,38 +119,39 @@ export interface Generic<params extends array<GenericParamAst> = array<GenericPa
|
|
|
118
119
|
$: Scope<$>;
|
|
119
120
|
arg$: Scope<arg$>;
|
|
120
121
|
internal: GenericRoot;
|
|
122
|
+
json: Json;
|
|
121
123
|
}
|
|
124
|
+
export type GenericConstructor<params extends array<GenericParamAst> = array<GenericParamAst>, bodyDef = unknown, $ = {}, arg$ = {}> = new () => Generic<params, bodyDef, $, arg$>;
|
|
125
|
+
export declare const Generic: GenericConstructor;
|
|
122
126
|
export type GenericDeclaration<name extends string = string, params extends ParameterString = ParameterString> = `${name}${params}`;
|
|
123
127
|
export type parseValidGenericParams<def extends ParameterString, $> = conform<parseGenericParams<extractParams<def>, $>, array<GenericParamAst>>;
|
|
124
128
|
export declare const emptyGenericParameterMessage = "An empty string is not a valid generic parameter name";
|
|
125
129
|
export type emptyGenericParameterMessage = typeof emptyGenericParameterMessage;
|
|
126
|
-
export declare const parseGenericParams: (def: string, ctx: ParseContext) => array<GenericParamDef>;
|
|
127
130
|
export type parseGenericParams<def extends string, $> = parseNextNameChar<Scanner.skipWhitespace<def>, "", [
|
|
128
131
|
], $>;
|
|
129
|
-
type ParamsTerminator = WhiteSpaceToken | ","
|
|
130
|
-
declare const
|
|
132
|
+
type ParamsTerminator = WhiteSpaceToken | ",";
|
|
133
|
+
export declare const parseGenericParamName: (scanner: Scanner, result: GenericParamDef[], ctx: BaseParseContext) => GenericParamDef[];
|
|
131
134
|
type parseName<unscanned extends string, result extends array<GenericParamAst>, $> = parseNextNameChar<Scanner.skipWhitespace<unscanned>, "", result, $>;
|
|
132
|
-
type parseNextNameChar<unscanned extends string, name extends string, result extends array<GenericParamAst>, $> = unscanned extends `${infer lookahead}${infer nextUnscanned}` ? lookahead extends ParamsTerminator ? name extends "" ? ErrorMessage<emptyGenericParameterMessage> : lookahead extends "," ? parseName<nextUnscanned, [...result, [name, unknown]], $> : lookahead extends
|
|
135
|
+
type parseNextNameChar<unscanned extends string, name extends string, result extends array<GenericParamAst>, $> = unscanned extends `${infer lookahead}${infer nextUnscanned}` ? lookahead extends ParamsTerminator ? name extends "" ? ErrorMessage<emptyGenericParameterMessage> : lookahead extends "," ? parseName<nextUnscanned, [...result, [name, unknown]], $> : lookahead extends WhiteSpaceToken ? _parseOptionalConstraint<nextUnscanned, name, result, $> : never : parseNextNameChar<nextUnscanned, `${name}${lookahead}`, result, $> : name extends "" ? result : [...result, [name, unknown]];
|
|
133
136
|
declare const extendsToken = "extends ";
|
|
134
|
-
type
|
|
135
|
-
declare const _parseOptionalConstraint: (scanner: Scanner, name: string, result: GenericParamDef[], ctx:
|
|
136
|
-
type _parseOptionalConstraint<unscanned extends string, name extends string, result extends array<GenericParamAst>, $> = Scanner.skipWhitespace<unscanned> extends (`${
|
|
137
|
+
type extendsToken = typeof extendsToken;
|
|
138
|
+
declare const _parseOptionalConstraint: (scanner: Scanner, name: string, result: GenericParamDef[], ctx: BaseParseContext) => GenericParamDef[];
|
|
139
|
+
type _parseOptionalConstraint<unscanned extends string, name extends string, result extends array<GenericParamAst>, $> = Scanner.skipWhitespace<unscanned> extends (`${extendsToken}${infer nextUnscanned}`) ? parseUntilFinalizer<state.initialize<nextUnscanned>, $, {}> extends (infer finalArgState extends StaticState) ? validateAst<finalArgState["root"], $, {}> extends (infer e extends ErrorMessage) ? e : parseName<finalArgState["unscanned"], [
|
|
137
140
|
...result,
|
|
138
141
|
[name, inferAstRoot<finalArgState["root"], $, {}>]
|
|
139
142
|
], $> : never : parseName<Scanner.skipWhitespace<unscanned> extends `,${infer nextUnscanned}` ? nextUnscanned : unscanned, [
|
|
140
143
|
...result,
|
|
141
144
|
[name, unknown]
|
|
142
145
|
], $>;
|
|
143
|
-
type genericParamDefToAst<schema extends GenericParamDef, $> = schema extends string ? [schema, unknown] : schema extends readonly [infer name, infer def] ? [
|
|
144
|
-
name,
|
|
145
|
-
inferTypeRoot<def, $>
|
|
146
|
-
] : never;
|
|
146
|
+
type genericParamDefToAst<schema extends GenericParamDef, $> = schema extends string ? [schema, unknown] : schema extends readonly [infer name, infer def] ? [name, type.infer<def, $>] : never;
|
|
147
147
|
export type genericParamDefsToAst<defs extends array<GenericParamDef>, $> = [
|
|
148
148
|
...{
|
|
149
149
|
[i in keyof defs]: genericParamDefToAst<defs[i], $>;
|
|
150
150
|
}
|
|
151
151
|
];
|
|
152
|
-
export type GenericParser<$ = {}> = <const paramsDef extends array<GenericParamDef>>(...params:
|
|
152
|
+
export type GenericParser<$ = {}> = <const paramsDef extends array<GenericParamDef>>(...params: {
|
|
153
|
+
[i in keyof paramsDef]: paramsDef[i] extends (readonly [infer name, infer def]) ? readonly [name, type.validate<def, $>] : paramsDef[i];
|
|
154
|
+
}) => GenericBodyParser<genericParamDefsToAst<paramsDef, $>, $>;
|
|
153
155
|
interface GenericBodyParser<params extends array<GenericParamAst>, $> {
|
|
154
156
|
<const body>(body: validateDefinition<body, $, baseGenericConstraints<params>>): Generic<params, body, $, $>;
|
|
155
157
|
<hkt extends Hkt.constructor>(instantiateDef: LazyGenericBody<baseGenericResolutions<params, $>>, hkt: hkt): Generic<params, InstanceType<hkt>, $, $>;
|
package/out/generic.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { GenericRoot } from "@ark/schema";
|
|
1
2
|
import { throwParseError } from "@ark/util";
|
|
2
|
-
import { DynamicState } from "./parser/
|
|
3
|
-
import {
|
|
4
|
-
|
|
3
|
+
import { DynamicState } from "./parser/reduce/dynamic.js";
|
|
4
|
+
import { parseUntilFinalizer } from "./parser/string.js";
|
|
5
|
+
export const Generic = GenericRoot;
|
|
5
6
|
export const emptyGenericParameterMessage = "An empty string is not a valid generic parameter name";
|
|
6
|
-
export const
|
|
7
|
-
const parseName = (scanner, result, ctx) => {
|
|
7
|
+
export const parseGenericParamName = (scanner, result, ctx) => {
|
|
8
8
|
scanner.shiftUntilNonWhitespace();
|
|
9
9
|
const name = scanner.shiftUntilNextTerminator();
|
|
10
10
|
if (name === "") {
|
|
@@ -20,9 +20,7 @@ const parseName = (scanner, result, ctx) => {
|
|
|
20
20
|
const extendsToken = "extends ";
|
|
21
21
|
const _parseOptionalConstraint = (scanner, name, result, ctx) => {
|
|
22
22
|
scanner.shiftUntilNonWhitespace();
|
|
23
|
-
if (scanner.
|
|
24
|
-
scanner.shift();
|
|
25
|
-
else if (scanner.unscanned.startsWith(extendsToken))
|
|
23
|
+
if (scanner.unscanned.startsWith(extendsToken))
|
|
26
24
|
scanner.jumpForward(extendsToken.length);
|
|
27
25
|
else {
|
|
28
26
|
// if we don't have a contraining token here, return now so we can
|
|
@@ -30,9 +28,9 @@ const _parseOptionalConstraint = (scanner, name, result, ctx) => {
|
|
|
30
28
|
if (scanner.lookahead === ",")
|
|
31
29
|
scanner.shift();
|
|
32
30
|
result.push(name);
|
|
33
|
-
return
|
|
31
|
+
return parseGenericParamName(scanner, result, ctx);
|
|
34
32
|
}
|
|
35
|
-
const s = parseUntilFinalizer(new DynamicState(scanner, ctx
|
|
33
|
+
const s = parseUntilFinalizer(new DynamicState(scanner, ctx));
|
|
36
34
|
result.push([name, s.root]);
|
|
37
|
-
return
|
|
35
|
+
return parseGenericParamName(scanner, result, ctx);
|
|
38
36
|
};
|
package/out/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { ArkError, ArkErrors, type ArkConfig, type ArkScopeConfig, type JsonSchema } from "@ark/schema";
|
|
2
|
-
export { Hkt } from "@ark/util";
|
|
3
|
-
export
|
|
4
|
-
export {
|
|
2
|
+
export { Hkt, inferred } from "@ark/util";
|
|
3
|
+
export { Generic } from "./generic.ts";
|
|
4
|
+
export { ark, declare, define, generic, keywords, type, type Ark } from "./keywords/keywords.ts";
|
|
5
5
|
export { Module, type BoundModule, type Submodule } from "./module.ts";
|
|
6
|
-
export { module, scope, type Scope
|
|
7
|
-
export { Type
|
|
6
|
+
export { module, scope, type Scope } from "./scope.ts";
|
|
7
|
+
export { Type } from "./type.ts";
|
package/out/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { ArkError, ArkErrors } from "@ark/schema";
|
|
2
|
-
export { Hkt } from "@ark/util";
|
|
3
|
-
export {
|
|
2
|
+
export { Hkt, inferred } from "@ark/util";
|
|
3
|
+
export { Generic } from "./generic.js";
|
|
4
|
+
export { ark, declare, define, generic, keywords, type } from "./keywords/keywords.js";
|
|
4
5
|
export { Module } from "./module.js";
|
|
5
6
|
export { module, scope } from "./scope.js";
|
|
6
7
|
export { Type } from "./type.js";
|
|
@@ -5,9 +5,13 @@ declare class MergeHkt extends Hkt<[base: object, props: object]> {
|
|
|
5
5
|
body: util.merge<this[0], this[1]>;
|
|
6
6
|
}
|
|
7
7
|
declare const Merge: import("@ark/schema").GenericRoot<readonly [["base", object], ["props", object]], MergeHkt>;
|
|
8
|
-
export declare const
|
|
9
|
-
export type
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
export declare const arkBuiltins: arkBuiltins;
|
|
9
|
+
export type arkBuiltins = Module<arkBuiltins.$>;
|
|
10
|
+
export declare namespace arkBuiltins {
|
|
11
|
+
type submodule = Submodule<$>;
|
|
12
|
+
type $ = {
|
|
13
|
+
Key: Key;
|
|
14
|
+
Merge: typeof Merge.t;
|
|
15
|
+
};
|
|
16
|
+
}
|
|
13
17
|
export {};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { genericNode, intrinsic } from "@ark/schema";
|
|
2
2
|
import { Hkt } from "@ark/util";
|
|
3
|
-
import {
|
|
3
|
+
import { arkModule } from "./utils.js";
|
|
4
4
|
class MergeHkt extends Hkt {
|
|
5
5
|
}
|
|
6
6
|
const Merge = genericNode(["base", intrinsic.object], ["props", intrinsic.object])(args => args.base.merge(args.props), MergeHkt);
|
|
7
|
-
export const
|
|
7
|
+
export const arkBuiltins = arkModule({
|
|
8
8
|
Key: intrinsic.key,
|
|
9
9
|
Merge
|
|
10
10
|
});
|
|
@@ -1,16 +1,20 @@
|
|
|
1
1
|
import { Hkt, liftArray, type Digit } from "@ark/util";
|
|
2
2
|
import type { Module, Submodule } from "../../module.ts";
|
|
3
|
-
import type { To } from "../
|
|
3
|
+
import type { To } from "../inference.ts";
|
|
4
4
|
declare class liftFromHkt extends Hkt<[element: unknown]> {
|
|
5
5
|
body: liftArray<this[0]> extends infer lifted ? (In: this[0] | lifted) => To<lifted> : never;
|
|
6
6
|
}
|
|
7
7
|
declare const liftFrom: import("@ark/schema").GenericRoot<readonly [["element", unknown]], liftFromHkt>;
|
|
8
|
-
export declare const
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
8
|
+
export declare const arkArray: arkArray.module;
|
|
9
|
+
export declare namespace arkArray {
|
|
10
|
+
type module = Module<submodule>;
|
|
11
|
+
type submodule = Submodule<$>;
|
|
12
|
+
type $ = {
|
|
13
|
+
root: unknown[];
|
|
14
|
+
readonly: readonly unknown[];
|
|
15
|
+
index: NonNegativeIntegerString;
|
|
16
|
+
liftFrom: typeof liftFrom.t;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
15
19
|
export type NonNegativeIntegerString = `${Digit}` | (`${Exclude<Digit, 0>}${string}` & `${bigint}`);
|
|
16
20
|
export {};
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { genericNode, intrinsic,
|
|
1
|
+
import { genericNode, intrinsic, rootSchema } from "@ark/schema";
|
|
2
2
|
import { Hkt, liftArray } from "@ark/util";
|
|
3
|
-
import {
|
|
3
|
+
import { arkModule } from "../utils.js";
|
|
4
4
|
class liftFromHkt extends Hkt {
|
|
5
5
|
}
|
|
6
6
|
const liftFrom = genericNode("element")(args => {
|
|
7
7
|
const nonArrayElement = args.element.exclude(intrinsic.Array);
|
|
8
8
|
const lifted = nonArrayElement.array();
|
|
9
9
|
return nonArrayElement
|
|
10
|
-
.
|
|
10
|
+
.rawOr(lifted)
|
|
11
11
|
.pipe(liftArray)
|
|
12
|
-
.distribute(branch => branch.assertHasKind("morph").declareOut(lifted),
|
|
12
|
+
.distribute(branch => branch.assertHasKind("morph").declareOut(lifted), rootSchema);
|
|
13
13
|
}, liftFromHkt);
|
|
14
|
-
export const
|
|
15
|
-
|
|
16
|
-
readonly: "
|
|
14
|
+
export const arkArray = arkModule({
|
|
15
|
+
root: intrinsic.Array,
|
|
16
|
+
readonly: "root",
|
|
17
17
|
index: intrinsic.nonNegativeIntegerString,
|
|
18
18
|
liftFrom
|
|
19
19
|
});
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { Branded, constrain, constraint, Constraints, Default, Literal, Narrowed, normalizeLimit, Optional } from "../inference.ts";
|
|
2
|
+
export type AtOrAfter<rule> = {
|
|
3
|
+
atOrAfter: constraint<rule>;
|
|
4
|
+
};
|
|
5
|
+
export type AtOrBefore<rule> = {
|
|
6
|
+
atOrBefore: constraint<rule>;
|
|
7
|
+
};
|
|
8
|
+
export type After<rule> = {
|
|
9
|
+
after: constraint<rule>;
|
|
10
|
+
};
|
|
11
|
+
export type Before<rule> = {
|
|
12
|
+
before: constraint<rule>;
|
|
13
|
+
};
|
|
14
|
+
export declare namespace Date {
|
|
15
|
+
type atOrAfter<rule> = constrain<Date, AtOrAfter<rule>>;
|
|
16
|
+
type after<rule> = constrain<Date, After<rule>>;
|
|
17
|
+
type atOrBefore<rule> = constrain<Date, AtOrBefore<rule>>;
|
|
18
|
+
type before<rule> = constrain<Date, Before<rule>>;
|
|
19
|
+
type narrowed = constrain<Date, Narrowed>;
|
|
20
|
+
type optional = constrain<Date, Optional>;
|
|
21
|
+
type defaultsTo<rule> = constrain<Date, Default<rule>>;
|
|
22
|
+
type branded<rule> = constrain<Date, Branded<rule>>;
|
|
23
|
+
type literal<rule> = constrain<Date, Literal<rule>>;
|
|
24
|
+
type is<constraints extends Constraints> = constrain<Date, constraints>;
|
|
25
|
+
type afterSchemaToConstraint<schema, rule> = schema extends {
|
|
26
|
+
exclusive: true;
|
|
27
|
+
} ? After<normalizeLimit<rule>> : AtOrAfter<normalizeLimit<rule>>;
|
|
28
|
+
type beforeSchemaToConstraint<schema, rule> = schema extends {
|
|
29
|
+
exclusive: true;
|
|
30
|
+
} ? Before<normalizeLimit<rule>> : AtOrBefore<normalizeLimit<rule>>;
|
|
31
|
+
type withConstraint<constraint> = constraint extends After<infer rule> ? after<rule> : constraint extends Before<infer rule> ? before<rule> : constraint extends AtOrAfter<infer rule> ? atOrAfter<rule> : constraint extends AtOrBefore<infer rule> ? atOrBefore<rule> : constraint extends Optional ? optional : constraint extends Default<infer rule> ? defaultsTo<rule> : constraint extends Narrowed ? narrowed : never;
|
|
32
|
+
}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type {
|
|
2
|
+
import type { To } from "../inference.ts";
|
|
3
3
|
export type FormDataValue = string | File;
|
|
4
4
|
export type ParsedFormData = Record<string, FormDataValue | FormDataValue[]>;
|
|
5
|
-
export declare const
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
export declare const arkFormData: arkFormData.module;
|
|
6
|
+
export declare namespace arkFormData {
|
|
7
|
+
type module = Module<submodule>;
|
|
8
|
+
type submodule = Submodule<$>;
|
|
9
|
+
type $ = {
|
|
10
|
+
root: FormData;
|
|
11
|
+
value: FormDataValue;
|
|
12
|
+
parse: (In: FormData) => To<ParsedFormData>;
|
|
13
|
+
parsed: ParsedFormData;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
@@ -1,9 +1,21 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { rootSchema } from "@ark/schema";
|
|
2
2
|
import { registry } from "@ark/util";
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
import { arkModule } from "../utils.js";
|
|
4
|
+
const value = rootSchema(["string", registry.FileConstructor]);
|
|
5
|
+
const parsedFormDataValue = value.rawOr(value.array());
|
|
6
|
+
const parsed = rootSchema({
|
|
7
|
+
meta: "an object representing parsed form data",
|
|
8
|
+
domain: "object",
|
|
9
|
+
index: {
|
|
10
|
+
signature: "string",
|
|
11
|
+
value: parsedFormDataValue
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
export const arkFormData = arkModule({
|
|
15
|
+
root: ["instanceof", FormData],
|
|
16
|
+
value,
|
|
17
|
+
parsed,
|
|
18
|
+
parse: rootSchema({
|
|
7
19
|
in: FormData,
|
|
8
20
|
morphs: (data) => {
|
|
9
21
|
const result = {};
|
|
@@ -20,6 +32,7 @@ export const FormDataModule = submodule({
|
|
|
20
32
|
result[k] = v;
|
|
21
33
|
}
|
|
22
34
|
return result;
|
|
23
|
-
}
|
|
35
|
+
},
|
|
36
|
+
declaredOut: parsed
|
|
24
37
|
})
|
|
25
38
|
});
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
export declare const TypedArray:
|
|
3
|
-
export
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
export declare const TypedArray: TypedArray.module;
|
|
3
|
+
export declare namespace TypedArray {
|
|
4
|
+
type module = Module<TypedArray.$>;
|
|
5
|
+
type submodule = Submodule<$>;
|
|
6
|
+
type $ = {
|
|
7
|
+
Int8: Int8Array;
|
|
8
|
+
Uint8: Uint8Array;
|
|
9
|
+
Uint8Clamped: Uint8ClampedArray;
|
|
10
|
+
Int16: Int16Array;
|
|
11
|
+
Uint16: Uint16Array;
|
|
12
|
+
Int32: Int32Array;
|
|
13
|
+
Uint32: Uint32Array;
|
|
14
|
+
Float32: Float32Array;
|
|
15
|
+
Float64: Float64Array;
|
|
16
|
+
BigInt64: BigInt64Array;
|
|
17
|
+
BigUint64: BigUint64Array;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export const TypedArray =
|
|
1
|
+
import { arkModule } from "../utils.js";
|
|
2
|
+
export const TypedArray = arkModule({
|
|
3
3
|
Int8: ["instanceof", Int8Array],
|
|
4
4
|
Uint8: ["instanceof", Uint8Array],
|
|
5
5
|
Uint8Clamped: ["instanceof", Uint8ClampedArray],
|
|
@@ -1,41 +1,30 @@
|
|
|
1
|
+
import { type EcmascriptObjects, type PlatformObjects } from "@ark/util";
|
|
1
2
|
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
3
|
+
import { arkArray } from "./Array.ts";
|
|
4
|
+
import { arkFormData } from "./FormData.ts";
|
|
4
5
|
import { TypedArray } from "./TypedArray.ts";
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
declare const omittedPrototypes: {
|
|
7
|
+
Boolean: 1;
|
|
8
|
+
Number: 1;
|
|
9
|
+
String: 1;
|
|
10
|
+
};
|
|
11
|
+
export declare const arkPrototypes: arkPrototypes.module;
|
|
7
12
|
export declare namespace arkPrototypes {
|
|
13
|
+
type module = Module<submodule>;
|
|
8
14
|
type submodule = Submodule<$>;
|
|
9
|
-
interface
|
|
15
|
+
interface keywords extends ecmascript, platform {
|
|
10
16
|
}
|
|
11
|
-
interface
|
|
12
|
-
Array: ArrayModule;
|
|
13
|
-
TypedArray: TypedArray;
|
|
17
|
+
interface $ extends Omit<keywords, keyof wrapped>, wrapped {
|
|
14
18
|
}
|
|
15
|
-
|
|
16
|
-
Array:
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
WeakMap: WeakMap<object, unknown>;
|
|
24
|
-
WeakSet: WeakSet<object>;
|
|
25
|
-
Promise: Promise<unknown>;
|
|
26
|
-
};
|
|
27
|
-
type platform = {
|
|
28
|
-
ArrayBuffer: ArrayBuffer;
|
|
29
|
-
Blob: Blob;
|
|
30
|
-
File: File;
|
|
31
|
-
FormData: FormDataModule;
|
|
32
|
-
Headers: Headers;
|
|
33
|
-
Request: Request;
|
|
34
|
-
Response: Response;
|
|
35
|
-
URL: URL;
|
|
36
|
-
};
|
|
37
|
-
interface instances extends ecmascript, platform, TypedArray {
|
|
19
|
+
interface wrapped {
|
|
20
|
+
Array: arkArray.submodule;
|
|
21
|
+
TypedArray: TypedArray.submodule;
|
|
22
|
+
FormData: arkFormData.submodule;
|
|
23
|
+
}
|
|
24
|
+
type ecmascript = Omit<EcmascriptObjects, keyof typeof omittedPrototypes>;
|
|
25
|
+
type platform = PlatformObjects;
|
|
26
|
+
interface instances extends ecmascript, platform {
|
|
38
27
|
}
|
|
39
28
|
type instanceOf<name extends keyof instances = keyof instances> = instances[name];
|
|
40
|
-
type instanceOfExcluding<name extends keyof instances = keyof instances> = instances[Exclude<keyof instances, name>];
|
|
41
29
|
}
|
|
30
|
+
export {};
|
|
@@ -1,31 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { ecmascriptConstructors, flatMorph, platformConstructors } from "@ark/util";
|
|
2
|
+
import { arkModule } from "../utils.js";
|
|
3
|
+
import { arkArray } from "./Array.js";
|
|
4
|
+
import { arkFormData } from "./FormData.js";
|
|
5
5
|
import { TypedArray } from "./TypedArray.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
RegExp: ["instanceof", RegExp],
|
|
15
|
-
Set: ["instanceof", Set],
|
|
16
|
-
WeakMap: ["instanceof", WeakMap],
|
|
17
|
-
WeakSet: ["instanceof", WeakSet],
|
|
18
|
-
Promise: ["instanceof", Promise],
|
|
6
|
+
const omittedPrototypes = {
|
|
7
|
+
Boolean: 1,
|
|
8
|
+
Number: 1,
|
|
9
|
+
String: 1
|
|
10
|
+
};
|
|
11
|
+
export const arkPrototypes = arkModule({
|
|
12
|
+
...flatMorph({ ...ecmascriptConstructors, ...platformConstructors }, (k, v) => (k in omittedPrototypes ? [] : [k, ["instanceof", v]])),
|
|
13
|
+
Array: arkArray,
|
|
19
14
|
TypedArray,
|
|
20
|
-
|
|
21
|
-
// See https://developer.mozilla.org/en-US/docs/Web/API
|
|
22
|
-
// Must be implemented in Node etc. as well as the browser to include here
|
|
23
|
-
ArrayBuffer: ["instanceof", ArrayBuffer],
|
|
24
|
-
Blob: ["instanceof", Blob],
|
|
25
|
-
File: ["instanceof", registry.FileConstructor],
|
|
26
|
-
FormData: FormDataModule,
|
|
27
|
-
Headers: ["instanceof", Headers],
|
|
28
|
-
Request: ["instanceof", Request],
|
|
29
|
-
Response: ["instanceof", Response],
|
|
30
|
-
URL: ["instanceof", URL]
|
|
15
|
+
FormData: arkFormData
|
|
31
16
|
});
|