arktype 2.0.0-rc.9 → 2.0.1
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/attributes.d.ts +94 -0
- package/out/attributes.js +3 -0
- package/out/generic.d.ts +13 -13
- package/out/index.d.ts +3 -1
- package/out/index.js +2 -1
- package/out/keywords/{constructors/Array.d.ts → Array.d.ts} +2 -2
- package/out/keywords/{constructors/Array.js → Array.js} +2 -2
- package/out/keywords/{constructors/FormData.d.ts → FormData.d.ts} +2 -2
- package/out/keywords/{constructors/FormData.js → FormData.js} +2 -2
- package/out/keywords/{constructors/TypedArray.d.ts → TypedArray.d.ts} +1 -1
- package/out/keywords/{constructors/TypedArray.js → TypedArray.js} +2 -2
- package/out/keywords/builtins.js +2 -2
- package/out/keywords/{constructors/constructors.d.ts → constructors.d.ts} +1 -1
- package/out/keywords/{constructors/constructors.js → constructors.js} +2 -2
- package/out/keywords/keywords.d.ts +14 -13
- package/out/keywords/keywords.js +9 -5
- package/out/keywords/number.d.ts +23 -0
- package/out/keywords/{number/epoch.js → number.js} +22 -1
- package/out/keywords/string.d.ts +327 -0
- package/out/keywords/string.js +398 -0
- package/out/keywords/ts.d.ts +31 -4
- package/out/keywords/ts.js +21 -8
- package/out/methods/array.d.ts +6 -7
- package/out/methods/base.d.ts +461 -35
- package/out/methods/date.d.ts +5 -6
- package/out/methods/instantiate.d.ts +4 -4
- package/out/methods/morph.d.ts +6 -6
- package/out/methods/number.d.ts +8 -9
- package/out/methods/object.d.ts +39 -15
- package/out/methods/string.d.ts +9 -10
- package/out/parser/ast/bounds.d.ts +1 -1
- package/out/parser/ast/default.d.ts +2 -2
- package/out/parser/ast/generic.d.ts +17 -0
- package/out/parser/ast/infer.d.ts +8 -22
- package/out/parser/ast/validate.d.ts +13 -9
- package/out/parser/ast/validate.js +3 -1
- package/out/parser/definition.d.ts +17 -8
- package/out/parser/definition.js +38 -3
- package/out/parser/objectLiteral.d.ts +39 -39
- package/out/parser/objectLiteral.js +83 -67
- package/out/parser/property.d.ts +36 -0
- package/out/parser/property.js +16 -0
- package/out/parser/reduce/dynamic.d.ts +8 -9
- package/out/parser/reduce/shared.d.ts +1 -1
- package/out/parser/reduce/static.d.ts +4 -4
- package/out/parser/shift/operand/date.d.ts +1 -1
- package/out/parser/shift/operand/enclosed.d.ts +3 -4
- package/out/parser/shift/operand/operand.d.ts +3 -3
- package/out/parser/shift/operand/operand.js +2 -2
- package/out/parser/shift/operand/unenclosed.d.ts +13 -5
- package/out/parser/shift/operand/unenclosed.js +5 -4
- package/out/parser/shift/operator/bounds.d.ts +5 -5
- package/out/parser/shift/operator/bounds.js +5 -4
- package/out/parser/shift/operator/brand.d.ts +6 -0
- package/out/parser/shift/operator/brand.js +5 -0
- package/out/parser/shift/operator/default.d.ts +3 -2
- package/out/parser/shift/operator/default.js +4 -1
- package/out/parser/shift/operator/divisor.d.ts +2 -2
- package/out/parser/shift/operator/operator.d.ts +4 -3
- package/out/parser/shift/operator/operator.js +7 -5
- package/out/parser/shift/scanner.d.ts +31 -55
- package/out/parser/shift/scanner.js +24 -83
- package/out/parser/string.d.ts +5 -4
- package/out/parser/string.js +18 -1
- package/out/parser/tupleExpressions.d.ts +48 -0
- package/out/parser/tupleExpressions.js +67 -0
- package/out/parser/tupleLiteral.d.ts +95 -0
- package/out/parser/tupleLiteral.js +122 -0
- package/out/scope.d.ts +17 -12
- package/out/scope.js +25 -41
- package/out/type.d.ts +63 -5
- package/out/type.js +3 -2
- package/package.json +8 -8
- package/out/keywords/constructors/Date.d.ts +0 -31
- package/out/keywords/inference.d.ts +0 -220
- package/out/keywords/inference.js +0 -2
- package/out/keywords/number/epoch.d.ts +0 -9
- package/out/keywords/number/integer.d.ts +0 -3
- package/out/keywords/number/integer.js +0 -5
- package/out/keywords/number/number.d.ts +0 -53
- package/out/keywords/number/number.js +0 -21
- package/out/keywords/string/alpha.d.ts +0 -7
- package/out/keywords/string/alpha.js +0 -2
- package/out/keywords/string/alphanumeric.d.ts +0 -7
- package/out/keywords/string/alphanumeric.js +0 -2
- package/out/keywords/string/capitalize.d.ts +0 -15
- package/out/keywords/string/capitalize.js +0 -12
- package/out/keywords/string/creditCard.d.ts +0 -8
- package/out/keywords/string/creditCard.js +0 -37
- package/out/keywords/string/date.d.ts +0 -55
- package/out/keywords/string/date.js +0 -98
- package/out/keywords/string/digits.d.ts +0 -7
- package/out/keywords/string/digits.js +0 -2
- package/out/keywords/string/email.d.ts +0 -7
- package/out/keywords/string/email.js +0 -4
- package/out/keywords/string/integer.d.ts +0 -16
- package/out/keywords/string/integer.js +0 -16
- package/out/keywords/string/ip.d.ts +0 -20
- package/out/keywords/string/ip.js +0 -23
- package/out/keywords/string/json.d.ts +0 -16
- package/out/keywords/string/json.js +0 -53
- package/out/keywords/string/lower.d.ts +0 -15
- package/out/keywords/string/lower.js +0 -12
- package/out/keywords/string/normalize.d.ts +0 -88
- package/out/keywords/string/normalize.js +0 -43
- package/out/keywords/string/numeric.d.ts +0 -15
- package/out/keywords/string/numeric.js +0 -13
- package/out/keywords/string/semver.d.ts +0 -7
- package/out/keywords/string/semver.js +0 -4
- package/out/keywords/string/string.d.ts +0 -108
- package/out/keywords/string/string.js +0 -41
- package/out/keywords/string/trim.d.ts +0 -15
- package/out/keywords/string/trim.js +0 -14
- package/out/keywords/string/upper.d.ts +0 -15
- package/out/keywords/string/upper.js +0 -12
- package/out/keywords/string/url.d.ts +0 -15
- package/out/keywords/string/url.js +0 -37
- package/out/keywords/string/utils.d.ts +0 -2
- package/out/keywords/string/utils.js +0 -10
- package/out/keywords/string/uuid.d.ts +0 -42
- package/out/keywords/string/uuid.js +0 -19
- package/out/keywords/utils.d.ts +0 -1
- package/out/keywords/utils.js +0 -2
- package/out/methods/validator.d.ts +0 -11
- package/out/methods/validator.js +0 -1
- package/out/parser/tuple.d.ts +0 -143
- package/out/parser/tuple.js +0 -164
- /package/out/{keywords/constructors/Date.js → parser/ast/generic.js} +0 -0
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { rootSchema } from "@ark/schema";
|
|
2
|
-
import { flatMorph } from "@ark/util";
|
|
3
|
-
import { arkModule } from "../utils.js";
|
|
4
|
-
export const normalizedForms = ["NFC", "NFD", "NFKC", "NFKD"];
|
|
5
|
-
const preformattedNodes = flatMorph(normalizedForms, (i, form) => [
|
|
6
|
-
form,
|
|
7
|
-
rootSchema({
|
|
8
|
-
domain: "string",
|
|
9
|
-
predicate: (s) => s.normalize(form) === s,
|
|
10
|
-
meta: `${form}-normalized unicode`
|
|
11
|
-
})
|
|
12
|
-
]);
|
|
13
|
-
const normalizeNodes = flatMorph(normalizedForms, (i, form) => [
|
|
14
|
-
form,
|
|
15
|
-
rootSchema({
|
|
16
|
-
in: "string",
|
|
17
|
-
morphs: (s) => s.normalize(form),
|
|
18
|
-
declaredOut: preformattedNodes[form]
|
|
19
|
-
})
|
|
20
|
-
]);
|
|
21
|
-
export const NFC = arkModule({
|
|
22
|
-
root: normalizeNodes.NFC,
|
|
23
|
-
preformatted: preformattedNodes.NFC
|
|
24
|
-
});
|
|
25
|
-
export const NFD = arkModule({
|
|
26
|
-
root: normalizeNodes.NFD,
|
|
27
|
-
preformatted: preformattedNodes.NFD
|
|
28
|
-
});
|
|
29
|
-
export const NFKC = arkModule({
|
|
30
|
-
root: normalizeNodes.NFKC,
|
|
31
|
-
preformatted: preformattedNodes.NFKC
|
|
32
|
-
});
|
|
33
|
-
export const NFKD = arkModule({
|
|
34
|
-
root: normalizeNodes.NFKD,
|
|
35
|
-
preformatted: preformattedNodes.NFKD
|
|
36
|
-
});
|
|
37
|
-
export const normalize = arkModule({
|
|
38
|
-
root: "NFC",
|
|
39
|
-
NFC,
|
|
40
|
-
NFD,
|
|
41
|
-
NFKC,
|
|
42
|
-
NFKD
|
|
43
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type { Branded, constrain, To } from "../inference.ts";
|
|
3
|
-
declare namespace string {
|
|
4
|
-
type numeric = constrain<string, Branded<"numeric">>;
|
|
5
|
-
}
|
|
6
|
-
export declare const numeric: stringNumeric.module;
|
|
7
|
-
export declare namespace stringNumeric {
|
|
8
|
-
type module = Module<submodule>;
|
|
9
|
-
type submodule = Submodule<$>;
|
|
10
|
-
type $ = {
|
|
11
|
-
root: string.numeric;
|
|
12
|
-
parse: (In: string.numeric) => To<number>;
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
export {};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { intrinsic, rootSchema } from "@ark/schema";
|
|
2
|
-
import { wellFormedNumberMatcher } from "@ark/util";
|
|
3
|
-
import { arkModule } from "../utils.js";
|
|
4
|
-
import { regexStringNode } from "./utils.js";
|
|
5
|
-
const root = regexStringNode(wellFormedNumberMatcher, "a well-formed numeric string");
|
|
6
|
-
export const numeric = arkModule({
|
|
7
|
-
root,
|
|
8
|
-
parse: rootSchema({
|
|
9
|
-
in: root,
|
|
10
|
-
morphs: (s) => Number.parseFloat(s),
|
|
11
|
-
declaredOut: intrinsic.number
|
|
12
|
-
})
|
|
13
|
-
});
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { regexStringNode } from "./utils.js";
|
|
2
|
-
// https://semver.org/
|
|
3
|
-
const semverMatcher = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
|
|
4
|
-
export const semver = regexStringNode(semverMatcher, "a semantic version (see https://semver.org/)");
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type { AtLeastLength, AtMostLength, Branded, Constraints, ExactlyLength, LessThanLength, MoreThanLength, Narrowed, Optional, constrain, constraint } from "../inference.ts";
|
|
3
|
-
import { alpha } from "./alpha.ts";
|
|
4
|
-
import { alphanumeric } from "./alphanumeric.ts";
|
|
5
|
-
import { capitalize } from "./capitalize.ts";
|
|
6
|
-
import { creditCard } from "./creditCard.ts";
|
|
7
|
-
import { stringDate } from "./date.ts";
|
|
8
|
-
import { digits } from "./digits.ts";
|
|
9
|
-
import { email } from "./email.ts";
|
|
10
|
-
import { type stringInteger } from "./integer.ts";
|
|
11
|
-
import { ip } from "./ip.ts";
|
|
12
|
-
import { type stringJson } from "./json.ts";
|
|
13
|
-
import { lower } from "./lower.ts";
|
|
14
|
-
import { normalize } from "./normalize.ts";
|
|
15
|
-
import { type stringNumeric } from "./numeric.ts";
|
|
16
|
-
import { semver } from "./semver.ts";
|
|
17
|
-
import { trim } from "./trim.ts";
|
|
18
|
-
import { upper } from "./upper.ts";
|
|
19
|
-
import { url } from "./url.ts";
|
|
20
|
-
import { uuid } from "./uuid.ts";
|
|
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
|
-
};
|
|
73
|
-
export declare namespace string {
|
|
74
|
-
type atLeastLength<rule> = constrain<string, AtLeastLength<rule>>;
|
|
75
|
-
type moreThanLength<rule> = constrain<string, MoreThanLength<rule>>;
|
|
76
|
-
type atMostLength<rule> = constrain<string, AtMostLength<rule>>;
|
|
77
|
-
type lessThanLength<rule> = constrain<string, LessThanLength<rule>>;
|
|
78
|
-
type exactlyLength<rule> = constrain<string, ExactlyLength<rule>>;
|
|
79
|
-
type matching<rule> = constrain<string, Matching<rule>>;
|
|
80
|
-
type narrowed = constrain<string, Narrowed>;
|
|
81
|
-
type optional = constrain<string, Optional>;
|
|
82
|
-
type branded<rule> = constrain<string, Branded<rule>>;
|
|
83
|
-
type is<constraints extends Constraints> = constrain<string, constraints>;
|
|
84
|
-
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;
|
|
85
|
-
type module = Module<string.submodule>;
|
|
86
|
-
type submodule = Submodule<$>;
|
|
87
|
-
type $ = {
|
|
88
|
-
root: string;
|
|
89
|
-
alpha: alpha;
|
|
90
|
-
alphanumeric: alphanumeric;
|
|
91
|
-
digits: digits;
|
|
92
|
-
numeric: stringNumeric.submodule;
|
|
93
|
-
integer: stringInteger.submodule;
|
|
94
|
-
creditCard: creditCard;
|
|
95
|
-
email: email;
|
|
96
|
-
uuid: uuid.submodule;
|
|
97
|
-
semver: semver;
|
|
98
|
-
ip: ip.submodule;
|
|
99
|
-
json: stringJson.submodule;
|
|
100
|
-
date: stringDate.submodule;
|
|
101
|
-
url: url.submodule;
|
|
102
|
-
trim: trim.submodule;
|
|
103
|
-
normalize: normalize.submodule;
|
|
104
|
-
capitalize: capitalize.submodule;
|
|
105
|
-
lower: lower.submodule;
|
|
106
|
-
upper: upper.submodule;
|
|
107
|
-
};
|
|
108
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { intrinsic } from "@ark/schema";
|
|
2
|
-
import { arkModule } from "../utils.js";
|
|
3
|
-
import { alpha } from "./alpha.js";
|
|
4
|
-
import { alphanumeric } from "./alphanumeric.js";
|
|
5
|
-
import { capitalize } from "./capitalize.js";
|
|
6
|
-
import { creditCard } from "./creditCard.js";
|
|
7
|
-
import { stringDate } from "./date.js";
|
|
8
|
-
import { digits } from "./digits.js";
|
|
9
|
-
import { email } from "./email.js";
|
|
10
|
-
import { integer } from "./integer.js";
|
|
11
|
-
import { ip } from "./ip.js";
|
|
12
|
-
import { json } from "./json.js";
|
|
13
|
-
import { lower } from "./lower.js";
|
|
14
|
-
import { normalize } from "./normalize.js";
|
|
15
|
-
import { numeric } from "./numeric.js";
|
|
16
|
-
import { semver } from "./semver.js";
|
|
17
|
-
import { trim } from "./trim.js";
|
|
18
|
-
import { upper } from "./upper.js";
|
|
19
|
-
import { url } from "./url.js";
|
|
20
|
-
import { uuid } from "./uuid.js";
|
|
21
|
-
export const string = arkModule({
|
|
22
|
-
root: intrinsic.string,
|
|
23
|
-
numeric,
|
|
24
|
-
integer,
|
|
25
|
-
alpha,
|
|
26
|
-
alphanumeric,
|
|
27
|
-
digits,
|
|
28
|
-
semver,
|
|
29
|
-
ip,
|
|
30
|
-
creditCard,
|
|
31
|
-
email,
|
|
32
|
-
uuid,
|
|
33
|
-
url,
|
|
34
|
-
json,
|
|
35
|
-
trim,
|
|
36
|
-
upper,
|
|
37
|
-
lower,
|
|
38
|
-
normalize,
|
|
39
|
-
capitalize,
|
|
40
|
-
date: stringDate
|
|
41
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type { Branded, constrain, To } from "../inference.ts";
|
|
3
|
-
declare namespace string {
|
|
4
|
-
type trimmed = constrain<string, Branded<"trimmed">>;
|
|
5
|
-
}
|
|
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
|
-
}
|
|
15
|
-
export {};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { rootSchema } from "@ark/schema";
|
|
2
|
-
import { arkModule } from "../utils.js";
|
|
3
|
-
import { regexStringNode } from "./utils.js";
|
|
4
|
-
const preformatted = regexStringNode(
|
|
5
|
-
// no leading or trailing whitespace
|
|
6
|
-
/^\S.*\S$|^\S?$/, "trimmed");
|
|
7
|
-
export const trim = arkModule({
|
|
8
|
-
root: rootSchema({
|
|
9
|
-
in: "string",
|
|
10
|
-
morphs: (s) => s.trim(),
|
|
11
|
-
declaredOut: preformatted
|
|
12
|
-
}),
|
|
13
|
-
preformatted
|
|
14
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type { Branded, constrain, To } from "../inference.ts";
|
|
3
|
-
declare namespace string {
|
|
4
|
-
type uppercase = constrain<string, Branded<"uppercase">>;
|
|
5
|
-
}
|
|
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
|
-
}
|
|
15
|
-
export {};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { rootSchema } from "@ark/schema";
|
|
2
|
-
import { arkModule } from "../utils.js";
|
|
3
|
-
import { regexStringNode } from "./utils.js";
|
|
4
|
-
const preformatted = regexStringNode(/^[A-Z]*$/, "only uppercase letters");
|
|
5
|
-
export const upper = arkModule({
|
|
6
|
-
root: rootSchema({
|
|
7
|
-
in: "string",
|
|
8
|
-
morphs: (s) => s.toUpperCase(),
|
|
9
|
-
declaredOut: preformatted
|
|
10
|
-
}),
|
|
11
|
-
preformatted
|
|
12
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type { Branded, constrain, To } from "../inference.ts";
|
|
3
|
-
declare namespace string {
|
|
4
|
-
type url = constrain<string, Branded<"url">>;
|
|
5
|
-
}
|
|
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
|
-
}
|
|
15
|
-
export {};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { rootSchema } from "@ark/schema";
|
|
2
|
-
import { arkModule } from "../utils.js";
|
|
3
|
-
const isParsableUrl = (s) => {
|
|
4
|
-
if (URL.canParse)
|
|
5
|
-
return URL.canParse(s);
|
|
6
|
-
// Can be removed once Node 18 is EOL
|
|
7
|
-
try {
|
|
8
|
-
new URL(s);
|
|
9
|
-
return true;
|
|
10
|
-
}
|
|
11
|
-
catch {
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
const root = rootSchema({
|
|
16
|
-
domain: "string",
|
|
17
|
-
predicate: {
|
|
18
|
-
meta: "a URL string",
|
|
19
|
-
predicate: isParsableUrl
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
export const url = arkModule({
|
|
23
|
-
root,
|
|
24
|
-
parse: rootSchema({
|
|
25
|
-
declaredIn: root,
|
|
26
|
-
in: "string",
|
|
27
|
-
morphs: (s, ctx) => {
|
|
28
|
-
try {
|
|
29
|
-
return new URL(s);
|
|
30
|
-
}
|
|
31
|
-
catch {
|
|
32
|
-
return ctx.error("a URL string");
|
|
33
|
-
}
|
|
34
|
-
},
|
|
35
|
-
declaredOut: rootSchema(URL)
|
|
36
|
-
})
|
|
37
|
-
});
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { node } from "@ark/schema";
|
|
2
|
-
// Non-trivial expressions should have an explanation or attribution
|
|
3
|
-
export const regexStringNode = (regex, description) => node("intersection", {
|
|
4
|
-
domain: "string",
|
|
5
|
-
pattern: {
|
|
6
|
-
rule: regex.source,
|
|
7
|
-
flags: regex.flags,
|
|
8
|
-
meta: description
|
|
9
|
-
}
|
|
10
|
-
});
|
|
@@ -1,42 +0,0 @@
|
|
|
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
|
-
}>;
|
|
14
|
-
declare namespace string {
|
|
15
|
-
type uuid = constrain<string, Branded<"uuid">>;
|
|
16
|
-
namespace uuid {
|
|
17
|
-
type v1 = constrain<string, Branded<"uuid.v1">>;
|
|
18
|
-
type v2 = constrain<string, Branded<"uuid.v2">>;
|
|
19
|
-
type v3 = constrain<string, Branded<"uuid.v3">>;
|
|
20
|
-
type v4 = constrain<string, Branded<"uuid.v4">>;
|
|
21
|
-
type v5 = constrain<string, Branded<"uuid.v5">>;
|
|
22
|
-
type v6 = constrain<string, Branded<"uuid.v6">>;
|
|
23
|
-
type v7 = constrain<string, Branded<"uuid.v7">>;
|
|
24
|
-
type v8 = constrain<string, Branded<"uuid.v8">>;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
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
|
-
}
|
|
42
|
-
export {};
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { arkModule } from "../utils.js";
|
|
2
|
-
import { regexStringNode } from "./utils.js";
|
|
3
|
-
// Based on https://github.com/validatorjs/validator.js/blob/master/src/lib/isUUID.js
|
|
4
|
-
export const uuid = arkModule({
|
|
5
|
-
// the meta tuple expression ensures the error message does not delegate
|
|
6
|
-
// to the individual branches, which are too detailed
|
|
7
|
-
root: ["versioned | nil | max", "@", "a UUID"],
|
|
8
|
-
"#nil": "'00000000-0000-0000-0000-000000000000'",
|
|
9
|
-
"#max": "'ffffffff-ffff-ffff-ffff-ffffffffffff'",
|
|
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,
|
|
11
|
-
v1: regexStringNode(/^[0-9a-f]{8}-[0-9a-f]{4}-1[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, "a UUIDv1"),
|
|
12
|
-
v2: regexStringNode(/^[0-9a-f]{8}-[0-9a-f]{4}-2[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, "a UUIDv2"),
|
|
13
|
-
v3: regexStringNode(/^[0-9a-f]{8}-[0-9a-f]{4}-3[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, "a UUIDv3"),
|
|
14
|
-
v4: regexStringNode(/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, "a UUIDv4"),
|
|
15
|
-
v5: regexStringNode(/^[0-9a-f]{8}-[0-9a-f]{4}-5[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, "a UUIDv5"),
|
|
16
|
-
v6: regexStringNode(/^[0-9a-f]{8}-[0-9a-f]{4}-6[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, "a UUIDv6"),
|
|
17
|
-
v7: regexStringNode(/^[0-9a-f]{8}-[0-9a-f]{4}-7[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, "a UUIDv7"),
|
|
18
|
-
v8: regexStringNode(/^[0-9a-f]{8}-[0-9a-f]{4}-8[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i, "a UUIDv8")
|
|
19
|
-
});
|
package/out/keywords/utils.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const arkModule: import("../scope.ts").ModuleParser;
|
package/out/keywords/utils.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { Predicate, PredicateCast } from "@ark/schema";
|
|
2
|
-
import type { applyConstraintSchema } from "../keywords/inference.ts";
|
|
3
|
-
import type { BaseType } from "./base.ts";
|
|
4
|
-
import type { instantiateType } from "./instantiate.ts";
|
|
5
|
-
/** @ts-ignore cast variance */
|
|
6
|
-
interface Type<out t = unknown, $ = {}> extends BaseType<t, $> {
|
|
7
|
-
narrow<narrowed extends this["infer"] = never>(predicate: Predicate<this["infer"]> | PredicateCast<this["infer"], narrowed>): instantiateType<[
|
|
8
|
-
narrowed
|
|
9
|
-
] extends [never] ? applyConstraintSchema<t, "predicate", Predicate> : narrowed, $>;
|
|
10
|
-
}
|
|
11
|
-
export type { Type as ValidatorType };
|
package/out/methods/validator.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/out/parser/tuple.d.ts
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import { type BaseParseContext, type BaseRoot, type MetaSchema, type Morph, type Predicate } from "@ark/schema";
|
|
2
|
-
import { type anyOrNever, type array, type BuiltinObjectKind, type conform, type Constructor, type Domain, type ErrorMessage, type show } from "@ark/util";
|
|
3
|
-
import type { applyConstraint, Default, distill, inferIntersection, inferMorphOut, inferPredicate, InferredOptional, Optional, Out } from "../keywords/inference.ts";
|
|
4
|
-
import type { type } from "../keywords/keywords.ts";
|
|
5
|
-
import type { InfixOperator, PostfixExpression } from "./ast/infer.ts";
|
|
6
|
-
import type { inferDefinition, validateDefinition } from "./definition.ts";
|
|
7
|
-
import { writeMissingRightOperandMessage } from "./shift/operand/unenclosed.ts";
|
|
8
|
-
import type { BaseCompletions } from "./string.ts";
|
|
9
|
-
export declare const parseTuple: (def: array, ctx: BaseParseContext) => BaseRoot;
|
|
10
|
-
export declare const parseTupleLiteral: (def: array, ctx: BaseParseContext) => BaseRoot;
|
|
11
|
-
type InfixExpression = readonly [unknown, InfixOperator, ...unknown[]];
|
|
12
|
-
export type validateTuple<def extends array, $, args> = def extends IndexZeroExpression ? validatePrefixExpression<def, $, args> : def extends PostfixExpression ? validatePostfixExpression<def, $, args> : def extends InfixExpression ? validateInfixExpression<def, $, args> : def extends (readonly ["", ...unknown[]] | readonly [unknown, "", ...unknown[]]) ? readonly [
|
|
13
|
-
def[0] extends "" ? BaseCompletions<$, args, IndexZeroOperator | "..."> : def[0],
|
|
14
|
-
def[1] extends "" ? BaseCompletions<$, args, IndexOneOperator | "..."> : def[1]
|
|
15
|
-
] : validateTupleLiteral<def, $, args>;
|
|
16
|
-
export type validateTupleLiteral<def extends array, $, args> = parseSequence<def, $, args> extends infer s extends SequenceParseState ? Readonly<s["validated"]> : never;
|
|
17
|
-
type inferTupleLiteral<def extends array, $, args> = parseSequence<def, $, args> extends infer s extends SequenceParseState ? s["inferred"] : never;
|
|
18
|
-
type SequenceParseState = {
|
|
19
|
-
unscanned: array;
|
|
20
|
-
inferred: array;
|
|
21
|
-
validated: array;
|
|
22
|
-
includesOptional: boolean;
|
|
23
|
-
};
|
|
24
|
-
type parseSequence<def extends array, $, args> = parseNextElement<{
|
|
25
|
-
unscanned: def;
|
|
26
|
-
inferred: [];
|
|
27
|
-
validated: [];
|
|
28
|
-
includesOptional: false;
|
|
29
|
-
}, $, args>;
|
|
30
|
-
type PreparsedElement = {
|
|
31
|
-
head: unknown;
|
|
32
|
-
tail: array;
|
|
33
|
-
inferred: unknown;
|
|
34
|
-
optional: boolean;
|
|
35
|
-
spread: boolean;
|
|
36
|
-
};
|
|
37
|
-
declare namespace PreparsedElement {
|
|
38
|
-
type from<result extends PreparsedElement> = result;
|
|
39
|
-
}
|
|
40
|
-
type preparseNextElement<s extends SequenceParseState, $, args> = s["unscanned"] extends readonly ["...", infer head, ...infer tail] ? inferDefinition<head, $, args> extends infer t ? [
|
|
41
|
-
t
|
|
42
|
-
] extends [anyOrNever] ? PreparsedElement.from<{
|
|
43
|
-
head: head;
|
|
44
|
-
tail: tail;
|
|
45
|
-
inferred: t;
|
|
46
|
-
optional: false;
|
|
47
|
-
spread: true;
|
|
48
|
-
}> : [t] extends [InferredOptional<infer base>] ? PreparsedElement.from<{
|
|
49
|
-
head: head;
|
|
50
|
-
tail: tail;
|
|
51
|
-
inferred: base;
|
|
52
|
-
optional: true;
|
|
53
|
-
spread: true;
|
|
54
|
-
}> : PreparsedElement.from<{
|
|
55
|
-
head: head;
|
|
56
|
-
tail: tail;
|
|
57
|
-
inferred: t;
|
|
58
|
-
optional: false;
|
|
59
|
-
spread: true;
|
|
60
|
-
}> : never : s["unscanned"] extends readonly [infer head, ...infer tail] ? inferDefinition<head, $, args> extends infer t ? [
|
|
61
|
-
t
|
|
62
|
-
] extends [anyOrNever] ? PreparsedElement.from<{
|
|
63
|
-
head: head;
|
|
64
|
-
tail: tail;
|
|
65
|
-
inferred: t;
|
|
66
|
-
optional: false;
|
|
67
|
-
spread: false;
|
|
68
|
-
}> : [t] extends [InferredOptional<infer base>] ? PreparsedElement.from<{
|
|
69
|
-
head: head;
|
|
70
|
-
tail: tail;
|
|
71
|
-
inferred: base;
|
|
72
|
-
optional: true;
|
|
73
|
-
spread: false;
|
|
74
|
-
}> : PreparsedElement.from<{
|
|
75
|
-
head: head;
|
|
76
|
-
tail: tail;
|
|
77
|
-
inferred: t;
|
|
78
|
-
optional: false;
|
|
79
|
-
spread: false;
|
|
80
|
-
}> : never : null;
|
|
81
|
-
type parseNextElement<s extends SequenceParseState, $, args> = preparseNextElement<s, $, args> extends infer next extends PreparsedElement ? parseNextElement<{
|
|
82
|
-
unscanned: next["tail"];
|
|
83
|
-
inferred: next["spread"] extends true ? [
|
|
84
|
-
...s["inferred"],
|
|
85
|
-
...conform<next["inferred"], array>
|
|
86
|
-
] : next["optional"] extends true ? [...s["inferred"], next["inferred"]?] : [...s["inferred"], next["inferred"]];
|
|
87
|
-
validated: [
|
|
88
|
-
...s["validated"],
|
|
89
|
-
...(next["spread"] extends true ? [
|
|
90
|
-
next["inferred"] extends infer spreadOperand extends array ? [
|
|
91
|
-
number,
|
|
92
|
-
number
|
|
93
|
-
] extends ([
|
|
94
|
-
s["inferred"]["length"],
|
|
95
|
-
spreadOperand["length"]
|
|
96
|
-
]) ? ErrorMessage<multipleVariadicMessage> : "..." : ErrorMessage<writeNonArraySpreadMessage<next["head"]>>
|
|
97
|
-
] : []),
|
|
98
|
-
next["optional"] extends true ? next["spread"] extends true ? ErrorMessage<spreadOptionalMessage> : number extends s["inferred"]["length"] ? ErrorMessage<optionalPostVariadicMessage> : validateDefinition<next["head"], $, args> : [s["includesOptional"], next["spread"]] extends [true, false] ? ErrorMessage<requiredPostOptionalMessage> : validateDefinition<next["head"], $, args>
|
|
99
|
-
];
|
|
100
|
-
includesOptional: s["includesOptional"] | next["optional"] extends (false) ? false : true;
|
|
101
|
-
}, $, args> : s;
|
|
102
|
-
export declare const writeNonArraySpreadMessage: <operand extends string>(operand: operand) => writeNonArraySpreadMessage<operand>;
|
|
103
|
-
type writeNonArraySpreadMessage<operand> = `Spread element must be an array${operand extends string ? ` (was ${operand})` : ""}`;
|
|
104
|
-
export declare const multipleVariadicMesage = "A tuple may have at most one variadic element";
|
|
105
|
-
type multipleVariadicMessage = typeof multipleVariadicMesage;
|
|
106
|
-
export declare const requiredPostOptionalMessage = "A required element may not follow an optional element";
|
|
107
|
-
type requiredPostOptionalMessage = typeof requiredPostOptionalMessage;
|
|
108
|
-
export declare const optionalPostVariadicMessage = "An optional element may not follow a variadic element";
|
|
109
|
-
type optionalPostVariadicMessage = typeof optionalPostVariadicMessage;
|
|
110
|
-
export declare const spreadOptionalMessage = "A spread element cannot be optional";
|
|
111
|
-
type spreadOptionalMessage = typeof optionalPostVariadicMessage;
|
|
112
|
-
export type inferTuple<def extends array, $, args> = def extends TupleExpression ? inferTupleExpression<def, $, args> : inferTupleLiteral<def, $, args>;
|
|
113
|
-
export type inferTupleExpression<def extends TupleExpression, $, args> = def[1] extends "[]" ? inferDefinition<def[0], $, args>[] : def[1] extends "&" ? inferIntersection<inferDefinition<def[0], $, args>, inferDefinition<def[2], $, args>> : def[1] extends "|" ? inferDefinition<def[0], $, args> | inferDefinition<def[2], $, args> : def[1] extends ":" ? inferPredicate<inferDefinition<def[0], $, args>, def[2]> : def[1] extends "=>" ? parseMorph<def[0], def[2], $, args> : def[1] extends "@" ? inferDefinition<def[0], $, args> : def[1] extends "=" ? (In?: inferDefinition<def[0], $, args>) => Default<def[2]> : def[1] extends "?" ? applyConstraint<inferDefinition<def[0], $, args>, Optional> : def extends readonly ["===", ...infer values] ? values[number] : def extends (readonly ["instanceof", ...infer constructors extends Constructor[]]) ? InstanceType<constructors[number]> : def[0] extends "keyof" ? inferKeyOfExpression<def[1], $, args> : never;
|
|
114
|
-
export type validatePrefixExpression<def extends IndexZeroExpression, $, args> = def["length"] extends 1 ? readonly [writeMissingRightOperandMessage<def[0]>] : def[0] extends "keyof" ? readonly [def[0], validateDefinition<def[1], $, args>] : def[0] extends "===" ? readonly [def[0], ...unknown[]] : def[0] extends "instanceof" ? readonly [def[0], ...Constructor[]] : never;
|
|
115
|
-
export type validatePostfixExpression<def extends PostfixExpression, $, args> = conform<def, readonly [validateDefinition<def[0], $, args>, "[]" | "?"]>;
|
|
116
|
-
export type validateInfixExpression<def extends InfixExpression, $, args> = def["length"] extends 2 ? readonly [def[0], writeMissingRightOperandMessage<def[1]>] : readonly [
|
|
117
|
-
validateDefinition<def[0], $, args>,
|
|
118
|
-
def[1],
|
|
119
|
-
def[1] extends "|" ? validateDefinition<def[2], $, args> : def[1] extends "&" ? validateDefinition<def[2], $, args> : def[1] extends ":" ? Predicate<type.infer.Out<def[0], $, args>> : def[1] extends "=>" ? Morph<type.infer.Out<def[0], $, args>> : def[1] extends "@" ? MetaSchema : def[1] extends "=" ? type.infer.Out<def[0], $, args> : validateDefinition<def[2], $, args>
|
|
120
|
-
];
|
|
121
|
-
export type UnparsedTupleExpressionInput = {
|
|
122
|
-
instanceof: Constructor;
|
|
123
|
-
"===": unknown;
|
|
124
|
-
};
|
|
125
|
-
export type UnparsedTupleOperator = show<keyof UnparsedTupleExpressionInput>;
|
|
126
|
-
export declare const parseKeyOfTuple: PrefixParser<"keyof">;
|
|
127
|
-
export type inferKeyOfExpression<operandDef, $, args> = show<keyof inferDefinition<operandDef, $, args>>;
|
|
128
|
-
export type IndexOneParser<token extends IndexOneOperator> = (def: IndexOneExpression<token>, ctx: BaseParseContext) => BaseRoot;
|
|
129
|
-
export type PrefixParser<token extends IndexZeroOperator> = (def: IndexZeroExpression<token>, ctx: BaseParseContext) => BaseRoot;
|
|
130
|
-
export type TupleExpression = IndexZeroExpression | IndexOneExpression;
|
|
131
|
-
export type TupleExpressionOperator = IndexZeroOperator | IndexOneOperator;
|
|
132
|
-
export type IndexOneOperator = TuplePostfixOperator | TupleInfixOperator;
|
|
133
|
-
export type TuplePostfixOperator = "[]" | "?";
|
|
134
|
-
export type TupleInfixOperator = "&" | "|" | "=>" | ":" | "@" | "=";
|
|
135
|
-
export type IndexOneExpression<token extends IndexOneOperator = IndexOneOperator> = readonly [unknown, token, ...unknown[]];
|
|
136
|
-
export declare const parseMorphTuple: IndexOneParser<"=>">;
|
|
137
|
-
export declare const writeMalformedFunctionalExpressionMessage: (operator: ":" | "=>", value: unknown) => string;
|
|
138
|
-
export type parseMorph<inDef, morph, $, args> = morph extends Morph ? inferMorphOut<morph> extends infer out ? (In: distill.brandable.In<inferDefinition<inDef, $, args>>) => Out<out> : never : never;
|
|
139
|
-
export declare const parseNarrowTuple: IndexOneParser<":">;
|
|
140
|
-
export type IndexZeroOperator = "keyof" | "instanceof" | "===";
|
|
141
|
-
export type IndexZeroExpression<token extends IndexZeroOperator = IndexZeroOperator> = readonly [token, ...unknown[]];
|
|
142
|
-
export declare const writeInvalidConstructorMessage: <actual extends Domain | BuiltinObjectKind>(actual: actual) => string;
|
|
143
|
-
export {};
|