// PouchDB 8.0.1 // // (c) 2012-2023 Dale Harvey and the PouchDB team // PouchDB may be freely distributed under the Apache license, version 2.0. // For all details and documentation: // http://pouchdb.com !function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).PouchDB=e()}}((function(){return function e(t,n,r){function i(s,a){if(!n[s]){if(!t[s]){var c="function"==typeof require&&require;if(!a&&c)return c(s,!0);if(o)return o(s,!0);var u=new Error("Cannot find module '"+s+"'");throw u.code="MODULE_NOT_FOUND",u}var f=n[s]={exports:{}};t[s][0].call(f.exports,(function(e){return i(t[s][1][e]||e)}),f,f.exports,e,t,n,r)}return n[s].exports}for(var o="function"==typeof require&&require,s=0;s0&&a.length>o){a.warned=!0;var c=new Error("Possible EventEmitter memory leak detected. "+a.length+' "'+String(t)+'" listeners added. Use emitter.setMaxListeners() to increase limit.');c.name="MaxListenersExceededWarning",c.emitter=e,c.type=t,c.count=a.length,"object"==typeof console&&console.warn&&console.warn("%s: %s",c.name,c.message)}}else a=s[t]=n,++e._eventsCount;return e}function _(){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;t1&&(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 u="function"==typeof n;switch(r=arguments.length){case 1:l(n,u,this);break;case 2:d(n,u,this,arguments[1]);break;case 3:h(n,u,this,arguments[1],arguments[2]);break;case 4:p(n,u,this,arguments[1],arguments[2],arguments[3]);break;default:for(i=new Array(r-1),o=1;o=0;s--)if(n[s]===t||n[s].listener===t){a=n[s].listener,o=s;break}if(o<0)return this;0===o?n.shift():function(e,t){for(var n=t,r=n+1,i=e.length;r=0;o--)this.removeListener(e,t[o]);return this},s.prototype.listeners=function(e){return m(this,e,!0)},s.prototype.rawListeners=function(e){return m(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):[]}},{}],3:[function(e,t,n){"use strict";var r,i,o,s=[e(1),e(6),e(5),e(4),e(7),e(8)],a=-1,c=[],u=!1;function f(){r&&i&&(r=!1,i.length?c=i.concat(c):a=-1,c.length&&l())}function l(){if(!r){u=!1,r=!0;for(var e=c.length,t=setTimeout(f);e;){for(i=c,c=[];i&&++a1)for(var n=1;n1)for(var n=1;n>>25)+r|0)&r|~n&i)+t[1]-389564586|0)<<12|o>>>20)+n|0)&n|~o&r)+t[2]+606105819|0)<<17|i>>>15)+o|0)&o|~i&n)+t[3]-1044525330|0)<<22|r>>>10)+i|0,r=((r+=((i=((i+=((o=((o+=((n=((n+=(r&i|~r&o)+t[4]-176418897|0)<<7|n>>>25)+r|0)&r|~n&i)+t[5]+1200080426|0)<<12|o>>>20)+n|0)&n|~o&r)+t[6]-1473231341|0)<<17|i>>>15)+o|0)&o|~i&n)+t[7]-45705983|0)<<22|r>>>10)+i|0,r=((r+=((i=((i+=((o=((o+=((n=((n+=(r&i|~r&o)+t[8]+1770035416|0)<<7|n>>>25)+r|0)&r|~n&i)+t[9]-1958414417|0)<<12|o>>>20)+n|0)&n|~o&r)+t[10]-42063|0)<<17|i>>>15)+o|0)&o|~i&n)+t[11]-1990404162|0)<<22|r>>>10)+i|0,r=((r+=((i=((i+=((o=((o+=((n=((n+=(r&i|~r&o)+t[12]+1804603682|0)<<7|n>>>25)+r|0)&r|~n&i)+t[13]-40341101|0)<<12|o>>>20)+n|0)&n|~o&r)+t[14]-1502002290|0)<<17|i>>>15)+o|0)&o|~i&n)+t[15]+1236535329|0)<<22|r>>>10)+i|0,r=((r+=((i=((i+=((o=((o+=((n=((n+=(r&o|i&~o)+t[1]-165796510|0)<<5|n>>>27)+r|0)&i|r&~i)+t[6]-1069501632|0)<<9|o>>>23)+n|0)&r|n&~r)+t[11]+643717713|0)<<14|i>>>18)+o|0)&n|o&~n)+t[0]-373897302|0)<<20|r>>>12)+i|0,r=((r+=((i=((i+=((o=((o+=((n=((n+=(r&o|i&~o)+t[5]-701558691|0)<<5|n>>>27)+r|0)&i|r&~i)+t[10]+38016083|0)<<9|o>>>23)+n|0)&r|n&~r)+t[15]-660478335|0)<<14|i>>>18)+o|0)&n|o&~n)+t[4]-405537848|0)<<20|r>>>12)+i|0,r=((r+=((i=((i+=((o=((o+=((n=((n+=(r&o|i&~o)+t[9]+568446438|0)<<5|n>>>27)+r|0)&i|r&~i)+t[14]-1019803690|0)<<9|o>>>23)+n|0)&r|n&~r)+t[3]-187363961|0)<<14|i>>>18)+o|0)&n|o&~n)+t[8]+1163531501|0)<<20|r>>>12)+i|0,r=((r+=((i=((i+=((o=((o+=((n=((n+=(r&o|i&~o)+t[13]-1444681467|0)<<5|n>>>27)+r|0)&i|r&~i)+t[2]-51403784|0)<<9|o>>>23)+n|0)&r|n&~r)+t[7]+1735328473|0)<<14|i>>>18)+o|0)&n|o&~n)+t[12]-1926607734|0)<<20|r>>>12)+i|0,r=((r+=((i=((i+=((o=((o+=((n=((n+=(r^i^o)+t[5]-378558|0)<<4|n>>>28)+r|0)^r^i)+t[8]-2022574463|0)<<11|o>>>21)+n|0)^n^r)+t[11]+1839030562|0)<<16|i>>>16)+o|0)^o^n)+t[14]-35309556|0)<<23|r>>>9)+i|0,r=((r+=((i=((i+=((o=((o+=((n=((n+=(r^i^o)+t[1]-1530992060|0)<<4|n>>>28)+r|0)^r^i)+t[4]+1272893353|0)<<11|o>>>21)+n|0)^n^r)+t[7]-155497632|0)<<16|i>>>16)+o|0)^o^n)+t[10]-1094730640|0)<<23|r>>>9)+i|0,r=((r+=((i=((i+=((o=((o+=((n=((n+=(r^i^o)+t[13]+681279174|0)<<4|n>>>28)+r|0)^r^i)+t[0]-358537222|0)<<11|o>>>21)+n|0)^n^r)+t[3]-722521979|0)<<16|i>>>16)+o|0)^o^n)+t[6]+76029189|0)<<23|r>>>9)+i|0,r=((r+=((i=((i+=((o=((o+=((n=((n+=(r^i^o)+t[9]-640364487|0)<<4|n>>>28)+r|0)^r^i)+t[12]-421815835|0)<<11|o>>>21)+n|0)^n^r)+t[15]+530742520|0)<<16|i>>>16)+o|0)^o^n)+t[2]-995338651|0)<<23|r>>>9)+i|0,r=((r+=((o=((o+=(r^((n=((n+=(i^(r|~o))+t[0]-198630844|0)<<6|n>>>26)+r|0)|~i))+t[7]+1126891415|0)<<10|o>>>22)+n|0)^((i=((i+=(n^(o|~r))+t[14]-1416354905|0)<<15|i>>>17)+o|0)|~n))+t[5]-57434055|0)<<21|r>>>11)+i|0,r=((r+=((o=((o+=(r^((n=((n+=(i^(r|~o))+t[12]+1700485571|0)<<6|n>>>26)+r|0)|~i))+t[3]-1894986606|0)<<10|o>>>22)+n|0)^((i=((i+=(n^(o|~r))+t[10]-1051523|0)<<15|i>>>17)+o|0)|~n))+t[1]-2054922799|0)<<21|r>>>11)+i|0,r=((r+=((o=((o+=(r^((n=((n+=(i^(r|~o))+t[8]+1873313359|0)<<6|n>>>26)+r|0)|~i))+t[15]-30611744|0)<<10|o>>>22)+n|0)^((i=((i+=(n^(o|~r))+t[6]-1560198380|0)<<15|i>>>17)+o|0)|~n))+t[13]+1309151649|0)<<21|r>>>11)+i|0,r=((r+=((o=((o+=(r^((n=((n+=(i^(r|~o))+t[4]-145523070|0)<<6|n>>>26)+r|0)|~i))+t[11]-1120210379|0)<<10|o>>>22)+n|0)^((i=((i+=(n^(o|~r))+t[2]+718787259|0)<<15|i>>>17)+o|0)|~n))+t[9]-343485551|0)<<21|r>>>11)+i|0,e[0]=n+e[0]|0,e[1]=r+e[1]|0,e[2]=i+e[2]|0,e[3]=o+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 i(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 o(e){var t,i,o,s,a,c,u=e.length,f=[1732584193,-271733879,-1732584194,271733878];for(t=64;t<=u;t+=64)n(f,r(e.substring(t-64,t)));for(i=(e=e.substring(t-64)).length,o=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],t=0;t>2]|=e.charCodeAt(t)<<(t%4<<3);if(o[t>>2]|=128<<(t%4<<3),t>55)for(n(f,o),t=0;t<16;t+=1)o[t]=0;return s=(s=8*u).toString(16).match(/(.*?)(.{0,8})$/),a=parseInt(s[2],16),c=parseInt(s[1],16)||0,o[14]=a,o[15]=c,n(f,o),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 a(e){var t;for(t=0;t>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 i,o,s,a,c=this.byteLength,u=t(n,c),f=c;return r!==e&&(f=t(r,c)),u>f?new ArrayBuffer(0):(i=f-u,o=new ArrayBuffer(i),s=new Uint8Array(o),a=new Uint8Array(this,u,i),s.set(a),o)}}(),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,i=this._buff.length;for(t=64;t<=i;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,i=r.length,o=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(t=0;t>2]|=r.charCodeAt(t)<<(t%4<<3);return this._finish(o,i),n=a(this._hash),e&&(n=u(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,i,o,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})$/),i=parseInt(r[2],16),o=parseInt(r[1],16)||0,e[14]=i,e[15]=o,n(this._hash,e)},f.hash=function(e,t){return f.hashBinary(c(e),t)},f.hashBinary=function(e,t){var n=a(o(e));return t?u(n):n},f.ArrayBuffer=function(){this.reset()},f.ArrayBuffer.prototype.append=function(e){var t,r,o,s,a,c=(r=this._buff.buffer,o=e,s=!0,(a=new Uint8Array(r.byteLength+o.byteLength)).set(new Uint8Array(r)),a.set(new Uint8Array(o),r.byteLength),s?a:a.buffer),u=c.length;for(this._length+=e.byteLength,t=64;t<=u;t+=64)n(this._hash,i(c.subarray(t-64,t)));return this._buff=t-64>2]|=r[t]<<(t%4<<3);return this._finish(o,i),n=a(this._hash),e&&(n=u(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,i=new ArrayBuffer(r),o=new Uint8Array(i);for(n=0;n>2]|=e[t]<<(t%4<<3);if(o[t>>2]|=128<<(t%4<<3),t>55)for(n(f,o),t=0;t<16;t+=1)o[t]=0;return s=(s=8*u).toString(16).match(/(.*?)(.{0,8})$/),a=parseInt(s[2],16),c=parseInt(s[1],16)||0,o[14]=a,o[15]=c,n(f,o),f}(new Uint8Array(e)));return t?u(r):r},f}))},{}],11:[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 i.default}}),Object.defineProperty(n,"v4",{enumerable:!0,get:function(){return o.default}}),Object.defineProperty(n,"v5",{enumerable:!0,get:function(){return s.default}}),Object.defineProperty(n,"NIL",{enumerable:!0,get:function(){return a.default}}),Object.defineProperty(n,"version",{enumerable:!0,get:function(){return c.default}}),Object.defineProperty(n,"validate",{enumerable:!0,get:function(){return u.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(19)),i=d(e(20)),o=d(e(22)),s=d(e(23)),a=d(e(13)),c=d(e(25)),u=d(e(24)),f=d(e(18)),l=d(e(14));function d(e){return e&&e.__esModule?e:{default:e}}},{13:13,14:14,18:18,19:19,20:20,22:22,23:23,24:24,25:25}],12:[function(e,t,n){"use strict";function r(e){return 14+(e+64>>>9<<4)+1}function i(e,t){const n=(65535&e)+(65535&t);return(e>>16)+(t>>16)+(n>>16)<<16|65535&n}function o(e,t,n,r,o,s){return i((a=i(i(t,e),i(r,s)))<<(c=o)|a>>>32-c,n);var a,c}function s(e,t,n,r,i,s,a){return o(t&n|~t&r,e,t,i,s,a)}function a(e,t,n,r,i,s,a){return o(t&r|n&~r,e,t,i,s,a)}function c(e,t,n,r,i,s,a){return o(t^n^r,e,t,i,s,a)}function u(e,t,n,r,i,s,a){return o(n^(t|~r),e,t,i,s,a)}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>5]>>>r%32&255,i=parseInt("0123456789abcdef".charAt(n>>>4&15)+"0123456789abcdef".charAt(15&n),16);t.push(i)}return t}(function(e,t){e[t>>5]|=128<>5]|=(255&e[r/8])<>>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=o},{24:24}],15:[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},{}],16:[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(i)};const i=new Uint8Array(16)},{}],17:[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 i(e,t){return e<>>32-t}Object.defineProperty(n,"__esModule",{value:!0}),n.default=void 0;var o=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>>0;l=f,f=u,u=i(c,30)>>>0,c=s,s=a}n[0]=n[0]+s>>>0,n[1]=n[1]+c>>>0,n[2]=n[2]+u>>>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=o},{}],18:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default=void 0;var r,i=(r=e(24))&&r.__esModule?r:{default:r};const o=[];for(let e=0;e<256;++e)o.push((e+256).toString(16).substr(1));var s=function(e,t=0){const n=(o[e[t+0]]+o[e[t+1]]+o[e[t+2]]+o[e[t+3]]+"-"+o[e[t+4]]+o[e[t+5]]+"-"+o[e[t+6]]+o[e[t+7]]+"-"+o[e[t+8]]+o[e[t+9]]+"-"+o[e[t+10]]+o[e[t+11]]+o[e[t+12]]+o[e[t+13]]+o[e[t+14]]+o[e[t+15]]).toLowerCase();if(!(0,i.default)(n))throw TypeError("Stringified UUID is invalid");return n};n.default=s},{24:24}],19:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default=void 0;var r=o(e(16)),i=o(e(18));function o(e){return e&&e.__esModule?e:{default:e}}let s,a,c=0,u=0;var f=function(e,t,n){let o=t&&n||0;const f=t||new Array(16);let l=(e=e||{}).node||s,d=void 0!==e.clockseq?e.clockseq:a;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=a=16383&(t[6]<<8|t[7]))}let h=void 0!==e.msecs?e.msecs:Date.now(),p=void 0!==e.nsecs?e.nsecs:u+1;const v=h-c+(p-u)/1e4;if(v<0&&void 0===e.clockseq&&(d=d+1&16383),(v<0||h>c)&&void 0===e.nsecs&&(p=0),p>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");c=h,u=p,a=d,h+=122192928e5;const y=(1e4*(268435455&h)+p)%4294967296;f[o++]=y>>>24&255,f[o++]=y>>>16&255,f[o++]=y>>>8&255,f[o++]=255&y;const _=h/4294967296*1e4&268435455;f[o++]=_>>>8&255,f[o++]=255&_,f[o++]=_>>>24&15|16,f[o++]=_>>>16&255,f[o++]=d>>>8|128,f[o++]=255&d;for(let e=0;e<6;++e)f[o+e]=l[e];return t||(0,i.default)(f)};n.default=f},{16:16,18:18}],20:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default=void 0;var r=o(e(21)),i=o(e(12));function o(e){return e&&e.__esModule?e:{default:e}}var s=(0,r.default)("v3",48,i.default);n.default=s},{12:12,21:21}],21:[function(e,t,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.default=function(e,t,n){function o(e,o,s,a){if("string"==typeof e&&(e=function(e){e=unescape(encodeURIComponent(e));const t=[];for(let n=0;n=0;o--)s=0===o?"":",",t.push({obj:r[o],prefix:s});t.push({val:"["})}else{for(c in a=[],r)r.hasOwnProperty(c)&&a.push(c);for(t.push({val:"}"}),o=a.length-1;o>=0;o--)f=r[u=a[o]],l=o>0?",":"",l+=JSON.stringify(u)+":",t.push({obj:f,prefix:l});t.push({val:"{"})}return d},n.parse=function(e){for(var t,n,i,o,s,a,c,u,f,l=[],d=[],h=0;;)if("}"!==(t=e[h++])&&"]"!==t&&void 0!==t)switch(t){case" ":case"\t":case"\n":case":":case",":break;case"n":h+=3,r(null,l,d);break;case"t":h+=3,r(!0,l,d);break;case"f":h+=4,r(!1,l,d);break;case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":case"-":for(n="",h--;;){if(i=e[h++],!/[\d\.\-e\+]/.test(i)){h--;break}n+=i}r(parseFloat(n),l,d);break;case'"':for(o="",s=void 0,a=0;'"'!==(c=e[h++])||"\\"===s&&a%2==1;)o+=c,"\\"===(s=c)?a++:a=0;r(JSON.parse('"'+o+'"'),l,d);break;case"[":u={element:[],index:l.length},l.push(u.element),d.push(u);break;case"{":f={element:{},index:l.length},l.push(f.element),d.push(f);break;default:throw new Error("unexpectedly reached end of input: "+t)}else{if(1===l.length)return l.pop();r(l.pop(),l,d)}}},{}],27:[function(e,t,n){(function(n){(function(){"use strict";function r(e){return e&&"object"==typeof e&&"default"in e?e.default:e}var i,o,s=r(e(3)),a=r(e(10)),c=e(11),u=r(e(26)),f=r(e(2));function l(e){return"$"+e}function d(e){return e.substring(1)}function h(){this._store={}}function p(e){if(this._store=new h,e&&Array.isArray(e))for(var t=0,n=e.length;td(e))},h.prototype.delete=function(e){var t=l(e),n=t in this._store;return delete this._store[t],n},h.prototype.forEach=function(e){for(var t=Object.keys(this._store),n=0,r=t.length;n=f.length)){var n=Math.min(l+6,f.length),r=f.slice(l,n);!function(n,r){n.forEach((function(n,o){var s=r+o,a=i.get(n),f=k(a[0],["atts_since","attachments"]);f.open_revs=a.map((function(e){return e.rev})),f.open_revs=f.open_revs.filter(q);var l=q;0===f.open_revs.length&&(delete f.open_revs,l=O),["revs","attachments","binary","ajax","latest"].forEach((function(e){e in t&&(f[e]=t[e])})),e.get(n,f,(function(e,t){var r,i,o;r=e?[{error:e}]:l(t),i=n,o=r,c[s]={id:i,docs:o},u(),d()}))}))}(r,l),l+=r.length}}d()}try{localStorage.setItem("_pouch_check_localstorage",1),j=!!localStorage.getItem("_pouch_check_localstorage")}catch(e){j=!1}function S(){return j}function x(e){if("undefined"!=typeof console&&"function"==typeof console[e]){var t=Array.prototype.slice.call(arguments,1);console[e].apply(console,t)}}function E(e){var t=0;return e||(t=2e3),function(e,t){return e=parseInt(e,10)||0,(t=parseInt(t,10))!=t||t<=e?t=(e||1)<<1:t+=1,t>6e5&&(e=3e5,t=6e5),~~((t-e)*Math.random()+e)}(e,t)}function P(e,t){x("info","The above "+e+" is totally normal. "+t)}var C="function"==typeof Object.assign?Object.assign:function(e){for(var t=Object(e),n=1;n0||r0||r>>1],t)<0?i=r+1:o=r;return i}(e,t,n);e.splice(r,0,t)}function $e(e,t){for(var n,r,i=t,o=e.length;i0;){var i=n.pop(),o=i.tree1,s=i.tree2;(o[1].status||s[1].status)&&(o[1].status="available"===o[1].status||"available"===s[1].status?"available":"missing");for(var a=0;a0;){var v=p.pop();if(0!==v.diff)for(var y=v.ids[2],_=0,g=y.length;_t){n||(n={});var f=u.length-t;a={pos:c.pos+f,ids:$e(u,f)};for(var l=0;l{var r,o;t?(o="error",("listenerCount"in(r=this)?r.listenerCount(o):f.listenerCount(r,o))>0&&this.emit("error",t)):this.emit("complete",n),this.removeAllListeners(),e.removeListener("destroyed",i)});n&&(this.on("complete",(function(e){n(null,e)})),this.on("error",n));const i=()=>{this.cancel()};e.once("destroyed",i),t.onChange=(e,t,n)=>{this.isCancelled||function(e,t,n,r){try{e.emit("change",t,n,r)}catch(e){x("error",'Error in .on("change", function):',e)}}(this,e,t,n)};var o=new Promise((function(e,n){t.complete=function(t,r){t?n(t):e(r)}}));this.once("cancel",(function(){e.removeListener("destroyed",i),t.complete(null,{status:"cancelled"})})),this.then=o.then.bind(o),this.catch=o.catch.bind(o),this.then((function(e){r(null,e)}),r),e.taskqueue.isReady?this.validateChanges(t):e.taskqueue.addTask(e=>{e?t.complete(e):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;Ye._changesFilterPlugin?Ye._changesFilterPlugin.validate(e,n=>{if(n)return t(n);this.doChanges(e)}):this.doChanges(e)}doChanges(e){var t=e.complete;if("live"in(e=g(e))&&!("continuous"in e)&&(e.continuous=e.live),e.processChange=Ne,"latest"===e.since&&(e.since="now"),e.since||(e.since=0),"now"!==e.since){if(Ye._changesFilterPlugin){if(Ye._changesFilterPlugin.normalize(e),Ye._changesFilterPlugin.shouldFilter(this,e))return Ye._changesFilterPlugin.filter(this,e)}else["doc_ids","filter","selector","view"].forEach((function(t){t in e&&x("warn",'The "'+t+'" 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=0===e.limit?1:e.limit,e.complete=t;var n=this.db._changes(e);if(n&&"function"==typeof n.cancel){const e=this.cancel;this.cancel=(...t)=>{n.cancel(),e.apply(this,t)}}}else this.db.info().then(n=>{this.isCancelled?t(null,{status:"cancelled"}):(e.since=n.update_seq,this.doChanges(e))},t)}}function Fe(e,t){return et?1:0}function Ke(e,t){return function(n,r){n||r[0]&&r[0].error?((n=n||r[0]).docId=t,e(n)):e(null,r.length?r[0]:r)}}function Je(e,t){var n=Fe(e._id,t._id);return 0!==n?n:Fe(e._revisions?e._revisions.start:0,t._revisions?t._revisions.start:0)}function ze(e,t,n){return e.get("_local/purges").then((function(e){const r=e.purgeSeq+1;return e.purges.push({docId:t,rev:n,purgeSeq:r}),e.purges.length>self.purged_infos_limit&&e.purges.splice(0,e.purges.length-self.purged_infos_limit),e.purgeSeq=r,e})).catch((function(e){if(404!==e.status)throw e;return{_id:"_local/purges",purges:[{docId:t,rev:n,purgeSeq:0}],purgeSeq:0}})).then((function(t){return e.put(t)}))}class Ve extends f{_setup(){this.post=w("post",(function(e,t,n){if("function"==typeof t&&(n=t,t={}),"object"!=typeof e||Array.isArray(e))return n(Q(J));this.bulkDocs({docs:[e]},t,Ke(n,e._id))})).bind(this),this.put=w("put",(function(e,t,n){if("function"==typeof t&&(n=t,t={}),"object"!=typeof e||Array.isArray(e))return n(Q(J));if(X(e._id),Re(e._id)&&"function"==typeof this._putLocal)return e._deleted?this._removeLocal(e,n):this._putLocal(e,n);const r=n=>{"function"==typeof this._put&&!1!==t.new_edits?this._put(e,t,n):this.bulkDocs({docs:[e]},t,Ke(n,e._id))};var i,o,s,a;t.force&&e._rev?(i=e._rev.split("-"),o=i[1],s=parseInt(i[0],10)+1,a=ke(),e._revisions={start:s,ids:[a,o]},e._rev=s+"-"+a,t.new_edits=!1,r((function(t){var r=t?null:{ok:!0,id:e._id,rev:e._rev};n(t,r)}))):r(n)})).bind(this),this.putAttachment=w("putAttachment",(function(e,t,n,r,i){var o=this;function s(e){var n="_rev"in e?parseInt(e._rev,10):0;return e._attachments=e._attachments||{},e._attachments[t]={content_type:i,data:r,revpos:++n},o.put(e)}return"function"==typeof i&&(i=r,r=n,n=null),void 0===i&&(i=r,r=n,n=null),i||x("warn","Attachment",t,"on document",e,"is missing content_type"),o.get(e).then((function(e){if(e._rev!==n)throw Q(I);return s(e)}),(function(t){if(t.reason===D.message)return s({_id:e});throw t}))})).bind(this),this.removeAttachment=w("removeAttachment",(function(e,t,n,r){this.get(e,(e,i)=>{if(e)r(e);else if(i._rev===n){if(!i._attachments)return r();delete i._attachments[t],0===Object.keys(i._attachments).length&&delete i._attachments,this.put(i,r)}else r(Q(I))})})).bind(this),this.remove=w("remove",(function(e,t,n,r){var i;"string"==typeof t?(i={_id:e,_rev:t},"function"==typeof n&&(r=n,n={})):(i=e,"function"==typeof t?(r=t,n={}):(r=n,n=t)),(n=n||{}).was_delete=!0;var o={_id:i._id,_rev:i._rev||n.rev,_deleted:!0};if(Re(o._id)&&"function"==typeof this._removeLocal)return this._removeLocal(i,r);this.bulkDocs({docs:[o]},n,Ke(r,o._id))})).bind(this),this.revsDiff=w("revsDiff",(function(e,t,n){"function"==typeof t&&(n=t,t={});var r=Object.keys(e);if(!r.length)return n(null,{});var i=0,s=new o;function a(e,t){s.has(e)||s.set(e,{missing:[]}),s.get(e).missing.push(t)}r.map((function(t){this._getRevisionTree(t,(function(o,c){if(o&&404===o.status&&"missing"===o.message)s.set(t,{missing:e[t]});else{if(o)return n(o);!function(t,n){var r=e[t].slice(0);Oe(n,(function(e,n,i,o,s){var c=n+"-"+i,u=r.indexOf(c);-1!==u&&(r.splice(u,1),"available"!==s.status&&a(t,c))})),r.forEach((function(e){a(t,e)}))}(t,c)}if(++i===r.length){var u={};return s.forEach((function(e,t){u[t]=e})),n(null,u)}}))}),this)})).bind(this),this.bulkGet=w("bulkGet",(function(e,t){A(this,e,t)})).bind(this),this.compactDocument=w("compactDocument",(function(e,t,n){this._getRevisionTree(e,(r,i)=>{if(r)return n(r);var o=function(e){var t={},n=[];return Oe(e,(function(e,r,i,o){var s=r+"-"+i;return e&&(t[s]=0),void 0!==o&&n.push({from:o,to:s}),s})),n.reverse(),n.forEach((function(e){void 0===t[e.from]?t[e.from]=1+t[e.to]:t[e.from]=Math.min(t[e.from],1+t[e.to])})),t}(i),s=[],a=[];Object.keys(o).forEach((function(e){o[e]>t&&s.push(e)})),Oe(i,(function(e,t,n,r,i){var o=t+"-"+n;"available"===i.status&&-1!==s.indexOf(o)&&a.push(o)})),this._doCompaction(e,a,n)})})).bind(this),this.compact=w("compact",(function(e,t){"function"==typeof e&&(t=e,e={}),e=e||{},this._compactionQueue=this._compactionQueue||[],this._compactionQueue.push({opts:e,callback:t}),1===this._compactionQueue.length&&function e(t){var n=t._compactionQueue[0],r=n.opts,i=n.callback;t.get("_local/compaction").catch((function(){return!1})).then((function(n){n&&n.last_seq&&(r.last_seq=n.last_seq),t._compact(r,(function(n,r){n?i(n):i(null,r),s((function(){t._compactionQueue.shift(),t._compactionQueue.length&&e(t)}))}))}))}(this)})).bind(this),this.get=w("get",(function(e,t,n){if("function"==typeof t&&(n=t,t={}),"string"!=typeof e)return n(Q(T));if(Re(e)&&"function"==typeof this._getLocal)return this._getLocal(e,n);var r=[];const i=()=>{var i=[],o=r.length;if(!o)return n(null,i);r.forEach(r=>{this.get(e,{rev:r,revs:t.revs,latest:t.latest,attachments:t.attachments,binary:t.binary},(function(e,t){if(e)i.push({missing:r});else{for(var s,a=0,c=i.length;a{if(r)return r.docId=e,n(r);var o=i.doc,s=i.metadata,a=i.ctx;if(t.conflicts){var c=xe(s);c.length&&(o._conflicts=c)}if(Me(s,o._rev)&&(o._deleted=!0),t.revs||t.revs_info){for(var u=o._rev.split("-"),f=parseInt(u[0],10),l=u[1],d=Ee(s.rev_tree),h=null,p=0;p{this._getAttachment(o._id,e,b[e],{rev:o._rev,binary:t.binary,ctx:a},(function(t,r){var i=o._attachments[e];i.data=r,delete i.stub,delete i.length,--w||n(null,o)}))})}else{if(o._attachments)for(var k in o._attachments)Object.prototype.hasOwnProperty.call(o._attachments,k)&&(o._attachments[k].stub=!0);n(null,o)}});if("all"===t.open_revs)this._getRevisionTree(e,(function(e,t){if(e)return n(e);r=Se(t).map((function(e){return e.rev})),i()}));else{if(!Array.isArray(t.open_revs))return n(Q(R,"function_clause"));r=t.open_revs;for(var o=0;oi?r(i):o.doc._attachments&&o.doc._attachments[t]?(n.ctx=o.ctx,n.binary=!0,void this._getAttachment(e,t,o.doc._attachments[t],n,r)):r(Q(D)))})).bind(this),this.allDocs=w("allDocs",(function(e,t){if("function"==typeof e&&(t=e,e={}),e.skip=void 0!==e.skip?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 n=["startkey","endkey","key"].filter((function(t){return t in e}))[0];if(n)return void t(Q(U,"Query parameter `"+n+"` is not compatible with multi-get"));if(!Z(this)&&(function(e){var t="limit"in e?e.keys.slice(e.skip,e.limit+e.skip):e.skip>0?e.keys.slice(e.skip):e.keys;e.keys=t,e.skip=0,delete e.limit,e.descending&&(t.reverse(),e.descending=!1)}(e),0===e.keys.length))return this._allDocs({limit:0},t)}return this._allDocs(e,t)})).bind(this),this.close=w("close",(function(e){return this._closed=!0,this.emit("closed"),this._close(e)})).bind(this),this.info=w("info",(function(e){this._info((t,n)=>{if(t)return e(t);n.db_name=n.db_name||this.name,n.auto_compaction=!(!this.auto_compaction||Z(this)),n.adapter=this.adapter,e(null,n)})})).bind(this),this.id=w("id",(function(e){return this._id(e)})).bind(this),this.bulkDocs=w("bulkDocs",(function(e,t,n){if("function"==typeof t&&(n=t,t={}),t=t||{},Array.isArray(e)&&(e={docs:e}),!e||!e.docs||!Array.isArray(e.docs))return n(Q(L));for(var r=0;r{this._destroy(e,(e,n)=>{if(e)return t(e);this._destroyed=!0,this.emit("destroyed"),t(null,n||{ok:!0})})};if(Z(this))return r();this.get("_local/_pouch_dependentDbs",(e,i)=>{if(e)return 404!==e.status?t(e):r();var o=i.dependentDbs,s=this.constructor,a=Object.keys(o).map(e=>{var t=n?e.replace(new RegExp("^"+s.prefix),""):e;return new s(t,this.__opts).destroy()});Promise.all(a).then(r,t)})})).bind(this)}_compact(e,t){var n,r={return_docs:!1,last_seq:e.last_seq||0},i=[],o=0;const s=e=>{this.activeTasks.update(n,{completed_items:++o}),i.push(this.compactDocument(e.id,0))},a=e=>{this.activeTasks.remove(n,e),t(e)},c=e=>{var r=e.last_seq;Promise.all(i).then(()=>ae(this,"_local/compaction",e=>(!e.last_seq||e.last_seq{this.activeTasks.remove(n),t(null,{ok:!0})}).catch(a)};this.info().then(e=>{n=this.activeTasks.add({name:"database_compaction",total_items:e.update_seq-r.last_seq}),this.changes(r).on("change",s).on("complete",c).on("error",a)})}changes(e,t){return"function"==typeof e&&(t=e,e={}),(e=e||{}).return_docs="return_docs"in e?e.return_docs:!e.live,new Ue(this,e,t)}type(){return"function"==typeof this._type?this._type():this.adapter}}Ve.prototype.purge=w("_purge",(function(e,t,n){if(void 0===this._purge)return n(Q(R,"Purge is not implemented in the "+this.adapter+" adapter."));var r=this;r._getRevisionTree(e,(i,o)=>{if(i)return n(i);if(!o)return n(Q(D));let s;try{s=function(e,t){let n=[];const r=e.slice();let i;for(;i=r.pop();){const{pos:e,ids:o}=i,s=`${e}-${o[0]}`,a=o[2];if(n.push(s),s===t){if(0!==a.length)throw new Error("The requested revision is not a leaf");return n.reverse()}(0===a.length||a.length>1)&&(n=[]);for(let t=0,n=a.length;t{if(i)return n(i);ze(r,e,t).then((function(){return n(null,o)}))})})}));class Ge{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 Qe(e,t){let n=function(...e){if(!(this instanceof n))return new n(...e);t.apply(this,e)};var r,i;return i=e,(r=n).prototype=Object.create(i.prototype,{constructor:{value:r}}),n}class We extends Ve{constructor(e,t){super(),this._setup(e,t)}_setup(e,t){if(super._setup(),t=t||{},e&&"object"==typeof e&&(e=(t=e).name,delete t.name),void 0===t.deterministic_revs&&(t.deterministic_revs=!0),this.__opts=t=g(t),this.auto_compaction=t.auto_compaction,this.purged_infos_limit=t.purged_infos_limit||1e3,this.prefix=Ye.prefix,"string"!=typeof e)throw new Error("Missing/invalid DB name");var n=function(e,t){var n=e.match(/([a-z-]*):\/\/(.*)/);if(n)return{name:/https?/.test(n[1])?n[1]+"://"+n[2]:n[2],adapter:n[1]};var r=Ye.adapters,i=Ye.preferredAdapters,o=Ye.prefix,s=t.adapter;if(!s)for(var a=0;a{if(e)return this.taskqueue.fail(e);!function(e){function t(t){e.removeListener("closed",n),t||e.constructor.emit("destroyed",e.name)}function n(){e.removeListener("destroyed",t),e.constructor.emit("unref",e)}e.once("destroyed",t),e.once("closed",n),e.constructor.emit("ref",e)}(this),this.emit("created",this),Ye.emit("created",this.name),this.taskqueue.ready(this)})}}const Ye=Qe(We,(function(e,t){We.prototype._setup.call(this,e,t)}));var He="undefined"!=typeof AbortController?AbortController:function(){return{abort:function(){}}},Xe=fetch,Ze=Headers;Ye.adapters={},Ye.preferredAdapters=[],Ye.prefix="_pouch_";var et=new f;!function(e){Object.keys(f.prototype).forEach((function(t){"function"==typeof f.prototype[t]&&(e[t]=et[t].bind(et))}));var t=e._destructionListeners=new o;e.on("ref",(function(e){t.has(e.name)||t.set(e.name,[]),t.get(e.name).push(e)})),e.on("unref",(function(e){if(t.has(e.name)){var n=t.get(e.name),r=n.indexOf(e);r<0||(n.splice(r,1),n.length>1?t.set(e.name,n):t.delete(e.name))}})),e.on("destroyed",(function(e){if(t.has(e)){var n=t.get(e);t.delete(e),n.forEach((function(e){e.emit("destroyed",!0)}))}}))}(Ye),Ye.adapter=function(e,t,n){t.valid()&&(Ye.adapters[e]=t,n&&Ye.preferredAdapters.push(e))},Ye.plugin=function(e){if("function"==typeof e)e(Ye);else{if("object"!=typeof e||0===Object.keys(e).length)throw new Error('Invalid plugin: got "'+e+'", expected an object or a function');Object.keys(e).forEach((function(t){Ye.prototype[t]=e[t]}))}return this.__defaults&&(Ye.__defaults=C({},this.__defaults)),Ye},Ye.defaults=function(e){let t=Qe(Ye,(function(e,n){n=n||{},e&&"object"==typeof e&&(e=(n=e).name,delete n.name),n=C({},t.__defaults,n),Ye.call(this,e,n)}));return t.preferredAdapters=Ye.preferredAdapters.slice(),Object.keys(Ye).forEach((function(e){e in t||(t[e]=Ye[e])})),t.__defaults=C({},this.__defaults,e),t},Ye.fetch=function(e,t){return Xe(e,t)},Ye.prototype.activeTasks=Ye.activeTasks=new class{constructor(){this.tasks={}}list(){return Object.values(this.tasks)}add(e){const t=c.v4();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 n=this.tasks[e];if(void 0!==n){const r={id:n.id,name:n.name,created_at:n.created_at,total_items:t.total_items||n.total_items,completed_items:t.completed_items||n.completed_items,updated_at:(new Date).toJSON()};this.tasks[e]=r}return this.tasks}};function tt(e,t){for(var n=e,r=0,i=t.length;r0&&"\\"===e[r-1]&&("$"===o||"."===o)?n=n.substring(0,n.length-1)+o:"."===o?(t.push(n),n=""):n+=o}return t.push(n),t}var rt=["$or","$nor","$not"];function it(e){return rt.indexOf(e)>-1}function ot(e){return Object.keys(e)[0]}function st(e){var t={},n={$or:!0,$nor:!0};return e.forEach((function(e){Object.keys(e).forEach((function(r){var i=e[r];if("object"!=typeof i&&(i={$eq:i}),it(r))if(i instanceof Array){if(n[r])return n[r]=!1,void(t[r]=i);var o=[];t[r].forEach((function(e){Object.keys(i).forEach((function(t){var n=i[t],r=Math.max(Object.keys(e).length,Object.keys(n).length),s=st([e,n]);Object.keys(s).length<=r||o.push(s)}))})),t[r]=o}else t[r]=st([i]);else{var s=t[r]=t[r]||{};Object.keys(i).forEach((function(e){var t=i[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?tt?1:-1}(e,t)}return Array.isArray(e)?function(e,t){for(var n=Math.min(e.length,t.length),r=0;rt.length?1:-1}(e,t):function(e,t){for(var n=Object.keys(e),r=Object.keys(t),i=Math.min(n.length,r.length),o=0;or.length?1:-1}(e,t)}function ut(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;ri?1:0)}}(t.sort);e=e.sort(r),"string"!=typeof t.sort[0]&&"desc"===(i=t.sort[0])[ot(i)]&&(e=e.reverse())}var i;if("limit"in t||"skip"in t){var o=t.skip||0,s=("limit"in t?t.limit:e.length)+o;e=e.slice(o,s)}return e}function yt(e,t,n){return n.every((function(n){var r=t[n],i=nt(n),o=tt(e,i);return it(n)?function(e,t,n){if("$or"===e)return t.some((function(e){return yt(n,e,Object.keys(e))}));if("$not"===e)return!yt(n,t,Object.keys(t));return!t.find((function(e){return yt(n,e,Object.keys(e))}))}(n,r,e):_t(r,e,i,o)}))}function _t(e,t,n,r){return!e||("object"==typeof e?Object.keys(e).every((function(i){var o=e[i];if(0===i.indexOf("$"))return gt(i,t,o,n,r);var s=nt(i);if(void 0===r&&"object"!=typeof o&&s.length>0)return!1;var a=tt(r,s);return"object"==typeof o?_t(o,t,n,a):gt("$eq",t,o,s,a)})):e===r)}function gt(e,t,n,r,i){if(!kt[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 kt[e](t,n,r,i)}function mt(e){return null!=e}function bt(e){return void 0!==e}function wt(e,t){return t.some((function(t){return e instanceof Array?e.some((function(e){return 0===ct(t,e)})):0===ct(t,e)}))}var kt={$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 yt(e,t,Object.keys(t))})):r.some((function(r){return _t(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 yt(e,t,Object.keys(t))})):r.every((function(r){return _t(t,e,n,r)}))))},$eq:function(e,t,n,r){return bt(r)&&0===ct(r,t)},$gte:function(e,t,n,r){return bt(r)&&ct(r,t)>=0},$gt:function(e,t,n,r){return bt(r)&&ct(r,t)>0},$lte:function(e,t,n,r){return bt(r)&&ct(r,t)<=0},$lt:function(e,t,n,r){return bt(r)&&ct(r,t)<0},$exists:function(e,t,n,r){return t?bt(r):!bt(r)},$mod:function(e,t,n,r){return mt(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!==ct(r,e)}))},$in:function(e,t,n,r){return mt(r)&&wt(r,t)},$nin:function(e,t,n,r){return mt(r)&&!wt(r,t)},$size:function(e,t,n,r){return mt(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===ct(t,e)}))}))}(r,t)},$regex:function(e,t,n,r){return mt(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 jt(e,t){if(e.selector&&e.filter&&"_selector"!==e.filter){var n="string"==typeof e.filter?e.filter:"function";return t(new Error('selector invalid for filter "'+n+'"'))}t()}function qt(e){e.view&&!e.filter&&(e.filter="_view"),e.selector&&!e.filter&&(e.filter="_selector"),e.filter&&"string"==typeof e.filter&&("_view"===e.filter?e.view=te(e.view):e.filter=te(e.filter))}function Ot(e,t){return t.filter&&"string"==typeof t.filter&&!t.doc_ids&&!Z(e.db)}function At(e,t){var n=t.complete;if("_view"===t.filter){if(!t.view||"string"!=typeof t.view){var r=Q(K,"`view` filter parameter not found or invalid.");return n(r)}var i=ee(t.view);e.db.get("_design/"+i[0],(function(r,o){if(e.isCancelled)return n(null,{status:"cancelled"});if(r)return n(W(r));var s=o&&o.views&&o.views[i[1]]&&o.views[i[1]].map;if(!s)return n(Q(D,o.views?"missing json key: "+i[1]:"missing json key: views"));t.filter=se(["return function(doc) {",' "use strict";'," var emitted = false;"," var emit = function (a, b) {"," emitted = true;"," };"," var view = "+s+";"," view(doc);"," if (emitted) {"," return true;"," }","};"].join("\n"),{}),e.doChanges(t)}))}else if(t.selector)t.filter=function(e){return function(e,t){if("object"!=typeof t)throw new Error("Selector error: expected a JSON object");var n=vt([{doc:e}],{selector:t=at(t)},Object.keys(t));return n&&1===n.length}(e,t.selector)},e.doChanges(t);else{var o=ee(t.filter);e.db.get("_design/"+o[0],(function(r,i){if(e.isCancelled)return n(null,{status:"cancelled"});if(r)return n(W(r));var s=i&&i.filters&&i.filters[o[1]];if(!s)return n(Q(D,i&&i.filters?"missing json key: "+o[1]:"missing json key: filters"));t.filter=se('"use strict";\nreturn '+s+";",{}),e.doChanges(t)}))}}function St(e){return e.reduce((function(e,t){return e[t]=!0,e}),{})}Ye.plugin((function(e){e._changesFilterPlugin={validate:jt,normalize:qt,shouldFilter:Ot,filter:At}})),Ye.version="8.0.1";var xt=St(["_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"]),Et=St(["_access","_attachments","_replication_id","_replication_state","_replication_state_time","_replication_state_reason","_replication_stats"]);function Pt(e){if(!/^\d+-/.test(e))return Q(V);var t=e.indexOf("-"),n=e.substring(0,t),r=e.substring(t+1);return{prefix:parseInt(n,10),id:r}}function Ct(e,t,n){var r,i,o;n||(n={deterministic_revs:!0});var s={status:"available"};if(e._deleted&&(s.deleted=!0),t)if(e._id||(e._id=je()),i=ke(e,n.deterministic_revs),e._rev){if((o=Pt(e._rev)).error)return o;e._rev_tree=[{pos:o.prefix,ids:[o.id,{status:"missing"},[[i,s,[]]]]}],r=o.prefix+1}else e._rev_tree=[{pos:1,ids:[i,s,[]]}],r=1;else if(e._revisions&&(e._rev_tree=function(e,t){for(var n=e.start-e.ids.length+1,r=e.ids,i=[r[0],t,[]],o=1,s=r.length;o{this.emit(e.key)})}addListener(e,t,n,r){if(!this._listeners[t]){var i=!1,o=this;this._listeners[t]=a,this.on(e,a)}function a(){if(o._listeners[t])if(i)i="waiting";else{i=!0;var e=k(r,["style","include_docs","attachments","conflicts","filter","doc_ids","view","since","query_params","binary","return_docs"]);n.changes(e).on("change",(function(e){e.seq>r.since&&!r.cancelled&&(r.since=e.seq,r.onChange(e))})).on("complete",(function(){"waiting"===i&&s(a),i=!1})).on("error",(function(){i=!1}))}}}removeListener(e,t){t in this._listeners&&(super.removeListener(e,this._listeners[t]),delete this._listeners[t])}notifyLocalWindows(e){S()&&(localStorage[e]="a"===localStorage[e]?"b":"a")}notify(e){this.emit(e),this.notifyLocalWindows(e)}};function Wt(e,t,n,r,i,s){for(var a,c,u,f,l,d,h,p,v=t.docs,y=0,_=v.length;y<_;y++){var g=v[y];g._id&&Re(g._id)||(g=v[y]=Ct(g,n.new_edits,e)).error&&!h&&(h=g)}if(h)return s(h);var m=!1,b=0,w=new Array(v.length),k=new o,j=!1,q=r._meta.blobSupport?"blob":"base64";function O(){m=!0,A()}function A(){p&&m&&(p.docCount+=b,d.put(p))}function S(){j||(Qt.notify(r._meta.name),s(null,w))}function x(e,t,n,r,i,o,s,a){e.metadata.winningRev=t,e.metadata.deleted=n;var c=e.data;if(c._id=e.metadata.id,c._rev=e.metadata.rev,r&&(c._deleted=!0),c._attachments&&Object.keys(c._attachments).length)return function(e,t,n,r,i,o){var s=e.data,a=0,c=Object.keys(s._attachments);function u(){a===c.length&&E(e,t,n,r,i,o)}function l(){a++,u()}c.forEach((function(n){var r=e.data._attachments[n];if(r.stub)a++,u();else{var i=r.data;delete r.data,r.revpos=parseInt(t,10),function(e,t,n){f.count(e).onsuccess=function(r){if(r.target.result)return n();var i={digest:e,body:t};f.put(i).onsuccess=n}}(r.digest,i,l)}}))}(e,t,n,i,s,a);b+=o,A(),E(e,t,n,i,s,a)}function E(e,t,n,i,o,s){var f=e.data,d=e.metadata;function h(o){var s=e.stemmedRevs||[];i&&r.auto_compaction&&(s=s.concat(function(e){var t=[];return Oe(e.rev_tree,(function(e,n,r,i,o){"available"!==o.status||e||(t.push(n+"-"+r),o.status="missing")})),t}(e.metadata))),s&&s.length&&Vt(s,e.metadata.id,a),d.seq=o.target.result;var u=Nt(d,t,n);c.put(u).onsuccess=p}function p(){w[o]={ok:!0,id:d.id,rev:d.rev},k.set(e.metadata.id,e.metadata),function(e,t,n){var r=0,i=Object.keys(e.data._attachments||{});if(!i.length)return n();function o(){++r===i.length&&n()}function s(n){var r=e.data._attachments[n].digest,i=l.put({seq:t,digestSeq:r+"::"+t});i.onsuccess=o,i.onerror=function(e){e.preventDefault(),e.stopPropagation(),o()}}for(var a=0;a1&&!n?(a={continue:function(){if(!o.length)return i();var n,a=o[o.length-1];if(t&&t.upper)try{n=IDBKeyRange.bound(a,t.upper,!0,t.upperOpen)}catch(e){if("DataError"===e.name&&0===e.code)return i()}else n=IDBKeyRange.lowerBound(a,!0);t=n,o=null,s=null,e.getAll(t,r).onsuccess=c,e.getAllKeys(t,r).onsuccess=u}},e.getAll(t,r).onsuccess=c,e.getAllKeys(t,r).onsuccess=u):n?e.openCursor(t,"prev").onsuccess=f:e.openCursor(t).onsuccess=f}function Ht(e,t,n){var r,i,o="startkey"in e&&e.startkey,s="endkey"in e&&e.endkey,a="key"in e&&e.key,c="keys"in e&&e.keys,u=e.skip||0,f="number"==typeof e.limit?e.limit:-1,l=!1!==e.inclusive_end;if(!c&&(i=(r=function(e,t,n,r,i){try{if(e&&t)return i?IDBKeyRange.bound(t,e,!n,!1):IDBKeyRange.bound(e,t,!1,!n);if(e)return i?IDBKeyRange.upperBound(e):IDBKeyRange.lowerBound(e);if(t)return i?IDBKeyRange.lowerBound(t,!n):IDBKeyRange.upperBound(t,!n);if(r)return IDBKeyRange.only(r)}catch(e){return{error:e}}return null}(o,s,l,a,e.descending))&&r.error)&&("DataError"!==i.name||0!==i.code))return n(Q(z,i.name,i.message));var d=[Tt,"by-sequence",Bt];e.attachments&&d.push("attach-store");var h=Gt(t,d,"readonly");if(h.error)return n(h.error);var p=h.txn;p.oncomplete=function(){e.attachments?zt(k,e.binary).then(A):A()},p.onabort=Rt(n);var v,y,_,g=p.objectStore(Tt),m=p.objectStore("by-sequence"),b=p.objectStore(Bt),w=m.index("_doc_id_rev"),k=[];function j(t,n){var r={id:n.id,key:n.id,value:{rev:t}};n.deleted?c&&(k.push(r),r.value.deleted=!0,r.doc=null):u--<=0&&(k.push(r),e.include_docs&&function(t,n,r){var i=t.id+"::"+r;w.get(i).onsuccess=function(r){if(n.doc=Ft(r.target.result)||{},e.conflicts){var i=xe(t);i.length&&(n.doc._conflicts=i)}Jt(n.doc,e,p)}}(n,r,t))}function q(e){for(var t=0,n=e.length;t0&&(y=e.target.result[0])},m.openCursor(null,"prev").onsuccess=function(e){var t=e.target.result,n=void 0;return t&&t.key&&(n=t.key),_({target:{result:[n]}})}),i||0===f?void 0:c?function(e,t,n){var r=new Array(e.length),i=0;e.forEach((function(o,s){t.get(o).onsuccess=function(t){t.target.result?r[s]=t.target.result:r[s]={key:o,error:"not_found"},++i===e.length&&n(e,r,{})}}))}(e.keys,g,O):-1===f?function(e,t,n){if("function"!=typeof e.getAll){var r=[];e.openCursor(t).onsuccess=function(e){var t=e.target.result;t?(r.push(t.value),t.continue()):n({target:{result:r}})}}else e.getAll(t).onsuccess=n}(g,r,(function(t){var n=t.target.result;e.descending&&(n=n.reverse()),q(n)})):void Yt(g,r,e.descending,f+u,O)}var Xt=!1,Zt=[];function en(){!Xt&&Zt.length&&(Xt=!0,Zt.shift()())}function tn(e,t,n,r){if((e=g(e)).continuous){var s=n+":"+je();return Qt.addListener(n,s,t,e),Qt.notify(n),{cancel:function(){Qt.removeListener(n,s)}}}var a=e.doc_ids&&new i(e.doc_ids);e.since=e.since||0;var c=e.since,u="limit"in e?e.limit:-1;0===u&&(u=1);var f,l,d,h,p=[],v=0,y=Y(e),_=new o;function m(e,t,n,r){if(n.seq!==t)return r();if(n.winningRev===e._rev)return r(n,e);var i=e._id+"::"+n.winningRev;h.get(i).onsuccess=function(e){r(n,Ft(e.target.result))}}function b(){e.complete(null,{results:p,last_seq:c})}var w=[Tt,"by-sequence"];e.attachments&&w.push("attach-store");var k=Gt(r,w,"readonly");if(k.error)return e.complete(k.error);(f=k.txn).onabort=Rt(e.complete),f.oncomplete=function(){!e.continuous&&e.attachments?zt(p).then(b):b()},l=f.objectStore("by-sequence"),d=f.objectStore(Tt),h=l.index("_doc_id_rev"),Yt(l,e.since&&!e.descending?IDBKeyRange.lowerBound(e.since,!0):null,e.descending,u,(function(t,n,r){if(r&&t.length){var i=new Array(t.length),o=new Array(t.length),s=0;n.forEach((function(n,c){!function(e,t,n){if(a&&!a.has(e._id))return n();var r=_.get(e._id);if(r)return m(e,t,r,n);d.get(e._id).onsuccess=function(i){r=Ut(i.target.result),_.set(e._id,r),m(e,t,r,n)}}(Ft(n),t[c],(function(n,a){o[c]=n,i[c]=a,++s===t.length&&function(){for(var t=[],n=0,s=i.length;ni&&(i=n),t.continue()}}()}function s(){var e=Nt(o,o.winningRev,o.deleted);n.put(e).onsuccess=function(){r.continue()}}}}e._meta=null,e._remote=!1,e.type=function(){return"idb"},e._id=b((function(t){t(null,e._meta.instanceId)})),e._bulkDocs=function(n,r,o){Wt(t,n,r,e,i,a(o))},e._get=function(e,t,n){var r,o,s,a=t.ctx;if(!a){var c=Gt(i,[Tt,"by-sequence","attach-store"],"readonly");if(c.error)return n(c.error);a=c.txn}function u(){n(s,{doc:r,metadata:o,ctx:a})}a.objectStore(Tt).get(e).onsuccess=function(e){if(!(o=Ut(e.target.result)))return s=Q(D,"missing"),u();var n;if(t.rev)n=t.latest?function(e,t){for(var n,r=t.rev_tree.slice();n=r.pop();){var i=n.pos,o=n.ids,s=o[0],a=o[1],c=o[2],u=0===c.length,f=n.history?n.history.slice():[];if(f.push({id:s,pos:i,opts:a}),u)for(var l=0,d=f.length;l=43)},r.onerror=e.onabort=function(e){e.preventDefault(),e.stopPropagation(),t(!1)}})).catch((function(){return!1}))}(f)),nn.then((function(e){c=e,d()})),f.oncomplete=function(){l=!0,d()},f.onabort=Rt(n)},h.onerror=function(e){var t=e.target.error&&e.target.error.message;t?-1!==t.indexOf("stored database is a higher version")&&(t=new Error('This DB was created with the newer "indexeddb" adapter, but you are trying to open it with the older "idb" adapter')):t="Failed to open indexedDB, are you in private browsing mode?",x("error",t),n(Q(z,t))}}(n,e,t)}),t,n.constructor)}sn.valid=function(){try{return"undefined"!=typeof indexedDB&&"undefined"!=typeof IDBKeyRange}catch(e){return!1}};let an={};function cn(e){let t=e.doc||e.ok,n=t&&t._attachments;n&&Object.keys(n).forEach((function(e){let t=n[e];t.data=he(t.data,t.content_type)}))}function un(e){return/^_design/.test(e)?"_design/"+encodeURIComponent(e.slice(8)):/^_local/.test(e)?"_local/"+encodeURIComponent(e.slice(7)):encodeURIComponent(e)}function fn(e){return e._attachments&&Object.keys(e._attachments)?Promise.all(Object.keys(e._attachments).map((function(t){let n=e._attachments[t];if(n.data&&"string"!=typeof n.data)return new Promise((function(e){ye(n.data,e)})).then((function(e){n.data=e}))}))):Promise.resolve()}function ln(e,t){if(function(e){if(!e.prefix)return!1;let t=oe(e.prefix).protocol;return"http"===t||"https"===t}(t)){let n=t.name.substr(t.prefix.length);e=t.prefix.replace(/\/?$/,"/")+encodeURIComponent(n)}let n=oe(e);(n.user||n.password)&&(n.auth={username:n.user,password:n.password});let r=n.path.replace(/(^\/|\/$)/g,"").split("/");return n.db=r.pop(),-1===n.db.indexOf("%")&&(n.db=encodeURIComponent(n.db)),n.path=r.join("/"),n}function dn(e,t){return hn(e,e.db+"/"+t)}function hn(e,t){let n=e.path?"/":"";return e.protocol+"://"+e.host+(e.port?":"+e.port:"")+"/"+e.path+n+t}function pn(e){return"?"+Object.keys(e).map((function(t){return t+"="+encodeURIComponent(e[t])})).join("&")}function vn(e,t){let r=this,i=ln(e.name,e),o=dn(i,"");e=g(e);const a=async function(t,n){if((n=n||{}).headers=n.headers||new Ze,n.credentials="include",e.auth||i.auth){let t=e.auth||i.auth,r=t.username+":"+t.password,o=ue(unescape(encodeURIComponent(r)));n.headers.set("Authorization","Basic "+o)}let r=e.headers||{};Object.keys(r).forEach((function(e){n.headers.append(e,r[e])})),function(e){let t="undefined"!=typeof navigator&&navigator.userAgent?navigator.userAgent.toLowerCase():"",n=-1!==t.indexOf("msie"),r=-1!==t.indexOf("trident"),i=-1!==t.indexOf("edge"),o=!("method"in e)||"GET"===e.method;return(n||r||i)&&o}(n)&&(t+=(-1===t.indexOf("?")?"?":"&")+"_nonce="+Date.now());let o=e.fetch||Xe;return await o(t,n)};function c(e,t){return w(e,(function(...e){l().then((function(){return t.apply(this,e)})).catch((function(t){e.pop()(t)}))})).bind(r)}async function u(e,t){let n={};(t=t||{}).headers=t.headers||new Ze,t.headers.get("Content-Type")||t.headers.set("Content-Type","application/json"),t.headers.get("Accept")||t.headers.set("Accept","application/json");const r=await a(e,t);n.ok=r.ok,n.status=r.status;const i=await r.json();if(n.data=i,!n.ok){throw n.data.status=n.status,W(n.data)}return Array.isArray(n.data)&&(n.data=n.data.map((function(e){return e.error||e.missing?W(e):e}))),n}let f;async function l(){return e.skip_setup?Promise.resolve():f||(f=u(o).catch((function(e){return e&&e.status&&404===e.status?(P(404,"PouchDB is just detecting if the remote exists."),u(o,{method:"PUT"})):Promise.reject(e)})).catch((function(e){return!(!e||!e.status||412!==e.status)||Promise.reject(e)})),f.catch((function(){f=null})),f)}function d(e){return e.split("/").map(encodeURIComponent).join("/")}s((function(){t(null,r)})),r._remote=!0,r.type=function(){return"http"},r.id=c("id",(async function(e){let t;try{const e=await a(hn(i,""));t=await e.json()}catch(e){t={}}e(null,t&&t.uuid?t.uuid+i.db:dn(i,""))})),r.compact=c("compact",(async function(e,t){"function"==typeof e&&(t=e,e={}),e=g(e),await u(dn(i,"_compact"),{method:"POST"}),function n(){r.info((function(r,i){i&&!i.compact_running?t(null,{ok:!0}):setTimeout(n,e.interval||200)}))}()})),r.bulkGet=w("bulkGet",(function(e,t){let n=this;async function r(t){let n={};e.revs&&(n.revs=!0),e.attachments&&(n.attachments=!0),e.latest&&(n.latest=!0);try{const r=await u(dn(i,"_bulk_get"+pn(n)),{method:"POST",body:JSON.stringify({docs:e.docs})});e.attachments&&e.binary&&r.data.results.forEach((function(e){e.docs.forEach(cn)})),t(null,r.data)}catch(e){t(e)}}function o(){let r=Math.ceil(e.docs.length/50),i=0,o=new Array(r);function s(e){return function(n,s){o[e]=s.results,++i===r&&t(null,{results:H(o)})}}for(let t=0;tt?t:a;let p=dn(i,"_changes"+pn(r)),v={signal:h.signal,method:f,body:JSON.stringify(c)};if(d=n,!e.aborted)try{await l();s(null,(await u(p,v)).data)}catch(e){s(e)}};let v={results:[]};const y=function(n,r){if(e.aborted)return;let i=0;if(r&&r.results){i=r.results.length,v.last_seq=r.last_seq;let t=null,n=null;"number"==typeof r.pending&&(t=r.pending),"string"!=typeof v.last_seq&&"number"!=typeof v.last_seq||(n=v.last_seq),{}.query=e.query_params,r.results=r.results.filter((function(r){a--;let i=Y(e)(r);return i&&(e.include_docs&&e.attachments&&e.binary&&cn(r),e.return_docs&&v.results.push(r),e.onChange(r,t,n)),i}))}else if(n)return e.aborted=!0,void e.complete(n);r&&r.last_seq&&(d=r.last_seq);let c=o&&a<=0||r&&i0?e.slice(n):e}function l(e){const t=e.value;return t&&"object"==typeof t&&t._id||e.id}function d(e){return function(t){return e.include_docs&&e.attachments&&e.binary&&function(e){e.rows.forEach((function(e){const t=e.doc&&e.doc._attachments;t&&Object.keys(t).forEach((function(e){const n=t[e];t[e].data=he(n.data,n.content_type)}))}))}(t),t}}function h(e,t,n,r){let i=t[e];void 0!==i&&(r&&(i=encodeURIComponent(JSON.stringify(i))),n.push(e+"="+i))}function p(e){if(void 0!==e){const t=Number(e);return isNaN(t)||t!==parseInt(e,10)?e:t}}function v(e,t){const n=e.descending?"endkey":"startkey",r=e.descending?"startkey":"endkey";if(void 0!==e[n]&&void 0!==e[r]&&ct(e[n],e[r])>0)throw new yn("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 yn("{include_docs:true} is invalid for reduce");if(e.keys&&e.keys.length>1&&!e.group&&!e.group_level)throw new yn("Multi-key fetches for reduce views must use {group: true}")}["group_level","limit","skip"].forEach((function(t){const n=function(e){if(e){if("number"!=typeof e)return new yn(`Invalid value for integer: "${e}"`);if(e<0)return new yn(`Invalid value for positive integer: "${e}"`)}}(e[t]);if(n)throw n}))}function y(e){return function(t){if(404===t.status)return e;throw t}}function _(e,t,n){return e.db.get("_local/lastSeq").catch(y({_id:"_local/lastSeq",seq:0})).then((function(r){var o=kn(t);return Promise.all(o.map((function(n){return async function(e,t,n){const r="_local/doc_"+e,o={_id:r,keys:[]},s=n.get(e),a=s[0],c=s[1],u=await(function(e){return 1===e.length&&/^1-/.test(e[0].rev)}(c)?Promise.resolve(o):t.db.get(r).catch(y(o)));return function(e,t){const n=[],r=new i;for(let e=0,i=t.rows.length;efunction(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((function(e){if(404!==e.status)throw e})).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 g(e){const t="string"==typeof e?e:e.name;let n=$n[t];return n||(n=$n[t]=new En),n}async function m(e,n){return bn(g(e),(function(){return async function(e,n){let r,i,s;const c=t(e.mapFun,(function(e,t){const n={id:i._id,key:ut(e)};null!=t&&(n.value=ut(t)),r.push(n)}));let f=e.seq||0;let l=0;const d={view:e.name,indexed_docs:l};e.sourceDB.emit("indexing",d);const h=new En;async function p(){return function(t,d){var y=t.results;if(!y.length&&!d.length)return;for(let e of d){if(y.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})),y.push(t)}}var g=function(t){const n=new o;for(let o=0,s=t.length;ot})).map(e=>e.docId),i=r.filter((function(e,t){return r.indexOf(e)===t}));return Promise.all(i.map((function(t){return e.sourceDB.get(t).then((function(e){return{docId:t,doc:e}})).catch((function(e){if(404!==e.status)throw e;return{docId:t}}))})))})).catch((function(e){if(e&&404!==e.status)throw e;return[]}))})))}function v(e){const t=new o;let n;for(let r=0,i=e.length;r0&&0===ct(i.key,n)&&o.push(r),t.set(lt(o),i),n=i.key}return t}try{await e.sourceDB.info().then((function(t){s=e.sourceDB.activeTasks.add({name:"view_indexing",total_items:t.update_seq-f})})),await p(),await h.finish(),e.seq=f,e.sourceDB.activeTasks.remove(s)}catch(t){e.sourceDB.activeTasks.remove(s,t)}}(e,n)}))()}function b(e,t){return bn(g(e),(function(){return async function(e,t){let r;const i=e.reduceFun&&!1!==t.reduce,s=t.skip||0;void 0===t.keys||t.keys.length||(t.limit=0,delete t.keys);async function a(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(!(tn))return e.doc.value}const t=function(e){for(var t=[],n=[],r=0;;){var i=e[r++];if("\0"!==i)switch(i){case"1":t.push(null);break;case"2":t.push("1"===e[r]),r++;break;case"3":var o=dt(e,r);t.push(o.num),r+=o.length;break;case"4":for(var s="";;){var a=e[r];if("\0"===a)break;s+=a,r++}s=s.replace(/\u0001\u0001/g,"\0").replace(/\u0001\u0002/g,"").replace(/\u0002\u0002/g,""),t.push(s);break;case"5":var c={element:[],index:t.length};t.push(c.element),n.push(c);break;case"6":var u={element:{},index:t.length};t.push(u.element),n.push(u);break;default:throw new Error("bad collationIndex or unexpectedly reached end of input: "+i)}else{if(1===t.length)return t.pop();ht(t,n)}}}(e.doc._id);return{key:t[0],id:t[1],value:"value"in e.doc?e.doc.value:null}}))}async function u(a){let u;if(u=i?function(e,t,r){0===r.group_level&&delete r.group_level;const i=r.group||r.group_level,o=n(e.reduceFun),s=[],a=isNaN(r.group_level)?Number.POSITIVE_INFINITY:r.group_level;t.forEach((function(e){const t=s[s.length-1];let n=i?e.key:null;if(i&&Array.isArray(n)&&(n=n.slice(0,a)),t&&0===ct(t.groupKey,n))return t.keys.push([e.key,e.id]),void t.values.push(e.value);s.push({keys:[[e.key,e.id]],values:[e.value],groupKey:n})})),t=[];for(let n=0,r=s.length;n=m)&&(f.push(l),l={seq:0,changes:[],docs:[]},"pending"!==r.state&&"stopped"!==r.state||(r.state="active",r.emit("active")),L()):0!==f.length||o||((_&&S.live||h)&&(r.state="pending",r.emit("paused")),h&&T())}function I(e,t){p||(t.message||(t.message=e),i.ok=!1,i.status="aborting",f=[],l={seq:0,changes:[],docs:[]},T(t))}function T(o){if(!(p||r.cancelled&&(i.status="cancelled",d)))if(i.status=i.status||"complete",i.end_time=(new Date).toISOString(),i.last_seq=y,p=!0,e.activeTasks.remove(u,o),o){(o=Q(o)).result=i;var s=(o.name||"").toLowerCase();"unauthorized"===s||"forbidden"===s?(r.emit("error",o),r.removeAllListeners()):function(e,t,n,r){if(!1===e.retry)return t.emit("error",n),void t.removeAllListeners();if("function"!=typeof e.back_off_function&&(e.back_off_function=E),t.emit("requestError",n),"active"===t.state||"pending"===t.state){t.emit("paused",n),t.state="stopped";var i=function(){e.current_back_off=0};t.once("paused",(function(){t.removeListener("active",i)})),t.once("active",i)}e.current_back_off=e.current_back_off||0,e.current_back_off=e.back_off_function(e.current_back_off),setTimeout(r,e.current_back_off)}(n,r,o,(function(){Yn(e,t,n,r)}))}else r.emit("complete",i),r.removeAllListeners()}function B(t,i,o){if(r.cancelled)return T();if("number"==typeof i&&(l.pending=i),Y(n)(t))l.seq=t.seq||o,l.changes.push(t),r.emit("checkpoint",{pending_batch:l.seq}),s((function(){D(0===f.length&&S.live)}));else{var a=e.activeTasks.get(u);if(a){var c=a.completed_items||0;e.activeTasks.update(u,{completed_items:++c})}}}function M(e){if(k=!1,r.cancelled)return T();if(e.results.length>0)S.since=e.results[e.results.length-1].seq,N(),D(!0);else{var t=function(){_?(S.live=!0,N()):h=!0,D(!0)};o||0!==e.results.length?t():(d=!0,c.writeCheckpoint(e.last_seq,A).then((function(){if(d=!1,i.last_seq=y=e.last_seq,r.cancelled)throw T(),new Error("cancelled");t()})).catch(K))}}function R(e){if(k=!1,r.cancelled)return T();I("changes rejected",e)}function N(){if(!k&&!h&&f.length{this.once("complete",e),this.once("error",t)});this.then=function(t,n){return e.then(t,n)},this.catch=function(t){return e.catch(t)},this.catch((function(){}))}cancel(){this.cancelled=!0,this.state="cancelled",this.emit("cancel")}ready(e,t){if(this._readyCalled)return;this._readyCalled=!0;const n=()=>{this.cancel()};function r(){e.removeListener("destroyed",n),t.removeListener("destroyed",n)}e.once("destroyed",n),t.once("destroyed",n),this.once("complete",r),this.once("error",r)}}function Xn(e,t){var n=t.PouchConstructor;return"string"==typeof e?new n(e,t):e}function Zn(e,t,n,r){if("function"==typeof n&&(r=n,n={}),void 0===n&&(n={}),n.doc_ids&&!Array.isArray(n.doc_ids))throw Q(K,"`doc_ids` filter parameter is not a list.");n.complete=r,(n=g(n)).continuous=n.continuous||n.live,n.retry="retry"in n&&n.retry,n.PouchConstructor=n.PouchConstructor||this;var i=new Hn(n);return Yn(Xn(e,n),Xn(t,n),n,i),i}function er(e,t,n,r){return"function"==typeof n&&(r=n,n={}),void 0===n&&(n={}),(n=g(n)).PouchConstructor=n.PouchConstructor||this,e=Xn(e,n),t=Xn(t,n),new tr(e,t,n,r)}class tr extends f{constructor(e,t,n,r){super(),this.canceled=!1;const i=n.push?C({},n,n.push):n,o=n.pull?C({},n,n.pull):n;this.push=Zn(e,t,i),this.pull=Zn(t,e,o),this.pushPaused=!0,this.pullPaused=!0;const s=e=>{this.emit("change",{direction:"pull",change:e})},a=e=>{this.emit("change",{direction:"push",change:e})},c=e=>{this.emit("denied",{direction:"push",doc:e})},u=e=>{this.emit("denied",{direction:"pull",doc:e})},f=()=>{this.pushPaused=!0,this.pullPaused&&this.emit("paused")},l=()=>{this.pullPaused=!0,this.pushPaused&&this.emit("paused")},d=()=>{this.pushPaused=!1,this.pullPaused&&this.emit("active",{direction:"push"})},h=()=>{this.pullPaused=!1,this.pushPaused&&this.emit("active",{direction:"pull"})};let p={};const v=e=>(t,n)=>{("change"===t&&(n===s||n===a)||"denied"===t&&(n===u||n===c)||"paused"===t&&(n===l||n===f)||"active"===t&&(n===h||n===d))&&(t in p||(p[t]={}),p[t][e]=!0,2===Object.keys(p[t]).length&&this.removeAllListeners(t))};function y(e,t,n){-1==e.listeners(t).indexOf(n)&&e.on(t,n)}n.live&&(this.push.on("complete",this.pull.cancel.bind(this.pull)),this.pull.on("complete",this.push.cancel.bind(this.push))),this.on("newListener",(function(e){"change"===e?(y(this.pull,"change",s),y(this.push,"change",a)):"denied"===e?(y(this.pull,"denied",u),y(this.push,"denied",c)):"active"===e?(y(this.pull,"active",h),y(this.push,"active",d)):"paused"===e&&(y(this.pull,"paused",l),y(this.push,"paused",f))})),this.on("removeListener",(function(e){"change"===e?(this.pull.removeListener("change",s),this.push.removeListener("change",a)):"denied"===e?(this.pull.removeListener("denied",u),this.push.removeListener("denied",c)):"active"===e?(this.pull.removeListener("active",h),this.push.removeListener("active",d)):"paused"===e&&(this.pull.removeListener("paused",l),this.push.removeListener("paused",f))})),this.pull.on("removeListener",v("pull")),this.push.on("removeListener",v("push"));const _=Promise.all([this.push,this.pull]).then(e=>{const t={push:e[0],pull:e[1]};return this.emit("complete",t),r&&r(null,t),this.removeAllListeners(),t},e=>{if(this.cancel(),r?r(e):this.emit("error",e),this.removeAllListeners(),r)throw e});this.then=function(e,t){return _.then(e,t)},this.catch=function(e){return _.catch(e)}}cancel(){this.canceled||(this.canceled=!0,this.push.cancel(),this.pull.cancel())}}Ye.plugin((function(e){e.adapter("idb",sn,!0)})).plugin((function(e){e.adapter("http",vn,!1),e.adapter("https",vn,!1)})).plugin(Nn).plugin((function(e){e.replicate=Zn,e.sync=er,Object.defineProperty(e.prototype,"replicate",{get:function(){var e=this;return void 0===this.replicateMethods&&(this.replicateMethods={from:function(t,n,r){return e.constructor.replicate(t,e,n,r)},to:function(t,n,r){return e.constructor.replicate(e,t,n,r)}}),this.replicateMethods}}),e.prototype.sync=function(e,t,n){return this.constructor.sync(this,e,t,n)}})),t.exports=Ye}).call(this)}).call(this,e(9))},{10:10,11:11,2:2,26:26,3:3,9:9}]},{},[27])(27)}));