arktype 2.0.0-beta.4 → 2.0.0-beta.6
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/ast.d.ts +7 -10
- package/out/ast.js +0 -1
- package/out/config.d.ts +17 -2
- package/out/generic.d.ts +9 -16
- package/out/generic.js +1 -2
- package/out/index.d.ts +6 -7
- package/out/index.js +1 -1
- package/out/intersect.d.ts +1 -1
- package/out/keys.d.ts +2 -2
- package/out/keywords/ark.d.ts +40 -0
- package/out/keywords/ark.js +28 -0
- package/out/keywords/builtin.d.ts +26 -0
- package/out/keywords/builtin.js +21 -0
- package/out/keywords/format.d.ts +13 -10
- package/out/keywords/format.js +4 -1
- package/out/keywords/js.d.ts +18 -0
- package/out/keywords/{jsObjects.js → js.js} +4 -1
- package/out/keywords/number.d.ts +23 -0
- package/out/keywords/number.js +44 -0
- package/out/keywords/parse.d.ts +19 -0
- package/out/keywords/{parsing.js → parse.js} +9 -4
- package/out/keywords/platform.d.ts +16 -0
- package/out/keywords/{platformObjects.js → platform.js} +4 -1
- package/out/keywords/string.d.ts +31 -0
- package/out/keywords/string.js +89 -0
- package/out/keywords/ts.d.ts +58 -0
- package/out/keywords/ts.js +55 -0
- package/out/keywords/typedArray.d.ts +18 -15
- package/out/keywords/typedArray.js +4 -1
- package/out/keywords/utils/date.d.ts +1 -0
- package/out/keywords/utils/date.js +1 -1
- package/out/keywords/utils/ip.d.ts +16 -3
- package/out/keywords/utils/ip.js +10 -4
- package/out/keywords/utils/regex.d.ts +3 -2
- package/out/keywords/utils/uuid.d.ts +30 -0
- package/out/keywords/utils/uuid.js +22 -0
- package/out/module.d.ts +2 -2
- package/out/parser/definition.d.ts +9 -9
- package/out/parser/objectLiteral.d.ts +8 -6
- package/out/parser/semantic/bounds.d.ts +6 -6
- package/out/parser/semantic/default.d.ts +4 -4
- package/out/parser/semantic/divisor.d.ts +2 -2
- package/out/parser/semantic/infer.d.ts +8 -8
- package/out/parser/semantic/keyof.d.ts +2 -2
- package/out/parser/semantic/utils.d.ts +2 -2
- package/out/parser/semantic/validate.d.ts +12 -12
- package/out/parser/string/reduce/dynamic.d.ts +8 -8
- package/out/parser/string/reduce/dynamic.js +3 -3
- package/out/parser/string/reduce/shared.d.ts +1 -1
- package/out/parser/string/reduce/static.d.ts +19 -20
- package/out/parser/string/shift/operand/date.d.ts +1 -3
- package/out/parser/string/shift/operand/enclosed.d.ts +3 -3
- package/out/parser/string/shift/operand/genericArgs.d.ts +4 -4
- package/out/parser/string/shift/operand/operand.d.ts +6 -6
- package/out/parser/string/shift/operand/unenclosed.d.ts +12 -10
- package/out/parser/string/shift/operand/unenclosed.js +2 -2
- package/out/parser/string/shift/operator/bounds.d.ts +8 -12
- package/out/parser/string/shift/operator/bounds.js +0 -4
- package/out/parser/string/shift/operator/default.d.ts +4 -10
- package/out/parser/string/shift/operator/default.js +0 -6
- package/out/parser/string/shift/operator/divisor.d.ts +3 -3
- package/out/parser/string/shift/operator/operator.d.ts +5 -5
- package/out/parser/string/shift/scanner.d.ts +16 -16
- package/out/parser/string/shift/scanner.js +6 -8
- package/out/parser/string/string.d.ts +9 -9
- package/out/parser/tuple.d.ts +7 -7
- package/out/parser/tuple.js +2 -1
- package/out/scope.d.ts +24 -19
- package/out/scope.js +65 -111
- package/out/subtypes/array.d.ts +2 -2
- package/out/subtypes/base.d.ts +9 -8
- package/out/subtypes/date.d.ts +2 -2
- package/out/subtypes/instantiate.d.ts +8 -8
- package/out/subtypes/morph.d.ts +4 -4
- package/out/subtypes/number.d.ts +2 -2
- package/out/subtypes/object.d.ts +12 -6
- package/out/subtypes/string.d.ts +2 -2
- package/out/subtypes/validator.d.ts +3 -3
- package/out/type.d.ts +7 -7
- package/package.json +17 -8
- package/out/ark.d.ts +0 -33
- package/out/ark.js +0 -28
- package/out/keywords/arkGenerics.d.ts +0 -19
- package/out/keywords/arkGenerics.js +0 -19
- package/out/keywords/internal.d.ts +0 -11
- package/out/keywords/internal.js +0 -25
- package/out/keywords/jsObjects.d.ts +0 -15
- package/out/keywords/parsing.d.ts +0 -16
- package/out/keywords/platformObjects.d.ts +0 -13
- package/out/keywords/tsGenerics.d.ts +0 -37
- package/out/keywords/tsGenerics.js +0 -45
- package/out/keywords/tsKeywords.d.ts +0 -18
- package/out/keywords/tsKeywords.js +0 -17
- package/out/keywords/validation.d.ts +0 -19
- package/out/keywords/validation.js +0 -84
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Hkt, type Key, type omit, type pick, type show } from "@ark/util";
|
|
2
|
+
import type { Module } from "../module.ts";
|
|
3
|
+
declare class RecordHkt extends Hkt<[Key, unknown]> {
|
|
4
|
+
body: Record<this[0], this[1]>;
|
|
5
|
+
}
|
|
6
|
+
declare const Record: import("@ark/schema").GenericRoot<readonly [["K", Key], ["V", unknown]], RecordHkt>;
|
|
7
|
+
declare class PickHkt extends Hkt<[object, Key]> {
|
|
8
|
+
body: pick<this[0], this[1] & keyof this[0]>;
|
|
9
|
+
}
|
|
10
|
+
declare const Pick: import("@ark/schema").GenericRoot<readonly [["T", object], ["K", Key]], PickHkt>;
|
|
11
|
+
declare class OmitHkt extends Hkt<[object, Key]> {
|
|
12
|
+
body: omit<this[0], this[1] & keyof this[0]>;
|
|
13
|
+
}
|
|
14
|
+
declare const Omit: import("@ark/schema").GenericRoot<readonly [["T", object], ["K", Key]], OmitHkt>;
|
|
15
|
+
declare class PartialHkt extends Hkt<[object]> {
|
|
16
|
+
body: show<Partial<this[0]>>;
|
|
17
|
+
}
|
|
18
|
+
declare const Partial: import("@ark/schema").GenericRoot<readonly [["T", object]], PartialHkt>;
|
|
19
|
+
declare class RequiredHkt extends Hkt<[object]> {
|
|
20
|
+
body: show<Required<this[0]>>;
|
|
21
|
+
}
|
|
22
|
+
declare const Required: import("@ark/schema").GenericRoot<readonly [["T", object]], RequiredHkt>;
|
|
23
|
+
declare class ExcludeHkt extends Hkt<[unknown, unknown]> {
|
|
24
|
+
body: Exclude<this[0], this[1]>;
|
|
25
|
+
}
|
|
26
|
+
declare const Exclude: import("@ark/schema").GenericRoot<readonly [["T", unknown], ["U", unknown]], ExcludeHkt>;
|
|
27
|
+
declare class ExtractHkt extends Hkt<[unknown, unknown]> {
|
|
28
|
+
body: Extract<this[0], this[1]>;
|
|
29
|
+
}
|
|
30
|
+
declare const Extract: import("@ark/schema").GenericRoot<readonly [["T", unknown], ["U", unknown]], ExtractHkt>;
|
|
31
|
+
export declare const arkTs: {
|
|
32
|
+
keywords: Module<arkTs.keywords>;
|
|
33
|
+
};
|
|
34
|
+
export declare namespace arkTs {
|
|
35
|
+
interface keywords {
|
|
36
|
+
any: any;
|
|
37
|
+
bigint: bigint;
|
|
38
|
+
boolean: boolean;
|
|
39
|
+
false: false;
|
|
40
|
+
never: never;
|
|
41
|
+
null: null;
|
|
42
|
+
number: number;
|
|
43
|
+
object: object;
|
|
44
|
+
string: string;
|
|
45
|
+
symbol: symbol;
|
|
46
|
+
true: true;
|
|
47
|
+
unknown: unknown;
|
|
48
|
+
undefined: undefined;
|
|
49
|
+
Record: typeof Record.t;
|
|
50
|
+
Pick: typeof Pick.t;
|
|
51
|
+
Omit: typeof Omit.t;
|
|
52
|
+
Exclude: typeof Exclude.t;
|
|
53
|
+
Extract: typeof Extract.t;
|
|
54
|
+
Partial: typeof Partial.t;
|
|
55
|
+
Required: typeof Required.t;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { genericNode, intrinsic } from "@ark/schema";
|
|
2
|
+
import { Hkt } from "@ark/util";
|
|
3
|
+
import { scope } from "../scope.js";
|
|
4
|
+
class RecordHkt extends Hkt {
|
|
5
|
+
}
|
|
6
|
+
const Record = genericNode(["K", intrinsic.key], "V")(args => ({
|
|
7
|
+
domain: "object",
|
|
8
|
+
index: {
|
|
9
|
+
signature: args.K,
|
|
10
|
+
value: args.V
|
|
11
|
+
}
|
|
12
|
+
}), RecordHkt);
|
|
13
|
+
class PickHkt extends Hkt {
|
|
14
|
+
}
|
|
15
|
+
const Pick = genericNode(["T", intrinsic.object], ["K", intrinsic.key])(args => args.T.pick(args.K), PickHkt);
|
|
16
|
+
class OmitHkt extends Hkt {
|
|
17
|
+
}
|
|
18
|
+
const Omit = genericNode(["T", intrinsic.object], ["K", intrinsic.key])(args => args.T.omit(args.K), OmitHkt);
|
|
19
|
+
class PartialHkt extends Hkt {
|
|
20
|
+
}
|
|
21
|
+
const Partial = genericNode(["T", intrinsic.object])(args => args.T.partial(), PartialHkt);
|
|
22
|
+
class RequiredHkt extends Hkt {
|
|
23
|
+
}
|
|
24
|
+
const Required = genericNode(["T", intrinsic.object])(args => args.T.required(), RequiredHkt);
|
|
25
|
+
class ExcludeHkt extends Hkt {
|
|
26
|
+
}
|
|
27
|
+
const Exclude = genericNode("T", "U")(args => args.T.exclude(args.U), ExcludeHkt);
|
|
28
|
+
class ExtractHkt extends Hkt {
|
|
29
|
+
}
|
|
30
|
+
const Extract = genericNode("T", "U")(args => args.T.extract(args.U), ExtractHkt);
|
|
31
|
+
const keywords = scope({
|
|
32
|
+
any: intrinsic.unknown,
|
|
33
|
+
bigint: intrinsic.bigint,
|
|
34
|
+
boolean: intrinsic.boolean,
|
|
35
|
+
false: intrinsic.false,
|
|
36
|
+
never: intrinsic.never,
|
|
37
|
+
null: intrinsic.null,
|
|
38
|
+
number: intrinsic.number,
|
|
39
|
+
object: intrinsic.object,
|
|
40
|
+
string: intrinsic.string,
|
|
41
|
+
symbol: intrinsic.symbol,
|
|
42
|
+
true: intrinsic.true,
|
|
43
|
+
unknown: intrinsic.unknown,
|
|
44
|
+
undefined: intrinsic.undefined,
|
|
45
|
+
Record,
|
|
46
|
+
Pick,
|
|
47
|
+
Omit,
|
|
48
|
+
Exclude,
|
|
49
|
+
Extract,
|
|
50
|
+
Partial,
|
|
51
|
+
Required
|
|
52
|
+
}, { prereducedAliases: true }).export();
|
|
53
|
+
export const arkTs = {
|
|
54
|
+
keywords
|
|
55
|
+
};
|
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
import type { Module } from "../module.
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import type { Module, Submodule } from "../module.ts";
|
|
2
|
+
export declare const arkTypedArray: {
|
|
3
|
+
submodule: Module<arkTypedArray.submodule>;
|
|
4
|
+
};
|
|
5
|
+
export declare namespace arkTypedArray {
|
|
6
|
+
type submodule = Submodule<{
|
|
7
|
+
Int8: Int8Array;
|
|
8
|
+
Uint8: Uint8Array;
|
|
9
|
+
Uint8Clamped: Uint8ClampedArray;
|
|
10
|
+
Int16: Int16Array;
|
|
11
|
+
Uint16: Uint16Array;
|
|
12
|
+
Int32: Int32Array;
|
|
13
|
+
Uint32: Uint32Array;
|
|
14
|
+
Float32: Float32Array;
|
|
15
|
+
Float64: Float64Array;
|
|
16
|
+
BigInt64: BigInt64Array;
|
|
17
|
+
BigUint64: BigUint64Array;
|
|
18
|
+
}>;
|
|
14
19
|
}
|
|
15
|
-
export type typedArray = Module<typedArrayExports>;
|
|
16
|
-
export declare const typedArray: typedArray;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { scope } from "../scope.js";
|
|
2
|
-
|
|
2
|
+
const submodule = scope({
|
|
3
3
|
Int8: ["instanceof", Int8Array],
|
|
4
4
|
Uint8: ["instanceof", Uint8Array],
|
|
5
5
|
Uint8Clamped: ["instanceof", Uint8ClampedArray],
|
|
@@ -12,3 +12,6 @@ export const typedArray = scope({
|
|
|
12
12
|
BigInt64: ["instanceof", BigInt64Array],
|
|
13
13
|
BigUint64: ["instanceof", BigUint64Array]
|
|
14
14
|
}, { prereducedAliases: true }).export();
|
|
15
|
+
export const arkTypedArray = {
|
|
16
|
+
submodule
|
|
17
|
+
};
|
|
@@ -16,5 +16,6 @@ export type DateFormat = "iso8601" | DayPattern;
|
|
|
16
16
|
export type DateOptions = {
|
|
17
17
|
format?: DateFormat;
|
|
18
18
|
};
|
|
19
|
+
export declare const iso8601Matcher: RegExp;
|
|
19
20
|
export declare const tryParseDatePattern: (data: string, opts?: DateOptions) => Date | string;
|
|
20
21
|
export {};
|
|
@@ -2,7 +2,7 @@ const dayDelimiterMatcher = /^[./-]$/;
|
|
|
2
2
|
// ISO 8601 date/time modernized from https://github.com/validatorjs/validator.js/blob/master/src/lib/isISO8601.js
|
|
3
3
|
// Based on https://tc39.es/ecma262/#sec-date-time-string-format, the T
|
|
4
4
|
// delimiter for date/time is mandatory. Regex from validator.js strict matcher:
|
|
5
|
-
const iso8601Matcher = /^([+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-3])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([.,]\d+(?!:))?)?(\17[0-5]\d([.,]\d+)?)?([zZ]|([+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;
|
|
5
|
+
export const iso8601Matcher = /^([+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-3])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([.,]\d+(?!:))?)?(\17[0-5]\d([.,]\d+)?)?([zZ]|([+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;
|
|
6
6
|
const isValidDateInstance = (date) => !Number.isNaN(+date);
|
|
7
7
|
const writeFormattedExpected = (format) => `a ${format}-formatted date`;
|
|
8
8
|
export const tryParseDatePattern = (data, opts) => {
|
|
@@ -1,3 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
export declare const
|
|
1
|
+
import type { string } from "../../ast.ts";
|
|
2
|
+
import type { Submodule } from "../../module.ts";
|
|
3
|
+
export declare const arkIp: {
|
|
4
|
+
submodule: import("../../module.ts").Module<{
|
|
5
|
+
$root: string.matching<"?">;
|
|
6
|
+
v4: string.matching<"?">;
|
|
7
|
+
v6: string.matching<"?">;
|
|
8
|
+
}>;
|
|
9
|
+
};
|
|
10
|
+
export declare namespace arkIp {
|
|
11
|
+
type submodule = Submodule<{
|
|
12
|
+
$root: string.matching<"?">;
|
|
13
|
+
v4: string.matching<"?">;
|
|
14
|
+
v6: string.matching<"?">;
|
|
15
|
+
}>;
|
|
16
|
+
}
|
package/out/keywords/utils/ip.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { scope } from "../../scope.js";
|
|
2
2
|
import { regexStringNode } from "./regex.js";
|
|
3
3
|
// Based on https://github.com/validatorjs/validator.js/blob/master/src/lib/isIP.js
|
|
4
4
|
const ipv4Segment = "(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])";
|
|
5
5
|
const ipv4Address = `(${ipv4Segment}[.]){3}${ipv4Segment}`;
|
|
6
6
|
const ipv4Matcher = new RegExp(`^${ipv4Address}$`);
|
|
7
|
-
export const ipv4 = regexStringNode(ipv4Matcher, "a valid IPv4 address");
|
|
8
7
|
const ipv6Segment = "(?:[0-9a-fA-F]{1,4})";
|
|
9
8
|
const ipv6Matcher = new RegExp("^(" +
|
|
10
9
|
`(?:${ipv6Segment}:){7}(?:${ipv6Segment}|:)|` +
|
|
@@ -16,5 +15,12 @@ const ipv6Matcher = new RegExp("^(" +
|
|
|
16
15
|
`(?:${ipv6Segment}:){1}(?:(:${ipv6Segment}){0,4}:${ipv4Address}|(:${ipv6Segment}){1,6}|:)|` +
|
|
17
16
|
`(?::((?::${ipv6Segment}){0,5}:${ipv4Address}|(?::${ipv6Segment}){1,7}|:))` +
|
|
18
17
|
")(%[0-9a-zA-Z-.:]{1,})?$");
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
// Based on https://github.com/validatorjs/validator.js/blob/master/src/lib/isUUID.js
|
|
19
|
+
const submodule = scope({
|
|
20
|
+
$root: ["v4 | v6", "@", "an IP address"],
|
|
21
|
+
v4: regexStringNode(ipv4Matcher, "an IPv4 address"),
|
|
22
|
+
v6: regexStringNode(ipv6Matcher, "an IPv6 address")
|
|
23
|
+
}, { prereducedAliases: true }).export();
|
|
24
|
+
export const arkIp = {
|
|
25
|
+
submodule
|
|
26
|
+
};
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import type { string } from "../../ast.ts";
|
|
2
|
+
import type { Type } from "../../type.ts";
|
|
3
|
+
export declare const regexStringNode: (regex: RegExp, description: string) => Type<string.matching<"?">>;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { string } from "../../ast.ts";
|
|
2
|
+
import type { Submodule } from "../../module.ts";
|
|
3
|
+
export declare const arkUuid: {
|
|
4
|
+
submodule: import("../../module.ts").Module<{
|
|
5
|
+
$root: string.matching<string> | "00000000-0000-0000-0000-000000000000" | "ffffffff-ffff-ffff-ffff-ffffffffffff";
|
|
6
|
+
v1: string.matching<"?">;
|
|
7
|
+
v2: string.matching<"?">;
|
|
8
|
+
v3: string.matching<"?">;
|
|
9
|
+
v4: string.matching<"?">;
|
|
10
|
+
v5: string.matching<"?">;
|
|
11
|
+
v6: string.matching<"?">;
|
|
12
|
+
v7: string.matching<"?">;
|
|
13
|
+
v8: string.matching<"?">;
|
|
14
|
+
}>;
|
|
15
|
+
};
|
|
16
|
+
export declare namespace arkUuid {
|
|
17
|
+
type submodule = Submodule<{
|
|
18
|
+
$root: string.matching<"?">;
|
|
19
|
+
v1: string.matching<"?">;
|
|
20
|
+
v2: string.matching<"?">;
|
|
21
|
+
v3: string.matching<"?">;
|
|
22
|
+
v4: string.matching<"?">;
|
|
23
|
+
v5: string.matching<"?">;
|
|
24
|
+
v6: string.matching<"?">;
|
|
25
|
+
v7: string.matching<"?">;
|
|
26
|
+
v8: string.matching<"?">;
|
|
27
|
+
nil: string.matching<"?">;
|
|
28
|
+
max: string.matching<"?">;
|
|
29
|
+
}>;
|
|
30
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { scope } from "../../scope.js";
|
|
2
|
+
import { regexStringNode } from "./regex.js";
|
|
3
|
+
// Based on https://github.com/validatorjs/validator.js/blob/master/src/lib/isUUID.js
|
|
4
|
+
const submodule = scope({
|
|
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
|
+
}, { prereducedAliases: true }).export();
|
|
20
|
+
export const arkUuid = {
|
|
21
|
+
submodule
|
|
22
|
+
};
|
package/out/module.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { RootModule, type GenericAst, type PreparsedNodeResolution } from "@ark/schema";
|
|
2
2
|
import type { anyOrNever } from "@ark/util";
|
|
3
|
-
import type { Generic } from "./generic.
|
|
4
|
-
import type { Type } from "./type.
|
|
3
|
+
import type { Generic } from "./generic.ts";
|
|
4
|
+
import type { Type } from "./type.ts";
|
|
5
5
|
export declare const Module: new <$ extends {}>(exports: exportScope<$>) => Module<$>;
|
|
6
6
|
export interface Module<$ extends {} = {}> extends RootModule<exportScope<$>> {
|
|
7
7
|
}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { type BaseRoot } from "@ark/schema";
|
|
2
|
-
import { type ErrorMessage, type Primitive, type anyOrNever, type array, type defined, type equals, type objectKindOrDomainOf, type optionalKeyOf, type requiredKeyOf, type show } from "@ark/util";
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
import type { ParseContext } from "../scope.
|
|
6
|
-
import { type inferObjectLiteral, type validateObjectLiteral } from "./objectLiteral.
|
|
7
|
-
import type { validateString } from "./semantic/validate.
|
|
8
|
-
import type { BaseCompletions, inferString } from "./string/string.
|
|
9
|
-
import { type TupleExpression, type inferTuple, type validateTuple } from "./tuple.
|
|
2
|
+
import { type ErrorMessage, type Fn, type Primitive, type anyOrNever, type array, type defined, type equals, type objectKindOrDomainOf, type optionalKeyOf, type requiredKeyOf, type show } from "@ark/util";
|
|
3
|
+
import type { string } from "../ast.ts";
|
|
4
|
+
import type { type } from "../keywords/ark.ts";
|
|
5
|
+
import type { ParseContext } from "../scope.ts";
|
|
6
|
+
import { type inferObjectLiteral, type validateObjectLiteral } from "./objectLiteral.ts";
|
|
7
|
+
import type { validateString } from "./semantic/validate.ts";
|
|
8
|
+
import type { BaseCompletions, inferString } from "./string/string.ts";
|
|
9
|
+
import { type TupleExpression, type inferTuple, type validateTuple } from "./tuple.ts";
|
|
10
10
|
export declare const parseObject: (def: object, ctx: ParseContext) => BaseRoot;
|
|
11
11
|
export type inferDefinition<def, $, args> = [
|
|
12
12
|
def
|
|
@@ -25,7 +25,7 @@ type declarationMismatch<def, declared, $, args> = {
|
|
|
25
25
|
declared: declared;
|
|
26
26
|
inferred: inferDefinition<def, $, args>;
|
|
27
27
|
};
|
|
28
|
-
type Terminal = RegExp | type.cast<unknown> |
|
|
28
|
+
type Terminal = RegExp | type.cast<unknown> | Fn;
|
|
29
29
|
export type ThunkCast<t = unknown> = () => type.cast<t>;
|
|
30
30
|
type BadDefinitionType = Exclude<Primitive, string>;
|
|
31
31
|
export declare const writeBadDefinitionTypeMessage: <actual extends string>(actual: actual) => writeBadDefinitionTypeMessage<actual>;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { type BaseRoot, type Index, type Optional, type Required, type UndeclaredKeyBehavior, type writeInvalidPropertyKeyMessage } from "@ark/schema";
|
|
2
2
|
import { type anyOrNever, type conform, type Dict, type ErrorMessage, type ErrorType, type EscapeToken, type Key, type listable, type merge, type show } from "@ark/util";
|
|
3
|
-
import type { constrain, Default } from "../ast.
|
|
4
|
-
import type { ParseContext } from "../scope.
|
|
5
|
-
import type { inferDefinition, validateDefinition } from "./definition.
|
|
6
|
-
import type { astToString } from "./semantic/utils.
|
|
7
|
-
import type { validateString } from "./semantic/validate.
|
|
3
|
+
import type { constrain, Default } from "../ast.ts";
|
|
4
|
+
import type { ParseContext } from "../scope.ts";
|
|
5
|
+
import type { inferDefinition, validateDefinition } from "./definition.ts";
|
|
6
|
+
import type { astToString } from "./semantic/utils.ts";
|
|
7
|
+
import type { validateString } from "./semantic/validate.ts";
|
|
8
8
|
export declare const parseObjectLiteral: (def: Dict, ctx: ParseContext) => BaseRoot;
|
|
9
9
|
export declare const writeInvalidUndeclaredBehaviorMessage: (actual: unknown) => string;
|
|
10
10
|
export declare const nonLeadingSpreadError = "Spread operator may only be used as the first key in an object";
|
|
@@ -13,7 +13,9 @@ export type inferObjectLiteral<def extends object, $, args> = show<"..." extends
|
|
|
13
13
|
* Infers the contents of an object literal, ignoring a spread definition
|
|
14
14
|
*/
|
|
15
15
|
type _inferObjectLiteral<def extends object, $, args> = {
|
|
16
|
-
-readonly [k in keyof def as nonOptionalKeyFrom<k, $, args>]: def[k] extends (DefaultValueTuple<infer baseDef, infer defaultValue>) ?
|
|
16
|
+
-readonly [k in keyof def as nonOptionalKeyFrom<k, $, args>]: def[k] extends (DefaultValueTuple<infer baseDef, infer defaultValue>) ? [
|
|
17
|
+
def[k]
|
|
18
|
+
] extends [anyOrNever] ? def[k] : (In?: inferDefinition<baseDef, $, args>) => Default<defaultValue> : inferDefinition<def[k], $, args>;
|
|
17
19
|
} & {
|
|
18
20
|
-readonly [k in keyof def as optionalKeyFrom<k>]?: inferDefinition<def[k], $, args>;
|
|
19
21
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { writeUnboundableMessage } from "@ark/schema";
|
|
2
2
|
import type { ErrorMessage, array, typeToString } from "@ark/util";
|
|
3
|
-
import type { LimitLiteral } from "../../ast.
|
|
4
|
-
import type { Comparator } from "../string/reduce/shared.
|
|
5
|
-
import type { BoundExpressionKind, writeInvalidLimitMessage } from "../string/shift/operator/bounds.
|
|
6
|
-
import type { inferAstIn } from "./infer.
|
|
7
|
-
import type { astToString } from "./utils.
|
|
8
|
-
import type { validateAst } from "./validate.
|
|
3
|
+
import type { LimitLiteral } from "../../ast.ts";
|
|
4
|
+
import type { Comparator } from "../string/reduce/shared.ts";
|
|
5
|
+
import type { BoundExpressionKind, writeInvalidLimitMessage } from "../string/shift/operator/bounds.ts";
|
|
6
|
+
import type { inferAstIn } from "./infer.ts";
|
|
7
|
+
import type { astToString } from "./utils.ts";
|
|
8
|
+
import type { validateAst } from "./validate.ts";
|
|
9
9
|
export type validateRange<l, comparator extends Comparator, r, $, args> = l extends LimitLiteral ? validateBound<r, comparator, l, "left", $, args> : l extends [infer leftAst, Comparator, unknown] ? ErrorMessage<writeDoubleRightBoundMessage<astToString<leftAst>>> : validateBound<l, comparator, r & LimitLiteral, "right", $, args>;
|
|
10
10
|
export type validateBound<boundedAst, comparator extends Comparator, limit extends LimitLiteral, boundKind extends BoundExpressionKind, $, args> = inferAstIn<boundedAst, $, args> extends infer bounded ? isNumericallyBoundable<bounded> extends true ? limit extends number ? validateAst<boundedAst, $, args> : ErrorMessage<writeInvalidLimitMessage<comparator, limit, boundKind>> : [bounded] extends [Date] ? validateAst<boundedAst, $, args> : ErrorMessage<writeUnboundableMessage<typeToString<bounded>>> : never;
|
|
11
11
|
type isNumericallyBoundable<bounded> = [
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { ErrorMessage } from "@ark/util";
|
|
2
|
-
import type { UnitLiteral } from "../string/shift/operator/default.
|
|
3
|
-
import type { inferAstOut, inferTerminal } from "./infer.
|
|
4
|
-
import type { astToString } from "./utils.
|
|
5
|
-
import type { validateAst } from "./validate.
|
|
2
|
+
import type { UnitLiteral } from "../string/shift/operator/default.ts";
|
|
3
|
+
import type { inferAstOut, inferTerminal } from "./infer.ts";
|
|
4
|
+
import type { astToString } from "./utils.ts";
|
|
5
|
+
import type { validateAst } from "./validate.ts";
|
|
6
6
|
export type validateDefault<baseAst, unitLiteral extends UnitLiteral, $, args> = validateAst<baseAst, $, args> extends infer e extends ErrorMessage ? e : inferTerminal<unitLiteral, $, args> extends inferAstOut<baseAst, $, args> ? undefined : ErrorMessage<writeUnassignableDefaultValueMessage<astToString<baseAst>, unitLiteral>>;
|
|
7
7
|
export declare const writeUnassignableDefaultValueMessage: <key extends string, message extends string>(key: key, message: message) => string;
|
|
8
8
|
export type writeUnassignableDefaultValueMessage<baseDef extends string, defaultValue extends string> = `Default value ${defaultValue} is not assignable to ${baseDef}`;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { writeIndivisibleMessage } from "@ark/schema";
|
|
2
2
|
import type { ErrorMessage } from "@ark/util";
|
|
3
|
-
import type { inferAstIn } from "./infer.
|
|
4
|
-
import type { validateAst } from "./validate.
|
|
3
|
+
import type { inferAstIn } from "./infer.ts";
|
|
4
|
+
import type { validateAst } from "./validate.ts";
|
|
5
5
|
export type validateDivisor<l, $, args> = inferAstIn<l, $, args> extends infer data ? [
|
|
6
6
|
data
|
|
7
7
|
] extends [number] ? validateAst<l, $, args> : ErrorMessage<writeIndivisibleMessage<data>> : never;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { GenericAst } from "@ark/schema";
|
|
2
2
|
import type { BigintLiteral, Hkt, array } from "@ark/util";
|
|
3
|
-
import type {
|
|
4
|
-
import type { Date, DateLiteral, Default, LimitLiteral, RegexLiteral, applyConstraint, distillIn, distillOut, normalizeLimit, string } from "../../ast.
|
|
5
|
-
import type { inferIntersection } from "../../intersect.
|
|
6
|
-
import type { UnparsedScope, resolve, tryInferSubmoduleReference } from "../../scope.
|
|
7
|
-
import type { inferDefinition } from "../definition.
|
|
8
|
-
import type { Comparator, MinComparator } from "../string/reduce/shared.
|
|
9
|
-
import type { StringLiteral } from "../string/shift/operand/enclosed.
|
|
3
|
+
import type { ArkAmbient } from "arktype/config";
|
|
4
|
+
import type { Date, DateLiteral, Default, LimitLiteral, RegexLiteral, applyConstraint, distillIn, distillOut, normalizeLimit, string } from "../../ast.ts";
|
|
5
|
+
import type { inferIntersection } from "../../intersect.ts";
|
|
6
|
+
import type { UnparsedScope, resolve, tryInferSubmoduleReference } from "../../scope.ts";
|
|
7
|
+
import type { inferDefinition } from "../definition.ts";
|
|
8
|
+
import type { Comparator, MinComparator } from "../string/reduce/shared.ts";
|
|
9
|
+
import type { StringLiteral } from "../string/shift/operand/enclosed.ts";
|
|
10
10
|
export type inferAstRoot<ast, $, args> = inferConstrainableAst<ast, $, args>;
|
|
11
11
|
export type inferAstIn<ast, $, args> = distillIn<inferAstRoot<ast, $, args>>;
|
|
12
12
|
export type inferAstOut<ast, $, args> = distillOut<inferAstRoot<ast, $, args>>;
|
|
@@ -28,5 +28,5 @@ export type PostfixOperator = "[]";
|
|
|
28
28
|
export type PostfixExpression<operator extends PostfixOperator = PostfixOperator, operand = unknown> = readonly [operand, operator];
|
|
29
29
|
export type InfixOperator = "|" | "&" | Comparator | "%" | ":" | "=>" | "@";
|
|
30
30
|
export type InfixExpression<operator extends InfixOperator = InfixOperator, l = unknown, r = unknown> = [l, operator, r];
|
|
31
|
-
export type inferTerminal<token extends string, $, args> = token extends keyof args | keyof $ ? resolve<token, $, args> : token extends keyof
|
|
31
|
+
export type inferTerminal<token extends string, $, args> = token extends keyof args | keyof $ ? resolve<token, $, args> : token extends keyof ArkAmbient.$ ? resolve<token, ArkAmbient.$, args> : `#${token}` extends keyof $ ? resolve<`#${token}`, $, args> : token extends StringLiteral<infer text> ? text : token extends `${infer n extends number}` ? n : token extends BigintLiteral<infer b> ? b : token extends RegexLiteral<infer source> ? string.matching<source> : token extends DateLiteral<infer source> ? Date.literal<source> : tryInferSubmoduleReference<$, token>;
|
|
32
32
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { writeNonStructuralOperandMessage } from "@ark/schema";
|
|
2
2
|
import type { ErrorMessage, typeToString } from "@ark/util";
|
|
3
|
-
import type { inferAstRoot } from "./infer.
|
|
4
|
-
import type { validateAst } from "./validate.
|
|
3
|
+
import type { inferAstRoot } from "./infer.ts";
|
|
4
|
+
import type { validateAst } from "./validate.ts";
|
|
5
5
|
export type validateKeyof<operandAst, $, args> = inferAstRoot<operandAst, $, args> extends infer data ? [
|
|
6
6
|
data
|
|
7
7
|
] extends [object] ? validateAst<operandAst, $, args> : ErrorMessage<writeNonStructuralOperandMessage<"keyof", typeToString<data>>> : never;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Stringifiable } from "@ark/util";
|
|
2
|
-
import type { Comparator } from "../string/reduce/shared.
|
|
3
|
-
import type { InfixExpression, PostfixExpression } from "./infer.
|
|
2
|
+
import type { Comparator } from "../string/reduce/shared.ts";
|
|
3
|
+
import type { InfixExpression, PostfixExpression } from "./infer.ts";
|
|
4
4
|
export type astToString<ast> = ast extends PostfixExpression<infer operator, infer operand> ? operator extends "[]" ? `${astToString<operand>}[]` : never : ast extends InfixExpression<infer operator, infer l, infer r> ? operator extends "&" | "|" | "%" | Comparator ? `${astToString<l>} ${operator} ${astToString<r>}` : never : ast extends Stringifiable ? `${ast extends bigint ? `${ast}n` : ast}` : "...";
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import type { arkKind, GenericParamAst, PrivateDeclaration, writeMissingSubmoduleAccessMessage, writeUnsatisfiedParameterConstraintMessage } from "@ark/schema";
|
|
2
2
|
import type { anyOrNever, array, BigintLiteral, charsAfterFirst, Completion, ErrorMessage, typeToString, writeMalformedNumericLiteralMessage } from "@ark/util";
|
|
3
|
-
import type { Generic } from "../../generic.
|
|
4
|
-
import type { Comparator } from "../string/reduce/shared.
|
|
5
|
-
import type { writeInvalidGenericArgCountMessage } from "../string/shift/operand/genericArgs.
|
|
6
|
-
import type { UnitLiteral } from "../string/shift/operator/default.
|
|
7
|
-
import type { parseString } from "../string/string.
|
|
8
|
-
import type { validateRange } from "./bounds.
|
|
9
|
-
import type { validateDefault } from "./default.
|
|
10
|
-
import type { validateDivisor } from "./divisor.
|
|
11
|
-
import type { GenericInstantiationAst, inferAstRoot, InfixExpression, PostfixExpression } from "./infer.
|
|
12
|
-
import type { validateKeyof } from "./keyof.
|
|
13
|
-
import type { astToString } from "./utils.
|
|
3
|
+
import type { Generic } from "../../generic.ts";
|
|
4
|
+
import type { Comparator } from "../string/reduce/shared.ts";
|
|
5
|
+
import type { writeInvalidGenericArgCountMessage } from "../string/shift/operand/genericArgs.ts";
|
|
6
|
+
import type { UnitLiteral } from "../string/shift/operator/default.ts";
|
|
7
|
+
import type { parseString } from "../string/string.ts";
|
|
8
|
+
import type { validateRange } from "./bounds.ts";
|
|
9
|
+
import type { validateDefault } from "./default.ts";
|
|
10
|
+
import type { validateDivisor } from "./divisor.ts";
|
|
11
|
+
import type { GenericInstantiationAst, inferAstRoot, InfixExpression, PostfixExpression } from "./infer.ts";
|
|
12
|
+
import type { validateKeyof } from "./keyof.ts";
|
|
13
|
+
import type { astToString } from "./utils.ts";
|
|
14
14
|
export type validateAst<ast, $, args> = ast extends string ? validateStringAst<ast, $> : ast extends PostfixExpression<infer operator, infer operand> ? operator extends "[]" ? validateAst<operand, $, args> : never : ast extends InfixExpression<infer operator, infer l, infer r> ? operator extends "&" | "|" ? validateInfix<ast, $, args> : operator extends Comparator ? validateRange<l, operator, r, $, args> : operator extends "%" ? validateDivisor<l, $, args> : undefined : ast extends [infer baseAst, "=", infer unitLiteral extends UnitLiteral] ? validateDefault<baseAst, unitLiteral, $, args> : ast extends ["keyof", infer operand] ? validateKeyof<operand, $, args> : ast extends GenericInstantiationAst<infer g, infer argAsts> ? validateGenericArgs<g["paramsAst"], argAsts, $, args, []> : ErrorMessage<writeUnexpectedExpressionMessage<astToString<ast>>> & {
|
|
15
15
|
ast: ast;
|
|
16
16
|
};
|
|
@@ -22,7 +22,7 @@ type validateStringAst<def extends string, $> = def extends `${infer n extends n
|
|
|
22
22
|
$[alias]
|
|
23
23
|
] extends [anyOrNever] ? def : def extends PrivateDeclaration ? ErrorMessage<writePrefixedPrivateReferenceMessage<def>> : $[alias] extends Generic ? ErrorMessage<writeInvalidGenericArgCountMessage<def, $[alias]["names"], []>> : $[alias] extends {
|
|
24
24
|
[arkKind]: "module";
|
|
25
|
-
} ? ErrorMessage<writeMissingSubmoduleAccessMessage<def>> : undefined : def extends ErrorMessage ? def : undefined;
|
|
25
|
+
} ? "$root" extends keyof $[alias] ? undefined : ErrorMessage<writeMissingSubmoduleAccessMessage<def>> : undefined : def extends ErrorMessage ? def : undefined;
|
|
26
26
|
export type maybeExtractAlias<def extends string, $> = def extends keyof $ ? def : `#${def}` extends keyof $ ? `#${def}` : null;
|
|
27
27
|
export type validateString<def extends string, $, args> = validateAst<parseString<def, $, args>, $, args> extends (infer result extends ErrorMessage) ? result extends Completion<infer text> ? text : result : def;
|
|
28
28
|
type validateInfix<ast extends InfixExpression, $, args> = validateAst<ast[0], $, args> extends infer e extends ErrorMessage ? e : validateAst<ast[2], $, args> extends infer e extends ErrorMessage ? e : undefined;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { BaseRoot } from "@ark/schema";
|
|
2
2
|
import { type requireKeys } from "@ark/util";
|
|
3
|
-
import type { LimitLiteral } from "../../../ast.
|
|
4
|
-
import type { ParseContext } from "../../../scope.
|
|
5
|
-
import type { InfixOperator } from "../../semantic/infer.
|
|
6
|
-
import type { Scanner } from "../shift/scanner.
|
|
7
|
-
import { type Comparator, type MinComparator, type OpenLeftBound, type StringifiablePrefixOperator } from "./shared.
|
|
3
|
+
import type { LimitLiteral } from "../../../ast.ts";
|
|
4
|
+
import type { ParseContext } from "../../../scope.ts";
|
|
5
|
+
import type { InfixOperator } from "../../semantic/infer.ts";
|
|
6
|
+
import type { Scanner } from "../shift/scanner.ts";
|
|
7
|
+
import { type Comparator, type MinComparator, type OpenLeftBound, type StringifiablePrefixOperator } from "./shared.ts";
|
|
8
8
|
type BranchState = {
|
|
9
9
|
prefixes: StringifiablePrefixOperator[];
|
|
10
10
|
leftBound: OpenLeftBound | null;
|
|
@@ -13,13 +13,13 @@ type BranchState = {
|
|
|
13
13
|
};
|
|
14
14
|
export type DynamicStateWithRoot = requireKeys<DynamicState, "root">;
|
|
15
15
|
export declare class DynamicState {
|
|
16
|
-
readonly scanner: Scanner;
|
|
17
|
-
readonly ctx: ParseContext;
|
|
18
|
-
readonly defaultable: boolean;
|
|
19
16
|
root: BaseRoot<any> | undefined;
|
|
20
17
|
branches: BranchState;
|
|
21
18
|
finalizer: Scanner.FinalizingLookahead | undefined;
|
|
22
19
|
groups: BranchState[];
|
|
20
|
+
scanner: Scanner;
|
|
21
|
+
ctx: ParseContext;
|
|
22
|
+
defaultable: boolean;
|
|
23
23
|
constructor(scanner: Scanner, ctx: ParseContext, defaultable: boolean);
|
|
24
24
|
error(message: string): never;
|
|
25
25
|
hasRoot(): this is DynamicStateWithRoot;
|
|
@@ -4,9 +4,6 @@ import { parseOperator } from "../shift/operator/operator.js";
|
|
|
4
4
|
import { parseUntilFinalizer } from "../string.js";
|
|
5
5
|
import { invertedComparators, minComparators, writeMultipleLeftBoundsMessage, writeOpenRangeMessage, writeUnclosedGroupMessage, writeUnmatchedGroupCloseMessage, writeUnpairableComparatorMessage } from "./shared.js";
|
|
6
6
|
export class DynamicState {
|
|
7
|
-
scanner;
|
|
8
|
-
ctx;
|
|
9
|
-
defaultable;
|
|
10
7
|
// set root type to `any` so that all constraints can be applied
|
|
11
8
|
root;
|
|
12
9
|
branches = {
|
|
@@ -17,6 +14,9 @@ export class DynamicState {
|
|
|
17
14
|
};
|
|
18
15
|
finalizer;
|
|
19
16
|
groups = [];
|
|
17
|
+
scanner;
|
|
18
|
+
ctx;
|
|
19
|
+
defaultable;
|
|
20
20
|
constructor(scanner, ctx, defaultable) {
|
|
21
21
|
this.scanner = scanner;
|
|
22
22
|
this.ctx = ctx;
|