@dxos/client-services 0.5.9-main.9e81cb9 → 0.5.9-main.9f60463

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-DJUHMW47.mjs → chunk-BTHX37CG.mjs} +703 -538
  2. package/dist/lib/browser/chunk-BTHX37CG.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-QKO73PFC.cjs → chunk-AUGYXYOL.cjs} +854 -692
  8. package/dist/lib/node/chunk-AUGYXYOL.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 +33 -7
  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 +75 -145
  29. package/src/packlets/spaces/epoch-migrations.ts +135 -0
  30. package/src/packlets/spaces/spaces-service.ts +16 -4
  31. package/src/version.ts +1 -1
  32. package/dist/lib/browser/chunk-DJUHMW47.mjs.map +0 -7
  33. package/dist/lib/node/chunk-QKO73PFC.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.9e81cb9";
358
+ var DXOS_VERSION = "0.5.9-main.9f60463";
359
359
 
360
360
  // packages/sdk/client-services/src/packlets/services/platform.ts
361
361
  import { Platform } from "@dxos/protocols/proto/dxos/client/services";
@@ -1519,13 +1519,17 @@ IdentityManager = _ts_decorate3([
1519
1519
  ], IdentityManager);
1520
1520
 
1521
1521
  // packages/sdk/client-services/src/packlets/identity/identity-service.ts
1522
+ import { Trigger as Trigger3, sleep } from "@dxos/async";
1522
1523
  import { Stream as Stream8 } from "@dxos/codec-protobuf";
1523
1524
  import { Resource } from "@dxos/context";
1524
1525
  import { signPresentation } from "@dxos/credentials";
1525
1526
  import { todo } from "@dxos/debug";
1526
1527
  import { invariant as invariant4 } from "@dxos/invariant";
1528
+ import { log as log6 } from "@dxos/log";
1527
1529
  import { SpaceState } from "@dxos/protocols/proto/dxos/client/services";
1530
+ import { safeAwaitAll } from "@dxos/util";
1528
1531
  var __dxlog_file7 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/identity/identity-service.ts";
1532
+ var DEFAULT_SPACE_SEARCH_TIMEOUT = 1e4;
1529
1533
  var IdentityServiceImpl = class extends Resource {
1530
1534
  constructor(_identityManager, _keyring, _dataSpaceManagerProvider, _createIdentity, _onProfileUpdate) {
1531
1535
  super();
@@ -1555,7 +1559,7 @@ var IdentityServiceImpl = class extends Resource {
1555
1559
  const identity = this._identityManager.identity;
1556
1560
  invariant4(identity, void 0, {
1557
1561
  F: __dxlog_file7,
1558
- L: 54,
1562
+ L: 59,
1559
1563
  S: this,
1560
1564
  A: [
1561
1565
  "identity",
@@ -1589,7 +1593,7 @@ var IdentityServiceImpl = class extends Resource {
1589
1593
  async updateProfile(profile) {
1590
1594
  invariant4(this._identityManager.identity, "Identity not initialized.", {
1591
1595
  F: __dxlog_file7,
1592
- L: 84,
1596
+ L: 89,
1593
1597
  S: this,
1594
1598
  A: [
1595
1599
  "this._identityManager.identity",
@@ -1603,7 +1607,7 @@ var IdentityServiceImpl = class extends Resource {
1603
1607
  async signPresentation({ presentation, nonce }) {
1604
1608
  invariant4(this._identityManager.identity, "Identity not initialized.", {
1605
1609
  F: __dxlog_file7,
1606
- L: 91,
1610
+ L: 96,
1607
1611
  S: this,
1608
1612
  A: [
1609
1613
  "this._identityManager.identity",
@@ -1619,20 +1623,43 @@ var IdentityServiceImpl = class extends Resource {
1619
1623
  });
1620
1624
  }
1621
1625
  async _fixIdentityWithoutDefaultSpace(identity) {
1622
- let hasDefaultSpace = false;
1626
+ let recodedDefaultSpace = false;
1627
+ let foundDefaultSpace = false;
1623
1628
  const dataSpaceManager = this._dataSpaceManagerProvider();
1624
- for (const space of dataSpaceManager.spaces.values()) {
1629
+ const recordedDefaultSpaceTrigger = new Trigger3();
1630
+ const allProcessed = safeAwaitAll(dataSpaceManager.spaces.values(), async (space) => {
1625
1631
  if (space.state === SpaceState.CLOSED) {
1626
1632
  await space.open();
1627
- await space.initializeDataPipeline();
1633
+ const requiresMigration = space.stateUpdate.waitForCondition(() => space.state === SpaceState.REQUIRES_MIGRATION);
1634
+ await Promise.race([
1635
+ space.initializeDataPipeline(),
1636
+ requiresMigration
1637
+ ]);
1628
1638
  }
1629
1639
  if (await dataSpaceManager.isDefaultSpace(space)) {
1640
+ if (foundDefaultSpace) {
1641
+ log6.warn("Multiple default spaces found. Using the first one.", {
1642
+ duplicate: space.id
1643
+ }, {
1644
+ F: __dxlog_file7,
1645
+ L: 127,
1646
+ S: this,
1647
+ C: (f, a) => f(...a)
1648
+ });
1649
+ return;
1650
+ }
1651
+ foundDefaultSpace = true;
1630
1652
  await identity.updateDefaultSpace(space.id);
1631
- hasDefaultSpace = true;
1632
- break;
1653
+ recodedDefaultSpace = true;
1654
+ recordedDefaultSpaceTrigger.wake();
1633
1655
  }
1634
- }
1635
- if (!hasDefaultSpace) {
1656
+ });
1657
+ await Promise.race([
1658
+ allProcessed,
1659
+ recordedDefaultSpaceTrigger.wait(),
1660
+ sleep(DEFAULT_SPACE_SEARCH_TIMEOUT)
1661
+ ]);
1662
+ if (!recodedDefaultSpace) {
1636
1663
  await this._createDefaultSpace(dataSpaceManager);
1637
1664
  }
1638
1665
  }
@@ -1756,7 +1783,7 @@ import { ContextDisposedError as ContextDisposedError2 } from "@dxos/context";
1756
1783
  import { createKeyPair, sign } from "@dxos/crypto";
1757
1784
  import { invariant as invariant9 } from "@dxos/invariant";
1758
1785
  import { PublicKey as PublicKey7 } from "@dxos/keys";
1759
- import { log as log9 } from "@dxos/log";
1786
+ import { log as log10 } from "@dxos/log";
1760
1787
  import { createTeleportProtocolFactory } from "@dxos/network-manager";
1761
1788
  import { InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError3, trace as trace5 } from "@dxos/protocols";
1762
1789
  import { Invitation as Invitation4 } from "@dxos/protocols/proto/dxos/client/services";
@@ -1765,10 +1792,10 @@ import { Options as Options4 } from "@dxos/protocols/proto/dxos/halo/invitations
1765
1792
  import { ComplexSet as ComplexSet3 } from "@dxos/util";
1766
1793
 
1767
1794
  // packages/sdk/client-services/src/packlets/invitations/invitation-guest-extenstion.ts
1768
- import { Trigger as Trigger3 } from "@dxos/async";
1795
+ import { Trigger as Trigger4 } from "@dxos/async";
1769
1796
  import { cancelWithContext as cancelWithContext2, Context as Context4 } from "@dxos/context";
1770
1797
  import { invariant as invariant6 } from "@dxos/invariant";
1771
- import { log as log6 } from "@dxos/log";
1798
+ import { log as log7 } from "@dxos/log";
1772
1799
  import { InvalidInvitationExtensionRoleError, schema as schema2 } from "@dxos/protocols";
1773
1800
  import { Options } from "@dxos/protocols/proto/dxos/halo/invitations";
1774
1801
  import { RpcExtension } from "@dxos/teleport";
@@ -1808,7 +1835,7 @@ var InvitationGuestExtension = class extends RpcExtension {
1808
1835
  this._invitationFlowMutex = _invitationFlowMutex;
1809
1836
  this._callbacks = _callbacks;
1810
1837
  this._ctx = new Context4();
1811
- this._remoteOptionsTrigger = new Trigger3();
1838
+ this._remoteOptionsTrigger = new Trigger4();
1812
1839
  this._invitationFlowLock = null;
1813
1840
  }
1814
1841
  hasFlowLock() {
@@ -1845,14 +1872,14 @@ var InvitationGuestExtension = class extends RpcExtension {
1845
1872
  async onOpen(context) {
1846
1873
  await super.onOpen(context);
1847
1874
  try {
1848
- log6("guest acquire lock", void 0, {
1875
+ log7("guest acquire lock", void 0, {
1849
1876
  F: __dxlog_file9,
1850
1877
  L: 84,
1851
1878
  S: this,
1852
1879
  C: (f, a) => f(...a)
1853
1880
  });
1854
1881
  this._invitationFlowLock = await tryAcquireBeforeContextDisposed(this._ctx, this._invitationFlowMutex);
1855
- log6("guest lock acquired", void 0, {
1882
+ log7("guest lock acquired", void 0, {
1856
1883
  F: __dxlog_file9,
1857
1884
  L: 86,
1858
1885
  S: this,
@@ -1861,7 +1888,7 @@ var InvitationGuestExtension = class extends RpcExtension {
1861
1888
  await cancelWithContext2(this._ctx, this.rpc.InvitationHostService.options({
1862
1889
  role: Options.Role.GUEST
1863
1890
  }));
1864
- log6("options sent", void 0, {
1891
+ log7("options sent", void 0, {
1865
1892
  F: __dxlog_file9,
1866
1893
  L: 88,
1867
1894
  S: this,
@@ -1870,7 +1897,7 @@ var InvitationGuestExtension = class extends RpcExtension {
1870
1897
  await cancelWithContext2(this._ctx, this._remoteOptionsTrigger.wait({
1871
1898
  timeout: OPTIONS_TIMEOUT
1872
1899
  }));
1873
- log6("options received", void 0, {
1900
+ log7("options received", void 0, {
1874
1901
  F: __dxlog_file9,
1875
1902
  L: 90,
1876
1903
  S: this,
@@ -1904,7 +1931,7 @@ var InvitationGuestExtension = class extends RpcExtension {
1904
1931
  if (this._invitationFlowLock != null) {
1905
1932
  this._invitationFlowLock.release();
1906
1933
  this._invitationFlowLock = null;
1907
- log6("invitation flow lock released", void 0, {
1934
+ log7("invitation flow lock released", void 0, {
1908
1935
  F: __dxlog_file9,
1909
1936
  L: 123,
1910
1937
  S: this,
@@ -1915,12 +1942,12 @@ var InvitationGuestExtension = class extends RpcExtension {
1915
1942
  };
1916
1943
 
1917
1944
  // packages/sdk/client-services/src/packlets/invitations/invitation-host-extension.ts
1918
- import { Trigger as Trigger4, scheduleTask as scheduleTask2 } from "@dxos/async";
1945
+ import { Trigger as Trigger5, scheduleTask as scheduleTask2 } from "@dxos/async";
1919
1946
  import { cancelWithContext as cancelWithContext3, Context as Context5 } from "@dxos/context";
1920
1947
  import { randomBytes, verify } from "@dxos/crypto";
1921
1948
  import { invariant as invariant7, InvariantViolation } from "@dxos/invariant";
1922
1949
  import { PublicKey as PublicKey5 } from "@dxos/keys";
1923
- import { log as log7 } from "@dxos/log";
1950
+ import { log as log8 } from "@dxos/log";
1924
1951
  import { InvalidInvitationExtensionRoleError as InvalidInvitationExtensionRoleError2, schema as schema3, trace as trace4 } from "@dxos/protocols";
1925
1952
  import { Invitation as Invitation3 } from "@dxos/protocols/proto/dxos/client/services";
1926
1953
  import { AuthenticationResponse, Options as Options2 } from "@dxos/protocols/proto/dxos/halo/invitations";
@@ -1941,12 +1968,12 @@ var InvitationHostExtension = class extends RpcExtension2 {
1941
1968
  this._invitationFlowMutex = _invitationFlowMutex;
1942
1969
  this._callbacks = _callbacks;
1943
1970
  this._ctx = new Context5();
1944
- this._remoteOptionsTrigger = new Trigger4();
1971
+ this._remoteOptionsTrigger = new Trigger5();
1945
1972
  this._challenge = void 0;
1946
1973
  this.guestProfile = void 0;
1947
1974
  this.authenticationPassed = false;
1948
1975
  this.authenticationRetry = 0;
1949
- this.completedTrigger = new Trigger4();
1976
+ this.completedTrigger = new Trigger5();
1950
1977
  this._invitationFlowLock = null;
1951
1978
  }
1952
1979
  hasFlowLock() {
@@ -1973,7 +2000,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
1973
2000
  introduce: async (request) => {
1974
2001
  const { profile, invitationId } = request;
1975
2002
  const traceId = PublicKey5.random().toHex();
1976
- log7.trace("dxos.sdk.invitation-handler.host.introduce", trace4.begin({
2003
+ log8.trace("dxos.sdk.invitation-handler.host.introduce", trace4.begin({
1977
2004
  id: traceId
1978
2005
  }), {
1979
2006
  F: __dxlog_file10,
@@ -1984,7 +2011,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
1984
2011
  const invitation = this._requireActiveInvitation();
1985
2012
  this._assertInvitationState(Invitation3.State.CONNECTED);
1986
2013
  if (invitationId !== invitation?.invitationId) {
1987
- log7.warn("incorrect invitationId", {
2014
+ log8.warn("incorrect invitationId", {
1988
2015
  expected: invitation.invitationId,
1989
2016
  actual: invitationId
1990
2017
  }, {
@@ -1999,7 +2026,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
1999
2026
  authMethod: Invitation3.AuthMethod.NONE
2000
2027
  };
2001
2028
  }
2002
- log7("guest introduced themselves", {
2029
+ log8("guest introduced themselves", {
2003
2030
  guestProfile: profile
2004
2031
  }, {
2005
2032
  F: __dxlog_file10,
@@ -2010,7 +2037,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
2010
2037
  this.guestProfile = profile;
2011
2038
  this._callbacks.onStateUpdate(Invitation3.State.READY_FOR_AUTHENTICATION);
2012
2039
  this._challenge = invitation.authMethod === Invitation3.AuthMethod.KNOWN_PUBLIC_KEY ? randomBytes(32) : void 0;
2013
- log7.trace("dxos.sdk.invitation-handler.host.introduce", trace4.end({
2040
+ log8.trace("dxos.sdk.invitation-handler.host.introduce", trace4.end({
2014
2041
  id: traceId
2015
2042
  }), {
2016
2043
  F: __dxlog_file10,
@@ -2025,7 +2052,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
2025
2052
  },
2026
2053
  authenticate: async ({ authCode: code, signedChallenge }) => {
2027
2054
  const traceId = PublicKey5.random().toHex();
2028
- log7.trace("dxos.sdk.invitation-handler.host.authenticate", trace4.begin({
2055
+ log8.trace("dxos.sdk.invitation-handler.host.authenticate", trace4.begin({
2029
2056
  id: traceId
2030
2057
  }), {
2031
2058
  F: __dxlog_file10,
@@ -2034,7 +2061,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
2034
2061
  C: (f, a) => f(...a)
2035
2062
  });
2036
2063
  const invitation = this._requireActiveInvitation();
2037
- log7("received authentication request", {
2064
+ log8("received authentication request", {
2038
2065
  authCode: code
2039
2066
  }, {
2040
2067
  F: __dxlog_file10,
@@ -2050,7 +2077,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
2050
2077
  this._callbacks.onStateUpdate(Invitation3.State.AUTHENTICATING);
2051
2078
  switch (invitation.authMethod) {
2052
2079
  case Invitation3.AuthMethod.NONE: {
2053
- log7("authentication not required", void 0, {
2080
+ log8("authentication not required", void 0, {
2054
2081
  F: __dxlog_file10,
2055
2082
  L: 152,
2056
2083
  S: this,
@@ -2086,7 +2113,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
2086
2113
  break;
2087
2114
  }
2088
2115
  default: {
2089
- log7.error("invalid authentication method", {
2116
+ log8.error("invalid authentication method", {
2090
2117
  authMethod: invitation.authMethod
2091
2118
  }, {
2092
2119
  F: __dxlog_file10,
@@ -2108,7 +2135,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
2108
2135
  status
2109
2136
  };
2110
2137
  }
2111
- log7.trace("dxos.sdk.invitation-handler.host.authenticate", trace4.end({
2138
+ log8.trace("dxos.sdk.invitation-handler.host.authenticate", trace4.end({
2112
2139
  id: traceId,
2113
2140
  data: {
2114
2141
  status
@@ -2125,7 +2152,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
2125
2152
  },
2126
2153
  admit: async (request) => {
2127
2154
  const traceId = PublicKey5.random().toHex();
2128
- log7.trace("dxos.sdk.invitation-handler.host.admit", trace4.begin({
2155
+ log8.trace("dxos.sdk.invitation-handler.host.admit", trace4.begin({
2129
2156
  id: traceId
2130
2157
  }), {
2131
2158
  F: __dxlog_file10,
@@ -2142,7 +2169,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
2142
2169
  }
2143
2170
  }
2144
2171
  const response = await this._callbacks.admit(request);
2145
- log7.trace("dxos.sdk.invitation-handler.host.admit", trace4.end({
2172
+ log8.trace("dxos.sdk.invitation-handler.host.admit", trace4.end({
2146
2173
  id: traceId
2147
2174
  }), {
2148
2175
  F: __dxlog_file10,
@@ -2162,14 +2189,14 @@ var InvitationHostExtension = class extends RpcExtension2 {
2162
2189
  async onOpen(context) {
2163
2190
  await super.onOpen(context);
2164
2191
  try {
2165
- log7("host acquire lock", void 0, {
2192
+ log8("host acquire lock", void 0, {
2166
2193
  F: __dxlog_file10,
2167
2194
  L: 237,
2168
2195
  S: this,
2169
2196
  C: (f, a) => f(...a)
2170
2197
  });
2171
2198
  this._invitationFlowLock = await tryAcquireBeforeContextDisposed(this._ctx, this._invitationFlowMutex);
2172
- log7("host lock acquired", void 0, {
2199
+ log8("host lock acquired", void 0, {
2173
2200
  F: __dxlog_file10,
2174
2201
  L: 239,
2175
2202
  S: this,
@@ -2180,7 +2207,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
2180
2207
  await this.rpc.InvitationHostService.options({
2181
2208
  role: Options2.Role.HOST
2182
2209
  });
2183
- log7("options sent", void 0, {
2210
+ log8("options sent", void 0, {
2184
2211
  F: __dxlog_file10,
2185
2212
  L: 243,
2186
2213
  S: this,
@@ -2189,7 +2216,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
2189
2216
  await cancelWithContext3(this._ctx, this._remoteOptionsTrigger.wait({
2190
2217
  timeout: OPTIONS_TIMEOUT2
2191
2218
  }));
2192
- log7("options received", void 0, {
2219
+ log8("options received", void 0, {
2193
2220
  F: __dxlog_file10,
2194
2221
  L: 245,
2195
2222
  S: this,
@@ -2243,7 +2270,7 @@ var InvitationHostExtension = class extends RpcExtension2 {
2243
2270
  if (this._invitationFlowLock != null) {
2244
2271
  this._invitationFlowLock?.release();
2245
2272
  this._invitationFlowLock = null;
2246
- log7("invitation flow lock released", void 0, {
2273
+ log8("invitation flow lock released", void 0, {
2247
2274
  F: __dxlog_file10,
2248
2275
  L: 300,
2249
2276
  S: this,
@@ -2257,7 +2284,7 @@ var isAuthenticationRequired = (invitation) => invitation.authMethod !== Invitat
2257
2284
  // packages/sdk/client-services/src/packlets/invitations/invitation-topology.ts
2258
2285
  import { invariant as invariant8 } from "@dxos/invariant";
2259
2286
  import { PublicKey as PublicKey6 } from "@dxos/keys";
2260
- import { log as log8 } from "@dxos/log";
2287
+ import { log as log9 } from "@dxos/log";
2261
2288
  import { Options as Options3 } from "@dxos/protocols/proto/dxos/halo/invitations";
2262
2289
  import { ComplexSet as ComplexSet2 } from "@dxos/util";
2263
2290
  var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitation-topology.ts";
@@ -2299,7 +2326,7 @@ var InvitationTopology = class {
2299
2326
  const firstUnknownPeer = candidates.find((peerId) => !this._seenPeers.has(peerId));
2300
2327
  this._seenPeers = new ComplexSet2(PublicKey6.hash, allPeers.filter((peerId) => this._seenPeers.has(peerId)));
2301
2328
  if (firstUnknownPeer != null) {
2302
- log8("invitation connect", {
2329
+ log9("invitation connect", {
2303
2330
  ownPeerId,
2304
2331
  remotePeerId: firstUnknownPeer
2305
2332
  }, {
@@ -2384,7 +2411,7 @@ var InvitationsHandler = class {
2384
2411
  scheduleTask3(connectionCtx, async () => {
2385
2412
  const traceId = PublicKey7.random().toHex();
2386
2413
  try {
2387
- log9.trace("dxos.sdk.invitations-handler.host.onOpen", trace5.begin({
2414
+ log10.trace("dxos.sdk.invitations-handler.host.onOpen", trace5.begin({
2388
2415
  id: traceId
2389
2416
  }), {
2390
2417
  F: __dxlog_file12,
@@ -2392,7 +2419,7 @@ var InvitationsHandler = class {
2392
2419
  S: this,
2393
2420
  C: (f, a) => f(...a)
2394
2421
  });
2395
- log9("connected", {
2422
+ log10("connected", {
2396
2423
  ...protocol.toJSON()
2397
2424
  }, {
2398
2425
  F: __dxlog_file12,
@@ -2403,7 +2430,7 @@ var InvitationsHandler = class {
2403
2430
  const deviceKey = await extension.completedTrigger.wait({
2404
2431
  timeout: invitation.timeout
2405
2432
  });
2406
- log9("admitted guest", {
2433
+ log10("admitted guest", {
2407
2434
  guest: deviceKey,
2408
2435
  ...protocol.toJSON()
2409
2436
  }, {
@@ -2413,7 +2440,7 @@ var InvitationsHandler = class {
2413
2440
  C: (f, a) => f(...a)
2414
2441
  });
2415
2442
  guardedState.set(extension, Invitation4.State.SUCCESS);
2416
- log9.trace("dxos.sdk.invitations-handler.host.onOpen", trace5.end({
2443
+ log10.trace("dxos.sdk.invitations-handler.host.onOpen", trace5.end({
2417
2444
  id: traceId
2418
2445
  }), {
2419
2446
  F: __dxlog_file12,
@@ -2428,7 +2455,7 @@ var InvitationsHandler = class {
2428
2455
  } catch (err) {
2429
2456
  if (err instanceof TimeoutError) {
2430
2457
  if (guardedState.set(extension, Invitation4.State.TIMEOUT)) {
2431
- log9("timeout", {
2458
+ log10("timeout", {
2432
2459
  ...protocol.toJSON()
2433
2460
  }, {
2434
2461
  F: __dxlog_file12,
@@ -2439,7 +2466,7 @@ var InvitationsHandler = class {
2439
2466
  }
2440
2467
  } else {
2441
2468
  if (guardedState.error(extension, err)) {
2442
- log9.error("failed", err, {
2469
+ log10.error("failed", err, {
2443
2470
  F: __dxlog_file12,
2444
2471
  L: 133,
2445
2472
  S: this,
@@ -2447,7 +2474,7 @@ var InvitationsHandler = class {
2447
2474
  });
2448
2475
  }
2449
2476
  }
2450
- log9.trace("dxos.sdk.invitations-handler.host.onOpen", trace5.error({
2477
+ log10.trace("dxos.sdk.invitations-handler.host.onOpen", trace5.error({
2451
2478
  id: traceId,
2452
2479
  error: err
2453
2480
  }), {
@@ -2462,7 +2489,7 @@ var InvitationsHandler = class {
2462
2489
  },
2463
2490
  onError: (err) => {
2464
2491
  if (err instanceof InvalidInvitationExtensionRoleError3) {
2465
- log9("invalid role", {
2492
+ log10("invalid role", {
2466
2493
  ...err.context
2467
2494
  }, {
2468
2495
  F: __dxlog_file12,
@@ -2474,7 +2501,7 @@ var InvitationsHandler = class {
2474
2501
  }
2475
2502
  if (err instanceof TimeoutError) {
2476
2503
  if (guardedState.set(extension, Invitation4.State.TIMEOUT)) {
2477
- log9("timeout", {
2504
+ log10("timeout", {
2478
2505
  err
2479
2506
  }, {
2480
2507
  F: __dxlog_file12,
@@ -2485,7 +2512,7 @@ var InvitationsHandler = class {
2485
2512
  }
2486
2513
  } else {
2487
2514
  if (guardedState.error(extension, err)) {
2488
- log9.error("failed", err, {
2515
+ log10.error("failed", err, {
2489
2516
  F: __dxlog_file12,
2490
2517
  L: 153,
2491
2518
  S: this,
@@ -2499,7 +2526,7 @@ var InvitationsHandler = class {
2499
2526
  };
2500
2527
  if (invitation.lifetime && invitation.created) {
2501
2528
  if (invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now()) {
2502
- log9.warn("invitation has already expired", void 0, {
2529
+ log10.warn("invitation has already expired", void 0, {
2503
2530
  F: __dxlog_file12,
2504
2531
  L: 164,
2505
2532
  S: this,
@@ -2536,7 +2563,7 @@ var InvitationsHandler = class {
2536
2563
  const guardedState = this._createGuardedState(ctx, invitation, stream);
2537
2564
  const shouldCancelInvitationFlow = (extension) => {
2538
2565
  const isLockedByAnotherConnection = guardedState.mutex.isLocked() && !extension.hasFlowLock();
2539
- log9("should cancel invitation flow", {
2566
+ log10("should cancel invitation flow", {
2540
2567
  isLockedByAnotherConnection,
2541
2568
  invitationType: Invitation4.Type.DELEGATED,
2542
2569
  triedPeers: triedPeersIds.size
@@ -2564,7 +2591,7 @@ var InvitationsHandler = class {
2564
2591
  return;
2565
2592
  }
2566
2593
  connectionCtx.onDispose(async () => {
2567
- log9("extension disposed", {
2594
+ log10("extension disposed", {
2568
2595
  admitted,
2569
2596
  currentState: guardedState.current.state
2570
2597
  }, {
@@ -2583,7 +2610,7 @@ var InvitationsHandler = class {
2583
2610
  scheduleTask3(connectionCtx, async () => {
2584
2611
  const traceId = PublicKey7.random().toHex();
2585
2612
  try {
2586
- log9.trace("dxos.sdk.invitations-handler.guest.onOpen", trace5.begin({
2613
+ log10.trace("dxos.sdk.invitations-handler.guest.onOpen", trace5.begin({
2587
2614
  id: traceId
2588
2615
  }), {
2589
2616
  F: __dxlog_file12,
@@ -2595,7 +2622,7 @@ var InvitationsHandler = class {
2595
2622
  guardedState.set(extension, Invitation4.State.TIMEOUT);
2596
2623
  extensionCtx.close();
2597
2624
  }, timeout);
2598
- log9("connected", {
2625
+ log10("connected", {
2599
2626
  ...protocol.toJSON()
2600
2627
  }, {
2601
2628
  F: __dxlog_file12,
@@ -2604,7 +2631,7 @@ var InvitationsHandler = class {
2604
2631
  C: (f, a) => f(...a)
2605
2632
  });
2606
2633
  guardedState.set(extension, Invitation4.State.CONNECTED);
2607
- log9("introduce", {
2634
+ log10("introduce", {
2608
2635
  ...protocol.toJSON()
2609
2636
  }, {
2610
2637
  F: __dxlog_file12,
@@ -2616,7 +2643,7 @@ var InvitationsHandler = class {
2616
2643
  invitationId: invitation.invitationId,
2617
2644
  ...protocol.createIntroduction()
2618
2645
  });
2619
- log9("introduce response", {
2646
+ log10("introduce response", {
2620
2647
  ...protocol.toJSON(),
2621
2648
  response: introductionResponse
2622
2649
  }, {
@@ -2638,7 +2665,7 @@ var InvitationsHandler = class {
2638
2665
  break;
2639
2666
  }
2640
2667
  }
2641
- log9("request admission", {
2668
+ log10("request admission", {
2642
2669
  ...protocol.toJSON()
2643
2670
  }, {
2644
2671
  F: __dxlog_file12,
@@ -2650,7 +2677,7 @@ var InvitationsHandler = class {
2650
2677
  const admissionResponse = await extension.rpc.InvitationHostService.admit(admissionRequest);
2651
2678
  admitted = true;
2652
2679
  const result = await protocol.accept(admissionResponse, admissionRequest);
2653
- log9("admitted by host", {
2680
+ log10("admitted by host", {
2654
2681
  ...protocol.toJSON()
2655
2682
  }, {
2656
2683
  F: __dxlog_file12,
@@ -2663,7 +2690,7 @@ var InvitationsHandler = class {
2663
2690
  ...result,
2664
2691
  state: Invitation4.State.SUCCESS
2665
2692
  });
2666
- log9.trace("dxos.sdk.invitations-handler.guest.onOpen", trace5.end({
2693
+ log10.trace("dxos.sdk.invitations-handler.guest.onOpen", trace5.end({
2667
2694
  id: traceId
2668
2695
  }), {
2669
2696
  F: __dxlog_file12,
@@ -2673,7 +2700,7 @@ var InvitationsHandler = class {
2673
2700
  });
2674
2701
  } catch (err) {
2675
2702
  if (err instanceof TimeoutError) {
2676
- log9("timeout", {
2703
+ log10("timeout", {
2677
2704
  ...protocol.toJSON()
2678
2705
  }, {
2679
2706
  F: __dxlog_file12,
@@ -2683,7 +2710,7 @@ var InvitationsHandler = class {
2683
2710
  });
2684
2711
  guardedState.set(extension, Invitation4.State.TIMEOUT);
2685
2712
  } else {
2686
- log9("auth failed", err, {
2713
+ log10("auth failed", err, {
2687
2714
  F: __dxlog_file12,
2688
2715
  L: 314,
2689
2716
  S: this,
@@ -2692,7 +2719,7 @@ var InvitationsHandler = class {
2692
2719
  guardedState.error(extension, err);
2693
2720
  }
2694
2721
  extensionCtx.close(err);
2695
- log9.trace("dxos.sdk.invitations-handler.guest.onOpen", trace5.error({
2722
+ log10.trace("dxos.sdk.invitations-handler.guest.onOpen", trace5.error({
2696
2723
  id: traceId,
2697
2724
  error: err
2698
2725
  }), {
@@ -2709,7 +2736,7 @@ var InvitationsHandler = class {
2709
2736
  return;
2710
2737
  }
2711
2738
  if (err instanceof TimeoutError) {
2712
- log9("timeout", {
2739
+ log10("timeout", {
2713
2740
  ...protocol.toJSON()
2714
2741
  }, {
2715
2742
  F: __dxlog_file12,
@@ -2719,7 +2746,7 @@ var InvitationsHandler = class {
2719
2746
  });
2720
2747
  guardedState.set(extension, Invitation4.State.TIMEOUT);
2721
2748
  } else {
2722
- log9("auth failed", err, {
2749
+ log10("auth failed", err, {
2723
2750
  F: __dxlog_file12,
2724
2751
  L: 330,
2725
2752
  S: this,
@@ -2832,7 +2859,7 @@ var InvitationsHandler = class {
2832
2859
  };
2833
2860
  }
2834
2861
  _logStateUpdate(invitation, actor, newState) {
2835
- log9("invitation state update", {
2862
+ log10("invitation state update", {
2836
2863
  actor: actor?.constructor.name,
2837
2864
  newState: stateToString(newState),
2838
2865
  oldState: stateToString(invitation.state)
@@ -2854,7 +2881,7 @@ var InvitationsHandler = class {
2854
2881
  }
2855
2882
  async _handleGuestOtpAuth(extension, setState, authenticated, options) {
2856
2883
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
2857
- log9("guest waiting for authentication code...", void 0, {
2884
+ log10("guest waiting for authentication code...", void 0, {
2858
2885
  F: __dxlog_file12,
2859
2886
  L: 462,
2860
2887
  S: this,
@@ -2862,7 +2889,7 @@ var InvitationsHandler = class {
2862
2889
  });
2863
2890
  setState(Invitation4.State.READY_FOR_AUTHENTICATION);
2864
2891
  const authCode = await authenticated.wait(options);
2865
- log9("sending authentication request", void 0, {
2892
+ log10("sending authentication request", void 0, {
2866
2893
  F: __dxlog_file12,
2867
2894
  L: 466,
2868
2895
  S: this,
@@ -2879,7 +2906,7 @@ var InvitationsHandler = class {
2879
2906
  if (attempt === MAX_OTP_ATTEMPTS) {
2880
2907
  throw new Error(`Maximum retry attempts: ${MAX_OTP_ATTEMPTS}`);
2881
2908
  } else {
2882
- log9("retrying invalid code", {
2909
+ log10("retrying invalid code", {
2883
2910
  attempt
2884
2911
  }, {
2885
2912
  F: __dxlog_file12,
@@ -2899,7 +2926,7 @@ var InvitationsHandler = class {
2899
2926
  if (introductionResponse.challenge == null) {
2900
2927
  throw new Error("challenge missing in the introduction");
2901
2928
  }
2902
- log9("sending authentication request", void 0, {
2929
+ log10("sending authentication request", void 0, {
2903
2930
  F: __dxlog_file12,
2904
2931
  L: 496,
2905
2932
  S: this,
@@ -3024,7 +3051,7 @@ var InvitationsServiceImpl = class {
3024
3051
  import { createAdmissionCredentials, createCancelDelegatedSpaceInvitationCredential, createDelegatedSpaceInvitationCredential, getCredentialAssertion as getCredentialAssertion2 } from "@dxos/credentials";
3025
3052
  import { writeMessages as writeMessages2 } from "@dxos/feed-store";
3026
3053
  import { invariant as invariant10 } from "@dxos/invariant";
3027
- import { log as log10 } from "@dxos/log";
3054
+ import { log as log11 } from "@dxos/log";
3028
3055
  import { AlreadyJoinedError as AlreadyJoinedError2, AuthorizationError, InvalidInvitationError, SpaceNotFoundError } from "@dxos/protocols";
3029
3056
  import { Invitation as Invitation5 } from "@dxos/protocols/proto/dxos/client/services";
3030
3057
  import { SpaceMember as SpaceMember2 } from "@dxos/protocols/proto/dxos/halo/credentials";
@@ -3094,7 +3121,7 @@ var SpaceInvitationProtocol = class {
3094
3121
  if (space.inner.spaceState.getMemberRole(identityKey) !== SpaceMember2.Role.REMOVED) {
3095
3122
  throw new AlreadyJoinedError2();
3096
3123
  }
3097
- log10("writing guest credentials", {
3124
+ log11("writing guest credentials", {
3098
3125
  host: this._signingContext.deviceKey,
3099
3126
  guest: deviceKey
3100
3127
  }, {
@@ -3162,7 +3189,7 @@ var SpaceInvitationProtocol = class {
3162
3189
  ]
3163
3190
  });
3164
3191
  }
3165
- log10("writing delegate space invitation", {
3192
+ log11("writing delegate space invitation", {
3166
3193
  host: this._signingContext.deviceKey,
3167
3194
  id: invitation.invitationId
3168
3195
  }, {
@@ -3223,7 +3250,7 @@ var SpaceInvitationProtocol = class {
3223
3250
  ""
3224
3251
  ]
3225
3252
  });
3226
- log10("cancelling delegated space invitation", {
3253
+ log11("cancelling delegated space invitation", {
3227
3254
  host: this._signingContext.deviceKey,
3228
3255
  id: invitation.invitationId
3229
3256
  }, {
@@ -3318,14 +3345,14 @@ var SpaceInvitationProtocol = class {
3318
3345
  };
3319
3346
 
3320
3347
  // packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts
3321
- import { Event as Event3, PushStream, TimeoutError as TimeoutError2, Trigger as Trigger5 } from "@dxos/async";
3348
+ import { Event as Event3, PushStream, TimeoutError as TimeoutError2, Trigger as Trigger6 } from "@dxos/async";
3322
3349
  import { AuthenticatingInvitation, AUTHENTICATION_CODE_LENGTH, CancellableInvitation, INVITATION_TIMEOUT as INVITATION_TIMEOUT2 } from "@dxos/client-protocol";
3323
3350
  import { Context as Context6 } from "@dxos/context";
3324
3351
  import { generatePasscode } from "@dxos/credentials";
3325
3352
  import { hasInvitationExpired } from "@dxos/echo-pipeline";
3326
3353
  import { invariant as invariant11 } from "@dxos/invariant";
3327
3354
  import { PublicKey as PublicKey8 } from "@dxos/keys";
3328
- import { log as log11 } from "@dxos/log";
3355
+ import { log as log12 } from "@dxos/log";
3329
3356
  import { Invitation as Invitation6 } from "@dxos/protocols/proto/dxos/client/services";
3330
3357
  import { SpaceMember as SpaceMember3 } from "@dxos/protocols/proto/dxos/halo/credentials";
3331
3358
  var __dxlog_file14 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-manager.ts";
@@ -3370,7 +3397,7 @@ var InvitationsManager = class {
3370
3397
  try {
3371
3398
  await this._persistIfRequired(handler, stream, invitation);
3372
3399
  } catch (err) {
3373
- log11.catch(err, void 0, {
3400
+ log12.catch(err, void 0, {
3374
3401
  F: __dxlog_file14,
3375
3402
  L: 82,
3376
3403
  S: this,
@@ -3412,7 +3439,7 @@ var InvitationsManager = class {
3412
3439
  invitations: cInvitations.map((invitation) => invitation.get())
3413
3440
  };
3414
3441
  } catch (err) {
3415
- log11.catch(err, void 0, {
3442
+ log12.catch(err, void 0, {
3416
3443
  F: __dxlog_file14,
3417
3444
  L: 110,
3418
3445
  S: this,
@@ -3444,7 +3471,7 @@ var InvitationsManager = class {
3444
3471
  return invitation;
3445
3472
  }
3446
3473
  async authenticate({ invitationId, authCode }) {
3447
- log11("authenticating...", void 0, {
3474
+ log12("authenticating...", void 0, {
3448
3475
  F: __dxlog_file14,
3449
3476
  L: 140,
3450
3477
  S: this,
@@ -3461,7 +3488,7 @@ var InvitationsManager = class {
3461
3488
  });
3462
3489
  const observable = this._acceptInvitations.get(invitationId);
3463
3490
  if (!observable) {
3464
- log11.warn("invalid invitation", {
3491
+ log12.warn("invalid invitation", {
3465
3492
  invitationId
3466
3493
  }, {
3467
3494
  F: __dxlog_file14,
@@ -3474,7 +3501,7 @@ var InvitationsManager = class {
3474
3501
  }
3475
3502
  }
3476
3503
  async cancelInvitation({ invitationId }) {
3477
- log11("cancelInvitation...", {
3504
+ log12("cancelInvitation...", {
3478
3505
  invitationId
3479
3506
  }, {
3480
3507
  F: __dxlog_file14,
@@ -3559,7 +3586,7 @@ var InvitationsManager = class {
3559
3586
  }
3560
3587
  });
3561
3588
  ctx.onDispose(() => {
3562
- log11("complete", {
3589
+ log12("complete", {
3563
3590
  ...handler.toJSON()
3564
3591
  }, {
3565
3592
  F: __dxlog_file14,
@@ -3587,12 +3614,12 @@ var InvitationsManager = class {
3587
3614
  };
3588
3615
  }
3589
3616
  _createObservableAcceptingInvitation(handler, initialState) {
3590
- const otpEnteredTrigger = new Trigger5();
3617
+ const otpEnteredTrigger = new Trigger6();
3591
3618
  const stream = new PushStream();
3592
3619
  const ctx = new Context6({
3593
3620
  onError: (err) => {
3594
3621
  if (err instanceof TimeoutError2) {
3595
- log11("timeout", {
3622
+ log12("timeout", {
3596
3623
  ...handler.toJSON()
3597
3624
  }, {
3598
3625
  F: __dxlog_file14,
@@ -3605,7 +3632,7 @@ var InvitationsManager = class {
3605
3632
  state: Invitation6.State.TIMEOUT
3606
3633
  });
3607
3634
  } else {
3608
- log11.warn("auth failed", err, {
3635
+ log12.warn("auth failed", err, {
3609
3636
  F: __dxlog_file14,
3610
3637
  L: 264,
3611
3638
  S: this,
@@ -3620,7 +3647,7 @@ var InvitationsManager = class {
3620
3647
  }
3621
3648
  });
3622
3649
  ctx.onDispose(() => {
3623
- log11("complete", {
3650
+ log12("complete", {
3624
3651
  ...handler.toJSON()
3625
3652
  }, {
3626
3653
  F: __dxlog_file14,
@@ -3667,7 +3694,7 @@ var InvitationsManager = class {
3667
3694
  try {
3668
3695
  await this._metadataStore.removeInvitation(invitation.invitationId);
3669
3696
  } catch (err) {
3670
- log11.catch(err, void 0, {
3697
+ log12.catch(err, void 0, {
3671
3698
  F: __dxlog_file14,
3672
3699
  L: 307,
3673
3700
  S: this,
@@ -3683,33 +3710,40 @@ var InvitationsManager = class {
3683
3710
  };
3684
3711
 
3685
3712
  // 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";
3713
+ import { Event as Event6, Mutex as Mutex2, scheduleTask as scheduleTask5, sleep as sleep3, synchronized, trackLeaks } from "@dxos/async";
3687
3714
  import { AUTH_TIMEOUT as AUTH_TIMEOUT2 } from "@dxos/client-protocol";
3688
- import { Context as Context8, ContextDisposedError as ContextDisposedError3, cancelWithContext as cancelWithContext4 } from "@dxos/context";
3715
+ import { Context as Context8, ContextDisposedError as ContextDisposedError3, cancelWithContext as cancelWithContext5 } from "@dxos/context";
3689
3716
  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";
3717
+ import { createMappedFeedWriter } from "@dxos/echo-pipeline";
3718
+ import { SpaceDocVersion } from "@dxos/echo-protocol";
3719
+ import { failedInvariant } from "@dxos/invariant";
3693
3720
  import { PublicKey as PublicKey10 } from "@dxos/keys";
3694
- import { log as log13 } from "@dxos/log";
3721
+ import { log as log15 } from "@dxos/log";
3695
3722
  import { CancelledError, SystemError } from "@dxos/protocols";
3696
- import { CreateEpochRequest, SpaceState as SpaceState2 } from "@dxos/protocols/proto/dxos/client/services";
3723
+ import { SpaceState as SpaceState2 } from "@dxos/protocols/proto/dxos/client/services";
3697
3724
  import { AdmittedFeed as AdmittedFeed3, SpaceMember as SpaceMember4 } from "@dxos/protocols/proto/dxos/halo/credentials";
3698
3725
  import { Timeframe as Timeframe3 } from "@dxos/timeframe";
3699
3726
  import { trace as trace6 } from "@dxos/tracing";
3700
- import { ComplexSet as ComplexSet5, assignDeep } from "@dxos/util";
3727
+ import { ComplexSet as ComplexSet5 } from "@dxos/util";
3701
3728
 
3702
3729
  // packages/sdk/client-services/src/packlets/spaces/automerge-space-state.ts
3703
3730
  import { Event as Event4 } from "@dxos/async";
3731
+ import { Resource as Resource2 } from "@dxos/context";
3704
3732
  import { checkCredentialType } from "@dxos/credentials";
3705
- var AutomergeSpaceState = class {
3733
+ var AutomergeSpaceState = class extends Resource2 {
3706
3734
  constructor(_onNewRoot) {
3735
+ super();
3707
3736
  this._onNewRoot = _onNewRoot;
3708
3737
  this.rootUrl = void 0;
3709
3738
  this.lastEpoch = void 0;
3710
3739
  this.onNewEpoch = new Event4();
3711
3740
  this._isProcessingRootDocs = false;
3712
3741
  }
3742
+ async _open(ctx) {
3743
+ }
3744
+ async _close(ctx) {
3745
+ this._isProcessingRootDocs = false;
3746
+ }
3713
3747
  async processCredential(credential) {
3714
3748
  if (!checkCredentialType(credential, "dxos.halo.credentials.Epoch")) {
3715
3749
  return;
@@ -3737,16 +3771,162 @@ var AutomergeSpaceState = class {
3737
3771
  }
3738
3772
  };
3739
3773
 
3774
+ // packages/sdk/client-services/src/packlets/spaces/epoch-migrations.ts
3775
+ import { asyncTimeout as asyncTimeout2 } from "@dxos/async";
3776
+ import { next as am } from "@dxos/automerge/automerge";
3777
+ import { cancelWithContext as cancelWithContext4 } from "@dxos/context";
3778
+ import { convertLegacyReferences, convertLegacySpaceRootDoc, findInlineObjectOfType, migrateDocument } from "@dxos/echo-db";
3779
+ import { AutomergeDocumentLoaderImpl } from "@dxos/echo-pipeline";
3780
+ import { TYPE_PROPERTIES } from "@dxos/echo-schema";
3781
+ import { invariant as invariant12 } from "@dxos/invariant";
3782
+ import { log as log13 } from "@dxos/log";
3783
+ import { CreateEpochRequest } from "@dxos/protocols/proto/dxos/client/services";
3784
+ import { assignDeep } from "@dxos/util";
3785
+ var __dxlog_file15 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/epoch-migrations.ts";
3786
+ var runEpochMigration = async (ctx, context) => {
3787
+ switch (context.migration) {
3788
+ case CreateEpochRequest.Migration.INIT_AUTOMERGE: {
3789
+ const document = context.repo.create();
3790
+ await context.repo.flush();
3791
+ return {
3792
+ newRoot: document.url
3793
+ };
3794
+ }
3795
+ case CreateEpochRequest.Migration.PRUNE_AUTOMERGE_ROOT_HISTORY: {
3796
+ if (!context.currentRoot) {
3797
+ throw new Error("Space does not have an automerge root");
3798
+ }
3799
+ const rootHandle = context.repo.find(context.currentRoot);
3800
+ await cancelWithContext4(ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
3801
+ const newRoot = context.repo.create(rootHandle.docSync());
3802
+ await context.repo.flush();
3803
+ return {
3804
+ newRoot: newRoot.url
3805
+ };
3806
+ }
3807
+ case CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT: {
3808
+ log13.info("Fragmenting", void 0, {
3809
+ F: __dxlog_file15,
3810
+ L: 63,
3811
+ S: void 0,
3812
+ C: (f, a) => f(...a)
3813
+ });
3814
+ const currentRootUrl = context.currentRoot;
3815
+ const rootHandle = context.repo.find(currentRootUrl);
3816
+ await cancelWithContext4(ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
3817
+ const objects = Object.entries(rootHandle.docSync().objects);
3818
+ const properties = findInlineObjectOfType(rootHandle.docSync(), TYPE_PROPERTIES);
3819
+ const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
3820
+ invariant12(properties, "Properties not found", {
3821
+ F: __dxlog_file15,
3822
+ L: 73,
3823
+ S: void 0,
3824
+ A: [
3825
+ "properties",
3826
+ "'Properties not found'"
3827
+ ]
3828
+ });
3829
+ const newSpaceDoc = {
3830
+ ...rootHandle.docSync(),
3831
+ objects: Object.fromEntries([
3832
+ properties
3833
+ ])
3834
+ };
3835
+ const newRoot = context.repo.create(newSpaceDoc);
3836
+ invariant12(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3837
+ F: __dxlog_file15,
3838
+ L: 78,
3839
+ S: void 0,
3840
+ A: [
3841
+ "typeof newRoot.url === 'string' && newRoot.url.length > 0",
3842
+ ""
3843
+ ]
3844
+ });
3845
+ const docLoader = new AutomergeDocumentLoaderImpl(context.spaceId, context.repo, context.spaceKey);
3846
+ await docLoader.loadSpaceRootDocHandle(ctx, {
3847
+ rootUrl: newRoot.url
3848
+ });
3849
+ otherObjects.forEach(([key, value]) => {
3850
+ const handle = docLoader.createDocumentForObject(key);
3851
+ handle.change((doc) => {
3852
+ assignDeep(doc, [
3853
+ "objects",
3854
+ key
3855
+ ], value);
3856
+ });
3857
+ });
3858
+ await context.repo.flush();
3859
+ return {
3860
+ newRoot: newRoot.url
3861
+ };
3862
+ }
3863
+ case CreateEpochRequest.Migration.MIGRATE_REFERENCES_TO_DXN: {
3864
+ const currentRootUrl = context.currentRoot;
3865
+ const rootHandle = context.repo.find(currentRootUrl);
3866
+ await cancelWithContext4(ctx, asyncTimeout2(rootHandle.whenReady(), 1e4));
3867
+ invariant12(rootHandle.docSync(), "Root doc not found", {
3868
+ F: __dxlog_file15,
3869
+ L: 100,
3870
+ S: void 0,
3871
+ A: [
3872
+ "rootHandle.docSync()",
3873
+ "'Root doc not found'"
3874
+ ]
3875
+ });
3876
+ const newRootContent = await convertLegacySpaceRootDoc(structuredClone(rootHandle.docSync()));
3877
+ for (const [id, url] of Object.entries(newRootContent.links ?? {})) {
3878
+ const handle = context.repo.find(url);
3879
+ await cancelWithContext4(ctx, asyncTimeout2(handle.whenReady(), 1e4));
3880
+ invariant12(handle.docSync(), "Doc not found", {
3881
+ F: __dxlog_file15,
3882
+ L: 107,
3883
+ S: void 0,
3884
+ A: [
3885
+ "handle.docSync()",
3886
+ "'Doc not found'"
3887
+ ]
3888
+ });
3889
+ const newDoc = await convertLegacyReferences(structuredClone(handle.docSync()));
3890
+ const migratedDoc = migrateDocument(handle.docSync(), newDoc);
3891
+ const newHandle = context.repo.import(am.save(migratedDoc));
3892
+ newRootContent.links[id] = newHandle.url;
3893
+ }
3894
+ const migratedRoot = migrateDocument(rootHandle.docSync(), newRootContent);
3895
+ const newRoot = context.repo.import(am.save(migratedRoot));
3896
+ await context.repo.flush();
3897
+ return {
3898
+ newRoot: newRoot.url
3899
+ };
3900
+ }
3901
+ case CreateEpochRequest.Migration.REPLACE_AUTOMERGE_ROOT: {
3902
+ invariant12(context.newAutomergeRoot, void 0, {
3903
+ F: __dxlog_file15,
3904
+ L: 124,
3905
+ S: void 0,
3906
+ A: [
3907
+ "context.newAutomergeRoot",
3908
+ ""
3909
+ ]
3910
+ });
3911
+ await context.repo.flush();
3912
+ return {
3913
+ newRoot: context.newAutomergeRoot
3914
+ };
3915
+ }
3916
+ }
3917
+ return {};
3918
+ };
3919
+
3740
3920
  // packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts
3741
- import { DeferredTask, Event as Event5, scheduleTask as scheduleTask4, sleep, TimeoutError as TimeoutError3, Trigger as Trigger6 } from "@dxos/async";
3921
+ import { DeferredTask, Event as Event5, scheduleTask as scheduleTask4, sleep as sleep2, TimeoutError as TimeoutError3, Trigger as Trigger7 } from "@dxos/async";
3742
3922
  import { Context as Context7, rejectOnDispose } from "@dxos/context";
3743
- import { invariant as invariant12 } from "@dxos/invariant";
3923
+ import { invariant as invariant13 } from "@dxos/invariant";
3744
3924
  import { PublicKey as PublicKey9 } from "@dxos/keys";
3745
- import { log as log12 } from "@dxos/log";
3925
+ import { log as log14 } from "@dxos/log";
3746
3926
  import { schema as schema4 } from "@dxos/protocols";
3747
3927
  import { RpcExtension as RpcExtension3 } from "@dxos/teleport";
3748
3928
  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";
3929
+ var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
3750
3930
  var DEFAULT_RETRY_TIMEOUT = 1e3;
3751
3931
  var DEFAULT_SUCCESS_DELAY = 1e3;
3752
3932
  var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
@@ -3771,16 +3951,16 @@ var NotarizationPlugin = class {
3771
3951
  * Request credentials to be notarized.
3772
3952
  */
3773
3953
  async notarize({ ctx: opCtx, credentials, timeout = DEFAULT_NOTARIZE_TIMEOUT, retryTimeout = DEFAULT_RETRY_TIMEOUT, successDelay = DEFAULT_SUCCESS_DELAY }) {
3774
- log12("notarize", {
3954
+ log14("notarize", {
3775
3955
  credentials
3776
3956
  }, {
3777
- F: __dxlog_file15,
3957
+ F: __dxlog_file16,
3778
3958
  L: 90,
3779
3959
  S: this,
3780
3960
  C: (f, a) => f(...a)
3781
3961
  });
3782
- invariant12(credentials.every((credential) => credential.id), "Credentials must have an id", {
3783
- F: __dxlog_file15,
3962
+ invariant13(credentials.every((credential) => credential.id), "Credentials must have an id", {
3963
+ F: __dxlog_file16,
3784
3964
  L: 91,
3785
3965
  S: this,
3786
3966
  A: [
@@ -3788,13 +3968,13 @@ var NotarizationPlugin = class {
3788
3968
  "'Credentials must have an id'"
3789
3969
  ]
3790
3970
  });
3791
- const errors = new Trigger6();
3971
+ const errors = new Trigger7();
3792
3972
  const ctx = this._ctx.derive({
3793
3973
  onError: (err) => {
3794
- log12.warn("Notarization error", {
3974
+ log14.warn("Notarization error", {
3795
3975
  err
3796
3976
  }, {
3797
- F: __dxlog_file15,
3977
+ F: __dxlog_file16,
3798
3978
  L: 99,
3799
3979
  S: this,
3800
3980
  C: (f, a) => f(...a)
@@ -3806,11 +3986,11 @@ var NotarizationPlugin = class {
3806
3986
  opCtx?.onDispose(() => ctx.dispose());
3807
3987
  if (timeout !== 0) {
3808
3988
  scheduleTask4(ctx, () => {
3809
- log12.warn("Notarization timeout", {
3989
+ log14.warn("Notarization timeout", {
3810
3990
  timeout,
3811
3991
  peers: Array.from(this._extensions).map((extension) => extension.remotePeerId)
3812
3992
  }, {
3813
- F: __dxlog_file15,
3993
+ F: __dxlog_file16,
3814
3994
  L: 111,
3815
3995
  S: this,
3816
3996
  C: (f, a) => f(...a)
@@ -3830,10 +4010,10 @@ var NotarizationPlugin = class {
3830
4010
  ...this._extensions
3831
4011
  ].find((peer2) => !peersTried.has(peer2));
3832
4012
  if (!peer) {
3833
- log12.info("Exhausted all peers to notarize with", {
4013
+ log14.info("Exhausted all peers to notarize with", {
3834
4014
  retryIn: retryTimeout
3835
4015
  }, {
3836
- F: __dxlog_file15,
4016
+ F: __dxlog_file16,
3837
4017
  L: 136,
3838
4018
  S: this,
3839
4019
  C: (f, a) => f(...a)
@@ -3843,11 +4023,11 @@ var NotarizationPlugin = class {
3843
4023
  return;
3844
4024
  }
3845
4025
  peersTried.add(peer);
3846
- log12("try notarizing", {
4026
+ log14("try notarizing", {
3847
4027
  peer: peer.localPeerId,
3848
4028
  credentialId: credentials.map((credential) => credential.id)
3849
4029
  }, {
3850
- F: __dxlog_file15,
4030
+ F: __dxlog_file16,
3851
4031
  L: 143,
3852
4032
  S: this,
3853
4033
  C: (f, a) => f(...a)
@@ -3855,17 +4035,17 @@ var NotarizationPlugin = class {
3855
4035
  await peer.rpc.NotarizationService.notarize({
3856
4036
  credentials: credentials.filter((credential) => !this._processedCredentials.has(credential.id))
3857
4037
  });
3858
- log12("success", void 0, {
3859
- F: __dxlog_file15,
4038
+ log14("success", void 0, {
4039
+ F: __dxlog_file16,
3860
4040
  L: 147,
3861
4041
  S: this,
3862
4042
  C: (f, a) => f(...a)
3863
4043
  });
3864
- await sleep(successDelay);
4044
+ await sleep2(successDelay);
3865
4045
  } catch (err) {
3866
4046
  if (!ctx.disposed && !err.message.includes(WRITER_NOT_SET_ERROR_CODE)) {
3867
- log12.info("error notarizing (recoverable)", err, {
3868
- F: __dxlog_file15,
4047
+ log14.info("error notarizing (recoverable)", err, {
4048
+ F: __dxlog_file16,
3869
4049
  L: 151,
3870
4050
  S: this,
3871
4051
  C: (f, a) => f(...a)
@@ -3882,8 +4062,8 @@ var NotarizationPlugin = class {
3882
4062
  allNotarized,
3883
4063
  errors.wait()
3884
4064
  ]);
3885
- log12("done", void 0, {
3886
- F: __dxlog_file15,
4065
+ log14("done", void 0, {
4066
+ F: __dxlog_file16,
3887
4067
  L: 162,
3888
4068
  S: this,
3889
4069
  C: (f, a) => f(...a)
@@ -3904,8 +4084,8 @@ var NotarizationPlugin = class {
3904
4084
  this._processCredentialsTriggers.delete(credential.id);
3905
4085
  }
3906
4086
  setWriter(writer) {
3907
- invariant12(!this._writer, "Writer already set.", {
3908
- F: __dxlog_file15,
4087
+ invariant13(!this._writer, "Writer already set.", {
4088
+ F: __dxlog_file16,
3909
4089
  L: 181,
3910
4090
  S: this,
3911
4091
  A: [
@@ -3919,7 +4099,7 @@ var NotarizationPlugin = class {
3919
4099
  if (this._processedCredentials.has(id)) {
3920
4100
  return;
3921
4101
  }
3922
- await entry(this._processCredentialsTriggers, id).orInsert(new Trigger6()).value.wait();
4102
+ await entry(this._processCredentialsTriggers, id).orInsert(new Trigger7()).value.wait();
3923
4103
  }
3924
4104
  /**
3925
4105
  * Requests from other peers to notarize credentials.
@@ -3929,8 +4109,8 @@ var NotarizationPlugin = class {
3929
4109
  throw new Error(WRITER_NOT_SET_ERROR_CODE);
3930
4110
  }
3931
4111
  for (const credential of request.credentials ?? []) {
3932
- invariant12(credential.id, "Credential must have an id", {
3933
- F: __dxlog_file15,
4112
+ invariant13(credential.id, "Credential must have an id", {
4113
+ F: __dxlog_file16,
3934
4114
  L: 200,
3935
4115
  S: this,
3936
4116
  A: [
@@ -3947,10 +4127,10 @@ var NotarizationPlugin = class {
3947
4127
  createExtension() {
3948
4128
  const extension = new NotarizationTeleportExtension({
3949
4129
  onOpen: async () => {
3950
- log12("extension opened", {
4130
+ log14("extension opened", {
3951
4131
  peer: extension.localPeerId
3952
4132
  }, {
3953
- F: __dxlog_file15,
4133
+ F: __dxlog_file16,
3954
4134
  L: 211,
3955
4135
  S: this,
3956
4136
  C: (f, a) => f(...a)
@@ -3959,10 +4139,10 @@ var NotarizationPlugin = class {
3959
4139
  this._extensionOpened.emit();
3960
4140
  },
3961
4141
  onClose: async () => {
3962
- log12("extension closed", {
4142
+ log14("extension closed", {
3963
4143
  peer: extension.localPeerId
3964
4144
  }, {
3965
- F: __dxlog_file15,
4145
+ F: __dxlog_file16,
3966
4146
  L: 216,
3967
4147
  S: this,
3968
4148
  C: (f, a) => f(...a)
@@ -4016,7 +4196,70 @@ function _ts_decorate4(decorators, target, key, desc) {
4016
4196
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4017
4197
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4018
4198
  }
4019
- var __dxlog_file16 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
4199
+ function _using_ctx() {
4200
+ var _disposeSuppressedError = typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed) {
4201
+ var err = new Error();
4202
+ err.name = "SuppressedError";
4203
+ err.suppressed = suppressed;
4204
+ err.error = error;
4205
+ return err;
4206
+ }, empty = {}, stack = [];
4207
+ function using(isAwait, value) {
4208
+ if (value != null) {
4209
+ if (Object(value) !== value) {
4210
+ throw new TypeError("using declarations can only be used with objects, functions, null, or undefined.");
4211
+ }
4212
+ if (isAwait) {
4213
+ var dispose = value[Symbol.asyncDispose || Symbol.for("Symbol.asyncDispose")];
4214
+ }
4215
+ if (dispose == null) {
4216
+ dispose = value[Symbol.dispose || Symbol.for("Symbol.dispose")];
4217
+ }
4218
+ if (typeof dispose !== "function") {
4219
+ throw new TypeError(`Property [Symbol.dispose] is not a function.`);
4220
+ }
4221
+ stack.push({
4222
+ v: value,
4223
+ d: dispose,
4224
+ a: isAwait
4225
+ });
4226
+ } else if (isAwait) {
4227
+ stack.push({
4228
+ d: value,
4229
+ a: isAwait
4230
+ });
4231
+ }
4232
+ return value;
4233
+ }
4234
+ return {
4235
+ e: empty,
4236
+ u: using.bind(null, false),
4237
+ a: using.bind(null, true),
4238
+ d: function() {
4239
+ var error = this.e;
4240
+ function next() {
4241
+ while (resource = stack.pop()) {
4242
+ try {
4243
+ var resource, disposalResult = resource.d && resource.d.call(resource.v);
4244
+ if (resource.a) {
4245
+ return Promise.resolve(disposalResult).then(next, err);
4246
+ }
4247
+ } catch (e) {
4248
+ return err(e);
4249
+ }
4250
+ }
4251
+ if (error !== empty)
4252
+ throw error;
4253
+ }
4254
+ function err(e) {
4255
+ error = error !== empty ? new _disposeSuppressedError(error, e) : e;
4256
+ return next();
4257
+ }
4258
+ return next();
4259
+ }
4260
+ };
4261
+ }
4262
+ var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space.ts";
4020
4263
  var DataSpace = class {
4021
4264
  constructor(params) {
4022
4265
  this._ctx = new Context8();
@@ -4024,7 +4267,9 @@ var DataSpace = class {
4024
4267
  this._cache = void 0;
4025
4268
  // TODO(dmaretskyi): Move into Space?
4026
4269
  this._automergeSpaceState = new AutomergeSpaceState((rootUrl) => this._onNewAutomergeRoot(rootUrl));
4270
+ this._epochProcessingMutex = new Mutex2();
4027
4271
  this._state = SpaceState2.CLOSED;
4272
+ this._databaseRoot = null;
4028
4273
  /**
4029
4274
  * Error for _state === SpaceState.ERROR.
4030
4275
  */
@@ -4048,11 +4293,11 @@ var DataSpace = class {
4048
4293
  });
4049
4294
  this._cache = params.cache;
4050
4295
  this._state = params.initialState;
4051
- log13("new state", {
4296
+ log15("new state", {
4052
4297
  state: SpaceState2[this._state]
4053
4298
  }, {
4054
- F: __dxlog_file16,
4055
- L: 143,
4299
+ F: __dxlog_file17,
4300
+ L: 146,
4056
4301
  S: this,
4057
4302
  C: (f, a) => f(...a)
4058
4303
  });
@@ -4085,6 +4330,9 @@ var DataSpace = class {
4085
4330
  get automergeSpaceState() {
4086
4331
  return this._automergeSpaceState;
4087
4332
  }
4333
+ get databaseRoot() {
4334
+ return this._databaseRoot;
4335
+ }
4088
4336
  get _automergeInfo() {
4089
4337
  return {
4090
4338
  rootUrl: this._automergeSpaceState.rootUrl,
@@ -4101,14 +4349,15 @@ var DataSpace = class {
4101
4349
  await this._gossip.open();
4102
4350
  await this._notarizationPlugin.open();
4103
4351
  await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
4352
+ await this._automergeSpaceState.open();
4104
4353
  await this._inner.spaceState.addCredentialProcessor(this._automergeSpaceState);
4105
4354
  await this._inner.open(new Context8());
4106
4355
  this._state = SpaceState2.CONTROL_ONLY;
4107
- log13("new state", {
4356
+ log15("new state", {
4108
4357
  state: SpaceState2[this._state]
4109
4358
  }, {
4110
- F: __dxlog_file16,
4111
- L: 209,
4359
+ F: __dxlog_file17,
4360
+ L: 217,
4112
4361
  S: this,
4113
4362
  C: (f, a) => f(...a)
4114
4363
  });
@@ -4122,11 +4371,11 @@ var DataSpace = class {
4122
4371
  async _close() {
4123
4372
  await this._callbacks.beforeClose?.();
4124
4373
  this._state = SpaceState2.CLOSED;
4125
- log13("new state", {
4374
+ log15("new state", {
4126
4375
  state: SpaceState2[this._state]
4127
4376
  }, {
4128
- F: __dxlog_file16,
4129
- L: 223,
4377
+ F: __dxlog_file17,
4378
+ L: 231,
4130
4379
  S: this,
4131
4380
  C: (f, a) => f(...a)
4132
4381
  });
@@ -4135,6 +4384,7 @@ var DataSpace = class {
4135
4384
  await this.authVerifier.close();
4136
4385
  await this._inner.close();
4137
4386
  await this._inner.spaceState.removeCredentialProcessor(this._automergeSpaceState);
4387
+ await this._automergeSpaceState.close();
4138
4388
  await this._inner.spaceState.removeCredentialProcessor(this._notarizationPlugin);
4139
4389
  await this._notarizationPlugin.close();
4140
4390
  await this._presence.close();
@@ -4156,26 +4406,26 @@ var DataSpace = class {
4156
4406
  await this.initializeDataPipeline();
4157
4407
  } catch (err) {
4158
4408
  if (err instanceof CancelledError || err instanceof ContextDisposedError3) {
4159
- log13("data pipeline initialization cancelled", err, {
4160
- F: __dxlog_file16,
4161
- L: 256,
4409
+ log15("data pipeline initialization cancelled", err, {
4410
+ F: __dxlog_file17,
4411
+ L: 265,
4162
4412
  S: this,
4163
4413
  C: (f, a) => f(...a)
4164
4414
  });
4165
4415
  return;
4166
4416
  }
4167
- log13.error("Error initializing data pipeline", err, {
4168
- F: __dxlog_file16,
4169
- L: 260,
4417
+ log15.error("Error initializing data pipeline", err, {
4418
+ F: __dxlog_file17,
4419
+ L: 269,
4170
4420
  S: this,
4171
4421
  C: (f, a) => f(...a)
4172
4422
  });
4173
4423
  this._state = SpaceState2.ERROR;
4174
- log13("new state", {
4424
+ log15("new state", {
4175
4425
  state: SpaceState2[this._state]
4176
4426
  }, {
4177
- F: __dxlog_file16,
4178
- L: 262,
4427
+ F: __dxlog_file17,
4428
+ L: 271,
4179
4429
  S: this,
4180
4430
  C: (f, a) => f(...a)
4181
4431
  });
@@ -4191,31 +4441,28 @@ var DataSpace = class {
4191
4441
  throw new SystemError("Invalid operation");
4192
4442
  }
4193
4443
  this._state = SpaceState2.INITIALIZING;
4194
- log13("new state", {
4444
+ log15("new state", {
4195
4445
  state: SpaceState2[this._state]
4196
4446
  }, {
4197
- F: __dxlog_file16,
4198
- L: 278,
4447
+ F: __dxlog_file17,
4448
+ L: 287,
4199
4449
  S: this,
4200
4450
  C: (f, a) => f(...a)
4201
4451
  });
4202
4452
  await this._initializeAndReadControlPipeline();
4203
- await sleep2(1);
4453
+ await sleep3(1);
4454
+ const ready = this.stateUpdate.waitForCondition(() => this._state === SpaceState2.READY);
4204
4455
  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
- });
4456
+ await ready;
4457
+ }
4458
+ async _enterReadyState() {
4212
4459
  await this._callbacks.beforeReady?.();
4213
4460
  this._state = SpaceState2.READY;
4214
- log13("new state", {
4461
+ log15("new state", {
4215
4462
  state: SpaceState2[this._state]
4216
4463
  }, {
4217
- F: __dxlog_file16,
4218
- L: 294,
4464
+ F: __dxlog_file17,
4465
+ L: 306,
4219
4466
  S: this,
4220
4467
  C: (f, a) => f(...a)
4221
4468
  });
@@ -4229,9 +4476,9 @@ var DataSpace = class {
4229
4476
  });
4230
4477
  this.metrics.controlPipelineReady = /* @__PURE__ */ new Date();
4231
4478
  await this._createWritableFeeds();
4232
- log13("writable feeds created", void 0, {
4233
- F: __dxlog_file16,
4234
- L: 310,
4479
+ log15("writable feeds created", void 0, {
4480
+ F: __dxlog_file17,
4481
+ L: 322,
4235
4482
  S: this,
4236
4483
  C: (f, a) => f(...a)
4237
4484
  });
@@ -4289,12 +4536,12 @@ var DataSpace = class {
4289
4536
  }
4290
4537
  }
4291
4538
  _onNewAutomergeRoot(rootUrl) {
4292
- log13("loading automerge root doc for space", {
4539
+ log15("loading automerge root doc for space", {
4293
4540
  space: this.key,
4294
4541
  rootUrl
4295
4542
  }, {
4296
- F: __dxlog_file16,
4297
- L: 376,
4543
+ F: __dxlog_file17,
4544
+ L: 388,
4298
4545
  S: this,
4299
4546
  C: (f, a) => f(...a)
4300
4547
  });
@@ -4302,44 +4549,54 @@ var DataSpace = class {
4302
4549
  const handle = this._echoHost.automergeRepo.find(rootUrl);
4303
4550
  queueMicrotask(async () => {
4304
4551
  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)
4552
+ try {
4553
+ var _usingCtx = _using_ctx();
4554
+ await warnAfterTimeout(5e3, "Automerge root doc load timeout (DataSpace)", async () => {
4555
+ await cancelWithContext5(this._ctx, handle.whenReady());
4330
4556
  });
4557
+ if (this._ctx.disposed) {
4558
+ return;
4559
+ }
4560
+ const _guard = (
4561
+ // Ensure only one root is processed at a time.
4562
+ _usingCtx.u(await this._epochProcessingMutex.acquire())
4563
+ );
4564
+ const doc = handle.docSync() ?? failedInvariant();
4565
+ if (!doc.access?.spaceKey) {
4566
+ handle.change((doc2) => {
4567
+ doc2.access = {
4568
+ spaceKey: this.key.toHex()
4569
+ };
4570
+ });
4571
+ }
4572
+ const root = await this._echoHost.openSpaceRoot(handle.url);
4573
+ this._databaseRoot = root;
4574
+ if (root.getVersion() !== SpaceDocVersion.CURRENT) {
4575
+ if (this._state !== SpaceState2.REQUIRES_MIGRATION) {
4576
+ this._state = SpaceState2.REQUIRES_MIGRATION;
4577
+ this.stateUpdate.emit();
4578
+ }
4579
+ } else {
4580
+ if (this._state !== SpaceState2.READY) {
4581
+ await this._enterReadyState();
4582
+ }
4583
+ }
4584
+ } catch (_) {
4585
+ _usingCtx.e = _;
4586
+ } finally {
4587
+ _usingCtx.d();
4331
4588
  }
4332
4589
  } catch (err) {
4333
4590
  if (err instanceof ContextDisposedError3) {
4334
4591
  return;
4335
4592
  }
4336
- log13.warn("error loading automerge root doc", {
4593
+ log15.warn("error loading automerge root doc", {
4337
4594
  space: this.key,
4338
4595
  rootUrl,
4339
4596
  err
4340
4597
  }, {
4341
- F: __dxlog_file16,
4342
- L: 409,
4598
+ F: __dxlog_file17,
4599
+ L: 433,
4343
4600
  S: this,
4344
4601
  C: (f, a) => f(...a)
4345
4602
  });
@@ -4362,148 +4619,34 @@ var DataSpace = class {
4362
4619
  });
4363
4620
  }
4364
4621
  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;
4622
+ const ctx = this._ctx.derive();
4623
+ if (!options?.migration) {
4624
+ return null;
4497
4625
  }
4626
+ const { newRoot } = await runEpochMigration(ctx, {
4627
+ repo: this._echoHost.automergeRepo,
4628
+ spaceId: this.id,
4629
+ spaceKey: this.key,
4630
+ migration: options.migration,
4631
+ currentRoot: this._automergeSpaceState.rootUrl ?? null,
4632
+ newAutomergeRoot: options.newAutomergeRoot
4633
+ });
4634
+ const epoch = {
4635
+ previousId: this._automergeSpaceState.lastEpoch?.id,
4636
+ number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
4637
+ timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe3(),
4638
+ automergeRoot: newRoot ?? this._automergeSpaceState.rootUrl
4639
+ };
4640
+ const credential = await this._signingContext.credentialSigner.createCredential({
4641
+ subject: this.key,
4642
+ assertion: {
4643
+ "@type": "dxos.halo.credentials.Epoch",
4644
+ ...epoch
4645
+ }
4646
+ });
4498
4647
  const receipt = await this.inner.controlPipeline.writer.write({
4499
4648
  credential: {
4500
- credential: await this._signingContext.credentialSigner.createCredential({
4501
- subject: this.key,
4502
- assertion: {
4503
- "@type": "dxos.halo.credentials.Epoch",
4504
- ...epoch
4505
- }
4506
- })
4649
+ credential
4507
4650
  }
4508
4651
  });
4509
4652
  await this.inner.controlPipeline.state.waitUntilTimeframe(new Timeframe3([
@@ -4513,6 +4656,7 @@ var DataSpace = class {
4513
4656
  ]
4514
4657
  ]));
4515
4658
  await this._echoHost.updateIndexes();
4659
+ return credential;
4516
4660
  }
4517
4661
  async activate() {
4518
4662
  if (![
@@ -4534,11 +4678,11 @@ var DataSpace = class {
4534
4678
  await this._close();
4535
4679
  }
4536
4680
  this._state = SpaceState2.INACTIVE;
4537
- log13("new state", {
4681
+ log15("new state", {
4538
4682
  state: SpaceState2[this._state]
4539
4683
  }, {
4540
- F: __dxlog_file16,
4541
- L: 571,
4684
+ F: __dxlog_file17,
4685
+ L: 514,
4542
4686
  S: this,
4543
4687
  C: (f, a) => f(...a)
4544
4688
  });
@@ -4593,36 +4737,25 @@ DataSpace = _ts_decorate4([
4593
4737
  trackLeaks("open", "close"),
4594
4738
  trace6.resource()
4595
4739
  ], 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
4740
 
4609
4741
  // packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts
4610
4742
  import { Event as Event7, synchronized as synchronized2, trackLeaks as trackLeaks2 } from "@dxos/async";
4611
4743
  import { PropertiesType } from "@dxos/client-protocol";
4612
- import { cancelWithContext as cancelWithContext5, Context as Context9 } from "@dxos/context";
4744
+ import { Context as Context9, cancelWithContext as cancelWithContext6 } from "@dxos/context";
4613
4745
  import { getCredentialAssertion as getCredentialAssertion3 } from "@dxos/credentials";
4746
+ import { convertLegacyReferences as convertLegacyReferences2, findInlineObjectOfType as findInlineObjectOfType2 } from "@dxos/echo-db";
4614
4747
  import { AuthStatus } from "@dxos/echo-pipeline";
4615
- import { encodeReference } from "@dxos/echo-protocol";
4616
- import { getTypeReference } from "@dxos/echo-schema";
4748
+ import { LEGACY_TYPE_PROPERTIES, SpaceDocVersion as SpaceDocVersion2, encodeReference } from "@dxos/echo-protocol";
4749
+ import { TYPE_PROPERTIES as TYPE_PROPERTIES2, generateEchoId, getTypeReference } from "@dxos/echo-schema";
4617
4750
  import { invariant as invariant14 } from "@dxos/invariant";
4618
4751
  import { PublicKey as PublicKey11 } from "@dxos/keys";
4619
- import { log as log14 } from "@dxos/log";
4752
+ import { log as log16 } from "@dxos/log";
4620
4753
  import { trace as Trace2 } from "@dxos/protocols";
4621
4754
  import { Invitation as Invitation7, SpaceState as SpaceState3 } from "@dxos/protocols/proto/dxos/client/services";
4622
4755
  import { SpaceMember as SpaceMember6 } from "@dxos/protocols/proto/dxos/halo/credentials";
4623
4756
  import { Gossip as Gossip2, Presence as Presence2 } from "@dxos/teleport-extension-gossip";
4624
4757
  import { trace as trace7 } from "@dxos/tracing";
4625
- import { assignDeep as assignDeep2, ComplexMap as ComplexMap3, deferFunction as deferFunction2, forEachAsync } from "@dxos/util";
4758
+ import { ComplexMap as ComplexMap3, assignDeep as assignDeep2, deferFunction as deferFunction2, forEachAsync } from "@dxos/util";
4626
4759
 
4627
4760
  // packages/sdk/client-services/src/packlets/spaces/genesis.ts
4628
4761
  import { createCredential } from "@dxos/credentials";
@@ -4705,7 +4838,7 @@ function _ts_decorate5(decorators, target, key, desc) {
4705
4838
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
4706
4839
  return c > 3 && r && Object.defineProperty(target, key, r), r;
4707
4840
  }
4708
- var __dxlog_file17 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
4841
+ var __dxlog_file18 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/data-space-manager.ts";
4709
4842
  var PRESENCE_ANNOUNCE_INTERVAL = 1e4;
4710
4843
  var PRESENCE_OFFLINE_TIMEOUT = 2e4;
4711
4844
  var DEFAULT_SPACE_KEY = "__DEFAULT__";
@@ -4732,7 +4865,7 @@ var DataSpaceManager = class {
4732
4865
  const rootUrl = space.automergeSpaceState.rootUrl;
4733
4866
  const rootHandle = rootUrl ? this._echoHost.automergeRepo.find(rootUrl) : void 0;
4734
4867
  const rootDoc = rootHandle?.docSync();
4735
- const properties = rootDoc && findPropertiesObject(rootDoc);
4868
+ const properties = rootDoc && findInlineObjectOfType2(rootDoc, TYPE_PROPERTIES2);
4736
4869
  return {
4737
4870
  key: space.key.toHex(),
4738
4871
  state: SpaceState3[space.state],
@@ -4752,46 +4885,46 @@ var DataSpaceManager = class {
4752
4885
  return this._spaces;
4753
4886
  }
4754
4887
  async open() {
4755
- log14("open", void 0, {
4756
- F: __dxlog_file17,
4757
- L: 140,
4888
+ log16("open", void 0, {
4889
+ F: __dxlog_file18,
4890
+ L: 146,
4758
4891
  S: this,
4759
4892
  C: (f, a) => f(...a)
4760
4893
  });
4761
- log14.trace("dxos.echo.data-space-manager.open", Trace2.begin({
4894
+ log16.trace("dxos.echo.data-space-manager.open", Trace2.begin({
4762
4895
  id: this._instanceId
4763
4896
  }), {
4764
- F: __dxlog_file17,
4765
- L: 141,
4897
+ F: __dxlog_file18,
4898
+ L: 147,
4766
4899
  S: this,
4767
4900
  C: (f, a) => f(...a)
4768
4901
  });
4769
- log14("metadata loaded", {
4902
+ log16("metadata loaded", {
4770
4903
  spaces: this._metadataStore.spaces.length
4771
4904
  }, {
4772
- F: __dxlog_file17,
4773
- L: 142,
4905
+ F: __dxlog_file18,
4906
+ L: 148,
4774
4907
  S: this,
4775
4908
  C: (f, a) => f(...a)
4776
4909
  });
4777
4910
  await forEachAsync(this._metadataStore.spaces, async (spaceMetadata) => {
4778
4911
  try {
4779
- log14("load space", {
4912
+ log16("load space", {
4780
4913
  spaceMetadata
4781
4914
  }, {
4782
- F: __dxlog_file17,
4783
- L: 146,
4915
+ F: __dxlog_file18,
4916
+ L: 152,
4784
4917
  S: this,
4785
4918
  C: (f, a) => f(...a)
4786
4919
  });
4787
4920
  await this._constructSpace(spaceMetadata);
4788
4921
  } catch (err) {
4789
- log14.error("Error loading space", {
4922
+ log16.error("Error loading space", {
4790
4923
  spaceMetadata,
4791
4924
  err
4792
4925
  }, {
4793
- F: __dxlog_file17,
4794
- L: 149,
4926
+ F: __dxlog_file18,
4927
+ L: 155,
4795
4928
  S: this,
4796
4929
  C: (f, a) => f(...a)
4797
4930
  });
@@ -4799,19 +4932,19 @@ var DataSpaceManager = class {
4799
4932
  });
4800
4933
  this._isOpen = true;
4801
4934
  this.updated.emit();
4802
- log14.trace("dxos.echo.data-space-manager.open", Trace2.end({
4935
+ log16.trace("dxos.echo.data-space-manager.open", Trace2.end({
4803
4936
  id: this._instanceId
4804
4937
  }), {
4805
- F: __dxlog_file17,
4806
- L: 156,
4938
+ F: __dxlog_file18,
4939
+ L: 162,
4807
4940
  S: this,
4808
4941
  C: (f, a) => f(...a)
4809
4942
  });
4810
4943
  }
4811
4944
  async close() {
4812
- log14("close", void 0, {
4813
- F: __dxlog_file17,
4814
- L: 161,
4945
+ log16("close", void 0, {
4946
+ F: __dxlog_file18,
4947
+ L: 167,
4815
4948
  S: this,
4816
4949
  C: (f, a) => f(...a)
4817
4950
  });
@@ -4827,8 +4960,8 @@ var DataSpaceManager = class {
4827
4960
  */
4828
4961
  async createSpace() {
4829
4962
  invariant14(this._isOpen, "Not open.", {
4830
- F: __dxlog_file17,
4831
- L: 175,
4963
+ F: __dxlog_file18,
4964
+ L: 181,
4832
4965
  S: this,
4833
4966
  A: [
4834
4967
  "this._isOpen",
@@ -4845,11 +4978,11 @@ var DataSpaceManager = class {
4845
4978
  dataFeedKey,
4846
4979
  state: SpaceState3.ACTIVE
4847
4980
  };
4848
- log14("creating space...", {
4981
+ log16("creating space...", {
4849
4982
  spaceKey
4850
4983
  }, {
4851
- F: __dxlog_file17,
4852
- L: 187,
4984
+ F: __dxlog_file18,
4985
+ L: 193,
4853
4986
  S: this,
4854
4987
  C: (f, a) => f(...a)
4855
4988
  });
@@ -4860,8 +4993,8 @@ var DataSpaceManager = class {
4860
4993
  await this._metadataStore.addSpace(metadata);
4861
4994
  const memberCredential = credentials[1];
4862
4995
  invariant14(getCredentialAssertion3(memberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
4863
- F: __dxlog_file17,
4864
- L: 197,
4996
+ F: __dxlog_file18,
4997
+ L: 203,
4865
4998
  S: this,
4866
4999
  A: [
4867
5000
  "getCredentialAssertion(memberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -4874,9 +5007,31 @@ var DataSpaceManager = class {
4874
5007
  return space;
4875
5008
  }
4876
5009
  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();
5010
+ if (!space.databaseRoot) {
5011
+ return false;
5012
+ }
5013
+ switch (space.databaseRoot.getVersion()) {
5014
+ case SpaceDocVersion2.CURRENT: {
5015
+ const [_, properties] = findInlineObjectOfType2(space.databaseRoot.docSync(), TYPE_PROPERTIES2) ?? [];
5016
+ return properties?.data?.[DEFAULT_SPACE_KEY] === this._signingContext.identityKey.toHex();
5017
+ }
5018
+ case SpaceDocVersion2.LEGACY: {
5019
+ const convertedDoc = await convertLegacyReferences2(space.databaseRoot.docSync());
5020
+ const [_, properties] = findInlineObjectOfType2(convertedDoc, LEGACY_TYPE_PROPERTIES) ?? [];
5021
+ return properties?.data?.[DEFAULT_SPACE_KEY] === this._signingContext.identityKey.toHex();
5022
+ }
5023
+ default:
5024
+ log16.warn("unknown space version", {
5025
+ version: space.databaseRoot.getVersion(),
5026
+ spaceId: space.id
5027
+ }, {
5028
+ F: __dxlog_file18,
5029
+ L: 228,
5030
+ S: this,
5031
+ C: (f, a) => f(...a)
5032
+ });
5033
+ return false;
5034
+ }
4880
5035
  }
4881
5036
  async createDefaultSpace() {
4882
5037
  const space = await this.createSpace();
@@ -4892,7 +5047,7 @@ var DataSpaceManager = class {
4892
5047
  keys: []
4893
5048
  }
4894
5049
  };
4895
- const propertiesId = PublicKey11.random().toHex();
5050
+ const propertiesId = generateEchoId();
4896
5051
  document.change((doc) => {
4897
5052
  assignDeep2(doc, [
4898
5053
  "objects",
@@ -4905,8 +5060,8 @@ var DataSpaceManager = class {
4905
5060
  async _getSpaceRootDocument(space) {
4906
5061
  const automergeIndex = space.automergeSpaceState.rootUrl;
4907
5062
  invariant14(automergeIndex, void 0, {
4908
- F: __dxlog_file17,
4909
- L: 240,
5063
+ F: __dxlog_file18,
5064
+ L: 261,
4910
5065
  S: this,
4911
5066
  A: [
4912
5067
  "automergeIndex",
@@ -4919,17 +5074,17 @@ var DataSpaceManager = class {
4919
5074
  }
4920
5075
  // TODO(burdon): Rename join space.
4921
5076
  async acceptSpace(opts) {
4922
- log14("accept space", {
5077
+ log16("accept space", {
4923
5078
  opts
4924
5079
  }, {
4925
- F: __dxlog_file17,
4926
- L: 249,
5080
+ F: __dxlog_file18,
5081
+ L: 270,
4927
5082
  S: this,
4928
5083
  C: (f, a) => f(...a)
4929
5084
  });
4930
5085
  invariant14(this._isOpen, "Not open.", {
4931
- F: __dxlog_file17,
4932
- L: 250,
5086
+ F: __dxlog_file18,
5087
+ L: 271,
4933
5088
  S: this,
4934
5089
  A: [
4935
5090
  "this._isOpen",
@@ -4937,8 +5092,8 @@ var DataSpaceManager = class {
4937
5092
  ]
4938
5093
  });
4939
5094
  invariant14(!this._spaces.has(opts.spaceKey), "Space already exists.", {
4940
- F: __dxlog_file17,
4941
- L: 251,
5095
+ F: __dxlog_file18,
5096
+ L: 272,
4942
5097
  S: this,
4943
5098
  A: [
4944
5099
  "!this._spaces.has(opts.spaceKey)",
@@ -4964,17 +5119,17 @@ var DataSpaceManager = class {
4964
5119
  * TODO(dmaretskyi): Consider removing.
4965
5120
  */
4966
5121
  async waitUntilSpaceReady(spaceKey) {
4967
- await cancelWithContext5(this._ctx, this.updated.waitForCondition(() => {
5122
+ await cancelWithContext6(this._ctx, this.updated.waitForCondition(() => {
4968
5123
  const space = this._spaces.get(spaceKey);
4969
5124
  return !!space && space.state === SpaceState3.READY;
4970
5125
  }));
4971
5126
  }
4972
5127
  async _constructSpace(metadata) {
4973
- log14("construct space", {
5128
+ log16("construct space", {
4974
5129
  metadata
4975
5130
  }, {
4976
- F: __dxlog_file17,
4977
- L: 285,
5131
+ F: __dxlog_file18,
5132
+ L: 306,
4978
5133
  S: this,
4979
5134
  C: (f, a) => f(...a)
4980
5135
  });
@@ -5010,9 +5165,9 @@ var DataSpaceManager = class {
5010
5165
  session.addExtension("dxos.mesh.teleport.automerge", this._echoHost.createReplicationExtension());
5011
5166
  },
5012
5167
  onAuthFailure: () => {
5013
- log14.warn("auth failure", void 0, {
5014
- F: __dxlog_file17,
5015
- L: 322,
5168
+ log16.warn("auth failure", void 0, {
5169
+ F: __dxlog_file18,
5170
+ L: 343,
5016
5171
  S: this,
5017
5172
  C: (f, a) => f(...a)
5018
5173
  });
@@ -5041,22 +5196,22 @@ var DataSpaceManager = class {
5041
5196
  signingContext: this._signingContext,
5042
5197
  callbacks: {
5043
5198
  beforeReady: async () => {
5044
- log14("before space ready", {
5199
+ log16("before space ready", {
5045
5200
  space: space.key
5046
5201
  }, {
5047
- F: __dxlog_file17,
5048
- L: 349,
5202
+ F: __dxlog_file18,
5203
+ L: 370,
5049
5204
  S: this,
5050
5205
  C: (f, a) => f(...a)
5051
5206
  });
5052
5207
  },
5053
5208
  afterReady: async () => {
5054
- log14("after space ready", {
5209
+ log16("after space ready", {
5055
5210
  space: space.key,
5056
5211
  open: this._isOpen
5057
5212
  }, {
5058
- F: __dxlog_file17,
5059
- L: 352,
5213
+ F: __dxlog_file18,
5214
+ L: 373,
5060
5215
  S: this,
5061
5216
  C: (f, a) => f(...a)
5062
5217
  });
@@ -5071,11 +5226,11 @@ var DataSpaceManager = class {
5071
5226
  }
5072
5227
  },
5073
5228
  beforeClose: async () => {
5074
- log14("before space close", {
5229
+ log16("before space close", {
5075
5230
  space: space.key
5076
5231
  }, {
5077
- F: __dxlog_file17,
5078
- L: 360,
5232
+ F: __dxlog_file18,
5233
+ L: 381,
5079
5234
  S: this,
5080
5235
  C: (f, a) => f(...a)
5081
5236
  });
@@ -5106,17 +5261,17 @@ var DataSpaceManager = class {
5106
5261
  return (s && member.role === SpaceMember6.Role.REMOVED !== (s.authStatus === AuthStatus.FAILURE)) ?? false;
5107
5262
  });
5108
5263
  sessionsToClose.forEach((session) => {
5109
- void session.close().catch(log14.error);
5264
+ void session.close().catch(log16.error);
5110
5265
  });
5111
5266
  closedSessions += sessionsToClose.length;
5112
5267
  }
5113
- log14("processed member role changes", {
5268
+ log16("processed member role changes", {
5114
5269
  roleChangeCount: memberInfo.length,
5115
5270
  peersOnline: presence.getPeersOnline().length,
5116
5271
  closedSessions
5117
5272
  }, {
5118
- F: __dxlog_file17,
5119
- L: 396,
5273
+ F: __dxlog_file18,
5274
+ L: 417,
5120
5275
  S: this,
5121
5276
  C: (f, a) => f(...a)
5122
5277
  });
@@ -5127,15 +5282,15 @@ var DataSpaceManager = class {
5127
5282
  if (role === SpaceMember6.Role.REMOVED) {
5128
5283
  const session = peerState.peerId && space.protocol.sessions.get(peerState.peerId);
5129
5284
  if (session != null) {
5130
- log14("closing a session with a removed peer", {
5285
+ log16("closing a session with a removed peer", {
5131
5286
  peerId: peerState.peerId
5132
5287
  }, {
5133
- F: __dxlog_file17,
5134
- L: 410,
5288
+ F: __dxlog_file18,
5289
+ L: 431,
5135
5290
  S: this,
5136
5291
  C: (f, a) => f(...a)
5137
5292
  });
5138
- void session.close().catch(log14.error);
5293
+ void session.close().catch(log16.error);
5139
5294
  }
5140
5295
  }
5141
5296
  }
@@ -5198,11 +5353,11 @@ import { createAdmissionCredentials as createAdmissionCredentials2, getCredentia
5198
5353
  import { raise as raise2 } from "@dxos/debug";
5199
5354
  import { writeMessages as writeMessages3 } from "@dxos/feed-store";
5200
5355
  import { invariant as invariant15 } from "@dxos/invariant";
5201
- import { log as log15 } from "@dxos/log";
5356
+ import { log as log17 } from "@dxos/log";
5202
5357
  import { ApiError, SpaceNotFoundError as SpaceNotFoundError2, encodeError, IdentityNotInitializedError, AuthorizationError as AuthorizationError2 } from "@dxos/protocols";
5203
5358
  import { SpaceMember as SpaceMember7, SpaceState as SpaceState4 } from "@dxos/protocols/proto/dxos/client/services";
5204
5359
  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";
5360
+ var __dxlog_file19 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/spaces-service.ts";
5206
5361
  var SpacesServiceImpl = class {
5207
5362
  constructor(_identityManager, _spaceManager, _getDataSpaceManager) {
5208
5363
  this._identityManager = _identityManager;
@@ -5246,8 +5401,8 @@ var SpacesServiceImpl = class {
5246
5401
  }
5247
5402
  const credentials = await createAdmissionCredentials2(identity.getIdentityCredentialSigner(), request.memberKey, space.key, space.genesisFeedKey, request.newRole, space.spaceState.membershipChainHeads);
5248
5403
  invariant15(credentials[0].credential, void 0, {
5249
- F: __dxlog_file18,
5250
- L: 97,
5404
+ F: __dxlog_file19,
5405
+ L: 98,
5251
5406
  S: this,
5252
5407
  A: [
5253
5408
  "credentials[0].credential",
@@ -5256,8 +5411,8 @@ var SpacesServiceImpl = class {
5256
5411
  });
5257
5412
  const spaceMemberCredential = credentials[0].credential.credential;
5258
5413
  invariant15(getCredentialAssertion4(spaceMemberCredential)["@type"] === "dxos.halo.credentials.SpaceMember", void 0, {
5259
- F: __dxlog_file18,
5260
- L: 99,
5414
+ F: __dxlog_file19,
5415
+ L: 100,
5261
5416
  S: this,
5262
5417
  A: [
5263
5418
  "getCredentialAssertion(spaceMemberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember'",
@@ -5271,11 +5426,11 @@ var SpacesServiceImpl = class {
5271
5426
  const scheduler = new UpdateScheduler(ctx, async () => {
5272
5427
  const dataSpaceManager = await this._getDataSpaceManager();
5273
5428
  const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._serializeSpace(space));
5274
- log15("update", {
5429
+ log17("update", {
5275
5430
  spaces
5276
5431
  }, {
5277
- F: __dxlog_file18,
5278
- L: 110,
5432
+ F: __dxlog_file19,
5433
+ L: 111,
5279
5434
  S: this,
5280
5435
  C: (f, a) => f(...a)
5281
5436
  });
@@ -5293,7 +5448,15 @@ var SpacesServiceImpl = class {
5293
5448
  const subscribeSpaces = () => {
5294
5449
  subscriptions.clear();
5295
5450
  for (const space of dataSpaceManager.spaces.values()) {
5296
- subscriptions.add(space.stateUpdate.on(ctx, () => scheduler.forceTrigger()));
5451
+ let lastState;
5452
+ subscriptions.add(space.stateUpdate.on(ctx, () => {
5453
+ if (space.state !== lastState) {
5454
+ scheduler.forceTrigger();
5455
+ } else {
5456
+ scheduler.trigger();
5457
+ }
5458
+ lastState = space.state;
5459
+ }));
5297
5460
  subscriptions.add(space.presence.updated.on(ctx, () => scheduler.trigger()));
5298
5461
  subscriptions.add(space.automergeSpaceState.onNewEpoch.on(ctx, () => scheduler.trigger()));
5299
5462
  subscriptions.add(space.inner.controlPipeline.state.timeframeUpdate.on(ctx, () => scheduler.trigger()));
@@ -5358,8 +5521,8 @@ var SpacesServiceImpl = class {
5358
5521
  });
5359
5522
  } else {
5360
5523
  invariant15(!credential.id, "Id on unsigned credentials is not allowed", {
5361
- F: __dxlog_file18,
5362
- L: 198,
5524
+ F: __dxlog_file19,
5525
+ L: 209,
5363
5526
  S: this,
5364
5527
  A: [
5365
5528
  "!credential.id",
@@ -5367,8 +5530,8 @@ var SpacesServiceImpl = class {
5367
5530
  ]
5368
5531
  });
5369
5532
  invariant15(this._identityManager.identity, "Identity is not available", {
5370
- F: __dxlog_file18,
5371
- L: 199,
5533
+ F: __dxlog_file19,
5534
+ L: 210,
5372
5535
  S: this,
5373
5536
  A: [
5374
5537
  "this._identityManager.identity",
@@ -5377,8 +5540,8 @@ var SpacesServiceImpl = class {
5377
5540
  });
5378
5541
  const signer = this._identityManager.identity.getIdentityCredentialSigner();
5379
5542
  invariant15(credential.issuer.equals(signer.getIssuer()), void 0, {
5380
- F: __dxlog_file18,
5381
- L: 201,
5543
+ F: __dxlog_file19,
5544
+ L: 212,
5382
5545
  S: this,
5383
5546
  A: [
5384
5547
  "credential.issuer.equals(signer.getIssuer())",
@@ -5400,10 +5563,13 @@ var SpacesServiceImpl = class {
5400
5563
  async createEpoch({ spaceKey, migration, automergeRootUrl }) {
5401
5564
  const dataSpaceManager = await this._getDataSpaceManager();
5402
5565
  const space = dataSpaceManager.spaces.get(spaceKey) ?? raise2(new SpaceNotFoundError2(spaceKey));
5403
- await space.createEpoch({
5566
+ const credential = await space.createEpoch({
5404
5567
  migration,
5405
5568
  newAutomergeRoot: automergeRootUrl
5406
5569
  });
5570
+ return {
5571
+ epochCredential: credential ?? void 0
5572
+ };
5407
5573
  }
5408
5574
  _serializeSpace(space) {
5409
5575
  return {
@@ -5466,8 +5632,8 @@ var SpacesServiceImpl = class {
5466
5632
  var getChannelId = (channel) => `user-channel/${channel}`;
5467
5633
 
5468
5634
  // packages/sdk/client-services/src/packlets/services/service-context.ts
5469
- import { Trigger as Trigger7 } from "@dxos/async";
5470
- import { Context as Context10, Resource as Resource2 } from "@dxos/context";
5635
+ import { Trigger as Trigger8 } from "@dxos/async";
5636
+ import { Context as Context10, Resource as Resource3 } from "@dxos/context";
5471
5637
  import { getCredentialAssertion as getCredentialAssertion5 } from "@dxos/credentials";
5472
5638
  import { failUndefined as failUndefined2 } from "@dxos/debug";
5473
5639
  import { EchoHost } from "@dxos/echo-db";
@@ -5476,7 +5642,7 @@ import { FeedFactory, FeedStore } from "@dxos/feed-store";
5476
5642
  import { invariant as invariant16 } from "@dxos/invariant";
5477
5643
  import { Keyring } from "@dxos/keyring";
5478
5644
  import { PublicKey as PublicKey12 } from "@dxos/keys";
5479
- import { log as log16 } from "@dxos/log";
5645
+ import { log as log18 } from "@dxos/log";
5480
5646
  import { InvalidStorageVersionError, STORAGE_VERSION as STORAGE_VERSION2, trace as trace9 } from "@dxos/protocols";
5481
5647
  import { Invitation as Invitation8 } from "@dxos/protocols/proto/dxos/client/services";
5482
5648
  import { BlobStore } from "@dxos/teleport-extension-object-sync";
@@ -5492,8 +5658,8 @@ function _ts_decorate6(decorators, target, key, desc) {
5492
5658
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5493
5659
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5494
5660
  }
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 {
5661
+ var __dxlog_file20 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-context.ts";
5662
+ var ServiceContext = class extends Resource3 {
5497
5663
  constructor(storage, level, networkManager, signalManager, _runtimeParams) {
5498
5664
  super();
5499
5665
  this.storage = storage;
@@ -5501,7 +5667,7 @@ var ServiceContext = class extends Resource2 {
5501
5667
  this.networkManager = networkManager;
5502
5668
  this.signalManager = signalManager;
5503
5669
  this._runtimeParams = _runtimeParams;
5504
- this.initialized = new Trigger7();
5670
+ this.initialized = new Trigger8();
5505
5671
  this._handlerFactories = /* @__PURE__ */ new Map();
5506
5672
  this._instanceId = PublicKey12.random().toHex();
5507
5673
  this.metadataStore = new MetadataStore(storage.createDirectory("metadata"));
@@ -5535,16 +5701,16 @@ var ServiceContext = class extends Resource2 {
5535
5701
  }
5536
5702
  async _open(ctx) {
5537
5703
  await this._checkStorageVersion();
5538
- log16("opening...", void 0, {
5539
- F: __dxlog_file19,
5704
+ log18("opening...", void 0, {
5705
+ F: __dxlog_file20,
5540
5706
  L: 149,
5541
5707
  S: this,
5542
5708
  C: (f, a) => f(...a)
5543
5709
  });
5544
- log16.trace("dxos.sdk.service-context.open", trace9.begin({
5710
+ log18.trace("dxos.sdk.service-context.open", trace9.begin({
5545
5711
  id: this._instanceId
5546
5712
  }), {
5547
- F: __dxlog_file19,
5713
+ F: __dxlog_file20,
5548
5714
  L: 150,
5549
5715
  S: this,
5550
5716
  C: (f, a) => f(...a)
@@ -5559,32 +5725,32 @@ var ServiceContext = class extends Resource2 {
5559
5725
  await this._initialize(ctx);
5560
5726
  }
5561
5727
  const loadedInvitations = await this.invitationsManager.loadPersistentInvitations();
5562
- log16("loaded persistent invitations", {
5728
+ log18("loaded persistent invitations", {
5563
5729
  count: loadedInvitations.invitations?.length
5564
5730
  }, {
5565
- F: __dxlog_file19,
5731
+ F: __dxlog_file20,
5566
5732
  L: 163,
5567
5733
  S: this,
5568
5734
  C: (f, a) => f(...a)
5569
5735
  });
5570
- log16.trace("dxos.sdk.service-context.open", trace9.end({
5736
+ log18.trace("dxos.sdk.service-context.open", trace9.end({
5571
5737
  id: this._instanceId
5572
5738
  }), {
5573
- F: __dxlog_file19,
5739
+ F: __dxlog_file20,
5574
5740
  L: 165,
5575
5741
  S: this,
5576
5742
  C: (f, a) => f(...a)
5577
5743
  });
5578
- log16("opened", void 0, {
5579
- F: __dxlog_file19,
5744
+ log18("opened", void 0, {
5745
+ F: __dxlog_file20,
5580
5746
  L: 166,
5581
5747
  S: this,
5582
5748
  C: (f, a) => f(...a)
5583
5749
  });
5584
5750
  }
5585
5751
  async _close(ctx) {
5586
- log16("closing...", void 0, {
5587
- F: __dxlog_file19,
5752
+ log18("closing...", void 0, {
5753
+ F: __dxlog_file20,
5588
5754
  L: 170,
5589
5755
  S: this,
5590
5756
  C: (f, a) => f(...a)
@@ -5600,8 +5766,8 @@ var ServiceContext = class extends Resource2 {
5600
5766
  await this.echoHost.close(ctx);
5601
5767
  await this.networkManager.close();
5602
5768
  await this.signalManager.close();
5603
- log16("closed", void 0, {
5604
- F: __dxlog_file19,
5769
+ log18("closed", void 0, {
5770
+ F: __dxlog_file20,
5605
5771
  L: 182,
5606
5772
  S: this,
5607
5773
  C: (f, a) => f(...a)
@@ -5615,7 +5781,7 @@ var ServiceContext = class extends Resource2 {
5615
5781
  getInvitationHandler(invitation) {
5616
5782
  const factory = this._handlerFactories.get(invitation.kind);
5617
5783
  invariant16(factory, `Unknown invitation kind: ${invitation.kind}`, {
5618
- F: __dxlog_file19,
5784
+ F: __dxlog_file20,
5619
5785
  L: 193,
5620
5786
  S: this,
5621
5787
  A: [
@@ -5646,8 +5812,8 @@ var ServiceContext = class extends Resource2 {
5646
5812
  }
5647
5813
  // Called when identity is created.
5648
5814
  async _initialize(ctx) {
5649
- log16("initializing spaces...", void 0, {
5650
- F: __dxlog_file19,
5815
+ log18("initializing spaces...", void 0, {
5816
+ F: __dxlog_file20,
5651
5817
  L: 224,
5652
5818
  S: this,
5653
5819
  C: (f, a) => f(...a)
@@ -5670,7 +5836,7 @@ var ServiceContext = class extends Resource2 {
5670
5836
  await this.dataSpaceManager.open();
5671
5837
  this._handlerFactories.set(Invitation8.Kind.SPACE, (invitation) => {
5672
5838
  invariant16(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
5673
- F: __dxlog_file19,
5839
+ F: __dxlog_file20,
5674
5840
  L: 249,
5675
5841
  S: this,
5676
5842
  A: [
@@ -5691,10 +5857,10 @@ var ServiceContext = class extends Resource2 {
5691
5857
  return;
5692
5858
  }
5693
5859
  if (!this.dataSpaceManager) {
5694
- log16("dataSpaceManager not initialized yet, ignoring space admission", {
5860
+ log18("dataSpaceManager not initialized yet, ignoring space admission", {
5695
5861
  details: assertion
5696
5862
  }, {
5697
- F: __dxlog_file19,
5863
+ F: __dxlog_file20,
5698
5864
  L: 265,
5699
5865
  S: this,
5700
5866
  C: (f, a) => f(...a)
@@ -5702,10 +5868,10 @@ var ServiceContext = class extends Resource2 {
5702
5868
  return;
5703
5869
  }
5704
5870
  if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
5705
- log16("space already exists, ignoring space admission", {
5871
+ log18("space already exists, ignoring space admission", {
5706
5872
  details: assertion
5707
5873
  }, {
5708
- F: __dxlog_file19,
5874
+ F: __dxlog_file20,
5709
5875
  L: 269,
5710
5876
  S: this,
5711
5877
  C: (f, a) => f(...a)
@@ -5713,10 +5879,10 @@ var ServiceContext = class extends Resource2 {
5713
5879
  return;
5714
5880
  }
5715
5881
  try {
5716
- log16("accepting space recorded in halo", {
5882
+ log18("accepting space recorded in halo", {
5717
5883
  details: assertion
5718
5884
  }, {
5719
- F: __dxlog_file19,
5885
+ F: __dxlog_file20,
5720
5886
  L: 274,
5721
5887
  S: this,
5722
5888
  C: (f, a) => f(...a)
@@ -5726,8 +5892,8 @@ var ServiceContext = class extends Resource2 {
5726
5892
  genesisFeedKey: assertion.genesisFeedKey
5727
5893
  });
5728
5894
  } catch (err) {
5729
- log16.catch(err, void 0, {
5730
- F: __dxlog_file19,
5895
+ log18.catch(err, void 0, {
5896
+ F: __dxlog_file20,
5731
5897
  L: 280,
5732
5898
  S: this,
5733
5899
  C: (f, a) => f(...a)
@@ -5774,9 +5940,9 @@ var ServiceRegistry = class {
5774
5940
  };
5775
5941
 
5776
5942
  // packages/sdk/client-services/src/packlets/locks/browser.ts
5777
- import { asyncTimeout as asyncTimeout3, Trigger as Trigger8 } from "@dxos/async";
5943
+ import { asyncTimeout as asyncTimeout3, Trigger as Trigger9 } from "@dxos/async";
5778
5944
  import { RESOURCE_LOCK_TIMEOUT } from "@dxos/client-protocol";
5779
- import { log as log17, logInfo } from "@dxos/log";
5945
+ import { log as log19, logInfo } from "@dxos/log";
5780
5946
  function _ts_decorate7(decorators, target, key, desc) {
5781
5947
  var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
5782
5948
  if (typeof Reflect === "object" && typeof Reflect.decorate === "function")
@@ -5787,7 +5953,7 @@ function _ts_decorate7(decorators, target, key, desc) {
5787
5953
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5788
5954
  return c > 3 && r && Object.defineProperty(target, key, r), r;
5789
5955
  }
5790
- var __dxlog_file20 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
5956
+ var __dxlog_file21 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/locks/browser.ts";
5791
5957
  var Message;
5792
5958
  (function(Message2) {
5793
5959
  Message2["ACQUIRING"] = "acquiring";
@@ -5795,7 +5961,7 @@ var Message;
5795
5961
  var Lock = class {
5796
5962
  constructor({ lockKey, onAcquire, onRelease }) {
5797
5963
  this._broadcastChannel = new BroadcastChannel("vault-resource-lock");
5798
- this._releaseTrigger = new Trigger8();
5964
+ this._releaseTrigger = new Trigger9();
5799
5965
  this._lockKey = lockKey;
5800
5966
  this._onAcquire = onAcquire;
5801
5967
  this._onRelease = onRelease;
@@ -5809,29 +5975,29 @@ var Lock = class {
5809
5975
  message: "acquiring"
5810
5976
  });
5811
5977
  try {
5812
- log17("aquiring lock...", void 0, {
5813
- F: __dxlog_file20,
5978
+ log19("aquiring lock...", void 0, {
5979
+ F: __dxlog_file21,
5814
5980
  L: 42,
5815
5981
  S: this,
5816
5982
  C: (f, a) => f(...a)
5817
5983
  });
5818
5984
  await asyncTimeout3(this._requestLock(), RESOURCE_LOCK_TIMEOUT);
5819
- log17("acquired lock", void 0, {
5820
- F: __dxlog_file20,
5985
+ log19("acquired lock", void 0, {
5986
+ F: __dxlog_file21,
5821
5987
  L: 44,
5822
5988
  S: this,
5823
5989
  C: (f, a) => f(...a)
5824
5990
  });
5825
5991
  } catch {
5826
- log17("stealing lock...", void 0, {
5827
- F: __dxlog_file20,
5992
+ log19("stealing lock...", void 0, {
5993
+ F: __dxlog_file21,
5828
5994
  L: 46,
5829
5995
  S: this,
5830
5996
  C: (f, a) => f(...a)
5831
5997
  });
5832
5998
  await this._requestLock(true);
5833
- log17("stolen lock", void 0, {
5834
- F: __dxlog_file20,
5999
+ log19("stolen lock", void 0, {
6000
+ F: __dxlog_file21,
5835
6001
  L: 48,
5836
6002
  S: this,
5837
6003
  C: (f, a) => f(...a)
@@ -5847,31 +6013,31 @@ var Lock = class {
5847
6013
  }
5848
6014
  }
5849
6015
  async _requestLock(steal = false) {
5850
- log17("requesting lock...", {
6016
+ log19("requesting lock...", {
5851
6017
  steal
5852
6018
  }, {
5853
- F: __dxlog_file20,
6019
+ F: __dxlog_file21,
5854
6020
  L: 63,
5855
6021
  S: this,
5856
6022
  C: (f, a) => f(...a)
5857
6023
  });
5858
- const acquired = new Trigger8();
6024
+ const acquired = new Trigger9();
5859
6025
  void navigator.locks.request(this._lockKey, {
5860
6026
  steal
5861
6027
  }, async () => {
5862
6028
  await this._onAcquire?.();
5863
6029
  acquired.wake();
5864
- this._releaseTrigger = new Trigger8();
6030
+ this._releaseTrigger = new Trigger9();
5865
6031
  await this._releaseTrigger.wait();
5866
- log17("releasing lock...", void 0, {
5867
- F: __dxlog_file20,
6032
+ log19("releasing lock...", void 0, {
6033
+ F: __dxlog_file21,
5868
6034
  L: 72,
5869
6035
  S: this,
5870
6036
  C: (f, a) => f(...a)
5871
6037
  });
5872
6038
  await this._onRelease?.();
5873
- log17("released lock", void 0, {
5874
- F: __dxlog_file20,
6039
+ log19("released lock", void 0, {
6040
+ F: __dxlog_file21,
5875
6041
  L: 74,
5876
6042
  S: this,
5877
6043
  C: (f, a) => f(...a)
@@ -5880,10 +6046,10 @@ var Lock = class {
5880
6046
  await this._onRelease?.();
5881
6047
  });
5882
6048
  await acquired.wait();
5883
- log17("recieved lock", {
6049
+ log19("recieved lock", {
5884
6050
  steal
5885
6051
  }, {
5886
- F: __dxlog_file20,
6052
+ F: __dxlog_file21,
5887
6053
  L: 81,
5888
6054
  S: this,
5889
6055
  C: (f, a) => f(...a)
@@ -5977,7 +6143,7 @@ import { clientServiceBundle } from "@dxos/client-protocol";
5977
6143
  import { Context as Context11 } from "@dxos/context";
5978
6144
  import { invariant as invariant18 } from "@dxos/invariant";
5979
6145
  import { PublicKey as PublicKey16 } from "@dxos/keys";
5980
- import { log as log19 } from "@dxos/log";
6146
+ import { log as log21 } from "@dxos/log";
5981
6147
  import { WebsocketSignalManager } from "@dxos/messaging";
5982
6148
  import { SwarmNetworkManager, createSimplePeerTransportFactory } from "@dxos/network-manager";
5983
6149
  import { trace as trace10 } from "@dxos/protocols";
@@ -5990,7 +6156,7 @@ import { EventSubscriptions as EventSubscriptions3 } from "@dxos/async";
5990
6156
  import { Stream as Stream11 } from "@dxos/codec-protobuf";
5991
6157
  import { invariant as invariant17 } from "@dxos/invariant";
5992
6158
  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";
6159
+ var __dxlog_file22 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/devices/devices-service.ts";
5994
6160
  var DevicesServiceImpl = class {
5995
6161
  constructor(_identityManager) {
5996
6162
  this._identityManager = _identityManager;
@@ -6008,7 +6174,7 @@ var DevicesServiceImpl = class {
6008
6174
  });
6009
6175
  } else {
6010
6176
  invariant17(this._identityManager.identity?.presence, "presence not present", {
6011
- F: __dxlog_file21,
6177
+ F: __dxlog_file22,
6012
6178
  L: 32,
6013
6179
  S: this,
6014
6180
  A: [
@@ -6118,7 +6284,7 @@ var findConfigs = () => {
6118
6284
  import { Event as Event8 } from "@dxos/async";
6119
6285
  import { Stream as Stream12 } from "@dxos/codec-protobuf";
6120
6286
  import { PublicKey as PublicKey15 } from "@dxos/keys";
6121
- import { getContextFromEntry, log as log18 } from "@dxos/log";
6287
+ import { getContextFromEntry, log as log20 } from "@dxos/log";
6122
6288
  import { QueryLogsRequest } from "@dxos/protocols/proto/dxos/client/services";
6123
6289
  import { getDebugName, jsonify, numericalValues, tracer } from "@dxos/util";
6124
6290
  var LoggingServiceImpl = class {
@@ -6131,11 +6297,11 @@ var LoggingServiceImpl = class {
6131
6297
  };
6132
6298
  }
6133
6299
  async open() {
6134
- log18.runtimeConfig.processors.push(this._logProcessor);
6300
+ log20.runtimeConfig.processors.push(this._logProcessor);
6135
6301
  }
6136
6302
  async close() {
6137
- const index = log18.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
6138
- log18.runtimeConfig.processors.splice(index, 1);
6303
+ const index = log20.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
6304
+ log20.runtimeConfig.processors.splice(index, 1);
6139
6305
  }
6140
6306
  async controlMetrics({ reset, record }) {
6141
6307
  if (reset) {
@@ -6339,7 +6505,7 @@ function _ts_decorate8(decorators, target, key, desc) {
6339
6505
  r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6340
6506
  return c > 3 && r && Object.defineProperty(target, key, r), r;
6341
6507
  }
6342
- var __dxlog_file22 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
6508
+ var __dxlog_file23 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/service-host.ts";
6343
6509
  var ClientServicesHost = class {
6344
6510
  constructor({
6345
6511
  config,
@@ -6428,7 +6594,7 @@ var ClientServicesHost = class {
6428
6594
  */
6429
6595
  initialize({ config, ...options }) {
6430
6596
  invariant18(!this._open, "service host is open", {
6431
- F: __dxlog_file22,
6597
+ F: __dxlog_file23,
6432
6598
  L: 186,
6433
6599
  S: this,
6434
6600
  A: [
@@ -6436,15 +6602,15 @@ var ClientServicesHost = class {
6436
6602
  "'service host is open'"
6437
6603
  ]
6438
6604
  });
6439
- log19("initializing...", void 0, {
6440
- F: __dxlog_file22,
6605
+ log21("initializing...", void 0, {
6606
+ F: __dxlog_file23,
6441
6607
  L: 187,
6442
6608
  S: this,
6443
6609
  C: (f, a) => f(...a)
6444
6610
  });
6445
6611
  if (config) {
6446
6612
  invariant18(!this._config, "config already set", {
6447
- F: __dxlog_file22,
6613
+ F: __dxlog_file23,
6448
6614
  L: 190,
6449
6615
  S: this,
6450
6616
  A: [
@@ -6458,8 +6624,8 @@ var ClientServicesHost = class {
6458
6624
  }
6459
6625
  }
6460
6626
  if (!options.signalManager) {
6461
- log19.warn("running signaling without telemetry metadata.", void 0, {
6462
- F: __dxlog_file22,
6627
+ log21.warn("running signaling without telemetry metadata.", void 0, {
6628
+ F: __dxlog_file23,
6463
6629
  L: 198,
6464
6630
  S: this,
6465
6631
  C: (f, a) => f(...a)
@@ -6470,7 +6636,7 @@ var ClientServicesHost = class {
6470
6636
  }), signalManager = new WebsocketSignalManager(this._config?.get("runtime.services.signaling") ?? []) } = options;
6471
6637
  this._signalManager = signalManager;
6472
6638
  invariant18(!this._networkManager, "network manager already set", {
6473
- F: __dxlog_file22,
6639
+ F: __dxlog_file23,
6474
6640
  L: 209,
6475
6641
  S: this,
6476
6642
  A: [
@@ -6483,8 +6649,8 @@ var ClientServicesHost = class {
6483
6649
  transportFactory,
6484
6650
  signalManager
6485
6651
  });
6486
- log19("initialized", void 0, {
6487
- F: __dxlog_file22,
6652
+ log21("initialized", void 0, {
6653
+ F: __dxlog_file23,
6488
6654
  L: 216,
6489
6655
  S: this,
6490
6656
  C: (f, a) => f(...a)
@@ -6495,16 +6661,16 @@ var ClientServicesHost = class {
6495
6661
  return;
6496
6662
  }
6497
6663
  const traceId = PublicKey16.random().toHex();
6498
- log19.trace("dxos.client-services.host.open", trace10.begin({
6664
+ log21.trace("dxos.client-services.host.open", trace10.begin({
6499
6665
  id: traceId
6500
6666
  }), {
6501
- F: __dxlog_file22,
6667
+ F: __dxlog_file23,
6502
6668
  L: 227,
6503
6669
  S: this,
6504
6670
  C: (f, a) => f(...a)
6505
6671
  });
6506
6672
  invariant18(this._config, "config not set", {
6507
- F: __dxlog_file22,
6673
+ F: __dxlog_file23,
6508
6674
  L: 229,
6509
6675
  S: this,
6510
6676
  A: [
@@ -6513,7 +6679,7 @@ var ClientServicesHost = class {
6513
6679
  ]
6514
6680
  });
6515
6681
  invariant18(this._storage, "storage not set", {
6516
- F: __dxlog_file22,
6682
+ F: __dxlog_file23,
6517
6683
  L: 230,
6518
6684
  S: this,
6519
6685
  A: [
@@ -6522,7 +6688,7 @@ var ClientServicesHost = class {
6522
6688
  ]
6523
6689
  });
6524
6690
  invariant18(this._signalManager, "signal manager not set", {
6525
- F: __dxlog_file22,
6691
+ F: __dxlog_file23,
6526
6692
  L: 231,
6527
6693
  S: this,
6528
6694
  A: [
@@ -6531,7 +6697,7 @@ var ClientServicesHost = class {
6531
6697
  ]
6532
6698
  });
6533
6699
  invariant18(this._networkManager, "network manager not set", {
6534
- F: __dxlog_file22,
6700
+ F: __dxlog_file23,
6535
6701
  L: 232,
6536
6702
  S: this,
6537
6703
  A: [
@@ -6540,10 +6706,10 @@ var ClientServicesHost = class {
6540
6706
  ]
6541
6707
  });
6542
6708
  this._opening = true;
6543
- log19("opening...", {
6709
+ log21("opening...", {
6544
6710
  lockKey: this._resourceLock?.lockKey
6545
6711
  }, {
6546
- F: __dxlog_file22,
6712
+ F: __dxlog_file23,
6547
6713
  L: 235,
6548
6714
  S: this,
6549
6715
  C: (f, a) => f(...a)
@@ -6594,18 +6760,18 @@ var ClientServicesHost = class {
6594
6760
  this._open = true;
6595
6761
  this._statusUpdate.emit();
6596
6762
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
6597
- log19("opened", {
6763
+ log21("opened", {
6598
6764
  deviceKey
6599
6765
  }, {
6600
- F: __dxlog_file22,
6766
+ F: __dxlog_file23,
6601
6767
  L: 314,
6602
6768
  S: this,
6603
6769
  C: (f, a) => f(...a)
6604
6770
  });
6605
- log19.trace("dxos.client-services.host.open", trace10.end({
6771
+ log21.trace("dxos.client-services.host.open", trace10.end({
6606
6772
  id: traceId
6607
6773
  }), {
6608
- F: __dxlog_file22,
6774
+ F: __dxlog_file23,
6609
6775
  L: 315,
6610
6776
  S: this,
6611
6777
  C: (f, a) => f(...a)
@@ -6616,10 +6782,10 @@ var ClientServicesHost = class {
6616
6782
  return;
6617
6783
  }
6618
6784
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
6619
- log19("closing...", {
6785
+ log21("closing...", {
6620
6786
  deviceKey
6621
6787
  }, {
6622
- F: __dxlog_file22,
6788
+ F: __dxlog_file23,
6623
6789
  L: 326,
6624
6790
  S: this,
6625
6791
  C: (f, a) => f(...a)
@@ -6634,10 +6800,10 @@ var ClientServicesHost = class {
6634
6800
  await this._level?.close();
6635
6801
  this._open = false;
6636
6802
  this._statusUpdate.emit();
6637
- log19("closed", {
6803
+ log21("closed", {
6638
6804
  deviceKey
6639
6805
  }, {
6640
- F: __dxlog_file22,
6806
+ F: __dxlog_file23,
6641
6807
  L: 335,
6642
6808
  S: this,
6643
6809
  C: (f, a) => f(...a)
@@ -6645,32 +6811,32 @@ var ClientServicesHost = class {
6645
6811
  }
6646
6812
  async reset() {
6647
6813
  const traceId = PublicKey16.random().toHex();
6648
- log19.trace("dxos.sdk.client-services-host.reset", trace10.begin({
6814
+ log21.trace("dxos.sdk.client-services-host.reset", trace10.begin({
6649
6815
  id: traceId
6650
6816
  }), {
6651
- F: __dxlog_file22,
6817
+ F: __dxlog_file23,
6652
6818
  L: 340,
6653
6819
  S: this,
6654
6820
  C: (f, a) => f(...a)
6655
6821
  });
6656
- log19.info("resetting...", void 0, {
6657
- F: __dxlog_file22,
6822
+ log21.info("resetting...", void 0, {
6823
+ F: __dxlog_file23,
6658
6824
  L: 342,
6659
6825
  S: this,
6660
6826
  C: (f, a) => f(...a)
6661
6827
  });
6662
6828
  await this._serviceContext?.close();
6663
6829
  await this._storage.reset();
6664
- log19.info("reset", void 0, {
6665
- F: __dxlog_file22,
6830
+ log21.info("reset", void 0, {
6831
+ F: __dxlog_file23,
6666
6832
  L: 345,
6667
6833
  S: this,
6668
6834
  C: (f, a) => f(...a)
6669
6835
  });
6670
- log19.trace("dxos.sdk.client-services-host.reset", trace10.end({
6836
+ log21.trace("dxos.sdk.client-services-host.reset", trace10.end({
6671
6837
  id: traceId
6672
6838
  }), {
6673
- F: __dxlog_file22,
6839
+ F: __dxlog_file23,
6674
6840
  L: 346,
6675
6841
  S: this,
6676
6842
  C: (f, a) => f(...a)
@@ -6729,7 +6895,6 @@ export {
6729
6895
  SpaceInvitationProtocol,
6730
6896
  InvitationsManager,
6731
6897
  DataSpace,
6732
- findPropertiesObject,
6733
6898
  DataSpaceManager,
6734
6899
  SpacesServiceImpl,
6735
6900
  ServiceContext,
@@ -6742,4 +6907,4 @@ export {
6742
6907
  ClientServicesProviderResource,
6743
6908
  DiagnosticsCollector
6744
6909
  };
6745
- //# sourceMappingURL=chunk-DJUHMW47.mjs.map
6910
+ //# sourceMappingURL=chunk-BTHX37CG.mjs.map