Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
stores.bySeqStore.get(seq, function (err, resp) {
/* istanbul ignore if */
if (err || !pouchdbMerge.isLocalId(resp._id)) {
return next();
}
batches.push({
key: seq,
prefix: stores.bySeqStore,
type: 'del'
});
next();
});
}, function () {
cursor.onsuccess = function (event) {
var cursor = event.target.result;
if (cursor) {
var metadata = cursor.value;
var docId = metadata.id;
var local = isLocalId(docId);
var rev = calculateWinningRev(metadata);
if (local) {
var docIdRev = docId + "::" + rev;
// remove all seq entries
// associated with this docId
var start = docId + "::";
var end = docId + "::~";
var index = seqStore.index('_doc_id_rev');
var range = IDBKeyRange.bound(start, end, false, false);
var seqCursor = index.openCursor(range);
seqCursor.onsuccess = function (e) {
seqCursor = e.target.result;
if (!seqCursor) {
// done
docStore.delete(cursor.primaryKey);
cursor.continue();
docInfos.forEach(function (currentDoc, resultsIdx) {
if (currentDoc._id && isLocalId(currentDoc._id)) {
var fun = currentDoc._deleted ? '_removeLocal' : '_putLocal';
api[fun](currentDoc, {ctx: tx}, function (err, res) {
results[resultsIdx] = err || res;
checkAllDocsDone();
});
return;
}
var id = currentDoc.metadata.id;
if (idsToDocs.has(id)) {
docsToDo--; // duplicate
idsToDocs.get(id).push([currentDoc, resultsIdx]);
} else {
idsToDocs.set(id, [[currentDoc, resultsIdx]]);
}
});
AbstractPouchDB.prototype.get = adapterFun('get', function (id, opts, cb) {
if (typeof opts === 'function') {
cb = opts;
opts = {};
}
if (typeof id !== 'string') {
return cb(createError(INVALID_ID));
}
if (isLocalId(id) && typeof this._getLocal === 'function') {
return this._getLocal(id, cb);
}
var leaves = [], self = this;
function finishOpenRevs() {
var result = [];
var count = leaves.length;
/* istanbul ignore if */
if (!count) {
return cb(null, result);
}
// order with open_revs is unspecified
leaves.forEach(function (leaf) {
self.get(id, {
rev: leaf,
AbstractPouchDB.prototype.get = adapterFun('get', function (id, opts, cb) {
if (typeof opts === 'function') {
cb = opts;
opts = {};
}
if (typeof id !== 'string') {
return cb(createError(INVALID_ID));
}
if (isLocalId(id) && typeof this._getLocal === 'function') {
return this._getLocal(id, cb);
}
var leaves = [], self = this;
function finishOpenRevs() {
var result = [];
var count = leaves.length;
/* istanbul ignore if */
if (!count) {
return cb(null, result);
}
// order with open_revs is unspecified
leaves.forEach(function (leaf) {
self.get(id, {
rev: leaf,
AbstractPouchDB.prototype.put = adapterFun('put', function (doc, opts, cb) {
if (typeof opts === 'function') {
cb = opts;
opts = {};
}
if (typeof doc !== 'object' || Array.isArray(doc)) {
return cb(createError(NOT_AN_OBJECT));
}
invalidIdError(doc._id);
if (isLocalId(doc._id) && typeof this._putLocal === 'function') {
if (doc._deleted) {
return this._removeLocal(doc, cb);
} else {
return this._putLocal(doc, cb);
}
}
var self = this;
if (opts.force && doc._rev) {
transformForceOptionToNewEditsOption();
putDoc(function (err) {
var result = err ? null : {ok: true, id: doc._id, rev: doc._rev};
cb(err, result);
});
} else {
putDoc(cb);
}
}).pipe(through2.obj(function (ch, _, next) {
if (!pouchdbMerge.isLocalId(ch.key)) {
return next();
}
batches.push({
key: ch.key,
prefix: stores.docStore,
type: 'del'
});
var winner = pouchdbMerge.winningRev(ch.value);
Object.keys(ch.value.rev_map).forEach(function (key) {
if (key !== 'winner') {
this.push(formatSeq(ch.value.rev_map[key]));
}
}, this);
var winningSeq = ch.value.rev_map[winner];
stores.bySeqStore.get(formatSeq(winningSeq), function (err, value) {
if (!err) {
}).pipe(through(function (ch, _, next) {
if (!isLocalId(ch.key)) {
return next()
}
batches.push({
key: ch.key,
prefix: stores.docStore,
type: 'del'
})
var winner = winningRev(ch.value)
Object.keys(ch.value.rev_map).forEach(function (key) {
if (key !== 'winner') {
this.push(formatSeq(ch.value.rev_map[key]))
}
}, this)
var winningSeq = ch.value.rev_map[winner]
stores.bySeqStore.get(formatSeq(winningSeq), function (err, value) {
if (!err) {
}).pipe(through(function (ch, _, next) {
if (!isLocalId(ch.key)) {
return next();
}
batches.push({
key: ch.key,
prefix: stores.docStore,
type: 'del'
});
var winner = winningRev(ch.value);
Object.keys(ch.value.rev_map).forEach(function (key) {
if (key !== 'winner') {
this.push(formatSeq(ch.value.rev_map[key]));
}
}, this);
var winningSeq = ch.value.rev_map[winner];
stores.bySeqStore.get(formatSeq(winningSeq), function (err, value) {
if (!err) {
AbstractPouchDB.prototype.put = adapterFun('put', function (doc, opts, cb) {
if (typeof opts === 'function') {
cb = opts;
opts = {};
}
if (typeof doc !== 'object' || Array.isArray(doc)) {
return cb(createError(NOT_AN_OBJECT));
}
invalidIdError(doc._id);
if (isLocalId(doc._id) && typeof this._putLocal === 'function') {
if (doc._deleted) {
return this._removeLocal(doc, cb);
} else {
return this._putLocal(doc, cb);
}
}
if (typeof this._put === 'function' && opts.new_edits !== false) {
this._put(doc, opts, cb);
} else {
this.bulkDocs({docs: [doc]}, opts, yankError(cb));
}
});