diff --git a/packages/node_modules/pouchdb-core/src/adapter.js b/packages/node_modules/pouchdb-core/src/adapter.js index cc08c1fcf0..bf7a9c9ab7 100644 --- a/packages/node_modules/pouchdb-core/src/adapter.js +++ b/packages/node_modules/pouchdb-core/src/adapter.js @@ -197,6 +197,7 @@ function attachmentNameError(name) { class AbstractPouchDB extends EventEmitter { _setup() { + var pluginPrototype = Object.getPrototypeOf(this); this.post = adapterFun('post', function (doc, opts, callback) { if (typeof opts === 'function') { callback = opts; @@ -920,6 +921,13 @@ class AbstractPouchDB extends EventEmitter { Promise.all(deletedMap).then(destroyDb, callback); }); }).bind(this); + + // Re-add plugin methods that may have been overridden + for (var key in pluginPrototype) { + if (this[key] !== pluginPrototype[key]) { + this[key] = pluginPrototype[key]; + } + } } _compact(opts, callback) { diff --git a/tests/integration/test.basics.js b/tests/integration/test.basics.js index 946cb61736..bccf060f51 100644 --- a/tests/integration/test.basics.js +++ b/tests/integration/test.basics.js @@ -1205,6 +1205,25 @@ adapters.forEach(function (adapter) { }); } + it('8594, PouchDB.plugin() can override core methods', function (done) { + const pouchBulkDocs = PouchDB.prototype.bulkDocs; // original bulkDocs + let called = false; + PouchDB.plugin({ // override + bulkDocs: function (docs, options, callback) { + called = true; + return pouchBulkDocs.call(this, docs, options, callback); + } + }); + const db = new PouchDB("test"); + // will error, but we don't care about the error + // just checking if called === true so that + // bulkDocs indeed got overridden + db.bulkDocs().catch(function () { + called.should.equal(true); + done(); + }); + }); + if (typeof process !== 'undefined' && !process.browser) { it('#5471 PouchDB.plugin() should throw error if passed wrong type or empty object', function () { (function () {