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

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.
@@ -2,15 +2,15 @@ import "@dxos/node-std/globals";
2
2
 
3
3
  // packages/core/mesh/teleport/src/testing/test-builder.ts
4
4
  import { pipeline } from "@dxos/node-std/stream";
5
- import invariant4 from "tiny-invariant";
5
+ import { invariant as invariant4 } from "@dxos/invariant";
6
6
  import { PublicKey as PublicKey2 } from "@dxos/keys";
7
7
  import { log as log4 } from "@dxos/log";
8
8
 
9
9
  // packages/core/mesh/teleport/src/teleport.ts
10
- import invariant3 from "tiny-invariant";
11
10
  import { asyncTimeout, scheduleTaskInterval as scheduleTaskInterval2, runInContextAsync, synchronized, scheduleTask } from "@dxos/async";
12
11
  import { Context as Context2 } from "@dxos/context";
13
12
  import { failUndefined as failUndefined2 } from "@dxos/debug";
13
+ import { invariant as invariant3 } from "@dxos/invariant";
14
14
  import { PublicKey } from "@dxos/keys";
15
15
  import { log as log3 } from "@dxos/log";
16
16
  import { schema as schema2, RpcClosedError } from "@dxos/protocols";
@@ -19,10 +19,15 @@ import { Callback } from "@dxos/util";
19
19
 
20
20
  // packages/core/mesh/teleport/src/muxing/framer.ts
21
21
  import { Duplex } from "@dxos/node-std/stream";
22
- import invariant from "tiny-invariant";
22
+ import { invariant } from "@dxos/invariant";
23
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/muxing/framer.ts";
23
24
  var FRAME_LENGTH_SIZE = 2;
24
25
  var Framer = class {
25
26
  constructor() {
27
+ // private readonly _tagBuffer = Buffer.alloc(4)
28
+ this._messageCb = void 0;
29
+ this._subscribeCb = void 0;
30
+ this._buffer = void 0;
26
31
  this._sendCallbacks = [];
27
32
  this._bytesSent = 0;
28
33
  this._bytesReceived = 0;
@@ -32,7 +37,15 @@ var Framer = class {
32
37
  this._processResponseQueue();
33
38
  },
34
39
  write: (chunk, encoding, callback) => {
35
- invariant(!this._subscribeCb, "Internal Framer bug. Concurrent writes detected.");
40
+ invariant(!this._subscribeCb, "Internal Framer bug. Concurrent writes detected.", {
41
+ F: __dxlog_file,
42
+ L: 34,
43
+ S: this,
44
+ A: [
45
+ "!this._subscribeCb",
46
+ "'Internal Framer bug. Concurrent writes detected.'"
47
+ ]
48
+ });
36
49
  this._bytesReceived += chunk.length;
37
50
  if (this._buffer && this._buffer.length > 0) {
38
51
  this._buffer = Buffer.concat([
@@ -68,10 +81,17 @@ var Framer = class {
68
81
  });
69
82
  },
70
83
  subscribe: (callback) => {
71
- var _a;
72
- invariant(!this._messageCb, "Rpc port already has a message listener.");
84
+ invariant(!this._messageCb, "Rpc port already has a message listener.", {
85
+ F: __dxlog_file,
86
+ L: 73,
87
+ S: this,
88
+ A: [
89
+ "!this._messageCb",
90
+ "'Rpc port already has a message listener.'"
91
+ ]
92
+ });
73
93
  this._messageCb = callback;
74
- (_a = this._subscribeCb) == null ? void 0 : _a.call(this);
94
+ this._subscribeCb?.();
75
95
  return () => {
76
96
  this._messageCb = void 0;
77
97
  };
@@ -139,10 +159,10 @@ var encodeFrame = (payload) => {
139
159
 
140
160
  // packages/core/mesh/teleport/src/muxing/muxer.ts
141
161
  import { Duplex as Duplex2 } from "@dxos/node-std/stream";
142
- import invariant2 from "tiny-invariant";
143
162
  import { scheduleTaskInterval, Event as Event2, Trigger } from "@dxos/async";
144
163
  import { Context } from "@dxos/context";
145
164
  import { failUndefined } from "@dxos/debug";
165
+ import { invariant as invariant2 } from "@dxos/invariant";
146
166
  import { log as log2 } from "@dxos/log";
147
167
  import { schema } from "@dxos/protocols";
148
168
 
@@ -150,7 +170,7 @@ import { schema } from "@dxos/protocols";
150
170
  import * as varint from "varint";
151
171
  import { Event } from "@dxos/async";
152
172
  import { log } from "@dxos/log";
153
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/muxing/balancer.ts";
173
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/muxing/balancer.ts";
154
174
  var MAX_CHUNK_SIZE = 8192;
155
175
  var Balancer = class {
156
176
  constructor(_sysChannelId) {
@@ -200,7 +220,7 @@ var Balancer = class {
200
220
  });
201
221
  if (noCalls) {
202
222
  this._sendChunks().catch((err) => log.catch(err, void 0, {
203
- F: __dxlog_file,
223
+ F: __dxlog_file2,
204
224
  L: 96,
205
225
  S: this,
206
226
  C: (f, a) => f(...a)
@@ -260,16 +280,15 @@ var Balancer = class {
260
280
  return chunk;
261
281
  }
262
282
  async _sendChunks() {
263
- var _a, _b;
264
283
  if (this._sendBuffers.size === 0) {
265
284
  return;
266
285
  }
267
286
  const chunk = this._getNextChunk();
268
287
  try {
269
288
  await this._framer.port.send(chunk.msg);
270
- (_a = chunk.trigger) == null ? void 0 : _a.wake();
289
+ chunk.trigger?.wake();
271
290
  } catch (err) {
272
- (_b = chunk.trigger) == null ? void 0 : _b.throw(err);
291
+ chunk.trigger?.throw(err);
273
292
  }
274
293
  await this._sendChunks();
275
294
  }
@@ -302,7 +321,7 @@ var decodeChunk = (data, withLength) => {
302
321
  };
303
322
 
304
323
  // packages/core/mesh/teleport/src/muxing/muxer.ts
305
- var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/muxing/muxer.ts";
324
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/muxing/muxer.ts";
306
325
  var Command = schema.getCodecForType("dxos.mesh.muxer.Command");
307
326
  var STATS_INTERVAL = 1e3;
308
327
  var MAX_SAFE_FRAME_SIZE = 1e6;
@@ -316,6 +335,8 @@ var Muxer = class {
316
335
  this._nextId = 1;
317
336
  this._destroyed = false;
318
337
  this._destroying = false;
338
+ this._lastStats = void 0;
339
+ this._lastChannelStats = /* @__PURE__ */ new Map();
319
340
  this.close = new Event2();
320
341
  this.statsUpdated = new Event2();
321
342
  this.stream = this._balancer.stream;
@@ -335,7 +356,15 @@ var Muxer = class {
335
356
  tag,
336
357
  contentType: opts.contentType
337
358
  });
338
- invariant2(!channel.push, `Channel already open: ${tag}`);
359
+ invariant2(!channel.push, `Channel already open: ${tag}`, {
360
+ F: __dxlog_file3,
361
+ L: 134,
362
+ S: this,
363
+ A: [
364
+ "!channel.push",
365
+ "`Channel already open: ${tag}`"
366
+ ]
367
+ });
339
368
  const stream = new Duplex2({
340
369
  write: (data, encoding, callback) => {
341
370
  this._sendData(channel, data).then(() => callback()).catch(callback);
@@ -375,7 +404,15 @@ var Muxer = class {
375
404
  tag,
376
405
  contentType: opts.contentType
377
406
  });
378
- invariant2(!channel.push, `Channel already open: ${tag}`);
407
+ invariant2(!channel.push, `Channel already open: ${tag}`, {
408
+ F: __dxlog_file3,
409
+ L: 186,
410
+ S: this,
411
+ A: [
412
+ "!channel.push",
413
+ "`Channel already open: ${tag}`"
414
+ ]
415
+ });
379
416
  let inboundBuffer = [];
380
417
  let callback;
381
418
  channel.push = (data) => {
@@ -391,7 +428,15 @@ var Muxer = class {
391
428
  await this._sendData(channel, data);
392
429
  },
393
430
  subscribe: (cb) => {
394
- invariant2(!callback, "Only one subscriber is allowed");
431
+ invariant2(!callback, "Only one subscriber is allowed", {
432
+ F: __dxlog_file3,
433
+ L: 208,
434
+ S: this,
435
+ A: [
436
+ "!callback",
437
+ "'Only one subscriber is allowed'"
438
+ ]
439
+ });
395
440
  callback = cb;
396
441
  for (const data of inboundBuffer) {
397
442
  cb(data);
@@ -423,7 +468,7 @@ var Muxer = class {
423
468
  this._destroying = true;
424
469
  this._sendCommand({
425
470
  destroy: {
426
- error: err == null ? void 0 : err.message
471
+ error: err?.message
427
472
  }
428
473
  }, SYSTEM_CHANNEL_ID).then(() => {
429
474
  this._dispose();
@@ -433,35 +478,36 @@ var Muxer = class {
433
478
  void this._ctx.dispose();
434
479
  }
435
480
  _dispose(err) {
436
- var _a;
437
481
  if (this._destroyed) {
438
482
  return;
439
483
  }
440
484
  this._destroyed = true;
441
485
  this._balancer.destroy();
442
486
  for (const channel of this._channelsByTag.values()) {
443
- (_a = channel.destroy) == null ? void 0 : _a.call(channel, err);
487
+ channel.destroy?.(err);
444
488
  }
445
489
  this.close.emit(err);
446
490
  this._channelsByLocalId.clear();
447
491
  this._channelsByTag.clear();
448
492
  }
449
493
  async _handleCommand(cmd) {
450
- var _a;
451
494
  log2("Received command", {
452
495
  cmd
453
496
  }, {
454
- F: __dxlog_file2,
455
- L: 240,
497
+ F: __dxlog_file3,
498
+ L: 283,
456
499
  S: this,
457
500
  C: (f, a) => f(...a)
458
501
  });
459
502
  if (this._destroyed || this._destroying) {
503
+ if (cmd.destroy) {
504
+ return;
505
+ }
460
506
  log2.warn("Received command after destroy", {
461
507
  cmd
462
508
  }, {
463
- F: __dxlog_file2,
464
- L: 243,
509
+ F: __dxlog_file3,
510
+ L: 290,
465
511
  S: this,
466
512
  C: (f, a) => f(...a)
467
513
  });
@@ -483,13 +529,13 @@ var Muxer = class {
483
529
  }
484
530
  channel.buffer = [];
485
531
  } else if (cmd.data) {
486
- const stream = (_a = this._channelsByLocalId.get(cmd.data.channelId)) != null ? _a : failUndefined();
532
+ const stream = this._channelsByLocalId.get(cmd.data.channelId) ?? failUndefined();
487
533
  if (!stream.push) {
488
534
  log2.warn("Received data for channel before it was opened", {
489
535
  tag: stream.tag
490
536
  }, {
491
- F: __dxlog_file2,
492
- L: 270,
537
+ F: __dxlog_file3,
538
+ L: 317,
493
539
  S: this,
494
540
  C: (f, a) => f(...a)
495
541
  });
@@ -537,8 +583,8 @@ var Muxer = class {
537
583
  size: data.length,
538
584
  threshold: MAX_SAFE_FRAME_SIZE
539
585
  }, {
540
- F: __dxlog_file2,
541
- L: 314,
586
+ F: __dxlog_file3,
587
+ L: 362,
542
588
  S: this,
543
589
  C: (f, a) => f(...a)
544
590
  });
@@ -564,21 +610,40 @@ var Muxer = class {
564
610
  }
565
611
  async _emitStats() {
566
612
  if (this._destroyed || this._destroying) {
613
+ this._lastStats = void 0;
614
+ this._lastChannelStats.clear();
567
615
  return;
568
616
  }
569
617
  const bytesSent = this._balancer.bytesSent;
570
618
  const bytesReceived = this._balancer.bytesReceived;
571
- this.statsUpdated.emit({
572
- channels: Array.from(this._channelsByTag.values()).map((channel) => ({
573
- id: channel.id,
574
- tag: channel.tag,
575
- contentType: channel.contentType,
576
- bytesSent: channel.stats.bytesSent,
577
- bytesReceived: channel.stats.bytesReceived
578
- })),
619
+ const now = Date.now();
620
+ const interval = this._lastStats ? (now - this._lastStats.timestamp) / 1e3 : 0;
621
+ const calculateThroughput = (current, last) => last ? {
622
+ bytesSentRate: interval ? (current.bytesSent - last.bytesSent) / interval : void 0,
623
+ bytesReceivedRate: interval ? (current.bytesReceived - last.bytesReceived) / interval : void 0
624
+ } : {};
625
+ this._lastStats = {
626
+ timestamp: now,
627
+ channels: Array.from(this._channelsByTag.values()).map((channel) => {
628
+ const stats = {
629
+ id: channel.id,
630
+ tag: channel.tag,
631
+ contentType: channel.contentType,
632
+ bytesSent: channel.stats.bytesSent,
633
+ bytesReceived: channel.stats.bytesReceived,
634
+ ...calculateThroughput(channel.stats, this._lastChannelStats.get(channel.id))
635
+ };
636
+ this._lastChannelStats.set(channel.id, stats);
637
+ return stats;
638
+ }),
579
639
  bytesSent,
580
- bytesReceived
581
- });
640
+ bytesReceived,
641
+ ...calculateThroughput({
642
+ bytesSent,
643
+ bytesReceived
644
+ }, this._lastStats)
645
+ };
646
+ this.statsUpdated.emit(this._lastStats);
582
647
  }
583
648
  };
584
649
 
@@ -593,14 +658,14 @@ function _ts_decorate(decorators, target, key, desc) {
593
658
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
594
659
  return c > 3 && r && Object.defineProperty(target, key, r), r;
595
660
  }
596
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/teleport.ts";
661
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/teleport.ts";
597
662
  var Teleport = class {
598
663
  constructor({ initiator, localPeerId, remotePeerId }) {
599
664
  this._ctx = new Context2({
600
665
  onError: (err) => {
601
666
  void this.destroy(err).catch(() => {
602
667
  log3.error("Error during destroy", err, {
603
- F: __dxlog_file3,
668
+ F: __dxlog_file4,
604
669
  L: 34,
605
670
  S: this,
606
671
  C: (f, a) => f(...a)
@@ -614,7 +679,7 @@ var Teleport = class {
614
679
  heartbeatTimeout: 1e4,
615
680
  onTimeout: () => {
616
681
  this.destroy(new Error("Connection timed out")).catch((err) => log3.catch(err, void 0, {
617
- F: __dxlog_file3,
682
+ F: __dxlog_file4,
618
683
  L: 45,
619
684
  S: this,
620
685
  C: (f, a) => f(...a)
@@ -624,9 +689,33 @@ var Teleport = class {
624
689
  this._extensions = /* @__PURE__ */ new Map();
625
690
  this._remoteExtensions = /* @__PURE__ */ new Set();
626
691
  this._open = false;
627
- invariant3(typeof initiator === "boolean");
628
- invariant3(PublicKey.isPublicKey(localPeerId));
629
- invariant3(PublicKey.isPublicKey(remotePeerId));
692
+ invariant3(typeof initiator === "boolean", void 0, {
693
+ F: __dxlog_file4,
694
+ L: 55,
695
+ S: this,
696
+ A: [
697
+ "typeof initiator === 'boolean'",
698
+ ""
699
+ ]
700
+ });
701
+ invariant3(PublicKey.isPublicKey(localPeerId), void 0, {
702
+ F: __dxlog_file4,
703
+ L: 56,
704
+ S: this,
705
+ A: [
706
+ "PublicKey.isPublicKey(localPeerId)",
707
+ ""
708
+ ]
709
+ });
710
+ invariant3(PublicKey.isPublicKey(remotePeerId), void 0, {
711
+ F: __dxlog_file4,
712
+ L: 57,
713
+ S: this,
714
+ A: [
715
+ "PublicKey.isPublicKey(remotePeerId)",
716
+ ""
717
+ ]
718
+ });
630
719
  this.initiator = initiator;
631
720
  this.localPeerId = localPeerId;
632
721
  this.remotePeerId = remotePeerId;
@@ -634,12 +723,20 @@ var Teleport = class {
634
723
  log3("remote extension", {
635
724
  name
636
725
  }, {
637
- F: __dxlog_file3,
726
+ F: __dxlog_file4,
638
727
  L: 63,
639
728
  S: this,
640
729
  C: (f, a) => f(...a)
641
730
  });
642
- invariant3(!this._remoteExtensions.has(name), "Remote extension already exists");
731
+ invariant3(!this._remoteExtensions.has(name), "Remote extension already exists", {
732
+ F: __dxlog_file4,
733
+ L: 64,
734
+ S: this,
735
+ A: [
736
+ "!this._remoteExtensions.has(name)",
737
+ "'Remote extension already exists'"
738
+ ]
739
+ });
643
740
  this._remoteExtensions.add(name);
644
741
  if (this._extensions.has(name)) {
645
742
  try {
@@ -662,11 +759,13 @@ var Teleport = class {
662
759
  localPeerId,
663
760
  remotePeerId,
664
761
  bytesSent: stats.bytesSent,
762
+ bytesSentRate: stats.bytesSentRate,
665
763
  bytesReceived: stats.bytesReceived,
764
+ bytesReceivedRate: stats.bytesReceivedRate,
666
765
  channels: stats.channels
667
766
  }, {
668
- F: __dxlog_file3,
669
- L: 88,
767
+ F: __dxlog_file4,
768
+ L: 89,
670
769
  S: this,
671
770
  C: (f, a) => f(...a)
672
771
  });
@@ -699,8 +798,8 @@ var Teleport = class {
699
798
  await extension.onClose(err);
700
799
  } catch (err2) {
701
800
  log3.catch(err2, void 0, {
702
- F: __dxlog_file3,
703
- L: 132,
801
+ F: __dxlog_file4,
802
+ L: 137,
704
803
  S: this,
705
804
  C: (f, a) => f(...a)
706
805
  });
@@ -715,8 +814,8 @@ var Teleport = class {
715
814
  log3("addExtension", {
716
815
  name
717
816
  }, {
718
- F: __dxlog_file3,
719
- L: 144,
817
+ F: __dxlog_file4,
818
+ L: 149,
720
819
  S: this,
721
820
  C: (f, a) => f(...a)
722
821
  });
@@ -738,31 +837,62 @@ var Teleport = class {
738
837
  }
739
838
  }
740
839
  _setExtension(extensionName, extension) {
741
- invariant3(!extensionName.includes("/"), "Invalid extension name");
742
- invariant3(!this._extensions.has(extensionName), "Extension already exists");
840
+ invariant3(!extensionName.includes("/"), "Invalid extension name", {
841
+ F: __dxlog_file4,
842
+ L: 173,
843
+ S: this,
844
+ A: [
845
+ "!extensionName.includes('/')",
846
+ "'Invalid extension name'"
847
+ ]
848
+ });
849
+ invariant3(!this._extensions.has(extensionName), "Extension already exists", {
850
+ F: __dxlog_file4,
851
+ L: 174,
852
+ S: this,
853
+ A: [
854
+ "!this._extensions.has(extensionName)",
855
+ "'Extension already exists'"
856
+ ]
857
+ });
743
858
  this._extensions.set(extensionName, extension);
744
859
  }
745
860
  async _openExtension(extensionName) {
746
- var _a;
747
861
  log3("open extension", {
748
862
  extensionName
749
863
  }, {
750
- F: __dxlog_file3,
751
- L: 174,
864
+ F: __dxlog_file4,
865
+ L: 179,
752
866
  S: this,
753
867
  C: (f, a) => f(...a)
754
868
  });
755
- const extension = (_a = this._extensions.get(extensionName)) != null ? _a : failUndefined2();
869
+ const extension = this._extensions.get(extensionName) ?? failUndefined2();
756
870
  const context = {
757
871
  initiator: this.initiator,
758
872
  localPeerId: this.localPeerId,
759
873
  remotePeerId: this.remotePeerId,
760
874
  createPort: async (channelName, opts) => {
761
- invariant3(!channelName.includes("/"), "Invalid channel name");
875
+ invariant3(!channelName.includes("/"), "Invalid channel name", {
876
+ F: __dxlog_file4,
877
+ L: 187,
878
+ S: this,
879
+ A: [
880
+ "!channelName.includes('/')",
881
+ "'Invalid channel name'"
882
+ ]
883
+ });
762
884
  return this._muxer.createPort(`${extensionName}/${channelName}`, opts);
763
885
  },
764
886
  createStream: async (channelName, opts) => {
765
- invariant3(!channelName.includes("/"), "Invalid channel name");
887
+ invariant3(!channelName.includes("/"), "Invalid channel name", {
888
+ F: __dxlog_file4,
889
+ L: 191,
890
+ S: this,
891
+ A: [
892
+ "!channelName.includes('/')",
893
+ "'Invalid channel name'"
894
+ ]
895
+ });
766
896
  return this._muxer.createStream(`${extensionName}/${channelName}`, opts);
767
897
  },
768
898
  close: (err) => {
@@ -775,8 +905,8 @@ var Teleport = class {
775
905
  log3("extension opened", {
776
906
  extensionName
777
907
  }, {
778
- F: __dxlog_file3,
779
- L: 197,
908
+ F: __dxlog_file4,
909
+ L: 202,
780
910
  S: this,
781
911
  C: (f, a) => f(...a)
782
912
  });
@@ -838,7 +968,7 @@ var ControlExtension = class {
838
968
  };
839
969
 
840
970
  // packages/core/mesh/teleport/src/testing/test-builder.ts
841
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/testing/test-builder.ts";
971
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/testing/test-builder.ts";
842
972
  var TestBuilder = class {
843
973
  constructor() {
844
974
  this._peers = /* @__PURE__ */ new Set();
@@ -857,9 +987,33 @@ var TestBuilder = class {
857
987
  await Promise.all(Array.from(this._peers).map((agent) => agent.destroy()));
858
988
  }
859
989
  async connect(peer1, peer2) {
860
- invariant4(peer1 !== peer2);
861
- invariant4(this._peers.has(peer1));
862
- invariant4(this._peers.has(peer1));
990
+ invariant4(peer1 !== peer2, void 0, {
991
+ F: __dxlog_file5,
992
+ L: 37,
993
+ S: this,
994
+ A: [
995
+ "peer1 !== peer2",
996
+ ""
997
+ ]
998
+ });
999
+ invariant4(this._peers.has(peer1), void 0, {
1000
+ F: __dxlog_file5,
1001
+ L: 38,
1002
+ S: this,
1003
+ A: [
1004
+ "this._peers.has(peer1)",
1005
+ ""
1006
+ ]
1007
+ });
1008
+ invariant4(this._peers.has(peer1), void 0, {
1009
+ F: __dxlog_file5,
1010
+ L: 39,
1011
+ S: this,
1012
+ A: [
1013
+ "this._peers.has(peer1)",
1014
+ ""
1015
+ ]
1016
+ });
863
1017
  const connection1 = peer1.createConnection({
864
1018
  initiator: true,
865
1019
  remotePeerId: peer2.peerId
@@ -879,13 +1033,53 @@ var TestBuilder = class {
879
1033
  ];
880
1034
  }
881
1035
  async disconnect(peer1, peer2) {
882
- invariant4(peer1 !== peer2);
883
- invariant4(this._peers.has(peer1));
884
- invariant4(this._peers.has(peer1));
1036
+ invariant4(peer1 !== peer2, void 0, {
1037
+ F: __dxlog_file5,
1038
+ L: 51,
1039
+ S: this,
1040
+ A: [
1041
+ "peer1 !== peer2",
1042
+ ""
1043
+ ]
1044
+ });
1045
+ invariant4(this._peers.has(peer1), void 0, {
1046
+ F: __dxlog_file5,
1047
+ L: 52,
1048
+ S: this,
1049
+ A: [
1050
+ "this._peers.has(peer1)",
1051
+ ""
1052
+ ]
1053
+ });
1054
+ invariant4(this._peers.has(peer1), void 0, {
1055
+ F: __dxlog_file5,
1056
+ L: 53,
1057
+ S: this,
1058
+ A: [
1059
+ "this._peers.has(peer1)",
1060
+ ""
1061
+ ]
1062
+ });
885
1063
  const connection1 = Array.from(peer1.connections).find((connection) => connection.remotePeerId.equals(peer2.peerId));
886
1064
  const connection2 = Array.from(peer2.connections).find((connection) => connection.remotePeerId.equals(peer1.peerId));
887
- invariant4(connection1);
888
- invariant4(connection2);
1065
+ invariant4(connection1, void 0, {
1066
+ F: __dxlog_file5,
1067
+ L: 62,
1068
+ S: this,
1069
+ A: [
1070
+ "connection1",
1071
+ ""
1072
+ ]
1073
+ });
1074
+ invariant4(connection2, void 0, {
1075
+ F: __dxlog_file5,
1076
+ L: 63,
1077
+ S: this,
1078
+ A: [
1079
+ "connection2",
1080
+ ""
1081
+ ]
1082
+ });
889
1083
  await Promise.all([
890
1084
  peer1.closeConnection(connection1),
891
1085
  peer2.closeConnection(connection2)
@@ -907,12 +1101,28 @@ var TestPeer = class {
907
1101
  return connection;
908
1102
  }
909
1103
  async openConnection(connection) {
910
- invariant4(this.connections.has(connection));
1104
+ invariant4(this.connections.has(connection), void 0, {
1105
+ F: __dxlog_file5,
1106
+ L: 84,
1107
+ S: this,
1108
+ A: [
1109
+ "this.connections.has(connection)",
1110
+ ""
1111
+ ]
1112
+ });
911
1113
  await connection.teleport.open();
912
1114
  await this.onOpen(connection);
913
1115
  }
914
1116
  async closeConnection(connection) {
915
- invariant4(this.connections.has(connection));
1117
+ invariant4(this.connections.has(connection), void 0, {
1118
+ F: __dxlog_file5,
1119
+ L: 90,
1120
+ S: this,
1121
+ A: [
1122
+ "this.connections.has(connection)",
1123
+ ""
1124
+ ]
1125
+ });
916
1126
  await this.onClose(connection);
917
1127
  await connection.teleport.close();
918
1128
  this.connections.delete(connection);
@@ -927,7 +1137,7 @@ var pipeStreams = (stream1, stream2) => {
927
1137
  pipeline(stream1, stream2, (err) => {
928
1138
  if (err && err.code !== "ERR_STREAM_PREMATURE_CLOSE") {
929
1139
  log4.catch(err, void 0, {
930
- F: __dxlog_file4,
1140
+ F: __dxlog_file5,
931
1141
  L: 106,
932
1142
  S: void 0,
933
1143
  C: (f, a) => f(...a)
@@ -937,7 +1147,7 @@ var pipeStreams = (stream1, stream2) => {
937
1147
  pipeline(stream2, stream1, (err) => {
938
1148
  if (err && err.code !== "ERR_STREAM_PREMATURE_CLOSE") {
939
1149
  log4.catch(err, void 0, {
940
- F: __dxlog_file4,
1150
+ F: __dxlog_file5,
941
1151
  L: 111,
942
1152
  S: void 0,
943
1153
  C: (f, a) => f(...a)
@@ -959,12 +1169,12 @@ var TestConnection = class {
959
1169
  };
960
1170
 
961
1171
  // packages/core/mesh/teleport/src/testing/test-extension.ts
962
- import invariant5 from "tiny-invariant";
963
1172
  import { asyncTimeout as asyncTimeout2, Trigger as Trigger2 } from "@dxos/async";
1173
+ import { invariant as invariant5 } from "@dxos/invariant";
964
1174
  import { log as log5 } from "@dxos/log";
965
1175
  import { schema as schema3 } from "@dxos/protocols";
966
1176
  import { createProtoRpcPeer as createProtoRpcPeer2 } from "@dxos/rpc";
967
- var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/testing/test-extension.ts";
1177
+ var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/testing/test-extension.ts";
968
1178
  var TestExtension = class {
969
1179
  constructor(callbacks = {}) {
970
1180
  this.callbacks = callbacks;
@@ -972,17 +1182,15 @@ var TestExtension = class {
972
1182
  this.closed = new Trigger2();
973
1183
  }
974
1184
  get remotePeerId() {
975
- var _a;
976
- return (_a = this.extensionContext) == null ? void 0 : _a.remotePeerId;
1185
+ return this.extensionContext?.remotePeerId;
977
1186
  }
978
1187
  async onOpen(context) {
979
- var _a, _b;
980
1188
  log5("onOpen", {
981
1189
  localPeerId: context.localPeerId,
982
1190
  remotePeerId: context.remotePeerId
983
1191
  }, {
984
- F: __dxlog_file5,
985
- L: 33,
1192
+ F: __dxlog_file6,
1193
+ L: 32,
986
1194
  S: this,
987
1195
  C: (f, a) => f(...a)
988
1196
  });
@@ -1011,22 +1219,21 @@ var TestExtension = class {
1011
1219
  timeout: 2e3
1012
1220
  });
1013
1221
  await this._rpc.open();
1014
- await ((_b = (_a = this.callbacks).onOpen) == null ? void 0 : _b.call(_a));
1222
+ await this.callbacks.onOpen?.();
1015
1223
  this.open.wake();
1016
1224
  }
1017
1225
  async onClose(err) {
1018
- var _a, _b, _c;
1019
1226
  log5("onClose", {
1020
1227
  err
1021
1228
  }, {
1022
- F: __dxlog_file5,
1023
- L: 67,
1229
+ F: __dxlog_file6,
1230
+ L: 66,
1024
1231
  S: this,
1025
1232
  C: (f, a) => f(...a)
1026
1233
  });
1027
- await ((_b = (_a = this.callbacks).onClose) == null ? void 0 : _b.call(_a));
1234
+ await this.callbacks.onClose?.();
1028
1235
  this.closed.wake();
1029
- await ((_c = this._rpc) == null ? void 0 : _c.close());
1236
+ await this._rpc?.close();
1030
1237
  }
1031
1238
  async test(message = "test") {
1032
1239
  await this.open.wait({
@@ -1035,25 +1242,32 @@ var TestExtension = class {
1035
1242
  const res = await asyncTimeout2(this._rpc.rpc.TestService.testCall({
1036
1243
  data: message
1037
1244
  }), 1500);
1038
- invariant5(res.data === message);
1245
+ invariant5(res.data === message, void 0, {
1246
+ F: __dxlog_file6,
1247
+ L: 75,
1248
+ S: this,
1249
+ A: [
1250
+ "res.data === message",
1251
+ ""
1252
+ ]
1253
+ });
1039
1254
  }
1040
1255
  /**
1041
1256
  * Force-close the connection.
1042
1257
  */
1043
1258
  async closeConnection(err) {
1044
- var _a;
1045
- (_a = this.extensionContext) == null ? void 0 : _a.close(err);
1259
+ this.extensionContext?.close(err);
1046
1260
  }
1047
1261
  };
1048
1262
 
1049
1263
  // packages/core/mesh/teleport/src/testing/test-extension-with-streams.ts
1050
- import assert from "@dxos/node-std/assert";
1051
1264
  import { randomBytes } from "@dxos/node-std/crypto";
1052
1265
  import { Trigger as Trigger3 } from "@dxos/async";
1266
+ import { invariant as invariant6 } from "@dxos/invariant";
1053
1267
  import { log as log6 } from "@dxos/log";
1054
1268
  import { schema as schema4 } from "@dxos/protocols";
1055
1269
  import { createProtoRpcPeer as createProtoRpcPeer3 } from "@dxos/rpc";
1056
- var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/testing/test-extension-with-streams.ts";
1270
+ var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/testing/test-extension-with-streams.ts";
1057
1271
  var TestExtensionWithStreams = class {
1058
1272
  constructor(callbacks = {}) {
1059
1273
  this.callbacks = callbacks;
@@ -1062,11 +1276,18 @@ var TestExtensionWithStreams = class {
1062
1276
  this._streams = /* @__PURE__ */ new Map();
1063
1277
  }
1064
1278
  get remotePeerId() {
1065
- var _a;
1066
- return (_a = this.extensionContext) == null ? void 0 : _a.remotePeerId;
1279
+ return this.extensionContext?.remotePeerId;
1067
1280
  }
1068
1281
  async _openStream(streamTag, interval = 5, chunkSize = 2048) {
1069
- assert(!this._streams.has(streamTag), `Stream already exists: ${streamTag}`);
1282
+ invariant6(!this._streams.has(streamTag), `Stream already exists: ${streamTag}`, {
1283
+ F: __dxlog_file7,
1284
+ L: 37,
1285
+ S: this,
1286
+ A: [
1287
+ "!this._streams.has(streamTag)",
1288
+ "`Stream already exists: ${streamTag}`"
1289
+ ]
1290
+ });
1070
1291
  const networkStream = await this.extensionContext.createStream(streamTag, {
1071
1292
  contentType: "application/x-test-stream"
1072
1293
  });
@@ -1106,7 +1327,6 @@ var TestExtensionWithStreams = class {
1106
1327
  networkStream.removeAllListeners();
1107
1328
  });
1108
1329
  streamEntry.reportingTimer = setInterval(() => {
1109
- var _a, _b;
1110
1330
  const { bytesSent, bytesReceived, sendErrors, receiveErrors } = streamEntry;
1111
1331
  log6.trace("dxos.test.stream-stats", {
1112
1332
  streamTag,
@@ -1114,10 +1334,10 @@ var TestExtensionWithStreams = class {
1114
1334
  bytesReceived,
1115
1335
  sendErrors,
1116
1336
  receiveErrors,
1117
- from: (_a = this.extensionContext) == null ? void 0 : _a.localPeerId,
1118
- to: (_b = this.extensionContext) == null ? void 0 : _b.remotePeerId
1337
+ from: this.extensionContext?.localPeerId,
1338
+ to: this.extensionContext?.remotePeerId
1119
1339
  }, {
1120
- F: __dxlog_file6,
1340
+ F: __dxlog_file7,
1121
1341
  L: 91,
1122
1342
  S: this,
1123
1343
  C: (f, a) => f(...a)
@@ -1125,7 +1345,15 @@ var TestExtensionWithStreams = class {
1125
1345
  }, 100);
1126
1346
  }
1127
1347
  _closeStream(streamTag) {
1128
- assert(this._streams.has(streamTag), `Stream does not exist: ${streamTag}`);
1348
+ invariant6(this._streams.has(streamTag), `Stream does not exist: ${streamTag}`, {
1349
+ F: __dxlog_file7,
1350
+ L: 104,
1351
+ S: this,
1352
+ A: [
1353
+ "this._streams.has(streamTag)",
1354
+ "`Stream does not exist: ${streamTag}`"
1355
+ ]
1356
+ });
1129
1357
  const stream = this._streams.get(streamTag);
1130
1358
  clearTimeout(stream.timer);
1131
1359
  clearTimeout(stream.reportingTimer);
@@ -1137,16 +1365,15 @@ var TestExtensionWithStreams = class {
1137
1365
  bytesReceived,
1138
1366
  sendErrors,
1139
1367
  receiveErrors,
1140
- runningTime: Date.now() - (startTimestamp != null ? startTimestamp : 0)
1368
+ runningTime: Date.now() - (startTimestamp ?? 0)
1141
1369
  };
1142
1370
  }
1143
1371
  async onOpen(context) {
1144
- var _a, _b;
1145
1372
  log6("onOpen", {
1146
1373
  localPeerId: context.localPeerId,
1147
1374
  remotePeerId: context.remotePeerId
1148
1375
  }, {
1149
- F: __dxlog_file6,
1376
+ F: __dxlog_file7,
1150
1377
  L: 126,
1151
1378
  S: this,
1152
1379
  C: (f, a) => f(...a)
@@ -1188,26 +1415,25 @@ var TestExtensionWithStreams = class {
1188
1415
  timeout: 2e3
1189
1416
  });
1190
1417
  await this._rpc.open();
1191
- await ((_b = (_a = this.callbacks).onOpen) == null ? void 0 : _b.call(_a));
1418
+ await this.callbacks.onOpen?.();
1192
1419
  this.open.wake();
1193
1420
  }
1194
1421
  async onClose(err) {
1195
- var _a, _b, _c;
1196
1422
  log6("onClose", {
1197
1423
  err
1198
1424
  }, {
1199
- F: __dxlog_file6,
1425
+ F: __dxlog_file7,
1200
1426
  L: 177,
1201
1427
  S: this,
1202
1428
  C: (f, a) => f(...a)
1203
1429
  });
1204
- await ((_b = (_a = this.callbacks).onClose) == null ? void 0 : _b.call(_a));
1430
+ await this.callbacks.onClose?.();
1205
1431
  this.closed.wake();
1206
1432
  for (const [streamTag, stream] of Object.entries(this._streams)) {
1207
1433
  log6("closing stream", {
1208
1434
  streamTag
1209
1435
  }, {
1210
- F: __dxlog_file6,
1436
+ F: __dxlog_file7,
1211
1437
  L: 181,
1212
1438
  S: this,
1213
1439
  C: (f, a) => f(...a)
@@ -1215,7 +1441,7 @@ var TestExtensionWithStreams = class {
1215
1441
  clearTimeout(stream.interval);
1216
1442
  stream.networkStream.destroy();
1217
1443
  }
1218
- await ((_c = this._rpc) == null ? void 0 : _c.close());
1444
+ await this._rpc?.close();
1219
1445
  }
1220
1446
  async addNewStream(streamLoadInterval, streamLoadChunkSize, streamTag) {
1221
1447
  await this.open.wait({
@@ -1229,7 +1455,15 @@ var TestExtensionWithStreams = class {
1229
1455
  streamLoadInterval,
1230
1456
  streamLoadChunkSize
1231
1457
  });
1232
- assert(data === streamTag);
1458
+ invariant6(data === streamTag, void 0, {
1459
+ F: __dxlog_file7,
1460
+ L: 198,
1461
+ S: this,
1462
+ A: [
1463
+ "data === streamTag",
1464
+ ""
1465
+ ]
1466
+ });
1233
1467
  await this._openStream(streamTag, streamLoadInterval, streamLoadChunkSize);
1234
1468
  return streamTag;
1235
1469
  }
@@ -1240,7 +1474,15 @@ var TestExtensionWithStreams = class {
1240
1474
  const { data, bytesSent, bytesReceived, sendErrors, receiveErrors, runningTime } = await this._rpc.rpc.TestServiceWithStreams.closeTestStream({
1241
1475
  data: streamTag
1242
1476
  });
1243
- assert(data === streamTag);
1477
+ invariant6(data === streamTag, void 0, {
1478
+ F: __dxlog_file7,
1479
+ L: 211,
1480
+ S: this,
1481
+ A: [
1482
+ "data === streamTag",
1483
+ ""
1484
+ ]
1485
+ });
1244
1486
  const local = this._closeStream(streamTag);
1245
1487
  return {
1246
1488
  streamTag,
@@ -1260,8 +1502,7 @@ var TestExtensionWithStreams = class {
1260
1502
  * Force-close the connection.
1261
1503
  */
1262
1504
  async closeConnection(err) {
1263
- var _a;
1264
- (_a = this.extensionContext) == null ? void 0 : _a.close(err);
1505
+ this.extensionContext?.close(err);
1265
1506
  }
1266
1507
  };
1267
1508
 
@@ -1277,4 +1518,4 @@ export {
1277
1518
  TestExtension,
1278
1519
  TestExtensionWithStreams
1279
1520
  };
1280
- //# sourceMappingURL=chunk-GGVQ27WJ.mjs.map
1521
+ //# sourceMappingURL=chunk-QKTUX7U5.mjs.map