-
Notifications
You must be signed in to change notification settings - Fork 228
Expand file tree
/
Copy pathjsonrpc.ts
More file actions
51 lines (43 loc) · 921 Bytes
/
jsonrpc.ts
File metadata and controls
51 lines (43 loc) · 921 Bytes
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
50
51
/**
* JSON-RPC 2.0 type definitions for internal use.
*/
export type AnyMessage = AnyRequest | AnyResponse | AnyNotification;
export type AnyRequest = {
jsonrpc: "2.0";
id: string | number | null;
method: string;
params?: unknown;
};
export type AnyResponse = {
jsonrpc: "2.0";
id: string | number | null;
} & Result<unknown>;
export type AnyNotification = {
jsonrpc: "2.0";
method: string;
params?: unknown;
};
export type Result<T> =
| {
result: T;
}
| {
error: ErrorResponse;
};
export type ErrorResponse = {
code: number;
message: string;
data?: unknown;
};
export type PendingResponse = {
resolve: (response: unknown) => void;
reject: (error: ErrorResponse) => void;
};
export type RequestHandler = (
method: string,
params: unknown,
) => Promise<unknown>;
export type NotificationHandler = (
method: string,
params: unknown,
) => Promise<void>;