@dxos/client-services 0.4.8-main.ec0899a → 0.4.8-next.fff1521

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.
@@ -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_YFFKH75O_exports = {};
30
- __export(chunk_YFFKH75O_exports, {
29
+ var chunk_K2PCGWBW_exports = {};
30
+ __export(chunk_K2PCGWBW_exports, {
31
31
  ClientRpcServer: () => ClientRpcServer,
32
32
  ClientServicesHost: () => ClientServicesHost,
33
33
  DataSpace: () => DataSpace,
@@ -61,7 +61,7 @@ __export(chunk_YFFKH75O_exports, {
61
61
  subscribeToSpaces: () => subscribeToSpaces,
62
62
  subscribeToSwarmInfo: () => subscribeToSwarmInfo
63
63
  });
64
- module.exports = __toCommonJS(chunk_YFFKH75O_exports);
64
+ module.exports = __toCommonJS(chunk_K2PCGWBW_exports);
65
65
  var import_async = require("@dxos/async");
66
66
  var import_codec_protobuf = require("@dxos/codec-protobuf");
67
67
  var import_feed_store = require("@dxos/feed-store");
@@ -203,7 +203,6 @@ var import_log12 = require("@dxos/log");
203
203
  var import_protocols11 = require("@dxos/protocols");
204
204
  var import_services11 = require("@dxos/protocols/proto/dxos/client/services");
205
205
  var import_async14 = require("@dxos/async");
206
- var import_automerge = require("@dxos/automerge/automerge");
207
206
  var import_context10 = require("@dxos/context");
208
207
  var import_credentials15 = require("@dxos/credentials");
209
208
  var import_debug6 = require("@dxos/debug");
@@ -219,11 +218,14 @@ var import_services12 = require("@dxos/protocols/proto/dxos/client/services");
219
218
  var import_teleport_extension_object_sync = require("@dxos/teleport-extension-object-sync");
220
219
  var import_tracing6 = require("@dxos/tracing");
221
220
  var import_util7 = require("@dxos/util");
221
+ var import_automerge = require("@dxos/automerge/automerge");
222
+ var import_debug7 = require("@dxos/debug");
223
+ var import_protocols13 = require("@dxos/protocols");
222
224
  var import_invariant15 = require("@dxos/invariant");
223
225
  var import_lock_file = require("@dxos/lock-file");
224
226
  var import_log14 = require("@dxos/log");
225
227
  var import_client_protocol4 = require("@dxos/client-protocol");
226
- var import_protocols13 = require("@dxos/protocols");
228
+ var import_protocols14 = require("@dxos/protocols");
227
229
  var import_config = require("@dxos/protocols/proto/dxos/config");
228
230
  var import_random_access_storage = require("@dxos/random-access-storage");
229
231
  var import_util8 = require("@dxos/util");
@@ -240,7 +242,7 @@ var import_log15 = require("@dxos/log");
240
242
  var import_messaging = require("@dxos/messaging");
241
243
  var import_model_factory = require("@dxos/model-factory");
242
244
  var import_network_manager2 = require("@dxos/network-manager");
243
- var import_protocols14 = require("@dxos/protocols");
245
+ var import_protocols15 = require("@dxos/protocols");
244
246
  var import_services13 = require("@dxos/protocols/proto/dxos/client/services");
245
247
  var import_text_model = require("@dxos/text-model");
246
248
  var import_tracing7 = require("@dxos/tracing");
@@ -2888,7 +2890,7 @@ var getPlatform = () => {
2888
2890
  };
2889
2891
  }
2890
2892
  };
2891
- var DXOS_VERSION = "0.4.8-main.ec0899a";
2893
+ var DXOS_VERSION = "0.4.8-next.fff1521";
2892
2894
  var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/diagnostics.ts";
2893
2895
  var DEFAULT_TIMEOUT = 1e3;
2894
2896
  var createDiagnostics = async (clientServices, serviceContext, config) => {
@@ -4429,6 +4431,80 @@ var SpacesServiceImpl = class {
4429
4431
  }
4430
4432
  };
4431
4433
  var getChannelId = (channel) => `user-channel/${channel}`;
4434
+ var createLoadDocuments = (automergeHost) => (
4435
+ /**
4436
+ * Get object data blobs from Automerge Repo by ids.
4437
+ * @param ids
4438
+ */
4439
+ // TODO(mykola): Unload automerge handles after usage.
4440
+ async function* loadDocuments(ids) {
4441
+ for (const id of ids) {
4442
+ const { documentId, objectId } = import_protocols13.idCodec.decode(id);
4443
+ const handle = automergeHost.repo.find(documentId);
4444
+ await (0, import_debug7.warnAfterTimeout)(5e3, "to long to load doc", () => handle.whenReady());
4445
+ const doc = handle.docSync();
4446
+ const heads = (0, import_automerge.getHeads)(doc);
4447
+ yield [
4448
+ {
4449
+ id,
4450
+ object: doc.objects[objectId],
4451
+ currentHash: heads.at(-1)
4452
+ }
4453
+ ];
4454
+ }
4455
+ }
4456
+ );
4457
+ var createGetAllDocuments = (automergeHost) => (
4458
+ /**
4459
+ * Recursively get all object data blobs from Automerge Repo.
4460
+ * @param ids
4461
+ */
4462
+ // TODO(mykola): Unload automerge handles after usage.
4463
+ async function* getAllDocuments() {
4464
+ const visited = /* @__PURE__ */ new Set();
4465
+ async function* getObjectsFromHandle(handle) {
4466
+ if (visited.has(handle.documentId)) {
4467
+ return;
4468
+ }
4469
+ await (0, import_debug7.warnAfterTimeout)(5e3, "to long to load doc", () => handle.whenReady());
4470
+ const doc = handle.docSync();
4471
+ const heads = (0, import_automerge.getHeads)(doc);
4472
+ if (doc.objects) {
4473
+ yield Object.entries(doc.objects).map(([objectId, object]) => {
4474
+ return {
4475
+ id: import_protocols13.idCodec.encode({
4476
+ documentId: handle.documentId,
4477
+ objectId
4478
+ }),
4479
+ object,
4480
+ currentHash: heads.at(-1)
4481
+ };
4482
+ });
4483
+ }
4484
+ if (doc.links) {
4485
+ for (const id of Object.values(doc.links)) {
4486
+ if (visited.has(id)) {
4487
+ continue;
4488
+ }
4489
+ const linkHandle = automergeHost.repo.find(id);
4490
+ for await (const result of getObjectsFromHandle(linkHandle)) {
4491
+ yield result;
4492
+ }
4493
+ }
4494
+ }
4495
+ visited.add(handle.documentId);
4496
+ }
4497
+ for (const handle of Object.values(automergeHost.repo.handles)) {
4498
+ if (visited.has(handle.documentId)) {
4499
+ continue;
4500
+ }
4501
+ for await (const result of getObjectsFromHandle(handle)) {
4502
+ yield result;
4503
+ }
4504
+ visited.add(handle.documentId);
4505
+ }
4506
+ }
4507
+ );
4432
4508
  function _ts_decorate6(decorators, target, key, desc) {
4433
4509
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4434
4510
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -4486,21 +4562,8 @@ var ServiceContext = class {
4486
4562
  directory: storage.createDirectory("index-store")
4487
4563
  }),
4488
4564
  metadataStore: this.indexMetadata,
4489
- loadDocuments: async (ids) => {
4490
- const snapshots = await Promise.all(ids.map(async (id) => {
4491
- const { documentId, objectId } = import_protocols12.idCodec.decode(id);
4492
- const handle = this.automergeHost.repo.find(documentId);
4493
- await (0, import_debug6.warnAfterTimeout)(1e3, "to long to load doc", () => handle.whenReady());
4494
- const doc = handle.docSync();
4495
- const heads = (0, import_automerge.getHeads)(doc);
4496
- return {
4497
- id,
4498
- object: doc.objects[objectId],
4499
- currentHash: heads.at(-1)
4500
- };
4501
- }));
4502
- return snapshots.filter((snapshot) => snapshot.object);
4503
- }
4565
+ loadDocuments: createLoadDocuments(this.automergeHost),
4566
+ getAllDocuments: createGetAllDocuments(this.automergeHost)
4504
4567
  });
4505
4568
  this.invitations = new InvitationsHandler(this.networkManager);
4506
4569
  this._handlerFactories.set(import_services12.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? (0, import_debug6.failUndefined)(), this._acceptIdentity.bind(this)));
@@ -4509,7 +4572,7 @@ var ServiceContext = class {
4509
4572
  await this._checkStorageVersion();
4510
4573
  (0, import_log13.log)("opening...", void 0, {
4511
4574
  F: __dxlog_file15,
4512
- L: 173,
4575
+ L: 162,
4513
4576
  S: this,
4514
4577
  C: (f, a) => f(...a)
4515
4578
  });
@@ -4517,7 +4580,7 @@ var ServiceContext = class {
4517
4580
  id: this._instanceId
4518
4581
  }), {
4519
4582
  F: __dxlog_file15,
4520
- L: 174,
4583
+ L: 163,
4521
4584
  S: this,
4522
4585
  C: (f, a) => f(...a)
4523
4586
  });
@@ -4533,13 +4596,13 @@ var ServiceContext = class {
4533
4596
  id: this._instanceId
4534
4597
  }), {
4535
4598
  F: __dxlog_file15,
4536
- L: 184,
4599
+ L: 173,
4537
4600
  S: this,
4538
4601
  C: (f, a) => f(...a)
4539
4602
  });
4540
4603
  (0, import_log13.log)("opened", void 0, {
4541
4604
  F: __dxlog_file15,
4542
- L: 185,
4605
+ L: 174,
4543
4606
  S: this,
4544
4607
  C: (f, a) => f(...a)
4545
4608
  });
@@ -4547,7 +4610,7 @@ var ServiceContext = class {
4547
4610
  async close() {
4548
4611
  (0, import_log13.log)("closing...", void 0, {
4549
4612
  F: __dxlog_file15,
4550
- L: 189,
4613
+ L: 178,
4551
4614
  S: this,
4552
4615
  C: (f, a) => f(...a)
4553
4616
  });
@@ -4566,7 +4629,7 @@ var ServiceContext = class {
4566
4629
  await this.indexer.destroy();
4567
4630
  (0, import_log13.log)("closed", void 0, {
4568
4631
  F: __dxlog_file15,
4569
- L: 203,
4632
+ L: 192,
4570
4633
  S: this,
4571
4634
  C: (f, a) => f(...a)
4572
4635
  });
@@ -4580,7 +4643,7 @@ var ServiceContext = class {
4580
4643
  const factory = this._handlerFactories.get(invitation.kind);
4581
4644
  (0, import_invariant14.invariant)(factory, `Unknown invitation kind: ${invitation.kind}`, {
4582
4645
  F: __dxlog_file15,
4583
- L: 214,
4646
+ L: 203,
4584
4647
  S: this,
4585
4648
  A: [
4586
4649
  "factory",
@@ -4612,7 +4675,7 @@ var ServiceContext = class {
4612
4675
  async _initialize(ctx) {
4613
4676
  (0, import_log13.log)("initializing spaces...", void 0, {
4614
4677
  F: __dxlog_file15,
4615
- L: 245,
4678
+ L: 234,
4616
4679
  S: this,
4617
4680
  C: (f, a) => f(...a)
4618
4681
  });
@@ -4635,7 +4698,7 @@ var ServiceContext = class {
4635
4698
  this._handlerFactories.set(import_services12.Invitation.Kind.SPACE, (invitation) => {
4636
4699
  (0, import_invariant14.invariant)(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
4637
4700
  F: __dxlog_file15,
4638
- L: 270,
4701
+ L: 259,
4639
4702
  S: this,
4640
4703
  A: [
4641
4704
  "this.dataSpaceManager",
@@ -4659,7 +4722,7 @@ var ServiceContext = class {
4659
4722
  details: assertion
4660
4723
  }, {
4661
4724
  F: __dxlog_file15,
4662
- L: 286,
4725
+ L: 275,
4663
4726
  S: this,
4664
4727
  C: (f, a) => f(...a)
4665
4728
  });
@@ -4670,7 +4733,7 @@ var ServiceContext = class {
4670
4733
  details: assertion
4671
4734
  }, {
4672
4735
  F: __dxlog_file15,
4673
- L: 290,
4736
+ L: 279,
4674
4737
  S: this,
4675
4738
  C: (f, a) => f(...a)
4676
4739
  });
@@ -4681,7 +4744,7 @@ var ServiceContext = class {
4681
4744
  details: assertion
4682
4745
  }, {
4683
4746
  F: __dxlog_file15,
4684
- L: 295,
4747
+ L: 284,
4685
4748
  S: this,
4686
4749
  C: (f, a) => f(...a)
4687
4750
  });
@@ -4692,7 +4755,7 @@ var ServiceContext = class {
4692
4755
  } catch (err) {
4693
4756
  import_log13.log.catch(err, void 0, {
4694
4757
  F: __dxlog_file15,
4695
- L: 301,
4758
+ L: 290,
4696
4759
  S: this,
4697
4760
  C: (f, a) => f(...a)
4698
4761
  });
@@ -4792,16 +4855,16 @@ var StorageDriver = import_config.Runtime.Client.Storage.StorageDriver;
4792
4855
  var createStorageObjects = (config) => {
4793
4856
  const { persistent = false, keyStore, dataStore, dataRoot = (0, import_util8.isNode)() ? import_client_protocol4.DX_DATA : "dxos/storage" } = config ?? {};
4794
4857
  if (persistent && dataStore === StorageDriver.RAM) {
4795
- throw new import_protocols13.InvalidConfigError("RAM storage cannot be used in persistent mode.");
4858
+ throw new import_protocols14.InvalidConfigError("RAM storage cannot be used in persistent mode.");
4796
4859
  }
4797
4860
  if (!persistent && dataStore !== void 0 && dataStore !== StorageDriver.RAM) {
4798
- throw new import_protocols13.InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
4861
+ throw new import_protocols14.InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
4799
4862
  }
4800
4863
  if (persistent && keyStore === StorageDriver.RAM) {
4801
- throw new import_protocols13.InvalidConfigError("RAM key storage cannot be used in persistent mode.");
4864
+ throw new import_protocols14.InvalidConfigError("RAM key storage cannot be used in persistent mode.");
4802
4865
  }
4803
4866
  if (!persistent && keyStore !== StorageDriver.RAM && keyStore !== void 0) {
4804
- throw new import_protocols13.InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
4867
+ throw new import_protocols14.InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
4805
4868
  }
4806
4869
  return {
4807
4870
  storage: (0, import_random_access_storage.createStorage)({
@@ -5264,7 +5327,7 @@ var ClientServicesHost = class {
5264
5327
  return;
5265
5328
  }
5266
5329
  const traceId = import_keys11.PublicKey.random().toHex();
5267
- import_log15.log.trace("dxos.client-services.host.open", import_protocols14.trace.begin({
5330
+ import_log15.log.trace("dxos.client-services.host.open", import_protocols15.trace.begin({
5268
5331
  id: traceId
5269
5332
  }), {
5270
5333
  F: __dxlog_file18,
@@ -5385,7 +5448,7 @@ var ClientServicesHost = class {
5385
5448
  S: this,
5386
5449
  C: (f, a) => f(...a)
5387
5450
  });
5388
- import_log15.log.trace("dxos.client-services.host.open", import_protocols14.trace.end({
5451
+ import_log15.log.trace("dxos.client-services.host.open", import_protocols15.trace.end({
5389
5452
  id: traceId
5390
5453
  }), {
5391
5454
  F: __dxlog_file18,
@@ -5426,7 +5489,7 @@ var ClientServicesHost = class {
5426
5489
  }
5427
5490
  async reset() {
5428
5491
  const traceId = import_keys11.PublicKey.random().toHex();
5429
- import_log15.log.trace("dxos.sdk.client-services-host.reset", import_protocols14.trace.begin({
5492
+ import_log15.log.trace("dxos.sdk.client-services-host.reset", import_protocols15.trace.begin({
5430
5493
  id: traceId
5431
5494
  }), {
5432
5495
  F: __dxlog_file18,
@@ -5448,7 +5511,7 @@ var ClientServicesHost = class {
5448
5511
  S: this,
5449
5512
  C: (f, a) => f(...a)
5450
5513
  });
5451
- import_log15.log.trace("dxos.sdk.client-services-host.reset", import_protocols14.trace.end({
5514
+ import_log15.log.trace("dxos.sdk.client-services-host.reset", import_protocols15.trace.end({
5452
5515
  id: traceId
5453
5516
  }), {
5454
5517
  F: __dxlog_file18,
@@ -5537,4 +5600,4 @@ ClientServicesHost = _ts_decorate8([
5537
5600
  subscribeToSpaces,
5538
5601
  subscribeToSwarmInfo
5539
5602
  });
5540
- //# sourceMappingURL=chunk-YFFKH75O.cjs.map
5603
+ //# sourceMappingURL=chunk-K2PCGWBW.cjs.map