braid-text 0.2.46 → 0.2.47
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/index.js +13 -7
- package/package.json +1 -1
- package/test/test.html +39 -0
package/index.js
CHANGED
|
@@ -293,14 +293,20 @@ braid_text.get = async (key, options) => {
|
|
|
293
293
|
} else {
|
|
294
294
|
|
|
295
295
|
if (options.accept_encoding?.match(/updates\s*\((.*)\)/)?.[1].split(',').map(x=>x.trim()).includes('dt')) {
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
doc.
|
|
296
|
+
// optimization: if client wants past current version,
|
|
297
|
+
// send empty dt
|
|
298
|
+
if (options.parents && v_eq(options.parents, version)) {
|
|
299
|
+
options.subscribe({ encoding: 'dt', body: new Doc().toBytes() })
|
|
300
|
+
} else {
|
|
301
|
+
var bytes = resource.doc.toBytes()
|
|
302
|
+
if (options.parents) {
|
|
303
|
+
var doc = Doc.fromBytes(bytes)
|
|
304
|
+
bytes = doc.getPatchSince(
|
|
305
|
+
dt_get_local_version(bytes, options.parents))
|
|
306
|
+
doc.free()
|
|
307
|
+
}
|
|
308
|
+
options.subscribe({ encoding: 'dt', body: bytes })
|
|
302
309
|
}
|
|
303
|
-
options.subscribe({ encoding: 'dt', body: bytes })
|
|
304
310
|
} else {
|
|
305
311
|
var updates = null
|
|
306
312
|
if (!options.parents && !options.version) {
|
package/package.json
CHANGED
package/test/test.html
CHANGED
|
@@ -674,6 +674,45 @@ runTest(
|
|
|
674
674
|
'xy'
|
|
675
675
|
)
|
|
676
676
|
|
|
677
|
+
runTest(
|
|
678
|
+
"test accept-encoding updates(dt) (with parents which are current version)",
|
|
679
|
+
async () => {
|
|
680
|
+
await dt_p
|
|
681
|
+
let key = 'test-' + Math.random().toString(36).slice(2)
|
|
682
|
+
var doc = new Doc('hi')
|
|
683
|
+
doc.ins(0, 'xy')
|
|
684
|
+
|
|
685
|
+
let r = await braid_fetch(`/${key}`, {
|
|
686
|
+
method: 'PUT',
|
|
687
|
+
version: ['hi-1'],
|
|
688
|
+
parents: [],
|
|
689
|
+
body: 'xy'
|
|
690
|
+
})
|
|
691
|
+
if (!r.ok) throw 'got: ' + r.statusCode
|
|
692
|
+
|
|
693
|
+
var a = new AbortController()
|
|
694
|
+
let r2 = await braid_fetch(`/${key}`, {
|
|
695
|
+
signal: a.signal,
|
|
696
|
+
parents: ['hi-1'],
|
|
697
|
+
subscribe: true,
|
|
698
|
+
headers: {
|
|
699
|
+
'merge-type': 'dt',
|
|
700
|
+
'X-Accept-Encoding': 'updates(dt)'
|
|
701
|
+
}
|
|
702
|
+
})
|
|
703
|
+
|
|
704
|
+
return await new Promise(done => {
|
|
705
|
+
r2.subscribe(u => {
|
|
706
|
+
doc.mergeBytes(u.body)
|
|
707
|
+
done(doc.get())
|
|
708
|
+
doc.free()
|
|
709
|
+
a.abort()
|
|
710
|
+
})
|
|
711
|
+
})
|
|
712
|
+
},
|
|
713
|
+
'xy'
|
|
714
|
+
)
|
|
715
|
+
|
|
677
716
|
runTest(
|
|
678
717
|
"test accept-encoding updates(dt)",
|
|
679
718
|
async () => {
|