snow-cms 1.3.2 → 1.3.3

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{k as he,i as z,g as pe,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.es4.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 R={name:v,db:E,sourceDB:e,adapter:e.adapter,mapFun:n,reduceFun:i};let j;try{j=await R.db.get("_local/lastSeq")}catch(F){if(F.status!==404)throw F}return R.seq=j?j.seq:0,p&&R.db.once("destroyed",function(){delete p[u]}),R});return p&&(p[u]=g),g}const Me={},Te=new ge,yt=50;function fe(e){return e.indexOf("/")===-1?[e,e]:e.split("/")}function ht(e){return e.length===1&&/^1-/.test(e[0].rev)}function Ee(e,t,n){try{e.emit("error",t)}catch{Oe("error",`The user's map/reduce function threw an uncaught error.
1
+ import{k as he,i as z,g as pe,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.es4.js";import"./milkdown.js";class q extends Error{constructor(t){super(),this.status=400,this.name="query_parse_error",this.message=t,this.error=!0;try{Error.captureStackTrace(this,q)}catch{}}}class we extends Error{constructor(t){super(),this.status=404,this.name="not_found",this.message=t,this.error=!0;try{Error.captureStackTrace(this,we)}catch{}}}class _e extends Error{constructor(t){super(),this.status=500,this.name="invalid_value",this.message=t,this.error=!0;try{Error.captureStackTrace(this,_e)}catch{}}}function Qe(e,t){return t&&e.then(function(n){he(function(){t(null,n)})},function(n){he(function(){t(n)})}),e}function lt(e){return function(...t){var n=t.pop(),i=e.apply(this,t);return typeof n=="function"&&Qe(i,n),i}}function dt(e,t){return e.then(function(n){return t().then(function(){return n})},function(n){return t().then(function(){throw n})})}function le(e,t){return function(){var n=arguments,i=this;return e.add(function(){return t.apply(i,n)})}}function Ie(e){var t=new Set(e),n=new Array(t.size),i=-1;return t.forEach(function(o){n[++i]=o}),n}function de(e){var t=new Array(e.size),n=-1;return e.forEach(function(i,o){t[++n]=o}),t}class ge{constructor(){this.promise=Promise.resolve()}add(t){return this.promise=this.promise.catch(()=>{}).then(()=>t()),this.promise}finish(){return this.promise}}function Se(e){if(!e)return"undefined";switch(typeof e){case"function":return e.toString();case"string":return e.toString();default:return JSON.stringify(e)}}function ft(e,t){return Se(e)+Se(t)+"undefined"}async function je(e,t,n,i,o,l){const u=ft(n,i);let p;if(!o&&(p=e._cachedViews=e._cachedViews||{},p[u]))return p[u];const g=e.info().then(async function(S){const v=S.db_name+"-mrview-"+(o?"temp":Ae(u));function m(F){F.views=F.views||{};let P=t;P.indexOf("/")===-1&&(P=t+"/"+t);const Q=F.views[P]=F.views[P]||{};if(!Q[v])return Q[v]=!0,F}await ke(e,"_local/"+l,m);const E=(await e.registerDependentDatabase(v)).db;E.auto_compaction=!0;const R={name:v,db:E,sourceDB:e,adapter:e.adapter,mapFun:n,reduceFun:i};let j;try{j=await R.db.get("_local/lastSeq")}catch(F){if(F.status!==404)throw F}return R.seq=j?j.seq:0,p&&R.db.once("destroyed",function(){delete p[u]}),R});return p&&(p[u]=g),g}const Me={},Te=new ge,yt=50;function fe(e){return e.indexOf("/")===-1?[e,e]:e.split("/")}function ht(e){return e.length===1&&/^1-/.test(e[0].rev)}function Ee(e,t,n){try{e.emit("error",t)}catch{Oe("error",`The user's map/reduce function threw an uncaught error.
2
2
  You can debug this error by doing:
3
3
  myDatabase.on('error', function (err) { debugger; });
4
4
  Please double-check your map/reduce function.`),Oe("error",t,n)}}function pt(e,t,n,i){function o(r,s,c){try{s(c)}catch(a){Ee(r,a,{fun:s,doc:c})}}function l(r,s,c,a,f){try{return{output:s(c,a,f)}}catch(k){return Ee(r,k,{fun:s,keys:c,values:a,rereduce:f}),{error:k}}}function u(r,s){const c=U(r.key,s.key);return c!==0?c:U(r.value,s.value)}function p(r,s,c){return c=c||0,typeof s=="number"?r.slice(c,s+c):c>0?r.slice(c):r}function g(r){const s=r.value;return s&&typeof s=="object"&&s._id||r.id}function S(r){for(const s of r.rows){const c=s.doc&&s.doc._attachments;if(c)for(const a of Object.keys(c)){const f=c[a];c[a].data=st(f.data,f.content_type)}}}function v(r){return function(s){return r.include_docs&&r.attachments&&r.binary&&S(s),s}}function m(r,s,c,a){let f=s[r];typeof f<"u"&&(a&&(f=encodeURIComponent(JSON.stringify(f))),c.push(r+"="+f))}function T(r){if(typeof r<"u"){const s=Number(r);return!isNaN(s)&&s===parseInt(r,10)?s:r}}function E(r){return r.group_level=T(r.group_level),r.limit=T(r.limit),r.skip=T(r.skip),r}function R(r){if(r){if(typeof r!="number")return new q(`Invalid value for integer: "${r}"`);if(r<0)return new q(`Invalid value for positive integer: "${r}"`)}}function j(r,s){const c=r.descending?"endkey":"startkey",a=r.descending?"startkey":"endkey";if(typeof r[c]<"u"&&typeof r[a]<"u"&&U(r[c],r[a])>0)throw new q("No rows can match your key range, reverse your start_key and end_key or set {descending : true}");if(s.reduce&&r.reduce!==!1){if(r.include_docs)throw new q("{include_docs:true} is invalid for reduce");if(r.keys&&r.keys.length>1&&!r.group&&!r.group_level)throw new q("Multi-key fetches for reduce views must use {group: true}")}for(const f of["group_level","limit","skip"]){const k=R(r[f]);if(k)throw k}}async function F(r,s,c){let a=[],f,k="GET",I;if(m("reduce",c,a),m("include_docs",c,a),m("attachments",c,a),m("limit",c,a),m("descending",c,a),m("group",c,a),m("group_level",c,a),m("skip",c,a),m("stale",c,a),m("conflicts",c,a),m("startkey",c,a,!0),m("start_key",c,a,!0),m("endkey",c,a,!0),m("end_key",c,a,!0),m("inclusive_end",c,a),m("key",c,a,!0),m("update_seq",c,a),a=a.join("&"),a=a===""?"":"?"+a,typeof c.keys<"u"){const b=`keys=${encodeURIComponent(JSON.stringify(c.keys))}`;b.length+a.length+1<=2e3?a+=(a[0]==="?"?"&":"?")+b:(k="POST",typeof s=="string"?f={keys:c.keys}:s.keys=c.keys)}if(typeof s=="string"){const h=fe(s),b=await r.fetch("_design/"+h[0]+"/_view/"+h[1]+a,{headers:new D({"Content-Type":"application/json"}),method:k,body:JSON.stringify(f)});I=b.ok;const _=await b.json();if(!I)throw _.status=b.status,pe(_);for(const w of _.rows)if(w.value&&w.value.error&&w.value.error==="builtin_reduce_error")throw new Error(w.reason);return new Promise(function(w){w(_)}).then(v(c))}f=f||{};for(const h of Object.keys(s))Array.isArray(s[h])?f[h]=s[h]:f[h]=s[h].toString();const d=await r.fetch("_temp_view"+a,{headers:new D({"Content-Type":"application/json"}),method:"POST",body:JSON.stringify(f)});I=d.ok;const y=await d.json();if(!I)throw y.status=d.status,pe(y);return new Promise(function(h){h(y)}).then(v(c))}function P(r,s,c){return new Promise(function(a,f){r._query(s,c,function(k,I){if(k)return f(k);a(I)})})}function Q(r){return new Promise(function(s,c){r._viewCleanup(function(a,f){if(a)return c(a);s(f)})})}function L(r){return function(s){if(s.status===404)return r;throw s}}async function xe(r,s,c){const a="_local/doc_"+r,f={_id:a,keys:[]},k=c.get(r),I=k[0],d=k[1];function y(){return ht(d)?Promise.resolve(f):s.db.get(a).catch(L(f))}function h(A){return A.keys.length?s.db.allDocs({keys:A.keys,include_docs:!0}):Promise.resolve({rows:[]})}function b(A,K){const G=[],W=new Set;for(const $ of K.rows){const x=$.doc;if(x&&(G.push(x),W.add(x._id),x._deleted=!I.has(x._id),!x._deleted)){const O=I.get(x._id);"value"in O&&(x.value=O.value)}}const Z=de(I);for(const $ of Z)if(!W.has($)){const x={_id:$},O=I.get($);"value"in O&&(x.value=O.value),G.push(x)}return A.keys=Ie(Z.concat(A.keys)),G.push(A),G}const _=await y(),w=await h(_);return b(_,w)}function He(r){return r.sourceDB.get("_local/purges").then(function(s){const c=s.purgeSeq;return r.db.get("_local/purgeSeq").then(function(a){return a._rev}).catch(L(void 0)).then(function(a){return r.db.put({_id:"_local/purgeSeq",_rev:a,purgeSeq:c})})}).catch(function(s){if(s.status!==404)throw s})}function Ye(r,s,c){var a="_local/lastSeq";return r.db.get(a).catch(L({_id:a,seq:0})).then(function(f){var k=de(s);return Promise.all(k.map(function(I){return xe(I,r,s)})).then(function(I){var d=I.flat();return f.seq=c,d.push(f),r.db.bulkDocs({docs:d})}).then(()=>He(r))})}function oe(r){const s=typeof r=="string"?r:r.name;let c=Me[s];return c||(c=Me[s]=new ge),c}async function ce(r,s){return le(oe(r),function(){return We(r,s)})()}async function We(r,s){let c,a,f;function k($,x){const O={id:a._id,key:$e($)};typeof x<"u"&&x!==null&&(O.value=$e(x)),c.push(O)}const I=t(r.mapFun,k);let d=r.seq||0;function y(){return r.sourceDB.info().then(function($){f=r.sourceDB.activeTasks.add({name:"view_indexing",total_items:$.update_seq-d})})}function h($,x){return function(){return Ye(r,$,x)}}let b=0;const _={view:r.name,indexed_docs:b};r.sourceDB.emit("indexing",_);const w=new ge;async function A(){const $=await r.sourceDB.changes({return_docs:!0,conflicts:!0,include_docs:!0,style:"all_docs",since:d,limit:s.changes_batch_size}),x=await K();return G($,x)}function K(){return r.db.get("_local/purgeSeq").then(function($){return $.purgeSeq}).catch(L(-1)).then(function($){return r.sourceDB.get("_local/purges").then(function(x){const O=x.purges.filter(function(N,M){return M>$}).map(N=>N.docId),V=O.filter(function(N,M){return O.indexOf(N)===M});return Promise.all(V.map(function(N){return r.sourceDB.get(N).then(function(M){return{docId:N,doc:M}}).catch(L({docId:N}))}))}).catch(L([]))})}function G($,x){const O=$.results;if(!O.length&&!x.length)return;for(const M of x)if(O.findIndex(function(J){return J.id===M.docId})<0){const J={_id:M.docId,doc:{_id:M.docId,_deleted:1},changes:[]};M.doc&&(J.doc=M.doc,J.changes.push({rev:M.doc._rev})),O.push(J)}const V=W(O);w.add(h(V,d)),b=b+O.length;const N={view:r.name,last_seq:$.last_seq,results_count:O.length,indexed_docs:b};if(r.sourceDB.emit("indexing",N),r.sourceDB.activeTasks.update(f,{completed_items:b}),!(O.length<s.changes_batch_size))return A()}function W($){const x=new Map;for(const O of $){if(O.doc._id[0]!=="_"){c=[],a=O.doc,a._deleted||o(r.sourceDB,I,a),c.sort(u);const V=Z(c);x.set(O.doc._id,[V,O.changes])}d=O.seq}return x}function Z($){const x=new Map;let O;for(let V=0,N=$.length;V<N;V++){const M=$[V],ue=[M.key,M.id];V>0&&U(M.key,O)===0&&ue.push(V),x.set(B(ue),M),O=M.key}return x}try{await y(),await A(),await w.finish(),r.seq=d,r.sourceDB.activeTasks.remove(f)}catch($){r.sourceDB.activeTasks.remove(f,$)}}function Ze(r,s,c){c.group_level===0&&delete c.group_level;const a=c.group||c.group_level,f=n(r.reduceFun),k=[],I=isNaN(c.group_level)?Number.POSITIVE_INFINITY:c.group_level;for(const d of s){const y=k[k.length-1];let h=a?d.key:null;if(a&&Array.isArray(h)&&(h=h.slice(0,I)),y&&U(y.groupKey,h)===0){y.keys.push([d.key,d.id]),y.values.push(d.value);continue}k.push({keys:[[d.key,d.id]],values:[d.value],groupKey:h})}s=[];for(const d of k){const y=l(r.sourceDB,f,d.keys,d.values,!1);if(y.error&&y.error instanceof _e)throw y.error;s.push({value:y.error?null:y.output,key:d.groupKey})}return{rows:p(s,c.limit,c.skip)}}function ae(r,s){return le(oe(r),function(){return De(r,s)})()}async function De(r,s){let c;const a=r.reduceFun&&s.reduce!==!1,f=s.skip||0;typeof s.keys<"u"&&!s.keys.length&&(s.limit=0,delete s.keys);async function k(d){d.include_docs=!0;const y=await r.db.allDocs(d);return c=y.total_rows,y.rows.map(function(h){if("value"in h.doc&&typeof h.doc.value=="object"&&h.doc.value!==null){const _=Object.keys(h.doc.value).sort(),w=["id","key","value"];if(!(_<w||_>w))return h.doc.value}const b=ct(h.doc._id);return{key:b[0],id:b[1],value:"value"in h.doc?h.doc.value:null}})}async function I(d){let y;if(a?y=Ze(r,d,s):typeof s.keys>"u"?y={total_rows:c,offset:f,rows:d}:y={total_rows:c,offset:f,rows:p(d,s.limit,s.skip)},s.update_seq&&(y.update_seq=r.seq),s.include_docs){const h=Ie(d.map(g)),b=await r.sourceDB.allDocs({keys:h,include_docs:!0,conflicts:s.conflicts,attachments:s.attachments,binary:s.binary}),_=new Map;for(const w of b.rows)_.set(w.id,w.doc);for(const w of d){const A=g(w),K=_.get(A);K&&(w.doc=K)}}return y}if(typeof s.keys<"u"){const y=s.keys.map(function(_){const w={startkey:B([_]),endkey:B([_,{}])};return s.update_seq&&(w.update_seq=!0),k(w)}),b=(await Promise.all(y)).flat();return I(b)}else{const d={descending:s.descending};s.update_seq&&(d.update_seq=!0);let y,h;if("start_key"in s&&(y=s.start_key),"startkey"in s&&(y=s.startkey),"end_key"in s&&(h=s.end_key),"endkey"in s&&(h=s.endkey),typeof y<"u"&&(d.startkey=s.descending?B([y,{}]):B([y])),typeof h<"u"){let _=s.inclusive_end!==!1;s.descending&&(_=!_),d.endkey=B(_?[h,{}]:[h])}if(typeof s.key<"u"){const _=B([s.key]),w=B([s.key,{}]);d.descending?(d.endkey=_,d.startkey=w):(d.startkey=_,d.endkey=w)}a||(typeof s.limit=="number"&&(d.limit=s.limit),d.skip=f);const b=await k(d);return I(b)}}async function et(r){return(await r.fetch("_view_cleanup",{headers:new D({"Content-Type":"application/json"}),method:"POST"})).json()}async function tt(r){try{const s=await r.get("_local/"+e),c=new Map;for(const y of Object.keys(s.views)){const h=fe(y),b="_design/"+h[0],_=h[1];let w=c.get(b);w||(w=new Set,c.set(b,w)),w.add(_)}const a={keys:de(c),include_docs:!0},f=await r.allDocs(a),k={};for(const y of f.rows){const h=y.key.substring(8);for(const b of c.get(y.key)){let _=h+"/"+b;s.views[_]||(_=b);const w=Object.keys(s.views[_]),A=y.doc&&y.doc.views&&y.doc.views[b];for(const K of w)k[K]=k[K]||A}}const d=Object.keys(k).filter(function(y){return!k[y]}).map(function(y){return le(oe(y),function(){return new r.constructor(y,r.__opts).destroy()})()});return Promise.all(d).then(function(){return{ok:!0}})}catch(s){if(s.status===404)return{ok:!0};throw s}}async function nt(r,s,c){if(typeof r._query=="function")return P(r,s,c);if(z(r))return F(r,s,c);const a={changes_batch_size:r.__opts.view_update_changes_batch_size||yt};if(typeof s!="string")return j(c,s),Te.add(async function(){const f=await je(r,"temp_view/temp_view",s.map,s.reduce,!0,e);return dt(ce(f,a).then(function(){return ae(f,c)}),function(){return f.db.destroy()})}),Te.finish();{const f=s,k=fe(f),I=k[0],d=k[1],y=await r.get("_design/"+I);if(s=y.views&&y.views[d],!s)throw new we(`ddoc ${y._id} has no view named ${d}`);i(y,d),j(c,s);const h=await je(r,f,s.map,s.reduce,!1,e);return c.stale==="ok"||c.stale==="update_after"?(c.stale==="update_after"&&he(function(){ce(h,a)}),ae(h,c)):(await ce(h,a),ae(h,c))}}function rt(r,s,c){const a=this;typeof s=="function"&&(c=s,s={}),s=s?E(s):{},typeof r=="function"&&(r={map:r});const f=Promise.resolve().then(function(){return nt(a,r,s)});return Qe(f,c),f}const it=lt(function(){const r=this;return typeof r._viewCleanup=="function"?Q(r):z(r)?et(r):tt(r)});return{query:rt,viewCleanup:it}}const gt=(...e)=>e.flat(1/0),Ke=(...e)=>{let t=[];for(const n of e)Array.isArray(n)?t=t.concat(Ke(...n)):t.push(n);return t},Re=typeof Array.prototype.flat=="function"?gt:Ke;function ve(e){const t={};for(const n of e)Object.assign(t,n);return t}function mt(e,t){const n={};for(const i of t){const o=ie(i),l=Ce(e,o);typeof l<"u"&&ut(n,o,l)}return n}function Le(e,t){for(let n=0,i=Math.min(e.length,t.length);n<i;n++)if(e[n]!==t[n])return!1;return!0}function kt(e,t){return e.length>t.length?!1:Le(e,t)}function wt(e,t){e=e.slice();for(const n of t){if(!e.length)break;const i=e.indexOf(n);if(i===-1)return!1;e.splice(i,1)}return!0}function _t(e){const t={};for(const n of e)t[n]=!0;return t}function vt(e,t){let n=null,i=-1;for(const o of e){const l=t(o);l>i&&(i=l,n=o)}return n}function Fe(e,t){if(e.length!==t.length)return!1;for(let n=0,i=e.length;n<i;n++)if(e[n]!==t[n])return!1;return!0}function bt(e){return Array.from(new Set(e))}function X(e){return function(...t){const n=t[t.length-1];if(typeof n=="function"){const i=n.bind(null,null),o=n.bind(null);e.apply(this,t.slice(0,-1)).then(i,o)}else return e.apply(this,t)}}function Be(e){e=re(e),e.index||(e.index={});for(const t of["type","name","ddoc"])e.index[t]&&(e[t]=e.index[t],delete e.index[t]);return e.fields&&(e.index.fields=e.fields,delete e.fields),e.type||(e.type="json"),e}function ee(e){return typeof e=="object"&&e!==null}function xt(e,t,n){let i="",o=t,l=!0;if(["$in","$nin","$or","$and","$mod","$nor","$all"].indexOf(e)!==-1&&(Array.isArray(t)||(i="Query operator "+e+" must be an array.")),["$not","$elemMatch","$allMatch"].indexOf(e)!==-1&&(!Array.isArray(t)&&ee(t)||(i="Query operator "+e+" must be an object.")),e==="$mod"&&Array.isArray(t))if(t.length!==2)i="Query operator $mod must be in the format [divisor, remainder], where divisor and remainder are both integers.";else{const u=t[0],p=t[1];u===0&&(i="Query operator $mod's divisor cannot be 0, cannot divide by zero.",l=!1),(typeof u!="number"||parseInt(u,10)!==u)&&(i="Query operator $mod's divisor is not an integer.",o=u),parseInt(p,10)!==p&&(i="Query operator $mod's remainder is not an integer.",o=p)}if(e==="$exists"&&typeof t!="boolean"&&(i="Query operator $exists must be a boolean."),e==="$type"){const u=["null","boolean","number","string","array","object"],p='"'+u.slice(0,u.length-1).join('", "')+'", or "'+u[u.length-1]+'"';(typeof t!="string"||u.indexOf(t)==-1)&&(i="Query operator $type must be a string. Supported values: "+p+".")}if(e==="$size"&&parseInt(t,10)!==t&&(i="Query operator $size must be a integer."),e==="$regex"&&typeof t!="string"&&(n?i="Query operator $regex must be a string.":t instanceof RegExp||(i="Query operator $regex must be a string or an instance of a javascript regular expression.")),i){if(l){const u=o===null?" ":Array.isArray(o)?" array":" "+typeof o,p=ee(o)?JSON.stringify(o,null," "):o;i+=" Received"+u+": "+p}throw new Error(i)}}const Ot=["$all","$allMatch","$and","$elemMatch","$exists","$in","$mod","$nin","$nor","$not","$or","$regex","$size","$type"],$t=["$in","$nin","$mod","$all"],It=["$eq","$gt","$gte","$lt","$lte"];function te(e,t){if(Array.isArray(e))for(const n of e)ee(n)&&te(n,t);else for(const[n,i]of Object.entries(e))Ot.indexOf(n)!==-1&&xt(n,i,t),It.indexOf(n)===-1&&$t.indexOf(n)===-1&&ee(i)&&te(i,t)}async function H(e,t,n){n.body&&(n.body=JSON.stringify(n.body),n.headers=new D({"Content-type":"application/json"}));const i=await e.fetch(t,n),o=await i.json();if(!i.ok){o.status=i.status;const l=ot(o);throw pe(l)}return o}async function St(e,t){return await H(e,"_index",{method:"POST",body:Be(t)})}async function jt(e,t){return te(t.selector,!0),await H(e,"_find",{method:"POST",body:t})}async function Mt(e,t){return await H(e,"_explain",{method:"POST",body:t})}async function Tt(e){return await H(e,"_index",{method:"GET"})}async function Et(e,t){const n=t.ddoc,i=t.type||"json",o=t.name;if(!n)throw new Error("you must provide an index's ddoc");if(!o)throw new Error("you must provide an index's name");const l="_index/"+[n,i,o].map(encodeURIComponent).join("/");return await H(e,l,{method:"DELETE"})}function Ue(e,t){for(const n of t)if(e=e[n],e===void 0)return;return e}function Ft(e,t,n){return function(i){if(n&&!se(i,n))return;const o=[];for(const l of e){const u=Ue(i,ie(l));if(u===void 0)return;o.push(u)}t(o)}}function At(e,t,n){const i=ie(e);return function(o){if(n&&!se(o,n))return;const l=Ue(o,i);l!==void 0&&t(l)}}function Nt(e,t,n){return function(i){n&&!se(i,n)||t(i[e])}}function Pt(e,t,n){return function(i){if(n&&!se(i,n))return;const o=e.map(l=>i[l]);t(o)}}function Vt(e){return e.every(t=>t.indexOf(".")===-1)}function Ct(e,t,n){const i=Vt(e),o=e.length===1;return i?o?Nt(e[0],t,n):Pt(e,t,n):o?At(e[0],t,n):Ft(e,t,n)}function Qt(e,t){const n=Object.keys(e.fields),i=e.partial_filter_selector;return Ct(n,t,i)}function Kt(){throw new Error("reduce not supported")}function Rt(e,t){const n=e.views[t];if(!n.map||!n.map.fields)throw new Error("ddoc "+e._id+" with view "+t+" doesn't have map.fields defined. maybe it wasn't created by this plugin?")}const ye=pt("indexes",Qt,Kt,Rt);function be(e){return e._customFindAbstractMapper?{query:function(n,i){const o=ye.query.bind(this);return e._customFindAbstractMapper.query.call(this,n,i,o)},viewCleanup:function(){const n=ye.viewCleanup.bind(this);return e._customFindAbstractMapper.viewCleanup.call(this,n)}}:ye}function Lt(e){if(!Array.isArray(e))throw new Error("invalid sort json - should be an array");return e.map(function(t){if(typeof t=="string"){const n={};return n[t]="asc",n}else return t})}const Bt=/^_design\//;function Ut(e){let t=[];return typeof e=="string"?t.push(e):t=e,t.map(function(n){return n.replace(Bt,"")})}function qe(e){return e.fields=e.fields.map(function(t){if(typeof t=="string"){const n={};return n[t]="asc",n}return t}),e.partial_filter_selector&&(e.partial_filter_selector=Ne(e.partial_filter_selector)),e}function qt(e,t){return t.def.fields.map(n=>{const i=C(n);return Ce(e,ie(i))})}function zt(e,t,n){const i=n.def.fields;let o=0;for(const l of e){let u=qt(l.doc,n);if(i.length===1)u=u[0];else for(;u.length>t.length;)u.pop();if(Math.abs(U(u,t))>0)break;++o}return o>0?e.slice(o):e}function Gt(e){const t=re(e);return delete t.startkey,delete t.endkey,delete t.inclusive_start,delete t.inclusive_end,"endkey"in e&&(t.startkey=e.endkey),"startkey"in e&&(t.endkey=e.startkey),"inclusive_start"in e&&(t.inclusive_end=e.inclusive_start),"inclusive_end"in e&&(t.inclusive_start=e.inclusive_end),t}function Jt(e){const t=e.fields.filter(function(n){return Pe(n)==="asc"});if(t.length!==0&&t.length!==e.fields.length)throw new Error("unsupported mixed sorting")}function Xt(e,t){if(t.defaultUsed&&e.sort){const n=e.sort.filter(function(i){return Object.keys(i)[0]!=="_id"}).map(function(i){return Object.keys(i)[0]});if(n.length>0)throw new Error('Cannot sort on field(s) "'+n.join(",")+'" when using the default index')}t.defaultUsed}function Ht(e){if(typeof e.selector!="object")throw new Error("you must provide a selector when you find()")}function Yt(e,t){const n=Object.keys(e),i=t?t.map(C):[];let o;return n.length>=i.length?o=n:o=i,i.length===0?{fields:o}:(o=o.sort(function(l,u){let p=i.indexOf(l);p===-1&&(p=Number.MAX_VALUE);let g=i.indexOf(u);return g===-1&&(g=Number.MAX_VALUE),p<g?-1:p>g?1:0}),{fields:o,sortOrder:t.map(C)})}async function Wt(e,t){t=Be(t);const n=re(t.index);t.index=qe(t.index),Jt(t.index);let i;function o(){return i||(i=Ae(JSON.stringify(t)))}const l=t.name||"idx-"+o(),u=t.ddoc||"idx-"+o(),p="_design/"+u;let g=!1,S=!1;function v(T){return T._rev&&T.language!=="query"&&(g=!0),T.language="query",T.views=T.views||{},S=!!T.views[l],S?!1:(T.views[l]={map:{fields:ve(t.index.fields),partial_filter_selector:t.index.partial_filter_selector},reduce:"_count",options:{def:n}},T)}if(e.constructor.emit("debug",["find","creating index",p]),await ke(e,p,v),g)throw new Error('invalid language for ddoc with id "'+p+'" (should be "query")');const m=u+"/"+l;return await be(e).query.call(e,m,{limit:0,reduce:!1}),{id:p,name:l,result:S?"exists":"created"}}async function ze(e){const t=await e.allDocs({startkey:"_design/",endkey:"_design/￿",include_docs:!0}),n={indexes:[{ddoc:null,name:"_all_docs",type:"special",def:{fields:[{_id:"asc"}]}}]};return n.indexes=Re(n.indexes,t.rows.filter(function(i){return i.doc.language==="query"}).map(function(i){return(i.doc.views!==void 0?Object.keys(i.doc.views):[]).map(function(l){const u=i.doc.views[l];return{ddoc:i.id,name:l,type:"json",def:qe(u.options.def)}})})),n.indexes.sort(function(i,o){return Ve(i.name,o.name)}),n.total_rows=n.indexes.length,n}const ne=null,me={"￿":{}},Zt={queryOpts:{limit:0,startkey:me,endkey:ne},inMemoryFields:[]};function Dt(e,t){return e.def.fields.some(n=>C(n)===t)}function en(e,t){const n=e[t];return C(n)!=="$eq"}function Ge(e,t){const n=t.def.fields.map(C);return e.slice().sort(function(i,o){let l=n.indexOf(i),u=n.indexOf(o);return l===-1&&(l=Number.MAX_VALUE),u===-1&&(u=Number.MAX_VALUE),Ve(l,u)})}function tn(e,t,n){n=Ge(n,e);let i=!1;for(let o=0,l=n.length;o<l;o++){const u=n[o];if(i||!Dt(e,u))return n.slice(o);o<l-1&&en(t,u)&&(i=!0)}return[]}function nn(e){const t=[];for(const[n,i]of Object.entries(e))for(const o of Object.keys(i))o==="$ne"&&t.push(n);return t}function rn(e,t,n,i){const o=Re(e,tn(t,n,i),nn(n));return Ge(bt(o),t)}function sn(e,t,n){if(t){const i=kt(t,e),o=Le(n,e);return i&&o}return wt(n,e)}const on=["$eq","$gt","$gte","$lt","$lte"];function Je(e){return on.indexOf(e)===-1}function cn(e,t){const n=e[0],i=t[n];return typeof i>"u"?!0:!(Object.keys(i).length===1&&C(i)==="$ne")}function an(e,t,n,i){const o=e.def.fields.map(C);return sn(o,t,n)?cn(o,i):!1}function un(e,t,n,i){return i.filter(function(o){return an(o,n,t,e)})}function ln(e,t,n,i,o){const l=un(e,t,n,i);if(l.length===0){if(o)throw{error:"no_usable_index",message:"There is no index available for this selector."};const g=i[0];return g.defaultUsed=!0,g}if(l.length===1&&!o)return l[0];const u=_t(t);function p(g){const S=g.def.fields.map(C);let v=0;for(const m of S)u[m]&&v++;return v}if(o){const g="_design/"+o[0],S=o.length===2?o[1]:!1,v=l.find(function(m){return!!(S&&m.ddoc===g&&S===m.name||m.ddoc===g)});if(!v)throw{error:"unknown_error",message:"Could not find that index or could not use that index for the query"};return v}return vt(l,p)}function dn(e,t){switch(e){case"$eq":return{key:t};case"$lte":return{endkey:t};case"$gte":return{startkey:t};case"$lt":return{endkey:t,inclusive_end:!1};case"$gt":return{startkey:t,inclusive_start:!1}}return{startkey:ne}}function fn(e,t){const n=C(t.def.fields[0]),i=e[n]||{},o=[],l=Object.keys(i);let u;for(const p of l){Je(p)&&o.push(n);const g=i[p],S=dn(p,g);u?u=ve([u,S]):u=S}return{queryOpts:u,inMemoryFields:o}}function yn(e,t){switch(e){case"$eq":return{startkey:t,endkey:t};case"$lte":return{endkey:t};case"$gte":return{startkey:t};case"$lt":return{endkey:t,inclusive_end:!1};case"$gt":return{startkey:t,inclusive_start:!1}}}function hn(e,t){const n=t.def.fields.map(C);let i=[];const o=[],l=[];let u,p;function g(v){u!==!1&&o.push(ne),p!==!1&&l.push(me),i=n.slice(v)}for(let v=0,m=n.length;v<m;v++){const T=n[v],E=e[T];if(!E||!Object.keys(E).length){g(v);break}else if(Object.keys(E).some(Je)){g(v);break}else if(v>0){const F="$gt"in E||"$gte"in E||"$lt"in E||"$lte"in E,P=Object.keys(e[n[v-1]]),Q=Fe(P,["$eq"]),L=Fe(P,Object.keys(E));if(F&&!Q&&!L){g(v);break}}const R=Object.keys(E);let j=null;for(const F of R){const P=E[F],Q=yn(F,P);j?j=ve([j,Q]):j=Q}o.push("startkey"in j?j.startkey:ne),l.push("endkey"in j?j.endkey:me),"inclusive_start"in j&&(u=j.inclusive_start),"inclusive_end"in j&&(p=j.inclusive_end)}const S={startkey:o,endkey:l};return typeof u<"u"&&(S.inclusive_start=u),typeof p<"u"&&(S.inclusive_end=p),{queryOpts:S,inMemoryFields:i}}function pn(e){return Object.keys(e).map(function(n){return e[n]}).some(function(n){return typeof n=="object"&&Object.keys(n).length===0})}function gn(e){return{queryOpts:{startkey:null},inMemoryFields:[Object.keys(e)]}}function mn(e,t){return t.defaultUsed?gn(e):t.def.fields.length===1?fn(e,t):hn(e,t)}function kn(e,t){const n=e.selector,i=e.sort;if(pn(n))return Object.assign({},Zt,{index:t[0]});const o=Yt(n,i),l=o.fields,u=o.sortOrder,p=ln(n,l,u,t,e.use_index),g=mn(n,p),S=g.queryOpts,v=g.inMemoryFields,m=rn(v,p,n,l);return{queryOpts:S,index:p,inMemoryFields:m}}function wn(e){return e.ddoc.substring(8)+"/"+e.name}async function _n(e,t){const n=re(t);n.descending?("endkey"in n&&typeof n.endkey!="string"&&(n.endkey=""),"startkey"in n&&typeof n.startkey!="string"&&(n.limit=0)):("startkey"in n&&typeof n.startkey!="string"&&(n.startkey=""),"endkey"in n&&typeof n.endkey!="string"&&(n.limit=0)),"key"in n&&typeof n.key!="string"&&(n.limit=0),n.limit>0&&n.indexes_count&&(n.original_limit=n.limit,n.limit+=n.indexes_count);const i=await e.allDocs(n);return i.rows=i.rows.filter(function(o){return!/^_design\//.test(o.id)}),n.original_limit&&(n.limit=n.original_limit),i.rows=i.rows.slice(0,n.limit),i}async function vn(e,t,n){return n.name==="_all_docs"?_n(e,t):be(e).query.call(e,wn(n),t)}async function Xe(e,t,n){t.selector&&(te(t.selector,!1),t.selector=Ne(t.selector)),t.sort&&(t.sort=Lt(t.sort)),t.use_index&&(t.use_index=Ut(t.use_index)),"limit"in t||(t.limit=25),Ht(t);const i=await ze(e);e.constructor.emit("debug",["find","planning query",t]);const o=kn(t,i.indexes);e.constructor.emit("debug",["find","query plan",o]);const l=o.index;Xt(t,l);let u=Object.assign({include_docs:!0,reduce:!1,indexes_count:i.total_rows},o.queryOpts);if("startkey"in u&&"endkey"in u&&U(u.startkey,u.endkey)>0)return{docs:[]};if(t.sort&&typeof t.sort[0]!="string"&&Pe(t.sort[0])==="desc"&&(u.descending=!0,u=Gt(u)),o.inMemoryFields.length||(u.limit=t.limit,"skip"in t&&(u.skip=t.skip)),n)return Promise.resolve(o,u);const g=await vn(e,u,l);u.inclusive_start===!1&&(g.rows=zt(g.rows,u.startkey,l)),o.inMemoryFields.length&&(g.rows=at(g.rows,t,o.inMemoryFields));const S={docs:g.rows.map(function(v){const m=v.doc;return t.fields?mt(m,t.fields):m})};return l.defaultUsed&&(S.warning="No matching index found, create an index to optimize query time."),S}async function bn(e,t){const n=await Xe(e,t,!0);return{dbname:e.name,index:n.index,selector:t.selector,range:{start_key:n.queryOpts.startkey,end_key:n.queryOpts.endkey},opts:{use_index:t.use_index||[],bookmark:"nil",limit:t.limit,skip:t.skip,sort:t.sort||{},fields:t.fields,conflicts:!1,r:[49]},limit:t.limit,skip:t.skip||0,fields:t.fields}}async function xn(e,t){if(!t.ddoc)throw new Error("you must supply an index.ddoc when deleting");if(!t.name)throw new Error("you must supply an index.name when deleting");const n=t.ddoc,i=t.name;function o(l){return Object.keys(l.views).length===1&&l.views[i]?{_id:n,_deleted:!0}:(delete l.views[i],l)}return await ke(e,n,o),await be(e).viewCleanup.apply(e),{ok:!0}}const Y={};Y.createIndex=X(async function(e){if(typeof e!="object")throw new Error("you must provide an index to create");return(z(this)?St:Wt)(this,e)});Y.find=X(async function(e){if(typeof e!="object")throw new Error("you must provide search parameters to find()");return(z(this)?jt:Xe)(this,e)});Y.explain=X(async function(e){if(typeof e!="object")throw new Error("you must provide search parameters to explain()");return(z(this)?Mt:bn)(this,e)});Y.getIndexes=X(async function(){return(z(this)?Tt:ze)(this)});Y.deleteIndex=X(async function(e){if(typeof e!="object")throw new Error("you must provide an index to delete");return(z(this)?Et:xn)(this,e)});export{Y as default};
@@ -1 +1 @@
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 b(e){return e._maxListeners===void 0?c.defaultMaxListeners:e._maxListeners}c.prototype.getMaxListeners=function(){return b(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=b(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():w(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 w(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)();if(l[6]=l[6]&15|64,l[8]=l[8]&63|128,o){u=u||0;for(var f=0;f<16;++f)o[u+f]=l[f];return o}return 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 b(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 w(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=w(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?w(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=w(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=b(new Uint8Array(a)),e=A(r);return s?w(e):e},p})}(T)),T.exports}var me=ge();const U=G(me);var _e=self.setImmediate||self.setTimeout,we=32768;function be(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(we,l),c=Math.ceil(l/f),g=0,m=u?new U:new U.ArrayBuffer,b=u?Be:Ae;function S(){_e(E)}function A(){var L=m.end(!0),C=be(L);o(C),m.destroy()}function E(){var L=g*f,C=L+f;g++,g<c?b(m,i,L,C,S):b(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 b=Re(function(S,A){S?g(S):c(A)});o.push(b),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 b=["api",i.name,o];b=b.concat(g?["error",g]:["success",m]),i.constructor.emit("debug",b),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(w){f.has(w.id)?f.get(w.id).push(w):f.set(w.id,[w])});var c=f.size,g=0,m=new Array(c);function b(){var w=[];m.forEach(function(p){p.docs.forEach(function(a){w.push({id:p.id,docs:[a]})})}),u(null,{results:w})}function S(){++g===c&&b()}function A(w,p,a){m[w]={id:p,docs:a},S()}var E=[];f.forEach(function(w,p){E.push(p)});var L=0;function C(){if(!(L>=E.length)){var w=Math.min(L+Me,E.length),p=E.slice(L,w);R(p,L),L+=p.length}}function R(w,p){w.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 b=$(f,["style","include_docs","attachments","conflicts","filter","doc_ids","view","since","query_params","binary","return_docs"]);function S(){c=!1}l.changes(b).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};
1
+ import{g as G}from"./milkdown.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 b(e){return e._maxListeners===void 0?c.defaultMaxListeners:e._maxListeners}c.prototype.getMaxListeners=function(){return b(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=b(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():w(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 w(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)();if(l[6]=l[6]&15|64,l[8]=l[8]&63|128,o){u=u||0;for(var f=0;f<16;++f)o[u+f]=l[f];return o}return 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 b(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 w(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=w(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?w(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=w(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=b(new Uint8Array(a)),e=A(r);return s?w(e):e},p})}(T)),T.exports}var me=ge();const U=G(me);var _e=self.setImmediate||self.setTimeout,we=32768;function be(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(we,l),c=Math.ceil(l/f),g=0,m=u?new U:new U.ArrayBuffer,b=u?Be:Ae;function S(){_e(E)}function A(){var L=m.end(!0),C=be(L);o(C),m.destroy()}function E(){var L=g*f,C=L+f;g++,g<c?b(m,i,L,C,S):b(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 b=Re(function(S,A){S?g(S):c(A)});o.push(b),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 b=["api",i.name,o];b=b.concat(g?["error",g]:["success",m]),i.constructor.emit("debug",b),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(w){f.has(w.id)?f.get(w.id).push(w):f.set(w.id,[w])});var c=f.size,g=0,m=new Array(c);function b(){var w=[];m.forEach(function(p){p.docs.forEach(function(a){w.push({id:p.id,docs:[a]})})}),u(null,{results:w})}function S(){++g===c&&b()}function A(w,p,a){m[w]={id:p,docs:a},S()}var E=[];f.forEach(function(w,p){E.push(p)});var L=0;function C(){if(!(L>=E.length)){var w=Math.min(L+Me,E.length),p=E.slice(L,w);R(p,L),L+=p.length}}function R(w,p){w.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 b=$(f,["style","include_docs","attachments","conflicts","filter","doc_ids","view","since","query_params","binary","return_docs"]);function S(){c=!1}l.changes(b).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};
package/dist/index.es.js CHANGED
@@ -1,3 +1,3 @@
1
- import{i as P,t as b,c as Z,a as H,b as $,r as fe,f as ce}from"./index.es3.js";import{c as _,B as ee,p as G,g as z,M as C,i as w,n as W,s as te,a as d,E as x,N as I,b as oe,I as N,r as he,d as A,R as J,e as le,f as de,U as ie,Q as _e,h as ve,j as O,u as K,v as me,k as ge,l as ye,o as pe,m as we,q as De}from"./index-browser.es2.js";import{m as Ee,f as ke}from"./index.es4.js";import"./index.js";function Ce(n){return te(`"use strict";
1
+ import{i as P,t as b,c as Z,a as H,b as $,r as fe,f as ce}from"./index.es3.js";import{c as _,B as ee,p as G,g as z,M as C,i as w,n as W,s as te,a as d,E as x,N as I,b as oe,I as N,r as he,d as A,R as J,e as le,f as de,U as ie,Q as _e,h as ve,j as O,u as K,v as me,k as ge,l as ye,o as pe,m as we,q as De}from"./index-browser.es2.js";import{m as Ee,f as ke}from"./index.es4.js";import"./milkdown.js";function Ce(n){return te(`"use strict";
2
2
  return `+n+";",{})}function xe(n){var e=["return function(doc) {",' "use strict";'," var emitted = false;"," var emit = function (a, b) {"," emitted = true;"," };"," var view = "+n+";"," view(doc);"," if (emitted) {"," return true;"," }","};"].join(`
3
3
  `);return te(e,{})}function Ae(n,e){if(n.selector&&n.filter&&n.filter!=="_selector"){var t=typeof n.filter=="string"?n.filter:"function";return e(new Error('selector invalid for filter "'+t+'"'))}e()}function Le(n){n.view&&!n.filter&&(n.filter="_view"),n.selector&&!n.filter&&(n.filter="_selector"),n.filter&&typeof n.filter=="string"&&(n.filter==="_view"?n.view=W(n.view):n.filter=W(n.filter))}function Oe(n,e){return e.filter&&typeof e.filter=="string"&&!e.doc_ids&&!w(n.db)}function Re(n,e){var t=e.complete;if(e.filter==="_view"){if(!e.view||typeof e.view!="string"){var i=_(ee,"`view` filter parameter not found or invalid.");return t(i)}var r=G(e.view);n.db.get("_design/"+r[0],function(s,f){if(n.isCancelled)return t(null,{status:"cancelled"});if(s)return t(z(s));var u=f&&f.views&&f.views[r[1]]&&f.views[r[1]].map;if(!u)return t(_(C,f.views?"missing json key: "+r[1]:"missing json key: views"));e.filter=xe(u),n.doChanges(e)})}else if(e.selector)e.filter=function(s){return Ee(s,e.selector)},n.doChanges(e);else{var a=G(e.filter);n.db.get("_design/"+a[0],function(s,f){if(n.isCancelled)return t(null,{status:"cancelled"});if(s)return t(z(s));var u=f&&f.filters&&f.filters[a[1]];if(!u)return t(_(C,f&&f.filters?"missing json key: "+a[1]:"missing json key: filters"));e.filter=Ce(u),n.doChanges(e)})}}function Te(n){n._changesFilterPlugin={validate:Ae,normalize:Le,shouldFilter:Oe,filter:Re}}function Se(n,e,t,i){try{n.emit("change",e,t,i)}catch(r){A("error",'Error in .on("change", function):',r)}}function Fe(n,e,t){var i=[{rev:n._rev}];t.style==="all_docs"&&(i=Z(e.rev_tree).map(function(a){return{rev:a.rev}}));var r={id:e.id,changes:i,doc:n};return $(e,n._rev)&&(r.deleted=!0),t.conflicts&&(r.doc._conflicts=H(e),r.doc._conflicts.length||delete r.doc._conflicts),r}class Pe extends x{constructor(e,t,i){super(),this.db=e,t=t?O(t):{};var r=t.complete=pe((f,u)=>{f?we(this,"error")>0&&this.emit("error",f):this.emit("complete",u),this.removeAllListeners(),e.removeListener("destroyed",a)});i&&(this.on("complete",function(f){i(null,f)}),this.on("error",i));const a=()=>{this.cancel()};e.once("destroyed",a),t.onChange=(f,u,o)=>{this.isCancelled||Se(this,f,u,o)};var s=new Promise(function(f,u){t.complete=function(o,c){o?u(o):f(c)}});this.once("cancel",function(){e.removeListener("destroyed",a),t.complete(null,{status:"cancelled"})}),this.then=s.then.bind(s),this.catch=s.catch.bind(s),this.then(function(f){r(null,f)},r),e.taskqueue.isReady?this.validateChanges(t):e.taskqueue.addTask(f=>{f?t.complete(f):this.isCancelled?this.emit("cancel"):this.validateChanges(t)})}cancel(){this.isCancelled=!0,this.db.taskqueue.isReady&&this.emit("cancel")}validateChanges(e){var t=e.complete;h._changesFilterPlugin?h._changesFilterPlugin.validate(e,i=>{if(i)return t(i);this.doChanges(e)}):this.doChanges(e)}doChanges(e){var t=e.complete;if(e=O(e),"live"in e&&!("continuous"in e)&&(e.continuous=e.live),e.processChange=Fe,e.since==="latest"&&(e.since="now"),e.since||(e.since=0),e.since==="now"){this.db.info().then(r=>{if(this.isCancelled){t(null,{status:"cancelled"});return}e.since=r.update_seq,this.doChanges(e)},t);return}if(h._changesFilterPlugin){if(h._changesFilterPlugin.normalize(e),h._changesFilterPlugin.shouldFilter(this,e))return h._changesFilterPlugin.filter(this,e)}else["doc_ids","filter","selector","view"].forEach(function(r){r in e&&A("warn",'The "'+r+'" option was passed in to changes/replicate, but pouchdb-changes-filter plugin is not installed, so it was ignored. Please install the plugin to enable filtering.')});"descending"in e||(e.descending=!1),e.limit=e.limit===0?1:e.limit,e.complete=t;var i=this.db._changes(e);if(i&&typeof i.cancel=="function"){const r=this.cancel;this.cancel=(...a)=>{i.cancel(),r.apply(this,a)}}}}function q(n,e){return function(t,i){t||i[0]&&i[0].error?(t=t||i[0],t.docId=e,n(t)):n(null,i.length?i[0]:i)}}function Ie(n){for(var e=0;e<n.length;e++){var t=n[e];if(t._deleted)delete t._attachments;else if(t._attachments)for(var i=Object.keys(t._attachments),r=0;r<i.length;r++){var a=i[r];t._attachments[a]=ye(t._attachments[a],["data","digest","content_type","length","revpos","stub"])}}}function Ne(n,e){if(n._id===e._id){const t=n._revisions?n._revisions.start:0,i=e._revisions?e._revisions.start:0;return t-i}return n._id<e._id?-1:1}function qe(n){var e={},t=[];return b(n,function(i,r,a,s){var f=r+"-"+a;return i&&(e[f]=0),s!==void 0&&t.push({from:s,to:f}),f}),t.reverse(),t.forEach(function(i){e[i.from]===void 0?e[i.from]=1+e[i.to]:e[i.from]=Math.min(e[i.from],1+e[i.to])}),e}function je(n){var e="limit"in n?n.keys.slice(n.skip,n.limit+n.skip):n.skip>0?n.keys.slice(n.skip):n.keys;n.keys=e,n.skip=0,delete n.limit,n.descending&&(e.reverse(),n.descending=!1)}function ne(n){var e=n._compactionQueue[0],t=e.opts,i=e.callback;n.get("_local/compaction").catch(function(){return!1}).then(function(r){r&&r.last_seq&&(t.last_seq=r.last_seq),n._compact(t,function(a,s){a?i(a):i(null,s),ge(function(){n._compactionQueue.shift(),n._compactionQueue.length&&ne(n)})})})}function Qe(n,e,t){return n.get("_local/purges").then(function(i){const r=i.purgeSeq+1;return i.purges.push({docId:e,rev:t,purgeSeq:r}),i.purges.length>self.purged_infos_limit&&i.purges.splice(0,i.purges.length-self.purged_infos_limit),i.purgeSeq=r,i}).catch(function(i){if(i.status!==404)throw i;return{_id:"_local/purges",purges:[{docId:e,rev:t,purgeSeq:0}],purgeSeq:0}}).then(function(i){return n.put(i)})}function be(n){return n.charAt(0)==="_"?n+" is not a valid attachment name, attachment names cannot start with '_'":!1}function j(n){return n===null||typeof n!="object"||Array.isArray(n)}const Be=/^\d+-[^-]*$/;function Q(n){return typeof n=="string"&&Be.test(n)}class re extends x{_setup(){this.post=d("post",function(e,t,i){if(typeof t=="function"&&(i=t,t={}),j(e))return i(_(I));this.bulkDocs({docs:[e]},t,q(i,e._id))}).bind(this),this.put=d("put",function(e,t,i){if(typeof t=="function"&&(i=t,t={}),j(e))return i(_(I));if(oe(e._id),"_rev"in e&&!Q(e._rev))return i(_(N));if(P(e._id)&&typeof this._putLocal=="function")return e._deleted?this._removeLocal(e,i):this._putLocal(e,i);const r=s=>{typeof this._put=="function"&&t.new_edits!==!1?this._put(e,t,s):this.bulkDocs({docs:[e]},t,q(s,e._id))};t.force&&e._rev?(a(),r(function(s){var f=s?null:{ok:!0,id:e._id,rev:e._rev};i(s,f)})):r(i);function a(){var s=e._rev.split("-"),f=s[1],u=parseInt(s[0],10),o=u+1,c=he();e._revisions={start:o,ids:[c,f]},e._rev=o+"-"+c,t.new_edits=!1}}).bind(this),this.putAttachment=d("putAttachment",function(e,t,i,r,a){var s=this;typeof a=="function"&&(a=r,r=i,i=null),typeof a>"u"&&(a=r,r=i,i=null),a||A("warn","Attachment",t,"on document",e,"is missing content_type");function f(u){var o="_rev"in u?parseInt(u._rev,10):0;return u._attachments=u._attachments||{},u._attachments[t]={content_type:a,data:r,revpos:++o},s.put(u)}return s.get(e).then(function(u){if(u._rev!==i)throw _(J);return f(u)},function(u){if(u.reason===C.message)return f({_id:e});throw u})}).bind(this),this.removeAttachment=d("removeAttachment",function(e,t,i,r){this.get(e,(a,s)=>{if(a){r(a);return}if(s._rev!==i){r(_(J));return}if(!s._attachments)return r();delete s._attachments[t],Object.keys(s._attachments).length===0&&delete s._attachments,this.put(s,r)})}).bind(this),this.remove=d("remove",function(e,t,i,r){var a;typeof t=="string"?(a={_id:e,_rev:t},typeof i=="function"&&(r=i,i={})):(a=e,typeof t=="function"?(r=t,i={}):(r=i,i=t)),i=i||{},i.was_delete=!0;var s={_id:a._id,_rev:a._rev||i.rev};if(s._deleted=!0,P(s._id)&&typeof this._removeLocal=="function")return this._removeLocal(a,r);this.bulkDocs({docs:[s]},i,q(r,s._id))}).bind(this),this.revsDiff=d("revsDiff",function(e,t,i){typeof t=="function"&&(i=t,t={});var r=Object.keys(e);if(!r.length)return i(null,{});var a=0,s=new Map;function f(o,c){s.has(o)||s.set(o,{missing:[]}),s.get(o).missing.push(c)}function u(o,c){var l=e[o].slice(0);b(c,function(v,y,g,L,R){var D=y+"-"+g,m=l.indexOf(D);m!==-1&&(l.splice(m,1),R.status!=="available"&&f(o,D))}),l.forEach(function(v){f(o,v)})}r.forEach(function(o){this._getRevisionTree(o,function(c,l){if(c&&c.status===404&&c.message==="missing")s.set(o,{missing:e[o]});else{if(c)return i(c);u(o,l)}if(++a===r.length){var v={};return s.forEach(function(y,g){v[g]=y}),i(null,v)}})},this)}).bind(this),this.bulkGet=d("bulkGet",function(e,t){le(this,e,t)}).bind(this),this.compactDocument=d("compactDocument",function(e,t,i){this._getRevisionTree(e,(r,a)=>{if(r)return i(r);var s=qe(a),f=[],u=[];Object.keys(s).forEach(function(o){s[o]>t&&f.push(o)}),b(a,function(o,c,l,v,y){var g=c+"-"+l;y.status==="available"&&f.indexOf(g)!==-1&&u.push(g)}),this._doCompaction(e,u,i)})}).bind(this),this.compact=d("compact",function(e,t){typeof e=="function"&&(t=e,e={}),e=e||{},this._compactionQueue=this._compactionQueue||[],this._compactionQueue.push({opts:e,callback:t}),this._compactionQueue.length===1&&ne(this)}).bind(this),this.get=d("get",function(e,t,i){if(typeof t=="function"&&(i=t,t={}),t=t||{},typeof e!="string")return i(_(de));if(P(e)&&typeof this._getLocal=="function")return this._getLocal(e,i);var r=[];const a=()=>{var u=[],o=r.length;if(!o)return i(null,u);r.forEach(c=>{this.get(e,{rev:c,revs:t.revs,latest:t.latest,attachments:t.attachments,binary:t.binary},function(l,v){if(l)u.push({missing:c});else{for(var y,g=0,L=u.length;g<L;g++)if(u[g].ok&&u[g].ok._rev===v._rev){y=!0;break}y||u.push({ok:v})}o--,o||i(null,u)})})};if(t.open_revs){if(t.open_revs==="all")this._getRevisionTree(e,function(u,o){if(u)return i(u);r=Z(o).map(function(c){return c.rev}),a()});else if(Array.isArray(t.open_revs)){r=t.open_revs;for(var s=0;s<r.length;s++){var f=r[s];if(!Q(f))return i(_(N))}a()}else return i(_(ie,"function_clause"));return}return this._get(e,t,(u,o)=>{if(u)return u.docId=e,i(u);var c=o.doc,l=o.metadata,v=o.ctx;if(t.conflicts){var y=H(l);y.length&&(c._conflicts=y)}if($(l,c._rev)&&(c._deleted=!0),t.revs||t.revs_info){for(var g=c._rev.split("-"),L=parseInt(g[0],10),R=g[1],D=fe(l.rev_tree),m=null,T=0;T<D.length;T++){var B=D[T];const p=B.ids.findIndex(k=>k.id===R);var ae=p===L-1;(ae||!m&&p!==-1)&&(m=B)}if(!m)return u=new Error("invalid rev tree"),u.docId=e,i(u);const E=c._rev.split("-")[1],F=m.ids.findIndex(p=>p.id===E)+1;var ue=m.ids.length-F;if(m.ids.splice(F,ue),m.ids.reverse(),t.revs&&(c._revisions={start:m.pos+m.ids.length-1,ids:m.ids.map(function(p){return p.id})}),t.revs_info){var M=m.pos+m.ids.length;c._revs_info=m.ids.map(function(p){return M--,{rev:M+"-"+p.id,status:p.opts.status}})}}if(t.attachments&&c._attachments){var S=c._attachments,U=Object.keys(S).length;if(U===0)return i(null,c);Object.keys(S).forEach(E=>{this._getAttachment(c._id,E,S[E],{binary:t.binary,metadata:l,ctx:v},function(F,p){var k=c._attachments[E];k.data=p,delete k.stub,delete k.length,--U||i(null,c)})})}else{if(c._attachments)for(var V in c._attachments)Object.prototype.hasOwnProperty.call(c._attachments,V)&&(c._attachments[V].stub=!0);i(null,c)}})}).bind(this),this.getAttachment=d("getAttachment",function(e,t,i,r){i instanceof Function&&(r=i,i={}),this._get(e,i,(a,s)=>{if(a)return r(a);if(s.doc._attachments&&s.doc._attachments[t])i.ctx=s.ctx,i.binary=!0,i.metadata=s.metadata,this._getAttachment(e,t,s.doc._attachments[t],i,r);else return r(_(C))})}).bind(this),this.allDocs=d("allDocs",function(e,t){if(typeof e=="function"&&(t=e,e={}),e.skip=typeof e.skip<"u"?e.skip:0,e.start_key&&(e.startkey=e.start_key),e.end_key&&(e.endkey=e.end_key),"keys"in e){if(!Array.isArray(e.keys))return t(new TypeError("options.keys must be an array"));var i=["startkey","endkey","key"].filter(function(r){return r in e})[0];if(i){t(_(_e,"Query parameter `"+i+"` is not compatible with multi-get"));return}if(!w(this)&&(je(e),e.keys.length===0))return this._allDocs({limit:0},t)}return this._allDocs(e,t)}).bind(this),this.close=d("close",function(e){return this._closed=!0,this.emit("closed"),this._close(e)}).bind(this),this.info=d("info",function(e){this._info((t,i)=>{if(t)return e(t);i.db_name=i.db_name||this.name,i.auto_compaction=!!(this.auto_compaction&&!w(this)),i.adapter=this.adapter,e(null,i)})}).bind(this),this.id=d("id",function(e){return this._id(e)}).bind(this),this.bulkDocs=d("bulkDocs",function(e,t,i){if(typeof t=="function"&&(i=t,t={}),t=t||{},Array.isArray(e)&&(e={docs:e}),!e||!e.docs||!Array.isArray(e.docs))return i(_(ve));for(var r=0;r<e.docs.length;++r){const u=e.docs[r];if(j(u))return i(_(I));if("_rev"in u&&!Q(u._rev))return i(_(N))}var a;if(e.docs.forEach(function(u){u._attachments&&Object.keys(u._attachments).forEach(function(o){a=a||be(o),u._attachments[o].content_type||A("warn","Attachment",o,"on document",u._id,"is missing content_type")})}),a)return i(_(ee,a));"new_edits"in t||("new_edits"in e?t.new_edits=e.new_edits:t.new_edits=!0);var s=this;!t.new_edits&&!w(s)&&e.docs.sort(Ne),Ie(e.docs);var f=e.docs.map(function(u){return u._id});this._bulkDocs(e,t,function(u,o){if(u)return i(u);if(t.new_edits||(o=o.filter(function(v){return v.error})),!w(s))for(var c=0,l=o.length;c<l;c++)o[c].id=o[c].id||f[c];i(null,o)})}).bind(this),this.registerDependentDatabase=d("registerDependentDatabase",function(e,t){var i=O(this.__opts);this.__opts.view_adapter&&(i.adapter=this.__opts.view_adapter);var r=new this.constructor(e,i);function a(s){return s.dependentDbs=s.dependentDbs||{},s.dependentDbs[e]?!1:(s.dependentDbs[e]=!0,s)}K(this,"_local/_pouch_dependentDbs",a).then(function(){t(null,{db:r})}).catch(t)}).bind(this),this.destroy=d("destroy",function(e,t){typeof e=="function"&&(t=e,e={});var i="use_prefix"in this?this.use_prefix:!0;const r=()=>{this._destroy(e,(a,s)=>{if(a)return t(a);this._destroyed=!0,this.emit("destroyed"),t(null,s||{ok:!0})})};if(w(this))return r();this.get("_local/_pouch_dependentDbs",(a,s)=>{if(a)return a.status!==404?t(a):r();var f=s.dependentDbs,u=this.constructor,o=Object.keys(f).map(c=>{var l=i?c.replace(new RegExp("^"+u.prefix),""):c;return new u(l,this.__opts).destroy()});Promise.all(o).then(r,t)})}).bind(this)}_compact(e,t){var i={return_docs:!1,last_seq:e.last_seq||0,since:e.last_seq||0},r=[],a,s=0;const f=c=>{this.activeTasks.update(a,{completed_items:++s}),r.push(this.compactDocument(c.id,0))},u=c=>{this.activeTasks.remove(a,c),t(c)},o=c=>{var l=c.last_seq;Promise.all(r).then(()=>K(this,"_local/compaction",v=>!v.last_seq||v.last_seq<l?(v.last_seq=l,v):!1)).then(()=>{this.activeTasks.remove(a),t(null,{ok:!0})}).catch(u)};this.info().then(c=>{a=this.activeTasks.add({name:"database_compaction",total_items:c.update_seq-i.last_seq}),this.changes(i).on("change",f).on("complete",o).on("error",u)})}changes(e,t){return typeof e=="function"&&(t=e,e={}),e=e||{},e.return_docs="return_docs"in e?e.return_docs:!e.live,new Pe(this,e,t)}type(){return typeof this._type=="function"?this._type():this.adapter}}re.prototype.purge=d("_purge",function(n,e,t){if(typeof this._purge>"u")return t(_(ie,"Purge is not implemented in the "+this.adapter+" adapter."));var i=this;i._getRevisionTree(n,(r,a)=>{if(r)return t(r);if(!a)return t(_(C));let s;try{s=ce(a,e)}catch(f){return t(f.message||f)}i._purge(n,s,(f,u)=>{if(f)return t(f);Qe(i,n,e).then(function(){return t(null,u)})})})});class Me{constructor(){this.isReady=!1,this.failed=!1,this.queue=[]}execute(){var e;if(this.failed)for(;e=this.queue.shift();)e(this.failed);else for(;e=this.queue.shift();)e()}fail(e){this.failed=e,this.execute()}ready(e){this.isReady=!0,this.db=e,this.execute()}addTask(e){this.queue.push(e),this.failed&&this.execute()}}function Ue(n,e){var t=n.match(/([a-z-]*):\/\/(.*)/);if(t)return{name:/https?/.test(t[1])?t[1]+"://"+t[2]:t[2],adapter:t[1]};var i=h.adapters,r=h.preferredAdapters,a=h.prefix,s=e.adapter;if(!s)for(var f=0;f<r.length;++f){if(s=r[f],s==="idb"&&"websql"in i&&De()&&localStorage["_pouch__websqldb_"+a+n]){A("log",'PouchDB is downgrading "'+n+'" to WebSQL to avoid data loss, because it was already opened with WebSQL.');continue}break}var u=i[s],o=u&&"use_prefix"in u?u.use_prefix:!0;return{name:o?a+n:n,adapter:s}}function Ve(n,e){n.prototype=Object.create(e.prototype,{constructor:{value:n}})}function se(n,e){let t=function(...i){if(!(this instanceof t))return new t(...i);e.apply(this,i)};return Ve(t,n),t}function Ge(n){function e(i){n.removeListener("closed",t),i||n.constructor.emit("destroyed",n.name)}function t(){n.removeListener("destroyed",e),n.constructor.emit("unref",n)}n.once("destroyed",e),n.once("closed",t),n.constructor.emit("ref",n)}class Y extends re{constructor(e,t){super(),this._setup(e,t)}_setup(e,t){if(super._setup(),t=t||{},e&&typeof e=="object"&&(t=e,e=t.name,delete t.name),t.deterministic_revs===void 0&&(t.deterministic_revs=!0),this.__opts=t=O(t),this.auto_compaction=t.auto_compaction,this.purged_infos_limit=t.purged_infos_limit||1e3,this.prefix=h.prefix,typeof e!="string")throw new Error("Missing/invalid DB name");var i=(t.prefix||"")+e,r=Ue(i,t);if(t.name=r.name,t.adapter=t.adapter||r.adapter,this.name=e,this._adapter=t.adapter,h.emit("debug",["adapter","Picked adapter: ",t.adapter]),!h.adapters[t.adapter]||!h.adapters[t.adapter].valid())throw new Error("Invalid Adapter: "+t.adapter);if(t.view_adapter&&(!h.adapters[t.view_adapter]||!h.adapters[t.view_adapter].valid()))throw new Error("Invalid View Adapter: "+t.view_adapter);this.taskqueue=new Me,this.adapter=t.adapter,h.adapters[t.adapter].call(this,t,a=>{if(a)return this.taskqueue.fail(a);Ge(this),this.emit("created",this),h.emit("created",this.name),this.taskqueue.ready(this)})}}const h=se(Y,function(n,e){Y.prototype._setup.call(this,n,e)});class ze{constructor(){this.tasks={}}list(){return Object.values(this.tasks)}add(e){const t=me();return this.tasks[t]={id:t,name:e.name,total_items:e.total_items,created_at:new Date().toJSON()},t}get(e){return this.tasks[e]}remove(e,t){return delete this.tasks[e],this.tasks}update(e,t){const i=this.tasks[e];if(typeof i<"u"){const r={id:i.id,name:i.name,created_at:i.created_at,total_items:t.total_items||i.total_items,completed_items:t.completed_items||i.completed_items,updated_at:new Date().toJSON()};this.tasks[e]=r}return this.tasks}}h.adapters={};h.preferredAdapters=[];h.prefix="_pouch_";var X=new x;function We(n){Object.keys(x.prototype).forEach(function(t){typeof x.prototype[t]=="function"&&(n[t]=X[t].bind(X))});var e=n._destructionListeners=new Map;n.on("ref",function(i){e.has(i.name)||e.set(i.name,[]),e.get(i.name).push(i)}),n.on("unref",function(i){if(e.has(i.name)){var r=e.get(i.name),a=r.indexOf(i);a<0||(r.splice(a,1),r.length>1?e.set(i.name,r):e.delete(i.name))}}),n.on("destroyed",function(i){if(e.has(i)){var r=e.get(i);e.delete(i),r.forEach(function(a){a.emit("destroyed",!0)})}})}We(h);h.adapter=function(n,e,t){e.valid()&&(h.adapters[n]=e,t&&h.preferredAdapters.push(n))};h.plugin=function(n){if(typeof n=="function")n(h);else{if(typeof n!="object"||Object.keys(n).length===0)throw new Error('Invalid plugin: got "'+n+'", expected an object or a function');Object.keys(n).forEach(function(e){h.prototype[e]=n[e]})}return this.__defaults&&(h.__defaults=Object.assign({},this.__defaults)),h};h.defaults=function(n){let e=se(h,function(t,i){i=i||{},t&&typeof t=="object"&&(i=t,t=i.name,delete i.name),i=Object.assign({},e.__defaults,i),h.call(this,t,i)});return e.preferredAdapters=h.preferredAdapters.slice(),Object.keys(h).forEach(function(t){t in e||(e[t]=h[t])}),e.__defaults=Object.assign({},this.__defaults,n),e};h.fetch=function(n,e){return ke(n,e)};h.prototype.activeTasks=h.activeTasks=new ze;var Je="9.0.0";h.plugin(Te);h.version=Je;export{h as default};
package/dist/index.es2.js CHANGED
@@ -1,2 +1,2 @@
1
- import{g as Qe}from"./index.js";import{t as je,w as Ae,r as ze,b as Ue,c as W,D as we,I as Ye,x as Xe,y as Te,z as Pe,A as Ze,C as $e,F as ke,G as et,R as _e,M as ae,H as tt,J as rt,k as Ke,d as Oe,K as nt,L as at,O as Re,j as it,P as ot,l as st,q as ut,S as ct}from"./index-browser.es2.js";import{i as ge,m as Le,d as ft,w as le,b as ie,l as vt,t as lt,a as dt,e as _t}from"./index.es3.js";var de={},Ce;function gt(){if(Ce)return de;Ce=1,de.stringify=function(r){var t=[];t.push({obj:r});for(var a="",c,o,d,g,m,S,A,C,D,R,q;c=t.pop();)if(o=c.obj,d=c.prefix||"",g=c.val||"",a+=d,g)a+=g;else if(typeof o!="object")a+=typeof o>"u"?null:JSON.stringify(o);else if(o===null)a+="null";else if(Array.isArray(o)){for(t.push({val:"]"}),m=o.length-1;m>=0;m--)S=m===0?"":",",t.push({obj:o[m],prefix:S});t.push({val:"["})}else{A=[];for(C in o)o.hasOwnProperty(C)&&A.push(C);for(t.push({val:"}"}),m=A.length-1;m>=0;m--)D=A[m],R=o[D],q=m>0?",":"",q+=JSON.stringify(D)+":",t.push({obj:R,prefix:q});t.push({val:"{"})}return a};function e(n,r,t){var a=t[t.length-1];n===a.element&&(t.pop(),a=t[t.length-1]);var c=a.element,o=a.index;if(Array.isArray(c))c.push(n);else if(o===r.length-2){var d=r.pop();c[d]=n}else r.push(n)}return de.parse=function(n){for(var r=[],t=[],a=0,c,o,d,g,m,S,A,C,D;;){if(c=n[a++],c==="}"||c==="]"||typeof c>"u"){if(r.length===1)return r.pop();e(r.pop(),r,t);continue}switch(c){case" ":case" ":case`
1
+ import{g as Qe}from"./milkdown.js";import{t as je,w as Ae,r as ze,b as Ue,c as W,D as we,I as Ye,x as Xe,y as Te,z as Pe,A as Ze,C as $e,F as ke,G as et,R as _e,M as ae,H as tt,J as rt,k as Ke,d as Oe,K as nt,L as at,O as Re,j as it,P as ot,l as st,q as ut,S as ct}from"./index-browser.es2.js";import{i as ge,m as Le,d as ft,w as le,b as ie,l as vt,t as lt,a as dt,e as _t}from"./index.es3.js";var de={},Ce;function gt(){if(Ce)return de;Ce=1,de.stringify=function(r){var t=[];t.push({obj:r});for(var a="",c,o,d,g,m,S,A,C,D,R,q;c=t.pop();)if(o=c.obj,d=c.prefix||"",g=c.val||"",a+=d,g)a+=g;else if(typeof o!="object")a+=typeof o>"u"?null:JSON.stringify(o);else if(o===null)a+="null";else if(Array.isArray(o)){for(t.push({val:"]"}),m=o.length-1;m>=0;m--)S=m===0?"":",",t.push({obj:o[m],prefix:S});t.push({val:"["})}else{A=[];for(C in o)o.hasOwnProperty(C)&&A.push(C);for(t.push({val:"}"}),m=A.length-1;m>=0;m--)D=A[m],R=o[D],q=m>0?",":"",q+=JSON.stringify(D)+":",t.push({obj:R,prefix:q});t.push({val:"{"})}return a};function e(n,r,t){var a=t[t.length-1];n===a.element&&(t.pop(),a=t[t.length-1]);var c=a.element,o=a.index;if(Array.isArray(c))c.push(n);else if(o===r.length-2){var d=r.pop();c[d]=n}else r.push(n)}return de.parse=function(n){for(var r=[],t=[],a=0,c,o,d,g,m,S,A,C,D;;){if(c=n[a++],c==="}"||c==="]"||typeof c>"u"){if(r.length===1)return r.pop();e(r.pop(),r,t);continue}switch(c){case" ":case" ":case`
2
2
  `:case":":case",":break;case"n":a+=3,e(null,r,t);break;case"t":a+=3,e(!0,r,t);break;case"f":a+=4,e(!1,r,t);break;case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":case"-":for(o="",a--;;)if(d=n[a++],/[\d\.\-e\+]/.test(d))o+=d;else{a--;break}e(parseFloat(o),r,t);break;case'"':for(g="",m=void 0,S=0;A=n[a++],A!=='"'||m==="\\"&&S%2===1;)g+=A,m=A,m==="\\"?S++:S=0;e(JSON.parse('"'+g+'"'),r,t);break;case"[":C={element:[],index:r.length},r.push(C.element),t.push(C);break;case"{":D={element:{},index:r.length},r.push(D.element),t.push(D);break;default:throw new Error("unexpectedly reached end of input: "+c)}}},de}var ht=gt();const Me=Qe(ht);function mt(e){try{return JSON.parse(e)}catch{return Me.parse(e)}}function pt(e){try{return JSON.stringify(e)}catch{return Me.stringify(e)}}function yt(e,n,r){return new Promise(function(t){var a=je([""]);let c;{const o=r;c=e.objectStore(n).put(a,o)}c.onsuccess=function(){var o=navigator.userAgent.match(/Chrome\/(\d+)/),d=navigator.userAgent.match(/Edge\//);t(d||!o||parseInt(o[1],10)>=43)},c.onerror=e.onabort=function(o){o.preventDefault(),o.stopPropagation(),t(!1)}}).catch(function(){return!1})}function Ie(e){return e.reduce(function(n,r){return n[r]=!0,n},{})}var St=Ie(["_id","_rev","_access","_attachments","_deleted","_revisions","_revs_info","_conflicts","_deleted_conflicts","_local_seq","_rev_tree","_replication_id","_replication_state","_replication_state_time","_replication_state_reason","_replication_stats","_removed"]),Dt=Ie(["_access","_attachments","_replication_id","_replication_state","_replication_state_time","_replication_state_reason","_replication_stats"]);function Be(e){if(!/^\d+-/.test(e))return W(Ye);var n=e.indexOf("-"),r=e.substring(0,n),t=e.substring(n+1);return{prefix:parseInt(r,10),id:t}}function xt(e,n){for(var r=e.start-e.ids.length+1,t=e.ids,a=[t[0],n,[]],c=1,o=t.length;c<o;c++)a=[t[c],{status:"missing"},[a]];return[{pos:r,ids:a}]}function Ne(e,n,r){r||(r={deterministic_revs:!0});var t,a,c,o={status:"available"};if(e._deleted&&(o.deleted=!0),n)if(e._id||(e._id=Ae()),a=ze(e,r.deterministic_revs),e._rev){if(c=Be(e._rev),c.error)return c;e._rev_tree=[{pos:c.prefix,ids:[c.id,{status:"missing"},[[a,o,[]]]]}],t=c.prefix+1}else e._rev_tree=[{pos:1,ids:[a,o,[]]}],t=1;else if(e._revisions&&(e._rev_tree=xt(e._revisions,o),t=e._revisions.start,a=e._revisions.ids[0]),!e._rev_tree){if(c=Be(e._rev),c.error)return c;t=c.prefix,a=c.id,e._rev_tree=[{pos:t,ids:[a,o,[]]}]}Ue(e._id),e._rev=t+"-"+a;var d={metadata:{},data:{}};for(var g in e)if(Object.prototype.hasOwnProperty.call(e,g)){var m=g[0]==="_";if(m&&!St[g]){var S=W(we,g);throw S.message=we.message+": "+g,S}else m&&!Dt[g]?d.metadata[g.slice(1)]=e[g]:d.data[g]=e[g]}return d}function qt(e){try{return Ze(e)}catch{var n=W($e,"Attachment is not a valid base64 string");return{error:n}}}function bt(e,n,r){var t=qt(e.data);if(t.error)return r(t.error);e.length=t.length,n==="blob"?e.data=Xe(t,e.content_type):n==="base64"?e.data=Te(t):e.data=t,Pe(t,function(a){e.digest="md5-"+a,r()})}function At(e,n,r){Pe(e.data,function(t){e.digest="md5-"+t,e.length=e.data.size||e.data.length||0,n==="binary"?ke(e.data,function(a){e.data=a,r()}):n==="base64"?et(e.data,function(a){e.data=a,r()}):r()})}function Rt(e,n,r){if(e.stub)return r();typeof e.data=="string"?bt(e,n,r):At(e,n,r)}function wt(e,n,r){if(!e.length)return r();var t=0,a;e.forEach(function(o){var d=o.data&&o.data._attachments?Object.keys(o.data._attachments):[],g=0;if(!d.length)return c();function m(A){a=A,g++,g===d.length&&c()}for(var S in o.data._attachments)Object.prototype.hasOwnProperty.call(o.data._attachments,S)&&Rt(o.data._attachments[S],n,m)});function c(){t++,e.length===t&&(a?r(a):r())}}function Ot(e,n,r,t,a,c,o,d){if(ft(n.rev_tree,r.metadata.rev)&&!d)return t[a]=r,c();var g=n.winningRev||le(n),m="deleted"in n?n.deleted:ie(n,g),S="deleted"in r.metadata?r.metadata.deleted:ie(r.metadata),A=/^1-/.test(r.metadata.rev);if(m&&!S&&d&&A){var C=r.data;C._rev=g,C._id=r.metadata.id,r=Ne(C,d)}var D=Le(n.rev_tree,r.metadata.rev_tree[0],e),R=d&&(m&&S&&D.conflicts!=="new_leaf"||!m&&D.conflicts!=="new_leaf"||m&&!S&&D.conflicts==="new_branch");if(R){var q=W(_e);return t[a]=q,c()}var s=r.metadata.rev;r.metadata.rev_tree=D.tree,r.stemmedRevs=D.stemmedRevs||[],n.rev_map&&(r.metadata.rev_map=n.rev_map);var i=le(r.metadata),u=ie(r.metadata,i),v=m===u?0:m<u?-1:1,l;s===i?l=u:l=ie(r.metadata,s),o(r,i,u,l,!0,v,a,c)}function Ct(e){return e.metadata.rev_tree[0].ids[1].status==="missing"}function Bt(e,n,r,t,a,c,o,d,g){e=e||1e3;function m(q,s,i){var u=le(q.metadata),v=ie(q.metadata,u);if("was_delete"in d&&v)return c[s]=W(ae,"deleted"),i();var l=S&&Ct(q);if(l){var f=W(_e);return c[s]=f,i()}var _=v?0:1;o(q,u,v,v,!1,_,s,i)}var S=d.new_edits,A=new Map,C=0,D=n.length;function R(){++C===D&&g&&g()}n.forEach(function(q,s){if(q._id&&ge(q._id)){var i=q._deleted?"_removeLocal":"_putLocal";r[i](q,{ctx:a},function(v,l){c[s]=v||l,R()});return}var u=q.metadata.id;A.has(u)?(D--,A.get(u).push([q,s])):A.set(u,[[q,s]])}),A.forEach(function(q,s){var i=0;function u(){++i<q.length?v():R()}function v(){var l=q[i],f=l[0],_=l[1];if(t.has(s))Ot(e,t.get(s),f,c,_,u,o,S);else{var p=Le([],f.metadata.rev_tree[0],e);f.metadata.rev_tree=p.tree,f.stemmedRevs=p.stemmedRevs||[],m(f,_,u)}}v()})}var Et=5,V="document-store",Q="by-sequence",Y="attach-store",oe="attach-seq-store",U="meta-store",$="local-store",pe="detect-blob-support";function k(e){return function(n){var r="unknown_error";n.target&&n.target.error&&(r=n.target.error.name||n.target.error.message),e(W(Re,r,n.type))}}function De(e,n,r){return{data:pt(e),winningRev:n,deletedOrLocal:r?"1":"0",seq:e.seq,id:e.id}}function se(e){if(!e)return null;var n=mt(e.data);return n.winningRev=e.winningRev,n.deleted=e.deletedOrLocal==="1",n.seq=e.seq,n}function he(e){if(!e)return e;var n=e._doc_id_rev.lastIndexOf(":");return e._id=e._doc_id_rev.substring(0,n-1),e._rev=e._doc_id_rev.substring(n+1),delete e._doc_id_rev,e}function Ge(e,n,r,t){r?t(e?typeof e!="string"?e:nt(e,n):je([""],{type:n})):e?typeof e!="string"?at(e,function(a){t(Te(a))}):t(e):t("")}function Ve(e,n,r,t){var a=Object.keys(e._attachments||{});if(!a.length)return t&&t();var c=0;function o(){++c===a.length&&t&&t()}function d(g,m){var S=g._attachments[m],A=S.digest,C=r.objectStore(Y).get(A);C.onsuccess=function(D){S.body=D.target.result.body,o()}}a.forEach(function(g){n.attachments&&n.include_docs?d(e,g):(e._attachments[g].stub=!0,o())})}function xe(e,n){return Promise.all(e.map(function(r){if(r.doc&&r.doc._attachments){var t=Object.keys(r.doc._attachments);return Promise.all(t.map(function(a){var c=r.doc._attachments[a];if("body"in c){var o=c.body,d=c.content_type;return new Promise(function(g){Ge(o,d,n,function(m){r.doc._attachments[a]=Object.assign(st(c,["digest","content_type"]),{data:m}),g()})})}}))}}))}function Fe(e,n,r){var t=[],a=r.objectStore(Q),c=r.objectStore(Y),o=r.objectStore(oe),d=e.length;function g(){d--,d||m()}function m(){t.length&&t.forEach(function(S){var A=o.index("digestSeq").count(IDBKeyRange.bound(S+"::",S+"::￿",!1,!1));A.onsuccess=function(C){var D=C.target.result;D||c.delete(S)}})}e.forEach(function(S){var A=a.index("_doc_id_rev"),C=n+"::"+S;A.getKey(C).onsuccess=function(D){var R=D.target.result;if(typeof R!="number")return g();a.delete(R);var q=o.index("seq").openCursor(IDBKeyRange.only(R));q.onsuccess=function(s){var i=s.target.result;if(i){var u=i.value.digestSeq.split("::")[0];t.push(u),o.delete(i.primaryKey),i.continue()}else g()}}})}function X(e,n,r){try{return{txn:e.transaction(n,r)}}catch(t){return{error:t}}}var ve=new rt;function jt(e,n,r,t,a,c){for(var o=n.docs,d,g,m,S,A,C,D,R,q=0,s=o.length;q<s;q++){var i=o[q];i._id&&ge(i._id)||(i=o[q]=Ne(i,r.new_edits,e),i.error&&!D&&(D=i))}if(D)return c(D);var u=!1,v=0,l=new Array(o.length),f=new Map,_=!1,p=t._meta.blobSupport?"blob":"base64";wt(o,p,function(x){if(x)return c(x);y()});function y(){var x=[V,Q,Y,$,oe,U],E=X(a,x,"readwrite");if(E.error)return c(E.error);d=E.txn,d.onabort=k(c),d.ontimeout=k(c),d.oncomplete=B,g=d.objectStore(V),m=d.objectStore(Q),S=d.objectStore(Y),A=d.objectStore(oe),C=d.objectStore(U),C.get(U).onsuccess=function(K){R=K.target.result,O()},j(function(K){if(K)return _=!0,c(K);M()})}function h(){u=!0,O()}function w(){Bt(e.revs_limit,o,t,f,d,l,T,r,h)}function O(){!R||!u||(R.docCount+=v,C.put(R))}function M(){if(!o.length)return;var x=0;function E(){++x===o.length&&w()}function K(L){var H=se(L.target.result);H&&f.set(H.id,H),E()}for(var F=0,G=o.length;F<G;F++){var N=o[F];if(N._id&&ge(N._id)){E();continue}var I=g.get(N.metadata.id);I.onsuccess=K}}function B(){_||(ve.notify(t._meta.name),c(null,l))}function b(x,E){var K=S.get(x);K.onsuccess=function(F){if(F.target.result)E();else{var G=W(ct,"unknown stub attachment with digest "+x);G.status=412,E(G)}}}function j(x){var E=[];if(o.forEach(function(N){N.data&&N.data._attachments&&Object.keys(N.data._attachments).forEach(function(I){var L=N.data._attachments[I];L.stub&&E.push(L.digest)})}),!E.length)return x();var K=0,F;function G(){++K===E.length&&x(F)}E.forEach(function(N){b(N,function(I){I&&!F&&(F=I),G()})})}function T(x,E,K,F,G,N,I,L){x.metadata.winningRev=E,x.metadata.deleted=K;var H=x.data;H._id=x.metadata.id,H._rev=x.metadata.rev,F&&(H._deleted=!0);var te=H._attachments&&Object.keys(H._attachments).length;if(te)return J(x,E,K,G,I,L);v+=N,O(),P(x,E,K,G,I,L)}function P(x,E,K,F,G,N){var I=x.data,L=x.metadata;I._doc_id_rev=L.id+"::"+L.rev,delete I._id,delete I._rev;function H(Z){var ee=x.stemmedRevs||[];F&&t.auto_compaction&&(ee=ee.concat(_t(x.metadata))),ee&&ee.length&&Fe(ee,x.metadata.id,d),L.seq=Z.target.result;var fe=De(L,E,K),me=g.put(fe);me.onsuccess=ue}function te(Z){Z.preventDefault(),Z.stopPropagation();var ee=m.index("_doc_id_rev"),fe=ee.getKey(I._doc_id_rev);fe.onsuccess=function(me){var He=m.put(I,me.target.result);He.onsuccess=H}}function ue(){l[G]={ok:!0,id:L.id,rev:L.rev},f.set(x.metadata.id,x.metadata),z(x,L.seq,N)}var ne=m.put(I);ne.onsuccess=H,ne.onerror=te}function J(x,E,K,F,G,N){var I=x.data,L=0,H=Object.keys(I._attachments);function te(){L===H.length&&P(x,E,K,F,G,N)}function ue(){L++,te()}H.forEach(function(ne){var Z=x.data._attachments[ne];if(Z.stub)L++,te();else{var ee=Z.data;delete Z.data,Z.revpos=parseInt(E,10);var fe=Z.digest;re(fe,ee,ue)}})}function z(x,E,K){var F=0,G=Object.keys(x.data._attachments||{});if(!G.length)return K();function N(){++F===G.length&&K()}function I(H){var te=x.data._attachments[H].digest,ue=A.put({seq:E,digestSeq:te+"::"+E});ue.onsuccess=N,ue.onerror=function(ne){ne.preventDefault(),ne.stopPropagation(),N()}}for(var L=0;L<G.length;L++)I(G[L])}function re(x,E,K){var F=S.count(x);F.onsuccess=function(G){var N=G.target.result;if(N)return K();var I={digest:x,body:E},L=S.put(I);L.onsuccess=K}}}function Je(e,n,r,t,a){t===-1&&(t=1e3);var c=typeof e.getAll=="function"&&typeof e.getAllKeys=="function"&&t>1&&!r,o,d,g;function m(D){d=D.target.result,o&&a(o,d,g)}function S(D){o=D.target.result,d&&a(o,d,g)}function A(){if(!o.length)return a();var D=o[o.length-1],R;if(n&&n.upper)try{R=IDBKeyRange.bound(D,n.upper,!0,n.upperOpen)}catch(q){if(q.name==="DataError"&&q.code===0)return a()}else R=IDBKeyRange.lowerBound(D,!0);n=R,o=null,d=null,e.getAll(n,t).onsuccess=m,e.getAllKeys(n,t).onsuccess=S}function C(D){var R=D.target.result;if(!R)return a();a([R.key],[R.value],R)}c?(g={continue:A},e.getAll(n,t).onsuccess=m,e.getAllKeys(n,t).onsuccess=S):r?e.openCursor(n,"prev").onsuccess=C:e.openCursor(n).onsuccess=C}function Tt(e,n,r){if(typeof e.getAll=="function"){e.getAll(n).onsuccess=r;return}var t=[];function a(c){var o=c.target.result;o?(t.push(o.value),o.continue()):r({target:{result:t}})}e.openCursor(n).onsuccess=a}function Pt(e,n,r){var t=new Array(e.length),a=0;e.forEach(function(c,o){n.get(c).onsuccess=function(d){d.target.result?t[o]=d.target.result:t[o]={key:c,error:"not_found"},a++,a===e.length&&r(e,t,{})}})}function Kt(e,n,r,t,a){try{if(e&&n)return a?IDBKeyRange.bound(n,e,!r,!1):IDBKeyRange.bound(e,n,!1,!r);if(e)return a?IDBKeyRange.upperBound(e):IDBKeyRange.lowerBound(e);if(n)return a?IDBKeyRange.lowerBound(n,!r):IDBKeyRange.upperBound(n,!r);if(t)return IDBKeyRange.only(t)}catch(c){return{error:c}}return null}function Lt(e,n,r){var t="startkey"in e?e.startkey:!1,a="endkey"in e?e.endkey:!1,c="key"in e?e.key:!1,o="keys"in e?e.keys:!1,d=e.skip||0,g=typeof e.limit=="number"?e.limit:-1,m=e.inclusive_end!==!1,S,A;if(!o&&(S=Kt(t,a,m,c,e.descending),A=S&&S.error,A&&!(A.name==="DataError"&&A.code===0)))return r(W(Re,A.name,A.message));var C=[V,Q,U];e.attachments&&C.push(Y);var D=X(n,C,"readonly");if(D.error)return r(D.error);var R=D.txn;R.oncomplete=M,R.onabort=k(r);var q=R.objectStore(V),s=R.objectStore(Q),i=R.objectStore(U),u=s.index("_doc_id_rev"),v=[],l,f;i.get(U).onsuccess=function(B){l=B.target.result.docCount},e.update_seq&&(s.openKeyCursor(null,"prev").onsuccess=B=>{var b=B.target.result;b&&b.key&&(f=b.key)});function _(B,b,j){var T=B.id+"::"+j;u.get(T).onsuccess=function(J){if(b.doc=he(J.target.result)||{},e.conflicts){var z=dt(B);z.length&&(b.doc._conflicts=z)}Ve(b.doc,e,R)}}function p(B,b){var j={id:b.id,key:b.id,value:{rev:B}},T=b.deleted;T?o&&(v.push(j),j.value.deleted=!0,j.doc=null):d--<=0&&(v.push(j),e.include_docs&&_(b,j,B))}function y(B){for(var b=0,j=B.length;b<j&&v.length!==g;b++){var T=B[b];if(T.error&&o){v.push(T);continue}var P=se(T),J=P.winningRev;p(J,P)}}function h(B,b,j){j&&(y(b),v.length<g&&j.continue())}function w(B){var b=B.target.result;e.descending&&(b=b.reverse()),y(b)}function O(){var B={total_rows:l,offset:e.skip,rows:v};e.update_seq&&f!==void 0&&(B.update_seq=f),r(null,B)}function M(){e.attachments?xe(v,e.binary).then(O):O()}if(!(A||g===0)){if(o)return Pt(o,q,h);if(g===-1)return Tt(q,S,w);Je(q,S,e.descending,g+d,h)}}function Mt(e,n){var r=e.objectStore(V).index("deletedOrLocal");r.count(IDBKeyRange.only("0")).onsuccess=function(t){n(t.target.result)}}var qe=!1,be=[];function It(e,n,r,t){try{e(n,r)}catch(a){t.emit("error",a)}}function Ee(){qe||!be.length||(qe=!0,be.shift()())}function Nt(e,n,r){be.push(function(){e(function(c,o){It(n,c,o,r),qe=!1,Ke(function(){Ee()})})}),Ee()}function Gt(e,n,r,t){if(e=it(e),e.continuous){var a=r+":"+Ae();return ve.addListener(r,a,n,e),ve.notify(r),{cancel:function(){ve.removeListener(r,a)}}}var c=e.doc_ids&&new Set(e.doc_ids);e.since=e.since||0;var o=e.since,d="limit"in e?e.limit:-1;d===0&&(d=1);var g=[],m=0,S=ot(e),A=new Map,C,D,R,q;function s(y,h,w){if(!w||!y.length)return;var O=new Array(y.length),M=new Array(y.length);function B(T,P){var J=e.processChange(P,T,e);o=J.seq=T.seq;var z=S(J);return typeof z=="object"?Promise.reject(z):z?(m++,e.return_docs&&g.push(J),e.attachments&&e.include_docs?new Promise(function(re){Ve(P,e,C,function(){xe([J],e.binary).then(function(){re(J)})})}):Promise.resolve(J)):Promise.resolve()}function b(){for(var T=[],P=0,J=O.length;P<J&&m!==d;P++){var z=O[P];if(z){var re=M[P];T.push(B(re,z))}}Promise.all(T).then(function(x){for(var E=0,K=x.length;E<K;E++)x[E]&&e.onChange(x[E])}).catch(e.complete),m!==d&&w.continue()}var j=0;h.forEach(function(T,P){var J=he(T),z=y[P];u(J,z,function(re,x){M[P]=re,O[P]=x,++j===y.length&&b()})})}function i(y,h,w,O){if(w.seq!==h)return O();if(w.winningRev===y._rev)return O(w,y);var M=y._id+"::"+w.winningRev,B=q.get(M);B.onsuccess=function(b){O(w,he(b.target.result))}}function u(y,h,w){if(c&&!c.has(y._id))return w();var O=A.get(y._id);if(O)return i(y,h,O,w);R.get(y._id).onsuccess=function(M){O=se(M.target.result),A.set(y._id,O),i(y,h,O,w)}}function v(){e.complete(null,{results:g,last_seq:o})}function l(){!e.continuous&&e.attachments?xe(g).then(v):v()}var f=[V,Q];e.attachments&&f.push(Y);var _=X(t,f,"readonly");if(_.error)return e.complete(_.error);C=_.txn,C.onabort=k(e.complete),C.oncomplete=l,D=C.objectStore(Q),R=C.objectStore(V),q=D.index("_doc_id_rev");var p=e.since&&!e.descending?IDBKeyRange.lowerBound(e.since,!0):null;Je(D,p,e.descending,d,s)}var ce=new Map,ye,Se=new Map;function We(e,n){var r=this;Nt(function(t){Vt(r,e,t)},n,r.constructor)}function Vt(e,n,r){var t=n.name,a=null,c=null;e._meta=null;function o(s){return function(i,u){i&&i instanceof Error&&!i.reason&&c&&(i.reason=c),s(i,u)}}function d(s){var i=s.createObjectStore(V,{keyPath:"id"});s.createObjectStore(Q,{autoIncrement:!0}).createIndex("_doc_id_rev","_doc_id_rev",{unique:!0}),s.createObjectStore(Y,{keyPath:"digest"}),s.createObjectStore(U,{keyPath:"id",autoIncrement:!1}),s.createObjectStore(pe),i.createIndex("deletedOrLocal","deletedOrLocal",{unique:!1}),s.createObjectStore($,{keyPath:"_id"});var u=s.createObjectStore(oe,{autoIncrement:!0});u.createIndex("seq","seq"),u.createIndex("digestSeq","digestSeq",{unique:!0})}function g(s,i){var u=s.objectStore(V);u.createIndex("deletedOrLocal","deletedOrLocal",{unique:!1}),u.openCursor().onsuccess=function(v){var l=v.target.result;if(l){var f=l.value,_=ie(f);f.deletedOrLocal=_?"1":"0",u.put(f),l.continue()}else i()}}function m(s){s.createObjectStore($,{keyPath:"_id"}).createIndex("_doc_id_rev","_doc_id_rev",{unique:!0})}function S(s,i){var u=s.objectStore($),v=s.objectStore(V),l=s.objectStore(Q),f=v.openCursor();f.onsuccess=function(_){var p=_.target.result;if(p){var y=p.value,h=y.id,w=ge(h),O=le(y);if(w){var M=h+"::"+O,B=h+"::",b=h+"::~",j=l.index("_doc_id_rev"),T=IDBKeyRange.bound(B,b,!1,!1),P=j.openCursor(T);P.onsuccess=function(J){if(P=J.target.result,!P)v.delete(p.primaryKey),p.continue();else{var z=P.value;z._doc_id_rev===M&&u.put(z),l.delete(P.primaryKey),P.continue()}}}else p.continue()}else i&&i()}}function A(s){var i=s.createObjectStore(oe,{autoIncrement:!0});i.createIndex("seq","seq"),i.createIndex("digestSeq","digestSeq",{unique:!0})}function C(s,i){var u=s.objectStore(Q),v=s.objectStore(Y),l=s.objectStore(oe),f=v.count();f.onsuccess=function(_){var p=_.target.result;if(!p)return i();u.openCursor().onsuccess=function(y){var h=y.target.result;if(!h)return i();for(var w=h.value,O=h.primaryKey,M=Object.keys(w._attachments||{}),B={},b=0;b<M.length;b++){var j=w._attachments[M[b]];B[j.digest]=!0}var T=Object.keys(B);for(b=0;b<T.length;b++){var P=T[b];l.put({seq:O,digestSeq:P+"::"+O})}h.continue()}}}function D(s){function i(f){return f.data?se(f):(f.deleted=f.deletedOrLocal==="1",f)}var u=s.objectStore(Q),v=s.objectStore(V),l=v.openCursor();l.onsuccess=function(f){var _=f.target.result;if(!_)return;var p=i(_.value);p.winningRev=p.winningRev||le(p);function y(){var w=p.id+"::",O=p.id+"::￿",M=u.index("_doc_id_rev").openCursor(IDBKeyRange.bound(w,O)),B=0;M.onsuccess=function(b){var j=b.target.result;if(!j)return p.seq=B,h();var T=j.primaryKey;T>B&&(B=T),j.continue()}}function h(){var w=De(p,p.winningRev,p.deleted),O=v.put(w);O.onsuccess=function(){_.continue()}}if(p.seq)return h();y()}}e._remote=!1,e.type=function(){return"idb"},e._id=tt(function(s){s(null,e._meta.instanceId)}),e._bulkDocs=function(i,u,v){jt(n,i,u,e,a,o(v))},e._get=function(i,u,v){var l,f,_,p=u.ctx;if(!p){var y=X(a,[V,Q,Y],"readonly");if(y.error)return v(y.error);p=y.txn}function h(){v(_,{doc:l,metadata:f,ctx:p})}p.objectStore(V).get(i).onsuccess=function(w){if(f=se(w.target.result),!f)return _=W(ae,"missing"),h();var O;if(u.rev)O=u.latest?vt(u.rev,f):u.rev;else{O=f.winningRev;var M=ie(f);if(M)return _=W(ae,"deleted"),h()}var B=p.objectStore(Q),b=f.id+"::"+O;B.index("_doc_id_rev").get(b).onsuccess=function(j){if(l=j.target.result,l&&(l=he(l)),!l)return _=W(ae,"missing"),h();h()}}},e._getAttachment=function(s,i,u,v,l){var f;if(v.ctx)f=v.ctx;else{var _=X(a,[V,Q,Y],"readonly");if(_.error)return l(_.error);f=_.txn}var p=u.digest,y=u.content_type;f.objectStore(Y).get(p).onsuccess=function(h){var w=h.target.result.body;Ge(w,y,v.binary,function(O){l(null,O)})}},e._info=function(i){var u,v,l=X(a,[U,Q],"readonly");if(l.error)return i(l.error);var f=l.txn;f.objectStore(U).get(U).onsuccess=function(_){v=_.target.result.docCount},f.objectStore(Q).openKeyCursor(null,"prev").onsuccess=function(_){var p=_.target.result;u=p?p.key:0},f.oncomplete=function(){i(null,{doc_count:v,update_seq:u,idb_attachment_format:e._meta.blobSupport?"binary":"base64"})}},e._allDocs=function(i,u){Lt(i,a,o(u))},e._changes=function(i){return Gt(i,e,t,a)},e._close=function(s){a.close(),ce.delete(t),s()},e._getRevisionTree=function(s,i){var u=X(a,[V],"readonly");if(u.error)return i(u.error);var v=u.txn,l=v.objectStore(V).get(s);l.onsuccess=function(f){var _=se(f.target.result);_?i(null,_.rev_tree):i(W(ae))}},e._doCompaction=function(s,i,u){var v=[V,Q,Y,oe],l=X(a,v,"readwrite");if(l.error)return u(l.error);var f=l.txn,_=f.objectStore(V);_.get(s).onsuccess=function(p){var y=se(p.target.result);lt(y.rev_tree,function(O,M,B,b,j){var T=M+"-"+B;i.indexOf(T)!==-1&&(j.status="missing")}),Fe(i,s,f);var h=y.winningRev,w=y.deleted;f.objectStore(V).put(De(y,h,w))},f.onabort=k(u),f.oncomplete=function(){u()}},e._getLocal=function(s,i){var u=X(a,[$],"readonly");if(u.error)return i(u.error);var v=u.txn,l=v.objectStore($).get(s);l.onerror=k(i),l.onsuccess=function(f){var _=f.target.result;_?(delete _._doc_id_rev,i(null,_)):i(W(ae))}},e._putLocal=function(s,i,u){typeof i=="function"&&(u=i,i={}),delete s._revisions;var v=s._rev,l=s._id;v?s._rev="0-"+(parseInt(v.split("-")[1],10)+1):s._rev="0-1";var f=i.ctx,_;if(!f){var p=X(a,[$],"readwrite");if(p.error)return u(p.error);f=p.txn,f.onerror=k(u),f.oncomplete=function(){_&&u(null,_)}}var y=f.objectStore($),h;v?(h=y.get(l),h.onsuccess=function(w){var O=w.target.result;if(!O||O._rev!==v)u(W(_e));else{var M=y.put(s);M.onsuccess=function(){_={ok:!0,id:s._id,rev:s._rev},i.ctx&&u(null,_)}}}):(h=y.add(s),h.onerror=function(w){u(W(_e)),w.preventDefault(),w.stopPropagation()},h.onsuccess=function(){_={ok:!0,id:s._id,rev:s._rev},i.ctx&&u(null,_)})},e._removeLocal=function(s,i,u){typeof i=="function"&&(u=i,i={});var v=i.ctx;if(!v){var l=X(a,[$],"readwrite");if(l.error)return u(l.error);v=l.txn,v.oncomplete=function(){f&&u(null,f)}}var f,_=s._id,p=v.objectStore($),y=p.get(_);y.onerror=k(u),y.onsuccess=function(h){var w=h.target.result;!w||w._rev!==s._rev?u(W(ae)):(p.delete(_),f={ok:!0,id:_,rev:"0-0"},i.ctx&&u(null,f))}},e._destroy=function(s,i){ve.removeAllListeners(t);var u=Se.get(t);u&&u.result&&(u.result.close(),ce.delete(t));var v=indexedDB.deleteDatabase(t);v.onsuccess=function(){Se.delete(t),ut()&&t in localStorage&&delete localStorage[t],i(null,{ok:!0})},v.onerror=k(i)};var R=ce.get(t);if(R)return a=R.idb,e._meta=R.global,Ke(function(){r(null,e)});var q=indexedDB.open(t,Et);Se.set(t,q),q.onupgradeneeded=function(s){var i=s.target.result;if(s.oldVersion<1)return d(i);var u=s.currentTarget.transaction;s.oldVersion<3&&m(i),s.oldVersion<4&&A(i);var v=[g,S,C,D],l=s.oldVersion;function f(){var _=v[l-1];l++,_&&_(u,f)}f()},q.onsuccess=function(s){a=s.target.result,a.onversionchange=function(){a.close(),ce.delete(t)},a.onabort=function(h){Oe("error","Database has a global failure",h.target.error),c=h.target.error,a.close(),ce.delete(t)};var i=a.transaction([U,pe,V],"readwrite"),u=!1,v,l,f,_;function p(){typeof f>"u"||!u||(e._meta={name:t,instanceId:_,blobSupport:f},ce.set(t,{idb:a,global:e._meta}),r(null,e))}function y(){if(!(typeof l>"u"||typeof v>"u")){var h=t+"_id";h in v?_=v[h]:v[h]=_=Ae(),v.docCount=l,i.objectStore(U).put(v)}}i.objectStore(U).get(U).onsuccess=function(h){v=h.target.result||{id:U},y()},Mt(i,function(h){l=h,y()}),ye||(ye=yt(i,pe,"key")),ye.then(function(h){f=h,p()}),i.oncomplete=function(){u=!0,p()},i.onabort=k(r)},q.onerror=function(s){var i=s.target.error&&s.target.error.message;i?i.indexOf("stored database is a higher version")!==-1&&(i=new Error('This DB was created with the newer "indexeddb" adapter, but you are trying to open it with the older "idb" adapter')):i="Failed to open indexedDB, are you in private browsing mode?",Oe("error",i),r(W(Re,i))}}We.valid=function(){try{return typeof indexedDB<"u"&&typeof IDBKeyRange<"u"}catch{return!1}};function Ht(e){e.adapter("idb",We,!0)}export{Ht as default};