@dxos/rpc 0.5.1-next.ed1615e → 0.5.2-main.16cd857

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/rpc",
3
- "version": "0.5.1-next.ed1615e",
3
+ "version": "0.5.2-main.16cd857",
4
4
  "description": "A lightweight, transport-agnostic RPC implementation",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -16,14 +16,14 @@
16
16
  "src"
17
17
  ],
18
18
  "dependencies": {
19
- "@dxos/async": "0.5.1-next.ed1615e",
20
- "@dxos/codec-protobuf": "0.5.1-next.ed1615e",
21
- "@dxos/invariant": "0.5.1-next.ed1615e",
22
- "@dxos/debug": "0.5.1-next.ed1615e",
23
- "@dxos/log": "0.5.1-next.ed1615e",
24
- "@dxos/node-std": "0.5.1-next.ed1615e",
25
- "@dxos/protocols": "0.5.1-next.ed1615e",
26
- "@dxos/util": "0.5.1-next.ed1615e"
19
+ "@dxos/codec-protobuf": "0.5.2-main.16cd857",
20
+ "@dxos/debug": "0.5.2-main.16cd857",
21
+ "@dxos/async": "0.5.2-main.16cd857",
22
+ "@dxos/invariant": "0.5.2-main.16cd857",
23
+ "@dxos/node-std": "0.5.2-main.16cd857",
24
+ "@dxos/util": "0.5.2-main.16cd857",
25
+ "@dxos/protocols": "0.5.2-main.16cd857",
26
+ "@dxos/log": "0.5.2-main.16cd857"
27
27
  },
28
28
  "devDependencies": {
29
29
  "earljs": "~0.1.10",
package/src/rpc.ts CHANGED
@@ -28,13 +28,18 @@ export interface RpcPeerOptions {
28
28
  */
29
29
  timeout?: number;
30
30
 
31
- callHandler: (method: string, request: Any) => MaybePromise<Any>;
32
- streamHandler?: (method: string, request: Any) => Stream<Any>;
31
+ callHandler: (method: string, request: Any, options?: RequestOptions) => MaybePromise<Any>;
32
+ streamHandler?: (method: string, request: Any, options?: RequestOptions) => Stream<Any>;
33
33
 
34
34
  /**
35
35
  * Do not require or send handshake messages.
36
36
  */
37
37
  noHandshake?: boolean;
38
+
39
+ /**
40
+ * What options get passed to the `callHandler` and `streamHandler`.
41
+ */
42
+ handlerRpcOptions?: RequestOptions;
38
43
  }
39
44
 
40
45
  /**
@@ -388,7 +393,10 @@ export class RpcPeer {
388
393
  });
389
394
 
390
395
  // Wait until send completes or throws an error (or response throws a timeout), the resume waiting.
391
- const waiting = asyncTimeout<any>(responseReceived, options?.timeout ?? this._params.timeout ?? DEFAULT_TIMEOUT);
396
+ const timeout = options?.timeout ?? this._params.timeout;
397
+ const waiting =
398
+ timeout === 0 ? responseReceived : asyncTimeout<any>(responseReceived, timeout ?? DEFAULT_TIMEOUT);
399
+
392
400
  await Promise.race([sending, waiting]);
393
401
  response = await waiting;
394
402
  invariant(response.id === id);
@@ -481,7 +489,7 @@ export class RpcPeer {
481
489
  invariant(req.payload);
482
490
  invariant(req.method);
483
491
 
484
- const response = await this._params.callHandler(req.method, req.payload);
492
+ const response = await this._params.callHandler(req.method, req.payload, this._params.handlerRpcOptions);
485
493
  return {
486
494
  id: req.id,
487
495
  payload: response,
@@ -501,7 +509,7 @@ export class RpcPeer {
501
509
  invariant(req.payload);
502
510
  invariant(req.method);
503
511
 
504
- const responseStream = this._params.streamHandler(req.method, req.payload);
512
+ const responseStream = this._params.streamHandler(req.method, req.payload, this._params.handlerRpcOptions);
505
513
  responseStream.onReady(() => {
506
514
  callback({
507
515
  id: req.id,
package/src/service.ts CHANGED
@@ -103,22 +103,22 @@ export const createProtoRpcPeer = <Client = {}, Server = {}>({
103
103
  const peer = new RpcPeer({
104
104
  ...rest,
105
105
 
106
- callHandler: (method, request) => {
106
+ callHandler: (method, request, options) => {
107
107
  const [serviceName, methodName] = parseMethodName(method);
108
108
  if (!exposedRpcs[serviceName]) {
109
109
  throw new Error(`Service not supported: ${serviceName}`);
110
110
  }
111
111
 
112
- return exposedRpcs[serviceName].call(methodName, request);
112
+ return exposedRpcs[serviceName].call(methodName, request, options);
113
113
  },
114
114
 
115
- streamHandler: (method, request) => {
115
+ streamHandler: (method, request, options) => {
116
116
  const [serviceName, methodName] = parseMethodName(method);
117
117
  if (!exposedRpcs[serviceName]) {
118
118
  throw new Error(`Service not supported: ${serviceName}`);
119
119
  }
120
120
 
121
- return exposedRpcs[serviceName].callStream(methodName, request);
121
+ return exposedRpcs[serviceName].callStream(methodName, request, options);
122
122
  },
123
123
  });
124
124