@dxos/teleport 0.3.9-main.6370198 → 0.3.9-main.71124bf

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",
@@ -638,7 +661,7 @@ var Muxer = class {
638
661
  });
639
662
  invariant3(!channel.push, `Channel already open: ${tag}`, {
640
663
  F: __dxlog_file4,
641
- L: 200,
664
+ L: 211,
642
665
  S: this,
643
666
  A: [
644
667
  "!channel.push",
@@ -662,7 +685,7 @@ var Muxer = class {
662
685
  subscribe: (cb) => {
663
686
  invariant3(!callback, "Only one subscriber is allowed", {
664
687
  F: __dxlog_file4,
665
- L: 222,
688
+ L: 233,
666
689
  S: this,
667
690
  A: [
668
691
  "!callback",
@@ -695,7 +718,7 @@ var Muxer = class {
695
718
  if (this._destroying) {
696
719
  log4("already destroying, ignoring graceful close request", void 0, {
697
720
  F: __dxlog_file4,
698
- L: 255,
721
+ L: 266,
699
722
  S: this,
700
723
  C: (f, a) => f(...a)
701
724
  });
@@ -704,7 +727,7 @@ var Muxer = class {
704
727
  if (this._closing) {
705
728
  log4("already closing, ignoring graceful close request", void 0, {
706
729
  F: __dxlog_file4,
707
- L: 259,
730
+ L: 270,
708
731
  S: this,
709
732
  C: (f, a) => f(...a)
710
733
  });
@@ -720,29 +743,20 @@ var Muxer = class {
720
743
  err: err2
721
744
  }, {
722
745
  F: __dxlog_file4,
723
- L: 274,
746
+ L: 285,
724
747
  S: this,
725
748
  C: (f, a) => f(...a)
726
749
  });
727
750
  await this._dispose(err2);
728
751
  });
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
- ]);
752
+ await asyncTimeout2(this._dispose(err), GRACEFUL_CLOSE_TIMEOUT, new TimeoutError("gracefully closing muxer"));
739
753
  }
740
754
  // force close without confirmation
741
755
  async destroy(err) {
742
756
  if (this._destroying) {
743
757
  log4("already destroying, ignoring destroy request", void 0, {
744
758
  F: __dxlog_file4,
745
- L: 296,
759
+ L: 298,
746
760
  S: this,
747
761
  C: (f, a) => f(...a)
748
762
  });
@@ -753,7 +767,7 @@ var Muxer = class {
753
767
  if (this._closing) {
754
768
  log4("destroy cancelling graceful close", void 0, {
755
769
  F: __dxlog_file4,
756
- L: 302,
770
+ L: 304,
757
771
  S: this,
758
772
  C: (f, a) => f(...a)
759
773
  });
@@ -768,7 +782,7 @@ var Muxer = class {
768
782
  err: err2
769
783
  }, {
770
784
  F: __dxlog_file4,
771
- L: 315,
785
+ L: 317,
772
786
  S: this,
773
787
  C: (f, a) => f(...a)
774
788
  });
@@ -779,7 +793,7 @@ var Muxer = class {
779
793
  err: err2
780
794
  }, {
781
795
  F: __dxlog_file4,
782
- L: 320,
796
+ L: 322,
783
797
  S: this,
784
798
  C: (f, a) => f(...a)
785
799
  });
@@ -790,7 +804,7 @@ var Muxer = class {
790
804
  if (this._disposed) {
791
805
  log4("already destroyed, ignoring dispose request", void 0, {
792
806
  F: __dxlog_file4,
793
- L: 328,
807
+ L: 330,
794
808
  S: this,
795
809
  C: (f, a) => f(...a)
796
810
  });
@@ -813,7 +827,7 @@ var Muxer = class {
813
827
  cmd
814
828
  }, {
815
829
  F: __dxlog_file4,
816
- L: 351,
830
+ L: 353,
817
831
  S: this,
818
832
  C: (f, a) => f(...a)
819
833
  });
@@ -823,7 +837,7 @@ var Muxer = class {
823
837
  if (!this._closing) {
824
838
  log4("received peer close, initiating my own graceful close", void 0, {
825
839
  F: __dxlog_file4,
826
- L: 357,
840
+ L: 359,
827
841
  S: this,
828
842
  C: (f, a) => f(...a)
829
843
  });
@@ -831,7 +845,7 @@ var Muxer = class {
831
845
  } else {
832
846
  log4("received close from peer, already closing", void 0, {
833
847
  F: __dxlog_file4,
834
- L: 360,
848
+ L: 362,
835
849
  S: this,
836
850
  C: (f, a) => f(...a)
837
851
  });
@@ -860,7 +874,7 @@ var Muxer = class {
860
874
  tag: stream.tag
861
875
  }, {
862
876
  F: __dxlog_file4,
863
- L: 389,
877
+ L: 391,
864
878
  S: this,
865
879
  C: (f, a) => f(...a)
866
880
  });
@@ -875,7 +889,7 @@ var Muxer = class {
875
889
  cmd
876
890
  }, {
877
891
  F: __dxlog_file4,
878
- L: 398,
892
+ L: 400,
879
893
  S: this,
880
894
  C: (f, a) => f(...a)
881
895
  });
@@ -923,7 +937,7 @@ var Muxer = class {
923
937
  threshold: MAX_SAFE_FRAME_SIZE
924
938
  }, {
925
939
  F: __dxlog_file4,
926
- L: 439,
940
+ L: 441,
927
941
  S: this,
928
942
  C: (f, a) => f(...a)
929
943
  });
@@ -998,9 +1012,12 @@ var Muxer = class {
998
1012
  this.statsUpdated.emit(this._lastStats);
999
1013
  }
1000
1014
  };
1015
+ _ts_decorate([
1016
+ logInfo
1017
+ ], Muxer.prototype, "sessionIdString", null);
1001
1018
 
1002
1019
  // packages/core/mesh/teleport/src/teleport.ts
1003
- function _ts_decorate(decorators, target, key, desc) {
1020
+ function _ts_decorate2(decorators, target, key, desc) {
1004
1021
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
1005
1022
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
1006
1023
  r = Reflect.decorate(decorators, target, key, desc);
@@ -1020,7 +1037,7 @@ var Teleport = class {
1020
1037
  void this.destroy(err).catch(() => {
1021
1038
  log5.error("Error during destroy", err, {
1022
1039
  F: __dxlog_file5,
1023
- L: 38,
1040
+ L: 39,
1024
1041
  S: this,
1025
1042
  C: (f, a) => f(...a)
1026
1043
  });
@@ -1035,7 +1052,7 @@ var Teleport = class {
1035
1052
  this._aborting = false;
1036
1053
  invariant4(typeof initiator === "boolean", void 0, {
1037
1054
  F: __dxlog_file5,
1038
- L: 55,
1055
+ L: 56,
1039
1056
  S: this,
1040
1057
  A: [
1041
1058
  "typeof initiator === 'boolean'",
@@ -1044,7 +1061,7 @@ var Teleport = class {
1044
1061
  });
1045
1062
  invariant4(PublicKey.isPublicKey(localPeerId), void 0, {
1046
1063
  F: __dxlog_file5,
1047
- L: 56,
1064
+ L: 57,
1048
1065
  S: this,
1049
1066
  A: [
1050
1067
  "PublicKey.isPublicKey(localPeerId)",
@@ -1053,7 +1070,7 @@ var Teleport = class {
1053
1070
  });
1054
1071
  invariant4(PublicKey.isPublicKey(remotePeerId), void 0, {
1055
1072
  F: __dxlog_file5,
1056
- L: 57,
1073
+ L: 58,
1057
1074
  S: this,
1058
1075
  A: [
1059
1076
  "PublicKey.isPublicKey(remotePeerId)",
@@ -1072,13 +1089,13 @@ var Teleport = class {
1072
1089
  }
1073
1090
  log5.info("abort teleport due to onTimeout in ControlExtension", void 0, {
1074
1091
  F: __dxlog_file5,
1075
- L: 70,
1092
+ L: 71,
1076
1093
  S: this,
1077
1094
  C: (f, a) => f(...a)
1078
1095
  });
1079
1096
  this.abort(new TimeoutError2("control extension")).catch((err) => log5.catch(err, void 0, {
1080
1097
  F: __dxlog_file5,
1081
- L: 71,
1098
+ L: 72,
1082
1099
  S: this,
1083
1100
  C: (f, a) => f(...a)
1084
1101
  }));
@@ -1089,13 +1106,13 @@ var Teleport = class {
1089
1106
  name
1090
1107
  }, {
1091
1108
  F: __dxlog_file5,
1092
- L: 79,
1109
+ L: 80,
1093
1110
  S: this,
1094
1111
  C: (f, a) => f(...a)
1095
1112
  });
1096
1113
  invariant4(!this._remoteExtensions.has(name), "Remote extension already exists", {
1097
1114
  F: __dxlog_file5,
1098
- L: 80,
1115
+ L: 81,
1099
1116
  S: this,
1100
1117
  A: [
1101
1118
  "!this._remoteExtensions.has(name)",
@@ -1116,7 +1133,7 @@ var Teleport = class {
1116
1133
  if (this._destroying || this._aborting) {
1117
1134
  log5("destroy teleport due to muxer stream close, skipping due to already destroying/aborting", void 0, {
1118
1135
  F: __dxlog_file5,
1119
- L: 96,
1136
+ L: 97,
1120
1137
  S: this,
1121
1138
  C: (f, a) => f(...a)
1122
1139
  });
@@ -1139,12 +1156,15 @@ var Teleport = class {
1139
1156
  channels: stats.channels
1140
1157
  }, {
1141
1158
  F: __dxlog_file5,
1142
- L: 109,
1159
+ L: 110,
1143
1160
  S: this,
1144
1161
  C: (f, a) => f(...a)
1145
1162
  });
1146
1163
  });
1147
1164
  }
1165
+ get sessionIdString() {
1166
+ return this._sessionId ? this._sessionId.truncate() : "none";
1167
+ }
1148
1168
  get stream() {
1149
1169
  return this._muxer.stream;
1150
1170
  }
@@ -1154,10 +1174,18 @@ var Teleport = class {
1154
1174
  /**
1155
1175
  * Blocks until the handshake is complete.
1156
1176
  */
1157
- 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
+ });
1158
1185
  this._setExtension("dxos.mesh.teleport.control", this._control);
1159
1186
  await this._openExtension("dxos.mesh.teleport.control");
1160
1187
  this._open = true;
1188
+ this._muxer.setSessionId(sessionId);
1161
1189
  }
1162
1190
  async close(err) {
1163
1191
  await this.destroy(err);
@@ -1177,7 +1205,7 @@ var Teleport = class {
1177
1205
  } catch (err2) {
1178
1206
  log5.catch(err2, void 0, {
1179
1207
  F: __dxlog_file5,
1180
- L: 162,
1208
+ L: 173,
1181
1209
  S: this,
1182
1210
  C: (f, a) => f(...a)
1183
1211
  });
@@ -1200,7 +1228,7 @@ var Teleport = class {
1200
1228
  } catch (err2) {
1201
1229
  log5.catch(err2, void 0, {
1202
1230
  F: __dxlog_file5,
1203
- L: 186,
1231
+ L: 197,
1204
1232
  S: this,
1205
1233
  C: (f, a) => f(...a)
1206
1234
  });
@@ -1216,7 +1244,7 @@ var Teleport = class {
1216
1244
  name
1217
1245
  }, {
1218
1246
  F: __dxlog_file5,
1219
- L: 198,
1247
+ L: 209,
1220
1248
  S: this,
1221
1249
  C: (f, a) => f(...a)
1222
1250
  });
@@ -1240,7 +1268,7 @@ var Teleport = class {
1240
1268
  _setExtension(extensionName, extension) {
1241
1269
  invariant4(!extensionName.includes("/"), "Invalid extension name", {
1242
1270
  F: __dxlog_file5,
1243
- L: 222,
1271
+ L: 233,
1244
1272
  S: this,
1245
1273
  A: [
1246
1274
  "!extensionName.includes('/')",
@@ -1249,7 +1277,7 @@ var Teleport = class {
1249
1277
  });
1250
1278
  invariant4(!this._extensions.has(extensionName), "Extension already exists", {
1251
1279
  F: __dxlog_file5,
1252
- L: 223,
1280
+ L: 234,
1253
1281
  S: this,
1254
1282
  A: [
1255
1283
  "!this._extensions.has(extensionName)",
@@ -1263,7 +1291,7 @@ var Teleport = class {
1263
1291
  extensionName
1264
1292
  }, {
1265
1293
  F: __dxlog_file5,
1266
- L: 228,
1294
+ L: 239,
1267
1295
  S: this,
1268
1296
  C: (f, a) => f(...a)
1269
1297
  });
@@ -1275,7 +1303,7 @@ var Teleport = class {
1275
1303
  createPort: async (channelName, opts) => {
1276
1304
  invariant4(!channelName.includes("/"), "Invalid channel name", {
1277
1305
  F: __dxlog_file5,
1278
- L: 236,
1306
+ L: 247,
1279
1307
  S: this,
1280
1308
  A: [
1281
1309
  "!channelName.includes('/')",
@@ -1287,7 +1315,7 @@ var Teleport = class {
1287
1315
  createStream: async (channelName, opts) => {
1288
1316
  invariant4(!channelName.includes("/"), "Invalid channel name", {
1289
1317
  F: __dxlog_file5,
1290
- L: 240,
1318
+ L: 251,
1291
1319
  S: this,
1292
1320
  A: [
1293
1321
  "!channelName.includes('/')",
@@ -1307,16 +1335,19 @@ var Teleport = class {
1307
1335
  extensionName
1308
1336
  }, {
1309
1337
  F: __dxlog_file5,
1310
- L: 251,
1338
+ L: 262,
1311
1339
  S: this,
1312
1340
  C: (f, a) => f(...a)
1313
1341
  });
1314
1342
  }
1315
1343
  };
1316
- _ts_decorate([
1344
+ _ts_decorate2([
1345
+ logInfo2
1346
+ ], Teleport.prototype, "sessionIdString", null);
1347
+ _ts_decorate2([
1317
1348
  synchronized
1318
1349
  ], Teleport.prototype, "abort", null);
1319
- _ts_decorate([
1350
+ _ts_decorate2([
1320
1351
  synchronized
1321
1352
  ], Teleport.prototype, "destroy", null);
1322
1353
 
@@ -1463,7 +1494,7 @@ var TestPeer = class {
1463
1494
  ""
1464
1495
  ]
1465
1496
  });
1466
- await connection.teleport.open();
1497
+ await connection.teleport.open(PublicKey2.random());
1467
1498
  await this.onOpen(connection);
1468
1499
  }
1469
1500
  async closeConnection(connection) {
@@ -1522,7 +1553,7 @@ var TestConnection = class {
1522
1553
  };
1523
1554
 
1524
1555
  // packages/core/mesh/teleport/src/testing/test-extension.ts
1525
- import { asyncTimeout as asyncTimeout2, Trigger as Trigger2 } from "@dxos/async";
1556
+ import { asyncTimeout as asyncTimeout3, Trigger as Trigger2 } from "@dxos/async";
1526
1557
  import { invariant as invariant6 } from "@dxos/invariant";
1527
1558
  import { log as log7 } from "@dxos/log";
1528
1559
  import { schema as schema3 } from "@dxos/protocols";
@@ -1606,7 +1637,7 @@ var TestExtension = class {
1606
1637
  await this.open.wait({
1607
1638
  timeout: 1500
1608
1639
  });
1609
- const res = await asyncTimeout2(this._rpc.rpc.TestService.testCall({
1640
+ const res = await asyncTimeout3(this._rpc.rpc.TestService.testCall({
1610
1641
  data: message
1611
1642
  }), 1500);
1612
1643
  invariant6(res.data === message, void 0, {
@@ -1899,4 +1930,4 @@ export {
1899
1930
  TestExtension,
1900
1931
  TestExtensionWithStreams
1901
1932
  };
1902
- //# sourceMappingURL=chunk-HMQK4NR4.mjs.map
1933
+ //# sourceMappingURL=chunk-L2L2STAG.mjs.map