Skip to content

Commit

Permalink
(#41) - fix pouchdb 5.0.0 support
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanlawson committed Oct 11, 2015
1 parent 51a1070 commit fc17211
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 43 deletions.
2 changes: 1 addition & 1 deletion index.js → lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ exports.plugin.dump = utils.toPromise(function (writableStream, opts, callback)
var PouchDB = self.constructor;

var output = new PouchDB(self._db_name, {
stream: writableStream,
adapter: 'writableStream'
});
output.setupStream(writableStream);

var chain = self.info().then(function (info) {
var header = {
Expand Down
13 changes: 3 additions & 10 deletions pouch-utils.js → lib/pouch-utils.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
'use strict';

var Promise;
/* istanbul ignore next */
if (typeof window !== 'undefined' && window.PouchDB) {
Promise = window.PouchDB.utils.Promise;
} else {
Promise = typeof global.Promise === 'function' ? global.Promise : require('lie');
}
var Promise = require('pouchdb/extras/promise');

/* istanbul ignore next */
exports.once = function (fun) {
var called = false;
Expand Down Expand Up @@ -79,6 +74,4 @@ exports.toPromise = function (func) {
});
};

exports.extend = require('pouchdb-extend');
exports.inherits = require('inherits');
exports.Promise = Promise;
exports.inherits = require('inherits');
File renamed without changes.
1 change: 1 addition & 0 deletions lib/version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./../package.json').version;
54 changes: 33 additions & 21 deletions writable-stream.js → lib/writable-stream.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

var utils = require('./pouch-utils');
var Promise = require('pouchdb/extras/promise');
var ERROR_REV_CONFLICT = {
status: 409,
name: 'conflict',
Expand All @@ -13,23 +14,25 @@ var ERROR_MISSING_DOC = {
message: 'missing'
};
function WritableStreamPouch(opts, callback) {

this.instanceId = Math.random().toString();
this.stream = opts.stream;
this.ldj = ldj.serialize();
this.ldj.pipe(this.stream);
this.localStore = {};
var api = this;
process.nextTick(function () {
callback(null, api);
});
api.instanceId = Math.random().toString();
api.ldj = ldj.serialize();
api.localStore = {};
api.originalName = opts.name;

// TODO: I would pass this in as a constructor opt, but
// PouchDB changed how it clones in 5.0.0 so this broke
api.setupStream = function (stream) {
api.ldj.pipe(stream);
};

/* istanbul ignore next */
api.type = function () {
return 'readable-stream';
return 'writableStream';
};

api._id = utils.toPromise(function (callback) {
callback(null, this.instanceId);
callback(null, api.instanceId);
});

api._bulkDocs = function (req, opts, callback) {
Expand All @@ -50,7 +53,7 @@ function WritableStreamPouch(opts, callback) {
});
} else {
// writing local docs for replication
utils.Promise.all(docs.map(function (doc) {
Promise.all(docs.map(function (doc) {
self.localStore[doc._id] = doc;
})).then(function (res) {
callback(null, res);
Expand All @@ -59,6 +62,7 @@ function WritableStreamPouch(opts, callback) {
});
}
};

api._getRevisionTree = function (docId, callback) {
process.nextTick(function () {
callback(ERROR_MISSING_DOC);
Expand Down Expand Up @@ -118,6 +122,7 @@ function WritableStreamPouch(opts, callback) {
}
});
};

/* istanbul ignore next */
api._removeLocal = function (doc, callback) {
var self = this;
Expand All @@ -131,19 +136,26 @@ function WritableStreamPouch(opts, callback) {
}
});
};

/* istanbul ignore next */
api._destroy = function (opts, callback) {
if (typeof opts === 'function') {
callback = opts;
opts = {};
}
WritableStreamPouch.Changes.removeAllListeners(api.originalName);
process.nextTick(function () {
callback(null, {'ok': true});
});
};

process.nextTick(function () {
callback(null, api);
});
}

WritableStreamPouch.valid = function () {
return true;
};
/* istanbul ignore next */
WritableStreamPouch.destroy = utils.toPromise(function (name, opts, callback) {
WritableStreamPouch.Changes.removeAllListeners(name);
process.nextTick(function () {
callback(null, {'ok': true});
});
});

//WritableStreamPouch.Changes = new utils.Changes();

module.exports = WritableStreamPouch;
19 changes: 9 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "pouchdb-replication-stream",
"version": "1.2.4",
"description": "PouchDB/CouchDB replication as a stream",
"main": "index.js",
"main": "lib/index.js",
"repository": {
"type": "git",
"url": "git://github.com/nolanlawson/pouchdb-replication-stream.git"
Expand All @@ -24,10 +24,10 @@
"scripts": {
"test-node": "TEST_DB=testdb,http://localhost:5984/testdb istanbul test ./node_modules/mocha/bin/_mocha test/test.js -- -R spec",
"test-browser": "./bin/test-browser.js",
"jshint": "jshint -c .jshintrc *.js test/test.js",
"jshint": "jshint -c .jshintrc lib test/test.js",
"test": "npm run jshint && ./bin/run-test.sh",
"build": "mkdirp dist && npm run browserify && npm run min",
"browserify": "browserify index.js | ./bin/es3ify.js | derequire > dist/pouchdb.replication-stream.js",
"browserify": "browserify . | ./bin/es3ify.js | derequire > dist/pouchdb.replication-stream.js",
"min": "uglifyjs dist/pouchdb.replication-stream.js -mc > dist/pouchdb.replication-stream.min.js",
"dev": "browserify test/test.js > test/test-bundle.js && npm run dev-server",
"dev-server": "./bin/dev-server.js",
Expand All @@ -40,25 +40,24 @@
"lie": "^2.6.0",
"lodash": "^3.3.0",
"pouch-stream": "^0.4.0",
"pouchdb-extend": "^0.1.2",
"through2": "^0.6.1"
},
"devDependencies": {
"bluebird": "^1.0.7",
"browserify": "^9.0.8",
"chai": "~1.8.1",
"chai-as-promised": "~4.1.0",
"browserify": "^11.2.0",
"chai": "^3.3.0",
"chai-as-promised": "^5.1.0",
"derequire": "^2.0.0",
"es3ify": "^0.1.3",
"http-server": "~0.5.5",
"http-server": "~0.8.5",
"istanbul": "^0.2.7",
"jshint": "~2.3.0",
"jshint": "^2.3.0",
"memorystream": "^0.3.0",
"mkdirp": "^0.5.0",
"mocha": "~1.18",
"noms": "0.0.0",
"phantomjs": "^1.9.7-5",
"pouchdb": "pouchdb/pouchdb",
"pouchdb": "^5.0.0",
"random-document-stream": "0.0.0",
"request": "^2.36.0",
"sauce-connect-launcher": "^0.4.2",
Expand Down
1 change: 0 additions & 1 deletion version.js

This file was deleted.

0 comments on commit fc17211

Please sign in to comment.