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

Function httpQuery

lib/index-browser.es.js:8277–8390  ·  view source on GitHub ↗
(db, fun, opts)

Source from the content-addressed store, hash-verified

8275 }
8276
8277 async function httpQuery(db, fun, opts) {
8278 // List of parameters to add to the PUT request
8279 let params = [];
8280 let body;
8281 let method = 'GET';
8282 let ok;
8283
8284 // If opts.reduce exists and is defined, then add it to the list
8285 // of parameters.
8286 // If reduce=false then the results are that of only the map function
8287 // not the final result of map and reduce.
8288 addHttpParam('reduce', opts, params);
8289 addHttpParam('include_docs', opts, params);
8290 addHttpParam('attachments', opts, params);
8291 addHttpParam('limit', opts, params);
8292 addHttpParam('descending', opts, params);
8293 addHttpParam('group', opts, params);
8294 addHttpParam('group_level', opts, params);
8295 addHttpParam('skip', opts, params);
8296 addHttpParam('stale', opts, params);
8297 addHttpParam('conflicts', opts, params);
8298 addHttpParam('startkey', opts, params, true);
8299 addHttpParam('start_key', opts, params, true);
8300 addHttpParam('endkey', opts, params, true);
8301 addHttpParam('end_key', opts, params, true);
8302 addHttpParam('inclusive_end', opts, params);
8303 addHttpParam('key', opts, params, true);
8304 addHttpParam('update_seq', opts, params);
8305
8306 // Format the list of parameters into a valid URI query string
8307 params = params.join('&');
8308 params = params === '' ? '' : '?' + params;
8309
8310 // If keys are supplied, issue a POST to circumvent GET query string limits
8311 // see http://wiki.apache.org/couchdb/HTTP_view_API#Querying_Options
8312 if (typeof opts.keys !== 'undefined') {
8313 const MAX_URL_LENGTH = 2000;
8314 // according to http://stackoverflow.com/a/417184/680742,
8315 // the de facto URL length limit is 2000 characters
8316
8317 const keysAsString = `keys=${encodeURIComponent(JSON.stringify(opts.keys))}`;
8318 if (keysAsString.length + params.length + 1 <= MAX_URL_LENGTH) {
8319 // If the keys are short enough, do a GET. we do this to work around
8320 // Safari not understanding 304s on POSTs (see pouchdb/pouchdb#1239)
8321 params += (params[0] === '?' ? '&' : '?') + keysAsString;
8322 } else {
8323 method = 'POST';
8324 if (typeof fun === 'string') {
8325 body = {keys: opts.keys};
8326 } else { // fun is {map : mapfun}, so append to this
8327 fun.keys = opts.keys;
8328 }
8329 }
8330 }
8331
8332 // We are referencing a query defined in the design doc
8333 if (typeof fun === 'string') {
8334 const parts = parseViewName(fun);

Callers 1

queryPromisedFunction · 0.70

Calls 5

addHttpParamFunction · 0.70
parseViewNameFunction · 0.70
postprocessAttachmentsFunction · 0.70
toStringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…