@dxos/rpc 0.8.4-main.f9ba587 → 0.8.4-main.fcfe5033a5

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 CHANGED
@@ -4,8 +4,8 @@ A lightweight, transport-agnostic RPC implementation.
4
4
 
5
5
  ## Features
6
6
 
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.
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.
@@ -1,15 +1,5 @@
1
1
  import "@dxos/node-std/globals";
2
2
 
3
- // src/rpc.ts
4
- import { asyncTimeout, synchronized, Trigger } from "@dxos/async";
5
- import { Stream } from "@dxos/codec-protobuf";
6
- import { StackTrace as StackTrace2 } from "@dxos/debug";
7
- import { invariant } from "@dxos/invariant";
8
- import { log } from "@dxos/log";
9
- import { encodeError, RpcClosedError, RpcNotOpenError } from "@dxos/protocols";
10
- import { schema } from "@dxos/protocols/proto";
11
- import { exponentialBackoffInterval } from "@dxos/util";
12
-
13
3
  // src/errors.ts
14
4
  import { StackTrace } from "@dxos/debug";
15
5
  import { decodeError } from "@dxos/protocols";
@@ -20,6 +10,15 @@ var decodeRpcError = (err, rpcMethod) => decodeError(err, {
20
10
  });
21
11
 
22
12
  // src/rpc.ts
13
+ import { Trigger, asyncTimeout, synchronized } from "@dxos/async";
14
+ import { Stream } from "@dxos/codec-protobuf";
15
+ import { ContextRpcCodec } from "@dxos/context";
16
+ import { StackTrace as StackTrace2 } from "@dxos/debug";
17
+ import { invariant } from "@dxos/invariant";
18
+ import { log } from "@dxos/log";
19
+ import { RpcClosedError, RpcNotOpenError, encodeError } from "@dxos/protocols";
20
+ import { schema } from "@dxos/protocols/proto";
21
+ import { exponentialBackoffInterval } from "@dxos/util";
23
22
  function _ts_decorate(decorators, target, key, desc) {
24
23
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
25
24
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
@@ -27,11 +26,14 @@ function _ts_decorate(decorators, target, key, desc) {
27
26
  return c > 3 && r && Object.defineProperty(target, key, r), r;
28
27
  }
29
28
  var __dxlog_file = "/__w/dxos/dxos/packages/core/mesh/rpc/src/rpc.ts";
30
- var DEFAULT_TIMEOUT = 3e3;
29
+ var DEFAULT_TIMEOUT = 3e4;
31
30
  var BYE_SEND_TIMEOUT = 2e3;
32
31
  var DEBUG_CALLS = true;
33
32
  var CLOSE_TIMEOUT = 3e3;
34
33
  var PendingRpcRequest = class {
34
+ resolve;
35
+ reject;
36
+ stream;
35
37
  constructor(resolve, reject, stream) {
36
38
  this.resolve = resolve;
37
39
  this.reject = reject;
@@ -41,22 +43,23 @@ var PendingRpcRequest = class {
41
43
  var RpcMessageCodec;
42
44
  var getRpcMessageCodec = () => RpcMessageCodec ??= schema.getCodecForType("dxos.rpc.RpcMessage");
43
45
  var RpcPeer = class {
46
+ _params;
47
+ _outgoingRequests = /* @__PURE__ */ new Map();
48
+ _localStreams = /* @__PURE__ */ new Map();
49
+ _remoteOpenTrigger = new Trigger();
50
+ /**
51
+ * Triggered when the peer starts closing.
52
+ */
53
+ _closingTrigger = new Trigger();
54
+ /**
55
+ * Triggered when peer receives a bye message.
56
+ */
57
+ _byeTrigger = new Trigger();
58
+ _nextId = 0;
59
+ _state = "INITIAL";
60
+ _unsubscribeFromPort = void 0;
61
+ _clearOpenInterval = void 0;
44
62
  constructor(params) {
45
- this._outgoingRequests = /* @__PURE__ */ new Map();
46
- this._localStreams = /* @__PURE__ */ new Map();
47
- this._remoteOpenTrigger = new Trigger();
48
- /**
49
- * Triggered when the peer starts closing.
50
- */
51
- this._closingTrigger = new Trigger();
52
- /**
53
- * Triggered when peer receives a bye message.
54
- */
55
- this._byeTrigger = new Trigger();
56
- this._nextId = 0;
57
- this._state = "INITIAL";
58
- this._unsubscribeFromPort = void 0;
59
- this._clearOpenInterval = void 0;
60
63
  this._params = {
61
64
  timeout: void 0,
62
65
  streamHandler: void 0,
@@ -79,7 +82,7 @@ var RpcPeer = class {
79
82
  } catch (err) {
80
83
  log.catch(err, void 0, {
81
84
  F: __dxlog_file,
82
- L: 156,
85
+ L: 157,
83
86
  S: this,
84
87
  C: (f, a) => f(...a)
85
88
  });
@@ -95,7 +98,7 @@ var RpcPeer = class {
95
98
  state: this._state
96
99
  }, {
97
100
  F: __dxlog_file,
98
- L: 168,
101
+ L: 169,
99
102
  S: this,
100
103
  C: (f, a) => f(...a)
101
104
  });
@@ -110,7 +113,7 @@ var RpcPeer = class {
110
113
  open: true
111
114
  }).catch((err) => log.warn(err, void 0, {
112
115
  F: __dxlog_file,
113
- L: 177,
116
+ L: 178,
114
117
  S: this,
115
118
  C: (f, a) => f(...a)
116
119
  }));
@@ -127,7 +130,7 @@ var RpcPeer = class {
127
130
  state: this._state
128
131
  }, {
129
132
  F: __dxlog_file,
130
- L: 191,
133
+ L: 192,
131
134
  S: this,
132
135
  C: (f, a) => f(...a)
133
136
  });
@@ -157,7 +160,7 @@ var RpcPeer = class {
157
160
  err
158
161
  }, {
159
162
  F: __dxlog_file,
160
- L: 213,
163
+ L: 214,
161
164
  S: this,
162
165
  C: (f, a) => f(...a)
163
166
  });
@@ -165,7 +168,7 @@ var RpcPeer = class {
165
168
  try {
166
169
  log("closing waiting on bye", void 0, {
167
170
  F: __dxlog_file,
168
- L: 216,
171
+ L: 217,
169
172
  S: this,
170
173
  C: (f, a) => f(...a)
171
174
  });
@@ -177,7 +180,7 @@ var RpcPeer = class {
177
180
  err
178
181
  }, {
179
182
  F: __dxlog_file,
180
- L: 219,
183
+ L: 220,
181
184
  S: this,
182
185
  C: (f, a) => f(...a)
183
186
  });
@@ -221,7 +224,7 @@ var RpcPeer = class {
221
224
  type: Object.keys(decoded)[0]
222
225
  }, {
223
226
  F: __dxlog_file,
224
- L: 263,
227
+ L: 264,
225
228
  S: this,
226
229
  C: (f, a) => f(...a)
227
230
  });
@@ -229,7 +232,7 @@ var RpcPeer = class {
229
232
  if (this._state !== "OPENED" && this._state !== "OPENING") {
230
233
  log("received request while closed", void 0, {
231
234
  F: __dxlog_file,
232
- L: 267,
235
+ L: 268,
233
236
  S: this,
234
237
  C: (f, a) => f(...a)
235
238
  });
@@ -247,7 +250,7 @@ var RpcPeer = class {
247
250
  method: req.method
248
251
  }, {
249
252
  F: __dxlog_file,
250
- L: 279,
253
+ L: 280,
251
254
  S: this,
252
255
  C: (f, a) => f(...a)
253
256
  });
@@ -259,7 +262,7 @@ var RpcPeer = class {
259
262
  close: response.close
260
263
  }, {
261
264
  F: __dxlog_file,
262
- L: 281,
265
+ L: 282,
263
266
  S: this,
264
267
  C: (f, a) => f(...a)
265
268
  });
@@ -268,7 +271,7 @@ var RpcPeer = class {
268
271
  }).catch((err) => {
269
272
  log.warn("failed during close", err, {
270
273
  F: __dxlog_file,
271
- L: 289,
274
+ L: 290,
272
275
  S: this,
273
276
  C: (f, a) => f(...a)
274
277
  });
@@ -279,7 +282,7 @@ var RpcPeer = class {
279
282
  method: req.method
280
283
  }, {
281
284
  F: __dxlog_file,
282
- L: 293,
285
+ L: 294,
283
286
  S: this,
284
287
  C: (f, a) => f(...a)
285
288
  });
@@ -290,7 +293,7 @@ var RpcPeer = class {
290
293
  error: response.error
291
294
  }, {
292
295
  F: __dxlog_file,
293
- L: 296,
296
+ L: 297,
294
297
  S: this,
295
298
  C: (f, a) => f(...a)
296
299
  });
@@ -302,7 +305,7 @@ var RpcPeer = class {
302
305
  if (this._state !== "OPENED") {
303
306
  log("received response while closed", void 0, {
304
307
  F: __dxlog_file,
305
- L: 305,
308
+ L: 306,
306
309
  S: this,
307
310
  C: (f, a) => f(...a)
308
311
  });
@@ -311,7 +314,7 @@ var RpcPeer = class {
311
314
  const responseId = decoded.response.id;
312
315
  invariant(typeof responseId === "number", void 0, {
313
316
  F: __dxlog_file,
314
- L: 310,
317
+ L: 311,
315
318
  S: this,
316
319
  A: [
317
320
  "typeof responseId === 'number'",
@@ -323,7 +326,7 @@ var RpcPeer = class {
323
326
  responseId
324
327
  }, {
325
328
  F: __dxlog_file,
326
- L: 312,
329
+ L: 313,
327
330
  S: this,
328
331
  C: (f, a) => f(...a)
329
332
  });
@@ -337,7 +340,7 @@ var RpcPeer = class {
337
340
  type_url: decoded.response.payload?.type_url
338
341
  }, {
339
342
  F: __dxlog_file,
340
- L: 322,
343
+ L: 323,
341
344
  S: this,
342
345
  C: (f, a) => f(...a)
343
346
  });
@@ -347,7 +350,7 @@ var RpcPeer = class {
347
350
  state: this._state
348
351
  }, {
349
352
  F: __dxlog_file,
350
- L: 325,
353
+ L: 326,
351
354
  S: this,
352
355
  C: (f, a) => f(...a)
353
356
  });
@@ -362,7 +365,7 @@ var RpcPeer = class {
362
365
  state: this._state
363
366
  }, {
364
367
  F: __dxlog_file,
365
- L: 332,
368
+ L: 333,
366
369
  S: this,
367
370
  C: (f, a) => f(...a)
368
371
  });
@@ -375,7 +378,7 @@ var RpcPeer = class {
375
378
  if (this._state !== "OPENED") {
376
379
  log("received stream close while closed", void 0, {
377
380
  F: __dxlog_file,
378
- L: 341,
381
+ L: 342,
379
382
  S: this,
380
383
  C: (f, a) => f(...a)
381
384
  });
@@ -385,13 +388,13 @@ var RpcPeer = class {
385
388
  id: decoded.streamClose.id
386
389
  }, {
387
390
  F: __dxlog_file,
388
- L: 345,
391
+ L: 346,
389
392
  S: this,
390
393
  C: (f, a) => f(...a)
391
394
  });
392
395
  invariant(typeof decoded.streamClose.id === "number", void 0, {
393
396
  F: __dxlog_file,
394
- L: 346,
397
+ L: 347,
395
398
  S: this,
396
399
  A: [
397
400
  "typeof decoded.streamClose.id === 'number'",
@@ -404,7 +407,7 @@ var RpcPeer = class {
404
407
  id: decoded.streamClose.id
405
408
  }, {
406
409
  F: __dxlog_file,
407
- L: 349,
410
+ L: 350,
408
411
  S: this,
409
412
  C: (f, a) => f(...a)
410
413
  });
@@ -417,7 +420,7 @@ var RpcPeer = class {
417
420
  if (this._state !== "CLOSING" && this._state !== "CLOSED") {
418
421
  log("replying to bye", void 0, {
419
422
  F: __dxlog_file,
420
- L: 359,
423
+ L: 360,
421
424
  S: this,
422
425
  C: (f, a) => f(...a)
423
426
  });
@@ -433,7 +436,7 @@ var RpcPeer = class {
433
436
  msg
434
437
  }, {
435
438
  F: __dxlog_file,
436
- L: 367,
439
+ L: 368,
437
440
  S: this,
438
441
  C: (f, a) => f(...a)
439
442
  });
@@ -449,7 +452,7 @@ var RpcPeer = class {
449
452
  method
450
453
  }, {
451
454
  F: __dxlog_file,
452
- L: 377,
455
+ L: 378,
453
456
  S: this,
454
457
  C: (f, a) => f(...a)
455
458
  });
@@ -460,12 +463,28 @@ var RpcPeer = class {
460
463
  const responseReceived = new Promise((resolve, reject) => {
461
464
  this._outgoingRequests.set(id, new PendingRpcRequest(resolve, reject, false));
462
465
  });
466
+ let traceContext;
467
+ try {
468
+ traceContext = options?.ctx ? ContextRpcCodec.encode(options.ctx) : void 0;
469
+ } catch (err) {
470
+ log.warn("failed to encode trace context", {
471
+ err
472
+ }, {
473
+ F: __dxlog_file,
474
+ L: 393,
475
+ S: this,
476
+ C: (f, a) => f(...a)
477
+ });
478
+ }
463
479
  const sending = this._sendMessage({
464
480
  request: {
465
481
  id,
466
482
  method,
467
483
  payload: request,
468
- stream: false
484
+ stream: false,
485
+ ...traceContext ? {
486
+ traceContext
487
+ } : {}
469
488
  }
470
489
  });
471
490
  const timeout = options?.timeout ?? this._params.timeout;
@@ -477,7 +496,7 @@ var RpcPeer = class {
477
496
  response = await waiting;
478
497
  invariant(response.id === id, void 0, {
479
498
  F: __dxlog_file,
480
- L: 405,
499
+ L: 414,
481
500
  S: this,
482
501
  A: [
483
502
  "response.id === id",
@@ -538,16 +557,38 @@ ${stack.getStack()}`;
538
557
  }
539
558
  };
540
559
  this._outgoingRequests.set(id, new PendingRpcRequest(onResponse, closeStream, true));
541
- this._sendMessage({
542
- request: {
543
- id,
544
- method,
545
- payload: request,
546
- stream: true
547
- }
548
- }).catch((err) => {
549
- close(err);
550
- });
560
+ let traceContext;
561
+ try {
562
+ traceContext = options?.ctx ? ContextRpcCodec.encode(options.ctx) : void 0;
563
+ } catch (err) {
564
+ log.warn("failed to encode trace context", {
565
+ err
566
+ }, {
567
+ F: __dxlog_file,
568
+ L: 476,
569
+ S: this,
570
+ C: (f, a) => f(...a)
571
+ });
572
+ }
573
+ try {
574
+ this._sendMessage({
575
+ request: {
576
+ id,
577
+ method,
578
+ payload: request,
579
+ stream: true,
580
+ ...traceContext ? {
581
+ traceContext
582
+ } : {}
583
+ }
584
+ }).catch((err) => {
585
+ this._outgoingRequests.delete(id);
586
+ close(err);
587
+ });
588
+ } catch (err) {
589
+ this._outgoingRequests.delete(id);
590
+ throw err;
591
+ }
551
592
  return () => {
552
593
  this._sendMessage({
553
594
  streamClose: {
@@ -556,7 +597,7 @@ ${stack.getStack()}`;
556
597
  }).catch((err) => {
557
598
  log.catch(err, void 0, {
558
599
  F: __dxlog_file,
559
- L: 478,
600
+ L: 501,
560
601
  S: this,
561
602
  C: (f, a) => f(...a)
562
603
  });
@@ -570,7 +611,7 @@ ${stack.getStack()}`;
570
611
  type: Object.keys(message)[0]
571
612
  }, {
572
613
  F: __dxlog_file,
573
- L: 486,
614
+ L: 509,
574
615
  S: this,
575
616
  C: (f, a) => f(...a)
576
617
  });
@@ -578,11 +619,38 @@ ${stack.getStack()}`;
578
619
  preserveAny: true
579
620
  }), timeout);
580
621
  }
622
+ _getHandlerRpcOptions(req) {
623
+ let traceCtx;
624
+ if (req.traceContext) {
625
+ try {
626
+ traceCtx = ContextRpcCodec.decode(req.traceContext);
627
+ } catch (err) {
628
+ log.warn("failed to decode trace context", {
629
+ traceContext: req.traceContext,
630
+ err
631
+ }, {
632
+ F: __dxlog_file,
633
+ L: 519,
634
+ S: this,
635
+ C: (f, a) => f(...a)
636
+ });
637
+ }
638
+ }
639
+ if (!traceCtx && !this._params.handlerRpcOptions) {
640
+ return void 0;
641
+ }
642
+ return {
643
+ ...this._params.handlerRpcOptions,
644
+ ...traceCtx ? {
645
+ ctx: traceCtx
646
+ } : {}
647
+ };
648
+ }
581
649
  async _callHandler(req) {
582
650
  try {
583
651
  invariant(typeof req.id === "number", void 0, {
584
652
  F: __dxlog_file,
585
- L: 492,
653
+ L: 530,
586
654
  S: this,
587
655
  A: [
588
656
  "typeof req.id === 'number'",
@@ -591,7 +659,7 @@ ${stack.getStack()}`;
591
659
  });
592
660
  invariant(req.payload, void 0, {
593
661
  F: __dxlog_file,
594
- L: 493,
662
+ L: 531,
595
663
  S: this,
596
664
  A: [
597
665
  "req.payload",
@@ -600,14 +668,14 @@ ${stack.getStack()}`;
600
668
  });
601
669
  invariant(req.method, void 0, {
602
670
  F: __dxlog_file,
603
- L: 494,
671
+ L: 532,
604
672
  S: this,
605
673
  A: [
606
674
  "req.method",
607
675
  ""
608
676
  ]
609
677
  });
610
- const response = await this._params.callHandler(req.method, req.payload, this._params.handlerRpcOptions);
678
+ const response = await this._params.callHandler(req.method, req.payload, this._getHandlerRpcOptions(req));
611
679
  return {
612
680
  id: req.id,
613
681
  payload: response
@@ -623,7 +691,7 @@ ${stack.getStack()}`;
623
691
  try {
624
692
  invariant(this._params.streamHandler, "Requests with streaming responses are not supported.", {
625
693
  F: __dxlog_file,
626
- L: 511,
694
+ L: 549,
627
695
  S: this,
628
696
  A: [
629
697
  "this._params.streamHandler",
@@ -632,7 +700,7 @@ ${stack.getStack()}`;
632
700
  });
633
701
  invariant(typeof req.id === "number", void 0, {
634
702
  F: __dxlog_file,
635
- L: 512,
703
+ L: 550,
636
704
  S: this,
637
705
  A: [
638
706
  "typeof req.id === 'number'",
@@ -641,7 +709,7 @@ ${stack.getStack()}`;
641
709
  });
642
710
  invariant(req.payload, void 0, {
643
711
  F: __dxlog_file,
644
- L: 513,
712
+ L: 551,
645
713
  S: this,
646
714
  A: [
647
715
  "req.payload",
@@ -650,14 +718,14 @@ ${stack.getStack()}`;
650
718
  });
651
719
  invariant(req.method, void 0, {
652
720
  F: __dxlog_file,
653
- L: 514,
721
+ L: 552,
654
722
  S: this,
655
723
  A: [
656
724
  "req.method",
657
725
  ""
658
726
  ]
659
727
  });
660
- const responseStream = this._params.streamHandler(req.method, req.payload, this._params.handlerRpcOptions);
728
+ const responseStream = this._params.streamHandler(req.method, req.payload, this._getHandlerRpcOptions(req));
661
729
  responseStream.onReady(() => {
662
730
  callback({
663
731
  id: req.id,
@@ -713,6 +781,8 @@ import { invariant as invariant2 } from "@dxos/invariant";
713
781
  var __dxlog_file2 = "/__w/dxos/dxos/packages/core/mesh/rpc/src/service.ts";
714
782
  var createServiceBundle = (services) => services;
715
783
  var ProtoRpcPeer = class {
784
+ rpc;
785
+ _peer;
716
786
  constructor(rpc, _peer) {
717
787
  this.rpc = rpc;
718
788
  this._peer = _peer;
@@ -873,9 +943,11 @@ var encodeMessage = (msg) => isNode() ? Buffer.from(msg) : new TextEncoder().enc
873
943
  import { Event } from "@dxos/async";
874
944
  import { MessageTrace } from "@dxos/protocols/proto/dxos/rpc";
875
945
  var PortTracer = class {
946
+ _wrappedPort;
947
+ message = new Event();
948
+ _port;
876
949
  constructor(_wrappedPort) {
877
950
  this._wrappedPort = _wrappedPort;
878
- this.message = new Event();
879
951
  this._port = {
880
952
  send: (msg) => {
881
953
  this.message.emit({
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/errors.ts", "../../../src/rpc.ts", "../../../src/service.ts", "../../../src/testing.ts", "../../../src/trace.ts"],
4
+ "sourcesContent": ["//\n// Copyright 2021 DXOS.org\n//\n\nimport { StackTrace } from '@dxos/debug';\nimport { decodeError } from '@dxos/protocols';\nimport { type Error as ErrorResponse } from '@dxos/protocols/proto/dxos/error';\n\nexport const decodeRpcError = (err: ErrorResponse, rpcMethod: string): Error =>\n decodeError(err, {\n appendStack: `\\n at RPC ${rpcMethod} \\n` + new StackTrace().getStack(1),\n });\n", "//\n// Copyright 2021 DXOS.org\n//\n\nimport { Trigger, asyncTimeout, synchronized } from '@dxos/async';\nimport { type Any, type ProtoCodec, type RequestOptions, Stream } from '@dxos/codec-protobuf';\nimport { type Context, ContextRpcCodec } from '@dxos/context';\nimport { StackTrace } from '@dxos/debug';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\nimport { RpcClosedError, RpcNotOpenError, encodeError } from '@dxos/protocols';\nimport { schema } from '@dxos/protocols/proto';\nimport { type Request, type Response, type RpcMessage } from '@dxos/protocols/proto/dxos/rpc';\nimport { exponentialBackoffInterval } from '@dxos/util';\n\nimport { decodeRpcError } from './errors';\n\nconst DEFAULT_TIMEOUT = 30_000;\nconst BYE_SEND_TIMEOUT = 2_000;\n\nconst DEBUG_CALLS = true;\n\ntype MaybePromise<T> = Promise<T> | T;\n\nexport interface RpcPeerOptions {\n port: RpcPort;\n\n /**\n * Time to wait for a response to an RPC call.\n */\n timeout?: number;\n\n callHandler: (method: string, request: Any, options?: RequestOptions) => MaybePromise<Any>;\n streamHandler?: (method: string, request: Any, options?: RequestOptions) => Stream<Any>;\n\n /**\n * Do not require or send handshake messages.\n */\n noHandshake?: boolean;\n\n /**\n * What options get passed to the `callHandler` and `streamHandler`.\n */\n handlerRpcOptions?: RequestOptions;\n}\n\n/**\n * Interface for a transport-agnostic port to send/receive binary messages.\n */\nexport interface RpcPort {\n send: (msg: Uint8Array, timeout?: number) => MaybePromise<void>;\n subscribe: (cb: (msg: Uint8Array) => void) => (() => void) | void;\n}\n\nconst CLOSE_TIMEOUT = 3_000;\n\nexport type CloseOptions = {\n /**\n * Time to wait for the other side to confirm close.\n */\n timeout?: number;\n};\n\nclass PendingRpcRequest {\n constructor(\n public readonly resolve: (response: Response) => void,\n public readonly reject: (error?: Error) => void,\n public readonly stream: boolean,\n ) {}\n}\n\n// NOTE: Lazy so that code that doesn't use indexing doesn't need to load the codec (breaks in workerd).\nlet RpcMessageCodec!: ProtoCodec<RpcMessage>;\nconst getRpcMessageCodec = () => (RpcMessageCodec ??= schema.getCodecForType('dxos.rpc.RpcMessage'));\n\nenum RpcState {\n INITIAL = 'INITIAL',\n\n OPENING = 'OPENING',\n\n OPENED = 'OPENED',\n\n /**\n * Bye message sent, waiting for the other side to close.\n * Not possible to send requests.\n * All pending requests will be rejected.\n */\n CLOSING = 'CLOSING',\n\n /**\n * Connection fully closed.\n * The underlying transport can be disposed.\n */\n CLOSED = 'CLOSED',\n}\n\n/**\n * A remote procedure call peer.\n *\n * Provides a away to make RPC calls and get a response back as a promise.\n * Does not handle encoding/decoding and only works with byte buffers.\n * For type safe approach see `createRpcClient` and `createRpcServer`.\n *\n * Must be connected with another instance on the other side via `send`/`receive` methods.\n * Both sides must be opened before making any RPC calls.\n *\n * Errors inside the handler get serialized and sent to the other side.\n *\n * Inspired by JSON-RPC 2.0 https://www.jsonrpc.org/specification.\n */\nexport class RpcPeer {\n private readonly _params: RpcPeerOptions;\n\n private readonly _outgoingRequests = new Map<number, PendingRpcRequest>();\n private readonly _localStreams = new Map<number, Stream<any>>();\n private readonly _remoteOpenTrigger = new Trigger();\n\n /**\n * Triggered when the peer starts closing.\n */\n private readonly _closingTrigger = new Trigger();\n\n /**\n * Triggered when peer receives a bye message.\n */\n private readonly _byeTrigger = new Trigger();\n\n private _nextId = 0;\n private _state: RpcState = RpcState.INITIAL;\n private _unsubscribeFromPort: (() => void) | undefined = undefined;\n private _clearOpenInterval: (() => void) | undefined = undefined;\n\n constructor(params: RpcPeerOptions) {\n this._params = {\n timeout: undefined,\n streamHandler: undefined,\n noHandshake: false,\n ...params,\n };\n }\n\n /**\n * Open the peer. Required before making any calls.\n *\n * Will block before the other peer calls `open`.\n */\n @synchronized\n async open(): Promise<void> {\n if (this._state !== RpcState.INITIAL) {\n return;\n }\n\n this._unsubscribeFromPort = this._params.port.subscribe(async (msg) => {\n try {\n await this._receive(msg);\n } catch (err: any) {\n log.catch(err);\n }\n }) as any;\n\n this._state = RpcState.OPENING;\n\n if (this._params.noHandshake) {\n this._state = RpcState.OPENED;\n this._remoteOpenTrigger.wake();\n return;\n }\n\n log('sending open message', { state: this._state });\n await this._sendMessage({ open: true });\n\n if (this._state !== RpcState.OPENING) {\n return;\n }\n\n // Retry sending.\n this._clearOpenInterval = exponentialBackoffInterval(() => {\n void this._sendMessage({ open: true }).catch((err) => log.warn(err));\n }, 50);\n\n await Promise.race([this._remoteOpenTrigger.wait(), this._closingTrigger.wait()]);\n\n this._clearOpenInterval?.();\n\n if ((this._state as RpcState) !== RpcState.OPENED) {\n // Closed while opening.\n return; // TODO(dmaretskyi): Throw error?\n }\n\n // TODO(burdon): This seems error prone.\n // Send an \"open\" message in case the other peer has missed our first \"open\" message and is still waiting.\n log('resending open message', { state: this._state });\n await this._sendMessage({ openAck: true });\n }\n\n /**\n * Close the peer.\n * Stop taking or making requests.\n * Will wait for confirmation from the other side.\n * Any responses for RPC calls made before close will be delivered.\n */\n async close({ timeout = CLOSE_TIMEOUT }: CloseOptions = {}): Promise<void> {\n if (this._state === RpcState.CLOSED) {\n return;\n }\n\n this._abortRequests();\n\n if (this._state === RpcState.OPENED && !this._params.noHandshake) {\n try {\n this._state = RpcState.CLOSING;\n await this._sendMessage({ bye: {} }, BYE_SEND_TIMEOUT);\n } catch (err: any) {\n log('error closing peer, sending bye', { err });\n }\n try {\n log('closing waiting on bye');\n await this._byeTrigger.wait({ timeout });\n } catch (err: any) {\n log('error closing peer', { err });\n return;\n }\n }\n\n this._disposeAndClose();\n }\n\n /**\n * Dispose the connection without waiting for the other side.\n */\n async abort(): Promise<void> {\n if (this._state === RpcState.CLOSED) {\n return;\n }\n\n this._abortRequests();\n this._disposeAndClose();\n }\n\n private _abortRequests(): void {\n // Abort open\n this._clearOpenInterval?.();\n this._closingTrigger.wake();\n\n // Abort pending requests\n for (const req of this._outgoingRequests.values()) {\n req.reject(new RpcClosedError());\n }\n this._outgoingRequests.clear();\n }\n\n private _disposeAndClose(): void {\n this._unsubscribeFromPort?.();\n this._unsubscribeFromPort = undefined;\n this._clearOpenInterval?.();\n this._state = RpcState.CLOSED;\n }\n\n /**\n * Handle incoming message. Should be called as the result of other peer's `send` callback.\n */\n private async _receive(msg: Uint8Array): Promise<void> {\n const decoded = getRpcMessageCodec().decode(msg, { preserveAny: true });\n DEBUG_CALLS && log('received message', { type: Object.keys(decoded)[0] });\n\n if (decoded.request) {\n if (this._state !== RpcState.OPENED && this._state !== RpcState.OPENING) {\n log('received request while closed');\n await this._sendMessage({\n response: {\n id: decoded.request.id,\n error: encodeError(new RpcClosedError()),\n },\n });\n return;\n }\n\n const req = decoded.request;\n if (req.stream) {\n log('stream request', { method: req.method });\n this._callStreamHandler(req, (response) => {\n log('sending stream response', {\n method: req.method,\n response: response.payload?.type_url,\n error: response.error,\n close: response.close,\n });\n\n void this._sendMessage({ response }).catch((err) => {\n log.warn('failed during close', err);\n });\n });\n } else {\n DEBUG_CALLS && log('requesting...', { method: req.method });\n const response = await this._callHandler(req);\n DEBUG_CALLS &&\n log('sending response', {\n method: req.method,\n response: response.payload?.type_url,\n error: response.error,\n });\n await this._sendMessage({ response });\n }\n } else if (decoded.response) {\n if (this._state !== RpcState.OPENED) {\n log('received response while closed');\n return; // Ignore when not open.\n }\n\n const responseId = decoded.response.id;\n invariant(typeof responseId === 'number');\n if (!this._outgoingRequests.has(responseId)) {\n log('received response with invalid id', { responseId });\n return; // Ignore requests with incorrect id.\n }\n\n const item = this._outgoingRequests.get(responseId)!;\n // Delete the request record if no more responses are expected.\n if (!item.stream) {\n this._outgoingRequests.delete(responseId);\n }\n\n DEBUG_CALLS && log('response', { type_url: decoded.response.payload?.type_url });\n item.resolve(decoded.response);\n } else if (decoded.open) {\n log('received open message', { state: this._state });\n if (this._params.noHandshake) {\n return;\n }\n\n await this._sendMessage({ openAck: true });\n } else if (decoded.openAck) {\n log('received openAck message', { state: this._state });\n if (this._params.noHandshake) {\n return;\n }\n\n this._state = RpcState.OPENED;\n this._remoteOpenTrigger.wake();\n } else if (decoded.streamClose) {\n if (this._state !== RpcState.OPENED) {\n log('received stream close while closed');\n return; // Ignore when not open.\n }\n\n log('received stream close', { id: decoded.streamClose.id });\n invariant(typeof decoded.streamClose.id === 'number');\n const stream = this._localStreams.get(decoded.streamClose.id);\n if (!stream) {\n log('no local stream', { id: decoded.streamClose.id });\n return; // Ignore requests with incorrect id.\n }\n\n this._localStreams.delete(decoded.streamClose.id);\n await stream.close();\n } else if (decoded.bye) {\n this._byeTrigger.wake();\n // If we haven't already started closing, close now.\n if (this._state !== RpcState.CLOSING && this._state !== RpcState.CLOSED) {\n log('replying to bye');\n this._state = RpcState.CLOSING;\n await this._sendMessage({ bye: {} });\n\n this._abortRequests();\n this._disposeAndClose();\n }\n } else {\n log.error('received malformed message', { msg });\n throw new Error('Malformed message.');\n }\n }\n\n /**\n * Make RPC call. Will trigger a handler on the other side.\n * Peer should be open before making this call.\n */\n async call(method: string, request: Any, options?: RequestOptions): Promise<Any> {\n DEBUG_CALLS && log('calling...', { method });\n throwIfNotOpen(this._state);\n\n let response: Response;\n try {\n // Set-up response listener.\n const id = this._nextId++;\n const responseReceived = new Promise<Response>((resolve, reject) => {\n this._outgoingRequests.set(id, new PendingRpcRequest(resolve, reject, false));\n });\n\n let traceContext;\n try {\n traceContext = options?.ctx ? ContextRpcCodec.encode(options.ctx) : undefined;\n } catch (err) {\n log.warn('failed to encode trace context', { err });\n }\n\n // Send request call.\n const sending = this._sendMessage({\n request: {\n id,\n method,\n payload: request,\n stream: false,\n ...(traceContext ? { traceContext } : {}),\n },\n });\n\n // Wait until send completes or throws an error (or response throws a timeout), the resume waiting.\n const timeout = options?.timeout ?? this._params.timeout;\n const waiting =\n timeout === 0 ? responseReceived : asyncTimeout<any>(responseReceived, timeout ?? DEFAULT_TIMEOUT);\n\n await Promise.race([sending, waiting]);\n response = await waiting;\n invariant(response.id === id);\n } catch (err) {\n if (err instanceof RpcClosedError) {\n // Rethrow the error here to have the correct stack-trace.\n const error = new RpcClosedError();\n error.stack += `\\n\\n info: RPC client was closed at:\\n${err.stack?.split('\\n').slice(1).join('\\n')}`;\n throw error;\n }\n\n throw err;\n }\n\n if (response.payload) {\n return response.payload;\n } else if (response.error) {\n throw decodeRpcError(response.error, method);\n } else {\n throw new Error('Malformed response.');\n }\n }\n\n /**\n * Make RPC call with a streaming response.\n * Will trigger a handler on the other side.\n * Peer should be open before making this call.\n */\n callStream(method: string, request: Any, options?: RequestOptions): Stream<Any> {\n throwIfNotOpen(this._state);\n const id = this._nextId++;\n\n return new Stream(({ ready, next, close }) => {\n const onResponse = (response: Response) => {\n if (response.streamReady) {\n ready();\n } else if (response.close) {\n close();\n } else if (response.error) {\n // TODO(dmaretskyi): Stack trace might be lost because the stream producer function is called asynchronously.\n close(decodeRpcError(response.error, method));\n } else if (response.payload) {\n next(response.payload);\n } else {\n throw new Error('Malformed response.');\n }\n };\n\n const stack = new StackTrace();\n const closeStream = (err?: Error) => {\n if (!err) {\n close();\n } else {\n err.stack += `\\n\\nError happened in the stream at:\\n${stack.getStack()}`;\n close(err);\n }\n };\n\n this._outgoingRequests.set(id, new PendingRpcRequest(onResponse, closeStream, true));\n\n let traceContext;\n try {\n traceContext = options?.ctx ? ContextRpcCodec.encode(options.ctx) : undefined;\n } catch (err) {\n log.warn('failed to encode trace context', { err });\n }\n\n try {\n this._sendMessage({\n request: {\n id,\n method,\n payload: request,\n stream: true,\n ...(traceContext ? { traceContext } : {}),\n },\n }).catch((err) => {\n this._outgoingRequests.delete(id);\n close(err);\n });\n } catch (err) {\n this._outgoingRequests.delete(id);\n throw err;\n }\n\n return () => {\n this._sendMessage({\n streamClose: { id },\n }).catch((err) => {\n log.catch(err);\n });\n this._outgoingRequests.delete(id);\n };\n });\n }\n\n private async _sendMessage(message: RpcMessage, timeout?: number): Promise<void> {\n DEBUG_CALLS && log('sending message', { type: Object.keys(message)[0] });\n await this._params.port.send(getRpcMessageCodec().encode(message, { preserveAny: true }), timeout);\n }\n\n private _getHandlerRpcOptions(req: Request): RequestOptions | undefined {\n let traceCtx: Context | undefined;\n if (req.traceContext) {\n try {\n traceCtx = ContextRpcCodec.decode(req.traceContext);\n } catch (err) {\n log.warn('failed to decode trace context', { traceContext: req.traceContext, err });\n }\n }\n if (!traceCtx && !this._params.handlerRpcOptions) {\n return undefined;\n }\n return { ...this._params.handlerRpcOptions, ...(traceCtx ? { ctx: traceCtx } : {}) };\n }\n\n private async _callHandler(req: Request): Promise<Response> {\n try {\n invariant(typeof req.id === 'number');\n invariant(req.payload);\n invariant(req.method);\n\n const response = await this._params.callHandler(req.method, req.payload, this._getHandlerRpcOptions(req));\n return {\n id: req.id,\n payload: response,\n };\n } catch (err) {\n return {\n id: req.id,\n error: encodeError(err),\n };\n }\n }\n\n private _callStreamHandler(req: Request, callback: (response: Response) => void): void {\n try {\n invariant(this._params.streamHandler, 'Requests with streaming responses are not supported.');\n invariant(typeof req.id === 'number');\n invariant(req.payload);\n invariant(req.method);\n\n const responseStream = this._params.streamHandler(req.method, req.payload, this._getHandlerRpcOptions(req));\n responseStream.onReady(() => {\n callback({\n id: req.id,\n streamReady: true,\n });\n });\n\n responseStream.subscribe(\n (msg) => {\n callback({\n id: req.id,\n payload: msg,\n });\n },\n (error) => {\n if (error) {\n callback({\n id: req.id,\n error: encodeError(error),\n });\n } else {\n callback({\n id: req.id,\n close: true,\n });\n }\n },\n );\n\n this._localStreams.set(req.id, responseStream);\n } catch (err: any) {\n callback({\n id: req.id,\n error: encodeError(err),\n });\n }\n }\n}\n\nconst throwIfNotOpen = (state: RpcState) => {\n switch (state) {\n case RpcState.OPENED: {\n return;\n }\n case RpcState.INITIAL: {\n throw new RpcNotOpenError();\n }\n case RpcState.CLOSED: {\n throw new RpcClosedError();\n }\n }\n};\n", "//\n// Copyright 2021 DXOS.org\n//\n\nimport {\n type EncodingOptions,\n type ServiceDescriptor,\n type ServiceHandler,\n type ServiceProvider,\n} from '@dxos/codec-protobuf';\nimport { invariant } from '@dxos/invariant';\n\nimport { RpcPeer, type RpcPeerOptions } from './rpc';\n\n/**\n * Map of service definitions.\n */\n// TODO(burdon): Rename ServiceMap.\nexport type ServiceBundle<Services> = { [Key in keyof Services]: ServiceDescriptor<Services[Key]> };\n\nexport type ServiceHandlers<Services> = { [ServiceName in keyof Services]: ServiceProvider<Services[ServiceName]> };\n\nexport type ServiceTypesOf<Bundle extends ServiceBundle<any>> =\n Bundle extends ServiceBundle<infer Services> ? Services : never;\n\n/**\n * Groups multiple services together to be served by a single RPC peer.\n */\nexport const createServiceBundle = <Service>(services: ServiceBundle<Service>): ServiceBundle<Service> => services;\n\n/**\n * Type-safe RPC peer.\n */\nexport class ProtoRpcPeer<Service> {\n constructor(\n public readonly rpc: Service,\n private readonly _peer: RpcPeer,\n ) {}\n\n async open(): Promise<void> {\n await this._peer.open();\n }\n\n async close(): Promise<void> {\n await this._peer.close();\n }\n\n async abort(): Promise<void> {\n await this._peer.abort();\n }\n}\n\nexport interface ProtoRpcPeerOptions<Client, Server> extends Omit<RpcPeerOptions, 'callHandler' | 'streamHandler'> {\n /**\n * Services that are expected to be implemented by the counter-space.\n */\n // TODO(burdon): Rename proxy.\n requested?: ServiceBundle<Client>;\n\n /**\n * Services exposed to the counter-space.\n */\n // TODO(burdon): Rename service.\n exposed?: ServiceBundle<Server>;\n\n /**\n * Handlers for the exposed services\n */\n handlers?: ServiceHandlers<Server>;\n\n /**\n * Encoding options passed to the underlying proto codec.\n */\n encodingOptions?: EncodingOptions;\n}\n\n/**\n * Create type-safe RPC peer from a service bundle.\n * Can both handle and issue requests.\n */\n// TODO(burdon): Currently assumes that the proto service name is unique.\n// Support multiple instances services definitions (e.g., halo/space invitations).\nexport const createProtoRpcPeer = <Client = {}, Server = {}>({\n requested,\n exposed,\n handlers,\n encodingOptions,\n ...rest\n}: ProtoRpcPeerOptions<Client, Server>): ProtoRpcPeer<Client> => {\n // Create map of RPCs.\n const exposedRpcs: Record<string, ServiceHandler<any>> = {};\n if (exposed) {\n invariant(handlers);\n for (const serviceName of Object.keys(exposed) as (keyof Server)[]) {\n // Get full service name with the package name without '.' at the beginning.\n const serviceFqn = exposed[serviceName].serviceProto.fullName.slice(1);\n const serviceProvider = handlers[serviceName];\n exposedRpcs[serviceFqn] = exposed[serviceName].createServer(serviceProvider, encodingOptions);\n }\n }\n\n // Create peer.\n const peer = new RpcPeer({\n ...rest,\n\n callHandler: (method, request, options) => {\n const [serviceName, methodName] = parseMethodName(method);\n if (!exposedRpcs[serviceName]) {\n throw new Error(`Service not supported: ${serviceName}`);\n }\n\n return exposedRpcs[serviceName].call(methodName, request, options);\n },\n\n streamHandler: (method, request, options) => {\n const [serviceName, methodName] = parseMethodName(method);\n if (!exposedRpcs[serviceName]) {\n throw new Error(`Service not supported: ${serviceName}`);\n }\n\n return exposedRpcs[serviceName].callStream(methodName, request, options);\n },\n });\n\n const requestedRpcs: Client = {} as Client;\n if (requested) {\n for (const serviceName of Object.keys(requested) as (keyof Client)[]) {\n // Get full service name with the package name without '.' at the beginning.\n const serviceFqn = requested[serviceName].serviceProto.fullName.slice(1);\n\n requestedRpcs[serviceName] = requested[serviceName].createClient(\n {\n call: (method, req, options) => peer.call(`${serviceFqn}.${method}`, req, options),\n callStream: (method, req, options) => peer.callStream(`${serviceFqn}.${method}`, req, options),\n },\n encodingOptions,\n );\n }\n }\n\n return new ProtoRpcPeer(requestedRpcs, peer);\n};\n\nexport const parseMethodName = (method: string): [serviceName: string, methodName: string] => {\n const separator = method.lastIndexOf('.');\n const serviceName = method.slice(0, separator);\n const methodName = method.slice(separator + 1);\n if (serviceName.length === 0 || methodName.length === 0) {\n throw new Error(`Invalid method: ${method}`);\n }\n\n return [serviceName, methodName];\n};\n\n//\n// TODO(burdon): Remove deprecated (only bot factory).\n//\n\n/**\n * Create a type-safe RPC client.\n * @deprecated Use createProtoRpcPeer instead.\n */\nexport const createRpcClient = <S>(\n serviceDef: ServiceDescriptor<S>,\n options: Omit<RpcPeerOptions, 'callHandler'>,\n): ProtoRpcPeer<S> => {\n const peer = new RpcPeer({\n ...options,\n callHandler: () => {\n throw new Error('Requests to client are not supported.');\n },\n });\n\n const client = serviceDef.createClient({\n call: peer.call.bind(peer),\n callStream: peer.callStream.bind(peer),\n });\n\n return new ProtoRpcPeer(client, peer);\n};\n\n/**\n * @deprecated\n */\nexport interface RpcServerOptions<S> extends Omit<RpcPeerOptions, 'callHandler'> {\n service: ServiceDescriptor<S>;\n handlers: S;\n}\n\n/**\n * Create a type-safe RPC server.\n * @deprecated Use createProtoRpcPeer instead.\n */\nexport const createRpcServer = <S>({ service, handlers, ...rest }: RpcServerOptions<S>): RpcPeer => {\n const server = service.createServer(handlers);\n return new RpcPeer({\n ...rest,\n callHandler: server.call.bind(server),\n streamHandler: server.callStream.bind(server),\n });\n};\n\n/**\n * Create type-safe RPC client from a service bundle.\n * @deprecated Use createProtoRpcPeer instead.\n */\nexport const createBundledRpcClient = <S>(\n descriptors: ServiceBundle<S>,\n options: Omit<RpcPeerOptions, 'callHandler' | 'streamHandler'>,\n): ProtoRpcPeer<S> => {\n return createProtoRpcPeer({\n requested: descriptors,\n ...options,\n });\n};\n\n/**\n * @deprecated\n */\nexport interface RpcBundledServerOptions<S> extends Omit<RpcPeerOptions, 'callHandler'> {\n services: ServiceBundle<S>;\n handlers: S;\n}\n\n/**\n * Create type-safe RPC server from a service bundle.\n * @deprecated Use createProtoRpcPeer instead.\n */\n// TODO(burdon): Support late-binding via providers.\nexport const createBundledRpcServer = <S>({ services, handlers, ...rest }: RpcBundledServerOptions<S>): RpcPeer => {\n const rpc: Record<string, ServiceHandler<any>> = {};\n for (const serviceName of Object.keys(services) as (keyof S)[]) {\n // Get full service name with the package name without '.' at the beginning.\n const serviceFqn = services[serviceName].serviceProto.fullName.slice(1);\n rpc[serviceFqn] = services[serviceName].createServer(handlers[serviceName] as any);\n }\n\n return new RpcPeer({\n ...rest,\n\n callHandler: (method, request) => {\n const [serviceName, methodName] = parseMethodName(method);\n if (!rpc[serviceName]) {\n throw new Error(`Service not supported: ${serviceName}`);\n }\n\n return rpc[serviceName].call(methodName, request);\n },\n\n streamHandler: (method, request) => {\n const [serviceName, methodName] = parseMethodName(method);\n if (!rpc[serviceName]) {\n throw new Error(`Service not supported: ${serviceName}`);\n }\n\n return rpc[serviceName].callStream(methodName, request);\n },\n });\n};\n", "//\n// Copyright 2021 DXOS.org\n//\n\nimport { isNode } from '@dxos/util';\n\nimport { type RpcPort } from './rpc';\n\nexport type CreateLinkedPortsOptions = {\n delay?: number;\n};\n\n/**\n * Create bi-directionally linked ports.\n */\nexport const createLinkedPorts = ({ delay }: CreateLinkedPortsOptions = {}): [RpcPort, RpcPort] => {\n let port1Received: RpcPort['send'] | undefined;\n let port2Received: RpcPort['send'] | undefined;\n\n const send = (handler: RpcPort['send'] | undefined, msg: Uint8Array) => {\n if (delay) {\n setTimeout(() => handler?.(msg), delay);\n } else {\n void handler?.(msg);\n }\n };\n\n const port1: RpcPort = {\n send: (msg) => send(port2Received, msg),\n subscribe: (cb) => {\n port1Received = cb;\n },\n };\n\n const port2: RpcPort = {\n send: (msg) => send(port1Received, msg),\n subscribe: (cb) => {\n port2Received = cb;\n },\n };\n\n return [port1, port2];\n};\n\nexport const encodeMessage = (msg: string): Uint8Array => (isNode() ? Buffer.from(msg) : new TextEncoder().encode(msg));\n", "//\n// Copyright 2021 DXOS.org\n//\n\nimport { Event } from '@dxos/async';\nimport { MessageTrace } from '@dxos/protocols/proto/dxos/rpc';\n\nimport { type RpcPort } from './rpc';\n\nexport class PortTracer {\n readonly message = new Event<MessageTrace>();\n\n private readonly _port: RpcPort;\n\n constructor(private readonly _wrappedPort: RpcPort) {\n this._port = {\n send: (msg: Uint8Array) => {\n this.message.emit({\n direction: MessageTrace.Direction.OUTGOING,\n data: msg,\n });\n\n return this._wrappedPort.send(msg);\n },\n subscribe: (cb: (msg: Uint8Array) => void) => {\n return this._wrappedPort.subscribe((msg) => {\n this.message.emit({\n direction: MessageTrace.Direction.INCOMING,\n data: msg,\n });\n cb(msg);\n });\n },\n };\n }\n\n public get port() {\n return this._port;\n }\n}\n"],
5
+ "mappings": ";;;AAIA,SAASA,kBAAkB;AAC3B,SAASC,mBAAmB;AAGrB,IAAMC,iBAAiB,CAACC,KAAoBC,cACjDC,YAAYF,KAAK;EACfG,aAAa;aAAgBF,SAAAA;IAAiB,IAAIG,WAAAA,EAAaC,SAAS,CAAA;AAC1E,CAAA;;;ACPF,SAASC,SAASC,cAAcC,oBAAoB;AACpD,SAAyDC,cAAc;AACvE,SAAuBC,uBAAuB;AAC9C,SAASC,cAAAA,mBAAkB;AAC3B,SAASC,iBAAiB;AAC1B,SAASC,WAAW;AACpB,SAASC,gBAAgBC,iBAAiBC,mBAAmB;AAC7D,SAASC,cAAc;AAEvB,SAASC,kCAAkC;;;;;;;;AAI3C,IAAMC,kBAAkB;AACxB,IAAMC,mBAAmB;AAEzB,IAAMC,cAAc;AAkCpB,IAAMC,gBAAgB;AAStB,IAAMC,oBAAN,MAAMA;;;;EACJ,YACkBC,SACAC,QACAC,QAChB;SAHgBF,UAAAA;SACAC,SAAAA;SACAC,SAAAA;EACf;AACL;AAGA,IAAIC;AACJ,IAAMC,qBAAqB,MAAOD,oBAAoBE,OAAOC,gBAAgB,qBAAA;AAqCtE,IAAMC,UAAN,MAAMA;EACMC;EAEAC,oBAAoB,oBAAIC,IAAAA;EACxBC,gBAAgB,oBAAID,IAAAA;EACpBE,qBAAqB,IAAIC,QAAAA;;;;EAKzBC,kBAAkB,IAAID,QAAAA;;;;EAKtBE,cAAc,IAAIF,QAAAA;EAE3BG,UAAU;EACVC,SAAAA;EACAC,uBAAiDC;EACjDC,qBAA+CD;EAEvD,YAAYE,QAAwB;AAClC,SAAKb,UAAU;MACbc,SAASH;MACTI,eAAeJ;MACfK,aAAa;MACb,GAAGH;IACL;EACF;;;;;;EAOA,MACMI,OAAsB;AAC1B,QAAI,KAAKR,WAAM,WAAuB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MACAO,WAAW,CAACC,OAAAA;AACV,eAAO,KAAKV,aAAaS,UAAU,CAACP,QAAAA;AAClC,eAAKL,QAAQM,KAAK;YAChBC,WAAWC,aAAaC,UAAUK;YAClCH,MAAMN;UACR,CAAA;AACAQ,aAAGR,GAAAA;QACL,CAAA;MACF;IACF;EACF;EAEA,IAAWU,OAAO;AAChB,WAAO,KAAKb;EACd;AACF;",
6
+ "names": ["StackTrace", "decodeError", "decodeRpcError", "err", "rpcMethod", "decodeError", "appendStack", "StackTrace", "getStack", "Trigger", "asyncTimeout", "synchronized", "Stream", "ContextRpcCodec", "StackTrace", "invariant", "log", "RpcClosedError", "RpcNotOpenError", "encodeError", "schema", "exponentialBackoffInterval", "DEFAULT_TIMEOUT", "BYE_SEND_TIMEOUT", "DEBUG_CALLS", "CLOSE_TIMEOUT", "PendingRpcRequest", "resolve", "reject", "stream", "RpcMessageCodec", "getRpcMessageCodec", "schema", "getCodecForType", "RpcPeer", "_params", "_outgoingRequests", "Map", "_localStreams", "_remoteOpenTrigger", "Trigger", "_closingTrigger", "_byeTrigger", "_nextId", "_state", "_unsubscribeFromPort", "undefined", "_clearOpenInterval", "params", "timeout", "streamHandler", "noHandshake", "open", "port", "subscribe", "msg", "_receive", "err", "log", "catch", "wake", "state", "_sendMessage", "exponentialBackoffInterval", "warn", "Promise", "race", "wait", "openAck", "close", "CLOSE_TIMEOUT", "_abortRequests", "bye", "BYE_SEND_TIMEOUT", "_disposeAndClose", "abort", "req", "values", "reject", "RpcClosedError", "clear", "decoded", "getRpcMessageCodec", "decode", "preserveAny", "DEBUG_CALLS", "type", "Object", "keys", "request", "response", "id", "error", "encodeError", "stream", "method", "_callStreamHandler", "payload", "type_url", "_callHandler", "responseId", "invariant", "has", "item", "get", "delete", "resolve", "streamClose", "Error", "call", "options", "throwIfNotOpen", "responseReceived", "set", "PendingRpcRequest", "traceContext", "ctx", "ContextRpcCodec", "encode", "sending", "waiting", "asyncTimeout", "DEFAULT_TIMEOUT", "stack", "split", "slice", "join", "decodeRpcError", "callStream", "Stream", "ready", "next", "onResponse", "streamReady", "StackTrace", "closeStream", "getStack", "message", "send", "_getHandlerRpcOptions", "traceCtx", "handlerRpcOptions", "callHandler", "callback", "responseStream", "onReady", "RpcNotOpenError", "invariant", "createServiceBundle", "services", "ProtoRpcPeer", "rpc", "_peer", "open", "close", "abort", "createProtoRpcPeer", "requested", "exposed", "handlers", "encodingOptions", "rest", "exposedRpcs", "invariant", "serviceName", "Object", "keys", "serviceFqn", "serviceProto", "fullName", "slice", "serviceProvider", "createServer", "peer", "RpcPeer", "callHandler", "method", "request", "options", "methodName", "parseMethodName", "Error", "call", "streamHandler", "callStream", "requestedRpcs", "createClient", "req", "separator", "lastIndexOf", "length", "createRpcClient", "serviceDef", "client", "bind", "createRpcServer", "service", "server", "createBundledRpcClient", "descriptors", "createBundledRpcServer", "isNode", "createLinkedPorts", "delay", "port1Received", "port2Received", "send", "handler", "msg", "setTimeout", "port1", "subscribe", "cb", "port2", "encodeMessage", "isNode", "Buffer", "from", "TextEncoder", "encode", "Event", "MessageTrace", "PortTracer", "message", "Event", "_port", "_wrappedPort", "send", "msg", "emit", "direction", "MessageTrace", "Direction", "OUTGOING", "data", "subscribe", "cb", "INCOMING", "port"]
7
+ }