arktype 0.4.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/nodes/branch.js +18 -18
- package/dist/cjs/nodes/discriminate.js +86 -18
- package/dist/cjs/nodes/rules/class.js +2 -2
- package/dist/cjs/nodes/rules/divisor.js +1 -1
- package/dist/cjs/nodes/rules/props.js +1 -2
- package/dist/cjs/nodes/rules/range.js +1 -1
- package/dist/cjs/nodes/rules/regex.js +1 -1
- package/dist/cjs/parse/ast/morph.js +1 -1
- package/dist/cjs/parse/ast/tuple.js +3 -2
- package/dist/cjs/parse/string/shift/operator/bounds.js +1 -1
- package/dist/cjs/scopes/scope.js +5 -4
- package/dist/cjs/scopes/validation.js +16 -1
- package/dist/cjs/traverse/problems.js +22 -20
- package/dist/cjs/traverse/traverse.js +53 -46
- package/dist/cjs/utils/freeze.js +2 -3
- package/dist/cjs/utils/numericLiterals.js +2 -14
- package/dist/cjs/utils/serialize.js +3 -3
- package/dist/mjs/nodes/discriminate.js +87 -19
- package/dist/mjs/nodes/rules/class.js +2 -2
- package/dist/mjs/nodes/rules/divisor.js +1 -1
- package/dist/mjs/nodes/rules/props.js +1 -2
- package/dist/mjs/nodes/rules/range.js +1 -1
- package/dist/mjs/nodes/rules/regex.js +1 -1
- package/dist/mjs/parse/ast/morph.js +1 -1
- package/dist/mjs/parse/ast/tuple.js +3 -2
- package/dist/mjs/parse/string/shift/operator/bounds.js +2 -2
- package/dist/mjs/scopes/scope.js +5 -4
- package/dist/mjs/scopes/validation.js +16 -1
- package/dist/mjs/traverse/problems.js +20 -19
- package/dist/mjs/traverse/traverse.js +25 -18
- package/dist/mjs/utils/freeze.js +2 -3
- package/dist/mjs/utils/numericLiterals.js +1 -1
- package/dist/tsconfig.temp.tsbuildinfo +1 -1
- package/dist/types/nodes/discriminate.d.ts +6 -8
- package/dist/types/nodes/rules/range.d.ts +2 -2
- package/dist/types/parse/ast/divisor.d.ts +3 -3
- package/dist/types/parse/ast/morph.d.ts +8 -5
- package/dist/types/parse/ast/narrow.d.ts +8 -8
- package/dist/types/parse/ast/tuple.d.ts +5 -5
- package/dist/types/parse/string/shift/scanner.d.ts +1 -1
- package/dist/types/scopes/expressions.d.ts +2 -2
- package/dist/types/scopes/scope.d.ts +2 -2
- package/dist/types/scopes/standard.d.ts +15 -0
- package/dist/types/scopes/validation.d.ts +4 -0
- package/dist/types/traverse/problems.d.ts +9 -7
- package/dist/types/traverse/traverse.d.ts +3 -2
- package/dist/types/utils/generics.d.ts +1 -1
- package/dist/types/utils/numericLiterals.d.ts +16 -0
- package/dist/types/utils/paths.d.ts +1 -1
- package/dist/types/utils/unionToTuple.d.ts +2 -2
- package/package.json +7 -7
|
@@ -72,7 +72,7 @@ export declare namespace Scanner {
|
|
|
72
72
|
readonly "&": true;
|
|
73
73
|
};
|
|
74
74
|
type BranchToken = keyof typeof branchTokens;
|
|
75
|
-
type InfixToken = BranchToken | Comparator | "%" | ":" | "=>";
|
|
75
|
+
type InfixToken = BranchToken | Comparator | "%" | ":" | "=>" | "|>";
|
|
76
76
|
type PostfixToken = "[]";
|
|
77
77
|
type OperatorToken = InfixToken | PostfixToken;
|
|
78
78
|
const escapeToken = "\\";
|
|
@@ -14,8 +14,8 @@ export type Expressions<$> = {
|
|
|
14
14
|
fromNode: UnvalidatedExpressionParser<$, "node">;
|
|
15
15
|
instanceOf: UnvalidatedExpressionParser<$, "instanceof">;
|
|
16
16
|
valueOf: UnvalidatedExpressionParser<$, "===">;
|
|
17
|
-
narrow: FunctionalExpressionParser<$, "
|
|
18
|
-
morph: FunctionalExpressionParser<$, "
|
|
17
|
+
narrow: FunctionalExpressionParser<$, "=>">;
|
|
18
|
+
morph: FunctionalExpressionParser<$, "|>">;
|
|
19
19
|
};
|
|
20
20
|
type Standard = Expressions<PrecompiledDefaults>;
|
|
21
21
|
export declare const intersection: Standard["intersection"];
|
|
@@ -75,8 +75,8 @@ export declare class Scope<context extends ScopeContext = any> {
|
|
|
75
75
|
keyOf: import("./expressions.js").UnaryExpressionParser<resolutions<context>, "keyof">;
|
|
76
76
|
valueOf: import("./expressions.js").UnvalidatedExpressionParser<resolutions<context>, "===">;
|
|
77
77
|
instanceOf: import("./expressions.js").UnvalidatedExpressionParser<resolutions<context>, "instanceof">;
|
|
78
|
-
narrow: import("./expressions.js").FunctionalExpressionParser<resolutions<context>, "
|
|
79
|
-
morph: import("./expressions.js").FunctionalExpressionParser<resolutions<context>, "
|
|
78
|
+
narrow: import("./expressions.js").FunctionalExpressionParser<resolutions<context>, "=>">;
|
|
79
|
+
morph: import("./expressions.js").FunctionalExpressionParser<resolutions<context>, "|>">;
|
|
80
80
|
type: TypeParser<resolutions<context>>;
|
|
81
81
|
}
|
|
82
82
|
export declare const scope: ScopeParser;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Out } from "../parse/ast/morph.js";
|
|
1
2
|
import type { InferredObjectKinds } from "../utils/objectKinds.js";
|
|
2
3
|
import type { Space } from "./scope.js";
|
|
3
4
|
import type { TypeParser } from "./type.js";
|
|
@@ -39,6 +40,8 @@ export declare const standardScope: import("./scope.js").Scope<[{
|
|
|
39
40
|
creditCard: string;
|
|
40
41
|
email: string;
|
|
41
42
|
uuid: string;
|
|
43
|
+
parsedNumber: (In: string) => Out<number>;
|
|
44
|
+
parsedInteger: (In: string) => Out<number>;
|
|
42
45
|
integer: number;
|
|
43
46
|
}, {}, false]>;
|
|
44
47
|
export declare const standard: Space<{
|
|
@@ -79,6 +82,8 @@ export declare const standard: Space<{
|
|
|
79
82
|
creditCard: string;
|
|
80
83
|
email: string;
|
|
81
84
|
uuid: string;
|
|
85
|
+
parsedNumber: (In: string) => Out<number>;
|
|
86
|
+
parsedInteger: (In: string) => Out<number>;
|
|
82
87
|
integer: number;
|
|
83
88
|
}>;
|
|
84
89
|
export declare const scopes: {
|
|
@@ -124,6 +129,8 @@ export declare const scopes: {
|
|
|
124
129
|
creditCard: string;
|
|
125
130
|
email: string;
|
|
126
131
|
uuid: string;
|
|
132
|
+
parsedNumber: (In: string) => Out<number>;
|
|
133
|
+
parsedInteger: (In: string) => Out<number>;
|
|
127
134
|
integer: number;
|
|
128
135
|
}, {}, false]>;
|
|
129
136
|
standard: import("./scope.js").Scope<[{
|
|
@@ -164,6 +171,8 @@ export declare const scopes: {
|
|
|
164
171
|
creditCard: string;
|
|
165
172
|
email: string;
|
|
166
173
|
uuid: string;
|
|
174
|
+
parsedNumber: (In: string) => Out<number>;
|
|
175
|
+
parsedInteger: (In: string) => Out<number>;
|
|
167
176
|
integer: number;
|
|
168
177
|
}, {}, false]>;
|
|
169
178
|
};
|
|
@@ -210,6 +219,8 @@ export declare const spaces: {
|
|
|
210
219
|
creditCard: string;
|
|
211
220
|
email: string;
|
|
212
221
|
uuid: string;
|
|
222
|
+
parsedNumber: (In: string) => Out<number>;
|
|
223
|
+
parsedInteger: (In: string) => Out<number>;
|
|
213
224
|
integer: number;
|
|
214
225
|
}>;
|
|
215
226
|
standard: Space<{
|
|
@@ -250,6 +261,8 @@ export declare const spaces: {
|
|
|
250
261
|
creditCard: string;
|
|
251
262
|
email: string;
|
|
252
263
|
uuid: string;
|
|
264
|
+
parsedNumber: (In: string) => Out<number>;
|
|
265
|
+
parsedInteger: (In: string) => Out<number>;
|
|
253
266
|
integer: number;
|
|
254
267
|
}>;
|
|
255
268
|
};
|
|
@@ -276,5 +289,7 @@ export type PrecompiledDefaults = {
|
|
|
276
289
|
creditCard: string;
|
|
277
290
|
email: string;
|
|
278
291
|
uuid: string;
|
|
292
|
+
parsedNumber: (In: string) => Out<number>;
|
|
293
|
+
parsedInteger: (In: string) => Out<number>;
|
|
279
294
|
} & InferredObjectKinds;
|
|
280
295
|
export declare const type: TypeParser<PrecompiledDefaults>;
|
|
@@ -7,6 +7,8 @@ export declare const validationScope: import("./scope.js").Scope<[{
|
|
|
7
7
|
creditCard: string;
|
|
8
8
|
email: string;
|
|
9
9
|
uuid: string;
|
|
10
|
+
parsedNumber: (In: string) => import("../parse/ast/morph.js").Out<number>;
|
|
11
|
+
parsedInteger: (In: string) => import("../parse/ast/morph.js").Out<number>;
|
|
10
12
|
integer: number;
|
|
11
13
|
}, {}, false]>;
|
|
12
14
|
export declare const validation: import("./scope.js").Space<{
|
|
@@ -17,5 +19,7 @@ export declare const validation: import("./scope.js").Space<{
|
|
|
17
19
|
creditCard: string;
|
|
18
20
|
email: string;
|
|
19
21
|
uuid: string;
|
|
22
|
+
parsedNumber: (In: string) => import("../parse/ast/morph.js").Out<number>;
|
|
23
|
+
parsedInteger: (In: string) => import("../parse/ast/morph.js").Out<number>;
|
|
20
24
|
integer: number;
|
|
21
25
|
}>;
|
|
@@ -22,36 +22,38 @@ export declare class Problem<code extends ProblemCode = any> {
|
|
|
22
22
|
get reason(): string;
|
|
23
23
|
get mustBe(): string;
|
|
24
24
|
}
|
|
25
|
-
export type AddProblemOptions<
|
|
26
|
-
data?:
|
|
25
|
+
export type AddProblemOptions<data = unknown> = {
|
|
26
|
+
data?: data;
|
|
27
27
|
path?: Path;
|
|
28
28
|
};
|
|
29
29
|
declare class ProblemArray extends Array<Problem> {
|
|
30
30
|
#private;
|
|
31
31
|
byPath: Record<string, Problem>;
|
|
32
|
+
count: number;
|
|
32
33
|
constructor(state: TraversalState);
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
add<code extends ProblemCode>(code: code, source: ProblemSource<code>, opts?: AddProblemOptions<ProblemData<code>>): Problem;
|
|
35
|
+
addProblem(problem: Problem): void;
|
|
35
36
|
get summary(): string;
|
|
36
37
|
toString(): string;
|
|
37
38
|
throw(): never;
|
|
38
39
|
}
|
|
39
40
|
export declare const Problems: new (state: TraversalState) => arraySubclassToReadonly<ProblemArray>;
|
|
40
41
|
export type Problems = instanceOf<typeof Problems>;
|
|
41
|
-
export declare const
|
|
42
|
+
export declare const domainsToDescriptions: (domains: Domain[]) => ("boolean" | "undefined" | "null" | "a bigint" | "a number" | "an object" | "a string" | "a symbol")[];
|
|
43
|
+
export declare const objectKindsToDescriptions: (kinds: DefaultObjectKind[]) => ("an object" | "an array" | "a function" | "a Date" | "a RegExp" | "an Error" | "a Map" | "a Set" | "a String object" | "a Number object" | "a Boolean object" | "a Promise" | "a WeakMap" | "a WeakSet")[];
|
|
42
44
|
export declare const describeBranches: (descriptions: string[]) => string;
|
|
43
45
|
type ProblemSources = {
|
|
44
46
|
divisor: number;
|
|
45
47
|
class: DefaultObjectKind | constructor;
|
|
46
48
|
domain: Domain;
|
|
47
|
-
domainBranches: Domain[];
|
|
48
49
|
missing: undefined;
|
|
49
50
|
bound: FlatBound;
|
|
50
51
|
regex: RegexLiteral;
|
|
51
52
|
value: unknown;
|
|
52
|
-
valueBranches: unknown[];
|
|
53
53
|
multi: Problem[];
|
|
54
54
|
branches: readonly Problem[];
|
|
55
|
+
mustBe: string;
|
|
56
|
+
cases: string[];
|
|
55
57
|
};
|
|
56
58
|
export type ProblemCode = evaluate<keyof ProblemSources>;
|
|
57
59
|
export type ProblemSource<code extends ProblemCode = ProblemCode> = ProblemSources[code];
|
|
@@ -14,9 +14,10 @@ export declare class TraversalState<data = unknown> {
|
|
|
14
14
|
problems: import("../utils/generics.js").arraySubclassToReadonly<{
|
|
15
15
|
[n: number]: Problem<any>;
|
|
16
16
|
byPath: Record<string, Problem<any>>;
|
|
17
|
+
count: number;
|
|
17
18
|
"__#2@#state": TraversalState<unknown>;
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
add<code extends ProblemCode>(code: code, source: import("./problems.js").ProblemSource<code>, opts?: import("./problems.js").AddProblemOptions<import("./problems.js").ProblemData<code>> | undefined): Problem<any>;
|
|
20
|
+
addProblem(problem: Problem<any>): void;
|
|
20
21
|
readonly summary: string;
|
|
21
22
|
toString(): string;
|
|
22
23
|
throw(): never;
|
|
@@ -44,7 +44,7 @@ export declare const objectKeysOf: <o extends object>(o: o) => objectKeysOf<o>[]
|
|
|
44
44
|
export type stringKeyOf<o> = keyof o & string;
|
|
45
45
|
/** Mimics output of TS's keyof operator at runtime */
|
|
46
46
|
export declare const prototypeKeysOf: <t>(value: t) => (keyof t)[];
|
|
47
|
-
export declare const hasKey: <o, k extends string>(o: o, k: k) => o is o
|
|
47
|
+
export declare const hasKey: <o, k extends string>(o: o, k: k) => o is Extract<o, { [_ in k]: {}; }>;
|
|
48
48
|
export declare const keyCount: (o: object) => number;
|
|
49
49
|
export type keySet<key extends string = string> = {
|
|
50
50
|
readonly [_ in key]?: true;
|
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
export type BigintLiteral<Value extends bigint = bigint> = `${Value}n`;
|
|
2
2
|
export type NumberLiteral<Value extends number = number> = `${Value}`;
|
|
3
3
|
export type IntegerLiteral<Value extends bigint = bigint> = `${Value}`;
|
|
4
|
+
/**
|
|
5
|
+
* The goal of the number literal and bigint literal regular expressions is to:
|
|
6
|
+
*
|
|
7
|
+
* 1. Ensure definitions form a bijection with the values they represent.
|
|
8
|
+
* 2. Attempt to mirror TypeScript's own format for stringification of numeric
|
|
9
|
+
* values such that the regex should match a given definition if any only if
|
|
10
|
+
* a precise literal type will be inferred (in TS4.8+).
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Matches a well-formatted numeric expression according to the following rules:
|
|
14
|
+
* 1. Must include an integer portion (i.e. '.321' must be written as '0.321')
|
|
15
|
+
* 2. The first digit of the value must not be 0, unless the entire integer portion is 0
|
|
16
|
+
* 3. If the value includes a decimal, its last digit may not be 0
|
|
17
|
+
* 4. The value may not be "-0"
|
|
18
|
+
*/
|
|
19
|
+
export declare const wellFormedNumberMatcher: RegExp;
|
|
4
20
|
/**
|
|
5
21
|
* Matches a well-formatted integer according to the following rules:
|
|
6
22
|
* 1. Must begin with an integer, the first digit of which cannot be 0 unless the entire value is 0
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { arraySubclassToReadonly } from "./generics";
|
|
1
|
+
import type { arraySubclassToReadonly } from "./generics.js";
|
|
2
2
|
export declare class Path extends Array<string> {
|
|
3
3
|
static fromString(s: string, delimiter?: string): Path;
|
|
4
4
|
toString(delimiter?: string): string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { conform } from "./generics";
|
|
2
|
-
import type { join } from "./paths";
|
|
1
|
+
import type { conform } from "./generics.js";
|
|
2
|
+
import type { join } from "./paths.js";
|
|
3
3
|
export type stringifyUnion<t extends string> = join<unionToTuple<t>, ", ">;
|
|
4
4
|
export type unionToTuple<t> = unionToTupleRecurse<t, []> extends infer result ? conform<result, t[]> : never;
|
|
5
5
|
type unionToTupleRecurse<t, result extends unknown[]> = getLastBranch<t> extends infer current ? {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "arktype",
|
|
3
3
|
"description": "Isomorphic types for TS/JS",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.1",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "David Blass",
|
|
7
7
|
"email": "david@arktype.io",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"extends": "./dev/configs/.eslintrc.cjs"
|
|
83
83
|
},
|
|
84
84
|
"scripts": {
|
|
85
|
-
"prChecks": "pnpm install && pnpm build && pnpm typecheck && pnpm lint && pnpm
|
|
85
|
+
"prChecks": "pnpm install && pnpm build && pnpm typecheck && pnpm lint && pnpm testRepo && pnpm docgen && pnpm buildSite",
|
|
86
86
|
"typecheck": "tsc --noEmit",
|
|
87
87
|
"build": "ts-node ./dev/scripts/build.ts",
|
|
88
88
|
"buildRepo": "pnpm build && pnpm docgen && pnpm buildSite",
|
|
@@ -90,12 +90,12 @@
|
|
|
90
90
|
"docgen": "ts-node ./dev/scripts/docgen.ts",
|
|
91
91
|
"test": "ts-node ./dev/attest/cli.ts --cmd mocha",
|
|
92
92
|
"testCov": "c8 pnpm test",
|
|
93
|
-
"testBuild": "ts-node ./dev/scripts/testBuild.ts",
|
|
94
|
-
"buildThenTest": "pnpm build --test && pnpm testBuild",
|
|
95
93
|
"tnt": "ts-node ./dev/attest/cli.ts --skipTypes --cmd mocha",
|
|
96
|
-
"
|
|
97
|
-
"
|
|
98
|
-
"
|
|
94
|
+
"testRepo": " pnpm testBuild && pnpm testTsVersions && pnpm testAttest && pnpm testDeno",
|
|
95
|
+
"testBuild": "ts-node ./dev/scripts/testBuild.ts",
|
|
96
|
+
"testAttest": "ts-node ./dev/scripts/testAttest.ts",
|
|
97
|
+
"testTsVersions": "ts-node ./dev/scripts/testTsVersions.ts",
|
|
98
|
+
"testDeno": "deno task test",
|
|
99
99
|
"bench": "ts-node ./dev/attest/cli.ts bench --benchmarksPath ./test/benchmarks.json",
|
|
100
100
|
"lint": "eslint --max-warnings=0 .",
|
|
101
101
|
"format": "prettier --write --ignore-path ./dev/configs/.prettierignore .",
|