How to use the pouchdb-promise.resolve function in pouchdb-promise

To help you get started, we’ve selected a few pouchdb-promise examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nolanlawson / html5workertest / src / worker.js View on Github external
var register = require('promise-worker/register')
var Promise = require('pouchdb-promise')

var resolved = Promise.resolve()

function runTest (func) {
  return resolved.then(() => {
    /* eslint-disable no-new-func */
    return new Function(func)()
  }).catch(err => {
    if (typeof console !== 'undefined' && typeof console.log === 'function') {
      console.log(err)
    }
    return false // failed
  })
}

register(message => {
  return runTest(message.test)
})
github stockulus / pouchdb-react-native / packages / pouchdb-adapter-leveldb-core-rn / src / index.js View on Github external
function compact (revsMap, callback) {
      var promise = Promise.resolve()
      revsMap.forEach(function (revs, docId) {
        // TODO: parallelize, for now need to be sequential to
        // pass orphaned attachment tests
        promise = promise.then(function () {
          return new Promise(function (resolve, reject) {
            api._doCompactionNoLock(docId, revs, {ctx: txn}, function (err) {
              /* istanbul ignore if */
              if (err) {
                return reject(err)
              }
              resolve()
            })
          })
        })
      })
github stockulus / pouchdb-react-native / packages / pouchdb-adapter-leveldb-core-rn / src / index.js View on Github external
}

        return new Promise(function (resolve) {
          txn.batch([{
            type: 'put',
            prefix: stores.attachmentStore,
            key: digest,
            value: newAtt
          }]);
          resolve(!oldAtt);
        });
      }

      // put attachments in a per-digest queue, to avoid two docs with the same
      // attachment overwriting each other
      var queue = attachmentQueues[digest] || Promise.resolve();
      attachmentQueues[digest] = queue.then(function () {
        return fetchAtt().then(saveAtt).then(function (isNewAttachment) {
          callback(null, isNewAttachment);
        }, callback);
      });
    }
github nolanlawson / pouchdb-find / test / test-abstract-mapreduce / mapreduce.js View on Github external
function httpQuery(db, fun, opts, callback) {
  if (typeof opts === 'function') {
    callback = opts;
    opts = {};
  }
  opts = extend(true, {}, opts);

  if (typeof fun === 'function') {
    fun = {map : fun};
  }

  var promise = Promise.resolve().then(function () {
    return httpQueryPromised(db, fun, opts);
  });
  promisedCallback(promise, callback);
  return promise;
}
github pouchdb / pouchdb-server / packages / node_modules / express-pouchdb / lib / routes / documents.js View on Github external
app.post('/:db/:id(*)', utils.jsonParser, function (req, res) {
    if (!/^multipart\/form-data/.test(req.headers['content-type'])) {
      return utils.sendJSON(res, 400, {
        error: "bad_request",
        reason: "only_multipart_accepted"
      });
    }

    var opts = utils.makeOpts(req, req.query);

    var promise = Promise.resolve();
    var attachments = {};
    var form = new multiparty.Form();
    var doc;
    form.on('error', function (err) {
      promise = promise.then(function () {
        throw err;
      });
    }).on('field', function (name, field) {
      if (name !== '_rev') {
        return;
      }
      promise = promise.then(function () {
        return req.db.get(req.params.id, {rev: field});
      }).then(function (theDoc) {
        doc = theDoc;
      });
github pouchdb / pouchdb-server / packages / node_modules / pouchdb-auth / lib / writewrappers.js View on Github external
function modifyDoc(db, doc) {
  if (!(typeof doc.password == 'undefined' || doc.password === null)) {
    doc.iterations = utils.dbDataFor(db).iterations;
    doc.password_scheme = 'pbkdf2';
    doc.salt = utils.generateSecret();

    return utils.hashPassword(doc.password, doc.salt, doc.iterations).then(function (hash) {
      delete doc.password;
      doc.derived_key = hash;
    });
  }
  return Promise.resolve();
}
github pouchdb / pouchdb-server / packages / node_modules / express-pouchdb / lib / index.js View on Github external
app.setPouchDB = function (newPouchDB) {
    var oldPouchDB = currentPouchDB;
    currentPouchDB = newPouchDB;

    var stoppingDone = Promise.resolve();
    if (oldPouchDB) {
      stoppingDone = app.daemonManager.stop(oldPouchDB);
    }
    return stoppingDone.then(function () {
      return app.daemonManager.start(newPouchDB);
    });
  };
github stockulus / pouchdb-react-native / packages / pouchdb-adapter-leveldb-core-rn / src / index.js View on Github external
}, function (next) {
        Promise.resolve().then(function () {
          if (opts.include_docs && opts.attachments) {
            return fetchAttachments(results, stores, opts)
          }
        }).then(function () {
          callback(null, {
            total_rows: docCount,
            offset: opts.skip,
            rows: results
          })
        }, callback)
        next()
      }).on('unpipe', function () {
        throughStream.end()
github pouchdb-community / pouchdb-full-sync / lib / replicate.js View on Github external
function initCheckpointer() {
    if (checkpointer) {
      return Promise.resolve();
    }
    return generateReplicationId(src, target, opts).then(function (res) {
      repId = res;
      checkpointer = new Checkpointer(src, target, repId, returnValue);
    });
  }
github pouchdb / pouchdb-server / packages / node_modules / pouchdb-auth / lib / utils.js View on Github external
exports.hashPassword = function (password, salt, iterations) {
  var derived_key = crypto.pbkdf2(password, salt, iterations, 20);
  return Promise.resolve(derived_key.toString('hex'));
};

pouchdb-promise

Promises as used by PouchDB.

Apache-2.0
Latest version published 7 years ago

Package Health Score

78 / 100
Full package analysis

Similar packages