arktype 2.0.0-rc.5 → 2.0.0-rc.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/out/generic.d.ts +39 -42
- package/out/generic.js +3 -5
- package/out/index.d.ts +2 -2
- package/out/intersect.d.ts +2 -4
- package/out/keys.d.ts +5 -3
- package/out/keywords/ark.d.ts +8 -6
- package/out/keywords/ark.js +4 -2
- package/out/keywords/ast.d.ts +33 -21
- package/out/keywords/builtins.js +2 -2
- package/out/keywords/constructors/Array.js +5 -5
- package/out/keywords/constructors/FormData.js +7 -7
- 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/number/epoch.js +2 -2
- package/out/keywords/number/integer.js +2 -2
- package/out/keywords/number/number.d.ts +8 -0
- package/out/keywords/number/number.js +16 -4
- package/out/keywords/string/capitalize.js +4 -4
- package/out/keywords/string/creditCard.js +2 -2
- package/out/keywords/string/date.d.ts +0 -4
- package/out/keywords/string/date.js +9 -9
- package/out/keywords/string/integer.js +4 -4
- package/out/keywords/string/ip.js +4 -4
- package/out/keywords/string/json.js +5 -5
- package/out/keywords/string/lower.js +4 -4
- package/out/keywords/string/normalize.d.ts +0 -4
- package/out/keywords/string/normalize.js +9 -9
- package/out/keywords/string/numeric.js +4 -4
- package/out/keywords/string/string.d.ts +2 -5
- package/out/keywords/string/string.js +2 -2
- package/out/keywords/string/trim.js +4 -4
- package/out/keywords/string/upper.js +4 -4
- package/out/keywords/string/url.js +6 -6
- package/out/keywords/string/uuid.js +2 -2
- 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/methods/base.d.ts +18 -15
- package/out/methods/morph.d.ts +3 -3
- package/out/methods/object.d.ts +32 -8
- package/out/parser/definition.d.ts +2 -3
- package/out/parser/objectLiteral.d.ts +4 -5
- package/out/parser/objectLiteral.js +4 -4
- package/out/parser/semantic/default.d.ts +2 -2
- package/out/parser/semantic/infer.d.ts +3 -2
- package/out/parser/string/reduce/dynamic.d.ts +3 -4
- package/out/parser/string/reduce/dynamic.js +3 -2
- package/out/parser/string/shift/operand/enclosed.js +7 -3
- package/out/parser/string/shift/operand/unenclosed.js +6 -2
- package/out/parser/tuple.d.ts +5 -6
- package/out/parser/tuple.js +29 -20
- package/out/scope.d.ts +21 -23
- package/out/scope.js +33 -26
- package/out/type.d.ts +12 -12
- package/out/type.js +9 -9
- package/package.json +3 -3
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ArkErrors, intrinsic,
|
|
1
|
+
import { ArkErrors, intrinsic, rootSchema } from "@ark/schema";
|
|
2
2
|
import { number } from "../number/number.js";
|
|
3
|
-
import {
|
|
3
|
+
import { arkModule } from "../utils.js";
|
|
4
4
|
import { integer } from "./integer.js";
|
|
5
5
|
import { regexStringNode } from "./utils.js";
|
|
6
6
|
const dayDelimiterMatcher = /^[./-]$/;
|
|
@@ -40,7 +40,7 @@ export const tryParseDatePattern = (data, opts) => {
|
|
|
40
40
|
return writeFormattedExpected(opts.format);
|
|
41
41
|
};
|
|
42
42
|
const isParsableDate = (s) => !Number.isNaN(new Date(s).valueOf());
|
|
43
|
-
const parsableDate =
|
|
43
|
+
const parsableDate = rootSchema({
|
|
44
44
|
domain: "string",
|
|
45
45
|
predicate: {
|
|
46
46
|
meta: "a parsable date",
|
|
@@ -63,26 +63,26 @@ const epochroot = integer.root.internal
|
|
|
63
63
|
description: "an integer string representing a safe Unix timestamp"
|
|
64
64
|
})
|
|
65
65
|
.assertHasKind("intersection");
|
|
66
|
-
const epoch =
|
|
66
|
+
const epoch = arkModule({
|
|
67
67
|
root: epochroot,
|
|
68
|
-
parse:
|
|
68
|
+
parse: rootSchema({
|
|
69
69
|
in: epochroot,
|
|
70
70
|
morphs: (s) => new Date(s),
|
|
71
71
|
declaredOut: intrinsic.Date
|
|
72
72
|
})
|
|
73
73
|
});
|
|
74
74
|
const isoroot = regexStringNode(iso8601Matcher, "an ISO 8601 (YYYY-MM-DDTHH:mm:ss.sssZ) date").internal.assertHasKind("intersection");
|
|
75
|
-
const iso =
|
|
75
|
+
const iso = arkModule({
|
|
76
76
|
root: isoroot,
|
|
77
|
-
parse:
|
|
77
|
+
parse: rootSchema({
|
|
78
78
|
in: isoroot,
|
|
79
79
|
morphs: (s) => new Date(s),
|
|
80
80
|
declaredOut: intrinsic.Date
|
|
81
81
|
})
|
|
82
82
|
});
|
|
83
|
-
export const stringDate =
|
|
83
|
+
export const stringDate = arkModule({
|
|
84
84
|
root: parsableDate,
|
|
85
|
-
parse:
|
|
85
|
+
parse: rootSchema({
|
|
86
86
|
declaredIn: parsableDate,
|
|
87
87
|
in: "string",
|
|
88
88
|
morphs: (s, ctx) => {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { intrinsic,
|
|
1
|
+
import { intrinsic, rootSchema } from "@ark/schema";
|
|
2
2
|
import { wellFormedIntegerMatcher } from "@ark/util";
|
|
3
|
-
import {
|
|
3
|
+
import { arkModule } from "../utils.js";
|
|
4
4
|
import { regexStringNode } from "./utils.js";
|
|
5
5
|
const root = regexStringNode(wellFormedIntegerMatcher, "a well-formed integer string");
|
|
6
|
-
export const integer =
|
|
6
|
+
export const integer = arkModule({
|
|
7
7
|
root,
|
|
8
|
-
parse:
|
|
8
|
+
parse: rootSchema({
|
|
9
9
|
in: root,
|
|
10
10
|
morphs: (s, ctx) => {
|
|
11
11
|
const parsed = Number.parseInt(s);
|
|
@@ -1,6 +1,7 @@
|
|
|
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/isIP.js
|
|
4
|
+
// Adjusted to incorporate unmerged fix in https://github.com/validatorjs/validator.js/pull/2083
|
|
4
5
|
const ipv4Segment = "(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])";
|
|
5
6
|
const ipv4Address = `(${ipv4Segment}[.]){3}${ipv4Segment}`;
|
|
6
7
|
const ipv4Matcher = new RegExp(`^${ipv4Address}$`);
|
|
@@ -14,9 +15,8 @@ const ipv6Matcher = new RegExp("^(" +
|
|
|
14
15
|
`(?:${ipv6Segment}:){2}(?:(:${ipv6Segment}){0,3}:${ipv4Address}|(:${ipv6Segment}){1,5}|:)|` +
|
|
15
16
|
`(?:${ipv6Segment}:){1}(?:(:${ipv6Segment}){0,4}:${ipv4Address}|(:${ipv6Segment}){1,6}|:)|` +
|
|
16
17
|
`(?::((?::${ipv6Segment}){0,5}:${ipv4Address}|(?::${ipv6Segment}){1,7}|:))` +
|
|
17
|
-
")(%[0-9a-zA-Z
|
|
18
|
-
|
|
19
|
-
export const ip = submodule({
|
|
18
|
+
")(%[0-9a-zA-Z.]{1,})?$");
|
|
19
|
+
export const ip = arkModule({
|
|
20
20
|
root: ["v4 | v6", "@", "an IP address"],
|
|
21
21
|
v4: regexStringNode(ipv4Matcher, "an IPv4 address"),
|
|
22
22
|
v6: regexStringNode(ipv6Matcher, "an IPv6 address")
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { intrinsic,
|
|
2
|
-
import {
|
|
1
|
+
import { intrinsic, rootSchema } from "@ark/schema";
|
|
2
|
+
import { arkModule } from "../utils.js";
|
|
3
3
|
const jsonStringDescription = "a JSON string";
|
|
4
4
|
const isParsableJson = (s) => {
|
|
5
5
|
try {
|
|
@@ -10,16 +10,16 @@ const isParsableJson = (s) => {
|
|
|
10
10
|
return false;
|
|
11
11
|
}
|
|
12
12
|
};
|
|
13
|
-
const root =
|
|
13
|
+
const root = rootSchema({
|
|
14
14
|
domain: "string",
|
|
15
15
|
predicate: {
|
|
16
16
|
meta: jsonStringDescription,
|
|
17
17
|
predicate: isParsableJson
|
|
18
18
|
}
|
|
19
19
|
});
|
|
20
|
-
export const json =
|
|
20
|
+
export const json = arkModule({
|
|
21
21
|
root,
|
|
22
|
-
parse:
|
|
22
|
+
parse: rootSchema({
|
|
23
23
|
in: "string",
|
|
24
24
|
morphs: (s, ctx) => {
|
|
25
25
|
if (s.length === 0) {
|
|
@@ -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 lowercase letters");
|
|
5
|
-
export const lower =
|
|
6
|
-
root:
|
|
5
|
+
export const lower = arkModule({
|
|
6
|
+
root: rootSchema({
|
|
7
7
|
in: "string",
|
|
8
8
|
morphs: (s) => s.toLowerCase(),
|
|
9
9
|
declaredOut: preformatted
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type { type } from "../ark.ts";
|
|
3
2
|
import type { Branded, constrain, To } from "../ast.ts";
|
|
4
3
|
declare namespace string {
|
|
5
4
|
type normalized = normalized.NFC;
|
|
@@ -57,9 +56,6 @@ export declare namespace normalize {
|
|
|
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 $ = {
|
|
@@ -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,29 +12,29 @@ 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 =
|
|
21
|
+
export const NFC = arkModule({
|
|
22
22
|
root: normalizeNodes.NFC,
|
|
23
23
|
preformatted: preformattedNodes.NFC
|
|
24
24
|
});
|
|
25
|
-
export const NFD =
|
|
25
|
+
export const NFD = arkModule({
|
|
26
26
|
root: normalizeNodes.NFD,
|
|
27
27
|
preformatted: preformattedNodes.NFD
|
|
28
28
|
});
|
|
29
|
-
export const NFKC =
|
|
29
|
+
export const NFKC = arkModule({
|
|
30
30
|
root: normalizeNodes.NFKC,
|
|
31
31
|
preformatted: preformattedNodes.NFKC
|
|
32
32
|
});
|
|
33
|
-
export const NFKD =
|
|
33
|
+
export const NFKD = arkModule({
|
|
34
34
|
root: normalizeNodes.NFKD,
|
|
35
35
|
preformatted: preformattedNodes.NFKD
|
|
36
36
|
});
|
|
37
|
-
export const normalize =
|
|
37
|
+
export const normalize = arkModule({
|
|
38
38
|
root: "NFC",
|
|
39
39
|
NFC,
|
|
40
40
|
NFD,
|
|
@@ -1,11 +1,11 @@
|
|
|
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
5
|
const root = regexStringNode(wellFormedNumberMatcher, "a well-formed numeric string");
|
|
6
|
-
export const numeric =
|
|
6
|
+
export const numeric = arkModule({
|
|
7
7
|
root,
|
|
8
|
-
parse:
|
|
8
|
+
parse: rootSchema({
|
|
9
9
|
in: root,
|
|
10
10
|
morphs: (s) => Number.parseFloat(s),
|
|
11
11
|
declaredOut: intrinsic.number
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { Module, Submodule } from "../../module.ts";
|
|
2
|
-
import type { type } from "../ark.ts";
|
|
3
2
|
import type { AtLeastLength, AtMostLength, Branded, Constraints, ExactlyLength, LessThanLength, MoreThanLength, Narrowed, Optional, constrain, constraint } from "../ast.ts";
|
|
4
3
|
import { alpha } from "./alpha.ts";
|
|
5
4
|
import { alphanumeric } from "./alphanumeric.ts";
|
|
@@ -44,8 +43,8 @@ export declare const string: Module<{
|
|
|
44
43
|
date: Submodule<stringDate.submodule>;
|
|
45
44
|
lower: Submodule<lower.submodule>;
|
|
46
45
|
upper: Submodule<upper.submodule>;
|
|
47
|
-
json: Submodule<stringJson.submodule>;
|
|
48
46
|
integer: Submodule<stringInteger.submodule>;
|
|
47
|
+
json: Submodule<stringJson.submodule>;
|
|
49
48
|
alpha: unknown;
|
|
50
49
|
alphanumeric: unknown;
|
|
51
50
|
creditCard: unknown;
|
|
@@ -99,13 +98,11 @@ export declare namespace string {
|
|
|
99
98
|
ip: ip.submodule;
|
|
100
99
|
json: stringJson.submodule;
|
|
101
100
|
date: stringDate.submodule;
|
|
101
|
+
url: url.submodule;
|
|
102
102
|
trim: trim.submodule;
|
|
103
103
|
normalize: normalize.submodule;
|
|
104
104
|
capitalize: capitalize.submodule;
|
|
105
105
|
lower: lower.submodule;
|
|
106
106
|
upper: upper.submodule;
|
|
107
107
|
};
|
|
108
|
-
type shallowResolutions = {
|
|
109
|
-
[k in keyof $ as `string.${k}`]: $[k] extends type.cast<infer t> ? t : $[k];
|
|
110
|
-
};
|
|
111
108
|
}
|
|
@@ -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,7 +18,7 @@ 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 =
|
|
21
|
+
export const string = arkModule({
|
|
22
22
|
root: intrinsic.string,
|
|
23
23
|
numeric,
|
|
24
24
|
integer,
|
|
@@ -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
|
-
root:
|
|
7
|
+
export const trim = arkModule({
|
|
8
|
+
root: rootSchema({
|
|
9
9
|
in: "string",
|
|
10
10
|
morphs: (s) => s.trim(),
|
|
11
11
|
declaredOut: preformatted
|
|
@@ -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
|
-
root:
|
|
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
|
-
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,16 +12,16 @@ const isParsableUrl = (s) => {
|
|
|
12
12
|
return false;
|
|
13
13
|
}
|
|
14
14
|
};
|
|
15
|
-
const root =
|
|
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 =
|
|
22
|
+
export const url = arkModule({
|
|
23
23
|
root,
|
|
24
|
-
parse:
|
|
24
|
+
parse: rootSchema({
|
|
25
25
|
declaredIn: root,
|
|
26
26
|
in: "string",
|
|
27
27
|
morphs: (s, ctx) => {
|
|
@@ -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,7 +1,7 @@
|
|
|
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"],
|
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;
|
package/out/methods/base.d.ts
CHANGED
|
@@ -1,21 +1,24 @@
|
|
|
1
1
|
import type { ArkErrors, BaseRoot, Disjoint, JsonSchema, MetaSchema, Morph, UndeclaredKeyBehavior } from "@ark/schema";
|
|
2
2
|
import type { anyOrNever, array, Callable, ErrorMessage, inferred, Json, unset } from "@ark/util";
|
|
3
|
+
import type { ArkAmbient } from "../config.ts";
|
|
3
4
|
import type { inferIntersection } from "../intersect.ts";
|
|
5
|
+
import type { type } from "../keywords/ark.ts";
|
|
4
6
|
import type { applyConstraint, Default, distill, inferMorphOut, inferPipes, Optional } from "../keywords/ast.ts";
|
|
5
7
|
import type { Scope } from "../scope.ts";
|
|
6
|
-
import type { inferTypeRoot, validateTypeRoot } from "../type.ts";
|
|
7
8
|
import type { ArrayType } from "./array.ts";
|
|
8
9
|
import type { instantiateType } from "./instantiate.ts";
|
|
9
10
|
/** @ts-ignore cast variance */
|
|
10
11
|
interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => distill.Out<t> | ArkErrors> {
|
|
11
12
|
t: t;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
inferBrandableIn: distill.brandable.In<t>;
|
|
14
|
+
inferBrandableOut: distill.brandable.Out<t>;
|
|
15
|
+
inferIntrospectableOut: distill.introspectable.Out<t>;
|
|
15
16
|
infer: distill.Out<t>;
|
|
16
17
|
inferIn: distill.In<t>;
|
|
17
18
|
[inferred]: t;
|
|
18
19
|
json: Json;
|
|
20
|
+
meta: ArkAmbient.meta;
|
|
21
|
+
precompilation: string | undefined;
|
|
19
22
|
toJsonSchema(): JsonSchema;
|
|
20
23
|
description: string;
|
|
21
24
|
expression: string;
|
|
@@ -27,23 +30,23 @@ interface Type<out t = unknown, $ = {}> extends Callable<(data: unknown) => dist
|
|
|
27
30
|
configure(meta: MetaSchema): this;
|
|
28
31
|
describe(description: string): this;
|
|
29
32
|
optional<r = applyConstraint<t, Optional>>(): instantiateType<r, $>;
|
|
30
|
-
default<value extends this["infer"], r = (In?: this["
|
|
33
|
+
default<value extends this["infer"], r = (In?: this["inferBrandableIn"]) => Default<value>>(value: value): instantiateType<r, $>;
|
|
31
34
|
onUndeclaredKey(behavior: UndeclaredKeyBehavior): this;
|
|
32
35
|
onDeepUndeclaredKey(behavior: UndeclaredKeyBehavior): this;
|
|
33
36
|
from(literal: this["inferIn"]): this["infer"];
|
|
34
37
|
as<t = unset>(...args: validateChainedAsArgs<t>): instantiateType<t, $>;
|
|
35
|
-
get in(): instantiateType<this["
|
|
36
|
-
get out(): instantiateType<this["
|
|
37
|
-
intersect<const def, r =
|
|
38
|
-
and<const def, r =
|
|
39
|
-
or<const def, r =
|
|
38
|
+
get in(): instantiateType<this["inferBrandableIn"], $>;
|
|
39
|
+
get out(): instantiateType<this["inferIntrospectableOut"], $>;
|
|
40
|
+
intersect<const def, r = type.infer<def, $>>(def: type.validate<def, $>): instantiateType<inferIntersection<t, r>, $> | Disjoint;
|
|
41
|
+
and<const def, r = type.infer<def, $>>(def: type.validate<def, $>): instantiateType<inferIntersection<t, r>, $>;
|
|
42
|
+
or<const def, r = type.infer<def, $>>(def: type.validate<def, $>): instantiateType<t | r, $>;
|
|
40
43
|
array(): ArrayType<t[], $>;
|
|
41
44
|
pipe: ChainedPipes<t, $>;
|
|
42
|
-
equals<def>(def:
|
|
43
|
-
extract<def>(r:
|
|
44
|
-
exclude<def>(r:
|
|
45
|
-
extends<def>(other:
|
|
46
|
-
overlaps<def>(r:
|
|
45
|
+
equals<def>(def: type.validate<def, $>): this is instantiateType<type.infer<def, $>, $>;
|
|
46
|
+
extract<def>(r: type.validate<def, $>): instantiateType<Extract<t, type.infer<def, $>>, $>;
|
|
47
|
+
exclude<def>(r: type.validate<def, $>): instantiateType<Exclude<t, type.infer<def, $>>, $>;
|
|
48
|
+
extends<def>(other: type.validate<def, $>): this is instantiateType<type.infer<def, $>, $>;
|
|
49
|
+
overlaps<def>(r: type.validate<def, $>): boolean;
|
|
47
50
|
distribute<mapOut, reduceOut = mapOut[]>(mapBranch: (branch: Type, i: number, branches: array<Type>) => mapOut, reduceMapped?: (mappedBranches: mapOut[]) => reduceOut): reduceOut;
|
|
48
51
|
/** @deprecated */
|
|
49
52
|
apply: Function["apply"];
|
package/out/methods/morph.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { Predicate, PredicateCast } from "@ark/schema";
|
|
2
2
|
import type { inferPipe } from "../intersect.ts";
|
|
3
|
+
import type { type } from "../keywords/ark.ts";
|
|
3
4
|
import type { applyConstraintSchema, Out, To } from "../keywords/ast.ts";
|
|
4
|
-
import type { inferTypeRoot, validateTypeRoot } from "../type.ts";
|
|
5
5
|
import type { BaseType } from "./base.ts";
|
|
6
6
|
/** @ts-ignore cast variance */
|
|
7
7
|
interface Type<out t = unknown, $ = {}> extends BaseType<t, $> {
|
|
8
|
-
to<const def, r =
|
|
8
|
+
to<const def, r = type.infer<def, $>>(def: type.validate<def, $>): Type<inferPipe<t, r>, $>;
|
|
9
9
|
narrow<narrowed extends this["infer"] = never>(predicate: Predicate<this["infer"]> | PredicateCast<this["infer"], narrowed>): Type<([
|
|
10
10
|
narrowed
|
|
11
|
-
] extends [never] ? applyConstraintSchema<this["
|
|
11
|
+
] extends [never] ? applyConstraintSchema<this["inferBrandableOut"], "predicate", Predicate> : narrowed) extends infer o ? this["inferIntrospectableOut"] extends this["inferBrandableOut"] ? (In: this["inferBrandableIn"]) => To<o> : (In: this["inferBrandableIn"]) => Out<o> : never, $>;
|
|
12
12
|
}
|
|
13
13
|
export type { Type as MorphType };
|
package/out/methods/object.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import type { array, ErrorType, merge } from "@ark/util";
|
|
2
|
-
import type {
|
|
1
|
+
import type { array, ErrorType, inferred, intersectUnion, Key, listable, merge, optionalKeyOf, show } from "@ark/util";
|
|
2
|
+
import type { arkGet, arkKeyOf, toArkKey } from "../keys.ts";
|
|
3
3
|
import type { type } from "../keywords/ark.ts";
|
|
4
|
-
import type { inferTypeRoot, validateTypeRoot } from "../type.ts";
|
|
5
4
|
import type { ArrayType } from "./array.ts";
|
|
6
5
|
import type { instantiateType } from "./instantiate.ts";
|
|
7
6
|
import type { ValidatorType } from "./validator.ts";
|
|
@@ -12,22 +11,47 @@ interface Type<out t extends object = object, $ = {}> extends ValidatorType<t, $
|
|
|
12
11
|
}, $> : Type<{
|
|
13
12
|
readonly [k in keyof t]: t[k];
|
|
14
13
|
}, $>;
|
|
15
|
-
keyof(): instantiateType<
|
|
16
|
-
get<k1 extends arkKeyOf<t>, r = instantiateType<
|
|
17
|
-
get<k1 extends arkKeyOf<t>, k2 extends arkKeyOf<
|
|
18
|
-
get<k1 extends arkKeyOf<t>, k2 extends arkKeyOf<
|
|
14
|
+
keyof(): instantiateType<arkKeyOf<t>, $>;
|
|
15
|
+
get<k1 extends arkKeyOf<t>, r = instantiateType<arkGet<t, k1>, $>>(k1: k1 | type.cast<k1>): r;
|
|
16
|
+
get<k1 extends arkKeyOf<t>, k2 extends arkKeyOf<arkGet<t, k1>>, r = instantiateType<arkGet<arkGet<t, k1>, k2>, $>>(k1: k1 | type.cast<k1>, k2: k2 | type.cast<k2>): r;
|
|
17
|
+
get<k1 extends arkKeyOf<t>, k2 extends arkKeyOf<arkGet<t, k1>>, k3 extends arkKeyOf<arkGet<arkGet<t, k1>, k2>>, r = instantiateType<arkGet<arkGet<arkGet<t, k1>, k2>, k3>, $>>(k1: k1 | type.cast<k1>, k2: k2 | type.cast<k2>, k3: k3 | type.cast<k3>): r;
|
|
19
18
|
pick<const key extends arkKeyOf<t> = never>(...keys: (key | type.cast<key>)[]): Type<{
|
|
20
19
|
[k in keyof t as Extract<toArkKey<t, k>, key>]: t[k];
|
|
21
20
|
}, $>;
|
|
22
21
|
omit<const key extends arkKeyOf<t> = never>(...keys: (key | type.cast<key>)[]): Type<{
|
|
23
22
|
[k in keyof t as Exclude<toArkKey<t, k>, key>]: t[k];
|
|
24
23
|
}, $>;
|
|
25
|
-
merge<const def, r =
|
|
24
|
+
merge<const def, r = type.infer<def, $>>(def: type.validate<def, $> & (r extends object ? unknown : ErrorType<"Merged type must be an object", [actual: r]>)): Type<merge<t, r & object>, $>;
|
|
26
25
|
required(): Type<{
|
|
27
26
|
[k in keyof t]-?: t[k];
|
|
28
27
|
}, $>;
|
|
29
28
|
partial(): Type<{
|
|
30
29
|
[k in keyof t]?: t[k];
|
|
31
30
|
}, $>;
|
|
31
|
+
map<transformed extends listable<MappedTypeEntry<Key, v>>, v = unknown>(flatMapEntry: (entry: typeEntryOf<t, $>) => transformed): Type<constructMapped<t, transformed>, $>;
|
|
32
32
|
}
|
|
33
|
+
export type MappedTypeEntry<k extends Key = Key, v = unknown> = readonly [
|
|
34
|
+
key: k,
|
|
35
|
+
value: type.cast<v>,
|
|
36
|
+
kind?: "required" | "optional"
|
|
37
|
+
];
|
|
38
|
+
type TypeEntries = array<MappedTypeEntry>;
|
|
39
|
+
type typeEntryOf<t, $> = {
|
|
40
|
+
[k in keyof t]-?: readonly [
|
|
41
|
+
k,
|
|
42
|
+
instantiateType<t[k] & ({} | null), $>,
|
|
43
|
+
k extends optionalKeyOf<t> ? "optional" : "required"
|
|
44
|
+
];
|
|
45
|
+
}[keyof t] & unknown;
|
|
46
|
+
type constructMapped<t, transformed extends listable<MappedTypeEntry>> = show<intersectUnion<fromTypeEntries<t, transformed extends TypeEntries ? transformed : [transformed]>>>;
|
|
47
|
+
type fromTypeEntries<t, entries extends TypeEntries> = show<{
|
|
48
|
+
[entry in entries[number] as Extract<applyHomomorphicOptionality<t, entry>, readonly [unknown, unknown, "required"]>[0]]: entry[1][inferred];
|
|
49
|
+
} & {
|
|
50
|
+
[entry in entries[number] as Extract<applyHomomorphicOptionality<t, entry>, readonly [unknown, unknown, "optional"]>[0]]?: entry[1][inferred];
|
|
51
|
+
}>;
|
|
52
|
+
type applyHomomorphicOptionality<t, entry extends MappedTypeEntry> = readonly [
|
|
53
|
+
entry[0],
|
|
54
|
+
entry[1],
|
|
55
|
+
entry[2] extends string ? entry[2] : entry[0] extends optionalKeyOf<t> ? "optional" : "required"
|
|
56
|
+
];
|
|
33
57
|
export type { Type as ObjectType };
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import { type BaseRoot } from "@ark/schema";
|
|
1
|
+
import { type BaseParseContext, type BaseRoot } from "@ark/schema";
|
|
2
2
|
import { type ErrorMessage, type Fn, type Primitive, type anyOrNever, type array, type defined, type equals, type ifEmptyObjectLiteral, type objectKindOrDomainOf, type optionalKeyOf, type requiredKeyOf, type show } from "@ark/util";
|
|
3
3
|
import type { type } from "../keywords/ark.ts";
|
|
4
4
|
import type { string } from "../keywords/string/string.ts";
|
|
5
|
-
import type { ParseContext } from "../scope.ts";
|
|
6
5
|
import { type inferObjectLiteral, type validateObjectLiteral } from "./objectLiteral.ts";
|
|
7
6
|
import type { validateString } from "./semantic/validate.ts";
|
|
8
7
|
import type { BaseCompletions, inferString } from "./string/string.ts";
|
|
9
8
|
import { type TupleExpression, type inferTuple, type validateTuple } from "./tuple.ts";
|
|
10
|
-
export declare const parseObject: (def: object, ctx:
|
|
9
|
+
export declare const parseObject: (def: object, ctx: BaseParseContext) => BaseRoot;
|
|
11
10
|
export type inferDefinition<def, $, args> = [
|
|
12
11
|
def
|
|
13
12
|
] extends [anyOrNever] ? def : def extends type.cast<infer t> ? ifEmptyObjectLiteral<def, object, t> : def extends ThunkCast<infer t> ? t : def extends string ? inferString<def, $, args> : def extends array ? inferTuple<def, $, args> : def extends RegExp ? string.matching<string> : def extends object ? inferObjectLiteral<def, $, args> : never;
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import { type BaseRoot, type Index, type Optional, type Required, type UndeclaredKeyBehavior, type writeInvalidPropertyKeyMessage } from "@ark/schema";
|
|
1
|
+
import { type BaseParseContext, type BaseRoot, type Index, type Optional, type Required, type UndeclaredKeyBehavior, type writeInvalidPropertyKeyMessage } from "@ark/schema";
|
|
2
2
|
import { type anyOrNever, type Dict, type ErrorMessage, type ErrorType, type EscapeToken, type Key, type listable, type merge, type show } from "@ark/util";
|
|
3
3
|
import type { constrain } from "../keywords/ast.ts";
|
|
4
|
-
import type { ParseContext } from "../scope.ts";
|
|
5
4
|
import type { inferDefinition, validateDefinition } from "./definition.ts";
|
|
6
5
|
import type { astToString } from "./semantic/utils.ts";
|
|
7
6
|
import type { validateString } from "./semantic/validate.ts";
|
|
8
|
-
export declare const parseObjectLiteral: (def: Dict, ctx:
|
|
7
|
+
export declare const parseObjectLiteral: (def: Dict, ctx: BaseParseContext) => BaseRoot;
|
|
9
8
|
export declare const writeInvalidUndeclaredBehaviorMessage: (actual: unknown) => string;
|
|
10
9
|
export declare const nonLeadingSpreadError = "Spread operator may only be used as the first key in an object";
|
|
11
10
|
export type inferObjectLiteral<def extends object, $, args> = show<"..." extends keyof def ? merge<inferDefinition<def["..."], $, args>, _inferObjectLiteral<def, $, args>> : _inferObjectLiteral<def, $, args>>;
|
|
@@ -24,7 +23,7 @@ export type validateObjectLiteral<def, $, args> = {
|
|
|
24
23
|
};
|
|
25
24
|
type nonOptionalKeyFrom<k, $, args> = parseKey<k> extends PreparsedKey<"required", infer inner> ? inner : parseKey<k> extends PreparsedKey<"index", infer inner> ? inferDefinition<inner, $, args> extends infer t extends Key ? t : never : never;
|
|
26
25
|
type optionalKeyFrom<k> = parseKey<k> extends PreparsedKey<"optional", infer inner> ? inner : never;
|
|
27
|
-
type PreparsedKey<kind extends ParsedKeyKind = ParsedKeyKind, key extends Key = Key> = {
|
|
26
|
+
export type PreparsedKey<kind extends ParsedKeyKind = ParsedKeyKind, key extends Key = Key> = {
|
|
28
27
|
kind: kind;
|
|
29
28
|
key: key;
|
|
30
29
|
};
|
|
@@ -43,7 +42,7 @@ export type ParsedSpreadEntry = {
|
|
|
43
42
|
kind: "spread";
|
|
44
43
|
node: BaseRoot;
|
|
45
44
|
};
|
|
46
|
-
export declare const parseEntry: (key: Key, value: unknown, ctx:
|
|
45
|
+
export declare const parseEntry: (key: Key, value: unknown, ctx: BaseParseContext) => listable<ParsedEntry>;
|
|
47
46
|
declare const parseKey: (key: Key) => PreparsedKey;
|
|
48
47
|
type parseKey<k> = k extends `${infer inner}?` ? inner extends `${infer baseName}${EscapeToken}` ? PreparsedKey.from<{
|
|
49
48
|
kind: "required";
|
|
@@ -28,7 +28,7 @@ export const parseObjectLiteral = (def, ctx) => {
|
|
|
28
28
|
structure[entry.kind] = append(structure[entry.kind], entry);
|
|
29
29
|
}
|
|
30
30
|
const structureNode = ctx.$.node("structure", structure);
|
|
31
|
-
return ctx.$.
|
|
31
|
+
return ctx.$.parseSchema({
|
|
32
32
|
domain: "object",
|
|
33
33
|
structure: spread?.merge(structureNode) ?? structureNode
|
|
34
34
|
});
|
|
@@ -43,10 +43,10 @@ export const parseEntry = (key, value, ctx) => {
|
|
|
43
43
|
return { kind: "undeclared", behavior: value };
|
|
44
44
|
}
|
|
45
45
|
if (parsedKey.kind === "...")
|
|
46
|
-
return { kind: "spread", node: ctx.$.
|
|
47
|
-
const parsedValue = ctx.$.
|
|
46
|
+
return { kind: "spread", node: ctx.$.parseOwnDefinitionFormat(value, ctx) };
|
|
47
|
+
const parsedValue = ctx.$.parseOwnDefinitionFormat(value, ctx);
|
|
48
48
|
if (parsedKey.kind === "index") {
|
|
49
|
-
const signature = ctx.$.
|
|
49
|
+
const signature = ctx.$.parseOwnDefinitionFormat(parsedKey.key, ctx);
|
|
50
50
|
const normalized = normalizeIndex(signature, parsedValue, ctx.$);
|
|
51
51
|
return (normalized.index ?
|
|
52
52
|
normalized.required ?
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { writeUnassignableDefaultValueMessage } from "@ark/schema";
|
|
2
2
|
import type { ErrorMessage } from "@ark/util";
|
|
3
|
-
import type {
|
|
3
|
+
import type { type } from "../../keywords/ark.ts";
|
|
4
4
|
import type { UnitLiteral } from "../string/shift/operator/default.ts";
|
|
5
5
|
import type { inferAstOut } from "./infer.ts";
|
|
6
6
|
import type { astToString } from "./utils.ts";
|
|
7
7
|
import type { validateAst } from "./validate.ts";
|
|
8
|
-
export type validateDefault<baseAst, unitLiteral extends UnitLiteral, $, args> = validateAst<baseAst, $, args> extends infer e extends ErrorMessage ? e :
|
|
8
|
+
export type validateDefault<baseAst, unitLiteral extends UnitLiteral, $, args> = validateAst<baseAst, $, args> extends infer e extends ErrorMessage ? e : type.infer<unitLiteral> extends inferAstOut<baseAst, $, args> ? undefined : ErrorMessage<writeUnassignableDefaultValueMessage<astToString<baseAst>, unitLiteral>>;
|