@dxos/client-services 0.8.4-main.7ace549 → 0.8.4-main.8360d9e660
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-NXGWBEOK.mjs → chunk-FRMIC6UB.mjs} +1529 -1308
- package/dist/lib/browser/chunk-FRMIC6UB.mjs.map +7 -0
- package/dist/lib/browser/chunk-NQSC7HOE.mjs +22 -0
- package/dist/lib/browser/chunk-NQSC7HOE.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 +441 -66
- 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 +24 -12
- 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-AO4R6IID.mjs → chunk-6ONWVRY5.mjs} +972 -620
- package/dist/lib/node-esm/chunk-6ONWVRY5.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/index.mjs +441 -66
- 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 +24 -12
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- 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/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/default-space-state-machine.d.ts +2 -2
- 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 +4 -4
- 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.d.ts +2 -2
- package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts +2 -2
- package/dist/types/src/packlets/invitations/device-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/locks/index.d.ts +1 -1
- package/dist/types/src/packlets/locks/index.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/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 +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 +12 -7
- package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-host.d.ts +19 -5
- 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.map +1 -1
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts +10 -5
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space.d.ts +2 -2
- 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/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 +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 +70 -48
- package/src/packlets/devtools/devtools.ts +2 -2
- package/src/packlets/diagnostics/index.ts +1 -1
- package/src/packlets/identity/authenticator.ts +2 -2
- package/src/packlets/identity/default-space-state-machine.ts +2 -2
- package/src/packlets/identity/identity-manager.ts +6 -6
- package/src/packlets/identity/identity-recovery-manager.ts +2 -2
- package/src/packlets/identity/identity.ts +2 -2
- package/src/packlets/invitations/device-invitation-protocol.ts +2 -2
- package/src/packlets/invitations/invitations-handler.ts +6 -6
- package/src/packlets/locks/index.ts +1 -1
- package/src/packlets/logging/logging-service.ts +4 -0
- package/src/packlets/services/client-rpc-server.ts +4 -4
- package/src/packlets/services/feed-syncer.test.ts +340 -0
- package/src/packlets/services/feed-syncer.ts +330 -0
- package/src/packlets/services/platform.ts +7 -1
- package/src/packlets/services/service-context.ts +108 -24
- package/src/packlets/services/service-host.ts +58 -16
- package/src/packlets/space-export/space-archive-writer.ts +3 -2
- package/src/packlets/spaces/data-space-manager.ts +35 -16
- package/src/packlets/spaces/data-space.ts +9 -5
- package/src/packlets/spaces/edge-feed-replicator.ts +2 -2
- package/src/packlets/spaces/epoch-migrations.ts +2 -2
- package/src/packlets/spaces/notarization-plugin.test.ts +2 -2
- package/src/packlets/spaces/notarization-plugin.ts +6 -6
- package/src/packlets/testing/invitation-utils.ts +7 -4
- package/src/packlets/testing/test-builder.ts +36 -10
- package/src/packlets/worker/worker-runtime.ts +149 -11
- package/src/packlets/worker/worker-session.ts +8 -8
- package/src/version.ts +1 -1
- package/dist/lib/browser/chunk-NXGWBEOK.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-AO4R6IID.mjs.map +0 -7
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import type * as SqlClient from '@effect/sql/SqlClient';
|
|
6
|
+
|
|
5
7
|
import { Mutex, Trigger } from '@dxos/async';
|
|
6
8
|
import { Context, Resource } from '@dxos/context';
|
|
7
9
|
import { type CredentialProcessor, getCredentialAssertion } from '@dxos/credentials';
|
|
@@ -16,20 +18,23 @@ import {
|
|
|
16
18
|
} from '@dxos/echo-pipeline';
|
|
17
19
|
import { createChainEdgeIdentity, createEphemeralEdgeIdentity } from '@dxos/edge-client';
|
|
18
20
|
import type { EdgeConnection, EdgeHttpClient, EdgeIdentity } from '@dxos/edge-client';
|
|
21
|
+
import { type RuntimeProvider } from '@dxos/effect';
|
|
19
22
|
import { FeedFactory, FeedStore } from '@dxos/feed-store';
|
|
20
23
|
import { invariant } from '@dxos/invariant';
|
|
21
24
|
import { Keyring } from '@dxos/keyring';
|
|
22
|
-
import { PublicKey } from '@dxos/keys';
|
|
25
|
+
import { PublicKey, type SpaceId } from '@dxos/keys';
|
|
23
26
|
import { type LevelDB } from '@dxos/kv-store';
|
|
24
27
|
import { log } from '@dxos/log';
|
|
25
28
|
import { type SignalManager } from '@dxos/messaging';
|
|
26
29
|
import { type SwarmNetworkManager } from '@dxos/network-manager';
|
|
27
30
|
import { InvalidStorageVersionError, STORAGE_VERSION, trace } from '@dxos/protocols';
|
|
31
|
+
import { FeedProtocol } from '@dxos/protocols';
|
|
28
32
|
import { Invitation } from '@dxos/protocols/proto/dxos/client/services';
|
|
29
33
|
import { type Runtime } from '@dxos/protocols/proto/dxos/config';
|
|
30
34
|
import type { FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';
|
|
31
35
|
import { type Credential, type ProfileDocument } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
32
36
|
import { type Storage } from '@dxos/random-access-storage';
|
|
37
|
+
import type * as SqlTransaction from '@dxos/sql-sqlite/SqlTransaction';
|
|
33
38
|
import { BlobStore } from '@dxos/teleport-extension-object-sync';
|
|
34
39
|
import { trace as Trace } from '@dxos/tracing';
|
|
35
40
|
import { safeInstanceof } from '@dxos/util';
|
|
@@ -38,26 +43,28 @@ import { EdgeAgentManager } from '../agents';
|
|
|
38
43
|
import {
|
|
39
44
|
type CreateIdentityOptions,
|
|
40
45
|
IdentityManager,
|
|
41
|
-
type
|
|
42
|
-
type
|
|
46
|
+
type IdentityManagerProps,
|
|
47
|
+
type JoinIdentityProps,
|
|
43
48
|
} from '../identity';
|
|
44
49
|
import { EdgeIdentityRecoveryManager } from '../identity/identity-recovery-manager';
|
|
45
50
|
import {
|
|
46
51
|
DeviceInvitationProtocol,
|
|
47
|
-
type
|
|
52
|
+
type InvitationConnectionProps,
|
|
48
53
|
type InvitationProtocol,
|
|
49
54
|
InvitationsHandler,
|
|
50
55
|
InvitationsManager,
|
|
51
56
|
SpaceInvitationProtocol,
|
|
52
57
|
} from '../invitations';
|
|
53
|
-
import { DataSpaceManager, type
|
|
58
|
+
import { DataSpaceManager, type DataSpaceManagerRuntimeProps, type SigningContext } from '../spaces';
|
|
59
|
+
|
|
60
|
+
import { FeedSyncer } from './feed-syncer';
|
|
54
61
|
|
|
55
|
-
export type
|
|
56
|
-
|
|
62
|
+
export type ServiceContextRuntimeProps = Pick<
|
|
63
|
+
IdentityManagerProps,
|
|
57
64
|
'devicePresenceOfflineTimeout' | 'devicePresenceAnnounceInterval'
|
|
58
65
|
> &
|
|
59
|
-
|
|
60
|
-
|
|
66
|
+
DataSpaceManagerRuntimeProps & {
|
|
67
|
+
invitationConnectionDefaultProps?: InvitationConnectionProps;
|
|
61
68
|
disableP2pReplication?: boolean;
|
|
62
69
|
enableVectorIndexing?: boolean;
|
|
63
70
|
};
|
|
@@ -84,6 +91,7 @@ export class ServiceContext extends Resource {
|
|
|
84
91
|
public readonly echoHost: EchoHost;
|
|
85
92
|
private readonly _meshReplicator?: MeshEchoReplicator = undefined;
|
|
86
93
|
private readonly _echoEdgeReplicator?: EchoEdgeReplicator = undefined;
|
|
94
|
+
private readonly _feedSyncer?: FeedSyncer = undefined;
|
|
87
95
|
|
|
88
96
|
// Initialized after identity is initialized.
|
|
89
97
|
public dataSpaceManager?: DataSpaceManager;
|
|
@@ -105,11 +113,15 @@ export class ServiceContext extends Resource {
|
|
|
105
113
|
public readonly signalManager: SignalManager,
|
|
106
114
|
private readonly _edgeConnection: EdgeConnection | undefined,
|
|
107
115
|
private readonly _edgeHttpClient: EdgeHttpClient | undefined,
|
|
108
|
-
|
|
116
|
+
private readonly _runtime: RuntimeProvider.RuntimeProvider<SqlClient.SqlClient | SqlTransaction.SqlTransaction>,
|
|
117
|
+
public readonly _runtimeProps?: ServiceContextRuntimeProps,
|
|
109
118
|
private readonly _edgeFeatures?: Runtime.Client.EdgeFeatures,
|
|
110
119
|
) {
|
|
111
120
|
super();
|
|
112
121
|
|
|
122
|
+
log('runtimeProps', this._runtimeProps);
|
|
123
|
+
log('edgeFeatures', this._edgeFeatures);
|
|
124
|
+
|
|
113
125
|
// TODO(burdon): Move strings to constants.
|
|
114
126
|
this.metadataStore = new MetadataStore(storage.createDirectory('metadata'));
|
|
115
127
|
this.blobStore = new BlobStore(storage.createDirectory('blobs'));
|
|
@@ -131,7 +143,7 @@ export class ServiceContext extends Resource {
|
|
|
131
143
|
networkManager: this.networkManager,
|
|
132
144
|
blobStore: this.blobStore,
|
|
133
145
|
metadataStore: this.metadataStore,
|
|
134
|
-
disableP2pReplication: this.
|
|
146
|
+
disableP2pReplication: this._runtimeProps?.disableP2pReplication,
|
|
135
147
|
});
|
|
136
148
|
|
|
137
149
|
this.identityManager = new IdentityManager({
|
|
@@ -139,8 +151,8 @@ export class ServiceContext extends Resource {
|
|
|
139
151
|
keyring: this.keyring,
|
|
140
152
|
feedStore: this.feedStore,
|
|
141
153
|
spaceManager: this.spaceManager,
|
|
142
|
-
devicePresenceOfflineTimeout: this.
|
|
143
|
-
devicePresenceAnnounceInterval: this.
|
|
154
|
+
devicePresenceOfflineTimeout: this._runtimeProps?.devicePresenceOfflineTimeout,
|
|
155
|
+
devicePresenceAnnounceInterval: this._runtimeProps?.devicePresenceAnnounceInterval,
|
|
144
156
|
edgeConnection: this._edgeConnection,
|
|
145
157
|
edgeFeatures: this._edgeFeatures,
|
|
146
158
|
});
|
|
@@ -156,17 +168,21 @@ export class ServiceContext extends Resource {
|
|
|
156
168
|
kv: this.level,
|
|
157
169
|
peerIdProvider: () => this.identityManager.identity?.deviceKey?.toHex(),
|
|
158
170
|
getSpaceKeyByRootDocumentId: (documentId) => this.spaceManager.findSpaceByRootDocumentId(documentId)?.key,
|
|
159
|
-
|
|
160
|
-
|
|
171
|
+
runtime: this._runtime,
|
|
172
|
+
syncQueue: async (request) => {
|
|
173
|
+
return this._feedSyncer?.syncBlocking({
|
|
174
|
+
spaceId: request.spaceId as SpaceId,
|
|
175
|
+
subspaceTag: request.subspaceTag,
|
|
176
|
+
shouldPush: request.shouldPush,
|
|
177
|
+
shouldPull: request.shouldPull,
|
|
178
|
+
});
|
|
161
179
|
},
|
|
162
180
|
});
|
|
163
181
|
|
|
164
|
-
this._meshReplicator = new MeshEchoReplicator();
|
|
165
|
-
|
|
166
182
|
this.invitations = new InvitationsHandler(
|
|
167
183
|
this.networkManager, //
|
|
168
184
|
this._edgeHttpClient,
|
|
169
|
-
|
|
185
|
+
_runtimeProps?.invitationConnectionDefaultProps,
|
|
170
186
|
);
|
|
171
187
|
this.invitationsManager = new InvitationsManager(
|
|
172
188
|
this.invitations,
|
|
@@ -186,7 +202,7 @@ export class ServiceContext extends Resource {
|
|
|
186
202
|
),
|
|
187
203
|
);
|
|
188
204
|
|
|
189
|
-
if (!this.
|
|
205
|
+
if (!this._runtimeProps?.disableP2pReplication) {
|
|
190
206
|
this._meshReplicator = new MeshEchoReplicator();
|
|
191
207
|
}
|
|
192
208
|
if (this._edgeConnection && this._edgeFeatures?.echoReplicator && this._edgeHttpClient) {
|
|
@@ -195,6 +211,17 @@ export class ServiceContext extends Resource {
|
|
|
195
211
|
edgeHttpClient: this._edgeHttpClient,
|
|
196
212
|
});
|
|
197
213
|
}
|
|
214
|
+
|
|
215
|
+
if (this.echoHost.feedStore && this._edgeConnection) {
|
|
216
|
+
this._feedSyncer = new FeedSyncer({
|
|
217
|
+
runtime: this._runtime,
|
|
218
|
+
feedStore: this.echoHost.feedStore,
|
|
219
|
+
edgeClient: this._edgeConnection,
|
|
220
|
+
peerId: this.identityManager.identity?.deviceKey?.toHex() ?? '',
|
|
221
|
+
getSpaceIds: () => this.echoHost!.spaceIds,
|
|
222
|
+
syncNamespaces: [FeedProtocol.WellKnownNamespaces.data, FeedProtocol.WellKnownNamespaces.trace],
|
|
223
|
+
});
|
|
224
|
+
}
|
|
198
225
|
}
|
|
199
226
|
|
|
200
227
|
@Trace.span()
|
|
@@ -204,31 +231,66 @@ export class ServiceContext extends Resource {
|
|
|
204
231
|
log('opening...');
|
|
205
232
|
log.trace('dxos.sdk.service-context.open', trace.begin({ id: this._instanceId }));
|
|
206
233
|
|
|
234
|
+
log('opening identityManager...');
|
|
207
235
|
await this.identityManager.open(ctx);
|
|
236
|
+
log('identityManager opened', { hasIdentity: !!this.identityManager.identity });
|
|
208
237
|
|
|
238
|
+
log('setting network identity...');
|
|
209
239
|
await this._setNetworkIdentity();
|
|
240
|
+
log('network identity set');
|
|
210
241
|
|
|
242
|
+
log('opening edge connection...');
|
|
211
243
|
await this._edgeConnection?.open();
|
|
244
|
+
log('edge connection opened');
|
|
245
|
+
|
|
246
|
+
log('opening signal manager...');
|
|
212
247
|
await this.signalManager.open();
|
|
248
|
+
log('signal manager opened');
|
|
249
|
+
|
|
250
|
+
log('opening network manager...');
|
|
213
251
|
await this.networkManager.open();
|
|
252
|
+
log('network manager opened');
|
|
214
253
|
|
|
254
|
+
log('opening echo host...');
|
|
215
255
|
await this.echoHost.open(ctx);
|
|
256
|
+
log('echo host opened');
|
|
216
257
|
|
|
217
258
|
if (this._meshReplicator) {
|
|
259
|
+
log('adding mesh replicator...');
|
|
218
260
|
await this.echoHost.addReplicator(this._meshReplicator);
|
|
261
|
+
log('mesh replicator added');
|
|
219
262
|
}
|
|
220
263
|
if (this._echoEdgeReplicator) {
|
|
264
|
+
log('adding edge replicator...');
|
|
221
265
|
await this.echoHost.addReplicator(this._echoEdgeReplicator);
|
|
266
|
+
log('edge replicator added');
|
|
222
267
|
}
|
|
223
268
|
|
|
269
|
+
log('loading metadata store...');
|
|
224
270
|
await this.metadataStore.load();
|
|
271
|
+
log('metadata store loaded');
|
|
272
|
+
|
|
273
|
+
log('opening space manager...');
|
|
225
274
|
await this.spaceManager.open();
|
|
275
|
+
log('space manager opened');
|
|
226
276
|
|
|
227
277
|
if (this.identityManager.identity) {
|
|
278
|
+
log('joining network...');
|
|
228
279
|
await this.identityManager.identity.joinNetwork();
|
|
280
|
+
log('network joined');
|
|
281
|
+
|
|
282
|
+
log('initializing spaces...(calling _initialize)');
|
|
229
283
|
await this._initialize(ctx);
|
|
284
|
+
log('spaces initialized');
|
|
285
|
+
} else {
|
|
286
|
+
log('no identity, skipping network join and space initialization');
|
|
230
287
|
}
|
|
231
288
|
|
|
289
|
+
log('opening feed syncer...');
|
|
290
|
+
await this._feedSyncer?.open();
|
|
291
|
+
log('feed syncer opened');
|
|
292
|
+
|
|
293
|
+
log('loading persistent invitations...');
|
|
232
294
|
const loadedInvitations = await this.invitationsManager.loadPersistentInvitations();
|
|
233
295
|
log('loaded persistent invitations', { count: loadedInvitations.invitations?.length });
|
|
234
296
|
|
|
@@ -238,6 +300,9 @@ export class ServiceContext extends Resource {
|
|
|
238
300
|
|
|
239
301
|
protected override async _close(ctx: Context): Promise<void> {
|
|
240
302
|
log('closing...');
|
|
303
|
+
|
|
304
|
+
await this._feedSyncer?.close();
|
|
305
|
+
|
|
241
306
|
if (this._deviceSpaceSync && this.identityManager.identity) {
|
|
242
307
|
await this.identityManager.identity.space.spaceState.removeCredentialProcessor(this._deviceSpaceSync);
|
|
243
308
|
}
|
|
@@ -283,7 +348,7 @@ export class ServiceContext extends Resource {
|
|
|
283
348
|
}
|
|
284
349
|
}
|
|
285
350
|
|
|
286
|
-
private async _acceptIdentity(params:
|
|
351
|
+
private async _acceptIdentity(params: JoinIdentityProps) {
|
|
287
352
|
const { identity, identityRecord } = await this.identityManager.prepareIdentity(params);
|
|
288
353
|
await this._setNetworkIdentity({ deviceCredential: params.authorizedDeviceCredential! });
|
|
289
354
|
await identity.joinNetwork();
|
|
@@ -303,7 +368,7 @@ export class ServiceContext extends Resource {
|
|
|
303
368
|
// Called when identity is created.
|
|
304
369
|
@Trace.span()
|
|
305
370
|
private async _initialize(ctx: Context): Promise<void> {
|
|
306
|
-
log('
|
|
371
|
+
log('_initialize: start');
|
|
307
372
|
const identity = this.identityManager.identity ?? failUndefined();
|
|
308
373
|
const signingContext: SigningContext = {
|
|
309
374
|
credentialSigner: identity.getIdentityCredentialSigner(),
|
|
@@ -315,6 +380,7 @@ export class ServiceContext extends Resource {
|
|
|
315
380
|
},
|
|
316
381
|
};
|
|
317
382
|
|
|
383
|
+
log('_initialize: creating DataSpaceManager');
|
|
318
384
|
this.dataSpaceManager = new DataSpaceManager({
|
|
319
385
|
spaceManager: this.spaceManager,
|
|
320
386
|
metadataStore: this.metadataStore,
|
|
@@ -327,10 +393,12 @@ export class ServiceContext extends Resource {
|
|
|
327
393
|
edgeHttpClient: this._edgeHttpClient,
|
|
328
394
|
echoEdgeReplicator: this._echoEdgeReplicator,
|
|
329
395
|
meshReplicator: this._meshReplicator,
|
|
330
|
-
|
|
396
|
+
runtimeProps: this._runtimeProps as DataSpaceManagerRuntimeProps,
|
|
331
397
|
edgeFeatures: this._edgeFeatures,
|
|
332
398
|
});
|
|
399
|
+
log('_initialize: opening DataSpaceManager...');
|
|
333
400
|
await this.dataSpaceManager.open();
|
|
401
|
+
log('_initialize: DataSpaceManager opened');
|
|
334
402
|
|
|
335
403
|
this.edgeAgentManager = new EdgeAgentManager(
|
|
336
404
|
this._edgeFeatures,
|
|
@@ -338,13 +406,16 @@ export class ServiceContext extends Resource {
|
|
|
338
406
|
this.dataSpaceManager,
|
|
339
407
|
identity,
|
|
340
408
|
);
|
|
409
|
+
log('_initialize: opening EdgeAgentManager...');
|
|
341
410
|
await this.edgeAgentManager.open();
|
|
411
|
+
log('_initialize: EdgeAgentManager opened');
|
|
342
412
|
|
|
343
413
|
this._handlerFactories.set(Invitation.Kind.SPACE, (invitation) => {
|
|
344
414
|
invariant(this.dataSpaceManager, 'dataSpaceManager not initialized yet');
|
|
345
415
|
return new SpaceInvitationProtocol(this.dataSpaceManager, signingContext, this.keyring, invitation.spaceKey);
|
|
346
416
|
});
|
|
347
417
|
this.initialized.wake();
|
|
418
|
+
log('_initialize: initialized.wake() called');
|
|
348
419
|
|
|
349
420
|
this._deviceSpaceSync = {
|
|
350
421
|
processCredential: async (credential: Credential) => {
|
|
@@ -381,17 +452,20 @@ export class ServiceContext extends Resource {
|
|
|
381
452
|
}
|
|
382
453
|
|
|
383
454
|
private async _setNetworkIdentity(params?: { deviceCredential: Credential }): Promise<void> {
|
|
455
|
+
log('_setNetworkIdentity: acquiring mutex...');
|
|
384
456
|
using _ = await this._edgeIdentityUpdateMutex.acquire();
|
|
457
|
+
log('_setNetworkIdentity: mutex acquired');
|
|
385
458
|
|
|
386
459
|
let edgeIdentity: EdgeIdentity;
|
|
387
460
|
const identity = this.identityManager.identity;
|
|
388
461
|
if (identity) {
|
|
389
|
-
log('
|
|
462
|
+
log('_setNetworkIdentity: has identity', {
|
|
390
463
|
identity: identity.identityKey.toHex(),
|
|
391
|
-
|
|
464
|
+
hasDeviceCredential: !!params?.deviceCredential,
|
|
392
465
|
});
|
|
393
466
|
|
|
394
467
|
if (params?.deviceCredential) {
|
|
468
|
+
log('_setNetworkIdentity: creating chain edge identity with device credential...');
|
|
395
469
|
edgeIdentity = await createChainEdgeIdentity(
|
|
396
470
|
identity.signer,
|
|
397
471
|
identity.identityKey,
|
|
@@ -399,14 +473,20 @@ export class ServiceContext extends Resource {
|
|
|
399
473
|
params?.deviceCredential && { credential: params.deviceCredential },
|
|
400
474
|
[], // TODO(dmaretskyi): Service access credentials.
|
|
401
475
|
);
|
|
476
|
+
log('_setNetworkIdentity: chain edge identity created');
|
|
402
477
|
} else {
|
|
478
|
+
log('_setNetworkIdentity: waiting for identity.ready()...');
|
|
403
479
|
// TODO: throw here or from identity if device chain can't be loaded, to avoid indefinite hangup
|
|
404
480
|
await warnAfterTimeout(10_000, 'Waiting for identity to be ready for edge connection', async () => {
|
|
405
481
|
await identity.ready();
|
|
406
482
|
});
|
|
483
|
+
log('_setNetworkIdentity: identity.ready() resolved', {
|
|
484
|
+
hasDeviceCredentialChain: !!identity.deviceCredentialChain,
|
|
485
|
+
});
|
|
407
486
|
|
|
408
487
|
invariant(identity.deviceCredentialChain);
|
|
409
488
|
|
|
489
|
+
log('_setNetworkIdentity: creating chain edge identity...');
|
|
410
490
|
edgeIdentity = await createChainEdgeIdentity(
|
|
411
491
|
identity.signer,
|
|
412
492
|
identity.identityKey,
|
|
@@ -414,9 +494,12 @@ export class ServiceContext extends Resource {
|
|
|
414
494
|
identity.deviceCredentialChain,
|
|
415
495
|
[], // TODO(dmaretskyi): Service access credentials.
|
|
416
496
|
);
|
|
497
|
+
log('_setNetworkIdentity: chain edge identity created');
|
|
417
498
|
}
|
|
418
499
|
} else {
|
|
500
|
+
log('_setNetworkIdentity: no identity, creating ephemeral edge identity...');
|
|
419
501
|
edgeIdentity = await createEphemeralEdgeIdentity();
|
|
502
|
+
log('_setNetworkIdentity: ephemeral edge identity created');
|
|
420
503
|
}
|
|
421
504
|
|
|
422
505
|
this._edgeConnection?.setIdentity(edgeIdentity);
|
|
@@ -425,5 +508,6 @@ export class ServiceContext extends Resource {
|
|
|
425
508
|
identityKey: edgeIdentity.identityKey,
|
|
426
509
|
peerKey: edgeIdentity.peerKey,
|
|
427
510
|
});
|
|
511
|
+
log('_setNetworkIdentity: done');
|
|
428
512
|
}
|
|
429
513
|
}
|
|
@@ -2,11 +2,15 @@
|
|
|
2
2
|
// Copyright 2021 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import * as SqlClient from '@effect/sql/SqlClient';
|
|
6
|
+
import * as Effect from 'effect/Effect';
|
|
7
|
+
|
|
5
8
|
import { Event, synchronized } from '@dxos/async';
|
|
6
9
|
import { type ClientServices, clientServiceBundle } from '@dxos/client-protocol';
|
|
7
10
|
import { type Config } from '@dxos/config';
|
|
8
11
|
import { Context } from '@dxos/context';
|
|
9
12
|
import { EdgeClient, type EdgeConnection, EdgeHttpClient, createStubEdgeIdentity } from '@dxos/edge-client';
|
|
13
|
+
import { RuntimeProvider } from '@dxos/effect';
|
|
10
14
|
import { invariant } from '@dxos/invariant';
|
|
11
15
|
import { PublicKey } from '@dxos/keys';
|
|
12
16
|
import { type LevelDB } from '@dxos/kv-store';
|
|
@@ -21,6 +25,8 @@ import {
|
|
|
21
25
|
import { trace } from '@dxos/protocols';
|
|
22
26
|
import { SystemStatus } from '@dxos/protocols/proto/dxos/client/services';
|
|
23
27
|
import { type Storage } from '@dxos/random-access-storage';
|
|
28
|
+
import * as SqlExport from '@dxos/sql-sqlite/SqlExport';
|
|
29
|
+
import type * as SqlTransaction from '@dxos/sql-sqlite/SqlTransaction';
|
|
24
30
|
import { TRACE_PROCESSOR, trace as Trace } from '@dxos/tracing';
|
|
25
31
|
import { WebsocketRpcClient } from '@dxos/websocket-rpc';
|
|
26
32
|
|
|
@@ -42,10 +48,10 @@ import { SpacesServiceImpl } from '../spaces';
|
|
|
42
48
|
import { createLevel, createStorageObjects } from '../storage';
|
|
43
49
|
import { SystemServiceImpl } from '../system';
|
|
44
50
|
|
|
45
|
-
import { ServiceContext, type
|
|
51
|
+
import { ServiceContext, type ServiceContextRuntimeProps } from './service-context';
|
|
46
52
|
import { ServiceRegistry } from './service-registry';
|
|
47
53
|
|
|
48
|
-
export type
|
|
54
|
+
export type ClientServicesHostProps = {
|
|
49
55
|
/**
|
|
50
56
|
* Can be omitted if `initialize` is later called.
|
|
51
57
|
*/
|
|
@@ -57,7 +63,8 @@ export type ClientServicesHostParams = {
|
|
|
57
63
|
level?: LevelDB;
|
|
58
64
|
lockKey?: string;
|
|
59
65
|
callbacks?: ClientServicesHostCallbacks;
|
|
60
|
-
|
|
66
|
+
runtime: RuntimeProvider.RuntimeProvider<SqlClient.SqlClient | SqlExport.SqlExport | SqlTransaction.SqlTransaction>;
|
|
67
|
+
runtimeProps?: ServiceContextRuntimeProps;
|
|
61
68
|
};
|
|
62
69
|
|
|
63
70
|
export type ClientServicesHostCallbacks = {
|
|
@@ -95,7 +102,10 @@ export class ClientServicesHost {
|
|
|
95
102
|
private _edgeHttpClient?: EdgeHttpClient = undefined;
|
|
96
103
|
|
|
97
104
|
private _serviceContext!: ServiceContext;
|
|
98
|
-
private readonly
|
|
105
|
+
private readonly _runtime: RuntimeProvider.RuntimeProvider<
|
|
106
|
+
SqlClient.SqlClient | SqlExport.SqlExport | SqlTransaction.SqlTransaction
|
|
107
|
+
>;
|
|
108
|
+
private readonly _runtimeProps: ServiceContextRuntimeProps;
|
|
99
109
|
private diagnosticsBroadcastHandler: CollectDiagnosticsBroadcastHandler;
|
|
100
110
|
|
|
101
111
|
@Trace.info()
|
|
@@ -116,20 +126,14 @@ export class ClientServicesHost {
|
|
|
116
126
|
// TODO(wittjosiah): Turn this on by default.
|
|
117
127
|
lockKey,
|
|
118
128
|
callbacks,
|
|
119
|
-
|
|
120
|
-
|
|
129
|
+
runtime,
|
|
130
|
+
runtimeProps,
|
|
131
|
+
}: ClientServicesHostProps) {
|
|
121
132
|
this._storage = storage;
|
|
122
133
|
this._level = level;
|
|
123
134
|
this._callbacks = callbacks;
|
|
124
|
-
this.
|
|
125
|
-
|
|
126
|
-
if (this._runtimeParams.disableP2pReplication === undefined) {
|
|
127
|
-
this._runtimeParams.disableP2pReplication = config?.get('runtime.client.disableP2pReplication', false);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
if (this._runtimeParams.enableVectorIndexing === undefined) {
|
|
131
|
-
this._runtimeParams.enableVectorIndexing = config?.get('runtime.client.enableVectorIndexing', false);
|
|
132
|
-
}
|
|
135
|
+
this._runtime = runtime;
|
|
136
|
+
this._runtimeProps = runtimeProps ?? {};
|
|
133
137
|
|
|
134
138
|
if (config) {
|
|
135
139
|
this.initialize({ config, transportFactory, signalManager });
|
|
@@ -200,6 +204,30 @@ export class ClientServicesHost {
|
|
|
200
204
|
return this._serviceRegistry.services;
|
|
201
205
|
}
|
|
202
206
|
|
|
207
|
+
/**
|
|
208
|
+
* Debugging util.
|
|
209
|
+
*/
|
|
210
|
+
async exportSqliteDatabase(): Promise<Uint8Array> {
|
|
211
|
+
return await RuntimeProvider.runPromise(this._runtime)(
|
|
212
|
+
Effect.gen(function* () {
|
|
213
|
+
const sql = yield* SqlExport.SqlExport;
|
|
214
|
+
return yield* sql.export;
|
|
215
|
+
}),
|
|
216
|
+
);
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Debugging util.
|
|
221
|
+
*/
|
|
222
|
+
async runSqliteQuery(query: string, params?: any[]): Promise<readonly Record<string, unknown>[]> {
|
|
223
|
+
return await RuntimeProvider.runPromise(this._runtime)(
|
|
224
|
+
Effect.gen(function* () {
|
|
225
|
+
const sql = yield* SqlClient.SqlClient;
|
|
226
|
+
return yield* sql`${sql.unsafe(query, params)}`;
|
|
227
|
+
}),
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
|
|
203
231
|
/**
|
|
204
232
|
* Initialize the service host with the config.
|
|
205
233
|
* Config can also be provided in the constructor.
|
|
@@ -210,6 +238,13 @@ export class ClientServicesHost {
|
|
|
210
238
|
log('initializing...');
|
|
211
239
|
|
|
212
240
|
if (config) {
|
|
241
|
+
if (this._runtimeProps.disableP2pReplication === undefined) {
|
|
242
|
+
this._runtimeProps.disableP2pReplication = config?.get('runtime.client.disableP2pReplication', false);
|
|
243
|
+
}
|
|
244
|
+
if (this._runtimeProps.enableVectorIndexing === undefined) {
|
|
245
|
+
this._runtimeProps.enableVectorIndexing = config?.get('runtime.client.enableVectorIndexing', false);
|
|
246
|
+
}
|
|
247
|
+
|
|
213
248
|
invariant(!this._config, 'config already set');
|
|
214
249
|
this._config = config;
|
|
215
250
|
if (!this._storage) {
|
|
@@ -291,7 +326,8 @@ export class ClientServicesHost {
|
|
|
291
326
|
this._signalManager,
|
|
292
327
|
this._edgeConnection,
|
|
293
328
|
this._edgeHttpClient,
|
|
294
|
-
this.
|
|
329
|
+
this._runtime,
|
|
330
|
+
this._runtimeProps,
|
|
295
331
|
this._config.get('runtime.client.edgeFeatures'),
|
|
296
332
|
);
|
|
297
333
|
|
|
@@ -335,6 +371,7 @@ export class ClientServicesHost {
|
|
|
335
371
|
|
|
336
372
|
DataService: this._serviceContext.echoHost.dataService,
|
|
337
373
|
QueryService: this._serviceContext.echoHost.queryService,
|
|
374
|
+
QueueService: this._serviceContext.echoHost.queuesService,
|
|
338
375
|
|
|
339
376
|
NetworkService: new NetworkServiceImpl(
|
|
340
377
|
this._serviceContext.networkManager,
|
|
@@ -355,8 +392,13 @@ export class ClientServicesHost {
|
|
|
355
392
|
EdgeAgentService: new EdgeAgentServiceImpl(agentManagerProvider, this._edgeConnection),
|
|
356
393
|
});
|
|
357
394
|
|
|
395
|
+
log('service-host: opening service context...');
|
|
358
396
|
await this._serviceContext.open(ctx);
|
|
397
|
+
log('service-host: service context opened');
|
|
398
|
+
|
|
399
|
+
log('service-host: opening identity service...');
|
|
359
400
|
await identityService.open();
|
|
401
|
+
log('service-host: identity service opened');
|
|
360
402
|
|
|
361
403
|
const devtoolsProxy = this._config?.get('runtime.client.devtoolsProxy');
|
|
362
404
|
if (devtoolsProxy) {
|
|
@@ -9,6 +9,7 @@ import { assertArgument, assertState } from '@dxos/invariant';
|
|
|
9
9
|
import type { IdentityDid, SpaceId } from '@dxos/keys';
|
|
10
10
|
import { SpaceArchiveFileStructure, type SpaceArchiveMetadata, SpaceArchiveVersion } from '@dxos/protocols';
|
|
11
11
|
import type { SpaceArchive } from '@dxos/protocols/proto/dxos/client/services';
|
|
12
|
+
import { createFilename } from '@dxos/util';
|
|
12
13
|
|
|
13
14
|
export type SpaceArchiveBeginProps = {
|
|
14
15
|
spaceId?: SpaceId;
|
|
@@ -59,6 +60,7 @@ export class SpaceArchiveWriter extends Resource {
|
|
|
59
60
|
async finish(): Promise<SpaceArchive> {
|
|
60
61
|
assertState(this._archive, 'Not open');
|
|
61
62
|
assertState(this._meta, 'Not started');
|
|
63
|
+
assertState(this._meta.spaceId, 'No space ID set');
|
|
62
64
|
assertState(this._currentRootUrl, 'No root URL set');
|
|
63
65
|
|
|
64
66
|
const metadata: SpaceArchiveMetadata = {
|
|
@@ -76,8 +78,7 @@ export class SpaceArchiveWriter extends Resource {
|
|
|
76
78
|
const binary = this._archive.toUint8Array();
|
|
77
79
|
|
|
78
80
|
return {
|
|
79
|
-
|
|
80
|
-
filename: `${new Date().toISOString()}-${this._meta.spaceId}.tar`,
|
|
81
|
+
filename: createFilename({ parts: [this._meta.spaceId], ext: 'tar' }),
|
|
81
82
|
contents: binary,
|
|
82
83
|
};
|
|
83
84
|
}
|