Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function update(txn, doc, oldDoc) {
// Ignore updates to existing revisions
if ((doc.rev in oldDoc.revs) && !opts.new_edits) {
return false;
}
var isRoot = /^1-/.test(doc.rev);
// Reattach first writes after a deletion to last deleted tree
if (oldDoc.deleted && !doc.deleted && opts.new_edits && isRoot) {
var tmp = doc.revs[doc.rev].data;
tmp._rev = oldDoc.rev;
tmp._id = oldDoc.id;
doc = convertDocFormat(parseDoc(tmp, opts.new_edits, dbOpts));
}
var merged = merge(oldDoc.rev_tree, doc.rev_tree[0], docsRevsLimit(doc));
doc.stemmedRevs = merged.stemmedRevs;
doc.rev_tree = merged.tree;
// Merge the old and new rev data
var revs = oldDoc.revs;
revs[doc.rev] = doc.revs[doc.rev];
doc.revs = revs;
doc.attachments = oldDoc.attachments;
var inConflict = opts.new_edits && (((oldDoc.deleted && doc.deleted) ||
(!oldDoc.deleted && merged.conflicts !== 'new_leaf') ||
(oldDoc.deleted && !doc.deleted && merged.conflicts === 'new_branch') ||
processed[attachment.name] = attachment;
delete attachment.name;
});
data._attachments = processed;
return data;
});
});
return Promise.all(promises);
}
for (var i = 0, len = req.docs.length; i < len; i++) {
var result;
// TODO: We should get rid of throwing for invalid docs, also not sure
// why this is needed in idb-next and not idb
try {
result = parseDoc(req.docs[i], opts.new_edits, dbOpts);
} catch (err) {
result = err;
}
if (result.error) {
return callback(result);
}
// Ideally parseDoc would return data in this format, but it is currently
// shared so we need to convert
docs.push(convertDocFormat(result));
}
preProcessAttachments().then(function () {
api._openTransactionSafely([DOC_STORE, META_STORE], 'readwrite', function (err, _txn) {
if (err) {
return callback(err);
var docInfos = userDocs.map(function (doc) {
if (doc._id && isLocalId(doc._id)) {
return doc;
}
var newDoc = parseDoc(doc, newEdits, dbOpts);
return newDoc;
});
var docInfos = userDocs.map(function (doc) {
if (doc._id && pouchdbAdapterUtils.isLocalId(doc._id)) {
return doc;
}
var newDoc = pouchdbAdapterUtils.parseDoc(doc, newEdits);
if (newDoc.metadata && !newDoc.metadata.rev_map) {
newDoc.metadata.rev_map = {};
}
return newDoc;
});
var infoErrors = docInfos.filter(function (doc) {
var docInfos = userDocs.map(function (doc) {
if (doc._id && isLocalId(doc._id)) {
return doc;
}
var newDoc = parseDoc(doc, newEdits);
if (newDoc.metadata && !newDoc.metadata.rev_map) {
newDoc.metadata.rev_map = {};
}
return newDoc;
});
var infoErrors = docInfos.filter(function (doc) {
var docInfos = userDocs.map(function (doc) {
if (doc._id && isLocalId(doc._id)) {
return doc;
}
var newDoc = parseDoc(doc, newEdits, api.__opts);
if (newDoc.metadata && !newDoc.metadata.rev_map) {
newDoc.metadata.rev_map = {};
}
return newDoc;
});
var infoErrors = docInfos.filter(function (doc) {
var docInfos = req.docs;
var txn;
var docStore;
var bySeqStore;
var attachStore;
var attachAndSeqStore;
var metaStore;
var docInfoError;
var metaDoc;
for (var i = 0, len = docInfos.length; i < len; i++) {
var doc = docInfos[i];
if (doc._id && isLocalId(doc._id)) {
continue;
}
doc = docInfos[i] = parseDoc(doc, opts.new_edits, dbOpts);
if (doc.error && !docInfoError) {
docInfoError = doc;
}
}
if (docInfoError) {
return callback(docInfoError);
}
var allDocsProcessed = false;
var docCountDelta = 0;
var results = new Array(docInfos.length);
var fetchedDocs = new Map();
var preconditionErrored = false;
var blobType = api._meta.blobSupport ? 'blob' : 'base64';
var docInfos = userDocs.map(function (doc) {
if (doc._id && isLocalId(doc._id)) {
return doc
}
var newDoc = parseDoc(doc, newEdits)
if (newDoc.metadata && !newDoc.metadata.rev_map) {
newDoc.metadata.rev_map = {}
}
return newDoc
})
var infoErrors = docInfos.filter(function (doc) {
var docInfos = userDocs.map(function (doc) {
if (doc._id && pouchdbAdapterUtils.isLocalId(doc._id)) {
return doc;
}
var newDoc = pouchdbAdapterUtils.parseDoc(doc, newEdits);
if (newDoc.metadata && !newDoc.metadata.rev_map) {
newDoc.metadata.rev_map = {};
}
return newDoc;
});
var infoErrors = docInfos.filter(function (doc) {