UNPKG

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