1 | import type { Keys, Keys1, Keys2, Keys3, Keys4, Keys5, Keys6, Keys7, ValN } from "./keyval.js";
|
2 | import type { Maybe } from "./null.js";
|
3 | import type { NumOrString } from "./prim.js";
|
4 | import type { Head, IsEmpty, Tail } from "./tuple.js";
|
5 |
|
6 |
|
7 |
|
8 | export type Path = readonly NumOrString[] | NumOrString;
|
9 |
|
10 |
|
11 |
|
12 | export type Path0 = readonly [];
|
13 |
|
14 |
|
15 |
|
16 | export type Path1<T, A> = A extends Keys<T> ? readonly [A] : never;
|
17 |
|
18 |
|
19 |
|
20 | export type Path2<T, A, B> = A extends Keys<T> ? B extends Keys1<T, A> ? readonly [A, B] : never : never;
|
21 |
|
22 |
|
23 |
|
24 | export type Path3<T, A, B, C> = A extends Keys<T> ? B extends Keys1<T, A> ? C extends Keys2<T, A, B> ? readonly [A, B, C] : never : never : never;
|
25 |
|
26 |
|
27 |
|
28 | export type Path4<T, A, B, C, D> = A extends Keys<T> ? B extends Keys1<T, A> ? C extends Keys2<T, A, B> ? D extends Keys3<T, A, B, C> ? readonly [A, B, C, D] : never : never : never : never;
|
29 |
|
30 |
|
31 |
|
32 | export type Path5<T, A, B, C, D, E> = A extends Keys<T> ? B extends Keys1<T, A> ? C extends Keys2<T, A, B> ? D extends Keys3<T, A, B, C> ? E extends Keys4<T, A, B, C, D> ? readonly [A, B, C, D, E] : never : never : never : never : never;
|
33 |
|
34 |
|
35 |
|
36 | export type Path6<T, A, B, C, D, E, F> = A extends Keys<T> ? B extends Keys1<T, A> ? C extends Keys2<T, A, B> ? D extends Keys3<T, A, B, C> ? E extends Keys4<T, A, B, C, D> ? F extends Keys5<T, A, B, C, D, E> ? readonly [A, B, C, D, E, F] : never : never : never : never : never : never;
|
37 |
|
38 |
|
39 |
|
40 | export type Path7<T, A, B, C, D, E, F, G> = A extends Keys<T> ? B extends Keys1<T, A> ? C extends Keys2<T, A, B> ? D extends Keys3<T, A, B, C> ? E extends Keys4<T, A, B, C, D> ? F extends Keys5<T, A, B, C, D, E> ? G extends Keys6<T, A, B, C, D, E, F> ? readonly [A, B, C, D, E, F, G] : never : never : never : never : never : never : never;
|
41 |
|
42 |
|
43 |
|
44 | export type Path8<T, A, B, C, D, E, F, G, H> = A extends Keys<T> ? B extends Keys1<T, A> ? C extends Keys2<T, A, B> ? D extends Keys3<T, A, B, C> ? E extends Keys4<T, A, B, C, D> ? F extends Keys5<T, A, B, C, D, E> ? G extends Keys6<T, A, B, C, D, E, F> ? H extends Keys7<T, A, B, C, D, E, F, G> ? readonly [A, B, C, D, E, F, G, H] : never : never : never : never : never : never : never : never;
|
45 |
|
46 |
|
47 |
|
48 |
|
49 | export type DeepPath<T, A, B, C, D, E, F, G, H> = A extends Keys<T> ? B extends Keys1<T, A> ? C extends Keys2<T, A, B> ? D extends Keys3<T, A, B, C> ? E extends Keys4<T, A, B, C, D> ? F extends Keys5<T, A, B, C, D, E> ? G extends Keys6<T, A, B, C, D, E, F> ? H extends Keys7<T, A, B, C, D, E, F, G> ? readonly [A, B, C, D, E, F, G, H, ...NumOrString[]] : never : never : never : never : never : never : never : never;
|
50 |
|
51 |
|
52 |
|
53 | export type OptVal<PRED, RES> = [PRED] extends [never] ? RES : Maybe<RES>;
|
54 |
|
55 |
|
56 |
|
57 | export type IsOpt<T> = T extends undefined ? true : never;
|
58 |
|
59 |
|
60 |
|
61 | type IsOptR<T, K, P extends unknown[]> = K extends Keys<T> ? [true] extends [IsOpt<T[K]>] ? true : {
|
62 | 0: IsOptR<Required<T>[K], Head<P>, Tail<P>>;
|
63 | 1: never;
|
64 | }[IsEmpty<P>] : never;
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 | export type IsOptPath<T, P extends unknown[]> = P extends [] ? never : IsOptR<T, Head<P>, Tail<P>>;
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 | export type OptPathVal<T, P extends unknown[]> = OptVal<IsOptPath<T, P>, ValN<T, P>>;
|
82 |
|
83 |
|
84 |
|
85 |
|
86 | export type PathVal<T, P extends unknown[]> = ValN<T, P>;
|
87 | export {};
|
88 |
|
\ | No newline at end of file |