@dxos/teleport 0.6.12 → 0.6.13-main.041e8aa

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.
Files changed (35) hide show
  1. package/dist/lib/browser/chunk-NLPOT6AJ.mjs +2130 -0
  2. package/dist/lib/browser/chunk-NLPOT6AJ.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +7 -2
  4. package/dist/lib/browser/index.mjs.map +3 -3
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/testing/index.mjs +1 -1
  7. package/dist/lib/node/{chunk-TC7PLXKV.cjs → chunk-F45T5HZ2.cjs} +155 -47
  8. package/dist/lib/node/chunk-F45T5HZ2.cjs.map +7 -0
  9. package/dist/lib/node/index.cjs +11 -11
  10. package/dist/lib/node/meta.json +1 -1
  11. package/dist/lib/node/testing/index.cjs +6 -6
  12. package/dist/lib/node/testing/index.cjs.map +1 -1
  13. package/dist/lib/{browser/chunk-ISJQDU2V.mjs → node-esm/chunk-K64VAYIG.mjs} +164 -45
  14. package/dist/lib/node-esm/chunk-K64VAYIG.mjs.map +7 -0
  15. package/dist/lib/node-esm/index.mjs +86 -0
  16. package/dist/lib/node-esm/index.mjs.map +7 -0
  17. package/dist/lib/node-esm/meta.json +1 -0
  18. package/dist/lib/node-esm/testing/index.mjs +16 -0
  19. package/dist/lib/node-esm/testing/index.mjs.map +7 -0
  20. package/dist/types/src/muxing/muxer.d.ts.map +1 -1
  21. package/dist/types/src/teleport.d.ts.map +1 -1
  22. package/package.json +17 -17
  23. package/src/muxing/balancer.test.ts +5 -9
  24. package/src/muxing/balancer.ts +1 -1
  25. package/src/muxing/framer.test.ts +6 -10
  26. package/src/muxing/muxer.test.ts +3 -7
  27. package/src/muxing/muxer.ts +3 -0
  28. package/src/muxing/rpc-port.test.ts +2 -1
  29. package/src/teleport.test.ts +4 -5
  30. package/src/teleport.ts +1 -0
  31. package/src/testing/test-extension-with-streams.ts +2 -2
  32. package/dist/lib/browser/chunk-ISJQDU2V.mjs.map +0 -7
  33. package/dist/lib/node/chunk-TC7PLXKV.cjs.map +0 -7
  34. package/testing.d.ts +0 -11
  35. package/testing.js +0 -5
@@ -1,14 +1,115 @@
1
- import "@dxos/node-std/globals";
1
+ import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __commonJS = (cb, mod) => function __require() {
9
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+
28
+ // node_modules/.pnpm/varint@6.0.0/node_modules/varint/encode.js
29
+ var require_encode = __commonJS({
30
+ "node_modules/.pnpm/varint@6.0.0/node_modules/varint/encode.js"(exports, module) {
31
+ module.exports = encode;
32
+ var MSB = 128;
33
+ var REST = 127;
34
+ var MSBALL = ~REST;
35
+ var INT = Math.pow(2, 31);
36
+ function encode(num, out, offset) {
37
+ if (Number.MAX_SAFE_INTEGER && num > Number.MAX_SAFE_INTEGER) {
38
+ encode.bytes = 0;
39
+ throw new RangeError("Could not encode varint");
40
+ }
41
+ out = out || [];
42
+ offset = offset || 0;
43
+ var oldOffset = offset;
44
+ while (num >= INT) {
45
+ out[offset++] = num & 255 | MSB;
46
+ num /= 128;
47
+ }
48
+ while (num & MSBALL) {
49
+ out[offset++] = num & 255 | MSB;
50
+ num >>>= 7;
51
+ }
52
+ out[offset] = num | 0;
53
+ encode.bytes = offset - oldOffset + 1;
54
+ return out;
55
+ }
56
+ }
57
+ });
58
+
59
+ // node_modules/.pnpm/varint@6.0.0/node_modules/varint/decode.js
60
+ var require_decode = __commonJS({
61
+ "node_modules/.pnpm/varint@6.0.0/node_modules/varint/decode.js"(exports, module) {
62
+ module.exports = read;
63
+ var MSB = 128;
64
+ var REST = 127;
65
+ function read(buf, offset) {
66
+ var res = 0, offset = offset || 0, shift = 0, counter = offset, b, l = buf.length;
67
+ do {
68
+ if (counter >= l || shift > 49) {
69
+ read.bytes = 0;
70
+ throw new RangeError("Could not decode varint");
71
+ }
72
+ b = buf[counter++];
73
+ res += shift < 28 ? (b & REST) << shift : (b & REST) * Math.pow(2, shift);
74
+ shift += 7;
75
+ } while (b >= MSB);
76
+ read.bytes = counter - offset;
77
+ return res;
78
+ }
79
+ }
80
+ });
2
81
 
3
- // inject-globals:@inject-globals
4
- import {
5
- global,
6
- Buffer,
7
- process
8
- } from "@dxos/node-std/inject-globals";
82
+ // node_modules/.pnpm/varint@6.0.0/node_modules/varint/length.js
83
+ var require_length = __commonJS({
84
+ "node_modules/.pnpm/varint@6.0.0/node_modules/varint/length.js"(exports, module) {
85
+ var N1 = Math.pow(2, 7);
86
+ var N2 = Math.pow(2, 14);
87
+ var N3 = Math.pow(2, 21);
88
+ var N4 = Math.pow(2, 28);
89
+ var N5 = Math.pow(2, 35);
90
+ var N6 = Math.pow(2, 42);
91
+ var N7 = Math.pow(2, 49);
92
+ var N8 = Math.pow(2, 56);
93
+ var N9 = Math.pow(2, 63);
94
+ module.exports = function(value) {
95
+ return value < N1 ? 1 : value < N2 ? 2 : value < N3 ? 3 : value < N4 ? 4 : value < N5 ? 5 : value < N6 ? 6 : value < N7 ? 7 : value < N8 ? 8 : value < N9 ? 9 : 10;
96
+ };
97
+ }
98
+ });
99
+
100
+ // node_modules/.pnpm/varint@6.0.0/node_modules/varint/index.js
101
+ var require_varint = __commonJS({
102
+ "node_modules/.pnpm/varint@6.0.0/node_modules/varint/index.js"(exports, module) {
103
+ module.exports = {
104
+ encode: require_encode(),
105
+ decode: require_decode(),
106
+ encodingLength: require_length()
107
+ };
108
+ }
109
+ });
9
110
 
10
111
  // packages/core/mesh/teleport/src/testing/test-builder.ts
11
- import { pipeline } from "@dxos/node-std/stream";
112
+ import { pipeline } from "node:stream";
12
113
  import { waitForCondition } from "@dxos/async";
13
114
  import { invariant as invariant5 } from "@dxos/invariant";
14
115
  import { PublicKey as PublicKey2 } from "@dxos/keys";
@@ -176,7 +277,7 @@ var ControlExtension = class {
176
277
  };
177
278
 
178
279
  // packages/core/mesh/teleport/src/muxing/framer.ts
179
- import { Duplex } from "@dxos/node-std/stream";
280
+ import { Duplex } from "node:stream";
180
281
  import { Event } from "@dxos/async";
181
282
  import { invariant } from "@dxos/invariant";
182
283
  import { log as log2 } from "@dxos/log";
@@ -342,7 +443,7 @@ var encodeFrame = (payload) => {
342
443
  };
343
444
 
344
445
  // packages/core/mesh/teleport/src/muxing/muxer.ts
345
- import { Duplex as Duplex2 } from "@dxos/node-std/stream";
446
+ import { Duplex as Duplex2 } from "node:stream";
346
447
  import { scheduleTaskInterval as scheduleTaskInterval2, Event as Event3, Trigger, asyncTimeout as asyncTimeout2 } from "@dxos/async";
347
448
  import { Context as Context2 } from "@dxos/context";
348
449
  import { failUndefined } from "@dxos/debug";
@@ -352,7 +453,7 @@ import { TimeoutError } from "@dxos/protocols";
352
453
  import { schema as schema2 } from "@dxos/protocols/proto";
353
454
 
354
455
  // packages/core/mesh/teleport/src/muxing/balancer.ts
355
- import * as varint from "varint";
456
+ var import_varint = __toESM(require_varint());
356
457
  import { Event as Event2 } from "@dxos/async";
357
458
  import { invariant as invariant2 } from "@dxos/invariant";
358
459
  import { log as log3 } from "@dxos/log";
@@ -534,23 +635,23 @@ var Balancer = class {
534
635
  }
535
636
  };
536
637
  var encodeChunk = ({ channelId, dataLength, chunk }) => {
537
- const channelTagLength = varint.encodingLength(channelId);
538
- const dataLengthLength = dataLength ? varint.encodingLength(dataLength) : 0;
638
+ const channelTagLength = import_varint.default.encodingLength(channelId);
639
+ const dataLengthLength = dataLength ? import_varint.default.encodingLength(dataLength) : 0;
539
640
  const message = Buffer.allocUnsafe(channelTagLength + dataLengthLength + chunk.length);
540
- varint.encode(channelId, message);
641
+ import_varint.default.encode(channelId, message);
541
642
  if (dataLength) {
542
- varint.encode(dataLength, message, channelTagLength);
643
+ import_varint.default.encode(dataLength, message, channelTagLength);
543
644
  }
544
645
  message.set(chunk, channelTagLength + dataLengthLength);
545
646
  return message;
546
647
  };
547
648
  var decodeChunk = (data, withLength) => {
548
- const channelId = varint.decode(data);
649
+ const channelId = import_varint.default.decode(data);
549
650
  let dataLength;
550
- let offset = varint.decode.bytes;
651
+ let offset = import_varint.default.decode.bytes;
551
652
  if (withLength(channelId)) {
552
- dataLength = varint.decode(data, offset);
553
- offset += varint.decode.bytes;
653
+ dataLength = import_varint.default.decode(data, offset);
654
+ offset += import_varint.default.decode.bytes;
554
655
  }
555
656
  const chunk = data.subarray(offset);
556
657
  return {
@@ -958,6 +1059,16 @@ var Muxer = class {
958
1059
  }, channel.id, timeout);
959
1060
  }
960
1061
  _destroyChannel(channel, err) {
1062
+ if (err) {
1063
+ log4.warn("destroying channel with error", {
1064
+ err
1065
+ }, {
1066
+ F: __dxlog_file4,
1067
+ L: 465,
1068
+ S: this,
1069
+ C: (f, a) => f(...a)
1070
+ });
1071
+ }
961
1072
  if (channel.destroy) {
962
1073
  channel.destroy(err);
963
1074
  }
@@ -1033,10 +1144,18 @@ var Teleport = class {
1033
1144
  constructor({ initiator, localPeerId, remotePeerId, ...rest }) {
1034
1145
  this._ctx = new Context3({
1035
1146
  onError: (err) => {
1147
+ log5.info("error in teleport context", {
1148
+ err
1149
+ }, {
1150
+ F: __dxlog_file5,
1151
+ L: 40,
1152
+ S: this,
1153
+ C: (f, a) => f(...a)
1154
+ });
1036
1155
  void this.destroy(err).catch(() => {
1037
1156
  log5.error("Error during destroy", err, {
1038
1157
  F: __dxlog_file5,
1039
- L: 41,
1158
+ L: 42,
1040
1159
  S: this,
1041
1160
  C: (f, a) => f(...a)
1042
1161
  });
@@ -1054,7 +1173,7 @@ var Teleport = class {
1054
1173
  this._aborting = false;
1055
1174
  invariant4(typeof initiator === "boolean", void 0, {
1056
1175
  F: __dxlog_file5,
1057
- L: 62,
1176
+ L: 63,
1058
1177
  S: this,
1059
1178
  A: [
1060
1179
  "typeof initiator === 'boolean'",
@@ -1063,7 +1182,7 @@ var Teleport = class {
1063
1182
  });
1064
1183
  invariant4(PublicKey.isPublicKey(localPeerId), void 0, {
1065
1184
  F: __dxlog_file5,
1066
- L: 63,
1185
+ L: 64,
1067
1186
  S: this,
1068
1187
  A: [
1069
1188
  "PublicKey.isPublicKey(localPeerId)",
@@ -1072,7 +1191,7 @@ var Teleport = class {
1072
1191
  });
1073
1192
  invariant4(PublicKey.isPublicKey(remotePeerId), void 0, {
1074
1193
  F: __dxlog_file5,
1075
- L: 64,
1194
+ L: 65,
1076
1195
  S: this,
1077
1196
  A: [
1078
1197
  "PublicKey.isPublicKey(remotePeerId)",
@@ -1091,13 +1210,13 @@ var Teleport = class {
1091
1210
  }
1092
1211
  log5.info("abort teleport due to onTimeout in ControlExtension", void 0, {
1093
1212
  F: __dxlog_file5,
1094
- L: 77,
1213
+ L: 78,
1095
1214
  S: this,
1096
1215
  C: (f, a) => f(...a)
1097
1216
  });
1098
1217
  this.abort(new TimeoutError2("control extension")).catch((err) => log5.catch(err, void 0, {
1099
1218
  F: __dxlog_file5,
1100
- L: 78,
1219
+ L: 79,
1101
1220
  S: this,
1102
1221
  C: (f, a) => f(...a)
1103
1222
  }));
@@ -1108,13 +1227,13 @@ var Teleport = class {
1108
1227
  name
1109
1228
  }, {
1110
1229
  F: __dxlog_file5,
1111
- L: 86,
1230
+ L: 87,
1112
1231
  S: this,
1113
1232
  C: (f, a) => f(...a)
1114
1233
  });
1115
1234
  invariant4(!this._remoteExtensions.has(name), "Remote extension already exists", {
1116
1235
  F: __dxlog_file5,
1117
- L: 87,
1236
+ L: 88,
1118
1237
  S: this,
1119
1238
  A: [
1120
1239
  "!this._remoteExtensions.has(name)",
@@ -1135,7 +1254,7 @@ var Teleport = class {
1135
1254
  if (this._destroying || this._aborting) {
1136
1255
  log5("destroy teleport due to muxer stream close, skipping due to already destroying/aborting", void 0, {
1137
1256
  F: __dxlog_file5,
1138
- L: 103,
1257
+ L: 104,
1139
1258
  S: this,
1140
1259
  C: (f, a) => f(...a)
1141
1260
  });
@@ -1158,7 +1277,7 @@ var Teleport = class {
1158
1277
  channels: stats.channels
1159
1278
  }, {
1160
1279
  F: __dxlog_file5,
1161
- L: 116,
1280
+ L: 117,
1162
1281
  S: this,
1163
1282
  C: (f, a) => f(...a)
1164
1283
  });
@@ -1183,7 +1302,7 @@ var Teleport = class {
1183
1302
  this._sessionId = sessionId;
1184
1303
  log5("open", void 0, {
1185
1304
  F: __dxlog_file5,
1186
- L: 150,
1305
+ L: 151,
1187
1306
  S: this,
1188
1307
  C: (f, a) => f(...a)
1189
1308
  });
@@ -1211,7 +1330,7 @@ var Teleport = class {
1211
1330
  } catch (err2) {
1212
1331
  log5.catch(err2, void 0, {
1213
1332
  F: __dxlog_file5,
1214
- L: 180,
1333
+ L: 181,
1215
1334
  S: this,
1216
1335
  C: (f, a) => f(...a)
1217
1336
  });
@@ -1227,7 +1346,7 @@ var Teleport = class {
1227
1346
  extensionsCount: this._extensions.size
1228
1347
  }, {
1229
1348
  F: __dxlog_file5,
1230
- L: 193,
1349
+ L: 194,
1231
1350
  S: this,
1232
1351
  C: (f, a) => f(...a)
1233
1352
  });
@@ -1243,7 +1362,7 @@ var Teleport = class {
1243
1362
  name: extension.constructor.name
1244
1363
  }, {
1245
1364
  F: __dxlog_file5,
1246
- L: 205,
1365
+ L: 206,
1247
1366
  S: this,
1248
1367
  C: (f, a) => f(...a)
1249
1368
  });
@@ -1252,14 +1371,14 @@ var Teleport = class {
1252
1371
  name: extension.constructor.name
1253
1372
  }, {
1254
1373
  F: __dxlog_file5,
1255
- L: 207,
1374
+ L: 208,
1256
1375
  S: this,
1257
1376
  C: (f, a) => f(...a)
1258
1377
  });
1259
1378
  } catch (err2) {
1260
1379
  log5.catch(err2, void 0, {
1261
1380
  F: __dxlog_file5,
1262
- L: 209,
1381
+ L: 210,
1263
1382
  S: this,
1264
1383
  C: (f, a) => f(...a)
1265
1384
  });
@@ -1268,7 +1387,7 @@ var Teleport = class {
1268
1387
  await this._muxer.close();
1269
1388
  log5("teleport destroyed", void 0, {
1270
1389
  F: __dxlog_file5,
1271
- L: 214,
1390
+ L: 215,
1272
1391
  S: this,
1273
1392
  C: (f, a) => f(...a)
1274
1393
  });
@@ -1281,7 +1400,7 @@ var Teleport = class {
1281
1400
  name
1282
1401
  }, {
1283
1402
  F: __dxlog_file5,
1284
- L: 222,
1403
+ L: 223,
1285
1404
  S: this,
1286
1405
  C: (f, a) => f(...a)
1287
1406
  });
@@ -1305,7 +1424,7 @@ var Teleport = class {
1305
1424
  _setExtension(extensionName, extension) {
1306
1425
  invariant4(!extensionName.includes("/"), "Invalid extension name", {
1307
1426
  F: __dxlog_file5,
1308
- L: 246,
1427
+ L: 247,
1309
1428
  S: this,
1310
1429
  A: [
1311
1430
  "!extensionName.includes('/')",
@@ -1314,7 +1433,7 @@ var Teleport = class {
1314
1433
  });
1315
1434
  invariant4(!this._extensions.has(extensionName), "Extension already exists", {
1316
1435
  F: __dxlog_file5,
1317
- L: 247,
1436
+ L: 248,
1318
1437
  S: this,
1319
1438
  A: [
1320
1439
  "!this._extensions.has(extensionName)",
@@ -1328,7 +1447,7 @@ var Teleport = class {
1328
1447
  extensionName
1329
1448
  }, {
1330
1449
  F: __dxlog_file5,
1331
- L: 252,
1450
+ L: 253,
1332
1451
  S: this,
1333
1452
  C: (f, a) => f(...a)
1334
1453
  });
@@ -1340,7 +1459,7 @@ var Teleport = class {
1340
1459
  createPort: async (channelName, opts) => {
1341
1460
  invariant4(!channelName.includes("/"), "Invalid channel name", {
1342
1461
  F: __dxlog_file5,
1343
- L: 260,
1462
+ L: 261,
1344
1463
  S: this,
1345
1464
  A: [
1346
1465
  "!channelName.includes('/')",
@@ -1352,7 +1471,7 @@ var Teleport = class {
1352
1471
  createStream: async (channelName, opts) => {
1353
1472
  invariant4(!channelName.includes("/"), "Invalid channel name", {
1354
1473
  F: __dxlog_file5,
1355
- L: 264,
1474
+ L: 265,
1356
1475
  S: this,
1357
1476
  A: [
1358
1477
  "!channelName.includes('/')",
@@ -1372,7 +1491,7 @@ var Teleport = class {
1372
1491
  extensionName
1373
1492
  }, {
1374
1493
  F: __dxlog_file5,
1375
- L: 275,
1494
+ L: 276,
1376
1495
  S: this,
1377
1496
  C: (f, a) => f(...a)
1378
1497
  });
@@ -1701,7 +1820,7 @@ var TestExtension = class {
1701
1820
  };
1702
1821
 
1703
1822
  // packages/core/mesh/teleport/src/testing/test-extension-with-streams.ts
1704
- import { randomBytes } from "@dxos/node-std/crypto";
1823
+ import { randomBytes } from "node:crypto";
1705
1824
  import { Trigger as Trigger3 } from "@dxos/async";
1706
1825
  import { invariant as invariant7 } from "@dxos/invariant";
1707
1826
  import { log as log8 } from "@dxos/log";
@@ -1972,4 +2091,4 @@ export {
1972
2091
  TestExtension,
1973
2092
  TestExtensionWithStreams
1974
2093
  };
1975
- //# sourceMappingURL=chunk-ISJQDU2V.mjs.map
2094
+ //# sourceMappingURL=chunk-K64VAYIG.mjs.map