@dxos/teleport 0.3.9-main.3a0f16f → 0.3.9-main.3fcc0fa

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -12,7 +12,7 @@ import { Context as Context3 } from "@dxos/context";
12
12
  import { failUndefined as failUndefined2 } from "@dxos/debug";
13
13
  import { invariant as invariant4 } from "@dxos/invariant";
14
14
  import { PublicKey } from "@dxos/keys";
15
- import { log as log5 } from "@dxos/log";
15
+ import { log as log5, logInfo as logInfo2 } from "@dxos/log";
16
16
  import { RpcClosedError as RpcClosedError2, TimeoutError as TimeoutError2 } from "@dxos/protocols";
17
17
 
18
18
  // packages/core/mesh/teleport/src/control-extension.ts
@@ -325,11 +325,11 @@ var encodeFrame = (payload) => {
325
325
 
326
326
  // packages/core/mesh/teleport/src/muxing/muxer.ts
327
327
  import { Duplex as Duplex2 } from "@dxos/node-std/stream";
328
- import { scheduleTaskInterval as scheduleTaskInterval2, Event as Event3, Trigger } from "@dxos/async";
328
+ import { scheduleTaskInterval as scheduleTaskInterval2, Event as Event3, Trigger, asyncTimeout as asyncTimeout2 } from "@dxos/async";
329
329
  import { Context as Context2 } from "@dxos/context";
330
330
  import { failUndefined } from "@dxos/debug";
331
331
  import { invariant as invariant3 } from "@dxos/invariant";
332
- import { log as log4 } from "@dxos/log";
332
+ import { log as log4, logInfo } from "@dxos/log";
333
333
  import { schema as schema2, TimeoutError } from "@dxos/protocols";
334
334
 
335
335
  // packages/core/mesh/teleport/src/muxing/balancer.ts
@@ -542,6 +542,16 @@ var decodeChunk = (data, withLength) => {
542
542
  };
543
543
 
544
544
  // packages/core/mesh/teleport/src/muxing/muxer.ts
545
+ function _ts_decorate(decorators, target, key, desc) {
546
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
547
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
548
+ r = Reflect.decorate(decorators, target, key, desc);
549
+ else
550
+ for (var i = decorators.length - 1; i >= 0; i--)
551
+ if (d = decorators[i])
552
+ r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
553
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
554
+ }
545
555
  var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/core/mesh/teleport/src/muxing/muxer.ts";
546
556
  var Command = schema2.getCodecForType("dxos.mesh.muxer.Command");
547
557
  var DEFAULT_SEND_COMMAND_TIMEOUT = 6e4;
@@ -569,6 +579,12 @@ var Muxer = class {
569
579
  await this._handleCommand(Command.decode(msg));
570
580
  });
571
581
  }
582
+ setSessionId(sessionId) {
583
+ this._sessionId = sessionId;
584
+ }
585
+ get sessionIdString() {
586
+ return this._sessionId ? this._sessionId.truncate() : "none";
587
+ }
572
588
  /**
573
589
  * Creates a duplex Node.js-style stream.
574
590
  * The remote peer is expected to call `createStream` with the same tag.
@@ -582,7 +598,7 @@ var Muxer = class {
582
598
  });
583
599
  invariant3(!channel.push, `Channel already open: ${tag}`, {
584
600
  F: __dxlog_file4,
585
- L: 140,
601
+ L: 151,
586
602
  S: this,
587
603
  A: [
588
604
  "!channel.push",
@@ -638,7 +654,7 @@ var Muxer = class {
638
654
  });
639
655
  invariant3(!channel.push, `Channel already open: ${tag}`, {
640
656
  F: __dxlog_file4,
641
- L: 200,
657
+ L: 211,
642
658
  S: this,
643
659
  A: [
644
660
  "!channel.push",
@@ -662,7 +678,7 @@ var Muxer = class {
662
678
  subscribe: (cb) => {
663
679
  invariant3(!callback, "Only one subscriber is allowed", {
664
680
  F: __dxlog_file4,
665
- L: 222,
681
+ L: 233,
666
682
  S: this,
667
683
  A: [
668
684
  "!callback",
@@ -695,7 +711,7 @@ var Muxer = class {
695
711
  if (this._destroying) {
696
712
  log4("already destroying, ignoring graceful close request", void 0, {
697
713
  F: __dxlog_file4,
698
- L: 255,
714
+ L: 266,
699
715
  S: this,
700
716
  C: (f, a) => f(...a)
701
717
  });
@@ -704,7 +720,7 @@ var Muxer = class {
704
720
  if (this._closing) {
705
721
  log4("already closing, ignoring graceful close request", void 0, {
706
722
  F: __dxlog_file4,
707
- L: 259,
723
+ L: 270,
708
724
  S: this,
709
725
  C: (f, a) => f(...a)
710
726
  });
@@ -720,29 +736,20 @@ var Muxer = class {
720
736
  err: err2
721
737
  }, {
722
738
  F: __dxlog_file4,
723
- L: 274,
739
+ L: 285,
724
740
  S: this,
725
741
  C: (f, a) => f(...a)
726
742
  });
727
743
  await this._dispose(err2);
728
744
  });
729
- await Promise.race([
730
- new Promise((_resolve, reject) => {
731
- setTimeout(() => {
732
- reject(new TimeoutError("gracefully closing muxer"));
733
- }, GRACEFUL_CLOSE_TIMEOUT);
734
- }),
735
- (async () => {
736
- await this._dispose(err);
737
- })()
738
- ]);
745
+ await asyncTimeout2(this._dispose(err), GRACEFUL_CLOSE_TIMEOUT, new TimeoutError("gracefully closing muxer"));
739
746
  }
740
747
  // force close without confirmation
741
748
  async destroy(err) {
742
749
  if (this._destroying) {
743
750
  log4("already destroying, ignoring destroy request", void 0, {
744
751
  F: __dxlog_file4,
745
- L: 296,
752
+ L: 298,
746
753
  S: this,
747
754
  C: (f, a) => f(...a)
748
755
  });
@@ -753,7 +760,7 @@ var Muxer = class {
753
760
  if (this._closing) {
754
761
  log4("destroy cancelling graceful close", void 0, {
755
762
  F: __dxlog_file4,
756
- L: 302,
763
+ L: 304,
757
764
  S: this,
758
765
  C: (f, a) => f(...a)
759
766
  });
@@ -768,7 +775,7 @@ var Muxer = class {
768
775
  err: err2
769
776
  }, {
770
777
  F: __dxlog_file4,
771
- L: 315,
778
+ L: 317,
772
779
  S: this,
773
780
  C: (f, a) => f(...a)
774
781
  });
@@ -779,7 +786,7 @@ var Muxer = class {
779
786
  err: err2
780
787
  }, {
781
788
  F: __dxlog_file4,
782
- L: 320,
789
+ L: 322,
783
790
  S: this,
784
791
  C: (f, a) => f(...a)
785
792
  });
@@ -790,7 +797,7 @@ var Muxer = class {
790
797
  if (this._disposed) {
791
798
  log4("already destroyed, ignoring dispose request", void 0, {
792
799
  F: __dxlog_file4,
793
- L: 328,
800
+ L: 330,
794
801
  S: this,
795
802
  C: (f, a) => f(...a)
796
803
  });
@@ -813,7 +820,7 @@ var Muxer = class {
813
820
  cmd
814
821
  }, {
815
822
  F: __dxlog_file4,
816
- L: 351,
823
+ L: 353,
817
824
  S: this,
818
825
  C: (f, a) => f(...a)
819
826
  });
@@ -823,7 +830,7 @@ var Muxer = class {
823
830
  if (!this._closing) {
824
831
  log4("received peer close, initiating my own graceful close", void 0, {
825
832
  F: __dxlog_file4,
826
- L: 357,
833
+ L: 359,
827
834
  S: this,
828
835
  C: (f, a) => f(...a)
829
836
  });
@@ -831,7 +838,7 @@ var Muxer = class {
831
838
  } else {
832
839
  log4("received close from peer, already closing", void 0, {
833
840
  F: __dxlog_file4,
834
- L: 360,
841
+ L: 362,
835
842
  S: this,
836
843
  C: (f, a) => f(...a)
837
844
  });
@@ -860,7 +867,7 @@ var Muxer = class {
860
867
  tag: stream.tag
861
868
  }, {
862
869
  F: __dxlog_file4,
863
- L: 389,
870
+ L: 391,
864
871
  S: this,
865
872
  C: (f, a) => f(...a)
866
873
  });
@@ -875,7 +882,7 @@ var Muxer = class {
875
882
  cmd
876
883
  }, {
877
884
  F: __dxlog_file4,
878
- L: 398,
885
+ L: 400,
879
886
  S: this,
880
887
  C: (f, a) => f(...a)
881
888
  });
@@ -923,7 +930,7 @@ var Muxer = class {
923
930
  threshold: MAX_SAFE_FRAME_SIZE
924
931
  }, {
925
932
  F: __dxlog_file4,
926
- L: 439,
933
+ L: 441,
927
934
  S: this,
928
935
  C: (f, a) => f(...a)
929
936
  });
@@ -998,9 +1005,12 @@ var Muxer = class {
998
1005
  this.statsUpdated.emit(this._lastStats);
999
1006
  }
1000
1007
  };
1008
+ _ts_decorate([
1009
+ logInfo
1010
+ ], Muxer.prototype, "sessionIdString", null);
1001
1011
 
1002
1012
  // packages/core/mesh/teleport/src/teleport.ts
1003
- function _ts_decorate(decorators, target, key, desc) {
1013
+ function _ts_decorate2(decorators, target, key, desc) {
1004
1014
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1005
1015
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
1006
1016
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1020,7 +1030,7 @@ var Teleport = class {
1020
1030
  void this.destroy(err).catch(() => {
1021
1031
  log5.error("Error during destroy", err, {
1022
1032
  F: __dxlog_file5,
1023
- L: 38,
1033
+ L: 39,
1024
1034
  S: this,
1025
1035
  C: (f, a) => f(...a)
1026
1036
  });
@@ -1035,7 +1045,7 @@ var Teleport = class {
1035
1045
  this._aborting = false;
1036
1046
  invariant4(typeof initiator === "boolean", void 0, {
1037
1047
  F: __dxlog_file5,
1038
- L: 55,
1048
+ L: 56,
1039
1049
  S: this,
1040
1050
  A: [
1041
1051
  "typeof initiator === 'boolean'",
@@ -1044,7 +1054,7 @@ var Teleport = class {
1044
1054
  });
1045
1055
  invariant4(PublicKey.isPublicKey(localPeerId), void 0, {
1046
1056
  F: __dxlog_file5,
1047
- L: 56,
1057
+ L: 57,
1048
1058
  S: this,
1049
1059
  A: [
1050
1060
  "PublicKey.isPublicKey(localPeerId)",
@@ -1053,7 +1063,7 @@ var Teleport = class {
1053
1063
  });
1054
1064
  invariant4(PublicKey.isPublicKey(remotePeerId), void 0, {
1055
1065
  F: __dxlog_file5,
1056
- L: 57,
1066
+ L: 58,
1057
1067
  S: this,
1058
1068
  A: [
1059
1069
  "PublicKey.isPublicKey(remotePeerId)",
@@ -1072,13 +1082,13 @@ var Teleport = class {
1072
1082
  }
1073
1083
  log5.info("abort teleport due to onTimeout in ControlExtension", void 0, {
1074
1084
  F: __dxlog_file5,
1075
- L: 70,
1085
+ L: 71,
1076
1086
  S: this,
1077
1087
  C: (f, a) => f(...a)
1078
1088
  });
1079
1089
  this.abort(new TimeoutError2("control extension")).catch((err) => log5.catch(err, void 0, {
1080
1090
  F: __dxlog_file5,
1081
- L: 71,
1091
+ L: 72,
1082
1092
  S: this,
1083
1093
  C: (f, a) => f(...a)
1084
1094
  }));
@@ -1089,13 +1099,13 @@ var Teleport = class {
1089
1099
  name
1090
1100
  }, {
1091
1101
  F: __dxlog_file5,
1092
- L: 79,
1102
+ L: 80,
1093
1103
  S: this,
1094
1104
  C: (f, a) => f(...a)
1095
1105
  });
1096
1106
  invariant4(!this._remoteExtensions.has(name), "Remote extension already exists", {
1097
1107
  F: __dxlog_file5,
1098
- L: 80,
1108
+ L: 81,
1099
1109
  S: this,
1100
1110
  A: [
1101
1111
  "!this._remoteExtensions.has(name)",
@@ -1116,7 +1126,7 @@ var Teleport = class {
1116
1126
  if (this._destroying || this._aborting) {
1117
1127
  log5("destroy teleport due to muxer stream close, skipping due to already destroying/aborting", void 0, {
1118
1128
  F: __dxlog_file5,
1119
- L: 96,
1129
+ L: 97,
1120
1130
  S: this,
1121
1131
  C: (f, a) => f(...a)
1122
1132
  });
@@ -1139,12 +1149,15 @@ var Teleport = class {
1139
1149
  channels: stats.channels
1140
1150
  }, {
1141
1151
  F: __dxlog_file5,
1142
- L: 109,
1152
+ L: 110,
1143
1153
  S: this,
1144
1154
  C: (f, a) => f(...a)
1145
1155
  });
1146
1156
  });
1147
1157
  }
1158
+ get sessionIdString() {
1159
+ return this._sessionId ? this._sessionId.truncate() : "none";
1160
+ }
1148
1161
  get stream() {
1149
1162
  return this._muxer.stream;
1150
1163
  }
@@ -1154,10 +1167,18 @@ var Teleport = class {
1154
1167
  /**
1155
1168
  * Blocks until the handshake is complete.
1156
1169
  */
1157
- async open() {
1170
+ async open(sessionId = PublicKey.random()) {
1171
+ this._sessionId = sessionId;
1172
+ log5("open", void 0, {
1173
+ F: __dxlog_file5,
1174
+ L: 144,
1175
+ S: this,
1176
+ C: (f, a) => f(...a)
1177
+ });
1158
1178
  this._setExtension("dxos.mesh.teleport.control", this._control);
1159
1179
  await this._openExtension("dxos.mesh.teleport.control");
1160
1180
  this._open = true;
1181
+ this._muxer.setSessionId(sessionId);
1161
1182
  }
1162
1183
  async close(err) {
1163
1184
  await this.destroy(err);
@@ -1177,7 +1198,7 @@ var Teleport = class {
1177
1198
  } catch (err2) {
1178
1199
  log5.catch(err2, void 0, {
1179
1200
  F: __dxlog_file5,
1180
- L: 162,
1201
+ L: 173,
1181
1202
  S: this,
1182
1203
  C: (f, a) => f(...a)
1183
1204
  });
@@ -1200,7 +1221,7 @@ var Teleport = class {
1200
1221
  } catch (err2) {
1201
1222
  log5.catch(err2, void 0, {
1202
1223
  F: __dxlog_file5,
1203
- L: 186,
1224
+ L: 197,
1204
1225
  S: this,
1205
1226
  C: (f, a) => f(...a)
1206
1227
  });
@@ -1216,7 +1237,7 @@ var Teleport = class {
1216
1237
  name
1217
1238
  }, {
1218
1239
  F: __dxlog_file5,
1219
- L: 198,
1240
+ L: 209,
1220
1241
  S: this,
1221
1242
  C: (f, a) => f(...a)
1222
1243
  });
@@ -1240,7 +1261,7 @@ var Teleport = class {
1240
1261
  _setExtension(extensionName, extension) {
1241
1262
  invariant4(!extensionName.includes("/"), "Invalid extension name", {
1242
1263
  F: __dxlog_file5,
1243
- L: 222,
1264
+ L: 233,
1244
1265
  S: this,
1245
1266
  A: [
1246
1267
  "!extensionName.includes('/')",
@@ -1249,7 +1270,7 @@ var Teleport = class {
1249
1270
  });
1250
1271
  invariant4(!this._extensions.has(extensionName), "Extension already exists", {
1251
1272
  F: __dxlog_file5,
1252
- L: 223,
1273
+ L: 234,
1253
1274
  S: this,
1254
1275
  A: [
1255
1276
  "!this._extensions.has(extensionName)",
@@ -1263,7 +1284,7 @@ var Teleport = class {
1263
1284
  extensionName
1264
1285
  }, {
1265
1286
  F: __dxlog_file5,
1266
- L: 228,
1287
+ L: 239,
1267
1288
  S: this,
1268
1289
  C: (f, a) => f(...a)
1269
1290
  });
@@ -1275,7 +1296,7 @@ var Teleport = class {
1275
1296
  createPort: async (channelName, opts) => {
1276
1297
  invariant4(!channelName.includes("/"), "Invalid channel name", {
1277
1298
  F: __dxlog_file5,
1278
- L: 236,
1299
+ L: 247,
1279
1300
  S: this,
1280
1301
  A: [
1281
1302
  "!channelName.includes('/')",
@@ -1287,7 +1308,7 @@ var Teleport = class {
1287
1308
  createStream: async (channelName, opts) => {
1288
1309
  invariant4(!channelName.includes("/"), "Invalid channel name", {
1289
1310
  F: __dxlog_file5,
1290
- L: 240,
1311
+ L: 251,
1291
1312
  S: this,
1292
1313
  A: [
1293
1314
  "!channelName.includes('/')",
@@ -1307,16 +1328,19 @@ var Teleport = class {
1307
1328
  extensionName
1308
1329
  }, {
1309
1330
  F: __dxlog_file5,
1310
- L: 251,
1331
+ L: 262,
1311
1332
  S: this,
1312
1333
  C: (f, a) => f(...a)
1313
1334
  });
1314
1335
  }
1315
1336
  };
1316
- _ts_decorate([
1337
+ _ts_decorate2([
1338
+ logInfo2
1339
+ ], Teleport.prototype, "sessionIdString", null);
1340
+ _ts_decorate2([
1317
1341
  synchronized
1318
1342
  ], Teleport.prototype, "abort", null);
1319
- _ts_decorate([
1343
+ _ts_decorate2([
1320
1344
  synchronized
1321
1345
  ], Teleport.prototype, "destroy", null);
1322
1346
 
@@ -1463,7 +1487,7 @@ var TestPeer = class {
1463
1487
  ""
1464
1488
  ]
1465
1489
  });
1466
- await connection.teleport.open();
1490
+ await connection.teleport.open(PublicKey2.random());
1467
1491
  await this.onOpen(connection);
1468
1492
  }
1469
1493
  async closeConnection(connection) {
@@ -1522,7 +1546,7 @@ var TestConnection = class {
1522
1546
  };
1523
1547
 
1524
1548
  // packages/core/mesh/teleport/src/testing/test-extension.ts
1525
- import { asyncTimeout as asyncTimeout2, Trigger as Trigger2 } from "@dxos/async";
1549
+ import { asyncTimeout as asyncTimeout3, Trigger as Trigger2 } from "@dxos/async";
1526
1550
  import { invariant as invariant6 } from "@dxos/invariant";
1527
1551
  import { log as log7 } from "@dxos/log";
1528
1552
  import { schema as schema3 } from "@dxos/protocols";
@@ -1606,7 +1630,7 @@ var TestExtension = class {
1606
1630
  await this.open.wait({
1607
1631
  timeout: 1500
1608
1632
  });
1609
- const res = await asyncTimeout2(this._rpc.rpc.TestService.testCall({
1633
+ const res = await asyncTimeout3(this._rpc.rpc.TestService.testCall({
1610
1634
  data: message
1611
1635
  }), 1500);
1612
1636
  invariant6(res.data === message, void 0, {
@@ -1899,4 +1923,4 @@ export {
1899
1923
  TestExtension,
1900
1924
  TestExtensionWithStreams
1901
1925
  };
1902
- //# sourceMappingURL=chunk-HMQK4NR4.mjs.map
1926
+ //# sourceMappingURL=chunk-CZZOJEEL.mjs.map