@dxos/teleport 0.6.12-main.c4a728f → 0.6.12-main.ed7cda7

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,13 +1,136 @@
1
1
  import "@dxos/node-std/globals";
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 __esm = (fn, res) => function __init() {
9
+ return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
10
+ };
11
+ var __commonJS = (cb, mod) => function __require() {
12
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
13
+ };
14
+ var __copyProps = (to, from, except, desc) => {
15
+ if (from && typeof from === "object" || typeof from === "function") {
16
+ for (let key of __getOwnPropNames(from))
17
+ if (!__hasOwnProp.call(to, key) && key !== except)
18
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
23
+ // If the importer is in node compatibility mode or this is not an ESM
24
+ // file that has been converted to a CommonJS file using a Babel-
25
+ // compatible transform (i.e. "__esModule" has not been set), then set
26
+ // "default" to the CommonJS "module.exports" for node compatibility.
27
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
28
+ mod
29
+ ));
2
30
 
3
31
  // inject-globals:@inject-globals
4
32
  import {
5
33
  global,
6
- Buffer,
34
+ Buffer as Buffer2,
7
35
  process
8
36
  } from "@dxos/node-std/inject-globals";
37
+ var init_inject_globals = __esm({
38
+ "inject-globals:@inject-globals"() {
39
+ }
40
+ });
41
+
42
+ // node_modules/.pnpm/varint@6.0.0/node_modules/varint/encode.js
43
+ var require_encode = __commonJS({
44
+ "node_modules/.pnpm/varint@6.0.0/node_modules/varint/encode.js"(exports, module) {
45
+ init_inject_globals();
46
+ module.exports = encode;
47
+ var MSB = 128;
48
+ var REST = 127;
49
+ var MSBALL = ~REST;
50
+ var INT = Math.pow(2, 31);
51
+ function encode(num, out, offset) {
52
+ if (Number.MAX_SAFE_INTEGER && num > Number.MAX_SAFE_INTEGER) {
53
+ encode.bytes = 0;
54
+ throw new RangeError("Could not encode varint");
55
+ }
56
+ out = out || [];
57
+ offset = offset || 0;
58
+ var oldOffset = offset;
59
+ while (num >= INT) {
60
+ out[offset++] = num & 255 | MSB;
61
+ num /= 128;
62
+ }
63
+ while (num & MSBALL) {
64
+ out[offset++] = num & 255 | MSB;
65
+ num >>>= 7;
66
+ }
67
+ out[offset] = num | 0;
68
+ encode.bytes = offset - oldOffset + 1;
69
+ return out;
70
+ }
71
+ }
72
+ });
73
+
74
+ // node_modules/.pnpm/varint@6.0.0/node_modules/varint/decode.js
75
+ var require_decode = __commonJS({
76
+ "node_modules/.pnpm/varint@6.0.0/node_modules/varint/decode.js"(exports, module) {
77
+ init_inject_globals();
78
+ module.exports = read;
79
+ var MSB = 128;
80
+ var REST = 127;
81
+ function read(buf, offset) {
82
+ var res = 0, offset = offset || 0, shift = 0, counter = offset, b, l = buf.length;
83
+ do {
84
+ if (counter >= l || shift > 49) {
85
+ read.bytes = 0;
86
+ throw new RangeError("Could not decode varint");
87
+ }
88
+ b = buf[counter++];
89
+ res += shift < 28 ? (b & REST) << shift : (b & REST) * Math.pow(2, shift);
90
+ shift += 7;
91
+ } while (b >= MSB);
92
+ read.bytes = counter - offset;
93
+ return res;
94
+ }
95
+ }
96
+ });
97
+
98
+ // node_modules/.pnpm/varint@6.0.0/node_modules/varint/length.js
99
+ var require_length = __commonJS({
100
+ "node_modules/.pnpm/varint@6.0.0/node_modules/varint/length.js"(exports, module) {
101
+ init_inject_globals();
102
+ var N1 = Math.pow(2, 7);
103
+ var N2 = Math.pow(2, 14);
104
+ var N3 = Math.pow(2, 21);
105
+ var N4 = Math.pow(2, 28);
106
+ var N5 = Math.pow(2, 35);
107
+ var N6 = Math.pow(2, 42);
108
+ var N7 = Math.pow(2, 49);
109
+ var N8 = Math.pow(2, 56);
110
+ var N9 = Math.pow(2, 63);
111
+ module.exports = function(value) {
112
+ 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;
113
+ };
114
+ }
115
+ });
116
+
117
+ // node_modules/.pnpm/varint@6.0.0/node_modules/varint/index.js
118
+ var require_varint = __commonJS({
119
+ "node_modules/.pnpm/varint@6.0.0/node_modules/varint/index.js"(exports, module) {
120
+ init_inject_globals();
121
+ module.exports = {
122
+ encode: require_encode(),
123
+ decode: require_decode(),
124
+ encodingLength: require_length()
125
+ };
126
+ }
127
+ });
128
+
129
+ // packages/core/mesh/teleport/src/testing/index.ts
130
+ init_inject_globals();
9
131
 
10
132
  // packages/core/mesh/teleport/src/testing/test-builder.ts
133
+ init_inject_globals();
11
134
  import { pipeline } from "@dxos/node-std/stream";
12
135
  import { waitForCondition } from "@dxos/async";
13
136
  import { invariant as invariant5 } from "@dxos/invariant";
@@ -15,6 +138,7 @@ import { PublicKey as PublicKey2 } from "@dxos/keys";
15
138
  import { log as log6 } from "@dxos/log";
16
139
 
17
140
  // packages/core/mesh/teleport/src/teleport.ts
141
+ init_inject_globals();
18
142
  import { runInContextAsync, synchronized, scheduleTask } from "@dxos/async";
19
143
  import { Context as Context3 } from "@dxos/context";
20
144
  import { failUndefined as failUndefined2 } from "@dxos/debug";
@@ -24,6 +148,7 @@ import { log as log5, logInfo as logInfo2 } from "@dxos/log";
24
148
  import { RpcClosedError as RpcClosedError2, TimeoutError as TimeoutError2 } from "@dxos/protocols";
25
149
 
26
150
  // packages/core/mesh/teleport/src/control-extension.ts
151
+ init_inject_globals();
27
152
  import { asyncTimeout, scheduleTaskInterval, TimeoutError as AsyncTimeoutError } from "@dxos/async";
28
153
  import { Context } from "@dxos/context";
29
154
  import { log } from "@dxos/log";
@@ -175,7 +300,11 @@ var ControlExtension = class {
175
300
  }
176
301
  };
177
302
 
303
+ // packages/core/mesh/teleport/src/muxing/index.ts
304
+ init_inject_globals();
305
+
178
306
  // packages/core/mesh/teleport/src/muxing/framer.ts
307
+ init_inject_globals();
179
308
  import { Duplex } from "@dxos/node-std/stream";
180
309
  import { Event } from "@dxos/async";
181
310
  import { invariant } from "@dxos/invariant";
@@ -211,7 +340,7 @@ var Framer = class {
211
340
  });
212
341
  this._bytesReceived += chunk.length;
213
342
  if (this._buffer && this._buffer.length > 0) {
214
- this._buffer = Buffer.concat([
343
+ this._buffer = Buffer2.concat([
215
344
  this._buffer,
216
345
  chunk
217
346
  ]);
@@ -335,13 +464,14 @@ var decodeFrame = (buffer, offset) => {
335
464
  };
336
465
  };
337
466
  var encodeFrame = (payload) => {
338
- const frame = Buffer.allocUnsafe(FRAME_LENGTH_SIZE + payload.length);
467
+ const frame = Buffer2.allocUnsafe(FRAME_LENGTH_SIZE + payload.length);
339
468
  frame.writeUInt16BE(payload.length, 0);
340
469
  frame.set(payload, FRAME_LENGTH_SIZE);
341
470
  return frame;
342
471
  };
343
472
 
344
473
  // packages/core/mesh/teleport/src/muxing/muxer.ts
474
+ init_inject_globals();
345
475
  import { Duplex as Duplex2 } from "@dxos/node-std/stream";
346
476
  import { scheduleTaskInterval as scheduleTaskInterval2, Event as Event3, Trigger, asyncTimeout as asyncTimeout2 } from "@dxos/async";
347
477
  import { Context as Context2 } from "@dxos/context";
@@ -352,7 +482,8 @@ import { TimeoutError } from "@dxos/protocols";
352
482
  import { schema as schema2 } from "@dxos/protocols/proto";
353
483
 
354
484
  // packages/core/mesh/teleport/src/muxing/balancer.ts
355
- import * as varint from "varint";
485
+ init_inject_globals();
486
+ var import_varint = __toESM(require_varint());
356
487
  import { Event as Event2 } from "@dxos/async";
357
488
  import { invariant as invariant2 } from "@dxos/invariant";
358
489
  import { log as log3 } from "@dxos/log";
@@ -410,7 +541,7 @@ var Balancer = class {
410
541
  if (!this._receiveBuffers.has(channelId)) {
411
542
  if (chunk.length < dataLength) {
412
543
  this._receiveBuffers.set(channelId, {
413
- buffer: Buffer.from(chunk),
544
+ buffer: Buffer2.from(chunk),
414
545
  msgLength: dataLength
415
546
  });
416
547
  } else {
@@ -418,7 +549,7 @@ var Balancer = class {
418
549
  }
419
550
  } else {
420
551
  const channelBuffer = this._receiveBuffers.get(channelId);
421
- channelBuffer.buffer = Buffer.concat([
552
+ channelBuffer.buffer = Buffer2.concat([
422
553
  channelBuffer.buffer,
423
554
  chunk
424
555
  ]);
@@ -534,23 +665,23 @@ var Balancer = class {
534
665
  }
535
666
  };
536
667
  var encodeChunk = ({ channelId, dataLength, chunk }) => {
537
- const channelTagLength = varint.encodingLength(channelId);
538
- const dataLengthLength = dataLength ? varint.encodingLength(dataLength) : 0;
539
- const message = Buffer.allocUnsafe(channelTagLength + dataLengthLength + chunk.length);
540
- varint.encode(channelId, message);
668
+ const channelTagLength = import_varint.default.encodingLength(channelId);
669
+ const dataLengthLength = dataLength ? import_varint.default.encodingLength(dataLength) : 0;
670
+ const message = Buffer2.allocUnsafe(channelTagLength + dataLengthLength + chunk.length);
671
+ import_varint.default.encode(channelId, message);
541
672
  if (dataLength) {
542
- varint.encode(dataLength, message, channelTagLength);
673
+ import_varint.default.encode(dataLength, message, channelTagLength);
543
674
  }
544
675
  message.set(chunk, channelTagLength + dataLengthLength);
545
676
  return message;
546
677
  };
547
678
  var decodeChunk = (data, withLength) => {
548
- const channelId = varint.decode(data);
679
+ const channelId = import_varint.default.decode(data);
549
680
  let dataLength;
550
- let offset = varint.decode.bytes;
681
+ let offset = import_varint.default.decode.bytes;
551
682
  if (withLength(channelId)) {
552
- dataLength = varint.decode(data, offset);
553
- offset += varint.decode.bytes;
683
+ dataLength = import_varint.default.decode(data, offset);
684
+ offset += import_varint.default.decode.bytes;
554
685
  }
555
686
  const chunk = data.subarray(offset);
556
687
  return {
@@ -958,6 +1089,16 @@ var Muxer = class {
958
1089
  }, channel.id, timeout);
959
1090
  }
960
1091
  _destroyChannel(channel, err) {
1092
+ if (err) {
1093
+ log4.warn("destroying channel with error", {
1094
+ err
1095
+ }, {
1096
+ F: __dxlog_file4,
1097
+ L: 465,
1098
+ S: this,
1099
+ C: (f, a) => f(...a)
1100
+ });
1101
+ }
961
1102
  if (channel.destroy) {
962
1103
  channel.destroy(err);
963
1104
  }
@@ -1019,6 +1160,9 @@ _ts_decorate([
1019
1160
  logInfo
1020
1161
  ], Muxer.prototype, "sessionIdString", null);
1021
1162
 
1163
+ // packages/core/mesh/teleport/src/muxing/rpc-port.ts
1164
+ init_inject_globals();
1165
+
1022
1166
  // packages/core/mesh/teleport/src/teleport.ts
1023
1167
  function _ts_decorate2(decorators, target, key, desc) {
1024
1168
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
@@ -1033,10 +1177,18 @@ var Teleport = class {
1033
1177
  constructor({ initiator, localPeerId, remotePeerId, ...rest }) {
1034
1178
  this._ctx = new Context3({
1035
1179
  onError: (err) => {
1180
+ log5.info("error in teleport context", {
1181
+ err
1182
+ }, {
1183
+ F: __dxlog_file5,
1184
+ L: 40,
1185
+ S: this,
1186
+ C: (f, a) => f(...a)
1187
+ });
1036
1188
  void this.destroy(err).catch(() => {
1037
1189
  log5.error("Error during destroy", err, {
1038
1190
  F: __dxlog_file5,
1039
- L: 41,
1191
+ L: 42,
1040
1192
  S: this,
1041
1193
  C: (f, a) => f(...a)
1042
1194
  });
@@ -1054,7 +1206,7 @@ var Teleport = class {
1054
1206
  this._aborting = false;
1055
1207
  invariant4(typeof initiator === "boolean", void 0, {
1056
1208
  F: __dxlog_file5,
1057
- L: 62,
1209
+ L: 63,
1058
1210
  S: this,
1059
1211
  A: [
1060
1212
  "typeof initiator === 'boolean'",
@@ -1063,7 +1215,7 @@ var Teleport = class {
1063
1215
  });
1064
1216
  invariant4(PublicKey.isPublicKey(localPeerId), void 0, {
1065
1217
  F: __dxlog_file5,
1066
- L: 63,
1218
+ L: 64,
1067
1219
  S: this,
1068
1220
  A: [
1069
1221
  "PublicKey.isPublicKey(localPeerId)",
@@ -1072,7 +1224,7 @@ var Teleport = class {
1072
1224
  });
1073
1225
  invariant4(PublicKey.isPublicKey(remotePeerId), void 0, {
1074
1226
  F: __dxlog_file5,
1075
- L: 64,
1227
+ L: 65,
1076
1228
  S: this,
1077
1229
  A: [
1078
1230
  "PublicKey.isPublicKey(remotePeerId)",
@@ -1091,13 +1243,13 @@ var Teleport = class {
1091
1243
  }
1092
1244
  log5.info("abort teleport due to onTimeout in ControlExtension", void 0, {
1093
1245
  F: __dxlog_file5,
1094
- L: 77,
1246
+ L: 78,
1095
1247
  S: this,
1096
1248
  C: (f, a) => f(...a)
1097
1249
  });
1098
1250
  this.abort(new TimeoutError2("control extension")).catch((err) => log5.catch(err, void 0, {
1099
1251
  F: __dxlog_file5,
1100
- L: 78,
1252
+ L: 79,
1101
1253
  S: this,
1102
1254
  C: (f, a) => f(...a)
1103
1255
  }));
@@ -1108,13 +1260,13 @@ var Teleport = class {
1108
1260
  name
1109
1261
  }, {
1110
1262
  F: __dxlog_file5,
1111
- L: 86,
1263
+ L: 87,
1112
1264
  S: this,
1113
1265
  C: (f, a) => f(...a)
1114
1266
  });
1115
1267
  invariant4(!this._remoteExtensions.has(name), "Remote extension already exists", {
1116
1268
  F: __dxlog_file5,
1117
- L: 87,
1269
+ L: 88,
1118
1270
  S: this,
1119
1271
  A: [
1120
1272
  "!this._remoteExtensions.has(name)",
@@ -1135,7 +1287,7 @@ var Teleport = class {
1135
1287
  if (this._destroying || this._aborting) {
1136
1288
  log5("destroy teleport due to muxer stream close, skipping due to already destroying/aborting", void 0, {
1137
1289
  F: __dxlog_file5,
1138
- L: 103,
1290
+ L: 104,
1139
1291
  S: this,
1140
1292
  C: (f, a) => f(...a)
1141
1293
  });
@@ -1158,7 +1310,7 @@ var Teleport = class {
1158
1310
  channels: stats.channels
1159
1311
  }, {
1160
1312
  F: __dxlog_file5,
1161
- L: 116,
1313
+ L: 117,
1162
1314
  S: this,
1163
1315
  C: (f, a) => f(...a)
1164
1316
  });
@@ -1183,7 +1335,7 @@ var Teleport = class {
1183
1335
  this._sessionId = sessionId;
1184
1336
  log5("open", void 0, {
1185
1337
  F: __dxlog_file5,
1186
- L: 150,
1338
+ L: 151,
1187
1339
  S: this,
1188
1340
  C: (f, a) => f(...a)
1189
1341
  });
@@ -1211,7 +1363,7 @@ var Teleport = class {
1211
1363
  } catch (err2) {
1212
1364
  log5.catch(err2, void 0, {
1213
1365
  F: __dxlog_file5,
1214
- L: 180,
1366
+ L: 181,
1215
1367
  S: this,
1216
1368
  C: (f, a) => f(...a)
1217
1369
  });
@@ -1227,7 +1379,7 @@ var Teleport = class {
1227
1379
  extensionsCount: this._extensions.size
1228
1380
  }, {
1229
1381
  F: __dxlog_file5,
1230
- L: 193,
1382
+ L: 194,
1231
1383
  S: this,
1232
1384
  C: (f, a) => f(...a)
1233
1385
  });
@@ -1243,7 +1395,7 @@ var Teleport = class {
1243
1395
  name: extension.constructor.name
1244
1396
  }, {
1245
1397
  F: __dxlog_file5,
1246
- L: 205,
1398
+ L: 206,
1247
1399
  S: this,
1248
1400
  C: (f, a) => f(...a)
1249
1401
  });
@@ -1252,14 +1404,14 @@ var Teleport = class {
1252
1404
  name: extension.constructor.name
1253
1405
  }, {
1254
1406
  F: __dxlog_file5,
1255
- L: 207,
1407
+ L: 208,
1256
1408
  S: this,
1257
1409
  C: (f, a) => f(...a)
1258
1410
  });
1259
1411
  } catch (err2) {
1260
1412
  log5.catch(err2, void 0, {
1261
1413
  F: __dxlog_file5,
1262
- L: 209,
1414
+ L: 210,
1263
1415
  S: this,
1264
1416
  C: (f, a) => f(...a)
1265
1417
  });
@@ -1268,7 +1420,7 @@ var Teleport = class {
1268
1420
  await this._muxer.close();
1269
1421
  log5("teleport destroyed", void 0, {
1270
1422
  F: __dxlog_file5,
1271
- L: 214,
1423
+ L: 215,
1272
1424
  S: this,
1273
1425
  C: (f, a) => f(...a)
1274
1426
  });
@@ -1281,7 +1433,7 @@ var Teleport = class {
1281
1433
  name
1282
1434
  }, {
1283
1435
  F: __dxlog_file5,
1284
- L: 222,
1436
+ L: 223,
1285
1437
  S: this,
1286
1438
  C: (f, a) => f(...a)
1287
1439
  });
@@ -1305,7 +1457,7 @@ var Teleport = class {
1305
1457
  _setExtension(extensionName, extension) {
1306
1458
  invariant4(!extensionName.includes("/"), "Invalid extension name", {
1307
1459
  F: __dxlog_file5,
1308
- L: 246,
1460
+ L: 247,
1309
1461
  S: this,
1310
1462
  A: [
1311
1463
  "!extensionName.includes('/')",
@@ -1314,7 +1466,7 @@ var Teleport = class {
1314
1466
  });
1315
1467
  invariant4(!this._extensions.has(extensionName), "Extension already exists", {
1316
1468
  F: __dxlog_file5,
1317
- L: 247,
1469
+ L: 248,
1318
1470
  S: this,
1319
1471
  A: [
1320
1472
  "!this._extensions.has(extensionName)",
@@ -1328,7 +1480,7 @@ var Teleport = class {
1328
1480
  extensionName
1329
1481
  }, {
1330
1482
  F: __dxlog_file5,
1331
- L: 252,
1483
+ L: 253,
1332
1484
  S: this,
1333
1485
  C: (f, a) => f(...a)
1334
1486
  });
@@ -1340,7 +1492,7 @@ var Teleport = class {
1340
1492
  createPort: async (channelName, opts) => {
1341
1493
  invariant4(!channelName.includes("/"), "Invalid channel name", {
1342
1494
  F: __dxlog_file5,
1343
- L: 260,
1495
+ L: 261,
1344
1496
  S: this,
1345
1497
  A: [
1346
1498
  "!channelName.includes('/')",
@@ -1352,7 +1504,7 @@ var Teleport = class {
1352
1504
  createStream: async (channelName, opts) => {
1353
1505
  invariant4(!channelName.includes("/"), "Invalid channel name", {
1354
1506
  F: __dxlog_file5,
1355
- L: 264,
1507
+ L: 265,
1356
1508
  S: this,
1357
1509
  A: [
1358
1510
  "!channelName.includes('/')",
@@ -1372,7 +1524,7 @@ var Teleport = class {
1372
1524
  extensionName
1373
1525
  }, {
1374
1526
  F: __dxlog_file5,
1375
- L: 275,
1527
+ L: 276,
1376
1528
  S: this,
1377
1529
  C: (f, a) => f(...a)
1378
1530
  });
@@ -1595,6 +1747,7 @@ var TestConnection = class {
1595
1747
  };
1596
1748
 
1597
1749
  // packages/core/mesh/teleport/src/testing/test-extension.ts
1750
+ init_inject_globals();
1598
1751
  import { asyncTimeout as asyncTimeout3, Trigger as Trigger2 } from "@dxos/async";
1599
1752
  import { invariant as invariant6 } from "@dxos/invariant";
1600
1753
  import { log as log7 } from "@dxos/log";
@@ -1701,6 +1854,7 @@ var TestExtension = class {
1701
1854
  };
1702
1855
 
1703
1856
  // packages/core/mesh/teleport/src/testing/test-extension-with-streams.ts
1857
+ init_inject_globals();
1704
1858
  import { randomBytes } from "@dxos/node-std/crypto";
1705
1859
  import { Trigger as Trigger3 } from "@dxos/async";
1706
1860
  import { invariant as invariant7 } from "@dxos/invariant";
@@ -1961,6 +2115,7 @@ var TestExtensionWithStreams = class {
1961
2115
  };
1962
2116
 
1963
2117
  export {
2118
+ init_inject_globals,
1964
2119
  Framer,
1965
2120
  decodeFrame,
1966
2121
  encodeFrame,
@@ -1972,4 +2127,4 @@ export {
1972
2127
  TestExtension,
1973
2128
  TestExtensionWithStreams
1974
2129
  };
1975
- //# sourceMappingURL=chunk-K7XTPLL4.mjs.map
2130
+ //# sourceMappingURL=chunk-NLPOT6AJ.mjs.map