snow-cms 1.1.4 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index-browser.es.js +2 -2
- package/dist/index-browser.es2.js +1 -1
- package/dist/index.css +1 -1
- package/dist/index.es.js +22 -22
- package/dist/index.es2.js +1 -1
- package/dist/index.es3.js +2 -2
- package/dist/index.es4.js +1 -1
- package/dist/index.es5.js +1 -1
- package/dist/index.es6.js +2 -2
- package/dist/index.es7.js +2 -2
- package/dist/index.es9.js +1 -1
- package/dist/index.js +39 -40
- package/package.json +14 -14
package/dist/index.es5.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{J,X as h,q as m,u as O,Z as $,x as b,y as K,O as l,L as f,z as L,r as N,B as j,S as E,C as V,N as d,E as X,G as R,Y as T,K as p,U as k,M as q,V as M,W as C,_ as S,$ as U,a0 as A,a1 as v,a2 as x,a3 as D,a4 as H}from"./index.es.js";import"./index.js";let I=a=>crypto.getRandomValues(new Uint8Array(a)),Q=(a,s,n)=>{let t=(2<<Math.log2(a.length-1))-1,e=-~(1.6*t*s/a.length);return(r=s)=>{let c="";for(;;){let i=n(e),o=e|0;for(;o--;)if(c+=a[i[o]&t]||"",c.length>=r)return c}}},W=(a,s=21)=>Q(a,s|0,I);const B=W("abcedfghicklmn",10);function y(a,s,n){const t=K(n||B());let e=!1;const r=c=>(c.record(t),c.update(s,i=>i.concat(t)),async()=>{const i=await a(c,r,()=>{c.done(t),e=!0});return e||c.done(t),()=>{c.update(s,o=>o.filter(u=>u!==t)),c.clearTimer(t),i==null||i()}});return r.timer=t,r}function P(a,s){const n=R(a),t=e=>async()=>{t.key=n,await e.wait(T);const r=s(e);return e.get(l).create(n,r),t.run=c=>e.get(l).call(a,c),()=>{e.get(l).remove(n)}};return t}function tt(a,s,n){const t=R(a);return y(async(e,r)=>{await e.wait(T);const c=await s(e);return e.get(l).create(t,c),r.run=i=>e.get(l).call(a,i),r.key=t,()=>{e.get(l).remove(t)}},D,n)}function et(a){const s=n=>async()=>{await n.wait(p);const t=a(n);return n.update(k,e=>[...e,t]),s.inputRule=t,()=>{n.update(k,e=>e.filter(r=>r!==t))}};return s}function at(a,s){return y(async(n,t)=>{await n.wait(p);const e=await a(n);return n.update(k,r=>[...r,e]),t.inputRule=e,()=>{n.update(k,r=>r.filter(c=>c!==e))}},S,s)}function F(a,s){const n=t=>async()=>{const e=s(t);return t.update($,r=>[...r.filter(c=>c[0]!==a),[a,e]]),n.id=a,n.schema=e,()=>{t.update($,r=>r.filter(([c])=>c!==a))}};return n.type=t=>{const e=t.get(m).marks[a];if(!e)throw b(a);return e},n}function nt(a,s,n){const t=y(async(e,r,c)=>{const i=await s(e);return e.update($,o=>[...o.filter(u=>u[0]!==a),[a,i]]),r.id=a,r.schema=i,c(),()=>{e.update($,o=>o.filter(([u])=>u!==a))}},C,n);return t.type=e=>{const r=e.get(m).marks[a];if(!r)throw b(a);return r},t}function G(a,s){const n=t=>async()=>{const e=s(t);return t.update(h,r=>[...r.filter(c=>c[0]!==a),[a,e]]),n.id=a,n.schema=e,()=>{t.update(h,r=>r.filter(([c])=>c!==a))}};return n.type=t=>{const e=t.get(m).nodes[a];if(!e)throw O(a);return e},n}function rt(a,s,n){const t=y(async(e,r,c)=>{const i=await s(e);return e.update(h,o=>[...o.filter(u=>u[0]!==a),[a,i]]),r.id=a,r.schema=i,c(),()=>{e.update(h,o=>o.filter(([u])=>u!==a))}},C,n);return t.type=e=>{const r=e.get(m).nodes[a];if(!r)throw O(a);return r},t}function st(a){let s;const n=t=>async()=>(await t.wait(p),s=a(t),t.update(d,e=>[...e,s]),()=>{t.update(d,e=>e.filter(r=>r!==s))});return n.plugin=()=>s,n.key=()=>s.spec.key,n}function ct(a,s){let n;const t=y(async e=>(await e.wait(p),n=await a(e),e.update(d,r=>[...r,n]),()=>{e.update(d,r=>r.filter(c=>c!==n))}),S,s);return t.plugin=()=>n,t.key=()=>n.spec.key,t}function Y(a){const s=n=>async()=>{await n.wait(p);const t=a(n),e=U(t);return n.update(d,r=>[...r,e]),s.keymap=t,()=>{n.update(d,r=>r.filter(c=>c!==e))}};return s}function it(a,s){return y(async(n,t)=>{await n.wait(p);const e=await a(n),r=U(e);return n.update(d,c=>[...c,r]),t.keymap=e,()=>{n.update(d,c=>c.filter(i=>i!==r))}},S,s)}function ot(a,s){const n=t=>async()=>{await t.wait(p);const e=s(t);return a.type(t)instanceof A?t.update(v,r=>[...r,[a.id,e]]):t.update(x,r=>[...r,[a.id,e]]),n.view=e,n.type=a,()=>{a.type(t)instanceof A?t.update(v,r=>r.filter(c=>c[0]!==a.id)):t.update(x,r=>r.filter(c=>c[0]!==a.id))}};return n}function ut(a,s,n){return y(async(t,e)=>{await t.wait(p);const r=await s(t);return a.type(t)instanceof A?t.update(v,c=>[...c,[a.id,r]]):t.update(x,c=>[...c,[a.id,r]]),e.view=r,e.type=a,()=>{a.type(t)instanceof A?t.update(v,c=>c.filter(i=>i[0]!==a.id)):t.update(x,c=>c.filter(i=>i[0]!==a.id))}},H,n)}function g(a,s){const n=J(a,s),t=e=>(e.inject(n),()=>()=>{e.remove(n)});return t.key=n,t}function dt(a,s){const n=g(s,a),t=G(a,r=>r.get(n.key)(r)),e=[n,t];return e.id=t.id,e.node=t,e.type=r=>t.type(r),e.schema=t.schema,e.ctx=n,e.key=n.key,e.extendSchema=r=>c=>()=>{const i=c.get(n.key),o=r(i)(c);c.update(h,u=>[...u.filter(w=>w[0]!==a),[a,o]]),e.schema=o},e}function pt(a,s){const n=g(s,a),t=F(a,r=>r.get(n.key)(r)),e=[n,t];return e.id=t.id,e.mark=t,e.type=t.type,e.schema=t.schema,e.ctx=n,e.key=n.key,e.extendSchema=r=>c=>()=>{const i=c.get(n.key),o=r(i)(c);c.update($,u=>[...u.filter(w=>w[0]!==a),[a,o]]),e.schema=o},e}function lt(a,s){const n=Object.fromEntries(Object.entries(s).map(([c,{shortcuts:i}])=>[c,i])),t=g(n,`${a}Keymap`),e=Y(c=>{const i=c.get(t.key),o=Object.entries(s).flatMap(([u,{command:w}])=>[i[u]].flat().map(z=>[z,w(c)]));return Object.fromEntries(o)}),r=[t,e];return r.ctx=t,r.shortcuts=e,r.key=t.key,r.keymap=e.keymap,r}const ft=(a,s=()=>({}))=>g(s,`${a}Attr`),yt=(a,s=()=>({}))=>g(s,`${a}Attr`);function mt(a,s,n){const t=g(n??{},a),e=c=>async()=>{await c.wait(q);const i={plugin:s(c),options:c.get(t.key)};return c.update(M,o=>[...o,i]),()=>{c.update(M,o=>o.filter(u=>u!==i))}},r=[t,e];return r.id=a,r.plugin=e,r.options=t,r}function gt(a,s){return n=>n.get(l).call(a,s)}function wt(){return a=>{const s=a.get(f),{tr:n}=s.state,t=Object.assign(Object.create(n),n).setTime(Date.now());return s.dispatch(t)}}function ht(){return a=>{const s=document.createElement("div"),n=a.get(m),t=a.get(f),e=L.fromSchema(n).serializeFragment(t.state.doc.content);return s.appendChild(e),s.innerHTML}}function $t(){return a=>{const s=a.get(f);return a.get(N)(s.state.doc)}}function kt(a){return s=>{const n=s.get(f),t=s.get(j)(a);if(!t)return;const e=n.state.selection.content();return n.dispatch(n.state.tr.replaceSelection(new E(t.content,e.openStart,e.openEnd)).scrollIntoView())}}function At(){return a=>{const s=a.get(f),n=[];return s.state.doc.descendants(t=>{t.type.name==="heading"&&t.attrs.level&&n.push({text:t.textContent,level:t.attrs.level,id:t.attrs.id})}),n}}function vt(a,s=!1){return n=>{const t=n.get(f),e=n.get(j)(a);if(!e)return;if(!s){const{state:u}=t;return t.dispatch(u.tr.replace(0,u.doc.content.size,new E(e.content,0,0)))}const r=n.get(m),c=n.get(V),i=n.get(d),o=X.create({schema:r,doc:e,plugins:i,...c});t.updateState(o)}}function xt(a,s){return n=>{const t=n.get(f),{tr:e}=t.state,r=e.doc.nodeAt(a);if(!r)return;const c=s(r.attrs);return t.dispatch(e.setNodeMarkup(a,void 0,c))}}const St=(...a)=>{const s=a.length;let n=s;for(;n--;)if(typeof a[n]!="function")throw new TypeError("Expected a function");return(...t)=>{let e=0,r=s?a[e](...t):t[0];for(;++e<s;)r=a[e](r);return r}};export{P as $command,tt as $commandAsync,g as $ctx,et as $inputRule,at as $inputRuleAsync,F as $mark,nt as $markAsync,yt as $markAttr,pt as $markSchema,G as $node,rt as $nodeAsync,ft as $nodeAttr,dt as $nodeSchema,st as $prose,ct as $proseAsync,mt as $remark,Y as $shortcut,it as $shortcutAsync,lt as $useKeymap,ot as $view,ut as $viewAsync,y as addTimer,gt as callCommand,wt as forceUpdate,ht as getHTML,$t as getMarkdown,kt as insert,B as nanoid,At as outline,St as pipe,vt as replaceAll,xt as setAttr};
|
package/dist/index.es6.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.es8.js";import{
|
|
1
|
+
import{i as P,t as b,c as Z,a as H,b as $,r as fe,f as ce}from"./index.es8.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.es9.js";import"./index.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
|
-
`);return ee(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=G(n.view):n.filter=G(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=_(te,"`view` filter parameter not found or invalid.");return t(i)}var r=z(e.view);n.db.get("_design/"+r[0],function(s,f){if(n.isCancelled)return t(null,{status:"cancelled"});if(s)return t(W(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=z(e.filter);n.db.get("_design/"+a[0],function(s,f){if(n.isCancelled)return t(null,{status:"cancelled"});if(s)return t(W(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=he((f,u)=>{f?ve(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]=me(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(le(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=de();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 _(K);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(_(K));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){_e(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(_(ye));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(_(pe,"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(_(we));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(_(te,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)}J(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(()=>J(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=oe();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};
|
|
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.es7.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{t as
|
|
2
|
-
`:case":":case",":break;case"n":n+=3,ce(null,r,t);break;case"t":n+=3,ce(!0,r,t);break;case"f":n+=4,ce(!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(c="",n--;;)if(u=e[n++],/[\d\.\-e\+]/.test(u))c+=u;else{n--;break}ce(parseFloat(c),r,t);break;case'"':for(_="",d=void 0,D=0;p=e[n++],p!=='"'||d==="\\"&&D%2===1;)_+=p,d=p,d==="\\"?D++:D=0;ce(JSON.parse('"'+_+'"'),r,t);break;case"[":b={element:[],index:r.length},r.push(b.element),t.push(b);break;case"{":C={element:{},index:r.length},r.push(C.element),t.push(C);break;default:throw new Error("unexpectedly reached end of input: "+i)}}};function dt(e){try{return JSON.parse(e)}catch{return me.parse(e)}}function _t(e){try{return JSON.stringify(e)}catch{return me.stringify(e)}}function gt(e,r,t){return new Promise(function(n){var i=Ee([""]);let c;{const u=t;c=e.objectStore(r).put(i,u)}c.onsuccess=function(){var u=navigator.userAgent.match(/Chrome\/(\d+)/),_=navigator.userAgent.match(/Edge\//);n(_||!u||parseInt(u[1],10)>=43)},c.onerror=e.onabort=function(u){u.preventDefault(),u.stopPropagation(),n(!1)}}).catch(function(){return!1})}function Me(e){return e.reduce(function(r,t){return r[t]=!0,r},{})}var ht=Me(["_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"]),mt=Me(["_access","_attachments","_replication_id","_replication_state","_replication_state_time","_replication_state_reason","_replication_stats"]);function Be(e){if(!/^\d+-/.test(e))return W(Ue);var r=e.indexOf("-"),t=e.substring(0,r),n=e.substring(r+1);return{prefix:parseInt(t,10),id:n}}function pt(e,r){for(var t=e.start-e.ids.length+1,n=e.ids,i=[n[0],r,[]],c=1,u=n.length;c<u;c++)i=[n[c],{status:"missing"},[i]];return[{pos:t,ids:i}]}function Ie(e,r,t){t||(t={deterministic_revs:!0});var n,i,c,u={status:"available"};if(e._deleted&&(u.deleted=!0),r)if(e._id||(e._id=Re()),i=He(e,t.deterministic_revs),e._rev){if(c=Be(e._rev),c.error)return c;e._rev_tree=[{pos:c.prefix,ids:[c.id,{status:"missing"},[[i,u,[]]]]}],n=c.prefix+1}else e._rev_tree=[{pos:1,ids:[i,u,[]]}],n=1;else if(e._revisions&&(e._rev_tree=pt(e._revisions,u),n=e._revisions.start,i=e._revisions.ids[0]),!e._rev_tree){if(c=Be(e._rev),c.error)return c;n=c.prefix,i=c.id,e._rev_tree=[{pos:n,ids:[i,u,[]]}]}Qe(e._id),e._rev=n+"-"+i;var _={metadata:{},data:{}};for(var d in e)if(Object.prototype.hasOwnProperty.call(e,d)){var D=d[0]==="_";if(D&&!ht[d]){var p=W(Oe,d);throw p.message=Oe.message+": "+d,p}else D&&!mt[d]?_.metadata[d.slice(1)]=e[d]:_.data[d]=e[d]}return _}function yt(e){try{return Xe(e)}catch{var r=W(Ze,"Attachment is not a valid base64 string");return{error:r}}}function St(e,r,t){var n=yt(e.data);if(n.error)return t(n.error);e.length=n.length,r==="blob"?e.data=Ye(n,e.content_type):r==="base64"?e.data=Te(n):e.data=n,Pe(n,function(i){e.digest="md5-"+i,t()})}function Dt(e,r,t){Pe(e.data,function(n){e.digest="md5-"+n,e.length=e.data.size||e.data.length||0,r==="binary"?ze(e.data,function(i){e.data=i,t()}):r==="base64"?$e(e.data,function(i){e.data=i,t()}):t()})}function xt(e,r,t){if(e.stub)return t();typeof e.data=="string"?St(e,r,t):Dt(e,r,t)}function qt(e,r,t){if(!e.length)return t();var n=0,i;e.forEach(function(u){var _=u.data&&u.data._attachments?Object.keys(u.data._attachments):[],d=0;if(!_.length)return c();function D(b){i=b,d++,d===_.length&&c()}for(var p in u.data._attachments)Object.prototype.hasOwnProperty.call(u.data._attachments,p)&&xt(u.data._attachments[p],r,D)});function c(){n++,e.length===n&&(i?t(i):t())}}function bt(e,r,t,n,i,c,u,_){if(ut(r.rev_tree,t.metadata.rev)&&!_)return n[i]=t,c();var d=r.winningRev||de(r),D="deleted"in r?r.deleted:ie(r,d),p="deleted"in t.metadata?t.metadata.deleted:ie(t.metadata),b=/^1-/.test(t.metadata.rev);if(D&&!p&&_&&b){var C=t.data;C._rev=d,C._id=t.metadata.id,t=Ie(C,_)}var q=Le(r.rev_tree,t.metadata.rev_tree[0],e),A=_&&(D&&p&&q.conflicts!=="new_leaf"||!D&&q.conflicts!=="new_leaf"||D&&!p&&q.conflicts==="new_branch");if(A){var R=W(_e);return n[i]=R,c()}var o=t.metadata.rev;t.metadata.rev_tree=q.tree,t.stemmedRevs=q.stemmedRevs||[],r.rev_map&&(t.metadata.rev_map=r.rev_map);var a=de(t.metadata),s=ie(t.metadata,a),v=D===s?0:D<s?-1:1,l;o===a?l=s:l=ie(t.metadata,o),u(t,a,s,l,!0,v,i,c)}function At(e){return e.metadata.rev_tree[0].ids[1].status==="missing"}function Rt(e,r,t,n,i,c,u,_,d){e=e||1e3;function D(R,o,a){var s=de(R.metadata),v=ie(R.metadata,s);if("was_delete"in _&&v)return c[o]=W(ae,"deleted"),a();var l=p&&At(R);if(l){var f=W(_e);return c[o]=f,a()}var g=v?0:1;u(R,s,v,v,!1,g,o,a)}var p=_.new_edits,b=new Map,C=0,q=r.length;function A(){++C===q&&d&&d()}r.forEach(function(R,o){if(R._id&&ge(R._id)){var a=R._deleted?"_removeLocal":"_putLocal";t[a](R,{ctx:i},function(v,l){c[o]=v||l,A()});return}var s=R.metadata.id;b.has(s)?(q--,b.get(s).push([R,o])):b.set(s,[[R,o]])}),b.forEach(function(R,o){var a=0;function s(){++a<R.length?v():A()}function v(){var l=R[a],f=l[0],g=l[1];if(n.has(o))bt(e,n.get(o),f,c,g,s,u,p);else{var m=Le([],f.metadata.rev_tree[0],e);f.metadata.rev_tree=m.tree,f.stemmedRevs=m.stemmedRevs||[],D(f,g,s)}}v()})}var wt=5,J="document-store",Q="by-sequence",X="attach-store",oe="attach-seq-store",Y="meta-store",$="local-store",ye="detect-blob-support";function k(e){return function(r){var t="unknown_error";r.target&&r.target.error&&(t=r.target.error.name||r.target.error.message),e(W(we,t,r.type))}}function xe(e,r,t){return{data:_t(e),winningRev:r,deletedOrLocal:t?"1":"0",seq:e.seq,id:e.id}}function se(e){if(!e)return null;var r=dt(e.data);return r.winningRev=e.winningRev,r.deleted=e.deletedOrLocal==="1",r.seq=e.seq,r}function he(e){if(!e)return e;var r=e._doc_id_rev.lastIndexOf(":");return e._id=e._doc_id_rev.substring(0,r-1),e._rev=e._doc_id_rev.substring(r+1),delete e._doc_id_rev,e}function Ne(e,r,t,n){t?n(e?typeof e!="string"?e:rt(e,r):Ee([""],{type:r})):e?typeof e!="string"?nt(e,function(i){n(Te(i))}):n(e):n("")}function Ge(e,r,t,n){var i=Object.keys(e._attachments||{});if(!i.length)return n&&n();var c=0;function u(){++c===i.length&&n&&n()}function _(d,D){var p=d._attachments[D],b=p.digest,C=t.objectStore(X).get(b);C.onsuccess=function(q){p.body=q.target.result.body,u()}}i.forEach(function(d){r.attachments&&r.include_docs?_(e,d):(e._attachments[d].stub=!0,u())})}function qe(e,r){return Promise.all(e.map(function(t){if(t.doc&&t.doc._attachments){var n=Object.keys(t.doc._attachments);return Promise.all(n.map(function(i){var c=t.doc._attachments[i];if("body"in c){var u=c.body,_=c.content_type;return new Promise(function(d){Ne(u,_,r,function(D){t.doc._attachments[i]=Object.assign(ot(c,["digest","content_type"]),{data:D}),d()})})}}))}}))}function Je(e,r,t){var n=[],i=t.objectStore(Q),c=t.objectStore(X),u=t.objectStore(oe),_=e.length;function d(){_--,_||D()}function D(){n.length&&n.forEach(function(p){var b=u.index("digestSeq").count(IDBKeyRange.bound(p+"::",p+"::",!1,!1));b.onsuccess=function(C){var q=C.target.result;q||c.delete(p)}})}e.forEach(function(p){var b=i.index("_doc_id_rev"),C=r+"::"+p;b.getKey(C).onsuccess=function(q){var A=q.target.result;if(typeof A!="number")return d();i.delete(A);var R=u.index("seq").openCursor(IDBKeyRange.only(A));R.onsuccess=function(o){var a=o.target.result;if(a){var s=a.value.digestSeq.split("::")[0];n.push(s),u.delete(a.primaryKey),a.continue()}else d()}}})}function Z(e,r,t){try{return{txn:e.transaction(r,t)}}catch(n){return{error:n}}}var le=new ke;function Ot(e,r,t,n,i,c){for(var u=r.docs,_,d,D,p,b,C,q,A,R=0,o=u.length;R<o;R++){var a=u[R];a._id&&ge(a._id)||(a=u[R]=Ie(a,t.new_edits,e),a.error&&!q&&(q=a))}if(q)return c(q);var s=!1,v=0,l=new Array(u.length),f=new Map,g=!1,m=n._meta.blobSupport?"blob":"base64";qt(u,m,function(S){if(S)return c(S);y()});function y(){var S=[J,Q,X,$,oe,Y],j=Z(i,S,"readwrite");if(j.error)return c(j.error);_=j.txn,_.onabort=k(c),_.ontimeout=k(c),_.oncomplete=B,d=_.objectStore(J),D=_.objectStore(Q),p=_.objectStore(X),b=_.objectStore(oe),C=_.objectStore(Y),C.get(Y).onsuccess=function(K){A=K.target.result,O()},E(function(K){if(K)return g=!0,c(K);M()})}function h(){s=!0,O()}function w(){Rt(e.revs_limit,u,n,f,_,l,T,t,h)}function O(){!A||!s||(A.docCount+=v,C.put(A))}function M(){if(!u.length)return;var S=0;function j(){++S===u.length&&w()}function K(L){var H=se(L.target.result);H&&f.set(H.id,H),j()}for(var F=0,G=u.length;F<G;F++){var N=u[F];if(N._id&&ge(N._id)){j();continue}var I=d.get(N.metadata.id);I.onsuccess=K}}function B(){g||(le.notify(n._meta.name),c(null,l))}function x(S,j){var K=p.get(S);K.onsuccess=function(F){if(F.target.result)j();else{var G=W(st,"unknown stub attachment with digest "+S);G.status=412,j(G)}}}function E(S){var j=[];if(u.forEach(function(N){N.data&&N.data._attachments&&Object.keys(N.data._attachments).forEach(function(I){var L=N.data._attachments[I];L.stub&&j.push(L.digest)})}),!j.length)return S();var K=0,F;function G(){++K===j.length&&S(F)}j.forEach(function(N){x(N,function(I){I&&!F&&(F=I),G()})})}function T(S,j,K,F,G,N,I,L){S.metadata.winningRev=j,S.metadata.deleted=K;var H=S.data;H._id=S.metadata.id,H._rev=S.metadata.rev,F&&(H._deleted=!0);var te=H._attachments&&Object.keys(H._attachments).length;if(te)return V(S,j,K,G,I,L);v+=N,O(),P(S,j,K,G,I,L)}function P(S,j,K,F,G,N){var I=S.data,L=S.metadata;I._doc_id_rev=L.id+"::"+L.rev,delete I._id,delete I._rev;function H(z){var ee=S.stemmedRevs||[];F&&n.auto_compaction&&(ee=ee.concat(lt(S.metadata))),ee&&ee.length&&Je(ee,S.metadata.id,_),L.seq=z.target.result;var ve=xe(L,j,K),pe=d.put(ve);pe.onsuccess=ue}function te(z){z.preventDefault(),z.stopPropagation();var ee=D.index("_doc_id_rev"),ve=ee.getKey(I._doc_id_rev);ve.onsuccess=function(pe){var We=D.put(I,pe.target.result);We.onsuccess=H}}function ue(){l[G]={ok:!0,id:L.id,rev:L.rev},f.set(S.metadata.id,S.metadata),U(S,L.seq,N)}var ne=D.put(I);ne.onsuccess=H,ne.onerror=te}function V(S,j,K,F,G,N){var I=S.data,L=0,H=Object.keys(I._attachments);function te(){L===H.length&&P(S,j,K,F,G,N)}function ue(){L++,te()}H.forEach(function(ne){var z=S.data._attachments[ne];if(z.stub)L++,te();else{var ee=z.data;delete z.data,z.revpos=parseInt(j,10);var ve=z.digest;re(ve,ee,ue)}})}function U(S,j,K){var F=0,G=Object.keys(S.data._attachments||{});if(!G.length)return K();function N(){++F===G.length&&K()}function I(H){var te=S.data._attachments[H].digest,ue=b.put({seq:j,digestSeq:te+"::"+j});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(S,j,K){var F=p.count(S);F.onsuccess=function(G){var N=G.target.result;if(N)return K();var I={digest:S,body:j},L=p.put(I);L.onsuccess=K}}}function Fe(e,r,t,n,i){n===-1&&(n=1e3);var c=typeof e.getAll=="function"&&typeof e.getAllKeys=="function"&&n>1&&!t,u,_,d;function D(q){_=q.target.result,u&&i(u,_,d)}function p(q){u=q.target.result,_&&i(u,_,d)}function b(){if(!u.length)return i();var q=u[u.length-1],A;if(r&&r.upper)try{A=IDBKeyRange.bound(q,r.upper,!0,r.upperOpen)}catch(R){if(R.name==="DataError"&&R.code===0)return i()}else A=IDBKeyRange.lowerBound(q,!0);r=A,u=null,_=null,e.getAll(r,n).onsuccess=D,e.getAllKeys(r,n).onsuccess=p}function C(q){var A=q.target.result;if(!A)return i();i([A.key],[A.value],A)}c?(d={continue:b},e.getAll(r,n).onsuccess=D,e.getAllKeys(r,n).onsuccess=p):t?e.openCursor(r,"prev").onsuccess=C:e.openCursor(r).onsuccess=C}function Ct(e,r,t){if(typeof e.getAll=="function"){e.getAll(r).onsuccess=t;return}var n=[];function i(c){var u=c.target.result;u?(n.push(u.value),u.continue()):t({target:{result:n}})}e.openCursor(r).onsuccess=i}function Bt(e,r,t){var n=new Array(e.length),i=0;e.forEach(function(c,u){r.get(c).onsuccess=function(_){_.target.result?n[u]=_.target.result:n[u]={key:c,error:"not_found"},i++,i===e.length&&t(e,n,{})}})}function jt(e,r,t,n,i){try{if(e&&r)return i?IDBKeyRange.bound(r,e,!t,!1):IDBKeyRange.bound(e,r,!1,!t);if(e)return i?IDBKeyRange.upperBound(e):IDBKeyRange.lowerBound(e);if(r)return i?IDBKeyRange.lowerBound(r,!t):IDBKeyRange.upperBound(r,!t);if(n)return IDBKeyRange.only(n)}catch(c){return{error:c}}return null}function Et(e,r,t){var n="startkey"in e?e.startkey:!1,i="endkey"in e?e.endkey:!1,c="key"in e?e.key:!1,u="keys"in e?e.keys:!1,_=e.skip||0,d=typeof e.limit=="number"?e.limit:-1,D=e.inclusive_end!==!1,p,b;if(!u&&(p=jt(n,i,D,c,e.descending),b=p&&p.error,b&&!(b.name==="DataError"&&b.code===0)))return t(W(we,b.name,b.message));var C=[J,Q,Y];e.attachments&&C.push(X);var q=Z(r,C,"readonly");if(q.error)return t(q.error);var A=q.txn;A.oncomplete=M,A.onabort=k(t);var R=A.objectStore(J),o=A.objectStore(Q),a=A.objectStore(Y),s=o.index("_doc_id_rev"),v=[],l,f;a.get(Y).onsuccess=function(B){l=B.target.result.docCount},e.update_seq&&(o.openKeyCursor(null,"prev").onsuccess=B=>{var x=B.target.result;x&&x.key&&(f=x.key)});function g(B,x,E){var T=B.id+"::"+E;s.get(T).onsuccess=function(V){if(x.doc=he(V.target.result)||{},e.conflicts){var U=vt(B);U.length&&(x.doc._conflicts=U)}Ge(x.doc,e,A)}}function m(B,x){var E={id:x.id,key:x.id,value:{rev:B}},T=x.deleted;T?u&&(v.push(E),E.value.deleted=!0,E.doc=null):_--<=0&&(v.push(E),e.include_docs&&g(x,E,B))}function y(B){for(var x=0,E=B.length;x<E&&v.length!==d;x++){var T=B[x];if(T.error&&u){v.push(T);continue}var P=se(T),V=P.winningRev;m(V,P)}}function h(B,x,E){E&&(y(x),v.length<d&&E.continue())}function w(B){var x=B.target.result;e.descending&&(x=x.reverse()),y(x)}function O(){var B={total_rows:l,offset:e.skip,rows:v};e.update_seq&&f!==void 0&&(B.update_seq=f),t(null,B)}function M(){e.attachments?qe(v,e.binary).then(O):O()}if(!(b||d===0)){if(u)return Bt(u,R,h);if(d===-1)return Ct(R,p,w);Fe(R,p,e.descending,d+_,h)}}function Tt(e,r){var t=e.objectStore(J).index("deletedOrLocal");t.count(IDBKeyRange.only("0")).onsuccess=function(n){r(n.target.result)}}var be=!1,Ae=[];function Pt(e,r,t,n){try{e(r,t)}catch(i){n.emit("error",i)}}function je(){be||!Ae.length||(be=!0,Ae.shift()())}function Kt(e,r,t){Ae.push(function(){e(function(c,u){Pt(r,c,u,t),be=!1,Ke(function(){je()})})}),je()}function Lt(e,r,t,n){if(e=at(e),e.continuous){var i=t+":"+Re();return le.addListener(t,i,r,e),le.notify(t),{cancel:function(){le.removeListener(t,i)}}}var c=e.doc_ids&&new Set(e.doc_ids);e.since=e.since||0;var u=e.since,_="limit"in e?e.limit:-1;_===0&&(_=1);var d=[],D=0,p=it(e),b=new Map,C,q,A,R;function o(y,h,w){if(!w||!y.length)return;var O=new Array(y.length),M=new Array(y.length);function B(T,P){var V=e.processChange(P,T,e);u=V.seq=T.seq;var U=p(V);return typeof U=="object"?Promise.reject(U):U?(D++,e.return_docs&&d.push(V),e.attachments&&e.include_docs?new Promise(function(re){Ge(P,e,C,function(){qe([V],e.binary).then(function(){re(V)})})}):Promise.resolve(V)):Promise.resolve()}function x(){for(var T=[],P=0,V=O.length;P<V&&D!==_;P++){var U=O[P];if(U){var re=M[P];T.push(B(re,U))}}Promise.all(T).then(function(S){for(var j=0,K=S.length;j<K;j++)S[j]&&e.onChange(S[j])}).catch(e.complete),D!==_&&w.continue()}var E=0;h.forEach(function(T,P){var V=he(T),U=y[P];s(V,U,function(re,S){M[P]=re,O[P]=S,++E===y.length&&x()})})}function a(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=R.get(M);B.onsuccess=function(x){O(w,he(x.target.result))}}function s(y,h,w){if(c&&!c.has(y._id))return w();var O=b.get(y._id);if(O)return a(y,h,O,w);A.get(y._id).onsuccess=function(M){O=se(M.target.result),b.set(y._id,O),a(y,h,O,w)}}function v(){e.complete(null,{results:d,last_seq:u})}function l(){!e.continuous&&e.attachments?qe(d).then(v):v()}var f=[J,Q];e.attachments&&f.push(X);var g=Z(n,f,"readonly");if(g.error)return e.complete(g.error);C=g.txn,C.onabort=k(e.complete),C.oncomplete=l,q=C.objectStore(Q),A=C.objectStore(J),R=q.index("_doc_id_rev");var m=e.since&&!e.descending?IDBKeyRange.lowerBound(e.since,!0):null;Fe(q,m,e.descending,_,o)}var fe=new Map,Se,De=new Map;function Ve(e,r){var t=this;Kt(function(n){Mt(t,e,n)},r,t.constructor)}function Mt(e,r,t){var n=r.name,i=null,c=null;e._meta=null;function u(o){return function(a,s){a&&a instanceof Error&&!a.reason&&c&&(a.reason=c),o(a,s)}}function _(o){var a=o.createObjectStore(J,{keyPath:"id"});o.createObjectStore(Q,{autoIncrement:!0}).createIndex("_doc_id_rev","_doc_id_rev",{unique:!0}),o.createObjectStore(X,{keyPath:"digest"}),o.createObjectStore(Y,{keyPath:"id",autoIncrement:!1}),o.createObjectStore(ye),a.createIndex("deletedOrLocal","deletedOrLocal",{unique:!1}),o.createObjectStore($,{keyPath:"_id"});var s=o.createObjectStore(oe,{autoIncrement:!0});s.createIndex("seq","seq"),s.createIndex("digestSeq","digestSeq",{unique:!0})}function d(o,a){var s=o.objectStore(J);s.createIndex("deletedOrLocal","deletedOrLocal",{unique:!1}),s.openCursor().onsuccess=function(v){var l=v.target.result;if(l){var f=l.value,g=ie(f);f.deletedOrLocal=g?"1":"0",s.put(f),l.continue()}else a()}}function D(o){o.createObjectStore($,{keyPath:"_id"}).createIndex("_doc_id_rev","_doc_id_rev",{unique:!0})}function p(o,a){var s=o.objectStore($),v=o.objectStore(J),l=o.objectStore(Q),f=v.openCursor();f.onsuccess=function(g){var m=g.target.result;if(m){var y=m.value,h=y.id,w=ge(h),O=de(y);if(w){var M=h+"::"+O,B=h+"::",x=h+"::~",E=l.index("_doc_id_rev"),T=IDBKeyRange.bound(B,x,!1,!1),P=E.openCursor(T);P.onsuccess=function(V){if(P=V.target.result,!P)v.delete(m.primaryKey),m.continue();else{var U=P.value;U._doc_id_rev===M&&s.put(U),l.delete(P.primaryKey),P.continue()}}}else m.continue()}else a&&a()}}function b(o){var a=o.createObjectStore(oe,{autoIncrement:!0});a.createIndex("seq","seq"),a.createIndex("digestSeq","digestSeq",{unique:!0})}function C(o,a){var s=o.objectStore(Q),v=o.objectStore(X),l=o.objectStore(oe),f=v.count();f.onsuccess=function(g){var m=g.target.result;if(!m)return a();s.openCursor().onsuccess=function(y){var h=y.target.result;if(!h)return a();for(var w=h.value,O=h.primaryKey,M=Object.keys(w._attachments||{}),B={},x=0;x<M.length;x++){var E=w._attachments[M[x]];B[E.digest]=!0}var T=Object.keys(B);for(x=0;x<T.length;x++){var P=T[x];l.put({seq:O,digestSeq:P+"::"+O})}h.continue()}}}function q(o){function a(f){return f.data?se(f):(f.deleted=f.deletedOrLocal==="1",f)}var s=o.objectStore(Q),v=o.objectStore(J),l=v.openCursor();l.onsuccess=function(f){var g=f.target.result;if(!g)return;var m=a(g.value);m.winningRev=m.winningRev||de(m);function y(){var w=m.id+"::",O=m.id+"::",M=s.index("_doc_id_rev").openCursor(IDBKeyRange.bound(w,O)),B=0;M.onsuccess=function(x){var E=x.target.result;if(!E)return m.seq=B,h();var T=E.primaryKey;T>B&&(B=T),E.continue()}}function h(){var w=xe(m,m.winningRev,m.deleted),O=v.put(w);O.onsuccess=function(){g.continue()}}if(m.seq)return h();y()}}e._remote=!1,e.type=function(){return"idb"},e._id=et(function(o){o(null,e._meta.instanceId)}),e._bulkDocs=function(a,s,v){Ot(r,a,s,e,i,u(v))},e._get=function(a,s,v){var l,f,g,m=s.ctx;if(!m){var y=Z(i,[J,Q,X],"readonly");if(y.error)return v(y.error);m=y.txn}function h(){v(g,{doc:l,metadata:f,ctx:m})}m.objectStore(J).get(a).onsuccess=function(w){if(f=se(w.target.result),!f)return g=W(ae,"missing"),h();var O;if(s.rev)O=s.latest?ct(s.rev,f):s.rev;else{O=f.winningRev;var M=ie(f);if(M)return g=W(ae,"deleted"),h()}var B=m.objectStore(Q),x=f.id+"::"+O;B.index("_doc_id_rev").get(x).onsuccess=function(E){if(l=E.target.result,l&&(l=he(l)),!l)return g=W(ae,"missing"),h();h()}}},e._getAttachment=function(o,a,s,v,l){var f;if(v.ctx)f=v.ctx;else{var g=Z(i,[J,Q,X],"readonly");if(g.error)return l(g.error);f=g.txn}var m=s.digest,y=s.content_type;f.objectStore(X).get(m).onsuccess=function(h){var w=h.target.result.body;Ne(w,y,v.binary,function(O){l(null,O)})}},e._info=function(a){var s,v,l=Z(i,[Y,Q],"readonly");if(l.error)return a(l.error);var f=l.txn;f.objectStore(Y).get(Y).onsuccess=function(g){v=g.target.result.docCount},f.objectStore(Q).openKeyCursor(null,"prev").onsuccess=function(g){var m=g.target.result;s=m?m.key:0},f.oncomplete=function(){a(null,{doc_count:v,update_seq:s,idb_attachment_format:e._meta.blobSupport?"binary":"base64"})}},e._allDocs=function(a,s){Et(a,i,u(s))},e._changes=function(a){return Lt(a,e,n,i)},e._close=function(o){i.close(),fe.delete(n),o()},e._getRevisionTree=function(o,a){var s=Z(i,[J],"readonly");if(s.error)return a(s.error);var v=s.txn,l=v.objectStore(J).get(o);l.onsuccess=function(f){var g=se(f.target.result);g?a(null,g.rev_tree):a(W(ae))}},e._doCompaction=function(o,a,s){var v=[J,Q,X,oe],l=Z(i,v,"readwrite");if(l.error)return s(l.error);var f=l.txn,g=f.objectStore(J);g.get(o).onsuccess=function(m){var y=se(m.target.result);ft(y.rev_tree,function(O,M,B,x,E){var T=M+"-"+B;a.indexOf(T)!==-1&&(E.status="missing")}),Je(a,o,f);var h=y.winningRev,w=y.deleted;f.objectStore(J).put(xe(y,h,w))},f.onabort=k(s),f.oncomplete=function(){s()}},e._getLocal=function(o,a){var s=Z(i,[$],"readonly");if(s.error)return a(s.error);var v=s.txn,l=v.objectStore($).get(o);l.onerror=k(a),l.onsuccess=function(f){var g=f.target.result;g?(delete g._doc_id_rev,a(null,g)):a(W(ae))}},e._putLocal=function(o,a,s){typeof a=="function"&&(s=a,a={}),delete o._revisions;var v=o._rev,l=o._id;v?o._rev="0-"+(parseInt(v.split("-")[1],10)+1):o._rev="0-1";var f=a.ctx,g;if(!f){var m=Z(i,[$],"readwrite");if(m.error)return s(m.error);f=m.txn,f.onerror=k(s),f.oncomplete=function(){g&&s(null,g)}}var y=f.objectStore($),h;v?(h=y.get(l),h.onsuccess=function(w){var O=w.target.result;if(!O||O._rev!==v)s(W(_e));else{var M=y.put(o);M.onsuccess=function(){g={ok:!0,id:o._id,rev:o._rev},a.ctx&&s(null,g)}}}):(h=y.add(o),h.onerror=function(w){s(W(_e)),w.preventDefault(),w.stopPropagation()},h.onsuccess=function(){g={ok:!0,id:o._id,rev:o._rev},a.ctx&&s(null,g)})},e._removeLocal=function(o,a,s){typeof a=="function"&&(s=a,a={});var v=a.ctx;if(!v){var l=Z(i,[$],"readwrite");if(l.error)return s(l.error);v=l.txn,v.oncomplete=function(){f&&s(null,f)}}var f,g=o._id,m=v.objectStore($),y=m.get(g);y.onerror=k(s),y.onsuccess=function(h){var w=h.target.result;!w||w._rev!==o._rev?s(W(ae)):(m.delete(g),f={ok:!0,id:g,rev:"0-0"},a.ctx&&s(null,f))}},e._destroy=function(o,a){le.removeAllListeners(n);var s=De.get(n);s&&s.result&&(s.result.close(),fe.delete(n));var v=indexedDB.deleteDatabase(n);v.onsuccess=function(){De.delete(n),tt()&&n in localStorage&&delete localStorage[n],a(null,{ok:!0})},v.onerror=k(a)};var A=fe.get(n);if(A)return i=A.idb,e._meta=A.global,Ke(function(){t(null,e)});var R=indexedDB.open(n,wt);De.set(n,R),R.onupgradeneeded=function(o){var a=o.target.result;if(o.oldVersion<1)return _(a);var s=o.currentTarget.transaction;o.oldVersion<3&&D(a),o.oldVersion<4&&b(a);var v=[d,p,C,q],l=o.oldVersion;function f(){var g=v[l-1];l++,g&&g(s,f)}f()},R.onsuccess=function(o){i=o.target.result,i.onversionchange=function(){i.close(),fe.delete(n)},i.onabort=function(h){Ce("error","Database has a global failure",h.target.error),c=h.target.error,i.close(),fe.delete(n)};var a=i.transaction([Y,ye,J],"readwrite"),s=!1,v,l,f,g;function m(){typeof f>"u"||!s||(e._meta={name:n,instanceId:g,blobSupport:f},fe.set(n,{idb:i,global:e._meta}),t(null,e))}function y(){if(!(typeof l>"u"||typeof v>"u")){var h=n+"_id";h in v?g=v[h]:v[h]=g=Re(),v.docCount=l,a.objectStore(Y).put(v)}}a.objectStore(Y).get(Y).onsuccess=function(h){v=h.target.result||{id:Y},y()},Tt(a,function(h){l=h,y()}),Se||(Se=gt(a,ye,"key")),Se.then(function(h){f=h,m()}),a.oncomplete=function(){s=!0,m()},a.onabort=k(t)},R.onerror=function(o){var a=o.target.error&&o.target.error.message;a?a.indexOf("stored database is a higher version")!==-1&&(a=new Error('This DB was created with the newer "indexeddb" adapter, but you are trying to open it with the older "idb" adapter')):a="Failed to open indexedDB, are you in private browsing mode?",Ce("error",a),t(W(we,a))}}Ve.valid=function(){try{return typeof indexedDB<"u"&&typeof IDBKeyRange<"u"}catch{return!1}};function Jt(e){e.adapter("idb",Ve,!0)}export{Jt as default};
|
|
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.es8.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
|
+
`: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};
|
package/dist/index.es9.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{j as q}from"./index-browser.es2.js";var sn=fetch,$n=Headers;function J(r,n,t){for(var e="",f=t-r.length;e.length<f;)e+=n;return e}function H(r,n,t){var e=J(r,n,t);return e+r}var S=-324,x=3,A="";function s(r,n){if(r===n)return 0;r=y(r),n=y(n);var t=m(r),e=m(n);if(t-e!==0)return t-e;switch(typeof r){case"number":return r-n;case"boolean":return r<n?-1:1;case"string":return U(r,n)}return Array.isArray(r)?R(r,n):W(r,n)}function y(r){switch(typeof r){case"undefined":return null;case"number":return r===1/0||r===-1/0||isNaN(r)?null:r;case"object":var n=r;if(Array.isArray(r)){var t=r.length;r=new Array(t);for(var e=0;e<t;e++)r[e]=y(n[e])}else{if(r instanceof Date)return r.toJSON();if(r!==null){r={};for(var f in n)if(Object.prototype.hasOwnProperty.call(n,f)){var u=n[f];typeof u<"u"&&(r[f]=y(u))}}}}return r}function B(r){if(r!==null)switch(typeof r){case"boolean":return r?1:0;case"number":return X(r);case"string":return r.replace(/\u0002/g,"").replace(/\u0001/g,"").replace(/\u0000/g,"");case"object":var n=Array.isArray(r),t=n?r:Object.keys(r),e=-1,f=t.length,u="";if(n)for(;++e<f;)u+=j(t[e]);else for(;++e<f;){var i=t[e];u+=j(i)+j(r[i])}return u}return""}function j(r){var n="\0";return r=y(r),m(r)+A+B(r)+n}function P(r,n){var t=n,e,f=r[n]==="1";if(f)e=0,n++;else{var u=r[n]==="0";n++;var i="",a=r.substring(n,n+x),o=parseInt(a,10)+S;for(u&&(o=-o),n+=x;;){var c=r[n];if(c==="\0")break;i+=c,n++}i=i.split("."),i.length===1?e=parseInt(i,10):e=parseFloat(i[0]+"."+i[1]),u&&(e=e-10),o!==0&&(e=parseFloat(e+"e"+o))}return{num:e,length:n-t}}function Q(r,n){var t=r.pop();if(n.length){var e=n[n.length-1];t===e.element&&(n.pop(),e=n[n.length-1]);var f=e.element,u=e.index;if(Array.isArray(f))f.push(t);else if(u===r.length-2){var i=r.pop();f[i]=t}else r.push(t)}}function gn(r){for(var n=[],t=[],e=0;;){var f=r[e++];if(f==="\0"){if(n.length===1)return n.pop();Q(n,t);continue}switch(f){case"1":n.push(null);break;case"2":n.push(r[e]==="1"),e++;break;case"3":var u=P(r,e);n.push(u.num),e+=u.length;break;case"4":for(var i="";;){var a=r[e];if(a==="\0")break;i+=a,e++}i=i.replace(/\u0001\u0001/g,"\0").replace(/\u0001\u0002/g,"").replace(/\u0002\u0002/g,""),n.push(i);break;case"5":var o={element:[],index:n.length};n.push(o.element),t.push(o);break;case"6":var c={element:{},index:n.length};n.push(c.element),t.push(c);break;default:throw new Error("bad collationIndex or unexpectedly reached end of input: "+f)}}}function R(r,n){for(var t=Math.min(r.length,n.length),e=0;e<t;e++){var f=s(r[e],n[e]);if(f!==0)return f}return r.length===n.length?0:r.length>n.length?1:-1}function U(r,n){return r===n?0:r>n?1:-1}function W(r,n){for(var t=Object.keys(r),e=Object.keys(n),f=Math.min(t.length,e.length),u=0;u<f;u++){var i=s(t[u],e[u]);if(i!==0||(i=s(r[t[u]],n[e[u]]),i!==0))return i}return t.length===e.length?0:t.length>e.length?1:-1}function m(r){var n=["boolean","number","string","object"],t=n.indexOf(typeof r);if(~t)return r===null?1:Array.isArray(r)?5:t<3?t+2:t+3;if(Array.isArray(r))return 5}function X(r){if(r===0)return"1";var n=r.toExponential().split(/e\+?/),t=parseInt(n[1],10),e=r<0,f=e?"0":"2",u=(e?-t:t)-S,i=H(u.toString(),"0",x);f+=A+i;var a=Math.abs(parseFloat(n[0]));e&&(a=10-a);var o=a.toFixed(20);return o=o.replace(/\.?0+$/,""),f+=A+o,f}function I(r,n){for(var t=r,e=0,f=n.length;e<f;e++){var u=n[e];if(t=t[u],!t)break}return t}function vn(r,n,t){for(var e=0,f=n.length;e<f-1;e++){var u=n[e];r=r[u]=r[u]||{}}r[n[f-1]]=t}function Y(r,n){return r<n?-1:r>n?1:0}function E(r){for(var n=[],t="",e=0,f=r.length;e<f;e++){var u=r[e];e>0&&r[e-1]==="\\"&&(u==="$"||u===".")?t=t.substring(0,t.length-1)+u:u==="."?(n.push(t),t=""):t+=u}return n.push(t),n}var Z=["$or","$nor","$not"];function G(r){return Z.indexOf(r)>-1}function L(r){return Object.keys(r)[0]}function k(r){return r[L(r)]}function b(r){var n={},t={$or:!0,$nor:!0};return r.forEach(function(e){Object.keys(e).forEach(function(f){var u=e[f];if(typeof u!="object"&&(u={$eq:u}),G(f))if(u instanceof Array){if(t[f]){t[f]=!1,n[f]=u;return}var i=[];n[f].forEach(function(o){Object.keys(u).forEach(function(c){var v=u[c],p=Math.max(Object.keys(o).length,Object.keys(v).length),w=b([o,v]);Object.keys(w).length<=p||i.push(w)})}),n[f]=i}else n[f]=b([u]);else{var a=n[f]=n[f]||{};Object.keys(u).forEach(function(o){var c=u[o];if(o==="$gt"||o==="$gte")return K(o,c,a);if(o==="$lt"||o==="$lte")return D(o,c,a);if(o==="$ne")return F(c,a);if(o==="$eq")return d(c,a);if(o==="$regex")return M(c,a);a[o]=c})}})}),n}function K(r,n,t){typeof t.$eq<"u"||(typeof t.$gte<"u"?r==="$gte"?n>t.$gte&&(t.$gte=n):n>=t.$gte&&(delete t.$gte,t.$gt=n):typeof t.$gt<"u"?r==="$gte"?n>t.$gt&&(delete t.$gt,t.$gte=n):n>t.$gt&&(t.$gt=n):t[r]=n)}function D(r,n,t){typeof t.$eq<"u"||(typeof t.$lte<"u"?r==="$lte"?n<t.$lte&&(t.$lte=n):n<=t.$lte&&(delete t.$lte,t.$lt=n):typeof t.$lt<"u"?r==="$lte"?n<t.$lt&&(delete t.$lt,t.$lte=n):n<t.$lt&&(t.$lt=n):t[r]=n)}function F(r,n){"$ne"in n?n.$ne.push(r):n.$ne=[r]}function d(r,n){delete n.$gt,delete n.$gte,delete n.$lt,delete n.$lte,delete n.$ne,n.$eq=r}function M(r,n){"$regex"in n?n.$regex.push(r):n.$regex=[r]}function T(r){for(var n in r){if(Array.isArray(r))for(var t in r)r[t].$and&&(r[t]=b(r[t].$and));var e=r[n];typeof e=="object"&&T(e)}return r}function _(r,n){for(var t in r){t==="$and"&&(n=!0);var e=r[t];typeof e=="object"&&(n=_(e,n))}return n}function V(r){var n=q(r);_(n,!1)&&(n=T(n),"$and"in n&&(n=b(n.$and))),["$or","$nor"].forEach(function(i){i in n&&n[i].forEach(function(a){for(var o=Object.keys(a),c=0;c<o.length;c++){var v=o[c],p=a[v];(typeof p!="object"||p===null)&&(a[v]={$eq:p})}})}),"$not"in n&&(n.$not=b([n.$not]));for(var t=Object.keys(n),e=0;e<t.length;e++){var f=t[e],u=n[f];(typeof u!="object"||u===null)&&(u={$eq:u}),n[f]=u}return O(n),n}function O(r){Object.keys(r).forEach(function(n){var t=r[n];Array.isArray(t)?t.forEach(function(e){e&&typeof e=="object"&&O(e)}):n==="$ne"?r.$ne=[t]:n==="$regex"?r.$regex=[t]:t&&typeof t=="object"&&O(t)})}function nn(r){function n(t){return r.map(function(e){var f=L(e),u=E(f),i=I(t,u);return i})}return function(t,e){var f=n(t.doc),u=n(e.doc),i=s(f,u);return i!==0?i:Y(t.doc._id,e.doc._id)}}function rn(r,n,t){if(r=r.filter(function(i){return g(i.doc,n.selector,t)}),n.sort){var e=nn(n.sort);r=r.sort(e),typeof n.sort[0]!="string"&&k(n.sort[0])==="desc"&&(r=r.reverse())}if("limit"in n||"skip"in n){var f=n.skip||0,u=("limit"in n?n.limit:r.length)+f;r=r.slice(f,u)}return r}function g(r,n,t){return t.every(function(e){var f=n[e],u=E(e),i=I(r,u);return G(e)?en(e,f,r):h(f,r,u,i)})}function h(r,n,t,e){return r?typeof r=="object"?Object.keys(r).every(function(f){var u=r[f];if(f.indexOf("$")===0)return C(f,n,u,t,e);var i=E(f);if(e===void 0&&typeof u!="object"&&i.length>0)return!1;var a=I(e,i);return typeof u=="object"?h(u,n,t,a):C("$eq",n,u,i,a)}):r===e:!0}function en(r,n,t){return r==="$or"?n.some(function(e){return g(t,e,Object.keys(e))}):r==="$not"?!g(t,n,Object.keys(n)):!n.find(function(e){return g(t,e,Object.keys(e))})}function C(r,n,t,e,f){if(!z[r])throw new Error('unknown operator "'+r+'" - should be one of $eq, $lte, $lt, $gt, $gte, $exists, $ne, $in, $nin, $size, $mod, $regex, $elemMatch, $type, $allMatch or $all');return z[r](n,t,e,f)}function l(r){return typeof r<"u"&&r!==null}function $(r){return typeof r<"u"}function tn(r,n){if(typeof r!="number"||parseInt(r,10)!==r)return!1;var t=n[0],e=n[1];return r%t===e}function N(r,n){return n.some(function(t){return r instanceof Array?r.some(function(e){return s(t,e)===0}):s(t,r)===0})}function fn(r,n){return n.every(function(t){return r.some(function(e){return s(t,e)===0})})}function un(r,n){return r.length===n}function on(r,n){var t=new RegExp(n);return t.test(r)}function an(r,n){switch(n){case"null":return r===null;case"boolean":return typeof r=="boolean";case"number":return typeof r=="number";case"string":return typeof r=="string";case"array":return r instanceof Array;case"object":return{}.toString.call(r)==="[object Object]"}}var z={$elemMatch:function(r,n,t,e){return!Array.isArray(e)||e.length===0?!1:typeof e[0]=="object"&&e[0]!==null?e.some(function(f){return g(f,n,Object.keys(n))}):e.some(function(f){return h(n,r,t,f)})},$allMatch:function(r,n,t,e){return!Array.isArray(e)||e.length===0?!1:typeof e[0]=="object"&&e[0]!==null?e.every(function(f){return g(f,n,Object.keys(n))}):e.every(function(f){return h(n,r,t,f)})},$eq:function(r,n,t,e){return $(e)&&s(e,n)===0},$gte:function(r,n,t,e){return $(e)&&s(e,n)>=0},$gt:function(r,n,t,e){return $(e)&&s(e,n)>0},$lte:function(r,n,t,e){return $(e)&&s(e,n)<=0},$lt:function(r,n,t,e){return $(e)&&s(e,n)<0},$exists:function(r,n,t,e){return n?$(e):!$(e)},$mod:function(r,n,t,e){return l(e)&&tn(e,n)},$ne:function(r,n,t,e){return n.every(function(f){return s(e,f)!==0})},$in:function(r,n,t,e){return l(e)&&N(e,n)},$nin:function(r,n,t,e){return l(e)&&!N(e,n)},$size:function(r,n,t,e){return l(e)&&Array.isArray(e)&&un(e,n)},$all:function(r,n,t,e){return Array.isArray(e)&&fn(e,n)},$regex:function(r,n,t,e){return l(e)&&typeof e=="string"&&n.every(function(f){return on(e,f)})},$type:function(r,n,t,e){return an(e,n)}};function pn(r,n){if(typeof n!="object")throw new Error("Selector error: expected a JSON object");n=V(n);var t={doc:r},e=rn([t],{selector:n},Object.keys(n));return e&&e.length===1}export{V as a,rn as b,s as c,Y as d,E as e,sn as f,k as g,$n as h,I as i,L as j,pn as m,y as n,gn as p,vn as s,j as t};
|