From 98e6468750c5081061cb28216977ce3ec487b5e9 Mon Sep 17 00:00:00 2001 From: Gregor Martynus Date: Tue, 15 Mar 2016 22:52:51 -0400 Subject: [PATCH 1/3] test: fix "skips deleted docs" test --- test/test.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/test/test.js b/test/test.js index e80994a..fb080c5 100644 --- a/test/test.js +++ b/test/test.js @@ -140,19 +140,22 @@ function tests(dbName, dbType) { }); it('skips deleted docs', function () { - db.transform({ - incoming: function (doc) { - doc.foo.baz = 'baz'; - return doc; - } - }); var doc = {_id: 'foo', foo: {}}; return db.put(doc).then(function (res) { doc._rev = res.rev; return db.get('foo'); }).then(function (doc) { - doc.foo.baz.should.equal('baz'); - return db.remove(doc); + var transformCalledOnDelete = false; + db.transform({ + incoming: function (doc) { + transformCalledOnDelete = true; + return doc; + } + }); + + return db.remove(doc).then(function () { + transformCalledOnDelete.should.equal(false); + }); }); }); From 757c5a028068d34f9a723d0e629d011f4e83b874 Mon Sep 17 00:00:00 2001 From: Gregor Martynus Date: Tue, 15 Mar 2016 23:06:23 -0400 Subject: [PATCH 2/3] test: transforms deleted docs if `handleDeleted: true` --- test/test.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/test.js b/test/test.js index fb080c5..0618d71 100644 --- a/test/test.js +++ b/test/test.js @@ -159,6 +159,27 @@ function tests(dbName, dbType) { }); }); + it('transforms deleted docs if `handleDeleted: true` #18', function () { + var doc = {_id: 'foo', foo: {}}; + return db.put(doc).then(function (res) { + doc._rev = res.rev; + return db.get('foo'); + }).then(function (doc) { + var transformCalledOnDelete = false; + db.transform({ + incoming: function (doc) { + transformCalledOnDelete = true; + return doc; + }, + handleDeleted: true + }); + + return db.remove(doc).then(function () { + transformCalledOnDelete.should.equal(true); + }); + }); + }); + // TODO: convert sync errors in user code into async errors it.skip('handles sync errors', function () { db.transform({ From 8830b84c1e99fab4e06cfad474c77cf3d78bf6cf Mon Sep 17 00:00:00 2001 From: Gregor Martynus Date: Tue, 15 Mar 2016 23:06:33 -0400 Subject: [PATCH 3/3] feat: transforms deleted docs if `handleDeleted: true` --- index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 94f4490..3fa8798 100644 --- a/index.js +++ b/index.js @@ -3,9 +3,9 @@ var utils = require('./pouch-utils'); var wrappers = require('pouchdb-wrappers'); -function isUntransformable(doc) { +function isUntransformable(doc, config) { var isLocal = typeof doc._id === 'string' && utils.isLocalId(doc._id); - return isLocal || doc._deleted; + return isLocal || doc._deleted ? !config.handleDeleted : false; } // api.filter provided for backwards compat with the old "filter-pouch" @@ -13,13 +13,13 @@ exports.transform = exports.filter = function transform(config) { var db = this; var incoming = function (doc) { - if (!isUntransformable(doc) && config.incoming) { + if (!isUntransformable(doc, config) && config.incoming) { return config.incoming(utils.clone(doc)); } return doc; }; var outgoing = function (doc) { - if (!isUntransformable(doc) && config.outgoing) { + if (!isUntransformable(doc, config) && config.outgoing) { return config.outgoing(utils.clone(doc)); } return doc;