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

Function httpQuery

lib/index.js:8319–8432  ·  view source on GitHub ↗
(db, fun, opts)

Source from the content-addressed store, hash-verified

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