@dxos/client-services 0.8.4-main.b97322e → 0.8.4-main.bcb3aa67d6

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