@dxos/client-services 0.6.3-main.d007b87 → 0.6.3-main.d76104f

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 (32) hide show
  1. package/dist/lib/browser/{chunk-Y7UULU6J.mjs → chunk-TRX3WZGF.mjs} +143 -122
  2. package/dist/lib/browser/chunk-TRX3WZGF.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +1 -1
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/packlets/testing/index.mjs +1 -1
  6. package/dist/lib/node/{chunk-4VQMVHT4.cjs → chunk-JYYVESTN.cjs} +141 -120
  7. package/dist/lib/node/chunk-JYYVESTN.cjs.map +7 -0
  8. package/dist/lib/node/index.cjs +45 -45
  9. package/dist/lib/node/meta.json +1 -1
  10. package/dist/lib/node/packlets/testing/index.cjs +8 -8
  11. package/dist/types/src/packlets/invitations/invitation-guest-extenstion.d.ts.map +1 -1
  12. package/dist/types/src/packlets/invitations/invitation-host-extension.d.ts.map +1 -1
  13. package/dist/types/src/packlets/invitations/invitation-topology.d.ts +2 -2
  14. package/dist/types/src/packlets/invitations/invitation-topology.d.ts.map +1 -1
  15. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  16. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  17. package/dist/types/src/packlets/spaces/data-space.d.ts +8 -2
  18. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  19. package/dist/types/src/version.d.ts +1 -1
  20. package/package.json +36 -36
  21. package/src/packlets/identity/identity-service.ts +2 -2
  22. package/src/packlets/invitations/invitation-guest-extenstion.ts +8 -5
  23. package/src/packlets/invitations/invitation-host-extension.ts +5 -5
  24. package/src/packlets/invitations/invitation-topology.ts +4 -4
  25. package/src/packlets/invitations/invitations-handler.ts +13 -12
  26. package/src/packlets/spaces/data-space-manager.test.ts +6 -6
  27. package/src/packlets/spaces/data-space-manager.ts +28 -16
  28. package/src/packlets/spaces/data-space.ts +31 -27
  29. package/src/packlets/spaces/spaces-service.ts +6 -6
  30. package/src/version.ts +1 -1
  31. package/dist/lib/browser/chunk-Y7UULU6J.mjs.map +0 -7
  32. package/dist/lib/node/chunk-4VQMVHT4.cjs.map +0 -7
@@ -197,7 +197,7 @@ export class DataSpaceManager {
197
197
  genesisFeedKey: controlFeedKey,
198
198
  controlFeedKey,
199
199
  dataFeedKey,
200
- state: SpaceState.ACTIVE,
200
+ state: SpaceState.SPACE_ACTIVE,
201
201
  };
202
202
 
203
203
  log('creating space...', { spaceKey });
@@ -336,7 +336,7 @@ export class DataSpaceManager {
336
336
  this._ctx,
337
337
  this.updated.waitForCondition(() => {
338
338
  const space = this._spaces.get(spaceKey);
339
- return !!space && space.state === SpaceState.READY;
339
+ return !!space && space.state === SpaceState.SPACE_READY;
340
340
  }),
341
341
  );
342
342
  }
@@ -382,21 +382,33 @@ export class DataSpaceManager {
382
382
  credentialProvider: createAuthProvider(this._signingContext.credentialSigner),
383
383
  credentialAuthenticator: deferFunction(() => dataSpace.authVerifier.verifier),
384
384
  },
385
- onAuthorizedConnection: (session) => {
386
- session.addExtension('dxos.mesh.teleport.admission-discovery', new CredentialServerExtension(space));
387
- session.addExtension(
388
- 'dxos.mesh.teleport.gossip',
389
- gossip.createExtension({ remotePeerId: session.remotePeerId }),
390
- );
391
- session.addExtension('dxos.mesh.teleport.notarization', dataSpace.notarizationPlugin.createExtension());
392
- this._echoHost.authorizeDevice(space.key, session.remotePeerId);
393
- session.addExtension('dxos.mesh.teleport.automerge', this._echoHost.createReplicationExtension());
394
- },
385
+ onAuthorizedConnection: (session) =>
386
+ queueMicrotask(async () => {
387
+ try {
388
+ if (!session.isOpen) {
389
+ return;
390
+ }
391
+ session.addExtension('dxos.mesh.teleport.admission-discovery', new CredentialServerExtension(space));
392
+ session.addExtension(
393
+ 'dxos.mesh.teleport.gossip',
394
+ gossip.createExtension({ remotePeerId: session.remotePeerId }),
395
+ );
396
+ session.addExtension('dxos.mesh.teleport.notarization', dataSpace.notarizationPlugin.createExtension());
397
+ await this._echoHost.authorizeDevice(space.key, session.remotePeerId);
398
+ if (!session.isOpen) {
399
+ return;
400
+ }
401
+ session.addExtension('dxos.mesh.teleport.automerge', this._echoHost.createReplicationExtension());
402
+ } catch (err: any) {
403
+ log.warn('error on authorized connection', { err });
404
+ await session.close(err);
405
+ }
406
+ }),
395
407
  onAuthFailure: () => {
396
408
  log.warn('auth failure');
397
409
  },
398
410
  onMemberRolesChanged: async (members: MemberInfo[]) => {
399
- if (dataSpace?.state === SpaceState.READY) {
411
+ if (dataSpace?.state === SpaceState.SPACE_READY) {
400
412
  this._handleMemberRoleChanges(presence, space.protocol, members);
401
413
  }
402
414
  },
@@ -410,7 +422,7 @@ export class DataSpaceManager {
410
422
 
411
423
  const dataSpace = new DataSpace({
412
424
  inner: space,
413
- initialState: metadata.state === SpaceState.INACTIVE ? SpaceState.INACTIVE : SpaceState.CLOSED,
425
+ initialState: metadata.state === SpaceState.SPACE_INACTIVE ? SpaceState.SPACE_INACTIVE : SpaceState.SPACE_CLOSED,
414
426
  metadataStore: this._metadataStore,
415
427
  gossip,
416
428
  presence,
@@ -438,7 +450,7 @@ export class DataSpaceManager {
438
450
  });
439
451
 
440
452
  presence.newPeer.on((peerState) => {
441
- if (dataSpace.state === SpaceState.READY) {
453
+ if (dataSpace.state === SpaceState.SPACE_READY) {
442
454
  this._handleNewPeerConnected(space, peerState);
443
455
  }
444
456
  });
@@ -492,7 +504,7 @@ export class DataSpaceManager {
492
504
  delegatedInvitation: DelegateInvitationCredential,
493
505
  isActive: boolean,
494
506
  ): Promise<void> {
495
- if (dataSpace?.state !== SpaceState.READY) {
507
+ if (dataSpace?.state !== SpaceState.SPACE_READY) {
496
508
  return;
497
509
  }
498
510
  if (isActive) {
@@ -101,12 +101,12 @@ export class DataSpace {
101
101
 
102
102
  private readonly _epochProcessingMutex = new Mutex();
103
103
 
104
- private _state = SpaceState.CLOSED;
104
+ private _state = SpaceState.SPACE_CLOSED;
105
105
 
106
106
  private _databaseRoot: DatabaseRoot | null = null;
107
107
 
108
108
  /**
109
- * Error for _state === SpaceState.ERROR.
109
+ * Error for _state === SpaceState.SPACE_ERROR.
110
110
  */
111
111
  public error: Error | undefined = undefined;
112
112
 
@@ -200,7 +200,7 @@ export class DataSpace {
200
200
 
201
201
  @synchronized
202
202
  async open() {
203
- if (this._state === SpaceState.CLOSED) {
203
+ if (this._state === SpaceState.SPACE_CLOSED) {
204
204
  await this._open();
205
205
  }
206
206
  }
@@ -213,7 +213,7 @@ export class DataSpace {
213
213
  await this._automergeSpaceState.open();
214
214
  await this._inner.spaceState.addCredentialProcessor(this._automergeSpaceState);
215
215
  await this._inner.open(new Context());
216
- this._state = SpaceState.CONTROL_ONLY;
216
+ this._state = SpaceState.SPACE_CONTROL_ONLY;
217
217
  log('new state', { state: SpaceState[this._state] });
218
218
  this.stateUpdate.emit();
219
219
  this.metrics = {};
@@ -227,7 +227,7 @@ export class DataSpace {
227
227
 
228
228
  private async _close() {
229
229
  await this._callbacks.beforeClose?.();
230
- this._state = SpaceState.CLOSED;
230
+ this._state = SpaceState.SPACE_CLOSED;
231
231
  log('new state', { state: SpaceState[this._state] });
232
232
  await this._ctx.dispose();
233
233
  this._ctx = new Context();
@@ -267,7 +267,7 @@ export class DataSpace {
267
267
  }
268
268
 
269
269
  log.error('Error initializing data pipeline', err);
270
- this._state = SpaceState.ERROR;
270
+ this._state = SpaceState.SPACE_ERROR;
271
271
  log('new state', { state: SpaceState[this._state] });
272
272
  this.error = err as Error;
273
273
  this.stateUpdate.emit();
@@ -279,11 +279,11 @@ export class DataSpace {
279
279
 
280
280
  @trace.span({ showInBrowserTimeline: true })
281
281
  async initializeDataPipeline() {
282
- if (this._state !== SpaceState.CONTROL_ONLY) {
282
+ if (this._state !== SpaceState.SPACE_CONTROL_ONLY) {
283
283
  throw new SystemError('Invalid operation');
284
284
  }
285
285
 
286
- this._state = SpaceState.INITIALIZING;
286
+ this._state = SpaceState.SPACE_INITIALIZING;
287
287
  log('new state', { state: SpaceState[this._state] });
288
288
 
289
289
  await this._initializeAndReadControlPipeline();
@@ -291,7 +291,7 @@ export class DataSpace {
291
291
  // Allow other tasks to run before loading the data pipeline.
292
292
  await sleep(1);
293
293
 
294
- const ready = this.stateUpdate.waitForCondition(() => this._state === SpaceState.READY);
294
+ const ready = this.stateUpdate.waitForCondition(() => this._state === SpaceState.SPACE_READY);
295
295
 
296
296
  this._automergeSpaceState.startProcessingRootDocs();
297
297
 
@@ -302,7 +302,7 @@ export class DataSpace {
302
302
  private async _enterReadyState() {
303
303
  await this._callbacks.beforeReady?.();
304
304
 
305
- this._state = SpaceState.READY;
305
+ this._state = SpaceState.SPACE_READY;
306
306
  log('new state', { state: SpaceState[this._state] });
307
307
  this.stateUpdate.emit();
308
308
 
@@ -412,19 +412,17 @@ export class DataSpace {
412
412
 
413
413
  // TODO(dmaretskyi): Close roots.
414
414
  // TODO(dmaretskyi): How do we handle changing to the next EPOCH?
415
- const root = await this._echoHost.openSpaceRoot(handle.url);
415
+ const root = await this._echoHost.openSpaceRoot(this.id, handle.url);
416
416
 
417
417
  // NOTE: Make sure this assignment happens synchronously together with the state change.
418
418
  this._databaseRoot = root;
419
419
  if (root.getVersion() !== SpaceDocVersion.CURRENT) {
420
- if (this._state !== SpaceState.REQUIRES_MIGRATION) {
421
- this._state = SpaceState.REQUIRES_MIGRATION;
422
- this.stateUpdate.emit();
423
- }
420
+ this._state = SpaceState.SPACE_REQUIRES_MIGRATION;
421
+ this.stateUpdate.emit();
422
+ } else if (this._state !== SpaceState.SPACE_READY) {
423
+ await this._enterReadyState();
424
424
  } else {
425
- if (this._state !== SpaceState.READY) {
426
- await this._enterReadyState();
427
- }
425
+ this.stateUpdate.emit();
428
426
  }
429
427
  } catch (err) {
430
428
  if (err instanceof ContextDisposedError) {
@@ -447,7 +445,7 @@ export class DataSpace {
447
445
  await this.inner.controlPipeline.writer.write({ credential: { credential } });
448
446
  }
449
447
 
450
- async createEpoch(options?: CreateEpochOptions): Promise<SpecificCredential<Epoch> | null> {
448
+ async createEpoch(options?: CreateEpochOptions): Promise<CreateEpochResult | null> {
451
449
  const ctx = this._ctx.derive();
452
450
 
453
451
  // Preserving existing behavior.
@@ -483,35 +481,41 @@ export class DataSpace {
483
481
  credential: { credential },
484
482
  });
485
483
 
486
- await this.inner.controlPipeline.state.waitUntilTimeframe(new Timeframe([[receipt.feedKey, receipt.seq]]));
484
+ const timeframe = new Timeframe([[receipt.feedKey, receipt.seq]]);
485
+ await this.inner.controlPipeline.state.waitUntilTimeframe(timeframe);
487
486
  await this._echoHost.updateIndexes();
488
487
 
489
- return credential;
488
+ return { credential, timeframe };
490
489
  }
491
490
 
492
491
  @synchronized
493
492
  async activate() {
494
- if (![SpaceState.CLOSED, SpaceState.INACTIVE].includes(this._state)) {
493
+ if (![SpaceState.SPACE_CLOSED, SpaceState.SPACE_INACTIVE].includes(this._state)) {
495
494
  return;
496
495
  }
497
496
 
498
- await this._metadataStore.setSpaceState(this.key, SpaceState.ACTIVE);
497
+ await this._metadataStore.setSpaceState(this.key, SpaceState.SPACE_ACTIVE);
499
498
  await this._open();
500
499
  this.initializeDataPipelineAsync();
501
500
  }
502
501
 
503
502
  @synchronized
504
503
  async deactivate() {
505
- if (this._state === SpaceState.INACTIVE) {
504
+ if (this._state === SpaceState.SPACE_INACTIVE) {
506
505
  return;
507
506
  }
508
507
  // Unregister from data service.
509
- await this._metadataStore.setSpaceState(this.key, SpaceState.INACTIVE);
510
- if (this._state !== SpaceState.CLOSED) {
508
+ await this._metadataStore.setSpaceState(this.key, SpaceState.SPACE_INACTIVE);
509
+ if (this._state !== SpaceState.SPACE_CLOSED) {
511
510
  await this._close();
512
511
  }
513
- this._state = SpaceState.INACTIVE;
512
+ this._state = SpaceState.SPACE_INACTIVE;
514
513
  log('new state', { state: SpaceState[this._state] });
515
514
  this.stateUpdate.emit();
516
515
  }
517
516
  }
517
+
518
+ type CreateEpochResult = {
519
+ credential: SpecificCredential<Epoch>;
520
+ timeframe: Timeframe;
521
+ };
@@ -66,11 +66,11 @@ export class SpacesServiceImpl implements SpacesService {
66
66
 
67
67
  if (state) {
68
68
  switch (state) {
69
- case SpaceState.ACTIVE:
69
+ case SpaceState.SPACE_ACTIVE:
70
70
  await space.activate();
71
71
  break;
72
72
 
73
- case SpaceState.INACTIVE:
73
+ case SpaceState.SPACE_INACTIVE:
74
74
  await space.deactivate();
75
75
  break;
76
76
  default:
@@ -112,7 +112,7 @@ export class SpacesServiceImpl implements SpacesService {
112
112
  async () => {
113
113
  const dataSpaceManager = await this._getDataSpaceManager();
114
114
  const spaces = Array.from(dataSpaceManager.spaces.values()).map((space) => this._serializeSpace(space));
115
- log('update', { spaces });
115
+ log('update', () => ({ ids: spaces.map((space) => space.id) }));
116
116
  await this._updateMetrics();
117
117
  next({ spaces });
118
118
  },
@@ -226,8 +226,8 @@ export class SpacesServiceImpl implements SpacesService {
226
226
  async createEpoch({ spaceKey, migration, automergeRootUrl }: CreateEpochRequest): Promise<CreateEpochResponse> {
227
227
  const dataSpaceManager = await this._getDataSpaceManager();
228
228
  const space = dataSpaceManager.spaces.get(spaceKey) ?? raise(new SpaceNotFoundError(spaceKey));
229
- const credential = await space.createEpoch({ migration, newAutomergeRoot: automergeRootUrl });
230
- return { epochCredential: credential ?? undefined };
229
+ const result = await space.createEpoch({ migration, newAutomergeRoot: automergeRootUrl });
230
+ return { epochCredential: result?.credential, controlTimeframe: result?.timeframe };
231
231
  }
232
232
 
233
233
  async admitContact(request: AdmitContactRequest): Promise<void> {
@@ -324,7 +324,7 @@ export class SpacesServiceImpl implements SpacesService {
324
324
  const dataSpaceManager = await this._getDataSpaceManager();
325
325
  const identity = this._identityManager.identity?.identityKey.truncate();
326
326
  if (identity) {
327
- trace.metrics.gauge('echo.space.count', dataSpaceManager.spaces.size, {
327
+ trace.metrics.gauge('dxos.echo.space.count', dataSpaceManager.spaces.size, {
328
328
  tags: { identity },
329
329
  });
330
330
  }
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const DXOS_VERSION = "0.6.3-main.d007b87";
1
+ export const DXOS_VERSION = "0.6.3-main.d76104f";