@dxos/client-services 0.8.4-main.c85a9c8dae → 0.8.4-main.d05539e30a

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 (201) hide show
  1. package/LICENSE +102 -5
  2. package/README.md +1 -1
  3. package/dist/lib/browser/{chunk-MQ6PWJ76.mjs → chunk-NGONP3EI.mjs} +1640 -3097
  4. package/dist/lib/browser/chunk-NGONP3EI.mjs.map +7 -0
  5. package/dist/lib/browser/{chunk-NQSC7HOE.mjs → chunk-XJRPB3GA.mjs} +1 -1
  6. package/dist/lib/browser/index.mjs +106 -194
  7. package/dist/lib/browser/index.mjs.map +3 -3
  8. package/dist/lib/browser/meta.json +1 -1
  9. package/dist/lib/browser/packlets/diagnostics/browser-diagnostics-broadcast.mjs +1 -6
  10. package/dist/lib/browser/packlets/diagnostics/browser-diagnostics-broadcast.mjs.map +2 -2
  11. package/dist/lib/browser/packlets/diagnostics/diagnostics-broadcast.mjs +1 -1
  12. package/dist/lib/browser/packlets/locks/browser.mjs +9 -49
  13. package/dist/lib/browser/packlets/locks/browser.mjs.map +2 -2
  14. package/dist/lib/browser/packlets/locks/node.mjs +4 -22
  15. package/dist/lib/browser/packlets/locks/node.mjs.map +2 -2
  16. package/dist/lib/browser/testing/index.mjs +9 -22
  17. package/dist/lib/browser/testing/index.mjs.map +3 -3
  18. package/dist/lib/node-esm/{chunk-PKEGMOQ4.mjs → chunk-2DT3MZRL.mjs} +1 -1
  19. package/dist/lib/node-esm/{chunk-GUAL4U7S.mjs → chunk-OAECSUV2.mjs} +1640 -3097
  20. package/dist/lib/node-esm/chunk-OAECSUV2.mjs.map +7 -0
  21. package/dist/lib/node-esm/index.mjs +106 -194
  22. package/dist/lib/node-esm/index.mjs.map +3 -3
  23. package/dist/lib/node-esm/meta.json +1 -1
  24. package/dist/lib/node-esm/packlets/diagnostics/browser-diagnostics-broadcast.mjs +1 -6
  25. package/dist/lib/node-esm/packlets/diagnostics/browser-diagnostics-broadcast.mjs.map +2 -2
  26. package/dist/lib/node-esm/packlets/diagnostics/diagnostics-broadcast.mjs +1 -1
  27. package/dist/lib/node-esm/packlets/locks/browser.mjs +9 -49
  28. package/dist/lib/node-esm/packlets/locks/browser.mjs.map +2 -2
  29. package/dist/lib/node-esm/packlets/locks/node.mjs +4 -22
  30. package/dist/lib/node-esm/packlets/locks/node.mjs.map +2 -2
  31. package/dist/lib/node-esm/testing/index.mjs +9 -22
  32. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  33. package/dist/types/src/index.d.ts +1 -0
  34. package/dist/types/src/index.d.ts.map +1 -1
  35. package/dist/types/src/packlets/agents/edge-agent-manager.d.ts +3 -2
  36. package/dist/types/src/packlets/agents/edge-agent-manager.d.ts.map +1 -1
  37. package/dist/types/src/packlets/agents/edge-agent-service.d.ts +2 -1
  38. package/dist/types/src/packlets/agents/edge-agent-service.d.ts.map +1 -1
  39. package/dist/types/src/packlets/devices/devices-service.d.ts.map +1 -1
  40. package/dist/types/src/packlets/devtools/devtools.d.ts.map +1 -1
  41. package/dist/types/src/packlets/devtools/feeds.d.ts.map +1 -1
  42. package/dist/types/src/packlets/devtools/keys.d.ts.map +1 -1
  43. package/dist/types/src/packlets/devtools/metadata.d.ts.map +1 -1
  44. package/dist/types/src/packlets/devtools/network.d.ts.map +1 -1
  45. package/dist/types/src/packlets/devtools/spaces.d.ts.map +1 -1
  46. package/dist/types/src/packlets/diagnostics/browser-diagnostics-broadcast.d.ts.map +1 -1
  47. package/dist/types/src/packlets/diagnostics/diagnostics-broadcast.d.ts.map +1 -1
  48. package/dist/types/src/packlets/diagnostics/diagnostics-collector.d.ts.map +1 -1
  49. package/dist/types/src/packlets/diagnostics/diagnostics.d.ts +2 -3
  50. package/dist/types/src/packlets/diagnostics/diagnostics.d.ts.map +1 -1
  51. package/dist/types/src/packlets/identity/authenticator.d.ts.map +1 -1
  52. package/dist/types/src/packlets/identity/contacts-service.d.ts.map +1 -1
  53. package/dist/types/src/packlets/identity/identity-manager.d.ts +3 -3
  54. package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
  55. package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts +6 -5
  56. package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts.map +1 -1
  57. package/dist/types/src/packlets/identity/identity-service.d.ts +6 -10
  58. package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
  59. package/dist/types/src/packlets/identity/identity.d.ts +6 -9
  60. package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
  61. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts +2 -1
  62. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -1
  63. package/dist/types/src/packlets/invitations/edge-invitation-handler.d.ts +1 -1
  64. package/dist/types/src/packlets/invitations/edge-invitation-handler.d.ts.map +1 -1
  65. package/dist/types/src/packlets/invitations/invitation-guest-extenstion.d.ts.map +1 -1
  66. package/dist/types/src/packlets/invitations/invitation-host-extension.d.ts.map +1 -1
  67. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts +5 -1
  68. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts.map +1 -1
  69. package/dist/types/src/packlets/invitations/invitation-state.d.ts.map +1 -1
  70. package/dist/types/src/packlets/invitations/invitation-topology.d.ts.map +1 -1
  71. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  72. package/dist/types/src/packlets/invitations/invitations-manager.d.ts +3 -3
  73. package/dist/types/src/packlets/invitations/invitations-manager.d.ts.map +1 -1
  74. package/dist/types/src/packlets/invitations/invitations-service.d.ts +3 -3
  75. package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
  76. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +2 -1
  77. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
  78. package/dist/types/src/packlets/invitations/utils.d.ts.map +1 -1
  79. package/dist/types/src/packlets/locks/browser.d.ts.map +1 -1
  80. package/dist/types/src/packlets/locks/node.d.ts.map +1 -1
  81. package/dist/types/src/packlets/logging/logging-service.d.ts.map +1 -1
  82. package/dist/types/src/packlets/network/network-service.d.ts +5 -4
  83. package/dist/types/src/packlets/network/network-service.d.ts.map +1 -1
  84. package/dist/types/src/packlets/services/client-rpc-server.d.ts +3 -3
  85. package/dist/types/src/packlets/services/client-rpc-server.d.ts.map +1 -1
  86. package/dist/types/src/packlets/services/feed-syncer.d.ts +2 -2
  87. package/dist/types/src/packlets/services/feed-syncer.d.ts.map +1 -1
  88. package/dist/types/src/packlets/services/service-context.d.ts +2 -3
  89. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  90. package/dist/types/src/packlets/services/service-host.d.ts +2 -3
  91. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  92. package/dist/types/src/packlets/services/service-registry.d.ts.map +1 -1
  93. package/dist/types/src/packlets/services/util.d.ts.map +1 -1
  94. package/dist/types/src/packlets/space-export/archive-format.d.ts +9 -0
  95. package/dist/types/src/packlets/space-export/archive-format.d.ts.map +1 -0
  96. package/dist/types/src/packlets/space-export/index.d.ts +4 -1
  97. package/dist/types/src/packlets/space-export/index.d.ts.map +1 -1
  98. package/dist/types/src/packlets/space-export/serialized-space-reader.d.ts +23 -0
  99. package/dist/types/src/packlets/space-export/serialized-space-reader.d.ts.map +1 -0
  100. package/dist/types/src/packlets/space-export/serialized-space-writer.d.ts +36 -0
  101. package/dist/types/src/packlets/space-export/serialized-space-writer.d.ts.map +1 -0
  102. package/dist/types/src/packlets/space-export/space-archive-reader.d.ts +9 -1
  103. package/dist/types/src/packlets/space-export/space-archive-reader.d.ts.map +1 -1
  104. package/dist/types/src/packlets/space-export/space-archive-writer.d.ts +7 -1
  105. package/dist/types/src/packlets/space-export/space-archive-writer.d.ts.map +1 -1
  106. package/dist/types/src/packlets/space-export/space-archive.test.d.ts +2 -0
  107. package/dist/types/src/packlets/space-export/space-archive.test.d.ts.map +1 -0
  108. package/dist/types/src/packlets/spaces/automerge-space-state.d.ts.map +1 -1
  109. package/dist/types/src/packlets/spaces/data-space-manager.d.ts +20 -14
  110. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  111. package/dist/types/src/packlets/spaces/data-space.d.ts +24 -7
  112. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  113. package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts.map +1 -1
  114. package/dist/types/src/packlets/spaces/epoch-migrations.d.ts.map +1 -1
  115. package/dist/types/src/packlets/spaces/genesis.d.ts +2 -1
  116. package/dist/types/src/packlets/spaces/genesis.d.ts.map +1 -1
  117. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts +1 -4
  118. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts.map +1 -1
  119. package/dist/types/src/packlets/spaces/spaces-service.d.ts +10 -7
  120. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  121. package/dist/types/src/packlets/storage/level.d.ts.map +1 -1
  122. package/dist/types/src/packlets/storage/profile-archive.d.ts.map +1 -1
  123. package/dist/types/src/packlets/storage/storage.d.ts.map +1 -1
  124. package/dist/types/src/packlets/storage/util.d.ts.map +1 -1
  125. package/dist/types/src/packlets/system/system-service.d.ts +1 -1
  126. package/dist/types/src/packlets/system/system-service.d.ts.map +1 -1
  127. package/dist/types/src/packlets/testing/credential-utils.d.ts.map +1 -1
  128. package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
  129. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  130. package/dist/types/src/packlets/worker/worker-runtime.d.ts +11 -1
  131. package/dist/types/src/packlets/worker/worker-runtime.d.ts.map +1 -1
  132. package/dist/types/src/packlets/worker/worker-session.d.ts +0 -2
  133. package/dist/types/src/packlets/worker/worker-session.d.ts.map +1 -1
  134. package/dist/types/src/testing/setup.d.ts.map +1 -1
  135. package/dist/types/src/version.d.ts +1 -1
  136. package/dist/types/tsconfig.tsbuildinfo +1 -1
  137. package/package.json +43 -50
  138. package/src/index.ts +1 -0
  139. package/src/packlets/agents/edge-agent-manager.ts +8 -5
  140. package/src/packlets/agents/edge-agent-service.ts +4 -2
  141. package/src/packlets/devices/devices-service.test.ts +0 -1
  142. package/src/packlets/devtools/devtools.ts +0 -1
  143. package/src/packlets/diagnostics/diagnostics.ts +1 -2
  144. package/src/packlets/identity/contacts-service.ts +0 -1
  145. package/src/packlets/identity/identity-manager.test.ts +5 -5
  146. package/src/packlets/identity/identity-manager.ts +18 -17
  147. package/src/packlets/identity/identity-recovery-manager.ts +20 -16
  148. package/src/packlets/identity/identity-service.test.ts +6 -27
  149. package/src/packlets/identity/identity-service.ts +13 -81
  150. package/src/packlets/identity/identity.test.ts +2 -2
  151. package/src/packlets/identity/identity.ts +9 -32
  152. package/src/packlets/invitations/device-invitation-protocol.ts +3 -2
  153. package/src/packlets/invitations/edge-invitation-handler.ts +9 -5
  154. package/src/packlets/invitations/invitation-host-extension.ts +7 -10
  155. package/src/packlets/invitations/invitation-protocol.ts +5 -1
  156. package/src/packlets/invitations/invitation-state.ts +1 -15
  157. package/src/packlets/invitations/invitations-handler.test.ts +4 -5
  158. package/src/packlets/invitations/invitations-handler.ts +67 -15
  159. package/src/packlets/invitations/invitations-manager.ts +40 -15
  160. package/src/packlets/invitations/invitations-service.ts +9 -9
  161. package/src/packlets/invitations/space-invitation-protocol.test.ts +17 -16
  162. package/src/packlets/invitations/space-invitation-protocol.ts +4 -3
  163. package/src/packlets/logging/logging-service.ts +15 -15
  164. package/src/packlets/network/network-service.test.ts +0 -1
  165. package/src/packlets/network/network-service.ts +10 -8
  166. package/src/packlets/services/client-rpc-server.ts +15 -12
  167. package/src/packlets/services/feed-syncer.test.ts +3 -3
  168. package/src/packlets/services/feed-syncer.ts +67 -20
  169. package/src/packlets/services/service-context.test.ts +3 -2
  170. package/src/packlets/services/service-context.ts +106 -46
  171. package/src/packlets/services/service-host.test.ts +8 -8
  172. package/src/packlets/services/service-host.ts +17 -24
  173. package/src/packlets/services/service-registry.test.ts +0 -1
  174. package/src/packlets/space-export/archive-format.ts +42 -0
  175. package/src/packlets/space-export/index.ts +4 -1
  176. package/src/packlets/space-export/serialized-space-reader.ts +111 -0
  177. package/src/packlets/space-export/serialized-space-writer.ts +252 -0
  178. package/src/packlets/space-export/space-archive-reader.ts +64 -3
  179. package/src/packlets/space-export/space-archive-writer.ts +38 -2
  180. package/src/packlets/space-export/space-archive.test.ts +461 -0
  181. package/src/packlets/spaces/data-space-manager.test.ts +79 -13
  182. package/src/packlets/spaces/data-space-manager.ts +80 -115
  183. package/src/packlets/spaces/data-space.ts +55 -31
  184. package/src/packlets/spaces/edge-feed-replicator.test.ts +1 -1
  185. package/src/packlets/spaces/edge-feed-replicator.ts +9 -7
  186. package/src/packlets/spaces/epoch-migrations.ts +4 -3
  187. package/src/packlets/spaces/genesis.ts +6 -1
  188. package/src/packlets/spaces/notarization-plugin.ts +2 -1
  189. package/src/packlets/spaces/spaces-service.test.ts +18 -11
  190. package/src/packlets/spaces/spaces-service.ts +115 -17
  191. package/src/packlets/testing/invitation-utils.ts +3 -2
  192. package/src/packlets/worker/worker-runtime.ts +39 -6
  193. package/src/packlets/worker/worker-session.ts +4 -10
  194. package/src/version.ts +1 -1
  195. package/dist/lib/browser/chunk-MQ6PWJ76.mjs.map +0 -7
  196. package/dist/lib/node-esm/chunk-GUAL4U7S.mjs.map +0 -7
  197. package/dist/types/src/packlets/identity/default-space-state-machine.d.ts +0 -19
  198. package/dist/types/src/packlets/identity/default-space-state-machine.d.ts.map +0 -1
  199. package/src/packlets/identity/default-space-state-machine.ts +0 -44
  200. /package/dist/lib/browser/{chunk-NQSC7HOE.mjs.map → chunk-XJRPB3GA.mjs.map} +0 -0
  201. /package/dist/lib/node-esm/{chunk-PKEGMOQ4.mjs.map → chunk-2DT3MZRL.mjs.map} +0 -0
@@ -3,7 +3,6 @@
3
3
  //
4
4
 
5
5
  import { rmSync } from 'node:fs';
6
-
7
6
  import { afterEach, describe, expect, onTestFinished, test } from 'vitest';
8
7
 
9
8
  import { Trigger, asyncTimeout, latch } from '@dxos/async';
@@ -13,6 +12,7 @@ import { verifyPresentation } from '@dxos/credentials';
13
12
  import { type PublicKey } from '@dxos/keys';
14
13
  import { MemorySignalManagerContext } from '@dxos/messaging';
15
14
  import { type Identity } from '@dxos/protocols/proto/dxos/client/services';
15
+ import { MembershipPolicy } from '@dxos/protocols/proto/dxos/halo/credentials';
16
16
  import { type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';
17
17
  import { isNode } from '@dxos/util';
18
18
 
@@ -29,16 +29,16 @@ describe('ClientServicesHost', () => {
29
29
  test('open and close', async () => {
30
30
  const host = createServiceHost(new Config(), new MemorySignalManagerContext());
31
31
  await host.open(new Context());
32
- await host.close();
32
+ await host.close(Context.default());
33
33
  });
34
34
 
35
35
  test('queryCredentials', async () => {
36
36
  const host = createServiceHost(new Config(), new MemorySignalManagerContext());
37
37
  await host.open(new Context());
38
- onTestFinished(() => host.close());
38
+ onTestFinished(() => host.close(Context.default()));
39
39
 
40
40
  await host.services.IdentityService!.createIdentity({});
41
- const { spaceKey } = await host.services.SpacesService!.createSpace();
41
+ const { spaceKey } = await host.services.SpacesService!.createSpace({ membershipPolicy: MembershipPolicy.INVITE });
42
42
 
43
43
  const stream = host.services.SpacesService!.queryCredentials({ spaceKey });
44
44
  const [done, tick] = latch({ count: 3 });
@@ -54,7 +54,7 @@ describe('ClientServicesHost', () => {
54
54
  test('write and query credentials', async () => {
55
55
  const host = createServiceHost(new Config(), new MemorySignalManagerContext());
56
56
  await host.open(new Context());
57
- onTestFinished(() => host.close());
57
+ onTestFinished(() => host.close(Context.default()));
58
58
 
59
59
  await host.services.IdentityService!.createIdentity({});
60
60
 
@@ -91,7 +91,7 @@ describe('ClientServicesHost', () => {
91
91
  test('sign presentation', async () => {
92
92
  const host = createServiceHost(new Config(), new MemorySignalManagerContext());
93
93
  await host.open(new Context());
94
- onTestFinished(() => host.close());
94
+ onTestFinished(() => host.close(Context.default()));
95
95
 
96
96
  await host.services.IdentityService!.createIdentity({});
97
97
 
@@ -128,7 +128,7 @@ describe('ClientServicesHost', () => {
128
128
  expect(host.context.storage.size).to.exist;
129
129
 
130
130
  await asyncTimeout(host.reset(), 1000);
131
- await host.close();
131
+ await host.close(Context.default());
132
132
  }
133
133
 
134
134
  {
@@ -146,7 +146,7 @@ describe('ClientServicesHost', () => {
146
146
  });
147
147
  await expect(asyncTimeout(trigger.wait(), 200)).rejects.toBeInstanceOf(Error);
148
148
  await stream?.close();
149
- await host.close();
149
+ await host.close(Context.default());
150
150
  }
151
151
  });
152
152
  });
@@ -7,12 +7,11 @@ import * as Effect from 'effect/Effect';
7
7
 
8
8
  import { Event, synchronized } from '@dxos/async';
9
9
  import { type ClientServices, clientServiceBundle } from '@dxos/client-protocol';
10
- import { type Config } from '@dxos/config';
10
+ import { type Config, resolveTelemetryTag } from '@dxos/config';
11
11
  import { Context } from '@dxos/context';
12
12
  import { EdgeClient, type EdgeConnection, EdgeHttpClient, createStubEdgeIdentity } from '@dxos/edge-client';
13
13
  import { RuntimeProvider } from '@dxos/effect';
14
14
  import { invariant } from '@dxos/invariant';
15
- import { PublicKey } from '@dxos/keys';
16
15
  import { type LevelDB } from '@dxos/kv-store';
17
16
  import { log } from '@dxos/log';
18
17
  import { EdgeSignalManager, type SignalManager, WebsocketSignalManager } from '@dxos/messaging';
@@ -22,12 +21,11 @@ import {
22
21
  createIceProvider,
23
22
  createRtcTransportFactory,
24
23
  } from '@dxos/network-manager';
25
- import { trace } from '@dxos/protocols';
26
24
  import { SystemStatus } from '@dxos/protocols/proto/dxos/client/services';
27
25
  import { type Storage } from '@dxos/random-access-storage';
28
26
  import * as SqlExport from '@dxos/sql-sqlite/SqlExport';
29
27
  import type * as SqlTransaction from '@dxos/sql-sqlite/SqlTransaction';
30
- import { TRACE_PROCESSOR, trace as Trace } from '@dxos/tracing';
28
+ import { trace as Trace } from '@dxos/tracing';
31
29
  import { WebsocketRpcClient } from '@dxos/websocket-rpc';
32
30
 
33
31
  import { EdgeAgentServiceImpl } from '../agents';
@@ -47,7 +45,6 @@ import { NetworkServiceImpl } from '../network';
47
45
  import { SpacesServiceImpl } from '../spaces';
48
46
  import { createLevel, createStorageObjects } from '../storage';
49
47
  import { SystemServiceImpl } from '../system';
50
-
51
48
  import { ServiceContext, type ServiceContextRuntimeProps } from './service-context';
52
49
  import { ServiceRegistry } from './service-registry';
53
50
 
@@ -87,8 +84,6 @@ export class ClientServicesHost {
87
84
  private readonly _serviceRegistry: ServiceRegistry<ClientServices>;
88
85
  private readonly _systemService: SystemServiceImpl;
89
86
  private readonly _loggingService: LoggingServiceImpl;
90
- private readonly _tracingService = TRACE_PROCESSOR.createTraceSender();
91
-
92
87
  private readonly _statusUpdate = new Event<void>();
93
88
 
94
89
  private _config?: Config;
@@ -147,7 +142,7 @@ export class ClientServicesHost {
147
142
  void this.open(new Context());
148
143
  }
149
144
  },
150
- onRelease: () => this.close(),
145
+ onRelease: () => this.close(Context.default()),
151
146
  });
152
147
  }
153
148
 
@@ -176,7 +171,6 @@ export class ClientServicesHost {
176
171
 
177
172
  this._serviceRegistry = new ServiceRegistry<ClientServices>(clientServiceBundle, {
178
173
  SystemService: this._systemService,
179
- TracingService: this._tracingService,
180
174
  });
181
175
  }
182
176
 
@@ -259,8 +253,9 @@ export class ClientServicesHost {
259
253
 
260
254
  const endpoint = config?.get('runtime.services.edge.url');
261
255
  if (endpoint) {
262
- this._edgeConnection = new EdgeClient(createStubEdgeIdentity(), { socketEndpoint: endpoint });
263
- 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 });
264
259
  }
265
260
 
266
261
  const {
@@ -299,8 +294,7 @@ export class ClientServicesHost {
299
294
  return;
300
295
  }
301
296
 
302
- const traceId = PublicKey.random().toHex();
303
- log.trace('dxos.client-services.host.open', trace.begin({ id: traceId }));
297
+ log('opening service host');
304
298
 
305
299
  invariant(this._config, 'config not set');
306
300
  invariant(this._storage, 'storage not set');
@@ -345,8 +339,7 @@ export class ClientServicesHost {
345
339
  this._serviceContext.identityManager,
346
340
  this._serviceContext.recoveryManager,
347
341
  this._serviceContext.keyring,
348
- () => this._serviceContext.dataSpaceManager!,
349
- (params) => this._createIdentity(params),
342
+ (params, ctx) => this._createIdentity(params, ctx),
350
343
  (profile) => this._serviceContext.broadcastProfileUpdate(profile),
351
344
  );
352
345
 
@@ -366,6 +359,7 @@ export class ClientServicesHost {
366
359
  SpacesService: new SpacesServiceImpl(
367
360
  this._serviceContext.identityManager,
368
361
  this._serviceContext.spaceManager,
362
+ this._serviceContext.echoHost,
369
363
  dataSpaceManagerProvider,
370
364
  ),
371
365
 
@@ -380,7 +374,6 @@ export class ClientServicesHost {
380
374
  ),
381
375
 
382
376
  LoggingService: this._loggingService,
383
- TracingService: this._tracingService,
384
377
 
385
378
  // TODO(burdon): Move to new protobuf definitions.
386
379
  DevtoolsHost: new DevtoolsServiceImpl({
@@ -392,8 +385,13 @@ export class ClientServicesHost {
392
385
  EdgeAgentService: new EdgeAgentServiceImpl(agentManagerProvider, this._edgeConnection),
393
386
  });
394
387
 
388
+ log('service-host: opening service context...');
395
389
  await this._serviceContext.open(ctx);
390
+ log('service-host: service context opened');
391
+
392
+ log('service-host: opening identity service...');
396
393
  await identityService.open();
394
+ log('service-host: identity service opened');
397
395
 
398
396
  const devtoolsProxy = this._config?.get('runtime.client.devtoolsProxy');
399
397
  if (devtoolsProxy) {
@@ -412,12 +410,11 @@ export class ClientServicesHost {
412
410
  this._statusUpdate.emit();
413
411
  const deviceKey = this._serviceContext.identityManager.identity?.deviceKey;
414
412
  log('opened', { deviceKey });
415
- log.trace('dxos.client-services.host.open', trace.end({ id: traceId }));
416
413
  }
417
414
 
418
415
  @synchronized
419
416
  @Trace.span()
420
- async close(): Promise<void> {
417
+ async close(ctx: Context): Promise<void> {
421
418
  if (!this._open) {
422
419
  return;
423
420
  }
@@ -436,9 +433,6 @@ export class ClientServicesHost {
436
433
  }
437
434
 
438
435
  async reset(): Promise<void> {
439
- const traceId = PublicKey.random().toHex();
440
- log.trace('dxos.sdk.client-services-host.reset', trace.begin({ id: traceId }));
441
-
442
436
  log.info('resetting...');
443
437
  // Emit this status update immediately so app returns to fallback.
444
438
  // This state is never cleared because the app reloads.
@@ -453,12 +447,11 @@ export class ClientServicesHost {
453
447
  }
454
448
  await this._storage!.reset();
455
449
  log.info('reset');
456
- log.trace('dxos.sdk.client-services-host.reset', trace.end({ id: traceId }));
457
450
  await this._callbacks?.onReset?.();
458
451
  }
459
452
 
460
- private async _createIdentity(params: CreateIdentityOptions) {
461
- const identity = await this._serviceContext.createIdentity(params);
453
+ private async _createIdentity(params: CreateIdentityOptions, ctx?: Context) {
454
+ const identity = await this._serviceContext.createIdentity(params, ctx);
462
455
  await this._serviceContext.initialized.wait();
463
456
  return identity;
464
457
  }
@@ -15,7 +15,6 @@ import { createLinkedPorts, createProtoRpcPeer, createServiceBundle } from '@dxo
15
15
 
16
16
  import { SystemServiceImpl } from '../system';
17
17
  import { createServiceContext } from '../testing';
18
-
19
18
  import { ServiceRegistry } from './service-registry';
20
19
 
21
20
  // TODO(burdon): Create TestService (that doesn't require peers).
@@ -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
+ };
@@ -0,0 +1,252 @@
1
+ //
2
+ // Copyright 2025 DXOS.org
3
+ //
4
+
5
+ import { type AutomergeUrl } from '@automerge/automerge-repo';
6
+
7
+ import { Context } from '@dxos/context';
8
+ import { type Obj } from '@dxos/echo';
9
+ import { type SerializedFeed, type SerializedSpace } from '@dxos/echo-db';
10
+ import { type EchoHost } from '@dxos/echo-pipeline';
11
+ import { type DatabaseDirectory, type ObjectStructure } from '@dxos/echo-protocol';
12
+ import { assertState, invariant } from '@dxos/invariant';
13
+ import { DXN, type IdentityDid, type SpaceId } from '@dxos/keys';
14
+ import { log } from '@dxos/log';
15
+ import { FeedProtocol } from '@dxos/protocols';
16
+ import { SpaceArchive } from '@dxos/protocols/proto/dxos/client/services';
17
+ import { createFilename } from '@dxos/util';
18
+
19
+ import { type DataSpace } from '../spaces/data-space';
20
+
21
+ const SERIALIZED_SPACE_VERSION = 1;
22
+
23
+ const FEED_TYPENAME = 'org.dxos.type.feed';
24
+
25
+ const ATTR_ID = 'id';
26
+ const ATTR_TYPE = '@type';
27
+ const ATTR_META = '@meta';
28
+ const ATTR_DELETED = '@deleted';
29
+ const ATTR_PARENT = '@parent';
30
+ const ATTR_RELATION_SOURCE = '@relationSource';
31
+ const ATTR_RELATION_TARGET = '@relationTarget';
32
+
33
+ /**
34
+ * Canonical order of well-known system fields in a serialized object.
35
+ * All remaining `@*` fields follow in the order they appear on the source
36
+ * object, and finally the data fields are appended in their existing order.
37
+ */
38
+ const SYSTEM_FIELD_ORDER: readonly string[] = [
39
+ ATTR_ID,
40
+ ATTR_TYPE,
41
+ ATTR_META,
42
+ ATTR_DELETED,
43
+ ATTR_PARENT,
44
+ ATTR_RELATION_SOURCE,
45
+ ATTR_RELATION_TARGET,
46
+ ];
47
+
48
+ /**
49
+ * Reorder the keys of an {@link Obj.JSON} so that system fields appear first
50
+ * (`id`, `@type`, `@meta`, then any other `@*` attributes), followed by data
51
+ * fields. The returned object has identical values to the input — only the key
52
+ * iteration order changes.
53
+ */
54
+ export const orderObjJsonFields = (obj: Obj.JSON): Obj.JSON => {
55
+ const source = obj as Record<string, unknown>;
56
+ const result: Record<string, unknown> = {};
57
+ for (const key of SYSTEM_FIELD_ORDER) {
58
+ if (key in source) {
59
+ result[key] = source[key];
60
+ }
61
+ }
62
+ for (const key of Object.keys(source)) {
63
+ if (key.startsWith('@') && !(key in result)) {
64
+ result[key] = source[key];
65
+ }
66
+ }
67
+ for (const key of Object.keys(source)) {
68
+ if (!(key in result)) {
69
+ result[key] = source[key];
70
+ }
71
+ }
72
+ return result as Obj.JSON;
73
+ };
74
+
75
+ export type WriteSerializedSpaceArchiveOptions = {
76
+ space: DataSpace;
77
+ echoHost: EchoHost;
78
+ exportedBy?: IdentityDid;
79
+ };
80
+
81
+ /**
82
+ * Write a JSON space archive from a live {@link DataSpace}.
83
+ *
84
+ * This runs entirely inside the worker and walks automerge documents directly —
85
+ * it does not require a client-side {@link EchoDatabase}. The output conforms to
86
+ * {@link SerializedSpace} and is compatible with the JSON format consumed by the
87
+ * importer in {@link readSerializedSpaceArchive}.
88
+ */
89
+ export const writeSerializedSpaceArchive = async (
90
+ options: WriteSerializedSpaceArchiveOptions,
91
+ ): Promise<SpaceArchive> => {
92
+ const { space, echoHost, exportedBy } = options;
93
+
94
+ const rootUrl = space.automergeSpaceState.lastEpoch?.subject.assertion.automergeRoot;
95
+ assertState(rootUrl, 'Space does not have a root URL');
96
+ const databaseRoot = space.databaseRoot;
97
+ assertState(databaseRoot, 'Space database root is not ready');
98
+
99
+ const rootDoc = databaseRoot.doc();
100
+ invariant(rootDoc, 'Space database root document is not loaded');
101
+
102
+ // Collect all object structures across the root doc and any linked docs.
103
+ const objects: Obj.JSON[] = [];
104
+ collectObjectsFromDoc(rootDoc, objects);
105
+
106
+ for (const linkedUrl of databaseRoot.getAllLinkedDocuments()) {
107
+ const handle = await echoHost.loadDoc<DatabaseDirectory>(Context.default(), linkedUrl as AutomergeUrl);
108
+ if (!handle) {
109
+ log.warn('linked document handle not available; skipping', { url: linkedUrl });
110
+ continue;
111
+ }
112
+ const doc = handle.doc();
113
+ collectObjectsFromDoc(doc, objects);
114
+ }
115
+
116
+ // Export queue/feed messages for every Feed object in the space.
117
+ const feeds = await exportFeedData(space, echoHost, objects);
118
+
119
+ const serialized: SerializedSpace = {
120
+ version: SERIALIZED_SPACE_VERSION,
121
+ timestamp: new Date().toISOString(),
122
+ originalSpaceId: space.id,
123
+ exportedBy,
124
+ createdAt: Date.now(),
125
+ objects,
126
+ ...(feeds.length > 0 ? { feeds } : {}),
127
+ };
128
+
129
+ const encoded = new TextEncoder().encode(JSON.stringify(serialized));
130
+ return {
131
+ filename: createFilename({ parts: [space.id], ext: 'dx.json' }),
132
+ contents: encoded,
133
+ format: SpaceArchive.Format.JSON,
134
+ };
135
+ };
136
+
137
+ const collectObjectsFromDoc = (doc: DatabaseDirectory, out: Obj.JSON[]): void => {
138
+ const docObjects = doc.objects ?? {};
139
+ for (const [objectId, structure] of Object.entries(docObjects)) {
140
+ out.push(objectStructureToObjJson(objectId, structure));
141
+ }
142
+ };
143
+
144
+ /**
145
+ * Convert an internal {@link ObjectStructure} into an {@link Obj.JSON}.
146
+ *
147
+ * Unlike the equivalent helper used for indexing, this preserves the object's
148
+ * `@meta` section so archives produced by this writer can be round-tripped
149
+ * through {@link Obj.fromJSON}.
150
+ */
151
+ export const objectStructureToObjJson = (objectId: string, structure: ObjectStructure): Obj.JSON => {
152
+ const result: Record<string, unknown> = {
153
+ [ATTR_ID]: objectId,
154
+ [ATTR_TYPE]: (structure.system?.type?.['/'] ?? '') as any,
155
+ };
156
+
157
+ if (structure.meta) {
158
+ result[ATTR_META] = {
159
+ keys: structure.meta.keys ?? [],
160
+ ...(structure.meta.tags ? { tags: structure.meta.tags } : {}),
161
+ };
162
+ }
163
+ if (structure.system?.deleted) {
164
+ result[ATTR_DELETED] = true;
165
+ }
166
+ if (structure.system?.parent) {
167
+ result[ATTR_PARENT] = structure.system.parent['/'];
168
+ }
169
+ if (structure.system?.source) {
170
+ result[ATTR_RELATION_SOURCE] = structure.system.source['/'];
171
+ }
172
+ if (structure.system?.target) {
173
+ result[ATTR_RELATION_TARGET] = structure.system.target['/'];
174
+ }
175
+ Object.assign(result, structure.data);
176
+
177
+ return result as Obj.JSON;
178
+ };
179
+
180
+ const exportFeedData = async (space: DataSpace, echoHost: EchoHost, objects: Obj.JSON[]): Promise<SerializedFeed[]> => {
181
+ const feeds: SerializedFeed[] = [];
182
+ const spaceId: SpaceId = space.id;
183
+
184
+ for (const obj of objects) {
185
+ if (obj[ATTR_TYPE] == null) {
186
+ continue;
187
+ }
188
+
189
+ const typeDXN = DXN.tryParse(obj[ATTR_TYPE] as string);
190
+ if (typeDXN?.asTypeDXN()?.type !== FEED_TYPENAME) {
191
+ continue;
192
+ }
193
+
194
+ const namespace = (obj as any).namespace === 'trace' ? 'trace' : 'data';
195
+ const queueDXN = new DXN(DXN.kind.QUEUE, [namespace, spaceId, obj.id]);
196
+
197
+ try {
198
+ const messages = await collectQueueMessages(echoHost, queueDXN);
199
+ if (messages.length > 0) {
200
+ feeds.push({
201
+ feedObjectId: obj.id,
202
+ namespace,
203
+ messages,
204
+ });
205
+ }
206
+ } catch (err) {
207
+ log.warn('failed to export feed data', { feedObjectId: obj.id, error: err });
208
+ }
209
+ }
210
+
211
+ return feeds;
212
+ };
213
+
214
+ const collectQueueMessages = async (echoHost: EchoHost, queueDXN: DXN): Promise<Obj.JSON[]> => {
215
+ const parts = queueDXN.asQueueDXN();
216
+ invariant(parts, 'Expected a queue DXN');
217
+
218
+ const namespace =
219
+ parts.subspaceTag === 'trace' ? FeedProtocol.WellKnownNamespaces.trace : FeedProtocol.WellKnownNamespaces.data;
220
+
221
+ const messages: Obj.JSON[] = [];
222
+ let cursor: string | undefined;
223
+ while (true) {
224
+ const result = await echoHost.queuesService.queryQueue({
225
+ query: {
226
+ spaceId: parts.spaceId,
227
+ queueIds: [parts.queueId],
228
+ queuesNamespace: namespace,
229
+ after: cursor,
230
+ },
231
+ });
232
+ const batch = (result.objects ?? []).flatMap((encoded): Obj.JSON[] => {
233
+ try {
234
+ return [JSON.parse(encoded) as Obj.JSON];
235
+ } catch (err) {
236
+ log.verbose('queue object JSON parse failed; object ignored', { encoded, error: err });
237
+ return [];
238
+ }
239
+ });
240
+ if (batch.length === 0) {
241
+ break;
242
+ }
243
+ for (const message of batch) {
244
+ messages.push(orderObjJsonFields(message));
245
+ }
246
+ if (!result.nextCursor || result.nextCursor === cursor) {
247
+ break;
248
+ }
249
+ cursor = result.nextCursor;
250
+ }
251
+ return messages;
252
+ };