diff --git a/index.js b/index.js index 15ee6a6..a915c8a 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,5 @@ 'use strict'; -var Promise = require('lie'); var utils = require('./pouch-utils'); var wrappers = require('pouchdb-wrappers'); var immediate = require('immediate'); @@ -89,11 +88,31 @@ exports.transform = exports.filter = function transform(config) { }); }; + handlers.put = function (orig, args) { + if (args.base._put) { + // Not all adapters have a dedicated put implementation. + // Some reuse the bulkDocs API for that. Unfortunately not all. + // Therefore only adapters with a specific PUT implementation + // are overwritten here. Others are already handled through the + // bulkDocs overwrite. + return utils.Promise.resolve() + .then(function() { + return incoming(args.doc); + }) + .then(function(transformedDocument) { + args.doc = transformedDocument; + return orig(); + }); + } else { + return orig(); + } + }; + handlers.bulkDocs = function (orig, args) { for (var i = 0; i < args.docs.length; i++) { args.docs[i] = incoming(args.docs[i]); } - return Promise.all(args.docs).then(function (docs) { + return utils.Promise.all(args.docs).then(function (docs) { args.docs = docs; return orig(); }); diff --git a/package.json b/package.json index c85a0ed..8e59e8f 100644 --- a/package.json +++ b/package.json @@ -34,12 +34,11 @@ "dependencies": { "argsarray": "0.0.1", "es3ify": "0.2.2", + "immediate": "~3.0.5", "inherits": "2.0.1", - "lie": "3.0.4", "pouchdb-extend": "0.1.2", - "pouchdb-promise": "5.4.3", - "pouchdb-wrappers": "1.3.6", - "immediate": "~3.0.5" + "pouchdb-promise": "6.3.4", + "pouchdb-wrappers": "jakobwesthoff/pouchdb-wrappers#taskqueue-race" }, "devDependencies": { "bluebird": "^1.0.7", @@ -49,13 +48,14 @@ "http-server": "~0.5.5", "istanbul": "^0.2.7", "jshint": "~2.8.0", + "lie": "^3.1.1", "mocha": "^2.4.5", "phantomjs-prebuilt": "^2.1.7", - "pouchdb-adapter-http": "^5.4.4", - "pouchdb-adapter-memory": "^5.4.4", - "pouchdb-core": "^5.4.4", - "pouchdb-mapreduce": "^5.4.4", - "pouchdb-replication": "^5.4.4", + "pouchdb-adapter-http": "6.3.4", + "pouchdb-adapter-memory": "6.3.4", + "pouchdb-core": "6.3.4", + "pouchdb-mapreduce": "6.3.4", + "pouchdb-replication": "6.3.4", "request": "^2.36.0", "sauce-connect-launcher": "^0.14.0", "selenium-standalone": "^5.1.0", diff --git a/test/test.js b/test/test.js index f199bad..c2cd651 100644 --- a/test/test.js +++ b/test/test.js @@ -1,6 +1,9 @@ /*jshint expr:true */ 'use strict'; +// PhantomJs does not support native Promises +require('lie/polyfill'); + var Pouch = require('pouchdb-core') .plugin(require('pouchdb-mapreduce')) .plugin(require('pouchdb-replication'))