@dxos/rpc 0.8.4-main.f5c0578 → 0.8.4-main.fcc0d83b33
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/README.md +5 -5
- package/dist/lib/{browser → neutral}/index.mjs +112 -285
- package/dist/lib/neutral/index.mjs.map +7 -0
- package/dist/lib/neutral/meta.json +1 -0
- package/dist/types/src/errors.d.ts.map +1 -1
- package/dist/types/src/rpc.d.ts +1 -3
- package/dist/types/src/rpc.d.ts.map +1 -1
- package/dist/types/src/service.d.ts +2 -2
- package/dist/types/src/service.d.ts.map +1 -1
- package/dist/types/src/testing.d.ts.map +1 -1
- package/dist/types/src/trace.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +16 -15
- package/src/rpc.test.ts +1 -2
- package/src/rpc.ts +58 -20
- package/src/service.test.ts +126 -3
- package/dist/lib/browser/index.mjs.map +0 -7
- package/dist/lib/browser/meta.json +0 -1
- package/dist/lib/node-esm/index.mjs +0 -924
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
package/README.md
CHANGED
|
@@ -4,8 +4,8 @@ A lightweight, transport-agnostic RPC implementation.
|
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
- Performs a handshake to wait for the other side to be open.
|
|
8
|
+
- Errors are serialized and transported with their stack intact.
|
|
9
|
+
- Requests are terminated on close.
|
|
10
|
+
- TODO: Request timeouts.
|
|
11
|
+
- TODO: Data streams.
|
|
@@ -12,20 +12,21 @@ var decodeRpcError = (err, rpcMethod) => decodeError(err, {
|
|
|
12
12
|
// src/rpc.ts
|
|
13
13
|
import { Trigger, asyncTimeout, synchronized } from "@dxos/async";
|
|
14
14
|
import { Stream } from "@dxos/codec-protobuf";
|
|
15
|
+
import { ContextRpcCodec } from "@dxos/context";
|
|
15
16
|
import { StackTrace as StackTrace2 } from "@dxos/debug";
|
|
16
17
|
import { invariant } from "@dxos/invariant";
|
|
17
18
|
import { log } from "@dxos/log";
|
|
18
19
|
import { RpcClosedError, RpcNotOpenError, encodeError } from "@dxos/protocols";
|
|
19
20
|
import { schema } from "@dxos/protocols/proto";
|
|
20
21
|
import { exponentialBackoffInterval } from "@dxos/util";
|
|
22
|
+
var __dxlog_file = "/__w/dxos/dxos/packages/core/mesh/rpc/src/rpc.ts";
|
|
21
23
|
function _ts_decorate(decorators, target, key, desc) {
|
|
22
24
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
23
25
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
24
26
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
25
27
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
26
28
|
}
|
|
27
|
-
var
|
|
28
|
-
var DEFAULT_TIMEOUT = 3e3;
|
|
29
|
+
var DEFAULT_TIMEOUT = 3e4;
|
|
29
30
|
var BYE_SEND_TIMEOUT = 2e3;
|
|
30
31
|
var DEBUG_CALLS = true;
|
|
31
32
|
var CLOSE_TIMEOUT = 3e3;
|
|
@@ -79,12 +80,7 @@ var RpcPeer = class {
|
|
|
79
80
|
try {
|
|
80
81
|
await this._receive(msg);
|
|
81
82
|
} catch (err) {
|
|
82
|
-
log.catch(err, void 0, {
|
|
83
|
-
F: __dxlog_file,
|
|
84
|
-
L: 156,
|
|
85
|
-
S: this,
|
|
86
|
-
C: (f, a) => f(...a)
|
|
87
|
-
});
|
|
83
|
+
log.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 100, S: this });
|
|
88
84
|
}
|
|
89
85
|
});
|
|
90
86
|
this._state = "OPENING";
|
|
@@ -95,12 +91,7 @@ var RpcPeer = class {
|
|
|
95
91
|
}
|
|
96
92
|
log("sending open message", {
|
|
97
93
|
state: this._state
|
|
98
|
-
}, {
|
|
99
|
-
F: __dxlog_file,
|
|
100
|
-
L: 168,
|
|
101
|
-
S: this,
|
|
102
|
-
C: (f, a) => f(...a)
|
|
103
|
-
});
|
|
94
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 109, S: this });
|
|
104
95
|
await this._sendMessage({
|
|
105
96
|
open: true
|
|
106
97
|
});
|
|
@@ -110,12 +101,7 @@ var RpcPeer = class {
|
|
|
110
101
|
this._clearOpenInterval = exponentialBackoffInterval(() => {
|
|
111
102
|
void this._sendMessage({
|
|
112
103
|
open: true
|
|
113
|
-
}).catch((err) => log.warn(err, void 0, {
|
|
114
|
-
F: __dxlog_file,
|
|
115
|
-
L: 177,
|
|
116
|
-
S: this,
|
|
117
|
-
C: (f, a) => f(...a)
|
|
118
|
-
}));
|
|
104
|
+
}).catch((err) => log.warn(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 122, S: this }));
|
|
119
105
|
}, 50);
|
|
120
106
|
await Promise.race([
|
|
121
107
|
this._remoteOpenTrigger.wait(),
|
|
@@ -127,12 +113,7 @@ var RpcPeer = class {
|
|
|
127
113
|
}
|
|
128
114
|
log("resending open message", {
|
|
129
115
|
state: this._state
|
|
130
|
-
}, {
|
|
131
|
-
F: __dxlog_file,
|
|
132
|
-
L: 191,
|
|
133
|
-
S: this,
|
|
134
|
-
C: (f, a) => f(...a)
|
|
135
|
-
});
|
|
116
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 135, S: this });
|
|
136
117
|
await this._sendMessage({
|
|
137
118
|
openAck: true
|
|
138
119
|
});
|
|
@@ -157,32 +138,17 @@ var RpcPeer = class {
|
|
|
157
138
|
} catch (err) {
|
|
158
139
|
log("error closing peer, sending bye", {
|
|
159
140
|
err
|
|
160
|
-
}, {
|
|
161
|
-
F: __dxlog_file,
|
|
162
|
-
L: 213,
|
|
163
|
-
S: this,
|
|
164
|
-
C: (f, a) => f(...a)
|
|
165
|
-
});
|
|
141
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 159, S: this });
|
|
166
142
|
}
|
|
167
143
|
try {
|
|
168
|
-
log("closing waiting on bye", void 0, {
|
|
169
|
-
F: __dxlog_file,
|
|
170
|
-
L: 216,
|
|
171
|
-
S: this,
|
|
172
|
-
C: (f, a) => f(...a)
|
|
173
|
-
});
|
|
144
|
+
log("closing waiting on bye", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 164, S: this });
|
|
174
145
|
await this._byeTrigger.wait({
|
|
175
146
|
timeout
|
|
176
147
|
});
|
|
177
148
|
} catch (err) {
|
|
178
149
|
log("error closing peer", {
|
|
179
150
|
err
|
|
180
|
-
}, {
|
|
181
|
-
F: __dxlog_file,
|
|
182
|
-
L: 219,
|
|
183
|
-
S: this,
|
|
184
|
-
C: (f, a) => f(...a)
|
|
185
|
-
});
|
|
151
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 169, S: this });
|
|
186
152
|
return;
|
|
187
153
|
}
|
|
188
154
|
}
|
|
@@ -219,22 +185,12 @@ var RpcPeer = class {
|
|
|
219
185
|
const decoded = getRpcMessageCodec().decode(msg, {
|
|
220
186
|
preserveAny: true
|
|
221
187
|
});
|
|
222
|
-
DEBUG_CALLS && log("received message", {
|
|
188
|
+
DEBUG_CALLS && log.trace("received message", {
|
|
223
189
|
type: Object.keys(decoded)[0]
|
|
224
|
-
}, {
|
|
225
|
-
F: __dxlog_file,
|
|
226
|
-
L: 263,
|
|
227
|
-
S: this,
|
|
228
|
-
C: (f, a) => f(...a)
|
|
229
|
-
});
|
|
190
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 208, S: this });
|
|
230
191
|
if (decoded.request) {
|
|
231
192
|
if (this._state !== "OPENED" && this._state !== "OPENING") {
|
|
232
|
-
log("received request while closed", void 0, {
|
|
233
|
-
F: __dxlog_file,
|
|
234
|
-
L: 267,
|
|
235
|
-
S: this,
|
|
236
|
-
C: (f, a) => f(...a)
|
|
237
|
-
});
|
|
193
|
+
log("received request while closed", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 213, S: this });
|
|
238
194
|
await this._sendMessage({
|
|
239
195
|
response: {
|
|
240
196
|
id: decoded.request.id,
|
|
@@ -247,112 +203,59 @@ var RpcPeer = class {
|
|
|
247
203
|
if (req.stream) {
|
|
248
204
|
log("stream request", {
|
|
249
205
|
method: req.method
|
|
250
|
-
}, {
|
|
251
|
-
F: __dxlog_file,
|
|
252
|
-
L: 279,
|
|
253
|
-
S: this,
|
|
254
|
-
C: (f, a) => f(...a)
|
|
255
|
-
});
|
|
206
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 224, S: this });
|
|
256
207
|
this._callStreamHandler(req, (response) => {
|
|
257
208
|
log("sending stream response", {
|
|
258
209
|
method: req.method,
|
|
259
210
|
response: response.payload?.type_url,
|
|
260
211
|
error: response.error,
|
|
261
212
|
close: response.close
|
|
262
|
-
}, {
|
|
263
|
-
F: __dxlog_file,
|
|
264
|
-
L: 281,
|
|
265
|
-
S: this,
|
|
266
|
-
C: (f, a) => f(...a)
|
|
267
|
-
});
|
|
213
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 228, S: this });
|
|
268
214
|
void this._sendMessage({
|
|
269
215
|
response
|
|
270
216
|
}).catch((err) => {
|
|
271
|
-
log.warn("failed during close", err, {
|
|
272
|
-
F: __dxlog_file,
|
|
273
|
-
L: 289,
|
|
274
|
-
S: this,
|
|
275
|
-
C: (f, a) => f(...a)
|
|
276
|
-
});
|
|
217
|
+
log.warn("failed during close", err, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 237, S: this });
|
|
277
218
|
});
|
|
278
219
|
});
|
|
279
220
|
} else {
|
|
280
|
-
DEBUG_CALLS && log("requesting...", {
|
|
221
|
+
DEBUG_CALLS && log.trace("requesting...", {
|
|
281
222
|
method: req.method
|
|
282
|
-
}, {
|
|
283
|
-
F: __dxlog_file,
|
|
284
|
-
L: 293,
|
|
285
|
-
S: this,
|
|
286
|
-
C: (f, a) => f(...a)
|
|
287
|
-
});
|
|
223
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 241, S: this });
|
|
288
224
|
const response = await this._callHandler(req);
|
|
289
|
-
DEBUG_CALLS && log("sending response", {
|
|
225
|
+
DEBUG_CALLS && log.trace("sending response", {
|
|
290
226
|
method: req.method,
|
|
291
227
|
response: response.payload?.type_url,
|
|
292
228
|
error: response.error
|
|
293
|
-
}, {
|
|
294
|
-
F: __dxlog_file,
|
|
295
|
-
L: 296,
|
|
296
|
-
S: this,
|
|
297
|
-
C: (f, a) => f(...a)
|
|
298
|
-
});
|
|
229
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 245, S: this });
|
|
299
230
|
await this._sendMessage({
|
|
300
231
|
response
|
|
301
232
|
});
|
|
302
233
|
}
|
|
303
234
|
} else if (decoded.response) {
|
|
304
235
|
if (this._state !== "OPENED") {
|
|
305
|
-
log("received response while closed", void 0, {
|
|
306
|
-
F: __dxlog_file,
|
|
307
|
-
L: 305,
|
|
308
|
-
S: this,
|
|
309
|
-
C: (f, a) => f(...a)
|
|
310
|
-
});
|
|
236
|
+
log("received response while closed", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 256, S: this });
|
|
311
237
|
return;
|
|
312
238
|
}
|
|
313
239
|
const responseId = decoded.response.id;
|
|
314
|
-
invariant(typeof responseId === "number", void 0, {
|
|
315
|
-
F: __dxlog_file,
|
|
316
|
-
L: 310,
|
|
317
|
-
S: this,
|
|
318
|
-
A: [
|
|
319
|
-
"typeof responseId === 'number'",
|
|
320
|
-
""
|
|
321
|
-
]
|
|
322
|
-
});
|
|
240
|
+
invariant(typeof responseId === "number", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 260, S: this, A: ["typeof responseId === 'number'", ""] });
|
|
323
241
|
if (!this._outgoingRequests.has(responseId)) {
|
|
324
|
-
log("received response with invalid id", {
|
|
242
|
+
log.trace("received response with invalid id", {
|
|
325
243
|
responseId
|
|
326
|
-
}, {
|
|
327
|
-
F: __dxlog_file,
|
|
328
|
-
L: 312,
|
|
329
|
-
S: this,
|
|
330
|
-
C: (f, a) => f(...a)
|
|
331
|
-
});
|
|
244
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 262, S: this });
|
|
332
245
|
return;
|
|
333
246
|
}
|
|
334
247
|
const item = this._outgoingRequests.get(responseId);
|
|
335
248
|
if (!item.stream) {
|
|
336
249
|
this._outgoingRequests.delete(responseId);
|
|
337
250
|
}
|
|
338
|
-
DEBUG_CALLS && log("response", {
|
|
251
|
+
DEBUG_CALLS && log.trace("response", {
|
|
339
252
|
type_url: decoded.response.payload?.type_url
|
|
340
|
-
}, {
|
|
341
|
-
F: __dxlog_file,
|
|
342
|
-
L: 322,
|
|
343
|
-
S: this,
|
|
344
|
-
C: (f, a) => f(...a)
|
|
345
|
-
});
|
|
253
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 272, S: this });
|
|
346
254
|
item.resolve(decoded.response);
|
|
347
255
|
} else if (decoded.open) {
|
|
348
256
|
log("received open message", {
|
|
349
257
|
state: this._state
|
|
350
|
-
}, {
|
|
351
|
-
F: __dxlog_file,
|
|
352
|
-
L: 325,
|
|
353
|
-
S: this,
|
|
354
|
-
C: (f, a) => f(...a)
|
|
355
|
-
});
|
|
258
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 277, S: this });
|
|
356
259
|
if (this._params.noHandshake) {
|
|
357
260
|
return;
|
|
358
261
|
}
|
|
@@ -362,12 +265,7 @@ var RpcPeer = class {
|
|
|
362
265
|
} else if (decoded.openAck) {
|
|
363
266
|
log("received openAck message", {
|
|
364
267
|
state: this._state
|
|
365
|
-
}, {
|
|
366
|
-
F: __dxlog_file,
|
|
367
|
-
L: 332,
|
|
368
|
-
S: this,
|
|
369
|
-
C: (f, a) => f(...a)
|
|
370
|
-
});
|
|
268
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 287, S: this });
|
|
371
269
|
if (this._params.noHandshake) {
|
|
372
270
|
return;
|
|
373
271
|
}
|
|
@@ -375,41 +273,18 @@ var RpcPeer = class {
|
|
|
375
273
|
this._remoteOpenTrigger.wake();
|
|
376
274
|
} else if (decoded.streamClose) {
|
|
377
275
|
if (this._state !== "OPENED") {
|
|
378
|
-
log("received stream close while closed", void 0, {
|
|
379
|
-
F: __dxlog_file,
|
|
380
|
-
L: 341,
|
|
381
|
-
S: this,
|
|
382
|
-
C: (f, a) => f(...a)
|
|
383
|
-
});
|
|
276
|
+
log("received stream close while closed", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 297, S: this });
|
|
384
277
|
return;
|
|
385
278
|
}
|
|
386
279
|
log("received stream close", {
|
|
387
280
|
id: decoded.streamClose.id
|
|
388
|
-
}, {
|
|
389
|
-
|
|
390
|
-
L: 345,
|
|
391
|
-
S: this,
|
|
392
|
-
C: (f, a) => f(...a)
|
|
393
|
-
});
|
|
394
|
-
invariant(typeof decoded.streamClose.id === "number", void 0, {
|
|
395
|
-
F: __dxlog_file,
|
|
396
|
-
L: 346,
|
|
397
|
-
S: this,
|
|
398
|
-
A: [
|
|
399
|
-
"typeof decoded.streamClose.id === 'number'",
|
|
400
|
-
""
|
|
401
|
-
]
|
|
402
|
-
});
|
|
281
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 300, S: this });
|
|
282
|
+
invariant(typeof decoded.streamClose.id === "number", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 303, S: this, A: ["typeof decoded.streamClose.id === 'number'", ""] });
|
|
403
283
|
const stream = this._localStreams.get(decoded.streamClose.id);
|
|
404
284
|
if (!stream) {
|
|
405
285
|
log("no local stream", {
|
|
406
286
|
id: decoded.streamClose.id
|
|
407
|
-
}, {
|
|
408
|
-
F: __dxlog_file,
|
|
409
|
-
L: 349,
|
|
410
|
-
S: this,
|
|
411
|
-
C: (f, a) => f(...a)
|
|
412
|
-
});
|
|
287
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 306, S: this });
|
|
413
288
|
return;
|
|
414
289
|
}
|
|
415
290
|
this._localStreams.delete(decoded.streamClose.id);
|
|
@@ -417,12 +292,7 @@ var RpcPeer = class {
|
|
|
417
292
|
} else if (decoded.bye) {
|
|
418
293
|
this._byeTrigger.wake();
|
|
419
294
|
if (this._state !== "CLOSING" && this._state !== "CLOSED") {
|
|
420
|
-
log("replying to bye", void 0, {
|
|
421
|
-
F: __dxlog_file,
|
|
422
|
-
L: 359,
|
|
423
|
-
S: this,
|
|
424
|
-
C: (f, a) => f(...a)
|
|
425
|
-
});
|
|
295
|
+
log("replying to bye", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 317, S: this });
|
|
426
296
|
this._state = "CLOSING";
|
|
427
297
|
await this._sendMessage({
|
|
428
298
|
bye: {}
|
|
@@ -433,12 +303,7 @@ var RpcPeer = class {
|
|
|
433
303
|
} else {
|
|
434
304
|
log.error("received malformed message", {
|
|
435
305
|
msg
|
|
436
|
-
}, {
|
|
437
|
-
F: __dxlog_file,
|
|
438
|
-
L: 367,
|
|
439
|
-
S: this,
|
|
440
|
-
C: (f, a) => f(...a)
|
|
441
|
-
});
|
|
306
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 326, S: this });
|
|
442
307
|
throw new Error("Malformed message.");
|
|
443
308
|
}
|
|
444
309
|
}
|
|
@@ -447,14 +312,9 @@ var RpcPeer = class {
|
|
|
447
312
|
* Peer should be open before making this call.
|
|
448
313
|
*/
|
|
449
314
|
async call(method, request, options) {
|
|
450
|
-
DEBUG_CALLS && log("calling...", {
|
|
315
|
+
DEBUG_CALLS && log.trace("calling...", {
|
|
451
316
|
method
|
|
452
|
-
}, {
|
|
453
|
-
F: __dxlog_file,
|
|
454
|
-
L: 377,
|
|
455
|
-
S: this,
|
|
456
|
-
C: (f, a) => f(...a)
|
|
457
|
-
});
|
|
317
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 336, S: this });
|
|
458
318
|
throwIfNotOpen(this._state);
|
|
459
319
|
let response;
|
|
460
320
|
try {
|
|
@@ -462,12 +322,23 @@ var RpcPeer = class {
|
|
|
462
322
|
const responseReceived = new Promise((resolve, reject) => {
|
|
463
323
|
this._outgoingRequests.set(id, new PendingRpcRequest(resolve, reject, false));
|
|
464
324
|
});
|
|
325
|
+
let traceContext;
|
|
326
|
+
try {
|
|
327
|
+
traceContext = options?.ctx ? ContextRpcCodec.encode(options.ctx) : void 0;
|
|
328
|
+
} catch (err) {
|
|
329
|
+
log.warn("failed to encode trace context", {
|
|
330
|
+
err
|
|
331
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 351, S: this });
|
|
332
|
+
}
|
|
465
333
|
const sending = this._sendMessage({
|
|
466
334
|
request: {
|
|
467
335
|
id,
|
|
468
336
|
method,
|
|
469
337
|
payload: request,
|
|
470
|
-
stream: false
|
|
338
|
+
stream: false,
|
|
339
|
+
...traceContext ? {
|
|
340
|
+
traceContext
|
|
341
|
+
} : {}
|
|
471
342
|
}
|
|
472
343
|
});
|
|
473
344
|
const timeout = options?.timeout ?? this._params.timeout;
|
|
@@ -477,15 +348,7 @@ var RpcPeer = class {
|
|
|
477
348
|
waiting
|
|
478
349
|
]);
|
|
479
350
|
response = await waiting;
|
|
480
|
-
invariant(response.id === id, void 0, {
|
|
481
|
-
F: __dxlog_file,
|
|
482
|
-
L: 405,
|
|
483
|
-
S: this,
|
|
484
|
-
A: [
|
|
485
|
-
"response.id === id",
|
|
486
|
-
""
|
|
487
|
-
]
|
|
488
|
-
});
|
|
351
|
+
invariant(response.id === id, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 375, S: this, A: ["response.id === id", ""] });
|
|
489
352
|
} catch (err) {
|
|
490
353
|
if (err instanceof RpcClosedError) {
|
|
491
354
|
const error = new RpcClosedError();
|
|
@@ -540,76 +403,81 @@ ${stack.getStack()}`;
|
|
|
540
403
|
}
|
|
541
404
|
};
|
|
542
405
|
this._outgoingRequests.set(id, new PendingRpcRequest(onResponse, closeStream, true));
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
|
|
406
|
+
let traceContext;
|
|
407
|
+
try {
|
|
408
|
+
traceContext = options?.ctx ? ContextRpcCodec.encode(options.ctx) : void 0;
|
|
409
|
+
} catch (err) {
|
|
410
|
+
log.warn("failed to encode trace context", {
|
|
411
|
+
err
|
|
412
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 429, S: this });
|
|
413
|
+
}
|
|
414
|
+
try {
|
|
415
|
+
this._sendMessage({
|
|
416
|
+
request: {
|
|
417
|
+
id,
|
|
418
|
+
method,
|
|
419
|
+
payload: request,
|
|
420
|
+
stream: true,
|
|
421
|
+
...traceContext ? {
|
|
422
|
+
traceContext
|
|
423
|
+
} : {}
|
|
424
|
+
}
|
|
425
|
+
}).catch((err) => {
|
|
426
|
+
this._outgoingRequests.delete(id);
|
|
427
|
+
close(err);
|
|
428
|
+
});
|
|
429
|
+
} catch (err) {
|
|
430
|
+
this._outgoingRequests.delete(id);
|
|
431
|
+
throw err;
|
|
432
|
+
}
|
|
553
433
|
return () => {
|
|
554
434
|
this._sendMessage({
|
|
555
435
|
streamClose: {
|
|
556
436
|
id
|
|
557
437
|
}
|
|
558
438
|
}).catch((err) => {
|
|
559
|
-
log.catch(err, void 0, {
|
|
560
|
-
F: __dxlog_file,
|
|
561
|
-
L: 478,
|
|
562
|
-
S: this,
|
|
563
|
-
C: (f, a) => f(...a)
|
|
564
|
-
});
|
|
439
|
+
log.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 458, S: this });
|
|
565
440
|
});
|
|
566
441
|
this._outgoingRequests.delete(id);
|
|
567
442
|
};
|
|
568
443
|
});
|
|
569
444
|
}
|
|
570
445
|
async _sendMessage(message, timeout) {
|
|
571
|
-
DEBUG_CALLS && log("sending message", {
|
|
446
|
+
DEBUG_CALLS && log.trace("sending message", {
|
|
572
447
|
type: Object.keys(message)[0]
|
|
573
|
-
}, {
|
|
574
|
-
F: __dxlog_file,
|
|
575
|
-
L: 486,
|
|
576
|
-
S: this,
|
|
577
|
-
C: (f, a) => f(...a)
|
|
578
|
-
});
|
|
448
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 465, S: this });
|
|
579
449
|
await this._params.port.send(getRpcMessageCodec().encode(message, {
|
|
580
450
|
preserveAny: true
|
|
581
451
|
}), timeout);
|
|
582
452
|
}
|
|
453
|
+
_getHandlerRpcOptions(req) {
|
|
454
|
+
let traceCtx;
|
|
455
|
+
if (req.traceContext) {
|
|
456
|
+
try {
|
|
457
|
+
traceCtx = ContextRpcCodec.decode(req.traceContext);
|
|
458
|
+
} catch (err) {
|
|
459
|
+
log.warn("failed to decode trace context", {
|
|
460
|
+
traceContext: req.traceContext,
|
|
461
|
+
err
|
|
462
|
+
}, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 478, S: this });
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
if (!traceCtx && !this._params.handlerRpcOptions) {
|
|
466
|
+
return void 0;
|
|
467
|
+
}
|
|
468
|
+
return {
|
|
469
|
+
...this._params.handlerRpcOptions,
|
|
470
|
+
...traceCtx ? {
|
|
471
|
+
ctx: traceCtx
|
|
472
|
+
} : {}
|
|
473
|
+
};
|
|
474
|
+
}
|
|
583
475
|
async _callHandler(req) {
|
|
584
476
|
try {
|
|
585
|
-
invariant(typeof req.id === "number", void 0, {
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
A: [
|
|
590
|
-
"typeof req.id === 'number'",
|
|
591
|
-
""
|
|
592
|
-
]
|
|
593
|
-
});
|
|
594
|
-
invariant(req.payload, void 0, {
|
|
595
|
-
F: __dxlog_file,
|
|
596
|
-
L: 493,
|
|
597
|
-
S: this,
|
|
598
|
-
A: [
|
|
599
|
-
"req.payload",
|
|
600
|
-
""
|
|
601
|
-
]
|
|
602
|
-
});
|
|
603
|
-
invariant(req.method, void 0, {
|
|
604
|
-
F: __dxlog_file,
|
|
605
|
-
L: 494,
|
|
606
|
-
S: this,
|
|
607
|
-
A: [
|
|
608
|
-
"req.method",
|
|
609
|
-
""
|
|
610
|
-
]
|
|
611
|
-
});
|
|
612
|
-
const response = await this._params.callHandler(req.method, req.payload, this._params.handlerRpcOptions);
|
|
477
|
+
invariant(typeof req.id === "number", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 496, S: this, A: ["typeof req.id === 'number'", ""] });
|
|
478
|
+
invariant(req.payload, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 497, S: this, A: ["req.payload", ""] });
|
|
479
|
+
invariant(req.method, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 498, S: this, A: ["req.method", ""] });
|
|
480
|
+
const response = await this._params.callHandler(req.method, req.payload, this._getHandlerRpcOptions(req));
|
|
613
481
|
return {
|
|
614
482
|
id: req.id,
|
|
615
483
|
payload: response
|
|
@@ -623,43 +491,11 @@ ${stack.getStack()}`;
|
|
|
623
491
|
}
|
|
624
492
|
_callStreamHandler(req, callback) {
|
|
625
493
|
try {
|
|
626
|
-
invariant(this._params.streamHandler, "Requests with streaming responses are not supported.", {
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
"this._params.streamHandler",
|
|
632
|
-
"'Requests with streaming responses are not supported.'"
|
|
633
|
-
]
|
|
634
|
-
});
|
|
635
|
-
invariant(typeof req.id === "number", void 0, {
|
|
636
|
-
F: __dxlog_file,
|
|
637
|
-
L: 512,
|
|
638
|
-
S: this,
|
|
639
|
-
A: [
|
|
640
|
-
"typeof req.id === 'number'",
|
|
641
|
-
""
|
|
642
|
-
]
|
|
643
|
-
});
|
|
644
|
-
invariant(req.payload, void 0, {
|
|
645
|
-
F: __dxlog_file,
|
|
646
|
-
L: 513,
|
|
647
|
-
S: this,
|
|
648
|
-
A: [
|
|
649
|
-
"req.payload",
|
|
650
|
-
""
|
|
651
|
-
]
|
|
652
|
-
});
|
|
653
|
-
invariant(req.method, void 0, {
|
|
654
|
-
F: __dxlog_file,
|
|
655
|
-
L: 514,
|
|
656
|
-
S: this,
|
|
657
|
-
A: [
|
|
658
|
-
"req.method",
|
|
659
|
-
""
|
|
660
|
-
]
|
|
661
|
-
});
|
|
662
|
-
const responseStream = this._params.streamHandler(req.method, req.payload, this._params.handlerRpcOptions);
|
|
494
|
+
invariant(this._params.streamHandler, "Requests with streaming responses are not supported.", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 513, S: this, A: ["this._params.streamHandler", "'Requests with streaming responses are not supported.'"] });
|
|
495
|
+
invariant(typeof req.id === "number", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 514, S: this, A: ["typeof req.id === 'number'", ""] });
|
|
496
|
+
invariant(req.payload, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 515, S: this, A: ["req.payload", ""] });
|
|
497
|
+
invariant(req.method, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 516, S: this, A: ["req.method", ""] });
|
|
498
|
+
const responseStream = this._params.streamHandler(req.method, req.payload, this._getHandlerRpcOptions(req));
|
|
663
499
|
responseStream.onReady(() => {
|
|
664
500
|
callback({
|
|
665
501
|
id: req.id,
|
|
@@ -734,15 +570,7 @@ var ProtoRpcPeer = class {
|
|
|
734
570
|
var createProtoRpcPeer = ({ requested, exposed, handlers, encodingOptions, ...rest }) => {
|
|
735
571
|
const exposedRpcs = {};
|
|
736
572
|
if (exposed) {
|
|
737
|
-
invariant2(handlers, void 0, {
|
|
738
|
-
F: __dxlog_file2,
|
|
739
|
-
L: 93,
|
|
740
|
-
S: void 0,
|
|
741
|
-
A: [
|
|
742
|
-
"handlers",
|
|
743
|
-
""
|
|
744
|
-
]
|
|
745
|
-
});
|
|
573
|
+
invariant2(handlers, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 37, S: void 0, A: ["handlers", ""] });
|
|
746
574
|
for (const serviceName of Object.keys(exposed)) {
|
|
747
575
|
const serviceFqn = exposed[serviceName].serviceProto.fullName.slice(1);
|
|
748
576
|
const serviceProvider = handlers[serviceName];
|
|
@@ -878,11 +706,10 @@ import { Event } from "@dxos/async";
|
|
|
878
706
|
import { MessageTrace } from "@dxos/protocols/proto/dxos/rpc";
|
|
879
707
|
var PortTracer = class {
|
|
880
708
|
_wrappedPort;
|
|
881
|
-
message;
|
|
709
|
+
message = new Event();
|
|
882
710
|
_port;
|
|
883
711
|
constructor(_wrappedPort) {
|
|
884
712
|
this._wrappedPort = _wrappedPort;
|
|
885
|
-
this.message = new Event();
|
|
886
713
|
this._port = {
|
|
887
714
|
send: (msg) => {
|
|
888
715
|
this.message.emit({
|