PageSourceSearch

https://send2boox.com/static/js/pouchdb-abstract-mapreduce-DqzPn1tM.js

js send2boox.com collected 2026-09-28 07:01:11 UTC 12,934 bytes, 4 lines download raw bytes

1import{b as Te}from"./pouchdb-binary-utils-Cpnoy8M5.js";import{c as R,t as D,n as re,p as Ve}from"./pouchdb-collate-BelqQoNM.js";import{g as se}from"./pouchdb-errors-Nr-dVszh.js";import{h as Z}from"./pouchdb-fetch-CVv6zVb8.js";import{i as oe,n as De,u as Ie,g as ce}from"./pouchdb-utils-Bco8-zda.js";import{s as Ne}from"./pouchdb-md5-TKLkGpLu.js";import{c as Se,p as Pe,f as Ke,N as Oe,Q as j,s as W,u as ie,m as ee,B as xe}from"./pouchdb-mapreduce-utils-BuWW8dPW.js";class ne{constructor(){this.promise=Promise.resolve()}add(p){return this.promise=this.promise.catch(()=>{}).then(()=>p()),this.promise}finish(){return this.promise}}function ue(d){if(!d)return"undefined";switch(typeof d){case"function":return d.toString();case"string":return d.toString();default:return JSON.stringify(d)}}function Be(d,p){return ue(d)+ue(p)+"undefined"}async function ae(d,p,S,A,M,J){const I=Be(S,A);let q;if(!M&&(q=d._cachedViews=d._cachedViews||{},q[I]))return q[I];const C=d.info().then(async function($){const N=$.db_name+"-mrview-"+(M?"temp":Ne(I));function m(T){T.views=T.views||{};let O=p;O.indexOf("/")===-1&&(O=p+"/"+p);const G=T.views[O]=T.views[O]||{};if(!G[N])return G[N]=!0,T}await Ie(d,"_local/"+J,m);const F=(await d.registerDependentDatabase(N)).db;F.auto_compaction=!0;const P={name:N,db:F,sourceDB:d,adapter:d.adapter,mapFun:S,reduceFun:A};let K;try{K=await P.db.get("_local/lastSeq")}catch(T){if(T.status!==404)throw T}return P.seq=K?K.seq:0,q&&P.db.once("destroyed",function(){delete q[I]}),P});return q&&(q[I]=C),C}const fe={},de=new ne,Ae=50;function te(d){return d.indexOf("/")===-1?[d,d]:d.split("/")}function Ce(d){return d.length===1&&/^1-/.test(d[0].rev)}function le(d,p,S){try{d.emit("error",p)}catch{ce("error",`The user's map/reduce function threw an uncaught error.
2You can debug this error by doing:
3myDatabase.on('error', function (err) { debugger; });
4Please double-check your map/reduce function.`),ce("error",p,S)}}function ze(d,p,S,A){function M(e,t,n){try{t(n)}catch(r){le(e,r,{fun:t,doc:n})}}function J(e,t,n,r,o){try{return{output:t(n,r,o)}}catch(u){return le(e,u,{fun:t,keys:n,values:r,rereduce:o}),{error:u}}}function I(e,t){const n=R(e.key,t.key);return n!==0?n:R(e.value,t.value)}function q(e,t,n){return n=n||0,typeof t=="number"?e.slice(n,t+n):n>0?e.slice(n):e}function C(e){const t=e.value;return t&&typeof t=="object"&&t._id||e.id}function $(e){for(const t of e.rows){const n=t.doc&&t.doc._attachments;if(n)for(const r of Object.keys(n)){const o=n[r];n[r].data=Te(o.data,o.content_type)}}}function N(e){return function(t){return e.include_docs&&e.attachments&&e.binary&&$(t),t}}function m(e,t,n,r){let o=t[e];typeof o<"u"&&(r&&(o=encodeURIComponent(JSON.stringify(o))),n.push(e+"="+o))}function Q(e){if(typeof e<"u"){const t=Number(e);return!isNaN(t)&&t===parseInt(e,10)?t:e}}function F(e){return e.group_level=Q(e.group_level),e.limit=Q(e.limit),e.skip=Q(e.skip),e}function P(e){if(e){if(typeof e!="number")return new j(`Invalid value for integer: "${e}"`);if(e<0)return new j(`Invalid value for positive integer: "${e}"`)}}function K(e,t){const n=e.descending?"endkey":"startkey",r=e.descending?"startkey":"endkey";if(typeof e[n]<"u"&&typeof e[r]<"u"&&R(e[n],e[r])>0)throw new j("No rows can match your key range, reverse your start_key and end_key or set {descending : true}");if(t.reduce&&e.reduce!==!1){if(e.include_docs)throw new j("{include_docs:true} is invalid for reduce");if(e.keys&&e.keys.length>1&&!e.group&&!e.group_level)throw new j("Multi-key fetches for reduce views must use {group: true}")}for(const o of["group_level","limit","skip"]){const u=P(e[o]);if(u)throw u}}async function T(e,t,n){let r=[],o,u="GET",_;if(m("reduce",n,r),m("include_docs",n,r),m("attachments",n,r),m("limit",n,r),m("descending",n,r),m("group",n,r),m("group_level",n,r),m("skip",n,r),m("stale",n,r),m("conflicts",n,r),m("startkey",n,r,!0),m("start_key",n,r,!0),m("endkey",n,r,!0),m("end_key",n,r,!0),m("inclusive_end",n,r),m("key",n,r,!0),m("update_seq",n,r),r=r.join("&"),r=r===""?"":"?"+r,typeof n.keys<"u"){const l=`keys=${encodeURIComponent(JSON.stringify(n.keys))}`;l.length+r.length+1<=2e3?r+=(r[0]==="?"?"&":"?")+l:(u="POST",typeof t=="string"?o={keys:n.keys}:t.keys=n.keys)}if(typeof t=="string"){const i=te(t),l=await e.fetch("_design/"+i[0]+"/_view/"+i[1]+r,{headers:new Z({"Content-Type":"application/json"}),method:u,body:JSON.stringify(o)});_=l.ok;const f=await l.json();if(!_)throw f.status=l.status,se(f);for(const a of f.rows)if(a.value&&a.value.error&&a.value.error==="builtin_reduce_error")throw new Error(a.reason);return new Promise(function(a){a(f)}).then(N(n))}o=o||{};for(const i of Object.keys(t))Array.isArray(t[i])?o[i]=t[i]:o[i]=t[i].toString();const s=await e.fetch("_temp_view"+r,{headers:new Z({"Content-Type":"application/json"}),method:"POST",body:JSON.stringify(o)});_=s.ok;const c=await s.json();if(!_)throw c.status=s.status,se(c);return new Promise(function(i){i(c)}).then(N(n))}function O(e,t,n){return new Promise(function(r,o){e._query(t,n,function(u,_){if(u)return o(u);r(_)})})}function G(e){return new Promise(function(t,n){e._viewCleanup(function(r,o){if(r)return n(r);t(o)})})}function x(e){return function(t){if(t.status===404)return e;throw t}}async function ye(e,t,n){const r="_local/doc_"+e,o={_id:r,keys:[]},u=n.get(e),_=u[0],s=u[1];function c(){return Ce(s)?Promise.resolve(o):t.db.get(r).catch(x(o)
4)}function i(w){return w.keys.length?t.db.allDocs({keys:w.keys,include_docs:!0}):Promise.resolve({rows:[]})}function l(w,V){const B=[],z=new Set;for(const g of V.rows){const y=g.doc;if(y&&(B.push(y),z.add(y._id),y._deleted=!_.has(y._id),!y._deleted)){const h=_.get(y._id);"value"in h&&(y.value=h.value)}}const H=ee(_);for(const g of H)if(!z.has(g)){const y={_id:g},h=_.get(g);"value"in h&&(y.value=h.value),B.push(y)}return w.keys=ie(H.concat(w.keys)),B.push(w),B}const f=await c(),a=await i(f);return l(f,a)}function he(e){return e.sourceDB.get("_local/purges").then(function(t){const n=t.purgeSeq;return e.db.get("_local/purgeSeq").then(function(r){return r._rev}).catch(x(void 0)).then(function(r){return e.db.put({_id:"_local/purgeSeq",_rev:r,purgeSeq:n})})}).catch(function(t){if(t.status!==404)throw t})}function ge(e,t,n){var r="_local/lastSeq";return e.db.get(r).catch(x({_id:r,seq:0})).then(function(o){var u=ee(t);return Promise.all(u.map(function(_){return ye(_,e,t)})).then(function(_){var s=_.flat();return o.seq=n,s.push(o),e.db.bulkDocs({docs:s})}).then(()=>he(e))})}function L(e){const t=typeof e=="string"?e:e.name;let n=fe[t];return n||(n=fe[t]=new ne),n}async function U(e,t){return W(L(e),function(){return _e(e,t)})()}async function _e(e,t){let n,r,o;function u(g,y){const h={id:r._id,key:re(g)};typeof y<"u"&&y!==null&&(h.value=re(y)),n.push(h)}const _=p(e.mapFun,u);let s=e.seq||0;function c(){return e.sourceDB.info().then(function(g){o=e.sourceDB.activeTasks.add({name:"view_indexing",total_items:g.update_seq-s})})}function i(g,y){return function(){return ge(e,g,y)}}let l=0;const f={view:e.name,indexed_docs:l};e.sourceDB.emit("indexing",f);const a=new ne;async function w(){const g=await e.sourceDB.changes({return_docs:!0,conflicts:!0,include_docs:!0,style:"all_docs",since:s,limit:t.changes_batch_size}),y=await V();return B(g,y)}function V(){return e.db.get("_local/purgeSeq").then(function(g){return g.purgeSeq}).catch(x(-1)).then(function(g){return e.sourceDB.get("_local/purges").then(function(y){const h=y.purges.filter(function(v,k){return k>g}).map(v=>v.docId),b=h.filter(function(v,k){return h.indexOf(v)===k});return Promise.all(b.map(function(v){return e.sourceDB.get(v).then(function(k){return{docId:v,doc:k}}).catch(x({docId:v}))}))}).catch(x([]))})}function B(g,y){const h=g.results;if(!h.length&&!y.length)return;for(const k of y)if(h.findIndex(function(E){return E.id===k.docId})<0){const E={_id:k.docId,doc:{_id:k.docId,_deleted:1},changes:[]};k.doc&&(E.doc=k.doc,E.changes.push({rev:k.doc._rev})),h.push(E)}const b=z(h);a.add(i(b,s)),l=l+h.length;const v={view:e.name,last_seq:g.last_seq,results_count:h.length,indexed_docs:l};if(e.sourceDB.emit("indexing",v),e.sourceDB.activeTasks.update(o,{completed_items:l}),!(h.length<t.changes_batch_size))return w()}function z(g){const y=new Map;for(const h of g){if(h.doc._id[0]!=="_"){n=[],r=h.doc,r._deleted||M(e.sourceDB,_,r),n.sort(I);const b=H(n);y.set(h.doc._id,[b,h.changes])}s=h.seq}return y}function H(g){const y=new Map;let h;for(let b=0,v=g.length;b<v;b++){const k=g[b],Y=[k.key,k.id];b>0&&R(k.key,h)===0&&Y.push(b),y.set(D(Y),k),h=k.key}return y}try{await c(),await w(),await a.finish(),e.seq=s,e.sourceDB.activeTasks.remove(o)}catch(g){e.sourceDB.activeTasks.remove(o,g)}}function me(e,t,n){n.group_level===0&&delete n.group_level;const r=n.group||n.group_level,o=S(e.reduceFun),u=[],_=isNaN(n.group_level)?Number.POSITIVE_INFINITY:n.group_level;for(const s of t){const c=u[u.length-1];let i=r?s.key:null;if(r&&Array.isArray(i)&&(i=i.slice(0,_)),c&&R(c.groupKey,i)===0){c.keys.push([s.key,s.id]),c.values.push(s.value);continue}u.push({keys:[[s.key,s.id]],values:[s.value],groupKey:i})}t=[];for(const s of u){const c=J(e.sourceDB,o,s.keys,s.values,!1);if(c.error&&c.error instanceof xe)throw c.error;t.push({value:c.error?null:c.output,key:s.groupKey})}return{rows:q(t,n.limit,n.skip)}}function X(e,t){return W(L(e),function(){return ke(e,t)})()}async function ke(e,t){let n;const r=e.reduceFun&&t.reduce!==!1,o=t.skip||0;typeof t.keys<"u"&&!t.keys.length&&(t.limit=0,delete t.keys);async function u(s){s.include_docs=!0;const c=await e.db.allDocs(s);return n=c.total_rows,c.rows.map(function(i){if("value"in i.doc&&typeof i.doc.value=="object"&&i.doc.value!==null){const f=Object.keys(i.doc.value).sort(),a=["id","key","value"];if(!(f<a||f>a))return i.doc.value}const l=Ve(i.doc._id);return{key:l[0],id:l[1],value:"value"in i.doc?i.doc.value:null}})}async function _(s){let c;if(r?c=me(e,s,t):typeof t.keys>"u"?c={total_rows:n,offset:o,rows:s}:c={total_rows:n,offset:o,rows:q(s,t.limit,t.skip)},t.update_seq&&(c.update_seq=e.seq),t.include_docs){const i=ie(s.map(C)),l=await e.sourceDB.allDocs({keys:i,include_docs:!0,conflicts:t.conflicts,attachments:t.attachments,binary:t.binary}),f=new Map;for(const a of l.rows)f.set(a.id,a.doc);for(const a of s){const w=C(a),V=f.get(w);V&&(a.doc=V)}}return c}if(typeof t.keys<"u"){const c=t.keys.map(function(f){const a={startkey:D([f]),endkey:D([f,{}])};
4return t.update_seq&&(a.update_seq=!0),u(a)}),l=(await Promise.all(c)).flat();return _(l)}else{const s={descending:t.descending};t.update_seq&&(s.update_seq=!0);let c,i;if("start_key"in t&&(c=t.start_key),"startkey"in t&&(c=t.startkey),"end_key"in t&&(i=t.end_key),"endkey"in t&&(i=t.endkey),typeof c<"u"&&(s.startkey=t.descending?D([c,{}]):D([c])),typeof i<"u"){let f=t.inclusive_end!==!1;t.descending&&(f=!f),s.endkey=D(f?[i,{}]:[i])}if(typeof t.key<"u"){const f=D([t.key]),a=D([t.key,{}]);s.descending?(s.endkey=f,s.startkey=a):(s.startkey=f,s.endkey=a)}r||(typeof t.limit=="number"&&(s.limit=t.limit),s.skip=o);const l=await u(s);return _(l)}}async function we(e){return(await e.fetch("_view_cleanup",{headers:new Z({"Content-Type":"application/json"}),method:"POST"})).json()}async function pe(e){try{const t=await e.get("_local/"+d),n=new Map;for(const c of Object.keys(t.views)){const i=te(c),l="_design/"+i[0],f=i[1];let a=n.get(l);a||(a=new Set,n.set(l,a)),a.add(f)}const r={keys:ee(n),include_docs:!0},o=await e.allDocs(r),u={};for(const c of o.rows){const i=c.key.substring(8);for(const l of n.get(c.key)){let f=i+"/"+l;t.views[f]||(f=l);const a=Object.keys(t.views[f]),w=c.doc&&c.doc.views&&c.doc.views[l];for(const V of a)u[V]=u[V]||w}}const s=Object.keys(u).filter(function(c){return!u[c]}).map(function(c){return W(L(c),function(){return new e.constructor(c,e.__opts).destroy()})()});return Promise.all(s).then(function(){return{ok:!0}})}catch(t){if(t.status===404)return{ok:!0};throw t}}async function ve(e,t,n){if(typeof e._query=="function")return O(e,t,n);if(oe(e))return T(e,t,n);const r={changes_batch_size:e.__opts.view_update_changes_batch_size||Ae};if(typeof t!="string")return K(n,t),de.add(async function(){const o=await ae(e,"temp_view/temp_view",t.map,t.reduce,!0,d);return Ke(U(o,r).then(function(){return X(o,n)}),function(){return o.db.destroy()})}),de.finish();{const o=t,u=te(o),_=u[0],s=u[1],c=await e.get("_design/"+_);if(t=c.views&&c.views[s],!t)throw new Oe(`ddoc ${c._id} has no view named ${s}`);A(c,s),K(n,t);const i=await ae(e,o,t.map,t.reduce,!1,d);return n.stale==="ok"||n.stale==="update_after"?(n.stale==="update_after"&&De(function(){U(i,r)}),X(i,n)):(await U(i,r),X(i,n))}}function be(e,t,n){const r=this;typeof t=="function"&&(n=t,t={}),t=t?F(t):{},typeof e=="function"&&(e={map:e});const o=Promise.resolve().then(function(){return ve(r,e,t)});return Pe(o,n),o}const qe=Se(function(){const e=this;return typeof e._viewCleanup=="function"?G(e):oe(e)?we(e):pe(e)});return{query:be,viewCleanup:qe}}export{ze as c};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.