@dxos/teleport 0.3.5-main.8a2ebe5 → 0.3.5-main.8a3798d

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.
@@ -40,7 +40,7 @@ module.exports = __toCommonJS(testing_exports);
40
40
 
41
41
  // packages/core/mesh/teleport/src/testing/test-builder.ts
42
42
  var import_node_stream3 = require("node:stream");
43
- var import_invariant4 = require("@dxos/invariant");
43
+ var import_invariant5 = require("@dxos/invariant");
44
44
  var import_keys2 = require("@dxos/keys");
45
45
  var import_log5 = require("@dxos/log");
46
46
 
@@ -48,7 +48,7 @@ var import_log5 = require("@dxos/log");
48
48
  var import_async4 = require("@dxos/async");
49
49
  var import_context2 = require("@dxos/context");
50
50
  var import_debug2 = require("@dxos/debug");
51
- var import_invariant3 = require("@dxos/invariant");
51
+ var import_invariant4 = require("@dxos/invariant");
52
52
  var import_keys = require("@dxos/keys");
53
53
  var import_log4 = require("@dxos/log");
54
54
  var import_protocols2 = require("@dxos/protocols");
@@ -226,13 +226,14 @@ var import_node_stream2 = require("node:stream");
226
226
  var import_async3 = require("@dxos/async");
227
227
  var import_context = require("@dxos/context");
228
228
  var import_debug = require("@dxos/debug");
229
- var import_invariant2 = require("@dxos/invariant");
229
+ var import_invariant3 = require("@dxos/invariant");
230
230
  var import_log3 = require("@dxos/log");
231
231
  var import_protocols = require("@dxos/protocols");
232
232
 
233
233
  // packages/core/mesh/teleport/src/muxing/balancer.ts
234
234
  var varint = __toESM(require("varint"));
235
235
  var import_async2 = require("@dxos/async");
236
+ var import_invariant2 = require("@dxos/invariant");
236
237
  var import_log2 = require("@dxos/log");
237
238
  var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/muxing/balancer.ts";
238
239
  var MAX_CHUNK_SIZE = 8192;
@@ -244,6 +245,7 @@ var Balancer = class {
244
245
  this._framer = new Framer();
245
246
  this._sendBuffers = /* @__PURE__ */ new Map();
246
247
  this._receiveBuffers = /* @__PURE__ */ new Map();
248
+ this._sending = false;
247
249
  this.incomingData = new import_async2.Event();
248
250
  this.stream = this._framer.stream;
249
251
  this._channels.push(_sysChannelId);
@@ -262,43 +264,19 @@ var Balancer = class {
262
264
  this._channels.push(channel);
263
265
  }
264
266
  pushData(data, trigger, channelId) {
265
- const noCalls = this._sendBuffers.size === 0;
266
- if (!this._channels.includes(channelId)) {
267
- throw new Error(`Unknown channel ${channelId}`);
268
- }
269
- if (!this._sendBuffers.has(channelId)) {
270
- this._sendBuffers.set(channelId, []);
271
- }
272
- const sendBuffer = this._sendBuffers.get(channelId);
273
- const chunks = [];
274
- for (let idx = 0; idx < data.length; idx += MAX_CHUNK_SIZE) {
275
- chunks.push(data.subarray(idx, idx + MAX_CHUNK_SIZE));
276
- }
277
- chunks.forEach((chunk, index) => {
278
- const msg = encodeChunk({
279
- chunk,
280
- channelId,
281
- dataLength: index === 0 ? data.length : void 0
282
- });
283
- sendBuffer.push({
284
- msg,
285
- trigger: index === chunks.length - 1 ? trigger : void 0
286
- });
287
- });
288
- if (noCalls) {
289
- this._sendChunk().catch((err) => import_log2.log.catch(err, void 0, {
290
- F: __dxlog_file2,
291
- L: 100,
292
- S: this,
293
- C: (f, a) => f(...a)
294
- }));
295
- }
267
+ this._enqueueChunk(data, trigger, channelId);
268
+ this._sendChunks().catch((err) => import_log2.log.catch(err, void 0, {
269
+ F: __dxlog_file2,
270
+ L: 75,
271
+ S: this,
272
+ C: (f, a) => f(...a)
273
+ }));
296
274
  }
297
275
  destroy() {
298
276
  if (this._sendBuffers.size !== 0) {
299
277
  import_log2.log.warn("destroying balancer with pending calls", void 0, {
300
278
  F: __dxlog_file2,
301
- L: 106,
279
+ L: 80,
302
280
  S: this,
303
281
  C: (f, a) => f(...a)
304
282
  });
@@ -339,36 +317,99 @@ var Balancer = class {
339
317
  this._lastCallerIndex = (this._lastCallerIndex + 1) % this._channels.length;
340
318
  return this._channels[index];
341
319
  }
320
+ _enqueueChunk(data, trigger, channelId) {
321
+ if (!this._channels.includes(channelId)) {
322
+ throw new Error(`Unknown channel ${channelId}`);
323
+ }
324
+ if (!this._sendBuffers.has(channelId)) {
325
+ this._sendBuffers.set(channelId, []);
326
+ }
327
+ const sendBuffer = this._sendBuffers.get(channelId);
328
+ const chunks = [];
329
+ for (let idx = 0; idx < data.length; idx += MAX_CHUNK_SIZE) {
330
+ chunks.push(data.subarray(idx, idx + MAX_CHUNK_SIZE));
331
+ }
332
+ chunks.forEach((chunk, index) => {
333
+ const msg = encodeChunk({
334
+ chunk,
335
+ channelId,
336
+ dataLength: index === 0 ? data.length : void 0
337
+ });
338
+ sendBuffer.push({
339
+ msg,
340
+ trigger: index === chunks.length - 1 ? trigger : void 0
341
+ });
342
+ });
343
+ }
344
+ // get the next chunk or null if there are no chunks remaining
342
345
  _getNextChunk() {
343
346
  let chunk;
344
- while (!chunk) {
347
+ while (this._sendBuffers.size > 0) {
345
348
  const channelId = this._getNextCallerId();
346
349
  const sendBuffer = this._sendBuffers.get(channelId);
347
350
  if (!sendBuffer) {
348
351
  continue;
349
352
  }
350
353
  chunk = sendBuffer.shift();
354
+ if (!chunk) {
355
+ continue;
356
+ }
351
357
  if (sendBuffer.length === 0) {
352
358
  this._sendBuffers.delete(channelId);
353
359
  }
360
+ return chunk;
354
361
  }
355
- return chunk;
362
+ return null;
356
363
  }
357
- async _sendChunk() {
358
- if (this._sendBuffers.size === 0) {
364
+ async _sendChunks() {
365
+ if (this._sending) {
359
366
  return;
360
367
  }
361
- if (!this._framer.writable) {
362
- await this._framer.drain.waitForCount(1);
363
- }
364
- const chunk = this._getNextChunk();
365
- try {
366
- await this._framer.port.send(chunk.msg);
367
- chunk.trigger?.wake();
368
- } catch (err) {
369
- chunk.trigger?.throw(err);
368
+ this._sending = true;
369
+ let chunk;
370
+ chunk = this._getNextChunk();
371
+ while (chunk) {
372
+ if (!this._framer.writable) {
373
+ (0, import_log2.log)("PAUSE for drain", void 0, {
374
+ F: __dxlog_file2,
375
+ L: 179,
376
+ S: this,
377
+ C: (f, a) => f(...a)
378
+ });
379
+ await this._framer.drain.waitForCount(1);
380
+ (0, import_log2.log)("RESUME for drain", void 0, {
381
+ F: __dxlog_file2,
382
+ L: 181,
383
+ S: this,
384
+ C: (f, a) => f(...a)
385
+ });
386
+ }
387
+ try {
388
+ await this._framer.port.send(chunk.msg);
389
+ chunk.trigger?.wake();
390
+ } catch (err) {
391
+ (0, import_log2.log)("Error sending chunk", {
392
+ err
393
+ }, {
394
+ F: __dxlog_file2,
395
+ L: 187,
396
+ S: this,
397
+ C: (f, a) => f(...a)
398
+ });
399
+ chunk.trigger?.throw(err);
400
+ }
401
+ chunk = this._getNextChunk();
370
402
  }
371
- await this._sendChunk();
403
+ (0, import_invariant2.invariant)(this._sendBuffers.size === 0, "sendBuffers not empty", {
404
+ F: __dxlog_file2,
405
+ L: 192,
406
+ S: this,
407
+ A: [
408
+ "this._sendBuffers.size === 0",
409
+ "'sendBuffers not empty'"
410
+ ]
411
+ });
412
+ this._sending = false;
372
413
  }
373
414
  };
374
415
  var encodeChunk = ({ channelId, dataLength, chunk }) => {
@@ -401,6 +442,8 @@ var decodeChunk = (data, withLength) => {
401
442
  // packages/core/mesh/teleport/src/muxing/muxer.ts
402
443
  var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/muxing/muxer.ts";
403
444
  var Command = import_protocols.schema.getCodecForType("dxos.mesh.muxer.Command");
445
+ var DEFAULT_SEND_COMMAND_TIMEOUT = 6e4;
446
+ var DESTROY_COMMAND_SEND_TIMEOUT = 5e3;
404
447
  var STATS_INTERVAL = 1e3;
405
448
  var MAX_SAFE_FRAME_SIZE = 1e6;
406
449
  var SYSTEM_CHANNEL_ID = 0;
@@ -412,9 +455,9 @@ var Muxer = class {
412
455
  this._channelsByTag = /* @__PURE__ */ new Map();
413
456
  this._ctx = new import_context.Context();
414
457
  this._nextId = 1;
415
- this._destroyed = false;
416
- this._destroying = false;
417
458
  this._closing = false;
459
+ this._destroying = false;
460
+ this._disposed = false;
418
461
  this._lastStats = void 0;
419
462
  this._lastChannelStats = /* @__PURE__ */ new Map();
420
463
  this.afterClosed = new import_async3.Event();
@@ -423,7 +466,6 @@ var Muxer = class {
423
466
  this._balancer.incomingData.on(async (msg) => {
424
467
  await this._handleCommand(Command.decode(msg));
425
468
  });
426
- (0, import_async3.scheduleTaskInterval)(this._ctx, async () => this._emitStats(), STATS_INTERVAL);
427
469
  }
428
470
  /**
429
471
  * Creates a duplex Node.js-style stream.
@@ -436,9 +478,9 @@ var Muxer = class {
436
478
  tag,
437
479
  contentType: opts.contentType
438
480
  });
439
- (0, import_invariant2.invariant)(!channel.push, `Channel already open: ${tag}`, {
481
+ (0, import_invariant3.invariant)(!channel.push, `Channel already open: ${tag}`, {
440
482
  F: __dxlog_file3,
441
- L: 138,
483
+ L: 140,
442
484
  S: this,
443
485
  A: [
444
486
  "!channel.push",
@@ -484,9 +526,9 @@ var Muxer = class {
484
526
  tag,
485
527
  contentType: opts.contentType
486
528
  });
487
- (0, import_invariant2.invariant)(!channel.push, `Channel already open: ${tag}`, {
529
+ (0, import_invariant3.invariant)(!channel.push, `Channel already open: ${tag}`, {
488
530
  F: __dxlog_file3,
489
- L: 190,
531
+ L: 192,
490
532
  S: this,
491
533
  A: [
492
534
  "!channel.push",
@@ -504,13 +546,13 @@ var Muxer = class {
504
546
  }
505
547
  };
506
548
  const port = {
507
- send: async (data) => {
508
- await this._sendData(channel, data);
549
+ send: async (data, timeout) => {
550
+ await this._sendData(channel, data, timeout);
509
551
  },
510
552
  subscribe: (cb) => {
511
- (0, import_invariant2.invariant)(!callback, "Only one subscriber is allowed", {
553
+ (0, import_invariant3.invariant)(!callback, "Only one subscriber is allowed", {
512
554
  F: __dxlog_file3,
513
- L: 212,
555
+ L: 214,
514
556
  S: this,
515
557
  A: [
516
558
  "!callback",
@@ -543,7 +585,7 @@ var Muxer = class {
543
585
  if (this._destroying) {
544
586
  (0, import_log3.log)("already destroying, ignoring graceful close request", void 0, {
545
587
  F: __dxlog_file3,
546
- L: 245,
588
+ L: 247,
547
589
  S: this,
548
590
  C: (f, a) => f(...a)
549
591
  });
@@ -552,7 +594,7 @@ var Muxer = class {
552
594
  if (this._closing) {
553
595
  (0, import_log3.log)("already closing, ignoring graceful close request", void 0, {
554
596
  F: __dxlog_file3,
555
- L: 249,
597
+ L: 251,
556
598
  S: this,
557
599
  C: (f, a) => f(...a)
558
600
  });
@@ -563,12 +605,12 @@ var Muxer = class {
563
605
  close: {
564
606
  error: err?.message
565
607
  }
566
- }, SYSTEM_CHANNEL_ID).catch(async (err2) => {
608
+ }, SYSTEM_CHANNEL_ID, DESTROY_COMMAND_SEND_TIMEOUT).catch(async (err2) => {
567
609
  (0, import_log3.log)("error sending close command", {
568
610
  err: err2
569
611
  }, {
570
612
  F: __dxlog_file3,
571
- L: 263,
613
+ L: 266,
572
614
  S: this,
573
615
  C: (f, a) => f(...a)
574
616
  });
@@ -590,7 +632,7 @@ var Muxer = class {
590
632
  if (this._destroying) {
591
633
  (0, import_log3.log)("already destroying, ignoring destroy request", void 0, {
592
634
  F: __dxlog_file3,
593
- L: 284,
635
+ L: 287,
594
636
  S: this,
595
637
  C: (f, a) => f(...a)
596
638
  });
@@ -601,7 +643,7 @@ var Muxer = class {
601
643
  if (this._closing) {
602
644
  (0, import_log3.log)("destroy cancelling graceful close", void 0, {
603
645
  F: __dxlog_file3,
604
- L: 290,
646
+ L: 293,
605
647
  S: this,
606
648
  C: (f, a) => f(...a)
607
649
  });
@@ -616,7 +658,7 @@ var Muxer = class {
616
658
  err: err2
617
659
  }, {
618
660
  F: __dxlog_file3,
619
- L: 303,
661
+ L: 306,
620
662
  S: this,
621
663
  C: (f, a) => f(...a)
622
664
  });
@@ -627,7 +669,7 @@ var Muxer = class {
627
669
  err: err2
628
670
  }, {
629
671
  F: __dxlog_file3,
630
- L: 308,
672
+ L: 311,
631
673
  S: this,
632
674
  C: (f, a) => f(...a)
633
675
  });
@@ -635,10 +677,10 @@ var Muxer = class {
635
677
  }
636
678
  // complete the termination, graceful or otherwise
637
679
  async dispose(err) {
638
- if (this._destroyed) {
680
+ if (this._disposed) {
639
681
  (0, import_log3.log)("already destroyed, ignoring dispose request", void 0, {
640
682
  F: __dxlog_file3,
641
- L: 316,
683
+ L: 319,
642
684
  S: this,
643
685
  C: (f, a) => f(...a)
644
686
  });
@@ -649,18 +691,18 @@ var Muxer = class {
649
691
  for (const channel of this._channelsByTag.values()) {
650
692
  channel.destroy?.(err);
651
693
  }
652
- this._destroyed = true;
694
+ this._disposed = true;
653
695
  this.afterClosed.emit(err);
654
696
  this._channelsByLocalId.clear();
655
697
  this._channelsByTag.clear();
656
698
  }
657
699
  async _handleCommand(cmd) {
658
- if (this._destroyed) {
700
+ if (this._disposed) {
659
701
  import_log3.log.warn("Received command after destroy", {
660
702
  cmd
661
703
  }, {
662
704
  F: __dxlog_file3,
663
- L: 338,
705
+ L: 341,
664
706
  S: this,
665
707
  C: (f, a) => f(...a)
666
708
  });
@@ -670,7 +712,7 @@ var Muxer = class {
670
712
  if (!this._closing) {
671
713
  (0, import_log3.log)("received peer close, initiating my own graceful close", void 0, {
672
714
  F: __dxlog_file3,
673
- L: 344,
715
+ L: 347,
674
716
  S: this,
675
717
  C: (f, a) => f(...a)
676
718
  });
@@ -678,7 +720,7 @@ var Muxer = class {
678
720
  } else {
679
721
  (0, import_log3.log)("received close from peer, already closing", void 0, {
680
722
  F: __dxlog_file3,
681
- L: 347,
723
+ L: 350,
682
724
  S: this,
683
725
  C: (f, a) => f(...a)
684
726
  });
@@ -707,7 +749,7 @@ var Muxer = class {
707
749
  tag: stream.tag
708
750
  }, {
709
751
  F: __dxlog_file3,
710
- L: 376,
752
+ L: 379,
711
753
  S: this,
712
754
  C: (f, a) => f(...a)
713
755
  });
@@ -716,16 +758,21 @@ var Muxer = class {
716
758
  stream.push(cmd.data.data);
717
759
  }
718
760
  }
719
- async _sendCommand(cmd, channelId = -1) {
761
+ async _sendCommand(cmd, channelId = -1, timeout = DEFAULT_SEND_COMMAND_TIMEOUT) {
720
762
  try {
721
763
  const trigger = new import_async3.Trigger();
722
764
  this._balancer.pushData(Command.encode(cmd), trigger, channelId);
723
- await trigger.wait();
765
+ await trigger.wait({
766
+ timeout
767
+ });
724
768
  } catch (err) {
725
769
  await this.destroy(err);
726
770
  }
727
771
  }
728
772
  _getOrCreateStream(params) {
773
+ if (this._channelsByTag.size === 0) {
774
+ (0, import_async3.scheduleTaskInterval)(this._ctx, async () => this._emitStats(), STATS_INTERVAL);
775
+ }
729
776
  let channel = this._channelsByTag.get(params.tag);
730
777
  if (!channel) {
731
778
  channel = {
@@ -747,14 +794,14 @@ var Muxer = class {
747
794
  }
748
795
  return channel;
749
796
  }
750
- async _sendData(channel, data) {
797
+ async _sendData(channel, data, timeout) {
751
798
  if (data.length > MAX_SAFE_FRAME_SIZE) {
752
799
  import_log3.log.warn("frame size exceeds maximum safe value", {
753
800
  size: data.length,
754
801
  threshold: MAX_SAFE_FRAME_SIZE
755
802
  }, {
756
803
  F: __dxlog_file3,
757
- L: 419,
804
+ L: 425,
758
805
  S: this,
759
806
  C: (f, a) => f(...a)
760
807
  });
@@ -769,7 +816,7 @@ var Muxer = class {
769
816
  channelId: channel.remoteId,
770
817
  data
771
818
  }
772
- }, channel.id);
819
+ }, channel.id, timeout);
773
820
  }
774
821
  _destroyChannel(channel, err) {
775
822
  if (channel.destroy) {
@@ -779,7 +826,7 @@ var Muxer = class {
779
826
  this._channelsByTag.delete(channel.tag);
780
827
  }
781
828
  async _emitStats() {
782
- if (this._destroyed || this._destroying) {
829
+ if (this._disposed || this._destroying) {
783
830
  this._lastStats = void 0;
784
831
  this._lastChannelStats.clear();
785
832
  return;
@@ -832,6 +879,8 @@ function _ts_decorate(decorators, target, key, desc) {
832
879
  return c > 3 && r && Object.defineProperty(target, key, r), r;
833
880
  }
834
881
  var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/teleport.ts";
882
+ var CONTROL_HEARTBEAT_INTERVAL = 1e4;
883
+ var CONTROL_HEARTBEAT_TIMEOUT = 6e4;
835
884
  var Teleport = class {
836
885
  constructor({ initiator, localPeerId, remotePeerId }) {
837
886
  this._ctx = new import_context2.Context({
@@ -839,7 +888,7 @@ var Teleport = class {
839
888
  void this.destroy(err).catch(() => {
840
889
  import_log4.log.error("Error during destroy", err, {
841
890
  F: __dxlog_file4,
842
- L: 44,
891
+ L: 47,
843
892
  S: this,
844
893
  C: (f, a) => f(...a)
845
894
  });
@@ -848,21 +897,21 @@ var Teleport = class {
848
897
  });
849
898
  this._muxer = new Muxer();
850
899
  this._control = new ControlExtension({
851
- heartbeatInterval: 1e4,
852
- heartbeatTimeout: 1e4,
900
+ heartbeatInterval: CONTROL_HEARTBEAT_INTERVAL,
901
+ heartbeatTimeout: CONTROL_HEARTBEAT_TIMEOUT,
853
902
  onTimeout: () => {
854
903
  if (this._destroying || this._aborting) {
855
904
  return;
856
905
  }
857
- (0, import_log4.log)("destroy teleport due to onTimeout in ControlExtension", void 0, {
906
+ (0, import_log4.log)("abort teleport due to onTimeout in ControlExtension", void 0, {
858
907
  F: __dxlog_file4,
859
- L: 59,
908
+ L: 62,
860
909
  S: this,
861
910
  C: (f, a) => f(...a)
862
911
  });
863
- this.destroy(new import_protocols2.TimeoutError("control extension")).catch((err) => import_log4.log.catch(err, void 0, {
912
+ this.abort(new import_protocols2.TimeoutError("control extension")).catch((err) => import_log4.log.catch(err, void 0, {
864
913
  F: __dxlog_file4,
865
- L: 60,
914
+ L: 63,
866
915
  S: this,
867
916
  C: (f, a) => f(...a)
868
917
  }));
@@ -873,27 +922,27 @@ var Teleport = class {
873
922
  this._open = false;
874
923
  this._destroying = false;
875
924
  this._aborting = false;
876
- (0, import_invariant3.invariant)(typeof initiator === "boolean", void 0, {
925
+ (0, import_invariant4.invariant)(typeof initiator === "boolean", void 0, {
877
926
  F: __dxlog_file4,
878
- L: 72,
927
+ L: 75,
879
928
  S: this,
880
929
  A: [
881
930
  "typeof initiator === 'boolean'",
882
931
  ""
883
932
  ]
884
933
  });
885
- (0, import_invariant3.invariant)(import_keys.PublicKey.isPublicKey(localPeerId), void 0, {
934
+ (0, import_invariant4.invariant)(import_keys.PublicKey.isPublicKey(localPeerId), void 0, {
886
935
  F: __dxlog_file4,
887
- L: 73,
936
+ L: 76,
888
937
  S: this,
889
938
  A: [
890
939
  "PublicKey.isPublicKey(localPeerId)",
891
940
  ""
892
941
  ]
893
942
  });
894
- (0, import_invariant3.invariant)(import_keys.PublicKey.isPublicKey(remotePeerId), void 0, {
943
+ (0, import_invariant4.invariant)(import_keys.PublicKey.isPublicKey(remotePeerId), void 0, {
895
944
  F: __dxlog_file4,
896
- L: 74,
945
+ L: 77,
897
946
  S: this,
898
947
  A: [
899
948
  "PublicKey.isPublicKey(remotePeerId)",
@@ -908,13 +957,13 @@ var Teleport = class {
908
957
  name
909
958
  }, {
910
959
  F: __dxlog_file4,
911
- L: 80,
960
+ L: 83,
912
961
  S: this,
913
962
  C: (f, a) => f(...a)
914
963
  });
915
- (0, import_invariant3.invariant)(!this._remoteExtensions.has(name), "Remote extension already exists", {
964
+ (0, import_invariant4.invariant)(!this._remoteExtensions.has(name), "Remote extension already exists", {
916
965
  F: __dxlog_file4,
917
- L: 81,
966
+ L: 84,
918
967
  S: this,
919
968
  A: [
920
969
  "!this._remoteExtensions.has(name)",
@@ -935,7 +984,7 @@ var Teleport = class {
935
984
  if (this._destroying || this._aborting) {
936
985
  (0, import_log4.log)("destroy teleport due to muxer stream close, skipping due to already destroying/aborting", void 0, {
937
986
  F: __dxlog_file4,
938
- L: 97,
987
+ L: 100,
939
988
  S: this,
940
989
  C: (f, a) => f(...a)
941
990
  });
@@ -958,7 +1007,7 @@ var Teleport = class {
958
1007
  channels: stats.channels
959
1008
  }, {
960
1009
  F: __dxlog_file4,
961
- L: 110,
1010
+ L: 113,
962
1011
  S: this,
963
1012
  C: (f, a) => f(...a)
964
1013
  });
@@ -996,7 +1045,7 @@ var Teleport = class {
996
1045
  } catch (err2) {
997
1046
  import_log4.log.catch(err2, void 0, {
998
1047
  F: __dxlog_file4,
999
- L: 163,
1048
+ L: 166,
1000
1049
  S: this,
1001
1050
  C: (f, a) => f(...a)
1002
1051
  });
@@ -1019,7 +1068,7 @@ var Teleport = class {
1019
1068
  } catch (err2) {
1020
1069
  import_log4.log.catch(err2, void 0, {
1021
1070
  F: __dxlog_file4,
1022
- L: 187,
1071
+ L: 190,
1023
1072
  S: this,
1024
1073
  C: (f, a) => f(...a)
1025
1074
  });
@@ -1035,7 +1084,7 @@ var Teleport = class {
1035
1084
  name
1036
1085
  }, {
1037
1086
  F: __dxlog_file4,
1038
- L: 199,
1087
+ L: 202,
1039
1088
  S: this,
1040
1089
  C: (f, a) => f(...a)
1041
1090
  });
@@ -1057,18 +1106,18 @@ var Teleport = class {
1057
1106
  }
1058
1107
  }
1059
1108
  _setExtension(extensionName, extension) {
1060
- (0, import_invariant3.invariant)(!extensionName.includes("/"), "Invalid extension name", {
1109
+ (0, import_invariant4.invariant)(!extensionName.includes("/"), "Invalid extension name", {
1061
1110
  F: __dxlog_file4,
1062
- L: 223,
1111
+ L: 226,
1063
1112
  S: this,
1064
1113
  A: [
1065
1114
  "!extensionName.includes('/')",
1066
1115
  "'Invalid extension name'"
1067
1116
  ]
1068
1117
  });
1069
- (0, import_invariant3.invariant)(!this._extensions.has(extensionName), "Extension already exists", {
1118
+ (0, import_invariant4.invariant)(!this._extensions.has(extensionName), "Extension already exists", {
1070
1119
  F: __dxlog_file4,
1071
- L: 224,
1120
+ L: 227,
1072
1121
  S: this,
1073
1122
  A: [
1074
1123
  "!this._extensions.has(extensionName)",
@@ -1082,7 +1131,7 @@ var Teleport = class {
1082
1131
  extensionName
1083
1132
  }, {
1084
1133
  F: __dxlog_file4,
1085
- L: 229,
1134
+ L: 232,
1086
1135
  S: this,
1087
1136
  C: (f, a) => f(...a)
1088
1137
  });
@@ -1092,9 +1141,9 @@ var Teleport = class {
1092
1141
  localPeerId: this.localPeerId,
1093
1142
  remotePeerId: this.remotePeerId,
1094
1143
  createPort: async (channelName, opts) => {
1095
- (0, import_invariant3.invariant)(!channelName.includes("/"), "Invalid channel name", {
1144
+ (0, import_invariant4.invariant)(!channelName.includes("/"), "Invalid channel name", {
1096
1145
  F: __dxlog_file4,
1097
- L: 237,
1146
+ L: 240,
1098
1147
  S: this,
1099
1148
  A: [
1100
1149
  "!channelName.includes('/')",
@@ -1104,9 +1153,9 @@ var Teleport = class {
1104
1153
  return this._muxer.createPort(`${extensionName}/${channelName}`, opts);
1105
1154
  },
1106
1155
  createStream: async (channelName, opts) => {
1107
- (0, import_invariant3.invariant)(!channelName.includes("/"), "Invalid channel name", {
1156
+ (0, import_invariant4.invariant)(!channelName.includes("/"), "Invalid channel name", {
1108
1157
  F: __dxlog_file4,
1109
- L: 241,
1158
+ L: 244,
1110
1159
  S: this,
1111
1160
  A: [
1112
1161
  "!channelName.includes('/')",
@@ -1126,7 +1175,7 @@ var Teleport = class {
1126
1175
  extensionName
1127
1176
  }, {
1128
1177
  F: __dxlog_file4,
1129
- L: 252,
1178
+ L: 255,
1130
1179
  S: this,
1131
1180
  C: (f, a) => f(...a)
1132
1181
  });
@@ -1214,7 +1263,7 @@ var TestBuilder = class {
1214
1263
  await Promise.all(Array.from(this._peers).map((agent) => agent.destroy()));
1215
1264
  }
1216
1265
  async connect(peer1, peer2) {
1217
- (0, import_invariant4.invariant)(peer1 !== peer2, void 0, {
1266
+ (0, import_invariant5.invariant)(peer1 !== peer2, void 0, {
1218
1267
  F: __dxlog_file5,
1219
1268
  L: 37,
1220
1269
  S: this,
@@ -1223,7 +1272,7 @@ var TestBuilder = class {
1223
1272
  ""
1224
1273
  ]
1225
1274
  });
1226
- (0, import_invariant4.invariant)(this._peers.has(peer1), void 0, {
1275
+ (0, import_invariant5.invariant)(this._peers.has(peer1), void 0, {
1227
1276
  F: __dxlog_file5,
1228
1277
  L: 38,
1229
1278
  S: this,
@@ -1232,7 +1281,7 @@ var TestBuilder = class {
1232
1281
  ""
1233
1282
  ]
1234
1283
  });
1235
- (0, import_invariant4.invariant)(this._peers.has(peer1), void 0, {
1284
+ (0, import_invariant5.invariant)(this._peers.has(peer1), void 0, {
1236
1285
  F: __dxlog_file5,
1237
1286
  L: 39,
1238
1287
  S: this,
@@ -1260,7 +1309,7 @@ var TestBuilder = class {
1260
1309
  ];
1261
1310
  }
1262
1311
  async disconnect(peer1, peer2) {
1263
- (0, import_invariant4.invariant)(peer1 !== peer2, void 0, {
1312
+ (0, import_invariant5.invariant)(peer1 !== peer2, void 0, {
1264
1313
  F: __dxlog_file5,
1265
1314
  L: 51,
1266
1315
  S: this,
@@ -1269,7 +1318,7 @@ var TestBuilder = class {
1269
1318
  ""
1270
1319
  ]
1271
1320
  });
1272
- (0, import_invariant4.invariant)(this._peers.has(peer1), void 0, {
1321
+ (0, import_invariant5.invariant)(this._peers.has(peer1), void 0, {
1273
1322
  F: __dxlog_file5,
1274
1323
  L: 52,
1275
1324
  S: this,
@@ -1278,7 +1327,7 @@ var TestBuilder = class {
1278
1327
  ""
1279
1328
  ]
1280
1329
  });
1281
- (0, import_invariant4.invariant)(this._peers.has(peer1), void 0, {
1330
+ (0, import_invariant5.invariant)(this._peers.has(peer1), void 0, {
1282
1331
  F: __dxlog_file5,
1283
1332
  L: 53,
1284
1333
  S: this,
@@ -1289,7 +1338,7 @@ var TestBuilder = class {
1289
1338
  });
1290
1339
  const connection1 = Array.from(peer1.connections).find((connection) => connection.remotePeerId.equals(peer2.peerId));
1291
1340
  const connection2 = Array.from(peer2.connections).find((connection) => connection.remotePeerId.equals(peer1.peerId));
1292
- (0, import_invariant4.invariant)(connection1, void 0, {
1341
+ (0, import_invariant5.invariant)(connection1, void 0, {
1293
1342
  F: __dxlog_file5,
1294
1343
  L: 62,
1295
1344
  S: this,
@@ -1298,7 +1347,7 @@ var TestBuilder = class {
1298
1347
  ""
1299
1348
  ]
1300
1349
  });
1301
- (0, import_invariant4.invariant)(connection2, void 0, {
1350
+ (0, import_invariant5.invariant)(connection2, void 0, {
1302
1351
  F: __dxlog_file5,
1303
1352
  L: 63,
1304
1353
  S: this,
@@ -1328,7 +1377,7 @@ var TestPeer = class {
1328
1377
  return connection;
1329
1378
  }
1330
1379
  async openConnection(connection) {
1331
- (0, import_invariant4.invariant)(this.connections.has(connection), void 0, {
1380
+ (0, import_invariant5.invariant)(this.connections.has(connection), void 0, {
1332
1381
  F: __dxlog_file5,
1333
1382
  L: 84,
1334
1383
  S: this,
@@ -1341,7 +1390,7 @@ var TestPeer = class {
1341
1390
  await this.onOpen(connection);
1342
1391
  }
1343
1392
  async closeConnection(connection) {
1344
- (0, import_invariant4.invariant)(this.connections.has(connection), void 0, {
1393
+ (0, import_invariant5.invariant)(this.connections.has(connection), void 0, {
1345
1394
  F: __dxlog_file5,
1346
1395
  L: 90,
1347
1396
  S: this,
@@ -1397,7 +1446,7 @@ var TestConnection = class {
1397
1446
 
1398
1447
  // packages/core/mesh/teleport/src/testing/test-extension.ts
1399
1448
  var import_async5 = require("@dxos/async");
1400
- var import_invariant5 = require("@dxos/invariant");
1449
+ var import_invariant6 = require("@dxos/invariant");
1401
1450
  var import_log6 = require("@dxos/log");
1402
1451
  var import_protocols3 = require("@dxos/protocols");
1403
1452
  var import_rpc2 = require("@dxos/rpc");
@@ -1483,7 +1532,7 @@ var TestExtension = class {
1483
1532
  const res = await (0, import_async5.asyncTimeout)(this._rpc.rpc.TestService.testCall({
1484
1533
  data: message
1485
1534
  }), 1500);
1486
- (0, import_invariant5.invariant)(res.data === message, void 0, {
1535
+ (0, import_invariant6.invariant)(res.data === message, void 0, {
1487
1536
  F: __dxlog_file6,
1488
1537
  L: 84,
1489
1538
  S: this,
@@ -1504,7 +1553,7 @@ var TestExtension = class {
1504
1553
  // packages/core/mesh/teleport/src/testing/test-extension-with-streams.ts
1505
1554
  var import_node_crypto = require("node:crypto");
1506
1555
  var import_async6 = require("@dxos/async");
1507
- var import_invariant6 = require("@dxos/invariant");
1556
+ var import_invariant7 = require("@dxos/invariant");
1508
1557
  var import_log7 = require("@dxos/log");
1509
1558
  var import_protocols4 = require("@dxos/protocols");
1510
1559
  var import_rpc3 = require("@dxos/rpc");
@@ -1521,7 +1570,7 @@ var TestExtensionWithStreams = class {
1521
1570
  return this.extensionContext?.remotePeerId;
1522
1571
  }
1523
1572
  async _openStream(streamTag, interval = 5, chunkSize = 2048) {
1524
- (0, import_invariant6.invariant)(!this._streams.has(streamTag), `Stream already exists: ${streamTag}`, {
1573
+ (0, import_invariant7.invariant)(!this._streams.has(streamTag), `Stream already exists: ${streamTag}`, {
1525
1574
  F: __dxlog_file7,
1526
1575
  L: 39,
1527
1576
  S: this,
@@ -1587,7 +1636,7 @@ var TestExtensionWithStreams = class {
1587
1636
  }, 100);
1588
1637
  }
1589
1638
  _closeStream(streamTag) {
1590
- (0, import_invariant6.invariant)(this._streams.has(streamTag), `Stream does not exist: ${streamTag}`, {
1639
+ (0, import_invariant7.invariant)(this._streams.has(streamTag), `Stream does not exist: ${streamTag}`, {
1591
1640
  F: __dxlog_file7,
1592
1641
  L: 106,
1593
1642
  S: this,
@@ -1710,7 +1759,7 @@ var TestExtensionWithStreams = class {
1710
1759
  streamLoadInterval,
1711
1760
  streamLoadChunkSize
1712
1761
  });
1713
- (0, import_invariant6.invariant)(data === streamTag, void 0, {
1762
+ (0, import_invariant7.invariant)(data === streamTag, void 0, {
1714
1763
  F: __dxlog_file7,
1715
1764
  L: 207,
1716
1765
  S: this,
@@ -1729,7 +1778,7 @@ var TestExtensionWithStreams = class {
1729
1778
  const { data, bytesSent, bytesReceived, sendErrors, receiveErrors, runningTime } = await this._rpc.rpc.TestServiceWithStreams.closeTestStream({
1730
1779
  data: streamTag
1731
1780
  });
1732
- (0, import_invariant6.invariant)(data === streamTag, void 0, {
1781
+ (0, import_invariant7.invariant)(data === streamTag, void 0, {
1733
1782
  F: __dxlog_file7,
1734
1783
  L: 220,
1735
1784
  S: this,