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
package/out/keywords/internal.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { scope } from "../scope.js";
|
|
2
|
-
// these are needed to create some internal types
|
|
3
|
-
import { intrinsic, node } from "@ark/schema";
|
|
4
|
-
import "./tsKeywords.js";
|
|
5
|
-
export const internal = scope({
|
|
6
|
-
lengthBoundable: intrinsic.lengthBoundable,
|
|
7
|
-
key: intrinsic.key,
|
|
8
|
-
nonNegativeIntegerString: intrinsic.nonNegativeIntegerString
|
|
9
|
-
}, {
|
|
10
|
-
prereducedAliases: true
|
|
11
|
-
}).export();
|
|
12
|
-
// reduce union of all possible values reduces to unknown
|
|
13
|
-
node("union", {
|
|
14
|
-
branches: [
|
|
15
|
-
"string",
|
|
16
|
-
"number",
|
|
17
|
-
"object",
|
|
18
|
-
"bigint",
|
|
19
|
-
"symbol",
|
|
20
|
-
{ unit: true },
|
|
21
|
-
{ unit: false },
|
|
22
|
-
{ unit: null },
|
|
23
|
-
{ unit: undefined }
|
|
24
|
-
]
|
|
25
|
-
}, { reduceTo: node("intersection", {}, { prereduced: true }) });
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Module } from "../module.js";
|
|
2
|
-
export interface jsObjectExports {
|
|
3
|
-
Array: Array<unknown>;
|
|
4
|
-
Date: Date;
|
|
5
|
-
Error: Error;
|
|
6
|
-
Function: Function;
|
|
7
|
-
Map: Map<unknown, unknown>;
|
|
8
|
-
RegExp: RegExp;
|
|
9
|
-
Set: Set<unknown>;
|
|
10
|
-
WeakMap: WeakMap<object, unknown>;
|
|
11
|
-
WeakSet: WeakSet<object>;
|
|
12
|
-
Promise: Promise<unknown>;
|
|
13
|
-
}
|
|
14
|
-
export type jsObjects = Module<jsObjectExports>;
|
|
15
|
-
export declare const jsObjects: jsObjects;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { Out, number } from "../ast.js";
|
|
2
|
-
import type { Module } from "../module.js";
|
|
3
|
-
declare const number: import("@ark/schema").BaseRoot<import("@ark/schema").InternalRootDeclaration>;
|
|
4
|
-
export type FormDataValue = string | File;
|
|
5
|
-
export type ParsedFormData = Record<string, FormDataValue | FormDataValue[]>;
|
|
6
|
-
export type parsingExports = {
|
|
7
|
-
url: (In: string) => Out<URL>;
|
|
8
|
-
number: (In: string) => Out<number>;
|
|
9
|
-
integer: (In: string) => Out<number.divisibleBy<1>>;
|
|
10
|
-
date: (In: string) => Out<Date>;
|
|
11
|
-
json: (In: string) => Out<object>;
|
|
12
|
-
formData: (In: FormData) => Out<ParsedFormData>;
|
|
13
|
-
};
|
|
14
|
-
export type parsing = Module<parsingExports>;
|
|
15
|
-
export declare const parsing: parsing;
|
|
16
|
-
export {};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Module } from "../module.js";
|
|
2
|
-
export interface platformObjectExports {
|
|
3
|
-
ArrayBuffer: ArrayBuffer;
|
|
4
|
-
Blob: Blob;
|
|
5
|
-
File: File;
|
|
6
|
-
FormData: FormData;
|
|
7
|
-
Headers: Headers;
|
|
8
|
-
Request: Request;
|
|
9
|
-
Response: Response;
|
|
10
|
-
URL: URL;
|
|
11
|
-
}
|
|
12
|
-
export type platformObjects = Module<platformObjectExports>;
|
|
13
|
-
export declare const platformObjects: platformObjects;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { Hkt, type Key, type omit, type pick, type show } from "@ark/util";
|
|
2
|
-
import type { Module } from "../module.js";
|
|
3
|
-
import { type inferScope } from "../scope.js";
|
|
4
|
-
declare class RecordHkt extends Hkt<[Key, unknown]> {
|
|
5
|
-
body: Record<this[0], this[1]>;
|
|
6
|
-
}
|
|
7
|
-
declare class PickHkt extends Hkt<[object, Key]> {
|
|
8
|
-
body: pick<this[0], this[1] & keyof this[0]>;
|
|
9
|
-
}
|
|
10
|
-
declare class OmitHkt extends Hkt<[object, Key]> {
|
|
11
|
-
body: omit<this[0], this[1] & keyof this[0]>;
|
|
12
|
-
}
|
|
13
|
-
declare class PartialHkt extends Hkt<[object]> {
|
|
14
|
-
body: show<Partial<this[0]>>;
|
|
15
|
-
}
|
|
16
|
-
declare class RequiredHkt extends Hkt<[object]> {
|
|
17
|
-
body: show<Required<this[0]>>;
|
|
18
|
-
}
|
|
19
|
-
declare class ExcludeHkt extends Hkt<[unknown, unknown]> {
|
|
20
|
-
body: Exclude<this[0], this[1]>;
|
|
21
|
-
}
|
|
22
|
-
declare class ExtractHkt extends Hkt<[unknown, unknown]> {
|
|
23
|
-
body: Extract<this[0], this[1]>;
|
|
24
|
-
}
|
|
25
|
-
declare const tsGenericsExports: {
|
|
26
|
-
Record: import("@ark/schema").GenericRoot<readonly [["K", Key], ["V", unknown]], RecordHkt>;
|
|
27
|
-
Pick: import("@ark/schema").GenericRoot<readonly [["T", object], ["K", Key]], PickHkt>;
|
|
28
|
-
Omit: import("@ark/schema").GenericRoot<readonly [["T", object], ["K", Key]], OmitHkt>;
|
|
29
|
-
Exclude: import("@ark/schema").GenericRoot<readonly [["T", unknown], ["U", unknown]], ExcludeHkt>;
|
|
30
|
-
Extract: import("@ark/schema").GenericRoot<readonly [["T", unknown], ["U", unknown]], ExtractHkt>;
|
|
31
|
-
Partial: import("@ark/schema").GenericRoot<readonly [["T", object]], PartialHkt>;
|
|
32
|
-
Required: import("@ark/schema").GenericRoot<readonly [["T", object]], RequiredHkt>;
|
|
33
|
-
};
|
|
34
|
-
export type tsGenericsExports = inferScope<typeof tsGenericsExports>;
|
|
35
|
-
export type tsGenerics = Module<tsGenericsExports>;
|
|
36
|
-
export declare const tsGenerics: tsGenerics;
|
|
37
|
-
export {};
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { genericNode } from "@ark/schema";
|
|
2
|
-
import { Hkt } from "@ark/util";
|
|
3
|
-
import { scope } from "../scope.js";
|
|
4
|
-
import { internal } from "./internal.js";
|
|
5
|
-
import { tsKeywords } from "./tsKeywords.js";
|
|
6
|
-
class RecordHkt extends Hkt {
|
|
7
|
-
}
|
|
8
|
-
const Record = genericNode(["K", internal.key], "V")(args => ({
|
|
9
|
-
domain: "object",
|
|
10
|
-
index: {
|
|
11
|
-
signature: args.K,
|
|
12
|
-
value: args.V
|
|
13
|
-
}
|
|
14
|
-
}), RecordHkt);
|
|
15
|
-
class PickHkt extends Hkt {
|
|
16
|
-
}
|
|
17
|
-
const Pick = genericNode(["T", tsKeywords.object], ["K", internal.key])(args => args.T.pick(args.K), PickHkt);
|
|
18
|
-
class OmitHkt extends Hkt {
|
|
19
|
-
}
|
|
20
|
-
const Omit = genericNode(["T", tsKeywords.object], ["K", internal.key])(args => args.T.omit(args.K), OmitHkt);
|
|
21
|
-
class PartialHkt extends Hkt {
|
|
22
|
-
}
|
|
23
|
-
const Partial = genericNode(["T", tsKeywords.object])(args => args.T.partial(), PartialHkt);
|
|
24
|
-
class RequiredHkt extends Hkt {
|
|
25
|
-
}
|
|
26
|
-
const Required = genericNode(["T", tsKeywords.object])(args => args.T.required(), RequiredHkt);
|
|
27
|
-
class ExcludeHkt extends Hkt {
|
|
28
|
-
}
|
|
29
|
-
const Exclude = genericNode("T", "U")(args => args.T.exclude(args.U), ExcludeHkt);
|
|
30
|
-
class ExtractHkt extends Hkt {
|
|
31
|
-
}
|
|
32
|
-
const Extract = genericNode("T", "U")(args => args.T.extract(args.U), ExtractHkt);
|
|
33
|
-
const tsGenericsExports = {
|
|
34
|
-
Record,
|
|
35
|
-
Pick,
|
|
36
|
-
Omit,
|
|
37
|
-
Exclude,
|
|
38
|
-
Extract,
|
|
39
|
-
Partial,
|
|
40
|
-
Required
|
|
41
|
-
};
|
|
42
|
-
const $ = scope(tsGenericsExports, {
|
|
43
|
-
prereducedAliases: true
|
|
44
|
-
});
|
|
45
|
-
export const tsGenerics = $.export();
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { Module } from "../module.js";
|
|
2
|
-
export interface tsKeywordExports {
|
|
3
|
-
any: any;
|
|
4
|
-
bigint: bigint;
|
|
5
|
-
boolean: boolean;
|
|
6
|
-
false: false;
|
|
7
|
-
never: never;
|
|
8
|
-
null: null;
|
|
9
|
-
number: number;
|
|
10
|
-
object: object;
|
|
11
|
-
string: string;
|
|
12
|
-
symbol: symbol;
|
|
13
|
-
true: true;
|
|
14
|
-
unknown: unknown;
|
|
15
|
-
undefined: undefined;
|
|
16
|
-
}
|
|
17
|
-
export type tsKeywords = Module<tsKeywordExports>;
|
|
18
|
-
export declare const tsKeywords: tsKeywords;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { intrinsic } from "@ark/schema";
|
|
2
|
-
import { scope } from "../scope.js";
|
|
3
|
-
export const tsKeywords = scope({
|
|
4
|
-
any: intrinsic.unknown,
|
|
5
|
-
bigint: intrinsic.bigint,
|
|
6
|
-
boolean: intrinsic.boolean,
|
|
7
|
-
false: intrinsic.false,
|
|
8
|
-
never: intrinsic.never,
|
|
9
|
-
null: intrinsic.null,
|
|
10
|
-
number: intrinsic.number,
|
|
11
|
-
object: intrinsic.object,
|
|
12
|
-
string: intrinsic.string,
|
|
13
|
-
symbol: intrinsic.symbol,
|
|
14
|
-
true: intrinsic.true,
|
|
15
|
-
unknown: intrinsic.unknown,
|
|
16
|
-
undefined: intrinsic.undefined
|
|
17
|
-
}, { prereducedAliases: true }).export();
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { anonymous, AtLeast, AtMost, DivisibleBy, number, string } from "../ast.js";
|
|
2
|
-
import type { Module } from "../module.js";
|
|
3
|
-
export interface validationExports {
|
|
4
|
-
alpha: string.matching<anonymous>;
|
|
5
|
-
alphanumeric: string.matching<anonymous>;
|
|
6
|
-
digits: string.matching<anonymous>;
|
|
7
|
-
lowercase: string.matching<anonymous>;
|
|
8
|
-
uppercase: string.matching<anonymous>;
|
|
9
|
-
creditCard: string.matching<anonymous>;
|
|
10
|
-
email: string.matching<anonymous>;
|
|
11
|
-
uuid: string.matching<anonymous>;
|
|
12
|
-
url: string.matching<anonymous>;
|
|
13
|
-
semver: string.matching<anonymous>;
|
|
14
|
-
ip: string.matching<anonymous>;
|
|
15
|
-
integer: number.divisibleBy<1>;
|
|
16
|
-
unixTimestamp: number.is<DivisibleBy<1> & AtMost<8640000000000000> & AtLeast<-8640000000000000>>;
|
|
17
|
-
}
|
|
18
|
-
export type validation = Module<validationExports>;
|
|
19
|
-
export declare const validation: validation;
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { rootNode } from "@ark/schema";
|
|
2
|
-
import { scope } from "../scope.js";
|
|
3
|
-
import { creditCardMatcher, isLuhnValid } from "./utils/creditCard.js";
|
|
4
|
-
import { ip } from "./utils/ip.js";
|
|
5
|
-
import { regexStringNode } from "./utils/regex.js";
|
|
6
|
-
// Non-trivial expressions should have an explanation or attribution
|
|
7
|
-
const url = rootNode({
|
|
8
|
-
domain: "string",
|
|
9
|
-
predicate: {
|
|
10
|
-
meta: "a valid URL",
|
|
11
|
-
predicate: (s) => {
|
|
12
|
-
try {
|
|
13
|
-
new URL(s);
|
|
14
|
-
}
|
|
15
|
-
catch {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
return true;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
// https://www.regular-expressions.info/email.html
|
|
23
|
-
const emailMatcher = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/;
|
|
24
|
-
const email = regexStringNode(emailMatcher, "a valid email");
|
|
25
|
-
const uuidMatcher = /^[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}$/;
|
|
26
|
-
// https://github.com/validatorjs/validator.js/blob/master/src/lib/isUUID.js
|
|
27
|
-
const uuid = regexStringNode(uuidMatcher, "a valid UUID");
|
|
28
|
-
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-]+)*))?$/;
|
|
29
|
-
// https://semver.org/
|
|
30
|
-
const semver = regexStringNode(semverMatcher, "a valid semantic version (see https://semver.org/)");
|
|
31
|
-
const creditCard = rootNode({
|
|
32
|
-
domain: "string",
|
|
33
|
-
pattern: {
|
|
34
|
-
meta: "a valid credit card number",
|
|
35
|
-
rule: creditCardMatcher.source
|
|
36
|
-
},
|
|
37
|
-
predicate: {
|
|
38
|
-
meta: "a valid credit card number",
|
|
39
|
-
predicate: isLuhnValid
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
/**
|
|
43
|
-
* As per the ECMA-262 specification:
|
|
44
|
-
* A time value supports a slightly smaller range of -8,640,000,000,000,000 to 8,640,000,000,000,000 milliseconds.
|
|
45
|
-
*
|
|
46
|
-
* @see https://262.ecma-international.org/15.0/index.html#sec-time-values-and-time-range
|
|
47
|
-
*/
|
|
48
|
-
const unixTimestamp = rootNode({
|
|
49
|
-
domain: {
|
|
50
|
-
domain: "number",
|
|
51
|
-
meta: "a number representing a Unix timestamp"
|
|
52
|
-
},
|
|
53
|
-
divisor: {
|
|
54
|
-
rule: 1,
|
|
55
|
-
meta: `an integer representing a Unix timestamp`
|
|
56
|
-
},
|
|
57
|
-
min: {
|
|
58
|
-
rule: -8640000000000000,
|
|
59
|
-
meta: `a Unix timestamp after -8640000000000000`
|
|
60
|
-
},
|
|
61
|
-
max: {
|
|
62
|
-
rule: 8640000000000000,
|
|
63
|
-
meta: "a Unix timestamp before 8640000000000000"
|
|
64
|
-
},
|
|
65
|
-
meta: "an integer representing a safe Unix timestamp"
|
|
66
|
-
});
|
|
67
|
-
export const validation = scope({
|
|
68
|
-
alpha: regexStringNode(/^[A-Za-z]*$/, "only letters"),
|
|
69
|
-
alphanumeric: regexStringNode(/^[A-Za-z\d]*$/, "only letters and digits 0-9"),
|
|
70
|
-
digits: regexStringNode(/^\d*$/, "only digits 0-9"),
|
|
71
|
-
lowercase: regexStringNode(/^[a-z]*$/, "only lowercase letters"),
|
|
72
|
-
uppercase: regexStringNode(/^[A-Z]*$/, "only uppercase letters"),
|
|
73
|
-
creditCard,
|
|
74
|
-
email,
|
|
75
|
-
uuid,
|
|
76
|
-
url,
|
|
77
|
-
semver,
|
|
78
|
-
ip,
|
|
79
|
-
integer: rootNode({
|
|
80
|
-
domain: "number",
|
|
81
|
-
divisor: 1
|
|
82
|
-
}),
|
|
83
|
-
unixTimestamp
|
|
84
|
-
}, { prereducedAliases: true }).export();
|