@dxos/client-services 0.5.9-main.9587514 → 0.5.9-main.9908c63

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 (32) hide show
  1. package/dist/lib/browser/{chunk-Y4NGEDFZ.mjs → chunk-ZWYYPM2X.mjs} +323 -125
  2. package/dist/lib/browser/chunk-ZWYYPM2X.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +9 -1
  4. package/dist/lib/browser/index.mjs.map +1 -1
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/packlets/testing/index.mjs +1 -1
  7. package/dist/lib/node/{chunk-TZZXMQEN.cjs → chunk-CKM7SKSH.cjs} +390 -190
  8. package/dist/lib/node/chunk-CKM7SKSH.cjs.map +7 -0
  9. package/dist/lib/node/index.cjs +49 -41
  10. package/dist/lib/node/index.cjs.map +1 -1
  11. package/dist/lib/node/meta.json +1 -1
  12. package/dist/lib/node/packlets/testing/index.cjs +8 -8
  13. package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
  14. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  15. package/dist/types/src/packlets/spaces/epoch-migrations.d.ts +2 -2
  16. package/dist/types/src/packlets/spaces/epoch-migrations.d.ts.map +1 -1
  17. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  18. package/dist/types/src/packlets/storage/index.d.ts +1 -0
  19. package/dist/types/src/packlets/storage/index.d.ts.map +1 -1
  20. package/dist/types/src/packlets/storage/profile-archive.d.ts +14 -0
  21. package/dist/types/src/packlets/storage/profile-archive.d.ts.map +1 -0
  22. package/dist/types/src/version.d.ts +1 -1
  23. package/package.json +36 -36
  24. package/src/packlets/identity/identity-service.ts +28 -22
  25. package/src/packlets/spaces/data-space.ts +3 -1
  26. package/src/packlets/spaces/epoch-migrations.ts +57 -38
  27. package/src/packlets/spaces/spaces-service.ts +2 -0
  28. package/src/packlets/storage/index.ts +1 -0
  29. package/src/packlets/storage/profile-archive.ts +111 -0
  30. package/src/version.ts +1 -1
  31. package/dist/lib/browser/chunk-Y4NGEDFZ.mjs.map +0 -7
  32. package/dist/lib/node/chunk-TZZXMQEN.cjs.map +0 -7
@@ -359,7 +359,7 @@ import { SpaceMember } from "@dxos/protocols/proto/dxos/client/services";
359
359
  import { TRACE_PROCESSOR } from "@dxos/tracing";
360
360
 
361
361
  // packages/sdk/client-services/src/version.ts
362
- var DXOS_VERSION = "0.5.9-main.9587514";
362
+ var DXOS_VERSION = "0.5.9-main.9908c63";
363
363
 
364
364
  // packages/sdk/client-services/src/packlets/services/platform.ts
365
365
  import { Platform } from "@dxos/protocols/proto/dxos/client/services";
@@ -1658,7 +1658,7 @@ var IdentityServiceImpl = class extends Resource {
1658
1658
  duplicate: space.id
1659
1659
  }, {
1660
1660
  F: __dxlog_file8,
1661
- L: 127,
1661
+ L: 129,
1662
1662
  S: this,
1663
1663
  C: (f, a) => f(...a)
1664
1664
  });
@@ -1669,6 +1669,13 @@ var IdentityServiceImpl = class extends Resource {
1669
1669
  recodedDefaultSpace = true;
1670
1670
  recordedDefaultSpaceTrigger.wake();
1671
1671
  }
1672
+ }, (err) => {
1673
+ log6.catch(err, void 0, {
1674
+ F: __dxlog_file8,
1675
+ L: 140,
1676
+ S: this,
1677
+ C: (f, a) => f(...a)
1678
+ });
1672
1679
  });
1673
1680
  await Promise.race([
1674
1681
  allProcessed,
@@ -3717,10 +3724,10 @@ var InvitationsManager = class {
3717
3724
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
3718
3725
  import { Event as Event6, Mutex as Mutex2, scheduleTask as scheduleTask5, sleep as sleep3, synchronized, trackLeaks } from "@dxos/async";
3719
3726
  import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
3720
- import { Context as Context8, ContextDisposedError as ContextDisposedError3, cancelWithContext as cancelWithContext5 } from "@dxos/context";
3727
+ import { Context as Context8, ContextDisposedError as ContextDisposedError3, cancelWithContext as cancelWithContext4 } from "@dxos/context";
3721
3728
  import { timed, warnAfterTimeout } from "@dxos/debug";
3722
3729
  import { createMappedFeedWriter } from "@dxos/echo-pipeline";
3723
- import { SpaceDocVersion } from "@dxos/echo-protocol";
3730
+ import { SpaceDocVersion as SpaceDocVersion2 } from "@dxos/echo-protocol";
3724
3731
  import { failedInvariant } from "@dxos/invariant";
3725
3732
  import { PublicKey as PublicKey10 } from "@dxos/keys";
3726
3733
  import { log as log15 } from "@dxos/log";
@@ -3777,22 +3784,19 @@ var AutomergeSpaceState = class extends Resource2 {
3777
3784
  };
3778
3785
 
3779
3786
  // packages/sdk/client-services/src/packlets/spaces/epoch-migrations.ts
3780
- import { asyncTimeout as asyncTimeout2 } from "@dxos/async";
3781
- import { next as am } from "@dxos/automerge/automerge";
3782
- import { cancelWithContext as cancelWithContext4 } from "@dxos/context";
3783
3787
  import { convertLegacyReferences, convertLegacySpaceRootDoc, findInlineObjectOfType, migrateDocument } from "@dxos/echo-db";
3784
- import { AutomergeDocumentLoaderImpl } from "@dxos/echo-pipeline";
3788
+ import { SpaceDocVersion } from "@dxos/echo-protocol";
3785
3789
  import { TYPE_PROPERTIES } from "@dxos/echo-schema";
3786
3790
  import { invariant as invariant12 } from "@dxos/invariant";
3787
3791
  import { log as log13 } from "@dxos/log";
3788
3792
  import { CreateEpochRequest } from "@dxos/protocols/proto/dxos/client/services";
3789
- import { assignDeep } from "@dxos/util";
3790
3793
  var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/epoch-migrations.ts";
3794
+ var LOAD_DOC_TIMEOUT = 1e4;
3791
3795
  var runEpochMigration = async (ctx, context) => {
3792
3796
  switch (context.migration) {
3793
3797
  case CreateEpochRequest.Migration.INIT_AUTOMERGE: {
3794
- const document = context.repo.create();
3795
- await context.repo.flush();
3798
+ const document = context.echoHost.createDoc();
3799
+ await context.echoHost.flush();
3796
3800
  return {
3797
3801
  newRoot: document.url
3798
3802
  };
@@ -3801,10 +3805,11 @@ var runEpochMigration = async (ctx, context) => {
3801
3805
  if (!context.currentRoot) {
3802
3806
  throw new Error("Space does not have an automerge root");
3803
3807
  }
3804
- const rootHandle = context.repo.find(context.currentRoot);
3805
- await cancelWithContext4(ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
3806
- const newRoot = context.repo.create(rootHandle.docSync());
3807
- await context.repo.flush();
3808
+ const rootHandle = await context.echoHost.loadDoc(ctx, context.currentRoot, {
3809
+ timeout: LOAD_DOC_TIMEOUT
3810
+ });
3811
+ const newRoot = context.echoHost.createDoc(rootHandle.docSync());
3812
+ await context.echoHost.flush();
3808
3813
  return {
3809
3814
  newRoot: newRoot.url
3810
3815
  };
@@ -3812,66 +3817,76 @@ var runEpochMigration = async (ctx, context) => {
3812
3817
  case CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT: {
3813
3818
  log13.info("Fragmenting", void 0, {
3814
3819
  F: __dxlog_file16,
3815
- L: 63,
3820
+ L: 64,
3816
3821
  S: void 0,
3817
3822
  C: (f, a) => f(...a)
3818
3823
  });
3819
3824
  const currentRootUrl = context.currentRoot;
3820
- const rootHandle = context.repo.find(currentRootUrl);
3821
- await cancelWithContext4(ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
3825
+ const rootHandle = await context.echoHost.loadDoc(ctx, currentRootUrl, {
3826
+ timeout: LOAD_DOC_TIMEOUT
3827
+ });
3822
3828
  const objects = Object.entries(rootHandle.docSync().objects);
3823
3829
  const properties = findInlineObjectOfType(rootHandle.docSync(), TYPE_PROPERTIES);
3824
3830
  const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
3825
3831
  invariant12(properties, "Properties not found", {
3826
3832
  F: __dxlog_file16,
3827
- L: 73,
3833
+ L: 75,
3828
3834
  S: void 0,
3829
3835
  A: [
3830
3836
  "properties",
3831
3837
  "'Properties not found'"
3832
3838
  ]
3833
3839
  });
3834
- const newSpaceDoc = {
3840
+ const newRoot = context.echoHost.createDoc({
3835
3841
  ...rootHandle.docSync(),
3836
3842
  objects: Object.fromEntries([
3837
3843
  properties
3838
3844
  ])
3839
- };
3840
- const newRoot = context.repo.create(newSpaceDoc);
3845
+ });
3841
3846
  invariant12(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3842
3847
  F: __dxlog_file16,
3843
- L: 78,
3848
+ L: 82,
3844
3849
  S: void 0,
3845
3850
  A: [
3846
3851
  "typeof newRoot.url === 'string' && newRoot.url.length > 0",
3847
3852
  ""
3848
3853
  ]
3849
3854
  });
3850
- const docLoader = new AutomergeDocumentLoaderImpl(context.spaceId, context.repo, context.spaceKey);
3851
- await docLoader.loadSpaceRootDocHandle(ctx, {
3852
- rootUrl: newRoot.url
3853
- });
3854
- otherObjects.forEach(([key, value]) => {
3855
- const handle = docLoader.createDocumentForObject(key);
3856
- handle.change((doc) => {
3857
- assignDeep(doc, [
3858
- "objects",
3859
- key
3860
- ], value);
3855
+ const newLinks = [];
3856
+ for (const [id, objData] of otherObjects) {
3857
+ const handle = context.echoHost.createDoc({
3858
+ version: SpaceDocVersion.CURRENT,
3859
+ access: {
3860
+ spaceKey: context.spaceKey.toHex()
3861
+ },
3862
+ objects: {
3863
+ [id]: objData
3864
+ }
3861
3865
  });
3866
+ newLinks.push([
3867
+ id,
3868
+ handle.url
3869
+ ]);
3870
+ }
3871
+ newRoot.change((doc) => {
3872
+ doc.links ??= {};
3873
+ for (const [id, url] of newLinks) {
3874
+ doc.links[id] = url;
3875
+ }
3862
3876
  });
3863
- await context.repo.flush();
3877
+ await context.echoHost.flush();
3864
3878
  return {
3865
3879
  newRoot: newRoot.url
3866
3880
  };
3867
3881
  }
3868
3882
  case CreateEpochRequest.Migration.MIGRATE_REFERENCES_TO_DXN: {
3869
3883
  const currentRootUrl = context.currentRoot;
3870
- const rootHandle = context.repo.find(currentRootUrl);
3871
- await cancelWithContext4(ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
3884
+ const rootHandle = await context.echoHost.loadDoc(ctx, currentRootUrl, {
3885
+ timeout: LOAD_DOC_TIMEOUT
3886
+ });
3872
3887
  invariant12(rootHandle.docSync(), "Root doc not found", {
3873
3888
  F: __dxlog_file16,
3874
- L: 100,
3889
+ L: 115,
3875
3890
  S: void 0,
3876
3891
  A: [
3877
3892
  "rootHandle.docSync()",
@@ -3880,25 +3895,44 @@ var runEpochMigration = async (ctx, context) => {
3880
3895
  });
3881
3896
  const newRootContent = await convertLegacySpaceRootDoc(structuredClone(rootHandle.docSync()));
3882
3897
  for (const [id, url] of Object.entries(newRootContent.links ?? {})) {
3883
- const handle = context.repo.find(url);
3884
- await cancelWithContext4(ctx, asyncTimeout2(handle.whenReady(), 1e4));
3885
- invariant12(handle.docSync(), "Doc not found", {
3886
- F: __dxlog_file16,
3887
- L: 107,
3888
- S: void 0,
3889
- A: [
3890
- "handle.docSync()",
3891
- "'Doc not found'"
3892
- ]
3893
- });
3894
- const newDoc = await convertLegacyReferences(structuredClone(handle.docSync()));
3895
- const migratedDoc = migrateDocument(handle.docSync(), newDoc);
3896
- const newHandle = context.repo.import(am.save(migratedDoc));
3897
- newRootContent.links[id] = newHandle.url;
3898
+ try {
3899
+ const handle = await context.echoHost.loadDoc(ctx, url, {
3900
+ timeout: LOAD_DOC_TIMEOUT
3901
+ });
3902
+ invariant12(handle.docSync(), void 0, {
3903
+ F: __dxlog_file16,
3904
+ L: 122,
3905
+ S: void 0,
3906
+ A: [
3907
+ "handle.docSync()",
3908
+ ""
3909
+ ]
3910
+ });
3911
+ const newDoc = await convertLegacyReferences(structuredClone(handle.docSync()));
3912
+ const migratedDoc = migrateDocument(handle.docSync(), newDoc);
3913
+ const newHandle = context.echoHost.createDoc(migratedDoc, {
3914
+ preserveHistory: true
3915
+ });
3916
+ newRootContent.links[id] = newHandle.url;
3917
+ } catch (err) {
3918
+ log13.warn("Failed to migrate reference", {
3919
+ id,
3920
+ url,
3921
+ error: err
3922
+ }, {
3923
+ F: __dxlog_file16,
3924
+ L: 128,
3925
+ S: void 0,
3926
+ C: (f, a) => f(...a)
3927
+ });
3928
+ delete newRootContent.links[id];
3929
+ }
3898
3930
  }
3899
3931
  const migratedRoot = migrateDocument(rootHandle.docSync(), newRootContent);
3900
- const newRoot = context.repo.import(am.save(migratedRoot));
3901
- await context.repo.flush();
3932
+ const newRoot = context.echoHost.createDoc(migratedRoot, {
3933
+ preserveHistory: true
3934
+ });
3935
+ await context.echoHost.flush();
3902
3936
  return {
3903
3937
  newRoot: newRoot.url
3904
3938
  };
@@ -3906,14 +3940,14 @@ var runEpochMigration = async (ctx, context) => {
3906
3940
  case CreateEpochRequest.Migration.REPLACE_AUTOMERGE_ROOT: {
3907
3941
  invariant12(context.newAutomergeRoot, void 0, {
3908
3942
  F: __dxlog_file16,
3909
- L: 124,
3943
+ L: 143,
3910
3944
  S: void 0,
3911
3945
  A: [
3912
3946
  "context.newAutomergeRoot",
3913
3947
  ""
3914
3948
  ]
3915
3949
  });
3916
- await context.repo.flush();
3950
+ await context.echoHost.flush();
3917
3951
  return {
3918
3952
  newRoot: context.newAutomergeRoot
3919
3953
  };
@@ -4568,7 +4602,7 @@ var DataSpace = class {
4568
4602
  try {
4569
4603
  var _usingCtx = _using_ctx();
4570
4604
  await warnAfterTimeout(5e3, "Automerge root doc load timeout (DataSpace)", async () => {
4571
- await cancelWithContext5(this._ctx, handle.whenReady());
4605
+ await cancelWithContext4(this._ctx, handle.whenReady());
4572
4606
  });
4573
4607
  if (this._ctx.disposed) {
4574
4608
  return;
@@ -4587,7 +4621,7 @@ var DataSpace = class {
4587
4621
  }
4588
4622
  const root = await this._echoHost.openSpaceRoot(handle.url);
4589
4623
  this._databaseRoot = root;
4590
- if (root.getVersion() !== SpaceDocVersion.CURRENT) {
4624
+ if (root.getVersion() !== SpaceDocVersion2.CURRENT) {
4591
4625
  if (this._state !== SpaceState2.REQUIRES_MIGRATION) {
4592
4626
  this._state = SpaceState2.REQUIRES_MIGRATION;
4593
4627
  this.stateUpdate.emit();
@@ -4612,7 +4646,7 @@ var DataSpace = class {
4612
4646
  err
4613
4647
  }, {
4614
4648
  F: __dxlog_file18,
4615
- L: 431,
4649
+ L: 433,
4616
4650
  S: this,
4617
4651
  C: (f, a) => f(...a)
4618
4652
  });
@@ -4640,7 +4674,7 @@ var DataSpace = class {
4640
4674
  return null;
4641
4675
  }
4642
4676
  const { newRoot } = await runEpochMigration(ctx, {
4643
- repo: this._echoHost.automergeRepo,
4677
+ echoHost: this._echoHost,
4644
4678
  spaceId: this.id,
4645
4679
  spaceKey: this.key,
4646
4680
  migration: options.migration,
@@ -4698,7 +4732,7 @@ var DataSpace = class {
4698
4732
  state: SpaceState2[this._state]
4699
4733
  }, {
4700
4734
  F: __dxlog_file18,
4701
- L: 512,
4735
+ L: 514,
4702
4736
  S: this,
4703
4737
  C: (f, a) => f(...a)
4704
4738
  });
@@ -4757,12 +4791,12 @@ DataSpace = _ts_decorate4([
4757
4791
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
4758
4792
  import { Event as Event7, synchronized as synchronized2, trackLeaks as trackLeaks2 } from "@dxos/async";
4759
4793
  import { PropertiesType } from "@dxos/client-protocol";
4760
- import { Context as Context9, cancelWithContext as cancelWithContext6 } from "@dxos/context";
4794
+ import { Context as Context9, cancelWithContext as cancelWithContext5 } from "@dxos/context";
4761
4795
  import { getCredentialAssertion as getCredentialAssertion3, createAdmissionCredentials } from "@dxos/credentials";
4762
4796
  import { convertLegacyReferences as convertLegacyReferences2, findInlineObjectOfType as findInlineObjectOfType2 } from "@dxos/echo-db";
4763
4797
  import { AuthStatus } from "@dxos/echo-pipeline";
4764
4798
  import { CredentialServerExtension } from "@dxos/echo-pipeline";
4765
- import { LEGACY_TYPE_PROPERTIES, SpaceDocVersion as SpaceDocVersion2, encodeReference } from "@dxos/echo-protocol";
4799
+ import { LEGACY_TYPE_PROPERTIES, SpaceDocVersion as SpaceDocVersion3, encodeReference } from "@dxos/echo-protocol";
4766
4800
  import { TYPE_PROPERTIES as TYPE_PROPERTIES2, generateEchoId, getTypeReference } from "@dxos/echo-schema";
4767
4801
  import { writeMessages as writeMessages3 } from "@dxos/feed-store";
4768
4802
  import { invariant as invariant14 } from "@dxos/invariant";
@@ -4773,7 +4807,7 @@ import { Invitation as Invitation7, SpaceState as SpaceState3 } from "@dxos/prot
4773
4807
  import { SpaceMember as SpaceMember6 } from "@dxos/protocols/proto/dxos/halo/credentials";
4774
4808
  import { Gossip as Gossip2, Presence as Presence2 } from "@dxos/teleport-extension-gossip";
4775
4809
  import { trace as trace7 } from "@dxos/tracing";
4776
- import { ComplexMap as ComplexMap3, assignDeep as assignDeep2, deferFunction as deferFunction2, forEachAsync } from "@dxos/util";
4810
+ import { ComplexMap as ComplexMap3, assignDeep, deferFunction as deferFunction2, forEachAsync } from "@dxos/util";
4777
4811
 
4778
4812
  // packages/sdk/client-services/src/packlets/spaces/genesis.ts
4779
4813
  import { createCredential } from "@dxos/credentials";
@@ -5032,11 +5066,11 @@ var DataSpaceManager = class {
5032
5066
  return false;
5033
5067
  }
5034
5068
  switch (space.databaseRoot.getVersion()) {
5035
- case SpaceDocVersion2.CURRENT: {
5069
+ case SpaceDocVersion3.CURRENT: {
5036
5070
  const [_, properties] = findInlineObjectOfType2(space.databaseRoot.docSync(), TYPE_PROPERTIES2) ?? [];
5037
5071
  return properties?.data?.[DEFAULT_SPACE_KEY] === this._signingContext.identityKey.toHex();
5038
5072
  }
5039
- case SpaceDocVersion2.LEGACY: {
5073
+ case SpaceDocVersion3.LEGACY: {
5040
5074
  const convertedDoc = await convertLegacyReferences2(space.databaseRoot.docSync());
5041
5075
  const [_, properties] = findInlineObjectOfType2(convertedDoc, LEGACY_TYPE_PROPERTIES) ?? [];
5042
5076
  return properties?.data?.[DEFAULT_SPACE_KEY] === this._signingContext.identityKey.toHex();
@@ -5070,7 +5104,7 @@ var DataSpaceManager = class {
5070
5104
  };
5071
5105
  const propertiesId = generateEchoId();
5072
5106
  document.change((doc) => {
5073
- assignDeep2(doc, [
5107
+ assignDeep(doc, [
5074
5108
  "objects",
5075
5109
  propertiesId
5076
5110
  ], properties);
@@ -5177,7 +5211,7 @@ var DataSpaceManager = class {
5177
5211
  * TODO(dmaretskyi): Consider removing.
5178
5212
  */
5179
5213
  async waitUntilSpaceReady(spaceKey) {
5180
- await cancelWithContext6(this._ctx, this.updated.waitForCondition(() => {
5214
+ await cancelWithContext5(this._ctx, this.updated.waitForCondition(() => {
5181
5215
  const space = this._spaces.get(spaceKey);
5182
5216
  return !!space && space.state === SpaceState3.READY;
5183
5217
  }));
@@ -5712,7 +5746,8 @@ var SpacesServiceImpl = class {
5712
5746
  startDataTimeframe: void 0,
5713
5747
  currentDataTimeframe: void 0,
5714
5748
  targetDataTimeframe: void 0,
5715
- totalDataTimeframe: void 0
5749
+ totalDataTimeframe: void 0,
5750
+ spaceRootUrl: space.databaseRoot?.url
5716
5751
  },
5717
5752
  members: Array.from(space.inner.spaceState.members.values()).map((member) => {
5718
5753
  const peers = space.presence.getPeersOnline().filter(({ identityKey }) => identityKey.equals(member.key));
@@ -6070,7 +6105,7 @@ var ServiceRegistry = class {
6070
6105
  };
6071
6106
 
6072
6107
  // packages/sdk/client-services/src/packlets/locks/browser.ts
6073
- import { asyncTimeout as asyncTimeout3, Trigger as Trigger9 } from "@dxos/async";
6108
+ import { asyncTimeout as asyncTimeout2, Trigger as Trigger9 } from "@dxos/async";
6074
6109
  import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
6075
6110
  import { log as log19, logInfo } from "@dxos/log";
6076
6111
  function _ts_decorate7(decorators, target, key, desc) {
@@ -6111,7 +6146,7 @@ var Lock = class {
6111
6146
  S: this,
6112
6147
  C: (f, a) => f(...a)
6113
6148
  });
6114
- await asyncTimeout3(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
6149
+ await asyncTimeout2(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
6115
6150
  log19("acquired lock", void 0, {
6116
6151
  F: __dxlog_file22,
6117
6152
  L: 44,
@@ -6267,13 +6302,172 @@ var createLevel = async (config) => {
6267
6302
  return level;
6268
6303
  };
6269
6304
 
6305
+ // packages/sdk/client-services/src/packlets/storage/profile-archive.ts
6306
+ import { cbor } from "@dxos/automerge/automerge-repo";
6307
+ import { invariant as invariant17 } from "@dxos/invariant";
6308
+ import { log as log20 } from "@dxos/log";
6309
+ import { ProfileArchiveEntryType } from "@dxos/protocols";
6310
+ import { arrayToBuffer } from "@dxos/util";
6311
+ var __dxlog_file23 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/storage/profile-archive.ts";
6312
+ var encodeProfileArchive = (profile) => cbor.encode(profile);
6313
+ var decodeProfileArchive = (data) => cbor.decode(data);
6314
+ var exportProfileData = async ({ storage, level }) => {
6315
+ const archive = {
6316
+ storage: [],
6317
+ meta: {
6318
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
6319
+ }
6320
+ };
6321
+ {
6322
+ const directory = await storage.createDirectory();
6323
+ const files = await directory.list();
6324
+ log20.info("begin exporting files", {
6325
+ count: files.length
6326
+ }, {
6327
+ F: __dxlog_file23,
6328
+ L: 30,
6329
+ S: void 0,
6330
+ C: (f, a) => f(...a)
6331
+ });
6332
+ for (const filename of files) {
6333
+ const file = await directory.getOrCreateFile(filename);
6334
+ const { size } = await file.stat();
6335
+ const data = await file.read(0, size);
6336
+ archive.storage.push({
6337
+ type: ProfileArchiveEntryType.FILE,
6338
+ key: filename,
6339
+ value: data
6340
+ });
6341
+ }
6342
+ log20.info("done exporting files", {
6343
+ count: files.length
6344
+ }, {
6345
+ F: __dxlog_file23,
6346
+ L: 41,
6347
+ S: void 0,
6348
+ C: (f, a) => f(...a)
6349
+ });
6350
+ }
6351
+ {
6352
+ log20.info("begin exporting kv pairs", void 0, {
6353
+ F: __dxlog_file23,
6354
+ L: 45,
6355
+ S: void 0,
6356
+ C: (f, a) => f(...a)
6357
+ });
6358
+ const iter = await level.iterator({
6359
+ keyEncoding: "binary",
6360
+ valueEncoding: "binary"
6361
+ });
6362
+ let count = 0;
6363
+ for await (const [key, value] of iter) {
6364
+ archive.storage.push({
6365
+ type: ProfileArchiveEntryType.KEY_VALUE,
6366
+ key,
6367
+ value
6368
+ });
6369
+ count++;
6370
+ }
6371
+ log20.info("done exporting kv pairs", {
6372
+ count
6373
+ }, {
6374
+ F: __dxlog_file23,
6375
+ L: 56,
6376
+ S: void 0,
6377
+ C: (f, a) => f(...a)
6378
+ });
6379
+ }
6380
+ return archive;
6381
+ };
6382
+ var importProfileData = async ({ storage, level }, archive) => {
6383
+ let batch = level.batch();
6384
+ let count = 0;
6385
+ for (const entry2 of archive.storage) {
6386
+ switch (entry2.type) {
6387
+ case ProfileArchiveEntryType.FILE: {
6388
+ const directory = await storage.createDirectory();
6389
+ invariant17(typeof entry2.key === "string", "Invalid key type", {
6390
+ F: __dxlog_file23,
6391
+ L: 79,
6392
+ S: void 0,
6393
+ A: [
6394
+ "typeof entry.key === 'string'",
6395
+ "'Invalid key type'"
6396
+ ]
6397
+ });
6398
+ const file = await directory.getOrCreateFile(entry2.key);
6399
+ invariant17(entry2.value instanceof Uint8Array, "Invalid value type", {
6400
+ F: __dxlog_file23,
6401
+ L: 81,
6402
+ S: void 0,
6403
+ A: [
6404
+ "entry.value instanceof Uint8Array",
6405
+ "'Invalid value type'"
6406
+ ]
6407
+ });
6408
+ await file.write(0, arrayToBuffer(entry2.value));
6409
+ await file.close();
6410
+ break;
6411
+ }
6412
+ case ProfileArchiveEntryType.KEY_VALUE: {
6413
+ invariant17(entry2.key instanceof Uint8Array, "Invalid key type", {
6414
+ F: __dxlog_file23,
6415
+ L: 87,
6416
+ S: void 0,
6417
+ A: [
6418
+ "entry.key instanceof Uint8Array",
6419
+ "'Invalid key type'"
6420
+ ]
6421
+ });
6422
+ invariant17(entry2.value instanceof Uint8Array, "Invalid value type", {
6423
+ F: __dxlog_file23,
6424
+ L: 88,
6425
+ S: void 0,
6426
+ A: [
6427
+ "entry.value instanceof Uint8Array",
6428
+ "'Invalid value type'"
6429
+ ]
6430
+ });
6431
+ batch.put(entry2.key, entry2.value, {
6432
+ keyEncoding: "binary",
6433
+ valueEncoding: "binary"
6434
+ });
6435
+ break;
6436
+ }
6437
+ default:
6438
+ throw new Error(`Invalid entry type: ${entry2.type}`);
6439
+ }
6440
+ if (++count % 1e3 === 0) {
6441
+ await batch.write();
6442
+ batch = level.batch();
6443
+ log20.info("importing", {
6444
+ count,
6445
+ total: archive.storage.length,
6446
+ progress: `${(count / archive.storage.length * 100).toFixed()}%`
6447
+ }, {
6448
+ F: __dxlog_file23,
6449
+ L: 101,
6450
+ S: void 0,
6451
+ C: (f, a) => f(...a)
6452
+ });
6453
+ }
6454
+ }
6455
+ log20.info("committing changes..", void 0, {
6456
+ F: __dxlog_file23,
6457
+ L: 109,
6458
+ S: void 0,
6459
+ C: (f, a) => f(...a)
6460
+ });
6461
+ await batch.write();
6462
+ };
6463
+
6270
6464
  // packages/sdk/client-services/src/packlets/services/service-host.ts
6271
6465
  import { Event as Event9, synchronized as synchronized3 } from "@dxos/async";
6272
6466
  import { clientServiceBundle } from "@dxos/client-protocol";
6273
6467
  import { Context as Context11 } from "@dxos/context";
6274
- import { invariant as invariant18 } from "@dxos/invariant";
6468
+ import { invariant as invariant19 } from "@dxos/invariant";
6275
6469
  import { PublicKey as PublicKey17 } from "@dxos/keys";
6276
- import { log as log21 } from "@dxos/log";
6470
+ import { log as log22 } from "@dxos/log";
6277
6471
  import { WebsocketSignalManager } from "@dxos/messaging";
6278
6472
  import { SwarmNetworkManager, createSimplePeerTransportFactory } from "@dxos/network-manager";
6279
6473
  import { trace as trace10 } from "@dxos/protocols";
@@ -6284,9 +6478,9 @@ import { WebsocketRpcClient } from "@dxos/websocket-rpc";
6284
6478
  // packages/sdk/client-services/src/packlets/devices/devices-service.ts
6285
6479
  import { EventSubscriptions as EventSubscriptions3 } from "@dxos/async";
6286
6480
  import { Stream as Stream11 } from "@dxos/codec-protobuf";
6287
- import { invariant as invariant17 } from "@dxos/invariant";
6481
+ import { invariant as invariant18 } from "@dxos/invariant";
6288
6482
  import { Device as Device2, DeviceKind as DeviceKind2 } from "@dxos/protocols/proto/dxos/client/services";
6289
- var __dxlog_file23 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
6483
+ var __dxlog_file24 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
6290
6484
  var DevicesServiceImpl = class {
6291
6485
  constructor(_identityManager) {
6292
6486
  this._identityManager = _identityManager;
@@ -6303,8 +6497,8 @@ var DevicesServiceImpl = class {
6303
6497
  devices: []
6304
6498
  });
6305
6499
  } else {
6306
- invariant17(this._identityManager.identity?.presence, "presence not present", {
6307
- F: __dxlog_file23,
6500
+ invariant18(this._identityManager.identity?.presence, "presence not present", {
6501
+ F: __dxlog_file24,
6308
6502
  L: 32,
6309
6503
  S: this,
6310
6504
  A: [
@@ -6497,7 +6691,7 @@ var ContactsServiceImpl = class {
6497
6691
  import { Event as Event8 } from "@dxos/async";
6498
6692
  import { Stream as Stream13 } from "@dxos/codec-protobuf";
6499
6693
  import { PublicKey as PublicKey16 } from "@dxos/keys";
6500
- import { getContextFromEntry, log as log20 } from "@dxos/log";
6694
+ import { getContextFromEntry, log as log21 } from "@dxos/log";
6501
6695
  import { QueryLogsRequest } from "@dxos/protocols/proto/dxos/client/services";
6502
6696
  import { getDebugName, jsonify, numericalValues, tracer } from "@dxos/util";
6503
6697
  var LoggingServiceImpl = class {
@@ -6510,11 +6704,11 @@ var LoggingServiceImpl = class {
6510
6704
  };
6511
6705
  }
6512
6706
  async open() {
6513
- log20.runtimeConfig.processors.push(this._logProcessor);
6707
+ log21.runtimeConfig.processors.push(this._logProcessor);
6514
6708
  }
6515
6709
  async close() {
6516
- const index = log20.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
6517
- log20.runtimeConfig.processors.splice(index, 1);
6710
+ const index = log21.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
6711
+ log21.runtimeConfig.processors.splice(index, 1);
6518
6712
  }
6519
6713
  async controlMetrics({ reset, record }) {
6520
6714
  if (reset) {
@@ -6718,7 +6912,7 @@ function _ts_decorate8(decorators, target, key, desc) {
6718
6912
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6719
6913
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6720
6914
  }
6721
- var __dxlog_file24 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
6915
+ var __dxlog_file25 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
6722
6916
  var ClientServicesHost = class {
6723
6917
  constructor({
6724
6918
  config,
@@ -6752,7 +6946,7 @@ var ClientServicesHost = class {
6752
6946
  onAcquire: () => {
6753
6947
  if (!this._opening) {
6754
6948
  void this.open(new Context11(void 0, {
6755
- F: __dxlog_file24,
6949
+ F: __dxlog_file25,
6756
6950
  L: 121
6757
6951
  }));
6758
6952
  }
@@ -6809,8 +7003,8 @@ var ClientServicesHost = class {
6809
7003
  * Can only be called once.
6810
7004
  */
6811
7005
  initialize({ config, ...options }) {
6812
- invariant18(!this._open, "service host is open", {
6813
- F: __dxlog_file24,
7006
+ invariant19(!this._open, "service host is open", {
7007
+ F: __dxlog_file25,
6814
7008
  L: 187,
6815
7009
  S: this,
6816
7010
  A: [
@@ -6818,15 +7012,15 @@ var ClientServicesHost = class {
6818
7012
  "'service host is open'"
6819
7013
  ]
6820
7014
  });
6821
- log21("initializing...", void 0, {
6822
- F: __dxlog_file24,
7015
+ log22("initializing...", void 0, {
7016
+ F: __dxlog_file25,
6823
7017
  L: 188,
6824
7018
  S: this,
6825
7019
  C: (f, a) => f(...a)
6826
7020
  });
6827
7021
  if (config) {
6828
- invariant18(!this._config, "config already set", {
6829
- F: __dxlog_file24,
7022
+ invariant19(!this._config, "config already set", {
7023
+ F: __dxlog_file25,
6830
7024
  L: 191,
6831
7025
  S: this,
6832
7026
  A: [
@@ -6840,8 +7034,8 @@ var ClientServicesHost = class {
6840
7034
  }
6841
7035
  }
6842
7036
  if (!options.signalManager) {
6843
- log21.warn("running signaling without telemetry metadata.", void 0, {
6844
- F: __dxlog_file24,
7037
+ log22.warn("running signaling without telemetry metadata.", void 0, {
7038
+ F: __dxlog_file25,
6845
7039
  L: 199,
6846
7040
  S: this,
6847
7041
  C: (f, a) => f(...a)
@@ -6851,8 +7045,8 @@ var ClientServicesHost = class {
6851
7045
  iceServers: this._config?.get("runtime.services.ice")
6852
7046
  }), signalManager = new WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
6853
7047
  this._signalManager = signalManager;
6854
- invariant18(!this._networkManager, "network manager already set", {
6855
- F: __dxlog_file24,
7048
+ invariant19(!this._networkManager, "network manager already set", {
7049
+ F: __dxlog_file25,
6856
7050
  L: 210,
6857
7051
  S: this,
6858
7052
  A: [
@@ -6865,8 +7059,8 @@ var ClientServicesHost = class {
6865
7059
  transportFactory,
6866
7060
  signalManager
6867
7061
  });
6868
- log21("initialized", void 0, {
6869
- F: __dxlog_file24,
7062
+ log22("initialized", void 0, {
7063
+ F: __dxlog_file25,
6870
7064
  L: 217,
6871
7065
  S: this,
6872
7066
  C: (f, a) => f(...a)
@@ -6877,16 +7071,16 @@ var ClientServicesHost = class {
6877
7071
  return;
6878
7072
  }
6879
7073
  const traceId = PublicKey17.random().toHex();
6880
- log21.trace("dxos.client-services.host.open", trace10.begin({
7074
+ log22.trace("dxos.client-services.host.open", trace10.begin({
6881
7075
  id: traceId
6882
7076
  }), {
6883
- F: __dxlog_file24,
7077
+ F: __dxlog_file25,
6884
7078
  L: 228,
6885
7079
  S: this,
6886
7080
  C: (f, a) => f(...a)
6887
7081
  });
6888
- invariant18(this._config, "config not set", {
6889
- F: __dxlog_file24,
7082
+ invariant19(this._config, "config not set", {
7083
+ F: __dxlog_file25,
6890
7084
  L: 230,
6891
7085
  S: this,
6892
7086
  A: [
@@ -6894,8 +7088,8 @@ var ClientServicesHost = class {
6894
7088
  "'config not set'"
6895
7089
  ]
6896
7090
  });
6897
- invariant18(this._storage, "storage not set", {
6898
- F: __dxlog_file24,
7091
+ invariant19(this._storage, "storage not set", {
7092
+ F: __dxlog_file25,
6899
7093
  L: 231,
6900
7094
  S: this,
6901
7095
  A: [
@@ -6903,8 +7097,8 @@ var ClientServicesHost = class {
6903
7097
  "'storage not set'"
6904
7098
  ]
6905
7099
  });
6906
- invariant18(this._signalManager, "signal manager not set", {
6907
- F: __dxlog_file24,
7100
+ invariant19(this._signalManager, "signal manager not set", {
7101
+ F: __dxlog_file25,
6908
7102
  L: 232,
6909
7103
  S: this,
6910
7104
  A: [
@@ -6912,8 +7106,8 @@ var ClientServicesHost = class {
6912
7106
  "'signal manager not set'"
6913
7107
  ]
6914
7108
  });
6915
- invariant18(this._networkManager, "network manager not set", {
6916
- F: __dxlog_file24,
7109
+ invariant19(this._networkManager, "network manager not set", {
7110
+ F: __dxlog_file25,
6917
7111
  L: 233,
6918
7112
  S: this,
6919
7113
  A: [
@@ -6922,10 +7116,10 @@ var ClientServicesHost = class {
6922
7116
  ]
6923
7117
  });
6924
7118
  this._opening = true;
6925
- log21("opening...", {
7119
+ log22("opening...", {
6926
7120
  lockKey: this._resourceLock?.lockKey
6927
7121
  }, {
6928
- F: __dxlog_file24,
7122
+ F: __dxlog_file25,
6929
7123
  L: 236,
6930
7124
  S: this,
6931
7125
  C: (f, a) => f(...a)
@@ -6978,18 +7172,18 @@ var ClientServicesHost = class {
6978
7172
  this._open = true;
6979
7173
  this._statusUpdate.emit();
6980
7174
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
6981
- log21("opened", {
7175
+ log22("opened", {
6982
7176
  deviceKey
6983
7177
  }, {
6984
- F: __dxlog_file24,
7178
+ F: __dxlog_file25,
6985
7179
  L: 322,
6986
7180
  S: this,
6987
7181
  C: (f, a) => f(...a)
6988
7182
  });
6989
- log21.trace("dxos.client-services.host.open", trace10.end({
7183
+ log22.trace("dxos.client-services.host.open", trace10.end({
6990
7184
  id: traceId
6991
7185
  }), {
6992
- F: __dxlog_file24,
7186
+ F: __dxlog_file25,
6993
7187
  L: 323,
6994
7188
  S: this,
6995
7189
  C: (f, a) => f(...a)
@@ -7000,10 +7194,10 @@ var ClientServicesHost = class {
7000
7194
  return;
7001
7195
  }
7002
7196
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
7003
- log21("closing...", {
7197
+ log22("closing...", {
7004
7198
  deviceKey
7005
7199
  }, {
7006
- F: __dxlog_file24,
7200
+ F: __dxlog_file25,
7007
7201
  L: 334,
7008
7202
  S: this,
7009
7203
  C: (f, a) => f(...a)
@@ -7018,10 +7212,10 @@ var ClientServicesHost = class {
7018
7212
  await this._level?.close();
7019
7213
  this._open = false;
7020
7214
  this._statusUpdate.emit();
7021
- log21("closed", {
7215
+ log22("closed", {
7022
7216
  deviceKey
7023
7217
  }, {
7024
- F: __dxlog_file24,
7218
+ F: __dxlog_file25,
7025
7219
  L: 343,
7026
7220
  S: this,
7027
7221
  C: (f, a) => f(...a)
@@ -7029,32 +7223,32 @@ var ClientServicesHost = class {
7029
7223
  }
7030
7224
  async reset() {
7031
7225
  const traceId = PublicKey17.random().toHex();
7032
- log21.trace("dxos.sdk.client-services-host.reset", trace10.begin({
7226
+ log22.trace("dxos.sdk.client-services-host.reset", trace10.begin({
7033
7227
  id: traceId
7034
7228
  }), {
7035
- F: __dxlog_file24,
7229
+ F: __dxlog_file25,
7036
7230
  L: 348,
7037
7231
  S: this,
7038
7232
  C: (f, a) => f(...a)
7039
7233
  });
7040
- log21.info("resetting...", void 0, {
7041
- F: __dxlog_file24,
7234
+ log22.info("resetting...", void 0, {
7235
+ F: __dxlog_file25,
7042
7236
  L: 350,
7043
7237
  S: this,
7044
7238
  C: (f, a) => f(...a)
7045
7239
  });
7046
7240
  await this._serviceContext?.close();
7047
7241
  await this._storage.reset();
7048
- log21.info("reset", void 0, {
7049
- F: __dxlog_file24,
7242
+ log22.info("reset", void 0, {
7243
+ F: __dxlog_file25,
7050
7244
  L: 353,
7051
7245
  S: this,
7052
7246
  C: (f, a) => f(...a)
7053
7247
  });
7054
- log21.trace("dxos.sdk.client-services-host.reset", trace10.end({
7248
+ log22.trace("dxos.sdk.client-services-host.reset", trace10.end({
7055
7249
  id: traceId
7056
7250
  }), {
7057
- F: __dxlog_file24,
7251
+ F: __dxlog_file25,
7058
7252
  L: 354,
7059
7253
  S: this,
7060
7254
  C: (f, a) => f(...a)
@@ -7121,8 +7315,12 @@ export {
7121
7315
  isLocked,
7122
7316
  createStorageObjects,
7123
7317
  createLevel,
7318
+ encodeProfileArchive,
7319
+ decodeProfileArchive,
7320
+ exportProfileData,
7321
+ importProfileData,
7124
7322
  ClientServicesHost,
7125
7323
  ClientServicesProviderResource,
7126
7324
  DiagnosticsCollector
7127
7325
  };
7128
- //# sourceMappingURL=chunk-Y4NGEDFZ.mjs.map
7326
+ //# sourceMappingURL=chunk-ZWYYPM2X.mjs.map