@dxos/client-services 0.4.7 → 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.
Files changed (44) hide show
  1. package/dist/lib/browser/{chunk-NI6XJLUJ.mjs → chunk-EQPR3Z5Y.mjs} +413 -158
  2. package/dist/lib/browser/chunk-EQPR3Z5Y.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +3 -1
  4. package/dist/lib/browser/index.mjs.map +1 -1
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/packlets/testing/index.mjs +1 -1
  7. package/dist/lib/node/{chunk-RH65IX2V.cjs → chunk-VDSDEN45.cjs} +396 -144
  8. package/dist/lib/node/chunk-VDSDEN45.cjs.map +7 -0
  9. package/dist/lib/node/index.cjs +39 -37
  10. package/dist/lib/node/index.cjs.map +1 -1
  11. package/dist/lib/node/meta.json +1 -1
  12. package/dist/lib/node/packlets/testing/index.cjs +8 -8
  13. package/dist/types/src/packlets/indexing/index.d.ts +2 -0
  14. package/dist/types/src/packlets/indexing/index.d.ts.map +1 -0
  15. package/dist/types/src/packlets/indexing/util.d.ts +15 -0
  16. package/dist/types/src/packlets/indexing/util.d.ts.map +1 -0
  17. package/dist/types/src/packlets/invitations/invitations-handler.d.ts +1 -0
  18. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  19. package/dist/types/src/packlets/invitations/invitations-service.d.ts +9 -1
  20. package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
  21. package/dist/types/src/packlets/services/service-context.d.ts +2 -1
  22. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  23. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  24. package/dist/types/src/packlets/spaces/automerge-space-state.d.ts +2 -0
  25. package/dist/types/src/packlets/spaces/automerge-space-state.d.ts.map +1 -1
  26. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  27. package/dist/types/src/packlets/spaces/spaces-service.d.ts +1 -1
  28. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  29. package/dist/types/src/version.d.ts +1 -1
  30. package/dist/types/src/version.d.ts.map +1 -1
  31. package/package.json +37 -35
  32. package/src/packlets/identity/identity-manager.ts +1 -1
  33. package/src/packlets/indexing/index.ts +5 -0
  34. package/src/packlets/indexing/util.ts +89 -0
  35. package/src/packlets/invitations/invitations-handler.ts +37 -2
  36. package/src/packlets/invitations/invitations-service.ts +83 -5
  37. package/src/packlets/services/service-context.ts +13 -2
  38. package/src/packlets/services/service-host.ts +15 -2
  39. package/src/packlets/spaces/automerge-space-state.ts +15 -0
  40. package/src/packlets/spaces/data-space.ts +33 -11
  41. package/src/packlets/spaces/spaces-service.ts +2 -2
  42. package/src/version.ts +1 -5
  43. package/dist/lib/browser/chunk-NI6XJLUJ.mjs.map +0 -7
  44. package/dist/lib/node/chunk-RH65IX2V.cjs.map +0 -7
@@ -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(this._serviceContext.invitations, (invitation) =>
260
- this._serviceContext.getInvitationHandler(invitation),
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
- const document = this._automergeHost.repo.create();
431
- epoch = {
432
- previousId: this._automergeSpaceState.lastEpoch?.id,
433
- number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
434
- timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe(),
435
- automergeRoot: document.url,
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,5 +1 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- export const DXOS_VERSION = '0.4.7'; // {x-release-please-version}
1
+ export const DXOS_VERSION = "0.4.8-main.00e6f19";