@dxos/echo-pipeline 0.8.2-main.fbd8ed0 → 0.8.2-staging.7ac8446
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-TPEBUDNJ.mjs → chunk-32WDI3LB.mjs} +9 -9
- package/dist/lib/browser/{chunk-TPEBUDNJ.mjs.map → chunk-32WDI3LB.mjs.map} +3 -3
- package/dist/lib/browser/index.mjs +156 -157
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +12 -11
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node/{chunk-QD3U65NM.cjs → chunk-TC2PRBEU.cjs} +12 -12
- package/dist/lib/node/{chunk-QD3U65NM.cjs.map → chunk-TC2PRBEU.cjs.map} +2 -2
- package/dist/lib/node/index.cjs +180 -182
- package/dist/lib/node/index.cjs.map +3 -3
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +21 -20
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/lib/node-esm/{chunk-S5YERQ4D.mjs → chunk-UKOLB3LW.mjs} +9 -9
- package/dist/lib/node-esm/{chunk-S5YERQ4D.mjs.map → chunk-UKOLB3LW.mjs.map} +3 -3
- package/dist/lib/node-esm/index.mjs +156 -157
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +12 -11
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/types/src/automerge/automerge-host.d.ts +2 -5
- package/dist/types/src/automerge/automerge-host.d.ts.map +1 -1
- package/dist/types/src/automerge/collection-synchronizer.d.ts +1 -1
- package/dist/types/src/automerge/collection-synchronizer.d.ts.map +1 -1
- package/dist/types/src/automerge/echo-data-monitor.d.ts +6 -6
- package/dist/types/src/automerge/echo-data-monitor.d.ts.map +1 -1
- package/dist/types/src/automerge/echo-network-adapter.d.ts +1 -4
- package/dist/types/src/automerge/echo-network-adapter.d.ts.map +1 -1
- package/dist/types/src/automerge/heads-store.d.ts +2 -2
- package/dist/types/src/automerge/heads-store.d.ts.map +1 -1
- package/dist/types/src/automerge/leveldb-storage-adapter.d.ts +1 -1
- package/dist/types/src/automerge/leveldb-storage-adapter.d.ts.map +1 -1
- package/dist/types/src/automerge/mesh-echo-replicator-connection.d.ts.map +1 -1
- package/dist/types/src/automerge/network-protocol.d.ts +1 -1
- package/dist/types/src/automerge/network-protocol.d.ts.map +1 -1
- package/dist/types/src/automerge/space-collection.d.ts +1 -1
- package/dist/types/src/automerge/space-collection.d.ts.map +1 -1
- package/dist/types/src/common/feeds.d.ts.map +1 -1
- package/dist/types/src/common/space-id.d.ts.map +1 -1
- package/dist/types/src/db-host/automerge-metrics.d.ts +1 -1
- package/dist/types/src/db-host/automerge-metrics.d.ts.map +1 -1
- package/dist/types/src/db-host/data-service.d.ts.map +1 -1
- package/dist/types/src/db-host/database-root.d.ts +3 -3
- package/dist/types/src/db-host/database-root.d.ts.map +1 -1
- package/dist/types/src/db-host/documents-iterator.d.ts.map +1 -1
- package/dist/types/src/db-host/documents-synchronizer.d.ts +2 -2
- package/dist/types/src/db-host/documents-synchronizer.d.ts.map +1 -1
- package/dist/types/src/db-host/echo-host.d.ts +1 -1
- package/dist/types/src/db-host/echo-host.d.ts.map +1 -1
- package/dist/types/src/db-host/query-service.d.ts.map +1 -1
- package/dist/types/src/db-host/query-state.d.ts.map +1 -1
- package/dist/types/src/db-host/space-state-manager.d.ts +1 -1
- package/dist/types/src/db-host/space-state-manager.d.ts.map +1 -1
- package/dist/types/src/edge/echo-edge-replicator.d.ts.map +1 -1
- package/dist/types/src/metadata/metadata-store.d.ts.map +1 -1
- package/dist/types/src/pipeline/message-selector.d.ts.map +1 -1
- package/dist/types/src/pipeline/timeframe-clock.d.ts.map +1 -1
- package/dist/types/src/space/space-manager.d.ts.map +1 -1
- package/dist/types/src/testing/change-metadata.d.ts.map +1 -1
- package/dist/types/src/testing/test-agent-builder.d.ts.map +1 -1
- package/dist/types/src/testing/test-network-adapter.d.ts +2 -3
- package/dist/types/src/testing/test-network-adapter.d.ts.map +1 -1
- package/dist/types/src/util.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +34 -35
- package/src/automerge/automerge-host.test.ts +7 -7
- package/src/automerge/automerge-host.ts +23 -30
- package/src/automerge/automerge-repo.test.ts +65 -65
- package/src/automerge/collection-synchronizer.test.ts +1 -1
- package/src/automerge/collection-synchronizer.ts +2 -3
- package/src/automerge/echo-data-monitor.ts +8 -9
- package/src/automerge/echo-network-adapter.test.ts +1 -1
- package/src/automerge/echo-network-adapter.ts +6 -13
- package/src/automerge/heads-store.ts +2 -3
- package/src/automerge/leveldb-storage-adapter.ts +1 -1
- package/src/automerge/mesh-echo-replicator-connection.ts +2 -3
- package/src/automerge/network-protocol.ts +1 -2
- package/src/automerge/space-collection.ts +1 -2
- package/src/db-host/automerge-metrics.ts +1 -2
- package/src/db-host/data-service.ts +1 -2
- package/src/db-host/database-root.ts +16 -12
- package/src/db-host/documents-iterator.ts +3 -4
- package/src/db-host/documents-synchronizer.test.ts +2 -2
- package/src/db-host/documents-synchronizer.ts +9 -11
- package/src/db-host/echo-host.ts +3 -6
- package/src/db-host/query-service.ts +5 -6
- package/src/db-host/query-state.ts +13 -20
- package/src/db-host/space-state-manager.ts +1 -1
- package/src/edge/echo-edge-replicator.test.ts +3 -3
- package/src/edge/echo-edge-replicator.ts +1 -2
- package/src/space/space-manager.ts +1 -2
- package/src/testing/test-network-adapter.ts +5 -8
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { onTestFinished, describe, expect, test } from 'vitest';
|
|
6
|
+
|
|
7
|
+
import { asyncTimeout, sleep } from '@dxos/async';
|
|
5
8
|
import {
|
|
6
9
|
change,
|
|
7
10
|
clone,
|
|
@@ -13,7 +16,7 @@ import {
|
|
|
13
16
|
next as A,
|
|
14
17
|
save,
|
|
15
18
|
saveSince,
|
|
16
|
-
} from '@automerge/automerge';
|
|
19
|
+
} from '@dxos/automerge/automerge';
|
|
17
20
|
import {
|
|
18
21
|
type AutomergeUrl,
|
|
19
22
|
type DocHandle,
|
|
@@ -25,10 +28,7 @@ import {
|
|
|
25
28
|
type PeerId,
|
|
26
29
|
Repo,
|
|
27
30
|
type SharePolicy,
|
|
28
|
-
} from '@automerge/automerge-repo';
|
|
29
|
-
import { onTestFinished, describe, expect, test } from 'vitest';
|
|
30
|
-
|
|
31
|
-
import { asyncTimeout, sleep } from '@dxos/async';
|
|
31
|
+
} from '@dxos/automerge/automerge-repo';
|
|
32
32
|
import { randomBytes } from '@dxos/crypto';
|
|
33
33
|
import { PublicKey } from '@dxos/keys';
|
|
34
34
|
import { createTestLevel } from '@dxos/kv-store/testing';
|
|
@@ -36,7 +36,6 @@ import { TestBuilder as TeleportBuilder, TestPeer as TeleportPeer } from '@dxos/
|
|
|
36
36
|
import { openAndClose } from '@dxos/test-utils';
|
|
37
37
|
import { isNonNullable, range } from '@dxos/util';
|
|
38
38
|
|
|
39
|
-
import { FIND_PARAMS } from './automerge-host';
|
|
40
39
|
import { EchoNetworkAdapter } from './echo-network-adapter';
|
|
41
40
|
import { LevelDBStorageAdapter } from './leveldb-storage-adapter';
|
|
42
41
|
import { MeshEchoReplicator } from './mesh-echo-replicator';
|
|
@@ -52,7 +51,7 @@ describe('AutomergeRepo', () => {
|
|
|
52
51
|
let valueDuringChange: string | undefined;
|
|
53
52
|
|
|
54
53
|
handle.addListener('change', (doc) => {
|
|
55
|
-
valueDuringChange = handle.
|
|
54
|
+
valueDuringChange = handle.docSync()!.field;
|
|
56
55
|
});
|
|
57
56
|
|
|
58
57
|
handle.change((doc: any) => {
|
|
@@ -116,7 +115,7 @@ describe('AutomergeRepo', () => {
|
|
|
116
115
|
const [host] = repos;
|
|
117
116
|
await connectAdapters(adapters);
|
|
118
117
|
const url = 'automerge:3JN8F3Z4dUWEEKKFN7WE9gEGvVUT';
|
|
119
|
-
const handle =
|
|
118
|
+
const handle = host.find(url as AutomergeUrl);
|
|
120
119
|
await handle.whenReady(['requesting']);
|
|
121
120
|
});
|
|
122
121
|
|
|
@@ -133,7 +132,7 @@ describe('AutomergeRepo', () => {
|
|
|
133
132
|
|
|
134
133
|
{
|
|
135
134
|
const repo = new Repo({ network: [], storage });
|
|
136
|
-
const handle =
|
|
135
|
+
const handle = repo.find(url as AutomergeUrl);
|
|
137
136
|
|
|
138
137
|
let requestingState = false;
|
|
139
138
|
queueMicrotask(async () => {
|
|
@@ -158,7 +157,8 @@ describe('AutomergeRepo', () => {
|
|
|
158
157
|
doc.text = text;
|
|
159
158
|
});
|
|
160
159
|
|
|
161
|
-
|
|
160
|
+
const docOnClient = client.find<any>(handle.url);
|
|
161
|
+
expect((await asyncTimeout(docOnClient.doc(), 1000))!.text).to.equal(text);
|
|
162
162
|
});
|
|
163
163
|
|
|
164
164
|
test('share policy gets enabled afterwards', async () => {
|
|
@@ -177,13 +177,16 @@ describe('AutomergeRepo', () => {
|
|
|
177
177
|
});
|
|
178
178
|
|
|
179
179
|
{
|
|
180
|
-
|
|
180
|
+
const docOnClient = client.find(handle.url);
|
|
181
|
+
await asyncTimeout(docOnClient.whenReady(['unavailable']), 1000);
|
|
181
182
|
}
|
|
182
183
|
|
|
183
184
|
sharePolicy = true;
|
|
184
185
|
|
|
185
186
|
{
|
|
186
|
-
|
|
187
|
+
const docOnClient = client.find(handle.url);
|
|
188
|
+
// TODO(mykola): We expect the document to be available here, but it's not.
|
|
189
|
+
await asyncTimeout(docOnClient.whenReady(['unavailable']), 1000);
|
|
187
190
|
}
|
|
188
191
|
});
|
|
189
192
|
|
|
@@ -203,26 +206,26 @@ describe('AutomergeRepo', () => {
|
|
|
203
206
|
|
|
204
207
|
const firstHandle = host.create();
|
|
205
208
|
firstHandle.change((doc: any) => (doc.text = 'Hello world'));
|
|
206
|
-
await host.find(firstHandle.url);
|
|
209
|
+
await host.find(firstHandle.url).whenReady();
|
|
207
210
|
allowedDocs.push(firstHandle.documentId);
|
|
208
211
|
|
|
209
212
|
await connectAdapters(adapters);
|
|
210
213
|
|
|
211
214
|
{
|
|
212
|
-
const firstDocOnClient =
|
|
215
|
+
const firstDocOnClient = client.find<any>(firstHandle.url);
|
|
213
216
|
await asyncTimeout(firstDocOnClient.whenReady(), 1000);
|
|
214
|
-
expect(firstDocOnClient.
|
|
217
|
+
expect(firstDocOnClient.docSync()!.text).to.equal('Hello world');
|
|
215
218
|
}
|
|
216
219
|
|
|
217
220
|
const secondHandle = host.create();
|
|
218
221
|
secondHandle.change((doc: any) => (doc.text = 'Hello world'));
|
|
219
|
-
await host.find(secondHandle.url);
|
|
222
|
+
await host.find(secondHandle.url).whenReady();
|
|
220
223
|
allowedDocs.push(secondHandle.documentId);
|
|
221
224
|
|
|
222
225
|
{
|
|
223
|
-
const secondDocOnClient =
|
|
226
|
+
const secondDocOnClient = client.find<any>(secondHandle.url);
|
|
224
227
|
await asyncTimeout(secondDocOnClient.whenReady(), 1000);
|
|
225
|
-
expect(secondDocOnClient.
|
|
228
|
+
expect(secondDocOnClient.docSync()!.text).to.equal('Hello world');
|
|
226
229
|
}
|
|
227
230
|
});
|
|
228
231
|
|
|
@@ -236,15 +239,14 @@ describe('AutomergeRepo', () => {
|
|
|
236
239
|
await connectAdapters(adapters);
|
|
237
240
|
|
|
238
241
|
const handle = host.create();
|
|
239
|
-
const docOnClient =
|
|
242
|
+
const docOnClient = client.find<any>(handle.url);
|
|
240
243
|
{
|
|
241
244
|
const sanityText = 'Hello world';
|
|
242
245
|
handle.change((doc: any) => {
|
|
243
246
|
doc.sanityText = sanityText;
|
|
244
247
|
});
|
|
245
|
-
await asyncTimeout(docOnClient.whenReady(), 1000);
|
|
246
248
|
|
|
247
|
-
expect(docOnClient.doc()
|
|
249
|
+
expect((await asyncTimeout(docOnClient.doc(), 1000))!.sanityText).to.equal(sanityText);
|
|
248
250
|
}
|
|
249
251
|
|
|
250
252
|
// Disrupt connection.
|
|
@@ -257,8 +259,7 @@ describe('AutomergeRepo', () => {
|
|
|
257
259
|
});
|
|
258
260
|
|
|
259
261
|
await sleep(100);
|
|
260
|
-
await asyncTimeout(docOnClient.
|
|
261
|
-
expect(docOnClient.doc().offlineText).to.be.undefined;
|
|
262
|
+
expect((await asyncTimeout(docOnClient.doc(), 1000))!.offlineText).to.be.undefined;
|
|
262
263
|
}
|
|
263
264
|
|
|
264
265
|
// Re-establish connection.
|
|
@@ -271,9 +272,8 @@ describe('AutomergeRepo', () => {
|
|
|
271
272
|
doc.onlineText = onlineText;
|
|
272
273
|
});
|
|
273
274
|
await sleep(100);
|
|
274
|
-
await asyncTimeout(docOnClient.
|
|
275
|
-
expect(docOnClient.doc()
|
|
276
|
-
expect(docOnClient.doc().offlineText).to.equal(offlineText);
|
|
275
|
+
expect((await asyncTimeout(docOnClient.doc(), 1000))!.onlineText).to.equal(onlineText);
|
|
276
|
+
expect((await asyncTimeout(docOnClient.doc(), 1000))!.offlineText).to.equal(offlineText);
|
|
277
277
|
}
|
|
278
278
|
});
|
|
279
279
|
|
|
@@ -297,9 +297,9 @@ describe('AutomergeRepo', () => {
|
|
|
297
297
|
|
|
298
298
|
// If we wait here for replication to finish naturally, the test will pass.
|
|
299
299
|
|
|
300
|
-
const docD =
|
|
300
|
+
const docD = repoD.find(docA.url);
|
|
301
301
|
|
|
302
|
-
await
|
|
302
|
+
await docD.whenReady();
|
|
303
303
|
});
|
|
304
304
|
|
|
305
305
|
test('replication though a 3 peer chain', async () => {
|
|
@@ -319,9 +319,9 @@ describe('AutomergeRepo', () => {
|
|
|
319
319
|
doc.text = 'Hello world';
|
|
320
320
|
});
|
|
321
321
|
|
|
322
|
-
const _ = repoB.find(docA.url
|
|
323
|
-
const docC =
|
|
324
|
-
await
|
|
322
|
+
const _ = repoB.find(docA.url);
|
|
323
|
+
const docC = repoC.find(docA.url);
|
|
324
|
+
await docC.whenReady();
|
|
325
325
|
});
|
|
326
326
|
|
|
327
327
|
test('replicate document after request', async () => {
|
|
@@ -338,7 +338,7 @@ describe('AutomergeRepo', () => {
|
|
|
338
338
|
doc.text = 'Hello world';
|
|
339
339
|
});
|
|
340
340
|
|
|
341
|
-
const docB =
|
|
341
|
+
const docB = client.find(docA.url);
|
|
342
342
|
|
|
343
343
|
// Request document from repoB.
|
|
344
344
|
await asyncTimeout(docB.whenReady([unavailable]), 1_000);
|
|
@@ -373,12 +373,11 @@ describe('AutomergeRepo', () => {
|
|
|
373
373
|
await connectAdapters(adapters);
|
|
374
374
|
|
|
375
375
|
// Load doc on peer1
|
|
376
|
-
const hostHandle =
|
|
376
|
+
const hostHandle = peer1.find<any>(url as AutomergeUrl);
|
|
377
377
|
|
|
378
378
|
// Doc should be pushed to peer2
|
|
379
|
-
await hostHandle.
|
|
380
|
-
await expect.poll(() => hostHandle.
|
|
381
|
-
await expect.poll(() => peer2.handles[hostHandle.documentId].doc()).toEqual(hostHandle.doc());
|
|
379
|
+
await expect.poll(() => hostHandle.docSync()!.text).not.toBeUndefined();
|
|
380
|
+
await expect.poll(() => peer2.handles[hostHandle.documentId].docSync()).toEqual(hostHandle.docSync());
|
|
382
381
|
});
|
|
383
382
|
|
|
384
383
|
test('client cold-starts and syncs doc from a Repo', async () => {
|
|
@@ -391,8 +390,8 @@ describe('AutomergeRepo', () => {
|
|
|
391
390
|
};
|
|
392
391
|
|
|
393
392
|
// Sync handshake.
|
|
394
|
-
let syncedHeads = getHeads(serverHandle.
|
|
395
|
-
receiveByClient(save(serverHandle.
|
|
393
|
+
let syncedHeads = getHeads(serverHandle.docSync()!);
|
|
394
|
+
receiveByClient(save(serverHandle.docSync()!));
|
|
396
395
|
|
|
397
396
|
serverHandle.on('change', ({ doc }) => {
|
|
398
397
|
// Note: This is mock of a sync protocol between client and server.
|
|
@@ -421,7 +420,7 @@ describe('AutomergeRepo', () => {
|
|
|
421
420
|
test('client creates doc and syncs with a Repo', async () => {
|
|
422
421
|
const repo = new Repo({ network: [] });
|
|
423
422
|
const receiveByServer = async (blob: Uint8Array, docId: DocumentId) => {
|
|
424
|
-
const serverHandle =
|
|
423
|
+
const serverHandle = repo.find(docId);
|
|
425
424
|
serverHandle.update((doc) => {
|
|
426
425
|
return A.loadIncremental(doc, blob);
|
|
427
426
|
});
|
|
@@ -446,8 +445,8 @@ describe('AutomergeRepo', () => {
|
|
|
446
445
|
});
|
|
447
446
|
await sendDoc(clientDoc);
|
|
448
447
|
|
|
449
|
-
|
|
450
|
-
expect(
|
|
448
|
+
await repo.find(documentId).whenReady();
|
|
449
|
+
expect(repo.find<any>(documentId).docSync()!.field).to.deep.equal(value);
|
|
451
450
|
}
|
|
452
451
|
});
|
|
453
452
|
|
|
@@ -457,7 +456,7 @@ describe('AutomergeRepo', () => {
|
|
|
457
456
|
await connectAdapters(adapters);
|
|
458
457
|
|
|
459
458
|
const handleA = repoA.create<any>();
|
|
460
|
-
const handleB =
|
|
459
|
+
const handleB = repoB.find<any>(handleA.url);
|
|
461
460
|
|
|
462
461
|
const text = 'Hello world';
|
|
463
462
|
handleA.update((doc: any) => {
|
|
@@ -466,11 +465,10 @@ describe('AutomergeRepo', () => {
|
|
|
466
465
|
});
|
|
467
466
|
});
|
|
468
467
|
|
|
469
|
-
expect(handleA.
|
|
468
|
+
expect(handleA.docSync()!.text).to.equal(text);
|
|
470
469
|
|
|
471
|
-
await sleep(100);
|
|
472
470
|
await asyncTimeout(handleB.whenReady(), 1000);
|
|
473
|
-
expect(handleB.
|
|
471
|
+
expect(handleB.docSync()!.text).to.equal(text);
|
|
474
472
|
});
|
|
475
473
|
});
|
|
476
474
|
|
|
@@ -495,10 +493,11 @@ describe('AutomergeRepo', () => {
|
|
|
495
493
|
await expect
|
|
496
494
|
.poll(
|
|
497
495
|
async () => {
|
|
498
|
-
const docOnPeer2 =
|
|
499
|
-
|
|
496
|
+
const docOnPeer2 = peer2.repo.find<any>(handle.url);
|
|
497
|
+
const doc = await asyncTimeout(docOnPeer2.doc(), 1000);
|
|
498
|
+
return doc!.text;
|
|
500
499
|
},
|
|
501
|
-
{ timeout:
|
|
500
|
+
{ timeout: 1_000 },
|
|
502
501
|
)
|
|
503
502
|
.toEqual(text);
|
|
504
503
|
}
|
|
@@ -511,18 +510,17 @@ describe('AutomergeRepo', () => {
|
|
|
511
510
|
handle.change((doc: any) => {
|
|
512
511
|
doc.offlineText = offlineText;
|
|
513
512
|
});
|
|
514
|
-
const docOnPeer2 =
|
|
513
|
+
const docOnPeer2 = peer2.repo.find<any>(handle.url);
|
|
515
514
|
await sleep(100);
|
|
516
|
-
await asyncTimeout(docOnPeer2.
|
|
517
|
-
expect(docOnPeer2.doc()!.offlineText).to.be.undefined;
|
|
515
|
+
expect((await asyncTimeout(docOnPeer2.doc(), 1000))!.offlineText).to.be.undefined;
|
|
518
516
|
}
|
|
519
517
|
|
|
520
518
|
{
|
|
521
519
|
// Wait for offline changes to be synced after reconnect.
|
|
522
|
-
const docOnPeer2 =
|
|
520
|
+
const docOnPeer2 = peer2.repo.find<any>(handle.url);
|
|
523
521
|
await docChangeAfterAction(docOnPeer2, () => connectPeers(spaceKey, teleportBuilder, peer1, peer2));
|
|
524
522
|
await docOnPeer2.whenReady();
|
|
525
|
-
expect(docOnPeer2.doc()!.offlineText).to.eq(offlineText);
|
|
523
|
+
expect((await asyncTimeout(docOnPeer2.doc(), 1000))!.offlineText).to.eq(offlineText);
|
|
526
524
|
|
|
527
525
|
// Test connection.
|
|
528
526
|
const onlineText = 'This has been written after the connection was re-established';
|
|
@@ -532,7 +530,7 @@ describe('AutomergeRepo', () => {
|
|
|
532
530
|
});
|
|
533
531
|
});
|
|
534
532
|
await docOnPeer2.whenReady();
|
|
535
|
-
expect(docOnPeer2.doc()!.onlineText).to.eq(onlineText);
|
|
533
|
+
expect((await asyncTimeout(docOnPeer2.doc(), 1000))!.onlineText).to.eq(onlineText);
|
|
536
534
|
}
|
|
537
535
|
});
|
|
538
536
|
|
|
@@ -558,11 +556,11 @@ describe('AutomergeRepo', () => {
|
|
|
558
556
|
});
|
|
559
557
|
await connectPeers(spaceKey, teleportBuilder, peerWithDocs.peer, peer2);
|
|
560
558
|
|
|
561
|
-
const shouldNotFindDoc =
|
|
562
|
-
const shouldFindDoc =
|
|
559
|
+
const shouldNotFindDoc = peer2.repo.find(docNotInRemoteCollection.url);
|
|
560
|
+
const shouldFindDoc = peer2.repo.find(docInRemoteCollection.url);
|
|
563
561
|
await shouldFindDoc.whenReady();
|
|
564
|
-
expect(shouldFindDoc.
|
|
565
|
-
await
|
|
562
|
+
expect(shouldFindDoc.docSync()).to.deep.eq(docInRemoteCollection.docSync());
|
|
563
|
+
await shouldNotFindDoc.whenReady(['unavailable']);
|
|
566
564
|
});
|
|
567
565
|
|
|
568
566
|
/**
|
|
@@ -592,12 +590,12 @@ describe('AutomergeRepo', () => {
|
|
|
592
590
|
await connectPeers(spaceKey, teleportBuilder, peerWithDocs.peer, peer2);
|
|
593
591
|
await connectPeers(anotherSpaceKey, teleportBuilder, peer2, peerFromAnotherSpace);
|
|
594
592
|
|
|
595
|
-
const loadedDocument =
|
|
596
|
-
await
|
|
593
|
+
const loadedDocument = peer2.repo.find(document.url);
|
|
594
|
+
await loadedDocument.whenReady();
|
|
597
595
|
|
|
598
596
|
await sleep(200);
|
|
599
|
-
const doc =
|
|
600
|
-
await
|
|
597
|
+
const doc = peerFromAnotherSpace.repo.find(document.url);
|
|
598
|
+
await doc.whenReady(['unavailable']);
|
|
601
599
|
});
|
|
602
600
|
|
|
603
601
|
test('collection-sync with chain of peers', async () => {
|
|
@@ -626,12 +624,12 @@ describe('AutomergeRepo', () => {
|
|
|
626
624
|
await connectPeers(spaceKey, teleportBuilder, peerWithDocs.peer, peer2);
|
|
627
625
|
await connectPeers(spaceKey, teleportBuilder, peer2, peer3);
|
|
628
626
|
|
|
629
|
-
const loadedDocument =
|
|
627
|
+
const loadedDocument = peer2.repo.find(document.url);
|
|
630
628
|
await loadedDocument.whenReady();
|
|
631
629
|
|
|
632
|
-
const doc =
|
|
630
|
+
const doc = peer3.repo.find(document.url);
|
|
633
631
|
await doc.whenReady();
|
|
634
|
-
expect(doc.
|
|
632
|
+
expect(doc.docSync()).to.deep.eq(document.docSync());
|
|
635
633
|
});
|
|
636
634
|
});
|
|
637
635
|
|
|
@@ -694,6 +692,8 @@ const createRepoTopology = async <Peers extends string[], Peer extends string =
|
|
|
694
692
|
|
|
695
693
|
const connectAdapters = async (pairs: [TestAdapter, TestAdapter][], options?: { noEmitPeerCandidate?: boolean }) => {
|
|
696
694
|
for (const pair of pairs) {
|
|
695
|
+
pair[0].ready();
|
|
696
|
+
pair[1].ready();
|
|
697
697
|
await pair[0].onConnect.wait();
|
|
698
698
|
await pair[1].onConnect.wait();
|
|
699
699
|
if (!options?.noEmitPeerCandidate) {
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import type { PeerId } from '@automerge/automerge-repo';
|
|
6
5
|
import { onTestFinished, describe, expect, test } from 'vitest';
|
|
7
6
|
|
|
8
7
|
import { sleep } from '@dxos/async';
|
|
8
|
+
import type { PeerId } from '@dxos/automerge/automerge-repo';
|
|
9
9
|
|
|
10
10
|
import { CollectionSynchronizer, diffCollectionState, type CollectionState } from './collection-synchronizer';
|
|
11
11
|
|
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { next as am } from '@automerge/automerge';
|
|
6
|
-
import type { DocumentId, PeerId } from '@automerge/automerge-repo';
|
|
7
|
-
|
|
8
5
|
import { asyncReturn, Event, scheduleTask, scheduleTaskInterval } from '@dxos/async';
|
|
6
|
+
import { next as am } from '@dxos/automerge/automerge';
|
|
7
|
+
import type { DocumentId, PeerId } from '@dxos/automerge/automerge-repo';
|
|
9
8
|
import { Resource, type Context } from '@dxos/context';
|
|
10
9
|
import { log } from '@dxos/log';
|
|
11
10
|
import { trace } from '@dxos/tracing';
|
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type Message } from '@automerge/automerge-repo';
|
|
6
|
-
|
|
5
|
+
import { type Message } from '@dxos/automerge/automerge-repo';
|
|
7
6
|
import { type TimeAware, trace } from '@dxos/tracing';
|
|
8
7
|
import { CircularBuffer, mapValues, SlidingWindowSummary, type SlidingWindowSummaryConfig } from '@dxos/util';
|
|
9
8
|
|
|
@@ -27,7 +26,7 @@ export class EchoDataMonitor implements StorageAdapterDataMonitor, NetworkDataMo
|
|
|
27
26
|
private readonly _localTimeSeries = createLocalTimeSeries();
|
|
28
27
|
private readonly _storageAverages = createStorageAverages();
|
|
29
28
|
private readonly _replicationAverages = createNetworkAverages();
|
|
30
|
-
private readonly
|
|
29
|
+
private readonly _sizeByMessageType: { [type: string]: SlidingWindowSummary } = {};
|
|
31
30
|
private readonly _lastReceivedMessages = new CircularBuffer<StoredMessage>(100);
|
|
32
31
|
private readonly _lastSentMessages = new CircularBuffer<StoredMessage>(100);
|
|
33
32
|
|
|
@@ -69,8 +68,8 @@ export class EchoDataMonitor implements StorageAdapterDataMonitor, NetworkDataMo
|
|
|
69
68
|
countPerSecond: this._replicationAverages.sentPerSecond.average(),
|
|
70
69
|
failedPerSecond: this._replicationAverages.sendsFailedPerSecond.average(),
|
|
71
70
|
},
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
countByMessageType: this._computeMessageHistogram('type'),
|
|
72
|
+
avgSizeByMessageType: mapValues(this._sizeByMessageType, (summary) => summary.average()),
|
|
74
73
|
},
|
|
75
74
|
};
|
|
76
75
|
}
|
|
@@ -226,7 +225,7 @@ export class EchoDataMonitor implements StorageAdapterDataMonitor, NetworkDataMo
|
|
|
226
225
|
}
|
|
227
226
|
|
|
228
227
|
private _getStatsForType(message: Message) {
|
|
229
|
-
const messageSize = (this.
|
|
228
|
+
const messageSize = (this._sizeByMessageType[message.type] ??= createSlidingWindow());
|
|
230
229
|
const messageCounts = (this._activeCounters.byType[message.type] ??= createMessageCounter());
|
|
231
230
|
return { messageCounts, messageSize };
|
|
232
231
|
}
|
|
@@ -270,7 +269,7 @@ type MessageCounts = {
|
|
|
270
269
|
type MessageCountTimeSeries = TimeSeries<MessageCounts>;
|
|
271
270
|
|
|
272
271
|
type MessageAttributeHistogram = {
|
|
273
|
-
[
|
|
272
|
+
[messageType: string]: {
|
|
274
273
|
received: number;
|
|
275
274
|
sent: number;
|
|
276
275
|
};
|
|
@@ -288,8 +287,8 @@ export type EchoDataStats = {
|
|
|
288
287
|
connections: number;
|
|
289
288
|
receivedMessages: BaseDataOpStats;
|
|
290
289
|
sentMessages: TimedDataOpStats & { failedPerSecond: number };
|
|
291
|
-
|
|
292
|
-
|
|
290
|
+
avgSizeByMessageType: { [messageType: string]: number };
|
|
291
|
+
countByMessageType: MessageAttributeHistogram;
|
|
293
292
|
};
|
|
294
293
|
};
|
|
295
294
|
|
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { cbor, type PeerId } from '@automerge/automerge-repo';
|
|
6
5
|
import { onTestFinished, describe, expect, test } from 'vitest';
|
|
7
6
|
|
|
8
7
|
import { sleep, Trigger, waitForCondition } from '@dxos/async';
|
|
8
|
+
import { cbor, type PeerId } from '@dxos/automerge/automerge-repo';
|
|
9
9
|
import { invariant } from '@dxos/invariant';
|
|
10
10
|
import { PublicKey } from '@dxos/keys';
|
|
11
11
|
import { type SyncMessage } from '@dxos/protocols/proto/dxos/mesh/teleport/automerge';
|
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { NetworkAdapter, type Message, type PeerId, type PeerMetadata } from '@automerge/automerge-repo';
|
|
6
|
-
|
|
7
5
|
import { synchronized, Trigger } from '@dxos/async';
|
|
6
|
+
import { NetworkAdapter, type Message, type PeerId, type PeerMetadata } from '@dxos/automerge/automerge-repo';
|
|
8
7
|
import { LifecycleState } from '@dxos/context';
|
|
9
8
|
import { invariant } from '@dxos/invariant';
|
|
10
9
|
import { type PublicKey } from '@dxos/keys';
|
|
@@ -54,20 +53,11 @@ export class EchoNetworkAdapter extends NetworkAdapter {
|
|
|
54
53
|
private readonly _connections = new Map<PeerId, ConnectionEntry>();
|
|
55
54
|
private _lifecycleState: LifecycleState = LifecycleState.CLOSED;
|
|
56
55
|
private readonly _connected = new Trigger();
|
|
57
|
-
private readonly _ready = new Trigger();
|
|
58
56
|
|
|
59
57
|
constructor(private readonly _params: EchoNetworkAdapterParams) {
|
|
60
58
|
super();
|
|
61
59
|
}
|
|
62
60
|
|
|
63
|
-
override isReady(): boolean {
|
|
64
|
-
return this._lifecycleState === LifecycleState.OPEN;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
override whenReady(): Promise<void> {
|
|
68
|
-
return this._ready.wait();
|
|
69
|
-
}
|
|
70
|
-
|
|
71
61
|
override connect(peerId: PeerId, peerMetadata?: PeerMetadata | undefined): void {
|
|
72
62
|
this.peerId = peerId;
|
|
73
63
|
this.peerMetadata = peerMetadata;
|
|
@@ -88,7 +78,11 @@ export class EchoNetworkAdapter extends NetworkAdapter {
|
|
|
88
78
|
return;
|
|
89
79
|
}
|
|
90
80
|
this._lifecycleState = LifecycleState.OPEN;
|
|
91
|
-
|
|
81
|
+
|
|
82
|
+
log('emit ready');
|
|
83
|
+
this.emit('ready', {
|
|
84
|
+
network: this,
|
|
85
|
+
});
|
|
92
86
|
}
|
|
93
87
|
|
|
94
88
|
@synchronized
|
|
@@ -102,7 +96,6 @@ export class EchoNetworkAdapter extends NetworkAdapter {
|
|
|
102
96
|
}
|
|
103
97
|
this._replicators.clear();
|
|
104
98
|
|
|
105
|
-
this._ready.reset();
|
|
106
99
|
this._lifecycleState = LifecycleState.CLOSED;
|
|
107
100
|
}
|
|
108
101
|
|
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import type { Heads } from '@automerge/automerge';
|
|
6
|
-
import type { DocumentId } from '@automerge/automerge-repo';
|
|
7
|
-
|
|
5
|
+
import type { Heads } from '@dxos/automerge/automerge';
|
|
6
|
+
import type { DocumentId } from '@dxos/automerge/automerge-repo';
|
|
8
7
|
import { headsEncoding } from '@dxos/indexing';
|
|
9
8
|
import type { BatchLevel, SublevelDB } from '@dxos/kv-store';
|
|
10
9
|
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
// s
|
|
4
4
|
|
|
5
|
-
import { type StorageAdapterInterface, type Chunk, type StorageKey } from '@automerge/automerge-repo';
|
|
6
5
|
import { type MixedEncoding } from 'level-transcoder';
|
|
7
6
|
|
|
7
|
+
import { type StorageAdapterInterface, type Chunk, type StorageKey } from '@dxos/automerge/automerge-repo';
|
|
8
8
|
import { LifecycleState, Resource } from '@dxos/context';
|
|
9
9
|
import { type BatchLevel, type SublevelDB } from '@dxos/kv-store';
|
|
10
10
|
import { type MaybePromise } from '@dxos/util';
|
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import * as A from '@automerge/automerge';
|
|
6
|
-
import { cbor } from '@automerge/automerge-repo';
|
|
7
|
-
|
|
5
|
+
import * as A from '@dxos/automerge/automerge';
|
|
6
|
+
import { cbor } from '@dxos/automerge/automerge-repo';
|
|
8
7
|
import { Resource } from '@dxos/context';
|
|
9
8
|
import { invariant } from '@dxos/invariant';
|
|
10
9
|
import { type PublicKey } from '@dxos/keys';
|
|
@@ -2,8 +2,7 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type DocumentId } from '@automerge/automerge-repo';
|
|
6
|
-
|
|
5
|
+
import { type DocumentId } from '@dxos/automerge/automerge-repo';
|
|
7
6
|
import type { CollectionId } from '@dxos/echo-protocol';
|
|
8
7
|
import { invariant } from '@dxos/invariant';
|
|
9
8
|
import { SpaceId } from '@dxos/keys';
|
|
@@ -2,9 +2,8 @@
|
|
|
2
2
|
// Copyright 2021 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type DocumentId } from '@automerge/automerge-repo';
|
|
6
|
-
|
|
7
5
|
import { UpdateScheduler } from '@dxos/async';
|
|
6
|
+
import { type DocumentId } from '@dxos/automerge/automerge-repo';
|
|
8
7
|
import { type RequestOptions } from '@dxos/codec-protobuf';
|
|
9
8
|
import { Stream } from '@dxos/codec-protobuf/stream';
|
|
10
9
|
import { invariant } from '@dxos/invariant';
|