From 3dca62f005b8e585963c20643f3902982bdf9d92 Mon Sep 17 00:00:00 2001 From: funblaster22 <53224922+funblaster22@users.noreply.github.com> Date: Mon, 1 May 2023 14:19:00 -0500 Subject: [PATCH] (#8594) - plugin override built-in methods --- packages/node_modules/pouchdb-core/src/adapter.js | 8 ++++++++ tests/integration/test.basics.js | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/packages/node_modules/pouchdb-core/src/adapter.js b/packages/node_modules/pouchdb-core/src/adapter.js index 9f90ce8452..34b4c1e77a 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; @@ -919,6 +920,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 55e6b89ba8..675679e4d7 100644 --- a/tests/integration/test.basics.js +++ b/tests/integration/test.basics.js @@ -1207,6 +1207,12 @@ adapters.forEach(function (adapter) { }); } + it('#8594 Plugins can override core methods', function () { + PouchDB.plugin({bulkDocs: function () {return true;}}); + var db = new PouchDB("test"); + db.bulkDocs().should.equal(true); + }); + if (typeof process !== 'undefined' && !process.browser) { it('#5471 PouchDB.plugin() should throw error if passed wrong type or empty object', function () { (function () {