1 | import { Builtin } from "../built-in";
|
2 | import { IsAny } from "../is-any";
|
3 | import { IsNever } from "../is-never";
|
4 | import { CreateTypeOptions } from "../create-type-options";
|
5 | import { ValueOf } from "../value-of";
|
6 | type Pathable = string | number;
|
7 | type NonRecursiveType = Builtin | Promise<unknown> | ReadonlyMap<unknown, unknown> | ReadonlySet<unknown>;
|
8 | type DefaultRecursivePathsOptions = {
|
9 | depth: [];
|
10 | };
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | type RecursivePathsOptions = {
|
17 | depth: any[];
|
18 | };
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 | type DefaultPathsOptions = {
|
29 | depth: 7;
|
30 | anyArrayIndexAccessor: `${number}`;
|
31 | };
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | type PathsOptions = {
|
40 | depth: number;
|
41 | anyArrayIndexAccessor: string;
|
42 | };
|
43 | type Append<Tuple extends any[]> = [...Tuple, 0];
|
44 | type RecursivePaths<Type, UserOptions extends Required<PathsOptions>, CallOptions extends RecursivePathsOptions> = IsNever<keyof Type> extends true ? never : NonNullable<ValueOf<{
|
45 | [Key in keyof Type]: Key extends Pathable ? `${AnyArrayIndexAccessorOrKey<Key, UserOptions>}` | (CallOptions["depth"]["length"] extends UserOptions["depth"] ? never : Type[Key] extends infer Value ? Value extends Value ? HasParsablePath<Value> extends true ? RecursivePaths<Value, UserOptions, {
|
46 | depth: Append<CallOptions["depth"]>;
|
47 | }> extends infer Rest ? IsNever<Rest> extends true ? never : Rest extends Pathable ? `${AnyArrayIndexAccessorOrKey<Key, UserOptions>}.${Rest}` : never : never : never : never : never) : never;
|
48 | }>>;
|
49 | type HasParsablePath<Type> = Type extends NonRecursiveType ? false : IsAny<Type> extends true ? false : Type extends object ? true : false;
|
50 | type UnsafePaths<Type, Options extends Required<PathsOptions>> = Type extends Type ? HasParsablePath<Type> extends true ? RecursivePaths<Type, Options, DefaultRecursivePathsOptions> : never : never;
|
51 | type AnyArrayIndexAccessorOrKey<Key extends Pathable, UserOptions extends Required<PathsOptions>> = Key extends number ? Key | UserOptions["anyArrayIndexAccessor"] : Key;
|
52 | export type Paths<Type, OverridePathOptions extends Partial<PathsOptions> = {}> = UnsafePaths<Type, CreateTypeOptions<PathsOptions, OverridePathOptions, DefaultPathsOptions>>;
|
53 | export {};
|