Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function upsertInner(db, docId, diffFun) {
if (typeof docId !== 'string') {
return PouchPromise.reject(new Error('doc id is required'));
}
return db.get(docId)["catch"](function (err) {
/* istanbul ignore next */
if (err.status !== 404) {
throw err;
}
return {};
}).then(function (doc) {
// the user might change the _rev, so save it for posterity
var docRev = doc._rev;
var newDoc = diffFun(doc);
if (!newDoc) {
// if the diffFun returns falsy, we short-circuit as
// an optimization
function upsertInner(db, docId, diffFun) {
if (typeof docId !== 'string') {
return PouchPromise.reject(new Error('doc id is required'));
}
return db.get(docId).catch(function (err) {
/* istanbul ignore next */
if (err.status !== 404) {
throw err;
}
return {};
}).then(function (doc) {
// the user might change the _rev, so save it for posterity
var docRev = doc._rev;
var newDoc = diffFun(doc);
if (!newDoc) {
// if the diffFun returns falsy, we short-circuit as
// an optimization