@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
@@ -3,43 +3,36 @@
3
3
  //
4
4
 
5
5
  import { type Doc } from '@automerge/automerge';
6
- import { interpretAsDocumentId, type AutomergeUrl, type DocHandle, type DocumentId } from '@automerge/automerge-repo';
6
+ import { type AutomergeUrl, type DocumentId, interpretAsDocumentId } from '@automerge/automerge-repo';
7
7
 
8
8
  import { Event, synchronized, trackLeaks } from '@dxos/async';
9
- import { PropertiesType, TYPE_PROPERTIES } from '@dxos/client-protocol';
9
+ import { LegacySpaceProperties, SpaceProperties } from '@dxos/client-protocol';
10
10
  import { Context, LifecycleState, Resource, cancelWithContext } from '@dxos/context';
11
11
  import {
12
- createAdmissionCredentials,
13
- getCredentialAssertion,
14
12
  type CredentialSigner,
15
13
  type DelegateInvitationCredential,
16
14
  type MemberInfo,
15
+ createAdmissionCredentials,
16
+ getCredentialAssertion,
17
17
  } from '@dxos/credentials';
18
+ import { Type } from '@dxos/echo';
18
19
  import {
20
+ AuthStatus,
21
+ CredentialServerExtension,
19
22
  DatabaseRoot,
20
- findInlineObjectOfType,
21
23
  type EchoEdgeReplicator,
22
24
  type EchoHost,
23
- AuthStatus,
24
- CredentialServerExtension,
25
25
  type MeshEchoReplicator,
26
26
  type MetadataStore,
27
27
  type Space,
28
28
  type SpaceManager,
29
29
  type SpaceProtocol,
30
30
  type SpaceProtocolSession,
31
- FIND_PARAMS,
31
+ findInlineObjectOfType,
32
32
  } from '@dxos/echo-pipeline';
33
- import {
34
- SpaceDocVersion,
35
- createIdFromSpaceKey,
36
- encodeReference,
37
- type ObjectStructure,
38
- type DatabaseDirectory,
39
- } from '@dxos/echo-protocol';
40
- import { ObjectId, getTypeReference } from '@dxos/echo-schema';
33
+ import { type DatabaseDirectory, createIdFromSpaceKey } from '@dxos/echo-protocol';
41
34
  import type { EdgeConnection, EdgeHttpClient } from '@dxos/edge-client';
42
- import { writeMessages, type FeedStore } from '@dxos/feed-store';
35
+ import { type FeedStore, writeMessages } from '@dxos/feed-store';
43
36
  import { assertArgument, assertState, failedInvariant, invariant } from '@dxos/invariant';
44
37
  import { type Keyring } from '@dxos/keyring';
45
38
  import { PublicKey, type SpaceId } from '@dxos/keys';
@@ -48,27 +41,30 @@ import { AlreadyJoinedError, trace as Trace } from '@dxos/protocols';
48
41
  import { Invitation, SpaceState } from '@dxos/protocols/proto/dxos/client/services';
49
42
  import { type Runtime } from '@dxos/protocols/proto/dxos/config';
50
43
  import { type FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';
51
- import { type SpaceMetadata, EdgeReplicationSetting } from '@dxos/protocols/proto/dxos/echo/metadata';
52
- import { SpaceMember, type Credential, type ProfileDocument } from '@dxos/protocols/proto/dxos/halo/credentials';
44
+ import { EdgeReplicationSetting, type SpaceMetadata } from '@dxos/protocols/proto/dxos/echo/metadata';
45
+ import {
46
+ type Credential,
47
+ MembershipPolicy,
48
+ type ProfileDocument,
49
+ SpaceMember,
50
+ } from '@dxos/protocols/proto/dxos/halo/credentials';
53
51
  import { type DelegateSpaceInvitation } from '@dxos/protocols/proto/dxos/halo/invitations';
54
52
  import { type PeerState } from '@dxos/protocols/proto/dxos/mesh/presence';
55
53
  import { type Teleport } from '@dxos/teleport';
56
54
  import { Gossip, Presence } from '@dxos/teleport-extension-gossip';
57
55
  import { type Timeframe } from '@dxos/timeframe';
58
56
  import { trace } from '@dxos/tracing';
59
- import { ComplexMap, setDeep, deferFunction, forEachAsync } from '@dxos/util';
57
+ import { ComplexMap, deferFunction, forEachAsync } from '@dxos/util';
60
58
 
61
- import { DataSpace } from './data-space';
62
- import { spaceGenesis } from './genesis';
63
59
  import { createAuthProvider } from '../identity';
64
60
  import { type InvitationsManager } from '../invitations';
65
61
 
62
+ import { DataSpace } from './data-space';
63
+ import { spaceGenesis } from './genesis';
64
+
66
65
  const PRESENCE_ANNOUNCE_INTERVAL = 10_000;
67
66
  const PRESENCE_OFFLINE_TIMEOUT = 20_000;
68
67
 
69
- // Space properties key for default metadata.
70
- const DEFAULT_SPACE_KEY = '__DEFAULT__';
71
-
72
68
  export interface SigningContext {
73
69
  identityKey: PublicKey;
74
70
  deviceKey: PublicKey;
@@ -93,6 +89,9 @@ export type AcceptSpaceOptions = {
93
89
  * We will try to catch up to this timeframe before initializing the database.
94
90
  */
95
91
  dataTimeframe?: Timeframe;
92
+
93
+ /** Tags assigned to the space member. */
94
+ tags?: string[];
96
95
  };
97
96
 
98
97
  export type AdmitMemberOptions = {
@@ -101,9 +100,10 @@ export type AdmitMemberOptions = {
101
100
  role: SpaceMember.Role;
102
101
  profile?: ProfileDocument;
103
102
  delegationCredentialId?: PublicKey;
103
+ tags?: string[];
104
104
  };
105
105
 
106
- export type DataSpaceManagerParams = {
106
+ export type DataSpaceManagerProps = {
107
107
  spaceManager: SpaceManager;
108
108
  metadataStore: MetadataStore;
109
109
  keyring: Keyring;
@@ -115,23 +115,31 @@ export type DataSpaceManagerParams = {
115
115
  edgeHttpClient?: EdgeHttpClient;
116
116
  meshReplicator?: MeshEchoReplicator;
117
117
  echoEdgeReplicator?: EchoEdgeReplicator;
118
- runtimeParams?: DataSpaceManagerRuntimeParams;
118
+ runtimeProps?: DataSpaceManagerRuntimeProps;
119
119
  edgeFeatures?: Runtime.Client.EdgeFeatures;
120
120
  };
121
121
 
122
- export type DataSpaceManagerRuntimeParams = {
122
+ export type DataSpaceManagerRuntimeProps = {
123
123
  spaceMemberPresenceAnnounceInterval?: number;
124
124
  spaceMemberPresenceOfflineTimeout?: number;
125
125
  activeEdgeNotarizationPollingInterval?: number;
126
126
  disableP2pReplication?: boolean;
127
+ /**
128
+ * If true, spaces that were previously SPACE_ACTIVE will be automatically activated on startup.
129
+ * This is used in dedicated worker mode to restore space state after leader changeover.
130
+ */
131
+ autoActivateSpaces?: boolean;
127
132
  };
128
133
 
129
134
  export type CreateSpaceOptions = {
130
135
  rootUrl?: AutomergeUrl;
131
136
  documents?: Record<DocumentId, Uint8Array>;
137
+ tags?: string[];
138
+ membershipPolicy?: MembershipPolicy;
132
139
  };
133
140
 
134
141
  @trackLeaks('open', 'close')
142
+ @trace.resource()
135
143
  export class DataSpaceManager extends Resource {
136
144
  public readonly updated = new Event();
137
145
 
@@ -151,9 +159,9 @@ export class DataSpaceManager extends Resource {
151
159
  private readonly _edgeFeatures?: Runtime.Client.EdgeFeatures = undefined;
152
160
  private readonly _meshReplicator?: MeshEchoReplicator = undefined;
153
161
  private readonly _echoEdgeReplicator?: EchoEdgeReplicator = undefined;
154
- private readonly _runtimeParams?: DataSpaceManagerRuntimeParams = undefined;
162
+ private readonly _runtimeProps?: DataSpaceManagerRuntimeProps = undefined;
155
163
 
156
- constructor(params: DataSpaceManagerParams) {
164
+ constructor(params: DataSpaceManagerProps) {
157
165
  super();
158
166
 
159
167
  this._spaceManager = params.spaceManager;
@@ -168,7 +176,7 @@ export class DataSpaceManager extends Resource {
168
176
  this._edgeFeatures = params.edgeFeatures;
169
177
  this._echoEdgeReplicator = params.echoEdgeReplicator;
170
178
  this._edgeHttpClient = params.edgeHttpClient;
171
- this._runtimeParams = params.runtimeParams;
179
+ this._runtimeProps = params.runtimeProps;
172
180
 
173
181
  trace.diagnostic({
174
182
  id: 'spaces',
@@ -178,12 +186,15 @@ export class DataSpaceManager extends Resource {
178
186
  Array.from(this._spaces.values()).map(async (space) => {
179
187
  const rootUrl = space.automergeSpaceState.rootUrl;
180
188
  const rootHandle = rootUrl
181
- ? await this._echoHost.automergeRepo.find<Doc<DatabaseDirectory>>(rootUrl as AutomergeUrl, FIND_PARAMS)
189
+ ? await this._echoHost.loadDoc<Doc<DatabaseDirectory>>(this._ctx, rootUrl as AutomergeUrl)
182
190
  : undefined;
183
191
  await rootHandle?.whenReady();
184
192
  const rootDoc = rootHandle?.doc();
185
193
 
186
- const properties = rootDoc && findInlineObjectOfType(rootDoc, TYPE_PROPERTIES);
194
+ const properties =
195
+ rootDoc &&
196
+ (findInlineObjectOfType(rootDoc, Type.getTypename(SpaceProperties)) ??
197
+ findInlineObjectOfType(rootDoc, Type.getTypename(LegacySpaceProperties)));
187
198
 
188
199
  return {
189
200
  key: space.key.toHex(),
@@ -216,25 +227,38 @@ export class DataSpaceManager extends Resource {
216
227
  log.trace('dxos.echo.data-space-manager.open', Trace.begin({ id: this._instanceId }));
217
228
  log('metadata loaded', { spaces: this._metadataStore.spaces.length });
218
229
 
230
+ const spacesToActivate: DataSpace[] = [];
219
231
  await forEachAsync(this._metadataStore.spaces, async (spaceMetadata) => {
220
232
  try {
221
233
  log('load space', { spaceMetadata });
222
- await this._constructSpace(spaceMetadata);
234
+ const space = await this._constructSpace(this._ctx, spaceMetadata);
235
+ // Track spaces that were previously active for auto-activation (used in dedicated worker mode).
236
+ if (this._runtimeProps?.autoActivateSpaces && spaceMetadata.state === SpaceState.SPACE_ACTIVE) {
237
+ spacesToActivate.push(space);
238
+ }
223
239
  } catch (err) {
224
240
  log.error('Error loading space', { spaceMetadata, err });
225
241
  }
226
242
  });
227
243
 
244
+ // Auto-activate spaces that were previously active (used in dedicated worker mode after leader changeover).
245
+ for (const space of spacesToActivate) {
246
+ log('auto-activating space', { spaceKey: space.key });
247
+ space.activate(this._ctx).catch((err) => {
248
+ log.error('Error auto-activating space', { spaceKey: space.key, err });
249
+ });
250
+ }
251
+
228
252
  this.updated.emit();
229
253
 
230
254
  log.trace('dxos.echo.data-space-manager.open', Trace.end({ id: this._instanceId }));
231
255
  }
232
256
 
233
257
  @synchronized
234
- protected override async _close(): Promise<void> {
258
+ protected override async _close(ctx: Context): Promise<void> {
235
259
  log('close');
236
260
  for (const space of this._spaces.values()) {
237
- await space.close();
261
+ await space.close(ctx);
238
262
  }
239
263
  this._spaces.clear();
240
264
  }
@@ -243,10 +267,17 @@ export class DataSpaceManager extends Resource {
243
267
  * Creates a new space writing the genesis credentials to the control feed.
244
268
  */
245
269
  @synchronized
246
- async createSpace(options: CreateSpaceOptions = {}): Promise<DataSpace> {
247
- assertArgument(!!options.rootUrl === !!options.documents, 'root url must be required when providing documents');
270
+ @trace.span({ showInBrowserTimeline: true })
271
+ async createSpace(ctx: Context, options: CreateSpaceOptions = {}): Promise<DataSpace> {
272
+ assertArgument(
273
+ !!options.rootUrl === !!options.documents,
274
+ 'options',
275
+ 'root url must be required when providing documents',
276
+ );
248
277
 
249
278
  assertState(this._lifecycleState === LifecycleState.OPEN, 'Not open.');
279
+
280
+ const tags = options.tags ? Array.from(options.tags) : [];
250
281
  const spaceKey = await this._keyring.createKey();
251
282
  const controlFeedKey = await this._keyring.createKey();
252
283
  const dataFeedKey = await this._keyring.createKey();
@@ -259,6 +290,7 @@ export class DataSpaceManager extends Resource {
259
290
  controlFeedKey,
260
291
  dataFeedKey,
261
292
  state: SpaceState.SPACE_ACTIVE,
293
+ tags,
262
294
  };
263
295
 
264
296
  log('creating space...', { spaceId, spaceKey });
@@ -274,7 +306,18 @@ export class DataSpaceManager extends Resource {
274
306
  await Promise.all(
275
307
  Object.entries(options.documents).map(async ([documentId, data]) => {
276
308
  log('creating document...', { documentId });
277
- const newDoc = await this._echoHost.createDoc(data, { preserveHistory: true });
309
+ // TODO(dmaretskyi): Broken types -- the bytes get interpreted as CRDT data.
310
+ const newDoc = await this._echoHost.createDoc(data as any as DatabaseDirectory, {
311
+ preserveHistory: true,
312
+ });
313
+
314
+ // The archived documents might have the spaceKey from the space they were expored from, we need to update it to the new spaceKey.
315
+ if (newDoc.doc().access !== undefined && newDoc.doc().access!.spaceKey !== spaceKey.toHex()) {
316
+ newDoc.change((doc) => {
317
+ doc.access!.spaceKey = spaceKey.toHex();
318
+ });
319
+ }
320
+
278
321
  documentIdMapping[documentId as DocumentId] = newDoc.documentId;
279
322
  }),
280
323
  );
@@ -285,29 +328,37 @@ export class DataSpaceManager extends Resource {
285
328
  let root: DatabaseRoot;
286
329
  if (options.rootUrl) {
287
330
  const newRootDocId = documentIdMapping[interpretAsDocumentId(options.rootUrl)] ?? failedInvariant();
288
- const rootDocHandle = await this._echoHost.loadDoc<DatabaseDirectory>(Context.default(), newRootDocId);
331
+ const rootDocHandle = await this._echoHost.loadDoc<DatabaseDirectory>(ctx, newRootDocId);
289
332
  DatabaseRoot.mapLinks(rootDocHandle, documentIdMapping);
290
333
 
291
- root = await this._echoHost.openSpaceRoot(spaceId, `automerge:${newRootDocId}` as AutomergeUrl);
334
+ root = await this._echoHost.openSpaceRoot(ctx, spaceId, `automerge:${newRootDocId}` as AutomergeUrl);
292
335
  } else {
293
- root = await this._echoHost.createSpaceRoot(spaceKey);
336
+ root = await this._echoHost.createSpaceRoot(ctx, spaceKey);
294
337
  }
338
+ await this._echoHost.flush(ctx);
295
339
 
296
340
  log('constructing space...', { spaceKey });
297
341
 
298
- const space = await this._constructSpace(metadata);
299
- await space.open();
342
+ const space = await this._constructSpace(ctx, metadata);
343
+ await space.open(ctx);
300
344
 
301
345
  log('adding space...', { spaceKey });
302
346
 
303
- const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, root.url);
347
+ const credentials = await spaceGenesis(
348
+ this._keyring,
349
+ this._signingContext,
350
+ space.inner,
351
+ root.url,
352
+ tags,
353
+ options.membershipPolicy,
354
+ );
304
355
  await this._metadataStore.addSpace(metadata);
305
356
 
306
357
  const memberCredential = credentials[1];
307
358
  invariant(getCredentialAssertion(memberCredential)['@type'] === 'dxos.halo.credentials.SpaceMember');
308
359
  await this._signingContext.recordCredential(memberCredential);
309
360
 
310
- await space.initializeDataPipeline();
361
+ await space.initializeDataPipeline(ctx);
311
362
 
312
363
  log('space ready.', { spaceId, spaceKey });
313
364
 
@@ -315,79 +366,30 @@ export class DataSpaceManager extends Resource {
315
366
  return space;
316
367
  }
317
368
 
318
- async isDefaultSpace(space: DataSpace): Promise<boolean> {
319
- if (!space.databaseRoot) {
320
- return false;
321
- }
322
- switch (space.databaseRoot.getVersion()) {
323
- case SpaceDocVersion.CURRENT: {
324
- if (!space.databaseRoot.handle.isReady()) {
325
- log.warn('waiting for space root to be ready', { spaceId: space.id });
326
- await space.databaseRoot.handle.whenReady();
327
- }
328
- const [_, properties] = findInlineObjectOfType(space.databaseRoot.doc()!, TYPE_PROPERTIES) ?? [];
329
- return properties?.data?.[DEFAULT_SPACE_KEY] === this._signingContext.identityKey.toHex();
330
- }
331
- case SpaceDocVersion.LEGACY: {
332
- throw new Error('Legacy space version is not supported');
333
- }
334
-
335
- default:
336
- log.warn('unknown space version', { version: space.databaseRoot.getVersion(), spaceId: space.id });
337
- return false;
338
- }
339
- }
340
-
341
- async createDefaultSpace(): Promise<DataSpace> {
342
- const space = await this.createSpace();
343
- const document = await this._getSpaceRootDocument(space);
344
-
345
- // TODO(dmaretskyi): Better API for low-level data access.
346
- const properties: ObjectStructure = {
347
- system: {
348
- type: encodeReference(getTypeReference(PropertiesType)!),
349
- },
350
- data: {
351
- [DEFAULT_SPACE_KEY]: this._signingContext.identityKey.toHex(),
352
- },
353
- meta: {
354
- keys: [],
355
- },
356
- };
357
-
358
- const propertiesId = ObjectId.random();
359
- document.change((doc: DatabaseDirectory) => {
360
- setDeep(doc, ['objects', propertiesId], properties);
361
- });
362
-
363
- await this._echoHost.flush();
364
- return space;
365
- }
366
-
367
- private async _getSpaceRootDocument(space: DataSpace): Promise<DocHandle<DatabaseDirectory>> {
368
- const automergeIndex = space.automergeSpaceState.rootUrl;
369
- invariant(automergeIndex);
370
- const document = await this._echoHost.automergeRepo.find<DatabaseDirectory>(automergeIndex as any, FIND_PARAMS);
371
- await document.whenReady();
372
- return document;
373
- }
374
-
369
+ /**
370
+ * Accepts an existing space by joining its swarm and initializing the data pipeline.
371
+ * @param ctx - Caller context for cancellation and tracing.
372
+ * @param opts - Space keys and optional timeframes for catch-up.
373
+ */
375
374
  // TODO(burdon): Rename join space.
376
375
  @synchronized
377
- async acceptSpace(opts: AcceptSpaceOptions): Promise<DataSpace> {
376
+ @trace.span({ showInBrowserTimeline: true })
377
+ async acceptSpace(ctx: Context, opts: AcceptSpaceOptions): Promise<DataSpace> {
378
378
  log('accept space', { opts });
379
379
  invariant(this._lifecycleState === LifecycleState.OPEN, 'Not open.');
380
380
  invariant(!this._spaces.has(opts.spaceKey), 'Space already exists.');
381
381
 
382
+ const tags = opts.tags ? Array.from(opts.tags) : [];
382
383
  const metadata: SpaceMetadata = {
383
384
  key: opts.spaceKey,
384
385
  genesisFeedKey: opts.genesisFeedKey,
385
386
  controlTimeframe: opts.controlTimeframe,
386
387
  dataTimeframe: opts.dataTimeframe,
388
+ tags,
387
389
  };
388
390
 
389
- const space = await this._constructSpace(metadata);
390
- await space.open();
391
+ const space = await this._constructSpace(ctx, metadata);
392
+ await space.open(ctx);
391
393
  await this._metadataStore.addSpace(metadata);
392
394
  space.initializeDataPipelineAsync();
393
395
 
@@ -413,6 +415,7 @@ export class DataSpaceManager extends Resource {
413
415
  space.spaceState.membershipChainHeads,
414
416
  options.profile,
415
417
  options.delegationCredentialId,
418
+ space.spaceState.tags,
416
419
  );
417
420
 
418
421
  // TODO(dmaretskyi): Refactor.
@@ -439,8 +442,8 @@ export class DataSpaceManager extends Resource {
439
442
  );
440
443
  }
441
444
 
442
- public async requestSpaceAdmissionCredential(spaceKey: PublicKey): Promise<Credential> {
443
- return this._spaceManager.requestSpaceAdmissionCredential({
445
+ public async requestSpaceAdmissionCredential(ctx: Context, spaceKey: PublicKey): Promise<Credential> {
446
+ return this._spaceManager.requestSpaceAdmissionCredential(ctx, {
444
447
  spaceKey,
445
448
  identityKey: this._signingContext.identityKey,
446
449
  timeout: 15_000,
@@ -453,7 +456,11 @@ export class DataSpaceManager extends Resource {
453
456
  });
454
457
  }
455
458
 
456
- async setSpaceEdgeReplicationSetting(spaceKey: PublicKey, setting: EdgeReplicationSetting): Promise<void> {
459
+ async setSpaceEdgeReplicationSetting(
460
+ ctx: Context,
461
+ spaceKey: PublicKey,
462
+ setting: EdgeReplicationSetting,
463
+ ): Promise<void> {
457
464
  const space = this._spaces.get(spaceKey);
458
465
  invariant(space, 'Space not found.');
459
466
 
@@ -465,7 +472,7 @@ export class DataSpaceManager extends Resource {
465
472
  await this._echoEdgeReplicator?.disconnectFromSpace(space.id);
466
473
  break;
467
474
  case EdgeReplicationSetting.ENABLED:
468
- await this._echoEdgeReplicator?.connectToSpace(space.id);
475
+ await this._echoEdgeReplicator?.connectToSpace(ctx, space.id);
469
476
  break;
470
477
  }
471
478
  }
@@ -473,14 +480,14 @@ export class DataSpaceManager extends Resource {
473
480
  space.stateUpdate.emit();
474
481
  }
475
482
 
476
- private async _constructSpace(metadata: SpaceMetadata): Promise<DataSpace> {
483
+ private async _constructSpace(ctx: Context, metadata: SpaceMetadata): Promise<DataSpace> {
477
484
  log('construct space', { metadata });
478
485
  const gossip = new Gossip({
479
486
  localPeerId: this._signingContext.deviceKey,
480
487
  });
481
488
  const presence = new Presence({
482
- announceInterval: this._runtimeParams?.spaceMemberPresenceAnnounceInterval ?? PRESENCE_ANNOUNCE_INTERVAL,
483
- offlineTimeout: this._runtimeParams?.spaceMemberPresenceOfflineTimeout ?? PRESENCE_OFFLINE_TIMEOUT,
489
+ announceInterval: this._runtimeProps?.spaceMemberPresenceAnnounceInterval ?? PRESENCE_ANNOUNCE_INTERVAL,
490
+ offlineTimeout: this._runtimeProps?.spaceMemberPresenceOfflineTimeout ?? PRESENCE_OFFLINE_TIMEOUT,
484
491
  identityKey: this._signingContext.identityKey,
485
492
  gossip,
486
493
  });
@@ -563,15 +570,16 @@ export class DataSpaceManager extends Resource {
563
570
  },
564
571
  },
565
572
  cache: metadata.cache,
573
+ tags: metadata.tags,
566
574
  edgeConnection: this._edgeConnection,
567
575
  edgeHttpClient: this._edgeHttpClient,
568
576
  edgeFeatures: this._edgeFeatures,
569
- activeEdgeNotarizationPollingInterval: this._runtimeParams?.activeEdgeNotarizationPollingInterval,
577
+ activeEdgeNotarizationPollingInterval: this._runtimeProps?.activeEdgeNotarizationPollingInterval,
570
578
  });
571
579
  dataSpace.postOpen.append(async () => {
572
580
  const setting = dataSpace.getEdgeReplicationSetting();
573
581
  if (!setting || setting === EdgeReplicationSetting.ENABLED) {
574
- await this._echoEdgeReplicator?.connectToSpace(dataSpace.id);
582
+ await this._echoEdgeReplicator?.connectToSpace(ctx, dataSpace.id);
575
583
  } else if (this._echoEdgeReplicator) {
576
584
  log('not connecting EchoEdgeReplicator because of EdgeReplicationSetting', { spaceId: dataSpace.id });
577
585
  }
@@ -668,7 +676,7 @@ export class DataSpaceManager extends Resource {
668
676
  invitations: Array<[PublicKey, DelegateSpaceInvitation]>,
669
677
  ): Promise<void> {
670
678
  const tasks = invitations.map(([credentialId, invitation]) => {
671
- return this._invitationsManager.createInvitation({
679
+ return this._invitationsManager.createInvitation(this._ctx, {
672
680
  type: Invitation.Type.DELEGATED,
673
681
  kind: Invitation.Kind.SPACE,
674
682
  spaceKey: space.key,