@trenskow/rpc 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +25 -11
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -19,22 +19,29 @@ export interface RPC<D> {
|
|
|
19
19
|
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export class Server<T extends object>
|
|
22
|
+
export class Server<T extends object> implements RPC<any[]> {
|
|
23
23
|
|
|
24
24
|
private readonly local: T;
|
|
25
|
+
|
|
26
|
+
sender: MessageSender;
|
|
25
27
|
|
|
26
28
|
constructor(
|
|
27
29
|
local: T,
|
|
28
30
|
sender?: MessageSender
|
|
29
31
|
)
|
|
30
32
|
|
|
31
|
-
|
|
33
|
+
onMessage(
|
|
34
|
+
command: string,
|
|
35
|
+
data: any[]
|
|
36
|
+
): void;
|
|
37
|
+
|
|
38
|
+
}
|
|
32
39
|
|
|
33
40
|
interface ClientOptions {
|
|
34
41
|
timeout?: number;
|
|
35
42
|
}
|
|
36
43
|
|
|
37
|
-
export class Client<T extends object>
|
|
44
|
+
export class Client<T extends object> implements RPC<any> {
|
|
38
45
|
|
|
39
46
|
readonly remote: T;
|
|
40
47
|
|
|
@@ -45,18 +52,25 @@ export class Client<T extends object> extends RPC<any> {
|
|
|
45
52
|
options?: ClientOptions
|
|
46
53
|
)
|
|
47
54
|
|
|
55
|
+
onMessage(
|
|
56
|
+
command: string,
|
|
57
|
+
data: any
|
|
58
|
+
): void;
|
|
59
|
+
|
|
48
60
|
}
|
|
49
61
|
|
|
50
|
-
|
|
62
|
+
type Serve = <T extends object>(
|
|
51
63
|
handler: T,
|
|
52
64
|
sender: MessageSender
|
|
53
|
-
)
|
|
65
|
+
) => Server<T>;
|
|
54
66
|
|
|
55
|
-
|
|
67
|
+
type Connect = <T extends object>(
|
|
56
68
|
sender: MessageSender
|
|
57
|
-
)
|
|
69
|
+
) => Client<T>;
|
|
70
|
+
|
|
71
|
+
declare const rpc: {
|
|
72
|
+
serve: Serve;
|
|
73
|
+
connect: Connect;
|
|
74
|
+
}
|
|
58
75
|
|
|
59
|
-
export default
|
|
60
|
-
serve,
|
|
61
|
-
connect
|
|
62
|
-
};
|
|
76
|
+
export default rpc;
|