pouchdb-live-find
Version:
Live PouchDB queries that update automatically as changes come in!
2 lines • 34.4 kB
JavaScript
!function e(t,n,r){function o(s,u){if(!n[s]){if(!t[s]){var c="function"==typeof require&&require;if(!u&&c)return c(s,!0);if(i)return i(s,!0);var a=new Error("Cannot find module '"+s+"'");throw a.code="MODULE_NOT_FOUND",a}var f=n[s]={exports:{}};t[s][0].call(f.exports,function(e){var n=t[s][1][e];return o(n||e)},f,f.exports,e,t,n,r)}return n[s].exports}for(var i="function"==typeof require&&require,s=0;s<r.length;s++)o(r[s]);return o}({1:[function(e,t,n){"use strict";function r(e,t){for(var n=e,r=0,o=t.length;r<o;r++){if(!(n=n[t[r]]))break}return n}var o=e("pouchdb-collate").collate,i=e("pouchdb-selector-core"),s=i.filterInMemoryFields,u=e("./utils"),c=i.compare,a=u.getUserFields,f=i.getKey,l=i.getValue,h=i.parseField;n.memoryFilter=function(e,t){var n=a(t.selector,t.sort),r=n.fields,o=e.map(function(e){return{doc:e}});return s(o,t,r).map(function(e){return e.doc})},n.createFieldSorter=function(e){function t(t){return e.map(function(e){var n=f(e),o=h(n);return r(t,o)})}var n=e.map(function(e){return"string"!=typeof e&&"desc"===l(e)?-1:1});return function(e,r){for(var i=t(e),s=t(r),u=0,a=n.length;u<a;u++){var f=o(i[u],s[u]);if(0!==f)return f*n[u]}return c(e._id,r._id)*n[0]}}},{"./utils":3,"pouchdb-collate":9,"pouchdb-selector-core":13}],2:[function(e,t,n){"use strict";function r(e){function t(e){R.then(function(){e.doc&&h(e.doc)})}function n(e){E.emit("error",e)}function r(){b||(_._activeQueries--,_._activeQueries?(_._changeListener.removeListener("change",t),_._changeListener.removeListener("error",n)):(_._changeListener.cancel(),delete _._changeListener),E.emit("cancelled"),E.removeAllListeners(),b=!0)}function s(e){var t=i.memoryFilter([e],{selector:A});return t.length?t[0]:null}function f(e){if(j){var t=u.pick(e,j);return S&&delete t._id,L&&delete t._rev,t}return e}function l(e){w[e._id]=e._rev;var t=e._id,n=e._rev;return S&&delete e._id,L&&delete e._rev,p(e,t,n)}function h(e){if(w[e._id]!==e._rev){var t=e._id,n=e._rev;if(e._deleted&&w[t])return w[t]=null,d({_id:t,_rev:n,deleted:!0},t,n);var r=s(e);return!r&&w[t]?(w[t]=null,d({_id:t,_rev:n},t,n)):r&&!w[t]?(w[t]=n,p(f(r),t,n)):r&&w[t]?(w[t]=n,v(f(r),t,n)):void 0}}function d(e,t,n){var r;O&&($=$.filter(function(t){return t._id!==e._id}),r=g($)),E.emit("update",{action:"REMOVE",id:t,rev:n,doc:e},r)}function p(e,t,n){var r;O&&($=$.concat(e),r=g($)),E.emit("update",{action:"ADD",id:t,rev:n,doc:e},r)}function v(e,t,n){var r;O&&($=$.map(function(t){return t._id===e._id?e:t}),r=g($)),E.emit("update",{action:"UPDATE",id:t,rev:n,doc:e},r)}function y(e){return e.sort(k)}function g(e){return I&&(e=y(e)),(x||D)&&(e=D?e.slice(x,x+D):e.slice(x)),e}function m(e){if(O&&e&&"object"==typeof e)return null!=e.skip&&(x=parseInt(e.skip,10)||0),null!=e.limit&&(D=parseInt(e.limit,10)||0),e.sort&&e.sort instanceof Array&&(I=a(e.sort),k=i.createFieldSorter(I)),g($)}if("function"!=typeof this.find)throw new Error("ERROR: PouchDB Find is a requirement for LiveFind and must be loaded first.");var _=this,b=!1,w={},E=new o,$=[],O=e.aggregate||!1,j=e.fields,S=!1,L=!1;j&&(-1===j.indexOf("_id")&&(j.unshift("_id"),S=!0),-1===j.indexOf("_rev")&&(j.push("_rev"),L=!0));var A;e.selector&&(A=c(e.selector));var I,k;e.sort&&(I=a(e.sort),k=i.createFieldSorter(I));var x=parseInt(e.skip,10)||0,D=parseInt(e.limit,10)||0,F={selector:A,fields:j},R=_.find(F).then(function(e){e.docs.forEach(function(e){l(e)}),E.emit("ready")}).catch(function(e){throw E.emit("error",e),r(),e});return _._changeListener||function(){_._changeListener=_.changes({live:!0,retry:!0,include_docs:!0,since:"now"})}(),_._activeQueries?_._activeQueries++:_._activeQueries=1,_._changeListener.on("change",t).on("error",n),E.cancel=r,E.then=R.then.bind(R),E.catch=R.catch.bind(R),E.sort=function(e){return I?y(e):e},E.paginate=m,E}var o=e("events"),i=e("./helpers"),s=(e("pouchdb-collate").collate,e("pouchdb-selector-core")),u=e("./utils"),c=(s.getValue,s.massageSelector),a=u.massageSort;n.liveFind=r,"undefined"!=typeof window&&window.PouchDB&&window.PouchDB.plugin(n)},{"./helpers":1,"./utils":3,events:5,"pouchdb-collate":9,"pouchdb-selector-core":13}],3:[function(e,t,n){"use strict";var r=e("pouchdb-selector-core"),o=r.getKey,i=r.getFieldFromDoc,s=r.setFieldInDoc,u=r.parseField;n.getUserFields=function(e,t){var n,r=Object.keys(e),i=t?t.map(o):[];return n=r.length>=i.length?r:i,0===i.length?{fields:n}:(n=n.sort(function(e,t){var n=i.indexOf(e);-1===n&&(n=Number.MAX_VALUE);var r=i.indexOf(t);return-1===r&&(r=Number.MAX_VALUE),n<r?-1:n>r?1:0}),{fields:n,sortOrder:t.map(o)})},n.massageSort=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})},n.pick=function(e,t){for(var n={},r=0,o=t.length;r<o;r++){var c=u(t[r]),a=i(e,c);void 0!==a&&s(n,c,a)}return n}},{"pouchdb-selector-core":13}],4:[function(e,t,n){"use strict";function r(e){return function(){var t=arguments.length;if(t){for(var n=[],r=-1;++r<t;)n[r]=arguments[r];return e.call(this,n)}return e.call(this,[])}}t.exports=r},{}],5:[function(e,t,n){function r(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function o(e){return"function"==typeof e}function i(e){return"number"==typeof e}function s(e){return"object"==typeof e&&null!==e}function u(e){return void 0===e}t.exports=r,r.EventEmitter=r,r.prototype._events=void 0,r.prototype._maxListeners=void 0,r.defaultMaxListeners=10,r.prototype.setMaxListeners=function(e){if(!i(e)||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},r.prototype.emit=function(e){var t,n,r,i,c,a;if(this._events||(this._events={}),"error"===e&&(!this._events.error||s(this._events.error)&&!this._events.error.length)){if((t=arguments[1])instanceof Error)throw t;var f=new Error('Uncaught, unspecified "error" event. ('+t+")");throw f.context=t,f}if(n=this._events[e],u(n))return!1;if(o(n))switch(arguments.length){case 1:n.call(this);break;case 2:n.call(this,arguments[1]);break;case 3:n.call(this,arguments[1],arguments[2]);break;default:i=Array.prototype.slice.call(arguments,1),n.apply(this,i)}else if(s(n))for(i=Array.prototype.slice.call(arguments,1),a=n.slice(),r=a.length,c=0;c<r;c++)a[c].apply(this,i);return!0},r.prototype.addListener=function(e,t){var n;if(!o(t))throw TypeError("listener must be a function");return this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,o(t.listener)?t.listener:t),this._events[e]?s(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,s(this._events[e])&&!this._events[e].warned&&(n=u(this._maxListeners)?r.defaultMaxListeners:this._maxListeners)&&n>0&&this._events[e].length>n&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace&&console.trace()),this},r.prototype.on=r.prototype.addListener,r.prototype.once=function(e,t){function n(){this.removeListener(e,n),r||(r=!0,t.apply(this,arguments))}if(!o(t))throw TypeError("listener must be a function");var r=!1;return n.listener=t,this.on(e,n),this},r.prototype.removeListener=function(e,t){var n,r,i,u;if(!o(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(n=this._events[e],i=n.length,r=-1,n===t||o(n.listener)&&n.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(s(n)){for(u=i;u-- >0;)if(n[u]===t||n[u].listener&&n[u].listener===t){r=u;break}if(r<0)return this;1===n.length?(n.length=0,delete this._events[e]):n.splice(r,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},r.prototype.removeAllListeners=function(e){var t,n;if(!this._events)return this;if(!this._events.removeListener)return 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e],this;if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);return this.removeAllListeners("removeListener"),this._events={},this}if(n=this._events[e],o(n))this.removeListener(e,n);else if(n)for(;n.length;)this.removeListener(e,n[n.length-1]);return delete this._events[e],this},r.prototype.listeners=function(e){return this._events&&this._events[e]?o(this._events[e])?[this._events[e]]:this._events[e].slice():[]},r.prototype.listenerCount=function(e){if(this._events){var t=this._events[e];if(o(t))return 1;if(t)return t.length}return 0},r.listenerCount=function(e,t){return e.listenerCount(t)}},{}],6:[function(e,t,n){(function(e){"use strict";function n(){f=!0;for(var e,t,n=l.length;n;){for(t=l,l=[],e=-1;++e<n;)t[e]();n=l.length}f=!1}function r(e){1!==l.push(e)||f||o()}var o,i=e.MutationObserver||e.WebKitMutationObserver;if(i){var s=0,u=new i(n),c=e.document.createTextNode("");u.observe(c,{characterData:!0}),o=function(){c.data=s=++s%2}}else if(e.setImmediate||void 0===e.MessageChannel)o="document"in e&&"onreadystatechange"in e.document.createElement("script")?function(){var t=e.document.createElement("script");t.onreadystatechange=function(){n(),t.onreadystatechange=null,t.parentNode.removeChild(t),t=null},e.document.documentElement.appendChild(t)}:function(){setTimeout(n,0)};else{var a=new e.MessageChannel;a.port1.onmessage=n,o=function(){a.port2.postMessage(0)}}var f,l=[];t.exports=r}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],7:[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}},{}],8:[function(e,t,n){"use strict";function r(){}function o(e){if("function"!=typeof e)throw new TypeError("resolver must be a function");this.state=m,this.queue=[],this.outcome=void 0,e!==r&&c(this,e)}function i(e,t,n){this.promise=e,"function"==typeof t&&(this.onFulfilled=t,this.callFulfilled=this.otherCallFulfilled),"function"==typeof n&&(this.onRejected=n,this.callRejected=this.otherCallRejected)}function s(e,t,n){p(function(){var r;try{r=t(n)}catch(t){return v.reject(e,t)}r===e?v.reject(e,new TypeError("Cannot resolve promise with itself")):v.resolve(e,r)})}function u(e){var t=e&&e.then;if(e&&("object"==typeof e||"function"==typeof e)&&"function"==typeof t)return function(){t.apply(e,arguments)}}function c(e,t){function n(t){i||(i=!0,v.reject(e,t))}function r(t){i||(i=!0,v.resolve(e,t))}function o(){t(r,n)}var i=!1,s=a(o);"error"===s.status&&n(s.value)}function a(e,t){var n={};try{n.value=e(t),n.status="success"}catch(e){n.status="error",n.value=e}return n}function f(e){return e instanceof this?e:v.resolve(new this(r),e)}function l(e){var t=new this(r);return v.reject(t,e)}function h(e){var t=this;if("[object Array]"!==Object.prototype.toString.call(e))return this.reject(new TypeError("must be an array"));var n=e.length,o=!1;if(!n)return this.resolve([]);for(var i=new Array(n),s=0,u=-1,c=new this(r);++u<n;)!function(e,r){function u(e){i[r]=e,++s!==n||o||(o=!0,v.resolve(c,i))}t.resolve(e).then(u,function(e){o||(o=!0,v.reject(c,e))})}(e[u],u);return c}function d(e){var t=this;if("[object Array]"!==Object.prototype.toString.call(e))return this.reject(new TypeError("must be an array"));var n=e.length,o=!1;if(!n)return this.resolve([]);for(var i=-1,s=new this(r);++i<n;)!function(e){t.resolve(e).then(function(e){o||(o=!0,v.resolve(s,e))},function(e){o||(o=!0,v.reject(s,e))})}(e[i]);return s}var p=e("immediate"),v={},y=["REJECTED"],g=["FULFILLED"],m=["PENDING"];t.exports=o,o.prototype.catch=function(e){return this.then(null,e)},o.prototype.then=function(e,t){if("function"!=typeof e&&this.state===g||"function"!=typeof t&&this.state===y)return this;var n=new this.constructor(r);if(this.state!==m){s(n,this.state===g?e:t,this.outcome)}else this.queue.push(new i(n,e,t));return n},i.prototype.callFulfilled=function(e){v.resolve(this.promise,e)},i.prototype.otherCallFulfilled=function(e){s(this.promise,this.onFulfilled,e)},i.prototype.callRejected=function(e){v.reject(this.promise,e)},i.prototype.otherCallRejected=function(e){s(this.promise,this.onRejected,e)},v.resolve=function(e,t){var n=a(u,t);if("error"===n.status)return v.reject(e,n.value);var r=n.value;if(r)c(e,r);else{e.state=g,e.outcome=t;for(var o=-1,i=e.queue.length;++o<i;)e.queue[o].callFulfilled(t)}return e},v.reject=function(e,t){e.state=y,e.outcome=t;for(var n=-1,r=e.queue.length;++n<r;)e.queue[n].callRejected(t);return e},o.resolve=f,o.reject=l,o.all=h,o.race=d},{immediate:6}],9:[function(e,t,n){"use strict";function r(e,t,n){for(var r="",o=n-e.length;r.length<o;)r+=t;return r}function o(e,t,n){return r(e,t,n)+e}function i(e,t){if(e===t)return 0;e=s(e),t=s(t);var n=v(e),r=v(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 d(e,t)}return Array.isArray(e)?h(e,t):p(e,t)}function s(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]=s(t[r])}else{if(e instanceof Date)return e.toJSON();if(null!==e){e={};for(var o in t)if(t.hasOwnProperty(o)){var i=t[o];void 0!==i&&(e[o]=s(i))}}}}return e}function u(e){if(null!==e)switch(typeof e){case"boolean":return e?1:0;case"number":return y(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,o=n.length,i="";if(t)for(;++r<o;)i+=c(n[r]);else for(;++r<o;){var s=n[r];i+=c(s)+c(e[s])}return i}return""}function c(e){return e=s(e),v(e)+_+u(e)+"\0"}function a(e,t){var n,r=t;if("1"===e[t])n=0,t++;else{var o="0"===e[t];t++;var i="",s=e.substring(t,t+m),u=parseInt(s,10)+g;for(o&&(u=-u),t+=m;;){var c=e[t];if("\0"===c)break;i+=c,t++}i=i.split("."),n=1===i.length?parseInt(i,10):parseFloat(i[0]+"."+i[1]),o&&(n-=10),0!==u&&(n=parseFloat(n+"e"+u))}return{num:n,length:t-r}}function f(e,t){var n=e.pop();if(t.length){var r=t[t.length-1];n===r.element&&(t.pop(),r=t[t.length-1]);var o=r.element,i=r.index;if(Array.isArray(o))o.push(n);else if(i===e.length-2){var s=e.pop();o[s]=n}else e.push(n)}}function l(e){for(var t=[],n=[],r=0;;){var o=e[r++];if("\0"!==o)switch(o){case"1":t.push(null);break;case"2":t.push("1"===e[r]),r++;break;case"3":var i=a(e,r);t.push(i.num),r+=i.length;break;case"4":for(var s="";;){var u=e[r];if("\0"===u)break;s+=u,r++}s=s.replace(/\u0001\u0001/g,"\0").replace(/\u0001\u0002/g,"").replace(/\u0002\u0002/g,""),t.push(s);break;case"5":var c={element:[],index:t.length};t.push(c.element),n.push(c);break;case"6":var l={element:{},index:t.length};t.push(l.element),n.push(l);break;default:throw new Error("bad collationIndex or unexpectedly reached end of input: "+o)}else{if(1===t.length)return t.pop();f(t,n)}}}function h(e,t){for(var n=Math.min(e.length,t.length),r=0;r<n;r++){var o=i(e[r],t[r]);if(0!==o)return o}return e.length===t.length?0:e.length>t.length?1:-1}function d(e,t){return e===t?0:e>t?1:-1}function p(e,t){for(var n=Object.keys(e),r=Object.keys(t),o=Math.min(n.length,r.length),s=0;s<o;s++){var u=i(n[s],r[s]);if(0!==u)return u;if(0!==(u=i(e[n[s]],t[r[s]])))return u}return n.length===r.length?0:n.length>r.length?1:-1}function v(e){var t=["boolean","number","string","object"],n=t.indexOf(typeof e);return~n?null===e?1:Array.isArray(e)?5:n<3?n+2:n+3:Array.isArray(e)?5:void 0}function y(e){if(0===e)return"1";var t=e.toExponential().split(/e\+?/),n=parseInt(t[1],10),r=e<0,i=r?"0":"2",s=(r?-n:n)-g,u=o(s.toString(),"0",m);i+=_+u;var c=Math.abs(parseFloat(t[0]));r&&(c=10-c);var a=c.toFixed(20);return a=a.replace(/\.?0+$/,""),i+=_+a}Object.defineProperty(n,"__esModule",{value:!0});var g=-324,m=3,_="";n.collate=i,n.normalizeKey=s,n.toIndexableString=c,n.parseIndexableString=l},{}],10:[function(e,t,n){"use strict";function r(e){return"$"+e}function o(e){return e.substring(1)}function i(){this._store={}}function s(e){if(this._store=new i,e&&Array.isArray(e))for(var t=0,n=e.length;t<n;t++)this.add(e[t])}Object.defineProperty(n,"__esModule",{value:!0}),i.prototype.get=function(e){var t=r(e);return this._store[t]},i.prototype.set=function(e,t){var n=r(e);return this._store[n]=t,!0},i.prototype.has=function(e){return r(e)in this._store},i.prototype.delete=function(e){var t=r(e),n=t in this._store;return delete this._store[t],n},i.prototype.forEach=function(e){for(var t=Object.keys(this._store),n=0,r=t.length;n<r;n++){var i=t[n],s=this._store[i];i=o(i),e(s,i)}},Object.defineProperty(i.prototype,"size",{get:function(){return Object.keys(this._store).length}}),s.prototype.add=function(e){return this._store.set(e,!0)},s.prototype.has=function(e){return this._store.has(e)},s.prototype.forEach=function(e){this._store.forEach(function(t,n){e(n)})},Object.defineProperty(s.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}()?(n.Set=s,n.Map=i):(n.Set=Set,n.Map=Map)},{}],11:[function(e,t,n){"use strict";function r(e,t,n){Error.call(this,n),this.status=e,this.name=t,this.message=n,this.error=!0}function o(e,t){function n(t){for(var n in e)"function"!=typeof e[n]&&(this[n]=e[n]);void 0!==t&&(this.reason=t)}return n.prototype=r.prototype,new n(t)}function i(e){if("object"!=typeof e){var t=e;e=p,e.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}Object.defineProperty(n,"__esModule",{value:!0}),function(e){return e&&"object"==typeof e&&"default"in e?e.default:e}(e("inherits"))(r,Error),r.prototype.toString=function(){return JSON.stringify({status:this.status,name:this.name,message:this.message,reason:this.reason})};var s=new r(401,"unauthorized","Name or password is incorrect."),u=new r(400,"bad_request","Missing JSON list of 'docs'"),c=new r(404,"not_found","missing"),a=new r(409,"conflict","Document update conflict"),f=new r(400,"bad_request","_id field must contain a string"),l=new r(412,"missing_id","_id is required for puts"),h=new r(400,"bad_request","Only reserved document ids may start with underscore."),d=new r(412,"precondition_failed","Database not open"),p=new r(500,"unknown_error","Database encountered an unknown error"),v=new r(500,"badarg","Some query argument is invalid"),y=new r(400,"invalid_request","Request was invalid"),g=new r(400,"query_parse_error","Some query parameter is invalid"),m=new r(500,"doc_validation","Bad special document member"),_=new r(400,"bad_request","Something wrong with the request"),b=new r(400,"bad_request","Document must be a JSON object"),w=new r(404,"not_found","Database not found"),E=new r(500,"indexed_db_went_bad","unknown"),$=new r(500,"web_sql_went_bad","unknown"),O=new r(500,"levelDB_went_went_bad","unknown"),j=new r(403,"forbidden","Forbidden by design doc validate_doc_update function"),S=new r(400,"bad_request","Invalid rev format"),L=new r(412,"file_exists","The database could not be created, the file already exists."),A=new r(412,"missing_stub","A pre-existing attachment stub wasn't found"),I=new r(413,"invalid_url","Provided URL is invalid");n.UNAUTHORIZED=s,n.MISSING_BULK_DOCS=u,n.MISSING_DOC=c,n.REV_CONFLICT=a,n.INVALID_ID=f,n.MISSING_ID=l,n.RESERVED_ID=h,n.NOT_OPEN=d,n.UNKNOWN_ERROR=p,n.BAD_ARG=v,n.INVALID_REQUEST=y,n.QUERY_PARSE_ERROR=g,n.DOC_VALIDATION=m,n.BAD_REQUEST=_,n.NOT_AN_OBJECT=b,n.DB_MISSING=w,n.WSQ_ERROR=$,n.LDB_ERROR=O,n.FORBIDDEN=j,n.INVALID_REV=S,n.FILE_EXISTS=L,n.MISSING_STUB=A,n.IDB_ERROR=E,n.INVALID_URL=I,n.createError=o,n.generateErrorFromResponse=i},{inherits:7}],12:[function(e,t,n){"use strict";var r=function(e){return e&&"object"==typeof e&&"default"in e?e.default:e}(e("lie")),o="function"==typeof Promise?Promise:r;t.exports=o},{lie:8}],13:[function(e,t,n){"use strict";function r(e,t){for(var n=e,r=0,o=t.length;r<o;r++){if(!(n=n[t[r]]))break}return n}function o(e,t,n){for(var r=0,o=t.length;r<o-1;r++){e=e[t[r]]={}}e[t[o-1]]=n}function i(e,t){return e<t?-1:e>t?1:0}function s(e){for(var t=[],n="",r=0,o=e.length;r<o;r++){var i=e[r];"."===i?r>0&&"\\"===e[r-1]?n=n.substring(0,n.length-1)+".":(t.push(n),n=""):n+=i}return t.push(n),t}function u(e){return R.indexOf(e)>-1}function c(e){return Object.keys(e)[0]}function a(e){return e[c(e)]}function f(e){var t={};return e.forEach(function(e){Object.keys(e).forEach(function(n){var r=e[n];if("object"!=typeof r&&(r={$eq:r}),u(n))r instanceof Array?t[n]=r.map(function(e){return f([e])}):t[n]=f([r]);else{var o=t[n]=t[n]||{};Object.keys(r).forEach(function(e){var t=r[e];return"$gt"===e||"$gte"===e?l(e,t,o):"$lt"===e||"$lte"===e?h(e,t,o):"$ne"===e?d(t,o):"$eq"===e?p(t,o):void(o[e]=t)})}})}),t}function l(e,t,n){void 0===n.$eq&&(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)}function h(e,t,n){void 0===n.$eq&&(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)}function d(e,t){"$ne"in t?t.$ne.push(e):t.$ne=[e]}function p(e,t){delete t.$gt,delete t.$gte,delete t.$lt,delete t.$lte,delete t.$ne,t.$eq=e}function v(e){var t=D.clone(e),n=!1;"$and"in t&&(t=f(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],o=e[r];"object"==typeof o&&null!==o||(e[r]={$eq:o})}})}),"$not"in t&&(t.$not=f([t.$not]));for(var r=Object.keys(t),o=0;o<r.length;o++){var i=r[o],s=t[i];"object"!=typeof s||null===s?s={$eq:s}:"$ne"in s&&!n&&(s.$ne=[s.$ne]),t[i]=s}return t}function y(e){function t(t){return e.map(function(e){var n=c(e),o=s(n);return r(t,o)})}return function(e,n){var r=t(e.doc),o=t(n.doc),s=F.collate(r,o);return 0!==s?s:i(e.doc._id,n.doc._id)}}function g(e,t,n){if(e=e.filter(function(e){return m(e.doc,t.selector,n)}),t.sort){var r=y(t.sort);e=e.sort(r),"string"!=typeof t.sort[0]&&"desc"===a(t.sort[0])&&(e=e.reverse())}if("limit"in t||"skip"in t){var o=t.skip||0,i=("limit"in t?t.limit:e.length)+o;e=e.slice(o,i)}return e}function m(e,t,n){return n.every(function(n){if(_(e))return!1;var o=t[n],i=s(n),c=r(e,i);return u(n)?w(n,o,e):b(o,e,i,c)})}function _(e){return/^_design\//.test(e._id)}function b(e,t,n,r){return!e||Object.keys(e).every(function(o){var i=e[o];return E(o,t,i,n,r)})}function w(e,t,n){return"$or"===e?t.some(function(e){return m(n,e,Object.keys(e))}):"$not"===e?!m(n,t,Object.keys(t)):!t.find(function(e){return m(n,e,Object.keys(e))})}function E(e,t,n,r,o){if(!N[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 or $all');return N[e](t,n,r,o)}function $(e){return void 0!==e&&null!==e}function O(e){return void 0!==e}function j(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}function S(e,t){return t.some(function(t){return e instanceof Array?e.indexOf(t)>-1:e===t})}function L(e,t){return t.every(function(t){return e.indexOf(t)>-1})}function A(e,t){return e.length===t}function I(e,t){return new RegExp(t).test(e)}function k(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.")}function x(e,t){if("object"!=typeof t)throw"Selector error: expected a JSON object";t=v(t);var n={doc:e},r=g([n],{selector:t},Object.keys(t));return r&&1===r.length}Object.defineProperty(n,"__esModule",{value:!0});var D=e("pouchdb-utils"),F=e("pouchdb-collate"),R=["$or","$nor","$not"],N={$elemMatch:function(e,t,n,r){return!!Array.isArray(r)&&(0!==r.length&&("object"==typeof r[0]?r.some(function(e){return m(e,t,Object.keys(t))}):r.some(function(r){return b(t,e,n,r)})))},$eq:function(e,t,n,r){return O(r)&&0===F.collate(r,t)},$gte:function(e,t,n,r){return O(r)&&F.collate(r,t)>=0},$gt:function(e,t,n,r){return O(r)&&F.collate(r,t)>0},$lte:function(e,t,n,r){return O(r)&&F.collate(r,t)<=0},$lt:function(e,t,n,r){return O(r)&&F.collate(r,t)<0},$exists:function(e,t,n,r){return t?O(r):!O(r)},$mod:function(e,t,n,r){return $(r)&&j(r,t)},$ne:function(e,t,n,r){return t.every(function(e){return 0!==F.collate(r,e)})},$in:function(e,t,n,r){return $(r)&&S(r,t)},$nin:function(e,t,n,r){return $(r)&&!S(r,t)},$size:function(e,t,n,r){return $(r)&&A(r,t)},$all:function(e,t,n,r){return Array.isArray(r)&&L(r,t)},$regex:function(e,t,n,r){return $(r)&&I(r,t)},$type:function(e,t,n,r){return k(r,t)}};n.massageSelector=v,n.matchesSelector=x,n.filterInMemoryFields=g,n.createFieldSorter=y,n.rowFilter=m,n.isCombinationalField=u,n.getKey=c,n.getValue=a,n.getFieldFromDoc=r,n.setFieldInDoc=o,n.compare=i,n.parseField=s},{"pouchdb-collate":9,"pouchdb-utils":14}],14:[function(e,t,n){"use strict";function r(e){return e&&"object"==typeof e&&"default"in e?e.default:e}function o(e){return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer||"undefined"!=typeof Blob&&e instanceof Blob}function i(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}function s(e){if(e instanceof ArrayBuffer)return i(e);var t=e.size,n=e.type;return"function"==typeof e.slice?e.slice(0,t,n):e.webkitSlice(0,t,n)}function u(e){var t=Object.getPrototypeOf(e);if(null===t)return!0;var n=t.constructor;return"function"==typeof n&&n instanceof n&&W.call(n)==X}function c(e){var t,n,r;if(!e||"object"!=typeof e)return e;if(Array.isArray(e)){for(t=[],n=0,r=e.length;n<r;n++)t[n]=c(e[n]);return t}if(e instanceof Date)return e.toISOString();if(o(e))return s(e);if(!u(e))return e;t={};for(n in e)if(Object.prototype.hasOwnProperty.call(e,n)){var i=c(e[n]);void 0!==i&&(t[n]=i)}return t}function a(e){var t=!1;return V(function(n){if(t)throw new Error("once called more than once");t=!0,e.apply(this,n)})}function f(e){return V(function(t){t=c(t);var n=this,r="function"==typeof t[t.length-1]&&t.pop(),o=new B(function(r,o){var i;try{var s=a(function(e,t){e?o(e):r(t)});t.push(s),i=e.apply(n,t),i&&"function"==typeof i.then&&r(i)}catch(e){o(e)}});return r&&o.then(function(e){r(null,e)},r),o})}function l(e,t,n){if(e.constructor.listeners("debug").length){for(var r=["api",e.name,t],o=0;o<n.length-1;o++)r.push(n[o]);e.constructor.emit("debug",r);var i=n[n.length-1];n[n.length-1]=function(n,r){var o=["api",e.name,t];o=o.concat(n?["error",n]:["success",r]),e.constructor.emit("debug",o),i(n,r)}}}function h(e,t){return f(V(function(n){if(this._closed)return B.reject(new Error("database is closed"));if(this._destroyed)return B.reject(new Error("database is destroyed"));var r=this;return l(r,e,n),this.taskqueue.isReady?t.apply(this,n):new B(function(t,o){r.taskqueue.addTask(function(i){i?o(i):t(r[e].apply(r,n))})})}))}function d(e,t){for(var n={},r=0,o=t.length;r<o;r++){var i=t[r];i in e&&(n[i]=e[i])}return n}function p(e){return e}function v(e){return[{ok:e}]}function y(e,t,n){function r(){var e=[];h.forEach(function(t){t.docs.forEach(function(n){e.push({id:t.id,docs:[n]})})}),n(null,{results:e})}function o(){++l===f&&r()}function i(e,t,n){h[e]={id:t,docs:n},o()}function s(){if(!(g>=y.length)){var e=Math.min(g+H,y.length),t=y.slice(g,e);u(t,g),g+=t.length}}function u(n,r){n.forEach(function(n,o){var u=r+o,c=a.get(n),f=d(c[0],["atts_since","attachments"]);f.open_revs=c.map(function(e){return e.rev}),f.open_revs=f.open_revs.filter(p);var l=p;0===f.open_revs.length&&(delete f.open_revs,l=v),["revs","attachments","binary","ajax","latest"].forEach(function(e){e in t&&(f[e]=t[e])}),e.get(n,f,function(e,t){var r;r=e?[{error:e}]:l(t),i(u,n,r),s()})})}var c=t.docs,a=new z.Map;c.forEach(function(e){a.has(e.id)?a.get(e.id).push(e):a.set(e.id,[e])});var f=a.size,l=0,h=new Array(f),y=[];a.forEach(function(e,t){y.push(t)});var g=0;s()}function g(){return"undefined"!=typeof chrome&&void 0!==chrome.storage&&void 0!==chrome.storage.local}function m(){return U}function _(e){g()?chrome.storage.onChanged.addListener(function(t){null!=t.db_name&&e.emit(t.dbName.newValue)}):m()&&("undefined"!=typeof addEventListener?addEventListener("storage",function(t){e.emit(t.key)}):window.attachEvent("storage",function(t){e.emit(t.key)}))}function b(){G.EventEmitter.call(this),this._listeners={},_(this)}function w(e){if("undefined"!==console&&e in console){var t=Array.prototype.slice.call(arguments,1);console[e].apply(console,t)}}function E(e,t){return e=parseInt(e,10)||0,t=parseInt(t,10),t!==t||t<=e?t=(e||1)<<1:t+=1,t>6e5&&(e=3e5,t=6e5),~~((t-e)*Math.random()+e)}function $(e){var t=0;return e||(t=2e3),E(e,t)}function O(e,t){w("info","The above "+e+" is totally normal. "+t)}function j(e,t,n){try{return!e(t,n)}catch(e){var r="Filter function threw: "+e.toString();return J.createError(J.BAD_REQUEST,r)}}function S(e){var t={},n=e.filter&&"function"==typeof e.filter;return t.query=e.query_params,function(r){r.doc||(r.doc={});var o=n&&j(e.filter,r.doc,t);if("object"==typeof o)return o;if(o)return!1;if(e.include_docs){if(!e.attachments)for(var i in r.doc._attachments)r.doc._attachments.hasOwnProperty(i)&&(r.doc._attachments[i].stub=!0)}else delete r.doc;return!0}}function L(e){for(var t=[],n=0,r=e.length;n<r;n++)t=t.concat(e[n]);return t}function A(){}function I(e){var t;if(e?"string"!=typeof e?t=J.createError(J.INVALID_ID):/^_/.test(e)&&!/^_(design|local)/.test(e)&&(t=J.createError(J.RESERVED_ID)):t=J.createError(J.MISSING_ID),t)throw t}function k(){return"undefined"!=typeof cordova||"undefined"!=typeof PhoneGap||"undefined"!=typeof phonegap}function x(e){return"boolean"==typeof e._remote?e._remote:"function"==typeof e.type&&(w("warn","db.type() is deprecated and will be removed in a future version of PouchDB"),"http"===e.type())}function D(e,t){return"listenerCount"in e?e.listenerCount(t):G.EventEmitter.listenerCount(e,t)}function F(e){if(!e)return null;var t=e.split("/");return 2===t.length?t:1===t.length?[e,e]:null}function R(e){var t=F(e);return t?t.join("/"):null}function N(e){for(var t=se.exec(e),n={},r=14;r--;){var o=re[r],i=t[r]||"",s=-1!==["user","password"].indexOf(o);n[o]=s?decodeURIComponent(i):i}return n[oe]={},n[re[12]].replace(ie,function(e,t,r){t&&(n[oe][t]=r)}),n}function M(e,t){var n=[],r=[];for(var o in t)t.hasOwnProperty(o)&&(n.push(o),r.push(t[o]));return n.push(e),Function.apply(null,n).apply(null,r)}function q(e,t,n){return new B(function(r,o){e.get(t,function(i,s){if(i){if(404!==i.status)return o(i);s={}}var u=s._rev,c=n(s);if(!c)return r({updated:!1,rev:u});c._id=t,c._rev=u,r(C(e,c,n))})})}function C(e,t,n){return e.put(t).then(function(e){return{updated:!0,rev:e.rev}},function(r){if(409!==r.status)throw r;return q(e,t._id,n)})}function P(e){return 0|Math.random()*e}function T(e,t){t=t||ue.length;var n="",r=-1;if(e){for(;++r<e;)n+=ue[P(t)];return n}for(;++r<36;)switch(r){case 8:case 13:case 18:case 23:n+="-";break;case 19:n+=ue[3&P(16)|8];break;default:n+=ue[P(16)]}return n}Object.defineProperty(n,"__esModule",{value:!0})
;var U,B=r(e("pouchdb-promise")),V=r(e("argsarray")),z=e("pouchdb-collections"),G=e("events"),Q=r(e("inherits")),K=r(e("immediate")),J=e("pouchdb-errors"),W=Function.prototype.toString,X=W.call(Object),H=6;if(g())U=!1;else try{localStorage.setItem("_pouch_check_localstorage",1),U=!!localStorage.getItem("_pouch_check_localstorage")}catch(e){U=!1}Q(b,G.EventEmitter),b.prototype.addListener=function(e,t,n,r){function o(){function e(){s=!1}if(i._listeners[t]){if(s)return void(s="waiting");s=!0;var u=d(r,["style","include_docs","attachments","conflicts","filter","doc_ids","view","since","query_params","binary"]);n.changes(u).on("change",function(e){e.seq>r.since&&!r.cancelled&&(r.since=e.seq,r.onChange(e))}).on("complete",function(){"waiting"===s&&K(o),s=!1}).on("error",e)}}if(!this._listeners[t]){var i=this,s=!1;this._listeners[t]=o,this.on(e,o)}},b.prototype.removeListener=function(e,t){t in this._listeners&&(G.EventEmitter.prototype.removeListener.call(this,e,this._listeners[t]),delete this._listeners[t])},b.prototype.notifyLocalWindows=function(e){g()?chrome.storage.local.set({dbName:e}):m()&&(localStorage[e]="a"===localStorage[e]?"b":"a")},b.prototype.notify=function(e){this.emit(e),this.notifyLocalWindows(e)};var Y;Y="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 o in r)Object.prototype.hasOwnProperty.call(r,o)&&(t[o]=r[o])}return t};var Z,ee=Y,te=A.name;Z=te?function(e){return e.name}:function(e){return e.toString().match(/^\s*function\s*(\S*)\s*\(/)[1]};var ne=Z,re=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],oe="queryKey",ie=/(?:^|&)([^&=]*)=?([^&]*)/g,se=/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/,ue="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");n.adapterFun=h,n.bulkGetShim=y,n.changesHandler=b,n.clone=c,n.defaultBackOff=$,n.explainError=O,n.assign=ee,n.filterChange=S,n.flatten=L,n.functionName=ne,n.guardedConsole=w,n.hasLocalStorage=m,n.invalidIdError=I,n.isChromeApp=g,n.isCordova=k,n.isRemote=x,n.listenerCount=D,n.nextTick=K,n.normalizeDdocFunctionName=R,n.once=a,n.parseDdocFunctionName=F,n.parseUri=N,n.pick=d,n.scopeEval=M,n.toPromise=f,n.upsert=q,n.uuid=T},{argsarray:4,events:5,immediate:6,inherits:7,"pouchdb-collections":10,"pouchdb-errors":11,"pouchdb-promise":12}]},{},[2]);