@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,39 +2,43 @@
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
15
  import { PublicKey } from '@dxos/keys';
12
16
  import { type LevelDB } from '@dxos/kv-store';
13
17
  import { log } from '@dxos/log';
14
- import { EdgeSignalManager, WebsocketSignalManager, type SignalManager } from '@dxos/messaging';
18
+ import { EdgeSignalManager, type SignalManager, WebsocketSignalManager } from '@dxos/messaging';
15
19
  import {
16
20
  SwarmNetworkManager,
21
+ type TransportFactory,
17
22
  createIceProvider,
18
23
  createRtcTransportFactory,
19
- type TransportFactory,
20
24
  } from '@dxos/network-manager';
21
25
  import { trace } from '@dxos/protocols';
22
26
  import { SystemStatus } from '@dxos/protocols/proto/dxos/client/services';
23
27
  import { type Storage } from '@dxos/random-access-storage';
24
- import { TRACE_PROCESSOR, trace as Trace } from '@dxos/tracing';
28
+ import * as SqlExport from '@dxos/sql-sqlite/SqlExport';
29
+ import type * as SqlTransaction from '@dxos/sql-sqlite/SqlTransaction';
30
+ import { trace as Trace } from '@dxos/tracing';
25
31
  import { WebsocketRpcClient } from '@dxos/websocket-rpc';
26
32
 
27
- import { ServiceContext, type ServiceContextRuntimeParams } from './service-context';
28
- import { ServiceRegistry } from './service-registry';
29
33
  import { EdgeAgentServiceImpl } from '../agents';
30
34
  import { DevicesServiceImpl } from '../devices';
31
35
  import { DevtoolsHostEvents, DevtoolsServiceImpl } from '../devtools';
32
36
  import {
37
+ type CollectDiagnosticsBroadcastHandler,
33
38
  createCollectDiagnosticsBroadcastHandler,
34
39
  createDiagnostics,
35
- type CollectDiagnosticsBroadcastHandler,
36
40
  } from '../diagnostics';
37
- import { IdentityServiceImpl, type CreateIdentityOptions } from '../identity';
41
+ import { type CreateIdentityOptions, IdentityServiceImpl } from '../identity';
38
42
  import { ContactsServiceImpl } from '../identity/contacts-service';
39
43
  import { InvitationsServiceImpl } from '../invitations';
40
44
  import { Lock, type ResourceLock } from '../locks';
@@ -43,8 +47,10 @@ import { NetworkServiceImpl } from '../network';
43
47
  import { SpacesServiceImpl } from '../spaces';
44
48
  import { createLevel, createStorageObjects } from '../storage';
45
49
  import { SystemServiceImpl } from '../system';
50
+ import { ServiceContext, type ServiceContextRuntimeProps } from './service-context';
51
+ import { ServiceRegistry } from './service-registry';
46
52
 
47
- export type ClientServicesHostParams = {
53
+ export type ClientServicesHostProps = {
48
54
  /**
49
55
  * Can be omitted if `initialize` is later called.
50
56
  */
@@ -56,7 +62,8 @@ export type ClientServicesHostParams = {
56
62
  level?: LevelDB;
57
63
  lockKey?: string;
58
64
  callbacks?: ClientServicesHostCallbacks;
59
- runtimeParams?: ServiceContextRuntimeParams;
65
+ runtime: RuntimeProvider.RuntimeProvider<SqlClient.SqlClient | SqlExport.SqlExport | SqlTransaction.SqlTransaction>;
66
+ runtimeProps?: ServiceContextRuntimeProps;
60
67
  };
61
68
 
62
69
  export type ClientServicesHostCallbacks = {
@@ -79,10 +86,9 @@ export class ClientServicesHost {
79
86
  private readonly _serviceRegistry: ServiceRegistry<ClientServices>;
80
87
  private readonly _systemService: SystemServiceImpl;
81
88
  private readonly _loggingService: LoggingServiceImpl;
82
- private readonly _tracingService = TRACE_PROCESSOR.createTraceSender();
89
+ private readonly _statusUpdate = new Event<void>();
83
90
 
84
91
  private _config?: Config;
85
- private readonly _statusUpdate = new Event<void>();
86
92
  private _signalManager?: SignalManager;
87
93
  private _networkManager?: SwarmNetworkManager;
88
94
  private _storage?: Storage;
@@ -93,7 +99,10 @@ export class ClientServicesHost {
93
99
  private _edgeHttpClient?: EdgeHttpClient = undefined;
94
100
 
95
101
  private _serviceContext!: ServiceContext;
96
- private readonly _runtimeParams: ServiceContextRuntimeParams;
102
+ private readonly _runtime: RuntimeProvider.RuntimeProvider<
103
+ SqlClient.SqlClient | SqlExport.SqlExport | SqlTransaction.SqlTransaction
104
+ >;
105
+ private readonly _runtimeProps: ServiceContextRuntimeProps;
97
106
  private diagnosticsBroadcastHandler: CollectDiagnosticsBroadcastHandler;
98
107
 
99
108
  @Trace.info()
@@ -114,20 +123,14 @@ export class ClientServicesHost {
114
123
  // TODO(wittjosiah): Turn this on by default.
115
124
  lockKey,
116
125
  callbacks,
117
- runtimeParams,
118
- }: ClientServicesHostParams = {}) {
126
+ runtime,
127
+ runtimeProps,
128
+ }: ClientServicesHostProps) {
119
129
  this._storage = storage;
120
130
  this._level = level;
121
131
  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
- }
132
+ this._runtime = runtime;
133
+ this._runtimeProps = runtimeProps ?? {};
131
134
 
132
135
  if (config) {
133
136
  this.initialize({ config, transportFactory, signalManager });
@@ -141,7 +144,7 @@ export class ClientServicesHost {
141
144
  void this.open(new Context());
142
145
  }
143
146
  },
144
- onRelease: () => this.close(),
147
+ onRelease: () => this.close(Context.default()),
145
148
  });
146
149
  }
147
150
 
@@ -170,7 +173,6 @@ export class ClientServicesHost {
170
173
 
171
174
  this._serviceRegistry = new ServiceRegistry<ClientServices>(clientServiceBundle, {
172
175
  SystemService: this._systemService,
173
- TracingService: this._tracingService,
174
176
  });
175
177
  }
176
178
 
@@ -198,6 +200,30 @@ export class ClientServicesHost {
198
200
  return this._serviceRegistry.services;
199
201
  }
200
202
 
203
+ /**
204
+ * Debugging util.
205
+ */
206
+ async exportSqliteDatabase(): Promise<Uint8Array> {
207
+ return await RuntimeProvider.runPromise(this._runtime)(
208
+ Effect.gen(function* () {
209
+ const sql = yield* SqlExport.SqlExport;
210
+ return yield* sql.export;
211
+ }),
212
+ );
213
+ }
214
+
215
+ /**
216
+ * Debugging util.
217
+ */
218
+ async runSqliteQuery(query: string, params?: any[]): Promise<readonly Record<string, unknown>[]> {
219
+ return await RuntimeProvider.runPromise(this._runtime)(
220
+ Effect.gen(function* () {
221
+ const sql = yield* SqlClient.SqlClient;
222
+ return yield* sql`${sql.unsafe(query, params)}`;
223
+ }),
224
+ );
225
+ }
226
+
201
227
  /**
202
228
  * Initialize the service host with the config.
203
229
  * Config can also be provided in the constructor.
@@ -208,6 +234,13 @@ export class ClientServicesHost {
208
234
  log('initializing...');
209
235
 
210
236
  if (config) {
237
+ if (this._runtimeProps.disableP2pReplication === undefined) {
238
+ this._runtimeProps.disableP2pReplication = config?.get('runtime.client.disableP2pReplication', false);
239
+ }
240
+ if (this._runtimeProps.enableVectorIndexing === undefined) {
241
+ this._runtimeProps.enableVectorIndexing = config?.get('runtime.client.enableVectorIndexing', false);
242
+ }
243
+
211
244
  invariant(!this._config, 'config already set');
212
245
  this._config = config;
213
246
  if (!this._storage) {
@@ -215,14 +248,16 @@ export class ClientServicesHost {
215
248
  }
216
249
  }
217
250
 
251
+ // TODO(wittjosiah): This is quite noisy during tests. Make configurable? Remove?
218
252
  if (!options.signalManager) {
219
- log.warn('running signaling without telemetry metadata.');
253
+ // log.warn('running signaling without telemetry metadata.');
220
254
  }
221
255
 
222
256
  const endpoint = config?.get('runtime.services.edge.url');
223
257
  if (endpoint) {
224
- this._edgeConnection = new EdgeClient(createStubEdgeIdentity(), { socketEndpoint: endpoint });
225
- this._edgeHttpClient = new EdgeHttpClient(endpoint);
258
+ const clientTag = resolveTelemetryTag(config);
259
+ this._edgeConnection = new EdgeClient(createStubEdgeIdentity(), { socketEndpoint: endpoint, clientTag });
260
+ this._edgeHttpClient = new EdgeHttpClient(endpoint, { clientTag });
226
261
  }
227
262
 
228
263
  const {
@@ -288,7 +323,8 @@ export class ClientServicesHost {
288
323
  this._signalManager,
289
324
  this._edgeConnection,
290
325
  this._edgeHttpClient,
291
- this._runtimeParams,
326
+ this._runtime,
327
+ this._runtimeProps,
292
328
  this._config.get('runtime.client.edgeFeatures'),
293
329
  );
294
330
 
@@ -306,8 +342,7 @@ export class ClientServicesHost {
306
342
  this._serviceContext.identityManager,
307
343
  this._serviceContext.recoveryManager,
308
344
  this._serviceContext.keyring,
309
- () => this._serviceContext.dataSpaceManager!,
310
- (params) => this._createIdentity(params),
345
+ (params, ctx) => this._createIdentity(params, ctx),
311
346
  (profile) => this._serviceContext.broadcastProfileUpdate(profile),
312
347
  );
313
348
 
@@ -327,11 +362,13 @@ export class ClientServicesHost {
327
362
  SpacesService: new SpacesServiceImpl(
328
363
  this._serviceContext.identityManager,
329
364
  this._serviceContext.spaceManager,
365
+ this._serviceContext.echoHost,
330
366
  dataSpaceManagerProvider,
331
367
  ),
332
368
 
333
369
  DataService: this._serviceContext.echoHost.dataService,
334
370
  QueryService: this._serviceContext.echoHost.queryService,
371
+ QueueService: this._serviceContext.echoHost.queuesService,
335
372
 
336
373
  NetworkService: new NetworkServiceImpl(
337
374
  this._serviceContext.networkManager,
@@ -340,7 +377,6 @@ export class ClientServicesHost {
340
377
  ),
341
378
 
342
379
  LoggingService: this._loggingService,
343
- TracingService: this._tracingService,
344
380
 
345
381
  // TODO(burdon): Move to new protobuf definitions.
346
382
  DevtoolsHost: new DevtoolsServiceImpl({
@@ -352,8 +388,13 @@ export class ClientServicesHost {
352
388
  EdgeAgentService: new EdgeAgentServiceImpl(agentManagerProvider, this._edgeConnection),
353
389
  });
354
390
 
391
+ log('service-host: opening service context...');
355
392
  await this._serviceContext.open(ctx);
393
+ log('service-host: service context opened');
394
+
395
+ log('service-host: opening identity service...');
356
396
  await identityService.open();
397
+ log('service-host: identity service opened');
357
398
 
358
399
  const devtoolsProxy = this._config?.get('runtime.client.devtoolsProxy');
359
400
  if (devtoolsProxy) {
@@ -377,7 +418,7 @@ export class ClientServicesHost {
377
418
 
378
419
  @synchronized
379
420
  @Trace.span()
380
- async close(): Promise<void> {
421
+ async close(ctx: Context): Promise<void> {
381
422
  if (!this._open) {
382
423
  return;
383
424
  }
@@ -405,14 +446,20 @@ export class ClientServicesHost {
405
446
  this._resetting = true;
406
447
  this._statusUpdate.emit();
407
448
  await this._serviceContext?.close();
449
+ // Clear LevelDB contents to remove all persisted Echo/Automerge/index data.
450
+ try {
451
+ await this._level!.clear();
452
+ } catch (err) {
453
+ log.warn('failed to clear leveldb during reset', { err });
454
+ }
408
455
  await this._storage!.reset();
409
456
  log.info('reset');
410
457
  log.trace('dxos.sdk.client-services-host.reset', trace.end({ id: traceId }));
411
458
  await this._callbacks?.onReset?.();
412
459
  }
413
460
 
414
- private async _createIdentity(params: CreateIdentityOptions) {
415
- const identity = await this._serviceContext.createIdentity(params);
461
+ private async _createIdentity(params: CreateIdentityOptions, ctx?: Context) {
462
+ const identity = await this._serviceContext.createIdentity(params, ctx);
416
463
  await this._serviceContext.initialized.wait();
417
464
  return identity;
418
465
  }
@@ -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
+ };