diff --git a/couch-replicator-api.js b/couch-replicator-api.js index 11c3a5d..2440cf1 100644 --- a/couch-replicator-api.js +++ b/couch-replicator-api.js @@ -1,31 +1,42 @@ - -function CouchReplicatorApi (url, user, pass, db) { +/** + * @constructor CouchReplicatorApi + * @param {string} url - The url of couch + * @param {string} user - The username of couch + * @param {string} pass - The password of couch + * @param {string|false} db - The database of the replication (may be false if doc_id param is set) + * @param {string|false} [doc_id] - The doc_id of the replication (may be false if db param is set) (optional) + * @returns {CouchReplicatorApi} + */ +function CouchReplicatorApi (url, user, pass, db, doc_id) { if (!(this instanceof CouchReplicatorApi)) return new CouchReplicatorApi(url, user, pass) - this.url = url - this.user = user - this.pass = pass - this.db = db + this.url = url + this.user = user + this.pass = pass + this.db = db + this.doc_id = false + if(doc_id) + this.doc_id = doc_id } CouchReplicatorApi.prototype.status = function (callback) { - CouchReplicatorApi.status(this.url, this.user, this.pass, this.db, callback) + CouchReplicatorApi.status(this.url, this.user, this.pass, this.db, this.doc_id, callback) } CouchReplicatorApi.prototype.get = function (callback) { - CouchReplicatorApi.get(this.url, this.user, this.pass, this.db, callback) + CouchReplicatorApi.get(this.url, this.user, this.pass, (this.doc_id?this.doc_id:this.db), callback) } CouchReplicatorApi.prototype.put = function (doc, callback) { - CouchReplicatorApi.put(this.url, this.user, this.pass, this.db, doc, callback) + CouchReplicatorApi.put(this.url, this.user, this.pass, (this.doc_id?this.doc_id:this.db), doc, callback) } CouchReplicatorApi.prototype.del = function (rev, callback) { - CouchReplicatorApi.del(this.url, this.user, this.pass, this.db, rev, callback) + CouchReplicatorApi.del(this.url, this.user, this.pass, (this.doc_id?this.doc_id:this.db), rev, callback) } diff --git a/status.js b/status.js index 726df13..c961963 100644 --- a/status.js +++ b/status.js @@ -4,7 +4,12 @@ const hyperquest = require('hyperquest') , statusUrl = '/_active_tasks' -function status (couch, user, pass, target, callback) { +function status (couch, user, pass, target, doc_id, callback) { + if (typeof doc_id == 'function') { + var callback = doc_id + , doc_id = false + } + hyperquest(couch + statusUrl, { auth: user + ':' + pass }).pipe(bl(function (err, data) { if (err) return callback(err) @@ -18,6 +23,8 @@ function status (couch, user, pass, target, callback) { return callback(new Error('Unexpected response from couch: ' + data.toString())) _data = _data.filter(function (s) { + if(doc_id) + return s && s.type == 'replication' && s.doc_id == doc_id return s && s.type == 'replication' && s.target == target })[0]