arktype 2.0.0-rc.1 → 2.0.0-rc.11
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 +47 -48
- package/out/generic.js +6 -8
- package/out/index.d.ts +4 -4
- package/out/index.js +2 -2
- package/out/keywords/builtins.js +2 -2
- package/out/keywords/constructors/Array.d.ts +2 -2
- package/out/keywords/constructors/Array.js +7 -7
- package/out/keywords/constructors/Date.d.ts +32 -0
- package/out/keywords/constructors/FormData.d.ts +2 -2
- package/out/keywords/constructors/FormData.js +8 -8
- package/out/keywords/constructors/TypedArray.js +2 -2
- package/out/keywords/constructors/constructors.d.ts +0 -1
- package/out/keywords/constructors/constructors.js +2 -2
- package/out/keywords/inference.d.ts +228 -0
- package/out/keywords/keywords.d.ts +62 -0
- package/out/keywords/{ark.js → keywords.js} +11 -8
- 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 +32 -6
- 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 +2 -2
- 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 +4 -8
- 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 +2 -2
- package/out/keywords/string/integer.js +7 -7
- package/out/keywords/string/ip.d.ts +2 -2
- package/out/keywords/string/ip.js +5 -5
- package/out/keywords/string/json.d.ts +3 -2
- package/out/keywords/string/json.js +24 -16
- package/out/keywords/string/lower.d.ts +2 -2
- package/out/keywords/string/lower.js +4 -4
- package/out/keywords/string/normalize.d.ts +23 -27
- package/out/keywords/string/normalize.js +14 -14
- package/out/keywords/string/numeric.d.ts +2 -2
- package/out/keywords/string/numeric.js +7 -7
- package/out/keywords/string/semver.d.ts +1 -1
- package/out/keywords/string/string.d.ts +39 -42
- package/out/keywords/string/string.js +3 -3
- package/out/keywords/string/trim.d.ts +2 -2
- package/out/keywords/string/trim.js +4 -4
- package/out/keywords/string/upper.d.ts +2 -2
- package/out/keywords/string/upper.js +4 -4
- package/out/keywords/string/url.d.ts +2 -2
- package/out/keywords/string/url.js +8 -8
- package/out/keywords/string/uuid.d.ts +11 -11
- package/out/keywords/string/uuid.js +3 -3
- package/out/keywords/ts.d.ts +38 -1
- package/out/keywords/ts.js +20 -4
- 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 +3 -3
- package/out/parser/ast/default.d.ts +8 -0
- package/out/parser/{semantic → ast}/infer.d.ts +11 -11
- package/out/parser/{semantic → ast}/utils.d.ts +1 -1
- package/out/parser/{semantic → ast}/validate.d.ts +6 -6
- package/out/parser/definition.d.ts +8 -9
- package/out/parser/objectLiteral.d.ts +11 -37
- 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 +3 -2
- package/out/parser/{string/shift → shift}/operand/enclosed.js +7 -3
- package/out/parser/{string/shift → shift}/operand/unenclosed.d.ts +3 -3
- package/out/parser/{string/shift → shift}/operand/unenclosed.js +7 -3
- package/out/parser/{string/shift → shift}/operator/bounds.d.ts +3 -3
- 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}/scanner.d.ts +3 -1
- package/out/parser/{string/shift → shift}/scanner.js +5 -3
- package/out/parser/{string/string.d.ts → string.d.ts} +6 -7
- 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 +32 -39
- package/out/scope.js +43 -35
- package/out/type.d.ts +24 -21
- package/out/type.js +14 -10
- 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 -39
- package/out/keywords/ast.d.ts +0 -193
- package/out/parser/semantic/default.d.ts +0 -9
- package/out/parser/semantic/default.js +0 -1
- package/out/subtypes/base.d.ts +0 -85
- 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/parser/{string/shift → shift}/operator/operator.js +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { rootSchema } from "@ark/schema";
|
|
2
|
+
import { arkModule } from "../utils.js";
|
|
3
3
|
const isParsableUrl = (s) => {
|
|
4
4
|
if (URL.canParse)
|
|
5
5
|
return URL.canParse(s);
|
|
@@ -12,17 +12,17 @@ const isParsableUrl = (s) => {
|
|
|
12
12
|
return false;
|
|
13
13
|
}
|
|
14
14
|
};
|
|
15
|
-
const
|
|
15
|
+
const root = rootSchema({
|
|
16
16
|
domain: "string",
|
|
17
17
|
predicate: {
|
|
18
18
|
meta: "a URL string",
|
|
19
19
|
predicate: isParsableUrl
|
|
20
20
|
}
|
|
21
21
|
});
|
|
22
|
-
export const url =
|
|
23
|
-
|
|
24
|
-
parse:
|
|
25
|
-
declaredIn:
|
|
22
|
+
export const url = arkModule({
|
|
23
|
+
root,
|
|
24
|
+
parse: rootSchema({
|
|
25
|
+
declaredIn: root,
|
|
26
26
|
in: "string",
|
|
27
27
|
morphs: (s, ctx) => {
|
|
28
28
|
try {
|
|
@@ -32,6 +32,6 @@ export const url = submodule({
|
|
|
32
32
|
return ctx.error("a URL string");
|
|
33
33
|
}
|
|
34
34
|
},
|
|
35
|
-
declaredOut:
|
|
35
|
+
declaredOut: rootSchema(URL)
|
|
36
36
|
})
|
|
37
37
|
});
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type { Branded, constrain } from "../
|
|
2
|
+
import type { Branded, constrain } from "../inference.ts";
|
|
3
3
|
export declare const uuid: Module<{
|
|
4
|
-
|
|
5
|
-
v4:
|
|
6
|
-
v6:
|
|
7
|
-
v1:
|
|
8
|
-
v2:
|
|
9
|
-
v3:
|
|
10
|
-
v5:
|
|
11
|
-
v7:
|
|
12
|
-
v8:
|
|
4
|
+
root: import("./string.ts").string.matching<string> | "00000000-0000-0000-0000-000000000000" | "ffffffff-ffff-ffff-ffff-ffffffffffff";
|
|
5
|
+
v4: unknown;
|
|
6
|
+
v6: unknown;
|
|
7
|
+
v1: unknown;
|
|
8
|
+
v2: unknown;
|
|
9
|
+
v3: unknown;
|
|
10
|
+
v5: unknown;
|
|
11
|
+
v7: unknown;
|
|
12
|
+
v8: unknown;
|
|
13
13
|
}>;
|
|
14
14
|
declare namespace string {
|
|
15
15
|
type uuid = constrain<string, Branded<"uuid">>;
|
|
@@ -28,7 +28,7 @@ export declare namespace uuid {
|
|
|
28
28
|
type module = Module<submodule>;
|
|
29
29
|
type submodule = Submodule<$>;
|
|
30
30
|
type $ = {
|
|
31
|
-
|
|
31
|
+
root: string.uuid;
|
|
32
32
|
v1: string.uuid.v1;
|
|
33
33
|
v2: string.uuid.v2;
|
|
34
34
|
v3: string.uuid.v3;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { arkModule } from "../utils.js";
|
|
2
2
|
import { regexStringNode } from "./utils.js";
|
|
3
3
|
// Based on https://github.com/validatorjs/validator.js/blob/master/src/lib/isUUID.js
|
|
4
|
-
export const uuid =
|
|
4
|
+
export const uuid = arkModule({
|
|
5
5
|
// the meta tuple expression ensures the error message does not delegate
|
|
6
6
|
// to the individual branches, which are too detailed
|
|
7
|
-
|
|
7
|
+
root: ["versioned | nil | max", "@", "a UUID"],
|
|
8
8
|
"#nil": "'00000000-0000-0000-0000-000000000000'",
|
|
9
9
|
"#max": "'ffffffff-ffff-ffff-ffff-ffffffffffff'",
|
|
10
10
|
"#versioned": /[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/i,
|
package/out/keywords/ts.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { Hkt, type Key, type omit, type pick, type show } from "@ark/util";
|
|
1
|
+
import { Hkt, type Json, type Key, type omit, type pick, type show } from "@ark/util";
|
|
2
2
|
import type { Module, Submodule } from "../module.ts";
|
|
3
|
+
import type { To } from "./inference.ts";
|
|
3
4
|
export declare const arkTsKeywords: arkTsKeywords;
|
|
4
5
|
export type arkTsKeywords = Module<arkTsKeywords.$>;
|
|
5
6
|
export declare namespace arkTsKeywords {
|
|
@@ -19,6 +20,42 @@ export declare namespace arkTsKeywords {
|
|
|
19
20
|
undefined: undefined;
|
|
20
21
|
};
|
|
21
22
|
}
|
|
23
|
+
export declare const unknown: Module<{
|
|
24
|
+
root: unknown;
|
|
25
|
+
any: unknown;
|
|
26
|
+
}>;
|
|
27
|
+
export declare namespace unknown {
|
|
28
|
+
type submodule = Submodule<$>;
|
|
29
|
+
type $ = {
|
|
30
|
+
root: unknown;
|
|
31
|
+
any: any;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export declare const json: Module<{
|
|
35
|
+
root: unknown;
|
|
36
|
+
stringify: unknown;
|
|
37
|
+
}>;
|
|
38
|
+
export declare namespace json {
|
|
39
|
+
type submodule = Submodule<$>;
|
|
40
|
+
type $ = {
|
|
41
|
+
root: Json;
|
|
42
|
+
stringify: (In: Json) => To<string>;
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export declare const object: Module<{
|
|
46
|
+
root: unknown;
|
|
47
|
+
json: Submodule<{
|
|
48
|
+
root: unknown;
|
|
49
|
+
stringify: unknown;
|
|
50
|
+
}>;
|
|
51
|
+
}>;
|
|
52
|
+
export declare namespace object {
|
|
53
|
+
type submodule = Submodule<$>;
|
|
54
|
+
type $ = {
|
|
55
|
+
root: object;
|
|
56
|
+
json: json.submodule;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
22
59
|
declare class RecordHkt extends Hkt<[Key, unknown]> {
|
|
23
60
|
body: Record<this[0], this[1]>;
|
|
24
61
|
}
|
package/out/keywords/ts.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { genericNode, intrinsic } from "@ark/schema";
|
|
1
|
+
import { genericNode, intrinsic, node } from "@ark/schema";
|
|
2
2
|
import { Hkt } from "@ark/util";
|
|
3
|
-
import {
|
|
4
|
-
export const arkTsKeywords =
|
|
3
|
+
import { arkModule } from "./utils.js";
|
|
4
|
+
export const arkTsKeywords = arkModule({
|
|
5
5
|
bigint: intrinsic.bigint,
|
|
6
6
|
boolean: intrinsic.boolean,
|
|
7
7
|
false: intrinsic.false,
|
|
@@ -15,6 +15,22 @@ export const arkTsKeywords = submodule({
|
|
|
15
15
|
unknown: intrinsic.unknown,
|
|
16
16
|
undefined: intrinsic.undefined
|
|
17
17
|
});
|
|
18
|
+
export const unknown = arkModule({
|
|
19
|
+
root: intrinsic.unknown,
|
|
20
|
+
any: intrinsic.unknown
|
|
21
|
+
});
|
|
22
|
+
export const json = arkModule({
|
|
23
|
+
root: intrinsic.json,
|
|
24
|
+
stringify: node("morph", {
|
|
25
|
+
in: intrinsic.json,
|
|
26
|
+
morphs: (data) => JSON.stringify(data),
|
|
27
|
+
declaredOut: intrinsic.string
|
|
28
|
+
})
|
|
29
|
+
});
|
|
30
|
+
export const object = arkModule({
|
|
31
|
+
root: intrinsic.object,
|
|
32
|
+
json
|
|
33
|
+
});
|
|
18
34
|
class RecordHkt extends Hkt {
|
|
19
35
|
}
|
|
20
36
|
const Record = genericNode(["K", intrinsic.key], "V")(args => ({
|
|
@@ -42,7 +58,7 @@ const Exclude = genericNode("T", "U")(args => args.T.exclude(args.U), ExcludeHkt
|
|
|
42
58
|
class ExtractHkt extends Hkt {
|
|
43
59
|
}
|
|
44
60
|
const Extract = genericNode("T", "U")(args => args.T.extract(args.U), ExtractHkt);
|
|
45
|
-
export const arkTsGenerics =
|
|
61
|
+
export const arkTsGenerics = arkModule({
|
|
46
62
|
Record,
|
|
47
63
|
Pick,
|
|
48
64
|
Omit,
|
package/out/keywords/utils.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const arkModule: import("../scope.ts").ModuleParser;
|
package/out/keywords/utils.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { module } from "../scope.js";
|
|
2
|
-
export const
|
|
2
|
+
export const arkModule = module;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { ExactLength, ExclusiveNumericRangeSchema, exclusivizeRangeSchema, InclusiveNumericRangeSchema } from "@ark/schema";
|
|
2
|
-
import type {
|
|
2
|
+
import type { applyConstraintSchema } from "../keywords/inference.ts";
|
|
3
3
|
import type { ObjectType } from "./object.ts";
|
|
4
4
|
interface Type<
|
|
5
5
|
/** @ts-ignore cast variance */
|
|
6
6
|
out t extends readonly unknown[] = readonly unknown[], $ = {}> extends ObjectType<t, $> {
|
|
7
|
-
atLeastLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<
|
|
8
|
-
atMostLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<
|
|
9
|
-
moreThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<
|
|
10
|
-
lessThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<
|
|
11
|
-
exactlyLength<const schema extends ExactLength.Schema>(schema: schema): Type<
|
|
7
|
+
atLeastLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<applyConstraintSchema<t, "minLength", schema>, $>;
|
|
8
|
+
atMostLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<applyConstraintSchema<t, "maxLength", schema>, $>;
|
|
9
|
+
moreThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<applyConstraintSchema<t, "minLength", exclusivizeRangeSchema<schema>>, $>;
|
|
10
|
+
lessThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<applyConstraintSchema<t, "maxLength", exclusivizeRangeSchema<schema>>, $>;
|
|
11
|
+
exactlyLength<const schema extends ExactLength.Schema>(schema: schema): Type<applyConstraintSchema<t, "exactLength", schema>, $>;
|
|
12
12
|
}
|
|
13
13
|
export type { Type as ArrayType };
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { ArkErrors, BaseRoot, Disjoint, JsonSchema, MetaSchema, Morph, UndeclaredKeyBehavior } from "@ark/schema";
|
|
2
|
+
import type { anyOrNever, array, Callable, ErrorMessage, inferred, Json, unset } from "@ark/util";
|
|
3
|
+
import type { ArkAmbient } from "../config.ts";
|
|
4
|
+
import type { applyConstraint, Default, distill, inferIntersection, inferMorphOut, inferPipes, InferredMorph, Optional, To } from "../keywords/inference.ts";
|
|
5
|
+
import type { type } from "../keywords/keywords.ts";
|
|
6
|
+
import type { Scope } from "../scope.ts";
|
|
7
|
+
import type { ArrayType } from "./array.ts";
|
|
8
|
+
import type { instantiateType } from "./instantiate.ts";
|
|
9
|
+
/** @ts-ignore cast variance */
|
|
10
|
+
interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => distill.Out<t> | ArkErrors> {
|
|
11
|
+
t: t;
|
|
12
|
+
infer: this["inferOut"];
|
|
13
|
+
inferBrandableIn: distill.brandable.In<t>;
|
|
14
|
+
inferBrandableOut: distill.brandable.Out<t>;
|
|
15
|
+
inferIntrospectableOut: distill.introspectable.Out<t>;
|
|
16
|
+
inferOut: distill.Out<t>;
|
|
17
|
+
inferIn: distill.In<t>;
|
|
18
|
+
inferredOutIsIntrospectable: t extends InferredMorph<any, infer o> ? [
|
|
19
|
+
o
|
|
20
|
+
] extends [anyOrNever] ? true : o extends To ? true : false : true;
|
|
21
|
+
[inferred]: t;
|
|
22
|
+
json: Json;
|
|
23
|
+
toJSON(): Json;
|
|
24
|
+
meta: ArkAmbient.meta;
|
|
25
|
+
precompilation: string | undefined;
|
|
26
|
+
toJsonSchema(): JsonSchema;
|
|
27
|
+
description: string;
|
|
28
|
+
expression: string;
|
|
29
|
+
internal: BaseRoot;
|
|
30
|
+
$: Scope<$>;
|
|
31
|
+
assert(data: unknown): this["infer"];
|
|
32
|
+
allows(data: unknown): data is this["inferIn"];
|
|
33
|
+
traverse(data: unknown): this["infer"] | ArkErrors;
|
|
34
|
+
configure(meta: MetaSchema): this;
|
|
35
|
+
describe(description: string): this;
|
|
36
|
+
onUndeclaredKey(behavior: UndeclaredKeyBehavior): this;
|
|
37
|
+
onDeepUndeclaredKey(behavior: UndeclaredKeyBehavior): this;
|
|
38
|
+
from(literal: this["inferIn"]): this["infer"];
|
|
39
|
+
as<t = unset>(...args: validateChainedAsArgs<t>): instantiateType<t, $>;
|
|
40
|
+
get in(): instantiateType<this["inferBrandableIn"], $>;
|
|
41
|
+
get out(): instantiateType<this["inferIntrospectableOut"], $>;
|
|
42
|
+
intersect<const def>(def: type.validate<def, $>): type.infer<def, $> extends infer r ? instantiateType<inferIntersection<t, r>, $> | Disjoint : never;
|
|
43
|
+
and<const def>(def: type.validate<def, $>): type.infer<def, $> extends infer r ? instantiateType<inferIntersection<t, r>, $> : never;
|
|
44
|
+
or<const def>(def: type.validate<def, $>): type.infer<def, $> extends infer r ? instantiateType<t | r, $> : never;
|
|
45
|
+
array(): ArrayType<t[], $>;
|
|
46
|
+
pipe: ChainedPipes<t, $>;
|
|
47
|
+
equals<const def>(def: type.validate<def, $>): boolean;
|
|
48
|
+
ifEquals<const def>(def: type.validate<def, $>): type.infer<def, $> extends infer r ? instantiateType<r, $> | undefined : never;
|
|
49
|
+
extends<const def>(other: type.validate<def, $>): boolean;
|
|
50
|
+
ifExtends<const def>(other: type.validate<def, $>): type.infer<def, $> extends infer r ? instantiateType<r, $> | undefined : never;
|
|
51
|
+
overlaps<const def>(r: type.validate<def, $>): boolean;
|
|
52
|
+
extract<const def>(r: type.validate<def, $>): type.infer<def, $> extends infer r ? instantiateType<Extract<t, r>, $> : never;
|
|
53
|
+
exclude<const def>(r: type.validate<def, $>): type.infer<def, $> extends infer r ? instantiateType<Exclude<t, r>, $> : never;
|
|
54
|
+
distribute<mapOut, reduceOut = mapOut[]>(mapBranch: (branch: Type, i: number, branches: array<Type>) => mapOut, reduceMapped?: (mappedBranches: mapOut[]) => reduceOut): NoInfer<reduceOut>;
|
|
55
|
+
optional<r = applyConstraint<t, Optional>>(): instantiateType<r, $>;
|
|
56
|
+
default<const value extends this["inferIn"], r = applyConstraint<t, Default<value>>>(value: value): instantiateType<r, $>;
|
|
57
|
+
/** @deprecated */
|
|
58
|
+
apply: Function["apply"];
|
|
59
|
+
/** @deprecated */
|
|
60
|
+
bind: Function["bind"];
|
|
61
|
+
/** @deprecated */
|
|
62
|
+
call: Function["call"];
|
|
63
|
+
/** @deprecated */
|
|
64
|
+
caller: Function;
|
|
65
|
+
/** @deprecated */
|
|
66
|
+
length: number;
|
|
67
|
+
/** @deprecated */
|
|
68
|
+
name: string;
|
|
69
|
+
/** @deprecated */
|
|
70
|
+
prototype: Function["prototype"];
|
|
71
|
+
/** @deprecated */
|
|
72
|
+
arguments: Function["arguments"];
|
|
73
|
+
/** @deprecated */
|
|
74
|
+
Symbol: never;
|
|
75
|
+
}
|
|
76
|
+
interface ChainedPipeSignature<t, $> {
|
|
77
|
+
<a extends Morph<distill.Out<t>>, r = instantiateType<inferPipes<t, [a]>, $>>(a: a): NoInfer<r>;
|
|
78
|
+
<a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, r = instantiateType<inferPipes<t, [a, b]>, $>>(a: a, b: b): NoInfer<r>;
|
|
79
|
+
<a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, r = instantiateType<inferPipes<t, [a, b, c]>, $>>(a: a, b: b, c: c): NoInfer<r>;
|
|
80
|
+
<a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, r = instantiateType<inferPipes<t, [a, b, c, d]>, $>>(a: a, b: b, c: c, d: d): NoInfer<r>;
|
|
81
|
+
<a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, r = instantiateType<inferPipes<t, [a, b, c, d, e]>, $>>(a: a, b: b, c: c, d: d, e: e): NoInfer<r>;
|
|
82
|
+
<a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, f extends Morph<inferMorphOut<e>>, r = instantiateType<inferPipes<t, [a, b, c, d, e, f]>, $>>(a: a, b: b, c: c, d: d, e: e, f: f): NoInfer<r>;
|
|
83
|
+
<a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, c extends Morph<inferMorphOut<b>>, d extends Morph<inferMorphOut<c>>, e extends Morph<inferMorphOut<d>>, f extends Morph<inferMorphOut<e>>, g extends Morph<inferMorphOut<f>>, r = instantiateType<inferPipes<t, [a, b, c, d, e, f, g]>, $>>(a: a, b: b, c: c, d: d, e: e, f: f, g: g): NoInfer<r>;
|
|
84
|
+
}
|
|
85
|
+
export interface ChainedPipes<t, $> extends ChainedPipeSignature<t, $> {
|
|
86
|
+
try: ChainedPipeSignature<t, $>;
|
|
87
|
+
}
|
|
88
|
+
type validateChainedAsArgs<t> = [
|
|
89
|
+
t
|
|
90
|
+
] extends [unset] ? [
|
|
91
|
+
t
|
|
92
|
+
] extends [anyOrNever] ? [
|
|
93
|
+
] : [
|
|
94
|
+
ErrorMessage<"as requires an explicit type parameter like myType.as<t>()">
|
|
95
|
+
] : [];
|
|
96
|
+
export type { Type as BaseType };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { ExclusiveDateRangeSchema, exclusivizeRangeSchema, InclusiveDateRangeSchema } from "@ark/schema";
|
|
2
|
-
import type {
|
|
2
|
+
import type { applyConstraintSchema } from "../keywords/inference.ts";
|
|
3
3
|
import type { ObjectType } from "./object.ts";
|
|
4
4
|
/** @ts-ignore cast variance */
|
|
5
5
|
interface Type<out t extends globalThis.Date = globalThis.Date, $ = {}> extends ObjectType<t, $> {
|
|
6
|
-
atOrAfter<const schema extends InclusiveDateRangeSchema>(schema: schema): Type<
|
|
7
|
-
atOrBefore<const schema extends InclusiveDateRangeSchema>(schema: schema): Type<
|
|
8
|
-
laterThan<const schema extends ExclusiveDateRangeSchema>(schema: schema): Type<
|
|
9
|
-
earlierThan<const schema extends ExclusiveDateRangeSchema>(schema: schema): Type<
|
|
6
|
+
atOrAfter<const schema extends InclusiveDateRangeSchema>(schema: schema): Type<applyConstraintSchema<t, "after", schema>, $>;
|
|
7
|
+
atOrBefore<const schema extends InclusiveDateRangeSchema>(schema: schema): Type<applyConstraintSchema<t, "before", schema>, $>;
|
|
8
|
+
laterThan<const schema extends ExclusiveDateRangeSchema>(schema: schema): Type<applyConstraintSchema<t, "after", exclusivizeRangeSchema<schema>>, $>;
|
|
9
|
+
earlierThan<const schema extends ExclusiveDateRangeSchema>(schema: schema): Type<applyConstraintSchema<t, "before", exclusivizeRangeSchema<schema>>, $>;
|
|
10
10
|
}
|
|
11
11
|
export type { Type as DateType };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { anyOrNever, array } from "@ark/util";
|
|
2
|
-
import type {
|
|
2
|
+
import type { InferredMorph } from "../keywords/inference.ts";
|
|
3
3
|
import type { ArrayType } from "./array.ts";
|
|
4
|
+
import type { BaseType } from "./base.ts";
|
|
4
5
|
import type { DateType } from "./date.ts";
|
|
5
6
|
import type { MorphType } from "./morph.ts";
|
|
6
7
|
import type { NumberType } from "./number.ts";
|
|
@@ -8,9 +9,9 @@ import type { ObjectType } from "./object.ts";
|
|
|
8
9
|
import type { StringType } from "./string.ts";
|
|
9
10
|
import type { ValidatorType } from "./validator.ts";
|
|
10
11
|
export type instantiateType<t, $> = [
|
|
11
|
-
Extract<t,
|
|
12
|
+
Extract<t, InferredMorph>
|
|
12
13
|
] extends [anyOrNever] ? [
|
|
13
14
|
t
|
|
14
|
-
] extends [string] ? StringType<t, $> : [t] extends [number] ? NumberType<t, $> : [t] extends [object] ? [
|
|
15
|
+
] extends [anyOrNever] ? BaseType<t, $> : [t] extends [string] ? StringType<t, $> : [t] extends [number] ? NumberType<t, $> : [t] extends [object] ? [
|
|
15
16
|
t
|
|
16
|
-
] extends [array] ? ArrayType<t, $> : [t] extends [Date] ? DateType<t, $> : ObjectType<t, $> : ValidatorType<t, $> : MorphType<t, $>;
|
|
17
|
+
] extends [array] ? ArrayType<t, $> : [t] extends [Date] ? DateType<t, $> : ObjectType<t, $> : unknown extends t ? BaseType<unknown, $> : ValidatorType<t, $> : MorphType<t, $>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Predicate, PredicateCast } from "@ark/schema";
|
|
2
|
+
import type { applyConstraintSchema, inferPipe, Out, To } from "../keywords/inference.ts";
|
|
3
|
+
import type { type } from "../keywords/keywords.ts";
|
|
4
|
+
import type { BaseType } from "./base.ts";
|
|
5
|
+
/** @ts-ignore cast variance */
|
|
6
|
+
interface Type<out t = unknown, $ = {}> extends BaseType<t, $> {
|
|
7
|
+
to<const def, r = type.infer<def, $>>(def: type.validate<def, $>): Type<inferPipe<t, NoInfer<r>>, $>;
|
|
8
|
+
narrow<narrowed extends this["infer"] = never>(predicate: Predicate<this["infer"]> | PredicateCast<this["infer"], narrowed>): Type<([
|
|
9
|
+
narrowed
|
|
10
|
+
] extends [never] ? applyConstraintSchema<this["inferBrandableOut"], "predicate", Predicate> : narrowed) extends infer o ? this["inferredOutIsIntrospectable"] extends true ? (In: this["inferBrandableIn"]) => To<o> : (In: this["inferBrandableIn"]) => Out<o> : never, $>;
|
|
11
|
+
}
|
|
12
|
+
export type { Type as MorphType };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { Divisor, ExclusiveNumericRangeSchema, exclusivizeRangeSchema, InclusiveNumericRangeSchema } from "@ark/schema";
|
|
2
|
-
import type {
|
|
2
|
+
import type { applyConstraintSchema } from "../keywords/inference.ts";
|
|
3
3
|
import type { ValidatorType } from "./validator.ts";
|
|
4
4
|
/** @ts-ignore cast variance */
|
|
5
5
|
interface Type<out t extends number = number, $ = {}> extends ValidatorType<t, $> {
|
|
6
|
-
divisibleBy<const schema extends Divisor.Schema>(schema: schema): Type<
|
|
7
|
-
atLeast<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<
|
|
8
|
-
atMost<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<
|
|
9
|
-
moreThan<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<
|
|
10
|
-
lessThan<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<
|
|
6
|
+
divisibleBy<const schema extends Divisor.Schema>(schema: schema): Type<applyConstraintSchema<t, "divisor", schema>, $>;
|
|
7
|
+
atLeast<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<applyConstraintSchema<t, "min", schema>, $>;
|
|
8
|
+
atMost<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<applyConstraintSchema<t, "max", schema>, $>;
|
|
9
|
+
moreThan<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<applyConstraintSchema<t, "min", exclusivizeRangeSchema<schema>>, $>;
|
|
10
|
+
lessThan<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<applyConstraintSchema<t, "max", exclusivizeRangeSchema<schema>>, $>;
|
|
11
11
|
}
|
|
12
12
|
export type { Type as NumberType };
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import type { BaseMappedPropInner, OptionalMappedPropInner, Prop } from "@ark/schema";
|
|
2
|
+
import type { arkGet, arkIndexableOf, arkKeyOf, array, ErrorType, inferred, intersectUnion, Json, Key, listable, merge, optionalKeyOf, show, toArkKey } from "@ark/util";
|
|
3
|
+
import type { applyConstraint, constrain, Default, Optional, parseConstraints } from "../keywords/inference.ts";
|
|
4
|
+
import type { type } from "../keywords/keywords.ts";
|
|
5
|
+
import type { ArrayType } from "./array.ts";
|
|
6
|
+
import type { instantiateType } from "./instantiate.ts";
|
|
7
|
+
import type { ValidatorType } from "./validator.ts";
|
|
8
|
+
/** @ts-ignore cast variance */
|
|
9
|
+
interface Type<out t extends object = object, $ = {}> extends ValidatorType<t, $> {
|
|
10
|
+
readonly(): t extends array ? ArrayType<{
|
|
11
|
+
readonly [i in keyof t]: t[i];
|
|
12
|
+
}, $> : Type<{
|
|
13
|
+
readonly [k in keyof t]: t[k];
|
|
14
|
+
}, $>;
|
|
15
|
+
keyof(): instantiateType<arkKeyOf<t>, $>;
|
|
16
|
+
get<const k1 extends arkIndexableOf<t>>(k1: k1 | type.cast<k1>): instantiateType<arkGet<t, k1>, $> extends infer r ? r : never;
|
|
17
|
+
get<const k1 extends arkIndexableOf<t>, const k2 extends arkIndexableOf<arkGet<t, k1>>>(k1: k1 | type.cast<k1>, k2: k2 | type.cast<k2>): instantiateType<arkGet<arkGet<t, k1>, k2>, $> extends infer r ? r : never;
|
|
18
|
+
get<const k1 extends arkIndexableOf<t>, const k2 extends arkIndexableOf<arkGet<t, k1>>, const k3 extends arkIndexableOf<arkGet<arkGet<t, k1>, k2>>>(k1: k1 | type.cast<k1>, k2: k2 | type.cast<k2>, k3: k3 | type.cast<k3>): instantiateType<arkGet<arkGet<arkGet<t, k1>, k2>, k3>, $> extends infer r ? r : never;
|
|
19
|
+
pick<const key extends arkKeyOf<t> = never>(...keys: (key | type.cast<key>)[]): Type<{
|
|
20
|
+
[k in keyof t as Extract<toArkKey<t, k>, key>]: t[k];
|
|
21
|
+
}, $>;
|
|
22
|
+
omit<const key extends arkKeyOf<t> = never>(...keys: (key | type.cast<key>)[]): Type<{
|
|
23
|
+
[k in keyof t as Exclude<toArkKey<t, k>, key>]: t[k];
|
|
24
|
+
}, $>;
|
|
25
|
+
merge<const def, r = type.infer<def, $>>(def: type.validate<def, $> & (r extends object ? unknown : ErrorType<"Merged type must be an object", [actual: r]>)): Type<merge<t, NoInfer<r & object>>, $>;
|
|
26
|
+
required(): Type<{
|
|
27
|
+
[k in keyof t]-?: t[k];
|
|
28
|
+
}, $>;
|
|
29
|
+
partial(): Type<{
|
|
30
|
+
[k in keyof t]?: t[k];
|
|
31
|
+
}, $>;
|
|
32
|
+
map<transformed extends listable<MappedTypeProp>>(flatMapEntry: (entry: typePropOf<t, $>) => transformed): Type<constructMapped<t, transformed>, $>;
|
|
33
|
+
props: array<typePropOf<t, $>>;
|
|
34
|
+
}
|
|
35
|
+
type typePropOf<o, $> = keyof o extends infer k ? k extends keyof o ? typeProp<o, k, $> : never : never;
|
|
36
|
+
type typeProp<o, k extends keyof o, $, t = o[k] & ({} | null)> = parseConstraints<t> extends ([
|
|
37
|
+
infer base,
|
|
38
|
+
infer constraints extends Default | Optional
|
|
39
|
+
]) ? constraints extends Default<infer defaultValue> ? DefaultedTypeProp<k & Key, keyof constraints extends keyof Default ? base : constrain<base, Omit<constraints, keyof Default>>, defaultValue, $> : constraints extends Optional ? BaseTypeProp<"optional", k & Key, keyof constraints extends keyof Optional ? base : constrain<base, Omit<constraints, keyof Optional>>, $> : never : BaseTypeProp<k extends optionalKeyOf<o> ? "optional" : "required", k & Key, t, $>;
|
|
40
|
+
export interface BaseTypeProp<kind extends Prop.Kind = Prop.Kind, k extends Key = Key,
|
|
41
|
+
/** @ts-ignore cast variance */
|
|
42
|
+
out v = unknown, $ = {}> {
|
|
43
|
+
kind: kind;
|
|
44
|
+
key: k;
|
|
45
|
+
value: instantiateType<v, $>;
|
|
46
|
+
meta: ArkEnv.meta;
|
|
47
|
+
toJSON: () => Json;
|
|
48
|
+
}
|
|
49
|
+
export interface DefaultedTypeProp<k extends Key = Key, v = unknown, defaultValue = v, $ = {}> extends BaseTypeProp<"optional", k, v, $> {
|
|
50
|
+
default: defaultValue;
|
|
51
|
+
}
|
|
52
|
+
type MappedTypeProp<k extends Key = Key, v = unknown> = BaseMappedTypeProp<k, v> | OptionalMappedTypeProp<k, v>;
|
|
53
|
+
type BaseMappedTypeProp<k extends Key, v> = merge<BaseMappedPropInner, {
|
|
54
|
+
key: k;
|
|
55
|
+
value: type.cast<v>;
|
|
56
|
+
}>;
|
|
57
|
+
type OptionalMappedTypeProp<k extends Key, v> = merge<OptionalMappedPropInner, {
|
|
58
|
+
key: k;
|
|
59
|
+
value: type.cast<v>;
|
|
60
|
+
default?: v;
|
|
61
|
+
}>;
|
|
62
|
+
type constructMapped<t, transformed extends listable<MappedTypeProp>> = show<intersectUnion<fromTypeProps<t, transformed extends array ? transformed : [transformed]>>>;
|
|
63
|
+
type fromTypeProps<t, props extends array<MappedTypeProp>> = show<{
|
|
64
|
+
[prop in props[number] as Extract<applyHomomorphicOptionality<t, prop>, {
|
|
65
|
+
kind: "required";
|
|
66
|
+
}>["key"]]: prop["value"][inferred];
|
|
67
|
+
} & {
|
|
68
|
+
[prop in props[number] as Extract<applyHomomorphicOptionality<t, prop>, {
|
|
69
|
+
kind: "optional";
|
|
70
|
+
default?: never;
|
|
71
|
+
}>["key"]]?: prop["value"][inferred];
|
|
72
|
+
} & {
|
|
73
|
+
[prop in props[number] as Extract<applyHomomorphicOptionality<t, prop>, {
|
|
74
|
+
kind: "optional";
|
|
75
|
+
default: unknown;
|
|
76
|
+
}>["key"]]: applyConstraint<prop["value"][inferred], Default<prop["default" & keyof prop]>>;
|
|
77
|
+
}>;
|
|
78
|
+
type applyHomomorphicOptionality<t, prop extends MappedTypeProp> = prop["kind"] extends string ? prop : prop & {
|
|
79
|
+
kind: prop["key"] extends optionalKeyOf<t> ? "optional" : "required";
|
|
80
|
+
};
|
|
81
|
+
export type { Type as ObjectType };
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { ExactLength, ExclusiveNumericRangeSchema, exclusivizeRangeSchema, InclusiveNumericRangeSchema, Pattern } from "@ark/schema";
|
|
2
|
-
import type {
|
|
2
|
+
import type { applyConstraintSchema } from "../keywords/inference.ts";
|
|
3
3
|
import type { ValidatorType } from "./validator.ts";
|
|
4
4
|
/** @ts-ignore cast variance */
|
|
5
5
|
interface Type<out t extends string = string, $ = {}> extends ValidatorType<t, $> {
|
|
6
|
-
matching<const schema extends Pattern.Schema>(schema: schema): Type<
|
|
7
|
-
atLeastLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<
|
|
8
|
-
atMostLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<
|
|
9
|
-
moreThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<
|
|
10
|
-
lessThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<
|
|
11
|
-
exactlyLength<const schema extends ExactLength.Schema>(schema: schema): Type<
|
|
6
|
+
matching<const schema extends Pattern.Schema>(schema: schema): Type<applyConstraintSchema<t, "pattern", schema>, $>;
|
|
7
|
+
atLeastLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<applyConstraintSchema<t, "minLength", schema>, $>;
|
|
8
|
+
atMostLength<const schema extends InclusiveNumericRangeSchema>(schema: schema): Type<applyConstraintSchema<t, "maxLength", schema>, $>;
|
|
9
|
+
moreThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<applyConstraintSchema<t, "minLength", exclusivizeRangeSchema<schema>>, $>;
|
|
10
|
+
lessThanLength<const schema extends ExclusiveNumericRangeSchema>(schema: schema): Type<applyConstraintSchema<t, "maxLength", exclusivizeRangeSchema<schema>>, $>;
|
|
11
|
+
exactlyLength<const schema extends ExactLength.Schema>(schema: schema): Type<applyConstraintSchema<t, "exactLength", schema>, $>;
|
|
12
12
|
}
|
|
13
13
|
export type { Type as StringType };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { Predicate, PredicateCast } from "@ark/schema";
|
|
2
|
-
import type {
|
|
2
|
+
import type { applyConstraintSchema } from "../keywords/inference.ts";
|
|
3
3
|
import type { BaseType } from "./base.ts";
|
|
4
4
|
import type { instantiateType } from "./instantiate.ts";
|
|
5
5
|
/** @ts-ignore cast variance */
|
|
6
6
|
interface Type<out t = unknown, $ = {}> extends BaseType<t, $> {
|
|
7
7
|
narrow<narrowed extends this["infer"] = never>(predicate: Predicate<this["infer"]> | PredicateCast<this["infer"], narrowed>): instantiateType<[
|
|
8
8
|
narrowed
|
|
9
|
-
] extends [never] ?
|
|
9
|
+
] extends [never] ? applyConstraintSchema<t, "predicate", Predicate> : narrowed, $>;
|
|
10
10
|
}
|
|
11
11
|
export type { Type as ValidatorType };
|
package/out/module.d.ts
CHANGED
|
@@ -12,8 +12,8 @@ export interface BoundModule<exports extends {}, $> extends RootModule<bindExpor
|
|
|
12
12
|
export type bindExportsToScope<exports, $> = {
|
|
13
13
|
[k in keyof exports]: instantiateExport<exports[k], $>;
|
|
14
14
|
} & unknown;
|
|
15
|
-
export type Submodule<exports extends {}> = RootModule<exports & ("
|
|
16
|
-
[inferred]: exports["
|
|
15
|
+
export type Submodule<exports extends {}> = RootModule<exports & ("root" extends keyof exports ? {
|
|
16
|
+
[inferred]: exports["root"];
|
|
17
17
|
} : {})>;
|
|
18
18
|
export type instantiateExport<t, $> = [
|
|
19
19
|
t
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { writeUnboundableMessage } from "@ark/schema";
|
|
2
2
|
import type { ErrorMessage, array, typeToString } from "@ark/util";
|
|
3
|
-
import type { LimitLiteral } from "../../keywords/
|
|
4
|
-
import type { Comparator } from "../
|
|
5
|
-
import type { BoundExpressionKind, writeInvalidLimitMessage } from "../
|
|
3
|
+
import type { LimitLiteral } from "../../keywords/inference.ts";
|
|
4
|
+
import type { Comparator } from "../reduce/shared.ts";
|
|
5
|
+
import type { BoundExpressionKind, writeInvalidLimitMessage } from "../shift/operator/bounds.ts";
|
|
6
6
|
import type { inferAstIn } from "./infer.ts";
|
|
7
7
|
import type { astToString } from "./utils.ts";
|
|
8
8
|
import type { validateAst } from "./validate.ts";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { writeUnassignableDefaultValueMessage } from "@ark/schema";
|
|
2
|
+
import type { ErrorMessage } from "@ark/util";
|
|
3
|
+
import type { type } from "../../keywords/keywords.ts";
|
|
4
|
+
import type { UnitLiteral } from "../shift/operator/default.ts";
|
|
5
|
+
import type { inferAstOut } from "./infer.ts";
|
|
6
|
+
import type { astToString } from "./utils.ts";
|
|
7
|
+
import type { validateAst } from "./validate.ts";
|
|
8
|
+
export type validateDefault<baseAst, unitLiteral extends UnitLiteral, $, args> = validateAst<baseAst, $, args> extends infer e extends ErrorMessage ? e : type.infer<unitLiteral> extends inferAstOut<baseAst, $, args> ? undefined : ErrorMessage<writeUnassignableDefaultValueMessage<astToString<baseAst>, unitLiteral>>;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import type { GenericAst } from "@ark/schema";
|
|
2
|
-
import type { Hkt, array } from "@ark/util";
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
2
|
+
import type { Hkt, arkKeyOf, array } from "@ark/util";
|
|
3
|
+
import type { Date } from "../../keywords/constructors/Date.ts";
|
|
4
|
+
import type { Default, LimitLiteral, Optional, applyConstraint, applyConstraintSchema, distill, inferIntersection, normalizeLimit } from "../../keywords/inference.ts";
|
|
5
|
+
import type { type } from "../../keywords/keywords.ts";
|
|
5
6
|
import type { UnparsedScope } from "../../scope.ts";
|
|
6
|
-
import type { inferAmbient } from "../../type.ts";
|
|
7
7
|
import type { inferDefinition } from "../definition.ts";
|
|
8
|
-
import type { Comparator, MinComparator } from "../
|
|
8
|
+
import type { Comparator, MinComparator } from "../reduce/shared.ts";
|
|
9
9
|
export type inferAstRoot<ast, $, args> = ast extends array ? inferExpression<ast, $, args> : never;
|
|
10
|
-
export type inferAstIn<ast, $, args> =
|
|
11
|
-
export type inferAstOut<ast, $, args> =
|
|
10
|
+
export type inferAstIn<ast, $, args> = distill.In<inferAstRoot<ast, $, args>>;
|
|
11
|
+
export type inferAstOut<ast, $, args> = distill.Out<inferAstRoot<ast, $, args>>;
|
|
12
12
|
export type DefAst<def = unknown, alias extends string = string> = [
|
|
13
13
|
def,
|
|
14
14
|
"def",
|
|
@@ -25,15 +25,15 @@ export type inferExpression<ast, $, args> = ast extends array ? ast extends Infe
|
|
|
25
25
|
[i in keyof argAsts]: inferExpression<argAsts[i], $, args>;
|
|
26
26
|
}> : inferDefinition<g["bodyDef"], resolveScope<g["$"], $>, {
|
|
27
27
|
[i in keyof g["names"] & `${number}` as g["names"][i]]: inferExpression<argAsts[i & keyof argAsts], resolveScope<g["arg$"], $>, args>;
|
|
28
|
-
}> : ast[1] extends "[]" ? inferExpression<ast[0], $, args>[] : ast[1] extends "|" ? inferExpression<ast[0], $, args> | inferExpression<ast[2], $, args> : ast[1] extends "&" ? inferIntersection<inferExpression<ast[0], $, args>, inferExpression<ast[2], $, args>> : ast[1] extends "=" ?
|
|
29
|
-
export type
|
|
28
|
+
}> : ast[1] extends "[]" ? inferExpression<ast[0], $, args>[] : ast[1] extends "|" ? inferExpression<ast[0], $, args> | inferExpression<ast[2], $, args> : ast[1] extends "&" ? inferIntersection<inferExpression<ast[0], $, args>, inferExpression<ast[2], $, args>> : ast[1] extends "=" ? type.infer<ast[2]> extends infer defaultValue ? applyConstraint<inferExpression<ast[0], $, args>, Default<defaultValue>> : never : ast[1] extends Comparator ? ast[0] extends LimitLiteral ? brandBound<inferExpression<ast[2], $, args>, ast[1], ast[0]> : brandBound<inferExpression<ast[0], $, args>, ast[1], ast[2] & LimitLiteral> : ast[1] extends "%" ? applyConstraintSchema<inferExpression<ast[0], $, args>, "divisor", ast[2] & number> : ast[1] extends "?" ? applyConstraint<inferExpression<ast[0], $, args>, Optional> : ast[0] extends "keyof" ? arkKeyOf<inferExpression<ast[1], $, args>> : never : never;
|
|
29
|
+
export type brandBound<brandableIn, comparator extends Comparator, limit extends LimitLiteral> = distill.In<brandableIn> extends infer In ? comparator extends "==" ? In extends number ? limit : In extends Date ? Date.literal<normalizeLimit<limit>> : applyConstraintSchema<brandableIn, "exactLength", limit & number> : applyConstraintSchema<brandableIn, In extends number ? comparator extends MinComparator ? "min" : "max" : In extends string | array ? comparator extends MinComparator ? "minLength" : "maxLength" : comparator extends MinComparator ? "after" : "before", {
|
|
30
30
|
rule: normalizeLimit<limit>;
|
|
31
31
|
exclusive: comparator extends ">" | "<" ? true : false;
|
|
32
32
|
}> : never;
|
|
33
33
|
export type PrefixOperator = "keyof" | "instanceof" | "===" | "node";
|
|
34
34
|
export type PrefixExpression<operator extends PrefixOperator = PrefixOperator, operand = unknown> = [operator, operand];
|
|
35
|
-
export type PostfixOperator = "[]";
|
|
35
|
+
export type PostfixOperator = "[]" | "?";
|
|
36
36
|
export type PostfixExpression<operator extends PostfixOperator = PostfixOperator, operand = unknown> = readonly [operand, operator];
|
|
37
|
-
export type InfixOperator = "|" | "&" | Comparator | "%" | ":" | "=>" | "@";
|
|
37
|
+
export type InfixOperator = "|" | "&" | Comparator | "%" | ":" | "=>" | "@" | "=";
|
|
38
38
|
export type InfixExpression<operator extends InfixOperator = InfixOperator, l = unknown, r = unknown> = [l, operator, r];
|
|
39
39
|
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Stringifiable } from "@ark/util";
|
|
2
|
-
import type { Comparator } from "../
|
|
2
|
+
import type { Comparator } from "../reduce/shared.ts";
|
|
3
3
|
import type { DefAst, InferredAst, InfixExpression, PostfixExpression } from "./infer.ts";
|
|
4
4
|
export type astToString<ast> = ast extends InferredAst | DefAst ? ast[2] : ast extends PostfixExpression<infer operator, infer operand> ? operator extends "[]" ? `${astToString<operand>}[]` : never : ast extends InfixExpression<infer operator, infer l, infer r> ? operator extends "&" | "|" | "%" | Comparator ? `${astToString<l>} ${operator} ${astToString<r>}` : never : ast extends Stringifiable ? `${ast extends bigint ? `${ast}n` : ast}` : "...";
|