8 | !function e(t,n,r){function o(s,u){if(!n[s]){if(!t[s]){var c="function"==typeof require&&require;if(!u&&c)return c(s,!0);if(i)return i(s,!0);var a=new Error("Cannot find module '"+s+"'");throw a.code="MODULE_NOT_FOUND",a}var f=n[s]={exports:{}};t[s][0].call(f.exports,(function(e){return o(t[s][1][e]||e)}),f,f.exports,e,t,n,r)}return n[s].exports}for(var i="function"==typeof require&&require,s=0;s<r.length;s++)o(r[s]);return o}({1:[function(e,t,n){var r=Object.create||function(e){var t=function(){};return t.prototype=e,new t},o=Object.keys||function(e){var t=[];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.push(n);return n},i=Function.prototype.bind||function(e){var t=this;return function(){return t.apply(e,arguments)}};function s(){this._events&&Object.prototype.hasOwnProperty.call(this,"_events")||(this._events=r(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0}t.exports=s,s.EventEmitter=s,s.prototype._events=void 0,s.prototype._maxListeners=void 0;var u,c=10;try{var a={};Object.defineProperty&&Object.defineProperty(a,"x",{value:0}),u=0===a.x}catch(e){u=!1}function f(e){return void 0===e._maxListeners?s.defaultMaxListeners:e._maxListeners}function l(e,t,n){if(t)e.call(n);else for(var r=e.length,o=w(e,r),i=0;i<r;++i)o[i].call(n)}function d(e,t,n,r){if(t)e.call(n,r);else for(var o=e.length,i=w(e,o),s=0;s<o;++s)i[s].call(n,r)}function y(e,t,n,r,o){if(t)e.call(n,r,o);else for(var i=e.length,s=w(e,i),u=0;u<i;++u)s[u].call(n,r,o)}function p(e,t,n,r,o,i){if(t)e.call(n,r,o,i);else for(var s=e.length,u=w(e,s),c=0;c<s;++c)u[c].call(n,r,o,i)}function h(e,t,n,r){if(t)e.apply(n,r);else for(var o=e.length,i=w(e,o),s=0;s<o;++s)i[s].apply(n,r)}function v(e,t,n,o){var i,s,u;if("function"!=typeof n)throw new TypeError('"listener" argument must be a function');if((s=e._events)?(s.newListener&&(e.emit("newListener",t,n.listener?n.listener:n),s=e._events),u=s[t]):(s=e._events=r(null),e._eventsCount=0),u){if("function"==typeof u?u=s[t]=o?[n,u]:[u,n]:o?u.unshift(n):u.push(n),!u.warned&&(i=f(e))&&i>0&&u.length>i){u.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+u.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');c.name="MaxListenersExceededWarning",c.emitter=e,c.type=t,c.count=u.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",c.name,c.message)}}else u=s[t]=n,++e._eventsCount;return e}function g(){if(!this.fired)switch(this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length){case 0:return this.listener.call(this.target);case 1:return this.listener.call(this.target,arguments[0]);case 2:return this.listener.call(this.target,arguments[0],arguments[1]);case 3:return this.listener.call(this.target,arguments[0],arguments[1],arguments[2]);default:for(var e=new Array(arguments.length),t=0;t<e.length;++t)e[t]=arguments[t];this.listener.apply(this.target,e)}}function m(e,t,n){var r={fired:!1,wrapFn:void 0,target:e,type:t,listener:n},o=i.call(g,r);return o.listener=n,r.wrapFn=o,o}function _(e,t,n){var r=e._events;if(!r)return[];var o=r[t];return o?"function"==typeof o?n?[o.listener||o]:[o]:n?function(e){for(var t=new Array(e.length),n=0;n<t.length;++n)t[n]=e[n].listener||e[n];return t}(o):w(o,o.length):[]}function b(e){var t=this._events;if(t){var n=t[e];if("function"==typeof n)return 1;if(n)return n.length}return 0}function w(e,t){for(var n=new Array(t),r=0;r<t;++r)n[r]=e[r];return n}u?Object.defineProperty(s,"defaultMaxListeners",{enumerable:!0,get:function(){return c},set:function(e){if("number"!=typeof e||e<0||e!=e)throw new TypeError('"defaultMaxListeners" must be a positive number');c=e}}):s.defaultMaxListeners=c,s.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||isNaN(e))throw new TypeError('"n" argument must be a positive number');return this._maxListeners=e,this},s.prototype.getMaxListeners=function(){return f(this)},s.prototype.emit=function(e){var t,n,r,o,i,s,u="error"===e;if(s=this._events)u=u&&null==s.error;else if(!u)return!1;if(u){if(arguments.length>1&&(t=arguments[1]),t instanceof Error)throw t;var c=new Error('Unhandled "error" event. ('+t+")");throw c.context=t,c}if(!(n=s[e]))return!1;var a="function"==typeof n;switch(r=arguments.length){case 1:l(n,a,this);break;case 2:d(n,a,this,arguments[1]);break;case 3:y(n,a,this,arguments[1],arguments[2]);break;case 4:p(n,a,this,arguments[1],arguments[2],arguments[3]);break;default:for(o=new Array(r-1),i=1;i<r;i++)o[i-1]=arguments[i];h(n,a,this,o)}return!0},s.prototype.addListener=function(e,t){return v(this,e,t,!1)},s.prototype.on=s.prototype.addListener,s.prototype.prependListener=function(e,t){return v(this,e,t,!0)},s.prototype.once=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.on(e,m(this,e,t)),this},s.prototype.prependOnceListener=function(e,t){if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');return this.prependListener(e,m(this,e,t)),this},s.prototype.removeListener=function(e,t){var n,o,i,s,u;if("function"!=typeof t)throw new TypeError('"listener" argument must be a function');if(!(o=this._events))return this;if(!(n=o[e]))return this;if(n===t||n.listener===t)0==--this._eventsCount?this._events=r(null):(delete o[e],o.removeListener&&this.emit("removeListener",e,n.listener||t));else if("function"!=typeof n){for(i=-1,s=n.length-1;s>=0;s--)if(n[s]===t||n[s].listener===t){u=n[s].listener,i=s;break}if(i<0)return this;0===i?n.shift():function(e,t){for(var n=t,r=n+1,o=e.length;r<o;n+=1,r+=1)e[n]=e[r];e.pop()}(n,i),1===n.length&&(o[e]=n[0]),o.removeListener&&this.emit("removeListener",e,u||t)}return this},s.prototype.removeAllListeners=function(e){var t,n,i;if(!(n=this._events))return this;if(!n.removeListener)return 0===arguments.length?(this._events=r(null),this._eventsCount=0):n[e]&&(0==--this._eventsCount?this._events=r(null):delete n[e]),this;if(0===arguments.length){var s,u=o(n);for(i=0;i<u.length;++i)"removeListener"!==(s=u[i])&&this.removeAllListeners(s);return this.removeAllListeners("removeListener"),this._events=r(null),this._eventsCount=0,this}if("function"==typeof(t=n[e]))this.removeListener(e,t);else if(t)for(i=t.length-1;i>=0;i--)this.removeListener(e,t[i]);return this},s.prototype.listeners=function(e){return _(this,e,!0)},s.prototype.rawListeners=function(e){return _(this,e,!1)},s.listenerCount=function(e,t){return"function"==typeof e.listenerCount?e.listenerCount(t):b.call(e,t)},s.prototype.listenerCount=b,s.prototype.eventNames=function(){return this._eventsCount>0?Reflect.ownKeys(this._events):[]}},{}],2:[function(e,t,n){!function(e){if("object"==typeof n)t.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var r;try{r=window}catch(e){r=self}r.SparkMD5=e()}}((function(e){"use strict";var t=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];function n(e,t){var n=e[0],r=e[1],o=e[2],i=e[3];r=((r+=((o=((o+=((i=((i+=((n=((n+=(r&o|~r&i)+t[0]-680876936|0)<<7|n>>>25)+r|0)&r|~n&o)+t[1]-389564586|0)<<12|i>>>20)+n|0)&n|~i&r)+t[2]+606105819|0)<<17|o>>>15)+i|0)&i|~o&n)+t[3]-1044525330|0)<<22|r>>>10)+o|0,r=((r+=((o=((o+=((i=((i+=((n=((n+=(r&o|~r&i)+t[4]-176418897|0)<<7|n>>>25)+r|0)&r|~n&o)+t[5]+1200080426|0)<<12|i>>>20)+n|0)&n|~i&r)+t[6]-1473231341|0)<<17|o>>>15)+i|0)&i|~o&n)+t[7]-45705983|0)<<22|r>>>10)+o|0,r=((r+=((o=((o+=((i=((i+=((n=((n+=(r&o|~r&i)+t[8]+1770035416|0)<<7|n>>>25)+r|0)&r|~n&o)+t[9]-1958414417|0)<<12|i>>>20)+n|0)&n|~i&r)+t[10]-42063|0)<<17|o>>>15)+i|0)&i|~o&n)+t[11]-1990404162|0)<<22|r>>>10)+o|0,r=((r+=((o=((o+=((i=((i+=((n=((n+=(r&o|~r&i)+t[12]+1804603682|0)<<7|n>>>25)+r|0)&r|~n&o)+t[13]-40341101|0)<<12|i>>>20)+n|0)&n|~i&r)+t[14]-1502002290|0)<<17|o>>>15)+i|0)&i|~o&n)+t[15]+1236535329|0)<<22|r>>>10)+o|0,r=((r+=((o=((o+=((i=((i+=((n=((n+=(r&i|o&~i)+t[1]-165796510|0)<<5|n>>>27)+r|0)&o|r&~o)+t[6]-1069501632|0)<<9|i>>>23)+n|0)&r|n&~r)+t[11]+643717713|0)<<14|o>>>18)+i|0)&n|i&~n)+t[0]-373897302|0)<<20|r>>>12)+o|0,r=((r+=((o=((o+=((i=((i+=((n=((n+=(r&i|o&~i)+t[5]-701558691|0)<<5|n>>>27)+r|0)&o|r&~o)+t[10]+38016083|0)<<9|i>>>23)+n|0)&r|n&~r)+t[15]-660478335|0)<<14|o>>>18)+i|0)&n|i&~n)+t[4]-405537848|0)<<20|r>>>12)+o|0,r=((r+=((o=((o+=((i=((i+=((n=((n+=(r&i|o&~i)+t[9]+568446438|0)<<5|n>>>27)+r|0)&o|r&~o)+t[14]-1019803690|0)<<9|i>>>23)+n|0)&r|n&~r)+t[3]-187363961|0)<<14|o>>>18)+i|0)&n|i&~n)+t[8]+1163531501|0)<<20|r>>>12)+o|0,r=((r+=((o=((o+=((i=((i+=((n=((n+=(r&i|o&~i)+t[13]-1444681467|0)<<5|n>>>27)+r|0)&o|r&~o)+t[2]-51403784|0)<<9|i>>>23)+n|0)&r|n&~r)+t[7]+1735328473|0)<<14|o>>>18)+i|0)&n|i&~n)+t[12]-1926607734|0)<<20|r>>>12)+o|0,r=((r+=((o=((o+=((i=((i+=((n=((n+=(r^o^i)+t[5]-378558|0)<<4|n>>>28)+r|0)^r^o)+t[8]-2022574463|0)<<11|i>>>21)+n|0)^n^r)+t[11]+1839030562|0)<<16|o>>>16)+i|0)^i^n)+t[14]-35309556|0)<<23|r>>>9)+o|0,r=((r+=((o=((o+=((i=((i+=((n=((n+=(r^o^i)+t[1]-1530992060|0)<<4|n>>>28)+r|0)^r^o)+t[4]+1272893353|0)<<11|i>>>21)+n|0)^n^r)+t[7]-155497632|0)<<16|o>>>16)+i|0)^i^n)+t[10]-1094730640|0)<<23|r>>>9)+o|0,r=((r+=((o=((o+=((i=((i+=((n=((n+=(r^o^i)+t[13]+681279174|0)<<4|n>>>28)+r|0)^r^o)+t[0]-358537222|0)<<11|i>>>21)+n|0)^n^r)+t[3]-722521979|0)<<16|o>>>16)+i|0)^i^n)+t[6]+76029189|0)<<23|r>>>9)+o|0,r=((r+=((o=((o+=((i=((i+=((n=((n+=(r^o^i)+t[9]-640364487|0)<<4|n>>>28)+r|0)^r^o)+t[12]-421815835|0)<<11|i>>>21)+n|0)^n^r)+t[15]+530742520|0)<<16|o>>>16)+i|0)^i^n)+t[2]-995338651|0)<<23|r>>>9)+o|0,r=((r+=((i=((i+=(r^((n=((n+=(o^(r|~i))+t[0]-198630844|0)<<6|n>>>26)+r|0)|~o))+t[7]+1126891415|0)<<10|i>>>22)+n|0)^((o=((o+=(n^(i|~r))+t[14]-1416354905|0)<<15|o>>>17)+i|0)|~n))+t[5]-57434055|0)<<21|r>>>11)+o|0,r=((r+=((i=((i+=(r^((n=((n+=(o^(r|~i))+t[12]+1700485571|0)<<6|n>>>26)+r|0)|~o))+t[3]-1894986606|0)<<10|i>>>22)+n|0)^((o=((o+=(n^(i|~r))+t[10]-1051523|0)<<15|o>>>17)+i|0)|~n))+t[1]-2054922799|0)<<21|r>>>11)+o|0,r=((r+=((i=((i+=(r^((n=((n+=(o^(r|~i))+t[8]+1873313359|0)<<6|n>>>26)+r|0)|~o))+t[15]-30611744|0)<<10|i>>>22)+n|0)^((o=((o+=(n^(i|~r))+t[6]-1560198380|0)<<15|o>>>17)+i|0)|~n))+t[13]+1309151649|0)<<21|r>>>11)+o|0,r=((r+=((i=((i+=(r^((n=((n+=(o^(r|~i))+t[4]-145523070|0)<<6|n>>>26)+r|0)|~o))+t[11]-1120210379|0)<<10|i>>>22)+n|0)^((o=((o+=(n^(i|~r))+t[2]+718787259|0)<<15|o>>>17)+i|0)|~n))+t[9]-343485551|0)<<21|r>>>11)+o|0,e[0]=n+e[0]|0,e[1]=r+e[1]|0,e[2]=o+e[2]|0,e[3]=i+e[3]|0}function r(e){var t,n=[];for(t=0;t<64;t+=4)n[t>>2]=e.charCodeAt(t)+(e.charCodeAt(t+1)<<8)+(e.charCodeAt(t+2)<<16)+(e.charCodeAt(t+3)<<24);return n}function o(e){var t,n=[];for(t=0;t<64;t+=4)n[t>>2]=e[t]+(e[t+1]<<8)+(e[t+2]<<16)+(e[t+3]<<24);return n}function i(e){var t,o,i,s,u,c,a=e.length,f=[1732584193,-271733879,-1732584194,271733878];for(t=64;t<=a;t+=64)n(f,r(e.substring(t-64,t)));for(o=(e=e.substring(t-64)).length,i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],t=0;t<o;t+=1)i[t>>2]|=e.charCodeAt(t)<<(t%4<<3);if(i[t>>2]|=128<<(t%4<<3),t>55)for(n(f,i),t=0;t<16;t+=1)i[t]=0;return s=(s=8*a).toString(16).match(/(.*?)(.{0,8})$/),u=parseInt(s[2],16),c=parseInt(s[1],16)||0,i[14]=u,i[15]=c,n(f,i),f}function s(e){var n,r="";for(n=0;n<4;n+=1)r+=t[e>>8*n+4&15]+t[e>>8*n&15];return r}function u(e){var t;for(t=0;t<e.length;t+=1)e[t]=s(e[t]);return e.join("")}function c(e){return/[\u0080-\uFFFF]/.test(e)&&(e=unescape(encodeURIComponent(e))),e}function a(e){var t,n=[],r=e.length;for(t=0;t<r-1;t+=2)n.push(parseInt(e.substr(t,2),16));return String.fromCharCode.apply(String,n)}function f(){this.reset()}return"5d41402abc4b2a76b9719d911017c592"!==u(i("hello"))&&function(e,t){var n=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(n>>16)<<16|65535&n},"undefined"==typeof ArrayBuffer||ArrayBuffer.prototype.slice||function(){function t(e,t){return(e=0|e||0)<0?Math.max(e+t,0):Math.min(e,t)}ArrayBuffer.prototype.slice=function(n,r){var o,i,s,u,c=this.byteLength,a=t(n,c),f=c;return r!==e&&(f=t(r,c)),a>f?new ArrayBuffer(0):(o=f-a,i=new ArrayBuffer(o),s=new Uint8Array(i),u=new Uint8Array(this,a,o),s.set(u),i)}}(),f.prototype.append=function(e){return this.appendBinary(c(e)),this},f.prototype.appendBinary=function(e){this._buff+=e,this._length+=e.length;var t,o=this._buff.length;for(t=64;t<=o;t+=64)n(this._hash,r(this._buff.substring(t-64,t)));return this._buff=this._buff.substring(t-64),this},f.prototype.end=function(e){var t,n,r=this._buff,o=r.length,i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(t=0;t<o;t+=1)i[t>>2]|=r.charCodeAt(t)<<(t%4<<3);return this._finish(i,o),n=u(this._hash),e&&(n=a(n)),this.reset(),n},f.prototype.reset=function(){return this._buff="",this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},f.prototype.getState=function(){return{buff:this._buff,length:this._length,hash:this._hash.slice()}},f.prototype.setState=function(e){return this._buff=e.buff,this._length=e.length,this._hash=e.hash,this},f.prototype.destroy=function(){delete this._hash,delete this._buff,delete this._length},f.prototype._finish=function(e,t){var r,o,i,s=t;if(e[s>>2]|=128<<(s%4<<3),s>55)for(n(this._hash,e),s=0;s<16;s+=1)e[s]=0;r=(r=8*this._length).toString(16).match(/(.*?)(.{0,8})$/),o=parseInt(r[2],16),i=parseInt(r[1],16)||0,e[14]=o,e[15]=i,n(this._hash,e)},f.hash=function(e,t){return f.hashBinary(c(e),t)},f.hashBinary=function(e,t){var n=u(i(e));return t?a(n):n},f.ArrayBuffer=function(){this.reset()},f.ArrayBuffer.prototype.append=function(e){var t,r,i,s,u,c=(r=this._buff.buffer,i=e,s=!0,(u=new Uint8Array(r.byteLength+i.byteLength)).set(new Uint8Array(r)),u.set(new Uint8Array(i),r.byteLength),s?u:u.buffer),a=c.length;for(this._length+=e.byteLength,t=64;t<=a;t+=64)n(this._hash,o(c.subarray(t-64,t)));return this._buff=t-64<a?new Uint8Array(c.buffer.slice(t-64)):new Uint8Array(0),this},f.ArrayBuffer.prototype.end=function(e){var t,n,r=this._buff,o=r.length,i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(t=0;t<o;t+=1)i[t>>2]|=r[t]<<(t%4<<3);return this._finish(i,o),n=u(this._hash),e&&(n=a(n)),this.reset(),n},f.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array(0),this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},f.ArrayBuffer.prototype.getState=function(){var e,t=f.prototype.getState.call(this);return t.buff=(e=t.buff,String.fromCharCode.apply(null,new Uint8Array(e))),t},f.ArrayBuffer.prototype.setState=function(e){return e.buff=function(e,t){var n,r=e.length,o=new ArrayBuffer(r),i=new Uint8Array(o);for(n=0;n<r;n+=1)i[n]=e.charCodeAt(n);return t?i:o}(e.buff,!0),f.prototype.setState.call(this,e)},f.ArrayBuffer.prototype.destroy=f.prototype.destroy,f.ArrayBuffer.prototype._finish=f.prototype._finish,f.ArrayBuffer.hash=function(e,t){var r=u(function(e){var t,r,i,s,u,c,a=e.length,f=[1732584193,-271733879,-1732584194,271733878];for(t=64;t<=a;t+=64)n(f,o(e.subarray(t-64,t)));for(r=(e=t-64<a?e.subarray(t-64):new Uint8Array(0)).length,i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],t=0;t<r;t+=1)i[t>>2]|=e[t]<<(t%4<<3);if(i[t>>2]|=128<<(t%4<<3),t>55)for(n(f,i),t=0;t<16;t+=1)i[t]=0;return s=(s=8*a).toString(16).match(/(.*?)(.{0,8})$/),u=parseInt(s[2],16),c=parseInt(s[1],16)||0,i[14]=u,i[15]=c,n(f,i),f}(new Uint8Array(e)));return t?a(r):r},f}))},{}],3:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),Object.defineProperty(n,"v1",{enumerable:!0,get:function(){return r.default}}),Object.defineProperty(n,"v3",{enumerable:!0,get:function(){return o.default}}),Object.defineProperty(n,"v4",{enumerable:!0,get:function(){return i.default}}),Object.defineProperty(n,"v5",{enumerable:!0,get:function(){return s.default}}),Object.defineProperty(n,"NIL",{enumerable:!0,get:function(){return u.default}}),Object.defineProperty(n,"version",{enumerable:!0,get:function(){return c.default}}),Object.defineProperty(n,"validate",{enumerable:!0,get:function(){return a.default}}),Object.defineProperty(n,"stringify",{enumerable:!0,get:function(){return f.default}}),Object.defineProperty(n,"parse",{enumerable:!0,get:function(){return l.default}});var r=d(e("./v1.js")),o=d(e("./v3.js")),i=d(e("./v4.js")),s=d(e("./v5.js")),u=d(e("./nil.js")),c=d(e("./version.js")),a=d(e("./validate.js")),f=d(e("./stringify.js")),l=d(e("./parse.js"));function d(e){return e&&e.__esModule?e:{default:e}}},{"./nil.js":5,"./parse.js":6,"./stringify.js":10,"./v1.js":11,"./v3.js":12,"./v4.js":14,"./v5.js":15,"./validate.js":16,"./version.js":17}],4:[function(e,t,n){"use strict";function r(e){return 14+(e+64>>>9<<4)+1}function o(e,t){const n=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(n>>16)<<16|65535&n}function i(e,t,n,r,i,s){return o((u=o(o(t,e),o(r,s)))<<(c=i)|u>>>32-c,n);var u,c}function s(e,t,n,r,o,s,u){return i(t&n|~t&r,e,t,o,s,u)}function u(e,t,n,r,o,s,u){return i(t&r|n&~r,e,t,o,s,u)}function c(e,t,n,r,o,s,u){return i(t^n^r,e,t,o,s,u)}function a(e,t,n,r,o,s,u){return i(n^(t|~r),e,t,o,s,u)}Object.defineProperty(n,"__esModule",{value:!0}),n.default=void 0;var f=function(e){if("string"==typeof e){const t=unescape(encodeURIComponent(e));e=new Uint8Array(t.length);for(let n=0;n<t.length;++n)e[n]=t.charCodeAt(n)}return function(e){const t=[],n=32*e.length;for(let r=0;r<n;r+=8){const n=e[r>>5]>>>r%32&255,o=parseInt("0123456789abcdef".charAt(n>>>4&15)+"0123456789abcdef".charAt(15&n),16);t.push(o)}return t}(function(e,t){e[t>>5]|=128<<t%32,e[r(t)-1]=t;let n=1732584193,i=-271733879,f=-1732584194,l=271733878;for(let t=0;t<e.length;t+=16){const r=n,d=i,y=f,p=l;n=s(n,i,f,l,e[t],7,-680876936),l=s(l,n,i,f,e[t+1],12,-389564586),f=s(f,l,n,i,e[t+2],17,606105819),i=s(i,f,l,n,e[t+3],22,-1044525330),n=s(n,i,f,l,e[t+4],7,-176418897),l=s(l,n,i,f,e[t+5],12,1200080426),f=s(f,l,n,i,e[t+6],17,-1473231341),i=s(i,f,l,n,e[t+7],22,-45705983),n=s(n,i,f,l,e[t+8],7,1770035416),l=s(l,n,i,f,e[t+9],12,-1958414417),f=s(f,l,n,i,e[t+10],17,-42063),i=s(i,f,l,n,e[t+11],22,-1990404162),n=s(n,i,f,l,e[t+12],7,1804603682),l=s(l,n,i,f,e[t+13],12,-40341101),f=s(f,l,n,i,e[t+14],17,-1502002290),i=s(i,f,l,n,e[t+15],22,1236535329),n=u(n,i,f,l,e[t+1],5,-165796510),l=u(l,n,i,f,e[t+6],9,-1069501632),f=u(f,l,n,i,e[t+11],14,643717713),i=u(i,f,l,n,e[t],20,-373897302),n=u(n,i,f,l,e[t+5],5,-701558691),l=u(l,n,i,f,e[t+10],9,38016083),f=u(f,l,n,i,e[t+15],14,-660478335),i=u(i,f,l,n,e[t+4],20,-405537848),n=u(n,i,f,l,e[t+9],5,568446438),l=u(l,n,i,f,e[t+14],9,-1019803690),f=u(f,l,n,i,e[t+3],14,-187363961),i=u(i,f,l,n,e[t+8],20,1163531501),n=u(n,i,f,l,e[t+13],5,-1444681467),l=u(l,n,i,f,e[t+2],9,-51403784),f=u(f,l,n,i,e[t+7],14,1735328473),i=u(i,f,l,n,e[t+12],20,-1926607734),n=c(n,i,f,l,e[t+5],4,-378558),l=c(l,n,i,f,e[t+8],11,-2022574463),f=c(f,l,n,i,e[t+11],16,1839030562),i=c(i,f,l,n,e[t+14],23,-35309556),n=c(n,i,f,l,e[t+1],4,-1530992060),l=c(l,n,i,f,e[t+4],11,1272893353),f=c(f,l,n,i,e[t+7],16,-155497632),i=c(i,f,l,n,e[t+10],23,-1094730640),n=c(n,i,f,l,e[t+13],4,681279174),l=c(l,n,i,f,e[t],11,-358537222),f=c(f,l,n,i,e[t+3],16,-722521979),i=c(i,f,l,n,e[t+6],23,76029189),n=c(n,i,f,l,e[t+9],4,-640364487),l=c(l,n,i,f,e[t+12],11,-421815835),f=c(f,l,n,i,e[t+15],16,530742520),i=c(i,f,l,n,e[t+2],23,-995338651),n=a(n,i,f,l,e[t],6,-198630844),l=a(l,n,i,f,e[t+7],10,1126891415),f=a(f,l,n,i,e[t+14],15,-1416354905),i=a(i,f,l,n,e[t+5],21,-57434055),n=a(n,i,f,l,e[t+12],6,1700485571),l=a(l,n,i,f,e[t+3],10,-1894986606),f=a(f,l,n,i,e[t+10],15,-1051523),i=a(i,f,l,n,e[t+1],21,-2054922799),n=a(n,i,f,l,e[t+8],6,1873313359),l=a(l,n,i,f,e[t+15],10,-30611744),f=a(f,l,n,i,e[t+6],15,-1560198380),i=a(i,f,l,n,e[t+13],21,1309151649),n=a(n,i,f,l,e[t+4],6,-145523070),l=a(l,n,i,f,e[t+11],10,-1120210379),f=a(f,l,n,i,e[t+2],15,718787259),i=a(i,f,l,n,e[t+9],21,-343485551),n=o(n,r),i=o(i,d),f=o(f,y),l=o(l,p)}return[n,i,f,l]}(function(e){if(0===e.length)return[];const t=8*e.length,n=new Uint32Array(r(t));for(let r=0;r<t;r+=8)n[r>>5]|=(255&e[r/8])<<r%32;return n}(e),8*e.length))};n.default=f},{}],5:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default=void 0;n.default="00000000-0000-0000-0000-000000000000"},{}],6:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default=void 0;var r,o=(r=e("./validate.js"))&&r.__esModule?r:{default:r};var i=function(e){if(!(0,o.default)(e))throw TypeError("Invalid UUID");let t;const n=new Uint8Array(16);return n[0]=(t=parseInt(e.slice(0,8),16))>>>24,n[1]=t>>>16&255,n[2]=t>>>8&255,n[3]=255&t,n[4]=(t=parseInt(e.slice(9,13),16))>>>8,n[5]=255&t,n[6]=(t=parseInt(e.slice(14,18),16))>>>8,n[7]=255&t,n[8]=(t=parseInt(e.slice(19,23),16))>>>8,n[9]=255&t,n[10]=(t=parseInt(e.slice(24,36),16))/1099511627776&255,n[11]=t/4294967296&255,n[12]=t>>>24&255,n[13]=t>>>16&255,n[14]=t>>>8&255,n[15]=255&t,n};n.default=i},{"./validate.js":16}],7:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default=void 0;n.default=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i},{}],8:[function(e,t,n){"use strict";let r;Object.defineProperty(n,"__esModule",{value:!0}),n.default=function(){if(!r&&(r="undefined"!=typeof crypto&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||"undefined"!=typeof msCrypto&&"function"==typeof msCrypto.getRandomValues&&msCrypto.getRandomValues.bind(msCrypto),!r))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return r(o)};const o=new Uint8Array(16)},{}],9:[function(e,t,n){"use strict";function r(e,t,n,r){switch(e){case 0:return t&n^~t&r;case 1:return t^n^r;case 2:return t&n^t&r^n&r;case 3:return t^n^r}}function o(e,t){return e<<t|e>>>32-t}Object.defineProperty(n,"__esModule",{value:!0}),n.default=void 0;var i=function(e){const t=[1518500249,1859775393,2400959708,3395469782],n=[1732584193,4023233417,2562383102,271733878,3285377520];if("string"==typeof e){const t=unescape(encodeURIComponent(e));e=[];for(let n=0;n<t.length;++n)e.push(t.charCodeAt(n))}else Array.isArray(e)||(e=Array.prototype.slice.call(e));e.push(128);const i=e.length/4+2,s=Math.ceil(i/16),u=new Array(s);for(let t=0;t<s;++t){const n=new Uint32Array(16);for(let r=0;r<16;++r)n[r]=e[64*t+4*r]<<24|e[64*t+4*r+1]<<16|e[64*t+4*r+2]<<8|e[64*t+4*r+3];u[t]=n}u[s-1][14]=8*(e.length-1)/Math.pow(2,32),u[s-1][14]=Math.floor(u[s-1][14]),u[s-1][15]=8*(e.length-1)&4294967295;for(let e=0;e<s;++e){const i=new Uint32Array(80);for(let t=0;t<16;++t)i[t]=u[e][t];for(let e=16;e<80;++e)i[e]=o(i[e-3]^i[e-8]^i[e-14]^i[e-16],1);let s=n[0],c=n[1],a=n[2],f=n[3],l=n[4];for(let e=0;e<80;++e){const n=Math.floor(e/20),u=o(s,5)+r(n,c,a,f)+l+t[n]+i[e]>>>0;l=f,f=a,a=o(c,30)>>>0,c=s,s=u}n[0]=n[0]+s>>>0,n[1]=n[1]+c>>>0,n[2]=n[2]+a>>>0,n[3]=n[3]+f>>>0,n[4]=n[4]+l>>>0}return[n[0]>>24&255,n[0]>>16&255,n[0]>>8&255,255&n[0],n[1]>>24&255,n[1]>>16&255,n[1]>>8&255,255&n[1],n[2]>>24&255,n[2]>>16&255,n[2]>>8&255,255&n[2],n[3]>>24&255,n[3]>>16&255,n[3]>>8&255,255&n[3],n[4]>>24&255,n[4]>>16&255,n[4]>>8&255,255&n[4]]};n.default=i},{}],10:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default=void 0;var r,o=(r=e("./validate.js"))&&r.__esModule?r:{default:r};const i=[];for(let e=0;e<256;++e)i.push((e+256).toString(16).substr(1));var s=function(e,t=0){const n=(i[e[t+0]]+i[e[t+1]]+i[e[t+2]]+i[e[t+3]]+"-"+i[e[t+4]]+i[e[t+5]]+"-"+i[e[t+6]]+i[e[t+7]]+"-"+i[e[t+8]]+i[e[t+9]]+"-"+i[e[t+10]]+i[e[t+11]]+i[e[t+12]]+i[e[t+13]]+i[e[t+14]]+i[e[t+15]]).toLowerCase();if(!(0,o.default)(n))throw TypeError("Stringified UUID is invalid");return n};n.default=s},{"./validate.js":16}],11:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default=void 0;var r=i(e("./rng.js")),o=i(e("./stringify.js"));function i(e){return e&&e.__esModule?e:{default:e}}let s,u,c=0,a=0;var f=function(e,t,n){let i=t&&n||0;const f=t||new Array(16);let l=(e=e||{}).node||s,d=void 0!==e.clockseq?e.clockseq:u;if(null==l||null==d){const t=e.random||(e.rng||r.default)();null==l&&(l=s=[1|t[0],t[1],t[2],t[3],t[4],t[5]]),null==d&&(d=u=16383&(t[6]<<8|t[7]))}let y=void 0!==e.msecs?e.msecs:Date.now(),p=void 0!==e.nsecs?e.nsecs:a+1;const h=y-c+(p-a)/1e4;if(h<0&&void 0===e.clockseq&&(d=d+1&16383),(h<0||y>c)&&void 0===e.nsecs&&(p=0),p>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");c=y,a=p,u=d,y+=122192928e5;const v=(1e4*(268435455&y)+p)%4294967296;f[i++]=v>>>24&255,f[i++]=v>>>16&255,f[i++]=v>>>8&255,f[i++]=255&v;const g=y/4294967296*1e4&268435455;f[i++]=g>>>8&255,f[i++]=255&g,f[i++]=g>>>24&15|16,f[i++]=g>>>16&255,f[i++]=d>>>8|128,f[i++]=255&d;for(let e=0;e<6;++e)f[i+e]=l[e];return t||(0,o.default)(f)};n.default=f},{"./rng.js":8,"./stringify.js":10}],12:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default=void 0;var r=i(e("./v35.js")),o=i(e("./md5.js"));function i(e){return e&&e.__esModule?e:{default:e}}var s=(0,r.default)("v3",48,o.default);n.default=s},{"./md5.js":4,"./v35.js":13}],13:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default=function(e,t,n){function i(e,i,s,u){if("string"==typeof e&&(e=function(e){e=unescape(encodeURIComponent(e));const t=[];for(let n=0;n<e.length;++n)t.push(e.charCodeAt(n));return t}(e)),"string"==typeof i&&(i=(0,o.default)(i)),16!==i.length)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let c=new Uint8Array(16+e.length);if(c.set(i),c.set(e,i.length),c=n(c),c[6]=15&c[6]|t,c[8]=63&c[8]|128,s){u=u||0;for(let e=0;e<16;++e)s[u+e]=c[e];return s}return(0,r.default)(c)}try{i.name=e}catch(e){}return i.DNS=s,i.URL=u,i},n.URL=n.DNS=void 0;var r=i(e("./stringify.js")),o=i(e("./parse.js"));function i(e){return e&&e.__esModule?e:{default:e}}const s="6ba7b810-9dad-11d1-80b4-00c04fd430c8";n.DNS=s;const u="6ba7b811-9dad-11d1-80b4-00c04fd430c8";n.URL=u},{"./parse.js":6,"./stringify.js":10}],14:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default=void 0;var r=i(e("./rng.js")),o=i(e("./stringify.js"));function i(e){return e&&e.__esModule?e:{default:e}}var s=function(e,t,n){const i=(e=e||{}).random||(e.rng||r.default)();if(i[6]=15&i[6]|64,i[8]=63&i[8]|128,t){n=n||0;for(let e=0;e<16;++e)t[n+e]=i[e];return t}return(0,o.default)(i)};n.default=s},{"./rng.js":8,"./stringify.js":10}],15:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default=void 0;var r=i(e("./v35.js")),o=i(e("./sha1.js"));function i(e){return e&&e.__esModule?e:{default:e}}var s=(0,r.default)("v5",80,o.default);n.default=s},{"./sha1.js":9,"./v35.js":13}],16:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default=void 0;var r,o=(r=e("./regex.js"))&&r.__esModule?r:{default:r};var i=function(e){return"string"==typeof e&&o.default.test(e)};n.default=i},{"./regex.js":7}],17:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default=void 0;var r,o=(r=e("./validate.js"))&&r.__esModule?r:{default:r};var i=function(e){if(!(0,o.default)(e))throw TypeError("Invalid UUID");return parseInt(e.substr(14,1),16)};n.default=i},{"./validate.js":16}],18:[function(e,t,n){"use strict";e("events"),e("uuid");var r,o=(r=e("spark-md5"))&&"object"==typeof r&&"default"in r?r.default:r;var i=Function.prototype.toString,s=i.call(Object);function u(e){var t,n,r;if(!e||"object"!=typeof e)return e;if(Array.isArray(e)){for(t=[],n=0,r=e.length;n<r;n++)t[n]=u(e[n]);return t}if(e instanceof Date&&isFinite(e))return e.toISOString();if(function(e){return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer||"undefined"!=typeof Blob&&e instanceof Blob}(e))return function(e){return e instanceof ArrayBuffer?e.slice(0):e.slice(0,e.size,e.type)}(e);if(!function(e){var t=Object.getPrototypeOf(e);if(null===t)return!0;var n=t.constructor;return"function"==typeof n&&n instanceof n&&i.call(n)==s}(e))return e;for(n in t={},e)if(Object.prototype.hasOwnProperty.call(e,n)){var o=u(e[n]);void 0!==o&&(t[n]=o)}return t}try{localStorage.setItem("_pouch_check_localstorage",1),!!localStorage.getItem("_pouch_check_localstorage")}catch(e){!1}const c="function"==typeof queueMicrotask?queueMicrotask:function(e){Promise.resolve().then(e)};function a(e){if("undefined"!=typeof console&&"function"==typeof console[e]){var t=Array.prototype.slice.call(arguments,1);console[e].apply(console,t)}}class f extends Error{constructor(e,t,n){super(),this.status=e,this.name=t,this.message=n,this.error=!0}toString(){return JSON.stringify({status:this.status,name:this.name,message:this.message,reason:this.reason})}}new f(401,"unauthorized","Name or password is incorrect."),new f(400,"bad_request","Missing JSON list of 'docs'"),new f(404,"not_found","missing"),new f(409,"conflict","Document update conflict"),new f(400,"bad_request","_id field must contain a string"),new f(412,"missing_id","_id is required for puts"),new f(400,"bad_request","Only reserved document ids may start with underscore."),new f(412,"precondition_failed","Database not open");var l=new f(500,"unknown_error","Database encountered an unknown error");new f(500,"badarg","Some query argument is invalid"),new f(400,"invalid_request","Request was invalid"),new f(400,"query_parse_error","Some query parameter is invalid"),new f(500,"doc_validation","Bad special document member"),new f(400,"bad_request","Something wrong with the request"),new f(400,"bad_request","Document must be a JSON object"),new f(404,"not_found","Database not found"),new f(500,"indexed_db_went_bad","unknown"),new f(500,"web_sql_went_bad","unknown"),new f(500,"levelDB_went_went_bad","unknown"),new f(403,"forbidden","Forbidden by design doc validate_doc_update function"),new f(400,"bad_request","Invalid rev format"),new f(412,"file_exists","The database could not be created, the file already exists."),new f(412,"missing_stub","A pre-existing attachment stub wasn't found"),new f(413,"invalid_url","Provided URL is invalid");function d(e){if("object"!=typeof e){var t=e;(e=l).data=t}return"error"in e&&"conflict"===e.error&&(e.name="conflict",e.status=409),"name"in e||(e.name=e.error||"unknown"),"status"in e||(e.status=500),"message"in e||(e.message=e.message||e.reason),"stack"in e||(e.stack=(new Error).stack),e}function y(e){return"boolean"==typeof e._remote?e._remote:"function"==typeof e.type&&(a("warn","db.type() is deprecated and will be removed in a future version of PouchDB"),"http"===e.type())}function p(e,t,n){return e.get(t).catch((function(e){if(404!==e.status)throw e;return{}})).then((function(r){var o=r._rev,i=n(r);return i?(i._id=t,i._rev=o,function(e,t,n){return e.put(t).then((function(e){return{updated:!0,rev:e.rev}}),(function(r){if(409!==r.status)throw r;return p(e,t._id,n)}))}(e,i,n)):{updated:!1,rev:o}}))}function h(e){for(var t=e.length,n=new ArrayBuffer(t),r=new Uint8Array(n),o=0;o<t;o++)r[o]=e.charCodeAt(o);return n}function v(e,t){return function(e,t){e=e||[],t=t||{};try{return new Blob(e,t)}catch(o){if("TypeError"!==o.name)throw o;for(var n=new("undefined"!=typeof BlobBuilder?BlobBuilder:"undefined"!=typeof MSBlobBuilder?MSBlobBuilder:"undefined"!=typeof MozBlobBuilder?MozBlobBuilder:WebKitBlobBuilder),r=0;r<e.length;r+=1)n.append(e[r]);return n.getBlob(t.type)}}([h(e)],{type:t})}function g(e,t){return v(atob(e),t)}self.setImmediate||self.setTimeout;function m(e){return o.hash(e)}function _(e,t){for(var n=e,r=0,o=t.length;r<o;r++){if(!(n=n[t[r]]))break}return n}function b(e,t,n){for(var r=0,o=t.length;r<o-1;r++){var i=t[r];e=e[i]=e[i]||{}}e[t[o-1]]=n}function w(e,t){return e<t?-1:e>t?1:0}function k(e){for(var t=[],n="",r=0,o=e.length;r<o;r++){var i=e[r];r>0&&"\\"===e[r-1]&&("$"===i||"."===i)?n=n.substring(0,n.length-1)+i:"."===i?(t.push(n),n=""):n+=i}return t.push(n),t}var j=["$or","$nor","$not"];function $(e){return j.indexOf(e)>-1}function x(e){return Object.keys(e)[0]}function O(e){return e[x(e)]}function A(e){var t={},n={$or:!0,$nor:!0};return e.forEach((function(e){Object.keys(e).forEach((function(r){var o=e[r];if("object"!=typeof o&&(o={$eq:o}),$(r))if(o instanceof Array){if(n[r])return n[r]=!1,void(t[r]=o);var i=[];t[r].forEach((function(e){Object.keys(o).forEach((function(t){var n=o[t],r=Math.max(Object.keys(e).length,Object.keys(n).length),s=A([e,n]);Object.keys(s).length<=r||i.push(s)}))})),t[r]=i}else t[r]=A([o]);else{var s=t[r]=t[r]||{};Object.keys(o).forEach((function(e){var t=o[e];return"$gt"===e||"$gte"===e?function(e,t,n){if(void 0!==n.$eq)return;void 0!==n.$gte?"$gte"===e?t>n.$gte&&(n.$gte=t):t>=n.$gte&&(delete n.$gte,n.$gt=t):void 0!==n.$gt?"$gte"===e?t>n.$gt&&(delete n.$gt,n.$gte=t):t>n.$gt&&(n.$gt=t):n[e]=t}(e,t,s):"$lt"===e||"$lte"===e?function(e,t,n){if(void 0!==n.$eq)return;void 0!==n.$lte?"$lte"===e?t<n.$lte&&(n.$lte=t):t<=n.$lte&&(delete n.$lte,n.$lt=t):void 0!==n.$lt?"$lte"===e?t<n.$lt&&(delete n.$lt,n.$lte=t):t<n.$lt&&(n.$lt=t):n[e]=t}(e,t,s):"$ne"===e?function(e,t){"$ne"in t?t.$ne.push(e):t.$ne=[e]}(t,s):"$eq"===e?function(e,t){delete t.$gt,delete t.$gte,delete t.$lt,delete t.$lte,delete t.$ne,t.$eq=e}(t,s):"$regex"===e?function(e,t){"$regex"in t?t.$regex.push(e):t.$regex=[e]}(t,s):void(s[e]=t)}))}}))})),t}function q(e){var t=u(e);(function e(t,n){for(var r in t){"$and"===r&&(n=!0);var o=t[r];"object"==typeof o&&(n=e(o,n))}return n})(t,!1)&&"$and"in(t=function e(t){for(var n in t){if(Array.isArray(t))for(var r in t)t[r].$and&&(t[r]=A(t[r].$and));var o=t[n];"object"==typeof o&&e(o)}return t}(t))&&(t=A(t.$and)),["$or","$nor"].forEach((function(e){e in t&&t[e].forEach((function(e){for(var t=Object.keys(e),n=0;n<t.length;n++){var r=t[n],o=e[r];"object"==typeof o&&null!==o||(e[r]={$eq:o})}}))})),"$not"in t&&(t.$not=A([t.$not]));for(var n=Object.keys(t),r=0;r<n.length;r++){var o=n[r],i=t[o];"object"==typeof i&&null!==i||(i={$eq:i}),t[o]=i}return function e(t){Object.keys(t).forEach((function(n){var r=t[n];Array.isArray(r)?r.forEach((function(t){t&&"object"==typeof t&&e(t)})):"$ne"===n?t.$ne=[r]:"$regex"===n?t.$regex=[r]:r&&"object"==typeof r&&e(r)}))}(t),t}function M(e,t){if(e===t)return 0;e=E(e),t=E(t);var n=C(e),r=C(t);if(n-r!=0)return n-r;switch(typeof e){case"number":return e-t;case"boolean":return e<t?-1:1;case"string":return function(e,t){return e===t?0:e>t?1:-1}(e,t)}return Array.isArray(e)?function(e,t){for(var n=Math.min(e.length,t.length),r=0;r<n;r++){var o=M(e[r],t[r]);if(0!==o)return o}return e.length===t.length?0:e.length>t.length?1:-1}(e,t):function(e,t){for(var n=Object.keys(e),r=Object.keys(t),o=Math.min(n.length,r.length),i=0;i<o;i++){var s=M(n[i],r[i]);if(0!==s)return s;if(0!==(s=M(e[n[i]],t[r[i]])))return s}return n.length===r.length?0:n.length>r.length?1:-1}(e,t)}function E(e){switch(typeof e){case"undefined":return null;case"number":return e===1/0||e===-1/0||isNaN(e)?null:e;case"object":var t=e;if(Array.isArray(e)){var n=e.length;e=new Array(n);for(var r=0;r<n;r++)e[r]=E(t[r])}else{if(e instanceof Date)return e.toJSON();if(null!==e)for(var o in e={},t)if(Object.prototype.hasOwnProperty.call(t,o)){var i=t[o];void 0!==i&&(e[o]=E(i))}}}return e}function S(e){if(null!==e)switch(typeof e){case"boolean":return e?1:0;case"number":return function(e){if(0===e)return"1";var t=e.toExponential().split(/e\+?/),n=parseInt(t[1],10),r=e<0,o=r?"0":"2",i=(s=((r?-n:n)- -324).toString(),u="0",c=3,function(e,t,n){for(var r="",o=n-e.length;r.length<o;)r+=t;return r}(s,u,c)+s);var s,u,c;o+=""+i;var a=Math.abs(parseFloat(t[0]));r&&(a=10-a);var f=a.toFixed(20);return f=f.replace(/\.?0+$/,""),o+=""+f}(e);case"string":return e.replace(/\u0002/g,"\x02\x02").replace(/\u0001/g,"\x01\x02").replace(/\u0000/g,"\x01\x01");case"object":var t=Array.isArray(e),n=t?e:Object.keys(e),r=-1,o=n.length,i="";if(t)for(;++r<o;)i+=B(n[r]);else for(;++r<o;){var s=n[r];i+=B(s)+B(e[s])}return i}return""}function B(e){return C(e=E(e))+""+S(e)+"\0"}function P(e,t){var n,r=t;if("1"===e[t])n=0,t++;else{var o="0"===e[t];t++;var i="",s=e.substring(t,t+3),u=parseInt(s,10)+-324;for(o&&(u=-u),t+=3;;){var c=e[t];if("\0"===c)break;i+=c,t++}n=1===(i=i.split(".")).length?parseInt(i,10):parseFloat(i[0]+"."+i[1]),o&&(n-=10),0!==u&&(n=parseFloat(n+"e"+u))}return{num:n,length:t-r}}function I(e,t){var n=e.pop();if(t.length){var r=t[t.length-1];n===r.element&&(t.pop(),r=t[t.length-1]);var o=r.element,i=r.index;if(Array.isArray(o))o.push(n);else if(i===e.length-2){o[e.pop()]=n}else e.push(n)}}function C(e){var t=["boolean","number","string","object"].indexOf(typeof e);return~t?null===e?1:Array.isArray(e)?5:t<3?t+2:t+3:Array.isArray(e)?5:void 0}function L(e,t,n){if(e=e.filter((function(e){return U(e.doc,t.selector,n)})),t.sort){var r=function(e){function t(t){return e.map((function(e){var n=k(x(e));return _(t,n)}))}return function(e,n){var r=M(t(e.doc),t(n.doc));return 0!==r?r:w(e.doc._id,n.doc._id)}}(t.sort);e=e.sort(r),"string"!=typeof t.sort[0]&&"desc"===O(t.sort[0])&&(e=e.reverse())}if("limit"in t||"skip"in t){var o=t.skip||0,i=("limit"in t?t.limit:e.length)+o;e=e.slice(o,i)}return e}function U(e,t,n){return n.every((function(n){var r=t[n],o=k(n),i=_(e,o);return $(n)?function(e,t,n){if("$or"===e)return t.some((function(e){return U(n,e,Object.keys(e))}));if("$not"===e)return!U(n,t,Object.keys(t));return!t.find((function(e){return U(n,e,Object.keys(e))}))}(n,r,e):D(r,e,o,i)}))}function D(e,t,n,r){return!e||("object"==typeof e?Object.keys(e).every((function(o){var i=e[o];if(0===o.indexOf("$"))return N(o,t,i,n,r);var s=k(o);if(void 0===r&&"object"!=typeof i&&s.length>0)return!1;var u=_(r,s);return"object"==typeof i?D(i,t,n,u):N("$eq",t,i,s,u)})):e===r)}function N(e,t,n,r,o){if(!z[e])throw new Error('unknown operator "'+e+'" - should be one of $eq, $lte, $lt, $gt, $gte, $exists, $ne, $in, $nin, $size, $mod, $regex, $elemMatch, $type, $allMatch or $all');return z[e](t,n,r,o)}function T(e){return null!=e}function F(e){return void 0!==e}function R(e,t){return t.some((function(t){return e instanceof Array?e.some((function(e){return 0===M(t,e)})):0===M(t,e)}))}var z={$elemMatch:function(e,t,n,r){return!!Array.isArray(r)&&(0!==r.length&&("object"==typeof r[0]&&null!==r[0]?r.some((function(e){return U(e,t,Object.keys(t))})):r.some((function(r){return D(t,e,n,r)}))))},$allMatch:function(e,t,n,r){return!!Array.isArray(r)&&(0!==r.length&&("object"==typeof r[0]&&null!==r[0]?r.every((function(e){return U(e,t,Object.keys(t))})):r.every((function(r){return D(t,e,n,r)}))))},$eq:function(e,t,n,r){return F(r)&&0===M(r,t)},$gte:function(e,t,n,r){return F(r)&&M(r,t)>=0},$gt:function(e,t,n,r){return F(r)&&M(r,t)>0},$lte:function(e,t,n,r){return F(r)&&M(r,t)<=0},$lt:function(e,t,n,r){return F(r)&&M(r,t)<0},$exists:function(e,t,n,r){return t?F(r):!F(r)},$mod:function(e,t,n,r){return T(r)&&function(e,t){return"number"==typeof e&&parseInt(e,10)===e&&e%t[0]===t[1]}(r,t)},$ne:function(e,t,n,r){return t.every((function(e){return 0!==M(r,e)}))},$in:function(e,t,n,r){return T(r)&&R(r,t)},$nin:function(e,t,n,r){return T(r)&&!R(r,t)},$size:function(e,t,n,r){return T(r)&&Array.isArray(r)&&function(e,t){return e.length===t}(r,t)},$all:function(e,t,n,r){return Array.isArray(r)&&function(e,t){return t.every((function(t){return e.some((function(e){return 0===M(t,e)}))}))}(r,t)},$regex:function(e,t,n,r){return T(r)&&"string"==typeof r&&t.every((function(e){return function(e,t){return new RegExp(t).test(e)}(r,e)}))},$type:function(e,t,n,r){return function(e,t){switch(t){case"null":return null===e;case"boolean":return"boolean"==typeof e;case"number":return"number"==typeof e;case"string":return"string"==typeof e;case"array":return e instanceof Array;case"object":return"[object Object]"==={}.toString.call(e)}}(r,t)}};function J(e,t){if("object"!=typeof t)throw new Error("Selector error: expected a JSON object");var n=L([{doc:e}],{selector:t=q(t)},Object.keys(t));return n&&1===n.length}const V=(...e)=>{let t=[];for(const n of e)Array.isArray(n)?t=t.concat(V(...n)):t.push(n);return t},Q="function"==typeof Array.prototype.flat?(...e)=>e.flat(1/0):V;function K(e){const t={};for(const n of e)Object.assign(t,n);return t}function X(e,t){for(let n=0,r=Math.min(e.length,t.length);n<r;n++)if(e[n]!==t[n])return!1;return!0}function G(e,t){if(e.length!==t.length)return!1;for(let n=0,r=e.length;n<r;n++)if(e[n]!==t[n])return!1;return!0}function W(e){return function(...t){const n=t[t.length-1];if("function"!=typeof n)return e.apply(this,t);{const r=n.bind(null,null),o=n.bind(null);e.apply(this,t.slice(0,-1)).then(r,o)}}}var Y=Headers;function H(e){(e=u(e)).index||(e.index={});for(const t of["type","name","ddoc"])e.index[t]&&(e[t]=e.index[t],delete e.index[t]);return e.fields&&(e.index.fields=e.fields,delete e.fields),e.type||(e.type="json"),e}function Z(e){return"object"==typeof e&&null!==e}function ee(e,t,n){let r="",o=t,i=!0;if(-1!==["$in","$nin","$or","$and","$mod","$nor","$all"].indexOf(e)&&(Array.isArray(t)||(r="Query operator "+e+" must be an array.")),-1!==["$not","$elemMatch","$allMatch"].indexOf(e)&&(!Array.isArray(t)&&Z(t)||(r="Query operator "+e+" must be an object.")),"$mod"===e&&Array.isArray(t))if(2!==t.length)r="Query operator $mod must be in the format [divisor, remainder], where divisor and remainder are both integers.";else{const e=t[0],n=t[1];0===e&&(r="Query operator $mod's divisor cannot be 0, cannot divide by zero.",i=!1),"number"==typeof e&&parseInt(e,10)===e||(r="Query operator $mod's divisor is not an integer.",o=e),parseInt(n,10)!==n&&(r="Query operator $mod's remainder is not an integer.",o=n)}if("$exists"===e&&"boolean"!=typeof t&&(r="Query operator $exists must be a boolean."),"$type"===e){const e=["null","boolean","number","string","array","object"],n='"'+e.slice(0,e.length-1).join('", "')+'", or "'+e[e.length-1]+'"';("string"!=typeof t||-1==e.indexOf(t))&&(r="Query operator $type must be a string. Supported values: "+n+".")}if("$size"===e&&parseInt(t,10)!==t&&(r="Query operator $size must be a integer."),"$regex"===e&&"string"!=typeof t&&(n?r="Query operator $regex must be a string.":t instanceof RegExp||(r="Query operator $regex must be a string or an instance of a javascript regular expression.")),r){if(i){r+=" Received"+(null===o?" ":Array.isArray(o)?" array":" "+typeof o)+": "+(Z(o)?JSON.stringify(o,null,"\t"):o)}throw new Error(r)}}const te=["$all","$allMatch","$and","$elemMatch","$exists","$in","$mod","$nin","$nor","$not","$or","$regex","$size","$type"],ne=["$in","$nin","$mod","$all"],re=["$eq","$gt","$gte","$lt","$lte"];function oe(e,t){if(Array.isArray(e))for(const n of e)Z(n)&&oe(n,t);else for(const[n,r]of Object.entries(e))-1!==te.indexOf(n)&&ee(n,r,t),-1===re.indexOf(n)&&-1===ne.indexOf(n)&&Z(r)&&oe(r,t)}async function ie(e,t,n){n.body&&(n.body=JSON.stringify(n.body),n.headers=new Y({"Content-type":"application/json"}));const r=await e.fetch(t,n),o=await r.json();if(!r.ok){o.status=r.status;throw d(function(e,t){function n(t){for(var n=Object.getOwnPropertyNames(e),r=0,o=n.length;r<o;r++)"function"!=typeof e[n[r]]&&(this[n[r]]=e[n[r]]);void 0===this.stack&&(this.stack=(new Error).stack),void 0!==t&&(this.reason=t)}return n.prototype=f.prototype,new n(t)}(o))}return o}async function se(e,t){return await ie(e,"_index",{method:"POST",body:H(t)})}async function ue(e,t){return oe(t.selector,!0),await ie(e,"_find",{method:"POST",body:t})}async function ce(e,t){return await ie(e,"_explain",{method:"POST",body:t})}async function ae(e){return await ie(e,"_index",{method:"GET"})}async function fe(e,t){const n=t.ddoc,r=t.type||"json",o=t.name;if(!n)throw new Error("you must provide an index's ddoc");if(!o)throw new Error("you must provide an index's name");const i="_index/"+[n,r,o].map(encodeURIComponent).join("/");return await ie(e,i,{method:"DELETE"})}class le{constructor(){this.promise=Promise.resolve()}add(e){return this.promise=this.promise.catch(()=>{}).then(()=>e()),this.promise}finish(){return this.promise}}function de(e){if(!e)return"undefined";switch(typeof e){case"function":case"string":return e.toString();default:return JSON.stringify(e)}}async function ye(e,t,n,r,o,i){const s=function(e,t){return de(e)+de(t)+"undefined"}(n,r);let u;if(!o&&(u=e._cachedViews=e._cachedViews||{},u[s]))return u[s];const c=e.info().then((async function(c){const a=c.db_name+"-mrview-"+(o?"temp":m(s));await p(e,"_local/"+i,(function(e){e.views=e.views||{};let n=t;-1===n.indexOf("/")&&(n=t+"/"+t);const r=e.views[n]=e.views[n]||{};if(!r[a])return r[a]=!0,e}));const f=(await e.registerDependentDatabase(a)).db;f.auto_compaction=!0;const l={name:a,db:f,sourceDB:e,adapter:e.adapter,mapFun:n,reduceFun:r};let d;try{d=await l.db.get("_local/lastSeq")}catch(e){if(404!==e.status)throw e}return l.seq=d?d.seq:0,u&&l.db.once("destroyed",(function(){delete u[s]})),l}));return u&&(u[s]=c),c}class pe extends Error{constructor(e){super(),this.status=400,this.name="query_parse_error",this.message=e,this.error=!0;try{Error.captureStackTrace(this,pe)}catch(e){}}}class he extends Error{constructor(e){super(),this.status=404,this.name="not_found",this.message=e,this.error=!0;try{Error.captureStackTrace(this,he)}catch(e){}}}class ve extends Error{constructor(e){super(),this.status=500,this.name="invalid_value",this.message=e,this.error=!0;try{Error.captureStackTrace(this,ve)}catch(e){}}}function ge(e,t){return t&&e.then((function(e){c((function(){t(null,e)}))}),(function(e){c((function(){t(e)}))})),e}function me(e,t){return function(){var n=arguments,r=this;return e.add((function(){return t.apply(r,n)}))}}function _e(e){var t=new Set(e),n=new Array(t.size),r=-1;return t.forEach((function(e){n[++r]=e})),n}function be(e){var t=new Array(e.size),n=-1;return e.forEach((function(e,r){t[++n]=r})),t}const we={},ke=new le;function je(e){return-1===e.indexOf("/")?[e,e]:e.split("/")}function $e(e,t,n){try{e.emit("error",t)}catch(e){a("error","The user's map/reduce function threw an uncaught error.\nYou can debug this error by doing:\nmyDatabase.on('error', function (err) { debugger; });\nPlease double-check your map/reduce function."),a("error",t,n)}}function xe(e,t){for(const n of t)if(void 0===(e=e[n]))return;return e}function Oe(e,t,n){const r=function(e){return e.every(e=>-1===e.indexOf("."))}(e),o=1===e.length;return r?o?function(e,t,n){return function(r){n&&!J(r,n)||t(r[e])}}(e[0],t,n):function(e,t,n){return function(r){if(n&&!J(r,n))return;const o=e.map(e=>r[e]);t(o)}}(e,t,n):o?function(e,t,n){const r=k(e);return function(e){if(n&&!J(e,n))return;const o=xe(e,r);void 0!==o&&t(o)}}(e[0],t,n):function(e,t,n){return function(r){if(n&&!J(r,n))return;const o=[];for(const t of e){const e=xe(r,k(t));if(void 0===e)return;o.push(e)}t(o)}}(e,t,n)}const Ae=function(e,t,n,r){function o(e,t,n){try{t(n)}catch(r){$e(e,r,{fun:t,doc:n})}}function i(e,t,n,r,o){try{return{output:t(n,r,o)}}catch(i){return $e(e,i,{fun:t,keys:n,values:r,rereduce:o}),{error:i}}}function s(e,t){const n=M(e.key,t.key);return 0!==n?n:M(e.value,t.value)}function u(e,t,n){return n=n||0,"number"==typeof t?e.slice(n,t+n):n>0?e.slice(n):e}function a(e){const t=e.value;return t&&"object"==typeof t&&t._id||e.id}function f(e){return function(t){return e.include_docs&&e.attachments&&e.binary&&function(e){for(const t of e.rows){const e=t.doc&&t.doc._attachments;if(e)for(const t of Object.keys(e)){const n=e[t];e[t].data=g(n.data,n.content_type)}}}(t),t}}function l(e,t,n,r){let o=t[e];void 0!==o&&(r&&(o=encodeURIComponent(JSON.stringify(o))),n.push(e+"="+o))}function p(e){if(void 0!==e){const t=Number(e);return isNaN(t)||t!==parseInt(e,10)?e:t}}function h(e){if(e){if("number"!=typeof e)return new pe(`Invalid value for integer: "${e}"`);if(e<0)return new pe(`Invalid value for positive integer: "${e}"`)}}function v(e,t){const n=e.descending?"endkey":"startkey",r=e.descending?"startkey":"endkey";if(void 0!==e[n]&&void 0!==e[r]&&M(e[n],e[r])>0)throw new pe("No rows can match your key range, reverse your start_key and end_key or set {descending : true}");if(t.reduce&&!1!==e.reduce){if(e.include_docs)throw new pe("{include_docs:true} is invalid for reduce");if(e.keys&&e.keys.length>1&&!e.group&&!e.group_level)throw new pe("Multi-key fetches for reduce views must use {group: true}")}for(const t of["group_level","limit","skip"]){const n=h(e[t]);if(n)throw n}}function m(e){return function(t){if(404===t.status)return e;throw t}}function _(e,t,n){return e.db.get("_local/lastSeq").catch(m({_id:"_local/lastSeq",seq:0})).then((function(r){var o=be(t);return Promise.all(o.map((function(n){return async function(e,t,n){const r="_local/doc_"+e,o={_id:r,keys:[]},i=n.get(e),s=i[0],u=i[1],c=await(function(e){return 1===e.length&&/^1-/.test(e[0].rev)}(u)?Promise.resolve(o):t.db.get(r).catch(m(o)));return function(e,t){const n=[],r=new Set;for(const e of t.rows){const t=e.doc;if(t&&(n.push(t),r.add(t._id),t._deleted=!s.has(t._id),!t._deleted)){const e=s.get(t._id);"value"in e&&(t.value=e.value)}}const o=be(s);for(const e of o)if(!r.has(e)){const t={_id:e},r=s.get(e);"value"in r&&(t.value=r.value),n.push(t)}return e.keys=_e(o.concat(e.keys)),n.push(e),n}(c,await function(e){return e.keys.length?t.db.allDocs({keys:e.keys,include_docs:!0}):Promise.resolve({rows:[]})}(c))}(n,e,t)}))).then((function(t){var o=t.flat();return r.seq=n,o.push(r),e.db.bulkDocs({docs:o})})).then(()=>function(e){return e.sourceDB.get("_local/purges").then((function(t){const n=t.purgeSeq;return e.db.get("_local/purgeSeq").then((function(e){return e._rev})).catch(m(void 0)).then((function(t){return e.db.put({_id:"_local/purgeSeq",_rev:t,purgeSeq:n})}))})).catch((function(e){if(404!==e.status)throw e}))}(e))}))}function b(e){const t="string"==typeof e?e:e.name;let n=we[t];return n||(n=we[t]=new le),n}async function w(e,n){return me(b(e),(function(){return async function(e,n){let r,i,u;const c=t(e.mapFun,(function(e,t){const n={id:i._id,key:E(e)};null!=t&&(n.value=E(t)),r.push(n)}));let a=e.seq||0;let f=0;const l={view:e.name,indexed_docs:f};e.sourceDB.emit("indexing",l);const d=new le;async function y(){return function(t,l){const h=t.results;if(!h.length&&!l.length)return;for(const e of l){if(h.findIndex((function(t){return t.id===e.docId}))<0){const t={_id:e.docId,doc:{_id:e.docId,_deleted:1},changes:[]};e.doc&&(t.doc=e.doc,t.changes.push({rev:e.doc._rev})),h.push(t)}}const v=function(t){const n=new Map;for(const u of t){if("_"!==u.doc._id[0]){r=[],i=u.doc,i._deleted||o(e.sourceDB,c,i),r.sort(s);const t=p(r);n.set(u.doc._id,[t,u.changes])}a=u.seq}return n}(h);d.add(function(t,n){return function(){return _(e,t,n)}}(v,a)),f+=h.length;const g={view:e.name,last_seq:t.last_seq,results_count:h.length,indexed_docs:f};if(e.sourceDB.emit("indexing",g),e.sourceDB.activeTasks.update(u,{completed_items:f}),h.length<n.changes_batch_size)return;return y()}(await e.sourceDB.changes({return_docs:!0,conflicts:!0,include_docs:!0,style:"all_docs",since:a,limit:n.changes_batch_size}),await e.db.get("_local/purgeSeq").then((function(e){return e.purgeSeq})).catch(m(-1)).then((function(t){return e.sourceDB.get("_local/purges").then((function(n){const r=n.purges.filter((function(e,n){return n>t})).map(e=>e.docId),o=r.filter((function(e,t){return r.indexOf(e)===t}));return Promise.all(o.map((function(t){return e.sourceDB.get(t).then((function(e){return{docId:t,doc:e}})).catch(m({docId:t}))})))})).catch(m([]))})))}function p(e){const t=new Map;let n;for(let r=0,o=e.length;r<o;r++){const o=e[r],i=[o.key,o.id];r>0&&0===M(o.key,n)&&i.push(r),t.set(B(i),o),n=o.key}return t}try{await e.sourceDB.info().then((function(t){u=e.sourceDB.activeTasks.add({name:"view_indexing",total_items:t.update_seq-a})})),await y(),await d.finish(),e.seq=a,e.sourceDB.activeTasks.remove(u)}catch(t){e.sourceDB.activeTasks.remove(u,t)}}(e,n)}))()}function k(e,t){return me(b(e),(function(){return async function(e,t){let r;const o=e.reduceFun&&!1!==t.reduce,s=t.skip||0;void 0===t.keys||t.keys.length||(t.limit=0,delete t.keys);async function c(t){t.include_docs=!0;const n=await e.db.allDocs(t);return r=n.total_rows,n.rows.map((function(e){if("value"in e.doc&&"object"==typeof e.doc.value&&null!==e.doc.value){const t=Object.keys(e.doc.value).sort(),n=["id","key","value"];if(!(t<n||t>n))return e.doc.value}const t=function(e){for(var t=[],n=[],r=0;;){var o=e[r++];if("\0"!==o)switch(o){case"1":t.push(null);break;case"2":t.push("1"===e[r]),r++;break;case"3":var i=P(e,r);t.push(i.num),r+=i.length;break;case"4":for(var s="";;){var u=e[r];if("\0"===u)break;s+=u,r++}s=s.replace(/\u0001\u0001/g,"\0").replace(/\u0001\u0002/g,"\x01").replace(/\u0002\u0002/g,"\x02"),t.push(s);break;case"5":var c={element:[],index:t.length};t.push(c.element),n.push(c);break;case"6":var a={element:{},index:t.length};t.push(a.element),n.push(a);break;default:throw new Error("bad collationIndex or unexpectedly reached end of input: "+o)}else{if(1===t.length)return t.pop();I(t,n)}}}(e.doc._id);return{key:t[0],id:t[1],value:"value"in e.doc?e.doc.value:null}}))}async function f(c){let f;if(f=o?function(e,t,r){0===r.group_level&&delete r.group_level;const o=r.group||r.group_level,s=n(e.reduceFun),c=[],a=isNaN(r.group_level)?Number.POSITIVE_INFINITY:r.group_level;for(const e of t){const t=c[c.length-1];let n=o?e.key:null;o&&Array.isArray(n)&&(n=n.slice(0,a)),t&&0===M(t.groupKey,n)?(t.keys.push([e.key,e.id]),t.values.push(e.value)):c.push({keys:[[e.key,e.id]],values:[e.value],groupKey:n})}t=[];for(const n of c){const r=i(e.sourceDB,s,n.keys,n.values,!1);if(r.error&&r.error instanceof ve)throw r.error;t.push({value:r.error?null:r.output,key:n.groupKey})}return{rows:u(t,r.limit,r.skip)}}(e,c,t):void 0===t.keys?{total_rows:r,offset:s,rows:c}:{total_rows:r,offset:s,rows:u(c,t.limit,t.skip)},t.update_seq&&(f.update_seq=e.seq),t.include_docs){const n=_e(c.map(a)),r=await e.sourceDB.allDocs({keys:n,include_docs:!0,conflicts:t.conflicts,attachments:t.attachments,binary:t.binary}),o=new Map;for(const e of r.rows)o.set(e.id,e.doc);for(const e of c){const t=a(e),n=o.get(t);n&&(e.doc=n)}}return f}if(void 0!==t.keys){const e=t.keys.map((function(e){const n={startkey:B([e]),endkey:B([e,{}])};return t.update_seq&&(n.update_seq=!0),c(n)})),n=await Promise.all(e);return f(n.flat())}{const e={descending:t.descending};let n,r;if(t.update_seq&&(e.update_seq=!0),"start_key"in t&&(n=t.start_key),"startkey"in t&&(n=t.startkey),"end_key"in t&&(r=t.end_key),"endkey"in t&&(r=t.endkey),void 0!==n&&(e.startkey=t.descending?B([n,{}]):B([n])),void 0!==r){let n=!1!==t.inclusive_end;t.descending&&(n=!n),e.endkey=B(n?[r,{}]:[r])}if(void 0!==t.key){const n=B([t.key]),r=B([t.key,{}]);e.descending?(e.endkey=n,e.startkey=r):(e.startkey=n,e.endkey=r)}o||("number"==typeof t.limit&&(e.limit=t.limit),e.skip=s);return f(await c(e))}}(e,t)}))()}async function j(t,n,o){if("function"==typeof t._query)return function(e,t,n){return new Promise((function(r,o){e._query(t,n,(function(e,t){if(e)return o(e);r(t)}))}))}(t,n,o);if(y(t))return async function(e,t,n){let r,o,i=[],s="GET";if(l("reduce",n,i),l("include_docs",n,i),l("attachments",n,i),l("limit",n,i),l("descending",n,i),l("group",n,i),l("group_level",n,i),l("skip",n,i),l("stale",n,i),l("conflicts",n,i),l("startkey",n,i,!0),l("start_key",n,i,!0),l("endkey",n,i,!0),l("end_key",n,i,!0),l("inclusive_end",n,i),l("key",n,i,!0),l("update_seq",n,i),i=i.join("&"),i=""===i?"":"?"+i,void 0!==n.keys){const e=2e3,o="keys="+encodeURIComponent(JSON.stringify(n.keys));o.length+i.length+1<=e?i+=("?"===i[0]?"&":"?")+o:(s="POST","string"==typeof t?r={keys:n.keys}:t.keys=n.keys)}if("string"==typeof t){const u=je(t),c=await e.fetch("_design/"+u[0]+"/_view/"+u[1]+i,{headers:new Y({"Content-Type":"application/json"}),method:s,body:JSON.stringify(r)});o=c.ok;const a=await c.json();if(!o)throw a.status=c.status,d(a);for(const e of a.rows)if(e.value&&e.value.error&&"builtin_reduce_error"===e.value.error)throw new Error(e.reason);return new Promise((function(e){e(a)})).then(f(n))}r=r||{};for(const e of Object.keys(t))Array.isArray(t[e])?r[e]=t[e]:r[e]=t[e].toString();const u=await e.fetch("_temp_view"+i,{headers:new Y({"Content-Type":"application/json"}),method:"POST",body:JSON.stringify(r)});o=u.ok;const c=await u.json();if(!o)throw c.status=u.status,d(c);return new Promise((function(e){e(c)})).then(f(n))}(t,n,o);const i={changes_batch_size:t.__opts.view_update_changes_batch_size||50};if("string"!=typeof n)return v(o,n),ke.add((async function(){const r=await ye(t,"temp_view/temp_view",n.map,n.reduce,!0,e);return s=w(r,i).then((function(){return k(r,o)})),u=function(){return r.db.destroy()},s.then((function(e){return u().then((function(){return e}))}),(function(e){return u().then((function(){throw e}))}));var s,u})),ke.finish();{const s=n,u=je(s),a=u[0],f=u[1],l=await t.get("_design/"+a);if(!(n=l.views&&l.views[f]))throw new he(`ddoc ${l._id} has no view named ${f}`);r(l,f),v(o,n);const d=await ye(t,s,n.map,n.reduce,!1,e);return"ok"===o.stale||"update_after"===o.stale?("update_after"===o.stale&&c((function(){w(d,i)})),k(d,o)):(await w(d,i),k(d,o))}}var $;return{query:function(e,t,n){const r=this;"function"==typeof t&&(n=t,t={}),t=t?function(e){return e.group_level=p(e.group_level),e.limit=p(e.limit),e.skip=p(e.skip),e}(t):{},"function"==typeof e&&(e={map:e});const o=Promise.resolve().then((function(){return j(r,e,t)}));return ge(o,n),o},viewCleanup:($=function(){const t=this;return"function"==typeof t._viewCleanup?function(e){return new Promise((function(t,n){e._viewCleanup((function(e,r){if(e)return n(e);t(r)}))}))}(t):y(t)?async function(e){return(await e.fetch("_view_cleanup",{headers:new Y({"Content-Type":"application/json"}),method:"POST"})).json()}(t):async function(t){try{const n=await t.get("_local/"+e),r=new Map;for(const e of Object.keys(n.views)){const t=je(e),n="_design/"+t[0],o=t[1];let i=r.get(n);i||(i=new Set,r.set(n,i)),i.add(o)}const o={keys:be(r),include_docs:!0},i=await t.allDocs(o),s={};for(const e of i.rows){const t=e.key.substring(8);for(const o of r.get(e.key)){let r=t+"/"+o;n.views[r]||(r=o);const i=Object.keys(n.views[r]),u=e.doc&&e.doc.views&&e.doc.views[o];for(const e of i)s[e]=s[e]||u}}const u=Object.keys(s).filter((function(e){return!s[e]})).map((function(e){return me(b(e),(function(){return new t.constructor(e,t.__opts).destroy()}))()}));return Promise.all(u).then((function(){return{ok:!0}}))}catch(e){if(404===e.status)return{ok:!0};throw e}}(t)},function(...e){var t=e.pop(),n=$.apply(this,e);return"function"==typeof t&&ge(n,t),n})}}("indexes",(function(e,t){return Oe(Object.keys(e.fields),t,e.partial_filter_selector)}),(function(){throw new Error("reduce not supported")}),(function(e,t){const n=e.views[t];if(!n.map||!n.map.fields)throw new Error("ddoc "+e._id+" with view "+t+" doesn't have map.fields defined. maybe it wasn't created by this plugin?")}));function qe(e){return e._customFindAbstractMapper?{query:function(t,n){const r=Ae.query.bind(this);return e._customFindAbstractMapper.query.call(this,t,n,r)},viewCleanup:function(){const t=Ae.viewCleanup.bind(this);return e._customFindAbstractMapper.viewCleanup.call(this,t)}}:Ae}const Me=/^_design\//;function Ee(e){return e.fields=e.fields.map((function(e){if("string"==typeof e){const t={};return t[e]="asc",t}return e})),e.partial_filter_selector&&(e.partial_filter_selector=q(e.partial_filter_selector)),e}function Se(e,t){return t.def.fields.map(t=>{const n=x(t);return _(e,k(n))})}async function Be(e,t){const n=u((t=H(t)).index);let r;function o(){return r||(r=m(JSON.stringify(t)))}t.index=Ee(t.index),function(e){const t=e.fields.filter((function(e){return"asc"===O(e)}));if(0!==t.length&&t.length!==e.fields.length)throw new Error("unsupported mixed sorting")}(t.index);const i=t.name||"idx-"+o(),s=t.ddoc||"idx-"+o(),c="_design/"+s;let a=!1,f=!1;if(e.constructor.emit("debug",["find","creating index",c]),await p(e,c,(function(e){return e._rev&&"query"!==e.language&&(a=!0),e.language="query",e.views=e.views||{},f=!!e.views[i],!f&&(e.views[i]={map:{fields:K(t.index.fields),partial_filter_selector:t.index.partial_filter_selector},reduce:"_count",options:{def:n}},e)})),a)throw new Error('invalid language for ddoc with id "'+c+'" (should be "query")');const l=s+"/"+i;return await qe(e).query.call(e,l,{limit:0,reduce:!1}),{id:c,name:i,result:f?"exists":"created"}}async function Pe(e){const t=await e.allDocs({startkey:"_design/",endkey:"_design/\uffff",include_docs:!0}),n={indexes:[{ddoc:null,name:"_all_docs",type:"special",def:{fields:[{_id:"asc"}]}}]};return n.indexes=Q(n.indexes,t.rows.filter((function(e){return"query"===e.doc.language})).map((function(e){return(void 0!==e.doc.views?Object.keys(e.doc.views):[]).map((function(t){const n=e.doc.views[t];return{ddoc:e.id,name:t,type:"json",def:Ee(n.options.def)}}))}))),n.indexes.sort((function(e,t){return w(e.name,t.name)})),n.total_rows=n.indexes.length,n}const Ie={"\uffff":{}},Ce={queryOpts:{limit:0,startkey:Ie,endkey:null},inMemoryFields:[]};function Le(e,t){return e.def.fields.some(e=>x(e)===t)}function Ue(e,t){return"$eq"!==x(e[t])}function De(e,t){const n=t.def.fields.map(x);return e.slice().sort((function(e,t){let r=n.indexOf(e),o=n.indexOf(t);return-1===r&&(r=Number.MAX_VALUE),-1===o&&(o=Number.MAX_VALUE),w(r,o)}))}function Ne(e,t,n,r){const o=Q(e,function(e,t,n){let r=!1;for(let o=0,i=(n=De(n,e)).length;o<i;o++){const s=n[o];if(r||!Le(e,s))return n.slice(o);o<i-1&&Ue(t,s)&&(r=!0)}return[]}(t,n,r),function(e){const t=[];for(const[n,r]of Object.entries(e))for(const e of Object.keys(r))"$ne"===e&&t.push(n);return t}(n));return De((i=o,Array.from(new Set(i))),t);var i}function Te(e,t,n){if(t){const i=(o=e,!((r=t).length>o.length)&&X(r,o)),s=X(n,e);return i&&s}var r,o;return function(e,t){e=e.slice();for(const n of t){if(!e.length)break;const t=e.indexOf(n);if(-1===t)return!1;e.splice(t,1)}return!0}(n,e)}const Fe=["$eq","$gt","$gte","$lt","$lte"];function Re(e){return-1===Fe.indexOf(e)}function ze(e,t,n,r){const o=e.def.fields.map(x);return!!Te(o,t,n)&&function(e,t){const n=t[e[0]];return void 0===n||!(1===Object.keys(n).length&&"$ne"===x(n))}(o,r)}function Je(e,t,n,r,o){const i=function(e,t,n,r){return r.filter((function(r){return ze(r,n,t,e)}))}(e,t,n,r);if(0===i.length){if(o)throw{error:"no_usable_index",message:"There is no index available for this selector."};const e=r[0];return e.defaultUsed=!0,e}if(1===i.length&&!o)return i[0];const s=function(e){const t={};for(const n of e)t[n]=!0;return t}(t);if(o){const e="_design/"+o[0],t=2===o.length&&o[1],n=i.find((function(n){return!(!t||n.ddoc!==e||t!==n.name)||n.ddoc===e}));if(!n)throw{error:"unknown_error",message:"Could not find that index or could not use that index for the query"};return n}return function(e,t){let n=null,r=-1;for(const o of e){const e=t(o);e>r&&(r=e,n=o)}return n}(i,(function(e){const t=e.def.fields.map(x);let n=0;for(const e of t)s[e]&&n++;return n}))}function Ve(e,t){switch(e){case"$eq":return{key:t};case"$lte":return{endkey:t};case"$gte":return{startkey:t};case"$lt":return{endkey:t,inclusive_end:!1};case"$gt":return{startkey:t,inclusive_start:!1}}return{startkey:null}}function Qe(e,t){switch(e){case"$eq":return{startkey:t,endkey:t};case"$lte":return{endkey:t};case"$gte":return{startkey:t};case"$lt":return{endkey:t,inclusive_end:!1};case"$gt":return{startkey:t,inclusive_start:!1}}}function Ke(e,t){return t.defaultUsed?function(e){return{queryOpts:{startkey:null},inMemoryFields:[Object.keys(e)]}}(e):1===t.def.fields.length?function(e,t){const n=x(t.def.fields[0]),r=e[n]||{},o=[],i=Object.keys(r);let s;for(const e of i){Re(e)&&o.push(n);const t=Ve(e,r[e]);s=s?K([s,t]):t}return{queryOpts:s,inMemoryFields:o}}(e,t):function(e,t){const n=t.def.fields.map(x);let r=[];const o=[],i=[];let s,u;function c(e){!1!==s&&o.push(null),!1!==u&&i.push(Ie),r=n.slice(e)}for(let t=0,r=n.length;t<r;t++){const r=e[n[t]];if(!r||!Object.keys(r).length){c(t);break}if(Object.keys(r).some(Re)){c(t);break}if(t>0){const o="$gt"in r||"$gte"in r||"$lt"in r||"$lte"in r,i=Object.keys(e[n[t-1]]),s=G(i,["$eq"]),u=G(i,Object.keys(r));if(o&&!s&&!u){c(t);break}}const a=Object.keys(r);let f=null;for(const e of a){const t=Qe(e,r[e]);f=f?K([f,t]):t}o.push("startkey"in f?f.startkey:null),i.push("endkey"in f?f.endkey:Ie),"inclusive_start"in f&&(s=f.inclusive_start),"inclusive_end"in f&&(u=f.inclusive_end)}const a={startkey:o,endkey:i};return void 0!==s&&(a.inclusive_start=s),void 0!==u&&(a.inclusive_end=u),{queryOpts:a,inMemoryFields:r}}(e,t)}function Xe(e,t){const n=e.selector,r=e.sort;if(function(e){return Object.keys(e).map((function(t){return e[t]})).some((function(e){return"object"==typeof e&&0===Object.keys(e).length}))}(n))return Object.assign({},Ce,{index:t[0]});const o=function(e,t){const n=Object.keys(e),r=t?t.map(x):[];let o;return o=n.length>=r.length?n:r,0===r.length?{fields:o}:(o=o.sort((function(e,t){let n=r.indexOf(e);-1===n&&(n=Number.MAX_VALUE);let o=r.indexOf(t);return-1===o&&(o=Number.MAX_VALUE),n<o?-1:n>o?1:0})),{fields:o,sortOrder:t.map(x)})}(n,r),i=o.fields,s=Je(n,i,o.sortOrder,t,e.use_index),u=Ke(n,s);return{queryOpts:u.queryOpts,index:s,inMemoryFields:Ne(u.inMemoryFields,s,n,i)}}async function Ge(e,t,n){return"_all_docs"===n.name?async function(e,t){const n=u(t);n.descending?("endkey"in n&&"string"!=typeof n.endkey&&(n.endkey=""),"startkey"in n&&"string"!=typeof n.startkey&&(n.limit=0)):("startkey"in n&&"string"!=typeof n.startkey&&(n.startkey=""),"endkey"in n&&"string"!=typeof n.endkey&&(n.limit=0)),"key"in n&&"string"!=typeof n.key&&(n.limit=0),n.limit>0&&n.indexes_count&&(n.original_limit=n.limit,n.limit+=n.indexes_count);const r=await e.allDocs(n);return r.rows=r.rows.filter((function(e){return!/^_design\//.test(e.id)})),n.original_limit&&(n.limit=n.original_limit),r.rows=r.rows.slice(0,n.limit),r}(e,t):qe(e).query.call(e,(r=n).ddoc.substring(8)+"/"+r.name,t);var r}async function We(e,t,n){t.selector&&(oe(t.selector,!1),t.selector=q(t.selector)),t.sort&&(t.sort=function(e){if(!Array.isArray(e))throw new Error("invalid sort json - should be an array");return e.map((function(e){if("string"==typeof e){const t={};return t[e]="asc",t}return e}))}(t.sort)),t.use_index&&(t.use_index=function(e){let t=[];return"string"==typeof e?t.push(e):t=e,t.map((function(e){return e.replace(Me,"")}))}(t.use_index)),"limit"in t||(t.limit=25),function(e){if("object"!=typeof e.selector)throw new Error("you must provide a selector when you find()")}(t);const r=await Pe(e);e.constructor.emit("debug",["find","planning query",t]);const o=Xe(t,r.indexes);e.constructor.emit("debug",["find","query plan",o]);const i=o.index;!function(e,t){if(t.defaultUsed&&e.sort){const t=e.sort.filter((function(e){return"_id"!==Object.keys(e)[0]})).map((function(e){return Object.keys(e)[0]}));if(t.length>0)throw new Error('Cannot sort on field(s) "'+t.join(",")+'" when using the default index')}t.defaultUsed}(t,i);let s=Object.assign({include_docs:!0,reduce:!1,indexes_count:r.total_rows},o.queryOpts);if("startkey"in s&&"endkey"in s&&M(s.startkey,s.endkey)>0)return{docs:[]};if(t.sort&&"string"!=typeof t.sort[0]&&"desc"===O(t.sort[0])&&(s.descending=!0,s=function(e){const t=u(e);return delete t.startkey,delete t.endkey,delete t.inclusive_start,delete t.inclusive_end,"endkey"in e&&(t.startkey=e.endkey),"startkey"in e&&(t.endkey=e.startkey),"inclusive_start"in e&&(t.inclusive_end=e.inclusive_start),"inclusive_end"in e&&(t.inclusive_start=e.inclusive_end),t}(s)),o.inMemoryFields.length||(s.limit=t.limit,"skip"in t&&(s.skip=t.skip)),n)return Promise.resolve(o,s);const c=await Ge(e,s,i);!1===s.inclusive_start&&(c.rows=function(e,t,n){const r=n.def.fields;let o=0;for(const i of e){let e=Se(i.doc,n);if(1===r.length)e=e[0];else for(;e.length>t.length;)e.pop();if(Math.abs(M(e,t))>0)break;++o}return o>0?e.slice(o):e}(c.rows,s.startkey,i)),o.inMemoryFields.length&&(c.rows=L(c.rows,t,o.inMemoryFields));const a={docs:c.rows.map((function(e){const n=e.doc;return t.fields?function(e,t){const n={};for(const r of t){const t=k(r),o=_(e,t);void 0!==o&&b(n,t,o)}return n}(n,t.fields):n}))};return i.defaultUsed&&(a.warning="No matching index found, create an index to optimize query time."),a}async function Ye(e,t){const n=await We(e,t,!0);return{dbname:e.name,index:n.index,selector:t.selector,range:{start_key:n.queryOpts.startkey,end_key:n.queryOpts.endkey},opts:{use_index:t.use_index||[],bookmark:"nil",limit:t.limit,skip:t.skip,sort:t.sort||{},fields:t.fields,conflicts:!1,r:[49]},limit:t.limit,skip:t.skip||0,fields:t.fields}}async function He(e,t){if(!t.ddoc)throw new Error("you must supply an index.ddoc when deleting");if(!t.name)throw new Error("you must supply an index.name when deleting");const n=t.ddoc,r=t.name;return await p(e,n,(function(e){return 1===Object.keys(e.views).length&&e.views[r]?{_id:n,_deleted:!0}:(delete e.views[r],e)})),await qe(e).viewCleanup.apply(e),{ok:!0}}const Ze={};Ze.createIndex=W((async function(e){if("object"!=typeof e)throw new Error("you must provide an index to create");return(y(this)?se:Be)(this,e)})),Ze.find=W((async function(e){if("object"!=typeof e)throw new Error("you must provide search parameters to find()");return(y(this)?ue:We)(this,e)})),Ze.explain=W((async function(e){if("object"!=typeof e)throw new Error("you must provide search parameters to explain()");return(y(this)?ce:Ye)(this,e)})),Ze.getIndexes=W((async function(){return(y(this)?ae:Pe)(this)})),Ze.deleteIndex=W((async function(e){if("object"!=typeof e)throw new Error("you must provide an index to delete");return(y(this)?fe:He)(this,e)})),"undefined"==typeof PouchDB?a("error",'pouchdb-find plugin error: Cannot find global "PouchDB" object! Did you remember to include pouchdb.js?'):PouchDB.plugin(Ze)},{events:1,"spark-md5":2,uuid:3}]},{},[18]);
|