@dxos/client-services 0.8.4-main.84f28bd → 0.8.4-main.8baae0fced

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 (255) hide show
  1. package/LICENSE +102 -5
  2. package/README.md +1 -1
  3. package/dist/lib/browser/{chunk-OCFDRCSN.mjs → chunk-KBMYCFTL.mjs} +3177 -4457
  4. package/dist/lib/browser/chunk-KBMYCFTL.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 +451 -145
  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 +35 -36
  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-D7F3FYZS.mjs → chunk-TCS4PMDH.mjs} +3056 -4204
  27. package/dist/lib/node-esm/chunk-TCS4PMDH.mjs.map +7 -0
  28. package/dist/lib/node-esm/index.mjs +451 -145
  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 +35 -36
  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 +3 -2
  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 +20 -20
  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.map +1 -1
  53. package/dist/types/src/packlets/devtools/metadata.d.ts.map +1 -1
  54. package/dist/types/src/packlets/devtools/network.d.ts +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 +1 -1
  58. package/dist/types/src/packlets/diagnostics/browser-diagnostics-broadcast.d.ts.map +1 -1
  59. package/dist/types/src/packlets/diagnostics/diagnostics-broadcast.d.ts +1 -1
  60. package/dist/types/src/packlets/diagnostics/diagnostics-broadcast.d.ts.map +1 -1
  61. package/dist/types/src/packlets/diagnostics/diagnostics-collector.d.ts.map +1 -1
  62. package/dist/types/src/packlets/diagnostics/diagnostics.d.ts +3 -4
  63. package/dist/types/src/packlets/diagnostics/diagnostics.d.ts.map +1 -1
  64. package/dist/types/src/packlets/diagnostics/index.d.ts +1 -1
  65. package/dist/types/src/packlets/diagnostics/index.d.ts.map +1 -1
  66. package/dist/types/src/packlets/identity/authenticator.d.ts +2 -2
  67. package/dist/types/src/packlets/identity/authenticator.d.ts.map +1 -1
  68. package/dist/types/src/packlets/identity/contacts-service.d.ts +1 -1
  69. package/dist/types/src/packlets/identity/contacts-service.d.ts.map +1 -1
  70. package/dist/types/src/packlets/identity/identity-manager.d.ts +7 -7
  71. package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
  72. package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts +8 -7
  73. package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts.map +1 -1
  74. package/dist/types/src/packlets/identity/identity-service.d.ts +6 -10
  75. package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
  76. package/dist/types/src/packlets/identity/identity.d.ts +9 -12
  77. package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
  78. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts +6 -5
  79. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -1
  80. package/dist/types/src/packlets/invitations/edge-invitation-handler.d.ts +2 -2
  81. package/dist/types/src/packlets/invitations/edge-invitation-handler.d.ts.map +1 -1
  82. package/dist/types/src/packlets/invitations/index.d.ts +1 -1
  83. package/dist/types/src/packlets/invitations/index.d.ts.map +1 -1
  84. package/dist/types/src/packlets/invitations/invitation-guest-extenstion.d.ts.map +1 -1
  85. package/dist/types/src/packlets/invitations/invitation-host-extension.d.ts.map +1 -1
  86. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts +8 -5
  87. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts.map +1 -1
  88. package/dist/types/src/packlets/invitations/invitation-state.d.ts.map +1 -1
  89. package/dist/types/src/packlets/invitations/invitation-topology.d.ts.map +1 -1
  90. package/dist/types/src/packlets/invitations/invitations-handler.d.ts +4 -4
  91. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  92. package/dist/types/src/packlets/invitations/invitations-manager.d.ts +3 -3
  93. package/dist/types/src/packlets/invitations/invitations-manager.d.ts.map +1 -1
  94. package/dist/types/src/packlets/invitations/invitations-service.d.ts +4 -4
  95. package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
  96. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +5 -4
  97. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
  98. package/dist/types/src/packlets/invitations/utils.d.ts.map +1 -1
  99. package/dist/types/src/packlets/locks/browser.d.ts.map +1 -1
  100. package/dist/types/src/packlets/locks/index.d.ts +2 -2
  101. package/dist/types/src/packlets/locks/index.d.ts.map +1 -1
  102. package/dist/types/src/packlets/locks/node.d.ts.map +1 -1
  103. package/dist/types/src/packlets/logging/logging-service.d.ts +5 -1
  104. package/dist/types/src/packlets/logging/logging-service.d.ts.map +1 -1
  105. package/dist/types/src/packlets/network/network-service.d.ts +7 -6
  106. package/dist/types/src/packlets/network/network-service.d.ts.map +1 -1
  107. package/dist/types/src/packlets/services/client-rpc-server.d.ts +5 -5
  108. package/dist/types/src/packlets/services/client-rpc-server.d.ts.map +1 -1
  109. package/dist/types/src/packlets/services/feed-syncer.d.ts +59 -0
  110. package/dist/types/src/packlets/services/feed-syncer.d.ts.map +1 -0
  111. package/dist/types/src/packlets/services/feed-syncer.test.d.ts +2 -0
  112. package/dist/types/src/packlets/services/feed-syncer.test.d.ts.map +1 -0
  113. package/dist/types/src/packlets/services/platform.d.ts.map +1 -1
  114. package/dist/types/src/packlets/services/service-context.d.ts +14 -10
  115. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  116. package/dist/types/src/packlets/services/service-host.d.ts +21 -8
  117. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  118. package/dist/types/src/packlets/services/service-registry.d.ts.map +1 -1
  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 +8 -2
  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 +1 -1
  135. package/dist/types/src/packlets/spaces/automerge-space-state.d.ts.map +1 -1
  136. package/dist/types/src/packlets/spaces/data-space-manager.d.ts +31 -20
  137. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  138. package/dist/types/src/packlets/spaces/data-space.d.ts +30 -13
  139. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  140. package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts +2 -2
  141. package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts.map +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 +2 -1
  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 +11 -8
  148. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  149. package/dist/types/src/packlets/storage/level.d.ts.map +1 -1
  150. package/dist/types/src/packlets/storage/profile-archive.d.ts.map +1 -1
  151. package/dist/types/src/packlets/storage/storage.d.ts.map +1 -1
  152. package/dist/types/src/packlets/storage/util.d.ts.map +1 -1
  153. package/dist/types/src/packlets/system/system-service.d.ts +2 -2
  154. package/dist/types/src/packlets/system/system-service.d.ts.map +1 -1
  155. package/dist/types/src/packlets/testing/credential-utils.d.ts.map +1 -1
  156. package/dist/types/src/packlets/testing/invitation-utils.d.ts +6 -3
  157. package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
  158. package/dist/types/src/packlets/testing/test-builder.d.ts +8 -7
  159. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  160. package/dist/types/src/packlets/worker/worker-runtime.d.ts +41 -4
  161. package/dist/types/src/packlets/worker/worker-runtime.d.ts.map +1 -1
  162. package/dist/types/src/packlets/worker/worker-session.d.ts +2 -4
  163. package/dist/types/src/packlets/worker/worker-session.d.ts.map +1 -1
  164. package/dist/types/src/testing/setup.d.ts.map +1 -1
  165. package/dist/types/src/version.d.ts +1 -1
  166. package/dist/types/src/version.d.ts.map +1 -1
  167. package/dist/types/tsconfig.tsbuildinfo +1 -1
  168. package/package.json +73 -56
  169. package/src/index.ts +1 -0
  170. package/src/packlets/agents/edge-agent-manager.ts +10 -7
  171. package/src/packlets/agents/edge-agent-service.ts +17 -5
  172. package/src/packlets/devices/devices-service.test.ts +3 -3
  173. package/src/packlets/devices/devices-service.ts +2 -2
  174. package/src/packlets/devtools/devtools.ts +29 -29
  175. package/src/packlets/devtools/feeds.ts +2 -2
  176. package/src/packlets/devtools/network.ts +1 -1
  177. package/src/packlets/diagnostics/browser-diagnostics-broadcast.ts +1 -1
  178. package/src/packlets/diagnostics/diagnostics-broadcast.ts +1 -1
  179. package/src/packlets/diagnostics/diagnostics-collector.ts +1 -1
  180. package/src/packlets/diagnostics/diagnostics.ts +2 -3
  181. package/src/packlets/diagnostics/index.ts +1 -1
  182. package/src/packlets/identity/authenticator.node.test.ts +1 -1
  183. package/src/packlets/identity/authenticator.ts +3 -3
  184. package/src/packlets/identity/contacts-service.ts +2 -2
  185. package/src/packlets/identity/identity-manager.test.ts +8 -8
  186. package/src/packlets/identity/identity-manager.ts +25 -24
  187. package/src/packlets/identity/identity-recovery-manager.ts +22 -18
  188. package/src/packlets/identity/identity-service.test.ts +8 -28
  189. package/src/packlets/identity/identity-service.ts +13 -80
  190. package/src/packlets/identity/identity.test.ts +11 -11
  191. package/src/packlets/identity/identity.ts +17 -39
  192. package/src/packlets/invitations/device-invitation-protocol.test.ts +4 -4
  193. package/src/packlets/invitations/device-invitation-protocol.ts +8 -6
  194. package/src/packlets/invitations/edge-invitation-handler.ts +10 -6
  195. package/src/packlets/invitations/index.ts +1 -1
  196. package/src/packlets/invitations/invitation-guest-extenstion.ts +7 -5
  197. package/src/packlets/invitations/invitation-host-extension.ts +15 -16
  198. package/src/packlets/invitations/invitation-protocol.ts +8 -5
  199. package/src/packlets/invitations/invitation-state.ts +1 -15
  200. package/src/packlets/invitations/invitations-handler.test.ts +301 -292
  201. package/src/packlets/invitations/invitations-handler.ts +77 -25
  202. package/src/packlets/invitations/invitations-manager.ts +43 -18
  203. package/src/packlets/invitations/invitations-service.ts +10 -10
  204. package/src/packlets/invitations/space-invitation-protocol.test.ts +26 -25
  205. package/src/packlets/invitations/space-invitation-protocol.ts +13 -17
  206. package/src/packlets/invitations/utils.ts +1 -1
  207. package/src/packlets/locks/browser.ts +1 -1
  208. package/src/packlets/locks/index.ts +2 -2
  209. package/src/packlets/logging/logging-service.ts +22 -17
  210. package/src/packlets/logging/logging.test.ts +1 -1
  211. package/src/packlets/network/network-service.test.ts +3 -3
  212. package/src/packlets/network/network-service.ts +12 -10
  213. package/src/packlets/services/client-rpc-server.ts +20 -17
  214. package/src/packlets/services/feed-syncer.test.ts +340 -0
  215. package/src/packlets/services/feed-syncer.ts +377 -0
  216. package/src/packlets/services/platform.ts +7 -1
  217. package/src/packlets/services/service-context.test.ts +4 -3
  218. package/src/packlets/services/service-context.ts +160 -67
  219. package/src/packlets/services/service-host.test.ts +10 -9
  220. package/src/packlets/services/service-host.ts +86 -47
  221. package/src/packlets/services/service-registry.test.ts +1 -1
  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 +111 -0
  225. package/src/packlets/space-export/serialized-space-writer.ts +252 -0
  226. package/src/packlets/space-export/space-archive-reader.ts +65 -4
  227. package/src/packlets/space-export/space-archive-writer.ts +44 -6
  228. package/src/packlets/space-export/space-archive.test.ts +461 -0
  229. package/src/packlets/space-export/tar.test.ts +1 -1
  230. package/src/packlets/spaces/automerge-space-state.ts +1 -1
  231. package/src/packlets/spaces/data-space-manager.test.ts +79 -13
  232. package/src/packlets/spaces/data-space-manager.ts +134 -129
  233. package/src/packlets/spaces/data-space.ts +71 -42
  234. package/src/packlets/spaces/edge-feed-replicator.test.ts +4 -4
  235. package/src/packlets/spaces/edge-feed-replicator.ts +13 -11
  236. package/src/packlets/spaces/epoch-migrations.ts +6 -5
  237. package/src/packlets/spaces/genesis.ts +6 -1
  238. package/src/packlets/spaces/notarization-plugin.test.ts +3 -3
  239. package/src/packlets/spaces/notarization-plugin.ts +13 -12
  240. package/src/packlets/spaces/spaces-service.test.ts +20 -12
  241. package/src/packlets/spaces/spaces-service.ts +140 -38
  242. package/src/packlets/storage/profile-archive.ts +1 -1
  243. package/src/packlets/storage/storage.ts +7 -8
  244. package/src/packlets/system/system-service.test.ts +1 -1
  245. package/src/packlets/system/system-service.ts +4 -4
  246. package/src/packlets/testing/invitation-utils.ts +11 -7
  247. package/src/packlets/testing/test-builder.ts +39 -13
  248. package/src/packlets/worker/worker-runtime.ts +189 -17
  249. package/src/packlets/worker/worker-session.ts +15 -21
  250. package/src/version.ts +1 -1
  251. package/dist/lib/browser/chunk-OCFDRCSN.mjs.map +0 -7
  252. package/dist/lib/node-esm/chunk-D7F3FYZS.mjs.map +0 -7
  253. package/dist/types/src/packlets/identity/default-space-state-machine.d.ts +0 -19
  254. package/dist/types/src/packlets/identity/default-space-state-machine.d.ts.map +0 -1
  255. package/src/packlets/identity/default-space-state-machine.ts +0 -44
@@ -2,39 +2,41 @@
2
2
  // Copyright 2021 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 { Event, synchronized } from '@dxos/async';
6
- import { clientServiceBundle, type ClientServices } from '@dxos/client-protocol';
7
- import { type Config } from '@dxos/config';
9
+ import { type ClientServices, clientServiceBundle } from '@dxos/client-protocol';
10
+ import { type Config, resolveTelemetryTag } from '@dxos/config';
8
11
  import { Context } from '@dxos/context';
9
- import { EdgeClient, EdgeHttpClient, createStubEdgeIdentity, type EdgeConnection } from '@dxos/edge-client';
12
+ import { EdgeClient, type EdgeConnection, EdgeHttpClient, createStubEdgeIdentity } from '@dxos/edge-client';
13
+ import { RuntimeProvider } from '@dxos/effect';
10
14
  import { invariant } from '@dxos/invariant';
11
- import { PublicKey } from '@dxos/keys';
12
15
  import { type LevelDB } from '@dxos/kv-store';
13
16
  import { log } from '@dxos/log';
14
- import { EdgeSignalManager, WebsocketSignalManager, type SignalManager } from '@dxos/messaging';
17
+ import { EdgeSignalManager, type SignalManager, WebsocketSignalManager } from '@dxos/messaging';
15
18
  import {
16
19
  SwarmNetworkManager,
20
+ type TransportFactory,
17
21
  createIceProvider,
18
22
  createRtcTransportFactory,
19
- type TransportFactory,
20
23
  } from '@dxos/network-manager';
21
- import { trace } from '@dxos/protocols';
22
24
  import { SystemStatus } from '@dxos/protocols/proto/dxos/client/services';
23
25
  import { type Storage } from '@dxos/random-access-storage';
24
- import { TRACE_PROCESSOR, trace as Trace } from '@dxos/tracing';
26
+ import * as SqlExport from '@dxos/sql-sqlite/SqlExport';
27
+ import type * as SqlTransaction from '@dxos/sql-sqlite/SqlTransaction';
28
+ import { trace as Trace } from '@dxos/tracing';
25
29
  import { WebsocketRpcClient } from '@dxos/websocket-rpc';
26
30
 
27
- import { ServiceContext, type ServiceContextRuntimeParams } from './service-context';
28
- import { ServiceRegistry } from './service-registry';
29
31
  import { EdgeAgentServiceImpl } from '../agents';
30
32
  import { DevicesServiceImpl } from '../devices';
31
33
  import { DevtoolsHostEvents, DevtoolsServiceImpl } from '../devtools';
32
34
  import {
35
+ type CollectDiagnosticsBroadcastHandler,
33
36
  createCollectDiagnosticsBroadcastHandler,
34
37
  createDiagnostics,
35
- type CollectDiagnosticsBroadcastHandler,
36
38
  } from '../diagnostics';
37
- import { IdentityServiceImpl, type CreateIdentityOptions } from '../identity';
39
+ import { type CreateIdentityOptions, IdentityServiceImpl } from '../identity';
38
40
  import { ContactsServiceImpl } from '../identity/contacts-service';
39
41
  import { InvitationsServiceImpl } from '../invitations';
40
42
  import { Lock, type ResourceLock } from '../locks';
@@ -43,8 +45,10 @@ import { NetworkServiceImpl } from '../network';
43
45
  import { SpacesServiceImpl } from '../spaces';
44
46
  import { createLevel, createStorageObjects } from '../storage';
45
47
  import { SystemServiceImpl } from '../system';
48
+ import { ServiceContext, type ServiceContextRuntimeProps } from './service-context';
49
+ import { ServiceRegistry } from './service-registry';
46
50
 
47
- export type ClientServicesHostParams = {
51
+ export type ClientServicesHostProps = {
48
52
  /**
49
53
  * Can be omitted if `initialize` is later called.
50
54
  */
@@ -56,7 +60,8 @@ export type ClientServicesHostParams = {
56
60
  level?: LevelDB;
57
61
  lockKey?: string;
58
62
  callbacks?: ClientServicesHostCallbacks;
59
- runtimeParams?: ServiceContextRuntimeParams;
63
+ runtime: RuntimeProvider.RuntimeProvider<SqlClient.SqlClient | SqlExport.SqlExport | SqlTransaction.SqlTransaction>;
64
+ runtimeProps?: ServiceContextRuntimeProps;
60
65
  };
61
66
 
62
67
  export type ClientServicesHostCallbacks = {
@@ -79,10 +84,9 @@ export class ClientServicesHost {
79
84
  private readonly _serviceRegistry: ServiceRegistry<ClientServices>;
80
85
  private readonly _systemService: SystemServiceImpl;
81
86
  private readonly _loggingService: LoggingServiceImpl;
82
- private readonly _tracingService = TRACE_PROCESSOR.createTraceSender();
87
+ private readonly _statusUpdate = new Event<void>();
83
88
 
84
89
  private _config?: Config;
85
- private readonly _statusUpdate = new Event<void>();
86
90
  private _signalManager?: SignalManager;
87
91
  private _networkManager?: SwarmNetworkManager;
88
92
  private _storage?: Storage;
@@ -93,7 +97,10 @@ export class ClientServicesHost {
93
97
  private _edgeHttpClient?: EdgeHttpClient = undefined;
94
98
 
95
99
  private _serviceContext!: ServiceContext;
96
- private readonly _runtimeParams: ServiceContextRuntimeParams;
100
+ private readonly _runtime: RuntimeProvider.RuntimeProvider<
101
+ SqlClient.SqlClient | SqlExport.SqlExport | SqlTransaction.SqlTransaction
102
+ >;
103
+ private readonly _runtimeProps: ServiceContextRuntimeProps;
97
104
  private diagnosticsBroadcastHandler: CollectDiagnosticsBroadcastHandler;
98
105
 
99
106
  @Trace.info()
@@ -114,20 +121,14 @@ export class ClientServicesHost {
114
121
  // TODO(wittjosiah): Turn this on by default.
115
122
  lockKey,
116
123
  callbacks,
117
- runtimeParams,
118
- }: ClientServicesHostParams = {}) {
124
+ runtime,
125
+ runtimeProps,
126
+ }: ClientServicesHostProps) {
119
127
  this._storage = storage;
120
128
  this._level = level;
121
129
  this._callbacks = callbacks;
122
- this._runtimeParams = runtimeParams ?? {};
123
-
124
- if (this._runtimeParams.disableP2pReplication === undefined) {
125
- this._runtimeParams.disableP2pReplication = config?.get('runtime.client.disableP2pReplication', false);
126
- }
127
-
128
- if (this._runtimeParams.enableVectorIndexing === undefined) {
129
- this._runtimeParams.enableVectorIndexing = config?.get('runtime.client.enableVectorIndexing', false);
130
- }
130
+ this._runtime = runtime;
131
+ this._runtimeProps = runtimeProps ?? {};
131
132
 
132
133
  if (config) {
133
134
  this.initialize({ config, transportFactory, signalManager });
@@ -141,7 +142,7 @@ export class ClientServicesHost {
141
142
  void this.open(new Context());
142
143
  }
143
144
  },
144
- onRelease: () => this.close(),
145
+ onRelease: () => this.close(Context.default()),
145
146
  });
146
147
  }
147
148
 
@@ -170,7 +171,6 @@ export class ClientServicesHost {
170
171
 
171
172
  this._serviceRegistry = new ServiceRegistry<ClientServices>(clientServiceBundle, {
172
173
  SystemService: this._systemService,
173
- TracingService: this._tracingService,
174
174
  });
175
175
  }
176
176
 
@@ -198,6 +198,30 @@ export class ClientServicesHost {
198
198
  return this._serviceRegistry.services;
199
199
  }
200
200
 
201
+ /**
202
+ * Debugging util.
203
+ */
204
+ async exportSqliteDatabase(): Promise<Uint8Array> {
205
+ return await RuntimeProvider.runPromise(this._runtime)(
206
+ Effect.gen(function* () {
207
+ const sql = yield* SqlExport.SqlExport;
208
+ return yield* sql.export;
209
+ }),
210
+ );
211
+ }
212
+
213
+ /**
214
+ * Debugging util.
215
+ */
216
+ async runSqliteQuery(query: string, params?: any[]): Promise<readonly Record<string, unknown>[]> {
217
+ return await RuntimeProvider.runPromise(this._runtime)(
218
+ Effect.gen(function* () {
219
+ const sql = yield* SqlClient.SqlClient;
220
+ return yield* sql`${sql.unsafe(query, params)}`;
221
+ }),
222
+ );
223
+ }
224
+
201
225
  /**
202
226
  * Initialize the service host with the config.
203
227
  * Config can also be provided in the constructor.
@@ -208,6 +232,13 @@ export class ClientServicesHost {
208
232
  log('initializing...');
209
233
 
210
234
  if (config) {
235
+ if (this._runtimeProps.disableP2pReplication === undefined) {
236
+ this._runtimeProps.disableP2pReplication = config?.get('runtime.client.disableP2pReplication', false);
237
+ }
238
+ if (this._runtimeProps.enableVectorIndexing === undefined) {
239
+ this._runtimeProps.enableVectorIndexing = config?.get('runtime.client.enableVectorIndexing', false);
240
+ }
241
+
211
242
  invariant(!this._config, 'config already set');
212
243
  this._config = config;
213
244
  if (!this._storage) {
@@ -215,14 +246,16 @@ export class ClientServicesHost {
215
246
  }
216
247
  }
217
248
 
249
+ // TODO(wittjosiah): This is quite noisy during tests. Make configurable? Remove?
218
250
  if (!options.signalManager) {
219
- log.warn('running signaling without telemetry metadata.');
251
+ // log.warn('running signaling without telemetry metadata.');
220
252
  }
221
253
 
222
254
  const endpoint = config?.get('runtime.services.edge.url');
223
255
  if (endpoint) {
224
- this._edgeConnection = new EdgeClient(createStubEdgeIdentity(), { socketEndpoint: endpoint });
225
- this._edgeHttpClient = new EdgeHttpClient(endpoint);
256
+ const clientTag = resolveTelemetryTag(config);
257
+ this._edgeConnection = new EdgeClient(createStubEdgeIdentity(), { socketEndpoint: endpoint, clientTag });
258
+ this._edgeHttpClient = new EdgeHttpClient(endpoint, { clientTag });
226
259
  }
227
260
 
228
261
  const {
@@ -261,8 +294,7 @@ export class ClientServicesHost {
261
294
  return;
262
295
  }
263
296
 
264
- const traceId = PublicKey.random().toHex();
265
- log.trace('dxos.client-services.host.open', trace.begin({ id: traceId }));
297
+ log('opening service host');
266
298
 
267
299
  invariant(this._config, 'config not set');
268
300
  invariant(this._storage, 'storage not set');
@@ -288,7 +320,8 @@ export class ClientServicesHost {
288
320
  this._signalManager,
289
321
  this._edgeConnection,
290
322
  this._edgeHttpClient,
291
- this._runtimeParams,
323
+ this._runtime,
324
+ this._runtimeProps,
292
325
  this._config.get('runtime.client.edgeFeatures'),
293
326
  );
294
327
 
@@ -306,8 +339,7 @@ export class ClientServicesHost {
306
339
  this._serviceContext.identityManager,
307
340
  this._serviceContext.recoveryManager,
308
341
  this._serviceContext.keyring,
309
- () => this._serviceContext.dataSpaceManager!,
310
- (params) => this._createIdentity(params),
342
+ (params, ctx) => this._createIdentity(params, ctx),
311
343
  (profile) => this._serviceContext.broadcastProfileUpdate(profile),
312
344
  );
313
345
 
@@ -327,11 +359,13 @@ export class ClientServicesHost {
327
359
  SpacesService: new SpacesServiceImpl(
328
360
  this._serviceContext.identityManager,
329
361
  this._serviceContext.spaceManager,
362
+ this._serviceContext.echoHost,
330
363
  dataSpaceManagerProvider,
331
364
  ),
332
365
 
333
366
  DataService: this._serviceContext.echoHost.dataService,
334
367
  QueryService: this._serviceContext.echoHost.queryService,
368
+ QueueService: this._serviceContext.echoHost.queuesService,
335
369
 
336
370
  NetworkService: new NetworkServiceImpl(
337
371
  this._serviceContext.networkManager,
@@ -340,7 +374,6 @@ export class ClientServicesHost {
340
374
  ),
341
375
 
342
376
  LoggingService: this._loggingService,
343
- TracingService: this._tracingService,
344
377
 
345
378
  // TODO(burdon): Move to new protobuf definitions.
346
379
  DevtoolsHost: new DevtoolsServiceImpl({
@@ -352,8 +385,13 @@ export class ClientServicesHost {
352
385
  EdgeAgentService: new EdgeAgentServiceImpl(agentManagerProvider, this._edgeConnection),
353
386
  });
354
387
 
388
+ log('service-host: opening service context...');
355
389
  await this._serviceContext.open(ctx);
390
+ log('service-host: service context opened');
391
+
392
+ log('service-host: opening identity service...');
356
393
  await identityService.open();
394
+ log('service-host: identity service opened');
357
395
 
358
396
  const devtoolsProxy = this._config?.get('runtime.client.devtoolsProxy');
359
397
  if (devtoolsProxy) {
@@ -372,12 +410,11 @@ export class ClientServicesHost {
372
410
  this._statusUpdate.emit();
373
411
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
374
412
  log('opened', { deviceKey });
375
- log.trace('dxos.client-services.host.open', trace.end({ id: traceId }));
376
413
  }
377
414
 
378
415
  @synchronized
379
416
  @Trace.span()
380
- async close(): Promise<void> {
417
+ async close(ctx: Context): Promise<void> {
381
418
  if (!this._open) {
382
419
  return;
383
420
  }
@@ -396,23 +433,25 @@ export class ClientServicesHost {
396
433
  }
397
434
 
398
435
  async reset(): Promise<void> {
399
- const traceId = PublicKey.random().toHex();
400
- log.trace('dxos.sdk.client-services-host.reset', trace.begin({ id: traceId }));
401
-
402
436
  log.info('resetting...');
403
437
  // Emit this status update immediately so app returns to fallback.
404
438
  // This state is never cleared because the app reloads.
405
439
  this._resetting = true;
406
440
  this._statusUpdate.emit();
407
441
  await this._serviceContext?.close();
442
+ // Clear LevelDB contents to remove all persisted Echo/Automerge/index data.
443
+ try {
444
+ await this._level!.clear();
445
+ } catch (err) {
446
+ log.warn('failed to clear leveldb during reset', { err });
447
+ }
408
448
  await this._storage!.reset();
409
449
  log.info('reset');
410
- log.trace('dxos.sdk.client-services-host.reset', trace.end({ id: traceId }));
411
450
  await this._callbacks?.onReset?.();
412
451
  }
413
452
 
414
- private async _createIdentity(params: CreateIdentityOptions) {
415
- const identity = await this._serviceContext.createIdentity(params);
453
+ private async _createIdentity(params: CreateIdentityOptions, ctx?: Context) {
454
+ const identity = await this._serviceContext.createIdentity(params, ctx);
416
455
  await this._serviceContext.initialized.wait();
417
456
  return identity;
418
457
  }
@@ -13,9 +13,9 @@ import { schema } from '@dxos/protocols/proto';
13
13
  import { type SystemService, SystemStatus } from '@dxos/protocols/proto/dxos/client/services';
14
14
  import { createLinkedPorts, createProtoRpcPeer, createServiceBundle } from '@dxos/rpc';
15
15
 
16
- import { ServiceRegistry } from './service-registry';
17
16
  import { SystemServiceImpl } from '../system';
18
17
  import { createServiceContext } from '../testing';
18
+ import { ServiceRegistry } from './service-registry';
19
19
 
20
20
  // TODO(burdon): Create TestService (that doesn't require peers).
21
21
 
@@ -0,0 +1,42 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { SpaceArchive } from '@dxos/protocols/proto/dxos/client/services';
6
+
7
+ const JSON_EXTENSIONS = ['.dx.json', '.dx.json.gz', '.json'];
8
+ const BINARY_EXTENSIONS = ['.tar', '.tar.gz'];
9
+
10
+ /**
11
+ * Detect the format of a space archive.
12
+ *
13
+ * Uses filename extension as the primary signal, and falls back to sniffing
14
+ * the first bytes of the archive contents to distinguish JSON from tar.
15
+ */
16
+ export const detectSpaceArchiveFormat = (archive: Pick<SpaceArchive, 'filename' | 'contents'>): SpaceArchive.Format => {
17
+ const filename = archive.filename?.toLowerCase() ?? '';
18
+ if (JSON_EXTENSIONS.some((ext) => filename.endsWith(ext))) {
19
+ return SpaceArchive.Format.JSON;
20
+ }
21
+ if (BINARY_EXTENSIONS.some((ext) => filename.endsWith(ext))) {
22
+ return SpaceArchive.Format.BINARY;
23
+ }
24
+
25
+ // Fall back to byte sniffing: JSON archives start with '{' (0x7B) or whitespace.
26
+ const bytes = archive.contents;
27
+ if (bytes && bytes.length > 0) {
28
+ for (let i = 0; i < Math.min(bytes.length, 16); i++) {
29
+ const byte = bytes[i];
30
+ // Skip whitespace.
31
+ if (byte === 0x20 || byte === 0x09 || byte === 0x0a || byte === 0x0d) {
32
+ continue;
33
+ }
34
+ if (byte === 0x7b /* '{' */) {
35
+ return SpaceArchive.Format.JSON;
36
+ }
37
+ break;
38
+ }
39
+ }
40
+
41
+ return SpaceArchive.Format.BINARY;
42
+ };
@@ -2,5 +2,8 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- export * from './space-archive-writer';
5
+ export * from './archive-format';
6
+ export * from './serialized-space-reader';
7
+ export * from './serialized-space-writer';
6
8
  export * from './space-archive-reader';
9
+ export * from './space-archive-writer';
@@ -0,0 +1,111 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { type Obj } from '@dxos/echo';
6
+ import { type SerializedSpace } from '@dxos/echo-db';
7
+ import { type DatabaseDirectory, type ObjectStructure } from '@dxos/echo-protocol';
8
+ import { assertArgument } from '@dxos/invariant';
9
+ import { type SpaceArchive } from '@dxos/protocols/proto/dxos/client/services';
10
+
11
+ const ATTR_TYPE = '@type';
12
+ const ATTR_META = '@meta';
13
+ const ATTR_DELETED = '@deleted';
14
+ const ATTR_PARENT = '@parent';
15
+ const ATTR_RELATION_SOURCE = '@relationSource';
16
+ const ATTR_RELATION_TARGET = '@relationTarget';
17
+
18
+ const INTERNAL_KEYS: ReadonlySet<string> = new Set([
19
+ 'id',
20
+ ATTR_TYPE,
21
+ ATTR_META,
22
+ ATTR_DELETED,
23
+ ATTR_PARENT,
24
+ ATTR_RELATION_SOURCE,
25
+ ATTR_RELATION_TARGET,
26
+ ]);
27
+
28
+ /**
29
+ * Parse a JSON space archive.
30
+ *
31
+ * The archive contents are expected to be the UTF-8 encoding of
32
+ * `JSON.stringify(serializedSpace)`.
33
+ */
34
+ export const readSerializedSpaceArchive = (archive: SpaceArchive): SerializedSpace => {
35
+ const text = new TextDecoder().decode(archive.contents);
36
+ const parsed = JSON.parse(text) as SerializedSpace;
37
+ assertArgument(typeof parsed === 'object' && parsed !== null, 'archive', 'Invalid JSON archive payload');
38
+ assertArgument(typeof parsed.version === 'number', 'archive', 'Missing SerializedSpace.version');
39
+ assertArgument(Array.isArray(parsed.objects), 'archive', 'Missing SerializedSpace.objects');
40
+ return parsed;
41
+ };
42
+
43
+ /**
44
+ * Convert an {@link Obj.JSON} back into an internal {@link ObjectStructure} suitable
45
+ * for embedding into a {@link DatabaseDirectory}.
46
+ */
47
+ export const objJsonToObjectStructure = (obj: Obj.JSON): ObjectStructure => {
48
+ const data: Record<string, unknown> = {};
49
+ for (const [key, value] of Object.entries(obj)) {
50
+ if (INTERNAL_KEYS.has(key)) {
51
+ continue;
52
+ }
53
+ data[key] = value;
54
+ }
55
+
56
+ const system: NonNullable<ObjectStructure['system']> = {};
57
+
58
+ const type = obj[ATTR_TYPE];
59
+ if (type) {
60
+ system.type = { '/': type as string };
61
+ }
62
+
63
+ const parent = (obj as any)[ATTR_PARENT];
64
+ if (typeof parent === 'string') {
65
+ system.parent = { '/': parent };
66
+ }
67
+
68
+ const relationSource = (obj as any)[ATTR_RELATION_SOURCE];
69
+ const relationTarget = (obj as any)[ATTR_RELATION_TARGET];
70
+ if (typeof relationSource === 'string' || typeof relationTarget === 'string') {
71
+ system.kind = 'relation';
72
+ if (typeof relationSource === 'string') {
73
+ system.source = { '/': relationSource };
74
+ }
75
+ if (typeof relationTarget === 'string') {
76
+ system.target = { '/': relationTarget };
77
+ }
78
+ } else {
79
+ system.kind = 'object';
80
+ }
81
+
82
+ if ((obj as any)[ATTR_DELETED]) {
83
+ system.deleted = true;
84
+ }
85
+
86
+ const meta = (obj as any)[ATTR_META];
87
+ return {
88
+ system,
89
+ meta: {
90
+ keys: meta?.keys ?? [],
91
+ ...(meta?.tags ? { tags: meta.tags } : {}),
92
+ },
93
+ data,
94
+ };
95
+ };
96
+
97
+ /**
98
+ * Build a new {@link DatabaseDirectory} containing every object from the archive,
99
+ * keyed by object id. The caller is responsible for stamping the `access.spaceKey`
100
+ * and version fields after the document is created.
101
+ */
102
+ export const buildDatabaseDirectoryFromObjects = (objects: readonly Obj.JSON[]): DatabaseDirectory => {
103
+ const map: Record<string, ObjectStructure> = {};
104
+ for (const obj of objects) {
105
+ map[obj.id] = objJsonToObjectStructure(obj);
106
+ }
107
+ return {
108
+ objects: map,
109
+ links: {},
110
+ };
111
+ };