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