diff --git a/helpers/add-one.js b/helpers/add-one.js index 21395c0..f7b0651 100644 --- a/helpers/add-one.js +++ b/helpers/add-one.js @@ -1,14 +1,14 @@ 'use strict' +var PouchDBErrors = require('pouchdb-errors') +var Promise = require('lie') + var toDoc = require('../utils/to-doc') var addTimestamps = require('../utils/add-timestamps') module.exports = function addOne (object) { - var Promise = this.constructor.utils.Promise - var errors = this.constructor.Errors - if (typeof object !== 'object') { - return Promise.reject(errors.NOT_AN_OBJECT) + return Promise.reject(PouchDBErrors.NOT_AN_OBJECT) } var method = object.id ? 'put' : 'post' diff --git a/helpers/find-or-add-one.js b/helpers/find-or-add-one.js index ee09ac3..c0d8490 100644 --- a/helpers/find-or-add-one.js +++ b/helpers/find-or-add-one.js @@ -1,20 +1,23 @@ +module.exports = findOrAddOne + +var PouchDBErrors = require('pouchdb-errors') +var Promise = require('lie') + var toId = require('../utils/to-id') var findOne = require('./find-one') var addOne = require('./add-one') var eventify = require('./eventify') -module.exports = function findOrAddOne (state, idOrObject, newObject) { +function findOrAddOne (state, idOrObject, newObject) { var self = this - var Promise = this.constructor.utils.Promise - var errors = this.constructor.Errors var id = toId(idOrObject) if (!id) { - return Promise.reject(errors.MISSING_ID) + return Promise.reject(PouchDBErrors.MISSING_ID) } if (idOrObject === id && !newObject) { - return Promise.reject(errors.MISSING_ID) + return Promise.reject(PouchDBErrors.MISSING_ID) } return findOne.call(this, id) diff --git a/helpers/update-many.js b/helpers/update-many.js index 409f2b1..590899c 100644 --- a/helpers/update-many.js +++ b/helpers/update-many.js @@ -1,6 +1,7 @@ 'use strict' var extend = require('pouchdb-extend') +var PouchDBErrors = require('pouchdb-errors') var changeObject = require('../utils/change-object') var toDoc = require('../utils/to-doc') @@ -11,7 +12,6 @@ var findMany = require('./find-many') module.exports = function updateMany (array, change) { var self = this - var errors = this.constructor.Errors var objects var ids = array.map(toId) @@ -33,7 +33,7 @@ module.exports = function updateMany (array, change) { return object } if (typeof passedObject !== 'object') { - return errors.NOT_AN_OBJECT + return PouchDBErrors.NOT_AN_OBJECT } return extend(object, passedObject) }) diff --git a/helpers/update-one.js b/helpers/update-one.js index aea338d..7ab971a 100644 --- a/helpers/update-one.js +++ b/helpers/update-one.js @@ -1,6 +1,8 @@ 'use strict' var extend = require('pouchdb-extend') +var PouchDBErrors = require('pouchdb-errors') +var Promise = require('lie') var changeObject = require('../utils/change-object') var toDoc = require('../utils/to-doc') @@ -10,12 +12,10 @@ var findOne = require('./find-one') module.exports = function updateOne (idOrObject, change) { var self = this - var Promise = this.constructor.utils.Promise - var errors = this.constructor.Errors var object if (typeof idOrObject === 'string' && !change) { - return Promise.reject(errors.NOT_AN_OBJECT) + return Promise.reject(PouchDBErrors.NOT_AN_OBJECT) } return findOne.call(this, idOrObject) diff --git a/update-all.js b/update-all.js index 3a45f2e..f292abc 100644 --- a/update-all.js +++ b/update-all.js @@ -1,14 +1,13 @@ -'use strict' +module.exports = updateAll var extend = require('pouchdb-extend') +var Promise = require('lie') var toObject = require('./utils/to-object') var toDoc = require('./utils/to-doc') var addTimestamps = require('./utils/add-timestamps') var isntDesignDoc = require('./utils/isnt-design-doc') -module.exports = updateAll - /** * updates all existing objects * @@ -17,8 +16,6 @@ module.exports = updateAll * @return {Promise} */ function updateAll (changedProperties) { - var Promise = this.constructor.utils.Promise - var type = typeof changedProperties var objects diff --git a/update.js b/update.js index c8121c3..3f178fa 100644 --- a/update.js +++ b/update.js @@ -1,10 +1,10 @@ -'use strict' +module.exports = update + +var Promise = require('lie') var updateOne = require('./helpers/update-one') var updateMany = require('./helpers/update-many') -module.exports = update - /** * updates existing object. * @@ -15,7 +15,7 @@ module.exports = update */ function update (objectsOrIds, change) { if (typeof objectsOrIds !== 'object' && !change) { - return this.constructor.utils.Promise.reject( + return Promise.reject( new Error('Must provide change') ) }