braid-text 0.2.108 → 0.2.110

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 (2) hide show
  1. package/index.js +13 -4
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -305,11 +305,13 @@ function create_braid_text() {
305
305
  var cv = remote_res.headers.get('current-version')
306
306
  await braid_text.put(a, {
307
307
  body: update.body,
308
- transfer_encoding: 'dt'
308
+ transfer_encoding: 'dt',
309
+ peer: options.peer
309
310
  })
310
311
  if (signal.aborted) return
311
312
  if (cv) extend_fork_point({ version: JSON.parse(`[${cv}]`), parents: resource.meta.fork_point || [] })
312
313
  } else {
314
+ if (options.peer) update.peer = options.peer
313
315
  await braid_text.put(a, update)
314
316
  if (signal.aborted) return
315
317
  if (update.version) extend_fork_point(update)
@@ -880,7 +882,9 @@ function create_braid_text() {
880
882
 
881
883
  // Notify non-simpleton clients with the dt-encoded update
882
884
  var dt_update = { body, encoding: 'dt' }
883
- await Promise.all([...resource.clients].map(client => client.my_subscribe(dt_update)))
885
+ await Promise.all([...resource.clients].
886
+ filter(client => !peer || client.peer !== peer).
887
+ map(client => client.my_subscribe(dt_update)))
884
888
 
885
889
  return { change_count: end_i - start_i + 1 }
886
890
  }
@@ -927,7 +931,12 @@ function create_braid_text() {
927
931
  let og_patches = patches
928
932
  patches = patches.map((p) => ({
929
933
  ...p,
930
- range: p.range.match(/\d+/g).map((x) => parseInt(x)),
934
+ range: p.range.match(/-?\d+/g).map((x) => {
935
+ let n = parseInt(x)
936
+ // Handle negative indices (including -0) as offsets from max_pos
937
+ if (Object.is(n, -0) || n < 0) return max_pos + n
938
+ return n
939
+ }),
931
940
  content_codepoints: [...p.content],
932
941
  })).sort((a, b) => a.range[0] - b.range[0])
933
942
 
@@ -2530,7 +2539,7 @@ function create_braid_text() {
2530
2539
  if (typeof x != 'object') throw new Error(`invalid patch: not an object`)
2531
2540
  if (x.unit && x.unit !== 'text') throw new Error(`invalid patch unit '${x.unit}': only 'text' supported`)
2532
2541
  if (typeof x.range !== 'string') throw new Error(`invalid patch range: must be a string`)
2533
- if (!x.range.match(/^\s*\[\s*\d+\s*:\s*\d+\s*\]\s*$/)) throw new Error(`invalid patch range: ${x.range}`)
2542
+ if (!x.range.match(/^\s*\[\s*-?\d+\s*:\s*-?\d+\s*\]\s*$/)) throw new Error(`invalid patch range: ${x.range}`)
2534
2543
  if (typeof x.content !== 'string') throw new Error(`invalid patch content: must be a string`)
2535
2544
  }
2536
2545
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braid-text",
3
- "version": "0.2.108",
3
+ "version": "0.2.110",
4
4
  "description": "Library for collaborative text over http using braid.",
5
5
  "author": "Braid Working Group",
6
6
  "repository": "braid-org/braid-text",