snow-cms 1.1.4 → 1.2.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.
@@ -1,4 +1,4 @@
1
- import{j as he,i as z,T as Ae,u as ke,g as pe,L as st,d as Oe,b as re,c as ot}from"./index-browser.es2.js";import{c as U,h as D,t as B,n as $e,p as ct,a as Ne,b as Pe,g as Ve,d as at,e as ie,i as Ce,s as ut,j as C,m as se}from"./index.es9.js";import"./index.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 K={name:v,db:E,sourceDB:e,adapter:e.adapter,mapFun:n,reduceFun:i};let j;try{j=await K.db.get("_local/lastSeq")}catch(F){if(F.status!==404)throw F}return K.seq=j?j.seq:0,p&&K.db.once("destroyed",function(){delete p[u]}),K});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.
1
+ import{k as pe,i as z,g as he,T as Ae,u as ke,K as st,d as Oe,j 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.es9.js";import"./index.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){pe(function(){t(null,n)})},function(n){pe(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 h;if(!o&&(h=e._cachedViews=e._cachedViews||{},h[u]))return h[u];const g=e.info().then(async function(S){const v=S.db_name+"-mrview-"+(o?"temp":Ae(u));function m(T){T.views=T.views||{};let P=t;P.indexOf("/")===-1&&(P=t+"/"+t);const Q=T.views[P]=T.views[P]||{};if(!Q[v])return Q[v]=!0,T}await ke(e,"_local/"+l,m);const F=(await e.registerDependentDatabase(v)).db;F.auto_compaction=!0;const R={name:v,db:F,sourceDB:e,adapter:e.adapter,mapFun:n,reduceFun:i};let j;try{j=await R.db.get("_local/lastSeq")}catch(T){if(T.status!==404)throw T}return R.seq=j?j.seq:0,h&&R.db.once("destroyed",function(){delete h[u]}),R});return h&&(h[u]=g),g}const Me={},Ee=new ge,yt=50;function fe(e){return e.indexOf("/")===-1?[e,e]:e.split("/")}function pt(e){return e.length===1&&/^1-/.test(e[0].rev)}function Fe(e,t,n){try{e.emit("error",t)}catch{Oe("error",`The user's map/reduce function threw an uncaught error.
2
2
  You can debug this error by doing:
3
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 K(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=K(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,R){const G=[],W=new Set;for(const $ of R.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 R();return G($,x)}function R(){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),R=_.get(A);R&&(w.doc=R)}}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 R of w)k[R]=k[R]||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),Re=(...e)=>{let t=[];for(const n of e)Array.isArray(n)?t=t.concat(Re(...n)):t.push(n);return t},Ke=typeof Array.prototype.flat=="function"?gt:Re;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 Rt(){throw new Error("reduce not supported")}function Kt(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,Rt,Kt);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=Pe(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 Ve(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=Ke(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 Ne(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),Ne(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=Ke(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 K=Object.keys(E);let j=null;for(const F of K){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=Pe(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"&&Ve(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};
4
+ Please double-check your map/reduce function.`),Oe("error",t,n)}}function ht(e,t,n,i){function o(r,s,c){try{s(c)}catch(a){Fe(r,a,{fun:s,doc:c})}}function l(r,s,c,a,f){try{return{output:s(c,a,f)}}catch(k){return Fe(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 h(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 E(r){if(typeof r<"u"){const s=Number(r);return!isNaN(s)&&s===parseInt(r,10)?s:r}}function F(r){return r.group_level=E(r.group_level),r.limit=E(r.limit),r.skip=E(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 T(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 p=fe(s),b=await r.fetch("_design/"+p[0]+"/_view/"+p[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,he(_);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 p of Object.keys(s))Array.isArray(s[p])?f[p]=s[p]:f[p]=s[p].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,he(y);return new Promise(function(p){p(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 pt(d)?Promise.resolve(f):s.db.get(a).catch(L(f))}function p(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 p(_);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 p($,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(p(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 p=a?d.key:null;if(a&&Array.isArray(p)&&(p=p.slice(0,I)),y&&U(y.groupKey,p)===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:p})}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:h(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(p){if("value"in p.doc&&typeof p.doc.value=="object"&&p.doc.value!==null){const _=Object.keys(p.doc.value).sort(),w=["id","key","value"];if(!(_<w||_>w))return p.doc.value}const b=ct(p.doc._id);return{key:b[0],id:b[1],value:"value"in p.doc?p.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:h(d,s.limit,s.skip)},s.update_seq&&(y.update_seq=r.seq),s.include_docs){const p=Ie(d.map(g)),b=await r.sourceDB.allDocs({keys:p,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,p;if("start_key"in s&&(y=s.start_key),"startkey"in s&&(y=s.startkey),"end_key"in s&&(p=s.end_key),"endkey"in s&&(p=s.endkey),typeof y<"u"&&(d.startkey=s.descending?B([y,{}]):B([y])),typeof p<"u"){let _=s.inclusive_end!==!1;s.descending&&(_=!_),d.endkey=B(_?[p,{}]:[p])}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 p=fe(y),b="_design/"+p[0],_=p[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 p=y.key.substring(8);for(const b of c.get(y.key)){let _=p+"/"+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 T(r,s,c);const a={changes_batch_size:r.__opts.view_update_changes_batch_size||yt};if(typeof s!="string")return j(c,s),Ee.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()})}),Ee.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 p=await je(r,f,s.map,s.reduce,!1,e);return c.stale==="ok"||c.stale==="update_after"?(c.stale==="update_after"&&pe(function(){ce(p,a)}),ae(p,c)):(await ce(p,a),ae(p,c))}}function rt(r,s,c){const a=this;typeof s=="function"&&(c=s,s={}),s=s?F(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 Te(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],h=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(h,10)!==h&&(i="Query operator $mod's remainder is not an integer.",o=h)}if(e==="$exists"&&typeof t!="boolean"&&(i="Query operator $exists must be a boolean."),e==="$type"){const u=["null","boolean","number","string","array","object"],h='"'+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: "+h+".")}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,h=ee(o)?JSON.stringify(o,null," "):o;i+=" Received"+u+": "+h}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 he(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 Et(e){return await H(e,"_index",{method:"GET"})}async function Ft(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 Tt(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):Tt(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=ht("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 h=i.indexOf(l);h===-1&&(h=Number.MAX_VALUE);let g=i.indexOf(u);return g===-1&&(g=Number.MAX_VALUE),h<g?-1:h>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(),h="_design/"+u;let g=!1,S=!1;function v(E){return E._rev&&E.language!=="query"&&(g=!0),E.language="query",E.views=E.views||{},S=!!E.views[l],S?!1:(E.views[l]={map:{fields:ve(t.index.fields),partial_filter_selector:t.index.partial_filter_selector},reduce:"_count",options:{def:n}},E)}if(e.constructor.emit("debug",["find","creating index",h]),await ke(e,h,v),g)throw new Error('invalid language for ddoc with id "'+h+'" (should be "query")');const m=u+"/"+l;return await be(e).query.call(e,m,{limit:0,reduce:!1}),{id:h,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{};const g=i[0];return g.defaultUsed=!0,g}if(l.length===1&&!o)return l[0];const u=_t(t);function h(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{};return v}return vt(l,h)}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 h of l){Je(h)&&o.push(n);const g=i[h],S=dn(h,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 pn(e,t){const n=t.def.fields.map(C);let i=[];const o=[],l=[];let u,h;function g(v){u!==!1&&o.push(ne),h!==!1&&l.push(me),i=n.slice(v)}for(let v=0,m=n.length;v<m;v++){const E=n[v],F=e[E];if(!F||!Object.keys(F).length){g(v);break}else if(Object.keys(F).some(Je)){g(v);break}else if(v>0){const T="$gt"in F||"$gte"in F||"$lt"in F||"$lte"in F,P=Object.keys(e[n[v-1]]),Q=Te(P,["$eq"]),L=Te(P,Object.keys(F));if(T&&!Q&&!L){g(v);break}}const R=Object.keys(F);let j=null;for(const T of R){const P=F[T],Q=yn(T,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&&(h=j.inclusive_end)}const S={startkey:o,endkey:l};return typeof u<"u"&&(S.inclusive_start=u),typeof h<"u"&&(S.inclusive_end=h),{queryOpts:S,inMemoryFields:i}}function hn(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):pn(e,t)}function kn(e,t){const n=e.selector,i=e.sort;if(hn(n))return Object.assign({},Zt,{index:t[0]});const o=Yt(n,i),l=o.fields,u=o.sortOrder,h=ln(n,l,u,t,e.use_index),g=mn(n,h),S=g.queryOpts,v=g.inMemoryFields,m=rn(v,h,n,l);return{queryOpts:S,index:h,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)?Et: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)?Ft:xn)(this,e)});export{Y as default};
@@ -1 +1 @@
1
- import{g as G}from"./index.js";class y extends Error{constructor(t,o,u){super(),this.status=t,this.name=o,this.message=u,this.error=!0}toString(){return JSON.stringify({status:this.status,name:this.name,message:this.message,reason:this.reason})}}new y(401,"unauthorized","Name or password is incorrect.");var ke=new y(400,"bad_request","Missing JSON list of 'docs'"),et=new y(404,"not_found","missing"),tt=new y(409,"conflict","Document update conflict"),oe=new y(400,"bad_request","_id field must contain a string"),se=new y(412,"missing_id","_id is required for puts"),ae=new y(400,"bad_request","Only reserved document ids may start with underscore.");new y(412,"precondition_failed","Database not open");var ue=new y(500,"unknown_error","Database encountered an unknown error"),nt=new y(500,"badarg","Some query argument is invalid");new y(400,"invalid_request","Request was invalid");var rt=new y(400,"query_parse_error","Some query parameter is invalid"),it=new y(500,"doc_validation","Bad special document member"),fe=new y(400,"bad_request","Something wrong with the request"),ot=new y(400,"bad_request","Document must be a JSON object");new y(404,"not_found","Database not found");var st=new y(500,"indexed_db_went_bad","unknown");new y(500,"web_sql_went_bad","unknown");new y(500,"levelDB_went_went_bad","unknown");new y(403,"forbidden","Forbidden by design doc validate_doc_update function");var at=new y(400,"bad_request","Invalid rev format");new y(412,"file_exists","The database could not be created, the file already exists.");var ut=new y(412,"missing_stub","A pre-existing attachment stub wasn't found");new y(413,"invalid_url","Provided URL is invalid");function x(e,t){function o(u){for(var a=Object.getOwnPropertyNames(e),l=0,h=a.length;l<h;l++)typeof e[a[l]]!="function"&&(this[a[l]]=e[a[l]]);this.stack===void 0&&(this.stack=new Error().stack),u!==void 0&&(this.reason=u)}return o.prototype=y.prototype,new o(t)}function ft(e){if(typeof e!="object"){var t=e;e=ue,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=new Error().stack),e}var P={exports:{}},O=typeof Reflect=="object"?Reflect:null,j=O&&typeof O.apply=="function"?O.apply:function(t,o,u){return Function.prototype.apply.call(t,o,u)},I;O&&typeof O.ownKeys=="function"?I=O.ownKeys:Object.getOwnPropertySymbols?I=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:I=function(t){return Object.getOwnPropertyNames(t)};function ce(e){console&&console.warn&&console.warn(e)}var W=Number.isNaN||function(t){return t!==t};function v(){v.init.call(this)}P.exports=v;P.exports.once=pe;v.EventEmitter=v;v.prototype._events=void 0;v.prototype._eventsCount=0;v.prototype._maxListeners=void 0;var V=10;function M(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(v,"defaultMaxListeners",{enumerable:!0,get:function(){return V},set:function(e){if(typeof e!="number"||e<0||W(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");V=e}});v.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};v.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||W(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this};function J(e){return e._maxListeners===void 0?v.defaultMaxListeners:e._maxListeners}v.prototype.getMaxListeners=function(){return J(this)};v.prototype.emit=function(t){for(var o=[],u=1;u<arguments.length;u++)o.push(arguments[u]);var a=t==="error",l=this._events;if(l!==void 0)a=a&&l.error===void 0;else if(!a)return!1;if(a){var h;if(o.length>0&&(h=o[0]),h instanceof Error)throw h;var p=new Error("Unhandled error."+(h?" ("+h.message+")":""));throw p.context=h,p}var m=l[t];if(m===void 0)return!1;if(typeof m=="function")j(m,this,o);else for(var A=m.length,w=Y(m,A),u=0;u<A;++u)j(w[u],this,o);return!0};function $(e,t,o,u){var a,l,h;if(M(o),l=e._events,l===void 0?(l=e._events=Object.create(null),e._eventsCount=0):(l.newListener!==void 0&&(e.emit("newListener",t,o.listener?o.listener:o),l=e._events),h=l[t]),h===void 0)h=l[t]=o,++e._eventsCount;else if(typeof h=="function"?h=l[t]=u?[o,h]:[h,o]:u?h.unshift(o):h.push(o),a=J(e),a>0&&h.length>a&&!h.warned){h.warned=!0;var p=new Error("Possible EventEmitter memory leak detected. "+h.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");p.name="MaxListenersExceededWarning",p.emitter=e,p.type=t,p.count=h.length,ce(p)}return e}v.prototype.addListener=function(t,o){return $(this,t,o,!1)};v.prototype.on=v.prototype.addListener;v.prototype.prependListener=function(t,o){return $(this,t,o,!0)};function le(){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 H(e,t,o){var u={fired:!1,wrapFn:void 0,target:e,type:t,listener:o},a=le.bind(u);return a.listener=o,u.wrapFn=a,a}v.prototype.once=function(t,o){return M(o),this.on(t,H(this,t,o)),this};v.prototype.prependOnceListener=function(t,o){return M(o),this.prependListener(t,H(this,t,o)),this};v.prototype.removeListener=function(t,o){var u,a,l,h,p;if(M(o),a=this._events,a===void 0)return this;if(u=a[t],u===void 0)return this;if(u===o||u.listener===o)--this._eventsCount===0?this._events=Object.create(null):(delete a[t],a.removeListener&&this.emit("removeListener",t,u.listener||o));else if(typeof u!="function"){for(l=-1,h=u.length-1;h>=0;h--)if(u[h]===o||u[h].listener===o){p=u[h].listener,l=h;break}if(l<0)return this;l===0?u.shift():he(u,l),u.length===1&&(a[t]=u[0]),a.removeListener!==void 0&&this.emit("removeListener",t,p||o)}return this};v.prototype.off=v.prototype.removeListener;v.prototype.removeAllListeners=function(t){var o,u,a;if(u=this._events,u===void 0)return this;if(u.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):u[t]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete u[t]),this;if(arguments.length===0){var l=Object.keys(u),h;for(a=0;a<l.length;++a)h=l[a],h!=="removeListener"&&this.removeAllListeners(h);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(o=u[t],typeof o=="function")this.removeListener(t,o);else if(o!==void 0)for(a=o.length-1;a>=0;a--)this.removeListener(t,o[a]);return this};function Q(e,t,o){var u=e._events;if(u===void 0)return[];var a=u[t];return a===void 0?[]:typeof a=="function"?o?[a.listener||a]:[a]:o?de(a):Y(a,a.length)}v.prototype.listeners=function(t){return Q(this,t,!0)};v.prototype.rawListeners=function(t){return Q(this,t,!1)};v.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):X.call(e,t)};v.prototype.listenerCount=X;function X(e){var t=this._events;if(t!==void 0){var o=t[e];if(typeof o=="function")return 1;if(o!==void 0)return o.length}return 0}v.prototype.eventNames=function(){return this._eventsCount>0?I(this._events):[]};function Y(e,t){for(var o=new Array(t),u=0;u<t;++u)o[u]=e[u];return o}function he(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function de(e){for(var t=new Array(e.length),o=0;o<t.length;++o)t[o]=e[o].listener||e[o];return t}function pe(e,t){return new Promise(function(o,u){function a(h){e.removeListener(t,l),u(h)}function l(){typeof e.removeListener=="function"&&e.removeListener("error",a),o([].slice.call(arguments))}Z(e,t,l,{once:!0}),t!=="error"&&ve(e,a,{once:!0})})}function ve(e,t,o){typeof e.on=="function"&&Z(e,"error",t,o)}function Z(e,t,o,u){if(typeof e.on=="function")u.once?e.once(t,o):e.on(t,o);else if(typeof e.addEventListener=="function")e.addEventListener(t,function a(l){u.once&&e.removeEventListener(t,a),o(l)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e)}var ye=P.exports;const k=G(ye);var R,ge=new Uint8Array(16);function me(){if(!R&&(R=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||typeof msCrypto<"u"&&typeof msCrypto.getRandomValues=="function"&&msCrypto.getRandomValues.bind(msCrypto),!R))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return R(ge)}const _e=/^(?:[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 we(e){return typeof e=="string"&&_e.test(e)}var b=[];for(var D=0;D<256;++D)b.push((D+256).toString(16).substr(1));function be(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,o=(b[e[t+0]]+b[e[t+1]]+b[e[t+2]]+b[e[t+3]]+"-"+b[e[t+4]]+b[e[t+5]]+"-"+b[e[t+6]]+b[e[t+7]]+"-"+b[e[t+8]]+b[e[t+9]]+"-"+b[e[t+10]]+b[e[t+11]]+b[e[t+12]]+b[e[t+13]]+b[e[t+14]]+b[e[t+15]]).toLowerCase();if(!we(o))throw TypeError("Stringified UUID is invalid");return o}function ee(e,t,o){e=e||{};var u=e.random||(e.rng||me)();if(u[6]=u[6]&15|64,u[8]=u[8]&63|128,t){o=o||0;for(var a=0;a<16;++a)t[o+a]=u[a];return t}return be(u)}var Ae=function(e){return atob(e)},te=function(e){return btoa(e)};function Be(e,t){e=e||[],t=t||{};try{return new Blob(e,t)}catch(l){if(l.name!=="TypeError")throw l;for(var o=typeof BlobBuilder<"u"?BlobBuilder:typeof MSBlobBuilder<"u"?MSBlobBuilder:typeof MozBlobBuilder<"u"?MozBlobBuilder:WebKitBlobBuilder,u=new o,a=0;a<e.length;a+=1)u.append(e[a]);return u.getBlob(t.type)}}function Le(e){for(var t=e.length,o=new ArrayBuffer(t),u=new Uint8Array(o),a=0;a<t;a++)u[a]=e.charCodeAt(a);return o}function Se(e,t){return Be([Le(e)],{type:t})}function ct(e,t){return Se(Ae(e),t)}function Ee(e){for(var t="",o=new Uint8Array(e),u=o.byteLength,a=0;a<u;a++)t+=String.fromCharCode(o[a]);return t}function Ce(e,t){var o=new FileReader,u=typeof o.readAsBinaryString=="function";o.onloadend=function(a){var l=a.target.result||"";if(u)return t(l);t(Ee(l))},u?o.readAsBinaryString(e):o.readAsArrayBuffer(e)}function Oe(e,t){Ce(e,function(o){t(o)})}function lt(e,t){Oe(e,function(o){t(te(o))})}function Re(e,t){var o=new FileReader;o.onloadend=function(u){var a=u.target.result||new ArrayBuffer(0);t(a)},o.readAsArrayBuffer(e)}var ne={exports:{}};(function(e,t){(function(o){e.exports=o()})(function(o){var u=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];function a(c,f){var r=c[0],n=c[1],s=c[2],i=c[3];r+=(n&s|~n&i)+f[0]-680876936|0,r=(r<<7|r>>>25)+n|0,i+=(r&n|~r&s)+f[1]-389564586|0,i=(i<<12|i>>>20)+r|0,s+=(i&r|~i&n)+f[2]+606105819|0,s=(s<<17|s>>>15)+i|0,n+=(s&i|~s&r)+f[3]-1044525330|0,n=(n<<22|n>>>10)+s|0,r+=(n&s|~n&i)+f[4]-176418897|0,r=(r<<7|r>>>25)+n|0,i+=(r&n|~r&s)+f[5]+1200080426|0,i=(i<<12|i>>>20)+r|0,s+=(i&r|~i&n)+f[6]-1473231341|0,s=(s<<17|s>>>15)+i|0,n+=(s&i|~s&r)+f[7]-45705983|0,n=(n<<22|n>>>10)+s|0,r+=(n&s|~n&i)+f[8]+1770035416|0,r=(r<<7|r>>>25)+n|0,i+=(r&n|~r&s)+f[9]-1958414417|0,i=(i<<12|i>>>20)+r|0,s+=(i&r|~i&n)+f[10]-42063|0,s=(s<<17|s>>>15)+i|0,n+=(s&i|~s&r)+f[11]-1990404162|0,n=(n<<22|n>>>10)+s|0,r+=(n&s|~n&i)+f[12]+1804603682|0,r=(r<<7|r>>>25)+n|0,i+=(r&n|~r&s)+f[13]-40341101|0,i=(i<<12|i>>>20)+r|0,s+=(i&r|~i&n)+f[14]-1502002290|0,s=(s<<17|s>>>15)+i|0,n+=(s&i|~s&r)+f[15]+1236535329|0,n=(n<<22|n>>>10)+s|0,r+=(n&i|s&~i)+f[1]-165796510|0,r=(r<<5|r>>>27)+n|0,i+=(r&s|n&~s)+f[6]-1069501632|0,i=(i<<9|i>>>23)+r|0,s+=(i&n|r&~n)+f[11]+643717713|0,s=(s<<14|s>>>18)+i|0,n+=(s&r|i&~r)+f[0]-373897302|0,n=(n<<20|n>>>12)+s|0,r+=(n&i|s&~i)+f[5]-701558691|0,r=(r<<5|r>>>27)+n|0,i+=(r&s|n&~s)+f[10]+38016083|0,i=(i<<9|i>>>23)+r|0,s+=(i&n|r&~n)+f[15]-660478335|0,s=(s<<14|s>>>18)+i|0,n+=(s&r|i&~r)+f[4]-405537848|0,n=(n<<20|n>>>12)+s|0,r+=(n&i|s&~i)+f[9]+568446438|0,r=(r<<5|r>>>27)+n|0,i+=(r&s|n&~s)+f[14]-1019803690|0,i=(i<<9|i>>>23)+r|0,s+=(i&n|r&~n)+f[3]-187363961|0,s=(s<<14|s>>>18)+i|0,n+=(s&r|i&~r)+f[8]+1163531501|0,n=(n<<20|n>>>12)+s|0,r+=(n&i|s&~i)+f[13]-1444681467|0,r=(r<<5|r>>>27)+n|0,i+=(r&s|n&~s)+f[2]-51403784|0,i=(i<<9|i>>>23)+r|0,s+=(i&n|r&~n)+f[7]+1735328473|0,s=(s<<14|s>>>18)+i|0,n+=(s&r|i&~r)+f[12]-1926607734|0,n=(n<<20|n>>>12)+s|0,r+=(n^s^i)+f[5]-378558|0,r=(r<<4|r>>>28)+n|0,i+=(r^n^s)+f[8]-2022574463|0,i=(i<<11|i>>>21)+r|0,s+=(i^r^n)+f[11]+1839030562|0,s=(s<<16|s>>>16)+i|0,n+=(s^i^r)+f[14]-35309556|0,n=(n<<23|n>>>9)+s|0,r+=(n^s^i)+f[1]-1530992060|0,r=(r<<4|r>>>28)+n|0,i+=(r^n^s)+f[4]+1272893353|0,i=(i<<11|i>>>21)+r|0,s+=(i^r^n)+f[7]-155497632|0,s=(s<<16|s>>>16)+i|0,n+=(s^i^r)+f[10]-1094730640|0,n=(n<<23|n>>>9)+s|0,r+=(n^s^i)+f[13]+681279174|0,r=(r<<4|r>>>28)+n|0,i+=(r^n^s)+f[0]-358537222|0,i=(i<<11|i>>>21)+r|0,s+=(i^r^n)+f[3]-722521979|0,s=(s<<16|s>>>16)+i|0,n+=(s^i^r)+f[6]+76029189|0,n=(n<<23|n>>>9)+s|0,r+=(n^s^i)+f[9]-640364487|0,r=(r<<4|r>>>28)+n|0,i+=(r^n^s)+f[12]-421815835|0,i=(i<<11|i>>>21)+r|0,s+=(i^r^n)+f[15]+530742520|0,s=(s<<16|s>>>16)+i|0,n+=(s^i^r)+f[2]-995338651|0,n=(n<<23|n>>>9)+s|0,r+=(s^(n|~i))+f[0]-198630844|0,r=(r<<6|r>>>26)+n|0,i+=(n^(r|~s))+f[7]+1126891415|0,i=(i<<10|i>>>22)+r|0,s+=(r^(i|~n))+f[14]-1416354905|0,s=(s<<15|s>>>17)+i|0,n+=(i^(s|~r))+f[5]-57434055|0,n=(n<<21|n>>>11)+s|0,r+=(s^(n|~i))+f[12]+1700485571|0,r=(r<<6|r>>>26)+n|0,i+=(n^(r|~s))+f[3]-1894986606|0,i=(i<<10|i>>>22)+r|0,s+=(r^(i|~n))+f[10]-1051523|0,s=(s<<15|s>>>17)+i|0,n+=(i^(s|~r))+f[1]-2054922799|0,n=(n<<21|n>>>11)+s|0,r+=(s^(n|~i))+f[8]+1873313359|0,r=(r<<6|r>>>26)+n|0,i+=(n^(r|~s))+f[15]-30611744|0,i=(i<<10|i>>>22)+r|0,s+=(r^(i|~n))+f[6]-1560198380|0,s=(s<<15|s>>>17)+i|0,n+=(i^(s|~r))+f[13]+1309151649|0,n=(n<<21|n>>>11)+s|0,r+=(s^(n|~i))+f[4]-145523070|0,r=(r<<6|r>>>26)+n|0,i+=(n^(r|~s))+f[11]-1120210379|0,i=(i<<10|i>>>22)+r|0,s+=(r^(i|~n))+f[2]+718787259|0,s=(s<<15|s>>>17)+i|0,n+=(i^(s|~r))+f[9]-343485551|0,n=(n<<21|n>>>11)+s|0,c[0]=r+c[0]|0,c[1]=n+c[1]|0,c[2]=s+c[2]|0,c[3]=i+c[3]|0}function l(c){var f=[],r;for(r=0;r<64;r+=4)f[r>>2]=c.charCodeAt(r)+(c.charCodeAt(r+1)<<8)+(c.charCodeAt(r+2)<<16)+(c.charCodeAt(r+3)<<24);return f}function h(c){var f=[],r;for(r=0;r<64;r+=4)f[r>>2]=c[r]+(c[r+1]<<8)+(c[r+2]<<16)+(c[r+3]<<24);return f}function p(c){var f=c.length,r=[1732584193,-271733879,-1732584194,271733878],n,s,i,g,S,L;for(n=64;n<=f;n+=64)a(r,l(c.substring(n-64,n)));for(c=c.substring(n-64),s=c.length,i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],n=0;n<s;n+=1)i[n>>2]|=c.charCodeAt(n)<<(n%4<<3);if(i[n>>2]|=128<<(n%4<<3),n>55)for(a(r,i),n=0;n<16;n+=1)i[n]=0;return g=f*8,g=g.toString(16).match(/(.*?)(.{0,8})$/),S=parseInt(g[2],16),L=parseInt(g[1],16)||0,i[14]=S,i[15]=L,a(r,i),r}function m(c){var f=c.length,r=[1732584193,-271733879,-1732584194,271733878],n,s,i,g,S,L;for(n=64;n<=f;n+=64)a(r,h(c.subarray(n-64,n)));for(c=n-64<f?c.subarray(n-64):new Uint8Array(0),s=c.length,i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],n=0;n<s;n+=1)i[n>>2]|=c[n]<<(n%4<<3);if(i[n>>2]|=128<<(n%4<<3),n>55)for(a(r,i),n=0;n<16;n+=1)i[n]=0;return g=f*8,g=g.toString(16).match(/(.*?)(.{0,8})$/),S=parseInt(g[2],16),L=parseInt(g[1],16)||0,i[14]=S,i[15]=L,a(r,i),r}function A(c){var f="",r;for(r=0;r<4;r+=1)f+=u[c>>r*8+4&15]+u[c>>r*8&15];return f}function w(c){var f;for(f=0;f<c.length;f+=1)c[f]=A(c[f]);return c.join("")}w(p("hello")),typeof ArrayBuffer<"u"&&!ArrayBuffer.prototype.slice&&function(){function c(f,r){return f=f|0||0,f<0?Math.max(f+r,0):Math.min(f,r)}ArrayBuffer.prototype.slice=function(f,r){var n=this.byteLength,s=c(f,n),i=n,g,S,L,q;return r!==o&&(i=c(r,n)),s>i?new ArrayBuffer(0):(g=i-s,S=new ArrayBuffer(g),L=new Uint8Array(S),q=new Uint8Array(this,s,g),L.set(q),S)}}();function E(c){return/[\u0080-\uFFFF]/.test(c)&&(c=unescape(encodeURIComponent(c))),c}function B(c,f){var r=c.length,n=new ArrayBuffer(r),s=new Uint8Array(n),i;for(i=0;i<r;i+=1)s[i]=c.charCodeAt(i);return f?s:n}function C(c){return String.fromCharCode.apply(null,new Uint8Array(c))}function N(c,f,r){var n=new Uint8Array(c.byteLength+f.byteLength);return n.set(new Uint8Array(c)),n.set(new Uint8Array(f),c.byteLength),n}function _(c){var f=[],r=c.length,n;for(n=0;n<r-1;n+=2)f.push(parseInt(c.substr(n,2),16));return String.fromCharCode.apply(String,f)}function d(){this.reset()}return d.prototype.append=function(c){return this.appendBinary(E(c)),this},d.prototype.appendBinary=function(c){this._buff+=c,this._length+=c.length;var f=this._buff.length,r;for(r=64;r<=f;r+=64)a(this._hash,l(this._buff.substring(r-64,r)));return this._buff=this._buff.substring(r-64),this},d.prototype.end=function(c){var f=this._buff,r=f.length,n,s=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],i;for(n=0;n<r;n+=1)s[n>>2]|=f.charCodeAt(n)<<(n%4<<3);return this._finish(s,r),i=w(this._hash),c&&(i=_(i)),this.reset(),i},d.prototype.reset=function(){return this._buff="",this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},d.prototype.getState=function(){return{buff:this._buff,length:this._length,hash:this._hash.slice()}},d.prototype.setState=function(c){return this._buff=c.buff,this._length=c.length,this._hash=c.hash,this},d.prototype.destroy=function(){delete this._hash,delete this._buff,delete this._length},d.prototype._finish=function(c,f){var r=f,n,s,i;if(c[r>>2]|=128<<(r%4<<3),r>55)for(a(this._hash,c),r=0;r<16;r+=1)c[r]=0;n=this._length*8,n=n.toString(16).match(/(.*?)(.{0,8})$/),s=parseInt(n[2],16),i=parseInt(n[1],16)||0,c[14]=s,c[15]=i,a(this._hash,c)},d.hash=function(c,f){return d.hashBinary(E(c),f)},d.hashBinary=function(c,f){var r=p(c),n=w(r);return f?_(n):n},d.ArrayBuffer=function(){this.reset()},d.ArrayBuffer.prototype.append=function(c){var f=N(this._buff.buffer,c),r=f.length,n;for(this._length+=c.byteLength,n=64;n<=r;n+=64)a(this._hash,h(f.subarray(n-64,n)));return this._buff=n-64<r?new Uint8Array(f.buffer.slice(n-64)):new Uint8Array(0),this},d.ArrayBuffer.prototype.end=function(c){var f=this._buff,r=f.length,n=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],s,i;for(s=0;s<r;s+=1)n[s>>2]|=f[s]<<(s%4<<3);return this._finish(n,r),i=w(this._hash),c&&(i=_(i)),this.reset(),i},d.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array(0),this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},d.ArrayBuffer.prototype.getState=function(){var c=d.prototype.getState.call(this);return c.buff=C(c.buff),c},d.ArrayBuffer.prototype.setState=function(c){return c.buff=B(c.buff,!0),d.prototype.setState.call(this,c)},d.ArrayBuffer.prototype.destroy=d.prototype.destroy,d.ArrayBuffer.prototype._finish=d.prototype._finish,d.ArrayBuffer.hash=function(c,f){var r=m(new Uint8Array(c)),n=w(r);return f?_(n):n},d})})(ne);var xe=ne.exports;const T=G(xe);var Ie=self.setImmediate||self.setTimeout,Me=32768;function Ne(e){return te(e)}function De(e,t,o,u,a){(o>0||u<t.size)&&(t=t.slice(o,u)),Re(t,function(l){e.append(l),a()})}function Te(e,t,o,u,a){(o>0||u<t.length)&&(t=t.substring(o,u)),e.appendBinary(t),a()}function ht(e,t){var o=typeof e=="string",u=o?e.length:e.size,a=Math.min(Me,u),l=Math.ceil(u/a),h=0,p=o?new T:new T.ArrayBuffer,m=o?Te:De;function A(){Ie(E)}function w(){var B=p.end(!0),C=Ne(B);t(C),p.destroy()}function E(){var B=h*a,C=B+a;h++,h<l?m(p,e,B,C,A):m(p,e,B,C,w)}E()}function Ue(e){return T.hash(e)}function Fe(e){return typeof ArrayBuffer<"u"&&e instanceof ArrayBuffer||typeof Blob<"u"&&e instanceof Blob}function Pe(e){return e instanceof ArrayBuffer?e.slice(0):e.slice(0,e.size,e.type)}var re=Function.prototype.toString,qe=re.call(Object);function je(e){var t=Object.getPrototypeOf(e);if(t===null)return!0;var o=t.constructor;return typeof o=="function"&&o instanceof o&&re.call(o)==qe}function U(e){var t,o,u;if(!e||typeof e!="object")return e;if(Array.isArray(e)){for(t=[],o=0,u=e.length;o<u;o++)t[o]=U(e[o]);return t}if(e instanceof Date&&isFinite(e))return e.toISOString();if(Fe(e))return Pe(e);if(!je(e))return e;t={};for(o in e)if(Object.prototype.hasOwnProperty.call(e,o)){var a=U(e[o]);typeof a<"u"&&(t[o]=a)}return t}function Ve(e){var t=!1;return function(...o){if(t)throw new Error("once called more than once");t=!0,e.apply(this,o)}}function ze(e){return function(...t){t=U(t);var o=this,u=typeof t[t.length-1]=="function"?t.pop():!1,a=new Promise(function(l,h){var p;try{var m=Ve(function(A,w){A?h(A):l(w)});t.push(m),p=e.apply(o,t),p&&typeof p.then=="function"&&l(p)}catch(A){h(A)}});return u&&a.then(function(l){u(null,l)},u),a}}function Ke(e,t,o){if(e.constructor.listeners("debug").length){for(var u=["api",e.name,t],a=0;a<o.length-1;a++)u.push(o[a]);e.constructor.emit("debug",u);var l=o[o.length-1];o[o.length-1]=function(h,p){var m=["api",e.name,t];m=m.concat(h?["error",h]:["success",p]),e.constructor.emit("debug",m),l(h,p)}}}function dt(e,t){return ze(function(...o){if(this._closed)return Promise.reject(new Error("database is closed"));if(this._destroyed)return Promise.reject(new Error("database is destroyed"));var u=this;return Ke(u,e,o),this.taskqueue.isReady?t.apply(this,o):new Promise(function(a,l){u.taskqueue.addTask(function(h){h?l(h):a(u[e].apply(u,o))})})})}function ie(e,t){for(var o={},u=0,a=t.length;u<a;u++){var l=t[u];l in e&&(o[l]=e[l])}return o}var Ge=6;function z(e){return e}function We(e){return[{ok:e}]}function pt(e,t,o){var u=t.docs,a=new Map;u.forEach(function(_){a.has(_.id)?a.get(_.id).push(_):a.set(_.id,[_])});var l=a.size,h=0,p=new Array(l);function m(){var _=[];p.forEach(function(d){d.docs.forEach(function(c){_.push({id:d.id,docs:[c]})})}),o(null,{results:_})}function A(){++h===l&&m()}function w(_,d,c){p[_]={id:d,docs:c},A()}var E=[];a.forEach(function(_,d){E.push(d)});var B=0;function C(){if(!(B>=E.length)){var _=Math.min(B+Ge,E.length),d=E.slice(B,_);N(d,B),B+=d.length}}function N(_,d){_.forEach(function(c,f){var r=d+f,n=a.get(c),s=ie(n[0],["atts_since","attachments"]);s.open_revs=n.map(function(g){return g.rev}),s.open_revs=s.open_revs.filter(z);var i=z;s.open_revs.length===0&&(delete s.open_revs,i=We),["revs","attachments","binary","ajax","latest"].forEach(function(g){g in t&&(s[g]=t[g])}),e.get(c,s,function(g,S){var L;g?L=[{error:g}]:L=i(S),w(r,c,L),C()})})}C()}var F;try{localStorage.setItem("_pouch_check_localstorage",1),F=!!localStorage.getItem("_pouch_check_localstorage")}catch{F=!1}function K(){return F}const Je=typeof queueMicrotask=="function"?queueMicrotask:function(t){Promise.resolve().then(t)};class vt extends k{constructor(){super(),this._listeners={},K()&&addEventListener("storage",t=>{this.emit(t.key)})}addListener(t,o,u,a){if(this._listeners[o])return;var l=!1,h=this;function p(){if(!h._listeners[o])return;if(l){l="waiting";return}l=!0;var m=ie(a,["style","include_docs","attachments","conflicts","filter","doc_ids","view","since","query_params","binary","return_docs"]);function A(){l=!1}u.changes(m).on("change",function(w){w.seq>a.since&&!a.cancelled&&(a.since=w.seq,a.onChange(w))}).on("complete",function(){l==="waiting"&&Je(p),l=!1}).on("error",A)}this._listeners[o]=p,this.on(t,p)}removeListener(t,o){o in this._listeners&&(super.removeListener(t,this._listeners[o]),delete this._listeners[o])}notifyLocalWindows(t){K()&&(localStorage[t]=localStorage[t]==="a"?"b":"a")}notify(t){this.emit(t),this.notifyLocalWindows(t)}}function $e(e){if(typeof console<"u"&&typeof console[e]=="function"){var t=Array.prototype.slice.call(arguments,1);console[e].apply(console,t)}}function He(e,t,o){try{return!e(t,o)}catch(a){var u="Filter function threw: "+a.toString();return x(fe,u)}}function yt(e){var t={},o=e.filter&&typeof e.filter=="function";return t.query=e.query_params,function(a){a.doc||(a.doc={});var l=o&&He(e.filter,a.doc,t);if(typeof l=="object")return l;if(l)return!1;if(!e.include_docs)delete a.doc;else if(!e.attachments)for(var h in a.doc._attachments)Object.prototype.hasOwnProperty.call(a.doc._attachments,h)&&(a.doc._attachments[h].stub=!0);return!0}}function gt(e){var t;if(e?typeof e!="string"?t=x(oe):/^_/.test(e)&&!/^_(design|local)/.test(e)&&(t=x(ae)):t=x(se),t)throw t}function mt(e){return typeof e._remote=="boolean"?e._remote:typeof e.type=="function"?($e("warn","db.type() is deprecated and will be removed in a future version of PouchDB"),e.type()==="http"):!1}function _t(e,t){return"listenerCount"in e?e.listenerCount(t):k.listenerCount(e,t)}function Qe(e){if(!e)return null;var t=e.split("/");return t.length===2?t:t.length===1?[e,e]:null}function wt(e){var t=Qe(e);return t?t.join("/"):null}function bt(e,t){var o=[],u=[];for(var a in t)Object.prototype.hasOwnProperty.call(t,a)&&(o.push(a),u.push(t[a]));return o.push(e),Function.apply(null,o).apply(null,u)}function Xe(e,t,o){return e.get(t).catch(function(u){if(u.status!==404)throw u;return{}}).then(function(u){var a=u._rev,l=o(u);return l?(l._id=t,l._rev=a,Ye(e,l,o)):{updated:!1,rev:a}})}function Ye(e,t,o){return e.put(t).then(function(u){return{updated:!0,rev:u.rev}},function(u){if(u.status!==409)throw u;return Xe(e,t._id,o)})}function At(e,t){if(!t)return ee().replace(/-/g,"").toLowerCase();var o=Object.assign({},e);return delete o._rev_tree,Ue(JSON.stringify(o))}var Bt=ee;export{Ae as A,fe as B,nt as C,it as D,k as E,Oe as F,lt as G,vt as H,at as I,ze as J,st as K,ct as L,et as M,ot as N,Ce as O,yt as P,rt as Q,tt as R,ut as S,Ue as T,ue as U,dt as a,U as b,x as c,$e as d,gt as e,pt as f,ft as g,ie as h,mt as i,Je as j,oe as k,_t as l,ke as m,wt as n,Ve as o,Qe as p,K as q,At as r,bt as s,Be as t,Xe as u,ee as v,Bt as w,Se as x,te as y,ht as z};
1
+ import{g as G}from"./index.js";class _ extends Error{constructor(o,u,l){super(),this.status=o,this.name=u,this.message=l,this.error=!0}toString(){return JSON.stringify({status:this.status,name:this.name,message:this.message,reason:this.reason})}}new _(401,"unauthorized","Name or password is incorrect.");var Ve=new _(400,"bad_request","Missing JSON list of 'docs'"),ze=new _(404,"not_found","missing"),Ke=new _(409,"conflict","Document update conflict"),Y=new _(400,"bad_request","_id field must contain a string"),Z=new _(412,"missing_id","_id is required for puts"),k=new _(400,"bad_request","Only reserved document ids may start with underscore.");new _(412,"precondition_failed","Database not open");var ee=new _(500,"unknown_error","Database encountered an unknown error"),Ge=new _(500,"badarg","Some query argument is invalid");new _(400,"invalid_request","Request was invalid");var We=new _(400,"query_parse_error","Some query parameter is invalid"),Je=new _(500,"doc_validation","Bad special document member"),te=new _(400,"bad_request","Something wrong with the request"),He=new _(400,"bad_request","Document must be a JSON object");new _(404,"not_found","Database not found");var Qe=new _(500,"indexed_db_went_bad","unknown");new _(500,"web_sql_went_bad","unknown");new _(500,"levelDB_went_went_bad","unknown");new _(403,"forbidden","Forbidden by design doc validate_doc_update function");var $e=new _(400,"bad_request","Invalid rev format");new _(412,"file_exists","The database could not be created, the file already exists.");var Xe=new _(412,"missing_stub","A pre-existing attachment stub wasn't found");new _(413,"invalid_url","Provided URL is invalid");function N(i,o){function u(l){for(var f=Object.getOwnPropertyNames(i),c=0,g=f.length;c<g;c++)typeof i[f[c]]!="function"&&(this[f[c]]=i[f[c]]);this.stack===void 0&&(this.stack=new Error().stack),l!==void 0&&(this.reason=l)}return u.prototype=_.prototype,new u(o)}function Ye(i){if(typeof i!="object"){var o=i;i=ee,i.data=o}return"error"in i&&i.error==="conflict"&&(i.name="conflict",i.status=409),"name"in i||(i.name=i.error||"unknown"),"status"in i||(i.status=500),"message"in i||(i.message=i.message||i.reason),"stack"in i||(i.stack=new Error().stack),i}var I={exports:{}},j;function ne(){if(j)return I.exports;j=1;var i=typeof Reflect=="object"?Reflect:null,o=i&&typeof i.apply=="function"?i.apply:function(t,n,h){return Function.prototype.apply.call(t,n,h)},u;i&&typeof i.ownKeys=="function"?u=i.ownKeys:Object.getOwnPropertySymbols?u=function(t){return Object.getOwnPropertyNames(t).concat(Object.getOwnPropertySymbols(t))}:u=function(t){return Object.getOwnPropertyNames(t)};function l(e){console&&console.warn&&console.warn(e)}var f=Number.isNaN||function(t){return t!==t};function c(){c.init.call(this)}I.exports=c,I.exports.once=a,c.EventEmitter=c,c.prototype._events=void 0,c.prototype._eventsCount=0,c.prototype._maxListeners=void 0;var g=10;function m(e){if(typeof e!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof e)}Object.defineProperty(c,"defaultMaxListeners",{enumerable:!0,get:function(){return g},set:function(e){if(typeof e!="number"||e<0||f(e))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+e+".");g=e}}),c.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},c.prototype.setMaxListeners=function(t){if(typeof t!="number"||t<0||f(t))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+t+".");return this._maxListeners=t,this};function w(e){return e._maxListeners===void 0?c.defaultMaxListeners:e._maxListeners}c.prototype.getMaxListeners=function(){return w(this)},c.prototype.emit=function(t){for(var n=[],h=1;h<arguments.length;h++)n.push(arguments[h]);var d=t==="error",v=this._events;if(v!==void 0)d=d&&v.error===void 0;else if(!d)return!1;if(d){var y;if(n.length>0&&(y=n[0]),y instanceof Error)throw y;var O=new Error("Unhandled error."+(y?" ("+y.message+")":""));throw O.context=y,O}var x=v[t];if(x===void 0)return!1;if(typeof x=="function")o(x,this,n);else for(var P=x.length,X=R(x,P),h=0;h<P;++h)o(X[h],this,n);return!0};function S(e,t,n,h){var d,v,y;if(m(n),v=e._events,v===void 0?(v=e._events=Object.create(null),e._eventsCount=0):(v.newListener!==void 0&&(e.emit("newListener",t,n.listener?n.listener:n),v=e._events),y=v[t]),y===void 0)y=v[t]=n,++e._eventsCount;else if(typeof y=="function"?y=v[t]=h?[n,y]:[y,n]:h?y.unshift(n):y.push(n),d=w(e),d>0&&y.length>d&&!y.warned){y.warned=!0;var O=new Error("Possible EventEmitter memory leak detected. "+y.length+" "+String(t)+" listeners added. Use emitter.setMaxListeners() to increase limit");O.name="MaxListenersExceededWarning",O.emitter=e,O.type=t,O.count=y.length,l(O)}return e}c.prototype.addListener=function(t,n){return S(this,t,n,!1)},c.prototype.on=c.prototype.addListener,c.prototype.prependListener=function(t,n){return S(this,t,n,!0)};function A(){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 E(e,t,n){var h={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},d=A.bind(h);return d.listener=n,h.wrapFn=d,d}c.prototype.once=function(t,n){return m(n),this.on(t,E(this,t,n)),this},c.prototype.prependOnceListener=function(t,n){return m(n),this.prependListener(t,E(this,t,n)),this},c.prototype.removeListener=function(t,n){var h,d,v,y,O;if(m(n),d=this._events,d===void 0)return this;if(h=d[t],h===void 0)return this;if(h===n||h.listener===n)--this._eventsCount===0?this._events=Object.create(null):(delete d[t],d.removeListener&&this.emit("removeListener",t,h.listener||n));else if(typeof h!="function"){for(v=-1,y=h.length-1;y>=0;y--)if(h[y]===n||h[y].listener===n){O=h[y].listener,v=y;break}if(v<0)return this;v===0?h.shift():b(h,v),h.length===1&&(d[t]=h[0]),d.removeListener!==void 0&&this.emit("removeListener",t,O||n)}return this},c.prototype.off=c.prototype.removeListener,c.prototype.removeAllListeners=function(t){var n,h,d;if(h=this._events,h===void 0)return this;if(h.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):h[t]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete h[t]),this;if(arguments.length===0){var v=Object.keys(h),y;for(d=0;d<v.length;++d)y=v[d],y!=="removeListener"&&this.removeAllListeners(y);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(n=h[t],typeof n=="function")this.removeListener(t,n);else if(n!==void 0)for(d=n.length-1;d>=0;d--)this.removeListener(t,n[d]);return this};function L(e,t,n){var h=e._events;if(h===void 0)return[];var d=h[t];return d===void 0?[]:typeof d=="function"?n?[d.listener||d]:[d]:n?p(d):R(d,d.length)}c.prototype.listeners=function(t){return L(this,t,!0)},c.prototype.rawListeners=function(t){return L(this,t,!1)},c.listenerCount=function(e,t){return typeof e.listenerCount=="function"?e.listenerCount(t):C.call(e,t)},c.prototype.listenerCount=C;function C(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}c.prototype.eventNames=function(){return this._eventsCount>0?u(this._events):[]};function R(e,t){for(var n=new Array(t),h=0;h<t;++h)n[h]=e[h];return n}function b(e,t){for(;t+1<e.length;t++)e[t]=e[t+1];e.pop()}function p(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}function a(e,t){return new Promise(function(n,h){function d(y){e.removeListener(t,v),h(y)}function v(){typeof e.removeListener=="function"&&e.removeListener("error",d),n([].slice.call(arguments))}r(e,t,v,{once:!0}),t!=="error"&&s(e,d,{once:!0})})}function s(e,t,n){typeof e.on=="function"&&r(e,"error",t,n)}function r(e,t,n,h){if(typeof e.on=="function")h.once?e.once(t,n):e.on(t,n);else if(typeof e.addEventListener=="function")e.addEventListener(t,function d(v){h.once&&e.removeEventListener(t,d),n(v)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof e)}return I.exports}var re=ne();const W=G(re);var M,ie=new Uint8Array(16);function oe(){if(!M&&(M=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||typeof msCrypto<"u"&&typeof msCrypto.getRandomValues=="function"&&msCrypto.getRandomValues.bind(msCrypto),!M))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return M(ie)}const se=/^(?:[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 ae(i){return typeof i=="string"&&se.test(i)}var B=[];for(var D=0;D<256;++D)B.push((D+256).toString(16).substr(1));function ue(i){var o=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,u=(B[i[o+0]]+B[i[o+1]]+B[i[o+2]]+B[i[o+3]]+"-"+B[i[o+4]]+B[i[o+5]]+"-"+B[i[o+6]]+B[i[o+7]]+"-"+B[i[o+8]]+B[i[o+9]]+"-"+B[i[o+10]]+B[i[o+11]]+B[i[o+12]]+B[i[o+13]]+B[i[o+14]]+B[i[o+15]]).toLowerCase();if(!ae(u))throw TypeError("Stringified UUID is invalid");return u}function J(i,o,u){i=i||{};var l=i.random||(i.rng||oe)();return l[6]=l[6]&15|64,l[8]=l[8]&63|128,ue(l)}var fe=function(i){return atob(i)},H=function(i){return btoa(i)};function ce(i,o){i=i||[],o=o||{};try{return new Blob(i,o)}catch(c){if(c.name!=="TypeError")throw c;for(var u=typeof BlobBuilder<"u"?BlobBuilder:typeof MSBlobBuilder<"u"?MSBlobBuilder:typeof MozBlobBuilder<"u"?MozBlobBuilder:WebKitBlobBuilder,l=new u,f=0;f<i.length;f+=1)l.append(i[f]);return l.getBlob(o.type)}}function le(i){for(var o=i.length,u=new ArrayBuffer(o),l=new Uint8Array(u),f=0;f<o;f++)l[f]=i.charCodeAt(f);return u}function he(i,o){return ce([le(i)],{type:o})}function Ze(i,o){return he(fe(i),o)}function de(i){for(var o="",u=new Uint8Array(i),l=u.byteLength,f=0;f<l;f++)o+=String.fromCharCode(u[f]);return o}function pe(i,o){var u=new FileReader,l=typeof u.readAsBinaryString=="function";u.onloadend=function(f){var c=f.target.result||"";if(l)return o(c);o(de(c))},l?u.readAsBinaryString(i):u.readAsArrayBuffer(i)}function ve(i,o){pe(i,function(u){o(u)})}function ke(i,o){ve(i,function(u){o(H(u))})}function ye(i,o){var u=new FileReader;u.onloadend=function(l){var f=l.target.result||new ArrayBuffer(0);o(f)},u.readAsArrayBuffer(i)}var T={exports:{}},V;function ge(){return V||(V=1,function(i,o){(function(u){i.exports=u()})(function(u){var l=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];function f(a,s){var r=a[0],e=a[1],t=a[2],n=a[3];r+=(e&t|~e&n)+s[0]-680876936|0,r=(r<<7|r>>>25)+e|0,n+=(r&e|~r&t)+s[1]-389564586|0,n=(n<<12|n>>>20)+r|0,t+=(n&r|~n&e)+s[2]+606105819|0,t=(t<<17|t>>>15)+n|0,e+=(t&n|~t&r)+s[3]-1044525330|0,e=(e<<22|e>>>10)+t|0,r+=(e&t|~e&n)+s[4]-176418897|0,r=(r<<7|r>>>25)+e|0,n+=(r&e|~r&t)+s[5]+1200080426|0,n=(n<<12|n>>>20)+r|0,t+=(n&r|~n&e)+s[6]-1473231341|0,t=(t<<17|t>>>15)+n|0,e+=(t&n|~t&r)+s[7]-45705983|0,e=(e<<22|e>>>10)+t|0,r+=(e&t|~e&n)+s[8]+1770035416|0,r=(r<<7|r>>>25)+e|0,n+=(r&e|~r&t)+s[9]-1958414417|0,n=(n<<12|n>>>20)+r|0,t+=(n&r|~n&e)+s[10]-42063|0,t=(t<<17|t>>>15)+n|0,e+=(t&n|~t&r)+s[11]-1990404162|0,e=(e<<22|e>>>10)+t|0,r+=(e&t|~e&n)+s[12]+1804603682|0,r=(r<<7|r>>>25)+e|0,n+=(r&e|~r&t)+s[13]-40341101|0,n=(n<<12|n>>>20)+r|0,t+=(n&r|~n&e)+s[14]-1502002290|0,t=(t<<17|t>>>15)+n|0,e+=(t&n|~t&r)+s[15]+1236535329|0,e=(e<<22|e>>>10)+t|0,r+=(e&n|t&~n)+s[1]-165796510|0,r=(r<<5|r>>>27)+e|0,n+=(r&t|e&~t)+s[6]-1069501632|0,n=(n<<9|n>>>23)+r|0,t+=(n&e|r&~e)+s[11]+643717713|0,t=(t<<14|t>>>18)+n|0,e+=(t&r|n&~r)+s[0]-373897302|0,e=(e<<20|e>>>12)+t|0,r+=(e&n|t&~n)+s[5]-701558691|0,r=(r<<5|r>>>27)+e|0,n+=(r&t|e&~t)+s[10]+38016083|0,n=(n<<9|n>>>23)+r|0,t+=(n&e|r&~e)+s[15]-660478335|0,t=(t<<14|t>>>18)+n|0,e+=(t&r|n&~r)+s[4]-405537848|0,e=(e<<20|e>>>12)+t|0,r+=(e&n|t&~n)+s[9]+568446438|0,r=(r<<5|r>>>27)+e|0,n+=(r&t|e&~t)+s[14]-1019803690|0,n=(n<<9|n>>>23)+r|0,t+=(n&e|r&~e)+s[3]-187363961|0,t=(t<<14|t>>>18)+n|0,e+=(t&r|n&~r)+s[8]+1163531501|0,e=(e<<20|e>>>12)+t|0,r+=(e&n|t&~n)+s[13]-1444681467|0,r=(r<<5|r>>>27)+e|0,n+=(r&t|e&~t)+s[2]-51403784|0,n=(n<<9|n>>>23)+r|0,t+=(n&e|r&~e)+s[7]+1735328473|0,t=(t<<14|t>>>18)+n|0,e+=(t&r|n&~r)+s[12]-1926607734|0,e=(e<<20|e>>>12)+t|0,r+=(e^t^n)+s[5]-378558|0,r=(r<<4|r>>>28)+e|0,n+=(r^e^t)+s[8]-2022574463|0,n=(n<<11|n>>>21)+r|0,t+=(n^r^e)+s[11]+1839030562|0,t=(t<<16|t>>>16)+n|0,e+=(t^n^r)+s[14]-35309556|0,e=(e<<23|e>>>9)+t|0,r+=(e^t^n)+s[1]-1530992060|0,r=(r<<4|r>>>28)+e|0,n+=(r^e^t)+s[4]+1272893353|0,n=(n<<11|n>>>21)+r|0,t+=(n^r^e)+s[7]-155497632|0,t=(t<<16|t>>>16)+n|0,e+=(t^n^r)+s[10]-1094730640|0,e=(e<<23|e>>>9)+t|0,r+=(e^t^n)+s[13]+681279174|0,r=(r<<4|r>>>28)+e|0,n+=(r^e^t)+s[0]-358537222|0,n=(n<<11|n>>>21)+r|0,t+=(n^r^e)+s[3]-722521979|0,t=(t<<16|t>>>16)+n|0,e+=(t^n^r)+s[6]+76029189|0,e=(e<<23|e>>>9)+t|0,r+=(e^t^n)+s[9]-640364487|0,r=(r<<4|r>>>28)+e|0,n+=(r^e^t)+s[12]-421815835|0,n=(n<<11|n>>>21)+r|0,t+=(n^r^e)+s[15]+530742520|0,t=(t<<16|t>>>16)+n|0,e+=(t^n^r)+s[2]-995338651|0,e=(e<<23|e>>>9)+t|0,r+=(t^(e|~n))+s[0]-198630844|0,r=(r<<6|r>>>26)+e|0,n+=(e^(r|~t))+s[7]+1126891415|0,n=(n<<10|n>>>22)+r|0,t+=(r^(n|~e))+s[14]-1416354905|0,t=(t<<15|t>>>17)+n|0,e+=(n^(t|~r))+s[5]-57434055|0,e=(e<<21|e>>>11)+t|0,r+=(t^(e|~n))+s[12]+1700485571|0,r=(r<<6|r>>>26)+e|0,n+=(e^(r|~t))+s[3]-1894986606|0,n=(n<<10|n>>>22)+r|0,t+=(r^(n|~e))+s[10]-1051523|0,t=(t<<15|t>>>17)+n|0,e+=(n^(t|~r))+s[1]-2054922799|0,e=(e<<21|e>>>11)+t|0,r+=(t^(e|~n))+s[8]+1873313359|0,r=(r<<6|r>>>26)+e|0,n+=(e^(r|~t))+s[15]-30611744|0,n=(n<<10|n>>>22)+r|0,t+=(r^(n|~e))+s[6]-1560198380|0,t=(t<<15|t>>>17)+n|0,e+=(n^(t|~r))+s[13]+1309151649|0,e=(e<<21|e>>>11)+t|0,r+=(t^(e|~n))+s[4]-145523070|0,r=(r<<6|r>>>26)+e|0,n+=(e^(r|~t))+s[11]-1120210379|0,n=(n<<10|n>>>22)+r|0,t+=(r^(n|~e))+s[2]+718787259|0,t=(t<<15|t>>>17)+n|0,e+=(n^(t|~r))+s[9]-343485551|0,e=(e<<21|e>>>11)+t|0,a[0]=r+a[0]|0,a[1]=e+a[1]|0,a[2]=t+a[2]|0,a[3]=n+a[3]|0}function c(a){var s=[],r;for(r=0;r<64;r+=4)s[r>>2]=a.charCodeAt(r)+(a.charCodeAt(r+1)<<8)+(a.charCodeAt(r+2)<<16)+(a.charCodeAt(r+3)<<24);return s}function g(a){var s=[],r;for(r=0;r<64;r+=4)s[r>>2]=a[r]+(a[r+1]<<8)+(a[r+2]<<16)+(a[r+3]<<24);return s}function m(a){var s=a.length,r=[1732584193,-271733879,-1732584194,271733878],e,t,n,h,d,v;for(e=64;e<=s;e+=64)f(r,c(a.substring(e-64,e)));for(a=a.substring(e-64),t=a.length,n=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],e=0;e<t;e+=1)n[e>>2]|=a.charCodeAt(e)<<(e%4<<3);if(n[e>>2]|=128<<(e%4<<3),e>55)for(f(r,n),e=0;e<16;e+=1)n[e]=0;return h=s*8,h=h.toString(16).match(/(.*?)(.{0,8})$/),d=parseInt(h[2],16),v=parseInt(h[1],16)||0,n[14]=d,n[15]=v,f(r,n),r}function w(a){var s=a.length,r=[1732584193,-271733879,-1732584194,271733878],e,t,n,h,d,v;for(e=64;e<=s;e+=64)f(r,g(a.subarray(e-64,e)));for(a=e-64<s?a.subarray(e-64):new Uint8Array(0),t=a.length,n=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],e=0;e<t;e+=1)n[e>>2]|=a[e]<<(e%4<<3);if(n[e>>2]|=128<<(e%4<<3),e>55)for(f(r,n),e=0;e<16;e+=1)n[e]=0;return h=s*8,h=h.toString(16).match(/(.*?)(.{0,8})$/),d=parseInt(h[2],16),v=parseInt(h[1],16)||0,n[14]=d,n[15]=v,f(r,n),r}function S(a){var s="",r;for(r=0;r<4;r+=1)s+=l[a>>r*8+4&15]+l[a>>r*8&15];return s}function A(a){var s;for(s=0;s<a.length;s+=1)a[s]=S(a[s]);return a.join("")}A(m("hello")),typeof ArrayBuffer<"u"&&!ArrayBuffer.prototype.slice&&function(){function a(s,r){return s=s|0||0,s<0?Math.max(s+r,0):Math.min(s,r)}ArrayBuffer.prototype.slice=function(s,r){var e=this.byteLength,t=a(s,e),n=e,h,d,v,y;return r!==u&&(n=a(r,e)),t>n?new ArrayBuffer(0):(h=n-t,d=new ArrayBuffer(h),v=new Uint8Array(d),y=new Uint8Array(this,t,h),v.set(y),d)}}();function E(a){return/[\u0080-\uFFFF]/.test(a)&&(a=unescape(encodeURIComponent(a))),a}function L(a,s){var r=a.length,e=new ArrayBuffer(r),t=new Uint8Array(e),n;for(n=0;n<r;n+=1)t[n]=a.charCodeAt(n);return s?t:e}function C(a){return String.fromCharCode.apply(null,new Uint8Array(a))}function R(a,s,r){var e=new Uint8Array(a.byteLength+s.byteLength);return e.set(new Uint8Array(a)),e.set(new Uint8Array(s),a.byteLength),e}function b(a){var s=[],r=a.length,e;for(e=0;e<r-1;e+=2)s.push(parseInt(a.substr(e,2),16));return String.fromCharCode.apply(String,s)}function p(){this.reset()}return p.prototype.append=function(a){return this.appendBinary(E(a)),this},p.prototype.appendBinary=function(a){this._buff+=a,this._length+=a.length;var s=this._buff.length,r;for(r=64;r<=s;r+=64)f(this._hash,c(this._buff.substring(r-64,r)));return this._buff=this._buff.substring(r-64),this},p.prototype.end=function(a){var s=this._buff,r=s.length,e,t=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],n;for(e=0;e<r;e+=1)t[e>>2]|=s.charCodeAt(e)<<(e%4<<3);return this._finish(t,r),n=A(this._hash),a&&(n=b(n)),this.reset(),n},p.prototype.reset=function(){return this._buff="",this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},p.prototype.getState=function(){return{buff:this._buff,length:this._length,hash:this._hash.slice()}},p.prototype.setState=function(a){return this._buff=a.buff,this._length=a.length,this._hash=a.hash,this},p.prototype.destroy=function(){delete this._hash,delete this._buff,delete this._length},p.prototype._finish=function(a,s){var r=s,e,t,n;if(a[r>>2]|=128<<(r%4<<3),r>55)for(f(this._hash,a),r=0;r<16;r+=1)a[r]=0;e=this._length*8,e=e.toString(16).match(/(.*?)(.{0,8})$/),t=parseInt(e[2],16),n=parseInt(e[1],16)||0,a[14]=t,a[15]=n,f(this._hash,a)},p.hash=function(a,s){return p.hashBinary(E(a),s)},p.hashBinary=function(a,s){var r=m(a),e=A(r);return s?b(e):e},p.ArrayBuffer=function(){this.reset()},p.ArrayBuffer.prototype.append=function(a){var s=R(this._buff.buffer,a),r=s.length,e;for(this._length+=a.byteLength,e=64;e<=r;e+=64)f(this._hash,g(s.subarray(e-64,e)));return this._buff=e-64<r?new Uint8Array(s.buffer.slice(e-64)):new Uint8Array(0),this},p.ArrayBuffer.prototype.end=function(a){var s=this._buff,r=s.length,e=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],t,n;for(t=0;t<r;t+=1)e[t>>2]|=s[t]<<(t%4<<3);return this._finish(e,r),n=A(this._hash),a&&(n=b(n)),this.reset(),n},p.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array(0),this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},p.ArrayBuffer.prototype.getState=function(){var a=p.prototype.getState.call(this);return a.buff=C(a.buff),a},p.ArrayBuffer.prototype.setState=function(a){return a.buff=L(a.buff,!0),p.prototype.setState.call(this,a)},p.ArrayBuffer.prototype.destroy=p.prototype.destroy,p.ArrayBuffer.prototype._finish=p.prototype._finish,p.ArrayBuffer.hash=function(a,s){var r=w(new Uint8Array(a)),e=A(r);return s?b(e):e},p})}(T)),T.exports}var me=ge();const U=G(me);var _e=self.setImmediate||self.setTimeout,be=32768;function we(i){return H(i)}function Ae(i,o,u,l,f){(u>0||l<o.size)&&(o=o.slice(u,l)),ye(o,function(c){i.append(c),f()})}function Be(i,o,u,l,f){(u>0||l<o.length)&&(o=o.substring(u,l)),i.appendBinary(o),f()}function et(i,o){var u=typeof i=="string",l=u?i.length:i.size,f=Math.min(be,l),c=Math.ceil(l/f),g=0,m=u?new U:new U.ArrayBuffer,w=u?Be:Ae;function S(){_e(E)}function A(){var L=m.end(!0),C=we(L);o(C),m.destroy()}function E(){var L=g*f,C=L+f;g++,g<c?w(m,i,L,C,S):w(m,i,L,C,A)}E()}function Le(i){return U.hash(i)}function Se(i){return typeof ArrayBuffer<"u"&&i instanceof ArrayBuffer||typeof Blob<"u"&&i instanceof Blob}function Ee(i){return i instanceof ArrayBuffer?i.slice(0):i.slice(0,i.size,i.type)}var Q=Function.prototype.toString,Ce=Q.call(Object);function Oe(i){var o=Object.getPrototypeOf(i);if(o===null)return!0;var u=o.constructor;return typeof u=="function"&&u instanceof u&&Q.call(u)==Ce}function F(i){var o,u,l;if(!i||typeof i!="object")return i;if(Array.isArray(i)){for(o=[],u=0,l=i.length;u<l;u++)o[u]=F(i[u]);return o}if(i instanceof Date&&isFinite(i))return i.toISOString();if(Se(i))return Ee(i);if(!Oe(i))return i;o={};for(u in i)if(Object.prototype.hasOwnProperty.call(i,u)){var f=F(i[u]);typeof f<"u"&&(o[u]=f)}return o}function Re(i){var o=!1;return function(...u){if(o)throw new Error("once called more than once");o=!0,i.apply(this,u)}}function xe(i){return function(...o){o=F(o);var u=this,l=typeof o[o.length-1]=="function"?o.pop():!1,f=new Promise(function(c,g){var m;try{var w=Re(function(S,A){S?g(S):c(A)});o.push(w),m=i.apply(u,o),m&&typeof m.then=="function"&&c(m)}catch(S){g(S)}});return l&&f.then(function(c){l(null,c)},l),f}}function Ie(i,o,u){if(i.constructor.listeners("debug").length){for(var l=["api",i.name,o],f=0;f<u.length-1;f++)l.push(u[f]);i.constructor.emit("debug",l);var c=u[u.length-1];u[u.length-1]=function(g,m){var w=["api",i.name,o];w=w.concat(g?["error",g]:["success",m]),i.constructor.emit("debug",w),c(g,m)}}}function tt(i,o){return xe(function(...u){if(this._closed)return Promise.reject(new Error("database is closed"));if(this._destroyed)return Promise.reject(new Error("database is destroyed"));var l=this;return Ie(l,i,u),this.taskqueue.isReady?o.apply(this,u):new Promise(function(f,c){l.taskqueue.addTask(function(g){g?c(g):f(l[i].apply(l,u))})})})}function $(i,o){for(var u={},l=0,f=o.length;l<f;l++){var c=o[l];c in i&&(u[c]=i[c])}return u}var Me=6;function z(i){return i}function Ne(i){return[{ok:i}]}function nt(i,o,u){var l=o.docs,f=new Map;l.forEach(function(b){f.has(b.id)?f.get(b.id).push(b):f.set(b.id,[b])});var c=f.size,g=0,m=new Array(c);function w(){var b=[];m.forEach(function(p){p.docs.forEach(function(a){b.push({id:p.id,docs:[a]})})}),u(null,{results:b})}function S(){++g===c&&w()}function A(b,p,a){m[b]={id:p,docs:a},S()}var E=[];f.forEach(function(b,p){E.push(p)});var L=0;function C(){if(!(L>=E.length)){var b=Math.min(L+Me,E.length),p=E.slice(L,b);R(p,L),L+=p.length}}function R(b,p){b.forEach(function(a,s){var r=p+s,e=f.get(a),t=$(e[0],["atts_since","attachments"]);t.open_revs=e.map(function(h){return h.rev}),t.open_revs=t.open_revs.filter(z);var n=z;t.open_revs.length===0&&(delete t.open_revs,n=Ne),["revs","attachments","binary","ajax","latest"].forEach(function(h){h in o&&(t[h]=o[h])}),i.get(a,t,function(h,d){var v;h?v=[{error:h}]:v=n(d),A(r,a,v),C()})})}C()}var q;try{localStorage.setItem("_pouch_check_localstorage",1),q=!!localStorage.getItem("_pouch_check_localstorage")}catch{q=!1}function K(){return q}const De=typeof queueMicrotask=="function"?queueMicrotask:function(o){Promise.resolve().then(o)};class rt extends W{constructor(){super(),this._listeners={},K()&&addEventListener("storage",o=>{this.emit(o.key)})}addListener(o,u,l,f){if(this._listeners[u])return;var c=!1,g=this;function m(){if(!g._listeners[u])return;if(c){c="waiting";return}c=!0;var w=$(f,["style","include_docs","attachments","conflicts","filter","doc_ids","view","since","query_params","binary","return_docs"]);function S(){c=!1}l.changes(w).on("change",function(A){A.seq>f.since&&!f.cancelled&&(f.since=A.seq,f.onChange(A))}).on("complete",function(){c==="waiting"&&De(m),c=!1}).on("error",S)}this._listeners[u]=m,this.on(o,m)}removeListener(o,u){u in this._listeners&&(super.removeListener(o,this._listeners[u]),delete this._listeners[u])}notifyLocalWindows(o){K()&&(localStorage[o]=localStorage[o]==="a"?"b":"a")}notify(o){this.emit(o),this.notifyLocalWindows(o)}}function Te(i){if(typeof console<"u"&&typeof console[i]=="function"){var o=Array.prototype.slice.call(arguments,1);console[i].apply(console,o)}}function Ue(i,o,u){try{return!i(o,u)}catch(f){var l="Filter function threw: "+f.toString();return N(te,l)}}function it(i){var o={},u=i.filter&&typeof i.filter=="function";return o.query=i.query_params,function(f){f.doc||(f.doc={});var c=u&&Ue(i.filter,f.doc,o);if(typeof c=="object")return c;if(c)return!1;if(!i.include_docs)delete f.doc;else if(!i.attachments)for(var g in f.doc._attachments)Object.prototype.hasOwnProperty.call(f.doc._attachments,g)&&(f.doc._attachments[g].stub=!0);return!0}}function ot(i){var o;if(i?typeof i!="string"?o=N(Y):/^_/.test(i)&&!/^_(design|local)/.test(i)&&(o=N(k)):o=N(Z),o)throw o}function st(i){return typeof i._remote=="boolean"?i._remote:typeof i.type=="function"?(Te("warn","db.type() is deprecated and will be removed in a future version of PouchDB"),i.type()==="http"):!1}function at(i,o){return"listenerCount"in i?i.listenerCount(o):W.listenerCount(i,o)}function Fe(i){if(!i)return null;var o=i.split("/");return o.length===2?o:o.length===1?[i,i]:null}function ut(i){var o=Fe(i);return o?o.join("/"):null}function ft(i,o){var u=[],l=[];for(var f in o)Object.prototype.hasOwnProperty.call(o,f)&&(u.push(f),l.push(o[f]));return u.push(i),Function.apply(null,u).apply(null,l)}function qe(i,o,u){return i.get(o).catch(function(l){if(l.status!==404)throw l;return{}}).then(function(l){var f=l._rev,c=u(l);return c?(c._id=o,c._rev=f,Pe(i,c,u)):{updated:!1,rev:f}})}function Pe(i,o,u){return i.put(o).then(function(l){return{updated:!0,rev:l.rev}},function(l){if(l.status!==409)throw l;return qe(i,o._id,u)})}function ct(i,o){if(!o)return J().replace(/-/g,"").toLowerCase();var u=Object.assign({},i);return delete u._rev_tree,Le(JSON.stringify(u))}var lt=J;export{fe as A,te as B,Ge as C,Je as D,W as E,ve as F,ke as G,xe as H,$e as I,rt as J,Ze as K,pe as L,ze as M,He as N,Qe as O,it as P,We as Q,Ke as R,Xe as S,Le as T,ee as U,tt as a,ot as b,N as c,Te as d,nt as e,Y as f,Ye as g,Ve as h,st as i,F as j,De as k,$ as l,at as m,ut as n,Re as o,Fe as p,K as q,ct as r,ft as s,ce as t,qe as u,J as v,lt as w,he as x,H as y,et as z};