@dxos/teleport 0.1.56-main.e47dfd1 → 0.1.56-main.e79d64a

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.
@@ -46,10 +46,15 @@ module.exports = __toCommonJS(src_exports);
46
46
 
47
47
  // packages/core/mesh/teleport/src/muxing/framer.ts
48
48
  var import_node_stream = require("node:stream");
49
- var import_tiny_invariant = __toESM(require("tiny-invariant"));
49
+ var import_invariant = require("@dxos/invariant");
50
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/muxing/framer.ts";
50
51
  var FRAME_LENGTH_SIZE = 2;
51
52
  var Framer = class {
52
53
  constructor() {
54
+ // private readonly _tagBuffer = Buffer.alloc(4)
55
+ this._messageCb = void 0;
56
+ this._subscribeCb = void 0;
57
+ this._buffer = void 0;
53
58
  this._sendCallbacks = [];
54
59
  this._bytesSent = 0;
55
60
  this._bytesReceived = 0;
@@ -59,7 +64,15 @@ var Framer = class {
59
64
  this._processResponseQueue();
60
65
  },
61
66
  write: (chunk, encoding, callback) => {
62
- (0, import_tiny_invariant.default)(!this._subscribeCb, "Internal Framer bug. Concurrent writes detected.");
67
+ (0, import_invariant.invariant)(!this._subscribeCb, "Internal Framer bug. Concurrent writes detected.", {
68
+ F: __dxlog_file,
69
+ L: 34,
70
+ S: this,
71
+ A: [
72
+ "!this._subscribeCb",
73
+ "'Internal Framer bug. Concurrent writes detected.'"
74
+ ]
75
+ });
63
76
  this._bytesReceived += chunk.length;
64
77
  if (this._buffer && this._buffer.length > 0) {
65
78
  this._buffer = Buffer.concat([
@@ -95,10 +108,17 @@ var Framer = class {
95
108
  });
96
109
  },
97
110
  subscribe: (callback) => {
98
- var _a;
99
- (0, import_tiny_invariant.default)(!this._messageCb, "Rpc port already has a message listener.");
111
+ (0, import_invariant.invariant)(!this._messageCb, "Rpc port already has a message listener.", {
112
+ F: __dxlog_file,
113
+ L: 73,
114
+ S: this,
115
+ A: [
116
+ "!this._messageCb",
117
+ "'Rpc port already has a message listener.'"
118
+ ]
119
+ });
100
120
  this._messageCb = callback;
101
- (_a = this._subscribeCb) == null ? void 0 : _a.call(this);
121
+ this._subscribeCb?.();
102
122
  return () => {
103
123
  this._messageCb = void 0;
104
124
  };
@@ -166,10 +186,10 @@ var encodeFrame = (payload) => {
166
186
 
167
187
  // packages/core/mesh/teleport/src/muxing/muxer.ts
168
188
  var import_node_stream2 = require("node:stream");
169
- var import_tiny_invariant2 = __toESM(require("tiny-invariant"));
170
189
  var import_async2 = require("@dxos/async");
171
190
  var import_context = require("@dxos/context");
172
191
  var import_debug = require("@dxos/debug");
192
+ var import_invariant2 = require("@dxos/invariant");
173
193
  var import_log2 = require("@dxos/log");
174
194
  var import_protocols = require("@dxos/protocols");
175
195
 
@@ -177,7 +197,7 @@ var import_protocols = require("@dxos/protocols");
177
197
  var varint = __toESM(require("varint"));
178
198
  var import_async = require("@dxos/async");
179
199
  var import_log = require("@dxos/log");
180
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/muxing/balancer.ts";
200
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/muxing/balancer.ts";
181
201
  var MAX_CHUNK_SIZE = 8192;
182
202
  var Balancer = class {
183
203
  constructor(_sysChannelId) {
@@ -227,7 +247,7 @@ var Balancer = class {
227
247
  });
228
248
  if (noCalls) {
229
249
  this._sendChunks().catch((err) => import_log.log.catch(err, void 0, {
230
- F: __dxlog_file,
250
+ F: __dxlog_file2,
231
251
  L: 96,
232
252
  S: this,
233
253
  C: (f, a) => f(...a)
@@ -287,16 +307,15 @@ var Balancer = class {
287
307
  return chunk;
288
308
  }
289
309
  async _sendChunks() {
290
- var _a, _b;
291
310
  if (this._sendBuffers.size === 0) {
292
311
  return;
293
312
  }
294
313
  const chunk = this._getNextChunk();
295
314
  try {
296
315
  await this._framer.port.send(chunk.msg);
297
- (_a = chunk.trigger) == null ? void 0 : _a.wake();
316
+ chunk.trigger?.wake();
298
317
  } catch (err) {
299
- (_b = chunk.trigger) == null ? void 0 : _b.throw(err);
318
+ chunk.trigger?.throw(err);
300
319
  }
301
320
  await this._sendChunks();
302
321
  }
@@ -329,7 +348,7 @@ var decodeChunk = (data, withLength) => {
329
348
  };
330
349
 
331
350
  // packages/core/mesh/teleport/src/muxing/muxer.ts
332
- var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/muxing/muxer.ts";
351
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/muxing/muxer.ts";
333
352
  var Command = import_protocols.schema.getCodecForType("dxos.mesh.muxer.Command");
334
353
  var STATS_INTERVAL = 1e3;
335
354
  var MAX_SAFE_FRAME_SIZE = 1e6;
@@ -343,6 +362,8 @@ var Muxer = class {
343
362
  this._nextId = 1;
344
363
  this._destroyed = false;
345
364
  this._destroying = false;
365
+ this._lastStats = void 0;
366
+ this._lastChannelStats = /* @__PURE__ */ new Map();
346
367
  this.close = new import_async2.Event();
347
368
  this.statsUpdated = new import_async2.Event();
348
369
  this.stream = this._balancer.stream;
@@ -362,7 +383,15 @@ var Muxer = class {
362
383
  tag,
363
384
  contentType: opts.contentType
364
385
  });
365
- (0, import_tiny_invariant2.default)(!channel.push, `Channel already open: ${tag}`);
386
+ (0, import_invariant2.invariant)(!channel.push, `Channel already open: ${tag}`, {
387
+ F: __dxlog_file3,
388
+ L: 134,
389
+ S: this,
390
+ A: [
391
+ "!channel.push",
392
+ "`Channel already open: ${tag}`"
393
+ ]
394
+ });
366
395
  const stream = new import_node_stream2.Duplex({
367
396
  write: (data, encoding, callback) => {
368
397
  this._sendData(channel, data).then(() => callback()).catch(callback);
@@ -402,7 +431,15 @@ var Muxer = class {
402
431
  tag,
403
432
  contentType: opts.contentType
404
433
  });
405
- (0, import_tiny_invariant2.default)(!channel.push, `Channel already open: ${tag}`);
434
+ (0, import_invariant2.invariant)(!channel.push, `Channel already open: ${tag}`, {
435
+ F: __dxlog_file3,
436
+ L: 186,
437
+ S: this,
438
+ A: [
439
+ "!channel.push",
440
+ "`Channel already open: ${tag}`"
441
+ ]
442
+ });
406
443
  let inboundBuffer = [];
407
444
  let callback;
408
445
  channel.push = (data) => {
@@ -418,7 +455,15 @@ var Muxer = class {
418
455
  await this._sendData(channel, data);
419
456
  },
420
457
  subscribe: (cb) => {
421
- (0, import_tiny_invariant2.default)(!callback, "Only one subscriber is allowed");
458
+ (0, import_invariant2.invariant)(!callback, "Only one subscriber is allowed", {
459
+ F: __dxlog_file3,
460
+ L: 208,
461
+ S: this,
462
+ A: [
463
+ "!callback",
464
+ "'Only one subscriber is allowed'"
465
+ ]
466
+ });
422
467
  callback = cb;
423
468
  for (const data of inboundBuffer) {
424
469
  cb(data);
@@ -450,7 +495,7 @@ var Muxer = class {
450
495
  this._destroying = true;
451
496
  this._sendCommand({
452
497
  destroy: {
453
- error: err == null ? void 0 : err.message
498
+ error: err?.message
454
499
  }
455
500
  }, SYSTEM_CHANNEL_ID).then(() => {
456
501
  this._dispose();
@@ -460,35 +505,36 @@ var Muxer = class {
460
505
  void this._ctx.dispose();
461
506
  }
462
507
  _dispose(err) {
463
- var _a;
464
508
  if (this._destroyed) {
465
509
  return;
466
510
  }
467
511
  this._destroyed = true;
468
512
  this._balancer.destroy();
469
513
  for (const channel of this._channelsByTag.values()) {
470
- (_a = channel.destroy) == null ? void 0 : _a.call(channel, err);
514
+ channel.destroy?.(err);
471
515
  }
472
516
  this.close.emit(err);
473
517
  this._channelsByLocalId.clear();
474
518
  this._channelsByTag.clear();
475
519
  }
476
520
  async _handleCommand(cmd) {
477
- var _a;
478
521
  (0, import_log2.log)("Received command", {
479
522
  cmd
480
523
  }, {
481
- F: __dxlog_file2,
482
- L: 240,
524
+ F: __dxlog_file3,
525
+ L: 283,
483
526
  S: this,
484
527
  C: (f, a) => f(...a)
485
528
  });
486
529
  if (this._destroyed || this._destroying) {
530
+ if (cmd.destroy) {
531
+ return;
532
+ }
487
533
  import_log2.log.warn("Received command after destroy", {
488
534
  cmd
489
535
  }, {
490
- F: __dxlog_file2,
491
- L: 243,
536
+ F: __dxlog_file3,
537
+ L: 290,
492
538
  S: this,
493
539
  C: (f, a) => f(...a)
494
540
  });
@@ -510,13 +556,13 @@ var Muxer = class {
510
556
  }
511
557
  channel.buffer = [];
512
558
  } else if (cmd.data) {
513
- const stream = (_a = this._channelsByLocalId.get(cmd.data.channelId)) != null ? _a : (0, import_debug.failUndefined)();
559
+ const stream = this._channelsByLocalId.get(cmd.data.channelId) ?? (0, import_debug.failUndefined)();
514
560
  if (!stream.push) {
515
561
  import_log2.log.warn("Received data for channel before it was opened", {
516
562
  tag: stream.tag
517
563
  }, {
518
- F: __dxlog_file2,
519
- L: 270,
564
+ F: __dxlog_file3,
565
+ L: 317,
520
566
  S: this,
521
567
  C: (f, a) => f(...a)
522
568
  });
@@ -564,8 +610,8 @@ var Muxer = class {
564
610
  size: data.length,
565
611
  threshold: MAX_SAFE_FRAME_SIZE
566
612
  }, {
567
- F: __dxlog_file2,
568
- L: 314,
613
+ F: __dxlog_file3,
614
+ L: 362,
569
615
  S: this,
570
616
  C: (f, a) => f(...a)
571
617
  });
@@ -591,29 +637,48 @@ var Muxer = class {
591
637
  }
592
638
  async _emitStats() {
593
639
  if (this._destroyed || this._destroying) {
640
+ this._lastStats = void 0;
641
+ this._lastChannelStats.clear();
594
642
  return;
595
643
  }
596
644
  const bytesSent = this._balancer.bytesSent;
597
645
  const bytesReceived = this._balancer.bytesReceived;
598
- this.statsUpdated.emit({
599
- channels: Array.from(this._channelsByTag.values()).map((channel) => ({
600
- id: channel.id,
601
- tag: channel.tag,
602
- contentType: channel.contentType,
603
- bytesSent: channel.stats.bytesSent,
604
- bytesReceived: channel.stats.bytesReceived
605
- })),
646
+ const now = Date.now();
647
+ const interval = this._lastStats ? (now - this._lastStats.timestamp) / 1e3 : 0;
648
+ const calculateThroughput = (current, last) => last ? {
649
+ bytesSentRate: interval ? (current.bytesSent - last.bytesSent) / interval : void 0,
650
+ bytesReceivedRate: interval ? (current.bytesReceived - last.bytesReceived) / interval : void 0
651
+ } : {};
652
+ this._lastStats = {
653
+ timestamp: now,
654
+ channels: Array.from(this._channelsByTag.values()).map((channel) => {
655
+ const stats = {
656
+ id: channel.id,
657
+ tag: channel.tag,
658
+ contentType: channel.contentType,
659
+ bytesSent: channel.stats.bytesSent,
660
+ bytesReceived: channel.stats.bytesReceived,
661
+ ...calculateThroughput(channel.stats, this._lastChannelStats.get(channel.id))
662
+ };
663
+ this._lastChannelStats.set(channel.id, stats);
664
+ return stats;
665
+ }),
606
666
  bytesSent,
607
- bytesReceived
608
- });
667
+ bytesReceived,
668
+ ...calculateThroughput({
669
+ bytesSent,
670
+ bytesReceived
671
+ }, this._lastStats)
672
+ };
673
+ this.statsUpdated.emit(this._lastStats);
609
674
  }
610
675
  };
611
676
 
612
677
  // packages/core/mesh/teleport/src/teleport.ts
613
- var import_tiny_invariant3 = __toESM(require("tiny-invariant"));
614
678
  var import_async3 = require("@dxos/async");
615
679
  var import_context2 = require("@dxos/context");
616
680
  var import_debug2 = require("@dxos/debug");
681
+ var import_invariant3 = require("@dxos/invariant");
617
682
  var import_keys = require("@dxos/keys");
618
683
  var import_log3 = require("@dxos/log");
619
684
  var import_protocols2 = require("@dxos/protocols");
@@ -629,14 +694,14 @@ function _ts_decorate(decorators, target, key, desc) {
629
694
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
630
695
  return c > 3 && r && Object.defineProperty(target, key, r), r;
631
696
  }
632
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/teleport.ts";
697
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/teleport.ts";
633
698
  var Teleport = class {
634
699
  constructor({ initiator, localPeerId, remotePeerId }) {
635
700
  this._ctx = new import_context2.Context({
636
701
  onError: (err) => {
637
702
  void this.destroy(err).catch(() => {
638
703
  import_log3.log.error("Error during destroy", err, {
639
- F: __dxlog_file3,
704
+ F: __dxlog_file4,
640
705
  L: 34,
641
706
  S: this,
642
707
  C: (f, a) => f(...a)
@@ -650,7 +715,7 @@ var Teleport = class {
650
715
  heartbeatTimeout: 1e4,
651
716
  onTimeout: () => {
652
717
  this.destroy(new Error("Connection timed out")).catch((err) => import_log3.log.catch(err, void 0, {
653
- F: __dxlog_file3,
718
+ F: __dxlog_file4,
654
719
  L: 45,
655
720
  S: this,
656
721
  C: (f, a) => f(...a)
@@ -660,9 +725,33 @@ var Teleport = class {
660
725
  this._extensions = /* @__PURE__ */ new Map();
661
726
  this._remoteExtensions = /* @__PURE__ */ new Set();
662
727
  this._open = false;
663
- (0, import_tiny_invariant3.default)(typeof initiator === "boolean");
664
- (0, import_tiny_invariant3.default)(import_keys.PublicKey.isPublicKey(localPeerId));
665
- (0, import_tiny_invariant3.default)(import_keys.PublicKey.isPublicKey(remotePeerId));
728
+ (0, import_invariant3.invariant)(typeof initiator === "boolean", void 0, {
729
+ F: __dxlog_file4,
730
+ L: 55,
731
+ S: this,
732
+ A: [
733
+ "typeof initiator === 'boolean'",
734
+ ""
735
+ ]
736
+ });
737
+ (0, import_invariant3.invariant)(import_keys.PublicKey.isPublicKey(localPeerId), void 0, {
738
+ F: __dxlog_file4,
739
+ L: 56,
740
+ S: this,
741
+ A: [
742
+ "PublicKey.isPublicKey(localPeerId)",
743
+ ""
744
+ ]
745
+ });
746
+ (0, import_invariant3.invariant)(import_keys.PublicKey.isPublicKey(remotePeerId), void 0, {
747
+ F: __dxlog_file4,
748
+ L: 57,
749
+ S: this,
750
+ A: [
751
+ "PublicKey.isPublicKey(remotePeerId)",
752
+ ""
753
+ ]
754
+ });
666
755
  this.initiator = initiator;
667
756
  this.localPeerId = localPeerId;
668
757
  this.remotePeerId = remotePeerId;
@@ -670,12 +759,20 @@ var Teleport = class {
670
759
  (0, import_log3.log)("remote extension", {
671
760
  name
672
761
  }, {
673
- F: __dxlog_file3,
762
+ F: __dxlog_file4,
674
763
  L: 63,
675
764
  S: this,
676
765
  C: (f, a) => f(...a)
677
766
  });
678
- (0, import_tiny_invariant3.default)(!this._remoteExtensions.has(name), "Remote extension already exists");
767
+ (0, import_invariant3.invariant)(!this._remoteExtensions.has(name), "Remote extension already exists", {
768
+ F: __dxlog_file4,
769
+ L: 64,
770
+ S: this,
771
+ A: [
772
+ "!this._remoteExtensions.has(name)",
773
+ "'Remote extension already exists'"
774
+ ]
775
+ });
679
776
  this._remoteExtensions.add(name);
680
777
  if (this._extensions.has(name)) {
681
778
  try {
@@ -698,11 +795,13 @@ var Teleport = class {
698
795
  localPeerId,
699
796
  remotePeerId,
700
797
  bytesSent: stats.bytesSent,
798
+ bytesSentRate: stats.bytesSentRate,
701
799
  bytesReceived: stats.bytesReceived,
800
+ bytesReceivedRate: stats.bytesReceivedRate,
702
801
  channels: stats.channels
703
802
  }, {
704
- F: __dxlog_file3,
705
- L: 88,
803
+ F: __dxlog_file4,
804
+ L: 89,
706
805
  S: this,
707
806
  C: (f, a) => f(...a)
708
807
  });
@@ -735,8 +834,8 @@ var Teleport = class {
735
834
  await extension.onClose(err);
736
835
  } catch (err2) {
737
836
  import_log3.log.catch(err2, void 0, {
738
- F: __dxlog_file3,
739
- L: 132,
837
+ F: __dxlog_file4,
838
+ L: 137,
740
839
  S: this,
741
840
  C: (f, a) => f(...a)
742
841
  });
@@ -751,8 +850,8 @@ var Teleport = class {
751
850
  (0, import_log3.log)("addExtension", {
752
851
  name
753
852
  }, {
754
- F: __dxlog_file3,
755
- L: 144,
853
+ F: __dxlog_file4,
854
+ L: 149,
756
855
  S: this,
757
856
  C: (f, a) => f(...a)
758
857
  });
@@ -774,31 +873,62 @@ var Teleport = class {
774
873
  }
775
874
  }
776
875
  _setExtension(extensionName, extension) {
777
- (0, import_tiny_invariant3.default)(!extensionName.includes("/"), "Invalid extension name");
778
- (0, import_tiny_invariant3.default)(!this._extensions.has(extensionName), "Extension already exists");
876
+ (0, import_invariant3.invariant)(!extensionName.includes("/"), "Invalid extension name", {
877
+ F: __dxlog_file4,
878
+ L: 173,
879
+ S: this,
880
+ A: [
881
+ "!extensionName.includes('/')",
882
+ "'Invalid extension name'"
883
+ ]
884
+ });
885
+ (0, import_invariant3.invariant)(!this._extensions.has(extensionName), "Extension already exists", {
886
+ F: __dxlog_file4,
887
+ L: 174,
888
+ S: this,
889
+ A: [
890
+ "!this._extensions.has(extensionName)",
891
+ "'Extension already exists'"
892
+ ]
893
+ });
779
894
  this._extensions.set(extensionName, extension);
780
895
  }
781
896
  async _openExtension(extensionName) {
782
- var _a;
783
897
  (0, import_log3.log)("open extension", {
784
898
  extensionName
785
899
  }, {
786
- F: __dxlog_file3,
787
- L: 174,
900
+ F: __dxlog_file4,
901
+ L: 179,
788
902
  S: this,
789
903
  C: (f, a) => f(...a)
790
904
  });
791
- const extension = (_a = this._extensions.get(extensionName)) != null ? _a : (0, import_debug2.failUndefined)();
905
+ const extension = this._extensions.get(extensionName) ?? (0, import_debug2.failUndefined)();
792
906
  const context = {
793
907
  initiator: this.initiator,
794
908
  localPeerId: this.localPeerId,
795
909
  remotePeerId: this.remotePeerId,
796
910
  createPort: async (channelName, opts) => {
797
- (0, import_tiny_invariant3.default)(!channelName.includes("/"), "Invalid channel name");
911
+ (0, import_invariant3.invariant)(!channelName.includes("/"), "Invalid channel name", {
912
+ F: __dxlog_file4,
913
+ L: 187,
914
+ S: this,
915
+ A: [
916
+ "!channelName.includes('/')",
917
+ "'Invalid channel name'"
918
+ ]
919
+ });
798
920
  return this._muxer.createPort(`${extensionName}/${channelName}`, opts);
799
921
  },
800
922
  createStream: async (channelName, opts) => {
801
- (0, import_tiny_invariant3.default)(!channelName.includes("/"), "Invalid channel name");
923
+ (0, import_invariant3.invariant)(!channelName.includes("/"), "Invalid channel name", {
924
+ F: __dxlog_file4,
925
+ L: 191,
926
+ S: this,
927
+ A: [
928
+ "!channelName.includes('/')",
929
+ "'Invalid channel name'"
930
+ ]
931
+ });
802
932
  return this._muxer.createStream(`${extensionName}/${channelName}`, opts);
803
933
  },
804
934
  close: (err) => {
@@ -811,8 +941,8 @@ var Teleport = class {
811
941
  (0, import_log3.log)("extension opened", {
812
942
  extensionName
813
943
  }, {
814
- F: __dxlog_file3,
815
- L: 197,
944
+ F: __dxlog_file4,
945
+ L: 202,
816
946
  S: this,
817
947
  C: (f, a) => f(...a)
818
948
  });
@@ -875,10 +1005,10 @@ var ControlExtension = class {
875
1005
 
876
1006
  // packages/core/mesh/teleport/src/testing/test-builder.ts
877
1007
  var import_node_stream3 = require("node:stream");
878
- var import_tiny_invariant4 = __toESM(require("tiny-invariant"));
1008
+ var import_invariant4 = require("@dxos/invariant");
879
1009
  var import_keys2 = require("@dxos/keys");
880
1010
  var import_log4 = require("@dxos/log");
881
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/testing/test-builder.ts";
1011
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/testing/test-builder.ts";
882
1012
  var TestBuilder = class {
883
1013
  constructor() {
884
1014
  this._peers = /* @__PURE__ */ new Set();
@@ -897,9 +1027,33 @@ var TestBuilder = class {
897
1027
  await Promise.all(Array.from(this._peers).map((agent) => agent.destroy()));
898
1028
  }
899
1029
  async connect(peer1, peer2) {
900
- (0, import_tiny_invariant4.default)(peer1 !== peer2);
901
- (0, import_tiny_invariant4.default)(this._peers.has(peer1));
902
- (0, import_tiny_invariant4.default)(this._peers.has(peer1));
1030
+ (0, import_invariant4.invariant)(peer1 !== peer2, void 0, {
1031
+ F: __dxlog_file5,
1032
+ L: 37,
1033
+ S: this,
1034
+ A: [
1035
+ "peer1 !== peer2",
1036
+ ""
1037
+ ]
1038
+ });
1039
+ (0, import_invariant4.invariant)(this._peers.has(peer1), void 0, {
1040
+ F: __dxlog_file5,
1041
+ L: 38,
1042
+ S: this,
1043
+ A: [
1044
+ "this._peers.has(peer1)",
1045
+ ""
1046
+ ]
1047
+ });
1048
+ (0, import_invariant4.invariant)(this._peers.has(peer1), void 0, {
1049
+ F: __dxlog_file5,
1050
+ L: 39,
1051
+ S: this,
1052
+ A: [
1053
+ "this._peers.has(peer1)",
1054
+ ""
1055
+ ]
1056
+ });
903
1057
  const connection1 = peer1.createConnection({
904
1058
  initiator: true,
905
1059
  remotePeerId: peer2.peerId
@@ -919,13 +1073,53 @@ var TestBuilder = class {
919
1073
  ];
920
1074
  }
921
1075
  async disconnect(peer1, peer2) {
922
- (0, import_tiny_invariant4.default)(peer1 !== peer2);
923
- (0, import_tiny_invariant4.default)(this._peers.has(peer1));
924
- (0, import_tiny_invariant4.default)(this._peers.has(peer1));
1076
+ (0, import_invariant4.invariant)(peer1 !== peer2, void 0, {
1077
+ F: __dxlog_file5,
1078
+ L: 51,
1079
+ S: this,
1080
+ A: [
1081
+ "peer1 !== peer2",
1082
+ ""
1083
+ ]
1084
+ });
1085
+ (0, import_invariant4.invariant)(this._peers.has(peer1), void 0, {
1086
+ F: __dxlog_file5,
1087
+ L: 52,
1088
+ S: this,
1089
+ A: [
1090
+ "this._peers.has(peer1)",
1091
+ ""
1092
+ ]
1093
+ });
1094
+ (0, import_invariant4.invariant)(this._peers.has(peer1), void 0, {
1095
+ F: __dxlog_file5,
1096
+ L: 53,
1097
+ S: this,
1098
+ A: [
1099
+ "this._peers.has(peer1)",
1100
+ ""
1101
+ ]
1102
+ });
925
1103
  const connection1 = Array.from(peer1.connections).find((connection) => connection.remotePeerId.equals(peer2.peerId));
926
1104
  const connection2 = Array.from(peer2.connections).find((connection) => connection.remotePeerId.equals(peer1.peerId));
927
- (0, import_tiny_invariant4.default)(connection1);
928
- (0, import_tiny_invariant4.default)(connection2);
1105
+ (0, import_invariant4.invariant)(connection1, void 0, {
1106
+ F: __dxlog_file5,
1107
+ L: 62,
1108
+ S: this,
1109
+ A: [
1110
+ "connection1",
1111
+ ""
1112
+ ]
1113
+ });
1114
+ (0, import_invariant4.invariant)(connection2, void 0, {
1115
+ F: __dxlog_file5,
1116
+ L: 63,
1117
+ S: this,
1118
+ A: [
1119
+ "connection2",
1120
+ ""
1121
+ ]
1122
+ });
929
1123
  await Promise.all([
930
1124
  peer1.closeConnection(connection1),
931
1125
  peer2.closeConnection(connection2)
@@ -947,12 +1141,28 @@ var TestPeer = class {
947
1141
  return connection;
948
1142
  }
949
1143
  async openConnection(connection) {
950
- (0, import_tiny_invariant4.default)(this.connections.has(connection));
1144
+ (0, import_invariant4.invariant)(this.connections.has(connection), void 0, {
1145
+ F: __dxlog_file5,
1146
+ L: 84,
1147
+ S: this,
1148
+ A: [
1149
+ "this.connections.has(connection)",
1150
+ ""
1151
+ ]
1152
+ });
951
1153
  await connection.teleport.open();
952
1154
  await this.onOpen(connection);
953
1155
  }
954
1156
  async closeConnection(connection) {
955
- (0, import_tiny_invariant4.default)(this.connections.has(connection));
1157
+ (0, import_invariant4.invariant)(this.connections.has(connection), void 0, {
1158
+ F: __dxlog_file5,
1159
+ L: 90,
1160
+ S: this,
1161
+ A: [
1162
+ "this.connections.has(connection)",
1163
+ ""
1164
+ ]
1165
+ });
956
1166
  await this.onClose(connection);
957
1167
  await connection.teleport.close();
958
1168
  this.connections.delete(connection);
@@ -967,7 +1177,7 @@ var pipeStreams = (stream1, stream2) => {
967
1177
  (0, import_node_stream3.pipeline)(stream1, stream2, (err) => {
968
1178
  if (err && err.code !== "ERR_STREAM_PREMATURE_CLOSE") {
969
1179
  import_log4.log.catch(err, void 0, {
970
- F: __dxlog_file4,
1180
+ F: __dxlog_file5,
971
1181
  L: 106,
972
1182
  S: void 0,
973
1183
  C: (f, a) => f(...a)
@@ -977,7 +1187,7 @@ var pipeStreams = (stream1, stream2) => {
977
1187
  (0, import_node_stream3.pipeline)(stream2, stream1, (err) => {
978
1188
  if (err && err.code !== "ERR_STREAM_PREMATURE_CLOSE") {
979
1189
  import_log4.log.catch(err, void 0, {
980
- F: __dxlog_file4,
1190
+ F: __dxlog_file5,
981
1191
  L: 111,
982
1192
  S: void 0,
983
1193
  C: (f, a) => f(...a)
@@ -999,12 +1209,12 @@ var TestConnection = class {
999
1209
  };
1000
1210
 
1001
1211
  // packages/core/mesh/teleport/src/testing/test-extension.ts
1002
- var import_tiny_invariant5 = __toESM(require("tiny-invariant"));
1003
1212
  var import_async4 = require("@dxos/async");
1213
+ var import_invariant5 = require("@dxos/invariant");
1004
1214
  var import_log5 = require("@dxos/log");
1005
1215
  var import_protocols3 = require("@dxos/protocols");
1006
1216
  var import_rpc2 = require("@dxos/rpc");
1007
- var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/testing/test-extension.ts";
1217
+ var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/testing/test-extension.ts";
1008
1218
  var TestExtension = class {
1009
1219
  constructor(callbacks = {}) {
1010
1220
  this.callbacks = callbacks;
@@ -1012,17 +1222,15 @@ var TestExtension = class {
1012
1222
  this.closed = new import_async4.Trigger();
1013
1223
  }
1014
1224
  get remotePeerId() {
1015
- var _a;
1016
- return (_a = this.extensionContext) == null ? void 0 : _a.remotePeerId;
1225
+ return this.extensionContext?.remotePeerId;
1017
1226
  }
1018
1227
  async onOpen(context) {
1019
- var _a, _b;
1020
1228
  (0, import_log5.log)("onOpen", {
1021
1229
  localPeerId: context.localPeerId,
1022
1230
  remotePeerId: context.remotePeerId
1023
1231
  }, {
1024
- F: __dxlog_file5,
1025
- L: 33,
1232
+ F: __dxlog_file6,
1233
+ L: 32,
1026
1234
  S: this,
1027
1235
  C: (f, a) => f(...a)
1028
1236
  });
@@ -1051,22 +1259,21 @@ var TestExtension = class {
1051
1259
  timeout: 2e3
1052
1260
  });
1053
1261
  await this._rpc.open();
1054
- await ((_b = (_a = this.callbacks).onOpen) == null ? void 0 : _b.call(_a));
1262
+ await this.callbacks.onOpen?.();
1055
1263
  this.open.wake();
1056
1264
  }
1057
1265
  async onClose(err) {
1058
- var _a, _b, _c;
1059
1266
  (0, import_log5.log)("onClose", {
1060
1267
  err
1061
1268
  }, {
1062
- F: __dxlog_file5,
1063
- L: 67,
1269
+ F: __dxlog_file6,
1270
+ L: 66,
1064
1271
  S: this,
1065
1272
  C: (f, a) => f(...a)
1066
1273
  });
1067
- await ((_b = (_a = this.callbacks).onClose) == null ? void 0 : _b.call(_a));
1274
+ await this.callbacks.onClose?.();
1068
1275
  this.closed.wake();
1069
- await ((_c = this._rpc) == null ? void 0 : _c.close());
1276
+ await this._rpc?.close();
1070
1277
  }
1071
1278
  async test(message = "test") {
1072
1279
  await this.open.wait({
@@ -1075,25 +1282,32 @@ var TestExtension = class {
1075
1282
  const res = await (0, import_async4.asyncTimeout)(this._rpc.rpc.TestService.testCall({
1076
1283
  data: message
1077
1284
  }), 1500);
1078
- (0, import_tiny_invariant5.default)(res.data === message);
1285
+ (0, import_invariant5.invariant)(res.data === message, void 0, {
1286
+ F: __dxlog_file6,
1287
+ L: 75,
1288
+ S: this,
1289
+ A: [
1290
+ "res.data === message",
1291
+ ""
1292
+ ]
1293
+ });
1079
1294
  }
1080
1295
  /**
1081
1296
  * Force-close the connection.
1082
1297
  */
1083
1298
  async closeConnection(err) {
1084
- var _a;
1085
- (_a = this.extensionContext) == null ? void 0 : _a.close(err);
1299
+ this.extensionContext?.close(err);
1086
1300
  }
1087
1301
  };
1088
1302
 
1089
1303
  // packages/core/mesh/teleport/src/testing/test-extension-with-streams.ts
1090
- var import_node_assert = __toESM(require("node:assert"));
1091
1304
  var import_node_crypto = require("node:crypto");
1092
1305
  var import_async5 = require("@dxos/async");
1306
+ var import_invariant6 = require("@dxos/invariant");
1093
1307
  var import_log6 = require("@dxos/log");
1094
1308
  var import_protocols4 = require("@dxos/protocols");
1095
1309
  var import_rpc3 = require("@dxos/rpc");
1096
- var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/testing/test-extension-with-streams.ts";
1310
+ var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/testing/test-extension-with-streams.ts";
1097
1311
  var TestExtensionWithStreams = class {
1098
1312
  constructor(callbacks = {}) {
1099
1313
  this.callbacks = callbacks;
@@ -1102,11 +1316,18 @@ var TestExtensionWithStreams = class {
1102
1316
  this._streams = /* @__PURE__ */ new Map();
1103
1317
  }
1104
1318
  get remotePeerId() {
1105
- var _a;
1106
- return (_a = this.extensionContext) == null ? void 0 : _a.remotePeerId;
1319
+ return this.extensionContext?.remotePeerId;
1107
1320
  }
1108
1321
  async _openStream(streamTag, interval = 5, chunkSize = 2048) {
1109
- (0, import_node_assert.default)(!this._streams.has(streamTag), `Stream already exists: ${streamTag}`);
1322
+ (0, import_invariant6.invariant)(!this._streams.has(streamTag), `Stream already exists: ${streamTag}`, {
1323
+ F: __dxlog_file7,
1324
+ L: 37,
1325
+ S: this,
1326
+ A: [
1327
+ "!this._streams.has(streamTag)",
1328
+ "`Stream already exists: ${streamTag}`"
1329
+ ]
1330
+ });
1110
1331
  const networkStream = await this.extensionContext.createStream(streamTag, {
1111
1332
  contentType: "application/x-test-stream"
1112
1333
  });
@@ -1146,7 +1367,6 @@ var TestExtensionWithStreams = class {
1146
1367
  networkStream.removeAllListeners();
1147
1368
  });
1148
1369
  streamEntry.reportingTimer = setInterval(() => {
1149
- var _a, _b;
1150
1370
  const { bytesSent, bytesReceived, sendErrors, receiveErrors } = streamEntry;
1151
1371
  import_log6.log.trace("dxos.test.stream-stats", {
1152
1372
  streamTag,
@@ -1154,10 +1374,10 @@ var TestExtensionWithStreams = class {
1154
1374
  bytesReceived,
1155
1375
  sendErrors,
1156
1376
  receiveErrors,
1157
- from: (_a = this.extensionContext) == null ? void 0 : _a.localPeerId,
1158
- to: (_b = this.extensionContext) == null ? void 0 : _b.remotePeerId
1377
+ from: this.extensionContext?.localPeerId,
1378
+ to: this.extensionContext?.remotePeerId
1159
1379
  }, {
1160
- F: __dxlog_file6,
1380
+ F: __dxlog_file7,
1161
1381
  L: 91,
1162
1382
  S: this,
1163
1383
  C: (f, a) => f(...a)
@@ -1165,7 +1385,15 @@ var TestExtensionWithStreams = class {
1165
1385
  }, 100);
1166
1386
  }
1167
1387
  _closeStream(streamTag) {
1168
- (0, import_node_assert.default)(this._streams.has(streamTag), `Stream does not exist: ${streamTag}`);
1388
+ (0, import_invariant6.invariant)(this._streams.has(streamTag), `Stream does not exist: ${streamTag}`, {
1389
+ F: __dxlog_file7,
1390
+ L: 104,
1391
+ S: this,
1392
+ A: [
1393
+ "this._streams.has(streamTag)",
1394
+ "`Stream does not exist: ${streamTag}`"
1395
+ ]
1396
+ });
1169
1397
  const stream = this._streams.get(streamTag);
1170
1398
  clearTimeout(stream.timer);
1171
1399
  clearTimeout(stream.reportingTimer);
@@ -1177,16 +1405,15 @@ var TestExtensionWithStreams = class {
1177
1405
  bytesReceived,
1178
1406
  sendErrors,
1179
1407
  receiveErrors,
1180
- runningTime: Date.now() - (startTimestamp != null ? startTimestamp : 0)
1408
+ runningTime: Date.now() - (startTimestamp ?? 0)
1181
1409
  };
1182
1410
  }
1183
1411
  async onOpen(context) {
1184
- var _a, _b;
1185
1412
  (0, import_log6.log)("onOpen", {
1186
1413
  localPeerId: context.localPeerId,
1187
1414
  remotePeerId: context.remotePeerId
1188
1415
  }, {
1189
- F: __dxlog_file6,
1416
+ F: __dxlog_file7,
1190
1417
  L: 126,
1191
1418
  S: this,
1192
1419
  C: (f, a) => f(...a)
@@ -1228,26 +1455,25 @@ var TestExtensionWithStreams = class {
1228
1455
  timeout: 2e3
1229
1456
  });
1230
1457
  await this._rpc.open();
1231
- await ((_b = (_a = this.callbacks).onOpen) == null ? void 0 : _b.call(_a));
1458
+ await this.callbacks.onOpen?.();
1232
1459
  this.open.wake();
1233
1460
  }
1234
1461
  async onClose(err) {
1235
- var _a, _b, _c;
1236
1462
  (0, import_log6.log)("onClose", {
1237
1463
  err
1238
1464
  }, {
1239
- F: __dxlog_file6,
1465
+ F: __dxlog_file7,
1240
1466
  L: 177,
1241
1467
  S: this,
1242
1468
  C: (f, a) => f(...a)
1243
1469
  });
1244
- await ((_b = (_a = this.callbacks).onClose) == null ? void 0 : _b.call(_a));
1470
+ await this.callbacks.onClose?.();
1245
1471
  this.closed.wake();
1246
1472
  for (const [streamTag, stream] of Object.entries(this._streams)) {
1247
1473
  (0, import_log6.log)("closing stream", {
1248
1474
  streamTag
1249
1475
  }, {
1250
- F: __dxlog_file6,
1476
+ F: __dxlog_file7,
1251
1477
  L: 181,
1252
1478
  S: this,
1253
1479
  C: (f, a) => f(...a)
@@ -1255,7 +1481,7 @@ var TestExtensionWithStreams = class {
1255
1481
  clearTimeout(stream.interval);
1256
1482
  stream.networkStream.destroy();
1257
1483
  }
1258
- await ((_c = this._rpc) == null ? void 0 : _c.close());
1484
+ await this._rpc?.close();
1259
1485
  }
1260
1486
  async addNewStream(streamLoadInterval, streamLoadChunkSize, streamTag) {
1261
1487
  await this.open.wait({
@@ -1269,7 +1495,15 @@ var TestExtensionWithStreams = class {
1269
1495
  streamLoadInterval,
1270
1496
  streamLoadChunkSize
1271
1497
  });
1272
- (0, import_node_assert.default)(data === streamTag);
1498
+ (0, import_invariant6.invariant)(data === streamTag, void 0, {
1499
+ F: __dxlog_file7,
1500
+ L: 198,
1501
+ S: this,
1502
+ A: [
1503
+ "data === streamTag",
1504
+ ""
1505
+ ]
1506
+ });
1273
1507
  await this._openStream(streamTag, streamLoadInterval, streamLoadChunkSize);
1274
1508
  return streamTag;
1275
1509
  }
@@ -1280,7 +1514,15 @@ var TestExtensionWithStreams = class {
1280
1514
  const { data, bytesSent, bytesReceived, sendErrors, receiveErrors, runningTime } = await this._rpc.rpc.TestServiceWithStreams.closeTestStream({
1281
1515
  data: streamTag
1282
1516
  });
1283
- (0, import_node_assert.default)(data === streamTag);
1517
+ (0, import_invariant6.invariant)(data === streamTag, void 0, {
1518
+ F: __dxlog_file7,
1519
+ L: 211,
1520
+ S: this,
1521
+ A: [
1522
+ "data === streamTag",
1523
+ ""
1524
+ ]
1525
+ });
1284
1526
  const local = this._closeStream(streamTag);
1285
1527
  return {
1286
1528
  streamTag,
@@ -1300,14 +1542,14 @@ var TestExtensionWithStreams = class {
1300
1542
  * Force-close the connection.
1301
1543
  */
1302
1544
  async closeConnection(err) {
1303
- var _a;
1304
- (_a = this.extensionContext) == null ? void 0 : _a.close(err);
1545
+ this.extensionContext?.close(err);
1305
1546
  }
1306
1547
  };
1307
1548
 
1308
1549
  // packages/core/mesh/teleport/src/rpc-extension.ts
1309
- var import_tiny_invariant6 = __toESM(require("tiny-invariant"));
1550
+ var import_invariant7 = require("@dxos/invariant");
1310
1551
  var import_rpc4 = require("@dxos/rpc");
1552
+ var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/rpc-extension.ts";
1311
1553
  var RpcExtension = class {
1312
1554
  constructor(_rpcParams) {
1313
1555
  this._rpcParams = _rpcParams;
@@ -1323,7 +1565,15 @@ var RpcExtension = class {
1323
1565
  return this._extensionContext.remotePeerId;
1324
1566
  }
1325
1567
  get rpc() {
1326
- (0, import_tiny_invariant6.default)(this._rpc);
1568
+ (0, import_invariant7.invariant)(this._rpc, void 0, {
1569
+ F: __dxlog_file8,
1570
+ L: 32,
1571
+ S: this,
1572
+ A: [
1573
+ "this._rpc",
1574
+ ""
1575
+ ]
1576
+ });
1327
1577
  return this._rpc.rpc;
1328
1578
  }
1329
1579
  async onOpen(context) {
@@ -1343,9 +1593,8 @@ var RpcExtension = class {
1343
1593
  await this._rpc.open();
1344
1594
  }
1345
1595
  async onClose(err) {
1346
- var _a;
1347
1596
  this._isClosed = true;
1348
- await ((_a = this._rpc) == null ? void 0 : _a.close());
1597
+ await this._rpc?.close();
1349
1598
  }
1350
1599
  close() {
1351
1600
  this._extensionContext.close();