/
wallet.ts
47 lines (44 loc) · 1.63 KB
/
wallet.ts
1
2
3
4
5
6
7
8
9
10
11
12
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
import { MergeObjects } from './utilities';
/** @group Universal Wallets */
export type Plugin<
Name extends string,
PublicMethods extends Record<string, (...args: any[]) => any> = Record<never, never>,
DependentMethods extends Record<string, (...args: any[]) => any> = Record<never, never>
> = {
name?: Name;
pluginMethods: {
[Key in keyof PublicMethods]: <T extends Wallet<any, PublicMethods & DependentMethods>>(
wallet: T,
...args: Parameters<PublicMethods[Key]>
) => ReturnType<PublicMethods[Key]>;
};
};
/** @group Universal Wallets */
export type PublicFieldsObj<
PluginMethods extends Record<string, (...args: any[]) => any> = Record<never, never>
> = {
pluginMethods: PluginMethods;
};
/** @group Universal Wallets */
export type Wallet<
PluginNames extends string = '',
PluginMethods extends Record<string, (...args: any[]) => any> = Record<never, never>
> = PublicFieldsObj<PluginMethods> & {
contents: any[];
plugins: Plugin<PluginNames, Record<string, (...args: any[]) => any>>[];
add: (content: any) => Promise<Wallet<PluginNames, PluginMethods>>;
remove: (contentId: string) => Promise<Wallet<PluginNames, PluginMethods>>;
addPlugin: <
Name extends string,
Methods extends Record<string, (...args: any[]) => any> = Record<never, never>
>(
plugin: Plugin<Name, Methods>
) => Promise<
Wallet<
'' extends PluginNames ? Name : PluginNames | Name,
Record<never, never> extends PluginMethods
? Methods
: MergeObjects<[PluginMethods, Methods]>
>
>;
};