snow-cms 1.4.3 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index-browser.es.js +1 -4
- package/dist/index-browser2.es.js +4 -0
- package/dist/index.css +1 -1
- package/dist/index.es.js +1 -3
- package/dist/index.js +39 -44
- package/dist/index2.es.js +2 -0
- package/dist/index3.es.js +1 -0
- package/dist/index4.es.js +3 -0
- package/dist/milkdown.js +36 -34
- package/dist/rolldown-runtime.js +1 -0
- package/package.json +3 -3
- package/dist/index-browser.es2.js +0 -1
- package/dist/index.es2.js +0 -2
- package/dist/index.es3.js +0 -1
- package/dist/index.es4.js +0 -1
package/dist/index-browser.es.js
CHANGED
|
@@ -1,4 +1 @@
|
|
|
1
|
-
import{m as he,i as z,g as pe,T as Ae,u as ke,K as st,e as Oe,b as re,c as ot}from"./index-browser.es2.js";import{h as D,c as U,t as B,n as $e,p as ct,a as Ne,g as Pe,b as at,d as Ve,e as ie,i as Ce,s as ut,j as C,m as se}from"./index.es4.js";import"./milkdown.js";class q extends Error{constructor(t){super(),this.status=400,this.name="query_parse_error",this.message=t,this.error=!0;try{Error.captureStackTrace(this,q)}catch{}}}class we extends Error{constructor(t){super(),this.status=404,this.name="not_found",this.message=t,this.error=!0;try{Error.captureStackTrace(this,we)}catch{}}}class _e extends Error{constructor(t){super(),this.status=500,this.name="invalid_value",this.message=t,this.error=!0;try{Error.captureStackTrace(this,_e)}catch{}}}function Qe(e,t){return t&&e.then(function(n){he(function(){t(null,n)})},function(n){he(function(){t(n)})}),e}function lt(e){return function(...t){var n=t.pop(),i=e.apply(this,t);return typeof n=="function"&&Qe(i,n),i}}function dt(e,t){return e.then(function(n){return t().then(function(){return n})},function(n){return t().then(function(){throw n})})}function le(e,t){return function(){var n=arguments,i=this;return e.add(function(){return t.apply(i,n)})}}function Ie(e){var t=new Set(e),n=new Array(t.size),i=-1;return t.forEach(function(o){n[++i]=o}),n}function de(e){var t=new Array(e.size),n=-1;return e.forEach(function(i,o){t[++n]=o}),t}class ge{constructor(){this.promise=Promise.resolve()}add(t){return this.promise=this.promise.catch(()=>{}).then(()=>t()),this.promise}finish(){return this.promise}}function Se(e){if(!e)return"undefined";switch(typeof e){case"function":return e.toString();case"string":return e.toString();default:return JSON.stringify(e)}}function ft(e,t){return Se(e)+Se(t)+"undefined"}async function je(e,t,n,i,o,l){const u=ft(n,i);let p;if(!o&&(p=e._cachedViews=e._cachedViews||{},p[u]))return p[u];const g=e.info().then(async function(S){const v=S.db_name+"-mrview-"+(o?"temp":Ae(u));function m(F){F.views=F.views||{};let P=t;P.indexOf("/")===-1&&(P=t+"/"+t);const Q=F.views[P]=F.views[P]||{};if(!Q[v])return Q[v]=!0,F}await ke(e,"_local/"+l,m);const E=(await e.registerDependentDatabase(v)).db;E.auto_compaction=!0;const R={name:v,db:E,sourceDB:e,adapter:e.adapter,mapFun:n,reduceFun:i};let j;try{j=await R.db.get("_local/lastSeq")}catch(F){if(F.status!==404)throw F}return R.seq=j?j.seq:0,p&&R.db.once("destroyed",function(){delete p[u]}),R});return p&&(p[u]=g),g}const Me={},Te=new ge,yt=50;function fe(e){return e.indexOf("/")===-1?[e,e]:e.split("/")}function ht(e){return e.length===1&&/^1-/.test(e[0].rev)}function Ee(e,t,n){try{e.emit("error",t)}catch{Oe("error",`The user's map/reduce function threw an uncaught error.
|
|
2
|
-
You can debug this error by doing:
|
|
3
|
-
myDatabase.on('error', function (err) { debugger; });
|
|
4
|
-
Please double-check your map/reduce function.`),Oe("error",t,n)}}function pt(e,t,n,i){function o(r,s,c){try{s(c)}catch(a){Ee(r,a,{fun:s,doc:c})}}function l(r,s,c,a,f){try{return{output:s(c,a,f)}}catch(k){return Ee(r,k,{fun:s,keys:c,values:a,rereduce:f}),{error:k}}}function u(r,s){const c=U(r.key,s.key);return c!==0?c:U(r.value,s.value)}function p(r,s,c){return c=c||0,typeof s=="number"?r.slice(c,s+c):c>0?r.slice(c):r}function g(r){const s=r.value;return s&&typeof s=="object"&&s._id||r.id}function S(r){for(const s of r.rows){const c=s.doc&&s.doc._attachments;if(c)for(const a of Object.keys(c)){const f=c[a];c[a].data=st(f.data,f.content_type)}}}function v(r){return function(s){return r.include_docs&&r.attachments&&r.binary&&S(s),s}}function m(r,s,c,a){let f=s[r];typeof f<"u"&&(a&&(f=encodeURIComponent(JSON.stringify(f))),c.push(r+"="+f))}function T(r){if(typeof r<"u"){const s=Number(r);return!isNaN(s)&&s===parseInt(r,10)?s:r}}function E(r){return r.group_level=T(r.group_level),r.limit=T(r.limit),r.skip=T(r.skip),r}function R(r){if(r){if(typeof r!="number")return new q(`Invalid value for integer: "${r}"`);if(r<0)return new q(`Invalid value for positive integer: "${r}"`)}}function j(r,s){const c=r.descending?"endkey":"startkey",a=r.descending?"startkey":"endkey";if(typeof r[c]<"u"&&typeof r[a]<"u"&&U(r[c],r[a])>0)throw new q("No rows can match your key range, reverse your start_key and end_key or set {descending : true}");if(s.reduce&&r.reduce!==!1){if(r.include_docs)throw new q("{include_docs:true} is invalid for reduce");if(r.keys&&r.keys.length>1&&!r.group&&!r.group_level)throw new q("Multi-key fetches for reduce views must use {group: true}")}for(const f of["group_level","limit","skip"]){const k=R(r[f]);if(k)throw k}}async function F(r,s,c){let a=[],f,k="GET",I;if(m("reduce",c,a),m("include_docs",c,a),m("attachments",c,a),m("limit",c,a),m("descending",c,a),m("group",c,a),m("group_level",c,a),m("skip",c,a),m("stale",c,a),m("conflicts",c,a),m("startkey",c,a,!0),m("start_key",c,a,!0),m("endkey",c,a,!0),m("end_key",c,a,!0),m("inclusive_end",c,a),m("key",c,a,!0),m("update_seq",c,a),a=a.join("&"),a=a===""?"":"?"+a,typeof c.keys<"u"){const b=`keys=${encodeURIComponent(JSON.stringify(c.keys))}`;b.length+a.length+1<=2e3?a+=(a[0]==="?"?"&":"?")+b:(k="POST",typeof s=="string"?f={keys:c.keys}:s.keys=c.keys)}if(typeof s=="string"){const h=fe(s),b=await r.fetch("_design/"+h[0]+"/_view/"+h[1]+a,{headers:new D({"Content-Type":"application/json"}),method:k,body:JSON.stringify(f)});I=b.ok;const _=await b.json();if(!I)throw _.status=b.status,pe(_);for(const w of _.rows)if(w.value&&w.value.error&&w.value.error==="builtin_reduce_error")throw new Error(w.reason);return new Promise(function(w){w(_)}).then(v(c))}f=f||{};for(const h of Object.keys(s))Array.isArray(s[h])?f[h]=s[h]:f[h]=s[h].toString();const d=await r.fetch("_temp_view"+a,{headers:new D({"Content-Type":"application/json"}),method:"POST",body:JSON.stringify(f)});I=d.ok;const y=await d.json();if(!I)throw y.status=d.status,pe(y);return new Promise(function(h){h(y)}).then(v(c))}function P(r,s,c){return new Promise(function(a,f){r._query(s,c,function(k,I){if(k)return f(k);a(I)})})}function Q(r){return new Promise(function(s,c){r._viewCleanup(function(a,f){if(a)return c(a);s(f)})})}function L(r){return function(s){if(s.status===404)return r;throw s}}async function xe(r,s,c){const a="_local/doc_"+r,f={_id:a,keys:[]},k=c.get(r),I=k[0],d=k[1];function y(){return ht(d)?Promise.resolve(f):s.db.get(a).catch(L(f))}function h(A){return A.keys.length?s.db.allDocs({keys:A.keys,include_docs:!0}):Promise.resolve({rows:[]})}function b(A,K){const G=[],W=new Set;for(const $ of K.rows){const x=$.doc;if(x&&(G.push(x),W.add(x._id),x._deleted=!I.has(x._id),!x._deleted)){const O=I.get(x._id);"value"in O&&(x.value=O.value)}}const Z=de(I);for(const $ of Z)if(!W.has($)){const x={_id:$},O=I.get($);"value"in O&&(x.value=O.value),G.push(x)}return A.keys=Ie(Z.concat(A.keys)),G.push(A),G}const _=await y(),w=await h(_);return b(_,w)}function He(r){return r.sourceDB.get("_local/purges").then(function(s){const c=s.purgeSeq;return r.db.get("_local/purgeSeq").then(function(a){return a._rev}).catch(L(void 0)).then(function(a){return r.db.put({_id:"_local/purgeSeq",_rev:a,purgeSeq:c})})}).catch(function(s){if(s.status!==404)throw s})}function Ye(r,s,c){var a="_local/lastSeq";return r.db.get(a).catch(L({_id:a,seq:0})).then(function(f){var k=de(s);return Promise.all(k.map(function(I){return xe(I,r,s)})).then(function(I){var d=I.flat();return f.seq=c,d.push(f),r.db.bulkDocs({docs:d})}).then(()=>He(r))})}function oe(r){const s=typeof r=="string"?r:r.name;let c=Me[s];return c||(c=Me[s]=new ge),c}async function ce(r,s){return le(oe(r),function(){return We(r,s)})()}async function We(r,s){let c,a,f;function k($,x){const O={id:a._id,key:$e($)};typeof x<"u"&&x!==null&&(O.value=$e(x)),c.push(O)}const I=t(r.mapFun,k);let d=r.seq||0;function y(){return r.sourceDB.info().then(function($){f=r.sourceDB.activeTasks.add({name:"view_indexing",total_items:$.update_seq-d})})}function h($,x){return function(){return Ye(r,$,x)}}let b=0;const _={view:r.name,indexed_docs:b};r.sourceDB.emit("indexing",_);const w=new ge;async function A(){const $=await r.sourceDB.changes({return_docs:!0,conflicts:!0,include_docs:!0,style:"all_docs",since:d,limit:s.changes_batch_size}),x=await K();return G($,x)}function K(){return r.db.get("_local/purgeSeq").then(function($){return $.purgeSeq}).catch(L(-1)).then(function($){return r.sourceDB.get("_local/purges").then(function(x){const O=x.purges.filter(function(N,M){return M>$}).map(N=>N.docId),V=O.filter(function(N,M){return O.indexOf(N)===M});return Promise.all(V.map(function(N){return r.sourceDB.get(N).then(function(M){return{docId:N,doc:M}}).catch(L({docId:N}))}))}).catch(L([]))})}function G($,x){const O=$.results;if(!O.length&&!x.length)return;for(const M of x)if(O.findIndex(function(J){return J.id===M.docId})<0){const J={_id:M.docId,doc:{_id:M.docId,_deleted:1},changes:[]};M.doc&&(J.doc=M.doc,J.changes.push({rev:M.doc._rev})),O.push(J)}const V=W(O);w.add(h(V,d)),b=b+O.length;const N={view:r.name,last_seq:$.last_seq,results_count:O.length,indexed_docs:b};if(r.sourceDB.emit("indexing",N),r.sourceDB.activeTasks.update(f,{completed_items:b}),!(O.length<s.changes_batch_size))return A()}function W($){const x=new Map;for(const O of $){if(O.doc._id[0]!=="_"){c=[],a=O.doc,a._deleted||o(r.sourceDB,I,a),c.sort(u);const V=Z(c);x.set(O.doc._id,[V,O.changes])}d=O.seq}return x}function Z($){const x=new Map;let O;for(let V=0,N=$.length;V<N;V++){const M=$[V],ue=[M.key,M.id];V>0&&U(M.key,O)===0&&ue.push(V),x.set(B(ue),M),O=M.key}return x}try{await y(),await A(),await w.finish(),r.seq=d,r.sourceDB.activeTasks.remove(f)}catch($){r.sourceDB.activeTasks.remove(f,$)}}function Ze(r,s,c){c.group_level===0&&delete c.group_level;const a=c.group||c.group_level,f=n(r.reduceFun),k=[],I=isNaN(c.group_level)?Number.POSITIVE_INFINITY:c.group_level;for(const d of s){const y=k[k.length-1];let h=a?d.key:null;if(a&&Array.isArray(h)&&(h=h.slice(0,I)),y&&U(y.groupKey,h)===0){y.keys.push([d.key,d.id]),y.values.push(d.value);continue}k.push({keys:[[d.key,d.id]],values:[d.value],groupKey:h})}s=[];for(const d of k){const y=l(r.sourceDB,f,d.keys,d.values,!1);if(y.error&&y.error instanceof _e)throw y.error;s.push({value:y.error?null:y.output,key:d.groupKey})}return{rows:p(s,c.limit,c.skip)}}function ae(r,s){return le(oe(r),function(){return De(r,s)})()}async function De(r,s){let c;const a=r.reduceFun&&s.reduce!==!1,f=s.skip||0;typeof s.keys<"u"&&!s.keys.length&&(s.limit=0,delete s.keys);async function k(d){d.include_docs=!0;const y=await r.db.allDocs(d);return c=y.total_rows,y.rows.map(function(h){if("value"in h.doc&&typeof h.doc.value=="object"&&h.doc.value!==null){const _=Object.keys(h.doc.value).sort(),w=["id","key","value"];if(!(_<w||_>w))return h.doc.value}const b=ct(h.doc._id);return{key:b[0],id:b[1],value:"value"in h.doc?h.doc.value:null}})}async function I(d){let y;if(a?y=Ze(r,d,s):typeof s.keys>"u"?y={total_rows:c,offset:f,rows:d}:y={total_rows:c,offset:f,rows:p(d,s.limit,s.skip)},s.update_seq&&(y.update_seq=r.seq),s.include_docs){const h=Ie(d.map(g)),b=await r.sourceDB.allDocs({keys:h,include_docs:!0,conflicts:s.conflicts,attachments:s.attachments,binary:s.binary}),_=new Map;for(const w of b.rows)_.set(w.id,w.doc);for(const w of d){const A=g(w),K=_.get(A);K&&(w.doc=K)}}return y}if(typeof s.keys<"u"){const y=s.keys.map(function(_){const w={startkey:B([_]),endkey:B([_,{}])};return s.update_seq&&(w.update_seq=!0),k(w)}),b=(await Promise.all(y)).flat();return I(b)}else{const d={descending:s.descending};s.update_seq&&(d.update_seq=!0);let y,h;if("start_key"in s&&(y=s.start_key),"startkey"in s&&(y=s.startkey),"end_key"in s&&(h=s.end_key),"endkey"in s&&(h=s.endkey),typeof y<"u"&&(d.startkey=s.descending?B([y,{}]):B([y])),typeof h<"u"){let _=s.inclusive_end!==!1;s.descending&&(_=!_),d.endkey=B(_?[h,{}]:[h])}if(typeof s.key<"u"){const _=B([s.key]),w=B([s.key,{}]);d.descending?(d.endkey=_,d.startkey=w):(d.startkey=_,d.endkey=w)}a||(typeof s.limit=="number"&&(d.limit=s.limit),d.skip=f);const b=await k(d);return I(b)}}async function et(r){return(await r.fetch("_view_cleanup",{headers:new D({"Content-Type":"application/json"}),method:"POST"})).json()}async function tt(r){try{const s=await r.get("_local/"+e),c=new Map;for(const y of Object.keys(s.views)){const h=fe(y),b="_design/"+h[0],_=h[1];let w=c.get(b);w||(w=new Set,c.set(b,w)),w.add(_)}const a={keys:de(c),include_docs:!0},f=await r.allDocs(a),k={};for(const y of f.rows){const h=y.key.substring(8);for(const b of c.get(y.key)){let _=h+"/"+b;s.views[_]||(_=b);const w=Object.keys(s.views[_]),A=y.doc&&y.doc.views&&y.doc.views[b];for(const K of w)k[K]=k[K]||A}}const d=Object.keys(k).filter(function(y){return!k[y]}).map(function(y){return le(oe(y),function(){return new r.constructor(y,r.__opts).destroy()})()});return Promise.all(d).then(function(){return{ok:!0}})}catch(s){if(s.status===404)return{ok:!0};throw s}}async function nt(r,s,c){if(typeof r._query=="function")return P(r,s,c);if(z(r))return F(r,s,c);const a={changes_batch_size:r.__opts.view_update_changes_batch_size||yt};if(typeof s!="string")return j(c,s),Te.add(async function(){const f=await je(r,"temp_view/temp_view",s.map,s.reduce,!0,e);return dt(ce(f,a).then(function(){return ae(f,c)}),function(){return f.db.destroy()})}),Te.finish();{const f=s,k=fe(f),I=k[0],d=k[1],y=await r.get("_design/"+I);if(s=y.views&&y.views[d],!s)throw new we(`ddoc ${y._id} has no view named ${d}`);i(y,d),j(c,s);const h=await je(r,f,s.map,s.reduce,!1,e);return c.stale==="ok"||c.stale==="update_after"?(c.stale==="update_after"&&he(function(){ce(h,a)}),ae(h,c)):(await ce(h,a),ae(h,c))}}function rt(r,s,c){const a=this;typeof s=="function"&&(c=s,s={}),s=s?E(s):{},typeof r=="function"&&(r={map:r});const f=Promise.resolve().then(function(){return nt(a,r,s)});return Qe(f,c),f}const it=lt(function(){const r=this;return typeof r._viewCleanup=="function"?Q(r):z(r)?et(r):tt(r)});return{query:rt,viewCleanup:it}}const gt=(...e)=>e.flat(1/0),Ke=(...e)=>{let t=[];for(const n of e)Array.isArray(n)?t=t.concat(Ke(...n)):t.push(n);return t},Re=typeof Array.prototype.flat=="function"?gt:Ke;function ve(e){const t={};for(const n of e)Object.assign(t,n);return t}function mt(e,t){const n={};for(const i of t){const o=ie(i),l=Ce(e,o);typeof l<"u"&&ut(n,o,l)}return n}function Le(e,t){for(let n=0,i=Math.min(e.length,t.length);n<i;n++)if(e[n]!==t[n])return!1;return!0}function kt(e,t){return e.length>t.length?!1:Le(e,t)}function wt(e,t){e=e.slice();for(const n of t){if(!e.length)break;const i=e.indexOf(n);if(i===-1)return!1;e.splice(i,1)}return!0}function _t(e){const t={};for(const n of e)t[n]=!0;return t}function vt(e,t){let n=null,i=-1;for(const o of e){const l=t(o);l>i&&(i=l,n=o)}return n}function Fe(e,t){if(e.length!==t.length)return!1;for(let n=0,i=e.length;n<i;n++)if(e[n]!==t[n])return!1;return!0}function bt(e){return Array.from(new Set(e))}function X(e){return function(...t){const n=t[t.length-1];if(typeof n=="function"){const i=n.bind(null,null),o=n.bind(null);e.apply(this,t.slice(0,-1)).then(i,o)}else return e.apply(this,t)}}function Be(e){e=re(e),e.index||(e.index={});for(const t of["type","name","ddoc"])e.index[t]&&(e[t]=e.index[t],delete e.index[t]);return e.fields&&(e.index.fields=e.fields,delete e.fields),e.type||(e.type="json"),e}function ee(e){return typeof e=="object"&&e!==null}function xt(e,t,n){let i="",o=t,l=!0;if(["$in","$nin","$or","$and","$mod","$nor","$all"].indexOf(e)!==-1&&(Array.isArray(t)||(i="Query operator "+e+" must be an array.")),["$not","$elemMatch","$allMatch"].indexOf(e)!==-1&&(!Array.isArray(t)&&ee(t)||(i="Query operator "+e+" must be an object.")),e==="$mod"&&Array.isArray(t))if(t.length!==2)i="Query operator $mod must be in the format [divisor, remainder], where divisor and remainder are both integers.";else{const u=t[0],p=t[1];u===0&&(i="Query operator $mod's divisor cannot be 0, cannot divide by zero.",l=!1),(typeof u!="number"||parseInt(u,10)!==u)&&(i="Query operator $mod's divisor is not an integer.",o=u),parseInt(p,10)!==p&&(i="Query operator $mod's remainder is not an integer.",o=p)}if(e==="$exists"&&typeof t!="boolean"&&(i="Query operator $exists must be a boolean."),e==="$type"){const u=["null","boolean","number","string","array","object"],p='"'+u.slice(0,u.length-1).join('", "')+'", or "'+u[u.length-1]+'"';(typeof t!="string"||u.indexOf(t)==-1)&&(i="Query operator $type must be a string. Supported values: "+p+".")}if(e==="$size"&&parseInt(t,10)!==t&&(i="Query operator $size must be a integer."),e==="$regex"&&typeof t!="string"&&(n?i="Query operator $regex must be a string.":t instanceof RegExp||(i="Query operator $regex must be a string or an instance of a javascript regular expression.")),i){if(l){const u=o===null?" ":Array.isArray(o)?" array":" "+typeof o,p=ee(o)?JSON.stringify(o,null," "):o;i+=" Received"+u+": "+p}throw new Error(i)}}const Ot=["$all","$allMatch","$and","$elemMatch","$exists","$in","$mod","$nin","$nor","$not","$or","$regex","$size","$type"],$t=["$in","$nin","$mod","$all"],It=["$eq","$gt","$gte","$lt","$lte"];function te(e,t){if(Array.isArray(e))for(const n of e)ee(n)&&te(n,t);else for(const[n,i]of Object.entries(e))Ot.indexOf(n)!==-1&&xt(n,i,t),It.indexOf(n)===-1&&$t.indexOf(n)===-1&&ee(i)&&te(i,t)}async function H(e,t,n){n.body&&(n.body=JSON.stringify(n.body),n.headers=new D({"Content-type":"application/json"}));const i=await e.fetch(t,n),o=await i.json();if(!i.ok){o.status=i.status;const l=ot(o);throw pe(l)}return o}async function St(e,t){return await H(e,"_index",{method:"POST",body:Be(t)})}async function jt(e,t){return te(t.selector,!0),await H(e,"_find",{method:"POST",body:t})}async function Mt(e,t){return await H(e,"_explain",{method:"POST",body:t})}async function Tt(e){return await H(e,"_index",{method:"GET"})}async function Et(e,t){const n=t.ddoc,i=t.type||"json",o=t.name;if(!n)throw new Error("you must provide an index's ddoc");if(!o)throw new Error("you must provide an index's name");const l="_index/"+[n,i,o].map(encodeURIComponent).join("/");return await H(e,l,{method:"DELETE"})}function Ue(e,t){for(const n of t)if(e=e[n],e===void 0)return;return e}function Ft(e,t,n){return function(i){if(n&&!se(i,n))return;const o=[];for(const l of e){const u=Ue(i,ie(l));if(u===void 0)return;o.push(u)}t(o)}}function At(e,t,n){const i=ie(e);return function(o){if(n&&!se(o,n))return;const l=Ue(o,i);l!==void 0&&t(l)}}function Nt(e,t,n){return function(i){n&&!se(i,n)||t(i[e])}}function Pt(e,t,n){return function(i){if(n&&!se(i,n))return;const o=e.map(l=>i[l]);t(o)}}function Vt(e){return e.every(t=>t.indexOf(".")===-1)}function Ct(e,t,n){const i=Vt(e),o=e.length===1;return i?o?Nt(e[0],t,n):Pt(e,t,n):o?At(e[0],t,n):Ft(e,t,n)}function Qt(e,t){const n=Object.keys(e.fields),i=e.partial_filter_selector;return Ct(n,t,i)}function Kt(){throw new Error("reduce not supported")}function Rt(e,t){const n=e.views[t];if(!n.map||!n.map.fields)throw new Error("ddoc "+e._id+" with view "+t+" doesn't have map.fields defined. maybe it wasn't created by this plugin?")}const ye=pt("indexes",Qt,Kt,Rt);function be(e){return e._customFindAbstractMapper?{query:function(n,i){const o=ye.query.bind(this);return e._customFindAbstractMapper.query.call(this,n,i,o)},viewCleanup:function(){const n=ye.viewCleanup.bind(this);return e._customFindAbstractMapper.viewCleanup.call(this,n)}}:ye}function Lt(e){if(!Array.isArray(e))throw new Error("invalid sort json - should be an array");return e.map(function(t){if(typeof t=="string"){const n={};return n[t]="asc",n}else return t})}const Bt=/^_design\//;function Ut(e){let t=[];return typeof e=="string"?t.push(e):t=e,t.map(function(n){return n.replace(Bt,"")})}function qe(e){return e.fields=e.fields.map(function(t){if(typeof t=="string"){const n={};return n[t]="asc",n}return t}),e.partial_filter_selector&&(e.partial_filter_selector=Ne(e.partial_filter_selector)),e}function qt(e,t){return t.def.fields.map(n=>{const i=C(n);return Ce(e,ie(i))})}function zt(e,t,n){const i=n.def.fields;let o=0;for(const l of e){let u=qt(l.doc,n);if(i.length===1)u=u[0];else for(;u.length>t.length;)u.pop();if(Math.abs(U(u,t))>0)break;++o}return o>0?e.slice(o):e}function Gt(e){const t=re(e);return delete t.startkey,delete t.endkey,delete t.inclusive_start,delete t.inclusive_end,"endkey"in e&&(t.startkey=e.endkey),"startkey"in e&&(t.endkey=e.startkey),"inclusive_start"in e&&(t.inclusive_end=e.inclusive_start),"inclusive_end"in e&&(t.inclusive_start=e.inclusive_end),t}function Jt(e){const t=e.fields.filter(function(n){return Pe(n)==="asc"});if(t.length!==0&&t.length!==e.fields.length)throw new Error("unsupported mixed sorting")}function Xt(e,t){if(t.defaultUsed&&e.sort){const n=e.sort.filter(function(i){return Object.keys(i)[0]!=="_id"}).map(function(i){return Object.keys(i)[0]});if(n.length>0)throw new Error('Cannot sort on field(s) "'+n.join(",")+'" when using the default index')}t.defaultUsed}function Ht(e){if(typeof e.selector!="object")throw new Error("you must provide a selector when you find()")}function Yt(e,t){const n=Object.keys(e),i=t?t.map(C):[];let o;return n.length>=i.length?o=n:o=i,i.length===0?{fields:o}:(o=o.sort(function(l,u){let p=i.indexOf(l);p===-1&&(p=Number.MAX_VALUE);let g=i.indexOf(u);return g===-1&&(g=Number.MAX_VALUE),p<g?-1:p>g?1:0}),{fields:o,sortOrder:t.map(C)})}async function Wt(e,t){t=Be(t);const n=re(t.index);t.index=qe(t.index),Jt(t.index);let i;function o(){return i||(i=Ae(JSON.stringify(t)))}const l=t.name||"idx-"+o(),u=t.ddoc||"idx-"+o(),p="_design/"+u;let g=!1,S=!1;function v(T){return T._rev&&T.language!=="query"&&(g=!0),T.language="query",T.views=T.views||{},S=!!T.views[l],S?!1:(T.views[l]={map:{fields:ve(t.index.fields),partial_filter_selector:t.index.partial_filter_selector},reduce:"_count",options:{def:n}},T)}if(e.constructor.emit("debug",["find","creating index",p]),await ke(e,p,v),g)throw new Error('invalid language for ddoc with id "'+p+'" (should be "query")');const m=u+"/"+l;return await be(e).query.call(e,m,{limit:0,reduce:!1}),{id:p,name:l,result:S?"exists":"created"}}async function ze(e){const t=await e.allDocs({startkey:"_design/",endkey:"_design/",include_docs:!0}),n={indexes:[{ddoc:null,name:"_all_docs",type:"special",def:{fields:[{_id:"asc"}]}}]};return n.indexes=Re(n.indexes,t.rows.filter(function(i){return i.doc.language==="query"}).map(function(i){return(i.doc.views!==void 0?Object.keys(i.doc.views):[]).map(function(l){const u=i.doc.views[l];return{ddoc:i.id,name:l,type:"json",def:qe(u.options.def)}})})),n.indexes.sort(function(i,o){return Ve(i.name,o.name)}),n.total_rows=n.indexes.length,n}const ne=null,me={"":{}},Zt={queryOpts:{limit:0,startkey:me,endkey:ne},inMemoryFields:[]};function Dt(e,t){return e.def.fields.some(n=>C(n)===t)}function en(e,t){const n=e[t];return C(n)!=="$eq"}function Ge(e,t){const n=t.def.fields.map(C);return e.slice().sort(function(i,o){let l=n.indexOf(i),u=n.indexOf(o);return l===-1&&(l=Number.MAX_VALUE),u===-1&&(u=Number.MAX_VALUE),Ve(l,u)})}function tn(e,t,n){n=Ge(n,e);let i=!1;for(let o=0,l=n.length;o<l;o++){const u=n[o];if(i||!Dt(e,u))return n.slice(o);o<l-1&&en(t,u)&&(i=!0)}return[]}function nn(e){const t=[];for(const[n,i]of Object.entries(e))for(const o of Object.keys(i))o==="$ne"&&t.push(n);return t}function rn(e,t,n,i){const o=Re(e,tn(t,n,i),nn(n));return Ge(bt(o),t)}function sn(e,t,n){if(t){const i=kt(t,e),o=Le(n,e);return i&&o}return wt(n,e)}const on=["$eq","$gt","$gte","$lt","$lte"];function Je(e){return on.indexOf(e)===-1}function cn(e,t){const n=e[0],i=t[n];return typeof i>"u"?!0:!(Object.keys(i).length===1&&C(i)==="$ne")}function an(e,t,n,i){const o=e.def.fields.map(C);return sn(o,t,n)?cn(o,i):!1}function un(e,t,n,i){return i.filter(function(o){return an(o,n,t,e)})}function ln(e,t,n,i,o){const l=un(e,t,n,i);if(l.length===0){if(o)throw{error:"no_usable_index",message:"There is no index available for this selector."};const g=i[0];return g.defaultUsed=!0,g}if(l.length===1&&!o)return l[0];const u=_t(t);function p(g){const S=g.def.fields.map(C);let v=0;for(const m of S)u[m]&&v++;return v}if(o){const g="_design/"+o[0],S=o.length===2?o[1]:!1,v=l.find(function(m){return!!(S&&m.ddoc===g&&S===m.name||m.ddoc===g)});if(!v)throw{error:"unknown_error",message:"Could not find that index or could not use that index for the query"};return v}return vt(l,p)}function dn(e,t){switch(e){case"$eq":return{key:t};case"$lte":return{endkey:t};case"$gte":return{startkey:t};case"$lt":return{endkey:t,inclusive_end:!1};case"$gt":return{startkey:t,inclusive_start:!1}}return{startkey:ne}}function fn(e,t){const n=C(t.def.fields[0]),i=e[n]||{},o=[],l=Object.keys(i);let u;for(const p of l){Je(p)&&o.push(n);const g=i[p],S=dn(p,g);u?u=ve([u,S]):u=S}return{queryOpts:u,inMemoryFields:o}}function yn(e,t){switch(e){case"$eq":return{startkey:t,endkey:t};case"$lte":return{endkey:t};case"$gte":return{startkey:t};case"$lt":return{endkey:t,inclusive_end:!1};case"$gt":return{startkey:t,inclusive_start:!1}}}function hn(e,t){const n=t.def.fields.map(C);let i=[];const o=[],l=[];let u,p;function g(v){u!==!1&&o.push(ne),p!==!1&&l.push(me),i=n.slice(v)}for(let v=0,m=n.length;v<m;v++){const T=n[v],E=e[T];if(!E||!Object.keys(E).length){g(v);break}else if(Object.keys(E).some(Je)){g(v);break}else if(v>0){const F="$gt"in E||"$gte"in E||"$lt"in E||"$lte"in E,P=Object.keys(e[n[v-1]]),Q=Fe(P,["$eq"]),L=Fe(P,Object.keys(E));if(F&&!Q&&!L){g(v);break}}const R=Object.keys(E);let j=null;for(const F of R){const P=E[F],Q=yn(F,P);j?j=ve([j,Q]):j=Q}o.push("startkey"in j?j.startkey:ne),l.push("endkey"in j?j.endkey:me),"inclusive_start"in j&&(u=j.inclusive_start),"inclusive_end"in j&&(p=j.inclusive_end)}const S={startkey:o,endkey:l};return typeof u<"u"&&(S.inclusive_start=u),typeof p<"u"&&(S.inclusive_end=p),{queryOpts:S,inMemoryFields:i}}function pn(e){return Object.keys(e).map(function(n){return e[n]}).some(function(n){return typeof n=="object"&&Object.keys(n).length===0})}function gn(e){return{queryOpts:{startkey:null},inMemoryFields:[Object.keys(e)]}}function mn(e,t){return t.defaultUsed?gn(e):t.def.fields.length===1?fn(e,t):hn(e,t)}function kn(e,t){const n=e.selector,i=e.sort;if(pn(n))return Object.assign({},Zt,{index:t[0]});const o=Yt(n,i),l=o.fields,u=o.sortOrder,p=ln(n,l,u,t,e.use_index),g=mn(n,p),S=g.queryOpts,v=g.inMemoryFields,m=rn(v,p,n,l);return{queryOpts:S,index:p,inMemoryFields:m}}function wn(e){return e.ddoc.substring(8)+"/"+e.name}async function _n(e,t){const n=re(t);n.descending?("endkey"in n&&typeof n.endkey!="string"&&(n.endkey=""),"startkey"in n&&typeof n.startkey!="string"&&(n.limit=0)):("startkey"in n&&typeof n.startkey!="string"&&(n.startkey=""),"endkey"in n&&typeof n.endkey!="string"&&(n.limit=0)),"key"in n&&typeof n.key!="string"&&(n.limit=0),n.limit>0&&n.indexes_count&&(n.original_limit=n.limit,n.limit+=n.indexes_count);const i=await e.allDocs(n);return i.rows=i.rows.filter(function(o){return!/^_design\//.test(o.id)}),n.original_limit&&(n.limit=n.original_limit),i.rows=i.rows.slice(0,n.limit),i}async function vn(e,t,n){return n.name==="_all_docs"?_n(e,t):be(e).query.call(e,wn(n),t)}async function Xe(e,t,n){t.selector&&(te(t.selector,!1),t.selector=Ne(t.selector)),t.sort&&(t.sort=Lt(t.sort)),t.use_index&&(t.use_index=Ut(t.use_index)),"limit"in t||(t.limit=25),Ht(t);const i=await ze(e);e.constructor.emit("debug",["find","planning query",t]);const o=kn(t,i.indexes);e.constructor.emit("debug",["find","query plan",o]);const l=o.index;Xt(t,l);let u=Object.assign({include_docs:!0,reduce:!1,indexes_count:i.total_rows},o.queryOpts);if("startkey"in u&&"endkey"in u&&U(u.startkey,u.endkey)>0)return{docs:[]};if(t.sort&&typeof t.sort[0]!="string"&&Pe(t.sort[0])==="desc"&&(u.descending=!0,u=Gt(u)),o.inMemoryFields.length||(u.limit=t.limit,"skip"in t&&(u.skip=t.skip)),n)return Promise.resolve(o,u);const g=await vn(e,u,l);u.inclusive_start===!1&&(g.rows=zt(g.rows,u.startkey,l)),o.inMemoryFields.length&&(g.rows=at(g.rows,t,o.inMemoryFields));const S={docs:g.rows.map(function(v){const m=v.doc;return t.fields?mt(m,t.fields):m})};return l.defaultUsed&&(S.warning="No matching index found, create an index to optimize query time."),S}async function bn(e,t){const n=await Xe(e,t,!0);return{dbname:e.name,index:n.index,selector:t.selector,range:{start_key:n.queryOpts.startkey,end_key:n.queryOpts.endkey},opts:{use_index:t.use_index||[],bookmark:"nil",limit:t.limit,skip:t.skip,sort:t.sort||{},fields:t.fields,conflicts:!1,r:[49]},limit:t.limit,skip:t.skip||0,fields:t.fields}}async function xn(e,t){if(!t.ddoc)throw new Error("you must supply an index.ddoc when deleting");if(!t.name)throw new Error("you must supply an index.name when deleting");const n=t.ddoc,i=t.name;function o(l){return Object.keys(l.views).length===1&&l.views[i]?{_id:n,_deleted:!0}:(delete l.views[i],l)}return await ke(e,n,o),await be(e).viewCleanup.apply(e),{ok:!0}}const Y={};Y.createIndex=X(async function(e){if(typeof e!="object")throw new Error("you must provide an index to create");return(z(this)?St:Wt)(this,e)});Y.find=X(async function(e){if(typeof e!="object")throw new Error("you must provide search parameters to find()");return(z(this)?jt:Xe)(this,e)});Y.explain=X(async function(e){if(typeof e!="object")throw new Error("you must provide search parameters to explain()");return(z(this)?Mt:bn)(this,e)});Y.getIndexes=X(async function(){return(z(this)?Tt:ze)(this)});Y.deleteIndex=X(async function(e){if(typeof e!="object")throw new Error("you must provide an index to delete");return(z(this)?Et:xn)(this,e)});export{Y as default};
|
|
1
|
+
import{r as e,t}from"./rolldown-runtime.js";var n=function(e){return atob(e)},r=function(e){return btoa(e)};function i(e,t){e||=[],t||={};try{return new Blob(e,t)}catch(i){if(i.name!==`TypeError`)throw i;for(var n=new(typeof BlobBuilder<`u`?BlobBuilder:typeof MSBlobBuilder<`u`?MSBlobBuilder:typeof MozBlobBuilder<`u`?MozBlobBuilder:WebKitBlobBuilder),r=0;r<e.length;r+=1)n.append(e[r]);return n.getBlob(t.type)}}function a(e){for(var t=e.length,n=new ArrayBuffer(t),r=new Uint8Array(n),i=0;i<t;i++)r[i]=e.charCodeAt(i);return n}function o(e,t){return i([a(e)],{type:t})}function s(e,t){return o(n(e),t)}function c(e){for(var t=``,n=new Uint8Array(e),r=n.byteLength,i=0;i<r;i++)t+=String.fromCharCode(n[i]);return t}function l(e,t){var n=new FileReader,r=typeof n.readAsBinaryString==`function`;n.onloadend=function(e){var n=e.target.result||``;if(r)return t(n);t(c(n))},r?n.readAsBinaryString(e):n.readAsArrayBuffer(e)}function u(e,t){l(e,function(e){t(e)})}function d(e,t){u(e,function(e){t(r(e))})}function f(e,t){var n=new FileReader;n.onloadend=function(e){t(e.target.result||new ArrayBuffer(0))},n.readAsArrayBuffer(e)}var p=class extends Error{constructor(e,t,n){super(),this.status=e,this.name=t,this.message=n,this.error=!0}toString(){return JSON.stringify({status:this.status,name:this.name,message:this.message,reason:this.reason})}};new p(401,`unauthorized`,`Name or password is incorrect.`);var m=new p(400,`bad_request`,`Missing JSON list of 'docs'`),h=new p(404,`not_found`,`missing`),g=new p(409,`conflict`,`Document update conflict`),_=new p(400,`bad_request`,`_id field must contain a string`),v=new p(412,`missing_id`,`_id is required for puts`),y=new p(400,`bad_request`,`Only reserved document ids may start with underscore.`);new p(412,`precondition_failed`,`Database not open`);var b=new p(500,`unknown_error`,`Database encountered an unknown error`),x=new p(500,`badarg`,`Some query argument is invalid`);new p(400,`invalid_request`,`Request was invalid`);var S=new p(400,`query_parse_error`,`Some query parameter is invalid`),ee=new p(500,`doc_validation`,`Bad special document member`),C=new p(400,`bad_request`,`Something wrong with the request`),w=new p(400,`bad_request`,`Document must be a JSON object`);new p(404,`not_found`,`Database not found`);var te=new p(500,`indexed_db_went_bad`,`unknown`);new p(500,`web_sql_went_bad`,`unknown`),new p(500,`levelDB_went_went_bad`,`unknown`),new p(403,`forbidden`,`Forbidden by design doc validate_doc_update function`);var ne=new p(400,`bad_request`,`Invalid rev format`);new p(412,`file_exists`,`The database could not be created, the file already exists.`);var re=new p(412,`missing_stub`,`A pre-existing attachment stub wasn't found`);new p(413,`invalid_url`,`Provided URL is invalid`);function T(e,t){function n(t){for(var n=Object.getOwnPropertyNames(e),r=0,i=n.length;r<i;r++)typeof e[n[r]]!=`function`&&(this[n[r]]=e[n[r]]);this.stack===void 0&&(this.stack=Error().stack),t!==void 0&&(this.reason=t)}return n.prototype=p.prototype,new n(t)}function E(e){if(typeof e!=`object`){var t=e;e=b,e.data=t}return`error`in e&&e.error===`conflict`&&(e.name=`conflict`,e.status=409),`name`in e||(e.name=e.error||`unknown`),`status`in e||(e.status=500),`message`in e||(e.message=e.message||e.reason),`stack`in e||(e.stack=Error().stack),e}var D=t(((e,t)=>{var n=typeof Reflect==`object`?Reflect:null,r=n&&typeof n.apply==`function`?n.apply:function(e,t,n){return Function.prototype.apply.call(e,t,n)},i=n&&typeof n.ownKeys==`function`?n.ownKeys:Object.getOwnPropertySymbols?function(e){return Object.getOwnPropertyNames(e).concat(Object.getOwnPropertySymbols(e))}:function(e){return Object.getOwnPropertyNames(e)};function a(e){console&&console.warn&&console.warn(e)}var o=Number.isNaN||function(e){return e!==e};function s(){s.init.call(this)}t.exports=s,t.exports.once=y,s.EventEmitter=s,s.prototype._events=void 0,s.prototype._eventsCount=0,s.prototype._maxListeners=void 0;var c=10;function l(e){if(typeof e!=`function`)throw TypeError(`The "listener" argument must be of type Function. Received type `+typeof e)}Object.defineProperty(s,`defaultMaxListeners`,{enumerable:!0,get:function(){return c},set:function(e){if(typeof e!=`number`||e<0||o(e))throw RangeError(`The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received `+e+`.`);c=e}}),s.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},s.prototype.setMaxListeners=function(e){if(typeof e!=`number`||e<0||o(e))throw RangeError(`The value of "n" is out of range. It must be a non-negative number. Received `+e+`.`);return this._maxListeners=e,this};function u(e){return e._maxListeners===void 0?s.defaultMaxListeners:e._maxListeners}s.prototype.getMaxListeners=function(){return u(this)},s.prototype.emit=function(e){for(var t=[],n=1;n<arguments.length;n++)t.push(arguments[n]);var i=e===`error`,a=this._events;if(a!==void 0)i&&=a.error===void 0;else if(!i)return!1;if(i){var o;if(t.length>0&&(o=t[0]),o instanceof Error)throw o;var s=Error(`Unhandled error.`+(o?` (`+o.message+`)`:``));throw s.context=o,s}var c=a[e];if(c===void 0)return!1;if(typeof c==`function`)r(c,this,t);else for(var l=c.length,u=g(c,l),n=0;n<l;++n)r(u[n],this,t);return!0};function d(e,t,n,r){var i,o,s;if(l(n),o=e._events,o===void 0?(o=e._events=Object.create(null),e._eventsCount=0):(o.newListener!==void 0&&(e.emit(`newListener`,t,n.listener?n.listener:n),o=e._events),s=o[t]),s===void 0)s=o[t]=n,++e._eventsCount;else if(typeof s==`function`?s=o[t]=r?[n,s]:[s,n]:r?s.unshift(n):s.push(n),i=u(e),i>0&&s.length>i&&!s.warned){s.warned=!0;var c=Error(`Possible EventEmitter memory leak detected. `+s.length+` `+String(t)+` listeners added. Use emitter.setMaxListeners() to increase limit`);c.name=`MaxListenersExceededWarning`,c.emitter=e,c.type=t,c.count=s.length,a(c)}return e}s.prototype.addListener=function(e,t){return d(this,e,t,!1)},s.prototype.on=s.prototype.addListener,s.prototype.prependListener=function(e,t){return d(this,e,t,!0)};function f(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function p(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},i=f.bind(r);return i.listener=n,r.wrapFn=i,i}s.prototype.once=function(e,t){return l(t),this.on(e,p(this,e,t)),this},s.prototype.prependOnceListener=function(e,t){return l(t),this.prependListener(e,p(this,e,t)),this},s.prototype.removeListener=function(e,t){var n,r,i,a,o;if(l(t),r=this._events,r===void 0||(n=r[e],n===void 0))return this;if(n===t||n.listener===t)--this._eventsCount===0?this._events=Object.create(null):(delete r[e],r.removeListener&&this.emit(`removeListener`,e,n.listener||t));else if(typeof n!=`function`){for(i=-1,a=n.length-1;a>=0;a--)if(n[a]===t||n[a].listener===t){o=n[a].listener,i=a;break}if(i<0)return this;i===0?n.shift():_(n,i),n.length===1&&(r[e]=n[0]),r.removeListener!==void 0&&this.emit(`removeListener`,e,o||t)}return this},s.prototype.off=s.prototype.removeListener,s.prototype.removeAllListeners=function(e){var t,n=this._events,r;if(n===void 0)return this;if(n.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):n[e]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete n[e]),this;if(arguments.length===0){var i=Object.keys(n),a;for(r=0;r<i.length;++r)a=i[r],a!==`removeListener`&&this.removeAllListeners(a);return this.removeAllListeners(`removeListener`),this._events=Object.create(null),this._eventsCount=0,this}if(t=n[e],typeof t==`function`)this.removeListener(e,t);else if(t!==void 0)for(r=t.length-1;r>=0;r--)this.removeListener(e,t[r]);return this};function m(e,t,n){var r=e._events;if(r===void 0)return[];var i=r[t];return i===void 0?[]:typeof i==`function`?n?[i.listener||i]:[i]:n?v(i):g(i,i.length)}s.prototype.listeners=function(e){return m(this,e,!0)},s.prototype.rawListeners=function(e){return m(this,e,!1)},s.listenerCount=function(e,t){return typeof e.listenerCount==`function`?e.listenerCount(t):h.call(e,t)},s.prototype.listenerCount=h;function h(e){var t=this._events;if(t!==void 0){var n=t[e];if(typeof n==`function`)return 1;if(n!==void 0)return n.length}return 0}s.prototype.eventNames=function(){return this._eventsCount>0?i(this._events):[]};function g(e,t){for(var n=Array(t),r=0;r<t;++r)n[r]=e[r];return n}function _(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function v(e){for(var t=Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}function y(e,t){return new Promise(function(n,r){function i(n){e.removeListener(t,a),r(n)}function a(){typeof e.removeListener==`function`&&e.removeListener(`error`,i),n([].slice.call(arguments))}x(e,t,a,{once:!0}),t!==`error`&&b(e,i,{once:!0})})}function b(e,t,n){typeof e.on==`function`&&x(e,`error`,t,n)}function x(e,t,n,r){if(typeof e.on==`function`)r.once?e.once(t,n):e.on(t,n);else if(typeof e.addEventListener==`function`)e.addEventListener(t,function i(a){r.once&&e.removeEventListener(t,i),n(a)});else throw TypeError(`The "emitter" argument must be of type EventEmitter. Received type `+typeof e)}})),O,ie=new Uint8Array(16);function ae(){if(!O&&(O=typeof crypto<`u`&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||typeof msCrypto<`u`&&typeof msCrypto.getRandomValues==`function`&&msCrypto.getRandomValues.bind(msCrypto),!O))throw Error(`crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported`);return O(ie)}var oe=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function se(e){return typeof e==`string`&&oe.test(e)}for(var k=[],A=0;A<256;++A)k.push((A+256).toString(16).substr(1));function ce(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,n=(k[e[t+0]]+k[e[t+1]]+k[e[t+2]]+k[e[t+3]]+`-`+k[e[t+4]]+k[e[t+5]]+`-`+k[e[t+6]]+k[e[t+7]]+`-`+k[e[t+8]]+k[e[t+9]]+`-`+k[e[t+10]]+k[e[t+11]]+k[e[t+12]]+k[e[t+13]]+k[e[t+14]]+k[e[t+15]]).toLowerCase();if(!se(n))throw TypeError(`Stringified UUID is invalid`);return n}function j(e,t,n){e||={};var r=e.random||(e.rng||ae)();if(r[6]=r[6]&15|64,r[8]=r[8]&63|128,t){n||=0;for(var i=0;i<16;++i)t[n+i]=r[i];return t}return ce(r)}var M=e(t(((e,t)=>{(function(n){if(typeof e==`object`)t.exports=n();else if(typeof define==`function`&&define.amd)define(n);else{var r;try{r=window}catch{r=self}r.SparkMD5=n()}})(function(e){var t=[`0`,`1`,`2`,`3`,`4`,`5`,`6`,`7`,`8`,`9`,`a`,`b`,`c`,`d`,`e`,`f`];function n(e,t){var n=e[0],r=e[1],i=e[2],a=e[3];n+=(r&i|~r&a)+t[0]-680876936|0,n=(n<<7|n>>>25)+r|0,a+=(n&r|~n&i)+t[1]-389564586|0,a=(a<<12|a>>>20)+n|0,i+=(a&n|~a&r)+t[2]+606105819|0,i=(i<<17|i>>>15)+a|0,r+=(i&a|~i&n)+t[3]-1044525330|0,r=(r<<22|r>>>10)+i|0,n+=(r&i|~r&a)+t[4]-176418897|0,n=(n<<7|n>>>25)+r|0,a+=(n&r|~n&i)+t[5]+1200080426|0,a=(a<<12|a>>>20)+n|0,i+=(a&n|~a&r)+t[6]-1473231341|0,i=(i<<17|i>>>15)+a|0,r+=(i&a|~i&n)+t[7]-45705983|0,r=(r<<22|r>>>10)+i|0,n+=(r&i|~r&a)+t[8]+1770035416|0,n=(n<<7|n>>>25)+r|0,a+=(n&r|~n&i)+t[9]-1958414417|0,a=(a<<12|a>>>20)+n|0,i+=(a&n|~a&r)+t[10]-42063|0,i=(i<<17|i>>>15)+a|0,r+=(i&a|~i&n)+t[11]-1990404162|0,r=(r<<22|r>>>10)+i|0,n+=(r&i|~r&a)+t[12]+1804603682|0,n=(n<<7|n>>>25)+r|0,a+=(n&r|~n&i)+t[13]-40341101|0,a=(a<<12|a>>>20)+n|0,i+=(a&n|~a&r)+t[14]-1502002290|0,i=(i<<17|i>>>15)+a|0,r+=(i&a|~i&n)+t[15]+1236535329|0,r=(r<<22|r>>>10)+i|0,n+=(r&a|i&~a)+t[1]-165796510|0,n=(n<<5|n>>>27)+r|0,a+=(n&i|r&~i)+t[6]-1069501632|0,a=(a<<9|a>>>23)+n|0,i+=(a&r|n&~r)+t[11]+643717713|0,i=(i<<14|i>>>18)+a|0,r+=(i&n|a&~n)+t[0]-373897302|0,r=(r<<20|r>>>12)+i|0,n+=(r&a|i&~a)+t[5]-701558691|0,n=(n<<5|n>>>27)+r|0,a+=(n&i|r&~i)+t[10]+38016083|0,a=(a<<9|a>>>23)+n|0,i+=(a&r|n&~r)+t[15]-660478335|0,i=(i<<14|i>>>18)+a|0,r+=(i&n|a&~n)+t[4]-405537848|0,r=(r<<20|r>>>12)+i|0,n+=(r&a|i&~a)+t[9]+568446438|0,n=(n<<5|n>>>27)+r|0,a+=(n&i|r&~i)+t[14]-1019803690|0,a=(a<<9|a>>>23)+n|0,i+=(a&r|n&~r)+t[3]-187363961|0,i=(i<<14|i>>>18)+a|0,r+=(i&n|a&~n)+t[8]+1163531501|0,r=(r<<20|r>>>12)+i|0,n+=(r&a|i&~a)+t[13]-1444681467|0,n=(n<<5|n>>>27)+r|0,a+=(n&i|r&~i)+t[2]-51403784|0,a=(a<<9|a>>>23)+n|0,i+=(a&r|n&~r)+t[7]+1735328473|0,i=(i<<14|i>>>18)+a|0,r+=(i&n|a&~n)+t[12]-1926607734|0,r=(r<<20|r>>>12)+i|0,n+=(r^i^a)+t[5]-378558|0,n=(n<<4|n>>>28)+r|0,a+=(n^r^i)+t[8]-2022574463|0,a=(a<<11|a>>>21)+n|0,i+=(a^n^r)+t[11]+1839030562|0,i=(i<<16|i>>>16)+a|0,r+=(i^a^n)+t[14]-35309556|0,r=(r<<23|r>>>9)+i|0,n+=(r^i^a)+t[1]-1530992060|0,n=(n<<4|n>>>28)+r|0,a+=(n^r^i)+t[4]+1272893353|0,a=(a<<11|a>>>21)+n|0,i+=(a^n^r)+t[7]-155497632|0,i=(i<<16|i>>>16)+a|0,r+=(i^a^n)+t[10]-1094730640|0,r=(r<<23|r>>>9)+i|0,n+=(r^i^a)+t[13]+681279174|0,n=(n<<4|n>>>28)+r|0,a+=(n^r^i)+t[0]-358537222|0,a=(a<<11|a>>>21)+n|0,i+=(a^n^r)+t[3]-722521979|0,i=(i<<16|i>>>16)+a|0,r+=(i^a^n)+t[6]+76029189|0,r=(r<<23|r>>>9)+i|0,n+=(r^i^a)+t[9]-640364487|0,n=(n<<4|n>>>28)+r|0,a+=(n^r^i)+t[12]-421815835|0,a=(a<<11|a>>>21)+n|0,i+=(a^n^r)+t[15]+530742520|0,i=(i<<16|i>>>16)+a|0,r+=(i^a^n)+t[2]-995338651|0,r=(r<<23|r>>>9)+i|0,n+=(i^(r|~a))+t[0]-198630844|0,n=(n<<6|n>>>26)+r|0,a+=(r^(n|~i))+t[7]+1126891415|0,a=(a<<10|a>>>22)+n|0,i+=(n^(a|~r))+t[14]-1416354905|0,i=(i<<15|i>>>17)+a|0,r+=(a^(i|~n))+t[5]-57434055|0,r=(r<<21|r>>>11)+i|0,n+=(i^(r|~a))+t[12]+1700485571|0,n=(n<<6|n>>>26)+r|0,a+=(r^(n|~i))+t[3]-1894986606|0,a=(a<<10|a>>>22)+n|0,i+=(n^(a|~r))+t[10]-1051523|0,i=(i<<15|i>>>17)+a|0,r+=(a^(i|~n))+t[1]-2054922799|0,r=(r<<21|r>>>11)+i|0,n+=(i^(r|~a))+t[8]+1873313359|0,n=(n<<6|n>>>26)+r|0,a+=(r^(n|~i))+t[15]-30611744|0,a=(a<<10|a>>>22)+n|0,i+=(n^(a|~r))+t[6]-1560198380|0,i=(i<<15|i>>>17)+a|0,r+=(a^(i|~n))+t[13]+1309151649|0,r=(r<<21|r>>>11)+i|0,n+=(i^(r|~a))+t[4]-145523070|0,n=(n<<6|n>>>26)+r|0,a+=(r^(n|~i))+t[11]-1120210379|0,a=(a<<10|a>>>22)+n|0,i+=(n^(a|~r))+t[2]+718787259|0,i=(i<<15|i>>>17)+a|0,r+=(a^(i|~n))+t[9]-343485551|0,r=(r<<21|r>>>11)+i|0,e[0]=n+e[0]|0,e[1]=r+e[1]|0,e[2]=i+e[2]|0,e[3]=a+e[3]|0}function r(e){var t=[],n;for(n=0;n<64;n+=4)t[n>>2]=e.charCodeAt(n)+(e.charCodeAt(n+1)<<8)+(e.charCodeAt(n+2)<<16)+(e.charCodeAt(n+3)<<24);return t}function i(e){var t=[],n;for(n=0;n<64;n+=4)t[n>>2]=e[n]+(e[n+1]<<8)+(e[n+2]<<16)+(e[n+3]<<24);return t}function a(e){var t=e.length,i=[1732584193,-271733879,-1732584194,271733878],a,o,s,c,l,u;for(a=64;a<=t;a+=64)n(i,r(e.substring(a-64,a)));for(e=e.substring(a-64),o=e.length,s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],a=0;a<o;a+=1)s[a>>2]|=e.charCodeAt(a)<<(a%4<<3);if(s[a>>2]|=128<<(a%4<<3),a>55)for(n(i,s),a=0;a<16;a+=1)s[a]=0;return c=t*8,c=c.toString(16).match(/(.*?)(.{0,8})$/),l=parseInt(c[2],16),u=parseInt(c[1],16)||0,s[14]=l,s[15]=u,n(i,s),i}function o(e){var t=e.length,r=[1732584193,-271733879,-1732584194,271733878],a,o,s,c,l,u;for(a=64;a<=t;a+=64)n(r,i(e.subarray(a-64,a)));for(e=a-64<t?e.subarray(a-64):new Uint8Array,o=e.length,s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],a=0;a<o;a+=1)s[a>>2]|=e[a]<<(a%4<<3);if(s[a>>2]|=128<<(a%4<<3),a>55)for(n(r,s),a=0;a<16;a+=1)s[a]=0;return c=t*8,c=c.toString(16).match(/(.*?)(.{0,8})$/),l=parseInt(c[2],16),u=parseInt(c[1],16)||0,s[14]=l,s[15]=u,n(r,s),r}function s(e){var n=``,r;for(r=0;r<4;r+=1)n+=t[e>>r*8+4&15]+t[e>>r*8&15];return n}function c(e){var t;for(t=0;t<e.length;t+=1)e[t]=s(e[t]);return e.join(``)}c(a(`hello`)),typeof ArrayBuffer<`u`&&!ArrayBuffer.prototype.slice&&(function(){function t(e,t){return e=e|0||0,e<0?Math.max(e+t,0):Math.min(e,t)}ArrayBuffer.prototype.slice=function(n,r){var i=this.byteLength,a=t(n,i),o=i,s,c,l,u;return r!==e&&(o=t(r,i)),a>o?new ArrayBuffer(0):(s=o-a,c=new ArrayBuffer(s),l=new Uint8Array(c),u=new Uint8Array(this,a,s),l.set(u),c)}})();function l(e){return/[\u0080-\uFFFF]/.test(e)&&(e=unescape(encodeURIComponent(e))),e}function u(e,t){var n=e.length,r=new ArrayBuffer(n),i=new Uint8Array(r),a;for(a=0;a<n;a+=1)i[a]=e.charCodeAt(a);return t?i:r}function d(e){return String.fromCharCode.apply(null,new Uint8Array(e))}function f(e,t,n){var r=new Uint8Array(e.byteLength+t.byteLength);return r.set(new Uint8Array(e)),r.set(new Uint8Array(t),e.byteLength),n?r:r.buffer}function p(e){var t=[],n=e.length,r;for(r=0;r<n-1;r+=2)t.push(parseInt(e.substr(r,2),16));return String.fromCharCode.apply(String,t)}function m(){this.reset()}return m.prototype.append=function(e){return this.appendBinary(l(e)),this},m.prototype.appendBinary=function(e){this._buff+=e,this._length+=e.length;var t=this._buff.length,i;for(i=64;i<=t;i+=64)n(this._hash,r(this._buff.substring(i-64,i)));return this._buff=this._buff.substring(i-64),this},m.prototype.end=function(e){var t=this._buff,n=t.length,r,i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],a;for(r=0;r<n;r+=1)i[r>>2]|=t.charCodeAt(r)<<(r%4<<3);return this._finish(i,n),a=c(this._hash),e&&(a=p(a)),this.reset(),a},m.prototype.reset=function(){return this._buff=``,this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},m.prototype.getState=function(){return{buff:this._buff,length:this._length,hash:this._hash.slice()}},m.prototype.setState=function(e){return this._buff=e.buff,this._length=e.length,this._hash=e.hash,this},m.prototype.destroy=function(){delete this._hash,delete this._buff,delete this._length},m.prototype._finish=function(e,t){var r=t,i,a,o;if(e[r>>2]|=128<<(r%4<<3),r>55)for(n(this._hash,e),r=0;r<16;r+=1)e[r]=0;i=this._length*8,i=i.toString(16).match(/(.*?)(.{0,8})$/),a=parseInt(i[2],16),o=parseInt(i[1],16)||0,e[14]=a,e[15]=o,n(this._hash,e)},m.hash=function(e,t){return m.hashBinary(l(e),t)},m.hashBinary=function(e,t){var n=c(a(e));return t?p(n):n},m.ArrayBuffer=function(){this.reset()},m.ArrayBuffer.prototype.append=function(e){var t=f(this._buff.buffer,e,!0),r=t.length,a;for(this._length+=e.byteLength,a=64;a<=r;a+=64)n(this._hash,i(t.subarray(a-64,a)));return this._buff=a-64<r?new Uint8Array(t.buffer.slice(a-64)):new Uint8Array,this},m.ArrayBuffer.prototype.end=function(e){var t=this._buff,n=t.length,r=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],i,a;for(i=0;i<n;i+=1)r[i>>2]|=t[i]<<(i%4<<3);return this._finish(r,n),a=c(this._hash),e&&(a=p(a)),this.reset(),a},m.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array,this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},m.ArrayBuffer.prototype.getState=function(){var e=m.prototype.getState.call(this);return e.buff=d(e.buff),e},m.ArrayBuffer.prototype.setState=function(e){return e.buff=u(e.buff,!0),m.prototype.setState.call(this,e)},m.ArrayBuffer.prototype.destroy=m.prototype.destroy,m.ArrayBuffer.prototype._finish=m.prototype._finish,m.ArrayBuffer.hash=function(e,t){var n=c(o(new Uint8Array(e)));return t?p(n):n},m})}))()),le=self.setImmediate||self.setTimeout,ue=32768;function de(e){return r(e)}function fe(e,t,n,r,i){(n>0||r<t.size)&&(t=t.slice(n,r)),f(t,function(t){e.append(t),i()})}function N(e,t,n,r,i){(n>0||r<t.length)&&(t=t.substring(n,r)),e.appendBinary(t),i()}function P(e,t){var n=typeof e==`string`,r=n?e.length:e.size,i=Math.min(ue,r),a=Math.ceil(r/i),o=0,s=n?new M.default:new M.default.ArrayBuffer,c=n?N:fe;function l(){le(d)}function u(){t(de(s.end(!0))),s.destroy()}function d(){var t=o*i,n=t+i;o++,o<a?c(s,e,t,n,l):c(s,e,t,n,u)}d()}function F(e){return M.default.hash(e)}var I=e(D());function L(e){return typeof ArrayBuffer<`u`&&e instanceof ArrayBuffer||typeof Blob<`u`&&e instanceof Blob}function R(e){return e instanceof ArrayBuffer?e.slice(0):e.slice(0,e.size,e.type)}var z=Function.prototype.toString,B=z.call(Object);function V(e){var t=Object.getPrototypeOf(e);if(t===null)return!0;var n=t.constructor;return typeof n==`function`&&n instanceof n&&z.call(n)==B}function H(e){var t,n,r;if(!e||typeof e!=`object`)return e;if(Array.isArray(e)){for(t=[],n=0,r=e.length;n<r;n++)t[n]=H(e[n]);return t}if(e instanceof Date&&isFinite(e))return e.toISOString();if(L(e))return R(e);if(!V(e))return e;for(n in t={},e)if(Object.prototype.hasOwnProperty.call(e,n)){var i=H(e[n]);i!==void 0&&(t[n]=i)}return t}function U(e){var t=!1;return function(...n){if(t)throw Error(`once called more than once`);t=!0,e.apply(this,n)}}function W(e){return function(...t){t=H(t);var n=this,r=typeof t[t.length-1]==`function`?t.pop():!1,i=new Promise(function(r,i){var a;try{var o=U(function(e,t){e?i(e):r(t)});t.push(o),a=e.apply(n,t),a&&typeof a.then==`function`&&r(a)}catch(e){i(e)}});return r&&i.then(function(e){r(null,e)},r),i}}function pe(e,t,n){if(e.constructor.listeners(`debug`).length){for(var r=[`api`,e.name,t],i=0;i<n.length-1;i++)r.push(n[i]);e.constructor.emit(`debug`,r);var a=n[n.length-1];n[n.length-1]=function(n,r){var i=[`api`,e.name,t];i=i.concat(n?[`error`,n]:[`success`,r]),e.constructor.emit(`debug`,i),a(n,r)}}}function me(e,t){return W(function(...n){if(this._closed)return Promise.reject(Error(`database is closed`));if(this._destroyed)return Promise.reject(Error(`database is destroyed`));var r=this;return pe(r,e,n),this.taskqueue.isReady?t.apply(this,n):new Promise(function(t,i){r.taskqueue.addTask(function(a){a?i(a):t(r[e].apply(r,n))})})})}function G(e,t){for(var n={},r=0,i=t.length;r<i;r++){var a=t[r];a in e&&(n[a]=e[a])}return n}var he=6;function K(e){return e}function ge(e){return[{ok:e}]}function _e(e,t,n){var r=t.docs,i=new Map;r.forEach(function(e){i.has(e.id)?i.get(e.id).push(e):i.set(e.id,[e])});var a=i.size,o=0,s=Array(a);function c(){var e=[];s.forEach(function(t){t.docs.forEach(function(n){e.push({id:t.id,docs:[n]})})}),n(null,{results:e})}function l(){++o===a&&c()}function u(e,t,n){s[e]={id:t,docs:n},l()}var d=[];i.forEach(function(e,t){d.push(t)});var f=0;function p(){if(!(f>=d.length)){var e=Math.min(f+he,d.length),t=d.slice(f,e);m(t,f),f+=t.length}}function m(n,r){n.forEach(function(n,a){var o=r+a,s=i.get(n),c=G(s[0],[`atts_since`,`attachments`]);c.open_revs=s.map(function(e){return e.rev}),c.open_revs=c.open_revs.filter(K);var l=K;c.open_revs.length===0&&(delete c.open_revs,l=ge),[`revs`,`attachments`,`binary`,`ajax`,`latest`].forEach(function(e){e in t&&(c[e]=t[e])}),e.get(n,c,function(e,t){u(o,n,e?[{error:e}]:l(t)),p()})})}p()}var q;try{localStorage.setItem(`_pouch_check_localstorage`,1),q=!!localStorage.getItem(`_pouch_check_localstorage`)}catch{q=!1}function J(){return q}var Y=typeof queueMicrotask==`function`?queueMicrotask:function(e){Promise.resolve().then(e)},ve=class extends I.default{constructor(){super(),this._listeners={},J()&&addEventListener(`storage`,e=>{this.emit(e.key)})}addListener(e,t,n,r){if(this._listeners[t])return;var i=!1,a=this;function o(){if(!a._listeners[t])return;if(i){i=`waiting`;return}i=!0;var e=G(r,[`style`,`include_docs`,`attachments`,`conflicts`,`filter`,`doc_ids`,`view`,`since`,`query_params`,`binary`,`return_docs`]);function s(){i=!1}n.changes(e).on(`change`,function(e){e.seq>r.since&&!r.cancelled&&(r.since=e.seq,r.onChange(e))}).on(`complete`,function(){i===`waiting`&&Y(o),i=!1}).on(`error`,s)}this._listeners[t]=o,this.on(e,o)}removeListener(e,t){t in this._listeners&&(super.removeListener(e,this._listeners[t]),delete this._listeners[t])}notifyLocalWindows(e){J()&&(localStorage[e]=localStorage[e]===`a`?`b`:`a`)}notify(e){this.emit(e),this.notifyLocalWindows(e)}};function X(e){if(typeof console<`u`&&typeof console[e]==`function`){var t=Array.prototype.slice.call(arguments,1);console[e].apply(console,t)}}function ye(e,t,n){try{return!e(t,n)}catch(e){return T(C,`Filter function threw: `+e.toString())}}function be(e){var t={},n=e.filter&&typeof e.filter==`function`;return t.query=e.query_params,function(r){r.doc||={};var i=n&&ye(e.filter,r.doc,t);if(typeof i==`object`)return i;if(i)return!1;if(!e.include_docs)delete r.doc;else if(!e.attachments)for(var a in r.doc._attachments)Object.prototype.hasOwnProperty.call(r.doc._attachments,a)&&(r.doc._attachments[a].stub=!0);return!0}}function xe(){}xe.name;function Se(e){var t;if(e?typeof e==`string`?/^_/.test(e)&&!/^_(design|local)/.test(e)&&(t=T(y)):t=T(_):t=T(v),t)throw t}function Z(e){return typeof e._remote==`boolean`?e._remote:typeof e.type==`function`?(X(`warn`,`db.type() is deprecated and will be removed in a future version of PouchDB`),e.type()===`http`):!1}function Ce(e,t){return`listenerCount`in e?e.listenerCount(t):I.default.listenerCount(e,t)}function Q(e){if(!e)return null;var t=e.split(`/`);return t.length===2?t:t.length===1?[e,e]:null}function we(e){var t=Q(e);return t?t.join(`/`):null}function Te(e,t){var n=[],r=[];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(n.push(i),r.push(t[i]));return n.push(e),Function.apply(null,n).apply(null,r)}function $(e,t,n){return e.get(t).catch(function(e){if(e.status!==404)throw e;return{}}).then(function(r){var i=r._rev,a=n(r);return a?(a._id=t,a._rev=i,Ee(e,a,n)):{updated:!1,rev:i}})}function Ee(e,t,n){return e.put(t).then(function(e){return{updated:!0,rev:e.rev}},function(r){if(r.status!==409)throw r;return $(e,t._id,n)})}function De(e,t){if(!t)return j().replace(/-/g,``).toLowerCase();var n=Object.assign({},e);return delete n._rev_tree,F(JSON.stringify(n))}var Oe=j;export{ne as A,s as B,j as C,ee as D,C as E,S as F,l as G,d as H,g as I,n as K,b as L,h as M,re as N,te as O,w as P,T as R,F as S,x as T,u as U,o as V,i as W,Te as _,be as a,Oe as b,Se as c,Y as d,we as f,De as g,G as h,H as i,m as j,_ as k,Z as l,Q as m,me as n,X as o,U as p,r as q,_e as r,J as s,ve as t,Ce as u,W as v,D as w,P as x,$ as y,E as z};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{B as e,R as t,S as n,d as r,i,l as a,o,y as s,z as c}from"./index-browser.es.js";import{a as l,c as u,d,f,h as p,i as m,l as h,n as g,o as _,p as v,r as y,s as b,t as x,u as S}from"./index3.es.js";var C=class e extends Error{constructor(t){super(),this.status=400,this.name=`query_parse_error`,this.message=t,this.error=!0;try{Error.captureStackTrace(this,e)}catch{}}},ee=class e extends Error{constructor(t){super(),this.status=404,this.name=`not_found`,this.message=t,this.error=!0;try{Error.captureStackTrace(this,e)}catch{}}},te=class e extends Error{constructor(t){super(),this.status=500,this.name=`invalid_value`,this.message=t,this.error=!0;try{Error.captureStackTrace(this,e)}catch{}}};function w(e,t){return t&&e.then(function(e){r(function(){t(null,e)})},function(e){r(function(){t(e)})}),e}function ne(e){return function(...t){var n=t.pop(),r=e.apply(this,t);return typeof n==`function`&&w(r,n),r}}function re(e,t){return e.then(function(e){return t().then(function(){return e})},function(e){return t().then(function(){throw e})})}function T(e,t){return function(){var n=arguments,r=this;return e.add(function(){return t.apply(r,n)})}}function E(e){var t=new Set(e),n=Array(t.size),r=-1;return t.forEach(function(e){n[++r]=e}),n}function D(e){var t=Array(e.size),n=-1;return e.forEach(function(e,r){t[++n]=r}),t}var O=class{constructor(){this.promise=Promise.resolve()}add(e){return this.promise=this.promise.catch(()=>{}).then(()=>e()),this.promise}finish(){return this.promise}};function k(e){if(!e)return`undefined`;switch(typeof e){case`function`:return e.toString();case`string`:return e.toString();default:return JSON.stringify(e)}}function A(e,t){return k(e)+k(t)+`undefined`}async function ie(e,t,r,i,a,o){let c=A(r,i),l;if(!a&&(l=e._cachedViews=e._cachedViews||{},l[c]))return l[c];let u=e.info().then(async function(u){let d=u.db_name+`-mrview-`+(a?`temp`:n(c));function f(e){e.views=e.views||{};let n=t;n.indexOf(`/`)===-1&&(n=t+`/`+t);let r=e.views[n]=e.views[n]||{};if(!r[d])return r[d]=!0,e}await s(e,`_local/`+o,f);let p=(await e.registerDependentDatabase(d)).db;p.auto_compaction=!0;let m={name:d,db:p,sourceDB:e,adapter:e.adapter,mapFun:r,reduceFun:i},h;try{h=await m.db.get(`_local/lastSeq`)}catch(e){if(e.status!==404)throw e}return m.seq=h?h.seq:0,l&&m.db.once(`destroyed`,function(){delete l[c]}),m});return l&&(l[c]=u),u}var ae={},oe=new O,se=50;function j(e){return e.indexOf(`/`)===-1?[e,e]:e.split(`/`)}function ce(e){return e.length===1&&/^1-/.test(e[0].rev)}function le(e,t,n){try{e.emit(`error`,t)}catch{o(`error`,`The user's map/reduce function threw an uncaught error.
|
|
2
|
+
You can debug this error by doing:
|
|
3
|
+
myDatabase.on('error', function (err) { debugger; });
|
|
4
|
+
Please double-check your map/reduce function.`),o(`error`,t,n)}}function ue(t,n,i,o){function s(e,t,n){try{t(n)}catch(r){le(e,r,{fun:t,doc:n})}}function l(e,t,n,r,i){try{return{output:t(n,r,i)}}catch(a){return le(e,a,{fun:t,keys:n,values:r,rereduce:i}),{error:a}}}function u(e,t){let n=S(e.key,t.key);return n===0?S(e.value,t.value):n}function m(e,t,n){return n||=0,typeof t==`number`?e.slice(n,t+n):n>0?e.slice(n):e}function h(e){let t=e.value;return t&&typeof t==`object`&&t._id||e.id}function g(t){for(let n of t.rows){let t=n.doc&&n.doc._attachments;if(t)for(let n of Object.keys(t)){let r=t[n];t[n].data=e(r.data,r.content_type)}}}function _(e){return function(t){return e.include_docs&&e.attachments&&e.binary&&g(t),t}}function y(e,t,n,r){let i=t[e];i!==void 0&&(r&&(i=encodeURIComponent(JSON.stringify(i))),n.push(e+`=`+i))}function b(e){if(e!==void 0){let t=Number(e);return!isNaN(t)&&t===parseInt(e,10)?t:e}}function x(e){return e.group_level=b(e.group_level),e.limit=b(e.limit),e.skip=b(e.skip),e}function k(e){if(e){if(typeof e!=`number`)return new C(`Invalid value for integer: "${e}"`);if(e<0)return new C(`Invalid value for positive integer: "${e}"`)}}function A(e,t){let n=e.descending?`endkey`:`startkey`,r=e.descending?`startkey`:`endkey`;if(e[n]!==void 0&&e[r]!==void 0&&S(e[n],e[r])>0)throw new C(`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 C(`{include_docs:true} is invalid for reduce`);if(e.keys&&e.keys.length>1&&!e.group&&!e.group_level)throw new C(`Multi-key fetches for reduce views must use {group: true}`)}for(let t of[`group_level`,`limit`,`skip`]){let n=k(e[t]);if(n)throw n}}async function ue(e,t,n){let r=[],i,a=`GET`,o;if(y(`reduce`,n,r),y(`include_docs`,n,r),y(`attachments`,n,r),y(`limit`,n,r),y(`descending`,n,r),y(`group`,n,r),y(`group_level`,n,r),y(`skip`,n,r),y(`stale`,n,r),y(`conflicts`,n,r),y(`startkey`,n,r,!0),y(`start_key`,n,r,!0),y(`endkey`,n,r,!0),y(`end_key`,n,r,!0),y(`inclusive_end`,n,r),y(`key`,n,r,!0),y(`update_seq`,n,r),r=r.join(`&`),r=r===``?``:`?`+r,n.keys!==void 0){let e=`keys=${encodeURIComponent(JSON.stringify(n.keys))}`;e.length+r.length+1<=2e3?r+=(r[0]===`?`?`&`:`?`)+e:(a=`POST`,typeof t==`string`?i={keys:n.keys}:t.keys=n.keys)}if(typeof t==`string`){let s=j(t),l=await e.fetch(`_design/`+s[0]+`/_view/`+s[1]+r,{headers:new p({"Content-Type":`application/json`}),method:a,body:JSON.stringify(i)});o=l.ok;let u=await l.json();if(!o)throw u.status=l.status,c(u);for(let e of u.rows)if(e.value&&e.value.error&&e.value.error===`builtin_reduce_error`)throw Error(e.reason);return new Promise(function(e){e(u)}).then(_(n))}i||={};for(let e of Object.keys(t))Array.isArray(t[e])?i[e]=t[e]:i[e]=t[e].toString();let s=await e.fetch(`_temp_view`+r,{headers:new p({"Content-Type":`application/json`}),method:`POST`,body:JSON.stringify(i)});o=s.ok;let l=await s.json();if(!o)throw l.status=s.status,c(l);return new Promise(function(e){e(l)}).then(_(n))}function M(e,t,n){return new Promise(function(r,i){e._query(t,n,function(e,t){if(e)return i(e);r(t)})})}function N(e){return new Promise(function(t,n){e._viewCleanup(function(e,r){if(e)return n(e);t(r)})})}function P(e){return function(t){if(t.status===404)return e;throw t}}async function F(e,t,n){let r=`_local/doc_`+e,i={_id:r,keys:[]},a=n.get(e),o=a[0],s=a[1];function c(){return ce(s)?Promise.resolve(i):t.db.get(r).catch(P(i))}function l(e){return e.keys.length?t.db.allDocs({keys:e.keys,include_docs:!0}):Promise.resolve({rows:[]})}function u(e,t){let n=[],r=new Set;for(let e of t.rows){let t=e.doc;if(t&&(n.push(t),r.add(t._id),t._deleted=!o.has(t._id),!t._deleted)){let e=o.get(t._id);`value`in e&&(t.value=e.value)}}let i=D(o);for(let e of i)if(!r.has(e)){let t={_id:e},r=o.get(e);`value`in r&&(t.value=r.value),n.push(t)}return e.keys=E(i.concat(e.keys)),n.push(e),n}let d=await c();return u(d,await l(d))}function I(e){return e.sourceDB.get(`_local/purges`).then(function(t){let n=t.purgeSeq;return e.db.get(`_local/purgeSeq`).then(function(e){return e._rev}).catch(P(void 0)).then(function(t){return e.db.put({_id:`_local/purgeSeq`,_rev:t,purgeSeq:n})})}).catch(function(e){if(e.status!==404)throw e})}function L(e,t,n){var r=`_local/lastSeq`;return e.db.get(r).catch(P({_id:r,seq:0})).then(function(r){var i=D(t);return Promise.all(i.map(function(n){return F(n,e,t)})).then(function(t){var i=t.flat();return r.seq=n,i.push(r),e.db.bulkDocs({docs:i})}).then(()=>I(e))})}function R(e){let t=typeof e==`string`?e:e.name,n=ae[t];return n||=ae[t]=new O,n}async function z(e,t){return T(R(e),function(){return B(e,t)})()}async function B(e,t){let r,i,a;function o(e,t){let n={id:i._id,key:d(e)};t!=null&&(n.value=d(t)),r.push(n)}let c=n(e.mapFun,o),l=e.seq||0;function f(){return e.sourceDB.info().then(function(t){a=e.sourceDB.activeTasks.add({name:`view_indexing`,total_items:t.update_seq-l})})}function p(t,n){return function(){return L(e,t,n)}}let m=0,h={view:e.name,indexed_docs:m};e.sourceDB.emit(`indexing`,h);let g=new O;async function _(){return b(await e.sourceDB.changes({return_docs:!0,conflicts:!0,include_docs:!0,style:`all_docs`,since:l,limit:t.changes_batch_size}),await y())}function y(){return e.db.get(`_local/purgeSeq`).then(function(e){return e.purgeSeq}).catch(P(-1)).then(function(t){return e.sourceDB.get(`_local/purges`).then(function(n){let r=n.purges.filter(function(e,n){return n>t}).map(e=>e.docId),i=r.filter(function(e,t){return r.indexOf(e)===t});return Promise.all(i.map(function(t){return e.sourceDB.get(t).then(function(e){return{docId:t,doc:e}}).catch(P({docId:t}))}))}).catch(P([]))})}function b(n,r){let i=n.results;if(!i.length&&!r.length)return;for(let e of r)if(i.findIndex(function(t){return t.id===e.docId})<0){let t={_id:e.docId,doc:{_id:e.docId,_deleted:1},changes:[]};e.doc&&(t.doc=e.doc,t.changes.push({rev:e.doc._rev})),i.push(t)}let o=x(i);g.add(p(o,l)),m+=i.length;let s={view:e.name,last_seq:n.last_seq,results_count:i.length,indexed_docs:m};if(e.sourceDB.emit(`indexing`,s),e.sourceDB.activeTasks.update(a,{completed_items:m}),!(i.length<t.changes_batch_size))return _()}function x(t){let n=new Map;for(let a of t){if(a.doc._id[0]!==`_`){r=[],i=a.doc,i._deleted||s(e.sourceDB,c,i),r.sort(u);let t=C(r);n.set(a.doc._id,[t,a.changes])}l=a.seq}return n}function C(e){let t=new Map,n;for(let r=0,i=e.length;r<i;r++){let i=e[r],a=[i.key,i.id];r>0&&S(i.key,n)===0&&a.push(r),t.set(v(a),i),n=i.key}return t}try{await f(),await _(),await g.finish(),e.seq=l,e.sourceDB.activeTasks.remove(a)}catch(t){e.sourceDB.activeTasks.remove(a,t)}}function V(e,t,n){n.group_level===0&&delete n.group_level;let r=n.group||n.group_level,a=i(e.reduceFun),o=[],s=isNaN(n.group_level)?1/0:n.group_level;for(let e of t){let t=o[o.length-1],n=r?e.key:null;if(r&&Array.isArray(n)&&(n=n.slice(0,s)),t&&S(t.groupKey,n)===0){t.keys.push([e.key,e.id]),t.values.push(e.value);continue}o.push({keys:[[e.key,e.id]],values:[e.value],groupKey:n})}t=[];for(let n of o){let r=l(e.sourceDB,a,n.keys,n.values,!1);if(r.error&&r.error instanceof te)throw r.error;t.push({value:r.error?null:r.output,key:n.groupKey})}return{rows:m(t,n.limit,n.skip)}}function H(e,t){return T(R(e),function(){return U(e,t)})()}async function U(e,t){let n,r=e.reduceFun&&t.reduce!==!1,i=t.skip||0;t.keys!==void 0&&!t.keys.length&&(t.limit=0,delete t.keys);async function a(t){t.include_docs=!0;let r=await e.db.allDocs(t);return n=r.total_rows,r.rows.map(function(e){if(`value`in e.doc&&typeof e.doc.value==`object`&&e.doc.value!==null){let t=Object.keys(e.doc.value).sort(),n=[`id`,`key`,`value`];if(!(t<n||t>n))return e.doc.value}let t=f(e.doc._id);return{key:t[0],id:t[1],value:`value`in e.doc?e.doc.value:null}})}async function o(a){let o;if(o=r?V(e,a,t):t.keys===void 0?{total_rows:n,offset:i,rows:a}:{total_rows:n,offset:i,rows:m(a,t.limit,t.skip)},t.update_seq&&(o.update_seq=e.seq),t.include_docs){let n=E(a.map(h)),r=await e.sourceDB.allDocs({keys:n,include_docs:!0,conflicts:t.conflicts,attachments:t.attachments,binary:t.binary}),i=new Map;for(let e of r.rows)i.set(e.id,e.doc);for(let e of a){let t=h(e),n=i.get(t);n&&(e.doc=n)}}return o}if(t.keys!==void 0){let e=t.keys.map(function(e){let n={startkey:v([e]),endkey:v([e,{}])};return t.update_seq&&(n.update_seq=!0),a(n)});return o((await Promise.all(e)).flat())}else{let e={descending:t.descending};t.update_seq&&(e.update_seq=!0);let n,s;if(`start_key`in t&&(n=t.start_key),`startkey`in t&&(n=t.startkey),`end_key`in t&&(s=t.end_key),`endkey`in t&&(s=t.endkey),n!==void 0&&(e.startkey=t.descending?v([n,{}]):v([n])),s!==void 0){let n=t.inclusive_end!==!1;t.descending&&(n=!n),e.endkey=v(n?[s,{}]:[s])}if(t.key!==void 0){let n=v([t.key]),r=v([t.key,{}]);e.descending?(e.endkey=n,e.startkey=r):(e.startkey=n,e.endkey=r)}return r||(typeof t.limit==`number`&&(e.limit=t.limit),e.skip=i),o(await a(e))}}async function W(e){return(await e.fetch(`_view_cleanup`,{headers:new p({"Content-Type":`application/json`}),method:`POST`})).json()}async function G(e){try{let n=await e.get(`_local/`+t),r=new Map;for(let e of Object.keys(n.views)){let t=j(e),n=`_design/`+t[0],i=t[1],a=r.get(n);a||(a=new Set,r.set(n,a)),a.add(i)}let i={keys:D(r),include_docs:!0},a=await e.allDocs(i),o={};for(let e of a.rows){let t=e.key.substring(8);for(let i of r.get(e.key)){let r=t+`/`+i;n.views[r]||(r=i);let a=Object.keys(n.views[r]),s=e.doc&&e.doc.views&&e.doc.views[i];for(let e of a)o[e]=o[e]||s}}let s=Object.keys(o).filter(function(e){return!o[e]}).map(function(t){return T(R(t),function(){return new e.constructor(t,e.__opts).destroy()})()});return Promise.all(s).then(function(){return{ok:!0}})}catch(e){if(e.status===404)return{ok:!0};throw e}}async function K(e,n,i){if(typeof e._query==`function`)return M(e,n,i);if(a(e))return ue(e,n,i);let s={changes_batch_size:e.__opts.view_update_changes_batch_size||se};if(typeof n!=`string`)return A(i,n),oe.add(async function(){let r=await ie(e,`temp_view/temp_view`,n.map,n.reduce,!0,t);return re(z(r,s).then(function(){return H(r,i)}),function(){return r.db.destroy()})}),oe.finish();{let a=n,c=j(a),l=c[0],u=c[1],d=await e.get(`_design/`+l);if(n=d.views&&d.views[u],!n)throw new ee(`ddoc ${d._id} has no view named ${u}`);o(d,u),A(i,n);let f=await ie(e,a,n.map,n.reduce,!1,t);return i.stale===`ok`||i.stale===`update_after`?(i.stale===`update_after`&&r(function(){z(f,s)}),H(f,i)):(await z(f,s),H(f,i))}}function de(e,t,n){let r=this;typeof t==`function`&&(n=t,t={}),t=t?x(t):{},typeof e==`function`&&(e={map:e});let i=Promise.resolve().then(function(){return K(r,e,t)});return w(i,n),i}return{query:de,viewCleanup:ne(function(){let e=this;return typeof e._viewCleanup==`function`?N(e):a(e)?W(e):G(e)})}}var M=(...e)=>e.flat(1/0),N=(...e)=>{let t=[];for(let n of e)Array.isArray(n)?t=t.concat(N(...n)):t.push(n);return t},P=typeof Array.prototype.flat==`function`?M:N;function F(e){let t={};for(let n of e)Object.assign(t,n);return t}function I(e,t){let n={};for(let r of t){let t=u(r),i=y(e,t);i!==void 0&&h(n,t,i)}return n}function L(e,t){for(let n=0,r=Math.min(e.length,t.length);n<r;n++)if(e[n]!==t[n])return!1;return!0}function R(e,t){return e.length>t.length?!1:L(e,t)}function z(e,t){e=e.slice();for(let n of t){if(!e.length)break;let t=e.indexOf(n);if(t===-1)return!1;e.splice(t,1)}return!0}function B(e){let t={};for(let n of e)t[n]=!0;return t}function V(e,t){let n=null,r=-1;for(let i of e){let e=t(i);e>r&&(r=e,n=i)}return n}function H(e,t){if(e.length!==t.length)return!1;for(let n=0,r=e.length;n<r;n++)if(e[n]!==t[n])return!1;return!0}function U(e){return Array.from(new Set(e))}function W(e){return function(...t){let n=t[t.length-1];if(typeof n==`function`){let r=n.bind(null,null),i=n.bind(null);e.apply(this,t.slice(0,-1)).then(r,i)}else return e.apply(this,t)}}function G(e){e=i(e),e.index||={};for(let t of[`type`,`name`,`ddoc`])e.index[t]&&(e[t]=e.index[t],delete e.index[t]);return e.fields&&(e.index.fields=e.fields,delete e.fields),e.type||=`json`,e}function K(e){return typeof e==`object`&&!!e}function de(e,t,n){let r=``,i=t,a=!0;if([`$in`,`$nin`,`$or`,`$and`,`$mod`,`$nor`,`$all`].indexOf(e)!==-1&&(Array.isArray(t)||(r=`Query operator `+e+` must be an array.`)),[`$not`,`$elemMatch`,`$allMatch`].indexOf(e)!==-1&&(!Array.isArray(t)&&K(t)||(r=`Query operator `+e+` must be an object.`)),e===`$mod`&&Array.isArray(t))if(t.length!==2)r=`Query operator $mod must be in the format [divisor, remainder], where divisor and remainder are both integers.`;else{let e=t[0],n=t[1];e===0&&(r=`Query operator $mod's divisor cannot be 0, cannot divide by zero.`,a=!1),(typeof e!=`number`||parseInt(e,10)!==e)&&(r=`Query operator $mod's divisor is not an integer.`,i=e),parseInt(n,10)!==n&&(r=`Query operator $mod's remainder is not an integer.`,i=n)}if(e===`$exists`&&typeof t!=`boolean`&&(r=`Query operator $exists must be a boolean.`),e===`$type`){let e=[`null`,`boolean`,`number`,`string`,`array`,`object`],n=`"`+e.slice(0,e.length-1).join(`", "`)+`", or "`+e[e.length-1]+`"`;typeof t==`string`?e.indexOf(t)==-1&&(r=`Query operator $type must be a string. Supported values: `+n+`.`):r=`Query operator $type must be a string. Supported values: `+n+`.`}if(e===`$size`&&parseInt(t,10)!==t&&(r=`Query operator $size must be a integer.`),e===`$regex`&&typeof t!=`string`&&(n?r=`Query operator $regex must be a string.`:t instanceof RegExp||(r=`Query operator $regex must be a string or an instance of a javascript regular expression.`)),r){if(a){let e=i===null?` `:Array.isArray(i)?` array`:` `+typeof i,t=K(i)?JSON.stringify(i,null,` `):i;r+=` Received`+e+`: `+t}throw Error(r)}}var fe=[`$all`,`$allMatch`,`$and`,`$elemMatch`,`$exists`,`$in`,`$mod`,`$nin`,`$nor`,`$not`,`$or`,`$regex`,`$size`,`$type`],pe=[`$in`,`$nin`,`$mod`,`$all`],me=[`$eq`,`$gt`,`$gte`,`$lt`,`$lte`];function q(e,t){if(Array.isArray(e))for(let n of e)K(n)&&q(n,t);else for(let[n,r]of Object.entries(e))fe.indexOf(n)!==-1&&de(n,r,t),me.indexOf(n)===-1&&pe.indexOf(n)===-1&&K(r)&&q(r,t)}async function J(e,n,r){r.body&&(r.body=JSON.stringify(r.body),r.headers=new p({"Content-type":`application/json`}));let i=await e.fetch(n,r),a=await i.json();if(!i.ok)throw a.status=i.status,c(t(a));return a}async function he(e,t){return await J(e,`_index`,{method:`POST`,body:G(t)})}async function ge(e,t){return q(t.selector,!0),await J(e,`_find`,{method:`POST`,body:t})}async function _e(e,t){return await J(e,`_explain`,{method:`POST`,body:t})}async function ve(e){return await J(e,`_index`,{method:`GET`})}async function ye(e,t){let n=t.ddoc,r=t.type||`json`,i=t.name;if(!n)throw Error(`you must provide an index's ddoc`);if(!i)throw Error(`you must provide an index's name`);return await J(e,`_index/`+[n,r,i].map(encodeURIComponent).join(`/`),{method:`DELETE`})}function be(e,t){for(let n of t)if(e=e[n],e===void 0)return;return e}function xe(e,t,n){return function(r){if(n&&!b(r,n))return;let i=[];for(let t of e){let e=be(r,u(t));if(e===void 0)return;i.push(e)}t(i)}}function Se(e,t,n){let r=u(e);return function(e){if(n&&!b(e,n))return;let i=be(e,r);i!==void 0&&t(i)}}function Ce(e,t,n){return function(r){n&&!b(r,n)||t(r[e])}}function we(e,t,n){return function(r){n&&!b(r,n)||t(e.map(e=>r[e]))}}function Te(e){return e.every(e=>e.indexOf(`.`)===-1)}function Ee(e,t,n){let r=Te(e),i=e.length===1;return r?i?Ce(e[0],t,n):we(e,t,n):i?Se(e[0],t,n):xe(e,t,n)}function De(e,t){let n=Object.keys(e.fields),r=e.partial_filter_selector;return Ee(n,t,r)}function Oe(){throw Error(`reduce not supported`)}function ke(e,t){let n=e.views[t];if(!n.map||!n.map.fields)throw Error(`ddoc `+e._id+` with view `+t+` doesn't have map.fields defined. maybe it wasn't created by this plugin?`)}var Y=ue(`indexes`,De,Oe,ke);function X(e){return e._customFindAbstractMapper?{query:function(t,n){let r=Y.query.bind(this);return e._customFindAbstractMapper.query.call(this,t,n,r)},viewCleanup:function(){let t=Y.viewCleanup.bind(this);return e._customFindAbstractMapper.viewCleanup.call(this,t)}}:Y}function Ae(e){if(!Array.isArray(e))throw Error(`invalid sort json - should be an array`);return e.map(function(e){if(typeof e==`string`){let t={};return t[e]=`asc`,t}else return e})}var je=/^_design\//;function Me(e){let t=[];return typeof e==`string`?t.push(e):t=e,t.map(function(e){return e.replace(je,``)})}function Ne(e){return e.fields=e.fields.map(function(e){if(typeof e==`string`){let t={};return t[e]=`asc`,t}return e}),e.partial_filter_selector&&=_(e.partial_filter_selector),e}function Pe(e,t){return t.def.fields.map(t=>y(e,u(m(t))))}function Fe(e,t,n){let r=n.def.fields,i=0;for(let a of e){let e=Pe(a.doc,n);if(r.length===1)e=e[0];else for(;e.length>t.length;)e.pop();if(Math.abs(S(e,t))>0)break;++i}return i>0?e.slice(i):e}function Ie(e){let t=i(e);return delete t.startkey,delete t.endkey,delete t.inclusive_start,delete t.inclusive_end,`endkey`in e&&(t.startkey=e.endkey),`startkey`in e&&(t.endkey=e.startkey),`inclusive_start`in e&&(t.inclusive_end=e.inclusive_start),`inclusive_end`in e&&(t.inclusive_start=e.inclusive_end),t}function Le(e){let t=e.fields.filter(function(e){return l(e)===`asc`});if(t.length!==0&&t.length!==e.fields.length)throw Error(`unsupported mixed sorting`)}function Re(e,t){if(t.defaultUsed&&e.sort){let t=e.sort.filter(function(e){return Object.keys(e)[0]!==`_id`}).map(function(e){return Object.keys(e)[0]});if(t.length>0)throw Error(`Cannot sort on field(s) "`+t.join(`,`)+`" when using the default index`)}t.defaultUsed}function ze(e){if(typeof e.selector!=`object`)throw Error(`you must provide a selector when you find()`)}function Be(e,t){let n=Object.keys(e),r=t?t.map(m):[],i;return i=n.length>=r.length?n:r,r.length===0?{fields:i}:(i=i.sort(function(e,t){let n=r.indexOf(e);n===-1&&(n=Number.MAX_VALUE);let i=r.indexOf(t);return i===-1&&(i=Number.MAX_VALUE),n<i?-1:n>i?1:0}),{fields:i,sortOrder:t.map(m)})}async function Ve(e,t){t=G(t);let r=i(t.index);t.index=Ne(t.index),Le(t.index);let a;function o(){return a||=n(JSON.stringify(t))}let c=t.name||`idx-`+o(),l=t.ddoc||`idx-`+o(),u=`_design/`+l,d=!1,f=!1;function p(e){return e._rev&&e.language!==`query`&&(d=!0),e.language=`query`,e.views=e.views||{},f=!!e.views[c],f?!1:(e.views[c]={map:{fields:F(t.index.fields),partial_filter_selector:t.index.partial_filter_selector},reduce:`_count`,options:{def:r}},e)}if(e.constructor.emit(`debug`,[`find`,`creating index`,u]),await s(e,u,p),d)throw Error(`invalid language for ddoc with id "`+u+`" (should be "query")`);let m=l+`/`+c;return await X(e).query.call(e,m,{limit:0,reduce:!1}),{id:u,name:c,result:f?`exists`:`created`}}async function He(e){let t=await e.allDocs({startkey:`_design/`,endkey:`_design/`,include_docs:!0}),n={indexes:[{ddoc:null,name:`_all_docs`,type:`special`,def:{fields:[{_id:`asc`}]}}]};return n.indexes=P(n.indexes,t.rows.filter(function(e){return e.doc.language===`query`}).map(function(e){return(e.doc.views===void 0?[]:Object.keys(e.doc.views)).map(function(t){let n=e.doc.views[t];return{ddoc:e.id,name:t,type:`json`,def:Ne(n.options.def)}})})),n.indexes.sort(function(e,t){return x(e.name,t.name)}),n.total_rows=n.indexes.length,n}var Z=null,Q={"":{}},Ue={queryOpts:{limit:0,startkey:Q,endkey:Z},inMemoryFields:[]};function We(e,t){return e.def.fields.some(e=>m(e)===t)}function Ge(e,t){let n=e[t];return m(n)!==`$eq`}function Ke(e,t){let n=t.def.fields.map(m);return e.slice().sort(function(e,t){let r=n.indexOf(e),i=n.indexOf(t);return r===-1&&(r=Number.MAX_VALUE),i===-1&&(i=Number.MAX_VALUE),x(r,i)})}function qe(e,t,n){n=Ke(n,e);let r=!1;for(let i=0,a=n.length;i<a;i++){let o=n[i];if(r||!We(e,o))return n.slice(i);i<a-1&&Ge(t,o)&&(r=!0)}return[]}function Je(e){let t=[];for(let[n,r]of Object.entries(e))for(let e of Object.keys(r))e===`$ne`&&t.push(n);return t}function Ye(e,t,n,r){return Ke(U(P(e,qe(t,n,r),Je(n))),t)}function Xe(e,t,n){if(t){let r=R(t,e),i=L(n,e);return r&&i}return z(n,e)}var Ze=[`$eq`,`$gt`,`$gte`,`$lt`,`$lte`];function Qe(e){return Ze.indexOf(e)===-1}function $e(e,t){let n=t[e[0]];return n===void 0?!0:!(Object.keys(n).length===1&&m(n)===`$ne`)}function et(e,t,n,r){let i=e.def.fields.map(m);return Xe(i,t,n)?$e(i,r):!1}function tt(e,t,n,r){return r.filter(function(r){return et(r,n,t,e)})}function nt(e,t,n,r,i){let a=tt(e,t,n,r);if(a.length===0){if(i)throw{error:`no_usable_index`,message:`There is no index available for this selector.`};let e=r[0];return e.defaultUsed=!0,e}if(a.length===1&&!i)return a[0];let o=B(t);function s(e){let t=e.def.fields.map(m),n=0;for(let e of t)o[e]&&n++;return n}if(i){let e=`_design/`+i[0],t=i.length===2?i[1]:!1,n=a.find(function(n){return!!(t&&n.ddoc===e&&t===n.name||n.ddoc===e)});if(!n)throw{error:`unknown_error`,message:`Could not find that index or could not use that index for the query`};return n}return V(a,s)}function rt(e,t){switch(e){case`$eq`:return{key:t};case`$lte`:return{endkey:t};case`$gte`:return{startkey:t};case`$lt`:return{endkey:t,inclusive_end:!1};case`$gt`:return{startkey:t,inclusive_start:!1}}return{startkey:Z}}function it(e,t){let n=m(t.def.fields[0]),r=e[n]||{},i=[],a=Object.keys(r),o;for(let e of a){Qe(e)&&i.push(n);let t=r[e],a=rt(e,t);o=o?F([o,a]):a}return{queryOpts:o,inMemoryFields:i}}function at(e,t){switch(e){case`$eq`:return{startkey:t,endkey:t};case`$lte`:return{endkey:t};case`$gte`:return{startkey:t};case`$lt`:return{endkey:t,inclusive_end:!1};case`$gt`:return{startkey:t,inclusive_start:!1}}}function ot(e,t){let n=t.def.fields.map(m),r=[],i=[],a=[],o,s;function c(e){o!==!1&&i.push(Z),s!==!1&&a.push(Q),r=n.slice(e)}for(let t=0,r=n.length;t<r;t++){let r=e[n[t]];if(!r||!Object.keys(r).length){c(t);break}else if(Object.keys(r).some(Qe)){c(t);break}else if(t>0){let i=`$gt`in r||`$gte`in r||`$lt`in r||`$lte`in r,a=Object.keys(e[n[t-1]]),o=H(a,[`$eq`]),s=H(a,Object.keys(r));if(i&&!o&&!s){c(t);break}}let l=Object.keys(r),u=null;for(let e of l){let t=r[e],n=at(e,t);u=u?F([u,n]):n}i.push(`startkey`in u?u.startkey:Z),a.push(`endkey`in u?u.endkey:Q),`inclusive_start`in u&&(o=u.inclusive_start),`inclusive_end`in u&&(s=u.inclusive_end)}let l={startkey:i,endkey:a};return o!==void 0&&(l.inclusive_start=o),s!==void 0&&(l.inclusive_end=s),{queryOpts:l,inMemoryFields:r}}function st(e){return Object.keys(e).map(function(t){return e[t]}).some(function(e){return typeof e==`object`&&Object.keys(e).length===0})}function ct(e){return{queryOpts:{startkey:null},inMemoryFields:[Object.keys(e)]}}function lt(e,t){return t.defaultUsed?ct(e,t):t.def.fields.length===1?it(e,t):ot(e,t)}function ut(e,t){let n=e.selector,r=e.sort;if(st(n))return Object.assign({},Ue,{index:t[0]});let i=Be(n,r),a=i.fields,o=i.sortOrder,s=nt(n,a,o,t,e.use_index),c=lt(n,s),l=c.queryOpts,u=c.inMemoryFields;return{queryOpts:l,index:s,inMemoryFields:Ye(u,s,n,a)}}function dt(e){return e.ddoc.substring(8)+`/`+e.name}async function ft(e,t){let n=i(t);n.descending?(`endkey`in n&&typeof n.endkey!=`string`&&(n.endkey=``),`startkey`in n&&typeof n.startkey!=`string`&&(n.limit=0)):(`startkey`in n&&typeof n.startkey!=`string`&&(n.startkey=``),`endkey`in n&&typeof n.endkey!=`string`&&(n.limit=0)),`key`in n&&typeof n.key!=`string`&&(n.limit=0),n.limit>0&&n.indexes_count&&(n.original_limit=n.limit,n.limit+=n.indexes_count);let r=await e.allDocs(n);return r.rows=r.rows.filter(function(e){return!/^_design\//.test(e.id)}),n.original_limit&&(n.limit=n.original_limit),r.rows=r.rows.slice(0,n.limit),r}async function pt(e,t,n){return n.name===`_all_docs`?ft(e,t):X(e).query.call(e,dt(n),t)}async function mt(e,t,n){t.selector&&=(q(t.selector,!1),_(t.selector)),t.sort&&=Ae(t.sort),t.use_index&&=Me(t.use_index),`limit`in t||(t.limit=25),ze(t);let r=await He(e);e.constructor.emit(`debug`,[`find`,`planning query`,t]);let i=ut(t,r.indexes);e.constructor.emit(`debug`,[`find`,`query plan`,i]);let a=i.index;Re(t,a);let o=Object.assign({include_docs:!0,reduce:!1,indexes_count:r.total_rows},i.queryOpts);if(`startkey`in o&&`endkey`in o&&S(o.startkey,o.endkey)>0)return{docs:[]};if(t.sort&&typeof t.sort[0]!=`string`&&l(t.sort[0])===`desc`&&(o.descending=!0,o=Ie(o)),i.inMemoryFields.length||(o.limit=t.limit,`skip`in t&&(o.skip=t.skip)),n)return Promise.resolve(i,o);let s=await pt(e,o,a);o.inclusive_start===!1&&(s.rows=Fe(s.rows,o.startkey,a)),i.inMemoryFields.length&&(s.rows=g(s.rows,t,i.inMemoryFields));let c={docs:s.rows.map(function(e){let n=e.doc;return t.fields?I(n,t.fields):n})};return a.defaultUsed&&(c.warning=`No matching index found, create an index to optimize query time.`),c}async function ht(e,t){let n=await mt(e,t,!0);return{dbname:e.name,index:n.index,selector:t.selector,range:{start_key:n.queryOpts.startkey,end_key:n.queryOpts.endkey},opts:{use_index:t.use_index||[],bookmark:`nil`,limit:t.limit,skip:t.skip,sort:t.sort||{},fields:t.fields,conflicts:!1,r:[49]},limit:t.limit,skip:t.skip||0,fields:t.fields}}async function gt(e,t){if(!t.ddoc)throw Error(`you must supply an index.ddoc when deleting`);if(!t.name)throw Error(`you must supply an index.name when deleting`);let n=t.ddoc,r=t.name;function i(e){return Object.keys(e.views).length===1&&e.views[r]?{_id:n,_deleted:!0}:(delete e.views[r],e)}return await s(e,n,i),await X(e).viewCleanup.apply(e),{ok:!0}}var $={};$.createIndex=W(async function(e){if(typeof e!=`object`)throw Error(`you must provide an index to create`);return(a(this)?he:Ve)(this,e)}),$.find=W(async function(e){if(typeof e!=`object`)throw Error(`you must provide search parameters to find()`);return(a(this)?ge:mt)(this,e)}),$.explain=W(async function(e){if(typeof e!=`object`)throw Error(`you must provide search parameters to explain()`);return(a(this)?_e:ht)(this,e)}),$.getIndexes=W(async function(){return(a(this)?ve:He)(this)}),$.deleteIndex=W(async function(e){if(typeof e!=`object`)throw Error(`you must provide an index to delete`);return(a(this)?ye:gt)(this,e)});export{$ as default};
|