Comparing version 0.4.2 to 0.4.3
{ | ||
"name": "automerge", | ||
"version": "0.4.2", | ||
"version": "0.4.3", | ||
"description": "Data structures for building collaborative applications", | ||
@@ -5,0 +5,0 @@ "main": "src/automerge.js", |
@@ -186,3 +186,3 @@ # Automerge | ||
For an example of a real-life application built upon Automerge, check out | ||
[Trellis](https://github.com/inkandswitch/trellis), a project management tool. | ||
[Trellis](https://github.com/automerge/trellis), a project management tool. | ||
@@ -228,5 +228,5 @@ | ||
[Martin Kleppmann](http://martin.kleppmann.com/), | ||
[Orion Henry](https://www.linkedin.com/in/orion-henry-9056727/), | ||
Orion Henry, | ||
[Peter van Hardenberg](https://twitter.com/pvh), | ||
[Roshan Choxi](https://www.linkedin.com/in/choxi/), and | ||
[Adam Wiggins](https://twitter.com/hirodusk). | ||
[Adam Wiggins](http://about.adamwiggins.com/). |
@@ -243,6 +243,10 @@ const { Map, List, Set } = require('immutable') | ||
function insertionsAfter(opSet, objectId, key) { | ||
function insertionsAfter(opSet, objectId, parentId, childId) { | ||
const match = /^(.*):(\d+)$/.exec(childId || '') | ||
const childKey = match ? Map({actor: match[1], elem: parseInt(match[2])}) : null | ||
return opSet | ||
.getIn(['byObject', objectId, '_following', key], List()) | ||
.getIn(['byObject', objectId, '_following', parentId], List()) | ||
.filter(op => (op.get('action') === 'ins')) | ||
.filter(op => !childKey || lamportCompare(op, childKey) < 0) | ||
.sort(lamportCompare) | ||
@@ -261,3 +265,3 @@ .reverse() // descending order | ||
if (!ancestor) return | ||
const siblings = insertionsAfter(opSet, objectId, ancestor).filter(sib => sib < key) | ||
const siblings = insertionsAfter(opSet, objectId, ancestor, key) | ||
if (!siblings.isEmpty()) return siblings.first() | ||
@@ -264,0 +268,0 @@ key = ancestor |
@@ -12,3 +12,3 @@ const assert = require('assert') | ||
} catch (e) { | ||
if (e.name !== 'AssertionError' || i === expected.length - 1) throw e | ||
if (!e.name.match(/^AssertionError/) || i === expected.length - 1) throw e | ||
} | ||
@@ -15,0 +15,0 @@ } |
@@ -613,2 +613,40 @@ const assert = require('assert') | ||
}) | ||
describe('multiple insertions at the same list position', () => { | ||
it('should handle insertion by greater actor ID', () => { | ||
s1 = Automerge.init('A') | ||
s2 = Automerge.init('B') | ||
s1 = Automerge.changeset(s1, doc => doc.list = ['two']) | ||
s2 = Automerge.merge(s2, s1) | ||
s2 = Automerge.changeset(s2, doc => doc.list.splice(0, 0, 'one')) | ||
assert.deepEqual(s2.list, ['one', 'two']) | ||
}) | ||
it('should handle insertion by lesser actor ID', () => { | ||
s1 = Automerge.init('B') | ||
s2 = Automerge.init('A') | ||
s1 = Automerge.changeset(s1, doc => doc.list = ['two']) | ||
s2 = Automerge.merge(s2, s1) | ||
s2 = Automerge.changeset(s2, doc => doc.list.splice(0, 0, 'one')) | ||
assert.deepEqual(s2.list, ['one', 'two']) | ||
}) | ||
it('should handle insertion regardless of actor ID', () => { | ||
s1 = Automerge.changeset(s1, doc => doc.list = ['two']) | ||
s2 = Automerge.merge(s2, s1) | ||
s2 = Automerge.changeset(s2, doc => doc.list.splice(0, 0, 'one')) | ||
assert.deepEqual(s2.list, ['one', 'two']) | ||
}) | ||
it('should make insertion order consistent with causality', () => { | ||
s1 = Automerge.changeset(s1, doc => doc.list = ['four']) | ||
s2 = Automerge.merge(s2, s1) | ||
s2 = Automerge.changeset(s2, doc => doc.list.unshift('three')) | ||
s1 = Automerge.merge(s1, s2) | ||
s1 = Automerge.changeset(s1, doc => doc.list.unshift('two')) | ||
s2 = Automerge.merge(s2, s1) | ||
s2 = Automerge.changeset(s2, doc => doc.list.unshift('one')) | ||
assert.deepEqual(s2.list, ['one', 'two', 'three', 'four']) | ||
}) | ||
}) | ||
}) | ||
@@ -615,0 +653,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
114910
1900
0