@dxos/client-services 0.5.9-main.5d79202 → 0.5.9-main.6030c93

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 (33) hide show
  1. package/dist/lib/browser/{chunk-EKD7OOMO.mjs → chunk-WC3HHHUZ.mjs} +571 -439
  2. package/dist/lib/browser/chunk-WC3HHHUZ.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +1 -3
  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-Q4HUMNZ3.cjs → chunk-TWLCVZQI.cjs} +677 -548
  8. package/dist/lib/node/chunk-TWLCVZQI.cjs.map +7 -0
  9. package/dist/lib/node/index.cjs +41 -43
  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/automerge-space-state.d.ts +4 -1
  15. package/dist/types/src/packlets/spaces/automerge-space-state.d.ts.map +1 -1
  16. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  17. package/dist/types/src/packlets/spaces/data-space.d.ts +9 -9
  18. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  19. package/dist/types/src/packlets/spaces/epoch-migrations.d.ts +23 -0
  20. package/dist/types/src/packlets/spaces/epoch-migrations.d.ts.map +1 -0
  21. package/dist/types/src/packlets/spaces/spaces-service.d.ts +2 -2
  22. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  23. package/dist/types/src/version.d.ts +1 -1
  24. package/package.json +36 -36
  25. package/src/packlets/identity/identity-service.ts +6 -1
  26. package/src/packlets/spaces/automerge-space-state.ts +11 -2
  27. package/src/packlets/spaces/data-space-manager.ts +35 -14
  28. package/src/packlets/spaces/data-space.ts +73 -145
  29. package/src/packlets/spaces/epoch-migrations.ts +135 -0
  30. package/src/packlets/spaces/spaces-service.ts +4 -2
  31. package/src/version.ts +1 -1
  32. package/dist/lib/browser/chunk-EKD7OOMO.mjs.map +0 -7
  33. package/dist/lib/node/chunk-Q4HUMNZ3.cjs.map +0 -7
@@ -355,7 +355,7 @@ import { SpaceMember } from "@dxos/protocols/proto/dxos/client/services";
355
355
  import { TRACE_PROCESSOR } from "@dxos/tracing";
356
356
 
357
357
  // packages/sdk/client-services/src/version.ts
358
- var DXOS_VERSION = "0.5.9-main.5d79202";
358
+ var DXOS_VERSION = "0.5.9-main.6030c93";
359
359
 
360
360
  // packages/sdk/client-services/src/packlets/services/platform.ts
361
361
  import { Platform } from "@dxos/protocols/proto/dxos/client/services";
@@ -1624,7 +1624,11 @@ var IdentityServiceImpl = class extends Resource {
1624
1624
  for (const space of dataSpaceManager.spaces.values()) {
1625
1625
  if (space.state === SpaceState.CLOSED) {
1626
1626
  await space.open();
1627
- await space.initializeDataPipeline();
1627
+ const requiresMigration = space.stateUpdate.waitForCondition(() => space.state === SpaceState.REQUIRES_MIGRATION);
1628
+ await Promise.race([
1629
+ space.initializeDataPipeline(),
1630
+ requiresMigration
1631
+ ]);
1628
1632
  }
1629
1633
  if (await dataSpaceManager.isDefaultSpace(space)) {
1630
1634
  await identity.updateDefaultSpace(space.id);
@@ -3683,33 +3687,40 @@ var InvitationsManager = class {
3683
3687
  };
3684
3688
 
3685
3689
  // packages/sdk/client-services/src/packlets/spaces/data-space.ts
3686
- import { Event as Event6, asyncTimeout as asyncTimeout2, scheduleTask as scheduleTask5, sleep as sleep2, synchronized, trackLeaks } from "@dxos/async";
3690
+ import { Event as Event6, Mutex as Mutex2, scheduleTask as scheduleTask5, sleep as sleep2, synchronized, trackLeaks } from "@dxos/async";
3687
3691
  import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
3688
- import { Context as Context8, ContextDisposedError as ContextDisposedError3, cancelWithContext as cancelWithContext4 } from "@dxos/context";
3692
+ import { Context as Context8, ContextDisposedError as ContextDisposedError3, cancelWithContext as cancelWithContext5 } from "@dxos/context";
3689
3693
  import { timed, warnAfterTimeout } from "@dxos/debug";
3690
- import { AutomergeDocumentLoaderImpl, createIdFromSpaceKey, createMappedFeedWriter } from "@dxos/echo-pipeline";
3691
- import { TYPE_PROPERTIES } from "@dxos/echo-schema";
3692
- import { failedInvariant, invariant as invariant13 } from "@dxos/invariant";
3694
+ import { createMappedFeedWriter } from "@dxos/echo-pipeline";
3695
+ import { SpaceDocVersion } from "@dxos/echo-protocol";
3696
+ import { failedInvariant } from "@dxos/invariant";
3693
3697
  import { PublicKey as PublicKey10 } from "@dxos/keys";
3694
- import { log as log13 } from "@dxos/log";
3698
+ import { log as log14 } from "@dxos/log";
3695
3699
  import { CancelledError, SystemError } from "@dxos/protocols";
3696
- import { CreateEpochRequest, SpaceState as SpaceState2 } from "@dxos/protocols/proto/dxos/client/services";
3700
+ import { SpaceState as SpaceState2 } from "@dxos/protocols/proto/dxos/client/services";
3697
3701
  import { AdmittedFeed as AdmittedFeed3, SpaceMember as SpaceMember4 } from "@dxos/protocols/proto/dxos/halo/credentials";
3698
3702
  import { Timeframe as Timeframe3 } from "@dxos/timeframe";
3699
3703
  import { trace as trace6 } from "@dxos/tracing";
3700
- import { ComplexSet as ComplexSet5, assignDeep } from "@dxos/util";
3704
+ import { ComplexSet as ComplexSet5 } from "@dxos/util";
3701
3705
 
3702
3706
  // packages/sdk/client-services/src/packlets/spaces/automerge-space-state.ts
3703
3707
  import { Event as Event4 } from "@dxos/async";
3708
+ import { Resource as Resource2 } from "@dxos/context";
3704
3709
  import { checkCredentialType } from "@dxos/credentials";
3705
- var AutomergeSpaceState = class {
3710
+ var AutomergeSpaceState = class extends Resource2 {
3706
3711
  constructor(_onNewRoot) {
3712
+ super();
3707
3713
  this._onNewRoot = _onNewRoot;
3708
3714
  this.rootUrl = void 0;
3709
3715
  this.lastEpoch = void 0;
3710
3716
  this.onNewEpoch = new Event4();
3711
3717
  this._isProcessingRootDocs = false;
3712
3718
  }
3719
+ async _open(ctx) {
3720
+ }
3721
+ async _close(ctx) {
3722
+ this._isProcessingRootDocs = false;
3723
+ }
3713
3724
  async processCredential(credential) {
3714
3725
  if (!checkCredentialType(credential, "dxos.halo.credentials.Epoch")) {
3715
3726
  return;
@@ -3737,16 +3748,162 @@ var AutomergeSpaceState = class {
3737
3748
  }
3738
3749
  };
3739
3750
 
3751
+ // packages/sdk/client-services/src/packlets/spaces/epoch-migrations.ts
3752
+ import { asyncTimeout as asyncTimeout2 } from "@dxos/async";
3753
+ import { next as am } from "@dxos/automerge/automerge";
3754
+ import { cancelWithContext as cancelWithContext4 } from "@dxos/context";
3755
+ import { convertLegacyReferences, convertLegacySpaceRootDoc, findInlineObjectOfType, migrateDocument } from "@dxos/echo-db";
3756
+ import { AutomergeDocumentLoaderImpl } from "@dxos/echo-pipeline";
3757
+ import { TYPE_PROPERTIES } from "@dxos/echo-schema";
3758
+ import { invariant as invariant12 } from "@dxos/invariant";
3759
+ import { log as log12 } from "@dxos/log";
3760
+ import { CreateEpochRequest } from "@dxos/protocols/proto/dxos/client/services";
3761
+ import { assignDeep } from "@dxos/util";
3762
+ var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/epoch-migrations.ts";
3763
+ var runEpochMigration = async (ctx, context) => {
3764
+ switch (context.migration) {
3765
+ case CreateEpochRequest.Migration.INIT_AUTOMERGE: {
3766
+ const document = context.repo.create();
3767
+ await context.repo.flush();
3768
+ return {
3769
+ newRoot: document.url
3770
+ };
3771
+ }
3772
+ case CreateEpochRequest.Migration.PRUNE_AUTOMERGE_ROOT_HISTORY: {
3773
+ if (!context.currentRoot) {
3774
+ throw new Error("Space does not have an automerge root");
3775
+ }
3776
+ const rootHandle = context.repo.find(context.currentRoot);
3777
+ await cancelWithContext4(ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
3778
+ const newRoot = context.repo.create(rootHandle.docSync());
3779
+ await context.repo.flush();
3780
+ return {
3781
+ newRoot: newRoot.url
3782
+ };
3783
+ }
3784
+ case CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT: {
3785
+ log12.info("Fragmenting", void 0, {
3786
+ F: __dxlog_file15,
3787
+ L: 63,
3788
+ S: void 0,
3789
+ C: (f, a) => f(...a)
3790
+ });
3791
+ const currentRootUrl = context.currentRoot;
3792
+ const rootHandle = context.repo.find(currentRootUrl);
3793
+ await cancelWithContext4(ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
3794
+ const objects = Object.entries(rootHandle.docSync().objects);
3795
+ const properties = findInlineObjectOfType(rootHandle.docSync(), TYPE_PROPERTIES);
3796
+ const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
3797
+ invariant12(properties, "Properties not found", {
3798
+ F: __dxlog_file15,
3799
+ L: 73,
3800
+ S: void 0,
3801
+ A: [
3802
+ "properties",
3803
+ "'Properties not found'"
3804
+ ]
3805
+ });
3806
+ const newSpaceDoc = {
3807
+ ...rootHandle.docSync(),
3808
+ objects: Object.fromEntries([
3809
+ properties
3810
+ ])
3811
+ };
3812
+ const newRoot = context.repo.create(newSpaceDoc);
3813
+ invariant12(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3814
+ F: __dxlog_file15,
3815
+ L: 78,
3816
+ S: void 0,
3817
+ A: [
3818
+ "typeof newRoot.url === 'string' && newRoot.url.length > 0",
3819
+ ""
3820
+ ]
3821
+ });
3822
+ const docLoader = new AutomergeDocumentLoaderImpl(context.spaceId, context.repo, context.spaceKey);
3823
+ await docLoader.loadSpaceRootDocHandle(ctx, {
3824
+ rootUrl: newRoot.url
3825
+ });
3826
+ otherObjects.forEach(([key, value]) => {
3827
+ const handle = docLoader.createDocumentForObject(key);
3828
+ handle.change((doc) => {
3829
+ assignDeep(doc, [
3830
+ "objects",
3831
+ key
3832
+ ], value);
3833
+ });
3834
+ });
3835
+ await context.repo.flush();
3836
+ return {
3837
+ newRoot: newRoot.url
3838
+ };
3839
+ }
3840
+ case CreateEpochRequest.Migration.MIGRATE_REFERENCES_TO_DXN: {
3841
+ const currentRootUrl = context.currentRoot;
3842
+ const rootHandle = context.repo.find(currentRootUrl);
3843
+ await cancelWithContext4(ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
3844
+ invariant12(rootHandle.docSync(), "Root doc not found", {
3845
+ F: __dxlog_file15,
3846
+ L: 100,
3847
+ S: void 0,
3848
+ A: [
3849
+ "rootHandle.docSync()",
3850
+ "'Root doc not found'"
3851
+ ]
3852
+ });
3853
+ const newRootContent = await convertLegacySpaceRootDoc(structuredClone(rootHandle.docSync()));
3854
+ for (const [id, url] of Object.entries(newRootContent.links ?? {})) {
3855
+ const handle = context.repo.find(url);
3856
+ await cancelWithContext4(ctx, asyncTimeout2(handle.whenReady(), 1e4));
3857
+ invariant12(handle.docSync(), "Doc not found", {
3858
+ F: __dxlog_file15,
3859
+ L: 107,
3860
+ S: void 0,
3861
+ A: [
3862
+ "handle.docSync()",
3863
+ "'Doc not found'"
3864
+ ]
3865
+ });
3866
+ const newDoc = await convertLegacyReferences(structuredClone(handle.docSync()));
3867
+ const migratedDoc = migrateDocument(handle.docSync(), newDoc);
3868
+ const newHandle = context.repo.import(am.save(migratedDoc));
3869
+ newRootContent.links[id] = newHandle.url;
3870
+ }
3871
+ const migratedRoot = migrateDocument(rootHandle.docSync(), newRootContent);
3872
+ const newRoot = context.repo.import(am.save(migratedRoot));
3873
+ await context.repo.flush();
3874
+ return {
3875
+ newRoot: newRoot.url
3876
+ };
3877
+ }
3878
+ case CreateEpochRequest.Migration.REPLACE_AUTOMERGE_ROOT: {
3879
+ invariant12(context.newAutomergeRoot, void 0, {
3880
+ F: __dxlog_file15,
3881
+ L: 124,
3882
+ S: void 0,
3883
+ A: [
3884
+ "context.newAutomergeRoot",
3885
+ ""
3886
+ ]
3887
+ });
3888
+ await context.repo.flush();
3889
+ return {
3890
+ newRoot: context.newAutomergeRoot
3891
+ };
3892
+ }
3893
+ }
3894
+ return {};
3895
+ };
3896
+
3740
3897
  // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
3741
3898
  import { DeferredTask, Event as Event5, scheduleTask as scheduleTask4, sleep, TimeoutError as TimeoutError3, Trigger as Trigger6 } from "@dxos/async";
3742
3899
  import { Context as Context7, rejectOnDispose } from "@dxos/context";
3743
- import { invariant as invariant12 } from "@dxos/invariant";
3900
+ import { invariant as invariant13 } from "@dxos/invariant";
3744
3901
  import { PublicKey as PublicKey9 } from "@dxos/keys";
3745
- import { log as log12 } from "@dxos/log";
3902
+ import { log as log13 } from "@dxos/log";
3746
3903
  import { schema as schema4 } from "@dxos/protocols";
3747
3904
  import { RpcExtension as RpcExtension3 } from "@dxos/teleport";
3748
3905
  import { ComplexMap as ComplexMap2, ComplexSet as ComplexSet4, entry } from "@dxos/util";
3749
- var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
3906
+ var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
3750
3907
  var DEFAULT_RETRY_TIMEOUT = 1e3;
3751
3908
  var DEFAULT_SUCCESS_DELAY = 1e3;
3752
3909
  var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
@@ -3771,16 +3928,16 @@ var NotarizationPlugin = class {
3771
3928
  * Request credentials to be notarized.
3772
3929
  */
3773
3930
  async notarize({ ctx: opCtx, credentials, timeout = DEFAULT_NOTARIZE_TIMEOUT, retryTimeout = DEFAULT_RETRY_TIMEOUT, successDelay = DEFAULT_SUCCESS_DELAY }) {
3774
- log12("notarize", {
3931
+ log13("notarize", {
3775
3932
  credentials
3776
3933
  }, {
3777
- F: __dxlog_file15,
3934
+ F: __dxlog_file16,
3778
3935
  L: 90,
3779
3936
  S: this,
3780
3937
  C: (f, a) => f(...a)
3781
3938
  });
3782
- invariant12(credentials.every((credential) => credential.id), "Credentials must have an id", {
3783
- F: __dxlog_file15,
3939
+ invariant13(credentials.every((credential) => credential.id), "Credentials must have an id", {
3940
+ F: __dxlog_file16,
3784
3941
  L: 91,
3785
3942
  S: this,
3786
3943
  A: [
@@ -3791,10 +3948,10 @@ var NotarizationPlugin = class {
3791
3948
  const errors = new Trigger6();
3792
3949
  const ctx = this._ctx.derive({
3793
3950
  onError: (err) => {
3794
- log12.warn("Notarization error", {
3951
+ log13.warn("Notarization error", {
3795
3952
  err
3796
3953
  }, {
3797
- F: __dxlog_file15,
3954
+ F: __dxlog_file16,
3798
3955
  L: 99,
3799
3956
  S: this,
3800
3957
  C: (f, a) => f(...a)
@@ -3806,11 +3963,11 @@ var NotarizationPlugin = class {
3806
3963
  opCtx?.onDispose(() => ctx.dispose());
3807
3964
  if (timeout !== 0) {
3808
3965
  scheduleTask4(ctx, () => {
3809
- log12.warn("Notarization timeout", {
3966
+ log13.warn("Notarization timeout", {
3810
3967
  timeout,
3811
3968
  peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
3812
3969
  }, {
3813
- F: __dxlog_file15,
3970
+ F: __dxlog_file16,
3814
3971
  L: 111,
3815
3972
  S: this,
3816
3973
  C: (f, a) => f(...a)
@@ -3830,10 +3987,10 @@ var NotarizationPlugin = class {
3830
3987
  ...this._extensions
3831
3988
  ].find((peer2) => !peersTried.has(peer2));
3832
3989
  if (!peer) {
3833
- log12.info("Exhausted all peers to notarize with", {
3990
+ log13.info("Exhausted all peers to notarize with", {
3834
3991
  retryIn: retryTimeout
3835
3992
  }, {
3836
- F: __dxlog_file15,
3993
+ F: __dxlog_file16,
3837
3994
  L: 136,
3838
3995
  S: this,
3839
3996
  C: (f, a) => f(...a)
@@ -3843,11 +4000,11 @@ var NotarizationPlugin = class {
3843
4000
  return;
3844
4001
  }
3845
4002
  peersTried.add(peer);
3846
- log12("try notarizing", {
4003
+ log13("try notarizing", {
3847
4004
  peer: peer.localPeerId,
3848
4005
  credentialId: credentials.map((credential) => credential.id)
3849
4006
  }, {
3850
- F: __dxlog_file15,
4007
+ F: __dxlog_file16,
3851
4008
  L: 143,
3852
4009
  S: this,
3853
4010
  C: (f, a) => f(...a)
@@ -3855,8 +4012,8 @@ var NotarizationPlugin = class {
3855
4012
  await peer.rpc.NotarizationService.notarize({
3856
4013
  credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
3857
4014
  });
3858
- log12("success", void 0, {
3859
- F: __dxlog_file15,
4015
+ log13("success", void 0, {
4016
+ F: __dxlog_file16,
3860
4017
  L: 147,
3861
4018
  S: this,
3862
4019
  C: (f, a) => f(...a)
@@ -3864,8 +4021,8 @@ var NotarizationPlugin = class {
3864
4021
  await sleep(successDelay);
3865
4022
  } catch (err) {
3866
4023
  if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
3867
- log12.info("error notarizing (recoverable)", err, {
3868
- F: __dxlog_file15,
4024
+ log13.info("error notarizing (recoverable)", err, {
4025
+ F: __dxlog_file16,
3869
4026
  L: 151,
3870
4027
  S: this,
3871
4028
  C: (f, a) => f(...a)
@@ -3882,8 +4039,8 @@ var NotarizationPlugin = class {
3882
4039
  allNotarized,
3883
4040
  errors.wait()
3884
4041
  ]);
3885
- log12("done", void 0, {
3886
- F: __dxlog_file15,
4042
+ log13("done", void 0, {
4043
+ F: __dxlog_file16,
3887
4044
  L: 162,
3888
4045
  S: this,
3889
4046
  C: (f, a) => f(...a)
@@ -3904,8 +4061,8 @@ var NotarizationPlugin = class {
3904
4061
  this._processCredentialsTriggers.delete(credential.id);
3905
4062
  }
3906
4063
  setWriter(writer) {
3907
- invariant12(!this._writer, "Writer already set.", {
3908
- F: __dxlog_file15,
4064
+ invariant13(!this._writer, "Writer already set.", {
4065
+ F: __dxlog_file16,
3909
4066
  L: 181,
3910
4067
  S: this,
3911
4068
  A: [
@@ -3929,8 +4086,8 @@ var NotarizationPlugin = class {
3929
4086
  throw new Error(WRITER_NOT_SET_ERROR_CODE);
3930
4087
  }
3931
4088
  for (const credential of request.credentials ?? []) {
3932
- invariant12(credential.id, "Credential must have an id", {
3933
- F: __dxlog_file15,
4089
+ invariant13(credential.id, "Credential must have an id", {
4090
+ F: __dxlog_file16,
3934
4091
  L: 200,
3935
4092
  S: this,
3936
4093
  A: [
@@ -3947,10 +4104,10 @@ var NotarizationPlugin = class {
3947
4104
  createExtension() {
3948
4105
  const extension = new NotarizationTeleportExtension({
3949
4106
  onOpen: async () => {
3950
- log12("extension opened", {
4107
+ log13("extension opened", {
3951
4108
  peer: extension.localPeerId
3952
4109
  }, {
3953
- F: __dxlog_file15,
4110
+ F: __dxlog_file16,
3954
4111
  L: 211,
3955
4112
  S: this,
3956
4113
  C: (f, a) => f(...a)
@@ -3959,10 +4116,10 @@ var NotarizationPlugin = class {
3959
4116
  this._extensionOpened.emit();
3960
4117
  },
3961
4118
  onClose: async () => {
3962
- log12("extension closed", {
4119
+ log13("extension closed", {
3963
4120
  peer: extension.localPeerId
3964
4121
  }, {
3965
- F: __dxlog_file15,
4122
+ F: __dxlog_file16,
3966
4123
  L: 216,
3967
4124
  S: this,
3968
4125
  C: (f, a) => f(...a)
@@ -4016,7 +4173,70 @@ function _ts_decorate4(decorators, target, key, desc) {
4016
4173
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4017
4174
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4018
4175
  }
4019
- var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
4176
+ function _using_ctx() {
4177
+ var _disposeSuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed) {
4178
+ var err = new Error();
4179
+ err.name = "SuppressedError";
4180
+ err.suppressed = suppressed;
4181
+ err.error = error;
4182
+ return err;
4183
+ }, empty = {}, stack = [];
4184
+ function using(isAwait, value) {
4185
+ if (value != null) {
4186
+ if (Object(value) !== value) {
4187
+ throw new TypeError("using declarations can only be used with objects, functions, null, or undefined.");
4188
+ }
4189
+ if (isAwait) {
4190
+ var dispose = value[Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")];
4191
+ }
4192
+ if (dispose == null) {
4193
+ dispose = value[Symbol.dispose || Symbol.for("Symbol.dispose")];
4194
+ }
4195
+ if (typeof dispose !== "function") {
4196
+ throw new TypeError(`Property [Symbol.dispose] is not a function.`);
4197
+ }
4198
+ stack.push({
4199
+ v: value,
4200
+ d: dispose,
4201
+ a: isAwait
4202
+ });
4203
+ } else if (isAwait) {
4204
+ stack.push({
4205
+ d: value,
4206
+ a: isAwait
4207
+ });
4208
+ }
4209
+ return value;
4210
+ }
4211
+ return {
4212
+ e: empty,
4213
+ u: using.bind(null, false),
4214
+ a: using.bind(null, true),
4215
+ d: function() {
4216
+ var error = this.e;
4217
+ function next() {
4218
+ while (resource = stack.pop()) {
4219
+ try {
4220
+ var resource, disposalResult = resource.d && resource.d.call(resource.v);
4221
+ if (resource.a) {
4222
+ return Promise.resolve(disposalResult).then(next, err);
4223
+ }
4224
+ } catch (e) {
4225
+ return err(e);
4226
+ }
4227
+ }
4228
+ if (error !== empty)
4229
+ throw error;
4230
+ }
4231
+ function err(e) {
4232
+ error = error !== empty ? new _disposeSuppressedError(error, e) : e;
4233
+ return next();
4234
+ }
4235
+ return next();
4236
+ }
4237
+ };
4238
+ }
4239
+ var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
4020
4240
  var DataSpace = class {
4021
4241
  constructor(params) {
4022
4242
  this._ctx = new Context8();
@@ -4024,7 +4244,9 @@ var DataSpace = class {
4024
4244
  this._cache = void 0;
4025
4245
  // TODO(dmaretskyi): Move into Space?
4026
4246
  this._automergeSpaceState = new AutomergeSpaceState((rootUrl) => this._onNewAutomergeRoot(rootUrl));
4247
+ this._epochProcessingMutex = new Mutex2();
4027
4248
  this._state = SpaceState2.CLOSED;
4249
+ this._databaseRoot = null;
4028
4250
  /**
4029
4251
  * Error for _state === SpaceState.ERROR.
4030
4252
  */
@@ -4048,11 +4270,11 @@ var DataSpace = class {
4048
4270
  });
4049
4271
  this._cache = params.cache;
4050
4272
  this._state = params.initialState;
4051
- log13("new state", {
4273
+ log14("new state", {
4052
4274
  state: SpaceState2[this._state]
4053
4275
  }, {
4054
- F: __dxlog_file16,
4055
- L: 143,
4276
+ F: __dxlog_file17,
4277
+ L: 146,
4056
4278
  S: this,
4057
4279
  C: (f, a) => f(...a)
4058
4280
  });
@@ -4085,6 +4307,9 @@ var DataSpace = class {
4085
4307
  get automergeSpaceState() {
4086
4308
  return this._automergeSpaceState;
4087
4309
  }
4310
+ get databaseRoot() {
4311
+ return this._databaseRoot;
4312
+ }
4088
4313
  get _automergeInfo() {
4089
4314
  return {
4090
4315
  rootUrl: this._automergeSpaceState.rootUrl,
@@ -4101,14 +4326,15 @@ var DataSpace = class {
4101
4326
  await this._gossip.open();
4102
4327
  await this._notarizationPlugin.open();
4103
4328
  await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
4329
+ await this._automergeSpaceState.open();
4104
4330
  await this._inner.spaceState.addCredentialProcessor(this._automergeSpaceState);
4105
4331
  await this._inner.open(new Context8());
4106
4332
  this._state = SpaceState2.CONTROL_ONLY;
4107
- log13("new state", {
4333
+ log14("new state", {
4108
4334
  state: SpaceState2[this._state]
4109
4335
  }, {
4110
- F: __dxlog_file16,
4111
- L: 209,
4336
+ F: __dxlog_file17,
4337
+ L: 217,
4112
4338
  S: this,
4113
4339
  C: (f, a) => f(...a)
4114
4340
  });
@@ -4122,11 +4348,11 @@ var DataSpace = class {
4122
4348
  async _close() {
4123
4349
  await this._callbacks.beforeClose?.();
4124
4350
  this._state = SpaceState2.CLOSED;
4125
- log13("new state", {
4351
+ log14("new state", {
4126
4352
  state: SpaceState2[this._state]
4127
4353
  }, {
4128
- F: __dxlog_file16,
4129
- L: 223,
4354
+ F: __dxlog_file17,
4355
+ L: 231,
4130
4356
  S: this,
4131
4357
  C: (f, a) => f(...a)
4132
4358
  });
@@ -4135,6 +4361,7 @@ var DataSpace = class {
4135
4361
  await this.authVerifier.close();
4136
4362
  await this._inner.close();
4137
4363
  await this._inner.spaceState.removeCredentialProcessor(this._automergeSpaceState);
4364
+ await this._automergeSpaceState.close();
4138
4365
  await this._inner.spaceState.removeCredentialProcessor(this._notarizationPlugin);
4139
4366
  await this._notarizationPlugin.close();
4140
4367
  await this._presence.close();
@@ -4156,26 +4383,26 @@ var DataSpace = class {
4156
4383
  await this.initializeDataPipeline();
4157
4384
  } catch (err) {
4158
4385
  if (err instanceof CancelledError || err instanceof ContextDisposedError3) {
4159
- log13("data pipeline initialization cancelled", err, {
4160
- F: __dxlog_file16,
4161
- L: 256,
4386
+ log14("data pipeline initialization cancelled", err, {
4387
+ F: __dxlog_file17,
4388
+ L: 265,
4162
4389
  S: this,
4163
4390
  C: (f, a) => f(...a)
4164
4391
  });
4165
4392
  return;
4166
4393
  }
4167
- log13.error("Error initializing data pipeline", err, {
4168
- F: __dxlog_file16,
4169
- L: 260,
4394
+ log14.error("Error initializing data pipeline", err, {
4395
+ F: __dxlog_file17,
4396
+ L: 269,
4170
4397
  S: this,
4171
4398
  C: (f, a) => f(...a)
4172
4399
  });
4173
4400
  this._state = SpaceState2.ERROR;
4174
- log13("new state", {
4401
+ log14("new state", {
4175
4402
  state: SpaceState2[this._state]
4176
4403
  }, {
4177
- F: __dxlog_file16,
4178
- L: 262,
4404
+ F: __dxlog_file17,
4405
+ L: 271,
4179
4406
  S: this,
4180
4407
  C: (f, a) => f(...a)
4181
4408
  });
@@ -4191,31 +4418,28 @@ var DataSpace = class {
4191
4418
  throw new SystemError("Invalid operation");
4192
4419
  }
4193
4420
  this._state = SpaceState2.INITIALIZING;
4194
- log13("new state", {
4421
+ log14("new state", {
4195
4422
  state: SpaceState2[this._state]
4196
4423
  }, {
4197
- F: __dxlog_file16,
4198
- L: 278,
4424
+ F: __dxlog_file17,
4425
+ L: 287,
4199
4426
  S: this,
4200
4427
  C: (f, a) => f(...a)
4201
4428
  });
4202
4429
  await this._initializeAndReadControlPipeline();
4203
4430
  await sleep2(1);
4431
+ const ready = this.stateUpdate.waitForCondition(() => this._state === SpaceState2.READY);
4204
4432
  this._automergeSpaceState.startProcessingRootDocs();
4205
- await cancelWithContext4(this._ctx, this.automergeSpaceState.ensureEpochInitialized());
4206
- log13("data pipeline ready", void 0, {
4207
- F: __dxlog_file16,
4208
- L: 290,
4209
- S: this,
4210
- C: (f, a) => f(...a)
4211
- });
4433
+ await ready;
4434
+ }
4435
+ async _enterReadyState() {
4212
4436
  await this._callbacks.beforeReady?.();
4213
4437
  this._state = SpaceState2.READY;
4214
- log13("new state", {
4438
+ log14("new state", {
4215
4439
  state: SpaceState2[this._state]
4216
4440
  }, {
4217
- F: __dxlog_file16,
4218
- L: 294,
4441
+ F: __dxlog_file17,
4442
+ L: 306,
4219
4443
  S: this,
4220
4444
  C: (f, a) => f(...a)
4221
4445
  });
@@ -4229,9 +4453,9 @@ var DataSpace = class {
4229
4453
  });
4230
4454
  this.metrics.controlPipelineReady = /* @__PURE__ */ new Date();
4231
4455
  await this._createWritableFeeds();
4232
- log13("writable feeds created", void 0, {
4233
- F: __dxlog_file16,
4234
- L: 310,
4456
+ log14("writable feeds created", void 0, {
4457
+ F: __dxlog_file17,
4458
+ L: 322,
4235
4459
  S: this,
4236
4460
  C: (f, a) => f(...a)
4237
4461
  });
@@ -4289,12 +4513,12 @@ var DataSpace = class {
4289
4513
  }
4290
4514
  }
4291
4515
  _onNewAutomergeRoot(rootUrl) {
4292
- log13("loading automerge root doc for space", {
4516
+ log14("loading automerge root doc for space", {
4293
4517
  space: this.key,
4294
4518
  rootUrl
4295
4519
  }, {
4296
- F: __dxlog_file16,
4297
- L: 376,
4520
+ F: __dxlog_file17,
4521
+ L: 388,
4298
4522
  S: this,
4299
4523
  C: (f, a) => f(...a)
4300
4524
  });
@@ -4302,44 +4526,52 @@ var DataSpace = class {
4302
4526
  const handle = this._echoHost.automergeRepo.find(rootUrl);
4303
4527
  queueMicrotask(async () => {
4304
4528
  try {
4305
- await warnAfterTimeout(5e3, "Automerge root doc load timeout (DataSpace)", async () => {
4306
- await cancelWithContext4(this._ctx, handle.whenReady());
4307
- });
4308
- if (this._ctx.disposed) {
4309
- return;
4310
- }
4311
- const doc = handle.docSync() ?? failedInvariant();
4312
- if (!doc.access?.spaceKey) {
4313
- handle.change((doc2) => {
4314
- doc2.access = {
4315
- spaceKey: this.key.toHex()
4316
- };
4317
- });
4318
- }
4319
- if (!this._echoHost.roots.has(handle.documentId)) {
4320
- await this._echoHost.openSpaceRoot(handle.url);
4321
- } else {
4322
- log13.warn("echo database root already exists", {
4323
- space: this.key,
4324
- rootUrl
4325
- }, {
4326
- F: __dxlog_file16,
4327
- L: 403,
4328
- S: this,
4329
- C: (f, a) => f(...a)
4529
+ try {
4530
+ var _usingCtx = _using_ctx();
4531
+ await warnAfterTimeout(5e3, "Automerge root doc load timeout (DataSpace)", async () => {
4532
+ await cancelWithContext5(this._ctx, handle.whenReady());
4330
4533
  });
4534
+ if (this._ctx.disposed) {
4535
+ return;
4536
+ }
4537
+ const _guard = (
4538
+ // Ensure only one root is processed at a time.
4539
+ _usingCtx.u(await this._epochProcessingMutex.acquire())
4540
+ );
4541
+ const doc = handle.docSync() ?? failedInvariant();
4542
+ if (!doc.access?.spaceKey) {
4543
+ handle.change((doc2) => {
4544
+ doc2.access = {
4545
+ spaceKey: this.key.toHex()
4546
+ };
4547
+ });
4548
+ }
4549
+ const root = await this._echoHost.openSpaceRoot(handle.url);
4550
+ this._databaseRoot = root;
4551
+ if (root.getVersion() !== SpaceDocVersion.CURRENT) {
4552
+ this._state = SpaceState2.REQUIRES_MIGRATION;
4553
+ this.stateUpdate.emit();
4554
+ } else {
4555
+ if (this._state !== SpaceState2.READY) {
4556
+ await this._enterReadyState();
4557
+ }
4558
+ }
4559
+ } catch (_) {
4560
+ _usingCtx.e = _;
4561
+ } finally {
4562
+ _usingCtx.d();
4331
4563
  }
4332
4564
  } catch (err) {
4333
4565
  if (err instanceof ContextDisposedError3) {
4334
4566
  return;
4335
4567
  }
4336
- log13.warn("error loading automerge root doc", {
4568
+ log14.warn("error loading automerge root doc", {
4337
4569
  space: this.key,
4338
4570
  rootUrl,
4339
4571
  err
4340
4572
  }, {
4341
- F: __dxlog_file16,
4342
- L: 409,
4573
+ F: __dxlog_file17,
4574
+ L: 431,
4343
4575
  S: this,
4344
4576
  C: (f, a) => f(...a)
4345
4577
  });
@@ -4362,148 +4594,34 @@ var DataSpace = class {
4362
4594
  });
4363
4595
  }
4364
4596
  async createEpoch(options) {
4365
- let epoch;
4366
- switch (options?.migration) {
4367
- case void 0:
4368
- case CreateEpochRequest.Migration.NONE:
4369
- {
4370
- epoch = {
4371
- previousId: this._automergeSpaceState.lastEpoch?.id,
4372
- number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
4373
- timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe3(),
4374
- automergeRoot: this._automergeSpaceState.lastEpoch?.subject.assertion?.automergeRoot
4375
- };
4376
- }
4377
- break;
4378
- case CreateEpochRequest.Migration.INIT_AUTOMERGE:
4379
- {
4380
- const document = this._echoHost.automergeRepo.create();
4381
- epoch = {
4382
- previousId: this._automergeSpaceState.lastEpoch?.id,
4383
- number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
4384
- timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe3(),
4385
- automergeRoot: document.url
4386
- };
4387
- }
4388
- break;
4389
- case CreateEpochRequest.Migration.PRUNE_AUTOMERGE_ROOT_HISTORY:
4390
- {
4391
- const currentRootUrl = this._automergeSpaceState.rootUrl;
4392
- const rootHandle = this._echoHost.automergeRepo.find(currentRootUrl);
4393
- await cancelWithContext4(this._ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
4394
- const newRoot = this._echoHost.automergeRepo.create(rootHandle.docSync());
4395
- await this._echoHost.automergeRepo.flush([
4396
- newRoot.documentId
4397
- ]);
4398
- invariant13(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
4399
- F: __dxlog_file16,
4400
- L: 460,
4401
- S: this,
4402
- A: [
4403
- "typeof newRoot.url === 'string' && newRoot.url.length > 0",
4404
- ""
4405
- ]
4406
- });
4407
- epoch = {
4408
- previousId: this._automergeSpaceState.lastEpoch?.id,
4409
- number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
4410
- timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe3(),
4411
- automergeRoot: newRoot.url
4412
- };
4413
- }
4414
- break;
4415
- case CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT:
4416
- {
4417
- log13.info("Fragmenting", void 0, {
4418
- F: __dxlog_file16,
4419
- L: 472,
4420
- S: this,
4421
- C: (f, a) => f(...a)
4422
- });
4423
- const currentRootUrl = this._automergeSpaceState.rootUrl;
4424
- const rootHandle = this._echoHost.automergeRepo.find(currentRootUrl);
4425
- await cancelWithContext4(this._ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
4426
- const objects = Object.entries(rootHandle.docSync().objects);
4427
- const properties = findPropertiesObject(rootHandle.docSync());
4428
- const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
4429
- invariant13(properties, "Properties not found", {
4430
- F: __dxlog_file16,
4431
- L: 482,
4432
- S: this,
4433
- A: [
4434
- "properties",
4435
- "'Properties not found'"
4436
- ]
4437
- });
4438
- const newSpaceDoc = {
4439
- ...rootHandle.docSync(),
4440
- objects: Object.fromEntries([
4441
- properties
4442
- ])
4443
- };
4444
- const newRoot = this._echoHost.automergeRepo.create(newSpaceDoc);
4445
- invariant13(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
4446
- F: __dxlog_file16,
4447
- L: 487,
4448
- S: this,
4449
- A: [
4450
- "typeof newRoot.url === 'string' && newRoot.url.length > 0",
4451
- ""
4452
- ]
4453
- });
4454
- const docLoader = new AutomergeDocumentLoaderImpl(await createIdFromSpaceKey(this.key), this._echoHost.automergeRepo, this.key);
4455
- await docLoader.loadSpaceRootDocHandle(this._ctx, {
4456
- rootUrl: newRoot.url
4457
- });
4458
- otherObjects.forEach(([key, value]) => {
4459
- const handle = docLoader.createDocumentForObject(key);
4460
- handle.change((doc) => {
4461
- assignDeep(doc, [
4462
- "objects",
4463
- key
4464
- ], value);
4465
- });
4466
- });
4467
- epoch = {
4468
- previousId: this._automergeSpaceState.lastEpoch?.id,
4469
- number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
4470
- timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe3(),
4471
- automergeRoot: newRoot.url
4472
- };
4473
- }
4474
- break;
4475
- case CreateEpochRequest.Migration.REPLACE_AUTOMERGE_ROOT:
4476
- {
4477
- invariant13(options.newAutomergeRoot, void 0, {
4478
- F: __dxlog_file16,
4479
- L: 517,
4480
- S: this,
4481
- A: [
4482
- "options.newAutomergeRoot",
4483
- ""
4484
- ]
4485
- });
4486
- epoch = {
4487
- previousId: this._automergeSpaceState.lastEpoch?.id,
4488
- number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
4489
- timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe3(),
4490
- automergeRoot: options.newAutomergeRoot
4491
- };
4492
- }
4493
- break;
4494
- }
4495
- if (!epoch) {
4496
- return;
4597
+ const ctx = this._ctx.derive();
4598
+ if (!options?.migration) {
4599
+ return null;
4497
4600
  }
4601
+ const { newRoot } = await runEpochMigration(ctx, {
4602
+ repo: this._echoHost.automergeRepo,
4603
+ spaceId: this.id,
4604
+ spaceKey: this.key,
4605
+ migration: options.migration,
4606
+ currentRoot: this._automergeSpaceState.rootUrl ?? null,
4607
+ newAutomergeRoot: options.newAutomergeRoot
4608
+ });
4609
+ const epoch = {
4610
+ previousId: this._automergeSpaceState.lastEpoch?.id,
4611
+ number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
4612
+ timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe3(),
4613
+ automergeRoot: newRoot ?? this._automergeSpaceState.rootUrl
4614
+ };
4615
+ const credential = await this._signingContext.credentialSigner.createCredential({
4616
+ subject: this.key,
4617
+ assertion: {
4618
+ "@type": "dxos.halo.credentials.Epoch",
4619
+ ...epoch
4620
+ }
4621
+ });
4498
4622
  const receipt = await this.inner.controlPipeline.writer.write({
4499
4623
  credential: {
4500
- credential: await this._signingContext.credentialSigner.createCredential({
4501
- subject: this.key,
4502
- assertion: {
4503
- "@type": "dxos.halo.credentials.Epoch",
4504
- ...epoch
4505
- }
4506
- })
4624
+ credential
4507
4625
  }
4508
4626
  });
4509
4627
  await this.inner.controlPipeline.state.waitUntilTimeframe(new Timeframe3([
@@ -4513,6 +4631,7 @@ var DataSpace = class {
4513
4631
  ]
4514
4632
  ]));
4515
4633
  await this._echoHost.updateIndexes();
4634
+ return credential;
4516
4635
  }
4517
4636
  async activate() {
4518
4637
  if (![
@@ -4534,11 +4653,11 @@ var DataSpace = class {
4534
4653
  await this._close();
4535
4654
  }
4536
4655
  this._state = SpaceState2.INACTIVE;
4537
- log13("new state", {
4656
+ log14("new state", {
4538
4657
  state: SpaceState2[this._state]
4539
4658
  }, {
4540
- F: __dxlog_file16,
4541
- L: 571,
4659
+ F: __dxlog_file17,
4660
+ L: 512,
4542
4661
  S: this,
4543
4662
  C: (f, a) => f(...a)
4544
4663
  });
@@ -4593,36 +4712,25 @@ DataSpace = _ts_decorate4([
4593
4712
  trackLeaks("open", "close"),
4594
4713
  trace6.resource()
4595
4714
  ], DataSpace);
4596
- var findPropertiesObject = (spaceDoc) => {
4597
- for (const id in spaceDoc.objects ?? {}) {
4598
- const obj = spaceDoc.objects[id];
4599
- if (obj.system.type?.itemId === TYPE_PROPERTIES) {
4600
- return [
4601
- id,
4602
- obj
4603
- ];
4604
- }
4605
- }
4606
- return void 0;
4607
- };
4608
4715
 
4609
4716
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
4610
4717
  import { Event as Event7, synchronized as synchronized2, trackLeaks as trackLeaks2 } from "@dxos/async";
4611
4718
  import { PropertiesType } from "@dxos/client-protocol";
4612
- import { cancelWithContext as cancelWithContext5, Context as Context9 } from "@dxos/context";
4719
+ import { Context as Context9, cancelWithContext as cancelWithContext6 } from "@dxos/context";
4613
4720
  import { getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
4721
+ import { convertLegacyReferences as convertLegacyReferences2, findInlineObjectOfType as findInlineObjectOfType2 } from "@dxos/echo-db";
4614
4722
  import { AuthStatus } from "@dxos/echo-pipeline";
4615
- import { encodeReference } from "@dxos/echo-protocol";
4616
- import { getTypeReference } from "@dxos/echo-schema";
4723
+ import { LEGACY_TYPE_PROPERTIES, SpaceDocVersion as SpaceDocVersion2, encodeReference } from "@dxos/echo-protocol";
4724
+ import { TYPE_PROPERTIES as TYPE_PROPERTIES2, generateEchoId, getTypeReference } from "@dxos/echo-schema";
4617
4725
  import { invariant as invariant14 } from "@dxos/invariant";
4618
4726
  import { PublicKey as PublicKey11 } from "@dxos/keys";
4619
- import { log as log14 } from "@dxos/log";
4727
+ import { log as log15 } from "@dxos/log";
4620
4728
  import { trace as Trace2 } from "@dxos/protocols";
4621
4729
  import { Invitation as Invitation7, SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
4622
4730
  import { SpaceMember as SpaceMember6 } from "@dxos/protocols/proto/dxos/halo/credentials";
4623
4731
  import { Gossip as Gossip2, Presence as Presence2 } from "@dxos/teleport-extension-gossip";
4624
4732
  import { trace as trace7 } from "@dxos/tracing";
4625
- import { assignDeep as assignDeep2, ComplexMap as ComplexMap3, deferFunction as deferFunction2, forEachAsync } from "@dxos/util";
4733
+ import { ComplexMap as ComplexMap3, assignDeep as assignDeep2, deferFunction as deferFunction2, forEachAsync } from "@dxos/util";
4626
4734
 
4627
4735
  // packages/sdk/client-services/src/packlets/spaces/genesis.ts
4628
4736
  import { createCredential } from "@dxos/credentials";
@@ -4705,7 +4813,7 @@ function _ts_decorate5(decorators, target, key, desc) {
4705
4813
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4706
4814
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4707
4815
  }
4708
- var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
4816
+ var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
4709
4817
  var PRESENCE_ANNOUNCE_INTERVAL = 1e4;
4710
4818
  var PRESENCE_OFFLINE_TIMEOUT = 2e4;
4711
4819
  var DEFAULT_SPACE_KEY = "__DEFAULT__";
@@ -4732,7 +4840,7 @@ var DataSpaceManager = class {
4732
4840
  const rootUrl = space.automergeSpaceState.rootUrl;
4733
4841
  const rootHandle = rootUrl ? this._echoHost.automergeRepo.find(rootUrl) : void 0;
4734
4842
  const rootDoc = rootHandle?.docSync();
4735
- const properties = rootDoc && findPropertiesObject(rootDoc);
4843
+ const properties = rootDoc && findInlineObjectOfType2(rootDoc, TYPE_PROPERTIES2);
4736
4844
  return {
4737
4845
  key: space.key.toHex(),
4738
4846
  state: SpaceState3[space.state],
@@ -4752,46 +4860,46 @@ var DataSpaceManager = class {
4752
4860
  return this._spaces;
4753
4861
  }
4754
4862
  async open() {
4755
- log14("open", void 0, {
4756
- F: __dxlog_file17,
4757
- L: 140,
4863
+ log15("open", void 0, {
4864
+ F: __dxlog_file18,
4865
+ L: 146,
4758
4866
  S: this,
4759
4867
  C: (f, a) => f(...a)
4760
4868
  });
4761
- log14.trace("dxos.echo.data-space-manager.open", Trace2.begin({
4869
+ log15.trace("dxos.echo.data-space-manager.open", Trace2.begin({
4762
4870
  id: this._instanceId
4763
4871
  }), {
4764
- F: __dxlog_file17,
4765
- L: 141,
4872
+ F: __dxlog_file18,
4873
+ L: 147,
4766
4874
  S: this,
4767
4875
  C: (f, a) => f(...a)
4768
4876
  });
4769
- log14("metadata loaded", {
4877
+ log15("metadata loaded", {
4770
4878
  spaces: this._metadataStore.spaces.length
4771
4879
  }, {
4772
- F: __dxlog_file17,
4773
- L: 142,
4880
+ F: __dxlog_file18,
4881
+ L: 148,
4774
4882
  S: this,
4775
4883
  C: (f, a) => f(...a)
4776
4884
  });
4777
4885
  await forEachAsync(this._metadataStore.spaces, async (spaceMetadata) => {
4778
4886
  try {
4779
- log14("load space", {
4887
+ log15("load space", {
4780
4888
  spaceMetadata
4781
4889
  }, {
4782
- F: __dxlog_file17,
4783
- L: 146,
4890
+ F: __dxlog_file18,
4891
+ L: 152,
4784
4892
  S: this,
4785
4893
  C: (f, a) => f(...a)
4786
4894
  });
4787
4895
  await this._constructSpace(spaceMetadata);
4788
4896
  } catch (err) {
4789
- log14.error("Error loading space", {
4897
+ log15.error("Error loading space", {
4790
4898
  spaceMetadata,
4791
4899
  err
4792
4900
  }, {
4793
- F: __dxlog_file17,
4794
- L: 149,
4901
+ F: __dxlog_file18,
4902
+ L: 155,
4795
4903
  S: this,
4796
4904
  C: (f, a) => f(...a)
4797
4905
  });
@@ -4799,19 +4907,19 @@ var DataSpaceManager = class {
4799
4907
  });
4800
4908
  this._isOpen = true;
4801
4909
  this.updated.emit();
4802
- log14.trace("dxos.echo.data-space-manager.open", Trace2.end({
4910
+ log15.trace("dxos.echo.data-space-manager.open", Trace2.end({
4803
4911
  id: this._instanceId
4804
4912
  }), {
4805
- F: __dxlog_file17,
4806
- L: 156,
4913
+ F: __dxlog_file18,
4914
+ L: 162,
4807
4915
  S: this,
4808
4916
  C: (f, a) => f(...a)
4809
4917
  });
4810
4918
  }
4811
4919
  async close() {
4812
- log14("close", void 0, {
4813
- F: __dxlog_file17,
4814
- L: 161,
4920
+ log15("close", void 0, {
4921
+ F: __dxlog_file18,
4922
+ L: 167,
4815
4923
  S: this,
4816
4924
  C: (f, a) => f(...a)
4817
4925
  });
@@ -4827,8 +4935,8 @@ var DataSpaceManager = class {
4827
4935
  */
4828
4936
  async createSpace() {
4829
4937
  invariant14(this._isOpen, "Not open.", {
4830
- F: __dxlog_file17,
4831
- L: 175,
4938
+ F: __dxlog_file18,
4939
+ L: 181,
4832
4940
  S: this,
4833
4941
  A: [
4834
4942
  "this._isOpen",
@@ -4845,11 +4953,11 @@ var DataSpaceManager = class {
4845
4953
  dataFeedKey,
4846
4954
  state: SpaceState3.ACTIVE
4847
4955
  };
4848
- log14("creating space...", {
4956
+ log15("creating space...", {
4849
4957
  spaceKey
4850
4958
  }, {
4851
- F: __dxlog_file17,
4852
- L: 187,
4959
+ F: __dxlog_file18,
4960
+ L: 193,
4853
4961
  S: this,
4854
4962
  C: (f, a) => f(...a)
4855
4963
  });
@@ -4860,8 +4968,8 @@ var DataSpaceManager = class {
4860
4968
  await this._metadataStore.addSpace(metadata);
4861
4969
  const memberCredential = credentials[1];
4862
4970
  invariant14(getCredentialAssertion3(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
4863
- F: __dxlog_file17,
4864
- L: 197,
4971
+ F: __dxlog_file18,
4972
+ L: 203,
4865
4973
  S: this,
4866
4974
  A: [
4867
4975
  "getCredentialAssertion(memberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -4874,9 +4982,31 @@ var DataSpaceManager = class {
4874
4982
  return space;
4875
4983
  }
4876
4984
  async isDefaultSpace(space) {
4877
- const rootDoc = await this._getSpaceRootDocument(space);
4878
- const [_, properties] = findPropertiesObject(rootDoc.docSync()) ?? [];
4879
- return properties?.data?.[DEFAULT_SPACE_KEY] === this._signingContext.identityKey.toHex();
4985
+ if (!space.databaseRoot) {
4986
+ return false;
4987
+ }
4988
+ switch (space.databaseRoot.getVersion()) {
4989
+ case SpaceDocVersion2.CURRENT: {
4990
+ const [_, properties] = findInlineObjectOfType2(space.databaseRoot.docSync(), TYPE_PROPERTIES2) ?? [];
4991
+ return properties?.data?.[DEFAULT_SPACE_KEY] === this._signingContext.identityKey.toHex();
4992
+ }
4993
+ case SpaceDocVersion2.LEGACY: {
4994
+ const convertedDoc = await convertLegacyReferences2(space.databaseRoot.docSync());
4995
+ const [_, properties] = findInlineObjectOfType2(convertedDoc, LEGACY_TYPE_PROPERTIES) ?? [];
4996
+ return properties?.data?.[DEFAULT_SPACE_KEY] === this._signingContext.identityKey.toHex();
4997
+ }
4998
+ default:
4999
+ log15.warn("unknown space version", {
5000
+ version: space.databaseRoot.getVersion(),
5001
+ spaceId: space.id
5002
+ }, {
5003
+ F: __dxlog_file18,
5004
+ L: 228,
5005
+ S: this,
5006
+ C: (f, a) => f(...a)
5007
+ });
5008
+ return false;
5009
+ }
4880
5010
  }
4881
5011
  async createDefaultSpace() {
4882
5012
  const space = await this.createSpace();
@@ -4892,7 +5022,7 @@ var DataSpaceManager = class {
4892
5022
  keys: []
4893
5023
  }
4894
5024
  };
4895
- const propertiesId = PublicKey11.random().toHex();
5025
+ const propertiesId = generateEchoId();
4896
5026
  document.change((doc) => {
4897
5027
  assignDeep2(doc, [
4898
5028
  "objects",
@@ -4905,8 +5035,8 @@ var DataSpaceManager = class {
4905
5035
  async _getSpaceRootDocument(space) {
4906
5036
  const automergeIndex = space.automergeSpaceState.rootUrl;
4907
5037
  invariant14(automergeIndex, void 0, {
4908
- F: __dxlog_file17,
4909
- L: 240,
5038
+ F: __dxlog_file18,
5039
+ L: 261,
4910
5040
  S: this,
4911
5041
  A: [
4912
5042
  "automergeIndex",
@@ -4919,17 +5049,17 @@ var DataSpaceManager = class {
4919
5049
  }
4920
5050
  // TODO(burdon): Rename join space.
4921
5051
  async acceptSpace(opts) {
4922
- log14("accept space", {
5052
+ log15("accept space", {
4923
5053
  opts
4924
5054
  }, {
4925
- F: __dxlog_file17,
4926
- L: 249,
5055
+ F: __dxlog_file18,
5056
+ L: 270,
4927
5057
  S: this,
4928
5058
  C: (f, a) => f(...a)
4929
5059
  });
4930
5060
  invariant14(this._isOpen, "Not open.", {
4931
- F: __dxlog_file17,
4932
- L: 250,
5061
+ F: __dxlog_file18,
5062
+ L: 271,
4933
5063
  S: this,
4934
5064
  A: [
4935
5065
  "this._isOpen",
@@ -4937,8 +5067,8 @@ var DataSpaceManager = class {
4937
5067
  ]
4938
5068
  });
4939
5069
  invariant14(!this._spaces.has(opts.spaceKey), "Space already exists.", {
4940
- F: __dxlog_file17,
4941
- L: 251,
5070
+ F: __dxlog_file18,
5071
+ L: 272,
4942
5072
  S: this,
4943
5073
  A: [
4944
5074
  "!this._spaces.has(opts.spaceKey)",
@@ -4964,17 +5094,17 @@ var DataSpaceManager = class {
4964
5094
  * TODO(dmaretskyi): Consider removing.
4965
5095
  */
4966
5096
  async waitUntilSpaceReady(spaceKey) {
4967
- await cancelWithContext5(this._ctx, this.updated.waitForCondition(() => {
5097
+ await cancelWithContext6(this._ctx, this.updated.waitForCondition(() => {
4968
5098
  const space = this._spaces.get(spaceKey);
4969
5099
  return !!space && space.state === SpaceState3.READY;
4970
5100
  }));
4971
5101
  }
4972
5102
  async _constructSpace(metadata) {
4973
- log14("construct space", {
5103
+ log15("construct space", {
4974
5104
  metadata
4975
5105
  }, {
4976
- F: __dxlog_file17,
4977
- L: 285,
5106
+ F: __dxlog_file18,
5107
+ L: 306,
4978
5108
  S: this,
4979
5109
  C: (f, a) => f(...a)
4980
5110
  });
@@ -5010,9 +5140,9 @@ var DataSpaceManager = class {
5010
5140
  session.addExtension("dxos.mesh.teleport.automerge", this._echoHost.createReplicationExtension());
5011
5141
  },
5012
5142
  onAuthFailure: () => {
5013
- log14.warn("auth failure", void 0, {
5014
- F: __dxlog_file17,
5015
- L: 322,
5143
+ log15.warn("auth failure", void 0, {
5144
+ F: __dxlog_file18,
5145
+ L: 343,
5016
5146
  S: this,
5017
5147
  C: (f, a) => f(...a)
5018
5148
  });
@@ -5041,22 +5171,22 @@ var DataSpaceManager = class {
5041
5171
  signingContext: this._signingContext,
5042
5172
  callbacks: {
5043
5173
  beforeReady: async () => {
5044
- log14("before space ready", {
5174
+ log15("before space ready", {
5045
5175
  space: space.key
5046
5176
  }, {
5047
- F: __dxlog_file17,
5048
- L: 349,
5177
+ F: __dxlog_file18,
5178
+ L: 370,
5049
5179
  S: this,
5050
5180
  C: (f, a) => f(...a)
5051
5181
  });
5052
5182
  },
5053
5183
  afterReady: async () => {
5054
- log14("after space ready", {
5184
+ log15("after space ready", {
5055
5185
  space: space.key,
5056
5186
  open: this._isOpen
5057
5187
  }, {
5058
- F: __dxlog_file17,
5059
- L: 352,
5188
+ F: __dxlog_file18,
5189
+ L: 373,
5060
5190
  S: this,
5061
5191
  C: (f, a) => f(...a)
5062
5192
  });
@@ -5071,11 +5201,11 @@ var DataSpaceManager = class {
5071
5201
  }
5072
5202
  },
5073
5203
  beforeClose: async () => {
5074
- log14("before space close", {
5204
+ log15("before space close", {
5075
5205
  space: space.key
5076
5206
  }, {
5077
- F: __dxlog_file17,
5078
- L: 360,
5207
+ F: __dxlog_file18,
5208
+ L: 381,
5079
5209
  S: this,
5080
5210
  C: (f, a) => f(...a)
5081
5211
  });
@@ -5106,17 +5236,17 @@ var DataSpaceManager = class {
5106
5236
  return (s && member.role === SpaceMember6.Role.REMOVED !== (s.authStatus === AuthStatus.FAILURE)) ?? false;
5107
5237
  });
5108
5238
  sessionsToClose.forEach((session) => {
5109
- void session.close().catch(log14.error);
5239
+ void session.close().catch(log15.error);
5110
5240
  });
5111
5241
  closedSessions += sessionsToClose.length;
5112
5242
  }
5113
- log14("processed member role changes", {
5243
+ log15("processed member role changes", {
5114
5244
  roleChangeCount: memberInfo.length,
5115
5245
  peersOnline: presence.getPeersOnline().length,
5116
5246
  closedSessions
5117
5247
  }, {
5118
- F: __dxlog_file17,
5119
- L: 396,
5248
+ F: __dxlog_file18,
5249
+ L: 417,
5120
5250
  S: this,
5121
5251
  C: (f, a) => f(...a)
5122
5252
  });
@@ -5127,15 +5257,15 @@ var DataSpaceManager = class {
5127
5257
  if (role === SpaceMember6.Role.REMOVED) {
5128
5258
  const session = peerState.peerId && space.protocol.sessions.get(peerState.peerId);
5129
5259
  if (session != null) {
5130
- log14("closing a session with a removed peer", {
5260
+ log15("closing a session with a removed peer", {
5131
5261
  peerId: peerState.peerId
5132
5262
  }, {
5133
- F: __dxlog_file17,
5134
- L: 410,
5263
+ F: __dxlog_file18,
5264
+ L: 431,
5135
5265
  S: this,
5136
5266
  C: (f, a) => f(...a)
5137
5267
  });
5138
- void session.close().catch(log14.error);
5268
+ void session.close().catch(log15.error);
5139
5269
  }
5140
5270
  }
5141
5271
  }
@@ -5198,11 +5328,11 @@ import { createAdmissionCredentials as createAdmissionCredentials2, getCredentia
5198
5328
  import { raise as raise2 } from "@dxos/debug";
5199
5329
  import { writeMessages as writeMessages3 } from "@dxos/feed-store";
5200
5330
  import { invariant as invariant15 } from "@dxos/invariant";
5201
- import { log as log15 } from "@dxos/log";
5331
+ import { log as log16 } from "@dxos/log";
5202
5332
  import { ApiError, SpaceNotFoundError as SpaceNotFoundError2, encodeError, IdentityNotInitializedError, AuthorizationError as AuthorizationError2 } from "@dxos/protocols";
5203
5333
  import { SpaceMember as SpaceMember7, SpaceState as SpaceState4 } from "@dxos/protocols/proto/dxos/client/services";
5204
5334
  import { trace as trace8 } from "@dxos/tracing";
5205
- var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
5335
+ var __dxlog_file19 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
5206
5336
  var SpacesServiceImpl = class {
5207
5337
  constructor(_identityManager, _spaceManager, _getDataSpaceManager) {
5208
5338
  this._identityManager = _identityManager;
@@ -5246,8 +5376,8 @@ var SpacesServiceImpl = class {
5246
5376
  }
5247
5377
  const credentials = await createAdmissionCredentials2(identity.getIdentityCredentialSigner(), request.memberKey, space.key, space.genesisFeedKey, request.newRole, space.spaceState.membershipChainHeads);
5248
5378
  invariant15(credentials[0].credential, void 0, {
5249
- F: __dxlog_file18,
5250
- L: 97,
5379
+ F: __dxlog_file19,
5380
+ L: 98,
5251
5381
  S: this,
5252
5382
  A: [
5253
5383
  "credentials[0].credential",
@@ -5256,8 +5386,8 @@ var SpacesServiceImpl = class {
5256
5386
  });
5257
5387
  const spaceMemberCredential = credentials[0].credential.credential;
5258
5388
  invariant15(getCredentialAssertion4(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
5259
- F: __dxlog_file18,
5260
- L: 99,
5389
+ F: __dxlog_file19,
5390
+ L: 100,
5261
5391
  S: this,
5262
5392
  A: [
5263
5393
  "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -5271,11 +5401,11 @@ var SpacesServiceImpl = class {
5271
5401
  const scheduler = new UpdateScheduler(ctx, async () => {
5272
5402
  const dataSpaceManager = await this._getDataSpaceManager();
5273
5403
  const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._serializeSpace(space));
5274
- log15("update", {
5404
+ log16("update", {
5275
5405
  spaces
5276
5406
  }, {
5277
- F: __dxlog_file18,
5278
- L: 110,
5407
+ F: __dxlog_file19,
5408
+ L: 111,
5279
5409
  S: this,
5280
5410
  C: (f, a) => f(...a)
5281
5411
  });
@@ -5358,8 +5488,8 @@ var SpacesServiceImpl = class {
5358
5488
  });
5359
5489
  } else {
5360
5490
  invariant15(!credential.id, "Id on unsigned credentials is not allowed", {
5361
- F: __dxlog_file18,
5362
- L: 198,
5491
+ F: __dxlog_file19,
5492
+ L: 199,
5363
5493
  S: this,
5364
5494
  A: [
5365
5495
  "!credential.id",
@@ -5367,8 +5497,8 @@ var SpacesServiceImpl = class {
5367
5497
  ]
5368
5498
  });
5369
5499
  invariant15(this._identityManager.identity, "Identity is not available", {
5370
- F: __dxlog_file18,
5371
- L: 199,
5500
+ F: __dxlog_file19,
5501
+ L: 200,
5372
5502
  S: this,
5373
5503
  A: [
5374
5504
  "this._identityManager.identity",
@@ -5377,8 +5507,8 @@ var SpacesServiceImpl = class {
5377
5507
  });
5378
5508
  const signer = this._identityManager.identity.getIdentityCredentialSigner();
5379
5509
  invariant15(credential.issuer.equals(signer.getIssuer()), void 0, {
5380
- F: __dxlog_file18,
5381
- L: 201,
5510
+ F: __dxlog_file19,
5511
+ L: 202,
5382
5512
  S: this,
5383
5513
  A: [
5384
5514
  "credential.issuer.equals(signer.getIssuer())",
@@ -5400,10 +5530,13 @@ var SpacesServiceImpl = class {
5400
5530
  async createEpoch({ spaceKey, migration, automergeRootUrl }) {
5401
5531
  const dataSpaceManager = await this._getDataSpaceManager();
5402
5532
  const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError2(spaceKey));
5403
- await space.createEpoch({
5533
+ const credential = await space.createEpoch({
5404
5534
  migration,
5405
5535
  newAutomergeRoot: automergeRootUrl
5406
5536
  });
5537
+ return {
5538
+ epochCredential: credential ?? void 0
5539
+ };
5407
5540
  }
5408
5541
  _serializeSpace(space) {
5409
5542
  return {
@@ -5467,7 +5600,7 @@ var getChannelId = (channel) => `user-channel/${channel}`;
5467
5600
 
5468
5601
  // packages/sdk/client-services/src/packlets/services/service-context.ts
5469
5602
  import { Trigger as Trigger7 } from "@dxos/async";
5470
- import { Context as Context10, Resource as Resource2 } from "@dxos/context";
5603
+ import { Context as Context10, Resource as Resource3 } from "@dxos/context";
5471
5604
  import { getCredentialAssertion as getCredentialAssertion5 } from "@dxos/credentials";
5472
5605
  import { failUndefined as failUndefined2 } from "@dxos/debug";
5473
5606
  import { EchoHost } from "@dxos/echo-db";
@@ -5476,7 +5609,7 @@ import { FeedFactory, FeedStore } from "@dxos/feed-store";
5476
5609
  import { invariant as invariant16 } from "@dxos/invariant";
5477
5610
  import { Keyring } from "@dxos/keyring";
5478
5611
  import { PublicKey as PublicKey12 } from "@dxos/keys";
5479
- import { log as log16 } from "@dxos/log";
5612
+ import { log as log17 } from "@dxos/log";
5480
5613
  import { InvalidStorageVersionError, STORAGE_VERSION as STORAGE_VERSION2, trace as trace9 } from "@dxos/protocols";
5481
5614
  import { Invitation as Invitation8 } from "@dxos/protocols/proto/dxos/client/services";
5482
5615
  import { BlobStore } from "@dxos/teleport-extension-object-sync";
@@ -5492,8 +5625,8 @@ function _ts_decorate6(decorators, target, key, desc) {
5492
5625
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5493
5626
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5494
5627
  }
5495
- var __dxlog_file19 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
5496
- var ServiceContext = class extends Resource2 {
5628
+ var __dxlog_file20 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
5629
+ var ServiceContext = class extends Resource3 {
5497
5630
  constructor(storage, level, networkManager, signalManager, _runtimeParams) {
5498
5631
  super();
5499
5632
  this.storage = storage;
@@ -5535,16 +5668,16 @@ var ServiceContext = class extends Resource2 {
5535
5668
  }
5536
5669
  async _open(ctx) {
5537
5670
  await this._checkStorageVersion();
5538
- log16("opening...", void 0, {
5539
- F: __dxlog_file19,
5671
+ log17("opening...", void 0, {
5672
+ F: __dxlog_file20,
5540
5673
  L: 149,
5541
5674
  S: this,
5542
5675
  C: (f, a) => f(...a)
5543
5676
  });
5544
- log16.trace("dxos.sdk.service-context.open", trace9.begin({
5677
+ log17.trace("dxos.sdk.service-context.open", trace9.begin({
5545
5678
  id: this._instanceId
5546
5679
  }), {
5547
- F: __dxlog_file19,
5680
+ F: __dxlog_file20,
5548
5681
  L: 150,
5549
5682
  S: this,
5550
5683
  C: (f, a) => f(...a)
@@ -5559,32 +5692,32 @@ var ServiceContext = class extends Resource2 {
5559
5692
  await this._initialize(ctx);
5560
5693
  }
5561
5694
  const loadedInvitations = await this.invitationsManager.loadPersistentInvitations();
5562
- log16("loaded persistent invitations", {
5695
+ log17("loaded persistent invitations", {
5563
5696
  count: loadedInvitations.invitations?.length
5564
5697
  }, {
5565
- F: __dxlog_file19,
5698
+ F: __dxlog_file20,
5566
5699
  L: 163,
5567
5700
  S: this,
5568
5701
  C: (f, a) => f(...a)
5569
5702
  });
5570
- log16.trace("dxos.sdk.service-context.open", trace9.end({
5703
+ log17.trace("dxos.sdk.service-context.open", trace9.end({
5571
5704
  id: this._instanceId
5572
5705
  }), {
5573
- F: __dxlog_file19,
5706
+ F: __dxlog_file20,
5574
5707
  L: 165,
5575
5708
  S: this,
5576
5709
  C: (f, a) => f(...a)
5577
5710
  });
5578
- log16("opened", void 0, {
5579
- F: __dxlog_file19,
5711
+ log17("opened", void 0, {
5712
+ F: __dxlog_file20,
5580
5713
  L: 166,
5581
5714
  S: this,
5582
5715
  C: (f, a) => f(...a)
5583
5716
  });
5584
5717
  }
5585
5718
  async _close(ctx) {
5586
- log16("closing...", void 0, {
5587
- F: __dxlog_file19,
5719
+ log17("closing...", void 0, {
5720
+ F: __dxlog_file20,
5588
5721
  L: 170,
5589
5722
  S: this,
5590
5723
  C: (f, a) => f(...a)
@@ -5600,8 +5733,8 @@ var ServiceContext = class extends Resource2 {
5600
5733
  await this.echoHost.close(ctx);
5601
5734
  await this.networkManager.close();
5602
5735
  await this.signalManager.close();
5603
- log16("closed", void 0, {
5604
- F: __dxlog_file19,
5736
+ log17("closed", void 0, {
5737
+ F: __dxlog_file20,
5605
5738
  L: 182,
5606
5739
  S: this,
5607
5740
  C: (f, a) => f(...a)
@@ -5615,7 +5748,7 @@ var ServiceContext = class extends Resource2 {
5615
5748
  getInvitationHandler(invitation) {
5616
5749
  const factory = this._handlerFactories.get(invitation.kind);
5617
5750
  invariant16(factory, `Unknown invitation kind: ${invitation.kind}`, {
5618
- F: __dxlog_file19,
5751
+ F: __dxlog_file20,
5619
5752
  L: 193,
5620
5753
  S: this,
5621
5754
  A: [
@@ -5646,8 +5779,8 @@ var ServiceContext = class extends Resource2 {
5646
5779
  }
5647
5780
  // Called when identity is created.
5648
5781
  async _initialize(ctx) {
5649
- log16("initializing spaces...", void 0, {
5650
- F: __dxlog_file19,
5782
+ log17("initializing spaces...", void 0, {
5783
+ F: __dxlog_file20,
5651
5784
  L: 224,
5652
5785
  S: this,
5653
5786
  C: (f, a) => f(...a)
@@ -5670,7 +5803,7 @@ var ServiceContext = class extends Resource2 {
5670
5803
  await this.dataSpaceManager.open();
5671
5804
  this._handlerFactories.set(Invitation8.Kind.SPACE, (invitation) => {
5672
5805
  invariant16(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
5673
- F: __dxlog_file19,
5806
+ F: __dxlog_file20,
5674
5807
  L: 249,
5675
5808
  S: this,
5676
5809
  A: [
@@ -5691,10 +5824,10 @@ var ServiceContext = class extends Resource2 {
5691
5824
  return;
5692
5825
  }
5693
5826
  if (!this.dataSpaceManager) {
5694
- log16("dataSpaceManager not initialized yet, ignoring space admission", {
5827
+ log17("dataSpaceManager not initialized yet, ignoring space admission", {
5695
5828
  details: assertion
5696
5829
  }, {
5697
- F: __dxlog_file19,
5830
+ F: __dxlog_file20,
5698
5831
  L: 265,
5699
5832
  S: this,
5700
5833
  C: (f, a) => f(...a)
@@ -5702,10 +5835,10 @@ var ServiceContext = class extends Resource2 {
5702
5835
  return;
5703
5836
  }
5704
5837
  if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
5705
- log16("space already exists, ignoring space admission", {
5838
+ log17("space already exists, ignoring space admission", {
5706
5839
  details: assertion
5707
5840
  }, {
5708
- F: __dxlog_file19,
5841
+ F: __dxlog_file20,
5709
5842
  L: 269,
5710
5843
  S: this,
5711
5844
  C: (f, a) => f(...a)
@@ -5713,10 +5846,10 @@ var ServiceContext = class extends Resource2 {
5713
5846
  return;
5714
5847
  }
5715
5848
  try {
5716
- log16("accepting space recorded in halo", {
5849
+ log17("accepting space recorded in halo", {
5717
5850
  details: assertion
5718
5851
  }, {
5719
- F: __dxlog_file19,
5852
+ F: __dxlog_file20,
5720
5853
  L: 274,
5721
5854
  S: this,
5722
5855
  C: (f, a) => f(...a)
@@ -5726,8 +5859,8 @@ var ServiceContext = class extends Resource2 {
5726
5859
  genesisFeedKey: assertion.genesisFeedKey
5727
5860
  });
5728
5861
  } catch (err) {
5729
- log16.catch(err, void 0, {
5730
- F: __dxlog_file19,
5862
+ log17.catch(err, void 0, {
5863
+ F: __dxlog_file20,
5731
5864
  L: 280,
5732
5865
  S: this,
5733
5866
  C: (f, a) => f(...a)
@@ -5776,7 +5909,7 @@ var ServiceRegistry = class {
5776
5909
  // packages/sdk/client-services/src/packlets/locks/browser.ts
5777
5910
  import { asyncTimeout as asyncTimeout3, Trigger as Trigger8 } from "@dxos/async";
5778
5911
  import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
5779
- import { log as log17, logInfo } from "@dxos/log";
5912
+ import { log as log18, logInfo } from "@dxos/log";
5780
5913
  function _ts_decorate7(decorators, target, key, desc) {
5781
5914
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5782
5915
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -5787,7 +5920,7 @@ function _ts_decorate7(decorators, target, key, desc) {
5787
5920
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5788
5921
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5789
5922
  }
5790
- var __dxlog_file20 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
5923
+ var __dxlog_file21 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
5791
5924
  var Message;
5792
5925
  (function(Message2) {
5793
5926
  Message2["ACQUIRING"] = "acquiring";
@@ -5809,29 +5942,29 @@ var Lock = class {
5809
5942
  message: "acquiring"
5810
5943
  });
5811
5944
  try {
5812
- log17("aquiring lock...", void 0, {
5813
- F: __dxlog_file20,
5945
+ log18("aquiring lock...", void 0, {
5946
+ F: __dxlog_file21,
5814
5947
  L: 42,
5815
5948
  S: this,
5816
5949
  C: (f, a) => f(...a)
5817
5950
  });
5818
5951
  await asyncTimeout3(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
5819
- log17("acquired lock", void 0, {
5820
- F: __dxlog_file20,
5952
+ log18("acquired lock", void 0, {
5953
+ F: __dxlog_file21,
5821
5954
  L: 44,
5822
5955
  S: this,
5823
5956
  C: (f, a) => f(...a)
5824
5957
  });
5825
5958
  } catch {
5826
- log17("stealing lock...", void 0, {
5827
- F: __dxlog_file20,
5959
+ log18("stealing lock...", void 0, {
5960
+ F: __dxlog_file21,
5828
5961
  L: 46,
5829
5962
  S: this,
5830
5963
  C: (f, a) => f(...a)
5831
5964
  });
5832
5965
  await this._requestLock(true);
5833
- log17("stolen lock", void 0, {
5834
- F: __dxlog_file20,
5966
+ log18("stolen lock", void 0, {
5967
+ F: __dxlog_file21,
5835
5968
  L: 48,
5836
5969
  S: this,
5837
5970
  C: (f, a) => f(...a)
@@ -5847,10 +5980,10 @@ var Lock = class {
5847
5980
  }
5848
5981
  }
5849
5982
  async _requestLock(steal = false) {
5850
- log17("requesting lock...", {
5983
+ log18("requesting lock...", {
5851
5984
  steal
5852
5985
  }, {
5853
- F: __dxlog_file20,
5986
+ F: __dxlog_file21,
5854
5987
  L: 63,
5855
5988
  S: this,
5856
5989
  C: (f, a) => f(...a)
@@ -5863,15 +5996,15 @@ var Lock = class {
5863
5996
  acquired.wake();
5864
5997
  this._releaseTrigger = new Trigger8();
5865
5998
  await this._releaseTrigger.wait();
5866
- log17("releasing lock...", void 0, {
5867
- F: __dxlog_file20,
5999
+ log18("releasing lock...", void 0, {
6000
+ F: __dxlog_file21,
5868
6001
  L: 72,
5869
6002
  S: this,
5870
6003
  C: (f, a) => f(...a)
5871
6004
  });
5872
6005
  await this._onRelease?.();
5873
- log17("released lock", void 0, {
5874
- F: __dxlog_file20,
6006
+ log18("released lock", void 0, {
6007
+ F: __dxlog_file21,
5875
6008
  L: 74,
5876
6009
  S: this,
5877
6010
  C: (f, a) => f(...a)
@@ -5880,10 +6013,10 @@ var Lock = class {
5880
6013
  await this._onRelease?.();
5881
6014
  });
5882
6015
  await acquired.wait();
5883
- log17("recieved lock", {
6016
+ log18("recieved lock", {
5884
6017
  steal
5885
6018
  }, {
5886
- F: __dxlog_file20,
6019
+ F: __dxlog_file21,
5887
6020
  L: 81,
5888
6021
  S: this,
5889
6022
  C: (f, a) => f(...a)
@@ -5977,7 +6110,7 @@ import { clientServiceBundle } from "@dxos/client-protocol";
5977
6110
  import { Context as Context11 } from "@dxos/context";
5978
6111
  import { invariant as invariant18 } from "@dxos/invariant";
5979
6112
  import { PublicKey as PublicKey16 } from "@dxos/keys";
5980
- import { log as log19 } from "@dxos/log";
6113
+ import { log as log20 } from "@dxos/log";
5981
6114
  import { WebsocketSignalManager } from "@dxos/messaging";
5982
6115
  import { SwarmNetworkManager, createSimplePeerTransportFactory } from "@dxos/network-manager";
5983
6116
  import { trace as trace10 } from "@dxos/protocols";
@@ -5990,7 +6123,7 @@ import { EventSubscriptions as EventSubscriptions3 } from "@dxos/async";
5990
6123
  import { Stream as Stream11 } from "@dxos/codec-protobuf";
5991
6124
  import { invariant as invariant17 } from "@dxos/invariant";
5992
6125
  import { Device as Device2, DeviceKind as DeviceKind2 } from "@dxos/protocols/proto/dxos/client/services";
5993
- var __dxlog_file21 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
6126
+ var __dxlog_file22 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
5994
6127
  var DevicesServiceImpl = class {
5995
6128
  constructor(_identityManager) {
5996
6129
  this._identityManager = _identityManager;
@@ -6008,7 +6141,7 @@ var DevicesServiceImpl = class {
6008
6141
  });
6009
6142
  } else {
6010
6143
  invariant17(this._identityManager.identity?.presence, "presence not present", {
6011
- F: __dxlog_file21,
6144
+ F: __dxlog_file22,
6012
6145
  L: 32,
6013
6146
  S: this,
6014
6147
  A: [
@@ -6118,7 +6251,7 @@ var findConfigs = () => {
6118
6251
  import { Event as Event8 } from "@dxos/async";
6119
6252
  import { Stream as Stream12 } from "@dxos/codec-protobuf";
6120
6253
  import { PublicKey as PublicKey15 } from "@dxos/keys";
6121
- import { getContextFromEntry, log as log18 } from "@dxos/log";
6254
+ import { getContextFromEntry, log as log19 } from "@dxos/log";
6122
6255
  import { QueryLogsRequest } from "@dxos/protocols/proto/dxos/client/services";
6123
6256
  import { getDebugName, jsonify, numericalValues, tracer } from "@dxos/util";
6124
6257
  var LoggingServiceImpl = class {
@@ -6131,11 +6264,11 @@ var LoggingServiceImpl = class {
6131
6264
  };
6132
6265
  }
6133
6266
  async open() {
6134
- log18.runtimeConfig.processors.push(this._logProcessor);
6267
+ log19.runtimeConfig.processors.push(this._logProcessor);
6135
6268
  }
6136
6269
  async close() {
6137
- const index = log18.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
6138
- log18.runtimeConfig.processors.splice(index, 1);
6270
+ const index = log19.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
6271
+ log19.runtimeConfig.processors.splice(index, 1);
6139
6272
  }
6140
6273
  async controlMetrics({ reset, record }) {
6141
6274
  if (reset) {
@@ -6339,7 +6472,7 @@ function _ts_decorate8(decorators, target, key, desc) {
6339
6472
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6340
6473
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6341
6474
  }
6342
- var __dxlog_file22 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
6475
+ var __dxlog_file23 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
6343
6476
  var ClientServicesHost = class {
6344
6477
  constructor({
6345
6478
  config,
@@ -6428,7 +6561,7 @@ var ClientServicesHost = class {
6428
6561
  */
6429
6562
  initialize({ config, ...options }) {
6430
6563
  invariant18(!this._open, "service host is open", {
6431
- F: __dxlog_file22,
6564
+ F: __dxlog_file23,
6432
6565
  L: 186,
6433
6566
  S: this,
6434
6567
  A: [
@@ -6436,15 +6569,15 @@ var ClientServicesHost = class {
6436
6569
  "'service host is open'"
6437
6570
  ]
6438
6571
  });
6439
- log19("initializing...", void 0, {
6440
- F: __dxlog_file22,
6572
+ log20("initializing...", void 0, {
6573
+ F: __dxlog_file23,
6441
6574
  L: 187,
6442
6575
  S: this,
6443
6576
  C: (f, a) => f(...a)
6444
6577
  });
6445
6578
  if (config) {
6446
6579
  invariant18(!this._config, "config already set", {
6447
- F: __dxlog_file22,
6580
+ F: __dxlog_file23,
6448
6581
  L: 190,
6449
6582
  S: this,
6450
6583
  A: [
@@ -6458,8 +6591,8 @@ var ClientServicesHost = class {
6458
6591
  }
6459
6592
  }
6460
6593
  if (!options.signalManager) {
6461
- log19.warn("running signaling without telemetry metadata.", void 0, {
6462
- F: __dxlog_file22,
6594
+ log20.warn("running signaling without telemetry metadata.", void 0, {
6595
+ F: __dxlog_file23,
6463
6596
  L: 198,
6464
6597
  S: this,
6465
6598
  C: (f, a) => f(...a)
@@ -6470,7 +6603,7 @@ var ClientServicesHost = class {
6470
6603
  }), signalManager = new WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
6471
6604
  this._signalManager = signalManager;
6472
6605
  invariant18(!this._networkManager, "network manager already set", {
6473
- F: __dxlog_file22,
6606
+ F: __dxlog_file23,
6474
6607
  L: 209,
6475
6608
  S: this,
6476
6609
  A: [
@@ -6483,8 +6616,8 @@ var ClientServicesHost = class {
6483
6616
  transportFactory,
6484
6617
  signalManager
6485
6618
  });
6486
- log19("initialized", void 0, {
6487
- F: __dxlog_file22,
6619
+ log20("initialized", void 0, {
6620
+ F: __dxlog_file23,
6488
6621
  L: 216,
6489
6622
  S: this,
6490
6623
  C: (f, a) => f(...a)
@@ -6495,16 +6628,16 @@ var ClientServicesHost = class {
6495
6628
  return;
6496
6629
  }
6497
6630
  const traceId = PublicKey16.random().toHex();
6498
- log19.trace("dxos.client-services.host.open", trace10.begin({
6631
+ log20.trace("dxos.client-services.host.open", trace10.begin({
6499
6632
  id: traceId
6500
6633
  }), {
6501
- F: __dxlog_file22,
6634
+ F: __dxlog_file23,
6502
6635
  L: 227,
6503
6636
  S: this,
6504
6637
  C: (f, a) => f(...a)
6505
6638
  });
6506
6639
  invariant18(this._config, "config not set", {
6507
- F: __dxlog_file22,
6640
+ F: __dxlog_file23,
6508
6641
  L: 229,
6509
6642
  S: this,
6510
6643
  A: [
@@ -6513,7 +6646,7 @@ var ClientServicesHost = class {
6513
6646
  ]
6514
6647
  });
6515
6648
  invariant18(this._storage, "storage not set", {
6516
- F: __dxlog_file22,
6649
+ F: __dxlog_file23,
6517
6650
  L: 230,
6518
6651
  S: this,
6519
6652
  A: [
@@ -6522,7 +6655,7 @@ var ClientServicesHost = class {
6522
6655
  ]
6523
6656
  });
6524
6657
  invariant18(this._signalManager, "signal manager not set", {
6525
- F: __dxlog_file22,
6658
+ F: __dxlog_file23,
6526
6659
  L: 231,
6527
6660
  S: this,
6528
6661
  A: [
@@ -6531,7 +6664,7 @@ var ClientServicesHost = class {
6531
6664
  ]
6532
6665
  });
6533
6666
  invariant18(this._networkManager, "network manager not set", {
6534
- F: __dxlog_file22,
6667
+ F: __dxlog_file23,
6535
6668
  L: 232,
6536
6669
  S: this,
6537
6670
  A: [
@@ -6540,10 +6673,10 @@ var ClientServicesHost = class {
6540
6673
  ]
6541
6674
  });
6542
6675
  this._opening = true;
6543
- log19("opening...", {
6676
+ log20("opening...", {
6544
6677
  lockKey: this._resourceLock?.lockKey
6545
6678
  }, {
6546
- F: __dxlog_file22,
6679
+ F: __dxlog_file23,
6547
6680
  L: 235,
6548
6681
  S: this,
6549
6682
  C: (f, a) => f(...a)
@@ -6594,18 +6727,18 @@ var ClientServicesHost = class {
6594
6727
  this._open = true;
6595
6728
  this._statusUpdate.emit();
6596
6729
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
6597
- log19("opened", {
6730
+ log20("opened", {
6598
6731
  deviceKey
6599
6732
  }, {
6600
- F: __dxlog_file22,
6733
+ F: __dxlog_file23,
6601
6734
  L: 314,
6602
6735
  S: this,
6603
6736
  C: (f, a) => f(...a)
6604
6737
  });
6605
- log19.trace("dxos.client-services.host.open", trace10.end({
6738
+ log20.trace("dxos.client-services.host.open", trace10.end({
6606
6739
  id: traceId
6607
6740
  }), {
6608
- F: __dxlog_file22,
6741
+ F: __dxlog_file23,
6609
6742
  L: 315,
6610
6743
  S: this,
6611
6744
  C: (f, a) => f(...a)
@@ -6616,10 +6749,10 @@ var ClientServicesHost = class {
6616
6749
  return;
6617
6750
  }
6618
6751
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
6619
- log19("closing...", {
6752
+ log20("closing...", {
6620
6753
  deviceKey
6621
6754
  }, {
6622
- F: __dxlog_file22,
6755
+ F: __dxlog_file23,
6623
6756
  L: 326,
6624
6757
  S: this,
6625
6758
  C: (f, a) => f(...a)
@@ -6634,10 +6767,10 @@ var ClientServicesHost = class {
6634
6767
  await this._level?.close();
6635
6768
  this._open = false;
6636
6769
  this._statusUpdate.emit();
6637
- log19("closed", {
6770
+ log20("closed", {
6638
6771
  deviceKey
6639
6772
  }, {
6640
- F: __dxlog_file22,
6773
+ F: __dxlog_file23,
6641
6774
  L: 335,
6642
6775
  S: this,
6643
6776
  C: (f, a) => f(...a)
@@ -6645,32 +6778,32 @@ var ClientServicesHost = class {
6645
6778
  }
6646
6779
  async reset() {
6647
6780
  const traceId = PublicKey16.random().toHex();
6648
- log19.trace("dxos.sdk.client-services-host.reset", trace10.begin({
6781
+ log20.trace("dxos.sdk.client-services-host.reset", trace10.begin({
6649
6782
  id: traceId
6650
6783
  }), {
6651
- F: __dxlog_file22,
6784
+ F: __dxlog_file23,
6652
6785
  L: 340,
6653
6786
  S: this,
6654
6787
  C: (f, a) => f(...a)
6655
6788
  });
6656
- log19.info("resetting...", void 0, {
6657
- F: __dxlog_file22,
6789
+ log20.info("resetting...", void 0, {
6790
+ F: __dxlog_file23,
6658
6791
  L: 342,
6659
6792
  S: this,
6660
6793
  C: (f, a) => f(...a)
6661
6794
  });
6662
6795
  await this._serviceContext?.close();
6663
6796
  await this._storage.reset();
6664
- log19.info("reset", void 0, {
6665
- F: __dxlog_file22,
6797
+ log20.info("reset", void 0, {
6798
+ F: __dxlog_file23,
6666
6799
  L: 345,
6667
6800
  S: this,
6668
6801
  C: (f, a) => f(...a)
6669
6802
  });
6670
- log19.trace("dxos.sdk.client-services-host.reset", trace10.end({
6803
+ log20.trace("dxos.sdk.client-services-host.reset", trace10.end({
6671
6804
  id: traceId
6672
6805
  }), {
6673
- F: __dxlog_file22,
6806
+ F: __dxlog_file23,
6674
6807
  L: 346,
6675
6808
  S: this,
6676
6809
  C: (f, a) => f(...a)
@@ -6729,7 +6862,6 @@ export {
6729
6862
  SpaceInvitationProtocol,
6730
6863
  InvitationsManager,
6731
6864
  DataSpace,
6732
- findPropertiesObject,
6733
6865
  DataSpaceManager,
6734
6866
  SpacesServiceImpl,
6735
6867
  ServiceContext,
@@ -6742,4 +6874,4 @@ export {
6742
6874
  ClientServicesProviderResource,
6743
6875
  DiagnosticsCollector
6744
6876
  };
6745
- //# sourceMappingURL=chunk-EKD7OOMO.mjs.map
6877
+ //# sourceMappingURL=chunk-WC3HHHUZ.mjs.map