arktype 2.0.0-rc.1 → 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 +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 +227 -0
- package/out/keywords/keywords.d.ts +61 -0
- package/out/keywords/{ark.js → keywords.js} +10 -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 +11 -0
- package/out/keywords/ts.js +7 -3
- package/out/keywords/utils.d.ts +1 -1
- package/out/keywords/utils.js +1 -1
- package/out/{subtypes → methods}/array.d.ts +6 -6
- package/out/methods/base.d.ts +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,6 +1,5 @@
|
|
|
1
1
|
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type {
|
|
3
|
-
import type { Branded, constrain, To } from "../ast.ts";
|
|
2
|
+
import type { Branded, constrain, To } from "../inference.ts";
|
|
4
3
|
declare namespace string {
|
|
5
4
|
type normalized = normalized.NFC;
|
|
6
5
|
namespace normalized {
|
|
@@ -13,78 +12,75 @@ declare namespace string {
|
|
|
13
12
|
export declare const normalizedForms: readonly ["NFC", "NFD", "NFKC", "NFKD"];
|
|
14
13
|
export type NormalizedForm = (typeof normalizedForms)[number];
|
|
15
14
|
export declare const NFC: Module<{
|
|
16
|
-
|
|
17
|
-
preformatted:
|
|
15
|
+
root: unknown;
|
|
16
|
+
preformatted: unknown;
|
|
18
17
|
}>;
|
|
19
18
|
export declare const NFD: Module<{
|
|
20
|
-
|
|
21
|
-
preformatted:
|
|
19
|
+
root: unknown;
|
|
20
|
+
preformatted: unknown;
|
|
22
21
|
}>;
|
|
23
22
|
export declare const NFKC: Module<{
|
|
24
|
-
|
|
25
|
-
preformatted:
|
|
23
|
+
root: unknown;
|
|
24
|
+
preformatted: unknown;
|
|
26
25
|
}>;
|
|
27
26
|
export declare const NFKD: Module<{
|
|
28
|
-
|
|
29
|
-
preformatted:
|
|
27
|
+
root: unknown;
|
|
28
|
+
preformatted: unknown;
|
|
30
29
|
}>;
|
|
31
30
|
export declare const normalize: Module<{
|
|
32
|
-
|
|
31
|
+
root: unknown;
|
|
33
32
|
NFC: Submodule<{
|
|
34
|
-
|
|
35
|
-
preformatted:
|
|
33
|
+
root: unknown;
|
|
34
|
+
preformatted: unknown;
|
|
36
35
|
}>;
|
|
37
36
|
NFD: Submodule<{
|
|
38
|
-
|
|
39
|
-
preformatted:
|
|
37
|
+
root: unknown;
|
|
38
|
+
preformatted: unknown;
|
|
40
39
|
}>;
|
|
41
40
|
NFKC: Submodule<{
|
|
42
|
-
|
|
43
|
-
preformatted:
|
|
41
|
+
root: unknown;
|
|
42
|
+
preformatted: unknown;
|
|
44
43
|
}>;
|
|
45
44
|
NFKD: Submodule<{
|
|
46
|
-
|
|
47
|
-
preformatted:
|
|
45
|
+
root: unknown;
|
|
46
|
+
preformatted: unknown;
|
|
48
47
|
}>;
|
|
49
48
|
}>;
|
|
50
49
|
export declare namespace normalize {
|
|
51
50
|
type module = Module<submodule>;
|
|
52
51
|
type submodule = Submodule<$>;
|
|
53
52
|
type $ = {
|
|
54
|
-
|
|
53
|
+
root: (In: string) => To<string.normalized.NFC>;
|
|
55
54
|
NFC: NFC.submodule;
|
|
56
55
|
NFD: NFD.submodule;
|
|
57
56
|
NFKC: NFKC.submodule;
|
|
58
57
|
NFKD: NFKD.submodule;
|
|
59
58
|
};
|
|
60
|
-
type shallowResolutions = {
|
|
61
|
-
[k in keyof $ as `string.normalize.${k}`]: $[k] extends type.cast<infer t> ? t : $[k];
|
|
62
|
-
};
|
|
63
59
|
namespace NFC {
|
|
64
60
|
type submodule = Submodule<$>;
|
|
65
61
|
type $ = {
|
|
66
|
-
|
|
62
|
+
root: (In: string) => To<string.normalized.NFC>;
|
|
67
63
|
preformatted: string.normalized.NFC;
|
|
68
64
|
};
|
|
69
65
|
}
|
|
70
66
|
namespace NFD {
|
|
71
67
|
type submodule = Submodule<$>;
|
|
72
68
|
type $ = {
|
|
73
|
-
|
|
69
|
+
root: (In: string) => To<string.normalized.NFD>;
|
|
74
70
|
preformatted: string.normalized.NFD;
|
|
75
71
|
};
|
|
76
72
|
}
|
|
77
73
|
namespace NFKC {
|
|
78
74
|
type submodule = Submodule<$>;
|
|
79
75
|
type $ = {
|
|
80
|
-
|
|
76
|
+
root: (In: string) => To<string.normalized.NFKC>;
|
|
81
77
|
preformatted: string.normalized.NFKC;
|
|
82
78
|
};
|
|
83
79
|
}
|
|
84
80
|
namespace NFKD {
|
|
85
81
|
type submodule = Submodule<$>;
|
|
86
82
|
type $ = {
|
|
87
|
-
|
|
83
|
+
root: (In: string) => To<string.normalized.NFKD>;
|
|
88
84
|
preformatted: string.normalized.NFKD;
|
|
89
85
|
};
|
|
90
86
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { rootSchema } from "@ark/schema";
|
|
2
2
|
import { flatMorph } from "@ark/util";
|
|
3
|
-
import {
|
|
3
|
+
import { arkModule } from "../utils.js";
|
|
4
4
|
export const normalizedForms = ["NFC", "NFD", "NFKC", "NFKD"];
|
|
5
5
|
const preformattedNodes = flatMorph(normalizedForms, (i, form) => [
|
|
6
6
|
form,
|
|
7
|
-
|
|
7
|
+
rootSchema({
|
|
8
8
|
domain: "string",
|
|
9
9
|
predicate: (s) => s.normalize(form) === s,
|
|
10
10
|
meta: `${form}-normalized unicode`
|
|
@@ -12,30 +12,30 @@ const preformattedNodes = flatMorph(normalizedForms, (i, form) => [
|
|
|
12
12
|
]);
|
|
13
13
|
const normalizeNodes = flatMorph(normalizedForms, (i, form) => [
|
|
14
14
|
form,
|
|
15
|
-
|
|
15
|
+
rootSchema({
|
|
16
16
|
in: "string",
|
|
17
17
|
morphs: (s) => s.normalize(form),
|
|
18
18
|
declaredOut: preformattedNodes[form]
|
|
19
19
|
})
|
|
20
20
|
]);
|
|
21
|
-
export const NFC =
|
|
22
|
-
|
|
21
|
+
export const NFC = arkModule({
|
|
22
|
+
root: normalizeNodes.NFC,
|
|
23
23
|
preformatted: preformattedNodes.NFC
|
|
24
24
|
});
|
|
25
|
-
export const NFD =
|
|
26
|
-
|
|
25
|
+
export const NFD = arkModule({
|
|
26
|
+
root: normalizeNodes.NFD,
|
|
27
27
|
preformatted: preformattedNodes.NFD
|
|
28
28
|
});
|
|
29
|
-
export const NFKC =
|
|
30
|
-
|
|
29
|
+
export const NFKC = arkModule({
|
|
30
|
+
root: normalizeNodes.NFKC,
|
|
31
31
|
preformatted: preformattedNodes.NFKC
|
|
32
32
|
});
|
|
33
|
-
export const NFKD =
|
|
34
|
-
|
|
33
|
+
export const NFKD = arkModule({
|
|
34
|
+
root: normalizeNodes.NFKD,
|
|
35
35
|
preformatted: preformattedNodes.NFKD
|
|
36
36
|
});
|
|
37
|
-
export const normalize =
|
|
38
|
-
|
|
37
|
+
export const normalize = arkModule({
|
|
38
|
+
root: "NFC",
|
|
39
39
|
NFC,
|
|
40
40
|
NFD,
|
|
41
41
|
NFKC,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type { Branded, constrain, To } from "../
|
|
2
|
+
import type { Branded, constrain, To } from "../inference.ts";
|
|
3
3
|
declare namespace string {
|
|
4
4
|
type numeric = constrain<string, Branded<"numeric">>;
|
|
5
5
|
}
|
|
@@ -8,7 +8,7 @@ export declare namespace stringNumeric {
|
|
|
8
8
|
type module = Module<submodule>;
|
|
9
9
|
type submodule = Submodule<$>;
|
|
10
10
|
type $ = {
|
|
11
|
-
|
|
11
|
+
root: string.numeric;
|
|
12
12
|
parse: (In: string.numeric) => To<number>;
|
|
13
13
|
};
|
|
14
14
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { intrinsic,
|
|
1
|
+
import { intrinsic, rootSchema } from "@ark/schema";
|
|
2
2
|
import { wellFormedNumberMatcher } from "@ark/util";
|
|
3
|
-
import {
|
|
3
|
+
import { arkModule } from "../utils.js";
|
|
4
4
|
import { regexStringNode } from "./utils.js";
|
|
5
|
-
const
|
|
6
|
-
export const numeric =
|
|
7
|
-
|
|
8
|
-
parse:
|
|
9
|
-
in:
|
|
5
|
+
const root = regexStringNode(wellFormedNumberMatcher, "a well-formed numeric string");
|
|
6
|
+
export const numeric = arkModule({
|
|
7
|
+
root,
|
|
8
|
+
parse: rootSchema({
|
|
9
|
+
in: root,
|
|
10
10
|
morphs: (s) => Number.parseFloat(s),
|
|
11
11
|
declaredOut: intrinsic.number
|
|
12
12
|
})
|
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import { type Constraint, type NodeSchema } from "@ark/schema";
|
|
2
1
|
import type { Module, Submodule } from "../../module.ts";
|
|
3
|
-
import type {
|
|
4
|
-
import type { AtLeastLength, AtMostLength, Branded, Constraints, ExactlyLength, LessThanLength, Matching, MoreThanLength, Narrowed, constrain, normalizePrimitiveConstraintRoot } from "../ast.ts";
|
|
2
|
+
import type { AtLeastLength, AtMostLength, Branded, Constraints, Default, ExactlyLength, LessThanLength, MoreThanLength, Narrowed, Optional, constrain, constraint } from "../inference.ts";
|
|
5
3
|
import { alpha } from "./alpha.ts";
|
|
6
4
|
import { alphanumeric } from "./alphanumeric.ts";
|
|
7
5
|
import { capitalize } from "./capitalize.ts";
|
|
@@ -21,54 +19,57 @@ import { upper } from "./upper.ts";
|
|
|
21
19
|
import { url } from "./url.ts";
|
|
22
20
|
import { uuid } from "./uuid.ts";
|
|
23
21
|
export declare const string: Module<{
|
|
22
|
+
root: unknown;
|
|
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
|
+
alpha: unknown;
|
|
44
|
+
alphanumeric: unknown;
|
|
44
45
|
json: Submodule<stringJson.submodule>;
|
|
45
|
-
|
|
46
|
+
creditCard: unknown;
|
|
46
47
|
integer: Submodule<stringInteger.submodule>;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
date: Submodule<stringDate.submodule>;
|
|
49
|
+
digits: unknown;
|
|
50
|
+
email: unknown;
|
|
51
|
+
ip: Submodule<ip.submodule>;
|
|
50
52
|
numeric: Submodule<stringNumeric.submodule>;
|
|
51
|
-
|
|
52
|
-
|
|
53
|
+
semver: unknown;
|
|
54
|
+
url: Submodule<url.submodule>;
|
|
53
55
|
uuid: Submodule<{
|
|
54
|
-
|
|
55
|
-
v4:
|
|
56
|
-
v6:
|
|
57
|
-
v1:
|
|
58
|
-
v2:
|
|
59
|
-
v3:
|
|
60
|
-
v5:
|
|
61
|
-
v7:
|
|
62
|
-
v8:
|
|
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;
|
|
63
65
|
}>;
|
|
64
|
-
semver: object;
|
|
65
|
-
ip: Submodule<ip.submodule>;
|
|
66
|
-
date: Submodule<stringDate.submodule>;
|
|
67
|
-
capitalize: Submodule<capitalize.submodule>;
|
|
68
|
-
lower: Submodule<lower.submodule>;
|
|
69
66
|
upper: Submodule<upper.submodule>;
|
|
70
|
-
|
|
67
|
+
lower: Submodule<lower.submodule>;
|
|
68
|
+
capitalize: Submodule<capitalize.submodule>;
|
|
71
69
|
}>;
|
|
70
|
+
export type Matching<rule> = {
|
|
71
|
+
matching: constraint<rule>;
|
|
72
|
+
};
|
|
72
73
|
export declare namespace string {
|
|
73
74
|
type atLeastLength<rule> = constrain<string, AtLeastLength<rule>>;
|
|
74
75
|
type moreThanLength<rule> = constrain<string, MoreThanLength<rule>>;
|
|
@@ -77,17 +78,15 @@ export declare namespace string {
|
|
|
77
78
|
type exactlyLength<rule> = constrain<string, ExactlyLength<rule>>;
|
|
78
79
|
type matching<rule> = constrain<string, Matching<rule>>;
|
|
79
80
|
type narrowed = constrain<string, Narrowed>;
|
|
81
|
+
type optional = constrain<string, Optional>;
|
|
82
|
+
type defaultsTo<rule> = constrain<string, Default<rule>>;
|
|
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 Default<infer rule> ? defaultsTo<rule> : 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;
|
|
@@ -100,13 +99,11 @@ export declare namespace string {
|
|
|
100
99
|
ip: ip.submodule;
|
|
101
100
|
json: stringJson.submodule;
|
|
102
101
|
date: stringDate.submodule;
|
|
102
|
+
url: url.submodule;
|
|
103
103
|
trim: trim.submodule;
|
|
104
104
|
normalize: normalize.submodule;
|
|
105
105
|
capitalize: capitalize.submodule;
|
|
106
106
|
lower: lower.submodule;
|
|
107
107
|
upper: upper.submodule;
|
|
108
108
|
};
|
|
109
|
-
type shallowResolutions = {
|
|
110
|
-
[k in keyof $ as `string.${k}`]: $[k] extends type.cast<infer t> ? t : $[k];
|
|
111
|
-
};
|
|
112
109
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
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";
|
|
@@ -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,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type { Branded, constrain, To } from "../
|
|
2
|
+
import type { Branded, constrain, To } from "../inference.ts";
|
|
3
3
|
declare namespace string {
|
|
4
4
|
type trimmed = constrain<string, Branded<"trimmed">>;
|
|
5
5
|
}
|
|
@@ -8,7 +8,7 @@ export declare namespace trim {
|
|
|
8
8
|
type module = Module<submodule>;
|
|
9
9
|
type submodule = Submodule<$>;
|
|
10
10
|
type $ = {
|
|
11
|
-
|
|
11
|
+
root: (In: string) => To<string.trimmed>;
|
|
12
12
|
preformatted: string.trimmed;
|
|
13
13
|
};
|
|
14
14
|
}
|
|
@@ -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,5 +1,5 @@
|
|
|
1
1
|
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type { Branded, constrain, To } from "../
|
|
2
|
+
import type { Branded, constrain, To } from "../inference.ts";
|
|
3
3
|
declare namespace string {
|
|
4
4
|
type uppercase = constrain<string, Branded<"uppercase">>;
|
|
5
5
|
}
|
|
@@ -8,7 +8,7 @@ export declare namespace upper {
|
|
|
8
8
|
type module = Module<submodule>;
|
|
9
9
|
type submodule = Submodule<$>;
|
|
10
10
|
type $ = {
|
|
11
|
-
|
|
11
|
+
root: (In: string) => To<string.uppercase>;
|
|
12
12
|
preformatted: string.uppercase;
|
|
13
13
|
};
|
|
14
14
|
}
|
|
@@ -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,5 +1,5 @@
|
|
|
1
1
|
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type { Branded, constrain, To } from "../
|
|
2
|
+
import type { Branded, constrain, To } from "../inference.ts";
|
|
3
3
|
declare namespace string {
|
|
4
4
|
type url = constrain<string, Branded<"url">>;
|
|
5
5
|
}
|
|
@@ -8,7 +8,7 @@ export declare namespace url {
|
|
|
8
8
|
type module = Module<submodule>;
|
|
9
9
|
type submodule = Submodule<$>;
|
|
10
10
|
type $ = {
|
|
11
|
-
|
|
11
|
+
root: string.url;
|
|
12
12
|
parse: (In: string.url) => To<URL>;
|
|
13
13
|
};
|
|
14
14
|
}
|
|
@@ -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
|
@@ -19,6 +19,17 @@ export declare namespace arkTsKeywords {
|
|
|
19
19
|
undefined: undefined;
|
|
20
20
|
};
|
|
21
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
|
+
}
|
|
22
33
|
declare class RecordHkt extends Hkt<[Key, unknown]> {
|
|
23
34
|
body: Record<this[0], this[1]>;
|
|
24
35
|
}
|
package/out/keywords/ts.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { genericNode, intrinsic } 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,10 @@ 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
|
+
});
|
|
18
22
|
class RecordHkt extends Hkt {
|
|
19
23
|
}
|
|
20
24
|
const Record = genericNode(["K", intrinsic.key], "V")(args => ({
|
|
@@ -42,7 +46,7 @@ const Exclude = genericNode("T", "U")(args => args.T.exclude(args.U), ExcludeHkt
|
|
|
42
46
|
class ExtractHkt extends Hkt {
|
|
43
47
|
}
|
|
44
48
|
const Extract = genericNode("T", "U")(args => args.T.extract(args.U), ExtractHkt);
|
|
45
|
-
export const arkTsGenerics =
|
|
49
|
+
export const arkTsGenerics = arkModule({
|
|
46
50
|
Record,
|
|
47
51
|
Pick,
|
|
48
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 };
|