@automerge/automerge-repo 2.0.0-alpha.20 → 2.0.0-alpha.22
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/README.md +5 -6
- package/dist/DocHandle.d.ts +12 -15
- package/dist/DocHandle.d.ts.map +1 -1
- package/dist/DocHandle.js +22 -32
- package/dist/FindProgress.d.ts +30 -0
- package/dist/FindProgress.d.ts.map +1 -0
- package/dist/FindProgress.js +1 -0
- package/dist/Repo.d.ts +9 -4
- package/dist/Repo.d.ts.map +1 -1
- package/dist/Repo.js +166 -69
- package/dist/helpers/abortable.d.ts +39 -0
- package/dist/helpers/abortable.d.ts.map +1 -0
- package/dist/helpers/abortable.js +45 -0
- package/dist/helpers/tests/network-adapter-tests.d.ts.map +1 -1
- package/dist/helpers/tests/network-adapter-tests.js +13 -13
- package/dist/synchronizer/CollectionSynchronizer.d.ts +2 -1
- package/dist/synchronizer/CollectionSynchronizer.d.ts.map +1 -1
- package/dist/synchronizer/CollectionSynchronizer.js +18 -14
- package/dist/synchronizer/DocSynchronizer.d.ts +3 -2
- package/dist/synchronizer/DocSynchronizer.d.ts.map +1 -1
- package/dist/synchronizer/DocSynchronizer.js +16 -8
- package/fuzz/fuzz.ts +3 -3
- package/package.json +2 -2
- package/src/DocHandle.ts +26 -33
- package/src/FindProgress.ts +48 -0
- package/src/Repo.ts +187 -67
- package/src/helpers/abortable.ts +61 -0
- package/src/helpers/tests/network-adapter-tests.ts +14 -13
- package/src/synchronizer/CollectionSynchronizer.ts +18 -14
- package/src/synchronizer/DocSynchronizer.ts +19 -9
- package/test/CollectionSynchronizer.test.ts +4 -4
- package/test/DocHandle.test.ts +26 -73
- package/test/Repo.test.ts +171 -210
- package/test/remoteHeads.test.ts +27 -12
package/test/remoteHeads.test.ts
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
import { DummyStorageAdapter } from "../src/helpers/DummyStorageAdapter.js"
|
|
14
14
|
import { collectMessages } from "./helpers/collectMessages.js"
|
|
15
15
|
import { TestDoc } from "./types.js"
|
|
16
|
+
import { pause } from "../src/helpers/pause.js"
|
|
16
17
|
|
|
17
18
|
describe("DocHandle.remoteHeads", () => {
|
|
18
19
|
const TEST_ID = parseAutomergeUrl(generateAutomergeUrl()).documentId
|
|
@@ -128,13 +129,15 @@ describe("DocHandle.remoteHeads", () => {
|
|
|
128
129
|
const aliceDoc = alice.create<TestDoc>()
|
|
129
130
|
aliceDoc.change(d => (d.foo = "bar"))
|
|
130
131
|
|
|
132
|
+
await pause(50)
|
|
133
|
+
|
|
131
134
|
// bob waits for the document to arrive
|
|
132
|
-
const bobDoc = bob.find<TestDoc>(aliceDoc.url)
|
|
133
|
-
await bobDoc.whenReady()
|
|
135
|
+
const bobDoc = await bob.find<TestDoc>(aliceDoc.url)
|
|
134
136
|
|
|
135
137
|
// alice's service worker waits for the document to arrive
|
|
136
|
-
const aliceServiceWorkerDoc = aliceServiceWorker.find(
|
|
137
|
-
|
|
138
|
+
const aliceServiceWorkerDoc = await aliceServiceWorker.find(
|
|
139
|
+
aliceDoc.documentId
|
|
140
|
+
)
|
|
138
141
|
|
|
139
142
|
let aliceSeenByBobPromise = new Promise<DocHandleRemoteHeadsPayload>(
|
|
140
143
|
resolve => {
|
|
@@ -168,17 +171,21 @@ describe("DocHandle.remoteHeads", () => {
|
|
|
168
171
|
const bobDocB = bob.create<TestDoc>()
|
|
169
172
|
bobDocB.change(d => (d.foo = "B"))
|
|
170
173
|
|
|
174
|
+
await pause(50)
|
|
175
|
+
|
|
171
176
|
// alice opens doc A
|
|
172
|
-
const
|
|
177
|
+
const aliceDocAPromise = alice.find<TestDoc>(bobDocA.url)
|
|
173
178
|
|
|
174
179
|
const remoteHeadsChangedMessages = (
|
|
175
180
|
await collectMessages({
|
|
176
181
|
emitter: alice.networkSubsystem,
|
|
177
182
|
event: "message",
|
|
178
|
-
until:
|
|
183
|
+
until: aliceDocAPromise,
|
|
179
184
|
})
|
|
180
185
|
).filter(({ type }) => type === "remote-heads-changed")
|
|
181
186
|
|
|
187
|
+
const aliceDocA = await aliceDocAPromise
|
|
188
|
+
|
|
182
189
|
// we should only be notified of the head changes of doc A
|
|
183
190
|
assert(
|
|
184
191
|
remoteHeadsChangedMessages.every(
|
|
@@ -197,6 +204,8 @@ describe("DocHandle.remoteHeads", () => {
|
|
|
197
204
|
const bobDocB = bob.create<TestDoc>()
|
|
198
205
|
bobDocB.change(d => (d.foo = "B"))
|
|
199
206
|
|
|
207
|
+
await pause(50)
|
|
208
|
+
|
|
200
209
|
// alice opens the docs
|
|
201
210
|
const _aliceDocA = alice.find<TestDoc>(bobDocA.url)
|
|
202
211
|
const _aliceDocB = alice.find<TestDoc>(bobDocB.url)
|
|
@@ -209,19 +218,21 @@ describe("DocHandle.remoteHeads", () => {
|
|
|
209
218
|
// stored remote heads immediately.
|
|
210
219
|
|
|
211
220
|
// open doc and subscribe alice's second tab to bob's service worker
|
|
212
|
-
const
|
|
221
|
+
const alice2DocAPromise = alice2.find<TestDoc>(bobDocA.url)
|
|
213
222
|
alice2.subscribeToRemotes([bobServiceWorkerStorageId])
|
|
214
223
|
|
|
215
224
|
const remoteHeadsChangedMessages = (
|
|
216
225
|
await collectMessages({
|
|
217
226
|
emitter: alice2.networkSubsystem,
|
|
218
227
|
event: "message",
|
|
219
|
-
until:
|
|
228
|
+
until: alice2DocAPromise,
|
|
220
229
|
})
|
|
221
230
|
).filter(({ type }) => type === "remote-heads-changed")
|
|
222
231
|
|
|
232
|
+
const alice2DocA = await alice2DocAPromise
|
|
233
|
+
|
|
223
234
|
// we should only be notified of the head changes of doc A
|
|
224
|
-
assert.strictEqual(remoteHeadsChangedMessages.length,
|
|
235
|
+
assert.strictEqual(remoteHeadsChangedMessages.length, 1)
|
|
225
236
|
assert(
|
|
226
237
|
remoteHeadsChangedMessages.every(
|
|
227
238
|
d => d.documentId === alice2DocA.documentId
|
|
@@ -242,18 +253,22 @@ describe("DocHandle.remoteHeads", () => {
|
|
|
242
253
|
// alice subscribes to bob's service worker
|
|
243
254
|
alice.subscribeToRemotes([bobServiceWorkerStorageId])
|
|
244
255
|
|
|
256
|
+
await pause(50)
|
|
257
|
+
|
|
245
258
|
// alice opens doc A
|
|
246
|
-
const
|
|
259
|
+
const alice1DocAPromise = alice.find<TestDoc>(bobDocA.url)
|
|
247
260
|
|
|
248
261
|
const remoteHeadsChangedMessages = (
|
|
249
262
|
await collectMessages({
|
|
250
263
|
emitter: alice.networkSubsystem,
|
|
251
264
|
event: "message",
|
|
252
|
-
until:
|
|
265
|
+
until: alice1DocAPromise,
|
|
253
266
|
})
|
|
254
267
|
).filter(({ type }) => type === "remote-heads-changed")
|
|
255
268
|
|
|
256
|
-
|
|
269
|
+
const alice1DocA = await alice1DocAPromise
|
|
270
|
+
|
|
271
|
+
assert.strictEqual(remoteHeadsChangedMessages.length, 1)
|
|
257
272
|
assert(
|
|
258
273
|
remoteHeadsChangedMessages.every(
|
|
259
274
|
d => d.documentId === alice1DocA.documentId
|