@dxos/client-services 0.4.8-main.de30065 → 0.4.8-main.e23f3c5

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_LIBSX3BY_exports = {};
30
- __export(chunk_LIBSX3BY_exports, {
29
+ var chunk_RENA3JYD_exports = {};
30
+ __export(chunk_RENA3JYD_exports, {
31
31
  ClientRpcServer: () => ClientRpcServer,
32
32
  ClientServicesHost: () => ClientServicesHost,
33
33
  DataSpace: () => DataSpace,
@@ -61,7 +61,7 @@ __export(chunk_LIBSX3BY_exports, {
61
61
  subscribeToSpaces: () => subscribeToSpaces,
62
62
  subscribeToSwarmInfo: () => subscribeToSwarmInfo
63
63
  });
64
- module.exports = __toCommonJS(chunk_LIBSX3BY_exports);
64
+ module.exports = __toCommonJS(chunk_RENA3JYD_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");
@@ -730,6 +732,7 @@ var Identity = class {
730
732
  await this.space.open(ctx);
731
733
  }
732
734
  async close(ctx) {
735
+ await this._presence?.destroy();
733
736
  await this.authVerifier.close();
734
737
  await this.space.spaceState.removeCredentialProcessor(this._profileStateMachine);
735
738
  await this.space.spaceState.removeCredentialProcessor(this._deviceStateMachine);
@@ -769,7 +772,7 @@ var Identity = class {
769
772
  getIdentityCredentialSigner() {
770
773
  (0, import_invariant.invariant)(this._deviceStateMachine.deviceCredentialChain, "Device credential chain is not ready.", {
771
774
  F: __dxlog_file2,
772
- L: 144,
775
+ L: 145,
773
776
  S: this,
774
777
  A: [
775
778
  "this._deviceStateMachine.deviceCredentialChain",
@@ -793,7 +796,7 @@ var Identity = class {
793
796
  dataFeedKey
794
797
  }, {
795
798
  F: __dxlog_file2,
796
- L: 160,
799
+ L: 161,
797
800
  S: this,
798
801
  C: (f, a) => f(...a)
799
802
  });
@@ -2888,7 +2891,7 @@ var getPlatform = () => {
2888
2891
  };
2889
2892
  }
2890
2893
  };
2891
- var DXOS_VERSION = "0.4.8-main.de30065";
2894
+ var DXOS_VERSION = "0.4.8-main.e23f3c5";
2892
2895
  var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/diagnostics.ts";
2893
2896
  var DEFAULT_TIMEOUT = 1e3;
2894
2897
  var createDiagnostics = async (clientServices, serviceContext, config) => {
@@ -4429,6 +4432,80 @@ var SpacesServiceImpl = class {
4429
4432
  }
4430
4433
  };
4431
4434
  var getChannelId = (channel) => `user-channel/${channel}`;
4435
+ var createLoadDocuments = (automergeHost) => (
4436
+ /**
4437
+ * Get object data blobs from Automerge Repo by ids.
4438
+ * @param ids
4439
+ */
4440
+ // TODO(mykola): Unload automerge handles after usage.
4441
+ async function* loadDocuments(ids) {
4442
+ for (const id of ids) {
4443
+ const { documentId, objectId } = import_protocols13.idCodec.decode(id);
4444
+ const handle = automergeHost.repo.find(documentId);
4445
+ await (0, import_debug7.warnAfterTimeout)(5e3, "to long to load doc", () => handle.whenReady());
4446
+ const doc = handle.docSync();
4447
+ const heads = (0, import_automerge.getHeads)(doc);
4448
+ yield [
4449
+ {
4450
+ id,
4451
+ object: doc.objects[objectId],
4452
+ currentHash: heads.at(-1)
4453
+ }
4454
+ ];
4455
+ }
4456
+ }
4457
+ );
4458
+ var createGetAllDocuments = (automergeHost) => (
4459
+ /**
4460
+ * Recursively get all object data blobs from Automerge Repo.
4461
+ * @param ids
4462
+ */
4463
+ // TODO(mykola): Unload automerge handles after usage.
4464
+ async function* getAllDocuments() {
4465
+ const visited = /* @__PURE__ */ new Set();
4466
+ async function* getObjectsFromHandle(handle) {
4467
+ if (visited.has(handle.documentId)) {
4468
+ return;
4469
+ }
4470
+ await (0, import_debug7.warnAfterTimeout)(5e3, "to long to load doc", () => handle.whenReady());
4471
+ const doc = handle.docSync();
4472
+ const heads = (0, import_automerge.getHeads)(doc);
4473
+ if (doc.objects) {
4474
+ yield Object.entries(doc.objects).map(([objectId, object]) => {
4475
+ return {
4476
+ id: import_protocols13.idCodec.encode({
4477
+ documentId: handle.documentId,
4478
+ objectId
4479
+ }),
4480
+ object,
4481
+ currentHash: heads.at(-1)
4482
+ };
4483
+ });
4484
+ }
4485
+ if (doc.links) {
4486
+ for (const id of Object.values(doc.links)) {
4487
+ if (visited.has(id)) {
4488
+ continue;
4489
+ }
4490
+ const linkHandle = automergeHost.repo.find(id);
4491
+ for await (const result of getObjectsFromHandle(linkHandle)) {
4492
+ yield result;
4493
+ }
4494
+ }
4495
+ }
4496
+ visited.add(handle.documentId);
4497
+ }
4498
+ for (const handle of Object.values(automergeHost.repo.handles)) {
4499
+ if (visited.has(handle.documentId)) {
4500
+ continue;
4501
+ }
4502
+ for await (const result of getObjectsFromHandle(handle)) {
4503
+ yield result;
4504
+ }
4505
+ visited.add(handle.documentId);
4506
+ }
4507
+ }
4508
+ );
4432
4509
  function _ts_decorate6(decorators, target, key, desc) {
4433
4510
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4434
4511
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -4486,21 +4563,8 @@ var ServiceContext = class {
4486
4563
  directory: storage.createDirectory("index-store")
4487
4564
  }),
4488
4565
  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
- }
4566
+ loadDocuments: createLoadDocuments(this.automergeHost),
4567
+ getAllDocuments: createGetAllDocuments(this.automergeHost)
4504
4568
  });
4505
4569
  this.invitations = new InvitationsHandler(this.networkManager);
4506
4570
  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 +4573,7 @@ var ServiceContext = class {
4509
4573
  await this._checkStorageVersion();
4510
4574
  (0, import_log13.log)("opening...", void 0, {
4511
4575
  F: __dxlog_file15,
4512
- L: 173,
4576
+ L: 162,
4513
4577
  S: this,
4514
4578
  C: (f, a) => f(...a)
4515
4579
  });
@@ -4517,7 +4581,7 @@ var ServiceContext = class {
4517
4581
  id: this._instanceId
4518
4582
  }), {
4519
4583
  F: __dxlog_file15,
4520
- L: 174,
4584
+ L: 163,
4521
4585
  S: this,
4522
4586
  C: (f, a) => f(...a)
4523
4587
  });
@@ -4533,13 +4597,13 @@ var ServiceContext = class {
4533
4597
  id: this._instanceId
4534
4598
  }), {
4535
4599
  F: __dxlog_file15,
4536
- L: 184,
4600
+ L: 173,
4537
4601
  S: this,
4538
4602
  C: (f, a) => f(...a)
4539
4603
  });
4540
4604
  (0, import_log13.log)("opened", void 0, {
4541
4605
  F: __dxlog_file15,
4542
- L: 185,
4606
+ L: 174,
4543
4607
  S: this,
4544
4608
  C: (f, a) => f(...a)
4545
4609
  });
@@ -4547,7 +4611,7 @@ var ServiceContext = class {
4547
4611
  async close() {
4548
4612
  (0, import_log13.log)("closing...", void 0, {
4549
4613
  F: __dxlog_file15,
4550
- L: 189,
4614
+ L: 178,
4551
4615
  S: this,
4552
4616
  C: (f, a) => f(...a)
4553
4617
  });
@@ -4566,7 +4630,7 @@ var ServiceContext = class {
4566
4630
  await this.indexer.destroy();
4567
4631
  (0, import_log13.log)("closed", void 0, {
4568
4632
  F: __dxlog_file15,
4569
- L: 203,
4633
+ L: 192,
4570
4634
  S: this,
4571
4635
  C: (f, a) => f(...a)
4572
4636
  });
@@ -4580,7 +4644,7 @@ var ServiceContext = class {
4580
4644
  const factory = this._handlerFactories.get(invitation.kind);
4581
4645
  (0, import_invariant14.invariant)(factory, `Unknown invitation kind: ${invitation.kind}`, {
4582
4646
  F: __dxlog_file15,
4583
- L: 214,
4647
+ L: 203,
4584
4648
  S: this,
4585
4649
  A: [
4586
4650
  "factory",
@@ -4612,7 +4676,7 @@ var ServiceContext = class {
4612
4676
  async _initialize(ctx) {
4613
4677
  (0, import_log13.log)("initializing spaces...", void 0, {
4614
4678
  F: __dxlog_file15,
4615
- L: 245,
4679
+ L: 234,
4616
4680
  S: this,
4617
4681
  C: (f, a) => f(...a)
4618
4682
  });
@@ -4635,7 +4699,7 @@ var ServiceContext = class {
4635
4699
  this._handlerFactories.set(import_services12.Invitation.Kind.SPACE, (invitation) => {
4636
4700
  (0, import_invariant14.invariant)(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
4637
4701
  F: __dxlog_file15,
4638
- L: 270,
4702
+ L: 259,
4639
4703
  S: this,
4640
4704
  A: [
4641
4705
  "this.dataSpaceManager",
@@ -4659,7 +4723,7 @@ var ServiceContext = class {
4659
4723
  details: assertion
4660
4724
  }, {
4661
4725
  F: __dxlog_file15,
4662
- L: 286,
4726
+ L: 275,
4663
4727
  S: this,
4664
4728
  C: (f, a) => f(...a)
4665
4729
  });
@@ -4670,7 +4734,7 @@ var ServiceContext = class {
4670
4734
  details: assertion
4671
4735
  }, {
4672
4736
  F: __dxlog_file15,
4673
- L: 290,
4737
+ L: 279,
4674
4738
  S: this,
4675
4739
  C: (f, a) => f(...a)
4676
4740
  });
@@ -4681,7 +4745,7 @@ var ServiceContext = class {
4681
4745
  details: assertion
4682
4746
  }, {
4683
4747
  F: __dxlog_file15,
4684
- L: 295,
4748
+ L: 284,
4685
4749
  S: this,
4686
4750
  C: (f, a) => f(...a)
4687
4751
  });
@@ -4692,7 +4756,7 @@ var ServiceContext = class {
4692
4756
  } catch (err) {
4693
4757
  import_log13.log.catch(err, void 0, {
4694
4758
  F: __dxlog_file15,
4695
- L: 301,
4759
+ L: 290,
4696
4760
  S: this,
4697
4761
  C: (f, a) => f(...a)
4698
4762
  });
@@ -4792,16 +4856,16 @@ var StorageDriver = import_config.Runtime.Client.Storage.StorageDriver;
4792
4856
  var createStorageObjects = (config) => {
4793
4857
  const { persistent = false, keyStore, dataStore, dataRoot = (0, import_util8.isNode)() ? import_client_protocol4.DX_DATA : "dxos/storage" } = config ?? {};
4794
4858
  if (persistent && dataStore === StorageDriver.RAM) {
4795
- throw new import_protocols13.InvalidConfigError("RAM storage cannot be used in persistent mode.");
4859
+ throw new import_protocols14.InvalidConfigError("RAM storage cannot be used in persistent mode.");
4796
4860
  }
4797
4861
  if (!persistent && dataStore !== void 0 && dataStore !== StorageDriver.RAM) {
4798
- throw new import_protocols13.InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
4862
+ throw new import_protocols14.InvalidConfigError("Cannot use a persistent storage in not persistent mode.");
4799
4863
  }
4800
4864
  if (persistent && keyStore === StorageDriver.RAM) {
4801
- throw new import_protocols13.InvalidConfigError("RAM key storage cannot be used in persistent mode.");
4865
+ throw new import_protocols14.InvalidConfigError("RAM key storage cannot be used in persistent mode.");
4802
4866
  }
4803
4867
  if (!persistent && keyStore !== StorageDriver.RAM && keyStore !== void 0) {
4804
- throw new import_protocols13.InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
4868
+ throw new import_protocols14.InvalidConfigError("Cannot use a persistent key storage in not persistent mode.");
4805
4869
  }
4806
4870
  return {
4807
4871
  storage: (0, import_random_access_storage.createStorage)({
@@ -5264,7 +5328,7 @@ var ClientServicesHost = class {
5264
5328
  return;
5265
5329
  }
5266
5330
  const traceId = import_keys11.PublicKey.random().toHex();
5267
- import_log15.log.trace("dxos.client-services.host.open", import_protocols14.trace.begin({
5331
+ import_log15.log.trace("dxos.client-services.host.open", import_protocols15.trace.begin({
5268
5332
  id: traceId
5269
5333
  }), {
5270
5334
  F: __dxlog_file18,
@@ -5385,7 +5449,7 @@ var ClientServicesHost = class {
5385
5449
  S: this,
5386
5450
  C: (f, a) => f(...a)
5387
5451
  });
5388
- import_log15.log.trace("dxos.client-services.host.open", import_protocols14.trace.end({
5452
+ import_log15.log.trace("dxos.client-services.host.open", import_protocols15.trace.end({
5389
5453
  id: traceId
5390
5454
  }), {
5391
5455
  F: __dxlog_file18,
@@ -5426,7 +5490,7 @@ var ClientServicesHost = class {
5426
5490
  }
5427
5491
  async reset() {
5428
5492
  const traceId = import_keys11.PublicKey.random().toHex();
5429
- import_log15.log.trace("dxos.sdk.client-services-host.reset", import_protocols14.trace.begin({
5493
+ import_log15.log.trace("dxos.sdk.client-services-host.reset", import_protocols15.trace.begin({
5430
5494
  id: traceId
5431
5495
  }), {
5432
5496
  F: __dxlog_file18,
@@ -5448,7 +5512,7 @@ var ClientServicesHost = class {
5448
5512
  S: this,
5449
5513
  C: (f, a) => f(...a)
5450
5514
  });
5451
- import_log15.log.trace("dxos.sdk.client-services-host.reset", import_protocols14.trace.end({
5515
+ import_log15.log.trace("dxos.sdk.client-services-host.reset", import_protocols15.trace.end({
5452
5516
  id: traceId
5453
5517
  }), {
5454
5518
  F: __dxlog_file18,
@@ -5537,4 +5601,4 @@ ClientServicesHost = _ts_decorate8([
5537
5601
  subscribeToSpaces,
5538
5602
  subscribeToSwarmInfo
5539
5603
  });
5540
- //# sourceMappingURL=chunk-LIBSX3BY.cjs.map
5604
+ //# sourceMappingURL=chunk-RENA3JYD.cjs.map