@dxos/client-services 0.4.7-next.f4b92be → 0.4.8-main.00e6f19
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-NTKD4OQC.mjs → chunk-EQPR3Z5Y.mjs} +426 -164
- package/dist/lib/browser/chunk-EQPR3Z5Y.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +3 -1
- package/dist/lib/browser/index.mjs.map +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/packlets/testing/index.mjs +1 -1
- package/dist/lib/node/{chunk-GCIW4VHF.cjs → chunk-VDSDEN45.cjs} +405 -146
- package/dist/lib/node/chunk-VDSDEN45.cjs.map +7 -0
- package/dist/lib/node/index.cjs +39 -37
- package/dist/lib/node/index.cjs.map +1 -1
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/packlets/testing/index.cjs +8 -8
- package/dist/types/src/packlets/indexing/index.d.ts +2 -0
- package/dist/types/src/packlets/indexing/index.d.ts.map +1 -0
- package/dist/types/src/packlets/indexing/util.d.ts +15 -0
- package/dist/types/src/packlets/indexing/util.d.ts.map +1 -0
- package/dist/types/src/packlets/invitations/invitations-handler.d.ts +1 -0
- package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitations-service.d.ts +9 -1
- package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
- package/dist/types/src/packlets/logging/logging-service.d.ts +1 -0
- package/dist/types/src/packlets/logging/logging-service.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-context.d.ts +2 -1
- package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/automerge-space-state.d.ts +2 -0
- package/dist/types/src/packlets/spaces/automerge-space-state.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/spaces-service.d.ts +1 -1
- package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
- package/dist/types/src/version.d.ts +1 -1
- package/package.json +37 -35
- package/src/packlets/identity/identity-manager.ts +1 -1
- package/src/packlets/indexing/index.ts +5 -0
- package/src/packlets/indexing/util.ts +89 -0
- package/src/packlets/invitations/invitations-handler.ts +37 -2
- package/src/packlets/invitations/invitations-service.ts +83 -5
- package/src/packlets/logging/logging-service.ts +9 -2
- package/src/packlets/services/service-context.ts +13 -2
- package/src/packlets/services/service-host.ts +15 -2
- package/src/packlets/spaces/automerge-space-state.ts +15 -0
- package/src/packlets/spaces/data-space.ts +33 -11
- package/src/packlets/spaces/spaces-service.ts +2 -2
- package/src/version.ts +1 -1
- package/dist/lib/browser/chunk-NTKD4OQC.mjs.map +0 -7
- package/dist/lib/node/chunk-GCIW4VHF.cjs.map +0 -7
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { Event } from '@dxos/async';
|
|
6
6
|
import { Stream } from '@dxos/codec-protobuf';
|
|
7
|
+
import { PublicKey } from '@dxos/keys';
|
|
7
8
|
import {
|
|
8
9
|
type LogLevel,
|
|
9
10
|
type LogProcessor,
|
|
@@ -21,14 +22,15 @@ import {
|
|
|
21
22
|
type QueryMetricsRequest,
|
|
22
23
|
type QueryMetricsResponse,
|
|
23
24
|
} from '@dxos/protocols/proto/dxos/client/services';
|
|
24
|
-
import { jsonify, numericalValues, tracer } from '@dxos/util';
|
|
25
|
+
import { getDebugName, jsonify, numericalValues, tracer } from '@dxos/util';
|
|
25
26
|
|
|
26
27
|
/**
|
|
27
28
|
* Logging service used to spy on logs of the host.
|
|
28
29
|
*/
|
|
29
30
|
export class LoggingServiceImpl implements LoggingService {
|
|
30
31
|
private readonly _logs = new Event<NaturalLogEntry>();
|
|
31
|
-
private readonly _started =
|
|
32
|
+
private readonly _started = Date.now();
|
|
33
|
+
private readonly _sessionId = PublicKey.random().toHex();
|
|
32
34
|
|
|
33
35
|
async open() {
|
|
34
36
|
log.runtimeConfig.processors.push(this._logProcessor);
|
|
@@ -116,6 +118,11 @@ export class LoggingServiceImpl implements LoggingService {
|
|
|
116
118
|
// TODO(dmaretskyi): Fix proto.
|
|
117
119
|
file: entry.meta?.F ?? '',
|
|
118
120
|
line: entry.meta?.L ?? 0,
|
|
121
|
+
scope: {
|
|
122
|
+
hostSessionId: this._sessionId,
|
|
123
|
+
uptimeSeconds: (Date.now() - this._started) / 1000,
|
|
124
|
+
name: getDebugName(entry.meta?.S),
|
|
125
|
+
},
|
|
119
126
|
},
|
|
120
127
|
};
|
|
121
128
|
|
|
@@ -14,8 +14,8 @@ import {
|
|
|
14
14
|
SnapshotStore,
|
|
15
15
|
AutomergeHost,
|
|
16
16
|
} from '@dxos/echo-pipeline';
|
|
17
|
-
import { IndexMetadataStore } from '@dxos/echo-schema';
|
|
18
17
|
import { FeedFactory, FeedStore } from '@dxos/feed-store';
|
|
18
|
+
import { IndexMetadataStore, IndexStore, Indexer } from '@dxos/indexing';
|
|
19
19
|
import { invariant } from '@dxos/invariant';
|
|
20
20
|
import { Keyring } from '@dxos/keyring';
|
|
21
21
|
import { PublicKey } from '@dxos/keys';
|
|
@@ -38,6 +38,7 @@ import {
|
|
|
38
38
|
type IdentityManagerRuntimeParams,
|
|
39
39
|
type JoinIdentityParams,
|
|
40
40
|
} from '../identity';
|
|
41
|
+
import { createGetAllDocuments, createLoadDocuments } from '../indexing';
|
|
41
42
|
import {
|
|
42
43
|
DeviceInvitationProtocol,
|
|
43
44
|
InvitationsHandler,
|
|
@@ -70,6 +71,7 @@ export class ServiceContext {
|
|
|
70
71
|
public readonly invitations: InvitationsHandler;
|
|
71
72
|
public readonly automergeHost: AutomergeHost;
|
|
72
73
|
public readonly indexMetadata: IndexMetadataStore;
|
|
74
|
+
public readonly indexer: Indexer;
|
|
73
75
|
|
|
74
76
|
// Initialized after identity is initialized.
|
|
75
77
|
public dataSpaceManager?: DataSpaceManager;
|
|
@@ -92,7 +94,6 @@ export class ServiceContext {
|
|
|
92
94
|
) {
|
|
93
95
|
// TODO(burdon): Move strings to constants.
|
|
94
96
|
this.metadataStore = new MetadataStore(storage.createDirectory('metadata'));
|
|
95
|
-
this.indexMetadata = new IndexMetadataStore({ directory: storage.createDirectory('index-metadata') });
|
|
96
97
|
this.snapshotStore = new SnapshotStore(storage.createDirectory('snapshots'));
|
|
97
98
|
this.blobStore = new BlobStore(storage.createDirectory('blobs'));
|
|
98
99
|
|
|
@@ -125,11 +126,20 @@ export class ServiceContext {
|
|
|
125
126
|
this._runtimeParams as IdentityManagerRuntimeParams,
|
|
126
127
|
);
|
|
127
128
|
|
|
129
|
+
this.indexMetadata = new IndexMetadataStore({ directory: storage.createDirectory('index-metadata') });
|
|
130
|
+
|
|
128
131
|
this.automergeHost = new AutomergeHost({
|
|
129
132
|
directory: storage.createDirectory('automerge'),
|
|
130
133
|
metadata: this.indexMetadata,
|
|
131
134
|
});
|
|
132
135
|
|
|
136
|
+
this.indexer = new Indexer({
|
|
137
|
+
indexStore: new IndexStore({ directory: storage.createDirectory('index-store') }),
|
|
138
|
+
metadataStore: this.indexMetadata,
|
|
139
|
+
loadDocuments: createLoadDocuments(this.automergeHost),
|
|
140
|
+
getAllDocuments: createGetAllDocuments(this.automergeHost),
|
|
141
|
+
});
|
|
142
|
+
|
|
133
143
|
this.invitations = new InvitationsHandler(this.networkManager);
|
|
134
144
|
|
|
135
145
|
// TODO(burdon): _initialize called in multiple places.
|
|
@@ -178,6 +188,7 @@ export class ServiceContext {
|
|
|
178
188
|
await this.signalManager.close();
|
|
179
189
|
this.dataServiceSubscriptions.clear();
|
|
180
190
|
await this.metadataStore.close();
|
|
191
|
+
await this.indexer.destroy();
|
|
181
192
|
log('closed');
|
|
182
193
|
}
|
|
183
194
|
|
|
@@ -9,6 +9,7 @@ import { Context } from '@dxos/context';
|
|
|
9
9
|
import { DocumentModel } from '@dxos/document-model';
|
|
10
10
|
import { DataServiceImpl } from '@dxos/echo-pipeline';
|
|
11
11
|
import { type TypedObject, getRawDoc, type SpaceDoc, getAutomergeObjectCore } from '@dxos/echo-schema';
|
|
12
|
+
import { IndexServiceImpl } from '@dxos/indexing';
|
|
12
13
|
import { invariant } from '@dxos/invariant';
|
|
13
14
|
import { PublicKey } from '@dxos/keys';
|
|
14
15
|
import { log } from '@dxos/log';
|
|
@@ -256,8 +257,10 @@ export class ClientServicesHost {
|
|
|
256
257
|
(profile) => this._serviceContext.broadcastProfileUpdate(profile),
|
|
257
258
|
),
|
|
258
259
|
|
|
259
|
-
InvitationsService: new InvitationsServiceImpl(
|
|
260
|
-
this._serviceContext.
|
|
260
|
+
InvitationsService: new InvitationsServiceImpl(
|
|
261
|
+
this._serviceContext.invitations,
|
|
262
|
+
(invitation) => this._serviceContext.getInvitationHandler(invitation),
|
|
263
|
+
this._serviceContext.metadataStore,
|
|
261
264
|
),
|
|
262
265
|
|
|
263
266
|
DevicesService: new DevicesServiceImpl(this._serviceContext.identityManager),
|
|
@@ -277,6 +280,11 @@ export class ClientServicesHost {
|
|
|
277
280
|
this._serviceContext.automergeHost,
|
|
278
281
|
),
|
|
279
282
|
|
|
283
|
+
IndexService: new IndexServiceImpl({
|
|
284
|
+
indexer: this._serviceContext.indexer,
|
|
285
|
+
automergeHost: this._serviceContext.automergeHost,
|
|
286
|
+
}),
|
|
287
|
+
|
|
280
288
|
NetworkService: new NetworkServiceImpl(this._serviceContext.networkManager, this._serviceContext.signalManager),
|
|
281
289
|
|
|
282
290
|
LoggingService: this._loggingService,
|
|
@@ -291,6 +299,11 @@ export class ClientServicesHost {
|
|
|
291
299
|
});
|
|
292
300
|
|
|
293
301
|
await this._serviceContext.open(ctx);
|
|
302
|
+
// TODO(nf): move to InvitationManager in ServiceContext?
|
|
303
|
+
invariant(this.serviceRegistry.services.InvitationsService);
|
|
304
|
+
const loadedInvitations = await this.serviceRegistry.services.InvitationsService.loadPersistentInvitations();
|
|
305
|
+
|
|
306
|
+
log('loaded persistent invitations', { count: loadedInvitations.invitations?.length });
|
|
294
307
|
|
|
295
308
|
const devtoolsProxy = this._config?.get('runtime.client.devtoolsProxy');
|
|
296
309
|
if (devtoolsProxy) {
|
|
@@ -9,6 +9,8 @@ export class AutomergeSpaceState implements CredentialProcessor {
|
|
|
9
9
|
public rootUrl: string | undefined = undefined;
|
|
10
10
|
public lastEpoch: SpecificCredential<Epoch> | undefined = undefined;
|
|
11
11
|
|
|
12
|
+
private _isProcessingRootDocs = false;
|
|
13
|
+
|
|
12
14
|
constructor(private readonly _onNewRoot: (rootUrl: string) => void) {}
|
|
13
15
|
|
|
14
16
|
async processCredential(credential: Credential) {
|
|
@@ -20,7 +22,20 @@ export class AutomergeSpaceState implements CredentialProcessor {
|
|
|
20
22
|
if (credential.subject.assertion.automergeRoot) {
|
|
21
23
|
this.rootUrl = credential.subject.assertion.automergeRoot;
|
|
22
24
|
|
|
25
|
+
if (this._isProcessingRootDocs) {
|
|
26
|
+
this._onNewRoot(this.rootUrl);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
startProcessingRootDocs() {
|
|
32
|
+
if (this._isProcessingRootDocs) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (this.rootUrl) {
|
|
23
37
|
this._onNewRoot(this.rootUrl);
|
|
24
38
|
}
|
|
39
|
+
this._isProcessingRootDocs = true;
|
|
25
40
|
}
|
|
26
41
|
}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { Event, scheduleTask, sleep, synchronized, trackLeaks } from '@dxos/async';
|
|
5
|
+
import { Event, asyncTimeout, scheduleTask, sleep, synchronized, trackLeaks } from '@dxos/async';
|
|
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';
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
type AutomergeHost,
|
|
16
16
|
} from '@dxos/echo-pipeline';
|
|
17
17
|
import { type FeedStore } from '@dxos/feed-store';
|
|
18
|
-
import { failedInvariant } from '@dxos/invariant';
|
|
18
|
+
import { failedInvariant, invariant } from '@dxos/invariant';
|
|
19
19
|
import { type Keyring } from '@dxos/keyring';
|
|
20
20
|
import { PublicKey } from '@dxos/keys';
|
|
21
21
|
import { log } from '@dxos/log';
|
|
@@ -276,6 +276,8 @@ export class DataSpace {
|
|
|
276
276
|
// Allow other tasks to run before loading the data pipeline.
|
|
277
277
|
await sleep(1);
|
|
278
278
|
|
|
279
|
+
this._automergeSpaceState.startProcessingRootDocs();
|
|
280
|
+
|
|
279
281
|
await this._inner.initializeDataPipeline();
|
|
280
282
|
|
|
281
283
|
this.metrics.dataPipelineOpen = new Date();
|
|
@@ -423,18 +425,38 @@ export class DataSpace {
|
|
|
423
425
|
case undefined:
|
|
424
426
|
case CreateEpochRequest.Migration.NONE:
|
|
425
427
|
{
|
|
428
|
+
// TODO(dmaretskyi): Unify epoch construction.
|
|
426
429
|
epoch = await this.dataPipeline.createEpoch();
|
|
427
430
|
}
|
|
428
431
|
break;
|
|
429
|
-
case CreateEpochRequest.Migration.INIT_AUTOMERGE:
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
432
|
+
case CreateEpochRequest.Migration.INIT_AUTOMERGE:
|
|
433
|
+
{
|
|
434
|
+
const document = this._automergeHost.repo.create();
|
|
435
|
+
// TODO(dmaretskyi): Unify epoch construction.
|
|
436
|
+
epoch = {
|
|
437
|
+
previousId: this._automergeSpaceState.lastEpoch?.id,
|
|
438
|
+
number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
|
|
439
|
+
timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe(),
|
|
440
|
+
automergeRoot: document.url,
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
break;
|
|
444
|
+
case CreateEpochRequest.Migration.PRUNE_AUTOMERGE_ROOT_HISTORY:
|
|
445
|
+
{
|
|
446
|
+
const currentRootUrl = this._automergeSpaceState.rootUrl;
|
|
447
|
+
const rootHandle = this._automergeHost.repo.find(currentRootUrl as any);
|
|
448
|
+
await cancelWithContext(this._ctx, asyncTimeout(rootHandle.whenReady(), 10_000));
|
|
449
|
+
const newRoot = this._automergeHost.repo.create(rootHandle.docSync());
|
|
450
|
+
invariant(typeof newRoot.url === 'string' && newRoot.url.length > 0);
|
|
451
|
+
// TODO(dmaretskyi): Unify epoch construction.
|
|
452
|
+
epoch = {
|
|
453
|
+
previousId: this._automergeSpaceState.lastEpoch?.id,
|
|
454
|
+
number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
|
|
455
|
+
timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe(),
|
|
456
|
+
automergeRoot: newRoot.url,
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
break;
|
|
438
460
|
}
|
|
439
461
|
|
|
440
462
|
if (!epoch) {
|
|
@@ -178,10 +178,10 @@ export class SpacesServiceImpl implements SpacesService {
|
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
180
|
|
|
181
|
-
async createEpoch({ spaceKey }: CreateEpochRequest) {
|
|
181
|
+
async createEpoch({ spaceKey, migration }: CreateEpochRequest) {
|
|
182
182
|
const dataSpaceManager = await this._getDataSpaceManager();
|
|
183
183
|
const space = dataSpaceManager.spaces.get(spaceKey) ?? raise(new SpaceNotFoundError(spaceKey));
|
|
184
|
-
await space.createEpoch();
|
|
184
|
+
await space.createEpoch({ migration });
|
|
185
185
|
}
|
|
186
186
|
|
|
187
187
|
private _serializeSpace(space: DataSpace): Space {
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const DXOS_VERSION = "0.4.
|
|
1
|
+
export const DXOS_VERSION = "0.4.8-main.00e6f19";
|