snow-cms 1.1.0 → 1.1.2

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.es6.js CHANGED
@@ -1,3 +1,3 @@
1
- import{n as U,i as w,c as v,p as V,g as z,M as k,s as X,B as Z,a as d,E,b as N,d as ce,r as oe,e as A,f as H,h as he,j as x,u as G,U as $,v as le,o as de,l as _e,k as ve,m as me,N as F,R as W,I as ge,q as ye,Q as pe,t as we,w as De}from"./index-browser.es2.js";import{i as P,t as I,c as ee,a as te,b as ie,r as ke,f as Ee}from"./index.es8.js";import{m as Ae,f as Ce}from"./index.es9.js";import"./index.js";function xe(n){return X(`"use strict";
2
- return `+n+";",{})}function Le(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 X(e,{})}function Oe(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 Te(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=U(n.view):n.filter=U(n.filter))}function Re(n,e){return e.filter&&typeof e.filter=="string"&&!e.doc_ids&&!w(n.db)}function Fe(n,e){var t=e.complete;if(e.filter==="_view"){if(!e.view||typeof e.view!="string"){var i=v(Z,"`view` filter parameter not found or invalid.");return t(i)}var r=V(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(v(k,f.views?"missing json key: "+r[1]:"missing json key: views"));e.filter=Le(u),n.doChanges(e)})}else if(e.selector)e.filter=function(s){return Ae(s,e.selector)},n.doChanges(e);else{var a=V(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(v(k,f&&f.filters?"missing json key: "+a[1]:"missing json key: filters"));e.filter=xe(u),n.doChanges(e)})}}function Pe(n){n._changesFilterPlugin={validate:Oe,normalize:Te,shouldFilter:Re,filter:Fe}}function Se(n,e,t,i){try{n.emit("change",e,t,i)}catch(r){A("error",'Error in .on("change", function):',r)}}function Ne(n,e,t){var i=[{rev:n._rev}];t.style==="all_docs"&&(i=ee(e.rev_tree).map(function(a){return{rev:a.rev}}));var r={id:e.id,changes:i,doc:n};return ie(e,n._rev)&&(r.deleted=!0),t.conflicts&&(r.doc._conflicts=te(e),r.doc._conflicts.length||delete r.doc._conflicts),r}class Ie extends E{constructor(e,t,i){super(),this.db=e,t=t?x(t):{};var r=t.complete=de((f,u)=>{f?_e(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=x(e),"live"in e&&!("continuous"in e)&&(e.continuous=e.live),e.processChange=Ne,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 J(n,e){return n<e?-1:n>e?1:0}function S(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 be(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]=ve(t._attachments[a],["data","digest","content_type","length","revpos","stub"])}}}function qe(n,e){var t=J(n._id,e._id);if(t!==0)return t;var i=n._revisions?n._revisions.start:0,r=e._revisions?e._revisions.start:0;return J(i,r)}function Qe(n){var e={},t=[];return I(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),me(function(){n._compactionQueue.shift(),n._compactionQueue.length&&ne(n)})})})}function Be(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 Me(n){return n.charAt(0)==="_"?n+" is not a valid attachment name, attachment names cannot start with '_'":!1}class re extends E{_setup(){this.post=d("post",function(e,t,i){if(typeof t=="function"&&(i=t,t={}),typeof e!="object"||Array.isArray(e))return i(v(F));this.bulkDocs({docs:[e]},t,S(i,e._id))}).bind(this),this.put=d("put",function(e,t,i){if(typeof t=="function"&&(i=t,t={}),typeof e!="object"||Array.isArray(e))return i(v(F));if(ce(e._id),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,S(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=oe();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 v(W);return f(u)},function(u){if(u.reason===k.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(v(W));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,S(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 H;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);I(c,function(_,p,g,C,L){var D=p+"-"+g,m=l.indexOf(D);m!==-1&&(l.splice(m,1),L.status!=="available"&&f(o,D))}),l.forEach(function(_){f(o,_)})}r.map(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 _={};return s.forEach(function(p,g){_[g]=p}),i(null,_)}})},this)}).bind(this),this.bulkGet=d("bulkGet",function(e,t){he(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)}),I(a,function(o,c,l,_,p){var g=c+"-"+l;p.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={}),typeof e!="string")return i(v(ge));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,_){if(l)u.push({missing:c});else{for(var p,g=0,C=u.length;g<C;g++)if(u[g].ok&&u[g].ok._rev===_._rev){p=!0;break}p||u.push({ok:_})}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=ee(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(!(typeof f=="string"&&/^\d+-/.test(f)))return i(v(ye))}a()}else return i(v($,"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,_=o.ctx;if(t.conflicts){var p=te(l);p.length&&(c._conflicts=p)}if(ie(l,c._rev)&&(c._deleted=!0),t.revs||t.revs_info){for(var g=c._rev.split("-"),C=parseInt(g[0],10),L=g[1],D=ke(l.rev_tree),m=null,O=0;O<D.length;O++){var b=D[O],q=b.ids.map(function(y){return y.id}).indexOf(L),ae=q===C-1;(ae||!m&&q!==-1)&&(m=b)}if(!m)return u=new Error("invalid rev tree"),u.docId=e,i(u);var Q=m.ids.map(function(y){return y.id}).indexOf(c._rev.split("-")[1])+1,ue=m.ids.length-Q;if(m.ids.splice(Q,ue),m.ids.reverse(),t.revs&&(c._revisions={start:m.pos+m.ids.length-1,ids:m.ids.map(function(y){return y.id})}),t.revs_info){var j=m.pos+m.ids.length;c._revs_info=m.ids.map(function(y){return j--,{rev:j+"-"+y.id,status:y.opts.status}})}}if(t.attachments&&c._attachments){var T=c._attachments,B=Object.keys(T).length;if(B===0)return i(null,c);Object.keys(T).forEach(y=>{this._getAttachment(c._id,y,T[y],{rev:c._rev,binary:t.binary,ctx:_},function(Ye,fe){var R=c._attachments[y];R.data=fe,delete R.stub,delete R.length,--B||i(null,c)})})}else{if(c._attachments)for(var M in c._attachments)Object.prototype.hasOwnProperty.call(c._attachments,M)&&(c._attachments[M].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,this._getAttachment(e,t,s.doc._attachments[t],i,r);else return r(v(k))})}).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(v(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(v(we));for(var r=0;r<e.docs.length;++r)if(typeof e.docs[r]!="object"||Array.isArray(e.docs[r]))return i(v(F));var a;if(e.docs.forEach(function(u){u._attachments&&Object.keys(u._attachments).forEach(function(o){a=a||Me(o),u._attachments[o].content_type||A("warn","Attachment",o,"on document",u._id,"is missing content_type")})}),a)return i(v(Z,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(qe),be(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(_){return _.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=x(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)}G(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},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(()=>G(this,"_local/compaction",_=>!_.last_seq||_.last_seq<l?(_.last_seq=l,_):!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 Ie(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(v($,"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(v(k));let s;try{s=Ee(a,e)}catch(f){return t(f.message||f)}i._purge(n,s,(f,u)=>{if(f)return t(f);Be(i,n,e).then(function(){return t(null,u)})})})});class Ue{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 Ve(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 ze(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 ze(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 K 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=x(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=Ve(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 Ue,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(K,function(n,e){K.prototype._setup.call(this,n,e)});class We{constructor(){this.tasks={}}list(){return Object.values(this.tasks)}add(e){const t=le();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 Y=new E;function Je(n){Object.keys(E.prototype).forEach(function(t){typeof E.prototype[t]=="function"&&(n[t]=Y[t].bind(Y))});var e=n._destructionListeners=new H;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)})}})}Je(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=N({},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=N({},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=N({},this.__defaults,n),e};h.fetch=function(n,e){return Ce(n,e)};h.prototype.activeTasks=h.activeTasks=new We;var Ke="8.0.1";h.plugin(Pe);h.version=Ke;export{h as default};
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{n as G,i as w,c as _,p as z,g as W,M as C,s as ee,B as te,a as d,E as x,v as oe,b as O,o as he,d as A,e as le,r as de,f as _e,u as J,U as ie,l as ve,h as me,j as ge,N as I,I as N,R as K,k as ye,Q 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 ee(`"use strict";
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};
package/dist/index.es7.js CHANGED
@@ -1,2 +1,2 @@
1
- import{x as we,r as Qe,d as Ue,c as H,D as Ce,q as Ye,y as Xe,z as Te,A as Pe,C as Ze,F as ze,f as ge,R as _e,M as ae,G as ke,H as $e,J as et,K as tt,w as rt,m as Ke,e as Be,L as Oe,O as Le,P as nt,S as at,j as it,T as ot,V as st,b as ut,k as ct,W as ft}from"./index-browser.es2.js";import{i as he,m as Me,d as vt,w as de,b as ie,l as lt,t as dt,a as gt,e as _t}from"./index.es8.js";import"./index.js";function Ie(e){return e.reduce(function(r,t){return r[t]=!0,r},{})}var ht=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"]),mt=Ie(["_access","_attachments","_replication_id","_replication_state","_replication_state_time","_replication_state_reason","_replication_stats"]);function Ee(e){if(!/^\d+-/.test(e))return H(Ye);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,a=[n[0],r,[]],u=1,c=n.length;u<c;u++)a=[n[u],{status:"missing"},[a]];return[{pos:t,ids:a}]}function Ne(e,r,t){t||(t={deterministic_revs:!0});var n,a,u,c={status:"available"};if(e._deleted&&(c.deleted=!0),r)if(e._id||(e._id=we()),a=Qe(e,t.deterministic_revs),e._rev){if(u=Ee(e._rev),u.error)return u;e._rev_tree=[{pos:u.prefix,ids:[u.id,{status:"missing"},[[a,c,[]]]]}],n=u.prefix+1}else e._rev_tree=[{pos:1,ids:[a,c,[]]}],n=1;else if(e._revisions&&(e._rev_tree=pt(e._revisions,c),n=e._revisions.start,a=e._revisions.ids[0]),!e._rev_tree){if(u=Ee(e._rev),u.error)return u;n=u.prefix,a=u.id,e._rev_tree=[{pos:n,ids:[a,c,[]]}]}Ue(e._id),e._rev=n+"-"+a;var _={metadata:{},data:{}};for(var d in e)if(Object.prototype.hasOwnProperty.call(e,d)){var x=d[0]==="_";if(x&&!ht[d]){var p=H(Ce,d);throw p.message=Ce.message+": "+d,p}else x&&!mt[d]?_.metadata[d.slice(1)]=e[d]:_.data[d]=e[d]}return _}function yt(e){try{return Ze(e)}catch{var r=H(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=Xe(n,e.content_type):r==="base64"?e.data=Te(n):e.data=n,Pe(n,function(a){e.digest="md5-"+a,t()})}function xt(e,r,t){Pe(e.data,function(n){e.digest="md5-"+n,e.length=e.data.size||e.data.length||0,r==="binary"?ke(e.data,function(a){e.data=a,t()}):r==="base64"?$e(e.data,function(a){e.data=a,t()}):t()})}function Dt(e,r,t){if(e.stub)return t();typeof e.data=="string"?St(e,r,t):xt(e,r,t)}function qt(e,r,t){if(!e.length)return t();var n=0,a;e.forEach(function(c){var _=c.data&&c.data._attachments?Object.keys(c.data._attachments):[],d=0;if(!_.length)return u();function x(b){a=b,d++,d===_.length&&u()}for(var p in c.data._attachments)Object.prototype.hasOwnProperty.call(c.data._attachments,p)&&Dt(c.data._attachments[p],r,x)});function u(){n++,e.length===n&&(a?t(a):t())}}function bt(e,r,t,n,a,u,c,_){if(vt(r.rev_tree,t.metadata.rev)&&!_)return n[a]=t,u();var d=r.winningRev||de(r),x="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(x&&!p&&_&&b){var O=t.data;O._rev=d,O._id=t.metadata.id,t=Ne(O,_)}var q=Me(r.rev_tree,t.metadata.rev_tree[0],e),A=_&&(x&&p&&q.conflicts!=="new_leaf"||!x&&q.conflicts!=="new_leaf"||x&&!p&&q.conflicts==="new_branch");if(A){var w=H(_e);return n[a]=w,u()}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 i=de(t.metadata),s=ie(t.metadata,i),v=x===s?0:x<s?-1:1,l;o===i?l=s:l=ie(t.metadata,o),c(t,i,s,l,!0,v,a,u)}function At(e){return e.metadata.rev_tree[0].ids[1].status==="missing"}function Rt(e,r,t,n,a,u,c,_,d){e=e||1e3;function x(w,o,i){var s=de(w.metadata),v=ie(w.metadata,s);if("was_delete"in _&&v)return u[o]=H(ae,"deleted"),i();var l=p&&At(w);if(l){var f=H(_e);return u[o]=f,i()}var g=v?0:1;c(w,s,v,v,!1,g,o,i)}var p=_.new_edits,b=new ge,O=0,q=r.length;function A(){++O===q&&d&&d()}r.forEach(function(w,o){if(w._id&&he(w._id)){var i=w._deleted?"_removeLocal":"_putLocal";t[i](w,{ctx:a},function(v,l){u[o]=v||l,A()});return}var s=w.metadata.id;b.has(s)?(q--,b.get(s).push([w,o])):b.set(s,[[w,o]])}),b.forEach(function(w,o){var i=0;function s(){++i<w.length?v():A()}function v(){var l=w[i],f=l[0],g=l[1];if(n.has(o))bt(e,n.get(o),f,u,g,s,c,p);else{var m=Me([],f.metadata.rev_tree[0],e);f.metadata.rev_tree=m.tree,f.stemmedRevs=m.stemmedRevs||[],x(f,g,s)}}v()})}var pe={};pe.stringify=function(r){var t=[];t.push({obj:r});for(var n="",a,u,c,_,d,x,p,b,O,q,A;a=t.pop();)if(u=a.obj,c=a.prefix||"",_=a.val||"",n+=c,_)n+=_;else if(typeof u!="object")n+=typeof u>"u"?null:JSON.stringify(u);else if(u===null)n+="null";else if(Array.isArray(u)){for(t.push({val:"]"}),d=u.length-1;d>=0;d--)x=d===0?"":",",t.push({obj:u[d],prefix:x});t.push({val:"["})}else{p=[];for(b in u)u.hasOwnProperty(b)&&p.push(b);for(t.push({val:"}"}),d=p.length-1;d>=0;d--)O=p[d],q=u[O],A=d>0?",":"",A+=JSON.stringify(O)+":",t.push({obj:q,prefix:A});t.push({val:"{"})}return n};function ce(e,r,t){var n=t[t.length-1];e===n.element&&(t.pop(),n=t[t.length-1]);var a=n.element,u=n.index;if(Array.isArray(a))a.push(e);else if(u===r.length-2){var c=r.pop();a[c]=e}else r.push(e)}pe.parse=function(e){for(var r=[],t=[],n=0,a,u,c,_,d,x,p,b,O;;){if(a=e[n++],a==="}"||a==="]"||typeof a>"u"){if(r.length===1)return r.pop();ce(r.pop(),r,t);continue}switch(a){case" ":case" ":case`
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(u="",n--;;)if(c=e[n++],/[\d\.\-e\+]/.test(c))u+=c;else{n--;break}ce(parseFloat(u),r,t);break;case'"':for(_="",d=void 0,x=0;p=e[n++],p!=='"'||d==="\\"&&x%2===1;)_+=p,d=p,d==="\\"?x++:x=0;ce(JSON.parse('"'+_+'"'),r,t);break;case"[":b={element:[],index:r.length},r.push(b.element),t.push(b);break;case"{":O={element:{},index:r.length},r.push(O.element),t.push(O);break;default:throw new Error("unexpectedly reached end of input: "+a)}}};function wt(e){try{return JSON.parse(e)}catch{return pe.parse(e)}}function Ot(e){try{return JSON.stringify(e)}catch{return pe.stringify(e)}}var Ct=5,F="document-store",U="by-sequence",X="attach-store",oe="attach-seq-store",Y="meta-store",$="local-store",De="detect-blob-support";function ee(e){return function(r){var t="unknown_error";r.target&&r.target.error&&(t=r.target.error.name||r.target.error.message),e(H(Oe,t,r.type))}}function qe(e,r,t){return{data:Ot(e),winningRev:r,deletedOrLocal:t?"1":"0",seq:e.seq,id:e.id}}function se(e){if(!e)return null;var r=wt(e.data);return r.winningRev=e.winningRev,r.deleted=e.deletedOrLocal==="1",r.seq=e.seq,r}function me(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 Ge(e,r,t,n){t?n(e?typeof e!="string"?e:nt(e,r):Le([""],{type:r})):e?typeof e!="string"?at(e,function(a){n(Te(a))}):n(e):n("")}function Je(e,r,t,n){var a=Object.keys(e._attachments||{});if(!a.length)return n&&n();var u=0;function c(){++u===a.length&&n&&n()}function _(d,x){var p=d._attachments[x],b=p.digest,O=t.objectStore(X).get(b);O.onsuccess=function(q){p.body=q.target.result.body,c()}}a.forEach(function(d){r.attachments&&r.include_docs?_(e,d):(e._attachments[d].stub=!0,c())})}function be(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(a){var u=t.doc._attachments[a];if("body"in u){var c=u.body,_=u.content_type;return new Promise(function(d){Ge(c,_,r,function(x){t.doc._attachments[a]=ut(ct(u,["digest","content_type"]),{data:x}),d()})})}}))}}))}function Ve(e,r,t){var n=[],a=t.objectStore(U),u=t.objectStore(X),c=t.objectStore(oe),_=e.length;function d(){_--,_||x()}function x(){n.length&&n.forEach(function(p){var b=c.index("digestSeq").count(IDBKeyRange.bound(p+"::",p+"::￿",!1,!1));b.onsuccess=function(O){var q=O.target.result;q||u.delete(p)}})}e.forEach(function(p){var b=a.index("_doc_id_rev"),O=r+"::"+p;b.getKey(O).onsuccess=function(q){var A=q.target.result;if(typeof A!="number")return d();a.delete(A);var w=c.index("seq").openCursor(IDBKeyRange.only(A));w.onsuccess=function(o){var i=o.target.result;if(i){var s=i.value.digestSeq.split("::")[0];n.push(s),c.delete(i.primaryKey),i.continue()}else d()}}})}function Z(e,r,t){try{return{txn:e.transaction(r,t)}}catch(n){return{error:n}}}var le=new et;function Bt(e,r,t,n,a,u){for(var c=r.docs,_,d,x,p,b,O,q,A,w=0,o=c.length;w<o;w++){var i=c[w];i._id&&he(i._id)||(i=c[w]=Ne(i,t.new_edits,e),i.error&&!q&&(q=i))}if(q)return u(q);var s=!1,v=0,l=new Array(c.length),f=new ge,g=!1,m=n._meta.blobSupport?"blob":"base64";qt(c,m,function(S){if(S)return u(S);y()});function y(){var S=[F,U,X,$,oe,Y],T=Z(a,S,"readwrite");if(T.error)return u(T.error);_=T.txn,_.onabort=ee(u),_.ontimeout=ee(u),_.oncomplete=G,d=_.objectStore(F),x=_.objectStore(U),p=_.objectStore(X),b=_.objectStore(oe),O=_.objectStore(Y),O.get(Y).onsuccess=function(P){A=P.target.result,C()},B(function(P){if(P)return g=!0,u(P);L()})}function h(){s=!0,C()}function R(){Rt(e.revs_limit,c,n,f,_,l,E,t,h)}function C(){!A||!s||(A.docCount+=v,O.put(A))}function L(){if(!c.length)return;var S=0;function T(){++S===c.length&&R()}function P(K){var Q=se(K.target.result);Q&&f.set(Q.id,Q),T()}for(var W=0,V=c.length;W<V;W++){var N=c[W];if(N._id&&he(N._id)){T();continue}var I=d.get(N.metadata.id);I.onsuccess=P}}function G(){g||(le.notify(n._meta.name),u(null,l))}function D(S,T){var P=p.get(S);P.onsuccess=function(W){if(W.target.result)T();else{var V=H(ft,"unknown stub attachment with digest "+S);V.status=412,T(V)}}}function B(S){var T=[];if(c.forEach(function(N){N.data&&N.data._attachments&&Object.keys(N.data._attachments).forEach(function(I){var K=N.data._attachments[I];K.stub&&T.push(K.digest)})}),!T.length)return S();var P=0,W;function V(){++P===T.length&&S(W)}T.forEach(function(N){D(N,function(I){I&&!W&&(W=I),V()})})}function E(S,T,P,W,V,N,I,K){S.metadata.winningRev=T,S.metadata.deleted=P;var Q=S.data;Q._id=S.metadata.id,Q._rev=S.metadata.rev,W&&(Q._deleted=!0);var re=Q._attachments&&Object.keys(Q._attachments).length;if(re)return M(S,T,P,V,I,K);v+=N,C(),j(S,T,P,V,I,K)}function j(S,T,P,W,V,N){var I=S.data,K=S.metadata;I._doc_id_rev=K.id+"::"+K.rev,delete I._id,delete I._rev;function Q(k){var te=S.stemmedRevs||[];W&&n.auto_compaction&&(te=te.concat(_t(S.metadata))),te&&te.length&&Ve(te,S.metadata.id,_),K.seq=k.target.result;var ve=qe(K,T,P),ye=d.put(ve);ye.onsuccess=ue}function re(k){k.preventDefault(),k.stopPropagation();var te=x.index("_doc_id_rev"),ve=te.getKey(I._doc_id_rev);ve.onsuccess=function(ye){var He=x.put(I,ye.target.result);He.onsuccess=Q}}function ue(){l[V]={ok:!0,id:K.id,rev:K.rev},f.set(S.metadata.id,S.metadata),J(S,K.seq,N)}var ne=x.put(I);ne.onsuccess=Q,ne.onerror=re}function M(S,T,P,W,V,N){var I=S.data,K=0,Q=Object.keys(I._attachments);function re(){K===Q.length&&j(S,T,P,W,V,N)}function ue(){K++,re()}Q.forEach(function(ne){var k=S.data._attachments[ne];if(k.stub)K++,re();else{var te=k.data;delete k.data,k.revpos=parseInt(T,10);var ve=k.digest;z(ve,te,ue)}})}function J(S,T,P){var W=0,V=Object.keys(S.data._attachments||{});if(!V.length)return P();function N(){++W===V.length&&P()}function I(Q){var re=S.data._attachments[Q].digest,ue=b.put({seq:T,digestSeq:re+"::"+T});ue.onsuccess=N,ue.onerror=function(ne){ne.preventDefault(),ne.stopPropagation(),N()}}for(var K=0;K<V.length;K++)I(V[K])}function z(S,T,P){var W=p.count(S);W.onsuccess=function(V){var N=V.target.result;if(N)return P();var I={digest:S,body:T},K=p.put(I);K.onsuccess=P}}}function Fe(e,r,t,n,a){n===-1&&(n=1e3);var u=typeof e.getAll=="function"&&typeof e.getAllKeys=="function"&&n>1&&!t,c,_,d;function x(q){_=q.target.result,c&&a(c,_,d)}function p(q){c=q.target.result,_&&a(c,_,d)}function b(){if(!c.length)return a();var q=c[c.length-1],A;if(r&&r.upper)try{A=IDBKeyRange.bound(q,r.upper,!0,r.upperOpen)}catch(w){if(w.name==="DataError"&&w.code===0)return a()}else A=IDBKeyRange.lowerBound(q,!0);r=A,c=null,_=null,e.getAll(r,n).onsuccess=x,e.getAllKeys(r,n).onsuccess=p}function O(q){var A=q.target.result;if(!A)return a();a([A.key],[A.value],A)}u?(d={continue:b},e.getAll(r,n).onsuccess=x,e.getAllKeys(r,n).onsuccess=p):t?e.openCursor(r,"prev").onsuccess=O:e.openCursor(r).onsuccess=O}function Et(e,r,t){if(typeof e.getAll=="function"){e.getAll(r).onsuccess=t;return}var n=[];function a(u){var c=u.target.result;c?(n.push(c.value),c.continue()):t({target:{result:n}})}e.openCursor(r).onsuccess=a}function jt(e,r,t){var n=new Array(e.length),a=0;e.forEach(function(u,c){r.get(u).onsuccess=function(_){_.target.result?n[c]=_.target.result:n[c]={key:u,error:"not_found"},a++,a===e.length&&t(e,n,{})}})}function Tt(e,r,t,n,a){try{if(e&&r)return a?IDBKeyRange.bound(r,e,!t,!1):IDBKeyRange.bound(e,r,!1,!t);if(e)return a?IDBKeyRange.upperBound(e):IDBKeyRange.lowerBound(e);if(r)return a?IDBKeyRange.lowerBound(r,!t):IDBKeyRange.upperBound(r,!t);if(n)return IDBKeyRange.only(n)}catch(u){return{error:u}}return null}function Pt(e,r,t){var n="startkey"in e?e.startkey:!1,a="endkey"in e?e.endkey:!1,u="key"in e?e.key:!1,c="keys"in e?e.keys:!1,_=e.skip||0,d=typeof e.limit=="number"?e.limit:-1,x=e.inclusive_end!==!1,p,b;if(!c&&(p=Tt(n,a,x,u,e.descending),b=p&&p.error,b&&!(b.name==="DataError"&&b.code===0)))return t(H(Oe,b.name,b.message));var O=[F,U,Y];e.attachments&&O.push(X);var q=Z(r,O,"readonly");if(q.error)return t(q.error);var A=q.txn;A.oncomplete=G,A.onabort=ee(t);var w=A.objectStore(F),o=A.objectStore(U),i=A.objectStore(Y),s=o.index("_doc_id_rev"),v=[],l,f;i.get(Y).onsuccess=function(D){l=D.target.result.docCount},e.update_seq&&g(o,function(D){D.target.result&&D.target.result.length>0&&(f=D.target.result[0])});function g(D,B){function E(j){var M=j.target.result,J=void 0;return M&&M.key&&(J=M.key),B({target:{result:[J]}})}D.openCursor(null,"prev").onsuccess=E}function m(D,B,E){var j=D.id+"::"+E;s.get(j).onsuccess=function(J){if(B.doc=me(J.target.result)||{},e.conflicts){var z=gt(D);z.length&&(B.doc._conflicts=z)}Je(B.doc,e,A)}}function y(D,B){var E={id:B.id,key:B.id,value:{rev:D}},j=B.deleted;j?c&&(v.push(E),E.value.deleted=!0,E.doc=null):_--<=0&&(v.push(E),e.include_docs&&m(B,E,D))}function h(D){for(var B=0,E=D.length;B<E&&v.length!==d;B++){var j=D[B];if(j.error&&c){v.push(j);continue}var M=se(j),J=M.winningRev;y(J,M)}}function R(D,B,E){E&&(h(B),v.length<d&&E.continue())}function C(D){var B=D.target.result;e.descending&&(B=B.reverse()),h(B)}function L(){var D={total_rows:l,offset:e.skip,rows:v};e.update_seq&&f!==void 0&&(D.update_seq=f),t(null,D)}function G(){e.attachments?be(v,e.binary).then(L):L()}if(!(b||d===0)){if(c)return jt(e.keys,w,R);if(d===-1)return Et(w,p,C);Fe(w,p,e.descending,d+_,R)}}function Kt(e){return new Promise(function(r){var t=Le([""]),n=e.objectStore(De).put(t,"key");n.onsuccess=function(){var a=navigator.userAgent.match(/Chrome\/(\d+)/),u=navigator.userAgent.match(/Edge\//);r(u||!a||parseInt(a[1],10)>=43)},n.onerror=e.onabort=function(a){a.preventDefault(),a.stopPropagation(),r(!1)}}).catch(function(){return!1})}function Lt(e,r){var t=e.objectStore(F).index("deletedOrLocal");t.count(IDBKeyRange.only("0")).onsuccess=function(n){r(n.target.result)}}var Ae=!1,Re=[];function Mt(e,r,t,n){try{e(r,t)}catch(a){n.emit("error",a)}}function je(){Ae||!Re.length||(Ae=!0,Re.shift()())}function It(e,r,t){Re.push(function(){e(function(u,c){Mt(r,u,c,t),Ae=!1,Ke(function(){je()})})}),je()}function Nt(e,r,t,n){if(e=it(e),e.continuous){var a=t+":"+we();return le.addListener(t,a,r,e),le.notify(t),{cancel:function(){le.removeListener(t,a)}}}var u=e.doc_ids&&new ot(e.doc_ids);e.since=e.since||0;var c=e.since,_="limit"in e?e.limit:-1;_===0&&(_=1);var d=[],x=0,p=st(e),b=new ge,O,q,A,w;function o(y,h,R){if(!R||!y.length)return;var C=new Array(y.length),L=new Array(y.length);function G(E,j){var M=e.processChange(j,E,e);c=M.seq=E.seq;var J=p(M);return typeof J=="object"?Promise.reject(J):J?(x++,e.return_docs&&d.push(M),e.attachments&&e.include_docs?new Promise(function(z){Je(j,e,O,function(){be([M],e.binary).then(function(){z(M)})})}):Promise.resolve(M)):Promise.resolve()}function D(){for(var E=[],j=0,M=C.length;j<M&&x!==_;j++){var J=C[j];if(J){var z=L[j];E.push(G(z,J))}}Promise.all(E).then(function(S){for(var T=0,P=S.length;T<P;T++)S[T]&&e.onChange(S[T])}).catch(e.complete),x!==_&&R.continue()}var B=0;h.forEach(function(E,j){var M=me(E),J=y[j];s(M,J,function(z,S){L[j]=z,C[j]=S,++B===y.length&&D()})})}function i(y,h,R,C){if(R.seq!==h)return C();if(R.winningRev===y._rev)return C(R,y);var L=y._id+"::"+R.winningRev,G=w.get(L);G.onsuccess=function(D){C(R,me(D.target.result))}}function s(y,h,R){if(u&&!u.has(y._id))return R();var C=b.get(y._id);if(C)return i(y,h,C,R);A.get(y._id).onsuccess=function(L){C=se(L.target.result),b.set(y._id,C),i(y,h,C,R)}}function v(){e.complete(null,{results:d,last_seq:c})}function l(){!e.continuous&&e.attachments?be(d).then(v):v()}var f=[F,U];e.attachments&&f.push(X);var g=Z(n,f,"readonly");if(g.error)return e.complete(g.error);O=g.txn,O.onabort=ee(e.complete),O.oncomplete=l,q=O.objectStore(U),A=O.objectStore(F),w=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 ge,Se,xe=new ge;function We(e,r){var t=this;It(function(n){Gt(t,e,n)},r,t.constructor)}function Gt(e,r,t){var n=r.name,a=null,u=null;e._meta=null;function c(o){return function(i,s){i&&i instanceof Error&&!i.reason&&u&&(i.reason=u),o(i,s)}}function _(o){var i=o.createObjectStore(F,{keyPath:"id"});o.createObjectStore(U,{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(De),i.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,i){var s=o.objectStore(F);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 i()}}function x(o){o.createObjectStore($,{keyPath:"_id"}).createIndex("_doc_id_rev","_doc_id_rev",{unique:!0})}function p(o,i){var s=o.objectStore($),v=o.objectStore(F),l=o.objectStore(U),f=v.openCursor();f.onsuccess=function(g){var m=g.target.result;if(m){var y=m.value,h=y.id,R=he(h),C=de(y);if(R){var L=h+"::"+C,G=h+"::",D=h+"::~",B=l.index("_doc_id_rev"),E=IDBKeyRange.bound(G,D,!1,!1),j=B.openCursor(E);j.onsuccess=function(M){if(j=M.target.result,!j)v.delete(m.primaryKey),m.continue();else{var J=j.value;J._doc_id_rev===L&&s.put(J),l.delete(j.primaryKey),j.continue()}}}else m.continue()}else i&&i()}}function b(o){var i=o.createObjectStore(oe,{autoIncrement:!0});i.createIndex("seq","seq"),i.createIndex("digestSeq","digestSeq",{unique:!0})}function O(o,i){var s=o.objectStore(U),v=o.objectStore(X),l=o.objectStore(oe),f=v.count();f.onsuccess=function(g){var m=g.target.result;if(!m)return i();s.openCursor().onsuccess=function(y){var h=y.target.result;if(!h)return i();for(var R=h.value,C=h.primaryKey,L=Object.keys(R._attachments||{}),G={},D=0;D<L.length;D++){var B=R._attachments[L[D]];G[B.digest]=!0}var E=Object.keys(G);for(D=0;D<E.length;D++){var j=E[D];l.put({seq:C,digestSeq:j+"::"+C})}h.continue()}}}function q(o){function i(f){return f.data?se(f):(f.deleted=f.deletedOrLocal==="1",f)}var s=o.objectStore(U),v=o.objectStore(F),l=v.openCursor();l.onsuccess=function(f){var g=f.target.result;if(!g)return;var m=i(g.value);m.winningRev=m.winningRev||de(m);function y(){var R=m.id+"::",C=m.id+"::￿",L=s.index("_doc_id_rev").openCursor(IDBKeyRange.bound(R,C)),G=0;L.onsuccess=function(D){var B=D.target.result;if(!B)return m.seq=G,h();var E=B.primaryKey;E>G&&(G=E),B.continue()}}function h(){var R=qe(m,m.winningRev,m.deleted),C=v.put(R);C.onsuccess=function(){g.continue()}}if(m.seq)return h();y()}}e._remote=!1,e.type=function(){return"idb"},e._id=tt(function(o){o(null,e._meta.instanceId)}),e._bulkDocs=function(i,s,v){Bt(r,i,s,e,a,c(v))},e._get=function(i,s,v){var l,f,g,m=s.ctx;if(!m){var y=Z(a,[F,U,X],"readonly");if(y.error)return v(y.error);m=y.txn}function h(){v(g,{doc:l,metadata:f,ctx:m})}m.objectStore(F).get(i).onsuccess=function(R){if(f=se(R.target.result),!f)return g=H(ae,"missing"),h();var C;if(s.rev)C=s.latest?lt(s.rev,f):s.rev;else{C=f.winningRev;var L=ie(f);if(L)return g=H(ae,"deleted"),h()}var G=m.objectStore(U),D=f.id+"::"+C;G.index("_doc_id_rev").get(D).onsuccess=function(B){if(l=B.target.result,l&&(l=me(l)),!l)return g=H(ae,"missing"),h();h()}}},e._getAttachment=function(o,i,s,v,l){var f;if(v.ctx)f=v.ctx;else{var g=Z(a,[F,U,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 R=h.target.result.body;Ge(R,y,v.binary,function(C){l(null,C)})}},e._info=function(i){var s,v,l=Z(a,[Y,U],"readonly");if(l.error)return i(l.error);var f=l.txn;f.objectStore(Y).get(Y).onsuccess=function(g){v=g.target.result.docCount},f.objectStore(U).openCursor(null,"prev").onsuccess=function(g){var m=g.target.result;s=m?m.key:0},f.oncomplete=function(){i(null,{doc_count:v,update_seq:s,idb_attachment_format:e._meta.blobSupport?"binary":"base64"})}},e._allDocs=function(i,s){Pt(i,a,c(s))},e._changes=function(i){return Nt(i,e,n,a)},e._close=function(o){a.close(),fe.delete(n),o()},e._getRevisionTree=function(o,i){var s=Z(a,[F],"readonly");if(s.error)return i(s.error);var v=s.txn,l=v.objectStore(F).get(o);l.onsuccess=function(f){var g=se(f.target.result);g?i(null,g.rev_tree):i(H(ae))}},e._doCompaction=function(o,i,s){var v=[F,U,X,oe],l=Z(a,v,"readwrite");if(l.error)return s(l.error);var f=l.txn,g=f.objectStore(F);g.get(o).onsuccess=function(m){var y=se(m.target.result);dt(y.rev_tree,function(C,L,G,D,B){var E=L+"-"+G;i.indexOf(E)!==-1&&(B.status="missing")}),Ve(i,o,f);var h=y.winningRev,R=y.deleted;f.objectStore(F).put(qe(y,h,R))},f.onabort=ee(s),f.oncomplete=function(){s()}},e._getLocal=function(o,i){var s=Z(a,[$],"readonly");if(s.error)return i(s.error);var v=s.txn,l=v.objectStore($).get(o);l.onerror=ee(i),l.onsuccess=function(f){var g=f.target.result;g?(delete g._doc_id_rev,i(null,g)):i(H(ae))}},e._putLocal=function(o,i,s){typeof i=="function"&&(s=i,i={}),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=i.ctx,g;if(!f){var m=Z(a,[$],"readwrite");if(m.error)return s(m.error);f=m.txn,f.onerror=ee(s),f.oncomplete=function(){g&&s(null,g)}}var y=f.objectStore($),h;v?(h=y.get(l),h.onsuccess=function(R){var C=R.target.result;if(!C||C._rev!==v)s(H(_e));else{var L=y.put(o);L.onsuccess=function(){g={ok:!0,id:o._id,rev:o._rev},i.ctx&&s(null,g)}}}):(h=y.add(o),h.onerror=function(R){s(H(_e)),R.preventDefault(),R.stopPropagation()},h.onsuccess=function(){g={ok:!0,id:o._id,rev:o._rev},i.ctx&&s(null,g)})},e._removeLocal=function(o,i,s){typeof i=="function"&&(s=i,i={});var v=i.ctx;if(!v){var l=Z(a,[$],"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=ee(s),y.onsuccess=function(h){var R=h.target.result;!R||R._rev!==o._rev?s(H(ae)):(m.delete(g),f={ok:!0,id:g,rev:"0-0"},i.ctx&&s(null,f))}},e._destroy=function(o,i){le.removeAllListeners(n);var s=xe.get(n);s&&s.result&&(s.result.close(),fe.delete(n));var v=indexedDB.deleteDatabase(n);v.onsuccess=function(){xe.delete(n),rt()&&n in localStorage&&delete localStorage[n],i(null,{ok:!0})},v.onerror=ee(i)};var A=fe.get(n);if(A)return a=A.idb,e._meta=A.global,Ke(function(){t(null,e)});var w=indexedDB.open(n,Ct);xe.set(n,w),w.onupgradeneeded=function(o){var i=o.target.result;if(o.oldVersion<1)return _(i);var s=o.currentTarget.transaction;o.oldVersion<3&&x(i),o.oldVersion<4&&b(i);var v=[d,p,O,q],l=o.oldVersion;function f(){var g=v[l-1];l++,g&&g(s,f)}f()},w.onsuccess=function(o){a=o.target.result,a.onversionchange=function(){a.close(),fe.delete(n)},a.onabort=function(h){Be("error","Database has a global failure",h.target.error),u=h.target.error,a.close(),fe.delete(n)};var i=a.transaction([Y,De,F],"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:a,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=we(),v.docCount=l,i.objectStore(Y).put(v)}}i.objectStore(Y).get(Y).onsuccess=function(h){v=h.target.result||{id:Y},y()},Lt(i,function(h){l=h,y()}),Se||(Se=Kt(i)),Se.then(function(h){f=h,m()}),i.oncomplete=function(){s=!0,m()},i.onabort=ee(t)},w.onerror=function(o){var i=o.target.error&&o.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?",Be("error",i),t(H(Oe,i))}}We.valid=function(){try{return typeof indexedDB<"u"&&typeof IDBKeyRange<"u"}catch{return!1}};function Wt(e){e.adapter("idb",We,!0)}export{Wt as default};
1
+ import{t as Ee,w as Re,r as He,e as Qe,c as W,D as Oe,I as Ue,x as Ye,y as Te,z as Pe,A as Xe,C as Ze,R as _e,M as ae,F as ze,G as $e,H as ke,J as et,q as tt,j as Ke,d as Ce,K as we,L as rt,O as nt,b as at,P as it,h as ot,S as st}from"./index-browser.es2.js";import{i as ge,m as Le,d as ut,w as de,b as ie,l as ct,t as ft,a as vt,e as lt}from"./index.es8.js";import"./index.js";var me={};me.stringify=function(r){var t=[];t.push({obj:r});for(var n="",i,c,u,_,d,D,p,b,C,q,A;i=t.pop();)if(c=i.obj,u=i.prefix||"",_=i.val||"",n+=u,_)n+=_;else if(typeof c!="object")n+=typeof c>"u"?null:JSON.stringify(c);else if(c===null)n+="null";else if(Array.isArray(c)){for(t.push({val:"]"}),d=c.length-1;d>=0;d--)D=d===0?"":",",t.push({obj:c[d],prefix:D});t.push({val:"["})}else{p=[];for(b in c)c.hasOwnProperty(b)&&p.push(b);for(t.push({val:"}"}),d=p.length-1;d>=0;d--)C=p[d],q=c[C],A=d>0?",":"",A+=JSON.stringify(C)+":",t.push({obj:q,prefix:A});t.push({val:"{"})}return n};function ce(e,r,t){var n=t[t.length-1];e===n.element&&(t.pop(),n=t[t.length-1]);var i=n.element,c=n.index;if(Array.isArray(i))i.push(e);else if(c===r.length-2){var u=r.pop();i[u]=e}else r.push(e)}me.parse=function(e){for(var r=[],t=[],n=0,i,c,u,_,d,D,p,b,C;;){if(i=e[n++],i==="}"||i==="]"||typeof i>"u"){if(r.length===1)return r.pop();ce(r.pop(),r,t);continue}switch(i){case" ":case" ":case`
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};
package/dist/index.es8.js CHANGED
@@ -1 +1 @@
1
- import"./index-browser.es2.js";function V(t){for(var s,i,r,e=t.rev_tree.slice(),o;o=e.pop();){var n=o.ids,a=n[2],v=o.pos;if(a.length){for(var l=0,f=a.length;l<f;l++)e.push({pos:v+1,ids:a[l]});continue}var u=!!n[1].deleted,c=n[0];(!s||(r!==u?r:i!==v?i<v:s<c))&&(s=c,i=v,r=u)}return i+"-"+s}function x(t,s){for(var i=t.slice(),r;r=i.pop();)for(var e=r.pos,o=r.ids,n=o[2],a=s(n.length===0,e,o[0],r.ctx,o[1]),v=0,l=n.length;v<l;v++)i.push({pos:e+1,ids:n[v],ctx:a})}function P(t,s){return t.pos-s.pos}function q(t){var s=[];x(t,function(e,o,n,a,v){e&&s.push({rev:o+"-"+n,pos:o,opts:v})}),s.sort(P).reverse();for(var i=0,r=s.length;i<r;i++)delete s[i].pos;return s}function M(t){for(var s=V(t),i=q(t.rev_tree),r=[],e=0,o=i.length;e<o;e++){var n=i[e];n.rev!==s&&!n.opts.deleted&&r.push(n.rev)}return r}function U(t){var s=[];return x(t.rev_tree,function(i,r,e,o,n){n.status==="available"&&!i&&(s.push(r+"-"+e),n.status="missing")}),s}function z(t,s){let i=[];const r=t.slice();let e;for(;e=r.pop();){const{pos:o,ids:n}=e,a=`${o}-${n[0]}`,v=n[2];if(i.push(a),a===s){if(v.length!==0)throw new Error("The requested revision is not a leaf");return i.reverse()}(v.length===0||v.length>1)&&(i=[]);for(let l=0,f=v.length;l<f;l++)r.push({pos:o+1,ids:v[l]})}if(i.length===0)throw new Error("The requested revision does not exist");return i.reverse()}function y(t){for(var s=[],i=t.slice(),r;r=i.pop();){var e=r.pos,o=r.ids,n=o[0],a=o[1],v=o[2],l=v.length===0,f=r.history?r.history.slice():[];f.push({id:n,opts:a}),l&&s.push({pos:e+1-f.length,ids:f});for(var u=0,c=v.length;u<c;u++)i.push({pos:e+1,ids:v[u],history:f})}return s.reverse()}function L(t,s){return t.pos-s.pos}function $(t,s,i){for(var r=0,e=t.length,o;r<e;)o=r+e>>>1,i(t[o],s)<0?r=o+1:e=o;return r}function B(t,s,i){var r=$(t,s,i);t.splice(r,0,s)}function _(t,s){for(var i,r,e=s,o=t.length;e<o;e++){var n=t[e],a=[n.id,n.opts,[]];r?(r[2].push(a),r=a):i=r=a}return i}function D(t,s){return t[0]<s[0]?-1:1}function I(t,s){for(var i=[{tree1:t,tree2:s}],r=!1;i.length>0;){var e=i.pop(),o=e.tree1,n=e.tree2;(o[1].status||n[1].status)&&(o[1].status=o[1].status==="available"||n[1].status==="available"?"available":"missing");for(var a=0;a<n[2].length;a++){if(!o[2][0]){r="new_leaf",o[2][0]=n[2][a];continue}for(var v=!1,l=0;l<o[2].length;l++)o[2][l][0]===n[2][a][0]&&(i.push({tree1:o[2][l],tree2:n[2][a]}),v=!0);v||(r="new_branch",B(o[2],n[2][a],D))}}return{conflicts:r,tree:t}}function R(t,s,i){var r=[],e=!1,o=!1,n;if(!t.length)return{tree:[s],conflicts:"new_leaf"};for(var a=0,v=t.length;a<v;a++){var l=t[a];if(l.pos===s.pos&&l.ids[0]===s.ids[0])n=I(l.ids,s.ids),r.push({pos:l.pos,ids:n.tree}),e=e||n.conflicts,o=!0;else if(i!==!0){var f=l.pos<s.pos?l:s,u=l.pos<s.pos?s:l,c=u.pos-f.pos,h=[],d=[];for(d.push({ids:f.ids,diff:c,parent:null,parentIdx:null});d.length>0;){var p=d.pop();if(p.diff===0){p.ids[0]===u.ids[0]&&h.push(p);continue}for(var g=p.ids[2],w=0,E=g.length;w<E;w++)d.push({ids:g[w],diff:p.diff-1,parent:p.ids,parentIdx:w})}var T=h[0];T?(n=I(T.ids,u.ids),T.parent[2][T.parentIdx]=n.tree,r.push({pos:f.pos,ids:f.ids}),e=e||n.conflicts,o=!0):r.push(l)}else r.push(l)}return o||r.push(s),r.sort(L),{tree:r,conflicts:e||"internal_node"}}function O(t,s){for(var i=y(t),r,e,o=0,n=i.length;o<n;o++){var a=i[o],v=a.ids,l;if(v.length>s){r||(r={});var f=v.length-s;l={pos:a.pos+f,ids:_(v,f)};for(var u=0;u<f;u++){var c=a.pos+u+"-"+v[u].id;r[c]=!0}}else l={pos:a.pos,ids:_(v,0)};e?e=R(e,l,!0).tree:e=[l]}return r&&x(e,function(h,d,p){delete r[d+"-"+p]}),{tree:e,revs:r?Object.keys(r):[]}}function A(t,s,i){var r=R(t,s),e=O(r.tree,i);return{tree:e.tree,stemmedRevs:e.revs,conflicts:r.conflicts}}function F(t,s){for(var i=t.slice(),r=s.split("-"),e=parseInt(r[0],10),o=r[1],n;n=i.pop();){if(n.pos===e&&n.ids[0]===o)return!0;for(var a=n.ids[2],v=0,l=a.length;v<l;v++)i.push({pos:n.pos+1,ids:a[v]})}return!1}function k(t){return t.ids}function G(t,s){s||(s=V(t));for(var i=s.substring(s.indexOf("-")+1),r=t.rev_tree.map(k),e;e=r.pop();){if(e[0]===i)return!!e[1].deleted;r=r.concat(e[2])}}function H(t){return/^_local/.test(t)}function J(t,s){for(var i=s.rev_tree.slice(),r;r=i.pop();){var e=r.pos,o=r.ids,n=o[0],a=o[1],v=o[2],l=v.length===0,f=r.history?r.history.slice():[];if(f.push({id:n,pos:e,opts:a}),l)for(var u=0,c=f.length;u<c;u++){var h=f[u],d=h.pos+"-"+h.id;if(d===t)return e+"-"+n}for(var p=0,g=v.length;p<g;p++)i.push({pos:e+1,ids:v[p],history:f})}throw new Error("Unable to resolve latest revision for id "+s.id+", rev "+t)}export{M as a,G as b,q as c,F as d,U as e,z as f,H as i,J as l,A as m,y as r,x as t,V as w};
1
+ import"./index-browser.es2.js";function V(t){for(var e,i,r,s=t.rev_tree.slice(),n;n=s.pop();){var o=n.ids,v=o[2],a=n.pos;if(v.length){for(var l=0,f=v.length;l<f;l++)s.push({pos:a+1,ids:v[l]});continue}var u=!!o[1].deleted,c=o[0];(!e||(r!==u?r:i!==a?i<a:e<c))&&(e=c,i=a,r=u)}return i+"-"+e}function x(t,e){for(var i=t.slice(),r;r=i.pop();)for(var s=r.pos,n=r.ids,o=n[2],v=e(o.length===0,s,n[0],r.ctx,n[1]),a=0,l=o.length;a<l;a++)i.push({pos:s+1,ids:o[a],ctx:v})}function P(t,e){return t.pos-e.pos}function q(t){var e=[];x(t,function(s,n,o,v,a){s&&e.push({rev:n+"-"+o,pos:n,opts:a})}),e.sort(P).reverse();for(var i=0,r=e.length;i<r;i++)delete e[i].pos;return e}function M(t){for(var e=V(t),i=q(t.rev_tree),r=[],s=0,n=i.length;s<n;s++){var o=i[s];o.rev!==e&&!o.opts.deleted&&r.push(o.rev)}return r}function U(t){var e=[];return x(t.rev_tree,function(i,r,s,n,o){o.status==="available"&&!i&&(e.push(r+"-"+s),o.status="missing")}),e}function W(t,e){let i=[];const r=t.slice();let s;for(;s=r.pop();){const{pos:n,ids:o}=s,v=`${n}-${o[0]}`,a=o[2];if(i.push(v),v===e){if(a.length!==0)throw new Error("The requested revision is not a leaf");return i.reverse()}(a.length===0||a.length>1)&&(i=[]);for(let l=0,f=a.length;l<f;l++)r.push({pos:n+1,ids:a[l]})}if(i.length===0)throw new Error("The requested revision does not exist");return i.reverse()}function L(t){for(var e=[],i=t.slice(),r;r=i.pop();){var s=r.pos,n=r.ids,o=n[0],v=n[1],a=n[2],l=a.length===0,f=r.history?r.history.slice():[];f.push({id:o,opts:v}),l&&e.push({pos:s+1-f.length,ids:f});for(var u=0,c=a.length;u<c;u++)i.push({pos:s+1,ids:a[u],history:f})}return e.reverse()}function $(t,e){return t.pos-e.pos}function y(t,e,i){for(var r=0,s=t.length,n;r<s;)n=r+s>>>1,i(t[n],e)<0?r=n+1:s=n;return r}function B(t,e,i){var r=y(t,e,i);t.splice(r,0,e)}function _(t,e){for(var i,r,s=e,n=t.length;s<n;s++){var o=t[s],v=[o.id,o.opts,[]];r?(r[2].push(v),r=v):i=r=v}return i}function D(t,e){return t[0]<e[0]?-1:1}function I(t,e){for(var i=[{tree1:t,tree2:e}],r=!1;i.length>0;){var s=i.pop(),n=s.tree1,o=s.tree2;(n[1].status||o[1].status)&&(n[1].status=n[1].status==="available"||o[1].status==="available"?"available":"missing");for(var v=0;v<o[2].length;v++){if(!n[2][0]){r="new_leaf",n[2][0]=o[2][v];continue}for(var a=!1,l=0;l<n[2].length;l++)n[2][l][0]===o[2][v][0]&&(i.push({tree1:n[2][l],tree2:o[2][v]}),a=!0);a||(r="new_branch",B(n[2],o[2][v],D))}}return{conflicts:r,tree:t}}function R(t,e,i){var r=[],s=!1,n=!1,o;if(!t.length)return{tree:[e],conflicts:"new_leaf"};for(var v=0,a=t.length;v<a;v++){var l=t[v];if(l.pos===e.pos&&l.ids[0]===e.ids[0])o=I(l.ids,e.ids),r.push({pos:l.pos,ids:o.tree}),s=s||o.conflicts,n=!0;else if(i!==!0){var f=l.pos<e.pos?l:e,u=l.pos<e.pos?e:l,c=u.pos-f.pos,g=[],d=[];for(d.push({ids:f.ids,diff:c,parent:null,parentIdx:null});d.length>0;){var p=d.pop();if(p.diff===0){p.ids[0]===u.ids[0]&&g.push(p);continue}for(var h=p.ids[2],w=0,E=h.length;w<E;w++)d.push({ids:h[w],diff:p.diff-1,parent:p.ids,parentIdx:w})}var T=g[0];T?(o=I(T.ids,u.ids),T.parent[2][T.parentIdx]=o.tree,r.push({pos:f.pos,ids:f.ids}),s=s||o.conflicts,n=!0):r.push(l)}else r.push(l)}return n||r.push(e),r.sort($),{tree:r,conflicts:s||"internal_node"}}function O(t,e){for(var i=L(t),r,s,n=0,o=i.length;n<o;n++){var v=i[n],a=v.ids,l;if(a.length>e){r||(r={});var f=a.length-e;l={pos:v.pos+f,ids:_(a,f)};for(var u=0;u<f;u++){var c=v.pos+u+"-"+a[u].id;r[c]=!0}}else l={pos:v.pos,ids:_(a,0)};s?s=R(s,l,!0).tree:s=[l]}return r&&x(s,function(g,d,p){delete r[d+"-"+p]}),{tree:s,revs:r?Object.keys(r):[]}}function z(t,e,i){var r=R(t,e),s=O(r.tree,i);return{tree:s.tree,stemmedRevs:s.revs,conflicts:r.conflicts}}function A(t,e){for(var i=t.slice(),r=e.split("-"),s=parseInt(r[0],10),n=r[1],o;o=i.pop();){if(o.pos===s&&o.ids[0]===n)return!0;for(var v=o.ids[2],a=0,l=v.length;a<l;a++)i.push({pos:o.pos+1,ids:v[a]})}return!1}function k(t){return t.ids}function F(t,e){e||(e=V(t));for(var i=e.substring(e.indexOf("-")+1),r=t.rev_tree.map(k),s;s=r.pop();){if(s[0]===i)return!!s[1].deleted;r=r.concat(s[2])}}function G(t){return typeof t=="string"&&t.startsWith("_local/")}function H(t,e){for(var i=e.rev_tree.slice(),r;r=i.pop();){var s=r.pos,n=r.ids,o=n[0],v=n[1],a=n[2],l=a.length===0,f=r.history?r.history.slice():[];if(f.push({id:o,pos:s,opts:v}),l)for(var u=0,c=f.length;u<c;u++){var g=f[u],d=g.pos+"-"+g.id;if(d===t)return s+"-"+o}for(var p=0,h=a.length;p<h;p++)i.push({pos:s+1,ids:a[p],history:f})}throw new Error("Unable to resolve latest revision for id "+e.id+", rev "+t)}export{M as a,F as b,q as c,A as d,U as e,W as f,G as i,H as l,z as m,L as r,x as t,V as w};
package/dist/index.es9.js CHANGED
@@ -1 +1 @@
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{Y as a,V as b,s as c,rn 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};
1
+ import{b 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{Y as a,V as b,s as c,rn 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};