function upsert(db, docId, diffFun) {
  return new PouchPromise$1(function (fulfill, reject) {
    db.get(docId, function (err, doc) {
      if (err) {
        /* istanbul ignore next */
        if (err.status !== 404) {
          return reject(err);
        }
        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
        return fulfill({updated: false, rev: docRev});
      }

      // users aren't allowed to modify these values,
      // so reset them here
      newDoc._id = docId;
      newDoc._rev = docRev;
      fulfill(tryAndPut(db, newDoc, diffFun));
    });
  });
}
// the doc, or false if it doesn't need to do an update after all
the doc, or false if it doesn't need to do an update after all
the doc or false if it doesn ' t need to do an update after all
function upsert(db, docId, diffFun) {
  return new PouchPromise$1(function (fulfill, reject) {
    db.get(docId, function (err, doc) {
      if (err) {
        if (err.status !== 404) {
          return reject(err);
        }
        doc = {};
      }
      var docRev = doc._rev;
      var newDoc = diffFun(doc);
      if (!newDoc) {
        return fulfill({updated: false, rev: docRev});
      }
      newDoc._id = docId;
      newDoc._rev = docRev;
      fulfill(tryAndPut(db, newDoc, diffFun));
    });
  });
}
function upsert ( db , docId , diffFun ) { return new PouchPromise$1 ( function ( fulfill , reject ) { db . get ( docId , function ( err , doc ) { if ( err ) { if ( err . status !== 404 ) { return reject ( err ) ; } doc = { } ; } var docRev = doc . _rev ; var newDoc = diffFun ( doc ) ; if ( ! newDoc ) { return fulfill ( { updated : false , rev : docRev } ) ; } newDoc . _id = docId ; newDoc . _rev = docRev ; fulfill ( tryAndPut ( db , newDoc , diffFun ) ) ; } ) ; } ) ; }
the doc, or false if it doesn't need to do an update after all
the doc or false if it doesn ' t need to do an update after all
/* istanbul ignore next */ // the user might change the _rev, so save it for posterity // if the diffFun returns falsy, we short-circuit as // an optimization // users aren't allowed to modify these values, // so reset them here