braid-text 0.0.21 → 0.0.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.
Files changed (2) hide show
  1. package/index.js +10 -4
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -340,22 +340,27 @@ braid_text.put = async (key, options) => {
340
340
  // validate version: make sure we haven't seen it already
341
341
  if (v[1] <= (resource.actor_seqs[v[0]] ?? -1)) {
342
342
 
343
+ if (!options.validate_already_seen_versions) return
344
+
343
345
  // if we have seen it already, make sure it's the same as before
344
346
  let local_version = OpLog_remote_to_local(resource.doc, og_parents)
345
347
  let updates = OpLog_get_patches(resource.doc.getPatchSince(local_version), resource.doc.getOpsSince(local_version))
346
348
 
347
349
  let seen = {}
348
350
  for (let u of updates) {
349
- if (u.start != u.end) {
351
+ u.version = decode_version(u.version)
352
+ u.version[1] += u.end - u.start - 1
353
+
354
+ if (!u.content) {
350
355
  // delete
351
- let v = decode_version(u.version)
356
+ let v = u.version
352
357
  for (let i = 0; i < u.end - u.start; i++) {
353
358
  let ps = (i < u.end - u.start - 1) ? [`${v[0]}-${v[1] - i - 1}`] : u.parents
354
359
  seen[JSON.stringify([v[0], v[1] - i, ps, u.start + i])] = true
355
360
  }
356
361
  } else {
357
362
  // insert
358
- let v = decode_version(u.version)
363
+ let v = u.version
359
364
  let content = [...u.content]
360
365
  for (let i = 0; i < content.length; i++) {
361
366
  let ps = (i > 0) ? [`${v[0]}-${v[1] - content.length + i}`] : u.parents
@@ -381,13 +386,14 @@ braid_text.put = async (key, options) => {
381
386
  }
382
387
  // insert
383
388
  for (let i = 0; i < p.content?.length ?? 0; i++) {
389
+ let vv = decode_version(v)
384
390
  let c = p.content[i]
385
391
 
386
392
  if (!seen[JSON.stringify([vv[0], vv[1], ps, p.range[1] + offset, c])]) throw new Error('invalid update: different from previous update with same version')
387
393
 
388
394
  offset++
389
395
  ps = [v]
390
- v = decode_version(v)
396
+ v = vv
391
397
  v = `${v[0]}-${v[1] + 1}`
392
398
  }
393
399
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "braid-text",
3
- "version": "0.0.21",
3
+ "version": "0.0.22",
4
4
  "description": "Library for collaborative text over http using braid.",
5
5
  "author": "Braid Working Group",
6
6
  "repository": "braid-org/braidjs",