arktype 0.2.0 → 0.4.0
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/api.cjs +9 -0
- package/dist/api.d.ts +10 -0
- package/dist/api.mjs +1 -0
- package/dist/cjs/nodes/{branches.js → branch.js} +65 -10
- package/dist/cjs/nodes/compose.js +2 -3
- package/dist/cjs/nodes/discriminate.js +9 -15
- package/dist/cjs/nodes/node.js +21 -11
- package/dist/cjs/nodes/predicate.js +8 -10
- package/dist/cjs/nodes/rules/class.js +10 -4
- package/dist/cjs/nodes/rules/divisor.js +1 -5
- package/dist/cjs/nodes/rules/props.js +75 -25
- package/dist/cjs/nodes/rules/range.js +2 -6
- package/dist/cjs/nodes/rules/regex.js +1 -5
- package/dist/cjs/nodes/rules/rules.js +23 -63
- package/dist/cjs/parse/ast/ast.js +4 -0
- package/dist/cjs/parse/ast/bound.js +9 -0
- package/dist/cjs/parse/{tuple/utils.js → ast/distributableFunction.js} +1 -1
- package/dist/cjs/parse/ast/divisor.js +9 -0
- package/dist/cjs/parse/{string/ast.js → ast/intersection.js} +2 -8
- package/dist/cjs/parse/ast/keyof.js +109 -0
- package/dist/cjs/parse/{tuple → ast}/morph.js +2 -2
- package/dist/cjs/parse/{tuple → ast}/narrow.js +2 -2
- package/dist/cjs/parse/{tuple → ast}/tuple.js +23 -16
- package/dist/cjs/parse/ast/union.js +9 -0
- package/dist/cjs/parse/ast/utils.js +4 -0
- package/dist/cjs/parse/definition.js +12 -2
- package/dist/cjs/parse/string/reduce/dynamic.js +7 -8
- package/dist/cjs/parse/string/shift/operator/bounds.js +4 -4
- package/dist/cjs/parse/string/shift/operator/divisor.js +3 -3
- package/dist/cjs/parse/string/string.js +2 -2
- package/dist/cjs/scopes/expressions.js +29 -0
- package/dist/cjs/scopes/jsObjects.js +14 -14
- package/dist/cjs/scopes/scope.js +56 -4
- package/dist/cjs/scopes/type.js +4 -7
- package/dist/cjs/traverse/problems.js +67 -53
- package/dist/cjs/traverse/traverse.js +103 -135
- package/dist/cjs/utils/data.js +39 -0
- package/dist/cjs/utils/generics.js +20 -2
- package/dist/cjs/utils/numericLiterals.js +2 -0
- package/dist/cjs/utils/objectKinds.js +1 -2
- package/dist/mjs/nodes/{branches.js → branch.js} +54 -2
- package/dist/mjs/nodes/compose.js +3 -4
- package/dist/mjs/nodes/discriminate.js +9 -15
- package/dist/mjs/nodes/node.js +17 -8
- package/dist/mjs/nodes/predicate.js +4 -5
- package/dist/mjs/nodes/rules/class.js +10 -4
- package/dist/mjs/nodes/rules/divisor.js +1 -5
- package/dist/mjs/nodes/rules/props.js +74 -27
- package/dist/mjs/nodes/rules/range.js +2 -6
- package/dist/mjs/nodes/rules/regex.js +1 -5
- package/dist/mjs/nodes/rules/rules.js +23 -62
- package/dist/mjs/parse/ast/ast.js +1 -0
- package/dist/mjs/parse/ast/bound.js +1 -0
- package/dist/mjs/parse/{tuple/utils.js → ast/distributableFunction.js} +2 -2
- package/dist/mjs/parse/ast/divisor.js +1 -0
- package/dist/mjs/parse/{string/ast.js → ast/intersection.js} +2 -5
- package/dist/mjs/parse/ast/keyof.js +101 -0
- package/dist/mjs/parse/{tuple → ast}/morph.js +2 -2
- package/dist/mjs/parse/ast/narrow.js +7 -0
- package/dist/mjs/parse/{tuple → ast}/tuple.js +24 -17
- package/dist/mjs/parse/ast/union.js +1 -0
- package/dist/mjs/parse/ast/utils.js +1 -0
- package/dist/mjs/parse/definition.js +12 -2
- package/dist/mjs/parse/string/reduce/dynamic.js +8 -9
- package/dist/mjs/parse/string/shift/operator/bounds.js +4 -4
- package/dist/mjs/parse/string/shift/operator/divisor.js +3 -3
- package/dist/mjs/parse/string/string.js +2 -2
- package/dist/mjs/scopes/expressions.js +9 -0
- package/dist/mjs/scopes/jsObjects.js +14 -14
- package/dist/mjs/scopes/scope.js +55 -3
- package/dist/mjs/scopes/type.js +4 -7
- package/dist/mjs/traverse/problems.js +68 -53
- package/dist/mjs/traverse/traverse.js +107 -139
- package/dist/mjs/utils/data.js +24 -0
- package/dist/mjs/utils/generics.js +18 -1
- package/dist/mjs/utils/numericLiterals.js +1 -0
- package/dist/mjs/utils/objectKinds.js +1 -1
- package/dist/tsconfig.temp.tsbuildinfo +1 -1
- package/dist/types/nodes/branch.d.ts +27 -0
- package/dist/types/nodes/compose.d.ts +5 -10
- package/dist/types/nodes/discriminate.d.ts +3 -3
- package/dist/types/nodes/infer.d.ts +21 -20
- package/dist/types/nodes/node.d.ts +12 -16
- package/dist/types/nodes/predicate.d.ts +4 -59
- package/dist/types/nodes/rules/class.d.ts +3 -2
- package/dist/types/nodes/rules/divisor.d.ts +2 -1
- package/dist/types/nodes/rules/props.d.ts +19 -11
- package/dist/types/nodes/rules/range.d.ts +3 -2
- package/dist/types/nodes/rules/regex.d.ts +2 -1
- package/dist/types/nodes/rules/rules.d.ts +12 -14
- package/dist/types/parse/ast/ast.d.ts +24 -0
- package/dist/types/parse/ast/bound.d.ts +10 -0
- package/dist/types/parse/{tuple/utils.d.ts → ast/distributableFunction.d.ts} +2 -3
- package/dist/types/parse/ast/divisor.d.ts +8 -0
- package/dist/types/parse/ast/intersection.d.ts +17 -0
- package/dist/types/parse/{tuple → ast}/keyof.d.ts +4 -4
- package/dist/types/parse/{tuple → ast}/morph.d.ts +3 -3
- package/dist/types/parse/ast/narrow.d.ts +21 -0
- package/dist/types/parse/ast/tuple.d.ts +40 -0
- package/dist/types/parse/ast/union.d.ts +12 -0
- package/dist/types/parse/ast/utils.d.ts +7 -0
- package/dist/types/parse/definition.d.ts +9 -7
- package/dist/types/parse/record.d.ts +2 -2
- package/dist/types/parse/string/reduce/dynamic.d.ts +1 -1
- package/dist/types/parse/string/reduce/shared.d.ts +6 -5
- package/dist/types/parse/string/reduce/static.d.ts +11 -6
- package/dist/types/parse/string/shift/operand/unenclosed.d.ts +2 -2
- package/dist/types/parse/string/shift/operator/bounds.d.ts +4 -3
- package/dist/types/parse/string/shift/operator/divisor.d.ts +5 -1
- package/dist/types/parse/string/string.d.ts +2 -3
- package/dist/types/scopes/expressions.d.ts +48 -0
- package/dist/types/scopes/scope.d.ts +17 -7
- package/dist/types/scopes/type.d.ts +13 -15
- package/dist/types/traverse/problems.d.ts +17 -41
- package/dist/types/traverse/traverse.d.ts +85 -52
- package/dist/types/utils/data.d.ts +13 -0
- package/dist/types/utils/domains.d.ts +1 -1
- package/dist/types/utils/generics.d.ts +13 -10
- package/dist/types/utils/numericLiterals.d.ts +1 -0
- package/dist/types/utils/objectKinds.d.ts +43 -43
- package/dist/types/utils/paths.d.ts +2 -0
- package/package.json +1 -2
- package/dist/cjs/nodes/functors.js +0 -35
- package/dist/cjs/nodes/rules/objectKind.js +0 -78
- package/dist/cjs/parse/tuple/keyof.js +0 -45
- package/dist/cjs/utils/size.js +0 -16
- package/dist/mjs/nodes/functors.js +0 -27
- package/dist/mjs/nodes/rules/objectKind.js +0 -63
- package/dist/mjs/parse/tuple/keyof.js +0 -37
- package/dist/mjs/parse/tuple/narrow.js +0 -7
- package/dist/mjs/utils/size.js +0 -2
- package/dist/types/nodes/branches.d.ts +0 -14
- package/dist/types/nodes/functors.d.ts +0 -6
- package/dist/types/nodes/rules/objectKind.d.ts +0 -15
- package/dist/types/parse/string/ast.d.ts +0 -45
- package/dist/types/parse/tuple/narrow.d.ts +0 -13
- package/dist/types/parse/tuple/tuple.d.ts +0 -31
- package/dist/types/utils/size.d.ts +0 -3
|
@@ -1,70 +1,103 @@
|
|
|
1
|
-
import type { TraversalEntry, TraversalKey, TraversalNode } from "../nodes/node.js";
|
|
1
|
+
import type { TraversalEntry, TraversalKey, TraversalNode, TraversalValue } from "../nodes/node.js";
|
|
2
|
+
import type { TraversalProp } from "../nodes/rules/props.js";
|
|
2
3
|
import type { Type, TypeConfig } from "../scopes/type.js";
|
|
3
|
-
import type {
|
|
4
|
+
import type { SizedData } from "../utils/data.js";
|
|
5
|
+
import type { extend, stringKeyOf } from "../utils/generics.js";
|
|
4
6
|
import { Path } from "../utils/paths.js";
|
|
5
|
-
import type {
|
|
6
|
-
import
|
|
7
|
-
export declare class TraversalState {
|
|
7
|
+
import type { ProblemCode, ProblemWriters } from "./problems.js";
|
|
8
|
+
import { Problem } from "./problems.js";
|
|
9
|
+
export declare class TraversalState<data = unknown> {
|
|
8
10
|
#private;
|
|
11
|
+
data: data;
|
|
9
12
|
type: Type;
|
|
10
13
|
path: Path;
|
|
11
|
-
problems:
|
|
14
|
+
problems: import("../utils/generics.js").arraySubclassToReadonly<{
|
|
15
|
+
[n: number]: Problem<any>;
|
|
12
16
|
byPath: Record<string, Problem<any>>;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
17
|
+
"__#2@#state": TraversalState<unknown>;
|
|
18
|
+
create<code extends ProblemCode>(code: code, source: import("./problems.js").ProblemSource<code>, opts?: import("./problems.js").AddProblemOptions<code> | undefined): false;
|
|
19
|
+
add(problem: Problem<any>): false;
|
|
20
|
+
readonly summary: string;
|
|
21
|
+
toString(): string;
|
|
22
|
+
throw(): never;
|
|
23
|
+
length: number;
|
|
24
|
+
toLocaleString(): string;
|
|
25
|
+
pop(): Problem<any> | undefined;
|
|
26
|
+
push(...items: Problem<any>[]): number;
|
|
27
|
+
concat(...items: ConcatArray<Problem<any>>[]): Problem<any>[];
|
|
28
|
+
concat(...items: (Problem<any> | ConcatArray<Problem<any>>)[]): Problem<any>[];
|
|
29
|
+
join(separator?: string | undefined): string;
|
|
30
|
+
reverse(): Problem<any>[];
|
|
31
|
+
shift(): Problem<any> | undefined;
|
|
32
|
+
slice(start?: number | undefined, end?: number | undefined): Problem<any>[];
|
|
33
|
+
sort(compareFn?: ((a: Problem<any>, b: Problem<any>) => number) | undefined): any;
|
|
34
|
+
splice(start: number, deleteCount?: number | undefined): Problem<any>[];
|
|
35
|
+
splice(start: number, deleteCount: number, ...items: Problem<any>[]): Problem<any>[];
|
|
36
|
+
unshift(...items: Problem<any>[]): number;
|
|
37
|
+
indexOf(searchElement: Problem<any>, fromIndex?: number | undefined): number;
|
|
38
|
+
lastIndexOf(searchElement: Problem<any>, fromIndex?: number | undefined): number;
|
|
39
|
+
every<S extends Problem<any>>(predicate: (value: Problem<any>, index: number, array: Problem<any>[]) => value is S, thisArg?: any): this is S[];
|
|
40
|
+
every(predicate: (value: Problem<any>, index: number, array: Problem<any>[]) => unknown, thisArg?: any): boolean;
|
|
41
|
+
some(predicate: (value: Problem<any>, index: number, array: Problem<any>[]) => unknown, thisArg?: any): boolean;
|
|
42
|
+
forEach(callbackfn: (value: Problem<any>, index: number, array: Problem<any>[]) => void, thisArg?: any): void;
|
|
43
|
+
map<U>(callbackfn: (value: Problem<any>, index: number, array: Problem<any>[]) => U, thisArg?: any): U[];
|
|
44
|
+
filter<S_1 extends Problem<any>>(predicate: (value: Problem<any>, index: number, array: Problem<any>[]) => value is S_1, thisArg?: any): S_1[];
|
|
45
|
+
filter(predicate: (value: Problem<any>, index: number, array: Problem<any>[]) => unknown, thisArg?: any): Problem<any>[];
|
|
46
|
+
reduce(callbackfn: (previousValue: Problem<any>, currentValue: Problem<any>, currentIndex: number, array: Problem<any>[]) => Problem<any>): Problem<any>;
|
|
47
|
+
reduce(callbackfn: (previousValue: Problem<any>, currentValue: Problem<any>, currentIndex: number, array: Problem<any>[]) => Problem<any>, initialValue: Problem<any>): Problem<any>;
|
|
48
|
+
reduce<U_1>(callbackfn: (previousValue: U_1, currentValue: Problem<any>, currentIndex: number, array: Problem<any>[]) => U_1, initialValue: U_1): U_1;
|
|
49
|
+
reduceRight(callbackfn: (previousValue: Problem<any>, currentValue: Problem<any>, currentIndex: number, array: Problem<any>[]) => Problem<any>): Problem<any>;
|
|
50
|
+
reduceRight(callbackfn: (previousValue: Problem<any>, currentValue: Problem<any>, currentIndex: number, array: Problem<any>[]) => Problem<any>, initialValue: Problem<any>): Problem<any>;
|
|
51
|
+
reduceRight<U_2>(callbackfn: (previousValue: U_2, currentValue: Problem<any>, currentIndex: number, array: Problem<any>[]) => U_2, initialValue: U_2): U_2;
|
|
52
|
+
find<S_2 extends Problem<any>>(predicate: (value: Problem<any>, index: number, obj: Problem<any>[]) => value is S_2, thisArg?: any): S_2 | undefined;
|
|
53
|
+
find(predicate: (value: Problem<any>, index: number, obj: Problem<any>[]) => unknown, thisArg?: any): Problem<any> | undefined;
|
|
54
|
+
findIndex(predicate: (value: Problem<any>, index: number, obj: Problem<any>[]) => unknown, thisArg?: any): number;
|
|
55
|
+
fill(value: Problem<any>, start?: number | undefined, end?: number | undefined): any;
|
|
56
|
+
copyWithin(target: number, start: number, end?: number | undefined): any;
|
|
57
|
+
entries(): IterableIterator<[number, Problem<any>]>;
|
|
58
|
+
keys(): IterableIterator<number>;
|
|
59
|
+
values(): IterableIterator<Problem<any>>;
|
|
60
|
+
includes(searchElement: Problem<any>, fromIndex?: number | undefined): boolean;
|
|
61
|
+
flatMap<U_3, This = undefined>(callback: (this: This, value: Problem<any>, index: number, array: Problem<any>[]) => U_3 | readonly U_3[], thisArg?: This | undefined): U_3[];
|
|
62
|
+
flat<A, D extends number = 1>(this: A, depth?: D | undefined): FlatArray<A, D>[];
|
|
63
|
+
at(index: number): Problem<any> | undefined;
|
|
64
|
+
findLast<S_3 extends Problem<any>>(predicate: (value: Problem<any>, index: number, array: Problem<any>[]) => value is S_3, thisArg?: any): S_3 | undefined;
|
|
65
|
+
findLast(predicate: (value: Problem<any>, index: number, array: Problem<any>[]) => unknown, thisArg?: any): Problem<any> | undefined;
|
|
66
|
+
findLastIndex(predicate: (value: Problem<any>, index: number, array: Problem<any>[]) => unknown, thisArg?: any): number;
|
|
67
|
+
[Symbol.iterator](): IterableIterator<Problem<any>>;
|
|
68
|
+
[Symbol.unscopables](): {
|
|
69
|
+
copyWithin: boolean;
|
|
70
|
+
entries: boolean;
|
|
71
|
+
fill: boolean;
|
|
72
|
+
find: boolean;
|
|
73
|
+
findIndex: boolean;
|
|
74
|
+
keys: boolean;
|
|
75
|
+
values: boolean;
|
|
76
|
+
};
|
|
77
|
+
}>;
|
|
48
78
|
configs: TypeConfig[];
|
|
49
79
|
failFast: boolean;
|
|
50
|
-
constructor(type: Type);
|
|
80
|
+
constructor(data: data, type: Type);
|
|
51
81
|
getConfigForProblemCode<code extends ProblemCode>(code: code): ProblemWriters<code>;
|
|
52
|
-
|
|
53
|
-
|
|
82
|
+
traverseKey(key: stringKeyOf<this["data"]>, node: TraversalNode): boolean;
|
|
83
|
+
traverseResolution(name: string): boolean;
|
|
84
|
+
traverseBranches(branches: TraversalEntry[][]): boolean;
|
|
54
85
|
}
|
|
55
|
-
export declare const traverse: (
|
|
56
|
-
export declare const checkEntries: (
|
|
57
|
-
export declare const
|
|
58
|
-
export type
|
|
86
|
+
export declare const traverse: (node: TraversalNode, state: TraversalState) => boolean;
|
|
87
|
+
export declare const checkEntries: (entries: TraversalEntry[], state: TraversalState) => boolean;
|
|
88
|
+
export declare const checkRequiredProp: (prop: TraversalProp, state: TraversalState<TraversableData>) => boolean;
|
|
89
|
+
export type ValidationTraversalKey = Exclude<TraversalKey, "morph">;
|
|
90
|
+
export type EntryChecker<k extends TraversalKey> = (constraint: TraversalValue<k>, state: TraversalState<RuleData<k>>) => boolean;
|
|
91
|
+
export type TraversableData = Record<string | number, unknown>;
|
|
59
92
|
export type ConstrainedRuleTraversalData = extend<{
|
|
60
93
|
[k in TraversalKey]?: unknown;
|
|
61
94
|
}, {
|
|
62
95
|
regex: string;
|
|
63
96
|
divisor: number;
|
|
64
97
|
bound: SizedData;
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
98
|
+
prerequisiteProp: TraversableData;
|
|
99
|
+
optionalProp: TraversableData;
|
|
100
|
+
requiredProp: TraversableData;
|
|
101
|
+
indexProp: TraversableData;
|
|
69
102
|
}>;
|
|
70
103
|
export type RuleData<k extends TraversalKey> = k extends keyof ConstrainedRuleTraversalData ? ConstrainedRuleTraversalData[k] : unknown;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { domainOf } from "./domains.js";
|
|
2
|
+
export type SizedData = string | number | readonly unknown[];
|
|
3
|
+
export declare const sizeOf: (data: unknown) => number;
|
|
4
|
+
export declare const unitsOf: (data: unknown) => "" | "characters" | "items";
|
|
5
|
+
export declare class DataWrapper<value = unknown> {
|
|
6
|
+
value: value;
|
|
7
|
+
constructor(value: value);
|
|
8
|
+
toString(): string;
|
|
9
|
+
get domain(): domainOf<value>;
|
|
10
|
+
get size(): number;
|
|
11
|
+
get units(): "" | "characters" | "items";
|
|
12
|
+
get className(): any;
|
|
13
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { evaluate, isTopType } from "./generics.js";
|
|
2
|
-
export declare const hasDomain: <data, domain extends
|
|
2
|
+
export declare const hasDomain: <data, domain extends Domain>(data: data, domain: domain) => data is data & inferDomain<domain>;
|
|
3
3
|
type DomainTypes = {
|
|
4
4
|
bigint: bigint;
|
|
5
5
|
boolean: boolean;
|
|
@@ -5,19 +5,19 @@ type asConstRecurse<t> = {
|
|
|
5
5
|
};
|
|
6
6
|
export type castWithExclusion<t, castTo, excluded> = t extends excluded ? t : castTo;
|
|
7
7
|
export type Literalable = string | boolean | number | bigint;
|
|
8
|
-
export type
|
|
9
|
-
export type
|
|
8
|
+
export type evaluateObjectOrFunction<t> = isTopType<t> extends true ? t : t extends (...args: infer args) => infer ret ? (...args: args) => ret : evaluate<t>;
|
|
9
|
+
export type evaluate<t> = {
|
|
10
10
|
[k in keyof t]: t[k];
|
|
11
11
|
} & unknown;
|
|
12
12
|
/** Causes a type that would be eagerly calculated to be displayed as-is.
|
|
13
13
|
* WARNING: Makes t NonNullable as a side effect.
|
|
14
14
|
*/
|
|
15
15
|
export type defer<t> = t & {};
|
|
16
|
-
export type merge<base, merged> =
|
|
16
|
+
export type merge<base, merged> = evaluate<Omit<base, keyof merged> & merged>;
|
|
17
17
|
/** Replace existing keys of o without altering readonly or optional modifiers */
|
|
18
18
|
export type replaceProps<o, replacements extends {
|
|
19
19
|
-readonly [k in keyof o]?: unknown;
|
|
20
|
-
}> =
|
|
20
|
+
}> = evaluate<{
|
|
21
21
|
[k in keyof o]: k extends keyof replacements ? replacements[k] : o[k];
|
|
22
22
|
}>;
|
|
23
23
|
export type isTopType<t> = (any extends t ? true : false) extends true ? true : false;
|
|
@@ -39,10 +39,11 @@ export type entryOf<o> = {
|
|
|
39
39
|
export type entriesOf<o extends object> = entryOf<o>[];
|
|
40
40
|
export declare const entriesOf: <o extends object>(o: o) => entriesOf<o>;
|
|
41
41
|
/** Mimics the result of Object.keys(...) */
|
|
42
|
-
export type
|
|
43
|
-
export
|
|
44
|
-
export declare const keysOf: <o extends object>(o: o) => keyOf<o>[];
|
|
42
|
+
export type objectKeysOf<o> = [o] extends [object] ? o extends readonly unknown[] ? any[] extends o ? `${number}` : keyof o & `${number}` : keyof o extends number ? `${keyof o}` : Exclude<keyof o, symbol> : never;
|
|
43
|
+
export declare const objectKeysOf: <o extends object>(o: o) => objectKeysOf<o>[];
|
|
45
44
|
export type stringKeyOf<o> = keyof o & string;
|
|
45
|
+
/** Mimics output of TS's keyof operator at runtime */
|
|
46
|
+
export declare const prototypeKeysOf: <t>(value: t) => (keyof t)[];
|
|
46
47
|
export declare const hasKey: <o, k extends string>(o: o, k: k) => o is o & { [_ in k]: {}; };
|
|
47
48
|
export declare const keyCount: (o: object) => number;
|
|
48
49
|
export type keySet<key extends string = string> = {
|
|
@@ -101,7 +102,9 @@ export type Dict<k extends string = string, v = unknown> = {
|
|
|
101
102
|
readonly [_ in k]: v;
|
|
102
103
|
};
|
|
103
104
|
export type List<t = unknown> = readonly t[];
|
|
104
|
-
export type
|
|
105
|
+
export type arraySubclassToReadonly<t extends unknown[]> = readonly t[number][] & {
|
|
106
|
+
[k in Exclude<keyof t, keyof unknown[]>]: t[k];
|
|
107
|
+
};
|
|
105
108
|
export type HomogenousTuple<item, length extends number, result extends item[] = []> = result["length"] extends length ? result : HomogenousTuple<item, length, [...result, item]>;
|
|
106
109
|
export declare const listFrom: <t>(data: t) => t extends List<unknown> ? t : readonly t[];
|
|
107
110
|
export type CollapsibleList<t> = t | readonly t[];
|
|
@@ -110,9 +113,9 @@ export type CollapsibleList<t> = t | readonly t[];
|
|
|
110
113
|
* OR
|
|
111
114
|
* B, with all properties of A undefined
|
|
112
115
|
**/
|
|
113
|
-
export type xor<a, b> =
|
|
116
|
+
export type xor<a, b> = evaluate<a & {
|
|
114
117
|
[k in keyof b]?: undefined;
|
|
115
|
-
}> |
|
|
118
|
+
}> | evaluate<b & {
|
|
116
119
|
[k in keyof a]?: undefined;
|
|
117
120
|
}>;
|
|
118
121
|
export {};
|
|
@@ -8,6 +8,7 @@ export type IntegerLiteral<Value extends bigint = bigint> = `${Value}`;
|
|
|
8
8
|
*/
|
|
9
9
|
export declare const wellFormedIntegerMatcher: RegExp;
|
|
10
10
|
export declare const isWellFormedInteger: (s: string) => boolean;
|
|
11
|
+
export declare const wellFormedNonNegativeIntegerMatcher: RegExp;
|
|
11
12
|
type NumericLiteralKind = "number" | "bigint" | "integer";
|
|
12
13
|
declare const numericLiteralDescriptions: {
|
|
13
14
|
readonly number: "a number";
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import type { constructor, instanceOf, isTopType } from "./generics.js";
|
|
2
|
-
declare const defaultObjectKinds: {
|
|
3
|
-
Array: ArrayConstructor;
|
|
4
|
-
Date: DateConstructor;
|
|
5
|
-
Error: ErrorConstructor;
|
|
6
|
-
Function: FunctionConstructor;
|
|
7
|
-
Map: MapConstructor;
|
|
8
|
-
RegExp: RegExpConstructor;
|
|
9
|
-
Set: SetConstructor;
|
|
10
|
-
Object: ObjectConstructor;
|
|
11
|
-
String: StringConstructor;
|
|
12
|
-
Number: NumberConstructor;
|
|
13
|
-
Boolean: BooleanConstructor;
|
|
14
|
-
WeakMap: WeakMapConstructor;
|
|
15
|
-
WeakSet: WeakSetConstructor;
|
|
16
|
-
Promise: PromiseConstructor;
|
|
2
|
+
export declare const defaultObjectKinds: {
|
|
3
|
+
readonly Array: ArrayConstructor;
|
|
4
|
+
readonly Date: DateConstructor;
|
|
5
|
+
readonly Error: ErrorConstructor;
|
|
6
|
+
readonly Function: FunctionConstructor;
|
|
7
|
+
readonly Map: MapConstructor;
|
|
8
|
+
readonly RegExp: RegExpConstructor;
|
|
9
|
+
readonly Set: SetConstructor;
|
|
10
|
+
readonly Object: ObjectConstructor;
|
|
11
|
+
readonly String: StringConstructor;
|
|
12
|
+
readonly Number: NumberConstructor;
|
|
13
|
+
readonly Boolean: BooleanConstructor;
|
|
14
|
+
readonly WeakMap: WeakMapConstructor;
|
|
15
|
+
readonly WeakSet: WeakSetConstructor;
|
|
16
|
+
readonly Promise: PromiseConstructor;
|
|
17
17
|
};
|
|
18
18
|
export type InferredObjectKinds = {
|
|
19
19
|
[kind in DefaultObjectKind]: inferObjectKind<kind>;
|
|
@@ -31,36 +31,36 @@ export type objectKindOf<data, kinds extends ObjectKindSet = DefaultObjectKindSe
|
|
|
31
31
|
[kind in keyof kinds]: kinds[kind] extends constructor<data> ? kind : data extends (...args: any[]) => unknown ? "Function" : "Object";
|
|
32
32
|
}[keyof kinds] : undefined;
|
|
33
33
|
export declare const objectKindOf: <data, kinds extends ObjectKindSet = {
|
|
34
|
-
Array: ArrayConstructor;
|
|
35
|
-
Date: DateConstructor;
|
|
36
|
-
Error: ErrorConstructor;
|
|
37
|
-
Function: FunctionConstructor;
|
|
38
|
-
Map: MapConstructor;
|
|
39
|
-
RegExp: RegExpConstructor;
|
|
40
|
-
Set: SetConstructor;
|
|
41
|
-
Object: ObjectConstructor;
|
|
42
|
-
String: StringConstructor;
|
|
43
|
-
Number: NumberConstructor;
|
|
44
|
-
Boolean: BooleanConstructor;
|
|
45
|
-
WeakMap: WeakMapConstructor;
|
|
46
|
-
WeakSet: WeakSetConstructor;
|
|
47
|
-
Promise: PromiseConstructor;
|
|
34
|
+
readonly Array: ArrayConstructor;
|
|
35
|
+
readonly Date: DateConstructor;
|
|
36
|
+
readonly Error: ErrorConstructor;
|
|
37
|
+
readonly Function: FunctionConstructor;
|
|
38
|
+
readonly Map: MapConstructor;
|
|
39
|
+
readonly RegExp: RegExpConstructor;
|
|
40
|
+
readonly Set: SetConstructor;
|
|
41
|
+
readonly Object: ObjectConstructor;
|
|
42
|
+
readonly String: StringConstructor;
|
|
43
|
+
readonly Number: NumberConstructor;
|
|
44
|
+
readonly Boolean: BooleanConstructor;
|
|
45
|
+
readonly WeakMap: WeakMapConstructor;
|
|
46
|
+
readonly WeakSet: WeakSetConstructor;
|
|
47
|
+
readonly Promise: PromiseConstructor;
|
|
48
48
|
}>(data: data, kinds?: kinds | undefined) => objectKindOf<data, kinds> | undefined;
|
|
49
49
|
export declare const hasObjectKind: <kind extends keyof kinds, kinds extends ObjectKindSet = {
|
|
50
|
-
Array: ArrayConstructor;
|
|
51
|
-
Date: DateConstructor;
|
|
52
|
-
Error: ErrorConstructor;
|
|
53
|
-
Function: FunctionConstructor;
|
|
54
|
-
Map: MapConstructor;
|
|
55
|
-
RegExp: RegExpConstructor;
|
|
56
|
-
Set: SetConstructor;
|
|
57
|
-
Object: ObjectConstructor;
|
|
58
|
-
String: StringConstructor;
|
|
59
|
-
Number: NumberConstructor;
|
|
60
|
-
Boolean: BooleanConstructor;
|
|
61
|
-
WeakMap: WeakMapConstructor;
|
|
62
|
-
WeakSet: WeakSetConstructor;
|
|
63
|
-
Promise: PromiseConstructor;
|
|
50
|
+
readonly Array: ArrayConstructor;
|
|
51
|
+
readonly Date: DateConstructor;
|
|
52
|
+
readonly Error: ErrorConstructor;
|
|
53
|
+
readonly Function: FunctionConstructor;
|
|
54
|
+
readonly Map: MapConstructor;
|
|
55
|
+
readonly RegExp: RegExpConstructor;
|
|
56
|
+
readonly Set: SetConstructor;
|
|
57
|
+
readonly Object: ObjectConstructor;
|
|
58
|
+
readonly String: StringConstructor;
|
|
59
|
+
readonly Number: NumberConstructor;
|
|
60
|
+
readonly Boolean: BooleanConstructor;
|
|
61
|
+
readonly WeakMap: WeakMapConstructor;
|
|
62
|
+
readonly WeakSet: WeakSetConstructor;
|
|
63
|
+
readonly Promise: PromiseConstructor;
|
|
64
64
|
}>(data: unknown, kind: kind, kinds?: kinds | undefined) => data is inferObjectKind<kind, kinds>;
|
|
65
65
|
export declare const isArray: <data>(data: data) => data is Extract<data, readonly unknown[]>;
|
|
66
66
|
/** Each defaultObjectKind's completion for the phrase "Must be _____" */
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import type { arraySubclassToReadonly } from "./generics";
|
|
1
2
|
export declare class Path extends Array<string> {
|
|
2
3
|
static fromString(s: string, delimiter?: string): Path;
|
|
3
4
|
toString(delimiter?: string): string;
|
|
4
5
|
}
|
|
6
|
+
export type ReadonlyPath = arraySubclassToReadonly<Path>;
|
|
5
7
|
export type pathToString<segments extends string[], delimiter extends string = "/"> = segments extends [] ? "/" : join<segments, delimiter>;
|
|
6
8
|
export type join<segments extends string[], delimiter extends string = "/", result extends string = ""> = segments extends [infer head extends string, ...infer tail extends string[]] ? join<tail, delimiter, result extends "" ? head : `${result}${delimiter}${head}`> : result;
|
|
7
9
|
export declare const getPath: (root: unknown, path: string[]) => unknown;
|
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.4.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "David Blass",
|
|
7
7
|
"email": "david@arktype.io",
|
|
@@ -82,7 +82,6 @@
|
|
|
82
82
|
"extends": "./dev/configs/.eslintrc.cjs"
|
|
83
83
|
},
|
|
84
84
|
"scripts": {
|
|
85
|
-
"//temporarily disabled pr checks": "pnpm testRepo",
|
|
86
85
|
"prChecks": "pnpm install && pnpm build && pnpm typecheck && pnpm lint && pnpm test && pnpm docgen && pnpm buildSite",
|
|
87
86
|
"typecheck": "tsc --noEmit",
|
|
88
87
|
"build": "ts-node ./dev/scripts/build.ts",
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "functors", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: ()=>functors
|
|
8
|
-
});
|
|
9
|
-
const functors = {
|
|
10
|
-
Array: (node)=>({
|
|
11
|
-
object: {
|
|
12
|
-
objectKind: [
|
|
13
|
-
"Array",
|
|
14
|
-
node
|
|
15
|
-
]
|
|
16
|
-
}
|
|
17
|
-
}),
|
|
18
|
-
Set: (node)=>({
|
|
19
|
-
object: {
|
|
20
|
-
objectKind: [
|
|
21
|
-
"Set",
|
|
22
|
-
node
|
|
23
|
-
]
|
|
24
|
-
}
|
|
25
|
-
}),
|
|
26
|
-
Map: (k, v)=>({
|
|
27
|
-
object: {
|
|
28
|
-
objectKind: [
|
|
29
|
-
"Map",
|
|
30
|
-
k,
|
|
31
|
-
v
|
|
32
|
-
]
|
|
33
|
-
}
|
|
34
|
-
})
|
|
35
|
-
};
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
objectKindIntersection: ()=>objectKindIntersection,
|
|
13
|
-
objectKindPathSegments: ()=>objectKindPathSegments,
|
|
14
|
-
flattenObjectKind: ()=>flattenObjectKind
|
|
15
|
-
});
|
|
16
|
-
const _errorsJs = require("../../utils/errors.js");
|
|
17
|
-
const _composeJs = require("../compose.js");
|
|
18
|
-
const _nodeJs = require("../node.js");
|
|
19
|
-
const objectKindIntersection = (0, _composeJs.composeIntersection)((l, r, state)=>{
|
|
20
|
-
if (typeof l === "string") {
|
|
21
|
-
if (typeof r === "string") {
|
|
22
|
-
return l === r ? (0, _composeJs.equality)() : state.addDisjoint("objectKind", l, r);
|
|
23
|
-
}
|
|
24
|
-
return l === r[0] ? r : state.addDisjoint("objectKind", l, r[0]);
|
|
25
|
-
}
|
|
26
|
-
if (typeof r === "string") {
|
|
27
|
-
return l[0] === r ? l : state.addDisjoint("objectKind", l[0], r);
|
|
28
|
-
}
|
|
29
|
-
if (l[0] !== r[0]) {
|
|
30
|
-
return state.addDisjoint("objectKind", l[0], r[0]);
|
|
31
|
-
}
|
|
32
|
-
const result = [
|
|
33
|
-
l[0]
|
|
34
|
-
];
|
|
35
|
-
let lImpliesR = true;
|
|
36
|
-
let rImpliesL = true;
|
|
37
|
-
for(let i = 1; i < l.length; i++){
|
|
38
|
-
const lNode = l[i];
|
|
39
|
-
const rNode = r[i];
|
|
40
|
-
state.path.push(objectKindParameterToPathSegment(l[0], i));
|
|
41
|
-
const parameterResult = (0, _nodeJs.nodeIntersection)(lNode, rNode, state);
|
|
42
|
-
state.path.pop();
|
|
43
|
-
if ((0, _composeJs.isEquality)(parameterResult)) {
|
|
44
|
-
result[i] = lNode;
|
|
45
|
-
} else if (parameterResult === l) {
|
|
46
|
-
result[i] = lNode;
|
|
47
|
-
rImpliesL = false;
|
|
48
|
-
} else if (parameterResult === r) {
|
|
49
|
-
result[i] = rNode;
|
|
50
|
-
lImpliesR = false;
|
|
51
|
-
} else if ((0, _composeJs.isDisjoint)(parameterResult)) {
|
|
52
|
-
return parameterResult;
|
|
53
|
-
} else {
|
|
54
|
-
result[i] = parameterResult;
|
|
55
|
-
lImpliesR = false;
|
|
56
|
-
rImpliesL = false;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return lImpliesR ? rImpliesL ? (0, _composeJs.equality)() : l : rImpliesL ? r : result;
|
|
60
|
-
});
|
|
61
|
-
const objectKindParameterToPathSegment = (objectKind, i)=>objectKind === "Array" ? "${number}" : objectKind === "Set" ? "${item}" : objectKind === "Map" ? i === 1 ? "${key}" : "${value}" : (0, _errorsJs.throwInternalError)(`Unexpected parameterized objectKind '${objectKind}'`);
|
|
62
|
-
const objectKindPathSegments = {
|
|
63
|
-
"${number}": true,
|
|
64
|
-
"${item}": true,
|
|
65
|
-
"${key}": true,
|
|
66
|
-
"${value}": true
|
|
67
|
-
};
|
|
68
|
-
const flattenObjectKind = (entries, rule, ctx)=>entries.push([
|
|
69
|
-
"objectKind",
|
|
70
|
-
typeof rule === "string" ? rule : rule[0] === "Map" ? [
|
|
71
|
-
rule[0],
|
|
72
|
-
(0, _nodeJs.flattenNode)(rule[1], ctx),
|
|
73
|
-
(0, _nodeJs.flattenNode)(rule[2], ctx)
|
|
74
|
-
] : [
|
|
75
|
-
rule[0],
|
|
76
|
-
(0, _nodeJs.flattenNode)(rule[1], ctx)
|
|
77
|
-
]
|
|
78
|
-
]);
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
Object.defineProperty(exports, "parseKeyOfTuple", {
|
|
6
|
-
enumerable: true,
|
|
7
|
-
get: ()=>parseKeyOfTuple
|
|
8
|
-
});
|
|
9
|
-
const _predicateTs = require("../../nodes/predicate.js");
|
|
10
|
-
const _errorsTs = require("../../utils/errors.js");
|
|
11
|
-
const _genericsTs = require("../../utils/generics.js");
|
|
12
|
-
const _definitionTs = require("../definition.js");
|
|
13
|
-
const _astTs = require("../string/ast.js");
|
|
14
|
-
const parseKeyOfTuple = (def, ctx)=>{
|
|
15
|
-
const resolution = ctx.type.meta.scope.resolveNode((0, _definitionTs.parseDefinition)(def[1], ctx));
|
|
16
|
-
if (!(0, _predicateTs.resolutionExtendsDomain)(resolution, "object")) {
|
|
17
|
-
return (0, _errorsTs.throwParseError)((0, _astTs.writeImplicitNeverMessage)(ctx.path, "keyof"));
|
|
18
|
-
}
|
|
19
|
-
if (resolution.object === true) {
|
|
20
|
-
return (0, _astTs.writeImplicitNeverMessage)(ctx.path, "keyof");
|
|
21
|
-
}
|
|
22
|
-
const branchKeys = [];
|
|
23
|
-
const objectBranches = (0, _genericsTs.listFrom)(resolution.object);
|
|
24
|
-
const initialKeys = getPropsFromBranch(objectBranches[0]);
|
|
25
|
-
for(let i = 1; i < objectBranches.length; i++){
|
|
26
|
-
const keys = getPropsFromBranch(objectBranches[i]);
|
|
27
|
-
if (!keys.length) {
|
|
28
|
-
return (0, _astTs.writeImplicitNeverMessage)(ctx.path, "keyof");
|
|
29
|
-
}
|
|
30
|
-
branchKeys.push(keys);
|
|
31
|
-
}
|
|
32
|
-
const result = [];
|
|
33
|
-
initialKeys.forEach((key)=>{
|
|
34
|
-
const hasKey = branchKeys.every((keySet)=>keySet.includes(key));
|
|
35
|
-
if (hasKey) {
|
|
36
|
-
result.push({
|
|
37
|
-
value: key
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
return result.length ? {
|
|
42
|
-
string: result
|
|
43
|
-
} : (0, _astTs.writeImplicitNeverMessage)(ctx.path, "keyof");
|
|
44
|
-
};
|
|
45
|
-
const getPropsFromBranch = (branch)=>(0, _genericsTs.hasKey)(branch, "props") ? Object.keys(branch.props) : [];
|
package/dist/cjs/utils/size.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", {
|
|
3
|
-
value: true
|
|
4
|
-
});
|
|
5
|
-
function _export(target, all) {
|
|
6
|
-
for(var name in all)Object.defineProperty(target, name, {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: all[name]
|
|
9
|
-
});
|
|
10
|
-
}
|
|
11
|
-
_export(exports, {
|
|
12
|
-
sizeOf: ()=>sizeOf,
|
|
13
|
-
unitsOf: ()=>unitsOf
|
|
14
|
-
});
|
|
15
|
-
const sizeOf = (data)=>typeof data === "string" || Array.isArray(data) ? data.length : typeof data === "number" ? data : 0;
|
|
16
|
-
const unitsOf = (data)=>typeof data === "string" ? "characters" : Array.isArray(data) ? "items" : "";
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export const functors = {
|
|
2
|
-
Array: (node)=>({
|
|
3
|
-
object: {
|
|
4
|
-
objectKind: [
|
|
5
|
-
"Array",
|
|
6
|
-
node
|
|
7
|
-
]
|
|
8
|
-
}
|
|
9
|
-
}),
|
|
10
|
-
Set: (node)=>({
|
|
11
|
-
object: {
|
|
12
|
-
objectKind: [
|
|
13
|
-
"Set",
|
|
14
|
-
node
|
|
15
|
-
]
|
|
16
|
-
}
|
|
17
|
-
}),
|
|
18
|
-
Map: (k, v)=>({
|
|
19
|
-
object: {
|
|
20
|
-
objectKind: [
|
|
21
|
-
"Map",
|
|
22
|
-
k,
|
|
23
|
-
v
|
|
24
|
-
]
|
|
25
|
-
}
|
|
26
|
-
})
|
|
27
|
-
};
|