Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (metadata.seq) {
return onGetMetadataSeq();
}
fetchMetadataSeq();
};
}
api._remote = false;
api.type = function () {
return 'idb';
};
api._id = toPromise(function (callback) {
callback(null, api._meta.instanceId);
});
api._bulkDocs = function idb_bulkDocs(req, reqOpts, callback) {
idbBulkDocs(opts, req, reqOpts, api, idb, callback);
};
// First we look up the metadata in the ids database, then we fetch the
// current revision(s) from the by sequence store
api._get = function idb_get(id, opts, callback) {
var doc;
var metadata;
var err;
var txn = opts.ctx;
if (!txn) {
var txnResult = openTransactionSafely(idb,
'COUNT(' + DOC_STORE + '.id) AS \'num\'',
[DOC_STORE, BY_SEQ_STORE],
DOC_STORE_AND_BY_SEQ_JOINER,
BY_SEQ_STORE + '.deleted=0');
tx.executeSql(sql, [], function (tx, result) {
callback(result.rows.item(0).num);
});
}
api._remote = false;
api.type = function () {
return 'websql';
};
api._id = toPromise(function (callback) {
callback(null, instanceId);
});
api._info = function (callback) {
var seq;
var docCount;
db.readTransaction(function (tx) {
getMaxSeq(tx, function (theSeq) {
seq = theSeq;
});
countDocs(tx, function (theDocCount) {
docCount = theDocCount;
});
}, websqlError(callback), function () {
callback(null, {
doc_count: docCount,
db.getUser(username, opts, function (error, user) {
if (error) {
return callback(error);
}
var url = getUsersUrl(db) + '/' + encodeURIComponent(user._id) + '?rev=' + user._rev;
var ajaxOpts = assign({
method: 'DELETE',
url: url,
headers: getBasicAuthHeaders(db),
}, opts.ajax || {});
ajaxCore(ajaxOpts, wrapError(callback));
});
});
var changePassword = toPromise(function (username, password, opts, callback) {
var db = this;
if (typeof callback === 'undefined') {
callback = typeof opts === 'undefined' ? (typeof password === 'undefined' ?
username : password) : opts;
opts = {};
}
if (['http', 'https'].indexOf(db.type()) === -1) {
return callback(new AuthError('This plugin only works for the http/https adapter. ' +
'So you should use new PouchDB("http://mysite.com:5984/mydb") instead.'));
} else if (!username) {
return callback(new AuthError('You must provide a username'));
} else if (!password) {
return callback(new AuthError('You must provide a password'));
}
db.getUser(username, opts, function (error, user) {
}
var configUrl = getConfigUrl(db, nodeName);
var url = (opts.configUrl || configUrl) + '/admins/' + encodeURIComponent(username);
var ajaxOpts = assign({
method: 'PUT',
url: url,
processData: false,
headers: getBasicAuthHeaders(db),
body: '"' + password + '"',
}, opts.ajax || {});
ajaxCore(ajaxOpts, wrapError(callback));
});
});
var deleteAdmin = toPromise(function (username, opts, callback) {
var db = this;
if (typeof callback === 'undefined') {
callback = typeof opts === 'undefined' ? username : opts;
opts = {};
}
if (['http', 'https'].indexOf(db.type()) === -1) {
return callback(new AuthError('This plugin only works for the http/https adapter. ' +
'So you should use new PouchDB("http://mysite.com:5984/mydb") instead.'));
} else if (!username) {
return callback(new AuthError('You must provide a username'));
}
db.getMembership(opts, function (error, membership) {
var nodeName;
if (error) {
if (error.error !== 'illegal_database_name') {
if (typeof requestDef !== 'object') {
return callback(new Error('you must provide search parameters to explain()'));
}
var find = isRemote(this) ? http.explain : local.explain;
find(this, requestDef, callback);
});
plugin.getIndexes = toPromise(function (callback) {
var getIndexes = isRemote(this) ? 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 = isRemote(this) ?
http.deleteIndex : local.deleteIndex;
deleteIndex(this, indexDef, callback);
});
export default plugin;
import { AuthError, getBaseUrl, getBasicAuthHeaders, getConfigUrl, wrapError } from './utils';
import ajaxCore from 'pouchdb-ajax';
import { assign, toPromise } from 'pouchdb-utils';
var getMembership = toPromise(function (opts, callback) {
var db = this;
if (typeof callback === 'undefined') {
callback = opts;
opts = {};
}
var url = getBaseUrl(db) + '/_membership';
var ajaxOpts = assign({
method: 'GET',
url: url,
headers: getBasicAuthHeaders(db),
}, opts.ajax || {});
ajaxCore(ajaxOpts, wrapError(callback));
});
var signUpAdmin = toPromise(function (username, password, opts, 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 = isRemote(this) ? http.find : local.find;
find(this, requestDef, callback);
});
plugin.explain = 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 explain()'));
}
var find = isRemote(this) ? http.explain : local.explain;
find(this, requestDef, callback);
});
plugin.getIndexes = toPromise(function (callback) {
if (opts.roles) {
user = assign(user, {roles: opts.roles});
}
var url = getUsersUrl(db) + '/' + encodeURIComponent(user._id);
var ajaxOpts = assign({
method: 'PUT',
url: url,
body: user,
headers: getBasicAuthHeaders(db),
}, opts.ajax || {});
ajaxCore(ajaxOpts, wrapError(callback));
}
var signUp = toPromise(function (username, password, opts, callback) {
var db = this;
if (typeof callback === 'undefined') {
callback = typeof opts === 'undefined' ? (typeof password === 'undefined' ?
username : password) : opts;
opts = {};
}
if (['http', 'https'].indexOf(db.type()) === -1) {
return callback(new AuthError('This plugin only works for the http/https adapter. ' +
'So you should use new PouchDB("http://mysite.com:5984/mydb") instead.'));
} else if (!username) {
return callback(new AuthError('You must provide a username'));
} else if (!password) {
return callback(new AuthError('You must provide a password'));
}
var userId = 'org.couchdb.user:' + username;
import { toPromise, isRemote } 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 = isRemote(this) ?
http.createIndex : local.createIndex;
createIndex(this, requestDef, callback);
});
plugin.find = toPromise(function (requestDef, callback) {
if (typeof callback === 'undefined') {
callback = requestDef;
requestDef = undefined;
}
'use strict';
import { AuthError, getBasicAuthHeaders, getSessionUrl, wrapError } from './utils';
import ajaxCore from 'pouchdb-ajax';
import { assign, toPromise } from 'pouchdb-utils';
var logIn = toPromise(function (username, password, opts, callback) {
var db = this;
if (typeof callback === 'undefined') {
callback = opts;
opts = {};
}
if (['http', 'https'].indexOf(db.type()) === -1) {
return callback(new AuthError('this plugin only works for the http/https adapter'));
}
if (!username) {
return callback(new AuthError('you must provide a username'));
} else if (!password) {
return callback(new AuthError('you must provide a password'));
}
var ajaxOpts = assign({