braid-text 0.2.63 → 0.2.64

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 CHANGED
@@ -433,6 +433,26 @@ braid_text.put = async (key, options) => {
433
433
  })
434
434
  }
435
435
 
436
+ let resource = (typeof key == 'string') ? await get_resource(key) : key
437
+
438
+ if (options.transfer_encoding === 'dt') {
439
+ var start_i = 1 + resource.doc.getLocalVersion().reduce((a, b) => Math.max(a, b), -1)
440
+
441
+ resource.doc.mergeBytes(body)
442
+
443
+ var end_i = resource.doc.getLocalVersion().reduce((a, b) => Math.max(a, b), -1)
444
+ for (var i = start_i; i <= end_i; i++) {
445
+ let v = resource.doc.localToRemoteVersion([i])[0]
446
+ if (!resource.actor_seqs[v[0]]) resource.actor_seqs[v[0]] = new braid_text.RangeSet()
447
+ resource.actor_seqs[v[0]].add_range(v[1], v[1])
448
+ }
449
+ resource.val = resource.doc.get()
450
+ resource.version = resource.doc.getRemoteVersion().map(x => x.join("-")).sort()
451
+
452
+ await resource.db_delta(body)
453
+ return { change_count: end_i - start_i + 1 }
454
+ }
455
+
436
456
  if (version) validate_version_array(version)
437
457
 
438
458
  // translate a single parent of "root" to the empty array (same meaning)
@@ -445,8 +465,6 @@ braid_text.put = async (key, options) => {
445
465
  if (body != null && (typeof body !== 'string')) throw new Error(`body must be a string`)
446
466
  if (patches) validate_patches(patches)
447
467
 
448
- let resource = (typeof key == 'string') ? await get_resource(key) : key
449
-
450
468
  if (options_parents) {
451
469
  // make sure we have all these parents
452
470
  for (let p of options_parents) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braid-text",
3
- "version": "0.2.63",
3
+ "version": "0.2.64",
4
4
  "description": "Library for collaborative text over http using braid.",
5
5
  "author": "Braid Working Group",
6
6
  "repository": "braid-org/braid-text",
package/server-demo.js CHANGED
@@ -1,6 +1,4 @@
1
-
2
1
  var port = process.argv[2] || 8888
3
-
4
2
  var braid_text = require("./index.js")
5
3
 
6
4
  // TODO: set a custom database folder
package/test/test.html CHANGED
@@ -732,6 +732,35 @@ runTest(
732
732
  'xy'
733
733
  )
734
734
 
735
+ runTest(
736
+ "test put with transfer-encoding: dt",
737
+ async () => {
738
+ var key = 'test-' + Math.random().toString(36).slice(2)
739
+ var doc = new Doc('hi')
740
+ doc.ins(0, 'xy')
741
+
742
+ var bytes = doc.toBytes()
743
+
744
+ var r1 = await braid_fetch(`/eval`, {
745
+ method: 'PUT',
746
+ body: `void (async () => {
747
+ var key = '/${key}'
748
+
749
+ var {change_count} = await braid_text.put(key, {
750
+ body: new Uint8Array([${'' + bytes}]),
751
+ transfer_encoding: "dt"
752
+ })
753
+ var {body, version} = await braid_text.get(key, {})
754
+
755
+ res.end('' + change_count + " " + body + " " + version)
756
+ })()`
757
+ })
758
+
759
+ return await r1.text()
760
+ },
761
+ '2 xy hi-1'
762
+ )
763
+
735
764
  runTest(
736
765
  "test transfer-encoding dt (with parents)",
737
766
  async () => {