@dxos/rpc 0.5.1-next.bb5476b → 0.5.1-next.d0efa9a

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.
@@ -113,7 +113,7 @@ var RpcPeer = class {
113
113
  } catch (err) {
114
114
  import_log.log.catch(err, void 0, {
115
115
  F: __dxlog_file,
116
- L: 148,
116
+ L: 153,
117
117
  S: this,
118
118
  C: (f, a) => f(...a)
119
119
  });
@@ -129,7 +129,7 @@ var RpcPeer = class {
129
129
  state: this._state
130
130
  }, {
131
131
  F: __dxlog_file,
132
- L: 160,
132
+ L: 165,
133
133
  S: this,
134
134
  C: (f, a) => f(...a)
135
135
  });
@@ -144,7 +144,7 @@ var RpcPeer = class {
144
144
  open: true
145
145
  }).catch((err) => import_log.log.warn(err, void 0, {
146
146
  F: __dxlog_file,
147
- L: 169,
147
+ L: 174,
148
148
  S: this,
149
149
  C: (f, a) => f(...a)
150
150
  }));
@@ -161,7 +161,7 @@ var RpcPeer = class {
161
161
  state: this._state
162
162
  }, {
163
163
  F: __dxlog_file,
164
- L: 183,
164
+ L: 188,
165
165
  S: this,
166
166
  C: (f, a) => f(...a)
167
167
  });
@@ -191,7 +191,7 @@ var RpcPeer = class {
191
191
  err
192
192
  }, {
193
193
  F: __dxlog_file,
194
- L: 205,
194
+ L: 210,
195
195
  S: this,
196
196
  C: (f, a) => f(...a)
197
197
  });
@@ -199,7 +199,7 @@ var RpcPeer = class {
199
199
  try {
200
200
  (0, import_log.log)("closing waiting on bye", void 0, {
201
201
  F: __dxlog_file,
202
- L: 208,
202
+ L: 213,
203
203
  S: this,
204
204
  C: (f, a) => f(...a)
205
205
  });
@@ -211,7 +211,7 @@ var RpcPeer = class {
211
211
  err
212
212
  }, {
213
213
  F: __dxlog_file,
214
- L: 211,
214
+ L: 216,
215
215
  S: this,
216
216
  C: (f, a) => f(...a)
217
217
  });
@@ -255,7 +255,7 @@ var RpcPeer = class {
255
255
  type: Object.keys(decoded)[0]
256
256
  }, {
257
257
  F: __dxlog_file,
258
- L: 255,
258
+ L: 260,
259
259
  S: this,
260
260
  C: (f, a) => f(...a)
261
261
  });
@@ -263,7 +263,7 @@ var RpcPeer = class {
263
263
  if (this._state !== "OPENED" && this._state !== "OPENING") {
264
264
  (0, import_log.log)("received request while closed", void 0, {
265
265
  F: __dxlog_file,
266
- L: 259,
266
+ L: 264,
267
267
  S: this,
268
268
  C: (f, a) => f(...a)
269
269
  });
@@ -281,7 +281,7 @@ var RpcPeer = class {
281
281
  method: req.method
282
282
  }, {
283
283
  F: __dxlog_file,
284
- L: 271,
284
+ L: 276,
285
285
  S: this,
286
286
  C: (f, a) => f(...a)
287
287
  });
@@ -293,7 +293,7 @@ var RpcPeer = class {
293
293
  close: response.close
294
294
  }, {
295
295
  F: __dxlog_file,
296
- L: 273,
296
+ L: 278,
297
297
  S: this,
298
298
  C: (f, a) => f(...a)
299
299
  });
@@ -302,7 +302,7 @@ var RpcPeer = class {
302
302
  }).catch((err) => {
303
303
  import_log.log.warn("failed during close", err, {
304
304
  F: __dxlog_file,
305
- L: 281,
305
+ L: 286,
306
306
  S: this,
307
307
  C: (f, a) => f(...a)
308
308
  });
@@ -313,7 +313,7 @@ var RpcPeer = class {
313
313
  method: req.method
314
314
  }, {
315
315
  F: __dxlog_file,
316
- L: 285,
316
+ L: 290,
317
317
  S: this,
318
318
  C: (f, a) => f(...a)
319
319
  });
@@ -324,7 +324,7 @@ var RpcPeer = class {
324
324
  error: response.error
325
325
  }, {
326
326
  F: __dxlog_file,
327
- L: 288,
327
+ L: 293,
328
328
  S: this,
329
329
  C: (f, a) => f(...a)
330
330
  });
@@ -336,7 +336,7 @@ var RpcPeer = class {
336
336
  if (this._state !== "OPENED") {
337
337
  (0, import_log.log)("received response while closed", void 0, {
338
338
  F: __dxlog_file,
339
- L: 297,
339
+ L: 302,
340
340
  S: this,
341
341
  C: (f, a) => f(...a)
342
342
  });
@@ -345,7 +345,7 @@ var RpcPeer = class {
345
345
  const responseId = decoded.response.id;
346
346
  (0, import_invariant.invariant)(typeof responseId === "number", void 0, {
347
347
  F: __dxlog_file,
348
- L: 302,
348
+ L: 307,
349
349
  S: this,
350
350
  A: [
351
351
  "typeof responseId === 'number'",
@@ -357,7 +357,7 @@ var RpcPeer = class {
357
357
  responseId
358
358
  }, {
359
359
  F: __dxlog_file,
360
- L: 304,
360
+ L: 309,
361
361
  S: this,
362
362
  C: (f, a) => f(...a)
363
363
  });
@@ -371,7 +371,7 @@ var RpcPeer = class {
371
371
  type_url: decoded.response.payload?.type_url
372
372
  }, {
373
373
  F: __dxlog_file,
374
- L: 314,
374
+ L: 319,
375
375
  S: this,
376
376
  C: (f, a) => f(...a)
377
377
  });
@@ -381,7 +381,7 @@ var RpcPeer = class {
381
381
  state: this._state
382
382
  }, {
383
383
  F: __dxlog_file,
384
- L: 317,
384
+ L: 322,
385
385
  S: this,
386
386
  C: (f, a) => f(...a)
387
387
  });
@@ -396,7 +396,7 @@ var RpcPeer = class {
396
396
  state: this._state
397
397
  }, {
398
398
  F: __dxlog_file,
399
- L: 324,
399
+ L: 329,
400
400
  S: this,
401
401
  C: (f, a) => f(...a)
402
402
  });
@@ -409,7 +409,7 @@ var RpcPeer = class {
409
409
  if (this._state !== "OPENED") {
410
410
  (0, import_log.log)("received stream close while closed", void 0, {
411
411
  F: __dxlog_file,
412
- L: 333,
412
+ L: 338,
413
413
  S: this,
414
414
  C: (f, a) => f(...a)
415
415
  });
@@ -419,13 +419,13 @@ var RpcPeer = class {
419
419
  id: decoded.streamClose.id
420
420
  }, {
421
421
  F: __dxlog_file,
422
- L: 337,
422
+ L: 342,
423
423
  S: this,
424
424
  C: (f, a) => f(...a)
425
425
  });
426
426
  (0, import_invariant.invariant)(typeof decoded.streamClose.id === "number", void 0, {
427
427
  F: __dxlog_file,
428
- L: 338,
428
+ L: 343,
429
429
  S: this,
430
430
  A: [
431
431
  "typeof decoded.streamClose.id === 'number'",
@@ -438,7 +438,7 @@ var RpcPeer = class {
438
438
  id: decoded.streamClose.id
439
439
  }, {
440
440
  F: __dxlog_file,
441
- L: 341,
441
+ L: 346,
442
442
  S: this,
443
443
  C: (f, a) => f(...a)
444
444
  });
@@ -451,7 +451,7 @@ var RpcPeer = class {
451
451
  if (this._state !== "CLOSING" && this._state !== "CLOSED") {
452
452
  (0, import_log.log)("replying to bye", void 0, {
453
453
  F: __dxlog_file,
454
- L: 351,
454
+ L: 356,
455
455
  S: this,
456
456
  C: (f, a) => f(...a)
457
457
  });
@@ -467,7 +467,7 @@ var RpcPeer = class {
467
467
  msg
468
468
  }, {
469
469
  F: __dxlog_file,
470
- L: 359,
470
+ L: 364,
471
471
  S: this,
472
472
  C: (f, a) => f(...a)
473
473
  });
@@ -483,7 +483,7 @@ var RpcPeer = class {
483
483
  method
484
484
  }, {
485
485
  F: __dxlog_file,
486
- L: 369,
486
+ L: 374,
487
487
  S: this,
488
488
  C: (f, a) => f(...a)
489
489
  });
@@ -510,7 +510,7 @@ var RpcPeer = class {
510
510
  response = await waiting;
511
511
  (0, import_invariant.invariant)(response.id === id, void 0, {
512
512
  F: __dxlog_file,
513
- L: 394,
513
+ L: 399,
514
514
  S: this,
515
515
  A: [
516
516
  "response.id === id",
@@ -589,7 +589,7 @@ ${stack.getStack()}`;
589
589
  }).catch((err) => {
590
590
  import_log.log.catch(err, void 0, {
591
591
  F: __dxlog_file,
592
- L: 467,
592
+ L: 472,
593
593
  S: this,
594
594
  C: (f, a) => f(...a)
595
595
  });
@@ -602,7 +602,7 @@ ${stack.getStack()}`;
602
602
  type: Object.keys(message)[0]
603
603
  }, {
604
604
  F: __dxlog_file,
605
- L: 474,
605
+ L: 479,
606
606
  S: this,
607
607
  C: (f, a) => f(...a)
608
608
  });
@@ -614,7 +614,7 @@ ${stack.getStack()}`;
614
614
  try {
615
615
  (0, import_invariant.invariant)(typeof req.id === "number", void 0, {
616
616
  F: __dxlog_file,
617
- L: 480,
617
+ L: 485,
618
618
  S: this,
619
619
  A: [
620
620
  "typeof req.id === 'number'",
@@ -623,7 +623,7 @@ ${stack.getStack()}`;
623
623
  });
624
624
  (0, import_invariant.invariant)(req.payload, void 0, {
625
625
  F: __dxlog_file,
626
- L: 481,
626
+ L: 486,
627
627
  S: this,
628
628
  A: [
629
629
  "req.payload",
@@ -632,14 +632,14 @@ ${stack.getStack()}`;
632
632
  });
633
633
  (0, import_invariant.invariant)(req.method, void 0, {
634
634
  F: __dxlog_file,
635
- L: 482,
635
+ L: 487,
636
636
  S: this,
637
637
  A: [
638
638
  "req.method",
639
639
  ""
640
640
  ]
641
641
  });
642
- const response = await this._params.callHandler(req.method, req.payload);
642
+ const response = await this._params.callHandler(req.method, req.payload, this._params.handlerRpcOptions);
643
643
  return {
644
644
  id: req.id,
645
645
  payload: response
@@ -655,7 +655,7 @@ ${stack.getStack()}`;
655
655
  try {
656
656
  (0, import_invariant.invariant)(this._params.streamHandler, "Requests with streaming responses are not supported.", {
657
657
  F: __dxlog_file,
658
- L: 499,
658
+ L: 504,
659
659
  S: this,
660
660
  A: [
661
661
  "this._params.streamHandler",
@@ -664,7 +664,7 @@ ${stack.getStack()}`;
664
664
  });
665
665
  (0, import_invariant.invariant)(typeof req.id === "number", void 0, {
666
666
  F: __dxlog_file,
667
- L: 500,
667
+ L: 505,
668
668
  S: this,
669
669
  A: [
670
670
  "typeof req.id === 'number'",
@@ -673,7 +673,7 @@ ${stack.getStack()}`;
673
673
  });
674
674
  (0, import_invariant.invariant)(req.payload, void 0, {
675
675
  F: __dxlog_file,
676
- L: 501,
676
+ L: 506,
677
677
  S: this,
678
678
  A: [
679
679
  "req.payload",
@@ -682,14 +682,14 @@ ${stack.getStack()}`;
682
682
  });
683
683
  (0, import_invariant.invariant)(req.method, void 0, {
684
684
  F: __dxlog_file,
685
- L: 502,
685
+ L: 507,
686
686
  S: this,
687
687
  A: [
688
688
  "req.method",
689
689
  ""
690
690
  ]
691
691
  });
692
- const responseStream = this._params.streamHandler(req.method, req.payload);
692
+ const responseStream = this._params.streamHandler(req.method, req.payload, this._params.handlerRpcOptions);
693
693
  responseStream.onReady(() => {
694
694
  callback({
695
695
  id: req.id,
@@ -776,19 +776,19 @@ var createProtoRpcPeer = ({ requested, exposed, handlers, encodingOptions, ...re
776
776
  }
777
777
  const peer = new RpcPeer({
778
778
  ...rest,
779
- callHandler: (method, request) => {
779
+ callHandler: (method, request, options) => {
780
780
  const [serviceName, methodName] = parseMethodName(method);
781
781
  if (!exposedRpcs[serviceName]) {
782
782
  throw new Error(`Service not supported: ${serviceName}`);
783
783
  }
784
- return exposedRpcs[serviceName].call(methodName, request);
784
+ return exposedRpcs[serviceName].call(methodName, request, options);
785
785
  },
786
- streamHandler: (method, request) => {
786
+ streamHandler: (method, request, options) => {
787
787
  const [serviceName, methodName] = parseMethodName(method);
788
788
  if (!exposedRpcs[serviceName]) {
789
789
  throw new Error(`Service not supported: ${serviceName}`);
790
790
  }
791
- return exposedRpcs[serviceName].callStream(methodName, request);
791
+ return exposedRpcs[serviceName].callStream(methodName, request, options);
792
792
  }
793
793
  });
794
794
  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\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) => 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 = 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);\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,mBAAoD;AACpD,4B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A;AACV,eAAO,KAAKG,aAAa3H,UAAU,CAACC,QAAAA;AAClC,eAAKmE,QAAQ0D,KAAK;YAChBC,WAAWC,wBAAaC,UAAUG;YAClCD,MAAMlI;UACR,CAAA;AACAuH,aAAGvH,GAAAA;QACL,CAAA;MACF;IACF;EACF;EAEA,IAAWF,OAAO;AAChB,WAAO,KAAK8H;EACd;AACF;",
6
- "names": ["import_debug", "import_protocols", "import_invariant", "import_async", "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", "_nextId", "_state", "_unsubscribeFromPort", "undefined", "_clearOpenInterval", "_params", "timeout", "streamHandler", "noHandshake", "open", "port", "subscribe", "msg", "_receive", "log", "catch", "wake", "state", "_sendMessage", "exponentialBackoffInterval", "warn", "Promise", "race", "wait", "_closingTrigger", "openAck", "close", "_abortRequests", "bye", "_byeTrigger", "_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", "callStream", "Stream", "ready", "next", "onResponse", "streamReady", "closeStream", "message", "send", "encode", "callHandler", "callback", "responseStream", "onReady", "synchronized", "RpcNotOpenError", "createServiceBundle", "services", "ProtoRpcPeer", "rpc", "_peer", "createProtoRpcPeer", "requested", "exposed", "handlers", "encodingOptions", "rest", "exposedRpcs", "serviceName", "serviceFqn", "serviceProto", "fullName", "serviceProvider", "createServer", "peer", "methodName", "parseMethodName", "requestedRpcs", "createClient", "separator", "lastIndexOf", "length", "createRpcClient", "serviceDef", "client", "bind", "createRpcServer", "service", "server", "createBundledRpcClient", "descriptors", "createBundledRpcServer", "createLinkedPorts", "delay", "port1Received", "port2Received", "handler", "setTimeout", "port1", "cb", "port2", "PortTracer", "_wrappedPort", "Event", "_port", "emit", "direction", "MessageTrace", "Direction", "OUTGOING", "data", "INCOMING"]
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,mBAAoD;AACpD,4BAAsD;AACtD,mBAA2B;AAC3B,uBAA0B;AAC1B,iBAAoB;AACpB,uBAAqE;AAErE,kBAA2C;ACP3C,IAAAA,gBAA2B;AAC3B,IAAAC,oBAA4B;ACK5B,IAAAC,oBAA0B;AEN1B,IAAAC,gBAAsB;AACtB,iBAA6B;AHGtB,IAAMC,iBAAiB,CAACC,KAAoBC,kBACjDC,+BAAYF,KAAK;EACfG,aAAa;aAAgBF,SAAAA;IAAiB,IAAIG,yBAAAA,EAAaC,SAAS,CAAA;AAC1E,CAAA;;;;;;;;;;;;ADIF,IAAMC,kBAAkB;AACxB,IAAMC,mBAAmB;AAEzB,IAAMC,c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A,EAAa7B,WAAWoC,YAAYlE,OAAAA;IACjD;EACF,CAAA;AACF;ACrPO,IAAMmF,oBAAoB,CAAC,EAAEC,MAAK,IAA+B,CAAC,MAAC;AACxE,MAAIC;AACJ,MAAIC;AAEJ,QAAMhD,OAAO,CAACiD,SAAsCrH,QAAAA;AAClD,QAAIkH,OAAO;AACTI,iBAAW,MAAMD,UAAUrH,GAAAA,GAAMkH,KAAAA;IACnC,OAAO;AACL,WAAKG,UAAUrH,GAAAA;IACjB;EACF;AAEA,QAAMuH,QAAiB;IACrBnD,MAAM,CAACpE,QAAQoE,KAAKgD,eAAepH,GAAAA;IACnCD,WAAW,CAACyH,OAAAA;AACVL,sBAAgBK;IAClB;EACF;AAEA,QAAMC,QAAiB;IACrBrD,MAAM,CAACpE,QAAQoE,KAAK+C,eAAenH,GAAAA;IACnCD,WAAW,CAACyH,OAAAA;AACVJ,sBAAgBI;IAClB;EACF;AAEA,SAAO;IAACD;IAAOE;;AACjB;AC/BO,IAAMC,aAAN,MAAMA;EAKXrJ,YAA6BsJ,cAAuB;SAAvBA,eAAAA;SAJpBxD,UAAU,IAAIyD,oBAAAA;AAKrB,SAAKC,QAAQ;MACXzD,MAAM,CAACpE,QAAAA;AACL,aAAKmE,QAAQ2D,KAAK;UAChBC,WAAWC,wBAAaC,UAAUC;UAClCC,MAAMnI;QACR,CAAA;AAEA,eAAO,KAAK2H,aAAavD,KAAKpE,GAAAA;MAChC;MACAD,WAAW,CAACyH,OAAAA;AACV,eAAO,KAAKG,aAAa5H,UAAU,CAACC,QAAAA;AAClC,eAAKmE,QAAQ2D,KAAK;YAChBC,WAAWC,wBAAaC,UAAUG;YAClCD,MAAMnI;UACR,CAAA;AACAwH,aAAGxH,GAAAA;QACL,CAAA;MACF;IACF;EACF;EAEA,IAAWF,OAAO;AAChB,WAAO,KAAK+H;EACd;AACF;",
6
+ "names": ["import_debug", "import_protocols", "import_invariant", "import_async", "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", "_nextId", "_state", "_unsubscribeFromPort", "undefined", "_clearOpenInterval", "_params", "timeout", "streamHandler", "noHandshake", "open", "port", "subscribe", "msg", "_receive", "log", "catch", "wake", "state", "_sendMessage", "exponentialBackoffInterval", "warn", "Promise", "race", "wait", "_closingTrigger", "openAck", "close", "_abortRequests", "bye", "_byeTrigger", "_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", "callStream", "Stream", "ready", "next", "onResponse", "streamReady", "closeStream", "message", "send", "encode", "callHandler", "handlerRpcOptions", "callback", "responseStream", "onReady", "synchronized", "RpcNotOpenError", "createServiceBundle", "services", "ProtoRpcPeer", "rpc", "_peer", "createProtoRpcPeer", "requested", "exposed", "handlers", "encodingOptions", "rest", "exposedRpcs", "serviceName", "serviceFqn", "serviceProto", "fullName", "serviceProvider", "createServer", "peer", "methodName", "parseMethodName", "requestedRpcs", "createClient", "separator", "lastIndexOf", "length", "createRpcClient", "serviceDef", "client", "bind", "createRpcServer", "service", "server", "createBundledRpcClient", "descriptors", "createBundledRpcServer", "createLinkedPorts", "delay", "port1Received", "port2Received", "handler", "setTimeout", "port1", "cb", "port2", "PortTracer", "_wrappedPort", "Event", "_port", "emit", "direction", "MessageTrace", "Direction", "OUTGOING", "data", "INCOMING"]
7
7
  }
@@ -1 +1 @@
1
- {"inputs":{"packages/core/mesh/rpc/src/errors.ts":{"bytes":1482,"imports":[{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true}],"format":"esm"},"packages/core/mesh/rpc/src/rpc.ts":{"bytes":60797,"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/codec-protobuf","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/core/mesh/rpc/src/errors.ts","kind":"import-statement","original":"./errors"}],"format":"esm"},"packages/core/mesh/rpc/src/service.ts":{"bytes":22257,"imports":[{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"packages/core/mesh/rpc/src/rpc.ts","kind":"import-statement","original":"./rpc"}],"format":"esm"},"packages/core/mesh/rpc/src/testing.ts":{"bytes":2972,"imports":[],"format":"esm"},"packages/core/mesh/rpc/src/trace.ts":{"bytes":3543,"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/protocols/proto/dxos/rpc","kind":"import-statement","external":true}],"format":"esm"},"packages/core/mesh/rpc/src/index.ts":{"bytes":786,"imports":[{"path":"packages/core/mesh/rpc/src/rpc.ts","kind":"import-statement","original":"./rpc"},{"path":"packages/core/mesh/rpc/src/errors.ts","kind":"import-statement","original":"./errors"},{"path":"packages/core/mesh/rpc/src/service.ts","kind":"import-statement","original":"./service"},{"path":"packages/core/mesh/rpc/src/testing.ts","kind":"import-statement","original":"./testing"},{"path":"packages/core/mesh/rpc/src/trace.ts","kind":"import-statement","original":"./trace"}],"format":"esm"}},"outputs":{"packages/core/mesh/rpc/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":42258},"packages/core/mesh/rpc/dist/lib/node/index.cjs":{"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/codec-protobuf","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/protocols/proto/dxos/rpc","kind":"import-statement","external":true}],"exports":["PortTracer","ProtoRpcPeer","RpcPeer","createBundledRpcClient","createBundledRpcServer","createLinkedPorts","createProtoRpcPeer","createRpcClient","createRpcServer","createServiceBundle","decodeRpcError","parseMethodName"],"entryPoint":"packages/core/mesh/rpc/src/index.ts","inputs":{"packages/core/mesh/rpc/src/rpc.ts":{"bytesInOutput":17865},"packages/core/mesh/rpc/src/errors.ts":{"bytesInOutput":228},"packages/core/mesh/rpc/src/index.ts":{"bytesInOutput":0},"packages/core/mesh/rpc/src/service.ts":{"bytesInOutput":4206},"packages/core/mesh/rpc/src/testing.ts":{"bytesInOutput":528},"packages/core/mesh/rpc/src/trace.ts":{"bytesInOutput":732}},"bytes":24079}}}
1
+ {"inputs":{"packages/core/mesh/rpc/src/errors.ts":{"bytes":1482,"imports":[{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true}],"format":"esm"},"packages/core/mesh/rpc/src/rpc.ts":{"bytes":61305,"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/codec-protobuf","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"packages/core/mesh/rpc/src/errors.ts","kind":"import-statement","original":"./errors"}],"format":"esm"},"packages/core/mesh/rpc/src/service.ts":{"bytes":22389,"imports":[{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"packages/core/mesh/rpc/src/rpc.ts","kind":"import-statement","original":"./rpc"}],"format":"esm"},"packages/core/mesh/rpc/src/testing.ts":{"bytes":2972,"imports":[],"format":"esm"},"packages/core/mesh/rpc/src/trace.ts":{"bytes":3543,"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/protocols/proto/dxos/rpc","kind":"import-statement","external":true}],"format":"esm"},"packages/core/mesh/rpc/src/index.ts":{"bytes":786,"imports":[{"path":"packages/core/mesh/rpc/src/rpc.ts","kind":"import-statement","original":"./rpc"},{"path":"packages/core/mesh/rpc/src/errors.ts","kind":"import-statement","original":"./errors"},{"path":"packages/core/mesh/rpc/src/service.ts","kind":"import-statement","original":"./service"},{"path":"packages/core/mesh/rpc/src/testing.ts","kind":"import-statement","original":"./testing"},{"path":"packages/core/mesh/rpc/src/trace.ts","kind":"import-statement","original":"./trace"}],"format":"esm"}},"outputs":{"packages/core/mesh/rpc/dist/lib/node/index.cjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":42626},"packages/core/mesh/rpc/dist/lib/node/index.cjs":{"imports":[{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/codec-protobuf","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/log","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true},{"path":"@dxos/debug","kind":"import-statement","external":true},{"path":"@dxos/protocols","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/protocols/proto/dxos/rpc","kind":"import-statement","external":true}],"exports":["PortTracer","ProtoRpcPeer","RpcPeer","createBundledRpcClient","createBundledRpcServer","createLinkedPorts","createProtoRpcPeer","createRpcClient","createRpcServer","createServiceBundle","decodeRpcError","parseMethodName"],"entryPoint":"packages/core/mesh/rpc/src/index.ts","inputs":{"packages/core/mesh/rpc/src/rpc.ts":{"bytesInOutput":17929},"packages/core/mesh/rpc/src/errors.ts":{"bytesInOutput":228},"packages/core/mesh/rpc/src/index.ts":{"bytesInOutput":0},"packages/core/mesh/rpc/src/service.ts":{"bytesInOutput":4242},"packages/core/mesh/rpc/src/testing.ts":{"bytesInOutput":528},"packages/core/mesh/rpc/src/trace.ts":{"bytesInOutput":732}},"bytes":24179}}}
@@ -6,12 +6,16 @@ export interface RpcPeerOptions {
6
6
  * Time to wait for a response to an RPC call.
7
7
  */
8
8
  timeout?: number;
9
- callHandler: (method: string, request: Any) => MaybePromise<Any>;
10
- streamHandler?: (method: string, request: Any) => Stream<Any>;
9
+ callHandler: (method: string, request: Any, options?: RequestOptions) => MaybePromise<Any>;
10
+ streamHandler?: (method: string, request: Any, options?: RequestOptions) => Stream<Any>;
11
11
  /**
12
12
  * Do not require or send handshake messages.
13
13
  */
14
14
  noHandshake?: boolean;
15
+ /**
16
+ * What options get passed to the `callHandler` and `streamHandler`.
17
+ */
18
+ handlerRpcOptions?: RequestOptions;
15
19
  }
16
20
  /**
17
21
  * Interface for a transport-agnostic port to send/receive binary messages.
@@ -1 +1 @@
1
- {"version":3,"file":"rpc.d.ts","sourceRoot":"","sources":["../../../src/rpc.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,EAAE,KAAK,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAe7E,KAAK,YAAY,CAAC,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AAEtC,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,OAAO,CAAC;IAEd;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,WAAW,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,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