-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrpc.common.ts
49 lines (43 loc) · 856 Bytes
/
rpc.common.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
48
49
export type RPCMethod<C = unknown, P extends any[] = any[], R = unknown> = (
context: C,
...params: P
) => Promise<R>
export type RPCMethodMap<C = unknown> = {
[key: string]: RPCMethod<C>
}
export class RpcError extends Error {
constructor(
public message: string,
public code: number,
public data?: unknown
) {
super(message)
this.name = 'RpcError'
}
}
export interface JsonRpcRequest {
jsonrpc: '2.0'
method: string
params: unknown[]
id: string
}
export interface JsonRpcSuccessResponse {
jsonrpc: '2.0'
result: unknown
id: string
}
export interface JsonRpcErrorResponse {
jsonrpc: '2.0'
error: {
code: number
message: string
data?: {
stack?: string
name?: string
isRpcError?: boolean
[key: string]: unknown
}
}
id: string
}
export type JsonRpcResponse = JsonRpcSuccessResponse | JsonRpcErrorResponse