@dxos/rpc 0.5.1-main.ad6ccc9 → 0.5.1-main.af17cdd

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.
@@ -39,6 +39,7 @@ function _ts_decorate(decorators, target, key, desc) {
39
39
  var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/rpc/src/rpc.ts";
40
40
  var DEFAULT_TIMEOUT = 3e3;
41
41
  var BYE_SEND_TIMEOUT = 2e3;
42
+ var DEBUG_CALLS = true;
42
43
  var CLOSE_TIMEOUT = 3e3;
43
44
  var PendingRpcRequest = class {
44
45
  constructor(resolve, reject, stream) {
@@ -95,7 +96,7 @@ var RpcPeer = class {
95
96
  } catch (err) {
96
97
  log.catch(err, void 0, {
97
98
  F: __dxlog_file,
98
- L: 146,
99
+ L: 153,
99
100
  S: this,
100
101
  C: (f, a) => f(...a)
101
102
  });
@@ -107,9 +108,11 @@ var RpcPeer = class {
107
108
  this._remoteOpenTrigger.wake();
108
109
  return;
109
110
  }
110
- log("sending open message", void 0, {
111
+ log("sending open message", {
112
+ state: this._state
113
+ }, {
111
114
  F: __dxlog_file,
112
- L: 158,
115
+ L: 165,
113
116
  S: this,
114
117
  C: (f, a) => f(...a)
115
118
  });
@@ -124,7 +127,7 @@ var RpcPeer = class {
124
127
  open: true
125
128
  }).catch((err) => log.warn(err, void 0, {
126
129
  F: __dxlog_file,
127
- L: 167,
130
+ L: 174,
128
131
  S: this,
129
132
  C: (f, a) => f(...a)
130
133
  }));
@@ -134,13 +137,14 @@ var RpcPeer = class {
134
137
  this._closingTrigger.wait()
135
138
  ]);
136
139
  this._clearOpenInterval?.();
137
- this._state = "OPENED";
138
140
  if (this._state !== "OPENED") {
139
141
  return;
140
142
  }
141
- log("sending second open message", void 0, {
143
+ log("sending second open message", {
144
+ state: this._state
145
+ }, {
142
146
  F: __dxlog_file,
143
- L: 182,
147
+ L: 188,
144
148
  S: this,
145
149
  C: (f, a) => f(...a)
146
150
  });
@@ -170,7 +174,7 @@ var RpcPeer = class {
170
174
  err
171
175
  }, {
172
176
  F: __dxlog_file,
173
- L: 204,
177
+ L: 210,
174
178
  S: this,
175
179
  C: (f, a) => f(...a)
176
180
  });
@@ -178,7 +182,7 @@ var RpcPeer = class {
178
182
  try {
179
183
  log("closing waiting on bye", void 0, {
180
184
  F: __dxlog_file,
181
- L: 207,
185
+ L: 213,
182
186
  S: this,
183
187
  C: (f, a) => f(...a)
184
188
  });
@@ -190,7 +194,7 @@ var RpcPeer = class {
190
194
  err
191
195
  }, {
192
196
  F: __dxlog_file,
193
- L: 210,
197
+ L: 216,
194
198
  S: this,
195
199
  C: (f, a) => f(...a)
196
200
  });
@@ -230,11 +234,11 @@ var RpcPeer = class {
230
234
  const decoded = RpcMessage.decode(msg, {
231
235
  preserveAny: true
232
236
  });
233
- log("received message", {
237
+ DEBUG_CALLS && log("received message", {
234
238
  type: Object.keys(decoded)[0]
235
239
  }, {
236
240
  F: __dxlog_file,
237
- L: 254,
241
+ L: 260,
238
242
  S: this,
239
243
  C: (f, a) => f(...a)
240
244
  });
@@ -242,7 +246,7 @@ var RpcPeer = class {
242
246
  if (this._state !== "OPENED" && this._state !== "OPENING") {
243
247
  log("received request while closed", void 0, {
244
248
  F: __dxlog_file,
245
- L: 258,
249
+ L: 264,
246
250
  S: this,
247
251
  C: (f, a) => f(...a)
248
252
  });
@@ -260,7 +264,7 @@ var RpcPeer = class {
260
264
  method: req.method
261
265
  }, {
262
266
  F: __dxlog_file,
263
- L: 270,
267
+ L: 276,
264
268
  S: this,
265
269
  C: (f, a) => f(...a)
266
270
  });
@@ -272,7 +276,7 @@ var RpcPeer = class {
272
276
  close: response.close
273
277
  }, {
274
278
  F: __dxlog_file,
275
- L: 272,
279
+ L: 278,
276
280
  S: this,
277
281
  C: (f, a) => f(...a)
278
282
  });
@@ -281,29 +285,29 @@ var RpcPeer = class {
281
285
  }).catch((err) => {
282
286
  log.warn("failed during close", err, {
283
287
  F: __dxlog_file,
284
- L: 280,
288
+ L: 286,
285
289
  S: this,
286
290
  C: (f, a) => f(...a)
287
291
  });
288
292
  });
289
293
  });
290
294
  } else {
291
- log("request", {
295
+ DEBUG_CALLS && log("request", {
292
296
  method: req.method
293
297
  }, {
294
298
  F: __dxlog_file,
295
- L: 284,
299
+ L: 290,
296
300
  S: this,
297
301
  C: (f, a) => f(...a)
298
302
  });
299
303
  const response = await this._callHandler(req);
300
- log("sending response", {
304
+ DEBUG_CALLS && log("sending response", {
301
305
  method: req.method,
302
306
  response: response.payload?.type_url,
303
307
  error: response.error
304
308
  }, {
305
309
  F: __dxlog_file,
306
- L: 287,
310
+ L: 293,
307
311
  S: this,
308
312
  C: (f, a) => f(...a)
309
313
  });
@@ -315,7 +319,7 @@ var RpcPeer = class {
315
319
  if (this._state !== "OPENED") {
316
320
  log("received response while closed", void 0, {
317
321
  F: __dxlog_file,
318
- L: 296,
322
+ L: 302,
319
323
  S: this,
320
324
  C: (f, a) => f(...a)
321
325
  });
@@ -324,7 +328,7 @@ var RpcPeer = class {
324
328
  const responseId = decoded.response.id;
325
329
  invariant(typeof responseId === "number", void 0, {
326
330
  F: __dxlog_file,
327
- L: 301,
331
+ L: 307,
328
332
  S: this,
329
333
  A: [
330
334
  "typeof responseId === 'number'",
@@ -336,7 +340,7 @@ var RpcPeer = class {
336
340
  responseId
337
341
  }, {
338
342
  F: __dxlog_file,
339
- L: 303,
343
+ L: 309,
340
344
  S: this,
341
345
  C: (f, a) => f(...a)
342
346
  });
@@ -346,19 +350,21 @@ var RpcPeer = class {
346
350
  if (!item.stream) {
347
351
  this._outgoingRequests.delete(responseId);
348
352
  }
349
- log("response", {
353
+ DEBUG_CALLS && log("response", {
350
354
  type_url: decoded.response.payload?.type_url
351
355
  }, {
352
356
  F: __dxlog_file,
353
- L: 313,
357
+ L: 319,
354
358
  S: this,
355
359
  C: (f, a) => f(...a)
356
360
  });
357
361
  item.resolve(decoded.response);
358
362
  } else if (decoded.open) {
359
- log("received open message", void 0, {
363
+ log("received open message", {
364
+ state: this._state
365
+ }, {
360
366
  F: __dxlog_file,
361
- L: 316,
367
+ L: 322,
362
368
  S: this,
363
369
  C: (f, a) => f(...a)
364
370
  });
@@ -369,21 +375,24 @@ var RpcPeer = class {
369
375
  openAck: true
370
376
  });
371
377
  } else if (decoded.openAck) {
372
- log("received openAck message", void 0, {
378
+ log("received openAck message", {
379
+ state: this._state
380
+ }, {
373
381
  F: __dxlog_file,
374
- L: 323,
382
+ L: 329,
375
383
  S: this,
376
384
  C: (f, a) => f(...a)
377
385
  });
378
386
  if (this._params.noHandshake) {
379
387
  return;
380
388
  }
389
+ this._state = "OPENED";
381
390
  this._remoteOpenTrigger.wake();
382
391
  } else if (decoded.streamClose) {
383
392
  if (this._state !== "OPENED") {
384
393
  log("received stream close while closed", void 0, {
385
394
  F: __dxlog_file,
386
- L: 331,
395
+ L: 338,
387
396
  S: this,
388
397
  C: (f, a) => f(...a)
389
398
  });
@@ -393,13 +402,13 @@ var RpcPeer = class {
393
402
  id: decoded.streamClose.id
394
403
  }, {
395
404
  F: __dxlog_file,
396
- L: 335,
405
+ L: 342,
397
406
  S: this,
398
407
  C: (f, a) => f(...a)
399
408
  });
400
409
  invariant(typeof decoded.streamClose.id === "number", void 0, {
401
410
  F: __dxlog_file,
402
- L: 336,
411
+ L: 343,
403
412
  S: this,
404
413
  A: [
405
414
  "typeof decoded.streamClose.id === 'number'",
@@ -412,7 +421,7 @@ var RpcPeer = class {
412
421
  id: decoded.streamClose.id
413
422
  }, {
414
423
  F: __dxlog_file,
415
- L: 339,
424
+ L: 346,
416
425
  S: this,
417
426
  C: (f, a) => f(...a)
418
427
  });
@@ -425,7 +434,7 @@ var RpcPeer = class {
425
434
  if (this._state !== "CLOSING" && this._state !== "CLOSED") {
426
435
  log("replying to bye", void 0, {
427
436
  F: __dxlog_file,
428
- L: 349,
437
+ L: 356,
429
438
  S: this,
430
439
  C: (f, a) => f(...a)
431
440
  });
@@ -441,7 +450,7 @@ var RpcPeer = class {
441
450
  msg
442
451
  }, {
443
452
  F: __dxlog_file,
444
- L: 357,
453
+ L: 364,
445
454
  S: this,
446
455
  C: (f, a) => f(...a)
447
456
  });
@@ -453,11 +462,11 @@ var RpcPeer = class {
453
462
  * Peer should be open before making this call.
454
463
  */
455
464
  async call(method, request, options) {
456
- log("calling", {
465
+ DEBUG_CALLS && log("calling", {
457
466
  method
458
467
  }, {
459
468
  F: __dxlog_file,
460
- L: 367,
469
+ L: 374,
461
470
  S: this,
462
471
  C: (f, a) => f(...a)
463
472
  });
@@ -484,7 +493,7 @@ var RpcPeer = class {
484
493
  response = await waiting;
485
494
  invariant(response.id === id, void 0, {
486
495
  F: __dxlog_file,
487
- L: 392,
496
+ L: 399,
488
497
  S: this,
489
498
  A: [
490
499
  "response.id === id",
@@ -563,7 +572,7 @@ ${stack.getStack()}`;
563
572
  }).catch((err) => {
564
573
  log.catch(err, void 0, {
565
574
  F: __dxlog_file,
566
- L: 465,
575
+ L: 472,
567
576
  S: this,
568
577
  C: (f, a) => f(...a)
569
578
  });
@@ -572,11 +581,11 @@ ${stack.getStack()}`;
572
581
  });
573
582
  }
574
583
  async _sendMessage(message, timeout) {
575
- log("sending message", {
584
+ DEBUG_CALLS && log("sending message", {
576
585
  type: Object.keys(message)[0]
577
586
  }, {
578
587
  F: __dxlog_file,
579
- L: 472,
588
+ L: 479,
580
589
  S: this,
581
590
  C: (f, a) => f(...a)
582
591
  });
@@ -588,7 +597,7 @@ ${stack.getStack()}`;
588
597
  try {
589
598
  invariant(typeof req.id === "number", void 0, {
590
599
  F: __dxlog_file,
591
- L: 478,
600
+ L: 485,
592
601
  S: this,
593
602
  A: [
594
603
  "typeof req.id === 'number'",
@@ -597,7 +606,7 @@ ${stack.getStack()}`;
597
606
  });
598
607
  invariant(req.payload, void 0, {
599
608
  F: __dxlog_file,
600
- L: 479,
609
+ L: 486,
601
610
  S: this,
602
611
  A: [
603
612
  "req.payload",
@@ -606,14 +615,14 @@ ${stack.getStack()}`;
606
615
  });
607
616
  invariant(req.method, void 0, {
608
617
  F: __dxlog_file,
609
- L: 480,
618
+ L: 487,
610
619
  S: this,
611
620
  A: [
612
621
  "req.method",
613
622
  ""
614
623
  ]
615
624
  });
616
- const response = await this._params.callHandler(req.method, req.payload);
625
+ const response = await this._params.callHandler(req.method, req.payload, this._params.handlerRpcOptions);
617
626
  return {
618
627
  id: req.id,
619
628
  payload: response
@@ -629,7 +638,7 @@ ${stack.getStack()}`;
629
638
  try {
630
639
  invariant(this._params.streamHandler, "Requests with streaming responses are not supported.", {
631
640
  F: __dxlog_file,
632
- L: 497,
641
+ L: 504,
633
642
  S: this,
634
643
  A: [
635
644
  "this._params.streamHandler",
@@ -638,7 +647,7 @@ ${stack.getStack()}`;
638
647
  });
639
648
  invariant(typeof req.id === "number", void 0, {
640
649
  F: __dxlog_file,
641
- L: 498,
650
+ L: 505,
642
651
  S: this,
643
652
  A: [
644
653
  "typeof req.id === 'number'",
@@ -647,7 +656,7 @@ ${stack.getStack()}`;
647
656
  });
648
657
  invariant(req.payload, void 0, {
649
658
  F: __dxlog_file,
650
- L: 499,
659
+ L: 506,
651
660
  S: this,
652
661
  A: [
653
662
  "req.payload",
@@ -656,14 +665,14 @@ ${stack.getStack()}`;
656
665
  });
657
666
  invariant(req.method, void 0, {
658
667
  F: __dxlog_file,
659
- L: 500,
668
+ L: 507,
660
669
  S: this,
661
670
  A: [
662
671
  "req.method",
663
672
  ""
664
673
  ]
665
674
  });
666
- const responseStream = this._params.streamHandler(req.method, req.payload);
675
+ const responseStream = this._params.streamHandler(req.method, req.payload, this._params.handlerRpcOptions);
667
676
  responseStream.onReady(() => {
668
677
  callback({
669
678
  id: req.id,
@@ -753,19 +762,19 @@ var createProtoRpcPeer = ({ requested, exposed, handlers, encodingOptions, ...re
753
762
  }
754
763
  const peer = new RpcPeer({
755
764
  ...rest,
756
- callHandler: (method, request) => {
765
+ callHandler: (method, request, options) => {
757
766
  const [serviceName, methodName] = parseMethodName(method);
758
767
  if (!exposedRpcs[serviceName]) {
759
768
  throw new Error(`Service not supported: ${serviceName}`);
760
769
  }
761
- return exposedRpcs[serviceName].call(methodName, request);
770
+ return exposedRpcs[serviceName].call(methodName, request, options);
762
771
  },
763
- streamHandler: (method, request) => {
772
+ streamHandler: (method, request, options) => {
764
773
  const [serviceName, methodName] = parseMethodName(method);
765
774
  if (!exposedRpcs[serviceName]) {
766
775
  throw new Error(`Service not supported: ${serviceName}`);
767
776
  }
768
- return exposedRpcs[serviceName].callStream(methodName, request);
777
+ return exposedRpcs[serviceName].callStream(methodName, request, options);
769
778
  }
770
779
  });
771
780
  const requestedRpcs = {};
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/rpc.ts", "../../../src/errors.ts", "../../../src/service.ts", "../../../src/testing.ts", "../../../src/trace.ts"],
4
- "sourcesContent": ["//\n// Copyright 2021 DXOS.org\n//\n\nimport { asyncTimeout, synchronized, Trigger } from '@dxos/async';\nimport { type Any, Stream, type RequestOptions } from '@dxos/codec-protobuf';\nimport { StackTrace } from '@dxos/debug';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\nimport { encodeError, RpcClosedError, RpcNotOpenError, schema } from '@dxos/protocols';\nimport { type Request, type Response, RpcMessage } from '@dxos/protocols/proto/dxos/rpc';\nimport { exponentialBackoffInterval } from '@dxos/util';\n\nimport { decodeRpcError } from './errors';\n\nconst DEFAULT_TIMEOUT = 3_000;\nconst BYE_SEND_TIMEOUT = 2_000;\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) => MaybePromise<Any>;\n streamHandler?: (method: string, request: Any) => Stream<Any>;\n\n /**\n * Do not require or send handshake messages.\n */\n noHandshake?: boolean;\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\nconst RpcMessage = 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.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() {\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');\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 this._state = RpcState.OPENED;\n\n if (this._state !== 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('sending second open message');\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 = {}) {\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() {\n if (this._state === RpcState.CLOSED) {\n return;\n }\n\n this._abortRequests();\n this._disposeAndClose();\n }\n\n private _abortRequests() {\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() {\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 = RpcMessage.decode(msg, { preserveAny: true });\n 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 log('request', { method: req.method });\n const response = await this._callHandler(req);\n\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 log('response', { type_url: decoded.response.payload?.type_url });\n item.resolve(decoded.response);\n } else if (decoded.open) {\n log('received open message');\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');\n if (this._params.noHandshake) {\n return;\n }\n\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 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 // Send request call.\n const sending = this._sendMessage({\n request: {\n id,\n method,\n payload: request,\n stream: false,\n },\n });\n\n // Wait until send completes or throws an error (or response throws a timeout), the resume waiting.\n const waiting = asyncTimeout<any>(responseReceived, options?.timeout ?? this._params.timeout ?? DEFAULT_TIMEOUT);\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 this._sendMessage({\n request: {\n id,\n method,\n payload: request,\n stream: true,\n },\n }).catch((err) => {\n close(err);\n });\n\n return () => {\n this._sendMessage({\n streamClose: { id },\n }).catch((err) => {\n log.catch(err);\n });\n };\n });\n }\n\n private async _sendMessage(message: RpcMessage, timeout?: number) {\n log('sending message', { type: Object.keys(message)[0] });\n await this._params.port.send(RpcMessage.encode(message, { preserveAny: true }), timeout);\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);\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) {\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);\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 { 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 {\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() {\n await this._peer.open();\n }\n\n async close() {\n await this._peer.close();\n }\n\n async abort() {\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) => {\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);\n },\n\n streamHandler: (method, request) => {\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);\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 { 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", "//\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,cAAcC,cAAcC,eAAe;AACpD,SAAmBC,cAAmC;AACtD,SAASC,cAAAA,mBAAkB;AAC3B,SAASC,iBAAiB;AAC1B,SAASC,WAAW;AACpB,SAASC,aAAaC,gBAAgBC,iBAAiBC,cAAc;AAErE,SAASC,kCAAkC;;;ACP3C,SAASC,kBAAkB;AAC3B,SAASC,mBAAmB;AAGrB,IAAMC,iBAAiB,CAACC,KAAoBC,cACjDC,YAAYF,KAAK;EACfG,aAAa;aAAgBF,SAAAA;IAAiB,IAAIG,WAAAA,EAAaC,SAAS,CAAA;AAC1E,CAAA;;;;;;;;;;;;;;ADIF,IAAMC,kBAAkB;AACxB,IAAMC,mBAAmB;AA6BzB,IAAMC,gBAAgB;AAStB,IAAM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CAACE,QAAQF,KAAKF,eAAeI,GAAAA;IACnCG,WAAW,CAACC,OAAAA;AACVP,sBAAgBO;IAClB;EACF;AAEA,SAAO;IAACF;IAAOG;;AACjB;;;ACpCA,SAASC,aAAa;AACtB,SAASC,oBAAoB;AAItB,IAAMC,aAAN,MAAMA;EAKXC,YAA6BC,cAAuB;SAAvBA,eAAAA;SAJpBC,UAAU,IAAIC,MAAAA;AAKrB,SAAKC,QAAQ;MACXC,MAAM,CAACC,QAAAA;AACL,aAAKJ,QAAQK,KAAK;UAChBC,WAAWC,aAAaC,UAAUC;UAClCC,MAAMN;QACR,CAAA;AAEA,eAAO,KAAKL,aAAaI,KAAKC,GAAAA;MAChC;MACAO,WAAW,CAACC,OAAAA;AACV,eAAO,KAAKb,aAAaY,UAAU,CAACP,QAAAA;AAClC,eAAKJ,QAAQK,KAAK;YAChBC,WAAWC,aAAaC,UAAUK;YAClCH,MAAMN;UACR,CAAA;AACAQ,aAAGR,GAAAA;QACL,CAAA;MACF;IACF;EACF;EAEA,IAAWU,OAAO;AAChB,WAAO,KAAKZ;EACd;AACF;",
6
- "names": ["asyncTimeout", "synchronized", "Trigger", "Stream", "StackTrace", "invariant", "log", "encodeError", "RpcClosedError", "RpcNotOpenError", "schema", "exponentialBackoffInterval", "StackTrace", "decodeError", "decodeRpcError", "err", "rpcMethod", "decodeError", "appendStack", "StackTrace", "getStack", "DEFAULT_TIMEOUT", "BYE_SEND_TIMEOUT", "CLOSE_TIMEOUT", "PendingRpcRequest", "constructor", "resolve", "reject", "stream", "RpcMessage", "schema", "getCodecForType", "RpcState", "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", "_sendMessage", "exponentialBackoffInterval", "warn", "Promise", "race", "wait", "openAck", "close", "_abortRequests", "bye", "_disposeAndClose", "abort", "req", "values", "RpcClosedError", "clear", "decoded", "decode", "preserveAny", "type", "Object", "keys", "request", "response", "id", "error", "encodeError", "method", "_callStreamHandler", "payload", "type_url", "_callHandler", "responseId", "invariant", "has", "item", "get", "delete", "streamClose", "Error", "call", "options", "throwIfNotOpen", "responseReceived", "set", "sending", "waiting", "asyncTimeout", "stack", "split", "slice", "join", "decodeRpcError", "callStream", "Stream", "ready", "next", "onResponse", "streamReady", "StackTrace", "closeStream", "getStack", "message", "send", "encode", "callHandler", "callback", "responseStream", "onReady", "synchronized", "state", "RpcNotOpenError", "invariant", "createServiceBundle", "services", "ProtoRpcPeer", "constructor", "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", "methodName", "parseMethodName", "Error", "call", "streamHandler", "callStream", "requestedRpcs", "createClient", "req", "options", "separator", "lastIndexOf", "length", "createRpcClient", "serviceDef", "client", "bind", "createRpcServer", "service", "server", "createBundledRpcClient", "descriptors", "createBundledRpcServer", "createLinkedPorts", "delay", "port1Received", "port2Received", "send", "handler", "msg", "setTimeout", "port1", "subscribe", "cb", "port2", "Event", "MessageTrace", "PortTracer", "constructor", "_wrappedPort", "message", "Event", "_port", "send", "msg", "emit", "direction", "MessageTrace", "Direction", "OUTGOING", "data", "subscribe", "cb", "INCOMING", "port"]
4
+ "sourcesContent": ["//\n// Copyright 2021 DXOS.org\n//\n\nimport { asyncTimeout, synchronized, Trigger } from '@dxos/async';\nimport { type Any, Stream, type RequestOptions } from '@dxos/codec-protobuf';\nimport { StackTrace } from '@dxos/debug';\nimport { invariant } from '@dxos/invariant';\nimport { log } from '@dxos/log';\nimport { encodeError, RpcClosedError, RpcNotOpenError, schema } from '@dxos/protocols';\nimport { type Request, type Response, RpcMessage } from '@dxos/protocols/proto/dxos/rpc';\nimport { exponentialBackoffInterval } from '@dxos/util';\n\nimport { decodeRpcError } from './errors';\n\nconst DEFAULT_TIMEOUT = 3_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\nconst RpcMessage = 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() {\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('sending second 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 = {}) {\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() {\n if (this._state === RpcState.CLOSED) {\n return;\n }\n\n this._abortRequests();\n this._disposeAndClose();\n }\n\n private _abortRequests() {\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() {\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 = RpcMessage.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('request', { 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 // Send request call.\n const sending = this._sendMessage({\n request: {\n id,\n method,\n payload: request,\n stream: false,\n },\n });\n\n // Wait until send completes or throws an error (or response throws a timeout), the resume waiting.\n const waiting = asyncTimeout<any>(responseReceived, options?.timeout ?? this._params.timeout ?? DEFAULT_TIMEOUT);\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 this._sendMessage({\n request: {\n id,\n method,\n payload: request,\n stream: true,\n },\n }).catch((err) => {\n close(err);\n });\n\n return () => {\n this._sendMessage({\n streamClose: { id },\n }).catch((err) => {\n log.catch(err);\n });\n };\n });\n }\n\n private async _sendMessage(message: RpcMessage, timeout?: number) {\n DEBUG_CALLS && log('sending message', { type: Object.keys(message)[0] });\n await this._params.port.send(RpcMessage.encode(message, { preserveAny: true }), timeout);\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._params.handlerRpcOptions);\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) {\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._params.handlerRpcOptions);\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 { 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 {\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() {\n await this._peer.open();\n }\n\n async close() {\n await this._peer.close();\n }\n\n async abort() {\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 { 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", "//\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,cAAcC,cAAcC,eAAe;AACpD,SAAmBC,cAAmC;AACtD,SAASC,cAAAA,mBAAkB;AAC3B,SAASC,iBAAiB;AAC1B,SAASC,WAAW;AACpB,SAASC,aAAaC,gBAAgBC,iBAAiBC,cAAc;AAErE,SAASC,kCAAkC;;;ACP3C,SAASC,kBAAkB;AAC3B,SAASC,mBAAmB;AAGrB,IAAMC,iBAAiB,CAACC,KAAoBC,cACjDC,YAAYF,KAAK;EACfG,aAAa;aAAgBF,SAAAA;IAAiB,IAAIG,WAAAA,EAAaC,SAAS,CAAA;AAC1E,CAAA;;;;;;;;;;;;;;ADIF,IAAMC,kBAAkB;AACxB,IAAMC,mBAAmB;AAEzB,IAAMC,cAAc;AAkCpB,IAAMC,gBAAgB;AAStB,IAAMC,oBAAN,MAAMA;EACJC,YACkBC,SACAC,QACAC,QAChB;SAHgBF,UAAAA;SACAC,SAAAA;SACAC,SAAAA;EACf;AACL;AAEA,IAAMC,aAAaC,OAAOC,gBAAgB,qBAAA;;UAErCC,WAAAA;;;;AAWF,EAAAA,UAAA,SAAA,IAAA;AAMA,EAAAA,UAAA,QAAA,IAAA;GAjBEA,aAAAA,WAAAA,CAAAA,EAAAA;AAmCE,IAAMC,UAAN,MAAMA;EAsBXR,YAAYS,QAAwB;AAnBnBC,6BAAoB,oBAAIC,IAAAA;AACxBC,yBAAgB,oBAAID,IAAAA;AACpBE,8BAAqB,IAAIC,QAAAA;AAKzBC;;;2BAAkB,IAAID,QAAAA;AAKtBE;;;uBAAc,IAAIF,QAAAA;AAE3BG,mBAAU;A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BC,UAAU,IAAIC,MAAAA;AAKrB,SAAKC,QAAQ;MACXC,MAAM,CAACC,QAAAA;AACL,aAAKJ,QAAQK,KAAK;UAChBC,WAAWC,aAAaC,UAAUC;UAClCC,MAAMN;QACR,CAAA;AAEA,eAAO,KAAKL,aAAaI,KAAKC,GAAAA;MAChC;MACAO,WAAW,CAACC,OAAAA;AACV,eAAO,KAAKb,aAAaY,UAAU,CAACP,QAAAA;AAClC,eAAKJ,QAAQK,KAAK;YAChBC,WAAWC,aAAaC,UAAUK;YAClCH,MAAMN;UACR,CAAA;AACAQ,aAAGR,GAAAA;QACL,CAAA;MACF;IACF;EACF;EAEA,IAAWU,OAAO;AAChB,WAAO,KAAKZ;EACd;AACF;",
6
+ "names": ["asyncTimeout", "synchronized", "Trigger", "Stream", "StackTrace", "invariant", "log", "encodeError", "RpcClosedError", "RpcNotOpenError", "schema", "exponentialBackoffInterval", "StackTrace", "decodeError", "decodeRpcError", "err", "rpcMethod", "decodeError", "appendStack", "StackTrace", "getStack", "DEFAULT_TIMEOUT", "BYE_SEND_TIMEOUT", "DEBUG_CALLS", "CLOSE_TIMEOUT", "PendingRpcRequest", "constructor", "resolve", "reject", "stream", "RpcMessage", "schema", "getCodecForType", "RpcState", "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", "_abortRequests", "bye", "_disposeAndClose", "abort", "req", "values", "RpcClosedError", "clear", "decoded", "decode", "preserveAny", "type", "Object", "keys", "request", "response", "id", "error", "encodeError", "method", "_callStreamHandler", "payload", "type_url", "_callHandler", "responseId", "invariant", "has", "item", "get", "delete", "streamClose", "Error", "call", "options", "throwIfNotOpen", "responseReceived", "set", "sending", "waiting", "asyncTimeout", "stack", "split", "slice", "join", "decodeRpcError", "callStream", "Stream", "ready", "next", "onResponse", "streamReady", "StackTrace", "closeStream", "getStack", "message", "send", "encode", "callHandler", "handlerRpcOptions", "callback", "responseStream", "onReady", "synchronized", "RpcNotOpenError", "invariant", "createServiceBundle", "services", "ProtoRpcPeer", "constructor", "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", "createLinkedPorts", "delay", "port1Received", "port2Received", "send", "handler", "msg", "setTimeout", "port1", "subscribe", "cb", "port2", "Event", "MessageTrace", "PortTracer", "constructor", "_wrappedPort", "message", "Event", "_port", "send", "msg", "emit", "direction", "MessageTrace", "Direction", "OUTGOING", "data", "subscribe", "cb", "INCOMING", "port"]
7
7
  }