|
@@ -1,9 +1,7 @@
|
1
|
1
|
import * as I from "./Interfaces";
|
2
|
2
|
|
3
|
|
-export type AnyFunction = (...any:any)=>any
|
4
|
|
-export type AsyncFunction<Fn extends AnyFunction = AnyFunction> = ReturnType<Fn> extends Promise<any> ? Fn : (...any:Parameters<Fn>) => Promise<ReturnType<Fn>>
|
5
|
|
-export type RPCGroup = { [name in string] : AsyncFunction }
|
6
|
|
-export type RPCInterface<Impl extends RPCInterface = {}> = { [groupName in string]: RPCGroup } & Impl
|
|
3
|
+export type AnyFunction = (...args:any) => any
|
|
4
|
+export type HookFunction<F extends AnyFunction = AnyFunction, SubresT = {}> = (...args: Parameters<F>) => Promise<SubscriptionResponse<SubresT> | ErrorResponse>
|
7
|
5
|
|
8
|
6
|
export type Visibility = "127.0.0.1" | "0.0.0.0"
|
9
|
7
|
export type ConnectionHandler = (socket:I.Socket) => void
|
|
@@ -19,7 +17,6 @@ export type SocketConf = {
|
19
|
17
|
export type ResponseType = "Subscribe" | "Success" | "Error"
|
20
|
18
|
export type Outcome = "Success" | "Error"
|
21
|
19
|
|
22
|
|
-
|
23
|
20
|
export type Respose<T> = T & { result: Outcome }
|
24
|
21
|
export type SuccessResponse<T = {}> = Respose<T> & { result: "Success" }
|
25
|
22
|
export type ErrorResponse<T = {}> = Respose<T> & { result: "Error", message?:string }
|
|
@@ -27,22 +24,31 @@ export type SubscriptionResponse<T = {}> = Respose<T> & { result: "Success"; uui
|
27
|
24
|
|
28
|
25
|
export type RPCType = 'Hook' | 'Unhook' | 'Call'
|
29
|
26
|
|
30
|
|
-export type HookT<G extends RPCGroup, K extends keyof G, SubresT> = AsyncFunction<HookFunction<G[K], SubresT>>
|
31
|
|
-export type CallT<G extends RPCGroup, K extends keyof G> = AsyncFunction<G[K]>
|
|
27
|
+export type CallRPC<N, F> = {
|
|
28
|
+ name: N
|
|
29
|
+ call: F
|
|
30
|
+}
|
32
|
31
|
|
33
|
|
-export type HookRPC<G extends RPCGroup, K extends keyof G, SubresT = {}> = {
|
34
|
|
- name: K
|
35
|
|
- hook: HookT<G, K, SubresT>
|
36
|
|
- onCallback?: CallbackFunction,
|
|
32
|
+export type HookRPC<N, F extends AnyFunction, SubresT = {}> = {
|
|
33
|
+ name: N
|
|
34
|
+ hook: HookFunction<F, SubresT>
|
|
35
|
+ onCallback?: AnyFunction
|
37
|
36
|
onClose?: HookCloseFunction<SubresT>
|
38
|
37
|
}
|
39
|
38
|
|
40
|
|
-export type CallRPC<G extends RPCGroup, K extends keyof G> = {
|
41
|
|
- name: K
|
42
|
|
- call: CallT<G,K>
|
43
|
|
-}
|
|
39
|
+export type RPC<N, F extends AnyFunction, SubresT = {}> = HookRPC<N, F, SubresT> | CallRPC<N,F> | F
|
44
|
40
|
|
45
|
|
-export type RPC<G extends RPCGroup, Kg extends keyof G, SubresT> = CallRPC<G, Kg> | HookRPC<G, Kg, SubresT>
|
|
41
|
+export type RPCInterface<Impl extends RPCInterface = {}> = {
|
|
42
|
+ [grp in string] : {
|
|
43
|
+ [rpc in string] : AnyFunction
|
|
44
|
+ }
|
|
45
|
+} & Impl
|
|
46
|
+
|
|
47
|
+export type RPCInterfaceArray<Itfc extends RPCInterface, SubresT = {}> = {
|
|
48
|
+ [grp in keyof Itfc]: Array<
|
|
49
|
+ { [rpc in keyof Itfc[grp]]: RPC<rpc, Itfc[grp][rpc], SubresT> }[keyof Itfc[grp]]
|
|
50
|
+ >
|
|
51
|
+}
|
46
|
52
|
|
47
|
53
|
export type BaseInfo = {
|
48
|
54
|
name: string,
|
|
@@ -50,14 +56,14 @@ export type BaseInfo = {
|
50
|
56
|
argNames: string[],
|
51
|
57
|
}
|
52
|
58
|
|
53
|
|
-export type HookInfo<T = {}> = BaseInfo & {
|
|
59
|
+export type HookInfo<SubresT = {}> = BaseInfo & {
|
54
|
60
|
type: 'Hook',
|
55
|
|
- generator: (socket?:I.Socket) => HookFunction<AnyFunction, T>
|
|
61
|
+ generator: (socket?:I.Socket) => (...args:any) => SubresT
|
56
|
62
|
}
|
57
|
63
|
|
58
|
64
|
export type CallInfo = BaseInfo & {
|
59
|
65
|
type: 'Call',
|
60
|
|
- call: AsyncFunction
|
|
66
|
+ call: AnyFunction
|
61
|
67
|
}
|
62
|
68
|
|
63
|
69
|
export type RpcInfo = HookInfo | CallInfo
|
|
@@ -65,5 +71,3 @@ export type ExtendedRpcInfo = RpcInfo & { uniqueName: string }
|
65
|
71
|
|
66
|
72
|
export type OnFunction = (type: 'error' | 'close', f: (e?:any)=>void) => I.Socket
|
67
|
73
|
export type HookCloseFunction<T = {}> = (res:SubscriptionResponse<T>, rpc:HookRPC<any, any, T>) => any
|
68
|
|
-export type HookFunction<F extends AnyFunction = AnyFunction, SubResT = {}> = AsyncFunction<(...args:Parameters<F>) => SubscriptionResponse<SubResT> | ErrorResponse>
|
69
|
|
-export type CallbackFunction = (callback:AnyFunction, ...args:any) => any
|