@dxos/client-services 0.8.4-main.2e9d522 → 0.8.4-main.3c1ae3b

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 (154) hide show
  1. package/dist/lib/browser/{chunk-NPM7LZLM.mjs → chunk-OD5PC2PZ.mjs} +2400 -2140
  2. package/dist/lib/browser/chunk-OD5PC2PZ.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +37 -18
  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 +12 -12
  7. package/dist/lib/browser/testing/index.mjs.map +3 -3
  8. package/dist/lib/node-esm/{chunk-3GXJDHS7.mjs → chunk-CRPF6ZN2.mjs} +2397 -2136
  9. package/dist/lib/node-esm/chunk-CRPF6ZN2.mjs.map +7 -0
  10. package/dist/lib/node-esm/index.mjs +37 -18
  11. package/dist/lib/node-esm/index.mjs.map +3 -3
  12. package/dist/lib/node-esm/meta.json +1 -1
  13. package/dist/lib/node-esm/testing/index.mjs +12 -12
  14. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  15. package/dist/types/src/packlets/agents/edge-agent-service.d.ts +1 -1
  16. package/dist/types/src/packlets/agents/edge-agent-service.d.ts.map +1 -1
  17. package/dist/types/src/packlets/devices/devices-service.d.ts.map +1 -1
  18. package/dist/types/src/packlets/devtools/devtools.d.ts +18 -18
  19. package/dist/types/src/packlets/devtools/devtools.d.ts.map +1 -1
  20. package/dist/types/src/packlets/devtools/feeds.d.ts +1 -1
  21. package/dist/types/src/packlets/devtools/feeds.d.ts.map +1 -1
  22. package/dist/types/src/packlets/devtools/network.d.ts +1 -1
  23. package/dist/types/src/packlets/devtools/network.d.ts.map +1 -1
  24. package/dist/types/src/packlets/diagnostics/browser-diagnostics-broadcast.d.ts +1 -1
  25. package/dist/types/src/packlets/diagnostics/browser-diagnostics-broadcast.d.ts.map +1 -1
  26. package/dist/types/src/packlets/diagnostics/diagnostics-broadcast.d.ts +1 -1
  27. package/dist/types/src/packlets/diagnostics/diagnostics-broadcast.d.ts.map +1 -1
  28. package/dist/types/src/packlets/diagnostics/diagnostics.d.ts +1 -1
  29. package/dist/types/src/packlets/diagnostics/diagnostics.d.ts.map +1 -1
  30. package/dist/types/src/packlets/identity/authenticator.d.ts.map +1 -1
  31. package/dist/types/src/packlets/identity/contacts-service.d.ts +1 -1
  32. package/dist/types/src/packlets/identity/contacts-service.d.ts.map +1 -1
  33. package/dist/types/src/packlets/identity/default-space-state-machine.d.ts +1 -1
  34. package/dist/types/src/packlets/identity/default-space-state-machine.d.ts.map +1 -1
  35. package/dist/types/src/packlets/identity/identity-manager.d.ts +1 -1
  36. package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
  37. package/dist/types/src/packlets/identity/identity-service.d.ts +1 -1
  38. package/dist/types/src/packlets/identity/identity-service.d.ts.map +1 -1
  39. package/dist/types/src/packlets/identity/identity.d.ts +1 -1
  40. package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
  41. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts +3 -3
  42. package/dist/types/src/packlets/invitations/device-invitation-protocol.d.ts.map +1 -1
  43. package/dist/types/src/packlets/invitations/edge-invitation-handler.d.ts +1 -1
  44. package/dist/types/src/packlets/invitations/edge-invitation-handler.d.ts.map +1 -1
  45. package/dist/types/src/packlets/invitations/invitation-guest-extenstion.d.ts.map +1 -1
  46. package/dist/types/src/packlets/invitations/invitation-host-extension.d.ts.map +1 -1
  47. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts +3 -4
  48. package/dist/types/src/packlets/invitations/invitation-protocol.d.ts.map +1 -1
  49. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  50. package/dist/types/src/packlets/invitations/invitations-manager.d.ts.map +1 -1
  51. package/dist/types/src/packlets/invitations/invitations-service.d.ts +1 -1
  52. package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
  53. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts +3 -3
  54. package/dist/types/src/packlets/invitations/space-invitation-protocol.d.ts.map +1 -1
  55. package/dist/types/src/packlets/invitations/utils.d.ts.map +1 -1
  56. package/dist/types/src/packlets/logging/logging-service.d.ts +1 -1
  57. package/dist/types/src/packlets/logging/logging-service.d.ts.map +1 -1
  58. package/dist/types/src/packlets/network/network-service.d.ts +2 -2
  59. package/dist/types/src/packlets/network/network-service.d.ts.map +1 -1
  60. package/dist/types/src/packlets/services/client-rpc-server.d.ts.map +1 -1
  61. package/dist/types/src/packlets/services/service-context.d.ts +3 -3
  62. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  63. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  64. package/dist/types/src/packlets/space-export/space-archive-writer.d.ts +1 -1
  65. package/dist/types/src/packlets/space-export/space-archive-writer.d.ts.map +1 -1
  66. package/dist/types/src/packlets/spaces/automerge-space-state.d.ts +1 -1
  67. package/dist/types/src/packlets/spaces/automerge-space-state.d.ts.map +1 -1
  68. package/dist/types/src/packlets/spaces/data-space-manager.d.ts +2 -2
  69. package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
  70. package/dist/types/src/packlets/spaces/data-space.d.ts +4 -4
  71. package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
  72. package/dist/types/src/packlets/spaces/notarization-plugin.d.ts.map +1 -1
  73. package/dist/types/src/packlets/spaces/spaces-service.d.ts +2 -2
  74. package/dist/types/src/packlets/spaces/spaces-service.d.ts.map +1 -1
  75. package/dist/types/src/packlets/storage/profile-archive.d.ts.map +1 -1
  76. package/dist/types/src/packlets/storage/storage.d.ts.map +1 -1
  77. package/dist/types/src/packlets/system/system-service.d.ts +1 -1
  78. package/dist/types/src/packlets/system/system-service.d.ts.map +1 -1
  79. package/dist/types/src/packlets/testing/invitation-utils.d.ts.map +1 -1
  80. package/dist/types/src/packlets/testing/test-builder.d.ts +2 -2
  81. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  82. package/dist/types/src/packlets/worker/worker-runtime.d.ts.map +1 -1
  83. package/dist/types/src/packlets/worker/worker-session.d.ts.map +1 -1
  84. package/dist/types/src/version.d.ts +1 -1
  85. package/dist/types/tsconfig.tsbuildinfo +1 -1
  86. package/package.json +41 -39
  87. package/src/packlets/agents/edge-agent-manager.ts +2 -2
  88. package/src/packlets/agents/edge-agent-service.ts +13 -3
  89. package/src/packlets/devices/devices-service.test.ts +4 -3
  90. package/src/packlets/devices/devices-service.ts +2 -2
  91. package/src/packlets/devtools/devtools.ts +28 -27
  92. package/src/packlets/devtools/feeds.ts +2 -2
  93. package/src/packlets/devtools/network.ts +1 -1
  94. package/src/packlets/diagnostics/browser-diagnostics-broadcast.ts +1 -1
  95. package/src/packlets/diagnostics/diagnostics-broadcast.ts +1 -1
  96. package/src/packlets/diagnostics/diagnostics-collector.ts +1 -1
  97. package/src/packlets/diagnostics/diagnostics.ts +1 -1
  98. package/src/packlets/identity/authenticator.node.test.ts +1 -1
  99. package/src/packlets/identity/authenticator.ts +1 -1
  100. package/src/packlets/identity/contacts-service.ts +3 -2
  101. package/src/packlets/identity/default-space-state-machine.ts +1 -1
  102. package/src/packlets/identity/identity-manager.test.ts +3 -3
  103. package/src/packlets/identity/identity-manager.ts +3 -3
  104. package/src/packlets/identity/identity-service.test.ts +3 -2
  105. package/src/packlets/identity/identity-service.ts +2 -1
  106. package/src/packlets/identity/identity.test.ts +9 -9
  107. package/src/packlets/identity/identity.ts +7 -6
  108. package/src/packlets/invitations/device-invitation-protocol.test.ts +1 -1
  109. package/src/packlets/invitations/device-invitation-protocol.ts +5 -4
  110. package/src/packlets/invitations/edge-invitation-handler.ts +1 -1
  111. package/src/packlets/invitations/invitation-guest-extenstion.ts +7 -5
  112. package/src/packlets/invitations/invitation-host-extension.ts +8 -6
  113. package/src/packlets/invitations/invitation-protocol.ts +3 -4
  114. package/src/packlets/invitations/invitations-handler.test.ts +4 -3
  115. package/src/packlets/invitations/invitations-handler.ts +4 -4
  116. package/src/packlets/invitations/invitations-manager.ts +3 -3
  117. package/src/packlets/invitations/invitations-service.ts +1 -1
  118. package/src/packlets/invitations/space-invitation-protocol.test.ts +2 -2
  119. package/src/packlets/invitations/space-invitation-protocol.ts +10 -15
  120. package/src/packlets/invitations/utils.ts +1 -1
  121. package/src/packlets/locks/browser.ts +1 -1
  122. package/src/packlets/logging/logging-service.ts +3 -3
  123. package/src/packlets/logging/logging.test.ts +1 -1
  124. package/src/packlets/network/network-service.test.ts +4 -3
  125. package/src/packlets/network/network-service.ts +2 -2
  126. package/src/packlets/services/client-rpc-server.ts +1 -1
  127. package/src/packlets/services/service-context.test.ts +1 -1
  128. package/src/packlets/services/service-context.ts +9 -8
  129. package/src/packlets/services/service-host.test.ts +3 -2
  130. package/src/packlets/services/service-host.ts +17 -9
  131. package/src/packlets/services/service-registry.test.ts +2 -1
  132. package/src/packlets/space-export/space-archive-reader.ts +2 -2
  133. package/src/packlets/space-export/space-archive-writer.ts +7 -5
  134. package/src/packlets/space-export/tar.test.ts +1 -1
  135. package/src/packlets/spaces/automerge-space-state.ts +1 -1
  136. package/src/packlets/spaces/data-space-manager.ts +44 -23
  137. package/src/packlets/spaces/data-space.ts +10 -9
  138. package/src/packlets/spaces/edge-feed-replicator.test.ts +3 -3
  139. package/src/packlets/spaces/edge-feed-replicator.ts +2 -2
  140. package/src/packlets/spaces/notarization-plugin.test.ts +1 -1
  141. package/src/packlets/spaces/notarization-plugin.ts +5 -5
  142. package/src/packlets/spaces/spaces-service.test.ts +3 -2
  143. package/src/packlets/spaces/spaces-service.ts +27 -23
  144. package/src/packlets/storage/profile-archive.ts +1 -1
  145. package/src/packlets/storage/storage.ts +7 -8
  146. package/src/packlets/system/system-service.test.ts +1 -1
  147. package/src/packlets/system/system-service.ts +4 -4
  148. package/src/packlets/testing/invitation-utils.ts +1 -1
  149. package/src/packlets/testing/test-builder.ts +3 -3
  150. package/src/packlets/worker/worker-runtime.ts +2 -1
  151. package/src/packlets/worker/worker-session.ts +4 -4
  152. package/src/version.ts +1 -1
  153. package/dist/lib/browser/chunk-NPM7LZLM.mjs.map +0 -7
  154. package/dist/lib/node-esm/chunk-3GXJDHS7.mjs.map +0 -7
@@ -13,10 +13,11 @@ import { schema } from '@dxos/protocols/proto';
13
13
  import { type SystemService, SystemStatus } from '@dxos/protocols/proto/dxos/client/services';
14
14
  import { createLinkedPorts, createProtoRpcPeer, createServiceBundle } from '@dxos/rpc';
15
15
 
16
- import { ServiceRegistry } from './service-registry';
17
16
  import { SystemServiceImpl } from '../system';
18
17
  import { createServiceContext } from '../testing';
19
18
 
19
+ import { ServiceRegistry } from './service-registry';
20
+
20
21
  // TODO(burdon): Create TestService (that doesn't require peers).
21
22
 
22
23
  type TestServices = {
@@ -18,7 +18,7 @@ export const extractSpaceArchive = async (archive: SpaceArchive): Promise<Extrac
18
18
  const { Archive } = await import('@obsidize/tar-browserify');
19
19
  const { entries } = await Archive.extract(archive.contents);
20
20
  const metadataEntry = entries.find((entry) => entry.fileName === SpaceArchiveFileStructure.metadata);
21
- assertArgument(metadataEntry, 'Metadata entry not found');
21
+ assertArgument(metadataEntry, 'metadataEntry', 'Metadata entry not found');
22
22
  const metadata = JSON.parse(metadataEntry.getContentAsText());
23
23
  const documents: Record<DocumentId, Uint8Array> = {};
24
24
  for (const entry of entries.filter((entry) => entry.fileName.startsWith(`${SpaceArchiveFileStructure.documents}/`))) {
@@ -29,6 +29,6 @@ export const extractSpaceArchive = async (archive: SpaceArchive): Promise<Extrac
29
29
  documents[documentId] = entry.content ?? failedInvariant();
30
30
  }
31
31
 
32
- log.info('extracted space archive', { metadata, documents });
32
+ log('extracted space archive', { metadata, documents });
33
33
  return { metadata, documents };
34
34
  };
@@ -4,11 +4,12 @@
4
4
 
5
5
  import type * as tar from '@obsidize/tar-browserify';
6
6
 
7
- import { Resource, type Context } from '@dxos/context';
7
+ import { type Context, Resource } from '@dxos/context';
8
8
  import { assertArgument, assertState } from '@dxos/invariant';
9
9
  import type { IdentityDid, SpaceId } from '@dxos/keys';
10
- import { SpaceArchiveFileStructure, SpaceArchiveVersion, type SpaceArchiveMetadata } from '@dxos/protocols';
10
+ import { SpaceArchiveFileStructure, type SpaceArchiveMetadata, SpaceArchiveVersion } from '@dxos/protocols';
11
11
  import type { SpaceArchive } from '@dxos/protocols/proto/dxos/client/services';
12
+ import { createFilename } from '@dxos/util';
12
13
 
13
14
  export type SpaceArchiveBeginProps = {
14
15
  spaceId?: SpaceId;
@@ -44,14 +45,14 @@ export class SpaceArchiveWriter extends Resource {
44
45
  }
45
46
 
46
47
  async setCurrentRootUrl(url: string): Promise<void> {
47
- assertArgument(url.startsWith('automerge:'), 'Invalid root URL');
48
+ assertArgument(url.startsWith('automerge:'), 'url', 'Invalid root URL');
48
49
  assertState(this._tar, 'Not open');
49
50
  assertState(this._meta, 'Not started');
50
51
  this._currentRootUrl = url;
51
52
  }
52
53
 
53
54
  async writeDocument(documentId: string, data: Uint8Array): Promise<void> {
54
- assertArgument(!documentId.startsWith('automerge:'), 'Invalid document ID');
55
+ assertArgument(!documentId.startsWith('automerge:'), 'documentId', 'Invalid document ID');
55
56
  assertState(this._archive, 'Not open');
56
57
  this._archive.addBinaryFile(`${SpaceArchiveFileStructure.documents}/${documentId}.bin`, data);
57
58
  }
@@ -59,6 +60,7 @@ export class SpaceArchiveWriter extends Resource {
59
60
  async finish(): Promise<SpaceArchive> {
60
61
  assertState(this._archive, 'Not open');
61
62
  assertState(this._meta, 'Not started');
63
+ assertState(this._meta.spaceId, 'No space ID set');
62
64
  assertState(this._currentRootUrl, 'No root URL set');
63
65
 
64
66
  const metadata: SpaceArchiveMetadata = {
@@ -76,7 +78,7 @@ export class SpaceArchiveWriter extends Resource {
76
78
  const binary = this._archive.toUint8Array();
77
79
 
78
80
  return {
79
- filename: `${this._meta.spaceId}.tar`,
81
+ filename: createFilename({ parts: [this._meta.spaceId], ext: 'tar' }),
80
82
  contents: binary,
81
83
  };
82
84
  }
@@ -3,7 +3,7 @@
3
3
  //
4
4
 
5
5
  import { Archive } from '@obsidize/tar-browserify';
6
- import { describe, it, expect } from 'vitest';
6
+ import { describe, expect, it } from 'vitest';
7
7
 
8
8
  describe('tar', () => {
9
9
  it('should create a tar archive', async () => {
@@ -3,7 +3,7 @@
3
3
  //
4
4
 
5
5
  import { Event } from '@dxos/async';
6
- import { Resource, type Context } from '@dxos/context';
6
+ import { type Context, Resource } from '@dxos/context';
7
7
  import { type CredentialProcessor, type SpecificCredential, checkCredentialType } from '@dxos/credentials';
8
8
  import { type Credential, type Epoch } from '@dxos/protocols/proto/dxos/halo/credentials';
9
9
 
@@ -3,66 +3,68 @@
3
3
  //
4
4
 
5
5
  import { type Doc } from '@automerge/automerge';
6
- import { interpretAsDocumentId, type AutomergeUrl, type DocHandle, type DocumentId } from '@automerge/automerge-repo';
6
+ import { type AutomergeUrl, type DocHandle, type DocumentId, interpretAsDocumentId } from '@automerge/automerge-repo';
7
7
 
8
8
  import { Event, synchronized, trackLeaks } from '@dxos/async';
9
- import { PropertiesType, TYPE_PROPERTIES } from '@dxos/client-protocol';
9
+ import { SpaceProperties } from '@dxos/client-protocol';
10
10
  import { Context, LifecycleState, Resource, cancelWithContext } from '@dxos/context';
11
11
  import {
12
- createAdmissionCredentials,
13
- getCredentialAssertion,
14
12
  type CredentialSigner,
15
13
  type DelegateInvitationCredential,
16
14
  type MemberInfo,
15
+ createAdmissionCredentials,
16
+ getCredentialAssertion,
17
17
  } from '@dxos/credentials';
18
+ import { Type } from '@dxos/echo';
19
+ import { getTypeReference } from '@dxos/echo/internal';
18
20
  import {
21
+ AuthStatus,
22
+ CredentialServerExtension,
19
23
  DatabaseRoot,
20
- findInlineObjectOfType,
21
24
  type EchoEdgeReplicator,
22
25
  type EchoHost,
23
- AuthStatus,
24
- CredentialServerExtension,
26
+ FIND_PARAMS,
25
27
  type MeshEchoReplicator,
26
28
  type MetadataStore,
27
29
  type Space,
28
30
  type SpaceManager,
29
31
  type SpaceProtocol,
30
32
  type SpaceProtocolSession,
31
- FIND_PARAMS,
33
+ findInlineObjectOfType,
32
34
  } from '@dxos/echo-pipeline';
33
35
  import {
36
+ type DatabaseDirectory,
37
+ type ObjectStructure,
34
38
  SpaceDocVersion,
35
39
  createIdFromSpaceKey,
36
40
  encodeReference,
37
- type ObjectStructure,
38
- type DatabaseDirectory,
39
41
  } from '@dxos/echo-protocol';
40
- import { ObjectId, getTypeReference } from '@dxos/echo-schema';
41
42
  import type { EdgeConnection, EdgeHttpClient } from '@dxos/edge-client';
42
- import { writeMessages, type FeedStore } from '@dxos/feed-store';
43
+ import { type FeedStore, writeMessages } from '@dxos/feed-store';
43
44
  import { assertArgument, assertState, failedInvariant, invariant } from '@dxos/invariant';
44
45
  import { type Keyring } from '@dxos/keyring';
45
- import { PublicKey, type SpaceId } from '@dxos/keys';
46
+ import { ObjectId, PublicKey, type SpaceId } from '@dxos/keys';
46
47
  import { log } from '@dxos/log';
47
48
  import { AlreadyJoinedError, trace as Trace } from '@dxos/protocols';
48
49
  import { Invitation, SpaceState } from '@dxos/protocols/proto/dxos/client/services';
49
50
  import { type Runtime } from '@dxos/protocols/proto/dxos/config';
50
51
  import { type FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';
51
- import { type SpaceMetadata, EdgeReplicationSetting } from '@dxos/protocols/proto/dxos/echo/metadata';
52
- import { SpaceMember, type Credential, type ProfileDocument } from '@dxos/protocols/proto/dxos/halo/credentials';
52
+ import { EdgeReplicationSetting, type SpaceMetadata } from '@dxos/protocols/proto/dxos/echo/metadata';
53
+ import { type Credential, type ProfileDocument, SpaceMember } from '@dxos/protocols/proto/dxos/halo/credentials';
53
54
  import { type DelegateSpaceInvitation } from '@dxos/protocols/proto/dxos/halo/invitations';
54
55
  import { type PeerState } from '@dxos/protocols/proto/dxos/mesh/presence';
55
56
  import { type Teleport } from '@dxos/teleport';
56
57
  import { Gossip, Presence } from '@dxos/teleport-extension-gossip';
57
58
  import { type Timeframe } from '@dxos/timeframe';
58
59
  import { trace } from '@dxos/tracing';
59
- import { ComplexMap, setDeep, deferFunction, forEachAsync } from '@dxos/util';
60
+ import { ComplexMap, deferFunction, forEachAsync, setDeep } from '@dxos/util';
60
61
 
61
- import { DataSpace } from './data-space';
62
- import { spaceGenesis } from './genesis';
63
62
  import { createAuthProvider } from '../identity';
64
63
  import { type InvitationsManager } from '../invitations';
65
64
 
65
+ import { DataSpace } from './data-space';
66
+ import { spaceGenesis } from './genesis';
67
+
66
68
  const PRESENCE_ANNOUNCE_INTERVAL = 10_000;
67
69
  const PRESENCE_OFFLINE_TIMEOUT = 20_000;
68
70
 
@@ -183,7 +185,7 @@ export class DataSpaceManager extends Resource {
183
185
  await rootHandle?.whenReady();
184
186
  const rootDoc = rootHandle?.doc();
185
187
 
186
- const properties = rootDoc && findInlineObjectOfType(rootDoc, TYPE_PROPERTIES);
188
+ const properties = rootDoc && findInlineObjectOfType(rootDoc, Type.getTypename(SpaceProperties));
187
189
 
188
190
  return {
189
191
  key: space.key.toHex(),
@@ -244,7 +246,11 @@ export class DataSpaceManager extends Resource {
244
246
  */
245
247
  @synchronized
246
248
  async createSpace(options: CreateSpaceOptions = {}): Promise<DataSpace> {
247
- assertArgument(!!options.rootUrl === !!options.documents, 'root url must be required when providing documents');
249
+ assertArgument(
250
+ !!options.rootUrl === !!options.documents,
251
+ 'options',
252
+ 'root url must be required when providing documents',
253
+ );
248
254
 
249
255
  assertState(this._lifecycleState === LifecycleState.OPEN, 'Not open.');
250
256
  const spaceKey = await this._keyring.createKey();
@@ -274,7 +280,18 @@ export class DataSpaceManager extends Resource {
274
280
  await Promise.all(
275
281
  Object.entries(options.documents).map(async ([documentId, data]) => {
276
282
  log('creating document...', { documentId });
277
- const newDoc = await this._echoHost.createDoc(data, { preserveHistory: true });
283
+ // TODO(dmaretskyi): Broken types -- the bytes get interpreted as CRDT data.
284
+ const newDoc = await this._echoHost.createDoc(data as any as DatabaseDirectory, {
285
+ preserveHistory: true,
286
+ });
287
+
288
+ // The archived documents might have the spaceKey from the space they were expored from, we need to update it to the new spaceKey.
289
+ if (newDoc.doc().access !== undefined && newDoc.doc().access!.spaceKey !== spaceKey.toHex()) {
290
+ newDoc.change((doc) => {
291
+ doc.access!.spaceKey = spaceKey.toHex();
292
+ });
293
+ }
294
+
278
295
  documentIdMapping[documentId as DocumentId] = newDoc.documentId;
279
296
  }),
280
297
  );
@@ -292,6 +309,7 @@ export class DataSpaceManager extends Resource {
292
309
  } else {
293
310
  root = await this._echoHost.createSpaceRoot(spaceKey);
294
311
  }
312
+ await this._echoHost.flush();
295
313
 
296
314
  log('constructing space...', { spaceKey });
297
315
 
@@ -325,9 +343,12 @@ export class DataSpaceManager extends Resource {
325
343
  log.warn('waiting for space root to be ready', { spaceId: space.id });
326
344
  await space.databaseRoot.handle.whenReady();
327
345
  }
328
- const [_, properties] = findInlineObjectOfType(space.databaseRoot.doc()!, TYPE_PROPERTIES) ?? [];
346
+
347
+ const [_, properties] =
348
+ findInlineObjectOfType(space.databaseRoot.doc()!, Type.getTypename(SpaceProperties)) ?? [];
329
349
  return properties?.data?.[DEFAULT_SPACE_KEY] === this._signingContext.identityKey.toHex();
330
350
  }
351
+
331
352
  case SpaceDocVersion.LEGACY: {
332
353
  throw new Error('Legacy space version is not supported');
333
354
  }
@@ -345,7 +366,7 @@ export class DataSpaceManager extends Resource {
345
366
  // TODO(dmaretskyi): Better API for low-level data access.
346
367
  const properties: ObjectStructure = {
347
368
  system: {
348
- type: encodeReference(getTypeReference(PropertiesType)!),
369
+ type: encodeReference(getTypeReference(SpaceProperties)!),
349
370
  },
350
371
  data: {
351
372
  [DEFAULT_SPACE_KEY]: this._signingContext.identityKey.toHex(),
@@ -11,14 +11,14 @@ import { Context, ContextDisposedError, cancelWithContext } from '@dxos/context'
11
11
  import type { SpecificCredential } from '@dxos/credentials';
12
12
  import { timed, warnAfterTimeout } from '@dxos/debug';
13
13
  import {
14
- type EchoHost,
15
14
  type DatabaseRoot,
16
- createMappedFeedWriter,
15
+ type EchoHost,
16
+ FIND_PARAMS,
17
17
  type MetadataStore,
18
18
  type Space,
19
- FIND_PARAMS,
19
+ createMappedFeedWriter,
20
20
  } from '@dxos/echo-pipeline';
21
- import { SpaceDocVersion, type DatabaseDirectory } from '@dxos/echo-protocol';
21
+ import { type DatabaseDirectory, SpaceDocVersion } 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';
@@ -28,31 +28,32 @@ import { log } from '@dxos/log';
28
28
  import { CancelledError, SystemError } from '@dxos/protocols';
29
29
  import {
30
30
  type CreateEpochRequest,
31
- SpaceState,
32
31
  type Space as SpaceProto,
32
+ SpaceState,
33
33
  } from '@dxos/protocols/proto/dxos/client/services';
34
34
  import { type Runtime } from '@dxos/protocols/proto/dxos/config';
35
35
  import { type FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';
36
36
  import { type SpaceCache } from '@dxos/protocols/proto/dxos/echo/metadata';
37
37
  import {
38
38
  AdmittedFeed,
39
- SpaceMember,
40
39
  type Credential,
41
40
  type Epoch,
42
41
  type ProfileDocument,
42
+ SpaceMember,
43
43
  } from '@dxos/protocols/proto/dxos/halo/credentials';
44
44
  import { type GossipMessage } from '@dxos/protocols/proto/dxos/mesh/teleport/gossip';
45
45
  import { type Gossip, type Presence } from '@dxos/teleport-extension-gossip';
46
46
  import { Timeframe } from '@dxos/timeframe';
47
47
  import { trace } from '@dxos/tracing';
48
- import { CallbackCollection, ComplexSet, type AsyncCallback } from '@dxos/util';
48
+ import { type AsyncCallback, CallbackCollection, ComplexSet } from '@dxos/util';
49
+
50
+ import { TrustedKeySetAuthVerifier } from '../identity';
49
51
 
50
52
  import { AutomergeSpaceState } from './automerge-space-state';
51
53
  import { type SigningContext } from './data-space-manager';
52
54
  import { EdgeFeedReplicator } from './edge-feed-replicator';
53
55
  import { runEpochMigration } from './epoch-migrations';
54
56
  import { NotarizationPlugin } from './notarization-plugin';
55
- import { TrustedKeySetAuthVerifier } from '../identity';
56
57
 
57
58
  export type DataSpaceCallbacks = {
58
59
  /**
@@ -330,7 +331,7 @@ export class DataSpace {
330
331
  @trace.span({ showInBrowserTimeline: true })
331
332
  async initializeDataPipeline(): Promise<void> {
332
333
  if (this._state !== SpaceState.SPACE_CONTROL_ONLY) {
333
- throw new SystemError('Invalid operation');
334
+ throw new SystemError({ message: 'Invalid operation' });
334
335
  }
335
336
 
336
337
  this._state = SpaceState.SPACE_INITIALIZING;
@@ -6,10 +6,10 @@ import { decode as decodeCbor, encode as encodeCbor } from 'cbor-x';
6
6
  import { getPort } from 'get-port-please';
7
7
  import { describe, expect, onTestFinished, test, vi } from 'vitest';
8
8
 
9
- import { sleep, Trigger } from '@dxos/async';
9
+ import { Trigger, sleep } from '@dxos/async';
10
10
  import { Context } from '@dxos/context';
11
11
  import { valueEncoding } from '@dxos/echo-pipeline';
12
- import { createEphemeralEdgeIdentity, EdgeClient, EdgeIdentityChangedError } from '@dxos/edge-client';
12
+ import { EdgeClient, EdgeIdentityChangedError, createEphemeralEdgeIdentity } from '@dxos/edge-client';
13
13
  import { createTestEdgeWsServer } from '@dxos/edge-client/testing';
14
14
  import { FeedFactory, FeedStore, type FeedWrapper } from '@dxos/feed-store';
15
15
  import { Keyring } from '@dxos/keyring';
@@ -45,7 +45,7 @@ describe('EdgeFeedReplicator', () => {
45
45
  const { endpoint, admitConnection, messageSink } = await createEdge();
46
46
  const { messenger } = await createClient(endpoint);
47
47
  admitConnection.wake();
48
- await expect.poll(() => messenger.status).toBe(EdgeStatus.CONNECTED);
48
+ await expect.poll(() => messenger.status.state).toBe(EdgeStatus.ConnectionState.CONNECTED);
49
49
 
50
50
  await attachReplicator(messenger);
51
51
  await expect.poll(() => messageSink.length).toEqual(1);
@@ -15,8 +15,8 @@ import { log, logInfo } from '@dxos/log';
15
15
  import { EdgeService } from '@dxos/protocols';
16
16
  import { buf } from '@dxos/protocols/buf';
17
17
  import {
18
- MessageSchema as RouterMessageSchema,
19
18
  type Message as RouterMessage,
19
+ MessageSchema as RouterMessageSchema,
20
20
  } from '@dxos/protocols/buf/dxos/edge/messenger_pb';
21
21
  import type { FeedBlock, ProtocolMessage } from '@dxos/protocols/feed-replication';
22
22
  import { EdgeStatus } from '@dxos/protocols/proto/dxos/client/services';
@@ -87,7 +87,7 @@ export class EdgeFeedReplicator extends Resource {
87
87
 
88
88
  private async _handleReconnect(): Promise<void> {
89
89
  await this._resetConnection();
90
- if (this._messenger.status === EdgeStatus.CONNECTED) {
90
+ if (this._messenger.status.state === EdgeStatus.ConnectionState.CONNECTED) {
91
91
  this._startReplication();
92
92
  }
93
93
  }
@@ -2,7 +2,7 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { onTestFinished, describe, expect, test } from 'vitest';
5
+ import { describe, expect, onTestFinished, test } from 'vitest';
6
6
 
7
7
  import { Context } from '@dxos/context';
8
8
  import { CredentialGenerator } from '@dxos/credentials';
@@ -2,15 +2,15 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { DeferredTask, Event, scheduleTask, sleep, TimeoutError, Trigger, scheduleMicroTask } from '@dxos/async';
6
- import { type Context, rejectOnDispose, Resource } from '@dxos/context';
5
+ import { DeferredTask, Event, TimeoutError, Trigger, scheduleMicroTask, scheduleTask, sleep } from '@dxos/async';
6
+ import { type Context, Resource, rejectOnDispose } from '@dxos/context';
7
7
  import { type CredentialProcessor, verifyCredential } from '@dxos/credentials';
8
8
  import { type EdgeHttpClient } from '@dxos/edge-client';
9
9
  import { type FeedWriter } from '@dxos/feed-store';
10
10
  import { invariant } from '@dxos/invariant';
11
11
  import { PublicKey } from '@dxos/keys';
12
12
  import { type SpaceId } from '@dxos/keys';
13
- import { logInfo, log } from '@dxos/log';
13
+ import { log, logInfo } from '@dxos/log';
14
14
  import { EdgeCallFailedError } from '@dxos/protocols';
15
15
  import { schema } from '@dxos/protocols/proto';
16
16
  import { type Runtime } from '@dxos/protocols/proto/dxos/config';
@@ -392,10 +392,10 @@ export class NotarizationPlugin extends Resource implements CredentialProcessor
392
392
  }
393
393
 
394
394
  const handleEdgeError = (error: any) => {
395
- if (!(error instanceof EdgeCallFailedError) || error.errorData) {
395
+ if (!(error instanceof EdgeCallFailedError) || error.data) {
396
396
  log.catch(error);
397
397
  } else {
398
- log.info('Edge notarization failure', { reason: error.reason });
398
+ log.info('Edge notarization failure', { message: error.message });
399
399
  }
400
400
  };
401
401
 
@@ -2,17 +2,18 @@
2
2
  // Copyright 2023 DXOS.org
3
3
  //
4
4
 
5
- import { afterEach, onTestFinished, beforeEach, describe, expect, test } from 'vitest';
5
+ import { afterEach, beforeEach, describe, expect, onTestFinished, test } from 'vitest';
6
6
 
7
7
  import { Trigger } from '@dxos/async';
8
8
  import { Context } from '@dxos/context';
9
9
  import { PublicKey } from '@dxos/keys';
10
10
  import { type Space, type SpacesService } from '@dxos/protocols/proto/dxos/client/services';
11
11
 
12
- import { SpacesServiceImpl } from './spaces-service';
13
12
  import { type ServiceContext } from '../services';
14
13
  import { createServiceContext } from '../testing';
15
14
 
15
+ import { SpacesServiceImpl } from './spaces-service';
16
+
16
17
  describe('SpacesService', () => {
17
18
  let serviceContext: ServiceContext;
18
19
  let spacesService: SpacesService;
@@ -19,44 +19,45 @@ import { assertArgument, assertState, invariant } from '@dxos/invariant';
19
19
  import { SpaceId } from '@dxos/keys';
20
20
  import { log } from '@dxos/log';
21
21
  import {
22
- encodeError,
23
22
  ApiError,
24
23
  AuthorizationError,
25
24
  IdentityNotInitializedError,
26
25
  SpaceNotFoundError,
26
+ encodeError,
27
27
  } from '@dxos/protocols';
28
28
  import {
29
- SpaceMember,
30
- SpaceState,
29
+ type AdmitContactRequest,
30
+ type ContactAdmission,
31
31
  type CreateEpochRequest,
32
+ type CreateEpochResponse,
33
+ type ExportSpaceRequest,
34
+ type ExportSpaceResponse,
35
+ type ImportSpaceRequest,
36
+ type ImportSpaceResponse,
37
+ type JoinBySpaceKeyRequest,
38
+ type JoinSpaceResponse,
32
39
  type PostMessageRequest,
33
40
  type QueryCredentialsRequest,
34
41
  type QuerySpacesResponse,
35
42
  type Space,
43
+ SpaceMember,
44
+ SpaceState,
36
45
  type SpacesService,
37
46
  type SubscribeMessagesRequest,
47
+ type UpdateMemberRoleRequest,
38
48
  type UpdateSpaceRequest,
39
49
  type WriteCredentialsRequest,
40
- type UpdateMemberRoleRequest,
41
- type AdmitContactRequest,
42
- type ContactAdmission,
43
- type JoinSpaceResponse,
44
- type JoinBySpaceKeyRequest,
45
- type CreateEpochResponse,
46
- type ExportSpaceResponse,
47
- type ExportSpaceRequest,
48
- type ImportSpaceRequest,
49
- type ImportSpaceResponse,
50
50
  } from '@dxos/protocols/proto/dxos/client/services';
51
51
  import { type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';
52
52
  import { type GossipMessage } from '@dxos/protocols/proto/dxos/mesh/teleport/gossip';
53
53
  import { trace } from '@dxos/tracing';
54
54
  import { type Provider } from '@dxos/util';
55
55
 
56
+ import { type IdentityManager } from '../identity';
57
+ import { SpaceArchiveWriter, extractSpaceArchive } from '../space-export';
58
+
56
59
  import { type DataSpace } from './data-space';
57
60
  import { type DataSpaceManager } from './data-space-manager';
58
- import { type IdentityManager } from '../identity';
59
- import { extractSpaceArchive, SpaceArchiveWriter } from '../space-export';
60
61
 
61
62
  export class SpacesServiceImpl implements SpacesService {
62
63
  constructor(
@@ -87,7 +88,7 @@ export class SpacesServiceImpl implements SpacesService {
87
88
  await space.deactivate();
88
89
  break;
89
90
  default:
90
- throw new ApiError('Invalid space state');
91
+ throw new ApiError({ message: 'Invalid space state' });
91
92
  }
92
93
  }
93
94
 
@@ -103,9 +104,12 @@ export class SpacesServiceImpl implements SpacesService {
103
104
  throw new SpaceNotFoundError(request.spaceKey);
104
105
  }
105
106
  if (!space.spaceState.hasMembershipManagementPermission(identity.identityKey)) {
106
- throw new AuthorizationError('No member management permission.', {
107
- spaceKey: space.key,
108
- role: space.spaceState.getMemberRole(identity.identityKey),
107
+ throw new AuthorizationError({
108
+ message: 'No member management permission.',
109
+ context: {
110
+ spaceKey: space.key,
111
+ role: space.spaceState.getMemberRole(identity.identityKey),
112
+ },
109
113
  });
110
114
  }
111
115
  const credentials = await createAdmissionCredentials(
@@ -266,7 +270,7 @@ export class SpacesServiceImpl implements SpacesService {
266
270
 
267
271
  async exportSpace(request: ExportSpaceRequest): Promise<ExportSpaceResponse> {
268
272
  await using writer = await new SpaceArchiveWriter().open();
269
- assertArgument(SpaceId.isValid(request.spaceId), 'Invalid space ID');
273
+ assertArgument(SpaceId.isValid(request.spaceId), 'spaceId', 'Invalid space ID');
270
274
 
271
275
  const dataSpaceManager = await this._getDataSpaceManager();
272
276
  const space = dataSpaceManager.getSpaceById(request.spaceId) ?? raise(new Error('Space not found'));
@@ -367,9 +371,9 @@ export class SpacesServiceImpl implements SpacesService {
367
371
 
368
372
  private _requireIdentity() {
369
373
  if (!this._identityManager.identity) {
370
- throw new IdentityNotInitializedError(
371
- 'This device has no HALO identity available. See https://docs.dxos.org/guide/platform/halo',
372
- );
374
+ throw new IdentityNotInitializedError({
375
+ message: 'This device has no HALO identity available. See https://docs.dxos.org/guide/platform/halo',
376
+ });
373
377
  }
374
378
  return this._identityManager.identity;
375
379
  }
@@ -7,7 +7,7 @@ import { cbor } from '@automerge/automerge-repo';
7
7
  import { invariant } from '@dxos/invariant';
8
8
  import type { LevelDB } from '@dxos/kv-store';
9
9
  import { log } from '@dxos/log';
10
- import { ProfileArchiveEntryType, type ProfileArchive } from '@dxos/protocols';
10
+ import { type ProfileArchive, ProfileArchiveEntryType } from '@dxos/protocols';
11
11
  import type { Storage } from '@dxos/random-access-storage';
12
12
  import { arrayToBuffer } from '@dxos/util';
13
13
 
@@ -1,30 +1,29 @@
1
- //
2
-
3
1
  //
4
2
  // Copyright 2023 DXOS.org
5
3
  //
6
4
 
7
5
  import { InvalidConfigError } from '@dxos/protocols';
8
6
  import { Runtime } from '@dxos/protocols/proto/dxos/config';
9
- import { createStorage, StorageType } from '@dxos/random-access-storage';
7
+ import { StorageType, createStorage } from '@dxos/random-access-storage';
10
8
 
11
- import StorageDriver = Runtime.Client.Storage.StorageDriver;
12
9
  import { getRootPath } from './util';
13
10
 
11
+ import StorageDriver = Runtime.Client.Storage.StorageDriver;
12
+
14
13
  // TODO(burdon): Factor out.
15
14
  export const createStorageObjects = (config: Runtime.Client.Storage) => {
16
15
  const { persistent = false, keyStore, dataStore } = config ?? {};
17
16
  if (persistent && dataStore === StorageDriver.RAM) {
18
- throw new InvalidConfigError('RAM storage cannot be used in persistent mode.');
17
+ throw new InvalidConfigError({ message: 'RAM storage cannot be used in persistent mode.' });
19
18
  }
20
19
  if (!persistent && dataStore !== undefined && dataStore !== StorageDriver.RAM) {
21
- throw new InvalidConfigError('Cannot use a persistent storage in not persistent mode.');
20
+ throw new InvalidConfigError({ message: 'Cannot use a persistent storage in not persistent mode.' });
22
21
  }
23
22
  if (persistent && keyStore === StorageDriver.RAM) {
24
- throw new InvalidConfigError('RAM key storage cannot be used in persistent mode.');
23
+ throw new InvalidConfigError({ message: 'RAM key storage cannot be used in persistent mode.' });
25
24
  }
26
25
  if (!persistent && keyStore !== StorageDriver.RAM && keyStore !== undefined) {
27
- throw new InvalidConfigError('Cannot use a persistent key storage in not persistent mode.');
26
+ throw new InvalidConfigError({ message: 'Cannot use a persistent key storage in not persistent mode.' });
28
27
  }
29
28
 
30
29
  return {
@@ -6,7 +6,7 @@ import { beforeEach, describe, expect, test } from 'vitest';
6
6
 
7
7
  import { Event, Trigger } from '@dxos/async';
8
8
  import { Config } from '@dxos/config';
9
- import { type SystemService, SystemStatus, type QueryStatusResponse } from '@dxos/protocols/proto/dxos/client/services';
9
+ import { type QueryStatusResponse, type SystemService, SystemStatus } from '@dxos/protocols/proto/dxos/client/services';
10
10
 
11
11
  import { SystemServiceImpl } from './system-service';
12
12
 
@@ -7,14 +7,14 @@ import { Stream } from '@dxos/codec-protobuf/stream';
7
7
  import { type Config } from '@dxos/config';
8
8
  import {
9
9
  GetDiagnosticsRequest,
10
+ type Platform,
11
+ type QueryStatusRequest,
12
+ type QueryStatusResponse,
10
13
  type SystemService,
11
14
  type SystemStatus,
12
15
  type UpdateStatusRequest,
13
- type QueryStatusRequest,
14
- type QueryStatusResponse,
15
- type Platform,
16
16
  } from '@dxos/protocols/proto/dxos/client/services';
17
- import { jsonKeyReplacer, type MaybePromise } from '@dxos/util';
17
+ import { type MaybePromise, jsonKeyReplacer } from '@dxos/util';
18
18
 
19
19
  import { type Diagnostics } from '../diagnostics';
20
20
  import { getPlatform } from '../services/platform';
@@ -3,7 +3,7 @@
3
3
  //
4
4
 
5
5
  import { Trigger } from '@dxos/async';
6
- import { InvitationEncoder, type AuthenticatingInvitation, type CancellableInvitation } from '@dxos/client-protocol';
6
+ import { type AuthenticatingInvitation, type CancellableInvitation, InvitationEncoder } from '@dxos/client-protocol';
7
7
  import { invariant } from '@dxos/invariant';
8
8
  import { Invitation } from '@dxos/protocols/proto/dxos/client/services';
9
9
  import { type DeviceProfileDocument } from '@dxos/protocols/proto/dxos/halo/credentials';
@@ -4,9 +4,9 @@
4
4
 
5
5
  import { type Config } from '@dxos/config';
6
6
  import { Context } from '@dxos/context';
7
- import { createCredentialSignerWithChain, CredentialGenerator } from '@dxos/credentials';
7
+ import { CredentialGenerator, createCredentialSignerWithChain } from '@dxos/credentials';
8
8
  import { failUndefined } from '@dxos/debug';
9
- import { EchoHost, MetadataStore, SpaceManager, valueEncoding, MeshEchoReplicator } from '@dxos/echo-pipeline';
9
+ import { EchoHost, MeshEchoReplicator, MetadataStore, SpaceManager, valueEncoding } from '@dxos/echo-pipeline';
10
10
  import { FeedFactory, FeedStore } from '@dxos/feed-store';
11
11
  import { Keyring } from '@dxos/keyring';
12
12
  import { type LevelDB } from '@dxos/kv-store';
@@ -14,7 +14,7 @@ import { createTestLevel } from '@dxos/kv-store/testing';
14
14
  import { MemorySignalManager, MemorySignalManagerContext, type SignalManager } from '@dxos/messaging';
15
15
  import { MemoryTransportFactory, SwarmNetworkManager } from '@dxos/network-manager';
16
16
  import { Invitation } from '@dxos/protocols/proto/dxos/client/services';
17
- import { createStorage, StorageType, type Storage } from '@dxos/random-access-storage';
17
+ import { type Storage, StorageType, createStorage } from '@dxos/random-access-storage';
18
18
  import { BlobStore } from '@dxos/teleport-extension-object-sync';
19
19
 
20
20
  import { InvitationsHandler, InvitationsManager, SpaceInvitationProtocol } from '../invitations';