@dxos/rpc 0.6.7 → 0.6.8-main.046e6cf

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.6.7",
3
+ "version": "0.6.8-main.046e6cf",
4
4
  "description": "A lightweight, transport-agnostic RPC implementation",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -24,18 +24,18 @@
24
24
  "src"
25
25
  ],
26
26
  "dependencies": {
27
- "@dxos/async": "0.6.7",
28
- "@dxos/codec-protobuf": "0.6.7",
29
- "@dxos/invariant": "0.6.7",
30
- "@dxos/log": "0.6.7",
31
- "@dxos/debug": "0.6.7",
32
- "@dxos/util": "0.6.7",
33
- "@dxos/node-std": "0.6.7",
34
- "@dxos/protocols": "0.6.7"
27
+ "@dxos/async": "0.6.8-main.046e6cf",
28
+ "@dxos/debug": "0.6.8-main.046e6cf",
29
+ "@dxos/codec-protobuf": "0.6.8-main.046e6cf",
30
+ "@dxos/invariant": "0.6.8-main.046e6cf",
31
+ "@dxos/log": "0.6.8-main.046e6cf",
32
+ "@dxos/node-std": "0.6.8-main.046e6cf",
33
+ "@dxos/protocols": "0.6.8-main.046e6cf",
34
+ "@dxos/util": "0.6.8-main.046e6cf"
35
35
  },
36
36
  "devDependencies": {
37
37
  "earljs": "~0.1.10",
38
- "typescript": "^5.4.5"
38
+ "typescript": "^5.5.4"
39
39
  },
40
40
  "publishConfig": {
41
41
  "access": "public"
package/src/rpc.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  //
4
4
 
5
5
  import { asyncTimeout, synchronized, Trigger } from '@dxos/async';
6
- import { type Any, Stream, type RequestOptions } from '@dxos/codec-protobuf';
6
+ import { type Any, Stream, type RequestOptions, type ProtoCodec } from '@dxos/codec-protobuf';
7
7
  import { StackTrace } from '@dxos/debug';
8
8
  import { invariant } from '@dxos/invariant';
9
9
  import { log } from '@dxos/log';
@@ -67,7 +67,9 @@ class PendingRpcRequest {
67
67
  ) {}
68
68
  }
69
69
 
70
- const RpcMessage = schema.getCodecForType('dxos.rpc.RpcMessage');
70
+ // NOTE: Lazy so that code that doesn't use indexing doesn't need to load the codec (breaks in workerd).
71
+ let RpcMessageCodec!: ProtoCodec<RpcMessage>;
72
+ const getRpcMessageCodec = () => (RpcMessageCodec ??= schema.getCodecForType('dxos.rpc.RpcMessage'));
71
73
 
72
74
  enum RpcState {
73
75
  INITIAL = 'INITIAL',
@@ -256,7 +258,7 @@ export class RpcPeer {
256
258
  * Handle incoming message. Should be called as the result of other peer's `send` callback.
257
259
  */
258
260
  private async _receive(msg: Uint8Array): Promise<void> {
259
- const decoded = RpcMessage.decode(msg, { preserveAny: true });
261
+ const decoded = getRpcMessageCodec().decode(msg, { preserveAny: true });
260
262
  DEBUG_CALLS && log('received message', { type: Object.keys(decoded)[0] });
261
263
 
262
264
  if (decoded.request) {
@@ -481,7 +483,7 @@ export class RpcPeer {
481
483
 
482
484
  private async _sendMessage(message: RpcMessage, timeout?: number) {
483
485
  DEBUG_CALLS && log('sending message', { type: Object.keys(message)[0] });
484
- await this._params.port.send(RpcMessage.encode(message, { preserveAny: true }), timeout);
486
+ await this._params.port.send(getRpcMessageCodec().encode(message, { preserveAny: true }), timeout);
485
487
  }
486
488
 
487
489
  private async _callHandler(req: Request): Promise<Response> {