arktype 2.0.0-rc.4 → 2.0.0-rc.6
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/generic.d.ts +34 -36
- package/out/generic.js +1 -1
- package/out/index.d.ts +2 -2
- package/out/index.js +1 -1
- package/out/intersect.d.ts +2 -4
- package/out/keywords/ark.d.ts +20 -3
- package/out/keywords/ark.js +3 -2
- package/out/keywords/ast.d.ts +97 -102
- package/out/keywords/builtins.js +2 -2
- package/out/keywords/constructors/Array.d.ts +1 -1
- package/out/keywords/constructors/Array.js +4 -4
- package/out/keywords/constructors/Date.d.ts +31 -0
- package/out/keywords/constructors/FormData.d.ts +1 -1
- package/out/keywords/constructors/FormData.js +3 -3
- package/out/keywords/constructors/TypedArray.js +2 -2
- package/out/keywords/constructors/constructors.js +2 -2
- package/out/keywords/number/epoch.d.ts +1 -2
- package/out/keywords/number/number.d.ts +31 -6
- package/out/keywords/number/number.js +17 -5
- package/out/keywords/string/capitalize.d.ts +1 -1
- package/out/keywords/string/capitalize.js +3 -3
- package/out/keywords/string/date.d.ts +3 -7
- package/out/keywords/string/date.js +11 -11
- package/out/keywords/string/integer.d.ts +1 -1
- package/out/keywords/string/integer.js +5 -5
- package/out/keywords/string/ip.d.ts +1 -1
- package/out/keywords/string/ip.js +3 -3
- package/out/keywords/string/json.d.ts +1 -1
- package/out/keywords/string/json.js +4 -4
- package/out/keywords/string/lower.d.ts +1 -1
- package/out/keywords/string/lower.js +3 -3
- package/out/keywords/string/normalize.d.ts +14 -18
- package/out/keywords/string/normalize.js +11 -11
- package/out/keywords/string/numeric.d.ts +1 -1
- package/out/keywords/string/numeric.js +5 -5
- package/out/keywords/string/string.d.ts +18 -22
- package/out/keywords/string/string.js +3 -3
- package/out/keywords/string/trim.d.ts +1 -1
- package/out/keywords/string/trim.js +3 -3
- package/out/keywords/string/upper.d.ts +1 -1
- package/out/keywords/string/upper.js +3 -3
- package/out/keywords/string/url.d.ts +1 -1
- package/out/keywords/string/url.js +5 -5
- package/out/keywords/string/uuid.d.ts +2 -2
- package/out/keywords/string/uuid.js +3 -3
- package/out/keywords/ts.d.ts +11 -0
- package/out/keywords/ts.js +7 -3
- 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 +87 -0
- package/out/{subtypes → methods}/date.d.ts +5 -5
- package/out/methods/morph.d.ts +13 -0
- package/out/{subtypes → methods}/number.d.ts +6 -6
- package/out/{subtypes → methods}/object.d.ts +1 -2
- package/out/{subtypes → methods}/string.d.ts +7 -7
- package/out/{subtypes → methods}/validator.d.ts +2 -2
- package/out/methods/validator.js +1 -0
- package/out/module.d.ts +2 -2
- package/out/parser/objectLiteral.d.ts +5 -30
- package/out/parser/objectLiteral.js +18 -21
- package/out/parser/semantic/default.d.ts +3 -4
- package/out/parser/semantic/default.js +1 -1
- package/out/parser/semantic/infer.d.ts +8 -7
- package/out/parser/semantic/validate.d.ts +2 -2
- package/out/parser/string/reduce/dynamic.d.ts +1 -2
- package/out/parser/string/reduce/dynamic.js +2 -4
- package/out/parser/string/shift/operand/date.d.ts +2 -0
- package/out/parser/string/shift/operand/enclosed.d.ts +2 -1
- package/out/parser/string/shift/operand/enclosed.js +7 -3
- package/out/parser/string/shift/operator/default.d.ts +2 -5
- package/out/parser/string/shift/operator/default.js +1 -6
- package/out/parser/string/string.d.ts +2 -3
- package/out/parser/tuple.d.ts +6 -5
- package/out/parser/tuple.js +13 -6
- package/out/scope.d.ts +9 -5
- package/out/scope.js +12 -8
- package/out/type.d.ts +13 -12
- package/out/type.js +4 -1
- package/package.json +3 -3
- package/out/subtypes/base.d.ts +0 -85
- package/out/subtypes/morph.d.ts +0 -13
- /package/out/{subtypes/array.js → keywords/constructors/Date.js} +0 -0
- /package/out/{subtypes/base.js → methods/array.js} +0 -0
- /package/out/{subtypes/date.js → methods/base.js} +0 -0
- /package/out/{subtypes/instantiate.js → methods/date.js} +0 -0
- /package/out/{subtypes → methods}/instantiate.d.ts +0 -0
- /package/out/{subtypes/morph.js → methods/instantiate.js} +0 -0
- /package/out/{subtypes/number.js → methods/morph.js} +0 -0
- /package/out/{subtypes/object.js → methods/number.js} +0 -0
- /package/out/{subtypes/string.js → methods/object.js} +0 -0
- /package/out/{subtypes/validator.js → methods/string.js} +0 -0
package/out/generic.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { GenericRoot, type arkKind, type GenericAst, type GenericParamAst, type GenericParamDef, type genericParamNames, type LazyGenericBody } from "@ark/schema";
|
|
2
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/ark.ts";
|
|
3
4
|
import type { inferDefinition, validateDefinition } from "./parser/definition.ts";
|
|
4
5
|
import type { inferAstRoot } from "./parser/semantic/infer.ts";
|
|
5
6
|
import type { validateAst } from "./parser/semantic/validate.ts";
|
|
@@ -7,23 +8,23 @@ import type { state, StaticState } from "./parser/string/reduce/static.ts";
|
|
|
7
8
|
import { Scanner } from "./parser/string/shift/scanner.ts";
|
|
8
9
|
import { parseUntilFinalizer } from "./parser/string/string.ts";
|
|
9
10
|
import type { ParseContext, Scope } from "./scope.ts";
|
|
10
|
-
import type {
|
|
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
|
+
<const a, const b, r = instantiateGeneric<def, params, [a, b], $, args$>>(...args: [type.validate<a, args$>, type.validate<b, args$>] & [
|
|
19
20
|
validateGenericArg<a, params[0], args$>,
|
|
20
21
|
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], $>;
|
|
@@ -143,17 +144,14 @@ type _parseOptionalConstraint<unscanned extends string, name extends string, res
|
|
|
143
144
|
...result,
|
|
144
145
|
[name, unknown]
|
|
145
146
|
], $>;
|
|
146
|
-
type genericParamDefToAst<schema extends GenericParamDef, $> = schema extends string ? [schema, unknown] : schema extends readonly [infer name, infer def] ? [
|
|
147
|
-
name,
|
|
148
|
-
inferTypeRoot<def, $>
|
|
149
|
-
] : never;
|
|
147
|
+
type genericParamDefToAst<schema extends GenericParamDef, $> = schema extends string ? [schema, unknown] : schema extends readonly [infer name, infer def] ? [name, type.infer<def, $>] : never;
|
|
150
148
|
export type genericParamDefsToAst<defs extends array<GenericParamDef>, $> = [
|
|
151
149
|
...{
|
|
152
150
|
[i in keyof defs]: genericParamDefToAst<defs[i], $>;
|
|
153
151
|
}
|
|
154
152
|
];
|
|
155
153
|
export type GenericParser<$ = {}> = <const paramsDef extends array<GenericParamDef>>(...params: {
|
|
156
|
-
[i in keyof paramsDef]: paramsDef[i] extends (readonly [infer name, infer def]) ? readonly [name,
|
|
154
|
+
[i in keyof paramsDef]: paramsDef[i] extends (readonly [infer name, infer def]) ? readonly [name, type.validate<def, $>] : paramsDef[i];
|
|
157
155
|
}) => GenericBodyParser<genericParamDefsToAst<paramsDef, $>, $>;
|
|
158
156
|
interface GenericBodyParser<params extends array<GenericParamAst>, $> {
|
|
159
157
|
<const body>(body: validateDefinition<body, $, baseGenericConstraints<params>>): Generic<params, body, $, $>;
|
package/out/generic.js
CHANGED
|
@@ -32,7 +32,7 @@ const _parseOptionalConstraint = (scanner, name, result, ctx) => {
|
|
|
32
32
|
result.push(name);
|
|
33
33
|
return parseName(scanner, result, ctx);
|
|
34
34
|
}
|
|
35
|
-
const s = parseUntilFinalizer(new DynamicState(scanner, ctx
|
|
35
|
+
const s = parseUntilFinalizer(new DynamicState(scanner, ctx));
|
|
36
36
|
result.push([name, s.root]);
|
|
37
37
|
return parseName(scanner, result, ctx);
|
|
38
38
|
};
|
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";
|
|
2
|
+
export { Hkt, inferred } from "@ark/util";
|
|
3
3
|
export { Generic } from "./generic.ts";
|
|
4
4
|
export { ambient, ark, declare, define, generic, type, type Ark } from "./keywords/ark.ts";
|
|
5
5
|
export { Module, type BoundModule, type Submodule } from "./module.ts";
|
|
6
6
|
export { module, scope, type Scope, type inferScope, type validateScope } from "./scope.ts";
|
|
7
|
-
export { Type
|
|
7
|
+
export { Type } from "./type.ts";
|
package/out/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { ArkError, ArkErrors } from "@ark/schema";
|
|
2
|
-
export { Hkt } from "@ark/util";
|
|
2
|
+
export { Hkt, inferred } from "@ark/util";
|
|
3
3
|
export { Generic } from "./generic.js";
|
|
4
4
|
export { ambient, ark, declare, define, generic, type } from "./keywords/ark.js";
|
|
5
5
|
export { Module } from "./module.js";
|
package/out/intersect.d.ts
CHANGED
|
@@ -17,10 +17,8 @@ type _inferIntersection<l, r, piped extends boolean> = [
|
|
|
17
17
|
interface MorphableIntersection<piped extends boolean> extends Hkt<[unknown, unknown]> {
|
|
18
18
|
body: _inferIntersection<this[0], this[1], piped>;
|
|
19
19
|
}
|
|
20
|
-
type intersectObjects<l, r, piped extends boolean> = [
|
|
21
|
-
|
|
22
|
-
r
|
|
23
|
-
] extends [infer lList extends array, infer rList extends array] ? intersectArrays<lList, rList, MorphableIntersection<piped>> : show<{
|
|
20
|
+
type intersectObjects<l, r, piped extends boolean> = l extends array ? r extends array ? intersectArrays<l, r, MorphableIntersection<piped>> : // for an intersection with exactly one array operand like { name: string } & string[],
|
|
21
|
+
l & r : r extends array ? l & r : show<{
|
|
24
22
|
[k in keyof l]: k extends keyof r ? _inferIntersection<l[k], r[k], piped> : l[k];
|
|
25
23
|
} & {
|
|
26
24
|
[k in keyof r]: k extends keyof l ? _inferIntersection<l[k], r[k], piped> : r[k];
|
package/out/keywords/ark.d.ts
CHANGED
|
@@ -2,13 +2,15 @@ import type { ArkErrors, arkKind } from "@ark/schema";
|
|
|
2
2
|
import type { inferred } from "@ark/util";
|
|
3
3
|
import type { GenericParser } from "../generic.ts";
|
|
4
4
|
import type { BoundModule, Module } from "../module.ts";
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
5
|
+
import type { inferDefinition, validateDefinition } from "../parser/definition.ts";
|
|
6
|
+
import { type bindThis, type Scope } from "../scope.ts";
|
|
7
|
+
import type { DeclarationParser, DefinitionParser, Type, TypeParser } from "../type.ts";
|
|
8
|
+
import type { distill } from "./ast.ts";
|
|
7
9
|
import { arkBuiltins } from "./builtins.ts";
|
|
8
10
|
import { arkPrototypes } from "./constructors/constructors.ts";
|
|
9
11
|
import { number } from "./number/number.ts";
|
|
10
12
|
import { string } from "./string/string.ts";
|
|
11
|
-
import { arkTsGenerics, arkTsKeywords } from "./ts.ts";
|
|
13
|
+
import { arkTsGenerics, arkTsKeywords, unknown } from "./ts.ts";
|
|
12
14
|
export interface Ark extends Omit<Ark.keywords, keyof Ark.wrapped>, Ark.wrapped {
|
|
13
15
|
}
|
|
14
16
|
export declare namespace Ark {
|
|
@@ -17,6 +19,7 @@ export declare namespace Ark {
|
|
|
17
19
|
interface wrapped extends arkPrototypes.wrapped {
|
|
18
20
|
string: string.submodule;
|
|
19
21
|
number: number.submodule;
|
|
22
|
+
unknown: unknown.submodule;
|
|
20
23
|
}
|
|
21
24
|
interface typeAttachments extends arkTsKeywords.$ {
|
|
22
25
|
Key: arkBuiltins.$["Key"];
|
|
@@ -33,7 +36,21 @@ export declare namespace type {
|
|
|
33
36
|
[inferred]?: t;
|
|
34
37
|
};
|
|
35
38
|
type errors = ArkErrors;
|
|
39
|
+
type infer<def, $ = {}, args = bindThis<def>> = inferDefinition<def, $, args>;
|
|
40
|
+
namespace infer {
|
|
41
|
+
type In<def, $ = {}, args = {}> = distill.In<inferDefinition<def, $, args>>;
|
|
42
|
+
type Out<def, $ = {}, args = {}> = distill.Out<inferDefinition<def, $, args>>;
|
|
43
|
+
namespace brandable {
|
|
44
|
+
type In<def, $ = {}, args = {}> = distill.brandable.In<inferDefinition<def, $, args>>;
|
|
45
|
+
type Out<def, $ = {}, args = {}> = distill.brandable.Out<inferDefinition<def, $, args>>;
|
|
46
|
+
}
|
|
47
|
+
namespace introspectable {
|
|
48
|
+
type Out<def, $ = {}, args = {}> = distill.introspectable.Out<inferDefinition<def, $, args>>;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
type validate<def, $ = {}, args = bindThis<def>> = validateDefinition<def, $, args>;
|
|
36
52
|
}
|
|
53
|
+
export type type<t = unknown, $ = {}> = Type<t, $>;
|
|
37
54
|
export declare const generic: GenericParser<{}>;
|
|
38
55
|
export declare const define: DefinitionParser<{}>;
|
|
39
56
|
export declare const declare: DeclarationParser<{}>;
|
package/out/keywords/ark.js
CHANGED
|
@@ -3,7 +3,7 @@ import { arkBuiltins } from "./builtins.js";
|
|
|
3
3
|
import { arkPrototypes } from "./constructors/constructors.js";
|
|
4
4
|
import { number } from "./number/number.js";
|
|
5
5
|
import { string } from "./string/string.js";
|
|
6
|
-
import { arkTsGenerics, arkTsKeywords } from "./ts.js";
|
|
6
|
+
import { arkTsGenerics, arkTsKeywords, unknown } from "./ts.js";
|
|
7
7
|
$arkTypeRegistry.typeAttachments = {
|
|
8
8
|
...arkTsKeywords,
|
|
9
9
|
Key: arkBuiltins.Key,
|
|
@@ -15,7 +15,8 @@ export const ambient = scope({
|
|
|
15
15
|
...arkPrototypes,
|
|
16
16
|
...arkBuiltins,
|
|
17
17
|
string,
|
|
18
|
-
number
|
|
18
|
+
number,
|
|
19
|
+
unknown
|
|
19
20
|
}, { prereducedAliases: true, ambient: true });
|
|
20
21
|
export const ark = ambient.export();
|
|
21
22
|
export const type = ambient.type;
|
package/out/keywords/ast.d.ts
CHANGED
|
@@ -4,8 +4,9 @@ import type { inferPipe } from "../intersect.ts";
|
|
|
4
4
|
import type { Type } from "../type.ts";
|
|
5
5
|
import type { type } from "./ark.ts";
|
|
6
6
|
import type { arkPrototypes } from "./constructors/constructors.ts";
|
|
7
|
-
import type {
|
|
8
|
-
import type {
|
|
7
|
+
import type { Date } from "./constructors/Date.ts";
|
|
8
|
+
import type { DivisibleBy, number } from "./number/number.ts";
|
|
9
|
+
import type { Matching, string } from "./string/string.ts";
|
|
9
10
|
export type { arkPrototypes as object } from "./constructors/constructors.ts";
|
|
10
11
|
export type { number } from "./number/number.ts";
|
|
11
12
|
export type { string } from "./string/string.ts";
|
|
@@ -21,36 +22,15 @@ export type constrain<base, constraints extends Constraints> = base & {
|
|
|
21
22
|
};
|
|
22
23
|
export type LimitLiteral = number | DateLiteral;
|
|
23
24
|
export type normalizeLimit<limit> = limit extends DateLiteral<infer source> ? source : limit extends number | string ? limit : never;
|
|
24
|
-
type constraint<rule> = {
|
|
25
|
+
export type constraint<rule> = {
|
|
25
26
|
[k in rule & PropertyKey]: 1;
|
|
26
27
|
};
|
|
27
|
-
export type AtLeast<rule> = {
|
|
28
|
-
atLeast: constraint<rule>;
|
|
29
|
-
};
|
|
30
|
-
export type AtMost<rule> = {
|
|
31
|
-
atMost: constraint<rule>;
|
|
32
|
-
};
|
|
33
|
-
export type MoreThan<rule> = {
|
|
34
|
-
moreThan: constraint<rule>;
|
|
35
|
-
};
|
|
36
|
-
export type LessThan<rule> = {
|
|
37
|
-
lessThan: constraint<rule>;
|
|
38
|
-
};
|
|
39
28
|
export type Literal<rule> = {
|
|
40
29
|
literal: constraint<rule>;
|
|
41
30
|
};
|
|
42
|
-
export type DivisibleBy<rule> = {
|
|
43
|
-
divisibleBy: constraint<rule>;
|
|
44
|
-
};
|
|
45
|
-
export type Length<rule> = {
|
|
46
|
-
length: constraint<rule>;
|
|
47
|
-
};
|
|
48
|
-
export type Matching<rule> = {
|
|
49
|
-
matching: constraint<rule>;
|
|
50
|
-
};
|
|
51
31
|
export type Narrowed = {
|
|
52
32
|
predicate: {
|
|
53
|
-
|
|
33
|
+
"?": 1;
|
|
54
34
|
};
|
|
55
35
|
};
|
|
56
36
|
export type Branded<rule> = {
|
|
@@ -73,41 +53,14 @@ export type ExactlyLength<rule> = {
|
|
|
73
53
|
atLeastLength: constraint<rule>;
|
|
74
54
|
atMostLength: constraint<rule>;
|
|
75
55
|
};
|
|
76
|
-
export type
|
|
77
|
-
|
|
78
|
-
};
|
|
79
|
-
export type AtOrBefore<rule> = {
|
|
80
|
-
atOrBefore: constraint<rule>;
|
|
81
|
-
};
|
|
82
|
-
export type After<rule> = {
|
|
83
|
-
after: constraint<rule>;
|
|
84
|
-
};
|
|
85
|
-
export type Before<rule> = {
|
|
86
|
-
before: constraint<rule>;
|
|
87
|
-
};
|
|
88
|
-
export declare namespace Date {
|
|
89
|
-
type atOrAfter<rule> = constrain<Date, AtOrAfter<rule>>;
|
|
90
|
-
type after<rule> = constrain<Date, After<rule>>;
|
|
91
|
-
type atOrBefore<rule> = constrain<Date, AtOrBefore<rule>>;
|
|
92
|
-
type before<rule> = constrain<Date, Before<rule>>;
|
|
93
|
-
type narrowed = constrain<Date, Narrowed>;
|
|
94
|
-
type branded<rule> = constrain<Date, Branded<rule>>;
|
|
95
|
-
type literal<rule> = constrain<Date, Literal<rule>>;
|
|
96
|
-
type is<constraints extends Constraints> = constrain<Date, constraints>;
|
|
97
|
-
type parseConstraint<kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = normalizePrimitiveConstraintRoot<schema> extends infer rule ? kind extends "after" ? schema extends {
|
|
98
|
-
exclusive: true;
|
|
99
|
-
} ? after<normalizeLimit<rule>> : atOrAfter<normalizeLimit<rule>> : kind extends "before" ? schema extends {
|
|
100
|
-
exclusive: true;
|
|
101
|
-
} ? before<normalizeLimit<rule>> : atOrBefore<normalizeLimit<rule>> : narrowed : never;
|
|
102
|
-
}
|
|
103
|
-
export type applyConstraint<t, kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = t extends MorphAst<infer i, infer o> ? (In: leftIfEqual<i, _applyConstraint<i, kind, schema>>) => o : leftIfEqual<t, _applyConstraint<t, kind, schema>>;
|
|
104
|
-
type _applyConstraint<t, kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = schemaToConstraint<kind, schema> extends infer constraint ? parseConstraints<t> extends ([
|
|
56
|
+
export type applyConstraintSchema<t, kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = t extends MorphAst<infer i, infer o> ? (In: leftIfEqual<i, applyConstraint<i, schemaToConstraint<kind, schema>>>) => o : leftIfEqual<t, applyConstraint<t, schemaToConstraint<kind, schema>>>;
|
|
57
|
+
export type applyConstraint<t, constraint> = parseConstraints<t> extends ([
|
|
105
58
|
infer base,
|
|
106
59
|
infer constraints extends Constraints
|
|
107
60
|
]) ? [
|
|
108
61
|
number,
|
|
109
62
|
base
|
|
110
|
-
] extends [base, number] ? number.is<constraint & constraints> : [string, base] extends [base, string] ? string.is<constraint & constraints> : [Date, base] extends [base, Date] ? Date.is<constraint & constraints> : constrain<base, constraints & constraint> : [number, t] extends [t, number] ? number.
|
|
63
|
+
] extends [base, number] ? number.is<constraint & constraints> : [string, base] extends [base, string] ? string.is<constraint & constraints> : [Date, base] extends [base, Date] ? Date.is<constraint & constraints> : constrain<base, constraints & constraint> : [number, t] extends [t, number] ? number.withConstraint<constraint> : [string, t] extends [t, string] ? string.withConstraint<constraint> : [Date, t] extends [t, Date] ? Date.withConstraint<constraint> : constrain<t, conform<constraint, Constraints>>;
|
|
111
64
|
export type parseConstraints<t> = t extends constrain<infer base, infer constraints> ? equals<t, number & {
|
|
112
65
|
[constrained]: constraints;
|
|
113
66
|
}> extends true ? [
|
|
@@ -125,69 +78,111 @@ export type parseConstraints<t> = t extends constrain<infer base, infer constrai
|
|
|
125
78
|
constraints
|
|
126
79
|
] : [base, constraints] : null;
|
|
127
80
|
export type normalizePrimitiveConstraintRoot<schema extends NodeSchema<Constraint.PrimitiveKind>> = "rule" extends keyof schema ? conform<schema["rule"], PropertyKey> : conform<schema, PropertyKey>;
|
|
128
|
-
|
|
129
|
-
exclusive: true;
|
|
130
|
-
} ? MoreThan<rule> : AtLeast<rule> : kind extends "max" ? schema extends {
|
|
131
|
-
exclusive: true;
|
|
132
|
-
} ? LessThan<rule> : AtMost<rule> : kind extends "minLength" ? schema extends {
|
|
133
|
-
exclusive: true;
|
|
134
|
-
} ? MoreThanLength<rule> : AtLeastLength<rule> : kind extends "maxLength" ? schema extends {
|
|
81
|
+
type minLengthSchemaToConstraint<schema, rule> = schema extends {
|
|
135
82
|
exclusive: true;
|
|
136
|
-
} ?
|
|
83
|
+
} ? MoreThanLength<rule> : AtLeastLength<rule>;
|
|
84
|
+
type maxLengthSchemaToConstraint<schema, rule> = schema extends {
|
|
137
85
|
exclusive: true;
|
|
138
|
-
} ?
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
export
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
86
|
+
} ? LessThanLength<rule> : AtMostLength<rule>;
|
|
87
|
+
export type schemaToConstraint<kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = normalizePrimitiveConstraintRoot<schema> extends infer rule ? kind extends "pattern" ? Matching<rule> : kind extends "divisor" ? DivisibleBy<rule> : kind extends "min" ? number.minSchemaToConstraint<schema, rule> : kind extends "max" ? number.maxSchemaToConstraint<schema, rule> : kind extends "minLength" ? minLengthSchemaToConstraint<schema, rule> : kind extends "maxLength" ? maxLengthSchemaToConstraint<schema, rule> : kind extends "exactLength" ? ExactlyLength<rule> : kind extends "after" ? Date.afterSchemaToConstraint<schema, rule> : kind extends "before" ? Date.beforeSchemaToConstraint<schema, rule> : Narrowed : never;
|
|
88
|
+
export type distill<t, opts extends distill.Options = {}> = finalizeDistillation<t, _distill<t, opts>>;
|
|
89
|
+
export declare namespace distill {
|
|
90
|
+
type Endpoint = "in" | "out" | "out.introspectable";
|
|
91
|
+
type Options = {
|
|
92
|
+
endpoint?: Endpoint;
|
|
93
|
+
branded?: true;
|
|
94
|
+
};
|
|
95
|
+
type In<t> = distill<t, {
|
|
96
|
+
endpoint: "in";
|
|
97
|
+
}>;
|
|
98
|
+
type Out<t> = distill<t, {
|
|
99
|
+
endpoint: "out";
|
|
100
|
+
}>;
|
|
101
|
+
namespace brandable {
|
|
102
|
+
type In<t> = distill<t, {
|
|
103
|
+
endpoint: "in";
|
|
104
|
+
branded: true;
|
|
105
|
+
}>;
|
|
106
|
+
type Out<t> = distill<t, {
|
|
107
|
+
endpoint: "out";
|
|
108
|
+
branded: true;
|
|
109
|
+
}>;
|
|
110
|
+
namespace introspectable {
|
|
111
|
+
type Out<t> = distill<t, {
|
|
112
|
+
endpoint: "out.introspectable";
|
|
113
|
+
branded: true;
|
|
114
|
+
}>;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
type unbranded<t> = distill<t>;
|
|
118
|
+
namespace introspectable {
|
|
119
|
+
type Out<t> = distill<t, {
|
|
120
|
+
endpoint: "out.introspectable";
|
|
121
|
+
}>;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
146
124
|
type finalizeDistillation<t, distilled> = equals<t, distilled> extends true ? t : distilled;
|
|
147
125
|
export type includesMorphs<t> = [
|
|
148
|
-
_distill<t,
|
|
149
|
-
|
|
126
|
+
_distill<t, {
|
|
127
|
+
endpoint: "in";
|
|
128
|
+
branded: true;
|
|
129
|
+
}>,
|
|
130
|
+
_distill<t, {
|
|
131
|
+
endpoint: "out";
|
|
132
|
+
branded: true;
|
|
133
|
+
}>
|
|
150
134
|
] extends ([
|
|
151
|
-
_distill<t,
|
|
152
|
-
|
|
135
|
+
_distill<t, {
|
|
136
|
+
endpoint: "out";
|
|
137
|
+
branded: true;
|
|
138
|
+
}>,
|
|
139
|
+
_distill<t, {
|
|
140
|
+
endpoint: "in";
|
|
141
|
+
branded: true;
|
|
142
|
+
}>
|
|
153
143
|
]) ? false : true;
|
|
154
|
-
type
|
|
155
|
-
type DistilledKind = "base" | "constrainable";
|
|
156
|
-
type _distill<t, io extends IoKind, distilledKind extends DistilledKind> = t extends undefined ? t : [t] extends [anyOrNever] ? t : parseConstraints<t> extends ([
|
|
144
|
+
type _distill<t, opts extends distill.Options> = t extends undefined ? t : [t] extends [anyOrNever] ? t : parseConstraints<t> extends ([
|
|
157
145
|
infer base,
|
|
158
146
|
infer constraints extends Constraints
|
|
159
|
-
]) ?
|
|
147
|
+
]) ? opts["branded"] extends true ? constrain<_distill<base, opts>, constraints> : _distill<base, opts> : t extends TerminallyInferredObjectKind | Primitive ? t : unknown extends t ? unknown : t extends MorphAst<infer i, infer o> ? opts["endpoint"] extends "in" ? _distill<i, opts> : opts["endpoint"] extends "out.introspectable" ? o extends To<infer validatedOut> ? _distill<validatedOut, opts> : unknown : opts["endpoint"] extends "out" ? _distill<o[1], opts> : _distill<o[1], opts> extends infer r ? o extends To ? (In: i) => To<r> : (In: i) => Out<r> : never : t extends DefaultedAst<infer t> ? _distill<t, opts> : t extends array ? distillArray<t, opts, []> : t extends Function ? t : {
|
|
160
148
|
[k in keyof t]: t[k];
|
|
161
|
-
} extends t ?
|
|
162
|
-
[k in keyof t as k extends
|
|
149
|
+
} extends t ? opts["endpoint"] extends "in" ? show<{
|
|
150
|
+
[k in keyof t as k extends optionalInputKeyOf<t> ? never : k]: _distill<t[k], opts>;
|
|
163
151
|
} & {
|
|
164
|
-
[k in
|
|
165
|
-
}> : {
|
|
166
|
-
[k in keyof t]: _distill<t[k],
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
type
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
]
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
]
|
|
180
|
-
|
|
152
|
+
[k in optionalInputKeyOf<t>]?: _distill<t[k], opts>;
|
|
153
|
+
}> : show<{
|
|
154
|
+
[k in keyof t as k extends metaOptionalKeyOf<t> ? never : k]: _distill<t[k], opts>;
|
|
155
|
+
} & {
|
|
156
|
+
[k in keyof t as k extends metaOptionalKeyOf<t> ? k : never]?: _distill<t[k], opts>;
|
|
157
|
+
}> : t;
|
|
158
|
+
type optionalInputKeyOf<o> = metaDefaultedKeyOf<o> | metaOptionalKeyOf<o>;
|
|
159
|
+
type metaDefaultedKeyOf<o> = {
|
|
160
|
+
[k in keyof o]: [o[k]] extends [anyOrNever] ? never : o[k] extends DefaultedAst ? k : never;
|
|
161
|
+
}[keyof o];
|
|
162
|
+
type metaOptionalKeyOf<o> = {
|
|
163
|
+
[k in keyof o]: [o[k]] extends [anyOrNever] ? never : o[k] extends OptionalAst ? k : never;
|
|
164
|
+
}[keyof o];
|
|
165
|
+
type distillArray<t extends array, opts extends distill.Options, prefix extends array> = _distillArray<t, opts, prefix> extends infer result ? (t extends unknown[] ? result : Readonly<t>) & // re-intersect non-array props for a type like `{ name: string } & string[]`
|
|
166
|
+
_distill<{
|
|
167
|
+
[k in keyof t as k extends keyof unknown[] ? never : k]: t[k];
|
|
168
|
+
}, opts> : never;
|
|
169
|
+
type _distillArray<t extends array, opts extends distill.Options, prefix extends array> = t extends readonly [infer head, ...infer tail] ? _distillArray<tail, opts, [...prefix, _distill<head, opts>]> : [...prefix, ...distillPostfix<t, opts>];
|
|
170
|
+
type distillPostfix<t extends array, opts extends distill.Options, postfix extends array = []> = t extends readonly [...infer init, infer last] ? distillPostfix<init, opts, [_distill<last, opts>, ...postfix]> : [...{
|
|
171
|
+
[i in keyof t]: _distill<t[i], opts>;
|
|
181
172
|
}, ...postfix];
|
|
182
173
|
/** Objects we don't want to expand during inference like Date or Promise */
|
|
183
174
|
type TerminallyInferredObjectKind = arkPrototypes.instanceOfExcluding<"Array" | "Function"> | ArkEnv.prototypes;
|
|
184
|
-
export type inferPredicate<t, predicate> = predicate extends (data: any, ...args: any[]) => data is infer narrowed ? t extends constrain<unknown, infer constraints> ?
|
|
185
|
-
export type constrainWithPredicate<t> = t extends constrain<unknown, infer constraints> ?
|
|
186
|
-
export type inferPipes<t, pipes extends Morph[]> = pipes extends [infer head extends Morph, ...infer tail extends Morph[]] ? inferPipes<pipes[0] extends type.cast<infer tPipe> ? inferPipe<t, tPipe> : inferMorphOut<head> extends infer out ? (In:
|
|
175
|
+
export type inferPredicate<t, predicate> = predicate extends (data: any, ...args: any[]) => data is infer narrowed ? t extends constrain<unknown, infer constraints> ? applyConstraintSchema<constrain<narrowed, constraints>, "predicate", any> : applyConstraintSchema<narrowed, "predicate", any> : applyConstraintSchema<t, "predicate", any>;
|
|
176
|
+
export type constrainWithPredicate<t> = t extends constrain<unknown, infer constraints> ? applyConstraintSchema<constrain<t, constraints>, "predicate", any> : applyConstraintSchema<t, "predicate", any>;
|
|
177
|
+
export type inferPipes<t, pipes extends Morph[]> = pipes extends [infer head extends Morph, ...infer tail extends Morph[]] ? inferPipes<pipes[0] extends type.cast<infer tPipe> ? inferPipe<t, tPipe> : inferMorphOut<head> extends infer out ? (In: distill.brandable.In<t>) => Out<out> : never, tail> : t;
|
|
187
178
|
export type inferMorphOut<morph extends Morph> = Exclude<ReturnType<morph>, ArkError | ArkErrors>;
|
|
188
179
|
export type Out<o = any> = ["=>", o, boolean];
|
|
189
180
|
export type To<o = any> = ["=>", o, true];
|
|
190
181
|
export type MorphAst<i = any, o extends Out = Out> = (In: i) => o;
|
|
182
|
+
export type Optional = {
|
|
183
|
+
optional?: {};
|
|
184
|
+
};
|
|
185
|
+
export type OptionalAst<t = unknown> = constrain<t, Optional>;
|
|
191
186
|
export type Default<v = any> = ["=", v];
|
|
192
|
-
export type
|
|
187
|
+
export type DefaultedAst<t = any, v = any> = (In?: t) => Default<v>;
|
|
193
188
|
export type termOrType<t> = t | Type<t, any>;
|
package/out/keywords/builtins.js
CHANGED
|
@@ -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 arkBuiltins =
|
|
7
|
+
export const arkBuiltins = arkModule({
|
|
8
8
|
Key: intrinsic.key,
|
|
9
9
|
Merge
|
|
10
10
|
});
|
|
@@ -10,7 +10,7 @@ export declare namespace arkArray {
|
|
|
10
10
|
type module = Module<submodule>;
|
|
11
11
|
type submodule = Submodule<$>;
|
|
12
12
|
type $ = {
|
|
13
|
-
|
|
13
|
+
root: unknown[];
|
|
14
14
|
readonly: readonly unknown[];
|
|
15
15
|
index: NonNegativeIntegerString;
|
|
16
16
|
liftFrom: typeof liftFrom.t;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { genericNode, intrinsic, rootNode } 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 => {
|
|
@@ -11,9 +11,9 @@ const liftFrom = genericNode("element")(args => {
|
|
|
11
11
|
.pipe(liftArray)
|
|
12
12
|
.distribute(branch => branch.assertHasKind("morph").declareOut(lifted), rootNode);
|
|
13
13
|
}, liftFromHkt);
|
|
14
|
-
export const arkArray =
|
|
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,31 @@
|
|
|
1
|
+
import type { Branded, constrain, constraint, Constraints, Literal, Narrowed, normalizeLimit, Optional } from "../ast.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 branded<rule> = constrain<Date, Branded<rule>>;
|
|
22
|
+
type literal<rule> = constrain<Date, Literal<rule>>;
|
|
23
|
+
type is<constraints extends Constraints> = constrain<Date, constraints>;
|
|
24
|
+
type afterSchemaToConstraint<schema, rule> = schema extends {
|
|
25
|
+
exclusive: true;
|
|
26
|
+
} ? After<normalizeLimit<rule>> : AtOrAfter<normalizeLimit<rule>>;
|
|
27
|
+
type beforeSchemaToConstraint<schema, rule> = schema extends {
|
|
28
|
+
exclusive: true;
|
|
29
|
+
} ? Before<normalizeLimit<rule>> : AtOrBefore<normalizeLimit<rule>>;
|
|
30
|
+
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 Narrowed ? narrowed : never;
|
|
31
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { rootNode } from "@ark/schema";
|
|
2
2
|
import { registry } from "@ark/util";
|
|
3
|
-
import {
|
|
3
|
+
import { arkModule } from "../utils.js";
|
|
4
4
|
const value = rootNode(["string", registry.FileConstructor]);
|
|
5
5
|
const parsedFormDataValue = value.or(value.array());
|
|
6
6
|
const parsed = rootNode({
|
|
@@ -11,8 +11,8 @@ const parsed = rootNode({
|
|
|
11
11
|
value: parsedFormDataValue
|
|
12
12
|
}
|
|
13
13
|
});
|
|
14
|
-
export const arkFormData =
|
|
15
|
-
|
|
14
|
+
export const arkFormData = arkModule({
|
|
15
|
+
root: ["instanceof", FormData],
|
|
16
16
|
value,
|
|
17
17
|
parsed,
|
|
18
18
|
parse: rootNode({
|