@dxos/client-services 0.8.2-main.fbd8ed0 → 0.8.2-staging.4d6ad0f

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 (100) hide show
  1. package/dist/lib/browser/{chunk-I3QLQXQD.mjs → chunk-AA2G5WEV.mjs} +375 -394
  2. package/dist/lib/browser/chunk-AA2G5WEV.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +1 -1
  4. package/dist/lib/browser/index.mjs.map +3 -3
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/lib/browser/testing/index.mjs +1 -1
  7. package/dist/lib/browser/testing/index.mjs.map +3 -3
  8. package/dist/lib/node/{chunk-Y747YVDI.cjs → chunk-JC3EZ3VA.cjs} +378 -386
  9. package/dist/lib/node/chunk-JC3EZ3VA.cjs.map +7 -0
  10. package/dist/lib/node/index.cjs +47 -47
  11. package/dist/lib/node/index.cjs.map +3 -3
  12. package/dist/lib/node/meta.json +1 -1
  13. package/dist/lib/node/testing/index.cjs +8 -8
  14. package/dist/lib/node/testing/index.cjs.map +3 -3
  15. package/dist/lib/node-esm/{chunk-XNCWQTDB.mjs → chunk-ZCHUTUNU.mjs} +375 -383
  16. package/dist/lib/node-esm/chunk-ZCHUTUNU.mjs.map +7 -0
  17. package/dist/lib/node-esm/index.mjs +1 -1
  18. package/dist/lib/node-esm/index.mjs.map +3 -3
  19. package/dist/lib/node-esm/meta.json +1 -1
  20. package/dist/lib/node-esm/testing/index.mjs +1 -1
  21. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  22. package/dist/types/src/packlets/agents/edge-agent-manager.d.ts.map +1 -1
  23. package/dist/types/src/packlets/identity/authenticator.d.ts.map +1 -1
  24. package/dist/types/src/packlets/identity/default-space-state-machine.d.ts.map +1 -1
  25. package/dist/types/src/packlets/identity/identity-manager.d.ts +2 -2
  26. package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
  27. package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts +1 -1
  28. package/dist/types/src/packlets/identity/identity-recovery-manager.d.ts.map +1 -1
  29. package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
  30. package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
  31. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -1
  32. package/dist/types/src/packlets/invitations/edge-invitation-handler.d.ts.map +1 -1
  33. package/dist/types/src/packlets/invitations/invitation-guest-extenstion.d.ts.map +1 -1
  34. package/dist/types/src/packlets/invitations/invitation-host-extension.d.ts.map +1 -1
  35. package/dist/types/src/packlets/invitations/invitation-topology.d.ts.map +1 -1
  36. package/dist/types/src/packlets/invitations/invitations-manager.d.ts.map +1 -1
  37. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +1 -1
  38. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
  39. package/dist/types/src/packlets/locks/browser.d.ts.map +1 -1
  40. package/dist/types/src/packlets/locks/node.d.ts.map +1 -1
  41. package/dist/types/src/packlets/logging/logging-service.d.ts.map +1 -1
  42. package/dist/types/src/packlets/network/network-service.d.ts.map +1 -1
  43. package/dist/types/src/packlets/services/client-rpc-server.d.ts.map +1 -1
  44. package/dist/types/src/packlets/services/service-context.d.ts +1 -0
  45. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  46. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  47. package/dist/types/src/packlets/services/service-registry.d.ts.map +1 -1
  48. package/dist/types/src/packlets/space-export/space-archive-writer.d.ts.map +1 -1
  49. package/dist/types/src/packlets/spaces/automerge-space-state.d.ts.map +1 -1
  50. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  51. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  52. package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts.map +1 -1
  53. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts.map +1 -1
  54. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  55. package/dist/types/src/packlets/system/system-service.d.ts.map +1 -1
  56. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  57. package/dist/types/src/packlets/worker/worker-runtime.d.ts.map +1 -1
  58. package/dist/types/src/packlets/worker/worker-session.d.ts.map +1 -1
  59. package/dist/types/src/version.d.ts +1 -1
  60. package/dist/types/src/version.d.ts.map +1 -1
  61. package/package.json +39 -39
  62. package/src/packlets/agents/edge-agent-manager.ts +6 -6
  63. package/src/packlets/identity/authenticator.ts +2 -2
  64. package/src/packlets/identity/default-space-state-machine.ts +1 -1
  65. package/src/packlets/identity/identity-manager.ts +13 -9
  66. package/src/packlets/identity/identity-recovery-manager.ts +6 -4
  67. package/src/packlets/identity/identity-service.ts +4 -4
  68. package/src/packlets/identity/identity.ts +5 -5
  69. package/src/packlets/invitations/device-invitation-protocol.ts +1 -1
  70. package/src/packlets/invitations/edge-invitation-handler.ts +3 -3
  71. package/src/packlets/invitations/invitation-guest-extenstion.ts +3 -3
  72. package/src/packlets/invitations/invitation-host-extension.ts +5 -5
  73. package/src/packlets/invitations/invitation-topology.ts +1 -1
  74. package/src/packlets/invitations/invitations-handler.ts +2 -2
  75. package/src/packlets/invitations/invitations-manager.ts +15 -4
  76. package/src/packlets/invitations/space-invitation-protocol.ts +1 -1
  77. package/src/packlets/locks/browser.ts +4 -4
  78. package/src/packlets/locks/node.ts +2 -2
  79. package/src/packlets/logging/logging-service.ts +2 -2
  80. package/src/packlets/network/network-service.ts +2 -2
  81. package/src/packlets/services/client-rpc-server.ts +2 -2
  82. package/src/packlets/services/service-context.ts +10 -6
  83. package/src/packlets/services/service-host.ts +8 -4
  84. package/src/packlets/services/service-registry.ts +3 -3
  85. package/src/packlets/space-export/space-archive-writer.ts +3 -3
  86. package/src/packlets/spaces/automerge-space-state.ts +3 -3
  87. package/src/packlets/spaces/data-space-manager.ts +14 -14
  88. package/src/packlets/spaces/data-space.ts +18 -18
  89. package/src/packlets/spaces/edge-feed-replicator.ts +12 -12
  90. package/src/packlets/spaces/notarization-plugin.test.ts +1 -1
  91. package/src/packlets/spaces/notarization-plugin.ts +18 -18
  92. package/src/packlets/spaces/spaces-service.ts +5 -5
  93. package/src/packlets/system/system-service.ts +2 -2
  94. package/src/packlets/testing/test-builder.ts +3 -3
  95. package/src/packlets/worker/worker-runtime.ts +4 -4
  96. package/src/packlets/worker/worker-session.ts +3 -3
  97. package/src/version.ts +1 -1
  98. package/dist/lib/browser/chunk-I3QLQXQD.mjs.map +0 -7
  99. package/dist/lib/node/chunk-Y747YVDI.cjs.map +0 -7
  100. package/dist/lib/node-esm/chunk-XNCWQTDB.mjs.map +0 -7
@@ -28,7 +28,7 @@ export class Lock implements ResourceLock {
28
28
  return this._lockPath;
29
29
  }
30
30
 
31
- async acquire() {
31
+ async acquire(): Promise<void> {
32
32
  log('acquiring lock...');
33
33
  this._fileHandle = await LockFile.acquire(this._lockPath);
34
34
 
@@ -37,7 +37,7 @@ export class Lock implements ResourceLock {
37
37
  log('acquired lock');
38
38
  }
39
39
 
40
- async release() {
40
+ async release(): Promise<void> {
41
41
  await this._onRelease?.();
42
42
  invariant(this._fileHandle, 'Lock is not acquired');
43
43
  await LockFile.release(this._fileHandle);
@@ -32,11 +32,11 @@ export class LoggingServiceImpl implements LoggingService {
32
32
  private readonly _started = Date.now();
33
33
  private readonly _sessionId = PublicKey.random().toHex();
34
34
 
35
- async open() {
35
+ async open(): Promise<void> {
36
36
  log.runtimeConfig.processors.push(this._logProcessor);
37
37
  }
38
38
 
39
- async close() {
39
+ async close(): Promise<void> {
40
40
  const index = log.runtimeConfig.processors.findIndex((processor) => processor === this._logProcessor);
41
41
  log.runtimeConfig.processors.splice(index, 1);
42
42
  }
@@ -27,7 +27,7 @@ export class NetworkServiceImpl implements NetworkService {
27
27
  private readonly edgeConnection?: EdgeConnection,
28
28
  ) {}
29
29
 
30
- queryStatus() {
30
+ queryStatus(): Stream<NetworkStatus> {
31
31
  return new Stream<NetworkStatus>(({ ctx, next }) => {
32
32
  const update = () => {
33
33
  next({
@@ -43,7 +43,7 @@ export class NetworkServiceImpl implements NetworkService {
43
43
  });
44
44
  }
45
45
 
46
- async updateConfig(request: UpdateConfigRequest) {
46
+ async updateConfig(request: UpdateConfigRequest): Promise<void> {
47
47
  await this.networkManager.setConnectionState(request.swarm);
48
48
  }
49
49
 
@@ -80,11 +80,11 @@ export class ClientRpcServer {
80
80
  });
81
81
  }
82
82
 
83
- async open() {
83
+ async open(): Promise<void> {
84
84
  await this._rpcPeer.open();
85
85
  }
86
86
 
87
- async close() {
87
+ async close(): Promise<void> {
88
88
  await this._rpcPeer.close();
89
89
  }
90
90
 
@@ -59,6 +59,7 @@ export type ServiceContextRuntimeParams = Pick<
59
59
  DataSpaceManagerRuntimeParams & {
60
60
  invitationConnectionDefaultParams?: InvitationConnectionParams;
61
61
  disableP2pReplication?: boolean;
62
+ enableVectorIndexing?: boolean;
62
63
  };
63
64
  /**
64
65
  * Shared backend for all client services.
@@ -155,6 +156,9 @@ export class ServiceContext extends Resource {
155
156
  kv: this.level,
156
157
  peerIdProvider: () => this.identityManager.identity?.deviceKey?.toHex(),
157
158
  getSpaceKeyByRootDocumentId: (documentId) => this.spaceManager.findSpaceByRootDocumentId(documentId)?.key,
159
+ indexing: {
160
+ vector: this._runtimeParams?.enableVectorIndexing,
161
+ },
158
162
  });
159
163
 
160
164
  this._meshReplicator = new MeshEchoReplicator();
@@ -193,7 +197,7 @@ export class ServiceContext extends Resource {
193
197
  }
194
198
 
195
199
  @Trace.span()
196
- protected override async _open(ctx: Context) {
200
+ protected override async _open(ctx: Context): Promise<void> {
197
201
  await this._checkStorageVersion();
198
202
 
199
203
  log('opening...');
@@ -231,7 +235,7 @@ export class ServiceContext extends Resource {
231
235
  log('opened');
232
236
  }
233
237
 
234
- protected override async _close(ctx: Context) {
238
+ protected override async _close(ctx: Context): Promise<void> {
235
239
  log('closing...');
236
240
  if (this._deviceSpaceSync && this.identityManager.identity) {
237
241
  await this.identityManager.identity.space.spaceState.removeCredentialProcessor(this._deviceSpaceSync);
@@ -268,7 +272,7 @@ export class ServiceContext extends Resource {
268
272
  return factory(invitation);
269
273
  }
270
274
 
271
- async broadcastProfileUpdate(profile: ProfileDocument | undefined) {
275
+ async broadcastProfileUpdate(profile: ProfileDocument | undefined): Promise<void> {
272
276
  if (!profile || !this.dataSpaceManager) {
273
277
  return;
274
278
  }
@@ -287,7 +291,7 @@ export class ServiceContext extends Resource {
287
291
  return identity;
288
292
  }
289
293
 
290
- private async _checkStorageVersion() {
294
+ private async _checkStorageVersion(): Promise<void> {
291
295
  await this.metadataStore.load();
292
296
  if (this.metadataStore.version !== STORAGE_VERSION) {
293
297
  throw new InvalidStorageVersionError(STORAGE_VERSION, this.metadataStore.version);
@@ -297,7 +301,7 @@ export class ServiceContext extends Resource {
297
301
 
298
302
  // Called when identity is created.
299
303
  @Trace.span()
300
- private async _initialize(ctx: Context) {
304
+ private async _initialize(ctx: Context): Promise<void> {
301
305
  log('initializing spaces...');
302
306
  const identity = this.identityManager.identity ?? failUndefined();
303
307
  const signingContext: SigningContext = {
@@ -375,7 +379,7 @@ export class ServiceContext extends Resource {
375
379
  await identity.space.spaceState.addCredentialProcessor(this._deviceSpaceSync);
376
380
  }
377
381
 
378
- private async _setNetworkIdentity(params?: { deviceCredential: Credential }) {
382
+ private async _setNetworkIdentity(params?: { deviceCredential: Credential }): Promise<void> {
379
383
  using _ = await this._edgeIdentityUpdateMutex.acquire();
380
384
 
381
385
  let edgeIdentity: EdgeIdentity;
@@ -125,6 +125,10 @@ export class ClientServicesHost {
125
125
  this._runtimeParams.disableP2pReplication = config?.get('runtime.client.disableP2pReplication', false);
126
126
  }
127
127
 
128
+ if (this._runtimeParams.enableVectorIndexing === undefined) {
129
+ this._runtimeParams.enableVectorIndexing = config?.get('runtime.client.enableVectorIndexing', false);
130
+ }
131
+
128
132
  if (config) {
129
133
  this.initialize({ config, transportFactory, signalManager });
130
134
  }
@@ -199,7 +203,7 @@ export class ClientServicesHost {
199
203
  * Config can also be provided in the constructor.
200
204
  * Can only be called once.
201
205
  */
202
- initialize({ config, ...options }: InitializeOptions) {
206
+ initialize({ config, ...options }: InitializeOptions): void {
203
207
  invariant(!this._open, 'service host is open');
204
208
  log('initializing...');
205
209
 
@@ -252,7 +256,7 @@ export class ClientServicesHost {
252
256
 
253
257
  @synchronized
254
258
  @Trace.span()
255
- async open(ctx: Context) {
259
+ async open(ctx: Context): Promise<void> {
256
260
  if (this._open) {
257
261
  return;
258
262
  }
@@ -373,7 +377,7 @@ export class ClientServicesHost {
373
377
 
374
378
  @synchronized
375
379
  @Trace.span()
376
- async close() {
380
+ async close(): Promise<void> {
377
381
  if (!this._open) {
378
382
  return;
379
383
  }
@@ -391,7 +395,7 @@ export class ClientServicesHost {
391
395
  log('closed', { deviceKey });
392
396
  }
393
397
 
394
- async reset() {
398
+ async reset(): Promise<void> {
395
399
  const traceId = PublicKey.random().toHex();
396
400
  log.trace('dxos.sdk.client-services-host.reset', trace.begin({ id: traceId }));
397
401
 
@@ -22,15 +22,15 @@ export class ServiceRegistry<Services> {
22
22
  return this._handlers;
23
23
  }
24
24
 
25
- setServices(services: Partial<Services>) {
25
+ setServices(services: Partial<Services>): void {
26
26
  this._handlers = services;
27
27
  }
28
28
 
29
- addService(name: keyof Services, service: Services[keyof Services]) {
29
+ addService(name: keyof Services, service: Services[keyof Services]): void {
30
30
  this._handlers[name] = service;
31
31
  }
32
32
 
33
- removeService(name: keyof Services) {
33
+ removeService(name: keyof Services): void {
34
34
  delete this._handlers[name];
35
35
  }
36
36
  }
@@ -36,21 +36,21 @@ export class SpaceArchiveWriter extends Resource {
36
36
  return Promise.resolve();
37
37
  }
38
38
 
39
- async begin(meta: SpaceArchiveBeginProps) {
39
+ async begin(meta: SpaceArchiveBeginProps): Promise<void> {
40
40
  assertState(this._tar, 'Not open');
41
41
  assertState(!this._meta, 'Already started');
42
42
  this._meta = meta;
43
43
  this._archive = new this._tar.Archive();
44
44
  }
45
45
 
46
- async setCurrentRootUrl(url: string) {
46
+ async setCurrentRootUrl(url: string): Promise<void> {
47
47
  assertArgument(url.startsWith('automerge:'), 'Invalid root URL');
48
48
  assertState(this._tar, 'Not open');
49
49
  assertState(this._meta, 'Not started');
50
50
  this._currentRootUrl = url;
51
51
  }
52
52
 
53
- async writeDocument(documentId: string, data: Uint8Array) {
53
+ async writeDocument(documentId: string, data: Uint8Array): Promise<void> {
54
54
  assertArgument(!documentId.startsWith('automerge:'), 'Invalid document ID');
55
55
  assertState(this._archive, 'Not open');
56
56
  this._archive.addBinaryFile(`${SpaceArchiveFileStructure.documents}/${documentId}.bin`, data);
@@ -25,7 +25,7 @@ export class AutomergeSpaceState extends Resource implements CredentialProcessor
25
25
  this._isProcessingRootDocs = false;
26
26
  }
27
27
 
28
- async processCredential(credential: Credential) {
28
+ async processCredential(credential: Credential): Promise<void> {
29
29
  if (!checkCredentialType(credential, 'dxos.halo.credentials.Epoch')) {
30
30
  return;
31
31
  }
@@ -42,7 +42,7 @@ export class AutomergeSpaceState extends Resource implements CredentialProcessor
42
42
  this.onNewEpoch.emit(credential);
43
43
  }
44
44
 
45
- startProcessingRootDocs() {
45
+ startProcessingRootDocs(): void {
46
46
  if (this._isProcessingRootDocs) {
47
47
  return;
48
48
  }
@@ -53,7 +53,7 @@ export class AutomergeSpaceState extends Resource implements CredentialProcessor
53
53
  this._isProcessingRootDocs = true;
54
54
  }
55
55
 
56
- async ensureEpochInitialized() {
56
+ async ensureEpochInitialized(): Promise<void> {
57
57
  await this.onNewEpoch.waitForCondition(() => !!this.lastEpoch);
58
58
  }
59
59
  }
@@ -35,7 +35,7 @@ import {
35
35
  createIdFromSpaceKey,
36
36
  encodeReference,
37
37
  type ObjectStructure,
38
- type SpaceDoc,
38
+ type DatabaseDirectory,
39
39
  } from '@dxos/echo-protocol';
40
40
  import { ObjectId, getTypeReference } from '@dxos/echo-schema';
41
41
  import type { EdgeConnection, EdgeHttpClient } from '@dxos/edge-client';
@@ -178,7 +178,7 @@ export class DataSpaceManager extends Resource {
178
178
  Array.from(this._spaces.values()).map(async (space) => {
179
179
  const rootUrl = space.automergeSpaceState.rootUrl;
180
180
  const rootHandle = rootUrl
181
- ? await this._echoHost.automergeRepo.find<Doc<SpaceDoc>>(rootUrl as AutomergeUrl, FIND_PARAMS)
181
+ ? await this._echoHost.automergeRepo.find<Doc<DatabaseDirectory>>(rootUrl as AutomergeUrl, FIND_PARAMS)
182
182
  : undefined;
183
183
  await rootHandle?.whenReady();
184
184
  const rootDoc = rootHandle?.doc();
@@ -211,7 +211,7 @@ export class DataSpaceManager extends Resource {
211
211
  }
212
212
 
213
213
  @synchronized
214
- protected override async _open() {
214
+ protected override async _open(): Promise<void> {
215
215
  log('open');
216
216
  log.trace('dxos.echo.data-space-manager.open', Trace.begin({ id: this._instanceId }));
217
217
  log('metadata loaded', { spaces: this._metadataStore.spaces.length });
@@ -231,7 +231,7 @@ export class DataSpaceManager extends Resource {
231
231
  }
232
232
 
233
233
  @synchronized
234
- protected override async _close() {
234
+ protected override async _close(): Promise<void> {
235
235
  log('close');
236
236
  for (const space of this._spaces.values()) {
237
237
  await space.close();
@@ -243,7 +243,7 @@ export class DataSpaceManager extends Resource {
243
243
  * Creates a new space writing the genesis credentials to the control feed.
244
244
  */
245
245
  @synchronized
246
- async createSpace(options: CreateSpaceOptions = {}) {
246
+ async createSpace(options: CreateSpaceOptions = {}): Promise<DataSpace> {
247
247
  assertArgument(!!options.rootUrl === !!options.documents, 'root url must be required when providing documents');
248
248
 
249
249
  assertState(this._lifecycleState === LifecycleState.OPEN, 'Not open.');
@@ -285,7 +285,7 @@ export class DataSpaceManager extends Resource {
285
285
  let root: DatabaseRoot;
286
286
  if (options.rootUrl) {
287
287
  const newRootDocId = documentIdMapping[interpretAsDocumentId(options.rootUrl)] ?? failedInvariant();
288
- const rootDocHandle = await this._echoHost.loadDoc<SpaceDoc>(Context.default(), newRootDocId);
288
+ const rootDocHandle = await this._echoHost.loadDoc<DatabaseDirectory>(Context.default(), newRootDocId);
289
289
  DatabaseRoot.mapLinks(rootDocHandle, documentIdMapping);
290
290
 
291
291
  root = await this._echoHost.openSpaceRoot(spaceId, `automerge:${newRootDocId}` as AutomergeUrl);
@@ -338,7 +338,7 @@ export class DataSpaceManager extends Resource {
338
338
  }
339
339
  }
340
340
 
341
- async createDefaultSpace() {
341
+ async createDefaultSpace(): Promise<DataSpace> {
342
342
  const space = await this.createSpace();
343
343
  const document = await this._getSpaceRootDocument(space);
344
344
 
@@ -356,7 +356,7 @@ export class DataSpaceManager extends Resource {
356
356
  };
357
357
 
358
358
  const propertiesId = ObjectId.random();
359
- document.change((doc: SpaceDoc) => {
359
+ document.change((doc: DatabaseDirectory) => {
360
360
  setDeep(doc, ['objects', propertiesId], properties);
361
361
  });
362
362
 
@@ -364,10 +364,10 @@ export class DataSpaceManager extends Resource {
364
364
  return space;
365
365
  }
366
366
 
367
- private async _getSpaceRootDocument(space: DataSpace): Promise<DocHandle<SpaceDoc>> {
367
+ private async _getSpaceRootDocument(space: DataSpace): Promise<DocHandle<DatabaseDirectory>> {
368
368
  const automergeIndex = space.automergeSpaceState.rootUrl;
369
369
  invariant(automergeIndex);
370
- const document = await this._echoHost.automergeRepo.find<SpaceDoc>(automergeIndex as any, FIND_PARAMS);
370
+ const document = await this._echoHost.automergeRepo.find<DatabaseDirectory>(automergeIndex as any, FIND_PARAMS);
371
371
  await document.whenReady();
372
372
  return document;
373
373
  }
@@ -429,7 +429,7 @@ export class DataSpaceManager extends Resource {
429
429
  * Used by invitation handler.
430
430
  * TODO(dmaretskyi): Consider removing.
431
431
  */
432
- async waitUntilSpaceReady(spaceKey: PublicKey) {
432
+ async waitUntilSpaceReady(spaceKey: PublicKey): Promise<void> {
433
433
  await cancelWithContext(
434
434
  this._ctx,
435
435
  this.updated.waitForCondition(() => {
@@ -453,7 +453,7 @@ export class DataSpaceManager extends Resource {
453
453
  });
454
454
  }
455
455
 
456
- async setSpaceEdgeReplicationSetting(spaceKey: PublicKey, setting: EdgeReplicationSetting) {
456
+ async setSpaceEdgeReplicationSetting(spaceKey: PublicKey, setting: EdgeReplicationSetting): Promise<void> {
457
457
  const space = this._spaces.get(spaceKey);
458
458
  invariant(space, 'Space not found.');
459
459
 
@@ -473,7 +473,7 @@ export class DataSpaceManager extends Resource {
473
473
  space.stateUpdate.emit();
474
474
  }
475
475
 
476
- private async _constructSpace(metadata: SpaceMetadata) {
476
+ private async _constructSpace(metadata: SpaceMetadata): Promise<DataSpace> {
477
477
  log('construct space', { metadata });
478
478
  const gossip = new Gossip({
479
479
  localPeerId: this._signingContext.deviceKey,
@@ -597,7 +597,7 @@ export class DataSpaceManager extends Resource {
597
597
  return dataSpace;
598
598
  }
599
599
 
600
- private async _connectEchoMeshReplicator(space: Space, session: Teleport) {
600
+ private async _connectEchoMeshReplicator(space: Space, session: Teleport): Promise<void> {
601
601
  const replicator = this._meshReplicator;
602
602
  if (!replicator) {
603
603
  log.warn('p2p automerge replication disabled', { space: space.key });
@@ -18,7 +18,7 @@ import {
18
18
  type Space,
19
19
  FIND_PARAMS,
20
20
  } from '@dxos/echo-pipeline';
21
- import { SpaceDocVersion, type SpaceDoc } from '@dxos/echo-protocol';
21
+ import { SpaceDocVersion, type DatabaseDirectory } from '@dxos/echo-protocol';
22
22
  import type { EdgeConnection, EdgeHttpClient } from '@dxos/edge-client';
23
23
  import { type FeedStore, type FeedWrapper } from '@dxos/feed-store';
24
24
  import { failedInvariant, invariant } from '@dxos/invariant';
@@ -229,13 +229,13 @@ export class DataSpace {
229
229
  }
230
230
 
231
231
  @synchronized
232
- async open() {
232
+ async open(): Promise<void> {
233
233
  if (this._state === SpaceState.SPACE_CLOSED) {
234
234
  await this._open();
235
235
  }
236
236
  }
237
237
 
238
- private async _open() {
238
+ private async _open(): Promise<void> {
239
239
  await this._presence.open();
240
240
  await this._gossip.open();
241
241
  await this._notarizationPlugin.open();
@@ -262,11 +262,11 @@ export class DataSpace {
262
262
  }
263
263
 
264
264
  @synchronized
265
- async close() {
265
+ async close(): Promise<void> {
266
266
  await this._close();
267
267
  }
268
268
 
269
- private async _close() {
269
+ private async _close(): Promise<void> {
270
270
  await this._callbacks.beforeClose?.();
271
271
 
272
272
  await this.preClose.callSerial();
@@ -294,18 +294,18 @@ export class DataSpace {
294
294
  await this._gossip.close();
295
295
  }
296
296
 
297
- async postMessage(channel: string, message: any) {
297
+ async postMessage(channel: string, message: any): Promise<void> {
298
298
  return this._gossip.postMessage(channel, message);
299
299
  }
300
300
 
301
- listen(channel: string, callback: (message: GossipMessage) => void) {
301
+ listen(channel: string, callback: (message: GossipMessage) => void): { unsubscribe: () => void } {
302
302
  return this._gossip.listen(channel, callback);
303
303
  }
304
304
 
305
305
  /**
306
306
  * Initialize the data pipeline in a separate task.
307
307
  */
308
- initializeDataPipelineAsync() {
308
+ initializeDataPipelineAsync(): void {
309
309
  scheduleTask(this._ctx, async () => {
310
310
  try {
311
311
  this.metrics.pipelineInitBegin = new Date();
@@ -328,7 +328,7 @@ export class DataSpace {
328
328
  }
329
329
 
330
330
  @trace.span({ showInBrowserTimeline: true })
331
- async initializeDataPipeline() {
331
+ async initializeDataPipeline(): Promise<void> {
332
332
  if (this._state !== SpaceState.SPACE_CONTROL_ONLY) {
333
333
  throw new SystemError('Invalid operation');
334
334
  }
@@ -365,7 +365,7 @@ export class DataSpace {
365
365
  }
366
366
  }
367
367
 
368
- private async _enterReadyState() {
368
+ private async _enterReadyState(): Promise<void> {
369
369
  await this._callbacks.beforeReady?.();
370
370
 
371
371
  this._state = SpaceState.SPACE_READY;
@@ -376,7 +376,7 @@ export class DataSpace {
376
376
  }
377
377
 
378
378
  @trace.span({ showInBrowserTimeline: true })
379
- private async _initializeAndReadControlPipeline() {
379
+ private async _initializeAndReadControlPipeline(): Promise<void> {
380
380
  await this._inner.controlPipeline.state.waitUntilReachedTargetTimeframe({
381
381
  ctx: this._ctx,
382
382
  timeout: 10_000,
@@ -402,7 +402,7 @@ export class DataSpace {
402
402
  }
403
403
 
404
404
  @timed(10_000)
405
- private async _createWritableFeeds() {
405
+ private async _createWritableFeeds(): Promise<void> {
406
406
  const credentials: Credential[] = [];
407
407
  if (!this.inner.controlFeedKey) {
408
408
  const controlFeed = await this._feedStore.openFeed(await this._keyring.createKey(), { writable: true });
@@ -459,10 +459,10 @@ export class DataSpace {
459
459
  }
460
460
  }
461
461
 
462
- private _onNewAutomergeRoot(rootUrl: string) {
462
+ private _onNewAutomergeRoot(rootUrl: string): void {
463
463
  log('loading automerge root doc for space', { space: this.key, rootUrl });
464
464
 
465
- let handle: DocHandle<SpaceDoc>;
465
+ let handle: DocHandle<DatabaseDirectory>;
466
466
 
467
467
  // TODO(dmaretskyi): Make this single-threaded (but doc loading should still be parallel to not block epoch processing).
468
468
  queueMicrotask(async () => {
@@ -470,7 +470,7 @@ export class DataSpace {
470
470
  await warnAfterTimeout(5_000, 'Automerge root doc load timeout (DataSpace)', async () => {
471
471
  handle = await cancelWithContext(
472
472
  this._ctx,
473
- this._echoHost.automergeRepo.find<SpaceDoc>(rootUrl as any, FIND_PARAMS),
473
+ this._echoHost.automergeRepo.find<DatabaseDirectory>(rootUrl as any, FIND_PARAMS),
474
474
  );
475
475
  await cancelWithContext(this._ctx, handle.whenReady());
476
476
  });
@@ -513,7 +513,7 @@ export class DataSpace {
513
513
  }
514
514
 
515
515
  // TODO(dmaretskyi): Use profile from signing context.
516
- async updateOwnProfile(profile: ProfileDocument) {
516
+ async updateOwnProfile(profile: ProfileDocument): Promise<void> {
517
517
  const credential = await this._signingContext.credentialSigner.createCredential({
518
518
  subject: this._signingContext.identityKey,
519
519
  assertion: {
@@ -568,7 +568,7 @@ export class DataSpace {
568
568
  }
569
569
 
570
570
  @synchronized
571
- async activate() {
571
+ async activate(): Promise<void> {
572
572
  if (![SpaceState.SPACE_CLOSED, SpaceState.SPACE_INACTIVE].includes(this._state)) {
573
573
  return;
574
574
  }
@@ -579,7 +579,7 @@ export class DataSpace {
579
579
  }
580
580
 
581
581
  @synchronized
582
- async deactivate() {
582
+ async deactivate(): Promise<void> {
583
583
  if (this._state === SpaceState.SPACE_INACTIVE) {
584
584
  return;
585
585
  }
@@ -85,7 +85,7 @@ export class EdgeFeedReplicator extends Resource {
85
85
  );
86
86
  }
87
87
 
88
- private async _handleReconnect() {
88
+ private async _handleReconnect(): Promise<void> {
89
89
  await this._resetConnection();
90
90
  if (this._messenger.status === EdgeStatus.CONNECTED) {
91
91
  this._startReplication();
@@ -97,7 +97,7 @@ export class EdgeFeedReplicator extends Resource {
97
97
  await this._resetConnection();
98
98
  }
99
99
 
100
- private _startReplication() {
100
+ private _startReplication(): void {
101
101
  this._connected = true;
102
102
  const connectionCtx = this._createConnectionContext();
103
103
  this._connectionCtx = connectionCtx;
@@ -109,7 +109,7 @@ export class EdgeFeedReplicator extends Resource {
109
109
  });
110
110
  }
111
111
 
112
- private async _resetConnection() {
112
+ private async _resetConnection(): Promise<void> {
113
113
  log('resetConnection');
114
114
  this._connected = false;
115
115
  await this._connectionCtx?.dispose();
@@ -117,7 +117,7 @@ export class EdgeFeedReplicator extends Resource {
117
117
  this._remoteLength.clear();
118
118
  }
119
119
 
120
- async addFeed(feed: FeedWrapper<any>) {
120
+ async addFeed(feed: FeedWrapper<any>): Promise<void> {
121
121
  log('addFeed', { key: feed.key, connected: this._connected, hasConnectionCtx: !!this._connectionCtx });
122
122
  this._feeds.set(feed.key, feed);
123
123
 
@@ -126,11 +126,11 @@ export class EdgeFeedReplicator extends Resource {
126
126
  }
127
127
  }
128
128
 
129
- private _getPushMutex(key: PublicKey) {
129
+ private _getPushMutex(key: PublicKey): Mutex {
130
130
  return defaultMap(this._pushMutex, key, () => new Mutex());
131
131
  }
132
132
 
133
- private async _replicateFeed(ctx: Context, feed: FeedWrapper<any>) {
133
+ private async _replicateFeed(ctx: Context, feed: FeedWrapper<any>): Promise<void> {
134
134
  log('replicateFeed', { key: feed.key });
135
135
  await this._sendMessage({
136
136
  type: 'get-metadata',
@@ -142,7 +142,7 @@ export class EdgeFeedReplicator extends Resource {
142
142
  });
143
143
  }
144
144
 
145
- private async _sendMessage(message: ProtocolMessage) {
145
+ private async _sendMessage(message: ProtocolMessage): Promise<void> {
146
146
  if (!this._connectionCtx) {
147
147
  log('message dropped because connection was disposed');
148
148
  return;
@@ -171,7 +171,7 @@ export class EdgeFeedReplicator extends Resource {
171
171
  );
172
172
  }
173
173
 
174
- private _onMessage(message: ProtocolMessage) {
174
+ private _onMessage(message: ProtocolMessage): void {
175
175
  if (!this._connectionCtx) {
176
176
  log.warn('received message after connection context was disposed');
177
177
  return;
@@ -229,7 +229,7 @@ export class EdgeFeedReplicator extends Resource {
229
229
  });
230
230
  }
231
231
 
232
- private async _pushBlocks(feed: FeedWrapper<any>, from: number, to: number) {
232
+ private async _pushBlocks(feed: FeedWrapper<any>, from: number, to: number): Promise<void> {
233
233
  log('pushing blocks', { feed: feed.key.toHex(), from, to });
234
234
 
235
235
  const blocks: FeedBlock[] = await Promise.all(
@@ -255,7 +255,7 @@ export class EdgeFeedReplicator extends Resource {
255
255
  this._remoteLength.set(feed.key, to);
256
256
  }
257
257
 
258
- private async _integrateBlocks(feed: FeedWrapper<any>, blocks: FeedBlock[]) {
258
+ private async _integrateBlocks(feed: FeedWrapper<any>, blocks: FeedBlock[]): Promise<void> {
259
259
  log('integrating blocks', { feed: feed.key.toHex(), blocks: blocks.length });
260
260
 
261
261
  for (const block of blocks) {
@@ -273,7 +273,7 @@ export class EdgeFeedReplicator extends Resource {
273
273
  }
274
274
  }
275
275
 
276
- private async _pushBlocksIfNeeded(feed: FeedWrapper<any>) {
276
+ private async _pushBlocksIfNeeded(feed: FeedWrapper<any>): Promise<void> {
277
277
  using _ = await this._getPushMutex(feed.key).acquire();
278
278
 
279
279
  if (!this._remoteLength.has(feed.key)) {
@@ -287,7 +287,7 @@ export class EdgeFeedReplicator extends Resource {
287
287
  }
288
288
  }
289
289
 
290
- private _createConnectionContext() {
290
+ private _createConnectionContext(): Context {
291
291
  const connectionCtx = new Context({
292
292
  onError: async (err: any) => {
293
293
  if (connectionCtx !== this._connectionCtx) {
@@ -30,7 +30,7 @@ class TestAgent extends TestPeer {
30
30
  });
31
31
  }
32
32
 
33
- enableWriting() {
33
+ enableWriting(): void {
34
34
  this.notarizationPlugin.setWriter(this.feed);
35
35
  }
36
36