@fuzdev/fuz_app 0.167.0 → 0.168.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/CLAUDE.md +9 -8
- package/dist/actions/action_dispatcher.d.ts +1 -1
- package/dist/actions/action_dispatcher.d.ts.map +1 -1
- package/dist/actions/action_dispatcher.js +1 -1
- package/dist/actions/action_event.d.ts.map +1 -1
- package/dist/actions/action_event.js +1 -1
- package/dist/actions/action_event_data.d.ts +260 -65
- package/dist/actions/action_event_data.d.ts.map +1 -1
- package/dist/actions/action_event_data.js +11 -11
- package/dist/actions/action_event_types.d.ts +5 -14
- package/dist/actions/action_event_types.d.ts.map +1 -1
- package/dist/actions/action_event_types.js +3 -3
- package/dist/actions/action_rpc.js +5 -5
- package/dist/actions/action_spec.d.ts +8 -26
- package/dist/actions/action_spec.d.ts.map +1 -1
- package/dist/actions/action_spec.js +4 -4
- package/dist/actions/broadcast_api.d.ts +1 -1
- package/dist/actions/broadcast_api.js +1 -1
- package/dist/actions/cancel.d.ts +17 -9
- package/dist/actions/cancel.d.ts.map +1 -1
- package/dist/actions/cancel.js +3 -3
- package/dist/actions/heartbeat.d.ts +3 -4
- package/dist/actions/heartbeat.d.ts.map +1 -1
- package/dist/actions/heartbeat.js +4 -4
- package/dist/actions/peer_ping.d.ts +63 -23
- package/dist/actions/peer_ping.d.ts.map +1 -1
- package/dist/actions/peer_ping.js +20 -19
- package/dist/actions/peer_request.d.ts +6 -3
- package/dist/actions/peer_request.d.ts.map +1 -1
- package/dist/actions/peer_request.js +8 -2
- package/dist/actions/perform_action.d.ts +1 -1
- package/dist/actions/perform_action.d.ts.map +1 -1
- package/dist/actions/transports.d.ts +2 -3
- package/dist/actions/transports.d.ts.map +1 -1
- package/dist/actions/transports.js +0 -4
- package/dist/actions/transports_http.d.ts.map +1 -1
- package/dist/actions/transports_http.js +4 -3
- package/dist/actions/transports_ws.d.ts.map +1 -1
- package/dist/actions/ws_socket_session.d.ts.map +1 -1
- package/dist/actions/ws_socket_session.js +6 -5
- package/dist/http/CLAUDE.md +9 -8
- package/dist/http/jsonrpc.d.ts +231 -152
- package/dist/http/jsonrpc.d.ts.map +1 -1
- package/dist/http/jsonrpc.js +55 -85
- package/dist/http/jsonrpc_errors.d.ts +22 -4
- package/dist/http/jsonrpc_errors.d.ts.map +1 -1
- package/dist/http/jsonrpc_errors.js +37 -4
- package/dist/http/jsonrpc_helpers.d.ts.map +1 -1
- package/dist/http/jsonrpc_helpers.js +13 -12
- package/dist/testing/CLAUDE.md +6 -3
- package/dist/testing/cross_backend/peer_ping_ws.d.ts +3 -2
- package/dist/testing/cross_backend/peer_ping_ws.d.ts.map +1 -1
- package/dist/testing/cross_backend/peer_ping_ws.js +49 -2
- 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 +13 -14
- package/dist/testing/rpc_round_trip.d.ts.map +1 -1
- package/dist/testing/rpc_round_trip.js +11 -11
- package/dist/testing/transports/ws_client.js +1 -1
- package/dist/ui/SurfaceExplorer.svelte +2 -2
- package/package.json +2 -2
package/dist/http/jsonrpc.js
CHANGED
|
@@ -2,73 +2,57 @@
|
|
|
2
2
|
* JSON-RPC 2.0 envelope schemas for RPC dispatch and SAES transport.
|
|
3
3
|
*
|
|
4
4
|
* Params are object-only following MCP (no positional arrays); per-action
|
|
5
|
-
* spec.input narrows further. Result is
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* inherited from MCP would reject any action with `output: z.null()` /
|
|
10
|
-
* `z.string()` / etc. on the wire, so we relax it here while keeping
|
|
11
|
-
* MCP-superset shape on params + _meta.
|
|
5
|
+
* spec.input narrows further. Result is any value per spec §5 ("determined
|
|
6
|
+
* by the method invoked") — the per-action spec.output is the actual
|
|
7
|
+
* contract, so an action whose output is `null` or a string travels in the
|
|
8
|
+
* same envelope as one whose output is an object.
|
|
12
9
|
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
* schemas where it produces the correct error code (`invalid_params`, not
|
|
17
|
-
* `invalid_request`).
|
|
10
|
+
* The envelopes are `loose_object`s: JSON-RPC and MCP both extend them with
|
|
11
|
+
* members a reader passes over, so an unknown key is kept rather than
|
|
12
|
+
* refused. A parse returns the frame itself, not a copy.
|
|
18
13
|
*
|
|
19
14
|
* @source https://github.com/modelcontextprotocol/typescript-sdk
|
|
20
15
|
* @see https://www.jsonrpc.org/specification
|
|
21
16
|
* @module
|
|
22
17
|
*/
|
|
23
|
-
import {
|
|
18
|
+
import { brand, integer, literal, loose_object, max_value, min_value, nullable, number, one_of, optional, pipe, string, union, unknown } from '@fuzdev/fuz_schema/schema.ts';
|
|
24
19
|
export const JSONRPC_VERSION = '2.0';
|
|
25
20
|
/** A uniquely identifying id for a request in JSON-RPC. Like MCP, excludes null. */
|
|
26
|
-
export const JsonrpcRequestId =
|
|
21
|
+
export const JsonrpcRequestId = union([string, number]);
|
|
27
22
|
/** A JSON-RPC method name. */
|
|
28
|
-
export const JsonrpcMethod =
|
|
29
|
-
/**
|
|
30
|
-
export const
|
|
31
|
-
/**
|
|
32
|
-
export const
|
|
33
|
-
/** Request params metadata — extends MCP meta with optional progress token. */
|
|
34
|
-
export const JsonrpcRequestParamsMeta = JsonrpcMcpMeta.extend({
|
|
35
|
-
/**
|
|
36
|
-
* If specified, the caller is requesting out-of-band progress notifications
|
|
37
|
-
* for this request. The value is an opaque token attached to subsequent
|
|
38
|
-
* notifications. The receiver is not obligated to provide these notifications.
|
|
39
|
-
*/
|
|
40
|
-
progressToken: JsonrpcProgressToken.optional()
|
|
41
|
-
});
|
|
42
|
-
/** Request params — loose object. Per-action schemas validate `_meta` content. */
|
|
43
|
-
export const JsonrpcRequestParams = z.looseObject({});
|
|
44
|
-
/** Notification params — loose object. Per-action schemas validate `_meta` content. */
|
|
45
|
-
export const JsonrpcNotificationParams = z.looseObject({});
|
|
23
|
+
export const JsonrpcMethod = string;
|
|
24
|
+
/** Request params — an object, its keys kept. Per-action schemas validate the content. */
|
|
25
|
+
export const JsonrpcRequestParams = loose_object({});
|
|
26
|
+
/** Notification params — an object, its keys kept. Per-action schemas validate the content. */
|
|
27
|
+
export const JsonrpcNotificationParams = loose_object({});
|
|
46
28
|
/**
|
|
47
|
-
* Result — any
|
|
48
|
-
*
|
|
29
|
+
* Result — any value per JSON-RPC 2.0 §5. Per-action `spec.output` is the
|
|
30
|
+
* actual contract; the envelope asserts only that the key is present.
|
|
49
31
|
*
|
|
50
|
-
* `
|
|
51
|
-
* `
|
|
52
|
-
*
|
|
53
|
-
*
|
|
32
|
+
* `unknown` needs its key, so an error envelope `{jsonrpc, id, error}` fails
|
|
33
|
+
* the success envelope at `result` and the two stay apart in a union. It
|
|
34
|
+
* also takes what isn't a JSON value: `undefined` at a present key or a
|
|
35
|
+
* `Date`, which no parsed frame holds, and `±Infinity`, which `JSON.parse`
|
|
36
|
+
* makes of an out-of-range number such as `1e400` and which no server
|
|
37
|
+
* writes.
|
|
54
38
|
*/
|
|
55
|
-
export const JsonrpcResult =
|
|
39
|
+
export const JsonrpcResult = unknown;
|
|
56
40
|
/** A request that expects a response. */
|
|
57
|
-
export const JsonrpcRequest =
|
|
58
|
-
jsonrpc:
|
|
41
|
+
export const JsonrpcRequest = loose_object({
|
|
42
|
+
jsonrpc: literal(JSONRPC_VERSION),
|
|
59
43
|
id: JsonrpcRequestId,
|
|
60
44
|
method: JsonrpcMethod,
|
|
61
|
-
params:
|
|
45
|
+
params: optional(JsonrpcRequestParams)
|
|
62
46
|
});
|
|
63
47
|
/** A notification which does not expect a response. */
|
|
64
|
-
export const JsonrpcNotification =
|
|
65
|
-
jsonrpc:
|
|
48
|
+
export const JsonrpcNotification = loose_object({
|
|
49
|
+
jsonrpc: literal(JSONRPC_VERSION),
|
|
66
50
|
method: JsonrpcMethod,
|
|
67
|
-
params:
|
|
51
|
+
params: optional(JsonrpcNotificationParams)
|
|
68
52
|
});
|
|
69
53
|
/** A successful (non-error) response to a request. */
|
|
70
|
-
export const JsonrpcResponse =
|
|
71
|
-
jsonrpc:
|
|
54
|
+
export const JsonrpcResponse = loose_object({
|
|
55
|
+
jsonrpc: literal(JSONRPC_VERSION),
|
|
72
56
|
id: JsonrpcRequestId,
|
|
73
57
|
result: JsonrpcResult
|
|
74
58
|
});
|
|
@@ -83,28 +67,29 @@ export const JSONRPC_INTERNAL_ERROR = -32603;
|
|
|
83
67
|
export const JSONRPC_SERVER_ERROR_START = -32000;
|
|
84
68
|
/** End of the server-defined error code range (-32099). */
|
|
85
69
|
export const JSONRPC_SERVER_ERROR_END = -32099;
|
|
86
|
-
/** A server-defined error code in the -32000 to -32099 range. */
|
|
87
|
-
export const JsonrpcServerErrorCode = z
|
|
88
|
-
.number()
|
|
89
|
-
.gte(JSONRPC_SERVER_ERROR_END)
|
|
90
|
-
.lte(JSONRPC_SERVER_ERROR_START)
|
|
91
|
-
.brand('JsonrpcServerErrorCode');
|
|
92
70
|
/**
|
|
93
|
-
* A
|
|
94
|
-
*
|
|
71
|
+
* A server-defined error code, an integer in the -32000 to -32099 range (the
|
|
72
|
+
* Rust spine's codes are `i32`s).
|
|
73
|
+
*/
|
|
74
|
+
export const JsonrpcServerErrorCode = brand(pipe(number, integer, min_value(JSONRPC_SERVER_ERROR_END), max_value(JSONRPC_SERVER_ERROR_START)), 'JsonrpcServerErrorCode');
|
|
75
|
+
/**
|
|
76
|
+
* A valid JSON-RPC error code — one of the standard codes or a
|
|
77
|
+
* server-defined code in the -32000 to -32099 range.
|
|
95
78
|
*/
|
|
96
|
-
export const JsonrpcErrorCode =
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
79
|
+
export const JsonrpcErrorCode = union([
|
|
80
|
+
one_of([
|
|
81
|
+
JSONRPC_PARSE_ERROR,
|
|
82
|
+
JSONRPC_INVALID_REQUEST,
|
|
83
|
+
JSONRPC_METHOD_NOT_FOUND,
|
|
84
|
+
JSONRPC_INVALID_PARAMS,
|
|
85
|
+
JSONRPC_INTERNAL_ERROR
|
|
86
|
+
]),
|
|
102
87
|
JsonrpcServerErrorCode
|
|
103
88
|
]);
|
|
104
89
|
/**
|
|
105
90
|
* Whether `value` is a valid JSON-RPC error code — the codes `JsonrpcErrorCode`
|
|
106
|
-
* parses
|
|
107
|
-
*
|
|
91
|
+
* parses. A numeric `code` alone doesn't make an error a JSON-RPC one: a
|
|
92
|
+
* `DOMException`'s `code` is a small positive number.
|
|
108
93
|
*
|
|
109
94
|
* @param value - the candidate code
|
|
110
95
|
* @returns whether `value` is one of the standard codes or an integer in the server range
|
|
@@ -119,31 +104,16 @@ export const is_jsonrpc_error_code = (value) => typeof value === 'number' &&
|
|
|
119
104
|
value >= JSONRPC_SERVER_ERROR_END &&
|
|
120
105
|
value <= JSONRPC_SERVER_ERROR_START));
|
|
121
106
|
/** Error object within a JSON-RPC error response. */
|
|
122
|
-
export const JsonrpcErrorObject =
|
|
107
|
+
export const JsonrpcErrorObject = loose_object({
|
|
123
108
|
code: JsonrpcErrorCode,
|
|
124
|
-
message:
|
|
125
|
-
data:
|
|
109
|
+
message: string,
|
|
110
|
+
data: optional(unknown)
|
|
126
111
|
});
|
|
127
112
|
/** A response that indicates an error occurred. */
|
|
128
|
-
export const JsonrpcErrorResponse =
|
|
129
|
-
jsonrpc:
|
|
130
|
-
id:
|
|
113
|
+
export const JsonrpcErrorResponse = loose_object({
|
|
114
|
+
jsonrpc: literal(JSONRPC_VERSION),
|
|
115
|
+
id: nullable(JsonrpcRequestId),
|
|
131
116
|
error: JsonrpcErrorObject
|
|
132
117
|
});
|
|
133
118
|
/** A successful response or an error response. */
|
|
134
|
-
export const JsonrpcResponseOrError =
|
|
135
|
-
/** Any valid JSON-RPC message (request, notification, response, or error response). */
|
|
136
|
-
export const JsonrpcMessage = z.union([
|
|
137
|
-
JsonrpcRequest,
|
|
138
|
-
JsonrpcNotification,
|
|
139
|
-
JsonrpcResponse,
|
|
140
|
-
JsonrpcErrorResponse
|
|
141
|
-
]);
|
|
142
|
-
/** Messages a client can send to a server (request or notification). */
|
|
143
|
-
export const JsonrpcMessageFromClientToServer = z.union([JsonrpcRequest, JsonrpcNotification]);
|
|
144
|
-
/** Messages a server can send to a client (notification, response, or error response). */
|
|
145
|
-
export const JsonrpcMessageFromServerToClient = z.union([
|
|
146
|
-
JsonrpcNotification,
|
|
147
|
-
JsonrpcResponse,
|
|
148
|
-
JsonrpcErrorResponse
|
|
149
|
-
]);
|
|
119
|
+
export const JsonrpcResponseOrError = union([JsonrpcResponse, JsonrpcErrorResponse]);
|
|
@@ -7,12 +7,12 @@
|
|
|
7
7
|
* codes stay in consumers — add by casting `as JsonrpcErrorCode`, and
|
|
8
8
|
* declare each one's HTTP status with `register_jsonrpc_error_code`.
|
|
9
9
|
*
|
|
10
|
-
* `JsonrpcErrorCode` and `JsonrpcErrorObject` types are
|
|
11
|
-
*
|
|
12
|
-
* of truth.
|
|
10
|
+
* The `JsonrpcErrorCode` and `JsonrpcErrorObject` types are inferred from
|
|
11
|
+
* the schemas of `http/jsonrpc.ts` — this module re-uses those as the single
|
|
12
|
+
* source of truth.
|
|
13
13
|
*
|
|
14
14
|
* Complementary to `http/error_schemas.ts`: that module is declarative
|
|
15
|
-
* (
|
|
15
|
+
* (schemas for surface introspection), this one is runtime
|
|
16
16
|
* (throw + catch + map).
|
|
17
17
|
*
|
|
18
18
|
* @module
|
|
@@ -137,6 +137,24 @@ export declare const jsonrpc_errors: {
|
|
|
137
137
|
readonly queue_overflow: (...args: any[]) => ThrownJsonrpcError;
|
|
138
138
|
readonly request_cancelled: (...args: any[]) => ThrownJsonrpcError;
|
|
139
139
|
};
|
|
140
|
+
/**
|
|
141
|
+
* Read the `error` member of a peer's error reply — the reply a connected
|
|
142
|
+
* client sends to a server-initiated request — as the error the awaiting
|
|
143
|
+
* caller gets. Twin of the Rust spine's `parse_inbound_error` (`fuz_http`).
|
|
144
|
+
*
|
|
145
|
+
* The peer is untrusted, so the read is lenient and always yields a base-set
|
|
146
|
+
* error: a `code` that isn't one of `JSONRPC_ERROR_CODES` (a consumer's code
|
|
147
|
+
* included — the wire carries no HTTP status to rebuild one with — and any
|
|
148
|
+
* non-integer) is `internal_error` (an integral float spelling, `-32002.0`, is
|
|
149
|
+
* its integer, as on the Rust spine); a `message` that isn't a string is
|
|
150
|
+
* `'peer error'`; and an own `data` passes through as sent, `null` included.
|
|
151
|
+
* An `error` that isn't an object (`null`, an array) is read as one with none
|
|
152
|
+
* of the three.
|
|
153
|
+
*
|
|
154
|
+
* @param error - the reply's `error` member, of any shape
|
|
155
|
+
* @returns the error object the caller sees
|
|
156
|
+
*/
|
|
157
|
+
export declare const parse_inbound_jsonrpc_error: (error: unknown) => JsonrpcErrorObject;
|
|
140
158
|
/**
|
|
141
159
|
* Declare a consumer JSON-RPC error code and the HTTP status it answers, so
|
|
142
160
|
* `jsonrpc_error_code_to_http_status` maps it instead of falling back to 500.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonrpc_errors.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/jsonrpc_errors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAIH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAEnE,OAAO,EASN,KAAK,gBAAgB,EACrB,KAAK,kBAAkB,EACvB,MAAM,cAAc,CAAC;AAEtB,0CAA0C;AAC1C,eAAO,MAAM,qBAAqB,kBAAkB,CAAC;AAErD,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,GACT,gBAAgB,GAChB,mBAAmB,CAAC;AAEvB;;;;;;;;;;;GA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0BzF,CAAC;AAEF;;;;;;;;GAQG;AACH,eAAO,MAAM,iCAAiC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAQvF,CAAC;AAEH;;;;;;;;;GASG;AACH,eAAO,MAAM,iCAAiC,GAAI,MAAM,gBAAgB,KAAG,oBACC,CAAC;AAE7E;;;;GAIG;AACH,eAAO,MAAM,iCAAiC,GAAI,QAAQ,MAAM,KAAG,gBACa,CAAC;AAEjF;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,0BAA0B,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAMjF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,0BAA0B,GAAI,MAAM,gBAAgB,KAAG,gBACL,CAAC"}
|
|
@@ -7,12 +7,12 @@
|
|
|
7
7
|
* codes stay in consumers — add by casting `as JsonrpcErrorCode`, and
|
|
8
8
|
* declare each one's HTTP status with `register_jsonrpc_error_code`.
|
|
9
9
|
*
|
|
10
|
-
* `JsonrpcErrorCode` and `JsonrpcErrorObject` types are
|
|
11
|
-
*
|
|
12
|
-
* of truth.
|
|
10
|
+
* The `JsonrpcErrorCode` and `JsonrpcErrorObject` types are inferred from
|
|
11
|
+
* the schemas of `http/jsonrpc.ts` — this module re-uses those as the single
|
|
12
|
+
* source of truth.
|
|
13
13
|
*
|
|
14
14
|
* Complementary to `http/error_schemas.ts`: that module is declarative
|
|
15
|
-
* (
|
|
15
|
+
* (schemas for surface introspection), this one is runtime
|
|
16
16
|
* (throw + catch + map).
|
|
17
17
|
*
|
|
18
18
|
* @module
|
|
@@ -323,6 +323,39 @@ const jsonrpc_error_code_http_statuses = new Map(Object.entries(BASE_JSONRPC_ERR
|
|
|
323
323
|
]));
|
|
324
324
|
/** Every code `JSONRPC_ERROR_CODES` defines — the numbers a consumer code may not reuse. */
|
|
325
325
|
const BASE_JSONRPC_ERROR_CODE_SET = new Set(Object.values(JSONRPC_ERROR_CODES));
|
|
326
|
+
/**
|
|
327
|
+
* Read the `error` member of a peer's error reply — the reply a connected
|
|
328
|
+
* client sends to a server-initiated request — as the error the awaiting
|
|
329
|
+
* caller gets. Twin of the Rust spine's `parse_inbound_error` (`fuz_http`).
|
|
330
|
+
*
|
|
331
|
+
* The peer is untrusted, so the read is lenient and always yields a base-set
|
|
332
|
+
* error: a `code` that isn't one of `JSONRPC_ERROR_CODES` (a consumer's code
|
|
333
|
+
* included — the wire carries no HTTP status to rebuild one with — and any
|
|
334
|
+
* non-integer) is `internal_error` (an integral float spelling, `-32002.0`, is
|
|
335
|
+
* its integer, as on the Rust spine); a `message` that isn't a string is
|
|
336
|
+
* `'peer error'`; and an own `data` passes through as sent, `null` included.
|
|
337
|
+
* An `error` that isn't an object (`null`, an array) is read as one with none
|
|
338
|
+
* of the three.
|
|
339
|
+
*
|
|
340
|
+
* @param error - the reply's `error` member, of any shape
|
|
341
|
+
* @returns the error object the caller sees
|
|
342
|
+
*/
|
|
343
|
+
export const parse_inbound_jsonrpc_error = (error) => {
|
|
344
|
+
const obj = typeof error === 'object' && error !== null && !Array.isArray(error)
|
|
345
|
+
? error
|
|
346
|
+
: null;
|
|
347
|
+
const code = obj?.code;
|
|
348
|
+
const message = obj?.message;
|
|
349
|
+
const parsed = {
|
|
350
|
+
code: typeof code === 'number' && BASE_JSONRPC_ERROR_CODE_SET.has(code)
|
|
351
|
+
? code
|
|
352
|
+
: JSONRPC_ERROR_CODES.internal_error,
|
|
353
|
+
message: typeof message === 'string' ? message : 'peer error'
|
|
354
|
+
};
|
|
355
|
+
if (obj !== null && Object.hasOwn(obj, 'data'))
|
|
356
|
+
parsed.data = obj.data;
|
|
357
|
+
return parsed;
|
|
358
|
+
};
|
|
326
359
|
/**
|
|
327
360
|
* Declare a consumer JSON-RPC error code and the HTTP status it answers, so
|
|
328
361
|
* `jsonrpc_error_code_to_http_status` maps it instead of falling back to 500.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"jsonrpc_helpers.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/jsonrpc_helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;
|
|
1
|
+
{"version":3,"file":"jsonrpc_helpers.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/http/jsonrpc_helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAKH,OAAO,EACN,cAAc,EACd,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,aAAa,EAClB,KAAK,mBAAmB,EACxB,KAAK,yBAAyB,EAC9B,KAAK,gBAAgB,EACrB,KAAK,oBAAoB,EACzB,KAAK,eAAe,EACpB,KAAK,aAAa,EAElB,eAAe,EACf,MAAM,cAAc,CAAC;AAWtB,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,gBAAgB,EACpB,QAAQ,aAAa,KACnB,eAID,CAAC;AAEH,6EAA6E;AAC7E,eAAO,MAAM,2BAA2B,GACvC,QAAQ,aAAa,EACrB,QAAQ,yBAAyB,GAAG,SAAS,KAC3C,mBASF,CAAC;AAEF,iDAAiD;AACjD,eAAO,MAAM,6BAA6B,GACzC,IAAI,oBAAoB,CAAC,IAAI,CAAC,EAC9B,OAAO,oBAAoB,CAAC,OAAO,CAAC,KAClC,oBAID,CAAC;AAEH;;;;;;;GAOG;AACH,eAAO,MAAM,yCAAyC,GACrD,IAAI,gBAAgB,GAAG,IAAI,EAC3B,OAAO,OAAO,KACZ,oBA0BF,CAAC;AAIF,kFAAkF;AAClF,eAAO,MAAM,qBAAqB,GAAI,IAAI,OAAO,KAAG,EAAE,IAAI,gBAGzD,CAAC;AAEF,qEAAqE;AACrE,eAAO,MAAM,iBAAiB,GAC7B,SAAS,OAAO,KACd,OAAO,I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9
|
*/
|
|
10
10
|
import { DEV } from 'esm-env';
|
|
11
|
+
import { is, parse } from '@fuzdev/fuz_schema/schema.ts';
|
|
11
12
|
import { JsonrpcRequest, JSONRPC_VERSION } from './jsonrpc.js';
|
|
12
13
|
import { JSONRPC_ERROR_CODES, dev_only, jsonrpc_error_messages, to_thrown_jsonrpc_error } from './jsonrpc_errors.js';
|
|
13
14
|
import { to_wire_issues } from '../schema_issues.js';
|
|
@@ -173,16 +174,16 @@ export const classify_jsonrpc_message = (json) => {
|
|
|
173
174
|
else if (!('id' in frame)) {
|
|
174
175
|
return { kind: 'notification', method, params: frame.params };
|
|
175
176
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
177
|
+
// once per request: `is` allocates no result, and the issues are built
|
|
178
|
+
// only for a refused envelope, only in DEV
|
|
179
|
+
if (is(JsonrpcRequest, frame))
|
|
180
|
+
return { kind: 'request', request: frame };
|
|
181
|
+
return {
|
|
182
|
+
kind: 'invalid',
|
|
183
|
+
id,
|
|
184
|
+
error: jsonrpc_error_messages.invalid_request(dev_only(() => {
|
|
185
|
+
const parsed = parse(JsonrpcRequest, frame);
|
|
186
|
+
return { issues: parsed.ok ? [] : to_wire_issues(parsed.issues, frame) };
|
|
187
|
+
}))
|
|
188
|
+
};
|
|
188
189
|
};
|
package/dist/testing/CLAUDE.md
CHANGED
|
@@ -755,7 +755,7 @@ Three layers:
|
|
|
755
755
|
|
|
756
756
|
1. **Primitives** — `create_fake_ws(options?)` (a real `WSContext` over capture arrays `sends` / `closes`, plus `socket` — the fake runtime socket behind `ws.raw`, shaped like Node's `ws`: a `bufferedAmount` the registry's outbound writer reads for backpressure, `stalled` (start it with `{stalled: true}`) to model a client that stopped reading, and `terminate` / `terminated` for the frameless cut; `readyState` reads open until closed or terminated), `create_fake_hono_context(opts)`, `create_stub_upgrade()`, `MinimalActionEnvironment`, `dispatch_ws_message(on_message, event, ws)`. The fake context sets the `ResolvedAuth` the production auth middleware sets (`RESOLVED_AUTH_KEY`, built by `create_test_resolved_auth` — a session's hash as `hash_session_token(auth_session_id)`), because the dispatcher reads the credential through `get_resolved_auth(c)`; a hand-built upgrade context must do the same. `create_stub_upgrade()` stands in for a runtime adapter's `upgradeWebSocket`: it passes a request without `Upgrade: websocket` to `next()`, and records an upgrade request — its real `Context` and the endpoint's events factory — in `upgrades`, answering `200`. So a test can send `app.request('/api/ws', {headers: {upgrade: 'websocket', cookie | authorization, origin, 'x-forwarded-for'}})` through an assembled app's whole middleware chain and build the socket's events from the `Context` that chain produced (`src/test/server/create_app_server_ws_endpoints.dispatch.db.test.ts`); `get_create_events()` still returns the last mounted factory, for a hand-built context.
|
|
757
757
|
2. **Harness** — `create_ws_test_harness({actions, registry?, receive_timeout?, log?, on_socket_open?, on_socket_close?})` → `WsTestHarness`. `connect(identity?)` is async and resolves after the connection is admitted and `on_socket_open` completes, so broadcasts sent immediately after `await harness.connect()` reach the client. The harness pre-bakes its `RequestContext` (`TEST_CONTEXT_PRESET_KEY`), which also skips the admission credential re-read — there are no session or token rows behind a harness identity — so tests of the re-read itself drive `register_action_ws` with a real database and no preset (`src/test/actions/register_action_ws.admission.db.test.ts`). The harness threads its own `create_stub_db()` into the dispatcher's `db` slot so handlers declaring `side_effects: true` execute under the same transaction wrap they would in production (the stub's `transaction(fn)` synchronously calls `fn(stub_db)`); domain deps reach handlers via factory closures, the same way HTTP RPC factories already wire them. Audit fan-out runs through whatever `audit` emitter the consumer supplied to its action factory closure (typically `create_test_audit_emitter()` for unit harnesses).
|
|
758
|
-
3. **Round-trip helpers** — predicates + wire-frame types live in `transports/ws_client.ts` (shared with the cross-process `ws_transport.ts` impl): `is_notification(method)`, `is_notification_with<P>(method, match)` (type-guard combinator — narrows `wait_for` return type), `is_response_for(id)`, `JsonrpcNotificationFrame<P>` / `JsonrpcSuccessResponseFrame<R>` / `JsonrpcErrorResponseFrame<D>` (typed wire-frame shapes distinct from the runtime
|
|
758
|
+
3. **Round-trip helpers** — predicates + wire-frame types live in `transports/ws_client.ts` (shared with the cross-process `ws_transport.ts` impl): `is_notification(method)`, `is_notification_with<P>(method, match)` (type-guard combinator — narrows `wait_for` return type), `is_response_for(id)`, `JsonrpcNotificationFrame<P>` / `JsonrpcSuccessResponseFrame<R>` / `JsonrpcErrorResponseFrame<D>` (typed wire-frame shapes distinct from the runtime schemas in `http/jsonrpc.ts` — generic over `params` / `result` / `data` so tests narrow without casts).
|
|
759
759
|
|
|
760
760
|
`WsClient` (in `transports/ws_client.ts`):
|
|
761
761
|
`{send, request<R>, close, messages, wait_for, wait_for_close, close_code, close_reason}`.
|
|
@@ -1779,8 +1779,11 @@ socket's forged reply for the first's id, then a round-trip on the second
|
|
|
1779
1779
|
socket as a barrier, so the first's timeout is asserted to come after the
|
|
1780
1780
|
forged reply was read — never a deadline that ran out first), never-reply
|
|
1781
1781
|
`Timeout`, wrong-shape rejection, an undeclared reply key accepted and dropped
|
|
1782
|
-
(both spines read the reply forward-compatibly), client-error forwarding,
|
|
1783
|
-
|
|
1782
|
+
(both spines read the reply forward-compatibly), client-error forwarding, a
|
|
1783
|
+
malformed client error read alike on both spines (a code off the base set —
|
|
1784
|
+
a consumer's code, a fraction — is `internal_error`, a non-string message
|
|
1785
|
+
`'peer error'`, `error: null` neither, a present `data` kept), and the HTTP
|
|
1786
|
+
no-transport path. Gated on `capabilities.peer_request` — `true` on
|
|
1784
1787
|
both the Rust spine and the TS spine (the `ConnectionRegistry.request_connection`
|
|
1785
1788
|
path + `register_action_ws` response correlation); `peer/ping` is a protocol
|
|
1786
1789
|
action (manifest-excluded), so parity is behavioral here, not via the manifest
|
|
@@ -13,8 +13,9 @@ export interface PeerPingWsTestOptions extends WsEndpointTarget {
|
|
|
13
13
|
* Register the server-initiated `peer/ping` suite — a positive round-trip
|
|
14
14
|
* plus the security negatives the design doc's §Security surface mandates
|
|
15
15
|
* (unsolicited-response rejection, per-connection id isolation, never-reply
|
|
16
|
-
* `Timeout`, wrong-shape reply rejection, plus client-error forwarding
|
|
17
|
-
* the HTTP no-transport path).
|
|
16
|
+
* `Timeout`, wrong-shape reply rejection, plus client-error forwarding, the
|
|
17
|
+
* reading of a malformed client error, and the HTTP no-transport path).
|
|
18
|
+
* Gated on `capabilities.peer_request`.
|
|
18
19
|
*/
|
|
19
20
|
export declare const describe_peer_ping_ws_tests: (options: PeerPingWsTestOptions) => void;
|
|
20
21
|
//# sourceMappingURL=peer_ping_ws.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"peer_ping_ws.d.ts","sourceRoot":"../src/lib/","sources":["../../../src/lib/testing/cross_backend/peer_ping_ws.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAiD9B,OAAO,EAAE,KAAK,mBAAmB,EAAW,MAAM,mBAAmB,CAAC;AACtE,OAAO,KAAK,EAAE,SAAS,EAAe,MAAM,YAAY,CAAC;AAEzD,OAAO,EAAmB,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AA0B1E,uDAAuD;AACvD,MAAM,WAAW,qBAAsB,SAAQ,gBAAgB;IAC9D,8EAA8E;IAC9E,QAAQ,CAAC,UAAU,EAAE,SAAS,CAAC;IAC/B,iFAAiF;IACjF,QAAQ,CAAC,YAAY,EAAE,mBAAmB,CAAC;CAC3C;AAED
|
|
1
|
+
{"version":3,"file":"peer_ping_ws.d.ts","sourceRoot":"../src/lib/","sources":["../../../src/lib/testing/cross_backend/peer_ping_ws.ts"],"names":[],"mappings":"AAAA,OAAO,sBAAsB,CAAC;AAiD9B,OAAO,EAAE,KAAK,mBAAmB,EAAW,MAAM,mBAAmB,CAAC;AACtE,OAAO,KAAK,EAAE,SAAS,EAAe,MAAM,YAAY,CAAC;AAEzD,OAAO,EAAmB,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AA0B1E,uDAAuD;AACvD,MAAM,WAAW,qBAAsB,SAAQ,gBAAgB;IAC9D,8EAA8E;IAC9E,QAAQ,CAAC,UAAU,EAAE,SAAS,CAAC;IAC/B,iFAAiF;IACjF,QAAQ,CAAC,YAAY,EAAE,mBAAmB,CAAC;CAC3C;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,2BAA2B,GAAI,SAAS,qBAAqB,KAAG,IAkT5E,CAAC"}
|
|
@@ -64,8 +64,9 @@ const valid_reply = (nonce) => ({ nonce, protocol_version: 1 });
|
|
|
64
64
|
* Register the server-initiated `peer/ping` suite — a positive round-trip
|
|
65
65
|
* plus the security negatives the design doc's §Security surface mandates
|
|
66
66
|
* (unsolicited-response rejection, per-connection id isolation, never-reply
|
|
67
|
-
* `Timeout`, wrong-shape reply rejection, plus client-error forwarding
|
|
68
|
-
* the HTTP no-transport path).
|
|
67
|
+
* `Timeout`, wrong-shape reply rejection, plus client-error forwarding, the
|
|
68
|
+
* reading of a malformed client error, and the HTTP no-transport path).
|
|
69
|
+
* Gated on `capabilities.peer_request`.
|
|
69
70
|
*/
|
|
70
71
|
export const describe_peer_ping_ws_tests = (options) => {
|
|
71
72
|
const { setup_test, capabilities } = options;
|
|
@@ -164,6 +165,52 @@ export const describe_peer_ping_ws_tests = (options) => {
|
|
|
164
165
|
await ws.close();
|
|
165
166
|
}
|
|
166
167
|
});
|
|
168
|
+
// The client is untrusted: both spines read its error reply to a base-set
|
|
169
|
+
// code (anything else, a consumer's code included, is internal_error) and
|
|
170
|
+
// a string message (else 'peer error'), keeping a present `data` as sent.
|
|
171
|
+
test_if(capabilities.peer_request, 'a client error reply off the base set is read to internal_error, never forwarded raw', async () => {
|
|
172
|
+
const fixture = await setup_test();
|
|
173
|
+
const cases = [
|
|
174
|
+
{
|
|
175
|
+
error: { code: -32050, message: 'consumer code', data: { reason: 'client_says_no' } },
|
|
176
|
+
code: -32603,
|
|
177
|
+
message: 'consumer code',
|
|
178
|
+
data: { reason: 'client_says_no' }
|
|
179
|
+
},
|
|
180
|
+
{
|
|
181
|
+
error: { code: -32005.5, message: 42, data: null },
|
|
182
|
+
code: -32603,
|
|
183
|
+
message: 'peer error',
|
|
184
|
+
data: null
|
|
185
|
+
},
|
|
186
|
+
{ error: null, code: -32603, message: 'peer error' },
|
|
187
|
+
{
|
|
188
|
+
error: { code: -32002, message: 'base code', data: 'kept' },
|
|
189
|
+
code: -32002,
|
|
190
|
+
message: 'base code',
|
|
191
|
+
data: 'kept'
|
|
192
|
+
}
|
|
193
|
+
];
|
|
194
|
+
for (const [i, c] of cases.entries()) {
|
|
195
|
+
const ws = await open_ws(fixture, () => ({ error: c.error }));
|
|
196
|
+
try {
|
|
197
|
+
const frame = await ping_raw(ws, 10 + i, { nonce: 1, timeout_ms: 2000 });
|
|
198
|
+
const label = JSON.stringify(c.error);
|
|
199
|
+
assert.ok('error' in frame, `${label}: a client error reply must surface as an error`);
|
|
200
|
+
assert.strictEqual(frame.error.code, c.code, label);
|
|
201
|
+
assert.strictEqual(frame.error.message, c.message, label);
|
|
202
|
+
if ('data' in c) {
|
|
203
|
+
assert.deepStrictEqual(frame.error.data, c.data, label);
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
assert.notOk('data' in frame.error, label);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
finally {
|
|
210
|
+
await ws.close();
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
});
|
|
167
214
|
test_if(capabilities.peer_request, 'an unsolicited response is dropped: it resolves nothing and the socket survives', async () => {
|
|
168
215
|
const fixture = await setup_test();
|
|
169
216
|
const ws = await open_ws(fixture, echo_responder);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import './assert_dev_env.js';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
-
import type
|
|
3
|
+
import { type Schema } from '@fuzdev/fuz_schema/schema.ts';
|
|
4
4
|
import { type JsonrpcErrorCode } from '../http/jsonrpc.js';
|
|
5
5
|
import type { RequestResponseActionSpec } from '../actions/action_spec.js';
|
|
6
6
|
import type { RpcAction } from '../actions/action_types.js';
|
|
@@ -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;AAa7B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"rpc_helpers.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/rpc_helpers.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAa7B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAa,KAAK,MAAM,EAAE,MAAM,8BAA8B,CAAC;AAEtE,OAAO,EAIN,KAAK,gBAAgB,EACrB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAC;AAC3E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,KAAK,EACX,qBAAqB,EACrB,mBAAmB,EACnB,eAAe,EACf,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAGhE,OAAO,EAAa,KAAK,gBAAgB,EAAE,KAAK,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAE9F;;;;;;;;;GASG;AACH,MAAM,MAAM,uBAAuB,GAClC,KAAK,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,gBAAgB,KAAK,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC;AAE9E;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,+BAA+B,GAC3C,eAAe,uBAAuB,EACtC,iBAAiB,cAAc,C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AC,OAAO,CAAC,CAAC,CAAC;CACzC,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,iBAAiB,GAAU,KAAK,SAAS,yBAAyB,EAC9E,MAAM,kBAAkB,CAAC,KAAK,CAAC,KAC7B,OAAO,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAoBrC,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,GAAU,CAAC,EACrC,MAAM,WAAW,EACjB,eAAe,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,GAAG,CAAC,KAC1C,OAAO,CAAC,CAAC,CAkBX,CAAC;AAIF;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAC3B,eAAe,aAAa,CAAC,eAAe,CAAC,EAC7C,QAAQ,MAAM,KACZ;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,SAAS,CAAA;CAAE,GAAG,SAOxC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,eAAe,GAC3B,eAAe,aAAa,CAAC,qBAAqB,CAAC,EACnD,QAAQ,MAAM,KACZ;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,mBAAmB,CAAA;CAAE,GAAG,SAOvD,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,yBAAyB,GACrC,eAAe,aAAa,CAAC,eAAe,CAAC,KAC3C,MAcF,CAAC"}
|
|
@@ -10,6 +10,7 @@ import './assert_dev_env.js';
|
|
|
10
10
|
*/
|
|
11
11
|
import { assert } from 'vitest';
|
|
12
12
|
import { z } from 'zod';
|
|
13
|
+
import { is, parse } from '@fuzdev/fuz_schema/schema.ts';
|
|
13
14
|
import { JSONRPC_VERSION, JsonrpcErrorResponse, JsonrpcResponse } from '../http/jsonrpc.js';
|
|
14
15
|
import { create_stub_app_server_context } from './stubs.js';
|
|
15
16
|
import { TEST_ORIGIN } from './test_origin.js';
|
|
@@ -118,10 +119,10 @@ export const create_rpc_get_url = (endpoint_path, method, params, id = 'test') =
|
|
|
118
119
|
* @param expected_code - optional error code to assert
|
|
119
120
|
*/
|
|
120
121
|
export const assert_jsonrpc_error_response = (body, expected_code) => {
|
|
121
|
-
const result = JsonrpcErrorResponse
|
|
122
|
-
assert.ok(result.
|
|
122
|
+
const result = parse(JsonrpcErrorResponse, body);
|
|
123
|
+
assert.ok(result.ok, `not a valid JSON-RPC error response: ${JSON.stringify(body)}`);
|
|
123
124
|
if (expected_code !== undefined) {
|
|
124
|
-
assert.strictEqual(result.
|
|
125
|
+
assert.strictEqual(result.value.error.code, expected_code, `expected error code ${expected_code}, got ${result.value.error.code}`);
|
|
125
126
|
}
|
|
126
127
|
};
|
|
127
128
|
/**
|
|
@@ -134,10 +135,10 @@ export const assert_jsonrpc_error_response = (body, expected_code) => {
|
|
|
134
135
|
* @param output_schema - optional Zod or `@fuzdev/fuz_schema` schema to validate the `result` field against
|
|
135
136
|
*/
|
|
136
137
|
export const assert_jsonrpc_success_response = (body, output_schema) => {
|
|
137
|
-
const result = JsonrpcResponse
|
|
138
|
-
assert.ok(result.
|
|
138
|
+
const result = parse(JsonrpcResponse, body);
|
|
139
|
+
assert.ok(result.ok, `not a valid JSON-RPC success response: ${JSON.stringify(body)}`);
|
|
139
140
|
if (output_schema) {
|
|
140
|
-
const output_result = parse_any(output_schema, result.
|
|
141
|
+
const output_result = parse_any(output_schema, result.value.result);
|
|
141
142
|
if (!output_result.ok) {
|
|
142
143
|
assert.fail(`JSON-RPC result does not match output schema: ${JSON.stringify(output_result.issues)}`);
|
|
143
144
|
}
|
|
@@ -237,20 +238,18 @@ export const rpc_call_raw = async (args) => {
|
|
|
237
238
|
*/
|
|
238
239
|
export const parse_rpc_call_result = (raw, method) => {
|
|
239
240
|
const { status, headers, body } = raw;
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
return { ok: true, status, headers, result: success.data.result };
|
|
241
|
+
if (is(JsonrpcResponse, body)) {
|
|
242
|
+
return { ok: true, status, headers, result: body.result };
|
|
243
243
|
}
|
|
244
|
-
|
|
245
|
-
if (error.success) {
|
|
244
|
+
if (is(JsonrpcErrorResponse, body)) {
|
|
246
245
|
return {
|
|
247
246
|
ok: false,
|
|
248
247
|
status,
|
|
249
248
|
headers,
|
|
250
249
|
error: {
|
|
251
|
-
code:
|
|
252
|
-
message:
|
|
253
|
-
data:
|
|
250
|
+
code: body.error.code,
|
|
251
|
+
message: body.error.message,
|
|
252
|
+
data: body.error.data
|
|
254
253
|
}
|
|
255
254
|
};
|
|
256
255
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rpc_round_trip.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/rpc_round_trip.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"rpc_round_trip.d.ts","sourceRoot":"../src/lib/","sources":["../../src/lib/testing/rpc_round_trip.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,CAAC;AAuC7B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD,OAAO,KAAK,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9E,OAAO,EAQN,KAAK,uBAAuB,EAC5B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAKN,KAAK,aAAa,EAClB,KAAK,oBAAoB,EACzB,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAEhE,mDAAmD;AACnD,MAAM,WAAW,uBAAuB;IACvC,kEAAkE;IAClE,UAAU,EAAE,SAAS,CAAC;IACtB;;;;OAIG;IACH,cAAc,EAAE,cAAc,CAAC;IAC/B;;;;;OAKG;IACH,eAAe,EAAE,cAAc,CAAC,MAAM,CAAC,CA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