hoodie-plugins-manager
Advanced tools
Comparing version 0.0.7 to 0.0.8
@@ -20,3 +20,9 @@ var databases_api = require('hoodie-plugins-api/lib/databases'), | ||
tm.addSource = function (name) { | ||
tm.addSource = function (name, /*optional*/callback) { | ||
callback = callback || function (err) { | ||
if (err) { | ||
console.error('Error adding source: ' + name); | ||
console.error(err); | ||
} | ||
}; | ||
function docChangeEvent(doc) { | ||
@@ -36,22 +42,24 @@ doc = databases_api.parseDoc(doc); | ||
}); | ||
feed.on('error', function (err) { | ||
console.error(err); | ||
}); | ||
feed.on('error', callback); | ||
feeds[name] = feed; | ||
} | ||
var q = { | ||
start_key: '"$"', | ||
end_key: '"${}"', | ||
include_docs: true | ||
}; | ||
couchr.get(db_url + '/_all_docs', q, function (err, body, res) { | ||
if (err) { | ||
return console.error(err); | ||
} | ||
body.rows.forEach(function (row) { | ||
if (row.doc) { | ||
docChangeEvent(row.doc); | ||
var q = { | ||
start_key: '"$"', | ||
end_key: '"${}"', | ||
include_docs: true | ||
}; | ||
couchr.get(db_url + '/_all_docs', q, function (err, body, res) { | ||
if (err) { | ||
return callback(err); | ||
} | ||
body.rows.forEach(function (row) { | ||
if (row.doc) { | ||
docChangeEvent(row.doc); | ||
} | ||
}); | ||
callback(); | ||
}); | ||
}); | ||
} | ||
else { | ||
callback(); | ||
} | ||
}; | ||
@@ -58,0 +66,0 @@ |
{ | ||
"name": "hoodie-plugins-manager", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "Run and dispatch events to Hoodie plugin server extensions", | ||
@@ -5,0 +5,0 @@ "dependencies": { |
@@ -47,2 +47,3 @@ var MultiCouch = require('multicouch'), | ||
} | ||
process.setMaxListeners(100); | ||
process.on('exit', function (code) { | ||
@@ -49,0 +50,0 @@ couch.once('stop', function () { |
@@ -449,2 +449,57 @@ var plugins_manager = require('../lib/index'), | ||
exports['#1 multiple addSource calls'] = function (test) { | ||
test.expect(9); | ||
plugins_manager.start(DEFAULT_OPTIONS, function (err, manager) { | ||
if (err) { | ||
return test.done(err); | ||
} | ||
var add_calls = 0; | ||
var hoodie = manager.createAPI({name: 'myplugin'}); | ||
hoodie.task.on('add', function (dbname, task) { | ||
add_calls++; | ||
test.equal(dbname, 'testdb'); | ||
test.equal(task.type, '$email'); | ||
test.equal(task.from, 'from'); | ||
test.equal(task.to, 'to'); | ||
}); | ||
hoodie.task.on('add:email', function (dbname, task) { | ||
test.equal(dbname, 'testdb'); | ||
test.equal(task.type, '$email'); | ||
test.equal(task.from, 'from'); | ||
test.equal(task.to, 'to'); | ||
hoodie.task.success(dbname, task, function (err) { | ||
if (err) { | ||
return test.done(err); | ||
} | ||
test.equal(add_calls, 1); | ||
// give events from the finish call time to fire | ||
setTimeout(function () { | ||
manager.stop(test.done); | ||
}, 200); | ||
}); | ||
}); | ||
hoodie.database.add('testdb', function (err, db) { | ||
if (err) { | ||
return test.done(err); | ||
} | ||
async.series([ | ||
async.apply(hoodie.task.addSource, 'testdb'), | ||
async.apply(hoodie.task.addSource, 'testdb'), | ||
async.apply(hoodie.task.addSource, 'testdb') | ||
], | ||
function (err) { | ||
if (err) { | ||
return test.done(err); | ||
} | ||
db.add('$email', {to: 'to', from: 'from'}, function (err) { | ||
if (err) { | ||
return test.done(err); | ||
} | ||
}); | ||
}); | ||
}); | ||
}); | ||
}; | ||
exports['unprocessed tasks should be handled on addSource'] = function (test) { | ||
@@ -451,0 +506,0 @@ var couchdb = DEFAULT_OPTIONS.couchdb; |
94024
13
1019