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

Function createAbstractMapReduce

lib/index.js:8182–9188  ·  view source on GitHub ↗

* Returns an "abstract" mapreduce object of the form: * * { * query: queryFun, * viewCleanup: viewCleanupFun * } * * Arguments are: * * localDoc: string * This is for the local doc that gets saved in order to track the * "dependent" DBs and clean them up for viewCleanup. I

(localDocName, mapper, reducer, ddocValidator)

Source from the content-addressed store, hash-verified

8180 * indexer is invalid.
8181 */
8182function createAbstractMapReduce(localDocName, mapper, reducer, ddocValidator) {
8183
8184 function tryMap(db, fun, doc) {
8185 // emit an event if there was an error thrown by a map function.
8186 // putting try/catches in a single function also avoids deoptimizations.
8187 try {
8188 fun(doc);
8189 } catch (e) {
8190 emitError(db, e, {fun, doc});
8191 }
8192 }
8193
8194 function tryReduce(db, fun, keys, values, rereduce) {
8195 // same as above, but returning the result or an error. there are two separate
8196 // functions to avoid extra memory allocations since the tryCode() case is used
8197 // for custom map functions (common) vs this function, which is only used for
8198 // custom reduce functions (rare)
8199 try {
8200 return {output : fun(keys, values, rereduce)};
8201 } catch (e) {
8202 emitError(db, e, {fun, keys, values, rereduce});
8203 return {error: e};
8204 }
8205 }
8206
8207 function sortByKeyThenValue(x, y) {
8208 const keyCompare = collate(x.key, y.key);
8209 return keyCompare !== 0 ? keyCompare : collate(x.value, y.value);
8210 }
8211
8212 function sliceResults(results, limit, skip) {
8213 skip = skip || 0;
8214 if (typeof limit === 'number') {
8215 return results.slice(skip, limit + skip);
8216 } else if (skip > 0) {
8217 return results.slice(skip);
8218 }
8219 return results;
8220 }
8221
8222 function rowToDocId(row) {
8223 const val = row.value;
8224 // Users can explicitly specify a joined doc _id, or it
8225 // defaults to the doc _id that emitted the key/value.
8226 const docId = (val && typeof val === 'object' && val._id) || row.id;
8227 return docId;
8228 }
8229
8230 function readAttachmentsAsBlobOrBuffer(res$$1) {
8231 for (const row of res$$1.rows) {
8232 const atts = row.doc && row.doc._attachments;
8233 if (!atts) {
8234 continue;
8235 }
8236 for (const filename of Object.keys(atts)) {
8237 const att = atts[filename];
8238 atts[filename].data = b64ToBluffer(att.data, att.content_type);
8239 }

Callers 1

index.jsFile · 0.70

Calls 5

callbackifyFunction · 0.70
customViewCleanupFunction · 0.70
isRemoteFunction · 0.70
httpViewCleanupFunction · 0.70
localViewCleanupFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…