@automerge/automerge-repo 1.2.1 → 2.0.0-alpha.0
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/AutomergeUrl.d.ts +3 -3
- package/dist/AutomergeUrl.d.ts.map +1 -1
- package/dist/AutomergeUrl.js +5 -1
- package/dist/DocHandle.d.ts +11 -10
- package/dist/DocHandle.d.ts.map +1 -1
- package/dist/DocHandle.js +23 -43
- package/dist/Repo.d.ts +1 -1
- package/dist/Repo.d.ts.map +1 -1
- package/dist/Repo.js +53 -36
- package/dist/helpers/DummyNetworkAdapter.d.ts +3 -0
- package/dist/helpers/DummyNetworkAdapter.d.ts.map +1 -1
- package/dist/helpers/DummyNetworkAdapter.js +24 -5
- package/dist/helpers/tests/network-adapter-tests.d.ts.map +1 -1
- package/dist/helpers/tests/network-adapter-tests.js +88 -1
- package/dist/helpers/throttle.d.ts +1 -1
- package/dist/helpers/throttle.js +1 -1
- package/dist/network/NetworkAdapter.d.ts +2 -0
- package/dist/network/NetworkAdapter.d.ts.map +1 -1
- package/dist/network/NetworkAdapterInterface.d.ts +2 -2
- package/dist/network/NetworkAdapterInterface.d.ts.map +1 -1
- package/dist/network/NetworkSubsystem.d.ts +5 -2
- package/dist/network/NetworkSubsystem.d.ts.map +1 -1
- package/dist/network/NetworkSubsystem.js +21 -25
- package/package.json +3 -3
- package/src/AutomergeUrl.ts +6 -6
- package/src/DocHandle.ts +27 -57
- package/src/Repo.ts +55 -40
- package/src/helpers/DummyNetworkAdapter.ts +29 -5
- package/src/helpers/tests/network-adapter-tests.ts +121 -1
- package/src/helpers/throttle.ts +1 -1
- package/src/network/NetworkAdapter.ts +3 -0
- package/src/network/NetworkAdapterInterface.ts +4 -3
- package/src/network/NetworkSubsystem.ts +24 -31
- package/test/AutomergeUrl.test.ts +4 -0
- package/test/DocHandle.test.ts +20 -24
- package/test/DocSynchronizer.test.ts +5 -1
- package/test/NetworkSubsystem.test.ts +107 -0
- package/test/Repo.test.ts +37 -15
- package/test/remoteHeads.test.ts +3 -3
- package/test/Network.test.ts +0 -14
package/test/Repo.test.ts
CHANGED
|
@@ -47,6 +47,7 @@ describe("Repo", () => {
|
|
|
47
47
|
storage: storageAdapter,
|
|
48
48
|
network: [networkAdapter],
|
|
49
49
|
})
|
|
50
|
+
repo.saveDebounceRate = 1
|
|
50
51
|
return { repo, storageAdapter, networkAdapter }
|
|
51
52
|
}
|
|
52
53
|
|
|
@@ -61,7 +62,11 @@ describe("Repo", () => {
|
|
|
61
62
|
const { repo } = setup()
|
|
62
63
|
const handle = repo.create()
|
|
63
64
|
assert.notEqual(handle.documentId, null)
|
|
64
|
-
assert.equal(
|
|
65
|
+
assert.equal(
|
|
66
|
+
handle.isReady(),
|
|
67
|
+
true,
|
|
68
|
+
`handle is in ${handle.state}, not ready`
|
|
69
|
+
)
|
|
65
70
|
})
|
|
66
71
|
|
|
67
72
|
it("can create a document with an initial value", async () => {
|
|
@@ -197,8 +202,11 @@ describe("Repo", () => {
|
|
|
197
202
|
it("doesn't find a document that doesn't exist", async () => {
|
|
198
203
|
const { repo } = setup()
|
|
199
204
|
const handle = repo.find<TestDoc>(generateAutomergeUrl())
|
|
200
|
-
assert.equal(handle.isReady(), false)
|
|
201
205
|
|
|
206
|
+
await handle.whenReady(["ready", "unavailable"])
|
|
207
|
+
|
|
208
|
+
assert.equal(handle.isReady(), false)
|
|
209
|
+
assert.equal(handle.state, "unavailable")
|
|
202
210
|
const doc = await handle.doc()
|
|
203
211
|
assert.equal(doc, undefined)
|
|
204
212
|
})
|
|
@@ -220,10 +228,11 @@ describe("Repo", () => {
|
|
|
220
228
|
handle.on("unavailable", () => {
|
|
221
229
|
wasUnavailable = true
|
|
222
230
|
})
|
|
231
|
+
|
|
223
232
|
await pause(50)
|
|
224
233
|
assert.equal(wasUnavailable, false)
|
|
225
234
|
|
|
226
|
-
networkAdapter.
|
|
235
|
+
networkAdapter.forceReady()
|
|
227
236
|
await eventPromise(handle, "unavailable")
|
|
228
237
|
})
|
|
229
238
|
|
|
@@ -252,6 +261,8 @@ describe("Repo", () => {
|
|
|
252
261
|
storage: storageAdapter,
|
|
253
262
|
})
|
|
254
263
|
|
|
264
|
+
await repo.flush()
|
|
265
|
+
|
|
255
266
|
const bobHandle = repo2.find<TestDoc>(handle.url)
|
|
256
267
|
await bobHandle.whenReady()
|
|
257
268
|
assert.equal(bobHandle.isReady(), true)
|
|
@@ -267,7 +278,7 @@ describe("Repo", () => {
|
|
|
267
278
|
|
|
268
279
|
assert.equal(handle.isReady(), true)
|
|
269
280
|
|
|
270
|
-
await
|
|
281
|
+
await repo.flush()
|
|
271
282
|
|
|
272
283
|
const repo2 = new Repo({
|
|
273
284
|
storage: storageAdapter,
|
|
@@ -397,6 +408,8 @@ describe("Repo", () => {
|
|
|
397
408
|
d.count = 1
|
|
398
409
|
})
|
|
399
410
|
|
|
411
|
+
await repo.flush()
|
|
412
|
+
|
|
400
413
|
for (let i = 0; i < 3; i++) {
|
|
401
414
|
const repo2 = new Repo({
|
|
402
415
|
storage,
|
|
@@ -419,8 +432,17 @@ describe("Repo", () => {
|
|
|
419
432
|
})
|
|
420
433
|
}
|
|
421
434
|
|
|
435
|
+
await repo.flush()
|
|
436
|
+
|
|
422
437
|
const storageKeyTypes = storageAdapter.keys().map(k => k.split(".")[1])
|
|
423
|
-
|
|
438
|
+
const storedSnapshotCount = storageKeyTypes.filter(
|
|
439
|
+
k => k === "snapshot"
|
|
440
|
+
).length
|
|
441
|
+
assert.equal(
|
|
442
|
+
storedSnapshotCount,
|
|
443
|
+
1,
|
|
444
|
+
`found ${storedSnapshotCount} snapshots in storage instead of 1`
|
|
445
|
+
)
|
|
424
446
|
})
|
|
425
447
|
|
|
426
448
|
it("can import an existing document", async () => {
|
|
@@ -613,15 +635,14 @@ describe("Repo", () => {
|
|
|
613
635
|
networkAdapters.push(pair)
|
|
614
636
|
|
|
615
637
|
if (idx > 0) {
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
)
|
|
638
|
+
const a = networkAdapters[idx - 1][1]
|
|
639
|
+
network.push(a)
|
|
640
|
+
networkReady.push(a.whenReady())
|
|
620
641
|
}
|
|
621
642
|
|
|
622
643
|
if (idx < numberOfPeers - 1) {
|
|
623
644
|
network.push(pair[0])
|
|
624
|
-
|
|
645
|
+
pair[0].whenReady()
|
|
625
646
|
}
|
|
626
647
|
|
|
627
648
|
const repo = new Repo({
|
|
@@ -636,7 +657,7 @@ describe("Repo", () => {
|
|
|
636
657
|
await Promise.all(networkReady)
|
|
637
658
|
|
|
638
659
|
const connectedPromise = Promise.all(
|
|
639
|
-
repos.map(repo =>
|
|
660
|
+
repos.map(repo => repo.networkSubsystem.whenReady)
|
|
640
661
|
)
|
|
641
662
|
|
|
642
663
|
// Initialize the network.
|
|
@@ -944,6 +965,7 @@ describe("Repo", () => {
|
|
|
944
965
|
})
|
|
945
966
|
const unsyncedHandle = isolatedRepo.create<TestDoc>()
|
|
946
967
|
const url = unsyncedHandle.url
|
|
968
|
+
await isolatedRepo.flush()
|
|
947
969
|
|
|
948
970
|
// Now create a message channel to connect two repos
|
|
949
971
|
const abChannel = new MessageChannel()
|
|
@@ -1127,8 +1149,10 @@ describe("Repo", () => {
|
|
|
1127
1149
|
})
|
|
1128
1150
|
await pause(500)
|
|
1129
1151
|
|
|
1130
|
-
// repo has no stored sync state for charlie so we should see
|
|
1131
|
-
assert.strictEqual(bobSyncMessages,
|
|
1152
|
+
// repo has no stored sync state for charlie so we should see 2 sync messages
|
|
1153
|
+
assert.strictEqual(bobSyncMessages, 2)
|
|
1154
|
+
|
|
1155
|
+
await bobRepo.flush()
|
|
1132
1156
|
|
|
1133
1157
|
// setup new repo which uses bob's storage
|
|
1134
1158
|
const bob2Repo = new Repo({
|
|
@@ -1235,12 +1259,10 @@ describe("Repo", () => {
|
|
|
1235
1259
|
network: [bobAdapter],
|
|
1236
1260
|
peerId: bob,
|
|
1237
1261
|
})
|
|
1238
|
-
|
|
1239
1262
|
const aliceDoc = aliceRepo.create()
|
|
1240
1263
|
aliceDoc.change((doc: any) => (doc.text = "Hello world"))
|
|
1241
1264
|
|
|
1242
1265
|
const bobDoc = bobRepo.find(aliceDoc.url)
|
|
1243
|
-
bobDoc.unavailable()
|
|
1244
1266
|
await eventPromise(bobDoc, "unavailable")
|
|
1245
1267
|
|
|
1246
1268
|
aliceAdapter.peerCandidate(bob)
|
package/test/remoteHeads.test.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as A from "@automerge/automerge/next"
|
|
2
2
|
import assert from "assert"
|
|
3
3
|
import { describe, it } from "vitest"
|
|
4
|
-
import { MessageChannelNetworkAdapter } from "../../automerge-repo-network-messagechannel/
|
|
4
|
+
import { MessageChannelNetworkAdapter } from "../../automerge-repo-network-messagechannel/src/index.js"
|
|
5
5
|
import { generateAutomergeUrl, parseAutomergeUrl } from "../src/AutomergeUrl.js"
|
|
6
6
|
import { eventPromise } from "../src/helpers/eventPromise.js"
|
|
7
7
|
import {
|
|
@@ -270,7 +270,7 @@ async function connectRepos(a: Repo, b: Repo) {
|
|
|
270
270
|
a.networkSubsystem.addNetworkAdapter(aAdapter)
|
|
271
271
|
b.networkSubsystem.addNetworkAdapter(bAdapter)
|
|
272
272
|
await Promise.all([
|
|
273
|
-
|
|
274
|
-
|
|
273
|
+
a.networkSubsystem.whenReady(),
|
|
274
|
+
a.networkSubsystem.whenReady(),
|
|
275
275
|
])
|
|
276
276
|
}
|
package/test/Network.test.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import assert from "assert"
|
|
2
|
-
import { describe, it } from "vitest"
|
|
3
|
-
import { NetworkSubsystem } from "../src/network/NetworkSubsystem.js"
|
|
4
|
-
|
|
5
|
-
// Note: The sync tests in `Repo.test.ts` exercise the network subsystem, and the suite in
|
|
6
|
-
// `automerge-repo` provides test utilities that individual adapters can
|
|
7
|
-
// use to ensure that they work correctly.
|
|
8
|
-
|
|
9
|
-
describe("Network subsystem", () => {
|
|
10
|
-
it("Can be instantiated", () => {
|
|
11
|
-
const network = new NetworkSubsystem([])
|
|
12
|
-
assert(network !== null)
|
|
13
|
-
})
|
|
14
|
-
})
|