@dxos/echo-pipeline 0.6.13 → 0.6.14-main.2b6a0f3
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-COV5H3SU.mjs +2060 -0
- package/dist/lib/browser/chunk-COV5H3SU.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +3477 -17
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +17 -7
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node/{chunk-7HHYCGUR.cjs → chunk-XHGWCBX6.cjs} +116 -64
- package/dist/lib/node/chunk-XHGWCBX6.cjs.map +7 -0
- package/dist/lib/node/index.cjs +3454 -35
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +25 -15
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/lib/{browser/chunk-UKXIJW43.mjs → node-esm/chunk-KKYLPT56.mjs} +103 -53
- package/dist/lib/node-esm/chunk-KKYLPT56.mjs.map +7 -0
- package/dist/lib/{browser/chunk-MPWFDDQK.mjs → node-esm/index.mjs} +1723 -342
- package/dist/lib/node-esm/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -0
- package/dist/lib/node-esm/testing/index.mjs +562 -0
- package/dist/lib/node-esm/testing/index.mjs.map +7 -0
- package/dist/types/src/automerge/automerge-host.d.ts +24 -1
- package/dist/types/src/automerge/automerge-host.d.ts.map +1 -1
- package/dist/types/src/automerge/collection-synchronizer.d.ts +2 -0
- package/dist/types/src/automerge/collection-synchronizer.d.ts.map +1 -1
- package/dist/types/src/automerge/echo-network-adapter.d.ts.map +1 -1
- package/dist/types/src/automerge/echo-replicator.d.ts +3 -3
- package/dist/types/src/automerge/echo-replicator.d.ts.map +1 -1
- package/dist/types/src/automerge/mesh-echo-replicator-connection.d.ts +3 -3
- package/dist/types/src/automerge/mesh-echo-replicator-connection.d.ts.map +1 -1
- package/dist/types/src/automerge/mesh-echo-replicator.d.ts.map +1 -1
- package/dist/types/src/automerge/space-collection.d.ts +3 -2
- package/dist/types/src/automerge/space-collection.d.ts.map +1 -1
- package/dist/types/src/db-host/automerge-metrics.d.ts +11 -0
- package/dist/types/src/db-host/automerge-metrics.d.ts.map +1 -0
- package/dist/types/src/db-host/data-service.d.ts +3 -2
- package/dist/types/src/db-host/data-service.d.ts.map +1 -1
- package/dist/types/src/db-host/database-root.d.ts +20 -0
- package/dist/types/src/db-host/database-root.d.ts.map +1 -0
- package/dist/types/src/db-host/documents-iterator.d.ts +7 -0
- package/dist/types/src/db-host/documents-iterator.d.ts.map +1 -0
- package/dist/types/src/db-host/echo-host.d.ts +73 -0
- package/dist/types/src/db-host/echo-host.d.ts.map +1 -0
- package/dist/types/src/db-host/index.d.ts +5 -0
- package/dist/types/src/db-host/index.d.ts.map +1 -1
- package/dist/types/src/db-host/migration.d.ts +8 -0
- package/dist/types/src/db-host/migration.d.ts.map +1 -0
- package/dist/types/src/db-host/query-service.d.ts +25 -0
- package/dist/types/src/db-host/query-service.d.ts.map +1 -0
- package/dist/types/src/db-host/query-state.d.ts +41 -0
- package/dist/types/src/db-host/query-state.d.ts.map +1 -0
- package/dist/types/src/db-host/space-state-manager.d.ts +23 -0
- package/dist/types/src/db-host/space-state-manager.d.ts.map +1 -0
- package/dist/types/src/edge/echo-edge-replicator.d.ts +23 -0
- package/dist/types/src/edge/echo-edge-replicator.d.ts.map +1 -0
- package/dist/types/src/edge/echo-edge-replicator.test.d.ts +2 -0
- package/dist/types/src/edge/echo-edge-replicator.test.d.ts.map +1 -0
- package/dist/types/src/edge/index.d.ts +2 -0
- package/dist/types/src/edge/index.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/metadata/metadata-store.d.ts +4 -1
- package/dist/types/src/metadata/metadata-store.d.ts.map +1 -1
- package/dist/types/src/space/space-protocol.d.ts.map +1 -1
- package/dist/types/src/space/space.d.ts +1 -0
- package/dist/types/src/space/space.d.ts.map +1 -1
- package/dist/types/src/testing/test-agent-builder.d.ts +2 -0
- package/dist/types/src/testing/test-agent-builder.d.ts.map +1 -1
- package/dist/types/src/testing/test-replicator.d.ts +4 -4
- package/dist/types/src/testing/test-replicator.d.ts.map +1 -1
- package/package.json +41 -50
- package/src/automerge/automerge-host.test.ts +8 -9
- package/src/automerge/automerge-host.ts +46 -7
- package/src/automerge/automerge-repo.test.ts +18 -16
- package/src/automerge/collection-synchronizer.test.ts +10 -5
- package/src/automerge/collection-synchronizer.ts +17 -6
- package/src/automerge/echo-data-monitor.test.ts +1 -3
- package/src/automerge/echo-network-adapter.test.ts +4 -3
- package/src/automerge/echo-network-adapter.ts +5 -4
- package/src/automerge/echo-replicator.ts +3 -3
- package/src/automerge/mesh-echo-replicator-connection.ts +10 -9
- package/src/automerge/mesh-echo-replicator.ts +2 -1
- package/src/automerge/space-collection.ts +3 -2
- package/src/automerge/storage-adapter.test.ts +2 -3
- package/src/db-host/automerge-metrics.ts +38 -0
- package/src/db-host/data-service.ts +29 -14
- package/src/db-host/database-root.ts +87 -0
- package/src/db-host/documents-iterator.ts +73 -0
- package/src/db-host/documents-synchronizer.test.ts +2 -2
- package/src/db-host/echo-host.ts +257 -0
- package/src/db-host/index.ts +6 -1
- package/src/db-host/migration.ts +57 -0
- package/src/db-host/query-service.ts +209 -0
- package/src/db-host/query-state.ts +214 -0
- package/src/db-host/space-state-manager.ts +90 -0
- package/src/edge/echo-edge-replicator.test.ts +96 -0
- package/src/edge/echo-edge-replicator.ts +341 -0
- package/src/edge/index.ts +5 -0
- package/src/index.ts +1 -0
- package/src/metadata/metadata-store.ts +22 -2
- package/src/pipeline/pipeline-stress.test.ts +44 -47
- package/src/pipeline/pipeline.test.ts +3 -4
- package/src/space/control-pipeline.test.ts +2 -3
- package/src/space/control-pipeline.ts +10 -1
- package/src/space/replication.browser.test.ts +2 -8
- package/src/space/space-manager.browser.test.ts +6 -5
- package/src/space/space-protocol.browser.test.ts +29 -34
- package/src/space/space-protocol.test.ts +37 -27
- package/src/space/space-protocol.ts +0 -4
- package/src/space/space.test.ts +30 -11
- package/src/space/space.ts +7 -2
- package/src/testing/test-agent-builder.ts +16 -4
- package/src/testing/test-replicator.ts +3 -3
- package/dist/lib/browser/chunk-MPWFDDQK.mjs.map +0 -7
- package/dist/lib/browser/chunk-UKXIJW43.mjs.map +0 -7
- package/dist/lib/browser/chunk-XPCF2V5U.mjs +0 -31
- package/dist/lib/browser/chunk-XPCF2V5U.mjs.map +0 -7
- package/dist/lib/browser/light.mjs +0 -32
- package/dist/lib/browser/light.mjs.map +0 -7
- package/dist/lib/node/chunk-5DH4KR2S.cjs +0 -2148
- package/dist/lib/node/chunk-5DH4KR2S.cjs.map +0 -7
- package/dist/lib/node/chunk-7HHYCGUR.cjs.map +0 -7
- package/dist/lib/node/chunk-DZVH7HDD.cjs +0 -43
- package/dist/lib/node/chunk-DZVH7HDD.cjs.map +0 -7
- package/dist/lib/node/light.cjs +0 -52
- package/dist/lib/node/light.cjs.map +0 -7
- package/dist/types/src/light.d.ts +0 -4
- package/dist/types/src/light.d.ts.map +0 -1
- package/src/light.ts +0 -7
|
@@ -2,15 +2,11 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import expect from 'expect';
|
|
8
|
-
import waitForExpect from 'wait-for-expect';
|
|
5
|
+
import { describe, expect, test, onTestFinished } from 'vitest';
|
|
9
6
|
|
|
10
7
|
import { Keyring } from '@dxos/keyring';
|
|
11
8
|
import { PublicKey } from '@dxos/keys';
|
|
12
9
|
import { createStorage } from '@dxos/random-access-storage';
|
|
13
|
-
import { describe, test, afterTest } from '@dxos/test';
|
|
14
10
|
import { Timeframe } from '@dxos/timeframe';
|
|
15
11
|
|
|
16
12
|
import { TestFeedBuilder, TestAgentBuilder, WebsocketNetworkManagerProvider } from '../testing';
|
|
@@ -23,7 +19,9 @@ const SIGNAL_URL = `ws://localhost:${port}/.well-known/dx/signal`;
|
|
|
23
19
|
describe('space/space-protocol', () => {
|
|
24
20
|
test('two peers discover each other', async () => {
|
|
25
21
|
const builder = new TestAgentBuilder();
|
|
26
|
-
|
|
22
|
+
onTestFinished(async () => {
|
|
23
|
+
await builder.close();
|
|
24
|
+
});
|
|
27
25
|
const topic = PublicKey.random();
|
|
28
26
|
|
|
29
27
|
const peer1 = await builder.createPeer();
|
|
@@ -39,18 +37,22 @@ describe('space/space-protocol', () => {
|
|
|
39
37
|
await protocol1.start();
|
|
40
38
|
await protocol2.start();
|
|
41
39
|
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
onTestFinished(() => protocol1.stop());
|
|
41
|
+
onTestFinished(() => protocol2.stop());
|
|
44
42
|
|
|
45
|
-
await
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
await expect
|
|
44
|
+
.poll(() => presence1.getPeersOnline().some(({ identityKey }) => identityKey.equals(peer2.identityKey)))
|
|
45
|
+
.toBeTruthy();
|
|
46
|
+
await expect
|
|
47
|
+
.poll(() => presence2.getPeersOnline().some(({ identityKey }) => identityKey.equals(peer1.identityKey)))
|
|
48
|
+
.toBeTruthy();
|
|
49
49
|
});
|
|
50
50
|
|
|
51
51
|
test('replicates a feed', async () => {
|
|
52
52
|
const builder = new TestAgentBuilder();
|
|
53
|
-
|
|
53
|
+
onTestFinished(async () => {
|
|
54
|
+
await builder.close();
|
|
55
|
+
});
|
|
54
56
|
const topic = PublicKey.random();
|
|
55
57
|
|
|
56
58
|
const peer1 = await builder.createPeer();
|
|
@@ -62,8 +64,8 @@ describe('space/space-protocol', () => {
|
|
|
62
64
|
await protocol1.start();
|
|
63
65
|
await protocol2.start();
|
|
64
66
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
+
onTestFinished(() => protocol1.stop());
|
|
68
|
+
onTestFinished(() => protocol2.stop());
|
|
67
69
|
|
|
68
70
|
const builder1 = new TestFeedBuilder();
|
|
69
71
|
const feedStore1 = builder1.createFeedStore();
|
|
@@ -79,24 +81,23 @@ describe('space/space-protocol', () => {
|
|
|
79
81
|
await protocol2.addFeed(feed2);
|
|
80
82
|
|
|
81
83
|
await feed1.append({ timeframe: new Timeframe() });
|
|
82
|
-
await
|
|
83
|
-
expect(feed2.properties.length).toEqual(1);
|
|
84
|
-
});
|
|
84
|
+
await expect.poll(() => feed2.properties.length).toEqual(1);
|
|
85
85
|
|
|
86
86
|
await feed1.append({ timeframe: new Timeframe() });
|
|
87
|
-
await
|
|
88
|
-
expect(feed2.properties.length).toEqual(2);
|
|
89
|
-
});
|
|
87
|
+
await expect.poll(() => feed2.properties.length).toEqual(2);
|
|
90
88
|
|
|
91
89
|
await builder.close();
|
|
92
90
|
});
|
|
93
91
|
|
|
94
|
-
|
|
92
|
+
// TODO: Some storage drivers may break when there are multiple storage instances.
|
|
93
|
+
test.skip('replicates a feed through a webrtc connection', async () => {
|
|
95
94
|
const builder = new TestAgentBuilder({
|
|
96
95
|
storage: createStorage(),
|
|
97
96
|
networkManagerProvider: WebsocketNetworkManagerProvider(SIGNAL_URL),
|
|
98
97
|
});
|
|
99
|
-
|
|
98
|
+
onTestFinished(async () => {
|
|
99
|
+
await builder.close();
|
|
100
|
+
});
|
|
100
101
|
|
|
101
102
|
const keyring = new Keyring();
|
|
102
103
|
const topic = await keyring.createKey();
|
|
@@ -110,8 +111,8 @@ describe('space/space-protocol', () => {
|
|
|
110
111
|
await protocol1.start();
|
|
111
112
|
await protocol2.start();
|
|
112
113
|
|
|
113
|
-
|
|
114
|
-
|
|
114
|
+
onTestFinished(() => protocol1.stop());
|
|
115
|
+
onTestFinished(() => protocol2.stop());
|
|
115
116
|
|
|
116
117
|
const feedKey = await peer1.keyring.createKey();
|
|
117
118
|
|
|
@@ -122,17 +123,11 @@ describe('space/space-protocol', () => {
|
|
|
122
123
|
await protocol2.addFeed(feed2);
|
|
123
124
|
|
|
124
125
|
await feed1.append({ timeframe: new Timeframe() });
|
|
125
|
-
await
|
|
126
|
-
expect(feed2.properties.length).toEqual(1);
|
|
127
|
-
});
|
|
126
|
+
await expect.poll(() => feed2.properties.length).toEqual(1);
|
|
128
127
|
|
|
129
128
|
await feed1.append({ timeframe: new Timeframe() });
|
|
130
|
-
await
|
|
131
|
-
expect(feed2.properties.length).toEqual(2);
|
|
132
|
-
});
|
|
129
|
+
await expect.poll(() => feed2.properties.length).toEqual(2);
|
|
133
130
|
|
|
134
131
|
await builder.close();
|
|
135
|
-
})
|
|
136
|
-
.skipEnvironments('webkit')
|
|
137
|
-
.tag('flaky'); // Some storage drivers may break when there are multiple storage instances.
|
|
132
|
+
});
|
|
138
133
|
});
|
|
@@ -2,15 +2,13 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import expect from '
|
|
6
|
-
import waitForExpect from 'wait-for-expect';
|
|
5
|
+
import { describe, expect, test, onTestFinished } from 'vitest';
|
|
7
6
|
|
|
8
7
|
import { PublicKey } from '@dxos/keys';
|
|
9
8
|
import { MemorySignalManager, MemorySignalManagerContext } from '@dxos/messaging';
|
|
10
9
|
import { MemoryTransportFactory, SwarmNetworkManager } from '@dxos/network-manager';
|
|
11
10
|
import { StorageType, createStorage } from '@dxos/random-access-storage';
|
|
12
11
|
import { BlobStore } from '@dxos/teleport-extension-object-sync';
|
|
13
|
-
import { describe, test, afterTest } from '@dxos/test';
|
|
14
12
|
import { Timeframe } from '@dxos/timeframe';
|
|
15
13
|
|
|
16
14
|
import { AuthStatus, MOCK_AUTH_PROVIDER, MOCK_AUTH_VERIFIER, SpaceProtocol } from './space-protocol';
|
|
@@ -19,7 +17,9 @@ import { TestAgentBuilder, TestFeedBuilder } from '../testing';
|
|
|
19
17
|
describe('space/space-protocol', () => {
|
|
20
18
|
test('two peers discover each other via presence', async () => {
|
|
21
19
|
const builder = new TestAgentBuilder();
|
|
22
|
-
|
|
20
|
+
onTestFinished(async () => {
|
|
21
|
+
await builder.close();
|
|
22
|
+
});
|
|
23
23
|
const topic = PublicKey.random();
|
|
24
24
|
|
|
25
25
|
const peer1 = await builder.createPeer();
|
|
@@ -35,15 +35,21 @@ describe('space/space-protocol', () => {
|
|
|
35
35
|
const protocol2 = peer2.createSpaceProtocol(topic, gossip2);
|
|
36
36
|
|
|
37
37
|
await protocol1.start();
|
|
38
|
-
|
|
38
|
+
onTestFinished(() => protocol1.stop());
|
|
39
39
|
|
|
40
40
|
await protocol2.start();
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
await
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
onTestFinished(() => protocol2.stop());
|
|
42
|
+
|
|
43
|
+
await expect
|
|
44
|
+
.poll(() => presence1.getPeersOnline().some(({ identityKey }) => identityKey.equals(peer2.identityKey)), {
|
|
45
|
+
timeout: 1_000,
|
|
46
|
+
})
|
|
47
|
+
.toBeTruthy();
|
|
48
|
+
await expect
|
|
49
|
+
.poll(() => presence2.getPeersOnline().some(({ identityKey }) => identityKey.equals(peer1.identityKey)), {
|
|
50
|
+
timeout: 1_000,
|
|
51
|
+
})
|
|
52
|
+
.toBeTruthy();
|
|
47
53
|
});
|
|
48
54
|
|
|
49
55
|
test('failing authentication', async () => {
|
|
@@ -62,6 +68,10 @@ describe('space/space-protocol', () => {
|
|
|
62
68
|
networkManager: new SwarmNetworkManager({
|
|
63
69
|
signalManager: new MemorySignalManager(signalContext),
|
|
64
70
|
transportFactory: MemoryTransportFactory,
|
|
71
|
+
peerInfo: {
|
|
72
|
+
peerKey: peerId1.toHex(),
|
|
73
|
+
identityKey: peerId1.toHex(),
|
|
74
|
+
},
|
|
65
75
|
}),
|
|
66
76
|
});
|
|
67
77
|
|
|
@@ -77,23 +87,27 @@ describe('space/space-protocol', () => {
|
|
|
77
87
|
networkManager: new SwarmNetworkManager({
|
|
78
88
|
signalManager: new MemorySignalManager(signalContext),
|
|
79
89
|
transportFactory: MemoryTransportFactory,
|
|
90
|
+
peerInfo: {
|
|
91
|
+
peerKey: peerId2.toHex(),
|
|
92
|
+
identityKey: peerId2.toHex(),
|
|
93
|
+
},
|
|
80
94
|
}),
|
|
81
95
|
});
|
|
82
96
|
|
|
83
97
|
await protocol1.start();
|
|
84
|
-
|
|
98
|
+
onTestFinished(() => protocol1.stop());
|
|
85
99
|
|
|
86
100
|
await protocol2.start();
|
|
87
|
-
|
|
101
|
+
onTestFinished(() => protocol2.stop());
|
|
88
102
|
|
|
89
|
-
await
|
|
90
|
-
expect(protocol1.sessions.get(peerId2)?.authStatus).toEqual(AuthStatus.FAILURE);
|
|
91
|
-
});
|
|
103
|
+
await expect.poll(() => protocol1.sessions.get(peerId2)?.authStatus).toEqual(AuthStatus.FAILURE);
|
|
92
104
|
});
|
|
93
105
|
|
|
94
106
|
test('replicates a feed', async () => {
|
|
95
107
|
const builder = new TestAgentBuilder();
|
|
96
|
-
|
|
108
|
+
onTestFinished(async () => {
|
|
109
|
+
await builder.close();
|
|
110
|
+
});
|
|
97
111
|
|
|
98
112
|
const topic = PublicKey.random();
|
|
99
113
|
|
|
@@ -106,8 +120,8 @@ describe('space/space-protocol', () => {
|
|
|
106
120
|
await protocol1.start();
|
|
107
121
|
await protocol2.start();
|
|
108
122
|
|
|
109
|
-
|
|
110
|
-
|
|
123
|
+
onTestFinished(() => protocol1.stop());
|
|
124
|
+
onTestFinished(() => protocol2.stop());
|
|
111
125
|
|
|
112
126
|
//
|
|
113
127
|
// Create feeds.
|
|
@@ -131,16 +145,12 @@ describe('space/space-protocol', () => {
|
|
|
131
145
|
|
|
132
146
|
// TODO(burdon): Append batch of messages.
|
|
133
147
|
await feed1.append({ timeframe: new Timeframe() });
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
expect(feed2.properties.length).toEqual(1);
|
|
137
|
-
});
|
|
148
|
+
// Received message appended before replication.
|
|
149
|
+
await expect.poll(() => feed2.properties.length).toEqual(1);
|
|
138
150
|
|
|
139
151
|
// TODO(burdon): Append batch of messages.
|
|
140
152
|
await feed1.append({ timeframe: new Timeframe() });
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
expect(feed2.properties.length).toEqual(2);
|
|
144
|
-
});
|
|
153
|
+
// Received message appended after replication.
|
|
154
|
+
await expect.poll(() => feed2.properties.length).toEqual(2);
|
|
145
155
|
});
|
|
146
156
|
});
|
|
@@ -150,10 +150,6 @@ export class SpaceProtocol {
|
|
|
150
150
|
const topic = await this._topic;
|
|
151
151
|
this._connection = await this._networkManager.joinSwarm({
|
|
152
152
|
protocolProvider: this._createProtocolProvider(credentials),
|
|
153
|
-
peerInfo: {
|
|
154
|
-
peerKey: this._swarmIdentity.peerKey.toHex(),
|
|
155
|
-
identityKey: this._swarmIdentity.identityKey.toHex(),
|
|
156
|
-
},
|
|
157
153
|
topic,
|
|
158
154
|
topology: this._topology,
|
|
159
155
|
label: `swarm ${topic.truncate()} for space ${this._spaceKey.truncate()}`,
|
package/src/space/space.test.ts
CHANGED
|
@@ -2,11 +2,10 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import expect from '
|
|
5
|
+
import { onTestFinished, describe, expect, test } from 'vitest';
|
|
6
6
|
|
|
7
7
|
import { Context } from '@dxos/context';
|
|
8
8
|
import { CredentialGenerator } from '@dxos/credentials';
|
|
9
|
-
import { afterTest, describe, test } from '@dxos/test';
|
|
10
9
|
|
|
11
10
|
import { TestAgentBuilder } from '../testing';
|
|
12
11
|
|
|
@@ -16,13 +15,17 @@ const run = <T>(cb: () => Promise<T>): Promise<T> => cb();
|
|
|
16
15
|
describe('space/space', () => {
|
|
17
16
|
test('creates a database with object model', async () => {
|
|
18
17
|
const builder = new TestAgentBuilder();
|
|
19
|
-
|
|
18
|
+
onTestFinished(async () => {
|
|
19
|
+
await builder.close();
|
|
20
|
+
});
|
|
20
21
|
const agent = await builder.createPeer();
|
|
21
22
|
const space = await agent.createSpace();
|
|
22
23
|
|
|
23
24
|
await space.open(Context.default());
|
|
24
25
|
expect(space.isOpen).toBeTruthy();
|
|
25
|
-
|
|
26
|
+
onTestFinished(async () => {
|
|
27
|
+
await space.close();
|
|
28
|
+
});
|
|
26
29
|
|
|
27
30
|
await agent.spaceGenesis(space);
|
|
28
31
|
|
|
@@ -34,7 +37,9 @@ describe('space/space', () => {
|
|
|
34
37
|
|
|
35
38
|
test('two spaces replicating', async () => {
|
|
36
39
|
const builder = new TestAgentBuilder();
|
|
37
|
-
|
|
40
|
+
onTestFinished(async () => {
|
|
41
|
+
await builder.close();
|
|
42
|
+
});
|
|
38
43
|
|
|
39
44
|
//
|
|
40
45
|
// Agent 1
|
|
@@ -44,8 +49,11 @@ describe('space/space', () => {
|
|
|
44
49
|
const space = await agent.createSpace(agent.identityKey);
|
|
45
50
|
|
|
46
51
|
await space.open(Context.default());
|
|
52
|
+
await space.startProtocol();
|
|
47
53
|
expect(space.isOpen).toBeTruthy();
|
|
48
|
-
|
|
54
|
+
onTestFinished(async () => {
|
|
55
|
+
await space.close();
|
|
56
|
+
});
|
|
49
57
|
|
|
50
58
|
await agent.spaceGenesis(space);
|
|
51
59
|
|
|
@@ -63,8 +71,11 @@ describe('space/space', () => {
|
|
|
63
71
|
const space = await agent.createSpace(agent.identityKey, space1.key, space1.genesisFeedKey, undefined, true);
|
|
64
72
|
|
|
65
73
|
await space.open(Context.default());
|
|
74
|
+
await space.startProtocol();
|
|
66
75
|
expect(space.isOpen).toBeTruthy();
|
|
67
|
-
|
|
76
|
+
onTestFinished(async () => {
|
|
77
|
+
await space.close();
|
|
78
|
+
});
|
|
68
79
|
|
|
69
80
|
return [agent, space];
|
|
70
81
|
});
|
|
@@ -110,13 +121,17 @@ describe('space/space', () => {
|
|
|
110
121
|
|
|
111
122
|
test('open & close', async () => {
|
|
112
123
|
const builder = new TestAgentBuilder();
|
|
113
|
-
|
|
124
|
+
onTestFinished(async () => {
|
|
125
|
+
await builder.close();
|
|
126
|
+
});
|
|
114
127
|
const agent = await builder.createPeer();
|
|
115
128
|
const space1 = await agent.createSpace();
|
|
116
129
|
|
|
117
130
|
await space1.open(Context.default());
|
|
118
131
|
expect(space1.isOpen).toBeTruthy();
|
|
119
|
-
|
|
132
|
+
onTestFinished(async () => {
|
|
133
|
+
await space1.close();
|
|
134
|
+
});
|
|
120
135
|
|
|
121
136
|
await agent.spaceGenesis(space1);
|
|
122
137
|
|
|
@@ -134,13 +149,17 @@ describe('space/space', () => {
|
|
|
134
149
|
|
|
135
150
|
test('re-open', async () => {
|
|
136
151
|
const builder = new TestAgentBuilder();
|
|
137
|
-
|
|
152
|
+
onTestFinished(async () => {
|
|
153
|
+
await builder.close();
|
|
154
|
+
});
|
|
138
155
|
const agent = await builder.createPeer();
|
|
139
156
|
const space = await agent.createSpace();
|
|
140
157
|
|
|
141
158
|
{
|
|
142
159
|
await space.open(Context.default());
|
|
143
|
-
|
|
160
|
+
onTestFinished(async () => {
|
|
161
|
+
await space.close();
|
|
162
|
+
});
|
|
144
163
|
expect(space.isOpen).toBeTruthy();
|
|
145
164
|
|
|
146
165
|
await agent.spaceGenesis(space);
|
package/src/space/space.ts
CHANGED
|
@@ -176,12 +176,17 @@ export class Space extends Resource {
|
|
|
176
176
|
|
|
177
177
|
// Order is important.
|
|
178
178
|
await this._controlPipeline.start();
|
|
179
|
-
await this.protocol.start();
|
|
180
|
-
await this.protocol.addFeed(await this._feedProvider(this._genesisFeedKey));
|
|
181
179
|
|
|
182
180
|
log('opened');
|
|
183
181
|
}
|
|
184
182
|
|
|
183
|
+
@synchronized
|
|
184
|
+
public async startProtocol() {
|
|
185
|
+
invariant(this.isOpen);
|
|
186
|
+
await this.protocol.start();
|
|
187
|
+
await this.protocol.addFeed(await this._feedProvider(this._genesisFeedKey));
|
|
188
|
+
}
|
|
189
|
+
|
|
185
190
|
@synchronized
|
|
186
191
|
protected override async _close() {
|
|
187
192
|
log('closing...', { key: this._key });
|
|
@@ -8,7 +8,7 @@ import { type FeedStore } from '@dxos/feed-store';
|
|
|
8
8
|
import { type Keyring } from '@dxos/keyring';
|
|
9
9
|
import { PublicKey } from '@dxos/keys';
|
|
10
10
|
import { MemorySignalManager, MemorySignalManagerContext, WebsocketSignalManager } from '@dxos/messaging';
|
|
11
|
-
import { MemoryTransportFactory, SwarmNetworkManager,
|
|
11
|
+
import { MemoryTransportFactory, SwarmNetworkManager, createRtcTransportFactory } from '@dxos/network-manager';
|
|
12
12
|
import type { FeedMessage } from '@dxos/protocols/proto/dxos/echo/feed';
|
|
13
13
|
import { type SpaceMetadata } from '@dxos/protocols/proto/dxos/echo/metadata';
|
|
14
14
|
import { AdmittedFeed } from '@dxos/protocols/proto/dxos/halo/credentials';
|
|
@@ -36,7 +36,7 @@ export const WebsocketNetworkManagerProvider =
|
|
|
36
36
|
() =>
|
|
37
37
|
new SwarmNetworkManager({
|
|
38
38
|
signalManager: new WebsocketSignalManager([{ server: signalUrl }]),
|
|
39
|
-
transportFactory:
|
|
39
|
+
transportFactory: createRtcTransportFactory(),
|
|
40
40
|
});
|
|
41
41
|
|
|
42
42
|
export type TestAgentBuilderOptions = {
|
|
@@ -127,11 +127,23 @@ export class TestAgent {
|
|
|
127
127
|
return this._spaces.get(spaceKey);
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
+
private _networkManager?: SwarmNetworkManager;
|
|
131
|
+
get networkManager() {
|
|
132
|
+
if (this._networkManager) {
|
|
133
|
+
return this._networkManager;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
this._networkManager = this._networkManagerProvider();
|
|
137
|
+
this._networkManager.setPeerInfo({ peerKey: this.deviceKey.toHex(), identityKey: this.identityKey.toHex() });
|
|
138
|
+
|
|
139
|
+
return this._networkManager;
|
|
140
|
+
}
|
|
141
|
+
|
|
130
142
|
private _spaceManager?: SpaceManager;
|
|
131
143
|
get spaceManager() {
|
|
132
144
|
return (this._spaceManager ??= new SpaceManager({
|
|
133
145
|
feedStore: this.feedStore,
|
|
134
|
-
networkManager: this.
|
|
146
|
+
networkManager: this.networkManager,
|
|
135
147
|
metadataStore: this.metadataStore,
|
|
136
148
|
blobStore: this.blobStore,
|
|
137
149
|
}));
|
|
@@ -205,7 +217,7 @@ export class TestAgent {
|
|
|
205
217
|
credentialProvider: MOCK_AUTH_PROVIDER,
|
|
206
218
|
credentialAuthenticator: MOCK_AUTH_VERIFIER,
|
|
207
219
|
},
|
|
208
|
-
networkManager: this.
|
|
220
|
+
networkManager: this.networkManager,
|
|
209
221
|
blobStore: this.blobStore,
|
|
210
222
|
onSessionAuth: (session) => {
|
|
211
223
|
session.addExtension(
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { sleep, synchronized } from '@dxos/async';
|
|
6
|
-
import { type Message } from '@dxos/automerge/automerge-repo';
|
|
7
6
|
import { type Context, LifecycleState, Resource } from '@dxos/context';
|
|
8
7
|
import { invariant } from '@dxos/invariant';
|
|
9
8
|
import { log } from '@dxos/log';
|
|
9
|
+
import type { AutomergeProtocolMessage } from '@dxos/protocols';
|
|
10
10
|
import { AutomergeReplicator, type AutomergeReplicatorFactory } from '@dxos/teleport-extension-automerge-replicator';
|
|
11
11
|
|
|
12
12
|
import type {
|
|
@@ -159,8 +159,8 @@ export class TestReplicatorConnection implements ReplicatorConnection {
|
|
|
159
159
|
|
|
160
160
|
constructor(
|
|
161
161
|
public readonly peerId: string,
|
|
162
|
-
public readonly readable: ReadableStream<
|
|
163
|
-
public readonly writable: WritableStream<
|
|
162
|
+
public readonly readable: ReadableStream<AutomergeProtocolMessage>,
|
|
163
|
+
public readonly writable: WritableStream<AutomergeProtocolMessage>,
|
|
164
164
|
) {}
|
|
165
165
|
|
|
166
166
|
async shouldAdvertise(params: ShouldAdvertiseParams): Promise<boolean> {
|