@graffiti-garden/implementation-local 0.6.4 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. package/README.md +0 -1
  2. package/dist/browser/ajv-IY2ZY7VT.js +9 -0
  3. package/dist/browser/ajv-IY2ZY7VT.js.map +7 -0
  4. package/dist/browser/{chunk-KNUPPOQC.js → chunk-GE6AZATH.js} +2 -2
  5. package/dist/browser/{chunk-KNUPPOQC.js.map → chunk-GE6AZATH.js.map} +1 -1
  6. package/dist/browser/{index-browser.es-G37SKL53.js → index-browser.es-UXYPGJ2M.js} +2 -2
  7. package/dist/browser/{index-browser.es-G37SKL53.js.map → index-browser.es-UXYPGJ2M.js.map} +1 -1
  8. package/dist/browser/index.js +11 -2
  9. package/dist/browser/index.js.map +4 -4
  10. package/dist/cjs/identity.js +112 -0
  11. package/dist/cjs/identity.js.map +7 -0
  12. package/dist/cjs/index.js +43 -22
  13. package/dist/cjs/index.js.map +2 -2
  14. package/dist/cjs/media.js +111 -0
  15. package/dist/cjs/media.js.map +7 -0
  16. package/dist/cjs/objects.js +307 -0
  17. package/dist/cjs/objects.js.map +7 -0
  18. package/dist/cjs/tests.spec.js +1 -2
  19. package/dist/cjs/tests.spec.js.map +2 -2
  20. package/dist/cjs/utilities.js +68 -43
  21. package/dist/cjs/utilities.js.map +2 -2
  22. package/dist/esm/identity.js +92 -0
  23. package/dist/esm/identity.js.map +7 -0
  24. package/dist/esm/index.js +43 -24
  25. package/dist/esm/index.js.map +2 -2
  26. package/dist/esm/media.js +91 -0
  27. package/dist/esm/media.js.map +7 -0
  28. package/dist/esm/objects.js +285 -0
  29. package/dist/esm/objects.js.map +7 -0
  30. package/dist/esm/tests.spec.js +2 -4
  31. package/dist/esm/tests.spec.js.map +2 -2
  32. package/dist/esm/utilities.js +69 -48
  33. package/dist/esm/utilities.js.map +2 -2
  34. package/dist/{session-manager.d.ts → identity.d.ts} +7 -5
  35. package/dist/identity.d.ts.map +1 -0
  36. package/dist/index.d.ts +15 -13
  37. package/dist/index.d.ts.map +1 -1
  38. package/dist/media.d.ts +9 -0
  39. package/dist/media.d.ts.map +1 -0
  40. package/dist/objects.d.ts +63 -0
  41. package/dist/objects.d.ts.map +1 -0
  42. package/dist/utilities.d.ts +19 -8
  43. package/dist/utilities.d.ts.map +1 -1
  44. package/package.json +31 -19
  45. package/src/identity.ts +131 -0
  46. package/src/index.ts +44 -29
  47. package/src/media.ts +106 -0
  48. package/src/objects.ts +432 -0
  49. package/src/tests.spec.ts +2 -4
  50. package/src/utilities.ts +67 -87
  51. package/dist/browser/ajv-6AI3HK2A.js +0 -9
  52. package/dist/browser/ajv-6AI3HK2A.js.map +0 -7
  53. package/dist/browser/fast-json-patch-ZE7SZEYK.js +0 -19
  54. package/dist/browser/fast-json-patch-ZE7SZEYK.js.map +0 -7
  55. package/dist/cjs/database.js +0 -626
  56. package/dist/cjs/database.js.map +0 -7
  57. package/dist/cjs/session-manager.js +0 -107
  58. package/dist/cjs/session-manager.js.map +0 -7
  59. package/dist/database.d.ts +0 -106
  60. package/dist/database.d.ts.map +0 -1
  61. package/dist/esm/database.js +0 -608
  62. package/dist/esm/database.js.map +0 -7
  63. package/dist/esm/session-manager.js +0 -87
  64. package/dist/esm/session-manager.js.map +0 -7
  65. package/dist/session-manager.d.ts.map +0 -1
  66. package/src/database.ts +0 -921
  67. package/src/session-manager.ts +0 -123
@@ -1,8 +1,8 @@
1
- import{a as Sn,c as An,d as ie,e as _e,f as se,g as ae}from"./chunk-KNUPPOQC.js";var qn=Sn((On,xn)=>{ie();ae();se();(function(e){if(typeof On=="object")xn.exports=e();else if(typeof define=="function"&&define.amd)define(e);else{var t;try{t=window}catch{t=self}t.SparkMD5=e()}})(function(e){"use strict";var t=function(h,d){return h+d&4294967295},n=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];function r(h,d,o,a,f,c){return d=t(t(d,h),t(a,c)),t(d<<f|d>>>32-f,o)}function i(h,d){var o=h[0],a=h[1],f=h[2],c=h[3];o+=(a&f|~a&c)+d[0]-680876936|0,o=(o<<7|o>>>25)+a|0,c+=(o&a|~o&f)+d[1]-389564586|0,c=(c<<12|c>>>20)+o|0,f+=(c&o|~c&a)+d[2]+606105819|0,f=(f<<17|f>>>15)+c|0,a+=(f&c|~f&o)+d[3]-1044525330|0,a=(a<<22|a>>>10)+f|0,o+=(a&f|~a&c)+d[4]-176418897|0,o=(o<<7|o>>>25)+a|0,c+=(o&a|~o&f)+d[5]+1200080426|0,c=(c<<12|c>>>20)+o|0,f+=(c&o|~c&a)+d[6]-1473231341|0,f=(f<<17|f>>>15)+c|0,a+=(f&c|~f&o)+d[7]-45705983|0,a=(a<<22|a>>>10)+f|0,o+=(a&f|~a&c)+d[8]+1770035416|0,o=(o<<7|o>>>25)+a|0,c+=(o&a|~o&f)+d[9]-1958414417|0,c=(c<<12|c>>>20)+o|0,f+=(c&o|~c&a)+d[10]-42063|0,f=(f<<17|f>>>15)+c|0,a+=(f&c|~f&o)+d[11]-1990404162|0,a=(a<<22|a>>>10)+f|0,o+=(a&f|~a&c)+d[12]+1804603682|0,o=(o<<7|o>>>25)+a|0,c+=(o&a|~o&f)+d[13]-40341101|0,c=(c<<12|c>>>20)+o|0,f+=(c&o|~c&a)+d[14]-1502002290|0,f=(f<<17|f>>>15)+c|0,a+=(f&c|~f&o)+d[15]+1236535329|0,a=(a<<22|a>>>10)+f|0,o+=(a&c|f&~c)+d[1]-165796510|0,o=(o<<5|o>>>27)+a|0,c+=(o&f|a&~f)+d[6]-1069501632|0,c=(c<<9|c>>>23)+o|0,f+=(c&a|o&~a)+d[11]+643717713|0,f=(f<<14|f>>>18)+c|0,a+=(f&o|c&~o)+d[0]-373897302|0,a=(a<<20|a>>>12)+f|0,o+=(a&c|f&~c)+d[5]-701558691|0,o=(o<<5|o>>>27)+a|0,c+=(o&f|a&~f)+d[10]+38016083|0,c=(c<<9|c>>>23)+o|0,f+=(c&a|o&~a)+d[15]-660478335|0,f=(f<<14|f>>>18)+c|0,a+=(f&o|c&~o)+d[4]-405537848|0,a=(a<<20|a>>>12)+f|0,o+=(a&c|f&~c)+d[9]+568446438|0,o=(o<<5|o>>>27)+a|0,c+=(o&f|a&~f)+d[14]-1019803690|0,c=(c<<9|c>>>23)+o|0,f+=(c&a|o&~a)+d[3]-187363961|0,f=(f<<14|f>>>18)+c|0,a+=(f&o|c&~o)+d[8]+1163531501|0,a=(a<<20|a>>>12)+f|0,o+=(a&c|f&~c)+d[13]-1444681467|0,o=(o<<5|o>>>27)+a|0,c+=(o&f|a&~f)+d[2]-51403784|0,c=(c<<9|c>>>23)+o|0,f+=(c&a|o&~a)+d[7]+1735328473|0,f=(f<<14|f>>>18)+c|0,a+=(f&o|c&~o)+d[12]-1926607734|0,a=(a<<20|a>>>12)+f|0,o+=(a^f^c)+d[5]-378558|0,o=(o<<4|o>>>28)+a|0,c+=(o^a^f)+d[8]-2022574463|0,c=(c<<11|c>>>21)+o|0,f+=(c^o^a)+d[11]+1839030562|0,f=(f<<16|f>>>16)+c|0,a+=(f^c^o)+d[14]-35309556|0,a=(a<<23|a>>>9)+f|0,o+=(a^f^c)+d[1]-1530992060|0,o=(o<<4|o>>>28)+a|0,c+=(o^a^f)+d[4]+1272893353|0,c=(c<<11|c>>>21)+o|0,f+=(c^o^a)+d[7]-155497632|0,f=(f<<16|f>>>16)+c|0,a+=(f^c^o)+d[10]-1094730640|0,a=(a<<23|a>>>9)+f|0,o+=(a^f^c)+d[13]+681279174|0,o=(o<<4|o>>>28)+a|0,c+=(o^a^f)+d[0]-358537222|0,c=(c<<11|c>>>21)+o|0,f+=(c^o^a)+d[3]-722521979|0,f=(f<<16|f>>>16)+c|0,a+=(f^c^o)+d[6]+76029189|0,a=(a<<23|a>>>9)+f|0,o+=(a^f^c)+d[9]-640364487|0,o=(o<<4|o>>>28)+a|0,c+=(o^a^f)+d[12]-421815835|0,c=(c<<11|c>>>21)+o|0,f+=(c^o^a)+d[15]+530742520|0,f=(f<<16|f>>>16)+c|0,a+=(f^c^o)+d[2]-995338651|0,a=(a<<23|a>>>9)+f|0,o+=(f^(a|~c))+d[0]-198630844|0,o=(o<<6|o>>>26)+a|0,c+=(a^(o|~f))+d[7]+1126891415|0,c=(c<<10|c>>>22)+o|0,f+=(o^(c|~a))+d[14]-1416354905|0,f=(f<<15|f>>>17)+c|0,a+=(c^(f|~o))+d[5]-57434055|0,a=(a<<21|a>>>11)+f|0,o+=(f^(a|~c))+d[12]+1700485571|0,o=(o<<6|o>>>26)+a|0,c+=(a^(o|~f))+d[3]-1894986606|0,c=(c<<10|c>>>22)+o|0,f+=(o^(c|~a))+d[10]-1051523|0,f=(f<<15|f>>>17)+c|0,a+=(c^(f|~o))+d[1]-2054922799|0,a=(a<<21|a>>>11)+f|0,o+=(f^(a|~c))+d[8]+1873313359|0,o=(o<<6|o>>>26)+a|0,c+=(a^(o|~f))+d[15]-30611744|0,c=(c<<10|c>>>22)+o|0,f+=(o^(c|~a))+d[6]-1560198380|0,f=(f<<15|f>>>17)+c|0,a+=(c^(f|~o))+d[13]+1309151649|0,a=(a<<21|a>>>11)+f|0,o+=(f^(a|~c))+d[4]-145523070|0,o=(o<<6|o>>>26)+a|0,c+=(a^(o|~f))+d[11]-1120210379|0,c=(c<<10|c>>>22)+o|0,f+=(o^(c|~a))+d[2]+718787259|0,f=(f<<15|f>>>17)+c|0,a+=(c^(f|~o))+d[9]-343485551|0,a=(a<<21|a>>>11)+f|0,h[0]=o+h[0]|0,h[1]=a+h[1]|0,h[2]=f+h[2]|0,h[3]=c+h[3]|0}function s(h){var d=[],o;for(o=0;o<64;o+=4)d[o>>2]=h.charCodeAt(o)+(h.charCodeAt(o+1)<<8)+(h.charCodeAt(o+2)<<16)+(h.charCodeAt(o+3)<<24);return d}function u(h){var d=[],o;for(o=0;o<64;o+=4)d[o>>2]=h[o]+(h[o+1]<<8)+(h[o+2]<<16)+(h[o+3]<<24);return d}function v(h){var d=h.length,o=[1732584193,-271733879,-1732584194,271733878],a,f,c,O,x,E;for(a=64;a<=d;a+=64)i(o,s(h.substring(a-64,a)));for(h=h.substring(a-64),f=h.length,c=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],a=0;a<f;a+=1)c[a>>2]|=h.charCodeAt(a)<<(a%4<<3);if(c[a>>2]|=128<<(a%4<<3),a>55)for(i(o,c),a=0;a<16;a+=1)c[a]=0;return O=d*8,O=O.toString(16).match(/(.*?)(.{0,8})$/),x=parseInt(O[2],16),E=parseInt(O[1],16)||0,c[14]=x,c[15]=E,i(o,c),o}function _(h){var d=h.length,o=[1732584193,-271733879,-1732584194,271733878],a,f,c,O,x,E;for(a=64;a<=d;a+=64)i(o,u(h.subarray(a-64,a)));for(h=a-64<d?h.subarray(a-64):new Uint8Array(0),f=h.length,c=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],a=0;a<f;a+=1)c[a>>2]|=h[a]<<(a%4<<3);if(c[a>>2]|=128<<(a%4<<3),a>55)for(i(o,c),a=0;a<16;a+=1)c[a]=0;return O=d*8,O=O.toString(16).match(/(.*?)(.{0,8})$/),x=parseInt(O[2],16),E=parseInt(O[1],16)||0,c[14]=x,c[15]=E,i(o,c),o}function g(h){var d="",o;for(o=0;o<4;o+=1)d+=n[h>>o*8+4&15]+n[h>>o*8&15];return d}function m(h){var d;for(d=0;d<h.length;d+=1)h[d]=g(h[d]);return h.join("")}m(v("hello"))!=="5d41402abc4b2a76b9719d911017c592"&&(t=function(h,d){var o=(h&65535)+(d&65535),a=(h>>16)+(d>>16)+(o>>16);return a<<16|o&65535}),typeof ArrayBuffer<"u"&&!ArrayBuffer.prototype.slice&&function(){function h(d,o){return d=d|0||0,d<0?Math.max(d+o,0):Math.min(d,o)}ArrayBuffer.prototype.slice=function(d,o){var a=this.byteLength,f=h(d,a),c=a,O,x,E,R;return o!==e&&(c=h(o,a)),f>c?new ArrayBuffer(0):(O=c-f,x=new ArrayBuffer(O),E=new Uint8Array(x),R=new Uint8Array(this,f,O),E.set(R),x)}}();function l(h){return/[\u0080-\uFFFF]/.test(h)&&(h=unescape(encodeURIComponent(h))),h}function y(h,d){var o=h.length,a=new ArrayBuffer(o),f=new Uint8Array(a),c;for(c=0;c<o;c+=1)f[c]=h.charCodeAt(c);return d?f:a}function w(h){return String.fromCharCode.apply(null,new Uint8Array(h))}function S(h,d,o){var a=new Uint8Array(h.byteLength+d.byteLength);return a.set(new Uint8Array(h)),a.set(new Uint8Array(d),h.byteLength),o?a:a.buffer}function q(h){var d=[],o=h.length,a;for(a=0;a<o-1;a+=2)d.push(parseInt(h.substr(a,2),16));return String.fromCharCode.apply(String,d)}function p(){this.reset()}return p.prototype.append=function(h){return this.appendBinary(l(h)),this},p.prototype.appendBinary=function(h){this._buff+=h,this._length+=h.length;var d=this._buff.length,o;for(o=64;o<=d;o+=64)i(this._hash,s(this._buff.substring(o-64,o)));return this._buff=this._buff.substring(o-64),this},p.prototype.end=function(h){var d=this._buff,o=d.length,a,f=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],c;for(a=0;a<o;a+=1)f[a>>2]|=d.charCodeAt(a)<<(a%4<<3);return this._finish(f,o),c=m(this._hash),h&&(c=q(c)),this.reset(),c},p.prototype.reset=function(){return this._buff="",this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},p.prototype.getState=function(){return{buff:this._buff,length:this._length,hash:this._hash.slice()}},p.prototype.setState=function(h){return this._buff=h.buff,this._length=h.length,this._hash=h.hash,this},p.prototype.destroy=function(){delete this._hash,delete this._buff,delete this._length},p.prototype._finish=function(h,d){var o=d,a,f,c;if(h[o>>2]|=128<<(o%4<<3),o>55)for(i(this._hash,h),o=0;o<16;o+=1)h[o]=0;a=this._length*8,a=a.toString(16).match(/(.*?)(.{0,8})$/),f=parseInt(a[2],16),c=parseInt(a[1],16)||0,h[14]=f,h[15]=c,i(this._hash,h)},p.hash=function(h,d){return p.hashBinary(l(h),d)},p.hashBinary=function(h,d){var o=v(h),a=m(o);return d?q(a):a},p.ArrayBuffer=function(){this.reset()},p.ArrayBuffer.prototype.append=function(h){var d=S(this._buff.buffer,h,!0),o=d.length,a;for(this._length+=h.byteLength,a=64;a<=o;a+=64)i(this._hash,u(d.subarray(a-64,a)));return this._buff=a-64<o?new Uint8Array(d.buffer.slice(a-64)):new Uint8Array(0),this},p.ArrayBuffer.prototype.end=function(h){var d=this._buff,o=d.length,a=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],f,c;for(f=0;f<o;f+=1)a[f>>2]|=d[f]<<(f%4<<3);return this._finish(a,o),c=m(this._hash),h&&(c=q(c)),this.reset(),c},p.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array(0),this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},p.ArrayBuffer.prototype.getState=function(){var h=p.prototype.getState.call(this);return h.buff=w(h.buff),h},p.ArrayBuffer.prototype.setState=function(h){return h.buff=y(h.buff,!0),p.prototype.setState.call(this,h)},p.ArrayBuffer.prototype.destroy=p.prototype.destroy,p.ArrayBuffer.prototype._finish=p.prototype._finish,p.ArrayBuffer.hash=function(h,d){var o=_(new Uint8Array(h)),a=m(o);return d?q(a):a},p})});var kn=Sn(Ot=>{"use strict";ie();ae();se();Ot.stringify=function(t){var n=[];n.push({obj:t});for(var r="",i,s,u,v,_,g,m,l,y,w,S;i=n.pop();)if(s=i.obj,u=i.prefix||"",v=i.val||"",r+=u,v)r+=v;else if(typeof s!="object")r+=typeof s>"u"?null:JSON.stringify(s);else if(s===null)r+="null";else if(Array.isArray(s)){for(n.push({val:"]"}),_=s.length-1;_>=0;_--)g=_===0?"":",",n.push({obj:s[_],prefix:g});n.push({val:"["})}else{m=[];for(l in s)s.hasOwnProperty(l)&&m.push(l);for(n.push({val:"}"}),_=m.length-1;_>=0;_--)y=m[_],w=s[y],S=_>0?",":"",S+=JSON.stringify(y)+":",n.push({obj:w,prefix:S});n.push({val:"{"})}return r};function Ue(e,t,n){var r=n[n.length-1];e===r.element&&(n.pop(),r=n[n.length-1]);var i=r.element,s=r.index;if(Array.isArray(i))i.push(e);else if(s===t.length-2){var u=t.pop();i[u]=e}else t.push(e)}Ot.parse=function(e){for(var t=[],n=[],r=0,i,s,u,v,_,g,m,l,y;;){if(i=e[r++],i==="}"||i==="]"||typeof i>"u"){if(t.length===1)return t.pop();Ue(t.pop(),t,n);continue}switch(i){case" ":case" ":case`
1
+ import{a as Sn,b as An,c as ie,d as _e,e as se,g as ae}from"./chunk-GE6AZATH.js";var qn=Sn((On,xn)=>{ie();ae();se();(function(e){if(typeof On=="object")xn.exports=e();else if(typeof define=="function"&&define.amd)define(e);else{var t;try{t=window}catch{t=self}t.SparkMD5=e()}})(function(e){"use strict";var t=function(h,d){return h+d&4294967295},n=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];function r(h,d,o,a,f,c){return d=t(t(d,h),t(a,c)),t(d<<f|d>>>32-f,o)}function i(h,d){var o=h[0],a=h[1],f=h[2],c=h[3];o+=(a&f|~a&c)+d[0]-680876936|0,o=(o<<7|o>>>25)+a|0,c+=(o&a|~o&f)+d[1]-389564586|0,c=(c<<12|c>>>20)+o|0,f+=(c&o|~c&a)+d[2]+606105819|0,f=(f<<17|f>>>15)+c|0,a+=(f&c|~f&o)+d[3]-1044525330|0,a=(a<<22|a>>>10)+f|0,o+=(a&f|~a&c)+d[4]-176418897|0,o=(o<<7|o>>>25)+a|0,c+=(o&a|~o&f)+d[5]+1200080426|0,c=(c<<12|c>>>20)+o|0,f+=(c&o|~c&a)+d[6]-1473231341|0,f=(f<<17|f>>>15)+c|0,a+=(f&c|~f&o)+d[7]-45705983|0,a=(a<<22|a>>>10)+f|0,o+=(a&f|~a&c)+d[8]+1770035416|0,o=(o<<7|o>>>25)+a|0,c+=(o&a|~o&f)+d[9]-1958414417|0,c=(c<<12|c>>>20)+o|0,f+=(c&o|~c&a)+d[10]-42063|0,f=(f<<17|f>>>15)+c|0,a+=(f&c|~f&o)+d[11]-1990404162|0,a=(a<<22|a>>>10)+f|0,o+=(a&f|~a&c)+d[12]+1804603682|0,o=(o<<7|o>>>25)+a|0,c+=(o&a|~o&f)+d[13]-40341101|0,c=(c<<12|c>>>20)+o|0,f+=(c&o|~c&a)+d[14]-1502002290|0,f=(f<<17|f>>>15)+c|0,a+=(f&c|~f&o)+d[15]+1236535329|0,a=(a<<22|a>>>10)+f|0,o+=(a&c|f&~c)+d[1]-165796510|0,o=(o<<5|o>>>27)+a|0,c+=(o&f|a&~f)+d[6]-1069501632|0,c=(c<<9|c>>>23)+o|0,f+=(c&a|o&~a)+d[11]+643717713|0,f=(f<<14|f>>>18)+c|0,a+=(f&o|c&~o)+d[0]-373897302|0,a=(a<<20|a>>>12)+f|0,o+=(a&c|f&~c)+d[5]-701558691|0,o=(o<<5|o>>>27)+a|0,c+=(o&f|a&~f)+d[10]+38016083|0,c=(c<<9|c>>>23)+o|0,f+=(c&a|o&~a)+d[15]-660478335|0,f=(f<<14|f>>>18)+c|0,a+=(f&o|c&~o)+d[4]-405537848|0,a=(a<<20|a>>>12)+f|0,o+=(a&c|f&~c)+d[9]+568446438|0,o=(o<<5|o>>>27)+a|0,c+=(o&f|a&~f)+d[14]-1019803690|0,c=(c<<9|c>>>23)+o|0,f+=(c&a|o&~a)+d[3]-187363961|0,f=(f<<14|f>>>18)+c|0,a+=(f&o|c&~o)+d[8]+1163531501|0,a=(a<<20|a>>>12)+f|0,o+=(a&c|f&~c)+d[13]-1444681467|0,o=(o<<5|o>>>27)+a|0,c+=(o&f|a&~f)+d[2]-51403784|0,c=(c<<9|c>>>23)+o|0,f+=(c&a|o&~a)+d[7]+1735328473|0,f=(f<<14|f>>>18)+c|0,a+=(f&o|c&~o)+d[12]-1926607734|0,a=(a<<20|a>>>12)+f|0,o+=(a^f^c)+d[5]-378558|0,o=(o<<4|o>>>28)+a|0,c+=(o^a^f)+d[8]-2022574463|0,c=(c<<11|c>>>21)+o|0,f+=(c^o^a)+d[11]+1839030562|0,f=(f<<16|f>>>16)+c|0,a+=(f^c^o)+d[14]-35309556|0,a=(a<<23|a>>>9)+f|0,o+=(a^f^c)+d[1]-1530992060|0,o=(o<<4|o>>>28)+a|0,c+=(o^a^f)+d[4]+1272893353|0,c=(c<<11|c>>>21)+o|0,f+=(c^o^a)+d[7]-155497632|0,f=(f<<16|f>>>16)+c|0,a+=(f^c^o)+d[10]-1094730640|0,a=(a<<23|a>>>9)+f|0,o+=(a^f^c)+d[13]+681279174|0,o=(o<<4|o>>>28)+a|0,c+=(o^a^f)+d[0]-358537222|0,c=(c<<11|c>>>21)+o|0,f+=(c^o^a)+d[3]-722521979|0,f=(f<<16|f>>>16)+c|0,a+=(f^c^o)+d[6]+76029189|0,a=(a<<23|a>>>9)+f|0,o+=(a^f^c)+d[9]-640364487|0,o=(o<<4|o>>>28)+a|0,c+=(o^a^f)+d[12]-421815835|0,c=(c<<11|c>>>21)+o|0,f+=(c^o^a)+d[15]+530742520|0,f=(f<<16|f>>>16)+c|0,a+=(f^c^o)+d[2]-995338651|0,a=(a<<23|a>>>9)+f|0,o+=(f^(a|~c))+d[0]-198630844|0,o=(o<<6|o>>>26)+a|0,c+=(a^(o|~f))+d[7]+1126891415|0,c=(c<<10|c>>>22)+o|0,f+=(o^(c|~a))+d[14]-1416354905|0,f=(f<<15|f>>>17)+c|0,a+=(c^(f|~o))+d[5]-57434055|0,a=(a<<21|a>>>11)+f|0,o+=(f^(a|~c))+d[12]+1700485571|0,o=(o<<6|o>>>26)+a|0,c+=(a^(o|~f))+d[3]-1894986606|0,c=(c<<10|c>>>22)+o|0,f+=(o^(c|~a))+d[10]-1051523|0,f=(f<<15|f>>>17)+c|0,a+=(c^(f|~o))+d[1]-2054922799|0,a=(a<<21|a>>>11)+f|0,o+=(f^(a|~c))+d[8]+1873313359|0,o=(o<<6|o>>>26)+a|0,c+=(a^(o|~f))+d[15]-30611744|0,c=(c<<10|c>>>22)+o|0,f+=(o^(c|~a))+d[6]-1560198380|0,f=(f<<15|f>>>17)+c|0,a+=(c^(f|~o))+d[13]+1309151649|0,a=(a<<21|a>>>11)+f|0,o+=(f^(a|~c))+d[4]-145523070|0,o=(o<<6|o>>>26)+a|0,c+=(a^(o|~f))+d[11]-1120210379|0,c=(c<<10|c>>>22)+o|0,f+=(o^(c|~a))+d[2]+718787259|0,f=(f<<15|f>>>17)+c|0,a+=(c^(f|~o))+d[9]-343485551|0,a=(a<<21|a>>>11)+f|0,h[0]=o+h[0]|0,h[1]=a+h[1]|0,h[2]=f+h[2]|0,h[3]=c+h[3]|0}function s(h){var d=[],o;for(o=0;o<64;o+=4)d[o>>2]=h.charCodeAt(o)+(h.charCodeAt(o+1)<<8)+(h.charCodeAt(o+2)<<16)+(h.charCodeAt(o+3)<<24);return d}function u(h){var d=[],o;for(o=0;o<64;o+=4)d[o>>2]=h[o]+(h[o+1]<<8)+(h[o+2]<<16)+(h[o+3]<<24);return d}function v(h){var d=h.length,o=[1732584193,-271733879,-1732584194,271733878],a,f,c,O,x,E;for(a=64;a<=d;a+=64)i(o,s(h.substring(a-64,a)));for(h=h.substring(a-64),f=h.length,c=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],a=0;a<f;a+=1)c[a>>2]|=h.charCodeAt(a)<<(a%4<<3);if(c[a>>2]|=128<<(a%4<<3),a>55)for(i(o,c),a=0;a<16;a+=1)c[a]=0;return O=d*8,O=O.toString(16).match(/(.*?)(.{0,8})$/),x=parseInt(O[2],16),E=parseInt(O[1],16)||0,c[14]=x,c[15]=E,i(o,c),o}function _(h){var d=h.length,o=[1732584193,-271733879,-1732584194,271733878],a,f,c,O,x,E;for(a=64;a<=d;a+=64)i(o,u(h.subarray(a-64,a)));for(h=a-64<d?h.subarray(a-64):new Uint8Array(0),f=h.length,c=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],a=0;a<f;a+=1)c[a>>2]|=h[a]<<(a%4<<3);if(c[a>>2]|=128<<(a%4<<3),a>55)for(i(o,c),a=0;a<16;a+=1)c[a]=0;return O=d*8,O=O.toString(16).match(/(.*?)(.{0,8})$/),x=parseInt(O[2],16),E=parseInt(O[1],16)||0,c[14]=x,c[15]=E,i(o,c),o}function g(h){var d="",o;for(o=0;o<4;o+=1)d+=n[h>>o*8+4&15]+n[h>>o*8&15];return d}function m(h){var d;for(d=0;d<h.length;d+=1)h[d]=g(h[d]);return h.join("")}m(v("hello"))!=="5d41402abc4b2a76b9719d911017c592"&&(t=function(h,d){var o=(h&65535)+(d&65535),a=(h>>16)+(d>>16)+(o>>16);return a<<16|o&65535}),typeof ArrayBuffer<"u"&&!ArrayBuffer.prototype.slice&&(function(){function h(d,o){return d=d|0||0,d<0?Math.max(d+o,0):Math.min(d,o)}ArrayBuffer.prototype.slice=function(d,o){var a=this.byteLength,f=h(d,a),c=a,O,x,E,R;return o!==e&&(c=h(o,a)),f>c?new ArrayBuffer(0):(O=c-f,x=new ArrayBuffer(O),E=new Uint8Array(x),R=new Uint8Array(this,f,O),E.set(R),x)}})();function l(h){return/[\u0080-\uFFFF]/.test(h)&&(h=unescape(encodeURIComponent(h))),h}function y(h,d){var o=h.length,a=new ArrayBuffer(o),f=new Uint8Array(a),c;for(c=0;c<o;c+=1)f[c]=h.charCodeAt(c);return d?f:a}function w(h){return String.fromCharCode.apply(null,new Uint8Array(h))}function S(h,d,o){var a=new Uint8Array(h.byteLength+d.byteLength);return a.set(new Uint8Array(h)),a.set(new Uint8Array(d),h.byteLength),o?a:a.buffer}function q(h){var d=[],o=h.length,a;for(a=0;a<o-1;a+=2)d.push(parseInt(h.substr(a,2),16));return String.fromCharCode.apply(String,d)}function p(){this.reset()}return p.prototype.append=function(h){return this.appendBinary(l(h)),this},p.prototype.appendBinary=function(h){this._buff+=h,this._length+=h.length;var d=this._buff.length,o;for(o=64;o<=d;o+=64)i(this._hash,s(this._buff.substring(o-64,o)));return this._buff=this._buff.substring(o-64),this},p.prototype.end=function(h){var d=this._buff,o=d.length,a,f=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],c;for(a=0;a<o;a+=1)f[a>>2]|=d.charCodeAt(a)<<(a%4<<3);return this._finish(f,o),c=m(this._hash),h&&(c=q(c)),this.reset(),c},p.prototype.reset=function(){return this._buff="",this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},p.prototype.getState=function(){return{buff:this._buff,length:this._length,hash:this._hash.slice()}},p.prototype.setState=function(h){return this._buff=h.buff,this._length=h.length,this._hash=h.hash,this},p.prototype.destroy=function(){delete this._hash,delete this._buff,delete this._length},p.prototype._finish=function(h,d){var o=d,a,f,c;if(h[o>>2]|=128<<(o%4<<3),o>55)for(i(this._hash,h),o=0;o<16;o+=1)h[o]=0;a=this._length*8,a=a.toString(16).match(/(.*?)(.{0,8})$/),f=parseInt(a[2],16),c=parseInt(a[1],16)||0,h[14]=f,h[15]=c,i(this._hash,h)},p.hash=function(h,d){return p.hashBinary(l(h),d)},p.hashBinary=function(h,d){var o=v(h),a=m(o);return d?q(a):a},p.ArrayBuffer=function(){this.reset()},p.ArrayBuffer.prototype.append=function(h){var d=S(this._buff.buffer,h,!0),o=d.length,a;for(this._length+=h.byteLength,a=64;a<=o;a+=64)i(this._hash,u(d.subarray(a-64,a)));return this._buff=a-64<o?new Uint8Array(d.buffer.slice(a-64)):new Uint8Array(0),this},p.ArrayBuffer.prototype.end=function(h){var d=this._buff,o=d.length,a=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],f,c;for(f=0;f<o;f+=1)a[f>>2]|=d[f]<<(f%4<<3);return this._finish(a,o),c=m(this._hash),h&&(c=q(c)),this.reset(),c},p.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array(0),this._length=0,this._hash=[1732584193,-271733879,-1732584194,271733878],this},p.ArrayBuffer.prototype.getState=function(){var h=p.prototype.getState.call(this);return h.buff=w(h.buff),h},p.ArrayBuffer.prototype.setState=function(h){return h.buff=y(h.buff,!0),p.prototype.setState.call(this,h)},p.ArrayBuffer.prototype.destroy=p.prototype.destroy,p.ArrayBuffer.prototype._finish=p.prototype._finish,p.ArrayBuffer.hash=function(h,d){var o=_(new Uint8Array(h)),a=m(o);return d?q(a):a},p})});var kn=Sn(Ot=>{"use strict";ie();ae();se();Ot.stringify=function(t){var n=[];n.push({obj:t});for(var r="",i,s,u,v,_,g,m,l,y,w,S;i=n.pop();)if(s=i.obj,u=i.prefix||"",v=i.val||"",r+=u,v)r+=v;else if(typeof s!="object")r+=typeof s>"u"?null:JSON.stringify(s);else if(s===null)r+="null";else if(Array.isArray(s)){for(n.push({val:"]"}),_=s.length-1;_>=0;_--)g=_===0?"":",",n.push({obj:s[_],prefix:g});n.push({val:"["})}else{m=[];for(l in s)s.hasOwnProperty(l)&&m.push(l);for(n.push({val:"}"}),_=m.length-1;_>=0;_--)y=m[_],w=s[y],S=_>0?",":"",S+=JSON.stringify(y)+":",n.push({obj:w,prefix:S});n.push({val:"{"})}return r};function Ue(e,t,n){var r=n[n.length-1];e===r.element&&(n.pop(),r=n[n.length-1]);var i=r.element,s=r.index;if(Array.isArray(i))i.push(e);else if(s===t.length-2){var u=t.pop();i[u]=e}else t.push(e)}Ot.parse=function(e){for(var t=[],n=[],r=0,i,s,u,v,_,g,m,l,y;;){if(i=e[r++],i==="}"||i==="]"||typeof i>"u"){if(t.length===1)return t.pop();Ue(t.pop(),t,n);continue}switch(i){case" ":case" ":case`
2
2
  `:case":":case",":break;case"n":r+=3,Ue(null,t,n);break;case"t":r+=3,Ue(!0,t,n);break;case"f":r+=4,Ue(!1,t,n);break;case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":case"-":for(s="",r--;;)if(u=e[r++],/[\d\.\-e\+]/.test(u))s+=u;else{r--;break}Ue(parseFloat(s),t,n);break;case'"':for(v="",_=void 0,g=0;m=e[r++],m!=='"'||_==="\\"&&g%2===1;)v+=m,_=m,_==="\\"?g++:g=0;Ue(JSON.parse('"'+v+'"'),t,n);break;case"[":l={element:[],index:t.length},t.push(l.element),n.push(l);break;case"{":y={element:{},index:t.length},t.push(y.element),n.push(y);break;default:throw new Error("unexpectedly reached end of input: "+i)}}}});ie();ae();se();var ft=An(qn());ie();ae();se();ie();ae();se();var nt,Kr=new Uint8Array(16);function At(){if(!nt&&(nt=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto)||typeof msCrypto<"u"&&typeof msCrypto.getRandomValues=="function"&&msCrypto.getRandomValues.bind(msCrypto),!nt))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return nt(Kr)}ie();ae();se();ie();ae();se();ie();ae();se();var Cn=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function Ur(e){return typeof e=="string"&&Cn.test(e)}var En=Ur;var le=[];for(rt=0;rt<256;++rt)le.push((rt+256).toString(16).substr(1));var rt;function Mr(e){var t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:0,n=(le[e[t+0]]+le[e[t+1]]+le[e[t+2]]+le[e[t+3]]+"-"+le[e[t+4]]+le[e[t+5]]+"-"+le[e[t+6]]+le[e[t+7]]+"-"+le[e[t+8]]+le[e[t+9]]+"-"+le[e[t+10]]+le[e[t+11]]+le[e[t+12]]+le[e[t+13]]+le[e[t+14]]+le[e[t+15]]).toLowerCase();if(!En(n))throw TypeError("Stringified UUID is invalid");return n}var Dn=Mr;ie();ae();se();function Gr(e,t,n){e=e||{};var r=e.random||(e.rng||At)();if(r[6]=r[6]&15|64,r[8]=r[8]&63|128,t){n=n||0;for(var i=0;i<16;++i)t[n+i]=r[i];return t}return Dn(r)}var He=Gr;var on=An(kn());ie();ae();se();var it={},Tn=!1;function Jr(){if(Tn)return it;Tn=!0;var e=typeof Reflect=="object"?Reflect:null,t=e&&typeof e.apply=="function"?e.apply:function(f,c,O){return Function.prototype.apply.call(f,c,O)},n;e&&typeof e.ownKeys=="function"?n=e.ownKeys:Object.getOwnPropertySymbols?n=function(f){return Object.getOwnPropertyNames(f).concat(Object.getOwnPropertySymbols(f))}:n=function(f){return Object.getOwnPropertyNames(f)};function r(a){console&&console.warn&&console.warn(a)}var i=Number.isNaN||function(f){return f!==f};function s(){s.init.call(this)}it=s,it.once=h,s.EventEmitter=s,s.prototype._events=void 0,s.prototype._eventsCount=0,s.prototype._maxListeners=void 0;var u=10;function v(a){if(typeof a!="function")throw new TypeError('The "listener" argument must be of type Function. Received type '+typeof a)}Object.defineProperty(s,"defaultMaxListeners",{enumerable:!0,get:function(){return u},set:function(a){if(typeof a!="number"||a<0||i(a))throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received '+a+".");u=a}}),s.init=function(){(this._events===void 0||this._events===Object.getPrototypeOf(this)._events)&&(this._events=Object.create(null),this._eventsCount=0),this._maxListeners=this._maxListeners||void 0},s.prototype.setMaxListeners=function(f){if(typeof f!="number"||f<0||i(f))throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received '+f+".");return this._maxListeners=f,this};function _(a){return a._maxListeners===void 0?s.defaultMaxListeners:a._maxListeners}s.prototype.getMaxListeners=function(){return _(this)},s.prototype.emit=function(f){for(var c=[],O=1;O<arguments.length;O++)c.push(arguments[O]);var x=f==="error",E=this._events;if(E!==void 0)x=x&&E.error===void 0;else if(!x)return!1;if(x){var R;if(c.length>0&&(R=c[0]),R instanceof Error)throw R;var B=new Error("Unhandled error."+(R?" ("+R.message+")":""));throw B.context=R,B}var U=E[f];if(U===void 0)return!1;if(typeof U=="function")t(U,this,c);else for(var j=U.length,$=S(U,j),O=0;O<j;++O)t($[O],this,c);return!0};function g(a,f,c,O){var x,E,R;if(v(c),E=a._events,E===void 0?(E=a._events=Object.create(null),a._eventsCount=0):(E.newListener!==void 0&&(a.emit("newListener",f,c.listener?c.listener:c),E=a._events),R=E[f]),R===void 0)R=E[f]=c,++a._eventsCount;else if(typeof R=="function"?R=E[f]=O?[c,R]:[R,c]:O?R.unshift(c):R.push(c),x=_(a),x>0&&R.length>x&&!R.warned){R.warned=!0;var B=new Error("Possible EventEmitter memory leak detected. "+R.length+" "+String(f)+" listeners added. Use emitter.setMaxListeners() to increase limit");B.name="MaxListenersExceededWarning",B.emitter=a,B.type=f,B.count=R.length,r(B)}return a}s.prototype.addListener=function(f,c){return g(this,f,c,!1)},s.prototype.on=s.prototype.addListener,s.prototype.prependListener=function(f,c){return g(this,f,c,!0)};function m(){if(!this.fired)return this.target.removeListener(this.type,this.wrapFn),this.fired=!0,arguments.length===0?this.listener.call(this.target):this.listener.apply(this.target,arguments)}function l(a,f,c){var O={fired:!1,wrapFn:void 0,target:a,type:f,listener:c},x=m.bind(O);return x.listener=c,O.wrapFn=x,x}s.prototype.once=function(f,c){return v(c),this.on(f,l(this,f,c)),this},s.prototype.prependOnceListener=function(f,c){return v(c),this.prependListener(f,l(this,f,c)),this},s.prototype.removeListener=function(f,c){var O,x,E,R,B;if(v(c),x=this._events,x===void 0)return this;if(O=x[f],O===void 0)return this;if(O===c||O.listener===c)--this._eventsCount===0?this._events=Object.create(null):(delete x[f],x.removeListener&&this.emit("removeListener",f,O.listener||c));else if(typeof O!="function"){for(E=-1,R=O.length-1;R>=0;R--)if(O[R]===c||O[R].listener===c){B=O[R].listener,E=R;break}if(E<0)return this;E===0?O.shift():q(O,E),O.length===1&&(x[f]=O[0]),x.removeListener!==void 0&&this.emit("removeListener",f,B||c)}return this},s.prototype.off=s.prototype.removeListener,s.prototype.removeAllListeners=function(f){var c,O,x;if(O=this._events,O===void 0)return this;if(O.removeListener===void 0)return arguments.length===0?(this._events=Object.create(null),this._eventsCount=0):O[f]!==void 0&&(--this._eventsCount===0?this._events=Object.create(null):delete O[f]),this;if(arguments.length===0){var E=Object.keys(O),R;for(x=0;x<E.length;++x)R=E[x],R!=="removeListener"&&this.removeAllListeners(R);return this.removeAllListeners("removeListener"),this._events=Object.create(null),this._eventsCount=0,this}if(c=O[f],typeof c=="function")this.removeListener(f,c);else if(c!==void 0)for(x=c.length-1;x>=0;x--)this.removeListener(f,c[x]);return this};function y(a,f,c){var O=a._events;if(O===void 0)return[];var x=O[f];return x===void 0?[]:typeof x=="function"?c?[x.listener||x]:[x]:c?p(x):S(x,x.length)}s.prototype.listeners=function(f){return y(this,f,!0)},s.prototype.rawListeners=function(f){return y(this,f,!1)},s.listenerCount=function(a,f){return typeof a.listenerCount=="function"?a.listenerCount(f):w.call(a,f)},s.prototype.listenerCount=w;function w(a){var f=this._events;if(f!==void 0){var c=f[a];if(typeof c=="function")return 1;if(c!==void 0)return c.length}return 0}s.prototype.eventNames=function(){return this._eventsCount>0?n(this._events):[]};function S(a,f){for(var c=new Array(f),O=0;O<f;++O)c[O]=a[O];return c}function q(a,f){for(;f+1<a.length;f++)a[f]=a[f+1];a.pop()}function p(a){for(var f=new Array(a.length),c=0;c<f.length;++c)f[c]=a[c].listener||a[c];return f}function h(a,f){return new Promise(function(c,O){function x(R){a.removeListener(f,E),O(R)}function E(){typeof a.removeListener=="function"&&a.removeListener("error",x),c([].slice.call(arguments))}o(a,f,E,{once:!0}),f!=="error"&&d(a,x,{once:!0})})}function d(a,f,c){typeof a.on=="function"&&o(a,"error",f,c)}function o(a,f,c,O){if(typeof a.on=="function")O.once?a.once(f,c):a.on(f,c);else if(typeof a.addEventListener=="function")a.addEventListener(f,function x(E){O.once&&a.removeEventListener(f,x),c(E)});else throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type '+typeof a)}return it}var ge=Jr();ge.once;ge.once=function(e,t){return new Promise((n,r)=>{function i(...u){s!==void 0&&e.removeListener("error",s),n(u)}let s;t!=="error"&&(s=u=>{e.removeListener(name,i),r(u)},e.once("error",s)),e.once(t,i)})};ge.on=function(e,t){let n=[],r=[],i=null,s=!1,u={async next(){let g=n.shift();if(g)return createIterResult(g,!1);if(i){let m=Promise.reject(i);return i=null,m}return s?createIterResult(void 0,!0):new Promise((m,l)=>r.push({resolve:m,reject:l}))},async return(){e.removeListener(t,v),e.removeListener("error",_),s=!0;for(let g of r)g.resolve(createIterResult(void 0,!0));return createIterResult(void 0,!0)},throw(g){i=g,e.removeListener(t,v),e.removeListener("error",_)},[Symbol.asyncIterator](){return this}};return e.on(t,v),e.on("error",_),u;function v(...g){let m=r.shift();m?m.resolve(createIterResult(g,!1)):n.push(g)}function _(g){s=!0;let m=r.shift();m?m.reject(g):i=g,u.return()}};var{EventEmitter:go,defaultMaxListeners:yo,init:po,listenerCount:mo,on:wo,once:bo}=ge;function zr(e){return typeof ArrayBuffer<"u"&&e instanceof ArrayBuffer||typeof Blob<"u"&&e instanceof Blob}function Qr(e){return e instanceof ArrayBuffer?e.slice(0):e.slice(0,e.size,e.type)}var sr=Function.prototype.toString,Wr=sr.call(Object);function Hr(e){var t=Object.getPrototypeOf(e);if(t===null)return!0;var n=t.constructor;return typeof n=="function"&&n instanceof n&&sr.call(n)==Wr}function fe(e){var t,n,r;if(!e||typeof e!="object")return e;if(Array.isArray(e)){for(t=[],n=0,r=e.length;n<r;n++)t[n]=fe(e[n]);return t}if(e instanceof Date&&isFinite(e))return e.toISOString();if(zr(e))return Qr(e);if(!Hr(e))return e;t={};for(n in e)if(Object.prototype.hasOwnProperty.call(e,n)){var i=fe(e[n]);typeof i<"u"&&(t[n]=i)}return t}function ar(e){var t=!1;return function(...n){if(t)throw new Error("once called more than once");t=!0,e.apply(this,n)}}function or(e){return function(...t){t=fe(t);var n=this,r=typeof t[t.length-1]=="function"?t.pop():!1,i=new Promise(function(s,u){var v;try{var _=ar(function(g,m){g?u(g):s(m)});t.push(_),v=e.apply(n,t),v&&typeof v.then=="function"&&s(v)}catch(g){u(g)}});return r&&i.then(function(s){r(null,s)},r),i}}function Xr(e,t,n){if(e.constructor.listeners("debug").length){for(var r=["api",e.name,t],i=0;i<n.length-1;i++)r.push(n[i]);e.constructor.emit("debug",r);var s=n[n.length-1];n[n.length-1]=function(u,v){var _=["api",e.name,t];_=_.concat(u?["error",u]:["success",v]),e.constructor.emit("debug",_),s(u,v)}}}function te(e,t){return or(function(...n){if(this._closed)return Promise.reject(new Error("database is closed"));if(this._destroyed)return Promise.reject(new Error("database is destroyed"));var r=this;return Xr(r,e,n),this.taskqueue.isReady?t.apply(this,n):new Promise(function(i,s){r.taskqueue.addTask(function(u){u?s(u):i(r[e].apply(r,n))})})})}function et(e,t){for(var n={},r=0,i=t.length;r<i;r++){var s=t[r];s in e&&(n[s]=e[s])}return n}var Yr=6;function Rn(e){return e}function Zr(e){return[{ok:e}]}function ur(e,t,n){var r=t.docs,i=new Map;r.forEach(function(q){i.has(q.id)?i.get(q.id).push(q):i.set(q.id,[q])});var s=i.size,u=0,v=new Array(s);function _(){var q=[];v.forEach(function(p){p.docs.forEach(function(h){q.push({id:p.id,docs:[h]})})}),n(null,{results:q})}function g(){++u===s&&_()}function m(q,p,h){v[q]={id:p,docs:h},g()}var l=[];i.forEach(function(q,p){l.push(p)});var y=0;function w(){if(!(y>=l.length)){var q=Math.min(y+Yr,l.length),p=l.slice(y,q);S(p,y),y+=p.length}}function S(q,p){q.forEach(function(h,d){var o=p+d,a=i.get(h),f=et(a[0],["atts_since","attachments"]);f.open_revs=a.map(function(O){return O.rev}),f.open_revs=f.open_revs.filter(Rn);var c=Rn;f.open_revs.length===0&&(delete f.open_revs,c=Zr),["revs","attachments","binary","ajax","latest"].forEach(function(O){O in t&&(f[O]=t[O])}),e.get(h,f,function(O,x){var E;O?E=[{error:O}]:E=c(x),m(o,h,E),w()})})}w()}var Nt;try{localStorage.setItem("_pouch_check_localstorage",1),Nt=!!localStorage.getItem("_pouch_check_localstorage")}catch{Nt=!1}function ct(){return Nt}var De=typeof queueMicrotask=="function"?queueMicrotask:function(t){Promise.resolve().then(t)},$t=class extends ge{constructor(){super(),this._listeners={},ct()&&addEventListener("storage",t=>{this.emit(t.key)})}addListener(t,n,r,i){if(this._listeners[n])return;var s=!1,u=this;function v(){if(!u._listeners[n])return;if(s){s="waiting";return}s=!0;var _=et(i,["style","include_docs","attachments","conflicts","filter","doc_ids","view","since","query_params","binary","return_docs"]);function g(){s=!1}r.changes(_).on("change",function(m){m.seq>i.since&&!i.cancelled&&(i.since=m.seq,i.onChange(m))}).on("complete",function(){s==="waiting"&&De(v),s=!1}).on("error",g)}this._listeners[n]=v,this.on(t,v)}removeListener(t,n){n in this._listeners&&(super.removeListener(t,this._listeners[n]),delete this._listeners[n])}notifyLocalWindows(t){ct()&&(localStorage[t]=localStorage[t]==="a"?"b":"a")}notify(t){this.emit(t),this.notifyLocalWindows(t)}};function we(e){if(typeof console<"u"&&typeof console[e]=="function"){var t=Array.prototype.slice.call(arguments,1);console[e].apply(console,t)}}function Vr(e,t){var n=6e5;e=parseInt(e,10)||0,t=parseInt(t,10),t!==t||t<=e?t=(e||1)<<1:t=t+1,t>n&&(e=n>>1,t=n);var r=Math.random(),i=t-e;return~~(i*r+e)}function ei(e){var t=0;return e||(t=2e3),Vr(e,t)}function Ft(e,t){we("info","The above "+e+" is totally normal. "+t)}var V=class extends Error{constructor(t,n,r){super(),this.status=t,this.name=n,this.message=r,this.error=!0}toString(){return JSON.stringify({status:this.status,name:this.name,message:this.message,reason:this.reason})}},Eo=new V(401,"unauthorized","Name or password is incorrect."),ti=new V(400,"bad_request","Missing JSON list of 'docs'"),pe=new V(404,"not_found","missing"),ze=new V(409,"conflict","Document update conflict"),fr=new V(400,"bad_request","_id field must contain a string"),ni=new V(412,"missing_id","_id is required for puts"),ri=new V(400,"bad_request","Only reserved document ids may start with underscore."),Do=new V(412,"precondition_failed","Database not open"),un=new V(500,"unknown_error","Database encountered an unknown error"),cr=new V(500,"badarg","Some query argument is invalid"),ko=new V(400,"invalid_request","Request was invalid"),ii=new V(400,"query_parse_error","Some query parameter is invalid"),Ln=new V(500,"doc_validation","Bad special document member"),wt=new V(400,"bad_request","Something wrong with the request"),xt=new V(400,"bad_request","Document must be a JSON object"),To=new V(404,"not_found","Database not found"),fn=new V(500,"indexed_db_went_bad","unknown"),Ro=new V(500,"web_sql_went_bad","unknown"),Lo=new V(500,"levelDB_went_went_bad","unknown"),Po=new V(403,"forbidden","Forbidden by design doc validate_doc_update function"),ot=new V(400,"bad_request","Invalid rev format"),Bo=new V(412,"file_exists","The database could not be created, the file already exists."),si=new V(412,"missing_stub","A pre-existing attachment stub wasn't found"),Io=new V(413,"invalid_url","Provided URL is invalid");function G(e,t){function n(r){for(var i=Object.getOwnPropertyNames(e),s=0,u=i.length;s<u;s++)typeof e[i[s]]!="function"&&(this[i[s]]=e[i[s]]);this.stack===void 0&&(this.stack=new Error().stack),r!==void 0&&(this.reason=r)}return n.prototype=V.prototype,new n(t)}function Qe(e){if(typeof e!="object"){var t=e;e=un,e.data=t}return"error"in e&&e.error==="conflict"&&(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 ai(e,t,n){try{return!e(t,n)}catch(i){var r="Filter function threw: "+i.toString();return G(wt,r)}}function cn(e){var t={},n=e.filter&&typeof e.filter=="function";return t.query=e.query_params,function(i){i.doc||(i.doc={});var s=n&&ai(e.filter,i.doc,t);if(typeof s=="object")return s;if(s)return!1;if(!e.include_docs)delete i.doc;else if(!e.attachments)for(var u in i.doc._attachments)Object.prototype.hasOwnProperty.call(i.doc._attachments,u)&&(i.doc._attachments[u].stub=!0);return!0}}function lr(e){var t;if(e?typeof e!="string"?t=G(fr):/^_/.test(e)&&!/^_(design|local)/.test(e)&&(t=G(ri)):t=G(ni),t)throw t}function Ee(e){return typeof e._remote=="boolean"?e._remote:typeof e.type=="function"?(we("warn","db.type() is deprecated and will be removed in a future version of PouchDB"),e.type()==="http"):!1}function oi(e,t){return"listenerCount"in e?e.listenerCount(t):ge.listenerCount(e,t)}function Kt(e){if(!e)return null;var t=e.split("/");return t.length===2?t:t.length===1?[e,e]:null}function Pn(e){var t=Kt(e);return t?t.join("/"):null}var Bn=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],In="queryKey",ui=/(?:^|&)([^&=]*)=?([^&]*)/g,fi=/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;function dr(e){for(var t=fi.exec(e),n={},r=14;r--;){var i=Bn[r],s=t[r]||"",u=["user","password"].indexOf(i)!==-1;n[i]=u?decodeURIComponent(s):s}return n[In]={},n[Bn[12]].replace(ui,function(v,_,g){_&&(n[In][_]=g)}),n}function ln(e,t){var n=[],r=[];for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(n.push(i),r.push(t[i]));return n.push(e),Function.apply(null,n).apply(null,r)}function lt(e,t,n){return e.get(t).catch(function(r){if(r.status!==404)throw r;return{}}).then(function(r){var i=r._rev,s=n(r);return s?(s._id=t,s._rev=i,ci(e,s,n)):{updated:!1,rev:i}})}function ci(e,t,n){return e.put(t).then(function(r){return{updated:!0,rev:r.rev}},function(r){if(r.status!==409)throw r;return lt(e,t._id,n)})}var dn=function(e){return atob(e)},tt=function(e){return btoa(e)};function hn(e,t){e=e||[],t=t||{};try{return new Blob(e,t)}catch(s){if(s.name!=="TypeError")throw s;for(var n=typeof BlobBuilder<"u"?BlobBuilder:typeof MSBlobBuilder<"u"?MSBlobBuilder:typeof MozBlobBuilder<"u"?MozBlobBuilder:WebKitBlobBuilder,r=new n,i=0;i<e.length;i+=1)r.append(e[i]);return r.getBlob(t.type)}}function li(e){for(var t=e.length,n=new ArrayBuffer(t),r=new Uint8Array(n),i=0;i<t;i++)r[i]=e.charCodeAt(i);return n}function vn(e,t){return hn([li(e)],{type:t})}function _n(e,t){return vn(dn(e),t)}function di(e){for(var t="",n=new Uint8Array(e),r=n.byteLength,i=0;i<r;i++)t+=String.fromCharCode(n[i]);return t}function hr(e,t){var n=new FileReader,r=typeof n.readAsBinaryString=="function";n.onloadend=function(i){var s=i.target.result||"";if(r)return t(s);t(di(s))},r?n.readAsBinaryString(e):n.readAsArrayBuffer(e)}function vr(e,t){hr(e,function(n){t(n)})}function gn(e,t){vr(e,function(n){t(tt(n))})}function hi(e,t){var n=new FileReader;n.onloadend=function(r){var i=r.target.result||new ArrayBuffer(0);t(i)},n.readAsArrayBuffer(e)}var vi=self.setImmediate||self.setTimeout,_i=32768;function gi(e){return tt(e)}function yi(e,t,n,r,i){(n>0||r<t.size)&&(t=t.slice(n,r)),hi(t,function(s){e.append(s),i()})}function pi(e,t,n,r,i){(n>0||r<t.length)&&(t=t.substring(n,r)),e.appendBinary(t),i()}function yn(e,t){var n=typeof e=="string",r=n?e.length:e.size,i=Math.min(_i,r),s=Math.ceil(r/i),u=0,v=n?new ft.default:new ft.default.ArrayBuffer,_=n?pi:yi;function g(){vi(l)}function m(){var y=v.end(!0),w=gi(y);t(w),v.destroy()}function l(){var y=u*i,w=y+i;u++,u<s?_(v,e,y,w,g):_(v,e,y,w,m)}l()}function _r(e){return ft.default.hash(e)}function gr(e,t){if(!t)return He().replace(/-/g,"").toLowerCase();var n=Object.assign({},e);return delete n._rev_tree,_r(JSON.stringify(n))}var bt=He;function $e(e){for(var t,n,r,i=e.rev_tree.slice(),s;s=i.pop();){var u=s.ids,v=u[2],_=s.pos;if(v.length){for(var g=0,m=v.length;g<m;g++)i.push({pos:_+1,ids:v[g]});continue}var l=!!u[1].deleted,y=u[0];(!t||(r!==l?r:n!==_?n<_:t<y))&&(t=y,n=_,r=l)}return n+"-"+t}function Fe(e,t){for(var n=e.slice(),r;r=n.pop();)for(var i=r.pos,s=r.ids,u=s[2],v=t(u.length===0,i,s[0],r.ctx,s[1]),_=0,g=u.length;_<g;_++)n.push({pos:i+1,ids:u[_],ctx:v})}function mi(e,t){return e.pos-t.pos}function pn(e){var t=[];Fe(e,function(i,s,u,v,_){i&&t.push({rev:s+"-"+u,pos:s,opts:_})}),t.sort(mi).reverse();for(var n=0,r=t.length;n<r;n++)delete t[n].pos;return t}function mn(e){for(var t=$e(e),n=pn(e.rev_tree),r=[],i=0,s=n.length;i<s;i++){var u=n[i];u.rev!==t&&!u.opts.deleted&&r.push(u.rev)}return r}function wi(e){var t=[];return Fe(e.rev_tree,function(n,r,i,s,u){u.status==="available"&&!n&&(t.push(r+"-"+i),u.status="missing")}),t}function bi(e,t){let n=[],r=e.slice(),i;for(;i=r.pop();){let{pos:s,ids:u}=i,v=`${s}-${u[0]}`,_=u[2];if(n.push(v),v===t){if(_.length!==0)throw new Error("The requested revision is not a leaf");return n.reverse()}(_.length===0||_.length>1)&&(n=[]);for(let g=0,m=_.length;g<m;g++)r.push({pos:s+1,ids:_[g]})}if(n.length===0)throw new Error("The requested revision does not exist");return n.reverse()}function yr(e){for(var t=[],n=e.slice(),r;r=n.pop();){var i=r.pos,s=r.ids,u=s[0],v=s[1],_=s[2],g=_.length===0,m=r.history?r.history.slice():[];m.push({id:u,opts:v}),g&&t.push({pos:i+1-m.length,ids:m});for(var l=0,y=_.length;l<y;l++)n.push({pos:i+1,ids:_[l],history:m})}return t.reverse()}function Si(e,t){return e.pos-t.pos}function Ai(e,t,n){for(var r=0,i=e.length,s;r<i;)s=r+i>>>1,n(e[s],t)<0?r=s+1:i=s;return r}function Oi(e,t,n){var r=Ai(e,t,n);e.splice(r,0,t)}function jn(e,t){for(var n,r,i=t,s=e.length;i<s;i++){var u=e[i],v=[u.id,u.opts,[]];r?(r[2].push(v),r=v):n=r=v}return n}function xi(e,t){return e[0]<t[0]?-1:1}function Nn(e,t){for(var n=[{tree1:e,tree2:t}],r=!1;n.length>0;){var i=n.pop(),s=i.tree1,u=i.tree2;(s[1].status||u[1].status)&&(s[1].status=s[1].status==="available"||u[1].status==="available"?"available":"missing");for(var v=0;v<u[2].length;v++){if(!s[2][0]){r="new_leaf",s[2][0]=u[2][v];continue}for(var _=!1,g=0;g<s[2].length;g++)s[2][g][0]===u[2][v][0]&&(n.push({tree1:s[2][g],tree2:u[2][v]}),_=!0);_||(r="new_branch",Oi(s[2],u[2][v],xi))}}return{conflicts:r,tree:e}}function pr(e,t,n){var r=[],i=!1,s=!1,u;if(!e.length)return{tree:[t],conflicts:"new_leaf"};for(var v=0,_=e.length;v<_;v++){var g=e[v];if(g.pos===t.pos&&g.ids[0]===t.ids[0])u=Nn(g.ids,t.ids),r.push({pos:g.pos,ids:u.tree}),i=i||u.conflicts,s=!0;else if(n!==!0){var m=g.pos<t.pos?g:t,l=g.pos<t.pos?t:g,y=l.pos-m.pos,w=[],S=[];for(S.push({ids:m.ids,diff:y,parent:null,parentIdx:null});S.length>0;){var q=S.pop();if(q.diff===0){q.ids[0]===l.ids[0]&&w.push(q);continue}for(var p=q.ids[2],h=0,d=p.length;h<d;h++)S.push({ids:p[h],diff:q.diff-1,parent:q.ids,parentIdx:h})}var o=w[0];o?(u=Nn(o.ids,l.ids),o.parent[2][o.parentIdx]=u.tree,r.push({pos:m.pos,ids:m.ids}),i=i||u.conflicts,s=!0):r.push(g)}else r.push(g)}return s||r.push(t),r.sort(Si),{tree:r,conflicts:i||"internal_node"}}function qi(e,t){for(var n=yr(e),r,i,s=0,u=n.length;s<u;s++){var v=n[s],_=v.ids,g;if(_.length>t){r||(r={});var m=_.length-t;g={pos:v.pos+m,ids:jn(_,m)};for(var l=0;l<m;l++){var y=v.pos+l+"-"+_[l].id;r[y]=!0}}else g={pos:v.pos,ids:jn(_,0)};i?i=pr(i,g,!0).tree:i=[g]}return r&&Fe(i,function(w,S,q){delete r[S+"-"+q]}),{tree:i,revs:r?Object.keys(r):[]}}function mr(e,t,n){var r=pr(e,t),i=qi(r.tree,n);return{tree:i.tree,stemmedRevs:i.revs,conflicts:r.conflicts}}function Ci(e,t){for(var n=e.slice(),r=t.split("-"),i=parseInt(r[0],10),s=r[1],u;u=n.pop();){if(u.pos===i&&u.ids[0]===s)return!0;for(var v=u.ids[2],_=0,g=v.length;_<g;_++)n.push({pos:u.pos+1,ids:v[_]})}return!1}function Ei(e){return e.ids}function Re(e,t){t||(t=$e(e));for(var n=t.substring(t.indexOf("-")+1),r=e.rev_tree.map(Ei),i;i=r.pop();){if(i[0]===n)return!!i[1].deleted;r=r.concat(i[2])}}function Ne(e){return typeof e=="string"&&e.startsWith("_local/")}function Di(e,t){for(var n=t.rev_tree.slice(),r;r=n.pop();){var i=r.pos,s=r.ids,u=s[0],v=s[1],_=s[2],g=_.length===0,m=r.history?r.history.slice():[];if(m.push({id:u,pos:i,opts:v}),g)for(var l=0,y=m.length;l<y;l++){var w=m[l],S=w.pos+"-"+w.id;if(S===e)return i+"-"+u}for(var q=0,p=_.length;q<p;q++)n.push({pos:i+1,ids:_[q],history:m})}throw new Error("Unable to resolve latest revision for id "+t.id+", rev "+e)}function ki(e,t,n,r){try{e.emit("change",t,n,r)}catch(i){we("error",'Error in .on("change", function):',i)}}function Ti(e,t,n){var r=[{rev:e._rev}];n.style==="all_docs"&&(r=pn(t.rev_tree).map(function(s){return{rev:s.rev}}));var i={id:t.id,changes:r,doc:e};return Re(t,e._rev)&&(i.deleted=!0),n.conflicts&&(i.doc._conflicts=mn(t),i.doc._conflicts.length||delete i.doc._conflicts),i}var Ut=class extends ge{constructor(t,n,r){super(),this.db=t,n=n?fe(n):{};var i=n.complete=ar((v,_)=>{v?oi(this,"error")>0&&this.emit("error",v):this.emit("complete",_),this.removeAllListeners(),t.removeListener("destroyed",s)});r&&(this.on("complete",function(v){r(null,v)}),this.on("error",r));let s=()=>{this.cancel()};t.once("destroyed",s),n.onChange=(v,_,g)=>{this.isCancelled||ki(this,v,_,g)};var u=new Promise(function(v,_){n.complete=function(g,m){g?_(g):v(m)}});this.once("cancel",function(){t.removeListener("destroyed",s),n.complete(null,{status:"cancelled"})}),this.then=u.then.bind(u),this.catch=u.catch.bind(u),this.then(function(v){i(null,v)},i),t.taskqueue.isReady?this.validateChanges(n):t.taskqueue.addTask(v=>{v?n.complete(v):this.isCancelled?this.emit("cancel"):this.validateChanges(n)})}cancel(){this.isCancelled=!0,this.db.taskqueue.isReady&&this.emit("cancel")}validateChanges(t){var n=t.complete;J._changesFilterPlugin?J._changesFilterPlugin.validate(t,r=>{if(r)return n(r);this.doChanges(t)}):this.doChanges(t)}doChanges(t){var n=t.complete;if(t=fe(t),"live"in t&&!("continuous"in t)&&(t.continuous=t.live),t.processChange=Ti,t.since==="latest"&&(t.since="now"),t.since||(t.since=0),t.since==="now"){this.db.info().then(i=>{if(this.isCancelled){n(null,{status:"cancelled"});return}t.since=i.update_seq,this.doChanges(t)},n);return}if(J._changesFilterPlugin){if(J._changesFilterPlugin.normalize(t),J._changesFilterPlugin.shouldFilter(this,t))return J._changesFilterPlugin.filter(this,t)}else["doc_ids","filter","selector","view"].forEach(function(i){i in t&&we("warn",'The "'+i+'" 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 t||(t.descending=!1),t.limit=t.limit===0?1:t.limit,t.complete=n;var r=this.db._changes(t);if(r&&typeof r.cancel=="function"){let i=this.cancel;this.cancel=(...s)=>{r.cancel(),i.apply(this,s)}}}};function qt(e,t){return function(n,r){n||r[0]&&r[0].error?(n=n||r[0],n.docId=t,e(n)):e(null,r.length?r[0]:r)}}function Ri(e){for(var t=0;t<e.length;t++){var n=e[t];if(n._deleted)delete n._attachments;else if(n._attachments)for(var r=Object.keys(n._attachments),i=0;i<r.length;i++){var s=r[i];n._attachments[s]=et(n._attachments[s],["data","digest","content_type","length","revpos","stub"])}}}function Li(e,t){if(e._id===t._id){let n=e._revisions?e._revisions.start:0,r=t._revisions?t._revisions.start:0;return n-r}return e._id<t._id?-1:1}function Pi(e){var t={},n=[];return Fe(e,function(r,i,s,u){var v=i+"-"+s;return r&&(t[v]=0),u!==void 0&&n.push({from:u,to:v}),v}),n.reverse(),n.forEach(function(r){t[r.from]===void 0?t[r.from]=1+t[r.to]:t[r.from]=Math.min(t[r.from],1+t[r.to])}),t}function Bi(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)}function wr(e){var t=e._compactionQueue[0],n=t.opts,r=t.callback;e.get("_local/compaction").catch(function(){return!1}).then(function(i){i&&i.last_seq&&(n.last_seq=i.last_seq),e._compact(n,function(s,u){s?r(s):r(null,u),De(function(){e._compactionQueue.shift(),e._compactionQueue.length&&wr(e)})})})}function Ii(e,t,n){return e.get("_local/purges").then(function(r){let i=r.purgeSeq+1;return r.purges.push({docId:t,rev:n,purgeSeq:i}),r.purges.length>self.purged_infos_limit&&r.purges.splice(0,r.purges.length-self.purged_infos_limit),r.purgeSeq=i,r}).catch(function(r){if(r.status!==404)throw r;return{_id:"_local/purges",purges:[{docId:t,rev:n,purgeSeq:0}],purgeSeq:0}}).then(function(r){return e.put(r)})}function ji(e){return e.charAt(0)==="_"?e+" is not a valid attachment name, attachment names cannot start with '_'":!1}function Ct(e){return e===null||typeof e!="object"||Array.isArray(e)}var Ni=/^\d+-[^-]*$/;function Et(e){return typeof e=="string"&&Ni.test(e)}var dt=class extends ge{_setup(){this.post=te("post",function(t,n,r){if(typeof n=="function"&&(r=n,n={}),Ct(t))return r(G(xt));this.bulkDocs({docs:[t]},n,qt(r,t._id))}).bind(this),this.put=te("put",function(t,n,r){if(typeof n=="function"&&(r=n,n={}),Ct(t))return r(G(xt));if(lr(t._id),"_rev"in t&&!Et(t._rev))return r(G(ot));if(Ne(t._id)&&typeof this._putLocal=="function")return t._deleted?this._removeLocal(t,r):this._putLocal(t,r);let i=u=>{typeof this._put=="function"&&n.new_edits!==!1?this._put(t,n,u):this.bulkDocs({docs:[t]},n,qt(u,t._id))};n.force&&t._rev?(s(),i(function(u){var v=u?null:{ok:!0,id:t._id,rev:t._rev};r(u,v)})):i(r);function s(){var u=t._rev.split("-"),v=u[1],_=parseInt(u[0],10),g=_+1,m=gr();t._revisions={start:g,ids:[m,v]},t._rev=g+"-"+m,n.new_edits=!1}}).bind(this),this.putAttachment=te("putAttachment",function(t,n,r,i,s){var u=this;typeof s=="function"&&(s=i,i=r,r=null),typeof s>"u"&&(s=i,i=r,r=null),s||we("warn","Attachment",n,"on document",t,"is missing content_type");function v(_){var g="_rev"in _?parseInt(_._rev,10):0;return _._attachments=_._attachments||{},_._attachments[n]={content_type:s,data:i,revpos:++g},u.put(_)}return u.get(t).then(function(_){if(_._rev!==r)throw G(ze);return v(_)},function(_){if(_.reason===pe.message)return v({_id:t});throw _})}).bind(this),this.removeAttachment=te("removeAttachment",function(t,n,r,i){this.get(t,(s,u)=>{if(s){i(s);return}if(u._rev!==r){i(G(ze));return}if(!u._attachments)return i();delete u._attachments[n],Object.keys(u._attachments).length===0&&delete u._attachments,this.put(u,i)})}).bind(this),this.remove=te("remove",function(t,n,r,i){var s;typeof n=="string"?(s={_id:t,_rev:n},typeof r=="function"&&(i=r,r={})):(s=t,typeof n=="function"?(i=n,r={}):(i=r,r=n)),r=r||{},r.was_delete=!0;var u={_id:s._id,_rev:s._rev||r.rev};if(u._deleted=!0,Ne(u._id)&&typeof this._removeLocal=="function")return this._removeLocal(s,i);this.bulkDocs({docs:[u]},r,qt(i,u._id))}).bind(this),this.revsDiff=te("revsDiff",function(t,n,r){typeof n=="function"&&(r=n,n={});var i=Object.keys(t);if(!i.length)return r(null,{});var s=0,u=new Map;function v(g,m){u.has(g)||u.set(g,{missing:[]}),u.get(g).missing.push(m)}function _(g,m){var l=t[g].slice(0);Fe(m,function(y,w,S,q,p){var h=w+"-"+S,d=l.indexOf(h);d!==-1&&(l.splice(d,1),p.status!=="available"&&v(g,h))}),l.forEach(function(y){v(g,y)})}i.forEach(function(g){this._getRevisionTree(g,function(m,l){if(m&&m.status===404&&m.message==="missing")u.set(g,{missing:t[g]});else{if(m)return r(m);_(g,l)}if(++s===i.length){var y={};return u.forEach(function(w,S){y[S]=w}),r(null,y)}})},this)}).bind(this),this.bulkGet=te("bulkGet",function(t,n){ur(this,t,n)}).bind(this),this.compactDocument=te("compactDocument",function(t,n,r){this._getRevisionTree(t,(i,s)=>{if(i)return r(i);var u=Pi(s),v=[],_=[];Object.keys(u).forEach(function(g){u[g]>n&&v.push(g)}),Fe(s,function(g,m,l,y,w){var S=m+"-"+l;w.status==="available"&&v.indexOf(S)!==-1&&_.push(S)}),this._doCompaction(t,_,r)})}).bind(this),this.compact=te("compact",function(t,n){typeof t=="function"&&(n=t,t={}),t=t||{},this._compactionQueue=this._compactionQueue||[],this._compactionQueue.push({opts:t,callback:n}),this._compactionQueue.length===1&&wr(this)}).bind(this),this.get=te("get",function(t,n,r){if(typeof n=="function"&&(r=n,n={}),n=n||{},typeof t!="string")return r(G(fr));if(Ne(t)&&typeof this._getLocal=="function")return this._getLocal(t,r);var i=[];let s=()=>{var _=[],g=i.length;if(!g)return r(null,_);i.forEach(m=>{this.get(t,{rev:m,revs:n.revs,latest:n.latest,attachments:n.attachments,binary:n.binary},function(l,y){if(l)_.push({missing:m});else{for(var w,S=0,q=_.length;S<q;S++)if(_[S].ok&&_[S].ok._rev===y._rev){w=!0;break}w||_.push({ok:y})}g--,g||r(null,_)})})};if(n.open_revs){if(n.open_revs==="all")this._getRevisionTree(t,function(_,g){if(_)return r(_);i=pn(g).map(function(m){return m.rev}),s()});else if(Array.isArray(n.open_revs)){i=n.open_revs;for(var u=0;u<i.length;u++){var v=i[u];if(!Et(v))return r(G(ot))}s()}else return r(G(un,"function_clause"));return}return this._get(t,n,(_,g)=>{if(_)return _.docId=t,r(_);var m=g.doc,l=g.metadata,y=g.ctx;if(n.conflicts){var w=mn(l);w.length&&(m._conflicts=w)}if(Re(l,m._rev)&&(m._deleted=!0),n.revs||n.revs_info){for(var S=m._rev.split("-"),q=parseInt(S[0],10),p=S[1],h=yr(l.rev_tree),d=null,o=0;o<h.length;o++){var a=h[o];let j=a.ids.findIndex($=>$.id===p);var f=j===q-1;(f||!d&&j!==-1)&&(d=a)}if(!d)return _=new Error("invalid rev tree"),_.docId=t,r(_);let B=m._rev.split("-")[1],U=d.ids.findIndex(j=>j.id===B)+1;var c=d.ids.length-U;if(d.ids.splice(U,c),d.ids.reverse(),n.revs&&(m._revisions={start:d.pos+d.ids.length-1,ids:d.ids.map(function(j){return j.id})}),n.revs_info){var O=d.pos+d.ids.length;m._revs_info=d.ids.map(function(j){return O--,{rev:O+"-"+j.id,status:j.opts.status}})}}if(n.attachments&&m._attachments){var x=m._attachments,E=Object.keys(x).length;if(E===0)return r(null,m);Object.keys(x).forEach(B=>{this._getAttachment(m._id,B,x[B],{binary:n.binary,metadata:l,ctx:y},function(U,j){var $=m._attachments[B];$.data=j,delete $.stub,delete $.length,--E||r(null,m)})})}else{if(m._attachments)for(var R in m._attachments)Object.prototype.hasOwnProperty.call(m._attachments,R)&&(m._attachments[R].stub=!0);r(null,m)}})}).bind(this),this.getAttachment=te("getAttachment",function(t,n,r,i){r instanceof Function&&(i=r,r={}),this._get(t,r,(s,u)=>{if(s)return i(s);if(u.doc._attachments&&u.doc._attachments[n])r.ctx=u.ctx,r.binary=!0,r.metadata=u.metadata,this._getAttachment(t,n,u.doc._attachments[n],r,i);else return i(G(pe))})}).bind(this),this.allDocs=te("allDocs",function(t,n){if(typeof t=="function"&&(n=t,t={}),t.skip=typeof t.skip<"u"?t.skip:0,t.start_key&&(t.startkey=t.start_key),t.end_key&&(t.endkey=t.end_key),"keys"in t){if(!Array.isArray(t.keys))return n(new TypeError("options.keys must be an array"));var r=["startkey","endkey","key"].filter(function(i){return i in t})[0];if(r){n(G(ii,"Query parameter `"+r+"` is not compatible with multi-get"));return}if(!Ee(this)&&(Bi(t),t.keys.length===0))return this._allDocs({limit:0},n)}return this._allDocs(t,n)}).bind(this),this.close=te("close",function(t){return this._closed=!0,this.emit("closed"),this._close(t)}).bind(this),this.info=te("info",function(t){this._info((n,r)=>{if(n)return t(n);r.db_name=r.db_name||this.name,r.auto_compaction=!!(this.auto_compaction&&!Ee(this)),r.adapter=this.adapter,t(null,r)})}).bind(this),this.id=te("id",function(t){return this._id(t)}).bind(this),this.bulkDocs=te("bulkDocs",function(t,n,r){if(typeof n=="function"&&(r=n,n={}),n=n||{},Array.isArray(t)&&(t={docs:t}),!t||!t.docs||!Array.isArray(t.docs))return r(G(ti));for(var i=0;i<t.docs.length;++i){let _=t.docs[i];if(Ct(_))return r(G(xt));if("_rev"in _&&!Et(_._rev))return r(G(ot))}var s;if(t.docs.forEach(function(_){_._attachments&&Object.keys(_._attachments).forEach(function(g){s=s||ji(g),_._attachments[g].content_type||we("warn","Attachment",g,"on document",_._id,"is missing content_type")})}),s)return r(G(wt,s));"new_edits"in n||("new_edits"in t?n.new_edits=t.new_edits:n.new_edits=!0);var u=this;!n.new_edits&&!Ee(u)&&t.docs.sort(Li),Ri(t.docs);var v=t.docs.map(function(_){return _._id});this._bulkDocs(t,n,function(_,g){if(_)return r(_);if(n.new_edits||(g=g.filter(function(y){return y.error})),!Ee(u))for(var m=0,l=g.length;m<l;m++)g[m].id=g[m].id||v[m];r(null,g)})}).bind(this),this.registerDependentDatabase=te("registerDependentDatabase",function(t,n){var r=fe(this.__opts);this.__opts.view_adapter&&(r.adapter=this.__opts.view_adapter);var i=new this.constructor(t,r);function s(u){return u.dependentDbs=u.dependentDbs||{},u.dependentDbs[t]?!1:(u.dependentDbs[t]=!0,u)}lt(this,"_local/_pouch_dependentDbs",s).then(function(){n(null,{db:i})}).catch(n)}).bind(this),this.destroy=te("destroy",function(t,n){typeof t=="function"&&(n=t,t={});var r="use_prefix"in this?this.use_prefix:!0;let i=()=>{this._destroy(t,(s,u)=>{if(s)return n(s);this._destroyed=!0,this.emit("destroyed"),n(null,u||{ok:!0})})};if(Ee(this))return i();this.get("_local/_pouch_dependentDbs",(s,u)=>{if(s)return s.status!==404?n(s):i();var v=u.dependentDbs,_=this.constructor,g=Object.keys(v).map(m=>{var l=r?m.replace(new RegExp("^"+_.prefix),""):m;return new _(l,this.__opts).destroy()});Promise.all(g).then(i,n)})}).bind(this)}_compact(t,n){var r={return_docs:!1,last_seq:t.last_seq||0,since:t.last_seq||0},i=[],s,u=0;let v=m=>{this.activeTasks.update(s,{completed_items:++u}),i.push(this.compactDocument(m.id,0))},_=m=>{this.activeTasks.remove(s,m),n(m)},g=m=>{var l=m.last_seq;Promise.all(i).then(()=>lt(this,"_local/compaction",y=>!y.last_seq||y.last_seq<l?(y.last_seq=l,y):!1)).then(()=>{this.activeTasks.remove(s),n(null,{ok:!0})}).catch(_)};this.info().then(m=>{s=this.activeTasks.add({name:"database_compaction",total_items:m.update_seq-r.last_seq}),this.changes(r).on("change",v).on("complete",g).on("error",_)})}changes(t,n){return typeof t=="function"&&(n=t,t={}),t=t||{},t.return_docs="return_docs"in t?t.return_docs:!t.live,new Ut(this,t,n)}type(){return typeof this._type=="function"?this._type():this.adapter}};dt.prototype.purge=te("_purge",function(e,t,n){if(typeof this._purge>"u")return n(G(un,"Purge is not implemented in the "+this.adapter+" adapter."));var r=this;r._getRevisionTree(e,(i,s)=>{if(i)return n(i);if(!s)return n(G(pe));let u;try{u=bi(s,t)}catch(v){return n(v.message||v)}r._purge(e,u,(v,_)=>{if(v)return n(v);Ii(r,e,t).then(function(){return n(null,_)})})})});var Mt=class{constructor(){this.isReady=!1,this.failed=!1,this.queue=[]}execute(){var t;if(this.failed)for(;t=this.queue.shift();)t(this.failed);else for(;t=this.queue.shift();)t()}fail(t){this.failed=t,this.execute()}ready(t){this.isReady=!0,this.db=t,this.execute()}addTask(t){this.queue.push(t),this.failed&&this.execute()}};function $i(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=J.adapters,i=J.preferredAdapters,s=J.prefix,u=t.adapter;if(!u)for(var v=0;v<i.length;++v){if(u=i[v],u==="idb"&&"websql"in r&&ct()&&localStorage["_pouch__websqldb_"+s+e]){we("log",'PouchDB is downgrading "'+e+'" to WebSQL to avoid data loss, because it was already opened with WebSQL.');continue}break}var _=r[u],g=_&&"use_prefix"in _?_.use_prefix:!0;return{name:g?s+e:e,adapter:u}}function Fi(e,t){e.prototype=Object.create(t.prototype,{constructor:{value:e}})}function br(e,t){let n=function(...r){if(!(this instanceof n))return new n(...r);t.apply(this,r)};return Fi(n,e),n}function Ki(e){function t(r){e.removeListener("closed",n),r||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)}var ht=class extends dt{constructor(t,n){super(),this._setup(t,n)}_setup(t,n){if(super._setup(),n=n||{},t&&typeof t=="object"&&(n=t,t=n.name,delete n.name),n.deterministic_revs===void 0&&(n.deterministic_revs=!0),this.__opts=n=fe(n),this.auto_compaction=n.auto_compaction,this.purged_infos_limit=n.purged_infos_limit||1e3,this.prefix=J.prefix,typeof t!="string")throw new Error("Missing/invalid DB name");var r=(n.prefix||"")+t,i=$i(r,n);if(n.name=i.name,n.adapter=n.adapter||i.adapter,this.name=t,this._adapter=n.adapter,J.emit("debug",["adapter","Picked adapter: ",n.adapter]),!J.adapters[n.adapter]||!J.adapters[n.adapter].valid())throw new Error("Invalid Adapter: "+n.adapter);if(n.view_adapter&&(!J.adapters[n.view_adapter]||!J.adapters[n.view_adapter].valid()))throw new Error("Invalid View Adapter: "+n.view_adapter);this.taskqueue=new Mt,this.adapter=n.adapter,J.adapters[n.adapter].call(this,n,s=>{if(s)return this.taskqueue.fail(s);Ki(this),this.emit("created",this),J.emit("created",this.name),this.taskqueue.ready(this)})}},J=br(ht,function(e,t){ht.prototype._setup.call(this,e,t)}),Sr=fetch,Ge=Headers,Gt=class{constructor(){this.tasks={}}list(){return Object.values(this.tasks)}add(t){let n=He();return this.tasks[n]={id:n,name:t.name,total_items:t.total_items,created_at:new Date().toJSON()},n}get(t){return this.tasks[t]}remove(t,n){return delete this.tasks[t],this.tasks}update(t,n){let r=this.tasks[t];if(typeof r<"u"){let i={id:r.id,name:r.name,created_at:r.created_at,total_items:n.total_items||r.total_items,completed_items:n.completed_items||r.completed_items,updated_at:new Date().toJSON()};this.tasks[t]=i}return this.tasks}};J.adapters={};J.preferredAdapters=[];J.prefix="_pouch_";var $n=new ge;function Ui(e){Object.keys(ge.prototype).forEach(function(n){typeof ge.prototype[n]=="function"&&(e[n]=$n[n].bind($n))});var t=e._destructionListeners=new Map;e.on("ref",function(r){t.has(r.name)||t.set(r.name,[]),t.get(r.name).push(r)}),e.on("unref",function(r){if(t.has(r.name)){var i=t.get(r.name),s=i.indexOf(r);s<0||(i.splice(s,1),i.length>1?t.set(r.name,i):t.delete(r.name))}}),e.on("destroyed",function(r){if(t.has(r)){var i=t.get(r);t.delete(r),i.forEach(function(s){s.emit("destroyed",!0)})}})}Ui(J);J.adapter=function(e,t,n){t.valid()&&(J.adapters[e]=t,n&&J.preferredAdapters.push(e))};J.plugin=function(e){if(typeof e=="function")e(J);else{if(typeof e!="object"||Object.keys(e).length===0)throw new Error('Invalid plugin: got "'+e+'", expected an object or a function');Object.keys(e).forEach(function(t){J.prototype[t]=e[t]})}return this.__defaults&&(J.__defaults=Object.assign({},this.__defaults)),J};J.defaults=function(e){let t=br(J,function(n,r){r=r||{},n&&typeof n=="object"&&(r=n,n=r.name,delete r.name),r=Object.assign({},t.__defaults,r),J.call(this,n,r)});return t.preferredAdapters=J.preferredAdapters.slice(),Object.keys(J).forEach(function(n){n in t||(t[n]=J[n])}),t.__defaults=Object.assign({},this.__defaults,e),t};J.fetch=function(e,t){return Sr(e,t)};J.prototype.activeTasks=J.activeTasks=new Gt;var Mi="9.0.0";function wn(e,t){for(var n=e,r=0,i=t.length;r<i;r++){var s=t[r];if(n=n[s],!n)break}return n}function Gi(e,t){return e<t?-1:e>t?1:0}function bn(e){for(var t=[],n="",r=0,i=e.length;r<i;r++){var s=e[r];r>0&&e[r-1]==="\\"&&(s==="$"||s===".")?n=n.substring(0,n.length-1)+s:s==="."?(t.push(n),n=""):n+=s}return t.push(n),t}var Ji=["$or","$nor","$not"];function Ar(e){return Ji.indexOf(e)>-1}function Or(e){return Object.keys(e)[0]}function zi(e){return e[Or(e)]}function Ze(e){var t={},n={$or:!0,$nor:!0};return e.forEach(function(r){Object.keys(r).forEach(function(i){var s=r[i];if(typeof s!="object"&&(s={$eq:s}),Ar(i))if(s instanceof Array){if(n[i]){n[i]=!1,t[i]=s;return}var u=[];t[i].forEach(function(_){Object.keys(s).forEach(function(g){var m=s[g],l=Math.max(Object.keys(_).length,Object.keys(m).length),y=Ze([_,m]);Object.keys(y).length<=l||u.push(y)})}),t[i]=u}else t[i]=Ze([s]);else{var v=t[i]=t[i]||{};Object.keys(s).forEach(function(_){var g=s[_];if(_==="$gt"||_==="$gte")return Qi(_,g,v);if(_==="$lt"||_==="$lte")return Wi(_,g,v);if(_==="$ne")return Hi(g,v);if(_==="$eq")return Xi(g,v);if(_==="$regex")return Yi(g,v);v[_]=g})}})}),t}function Qi(e,t,n){typeof n.$eq<"u"||(typeof n.$gte<"u"?e==="$gte"?t>n.$gte&&(n.$gte=t):t>=n.$gte&&(delete n.$gte,n.$gt=t):typeof n.$gt<"u"?e==="$gte"?t>n.$gt&&(delete n.$gt,n.$gte=t):t>n.$gt&&(n.$gt=t):n[e]=t)}function Wi(e,t,n){typeof n.$eq<"u"||(typeof n.$lte<"u"?e==="$lte"?t<n.$lte&&(n.$lte=t):t<=n.$lte&&(delete n.$lte,n.$lt=t):typeof n.$lt<"u"?e==="$lte"?t<n.$lt&&(delete n.$lt,n.$lte=t):t<n.$lt&&(n.$lt=t):n[e]=t)}function Hi(e,t){"$ne"in t?t.$ne.push(e):t.$ne=[e]}function Xi(e,t){delete t.$gt,delete t.$gte,delete t.$lt,delete t.$lte,delete t.$ne,t.$eq=e}function Yi(e,t){"$regex"in t?t.$regex.push(e):t.$regex=[e]}function xr(e){for(var t in e){if(Array.isArray(e))for(var n in e)e[n].$and&&(e[n]=Ze(e[n].$and));var r=e[t];typeof r=="object"&&xr(r)}return e}function qr(e,t){for(var n in e){n==="$and"&&(t=!0);var r=e[n];typeof r=="object"&&(t=qr(r,t))}return t}function Zi(e){var t=fe(e);qr(t,!1)&&(t=xr(t),"$and"in t&&(t=Ze(t.$and))),["$or","$nor"].forEach(function(u){u in t&&t[u].forEach(function(v){for(var _=Object.keys(v),g=0;g<_.length;g++){var m=_[g],l=v[m];(typeof l!="object"||l===null)&&(v[m]={$eq:l})}})}),"$not"in t&&(t.$not=Ze([t.$not]));for(var n=Object.keys(t),r=0;r<n.length;r++){var i=n[r],s=t[i];(typeof s!="object"||s===null)&&(s={$eq:s}),t[i]=s}return Jt(t),t}function Jt(e){Object.keys(e).forEach(function(t){var n=e[t];Array.isArray(n)?n.forEach(function(r){r&&typeof r=="object"&&Jt(r)}):t==="$ne"?e.$ne=[n]:t==="$regex"?e.$regex=[n]:n&&typeof n=="object"&&Jt(n)})}function Vi(e,t,n){for(var r="",i=n-e.length;r.length<i;)r+=t;return r}function es(e,t,n){var r=Vi(e,t,n);return r+e}var Cr=-324,zt=3,Qt="";function ne(e,t){if(e===t)return 0;e=Ke(e),t=Ke(t);var n=Wt(e),r=Wt(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 as(e,t)}return Array.isArray(e)?ss(e,t):os(e,t)}function Ke(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]=Ke(t[r])}else{if(e instanceof Date)return e.toJSON();if(e!==null){e={};for(var i in t)if(Object.prototype.hasOwnProperty.call(t,i)){var s=t[i];typeof s<"u"&&(e[i]=Ke(s))}}}}return e}function ts(e){if(e!==null)switch(typeof e){case"boolean":return e?1:0;case"number":return us(e);case"string":return e.replace(/\u0002/g,"").replace(/\u0001/g,"").replace(/\u0000/g,"");case"object":var t=Array.isArray(e),n=t?e:Object.keys(e),r=-1,i=n.length,s="";if(t)for(;++r<i;)s+=Ae(n[r]);else for(;++r<i;){var u=n[r];s+=Ae(u)+Ae(e[u])}return s}return""}function Ae(e){var t="\0";return e=Ke(e),Wt(e)+Qt+ts(e)+t}function ns(e,t){var n=t,r,i=e[t]==="1";if(i)r=0,t++;else{var s=e[t]==="0";t++;var u="",v=e.substring(t,t+zt),_=parseInt(v,10)+Cr;for(s&&(_=-_),t+=zt;;){var g=e[t];if(g==="\0")break;u+=g,t++}u=u.split("."),u.length===1?r=parseInt(u,10):r=parseFloat(u[0]+"."+u[1]),s&&(r=r-10),_!==0&&(r=parseFloat(r+"e"+_))}return{num:r,length:t-n}}function rs(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 i=r.element,s=r.index;if(Array.isArray(i))i.push(n);else if(s===e.length-2){var u=e.pop();i[u]=n}else e.push(n)}}function is(e){for(var t=[],n=[],r=0;;){var i=e[r++];if(i==="\0"){if(t.length===1)return t.pop();rs(t,n);continue}switch(i){case"1":t.push(null);break;case"2":t.push(e[r]==="1"),r++;break;case"3":var s=ns(e,r);t.push(s.num),r+=s.length;break;case"4":for(var u="";;){var v=e[r];if(v==="\0")break;u+=v,r++}u=u.replace(/\u0001\u0001/g,"\0").replace(/\u0001\u0002/g,"").replace(/\u0002\u0002/g,""),t.push(u);break;case"5":var _={element:[],index:t.length};t.push(_.element),n.push(_);break;case"6":var g={element:{},index:t.length};t.push(g.element),n.push(g);break;default:throw new Error("bad collationIndex or unexpectedly reached end of input: "+i)}}}function ss(e,t){for(var n=Math.min(e.length,t.length),r=0;r<n;r++){var i=ne(e[r],t[r]);if(i!==0)return i}return e.length===t.length?0:e.length>t.length?1:-1}function as(e,t){return e===t?0:e>t?1:-1}function os(e,t){for(var n=Object.keys(e),r=Object.keys(t),i=Math.min(n.length,r.length),s=0;s<i;s++){var u=ne(n[s],r[s]);if(u!==0||(u=ne(e[n[s]],t[r[s]]),u!==0))return u}return n.length===r.length?0:n.length>r.length?1:-1}function Wt(e){var t=["boolean","number","string","object"],n=t.indexOf(typeof e);if(~n)return e===null?1:Array.isArray(e)?5:n<3?n+2:n+3;if(Array.isArray(e))return 5}function us(e){if(e===0)return"1";var t=e.toExponential().split(/e\+?/),n=parseInt(t[1],10),r=e<0,i=r?"0":"2",s=(r?-n:n)-Cr,u=es(s.toString(),"0",zt);i+=Qt+u;var v=Math.abs(parseFloat(t[0]));r&&(v=10-v);var _=v.toFixed(20);return _=_.replace(/\.?0+$/,""),i+=Qt+_,i}function fs(e){function t(n){return e.map(function(r){var i=Or(r),s=bn(i),u=wn(n,s);return u})}return function(n,r){var i=t(n.doc),s=t(r.doc),u=ne(i,s);return u!==0?u:Gi(n.doc._id,r.doc._id)}}function cs(e,t,n){if(e=e.filter(function(u){return Je(u.doc,t.selector,n)}),t.sort){var r=fs(t.sort);e=e.sort(r),typeof t.sort[0]!="string"&&zi(t.sort[0])==="desc"&&(e=e.reverse())}if("limit"in t||"skip"in t){var i=t.skip||0,s=("limit"in t?t.limit:e.length)+i;e=e.slice(i,s)}return e}function Je(e,t,n){return n.every(function(r){var i=t[r],s=bn(r),u=wn(e,s);return Ar(r)?ls(r,i,e):vt(i,e,s,u)})}function vt(e,t,n,r){return e?typeof e=="object"?Object.keys(e).every(function(i){var s=e[i];if(i.indexOf("$")===0)return Fn(i,t,s,n,r);var u=bn(i);if(r===void 0&&typeof s!="object"&&u.length>0)return!1;var v=wn(r,u);return typeof s=="object"?vt(s,t,n,v):Fn("$eq",t,s,u,v)}):e===r:!0}function ls(e,t,n){return e==="$or"?t.some(function(r){return Je(n,r,Object.keys(r))}):e==="$not"?!Je(n,t,Object.keys(t)):!t.find(function(r){return Je(n,r,Object.keys(r))})}function Fn(e,t,n,r,i){if(!Un[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 Un[e](t,n,r,i)}function Xe(e){return typeof e<"u"&&e!==null}function Le(e){return typeof e<"u"}function ds(e,t){if(typeof e!="number"||parseInt(e,10)!==e)return!1;var n=t[0],r=t[1];return e%n===r}function Kn(e,t){return t.some(function(n){return e instanceof Array?e.some(function(r){return ne(n,r)===0}):ne(n,e)===0})}function hs(e,t){return t.every(function(n){return e.some(function(r){return ne(n,r)===0})})}function vs(e,t){return e.length===t}function _s(e,t){var n=new RegExp(t);return n.test(e)}function gs(e,t){switch(t){case"null":return e===null;case"boolean":return typeof e=="boolean";case"number":return typeof e=="number";case"string":return typeof e=="string";case"array":return e instanceof Array;case"object":return{}.toString.call(e)==="[object Object]"}}var Un={$elemMatch:function(e,t,n,r){return!Array.isArray(r)||r.length===0?!1:typeof r[0]=="object"&&r[0]!==null?r.some(function(i){return Je(i,t,Object.keys(t))}):r.some(function(i){return vt(t,e,n,i)})},$allMatch:function(e,t,n,r){return!Array.isArray(r)||r.length===0?!1:typeof r[0]=="object"&&r[0]!==null?r.every(function(i){return Je(i,t,Object.keys(t))}):r.every(function(i){return vt(t,e,n,i)})},$eq:function(e,t,n,r){return Le(r)&&ne(r,t)===0},$gte:function(e,t,n,r){return Le(r)&&ne(r,t)>=0},$gt:function(e,t,n,r){return Le(r)&&ne(r,t)>0},$lte:function(e,t,n,r){return Le(r)&&ne(r,t)<=0},$lt:function(e,t,n,r){return Le(r)&&ne(r,t)<0},$exists:function(e,t,n,r){return t?Le(r):!Le(r)},$mod:function(e,t,n,r){return Xe(r)&&ds(r,t)},$ne:function(e,t,n,r){return t.every(function(i){return ne(r,i)!==0})},$in:function(e,t,n,r){return Xe(r)&&Kn(r,t)},$nin:function(e,t,n,r){return Xe(r)&&!Kn(r,t)},$size:function(e,t,n,r){return Xe(r)&&Array.isArray(r)&&vs(r,t)},$all:function(e,t,n,r){return Array.isArray(r)&&hs(r,t)},$regex:function(e,t,n,r){return Xe(r)&&typeof r=="string"&&t.every(function(i){return _s(r,i)})},$type:function(e,t,n,r){return gs(r,t)}};function ys(e,t){if(typeof t!="object")throw new Error("Selector error: expected a JSON object");t=Zi(t);var n={doc:e},r=cs([n],{selector:t},Object.keys(t));return r&&r.length===1}function ps(e){return ln(`"use strict";
3
3
  return `+e+";",{})}function ms(e){var t=["return function(doc) {",' "use strict";'," var emitted = false;"," var emit = function (a, b) {"," emitted = true;"," };"," var view = "+e+";"," view(doc);"," if (emitted) {"," return true;"," }","};"].join(`
4
4
  `);return ln(t,{})}function ws(e,t){if(e.selector&&e.filter&&e.filter!=="_selector"){var n=typeof e.filter=="string"?e.filter:"function";return t(new Error('selector invalid for filter "'+n+'"'))}t()}function bs(e){e.view&&!e.filter&&(e.filter="_view"),e.selector&&!e.filter&&(e.filter="_selector"),e.filter&&typeof e.filter=="string"&&(e.filter==="_view"?e.view=Pn(e.view):e.filter=Pn(e.filter))}function Ss(e,t){return t.filter&&typeof t.filter=="string"&&!t.doc_ids&&!Ee(e.db)}function As(e,t){var n=t.complete;if(t.filter==="_view"){if(!t.view||typeof t.view!="string"){var r=G(wt,"`view` filter parameter not found or invalid.");return n(r)}var i=Kt(t.view);e.db.get("_design/"+i[0],function(u,v){if(e.isCancelled)return n(null,{status:"cancelled"});if(u)return n(Qe(u));var _=v&&v.views&&v.views[i[1]]&&v.views[i[1]].map;if(!_)return n(G(pe,v.views?"missing json key: "+i[1]:"missing json key: views"));t.filter=ms(_),e.doChanges(t)})}else if(t.selector)t.filter=function(u){return ys(u,t.selector)},e.doChanges(t);else{var s=Kt(t.filter);e.db.get("_design/"+s[0],function(u,v){if(e.isCancelled)return n(null,{status:"cancelled"});if(u)return n(Qe(u));var _=v&&v.filters&&v.filters[s[1]];if(!_)return n(G(pe,v&&v.filters?"missing json key: "+s[1]:"missing json key: filters"));t.filter=ps(_),e.doChanges(t)})}}function Os(e){e._changesFilterPlugin={validate:ws,normalize:bs,shouldFilter:Ss,filter:As}}J.plugin(Os);J.version=Mi;function xs(e,t,n){return new Promise(function(r){var i=hn([""]);let s;if(typeof n=="function"){let v=n(i);s=e.objectStore(t).put(v)}else{let u=n;s=e.objectStore(t).put(i,u)}s.onsuccess=function(){var u=navigator.userAgent.match(/Chrome\/(\d+)/),v=navigator.userAgent.match(/Edge\//);r(v||!u||parseInt(u[1],10)>=43)},s.onerror=e.onabort=function(u){u.preventDefault(),u.stopPropagation(),r(!1)}}).catch(function(){return!1})}function Er(e){return e.reduce(function(t,n){return t[n]=!0,t},{})}var qs=Er(["_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"]),Cs=Er(["_access","_attachments","_replication_id","_replication_state","_replication_state_time","_replication_state_reason","_replication_stats"]);function Mn(e){if(!/^\d+-/.test(e))return G(ot);var t=e.indexOf("-"),n=e.substring(0,t),r=e.substring(t+1);return{prefix:parseInt(n,10),id:r}}function Es(e,t){for(var n=e.start-e.ids.length+1,r=e.ids,i=[r[0],t,[]],s=1,u=r.length;s<u;s++)i=[r[s],{status:"missing"},[i]];return[{pos:n,ids:i}]}function Dr(e,t,n){n||(n={deterministic_revs:!0});var r,i,s,u={status:"available"};if(e._deleted&&(u.deleted=!0),t)if(e._id||(e._id=bt()),i=gr(e,n.deterministic_revs),e._rev){if(s=Mn(e._rev),s.error)return s;e._rev_tree=[{pos:s.prefix,ids:[s.id,{status:"missing"},[[i,u,[]]]]}],r=s.prefix+1}else e._rev_tree=[{pos:1,ids:[i,u,[]]}],r=1;else if(e._revisions&&(e._rev_tree=Es(e._revisions,u),r=e._revisions.start,i=e._revisions.ids[0]),!e._rev_tree){if(s=Mn(e._rev),s.error)return s;r=s.prefix,i=s.id,e._rev_tree=[{pos:r,ids:[i,u,[]]}]}lr(e._id),e._rev=r+"-"+i;var v={metadata:{},data:{}};for(var _ in e)if(Object.prototype.hasOwnProperty.call(e,_)){var g=_[0]==="_";if(g&&!qs[_]){var m=G(Ln,_);throw m.message=Ln.message+": "+_,m}else g&&!Cs[_]?v.metadata[_.slice(1)]=e[_]:v.data[_]=e[_]}return v}function Ds(e){try{return dn(e)}catch{var t=G(cr,"Attachment is not a valid base64 string");return{error:t}}}function ks(e,t,n){var r=Ds(e.data);if(r.error)return n(r.error);e.length=r.length,t==="blob"?e.data=vn(r,e.content_type):t==="base64"?e.data=tt(r):e.data=r,yn(r,function(i){e.digest="md5-"+i,n()})}function Ts(e,t,n){yn(e.data,function(r){e.digest="md5-"+r,e.length=e.data.size||e.data.length||0,t==="binary"?vr(e.data,function(i){e.data=i,n()}):t==="base64"?gn(e.data,function(i){e.data=i,n()}):n()})}function Rs(e,t,n){if(e.stub)return n();typeof e.data=="string"?ks(e,t,n):Ts(e,t,n)}function Ls(e,t,n){if(!e.length)return n();var r=0,i;e.forEach(function(u){var v=u.data&&u.data._attachments?Object.keys(u.data._attachments):[],_=0;if(!v.length)return s();function g(l){i=l,_++,_===v.length&&s()}for(var m in u.data._attachments)Object.prototype.hasOwnProperty.call(u.data._attachments,m)&&Rs(u.data._attachments[m],t,g)});function s(){r++,e.length===r&&(i?n(i):n())}}function Ps(e,t,n,r,i,s,u,v){if(Ci(t.rev_tree,n.metadata.rev)&&!v)return r[i]=n,s();var _=t.winningRev||$e(t),g="deleted"in t?t.deleted:Re(t,_),m="deleted"in n.metadata?n.metadata.deleted:Re(n.metadata),l=/^1-/.test(n.metadata.rev);if(g&&!m&&v&&l){var y=n.data;y._rev=_,y._id=n.metadata.id,n=Dr(y,v)}var w=mr(t.rev_tree,n.metadata.rev_tree[0],e),S=v&&(g&&m&&w.conflicts!=="new_leaf"||!g&&w.conflicts!=="new_leaf"||g&&!m&&w.conflicts==="new_branch");if(S){var q=G(ze);return r[i]=q,s()}var p=n.metadata.rev;n.metadata.rev_tree=w.tree,n.stemmedRevs=w.stemmedRevs||[],t.rev_map&&(n.metadata.rev_map=t.rev_map);var h=$e(n.metadata),d=Re(n.metadata,h),o=g===d?0:g<d?-1:1,a;p===h?a=d:a=Re(n.metadata,p),u(n,h,d,a,!0,o,i,s)}function Bs(e){return e.metadata.rev_tree[0].ids[1].status==="missing"}function Is(e,t,n,r,i,s,u,v,_){e=e||1e3;function g(q,p,h){var d=$e(q.metadata),o=Re(q.metadata,d);if("was_delete"in v&&o)return s[p]=G(pe,"deleted"),h();var a=m&&Bs(q);if(a){var f=G(ze);return s[p]=f,h()}var c=o?0:1;u(q,d,o,o,!1,c,p,h)}var m=v.new_edits,l=new Map,y=0,w=t.length;function S(){++y===w&&_&&_()}t.forEach(function(q,p){if(q._id&&Ne(q._id)){var h=q._deleted?"_removeLocal":"_putLocal";n[h](q,{ctx:i},function(o,a){s[p]=o||a,S()});return}var d=q.metadata.id;l.has(d)?(w--,l.get(d).push([q,p])):l.set(d,[[q,p]])}),l.forEach(function(q,p){var h=0;function d(){++h<q.length?o():S()}function o(){var a=q[h],f=a[0],c=a[1];if(r.has(p))Ps(e,r.get(p),f,s,c,d,u,m);else{var O=mr([],f.metadata.rev_tree[0],e);f.metadata.rev_tree=O.tree,f.stemmedRevs=O.stemmedRevs||[],g(f,c,d)}}o()})}var js=5,oe="document-store",de="by-sequence",me="attach-store",Ie="attach-seq-store",he="meta-store",qe="local-store",Dt="detect-blob-support";function Ns(e){try{return JSON.parse(e)}catch{return on.default.parse(e)}}function $s(e){try{return JSON.stringify(e)}catch{return on.default.stringify(e)}}function Ce(e){return function(t){var n="unknown_error";t.target&&t.target.error&&(n=t.target.error.name||t.target.error.message),e(G(fn,n,t.type))}}function Ht(e,t,n){return{data:$s(e),winningRev:t,deletedOrLocal:n?"1":"0",seq:e.seq,id:e.id}}function je(e){if(!e)return null;var t=Ns(e.data);return t.winningRev=e.winningRev,t.deleted=e.deletedOrLocal==="1",t.seq=e.seq,t}function _t(e){if(!e)return e;var t=e._doc_id_rev.lastIndexOf(":");return e._id=e._doc_id_rev.substring(0,t-1),e._rev=e._doc_id_rev.substring(t+1),delete e._doc_id_rev,e}function kr(e,t,n,r){n?r(e?typeof e!="string"?e:_n(e,t):hn([""],{type:t})):e?typeof e!="string"?hr(e,function(i){r(tt(i))}):r(e):r("")}function Tr(e,t,n,r){var i=Object.keys(e._attachments||{});if(!i.length)return r&&r();var s=0;function u(){++s===i.length&&r&&r()}function v(_,g){var m=_._attachments[g],l=m.digest,y=n.objectStore(me).get(l);y.onsuccess=function(w){m.body=w.target.result.body,u()}}i.forEach(function(_){t.attachments&&t.include_docs?v(e,_):(e._attachments[_].stub=!0,u())})}function Xt(e,t){return Promise.all(e.map(function(n){if(n.doc&&n.doc._attachments){var r=Object.keys(n.doc._attachments);return Promise.all(r.map(function(i){var s=n.doc._attachments[i];if("body"in s){var u=s.body,v=s.content_type;return new Promise(function(_){kr(u,v,t,function(g){n.doc._attachments[i]=Object.assign(et(s,["digest","content_type"]),{data:g}),_()})})}}))}}))}function Rr(e,t,n){var r=[],i=n.objectStore(de),s=n.objectStore(me),u=n.objectStore(Ie),v=e.length;function _(){v--,v||g()}function g(){r.length&&r.forEach(function(m){var l=u.index("digestSeq").count(IDBKeyRange.bound(m+"::",m+"::\uFFFF",!1,!1));l.onsuccess=function(y){var w=y.target.result;w||s.delete(m)}})}e.forEach(function(m){var l=i.index("_doc_id_rev"),y=t+"::"+m;l.getKey(y).onsuccess=function(w){var S=w.target.result;if(typeof S!="number")return _();i.delete(S);var q=u.index("seq").openCursor(IDBKeyRange.only(S));q.onsuccess=function(p){var h=p.target.result;if(h){var d=h.value.digestSeq.split("::")[0];r.push(d),u.delete(h.primaryKey),h.continue()}else _()}}})}function Oe(e,t,n){try{return{txn:e.transaction(t,n)}}catch(r){return{error:r}}}var Ye=new $t;function Fs(e,t,n,r,i,s){for(var u=t.docs,v,_,g,m,l,y,w,S,q=0,p=u.length;q<p;q++){var h=u[q];h._id&&Ne(h._id)||(h=u[q]=Dr(h,n.new_edits,e),h.error&&!w&&(w=h))}if(w)return s(w);var d=!1,o=0,a=new Array(u.length),f=new Map,c=!1,O=r._meta.blobSupport?"blob":"base64";Ls(u,O,function(D){if(D)return s(D);x()});function x(){var D=[oe,de,me,qe,Ie,he],L=Oe(i,D,"readwrite");if(L.error)return s(L.error);v=L.txn,v.onabort=Ce(s),v.ontimeout=Ce(s),v.oncomplete=j,_=v.objectStore(oe),g=v.objectStore(de),m=v.objectStore(me),l=v.objectStore(Ie),y=v.objectStore(he),y.get(he).onsuccess=function(N){S=N.target.result,B()},z(function(N){if(N)return c=!0,s(N);U()})}function E(){d=!0,B()}function R(){Is(e.revs_limit,u,r,f,v,a,Q,n,E)}function B(){!S||!d||(S.docCount+=o,y.put(S))}function U(){if(!u.length)return;var D=0;function L(){++D===u.length&&R()}function N(I){var F=je(I.target.result);F&&f.set(F.id,F),L()}for(var M=0,P=u.length;M<P;M++){var C=u[M];if(C._id&&Ne(C._id)){L();continue}var k=_.get(C.metadata.id);k.onsuccess=N}}function j(){c||(Ye.notify(r._meta.name),s(null,a))}function $(D,L){var N=m.get(D);N.onsuccess=function(M){if(M.target.result)L();else{var P=G(si,"unknown stub attachment with digest "+D);P.status=412,L(P)}}}function z(D){var L=[];if(u.forEach(function(C){C.data&&C.data._attachments&&Object.keys(C.data._attachments).forEach(function(k){var I=C.data._attachments[k];I.stub&&L.push(I.digest)})}),!L.length)return D();var N=0,M;function P(){++N===L.length&&D(M)}L.forEach(function(C){$(C,function(k){k&&!M&&(M=k),P()})})}function Q(D,L,N,M,P,C,k,I){D.metadata.winningRev=L,D.metadata.deleted=N;var F=D.data;F._id=D.metadata.id,F._rev=D.metadata.rev,M&&(F._deleted=!0);var K=F._attachments&&Object.keys(F._attachments).length;if(K)return b(D,L,N,P,k,I);o+=C,B(),W(D,L,N,P,k,I)}function W(D,L,N,M,P,C){var k=D.data,I=D.metadata;k._doc_id_rev=I.id+"::"+I.rev,delete k._id,delete k._rev;function F(re){var ve=D.stemmedRevs||[];M&&r.auto_compaction&&(ve=ve.concat(wi(D.metadata))),ve&&ve.length&&Rr(ve,D.metadata.id,v),I.seq=re.target.result;var xe=Ht(I,L,N),X=_.put(xe);X.onsuccess=Y}function K(re){re.preventDefault(),re.stopPropagation();var ve=g.index("_doc_id_rev"),xe=ve.getKey(k._doc_id_rev);xe.onsuccess=function(X){var H=g.put(k,X.target.result);H.onsuccess=F}}function Y(){a[P]={ok:!0,id:I.id,rev:I.rev},f.set(D.metadata.id,D.metadata),A(D,I.seq,C)}var ee=g.put(k);ee.onsuccess=F,ee.onerror=K}function b(D,L,N,M,P,C){var k=D.data,I=0,F=Object.keys(k._attachments);function K(){I===F.length&&W(D,L,N,M,P,C)}function Y(){I++,K()}F.forEach(function(ee){var re=D.data._attachments[ee];if(re.stub)I++,K();else{var ve=re.data;delete re.data,re.revpos=parseInt(L,10);var xe=re.digest;T(xe,ve,Y)}})}function A(D,L,N){var M=0,P=Object.keys(D.data._attachments||{});if(!P.length)return N();function C(){++M===P.length&&N()}function k(F){var K=D.data._attachments[F].digest,Y=l.put({seq:L,digestSeq:K+"::"+L});Y.onsuccess=C,Y.onerror=function(ee){ee.preventDefault(),ee.stopPropagation(),C()}}for(var I=0;I<P.length;I++)k(P[I])}function T(D,L,N){var M=m.count(D);M.onsuccess=function(P){var C=P.target.result;if(C)return N();var k={digest:D,body:L},I=m.put(k);I.onsuccess=N}}}function Lr(e,t,n,r,i){r===-1&&(r=1e3);var s=typeof e.getAll=="function"&&typeof e.getAllKeys=="function"&&r>1&&!n,u,v,_;function g(w){v=w.target.result,u&&i(u,v,_)}function m(w){u=w.target.result,v&&i(u,v,_)}function l(){if(!u.length)return i();var w=u[u.length-1],S;if(t&&t.upper)try{S=IDBKeyRange.bound(w,t.upper,!0,t.upperOpen)}catch(q){if(q.name==="DataError"&&q.code===0)return i()}else S=IDBKeyRange.lowerBound(w,!0);t=S,u=null,v=null,e.getAll(t,r).onsuccess=g,e.getAllKeys(t,r).onsuccess=m}function y(w){var S=w.target.result;if(!S)return i();i([S.key],[S.value],S)}s?(_={continue:l},e.getAll(t,r).onsuccess=g,e.getAllKeys(t,r).onsuccess=m):n?e.openCursor(t,"prev").onsuccess=y:e.openCursor(t).onsuccess=y}function Ks(e,t,n){if(typeof e.getAll=="function"){e.getAll(t).onsuccess=n;return}var r=[];function i(s){var u=s.target.result;u?(r.push(u.value),u.continue()):n({target:{result:r}})}e.openCursor(t).onsuccess=i}function Us(e,t,n){var r=new Array(e.length),i=0;e.forEach(function(s,u){t.get(s).onsuccess=function(v){v.target.result?r[u]=v.target.result:r[u]={key:s,error:"not_found"},i++,i===e.length&&n(e,r,{})}})}function Ms(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(s){return{error:s}}return null}function Gs(e,t,n){var r="startkey"in e?e.startkey:!1,i="endkey"in e?e.endkey:!1,s="key"in e?e.key:!1,u="keys"in e?e.keys:!1,v=e.skip||0,_=typeof e.limit=="number"?e.limit:-1,g=e.inclusive_end!==!1,m,l;if(!u&&(m=Ms(r,i,g,s,e.descending),l=m&&m.error,l&&!(l.name==="DataError"&&l.code===0)))return n(G(fn,l.name,l.message));var y=[oe,de,he];e.attachments&&y.push(me);var w=Oe(t,y,"readonly");if(w.error)return n(w.error);var S=w.txn;S.oncomplete=U,S.onabort=Ce(n);var q=S.objectStore(oe),p=S.objectStore(de),h=S.objectStore(he),d=p.index("_doc_id_rev"),o=[],a,f;h.get(he).onsuccess=function(j){a=j.target.result.docCount},e.update_seq&&(p.openKeyCursor(null,"prev").onsuccess=j=>{var $=j.target.result;$&&$.key&&(f=$.key)});function c(j,$,z){var Q=j.id+"::"+z;d.get(Q).onsuccess=function(b){if($.doc=_t(b.target.result)||{},e.conflicts){var A=mn(j);A.length&&($.doc._conflicts=A)}Tr($.doc,e,S)}}function O(j,$){var z={id:$.id,key:$.id,value:{rev:j}},Q=$.deleted;Q?u&&(o.push(z),z.value.deleted=!0,z.doc=null):v--<=0&&(o.push(z),e.include_docs&&c($,z,j))}function x(j){for(var $=0,z=j.length;$<z&&o.length!==_;$++){var Q=j[$];if(Q.error&&u){o.push(Q);continue}var W=je(Q),b=W.winningRev;O(b,W)}}function E(j,$,z){z&&(x($),o.length<_&&z.continue())}function R(j){var $=j.target.result;e.descending&&($=$.reverse()),x($)}function B(){var j={total_rows:a,offset:e.skip,rows:o};e.update_seq&&f!==void 0&&(j.update_seq=f),n(null,j)}function U(){e.attachments?Xt(o,e.binary).then(B):B()}if(!(l||_===0)){if(u)return Us(u,q,E);if(_===-1)return Ks(q,m,R);Lr(q,m,e.descending,_+v,E)}}function Js(e,t){var n=e.objectStore(oe).index("deletedOrLocal");n.count(IDBKeyRange.only("0")).onsuccess=function(r){t(r.target.result)}}var Yt=!1,Zt=[];function zs(e,t,n,r){try{e(t,n)}catch(i){r.emit("error",i)}}function Gn(){Yt||!Zt.length||(Yt=!0,Zt.shift()())}function Qs(e,t,n){Zt.push(function(){e(function(s,u){zs(t,s,u,n),Yt=!1,De(function(){Gn(n)})})}),Gn()}function Ws(e,t,n,r){if(e=fe(e),e.continuous){var i=n+":"+bt();return Ye.addListener(n,i,t,e),Ye.notify(n),{cancel:function(){Ye.removeListener(n,i)}}}var s=e.doc_ids&&new Set(e.doc_ids);e.since=e.since||0;var u=e.since,v="limit"in e?e.limit:-1;v===0&&(v=1);var _=[],g=0,m=cn(e),l=new Map,y,w,S,q;function p(x,E,R){if(!R||!x.length)return;var B=new Array(x.length),U=new Array(x.length);function j(Q,W){var b=e.processChange(W,Q,e);u=b.seq=Q.seq;var A=m(b);return typeof A=="object"?Promise.reject(A):A?(g++,e.return_docs&&_.push(b),e.attachments&&e.include_docs?new Promise(function(T){Tr(W,e,y,function(){Xt([b],e.binary).then(function(){T(b)})})}):Promise.resolve(b)):Promise.resolve()}function $(){for(var Q=[],W=0,b=B.length;W<b&&g!==v;W++){var A=B[W];if(A){var T=U[W];Q.push(j(T,A))}}Promise.all(Q).then(function(D){for(var L=0,N=D.length;L<N;L++)D[L]&&e.onChange(D[L])}).catch(e.complete),g!==v&&R.continue()}var z=0;E.forEach(function(Q,W){var b=_t(Q),A=x[W];d(b,A,function(T,D){U[W]=T,B[W]=D,++z===x.length&&$()})})}function h(x,E,R,B){if(R.seq!==E)return B();if(R.winningRev===x._rev)return B(R,x);var U=x._id+"::"+R.winningRev,j=q.get(U);j.onsuccess=function($){B(R,_t($.target.result))}}function d(x,E,R){if(s&&!s.has(x._id))return R();var B=l.get(x._id);if(B)return h(x,E,B,R);S.get(x._id).onsuccess=function(U){B=je(U.target.result),l.set(x._id,B),h(x,E,B,R)}}function o(){e.complete(null,{results:_,last_seq:u})}function a(){!e.continuous&&e.attachments?Xt(_).then(o):o()}var f=[oe,de];e.attachments&&f.push(me);var c=Oe(r,f,"readonly");if(c.error)return e.complete(c.error);y=c.txn,y.onabort=Ce(e.complete),y.oncomplete=a,w=y.objectStore(de),S=y.objectStore(oe),q=w.index("_doc_id_rev");var O=e.since&&!e.descending?IDBKeyRange.lowerBound(e.since,!0):null;Lr(w,O,e.descending,v,p)}var Me=new Map,kt,Tt=new Map;function Pr(e,t){var n=this;Qs(function(r){Hs(n,e,r)},t,n.constructor)}function Hs(e,t,n){var r=t.name,i=null,s=null;e._meta=null;function u(p){return function(h,d){h&&h instanceof Error&&!h.reason&&s&&(h.reason=s),p(h,d)}}function v(p){var h=p.createObjectStore(oe,{keyPath:"id"});p.createObjectStore(de,{autoIncrement:!0}).createIndex("_doc_id_rev","_doc_id_rev",{unique:!0}),p.createObjectStore(me,{keyPath:"digest"}),p.createObjectStore(he,{keyPath:"id",autoIncrement:!1}),p.createObjectStore(Dt),h.createIndex("deletedOrLocal","deletedOrLocal",{unique:!1}),p.createObjectStore(qe,{keyPath:"_id"});var d=p.createObjectStore(Ie,{autoIncrement:!0});d.createIndex("seq","seq"),d.createIndex("digestSeq","digestSeq",{unique:!0})}function _(p,h){var d=p.objectStore(oe);d.createIndex("deletedOrLocal","deletedOrLocal",{unique:!1}),d.openCursor().onsuccess=function(o){var a=o.target.result;if(a){var f=a.value,c=Re(f);f.deletedOrLocal=c?"1":"0",d.put(f),a.continue()}else h()}}function g(p){p.createObjectStore(qe,{keyPath:"_id"}).createIndex("_doc_id_rev","_doc_id_rev",{unique:!0})}function m(p,h){var d=p.objectStore(qe),o=p.objectStore(oe),a=p.objectStore(de),f=o.openCursor();f.onsuccess=function(c){var O=c.target.result;if(O){var x=O.value,E=x.id,R=Ne(E),B=$e(x);if(R){var U=E+"::"+B,j=E+"::",$=E+"::~",z=a.index("_doc_id_rev"),Q=IDBKeyRange.bound(j,$,!1,!1),W=z.openCursor(Q);W.onsuccess=function(b){if(W=b.target.result,!W)o.delete(O.primaryKey),O.continue();else{var A=W.value;A._doc_id_rev===U&&d.put(A),a.delete(W.primaryKey),W.continue()}}}else O.continue()}else h&&h()}}function l(p){var h=p.createObjectStore(Ie,{autoIncrement:!0});h.createIndex("seq","seq"),h.createIndex("digestSeq","digestSeq",{unique:!0})}function y(p,h){var d=p.objectStore(de),o=p.objectStore(me),a=p.objectStore(Ie),f=o.count();f.onsuccess=function(c){var O=c.target.result;if(!O)return h();d.openCursor().onsuccess=function(x){var E=x.target.result;if(!E)return h();for(var R=E.value,B=E.primaryKey,U=Object.keys(R._attachments||{}),j={},$=0;$<U.length;$++){var z=R._attachments[U[$]];j[z.digest]=!0}var Q=Object.keys(j);for($=0;$<Q.length;$++){var W=Q[$];a.put({seq:B,digestSeq:W+"::"+B})}E.continue()}}}function w(p){function h(f){return f.data?je(f):(f.deleted=f.deletedOrLocal==="1",f)}var d=p.objectStore(de),o=p.objectStore(oe),a=o.openCursor();a.onsuccess=function(f){var c=f.target.result;if(!c)return;var O=h(c.value);O.winningRev=O.winningRev||$e(O);function x(){var R=O.id+"::",B=O.id+"::\uFFFF",U=d.index("_doc_id_rev").openCursor(IDBKeyRange.bound(R,B)),j=0;U.onsuccess=function($){var z=$.target.result;if(!z)return O.seq=j,E();var Q=z.primaryKey;Q>j&&(j=Q),z.continue()}}function E(){var R=Ht(O,O.winningRev,O.deleted),B=o.put(R);B.onsuccess=function(){c.continue()}}if(O.seq)return E();x()}}e._remote=!1,e.type=function(){return"idb"},e._id=or(function(p){p(null,e._meta.instanceId)}),e._bulkDocs=function(h,d,o){Fs(t,h,d,e,i,u(o))},e._get=function(h,d,o){var a,f,c,O=d.ctx;if(!O){var x=Oe(i,[oe,de,me],"readonly");if(x.error)return o(x.error);O=x.txn}function E(){o(c,{doc:a,metadata:f,ctx:O})}O.objectStore(oe).get(h).onsuccess=function(R){if(f=je(R.target.result),!f)return c=G(pe,"missing"),E();var B;if(d.rev)B=d.latest?Di(d.rev,f):d.rev;else{B=f.winningRev;var U=Re(f);if(U)return c=G(pe,"deleted"),E()}var j=O.objectStore(de),$=f.id+"::"+B;j.index("_doc_id_rev").get($).onsuccess=function(z){if(a=z.target.result,a&&(a=_t(a)),!a)return c=G(pe,"missing"),E();E()}}},e._getAttachment=function(p,h,d,o,a){var f;if(o.ctx)f=o.ctx;else{var c=Oe(i,[oe,de,me],"readonly");if(c.error)return a(c.error);f=c.txn}var O=d.digest,x=d.content_type;f.objectStore(me).get(O).onsuccess=function(E){var R=E.target.result.body;kr(R,x,o.binary,function(B){a(null,B)})}},e._info=function(h){var d,o,a=Oe(i,[he,de],"readonly");if(a.error)return h(a.error);var f=a.txn;f.objectStore(he).get(he).onsuccess=function(c){o=c.target.result.docCount},f.objectStore(de).openKeyCursor(null,"prev").onsuccess=function(c){var O=c.target.result;d=O?O.key:0},f.oncomplete=function(){h(null,{doc_count:o,update_seq:d,idb_attachment_format:e._meta.blobSupport?"binary":"base64"})}},e._allDocs=function(h,d){Gs(h,i,u(d))},e._changes=function(h){return Ws(h,e,r,i)},e._close=function(p){i.close(),Me.delete(r),p()},e._getRevisionTree=function(p,h){var d=Oe(i,[oe],"readonly");if(d.error)return h(d.error);var o=d.txn,a=o.objectStore(oe).get(p);a.onsuccess=function(f){var c=je(f.target.result);c?h(null,c.rev_tree):h(G(pe))}},e._doCompaction=function(p,h,d){var o=[oe,de,me,Ie],a=Oe(i,o,"readwrite");if(a.error)return d(a.error);var f=a.txn,c=f.objectStore(oe);c.get(p).onsuccess=function(O){var x=je(O.target.result);Fe(x.rev_tree,function(B,U,j,$,z){var Q=U+"-"+j;h.indexOf(Q)!==-1&&(z.status="missing")}),Rr(h,p,f);var E=x.winningRev,R=x.deleted;f.objectStore(oe).put(Ht(x,E,R))},f.onabort=Ce(d),f.oncomplete=function(){d()}},e._getLocal=function(p,h){var d=Oe(i,[qe],"readonly");if(d.error)return h(d.error);var o=d.txn,a=o.objectStore(qe).get(p);a.onerror=Ce(h),a.onsuccess=function(f){var c=f.target.result;c?(delete c._doc_id_rev,h(null,c)):h(G(pe))}},e._putLocal=function(p,h,d){typeof h=="function"&&(d=h,h={}),delete p._revisions;var o=p._rev,a=p._id;o?p._rev="0-"+(parseInt(o.split("-")[1],10)+1):p._rev="0-1";var f=h.ctx,c;if(!f){var O=Oe(i,[qe],"readwrite");if(O.error)return d(O.error);f=O.txn,f.onerror=Ce(d),f.oncomplete=function(){c&&d(null,c)}}var x=f.objectStore(qe),E;o?(E=x.get(a),E.onsuccess=function(R){var B=R.target.result;if(!B||B._rev!==o)d(G(ze));else{var U=x.put(p);U.onsuccess=function(){c={ok:!0,id:p._id,rev:p._rev},h.ctx&&d(null,c)}}}):(E=x.add(p),E.onerror=function(R){d(G(ze)),R.preventDefault(),R.stopPropagation()},E.onsuccess=function(){c={ok:!0,id:p._id,rev:p._rev},h.ctx&&d(null,c)})},e._removeLocal=function(p,h,d){typeof h=="function"&&(d=h,h={});var o=h.ctx;if(!o){var a=Oe(i,[qe],"readwrite");if(a.error)return d(a.error);o=a.txn,o.oncomplete=function(){f&&d(null,f)}}var f,c=p._id,O=o.objectStore(qe),x=O.get(c);x.onerror=Ce(d),x.onsuccess=function(E){var R=E.target.result;!R||R._rev!==p._rev?d(G(pe)):(O.delete(c),f={ok:!0,id:c,rev:"0-0"},h.ctx&&d(null,f))}},e._destroy=function(p,h){Ye.removeAllListeners(r);var d=Tt.get(r);d&&d.result&&(d.result.close(),Me.delete(r));var o=indexedDB.deleteDatabase(r);o.onsuccess=function(){Tt.delete(r),ct()&&r in localStorage&&delete localStorage[r],h(null,{ok:!0})},o.onerror=Ce(h)};var S=Me.get(r);if(S)return i=S.idb,e._meta=S.global,De(function(){n(null,e)});var q=indexedDB.open(r,js);Tt.set(r,q),q.onupgradeneeded=function(p){var h=p.target.result;if(p.oldVersion<1)return v(h);var d=p.currentTarget.transaction;p.oldVersion<3&&g(h),p.oldVersion<4&&l(h);var o=[_,m,y,w],a=p.oldVersion;function f(){var c=o[a-1];a++,c&&c(d,f)}f()},q.onsuccess=function(p){i=p.target.result,i.onversionchange=function(){i.close(),Me.delete(r)},i.onabort=function(E){we("error","Database has a global failure",E.target.error),s=E.target.error,i.close(),Me.delete(r)};var h=i.transaction([he,Dt,oe],"readwrite"),d=!1,o,a,f,c;function O(){typeof f>"u"||!d||(e._meta={name:r,instanceId:c,blobSupport:f},Me.set(r,{idb:i,global:e._meta}),n(null,e))}function x(){if(!(typeof a>"u"||typeof o>"u")){var E=r+"_id";E in o?c=o[E]:o[E]=c=bt(),o.docCount=a,h.objectStore(he).put(o)}}h.objectStore(he).get(he).onsuccess=function(E){o=E.target.result||{id:he},x()},Js(h,function(E){a=E,x()}),kt||(kt=xs(h,Dt,"key")),kt.then(function(E){f=E,O()}),h.oncomplete=function(){d=!0,O()},h.onabort=Ce(n)},q.onerror=function(p){var h=p.target.error&&p.target.error.message;h?h.indexOf("stored database is a higher version")!==-1&&(h=new Error('This DB was created with the newer "indexeddb" adapter, but you are trying to open it with the older "idb" adapter')):h="Failed to open indexedDB, are you in private browsing mode?",we("error",h),n(G(fn,h))}}Pr.valid=function(){try{return typeof indexedDB<"u"&&typeof IDBKeyRange<"u"}catch{return!1}};function Xs(e){e.adapter("idb",Pr,!0)}function Ys(e,t){return new Promise(function(n,r){var i=0,s=0,u=0,v=e.length,_;function g(){i++,e[s++]().then(l,y)}function m(){++u===v?_?r(_):n():w()}function l(){i--,m()}function y(S){i--,_=_||S,m()}function w(){for(;i<t&&s<v;)g()}w()})}var Zs=25,Vs=50,st=5e3,ea=1e4,Rt={};function Lt(e){let t=e.doc||e.ok,n=t&&t._attachments;n&&Object.keys(n).forEach(function(r){let i=n[r];i.data=_n(i.data,i.content_type)})}function Pe(e){return/^_design/.test(e)?"_design/"+encodeURIComponent(e.slice(8)):e.startsWith("_local/")?"_local/"+encodeURIComponent(e.slice(7)):encodeURIComponent(e)}function Jn(e){return!e._attachments||!Object.keys(e._attachments)?Promise.resolve():Promise.all(Object.keys(e._attachments).map(function(t){let n=e._attachments[t];if(n.data&&typeof n.data!="string")return new Promise(function(r){gn(n.data,r)}).then(function(r){n.data=r})}))}function ta(e){if(!e.prefix)return!1;let t=dr(e.prefix).protocol;return t==="http"||t==="https"}function na(e,t){if(ta(t)){let i=t.name.substr(t.prefix.length);e=t.prefix.replace(/\/?$/,"/")+encodeURIComponent(i)}let n=dr(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(),n.db.indexOf("%")===-1&&(n.db=encodeURIComponent(n.db)),n.path=r.join("/"),n}function ue(e,t){return ut(e,e.db+"/"+t)}function ut(e,t){let n=e.path?"/":"";return e.protocol+"://"+e.host+(e.port?":"+e.port:"")+"/"+e.path+n+t}function at(e){let t=Object.keys(e);return t.length===0?"":"?"+t.map(n=>n+"="+encodeURIComponent(e[n])).join("&")}function ra(e){let t=typeof navigator<"u"&&navigator.userAgent?navigator.userAgent.toLowerCase():"",n=t.indexOf("msie")!==-1,r=t.indexOf("trident")!==-1,i=t.indexOf("edge")!==-1,s=!("method"in e)||e.method==="GET";return(n||r||i)&&s}function Vt(e,t){let n=this,r=na(e.name,e),i=ue(r,"");e=fe(e);let s=async function(l,y){if(y=y||{},y.headers=y.headers||new Ge,y.credentials="include",e.auth||r.auth){let q=e.auth||r.auth,p=q.username+":"+q.password,h=tt(unescape(encodeURIComponent(p)));y.headers.set("Authorization","Basic "+h)}let w=e.headers||{};return Object.keys(w).forEach(function(q){y.headers.append(q,w[q])}),ra(y)&&(l+=(l.indexOf("?")===-1?"?":"&")+"_nonce="+Date.now()),await(e.fetch||Sr)(l,y)};function u(l,y){return te(l,function(...w){g().then(function(){return y.apply(this,w)}).catch(function(S){w.pop()(S)})}).bind(n)}async function v(l,y){let w={};y=y||{},y.headers=y.headers||new Ge,y.headers.get("Content-Type")||y.headers.set("Content-Type","application/json"),y.headers.get("Accept")||y.headers.set("Accept","application/json");let S=await s(l,y);w.ok=S.ok,w.status=S.status;let q=await S.json();if(w.data=q,!w.ok)throw w.data.status=w.status,Qe(w.data);return Array.isArray(w.data)&&(w.data=w.data.map(function(p){return p.error||p.missing?Qe(p):p})),w}let _;async function g(){return e.skip_setup?Promise.resolve():_||(_=v(i).catch(function(l){return l&&l.status&&l.status===404?(Ft(404,"PouchDB is just detecting if the remote exists."),v(i,{method:"PUT"})):Promise.reject(l)}).catch(function(l){return l&&l.status&&l.status===412?!0:Promise.reject(l)}),_.catch(function(){_=null}),_)}De(function(){t(null,n)}),n._remote=!0,n.type=function(){return"http"},n.id=u("id",async function(l){let y;try{y=await(await s(ut(r,""))).json()}catch{y={}}let w=y&&y.uuid?y.uuid+r.db:ue(r,"");l(null,w)}),n.compact=u("compact",async function(l,y){typeof l=="function"&&(y=l,l={}),l=fe(l),await v(ue(r,"_compact"),{method:"POST"});function w(){n.info(function(S,q){q&&!q.compact_running?y(null,{ok:!0}):setTimeout(w,l.interval||200)})}w()}),n.bulkGet=te("bulkGet",function(l,y){let w=this;async function S(d){let o={};l.revs&&(o.revs=!0),l.attachments&&(o.attachments=!0),l.latest&&(o.latest=!0);try{let a=await v(ue(r,"_bulk_get"+at(o)),{method:"POST",body:JSON.stringify({docs:l.docs})});l.attachments&&l.binary&&a.data.results.forEach(function(f){f.docs.forEach(Lt)}),d(null,a.data)}catch(a){d(a)}}function q(){let d=Vs,o=Math.ceil(l.docs.length/d),a=0,f=new Array(o);function c(O){return function(x,E){f[O]=E.results,++a===o&&y(null,{results:f.flat()})}}for(let O=0;O<o;O++){let x=et(l,["revs","attachments","binary","latest"]);x.docs=l.docs.slice(O*d,Math.min(l.docs.length,(O+1)*d)),ur(w,x,c(O))}}let p=ut(r,""),h=Rt[p];typeof h!="boolean"?S(function(d,o){d?(Rt[p]=!1,Ft(d.status,"PouchDB is just detecting if the remote supports the _bulk_get API."),q()):(Rt[p]=!0,y(null,o))}):h?S(y):q()}),n._info=async function(l){try{await g();let w=await(await s(ue(r,""))).json();w.host=ue(r,""),l(null,w)}catch(y){l(y)}},n.fetch=async function(l,y){await g();let w=l.substring(0,1)==="/"?ut(r,l.substring(1)):ue(r,l);return s(w,y)},n.get=u("get",async function(l,y,w){typeof y=="function"&&(w=y,y={}),y=fe(y);let S={};y.revs&&(S.revs=!0),y.revs_info&&(S.revs_info=!0),y.latest&&(S.latest=!0),y.open_revs&&(y.open_revs!=="all"&&(y.open_revs=JSON.stringify(y.open_revs)),S.open_revs=y.open_revs),y.rev&&(S.rev=y.rev),y.conflicts&&(S.conflicts=y.conflicts),y.update_seq&&(S.update_seq=y.update_seq),l=Pe(l);function q(d){let o=d._attachments,a=o&&Object.keys(o);if(!o||!a.length)return;async function f(O){let x=o[O],E=Pe(d._id)+"/"+m(O)+"?rev="+d._rev,R=await s(ue(r,E)),B;"buffer"in R?B=await R.buffer():B=await R.blob();let U;if(y.binary){let j=Object.getOwnPropertyDescriptor(B.__proto__,"type");(!j||j.set)&&(B.type=x.content_type),U=B}else U=await new Promise(function(j){gn(B,j)});delete x.stub,delete x.length,x.data=U}let c=a.map(function(O){return function(){return f(O)}});return Ys(c,5)}function p(d){return Array.isArray(d)?Promise.all(d.map(function(o){if(o.ok)return q(o.ok)})):q(d)}let h=ue(r,l+at(S));try{let d=await v(h);y.attachments&&await p(d.data),w(null,d.data)}catch(d){d.docId=l,w(d)}}),n.remove=u("remove",async function(l,y,w,S){let q;typeof y=="string"?(q={_id:l,_rev:y},typeof w=="function"&&(S=w,w={})):(q=l,typeof y=="function"?(S=y,w={}):(S=w,w=y));let p=q._rev||w.rev,h=ue(r,Pe(q._id))+"?rev="+p;try{let d=await v(h,{method:"DELETE"});S(null,d.data)}catch(d){S(d)}});function m(l){return l.split("/").map(encodeURIComponent).join("/")}n.getAttachment=u("getAttachment",async function(l,y,w,S){typeof w=="function"&&(S=w,w={});let q=w.rev?"?rev="+w.rev:"",p=ue(r,Pe(l))+"/"+m(y)+q,h;try{let d=await s(p,{method:"GET"});if(!d.ok)throw d;h=d.headers.get("content-type");let o;if(typeof _e<"u"&&!_e.browser&&typeof d.buffer=="function"?o=await d.buffer():o=await d.blob(),typeof _e<"u"&&!_e.browser){let a=Object.getOwnPropertyDescriptor(o.__proto__,"type");(!a||a.set)&&(o.type=h)}S(null,o)}catch(d){S(d)}}),n.removeAttachment=u("removeAttachment",async function(l,y,w,S){let q=ue(r,Pe(l)+"/"+m(y))+"?rev="+w;try{let p=await v(q,{method:"DELETE"});S(null,p.data)}catch(p){S(p)}}),n.putAttachment=u("putAttachment",async function(l,y,w,S,q,p){typeof q=="function"&&(p=q,q=S,S=w,w=null);let h=Pe(l)+"/"+m(y),d=ue(r,h);if(w&&(d+="?rev="+w),typeof S=="string"){let o;try{o=dn(S)}catch{return p(G(cr,"Attachment is not a valid base64 string"))}S=o?vn(o,q):""}try{let o=await v(d,{headers:new Ge({"Content-Type":q}),method:"PUT",body:S});p(null,o.data)}catch(o){p(o)}}),n._bulkDocs=async function(l,y,w){l.new_edits=y.new_edits;try{await g(),await Promise.all(l.docs.map(Jn));let S=await v(ue(r,"_bulk_docs"),{method:"POST",body:JSON.stringify(l)});w(null,S.data)}catch(S){w(S)}},n._put=async function(l,y,w){try{await g(),await Jn(l);let S=await v(ue(r,Pe(l._id)),{method:"PUT",body:JSON.stringify(l)});w(null,S.data)}catch(S){S.docId=l&&l._id,w(S)}},n.allDocs=u("allDocs",async function(l,y){typeof l=="function"&&(y=l,l={}),l=fe(l);let w={},S,q="GET";l.conflicts&&(w.conflicts=!0),l.update_seq&&(w.update_seq=!0),l.descending&&(w.descending=!0),l.include_docs&&(w.include_docs=!0),l.attachments&&(w.attachments=!0),l.key&&(w.key=JSON.stringify(l.key)),l.start_key&&(l.startkey=l.start_key),l.startkey&&(w.startkey=JSON.stringify(l.startkey)),l.end_key&&(l.endkey=l.end_key),l.endkey&&(w.endkey=JSON.stringify(l.endkey)),typeof l.inclusive_end<"u"&&(w.inclusive_end=!!l.inclusive_end),typeof l.limit<"u"&&(w.limit=l.limit),typeof l.skip<"u"&&(w.skip=l.skip);let p=at(w);typeof l.keys<"u"&&(q="POST",S={keys:l.keys});try{let h=await v(ue(r,"_all_docs"+p),{method:q,body:JSON.stringify(S)});l.include_docs&&l.attachments&&l.binary&&h.data.rows.forEach(Lt),y(null,h.data)}catch(h){y(h)}}),n._changes=function(l){let y="batch_size"in l?l.batch_size:Zs;l=fe(l),l.continuous&&!("heartbeat"in l)&&(l.heartbeat=ea);let w="timeout"in l?l.timeout:30*1e3;"timeout"in l&&l.timeout&&w-l.timeout<st&&(w=l.timeout+st),"heartbeat"in l&&l.heartbeat&&w-l.heartbeat<st&&(w=l.heartbeat+st);let S={};"timeout"in l&&l.timeout&&(S.timeout=l.timeout);let q=typeof l.limit<"u"?l.limit:!1,p=q;if(l.style&&(S.style=l.style),(l.include_docs||l.filter&&typeof l.filter=="function")&&(S.include_docs=!0),l.attachments&&(S.attachments=!0),l.continuous&&(S.feed="longpoll"),l.seq_interval&&(S.seq_interval=l.seq_interval),l.conflicts&&(S.conflicts=!0),l.descending&&(S.descending=!0),l.update_seq&&(S.update_seq=!0),"heartbeat"in l&&l.heartbeat&&(S.heartbeat=l.heartbeat),l.filter&&typeof l.filter=="string"&&(S.filter=l.filter),l.view&&typeof l.view=="string"&&(S.filter="_view",S.view=l.view),l.query_params&&typeof l.query_params=="object")for(let x in l.query_params)Object.prototype.hasOwnProperty.call(l.query_params,x)&&(S[x]=l.query_params[x]);let h="GET",d;l.doc_ids?(S.filter="_doc_ids",h="POST",d={doc_ids:l.doc_ids}):l.selector&&(S.filter="_selector",h="POST",d={selector:l.selector});let o=new AbortController,a,f=async function(x,E){if(l.aborted)return;S.since=x,typeof S.since=="object"&&(S.since=JSON.stringify(S.since)),l.descending?q&&(S.limit=p):S.limit=!q||p>y?y:p;let R=ue(r,"_changes"+at(S)),B={signal:o.signal,method:h,body:JSON.stringify(d)};if(a=x,!l.aborted)try{await g();let U=await v(R,B);E(null,U.data)}catch(U){E(U)}},c={results:[]},O=function(x,E){if(l.aborted)return;let R=0;if(E&&E.results){R=E.results.length,c.last_seq=E.last_seq;let U=null,j=null;typeof E.pending=="number"&&(U=E.pending),(typeof c.last_seq=="string"||typeof c.last_seq=="number")&&(j=c.last_seq);let $={};$.query=l.query_params,E.results=E.results.filter(function(z){p--;let Q=cn(l)(z);return Q&&(l.include_docs&&l.attachments&&l.binary&&Lt(z),l.return_docs&&c.results.push(z),l.onChange(z,U,j)),Q})}else if(x){l.aborted=!0,l.complete(x);return}E&&E.last_seq&&(a=E.last_seq);let B=q&&p<=0||E&&R<y||l.descending;l.continuous&&!(q&&p<=0)||!B?De(function(){f(a,O)}):l.complete(null,c)};return f(l.since||0,O),{cancel:function(){l.aborted=!0,o.abort()}}},n.revsDiff=u("revsDiff",async function(l,y,w){typeof y=="function"&&(w=y,y={});try{let S=await v(ue(r,"_revs_diff"),{method:"POST",body:JSON.stringify(l)});w(null,S.data)}catch(S){w(S)}}),n._close=function(l){l()},n._destroy=async function(l,y){try{let w=await v(ue(r,""),{method:"DELETE"});y(null,w)}catch(w){w.status===404?y(null,{ok:!0}):y(w)}}}Vt.valid=function(){return!0};function ia(e){e.adapter("http",Vt,!1),e.adapter("https",Vt,!1)}var Be=class e extends Error{constructor(t){super(),this.status=400,this.name="query_parse_error",this.message=t,this.error=!0;try{Error.captureStackTrace(this,e)}catch{}}},gt=class e extends Error{constructor(t){super(),this.status=404,this.name="not_found",this.message=t,this.error=!0;try{Error.captureStackTrace(this,e)}catch{}}},yt=class e extends Error{constructor(t){super(),this.status=500,this.name="invalid_value",this.message=t,this.error=!0;try{Error.captureStackTrace(this,e)}catch{}}};function Br(e,t){return t&&e.then(function(n){De(function(){t(null,n)})},function(n){De(function(){t(n)})}),e}function sa(e){return function(...t){var n=t.pop(),r=e.apply(this,t);return typeof n=="function"&&Br(r,n),r}}function aa(e,t){return e.then(function(n){return t().then(function(){return n})},function(n){return t().then(function(){throw n})})}function Pt(e,t){return function(){var n=arguments,r=this;return e.add(function(){return t.apply(r,n)})}}function zn(e){var t=new Set(e),n=new Array(t.size),r=-1;return t.forEach(function(i){n[++r]=i}),n}function Bt(e){var t=new Array(e.size),n=-1;return e.forEach(function(r,i){t[++n]=i}),t}function Qn(e){var t="builtin "+e+" function requires map values to be numbers or number arrays";return new yt(t)}function en(e){for(var t=0,n=0,r=e.length;n<r;n++){var i=e[n];if(typeof i!="number")if(Array.isArray(i)){t=typeof t=="number"?[t]:t;for(var s=0,u=i.length;s<u;s++){var v=i[s];if(typeof v!="number")throw Qn("_sum");typeof t[s]>"u"?t.push(v):t[s]+=v}}else throw Qn("_sum");else typeof t=="number"?t+=i:t[0]+=i}return t}var oa=we.bind(null,"log"),ua=Array.isArray,fa=JSON.parse;function Ir(e,t){return ln("return ("+e.replace(/;\s*$/,"")+");",{emit:t,sum:en,log:oa,isArray:ua,toJSON:fa})}var Ve=class{constructor(){this.promise=Promise.resolve()}add(t){return this.promise=this.promise.catch(()=>{}).then(()=>t()),this.promise}finish(){return this.promise}};function Wn(e){if(!e)return"undefined";switch(typeof e){case"function":return e.toString();case"string":return e.toString();default:return JSON.stringify(e)}}function ca(e,t){return Wn(e)+Wn(t)+"undefined"}async function Hn(e,t,n,r,i,s){let u=ca(n,r),v;if(!i&&(v=e._cachedViews=e._cachedViews||{},v[u]))return v[u];let _=e.info().then(async function(g){let m=g.db_name+"-mrview-"+(i?"temp":_r(u));function l(p){p.views=p.views||{};let h=t;h.indexOf("/")===-1&&(h=t+"/"+t);let d=p.views[h]=p.views[h]||{};if(!d[m])return d[m]=!0,p}await lt(e,"_local/"+s,l);let w=(await e.registerDependentDatabase(m)).db;w.auto_compaction=!0;let S={name:m,db:w,sourceDB:e,adapter:e.adapter,mapFun:n,reduceFun:r},q;try{q=await S.db.get("_local/lastSeq")}catch(p){if(p.status!==404)throw p}return S.seq=q?q.seq:0,v&&S.db.once("destroyed",function(){delete v[u]}),S});return v&&(v[u]=_),_}var Xn={},Yn=new Ve,la=50;function It(e){return e.indexOf("/")===-1?[e,e]:e.split("/")}function da(e){return e.length===1&&/^1-/.test(e[0].rev)}function Zn(e,t,n){try{e.emit("error",t)}catch{we("error",`The user's map/reduce function threw an uncaught error.
5
5
  You can debug this error by doing:
6
6
  myDatabase.on('error', function (err) { debugger; });
7
7
  Please double-check your map/reduce function.`),we("error",t,n)}}function ha(e,t,n,r){function i(b,A,T){try{A(T)}catch(D){Zn(b,D,{fun:A,doc:T})}}function s(b,A,T,D,L){try{return{output:A(T,D,L)}}catch(N){return Zn(b,N,{fun:A,keys:T,values:D,rereduce:L}),{error:N}}}function u(b,A){let T=ne(b.key,A.key);return T!==0?T:ne(b.value,A.value)}function v(b,A,T){return T=T||0,typeof A=="number"?b.slice(T,A+T):T>0?b.slice(T):b}function _(b){let A=b.value;return A&&typeof A=="object"&&A._id||b.id}function g(b){for(let A of b.rows){let T=A.doc&&A.doc._attachments;if(T)for(let D of Object.keys(T)){let L=T[D];T[D].data=_n(L.data,L.content_type)}}}function m(b){return function(A){return b.include_docs&&b.attachments&&b.binary&&g(A),A}}function l(b,A,T,D){let L=A[b];typeof L<"u"&&(D&&(L=encodeURIComponent(JSON.stringify(L))),T.push(b+"="+L))}function y(b){if(typeof b<"u"){let A=Number(b);return!isNaN(A)&&A===parseInt(b,10)?A:b}}function w(b){return b.group_level=y(b.group_level),b.limit=y(b.limit),b.skip=y(b.skip),b}function S(b){if(b){if(typeof b!="number")return new Be(`Invalid value for integer: "${b}"`);if(b<0)return new Be(`Invalid value for positive integer: "${b}"`)}}function q(b,A){let T=b.descending?"endkey":"startkey",D=b.descending?"startkey":"endkey";if(typeof b[T]<"u"&&typeof b[D]<"u"&&ne(b[T],b[D])>0)throw new Be("No rows can match your key range, reverse your start_key and end_key or set {descending : true}");if(A.reduce&&b.reduce!==!1){if(b.include_docs)throw new Be("{include_docs:true} is invalid for reduce");if(b.keys&&b.keys.length>1&&!b.group&&!b.group_level)throw new Be("Multi-key fetches for reduce views must use {group: true}")}for(let L of["group_level","limit","skip"]){let N=S(b[L]);if(N)throw N}}async function p(b,A,T){let D=[],L,N="GET",M;if(l("reduce",T,D),l("include_docs",T,D),l("attachments",T,D),l("limit",T,D),l("descending",T,D),l("group",T,D),l("group_level",T,D),l("skip",T,D),l("stale",T,D),l("conflicts",T,D),l("startkey",T,D,!0),l("start_key",T,D,!0),l("endkey",T,D,!0),l("end_key",T,D,!0),l("inclusive_end",T,D),l("key",T,D,!0),l("update_seq",T,D),D=D.join("&"),D=D===""?"":"?"+D,typeof T.keys<"u"){let I=`keys=${encodeURIComponent(JSON.stringify(T.keys))}`;I.length+D.length+1<=2e3?D+=(D[0]==="?"?"&":"?")+I:(N="POST",typeof A=="string"?L={keys:T.keys}:A.keys=T.keys)}if(typeof A=="string"){let k=It(A),I=await b.fetch("_design/"+k[0]+"/_view/"+k[1]+D,{headers:new Ge({"Content-Type":"application/json"}),method:N,body:JSON.stringify(L)});M=I.ok;let F=await I.json();if(!M)throw F.status=I.status,Qe(F);for(let K of F.rows)if(K.value&&K.value.error&&K.value.error==="builtin_reduce_error")throw new Error(K.reason);return new Promise(function(K){K(F)}).then(m(T))}L=L||{};for(let k of Object.keys(A))Array.isArray(A[k])?L[k]=A[k]:L[k]=A[k].toString();let P=await b.fetch("_temp_view"+D,{headers:new Ge({"Content-Type":"application/json"}),method:"POST",body:JSON.stringify(L)});M=P.ok;let C=await P.json();if(!M)throw C.status=P.status,Qe(C);return new Promise(function(k){k(C)}).then(m(T))}function h(b,A,T){return new Promise(function(D,L){b._query(A,T,function(N,M){if(N)return L(N);D(M)})})}function d(b){return new Promise(function(A,T){b._viewCleanup(function(D,L){if(D)return T(D);A(L)})})}function o(b){return function(A){if(A.status===404)return b;throw A}}async function a(b,A,T){let D="_local/doc_"+b,L={_id:D,keys:[]},N=T.get(b),M=N[0],P=N[1];function C(){return da(P)?Promise.resolve(L):A.db.get(D).catch(o(L))}function k(Y){return Y.keys.length?A.db.allDocs({keys:Y.keys,include_docs:!0}):Promise.resolve({rows:[]})}function I(Y,ee){let re=[],ve=new Set;for(let X of ee.rows){let H=X.doc;if(H&&(re.push(H),ve.add(H._id),H._deleted=!M.has(H._id),!H._deleted)){let Z=M.get(H._id);"value"in Z&&(H.value=Z.value)}}let xe=Bt(M);for(let X of xe)if(!ve.has(X)){let H={_id:X},Z=M.get(X);"value"in Z&&(H.value=Z.value),re.push(H)}return Y.keys=zn(xe.concat(Y.keys)),re.push(Y),re}let F=await C(),K=await k(F);return I(F,K)}function f(b){return b.sourceDB.get("_local/purges").then(function(A){let T=A.purgeSeq;return b.db.get("_local/purgeSeq").then(function(D){return D._rev}).catch(o(void 0)).then(function(D){return b.db.put({_id:"_local/purgeSeq",_rev:D,purgeSeq:T})})}).catch(function(A){if(A.status!==404)throw A})}function c(b,A,T){var D="_local/lastSeq";return b.db.get(D).catch(o({_id:D,seq:0})).then(function(L){var N=Bt(A);return Promise.all(N.map(function(M){return a(M,b,A)})).then(function(M){var P=M.flat();return L.seq=T,P.push(L),b.db.bulkDocs({docs:P})}).then(()=>f(b))})}function O(b){let A=typeof b=="string"?b:b.name,T=Xn[A];return T||(T=Xn[A]=new Ve),T}async function x(b,A){return Pt(O(b),function(){return E(b,A)})()}async function E(b,A){let T,D,L;function N(X,H){let Z={id:D._id,key:Ke(X)};typeof H<"u"&&H!==null&&(Z.value=Ke(H)),T.push(Z)}let M=t(b.mapFun,N),P=b.seq||0;function C(){return b.sourceDB.info().then(function(X){L=b.sourceDB.activeTasks.add({name:"view_indexing",total_items:X.update_seq-P})})}function k(X,H){return function(){return c(b,X,H)}}let I=0,F={view:b.name,indexed_docs:I};b.sourceDB.emit("indexing",F);let K=new Ve;async function Y(){let X=await b.sourceDB.changes({return_docs:!0,conflicts:!0,include_docs:!0,style:"all_docs",since:P,limit:A.changes_batch_size}),H=await ee();return re(X,H)}function ee(){return b.db.get("_local/purgeSeq").then(function(X){return X.purgeSeq}).catch(o(-1)).then(function(X){return b.sourceDB.get("_local/purges").then(function(H){let Z=H.purges.filter(function(ye,ce){return ce>X}).map(ye=>ye.docId),be=Z.filter(function(ye,ce){return Z.indexOf(ye)===ce});return Promise.all(be.map(function(ye){return b.sourceDB.get(ye).then(function(ce){return{docId:ye,doc:ce}}).catch(o({docId:ye}))}))}).catch(o([]))})}function re(X,H){let Z=X.results;if(!Z.length&&!H.length)return;for(let ce of H)if(Z.findIndex(function(We){return We.id===ce.docId})<0){let We={_id:ce.docId,doc:{_id:ce.docId,_deleted:1},changes:[]};ce.doc&&(We.doc=ce.doc,We.changes.push({rev:ce.doc._rev})),Z.push(We)}let be=ve(Z);K.add(k(be,P)),I=I+Z.length;let ye={view:b.name,last_seq:X.last_seq,results_count:Z.length,indexed_docs:I};if(b.sourceDB.emit("indexing",ye),b.sourceDB.activeTasks.update(L,{completed_items:I}),!(Z.length<A.changes_batch_size))return Y()}function ve(X){let H=new Map;for(let Z of X){if(Z.doc._id[0]!=="_"){T=[],D=Z.doc,D._deleted||i(b.sourceDB,M,D),T.sort(u);let be=xe(T);H.set(Z.doc._id,[be,Z.changes])}P=Z.seq}return H}function xe(X){let H=new Map,Z;for(let be=0,ye=X.length;be<ye;be++){let ce=X[be],St=[ce.key,ce.id];be>0&&ne(ce.key,Z)===0&&St.push(be),H.set(Ae(St),ce),Z=ce.key}return H}try{await C(),await Y(),await K.finish(),b.seq=P,b.sourceDB.activeTasks.remove(L)}catch(X){b.sourceDB.activeTasks.remove(L,X)}}function R(b,A,T){T.group_level===0&&delete T.group_level;let D=T.group||T.group_level,L=n(b.reduceFun),N=[],M=isNaN(T.group_level)?Number.POSITIVE_INFINITY:T.group_level;for(let P of A){let C=N[N.length-1],k=D?P.key:null;if(D&&Array.isArray(k)&&(k=k.slice(0,M)),C&&ne(C.groupKey,k)===0){C.keys.push([P.key,P.id]),C.values.push(P.value);continue}N.push({keys:[[P.key,P.id]],values:[P.value],groupKey:k})}A=[];for(let P of N){let C=s(b.sourceDB,L,P.keys,P.values,!1);if(C.error&&C.error instanceof yt)throw C.error;A.push({value:C.error?null:C.output,key:P.groupKey})}return{rows:v(A,T.limit,T.skip)}}function B(b,A){return Pt(O(b),function(){return U(b,A)})()}async function U(b,A){let T,D=b.reduceFun&&A.reduce!==!1,L=A.skip||0;typeof A.keys<"u"&&!A.keys.length&&(A.limit=0,delete A.keys);async function N(P){P.include_docs=!0;let C=await b.db.allDocs(P);return T=C.total_rows,C.rows.map(function(k){if("value"in k.doc&&typeof k.doc.value=="object"&&k.doc.value!==null){let F=Object.keys(k.doc.value).sort(),K=["id","key","value"];if(!(F<K||F>K))return k.doc.value}let I=is(k.doc._id);return{key:I[0],id:I[1],value:"value"in k.doc?k.doc.value:null}})}async function M(P){let C;if(D?C=R(b,P,A):typeof A.keys>"u"?C={total_rows:T,offset:L,rows:P}:C={total_rows:T,offset:L,rows:v(P,A.limit,A.skip)},A.update_seq&&(C.update_seq=b.seq),A.include_docs){let k=zn(P.map(_)),I=await b.sourceDB.allDocs({keys:k,include_docs:!0,conflicts:A.conflicts,attachments:A.attachments,binary:A.binary}),F=new Map;for(let K of I.rows)F.set(K.id,K.doc);for(let K of P){let Y=_(K),ee=F.get(Y);ee&&(K.doc=ee)}}return C}if(typeof A.keys<"u"){let C=A.keys.map(function(F){let K={startkey:Ae([F]),endkey:Ae([F,{}])};return A.update_seq&&(K.update_seq=!0),N(K)}),I=(await Promise.all(C)).flat();return M(I)}else{let P={descending:A.descending};A.update_seq&&(P.update_seq=!0);let C,k;if("start_key"in A&&(C=A.start_key),"startkey"in A&&(C=A.startkey),"end_key"in A&&(k=A.end_key),"endkey"in A&&(k=A.endkey),typeof C<"u"&&(P.startkey=A.descending?Ae([C,{}]):Ae([C])),typeof k<"u"){let F=A.inclusive_end!==!1;A.descending&&(F=!F),P.endkey=Ae(F?[k,{}]:[k])}if(typeof A.key<"u"){let F=Ae([A.key]),K=Ae([A.key,{}]);P.descending?(P.endkey=F,P.startkey=K):(P.startkey=F,P.endkey=K)}D||(typeof A.limit=="number"&&(P.limit=A.limit),P.skip=L);let I=await N(P);return M(I)}}async function j(b){return(await b.fetch("_view_cleanup",{headers:new Ge({"Content-Type":"application/json"}),method:"POST"})).json()}async function $(b){try{let A=await b.get("_local/"+e),T=new Map;for(let C of Object.keys(A.views)){let k=It(C),I="_design/"+k[0],F=k[1],K=T.get(I);K||(K=new Set,T.set(I,K)),K.add(F)}let D={keys:Bt(T),include_docs:!0},L=await b.allDocs(D),N={};for(let C of L.rows){let k=C.key.substring(8);for(let I of T.get(C.key)){let F=k+"/"+I;A.views[F]||(F=I);let K=Object.keys(A.views[F]),Y=C.doc&&C.doc.views&&C.doc.views[I];for(let ee of K)N[ee]=N[ee]||Y}}let P=Object.keys(N).filter(function(C){return!N[C]}).map(function(C){return Pt(O(C),function(){return new b.constructor(C,b.__opts).destroy()})()});return Promise.all(P).then(function(){return{ok:!0}})}catch(A){if(A.status===404)return{ok:!0};throw A}}async function z(b,A,T){if(typeof b._query=="function")return h(b,A,T);if(Ee(b))return p(b,A,T);let D={changes_batch_size:b.__opts.view_update_changes_batch_size||la};if(typeof A!="string")return q(T,A),Yn.add(async function(){let L=await Hn(b,"temp_view/temp_view",A.map,A.reduce,!0,e);return aa(x(L,D).then(function(){return B(L,T)}),function(){return L.db.destroy()})}),Yn.finish();{let L=A,N=It(L),M=N[0],P=N[1],C=await b.get("_design/"+M);if(A=C.views&&C.views[P],!A)throw new gt(`ddoc ${C._id} has no view named ${P}`);r(C,P),q(T,A);let k=await Hn(b,L,A.map,A.reduce,!1,e);return T.stale==="ok"||T.stale==="update_after"?(T.stale==="update_after"&&De(function(){x(k,D)}),B(k,T)):(await x(k,D),B(k,T))}}function Q(b,A,T){let D=this;typeof A=="function"&&(T=A,A={}),A=A?w(A):{},typeof b=="function"&&(b={map:b});let L=Promise.resolve().then(function(){return z(D,b,A)});return Br(L,T),L}let W=sa(function(){let b=this;return typeof b._viewCleanup=="function"?d(b):Ee(b)?j(b):$(b)});return{query:Q,viewCleanup:W}}var jt={_sum:function(e,t){return en(t)},_count:function(e,t){return t.length},_stats:function(e,t){function n(r){for(var i=0,s=0,u=r.length;s<u;s++){var v=r[s];i+=v*v}return i}return{sum:en(t),min:Math.min.apply(null,t),max:Math.max.apply(null,t),count:t.length,sumsqr:n(t)}}};function va(e){if(/^_sum/.test(e))return jt._sum;if(/^_count/.test(e))return jt._count;if(/^_stats/.test(e))return jt._stats;if(/^_/.test(e))throw new Error(e+" is not a supported reduce function.")}function _a(e,t){if(typeof e=="function"&&e.length===2){var n=e;return function(r){return n(r,t)}}else return Ir(e.toString(),t)}function ga(e){var t=e.toString(),n=va(t);return n||Ir(t)}function ya(e,t){var n=e.views&&e.views[t];if(typeof n.map!="string")throw new gt("ddoc "+e._id+" has no string view named "+t+", instead found object of type: "+typeof n.map)}var pa="mrviews",jr=ha(pa,_a,ga,ya);function ma(e,t,n){return jr.query.call(this,e,t,n)}function wa(e){return jr.viewCleanup.call(this,e)}var ba={query:ma,viewCleanup:wa};function Sa(e,t,n){return!e._attachments||!e._attachments[n]||e._attachments[n].digest!==t._attachments[n].digest}function Vn(e,t){var n=Object.keys(t._attachments);return Promise.all(n.map(function(r){return e.getAttachment(t._id,r,{rev:t._rev})}))}function Aa(e,t,n){var r=Ee(t)&&!Ee(e),i=Object.keys(n._attachments);return r?e.get(n._id).then(function(s){return Promise.all(i.map(function(u){return Sa(s,n,u)?t.getAttachment(n._id,u):e.getAttachment(s._id,u)}))}).catch(function(s){if(s.status!==404)throw s;return Vn(t,n)}):Vn(t,n)}function Oa(e){var t=[];return Object.keys(e).forEach(function(n){var r=e[n].missing;r.forEach(function(i){t.push({id:n,rev:i})})}),{docs:t,revs:!0,latest:!0}}function xa(e,t,n,r){n=fe(n);var i=[],s=!0;function u(){var _=Oa(n);if(_.docs.length)return e.bulkGet(_).then(function(g){if(r.cancelled)throw new Error("cancelled");return Promise.all(g.results.map(function(m){return Promise.all(m.docs.map(function(l){var y=l.ok;return l.error&&(s=!1),!y||!y._attachments?y:Aa(t,e,y).then(w=>{var S=Object.keys(y._attachments);return w.forEach(function(q,p){var h=y._attachments[S[p]];delete h.stub,delete h.length,h.data=q}),y})}))})).then(function(m){i=i.concat(m.flat().filter(Boolean))})})}function v(){return{ok:s,docs:i}}return Promise.resolve().then(u).then(v)}var er=1,tr="pouchdb",qa=5,Se=0;function tn(e,t,n,r,i){return e.get(t).catch(function(s){if(s.status===404)return(e.adapter==="http"||e.adapter==="https")&&Ft(404,"PouchDB is just checking if a remote checkpoint exists."),{session_id:r,_id:t,history:[],replicator:tr,version:er};throw s}).then(function(s){if(!i.cancelled&&s.last_seq!==n)return s.history=(s.history||[]).filter(function(u){return u.session_id!==r}),s.history.unshift({last_seq:n,session_id:r}),s.history=s.history.slice(0,qa),s.version=er,s.replicator=tr,s.session_id=r,s.last_seq=n,e.put(s).catch(function(u){if(u.status===409)return tn(e,t,n,r,i);throw u})})}var pt=class{constructor(t,n,r,i,s={writeSourceCheckpoint:!0,writeTargetCheckpoint:!0}){this.src=t,this.target=n,this.id=r,this.returnValue=i,this.opts=s,typeof s.writeSourceCheckpoint>"u"&&(s.writeSourceCheckpoint=!0),typeof s.writeTargetCheckpoint>"u"&&(s.writeTargetCheckpoint=!0)}writeCheckpoint(t,n){var r=this;return this.updateTarget(t,n).then(function(){return r.updateSource(t,n)})}updateTarget(t,n){return this.opts.writeTargetCheckpoint?tn(this.target,this.id,t,n,this.returnValue):Promise.resolve(!0)}updateSource(t,n){if(this.opts.writeSourceCheckpoint){var r=this;return tn(this.src,this.id,t,n,this.returnValue).catch(function(i){if(rr(i))return r.opts.writeSourceCheckpoint=!1,!0;throw i})}else return Promise.resolve(!0)}getCheckpoint(){var t=this;return!t.opts.writeSourceCheckpoint&&!t.opts.writeTargetCheckpoint?Promise.resolve(Se):t.opts&&t.opts.writeSourceCheckpoint&&!t.opts.writeTargetCheckpoint?t.src.get(t.id).then(function(n){return n.last_seq||Se}).catch(function(n){if(n.status!==404)throw n;return Se}):t.target.get(t.id).then(function(n){return t.opts&&t.opts.writeTargetCheckpoint&&!t.opts.writeSourceCheckpoint?n.last_seq||Se:t.src.get(t.id).then(function(r){if(n.version!==r.version)return Se;var i;return n.version?i=n.version.toString():i="undefined",i in nr?nr[i](n,r):Se},function(r){if(r.status===404&&n.last_seq)return t.src.put({_id:t.id,last_seq:Se}).then(function(){return Se},function(i){return rr(i)?(t.opts.writeSourceCheckpoint=!1,n.last_seq):Se});throw r})}).catch(function(n){if(n.status!==404)throw n;return Se})}},nr={undefined:function(e,t){return ne(e.last_seq,t.last_seq)===0?t.last_seq:0},1:function(e,t){return Ca(t,e).last_seq}};function Ca(e,t){return e.session_id===t.session_id?{last_seq:e.last_seq,history:e.history}:Nr(e.history,t.history)}function Nr(e,t){var n=e[0],r=e.slice(1),i=t[0],s=t.slice(1);if(!n||t.length===0)return{last_seq:Se,history:[]};var u=n.session_id;if(nn(u,t))return{last_seq:n.last_seq,history:e};var v=i.session_id;return nn(v,r)?{last_seq:i.last_seq,history:s}:Nr(r,s)}function nn(e,t){var n=t[0],r=t.slice(1);return!e||t.length===0?!1:e===n.session_id?!0:nn(e,r)}function rr(e){return typeof e.status=="number"&&Math.floor(e.status/100)===4}function $r(e,t,n,r,i){return this instanceof pt?$r:new pt(e,t,n,r,i)}var ir=0;function Ea(e,t,n,r){if(e.retry===!1){t.emit("error",n),t.removeAllListeners();return}if(typeof e.back_off_function!="function"&&(e.back_off_function=ei),t.emit("requestError",n),t.state==="active"||t.state==="pending"){t.emit("paused",n),t.state="stopped";var i=function(){e.current_back_off=ir},s=function(){t.removeListener("active",i)};t.once("paused",s),t.once("active",i)}e.current_back_off=e.current_back_off||ir,e.current_back_off=e.back_off_function(e.current_back_off),setTimeout(r,e.current_back_off)}function Da(e){return Object.keys(e).sort(ne).reduce(function(t,n){return t[n]=e[n],t},{})}function ka(e,t,n){var r=n.doc_ids?n.doc_ids.sort(ne):"",i=n.filter?n.filter.toString():"",s="",u="",v="";return n.selector&&(v=JSON.stringify(n.selector)),n.filter&&n.query_params&&(s=JSON.stringify(Da(n.query_params))),n.filter&&n.filter==="_view"&&(u=n.view.toString()),Promise.all([e.id(),t.id()]).then(function(_){var g=_[0]+_[1]+i+u+s+r+v;return new Promise(function(m){yn(g,m)})}).then(function(_){return _=_.replace(/\//g,".").replace(/\+/g,"_"),"_local/"+_})}function Fr(e,t,n,r,i){var s=[],u,v={seq:0,changes:[],docs:[]},_=!1,g=!1,m=!1,l=0,y=0,w=n.continuous||n.live||!1,S=n.batch_size||100,q=n.batches_limit||10,p=n.style||"all_docs",h=!1,d=n.doc_ids,o=n.selector,a,f,c=[],O=bt(),x;i=i||{ok:!0,start_time:new Date().toISOString(),docs_read:0,docs_written:0,doc_write_failures:0,errors:[]};var E={};r.ready(e,t);function R(){return f?Promise.resolve():ka(e,t,n).then(function(C){a=C;var k={};n.checkpoint===!1?k={writeSourceCheckpoint:!1,writeTargetCheckpoint:!1}:n.checkpoint==="source"?k={writeSourceCheckpoint:!0,writeTargetCheckpoint:!1}:n.checkpoint==="target"?k={writeSourceCheckpoint:!1,writeTargetCheckpoint:!0}:k={writeSourceCheckpoint:!0,writeTargetCheckpoint:!0},f=new $r(e,t,a,r,k)})}function B(){if(c=[],u.docs.length!==0){var C=u.docs,k={timeout:n.timeout};return t.bulkDocs({docs:C,new_edits:!1},k).then(function(I){if(r.cancelled)throw b(),new Error("cancelled");var F=Object.create(null);I.forEach(function(Y){Y.error&&(F[Y.id]=Y)});var K=Object.keys(F).length;i.doc_write_failures+=K,i.docs_written+=C.length-K,C.forEach(function(Y){var ee=F[Y._id];if(ee){i.errors.push(ee);var re=(ee.name||"").toLowerCase();if(re==="unauthorized"||re==="forbidden")r.emit("denied",fe(ee));else throw ee}else c.push(Y)})},function(I){throw i.doc_write_failures+=C.length,I})}}function U(){if(u.error)throw new Error("There was a problem getting docs.");i.last_seq=y=u.seq;var C=fe(i);return c.length&&(C.docs=c,typeof u.pending=="number"&&(C.pending=u.pending,delete u.pending),r.emit("change",C)),_=!0,e.info().then(function(k){var I=e.activeTasks.get(x);if(!(!u||!I)){var F=I.completed_items||0,K=parseInt(k.update_seq,10)-parseInt(l,10);e.activeTasks.update(x,{completed_items:F+u.changes.length,total_items:K})}}),f.writeCheckpoint(u.seq,O).then(function(){if(r.emit("checkpoint",{checkpoint:u.seq}),_=!1,r.cancelled)throw b(),new Error("cancelled");u=void 0,L()}).catch(function(k){throw P(k),k})}function j(){var C={};return u.changes.forEach(function(k){r.emit("checkpoint",{revs_diff:k}),k.id!=="_user/"&&(C[k.id]=k.changes.map(function(I){return I.rev}))}),t.revsDiff(C).then(function(k){if(r.cancelled)throw b(),new Error("cancelled");u.diffs=k})}function $(){return xa(e,t,u.diffs,r).then(function(C){u.error=!C.ok,C.docs.forEach(function(k){delete u.diffs[k._id],i.docs_read++,u.docs.push(k)})})}function z(){if(!(r.cancelled||u)){if(s.length===0){Q(!0);return}u=s.shift(),r.emit("checkpoint",{start_next_batch:u.seq}),j().then($).then(B).then(U).then(z).catch(function(C){W("batch processing terminated with error",C)})}}function Q(C){if(v.changes.length===0){s.length===0&&!u&&((w&&E.live||g)&&(r.state="pending",r.emit("paused")),g&&b());return}(C||g||v.changes.length>=S)&&(s.push(v),v={seq:0,changes:[],docs:[]},(r.state==="pending"||r.state==="stopped")&&(r.state="active",r.emit("active")),z())}function W(C,k){m||(k.message||(k.message=C),i.ok=!1,i.status="aborting",s=[],v={seq:0,changes:[],docs:[]},b(k))}function b(C){if(!m&&!(r.cancelled&&(i.status="cancelled",_)))if(i.status=i.status||"complete",i.end_time=new Date().toISOString(),i.last_seq=y,m=!0,e.activeTasks.remove(x,C),C){C=G(C),C.result=i;var k=(C.name||"").toLowerCase();k==="unauthorized"||k==="forbidden"?(r.emit("error",C),r.removeAllListeners()):Ea(n,r,C,function(){Fr(e,t,n,r)})}else r.emit("complete",i),r.removeAllListeners()}function A(C,k,I){if(r.cancelled)return b();typeof k=="number"&&(v.pending=k);var F=cn(n)(C);if(!F){var K=e.activeTasks.get(x);if(K){var Y=K.completed_items||0;e.activeTasks.update(x,{completed_items:++Y})}return}v.seq=C.seq||I,v.changes.push(C),r.emit("checkpoint",{pending_batch:v.seq}),De(function(){Q(s.length===0&&E.live)})}function T(C){if(h=!1,r.cancelled)return b();if(C.results.length>0)E.since=C.results[C.results.length-1].seq,L(),Q(!0);else{var k=function(){w?(E.live=!0,L()):g=!0,Q(!0)};!u&&C.results.length===0?(_=!0,f.writeCheckpoint(C.last_seq,O).then(function(){if(_=!1,i.last_seq=y=C.last_seq,r.cancelled)throw b(),new Error("cancelled");k()}).catch(P)):k()}}function D(C){if(h=!1,r.cancelled)return b();W("changes rejected",C)}function L(){if(!(!h&&!g&&s.length<q))return;h=!0;function C(){I.cancel()}function k(){r.removeListener("cancel",C)}r._changes&&(r.removeListener("cancel",r._abortChanges),r._changes.cancel()),r.once("cancel",C);var I=e.changes(E).on("change",A);I.then(k,k),I.then(T).catch(D),n.retry&&(r._changes=I,r._abortChanges=C)}function N(C){return e.info().then(function(k){var I=typeof n.since>"u"?parseInt(k.update_seq,10)-parseInt(C,10):parseInt(k.update_seq,10);return x=e.activeTasks.add({name:`${w?"continuous ":""}replication from ${k.db_name}`,total_items:I}),C})}function M(){R().then(function(){if(r.cancelled){b();return}return f.getCheckpoint().then(N).then(function(C){y=C,l=C,E={since:y,limit:S,batch_size:S,style:p,doc_ids:d,selector:o,return_docs:!0},n.filter&&(typeof n.filter!="string"?E.include_docs=!0:E.filter=n.filter),"heartbeat"in n&&(E.heartbeat=n.heartbeat),"timeout"in n&&(E.timeout=n.timeout),n.query_params&&(E.query_params=n.query_params),n.view&&(E.view=n.view),L()})}).catch(function(C){W("getCheckpoint rejected with ",C)})}function P(C){_=!1,W("writeCheckpoint completed with error",C)}if(r.cancelled){b();return}r._addedListeners||(r.once("cancel",b),typeof n.complete=="function"&&(r.once("error",n.complete),r.once("complete",function(C){n.complete(null,C)})),r._addedListeners=!0),typeof n.since>"u"?M():R().then(function(){return _=!0,f.writeCheckpoint(n.since,O)}).then(function(){if(_=!1,r.cancelled){b();return}y=n.since,M()}).catch(P)}var rn=class extends ge{constructor(){super(),this.cancelled=!1,this.state="pending";let t=new Promise((n,r)=>{this.once("complete",n),this.once("error",r)});this.then=function(n,r){return t.then(n,r)},this.catch=function(n){return t.catch(n)},this.catch(function(){})}cancel(){this.cancelled=!0,this.state="cancelled",this.emit("cancel")}ready(t,n){if(this._readyCalled)return;this._readyCalled=!0;let r=()=>{this.cancel()};t.once("destroyed",r),n.once("destroyed",r);function i(){t.removeListener("destroyed",r),n.removeListener("destroyed",r)}this.once("complete",i),this.once("error",i)}};function mt(e,t){var n=t.PouchConstructor;return typeof e=="string"?new n(e,t):e}function sn(e,t,n,r){if(typeof n=="function"&&(r=n,n={}),typeof n>"u"&&(n={}),n.doc_ids&&!Array.isArray(n.doc_ids))throw G(wt,"`doc_ids` filter parameter is not a list.");n.complete=r,n=fe(n),n.continuous=n.continuous||n.live,n.retry="retry"in n?n.retry:!1,n.PouchConstructor=n.PouchConstructor||this;var i=new rn(n),s=mt(e,n),u=mt(t,n);return Fr(s,u,n,i),i}function Ta(e,t,n,r){return typeof n=="function"&&(r=n,n={}),typeof n>"u"&&(n={}),n=fe(n),n.PouchConstructor=n.PouchConstructor||this,e=mt(e,n),t=mt(t,n),new an(e,t,n,r)}var an=class extends ge{constructor(t,n,r,i){super(),this.canceled=!1;let s=r.push?Object.assign({},r,r.push):r,u=r.pull?Object.assign({},r,r.pull):r;this.push=sn(t,n,s),this.pull=sn(n,t,u),this.pushPaused=!0,this.pullPaused=!0;let v=o=>{this.emit("change",{direction:"pull",change:o})},_=o=>{this.emit("change",{direction:"push",change:o})},g=o=>{this.emit("denied",{direction:"push",doc:o})},m=o=>{this.emit("denied",{direction:"pull",doc:o})},l=()=>{this.pushPaused=!0,this.pullPaused&&this.emit("paused")},y=()=>{this.pullPaused=!0,this.pushPaused&&this.emit("paused")},w=()=>{this.pushPaused=!1,this.pullPaused&&this.emit("active",{direction:"push"})},S=()=>{this.pullPaused=!1,this.pushPaused&&this.emit("active",{direction:"pull"})},q={},p=o=>(a,f)=>{(a==="change"&&(f===v||f===_)||a==="denied"&&(f===m||f===g)||a==="paused"&&(f===y||f===l)||a==="active"&&(f===S||f===w))&&(a in q||(q[a]={}),q[a][o]=!0,Object.keys(q[a]).length===2&&this.removeAllListeners(a))};r.live&&(this.push.on("complete",this.pull.cancel.bind(this.pull)),this.pull.on("complete",this.push.cancel.bind(this.push)));function h(o,a,f){o.listeners(a).indexOf(f)==-1&&o.on(a,f)}this.on("newListener",function(o){o==="change"?(h(this.pull,"change",v),h(this.push,"change",_)):o==="denied"?(h(this.pull,"denied",m),h(this.push,"denied",g)):o==="active"?(h(this.pull,"active",S),h(this.push,"active",w)):o==="paused"&&(h(this.pull,"paused",y),h(this.push,"paused",l))}),this.on("removeListener",function(o){o==="change"?(this.pull.removeListener("change",v),this.push.removeListener("change",_)):o==="denied"?(this.pull.removeListener("denied",m),this.push.removeListener("denied",g)):o==="active"?(this.pull.removeListener("active",S),this.push.removeListener("active",w)):o==="paused"&&(this.pull.removeListener("paused",y),this.push.removeListener("paused",l))}),this.pull.on("removeListener",p("pull")),this.push.on("removeListener",p("push"));let d=Promise.all([this.push,this.pull]).then(o=>{let a={push:o[0],pull:o[1]};return this.emit("complete",a),i&&i(null,a),this.removeAllListeners(),a},o=>{if(this.cancel(),i?i(o):this.emit("error",o),this.removeAllListeners(),i)throw o});this.then=function(o,a){return d.then(o,a)},this.catch=function(o){return d.catch(o)}}cancel(){this.canceled||(this.canceled=!0,this.push.cancel(),this.pull.cancel())}};function Ra(e){e.replicate=sn,e.sync=Ta,Object.defineProperty(e.prototype,"replicate",{get:function(){var t=this;return typeof this.replicateMethods>"u"&&(this.replicateMethods={from:function(n,r,i){return t.constructor.replicate(n,t,r,i)},to:function(n,r,i){return t.constructor.replicate(t,n,r,i)}}),this.replicateMethods}}),e.prototype.sync=function(t,n,r){return this.constructor.sync(this,t,n,r)}}J.plugin(Xs).plugin(ia).plugin(ba).plugin(Ra);var jo=J;export{jo as default};
8
- //# sourceMappingURL=index-browser.es-G37SKL53.js.map
8
+ //# sourceMappingURL=index-browser.es-UXYPGJ2M.js.map