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