MCPcopy Index your code
hub / github.com/apache/pouchdb / HttpPouch

Function HttpPouch

lib/index.js:6815–7786  ·  view source on GitHub ↗
(opts, callback)

Source from the content-addressed store, hash-verified

6813
6814// Implements the PouchDB API for dealing with CouchDB instances over HTTP
6815function HttpPouch(opts, callback) {
6816
6817 // The functions that will be publicly available for HttpPouch
6818 const api = this;
6819
6820 const host = getHost(opts.name, opts);
6821 const dbUrl = genDBUrl(host, '');
6822
6823 opts = clone(opts);
6824
6825 const ourFetch = async function (url, options) {
6826
6827 options = options || {};
6828 options.headers = options.headers || new nodeFetch.Headers();
6829
6830 options.credentials = 'include';
6831
6832 if (opts.auth || host.auth) {
6833 const nAuth = opts.auth || host.auth;
6834 const str = nAuth.username + ':' + nAuth.password;
6835 const token = thisBtoa(unescape(encodeURIComponent(str)));
6836 options.headers.set('Authorization', 'Basic ' + token);
6837 }
6838
6839 const headers = opts.headers || {};
6840 Object.keys(headers).forEach(function (key) {
6841 options.headers.append(key, headers[key]);
6842 });
6843
6844 /* istanbul ignore if */
6845 if (shouldCacheBust(options)) {
6846 url += (url.indexOf('?') === -1 ? '?' : '&') + '_nonce=' + Date.now();
6847 }
6848
6849 const fetchFun = opts.fetch || fetch;
6850 return await fetchFun(url, options);
6851 };
6852
6853 function adapterFun$$1(name, fun) {
6854 return adapterFun(name, function (...args) {
6855 setup().then(function () {
6856 return fun.apply(this, args);
6857 }).catch(function (e) {
6858 const callback = args.pop();
6859 callback(e);
6860 });
6861 }).bind(api);
6862 }
6863
6864 async function fetchJSON(url, options) {
6865
6866 const result = {};
6867
6868 options = options || {};
6869 options.headers = options.headers || new nodeFetch.Headers();
6870
6871 if (!options.headers.get('Content-Type')) {
6872 options.headers.set('Content-Type', 'application/json');

Callers

nothing calls this directly

Calls 15

getHostFunction · 0.70
genDBUrlFunction · 0.70
cloneFunction · 0.70
adapterFun$$1Function · 0.70
ourFetchFunction · 0.70
genUrlFunction · 0.70
fetchJSONFunction · 0.70
pingFunction · 0.70
adapterFunFunction · 0.70
doBulkGetFunction · 0.70
resFunction · 0.70
doBulkGetShimFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…