@fuzdev/fuz_app 0.9.0 → 0.10.0
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/dist/actions/action_rpc.d.ts.map +1 -1
- package/dist/actions/action_rpc.js +1 -1
- package/dist/http/jsonrpc.d.ts +197 -13
- package/dist/http/jsonrpc.d.ts.map +1 -1
- package/dist/http/jsonrpc.js +90 -10
- package/dist/http/jsonrpc_errors.d.ts +46 -34
- package/dist/http/jsonrpc_errors.d.ts.map +1 -1
- package/dist/http/jsonrpc_errors.js +57 -33
- package/dist/http/jsonrpc_helpers.d.ts +56 -0
- package/dist/http/jsonrpc_helpers.d.ts.map +1 -0
- package/dist/http/jsonrpc_helpers.js +138 -0
- package/dist/testing/rpc_helpers.d.ts +1 -1
- package/dist/testing/rpc_helpers.d.ts.map +1 -1
- package/dist/testing/rpc_helpers.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"action_rpc.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/actions/action_rpc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,yBAAyB,CAAC;AAEpD,OAAO,KAAK,EAAC,yBAAyB,EAAC,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAoB,KAAK,SAAS,EAAC,MAAM,uBAAuB,CAAC;AACxE,OAAO,EAAgC,KAAK,cAAc,EAAC,MAAM,4BAA4B,CAAC;AAE9F,OAAO,KAAK,EAAC,EAAE,EAAC,MAAM,aAAa,CAAC;AAEpC,OAAO,
|
|
1
|
+
{"version":3,"file":"action_rpc.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/actions/action_rpc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAKH,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,yBAAyB,CAAC;AAEpD,OAAO,KAAK,EAAC,yBAAy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,SAAS,CAoOtF,CAAC"}
|
|
@@ -17,7 +17,7 @@ import {} from '../http/route_spec.js';
|
|
|
17
17
|
import { get_request_context, has_role } from '../auth/request_context.js';
|
|
18
18
|
import { CREDENTIAL_TYPE_KEY } from '../hono_context.js';
|
|
19
19
|
import { is_null_schema } from '../http/schema_helpers.js';
|
|
20
|
-
import { JSONRPC_VERSION, JsonrpcRequest } from '../http/jsonrpc.js';
|
|
20
|
+
import { JSONRPC_VERSION, JsonrpcRequest, } from '../http/jsonrpc.js';
|
|
21
21
|
import { jsonrpc_error_messages, jsonrpc_error_code_to_http_status, JSONRPC_ERROR_CODES, } from '../http/jsonrpc_errors.js';
|
|
22
22
|
/**
|
|
23
23
|
* Format a JSON-RPC error response.
|
package/dist/http/jsonrpc.d.ts
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* JSON-RPC 2.0 envelope schemas for
|
|
2
|
+
* JSON-RPC 2.0 envelope schemas for RPC dispatch and SAES transport.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* MCP extensions, notification types) remain in zzz.
|
|
4
|
+
* MCP-superset: includes optional `_meta` and `progressToken` fields
|
|
5
|
+
* on params and results. These are `optional()` so consumers that
|
|
6
|
+
* don't use MCP are unaffected.
|
|
8
7
|
*
|
|
9
8
|
* Following MCP, params and result are object-only (no positional arrays).
|
|
10
9
|
*
|
|
@@ -20,30 +19,101 @@ export type JsonrpcRequestId = z.infer<typeof JsonrpcRequestId>;
|
|
|
20
19
|
/** A JSON-RPC method name. */
|
|
21
20
|
export declare const JsonrpcMethod: z.ZodString;
|
|
22
21
|
export type JsonrpcMethod = z.infer<typeof JsonrpcMethod>;
|
|
23
|
-
/**
|
|
24
|
-
export declare const
|
|
22
|
+
/** A progress token, used to associate progress notifications with the original request. */
|
|
23
|
+
export declare const JsonrpcProgressToken: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
24
|
+
export type JsonrpcProgressToken = z.infer<typeof JsonrpcProgressToken>;
|
|
25
|
+
/** MCP metadata object — loose to allow additional properties and `.extend`. */
|
|
26
|
+
export declare const JsonrpcMcpMeta: z.ZodObject<{}, z.core.$loose>;
|
|
27
|
+
export type JsonrpcMcpMeta = z.infer<typeof JsonrpcMcpMeta>;
|
|
28
|
+
/** Request params metadata — extends MCP meta with optional progress token. */
|
|
29
|
+
export declare const JsonrpcRequestParamsMeta: z.ZodObject<{
|
|
30
|
+
progressToken: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
31
|
+
}, z.core.$loose>;
|
|
32
|
+
export type JsonrpcRequestParamsMeta = z.infer<typeof JsonrpcRequestParamsMeta>;
|
|
33
|
+
/** Request params — loose object with optional MCP metadata. */
|
|
34
|
+
export declare const JsonrpcRequestParams: z.ZodObject<{
|
|
35
|
+
_meta: z.ZodOptional<z.ZodObject<{
|
|
36
|
+
progressToken: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
37
|
+
}, z.core.$loose>>;
|
|
38
|
+
}, z.core.$loose>;
|
|
25
39
|
export type JsonrpcRequestParams = z.infer<typeof JsonrpcRequestParams>;
|
|
26
|
-
/**
|
|
27
|
-
export declare const
|
|
40
|
+
/** Notification params — loose object with optional MCP metadata. */
|
|
41
|
+
export declare const JsonrpcNotificationParams: z.ZodObject<{
|
|
42
|
+
/**
|
|
43
|
+
* Reserved by MCP to allow clients and servers to attach
|
|
44
|
+
* additional metadata to their notifications.
|
|
45
|
+
*/
|
|
46
|
+
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
47
|
+
}, z.core.$loose>;
|
|
48
|
+
export type JsonrpcNotificationParams = z.infer<typeof JsonrpcNotificationParams>;
|
|
49
|
+
/** Result — loose object with optional MCP metadata. */
|
|
50
|
+
export declare const JsonrpcResult: z.ZodObject<{
|
|
51
|
+
/**
|
|
52
|
+
* Reserved by the protocol to allow clients and servers
|
|
53
|
+
* to attach additional metadata to their responses.
|
|
54
|
+
*/
|
|
55
|
+
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
56
|
+
}, z.core.$loose>;
|
|
28
57
|
export type JsonrpcResult = z.infer<typeof JsonrpcResult>;
|
|
29
58
|
/** A request that expects a response. */
|
|
30
59
|
export declare const JsonrpcRequest: z.ZodObject<{
|
|
31
60
|
jsonrpc: z.ZodLiteral<"2.0">;
|
|
32
61
|
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
33
62
|
method: z.ZodString;
|
|
34
|
-
params: z.ZodOptional<z.ZodObject<{
|
|
63
|
+
params: z.ZodOptional<z.ZodObject<{
|
|
64
|
+
_meta: z.ZodOptional<z.ZodObject<{
|
|
65
|
+
progressToken: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
66
|
+
}, z.core.$loose>>;
|
|
67
|
+
}, z.core.$loose>>;
|
|
35
68
|
}, z.core.$loose>;
|
|
36
69
|
export type JsonrpcRequest = z.infer<typeof JsonrpcRequest>;
|
|
70
|
+
/** A notification which does not expect a response. */
|
|
71
|
+
export declare const JsonrpcNotification: z.ZodObject<{
|
|
72
|
+
jsonrpc: z.ZodLiteral<"2.0">;
|
|
73
|
+
method: z.ZodString;
|
|
74
|
+
params: z.ZodOptional<z.ZodObject<{
|
|
75
|
+
/**
|
|
76
|
+
* Reserved by MCP to allow clients and servers to attach
|
|
77
|
+
* additional metadata to their notifications.
|
|
78
|
+
*/
|
|
79
|
+
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
80
|
+
}, z.core.$loose>>;
|
|
81
|
+
}, z.core.$loose>;
|
|
82
|
+
export type JsonrpcNotification = z.infer<typeof JsonrpcNotification>;
|
|
37
83
|
/** A successful (non-error) response to a request. */
|
|
38
84
|
export declare const JsonrpcResponse: z.ZodObject<{
|
|
39
85
|
jsonrpc: z.ZodLiteral<"2.0">;
|
|
40
86
|
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
41
|
-
result: z.ZodObject<{
|
|
87
|
+
result: z.ZodObject<{
|
|
88
|
+
/**
|
|
89
|
+
* Reserved by the protocol to allow clients and servers
|
|
90
|
+
* to attach additional metadata to their responses.
|
|
91
|
+
*/
|
|
92
|
+
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
93
|
+
}, z.core.$loose>;
|
|
42
94
|
}, z.core.$loose>;
|
|
43
95
|
export type JsonrpcResponse = z.infer<typeof JsonrpcResponse>;
|
|
96
|
+
export declare const JSONRPC_PARSE_ERROR = -32700;
|
|
97
|
+
export declare const JSONRPC_INVALID_REQUEST = -32600;
|
|
98
|
+
export declare const JSONRPC_METHOD_NOT_FOUND = -32601;
|
|
99
|
+
export declare const JSONRPC_INVALID_PARAMS = -32602;
|
|
100
|
+
export declare const JSONRPC_INTERNAL_ERROR = -32603;
|
|
101
|
+
/** Start of the server-defined error code range (-32000). */
|
|
102
|
+
export declare const JSONRPC_SERVER_ERROR_START = -32000;
|
|
103
|
+
/** End of the server-defined error code range (-32099). */
|
|
104
|
+
export declare const JSONRPC_SERVER_ERROR_END = -32099;
|
|
105
|
+
/** A server-defined error code in the -32000 to -32099 range. */
|
|
106
|
+
export declare const JsonrpcServerErrorCode: z.core.$ZodBranded<z.ZodNumber, "JsonrpcServerErrorCode", "out">;
|
|
107
|
+
export type JsonrpcServerErrorCode = z.infer<typeof JsonrpcServerErrorCode>;
|
|
108
|
+
/**
|
|
109
|
+
* A valid JSON-RPC error code — one of the 5 standard codes or
|
|
110
|
+
* a server-defined code in the -32000 to -32099 range.
|
|
111
|
+
*/
|
|
112
|
+
export declare const JsonrpcErrorCode: z.ZodUnion<readonly [z.ZodLiteral<-32700>, z.ZodLiteral<-32600>, z.ZodLiteral<-32601>, z.ZodLiteral<-32602>, z.ZodLiteral<-32603>, z.core.$ZodBranded<z.ZodNumber, "JsonrpcServerErrorCode", "out">]>;
|
|
113
|
+
export type JsonrpcErrorCode = z.infer<typeof JsonrpcErrorCode>;
|
|
44
114
|
/** Error object within a JSON-RPC error response. */
|
|
45
115
|
export declare const JsonrpcErrorObject: z.ZodObject<{
|
|
46
|
-
code: z.ZodNumber
|
|
116
|
+
code: z.ZodUnion<readonly [z.ZodLiteral<-32700>, z.ZodLiteral<-32600>, z.ZodLiteral<-32601>, z.ZodLiteral<-32602>, z.ZodLiteral<-32603>, z.core.$ZodBranded<z.ZodNumber, "JsonrpcServerErrorCode", "out">]>;
|
|
47
117
|
message: z.ZodString;
|
|
48
118
|
data: z.ZodOptional<z.ZodUnknown>;
|
|
49
119
|
}, z.core.$loose>;
|
|
@@ -53,10 +123,124 @@ export declare const JsonrpcErrorResponse: z.ZodObject<{
|
|
|
53
123
|
jsonrpc: z.ZodLiteral<"2.0">;
|
|
54
124
|
id: z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
55
125
|
error: z.ZodObject<{
|
|
56
|
-
code: z.ZodNumber
|
|
126
|
+
code: z.ZodUnion<readonly [z.ZodLiteral<-32700>, z.ZodLiteral<-32600>, z.ZodLiteral<-32601>, z.ZodLiteral<-32602>, z.ZodLiteral<-32603>, z.core.$ZodBranded<z.ZodNumber, "JsonrpcServerErrorCode", "out">]>;
|
|
57
127
|
message: z.ZodString;
|
|
58
128
|
data: z.ZodOptional<z.ZodUnknown>;
|
|
59
129
|
}, z.core.$loose>;
|
|
60
130
|
}, z.core.$loose>;
|
|
61
131
|
export type JsonrpcErrorResponse = z.infer<typeof JsonrpcErrorResponse>;
|
|
132
|
+
/** A successful response or an error response. */
|
|
133
|
+
export declare const JsonrpcResponseOrError: z.ZodUnion<readonly [z.ZodObject<{
|
|
134
|
+
jsonrpc: z.ZodLiteral<"2.0">;
|
|
135
|
+
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
136
|
+
result: z.ZodObject<{
|
|
137
|
+
/**
|
|
138
|
+
* Reserved by the protocol to allow clients and servers
|
|
139
|
+
* to attach additional metadata to their responses.
|
|
140
|
+
*/
|
|
141
|
+
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
142
|
+
}, z.core.$loose>;
|
|
143
|
+
}, z.core.$loose>, z.ZodObject<{
|
|
144
|
+
jsonrpc: z.ZodLiteral<"2.0">;
|
|
145
|
+
id: z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
146
|
+
error: z.ZodObject<{
|
|
147
|
+
code: z.ZodUnion<readonly [z.ZodLiteral<-32700>, z.ZodLiteral<-32600>, z.ZodLiteral<-32601>, z.ZodLiteral<-32602>, z.ZodLiteral<-32603>, z.core.$ZodBranded<z.ZodNumber, "JsonrpcServerErrorCode", "out">]>;
|
|
148
|
+
message: z.ZodString;
|
|
149
|
+
data: z.ZodOptional<z.ZodUnknown>;
|
|
150
|
+
}, z.core.$loose>;
|
|
151
|
+
}, z.core.$loose>]>;
|
|
152
|
+
export type JsonrpcResponseOrError = z.infer<typeof JsonrpcResponseOrError>;
|
|
153
|
+
/** Any valid JSON-RPC message (request, notification, response, or error response). */
|
|
154
|
+
export declare const JsonrpcMessage: z.ZodUnion<readonly [z.ZodObject<{
|
|
155
|
+
jsonrpc: z.ZodLiteral<"2.0">;
|
|
156
|
+
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
157
|
+
method: z.ZodString;
|
|
158
|
+
params: z.ZodOptional<z.ZodObject<{
|
|
159
|
+
_meta: z.ZodOptional<z.ZodObject<{
|
|
160
|
+
progressToken: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
161
|
+
}, z.core.$loose>>;
|
|
162
|
+
}, z.core.$loose>>;
|
|
163
|
+
}, z.core.$loose>, z.ZodObject<{
|
|
164
|
+
jsonrpc: z.ZodLiteral<"2.0">;
|
|
165
|
+
method: z.ZodString;
|
|
166
|
+
params: z.ZodOptional<z.ZodObject<{
|
|
167
|
+
/**
|
|
168
|
+
* Reserved by MCP to allow clients and servers to attach
|
|
169
|
+
* additional metadata to their notifications.
|
|
170
|
+
*/
|
|
171
|
+
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
172
|
+
}, z.core.$loose>>;
|
|
173
|
+
}, z.core.$loose>, z.ZodObject<{
|
|
174
|
+
jsonrpc: z.ZodLiteral<"2.0">;
|
|
175
|
+
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
176
|
+
result: z.ZodObject<{
|
|
177
|
+
/**
|
|
178
|
+
* Reserved by the protocol to allow clients and servers
|
|
179
|
+
* to attach additional metadata to their responses.
|
|
180
|
+
*/
|
|
181
|
+
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
182
|
+
}, z.core.$loose>;
|
|
183
|
+
}, z.core.$loose>, z.ZodObject<{
|
|
184
|
+
jsonrpc: z.ZodLiteral<"2.0">;
|
|
185
|
+
id: z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
186
|
+
error: z.ZodObject<{
|
|
187
|
+
code: z.ZodUnion<readonly [z.ZodLiteral<-32700>, z.ZodLiteral<-32600>, z.ZodLiteral<-32601>, z.ZodLiteral<-32602>, z.ZodLiteral<-32603>, z.core.$ZodBranded<z.ZodNumber, "JsonrpcServerErrorCode", "out">]>;
|
|
188
|
+
message: z.ZodString;
|
|
189
|
+
data: z.ZodOptional<z.ZodUnknown>;
|
|
190
|
+
}, z.core.$loose>;
|
|
191
|
+
}, z.core.$loose>]>;
|
|
192
|
+
export type JsonrpcMessage = z.infer<typeof JsonrpcMessage>;
|
|
193
|
+
/** Messages a client can send to a server (request or notification). */
|
|
194
|
+
export declare const JsonrpcMessageFromClientToServer: z.ZodUnion<readonly [z.ZodObject<{
|
|
195
|
+
jsonrpc: z.ZodLiteral<"2.0">;
|
|
196
|
+
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
197
|
+
method: z.ZodString;
|
|
198
|
+
params: z.ZodOptional<z.ZodObject<{
|
|
199
|
+
_meta: z.ZodOptional<z.ZodObject<{
|
|
200
|
+
progressToken: z.ZodOptional<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
201
|
+
}, z.core.$loose>>;
|
|
202
|
+
}, z.core.$loose>>;
|
|
203
|
+
}, z.core.$loose>, z.ZodObject<{
|
|
204
|
+
jsonrpc: z.ZodLiteral<"2.0">;
|
|
205
|
+
method: z.ZodString;
|
|
206
|
+
params: z.ZodOptional<z.ZodObject<{
|
|
207
|
+
/**
|
|
208
|
+
* Reserved by MCP to allow clients and servers to attach
|
|
209
|
+
* additional metadata to their notifications.
|
|
210
|
+
*/
|
|
211
|
+
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
212
|
+
}, z.core.$loose>>;
|
|
213
|
+
}, z.core.$loose>]>;
|
|
214
|
+
export type JsonrpcMessageFromClientToServer = z.infer<typeof JsonrpcMessageFromClientToServer>;
|
|
215
|
+
/** Messages a server can send to a client (notification, response, or error response). */
|
|
216
|
+
export declare const JsonrpcMessageFromServerToClient: z.ZodUnion<readonly [z.ZodObject<{
|
|
217
|
+
jsonrpc: z.ZodLiteral<"2.0">;
|
|
218
|
+
method: z.ZodString;
|
|
219
|
+
params: z.ZodOptional<z.ZodObject<{
|
|
220
|
+
/**
|
|
221
|
+
* Reserved by MCP to allow clients and servers to attach
|
|
222
|
+
* additional metadata to their notifications.
|
|
223
|
+
*/
|
|
224
|
+
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
225
|
+
}, z.core.$loose>>;
|
|
226
|
+
}, z.core.$loose>, z.ZodObject<{
|
|
227
|
+
jsonrpc: z.ZodLiteral<"2.0">;
|
|
228
|
+
id: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
|
|
229
|
+
result: z.ZodObject<{
|
|
230
|
+
/**
|
|
231
|
+
* Reserved by the protocol to allow clients and servers
|
|
232
|
+
* to attach additional metadata to their responses.
|
|
233
|
+
*/
|
|
234
|
+
_meta: z.ZodOptional<z.ZodObject<{}, z.core.$loose>>;
|
|
235
|
+
}, z.core.$loose>;
|
|
236
|
+
}, z.core.$loose>, z.ZodObject<{
|
|
237
|
+
jsonrpc: z.ZodLiteral<"2.0">;
|
|
238
|
+
id: z.ZodNullable<z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>;
|
|
239
|
+
error: z.ZodObject<{
|
|
240
|
+
code: z.ZodUnion<readonly [z.ZodLiteral<-32700>, z.ZodLiteral<-32600>, z.ZodLiteral<-32601>, z.ZodLiteral<-32602>, z.ZodLiteral<-32603>, z.core.$ZodBranded<z.ZodNumber, "JsonrpcServerErrorCode", "out">]>;
|
|
241
|
+
message: z.ZodString;
|
|
242
|
+
data: z.ZodOptional<z.ZodUnknown>;
|
|
243
|
+
}, z.core.$loose>;
|
|
244
|
+
}, z.core.$loose>]>;
|
|
245
|
+
export type JsonrpcMessageFromServerToClient = z.infer<typeof JsonrpcMessageFromServerToClient>;
|
|
62
246
|
//# sourceMappingURL=jsonrpc.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonrpc.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/jsonrpc.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"jsonrpc.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/jsonrpc.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAEtB,eAAO,MAAM,eAAe,QAAQ,CAAC;AAErC,oFAAoF;AACpF,eAAO,MAAM,gBAAgB,iDAAoC,CAAC;AAClE,MAAM,MAAM,gBAAgB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAEhE,8BAA8B;AAC9B,eAAO,MAAM,aAAa,aAAa,CAAC;AACxC,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK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;;;WAGG;;;;;;;;;;;mBA4FF,CAAC;AACH,MAAM,MAAM,cAAc,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,cAAc,CAAC,CAAC;AAE5D,wEAAwE;AACxE,eAAO,MAAM,gCAAgC;;;;;;;;;;;;;QA7G5C;;;WAGG;;;mBA0G0F,CAAC;AAC/F,MAAM,MAAM,gCAAgC,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gCAAgC,CAAC,CAAC;AAEhG,0FAA0F;AAC1F,eAAO,MAAM,gCAAgC;;;;QAjH5C;;;WAGG;;;;;;;QAOH;;;WAGG;;;;;;;;;;;mBAwGF,CAAC;AACH,MAAM,MAAM,gCAAgC,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gCAAgC,CAAC,CAAC"}
|
package/dist/http/jsonrpc.js
CHANGED
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* JSON-RPC 2.0 envelope schemas for
|
|
2
|
+
* JSON-RPC 2.0 envelope schemas for RPC dispatch and SAES transport.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* MCP extensions, notification types) remain in zzz.
|
|
4
|
+
* MCP-superset: includes optional `_meta` and `progressToken` fields
|
|
5
|
+
* on params and results. These are `optional()` so consumers that
|
|
6
|
+
* don't use MCP are unaffected.
|
|
8
7
|
*
|
|
9
8
|
* Following MCP, params and result are object-only (no positional arrays).
|
|
10
9
|
*
|
|
@@ -18,10 +17,39 @@ export const JSONRPC_VERSION = '2.0';
|
|
|
18
17
|
export const JsonrpcRequestId = z.union([z.string(), z.number()]);
|
|
19
18
|
/** A JSON-RPC method name. */
|
|
20
19
|
export const JsonrpcMethod = z.string();
|
|
21
|
-
/**
|
|
22
|
-
export const
|
|
23
|
-
/**
|
|
24
|
-
export const
|
|
20
|
+
/** A progress token, used to associate progress notifications with the original request. */
|
|
21
|
+
export const JsonrpcProgressToken = z.union([z.string(), z.number()]);
|
|
22
|
+
/** MCP metadata object — loose to allow additional properties and `.extend`. */
|
|
23
|
+
export const JsonrpcMcpMeta = z.looseObject({});
|
|
24
|
+
/** Request params metadata — extends MCP meta with optional progress token. */
|
|
25
|
+
export const JsonrpcRequestParamsMeta = JsonrpcMcpMeta.extend({
|
|
26
|
+
/**
|
|
27
|
+
* If specified, the caller is requesting out-of-band progress notifications
|
|
28
|
+
* for this request. The value is an opaque token attached to subsequent
|
|
29
|
+
* notifications. The receiver is not obligated to provide these notifications.
|
|
30
|
+
*/
|
|
31
|
+
progressToken: JsonrpcProgressToken.optional(),
|
|
32
|
+
});
|
|
33
|
+
/** Request params — loose object with optional MCP metadata. */
|
|
34
|
+
export const JsonrpcRequestParams = z.looseObject({
|
|
35
|
+
_meta: JsonrpcRequestParamsMeta.optional(),
|
|
36
|
+
});
|
|
37
|
+
/** Notification params — loose object with optional MCP metadata. */
|
|
38
|
+
export const JsonrpcNotificationParams = z.looseObject({
|
|
39
|
+
/**
|
|
40
|
+
* Reserved by MCP to allow clients and servers to attach
|
|
41
|
+
* additional metadata to their notifications.
|
|
42
|
+
*/
|
|
43
|
+
_meta: JsonrpcMcpMeta.optional(),
|
|
44
|
+
});
|
|
45
|
+
/** Result — loose object with optional MCP metadata. */
|
|
46
|
+
export const JsonrpcResult = z.looseObject({
|
|
47
|
+
/**
|
|
48
|
+
* Reserved by the protocol to allow clients and servers
|
|
49
|
+
* to attach additional metadata to their responses.
|
|
50
|
+
*/
|
|
51
|
+
_meta: JsonrpcMcpMeta.optional(),
|
|
52
|
+
});
|
|
25
53
|
/** A request that expects a response. */
|
|
26
54
|
export const JsonrpcRequest = z.looseObject({
|
|
27
55
|
jsonrpc: z.literal(JSONRPC_VERSION),
|
|
@@ -29,15 +57,50 @@ export const JsonrpcRequest = z.looseObject({
|
|
|
29
57
|
method: JsonrpcMethod,
|
|
30
58
|
params: JsonrpcRequestParams.optional(),
|
|
31
59
|
});
|
|
60
|
+
/** A notification which does not expect a response. */
|
|
61
|
+
export const JsonrpcNotification = z.looseObject({
|
|
62
|
+
jsonrpc: z.literal(JSONRPC_VERSION),
|
|
63
|
+
method: JsonrpcMethod,
|
|
64
|
+
params: JsonrpcNotificationParams.optional(),
|
|
65
|
+
});
|
|
32
66
|
/** A successful (non-error) response to a request. */
|
|
33
67
|
export const JsonrpcResponse = z.looseObject({
|
|
34
68
|
jsonrpc: z.literal(JSONRPC_VERSION),
|
|
35
69
|
id: JsonrpcRequestId,
|
|
36
70
|
result: JsonrpcResult,
|
|
37
71
|
});
|
|
72
|
+
// --- Error code schemas ---
|
|
73
|
+
// Standard JSON-RPC error codes — https://www.jsonrpc.org/specification
|
|
74
|
+
export const JSONRPC_PARSE_ERROR = -32700;
|
|
75
|
+
export const JSONRPC_INVALID_REQUEST = -32600;
|
|
76
|
+
export const JSONRPC_METHOD_NOT_FOUND = -32601;
|
|
77
|
+
export const JSONRPC_INVALID_PARAMS = -32602;
|
|
78
|
+
export const JSONRPC_INTERNAL_ERROR = -32603;
|
|
79
|
+
/** Start of the server-defined error code range (-32000). */
|
|
80
|
+
export const JSONRPC_SERVER_ERROR_START = -32000;
|
|
81
|
+
/** End of the server-defined error code range (-32099). */
|
|
82
|
+
export const JSONRPC_SERVER_ERROR_END = -32099;
|
|
83
|
+
/** A server-defined error code in the -32000 to -32099 range. */
|
|
84
|
+
export const JsonrpcServerErrorCode = z
|
|
85
|
+
.number()
|
|
86
|
+
.gte(JSONRPC_SERVER_ERROR_END)
|
|
87
|
+
.lte(JSONRPC_SERVER_ERROR_START)
|
|
88
|
+
.brand('JsonrpcServerErrorCode');
|
|
89
|
+
/**
|
|
90
|
+
* A valid JSON-RPC error code — one of the 5 standard codes or
|
|
91
|
+
* a server-defined code in the -32000 to -32099 range.
|
|
92
|
+
*/
|
|
93
|
+
export const JsonrpcErrorCode = z.union([
|
|
94
|
+
z.literal(JSONRPC_PARSE_ERROR),
|
|
95
|
+
z.literal(JSONRPC_INVALID_REQUEST),
|
|
96
|
+
z.literal(JSONRPC_METHOD_NOT_FOUND),
|
|
97
|
+
z.literal(JSONRPC_INVALID_PARAMS),
|
|
98
|
+
z.literal(JSONRPC_INTERNAL_ERROR),
|
|
99
|
+
JsonrpcServerErrorCode,
|
|
100
|
+
]);
|
|
38
101
|
/** Error object within a JSON-RPC error response. */
|
|
39
102
|
export const JsonrpcErrorObject = z.looseObject({
|
|
40
|
-
code:
|
|
103
|
+
code: JsonrpcErrorCode,
|
|
41
104
|
message: z.string(),
|
|
42
105
|
data: z.unknown().optional(),
|
|
43
106
|
});
|
|
@@ -47,3 +110,20 @@ export const JsonrpcErrorResponse = z.looseObject({
|
|
|
47
110
|
id: JsonrpcRequestId.nullable(),
|
|
48
111
|
error: JsonrpcErrorObject,
|
|
49
112
|
});
|
|
113
|
+
/** A successful response or an error response. */
|
|
114
|
+
export const JsonrpcResponseOrError = z.union([JsonrpcResponse, JsonrpcErrorResponse]);
|
|
115
|
+
/** Any valid JSON-RPC message (request, notification, response, or error response). */
|
|
116
|
+
export const JsonrpcMessage = z.union([
|
|
117
|
+
JsonrpcRequest,
|
|
118
|
+
JsonrpcNotification,
|
|
119
|
+
JsonrpcResponse,
|
|
120
|
+
JsonrpcErrorResponse,
|
|
121
|
+
]);
|
|
122
|
+
/** Messages a client can send to a server (request or notification). */
|
|
123
|
+
export const JsonrpcMessageFromClientToServer = z.union([JsonrpcRequest, JsonrpcNotification]);
|
|
124
|
+
/** Messages a server can send to a client (notification, response, or error response). */
|
|
125
|
+
export const JsonrpcMessageFromServerToClient = z.union([
|
|
126
|
+
JsonrpcNotification,
|
|
127
|
+
JsonrpcResponse,
|
|
128
|
+
JsonrpcErrorResponse,
|
|
129
|
+
]);
|
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Provides error types, named constructors, and HTTP status mapping
|
|
5
5
|
* for the throw/catch error pattern used by `apply_route_specs`.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* Core error codes (5 standard + 8 general application). Domain-specific
|
|
7
|
+
* codes stay in consumers — add by casting `as JsonrpcErrorCode`.
|
|
8
|
+
*
|
|
9
|
+
* `JsonrpcErrorCode` and `JsonrpcErrorObject` types are Zod-inferred
|
|
10
|
+
* from `jsonrpc.ts` — this module re-uses those as the single source
|
|
11
|
+
* of truth.
|
|
10
12
|
*
|
|
11
13
|
* Complementary to `error_schemas.ts`: that module is declarative
|
|
12
14
|
* (Zod schemas for surface introspection), this one is runtime
|
|
@@ -14,16 +16,7 @@
|
|
|
14
16
|
*
|
|
15
17
|
* @module
|
|
16
18
|
*/
|
|
17
|
-
|
|
18
|
-
export type JsonrpcErrorCode = number & {
|
|
19
|
-
readonly __brand: 'JsonrpcErrorCode';
|
|
20
|
-
};
|
|
21
|
-
/** JSON-RPC error response object — code, message, and optional data. */
|
|
22
|
-
export interface JsonrpcErrorJson {
|
|
23
|
-
code: JsonrpcErrorCode;
|
|
24
|
-
message: string;
|
|
25
|
-
data?: unknown;
|
|
26
|
-
}
|
|
19
|
+
import { type JsonrpcErrorCode, type JsonrpcErrorObject } from './jsonrpc.js';
|
|
27
20
|
/** Names of standard and general application JSON-RPC error codes. */
|
|
28
21
|
export type JsonrpcErrorName = 'parse_error' | 'invalid_request' | 'method_not_found' | 'invalid_params' | 'internal_error' | 'unauthenticated' | 'forbidden' | 'not_found' | 'conflict' | 'validation_error' | 'rate_limited' | 'service_unavailable' | 'timeout';
|
|
29
22
|
/**
|
|
@@ -34,15 +27,10 @@ export type JsonrpcErrorName = 'parse_error' | 'invalid_request' | 'method_not_f
|
|
|
34
27
|
* -32099 range reserved by the JSON-RPC spec.
|
|
35
28
|
*/
|
|
36
29
|
export declare const JSONRPC_ERROR_CODES: {
|
|
37
|
-
/** -32700 */
|
|
38
30
|
readonly parse_error: JsonrpcErrorCode;
|
|
39
|
-
/** -32600 */
|
|
40
31
|
readonly invalid_request: JsonrpcErrorCode;
|
|
41
|
-
/** -32601 */
|
|
42
32
|
readonly method_not_found: JsonrpcErrorCode;
|
|
43
|
-
/** -32602 */
|
|
44
33
|
readonly invalid_params: JsonrpcErrorCode;
|
|
45
|
-
/** -32603 */
|
|
46
34
|
readonly internal_error: JsonrpcErrorCode;
|
|
47
35
|
/**
|
|
48
36
|
* Same as HTTP 401 "unauthorized", but correctly named.
|
|
@@ -67,26 +55,26 @@ export declare const JSONRPC_ERROR_CODES: {
|
|
|
67
55
|
readonly timeout: JsonrpcErrorCode;
|
|
68
56
|
};
|
|
69
57
|
/**
|
|
70
|
-
* Named constructors for `
|
|
58
|
+
* Named constructors for `JsonrpcErrorObject` values.
|
|
71
59
|
*
|
|
72
|
-
* Each function creates a JSON-RPC error
|
|
60
|
+
* Each function creates a JSON-RPC error object with the correct
|
|
73
61
|
* code and a sensible default message. Used by the catch layer in
|
|
74
62
|
* `apply_route_specs` to build response bodies.
|
|
75
63
|
*/
|
|
76
64
|
export declare const jsonrpc_error_messages: {
|
|
77
|
-
readonly parse_error: (data?: unknown) =>
|
|
78
|
-
readonly invalid_request: (data?: unknown) =>
|
|
79
|
-
readonly method_not_found: (method?: string, data?: unknown) =>
|
|
80
|
-
readonly invalid_params: (message?: string, data?: unknown) =>
|
|
81
|
-
readonly internal_error: (message?: string, data?: unknown) =>
|
|
82
|
-
readonly unauthenticated: (message?: string, data?: unknown) =>
|
|
83
|
-
readonly forbidden: (message?: string, data?: unknown) =>
|
|
84
|
-
readonly not_found: (resource?: string, data?: unknown) =>
|
|
85
|
-
readonly conflict: (message?: string, data?: unknown) =>
|
|
86
|
-
readonly validation_error: (message?: string, data?: unknown) =>
|
|
87
|
-
readonly rate_limited: (message?: string, data?: unknown) =>
|
|
88
|
-
readonly service_unavailable: (message?: string, data?: unknown) =>
|
|
89
|
-
readonly timeout: (message?: string, data?: unknown) =>
|
|
65
|
+
readonly parse_error: (data?: unknown) => JsonrpcErrorObject;
|
|
66
|
+
readonly invalid_request: (data?: unknown) => JsonrpcErrorObject;
|
|
67
|
+
readonly method_not_found: (method?: string, data?: unknown) => JsonrpcErrorObject;
|
|
68
|
+
readonly invalid_params: (message?: string, data?: unknown) => JsonrpcErrorObject;
|
|
69
|
+
readonly internal_error: (message?: string, data?: unknown) => JsonrpcErrorObject;
|
|
70
|
+
readonly unauthenticated: (message?: string, data?: unknown) => JsonrpcErrorObject;
|
|
71
|
+
readonly forbidden: (message?: string, data?: unknown) => JsonrpcErrorObject;
|
|
72
|
+
readonly not_found: (resource?: string, data?: unknown) => JsonrpcErrorObject;
|
|
73
|
+
readonly conflict: (message?: string, data?: unknown) => JsonrpcErrorObject;
|
|
74
|
+
readonly validation_error: (message?: string, data?: unknown) => JsonrpcErrorObject;
|
|
75
|
+
readonly rate_limited: (message?: string, data?: unknown) => JsonrpcErrorObject;
|
|
76
|
+
readonly service_unavailable: (message?: string, data?: unknown) => JsonrpcErrorObject;
|
|
77
|
+
readonly timeout: (message?: string, data?: unknown) => JsonrpcErrorObject;
|
|
90
78
|
};
|
|
91
79
|
/**
|
|
92
80
|
* Error class carrying a JSON-RPC error code — thrown by handlers,
|
|
@@ -119,6 +107,21 @@ export declare const jsonrpc_errors: {
|
|
|
119
107
|
readonly service_unavailable: (message?: string | undefined, data?: unknown) => ThrownJsonrpcError;
|
|
120
108
|
readonly timeout: (message?: string | undefined, data?: unknown) => ThrownJsonrpcError;
|
|
121
109
|
};
|
|
110
|
+
/**
|
|
111
|
+
* Maps JSON-RPC error codes to HTTP status codes.
|
|
112
|
+
*
|
|
113
|
+
* Extensible — consumers with domain-specific error codes can spread
|
|
114
|
+
* this into their own mapping object.
|
|
115
|
+
*/
|
|
116
|
+
export declare const JSONRPC_ERROR_CODE_TO_HTTP_STATUS: Record<number, number>;
|
|
117
|
+
/**
|
|
118
|
+
* Maps HTTP status codes to JSON-RPC error codes (reverse mapping).
|
|
119
|
+
*
|
|
120
|
+
* When multiple error codes map to the same HTTP status (e.g. parse_error
|
|
121
|
+
* and invalid_request both map to 400), the last one wins. Use for
|
|
122
|
+
* best-effort HTTP → JSON-RPC translation.
|
|
123
|
+
*/
|
|
124
|
+
export declare const HTTP_STATUS_TO_JSONRPC_ERROR_CODE: Record<number, JsonrpcErrorCode>;
|
|
122
125
|
/**
|
|
123
126
|
* Map a JSON-RPC error code to an HTTP status code.
|
|
124
127
|
*
|
|
@@ -129,4 +132,13 @@ export declare const jsonrpc_errors: {
|
|
|
129
132
|
* @returns the corresponding HTTP status code
|
|
130
133
|
*/
|
|
131
134
|
export declare const jsonrpc_error_code_to_http_status: (code: JsonrpcErrorCode) => number;
|
|
135
|
+
/**
|
|
136
|
+
* Map an HTTP status code to a JSON-RPC error code.
|
|
137
|
+
*
|
|
138
|
+
* Returns `internal_error` (-32603) for unrecognized status codes.
|
|
139
|
+
*
|
|
140
|
+
* @param status - the HTTP status code
|
|
141
|
+
* @returns the corresponding JSON-RPC error code
|
|
142
|
+
*/
|
|
143
|
+
export declare const http_status_to_jsonrpc_error_code: (status: number) => JsonrpcErrorCode;
|
|
132
144
|
//# sourceMappingURL=jsonrpc_errors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonrpc_errors.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/jsonrpc_errors.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"jsonrpc_errors.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/jsonrpc_errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAMN,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,MAAM,cAAc,CAAC;AAEtB,sEAAsE;AACtE,MAAM,MAAM,gBAAgB,GACzB,aAAa,GACb,iBAAiB,GACjB,kBAAkB,GAClB,gBAAgB,GAChB,gBAAgB,GAChB,iBAAiB,GACjB,WAAW,GACX,WAAW,GACX,UAAU,GACV,kBAAkB,GAClB,cAAc,GACd,qBAAqB,GACrB,SAAS,CAAC;AAEb;;;;;;GAMG;AACH,eAAO,MAAM,m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AAlB,kBAAkB;yEAAlB,kBAAkB;iFAAlB,kBAAkB;6EAAlB,kBAAkB;oFAAlB,kBAAkB;wEAAlB,kBAAkB;CAyBqC,CAAC;AAI3F;;;;;GAKG;AACH,eAAO,MAAM,iCAAiC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAcpE,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,iCAAiC,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAMzC,CAAC;AAEvC;;;;;;;;GAQG;AACH,eAAO,MAAM,iCAAiC,GAAI,MAAM,gBAAgB,KAAG,MAClB,CAAC;AAE1D;;;;;;;GAOG;AACH,eAAO,MAAM,iCAAiC,GAAI,QAAQ,MAAM,KAAG,gBACa,CAAC"}
|
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Provides error types, named constructors, and HTTP status mapping
|
|
5
5
|
* for the throw/catch error pattern used by `apply_route_specs`.
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* Core error codes (5 standard + 8 general application). Domain-specific
|
|
7
|
+
* codes stay in consumers — add by casting `as JsonrpcErrorCode`.
|
|
8
|
+
*
|
|
9
|
+
* `JsonrpcErrorCode` and `JsonrpcErrorObject` types are Zod-inferred
|
|
10
|
+
* from `jsonrpc.ts` — this module re-uses those as the single source
|
|
11
|
+
* of truth.
|
|
10
12
|
*
|
|
11
13
|
* Complementary to `error_schemas.ts`: that module is declarative
|
|
12
14
|
* (Zod schemas for surface introspection), this one is runtime
|
|
@@ -14,6 +16,7 @@
|
|
|
14
16
|
*
|
|
15
17
|
* @module
|
|
16
18
|
*/
|
|
19
|
+
import { JSONRPC_PARSE_ERROR, JSONRPC_INVALID_REQUEST, JSONRPC_METHOD_NOT_FOUND, JSONRPC_INVALID_PARAMS, JSONRPC_INTERNAL_ERROR, } from './jsonrpc.js';
|
|
17
20
|
/**
|
|
18
21
|
* Standard JSON-RPC error codes (5) plus general application codes (8).
|
|
19
22
|
*
|
|
@@ -22,17 +25,12 @@
|
|
|
22
25
|
* -32099 range reserved by the JSON-RPC spec.
|
|
23
26
|
*/
|
|
24
27
|
export const JSONRPC_ERROR_CODES = {
|
|
25
|
-
// Standard JSON-RPC errors —
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
method_not_found: -32601,
|
|
32
|
-
/** -32602 */
|
|
33
|
-
invalid_params: -32602,
|
|
34
|
-
/** -32603 */
|
|
35
|
-
internal_error: -32603,
|
|
28
|
+
// Standard JSON-RPC errors — values from jsonrpc.ts
|
|
29
|
+
parse_error: JSONRPC_PARSE_ERROR,
|
|
30
|
+
invalid_request: JSONRPC_INVALID_REQUEST,
|
|
31
|
+
method_not_found: JSONRPC_METHOD_NOT_FOUND,
|
|
32
|
+
invalid_params: JSONRPC_INVALID_PARAMS,
|
|
33
|
+
internal_error: JSONRPC_INTERNAL_ERROR,
|
|
36
34
|
// General application errors (-32000 to -32099)
|
|
37
35
|
/**
|
|
38
36
|
* Same as HTTP 401 "unauthorized", but correctly named.
|
|
@@ -57,9 +55,9 @@ export const JSONRPC_ERROR_CODES = {
|
|
|
57
55
|
timeout: -32008,
|
|
58
56
|
};
|
|
59
57
|
/**
|
|
60
|
-
* Named constructors for `
|
|
58
|
+
* Named constructors for `JsonrpcErrorObject` values.
|
|
61
59
|
*
|
|
62
|
-
* Each function creates a JSON-RPC error
|
|
60
|
+
* Each function creates a JSON-RPC error object with the correct
|
|
63
61
|
* code and a sensible default message. Used by the catch layer in
|
|
64
62
|
* `apply_route_specs` to build response bodies.
|
|
65
63
|
*/
|
|
@@ -170,21 +168,38 @@ export const jsonrpc_errors = {
|
|
|
170
168
|
timeout: create_error_thrower(jsonrpc_error_messages.timeout),
|
|
171
169
|
};
|
|
172
170
|
// --- HTTP status mapping ---
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
[-
|
|
181
|
-
[-
|
|
182
|
-
[-
|
|
183
|
-
[-
|
|
184
|
-
[-
|
|
185
|
-
[-
|
|
186
|
-
[-
|
|
187
|
-
]
|
|
171
|
+
/**
|
|
172
|
+
* Maps JSON-RPC error codes to HTTP status codes.
|
|
173
|
+
*
|
|
174
|
+
* Extensible — consumers with domain-specific error codes can spread
|
|
175
|
+
* this into their own mapping object.
|
|
176
|
+
*/
|
|
177
|
+
export const JSONRPC_ERROR_CODE_TO_HTTP_STATUS = {
|
|
178
|
+
[-32700]: 400, // parse_error
|
|
179
|
+
[-32600]: 400, // invalid_request
|
|
180
|
+
[-32601]: 404, // method_not_found
|
|
181
|
+
[-32602]: 400, // invalid_params
|
|
182
|
+
[-32603]: 500, // internal_error
|
|
183
|
+
[-32001]: 401, // unauthenticated
|
|
184
|
+
[-32002]: 403, // forbidden
|
|
185
|
+
[-32003]: 404, // not_found
|
|
186
|
+
[-32004]: 409, // conflict
|
|
187
|
+
[-32005]: 422, // validation_error
|
|
188
|
+
[-32006]: 429, // rate_limited
|
|
189
|
+
[-32007]: 503, // service_unavailable
|
|
190
|
+
[-32008]: 504, // timeout
|
|
191
|
+
};
|
|
192
|
+
/**
|
|
193
|
+
* Maps HTTP status codes to JSON-RPC error codes (reverse mapping).
|
|
194
|
+
*
|
|
195
|
+
* When multiple error codes map to the same HTTP status (e.g. parse_error
|
|
196
|
+
* and invalid_request both map to 400), the last one wins. Use for
|
|
197
|
+
* best-effort HTTP → JSON-RPC translation.
|
|
198
|
+
*/
|
|
199
|
+
export const HTTP_STATUS_TO_JSONRPC_ERROR_CODE = Object.fromEntries(Object.entries(JSONRPC_ERROR_CODE_TO_HTTP_STATUS).map(([code, status]) => [
|
|
200
|
+
status,
|
|
201
|
+
Number(code),
|
|
202
|
+
]));
|
|
188
203
|
/**
|
|
189
204
|
* Map a JSON-RPC error code to an HTTP status code.
|
|
190
205
|
*
|
|
@@ -194,4 +209,13 @@ const JSONRPC_ERROR_CODE_HTTP_STATUS = new Map([
|
|
|
194
209
|
* @param code - the JSON-RPC error code
|
|
195
210
|
* @returns the corresponding HTTP status code
|
|
196
211
|
*/
|
|
197
|
-
export const jsonrpc_error_code_to_http_status = (code) =>
|
|
212
|
+
export const jsonrpc_error_code_to_http_status = (code) => JSONRPC_ERROR_CODE_TO_HTTP_STATUS[code] ?? 500;
|
|
213
|
+
/**
|
|
214
|
+
* Map an HTTP status code to a JSON-RPC error code.
|
|
215
|
+
*
|
|
216
|
+
* Returns `internal_error` (-32603) for unrecognized status codes.
|
|
217
|
+
*
|
|
218
|
+
* @param status - the HTTP status code
|
|
219
|
+
* @returns the corresponding JSON-RPC error code
|
|
220
|
+
*/
|
|
221
|
+
export const http_status_to_jsonrpc_error_code = (status) => HTTP_STATUS_TO_JSONRPC_ERROR_CODE[status] ?? JSONRPC_ERROR_CODES.internal_error;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON-RPC message builders, type guards, and converters.
|
|
3
|
+
*
|
|
4
|
+
* Used by the SAES runtime (ActionEvent, ActionPeer, transports) and
|
|
5
|
+
* the RPC endpoint dispatcher. Complements `jsonrpc.ts` (schemas) and
|
|
6
|
+
* `jsonrpc_errors.ts` (error infrastructure).
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import { type JsonrpcErrorResponse, type JsonrpcMethod, type JsonrpcNotification, type JsonrpcNotificationParams, type JsonrpcRequest, type JsonrpcRequestId, type JsonrpcRequestParams, type JsonrpcResponse, type JsonrpcResult, type JsonrpcMessage, JSONRPC_VERSION } from './jsonrpc.js';
|
|
11
|
+
/** Creates a JSON-RPC request message. */
|
|
12
|
+
export declare const create_jsonrpc_request: (method: JsonrpcMethod, params: JsonrpcRequestParams | undefined, id: JsonrpcRequestId) => JsonrpcRequest;
|
|
13
|
+
/** Creates a JSON-RPC success response message. */
|
|
14
|
+
export declare const create_jsonrpc_response: (id: JsonrpcRequestId, result: JsonrpcResult) => JsonrpcResponse;
|
|
15
|
+
/** Creates a JSON-RPC notification message (no id, no response expected). */
|
|
16
|
+
export declare const create_jsonrpc_notification: (method: JsonrpcMethod, params: JsonrpcNotificationParams | undefined) => JsonrpcNotification;
|
|
17
|
+
/** Creates a JSON-RPC error response message. */
|
|
18
|
+
export declare const create_jsonrpc_error_response: (id: JsonrpcErrorResponse["id"], error: JsonrpcErrorResponse["error"]) => JsonrpcErrorResponse;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a JSON-RPC error response from any error.
|
|
21
|
+
* Handles `ThrownJsonrpcError` (preserves code/message/data) and
|
|
22
|
+
* regular `Error` objects (maps to internal_error, includes stack in DEV).
|
|
23
|
+
*/
|
|
24
|
+
export declare const create_jsonrpc_error_response_from_thrown: (id: JsonrpcRequestId | null, error: unknown) => JsonrpcErrorResponse;
|
|
25
|
+
/** Checks if a value is a valid JSON-RPC request id (string or finite number). */
|
|
26
|
+
export declare const is_jsonrpc_request_id: (id: unknown) => id is JsonrpcRequestId;
|
|
27
|
+
/** Checks if a value is a JSON-RPC object (has `jsonrpc: '2.0'`). */
|
|
28
|
+
export declare const is_jsonrpc_object: (message: unknown) => message is {
|
|
29
|
+
jsonrpc: typeof JSONRPC_VERSION;
|
|
30
|
+
};
|
|
31
|
+
/** Checks if a value is any valid JSON-RPC message or batch array. */
|
|
32
|
+
export declare const is_jsonrpc_message: (message: unknown) => message is JsonrpcMessage | Array<JsonrpcMessage>;
|
|
33
|
+
/** Checks if a value is a JSON-RPC request (has method + id). */
|
|
34
|
+
export declare const is_jsonrpc_request: (message: unknown) => message is JsonrpcRequest;
|
|
35
|
+
/** Checks if a value is a JSON-RPC notification (has method, no id). */
|
|
36
|
+
export declare const is_jsonrpc_notification: (message: unknown) => message is JsonrpcNotification;
|
|
37
|
+
/** Checks if a value is a JSON-RPC success response (has result + id). */
|
|
38
|
+
export declare const is_jsonrpc_response: (message: unknown) => message is JsonrpcResponse;
|
|
39
|
+
/** Checks if a value is a JSON-RPC error response (has error + id). */
|
|
40
|
+
export declare const is_jsonrpc_error_response: (message: unknown) => message is JsonrpcErrorResponse;
|
|
41
|
+
/**
|
|
42
|
+
* Extracts a JSON-RPC request id from a message or raw value.
|
|
43
|
+
* Returns `null` if no valid id can be extracted.
|
|
44
|
+
*/
|
|
45
|
+
export declare const to_jsonrpc_message_id: (message_or_id: unknown) => JsonrpcRequestId | null;
|
|
46
|
+
/**
|
|
47
|
+
* Normalizes input to JSON-RPC params format.
|
|
48
|
+
* Returns `undefined` for null/undefined, wraps primitives in `{value}`.
|
|
49
|
+
*/
|
|
50
|
+
export declare const to_jsonrpc_params: (input: unknown) => Record<string, any> | undefined;
|
|
51
|
+
/**
|
|
52
|
+
* Normalizes output to JSON-RPC result format.
|
|
53
|
+
* Returns empty object for null/undefined, wraps primitives in `{value}`.
|
|
54
|
+
*/
|
|
55
|
+
export declare const to_jsonrpc_result: (output: unknown) => Record<string, any>;
|
|
56
|
+
//# sourceMappingURL=jsonrpc_helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jsonrpc_helpers.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/jsonrpc_helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,OAAO,EACN,KAAK,oBAAoB,EACzB,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,yBAAyB,EAC9B,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,cAAc,EAEnB,eAAe,EACf,MAAM,cAAc,CAAC;AAKtB,0CAA0C;AAC1C,eAAO,MAAM,sBAAsB,GAClC,QAAQ,aAAa,EACrB,QAAQ,oBAAoB,GAAG,SAAS,EACxC,IAAI,gBAAgB,KAClB,cAUF,CAAC;AAEF,mDAAmD;AACnD,eAAO,MAAM,uBAAuB,GACnC,IAAI,gBAAg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B,GAAI,OAAO,OAAO,KAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAQxE,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,iBAAiB,GAAI,QAAQ,OAAO,KAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAQrE,CAAC"}
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON-RPC message builders, type guards, and converters.
|
|
3
|
+
*
|
|
4
|
+
* Used by the SAES runtime (ActionEvent, ActionPeer, transports) and
|
|
5
|
+
* the RPC endpoint dispatcher. Complements `jsonrpc.ts` (schemas) and
|
|
6
|
+
* `jsonrpc_errors.ts` (error infrastructure).
|
|
7
|
+
*
|
|
8
|
+
* @module
|
|
9
|
+
*/
|
|
10
|
+
import { DEV } from 'esm-env';
|
|
11
|
+
import { JSONRPC_VERSION, } from './jsonrpc.js';
|
|
12
|
+
import { ThrownJsonrpcError, JSONRPC_ERROR_CODES } from './jsonrpc_errors.js';
|
|
13
|
+
// --- Message builders ---
|
|
14
|
+
/** Creates a JSON-RPC request message. */
|
|
15
|
+
export const create_jsonrpc_request = (method, params, id) => {
|
|
16
|
+
const message = {
|
|
17
|
+
jsonrpc: JSONRPC_VERSION,
|
|
18
|
+
id,
|
|
19
|
+
method,
|
|
20
|
+
};
|
|
21
|
+
if (params !== undefined) {
|
|
22
|
+
message.params = params;
|
|
23
|
+
}
|
|
24
|
+
return message;
|
|
25
|
+
};
|
|
26
|
+
/** Creates a JSON-RPC success response message. */
|
|
27
|
+
export const create_jsonrpc_response = (id, result) => ({
|
|
28
|
+
jsonrpc: JSONRPC_VERSION,
|
|
29
|
+
id,
|
|
30
|
+
result,
|
|
31
|
+
});
|
|
32
|
+
/** Creates a JSON-RPC notification message (no id, no response expected). */
|
|
33
|
+
export const create_jsonrpc_notification = (method, params) => {
|
|
34
|
+
const message = {
|
|
35
|
+
jsonrpc: JSONRPC_VERSION,
|
|
36
|
+
method,
|
|
37
|
+
};
|
|
38
|
+
if (params !== undefined) {
|
|
39
|
+
message.params = params;
|
|
40
|
+
}
|
|
41
|
+
return message;
|
|
42
|
+
};
|
|
43
|
+
/** Creates a JSON-RPC error response message. */
|
|
44
|
+
export const create_jsonrpc_error_response = (id, error) => ({
|
|
45
|
+
jsonrpc: JSONRPC_VERSION,
|
|
46
|
+
id,
|
|
47
|
+
error,
|
|
48
|
+
});
|
|
49
|
+
/**
|
|
50
|
+
* Creates a JSON-RPC error response from any error.
|
|
51
|
+
* Handles `ThrownJsonrpcError` (preserves code/message/data) and
|
|
52
|
+
* regular `Error` objects (maps to internal_error, includes stack in DEV).
|
|
53
|
+
*/
|
|
54
|
+
export const create_jsonrpc_error_response_from_thrown = (id, error) => {
|
|
55
|
+
let code = JSONRPC_ERROR_CODES.internal_error;
|
|
56
|
+
let message = 'internal server error';
|
|
57
|
+
let data = undefined;
|
|
58
|
+
if (error instanceof ThrownJsonrpcError) {
|
|
59
|
+
code = error.code;
|
|
60
|
+
message = error.message;
|
|
61
|
+
data = error.data;
|
|
62
|
+
}
|
|
63
|
+
else if (error instanceof Error) {
|
|
64
|
+
if (DEV) {
|
|
65
|
+
message = error.message;
|
|
66
|
+
data = { stack: error.stack };
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
jsonrpc: JSONRPC_VERSION,
|
|
71
|
+
id,
|
|
72
|
+
error: {
|
|
73
|
+
code,
|
|
74
|
+
message,
|
|
75
|
+
data,
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
};
|
|
79
|
+
// --- Type guards ---
|
|
80
|
+
/** Checks if a value is a valid JSON-RPC request id (string or finite number). */
|
|
81
|
+
export const is_jsonrpc_request_id = (id) => {
|
|
82
|
+
const type = typeof id;
|
|
83
|
+
return type === 'string' || (type === 'number' && !Number.isNaN(id) && Number.isFinite(id));
|
|
84
|
+
};
|
|
85
|
+
/** Checks if a value is a JSON-RPC object (has `jsonrpc: '2.0'`). */
|
|
86
|
+
export const is_jsonrpc_object = (message) => typeof message === 'object' &&
|
|
87
|
+
message !== null &&
|
|
88
|
+
!Array.isArray(message) &&
|
|
89
|
+
message.jsonrpc === JSONRPC_VERSION;
|
|
90
|
+
/** Checks if a value is any valid JSON-RPC message or batch array. */
|
|
91
|
+
export const is_jsonrpc_message = (message) => Array.isArray(message)
|
|
92
|
+
? message.length > 0 && message.every((m) => is_jsonrpc_object(m))
|
|
93
|
+
: is_jsonrpc_object(message);
|
|
94
|
+
/** Checks if a value is a JSON-RPC request (has method + id). */
|
|
95
|
+
export const is_jsonrpc_request = (message) => is_jsonrpc_object(message) && 'method' in message && 'id' in message;
|
|
96
|
+
/** Checks if a value is a JSON-RPC notification (has method, no id). */
|
|
97
|
+
export const is_jsonrpc_notification = (message) => is_jsonrpc_object(message) && 'method' in message && !('id' in message);
|
|
98
|
+
/** Checks if a value is a JSON-RPC success response (has result + id). */
|
|
99
|
+
export const is_jsonrpc_response = (message) => is_jsonrpc_object(message) && 'result' in message && 'id' in message;
|
|
100
|
+
/** Checks if a value is a JSON-RPC error response (has error + id). */
|
|
101
|
+
export const is_jsonrpc_error_response = (message) => is_jsonrpc_object(message) && 'error' in message && 'id' in message;
|
|
102
|
+
// --- Converters ---
|
|
103
|
+
/**
|
|
104
|
+
* Extracts a JSON-RPC request id from a message or raw value.
|
|
105
|
+
* Returns `null` if no valid id can be extracted.
|
|
106
|
+
*/
|
|
107
|
+
export const to_jsonrpc_message_id = (message_or_id) => {
|
|
108
|
+
if (message_or_id == null)
|
|
109
|
+
return null;
|
|
110
|
+
const maybe_id = typeof message_or_id === 'object' ? message_or_id.id : message_or_id;
|
|
111
|
+
return is_jsonrpc_request_id(maybe_id) ? maybe_id : null;
|
|
112
|
+
};
|
|
113
|
+
/**
|
|
114
|
+
* Normalizes input to JSON-RPC params format.
|
|
115
|
+
* Returns `undefined` for null/undefined, wraps primitives in `{value}`.
|
|
116
|
+
*/
|
|
117
|
+
export const to_jsonrpc_params = (input) => {
|
|
118
|
+
if (input === undefined || input === null) {
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
if (typeof input === 'object' && !Array.isArray(input)) {
|
|
122
|
+
return input;
|
|
123
|
+
}
|
|
124
|
+
return { value: input };
|
|
125
|
+
};
|
|
126
|
+
/**
|
|
127
|
+
* Normalizes output to JSON-RPC result format.
|
|
128
|
+
* Returns empty object for null/undefined, wraps primitives in `{value}`.
|
|
129
|
+
*/
|
|
130
|
+
export const to_jsonrpc_result = (output) => {
|
|
131
|
+
if (output === null || output === undefined) {
|
|
132
|
+
return {};
|
|
133
|
+
}
|
|
134
|
+
if (typeof output === 'object' && !Array.isArray(output)) {
|
|
135
|
+
return output;
|
|
136
|
+
}
|
|
137
|
+
return { value: output };
|
|
138
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc_helpers.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/rpc_helpers.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAW7B,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"rpc_helpers.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/rpc_helpers.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAW7B,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAEtB,OAAO,EAIN,KAAK,gBAAgB,EACrB,MAAM,oBAAoB,CAAC;AAE5B;;;;;;;GAOG;AACH,eAAO,MAAM,oBAAoB,GAChC,QAAQ,MAAM,EACd,SAAS,OAAO,EAChB,KAAI,MAAM,GAAG,MAAe,KAC1B,WAID,CAAC;AAEH;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,GAC9B,eAAe,MAAM,EACrB,QAAQ,MAAM,EACd,SAAS,OAAO,EAChB,KAAI,MAAM,GAAG,MAAe,KAC1B,MAMF,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,6BAA6B,GACzC,MAAM,OAAO,EACb,gBAAgB,gBAAgB,KAC9B,IAUF,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,+BAA+B,GAAI,MAAM,OAAO,EAAE,gBAAgB,CAAC,CAAC,OAAO,KAAG,IAU1F,CAAC"}
|
|
@@ -8,7 +8,7 @@ import './assert_dev_env.js';
|
|
|
8
8
|
*/
|
|
9
9
|
import { assert } from 'vitest';
|
|
10
10
|
import { z } from 'zod';
|
|
11
|
-
import { JSONRPC_VERSION, JsonrpcErrorResponse, JsonrpcResponse } from '../http/jsonrpc.js';
|
|
11
|
+
import { JSONRPC_VERSION, JsonrpcErrorResponse, JsonrpcResponse, } from '../http/jsonrpc.js';
|
|
12
12
|
/**
|
|
13
13
|
* Create a `RequestInit` for a JSON-RPC POST request.
|
|
14
14
|
*
|