@dxos/rpc 0.8.4-main.dedc0f3 → 0.8.4-main.dfabb4ec29

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.
@@ -12,49 +12,61 @@ var decodeRpcError = (err, rpcMethod) => decodeError(err, {
12
12
  // src/rpc.ts
13
13
  import { Trigger, asyncTimeout, synchronized } from "@dxos/async";
14
14
  import { Stream } from "@dxos/codec-protobuf";
15
+ import { ContextRpcCodec } from "@dxos/context";
15
16
  import { StackTrace as StackTrace2 } from "@dxos/debug";
16
17
  import { invariant } from "@dxos/invariant";
17
18
  import { log } from "@dxos/log";
18
19
  import { RpcClosedError, RpcNotOpenError, encodeError } from "@dxos/protocols";
19
20
  import { schema } from "@dxos/protocols/proto";
20
21
  import { exponentialBackoffInterval } from "@dxos/util";
21
- function _define_property(obj, key, value) {
22
- if (key in obj) {
23
- Object.defineProperty(obj, key, {
24
- value,
25
- enumerable: true,
26
- configurable: true,
27
- writable: true
28
- });
29
- } else {
30
- obj[key] = value;
31
- }
32
- return obj;
33
- }
22
+ var __dxlog_file = "/__w/dxos/dxos/packages/core/mesh/rpc/src/rpc.ts";
34
23
  function _ts_decorate(decorators, target, key, desc) {
35
24
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
36
25
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
37
26
  else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
38
27
  return c > 3 && r && Object.defineProperty(target, key, r), r;
39
28
  }
40
- var __dxlog_file = "/__w/dxos/dxos/packages/core/mesh/rpc/src/rpc.ts";
41
- var DEFAULT_TIMEOUT = 3e3;
29
+ var DEFAULT_TIMEOUT = 3e4;
42
30
  var BYE_SEND_TIMEOUT = 2e3;
43
31
  var DEBUG_CALLS = true;
44
32
  var CLOSE_TIMEOUT = 3e3;
45
33
  var PendingRpcRequest = class {
34
+ resolve;
35
+ reject;
36
+ stream;
46
37
  constructor(resolve, reject, stream) {
47
- _define_property(this, "resolve", void 0);
48
- _define_property(this, "reject", void 0);
49
- _define_property(this, "stream", void 0);
50
38
  this.resolve = resolve;
51
39
  this.reject = reject;
52
40
  this.stream = stream;
53
41
  }
54
42
  };
55
43
  var RpcMessageCodec;
56
- var getRpcMessageCodec = () => RpcMessageCodec ?? (RpcMessageCodec = schema.getCodecForType("dxos.rpc.RpcMessage"));
44
+ var getRpcMessageCodec = () => RpcMessageCodec ??= schema.getCodecForType("dxos.rpc.RpcMessage");
57
45
  var RpcPeer = class {
46
+ _params;
47
+ _outgoingRequests = /* @__PURE__ */ new Map();
48
+ _localStreams = /* @__PURE__ */ new Map();
49
+ _remoteOpenTrigger = new Trigger();
50
+ /**
51
+ * Triggered when the peer starts closing.
52
+ */
53
+ _closingTrigger = new Trigger();
54
+ /**
55
+ * Triggered when peer receives a bye message.
56
+ */
57
+ _byeTrigger = new Trigger();
58
+ _nextId = 0;
59
+ _state = "INITIAL";
60
+ _unsubscribeFromPort = void 0;
61
+ _clearOpenInterval = void 0;
62
+ constructor(params) {
63
+ this._params = {
64
+ timeout: void 0,
65
+ streamHandler: void 0,
66
+ noHandshake: false,
67
+ ...params
68
+ };
69
+ }
58
70
  /**
59
71
  * Open the peer. Required before making any calls.
60
72
  *
@@ -68,12 +80,7 @@ var RpcPeer = class {
68
80
  try {
69
81
  await this._receive(msg);
70
82
  } catch (err) {
71
- log.catch(err, void 0, {
72
- F: __dxlog_file,
73
- L: 156,
74
- S: this,
75
- C: (f, a) => f(...a)
76
- });
83
+ log.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 100, S: this });
77
84
  }
78
85
  });
79
86
  this._state = "OPENING";
@@ -84,12 +91,7 @@ var RpcPeer = class {
84
91
  }
85
92
  log("sending open message", {
86
93
  state: this._state
87
- }, {
88
- F: __dxlog_file,
89
- L: 168,
90
- S: this,
91
- C: (f, a) => f(...a)
92
- });
94
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 109, S: this });
93
95
  await this._sendMessage({
94
96
  open: true
95
97
  });
@@ -99,12 +101,7 @@ var RpcPeer = class {
99
101
  this._clearOpenInterval = exponentialBackoffInterval(() => {
100
102
  void this._sendMessage({
101
103
  open: true
102
- }).catch((err) => log.warn(err, void 0, {
103
- F: __dxlog_file,
104
- L: 177,
105
- S: this,
106
- C: (f, a) => f(...a)
107
- }));
104
+ }).catch((err) => log.warn(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 122, S: this }));
108
105
  }, 50);
109
106
  await Promise.race([
110
107
  this._remoteOpenTrigger.wait(),
@@ -116,12 +113,7 @@ var RpcPeer = class {
116
113
  }
117
114
  log("resending open message", {
118
115
  state: this._state
119
- }, {
120
- F: __dxlog_file,
121
- L: 191,
122
- S: this,
123
- C: (f, a) => f(...a)
124
- });
116
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 135, S: this });
125
117
  await this._sendMessage({
126
118
  openAck: true
127
119
  });
@@ -146,32 +138,17 @@ var RpcPeer = class {
146
138
  } catch (err) {
147
139
  log("error closing peer, sending bye", {
148
140
  err
149
- }, {
150
- F: __dxlog_file,
151
- L: 213,
152
- S: this,
153
- C: (f, a) => f(...a)
154
- });
141
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 159, S: this });
155
142
  }
156
143
  try {
157
- log("closing waiting on bye", void 0, {
158
- F: __dxlog_file,
159
- L: 216,
160
- S: this,
161
- C: (f, a) => f(...a)
162
- });
144
+ log("closing waiting on bye", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 164, S: this });
163
145
  await this._byeTrigger.wait({
164
146
  timeout
165
147
  });
166
148
  } catch (err) {
167
149
  log("error closing peer", {
168
150
  err
169
- }, {
170
- F: __dxlog_file,
171
- L: 219,
172
- S: this,
173
- C: (f, a) => f(...a)
174
- });
151
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 169, S: this });
175
152
  return;
176
153
  }
177
154
  }
@@ -208,22 +185,12 @@ var RpcPeer = class {
208
185
  const decoded = getRpcMessageCodec().decode(msg, {
209
186
  preserveAny: true
210
187
  });
211
- DEBUG_CALLS && log("received message", {
188
+ DEBUG_CALLS && log.trace("received message", {
212
189
  type: Object.keys(decoded)[0]
213
- }, {
214
- F: __dxlog_file,
215
- L: 263,
216
- S: this,
217
- C: (f, a) => f(...a)
218
- });
190
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 208, S: this });
219
191
  if (decoded.request) {
220
192
  if (this._state !== "OPENED" && this._state !== "OPENING") {
221
- log("received request while closed", void 0, {
222
- F: __dxlog_file,
223
- L: 267,
224
- S: this,
225
- C: (f, a) => f(...a)
226
- });
193
+ log("received request while closed", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 213, S: this });
227
194
  await this._sendMessage({
228
195
  response: {
229
196
  id: decoded.request.id,
@@ -236,112 +203,59 @@ var RpcPeer = class {
236
203
  if (req.stream) {
237
204
  log("stream request", {
238
205
  method: req.method
239
- }, {
240
- F: __dxlog_file,
241
- L: 279,
242
- S: this,
243
- C: (f, a) => f(...a)
244
- });
206
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 224, S: this });
245
207
  this._callStreamHandler(req, (response) => {
246
208
  log("sending stream response", {
247
209
  method: req.method,
248
210
  response: response.payload?.type_url,
249
211
  error: response.error,
250
212
  close: response.close
251
- }, {
252
- F: __dxlog_file,
253
- L: 281,
254
- S: this,
255
- C: (f, a) => f(...a)
256
- });
213
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 228, S: this });
257
214
  void this._sendMessage({
258
215
  response
259
216
  }).catch((err) => {
260
- log.warn("failed during close", err, {
261
- F: __dxlog_file,
262
- L: 289,
263
- S: this,
264
- C: (f, a) => f(...a)
265
- });
217
+ log.warn("failed during close", err, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 237, S: this });
266
218
  });
267
219
  });
268
220
  } else {
269
- DEBUG_CALLS && log("requesting...", {
221
+ DEBUG_CALLS && log.trace("requesting...", {
270
222
  method: req.method
271
- }, {
272
- F: __dxlog_file,
273
- L: 293,
274
- S: this,
275
- C: (f, a) => f(...a)
276
- });
223
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 241, S: this });
277
224
  const response = await this._callHandler(req);
278
- DEBUG_CALLS && log("sending response", {
225
+ DEBUG_CALLS && log.trace("sending response", {
279
226
  method: req.method,
280
227
  response: response.payload?.type_url,
281
228
  error: response.error
282
- }, {
283
- F: __dxlog_file,
284
- L: 296,
285
- S: this,
286
- C: (f, a) => f(...a)
287
- });
229
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 245, S: this });
288
230
  await this._sendMessage({
289
231
  response
290
232
  });
291
233
  }
292
234
  } else if (decoded.response) {
293
235
  if (this._state !== "OPENED") {
294
- log("received response while closed", void 0, {
295
- F: __dxlog_file,
296
- L: 305,
297
- S: this,
298
- C: (f, a) => f(...a)
299
- });
236
+ log("received response while closed", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 256, S: this });
300
237
  return;
301
238
  }
302
239
  const responseId = decoded.response.id;
303
- invariant(typeof responseId === "number", void 0, {
304
- F: __dxlog_file,
305
- L: 310,
306
- S: this,
307
- A: [
308
- "typeof responseId === 'number'",
309
- ""
310
- ]
311
- });
240
+ invariant(typeof responseId === "number", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 260, S: this, A: ["typeof responseId === 'number'", ""] });
312
241
  if (!this._outgoingRequests.has(responseId)) {
313
- log("received response with invalid id", {
242
+ log.trace("received response with invalid id", {
314
243
  responseId
315
- }, {
316
- F: __dxlog_file,
317
- L: 312,
318
- S: this,
319
- C: (f, a) => f(...a)
320
- });
244
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 262, S: this });
321
245
  return;
322
246
  }
323
247
  const item = this._outgoingRequests.get(responseId);
324
248
  if (!item.stream) {
325
249
  this._outgoingRequests.delete(responseId);
326
250
  }
327
- DEBUG_CALLS && log("response", {
251
+ DEBUG_CALLS && log.trace("response", {
328
252
  type_url: decoded.response.payload?.type_url
329
- }, {
330
- F: __dxlog_file,
331
- L: 322,
332
- S: this,
333
- C: (f, a) => f(...a)
334
- });
253
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 272, S: this });
335
254
  item.resolve(decoded.response);
336
255
  } else if (decoded.open) {
337
256
  log("received open message", {
338
257
  state: this._state
339
- }, {
340
- F: __dxlog_file,
341
- L: 325,
342
- S: this,
343
- C: (f, a) => f(...a)
344
- });
258
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 277, S: this });
345
259
  if (this._params.noHandshake) {
346
260
  return;
347
261
  }
@@ -351,12 +265,7 @@ var RpcPeer = class {
351
265
  } else if (decoded.openAck) {
352
266
  log("received openAck message", {
353
267
  state: this._state
354
- }, {
355
- F: __dxlog_file,
356
- L: 332,
357
- S: this,
358
- C: (f, a) => f(...a)
359
- });
268
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 287, S: this });
360
269
  if (this._params.noHandshake) {
361
270
  return;
362
271
  }
@@ -364,41 +273,18 @@ var RpcPeer = class {
364
273
  this._remoteOpenTrigger.wake();
365
274
  } else if (decoded.streamClose) {
366
275
  if (this._state !== "OPENED") {
367
- log("received stream close while closed", void 0, {
368
- F: __dxlog_file,
369
- L: 341,
370
- S: this,
371
- C: (f, a) => f(...a)
372
- });
276
+ log("received stream close while closed", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 297, S: this });
373
277
  return;
374
278
  }
375
279
  log("received stream close", {
376
280
  id: decoded.streamClose.id
377
- }, {
378
- F: __dxlog_file,
379
- L: 345,
380
- S: this,
381
- C: (f, a) => f(...a)
382
- });
383
- invariant(typeof decoded.streamClose.id === "number", void 0, {
384
- F: __dxlog_file,
385
- L: 346,
386
- S: this,
387
- A: [
388
- "typeof decoded.streamClose.id === 'number'",
389
- ""
390
- ]
391
- });
281
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 300, S: this });
282
+ invariant(typeof decoded.streamClose.id === "number", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 303, S: this, A: ["typeof decoded.streamClose.id === 'number'", ""] });
392
283
  const stream = this._localStreams.get(decoded.streamClose.id);
393
284
  if (!stream) {
394
285
  log("no local stream", {
395
286
  id: decoded.streamClose.id
396
- }, {
397
- F: __dxlog_file,
398
- L: 349,
399
- S: this,
400
- C: (f, a) => f(...a)
401
- });
287
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 306, S: this });
402
288
  return;
403
289
  }
404
290
  this._localStreams.delete(decoded.streamClose.id);
@@ -406,12 +292,7 @@ var RpcPeer = class {
406
292
  } else if (decoded.bye) {
407
293
  this._byeTrigger.wake();
408
294
  if (this._state !== "CLOSING" && this._state !== "CLOSED") {
409
- log("replying to bye", void 0, {
410
- F: __dxlog_file,
411
- L: 359,
412
- S: this,
413
- C: (f, a) => f(...a)
414
- });
295
+ log("replying to bye", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 317, S: this });
415
296
  this._state = "CLOSING";
416
297
  await this._sendMessage({
417
298
  bye: {}
@@ -422,12 +303,7 @@ var RpcPeer = class {
422
303
  } else {
423
304
  log.error("received malformed message", {
424
305
  msg
425
- }, {
426
- F: __dxlog_file,
427
- L: 367,
428
- S: this,
429
- C: (f, a) => f(...a)
430
- });
306
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 326, S: this });
431
307
  throw new Error("Malformed message.");
432
308
  }
433
309
  }
@@ -436,14 +312,9 @@ var RpcPeer = class {
436
312
  * Peer should be open before making this call.
437
313
  */
438
314
  async call(method, request, options) {
439
- DEBUG_CALLS && log("calling...", {
315
+ DEBUG_CALLS && log.trace("calling...", {
440
316
  method
441
- }, {
442
- F: __dxlog_file,
443
- L: 377,
444
- S: this,
445
- C: (f, a) => f(...a)
446
- });
317
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 336, S: this });
447
318
  throwIfNotOpen(this._state);
448
319
  let response;
449
320
  try {
@@ -451,12 +322,23 @@ var RpcPeer = class {
451
322
  const responseReceived = new Promise((resolve, reject) => {
452
323
  this._outgoingRequests.set(id, new PendingRpcRequest(resolve, reject, false));
453
324
  });
325
+ let traceContext;
326
+ try {
327
+ traceContext = options?.ctx ? ContextRpcCodec.encode(options.ctx) : void 0;
328
+ } catch (err) {
329
+ log.warn("failed to encode trace context", {
330
+ err
331
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 351, S: this });
332
+ }
454
333
  const sending = this._sendMessage({
455
334
  request: {
456
335
  id,
457
336
  method,
458
337
  payload: request,
459
- stream: false
338
+ stream: false,
339
+ ...traceContext ? {
340
+ traceContext
341
+ } : {}
460
342
  }
461
343
  });
462
344
  const timeout = options?.timeout ?? this._params.timeout;
@@ -466,15 +348,7 @@ var RpcPeer = class {
466
348
  waiting
467
349
  ]);
468
350
  response = await waiting;
469
- invariant(response.id === id, void 0, {
470
- F: __dxlog_file,
471
- L: 405,
472
- S: this,
473
- A: [
474
- "response.id === id",
475
- ""
476
- ]
477
- });
351
+ invariant(response.id === id, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 375, S: this, A: ["response.id === id", ""] });
478
352
  } catch (err) {
479
353
  if (err instanceof RpcClosedError) {
480
354
  const error = new RpcClosedError();
@@ -529,76 +403,81 @@ ${stack.getStack()}`;
529
403
  }
530
404
  };
531
405
  this._outgoingRequests.set(id, new PendingRpcRequest(onResponse, closeStream, true));
532
- this._sendMessage({
533
- request: {
534
- id,
535
- method,
536
- payload: request,
537
- stream: true
538
- }
539
- }).catch((err) => {
540
- close(err);
541
- });
406
+ let traceContext;
407
+ try {
408
+ traceContext = options?.ctx ? ContextRpcCodec.encode(options.ctx) : void 0;
409
+ } catch (err) {
410
+ log.warn("failed to encode trace context", {
411
+ err
412
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 429, S: this });
413
+ }
414
+ try {
415
+ this._sendMessage({
416
+ request: {
417
+ id,
418
+ method,
419
+ payload: request,
420
+ stream: true,
421
+ ...traceContext ? {
422
+ traceContext
423
+ } : {}
424
+ }
425
+ }).catch((err) => {
426
+ this._outgoingRequests.delete(id);
427
+ close(err);
428
+ });
429
+ } catch (err) {
430
+ this._outgoingRequests.delete(id);
431
+ throw err;
432
+ }
542
433
  return () => {
543
434
  this._sendMessage({
544
435
  streamClose: {
545
436
  id
546
437
  }
547
438
  }).catch((err) => {
548
- log.catch(err, void 0, {
549
- F: __dxlog_file,
550
- L: 478,
551
- S: this,
552
- C: (f, a) => f(...a)
553
- });
439
+ log.catch(err, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 458, S: this });
554
440
  });
555
441
  this._outgoingRequests.delete(id);
556
442
  };
557
443
  });
558
444
  }
559
445
  async _sendMessage(message, timeout) {
560
- DEBUG_CALLS && log("sending message", {
446
+ DEBUG_CALLS && log.trace("sending message", {
561
447
  type: Object.keys(message)[0]
562
- }, {
563
- F: __dxlog_file,
564
- L: 486,
565
- S: this,
566
- C: (f, a) => f(...a)
567
- });
448
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 465, S: this });
568
449
  await this._params.port.send(getRpcMessageCodec().encode(message, {
569
450
  preserveAny: true
570
451
  }), timeout);
571
452
  }
453
+ _getHandlerRpcOptions(req) {
454
+ let traceCtx;
455
+ if (req.traceContext) {
456
+ try {
457
+ traceCtx = ContextRpcCodec.decode(req.traceContext);
458
+ } catch (err) {
459
+ log.warn("failed to decode trace context", {
460
+ traceContext: req.traceContext,
461
+ err
462
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 478, S: this });
463
+ }
464
+ }
465
+ if (!traceCtx && !this._params.handlerRpcOptions) {
466
+ return void 0;
467
+ }
468
+ return {
469
+ ...this._params.handlerRpcOptions,
470
+ ...traceCtx ? {
471
+ ctx: traceCtx
472
+ } : {}
473
+ };
474
+ }
572
475
  async _callHandler(req) {
573
476
  try {
574
- invariant(typeof req.id === "number", void 0, {
575
- F: __dxlog_file,
576
- L: 492,
577
- S: this,
578
- A: [
579
- "typeof req.id === 'number'",
580
- ""
581
- ]
582
- });
583
- invariant(req.payload, void 0, {
584
- F: __dxlog_file,
585
- L: 493,
586
- S: this,
587
- A: [
588
- "req.payload",
589
- ""
590
- ]
591
- });
592
- invariant(req.method, void 0, {
593
- F: __dxlog_file,
594
- L: 494,
595
- S: this,
596
- A: [
597
- "req.method",
598
- ""
599
- ]
600
- });
601
- const response = await this._params.callHandler(req.method, req.payload, this._params.handlerRpcOptions);
477
+ invariant(typeof req.id === "number", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 496, S: this, A: ["typeof req.id === 'number'", ""] });
478
+ invariant(req.payload, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 497, S: this, A: ["req.payload", ""] });
479
+ invariant(req.method, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 498, S: this, A: ["req.method", ""] });
480
+ const response = await this._params.callHandler(req.method, req.payload, this._getHandlerRpcOptions(req));
602
481
  return {
603
482
  id: req.id,
604
483
  payload: response
@@ -612,43 +491,11 @@ ${stack.getStack()}`;
612
491
  }
613
492
  _callStreamHandler(req, callback) {
614
493
  try {
615
- invariant(this._params.streamHandler, "Requests with streaming responses are not supported.", {
616
- F: __dxlog_file,
617
- L: 511,
618
- S: this,
619
- A: [
620
- "this._params.streamHandler",
621
- "'Requests with streaming responses are not supported.'"
622
- ]
623
- });
624
- invariant(typeof req.id === "number", void 0, {
625
- F: __dxlog_file,
626
- L: 512,
627
- S: this,
628
- A: [
629
- "typeof req.id === 'number'",
630
- ""
631
- ]
632
- });
633
- invariant(req.payload, void 0, {
634
- F: __dxlog_file,
635
- L: 513,
636
- S: this,
637
- A: [
638
- "req.payload",
639
- ""
640
- ]
641
- });
642
- invariant(req.method, void 0, {
643
- F: __dxlog_file,
644
- L: 514,
645
- S: this,
646
- A: [
647
- "req.method",
648
- ""
649
- ]
650
- });
651
- const responseStream = this._params.streamHandler(req.method, req.payload, this._params.handlerRpcOptions);
494
+ invariant(this._params.streamHandler, "Requests with streaming responses are not supported.", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 513, S: this, A: ["this._params.streamHandler", "'Requests with streaming responses are not supported.'"] });
495
+ invariant(typeof req.id === "number", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 514, S: this, A: ["typeof req.id === 'number'", ""] });
496
+ invariant(req.payload, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 515, S: this, A: ["req.payload", ""] });
497
+ invariant(req.method, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 516, S: this, A: ["req.method", ""] });
498
+ const responseStream = this._params.streamHandler(req.method, req.payload, this._getHandlerRpcOptions(req));
652
499
  responseStream.onReady(() => {
653
500
  callback({
654
501
  id: req.id,
@@ -681,24 +528,6 @@ ${stack.getStack()}`;
681
528
  });
682
529
  }
683
530
  }
684
- constructor(params) {
685
- _define_property(this, "_params", void 0);
686
- _define_property(this, "_outgoingRequests", /* @__PURE__ */ new Map());
687
- _define_property(this, "_localStreams", /* @__PURE__ */ new Map());
688
- _define_property(this, "_remoteOpenTrigger", new Trigger());
689
- _define_property(this, "_closingTrigger", new Trigger());
690
- _define_property(this, "_byeTrigger", new Trigger());
691
- _define_property(this, "_nextId", 0);
692
- _define_property(this, "_state", "INITIAL");
693
- _define_property(this, "_unsubscribeFromPort", void 0);
694
- _define_property(this, "_clearOpenInterval", void 0);
695
- this._params = {
696
- timeout: void 0,
697
- streamHandler: void 0,
698
- noHandshake: false,
699
- ...params
700
- };
701
- }
702
531
  };
703
532
  _ts_decorate([
704
533
  synchronized
@@ -719,22 +548,15 @@ var throwIfNotOpen = (state) => {
719
548
 
720
549
  // src/service.ts
721
550
  import { invariant as invariant2 } from "@dxos/invariant";
722
- function _define_property2(obj, key, value) {
723
- if (key in obj) {
724
- Object.defineProperty(obj, key, {
725
- value,
726
- enumerable: true,
727
- configurable: true,
728
- writable: true
729
- });
730
- } else {
731
- obj[key] = value;
732
- }
733
- return obj;
734
- }
735
551
  var __dxlog_file2 = "/__w/dxos/dxos/packages/core/mesh/rpc/src/service.ts";
736
552
  var createServiceBundle = (services) => services;
737
553
  var ProtoRpcPeer = class {
554
+ rpc;
555
+ _peer;
556
+ constructor(rpc, _peer) {
557
+ this.rpc = rpc;
558
+ this._peer = _peer;
559
+ }
738
560
  async open() {
739
561
  await this._peer.open();
740
562
  }
@@ -744,25 +566,11 @@ var ProtoRpcPeer = class {
744
566
  async abort() {
745
567
  await this._peer.abort();
746
568
  }
747
- constructor(rpc, _peer) {
748
- _define_property2(this, "rpc", void 0);
749
- _define_property2(this, "_peer", void 0);
750
- this.rpc = rpc;
751
- this._peer = _peer;
752
- }
753
569
  };
754
570
  var createProtoRpcPeer = ({ requested, exposed, handlers, encodingOptions, ...rest }) => {
755
571
  const exposedRpcs = {};
756
572
  if (exposed) {
757
- invariant2(handlers, void 0, {
758
- F: __dxlog_file2,
759
- L: 93,
760
- S: void 0,
761
- A: [
762
- "handlers",
763
- ""
764
- ]
765
- });
573
+ invariant2(handlers, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file2, L: 37, S: void 0, A: ["handlers", ""] });
766
574
  for (const serviceName of Object.keys(exposed)) {
767
575
  const serviceFqn = exposed[serviceName].serviceProto.fullName.slice(1);
768
576
  const serviceProvider = handlers[serviceName];
@@ -896,29 +704,12 @@ var encodeMessage = (msg) => isNode() ? Buffer.from(msg) : new TextEncoder().enc
896
704
  // src/trace.ts
897
705
  import { Event } from "@dxos/async";
898
706
  import { MessageTrace } from "@dxos/protocols/proto/dxos/rpc";
899
- function _define_property3(obj, key, value) {
900
- if (key in obj) {
901
- Object.defineProperty(obj, key, {
902
- value,
903
- enumerable: true,
904
- configurable: true,
905
- writable: true
906
- });
907
- } else {
908
- obj[key] = value;
909
- }
910
- return obj;
911
- }
912
707
  var PortTracer = class {
913
- get port() {
914
- return this._port;
915
- }
708
+ _wrappedPort;
709
+ message = new Event();
710
+ _port;
916
711
  constructor(_wrappedPort) {
917
- _define_property3(this, "_wrappedPort", void 0);
918
- _define_property3(this, "message", void 0);
919
- _define_property3(this, "_port", void 0);
920
712
  this._wrappedPort = _wrappedPort;
921
- this.message = new Event();
922
713
  this._port = {
923
714
  send: (msg) => {
924
715
  this.message.emit({
@@ -938,6 +729,9 @@ var PortTracer = class {
938
729
  }
939
730
  };
940
731
  }
732
+ get port() {
733
+ return this._port;
734
+ }
941
735
  };
942
736
  export {
943
737
  PortTracer,