braid-text 0.2.10 → 0.2.12

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.
Files changed (3) hide show
  1. package/index.js +2 -1
  2. package/package.json +1 -1
  3. package/test.html +16 -0
package/index.js CHANGED
@@ -380,7 +380,7 @@ braid_text.put = async (key, options) => {
380
380
  let v = decode_version(og_v)
381
381
 
382
382
  resource.length_cache.put(`${v[0]}-${v[1]}`, patches.reduce((a, b) =>
383
- a + (b.content_codepoints.length ? b.content_codepoints.length : -(b.range[1] - b.range[0])),
383
+ a + (b.content_codepoints?.length ?? 0) - (b.range[1] - b.range[0]),
384
384
  max_pos))
385
385
 
386
386
  // validate version: make sure we haven't seen it already
@@ -1717,6 +1717,7 @@ braid_text.get_resource = get_resource
1717
1717
 
1718
1718
  braid_text.encode_filename = encode_filename
1719
1719
  braid_text.decode_filename = decode_filename
1720
+ braid_text.get_files_for_key = get_files_for_key
1720
1721
 
1721
1722
  braid_text.dt_get = dt_get
1722
1723
  braid_text.dt_get_patches = dt_get_patches
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braid-text",
3
- "version": "0.2.10",
3
+ "version": "0.2.12",
4
4
  "description": "Library for collaborative text over http using braid.",
5
5
  "author": "Braid Working Group",
6
6
  "repository": "braid-org/braidjs",
package/test.html CHANGED
@@ -222,4 +222,20 @@ runTest(
222
222
  JSON.stringify({b: 6}, null, 4)
223
223
  )
224
224
 
225
+ runTest(
226
+ "test length updating",
227
+ async () => {
228
+ let key = 'test-' + Math.random().toString(36).slice(2)
229
+
230
+ await fetch(`/${key}`, { method: 'PUT', body: '' })
231
+ await fetch(`/${key}`, { method: 'PUT', body: '0123456789' })
232
+ await fetch(`/${key}`, { method: 'PUT', body: '0123456789' })
233
+ await fetch(`/${key}`, { method: 'PUT', body: '0123456789' })
234
+
235
+ let r = await fetch(`/${key}`, { method: 'HEAD' })
236
+ return '' + parseInt(r.headers.get('version').split('-')[1])
237
+ },
238
+ '19'
239
+ )
240
+
225
241
  </script>