Skip to content

Commit a2ae510

Browse files
committed
chore: updating doc comments for RPC message types
[ci skip]
1 parent 7352f1f commit a2ae510

1 file changed

Lines changed: 96 additions & 38 deletions

File tree

src/rpc/types.ts

Lines changed: 96 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,82 +18,140 @@ import type { POJO } from '../types';
1818
* This is the JSON RPC request object. this is the generic message type used for the RPC.
1919
*/
2020
type JSONRPCRequestMessage<T extends JSONValue = JSONValue> = {
21-
// A String specifying the version of the JSON-RPC protocol. MUST be exactly "2.0"
21+
/**
22+
* A String specifying the version of the JSON-RPC protocol. MUST be exactly "2.0"
23+
*/
2224
jsonrpc: '2.0';
23-
// A String containing the name of the method to be invoked. Method names that begin with the word rpc followed by a
24-
// period character (U+002E or ASCII 46) are reserved for rpc-internal methods and extensions and MUST NOT be used
25-
// for anything else.
25+
/**
26+
* A String containing the name of the method to be invoked. Method names that begin with the word rpc followed by a
27+
* period character (U+002E or ASCII 46) are reserved for rpc-internal methods and extensions and MUST NOT be used
28+
* for anything else.
29+
*/
2630
method: string;
27-
// A Structured value that holds the parameter values to be used during the invocation of the method.
28-
// This member MAY be omitted.
31+
/**
32+
* A Structured value that holds the parameter values to be used during the invocation of the method.
33+
* This member MAY be omitted.
34+
*/
2935
params?: T;
30-
// An identifier established by the Client that MUST contain a String, Number, or NULL value if included.
31-
// If it is not included it is assumed to be a notification. The value SHOULD normally not be Null [1] and Numbers
32-
// SHOULD NOT contain fractional parts [2]
36+
/**
37+
* An identifier established by the Client that MUST contain a String, Number, or NULL value if included.
38+
* If it is not included it is assumed to be a notification. The value SHOULD normally not be Null [1] and Numbers
39+
* SHOULD NOT contain fractional parts [2]
40+
*/
3341
id: string | number | null;
3442
};
3543

44+
/**
45+
* This is the JSON RPC notification object. this is used for a request that
46+
* doesn't expect a response.
47+
*/
3648
type JSONRPCRequestNotification<T extends JSONValue = JSONValue> = {
37-
// A String specifying the version of the JSON-RPC protocol. MUST be exactly "2.0"
49+
/**
50+
* A String specifying the version of the JSON-RPC protocol. MUST be exactly "2.0"
51+
*/
3852
jsonrpc: '2.0';
39-
// A String containing the name of the method to be invoked. Method names that begin with the word rpc followed by a
40-
// period character (U+002E or ASCII 46) are reserved for rpc-internal methods and extensions and MUST NOT be used
41-
// for anything else.
53+
/**
54+
* A String containing the name of the method to be invoked. Method names that begin with the word rpc followed by a
55+
* period character (U+002E or ASCII 46) are reserved for rpc-internal methods and extensions and MUST NOT be used
56+
* for anything else.
57+
*/
4258
method: string;
43-
// A Structured value that holds the parameter values to be used during the invocation of the method.
44-
// This member MAY be omitted.
59+
/**
60+
* A Structured value that holds the parameter values to be used during the invocation of the method.
61+
* This member MAY be omitted.
62+
*/
4563
params?: T;
4664
};
4765

66+
/**
67+
* This is the JSON RPC response result object. It contains the response data for a
68+
* corresponding request.
69+
*/
4870
type JSONRPCResponseResult<T extends JSONValue = JSONValue> = {
49-
// A String specifying the version of the JSON-RPC protocol. MUST be exactly "2.0".
71+
/**
72+
* A String specifying the version of the JSON-RPC protocol. MUST be exactly "2.0".
73+
*/
5074
jsonrpc: '2.0';
51-
// This member is REQUIRED on success.
52-
// This member MUST NOT exist if there was an error invoking the method.
53-
// The value of this member is determined by the method invoked on the Server.
75+
/**
76+
* This member is REQUIRED on success.
77+
* This member MUST NOT exist if there was an error invoking the method.
78+
* The value of this member is determined by the method invoked on the Server.
79+
*/
5480
result: T;
55-
// This member is REQUIRED.
56-
// It MUST be the same as the value of the id member in the Request Object.
57-
// If there was an error in detecting the id in the Request object (e.g. Parse error/Invalid Request),
58-
// it MUST be Null.
81+
/**
82+
* This member is REQUIRED.
83+
* It MUST be the same as the value of the id member in the Request Object.
84+
* If there was an error in detecting the id in the Request object (e.g. Parse error/Invalid Request),
85+
* it MUST be Null.
86+
*/
5987
id: string | number | null;
6088
};
6189

90+
/**
91+
* This is the JSON RPC response Error object. It contains any errors that have
92+
* occurred when responding to a request.
93+
*/
6294
type JSONRPCResponseError = {
63-
// A String specifying the version of the JSON-RPC protocol. MUST be exactly "2.0".
95+
/**
96+
* A String specifying the version of the JSON-RPC protocol. MUST be exactly "2.0".
97+
*/
6498
jsonrpc: '2.0';
65-
// This member is REQUIRED on error.
66-
// This member MUST NOT exist if there was no error triggered during invocation.
67-
// The value for this member MUST be an Object as defined in section 5.1.
99+
/**
100+
* This member is REQUIRED on error.
101+
* This member MUST NOT exist if there was no error triggered during invocation.
102+
* The value for this member MUST be an Object as defined in section 5.1.
103+
*/
68104
error: JSONRPCError;
69-
// This member is REQUIRED.
70-
// It MUST be the same as the value of the id member in the Request Object.
71-
// If there was an error in detecting the id in the Request object (e.g. Parse error/Invalid Request),
72-
// it MUST be Null.
105+
/**
106+
* This member is REQUIRED.
107+
* It MUST be the same as the value of the id member in the Request Object.
108+
* If there was an error in detecting the id in the Request object (e.g. Parse error/Invalid Request),
109+
* it MUST be Null.
110+
*/
73111
id: string | number | null;
74112
};
75113

114+
/**
115+
* This is a JSON RPC error object, it encodes the error data for the JSONRPCResponseError object.
116+
*/
76117
type JSONRPCError = {
77-
// A Number that indicates the error type that occurred.
78-
// This MUST be an integer.
118+
/**
119+
* A Number that indicates the error type that occurred.
120+
* This MUST be an integer.
121+
*/
79122
code: number;
80-
// A String providing a short description of the error.
81-
// The message SHOULD be limited to a concise single sentence.
123+
/**
124+
* A String providing a short description of the error.
125+
* The message SHOULD be limited to a concise single sentence.
126+
*/
82127
message: string;
83-
// A Primitive or Structured value that contains additional information about the error.
84-
// This may be omitted.
85-
// The value of this member is defined by the Server (e.g. detailed error information, nested errors etc.).
128+
/**
129+
* A Primitive or Structured value that contains additional information about the error.
130+
* This may be omitted.
131+
* The value of this member is defined by the Server (e.g. detailed error information, nested errors etc.).
132+
*/
86133
data?: JSONValue;
87134
};
88135

136+
/**
137+
* This is the JSON RPC Request object. It can be a request message or
138+
* notification.
139+
*/
89140
type JSONRPCRequest<T extends JSONValue = JSONValue> =
90141
| JSONRPCRequestMessage<T>
91142
| JSONRPCRequestNotification<T>;
92143

144+
/**
145+
* This is a JSON RPC response object. It can be a response result or error.
146+
*/
93147
type JSONRPCResponse<T extends JSONValue = JSONValue> =
94148
| JSONRPCResponseResult<T>
95149
| JSONRPCResponseError;
96150

151+
/**
152+
* This is a JSON RPC Message object. This is top level and can be any kind of
153+
* message.
154+
*/
97155
type JSONRPCMessage<T extends JSONValue = JSONValue> =
98156
| JSONRPCRequest<T>
99157
| JSONRPCResponse<T>;

0 commit comments

Comments
 (0)