Hoodie Plugin API
File and directory structure
/hoodie-plugin-plugin_name
/pocket
hoodie.plugin_name.js
index.js
package.json
- /pocket - Extends the Pocket admin interface (contains a HTML fragment with code and styles)
- hoodie.plugin_name.js - Extends the hoodie.js front-end API
- index.js - Node.js worker for handling tasks and other events (this is just the default location, you have more options here, see below)
- package.json - The plugin's metadata and dependencies (since the plugin should function as an npm module)
The server-side component of the plugin can be left in an index.js for simplicity, but Hoodie will prefer the following, if present:
- Whatever you reference under
main
in the plugin's package.json
- Whatever you get when you
require()
the plugin root directory
Writing workers
module.exports = function (hoodie, callback) {
};
hoodie.request(method, path, options, callback)
hoodie.config.get(key)
hoodie.config.set(key, value)
hoodie.database.findAll(callback)
hoodie.database.add(name, callback)
hoodie.database.remove(name, callback)
hoodie.database(name) => db
db.add(type, attrs, callback)
db.update(type, id, changed_attrs, callback)
db.find(type, id, callback)
db.findAll(callback)
db.findAll(type, callback)
db.remove(type, id, callback)
db.removeAll(type, callback)
db.grantPublicReadAccess(callback)
db.grantPublicReadAccess(callback)
db.grantReadAccess(account_type, account_id, callback)
db.grantWriteAccess(account_type, account_id, callback)
db.revokePublicReadAccess(callback)
db.revokePublicWriteAccess(callback)
db.revokeReadAccess(account_type, account_id, callback)
db.revokeWriteAccess(account_type, account_id, callback)
db.addIndex(name, {map: .., reduce: ..}, callback)
db.removeIndex(name, callback)
db.query(index, options, callback)
hoodie.account.add(type, attrs, callback)
hoodie.account.update(type, id, changed_attrs, callback)
hoodie.account.find(type, id, callback)
hoodie.account.findAll(callback)
hoodie.account.findAll(type, callback)
hoodie.account.remove(type, id, callback)
hoodie.account.removeAll(type, callback)
hoodie.account.on('change', handler)
hoodie.account.on('change:type', handler)
hoodie.account.on('change:$passwordReset', function(object) {
})
hoodie.task.on('change', function (db, doc) { ... })
hoodie.task.on('change:type', function (db, doc) { ... })
hoodie.task.addSource( databaseName )
hoodie.task.removeSource( databaseName )