@dxos/client-services 0.8.4-main.fd6878d → 0.8.4-staging.60fe92afc8

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 (254) hide show
  1. package/LICENSE +102 -5
  2. package/README.md +1 -1
  3. package/dist/lib/browser/{chunk-6C7MTZLC.mjs → chunk-HPR4MJ4W.mjs} +2916 -3802
  4. package/dist/lib/browser/chunk-HPR4MJ4W.mjs.map +7 -0
  5. package/dist/lib/browser/chunk-QCWEHHJW.mjs +24 -0
  6. package/dist/lib/browser/chunk-QCWEHHJW.mjs.map +7 -0
  7. package/dist/lib/browser/chunk-XJRPB3GA.mjs +22 -0
  8. package/dist/lib/browser/chunk-XJRPB3GA.mjs.map +7 -0
  9. package/dist/lib/browser/index.mjs +576 -139
  10. package/dist/lib/browser/index.mjs.map +4 -4
  11. package/dist/lib/browser/meta.json +1 -1
  12. package/dist/lib/browser/packlets/diagnostics/browser-diagnostics-broadcast.mjs +88 -0
  13. package/dist/lib/browser/packlets/diagnostics/browser-diagnostics-broadcast.mjs.map +7 -0
  14. package/dist/lib/browser/packlets/diagnostics/diagnostics-broadcast.mjs +11 -0
  15. package/dist/lib/browser/packlets/diagnostics/diagnostics-broadcast.mjs.map +7 -0
  16. package/dist/lib/browser/packlets/locks/browser.mjs +86 -0
  17. package/dist/lib/browser/packlets/locks/browser.mjs.map +7 -0
  18. package/dist/lib/browser/packlets/locks/node.mjs +48 -0
  19. package/dist/lib/browser/packlets/locks/node.mjs.map +7 -0
  20. package/dist/lib/browser/testing/index.mjs +59 -55
  21. package/dist/lib/browser/testing/index.mjs.map +3 -3
  22. package/dist/lib/node-esm/chunk-2DT3MZRL.mjs +22 -0
  23. package/dist/lib/node-esm/chunk-2DT3MZRL.mjs.map +7 -0
  24. package/dist/lib/node-esm/chunk-2SZHAWBN.mjs +24 -0
  25. package/dist/lib/node-esm/chunk-2SZHAWBN.mjs.map +7 -0
  26. package/dist/lib/node-esm/{chunk-YOHACH7G.mjs → chunk-JW6QHPRJ.mjs} +2859 -3614
  27. package/dist/lib/node-esm/chunk-JW6QHPRJ.mjs.map +7 -0
  28. package/dist/lib/node-esm/index.mjs +576 -139
  29. package/dist/lib/node-esm/index.mjs.map +4 -4
  30. package/dist/lib/node-esm/meta.json +1 -1
  31. package/dist/lib/node-esm/packlets/diagnostics/browser-diagnostics-broadcast.mjs +88 -0
  32. package/dist/lib/node-esm/packlets/diagnostics/browser-diagnostics-broadcast.mjs.map +7 -0
  33. package/dist/lib/node-esm/packlets/diagnostics/diagnostics-broadcast.mjs +11 -0
  34. package/dist/lib/node-esm/packlets/diagnostics/diagnostics-broadcast.mjs.map +7 -0
  35. package/dist/lib/node-esm/packlets/locks/browser.mjs +86 -0
  36. package/dist/lib/node-esm/packlets/locks/browser.mjs.map +7 -0
  37. package/dist/lib/node-esm/packlets/locks/node.mjs +48 -0
  38. package/dist/lib/node-esm/packlets/locks/node.mjs.map +7 -0
  39. package/dist/lib/node-esm/testing/index.mjs +59 -55
  40. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  41. package/dist/types/src/index.d.ts +1 -0
  42. package/dist/types/src/index.d.ts.map +1 -1
  43. package/dist/types/src/packlets/agents/edge-agent-manager.d.ts +3 -2
  44. package/dist/types/src/packlets/agents/edge-agent-manager.d.ts.map +1 -1
  45. package/dist/types/src/packlets/agents/edge-agent-service.d.ts +2 -1
  46. package/dist/types/src/packlets/agents/edge-agent-service.d.ts.map +1 -1
  47. package/dist/types/src/packlets/devices/devices-service.d.ts.map +1 -1
  48. package/dist/types/src/packlets/devtools/devtools.d.ts +7 -3
  49. package/dist/types/src/packlets/devtools/devtools.d.ts.map +1 -1
  50. package/dist/types/src/packlets/devtools/feeds.d.ts +1 -1
  51. package/dist/types/src/packlets/devtools/feeds.d.ts.map +1 -1
  52. package/dist/types/src/packlets/devtools/keys.d.ts +2 -2
  53. package/dist/types/src/packlets/devtools/keys.d.ts.map +1 -1
  54. package/dist/types/src/packlets/devtools/metadata.d.ts.map +1 -1
  55. package/dist/types/src/packlets/devtools/network.d.ts.map +1 -1
  56. package/dist/types/src/packlets/devtools/spaces.d.ts.map +1 -1
  57. package/dist/types/src/packlets/diagnostics/browser-diagnostics-broadcast.d.ts.map +1 -1
  58. package/dist/types/src/packlets/diagnostics/diagnostics-broadcast.d.ts.map +1 -1
  59. package/dist/types/src/packlets/diagnostics/diagnostics-collector.d.ts.map +1 -1
  60. package/dist/types/src/packlets/diagnostics/diagnostics.d.ts +2 -3
  61. package/dist/types/src/packlets/diagnostics/diagnostics.d.ts.map +1 -1
  62. package/dist/types/src/packlets/diagnostics/index.d.ts +1 -1
  63. package/dist/types/src/packlets/diagnostics/index.d.ts.map +1 -1
  64. package/dist/types/src/packlets/identity/authenticator.d.ts +3 -3
  65. package/dist/types/src/packlets/identity/authenticator.d.ts.map +1 -1
  66. package/dist/types/src/packlets/identity/contacts-service.d.ts +1 -1
  67. package/dist/types/src/packlets/identity/contacts-service.d.ts.map +1 -1
  68. package/dist/types/src/packlets/identity/identity-manager.d.ts +10 -10
  69. package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
  70. package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts +14 -9
  71. package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts.map +1 -1
  72. package/dist/types/src/packlets/identity/identity-service.d.ts +7 -11
  73. package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
  74. package/dist/types/src/packlets/identity/identity.d.ts +10 -13
  75. package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
  76. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts +7 -6
  77. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -1
  78. package/dist/types/src/packlets/invitations/edge-invitation-handler.d.ts +1 -1
  79. package/dist/types/src/packlets/invitations/edge-invitation-handler.d.ts.map +1 -1
  80. package/dist/types/src/packlets/invitations/invitation-guest-extenstion.d.ts.map +1 -1
  81. package/dist/types/src/packlets/invitations/invitation-host-extension.d.ts.map +1 -1
  82. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts +7 -4
  83. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts.map +1 -1
  84. package/dist/types/src/packlets/invitations/invitation-state.d.ts.map +1 -1
  85. package/dist/types/src/packlets/invitations/invitation-topology.d.ts.map +1 -1
  86. package/dist/types/src/packlets/invitations/invitations-handler.d.ts +4 -4
  87. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  88. package/dist/types/src/packlets/invitations/invitations-manager.d.ts +5 -5
  89. package/dist/types/src/packlets/invitations/invitations-manager.d.ts.map +1 -1
  90. package/dist/types/src/packlets/invitations/invitations-service.d.ts +3 -3
  91. package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
  92. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +6 -5
  93. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
  94. package/dist/types/src/packlets/invitations/utils.d.ts.map +1 -1
  95. package/dist/types/src/packlets/locks/browser.d.ts.map +1 -1
  96. package/dist/types/src/packlets/locks/index.d.ts +1 -1
  97. package/dist/types/src/packlets/locks/index.d.ts.map +1 -1
  98. package/dist/types/src/packlets/locks/node.d.ts.map +1 -1
  99. package/dist/types/src/packlets/logging/logging-service.d.ts +4 -0
  100. package/dist/types/src/packlets/logging/logging-service.d.ts.map +1 -1
  101. package/dist/types/src/packlets/network/network-service.d.ts +5 -4
  102. package/dist/types/src/packlets/network/network-service.d.ts.map +1 -1
  103. package/dist/types/src/packlets/services/client-rpc-server.d.ts +5 -5
  104. package/dist/types/src/packlets/services/client-rpc-server.d.ts.map +1 -1
  105. package/dist/types/src/packlets/services/feed-syncer.d.ts +75 -0
  106. package/dist/types/src/packlets/services/feed-syncer.d.ts.map +1 -0
  107. package/dist/types/src/packlets/services/feed-syncer.test.d.ts +2 -0
  108. package/dist/types/src/packlets/services/feed-syncer.test.d.ts.map +1 -0
  109. package/dist/types/src/packlets/services/index.d.ts +1 -0
  110. package/dist/types/src/packlets/services/index.d.ts.map +1 -1
  111. package/dist/types/src/packlets/services/platform.d.ts.map +1 -1
  112. package/dist/types/src/packlets/services/service-context.d.ts +22 -19
  113. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  114. package/dist/types/src/packlets/services/service-host.d.ts +20 -13
  115. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  116. package/dist/types/src/packlets/services/service-registry.d.ts.map +1 -1
  117. package/dist/types/src/packlets/services/sqlite-storage.d.ts +27 -0
  118. package/dist/types/src/packlets/services/sqlite-storage.d.ts.map +1 -0
  119. package/dist/types/src/packlets/services/util.d.ts.map +1 -1
  120. package/dist/types/src/packlets/space-export/archive-format.d.ts +9 -0
  121. package/dist/types/src/packlets/space-export/archive-format.d.ts.map +1 -0
  122. package/dist/types/src/packlets/space-export/index.d.ts +4 -1
  123. package/dist/types/src/packlets/space-export/index.d.ts.map +1 -1
  124. package/dist/types/src/packlets/space-export/serialized-space-reader.d.ts +23 -0
  125. package/dist/types/src/packlets/space-export/serialized-space-reader.d.ts.map +1 -0
  126. package/dist/types/src/packlets/space-export/serialized-space-writer.d.ts +36 -0
  127. package/dist/types/src/packlets/space-export/serialized-space-writer.d.ts.map +1 -0
  128. package/dist/types/src/packlets/space-export/space-archive-reader.d.ts +9 -1
  129. package/dist/types/src/packlets/space-export/space-archive-reader.d.ts.map +1 -1
  130. package/dist/types/src/packlets/space-export/space-archive-writer.d.ts +7 -1
  131. package/dist/types/src/packlets/space-export/space-archive-writer.d.ts.map +1 -1
  132. package/dist/types/src/packlets/space-export/space-archive.test.d.ts +2 -0
  133. package/dist/types/src/packlets/space-export/space-archive.test.d.ts.map +1 -0
  134. package/dist/types/src/packlets/spaces/automerge-space-state.d.ts.map +1 -1
  135. package/dist/types/src/packlets/spaces/data-space-manager.d.ts +49 -22
  136. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  137. package/dist/types/src/packlets/spaces/data-space.d.ts +38 -13
  138. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  139. package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts +2 -2
  140. package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts.map +1 -1
  141. package/dist/types/src/packlets/spaces/epoch-migrations.d.ts +1 -1
  142. package/dist/types/src/packlets/spaces/epoch-migrations.d.ts.map +1 -1
  143. package/dist/types/src/packlets/spaces/genesis.d.ts +4 -3
  144. package/dist/types/src/packlets/spaces/genesis.d.ts.map +1 -1
  145. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts +6 -9
  146. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts.map +1 -1
  147. package/dist/types/src/packlets/spaces/spaces-service.d.ts +10 -7
  148. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  149. package/dist/types/src/packlets/storage/index.d.ts +1 -0
  150. package/dist/types/src/packlets/storage/index.d.ts.map +1 -1
  151. package/dist/types/src/packlets/storage/level.d.ts.map +1 -1
  152. package/dist/types/src/packlets/storage/profile-archive-sqlite.d.ts +24 -0
  153. package/dist/types/src/packlets/storage/profile-archive-sqlite.d.ts.map +1 -0
  154. package/dist/types/src/packlets/storage/profile-archive-sqlite.test.d.ts +2 -0
  155. package/dist/types/src/packlets/storage/profile-archive-sqlite.test.d.ts.map +1 -0
  156. package/dist/types/src/packlets/storage/profile-archive.d.ts.map +1 -1
  157. package/dist/types/src/packlets/storage/storage.d.ts.map +1 -1
  158. package/dist/types/src/packlets/storage/util.d.ts.map +1 -1
  159. package/dist/types/src/packlets/system/system-service.d.ts +1 -1
  160. package/dist/types/src/packlets/system/system-service.d.ts.map +1 -1
  161. package/dist/types/src/packlets/testing/credential-utils.d.ts.map +1 -1
  162. package/dist/types/src/packlets/testing/invitation-utils.d.ts +6 -3
  163. package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
  164. package/dist/types/src/packlets/testing/test-builder.d.ts +20 -22
  165. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  166. package/dist/types/src/packlets/worker/worker-runtime.d.ts +41 -4
  167. package/dist/types/src/packlets/worker/worker-runtime.d.ts.map +1 -1
  168. package/dist/types/src/packlets/worker/worker-session.d.ts +2 -4
  169. package/dist/types/src/packlets/worker/worker-session.d.ts.map +1 -1
  170. package/dist/types/src/testing/setup.d.ts.map +1 -1
  171. package/dist/types/src/version.d.ts +1 -1
  172. package/dist/types/src/version.d.ts.map +1 -1
  173. package/dist/types/tsconfig.tsbuildinfo +1 -1
  174. package/package.json +71 -57
  175. package/src/index.ts +1 -0
  176. package/src/packlets/agents/edge-agent-manager.ts +10 -7
  177. package/src/packlets/agents/edge-agent-service.ts +15 -3
  178. package/src/packlets/devices/devices-service.test.ts +0 -1
  179. package/src/packlets/devices/devices-service.ts +1 -1
  180. package/src/packlets/devtools/devtools.ts +28 -7
  181. package/src/packlets/devtools/feeds.ts +1 -1
  182. package/src/packlets/devtools/keys.ts +2 -2
  183. package/src/packlets/devtools/spaces.ts +1 -1
  184. package/src/packlets/diagnostics/diagnostics.ts +1 -2
  185. package/src/packlets/diagnostics/index.ts +1 -1
  186. package/src/packlets/identity/authenticator.ts +3 -3
  187. package/src/packlets/identity/contacts-service.ts +1 -2
  188. package/src/packlets/identity/identity-manager.test.ts +6 -6
  189. package/src/packlets/identity/identity-manager.ts +29 -28
  190. package/src/packlets/identity/identity-recovery-manager.ts +31 -22
  191. package/src/packlets/identity/identity-service.test.ts +6 -27
  192. package/src/packlets/identity/identity-service.ts +17 -83
  193. package/src/packlets/identity/identity.test.ts +7 -7
  194. package/src/packlets/identity/identity.ts +12 -35
  195. package/src/packlets/invitations/device-invitation-protocol.ts +10 -9
  196. package/src/packlets/invitations/edge-invitation-handler.ts +9 -5
  197. package/src/packlets/invitations/invitation-guest-extenstion.ts +6 -4
  198. package/src/packlets/invitations/invitation-host-extension.ts +13 -14
  199. package/src/packlets/invitations/invitation-protocol.ts +7 -4
  200. package/src/packlets/invitations/invitation-state.ts +1 -15
  201. package/src/packlets/invitations/invitations-handler.test.ts +4 -5
  202. package/src/packlets/invitations/invitations-handler.ts +74 -22
  203. package/src/packlets/invitations/invitations-manager.ts +42 -17
  204. package/src/packlets/invitations/invitations-service.ts +9 -9
  205. package/src/packlets/invitations/space-invitation-protocol.test.ts +17 -16
  206. package/src/packlets/invitations/space-invitation-protocol.ts +13 -18
  207. package/src/packlets/locks/index.ts +1 -1
  208. package/src/packlets/logging/logging-service.ts +20 -16
  209. package/src/packlets/network/network-service.test.ts +0 -1
  210. package/src/packlets/network/network-service.ts +10 -8
  211. package/src/packlets/services/client-rpc-server.ts +19 -16
  212. package/src/packlets/services/feed-syncer.test.ts +376 -0
  213. package/src/packlets/services/feed-syncer.ts +536 -0
  214. package/src/packlets/services/index.ts +1 -0
  215. package/src/packlets/services/platform.ts +7 -1
  216. package/src/packlets/services/service-context.test.ts +3 -2
  217. package/src/packlets/services/service-context.ts +218 -80
  218. package/src/packlets/services/service-host.test.ts +8 -10
  219. package/src/packlets/services/service-host.ts +104 -65
  220. package/src/packlets/services/service-registry.test.ts +0 -1
  221. package/src/packlets/services/sqlite-storage.ts +390 -0
  222. package/src/packlets/space-export/archive-format.ts +42 -0
  223. package/src/packlets/space-export/index.ts +4 -1
  224. package/src/packlets/space-export/serialized-space-reader.ts +129 -0
  225. package/src/packlets/space-export/serialized-space-writer.ts +260 -0
  226. package/src/packlets/space-export/space-archive-reader.ts +65 -4
  227. package/src/packlets/space-export/space-archive-writer.ts +43 -5
  228. package/src/packlets/space-export/space-archive.test.ts +482 -0
  229. package/src/packlets/spaces/data-space-manager.test.ts +169 -14
  230. package/src/packlets/spaces/data-space-manager.ts +209 -128
  231. package/src/packlets/spaces/data-space.ts +89 -43
  232. package/src/packlets/spaces/edge-feed-replicator.test.ts +3 -3
  233. package/src/packlets/spaces/edge-feed-replicator.ts +12 -10
  234. package/src/packlets/spaces/epoch-migrations.ts +7 -6
  235. package/src/packlets/spaces/genesis.ts +9 -4
  236. package/src/packlets/spaces/notarization-plugin.test.ts +2 -2
  237. package/src/packlets/spaces/notarization-plugin.ts +10 -9
  238. package/src/packlets/spaces/spaces-service.test.ts +18 -11
  239. package/src/packlets/spaces/spaces-service.ts +131 -25
  240. package/src/packlets/storage/index.ts +1 -0
  241. package/src/packlets/storage/profile-archive-sqlite.test.ts +79 -0
  242. package/src/packlets/storage/profile-archive-sqlite.ts +100 -0
  243. package/src/packlets/storage/profile-archive.ts +3 -0
  244. package/src/packlets/storage/storage.ts +4 -4
  245. package/src/packlets/testing/invitation-utils.ts +10 -6
  246. package/src/packlets/testing/test-builder.ts +59 -40
  247. package/src/packlets/worker/worker-runtime.ts +173 -17
  248. package/src/packlets/worker/worker-session.ts +12 -18
  249. package/src/version.ts +1 -1
  250. package/dist/lib/browser/chunk-6C7MTZLC.mjs.map +0 -7
  251. package/dist/lib/node-esm/chunk-YOHACH7G.mjs.map +0 -7
  252. package/dist/types/src/packlets/identity/default-space-state-machine.d.ts +0 -19
  253. package/dist/types/src/packlets/identity/default-space-state-machine.d.ts.map +0 -1
  254. package/src/packlets/identity/default-space-state-machine.ts +0 -44
@@ -2,62 +2,75 @@
2
2
  // Copyright 2022 DXOS.org
3
3
  //
4
4
 
5
+ import * as SqlClient from '@effect/sql/SqlClient';
6
+ import * as Effect from 'effect/Effect';
7
+
5
8
  import { Mutex, Trigger } from '@dxos/async';
6
9
  import { Context, Resource } from '@dxos/context';
7
10
  import { type CredentialProcessor, getCredentialAssertion } from '@dxos/credentials';
8
11
  import { failUndefined, warnAfterTimeout } from '@dxos/debug';
9
12
  import {
10
13
  EchoEdgeReplicator,
14
+ EchoEdgeSubductionReplicator,
11
15
  EchoHost,
16
+ type EdgeAutomergeReplicator,
12
17
  MeshEchoReplicator,
13
- MetadataStore,
18
+ runSqliteHealthCheck,
19
+ SqliteMetadataStore,
14
20
  SpaceManager,
15
21
  valueEncoding,
16
- } from '@dxos/echo-pipeline';
22
+ } from '@dxos/echo-host';
17
23
  import { createChainEdgeIdentity, createEphemeralEdgeIdentity } from '@dxos/edge-client';
18
24
  import type { EdgeConnection, EdgeHttpClient, EdgeIdentity } from '@dxos/edge-client';
25
+ import { RuntimeProvider } from '@dxos/effect';
19
26
  import { FeedFactory, FeedStore } from '@dxos/feed-store';
20
27
  import { invariant } from '@dxos/invariant';
21
- import { Keyring } from '@dxos/keyring';
22
- import { PublicKey } from '@dxos/keys';
23
- import { type LevelDB } from '@dxos/kv-store';
28
+ import { SqliteKeyring } from '@dxos/keyring';
29
+ import { type SpaceId } from '@dxos/keys';
24
30
  import { log } from '@dxos/log';
25
31
  import { type SignalManager } from '@dxos/messaging';
26
32
  import { type SwarmNetworkManager } from '@dxos/network-manager';
27
- import { InvalidStorageVersionError, STORAGE_VERSION, trace } from '@dxos/protocols';
33
+ import { InvalidStorageVersionError, STORAGE_VERSION } from '@dxos/protocols';
34
+ import { FeedProtocol } from '@dxos/protocols';
28
35
  import { Invitation } from '@dxos/protocols/proto/dxos/client/services';
29
36
  import { type Runtime } from '@dxos/protocols/proto/dxos/config';
30
37
  import type { FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';
31
38
  import { type Credential, type ProfileDocument } from '@dxos/protocols/proto/dxos/halo/credentials';
32
- import { type Storage } from '@dxos/random-access-storage';
33
- import { BlobStore } from '@dxos/teleport-extension-object-sync';
39
+ import { SqlTransaction } from '@dxos/sql-sqlite';
40
+ import { SqliteBlobStore } from '@dxos/teleport-extension-object-sync';
34
41
  import { trace as Trace } from '@dxos/tracing';
35
42
  import { safeInstanceof } from '@dxos/util';
36
43
 
44
+ // SqlTransaction.SqlTransaction is the Tag class exported from the SqlTransaction namespace.
45
+ type SqlTransactionTag = SqlTransaction.SqlTransaction;
46
+
37
47
  import { EdgeAgentManager } from '../agents';
38
48
  import {
39
49
  type CreateIdentityOptions,
50
+ type Identity,
40
51
  IdentityManager,
41
- type IdentityManagerParams,
42
- type JoinIdentityParams,
52
+ type IdentityManagerProps,
53
+ type JoinIdentityProps,
43
54
  } from '../identity';
44
55
  import { EdgeIdentityRecoveryManager } from '../identity/identity-recovery-manager';
45
56
  import {
46
57
  DeviceInvitationProtocol,
47
- type InvitationConnectionParams,
58
+ type InvitationConnectionProps,
48
59
  type InvitationProtocol,
49
60
  InvitationsHandler,
50
61
  InvitationsManager,
51
62
  SpaceInvitationProtocol,
52
63
  } from '../invitations';
53
- import { DataSpaceManager, type DataSpaceManagerRuntimeParams, type SigningContext } from '../spaces';
64
+ import { DataSpaceManager, type DataSpaceManagerRuntimeProps, type SigningContext } from '../spaces';
65
+ import { FeedSyncer } from './feed-syncer';
66
+ import { SqliteStorage } from './sqlite-storage';
54
67
 
55
- export type ServiceContextRuntimeParams = Pick<
56
- IdentityManagerParams,
68
+ export type ServiceContextRuntimeProps = Pick<
69
+ IdentityManagerProps,
57
70
  'devicePresenceOfflineTimeout' | 'devicePresenceAnnounceInterval'
58
71
  > &
59
- DataSpaceManagerRuntimeParams & {
60
- invitationConnectionDefaultParams?: InvitationConnectionParams;
72
+ DataSpaceManagerRuntimeProps & {
73
+ invitationConnectionDefaultProps?: InvitationConnectionProps;
61
74
  disableP2pReplication?: boolean;
62
75
  enableVectorIndexing?: boolean;
63
76
  };
@@ -67,15 +80,15 @@ export type ServiceContextRuntimeParams = Pick<
67
80
  // TODO(burdon): Rename/break-up into smaller components. And/or make members private.
68
81
  // TODO(dmaretskyi): Gets duplicated in CJS build between normal and testing bundles.
69
82
  @safeInstanceof('dxos.client-services.ServiceContext')
70
- @Trace.resource()
83
+ @Trace.resource({ lifecycle: true })
71
84
  export class ServiceContext extends Resource {
72
85
  private readonly _edgeIdentityUpdateMutex = new Mutex();
73
86
 
74
87
  public readonly initialized = new Trigger();
75
- public readonly metadataStore: MetadataStore;
76
- public readonly blobStore: BlobStore;
88
+ public readonly metadataStore: SqliteMetadataStore;
89
+ public readonly blobStore: SqliteBlobStore;
77
90
  public readonly feedStore: FeedStore<FeedMessage>;
78
- public readonly keyring: Keyring;
91
+ public readonly keyring: SqliteKeyring;
79
92
  public readonly spaceManager: SpaceManager;
80
93
  public readonly identityManager: IdentityManager;
81
94
  public readonly recoveryManager: EdgeIdentityRecoveryManager;
@@ -83,7 +96,9 @@ export class ServiceContext extends Resource {
83
96
  public readonly invitationsManager: InvitationsManager;
84
97
  public readonly echoHost: EchoHost;
85
98
  private readonly _meshReplicator?: MeshEchoReplicator = undefined;
86
- private readonly _echoEdgeReplicator?: EchoEdgeReplicator = undefined;
99
+ private readonly _echoEdgeReplicator?: EdgeAutomergeReplicator = undefined;
100
+ private readonly _feedSyncer?: FeedSyncer = undefined;
101
+ private readonly _feedStorage: SqliteStorage;
87
102
 
88
103
  // Initialized after identity is initialized.
89
104
  public dataSpaceManager?: DataSpaceManager;
@@ -96,28 +111,28 @@ export class ServiceContext extends Resource {
96
111
 
97
112
  private _deviceSpaceSync?: CredentialProcessor;
98
113
 
99
- private readonly _instanceId = PublicKey.random().toHex();
100
-
101
114
  constructor(
102
- public readonly storage: Storage,
103
- public readonly level: LevelDB,
104
115
  public readonly networkManager: SwarmNetworkManager,
105
116
  public readonly signalManager: SignalManager,
106
117
  private readonly _edgeConnection: EdgeConnection | undefined,
107
118
  private readonly _edgeHttpClient: EdgeHttpClient | undefined,
108
- public readonly _runtimeParams?: ServiceContextRuntimeParams,
119
+ private readonly _runtime: RuntimeProvider.RuntimeProvider<SqlClient.SqlClient | SqlTransactionTag>,
120
+ public readonly _runtimeProps?: ServiceContextRuntimeProps,
109
121
  private readonly _edgeFeatures?: Runtime.Client.EdgeFeatures,
110
122
  ) {
111
123
  super();
112
124
 
113
- // TODO(burdon): Move strings to constants.
114
- this.metadataStore = new MetadataStore(storage.createDirectory('metadata'));
115
- this.blobStore = new BlobStore(storage.createDirectory('blobs'));
125
+ log('runtimeProps', this._runtimeProps);
126
+ log('edgeFeatures', this._edgeFeatures);
116
127
 
117
- this.keyring = new Keyring(storage.createDirectory('keyring'));
128
+ this.metadataStore = new SqliteMetadataStore({ runtime: this._runtime });
129
+ this.blobStore = new SqliteBlobStore({ runtime: this._runtime });
130
+ this.keyring = new SqliteKeyring({ runtime: this._runtime });
131
+ this._feedStorage = new SqliteStorage({ runtime: this._runtime });
132
+ const feedStorage = this._feedStorage;
118
133
  this.feedStore = new FeedStore<FeedMessage>({
119
134
  factory: new FeedFactory<FeedMessage>({
120
- root: storage.createDirectory('feeds'),
135
+ root: feedStorage.createDirectory('feeds'),
121
136
  signer: this.keyring,
122
137
  hypercore: {
123
138
  valueEncoding,
@@ -131,7 +146,7 @@ export class ServiceContext extends Resource {
131
146
  networkManager: this.networkManager,
132
147
  blobStore: this.blobStore,
133
148
  metadataStore: this.metadataStore,
134
- disableP2pReplication: this._runtimeParams?.disableP2pReplication,
149
+ disableP2pReplication: this._runtimeProps?.disableP2pReplication,
135
150
  });
136
151
 
137
152
  this.identityManager = new IdentityManager({
@@ -139,8 +154,8 @@ export class ServiceContext extends Resource {
139
154
  keyring: this.keyring,
140
155
  feedStore: this.feedStore,
141
156
  spaceManager: this.spaceManager,
142
- devicePresenceOfflineTimeout: this._runtimeParams?.devicePresenceOfflineTimeout,
143
- devicePresenceAnnounceInterval: this._runtimeParams?.devicePresenceAnnounceInterval,
157
+ devicePresenceOfflineTimeout: this._runtimeProps?.devicePresenceOfflineTimeout,
158
+ devicePresenceAnnounceInterval: this._runtimeProps?.devicePresenceAnnounceInterval,
144
159
  edgeConnection: this._edgeConnection,
145
160
  edgeFeatures: this._edgeFeatures,
146
161
  });
@@ -153,20 +168,33 @@ export class ServiceContext extends Resource {
153
168
  );
154
169
 
155
170
  this.echoHost = new EchoHost({
156
- kv: this.level,
157
171
  peerIdProvider: () => this.identityManager.identity?.deviceKey?.toHex(),
158
172
  getSpaceKeyByRootDocumentId: (documentId) => this.spaceManager.findSpaceByRootDocumentId(documentId)?.key,
159
- indexing: {
160
- vector: this._runtimeParams?.enableVectorIndexing,
173
+ runtime: this._runtime,
174
+ useSubduction: this._edgeFeatures?.subductionReplicator,
175
+ syncQueue: async (ctx, request) => {
176
+ return this._feedSyncer?.syncBlocking(ctx, {
177
+ spaceId: request.spaceId as SpaceId,
178
+ subspaceTag: request.subspaceTag,
179
+ shouldPush: request.shouldPush,
180
+ shouldPull: request.shouldPull,
181
+ });
182
+ },
183
+ getSyncState: async (ctx, request) => {
184
+ // Mirror `syncQueue` above: in non-edge / partially-initialised modes the
185
+ // feed syncer is absent. Return an empty state instead of throwing so
186
+ // callers (e.g. devtools sync panel) keep working.
187
+ if (!this._feedSyncer) {
188
+ return { namespaces: [] };
189
+ }
190
+ return this._feedSyncer.getSyncState(ctx, request);
161
191
  },
162
192
  });
163
193
 
164
- this._meshReplicator = new MeshEchoReplicator();
165
-
166
194
  this.invitations = new InvitationsHandler(
167
195
  this.networkManager, //
168
196
  this._edgeHttpClient,
169
- _runtimeParams?.invitationConnectionDefaultParams,
197
+ _runtimeProps?.invitationConnectionDefaultProps,
170
198
  );
171
199
  this.invitationsManager = new InvitationsManager(
172
200
  this.invitations,
@@ -186,80 +214,144 @@ export class ServiceContext extends Resource {
186
214
  ),
187
215
  );
188
216
 
189
- if (!this._runtimeParams?.disableP2pReplication) {
217
+ if (!this._runtimeProps?.disableP2pReplication) {
190
218
  this._meshReplicator = new MeshEchoReplicator();
191
219
  }
192
- if (this._edgeConnection && this._edgeFeatures?.echoReplicator) {
193
- this._echoEdgeReplicator = new EchoEdgeReplicator({
194
- edgeConnection: this._edgeConnection,
220
+ if (this._edgeConnection && this._edgeHttpClient) {
221
+ if (this._edgeFeatures?.subductionReplicator) {
222
+ this._echoEdgeReplicator = new EchoEdgeSubductionReplicator({
223
+ edgeConnection: this._edgeConnection,
224
+ edgeHttpClient: this._edgeHttpClient,
225
+ });
226
+ } else if (this._edgeFeatures?.echoReplicator) {
227
+ this._echoEdgeReplicator = new EchoEdgeReplicator({
228
+ edgeConnection: this._edgeConnection,
229
+ edgeHttpClient: this._edgeHttpClient,
230
+ });
231
+ }
232
+ }
233
+
234
+ if (this.echoHost.feedStore && this._edgeConnection) {
235
+ this._feedSyncer = new FeedSyncer({
236
+ runtime: this._runtime,
237
+ feedStore: this.echoHost.feedStore,
238
+ edgeClient: this._edgeConnection,
239
+ peerId: this.identityManager.identity?.deviceKey?.toHex() ?? '',
240
+ getSpaceIds: () => this.echoHost!.spaceIds,
241
+ syncNamespaces: [FeedProtocol.WellKnownNamespaces.data, FeedProtocol.WellKnownNamespaces.trace],
195
242
  });
196
243
  }
197
244
  }
198
245
 
199
- @Trace.span()
246
+ @Trace.span({ op: 'lifecycle' })
200
247
  protected override async _open(ctx: Context): Promise<void> {
248
+ await RuntimeProvider.runPromise(this._runtime)(
249
+ Effect.all([this.metadataStore.migrate, this.blobStore.migrate, this.keyring.migrate, this._feedStorage.migrate]),
250
+ );
251
+
201
252
  await this._checkStorageVersion();
202
253
 
254
+ log('running sqlite health check...');
255
+ await runSqliteHealthCheck(this._runtime);
256
+ log('sqlite health check passed');
257
+
203
258
  log('opening...');
204
- log.trace('dxos.sdk.service-context.open', trace.begin({ id: this._instanceId }));
205
259
 
260
+ log('opening identityManager...');
206
261
  await this.identityManager.open(ctx);
262
+ log('identityManager opened', { hasIdentity: !!this.identityManager.identity });
263
+
264
+ log('setting network identity...');
265
+ await this._setNetworkIdentity({ identity: this.identityManager.identity });
266
+ log('network identity set');
207
267
 
208
- await this._setNetworkIdentity();
268
+ log('opening edge connection...');
269
+ await this._edgeConnection?.open(ctx);
270
+ log('edge connection opened');
209
271
 
210
- await this._edgeConnection?.open();
211
- await this.signalManager.open();
272
+ log('opening signal manager...');
273
+ await this.signalManager.open(ctx);
274
+ log('signal manager opened');
275
+
276
+ log('opening network manager...');
212
277
  await this.networkManager.open();
278
+ log('network manager opened');
213
279
 
280
+ log('opening echo host...');
214
281
  await this.echoHost.open(ctx);
282
+ log('echo host opened');
215
283
 
216
284
  if (this._meshReplicator) {
217
- await this.echoHost.addReplicator(this._meshReplicator);
285
+ log('adding mesh replicator...');
286
+ await this.echoHost.addReplicator(ctx, this._meshReplicator);
287
+ log('mesh replicator added');
218
288
  }
219
289
  if (this._echoEdgeReplicator) {
220
- await this.echoHost.addReplicator(this._echoEdgeReplicator);
290
+ log('adding edge replicator...');
291
+ await this.echoHost.addReplicator(ctx, this._echoEdgeReplicator);
292
+ log('edge replicator added');
221
293
  }
222
294
 
295
+ log('loading metadata store...');
223
296
  await this.metadataStore.load();
297
+ log('metadata store loaded');
298
+
299
+ log('opening space manager...');
224
300
  await this.spaceManager.open();
301
+ log('space manager opened');
225
302
 
226
303
  if (this.identityManager.identity) {
227
- await this.identityManager.identity.joinNetwork();
304
+ log('joining network...');
305
+ await this.identityManager.identity.joinNetwork(ctx);
306
+ log('network joined');
307
+
308
+ log('initializing spaces...(calling _initialize)');
228
309
  await this._initialize(ctx);
310
+ log('spaces initialized');
311
+ } else {
312
+ log('no identity, skipping network join and space initialization');
229
313
  }
230
314
 
231
- const loadedInvitations = await this.invitationsManager.loadPersistentInvitations();
315
+ log('opening feed syncer...');
316
+ await this._feedSyncer?.open(ctx);
317
+ log('feed syncer opened');
318
+
319
+ log('loading persistent invitations...');
320
+ const loadedInvitations = await this.invitationsManager.loadPersistentInvitations(ctx);
232
321
  log('loaded persistent invitations', { count: loadedInvitations.invitations?.length });
233
322
 
234
- log.trace('dxos.sdk.service-context.open', trace.end({ id: this._instanceId }));
235
323
  log('opened');
236
324
  }
237
325
 
238
326
  protected override async _close(ctx: Context): Promise<void> {
239
327
  log('closing...');
328
+
329
+ await this._feedSyncer?.close();
330
+
240
331
  if (this._deviceSpaceSync && this.identityManager.identity) {
241
332
  await this.identityManager.identity.space.spaceState.removeCredentialProcessor(this._deviceSpaceSync);
242
333
  }
243
- await this.dataSpaceManager?.close();
334
+ await this.dataSpaceManager?.close(ctx);
244
335
  await this.edgeAgentManager?.close();
245
- await this.identityManager.close();
336
+ await this.identityManager.close(ctx);
246
337
  await this.spaceManager.close();
247
- await this.feedStore.close();
248
- await this.metadataStore.close();
249
-
250
338
  await this.echoHost.close(ctx);
251
- await this.networkManager.close();
339
+
340
+ await this.networkManager.close(ctx);
252
341
  await this.signalManager.close();
253
342
  await this._edgeConnection?.close();
343
+ await this.feedStore.close();
344
+ await this.metadataStore.close();
254
345
 
255
346
  log('closed');
256
347
  }
257
348
 
258
- async createIdentity(params: CreateIdentityOptions = {}) {
259
- const identity = await this.identityManager.createIdentity(params);
260
- await this._setNetworkIdentity();
261
- await identity.joinNetwork();
262
- await this._initialize(new Context());
349
+ async createIdentity(params: CreateIdentityOptions = {}, ctx?: Context) {
350
+ ctx ??= this._ctx;
351
+ const identity = await this.identityManager.createIdentity(params, ctx);
352
+ await this._setNetworkIdentity({ identity });
353
+ await identity.joinNetwork(ctx);
354
+ await this._initialize(ctx);
263
355
  return identity;
264
356
  }
265
357
 
@@ -282,12 +374,12 @@ export class ServiceContext extends Resource {
282
374
  }
283
375
  }
284
376
 
285
- private async _acceptIdentity(params: JoinIdentityParams) {
286
- const { identity, identityRecord } = await this.identityManager.prepareIdentity(params);
287
- await this._setNetworkIdentity({ deviceCredential: params.authorizedDeviceCredential! });
288
- await identity.joinNetwork();
377
+ private async _acceptIdentity(params: JoinIdentityProps) {
378
+ const { identity, identityRecord } = await this.identityManager.prepareIdentity(params, this._ctx);
379
+ await this._setNetworkIdentity({ deviceCredential: params.authorizedDeviceCredential!, identity });
380
+ await identity.joinNetwork(this._ctx);
289
381
  await this.identityManager.acceptIdentity(identity, identityRecord, params.deviceProfile);
290
- await this._initialize(new Context());
382
+ await this._initialize(this._ctx);
291
383
  return identity;
292
384
  }
293
385
 
@@ -302,7 +394,7 @@ export class ServiceContext extends Resource {
302
394
  // Called when identity is created.
303
395
  @Trace.span()
304
396
  private async _initialize(ctx: Context): Promise<void> {
305
- log('initializing spaces...');
397
+ log('_initialize: start');
306
398
  const identity = this.identityManager.identity ?? failUndefined();
307
399
  const signingContext: SigningContext = {
308
400
  credentialSigner: identity.getIdentityCredentialSigner(),
@@ -314,6 +406,7 @@ export class ServiceContext extends Resource {
314
406
  },
315
407
  };
316
408
 
409
+ log('_initialize: creating DataSpaceManager');
317
410
  this.dataSpaceManager = new DataSpaceManager({
318
411
  spaceManager: this.spaceManager,
319
412
  metadataStore: this.metadataStore,
@@ -326,10 +419,12 @@ export class ServiceContext extends Resource {
326
419
  edgeHttpClient: this._edgeHttpClient,
327
420
  echoEdgeReplicator: this._echoEdgeReplicator,
328
421
  meshReplicator: this._meshReplicator,
329
- runtimeParams: this._runtimeParams as DataSpaceManagerRuntimeParams,
422
+ runtimeProps: this._runtimeProps as DataSpaceManagerRuntimeProps,
330
423
  edgeFeatures: this._edgeFeatures,
331
424
  });
332
- await this.dataSpaceManager.open();
425
+ log('_initialize: opening DataSpaceManager...');
426
+ await this.dataSpaceManager.open(ctx);
427
+ log('_initialize: DataSpaceManager opened');
333
428
 
334
429
  this.edgeAgentManager = new EdgeAgentManager(
335
430
  this._edgeFeatures,
@@ -337,17 +432,41 @@ export class ServiceContext extends Resource {
337
432
  this.dataSpaceManager,
338
433
  identity,
339
434
  );
340
- await this.edgeAgentManager.open();
435
+ log('_initialize: opening EdgeAgentManager...');
436
+ await this.edgeAgentManager.open(ctx);
437
+ log('_initialize: EdgeAgentManager opened');
341
438
 
342
439
  this._handlerFactories.set(Invitation.Kind.SPACE, (invitation) => {
343
440
  invariant(this.dataSpaceManager, 'dataSpaceManager not initialized yet');
344
441
  return new SpaceInvitationProtocol(this.dataSpaceManager, signingContext, this.keyring, invitation.spaceKey);
345
442
  });
346
443
  this.initialized.wake();
444
+ log('_initialize: initialized.wake() called');
347
445
 
348
446
  this._deviceSpaceSync = {
349
447
  processCredential: async (credential: Credential) => {
350
448
  const assertion = getCredentialAssertion(credential);
449
+
450
+ // A space was tombstoned on another device: replicate the deletion locally.
451
+ if (assertion['@type'] === 'dxos.halo.credentials.SpaceDeleted') {
452
+ if (assertion.spaceKey.equals(identity.space.key)) {
453
+ // ignore halo space
454
+ return;
455
+ }
456
+ if (!this.dataSpaceManager) {
457
+ log('dataSpaceManager not initialized yet, ignoring space deletion', { details: assertion });
458
+ return;
459
+ }
460
+
461
+ try {
462
+ log('tombstoning space recorded in halo', { details: assertion });
463
+ await this.dataSpaceManager.handleRemoteSpaceDeleted(this._ctx, assertion.spaceKey);
464
+ } catch (err) {
465
+ log.catch(err);
466
+ }
467
+ return;
468
+ }
469
+
351
470
  if (assertion['@type'] !== 'dxos.halo.credentials.SpaceMember') {
352
471
  return;
353
472
  }
@@ -359,6 +478,11 @@ export class ServiceContext extends Resource {
359
478
  log('dataSpaceManager not initialized yet, ignoring space admission', { details: assertion });
360
479
  return;
361
480
  }
481
+ // Do not re-accept a space that has been tombstoned (handles out-of-order credential replay).
482
+ if (this.dataSpaceManager.isSpaceDeleted(assertion.spaceKey)) {
483
+ log('space is deleted, ignoring space admission', { details: assertion });
484
+ return;
485
+ }
362
486
  if (this.dataSpaceManager.spaces.has(assertion.spaceKey)) {
363
487
  log('space already exists, ignoring space admission', { details: assertion });
364
488
  return;
@@ -366,9 +490,10 @@ export class ServiceContext extends Resource {
366
490
 
367
491
  try {
368
492
  log('accepting space recorded in halo', { details: assertion });
369
- await this.dataSpaceManager.acceptSpace({
493
+ await this.dataSpaceManager.acceptSpace(this._ctx, {
370
494
  spaceKey: assertion.spaceKey,
371
495
  genesisFeedKey: assertion.genesisFeedKey,
496
+ tags: assertion.tags,
372
497
  });
373
498
  } catch (err) {
374
499
  log.catch(err);
@@ -379,33 +504,42 @@ export class ServiceContext extends Resource {
379
504
  await identity.space.spaceState.addCredentialProcessor(this._deviceSpaceSync);
380
505
  }
381
506
 
382
- private async _setNetworkIdentity(params?: { deviceCredential: Credential }): Promise<void> {
507
+ private async _setNetworkIdentity(params?: { deviceCredential?: Credential; identity?: Identity }): Promise<void> {
508
+ log('_setNetworkIdentity: acquiring mutex...');
383
509
  using _ = await this._edgeIdentityUpdateMutex.acquire();
510
+ log('_setNetworkIdentity: mutex acquired');
384
511
 
385
512
  let edgeIdentity: EdgeIdentity;
386
- const identity = this.identityManager.identity;
513
+ const identity = params?.identity;
387
514
  if (identity) {
388
- log('setting identity on edge connection', {
515
+ log('_setNetworkIdentity: has identity', {
389
516
  identity: identity.identityKey.toHex(),
390
- swarms: this.networkManager.topics,
517
+ hasDeviceCredential: !!params?.deviceCredential,
391
518
  });
392
519
 
393
520
  if (params?.deviceCredential) {
521
+ log('_setNetworkIdentity: creating chain edge identity with device credential...');
394
522
  edgeIdentity = await createChainEdgeIdentity(
395
523
  identity.signer,
396
524
  identity.identityKey,
397
525
  identity.deviceKey,
398
- params?.deviceCredential && { credential: params.deviceCredential },
526
+ { credential: params.deviceCredential },
399
527
  [], // TODO(dmaretskyi): Service access credentials.
400
528
  );
529
+ log('_setNetworkIdentity: chain edge identity created');
401
530
  } else {
531
+ log('_setNetworkIdentity: waiting for identity.ready()...');
402
532
  // TODO: throw here or from identity if device chain can't be loaded, to avoid indefinite hangup
403
533
  await warnAfterTimeout(10_000, 'Waiting for identity to be ready for edge connection', async () => {
404
534
  await identity.ready();
405
535
  });
536
+ log('_setNetworkIdentity: identity.ready() resolved', {
537
+ hasDeviceCredentialChain: !!identity.deviceCredentialChain,
538
+ });
406
539
 
407
540
  invariant(identity.deviceCredentialChain);
408
541
 
542
+ log('_setNetworkIdentity: creating chain edge identity...');
409
543
  edgeIdentity = await createChainEdgeIdentity(
410
544
  identity.signer,
411
545
  identity.identityKey,
@@ -413,9 +547,12 @@ export class ServiceContext extends Resource {
413
547
  identity.deviceCredentialChain,
414
548
  [], // TODO(dmaretskyi): Service access credentials.
415
549
  );
550
+ log('_setNetworkIdentity: chain edge identity created');
416
551
  }
417
552
  } else {
553
+ log('_setNetworkIdentity: no identity, creating ephemeral edge identity...');
418
554
  edgeIdentity = await createEphemeralEdgeIdentity();
555
+ log('_setNetworkIdentity: ephemeral edge identity created');
419
556
  }
420
557
 
421
558
  this._edgeConnection?.setIdentity(edgeIdentity);
@@ -424,5 +561,6 @@ export class ServiceContext extends Resource {
424
561
  identityKey: edgeIdentity.identityKey,
425
562
  peerKey: edgeIdentity.peerKey,
426
563
  });
564
+ log('_setNetworkIdentity: done');
427
565
  }
428
566
  }
@@ -3,7 +3,6 @@
3
3
  //
4
4
 
5
5
  import { rmSync } from 'node:fs';
6
-
7
6
  import { afterEach, describe, expect, onTestFinished, test } from 'vitest';
8
7
 
9
8
  import { Trigger, asyncTimeout, latch } from '@dxos/async';
@@ -13,6 +12,7 @@ import { verifyPresentation } from '@dxos/credentials';
13
12
  import { type PublicKey } from '@dxos/keys';
14
13
  import { MemorySignalManagerContext } from '@dxos/messaging';
15
14
  import { type Identity } from '@dxos/protocols/proto/dxos/client/services';
15
+ import { MembershipPolicy } from '@dxos/protocols/proto/dxos/halo/credentials';
16
16
  import { type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';
17
17
  import { isNode } from '@dxos/util';
18
18
 
@@ -29,16 +29,16 @@ describe('ClientServicesHost', () => {
29
29
  test('open and close', async () => {
30
30
  const host = createServiceHost(new Config(), new MemorySignalManagerContext());
31
31
  await host.open(new Context());
32
- await host.close();
32
+ await host.close(Context.default());
33
33
  });
34
34
 
35
35
  test('queryCredentials', async () => {
36
36
  const host = createServiceHost(new Config(), new MemorySignalManagerContext());
37
37
  await host.open(new Context());
38
- onTestFinished(() => host.close());
38
+ onTestFinished(() => host.close(Context.default()));
39
39
 
40
40
  await host.services.IdentityService!.createIdentity({});
41
- const { spaceKey } = await host.services.SpacesService!.createSpace();
41
+ const { spaceKey } = await host.services.SpacesService!.createSpace({ membershipPolicy: MembershipPolicy.INVITE });
42
42
 
43
43
  const stream = host.services.SpacesService!.queryCredentials({ spaceKey });
44
44
  const [done, tick] = latch({ count: 3 });
@@ -54,7 +54,7 @@ describe('ClientServicesHost', () => {
54
54
  test('write and query credentials', async () => {
55
55
  const host = createServiceHost(new Config(), new MemorySignalManagerContext());
56
56
  await host.open(new Context());
57
- onTestFinished(() => host.close());
57
+ onTestFinished(() => host.close(Context.default()));
58
58
 
59
59
  await host.services.IdentityService!.createIdentity({});
60
60
 
@@ -91,7 +91,7 @@ describe('ClientServicesHost', () => {
91
91
  test('sign presentation', async () => {
92
92
  const host = createServiceHost(new Config(), new MemorySignalManagerContext());
93
93
  await host.open(new Context());
94
- onTestFinished(() => host.close());
94
+ onTestFinished(() => host.close(Context.default()));
95
95
 
96
96
  await host.services.IdentityService!.createIdentity({});
97
97
 
@@ -125,10 +125,8 @@ describe('ClientServicesHost', () => {
125
125
 
126
126
  await host.services.IdentityService?.createIdentity({});
127
127
 
128
- expect(host.context.storage.size).to.exist;
129
-
130
128
  await asyncTimeout(host.reset(), 1000);
131
- await host.close();
129
+ await host.close(Context.default());
132
130
  }
133
131
 
134
132
  {
@@ -146,7 +144,7 @@ describe('ClientServicesHost', () => {
146
144
  });
147
145
  await expect(asyncTimeout(trigger.wait(), 200)).rejects.toBeInstanceOf(Error);
148
146
  await stream?.close();
149
- await host.close();
147
+ await host.close(Context.default());
150
148
  }
151
149
  });
152
150
  });