@dxos/client-services 0.6.12-staging.e11e696 → 0.6.12
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.
- package/dist/lib/browser/{chunk-67FEJJ6J.mjs → chunk-TOAILL4T.mjs} +5127 -5565
- package/dist/lib/browser/chunk-TOAILL4T.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +3 -3
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +6 -5
- package/dist/lib/browser/testing/index.mjs.map +2 -2
- package/dist/lib/node/{chunk-2KIDYJ7O.cjs → chunk-H6C4XY6B.cjs} +4908 -5346
- package/dist/lib/node/chunk-H6C4XY6B.cjs.map +7 -0
- package/dist/lib/node/index.cjs +46 -46
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +12 -11
- package/dist/lib/node/testing/index.cjs.map +2 -2
- package/dist/types/src/packlets/diagnostics/diagnostics-broadcast.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/authenticator.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/authenticator.test.d.ts +2 -0
- package/dist/types/src/packlets/identity/authenticator.test.d.ts.map +1 -0
- package/dist/types/src/packlets/identity/contacts-service.d.ts +1 -1
- package/dist/types/src/packlets/identity/contacts-service.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity-manager.d.ts +7 -19
- package/dist/types/src/packlets/identity/identity-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/identity/identity.d.ts +1 -8
- package/dist/types/src/packlets/identity/identity.d.ts.map +1 -1
- package/dist/types/src/packlets/invitations/invitation-host-extension.d.ts.map +1 -1
- package/dist/types/src/packlets/services/automerge-host.test.d.ts +2 -0
- package/dist/types/src/packlets/services/automerge-host.test.d.ts.map +1 -0
- package/dist/types/src/packlets/services/service-context.d.ts +6 -7
- package/dist/types/src/packlets/services/service-context.d.ts.map +1 -1
- package/dist/types/src/packlets/services/service-host.d.ts +0 -1
- package/dist/types/src/packlets/services/service-host.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts +3 -4
- package/dist/types/src/packlets/spaces/data-space-manager.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/data-space.d.ts +3 -3
- package/dist/types/src/packlets/spaces/data-space.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts +0 -3
- package/dist/types/src/packlets/spaces/edge-feed-replicator.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/epoch-migrations.d.ts +1 -1
- package/dist/types/src/packlets/spaces/epoch-migrations.d.ts.map +1 -1
- package/dist/types/src/packlets/spaces/notarization-plugin.d.ts +6 -31
- package/dist/types/src/packlets/spaces/notarization-plugin.d.ts.map +1 -1
- package/dist/types/src/packlets/storage/storage.d.ts.map +1 -1
- package/dist/types/src/packlets/testing/test-builder.d.ts +2 -1
- package/dist/types/src/packlets/testing/test-builder.d.ts.map +1 -1
- package/dist/types/src/packlets/worker/worker-runtime.d.ts.map +1 -1
- package/dist/types/src/version.d.ts +1 -1
- package/dist/types/src/version.d.ts.map +1 -1
- package/package.json +39 -43
- package/src/packlets/devices/devices-service.test.ts +5 -4
- package/src/packlets/diagnostics/diagnostics-broadcast.ts +0 -1
- package/src/packlets/identity/{authenticator.node.test.ts → authenticator.test.ts} +3 -2
- package/src/packlets/identity/authenticator.ts +2 -5
- package/src/packlets/identity/contacts-service.ts +1 -1
- package/src/packlets/identity/identity-manager.test.ts +6 -5
- package/src/packlets/identity/identity-manager.ts +19 -35
- package/src/packlets/identity/identity-service.test.ts +8 -4
- package/src/packlets/identity/identity.test.ts +239 -128
- package/src/packlets/identity/identity.ts +8 -42
- package/src/packlets/invitations/device-invitation-protocol.test.ts +4 -7
- package/src/packlets/invitations/invitation-host-extension.ts +3 -0
- package/src/packlets/invitations/invitations-handler.test.ts +7 -14
- package/src/packlets/invitations/invitations-handler.ts +1 -1
- package/src/packlets/invitations/space-invitation-protocol.test.ts +3 -4
- package/src/packlets/logging/logging.test.ts +2 -1
- package/src/packlets/network/network-service.test.ts +3 -2
- package/src/packlets/services/automerge-host.test.ts +60 -0
- package/src/packlets/services/service-context.test.ts +1 -3
- package/src/packlets/services/service-context.ts +28 -64
- package/src/packlets/services/service-host.test.ts +12 -8
- package/src/packlets/services/service-host.ts +6 -8
- package/src/packlets/services/service-registry.test.ts +2 -1
- package/src/packlets/spaces/data-space-manager.test.ts +2 -2
- package/src/packlets/spaces/data-space-manager.ts +2 -9
- package/src/packlets/spaces/data-space.ts +6 -30
- package/src/packlets/spaces/edge-feed-replicator.ts +22 -80
- package/src/packlets/spaces/epoch-migrations.ts +2 -2
- package/src/packlets/spaces/notarization-plugin.test.ts +7 -10
- package/src/packlets/spaces/notarization-plugin.ts +29 -169
- package/src/packlets/spaces/spaces-service.test.ts +9 -5
- package/src/packlets/storage/storage.ts +1 -0
- package/src/packlets/system/system-service.test.ts +2 -1
- package/src/packlets/testing/test-builder.ts +3 -2
- package/src/packlets/worker/worker-runtime.ts +2 -2
- package/src/version.ts +5 -1
- package/dist/lib/browser/chunk-67FEJJ6J.mjs.map +0 -7
- package/dist/lib/node/chunk-2KIDYJ7O.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-36ZRRDQI.mjs +0 -8154
- package/dist/lib/node-esm/chunk-36ZRRDQI.mjs.map +0 -7
- package/dist/lib/node-esm/index.mjs +0 -416
- package/dist/lib/node-esm/index.mjs.map +0 -7
- package/dist/lib/node-esm/meta.json +0 -1
- package/dist/lib/node-esm/testing/index.mjs +0 -418
- package/dist/lib/node-esm/testing/index.mjs.map +0 -7
- package/dist/types/src/packlets/identity/authenticator.node.test.d.ts +0 -2
- package/dist/types/src/packlets/identity/authenticator.node.test.d.ts.map +0 -1
- package/dist/types/src/packlets/spaces/edge-feed-replicator.test.d.ts +0 -2
- package/dist/types/src/packlets/spaces/edge-feed-replicator.test.d.ts.map +0 -1
- package/dist/types/src/testing/setup.d.ts +0 -3
- package/dist/types/src/testing/setup.d.ts.map +0 -1
- package/src/packlets/spaces/edge-feed-replicator.test.ts +0 -251
- package/src/testing/setup.ts +0 -11
|
@@ -2,21 +2,20 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { expect } from 'chai';
|
|
6
6
|
|
|
7
7
|
import { asyncChain, Trigger } from '@dxos/async';
|
|
8
8
|
import { raise } from '@dxos/debug';
|
|
9
9
|
import { AlreadyJoinedError } from '@dxos/protocols';
|
|
10
10
|
import { Invitation } from '@dxos/protocols/proto/dxos/client/services';
|
|
11
|
+
import { afterTest, describe, test } from '@dxos/test';
|
|
11
12
|
|
|
12
13
|
import { type ServiceContext } from '../services';
|
|
13
14
|
import { createIdentity, createPeers } from '../testing';
|
|
14
15
|
import { acceptInvitation, createInvitation, performInvitation } from '../testing/invitation-utils';
|
|
15
16
|
|
|
16
17
|
const closeAfterTest = async (peer: ServiceContext) => {
|
|
17
|
-
|
|
18
|
-
await peer.close();
|
|
19
|
-
});
|
|
18
|
+
afterTest(() => peer.close());
|
|
20
19
|
return peer;
|
|
21
20
|
};
|
|
22
21
|
|
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { expect } from 'chai';
|
|
6
6
|
|
|
7
7
|
import { Trigger } from '@dxos/async';
|
|
8
8
|
import { log, LogLevel } from '@dxos/log';
|
|
9
9
|
import { type LogEntry } from '@dxos/protocols/proto/dxos/client/services';
|
|
10
|
+
import { beforeEach, describe, test } from '@dxos/test';
|
|
10
11
|
|
|
11
12
|
import { LoggingServiceImpl } from './logging-service';
|
|
12
13
|
|
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { expect } from 'chai';
|
|
6
6
|
|
|
7
7
|
import { Trigger } from '@dxos/async';
|
|
8
8
|
import { Context } from '@dxos/context';
|
|
9
9
|
import { type NetworkService, ConnectionState } from '@dxos/protocols/proto/dxos/client/services';
|
|
10
|
+
import { afterEach, afterTest, beforeEach, describe, test } from '@dxos/test';
|
|
10
11
|
|
|
11
12
|
import { NetworkServiceImpl } from './network-service';
|
|
12
13
|
import { type ServiceContext } from '../services';
|
|
@@ -40,7 +41,7 @@ describe('NetworkService', () => {
|
|
|
40
41
|
query.subscribe(({ swarm }) => {
|
|
41
42
|
result.wake(swarm);
|
|
42
43
|
});
|
|
43
|
-
|
|
44
|
+
afterTest(() => query.close());
|
|
44
45
|
expect(await result.wait()).to.equal(ConnectionState.ONLINE);
|
|
45
46
|
|
|
46
47
|
result = new Trigger<ConnectionState | undefined>();
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2023 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { expect } from 'chai';
|
|
6
|
+
|
|
7
|
+
import { asyncTimeout } from '@dxos/async';
|
|
8
|
+
import { AutomergeContext } from '@dxos/echo-db';
|
|
9
|
+
import { AutomergeHost, DataServiceImpl } from '@dxos/echo-pipeline';
|
|
10
|
+
import { IndexMetadataStore } from '@dxos/indexing';
|
|
11
|
+
import { createTestLevel } from '@dxos/kv-store/testing';
|
|
12
|
+
import { afterTest, describe, openAndClose, test } from '@dxos/test';
|
|
13
|
+
|
|
14
|
+
describe('AutomergeHost', () => {
|
|
15
|
+
test('automerge context is being synced with host', async () => {
|
|
16
|
+
//
|
|
17
|
+
// Setup:
|
|
18
|
+
// client-services | <-------------> | client
|
|
19
|
+
// AutomergeHost | DataServiceImpl | AutomergeContext
|
|
20
|
+
// creates repo and document | replicates repo | finds document in repo
|
|
21
|
+
//
|
|
22
|
+
|
|
23
|
+
const level = createTestLevel();
|
|
24
|
+
await level.open();
|
|
25
|
+
afterTest(() => level.close());
|
|
26
|
+
|
|
27
|
+
const host = new AutomergeHost({
|
|
28
|
+
db: level,
|
|
29
|
+
indexMetadataStore: new IndexMetadataStore({ db: level.sublevel('index-metadata') }),
|
|
30
|
+
});
|
|
31
|
+
await host.open();
|
|
32
|
+
afterTest(() => host.close());
|
|
33
|
+
|
|
34
|
+
const dataService = new DataServiceImpl({ automergeHost: host, updateIndexes: async () => {} });
|
|
35
|
+
const client = new AutomergeContext(dataService);
|
|
36
|
+
await openAndClose(client);
|
|
37
|
+
|
|
38
|
+
// Create document in repo.
|
|
39
|
+
const handle = host.repo.create();
|
|
40
|
+
const text = 'Hello World!';
|
|
41
|
+
handle.change((doc: any) => {
|
|
42
|
+
doc.text = text;
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
// Find document in repo.
|
|
46
|
+
const doc = client.repo.find<{ text: string }>(handle.url);
|
|
47
|
+
await asyncTimeout(doc.whenReady(), 1_000);
|
|
48
|
+
expect(doc.docSync().text).to.equal(text);
|
|
49
|
+
|
|
50
|
+
// Changes from client are replicated to host.
|
|
51
|
+
const newText = 'Goodbye World!!!';
|
|
52
|
+
doc.change((doc: any) => {
|
|
53
|
+
doc.text = newText;
|
|
54
|
+
});
|
|
55
|
+
await client.flush({ documentIds: [doc.documentId] });
|
|
56
|
+
|
|
57
|
+
await asyncTimeout(handle.whenReady(), 1_000);
|
|
58
|
+
expect(handle.docSync().text).to.equal(newText);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -2,11 +2,9 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { describe, test } from 'vitest';
|
|
6
|
-
|
|
7
5
|
import { MemorySignalManagerContext, MemorySignalManager } from '@dxos/messaging';
|
|
8
6
|
import { Invitation } from '@dxos/protocols/proto/dxos/client/services';
|
|
9
|
-
import { openAndClose } from '@dxos/test
|
|
7
|
+
import { describe, openAndClose, test } from '@dxos/test';
|
|
10
8
|
|
|
11
9
|
import { createServiceContext, performInvitation } from '../testing';
|
|
12
10
|
|
|
@@ -2,20 +2,13 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { Trigger } from '@dxos/async';
|
|
6
6
|
import { Context, Resource } from '@dxos/context';
|
|
7
7
|
import { getCredentialAssertion, type CredentialProcessor } from '@dxos/credentials';
|
|
8
|
-
import { failUndefined
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
MeshEchoReplicator,
|
|
13
|
-
MetadataStore,
|
|
14
|
-
SpaceManager,
|
|
15
|
-
valueEncoding,
|
|
16
|
-
} from '@dxos/echo-pipeline';
|
|
17
|
-
import { createChainEdgeIdentity, createEphemeralEdgeIdentity } from '@dxos/edge-client';
|
|
18
|
-
import type { EdgeHttpClient, EdgeConnection } from '@dxos/edge-client';
|
|
8
|
+
import { failUndefined } from '@dxos/debug';
|
|
9
|
+
import { EchoEdgeReplicator, EchoHost } from '@dxos/echo-db';
|
|
10
|
+
import { MeshEchoReplicator, MetadataStore, SpaceManager, valueEncoding } from '@dxos/echo-pipeline';
|
|
11
|
+
import type { EdgeConnection } from '@dxos/edge-client';
|
|
19
12
|
import { FeedFactory, FeedStore } from '@dxos/feed-store';
|
|
20
13
|
import { invariant } from '@dxos/invariant';
|
|
21
14
|
import { Keyring } from '@dxos/keyring';
|
|
@@ -38,7 +31,7 @@ import { safeInstanceof } from '@dxos/util';
|
|
|
38
31
|
import {
|
|
39
32
|
IdentityManager,
|
|
40
33
|
type CreateIdentityOptions,
|
|
41
|
-
type
|
|
34
|
+
type IdentityManagerRuntimeParams,
|
|
42
35
|
type JoinIdentityParams,
|
|
43
36
|
} from '../identity';
|
|
44
37
|
import {
|
|
@@ -50,10 +43,7 @@ import {
|
|
|
50
43
|
} from '../invitations';
|
|
51
44
|
import { DataSpaceManager, type DataSpaceManagerRuntimeParams, type SigningContext } from '../spaces';
|
|
52
45
|
|
|
53
|
-
export type ServiceContextRuntimeParams =
|
|
54
|
-
IdentityManagerParams,
|
|
55
|
-
'devicePresenceOfflineTimeout' | 'devicePresenceAnnounceInterval'
|
|
56
|
-
> &
|
|
46
|
+
export type ServiceContextRuntimeParams = IdentityManagerRuntimeParams &
|
|
57
47
|
DataSpaceManagerRuntimeParams & {
|
|
58
48
|
invitationConnectionDefaultParams?: Partial<TeleportParams>;
|
|
59
49
|
disableP2pReplication?: boolean;
|
|
@@ -66,8 +56,6 @@ export type ServiceContextRuntimeParams = Pick<
|
|
|
66
56
|
@safeInstanceof('dxos.client-services.ServiceContext')
|
|
67
57
|
@Trace.resource()
|
|
68
58
|
export class ServiceContext extends Resource {
|
|
69
|
-
private readonly _edgeIdentityUpdateMutex = new Mutex();
|
|
70
|
-
|
|
71
59
|
public readonly initialized = new Trigger();
|
|
72
60
|
public readonly metadataStore: MetadataStore;
|
|
73
61
|
public readonly blobStore: BlobStore;
|
|
@@ -99,7 +87,6 @@ export class ServiceContext extends Resource {
|
|
|
99
87
|
public readonly networkManager: SwarmNetworkManager,
|
|
100
88
|
public readonly signalManager: SignalManager,
|
|
101
89
|
private readonly _edgeConnection: EdgeConnection | undefined,
|
|
102
|
-
private readonly _edgeHttpClient: EdgeHttpClient | undefined,
|
|
103
90
|
public readonly _runtimeParams?: ServiceContextRuntimeParams,
|
|
104
91
|
private readonly _edgeFeatures?: Runtime.Client.EdgeFeatures,
|
|
105
92
|
) {
|
|
@@ -129,50 +116,32 @@ export class ServiceContext extends Resource {
|
|
|
129
116
|
disableP2pReplication: this._runtimeParams?.disableP2pReplication,
|
|
130
117
|
});
|
|
131
118
|
|
|
132
|
-
this.identityManager = new IdentityManager(
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
edgeConnection: this._edgeConnection,
|
|
140
|
-
edgeFeatures: this._edgeFeatures,
|
|
141
|
-
callbacks: {
|
|
119
|
+
this.identityManager = new IdentityManager(
|
|
120
|
+
this.metadataStore,
|
|
121
|
+
this.keyring,
|
|
122
|
+
this.feedStore,
|
|
123
|
+
this.spaceManager,
|
|
124
|
+
this._runtimeParams as IdentityManagerRuntimeParams,
|
|
125
|
+
{
|
|
142
126
|
onIdentityConstruction: (identity) => {
|
|
143
127
|
if (this._edgeConnection) {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
invariant(identity.deviceCredentialChain);
|
|
158
|
-
this._edgeConnection!.setIdentity(
|
|
159
|
-
await createChainEdgeIdentity(
|
|
160
|
-
identity.signer,
|
|
161
|
-
identity.identityKey,
|
|
162
|
-
identity.deviceKey,
|
|
163
|
-
identity.deviceCredentialChain,
|
|
164
|
-
[], // TODO(dmaretskyi): Service access credentials.
|
|
165
|
-
),
|
|
166
|
-
);
|
|
167
|
-
this.networkManager.setPeerInfo({
|
|
168
|
-
identityKey: identity.identityKey.toHex(),
|
|
169
|
-
peerKey: identity.deviceKey.toHex(),
|
|
170
|
-
});
|
|
128
|
+
log.info('Setting identity on edge connection', {
|
|
129
|
+
identity: identity.identityKey.toHex(),
|
|
130
|
+
oldIdentity: this._edgeConnection.identityKey,
|
|
131
|
+
swarms: this.networkManager.topics,
|
|
132
|
+
});
|
|
133
|
+
this._edgeConnection.setIdentity({
|
|
134
|
+
peerKey: identity.deviceKey.toHex(),
|
|
135
|
+
identityKey: identity.identityKey.toHex(),
|
|
136
|
+
});
|
|
137
|
+
this.networkManager.setPeerInfo({
|
|
138
|
+
identityKey: identity.identityKey.toHex(),
|
|
139
|
+
peerKey: identity.deviceKey.toHex(),
|
|
171
140
|
});
|
|
172
141
|
}
|
|
173
142
|
},
|
|
174
143
|
},
|
|
175
|
-
|
|
144
|
+
);
|
|
176
145
|
|
|
177
146
|
this.echoHost = new EchoHost({ kv: this.level });
|
|
178
147
|
|
|
@@ -216,11 +185,7 @@ export class ServiceContext extends Resource {
|
|
|
216
185
|
|
|
217
186
|
log('opening...');
|
|
218
187
|
log.trace('dxos.sdk.service-context.open', trace.begin({ id: this._instanceId }));
|
|
219
|
-
|
|
220
|
-
// TODO(dmaretskyi): Use device key.
|
|
221
|
-
this._edgeConnection.setIdentity(await createEphemeralEdgeIdentity());
|
|
222
|
-
await this._edgeConnection.open();
|
|
223
|
-
}
|
|
188
|
+
await this._edgeConnection?.open();
|
|
224
189
|
await this.signalManager.open();
|
|
225
190
|
await this.networkManager.open();
|
|
226
191
|
|
|
@@ -327,7 +292,6 @@ export class ServiceContext extends Resource {
|
|
|
327
292
|
echoHost: this.echoHost,
|
|
328
293
|
invitationsManager: this.invitationsManager,
|
|
329
294
|
edgeConnection: this._edgeConnection,
|
|
330
|
-
edgeHttpClient: this._edgeHttpClient,
|
|
331
295
|
echoEdgeReplicator: this._echoEdgeReplicator,
|
|
332
296
|
meshReplicator: this._meshReplicator,
|
|
333
297
|
runtimeParams: this._runtimeParams as DataSpaceManagerRuntimeParams,
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import chai, { expect } from 'chai';
|
|
6
|
+
import chaiAsPromised from 'chai-as-promised';
|
|
5
7
|
import { rmSync } from 'node:fs';
|
|
6
|
-
import { afterEach, onTestFinished, describe, expect, test } from 'vitest';
|
|
7
8
|
|
|
8
9
|
import { asyncTimeout, latch, Trigger } from '@dxos/async';
|
|
9
10
|
import { Config } from '@dxos/config';
|
|
@@ -13,10 +14,13 @@ import { type PublicKey } from '@dxos/keys';
|
|
|
13
14
|
import { MemorySignalManagerContext } from '@dxos/messaging';
|
|
14
15
|
import { type Identity } from '@dxos/protocols/proto/dxos/client/services';
|
|
15
16
|
import { type Credential } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
17
|
+
import { afterTest, describe, test } from '@dxos/test';
|
|
16
18
|
import { isNode } from '@dxos/util';
|
|
17
19
|
|
|
18
20
|
import { createMockCredential, createServiceHost } from '../testing';
|
|
19
21
|
|
|
22
|
+
chai.use(chaiAsPromised);
|
|
23
|
+
|
|
20
24
|
describe('ClientServicesHost', () => {
|
|
21
25
|
const dataRoot = '/tmp/dxos/client-services/service-host/storage';
|
|
22
26
|
|
|
@@ -34,7 +38,7 @@ describe('ClientServicesHost', () => {
|
|
|
34
38
|
test('queryCredentials', async () => {
|
|
35
39
|
const host = createServiceHost(new Config(), new MemorySignalManagerContext());
|
|
36
40
|
await host.open(new Context());
|
|
37
|
-
|
|
41
|
+
afterTest(() => host.close());
|
|
38
42
|
|
|
39
43
|
await host.services.IdentityService!.createIdentity({});
|
|
40
44
|
const { spaceKey } = await host.services.SpacesService!.createSpace();
|
|
@@ -45,7 +49,7 @@ describe('ClientServicesHost', () => {
|
|
|
45
49
|
tick();
|
|
46
50
|
// console.log(credential);
|
|
47
51
|
});
|
|
48
|
-
|
|
52
|
+
afterTest(() => stream.close());
|
|
49
53
|
|
|
50
54
|
await done();
|
|
51
55
|
});
|
|
@@ -53,7 +57,7 @@ describe('ClientServicesHost', () => {
|
|
|
53
57
|
test('write and query credentials', async () => {
|
|
54
58
|
const host = createServiceHost(new Config(), new MemorySignalManagerContext());
|
|
55
59
|
await host.open(new Context());
|
|
56
|
-
|
|
60
|
+
afterTest(() => host.close());
|
|
57
61
|
|
|
58
62
|
await host.services.IdentityService!.createIdentity({});
|
|
59
63
|
|
|
@@ -82,7 +86,7 @@ describe('ClientServicesHost', () => {
|
|
|
82
86
|
queriedCredential.wake(credential);
|
|
83
87
|
}
|
|
84
88
|
});
|
|
85
|
-
|
|
89
|
+
afterTest(() => credentials.close());
|
|
86
90
|
|
|
87
91
|
await queriedCredential.wait();
|
|
88
92
|
});
|
|
@@ -90,7 +94,7 @@ describe('ClientServicesHost', () => {
|
|
|
90
94
|
test('sign presentation', async () => {
|
|
91
95
|
const host = createServiceHost(new Config(), new MemorySignalManagerContext());
|
|
92
96
|
await host.open(new Context());
|
|
93
|
-
|
|
97
|
+
afterTest(() => host.close());
|
|
94
98
|
|
|
95
99
|
await host.services.IdentityService!.createIdentity({});
|
|
96
100
|
|
|
@@ -143,9 +147,9 @@ describe('ClientServicesHost', () => {
|
|
|
143
147
|
trigger.wake(identity.identity);
|
|
144
148
|
}
|
|
145
149
|
});
|
|
146
|
-
await expect(asyncTimeout(trigger.wait(), 200)).
|
|
150
|
+
await expect(asyncTimeout(trigger.wait(), 200)).to.be.rejectedWith();
|
|
147
151
|
await stream?.close();
|
|
148
152
|
await host.close();
|
|
149
153
|
}
|
|
150
|
-
});
|
|
154
|
+
}).onlyEnvironments('nodejs', 'chromium', 'firefox');
|
|
151
155
|
});
|
|
@@ -6,7 +6,7 @@ import { Event, synchronized } from '@dxos/async';
|
|
|
6
6
|
import { clientServiceBundle, type ClientServices } from '@dxos/client-protocol';
|
|
7
7
|
import { type Config } from '@dxos/config';
|
|
8
8
|
import { Context } from '@dxos/context';
|
|
9
|
-
import { EdgeClient,
|
|
9
|
+
import { EdgeClient, type EdgeConnection } from '@dxos/edge-client';
|
|
10
10
|
import { invariant } from '@dxos/invariant';
|
|
11
11
|
import { PublicKey } from '@dxos/keys';
|
|
12
12
|
import { type LevelDB } from '@dxos/kv-store';
|
|
@@ -15,7 +15,7 @@ import { EdgeSignalManager, WebsocketSignalManager, type SignalManager } from '@
|
|
|
15
15
|
import {
|
|
16
16
|
SwarmNetworkManager,
|
|
17
17
|
createIceProvider,
|
|
18
|
-
|
|
18
|
+
createSimplePeerTransportFactory,
|
|
19
19
|
type TransportFactory,
|
|
20
20
|
} from '@dxos/network-manager';
|
|
21
21
|
import { trace } from '@dxos/protocols';
|
|
@@ -29,9 +29,9 @@ import { ServiceRegistry } from './service-registry';
|
|
|
29
29
|
import { DevicesServiceImpl } from '../devices';
|
|
30
30
|
import { DevtoolsHostEvents, DevtoolsServiceImpl } from '../devtools';
|
|
31
31
|
import {
|
|
32
|
+
type CollectDiagnosticsBroadcastHandler,
|
|
32
33
|
createCollectDiagnosticsBroadcastHandler,
|
|
33
34
|
createDiagnostics,
|
|
34
|
-
type CollectDiagnosticsBroadcastHandler,
|
|
35
35
|
} from '../diagnostics';
|
|
36
36
|
import { IdentityServiceImpl, type CreateIdentityOptions } from '../identity';
|
|
37
37
|
import { ContactsServiceImpl } from '../identity/contacts-service';
|
|
@@ -89,7 +89,6 @@ export class ClientServicesHost {
|
|
|
89
89
|
private _callbacks?: ClientServicesHostCallbacks;
|
|
90
90
|
private _devtoolsProxy?: WebsocketRpcClient<{}, ClientServices>;
|
|
91
91
|
private _edgeConnection?: EdgeConnection = undefined;
|
|
92
|
-
private _edgeHttpClient?: EdgeHttpClient = undefined;
|
|
93
92
|
|
|
94
93
|
private _serviceContext!: ServiceContext;
|
|
95
94
|
private readonly _runtimeParams: ServiceContextRuntimeParams;
|
|
@@ -213,13 +212,13 @@ export class ClientServicesHost {
|
|
|
213
212
|
|
|
214
213
|
const edgeEndpoint = config?.get('runtime.services.edge.url');
|
|
215
214
|
if (edgeEndpoint) {
|
|
216
|
-
|
|
217
|
-
this.
|
|
215
|
+
const randomKey = PublicKey.random().toHex();
|
|
216
|
+
this._edgeConnection = new EdgeClient(randomKey, randomKey, { socketEndpoint: edgeEndpoint });
|
|
218
217
|
}
|
|
219
218
|
|
|
220
219
|
const {
|
|
221
220
|
connectionLog = true,
|
|
222
|
-
transportFactory =
|
|
221
|
+
transportFactory = createSimplePeerTransportFactory(
|
|
223
222
|
{ iceServers: this._config?.get('runtime.services.ice') },
|
|
224
223
|
this._config?.get('runtime.services.iceProviders') &&
|
|
225
224
|
createIceProvider(this._config!.get('runtime.services.iceProviders')!),
|
|
@@ -279,7 +278,6 @@ export class ClientServicesHost {
|
|
|
279
278
|
this._networkManager,
|
|
280
279
|
this._signalManager,
|
|
281
280
|
this._edgeConnection,
|
|
282
|
-
this._edgeHttpClient,
|
|
283
281
|
this._runtimeParams,
|
|
284
282
|
this._config.get('runtime.client.edgeFeatures'),
|
|
285
283
|
);
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { expect } from 'chai';
|
|
6
6
|
|
|
7
7
|
import { Event } from '@dxos/async';
|
|
8
8
|
import { type ClientServices } from '@dxos/client-protocol';
|
|
@@ -12,6 +12,7 @@ import { log } from '@dxos/log';
|
|
|
12
12
|
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
|
+
import { describe, test } from '@dxos/test';
|
|
15
16
|
|
|
16
17
|
import { ServiceRegistry } from './service-registry';
|
|
17
18
|
import { SystemServiceImpl } from '../system';
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { expect } from 'chai';
|
|
6
6
|
|
|
7
7
|
import { asyncTimeout, latch } from '@dxos/async';
|
|
8
8
|
import { createAdmissionCredentials } from '@dxos/credentials';
|
|
@@ -10,7 +10,7 @@ import { AuthStatus } from '@dxos/echo-pipeline';
|
|
|
10
10
|
import { writeMessages } from '@dxos/feed-store';
|
|
11
11
|
import { log } from '@dxos/log';
|
|
12
12
|
import { SpaceState } from '@dxos/protocols/proto/dxos/client/services';
|
|
13
|
-
import { openAndClose } from '@dxos/test
|
|
13
|
+
import { describe, openAndClose, test } from '@dxos/test';
|
|
14
14
|
|
|
15
15
|
import { TestBuilder, type TestPeer } from '../testing';
|
|
16
16
|
|
|
@@ -14,11 +14,8 @@ import {
|
|
|
14
14
|
type DelegateInvitationCredential,
|
|
15
15
|
type MemberInfo,
|
|
16
16
|
} from '@dxos/credentials';
|
|
17
|
+
import { convertLegacyReferences, findInlineObjectOfType, type EchoEdgeReplicator, type EchoHost } from '@dxos/echo-db';
|
|
17
18
|
import {
|
|
18
|
-
convertLegacyReferences,
|
|
19
|
-
findInlineObjectOfType,
|
|
20
|
-
type EchoEdgeReplicator,
|
|
21
|
-
type EchoHost,
|
|
22
19
|
AuthStatus,
|
|
23
20
|
CredentialServerExtension,
|
|
24
21
|
type MeshEchoReplicator,
|
|
@@ -36,7 +33,7 @@ import {
|
|
|
36
33
|
type SpaceDoc,
|
|
37
34
|
} from '@dxos/echo-protocol';
|
|
38
35
|
import { TYPE_PROPERTIES, generateEchoId, getTypeReference } from '@dxos/echo-schema';
|
|
39
|
-
import type { EdgeConnection
|
|
36
|
+
import type { EdgeConnection } from '@dxos/edge-client';
|
|
40
37
|
import { writeMessages, type FeedStore } from '@dxos/feed-store';
|
|
41
38
|
import { invariant } from '@dxos/invariant';
|
|
42
39
|
import { type Keyring } from '@dxos/keyring';
|
|
@@ -110,7 +107,6 @@ export type DataSpaceManagerParams = {
|
|
|
110
107
|
echoHost: EchoHost;
|
|
111
108
|
invitationsManager: InvitationsManager;
|
|
112
109
|
edgeConnection?: EdgeConnection;
|
|
113
|
-
edgeHttpClient?: EdgeHttpClient;
|
|
114
110
|
meshReplicator?: MeshEchoReplicator;
|
|
115
111
|
echoEdgeReplicator?: EchoEdgeReplicator;
|
|
116
112
|
runtimeParams?: DataSpaceManagerRuntimeParams;
|
|
@@ -139,7 +135,6 @@ export class DataSpaceManager extends Resource {
|
|
|
139
135
|
private readonly _echoHost: EchoHost;
|
|
140
136
|
private readonly _invitationsManager: InvitationsManager;
|
|
141
137
|
private readonly _edgeConnection?: EdgeConnection = undefined;
|
|
142
|
-
private readonly _edgeHttpClient?: EdgeHttpClient = undefined;
|
|
143
138
|
private readonly _edgeFeatures?: Runtime.Client.EdgeFeatures = undefined;
|
|
144
139
|
private readonly _meshReplicator?: MeshEchoReplicator = undefined;
|
|
145
140
|
private readonly _echoEdgeReplicator?: EchoEdgeReplicator = undefined;
|
|
@@ -159,7 +154,6 @@ export class DataSpaceManager extends Resource {
|
|
|
159
154
|
this._edgeConnection = params.edgeConnection;
|
|
160
155
|
this._edgeFeatures = params.edgeFeatures;
|
|
161
156
|
this._echoEdgeReplicator = params.echoEdgeReplicator;
|
|
162
|
-
this._edgeHttpClient = params.edgeHttpClient;
|
|
163
157
|
this._runtimeParams = params.runtimeParams;
|
|
164
158
|
|
|
165
159
|
trace.diagnostic({
|
|
@@ -485,7 +479,6 @@ export class DataSpaceManager extends Resource {
|
|
|
485
479
|
},
|
|
486
480
|
cache: metadata.cache,
|
|
487
481
|
edgeConnection: this._edgeConnection,
|
|
488
|
-
edgeHttpClient: this._edgeHttpClient,
|
|
489
482
|
edgeFeatures: this._edgeFeatures,
|
|
490
483
|
});
|
|
491
484
|
dataSpace.postOpen.append(async () => {
|
|
@@ -7,15 +7,10 @@ import { AUTH_TIMEOUT } from '@dxos/client-protocol';
|
|
|
7
7
|
import { Context, ContextDisposedError, cancelWithContext } from '@dxos/context';
|
|
8
8
|
import type { SpecificCredential } from '@dxos/credentials';
|
|
9
9
|
import { timed, warnAfterTimeout } from '@dxos/debug';
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
type DatabaseRoot,
|
|
13
|
-
createMappedFeedWriter,
|
|
14
|
-
type MetadataStore,
|
|
15
|
-
type Space,
|
|
16
|
-
} from '@dxos/echo-pipeline';
|
|
10
|
+
import { type EchoHost, type DatabaseRoot } from '@dxos/echo-db';
|
|
11
|
+
import { createMappedFeedWriter, type MetadataStore, type Space } from '@dxos/echo-pipeline';
|
|
17
12
|
import { SpaceDocVersion } from '@dxos/echo-protocol';
|
|
18
|
-
import type { EdgeConnection
|
|
13
|
+
import type { EdgeConnection } from '@dxos/edge-client';
|
|
19
14
|
import { type FeedStore, type FeedWrapper } from '@dxos/feed-store';
|
|
20
15
|
import { failedInvariant } from '@dxos/invariant';
|
|
21
16
|
import { type Keyring } from '@dxos/keyring';
|
|
@@ -80,7 +75,6 @@ export type DataSpaceParams = {
|
|
|
80
75
|
callbacks?: DataSpaceCallbacks;
|
|
81
76
|
cache?: SpaceCache;
|
|
82
77
|
edgeConnection?: EdgeConnection;
|
|
83
|
-
edgeHttpClient?: EdgeHttpClient;
|
|
84
78
|
edgeFeatures?: Runtime.Client.EdgeFeatures;
|
|
85
79
|
};
|
|
86
80
|
|
|
@@ -102,7 +96,7 @@ export class DataSpace {
|
|
|
102
96
|
private readonly _feedStore: FeedStore<FeedMessage>;
|
|
103
97
|
private readonly _metadataStore: MetadataStore;
|
|
104
98
|
private readonly _signingContext: SigningContext;
|
|
105
|
-
private readonly _notarizationPlugin
|
|
99
|
+
private readonly _notarizationPlugin = new NotarizationPlugin();
|
|
106
100
|
private readonly _callbacks: DataSpaceCallbacks;
|
|
107
101
|
private readonly _cache?: SpaceCache = undefined;
|
|
108
102
|
private readonly _echoHost: EchoHost;
|
|
@@ -142,11 +136,6 @@ export class DataSpace {
|
|
|
142
136
|
this._signingContext = params.signingContext;
|
|
143
137
|
this._callbacks = params.callbacks ?? {};
|
|
144
138
|
this._echoHost = params.echoHost;
|
|
145
|
-
this._notarizationPlugin = new NotarizationPlugin({
|
|
146
|
-
spaceId: this._inner.id,
|
|
147
|
-
edgeClient: params.edgeHttpClient,
|
|
148
|
-
edgeFeatures: params.edgeFeatures,
|
|
149
|
-
});
|
|
150
139
|
|
|
151
140
|
this.authVerifier = new TrustedKeySetAuthVerifier({
|
|
152
141
|
trustedKeysProvider: () =>
|
|
@@ -329,7 +318,6 @@ export class DataSpace {
|
|
|
329
318
|
this._state = SpaceState.SPACE_INITIALIZING;
|
|
330
319
|
log('new state', { state: SpaceState[this._state] });
|
|
331
320
|
|
|
332
|
-
log('initializing control pipeline');
|
|
333
321
|
await this._initializeAndReadControlPipeline();
|
|
334
322
|
|
|
335
323
|
// Allow other tasks to run before loading the data pipeline.
|
|
@@ -337,13 +325,10 @@ export class DataSpace {
|
|
|
337
325
|
|
|
338
326
|
const ready = this.stateUpdate.waitForCondition(() => this._state === SpaceState.SPACE_READY);
|
|
339
327
|
|
|
340
|
-
log('initializing automerge root');
|
|
341
328
|
this._automergeSpaceState.startProcessingRootDocs();
|
|
342
329
|
|
|
343
330
|
// TODO(dmaretskyi): Change so `initializeDataPipeline` doesn't wait for the space to be READY, but rather any state with a valid root.
|
|
344
|
-
log('waiting for space to be ready');
|
|
345
331
|
await ready;
|
|
346
|
-
log('space is ready');
|
|
347
332
|
}
|
|
348
333
|
|
|
349
334
|
private async _enterReadyState() {
|
|
@@ -360,7 +345,6 @@ export class DataSpace {
|
|
|
360
345
|
private async _initializeAndReadControlPipeline() {
|
|
361
346
|
await this._inner.controlPipeline.state.waitUntilReachedTargetTimeframe({
|
|
362
347
|
ctx: this._ctx,
|
|
363
|
-
timeout: 10_000,
|
|
364
348
|
breakOnStall: false,
|
|
365
349
|
});
|
|
366
350
|
|
|
@@ -424,16 +408,8 @@ export class DataSpace {
|
|
|
424
408
|
}
|
|
425
409
|
|
|
426
410
|
if (credentials.length > 0) {
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
// Never times out
|
|
430
|
-
await this.notarizationPlugin.notarize({ ctx: this._ctx, credentials, timeout: 0 });
|
|
431
|
-
|
|
432
|
-
log('credentials notarized');
|
|
433
|
-
} catch (err) {
|
|
434
|
-
log.error('error notarizing credentials for feed admission', err);
|
|
435
|
-
throw err;
|
|
436
|
-
}
|
|
411
|
+
// Never times out
|
|
412
|
+
await this.notarizationPlugin.notarize({ ctx: this._ctx, credentials, timeout: 0 });
|
|
437
413
|
|
|
438
414
|
// Set this after credentials are notarized so that on failure we will retry.
|
|
439
415
|
await this._metadataStore.setWritableFeedKeys(this.key, this.inner.controlFeedKey!, this.inner.dataFeedKey!);
|