arktype 2.0.0-rc.3 → 2.0.0-rc.30
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/config.d.ts +1 -1
- package/out/generic.d.ts +55 -58
- package/out/generic.js +6 -8
- package/out/index.d.ts +6 -4
- package/out/index.js +4 -3
- package/out/keywords/{constructors/Array.d.ts → Array.d.ts} +3 -3
- package/out/keywords/{constructors/Array.js → Array.js} +7 -7
- package/out/keywords/{constructors/FormData.d.ts → FormData.d.ts} +3 -3
- package/out/keywords/{constructors/FormData.js → FormData.js} +8 -8
- 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 -2
- package/out/keywords/{constructors/constructors.js → constructors.js} +2 -2
- package/out/keywords/keywords.d.ts +61 -0
- package/out/keywords/keywords.js +29 -0
- package/out/keywords/number.d.ts +23 -0
- package/out/keywords/{number/epoch.js → number.js} +24 -2
- package/out/keywords/string.d.ts +327 -0
- package/out/keywords/string.js +398 -0
- package/out/keywords/ts.d.ts +42 -4
- package/out/keywords/ts.js +24 -7
- package/out/methods/array.d.ts +12 -0
- package/out/methods/base.d.ts +178 -0
- package/out/methods/date.d.ts +10 -0
- package/out/methods/instantiate.d.ts +17 -0
- package/out/methods/morph.d.ts +12 -0
- package/out/methods/number.d.ts +11 -0
- package/out/methods/object.d.ts +106 -0
- package/out/methods/string.d.ts +12 -0
- 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/ast/generic.d.ts +17 -0
- package/out/parser/ast/infer.d.ts +25 -0
- package/out/parser/{semantic → ast}/utils.d.ts +1 -1
- package/out/parser/ast/validate.d.ts +30 -0
- package/out/parser/ast/validate.js +3 -0
- package/out/parser/definition.d.ts +21 -13
- package/out/parser/definition.js +20 -2
- package/out/parser/objectLiteral.d.ts +41 -67
- package/out/parser/objectLiteral.js +79 -71
- package/out/parser/property.d.ts +36 -0
- package/out/parser/property.js +16 -0
- package/out/parser/{string/reduce → reduce}/dynamic.d.ts +10 -13
- 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 +4 -4
- package/out/parser/{string/shift → shift}/operand/date.d.ts +3 -1
- package/out/parser/{string/shift → shift}/operand/enclosed.d.ts +4 -4
- package/out/parser/{string/shift → shift}/operand/enclosed.js +7 -3
- package/out/parser/shift/operand/operand.d.ts +9 -0
- package/out/parser/{string/shift → shift}/operand/operand.js +2 -2
- package/out/parser/{string/shift → shift}/operand/unenclosed.d.ts +15 -7
- package/out/parser/{string/shift → shift}/operand/unenclosed.js +12 -7
- package/out/parser/{string/shift → shift}/operator/bounds.d.ts +7 -7
- package/out/parser/{string/shift → 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/{string/shift → shift}/operator/default.d.ts +4 -6
- package/out/parser/{string/shift → shift}/operator/default.js +4 -6
- package/out/parser/{string/shift → shift}/operator/divisor.d.ts +2 -2
- package/out/parser/shift/operator/operator.d.ts +14 -0
- package/out/parser/{string/shift → shift}/operator/operator.js +7 -5
- package/out/parser/shift/scanner.d.ts +47 -0
- package/out/parser/shift/scanner.js +43 -0
- package/out/parser/{string/string.d.ts → string.d.ts} +9 -9
- package/out/parser/{string/string.js → string.js} +19 -0
- package/out/parser/tupleExpressions.d.ts +47 -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 +41 -34
- package/out/scope.js +54 -62
- package/out/type.d.ts +46 -22
- package/out/type.js +15 -11
- 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/ark.js +0 -24
- package/out/keywords/ast.d.ts +0 -193
- package/out/keywords/ast.js +0 -2
- package/out/keywords/number/epoch.d.ts +0 -10
- 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 -28
- package/out/keywords/number/number.js +0 -9
- 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 -59
- 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 -15
- package/out/keywords/string/json.js +0 -45
- 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 -92
- 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 -112
- 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/parser/semantic/default.d.ts +0 -9
- package/out/parser/semantic/default.js +0 -1
- package/out/parser/semantic/infer.d.ts +0 -39
- package/out/parser/semantic/validate.d.ts +0 -26
- package/out/parser/semantic/validate.js +0 -1
- package/out/parser/string/shift/operand/operand.d.ts +0 -9
- package/out/parser/string/shift/operator/operator.d.ts +0 -13
- package/out/parser/string/shift/scanner.d.ts +0 -69
- package/out/parser/string/shift/scanner.js +0 -100
- package/out/parser/tuple.d.ts +0 -132
- package/out/parser/tuple.js +0 -158
- package/out/subtypes/array.d.ts +0 -13
- package/out/subtypes/base.d.ts +0 -85
- package/out/subtypes/date.d.ts +0 -11
- package/out/subtypes/instantiate.d.ts +0 -16
- package/out/subtypes/morph.d.ts +0 -13
- package/out/subtypes/number.d.ts +0 -12
- package/out/subtypes/object.d.ts +0 -33
- package/out/subtypes/string.d.ts +0 -13
- package/out/subtypes/validator.d.ts +0 -11
- package/out/subtypes/validator.js +0 -1
- /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/parser/{semantic → ast}/bounds.js +0 -0
- /package/out/{intersect.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/{keys.js → parser/ast/generic.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/{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}/operator/divisor.js +0 -0
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type { Branded, constrain } from "../ast.ts";
|
|
3
|
-
declare namespace string {
|
|
4
|
-
type ip = constrain<string, Branded<"ip">>;
|
|
5
|
-
namespace ip {
|
|
6
|
-
type v4 = constrain<string, Branded<"ip.v4">>;
|
|
7
|
-
type v6 = constrain<string, Branded<"ip.v6">>;
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
export declare const ip: ip.module;
|
|
11
|
-
export declare namespace ip {
|
|
12
|
-
type module = Module<submodule>;
|
|
13
|
-
type submodule = Submodule<$>;
|
|
14
|
-
type $ = {
|
|
15
|
-
$root: string.ip;
|
|
16
|
-
v4: string.ip.v4;
|
|
17
|
-
v6: string.ip.v6;
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
export {};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { submodule } from "../utils.js";
|
|
2
|
-
import { regexStringNode } from "./utils.js";
|
|
3
|
-
// Based on https://github.com/validatorjs/validator.js/blob/master/src/lib/isIP.js
|
|
4
|
-
const ipv4Segment = "(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])";
|
|
5
|
-
const ipv4Address = `(${ipv4Segment}[.]){3}${ipv4Segment}`;
|
|
6
|
-
const ipv4Matcher = new RegExp(`^${ipv4Address}$`);
|
|
7
|
-
const ipv6Segment = "(?:[0-9a-fA-F]{1,4})";
|
|
8
|
-
const ipv6Matcher = new RegExp("^(" +
|
|
9
|
-
`(?:${ipv6Segment}:){7}(?:${ipv6Segment}|:)|` +
|
|
10
|
-
`(?:${ipv6Segment}:){6}(?:${ipv4Address}|:${ipv6Segment}|:)|` +
|
|
11
|
-
`(?:${ipv6Segment}:){5}(?::${ipv4Address}|(:${ipv6Segment}){1,2}|:)|` +
|
|
12
|
-
`(?:${ipv6Segment}:){4}(?:(:${ipv6Segment}){0,1}:${ipv4Address}|(:${ipv6Segment}){1,3}|:)|` +
|
|
13
|
-
`(?:${ipv6Segment}:){3}(?:(:${ipv6Segment}){0,2}:${ipv4Address}|(:${ipv6Segment}){1,4}|:)|` +
|
|
14
|
-
`(?:${ipv6Segment}:){2}(?:(:${ipv6Segment}){0,3}:${ipv4Address}|(:${ipv6Segment}){1,5}|:)|` +
|
|
15
|
-
`(?:${ipv6Segment}:){1}(?:(:${ipv6Segment}){0,4}:${ipv4Address}|(:${ipv6Segment}){1,6}|:)|` +
|
|
16
|
-
`(?::((?::${ipv6Segment}){0,5}:${ipv4Address}|(?::${ipv6Segment}){1,7}|:))` +
|
|
17
|
-
")(%[0-9a-zA-Z-.:]{1,})?$");
|
|
18
|
-
// Based on https://github.com/validatorjs/validator.js/blob/master/src/lib/isUUID.js
|
|
19
|
-
export const ip = submodule({
|
|
20
|
-
$root: ["v4 | v6", "@", "an IP address"],
|
|
21
|
-
v4: regexStringNode(ipv4Matcher, "an IPv4 address"),
|
|
22
|
-
v6: regexStringNode(ipv6Matcher, "an IPv6 address")
|
|
23
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type { Branded, To, constrain } from "../ast.ts";
|
|
3
|
-
declare namespace string {
|
|
4
|
-
type json = constrain<string, Branded<"json">>;
|
|
5
|
-
}
|
|
6
|
-
export declare const json: stringJson.module;
|
|
7
|
-
export declare namespace stringJson {
|
|
8
|
-
type module = Module<submodule>;
|
|
9
|
-
type submodule = Submodule<$>;
|
|
10
|
-
type $ = {
|
|
11
|
-
$root: string.json;
|
|
12
|
-
parse: (In: string.json) => To<object>;
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
export {};
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { intrinsic, rootNode } from "@ark/schema";
|
|
2
|
-
import { submodule } from "../utils.js";
|
|
3
|
-
const jsonStringDescription = "a JSON string";
|
|
4
|
-
const isParsableJson = (s) => {
|
|
5
|
-
try {
|
|
6
|
-
JSON.parse(s);
|
|
7
|
-
return true;
|
|
8
|
-
}
|
|
9
|
-
catch {
|
|
10
|
-
return false;
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
const $root = rootNode({
|
|
14
|
-
domain: "string",
|
|
15
|
-
predicate: {
|
|
16
|
-
meta: jsonStringDescription,
|
|
17
|
-
predicate: isParsableJson
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
export const json = submodule({
|
|
21
|
-
$root,
|
|
22
|
-
parse: rootNode({
|
|
23
|
-
in: "string",
|
|
24
|
-
morphs: (s, ctx) => {
|
|
25
|
-
if (s.length === 0) {
|
|
26
|
-
return ctx.error({
|
|
27
|
-
code: "predicate",
|
|
28
|
-
expected: jsonStringDescription,
|
|
29
|
-
actual: "empty"
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
try {
|
|
33
|
-
return JSON.parse(s);
|
|
34
|
-
}
|
|
35
|
-
catch (e) {
|
|
36
|
-
return ctx.error({
|
|
37
|
-
code: "predicate",
|
|
38
|
-
expected: jsonStringDescription,
|
|
39
|
-
problem: `must be ${jsonStringDescription} (${e})`
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
declaredOut: intrinsic.json
|
|
44
|
-
})
|
|
45
|
-
});
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type { Branded, constrain, To } from "../ast.ts";
|
|
3
|
-
declare namespace string {
|
|
4
|
-
type lowercase = constrain<string, Branded<"lowercase">>;
|
|
5
|
-
}
|
|
6
|
-
export declare const lower: lower.module;
|
|
7
|
-
export declare namespace lower {
|
|
8
|
-
type module = Module<submodule>;
|
|
9
|
-
type submodule = Submodule<$>;
|
|
10
|
-
type $ = {
|
|
11
|
-
$root: (In: string) => To<string.lowercase>;
|
|
12
|
-
preformatted: string.lowercase;
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
export {};
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { rootNode } from "@ark/schema";
|
|
2
|
-
import { submodule } from "../utils.js";
|
|
3
|
-
import { regexStringNode } from "./utils.js";
|
|
4
|
-
const preformatted = regexStringNode(/^[a-z]*$/, "only lowercase letters");
|
|
5
|
-
export const lower = submodule({
|
|
6
|
-
$root: rootNode({
|
|
7
|
-
in: "string",
|
|
8
|
-
morphs: (s) => s.toLowerCase(),
|
|
9
|
-
declaredOut: preformatted
|
|
10
|
-
}),
|
|
11
|
-
preformatted
|
|
12
|
-
});
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type { type } from "../ark.ts";
|
|
3
|
-
import type { Branded, constrain, To } from "../ast.ts";
|
|
4
|
-
declare namespace string {
|
|
5
|
-
type normalized = normalized.NFC;
|
|
6
|
-
namespace normalized {
|
|
7
|
-
type NFC = constrain<string, Branded<"normalized.NFC">>;
|
|
8
|
-
type NFD = constrain<string, Branded<"normalized.NFD">>;
|
|
9
|
-
type NFKC = constrain<string, Branded<"normalized.NFKC">>;
|
|
10
|
-
type NFKD = constrain<string, Branded<"normalized.NFKD">>;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
export declare const normalizedForms: readonly ["NFC", "NFD", "NFKC", "NFKD"];
|
|
14
|
-
export type NormalizedForm = (typeof normalizedForms)[number];
|
|
15
|
-
export declare const NFC: Module<{
|
|
16
|
-
$root: object;
|
|
17
|
-
preformatted: object;
|
|
18
|
-
}>;
|
|
19
|
-
export declare const NFD: Module<{
|
|
20
|
-
$root: object;
|
|
21
|
-
preformatted: object;
|
|
22
|
-
}>;
|
|
23
|
-
export declare const NFKC: Module<{
|
|
24
|
-
$root: object;
|
|
25
|
-
preformatted: object;
|
|
26
|
-
}>;
|
|
27
|
-
export declare const NFKD: Module<{
|
|
28
|
-
$root: object;
|
|
29
|
-
preformatted: object;
|
|
30
|
-
}>;
|
|
31
|
-
export declare const normalize: Module<{
|
|
32
|
-
$root: object;
|
|
33
|
-
NFC: Submodule<{
|
|
34
|
-
$root: object;
|
|
35
|
-
preformatted: object;
|
|
36
|
-
}>;
|
|
37
|
-
NFD: Submodule<{
|
|
38
|
-
$root: object;
|
|
39
|
-
preformatted: object;
|
|
40
|
-
}>;
|
|
41
|
-
NFKC: Submodule<{
|
|
42
|
-
$root: object;
|
|
43
|
-
preformatted: object;
|
|
44
|
-
}>;
|
|
45
|
-
NFKD: Submodule<{
|
|
46
|
-
$root: object;
|
|
47
|
-
preformatted: object;
|
|
48
|
-
}>;
|
|
49
|
-
}>;
|
|
50
|
-
export declare namespace normalize {
|
|
51
|
-
type module = Module<submodule>;
|
|
52
|
-
type submodule = Submodule<$>;
|
|
53
|
-
type $ = {
|
|
54
|
-
$root: (In: string) => To<string.normalized.NFC>;
|
|
55
|
-
NFC: NFC.submodule;
|
|
56
|
-
NFD: NFD.submodule;
|
|
57
|
-
NFKC: NFKC.submodule;
|
|
58
|
-
NFKD: NFKD.submodule;
|
|
59
|
-
};
|
|
60
|
-
type shallowResolutions = {
|
|
61
|
-
[k in keyof $ as `string.normalize.${k}`]: $[k] extends type.cast<infer t> ? t : $[k];
|
|
62
|
-
};
|
|
63
|
-
namespace NFC {
|
|
64
|
-
type submodule = Submodule<$>;
|
|
65
|
-
type $ = {
|
|
66
|
-
$root: (In: string) => To<string.normalized.NFC>;
|
|
67
|
-
preformatted: string.normalized.NFC;
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
namespace NFD {
|
|
71
|
-
type submodule = Submodule<$>;
|
|
72
|
-
type $ = {
|
|
73
|
-
$root: (In: string) => To<string.normalized.NFD>;
|
|
74
|
-
preformatted: string.normalized.NFD;
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
namespace NFKC {
|
|
78
|
-
type submodule = Submodule<$>;
|
|
79
|
-
type $ = {
|
|
80
|
-
$root: (In: string) => To<string.normalized.NFKC>;
|
|
81
|
-
preformatted: string.normalized.NFKC;
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
namespace NFKD {
|
|
85
|
-
type submodule = Submodule<$>;
|
|
86
|
-
type $ = {
|
|
87
|
-
$root: (In: string) => To<string.normalized.NFKD>;
|
|
88
|
-
preformatted: string.normalized.NFKD;
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
export {};
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { rootNode } from "@ark/schema";
|
|
2
|
-
import { flatMorph } from "@ark/util";
|
|
3
|
-
import { submodule } from "../utils.js";
|
|
4
|
-
export const normalizedForms = ["NFC", "NFD", "NFKC", "NFKD"];
|
|
5
|
-
const preformattedNodes = flatMorph(normalizedForms, (i, form) => [
|
|
6
|
-
form,
|
|
7
|
-
rootNode({
|
|
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
|
-
rootNode({
|
|
16
|
-
in: "string",
|
|
17
|
-
morphs: (s) => s.normalize(form),
|
|
18
|
-
declaredOut: preformattedNodes[form]
|
|
19
|
-
})
|
|
20
|
-
]);
|
|
21
|
-
export const NFC = submodule({
|
|
22
|
-
$root: normalizeNodes.NFC,
|
|
23
|
-
preformatted: preformattedNodes.NFC
|
|
24
|
-
});
|
|
25
|
-
export const NFD = submodule({
|
|
26
|
-
$root: normalizeNodes.NFD,
|
|
27
|
-
preformatted: preformattedNodes.NFD
|
|
28
|
-
});
|
|
29
|
-
export const NFKC = submodule({
|
|
30
|
-
$root: normalizeNodes.NFKC,
|
|
31
|
-
preformatted: preformattedNodes.NFKC
|
|
32
|
-
});
|
|
33
|
-
export const NFKD = submodule({
|
|
34
|
-
$root: normalizeNodes.NFKD,
|
|
35
|
-
preformatted: preformattedNodes.NFKD
|
|
36
|
-
});
|
|
37
|
-
export const normalize = submodule({
|
|
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 "../ast.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, rootNode } from "@ark/schema";
|
|
2
|
-
import { wellFormedNumberMatcher } from "@ark/util";
|
|
3
|
-
import { submodule } from "../utils.js";
|
|
4
|
-
import { regexStringNode } from "./utils.js";
|
|
5
|
-
const $root = regexStringNode(wellFormedNumberMatcher, "a well-formed numeric string");
|
|
6
|
-
export const numeric = submodule({
|
|
7
|
-
$root,
|
|
8
|
-
parse: rootNode({
|
|
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,112 +0,0 @@
|
|
|
1
|
-
import { type Constraint, type NodeSchema } from "@ark/schema";
|
|
2
|
-
import type { Module, Submodule } from "../../module.ts";
|
|
3
|
-
import type { type } from "../ark.ts";
|
|
4
|
-
import type { AtLeastLength, AtMostLength, Branded, Constraints, ExactlyLength, LessThanLength, Matching, MoreThanLength, Narrowed, constrain, normalizePrimitiveConstraintRoot } from "../ast.ts";
|
|
5
|
-
import { alpha } from "./alpha.ts";
|
|
6
|
-
import { alphanumeric } from "./alphanumeric.ts";
|
|
7
|
-
import { capitalize } from "./capitalize.ts";
|
|
8
|
-
import { creditCard } from "./creditCard.ts";
|
|
9
|
-
import { stringDate } from "./date.ts";
|
|
10
|
-
import { digits } from "./digits.ts";
|
|
11
|
-
import { email } from "./email.ts";
|
|
12
|
-
import { type stringInteger } from "./integer.ts";
|
|
13
|
-
import { ip } from "./ip.ts";
|
|
14
|
-
import { type stringJson } from "./json.ts";
|
|
15
|
-
import { lower } from "./lower.ts";
|
|
16
|
-
import { normalize } from "./normalize.ts";
|
|
17
|
-
import { type stringNumeric } from "./numeric.ts";
|
|
18
|
-
import { semver } from "./semver.ts";
|
|
19
|
-
import { trim } from "./trim.ts";
|
|
20
|
-
import { upper } from "./upper.ts";
|
|
21
|
-
import { url } from "./url.ts";
|
|
22
|
-
import { uuid } from "./uuid.ts";
|
|
23
|
-
export declare const string: Module<{
|
|
24
|
-
trim: Submodule<trim.submodule>;
|
|
25
|
-
normalize: Submodule<{
|
|
26
|
-
$root: object;
|
|
27
|
-
NFC: Submodule<{
|
|
28
|
-
$root: object;
|
|
29
|
-
preformatted: object;
|
|
30
|
-
}>;
|
|
31
|
-
NFD: Submodule<{
|
|
32
|
-
$root: object;
|
|
33
|
-
preformatted: object;
|
|
34
|
-
}>;
|
|
35
|
-
NFKC: Submodule<{
|
|
36
|
-
$root: object;
|
|
37
|
-
preformatted: object;
|
|
38
|
-
}>;
|
|
39
|
-
NFKD: Submodule<{
|
|
40
|
-
$root: object;
|
|
41
|
-
preformatted: object;
|
|
42
|
-
}>;
|
|
43
|
-
}>;
|
|
44
|
-
json: Submodule<stringJson.submodule>;
|
|
45
|
-
$root: object;
|
|
46
|
-
integer: Submodule<stringInteger.submodule>;
|
|
47
|
-
alpha: object;
|
|
48
|
-
alphanumeric: object;
|
|
49
|
-
creditCard: object;
|
|
50
|
-
date: Submodule<stringDate.submodule>;
|
|
51
|
-
digits: object;
|
|
52
|
-
email: object;
|
|
53
|
-
ip: Submodule<ip.submodule>;
|
|
54
|
-
numeric: Submodule<stringNumeric.submodule>;
|
|
55
|
-
semver: object;
|
|
56
|
-
url: Submodule<url.submodule>;
|
|
57
|
-
uuid: Submodule<{
|
|
58
|
-
$root: string.matching<string> | "00000000-0000-0000-0000-000000000000" | "ffffffff-ffff-ffff-ffff-ffffffffffff";
|
|
59
|
-
v4: object;
|
|
60
|
-
v6: object;
|
|
61
|
-
v1: object;
|
|
62
|
-
v2: object;
|
|
63
|
-
v3: object;
|
|
64
|
-
v5: object;
|
|
65
|
-
v7: object;
|
|
66
|
-
v8: object;
|
|
67
|
-
}>;
|
|
68
|
-
upper: Submodule<upper.submodule>;
|
|
69
|
-
lower: Submodule<lower.submodule>;
|
|
70
|
-
capitalize: Submodule<capitalize.submodule>;
|
|
71
|
-
}>;
|
|
72
|
-
export declare namespace string {
|
|
73
|
-
type atLeastLength<rule> = constrain<string, AtLeastLength<rule>>;
|
|
74
|
-
type moreThanLength<rule> = constrain<string, MoreThanLength<rule>>;
|
|
75
|
-
type atMostLength<rule> = constrain<string, AtMostLength<rule>>;
|
|
76
|
-
type lessThanLength<rule> = constrain<string, LessThanLength<rule>>;
|
|
77
|
-
type exactlyLength<rule> = constrain<string, ExactlyLength<rule>>;
|
|
78
|
-
type matching<rule> = constrain<string, Matching<rule>>;
|
|
79
|
-
type narrowed = constrain<string, Narrowed>;
|
|
80
|
-
type branded<rule> = constrain<string, Branded<rule>>;
|
|
81
|
-
type is<constraints extends Constraints> = constrain<string, constraints>;
|
|
82
|
-
type parseConstraint<kind extends Constraint.PrimitiveKind, schema extends NodeSchema<kind>> = normalizePrimitiveConstraintRoot<schema> extends infer rule ? kind extends "minLength" ? schema extends {
|
|
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;
|
|
87
|
-
type module = Module<string.submodule>;
|
|
88
|
-
type submodule = Submodule<$>;
|
|
89
|
-
type $ = {
|
|
90
|
-
$root: string;
|
|
91
|
-
alpha: alpha;
|
|
92
|
-
alphanumeric: alphanumeric;
|
|
93
|
-
digits: digits;
|
|
94
|
-
numeric: stringNumeric.submodule;
|
|
95
|
-
integer: stringInteger.submodule;
|
|
96
|
-
creditCard: creditCard;
|
|
97
|
-
email: email;
|
|
98
|
-
uuid: uuid.submodule;
|
|
99
|
-
semver: semver;
|
|
100
|
-
ip: ip.submodule;
|
|
101
|
-
json: stringJson.submodule;
|
|
102
|
-
date: stringDate.submodule;
|
|
103
|
-
trim: trim.submodule;
|
|
104
|
-
normalize: normalize.submodule;
|
|
105
|
-
capitalize: capitalize.submodule;
|
|
106
|
-
lower: lower.submodule;
|
|
107
|
-
upper: upper.submodule;
|
|
108
|
-
};
|
|
109
|
-
type shallowResolutions = {
|
|
110
|
-
[k in keyof $ as `string.${k}`]: $[k] extends type.cast<infer t> ? t : $[k];
|
|
111
|
-
};
|
|
112
|
-
}
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { intrinsic } from "@ark/schema";
|
|
2
|
-
import { submodule } 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 = submodule({
|
|
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 "../ast.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 { rootNode } from "@ark/schema";
|
|
2
|
-
import { submodule } 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 = submodule({
|
|
8
|
-
$root: rootNode({
|
|
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 "../ast.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 { rootNode } from "@ark/schema";
|
|
2
|
-
import { submodule } from "../utils.js";
|
|
3
|
-
import { regexStringNode } from "./utils.js";
|
|
4
|
-
const preformatted = regexStringNode(/^[A-Z]*$/, "only uppercase letters");
|
|
5
|
-
export const upper = submodule({
|
|
6
|
-
$root: rootNode({
|
|
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 "../ast.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 { rootNode } from "@ark/schema";
|
|
2
|
-
import { submodule } 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 = rootNode({
|
|
16
|
-
domain: "string",
|
|
17
|
-
predicate: {
|
|
18
|
-
meta: "a URL string",
|
|
19
|
-
predicate: isParsableUrl
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
export const url = submodule({
|
|
23
|
-
$root,
|
|
24
|
-
parse: rootNode({
|
|
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: rootNode(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 "../ast.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: object;
|
|
6
|
-
v6: object;
|
|
7
|
-
v1: object;
|
|
8
|
-
v2: object;
|
|
9
|
-
v3: object;
|
|
10
|
-
v5: object;
|
|
11
|
-
v7: object;
|
|
12
|
-
v8: object;
|
|
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 { submodule } 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 = submodule({
|
|
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
|
-
});
|