blob: 0bedd51f855d374abb8b82391a3eec1f0015ca46 [file] [log] [blame]
import { toPromise } from 'pouchdb-utils';
import * as http from './adapters/http/index';
import * as local from './adapters/local/index';
var plugin = {};
plugin.createIndex = toPromise(function (requestDef, callback) {
if (typeof requestDef !== 'object') {
return callback(new Error('you must provide an index to create'));
}
var createIndex = this.type() === 'http' ?
http.createIndex : local.createIndex;
createIndex(this, requestDef, callback);
});
plugin.find = toPromise(function (requestDef, callback) {
if (typeof callback === 'undefined') {
callback = requestDef;
requestDef = undefined;
}
if (typeof requestDef !== 'object') {
return callback(new Error('you must provide search parameters to find()'));
}
var find = this.type() === 'http' ? http.find : local.find;
find(this, requestDef, callback);
});
plugin.getIndexes = toPromise(function (callback) {
var getIndexes = this.type() === 'http' ? http.getIndexes : local.getIndexes;
getIndexes(this, callback);
});
plugin.deleteIndex = toPromise(function (indexDef, callback) {
if (typeof indexDef !== 'object') {
return callback(new Error('you must provide an index to delete'));
}
var deleteIndex = this.type() === 'http' ?
http.deleteIndex : local.deleteIndex;
deleteIndex(this, indexDef, callback);
});
export default plugin;