@dxos/client-services 0.4.10-main.c42bfdb → 0.4.10-main.ccba876

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 (37) hide show
  1. package/dist/lib/browser/{chunk-W7UANCHR.mjs → chunk-LGZBUJLB.mjs} +208 -144
  2. package/dist/lib/browser/chunk-LGZBUJLB.mjs.map +7 -0
  3. package/dist/lib/browser/index.mjs +3 -3
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/packlets/testing/index.mjs +8 -4
  6. package/dist/lib/browser/packlets/testing/index.mjs.map +3 -3
  7. package/dist/lib/node/{chunk-JSVLZGJM.cjs → chunk-HM374IDE.cjs} +224 -160
  8. package/dist/lib/node/chunk-HM374IDE.cjs.map +7 -0
  9. package/dist/lib/node/index.cjs +43 -43
  10. package/dist/lib/node/meta.json +1 -1
  11. package/dist/lib/node/packlets/testing/index.cjs +13 -9
  12. package/dist/lib/node/packlets/testing/index.cjs.map +3 -3
  13. package/dist/types/src/packlets/invitations/invitation-extension.d.ts +1 -0
  14. package/dist/types/src/packlets/invitations/invitation-extension.d.ts.map +1 -1
  15. package/dist/types/src/packlets/invitations/invitations-handler.d.ts +4 -2
  16. package/dist/types/src/packlets/invitations/invitations-handler.d.ts.map +1 -1
  17. package/dist/types/src/packlets/invitations/invitations-service.d.ts.map +1 -1
  18. package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
  19. package/dist/types/src/packlets/services/service-host.d.ts +3 -1
  20. package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
  21. package/dist/types/src/packlets/testing/test-builder.d.ts +4 -1
  22. package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
  23. package/dist/types/src/version.d.ts +1 -1
  24. package/package.json +34 -34
  25. package/src/packlets/invitations/invitation-extension.ts +28 -1
  26. package/src/packlets/invitations/invitations-handler.ts +73 -32
  27. package/src/packlets/invitations/invitations-service.ts +5 -5
  28. package/src/packlets/services/automerge-host.test.ts +9 -3
  29. package/src/packlets/services/service-context.test.ts +4 -1
  30. package/src/packlets/services/service-context.ts +2 -0
  31. package/src/packlets/services/service-host.ts +12 -1
  32. package/src/packlets/spaces/data-space-manager.test.ts +4 -4
  33. package/src/packlets/storage/level.ts +1 -1
  34. package/src/packlets/testing/test-builder.ts +20 -4
  35. package/src/version.ts +1 -1
  36. package/dist/lib/browser/chunk-W7UANCHR.mjs.map +0 -7
  37. package/dist/lib/node/chunk-JSVLZGJM.cjs.map +0 -7
@@ -6,7 +6,7 @@ import { Event, scheduleTask } from '@dxos/async';
6
6
  import { type AuthenticatingInvitation, type CancellableInvitation } from '@dxos/client-protocol';
7
7
  import { Stream } from '@dxos/codec-protobuf';
8
8
  import { Context } from '@dxos/context';
9
- import { type MetadataStore } from '@dxos/echo-pipeline';
9
+ import { hasInvitationExpired, type MetadataStore } from '@dxos/echo-pipeline';
10
10
  import { invariant } from '@dxos/invariant';
11
11
  import { log } from '@dxos/log';
12
12
  import {
@@ -18,7 +18,7 @@ import {
18
18
  } from '@dxos/protocols/proto/dxos/client/services';
19
19
 
20
20
  import { type InvitationProtocol } from './invitation-protocol';
21
- import { invitationExpired, type InvitationsHandler } from './invitations-handler';
21
+ import { type InvitationsHandler } from './invitations-handler';
22
22
 
23
23
  /**
24
24
  * Adapts invitation service observable to client/service stream.
@@ -91,7 +91,7 @@ export class InvitationsServiceImpl implements InvitationsService {
91
91
  }
92
92
 
93
93
  this._createInvitations.delete(invitation.get().invitationId);
94
- if (invitation.get().type !== Invitation.Type.MULTIUSE) {
94
+ if (!invitation.get().multiUse) {
95
95
  this._removedCreated.emit(invitation.get());
96
96
  }
97
97
  },
@@ -103,7 +103,7 @@ export class InvitationsServiceImpl implements InvitationsService {
103
103
  const persistentInvitations = this._metadataStore.getInvitations();
104
104
 
105
105
  // get saved persistent invitations, filter and remove from storage those that have expired.
106
- const freshInvitations = persistentInvitations.filter(async (invitation) => !invitationExpired(invitation));
106
+ const freshInvitations = persistentInvitations.filter(async (invitation) => !hasInvitationExpired(invitation));
107
107
 
108
108
  const cInvitations = freshInvitations.map((persistentInvitation) => {
109
109
  invariant(!this._createInvitations.get(persistentInvitation.invitationId), 'invitation already exists');
@@ -148,7 +148,7 @@ export class InvitationsServiceImpl implements InvitationsService {
148
148
  () => {
149
149
  close();
150
150
  this._acceptInvitations.delete(invitation.get().invitationId);
151
- if (invitation.get().type !== Invitation.Type.MULTIUSE) {
151
+ if (!invitation.get().multiUse) {
152
152
  this._removedAccepted.emit(invitation.get());
153
153
  }
154
154
  },
@@ -6,8 +6,8 @@ import { expect } from 'chai';
6
6
 
7
7
  import { asyncTimeout, sleep } from '@dxos/async';
8
8
  import { AutomergeHost, DataServiceImpl } from '@dxos/echo-pipeline';
9
+ import { createTestLevel } from '@dxos/echo-pipeline/testing';
9
10
  import { AutomergeContext } from '@dxos/echo-schema';
10
- import { StorageType, createStorage } from '@dxos/random-access-storage';
11
11
  import { afterTest, describe, test } from '@dxos/test';
12
12
 
13
13
  describe('AutomergeHost', () => {
@@ -19,10 +19,16 @@ describe('AutomergeHost', () => {
19
19
  // creates repo and document | replicates repo | finds document in repo
20
20
  //
21
21
 
22
- const storageDirectory = createStorage({ type: StorageType.RAM }).createDirectory();
22
+ const level = createTestLevel();
23
+ await level.open();
24
+ afterTest(() => level.close());
23
25
 
24
- const host = new AutomergeHost({ directory: storageDirectory });
26
+ const host = new AutomergeHost({
27
+ db: level.sublevel('automerge'),
28
+ });
29
+ await host.open();
25
30
  afterTest(() => host.close());
31
+
26
32
  const dataService = new DataServiceImpl(host);
27
33
  const client = new AutomergeContext(dataService);
28
34
  afterTest(() => client.close());
@@ -4,7 +4,7 @@
4
4
 
5
5
  import { MemorySignalManagerContext } from '@dxos/messaging';
6
6
  import { Invitation } from '@dxos/protocols/proto/dxos/client/services';
7
- import { describe, test } from '@dxos/test';
7
+ import { describe, openAndClose, test } from '@dxos/test';
8
8
 
9
9
  import { createServiceContext } from '../testing';
10
10
  import { performInvitation } from '../testing/invitation-utils';
@@ -27,12 +27,15 @@ describe('services/ServiceContext', () => {
27
27
  test('joined space is synchronized on device invitations', async () => {
28
28
  const networkContext = new MemorySignalManagerContext();
29
29
  const device1 = await createServiceContext({ signalContext: networkContext });
30
+ await openAndClose(device1.automergeHost);
30
31
  await device1.createIdentity();
31
32
 
32
33
  const device2 = await createServiceContext({ signalContext: networkContext });
34
+ await openAndClose(device2.automergeHost);
33
35
  await Promise.all(performInvitation({ host: device1, guest: device2, options: { kind: Invitation.Kind.DEVICE } }));
34
36
 
35
37
  const identity2 = await createServiceContext({ signalContext: networkContext });
38
+ await openAndClose(identity2.automergeHost);
36
39
  await identity2.createIdentity();
37
40
  const space1 = await identity2.dataSpaceManager!.createSpace();
38
41
  await Promise.all(
@@ -124,6 +124,7 @@ export class ServiceContext extends Resource {
124
124
 
125
125
  this.automergeHost = new AutomergeHost({
126
126
  directory: storage.createDirectory('automerge'),
127
+ db: level.sublevel('automerge'),
127
128
  metadata: this.indexMetadata,
128
129
  });
129
130
 
@@ -158,6 +159,7 @@ export class ServiceContext extends Resource {
158
159
  await this.signalManager.open();
159
160
  await this.networkManager.open();
160
161
 
162
+ await this.automergeHost.open();
161
163
  await this.metadataStore.load();
162
164
  await this.spaceManager.open();
163
165
  await this.identityManager.open(ctx);
@@ -8,7 +8,13 @@ import { Event, synchronized } from '@dxos/async';
8
8
  import { clientServiceBundle, defaultKey, type ClientServices, Properties } from '@dxos/client-protocol';
9
9
  import { type Config } from '@dxos/config';
10
10
  import { Context } from '@dxos/context';
11
- import { DataServiceImpl, type ObjectStructure, encodeReference, type SpaceDoc } from '@dxos/echo-pipeline';
11
+ import {
12
+ DataServiceImpl,
13
+ type ObjectStructure,
14
+ encodeReference,
15
+ type SpaceDoc,
16
+ type MyLevel,
17
+ } from '@dxos/echo-pipeline';
12
18
  import * as E from '@dxos/echo-schema';
13
19
  import { IndexServiceImpl } from '@dxos/indexing';
14
20
  import { invariant } from '@dxos/invariant';
@@ -50,6 +56,7 @@ export type ClientServicesHostParams = {
50
56
  signalManager?: SignalManager;
51
57
  connectionLog?: boolean;
52
58
  storage?: Storage;
59
+ level?: MyLevel;
53
60
  lockKey?: string;
54
61
  callbacks?: ClientServicesHostCallbacks;
55
62
  runtimeParams?: ServiceContextRuntimeParams;
@@ -101,12 +108,14 @@ export class ClientServicesHost {
101
108
  transportFactory,
102
109
  signalManager,
103
110
  storage,
111
+ level,
104
112
  // TODO(wittjosiah): Turn this on by default.
105
113
  lockKey,
106
114
  callbacks,
107
115
  runtimeParams,
108
116
  }: ClientServicesHostParams = {}) {
109
117
  this._storage = storage;
118
+ this._level = level;
110
119
  this._callbacks = callbacks;
111
120
  this._runtimeParams = runtimeParams;
112
121
 
@@ -239,6 +248,8 @@ export class ClientServicesHost {
239
248
  if (!this._level) {
240
249
  this._level = await createLevel(this._config.get('runtime.client.storage', {})!);
241
250
  }
251
+ await this._level.open();
252
+
242
253
  await this._resourceLock?.acquire();
243
254
 
244
255
  await this._loggingService.open();
@@ -20,7 +20,7 @@ describe('DataSpaceManager', () => {
20
20
 
21
21
  const peer = builder.createPeer();
22
22
  await peer.createIdentity();
23
- await openAndClose(peer.dataSpaceManager);
23
+ await openAndClose(peer.automergeHost, peer.dataSpaceManager);
24
24
 
25
25
  const space = await peer.dataSpaceManager.createSpace();
26
26
 
@@ -42,7 +42,7 @@ describe('DataSpaceManager', () => {
42
42
  const peer2 = builder.createPeer();
43
43
  await peer2.createIdentity();
44
44
 
45
- await openAndClose(peer1.dataSpaceManager, peer2.dataSpaceManager);
45
+ await openAndClose(peer1.automergeHost, peer1.dataSpaceManager, peer2.automergeHost, peer2.dataSpaceManager);
46
46
 
47
47
  const space1 = await peer1.dataSpaceManager.createSpace();
48
48
  await space1.inner.controlPipeline.state.waitUntilTimeframe(space1.inner.controlPipeline.state.endTimeframe);
@@ -111,7 +111,7 @@ describe('DataSpaceManager', () => {
111
111
  await peer2.createIdentity();
112
112
  await peer2.dataSpaceManager.open();
113
113
 
114
- await openAndClose(peer1.dataSpaceManager, peer2.dataSpaceManager);
114
+ await openAndClose(peer1.automergeHost, peer1.dataSpaceManager, peer2.automergeHost, peer2.dataSpaceManager);
115
115
 
116
116
  const space1 = await peer1.dataSpaceManager.createSpace();
117
117
  await space1.inner.controlPipeline.state.waitUntilTimeframe(space1.inner.controlPipeline.state.endTimeframe);
@@ -153,7 +153,7 @@ describe('DataSpaceManager', () => {
153
153
 
154
154
  const peer = builder.createPeer();
155
155
  await peer.createIdentity();
156
- await openAndClose(peer.dataSpaceManager);
156
+ await openAndClose(peer.automergeHost, peer.dataSpaceManager);
157
157
 
158
158
  const space = await peer.dataSpaceManager.createSpace();
159
159
  await space.inner.controlPipeline.state.waitUntilTimeframe(space.inner.controlPipeline.state.endTimeframe);
@@ -12,7 +12,7 @@ import { getRootPath, isPersistent } from './util';
12
12
 
13
13
  export const createLevel = async (config: Runtime.Client.Storage) => {
14
14
  const persistent = isPersistent(config);
15
- const storagePath = persistent ? getRootPath(config) : path.join('tmp', 'level', PublicKey.random().toHex());
15
+ const storagePath = persistent ? path.join(getRootPath(config), 'level') : `/tmp/dxos-${PublicKey.random().toHex()}`;
16
16
  const level = new Level<string, string>(storagePath);
17
17
  await level.open();
18
18
  return level;
@@ -6,14 +6,22 @@ import { type Config } from '@dxos/config';
6
6
  import { Context } from '@dxos/context';
7
7
  import { createCredentialSignerWithChain, CredentialGenerator } from '@dxos/credentials';
8
8
  import { failUndefined } from '@dxos/debug';
9
- import { AutomergeHost, MetadataStore, SnapshotStore, SpaceManager, valueEncoding } from '@dxos/echo-pipeline';
9
+ import {
10
+ AutomergeHost,
11
+ MetadataStore,
12
+ type MyLevel,
13
+ SnapshotStore,
14
+ SpaceManager,
15
+ valueEncoding,
16
+ } from '@dxos/echo-pipeline';
17
+ import { createTestLevel } from '@dxos/echo-pipeline/testing';
10
18
  import { FeedFactory, FeedStore } from '@dxos/feed-store';
11
- import { createTestLevel } from '@dxos/indexing/testing';
12
19
  import { Keyring } from '@dxos/keyring';
13
20
  import { MemorySignalManager, MemorySignalManagerContext } from '@dxos/messaging';
14
21
  import { MemoryTransportFactory, NetworkManager } from '@dxos/network-manager';
15
22
  import { createStorage, StorageType, type Storage } from '@dxos/random-access-storage';
16
23
  import { BlobStore } from '@dxos/teleport-extension-object-sync';
24
+ import { type MaybePromise } from '@dxos/util';
17
25
 
18
26
  import { ClientServicesHost, ServiceContext } from '../services';
19
27
  import { DataSpaceManager, type SigningContext } from '../spaces';
@@ -42,7 +50,8 @@ export const createServiceContext = async ({
42
50
  signalManager,
43
51
  transportFactory: MemoryTransportFactory,
44
52
  });
45
- const level = await createTestLevel();
53
+ const level = createTestLevel();
54
+ await level.open();
46
55
 
47
56
  return new ServiceContext(storage, level, networkManager, signalManager);
48
57
  };
@@ -85,6 +94,7 @@ export type TestPeerOpts = {
85
94
 
86
95
  export type TestPeerProps = {
87
96
  storage?: Storage;
97
+ level?: MaybePromise<MyLevel>;
88
98
  feedStore?: FeedStore<any>;
89
99
  metadataStore?: MetadataStore;
90
100
  keyring?: Keyring;
@@ -117,6 +127,10 @@ export class TestPeer {
117
127
  return (this._props.keyring ??= new Keyring(this.storage.createDirectory('keyring')));
118
128
  }
119
129
 
130
+ get level() {
131
+ return (this._props.level ??= createTestLevel());
132
+ }
133
+
120
134
  get feedStore() {
121
135
  return (this._props.feedStore ??= new FeedStore({
122
136
  factory: new FeedFactory({
@@ -163,7 +177,9 @@ export class TestPeer {
163
177
  }
164
178
 
165
179
  get automergeHost() {
166
- return (this._props.automergeHost ??= new AutomergeHost({ directory: this.storage.createDirectory('automerge') }));
180
+ return (this._props.automergeHost ??= new AutomergeHost({
181
+ db: Promise.resolve(this.level).then((level) => level.sublevel('automerge')),
182
+ }));
167
183
  }
168
184
 
169
185
  get dataSpaceManager() {
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const DXOS_VERSION = "0.4.10-main.c42bfdb";
1
+ export const DXOS_VERSION = "0.4.10-main.ccba876";