@dxos/client-services 0.4.10-main.93fda5f → 0.4.10-main.94e3e06

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.
@@ -1,2 +1,2 @@
1
- export declare const DXOS_VERSION = "0.4.10-main.93fda5f";
1
+ export declare const DXOS_VERSION = "0.4.10-main.94e3e06";
2
2
  //# sourceMappingURL=version.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/client-services",
3
- "version": "0.4.10-main.93fda5f",
3
+ "version": "0.4.10-main.94e3e06",
4
4
  "description": "DXOS client services implementation",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -22,43 +22,43 @@
22
22
  ],
23
23
  "dependencies": {
24
24
  "platform": "^1.3.6",
25
- "@dxos/automerge": "0.4.10-main.93fda5f",
26
- "@dxos/async": "0.4.10-main.93fda5f",
27
- "@dxos/client-protocol": "0.4.10-main.93fda5f",
28
- "@dxos/config": "0.4.10-main.93fda5f",
29
- "@dxos/codec-protobuf": "0.4.10-main.93fda5f",
30
- "@dxos/context": "0.4.10-main.93fda5f",
31
- "@dxos/credentials": "0.4.10-main.93fda5f",
32
- "@dxos/crypto": "0.4.10-main.93fda5f",
33
- "@dxos/debug": "0.4.10-main.93fda5f",
34
- "@dxos/echo-pipeline": "0.4.10-main.93fda5f",
35
- "@dxos/echo-schema": "0.4.10-main.93fda5f",
36
- "@dxos/echo-db": "0.4.10-main.93fda5f",
37
- "@dxos/feed-store": "0.4.10-main.93fda5f",
38
- "@dxos/indexing": "0.4.10-main.93fda5f",
39
- "@dxos/invariant": "0.4.10-main.93fda5f",
40
- "@dxos/keyring": "0.4.10-main.93fda5f",
41
- "@dxos/log": "0.4.10-main.93fda5f",
42
- "@dxos/messaging": "0.4.10-main.93fda5f",
43
- "@dxos/network-manager": "0.4.10-main.93fda5f",
44
- "@dxos/keys": "0.4.10-main.93fda5f",
45
- "@dxos/lock-file": "0.4.10-main.93fda5f",
46
- "@dxos/node-std": "0.4.10-main.93fda5f",
47
- "@dxos/protocols": "0.4.10-main.93fda5f",
48
- "@dxos/rpc": "0.4.10-main.93fda5f",
49
- "@dxos/random-access-storage": "0.4.10-main.93fda5f",
50
- "@dxos/teleport-extension-object-sync": "0.4.10-main.93fda5f",
51
- "@dxos/teleport-extension-gossip": "0.4.10-main.93fda5f",
52
- "@dxos/timeframe": "0.4.10-main.93fda5f",
53
- "@dxos/teleport": "0.4.10-main.93fda5f",
54
- "@dxos/tracing": "0.4.10-main.93fda5f",
55
- "@dxos/util": "0.4.10-main.93fda5f",
56
- "@dxos/websocket-rpc": "0.4.10-main.93fda5f"
25
+ "@dxos/async": "0.4.10-main.94e3e06",
26
+ "@dxos/client-protocol": "0.4.10-main.94e3e06",
27
+ "@dxos/automerge": "0.4.10-main.94e3e06",
28
+ "@dxos/config": "0.4.10-main.94e3e06",
29
+ "@dxos/context": "0.4.10-main.94e3e06",
30
+ "@dxos/codec-protobuf": "0.4.10-main.94e3e06",
31
+ "@dxos/credentials": "0.4.10-main.94e3e06",
32
+ "@dxos/crypto": "0.4.10-main.94e3e06",
33
+ "@dxos/debug": "0.4.10-main.94e3e06",
34
+ "@dxos/echo-pipeline": "0.4.10-main.94e3e06",
35
+ "@dxos/echo-schema": "0.4.10-main.94e3e06",
36
+ "@dxos/echo-db": "0.4.10-main.94e3e06",
37
+ "@dxos/feed-store": "0.4.10-main.94e3e06",
38
+ "@dxos/indexing": "0.4.10-main.94e3e06",
39
+ "@dxos/invariant": "0.4.10-main.94e3e06",
40
+ "@dxos/keyring": "0.4.10-main.94e3e06",
41
+ "@dxos/keys": "0.4.10-main.94e3e06",
42
+ "@dxos/lock-file": "0.4.10-main.94e3e06",
43
+ "@dxos/log": "0.4.10-main.94e3e06",
44
+ "@dxos/messaging": "0.4.10-main.94e3e06",
45
+ "@dxos/network-manager": "0.4.10-main.94e3e06",
46
+ "@dxos/protocols": "0.4.10-main.94e3e06",
47
+ "@dxos/rpc": "0.4.10-main.94e3e06",
48
+ "@dxos/random-access-storage": "0.4.10-main.94e3e06",
49
+ "@dxos/teleport": "0.4.10-main.94e3e06",
50
+ "@dxos/node-std": "0.4.10-main.94e3e06",
51
+ "@dxos/timeframe": "0.4.10-main.94e3e06",
52
+ "@dxos/teleport-extension-gossip": "0.4.10-main.94e3e06",
53
+ "@dxos/util": "0.4.10-main.94e3e06",
54
+ "@dxos/tracing": "0.4.10-main.94e3e06",
55
+ "@dxos/teleport-extension-object-sync": "0.4.10-main.94e3e06",
56
+ "@dxos/websocket-rpc": "0.4.10-main.94e3e06"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@types/platform": "^1.3.4",
60
60
  "@types/readable-stream": "^2.3.9",
61
- "@dxos/signal": "0.4.10-main.93fda5f"
61
+ "@dxos/signal": "0.4.10-main.94e3e06"
62
62
  },
63
63
  "publishConfig": {
64
64
  "access": "public"
@@ -12,7 +12,7 @@ import { idCodec } from '@dxos/protocols';
12
12
  /**
13
13
  * Factory for `loadDocuments` iterator.
14
14
  */
15
- export const createLoadDocuments = (automergeHost: AutomergeHost) =>
15
+ export const createSelectedDocumentsIterator = (automergeHost: AutomergeHost) =>
16
16
  /**
17
17
  * Get object data blobs from Automerge Repo by ids.
18
18
  * @param ids
@@ -25,14 +25,14 @@ export const createLoadDocuments = (automergeHost: AutomergeHost) =>
25
25
  await warnAfterTimeout(5000, 'to long to load doc', () => handle.whenReady());
26
26
  const doc = handle.docSync();
27
27
  const hash = getHeads(doc).join('');
28
- yield [{ id, object: doc.objects[objectId], currentHash: hash }];
28
+ yield doc.objects?.[objectId] ? [{ id, object: doc.objects[objectId], currentHash: hash }] : [];
29
29
  }
30
30
  };
31
31
 
32
32
  /**
33
33
  * Factory for `getAllDocuments` iterator.
34
34
  */
35
- export const createGetAllDocuments = (automergeHost: AutomergeHost) =>
35
+ export const createDocumentsIterator = (automergeHost: AutomergeHost) =>
36
36
  /**
37
37
  * Recursively get all object data blobs from Automerge Repo.
38
38
  * @param ids
@@ -57,7 +57,7 @@ export const createGetAllDocuments = (automergeHost: AutomergeHost) =>
57
57
  return {
58
58
  id: idCodec.encode({ documentId: handle.documentId, objectId }),
59
59
  object,
60
- currentHash: heads.at(-1)!,
60
+ currentHash: heads.join(''),
61
61
  };
62
62
  });
63
63
  }
@@ -30,7 +30,7 @@ import {
30
30
  type IdentityManagerRuntimeParams,
31
31
  type JoinIdentityParams,
32
32
  } from '../identity';
33
- import { createGetAllDocuments, createLoadDocuments } from '../indexing';
33
+ import { createDocumentsIterator, createSelectedDocumentsIterator } from '../indexing';
34
34
  import {
35
35
  DeviceInvitationProtocol,
36
36
  InvitationsHandler,
@@ -125,8 +125,8 @@ export class ServiceContext {
125
125
  this.indexer = new Indexer({
126
126
  indexStore: new IndexStore({ directory: storage.createDirectory('index-store') }),
127
127
  metadataStore: this.indexMetadata,
128
- loadDocuments: createLoadDocuments(this.automergeHost),
129
- getAllDocuments: createGetAllDocuments(this.automergeHost),
128
+ loadDocuments: createSelectedDocumentsIterator(this.automergeHost),
129
+ getAllDocuments: createDocumentsIterator(this.automergeHost),
130
130
  });
131
131
 
132
132
  this.invitations = new InvitationsHandler(this.networkManager);
@@ -2,12 +2,13 @@
2
2
  // Copyright 2021 DXOS.org
3
3
  //
4
4
 
5
- import { Event, synchronized } from '@dxos/async';
6
- import { Properties, clientServiceBundle, defaultKey, type ClientServices } from '@dxos/client-protocol';
5
+ import { Event, sleep, synchronized } from '@dxos/async';
6
+ import { clientServiceBundle, defaultKey, type ClientServices, PropertiesSchema } from '@dxos/client-protocol';
7
7
  import { type Config } from '@dxos/config';
8
8
  import { Context } from '@dxos/context';
9
- import { DataServiceImpl } from '@dxos/echo-pipeline';
10
- import { getAutomergeObjectCore, getRawDoc, type SpaceDoc, type TypedObject } from '@dxos/echo-schema';
9
+ import { DataServiceImpl, type SpaceDoc } from '@dxos/echo-pipeline';
10
+ import * as E from '@dxos/echo-schema';
11
+ import { createRawObjectDoc } from '@dxos/echo-schema';
11
12
  import { IndexServiceImpl } from '@dxos/indexing';
12
13
  import { invariant } from '@dxos/invariant';
13
14
  import { PublicKey } from '@dxos/keys';
@@ -347,17 +348,20 @@ export class ClientServicesHost {
347
348
  await this._serviceContext.initialized.wait();
348
349
  const space = await this._serviceContext.dataSpaceManager!.createSpace();
349
350
 
350
- const obj: TypedObject = new Properties(undefined);
351
- obj[defaultKey] = identity.identityKey.toHex();
352
-
353
351
  const automergeIndex = space.automergeSpaceState.rootUrl;
354
352
  invariant(automergeIndex);
355
353
  const document = await this._serviceContext.automergeHost.repo.find<SpaceDoc>(automergeIndex as any);
356
354
  await document.whenReady();
357
355
 
356
+ const objectDocument = createRawObjectDoc(
357
+ { [defaultKey]: identity.identityKey.toHex() },
358
+ { type: E.getTypeReference(PropertiesSchema) },
359
+ );
358
360
  document.change((doc: SpaceDoc) => {
359
- assignDeep(doc, ['objects', getAutomergeObjectCore(obj).id], getRawDoc(obj).handle.docSync());
361
+ assignDeep(doc, ['objects', objectDocument.id], objectDocument.handle.docSync());
360
362
  });
363
+ // TODO: replace with flush when supported by automerge-repo
364
+ await sleep(200);
361
365
 
362
366
  return identity;
363
367
  }
@@ -6,7 +6,15 @@ 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 { type MetadataStore, type Space, createMappedFeedWriter, type AutomergeHost } from '@dxos/echo-pipeline';
9
+ import { TYPE_PROPERTIES } from '@dxos/echo-db';
10
+ import {
11
+ type MetadataStore,
12
+ type Space,
13
+ createMappedFeedWriter,
14
+ type AutomergeHost,
15
+ type SpaceDoc,
16
+ } from '@dxos/echo-pipeline';
17
+ import { AutomergeDocumentLoaderImpl } from '@dxos/echo-pipeline';
10
18
  import { type FeedStore } from '@dxos/feed-store';
11
19
  import { failedInvariant, invariant } from '@dxos/invariant';
12
20
  import { type Keyring } from '@dxos/keyring';
@@ -26,7 +34,7 @@ import { type GossipMessage } from '@dxos/protocols/proto/dxos/mesh/teleport/gos
26
34
  import { type Gossip, type Presence } from '@dxos/teleport-extension-gossip';
27
35
  import { Timeframe } from '@dxos/timeframe';
28
36
  import { trace } from '@dxos/tracing';
29
- import { ComplexSet } from '@dxos/util';
37
+ import { ComplexSet, assignDeep } from '@dxos/util';
30
38
 
31
39
  import { AutomergeSpaceState } from './automerge-space-state';
32
40
  import { type SigningContext } from './data-space-manager';
@@ -437,6 +445,47 @@ export class DataSpace {
437
445
  };
438
446
  }
439
447
  break;
448
+ case CreateEpochRequest.Migration.FRAGMENT_AUTOMERGE_ROOT:
449
+ {
450
+ log.info('Fragmenting');
451
+
452
+ const currentRootUrl = this._automergeSpaceState.rootUrl;
453
+ const rootHandle = this._automergeHost.repo.find<SpaceDoc>(currentRootUrl as any);
454
+ await cancelWithContext(this._ctx, asyncTimeout(rootHandle.whenReady(), 10_000));
455
+
456
+ // Find properties object.
457
+ const objects = Object.entries((rootHandle.docSync() as SpaceDoc).objects!);
458
+ const properties = objects.find(([_, value]) => value.system.type?.itemId === TYPE_PROPERTIES);
459
+ const otherObjects = objects.filter(([key]) => key !== properties?.[0]);
460
+ invariant(properties, 'Properties not found');
461
+
462
+ // Create a new space doc with the properties object.
463
+ const newSpaceDoc: SpaceDoc = { ...rootHandle.docSync(), objects: Object.fromEntries([properties]) };
464
+ const newRoot = this._automergeHost.repo.create(newSpaceDoc);
465
+ invariant(typeof newRoot.url === 'string' && newRoot.url.length > 0);
466
+
467
+ // Create new automerge documents for all objects.
468
+ const docLoader = new AutomergeDocumentLoaderImpl(this.key, this._automergeHost.repo);
469
+ await docLoader.loadSpaceRootDocHandle(this._ctx, { rootUrl: newRoot.url });
470
+
471
+ otherObjects.forEach(([key, value]) => {
472
+ const handle = docLoader.createDocumentForObject(key);
473
+ handle.change((doc: any) => {
474
+ assignDeep(doc, ['objects', key], value);
475
+ });
476
+ });
477
+
478
+ // TODO(mykola): Delete old root.
479
+
480
+ // TODO(dmaretskyi): Unify epoch construction.
481
+ epoch = {
482
+ previousId: this._automergeSpaceState.lastEpoch?.id,
483
+ number: (this._automergeSpaceState.lastEpoch?.subject.assertion.number ?? -1) + 1,
484
+ timeframe: this._automergeSpaceState.lastEpoch?.subject.assertion.timeframe ?? new Timeframe(),
485
+ automergeRoot: newRoot.url,
486
+ };
487
+ }
488
+ break;
440
489
  }
441
490
 
442
491
  if (!epoch) {
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const DXOS_VERSION = "0.4.10-main.93fda5f";
1
+ export const DXOS_VERSION = "0.4.10-main.94e3e06";