@dxos/client-services 0.8.3 → 0.8.4-main.1068cf700f
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-NQSC7HOE.mjs +22 -0
- package/dist/lib/browser/chunk-NQSC7HOE.mjs.map +7 -0
- package/dist/lib/browser/{chunk-LBG3C332.mjs → chunk-OZGICTH7.mjs} +3864 -3786
- package/dist/lib/browser/chunk-OZGICTH7.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/index.mjs +474 -80
- 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 +93 -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 +126 -0
- package/dist/lib/browser/packlets/locks/browser.mjs.map +7 -0
- package/dist/lib/browser/packlets/locks/node.mjs +66 -0
- package/dist/lib/browser/packlets/locks/node.mjs.map +7 -0
- package/dist/lib/browser/testing/index.mjs +39 -27
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- 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-PKEGMOQ4.mjs +22 -0
- package/dist/lib/node-esm/chunk-PKEGMOQ4.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-SKGQLRKS.mjs → chunk-RXHISBCS.mjs} +3551 -3341
- package/dist/lib/node-esm/chunk-RXHISBCS.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +474 -80
- 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 +93 -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 +126 -0
- package/dist/lib/node-esm/packlets/locks/browser.mjs.map +7 -0
- package/dist/lib/node-esm/packlets/locks/node.mjs +66 -0
- package/dist/lib/node-esm/packlets/locks/node.mjs.map +7 -0
- package/dist/lib/node-esm/testing/index.mjs +39 -27
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/packlets/agents/edge-agent-service.d.ts +1 -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 +20 -20
- package/dist/types/src/packlets/devtools/devtools.d.ts.map +1 -1
- package/dist/types/src/packlets/devtools/feeds.d.ts +1 -1
- package/dist/types/src/packlets/devtools/feeds.d.ts.map +1 -1
- package/dist/types/src/packlets/devtools/network.d.ts +1 -1
- package/dist/types/src/packlets/devtools/network.d.ts.map +1 -1
- package/dist/types/src/packlets/diagnostics/browser-diagnostics-broadcast.d.ts +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 +1 -1
- package/dist/types/src/packlets/diagnostics/diagnostics-broadcast.d.ts.map +1 -1
- package/dist/types/src/packlets/diagnostics/diagnostics.d.ts +1 -1
- 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 +1 -1
- package/dist/types/src/packlets/identity/contacts-service.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/default-space-state-machine.d.ts +3 -3
- package/dist/types/src/packlets/identity/default-space-state-machine.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity-manager.d.ts +5 -5
- package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts +2 -2
- package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity-service.d.ts +1 -1
- package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity.d.ts +3 -3
- package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts +4 -4
- 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/index.d.ts +1 -1
- package/dist/types/src/packlets/invitations/index.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 +3 -4
- package/dist/types/src/packlets/invitations/invitation-protocol.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.map +1 -1
- package/dist/types/src/packlets/invitations/invitations-service.d.ts +1 -1
- package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +3 -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/index.d.ts +2 -2
- package/dist/types/src/packlets/locks/index.d.ts.map +1 -1
- package/dist/types/src/packlets/logging/logging-service.d.ts +5 -1
- package/dist/types/src/packlets/logging/logging-service.d.ts.map +1 -1
- package/dist/types/src/packlets/network/network-service.d.ts +2 -2
- package/dist/types/src/packlets/network/network-service.d.ts.map +1 -1
- package/dist/types/src/packlets/services/client-rpc-server.d.ts +2 -2
- package/dist/types/src/packlets/services/client-rpc-server.d.ts.map +1 -1
- package/dist/types/src/packlets/services/feed-syncer.d.ts +41 -0
- package/dist/types/src/packlets/services/feed-syncer.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 +14 -8
- package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-host.d.ts +20 -6
- package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
- package/dist/types/src/packlets/space-export/space-archive-writer.d.ts +1 -1
- package/dist/types/src/packlets/space-export/space-archive-writer.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/automerge-space-state.d.ts +1 -1
- 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 +12 -7
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space.d.ts +6 -6
- 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/notarization-plugin.d.ts +6 -6
- package/dist/types/src/packlets/spaces/notarization-plugin.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/spaces-service.d.ts +2 -2
- package/dist/types/src/packlets/spaces/spaces-service.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/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/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 +8 -7
- package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/packlets/worker/worker-runtime.d.ts +31 -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 -2
- package/dist/types/src/packlets/worker/worker-session.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 +72 -48
- package/src/packlets/agents/edge-agent-manager.ts +2 -2
- package/src/packlets/agents/edge-agent-service.ts +13 -3
- package/src/packlets/devices/devices-service.test.ts +4 -3
- package/src/packlets/devices/devices-service.ts +2 -2
- package/src/packlets/devtools/devtools.ts +30 -29
- package/src/packlets/devtools/feeds.ts +2 -2
- package/src/packlets/devtools/network.ts +1 -1
- package/src/packlets/diagnostics/browser-diagnostics-broadcast.ts +1 -1
- package/src/packlets/diagnostics/diagnostics-broadcast.ts +1 -1
- package/src/packlets/diagnostics/diagnostics-collector.ts +1 -1
- package/src/packlets/diagnostics/diagnostics.ts +1 -1
- package/src/packlets/diagnostics/index.ts +1 -1
- package/src/packlets/identity/authenticator.node.test.ts +1 -1
- package/src/packlets/identity/authenticator.ts +3 -3
- package/src/packlets/identity/contacts-service.ts +3 -2
- package/src/packlets/identity/default-space-state-machine.ts +3 -3
- package/src/packlets/identity/identity-manager.test.ts +3 -3
- package/src/packlets/identity/identity-manager.ts +9 -9
- package/src/packlets/identity/identity-recovery-manager.ts +2 -2
- package/src/packlets/identity/identity-service.test.ts +3 -2
- package/src/packlets/identity/identity-service.ts +2 -1
- package/src/packlets/identity/identity.test.ts +9 -9
- package/src/packlets/identity/identity.ts +9 -8
- package/src/packlets/invitations/device-invitation-protocol.test.ts +4 -4
- package/src/packlets/invitations/device-invitation-protocol.ts +6 -5
- package/src/packlets/invitations/edge-invitation-handler.ts +1 -1
- package/src/packlets/invitations/index.ts +1 -1
- package/src/packlets/invitations/invitation-guest-extenstion.ts +7 -5
- package/src/packlets/invitations/invitation-host-extension.ts +8 -6
- package/src/packlets/invitations/invitation-protocol.ts +3 -4
- package/src/packlets/invitations/invitations-handler.test.ts +302 -292
- package/src/packlets/invitations/invitations-handler.ts +10 -10
- package/src/packlets/invitations/invitations-manager.ts +3 -3
- package/src/packlets/invitations/invitations-service.ts +1 -1
- package/src/packlets/invitations/space-invitation-protocol.test.ts +9 -9
- package/src/packlets/invitations/space-invitation-protocol.ts +10 -15
- package/src/packlets/invitations/utils.ts +1 -1
- package/src/packlets/locks/browser.ts +1 -1
- package/src/packlets/locks/index.ts +2 -2
- package/src/packlets/logging/logging-service.ts +8 -3
- package/src/packlets/logging/logging.test.ts +1 -1
- package/src/packlets/network/network-service.test.ts +4 -3
- package/src/packlets/network/network-service.ts +2 -2
- package/src/packlets/services/client-rpc-server.ts +5 -5
- package/src/packlets/services/feed-syncer.ts +227 -0
- package/src/packlets/services/platform.ts +7 -1
- package/src/packlets/services/service-context.test.ts +1 -1
- package/src/packlets/services/service-context.ts +56 -29
- package/src/packlets/services/service-host.test.ts +3 -2
- package/src/packlets/services/service-host.ts +78 -29
- package/src/packlets/services/service-registry.test.ts +2 -1
- package/src/packlets/space-export/space-archive-reader.ts +2 -2
- package/src/packlets/space-export/space-archive-writer.ts +7 -5
- package/src/packlets/space-export/tar.test.ts +1 -1
- package/src/packlets/spaces/automerge-space-state.ts +1 -1
- package/src/packlets/spaces/data-space-manager.ts +76 -36
- package/src/packlets/spaces/data-space.ts +18 -13
- package/src/packlets/spaces/edge-feed-replicator.test.ts +3 -3
- package/src/packlets/spaces/edge-feed-replicator.ts +4 -4
- package/src/packlets/spaces/epoch-migrations.ts +2 -2
- package/src/packlets/spaces/notarization-plugin.test.ts +3 -3
- package/src/packlets/spaces/notarization-plugin.ts +11 -11
- package/src/packlets/spaces/spaces-service.test.ts +3 -2
- package/src/packlets/spaces/spaces-service.ts +27 -23
- package/src/packlets/storage/profile-archive.ts +1 -1
- package/src/packlets/storage/storage.ts +7 -8
- package/src/packlets/system/system-service.test.ts +1 -1
- package/src/packlets/system/system-service.ts +4 -4
- package/src/packlets/testing/invitation-utils.ts +8 -5
- package/src/packlets/testing/test-builder.ts +39 -13
- package/src/packlets/worker/worker-runtime.ts +151 -12
- package/src/packlets/worker/worker-session.ts +7 -7
- package/src/version.ts +1 -5
- package/README.yml +0 -5
- package/dist/lib/browser/chunk-LBG3C332.mjs.map +0 -7
- package/dist/lib/node/chunk-LMGLGOUU.cjs +0 -9311
- package/dist/lib/node/chunk-LMGLGOUU.cjs.map +0 -7
- package/dist/lib/node/index.cjs +0 -437
- package/dist/lib/node/index.cjs.map +0 -7
- package/dist/lib/node/meta.json +0 -1
- package/dist/lib/node/testing/index.cjs +0 -452
- package/dist/lib/node/testing/index.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-SKGQLRKS.mjs.map +0 -7
|
@@ -3,66 +3,67 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { type Doc } from '@automerge/automerge';
|
|
6
|
-
import {
|
|
6
|
+
import { type AutomergeUrl, type DocHandle, 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
|
-
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';
|
|
19
|
+
import { getSchemaDXN } from '@dxos/echo/internal';
|
|
18
20
|
import {
|
|
21
|
+
AuthStatus,
|
|
22
|
+
CredentialServerExtension,
|
|
19
23
|
DatabaseRoot,
|
|
20
|
-
findInlineObjectOfType,
|
|
21
24
|
type EchoEdgeReplicator,
|
|
22
25
|
type EchoHost,
|
|
23
|
-
AuthStatus,
|
|
24
|
-
CredentialServerExtension,
|
|
25
26
|
type MeshEchoReplicator,
|
|
26
27
|
type MetadataStore,
|
|
27
28
|
type Space,
|
|
28
29
|
type SpaceManager,
|
|
29
30
|
type SpaceProtocol,
|
|
30
31
|
type SpaceProtocolSession,
|
|
31
|
-
|
|
32
|
+
findInlineObjectOfType,
|
|
32
33
|
} from '@dxos/echo-pipeline';
|
|
33
34
|
import {
|
|
35
|
+
type DatabaseDirectory,
|
|
36
|
+
EncodedReference,
|
|
37
|
+
type ObjectStructure,
|
|
34
38
|
SpaceDocVersion,
|
|
35
39
|
createIdFromSpaceKey,
|
|
36
|
-
encodeReference,
|
|
37
|
-
type ObjectStructure,
|
|
38
|
-
type DatabaseDirectory,
|
|
39
40
|
} from '@dxos/echo-protocol';
|
|
40
|
-
import { ObjectId, getTypeReference } from '@dxos/echo-schema';
|
|
41
41
|
import type { EdgeConnection, EdgeHttpClient } from '@dxos/edge-client';
|
|
42
|
-
import {
|
|
42
|
+
import { type FeedStore, writeMessages } from '@dxos/feed-store';
|
|
43
43
|
import { assertArgument, assertState, failedInvariant, invariant } from '@dxos/invariant';
|
|
44
44
|
import { type Keyring } from '@dxos/keyring';
|
|
45
|
-
import { PublicKey, type SpaceId } from '@dxos/keys';
|
|
45
|
+
import { ObjectId, PublicKey, type SpaceId } from '@dxos/keys';
|
|
46
46
|
import { log } from '@dxos/log';
|
|
47
47
|
import { AlreadyJoinedError, trace as Trace } from '@dxos/protocols';
|
|
48
48
|
import { Invitation, SpaceState } from '@dxos/protocols/proto/dxos/client/services';
|
|
49
49
|
import { type Runtime } from '@dxos/protocols/proto/dxos/config';
|
|
50
50
|
import { type FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';
|
|
51
|
-
import { type SpaceMetadata
|
|
52
|
-
import {
|
|
51
|
+
import { EdgeReplicationSetting, type SpaceMetadata } from '@dxos/protocols/proto/dxos/echo/metadata';
|
|
52
|
+
import { type Credential, type ProfileDocument, SpaceMember } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
53
53
|
import { type DelegateSpaceInvitation } from '@dxos/protocols/proto/dxos/halo/invitations';
|
|
54
54
|
import { type PeerState } from '@dxos/protocols/proto/dxos/mesh/presence';
|
|
55
55
|
import { type Teleport } from '@dxos/teleport';
|
|
56
56
|
import { Gossip, Presence } from '@dxos/teleport-extension-gossip';
|
|
57
57
|
import { type Timeframe } from '@dxos/timeframe';
|
|
58
58
|
import { trace } from '@dxos/tracing';
|
|
59
|
-
import { ComplexMap,
|
|
59
|
+
import { ComplexMap, deferFunction, forEachAsync, setDeep } from '@dxos/util';
|
|
60
60
|
|
|
61
|
-
import { DataSpace } from './data-space';
|
|
62
|
-
import { spaceGenesis } from './genesis';
|
|
63
61
|
import { createAuthProvider } from '../identity';
|
|
64
62
|
import { type InvitationsManager } from '../invitations';
|
|
65
63
|
|
|
64
|
+
import { DataSpace } from './data-space';
|
|
65
|
+
import { spaceGenesis } from './genesis';
|
|
66
|
+
|
|
66
67
|
const PRESENCE_ANNOUNCE_INTERVAL = 10_000;
|
|
67
68
|
const PRESENCE_OFFLINE_TIMEOUT = 20_000;
|
|
68
69
|
|
|
@@ -103,7 +104,7 @@ export type AdmitMemberOptions = {
|
|
|
103
104
|
delegationCredentialId?: PublicKey;
|
|
104
105
|
};
|
|
105
106
|
|
|
106
|
-
export type
|
|
107
|
+
export type DataSpaceManagerProps = {
|
|
107
108
|
spaceManager: SpaceManager;
|
|
108
109
|
metadataStore: MetadataStore;
|
|
109
110
|
keyring: Keyring;
|
|
@@ -115,15 +116,20 @@ export type DataSpaceManagerParams = {
|
|
|
115
116
|
edgeHttpClient?: EdgeHttpClient;
|
|
116
117
|
meshReplicator?: MeshEchoReplicator;
|
|
117
118
|
echoEdgeReplicator?: EchoEdgeReplicator;
|
|
118
|
-
|
|
119
|
+
runtimeProps?: DataSpaceManagerRuntimeProps;
|
|
119
120
|
edgeFeatures?: Runtime.Client.EdgeFeatures;
|
|
120
121
|
};
|
|
121
122
|
|
|
122
|
-
export type
|
|
123
|
+
export type DataSpaceManagerRuntimeProps = {
|
|
123
124
|
spaceMemberPresenceAnnounceInterval?: number;
|
|
124
125
|
spaceMemberPresenceOfflineTimeout?: number;
|
|
125
126
|
activeEdgeNotarizationPollingInterval?: number;
|
|
126
127
|
disableP2pReplication?: boolean;
|
|
128
|
+
/**
|
|
129
|
+
* If true, spaces that were previously SPACE_ACTIVE will be automatically activated on startup.
|
|
130
|
+
* This is used in dedicated worker mode to restore space state after leader changeover.
|
|
131
|
+
*/
|
|
132
|
+
autoActivateSpaces?: boolean;
|
|
127
133
|
};
|
|
128
134
|
|
|
129
135
|
export type CreateSpaceOptions = {
|
|
@@ -151,9 +157,9 @@ export class DataSpaceManager extends Resource {
|
|
|
151
157
|
private readonly _edgeFeatures?: Runtime.Client.EdgeFeatures = undefined;
|
|
152
158
|
private readonly _meshReplicator?: MeshEchoReplicator = undefined;
|
|
153
159
|
private readonly _echoEdgeReplicator?: EchoEdgeReplicator = undefined;
|
|
154
|
-
private readonly
|
|
160
|
+
private readonly _runtimeProps?: DataSpaceManagerRuntimeProps = undefined;
|
|
155
161
|
|
|
156
|
-
constructor(params:
|
|
162
|
+
constructor(params: DataSpaceManagerProps) {
|
|
157
163
|
super();
|
|
158
164
|
|
|
159
165
|
this._spaceManager = params.spaceManager;
|
|
@@ -168,7 +174,7 @@ export class DataSpaceManager extends Resource {
|
|
|
168
174
|
this._edgeFeatures = params.edgeFeatures;
|
|
169
175
|
this._echoEdgeReplicator = params.echoEdgeReplicator;
|
|
170
176
|
this._edgeHttpClient = params.edgeHttpClient;
|
|
171
|
-
this.
|
|
177
|
+
this._runtimeProps = params.runtimeProps;
|
|
172
178
|
|
|
173
179
|
trace.diagnostic({
|
|
174
180
|
id: 'spaces',
|
|
@@ -178,12 +184,12 @@ export class DataSpaceManager extends Resource {
|
|
|
178
184
|
Array.from(this._spaces.values()).map(async (space) => {
|
|
179
185
|
const rootUrl = space.automergeSpaceState.rootUrl;
|
|
180
186
|
const rootHandle = rootUrl
|
|
181
|
-
? await this._echoHost.
|
|
187
|
+
? await this._echoHost.loadDoc<Doc<DatabaseDirectory>>(Context.default(), rootUrl as AutomergeUrl)
|
|
182
188
|
: undefined;
|
|
183
189
|
await rootHandle?.whenReady();
|
|
184
190
|
const rootDoc = rootHandle?.doc();
|
|
185
191
|
|
|
186
|
-
const properties = rootDoc && findInlineObjectOfType(rootDoc,
|
|
192
|
+
const properties = rootDoc && findInlineObjectOfType(rootDoc, Type.getTypename(SpaceProperties));
|
|
187
193
|
|
|
188
194
|
return {
|
|
189
195
|
key: space.key.toHex(),
|
|
@@ -216,15 +222,28 @@ export class DataSpaceManager extends Resource {
|
|
|
216
222
|
log.trace('dxos.echo.data-space-manager.open', Trace.begin({ id: this._instanceId }));
|
|
217
223
|
log('metadata loaded', { spaces: this._metadataStore.spaces.length });
|
|
218
224
|
|
|
225
|
+
const spacesToActivate: DataSpace[] = [];
|
|
219
226
|
await forEachAsync(this._metadataStore.spaces, async (spaceMetadata) => {
|
|
220
227
|
try {
|
|
221
228
|
log('load space', { spaceMetadata });
|
|
222
|
-
await this._constructSpace(spaceMetadata);
|
|
229
|
+
const space = await this._constructSpace(spaceMetadata);
|
|
230
|
+
// Track spaces that were previously active for auto-activation (used in dedicated worker mode).
|
|
231
|
+
if (this._runtimeProps?.autoActivateSpaces && spaceMetadata.state === SpaceState.SPACE_ACTIVE) {
|
|
232
|
+
spacesToActivate.push(space);
|
|
233
|
+
}
|
|
223
234
|
} catch (err) {
|
|
224
235
|
log.error('Error loading space', { spaceMetadata, err });
|
|
225
236
|
}
|
|
226
237
|
});
|
|
227
238
|
|
|
239
|
+
// Auto-activate spaces that were previously active (used in dedicated worker mode after leader changeover).
|
|
240
|
+
for (const space of spacesToActivate) {
|
|
241
|
+
log('auto-activating space', { spaceKey: space.key });
|
|
242
|
+
space.activate().catch((err) => {
|
|
243
|
+
log.error('Error auto-activating space', { spaceKey: space.key, err });
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
|
|
228
247
|
this.updated.emit();
|
|
229
248
|
|
|
230
249
|
log.trace('dxos.echo.data-space-manager.open', Trace.end({ id: this._instanceId }));
|
|
@@ -244,7 +263,11 @@ export class DataSpaceManager extends Resource {
|
|
|
244
263
|
*/
|
|
245
264
|
@synchronized
|
|
246
265
|
async createSpace(options: CreateSpaceOptions = {}): Promise<DataSpace> {
|
|
247
|
-
assertArgument(
|
|
266
|
+
assertArgument(
|
|
267
|
+
!!options.rootUrl === !!options.documents,
|
|
268
|
+
'options',
|
|
269
|
+
'root url must be required when providing documents',
|
|
270
|
+
);
|
|
248
271
|
|
|
249
272
|
assertState(this._lifecycleState === LifecycleState.OPEN, 'Not open.');
|
|
250
273
|
const spaceKey = await this._keyring.createKey();
|
|
@@ -274,7 +297,18 @@ export class DataSpaceManager extends Resource {
|
|
|
274
297
|
await Promise.all(
|
|
275
298
|
Object.entries(options.documents).map(async ([documentId, data]) => {
|
|
276
299
|
log('creating document...', { documentId });
|
|
277
|
-
|
|
300
|
+
// TODO(dmaretskyi): Broken types -- the bytes get interpreted as CRDT data.
|
|
301
|
+
const newDoc = await this._echoHost.createDoc(data as any as DatabaseDirectory, {
|
|
302
|
+
preserveHistory: true,
|
|
303
|
+
});
|
|
304
|
+
|
|
305
|
+
// The archived documents might have the spaceKey from the space they were expored from, we need to update it to the new spaceKey.
|
|
306
|
+
if (newDoc.doc().access !== undefined && newDoc.doc().access!.spaceKey !== spaceKey.toHex()) {
|
|
307
|
+
newDoc.change((doc) => {
|
|
308
|
+
doc.access!.spaceKey = spaceKey.toHex();
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
|
|
278
312
|
documentIdMapping[documentId as DocumentId] = newDoc.documentId;
|
|
279
313
|
}),
|
|
280
314
|
);
|
|
@@ -292,6 +326,7 @@ export class DataSpaceManager extends Resource {
|
|
|
292
326
|
} else {
|
|
293
327
|
root = await this._echoHost.createSpaceRoot(spaceKey);
|
|
294
328
|
}
|
|
329
|
+
await this._echoHost.flush();
|
|
295
330
|
|
|
296
331
|
log('constructing space...', { spaceKey });
|
|
297
332
|
|
|
@@ -325,9 +360,12 @@ export class DataSpaceManager extends Resource {
|
|
|
325
360
|
log.warn('waiting for space root to be ready', { spaceId: space.id });
|
|
326
361
|
await space.databaseRoot.handle.whenReady();
|
|
327
362
|
}
|
|
328
|
-
|
|
363
|
+
|
|
364
|
+
const [_, properties] =
|
|
365
|
+
findInlineObjectOfType(space.databaseRoot.doc()!, Type.getTypename(SpaceProperties)) ?? [];
|
|
329
366
|
return properties?.data?.[DEFAULT_SPACE_KEY] === this._signingContext.identityKey.toHex();
|
|
330
367
|
}
|
|
368
|
+
|
|
331
369
|
case SpaceDocVersion.LEGACY: {
|
|
332
370
|
throw new Error('Legacy space version is not supported');
|
|
333
371
|
}
|
|
@@ -345,7 +383,7 @@ export class DataSpaceManager extends Resource {
|
|
|
345
383
|
// TODO(dmaretskyi): Better API for low-level data access.
|
|
346
384
|
const properties: ObjectStructure = {
|
|
347
385
|
system: {
|
|
348
|
-
type:
|
|
386
|
+
type: EncodedReference.fromDXN(getSchemaDXN(SpaceProperties)!),
|
|
349
387
|
},
|
|
350
388
|
data: {
|
|
351
389
|
[DEFAULT_SPACE_KEY]: this._signingContext.identityKey.toHex(),
|
|
@@ -367,7 +405,9 @@ export class DataSpaceManager extends Resource {
|
|
|
367
405
|
private async _getSpaceRootDocument(space: DataSpace): Promise<DocHandle<DatabaseDirectory>> {
|
|
368
406
|
const automergeIndex = space.automergeSpaceState.rootUrl;
|
|
369
407
|
invariant(automergeIndex);
|
|
370
|
-
const document = await this._echoHost.
|
|
408
|
+
const document = await this._echoHost.loadDoc<DatabaseDirectory>(Context.default(), automergeIndex as any, {
|
|
409
|
+
fetchFromNetwork: true,
|
|
410
|
+
});
|
|
371
411
|
await document.whenReady();
|
|
372
412
|
return document;
|
|
373
413
|
}
|
|
@@ -479,8 +519,8 @@ export class DataSpaceManager extends Resource {
|
|
|
479
519
|
localPeerId: this._signingContext.deviceKey,
|
|
480
520
|
});
|
|
481
521
|
const presence = new Presence({
|
|
482
|
-
announceInterval: this.
|
|
483
|
-
offlineTimeout: this.
|
|
522
|
+
announceInterval: this._runtimeProps?.spaceMemberPresenceAnnounceInterval ?? PRESENCE_ANNOUNCE_INTERVAL,
|
|
523
|
+
offlineTimeout: this._runtimeProps?.spaceMemberPresenceOfflineTimeout ?? PRESENCE_OFFLINE_TIMEOUT,
|
|
484
524
|
identityKey: this._signingContext.identityKey,
|
|
485
525
|
gossip,
|
|
486
526
|
});
|
|
@@ -566,7 +606,7 @@ export class DataSpaceManager extends Resource {
|
|
|
566
606
|
edgeConnection: this._edgeConnection,
|
|
567
607
|
edgeHttpClient: this._edgeHttpClient,
|
|
568
608
|
edgeFeatures: this._edgeFeatures,
|
|
569
|
-
activeEdgeNotarizationPollingInterval: this.
|
|
609
|
+
activeEdgeNotarizationPollingInterval: this._runtimeProps?.activeEdgeNotarizationPollingInterval,
|
|
570
610
|
});
|
|
571
611
|
dataSpace.postOpen.append(async () => {
|
|
572
612
|
const setting = dataSpace.getEdgeReplicationSetting();
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { save } from '@automerge/automerge';
|
|
6
|
-
import { type DocHandle } from '@automerge/automerge-repo';
|
|
6
|
+
import { type AutomergeUrl, type DocHandle } from '@automerge/automerge-repo';
|
|
7
7
|
|
|
8
8
|
import { Event, Mutex, scheduleTask, sleep, synchronized, trackLeaks } from '@dxos/async';
|
|
9
9
|
import { AUTH_TIMEOUT } from '@dxos/client-protocol';
|
|
@@ -11,14 +11,13 @@ import { Context, ContextDisposedError, cancelWithContext } from '@dxos/context'
|
|
|
11
11
|
import type { SpecificCredential } from '@dxos/credentials';
|
|
12
12
|
import { timed, warnAfterTimeout } from '@dxos/debug';
|
|
13
13
|
import {
|
|
14
|
-
type EchoHost,
|
|
15
14
|
type DatabaseRoot,
|
|
16
|
-
|
|
15
|
+
type EchoHost,
|
|
17
16
|
type MetadataStore,
|
|
18
17
|
type Space,
|
|
19
|
-
|
|
18
|
+
createMappedFeedWriter,
|
|
20
19
|
} from '@dxos/echo-pipeline';
|
|
21
|
-
import {
|
|
20
|
+
import { type DatabaseDirectory, SpaceDocVersion } from '@dxos/echo-protocol';
|
|
22
21
|
import type { EdgeConnection, EdgeHttpClient } from '@dxos/edge-client';
|
|
23
22
|
import { type FeedStore, type FeedWrapper } from '@dxos/feed-store';
|
|
24
23
|
import { failedInvariant, invariant } from '@dxos/invariant';
|
|
@@ -28,31 +27,32 @@ import { log } from '@dxos/log';
|
|
|
28
27
|
import { CancelledError, SystemError } from '@dxos/protocols';
|
|
29
28
|
import {
|
|
30
29
|
type CreateEpochRequest,
|
|
31
|
-
SpaceState,
|
|
32
30
|
type Space as SpaceProto,
|
|
31
|
+
SpaceState,
|
|
33
32
|
} from '@dxos/protocols/proto/dxos/client/services';
|
|
34
33
|
import { type Runtime } from '@dxos/protocols/proto/dxos/config';
|
|
35
34
|
import { type FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';
|
|
36
35
|
import { type SpaceCache } from '@dxos/protocols/proto/dxos/echo/metadata';
|
|
37
36
|
import {
|
|
38
37
|
AdmittedFeed,
|
|
39
|
-
SpaceMember,
|
|
40
38
|
type Credential,
|
|
41
39
|
type Epoch,
|
|
42
40
|
type ProfileDocument,
|
|
41
|
+
SpaceMember,
|
|
43
42
|
} from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
44
43
|
import { type GossipMessage } from '@dxos/protocols/proto/dxos/mesh/teleport/gossip';
|
|
45
44
|
import { type Gossip, type Presence } from '@dxos/teleport-extension-gossip';
|
|
46
45
|
import { Timeframe } from '@dxos/timeframe';
|
|
47
46
|
import { trace } from '@dxos/tracing';
|
|
48
|
-
import { CallbackCollection, ComplexSet
|
|
47
|
+
import { type AsyncCallback, CallbackCollection, ComplexSet } from '@dxos/util';
|
|
48
|
+
|
|
49
|
+
import { TrustedKeySetAuthVerifier } from '../identity';
|
|
49
50
|
|
|
50
51
|
import { AutomergeSpaceState } from './automerge-space-state';
|
|
51
52
|
import { type SigningContext } from './data-space-manager';
|
|
52
53
|
import { EdgeFeedReplicator } from './edge-feed-replicator';
|
|
53
54
|
import { runEpochMigration } from './epoch-migrations';
|
|
54
55
|
import { NotarizationPlugin } from './notarization-plugin';
|
|
55
|
-
import { TrustedKeySetAuthVerifier } from '../identity';
|
|
56
56
|
|
|
57
57
|
export type DataSpaceCallbacks = {
|
|
58
58
|
/**
|
|
@@ -71,7 +71,7 @@ export type DataSpaceCallbacks = {
|
|
|
71
71
|
beforeClose?: () => Promise<void>;
|
|
72
72
|
};
|
|
73
73
|
|
|
74
|
-
export type
|
|
74
|
+
export type DataSpaceProps = {
|
|
75
75
|
initialState: SpaceState;
|
|
76
76
|
inner: Space;
|
|
77
77
|
metadataStore: MetadataStore;
|
|
@@ -135,7 +135,7 @@ export class DataSpace {
|
|
|
135
135
|
|
|
136
136
|
public metrics: SpaceProto.Metrics = {};
|
|
137
137
|
|
|
138
|
-
constructor(params:
|
|
138
|
+
constructor(params: DataSpaceProps) {
|
|
139
139
|
this._inner = params.inner;
|
|
140
140
|
this._inner.stateUpdate.on(this._ctx, () => this.stateUpdate.emit());
|
|
141
141
|
|
|
@@ -330,7 +330,7 @@ export class DataSpace {
|
|
|
330
330
|
@trace.span({ showInBrowserTimeline: true })
|
|
331
331
|
async initializeDataPipeline(): Promise<void> {
|
|
332
332
|
if (this._state !== SpaceState.SPACE_CONTROL_ONLY) {
|
|
333
|
-
throw new SystemError('Invalid operation');
|
|
333
|
+
throw new SystemError({ message: 'Invalid operation' });
|
|
334
334
|
}
|
|
335
335
|
|
|
336
336
|
this._state = SpaceState.SPACE_INITIALIZING;
|
|
@@ -450,6 +450,9 @@ export class DataSpace {
|
|
|
450
450
|
|
|
451
451
|
log('credentials notarized');
|
|
452
452
|
} catch (err) {
|
|
453
|
+
if (err instanceof ContextDisposedError) {
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
453
456
|
log.error('error notarizing credentials for feed admission', err);
|
|
454
457
|
throw err;
|
|
455
458
|
}
|
|
@@ -470,7 +473,9 @@ export class DataSpace {
|
|
|
470
473
|
await warnAfterTimeout(5_000, 'Automerge root doc load timeout (DataSpace)', async () => {
|
|
471
474
|
handle = await cancelWithContext(
|
|
472
475
|
this._ctx,
|
|
473
|
-
this._echoHost.
|
|
476
|
+
this._echoHost.loadDoc<DatabaseDirectory>(Context.default(), rootUrl as AutomergeUrl, {
|
|
477
|
+
fetchFromNetwork: true,
|
|
478
|
+
}),
|
|
474
479
|
);
|
|
475
480
|
await cancelWithContext(this._ctx, handle.whenReady());
|
|
476
481
|
});
|
|
@@ -6,10 +6,10 @@ import { decode as decodeCbor, encode as encodeCbor } from 'cbor-x';
|
|
|
6
6
|
import { getPort } from 'get-port-please';
|
|
7
7
|
import { describe, expect, onTestFinished, test, vi } from 'vitest';
|
|
8
8
|
|
|
9
|
-
import {
|
|
9
|
+
import { Trigger, sleep } from '@dxos/async';
|
|
10
10
|
import { Context } from '@dxos/context';
|
|
11
11
|
import { valueEncoding } from '@dxos/echo-pipeline';
|
|
12
|
-
import {
|
|
12
|
+
import { EdgeClient, EdgeIdentityChangedError, createEphemeralEdgeIdentity } from '@dxos/edge-client';
|
|
13
13
|
import { createTestEdgeWsServer } from '@dxos/edge-client/testing';
|
|
14
14
|
import { FeedFactory, FeedStore, type FeedWrapper } from '@dxos/feed-store';
|
|
15
15
|
import { Keyring } from '@dxos/keyring';
|
|
@@ -45,7 +45,7 @@ describe('EdgeFeedReplicator', () => {
|
|
|
45
45
|
const { endpoint, admitConnection, messageSink } = await createEdge();
|
|
46
46
|
const { messenger } = await createClient(endpoint);
|
|
47
47
|
admitConnection.wake();
|
|
48
|
-
await expect.poll(() => messenger.status).toBe(EdgeStatus.CONNECTED);
|
|
48
|
+
await expect.poll(() => messenger.status.state).toBe(EdgeStatus.ConnectionState.CONNECTED);
|
|
49
49
|
|
|
50
50
|
await attachReplicator(messenger);
|
|
51
51
|
await expect.poll(() => messageSink.length).toEqual(1);
|
|
@@ -15,14 +15,14 @@ import { log, logInfo } from '@dxos/log';
|
|
|
15
15
|
import { EdgeService } from '@dxos/protocols';
|
|
16
16
|
import { buf } from '@dxos/protocols/buf';
|
|
17
17
|
import {
|
|
18
|
-
MessageSchema as RouterMessageSchema,
|
|
19
18
|
type Message as RouterMessage,
|
|
19
|
+
MessageSchema as RouterMessageSchema,
|
|
20
20
|
} from '@dxos/protocols/buf/dxos/edge/messenger_pb';
|
|
21
21
|
import type { FeedBlock, ProtocolMessage } from '@dxos/protocols/feed-replication';
|
|
22
22
|
import { EdgeStatus } from '@dxos/protocols/proto/dxos/client/services';
|
|
23
23
|
import { ComplexMap, arrayToBuffer, bufferToArray, defaultMap, rangeFromTo } from '@dxos/util';
|
|
24
24
|
|
|
25
|
-
export type
|
|
25
|
+
export type EdgeFeedReplicatorProps = {
|
|
26
26
|
messenger: EdgeConnection;
|
|
27
27
|
spaceId: SpaceId;
|
|
28
28
|
};
|
|
@@ -47,7 +47,7 @@ export class EdgeFeedReplicator extends Resource {
|
|
|
47
47
|
*/
|
|
48
48
|
private _pushMutex = new ComplexMap<PublicKey, Mutex>(PublicKey.hash);
|
|
49
49
|
|
|
50
|
-
constructor({ messenger, spaceId }:
|
|
50
|
+
constructor({ messenger, spaceId }: EdgeFeedReplicatorProps) {
|
|
51
51
|
super();
|
|
52
52
|
this._messenger = messenger;
|
|
53
53
|
this._spaceId = spaceId;
|
|
@@ -87,7 +87,7 @@ export class EdgeFeedReplicator extends Resource {
|
|
|
87
87
|
|
|
88
88
|
private async _handleReconnect(): Promise<void> {
|
|
89
89
|
await this._resetConnection();
|
|
90
|
-
if (this._messenger.status === EdgeStatus.CONNECTED) {
|
|
90
|
+
if (this._messenger.status.state === EdgeStatus.ConnectionState.CONNECTED) {
|
|
91
91
|
this._startReplication();
|
|
92
92
|
}
|
|
93
93
|
}
|
|
@@ -36,7 +36,7 @@ const LOAD_DOC_TIMEOUT = 10_000;
|
|
|
36
36
|
export const runEpochMigration = async (ctx: Context, context: MigrationContext): Promise<MigrationResult> => {
|
|
37
37
|
switch (context.migration) {
|
|
38
38
|
case CreateEpochRequest.Migration.INIT_AUTOMERGE: {
|
|
39
|
-
const document = context.echoHost.createDoc();
|
|
39
|
+
const document = await context.echoHost.createDoc();
|
|
40
40
|
await context.echoHost.flush();
|
|
41
41
|
return { newRoot: document.url };
|
|
42
42
|
}
|
|
@@ -48,7 +48,7 @@ export const runEpochMigration = async (ctx: Context, context: MigrationContext)
|
|
|
48
48
|
timeout: LOAD_DOC_TIMEOUT,
|
|
49
49
|
});
|
|
50
50
|
|
|
51
|
-
const newRoot = context.echoHost.createDoc(rootHandle.doc());
|
|
51
|
+
const newRoot = await context.echoHost.createDoc(rootHandle.doc());
|
|
52
52
|
await context.echoHost.flush();
|
|
53
53
|
return { newRoot: newRoot.url };
|
|
54
54
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { describe, expect, onTestFinished, test } from 'vitest';
|
|
6
6
|
|
|
7
7
|
import { Context } from '@dxos/context';
|
|
8
8
|
import { CredentialGenerator } from '@dxos/credentials';
|
|
@@ -13,7 +13,7 @@ import { log } from '@dxos/log';
|
|
|
13
13
|
import { AdmittedFeed, type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
14
14
|
import { TestBuilder, type TestConnection, TestPeer } from '@dxos/teleport/testing';
|
|
15
15
|
|
|
16
|
-
import { NotarizationPlugin, type
|
|
16
|
+
import { NotarizationPlugin, type NotarizationPluginProps } from './notarization-plugin';
|
|
17
17
|
|
|
18
18
|
class TestAgent extends TestPeer {
|
|
19
19
|
private readonly _ctx = new Context();
|
|
@@ -21,7 +21,7 @@ class TestAgent extends TestPeer {
|
|
|
21
21
|
feed = new MockFeedWriter<Credential>();
|
|
22
22
|
notarizationPlugin: NotarizationPlugin;
|
|
23
23
|
|
|
24
|
-
constructor(params:
|
|
24
|
+
constructor(params: NotarizationPluginProps) {
|
|
25
25
|
super();
|
|
26
26
|
this.notarizationPlugin = new NotarizationPlugin(params);
|
|
27
27
|
this.feed.written.on(this._ctx, async ([credential]) => {
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { DeferredTask, Event,
|
|
6
|
-
import { type Context,
|
|
5
|
+
import { DeferredTask, Event, TimeoutError, Trigger, scheduleMicroTask, scheduleTask, sleep } from '@dxos/async';
|
|
6
|
+
import { type Context, Resource, rejectOnDispose } from '@dxos/context';
|
|
7
7
|
import { type CredentialProcessor, verifyCredential } from '@dxos/credentials';
|
|
8
8
|
import { type EdgeHttpClient } from '@dxos/edge-client';
|
|
9
9
|
import { type FeedWriter } from '@dxos/feed-store';
|
|
10
10
|
import { invariant } from '@dxos/invariant';
|
|
11
11
|
import { PublicKey } from '@dxos/keys';
|
|
12
12
|
import { type SpaceId } from '@dxos/keys';
|
|
13
|
-
import {
|
|
13
|
+
import { log, logInfo } from '@dxos/log';
|
|
14
14
|
import { EdgeCallFailedError } from '@dxos/protocols';
|
|
15
15
|
import { schema } from '@dxos/protocols/proto';
|
|
16
16
|
import { type Runtime } from '@dxos/protocols/proto/dxos/config';
|
|
@@ -33,14 +33,14 @@ const WRITER_NOT_SET_ERROR_CODE = 'WRITER_NOT_SET';
|
|
|
33
33
|
|
|
34
34
|
const credentialCodec = schema.getCodecForType('dxos.halo.credentials.Credential');
|
|
35
35
|
|
|
36
|
-
export type
|
|
36
|
+
export type NotarizationPluginProps = {
|
|
37
37
|
spaceId: SpaceId;
|
|
38
38
|
edgeClient?: EdgeHttpClient;
|
|
39
39
|
edgeFeatures?: Runtime.Client.EdgeFeatures;
|
|
40
40
|
activeEdgePollingInterval?: number;
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
export type
|
|
43
|
+
export type NotarizeProps = {
|
|
44
44
|
/**
|
|
45
45
|
* For cancellation.
|
|
46
46
|
*/
|
|
@@ -97,7 +97,7 @@ export class NotarizationPlugin extends Resource implements CredentialProcessor
|
|
|
97
97
|
|
|
98
98
|
private readonly _edgeClient: EdgeHttpClient | undefined;
|
|
99
99
|
|
|
100
|
-
constructor(params:
|
|
100
|
+
constructor(params: NotarizationPluginProps) {
|
|
101
101
|
super();
|
|
102
102
|
this._spaceId = params.spaceId;
|
|
103
103
|
this._activeEdgePollingInterval = params.activeEdgePollingInterval ?? DEFAULT_ACTIVE_EDGE_POLLING_INTERVAL;
|
|
@@ -149,7 +149,7 @@ export class NotarizationPlugin extends Resource implements CredentialProcessor
|
|
|
149
149
|
retryTimeout = DEFAULT_RETRY_TIMEOUT,
|
|
150
150
|
successDelay = DEFAULT_SUCCESS_DELAY,
|
|
151
151
|
edgeRetryJitter,
|
|
152
|
-
}:
|
|
152
|
+
}: NotarizeProps): Promise<void> {
|
|
153
153
|
log('notarize', { credentials });
|
|
154
154
|
invariant(
|
|
155
155
|
credentials.every((credential) => credential.id),
|
|
@@ -392,21 +392,21 @@ export class NotarizationPlugin extends Resource implements CredentialProcessor
|
|
|
392
392
|
}
|
|
393
393
|
|
|
394
394
|
const handleEdgeError = (error: any) => {
|
|
395
|
-
if (!(error instanceof EdgeCallFailedError) || error.
|
|
395
|
+
if (!(error instanceof EdgeCallFailedError) || error.data) {
|
|
396
396
|
log.catch(error);
|
|
397
397
|
} else {
|
|
398
|
-
log.info('Edge notarization failure', {
|
|
398
|
+
log.info('Edge notarization failure', { message: error.message });
|
|
399
399
|
}
|
|
400
400
|
};
|
|
401
401
|
|
|
402
|
-
export type
|
|
402
|
+
export type NotarizationTeleportExtensionProps = {
|
|
403
403
|
onOpen: () => Promise<void>;
|
|
404
404
|
onClose: () => Promise<void>;
|
|
405
405
|
onNotarize: (request: NotarizeRequest) => Promise<void>;
|
|
406
406
|
};
|
|
407
407
|
|
|
408
408
|
export class NotarizationTeleportExtension extends RpcExtension<Services, Services> {
|
|
409
|
-
constructor(private readonly _params:
|
|
409
|
+
constructor(private readonly _params: NotarizationTeleportExtensionProps) {
|
|
410
410
|
super({
|
|
411
411
|
requested: {
|
|
412
412
|
NotarizationService: schema.getService('dxos.mesh.teleport.notarization.NotarizationService'),
|
|
@@ -2,17 +2,18 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { afterEach,
|
|
5
|
+
import { afterEach, beforeEach, describe, expect, onTestFinished, test } from 'vitest';
|
|
6
6
|
|
|
7
7
|
import { Trigger } from '@dxos/async';
|
|
8
8
|
import { Context } from '@dxos/context';
|
|
9
9
|
import { PublicKey } from '@dxos/keys';
|
|
10
10
|
import { type Space, type SpacesService } from '@dxos/protocols/proto/dxos/client/services';
|
|
11
11
|
|
|
12
|
-
import { SpacesServiceImpl } from './spaces-service';
|
|
13
12
|
import { type ServiceContext } from '../services';
|
|
14
13
|
import { createServiceContext } from '../testing';
|
|
15
14
|
|
|
15
|
+
import { SpacesServiceImpl } from './spaces-service';
|
|
16
|
+
|
|
16
17
|
describe('SpacesService', () => {
|
|
17
18
|
let serviceContext: ServiceContext;
|
|
18
19
|
let spacesService: SpacesService;
|