forked from timonson/gentle_rpc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
json_rpc_types.ts
45 lines (35 loc) · 1.07 KB
/
json_rpc_types.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
// https://www.jsonrpc.org/specification
export type RpcVersion = "2.0";
export type RpcReservedMethod = string;
export type RpcId = number | string | null;
export type RpcParams = JsonArray | JsonObject;
export type RpcMethod = string;
export interface RpcRequest {
jsonrpc: RpcVersion;
method: RpcMethod;
id?: RpcId;
params?: RpcParams;
}
export type RpcResponse = RpcSuccess | RpcFailure;
export type RpcBatchRequest = RpcRequest[];
export type RpcBatchResponse = RpcResponse[];
export type RpcResponseOrBatch = RpcResponse | RpcBatchResponse;
export interface RpcResponseBasis {
jsonrpc: RpcVersion;
id: RpcId;
}
export interface RpcSuccess extends RpcResponseBasis {
result: JsonValue;
}
export interface RpcFailure extends RpcResponseBasis {
error: RpcError;
}
export interface RpcError {
code: number;
message: string;
data?: JsonValue;
}
export type JsonPrimitive = string | number | boolean | null;
export type JsonValue = JsonPrimitive | JsonObject | JsonArray;
export type JsonObject = { [member: string]: JsonValue };
export type JsonArray = JsonValue[];