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

Function HttpPouch

lib/index-browser.js:6823–7796  ·  view source on GitHub ↗
(opts, callback)

Source from the content-addressed store, hash-verified

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

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…