pouchdb-merge
Advanced tools
Comparing version 6.0.7 to 6.1.0
@@ -414,2 +414,38 @@ 'use strict'; | ||
// returns the current leaf node for a given revision | ||
function latest(rev, metadata) { | ||
var toVisit = metadata.rev_tree.slice(); | ||
var node; | ||
while ((node = toVisit.pop())) { | ||
var pos = node.pos; | ||
var tree = node.ids; | ||
var id = tree[0]; | ||
var opts = tree[1]; | ||
var branches = tree[2]; | ||
var isLeaf = branches.length === 0; | ||
var history = node.history ? node.history.slice() : []; | ||
history.push({id: id, pos: pos, opts: opts}); | ||
if (isLeaf) { | ||
for (var i = 0, len = history.length; i < len; i++) { | ||
var historyNode = history[i]; | ||
var historyRev = historyNode.pos + '-' + historyNode.id; | ||
if (historyRev === rev) { | ||
// return the rev of this leaf | ||
return pos + '-' + id; | ||
} | ||
} | ||
} | ||
for (var j = 0, l = branches.length; j < l; j++) { | ||
toVisit.push({pos: pos + 1, ids: branches[j], history: history}); | ||
} | ||
} | ||
/* istanbul ignore next */ | ||
throw new Error('Unable to resolve latest revision for id ' + metadata.id + ', rev ' + rev); | ||
} | ||
exports.collectConflicts = collectConflicts; | ||
@@ -424,2 +460,3 @@ exports.collectLeaves = collectLeaves; | ||
exports.traverseRevTree = traverseRevTree; | ||
exports.winningRev = winningRev; | ||
exports.winningRev = winningRev; | ||
exports.latest = latest; |
{ | ||
"name": "pouchdb-merge", | ||
"version": "6.0.7", | ||
"version": "6.1.0", | ||
"description": "PouchDB's document merge algorithm.", | ||
@@ -5,0 +5,0 @@ "main": "./lib/index.js", |
@@ -11,2 +11,3 @@ import collectConflicts from './collectConflicts'; | ||
import isLocalId from './isLocalId'; | ||
import latest from './latest'; | ||
@@ -23,3 +24,4 @@ export { | ||
traverseRevTree, | ||
winningRev | ||
winningRev, | ||
latest | ||
}; |
39253
16
833