(db, fun, opts)
| 8312 | } |
| 8313 | |
| 8314 | async function httpQuery(db, fun, opts) { |
| 8315 | // List of parameters to add to the PUT request |
| 8316 | let params = []; |
| 8317 | let body; |
| 8318 | let method = 'GET'; |
| 8319 | let ok; |
| 8320 | |
| 8321 | // If opts.reduce exists and is defined, then add it to the list |
| 8322 | // of parameters. |
| 8323 | // If reduce=false then the results are that of only the map function |
| 8324 | // not the final result of map and reduce. |
| 8325 | addHttpParam('reduce', opts, params); |
| 8326 | addHttpParam('include_docs', opts, params); |
| 8327 | addHttpParam('attachments', opts, params); |
| 8328 | addHttpParam('limit', opts, params); |
| 8329 | addHttpParam('descending', opts, params); |
| 8330 | addHttpParam('group', opts, params); |
| 8331 | addHttpParam('group_level', opts, params); |
| 8332 | addHttpParam('skip', opts, params); |
| 8333 | addHttpParam('stale', opts, params); |
| 8334 | addHttpParam('conflicts', opts, params); |
| 8335 | addHttpParam('startkey', opts, params, true); |
| 8336 | addHttpParam('start_key', opts, params, true); |
| 8337 | addHttpParam('endkey', opts, params, true); |
| 8338 | addHttpParam('end_key', opts, params, true); |
| 8339 | addHttpParam('inclusive_end', opts, params); |
| 8340 | addHttpParam('key', opts, params, true); |
| 8341 | addHttpParam('update_seq', opts, params); |
| 8342 | |
| 8343 | // Format the list of parameters into a valid URI query string |
| 8344 | params = params.join('&'); |
| 8345 | params = params === '' ? '' : '?' + params; |
| 8346 | |
| 8347 | // If keys are supplied, issue a POST to circumvent GET query string limits |
| 8348 | // see http://wiki.apache.org/couchdb/HTTP_view_API#Querying_Options |
| 8349 | if (typeof opts.keys !== 'undefined') { |
| 8350 | const MAX_URL_LENGTH = 2000; |
| 8351 | // according to http://stackoverflow.com/a/417184/680742, |
| 8352 | // the de facto URL length limit is 2000 characters |
| 8353 | |
| 8354 | const keysAsString = `keys=${encodeURIComponent(JSON.stringify(opts.keys))}`; |
| 8355 | if (keysAsString.length + params.length + 1 <= MAX_URL_LENGTH) { |
| 8356 | // If the keys are short enough, do a GET. we do this to work around |
| 8357 | // Safari not understanding 304s on POSTs (see pouchdb/pouchdb#1239) |
| 8358 | params += (params[0] === '?' ? '&' : '?') + keysAsString; |
| 8359 | } else { |
| 8360 | method = 'POST'; |
| 8361 | if (typeof fun === 'string') { |
| 8362 | body = {keys: opts.keys}; |
| 8363 | } else { // fun is {map : mapfun}, so append to this |
| 8364 | fun.keys = opts.keys; |
| 8365 | } |
| 8366 | } |
| 8367 | } |
| 8368 | |
| 8369 | // We are referencing a query defined in the design doc |
| 8370 | if (typeof fun === 'string') { |
| 8371 | const parts = parseViewName(fun); |
no test coverage detected
searching dependent graphs…