@dxos/client-services 0.4.7 → 0.4.8-main.0602afb

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 (38) hide show
  1. package/dist/lib/browser/{chunk-NI6XJLUJ.mjs → chunk-WAR4XN64.mjs} +348 -160
  2. package/dist/lib/browser/chunk-WAR4XN64.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +3 -1
  4. package/dist/lib/browser/index.mjs.map +1 -1
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/packlets/testing/index.mjs +1 -1
  7. package/dist/lib/node/{chunk-RH65IX2V.cjs → chunk-S4SHWFEU.cjs} +323 -134
  8. package/dist/lib/node/chunk-S4SHWFEU.cjs.map +7 -0
  9. package/dist/lib/node/index.cjs +39 -37
  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/invitations/invitations-handler.d.ts +1 -0
  14. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  15. package/dist/types/src/packlets/invitations/invitations-service.d.ts +9 -1
  16. package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
  17. package/dist/types/src/packlets/services/service-context.d.ts +2 -1
  18. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  19. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  20. package/dist/types/src/packlets/spaces/automerge-space-state.d.ts +2 -0
  21. package/dist/types/src/packlets/spaces/automerge-space-state.d.ts.map +1 -1
  22. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  23. package/dist/types/src/packlets/spaces/spaces-service.d.ts +1 -1
  24. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  25. package/dist/types/src/version.d.ts +1 -1
  26. package/dist/types/src/version.d.ts.map +1 -1
  27. package/package.json +37 -35
  28. package/src/packlets/identity/identity-manager.ts +1 -1
  29. package/src/packlets/invitations/invitations-handler.ts +37 -2
  30. package/src/packlets/invitations/invitations-service.ts +83 -5
  31. package/src/packlets/services/service-context.ts +26 -4
  32. package/src/packlets/services/service-host.ts +15 -2
  33. package/src/packlets/spaces/automerge-space-state.ts +15 -0
  34. package/src/packlets/spaces/data-space.ts +33 -11
  35. package/src/packlets/spaces/spaces-service.ts +2 -2
  36. package/src/version.ts +1 -5
  37. package/dist/lib/browser/chunk-NI6XJLUJ.mjs.map +0 -7
  38. package/dist/lib/node/chunk-RH65IX2V.cjs.map +0 -7
@@ -26,8 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var chunk_RH65IX2V_exports = {};
30
- __export(chunk_RH65IX2V_exports, {
29
+ var chunk_S4SHWFEU_exports = {};
30
+ __export(chunk_S4SHWFEU_exports, {
31
31
  ClientRpcServer: () => ClientRpcServer,
32
32
  ClientServicesHost: () => ClientServicesHost,
33
33
  DataSpace: () => DataSpace,
@@ -51,6 +51,7 @@ __export(chunk_RH65IX2V_exports, {
51
51
  createDiagnostics: () => createDiagnostics,
52
52
  createStorageObjects: () => createStorageObjects,
53
53
  getNetworkPeers: () => getNetworkPeers,
54
+ invitationExpired: () => invitationExpired,
54
55
  isLocked: () => isLocked,
55
56
  subscribeToFeedBlocks: () => subscribeToFeedBlocks,
56
57
  subscribeToFeeds: () => subscribeToFeeds,
@@ -60,7 +61,7 @@ __export(chunk_RH65IX2V_exports, {
60
61
  subscribeToSpaces: () => subscribeToSpaces,
61
62
  subscribeToSwarmInfo: () => subscribeToSwarmInfo
62
63
  });
63
- module.exports = __toCommonJS(chunk_RH65IX2V_exports);
64
+ module.exports = __toCommonJS(chunk_S4SHWFEU_exports);
64
65
  var import_async = require("@dxos/async");
65
66
  var import_codec_protobuf = require("@dxos/codec-protobuf");
66
67
  var import_feed_store = require("@dxos/feed-store");
@@ -133,6 +134,7 @@ var import_invitations2 = require("@dxos/protocols/proto/dxos/halo/invitations")
133
134
  var import_teleport = require("@dxos/teleport");
134
135
  var import_async9 = require("@dxos/async");
135
136
  var import_codec_protobuf8 = require("@dxos/codec-protobuf");
137
+ var import_context6 = require("@dxos/context");
136
138
  var import_invariant7 = require("@dxos/invariant");
137
139
  var import_log6 = require("@dxos/log");
138
140
  var import_services5 = require("@dxos/protocols/proto/dxos/client/services");
@@ -158,7 +160,7 @@ var import_tracing4 = require("@dxos/tracing");
158
160
  var import_services8 = require("@dxos/protocols/proto/dxos/client/services");
159
161
  var import_async10 = require("@dxos/async");
160
162
  var import_client_protocol3 = require("@dxos/client-protocol");
161
- var import_context6 = require("@dxos/context");
163
+ var import_context7 = require("@dxos/context");
162
164
  var import_debug3 = require("@dxos/debug");
163
165
  var import_echo_pipeline = require("@dxos/echo-pipeline");
164
166
  var import_invariant10 = require("@dxos/invariant");
@@ -172,7 +174,7 @@ var import_tracing5 = require("@dxos/tracing");
172
174
  var import_util4 = require("@dxos/util");
173
175
  var import_credentials11 = require("@dxos/credentials");
174
176
  var import_async11 = require("@dxos/async");
175
- var import_context7 = require("@dxos/context");
177
+ var import_context8 = require("@dxos/context");
176
178
  var import_invariant11 = require("@dxos/invariant");
177
179
  var import_keys8 = require("@dxos/keys");
178
180
  var import_log10 = require("@dxos/log");
@@ -180,7 +182,7 @@ var import_protocols9 = require("@dxos/protocols");
180
182
  var import_teleport2 = require("@dxos/teleport");
181
183
  var import_util5 = require("@dxos/util");
182
184
  var import_async12 = require("@dxos/async");
183
- var import_context8 = require("@dxos/context");
185
+ var import_context9 = require("@dxos/context");
184
186
  var import_credentials12 = require("@dxos/credentials");
185
187
  var import_invariant12 = require("@dxos/invariant");
186
188
  var import_keys9 = require("@dxos/keys");
@@ -201,12 +203,13 @@ var import_log12 = require("@dxos/log");
201
203
  var import_protocols11 = require("@dxos/protocols");
202
204
  var import_services11 = require("@dxos/protocols/proto/dxos/client/services");
203
205
  var import_async14 = require("@dxos/async");
204
- var import_context9 = require("@dxos/context");
206
+ var import_automerge = require("@dxos/automerge/automerge");
207
+ var import_context10 = require("@dxos/context");
205
208
  var import_credentials15 = require("@dxos/credentials");
206
209
  var import_debug6 = require("@dxos/debug");
207
210
  var import_echo_pipeline2 = require("@dxos/echo-pipeline");
208
- var import_echo_schema = require("@dxos/echo-schema");
209
211
  var import_feed_store4 = require("@dxos/feed-store");
212
+ var import_indexing = require("@dxos/indexing");
210
213
  var import_invariant14 = require("@dxos/invariant");
211
214
  var import_keyring = require("@dxos/keyring");
212
215
  var import_keys10 = require("@dxos/keys");
@@ -226,10 +229,11 @@ var import_random_access_storage = require("@dxos/random-access-storage");
226
229
  var import_util8 = require("@dxos/util");
227
230
  var import_async15 = require("@dxos/async");
228
231
  var import_client_protocol5 = require("@dxos/client-protocol");
229
- var import_context10 = require("@dxos/context");
232
+ var import_context11 = require("@dxos/context");
230
233
  var import_document_model2 = require("@dxos/document-model");
231
234
  var import_echo_pipeline3 = require("@dxos/echo-pipeline");
232
- var import_echo_schema2 = require("@dxos/echo-schema");
235
+ var import_echo_schema = require("@dxos/echo-schema");
236
+ var import_indexing2 = require("@dxos/indexing");
233
237
  var import_invariant16 = require("@dxos/invariant");
234
238
  var import_keys11 = require("@dxos/keys");
235
239
  var import_log15 = require("@dxos/log");
@@ -1230,7 +1234,7 @@ var IdentityManager = class {
1230
1234
  identityKey: identityRecord.identityKey
1231
1235
  });
1232
1236
  await space.setControlFeed(controlFeed);
1233
- void space.setDataFeed(dataFeed);
1237
+ await space.setDataFeed(dataFeed);
1234
1238
  const identity = new Identity({
1235
1239
  space,
1236
1240
  presence,
@@ -1788,11 +1792,11 @@ var InvitationsHandler = class {
1788
1792
  this._networkManager = _networkManager;
1789
1793
  }
1790
1794
  createInvitation(protocol, options) {
1791
- const { invitationId = import_keys5.PublicKey.random().toHex(), type = import_services3.Invitation.Type.INTERACTIVE, authMethod = import_services3.Invitation.AuthMethod.SHARED_SECRET, state = import_services3.Invitation.State.INIT, timeout = import_client_protocol2.INVITATION_TIMEOUT, swarmKey = import_keys5.PublicKey.random() } = options ?? {};
1795
+ const { invitationId = import_keys5.PublicKey.random().toHex(), type = import_services3.Invitation.Type.INTERACTIVE, authMethod = import_services3.Invitation.AuthMethod.SHARED_SECRET, state = import_services3.Invitation.State.INIT, timeout = import_client_protocol2.INVITATION_TIMEOUT, swarmKey = import_keys5.PublicKey.random(), persistent = true, created = /* @__PURE__ */ new Date(), lifetime = 86400 } = options ?? {};
1792
1796
  const authCode = options?.authCode ?? (authMethod === import_services3.Invitation.AuthMethod.SHARED_SECRET ? (0, import_credentials7.generatePasscode)(import_client_protocol2.AUTHENTICATION_CODE_LENGTH) : void 0);
1793
1797
  (0, import_invariant5.invariant)(protocol, void 0, {
1794
1798
  F: __dxlog_file7,
1795
- L: 81,
1799
+ L: 84,
1796
1800
  S: this,
1797
1801
  A: [
1798
1802
  "protocol",
@@ -1807,13 +1811,16 @@ var InvitationsHandler = class {
1807
1811
  swarmKey,
1808
1812
  authCode,
1809
1813
  timeout,
1814
+ persistent,
1815
+ created,
1816
+ lifetime,
1810
1817
  ...protocol.getInvitationContext()
1811
1818
  };
1812
1819
  const stream = new import_async7.PushStream();
1813
1820
  const ctx = new import_context4.Context({
1814
1821
  onError: (err) => {
1815
- void ctx.dispose();
1816
1822
  stream.error(err);
1823
+ void ctx.dispose();
1817
1824
  }
1818
1825
  });
1819
1826
  ctx.onDispose(() => {
@@ -1821,7 +1828,7 @@ var InvitationsHandler = class {
1821
1828
  ...protocol.toJSON()
1822
1829
  }, {
1823
1830
  F: __dxlog_file7,
1824
- L: 103,
1831
+ L: 109,
1825
1832
  S: this,
1826
1833
  C: (f, a) => f(...a)
1827
1834
  });
@@ -1846,7 +1853,7 @@ var InvitationsHandler = class {
1846
1853
  const deviceKey = admissionRequest.device?.deviceKey ?? admissionRequest.space?.deviceKey;
1847
1854
  (0, import_invariant5.invariant)(deviceKey, void 0, {
1848
1855
  F: __dxlog_file7,
1849
- L: 124,
1856
+ L: 130,
1850
1857
  S: this,
1851
1858
  A: [
1852
1859
  "deviceKey",
@@ -1869,7 +1876,7 @@ var InvitationsHandler = class {
1869
1876
  id: traceId
1870
1877
  }), {
1871
1878
  F: __dxlog_file7,
1872
- L: 142,
1879
+ L: 148,
1873
1880
  S: this,
1874
1881
  C: (f, a) => f(...a)
1875
1882
  });
@@ -1877,7 +1884,7 @@ var InvitationsHandler = class {
1877
1884
  ...protocol.toJSON()
1878
1885
  }, {
1879
1886
  F: __dxlog_file7,
1880
- L: 143,
1887
+ L: 149,
1881
1888
  S: this,
1882
1889
  C: (f, a) => f(...a)
1883
1890
  });
@@ -1893,7 +1900,7 @@ var InvitationsHandler = class {
1893
1900
  ...protocol.toJSON()
1894
1901
  }, {
1895
1902
  F: __dxlog_file7,
1896
- L: 146,
1903
+ L: 152,
1897
1904
  S: this,
1898
1905
  C: (f, a) => f(...a)
1899
1906
  });
@@ -1905,7 +1912,7 @@ var InvitationsHandler = class {
1905
1912
  id: traceId
1906
1913
  }), {
1907
1914
  F: __dxlog_file7,
1908
- L: 148,
1915
+ L: 154,
1909
1916
  S: this,
1910
1917
  C: (f, a) => f(...a)
1911
1918
  });
@@ -1915,7 +1922,7 @@ var InvitationsHandler = class {
1915
1922
  ...protocol.toJSON()
1916
1923
  }, {
1917
1924
  F: __dxlog_file7,
1918
- L: 151,
1925
+ L: 157,
1919
1926
  S: this,
1920
1927
  C: (f, a) => f(...a)
1921
1928
  });
@@ -1926,7 +1933,7 @@ var InvitationsHandler = class {
1926
1933
  } else {
1927
1934
  import_log4.log.error("failed", err, {
1928
1935
  F: __dxlog_file7,
1929
- L: 154,
1936
+ L: 160,
1930
1937
  S: this,
1931
1938
  C: (f, a) => f(...a)
1932
1939
  });
@@ -1937,7 +1944,7 @@ var InvitationsHandler = class {
1937
1944
  error: err
1938
1945
  }), {
1939
1946
  F: __dxlog_file7,
1940
- L: 157,
1947
+ L: 163,
1941
1948
  S: this,
1942
1949
  C: (f, a) => f(...a)
1943
1950
  });
@@ -1958,7 +1965,7 @@ var InvitationsHandler = class {
1958
1965
  ...protocol.toJSON()
1959
1966
  }, {
1960
1967
  F: __dxlog_file7,
1961
- L: 172,
1968
+ L: 178,
1962
1969
  S: this,
1963
1970
  C: (f, a) => f(...a)
1964
1971
  });
@@ -1969,7 +1976,7 @@ var InvitationsHandler = class {
1969
1976
  } else {
1970
1977
  import_log4.log.error("failed", err, {
1971
1978
  F: __dxlog_file7,
1972
- L: 175,
1979
+ L: 181,
1973
1980
  S: this,
1974
1981
  C: (f, a) => f(...a)
1975
1982
  });
@@ -1979,7 +1986,27 @@ var InvitationsHandler = class {
1979
1986
  });
1980
1987
  return extension;
1981
1988
  };
1989
+ if (invitation.lifetime && invitation.created && invitation.lifetime !== 0) {
1990
+ if (invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now()) {
1991
+ import_log4.log.warn("invitation has already expired", void 0, {
1992
+ F: __dxlog_file7,
1993
+ L: 192,
1994
+ S: this,
1995
+ C: (f, a) => f(...a)
1996
+ });
1997
+ } else {
1998
+ (0, import_async7.scheduleTask)(ctx, async () => {
1999
+ await swarmConnection.close();
2000
+ stream.next({
2001
+ ...invitation,
2002
+ state: import_services3.Invitation.State.EXPIRED
2003
+ });
2004
+ await ctx.dispose();
2005
+ }, invitation.created.getTime() + invitation.lifetime * 1e3 - Date.now());
2006
+ }
2007
+ }
1982
2008
  let swarmConnection;
2009
+ const invitationLabel = "invitation host for " + (invitation.kind === import_services3.Invitation.Kind.DEVICE ? "device" : `space ${invitation.spaceKey?.truncate()}`);
1983
2010
  (0, import_async7.scheduleTask)(ctx, async () => {
1984
2011
  const topic = invitation.swarmKey;
1985
2012
  swarmConnection = await this._networkManager.joinSwarm({
@@ -1989,7 +2016,7 @@ var InvitationsHandler = class {
1989
2016
  teleport.addExtension("dxos.halo.invitations", createExtension());
1990
2017
  }),
1991
2018
  topology: new import_network_manager.StarTopology(topic),
1992
- label: "invitation host"
2019
+ label: invitationLabel
1993
2020
  });
1994
2021
  ctx.onDispose(() => swarmConnection.close());
1995
2022
  stream.next({
@@ -2014,7 +2041,7 @@ var InvitationsHandler = class {
2014
2041
  const { timeout = import_client_protocol2.INVITATION_TIMEOUT } = invitation;
2015
2042
  (0, import_invariant5.invariant)(protocol, void 0, {
2016
2043
  F: __dxlog_file7,
2017
- L: 220,
2044
+ L: 246,
2018
2045
  S: this,
2019
2046
  A: [
2020
2047
  "protocol",
@@ -2024,7 +2051,7 @@ var InvitationsHandler = class {
2024
2051
  if (deviceProfile) {
2025
2052
  (0, import_invariant5.invariant)(invitation.kind === import_services3.Invitation.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
2026
2053
  F: __dxlog_file7,
2027
- L: 224,
2054
+ L: 250,
2028
2055
  S: this,
2029
2056
  A: [
2030
2057
  "invitation.kind === Invitation.Kind.DEVICE",
@@ -2039,7 +2066,7 @@ var InvitationsHandler = class {
2039
2066
  const setState = (newData) => {
2040
2067
  (0, import_invariant5.invariant)(newData.state !== void 0, void 0, {
2041
2068
  F: __dxlog_file7,
2042
- L: 235,
2069
+ L: 261,
2043
2070
  S: this,
2044
2071
  A: [
2045
2072
  "newData.state !== undefined",
@@ -2059,7 +2086,7 @@ var InvitationsHandler = class {
2059
2086
  ...protocol.toJSON()
2060
2087
  }, {
2061
2088
  F: __dxlog_file7,
2062
- L: 243,
2089
+ L: 269,
2063
2090
  S: this,
2064
2091
  C: (f, a) => f(...a)
2065
2092
  });
@@ -2069,7 +2096,7 @@ var InvitationsHandler = class {
2069
2096
  } else {
2070
2097
  import_log4.log.warn("auth failed", err, {
2071
2098
  F: __dxlog_file7,
2072
- L: 246,
2099
+ L: 272,
2073
2100
  S: this,
2074
2101
  C: (f, a) => f(...a)
2075
2102
  });
@@ -2083,7 +2110,7 @@ var InvitationsHandler = class {
2083
2110
  ...protocol.toJSON()
2084
2111
  }, {
2085
2112
  F: __dxlog_file7,
2086
- L: 254,
2113
+ L: 280,
2087
2114
  S: this,
2088
2115
  C: (f, a) => f(...a)
2089
2116
  });
@@ -2098,7 +2125,7 @@ var InvitationsHandler = class {
2098
2125
  currentState
2099
2126
  }, {
2100
2127
  F: __dxlog_file7,
2101
- L: 264,
2128
+ L: 290,
2102
2129
  S: this,
2103
2130
  C: (f, a) => f(...a)
2104
2131
  });
@@ -2113,7 +2140,7 @@ var InvitationsHandler = class {
2113
2140
  id: traceId
2114
2141
  }), {
2115
2142
  F: __dxlog_file7,
2116
- L: 273,
2143
+ L: 299,
2117
2144
  S: this,
2118
2145
  C: (f, a) => f(...a)
2119
2146
  });
@@ -2125,7 +2152,7 @@ var InvitationsHandler = class {
2125
2152
  ...protocol.toJSON()
2126
2153
  }, {
2127
2154
  F: __dxlog_file7,
2128
- L: 281,
2155
+ L: 307,
2129
2156
  S: this,
2130
2157
  C: (f, a) => f(...a)
2131
2158
  });
@@ -2136,7 +2163,7 @@ var InvitationsHandler = class {
2136
2163
  ...protocol.toJSON()
2137
2164
  }, {
2138
2165
  F: __dxlog_file7,
2139
- L: 285,
2166
+ L: 311,
2140
2167
  S: this,
2141
2168
  C: (f, a) => f(...a)
2142
2169
  });
@@ -2146,7 +2173,7 @@ var InvitationsHandler = class {
2146
2173
  response: introductionResponse
2147
2174
  }, {
2148
2175
  F: __dxlog_file7,
2149
- L: 289,
2176
+ L: 315,
2150
2177
  S: this,
2151
2178
  C: (f, a) => f(...a)
2152
2179
  });
@@ -2155,7 +2182,7 @@ var InvitationsHandler = class {
2155
2182
  for (let attempt = 1; attempt <= MAX_OTP_ATTEMPTS; attempt++) {
2156
2183
  (0, import_log4.log)("guest waiting for authentication code...", void 0, {
2157
2184
  F: __dxlog_file7,
2158
- L: 295,
2185
+ L: 321,
2159
2186
  S: this,
2160
2187
  C: (f, a) => f(...a)
2161
2188
  });
@@ -2167,7 +2194,7 @@ var InvitationsHandler = class {
2167
2194
  });
2168
2195
  (0, import_log4.log)("sending authentication request", void 0, {
2169
2196
  F: __dxlog_file7,
2170
- L: 299,
2197
+ L: 325,
2171
2198
  S: this,
2172
2199
  C: (f, a) => f(...a)
2173
2200
  });
@@ -2188,7 +2215,7 @@ var InvitationsHandler = class {
2188
2215
  attempt
2189
2216
  }, {
2190
2217
  F: __dxlog_file7,
2191
- L: 310,
2218
+ L: 336,
2192
2219
  S: this,
2193
2220
  C: (f, a) => f(...a)
2194
2221
  });
@@ -2201,7 +2228,7 @@ var InvitationsHandler = class {
2201
2228
  ...protocol.toJSON()
2202
2229
  }, {
2203
2230
  F: __dxlog_file7,
2204
- L: 318,
2231
+ L: 344,
2205
2232
  S: this,
2206
2233
  C: (f, a) => f(...a)
2207
2234
  });
@@ -2213,7 +2240,7 @@ var InvitationsHandler = class {
2213
2240
  ...protocol.toJSON()
2214
2241
  }, {
2215
2242
  F: __dxlog_file7,
2216
- L: 329,
2243
+ L: 355,
2217
2244
  S: this,
2218
2245
  C: (f, a) => f(...a)
2219
2246
  });
@@ -2226,7 +2253,7 @@ var InvitationsHandler = class {
2226
2253
  id: traceId
2227
2254
  }), {
2228
2255
  F: __dxlog_file7,
2229
- L: 331,
2256
+ L: 357,
2230
2257
  S: this,
2231
2258
  C: (f, a) => f(...a)
2232
2259
  });
@@ -2236,7 +2263,7 @@ var InvitationsHandler = class {
2236
2263
  ...protocol.toJSON()
2237
2264
  }, {
2238
2265
  F: __dxlog_file7,
2239
- L: 334,
2266
+ L: 360,
2240
2267
  S: this,
2241
2268
  C: (f, a) => f(...a)
2242
2269
  });
@@ -2246,7 +2273,7 @@ var InvitationsHandler = class {
2246
2273
  } else {
2247
2274
  (0, import_log4.log)("auth failed", err, {
2248
2275
  F: __dxlog_file7,
2249
- L: 337,
2276
+ L: 363,
2250
2277
  S: this,
2251
2278
  C: (f, a) => f(...a)
2252
2279
  });
@@ -2257,7 +2284,7 @@ var InvitationsHandler = class {
2257
2284
  error: err
2258
2285
  }), {
2259
2286
  F: __dxlog_file7,
2260
- L: 340,
2287
+ L: 366,
2261
2288
  S: this,
2262
2289
  C: (f, a) => f(...a)
2263
2290
  });
@@ -2275,7 +2302,7 @@ var InvitationsHandler = class {
2275
2302
  ...protocol.toJSON()
2276
2303
  }, {
2277
2304
  F: __dxlog_file7,
2278
- L: 351,
2305
+ L: 377,
2279
2306
  S: this,
2280
2307
  C: (f, a) => f(...a)
2281
2308
  });
@@ -2285,7 +2312,7 @@ var InvitationsHandler = class {
2285
2312
  } else {
2286
2313
  (0, import_log4.log)("auth failed", err, {
2287
2314
  F: __dxlog_file7,
2288
- L: 354,
2315
+ L: 380,
2289
2316
  S: this,
2290
2317
  C: (f, a) => f(...a)
2291
2318
  });
@@ -2302,7 +2329,7 @@ var InvitationsHandler = class {
2302
2329
  } else {
2303
2330
  (0, import_invariant5.invariant)(invitation.swarmKey, void 0, {
2304
2331
  F: __dxlog_file7,
2305
- L: 368,
2332
+ L: 394,
2306
2333
  S: this,
2307
2334
  A: [
2308
2335
  "invitation.swarmKey",
@@ -2341,17 +2368,24 @@ var InvitationsHandler = class {
2341
2368
  return observable;
2342
2369
  }
2343
2370
  };
2371
+ var invitationExpired = (invitation) => {
2372
+ return invitation.created && invitation.lifetime && invitation.lifetime !== 0 && invitation.created.getTime() + invitation.lifetime * 1e3 < Date.now();
2373
+ };
2344
2374
  var __dxlog_file8 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/invitations/invitations-service.ts";
2345
2375
  var InvitationsServiceImpl = class {
2346
- constructor(_invitationsHandler, _getHandler) {
2376
+ constructor(_invitationsHandler, _getHandler, _metadataStore) {
2347
2377
  this._invitationsHandler = _invitationsHandler;
2348
2378
  this._getHandler = _getHandler;
2379
+ this._metadataStore = _metadataStore;
2349
2380
  this._createInvitations = /* @__PURE__ */ new Map();
2350
2381
  this._acceptInvitations = /* @__PURE__ */ new Map();
2351
2382
  this._invitationCreated = new import_async9.Event();
2352
2383
  this._invitationAccepted = new import_async9.Event();
2353
2384
  this._removedCreated = new import_async9.Event();
2354
2385
  this._removedAccepted = new import_async9.Event();
2386
+ this._saved = new import_async9.Event();
2387
+ this._persistentInvitationsLoadedEvent = new import_async9.Event();
2388
+ this._persistentInvitationsLoaded = false;
2355
2389
  }
2356
2390
  // TODO(burdon): Guest/host label.
2357
2391
  getLoggingContext() {
@@ -2359,6 +2393,7 @@ var InvitationsServiceImpl = class {
2359
2393
  }
2360
2394
  createInvitation(options) {
2361
2395
  let invitation;
2396
+ const savePersistentInvitationCtx = new import_context6.Context();
2362
2397
  const existingInvitation = this._createInvitations.get(options.invitationId);
2363
2398
  if (existingInvitation) {
2364
2399
  invitation = existingInvitation;
@@ -2369,12 +2404,27 @@ var InvitationsServiceImpl = class {
2369
2404
  this._invitationCreated.emit(invitation.get());
2370
2405
  }
2371
2406
  return new import_codec_protobuf8.Stream(({ next, close }) => {
2407
+ if (invitation.get().persistent) {
2408
+ (0, import_async9.scheduleTask)(savePersistentInvitationCtx, async () => {
2409
+ try {
2410
+ await this._metadataStore.addInvitation(invitation.get());
2411
+ this._saved.emit(invitation.get());
2412
+ } catch (err) {
2413
+ close(err);
2414
+ }
2415
+ });
2416
+ }
2372
2417
  invitation.subscribe((invitation2) => {
2373
2418
  next(invitation2);
2374
- }, (err) => {
2419
+ }, async (err) => {
2420
+ await savePersistentInvitationCtx.dispose();
2375
2421
  close(err);
2376
- }, () => {
2422
+ }, async () => {
2377
2423
  close();
2424
+ if (invitation.get().persistent) {
2425
+ await savePersistentInvitationCtx.dispose();
2426
+ await this._metadataStore.removeInvitation(invitation.get().invitationId);
2427
+ }
2378
2428
  this._createInvitations.delete(invitation.get().invitationId);
2379
2429
  if (invitation.get().type !== import_services5.Invitation.Type.MULTIUSE) {
2380
2430
  this._removedCreated.emit(invitation.get());
@@ -2382,12 +2432,37 @@ var InvitationsServiceImpl = class {
2382
2432
  });
2383
2433
  });
2384
2434
  }
2435
+ async loadPersistentInvitations() {
2436
+ const persistentInvitations = this._metadataStore.getInvitations();
2437
+ const freshInvitations = persistentInvitations.filter(async (invitation) => !invitationExpired(invitation));
2438
+ const cInvitations = freshInvitations.map((persistentInvitation) => {
2439
+ (0, import_invariant7.invariant)(!this._createInvitations.get(persistentInvitation.invitationId), "invitation already exists", {
2440
+ F: __dxlog_file8,
2441
+ L: 109,
2442
+ S: this,
2443
+ A: [
2444
+ "!this._createInvitations.get(persistentInvitation.invitationId)",
2445
+ "'invitation already exists'"
2446
+ ]
2447
+ });
2448
+ const handler = this._getHandler(persistentInvitation);
2449
+ const invitation = this._invitationsHandler.createInvitation(handler, persistentInvitation);
2450
+ this._createInvitations.set(invitation.get().invitationId, invitation);
2451
+ this._invitationCreated.emit(invitation.get());
2452
+ return persistentInvitation;
2453
+ });
2454
+ this._persistentInvitationsLoadedEvent.emit();
2455
+ this._persistentInvitationsLoaded = true;
2456
+ return {
2457
+ invitations: cInvitations
2458
+ };
2459
+ }
2385
2460
  acceptInvitation({ invitation: options, deviceProfile }) {
2386
2461
  let invitation;
2387
2462
  if (deviceProfile) {
2388
2463
  (0, import_invariant7.invariant)(options.kind === import_services5.Invitation.Kind.DEVICE, "deviceProfile provided for non-device invitation", {
2389
2464
  F: __dxlog_file8,
2390
- L: 81,
2465
+ L: 127,
2391
2466
  S: this,
2392
2467
  A: [
2393
2468
  "options.kind === Invitation.Kind.DEVICE",
@@ -2421,13 +2496,13 @@ var InvitationsServiceImpl = class {
2421
2496
  async authenticate({ invitationId, authCode }) {
2422
2497
  (0, import_log6.log)("authenticating...", void 0, {
2423
2498
  F: __dxlog_file8,
2424
- L: 114,
2499
+ L: 160,
2425
2500
  S: this,
2426
2501
  C: (f, a) => f(...a)
2427
2502
  });
2428
2503
  (0, import_invariant7.invariant)(invitationId, void 0, {
2429
2504
  F: __dxlog_file8,
2430
- L: 115,
2505
+ L: 161,
2431
2506
  S: this,
2432
2507
  A: [
2433
2508
  "invitationId",
@@ -2440,7 +2515,7 @@ var InvitationsServiceImpl = class {
2440
2515
  invitationId
2441
2516
  }, {
2442
2517
  F: __dxlog_file8,
2443
- L: 118,
2518
+ L: 164,
2444
2519
  S: this,
2445
2520
  C: (f, a) => f(...a)
2446
2521
  });
@@ -2449,15 +2524,17 @@ var InvitationsServiceImpl = class {
2449
2524
  }
2450
2525
  }
2451
2526
  async cancelInvitation({ invitationId }) {
2452
- (0, import_log6.log)("deleting...", void 0, {
2527
+ (0, import_log6.log)("cancelInvitation...", {
2528
+ invitationId
2529
+ }, {
2453
2530
  F: __dxlog_file8,
2454
- L: 125,
2531
+ L: 171,
2455
2532
  S: this,
2456
2533
  C: (f, a) => f(...a)
2457
2534
  });
2458
2535
  (0, import_invariant7.invariant)(invitationId, void 0, {
2459
2536
  F: __dxlog_file8,
2460
- L: 126,
2537
+ L: 172,
2461
2538
  S: this,
2462
2539
  A: [
2463
2540
  "invitationId",
@@ -2470,6 +2547,9 @@ var InvitationsServiceImpl = class {
2470
2547
  await created.cancel();
2471
2548
  this._createInvitations.delete(invitationId);
2472
2549
  this._removedCreated.emit(created.get());
2550
+ if (created.get().persistent) {
2551
+ await this._metadataStore.removeInvitation(created.get().invitationId);
2552
+ }
2473
2553
  } else if (accepted) {
2474
2554
  await accepted.cancel();
2475
2555
  this._acceptInvitations.delete(invitationId);
@@ -2514,16 +2594,40 @@ var InvitationsServiceImpl = class {
2514
2594
  ]
2515
2595
  });
2516
2596
  });
2597
+ this._saved.on(ctx, (invitation) => {
2598
+ next({
2599
+ action: import_services5.QueryInvitationsResponse.Action.SAVED,
2600
+ type: import_services5.QueryInvitationsResponse.Type.CREATED,
2601
+ invitations: [
2602
+ invitation
2603
+ ]
2604
+ });
2605
+ });
2517
2606
  next({
2518
2607
  action: import_services5.QueryInvitationsResponse.Action.ADDED,
2519
2608
  type: import_services5.QueryInvitationsResponse.Type.CREATED,
2520
- invitations: Array.from(this._createInvitations.values()).map((invitation) => invitation.get())
2609
+ invitations: Array.from(this._createInvitations.values()).map((invitation) => invitation.get()),
2610
+ existing: true
2521
2611
  });
2522
2612
  next({
2523
2613
  action: import_services5.QueryInvitationsResponse.Action.ADDED,
2524
2614
  type: import_services5.QueryInvitationsResponse.Type.ACCEPTED,
2525
- invitations: Array.from(this._acceptInvitations.values()).map((invitation) => invitation.get())
2615
+ invitations: Array.from(this._acceptInvitations.values()).map((invitation) => invitation.get()),
2616
+ existing: true
2526
2617
  });
2618
+ if (this._persistentInvitationsLoaded) {
2619
+ next({
2620
+ action: import_services5.QueryInvitationsResponse.Action.LOAD_COMPLETE,
2621
+ type: import_services5.QueryInvitationsResponse.Type.CREATED
2622
+ });
2623
+ } else {
2624
+ this._persistentInvitationsLoadedEvent.on(ctx, () => {
2625
+ next({
2626
+ action: import_services5.QueryInvitationsResponse.Action.LOAD_COMPLETE,
2627
+ type: import_services5.QueryInvitationsResponse.Type.CREATED
2628
+ });
2629
+ });
2630
+ }
2527
2631
  });
2528
2632
  }
2529
2633
  };
@@ -2784,7 +2888,7 @@ var getPlatform = () => {
2784
2888
  };
2785
2889
  }
2786
2890
  };
2787
- var DXOS_VERSION = "0.4.7";
2891
+ var DXOS_VERSION = "0.4.8-main.0602afb";
2788
2892
  var __dxlog_file10 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/services/diagnostics.ts";
2789
2893
  var DEFAULT_TIMEOUT = 1e3;
2790
2894
  var createDiagnostics = async (clientServices, serviceContext, config) => {
@@ -2927,6 +3031,7 @@ var AutomergeSpaceState = class {
2927
3031
  this._onNewRoot = _onNewRoot;
2928
3032
  this.rootUrl = void 0;
2929
3033
  this.lastEpoch = void 0;
3034
+ this._isProcessingRootDocs = false;
2930
3035
  }
2931
3036
  async processCredential(credential) {
2932
3037
  if (!(0, import_credentials11.checkCredentialType)(credential, "dxos.halo.credentials.Epoch")) {
@@ -2935,8 +3040,19 @@ var AutomergeSpaceState = class {
2935
3040
  this.lastEpoch = credential;
2936
3041
  if (credential.subject.assertion.automergeRoot) {
2937
3042
  this.rootUrl = credential.subject.assertion.automergeRoot;
3043
+ if (this._isProcessingRootDocs) {
3044
+ this._onNewRoot(this.rootUrl);
3045
+ }
3046
+ }
3047
+ }
3048
+ startProcessingRootDocs() {
3049
+ if (this._isProcessingRootDocs) {
3050
+ return;
3051
+ }
3052
+ if (this.rootUrl) {
2938
3053
  this._onNewRoot(this.rootUrl);
2939
3054
  }
3055
+ this._isProcessingRootDocs = true;
2940
3056
  }
2941
3057
  };
2942
3058
  var __dxlog_file11 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/src/packlets/spaces/notarization-plugin.ts";
@@ -2946,7 +3062,7 @@ var DEFAULT_NOTARIZE_TIMEOUT = 1e4;
2946
3062
  var WRITER_NOT_SET_ERROR_CODE = "WRITER_NOT_SET";
2947
3063
  var NotarizationPlugin = class {
2948
3064
  constructor() {
2949
- this._ctx = new import_context7.Context();
3065
+ this._ctx = new import_context8.Context();
2950
3066
  this._extensionOpened = new import_async11.Event();
2951
3067
  this._extensions = /* @__PURE__ */ new Set();
2952
3068
  this._processedCredentials = new import_util5.ComplexSet(import_keys8.PublicKey.hash);
@@ -3071,7 +3187,7 @@ var NotarizationPlugin = class {
3071
3187
  this._extensionOpened.on(ctx, () => notarizeTask.schedule());
3072
3188
  try {
3073
3189
  await Promise.race([
3074
- (0, import_context7.rejectOnDispose)(ctx),
3190
+ (0, import_context8.rejectOnDispose)(ctx),
3075
3191
  allNotarized,
3076
3192
  errors.wait()
3077
3193
  ]);
@@ -3211,7 +3327,7 @@ var __dxlog_file12 = "/home/runner/work/dxos/dxos/packages/sdk/client-services/s
3211
3327
  var ENABLE_FEED_PURGE = false;
3212
3328
  var DataSpace = class {
3213
3329
  constructor(params) {
3214
- this._ctx = new import_context6.Context();
3330
+ this._ctx = new import_context7.Context();
3215
3331
  this._notarizationPlugin = new NotarizationPlugin();
3216
3332
  this._cache = void 0;
3217
3333
  this._automergeSpaceState = new AutomergeSpaceState((rootUrl) => this._onNewAutomergeRoot(rootUrl));
@@ -3287,7 +3403,7 @@ var DataSpace = class {
3287
3403
  await this._notarizationPlugin.open();
3288
3404
  await this._inner.spaceState.addCredentialProcessor(this._notarizationPlugin);
3289
3405
  await this._inner.spaceState.addCredentialProcessor(this._automergeSpaceState);
3290
- await this._inner.open(new import_context6.Context());
3406
+ await this._inner.open(new import_context7.Context());
3291
3407
  this._state = import_services9.SpaceState.CONTROL_ONLY;
3292
3408
  (0, import_log9.log)("new state", {
3293
3409
  state: import_services9.SpaceState[this._state]
@@ -3316,7 +3432,7 @@ var DataSpace = class {
3316
3432
  C: (f, a) => f(...a)
3317
3433
  });
3318
3434
  await this._ctx.dispose();
3319
- this._ctx = new import_context6.Context();
3435
+ this._ctx = new import_context7.Context();
3320
3436
  await this.authVerifier.close();
3321
3437
  await this._inner.close();
3322
3438
  await this._inner.spaceState.removeCredentialProcessor(this._automergeSpaceState);
@@ -3340,7 +3456,7 @@ var DataSpace = class {
3340
3456
  this.metrics.pipelineInitBegin = /* @__PURE__ */ new Date();
3341
3457
  await this.initializeDataPipeline();
3342
3458
  } catch (err) {
3343
- if (err instanceof import_protocols8.CancelledError || err instanceof import_context6.ContextDisposedError) {
3459
+ if (err instanceof import_protocols8.CancelledError || err instanceof import_context7.ContextDisposedError) {
3344
3460
  (0, import_log9.log)("data pipeline initialization cancelled", err, {
3345
3461
  F: __dxlog_file12,
3346
3462
  L: 250,
@@ -3386,12 +3502,13 @@ var DataSpace = class {
3386
3502
  });
3387
3503
  await this._initializeAndReadControlPipeline();
3388
3504
  await (0, import_async10.sleep)(1);
3505
+ this._automergeSpaceState.startProcessingRootDocs();
3389
3506
  await this._inner.initializeDataPipeline();
3390
3507
  this.metrics.dataPipelineOpen = /* @__PURE__ */ new Date();
3391
- await (0, import_context6.cancelWithContext)(this._ctx, this._inner.dataPipeline.ensureEpochInitialized());
3508
+ await (0, import_context7.cancelWithContext)(this._ctx, this._inner.dataPipeline.ensureEpochInitialized());
3392
3509
  (0, import_log9.log)("waiting for data pipeline to reach target timeframe", void 0, {
3393
3510
  F: __dxlog_file12,
3394
- L: 286,
3511
+ L: 288,
3395
3512
  S: this,
3396
3513
  C: (f, a) => f(...a)
3397
3514
  });
@@ -3402,7 +3519,7 @@ var DataSpace = class {
3402
3519
  this.metrics.dataPipelineReady = /* @__PURE__ */ new Date();
3403
3520
  (0, import_log9.log)("data pipeline ready", void 0, {
3404
3521
  F: __dxlog_file12,
3405
- L: 294,
3522
+ L: 296,
3406
3523
  S: this,
3407
3524
  C: (f, a) => f(...a)
3408
3525
  });
@@ -3412,7 +3529,7 @@ var DataSpace = class {
3412
3529
  state: import_services9.SpaceState[this._state]
3413
3530
  }, {
3414
3531
  F: __dxlog_file12,
3415
- L: 298,
3532
+ L: 300,
3416
3533
  S: this,
3417
3534
  C: (f, a) => f(...a)
3418
3535
  });
@@ -3428,7 +3545,7 @@ var DataSpace = class {
3428
3545
  await this._createWritableFeeds();
3429
3546
  (0, import_log9.log)("writable feeds created", void 0, {
3430
3547
  F: __dxlog_file12,
3431
- L: 314,
3548
+ L: 316,
3432
3549
  S: this,
3433
3550
  C: (f, a) => f(...a)
3434
3551
  });
@@ -3491,7 +3608,7 @@ var DataSpace = class {
3491
3608
  rootUrl
3492
3609
  }, {
3493
3610
  F: __dxlog_file12,
3494
- L: 380,
3611
+ L: 382,
3495
3612
  S: this,
3496
3613
  C: (f, a) => f(...a)
3497
3614
  });
@@ -3500,7 +3617,7 @@ var DataSpace = class {
3500
3617
  queueMicrotask(async () => {
3501
3618
  try {
3502
3619
  await (0, import_debug3.warnAfterTimeout)(5e3, "Automerge root doc load timeout (DataSpace)", async () => {
3503
- await (0, import_context6.cancelWithContext)(this._ctx, handle.whenReady());
3620
+ await (0, import_context7.cancelWithContext)(this._ctx, handle.whenReady());
3504
3621
  });
3505
3622
  if (this._ctx.disposed) {
3506
3623
  return;
@@ -3514,7 +3631,7 @@ var DataSpace = class {
3514
3631
  });
3515
3632
  }
3516
3633
  } catch (err) {
3517
- if (err instanceof import_context6.ContextDisposedError) {
3634
+ if (err instanceof import_context7.ContextDisposedError) {
3518
3635
  return;
3519
3636
  }
3520
3637
  import_log9.log.warn("error loading automerge root doc", {
@@ -3523,7 +3640,7 @@ var DataSpace = class {
3523
3640
  err
3524
3641
  }, {
3525
3642
  F: __dxlog_file12,
3526
- L: 403,
3643
+ L: 405,
3527
3644
  S: this,
3528
3645
  C: (f, a) => f(...a)
3529
3646
  });
@@ -3554,15 +3671,40 @@ var DataSpace = class {
3554
3671
  epoch = await this.dataPipeline.createEpoch();
3555
3672
  }
3556
3673
  break;
3557
- case import_services9.CreateEpochRequest.Migration.INIT_AUTOMERGE: {
3558
- const document = this._automergeHost.repo.create();
3559
- epoch = {
3560
- previousId: this._automergeSpaceState.lastEpoch?.id,
3561
- number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
3562
- timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new import_timeframe2.Timeframe(),
3563
- automergeRoot: document.url
3564
- };
3565
- }
3674
+ case import_services9.CreateEpochRequest.Migration.INIT_AUTOMERGE:
3675
+ {
3676
+ const document = this._automergeHost.repo.create();
3677
+ epoch = {
3678
+ previousId: this._automergeSpaceState.lastEpoch?.id,
3679
+ number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
3680
+ timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new import_timeframe2.Timeframe(),
3681
+ automergeRoot: document.url
3682
+ };
3683
+ }
3684
+ break;
3685
+ case import_services9.CreateEpochRequest.Migration.PRUNE_AUTOMERGE_ROOT_HISTORY:
3686
+ {
3687
+ const currentRootUrl = this._automergeSpaceState.rootUrl;
3688
+ const rootHandle = this._automergeHost.repo.find(currentRootUrl);
3689
+ await (0, import_context7.cancelWithContext)(this._ctx, (0, import_async10.asyncTimeout)(rootHandle.whenReady(), 1e4));
3690
+ const newRoot = this._automergeHost.repo.create(rootHandle.docSync());
3691
+ (0, import_invariant10.invariant)(typeof newRoot.url === "string" && newRoot.url.length > 0, void 0, {
3692
+ F: __dxlog_file12,
3693
+ L: 450,
3694
+ S: this,
3695
+ A: [
3696
+ "typeof newRoot.url === 'string' && newRoot.url.length > 0",
3697
+ ""
3698
+ ]
3699
+ });
3700
+ epoch = {
3701
+ previousId: this._automergeSpaceState.lastEpoch?.id,
3702
+ number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
3703
+ timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new import_timeframe2.Timeframe(),
3704
+ automergeRoot: newRoot.url
3705
+ };
3706
+ }
3707
+ break;
3566
3708
  }
3567
3709
  if (!epoch) {
3568
3710
  return;
@@ -3613,7 +3755,7 @@ var DataSpace = class {
3613
3755
  state: import_services9.SpaceState[this._state]
3614
3756
  }, {
3615
3757
  F: __dxlog_file12,
3616
- L: 492,
3758
+ L: 514,
3617
3759
  S: this,
3618
3760
  C: (f, a) => f(...a)
3619
3761
  });
@@ -3751,7 +3893,7 @@ var DataSpaceManager = class {
3751
3893
  this._signingContext = _signingContext;
3752
3894
  this._feedStore = _feedStore;
3753
3895
  this._automergeHost = _automergeHost;
3754
- this._ctx = new import_context8.Context();
3896
+ this._ctx = new import_context9.Context();
3755
3897
  this.updated = new import_async12.Event();
3756
3898
  this._spaces = new import_util6.ComplexMap(import_keys9.PublicKey.hash);
3757
3899
  this._isOpen = false;
@@ -3940,7 +4082,7 @@ var DataSpaceManager = class {
3940
4082
  * TODO(dmaretskyi): Consider removing.
3941
4083
  */
3942
4084
  async waitUntilSpaceReady(spaceKey) {
3943
- await (0, import_context8.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
4085
+ await (0, import_context9.cancelWithContext)(this._ctx, this.updated.waitForCondition(() => {
3944
4086
  const space = this._spaces.get(spaceKey);
3945
4087
  return !!space && space.state === import_services10.SpaceState.READY;
3946
4088
  }));
@@ -4240,10 +4382,12 @@ var SpacesServiceImpl = class {
4240
4382
  }
4241
4383
  }
4242
4384
  }
4243
- async createEpoch({ spaceKey }) {
4385
+ async createEpoch({ spaceKey, migration }) {
4244
4386
  const dataSpaceManager = await this._getDataSpaceManager();
4245
4387
  const space = dataSpaceManager.spaces.get(spaceKey) ?? (0, import_debug5.raise)(new import_protocols11.SpaceNotFoundError(spaceKey));
4246
- await space.createEpoch();
4388
+ await space.createEpoch({
4389
+ migration
4390
+ });
4247
4391
  }
4248
4392
  _serializeSpace(space) {
4249
4393
  return {
@@ -4308,9 +4452,6 @@ var ServiceContext = class {
4308
4452
  this._handlerFactories = /* @__PURE__ */ new Map();
4309
4453
  this._instanceId = import_keys10.PublicKey.random().toHex();
4310
4454
  this.metadataStore = new import_echo_pipeline2.MetadataStore(storage.createDirectory("metadata"));
4311
- this.indexMetadata = new import_echo_schema.IndexMetadataStore({
4312
- directory: storage.createDirectory("index-metadata")
4313
- });
4314
4455
  this.snapshotStore = new import_echo_pipeline2.SnapshotStore(storage.createDirectory("snapshots"));
4315
4456
  this.blobStore = new import_teleport_extension_object_sync.BlobStore(storage.createDirectory("blobs"));
4316
4457
  this.keyring = new import_keyring.Keyring(storage.createDirectory("keyring"));
@@ -4333,10 +4474,34 @@ var ServiceContext = class {
4333
4474
  snapshotStore: this.snapshotStore
4334
4475
  });
4335
4476
  this.identityManager = new IdentityManager(this.metadataStore, this.keyring, this.feedStore, this.spaceManager, this._runtimeParams);
4477
+ this.indexMetadata = new import_indexing.IndexMetadataStore({
4478
+ directory: storage.createDirectory("index-metadata")
4479
+ });
4336
4480
  this.automergeHost = new import_echo_pipeline2.AutomergeHost({
4337
4481
  directory: storage.createDirectory("automerge"),
4338
4482
  metadata: this.indexMetadata
4339
4483
  });
4484
+ this.indexer = new import_indexing.Indexer({
4485
+ indexStore: new import_indexing.IndexStore({
4486
+ directory: storage.createDirectory("index-store")
4487
+ }),
4488
+ metadataStore: this.indexMetadata,
4489
+ loadDocuments: async (ids) => {
4490
+ const snapshots = await Promise.all(ids.map(async (id) => {
4491
+ const { documentId, objectId } = import_protocols12.idCodec.decode(id);
4492
+ const handle = this.automergeHost.repo.find(documentId);
4493
+ await (0, import_debug6.warnAfterTimeout)(1e3, "to long to load doc", () => handle.whenReady());
4494
+ const doc = handle.docSync();
4495
+ const heads = (0, import_automerge.getHeads)(doc);
4496
+ return {
4497
+ id,
4498
+ object: doc.objects[objectId],
4499
+ currentHash: heads.at(-1)
4500
+ };
4501
+ }));
4502
+ return snapshots.filter((snapshot) => snapshot.object);
4503
+ }
4504
+ });
4340
4505
  this.invitations = new InvitationsHandler(this.networkManager);
4341
4506
  this._handlerFactories.set(import_services12.Invitation.Kind.DEVICE, () => new DeviceInvitationProtocol(this.keyring, () => this.identityManager.identity ?? (0, import_debug6.failUndefined)(), this._acceptIdentity.bind(this)));
4342
4507
  }
@@ -4344,7 +4509,7 @@ var ServiceContext = class {
4344
4509
  await this._checkStorageVersion();
4345
4510
  (0, import_log13.log)("opening...", void 0, {
4346
4511
  F: __dxlog_file15,
4347
- L: 152,
4512
+ L: 173,
4348
4513
  S: this,
4349
4514
  C: (f, a) => f(...a)
4350
4515
  });
@@ -4352,7 +4517,7 @@ var ServiceContext = class {
4352
4517
  id: this._instanceId
4353
4518
  }), {
4354
4519
  F: __dxlog_file15,
4355
- L: 153,
4520
+ L: 174,
4356
4521
  S: this,
4357
4522
  C: (f, a) => f(...a)
4358
4523
  });
@@ -4368,13 +4533,13 @@ var ServiceContext = class {
4368
4533
  id: this._instanceId
4369
4534
  }), {
4370
4535
  F: __dxlog_file15,
4371
- L: 163,
4536
+ L: 184,
4372
4537
  S: this,
4373
4538
  C: (f, a) => f(...a)
4374
4539
  });
4375
4540
  (0, import_log13.log)("opened", void 0, {
4376
4541
  F: __dxlog_file15,
4377
- L: 164,
4542
+ L: 185,
4378
4543
  S: this,
4379
4544
  C: (f, a) => f(...a)
4380
4545
  });
@@ -4382,7 +4547,7 @@ var ServiceContext = class {
4382
4547
  async close() {
4383
4548
  (0, import_log13.log)("closing...", void 0, {
4384
4549
  F: __dxlog_file15,
4385
- L: 168,
4550
+ L: 189,
4386
4551
  S: this,
4387
4552
  C: (f, a) => f(...a)
4388
4553
  });
@@ -4398,23 +4563,24 @@ var ServiceContext = class {
4398
4563
  await this.signalManager.close();
4399
4564
  this.dataServiceSubscriptions.clear();
4400
4565
  await this.metadataStore.close();
4566
+ await this.indexer.destroy();
4401
4567
  (0, import_log13.log)("closed", void 0, {
4402
4568
  F: __dxlog_file15,
4403
- L: 181,
4569
+ L: 203,
4404
4570
  S: this,
4405
4571
  C: (f, a) => f(...a)
4406
4572
  });
4407
4573
  }
4408
4574
  async createIdentity(params = {}) {
4409
4575
  const identity = await this.identityManager.createIdentity(params);
4410
- await this._initialize(new import_context9.Context());
4576
+ await this._initialize(new import_context10.Context());
4411
4577
  return identity;
4412
4578
  }
4413
4579
  getInvitationHandler(invitation) {
4414
4580
  const factory = this._handlerFactories.get(invitation.kind);
4415
4581
  (0, import_invariant14.invariant)(factory, `Unknown invitation kind: ${invitation.kind}`, {
4416
4582
  F: __dxlog_file15,
4417
- L: 192,
4583
+ L: 214,
4418
4584
  S: this,
4419
4585
  A: [
4420
4586
  "factory",
@@ -4433,7 +4599,7 @@ var ServiceContext = class {
4433
4599
  }
4434
4600
  async _acceptIdentity(params) {
4435
4601
  const identity = await this.identityManager.acceptIdentity(params);
4436
- await this._initialize(new import_context9.Context());
4602
+ await this._initialize(new import_context10.Context());
4437
4603
  return identity;
4438
4604
  }
4439
4605
  async _checkStorageVersion() {
@@ -4446,7 +4612,7 @@ var ServiceContext = class {
4446
4612
  async _initialize(ctx) {
4447
4613
  (0, import_log13.log)("initializing spaces...", void 0, {
4448
4614
  F: __dxlog_file15,
4449
- L: 223,
4615
+ L: 245,
4450
4616
  S: this,
4451
4617
  C: (f, a) => f(...a)
4452
4618
  });
@@ -4469,7 +4635,7 @@ var ServiceContext = class {
4469
4635
  this._handlerFactories.set(import_services12.Invitation.Kind.SPACE, (invitation) => {
4470
4636
  (0, import_invariant14.invariant)(this.dataSpaceManager, "dataSpaceManager not initialized yet", {
4471
4637
  F: __dxlog_file15,
4472
- L: 248,
4638
+ L: 270,
4473
4639
  S: this,
4474
4640
  A: [
4475
4641
  "this.dataSpaceManager",
@@ -4493,7 +4659,7 @@ var ServiceContext = class {
4493
4659
  details: assertion
4494
4660
  }, {
4495
4661
  F: __dxlog_file15,
4496
- L: 264,
4662
+ L: 286,
4497
4663
  S: this,
4498
4664
  C: (f, a) => f(...a)
4499
4665
  });
@@ -4504,7 +4670,7 @@ var ServiceContext = class {
4504
4670
  details: assertion
4505
4671
  }, {
4506
4672
  F: __dxlog_file15,
4507
- L: 268,
4673
+ L: 290,
4508
4674
  S: this,
4509
4675
  C: (f, a) => f(...a)
4510
4676
  });
@@ -4515,7 +4681,7 @@ var ServiceContext = class {
4515
4681
  details: assertion
4516
4682
  }, {
4517
4683
  F: __dxlog_file15,
4518
- L: 273,
4684
+ L: 295,
4519
4685
  S: this,
4520
4686
  C: (f, a) => f(...a)
4521
4687
  });
@@ -4526,7 +4692,7 @@ var ServiceContext = class {
4526
4692
  } catch (err) {
4527
4693
  import_log13.log.catch(err, void 0, {
4528
4694
  F: __dxlog_file15,
4529
- L: 279,
4695
+ L: 301,
4530
4696
  S: this,
4531
4697
  C: (f, a) => f(...a)
4532
4698
  });
@@ -4984,7 +5150,7 @@ var ClientServicesHost = class {
4984
5150
  lockKey,
4985
5151
  onAcquire: () => {
4986
5152
  if (!this._opening) {
4987
- void this.open(new import_context10.Context());
5153
+ void this.open(new import_context11.Context());
4988
5154
  }
4989
5155
  },
4990
5156
  onRelease: () => this.close()
@@ -5040,7 +5206,7 @@ var ClientServicesHost = class {
5040
5206
  initialize({ config, ...options }) {
5041
5207
  (0, import_invariant16.invariant)(!this._open, "service host is open", {
5042
5208
  F: __dxlog_file18,
5043
- L: 190,
5209
+ L: 191,
5044
5210
  S: this,
5045
5211
  A: [
5046
5212
  "!this._open",
@@ -5049,14 +5215,14 @@ var ClientServicesHost = class {
5049
5215
  });
5050
5216
  (0, import_log15.log)("initializing...", void 0, {
5051
5217
  F: __dxlog_file18,
5052
- L: 191,
5218
+ L: 192,
5053
5219
  S: this,
5054
5220
  C: (f, a) => f(...a)
5055
5221
  });
5056
5222
  if (config) {
5057
5223
  (0, import_invariant16.invariant)(!this._config, "config already set", {
5058
5224
  F: __dxlog_file18,
5059
- L: 194,
5225
+ L: 195,
5060
5226
  S: this,
5061
5227
  A: [
5062
5228
  "!this._config",
@@ -5074,7 +5240,7 @@ var ClientServicesHost = class {
5074
5240
  this._signalManager = signalManager;
5075
5241
  (0, import_invariant16.invariant)(!this._networkManager, "network manager already set", {
5076
5242
  F: __dxlog_file18,
5077
- L: 210,
5243
+ L: 211,
5078
5244
  S: this,
5079
5245
  A: [
5080
5246
  "!this._networkManager",
@@ -5088,7 +5254,7 @@ var ClientServicesHost = class {
5088
5254
  });
5089
5255
  (0, import_log15.log)("initialized", void 0, {
5090
5256
  F: __dxlog_file18,
5091
- L: 217,
5257
+ L: 218,
5092
5258
  S: this,
5093
5259
  C: (f, a) => f(...a)
5094
5260
  });
@@ -5102,13 +5268,13 @@ var ClientServicesHost = class {
5102
5268
  id: traceId
5103
5269
  }), {
5104
5270
  F: __dxlog_file18,
5105
- L: 228,
5271
+ L: 229,
5106
5272
  S: this,
5107
5273
  C: (f, a) => f(...a)
5108
5274
  });
5109
5275
  (0, import_invariant16.invariant)(this._config, "config not set", {
5110
5276
  F: __dxlog_file18,
5111
- L: 230,
5277
+ L: 231,
5112
5278
  S: this,
5113
5279
  A: [
5114
5280
  "this._config",
@@ -5117,7 +5283,7 @@ var ClientServicesHost = class {
5117
5283
  });
5118
5284
  (0, import_invariant16.invariant)(this._storage, "storage not set", {
5119
5285
  F: __dxlog_file18,
5120
- L: 231,
5286
+ L: 232,
5121
5287
  S: this,
5122
5288
  A: [
5123
5289
  "this._storage",
@@ -5126,7 +5292,7 @@ var ClientServicesHost = class {
5126
5292
  });
5127
5293
  (0, import_invariant16.invariant)(this._signalManager, "signal manager not set", {
5128
5294
  F: __dxlog_file18,
5129
- L: 232,
5295
+ L: 233,
5130
5296
  S: this,
5131
5297
  A: [
5132
5298
  "this._signalManager",
@@ -5135,7 +5301,7 @@ var ClientServicesHost = class {
5135
5301
  });
5136
5302
  (0, import_invariant16.invariant)(this._networkManager, "network manager not set", {
5137
5303
  F: __dxlog_file18,
5138
- L: 233,
5304
+ L: 234,
5139
5305
  S: this,
5140
5306
  A: [
5141
5307
  "this._networkManager",
@@ -5147,7 +5313,7 @@ var ClientServicesHost = class {
5147
5313
  lockKey: this._resourceLock?.lockKey
5148
5314
  }, {
5149
5315
  F: __dxlog_file18,
5150
- L: 236,
5316
+ L: 237,
5151
5317
  S: this,
5152
5318
  C: (f, a) => f(...a)
5153
5319
  });
@@ -5157,13 +5323,17 @@ var ClientServicesHost = class {
5157
5323
  this._serviceRegistry.setServices({
5158
5324
  SystemService: this._systemService,
5159
5325
  IdentityService: new IdentityServiceImpl((params) => this._createIdentity(params), this._serviceContext.identityManager, this._serviceContext.keyring, (profile) => this._serviceContext.broadcastProfileUpdate(profile)),
5160
- InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitations, (invitation) => this._serviceContext.getInvitationHandler(invitation)),
5326
+ InvitationsService: new InvitationsServiceImpl(this._serviceContext.invitations, (invitation) => this._serviceContext.getInvitationHandler(invitation), this._serviceContext.metadataStore),
5161
5327
  DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
5162
5328
  SpacesService: new SpacesServiceImpl(this._serviceContext.identityManager, this._serviceContext.spaceManager, this._serviceContext.dataServiceSubscriptions, async () => {
5163
5329
  await this._serviceContext.initialized.wait();
5164
5330
  return this._serviceContext.dataSpaceManager;
5165
5331
  }),
5166
5332
  DataService: new import_echo_pipeline3.DataServiceImpl(this._serviceContext.dataServiceSubscriptions, this._serviceContext.automergeHost),
5333
+ IndexService: new import_indexing2.IndexServiceImpl({
5334
+ indexer: this._serviceContext.indexer,
5335
+ automergeHost: this._serviceContext.automergeHost
5336
+ }),
5167
5337
  NetworkService: new NetworkServiceImpl(this._serviceContext.networkManager, this._serviceContext.signalManager),
5168
5338
  LoggingService: this._loggingService,
5169
5339
  TracingService: this._tracingService,
@@ -5175,6 +5345,24 @@ var ClientServicesHost = class {
5175
5345
  })
5176
5346
  });
5177
5347
  await this._serviceContext.open(ctx);
5348
+ (0, import_invariant16.invariant)(this.serviceRegistry.services.InvitationsService, void 0, {
5349
+ F: __dxlog_file18,
5350
+ L: 303,
5351
+ S: this,
5352
+ A: [
5353
+ "this.serviceRegistry.services.InvitationsService",
5354
+ ""
5355
+ ]
5356
+ });
5357
+ const loadedInvitations = await this.serviceRegistry.services.InvitationsService.loadPersistentInvitations();
5358
+ (0, import_log15.log)("loaded persistent invitations", {
5359
+ count: loadedInvitations.invitations?.length
5360
+ }, {
5361
+ F: __dxlog_file18,
5362
+ L: 306,
5363
+ S: this,
5364
+ C: (f, a) => f(...a)
5365
+ });
5178
5366
  const devtoolsProxy = this._config?.get("runtime.client.devtoolsProxy");
5179
5367
  if (devtoolsProxy) {
5180
5368
  this._devtoolsProxy = new import_websocket_rpc.WebsocketRpcClient({
@@ -5193,7 +5381,7 @@ var ClientServicesHost = class {
5193
5381
  deviceKey
5194
5382
  }, {
5195
5383
  F: __dxlog_file18,
5196
- L: 310,
5384
+ L: 323,
5197
5385
  S: this,
5198
5386
  C: (f, a) => f(...a)
5199
5387
  });
@@ -5201,7 +5389,7 @@ var ClientServicesHost = class {
5201
5389
  id: traceId
5202
5390
  }), {
5203
5391
  F: __dxlog_file18,
5204
- L: 311,
5392
+ L: 324,
5205
5393
  S: this,
5206
5394
  C: (f, a) => f(...a)
5207
5395
  });
@@ -5215,7 +5403,7 @@ var ClientServicesHost = class {
5215
5403
  deviceKey
5216
5404
  }, {
5217
5405
  F: __dxlog_file18,
5218
- L: 322,
5406
+ L: 335,
5219
5407
  S: this,
5220
5408
  C: (f, a) => f(...a)
5221
5409
  });
@@ -5231,7 +5419,7 @@ var ClientServicesHost = class {
5231
5419
  deviceKey
5232
5420
  }, {
5233
5421
  F: __dxlog_file18,
5234
- L: 329,
5422
+ L: 342,
5235
5423
  S: this,
5236
5424
  C: (f, a) => f(...a)
5237
5425
  });
@@ -5242,13 +5430,13 @@ var ClientServicesHost = class {
5242
5430
  id: traceId
5243
5431
  }), {
5244
5432
  F: __dxlog_file18,
5245
- L: 334,
5433
+ L: 347,
5246
5434
  S: this,
5247
5435
  C: (f, a) => f(...a)
5248
5436
  });
5249
5437
  (0, import_log15.log)("resetting...", void 0, {
5250
5438
  F: __dxlog_file18,
5251
- L: 336,
5439
+ L: 349,
5252
5440
  S: this,
5253
5441
  C: (f, a) => f(...a)
5254
5442
  });
@@ -5256,7 +5444,7 @@ var ClientServicesHost = class {
5256
5444
  await this._storage.reset();
5257
5445
  (0, import_log15.log)("reset", void 0, {
5258
5446
  F: __dxlog_file18,
5259
- L: 339,
5447
+ L: 352,
5260
5448
  S: this,
5261
5449
  C: (f, a) => f(...a)
5262
5450
  });
@@ -5264,7 +5452,7 @@ var ClientServicesHost = class {
5264
5452
  id: traceId
5265
5453
  }), {
5266
5454
  F: __dxlog_file18,
5267
- L: 340,
5455
+ L: 353,
5268
5456
  S: this,
5269
5457
  C: (f, a) => f(...a)
5270
5458
  });
@@ -5279,7 +5467,7 @@ var ClientServicesHost = class {
5279
5467
  const automergeIndex = space.automergeSpaceState.rootUrl;
5280
5468
  (0, import_invariant16.invariant)(automergeIndex, void 0, {
5281
5469
  F: __dxlog_file18,
5282
- L: 355,
5470
+ L: 368,
5283
5471
  S: this,
5284
5472
  A: [
5285
5473
  "automergeIndex",
@@ -5291,8 +5479,8 @@ var ClientServicesHost = class {
5291
5479
  document.change((doc) => {
5292
5480
  (0, import_util9.assignDeep)(doc, [
5293
5481
  "objects",
5294
- (0, import_echo_schema2.getAutomergeObjectCore)(obj).id
5295
- ], (0, import_echo_schema2.getRawDoc)(obj).handle.docSync());
5482
+ (0, import_echo_schema.getAutomergeObjectCore)(obj).id
5483
+ ], (0, import_echo_schema.getRawDoc)(obj).handle.docSync());
5296
5484
  });
5297
5485
  return identity;
5298
5486
  }
@@ -5339,6 +5527,7 @@ ClientServicesHost = _ts_decorate8([
5339
5527
  createDiagnostics,
5340
5528
  createStorageObjects,
5341
5529
  getNetworkPeers,
5530
+ invitationExpired,
5342
5531
  isLocked,
5343
5532
  subscribeToFeedBlocks,
5344
5533
  subscribeToFeeds,
@@ -5348,4 +5537,4 @@ ClientServicesHost = _ts_decorate8([
5348
5537
  subscribeToSpaces,
5349
5538
  subscribeToSwarmInfo
5350
5539
  });
5351
- //# sourceMappingURL=chunk-RH65IX2V.cjs.map
5540
+ //# sourceMappingURL=chunk-S4SHWFEU.cjs.map