1 | import { At } from '../Any/At';
|
2 | import { Key } from '../Any/Key';
|
3 | import { List } from '../List/List';
|
4 | import { Depth } from './_Internal';
|
5 | import { BuiltIn } from '../Misc/BuiltIn';
|
6 | import { _Omit } from './Omit';
|
7 | import { Length } from '../List/Length';
|
8 | import { Has } from '../Union/Has';
|
9 |
|
10 |
|
11 |
|
12 | declare type Longer<L extends List, L1 extends List> = L extends unknown ? L1 extends unknown ? {
|
13 | 0: 0;
|
14 | 1: 1;
|
15 | }[Has<keyof L, keyof L1>] : never : never;
|
16 |
|
17 |
|
18 |
|
19 | declare type PatchProp<OK, O1K, fill, OKeys extends Key, K extends Key> = K extends OKeys ? OK extends fill ? O1K : OK : O1K;
|
20 |
|
21 |
|
22 |
|
23 | declare type PatchFlatObject<O extends object, O1 extends object, fill, OKeys extends Key = keyof O> = {
|
24 | [K in keyof (O & _Omit<O1, OKeys>)]: PatchProp<At<O, K>, At<O1, K>, fill, OKeys, K>;
|
25 | } & {};
|
26 |
|
27 |
|
28 |
|
29 | declare type PatchFlatList<L extends List, L1 extends List, ignore extends object, fill> = number extends Length<L | L1> ? PatchFlatChoice<L[number], L1[number], ignore, fill>[] : Longer<L, L1> extends 1 ? {
|
30 | [K in keyof L]: PatchProp<L[K], At<L1, K>, fill, keyof L, K>;
|
31 | } : {
|
32 | [K in keyof L1]: PatchProp<At<L, K>, L1[K], fill, keyof L, K>;
|
33 | };
|
34 |
|
35 |
|
36 |
|
37 | export declare type PatchFlatChoice<O extends object, O1 extends object, ignore extends object, fill> = O extends ignore ? O : O1 extends ignore ? O : O extends List ? O1 extends List ? PatchFlatList<O, O1, ignore, fill> : PatchFlatObject<O, O1, fill> : PatchFlatObject<O, O1, fill>;
|
38 |
|
39 |
|
40 |
|
41 | export declare type PatchFlat<O extends object, O1 extends object, ignore extends object = BuiltIn, fill = never> = O extends unknown ? O1 extends unknown ? PatchFlatChoice<O, O1, ignore, fill> : never : never;
|
42 |
|
43 |
|
44 |
|
45 | declare type PatchDeepList<L extends List, L1 extends List, ignore extends object, fill> = number extends Length<L | L1> ? PatchDeepChoice<L[number], L1[number], ignore, fill, never, any>[] : Longer<L, L1> extends 1 ? {
|
46 | [K in keyof L]: PatchDeepChoice<L[K], At<L1, K>, ignore, fill, keyof L, K>;
|
47 | } : {
|
48 | [K in keyof L1]: PatchDeepChoice<At<L, K>, L1[K], ignore, fill, keyof L, K>;
|
49 | };
|
50 |
|
51 |
|
52 |
|
53 | declare type PatchDeepObject<O extends object, O1 extends object, ignore extends object, fill, OKeys extends Key = keyof O> = {
|
54 | [K in keyof (O & _Omit<O1, OKeys>)]: PatchDeepChoice<At<O, K>, At<O1, K>, ignore, fill, OKeys, K>;
|
55 | };
|
56 |
|
57 |
|
58 |
|
59 | declare type PatchDeepChoice<OK, O1K, ignore extends object, fill, OKeys extends Key, K extends Key> = [
|
60 | OK
|
61 | ] extends [never] ? PatchProp<OK, O1K, fill, OKeys, K> : [
|
62 | O1K
|
63 | ] extends [never] ? PatchProp<OK, O1K, fill, OKeys, K> : OK extends ignore ? PatchProp<OK, O1K, fill, OKeys, K> : O1K extends ignore ? PatchProp<OK, O1K, fill, OKeys, K> : OK extends List ? O1K extends List ? PatchDeepList<OK, O1K, ignore, fill> : PatchProp<OK, O1K, fill, OKeys, K> : OK extends object ? O1K extends object ? PatchDeepObject<OK, O1K, ignore, fill> : PatchProp<OK, O1K, fill, OKeys, K> : PatchProp<OK, O1K, fill, OKeys, K>;
|
64 |
|
65 |
|
66 |
|
67 | export declare type PatchDeep<O extends object, O1 extends object, ignore extends object, fill> = O extends unknown ? O1 extends unknown ? PatchDeepChoice<O, O1, ignore, fill, 'x', 'y'> : never : never;
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 | export declare type Patch<O extends object, O1 extends object, depth extends Depth = 'flat', ignore extends object = BuiltIn, fill extends any = never> = {
|
115 | 'flat': PatchFlat<O, O1, ignore, fill>;
|
116 | 'deep': PatchDeep<O, O1, ignore, fill>;
|
117 | }[depth];
|
118 | export {};
|