@dxos/client-services 0.8.4-main.f9ba587 → 0.8.4-main.fcfe5033a5

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