arktype 2.0.0-rc.0 → 2.0.0-rc.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/config.d.ts +1 -1
- package/out/generic.d.ts +55 -53
- package/out/generic.js +9 -11
- package/out/index.d.ts +5 -5
- package/out/index.js +3 -2
- package/out/keywords/{builtin.d.ts → builtins.d.ts} +9 -5
- package/out/keywords/{builtin.js → builtins.js} +2 -2
- package/out/keywords/constructors/Array.d.ts +12 -8
- package/out/keywords/constructors/Array.js +7 -7
- package/out/keywords/constructors/Date.d.ts +32 -0
- package/out/keywords/constructors/FormData.d.ts +12 -6
- package/out/keywords/constructors/FormData.js +19 -6
- package/out/keywords/constructors/TypedArray.d.ts +18 -14
- package/out/keywords/constructors/TypedArray.js +2 -2
- package/out/keywords/constructors/constructors.d.ts +21 -32
- package/out/keywords/constructors/constructors.js +13 -28
- package/out/keywords/inference.d.ts +227 -0
- package/out/keywords/keywords.d.ts +61 -0
- package/out/keywords/keywords.js +26 -0
- package/out/keywords/number/epoch.d.ts +1 -2
- package/out/keywords/number/epoch.js +2 -2
- package/out/keywords/number/integer.js +2 -2
- package/out/keywords/number/number.d.ts +37 -9
- package/out/keywords/number/number.js +17 -5
- package/out/keywords/string/alpha.d.ts +1 -1
- package/out/keywords/string/alphanumeric.d.ts +1 -1
- package/out/keywords/string/capitalize.d.ts +11 -10
- package/out/keywords/string/capitalize.js +4 -4
- package/out/keywords/string/creditCard.d.ts +1 -1
- package/out/keywords/string/creditCard.js +2 -2
- package/out/keywords/string/date.d.ts +27 -26
- package/out/keywords/string/date.js +16 -16
- package/out/keywords/string/digits.d.ts +1 -1
- package/out/keywords/string/email.d.ts +1 -1
- package/out/keywords/string/integer.d.ts +11 -10
- package/out/keywords/string/integer.js +7 -7
- package/out/keywords/string/ip.d.ts +12 -12
- package/out/keywords/string/ip.js +5 -5
- package/out/keywords/string/json.d.ts +12 -10
- package/out/keywords/string/json.js +24 -16
- package/out/keywords/string/lower.d.ts +11 -10
- package/out/keywords/string/lower.js +4 -4
- package/out/keywords/string/normalize.d.ts +63 -47
- package/out/keywords/string/normalize.js +14 -14
- package/out/keywords/string/numeric.d.ts +11 -10
- package/out/keywords/string/numeric.js +7 -7
- package/out/keywords/string/semver.d.ts +1 -1
- package/out/keywords/string/string.d.ts +78 -26
- package/out/keywords/string/string.js +5 -5
- package/out/keywords/string/trim.d.ts +11 -10
- package/out/keywords/string/trim.js +4 -4
- package/out/keywords/string/upper.d.ts +11 -10
- package/out/keywords/string/upper.js +4 -4
- package/out/keywords/string/url.d.ts +11 -10
- package/out/keywords/string/url.js +8 -8
- package/out/keywords/string/uuid.d.ts +27 -23
- package/out/keywords/string/uuid.js +3 -3
- package/out/keywords/ts.d.ts +44 -22
- package/out/keywords/ts.js +20 -14
- package/out/keywords/utils.d.ts +1 -1
- package/out/keywords/utils.js +1 -1
- package/out/{subtypes → methods}/array.d.ts +6 -6
- package/out/methods/base.d.ts +96 -0
- package/out/{subtypes → methods}/date.d.ts +5 -5
- package/out/{subtypes → methods}/instantiate.d.ts +5 -4
- package/out/methods/morph.d.ts +12 -0
- package/out/{subtypes → methods}/number.d.ts +6 -6
- package/out/methods/object.d.ts +81 -0
- package/out/{subtypes → methods}/string.d.ts +7 -7
- package/out/{subtypes → methods}/validator.d.ts +2 -2
- package/out/module.d.ts +2 -2
- package/out/parser/{semantic → ast}/bounds.d.ts +6 -4
- package/out/parser/ast/default.d.ts +8 -0
- package/out/parser/ast/infer.d.ts +39 -0
- package/out/parser/ast/utils.d.ts +4 -0
- package/out/parser/ast/validate.d.ts +26 -0
- package/out/parser/definition.d.ts +9 -12
- package/out/parser/objectLiteral.d.ts +11 -25
- package/out/parser/objectLiteral.js +6 -24
- package/out/parser/{string/reduce → reduce}/dynamic.d.ts +5 -7
- package/out/parser/{string/reduce → reduce}/dynamic.js +5 -6
- package/out/parser/{string/reduce → reduce}/shared.d.ts +1 -1
- package/out/parser/{string/reduce → reduce}/static.d.ts +1 -1
- package/out/parser/{string/shift → shift}/operand/date.d.ts +3 -1
- package/out/parser/{string/shift → shift}/operand/enclosed.d.ts +4 -1
- package/out/parser/{string/shift → shift}/operand/enclosed.js +7 -3
- package/out/parser/{string/shift → shift}/operand/unenclosed.d.ts +7 -8
- package/out/parser/{string/shift → shift}/operand/unenclosed.js +7 -3
- package/out/parser/{string/shift → shift}/operator/bounds.d.ts +7 -6
- package/out/parser/{string/shift → shift}/operator/default.d.ts +3 -6
- package/out/parser/{string/shift → shift}/operator/default.js +1 -6
- package/out/parser/{string/shift → shift}/operator/operator.js +2 -2
- package/out/parser/{string/shift → shift}/scanner.d.ts +6 -2
- package/out/parser/{string/shift → shift}/scanner.js +7 -5
- package/out/parser/{string/string.d.ts → string.d.ts} +8 -8
- package/out/parser/{string/string.js → string.js} +2 -0
- package/out/parser/tuple.d.ts +54 -43
- package/out/parser/tuple.js +36 -30
- package/out/scope.d.ts +41 -34
- package/out/scope.js +48 -27
- package/out/type.d.ts +25 -20
- package/out/type.js +23 -14
- package/package.json +3 -3
- package/out/intersect.d.ts +0 -28
- package/out/keys.d.ts +0 -16
- package/out/keywords/ark.d.ts +0 -33
- package/out/keywords/ark.js +0 -18
- package/out/keywords/ast.d.ts +0 -193
- package/out/parser/semantic/default.d.ts +0 -8
- package/out/parser/semantic/default.js +0 -1
- package/out/parser/semantic/infer.d.ts +0 -33
- package/out/parser/semantic/utils.d.ts +0 -4
- package/out/parser/semantic/validate.d.ts +0 -29
- package/out/subtypes/base.d.ts +0 -84
- package/out/subtypes/morph.d.ts +0 -13
- package/out/subtypes/object.d.ts +0 -33
- /package/out/{intersect.js → keywords/constructors/Date.js} +0 -0
- /package/out/keywords/{ast.js → inference.js} +0 -0
- /package/out/{subtypes → methods}/array.js +0 -0
- /package/out/{subtypes → methods}/base.js +0 -0
- /package/out/{subtypes → methods}/date.js +0 -0
- /package/out/{subtypes → methods}/instantiate.js +0 -0
- /package/out/{subtypes → methods}/morph.js +0 -0
- /package/out/{subtypes → methods}/number.js +0 -0
- /package/out/{subtypes → methods}/object.js +0 -0
- /package/out/{subtypes → methods}/string.js +0 -0
- /package/out/{subtypes → methods}/validator.js +0 -0
- /package/out/parser/{semantic → ast}/bounds.js +0 -0
- /package/out/{keys.js → parser/ast/default.js} +0 -0
- /package/out/parser/{semantic → ast}/divisor.d.ts +0 -0
- /package/out/parser/{semantic → ast}/divisor.js +0 -0
- /package/out/parser/{semantic → ast}/infer.js +0 -0
- /package/out/parser/{semantic → ast}/keyof.d.ts +0 -0
- /package/out/parser/{semantic → ast}/keyof.js +0 -0
- /package/out/parser/{semantic → ast}/utils.js +0 -0
- /package/out/parser/{semantic → ast}/validate.js +0 -0
- /package/out/parser/{string/reduce → reduce}/shared.js +0 -0
- /package/out/parser/{string/reduce → reduce}/static.js +0 -0
- /package/out/parser/{string/shift → shift}/operand/date.js +0 -0
- /package/out/parser/{string/shift → shift}/operand/genericArgs.d.ts +0 -0
- /package/out/parser/{string/shift → shift}/operand/genericArgs.js +0 -0
- /package/out/parser/{string/shift → shift}/operand/operand.d.ts +0 -0
- /package/out/parser/{string/shift → shift}/operand/operand.js +0 -0
- /package/out/parser/{string/shift → shift}/operator/bounds.js +0 -0
- /package/out/parser/{string/shift → shift}/operator/divisor.d.ts +0 -0
- /package/out/parser/{string/shift → shift}/operator/divisor.js +0 -0
- /package/out/parser/{string/shift → shift}/operator/operator.d.ts +0 -0
|
@@ -1,24 +1,75 @@
|
|
|
1
|
-
import { type Constraint, type NodeSchema } from "@ark/schema";
|
|
2
1
|
import type { Module, Submodule } from "../../module.ts";
|
|
3
|
-
import type { AtLeastLength, AtMostLength, Branded, Constraints, ExactlyLength, LessThanLength,
|
|
2
|
+
import type { AtLeastLength, AtMostLength, Branded, Constraints, Default, ExactlyLength, LessThanLength, MoreThanLength, Narrowed, Optional, constrain, constraint } from "../inference.ts";
|
|
4
3
|
import { alpha } from "./alpha.ts";
|
|
5
4
|
import { alphanumeric } from "./alphanumeric.ts";
|
|
6
5
|
import { capitalize } from "./capitalize.ts";
|
|
7
6
|
import { creditCard } from "./creditCard.ts";
|
|
8
|
-
import {
|
|
7
|
+
import { stringDate } from "./date.ts";
|
|
9
8
|
import { digits } from "./digits.ts";
|
|
10
9
|
import { email } from "./email.ts";
|
|
11
|
-
import {
|
|
10
|
+
import { type stringInteger } from "./integer.ts";
|
|
12
11
|
import { ip } from "./ip.ts";
|
|
13
|
-
import {
|
|
12
|
+
import { type stringJson } from "./json.ts";
|
|
14
13
|
import { lower } from "./lower.ts";
|
|
15
14
|
import { normalize } from "./normalize.ts";
|
|
16
|
-
import {
|
|
15
|
+
import { type stringNumeric } from "./numeric.ts";
|
|
17
16
|
import { semver } from "./semver.ts";
|
|
18
17
|
import { trim } from "./trim.ts";
|
|
19
18
|
import { upper } from "./upper.ts";
|
|
19
|
+
import { url } from "./url.ts";
|
|
20
20
|
import { uuid } from "./uuid.ts";
|
|
21
|
-
export declare const string: Module<
|
|
21
|
+
export declare const string: Module<{
|
|
22
|
+
root: unknown;
|
|
23
|
+
trim: Submodule<trim.submodule>;
|
|
24
|
+
normalize: Submodule<{
|
|
25
|
+
root: unknown;
|
|
26
|
+
NFC: Submodule<{
|
|
27
|
+
root: unknown;
|
|
28
|
+
preformatted: unknown;
|
|
29
|
+
}>;
|
|
30
|
+
NFD: Submodule<{
|
|
31
|
+
root: unknown;
|
|
32
|
+
preformatted: unknown;
|
|
33
|
+
}>;
|
|
34
|
+
NFKC: Submodule<{
|
|
35
|
+
root: unknown;
|
|
36
|
+
preformatted: unknown;
|
|
37
|
+
}>;
|
|
38
|
+
NFKD: Submodule<{
|
|
39
|
+
root: unknown;
|
|
40
|
+
preformatted: unknown;
|
|
41
|
+
}>;
|
|
42
|
+
}>;
|
|
43
|
+
alpha: unknown;
|
|
44
|
+
alphanumeric: unknown;
|
|
45
|
+
json: Submodule<stringJson.submodule>;
|
|
46
|
+
creditCard: unknown;
|
|
47
|
+
integer: Submodule<stringInteger.submodule>;
|
|
48
|
+
date: Submodule<stringDate.submodule>;
|
|
49
|
+
digits: unknown;
|
|
50
|
+
email: unknown;
|
|
51
|
+
ip: Submodule<ip.submodule>;
|
|
52
|
+
numeric: Submodule<stringNumeric.submodule>;
|
|
53
|
+
semver: unknown;
|
|
54
|
+
url: Submodule<url.submodule>;
|
|
55
|
+
uuid: Submodule<{
|
|
56
|
+
root: string.matching<string> | "00000000-0000-0000-0000-000000000000" | "ffffffff-ffff-ffff-ffff-ffffffffffff";
|
|
57
|
+
v4: unknown;
|
|
58
|
+
v6: unknown;
|
|
59
|
+
v1: unknown;
|
|
60
|
+
v2: unknown;
|
|
61
|
+
v3: unknown;
|
|
62
|
+
v5: unknown;
|
|
63
|
+
v7: unknown;
|
|
64
|
+
v8: unknown;
|
|
65
|
+
}>;
|
|
66
|
+
upper: Submodule<upper.submodule>;
|
|
67
|
+
lower: Submodule<lower.submodule>;
|
|
68
|
+
capitalize: Submodule<capitalize.submodule>;
|
|
69
|
+
}>;
|
|
70
|
+
export type Matching<rule> = {
|
|
71
|
+
matching: constraint<rule>;
|
|
72
|
+
};
|
|
22
73
|
export declare namespace string {
|
|
23
74
|
type atLeastLength<rule> = constrain<string, AtLeastLength<rule>>;
|
|
24
75
|
type moreThanLength<rule> = constrain<string, MoreThanLength<rule>>;
|
|
@@ -27,31 +78,32 @@ export declare namespace string {
|
|
|
27
78
|
type exactlyLength<rule> = constrain<string, ExactlyLength<rule>>;
|
|
28
79
|
type matching<rule> = constrain<string, Matching<rule>>;
|
|
29
80
|
type narrowed = constrain<string, Narrowed>;
|
|
81
|
+
type optional = constrain<string, Optional>;
|
|
82
|
+
type defaultsTo<rule> = constrain<string, Default<rule>>;
|
|
30
83
|
type branded<rule> = constrain<string, Branded<rule>>;
|
|
31
84
|
type is<constraints extends Constraints> = constrain<string, constraints>;
|
|
32
|
-
type
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
type submodule = Submodule<{
|
|
38
|
-
$root: string;
|
|
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 Default<infer rule> ? defaultsTo<rule> : constraint extends Narrowed ? narrowed : never;
|
|
86
|
+
type module = Module<string.submodule>;
|
|
87
|
+
type submodule = Submodule<$>;
|
|
88
|
+
type $ = {
|
|
89
|
+
root: string;
|
|
39
90
|
alpha: alpha;
|
|
40
91
|
alphanumeric: alphanumeric;
|
|
41
92
|
digits: digits;
|
|
42
|
-
numeric:
|
|
43
|
-
integer:
|
|
93
|
+
numeric: stringNumeric.submodule;
|
|
94
|
+
integer: stringInteger.submodule;
|
|
44
95
|
creditCard: creditCard;
|
|
45
96
|
email: email;
|
|
46
|
-
uuid: uuid;
|
|
97
|
+
uuid: uuid.submodule;
|
|
47
98
|
semver: semver;
|
|
48
|
-
ip: ip;
|
|
49
|
-
json:
|
|
50
|
-
date:
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
99
|
+
ip: ip.submodule;
|
|
100
|
+
json: stringJson.submodule;
|
|
101
|
+
date: stringDate.submodule;
|
|
102
|
+
url: url.submodule;
|
|
103
|
+
trim: trim.submodule;
|
|
104
|
+
normalize: normalize.submodule;
|
|
105
|
+
capitalize: capitalize.submodule;
|
|
106
|
+
lower: lower.submodule;
|
|
107
|
+
upper: upper.submodule;
|
|
108
|
+
};
|
|
57
109
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { intrinsic } from "@ark/schema";
|
|
2
|
-
import {
|
|
2
|
+
import { arkModule } from "../utils.js";
|
|
3
3
|
import { alpha } from "./alpha.js";
|
|
4
4
|
import { alphanumeric } from "./alphanumeric.js";
|
|
5
5
|
import { capitalize } from "./capitalize.js";
|
|
6
6
|
import { creditCard } from "./creditCard.js";
|
|
7
|
-
import {
|
|
7
|
+
import { stringDate } from "./date.js";
|
|
8
8
|
import { digits } from "./digits.js";
|
|
9
9
|
import { email } from "./email.js";
|
|
10
10
|
import { integer } from "./integer.js";
|
|
@@ -18,8 +18,8 @@ import { trim } from "./trim.js";
|
|
|
18
18
|
import { upper } from "./upper.js";
|
|
19
19
|
import { url } from "./url.js";
|
|
20
20
|
import { uuid } from "./uuid.js";
|
|
21
|
-
export const string =
|
|
22
|
-
|
|
21
|
+
export const string = arkModule({
|
|
22
|
+
root: intrinsic.string,
|
|
23
23
|
numeric,
|
|
24
24
|
integer,
|
|
25
25
|
alpha,
|
|
@@ -37,5 +37,5 @@ export const string = submodule({
|
|
|
37
37
|
lower,
|
|
38
38
|
normalize,
|
|
39
39
|
capitalize,
|
|
40
|
-
date
|
|
40
|
+
date: stringDate
|
|
41
41
|
});
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import type { Submodule } from "../../module.ts";
|
|
2
|
-
import type { Branded, constrain, To } from "../
|
|
1
|
+
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
+
import type { Branded, constrain, To } from "../inference.ts";
|
|
3
3
|
declare namespace string {
|
|
4
4
|
type trimmed = constrain<string, Branded<"trimmed">>;
|
|
5
5
|
}
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
6
|
+
export declare const trim: trim.module;
|
|
7
|
+
export declare namespace trim {
|
|
8
|
+
type module = Module<submodule>;
|
|
9
|
+
type submodule = Submodule<$>;
|
|
10
|
+
type $ = {
|
|
11
|
+
root: (In: string) => To<string.trimmed>;
|
|
12
|
+
preformatted: string.trimmed;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
14
15
|
export {};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { rootSchema } from "@ark/schema";
|
|
2
|
+
import { arkModule } from "../utils.js";
|
|
3
3
|
import { regexStringNode } from "./utils.js";
|
|
4
4
|
const preformatted = regexStringNode(
|
|
5
5
|
// no leading or trailing whitespace
|
|
6
6
|
/^\S.*\S$|^\S?$/, "trimmed");
|
|
7
|
-
export const trim =
|
|
8
|
-
|
|
7
|
+
export const trim = arkModule({
|
|
8
|
+
root: rootSchema({
|
|
9
9
|
in: "string",
|
|
10
10
|
morphs: (s) => s.trim(),
|
|
11
11
|
declaredOut: preformatted
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import type { Submodule } from "../../module.ts";
|
|
2
|
-
import type { Branded, constrain, To } from "../
|
|
1
|
+
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
+
import type { Branded, constrain, To } from "../inference.ts";
|
|
3
3
|
declare namespace string {
|
|
4
4
|
type uppercase = constrain<string, Branded<"uppercase">>;
|
|
5
5
|
}
|
|
6
|
-
export
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
6
|
+
export declare const upper: upper.module;
|
|
7
|
+
export declare namespace upper {
|
|
8
|
+
type module = Module<submodule>;
|
|
9
|
+
type submodule = Submodule<$>;
|
|
10
|
+
type $ = {
|
|
11
|
+
root: (In: string) => To<string.uppercase>;
|
|
12
|
+
preformatted: string.uppercase;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
14
15
|
export {};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { rootSchema } from "@ark/schema";
|
|
2
|
+
import { arkModule } from "../utils.js";
|
|
3
3
|
import { regexStringNode } from "./utils.js";
|
|
4
4
|
const preformatted = regexStringNode(/^[A-Z]*$/, "only uppercase letters");
|
|
5
|
-
export const upper =
|
|
6
|
-
|
|
5
|
+
export const upper = arkModule({
|
|
6
|
+
root: rootSchema({
|
|
7
7
|
in: "string",
|
|
8
8
|
morphs: (s) => s.toUpperCase(),
|
|
9
9
|
declaredOut: preformatted
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import type { Submodule } from "../../module.ts";
|
|
2
|
-
import type { Branded, constrain, To } from "../
|
|
1
|
+
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
+
import type { Branded, constrain, To } from "../inference.ts";
|
|
3
3
|
declare namespace string {
|
|
4
4
|
type url = constrain<string, Branded<"url">>;
|
|
5
5
|
}
|
|
6
|
-
export declare const url:
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
6
|
+
export declare const url: url.module;
|
|
7
|
+
export declare namespace url {
|
|
8
|
+
type module = Module<submodule>;
|
|
9
|
+
type submodule = Submodule<$>;
|
|
10
|
+
type $ = {
|
|
11
|
+
root: string.url;
|
|
12
|
+
parse: (In: string.url) => To<URL>;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
14
15
|
export {};
|
|
@@ -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
|
-
import type { Submodule } from "../../module.ts";
|
|
2
|
-
import type { Branded, constrain } from "../
|
|
3
|
-
export declare const uuid:
|
|
4
|
-
|
|
5
|
-
v4:
|
|
6
|
-
v6:
|
|
7
|
-
v1:
|
|
8
|
-
v2:
|
|
9
|
-
v3:
|
|
10
|
-
v5:
|
|
11
|
-
v7:
|
|
12
|
-
v8:
|
|
1
|
+
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
+
import type { Branded, constrain } from "../inference.ts";
|
|
3
|
+
export declare const uuid: Module<{
|
|
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">>;
|
|
@@ -24,15 +24,19 @@ declare namespace string {
|
|
|
24
24
|
type v8 = constrain<string, Branded<"uuid.v8">>;
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
export
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
27
|
+
export declare namespace uuid {
|
|
28
|
+
type module = Module<submodule>;
|
|
29
|
+
type submodule = Submodule<$>;
|
|
30
|
+
type $ = {
|
|
31
|
+
root: string.uuid;
|
|
32
|
+
v1: string.uuid.v1;
|
|
33
|
+
v2: string.uuid.v2;
|
|
34
|
+
v3: string.uuid.v3;
|
|
35
|
+
v4: string.uuid.v4;
|
|
36
|
+
v5: string.uuid.v5;
|
|
37
|
+
v6: string.uuid.v6;
|
|
38
|
+
v7: string.uuid.v7;
|
|
39
|
+
v8: string.uuid.v8;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
38
42
|
export {};
|
|
@@ -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,35 @@
|
|
|
1
1
|
import { Hkt, type Key, type omit, type pick, type show } from "@ark/util";
|
|
2
2
|
import type { Module, Submodule } from "../module.ts";
|
|
3
|
+
export declare const arkTsKeywords: arkTsKeywords;
|
|
4
|
+
export type arkTsKeywords = Module<arkTsKeywords.$>;
|
|
5
|
+
export declare namespace arkTsKeywords {
|
|
6
|
+
type submodule = Submodule<$>;
|
|
7
|
+
type $ = {
|
|
8
|
+
bigint: bigint;
|
|
9
|
+
boolean: boolean;
|
|
10
|
+
false: false;
|
|
11
|
+
never: never;
|
|
12
|
+
null: null;
|
|
13
|
+
number: number;
|
|
14
|
+
object: object;
|
|
15
|
+
string: string;
|
|
16
|
+
symbol: symbol;
|
|
17
|
+
true: true;
|
|
18
|
+
unknown: unknown;
|
|
19
|
+
undefined: undefined;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export declare const unknown: Module<{
|
|
23
|
+
root: unknown;
|
|
24
|
+
any: unknown;
|
|
25
|
+
}>;
|
|
26
|
+
export declare namespace unknown {
|
|
27
|
+
type submodule = Submodule<$>;
|
|
28
|
+
type $ = {
|
|
29
|
+
root: unknown;
|
|
30
|
+
any: any;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
3
33
|
declare class RecordHkt extends Hkt<[Key, unknown]> {
|
|
4
34
|
body: Record<this[0], this[1]>;
|
|
5
35
|
}
|
|
@@ -28,26 +58,18 @@ declare class ExtractHkt extends Hkt<[unknown, unknown]> {
|
|
|
28
58
|
body: Extract<this[0], this[1]>;
|
|
29
59
|
}
|
|
30
60
|
declare const Extract: import("@ark/schema").GenericRoot<readonly [["T", unknown], ["U", unknown]], ExtractHkt>;
|
|
31
|
-
export declare const
|
|
32
|
-
export
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
Record: typeof Record.t;
|
|
46
|
-
Pick: typeof Pick.t;
|
|
47
|
-
Omit: typeof Omit.t;
|
|
48
|
-
Exclude: typeof Exclude.t;
|
|
49
|
-
Extract: typeof Extract.t;
|
|
50
|
-
Partial: typeof Partial.t;
|
|
51
|
-
Required: typeof Required.t;
|
|
52
|
-
}>;
|
|
61
|
+
export declare const arkTsGenerics: arkTsGenerics.module;
|
|
62
|
+
export declare namespace arkTsGenerics {
|
|
63
|
+
type module = Module<arkTsGenerics.$>;
|
|
64
|
+
type submodule = Submodule<$>;
|
|
65
|
+
type $ = {
|
|
66
|
+
Record: typeof Record.t;
|
|
67
|
+
Pick: typeof Pick.t;
|
|
68
|
+
Omit: typeof Omit.t;
|
|
69
|
+
Exclude: typeof Exclude.t;
|
|
70
|
+
Extract: typeof Extract.t;
|
|
71
|
+
Partial: typeof Partial.t;
|
|
72
|
+
Required: typeof Required.t;
|
|
73
|
+
};
|
|
74
|
+
}
|
|
53
75
|
export {};
|
package/out/keywords/ts.js
CHANGED
|
@@ -1,6 +1,24 @@
|
|
|
1
1
|
import { genericNode, intrinsic } from "@ark/schema";
|
|
2
2
|
import { Hkt } from "@ark/util";
|
|
3
|
-
import {
|
|
3
|
+
import { arkModule } from "./utils.js";
|
|
4
|
+
export const arkTsKeywords = arkModule({
|
|
5
|
+
bigint: intrinsic.bigint,
|
|
6
|
+
boolean: intrinsic.boolean,
|
|
7
|
+
false: intrinsic.false,
|
|
8
|
+
never: intrinsic.never,
|
|
9
|
+
null: intrinsic.null,
|
|
10
|
+
number: intrinsic.number,
|
|
11
|
+
object: intrinsic.object,
|
|
12
|
+
string: intrinsic.string,
|
|
13
|
+
symbol: intrinsic.symbol,
|
|
14
|
+
true: intrinsic.true,
|
|
15
|
+
unknown: intrinsic.unknown,
|
|
16
|
+
undefined: intrinsic.undefined
|
|
17
|
+
});
|
|
18
|
+
export const unknown = arkModule({
|
|
19
|
+
root: intrinsic.unknown,
|
|
20
|
+
any: intrinsic.unknown
|
|
21
|
+
});
|
|
4
22
|
class RecordHkt extends Hkt {
|
|
5
23
|
}
|
|
6
24
|
const Record = genericNode(["K", intrinsic.key], "V")(args => ({
|
|
@@ -28,19 +46,7 @@ const Exclude = genericNode("T", "U")(args => args.T.exclude(args.U), ExcludeHkt
|
|
|
28
46
|
class ExtractHkt extends Hkt {
|
|
29
47
|
}
|
|
30
48
|
const Extract = genericNode("T", "U")(args => args.T.extract(args.U), ExtractHkt);
|
|
31
|
-
export const
|
|
32
|
-
bigint: intrinsic.bigint,
|
|
33
|
-
boolean: intrinsic.boolean,
|
|
34
|
-
false: intrinsic.false,
|
|
35
|
-
never: intrinsic.never,
|
|
36
|
-
null: intrinsic.null,
|
|
37
|
-
number: intrinsic.number,
|
|
38
|
-
object: intrinsic.object,
|
|
39
|
-
string: intrinsic.string,
|
|
40
|
-
symbol: intrinsic.symbol,
|
|
41
|
-
true: intrinsic.true,
|
|
42
|
-
unknown: intrinsic.unknown,
|
|
43
|
-
undefined: intrinsic.undefined,
|
|
49
|
+
export const arkTsGenerics = arkModule({
|
|
44
50
|
Record,
|
|
45
51
|
Pick,
|
|
46
52
|
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 };
|