How to use the pouchdb-errors.NOT_AN_OBJECT function in pouchdb-errors

To help you get started, we’ve selected a few pouchdb-errors 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 hoodiehq / hoodie-store-client / lib / helpers / update-one.js View on Github external
module.exports = function updateOne (state, idOrDoc, change, prefix) {
  var doc

  if (typeof idOrDoc === 'string' && !change) {
    return Promise.reject(PouchDBErrors.NOT_AN_OBJECT)
  }

  return findOne(state, idOrDoc, prefix)

  .then(function (doc) {
    if (!change) {
      return assign(doc, idOrDoc, {_id: doc._id, _rev: doc._rev, hoodie: doc.hoodie})
    }

    return changeObject(state, change, doc)
  })

  .then(function (_doc) {
    doc = _doc
    return put(state, addTimestamps(doc))
  })
github hoodiehq / hoodie-store-client / lib / helpers / add-one.js View on Github external
function addOne (state, doc, prefix) {
  if (typeof doc !== 'object') {
    return Promise.reject(PouchDBErrors.NOT_AN_OBJECT)
  }

  doc = clone(doc)

  if (!doc._id) {
    doc._id = uuid()
  }

  if (prefix) {
    doc._id = prefix + doc._id
  }

  delete doc.hoodie

  return validate(state, doc)
github hoodiehq / hoodie-store-client / lib / helpers / update-many.js View on Github external
return docs.map(function (doc, index) {
      var passedDoc = array[index]
      if (doc instanceof Error) {
        return doc
      }
      if (typeof passedDoc !== 'object') {
        return PouchDBErrors.NOT_AN_OBJECT
      }
      return assign(doc, passedDoc, {_id: doc._id, _rev: doc._rev, hoodie: doc.hoodie})
    })
  })