@dxos/client-services 0.5.9-main.1cc8373 → 0.5.9-main.1f2bcac

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.
@@ -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.1cc8373";
362
+ var DXOS_VERSION = "0.5.9-main.1f2bcac";
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();
@@ -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,
@@ -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
  }));
@@ -6070,7 +6104,7 @@ var ServiceRegistry = class {
6070
6104
  };
6071
6105
 
6072
6106
  // packages/sdk/client-services/src/packlets/locks/browser.ts
6073
- import { asyncTimeout as asyncTimeout3, Trigger as Trigger9 } from "@dxos/async";
6107
+ import { asyncTimeout as asyncTimeout2, Trigger as Trigger9 } from "@dxos/async";
6074
6108
  import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
6075
6109
  import { log as log19, logInfo } from "@dxos/log";
6076
6110
  function _ts_decorate7(decorators, target, key, desc) {
@@ -6111,7 +6145,7 @@ var Lock = class {
6111
6145
  S: this,
6112
6146
  C: (f, a) => f(...a)
6113
6147
  });
6114
- await asyncTimeout3(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
6148
+ await asyncTimeout2(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
6115
6149
  log19("acquired lock", void 0, {
6116
6150
  F: __dxlog_file22,
6117
6151
  L: 44,
@@ -6345,14 +6379,15 @@ var exportProfileData = async ({ storage, level }) => {
6345
6379
  return archive;
6346
6380
  };
6347
6381
  var importProfileData = async ({ storage, level }, archive) => {
6348
- const batch = level.batch();
6382
+ let batch = level.batch();
6383
+ let count = 0;
6349
6384
  for (const entry2 of archive.storage) {
6350
6385
  switch (entry2.type) {
6351
6386
  case ProfileArchiveEntryType.FILE: {
6352
6387
  const directory = await storage.createDirectory();
6353
6388
  invariant17(typeof entry2.key === "string", "Invalid key type", {
6354
6389
  F: __dxlog_file23,
6355
- L: 78,
6390
+ L: 79,
6356
6391
  S: void 0,
6357
6392
  A: [
6358
6393
  "typeof entry.key === 'string'",
@@ -6362,7 +6397,7 @@ var importProfileData = async ({ storage, level }, archive) => {
6362
6397
  const file = await directory.getOrCreateFile(entry2.key);
6363
6398
  invariant17(entry2.value instanceof Uint8Array, "Invalid value type", {
6364
6399
  F: __dxlog_file23,
6365
- L: 80,
6400
+ L: 81,
6366
6401
  S: void 0,
6367
6402
  A: [
6368
6403
  "entry.value instanceof Uint8Array",
@@ -6376,7 +6411,7 @@ var importProfileData = async ({ storage, level }, archive) => {
6376
6411
  case ProfileArchiveEntryType.KEY_VALUE: {
6377
6412
  invariant17(entry2.key instanceof Uint8Array, "Invalid key type", {
6378
6413
  F: __dxlog_file23,
6379
- L: 86,
6414
+ L: 87,
6380
6415
  S: void 0,
6381
6416
  A: [
6382
6417
  "entry.key instanceof Uint8Array",
@@ -6385,7 +6420,7 @@ var importProfileData = async ({ storage, level }, archive) => {
6385
6420
  });
6386
6421
  invariant17(entry2.value instanceof Uint8Array, "Invalid value type", {
6387
6422
  F: __dxlog_file23,
6388
- L: 87,
6423
+ L: 88,
6389
6424
  S: void 0,
6390
6425
  A: [
6391
6426
  "entry.value instanceof Uint8Array",
@@ -6401,7 +6436,27 @@ var importProfileData = async ({ storage, level }, archive) => {
6401
6436
  default:
6402
6437
  throw new Error(`Invalid entry type: ${entry2.type}`);
6403
6438
  }
6439
+ if (++count % 1e3 === 0) {
6440
+ await batch.write();
6441
+ batch = level.batch();
6442
+ log20.info("importing", {
6443
+ count,
6444
+ total: archive.storage.length,
6445
+ progress: `${(count / archive.storage.length * 100).toFixed()}%`
6446
+ }, {
6447
+ F: __dxlog_file23,
6448
+ L: 101,
6449
+ S: void 0,
6450
+ C: (f, a) => f(...a)
6451
+ });
6452
+ }
6404
6453
  }
6454
+ log20.info("committing changes..", void 0, {
6455
+ F: __dxlog_file23,
6456
+ L: 109,
6457
+ S: void 0,
6458
+ C: (f, a) => f(...a)
6459
+ });
6405
6460
  await batch.write();
6406
6461
  };
6407
6462
 
@@ -7267,4 +7322,4 @@ export {
7267
7322
  ClientServicesProviderResource,
7268
7323
  DiagnosticsCollector
7269
7324
  };
7270
- //# sourceMappingURL=chunk-W55ZOE2M.mjs.map
7325
+ //# sourceMappingURL=chunk-LAXUVAKD.mjs.map