@dxos/client-services 0.6.12-main.15a606f → 0.6.12-main.78ddbdf

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 (28) hide show
  1. package/dist/lib/browser/{chunk-BDGSOBZV.mjs → chunk-XSFLJVDP.mjs} +105 -61
  2. package/dist/lib/browser/chunk-XSFLJVDP.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +1 -1
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/testing/index.mjs +1 -1
  6. package/dist/lib/node/{chunk-EBZ7KFXS.cjs → chunk-F3WGFGEN.cjs} +87 -43
  7. package/dist/lib/node/chunk-F3WGFGEN.cjs.map +7 -0
  8. package/dist/lib/node/index.cjs +45 -45
  9. package/dist/lib/node/meta.json +1 -1
  10. package/dist/lib/node/testing/index.cjs +8 -8
  11. package/dist/lib/node-esm/{chunk-LDBJYNPL.mjs → chunk-3HDLTAT2.mjs} +105 -61
  12. package/dist/lib/node-esm/chunk-3HDLTAT2.mjs.map +7 -0
  13. package/dist/lib/node-esm/index.mjs +1 -1
  14. package/dist/lib/node-esm/meta.json +1 -1
  15. package/dist/lib/node-esm/testing/index.mjs +1 -1
  16. package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts +1 -0
  17. package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts.map +1 -1
  18. package/dist/types/src/packlets/spaces/edge-feed-replicator.test.d.ts +2 -0
  19. package/dist/types/src/packlets/spaces/edge-feed-replicator.test.d.ts.map +1 -0
  20. package/dist/types/src/version.d.ts +1 -1
  21. package/package.json +39 -38
  22. package/src/packlets/identity/identity.test.ts +4 -0
  23. package/src/packlets/spaces/edge-feed-replicator.test.ts +244 -0
  24. package/src/packlets/spaces/edge-feed-replicator.ts +50 -17
  25. package/src/version.ts +1 -1
  26. package/dist/lib/browser/chunk-BDGSOBZV.mjs.map +0 -7
  27. package/dist/lib/node/chunk-EBZ7KFXS.cjs.map +0 -7
  28. package/dist/lib/node-esm/chunk-LDBJYNPL.mjs.map +0 -7
@@ -7,7 +7,7 @@ import {
7
7
  InvitationsManager,
8
8
  ServiceContext,
9
9
  SpaceInvitationProtocol
10
- } from "../chunk-BDGSOBZV.mjs";
10
+ } from "../chunk-XSFLJVDP.mjs";
11
11
 
12
12
  // packages/sdk/client-services/src/packlets/testing/credential-utils.ts
13
13
  import { createCredential } from "@dxos/credentials";
@@ -26,8 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var chunk_EBZ7KFXS_exports = {};
30
- __export(chunk_EBZ7KFXS_exports, {
29
+ var chunk_F3WGFGEN_exports = {};
30
+ __export(chunk_F3WGFGEN_exports, {
31
31
  ClientRpcServer: () => ClientRpcServer,
32
32
  ClientServicesHost: () => ClientServicesHost,
33
33
  DataSpace: () => DataSpace,
@@ -70,7 +70,7 @@ __export(chunk_EBZ7KFXS_exports, {
70
70
  subscribeToSpaces: () => subscribeToSpaces,
71
71
  subscribeToSwarmInfo: () => subscribeToSwarmInfo
72
72
  });
73
- module.exports = __toCommonJS(chunk_EBZ7KFXS_exports);
73
+ module.exports = __toCommonJS(chunk_F3WGFGEN_exports);
74
74
  var import_async = require("@dxos/async");
75
75
  var import_codec_protobuf = require("@dxos/codec-protobuf");
76
76
  var import_feed_store = require("@dxos/feed-store");
@@ -107,6 +107,7 @@ var import_proto = require("@dxos/protocols/proto");
107
107
  var import_cbor_x = require("cbor-x");
108
108
  var import_async6 = require("@dxos/async");
109
109
  var import_context3 = require("@dxos/context");
110
+ var import_edge_client = require("@dxos/edge-client");
110
111
  var import_invariant2 = require("@dxos/invariant");
111
112
  var import_keys3 = require("@dxos/keys");
112
113
  var import_log3 = require("@dxos/log");
@@ -316,7 +317,7 @@ var import_util14 = require("@dxos/util");
316
317
  var import_async20 = require("@dxos/async");
317
318
  var import_client_protocol8 = require("@dxos/client-protocol");
318
319
  var import_context16 = require("@dxos/context");
319
- var import_edge_client = require("@dxos/edge-client");
320
+ var import_edge_client2 = require("@dxos/edge-client");
320
321
  var import_invariant21 = require("@dxos/invariant");
321
322
  var import_keys16 = require("@dxos/keys");
322
323
  var import_log22 = require("@dxos/log");
@@ -702,7 +703,7 @@ var DevtoolsServiceImpl = class {
702
703
  });
703
704
  }
704
705
  };
705
- var DXOS_VERSION = "0.6.12-main.15a606f";
706
+ var DXOS_VERSION = "0.6.12-main.78ddbdf";
706
707
  var getPlatform = () => {
707
708
  if (process.browser) {
708
709
  if (typeof window !== "undefined") {
@@ -1081,7 +1082,7 @@ var EdgeFeedReplicator = class extends import_context3.Resource {
1081
1082
  this._spaceId = spaceId;
1082
1083
  }
1083
1084
  async _open() {
1084
- this._ctx.onDispose(this._messenger.addListener(async (message) => {
1085
+ this._ctx.onDispose(this._messenger.addListener((message) => {
1085
1086
  if (!message.serviceId) {
1086
1087
  return;
1087
1088
  }
@@ -1096,7 +1097,7 @@ var EdgeFeedReplicator = class extends import_context3.Resource {
1096
1097
  _spaceId: this._spaceId
1097
1098
  }, {
1098
1099
  F: __dxlog_file5,
1099
- L: 62,
1100
+ L: 66,
1100
1101
  S: this,
1101
1102
  C: (f, a) => f(...a)
1102
1103
  });
@@ -1109,20 +1110,54 @@ var EdgeFeedReplicator = class extends import_context3.Resource {
1109
1110
  type: payload.type
1110
1111
  }, {
1111
1112
  F: __dxlog_file5,
1112
- L: 67,
1113
+ L: 71,
1113
1114
  S: this,
1114
1115
  C: (f, a) => f(...a)
1115
1116
  });
1116
1117
  this._onMessage(payload);
1117
1118
  }));
1118
- this._connected = true;
1119
- this._connectionCtx = this._ctx.derive();
1120
- for (const feed of this._feeds.values()) {
1121
- await this._replicateFeed(feed);
1122
- }
1119
+ this._messenger.connected.on(this._ctx, async () => {
1120
+ await this._resetConnection();
1121
+ this._connected = true;
1122
+ const connectionCtx = new import_context3.Context({
1123
+ onError: async (err) => {
1124
+ if (connectionCtx !== this._connectionCtx) {
1125
+ return;
1126
+ }
1127
+ if (err instanceof import_edge_client.EdgeIdentityChangedError || err instanceof import_edge_client.EdgeConnectionClosedError) {
1128
+ (0, import_log3.log)("resetting on reconnect", void 0, {
1129
+ F: __dxlog_file5,
1130
+ L: 86,
1131
+ S: this,
1132
+ C: (f, a) => f(...a)
1133
+ });
1134
+ await this._resetConnection();
1135
+ } else {
1136
+ this._ctx.raise(err);
1137
+ }
1138
+ }
1139
+ }, {
1140
+ F: __dxlog_file5,
1141
+ L: 80
1142
+ });
1143
+ this._connectionCtx = connectionCtx;
1144
+ (0, import_log3.log)("connection context created", void 0, {
1145
+ F: __dxlog_file5,
1146
+ L: 94,
1147
+ S: this,
1148
+ C: (f, a) => f(...a)
1149
+ });
1150
+ (0, import_async6.scheduleMicroTask)(connectionCtx, async () => {
1151
+ for (const feed of this._feeds.values()) {
1152
+ await this._replicateFeed(connectionCtx, feed);
1153
+ }
1154
+ });
1155
+ });
1123
1156
  }
1124
1157
  async _close() {
1125
- this._connected = false;
1158
+ await this._resetConnection();
1159
+ }
1160
+ async _resetConnection() {
1126
1161
  this._connected = false;
1127
1162
  await this._connectionCtx?.dispose();
1128
1163
  this._connectionCtx = void 0;
@@ -1133,37 +1168,37 @@ var EdgeFeedReplicator = class extends import_context3.Resource {
1133
1168
  key: feed.key
1134
1169
  }, {
1135
1170
  F: __dxlog_file5,
1136
- L: 89,
1171
+ L: 115,
1137
1172
  S: this,
1138
1173
  C: (f, a) => f(...a)
1139
1174
  });
1140
1175
  this._feeds.set(feed.key, feed);
1141
- if (this._connected) {
1142
- await this._replicateFeed(feed);
1176
+ if (this._connected && this._connectionCtx) {
1177
+ await this._replicateFeed(this._connectionCtx, feed);
1143
1178
  }
1144
1179
  }
1145
1180
  _getPushMutex(key) {
1146
1181
  return (0, import_util3.defaultMap)(this._pushMutex, key, () => new import_async6.Mutex());
1147
1182
  }
1148
- async _replicateFeed(feed) {
1149
- (0, import_invariant2.invariant)(this._connectionCtx, void 0, {
1150
- F: __dxlog_file5,
1151
- L: 102,
1152
- S: this,
1153
- A: [
1154
- "this._connectionCtx",
1155
- ""
1156
- ]
1157
- });
1183
+ async _replicateFeed(ctx, feed) {
1158
1184
  await this._sendMessage({
1159
1185
  type: "get-metadata",
1160
1186
  feedKey: feed.key.toHex()
1161
1187
  });
1162
- import_async6.Event.wrap(feed.core, "append").on(this._connectionCtx, async () => {
1188
+ import_async6.Event.wrap(feed.core, "append").on(ctx, async () => {
1163
1189
  await this._pushBlocksIfNeeded(feed);
1164
1190
  });
1165
1191
  }
1166
1192
  async _sendMessage(message) {
1193
+ if (!this._connectionCtx) {
1194
+ import_log3.log.info("message dropped because connection was disposed", void 0, {
1195
+ F: __dxlog_file5,
1196
+ L: 140,
1197
+ S: this,
1198
+ C: (f, a) => f(...a)
1199
+ });
1200
+ return;
1201
+ }
1167
1202
  const logPayload = message.type === "data" ? {
1168
1203
  feedKey: message.feedKey,
1169
1204
  blocks: message.blocks.map((b) => b.index)
@@ -1172,13 +1207,13 @@ var EdgeFeedReplicator = class extends import_context3.Resource {
1172
1207
  };
1173
1208
  import_log3.log.info("sending message", logPayload, {
1174
1209
  F: __dxlog_file5,
1175
- L: 117,
1210
+ L: 146,
1176
1211
  S: this,
1177
1212
  C: (f, a) => f(...a)
1178
1213
  });
1179
1214
  (0, import_invariant2.invariant)(message.feedKey, void 0, {
1180
1215
  F: __dxlog_file5,
1181
- L: 119,
1216
+ L: 148,
1182
1217
  S: this,
1183
1218
  A: [
1184
1219
  "message.feedKey",
@@ -1198,7 +1233,16 @@ var EdgeFeedReplicator = class extends import_context3.Resource {
1198
1233
  }));
1199
1234
  }
1200
1235
  _onMessage(message) {
1201
- (0, import_async6.scheduleMicroTask)(this._ctx, async () => {
1236
+ if (!this._connectionCtx) {
1237
+ import_log3.log.warn("received message after connection context was disposed", void 0, {
1238
+ F: __dxlog_file5,
1239
+ L: 165,
1240
+ S: this,
1241
+ C: (f, a) => f(...a)
1242
+ });
1243
+ return;
1244
+ }
1245
+ (0, import_async6.scheduleMicroTask)(this._connectionCtx, async () => {
1202
1246
  switch (message.type) {
1203
1247
  case "metadata": {
1204
1248
  try {
@@ -1207,7 +1251,7 @@ var EdgeFeedReplicator = class extends import_context3.Resource {
1207
1251
  message
1208
1252
  }, {
1209
1253
  F: __dxlog_file5,
1210
- L: 138,
1254
+ L: 171,
1211
1255
  S: this,
1212
1256
  C: (f, a) => f(...a)
1213
1257
  });
@@ -1218,7 +1262,7 @@ var EdgeFeedReplicator = class extends import_context3.Resource {
1218
1262
  feedKey
1219
1263
  }, {
1220
1264
  F: __dxlog_file5,
1221
- L: 143,
1265
+ L: 176,
1222
1266
  S: this,
1223
1267
  C: (f, a) => f(...a)
1224
1268
  });
@@ -1251,7 +1295,7 @@ var EdgeFeedReplicator = class extends import_context3.Resource {
1251
1295
  blocks: message.blocks.map((b) => b.index)
1252
1296
  }, {
1253
1297
  F: __dxlog_file5,
1254
- L: 165,
1298
+ L: 198,
1255
1299
  S: this,
1256
1300
  C: (f, a) => f(...a)
1257
1301
  });
@@ -1262,7 +1306,7 @@ var EdgeFeedReplicator = class extends import_context3.Resource {
1262
1306
  feedKey
1263
1307
  }, {
1264
1308
  F: __dxlog_file5,
1265
- L: 170,
1309
+ L: 203,
1266
1310
  S: this,
1267
1311
  C: (f, a) => f(...a)
1268
1312
  });
@@ -1276,7 +1320,7 @@ var EdgeFeedReplicator = class extends import_context3.Resource {
1276
1320
  ...message
1277
1321
  }, {
1278
1322
  F: __dxlog_file5,
1279
- L: 179,
1323
+ L: 212,
1280
1324
  S: this,
1281
1325
  C: (f, a) => f(...a)
1282
1326
  });
@@ -1291,7 +1335,7 @@ var EdgeFeedReplicator = class extends import_context3.Resource {
1291
1335
  to
1292
1336
  }, {
1293
1337
  F: __dxlog_file5,
1294
- L: 186,
1338
+ L: 219,
1295
1339
  S: this,
1296
1340
  C: (f, a) => f(...a)
1297
1341
  });
@@ -1301,7 +1345,7 @@ var EdgeFeedReplicator = class extends import_context3.Resource {
1301
1345
  });
1302
1346
  (0, import_invariant2.invariant)(data instanceof Uint8Array, void 0, {
1303
1347
  F: __dxlog_file5,
1304
- L: 191,
1348
+ L: 224,
1305
1349
  S: this,
1306
1350
  A: [
1307
1351
  "data instanceof Uint8Array",
@@ -1329,7 +1373,7 @@ var EdgeFeedReplicator = class extends import_context3.Resource {
1329
1373
  blocks: blocks.length
1330
1374
  }, {
1331
1375
  F: __dxlog_file5,
1332
- L: 212,
1376
+ L: 245,
1333
1377
  S: this,
1334
1378
  C: (f, a) => f(...a)
1335
1379
  });
@@ -1347,11 +1391,11 @@ var EdgeFeedReplicator = class extends import_context3.Resource {
1347
1391
  async _pushBlocksIfNeeded(feed) {
1348
1392
  try {
1349
1393
  var _usingCtx = _using_ctx();
1350
- const _guard = _usingCtx.u(await this._getPushMutex(feed.key).acquire());
1394
+ const _ = _usingCtx.u(await this._getPushMutex(feed.key).acquire());
1351
1395
  if (!this._remoteLength.has(feed.key)) {
1352
1396
  (0, import_log3.log)("blocks not pushed because remote length is unknown", void 0, {
1353
1397
  F: __dxlog_file5,
1354
- L: 233,
1398
+ L: 266,
1355
1399
  S: this,
1356
1400
  C: (f, a) => f(...a)
1357
1401
  });
@@ -7421,7 +7465,7 @@ var ClientServicesHost = class {
7421
7465
  const edgeEndpoint = config?.get("runtime.services.edge.url");
7422
7466
  if (edgeEndpoint) {
7423
7467
  const randomKey = import_keys16.PublicKey.random().toHex();
7424
- this._edgeConnection = new import_edge_client.EdgeClient(randomKey, randomKey, {
7468
+ this._edgeConnection = new import_edge_client2.EdgeClient(randomKey, randomKey, {
7425
7469
  socketEndpoint: edgeEndpoint
7426
7470
  });
7427
7471
  }
@@ -7712,4 +7756,4 @@ ClientServicesHost = _ts_decorate8([
7712
7756
  subscribeToSpaces,
7713
7757
  subscribeToSwarmInfo
7714
7758
  });
7715
- //# sourceMappingURL=chunk-EBZ7KFXS.cjs.map
7759
+ //# sourceMappingURL=chunk-F3WGFGEN.cjs.map