Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/node_modules/pouchdb-core/src/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
19 changes: 19 additions & 0 deletions tests/integration/test.basics.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down