@dxos/echo-pipeline 0.3.11-main.cf6cc01 → 0.3.11-main.d46c1ca
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-WDT56L4E.mjs → chunk-RM4WCR2Z.mjs} +14 -11
- package/dist/lib/browser/{chunk-WDT56L4E.mjs.map → chunk-RM4WCR2Z.mjs.map} +3 -3
- package/dist/lib/browser/index.mjs +1 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +1 -1
- package/dist/lib/browser/testing/index.mjs.map +1 -1
- package/dist/lib/node/{chunk-C6GFWBRK.cjs → chunk-W5EK5DXL.cjs} +16 -14
- package/dist/lib/node/{chunk-C6GFWBRK.cjs.map → chunk-W5EK5DXL.cjs.map} +3 -3
- package/dist/lib/node/index.cjs +26 -28
- package/dist/lib/node/index.cjs.map +2 -2
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +16 -16
- package/dist/lib/node/testing/index.cjs.map +1 -1
- package/dist/types/src/automerge/automerge-host.d.ts +15 -1
- package/dist/types/src/automerge/automerge-host.d.ts.map +1 -1
- package/dist/types/src/automerge/index.d.ts +1 -1
- package/dist/types/src/automerge/index.d.ts.map +1 -1
- package/package.json +33 -33
- package/src/automerge/automerge-host.test.ts +162 -36
- package/src/automerge/automerge-host.ts +8 -5
- package/src/automerge/index.ts +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Repo, StorageAdapter, type Chunk, type StorageKey } from '@dxos/automerge/automerge-repo';
|
|
1
|
+
import { Repo, NetworkAdapter, StorageAdapter, type Message, type PeerId, type Chunk, type StorageKey } from '@dxos/automerge/automerge-repo';
|
|
2
2
|
import { Stream } from '@dxos/codec-protobuf';
|
|
3
3
|
import { type HostInfo, type SyncRepoRequest, type SyncRepoResponse } from '@dxos/protocols/proto/dxos/echo/service';
|
|
4
4
|
import { type Directory } from '@dxos/random-access-storage';
|
|
@@ -16,6 +16,20 @@ export declare class AutomergeHost {
|
|
|
16
16
|
getHostInfo(): HostInfo;
|
|
17
17
|
createExtension(): AutomergeReplicator;
|
|
18
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Used to replicate with other peers over the network.
|
|
21
|
+
*/
|
|
22
|
+
export declare class MeshNetworkAdapter extends NetworkAdapter {
|
|
23
|
+
private readonly _extensions;
|
|
24
|
+
/**
|
|
25
|
+
* Emits `ready` event. That signals to `Repo` that it can start using the adapter.
|
|
26
|
+
*/
|
|
27
|
+
ready(): void;
|
|
28
|
+
connect(peerId: PeerId): void;
|
|
29
|
+
send(message: Message): void;
|
|
30
|
+
disconnect(): void;
|
|
31
|
+
createExtension(): AutomergeReplicator;
|
|
32
|
+
}
|
|
19
33
|
export declare class AutomergeStorageAdapter extends StorageAdapter {
|
|
20
34
|
private readonly _directory;
|
|
21
35
|
constructor(_directory: Directory);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"automerge-host.d.ts","sourceRoot":"","sources":["../../../../src/automerge/automerge-host.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,IAAI,
|
|
1
|
+
{"version":3,"file":"automerge-host.d.ts","sourceRoot":"","sources":["../../../../src/automerge/automerge-host.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,IAAI,EACJ,cAAc,EACd,cAAc,EACd,KAAK,OAAO,EACZ,KAAK,MAAM,EACX,KAAK,KAAK,EACV,KAAK,UAAU,EAEhB,MAAM,gCAAgC,CAAC;AAExC,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAG9C,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,eAAe,EAAE,KAAK,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAErH,OAAO,EAAe,KAAK,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,+CAA+C,CAAC;AAGpF,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAO;IAC7B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAqB;IAClD,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA0B;IACzD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAiB;gBAE9B,gBAAgB,EAAE,SAAS;IAoBvC,IAAI,IAAI,IAAI,IAAI,CAEf;IAEK,KAAK;IAQX,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,MAAM,CAAC,gBAAgB,CAAC;IAI5D,eAAe,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,IAAI,CAAC;IAIxD,WAAW,IAAI,QAAQ;IAQvB,eAAe,IAAI,mBAAmB;CAGvC;AA0FD;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,cAAc;IACpD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAA+C;IAE3E;;OAEG;IACH,KAAK;IAQI,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI;IAI7B,IAAI,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;IAO5B,UAAU,IAAI,IAAI;IAI3B,eAAe,IAAI,mBAAmB;CA4CvC;AAED,qBAAa,uBAAwB,SAAQ,cAAc;IAC7C,OAAO,CAAC,QAAQ,CAAC,UAAU;gBAAV,UAAU,EAAE,SAAS;IAInC,IAAI,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAWtD,IAAI,CAAC,GAAG,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAStD,MAAM,CAAC,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAOtC,SAAS,CAAC,SAAS,EAAE,UAAU,GAAG,OAAO,CAAC,KAAK,EAAE,CAAC;IAkBlD,WAAW,CAAC,SAAS,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAahE,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,mBAAmB;CAG5B"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { AutomergeHost } from './automerge-host';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/automerge/index.ts"],"names":[],"mappings":"AAIA,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/automerge/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/echo-pipeline",
|
|
3
|
-
"version": "0.3.11-main.
|
|
3
|
+
"version": "0.3.11-main.d46c1ca",
|
|
4
4
|
"description": "ECHO database.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -36,38 +36,38 @@
|
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"crc-32": "^1.2.2",
|
|
39
|
-
"@dxos/async": "0.3.11-main.
|
|
40
|
-
"@dxos/automerge": "0.3.11-main.
|
|
41
|
-
"@dxos/
|
|
42
|
-
"@dxos/
|
|
43
|
-
"@dxos/
|
|
44
|
-
"@dxos/
|
|
45
|
-
"@dxos/
|
|
46
|
-
"@dxos/
|
|
47
|
-
"@dxos/
|
|
48
|
-
"@dxos/feed-store": "0.3.11-main.
|
|
49
|
-
"@dxos/hypercore": "0.3.11-main.
|
|
50
|
-
"@dxos/invariant": "0.3.11-main.
|
|
51
|
-
"@dxos/keyring": "0.3.11-main.
|
|
52
|
-
"@dxos/log": "0.3.11-main.
|
|
53
|
-
"@dxos/
|
|
54
|
-
"@dxos/
|
|
55
|
-
"@dxos/
|
|
56
|
-
"@dxos/
|
|
57
|
-
"@dxos/
|
|
58
|
-
"@dxos/protocols": "0.3.11-main.
|
|
59
|
-
"@dxos/
|
|
60
|
-
"@dxos/
|
|
61
|
-
"@dxos/teleport": "0.3.11-main.
|
|
62
|
-
"@dxos/teleport-extension-automerge-replicator": "0.3.11-main.
|
|
63
|
-
"@dxos/teleport-extension-object-sync": "0.3.11-main.
|
|
64
|
-
"@dxos/teleport-extension-gossip": "0.3.11-main.
|
|
65
|
-
"@dxos/
|
|
66
|
-
"@dxos/timeframe": "0.3.11-main.
|
|
67
|
-
"@dxos/
|
|
68
|
-
"@dxos/
|
|
69
|
-
"@dxos/typings": "0.3.11-main.
|
|
70
|
-
"@dxos/
|
|
39
|
+
"@dxos/async": "0.3.11-main.d46c1ca",
|
|
40
|
+
"@dxos/automerge": "0.3.11-main.d46c1ca",
|
|
41
|
+
"@dxos/context": "0.3.11-main.d46c1ca",
|
|
42
|
+
"@dxos/codec-protobuf": "0.3.11-main.d46c1ca",
|
|
43
|
+
"@dxos/credentials": "0.3.11-main.d46c1ca",
|
|
44
|
+
"@dxos/document-model": "0.3.11-main.d46c1ca",
|
|
45
|
+
"@dxos/crypto": "0.3.11-main.d46c1ca",
|
|
46
|
+
"@dxos/echo-db": "0.3.11-main.d46c1ca",
|
|
47
|
+
"@dxos/debug": "0.3.11-main.d46c1ca",
|
|
48
|
+
"@dxos/feed-store": "0.3.11-main.d46c1ca",
|
|
49
|
+
"@dxos/hypercore": "0.3.11-main.d46c1ca",
|
|
50
|
+
"@dxos/invariant": "0.3.11-main.d46c1ca",
|
|
51
|
+
"@dxos/keyring": "0.3.11-main.d46c1ca",
|
|
52
|
+
"@dxos/log": "0.3.11-main.d46c1ca",
|
|
53
|
+
"@dxos/messaging": "0.3.11-main.d46c1ca",
|
|
54
|
+
"@dxos/model-factory": "0.3.11-main.d46c1ca",
|
|
55
|
+
"@dxos/keys": "0.3.11-main.d46c1ca",
|
|
56
|
+
"@dxos/network-manager": "0.3.11-main.d46c1ca",
|
|
57
|
+
"@dxos/node-std": "0.3.11-main.d46c1ca",
|
|
58
|
+
"@dxos/protocols": "0.3.11-main.d46c1ca",
|
|
59
|
+
"@dxos/rpc": "0.3.11-main.d46c1ca",
|
|
60
|
+
"@dxos/random-access-storage": "0.3.11-main.d46c1ca",
|
|
61
|
+
"@dxos/teleport": "0.3.11-main.d46c1ca",
|
|
62
|
+
"@dxos/teleport-extension-automerge-replicator": "0.3.11-main.d46c1ca",
|
|
63
|
+
"@dxos/teleport-extension-object-sync": "0.3.11-main.d46c1ca",
|
|
64
|
+
"@dxos/teleport-extension-gossip": "0.3.11-main.d46c1ca",
|
|
65
|
+
"@dxos/text-model": "0.3.11-main.d46c1ca",
|
|
66
|
+
"@dxos/timeframe": "0.3.11-main.d46c1ca",
|
|
67
|
+
"@dxos/teleport-extension-replicator": "0.3.11-main.d46c1ca",
|
|
68
|
+
"@dxos/tracing": "0.3.11-main.d46c1ca",
|
|
69
|
+
"@dxos/typings": "0.3.11-main.d46c1ca",
|
|
70
|
+
"@dxos/util": "0.3.11-main.d46c1ca"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"fast-check": "~3.3.0",
|
|
@@ -4,16 +4,17 @@
|
|
|
4
4
|
|
|
5
5
|
import { randomBytes } from 'crypto';
|
|
6
6
|
import expect from 'expect';
|
|
7
|
+
import waitForExpect from 'wait-for-expect';
|
|
7
8
|
|
|
8
|
-
import {
|
|
9
|
+
import { asyncTimeout, sleep } from '@dxos/async';
|
|
9
10
|
import { type Message, NetworkAdapter, type PeerId, Repo } from '@dxos/automerge/automerge-repo';
|
|
10
11
|
import { invariant } from '@dxos/invariant';
|
|
11
|
-
import { log } from '@dxos/log';
|
|
12
12
|
import { StorageType, createStorage } from '@dxos/random-access-storage';
|
|
13
|
-
import {
|
|
13
|
+
import { TestBuilder as TeleportBuilder, TestPeer as TeleportPeer } from '@dxos/teleport/testing';
|
|
14
|
+
import { afterTest, describe, test } from '@dxos/test';
|
|
14
15
|
import { arrayToBuffer, bufferToArray } from '@dxos/util';
|
|
15
16
|
|
|
16
|
-
import { AutomergeHost, AutomergeStorageAdapter } from './automerge-host';
|
|
17
|
+
import { AutomergeHost, AutomergeStorageAdapter, MeshNetworkAdapter } from './automerge-host';
|
|
17
18
|
|
|
18
19
|
describe('AutomergeHost', () => {
|
|
19
20
|
test('can create documents', () => {
|
|
@@ -46,13 +47,12 @@ describe('AutomergeHost', () => {
|
|
|
46
47
|
});
|
|
47
48
|
|
|
48
49
|
test('basic networking', async () => {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const clientAdapter = new TestAdapter(context, 'client');
|
|
50
|
+
const hostAdapter: TestAdapter = new TestAdapter({
|
|
51
|
+
send: (message: Message) => clientAdapter.receive(message),
|
|
52
|
+
});
|
|
53
|
+
const clientAdapter: TestAdapter = new TestAdapter({
|
|
54
|
+
send: (message: Message) => hostAdapter.receive(message),
|
|
55
|
+
});
|
|
56
56
|
|
|
57
57
|
const host = new Repo({
|
|
58
58
|
network: [hostAdapter],
|
|
@@ -62,6 +62,8 @@ describe('AutomergeHost', () => {
|
|
|
62
62
|
});
|
|
63
63
|
hostAdapter.ready();
|
|
64
64
|
clientAdapter.ready();
|
|
65
|
+
hostAdapter.peerCandidate(clientAdapter.peerId!);
|
|
66
|
+
clientAdapter.peerCandidate(hostAdapter.peerId!);
|
|
65
67
|
|
|
66
68
|
const handle = host.create();
|
|
67
69
|
const text = 'Hello world';
|
|
@@ -70,11 +72,145 @@ describe('AutomergeHost', () => {
|
|
|
70
72
|
});
|
|
71
73
|
|
|
72
74
|
const docOnClient = client.find(handle.url);
|
|
73
|
-
await asyncTimeout(docOnClient.
|
|
74
|
-
expect(docOnClient.docSync().text).toEqual(text);
|
|
75
|
+
expect((await asyncTimeout(docOnClient.doc(), 1000)).text).toEqual(text);
|
|
75
76
|
});
|
|
76
77
|
|
|
77
|
-
test('
|
|
78
|
+
test('recovering from a lost connection', async () => {
|
|
79
|
+
let connectionState: 'on' | 'off' = 'on';
|
|
80
|
+
|
|
81
|
+
const hostAdapter: TestAdapter = new TestAdapter({
|
|
82
|
+
send: (message: Message) => connectionState === 'on' && sleep(10).then(() => clientAdapter.receive(message)),
|
|
83
|
+
});
|
|
84
|
+
const clientAdapter: TestAdapter = new TestAdapter({
|
|
85
|
+
send: (message: Message) => connectionState === 'on' && sleep(10).then(() => hostAdapter.receive(message)),
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
const host = new Repo({
|
|
89
|
+
network: [hostAdapter],
|
|
90
|
+
});
|
|
91
|
+
const client = new Repo({
|
|
92
|
+
network: [clientAdapter],
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
// Establish connection.
|
|
96
|
+
hostAdapter.ready();
|
|
97
|
+
clientAdapter.ready();
|
|
98
|
+
hostAdapter.peerCandidate(clientAdapter.peerId!);
|
|
99
|
+
clientAdapter.peerCandidate(hostAdapter.peerId!);
|
|
100
|
+
|
|
101
|
+
const handle = host.create();
|
|
102
|
+
const docOnClient = client.find(handle.url);
|
|
103
|
+
{
|
|
104
|
+
const sanityText = 'Hello world';
|
|
105
|
+
handle.change((doc: any) => {
|
|
106
|
+
doc.sanityText = sanityText;
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
expect((await asyncTimeout(docOnClient.doc(), 1000)).sanityText).toEqual(sanityText);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Disrupt connection.
|
|
113
|
+
const offlineText = 'This has been written while the connection was off';
|
|
114
|
+
{
|
|
115
|
+
connectionState = 'off';
|
|
116
|
+
|
|
117
|
+
handle.change((doc: any) => {
|
|
118
|
+
doc.offlineText = offlineText;
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
await sleep(100);
|
|
122
|
+
expect((await asyncTimeout(docOnClient.doc(), 1000)).offlineText).toBeUndefined();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Re-establish connection.
|
|
126
|
+
const onlineText = 'This has been written after the connection was re-established';
|
|
127
|
+
{
|
|
128
|
+
connectionState = 'on';
|
|
129
|
+
hostAdapter.peerDisconnected(clientAdapter.peerId!);
|
|
130
|
+
clientAdapter.peerDisconnected(hostAdapter.peerId!);
|
|
131
|
+
hostAdapter.peerCandidate(clientAdapter.peerId!);
|
|
132
|
+
clientAdapter.peerCandidate(hostAdapter.peerId!);
|
|
133
|
+
|
|
134
|
+
handle.change((doc: any) => {
|
|
135
|
+
doc.onlineText = onlineText;
|
|
136
|
+
});
|
|
137
|
+
await sleep(100);
|
|
138
|
+
expect((await asyncTimeout(docOnClient.doc(), 1000)).onlineText).toEqual(onlineText);
|
|
139
|
+
expect((await asyncTimeout(docOnClient.doc(), 1000)).offlineText).toEqual(offlineText);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
test('integration test with teleport', async () => {
|
|
144
|
+
const createAutomergeRepo = () => {
|
|
145
|
+
const meshAdapter = new MeshNetworkAdapter();
|
|
146
|
+
const repo = new Repo({
|
|
147
|
+
network: [meshAdapter],
|
|
148
|
+
});
|
|
149
|
+
meshAdapter.ready();
|
|
150
|
+
return { repo, meshAdapter };
|
|
151
|
+
};
|
|
152
|
+
const peer1 = createAutomergeRepo();
|
|
153
|
+
const peer2 = createAutomergeRepo();
|
|
154
|
+
const handle = peer1.repo.create();
|
|
155
|
+
|
|
156
|
+
const teleportBuilder = new TeleportBuilder();
|
|
157
|
+
afterTest(() => teleportBuilder.destroy());
|
|
158
|
+
|
|
159
|
+
const [teleportPeer1, teleportPeer2] = teleportBuilder.createPeers({ factory: () => new TeleportPeer() });
|
|
160
|
+
{
|
|
161
|
+
// Initiate connection.
|
|
162
|
+
const [connection1, connection2] = await teleportBuilder.connect(teleportPeer1, teleportPeer2);
|
|
163
|
+
connection1.teleport.addExtension('automerge', peer1.meshAdapter.createExtension());
|
|
164
|
+
connection2.teleport.addExtension('automerge', peer2.meshAdapter.createExtension());
|
|
165
|
+
|
|
166
|
+
// Test connection.
|
|
167
|
+
const text = 'Hello world';
|
|
168
|
+
handle.change((doc: any) => {
|
|
169
|
+
doc.text = text;
|
|
170
|
+
});
|
|
171
|
+
const docOnPeer2 = peer2.repo.find(handle.url);
|
|
172
|
+
await waitForExpect(async () => expect((await asyncTimeout(docOnPeer2.doc(), 1000)).text).toEqual(text), 1000);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const offlineText = 'This has been written while the connection was off';
|
|
176
|
+
{
|
|
177
|
+
// Disconnect peers.
|
|
178
|
+
await teleportBuilder.disconnect(teleportPeer1, teleportPeer2);
|
|
179
|
+
|
|
180
|
+
// Make offline changes.
|
|
181
|
+
const offlineText = 'This has been written while the connection was off';
|
|
182
|
+
handle.change((doc: any) => {
|
|
183
|
+
doc.offlineText = offlineText;
|
|
184
|
+
});
|
|
185
|
+
const docOnPeer2 = peer2.repo.find(handle.url);
|
|
186
|
+
await sleep(100);
|
|
187
|
+
expect((await asyncTimeout(docOnPeer2.doc(), 1000)).offlineText).toBeUndefined();
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
{
|
|
191
|
+
// Reconnect peers.
|
|
192
|
+
const [connection1, connection2] = await teleportBuilder.connect(teleportPeer1, teleportPeer2);
|
|
193
|
+
connection1.teleport.addExtension('automerge', peer1.meshAdapter.createExtension());
|
|
194
|
+
connection2.teleport.addExtension('automerge', peer2.meshAdapter.createExtension());
|
|
195
|
+
|
|
196
|
+
// Wait for offline changes to be synced.
|
|
197
|
+
const docOnPeer2 = peer2.repo.find(handle.url);
|
|
198
|
+
await waitForExpect(
|
|
199
|
+
async () => expect((await asyncTimeout(docOnPeer2.doc(), 1000)).offlineText).toEqual(offlineText),
|
|
200
|
+
1000,
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
// Test connection.
|
|
204
|
+
const onlineText = 'This has been written after the connection was re-established';
|
|
205
|
+
handle.change((doc: any) => {
|
|
206
|
+
doc.onlineText = onlineText;
|
|
207
|
+
});
|
|
208
|
+
await waitForExpect(
|
|
209
|
+
async () => expect((await asyncTimeout(docOnPeer2.doc(), 1000)).onlineText).toEqual(onlineText),
|
|
210
|
+
1000,
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
});
|
|
78
214
|
|
|
79
215
|
describe('storage', () => {
|
|
80
216
|
test('load range on node', async () => {
|
|
@@ -103,10 +239,8 @@ describe('AutomergeHost', () => {
|
|
|
103
239
|
});
|
|
104
240
|
});
|
|
105
241
|
|
|
106
|
-
type Context = { client: Trigger<TestAdapter>; host: Trigger<TestAdapter> };
|
|
107
|
-
|
|
108
242
|
class TestAdapter extends NetworkAdapter {
|
|
109
|
-
constructor(
|
|
243
|
+
constructor(private readonly _params: { send: (message: Message) => void }) {
|
|
110
244
|
super();
|
|
111
245
|
}
|
|
112
246
|
|
|
@@ -118,32 +252,24 @@ class TestAdapter extends NetworkAdapter {
|
|
|
118
252
|
|
|
119
253
|
override connect(peerId: PeerId) {
|
|
120
254
|
this.peerId = peerId;
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
peerCandidate(peerId: PeerId) {
|
|
258
|
+
invariant(peerId, 'PeerId is required');
|
|
259
|
+
this.emit('peer-candidate', { peerId });
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
peerDisconnected(peerId: PeerId) {
|
|
263
|
+
invariant(peerId, 'PeerId is required');
|
|
264
|
+
this.emit('peer-disconnected', { peerId });
|
|
131
265
|
}
|
|
132
266
|
|
|
133
267
|
override send(message: Message) {
|
|
134
|
-
this.
|
|
135
|
-
.wait()
|
|
136
|
-
.then((adapter) => {
|
|
137
|
-
adapter.receive(message);
|
|
138
|
-
})
|
|
139
|
-
.catch((error) => {
|
|
140
|
-
log.catch(error);
|
|
141
|
-
});
|
|
268
|
+
this._params.send(message);
|
|
142
269
|
}
|
|
143
270
|
|
|
144
271
|
override disconnect() {
|
|
145
272
|
this.peerId = undefined;
|
|
146
|
-
this.context[this.role].reset();
|
|
147
273
|
}
|
|
148
274
|
|
|
149
275
|
receive(message: Message) {
|
|
@@ -172,7 +172,7 @@ class LocalHostNetworkAdapter extends NetworkAdapter {
|
|
|
172
172
|
/**
|
|
173
173
|
* Used to replicate with other peers over the network.
|
|
174
174
|
*/
|
|
175
|
-
class MeshNetworkAdapter extends NetworkAdapter {
|
|
175
|
+
export class MeshNetworkAdapter extends NetworkAdapter {
|
|
176
176
|
private readonly _extensions: Map<string, AutomergeReplicator> = new Map();
|
|
177
177
|
|
|
178
178
|
/**
|
|
@@ -233,10 +233,13 @@ class MeshNetworkAdapter extends NetworkAdapter {
|
|
|
233
233
|
this.emit('message', message);
|
|
234
234
|
},
|
|
235
235
|
onClose: async () => {
|
|
236
|
-
peerInfo
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
236
|
+
if (!peerInfo) {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
this.emit('peer-disconnected', {
|
|
240
|
+
peerId: peerInfo.id as PeerId,
|
|
241
|
+
});
|
|
242
|
+
this._extensions.delete(peerInfo.id);
|
|
240
243
|
},
|
|
241
244
|
},
|
|
242
245
|
);
|
package/src/automerge/index.ts
CHANGED