@dxos/client-services 0.5.0 → 0.5.1-main.140276b
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-ESEYLOPB.mjs → chunk-M4WLMX2J.mjs} +105 -164
- package/dist/lib/browser/chunk-M4WLMX2J.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +6 -4
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/packlets/testing/index.mjs +8 -6
- package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
- package/dist/lib/node/{chunk-GA7JFIXK.cjs → chunk-OG4ZQV4H.cjs} +118 -173
- package/dist/lib/node/chunk-OG4ZQV4H.cjs.map +7 -0
- package/dist/lib/node/index.cjs +48 -46
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/packlets/testing/index.cjs +13 -11
- package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
- package/dist/types/src/packlets/services/service-context.d.ts +4 -6
- package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-host.d.ts +0 -1
- package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts +4 -3
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space.d.ts +4 -3
- package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
- package/dist/types/src/packlets/storage/level.d.ts.map +1 -1
- package/dist/types/src/packlets/testing/test-builder.d.ts +4 -3
- package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/packlets/vault/worker-runtime.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/package.json +34 -34
- package/src/packlets/services/automerge-host.test.ts +3 -3
- package/src/packlets/services/service-context.test.ts +3 -3
- package/src/packlets/services/service-context.ts +11 -25
- package/src/packlets/services/service-host.test.ts +6 -0
- package/src/packlets/services/service-host.ts +7 -23
- package/src/packlets/spaces/data-space-manager.test.ts +4 -4
- package/src/packlets/spaces/data-space-manager.ts +8 -11
- package/src/packlets/spaces/data-space.ts +13 -18
- package/src/packlets/storage/level.ts +1 -0
- package/src/packlets/testing/test-builder.ts +8 -13
- package/src/packlets/vault/worker-runtime.ts +3 -1
- package/src/version.ts +1 -5
- package/dist/lib/browser/chunk-ESEYLOPB.mjs.map +0 -7
- package/dist/lib/node/chunk-GA7JFIXK.cjs.map +0 -7
- package/dist/types/src/packlets/indexing/index.d.ts +0 -2
- package/dist/types/src/packlets/indexing/index.d.ts.map +0 -1
- package/dist/types/src/packlets/indexing/util.d.ts +0 -11
- package/dist/types/src/packlets/indexing/util.d.ts.map +0 -1
- package/src/packlets/indexing/index.ts +0 -5
- package/src/packlets/indexing/util.ts +0 -32
|
@@ -8,9 +8,9 @@ import { Trigger } from '@dxos/async';
|
|
|
8
8
|
import { Context, Resource } from '@dxos/context';
|
|
9
9
|
import { getCredentialAssertion, type CredentialProcessor } from '@dxos/credentials';
|
|
10
10
|
import { failUndefined } from '@dxos/debug';
|
|
11
|
-
import {
|
|
11
|
+
import { EchoHost } from '@dxos/echo-db';
|
|
12
|
+
import { MetadataStore, SnapshotStore, SpaceManager, valueEncoding } from '@dxos/echo-pipeline';
|
|
12
13
|
import { FeedFactory, FeedStore } from '@dxos/feed-store';
|
|
13
|
-
import { IndexMetadataStore, IndexStore, Indexer, createStorageCallbacks } from '@dxos/indexing';
|
|
14
14
|
import { invariant } from '@dxos/invariant';
|
|
15
15
|
import { Keyring } from '@dxos/keyring';
|
|
16
16
|
import { PublicKey } from '@dxos/keys';
|
|
@@ -32,7 +32,6 @@ import {
|
|
|
32
32
|
type IdentityManagerRuntimeParams,
|
|
33
33
|
type JoinIdentityParams,
|
|
34
34
|
} from '../identity';
|
|
35
|
-
import { createSelectedDocumentsIterator } from '../indexing';
|
|
36
35
|
import {
|
|
37
36
|
DeviceInvitationProtocol,
|
|
38
37
|
InvitationsHandler,
|
|
@@ -64,9 +63,7 @@ export class ServiceContext extends Resource {
|
|
|
64
63
|
public readonly identityManager: IdentityManager;
|
|
65
64
|
public readonly invitations: InvitationsHandler;
|
|
66
65
|
public readonly invitationsManager: InvitationsManager;
|
|
67
|
-
public readonly
|
|
68
|
-
public readonly indexMetadata: IndexMetadataStore;
|
|
69
|
-
public readonly indexer: Indexer;
|
|
66
|
+
public readonly echoHost: EchoHost;
|
|
70
67
|
|
|
71
68
|
// Initialized after identity is initialized.
|
|
72
69
|
public dataSpaceManager?: DataSpaceManager;
|
|
@@ -122,19 +119,9 @@ export class ServiceContext extends Resource {
|
|
|
122
119
|
this._runtimeParams as IdentityManagerRuntimeParams,
|
|
123
120
|
);
|
|
124
121
|
|
|
125
|
-
this.
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
directory: storage.createDirectory('automerge'),
|
|
129
|
-
db: level.sublevel('automerge'),
|
|
130
|
-
storageCallbacks: createStorageCallbacks({ host: () => this.automergeHost, metadata: this.indexMetadata }),
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
this.indexer = new Indexer({
|
|
134
|
-
db: this.level,
|
|
135
|
-
indexStore: new IndexStore({ db: level.sublevel('index-storage') }),
|
|
136
|
-
metadataStore: this.indexMetadata,
|
|
137
|
-
loadDocuments: createSelectedDocumentsIterator(this.automergeHost),
|
|
122
|
+
this.echoHost = new EchoHost({
|
|
123
|
+
kv: this.level,
|
|
124
|
+
storage: this.storage,
|
|
138
125
|
});
|
|
139
126
|
|
|
140
127
|
this.invitations = new InvitationsHandler(this.networkManager);
|
|
@@ -166,7 +153,7 @@ export class ServiceContext extends Resource {
|
|
|
166
153
|
await this.signalManager.open();
|
|
167
154
|
await this.networkManager.open();
|
|
168
155
|
|
|
169
|
-
await this.
|
|
156
|
+
await this.echoHost.open(ctx);
|
|
170
157
|
await this.metadataStore.load();
|
|
171
158
|
await this.spaceManager.open();
|
|
172
159
|
await this.identityManager.open(ctx);
|
|
@@ -181,20 +168,19 @@ export class ServiceContext extends Resource {
|
|
|
181
168
|
log('opened');
|
|
182
169
|
}
|
|
183
170
|
|
|
184
|
-
protected override async _close() {
|
|
171
|
+
protected override async _close(ctx: Context) {
|
|
185
172
|
log('closing...');
|
|
186
173
|
if (this._deviceSpaceSync && this.identityManager.identity) {
|
|
187
174
|
await this.identityManager.identity.space.spaceState.removeCredentialProcessor(this._deviceSpaceSync);
|
|
188
175
|
}
|
|
189
|
-
await this.automergeHost.close();
|
|
190
176
|
await this.dataSpaceManager?.close();
|
|
191
177
|
await this.identityManager.close();
|
|
192
178
|
await this.spaceManager.close();
|
|
193
179
|
await this.feedStore.close();
|
|
180
|
+
await this.metadataStore.close();
|
|
181
|
+
await this.echoHost.close(ctx);
|
|
194
182
|
await this.networkManager.close();
|
|
195
183
|
await this.signalManager.close();
|
|
196
|
-
await this.metadataStore.close();
|
|
197
|
-
await this.indexer.destroy();
|
|
198
184
|
log('closed');
|
|
199
185
|
}
|
|
200
186
|
|
|
@@ -255,7 +241,7 @@ export class ServiceContext extends Resource {
|
|
|
255
241
|
this.keyring,
|
|
256
242
|
signingContext,
|
|
257
243
|
this.feedStore,
|
|
258
|
-
this.
|
|
244
|
+
this.echoHost,
|
|
259
245
|
this.invitationsManager,
|
|
260
246
|
this._runtimeParams as DataSpaceManagerRuntimeParams,
|
|
261
247
|
);
|
|
@@ -29,6 +29,12 @@ describe('ClientServicesHost', () => {
|
|
|
29
29
|
isNode() && rmSync(dataRoot, { recursive: true, force: true });
|
|
30
30
|
});
|
|
31
31
|
|
|
32
|
+
test('open and close', async () => {
|
|
33
|
+
const host = createServiceHost(new Config(), new MemorySignalManagerContext());
|
|
34
|
+
await host.open(new Context());
|
|
35
|
+
await host.close();
|
|
36
|
+
});
|
|
37
|
+
|
|
32
38
|
test('queryCredentials', async () => {
|
|
33
39
|
const host = createServiceHost(new Config(), new MemorySignalManagerContext());
|
|
34
40
|
await host.open(new Context());
|
|
@@ -8,15 +8,8 @@ import { Event, synchronized } from '@dxos/async';
|
|
|
8
8
|
import { clientServiceBundle, defaultKey, type ClientServices, Properties } from '@dxos/client-protocol';
|
|
9
9
|
import { type Config } from '@dxos/config';
|
|
10
10
|
import { Context } from '@dxos/context';
|
|
11
|
-
import {
|
|
12
|
-
DataServiceImpl,
|
|
13
|
-
type ObjectStructure,
|
|
14
|
-
encodeReference,
|
|
15
|
-
type SpaceDoc,
|
|
16
|
-
type LevelDB,
|
|
17
|
-
} from '@dxos/echo-pipeline';
|
|
11
|
+
import { type ObjectStructure, encodeReference, type SpaceDoc, type LevelDB } from '@dxos/echo-pipeline';
|
|
18
12
|
import { getTypeReference } from '@dxos/echo-schema';
|
|
19
|
-
import { QueryServiceImpl } from '@dxos/indexing';
|
|
20
13
|
import { invariant } from '@dxos/invariant';
|
|
21
14
|
import { PublicKey } from '@dxos/keys';
|
|
22
15
|
import { log } from '@dxos/log';
|
|
@@ -83,7 +76,6 @@ export class ClientServicesHost {
|
|
|
83
76
|
private readonly _systemService: SystemServiceImpl;
|
|
84
77
|
private readonly _loggingService: LoggingServiceImpl;
|
|
85
78
|
private readonly _tracingService = TRACE_PROCESSOR.createTraceSender();
|
|
86
|
-
private _queryService!: QueryServiceImpl;
|
|
87
79
|
|
|
88
80
|
private _config?: Config;
|
|
89
81
|
private readonly _statusUpdate = new Event<void>();
|
|
@@ -246,13 +238,13 @@ export class ClientServicesHost {
|
|
|
246
238
|
this._opening = true;
|
|
247
239
|
log('opening...', { lockKey: this._resourceLock?.lockKey });
|
|
248
240
|
|
|
241
|
+
await this._resourceLock?.acquire();
|
|
242
|
+
|
|
249
243
|
if (!this._level) {
|
|
250
244
|
this._level = await createLevel(this._config.get('runtime.client.storage', {})!);
|
|
251
245
|
}
|
|
252
246
|
await this._level.open();
|
|
253
247
|
|
|
254
|
-
await this._resourceLock?.acquire();
|
|
255
|
-
|
|
256
248
|
await this._loggingService.open();
|
|
257
249
|
|
|
258
250
|
this._serviceContext = new ServiceContext(
|
|
@@ -263,12 +255,6 @@ export class ClientServicesHost {
|
|
|
263
255
|
this._runtimeParams,
|
|
264
256
|
);
|
|
265
257
|
|
|
266
|
-
this._queryService = new QueryServiceImpl({
|
|
267
|
-
indexer: this._serviceContext.indexer,
|
|
268
|
-
automergeHost: this._serviceContext.automergeHost,
|
|
269
|
-
});
|
|
270
|
-
await this._queryService.open(ctx);
|
|
271
|
-
|
|
272
258
|
this._serviceRegistry.setServices({
|
|
273
259
|
SystemService: this._systemService,
|
|
274
260
|
|
|
@@ -292,9 +278,8 @@ export class ClientServicesHost {
|
|
|
292
278
|
},
|
|
293
279
|
),
|
|
294
280
|
|
|
295
|
-
DataService:
|
|
296
|
-
|
|
297
|
-
QueryService: this._queryService,
|
|
281
|
+
DataService: this._serviceContext.echoHost.dataService,
|
|
282
|
+
QueryService: this._serviceContext.echoHost.queryService,
|
|
298
283
|
|
|
299
284
|
NetworkService: new NetworkServiceImpl(this._serviceContext.networkManager, this._serviceContext.signalManager),
|
|
300
285
|
|
|
@@ -344,7 +329,6 @@ export class ClientServicesHost {
|
|
|
344
329
|
await this._devtoolsProxy?.close();
|
|
345
330
|
this._serviceRegistry.setServices({ SystemService: this._systemService });
|
|
346
331
|
await this._loggingService.close();
|
|
347
|
-
await this._queryService.close();
|
|
348
332
|
await this._serviceContext.close();
|
|
349
333
|
await this._level?.close();
|
|
350
334
|
this._open = false;
|
|
@@ -373,7 +357,7 @@ export class ClientServicesHost {
|
|
|
373
357
|
|
|
374
358
|
const automergeIndex = space.automergeSpaceState.rootUrl;
|
|
375
359
|
invariant(automergeIndex);
|
|
376
|
-
const document = await this._serviceContext.
|
|
360
|
+
const document = await this._serviceContext.echoHost.automergeRepo.find<SpaceDoc>(automergeIndex as any);
|
|
377
361
|
await document.whenReady();
|
|
378
362
|
|
|
379
363
|
// TODO(dmaretskyi): Better API for low-level data access.
|
|
@@ -393,7 +377,7 @@ export class ClientServicesHost {
|
|
|
393
377
|
assignDeep(doc, ['objects', propertiesId], properties);
|
|
394
378
|
});
|
|
395
379
|
|
|
396
|
-
await this._serviceContext.
|
|
380
|
+
await this._serviceContext.echoHost.flush();
|
|
397
381
|
|
|
398
382
|
return identity;
|
|
399
383
|
}
|
|
@@ -20,7 +20,7 @@ describe('DataSpaceManager', () => {
|
|
|
20
20
|
|
|
21
21
|
const peer = builder.createPeer();
|
|
22
22
|
await peer.createIdentity();
|
|
23
|
-
await openAndClose(peer.
|
|
23
|
+
await openAndClose(peer.echoHost, peer.dataSpaceManager);
|
|
24
24
|
|
|
25
25
|
const space = await peer.dataSpaceManager.createSpace();
|
|
26
26
|
|
|
@@ -42,7 +42,7 @@ describe('DataSpaceManager', () => {
|
|
|
42
42
|
const peer2 = builder.createPeer();
|
|
43
43
|
await peer2.createIdentity();
|
|
44
44
|
|
|
45
|
-
await openAndClose(peer1.
|
|
45
|
+
await openAndClose(peer1.echoHost, peer1.dataSpaceManager, peer2.echoHost, peer2.dataSpaceManager);
|
|
46
46
|
|
|
47
47
|
const space1 = await peer1.dataSpaceManager.createSpace();
|
|
48
48
|
await space1.inner.controlPipeline.state.waitUntilTimeframe(space1.inner.controlPipeline.state.endTimeframe);
|
|
@@ -111,7 +111,7 @@ describe('DataSpaceManager', () => {
|
|
|
111
111
|
await peer2.createIdentity();
|
|
112
112
|
await peer2.dataSpaceManager.open();
|
|
113
113
|
|
|
114
|
-
await openAndClose(peer1.
|
|
114
|
+
await openAndClose(peer1.echoHost, peer1.dataSpaceManager, peer2.echoHost, peer2.dataSpaceManager);
|
|
115
115
|
|
|
116
116
|
const space1 = await peer1.dataSpaceManager.createSpace();
|
|
117
117
|
await space1.inner.controlPipeline.state.waitUntilTimeframe(space1.inner.controlPipeline.state.endTimeframe);
|
|
@@ -153,7 +153,7 @@ describe('DataSpaceManager', () => {
|
|
|
153
153
|
|
|
154
154
|
const peer = builder.createPeer();
|
|
155
155
|
await peer.createIdentity();
|
|
156
|
-
await openAndClose(peer.
|
|
156
|
+
await openAndClose(peer.echoHost, peer.dataSpaceManager);
|
|
157
157
|
|
|
158
158
|
const space = await peer.dataSpaceManager.createSpace();
|
|
159
159
|
await space.inner.controlPipeline.state.waitUntilTimeframe(space.inner.controlPipeline.state.endTimeframe);
|
|
@@ -5,7 +5,8 @@
|
|
|
5
5
|
import { Event, synchronized, trackLeaks } from '@dxos/async';
|
|
6
6
|
import { Context, cancelWithContext } from '@dxos/context';
|
|
7
7
|
import { getCredentialAssertion, type CredentialSigner, type DelegateInvitationCredential } from '@dxos/credentials';
|
|
8
|
-
import { type
|
|
8
|
+
import { type EchoHost } from '@dxos/echo-db';
|
|
9
|
+
import { type MetadataStore, type Space, type SpaceManager } from '@dxos/echo-pipeline';
|
|
9
10
|
import { type FeedStore } from '@dxos/feed-store';
|
|
10
11
|
import { invariant } from '@dxos/invariant';
|
|
11
12
|
import { type Keyring } from '@dxos/keyring';
|
|
@@ -79,7 +80,7 @@ export class DataSpaceManager {
|
|
|
79
80
|
private readonly _keyring: Keyring,
|
|
80
81
|
private readonly _signingContext: SigningContext,
|
|
81
82
|
private readonly _feedStore: FeedStore<FeedMessage>,
|
|
82
|
-
private readonly
|
|
83
|
+
private readonly _echoHost: EchoHost,
|
|
83
84
|
private readonly _invitationsManager: InvitationsManager,
|
|
84
85
|
params?: DataSpaceManagerRuntimeParams,
|
|
85
86
|
) {
|
|
@@ -152,14 +153,10 @@ export class DataSpaceManager {
|
|
|
152
153
|
|
|
153
154
|
log('creating space...', { spaceKey });
|
|
154
155
|
|
|
155
|
-
const
|
|
156
|
-
automergeRoot.change((doc: any) => {
|
|
157
|
-
doc.access = { spaceKey: spaceKey.toHex() };
|
|
158
|
-
});
|
|
159
|
-
|
|
156
|
+
const automergeRootUrl = await this._echoHost.createSpaceRoot(spaceKey);
|
|
160
157
|
const space = await this._constructSpace(metadata);
|
|
161
158
|
|
|
162
|
-
const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner,
|
|
159
|
+
const credentials = await spaceGenesis(this._keyring, this._signingContext, space.inner, automergeRootUrl);
|
|
163
160
|
await this._metadataStore.addSpace(metadata);
|
|
164
161
|
|
|
165
162
|
const memberCredential = credentials[1];
|
|
@@ -243,8 +240,8 @@ export class DataSpaceManager {
|
|
|
243
240
|
gossip.createExtension({ remotePeerId: session.remotePeerId }),
|
|
244
241
|
);
|
|
245
242
|
session.addExtension('dxos.mesh.teleport.notarization', dataSpace.notarizationPlugin.createExtension());
|
|
246
|
-
this.
|
|
247
|
-
session.addExtension('dxos.mesh.teleport.automerge', this.
|
|
243
|
+
this._echoHost.authorizeDevice(space.key, session.remotePeerId);
|
|
244
|
+
session.addExtension('dxos.mesh.teleport.automerge', this._echoHost.createReplicationExtension());
|
|
248
245
|
},
|
|
249
246
|
onAuthFailure: () => {
|
|
250
247
|
log.warn('auth failure');
|
|
@@ -265,6 +262,7 @@ export class DataSpaceManager {
|
|
|
265
262
|
presence,
|
|
266
263
|
keyring: this._keyring,
|
|
267
264
|
feedStore: this._feedStore,
|
|
265
|
+
echoHost: this._echoHost,
|
|
268
266
|
signingContext: this._signingContext,
|
|
269
267
|
callbacks: {
|
|
270
268
|
beforeReady: async () => {
|
|
@@ -282,7 +280,6 @@ export class DataSpaceManager {
|
|
|
282
280
|
},
|
|
283
281
|
},
|
|
284
282
|
cache: metadata.cache,
|
|
285
|
-
automergeHost: this._automergeHost,
|
|
286
283
|
});
|
|
287
284
|
|
|
288
285
|
if (metadata.state !== SpaceState.INACTIVE) {
|
|
@@ -6,13 +6,8 @@ import { Event, asyncTimeout, scheduleTask, sleep, synchronized, trackLeaks } fr
|
|
|
6
6
|
import { AUTH_TIMEOUT } from '@dxos/client-protocol';
|
|
7
7
|
import { cancelWithContext, Context, ContextDisposedError } from '@dxos/context';
|
|
8
8
|
import { timed, warnAfterTimeout } from '@dxos/debug';
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
type Space,
|
|
12
|
-
createMappedFeedWriter,
|
|
13
|
-
type AutomergeHost,
|
|
14
|
-
type SpaceDoc,
|
|
15
|
-
} from '@dxos/echo-pipeline';
|
|
9
|
+
import { type EchoHost } from '@dxos/echo-db';
|
|
10
|
+
import { type MetadataStore, type Space, createMappedFeedWriter, type SpaceDoc } from '@dxos/echo-pipeline';
|
|
16
11
|
import { AutomergeDocumentLoaderImpl } from '@dxos/echo-pipeline';
|
|
17
12
|
import { TYPE_PROPERTIES } from '@dxos/echo-schema';
|
|
18
13
|
import { type FeedStore } from '@dxos/feed-store';
|
|
@@ -66,10 +61,10 @@ export type DataSpaceParams = {
|
|
|
66
61
|
presence: Presence;
|
|
67
62
|
keyring: Keyring;
|
|
68
63
|
feedStore: FeedStore<FeedMessage>;
|
|
64
|
+
echoHost: EchoHost;
|
|
69
65
|
signingContext: SigningContext;
|
|
70
66
|
callbacks?: DataSpaceCallbacks;
|
|
71
67
|
cache?: SpaceCache;
|
|
72
|
-
automergeHost: AutomergeHost;
|
|
73
68
|
};
|
|
74
69
|
|
|
75
70
|
export type CreateEpochOptions = {
|
|
@@ -92,7 +87,7 @@ export class DataSpace {
|
|
|
92
87
|
private readonly _notarizationPlugin = new NotarizationPlugin();
|
|
93
88
|
private readonly _callbacks: DataSpaceCallbacks;
|
|
94
89
|
private readonly _cache?: SpaceCache = undefined;
|
|
95
|
-
private readonly
|
|
90
|
+
private readonly _echoHost: EchoHost;
|
|
96
91
|
|
|
97
92
|
// TODO(dmaretskyi): Move into Space?
|
|
98
93
|
private readonly _automergeSpaceState = new AutomergeSpaceState((rootUrl) => this._onNewAutomergeRoot(rootUrl));
|
|
@@ -120,7 +115,7 @@ export class DataSpace {
|
|
|
120
115
|
this._metadataStore = params.metadataStore;
|
|
121
116
|
this._signingContext = params.signingContext;
|
|
122
117
|
this._callbacks = params.callbacks ?? {};
|
|
123
|
-
this.
|
|
118
|
+
this._echoHost = params.echoHost;
|
|
124
119
|
|
|
125
120
|
this.authVerifier = new TrustedKeySetAuthVerifier({
|
|
126
121
|
trustedKeysProvider: () =>
|
|
@@ -363,8 +358,8 @@ export class DataSpace {
|
|
|
363
358
|
|
|
364
359
|
private _onNewAutomergeRoot(rootUrl: string) {
|
|
365
360
|
log('loading automerge root doc for space', { space: this.key, rootUrl });
|
|
366
|
-
this.
|
|
367
|
-
const handle = this.
|
|
361
|
+
this._echoHost.replicateDocument(rootUrl);
|
|
362
|
+
const handle = this._echoHost.automergeRepo.find(rootUrl as any);
|
|
368
363
|
|
|
369
364
|
queueMicrotask(async () => {
|
|
370
365
|
try {
|
|
@@ -419,7 +414,7 @@ export class DataSpace {
|
|
|
419
414
|
break;
|
|
420
415
|
case CreateEpochRequest.Migration.INIT_AUTOMERGE:
|
|
421
416
|
{
|
|
422
|
-
const document = this.
|
|
417
|
+
const document = this._echoHost.automergeRepo.create();
|
|
423
418
|
// TODO(dmaretskyi): Unify epoch construction.
|
|
424
419
|
epoch = {
|
|
425
420
|
previousId: this._automergeSpaceState.lastEpoch?.id,
|
|
@@ -432,9 +427,9 @@ export class DataSpace {
|
|
|
432
427
|
case CreateEpochRequest.Migration.PRUNE_AUTOMERGE_ROOT_HISTORY:
|
|
433
428
|
{
|
|
434
429
|
const currentRootUrl = this._automergeSpaceState.rootUrl;
|
|
435
|
-
const rootHandle = this.
|
|
430
|
+
const rootHandle = this._echoHost.automergeRepo.find(currentRootUrl as any);
|
|
436
431
|
await cancelWithContext(this._ctx, asyncTimeout(rootHandle.whenReady(), 10_000));
|
|
437
|
-
const newRoot = this.
|
|
432
|
+
const newRoot = this._echoHost.automergeRepo.create(rootHandle.docSync());
|
|
438
433
|
invariant(typeof newRoot.url === 'string' && newRoot.url.length > 0);
|
|
439
434
|
// TODO(dmaretskyi): Unify epoch construction.
|
|
440
435
|
epoch = {
|
|
@@ -450,7 +445,7 @@ export class DataSpace {
|
|
|
450
445
|
log.info('Fragmenting');
|
|
451
446
|
|
|
452
447
|
const currentRootUrl = this._automergeSpaceState.rootUrl;
|
|
453
|
-
const rootHandle = this.
|
|
448
|
+
const rootHandle = this._echoHost.automergeRepo.find<SpaceDoc>(currentRootUrl as any);
|
|
454
449
|
await cancelWithContext(this._ctx, asyncTimeout(rootHandle.whenReady(), 10_000));
|
|
455
450
|
|
|
456
451
|
// Find properties object.
|
|
@@ -461,11 +456,11 @@ export class DataSpace {
|
|
|
461
456
|
|
|
462
457
|
// Create a new space doc with the properties object.
|
|
463
458
|
const newSpaceDoc: SpaceDoc = { ...rootHandle.docSync(), objects: Object.fromEntries([properties]) };
|
|
464
|
-
const newRoot = this.
|
|
459
|
+
const newRoot = this._echoHost.automergeRepo.create(newSpaceDoc);
|
|
465
460
|
invariant(typeof newRoot.url === 'string' && newRoot.url.length > 0);
|
|
466
461
|
|
|
467
462
|
// Create new automerge documents for all objects.
|
|
468
|
-
const docLoader = new AutomergeDocumentLoaderImpl(this.key, this.
|
|
463
|
+
const docLoader = new AutomergeDocumentLoaderImpl(this.key, this._echoHost.automergeRepo);
|
|
469
464
|
await docLoader.loadSpaceRootDocHandle(this._ctx, { rootUrl: newRoot.url });
|
|
470
465
|
|
|
471
466
|
otherObjects.forEach(([key, value]) => {
|
|
@@ -14,6 +14,7 @@ export const createLevel = async (config: Runtime.Client.Storage) => {
|
|
|
14
14
|
const persistent = isPersistent(config);
|
|
15
15
|
const storagePath = persistent ? path.join(getRootPath(config), 'level') : `/tmp/dxos-${PublicKey.random().toHex()}`;
|
|
16
16
|
const level = new Level<string, string>(storagePath);
|
|
17
|
+
// TODO(dmaretskyi): This function shouldn't call open - .
|
|
17
18
|
await level.open();
|
|
18
19
|
return level;
|
|
19
20
|
};
|
|
@@ -6,14 +6,8 @@ import { type Config } from '@dxos/config';
|
|
|
6
6
|
import { Context } from '@dxos/context';
|
|
7
7
|
import { createCredentialSignerWithChain, CredentialGenerator } from '@dxos/credentials';
|
|
8
8
|
import { failUndefined } from '@dxos/debug';
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
MetadataStore,
|
|
12
|
-
type LevelDB,
|
|
13
|
-
SnapshotStore,
|
|
14
|
-
SpaceManager,
|
|
15
|
-
valueEncoding,
|
|
16
|
-
} from '@dxos/echo-pipeline';
|
|
9
|
+
import { EchoHost } from '@dxos/echo-db';
|
|
10
|
+
import { MetadataStore, type LevelDB, SnapshotStore, SpaceManager, valueEncoding } from '@dxos/echo-pipeline';
|
|
17
11
|
import { createTestLevel } from '@dxos/echo-pipeline/testing';
|
|
18
12
|
import { FeedFactory, FeedStore } from '@dxos/feed-store';
|
|
19
13
|
import { Keyring } from '@dxos/keyring';
|
|
@@ -105,7 +99,7 @@ export type TestPeerProps = {
|
|
|
105
99
|
snapshotStore?: SnapshotStore;
|
|
106
100
|
signingContext?: SigningContext;
|
|
107
101
|
blobStore?: BlobStore;
|
|
108
|
-
|
|
102
|
+
echoHost?: EchoHost;
|
|
109
103
|
invitationsManager?: InvitationsManager;
|
|
110
104
|
};
|
|
111
105
|
|
|
@@ -178,9 +172,10 @@ export class TestPeer {
|
|
|
178
172
|
return this._props.signingContext ?? failUndefined();
|
|
179
173
|
}
|
|
180
174
|
|
|
181
|
-
get
|
|
182
|
-
return (this._props.
|
|
183
|
-
|
|
175
|
+
get echoHost() {
|
|
176
|
+
return (this._props.echoHost ??= new EchoHost({
|
|
177
|
+
kv: this.level,
|
|
178
|
+
storage: this.storage,
|
|
184
179
|
}));
|
|
185
180
|
}
|
|
186
181
|
|
|
@@ -191,7 +186,7 @@ export class TestPeer {
|
|
|
191
186
|
this.keyring,
|
|
192
187
|
this.identity,
|
|
193
188
|
this.feedStore,
|
|
194
|
-
this.
|
|
189
|
+
this.echoHost,
|
|
195
190
|
this.invitationsManager,
|
|
196
191
|
));
|
|
197
192
|
}
|
|
@@ -120,7 +120,9 @@ export class WorkerRuntime {
|
|
|
120
120
|
this._sessions.delete(session);
|
|
121
121
|
if (this._sessions.size === 0) {
|
|
122
122
|
// Terminate the worker when all sessions are closed.
|
|
123
|
-
self
|
|
123
|
+
if (globalThis.self) {
|
|
124
|
+
self.close();
|
|
125
|
+
}
|
|
124
126
|
} else {
|
|
125
127
|
this._reconnectWebrtc();
|
|
126
128
|
}
|
package/src/version.ts
CHANGED