@dxos/teleport 0.3.9-main.b7e6a67 → 0.3.9-main.c7cd0ec

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.
@@ -1,5 +1,12 @@
1
1
  import "@dxos/node-std/globals";
2
2
 
3
+ // inject-globals:@inject-globals
4
+ import {
5
+ global,
6
+ Buffer,
7
+ process
8
+ } from "@dxos/node-std/inject-globals";
9
+
3
10
  // packages/core/mesh/teleport/src/testing/test-builder.ts
4
11
  import { pipeline } from "@dxos/node-std/stream";
5
12
  import { invariant as invariant5 } from "@dxos/invariant";
@@ -12,7 +19,7 @@ import { Context as Context3 } from "@dxos/context";
12
19
  import { failUndefined as failUndefined2 } from "@dxos/debug";
13
20
  import { invariant as invariant4 } from "@dxos/invariant";
14
21
  import { PublicKey } from "@dxos/keys";
15
- import { log as log5 } from "@dxos/log";
22
+ import { log as log5, logInfo as logInfo2 } from "@dxos/log";
16
23
  import { RpcClosedError as RpcClosedError2, TimeoutError as TimeoutError2 } from "@dxos/protocols";
17
24
 
18
25
  // packages/core/mesh/teleport/src/control-extension.ts
@@ -325,11 +332,11 @@ var encodeFrame = (payload) => {
325
332
 
326
333
  // packages/core/mesh/teleport/src/muxing/muxer.ts
327
334
  import { Duplex as Duplex2 } from "@dxos/node-std/stream";
328
- import { scheduleTaskInterval as scheduleTaskInterval2, Event as Event3, Trigger } from "@dxos/async";
335
+ import { scheduleTaskInterval as scheduleTaskInterval2, Event as Event3, Trigger, asyncTimeout as asyncTimeout2 } from "@dxos/async";
329
336
  import { Context as Context2 } from "@dxos/context";
330
337
  import { failUndefined } from "@dxos/debug";
331
338
  import { invariant as invariant3 } from "@dxos/invariant";
332
- import { log as log4 } from "@dxos/log";
339
+ import { log as log4, logInfo } from "@dxos/log";
333
340
  import { schema as schema2, TimeoutError } from "@dxos/protocols";
334
341
 
335
342
  // packages/core/mesh/teleport/src/muxing/balancer.ts
@@ -542,6 +549,16 @@ var decodeChunk = (data, withLength) => {
542
549
  };
543
550
 
544
551
  // packages/core/mesh/teleport/src/muxing/muxer.ts
552
+ function _ts_decorate(decorators, target, key, desc) {
553
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
554
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
555
+ r = Reflect.decorate(decorators, target, key, desc);
556
+ else
557
+ for (var i = decorators.length - 1; i >= 0; i--)
558
+ if (d = decorators[i])
559
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
560
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
561
+ }
545
562
  var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/muxing/muxer.ts";
546
563
  var Command = schema2.getCodecForType("dxos.mesh.muxer.Command");
547
564
  var DEFAULT_SEND_COMMAND_TIMEOUT = 6e4;
@@ -569,6 +586,12 @@ var Muxer = class {
569
586
  await this._handleCommand(Command.decode(msg));
570
587
  });
571
588
  }
589
+ setSessionId(sessionId) {
590
+ this._sessionId = sessionId;
591
+ }
592
+ get sessionIdString() {
593
+ return this._sessionId ? this._sessionId.truncate() : "none";
594
+ }
572
595
  /**
573
596
  * Creates a duplex Node.js-style stream.
574
597
  * The remote peer is expected to call `createStream` with the same tag.
@@ -582,7 +605,7 @@ var Muxer = class {
582
605
  });
583
606
  invariant3(!channel.push, `Channel already open: ${tag}`, {
584
607
  F: __dxlog_file4,
585
- L: 140,
608
+ L: 151,
586
609
  S: this,
587
610
  A: [
588
611
  "!channel.push",
@@ -601,7 +624,15 @@ var Muxer = class {
601
624
  stream.push(data);
602
625
  };
603
626
  channel.destroy = (err) => {
604
- stream.destroy(err);
627
+ if (err) {
628
+ if (stream.listeners("error").length > 0) {
629
+ stream.destroy(err);
630
+ } else {
631
+ stream.destroy();
632
+ }
633
+ } else {
634
+ stream.destroy();
635
+ }
605
636
  };
606
637
  try {
607
638
  await this._sendCommand({
@@ -630,7 +661,7 @@ var Muxer = class {
630
661
  });
631
662
  invariant3(!channel.push, `Channel already open: ${tag}`, {
632
663
  F: __dxlog_file4,
633
- L: 192,
664
+ L: 211,
634
665
  S: this,
635
666
  A: [
636
667
  "!channel.push",
@@ -654,7 +685,7 @@ var Muxer = class {
654
685
  subscribe: (cb) => {
655
686
  invariant3(!callback, "Only one subscriber is allowed", {
656
687
  F: __dxlog_file4,
657
- L: 214,
688
+ L: 233,
658
689
  S: this,
659
690
  A: [
660
691
  "!callback",
@@ -687,7 +718,7 @@ var Muxer = class {
687
718
  if (this._destroying) {
688
719
  log4("already destroying, ignoring graceful close request", void 0, {
689
720
  F: __dxlog_file4,
690
- L: 247,
721
+ L: 266,
691
722
  S: this,
692
723
  C: (f, a) => f(...a)
693
724
  });
@@ -696,7 +727,7 @@ var Muxer = class {
696
727
  if (this._closing) {
697
728
  log4("already closing, ignoring graceful close request", void 0, {
698
729
  F: __dxlog_file4,
699
- L: 251,
730
+ L: 270,
700
731
  S: this,
701
732
  C: (f, a) => f(...a)
702
733
  });
@@ -712,29 +743,20 @@ var Muxer = class {
712
743
  err: err2
713
744
  }, {
714
745
  F: __dxlog_file4,
715
- L: 266,
746
+ L: 285,
716
747
  S: this,
717
748
  C: (f, a) => f(...a)
718
749
  });
719
- await this.dispose(err2);
750
+ await this._dispose(err2);
720
751
  });
721
- await Promise.race([
722
- new Promise((_resolve, reject) => {
723
- setTimeout(() => {
724
- reject(new TimeoutError("gracefully closing muxer"));
725
- }, GRACEFUL_CLOSE_TIMEOUT);
726
- }),
727
- (async () => {
728
- await this.dispose(err);
729
- })()
730
- ]);
752
+ await asyncTimeout2(this._dispose(err), GRACEFUL_CLOSE_TIMEOUT, new TimeoutError("gracefully closing muxer"));
731
753
  }
732
754
  // force close without confirmation
733
755
  async destroy(err) {
734
756
  if (this._destroying) {
735
757
  log4("already destroying, ignoring destroy request", void 0, {
736
758
  F: __dxlog_file4,
737
- L: 287,
759
+ L: 298,
738
760
  S: this,
739
761
  C: (f, a) => f(...a)
740
762
  });
@@ -745,7 +767,7 @@ var Muxer = class {
745
767
  if (this._closing) {
746
768
  log4("destroy cancelling graceful close", void 0, {
747
769
  F: __dxlog_file4,
748
- L: 293,
770
+ L: 304,
749
771
  S: this,
750
772
  C: (f, a) => f(...a)
751
773
  });
@@ -760,29 +782,29 @@ var Muxer = class {
760
782
  err: err2
761
783
  }, {
762
784
  F: __dxlog_file4,
763
- L: 306,
785
+ L: 317,
764
786
  S: this,
765
787
  C: (f, a) => f(...a)
766
788
  });
767
789
  });
768
790
  }
769
- this.dispose(err).catch((err2) => {
791
+ this._dispose(err).catch((err2) => {
770
792
  log4("error disposing after destroy", {
771
793
  err: err2
772
794
  }, {
773
795
  F: __dxlog_file4,
774
- L: 311,
796
+ L: 322,
775
797
  S: this,
776
798
  C: (f, a) => f(...a)
777
799
  });
778
800
  });
779
801
  }
780
802
  // complete the termination, graceful or otherwise
781
- async dispose(err) {
803
+ async _dispose(err) {
782
804
  if (this._disposed) {
783
805
  log4("already destroyed, ignoring dispose request", void 0, {
784
806
  F: __dxlog_file4,
785
- L: 319,
807
+ L: 330,
786
808
  S: this,
787
809
  C: (f, a) => f(...a)
788
810
  });
@@ -794,6 +816,7 @@ var Muxer = class {
794
816
  channel.destroy?.(err);
795
817
  }
796
818
  this._disposed = true;
819
+ await this._emitStats();
797
820
  this.afterClosed.emit(err);
798
821
  this._channelsByLocalId.clear();
799
822
  this._channelsByTag.clear();
@@ -804,7 +827,7 @@ var Muxer = class {
804
827
  cmd
805
828
  }, {
806
829
  F: __dxlog_file4,
807
- L: 341,
830
+ L: 353,
808
831
  S: this,
809
832
  C: (f, a) => f(...a)
810
833
  });
@@ -814,15 +837,15 @@ var Muxer = class {
814
837
  if (!this._closing) {
815
838
  log4("received peer close, initiating my own graceful close", void 0, {
816
839
  F: __dxlog_file4,
817
- L: 347,
840
+ L: 359,
818
841
  S: this,
819
842
  C: (f, a) => f(...a)
820
843
  });
821
- await this.close();
844
+ await this.close(new Error("received peer close"));
822
845
  } else {
823
846
  log4("received close from peer, already closing", void 0, {
824
847
  F: __dxlog_file4,
825
- L: 350,
848
+ L: 362,
826
849
  S: this,
827
850
  C: (f, a) => f(...a)
828
851
  });
@@ -851,7 +874,7 @@ var Muxer = class {
851
874
  tag: stream.tag
852
875
  }, {
853
876
  F: __dxlog_file4,
854
- L: 379,
877
+ L: 391,
855
878
  S: this,
856
879
  C: (f, a) => f(...a)
857
880
  });
@@ -866,7 +889,7 @@ var Muxer = class {
866
889
  cmd
867
890
  }, {
868
891
  F: __dxlog_file4,
869
- L: 388,
892
+ L: 400,
870
893
  S: this,
871
894
  C: (f, a) => f(...a)
872
895
  });
@@ -914,7 +937,7 @@ var Muxer = class {
914
937
  threshold: MAX_SAFE_FRAME_SIZE
915
938
  }, {
916
939
  F: __dxlog_file4,
917
- L: 429,
940
+ L: 441,
918
941
  S: this,
919
942
  C: (f, a) => f(...a)
920
943
  });
@@ -989,9 +1012,12 @@ var Muxer = class {
989
1012
  this.statsUpdated.emit(this._lastStats);
990
1013
  }
991
1014
  };
1015
+ _ts_decorate([
1016
+ logInfo
1017
+ ], Muxer.prototype, "sessionIdString", null);
992
1018
 
993
1019
  // packages/core/mesh/teleport/src/teleport.ts
994
- function _ts_decorate(decorators, target, key, desc) {
1020
+ function _ts_decorate2(decorators, target, key, desc) {
995
1021
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
996
1022
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
997
1023
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1011,7 +1037,7 @@ var Teleport = class {
1011
1037
  void this.destroy(err).catch(() => {
1012
1038
  log5.error("Error during destroy", err, {
1013
1039
  F: __dxlog_file5,
1014
- L: 38,
1040
+ L: 39,
1015
1041
  S: this,
1016
1042
  C: (f, a) => f(...a)
1017
1043
  });
@@ -1026,7 +1052,7 @@ var Teleport = class {
1026
1052
  this._aborting = false;
1027
1053
  invariant4(typeof initiator === "boolean", void 0, {
1028
1054
  F: __dxlog_file5,
1029
- L: 55,
1055
+ L: 56,
1030
1056
  S: this,
1031
1057
  A: [
1032
1058
  "typeof initiator === 'boolean'",
@@ -1035,7 +1061,7 @@ var Teleport = class {
1035
1061
  });
1036
1062
  invariant4(PublicKey.isPublicKey(localPeerId), void 0, {
1037
1063
  F: __dxlog_file5,
1038
- L: 56,
1064
+ L: 57,
1039
1065
  S: this,
1040
1066
  A: [
1041
1067
  "PublicKey.isPublicKey(localPeerId)",
@@ -1044,7 +1070,7 @@ var Teleport = class {
1044
1070
  });
1045
1071
  invariant4(PublicKey.isPublicKey(remotePeerId), void 0, {
1046
1072
  F: __dxlog_file5,
1047
- L: 57,
1073
+ L: 58,
1048
1074
  S: this,
1049
1075
  A: [
1050
1076
  "PublicKey.isPublicKey(remotePeerId)",
@@ -1063,13 +1089,13 @@ var Teleport = class {
1063
1089
  }
1064
1090
  log5.info("abort teleport due to onTimeout in ControlExtension", void 0, {
1065
1091
  F: __dxlog_file5,
1066
- L: 70,
1092
+ L: 71,
1067
1093
  S: this,
1068
1094
  C: (f, a) => f(...a)
1069
1095
  });
1070
1096
  this.abort(new TimeoutError2("control extension")).catch((err) => log5.catch(err, void 0, {
1071
1097
  F: __dxlog_file5,
1072
- L: 71,
1098
+ L: 72,
1073
1099
  S: this,
1074
1100
  C: (f, a) => f(...a)
1075
1101
  }));
@@ -1080,13 +1106,13 @@ var Teleport = class {
1080
1106
  name
1081
1107
  }, {
1082
1108
  F: __dxlog_file5,
1083
- L: 79,
1109
+ L: 80,
1084
1110
  S: this,
1085
1111
  C: (f, a) => f(...a)
1086
1112
  });
1087
1113
  invariant4(!this._remoteExtensions.has(name), "Remote extension already exists", {
1088
1114
  F: __dxlog_file5,
1089
- L: 80,
1115
+ L: 81,
1090
1116
  S: this,
1091
1117
  A: [
1092
1118
  "!this._remoteExtensions.has(name)",
@@ -1107,7 +1133,7 @@ var Teleport = class {
1107
1133
  if (this._destroying || this._aborting) {
1108
1134
  log5("destroy teleport due to muxer stream close, skipping due to already destroying/aborting", void 0, {
1109
1135
  F: __dxlog_file5,
1110
- L: 96,
1136
+ L: 97,
1111
1137
  S: this,
1112
1138
  C: (f, a) => f(...a)
1113
1139
  });
@@ -1130,12 +1156,15 @@ var Teleport = class {
1130
1156
  channels: stats.channels
1131
1157
  }, {
1132
1158
  F: __dxlog_file5,
1133
- L: 109,
1159
+ L: 110,
1134
1160
  S: this,
1135
1161
  C: (f, a) => f(...a)
1136
1162
  });
1137
1163
  });
1138
1164
  }
1165
+ get sessionIdString() {
1166
+ return this._sessionId ? this._sessionId.truncate() : "none";
1167
+ }
1139
1168
  get stream() {
1140
1169
  return this._muxer.stream;
1141
1170
  }
@@ -1145,10 +1174,18 @@ var Teleport = class {
1145
1174
  /**
1146
1175
  * Blocks until the handshake is complete.
1147
1176
  */
1148
- async open() {
1177
+ async open(sessionId = PublicKey.random()) {
1178
+ this._sessionId = sessionId;
1179
+ log5("open", void 0, {
1180
+ F: __dxlog_file5,
1181
+ L: 144,
1182
+ S: this,
1183
+ C: (f, a) => f(...a)
1184
+ });
1149
1185
  this._setExtension("dxos.mesh.teleport.control", this._control);
1150
1186
  await this._openExtension("dxos.mesh.teleport.control");
1151
1187
  this._open = true;
1188
+ this._muxer.setSessionId(sessionId);
1152
1189
  }
1153
1190
  async close(err) {
1154
1191
  await this.destroy(err);
@@ -1168,7 +1205,7 @@ var Teleport = class {
1168
1205
  } catch (err2) {
1169
1206
  log5.catch(err2, void 0, {
1170
1207
  F: __dxlog_file5,
1171
- L: 162,
1208
+ L: 173,
1172
1209
  S: this,
1173
1210
  C: (f, a) => f(...a)
1174
1211
  });
@@ -1191,7 +1228,7 @@ var Teleport = class {
1191
1228
  } catch (err2) {
1192
1229
  log5.catch(err2, void 0, {
1193
1230
  F: __dxlog_file5,
1194
- L: 186,
1231
+ L: 197,
1195
1232
  S: this,
1196
1233
  C: (f, a) => f(...a)
1197
1234
  });
@@ -1207,7 +1244,7 @@ var Teleport = class {
1207
1244
  name
1208
1245
  }, {
1209
1246
  F: __dxlog_file5,
1210
- L: 198,
1247
+ L: 209,
1211
1248
  S: this,
1212
1249
  C: (f, a) => f(...a)
1213
1250
  });
@@ -1231,7 +1268,7 @@ var Teleport = class {
1231
1268
  _setExtension(extensionName, extension) {
1232
1269
  invariant4(!extensionName.includes("/"), "Invalid extension name", {
1233
1270
  F: __dxlog_file5,
1234
- L: 222,
1271
+ L: 233,
1235
1272
  S: this,
1236
1273
  A: [
1237
1274
  "!extensionName.includes('/')",
@@ -1240,7 +1277,7 @@ var Teleport = class {
1240
1277
  });
1241
1278
  invariant4(!this._extensions.has(extensionName), "Extension already exists", {
1242
1279
  F: __dxlog_file5,
1243
- L: 223,
1280
+ L: 234,
1244
1281
  S: this,
1245
1282
  A: [
1246
1283
  "!this._extensions.has(extensionName)",
@@ -1254,7 +1291,7 @@ var Teleport = class {
1254
1291
  extensionName
1255
1292
  }, {
1256
1293
  F: __dxlog_file5,
1257
- L: 228,
1294
+ L: 239,
1258
1295
  S: this,
1259
1296
  C: (f, a) => f(...a)
1260
1297
  });
@@ -1266,7 +1303,7 @@ var Teleport = class {
1266
1303
  createPort: async (channelName, opts) => {
1267
1304
  invariant4(!channelName.includes("/"), "Invalid channel name", {
1268
1305
  F: __dxlog_file5,
1269
- L: 236,
1306
+ L: 247,
1270
1307
  S: this,
1271
1308
  A: [
1272
1309
  "!channelName.includes('/')",
@@ -1278,7 +1315,7 @@ var Teleport = class {
1278
1315
  createStream: async (channelName, opts) => {
1279
1316
  invariant4(!channelName.includes("/"), "Invalid channel name", {
1280
1317
  F: __dxlog_file5,
1281
- L: 240,
1318
+ L: 251,
1282
1319
  S: this,
1283
1320
  A: [
1284
1321
  "!channelName.includes('/')",
@@ -1298,16 +1335,19 @@ var Teleport = class {
1298
1335
  extensionName
1299
1336
  }, {
1300
1337
  F: __dxlog_file5,
1301
- L: 251,
1338
+ L: 262,
1302
1339
  S: this,
1303
1340
  C: (f, a) => f(...a)
1304
1341
  });
1305
1342
  }
1306
1343
  };
1307
- _ts_decorate([
1344
+ _ts_decorate2([
1345
+ logInfo2
1346
+ ], Teleport.prototype, "sessionIdString", null);
1347
+ _ts_decorate2([
1308
1348
  synchronized
1309
1349
  ], Teleport.prototype, "abort", null);
1310
- _ts_decorate([
1350
+ _ts_decorate2([
1311
1351
  synchronized
1312
1352
  ], Teleport.prototype, "destroy", null);
1313
1353
 
@@ -1454,7 +1494,7 @@ var TestPeer = class {
1454
1494
  ""
1455
1495
  ]
1456
1496
  });
1457
- await connection.teleport.open();
1497
+ await connection.teleport.open(PublicKey2.random());
1458
1498
  await this.onOpen(connection);
1459
1499
  }
1460
1500
  async closeConnection(connection) {
@@ -1513,7 +1553,7 @@ var TestConnection = class {
1513
1553
  };
1514
1554
 
1515
1555
  // packages/core/mesh/teleport/src/testing/test-extension.ts
1516
- import { asyncTimeout as asyncTimeout2, Trigger as Trigger2 } from "@dxos/async";
1556
+ import { asyncTimeout as asyncTimeout3, Trigger as Trigger2 } from "@dxos/async";
1517
1557
  import { invariant as invariant6 } from "@dxos/invariant";
1518
1558
  import { log as log7 } from "@dxos/log";
1519
1559
  import { schema as schema3 } from "@dxos/protocols";
@@ -1597,7 +1637,7 @@ var TestExtension = class {
1597
1637
  await this.open.wait({
1598
1638
  timeout: 1500
1599
1639
  });
1600
- const res = await asyncTimeout2(this._rpc.rpc.TestService.testCall({
1640
+ const res = await asyncTimeout3(this._rpc.rpc.TestService.testCall({
1601
1641
  data: message
1602
1642
  }), 1500);
1603
1643
  invariant6(res.data === message, void 0, {
@@ -1890,4 +1930,4 @@ export {
1890
1930
  TestExtension,
1891
1931
  TestExtensionWithStreams
1892
1932
  };
1893
- //# sourceMappingURL=chunk-2FV5BKLH.mjs.map
1933
+ //# sourceMappingURL=chunk-L2L2STAG.mjs.map