arktype 2.0.0-rc.3 → 2.0.0-rc.5
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.js +1 -1
- package/out/index.d.ts +1 -1
- package/out/index.js +1 -1
- package/out/keywords/ark.d.ts +17 -1
- package/out/keywords/ast.d.ts +94 -101
- package/out/keywords/constructors/Array.d.ts +1 -1
- package/out/keywords/constructors/Array.js +2 -2
- package/out/keywords/constructors/Date.d.ts +31 -0
- package/out/keywords/constructors/FormData.d.ts +1 -1
- package/out/keywords/constructors/FormData.js +1 -1
- package/out/keywords/number/epoch.d.ts +1 -2
- package/out/keywords/number/number.d.ts +23 -6
- package/out/keywords/number/number.js +1 -1
- package/out/keywords/string/capitalize.d.ts +1 -1
- package/out/keywords/string/capitalize.js +1 -1
- package/out/keywords/string/date.d.ts +3 -3
- package/out/keywords/string/date.js +7 -7
- package/out/keywords/string/integer.d.ts +1 -1
- package/out/keywords/string/integer.js +3 -3
- package/out/keywords/string/ip.d.ts +1 -1
- package/out/keywords/string/ip.js +1 -1
- package/out/keywords/string/json.d.ts +1 -1
- package/out/keywords/string/json.js +2 -2
- package/out/keywords/string/lower.d.ts +1 -1
- package/out/keywords/string/lower.js +1 -1
- package/out/keywords/string/normalize.d.ts +22 -22
- package/out/keywords/string/normalize.js +5 -5
- package/out/keywords/string/numeric.d.ts +1 -1
- package/out/keywords/string/numeric.js +3 -3
- package/out/keywords/string/string.d.ts +35 -36
- package/out/keywords/string/string.js +1 -1
- package/out/keywords/string/trim.d.ts +1 -1
- package/out/keywords/string/trim.js +1 -1
- package/out/keywords/string/upper.d.ts +1 -1
- package/out/keywords/string/upper.js +1 -1
- package/out/keywords/string/url.d.ts +1 -1
- package/out/keywords/string/url.js +3 -3
- package/out/keywords/string/uuid.d.ts +10 -10
- package/out/keywords/string/uuid.js +1 -1
- package/out/{subtypes → methods}/array.d.ts +6 -6
- package/out/{subtypes → methods}/base.d.ts +17 -15
- package/out/{subtypes → methods}/date.d.ts +5 -5
- package/out/{subtypes → methods}/morph.d.ts +2 -2
- package/out/{subtypes → methods}/number.d.ts +6 -6
- 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/definition.d.ts +1 -1
- package/out/parser/objectLiteral.d.ts +5 -30
- package/out/parser/objectLiteral.js +18 -21
- package/out/parser/semantic/default.d.ts +1 -2
- package/out/parser/semantic/default.js +1 -1
- package/out/parser/semantic/infer.d.ts +7 -6
- 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/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 +3 -1
- package/out/scope.d.ts +8 -5
- package/out/scope.js +7 -6
- package/out/type.d.ts +8 -4
- package/out/type.js +3 -1
- package/package.json +3 -3
- /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 → methods}/object.d.ts +0 -0
- /package/out/{subtypes/string.js → methods/object.js} +0 -0
- /package/out/{subtypes/validator.js → methods/string.js} +0 -0
|
@@ -3,7 +3,7 @@ import { submodule } from "../utils.js";
|
|
|
3
3
|
import { regexStringNode } from "./utils.js";
|
|
4
4
|
const preformatted = regexStringNode(/^[a-z]*$/, "only lowercase letters");
|
|
5
5
|
export const lower = submodule({
|
|
6
|
-
|
|
6
|
+
root: rootNode({
|
|
7
7
|
in: "string",
|
|
8
8
|
morphs: (s) => s.toLowerCase(),
|
|
9
9
|
declaredOut: preformatted
|
|
@@ -13,45 +13,45 @@ declare namespace string {
|
|
|
13
13
|
export declare const normalizedForms: readonly ["NFC", "NFD", "NFKC", "NFKD"];
|
|
14
14
|
export type NormalizedForm = (typeof normalizedForms)[number];
|
|
15
15
|
export declare const NFC: Module<{
|
|
16
|
-
|
|
17
|
-
preformatted:
|
|
16
|
+
root: unknown;
|
|
17
|
+
preformatted: unknown;
|
|
18
18
|
}>;
|
|
19
19
|
export declare const NFD: Module<{
|
|
20
|
-
|
|
21
|
-
preformatted:
|
|
20
|
+
root: unknown;
|
|
21
|
+
preformatted: unknown;
|
|
22
22
|
}>;
|
|
23
23
|
export declare const NFKC: Module<{
|
|
24
|
-
|
|
25
|
-
preformatted:
|
|
24
|
+
root: unknown;
|
|
25
|
+
preformatted: unknown;
|
|
26
26
|
}>;
|
|
27
27
|
export declare const NFKD: Module<{
|
|
28
|
-
|
|
29
|
-
preformatted:
|
|
28
|
+
root: unknown;
|
|
29
|
+
preformatted: unknown;
|
|
30
30
|
}>;
|
|
31
31
|
export declare const normalize: Module<{
|
|
32
|
-
|
|
32
|
+
root: unknown;
|
|
33
33
|
NFC: Submodule<{
|
|
34
|
-
|
|
35
|
-
preformatted:
|
|
34
|
+
root: unknown;
|
|
35
|
+
preformatted: unknown;
|
|
36
36
|
}>;
|
|
37
37
|
NFD: Submodule<{
|
|
38
|
-
|
|
39
|
-
preformatted:
|
|
38
|
+
root: unknown;
|
|
39
|
+
preformatted: unknown;
|
|
40
40
|
}>;
|
|
41
41
|
NFKC: Submodule<{
|
|
42
|
-
|
|
43
|
-
preformatted:
|
|
42
|
+
root: unknown;
|
|
43
|
+
preformatted: unknown;
|
|
44
44
|
}>;
|
|
45
45
|
NFKD: Submodule<{
|
|
46
|
-
|
|
47
|
-
preformatted:
|
|
46
|
+
root: unknown;
|
|
47
|
+
preformatted: unknown;
|
|
48
48
|
}>;
|
|
49
49
|
}>;
|
|
50
50
|
export declare namespace normalize {
|
|
51
51
|
type module = Module<submodule>;
|
|
52
52
|
type submodule = Submodule<$>;
|
|
53
53
|
type $ = {
|
|
54
|
-
|
|
54
|
+
root: (In: string) => To<string.normalized.NFC>;
|
|
55
55
|
NFC: NFC.submodule;
|
|
56
56
|
NFD: NFD.submodule;
|
|
57
57
|
NFKC: NFKC.submodule;
|
|
@@ -63,28 +63,28 @@ export declare namespace normalize {
|
|
|
63
63
|
namespace NFC {
|
|
64
64
|
type submodule = Submodule<$>;
|
|
65
65
|
type $ = {
|
|
66
|
-
|
|
66
|
+
root: (In: string) => To<string.normalized.NFC>;
|
|
67
67
|
preformatted: string.normalized.NFC;
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
70
|
namespace NFD {
|
|
71
71
|
type submodule = Submodule<$>;
|
|
72
72
|
type $ = {
|
|
73
|
-
|
|
73
|
+
root: (In: string) => To<string.normalized.NFD>;
|
|
74
74
|
preformatted: string.normalized.NFD;
|
|
75
75
|
};
|
|
76
76
|
}
|
|
77
77
|
namespace NFKC {
|
|
78
78
|
type submodule = Submodule<$>;
|
|
79
79
|
type $ = {
|
|
80
|
-
|
|
80
|
+
root: (In: string) => To<string.normalized.NFKC>;
|
|
81
81
|
preformatted: string.normalized.NFKC;
|
|
82
82
|
};
|
|
83
83
|
}
|
|
84
84
|
namespace NFKD {
|
|
85
85
|
type submodule = Submodule<$>;
|
|
86
86
|
type $ = {
|
|
87
|
-
|
|
87
|
+
root: (In: string) => To<string.normalized.NFKD>;
|
|
88
88
|
preformatted: string.normalized.NFKD;
|
|
89
89
|
};
|
|
90
90
|
}
|
|
@@ -19,23 +19,23 @@ const normalizeNodes = flatMorph(normalizedForms, (i, form) => [
|
|
|
19
19
|
})
|
|
20
20
|
]);
|
|
21
21
|
export const NFC = submodule({
|
|
22
|
-
|
|
22
|
+
root: normalizeNodes.NFC,
|
|
23
23
|
preformatted: preformattedNodes.NFC
|
|
24
24
|
});
|
|
25
25
|
export const NFD = submodule({
|
|
26
|
-
|
|
26
|
+
root: normalizeNodes.NFD,
|
|
27
27
|
preformatted: preformattedNodes.NFD
|
|
28
28
|
});
|
|
29
29
|
export const NFKC = submodule({
|
|
30
|
-
|
|
30
|
+
root: normalizeNodes.NFKC,
|
|
31
31
|
preformatted: preformattedNodes.NFKC
|
|
32
32
|
});
|
|
33
33
|
export const NFKD = submodule({
|
|
34
|
-
|
|
34
|
+
root: normalizeNodes.NFKD,
|
|
35
35
|
preformatted: preformattedNodes.NFKD
|
|
36
36
|
});
|
|
37
37
|
export const normalize = submodule({
|
|
38
|
-
|
|
38
|
+
root: "NFC",
|
|
39
39
|
NFC,
|
|
40
40
|
NFD,
|
|
41
41
|
NFKC,
|
|
@@ -2,11 +2,11 @@ import { intrinsic, rootNode } from "@ark/schema";
|
|
|
2
2
|
import { wellFormedNumberMatcher } from "@ark/util";
|
|
3
3
|
import { submodule } from "../utils.js";
|
|
4
4
|
import { regexStringNode } from "./utils.js";
|
|
5
|
-
const
|
|
5
|
+
const root = regexStringNode(wellFormedNumberMatcher, "a well-formed numeric string");
|
|
6
6
|
export const numeric = submodule({
|
|
7
|
-
|
|
7
|
+
root,
|
|
8
8
|
parse: rootNode({
|
|
9
|
-
in:
|
|
9
|
+
in: root,
|
|
10
10
|
morphs: (s) => Number.parseFloat(s),
|
|
11
11
|
declaredOut: intrinsic.number
|
|
12
12
|
})
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { type Constraint, type NodeSchema } from "@ark/schema";
|
|
2
1
|
import type { Module, Submodule } from "../../module.ts";
|
|
3
2
|
import type { type } from "../ark.ts";
|
|
4
|
-
import type { AtLeastLength, AtMostLength, Branded, Constraints, ExactlyLength, LessThanLength,
|
|
3
|
+
import type { AtLeastLength, AtMostLength, Branded, Constraints, ExactlyLength, LessThanLength, MoreThanLength, Narrowed, Optional, constrain, constraint } from "../ast.ts";
|
|
5
4
|
import { alpha } from "./alpha.ts";
|
|
6
5
|
import { alphanumeric } from "./alphanumeric.ts";
|
|
7
6
|
import { capitalize } from "./capitalize.ts";
|
|
@@ -23,52 +22,55 @@ import { uuid } from "./uuid.ts";
|
|
|
23
22
|
export declare const string: Module<{
|
|
24
23
|
trim: Submodule<trim.submodule>;
|
|
25
24
|
normalize: Submodule<{
|
|
26
|
-
|
|
25
|
+
root: unknown;
|
|
27
26
|
NFC: Submodule<{
|
|
28
|
-
|
|
29
|
-
preformatted:
|
|
27
|
+
root: unknown;
|
|
28
|
+
preformatted: unknown;
|
|
30
29
|
}>;
|
|
31
30
|
NFD: Submodule<{
|
|
32
|
-
|
|
33
|
-
preformatted:
|
|
31
|
+
root: unknown;
|
|
32
|
+
preformatted: unknown;
|
|
34
33
|
}>;
|
|
35
34
|
NFKC: Submodule<{
|
|
36
|
-
|
|
37
|
-
preformatted:
|
|
35
|
+
root: unknown;
|
|
36
|
+
preformatted: unknown;
|
|
38
37
|
}>;
|
|
39
38
|
NFKD: Submodule<{
|
|
40
|
-
|
|
41
|
-
preformatted:
|
|
39
|
+
root: unknown;
|
|
40
|
+
preformatted: unknown;
|
|
42
41
|
}>;
|
|
43
42
|
}>;
|
|
43
|
+
root: unknown;
|
|
44
|
+
date: Submodule<stringDate.submodule>;
|
|
45
|
+
lower: Submodule<lower.submodule>;
|
|
46
|
+
upper: Submodule<upper.submodule>;
|
|
44
47
|
json: Submodule<stringJson.submodule>;
|
|
45
|
-
$root: object;
|
|
46
48
|
integer: Submodule<stringInteger.submodule>;
|
|
47
|
-
alpha:
|
|
48
|
-
alphanumeric:
|
|
49
|
-
creditCard:
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
email: object;
|
|
49
|
+
alpha: unknown;
|
|
50
|
+
alphanumeric: unknown;
|
|
51
|
+
creditCard: unknown;
|
|
52
|
+
digits: unknown;
|
|
53
|
+
email: unknown;
|
|
53
54
|
ip: Submodule<ip.submodule>;
|
|
54
55
|
numeric: Submodule<stringNumeric.submodule>;
|
|
55
|
-
semver:
|
|
56
|
+
semver: unknown;
|
|
56
57
|
url: Submodule<url.submodule>;
|
|
57
58
|
uuid: Submodule<{
|
|
58
|
-
|
|
59
|
-
v4:
|
|
60
|
-
v6:
|
|
61
|
-
v1:
|
|
62
|
-
v2:
|
|
63
|
-
v3:
|
|
64
|
-
v5:
|
|
65
|
-
v7:
|
|
66
|
-
v8:
|
|
59
|
+
root: string.matching<string> | "00000000-0000-0000-0000-000000000000" | "ffffffff-ffff-ffff-ffff-ffffffffffff";
|
|
60
|
+
v4: unknown;
|
|
61
|
+
v6: unknown;
|
|
62
|
+
v1: unknown;
|
|
63
|
+
v2: unknown;
|
|
64
|
+
v3: unknown;
|
|
65
|
+
v5: unknown;
|
|
66
|
+
v7: unknown;
|
|
67
|
+
v8: unknown;
|
|
67
68
|
}>;
|
|
68
|
-
upper: Submodule<upper.submodule>;
|
|
69
|
-
lower: Submodule<lower.submodule>;
|
|
70
69
|
capitalize: Submodule<capitalize.submodule>;
|
|
71
70
|
}>;
|
|
71
|
+
export type Matching<rule> = {
|
|
72
|
+
matching: constraint<rule>;
|
|
73
|
+
};
|
|
72
74
|
export declare namespace string {
|
|
73
75
|
type atLeastLength<rule> = constrain<string, AtLeastLength<rule>>;
|
|
74
76
|
type moreThanLength<rule> = constrain<string, MoreThanLength<rule>>;
|
|
@@ -77,17 +79,14 @@ export declare namespace string {
|
|
|
77
79
|
type exactlyLength<rule> = constrain<string, ExactlyLength<rule>>;
|
|
78
80
|
type matching<rule> = constrain<string, Matching<rule>>;
|
|
79
81
|
type narrowed = constrain<string, Narrowed>;
|
|
82
|
+
type optional = constrain<string, Optional>;
|
|
80
83
|
type branded<rule> = constrain<string, Branded<rule>>;
|
|
81
84
|
type is<constraints extends Constraints> = constrain<string, constraints>;
|
|
82
|
-
type
|
|
83
|
-
exclusive: true;
|
|
84
|
-
} ? moreThanLength<rule> : atLeastLength<rule> : kind extends "maxLength" ? schema extends {
|
|
85
|
-
exclusive: true;
|
|
86
|
-
} ? lessThanLength<rule> : atMostLength<rule> : kind extends "pattern" ? matching<rule & string> : kind extends "exactLength" ? exactlyLength<rule> : narrowed : never;
|
|
85
|
+
type withConstraint<constraint> = constraint extends ExactlyLength<infer rule> ? exactlyLength<rule> : constraint extends MoreThanLength<infer rule> ? moreThanLength<rule> : constraint extends AtLeastLength<infer rule> ? atLeastLength<rule> : constraint extends AtMostLength<infer rule> ? atMostLength<rule> : constraint extends LessThanLength<infer rule> ? lessThanLength<rule> : constraint extends Matching<infer rule> ? matching<rule> : constraint extends Optional ? optional : constraint extends Narrowed ? narrowed : never;
|
|
87
86
|
type module = Module<string.submodule>;
|
|
88
87
|
type submodule = Submodule<$>;
|
|
89
88
|
type $ = {
|
|
90
|
-
|
|
89
|
+
root: string;
|
|
91
90
|
alpha: alpha;
|
|
92
91
|
alphanumeric: alphanumeric;
|
|
93
92
|
digits: digits;
|
|
@@ -3,7 +3,7 @@ import { submodule } from "../utils.js";
|
|
|
3
3
|
import { regexStringNode } from "./utils.js";
|
|
4
4
|
const preformatted = regexStringNode(/^[A-Z]*$/, "only uppercase letters");
|
|
5
5
|
export const upper = submodule({
|
|
6
|
-
|
|
6
|
+
root: rootNode({
|
|
7
7
|
in: "string",
|
|
8
8
|
morphs: (s) => s.toUpperCase(),
|
|
9
9
|
declaredOut: preformatted
|
|
@@ -12,7 +12,7 @@ const isParsableUrl = (s) => {
|
|
|
12
12
|
return false;
|
|
13
13
|
}
|
|
14
14
|
};
|
|
15
|
-
const
|
|
15
|
+
const root = rootNode({
|
|
16
16
|
domain: "string",
|
|
17
17
|
predicate: {
|
|
18
18
|
meta: "a URL string",
|
|
@@ -20,9 +20,9 @@ const $root = rootNode({
|
|
|
20
20
|
}
|
|
21
21
|
});
|
|
22
22
|
export const url = submodule({
|
|
23
|
-
|
|
23
|
+
root,
|
|
24
24
|
parse: rootNode({
|
|
25
|
-
declaredIn:
|
|
25
|
+
declaredIn: root,
|
|
26
26
|
in: "string",
|
|
27
27
|
morphs: (s, ctx) => {
|
|
28
28
|
try {
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import type { Module, Submodule } from "../../module.ts";
|
|
2
2
|
import type { Branded, constrain } from "../ast.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;
|
|
@@ -4,7 +4,7 @@ import { regexStringNode } from "./utils.js";
|
|
|
4
4
|
export const uuid = submodule({
|
|
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,
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { ExactLength, ExclusiveNumericRangeSchema, exclusivizeRangeSchema, InclusiveNumericRangeSchema } from "@ark/schema";
|
|
2
|
-
import type {
|
|
2
|
+
import type { applyConstraintSchema } from "../keywords/ast.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 };
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import type { ArkErrors, BaseRoot, Disjoint, JsonSchema, MetaSchema, Morph, UndeclaredKeyBehavior } from "@ark/schema";
|
|
2
2
|
import type { anyOrNever, array, Callable, ErrorMessage, inferred, Json, unset } from "@ark/util";
|
|
3
3
|
import type { inferIntersection } from "../intersect.ts";
|
|
4
|
-
import type {
|
|
4
|
+
import type { applyConstraint, Default, distill, inferMorphOut, inferPipes, Optional } from "../keywords/ast.ts";
|
|
5
5
|
import type { Scope } from "../scope.ts";
|
|
6
6
|
import type { inferTypeRoot, validateTypeRoot } from "../type.ts";
|
|
7
7
|
import type { ArrayType } from "./array.ts";
|
|
8
8
|
import type { instantiateType } from "./instantiate.ts";
|
|
9
9
|
/** @ts-ignore cast variance */
|
|
10
|
-
interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) =>
|
|
10
|
+
interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => distill.Out<t> | ArkErrors> {
|
|
11
11
|
t: t;
|
|
12
|
-
tIn:
|
|
13
|
-
tOut:
|
|
14
|
-
tValidatedOut:
|
|
15
|
-
infer:
|
|
16
|
-
inferIn:
|
|
12
|
+
tIn: distill.brandable.In<t>;
|
|
13
|
+
tOut: distill.brandable.Out<t>;
|
|
14
|
+
tValidatedOut: distill.introspectable.Out<t>;
|
|
15
|
+
infer: distill.Out<t>;
|
|
16
|
+
inferIn: distill.In<t>;
|
|
17
17
|
[inferred]: t;
|
|
18
18
|
json: Json;
|
|
19
19
|
toJsonSchema(): JsonSchema;
|
|
@@ -23,9 +23,11 @@ interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => dist
|
|
|
23
23
|
$: Scope<$>;
|
|
24
24
|
assert(data: unknown): this["infer"];
|
|
25
25
|
allows(data: unknown): data is this["inferIn"];
|
|
26
|
-
traverse(data: unknown):
|
|
26
|
+
traverse(data: unknown): distill.Out<t> | ArkErrors;
|
|
27
27
|
configure(meta: MetaSchema): this;
|
|
28
28
|
describe(description: string): this;
|
|
29
|
+
optional<r = applyConstraint<t, Optional>>(): instantiateType<r, $>;
|
|
30
|
+
default<value extends this["infer"], r = (In?: this["tIn"]) => Default<value>>(value: value): instantiateType<r, $>;
|
|
29
31
|
onUndeclaredKey(behavior: UndeclaredKeyBehavior): this;
|
|
30
32
|
onDeepUndeclaredKey(behavior: UndeclaredKeyBehavior): this;
|
|
31
33
|
from(literal: this["inferIn"]): this["infer"];
|
|
@@ -63,13 +65,13 @@ interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => dist
|
|
|
63
65
|
Symbol: never;
|
|
64
66
|
}
|
|
65
67
|
interface ChainedPipeSignature<t, $> {
|
|
66
|
-
<a extends Morph<
|
|
67
|
-
<a extends Morph<
|
|
68
|
-
<a extends Morph<
|
|
69
|
-
<a extends Morph<
|
|
70
|
-
<a extends Morph<
|
|
71
|
-
<a extends Morph<
|
|
72
|
-
<a extends Morph<
|
|
68
|
+
<a extends Morph<distill.Out<t>>, r = instantiateType<inferPipes<t, [a]>, $>>(a: a): r;
|
|
69
|
+
<a extends Morph<distill.Out<t>>, b extends Morph<inferMorphOut<a>>, r = instantiateType<inferPipes<t, [a, b]>, $>>(a: a, b: b): r;
|
|
70
|
+
<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): r;
|
|
71
|
+
<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): r;
|
|
72
|
+
<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): r;
|
|
73
|
+
<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): r;
|
|
74
|
+
<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): r;
|
|
73
75
|
}
|
|
74
76
|
export interface ChainedPipes<t, $> extends ChainedPipeSignature<t, $> {
|
|
75
77
|
try: ChainedPipeSignature<t, $>;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { ExclusiveDateRangeSchema, exclusivizeRangeSchema, InclusiveDateRangeSchema } from "@ark/schema";
|
|
2
|
-
import type {
|
|
2
|
+
import type { applyConstraintSchema } from "../keywords/ast.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,6 @@
|
|
|
1
1
|
import type { Predicate, PredicateCast } from "@ark/schema";
|
|
2
2
|
import type { inferPipe } from "../intersect.ts";
|
|
3
|
-
import type {
|
|
3
|
+
import type { applyConstraintSchema, Out, To } from "../keywords/ast.ts";
|
|
4
4
|
import type { inferTypeRoot, validateTypeRoot } from "../type.ts";
|
|
5
5
|
import type { BaseType } from "./base.ts";
|
|
6
6
|
/** @ts-ignore cast variance */
|
|
@@ -8,6 +8,6 @@ interface Type<out t = unknown, $ = {}> extends BaseType<t, $> {
|
|
|
8
8
|
to<const def, r = inferTypeRoot<def, $>>(def: validateTypeRoot<def, $>): Type<inferPipe<t, r>, $>;
|
|
9
9
|
narrow<narrowed extends this["infer"] = never>(predicate: Predicate<this["infer"]> | PredicateCast<this["infer"], narrowed>): Type<([
|
|
10
10
|
narrowed
|
|
11
|
-
] extends [never] ?
|
|
11
|
+
] extends [never] ? applyConstraintSchema<this["tOut"], "predicate", Predicate> : narrowed) extends infer o ? this["tValidatedOut"] extends this["tOut"] ? (In: this["tIn"]) => To<o> : (In: this["tIn"]) => Out<o> : never, $>;
|
|
12
12
|
}
|
|
13
13
|
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/ast.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 };
|
|
@@ -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/ast.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/ast.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 };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
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
|
|
@@ -10,7 +10,7 @@ import { type TupleExpression, type inferTuple, type validateTuple } from "./tup
|
|
|
10
10
|
export declare const parseObject: (def: object, ctx: ParseContext) => BaseRoot;
|
|
11
11
|
export type inferDefinition<def, $, args> = [
|
|
12
12
|
def
|
|
13
|
-
] extends [anyOrNever] ? def : def extends type.cast<infer t> ? ifEmptyObjectLiteral<
|
|
13
|
+
] extends [anyOrNever] ? def : def extends type.cast<infer t> ? ifEmptyObjectLiteral<def, object, t> : def extends ThunkCast<infer t> ? t : def extends string ? inferString<def, $, args> : def extends array ? inferTuple<def, $, args> : def extends RegExp ? string.matching<string> : def extends object ? inferObjectLiteral<def, $, args> : never;
|
|
14
14
|
export type validateDefinition<def, $, args> = null extends undefined ? ErrorMessage<`'strict' or 'strictNullChecks' must be set to true in your tsconfig's 'compilerOptions'`> : [def] extends [Terminal] ? def : def extends string ? validateString<def, $, args> : def extends array ? validateTuple<def, $, args> : def extends BadDefinitionType ? ErrorMessage<writeBadDefinitionTypeMessage<objectKindOrDomainOf<def>>> : unknown extends def ? BaseCompletions<$, args> | {} : validateObjectLiteral<def, $, args>;
|
|
15
15
|
export type validateDeclared<declared, def, $, args> = def extends validateDefinition<def, $, args> ? validateInference<def, declared, $, args> : validateDefinition<def, $, args>;
|
|
16
16
|
type validateInference<def, declared, $, args> = def extends RegExp | type.cast<unknown> | ThunkCast | TupleExpression ? validateShallowInference<def, declared, $, args> : def extends array ? declared extends array ? {
|