-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpouchdb-3.2.1.min.js
12 lines (12 loc) · 159 KB
/
pouchdb-3.2.1.min.js
1
2
3
4
5
6
7
8
9
10
11
12
// PouchDB 3.2.1
//
// (c) 2012-2014 Dale Harvey and the PouchDB team
// PouchDB may be freely distributed under the Apache license, version 2.0.
// For all details and documentation:
// http://pouchdb.com
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var t;"undefined"!=typeof window?t=window:"undefined"!=typeof global?t=global:"undefined"!=typeof self&&(t=self),t.PouchDB=e()}}(function(){var define,module,exports;return function e(t,n,r){function o(s,a){if(!n[s]){if(!t[s]){var u="function"==typeof require&&require;if(!a&&u)return u(s,!0);if(i)return i(s,!0);var c=new Error("Cannot find module '"+s+"'");throw c.code="MODULE_NOT_FOUND",c}var f=n[s]={exports:{}};t[s][0].call(f.exports,function(e){var n=t[s][1][e];return o(n?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){"use strict";function n(e,t){for(var n=0;n<e.length;n++)if(t(e[n],n)===!0)return e[n];return!1}function r(e){return function(t,n){t||n[0]&&n[0].error?e(t||n[0]):e(null,n.length?n[0]:n)}}function o(e){var t={},n=[];return u.traverseRevTree(e,function(e,r,o,i){var s=r+"-"+o;return e&&(t[s]=0),void 0!==i&&n.push({from:i,to:s}),s}),n.reverse(),n.forEach(function(e){t[e.from]=void 0===t[e.from]?1+t[e.to]:Math.min(t[e.from],1+t[e.to])}),t}function i(e,t,n){var r="limit"in t?t.keys.slice(t.skip,t.limit+t.skip):t.skip>0?t.keys.slice(t.skip):t.keys;if(t.descending&&r.reverse(),!r.length)return e._allDocs({limit:0},n);var o={offset:t.skip};return h.all(r.map(function(n){var r=a.extend(!0,{key:n,deleted:"ok"},t);return["limit","skip","keys"].forEach(function(e){delete r[e]}),new h(function(t,i){e._allDocs(r,function(e,r){return e?i(e):(o.total_rows=r.total_rows,void t(r.rows[0]||{key:n,error:"not_found"}))})})})).then(function(e){return o.rows=e,o})}function s(){var e=this;f.call(this);var t,n=0,r=["change","delete","create","update"];this.on("newListener",function(o){if(~r.indexOf(o)){if(n)return void n++;n++;var i=0;t=this.changes({conflicts:!0,include_docs:!0,continuous:!0,since:"now",onChange:function(t){t.seq<=i||(i=t.seq,e.emit("change",t),t.doc._deleted?e.emit("delete",t):"1"===t.doc._rev.split("-")[0]?e.emit("create",t):e.emit("update",t))}})}}),this.on("removeListener",function(e){~r.indexOf(e)&&(n--,n||t.cancel())})}var a=e("./utils"),u=e("./merge"),c=e("./deps/errors"),f=e("events").EventEmitter,l=e("./deps/upsert"),d=e("./changes"),h=a.Promise;a.inherits(s,f),t.exports=s,s.prototype.post=a.adapterFun("post",function(e,t,n){return"function"==typeof t&&(n=t,t={}),"object"!=typeof e||Array.isArray(e)?n(c.error(c.NOT_AN_OBJECT)):void this.bulkDocs({docs:[e]},t,r(n))}),s.prototype.put=a.adapterFun("put",a.getArguments(function(e){var t,n,o,i,s=e.shift(),u="_id"in s;if("object"!=typeof s||Array.isArray(s))return(i=e.pop())(c.error(c.NOT_AN_OBJECT));for(s=a.clone(s);;)if(t=e.shift(),n=typeof t,"string"!==n||u?"string"!==n||!u||"_rev"in s?"object"===n?o=t:"function"===n&&(i=t):s._rev=t:(s._id=t,u=!0),!e.length)break;o=o||{};var f=a.invalidIdError(s._id);return f?i(f):a.isLocalId(s._id)&&"function"==typeof this._putLocal?s._deleted?this._removeLocal(s,i):this._putLocal(s,i):void this.bulkDocs({docs:[s]},o,r(i))})),s.prototype.putAttachment=a.adapterFun("putAttachment",function(e,t,n,r,o,i){function s(e){return e._attachments=e._attachments||{},e._attachments[t]={content_type:o,data:r},a.put(e)}var a=this;return"function"==typeof o&&(i=o,o=r,r=n,n=null),"undefined"==typeof o&&(o=r,r=n,n=null),a.get(e).then(function(e){if(e._rev!==n)throw c.error(c.REV_CONFLICT);return s(e)},function(t){if(t.reason===c.MISSING_DOC.message)return s({_id:e});throw t})}),s.prototype.removeAttachment=a.adapterFun("removeAttachment",function(e,t,n,r){var o=this;o.get(e,function(e,i){return e?void r(e):i._rev!==n?void r(c.error(c.REV_CONFLICT)):i._attachments?(delete i._attachments[t],0===Object.keys(i._attachments).length&&delete i._attachments,void o.put(i,r)):r()})}),s.prototype.remove=a.adapterFun("remove",function(e,t,n,o){var i;"string"==typeof t?(i={_id:e,_rev:t},"function"==typeof n&&(o=n,n={})):(i=e,"function"==typeof t?(o=t,n={}):(o=n,n=t)),n=a.clone(n||{}),n.was_delete=!0;var s={_id:i._id,_rev:i._rev||n.rev};return s._deleted=!0,a.isLocalId(s._id)&&"function"==typeof this._removeLocal?this._removeLocal(i,o):void this.bulkDocs({docs:[s]},n,r(o))}),s.prototype.revsDiff=a.adapterFun("revsDiff",function(e,t,n){function r(e,t){c.has(e)||c.set(e,{missing:[]}),c.get(e).missing.push(t)}function o(t,n){var o=e[t].slice(0);u.traverseRevTree(n,function(e,n,i,s,a){var u=n+"-"+i,c=o.indexOf(u);-1!==c&&(o.splice(c,1),"available"!==a.status&&r(t,u))}),o.forEach(function(e){r(t,e)})}"function"==typeof t&&(n=t,t={}),t=a.clone(t);var i=Object.keys(e);if(!i.length)return n(null,{});var s=0,c=new a.Map;i.map(function(t){this._getRevisionTree(t,function(r,a){if(r&&404===r.status&&"missing"===r.message)c.set(t,{missing:e[t]});else{if(r)return n(r);o(t,a)}if(++s===i.length){var u={};return c.forEach(function(e,t){u[t]=e}),n(null,u)}})},this)}),s.prototype.compactDocument=a.adapterFun("compactDocument",function(e,t,n){var r=this;this._getRevisionTree(e,function(i,s){if(i)return n(i);var a=o(s),c=[],f=[];Object.keys(a).forEach(function(e){a[e]>t&&c.push(e)}),u.traverseRevTree(s,function(e,t,n,r,o){var i=t+"-"+n;"available"===o.status&&-1!==c.indexOf(i)&&f.push(i)}),r._doCompaction(e,f,n)})}),s.prototype.compact=a.adapterFun("compact",function(e,t){"function"==typeof e&&(t=e,e={});var n=this;e=a.clone(e||{}),n.get("_local/compaction")["catch"](function(){return!1}).then(function(r){return"function"==typeof n._compact?(r&&r.last_seq&&(e.last_seq=r.last_seq),n._compact(e,t)):void 0})}),s.prototype._compact=function(e,t){function n(){l(c,"_local/compaction",function(e){return!e.last_seq||e.last_seq<i?(e.last_seq=i,e):!1},function(){t()})}function r(){a--,!a&&s&&n()}function o(e){a++,c.compactDocument(e.id,0).then(r,t)}var i,s=!1,a=0,u={returnDocs:!1},c=this;e.last_seq&&(u.since=e.last_seq),c.changes(u).on("change",o).on("complete",function(e){s=!0,i=e.last_seq,a||n()}).on("error",t)},s.prototype.get=a.adapterFun("get",function(e,t,r){function o(){var n=[],o=i.length;return o?void i.forEach(function(i){s.get(e,{rev:i,revs:t.revs,attachments:t.attachments},function(e,t){n.push(e?{missing:i}:{ok:t}),o--,o||r(null,n)})}):r(null,n)}if("function"==typeof t&&(r=t,t={}),"string"!=typeof e)return r(c.error(c.INVALID_ID));if(a.isLocalId(e)&&"function"==typeof this._getLocal)return this._getLocal(e,r);var i=[],s=this;if(!t.open_revs)return this._get(e,t,function(e,o){if(t=a.clone(t),e)return r(e);var i=o.doc,c=o.metadata,f=o.ctx;if(t.conflicts){var l=u.collectConflicts(c);l.length&&(i._conflicts=l)}if(a.isDeleted(c,i._rev)&&(i._deleted=!0),t.revs||t.revs_info){var d=u.rootToLeaf(c.rev_tree),h=n(d,function(e){return-1!==e.ids.map(function(e){return e.id}).indexOf(i._rev.split("-")[1])}),p=h.ids.map(function(e){return e.id}).indexOf(i._rev.split("-")[1])+1,v=h.ids.length-p;if(h.ids.splice(p,v),h.ids.reverse(),t.revs&&(i._revisions={start:h.pos+h.ids.length-1,ids:h.ids.map(function(e){return e.id})}),t.revs_info){var g=h.pos+h.ids.length;i._revs_info=h.ids.map(function(e){return g--,{rev:g+"-"+e.id,status:e.opts.status}})}}if(t.local_seq&&(i._local_seq=o.metadata.seq),t.attachments&&i._attachments){var m=i._attachments,_=Object.keys(m).length;if(0===_)return r(null,i);Object.keys(m).forEach(function(e){this._getAttachment(m[e],{encode:!0,ctx:f},function(t,n){var o=i._attachments[e];o.data=n,delete o.stub,delete o.length,--_||r(null,i)})},s)}else{if(i._attachments)for(var y in i._attachments)i._attachments.hasOwnProperty(y)&&(i._attachments[y].stub=!0);r(null,i)}});if("all"===t.open_revs)this._getRevisionTree(e,function(e,t){e&&(t=[]),i=u.collectLeaves(t).map(function(e){return e.rev}),o()});else{if(!Array.isArray(t.open_revs))return r(c.error(c.UNKNOWN_ERROR,"function_clause"));i=t.open_revs;for(var f=0;f<i.length;f++){var l=i[f];if("string"!=typeof l||!/^\d+-/.test(l))return r(c.error(c.INVALID_REV))}o()}}),s.prototype.getAttachment=a.adapterFun("getAttachment",function(e,t,n,r){var o=this;n instanceof Function&&(r=n,n={}),n=a.clone(n),this._get(e,n,function(e,i){return e?r(e):i.doc._attachments&&i.doc._attachments[t]?(n.ctx=i.ctx,void o._getAttachment(i.doc._attachments[t],n,r)):r(c.error(c.MISSING_DOC))})}),s.prototype.allDocs=a.adapterFun("allDocs",function(e,t){if("function"==typeof e&&(t=e,e={}),e=a.clone(e),e.skip="undefined"!=typeof e.skip?e.skip:0,"keys"in e){if(!Array.isArray(e.keys))return t(new TypeError("options.keys must be an array"));var n=["startkey","endkey","key"].filter(function(t){return t in e})[0];if(n)return void t(c.error(c.QUERY_PARSE_ERROR,"Query parameter `"+n+"` is not compatible with multi-get"));if("http"!==this.type())return i(this,e,t)}return this._allDocs(e,t)}),s.prototype.changes=function(e,t){return"function"==typeof e&&(t=e,e={}),new d(this,e,t)},s.prototype.close=a.adapterFun("close",function(e){return this._closed=!0,this._close(e)}),s.prototype.info=a.adapterFun("info",function(e){var t=this;this._info(function(n,r){return n?e(n):(r.db_name=r.db_name||t._db_name,r.auto_compaction=!(!t.auto_compaction||"http"===t.type()),void e(null,r))})}),s.prototype.id=a.adapterFun("id",function(e){return this._id(e)}),s.prototype.type=function(){return"function"==typeof this._type?this._type():this.adapter},s.prototype.bulkDocs=a.adapterFun("bulkDocs",function(e,t,n){if("function"==typeof t&&(n=t,t={}),t=a.clone(t),Array.isArray(e)&&(e={docs:e}),!e||!e.docs||!Array.isArray(e.docs))return n(c.error(c.MISSING_BULK_DOCS));for(var r=0;r<e.docs.length;++r)if("object"!=typeof e.docs[r]||Array.isArray(e.docs[r]))return n(c.error(c.NOT_AN_OBJECT));return e=a.clone(e),"new_edits"in t||(t.new_edits="new_edits"in e?e.new_edits:!0),t.new_edits||"http"===this.type()||e.docs.sort(function(e,t){var n=a.compare(e._id,t._id);if(0!==n)return n;var r=e._revisions?e._revisions.start:0,o=t._revisions?t._revisions.start:0;return a.compare(r,o)}),e.docs.forEach(function(e){e._deleted&&delete e._attachments}),this._bulkDocs(e,t,function(e,r){return e?n(e):(t.new_edits||(r=r.filter(function(e){return e.error})),void n(null,r))})}),s.prototype.registerDependentDatabase=a.adapterFun("registerDependentDatabase",function(e,t){function n(t){return t.dependentDbs=t.dependentDbs||{},t.dependentDbs[e]?!1:(t.dependentDbs[e]=!0,t)}var r=new this.constructor(e,this.__opts||{});l(this,"_local/_pouch_dependentDbs",n,function(e){return e?t(e):t(null,{db:r})})})},{"./changes":12,"./deps/errors":18,"./deps/upsert":22,"./merge":26,"./utils":31,events:39}],2:[function(e,t){(function(n,r){"use strict";function o(e){return/^_(design|local)/.test(e)?e:encodeURIComponent(e)}function i(e){return e._attachments&&Object.keys(e._attachments)?d.Promise.all(Object.keys(e._attachments).map(function(t){var n=e._attachments[t];if(n.data&&"string"!=typeof n.data){if(v)return new d.Promise(function(e){d.readAsBinaryString(n.data,function(t){n.data=d.btoa(t),e()})});n.data=n.data.toString("base64")}})):d.Promise.resolve()}function s(e,t){if(/http(s?):/.test(e)){var n=d.parseUri(e);n.remote=!0,(n.user||n.password)&&(n.auth={username:n.user,password:n.password});var r=n.path.replace(/(^\/|\/$)/g,"").split("/");if(n.db=r.pop(),n.path=r.join("/"),t=t||{},t=d.clone(t),n.headers=t.headers||{},t.auth||n.auth){var o=t.auth||n.auth,i=d.btoa(o.username+":"+o.password);n.headers.Authorization="Basic "+i}return t.headers&&(n.headers=t.headers),n}return{host:"",path:"/",db:e,auth:!1}}function a(e,t){return u(e,e.db+"/"+t)}function u(e,t){if(e.remote){var n=e.path?"/":"";return e.protocol+"://"+e.host+":"+e.port+"/"+e.path+n+t}return"/"+t}function c(e,t){function n(e,t){var n=d.extend({},y,e);return p(n.method+" "+n.url),d.ajax(n,t)}function c(e){return e.split("/").map(encodeURIComponent).join("/")}var g=this;g.getHost=e.getHost?e.getHost:s;var m=g.getHost(e.name,e),_=a(m,"");g.getUrl=function(){return _},g.getHeaders=function(){return d.clone(m.headers)};var y=e.ajax||{};e=d.clone(e);var b=function(){n({headers:m.headers,method:"PUT",url:_},function(e){e&&401===e.status?n({headers:m.headers,method:"HEAD",url:_},function(e){e?t(e):t(null,g)}):e&&412!==e.status?t(e):t(null,g)})};e.skipSetup||n({headers:m.headers,method:"GET",url:_},function(e){e?404===e.status?(d.explain404("PouchDB is just detecting if the remote DB exists."),b()):t(e):t(null,g)}),g.type=function(){return"http"},g.id=d.adapterFun("id",function(e){n({headers:m.headers,method:"GET",url:u(m,"")},function(t,n){var r=n&&n.uuid?n.uuid+m.db:a(m,"");e(null,r)})}),g.request=d.adapterFun("request",function(e,t){e.headers=m.headers,e.url=a(m,e.url),n(e,t)}),g.compact=d.adapterFun("compact",function(e,t){"function"==typeof e&&(t=e,e={}),e=d.clone(e),n({headers:m.headers,url:a(m,"_compact"),method:"POST"},function(){function n(){g.info(function(r,o){o.compact_running?setTimeout(n,e.interval||200):t()})}"function"==typeof t&&n()})}),g._info=function(e){n({headers:m.headers,method:"GET",url:a(m,"")},function(t,n){t?e(t):(n.host=a(m,""),e(null,n))})},g.get=d.adapterFun("get",function(e,t,r){"function"==typeof t&&(r=t,t={}),t=d.clone(t),void 0===t.auto_encode&&(t.auto_encode=!0);var i=[];t.revs&&i.push("revs=true"),t.revs_info&&i.push("revs_info=true"),t.local_seq&&i.push("local_seq=true"),t.open_revs&&("all"!==t.open_revs&&(t.open_revs=JSON.stringify(t.open_revs)),i.push("open_revs="+t.open_revs)),t.attachments&&i.push("attachments=true"),t.rev&&i.push("rev="+t.rev),t.conflicts&&i.push("conflicts="+t.conflicts),i=i.join("&"),i=""===i?"":"?"+i,t.auto_encode&&(e=o(e));var s={headers:m.headers,method:"GET",url:a(m,e+i)},u=e.split("/");(u.length>1&&"_design"!==u[0]&&"_local"!==u[0]||u.length>2&&"_design"===u[0]&&"_local"!==u[0])&&(s.binary=!0),n(s,function(e,t,n){return e?r(e):void r(null,t,n)})}),g.remove=d.adapterFun("remove",function(e,t,r,i){var s;"string"==typeof t?(s={_id:e,_rev:t},"function"==typeof r&&(i=r,r={})):(s=e,"function"==typeof t?(i=t,r={}):(i=r,r=t));var u=s._rev||r.rev;n({headers:m.headers,method:"DELETE",url:a(m,o(s._id))+"?rev="+u},i)}),g.getAttachment=d.adapterFun("getAttachment",function(e,t,n,r){"function"==typeof n&&(r=n,n={}),n=d.clone(n),void 0===n.auto_encode&&(n.auto_encode=!0),n.auto_encode&&(e=o(e)),n.auto_encode=!1,g.get(e+"/"+c(t),n,r)}),g.removeAttachment=d.adapterFun("removeAttachment",function(e,t,r,i){var s=a(m,o(e)+"/"+c(t))+"?rev="+r;n({headers:m.headers,method:"DELETE",url:s},i)}),g.putAttachment=d.adapterFun("putAttachment",function(e,t,i,s,u,f){"function"==typeof u&&(f=u,u=s,s=i,i=null),"undefined"==typeof u&&(u=s,s=i,i=null);var l=o(e)+"/"+c(t),p=a(m,l);if(i&&(p+="?rev="+i),"string"==typeof s){var g;try{g=d.atob(s)}catch(_){return f(h.error(h.BAD_ARG,"Attachments need to be base64 encoded"))}s=v?d.createBlob([d.fixBinary(g)],{type:u}):g?new r(g,"binary"):""}var y={headers:d.clone(m.headers),method:"PUT",url:p,processData:!1,body:s,timeout:6e4};y.headers["Content-Type"]=u,n(y,f)}),g.put=d.adapterFun("put",d.getArguments(function(e){var t,r,s,u=e.shift(),c="_id"in u,f=e.pop();return"object"!=typeof u||Array.isArray(u)?f(h.error(h.NOT_AN_OBJECT)):(u=d.clone(u),void i(u).then(function(){for(;;)if(t=e.shift(),r=typeof t,"string"!==r||c?"string"!==r||!c||"_rev"in u?"object"===r&&(s=d.clone(t)):u._rev=t:(u._id=t,c=!0),!e.length)break;s=s||{};var i=d.invalidIdError(u._id);if(i)throw i;var l=[];s&&"undefined"!=typeof s.new_edits&&l.push("new_edits="+s.new_edits),l=l.join("&"),""!==l&&(l="?"+l),n({headers:m.headers,method:"PUT",url:a(m,o(u._id))+l,body:u},function(e,t){return e?f(e):(t.ok=!0,void f(null,t))})})["catch"](f))})),g.post=d.adapterFun("post",function(e,t,n){return"function"==typeof t&&(n=t,t={}),t=d.clone(t),"object"!=typeof e?n(h.error(h.NOT_AN_OBJECT)):("_id"in e||(e._id=d.uuid()),void g.put(e,t,function(e,t){return e?n(e):(t.ok=!0,void n(null,t))}))}),g._bulkDocs=function(e,t,r){"undefined"!=typeof t.new_edits&&(e.new_edits=t.new_edits),d.Promise.all(e.docs.map(i)).then(function(){n({headers:m.headers,method:"POST",url:a(m,"_bulk_docs"),body:e},function(e,t){return e?r(e):(t.forEach(function(e){e.ok=!0}),void r(null,t))})})["catch"](r)},g.allDocs=d.adapterFun("allDocs",function(e,t){"function"==typeof e&&(t=e,e={}),e=d.clone(e);var r,o=[],i="GET";if(e.conflicts&&o.push("conflicts=true"),e.descending&&o.push("descending=true"),e.include_docs&&o.push("include_docs=true"),e.attachments&&o.push("attachments=true"),e.key&&o.push("key="+encodeURIComponent(JSON.stringify(e.key))),e.startkey&&o.push("startkey="+encodeURIComponent(JSON.stringify(e.startkey))),e.endkey&&o.push("endkey="+encodeURIComponent(JSON.stringify(e.endkey))),"undefined"!=typeof e.inclusive_end&&o.push("inclusive_end="+!!e.inclusive_end),"undefined"!=typeof e.limit&&o.push("limit="+e.limit),"undefined"!=typeof e.skip&&o.push("skip="+e.skip),o=o.join("&"),""!==o&&(o="?"+o),"undefined"!=typeof e.keys){var s="keys="+encodeURIComponent(JSON.stringify(e.keys));s.length+o.length+1<=l?o+=(-1!==o.indexOf("?")?"&":"?")+s:(i="POST",r=JSON.stringify({keys:e.keys}))}n({headers:m.headers,method:i,url:a(m,"_all_docs"+o),body:r},t)}),g._changes=function(e){var t="batch_size"in e?e.batch_size:f;e=d.clone(e),e.timeout=e.timeout||3e4;var r={timeout:e.timeout-5e3},o="undefined"!=typeof e.limit?e.limit:!1;0===o&&(o=1);var i;i="returnDocs"in e?e.returnDocs:!0;var s=o;if(e.style&&(r.style=e.style),(e.include_docs||e.filter&&"function"==typeof e.filter)&&(r.include_docs=!0),e.attachments&&(r.attachments=!0),e.continuous&&(r.feed="longpoll"),e.conflicts&&(r.conflicts=!0),e.descending&&(r.descending=!0),e.filter&&"string"==typeof e.filter&&(r.filter=e.filter,"_view"===e.filter&&e.view&&"string"==typeof e.view&&(r.view=e.view)),e.query_params&&"object"==typeof e.query_params)for(var u in e.query_params)e.query_params.hasOwnProperty(u)&&(r[u]=e.query_params[u]);var c,p="GET";if(e.doc_ids){r.filter="_doc_ids";var v=JSON.stringify(e.doc_ids);v.length<l?r.doc_ids=v:(p="POST",c={doc_ids:e.doc_ids})}if(e.continuous&&g._useSSE)return g.sse(e,r,i);var _,y,b=function(i,u){if(!e.aborted){r.since=i,"object"==typeof r.since&&(r.since=JSON.stringify(r.since)),e.descending?o&&(r.limit=s):r.limit=!o||s>t?t:s;var f="?"+Object.keys(r).map(function(e){return e+"="+r[e]}).join("&"),l={headers:m.headers,method:p,url:a(m,"_changes"+f),timeout:e.timeout,body:c};y=i,e.aborted||(_=n(l,u))}},w=10,E=0,S={results:[]},A=function(n,r){if(!e.aborted){var a=0;if(r&&r.results){a=r.results.length,S.last_seq=r.last_seq;var u={};u.query=e.query_params,r.results=r.results.filter(function(t){s--;var n=d.filterChange(e)(t);return n&&(i&&S.results.push(t),d.call(e.onChange,t)),n})}else if(n)return e.aborted=!0,void d.call(e.complete,n);r&&r.last_seq&&(y=r.last_seq);var c=o&&0>=s||r&&t>a||e.descending;if((!e.continuous||o&&0>=s)&&c)d.call(e.complete,null,S);else{n?E+=1:E=0;var f=1<<E,l=w*f,p=e.maximumWait||3e4;if(l>p)return void d.call(e.complete,n||h.error(h.UNKNOWN_ERROR));setTimeout(function(){b(y,A)},l)}}};return b(e.since||0,A),{cancel:function(){e.aborted=!0,_&&_.abort()}}},g.sse=function(e,t,n){function r(t){var r=JSON.parse(t.data);n&&c.results.push(r),c.last_seq=r.seq,d.call(e.onChange,r)}function o(t){return u.removeEventListener("message",r,!1),l===!1?(g._useSSE=!1,void(f=g._changes(e))):(u.close(),void d.call(e.complete,t))}t.feed="eventsource",t.since=e.since||0,t.limit=e.limit,delete t.timeout;var i="?"+Object.keys(t).map(function(e){return e+"="+t[e]}).join("&"),s=a(m,"_changes"+i),u=new EventSource(s),c={results:[],last_seq:!1},f=!1,l=!1;return u.addEventListener("message",r,!1),u.onopen=function(){l=!0},u.onerror=o,{cancel:function(){return f?f.cancel():(u.removeEventListener("message",r,!1),void u.close())}}},g._useSSE=!1,g.revsDiff=d.adapterFun("revsDiff",function(e,t,r){"function"==typeof t&&(r=t,t={}),n({headers:m.headers,method:"POST",url:a(m,"_revs_diff"),body:JSON.stringify(e)},r)}),g._close=function(e){e()},g.destroy=d.adapterFun("destroy",function(e){n({url:a(m,""),method:"DELETE",headers:m.headers},function(t,n){t?(g.emit("error",t),e(t)):(g.emit("destroyed"),e(null,n))})})}var f=25,l=1800,d=e("../../utils"),h=e("../../deps/errors"),p=e("debug")("pouchdb:http"),v="undefined"==typeof n||n.browser;c.destroy=d.toPromise(function(e,t,n){var r=s(e,t);t=t||{},"function"==typeof t&&(n=t,t={}),t=d.clone(t),t.headers=r.headers,t.method="DELETE",t.url=a(r,"");var o=t.ajax||{};t=d.extend({},t,o),d.ajax(t,n)}),c.valid=function(){return!0},t.exports=c}).call(this,e("_process"),e("buffer").Buffer)},{"../../deps/errors":18,"../../utils":31,_process:40,buffer:35,debug:41}],3:[function(e,t){"use strict";function n(e,t,n,i,s,m){function _(){var e=[f,c,u,d,l,a];I=i.transaction(e,"readwrite"),I.onerror=g(m),I.ontimeout=g(m),I.oncomplete=w,q=I.objectStore(f),L=I.objectStore(c),C=I.objectStore(u),D=I.objectStore(a),S(function(e){return e?(J=!0,m(e)):void b()})}function y(){r.processDocs(j,n,F,I,U,A,t)}function b(){function e(){++n===j.length&&y()}function t(t){var n=p(t.target.result);n&&F.set(n.id,n),e()}if(j.length)for(var n=0,o=0,i=j.length;i>o;o++){var s=j[o];if(s._id&&r.isLocalId(s._id))e();else{var a=q.get(s.metadata.id);a.onsuccess=t}}}function w(){J||(s.notify(n._name),n._docCount=-1,m(null,U))}function E(e,t){var n=C.get(e);n.onsuccess=function(n){if(n.target.result)t();else{var r=o.error(o.MISSING_STUB,"unknown stub attachment with digest "+e);r.status=412,t(r)}}}function S(e){function t(){++o===n.length&&e(r)}var n=[];if(j.forEach(function(e){e.data&&e.data._attachments&&Object.keys(e.data._attachments).forEach(function(t){var r=e.data._attachments[t];r.stub&&n.push(r.digest)})}),!n.length)return e();var r,o=0;n.forEach(function(e){E(e,function(e){e&&!r&&(r=e),t()})})}function A(e,t,n,r,o,i,s){var a=e.data;a._id=e.metadata.id,a._rev=e.metadata.rev,n&&(a._deleted=!0);var u=a._attachments&&Object.keys(a._attachments).length;return u?k(e,t,n,r,o,s):void R(e,t,n,r,o,s)}function T(e){var t=r.compactTree(e.metadata);h(t,e.metadata.id,I)}function R(e,t,r,o,i,s){function a(o){i&&n.auto_compaction&&T(e),l.seq=o.target.result,delete l.rev;var s=v(l,t,r),a=q.put(s);a.onsuccess=c}function u(e){e.preventDefault(),e.stopPropagation();var t=L.index("_doc_id_rev"),n=t.getKey(f._doc_id_rev);n.onsuccess=function(e){var t=L.put(f,e.target.result);t.onsuccess=a}}function c(){U[s]={ok:!0,id:l.id,rev:t},F.set(e.metadata.id,e.metadata),x(e,l.seq,o)}var f=e.data,l=e.metadata;f._doc_id_rev=l.id+"::"+l.rev,delete f._id,delete f._rev;var d=L.put(f);d.onsuccess=a,d.onerror=u}function k(e,t,n,r,o,i){function s(){c===f.length&&R(e,t,n,r,o,i)}function a(){c++,s()}var u=e.data,c=0,f=Object.keys(u._attachments);f.forEach(function(t){var n=e.data._attachments[t];if(n.stub)c++,s();else{var r=n.data;delete n.data;var o=n.digest;O(o,r,a)}})}function x(e,t,n){function r(){++i===s.length&&n()}function o(n){var o=e.data._attachments[n].digest,i=D.put({seq:t,digestSeq:o+"::"+t});i.onsuccess=r,i.onerror=function(e){e.preventDefault(),e.stopPropagation(),r()}}var i=0,s=Object.keys(e.data._attachments||{});if(!s.length)return n();for(var a=0;a<s.length;a++)o(s[a])}function O(e,t,n){var r=C.count(e);r.onsuccess=function(r){var o=r.target.result;if(o)return n();var i={digest:e,body:t},s=C.put(i);s.onsuccess=n}}for(var I,q,L,C,D,N,j=e.docs,B=0,P=j.length;P>B;B++){var M=j[B];M._id&&r.isLocalId(M._id)||(M=j[B]=r.parseDoc(M,t.new_edits),M.error&&!N&&(N=M))}if(N)return m(N);var U=new Array(j.length),F=new r.Map,J=!1,H=n._blobSupport?"blob":"base64";r.preprocessAttachments(j,H,function(e){return e?m(e):void _()})}var r=e("../../utils"),o=e("../../deps/errors"),i=e("./idb-utils"),s=e("./idb-constants"),a=s.ATTACH_AND_SEQ_STORE,u=s.ATTACH_STORE,c=s.BY_SEQ_STORE,f=s.DOC_STORE,l=s.LOCAL_STORE,d=s.META_STORE,h=i.compactRevs,p=i.decodeMetadata,v=i.encodeMetadata,g=i.idbError;t.exports=n},{"../../deps/errors":18,"../../utils":31,"./idb-constants":4,"./idb-utils":5}],4:[function(e,t,n){"use strict";n.ADAPTER_VERSION=5,n.DOC_STORE="document-store",n.BY_SEQ_STORE="by-sequence",n.ATTACH_STORE="attach-store",n.ATTACH_AND_SEQ_STORE="attach-seq-store",n.META_STORE="meta-store",n.LOCAL_STORE="local-store",n.DETECT_BLOB_SUPPORT_STORE="detect-blob-support"},{}],5:[function(e,t,n){(function(t){"use strict";function r(e,t,n){try{e.apply(t,n)}catch(r){"undefined"!=typeof PouchDB&&PouchDB.emit("error",r)}}var o=e("../../deps/errors"),i=e("../../utils"),s=e("./idb-constants");n.taskQueue={running:!1,queue:[]},n.applyNext=function(){if(!n.taskQueue.running&&n.taskQueue.queue.length){n.taskQueue.running=!0;var e=n.taskQueue.queue.shift();e.action(function(o,i){r(e.callback,this,[o,i]),n.taskQueue.running=!1,t.nextTick(n.applyNext)})}},n.idbError=function(e){return function(t){var n=t.target&&t.target.error&&t.target.error.name||t.target;e(o.error(o.IDB_ERROR,n,t.type))}},n.encodeMetadata=function(e,t,n){return{data:i.safeJsonStringify(e),winningRev:t,deletedOrLocal:n?"1":"0",seq:e.seq,id:e.id}},n.decodeMetadata=function(e){if(!e)return null;var t=i.safeJsonParse(e.data);return t.winningRev=e.winningRev,t.deletedOrLocal="1"===e.deletedOrLocal,t.seq=e.seq,t},n.decodeDoc=function(e){if(!e)return e;var t=i.lastIndexOf(e._doc_id_rev,":");return e._id=e._doc_id_rev.substring(0,t-1),e._rev=e._doc_id_rev.substring(t+1),delete e._doc_id_rev,e},n.readBlobData=function(e,t,n,r){n?e?"string"!=typeof e?i.readAsBinaryString(e,function(e){r(i.btoa(e))}):r(e):r(""):e?"string"!=typeof e?r(e):(e=i.fixBinary(atob(e)),r(i.createBlob([e],{type:t}))):r(i.createBlob([""],{type:t}))},n.fetchAttachmentsIfNecessary=function(e,t,n,r){function o(){++u===a.length&&r&&r()}function i(e,t){var r=e._attachments[t],i=r.digest,a=n.objectStore(s.ATTACH_STORE).get(i);a.onsuccess=function(e){r.body=e.target.result.body,o()}}var a=Object.keys(e._attachments||{});if(!a.length)return r&&r();var u=0;a.forEach(function(n){t.attachments&&t.include_docs?i(e,n):(e._attachments[n].stub=!0,o())})},n.postProcessAttachments=function(e){return i.Promise.all(e.map(function(e){if(e.doc&&e.doc._attachments){var t=Object.keys(e.doc._attachments);return i.Promise.all(t.map(function(t){var r=e.doc._attachments[t];if("body"in r){var o=r.body,s=r.content_type;return new i.Promise(function(a){n.readBlobData(o,s,!0,function(n){e.doc._attachments[t]=i.extend(i.pick(r,["digest","content_type"]),{data:n}),a()})})}}))}}))},n.compactRevs=function(e,t,n){function r(){f--,f||o()}function o(){i.length&&i.forEach(function(e){var t=c.index("digestSeq").count(IDBKeyRange.bound(e+"::",e+"::",!1,!1));t.onsuccess=function(t){var n=t.target.result;n||u["delete"](e)}})}var i=[],a=n.objectStore(s.BY_SEQ_STORE),u=n.objectStore(s.ATTACH_STORE),c=n.objectStore(s.ATTACH_AND_SEQ_STORE),f=e.length;e.forEach(function(e){var n=a.index("_doc_id_rev"),o=t+"::"+e;n.getKey(o).onsuccess=function(e){var t=e.target.result;if("number"!=typeof t)return r();a["delete"](t);var n=c.index("seq").openCursor(IDBKeyRange.only(t));n.onsuccess=function(e){var t=e.target.result;if(t){var n=t.value.digestSeq.split("::")[0];i.push(n),c["delete"](t.primaryKey),t["continue"]()}else r()}}})}}).call(this,e("_process"))},{"../../deps/errors":18,"../../utils":31,"./idb-constants":4,_process:40}],6:[function(e,t){(function(n){"use strict";function r(e,t){var n=this;I.queue.push({action:function(t){o(n,e,t)},callback:t}),w()}function o(e,t,o){function i(e){var t=e.createObjectStore(_,{keyPath:"id"});e.createObjectStore(g,{autoIncrement:!0}).createIndex("_doc_id_rev","_doc_id_rev",{unique:!0}),e.createObjectStore(v,{keyPath:"digest"}),e.createObjectStore(b,{keyPath:"id",autoIncrement:!1}),e.createObjectStore(m),t.createIndex("deletedOrLocal","deletedOrLocal",{unique:!1}),e.createObjectStore(y,{keyPath:"_id"});var n=e.createObjectStore(p,{autoIncrement:!0});n.createIndex("seq","seq"),n.createIndex("digestSeq","digestSeq",{unique:!0})}function f(e,t){var n=e.objectStore(_);n.createIndex("deletedOrLocal","deletedOrLocal",{unique:!1}),n.openCursor().onsuccess=function(e){var r=e.target.result;if(r){var o=r.value,i=a.isDeleted(o);o.deletedOrLocal=i?"1":"0",n.put(o),r["continue"]()}else t()}}function l(e){e.createObjectStore(y,{keyPath:"_id"}).createIndex("_doc_id_rev","_doc_id_rev",{unique:!0})}function w(e,t){var n=e.objectStore(y),r=e.objectStore(_),o=e.objectStore(g),i=r.openCursor();i.onsuccess=function(e){var i=e.target.result;if(i){var s=i.value,c=s.id,f=a.isLocalId(c),l=u.winningRev(s);if(f){var d=c+"::"+l,h=c+"::",p=c+"::~",v=o.index("_doc_id_rev"),g=IDBKeyRange.bound(h,p,!1,!1),m=v.openCursor(g);m.onsuccess=function(e){if(m=e.target.result){var t=m.value;t._doc_id_rev===d&&n.put(t),o["delete"](m.primaryKey),m["continue"]()}else r["delete"](i.primaryKey),i["continue"]()}}else i["continue"]()}else t&&t()}}function I(e){var t=e.createObjectStore(p,{autoIncrement:!0});t.createIndex("seq","seq"),t.createIndex("digestSeq","digestSeq",{unique:!0})}function L(e,t){var n=e.objectStore(g),r=e.objectStore(v),o=e.objectStore(p),i=r.count();i.onsuccess=function(e){var r=e.target.result;return r?void(n.openCursor().onsuccess=function(e){var n=e.target.result;if(!n)return t();for(var r=n.value,i=n.primaryKey,s=Object.keys(r._attachments||{}),a={},u=0;u<s.length;u++){var c=r._attachments[s[u]];a[c.digest]=!0}var f=Object.keys(a);for(u=0;u<f.length;u++){var l=f[u];o.put({seq:i,digestSeq:l+"::"+i})}n["continue"]()}):t()}}function C(e){function t(e){return e.data?A(e):(e.deletedOrLocal="1"===e.deletedOrLocal,e)}var n=e.objectStore(g),r=e.objectStore(_),o=r.openCursor();o.onsuccess=function(e){function o(){var e=a.id+"::",t=a.id+"::",r=n.index("_doc_id_rev").openCursor(IDBKeyRange.bound(e,t)),o=0;r.onsuccess=function(e){var t=e.target.result;if(!t)return a.seq=o,i();var n=t.primaryKey;n>o&&(o=n),t["continue"]()}}function i(){var e=T(a,a.winningRev,a.deletedOrLocal),t=r.put(e);t.onsuccess=function(){s["continue"]()}}var s=e.target.result;if(s){var a=t(s.value);return a.winningRev=a.winningRev||u.winningRev(a),a.seq?i():void o()}}}function D(e,t,n){function r(){n(null,{total_rows:e,offset:t.skip,rows:k})}var o="startkey"in t?t.startkey:!1,i="endkey"in t?t.endkey:!1,s="key"in t?t.key:!1,f=t.skip||0,l="number"==typeof t.limit?t.limit:-1,d=t.inclusive_end!==!1,h="descending"in t&&t.descending?"prev":null,p=!1;h&&o&&i&&(p=i,i=!1);var m=null;try{o&&i?m=IDBKeyRange.bound(o,i,!1,!d):o?m=h?IDBKeyRange.upperBound(o):IDBKeyRange.lowerBound(o):i?m=h?IDBKeyRange.lowerBound(i,!d):IDBKeyRange.upperBound(i,!d):s&&(m=IDBKeyRange.only(s))}catch(y){return"DataError"===y.name&&0===y.code?n(null,{total_rows:e,offset:t.skip,rows:[]}):n(c.error(c.IDB_ERROR,y.name,y.message))}var b=[_,g];t.attachments&&b.push(v);var w=M.transaction(b,"readonly");w.oncomplete=function(){t.attachments?x(k).then(r):r()};var E=w.objectStore(_),T=h?E.openCursor(m,h):E.openCursor(m),k=[];T.onsuccess=function(e){function n(e,n){var o={id:e.id,key:e.id,value:{rev:i}};t.include_docs&&(o.doc=n,t.conflicts&&(o.doc._conflicts=u.collectConflicts(e)),R(o.doc,t,w));var s=a.isDeleted(e,i);if("ok"===t.deleted)s&&(o.value.deleted=!0,o.doc=null),k.push(o);else if(!s&&f--<=0){if(p){if(d&&o.key<p)return;if(!d&&o.key<=p)return}if(k.push(o),0===--l)return}r["continue"]()}if(e.target.result){var r=e.target.result,o=A(r.value),i=o.winningRev;if(t.include_docs){var s=w.objectStore(g).index("_doc_id_rev"),c=o.id+"::"+i;s.get(c).onsuccess=function(e){n(A(r.value),S(e.target.result))}}else n(o)}}}function N(t){if(-1!==e._docCount)return t(null,e._docCount);var n,r=M.transaction([_],"readonly"),o=r.objectStore(_).index("deletedOrLocal");o.count(IDBKeyRange.only("0")).onsuccess=function(e){n=e.target.result},r.onerror=k(t),r.oncomplete=function(){e._docCount=n,t(null,e._docCount)}}var j=t.name,B=null,P=!1,M=null;e._docCount=-1,e._blobSupport=null,e._name=j,e.type=function(){return"idb"},e._id=a.toPromise(function(e){e(null,B)}),e._bulkDocs=function(t,n,o){d(t,n,e,M,r.Changes,o)},e._get=function(e,t,n){function r(){n(s,{doc:o,metadata:i,ctx:u})}var o,i,s,u;t=a.clone(t),u=t.ctx?t.ctx:M.transaction([_,g,v],"readonly"),u.objectStore(_).get(e).onsuccess=function(e){if(i=A(e.target.result),!i)return s=c.error(c.MISSING_DOC,"missing"),r();
if(a.isDeleted(i)&&!t.rev)return s=c.error(c.MISSING_DOC,"deleted"),r();var n=u.objectStore(g),f=t.rev||i.winningRev,l=i.id+"::"+f;n.index("_doc_id_rev").get(l).onsuccess=function(e){return o=e.target.result,o&&(o=S(o)),o?void r():(s=c.error(c.MISSING_DOC,"missing"),r())}}},e._getAttachment=function(e,t,n){var r;t=a.clone(t),r=t.ctx?t.ctx:M.transaction([_,g,v],"readonly");var o=e.digest,i=e.content_type;r.objectStore(v).get(o).onsuccess=function(e){var r=e.target.result.body;O(r,i,t.encode,function(e){n(null,e)})}},e._allDocs=function(e,t){N(function(n,r){return n?t(n):0===e.limit?t(null,{total_rows:r,offset:e.skip,rows:[]}):void D(r,e,t)})},e._info=function(e){N(function(t,n){if(t)return e(t);if(null===M){var r=new Error("db isn't open");return r.id="idbNull",e(r)}var o=0,i=M.transaction([g],"readonly");i.objectStore(g).openCursor(null,"prev").onsuccess=function(e){var t=e.target.result;o=t?t.key:0},i.oncomplete=function(){e(null,{doc_count:n,update_seq:o})}})},e._changes=function(t){function n(e){function n(){return a.seq!==s?e["continue"]():a.winningRev===i._rev?o(i):void r()}function r(){var e=i._id+"::"+a.winningRev,t=m.index("_doc_id_rev").openCursor(IDBKeyRange.bound(e,e+""));t.onsuccess=function(e){o(S(e.target.result.value))}}function o(n){var r=t.processChange(n,a,t);r.seq=a.seq,E(r)&&(w++,h&&b.push(r),t.attachments&&t.include_docs?R(n,t,p,function(){x([r]).then(function(){t.onChange(r)})}):t.onChange(r)),w!==d&&e["continue"]()}var i=S(e.value),s=e.key;if(l=s,c&&!c.has(i._id))return e["continue"]();var a;return(a=T.get(i._id))?n():void(y.get(i._id).onsuccess=function(e){a=A(e.target.result),T.set(i._id,a),n()})}function o(e){var t=e.target.result;t&&n(t)}function i(){var e=[_,g];t.attachments&&e.push(v),p=M.transaction(e,"readonly"),p.onerror=k(t.complete),p.oncomplete=s,m=p.objectStore(g),y=p.objectStore(_);var n;n=f?m.openCursor(null,f):m.openCursor(IDBKeyRange.lowerBound(t.since,!0)),n.onsuccess=o}function s(){function e(){t.complete(null,{results:b,last_seq:l})}!t.continuous&&t.attachments?x(b).then(e):e()}if(t=a.clone(t),t.continuous){var u=j+":"+a.uuid();return r.Changes.addListener(j,u,e,t),r.Changes.notify(j),{cancel:function(){r.Changes.removeListener(j,u)}}}var c=t.doc_ids&&new a.Set(t.doc_ids),f=t.descending?"prev":null;t.since=t.since||0;var l=t.since,d="limit"in t?t.limit:-1;0===d&&(d=1);var h;h="returnDocs"in t?t.returnDocs:!0;var p,m,y,b=[],w=0,E=a.filterChange(t),T=new a.Map;i()},e._close=function(e){return null===M?e(c.error(c.NOT_OPEN)):(M.close(),delete q[j],M=null,void e())},e._getRevisionTree=function(e,t){var n=M.transaction([_],"readonly"),r=n.objectStore(_).get(e);r.onsuccess=function(e){var n=A(e.target.result);n?t(null,n.rev_tree):t(c.error(c.MISSING_DOC))}},e._doCompaction=function(e,t,n){var r=M.transaction([_,g,v,p],"readwrite"),o=r.objectStore(_);o.get(e).onsuccess=function(n){var o=A(n.target.result);u.traverseRevTree(o.rev_tree,function(e,n,r,o,i){var s=n+"-"+r;-1!==t.indexOf(s)&&(i.status="missing")}),E(t,e,r);var i=o.winningRev,s=o.deletedOrLocal;r.objectStore(_).put(T(o,i,s))},r.onerror=k(n),r.oncomplete=function(){a.call(n)}},e._getLocal=function(e,t){var n=M.transaction([y],"readonly"),r=n.objectStore(y).get(e);r.onerror=k(t),r.onsuccess=function(e){var n=e.target.result;n?(delete n._doc_id_rev,t(null,n)):t(c.error(c.MISSING_DOC))}},e._putLocal=function(e,t,n){"function"==typeof t&&(n=t,t={}),delete e._revisions;var r=e._rev,o=e._id;e._rev=r?"0-"+(parseInt(r.split("-")[1],10)+1):"0-1";var i,s=t.ctx;s||(s=M.transaction([y],"readwrite"),s.onerror=k(n),s.oncomplete=function(){i&&n(null,i)});var a,u=s.objectStore(y);r?(a=u.get(o),a.onsuccess=function(o){var s=o.target.result;if(s&&s._rev===r){var a=u.put(e);a.onsuccess=function(){i={ok:!0,id:e._id,rev:e._rev},t.ctx&&n(null,i)}}else n(c.error(c.REV_CONFLICT))}):(a=u.add(e),a.onerror=function(e){n(c.error(c.REV_CONFLICT)),e.preventDefault(),e.stopPropagation()},a.onsuccess=function(){i={ok:!0,id:e._id,rev:e._rev},t.ctx&&n(null,i)})},e._removeLocal=function(e,t){var n,r=M.transaction([y],"readwrite");r.oncomplete=function(){n&&t(null,n)};var o=e._id,i=r.objectStore(y),s=i.get(o);s.onerror=k(t),s.onsuccess=function(r){var s=r.target.result;s&&s._rev===e._rev?(i["delete"](o),n={ok:!0,id:o,rev:"0-0"}):t(c.error(c.MISSING_DOC))}};var U=q[j];if(U)return M=U.idb,B=U.instanceId,e._blobSupport=U.blobSupport,void n.nextTick(function(){o(null,e)});var F=indexedDB.open(j,h);"openReqList"in r||(r.openReqList={}),r.openReqList[j]=F,F.onupgradeneeded=function(e){function t(){var e=o[s-1];s++,e&&e(r,t)}var n=e.target.result;if(e.oldVersion<1)return i(n);var r=e.currentTarget.transaction;e.oldVersion<3&&l(n),e.oldVersion<4&&I(n);var o=[f,w,L,C],s=e.oldVersion;t()},F.onsuccess=function(t){M=t.target.result,M.onversionchange=function(){M.close(),delete q[j]},M.onabort=function(){M.close(),delete q[j]};var n=M.transaction([b,m],"readwrite"),r=n.objectStore(b).get(b);r.onsuccess=function(t){var r=function(){null!==e._blobSupport&&P&&(q[j]={idb:M,instanceId:B,blobSupport:e._blobSupport,loaded:!0},o(null,e))},i=t.target.result||{id:b};j+"_id"in i?(B=i[j+"_id"],P=!0,r()):(B=a.uuid(),i[j+"_id"]=B,n.objectStore(b).put(i).onsuccess=function(){P=!0,r()}),s||(s=new a.Promise(function(e,t){var r=a.createBlob([a.fixBinary(a.atob("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVQYV2NgYAAAAAMAAWgmWQ0AAAAASUVORK5CYII="))],{type:"image/png"});n.objectStore(m).put(r,"key"),n.oncomplete=function(){var n=M.transaction([m],"readwrite"),r=n.objectStore(m).get("key");r.onerror=t,r.onsuccess=function(t){var n=t.target.result,r=URL.createObjectURL(n);a.ajax({url:r,cache:!0,binary:!0},function(t,n){e(t&&405===t.status?!0:!(!n||"image/png"!==n.type)),URL.revokeObjectURL(r)})}}})["catch"](function(){return!1})),s.then(function(t){e._blobSupport=t,r()})}},F.onerror=k(o)}function i(e,t,n){"openReqList"in r||(r.openReqList={}),r.Changes.removeAllListeners(e),r.openReqList[e]&&r.openReqList[e].result&&r.openReqList[e].result.close();var o=indexedDB.deleteDatabase(e);o.onsuccess=function(){r.openReqList[e]&&(r.openReqList[e]=null),a.hasLocalStorage()&&e in localStorage&&delete localStorage[e],delete q[e],n(null,{ok:!0})},o.onerror=k(n)}var s,a=e("../../utils"),u=e("../../merge"),c=e("../../deps/errors"),f=e("./idb-utils"),l=e("./idb-constants"),d=e("./idb-bulk-docs"),h=l.ADAPTER_VERSION,p=l.ATTACH_AND_SEQ_STORE,v=l.ATTACH_STORE,g=l.BY_SEQ_STORE,m=l.DETECT_BLOB_SUPPORT_STORE,_=l.DOC_STORE,y=l.LOCAL_STORE,b=l.META_STORE,w=f.applyNext,E=f.compactRevs,S=f.decodeDoc,A=f.decodeMetadata,T=f.encodeMetadata,R=f.fetchAttachmentsIfNecessary,k=f.idbError,x=f.postProcessAttachments,O=f.readBlobData,I=f.taskQueue,q={};r.valid=function(){var e="undefined"!=typeof openDatabase&&/Safari/.test(navigator.userAgent)&&!/Chrome/.test(navigator.userAgent);return!e&&"undefined"!=typeof indexedDB&&"undefined"!=typeof IDBKeyRange},r.destroy=a.toPromise(function(e,t,n){I.queue.push({action:function(n){i(e,t,n)},callback:n}),w()}),r.Changes=new a.Changes,t.exports=r}).call(this,e("_process"))},{"../../deps/errors":18,"../../merge":26,"../../utils":31,"./idb-bulk-docs":3,"./idb-constants":4,"./idb-utils":5,_process:40}],7:[function(e,t){t.exports=["idb","websql"]},{}],8:[function(e,t){"use strict";function n(e,t,n,s,v,g){function m(){return O?g(O):(v.notify(n._name),n._docCount=-1,void g(null,I))}function _(e,t){var n="SELECT count(*) as cnt FROM "+c+" WHERE digest=?";x.executeSql(n,[e],function(n,r){if(0===r.rows.item(0).cnt){var i=o.error(o.MISSING_STUB,"unknown stub attachment with digest "+e);t(i)}else t()})}function y(e){function t(){++o===n.length&&e(r)}var n=[];if(R.forEach(function(e){e.data&&e.data._attachments&&Object.keys(e.data._attachments).forEach(function(t){var r=e.data._attachments[t];r.stub&&n.push(r.digest)})}),!n.length)return e();var r,o=0;n.forEach(function(e){_(e,function(e){e&&!r&&(r=e),t()})})}function b(e,t,o,i,s,c,p){function v(){function t(e,t){function r(){return++i===s.length&&t(),!1}function o(t){var o="INSERT INTO "+f+" (digest, seq) VALUES (?,?)",i=[n._attachments[t].digest,e];x.executeSql(o,i,r,r)}var i=0,s=Object.keys(n._attachments||{});if(!s.length)return t();for(var a=0;a<s.length;a++)o(s[a])}var n=e.data,r=o?1:0,i=n._id,s=n._rev,a=d(n),c="INSERT INTO "+u+" (doc_id, rev, json, deleted) VALUES (?, ?, ?, ?);",h=[i,s,a,r];x.executeSql(c,h,function(e,n){var r=n.insertId;t(r,function(){y(e,r)})},function(){var e=l("seq",u,null,"doc_id=? AND rev=?");return x.executeSql(e,[i,s],function(e,n){var o=n.rows.item(0).seq,c="UPDATE "+u+" SET json=?, deleted=? WHERE doc_id=? AND rev=?;",f=[a,r,i,s];e.executeSql(c,f,function(e){t(o,function(){y(e,o)})})}),!1})}function g(e){b||(e?(b=e,i(b)):w===E.length&&v())}function m(e){w++,g(e)}function _(){if(s&&n.auto_compaction){var t=e.metadata.id,o=r.compactTree(e.metadata);h(o,t,x)}}function y(n,o){_(),e.metadata.seq=o,delete e.metadata.rev;var c=s?"UPDATE "+a+" SET json=?, max_seq=?, winningseq=(SELECT seq FROM "+u+" WHERE doc_id="+a+".id AND rev=?) WHERE id=?":"INSERT INTO "+a+" (id, winningseq, max_seq, json) VALUES (?,?,?,?);",f=r.safeJsonStringify(e.metadata),l=e.metadata.id,d=s?[f,o,t,l]:[l,o,o,f];n.executeSql(c,d,function(){I[p]={ok:!0,id:e.metadata.id,rev:t},q.set(l,e.metadata),i()})}var b=null,w=0;e.data._id=e.metadata.id,e.data._rev=e.metadata.rev;var E=Object.keys(e.data._attachments||{});o&&(e.data._deleted=!0),E.forEach(function(t){var n=e.data._attachments[t];if(n.stub)w++,g();else{var r=n.data;delete n.data;var o=n.digest;S(o,r,m)}}),E.length||v()}function w(){r.processDocs(R,n,q,x,I,b,t)}function E(e){function t(){++n===R.length&&e()}if(!R.length)return e();var n=0;R.forEach(function(e){if(e._id&&r.isLocalId(e._id))return t();var n=e.metadata.id;x.executeSql("SELECT json FROM "+a+" WHERE id = ?",[n],function(e,o){if(o.rows.length){var i=r.safeJsonParse(o.rows.item(0).json);q.set(n,i)}t()})})}function S(e,t,n){var r="SELECT digest FROM "+c+" WHERE digest=?";x.executeSql(r,[e],function(o,s){return s.rows.length?n():(r="INSERT INTO "+c+" (digest, body, escaped) VALUES (?,?,1)",void o.executeSql(r,[e,i.escapeBlob(t)],function(){n()},function(){return n(),!1}))})}var A=t.new_edits,T=e.docs,R=T.map(function(e){if(e._id&&r.isLocalId(e._id))return e;var t=r.parseDoc(e,A);return t}),k=R.filter(function(e){return e.error});if(k.length)return g(k[0]);var x,O,I=new Array(R.length),q=new r.Map;r.preprocessAttachments(R,"binary",function(e){return e?g(e):void s.transaction(function(e){x=e,y(function(e){e?O=e:E(w)})},p(g),m)})}var r=e("../../utils"),o=e("../../deps/errors"),i=e("./websql-utils"),s=e("./websql-constants"),a=s.DOC_STORE,u=s.BY_SEQ_STORE,c=s.ATTACH_STORE,f=s.ATTACH_AND_SEQ_STORE,l=i.select,d=i.stringifyDoc,h=i.compactRevs,p=i.unknownError;t.exports=n},{"../../deps/errors":18,"../../utils":31,"./websql-constants":9,"./websql-utils":10}],9:[function(e,t,n){"use strict";function r(e){return"'"+e+"'"}n.ADAPTER_VERSION=7,n.DOC_STORE=r("document-store"),n.BY_SEQ_STORE=r("by-sequence"),n.ATTACH_STORE=r("attach-store"),n.LOCAL_STORE=r("local-store"),n.META_STORE=r("metadata-store"),n.ATTACH_AND_SEQ_STORE=r("attach-seq-store")},{}],10:[function(e,t){"use strict";function n(e){return e.replace(/\u0002/g,"").replace(/\u0001/g,"").replace(/\u0000/g,"")}function r(e){return e.replace(/\u0001\u0001/g,"\x00").replace(/\u0001\u0002/g,"").replace(/\u0002\u0002/g,"")}function o(e){return delete e._id,delete e._rev,JSON.stringify(e)}function i(e,t,n){return e=JSON.parse(e),e._id=t,e._rev=n,e}function s(e){for(var t="(";e--;)t+="?",e&&(t+=",");return t+")"}function a(e,t,n,r,o){return"SELECT "+e+" FROM "+("string"==typeof t?t:t.join(" JOIN "))+(n?" ON "+n:"")+(r?" WHERE "+("string"==typeof r?r:r.join(" AND ")):"")+(o?" ORDER BY "+o:"")}function u(e,t,n){function r(){++i===e.length&&o()}function o(){if(a.length){var e="SELECT DISTINCT digest AS digest FROM "+g+" WHERE seq IN "+s(a.length);n.executeSql(e,a,function(e,t){for(var n=[],r=0;r<t.rows.length;r++)n.push(t.rows.item(r).digest);if(n.length){var o="DELETE FROM "+g+" WHERE seq IN ("+a.map(function(){return"?"}).join(",")+")";e.executeSql(o,a,function(e){var t="SELECT digest FROM "+g+" WHERE digest IN ("+n.map(function(){return"?"}).join(",")+")";e.executeSql(t,n,function(e,t){for(var r=new l.Set,o=0;o<t.rows.length;o++)r.add(t.rows.item(o).digest);n.forEach(function(t){r.has(t)||(e.executeSql("DELETE FROM "+g+" WHERE digest=?",[t]),e.executeSql("DELETE FROM "+v+" WHERE digest=?",[t]))})})})}})}}if(e.length){var i=0,a=[];e.forEach(function(e){var o="SELECT seq FROM "+p+" WHERE doc_id=? AND rev=?";n.executeSql(o,[t,e],function(e,t){if(!t.rows.length)return r();var n=t.rows.item(0).seq;a.push(n),e.executeSql("DELETE FROM "+p+" WHERE seq=?",[n],r)})})}}function c(e){return function(t){var n=t&&t.constructor.toString().match(/function ([^\(]+)/),r=n&&n[1]||t.type,o=t.target||t.message;e(d.error(d.WSQ_ERROR,o,r))}}function f(e){if("size"in e)return 1e6*e.size;var t=/Android/.test(window.navigator.userAgent);return t?5e6:1}var l=e("../../utils"),d=e("../../deps/errors"),h=e("./websql-constants"),p=h.BY_SEQ_STORE,v=h.ATTACH_STORE,g=h.ATTACH_AND_SEQ_STORE;t.exports={escapeBlob:n,unescapeBlob:r,stringifyDoc:o,unstringifyDoc:i,qMarks:s,select:a,compactRevs:u,unknownError:c,getSize:f}},{"../../deps/errors":18,"../../utils":31,"./websql-constants":9}],11:[function(e,t){"use strict";function n(e,t,n,r,o){function s(){++c===u.length&&o&&o()}function a(e,t){var o=e._attachments[t],a={encode:!0,ctx:r};n._getAttachment(o,a,function(n,r){e._attachments[t]=i.extend(i.pick(o,["digest","content_type"]),{data:r}),s()})}var u=Object.keys(e._attachments||{});if(!u.length)return o&&o();var c=0;u.forEach(function(n){t.attachments&&t.include_docs?a(e,n):(e._attachments[n].stub=!0,s())})}function r(e,t,n,r){var o=R[e];return o||(o=R[e]=k(e,t,n,r)),o}function o(e,t){function c(){i.hasLocalStorage()&&(window.localStorage["_pouch__websqldb_"+W._name]=!0),t(null,W)}function R(e,t){e.executeSql(q),e.executeSql("ALTER TABLE "+p+" ADD COLUMN deleted TINYINT(1) DEFAULT 0",[],function(){e.executeSql(O),e.executeSql("ALTER TABLE "+h+" ADD COLUMN local TINYINT(1) DEFAULT 0",[],function(){e.executeSql("CREATE INDEX IF NOT EXISTS 'doc-store-local-idx' ON "+h+" (local, id)");var n="SELECT "+h+".winningseq AS seq, "+h+".json AS metadata FROM "+p+" JOIN "+h+" ON "+p+".seq = "+h+".winningseq";e.executeSql(n,[],function(e,n){for(var r=[],o=[],s=0;s<n.rows.length;s++){var a=n.rows.item(s),u=a.seq,c=JSON.parse(a.metadata);i.isDeleted(c)&&r.push(u),i.isLocalId(c.id)&&o.push(c.id)}e.executeSql("UPDATE "+h+"SET local = 1 WHERE id IN "+y(o.length),o,function(){e.executeSql("UPDATE "+p+" SET deleted = 1 WHERE seq IN "+y(r.length),r,t)})})})})}function k(e,t){var n="CREATE TABLE IF NOT EXISTS "+g+" (id UNIQUE, rev, json)";e.executeSql(n,[],function(){var n="SELECT "+h+".id AS id, "+p+".json AS data FROM "+p+" JOIN "+h+" ON "+p+".seq = "+h+".winningseq WHERE local = 1";e.executeSql(n,[],function(e,n){function r(){if(!o.length)return t(e);var n=o.shift(),i=JSON.parse(n.data)._rev;e.executeSql("INSERT INTO "+g+" (id, rev, json) VALUES (?,?,?)",[n.id,i,n.data],function(e){e.executeSql("DELETE FROM "+h+" WHERE id=?",[n.id],function(e){e.executeSql("DELETE FROM "+p+" WHERE seq=?",[n.seq],function(){r()})})})}for(var o=[],i=0;i<n.rows.length;i++)o.push(n.rows.item(i));r()})})}function j(e,t){function n(n){function r(){if(!n.length)return t(e);var o=n.shift(),i=u(o.hex,G),s=i.lastIndexOf("::"),a=i.substring(0,s),c=i.substring(s+2),f="UPDATE "+p+" SET doc_id=?, rev=? WHERE doc_id_rev=?";e.executeSql(f,[a,c,i],function(){r()})}r()}var r="ALTER TABLE "+p+" ADD COLUMN doc_id";e.executeSql(r,[],function(e){var t="ALTER TABLE "+p+" ADD COLUMN rev";e.executeSql(t,[],function(e){e.executeSql(I,[],function(e){var t="SELECT hex(doc_id_rev) as hex FROM "+p;e.executeSql(t,[],function(e,t){for(var r=[],o=0;o<t.rows.length;o++)r.push(t.rows.item(o));n(r)})})})})}function B(e,t){function n(e){var n="SELECT COUNT(*) AS cnt FROM "+v;e.executeSql(n,[],function(e,n){function r(){var n=E(N+", "+h+".id AS id",[h,p],D,null,h+".id ");n+=" LIMIT "+s+" OFFSET "+i,i+=s,e.executeSql(n,[],function(e,n){function o(e,t){var n=i[e]=i[e]||[];-1===n.indexOf(t)&&n.push(t)}if(!n.rows.length)return t(e);for(var i={},s=0;s<n.rows.length;s++)for(var a=n.rows.item(s),u=w(a.data,a.id,a.rev),c=Object.keys(u._attachments||{}),f=0;f<c.length;f++){var l=u._attachments[c[f]];o(l.digest,a.seq)}var d=[];if(Object.keys(i).forEach(function(e){var t=i[e];t.forEach(function(t){d.push([e,t])})}),!d.length)return r();var h=0;d.forEach(function(t){var n="INSERT INTO "+_+" (digest, seq) VALUES (?,?)";e.executeSql(n,t,function(){++h===d.length&&r()})})})}var o=n.rows.item(0).cnt;if(!o)return t(e);var i=0,s=10;r()})}var r="CREATE TABLE IF NOT EXISTS "+_+" (digest, seq INTEGER)";e.executeSql(r,[],function(e){e.executeSql(C,[],function(e){e.executeSql(L,[],n)})})}function P(e,t){var n="ALTER TABLE "+v+" ADD COLUMN escaped TINYINT(1) DEFAULT 0";e.executeSql(n,[],t)}function M(e,t){var n="ALTER TABLE "+h+" ADD COLUMN max_seq INTEGER";e.executeSql(n,[],function(e){var n="UPDATE "+h+" SET max_seq=(SELECT MAX(seq) FROM "+p+" WHERE doc_id=id)";e.executeSql(n,[],function(e){var n="CREATE UNIQUE INDEX IF NOT EXISTS 'doc-max-seq-idx' ON "+h+" (max_seq)";e.executeSql(n,[],t)})})}function U(e,t){e.executeSql('SELECT HEX("a") AS hex',[],function(e,n){var r=n.rows.item(0).hex;G=2===r.length?"UTF-8":"UTF-16",t()})}function F(){for(;z.length>0;){var e=z.pop();e(null,Q)}}function J(e,t){if(0===t){var n="CREATE TABLE IF NOT EXISTS "+m+" (dbid, db_version INTEGER)",r="CREATE TABLE IF NOT EXISTS "+v+" (digest UNIQUE, escaped TINYINT(1), body BLOB)",o="CREATE TABLE IF NOT EXISTS "+_+" (digest, seq INTEGER)",s="CREATE TABLE IF NOT EXISTS "+h+" (id unique, json, winningseq, max_seq INTEGER UNIQUE)",a="CREATE TABLE IF NOT EXISTS "+p+" (seq INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, json, deleted TINYINT(1), doc_id, rev)",u="CREATE TABLE IF NOT EXISTS "+g+" (id UNIQUE, rev, json)";e.executeSql(r),e.executeSql(u),e.executeSql(o,[],function(){e.executeSql(L),e.executeSql(C)}),e.executeSql(s,[],function(){e.executeSql(q),e.executeSql(a,[],function(){e.executeSql(O),e.executeSql(I),e.executeSql(n,[],function(){var t="INSERT INTO "+m+" (db_version, dbid) VALUES (?,?)";Q=i.uuid();var n=[d,Q];e.executeSql(t,n,function(){F()})})})})}else{var c=function(){var n=d>t;n&&e.executeSql("UPDATE "+m+" SET db_version = "+d);var r="SELECT dbid FROM "+m;e.executeSql(r,[],function(e,t){Q=t.rows.item(0).dbid,F()})},f=[R,k,j,B,P,M,c],l=t,y=function(e){f[l-1](e,y),l++};y(e)}}function H(){X.transaction(function(e){U(e,function(){V(e)})},A(t),c)}function V(e){var t="SELECT sql FROM sqlite_master WHERE tbl_name = "+m;e.executeSql(t,[],function(e,t){t.rows.length?/db_version/.test(t.rows.item(0).sql)?e.executeSql("SELECT db_version FROM "+m,[],function(e,t){var n=t.rows.item(0).db_version;J(e,n)}):e.executeSql("ALTER TABLE "+m+" ADD COLUMN db_version INTEGER",[],function(){J(e,1)}):J(e,0)})}function Y(e,t){if(-1!==W._docCount)return t(W._docCount);var n=E("COUNT("+h+".id) AS 'num'",[h,p],D,p+".deleted=0");e.executeSql(n,[],function(e,n){W._docCount=n.rows.item(0).num,t(W._docCount)})}var G,W=this,Q=null,K=T(e),z=[];W._docCount=-1,W._name=e.name;var X=r(W._name,x,W._name,K);return X?("function"!=typeof X.readTransaction&&(X.readTransaction=X.transaction),i.isCordova()?window.addEventListener(W._name+"_pouch",function $(){window.removeEventListener(W._name+"_pouch",$,!1),H()},!1):H(),W.type=function(){return"websql"},W._id=i.toPromise(function(e){e(null,Q)}),W._info=function(e){X.readTransaction(function(t){Y(t,function(n){var r="SELECT MAX(seq) AS seq FROM "+p;t.executeSql(r,[],function(t,r){var o=r.rows.item(0).seq||0;e(null,{doc_count:n,update_seq:o})})})},A(e))},W._bulkDocs=function(e,t,n){l(e,t,W,X,o.Changes,n)},W._get=function(e,t,n){function r(){n(u,{doc:o,metadata:s,ctx:l})}t=i.clone(t);var o,s,u;if(!t.ctx)return void X.readTransaction(function(r){t.ctx=r,W._get(e,t,n)});var c,f,l=t.ctx;t.rev?(c=E(N,[h,p],h+".id="+p+".doc_id",[p+".doc_id=?",p+".rev=?"]),f=[e,t.rev]):(c=E(N,[h,p],D,h+".id=?"),f=[e]),l.executeSql(c,f,function(e,n){if(!n.rows.length)return u=a.error(a.MISSING_DOC,"missing"),r();var c=n.rows.item(0);return s=i.safeJsonParse(c.metadata),c.deleted&&!t.rev?(u=a.error(a.MISSING_DOC,"deleted"),r()):(o=w(c.data,s.id,c.rev),void r())})},W._allDocs=function(e,t){var r,o=[],a="startkey"in e?e.startkey:!1,u="endkey"in e?e.endkey:!1,c="key"in e?e.key:!1,f="descending"in e?e.descending:!1,l="limit"in e?e.limit:-1,d="skip"in e?e.skip:0,v=e.inclusive_end!==!1,g=[],m=[];if(c!==!1)m.push(h+".id = ?"),g.push(c);else if(a!==!1||u!==!1){if(a!==!1&&(m.push(h+".id "+(f?"<=":">=")+" ?"),g.push(a)),u!==!1){var _=f?">":"<";v&&(_+="="),m.push(h+".id "+_+" ?"),g.push(u)}c!==!1&&(m.push(h+".id = ?"),g.push(c))}"ok"!==e.deleted&&m.push(p+".deleted = 0"),X.readTransaction(function(t){Y(t,function(a){if(r=a,0!==l){var u=E(N,[h,p],D,m,h+".id "+(f?"DESC":"ASC"));u+=" LIMIT "+l+" OFFSET "+d,t.executeSql(u,g,function(t,r){for(var a=0,u=r.rows.length;u>a;a++){var c=r.rows.item(a),f=i.safeJsonParse(c.metadata),l=f.id,d=w(c.data,l,c.rev),h=d._rev,p={id:l,key:l,value:{rev:h}};if(e.include_docs&&(p.doc=d,p.doc._rev=h,e.conflicts&&(p.doc._conflicts=s.collectConflicts(f)),n(p.doc,e,W,t)),c.deleted){if("ok"!==e.deleted)continue;p.value.deleted=!0,p.doc=null}o.push(p)}})}})},A(t),function(){t(null,{total_rows:r,offset:e.skip,rows:o})})},W._changes=function(e){function t(){var t=h+".json AS metadata, "+h+".max_seq AS maxSeq, "+p+".json AS winningDoc, "+p+".rev AS winningRev ",r=h+" JOIN "+p,o=h+".id="+p+".doc_id AND "+h+".winningseq="+p+".seq",l=["maxSeq > ?"],d=[e.since];e.doc_ids&&(l.push(h+".id IN "+y(e.doc_ids.length)),d=d.concat(e.doc_ids));var v="maxSeq "+(s?"DESC":"ASC"),g=E(t,r,o,l,v),m=i.filterChange(e);e.view||e.filter||(g+=" LIMIT "+a);var _=e.since||0;X.readTransaction(function(t){t.executeSql(g,d,function(t,r){function o(t){return function(){e.onChange(t)}}for(var s=0,l=r.rows.length;l>s;s++){var d=r.rows.item(s),h=i.safeJsonParse(d.metadata);_=d.maxSeq;var p=w(d.winningDoc,h.id,d.winningRev),v=e.processChange(p,h,e);if(v.seq=d.maxSeq,m(v)&&(f++,u&&c.push(v),e.attachments&&e.include_docs?n(p,e,W,t,o(v)):o(v)()),f===a)break}})},A(e.complete),function(){e.continuous||e.complete(null,{results:c,last_seq:_})})}if(e=i.clone(e),e.continuous){var r=W._name+":"+i.uuid();return o.Changes.addListener(W._name,r,W,e),o.Changes.notify(W._name),{cancel:function(){o.Changes.removeListener(W._name,r)}}}var s=e.descending;e.since=e.since&&!s?e.since:0;var a="limit"in e?e.limit:-1;0===a&&(a=1);var u;u="returnDocs"in e?e.returnDocs:!0;var c=[],f=0;t()},W._close=function(e){e()},W._getAttachment=function(e,t,n){var r,o=t.ctx,s=e.digest,a=e.content_type,c="SELECT escaped, CASE WHEN escaped = 1 THEN body ELSE HEX(body) END AS body FROM "+v+" WHERE digest=?";o.executeSql(c,[s],function(e,o){var s=o.rows.item(0),c=s.escaped?f.unescapeBlob(s.body):u(s.body,G);t.encode?r=btoa(c):(c=i.fixBinary(c),r=i.createBlob([c],{type:a})),n(null,r)})},W._getRevisionTree=function(e,t){X.readTransaction(function(n){var r="SELECT json AS metadata FROM "+h+" WHERE id = ?";n.executeSql(r,[e],function(e,n){if(n.rows.length){var r=i.safeJsonParse(n.rows.item(0).metadata);t(null,r.rev_tree)}else t(a.error(a.MISSING_DOC))})})},W._doCompaction=function(e,t,n){return t.length?void X.transaction(function(n){var r="SELECT json AS metadata FROM "+h+" WHERE id = ?";n.executeSql(r,[e],function(n,r){var o=i.safeJsonParse(r.rows.item(0).metadata);s.traverseRevTree(o.rev_tree,function(e,n,r,o,i){var s=n+"-"+r;-1!==t.indexOf(s)&&(i.status="missing")});var a="UPDATE "+h+" SET json = ? WHERE id = ?";n.executeSql(a,[i.safeJsonStringify(o),e])}),S(t,e,n)},A(n),function(){n()}):n()},W._getLocal=function(e,t){X.readTransaction(function(n){var r="SELECT json, rev FROM "+g+" WHERE id=?";n.executeSql(r,[e],function(n,r){if(r.rows.length){var o=r.rows.item(0),i=w(o.json,e,o.rev);t(null,i)}else t(a.error(a.MISSING_DOC))})})},W._putLocal=function(e,t,n){function r(e){var r,f;i?(r="UPDATE "+g+" SET rev=?, json=? WHERE id=? AND rev=?",f=[o,c,s,i]):(r="INSERT INTO "+g+" (id, rev, json) VALUES (?,?,?)",f=[s,o,c]),e.executeSql(r,f,function(e,r){r.rowsAffected?(u={ok:!0,id:s,rev:o},t.ctx&&n(null,u)):n(a.error(a.REV_CONFLICT))},function(){return n(a.error(a.REV_CONFLICT)),!1})}"function"==typeof t&&(n=t,t={}),delete e._revisions;var o,i=e._rev,s=e._id;o=e._rev=i?"0-"+(parseInt(i.split("-")[1],10)+1):"0-1";var u,c=b(e);t.ctx?r(t.ctx):X.transaction(function(e){r(e)},A(n),function(){u&&n(null,u)})},void(W._removeLocal=function(e,t){var n;X.transaction(function(r){var o="DELETE FROM "+g+" WHERE id=? AND rev=?",i=[e._id,e._rev];r.executeSql(o,i,function(r,o){return o.rowsAffected?void(n={ok:!0,id:e._id,rev:"0-0"}):t(a.error(a.MISSING_DOC))})},A(t),function(){n&&t(null,n)})})):t(a.error(a.UNKNOWN_ERROR))}var i=e("../../utils"),s=e("../../merge"),a=e("../../deps/errors"),u=e("../../deps/parse-hex"),c=e("./websql-constants"),f=e("./websql-utils"),l=e("./websql-bulk-docs"),d=c.ADAPTER_VERSION,h=c.DOC_STORE,p=c.BY_SEQ_STORE,v=c.ATTACH_STORE,g=c.LOCAL_STORE,m=c.META_STORE,_=c.ATTACH_AND_SEQ_STORE,y=f.qMarks,b=f.stringifyDoc,w=f.unstringifyDoc,E=f.select,S=f.compactRevs,A=f.unknownError,T=f.getSize,R={},k="undefined"!=typeof navigator&&navigator.sqlitePlugin&&navigator.sqlitePlugin.openDatabase?navigator.sqlitePlugin.openDatabase.bind(navigator.sqlitePlugin):"undefined"!=typeof sqlitePlugin&&sqlitePlugin.openDatabase?sqlitePlugin.openDatabase.bind(sqlitePlugin):"undefined"!=typeof openDatabase?openDatabase:null,x=1,O="CREATE INDEX IF NOT EXISTS 'by-seq-deleted-idx' ON "+p+" (seq, deleted)",I="CREATE UNIQUE INDEX IF NOT EXISTS 'by-seq-doc-id-rev' ON "+p+" (doc_id, rev)",q="CREATE INDEX IF NOT EXISTS 'doc-winningseq-idx' ON "+h+" (winningseq)",L="CREATE INDEX IF NOT EXISTS 'attach-seq-seq-idx' ON "+_+" (seq)",C="CREATE UNIQUE INDEX IF NOT EXISTS 'attach-seq-digest-idx' ON "+_+" (digest, seq)",D=p+".seq = "+h+".winningseq",N=p+".seq AS seq, "+p+".deleted AS deleted, "+p+".json AS data, "+p+".rev AS rev, "+h+".json AS metadata";o.valid=function(){return!!k},o.destroy=i.toPromise(function(e,t,n){o.Changes.removeAllListeners(e);var s=T(t),a=r(e,x,e,s);a.transaction(function(e){var t=[h,p,v,m,g,_];t.forEach(function(t){e.executeSql("DROP TABLE IF EXISTS "+t,[])})},A(n),function(){i.hasLocalStorage()&&(delete window.localStorage["_pouch__websqldb_"+e],delete window.localStorage[e]),n(null,{ok:!0})})}),o.Changes=new i.Changes,t.exports=o},{"../../deps/errors":18,"../../deps/parse-hex":20,"../../merge":26,"../../utils":31,"./websql-bulk-docs":8,"./websql-constants":9,"./websql-utils":10}],12:[function(e,t){"use strict";function n(e,t,n){function r(){i.cancel()}a.call(this);var i=this;this.db=e,t=t?o.clone(t):{};var s=n||t.complete||function(){},u=t.complete=o.once(function(t,n){t?i.emit("error",t):i.emit("complete",n),i.removeAllListeners(),e.removeListener("destroyed",r)});s&&(i.on("complete",function(e){s(null,e)}),i.on("error",function(e){s(e)}));var c=t.onChange;c&&i.on("change",c),e.once("destroyed",r),t.onChange=function(e){t.isCancelled||(i.emit("change",e),i.startSeq&&i.startSeq<=e.seq&&(i.emit("uptodate"),i.startSeq=!1),e.deleted?i.emit("delete",e):1===e.changes.length&&"1-"===e.changes[0].rev.slice(0,2)?i.emit("create",e):i.emit("update",e))};var f=new o.Promise(function(e,n){t.complete=function(t,r){t?n(t):e(r)}});i.once("cancel",function(){c&&i.removeListener("change",c),t.complete(null,{status:"cancelled"})}),this.then=f.then.bind(f),this["catch"]=f["catch"].bind(f),this.then(function(e){u(null,e)},u),e.taskqueue.isReady?i.doChanges(t):e.taskqueue.addTask(function(){i.isCancelled?i.emit("cancel"):i.doChanges(t)})}function r(e,t,n){var r=[{rev:e._rev}];"all_docs"===n.style&&(r=i.collectLeaves(t.rev_tree).map(function(e){return{rev:e.rev}}));var s={id:t.id,changes:r,doc:e};return o.isDeleted(t,e._rev)&&(s.deleted=!0),n.conflicts&&(s.doc._conflicts=i.collectConflicts(t),s.doc._conflicts.length||delete s.doc._conflicts),s}var o=e("./utils"),i=e("./merge"),s=e("./deps/errors"),a=e("events").EventEmitter,u=e("./evalFilter"),c=e("./evalView");t.exports=n,o.inherits(n,a),n.prototype.cancel=function(){this.isCancelled=!0,this.db.taskqueue.isReady&&this.emit("cancel")},n.prototype.doChanges=function(e){var t=this,n=e.complete;if(e=o.clone(e),"live"in e&&!("continuous"in e)&&(e.continuous=e.live),e.processChange=r,"latest"===e.since&&(e.since="now"),e.since||(e.since=0),"now"===e.since)return void this.db.info().then(function(r){return t.isCancelled?void n(null,{status:"cancelled"}):(e.since=r.update_seq-1,void t.doChanges(e))},n);if(e.continuous&&"now"!==e.since&&this.db.info().then(function(e){t.startSeq=e.update_seq-1},function(e){if("idbNull"!==e.id)throw e}),"http"!==this.db.type()&&e.filter&&"string"==typeof e.filter&&!e.doc_ids)return this.filterChanges(e);"descending"in e||(e.descending=!1),e.limit=0===e.limit?1:e.limit,e.complete=n;var i=this.db._changes(e);if(i&&"function"==typeof i.cancel){var s=t.cancel;t.cancel=o.getArguments(function(e){i.cancel(),s.apply(this,e)})}},n.prototype.filterChanges=function(e){var t=this,n=e.complete;if("_view"===e.filter){if(!e.view||"string"!=typeof e.view){var r=s.error(s.BAD_REQUEST,"`view` filter parameter is not provided.");return void n(r)}var o=e.view.split("/");this.db.get("_design/"+o[0],function(r,i){if(t.isCancelled)return void n(null,{status:"cancelled"});if(r)return void n(s.generateErrorFromResponse(r));if(i&&i.views&&i.views[o[1]]){var a=c(i.views[o[1]].map);return e.filter=a,void t.doChanges(e)}var u=i.views?"missing json key: "+o[1]:"missing json key: views";r||(r=s.error(s.MISSING_DOC,u)),n(r)})}else{var i=e.filter.split("/");this.db.get("_design/"+i[0],function(r,o){if(t.isCancelled)return void n(null,{status:"cancelled"});if(r)return void n(s.generateErrorFromResponse(r));if(o&&o.filters&&o.filters[i[1]]){var a=u(o.filters[i[1]]);return e.filter=a,void t.doChanges(e)}var c=o&&o.filters?"missing json key: "+i[1]:"missing json key: filters";return r||(r=s.error(s.MISSING_DOC,c)),void n(r)})}}},{"./deps/errors":18,"./evalFilter":24,"./evalView":25,"./merge":26,"./utils":31,events:39}],13:[function(e,t){"use strict";function n(e,t,n,r){return e.get(t)["catch"](function(n){if(404===n.status)return"http"===e.type()&&o.explain404("PouchDB is just checking if a remote checkpoint exists."),{_id:t};throw n}).then(function(t){return r.cancelled?void 0:(t.last_seq=n,e.put(t))})}function r(e,t,n,r){this.src=e,this.target=t,this.id=n,this.returnValue=r}var o=e("./utils"),i=e("pouchdb-collate"),s=i.collate;r.prototype.writeCheckpoint=function(e){var t=this;return this.updateTarget(e).then(function(){return t.updateSource(e)})},r.prototype.updateTarget=function(e){return n(this.target,this.id,e,this.returnValue)},r.prototype.updateSource=function(e){var t=this;return this.readOnlySource?o.Promise.resolve(!0):n(this.src,this.id,e,this.returnValue)["catch"](function(e){var n="number"==typeof e.status&&4===Math.floor(e.status/100);if(n)return t.readOnlySource=!0,!0;throw e})},r.prototype.getCheckpoint=function(){var e=this;return e.target.get(e.id).then(function(t){return e.src.get(e.id).then(function(e){return 0===s(t.last_seq,e.last_seq)?e.last_seq:0},function(n){if(404===n.status&&t.last_seq)return e.src.put({_id:e.id,last_seq:0}).then(function(){return 0},function(n){return 401===n.status?(e.readOnlySource=!0,t.last_seq):0});throw n})})["catch"](function(e){if(404!==e.status)throw e;return 0})},t.exports=r},{"./utils":31,"pouchdb-collate":63}],14:[function(e,t){(function(n,r){"use strict";function o(e){e&&r.debug&&console.error(e)}function i(e,t,r){if(!(this instanceof i))return new i(e,t,r);var f=this;("function"==typeof t||"undefined"==typeof t)&&(r=t,t={}),e&&"object"==typeof e&&(t=e,e=void 0),"undefined"==typeof r&&(r=o),t=t||{},this.__opts=t;var l=r;f.auto_compaction=t.auto_compaction,f.prefix=i.prefix,s.call(f),f.taskqueue=new u;
var d=new c(function(o,s){r=function(e,t){return e?s(e):(delete t.then,void o(t))},t=a.clone(t);var u,c,l=t.name||e;return function(){try{if("string"!=typeof l)throw c=new Error("Missing/invalid DB name"),c.code=400,c;if(u=i.parseAdapter(l,t),t.originalName=l,t.name=u.name,t.prefix&&"http"!==u.adapter&&"https"!==u.adapter&&(t.name=t.prefix+t.name),t.adapter=t.adapter||u.adapter,f._adapter=t.adapter,f._db_name=l,!i.adapters[t.adapter])throw c=new Error("Adapter is missing"),c.code=404,c;if(!i.adapters[t.adapter].valid())throw c=new Error("Invalid Adapter"),c.code=404,c}catch(e){f.taskqueue.fail(e),f.changes=a.toPromise(function(t){t.complete&&t.complete(e)})}}(),c?s(c):(f.adapter=t.adapter,f.replicate={},f.replicate.from=function(e,t,n){return f.constructor.replicate(e,f,t,n)},f.replicate.to=function(e,t,n){return f.constructor.replicate(f,e,t,n)},f.sync=function(e,t,n){return f.constructor.sync(f,e,t,n)},f.replicate.sync=f.sync,f.destroy=a.adapterFun("destroy",function(e){var t=this,n=this.__opts||{};t.info(function(r,o){return r?e(r):void t.constructor.destroy(o.db_name,n,e)})}),i.adapters[t.adapter].call(f,t,function(e){function n(e){"destroyed"===e&&(f.emit("destroyed"),i.removeListener(l,n))}return e?void(r&&(f.taskqueue.fail(e),r(e))):(i.on(l,n),f.emit("created",f),i.emit("created",t.originalName),f.taskqueue.ready(f),void r(null,f))}),t.skipSetup&&(f.taskqueue.ready(f),n.nextTick(function(){r(null,f)})),void(a.isCordova()&&cordova.fireWindowEvent(t.name+"_pouch",{})))});d.then(function(e){l(null,e)},l),f.then=d.then.bind(d),f["catch"]=d["catch"].bind(d)}var s=e("./adapter"),a=e("./utils"),u=e("./taskqueue"),c=a.Promise;a.inherits(i,s),i.debug=e("debug"),t.exports=i}).call(this,e("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./adapter":1,"./taskqueue":30,"./utils":31,_process:40,debug:41}],15:[function(e,t){"use strict";function n(e,t){function n(t,n,r){if(e.binary||e.json||!e.processData||"string"==typeof t){if(!e.binary&&e.json&&"string"==typeof t)try{t=JSON.parse(t)}catch(o){return r(o)}}else t=JSON.stringify(t);Array.isArray(t)&&(t=t.map(function(e){return e.error||e.missing?i.generateErrorFromResponse(e):e})),r(null,t,n)}function a(e,t){var n,r;try{n=JSON.parse(e.responseText),r=i.generateErrorFromResponse(n)}catch(o){r=i.generateErrorFromResponse(e)}e.withCredentials&&0===e.status&&(r.status=405,r.statusText="Method Not Allowed"),t(r)}var u=!1,c=s.getArguments(function(e){u||(t.apply(this,e),u=!0)});"function"==typeof e&&(c=e,e={}),e=s.clone(e);var f={method:"GET",headers:{},json:!0,processData:!0,timeout:1e4,cache:!1};if(e=s.extend(!0,f,e),"GET"===e.method&&!e.cache){var l=-1!==e.url.indexOf("?");e.url+=(l?"&":"?")+"_nonce="+s.uuid(16)}var d,h;h=e.xhr?new e.xhr:new XMLHttpRequest,h.open(e.method,e.url),h.withCredentials=!0,e.json&&(e.headers.Accept="application/json",e.headers["Content-Type"]=e.headers["Content-Type"]||"application/json",e.body&&e.processData&&"string"!=typeof e.body&&(e.body=JSON.stringify(e.body))),e.binary&&(h.responseType="arraybuffer");var p=function(e,t,n){var r="";if(n){var o=new Date;o.setTime(o.getTime()+24*n*60*60*1e3),r="; expires="+o.toGMTString()}document.cookie=e+"="+t+r+"; path=/"};for(var v in e.headers)if(e.headers.hasOwnProperty(v))if("Cookie"===v){var g=e.headers[v].split("=");p(g[0],g[1],10)}else h.setRequestHeader(v,e.headers[v]);"body"in e||(e.body=null);var m=function(){u||(h.abort(),a(h,c))};return h.onreadystatechange=function(){if(4===h.readyState&&!u)if(clearTimeout(d),h.status>=200&&h.status<300){var t;t=e.binary?o([h.response||""],{type:h.getResponseHeader("Content-Type")}):h.responseText,n(t,h,c)}else a(h,c)},e.timeout>0&&(d=setTimeout(m,e.timeout),h.onprogress=function(){clearTimeout(d),d=setTimeout(m,e.timeout)},"undefined"==typeof r&&(r=-1!==Object.keys(h).indexOf("upload")),r&&(h.upload.onprogress=h.onprogress)),e.body&&e.body instanceof Blob?s.readAsBinaryString(e.body,function(e){h.send(s.fixBinary(e))}):h.send(e.body),{abort:m}}var r,o=e("./blob.js"),i=e("./errors"),s=e("../utils");t.exports=n},{"../utils":31,"./blob.js":16,"./errors":18}],16:[function(e,t){(function(e){"use strict";function n(t,n){t=t||[],n=n||{};try{return new Blob(t,n)}catch(r){if("TypeError"!==r.name)throw r;for(var o=e.BlobBuilder||e.MSBlobBuilder||e.MozBlobBuilder||e.WebKitBlobBuilder,i=new o,s=0;s<t.length;s+=1)i.append(t[s]);return i.getBlob(n.type)}}t.exports=n}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],17:[function(e,t,n){"use strict";function r(){this.store={}}function o(e){if(this.store=new r,e&&Array.isArray(e))for(var t=0,n=e.length;n>t;t++)this.add(e[t])}n.Map=r,n.Set=o,r.prototype.mangle=function(e){if("string"!=typeof e)throw new TypeError("key must be a string but Got "+e);return"$"+e},r.prototype.unmangle=function(e){return e.substring(1)},r.prototype.get=function(e){var t=this.mangle(e);return t in this.store?this.store[t]:void 0},r.prototype.set=function(e,t){var n=this.mangle(e);return this.store[n]=t,!0},r.prototype.has=function(e){var t=this.mangle(e);return t in this.store},r.prototype["delete"]=function(e){var t=this.mangle(e);return t in this.store?(delete this.store[t],!0):!1},r.prototype.forEach=function(e){var t=this,n=Object.keys(t.store);n.forEach(function(n){var r=t.store[n];n=t.unmangle(n),e(r,n)})},o.prototype.add=function(e){return this.store.set(e,!0)},o.prototype.has=function(e){return this.store.has(e)},o.prototype["delete"]=function(e){return this.store["delete"](e)}},{}],18:[function(e,t,n){"use strict";function r(e){this.status=e.status,this.name=e.error,this.message=e.reason,this.error=!0}r.prototype__proto__=Error.prototype,r.prototype.toString=function(){return JSON.stringify({status:this.status,name:this.name,message:this.message})},n.UNAUTHORIZED=new r({status:401,error:"unauthorized",reason:"Name or password is incorrect."}),n.MISSING_BULK_DOCS=new r({status:400,error:"bad_request",reason:"Missing JSON list of 'docs'"}),n.MISSING_DOC=new r({status:404,error:"not_found",reason:"missing"}),n.REV_CONFLICT=new r({status:409,error:"conflict",reason:"Document update conflict"}),n.INVALID_ID=new r({status:400,error:"invalid_id",reason:"_id field must contain a string"}),n.MISSING_ID=new r({status:412,error:"missing_id",reason:"_id is required for puts"}),n.RESERVED_ID=new r({status:400,error:"bad_request",reason:"Only reserved document ids may start with underscore."}),n.NOT_OPEN=new r({status:412,error:"precondition_failed",reason:"Database not open"}),n.UNKNOWN_ERROR=new r({status:500,error:"unknown_error",reason:"Database encountered an unknown error"}),n.BAD_ARG=new r({status:500,error:"badarg",reason:"Some query argument is invalid"}),n.INVALID_REQUEST=new r({status:400,error:"invalid_request",reason:"Request was invalid"}),n.QUERY_PARSE_ERROR=new r({status:400,error:"query_parse_error",reason:"Some query parameter is invalid"}),n.DOC_VALIDATION=new r({status:500,error:"doc_validation",reason:"Bad special document member"}),n.BAD_REQUEST=new r({status:400,error:"bad_request",reason:"Something wrong with the request"}),n.NOT_AN_OBJECT=new r({status:400,error:"bad_request",reason:"Document must be a JSON object"}),n.DB_MISSING=new r({status:404,error:"not_found",reason:"Database not found"}),n.IDB_ERROR=new r({status:500,error:"indexed_db_went_bad",reason:"unknown"}),n.WSQ_ERROR=new r({status:500,error:"web_sql_went_bad",reason:"unknown"}),n.LDB_ERROR=new r({status:500,error:"levelDB_went_went_bad",reason:"unknown"}),n.FORBIDDEN=new r({status:403,error:"forbidden",reason:"Forbidden by design doc validate_doc_update function"}),n.INVALID_REV=new r({status:400,error:"bad_request",reason:"Invalid rev format"}),n.FILE_EXISTS=new r({status:412,error:"file_exists",reason:"The database could not be created, the file already exists."}),n.MISSING_STUB=new r({status:412,error:"missing_stub"}),n.error=function(e,t,n){function o(t){for(var r in e)"function"!=typeof e[r]&&(this[r]=e[r]);void 0!==n&&(this.name=n),void 0!==t&&(this.reason=t)}return o.prototype=r.prototype,new o(t)},n.getErrorTypeByProp=function(e,t,r){var o=n,i=Object.keys(o).filter(function(n){var r=o[n];return"function"!=typeof r&&r[e]===t}),s=r&&i.filter(function(e){var t=o[e];return t.message===r})[0]||i[0];return s?o[s]:null},n.generateErrorFromResponse=function(e){var t,r,o,i,s,a=n;return r=e.error===!0&&"string"==typeof e.name?e.name:e.error,s=e.reason,o=a.getErrorTypeByProp("name",r,s),e.missing||"missing"===s||"deleted"===s||"not_found"===r?o=a.MISSING_DOC:"doc_validation"===r?(o=a.DOC_VALIDATION,i=s):"bad_request"===r&&o.message!==s&&(0===s.indexOf("unknown stub attachment")?(o=a.MISSING_STUB,i=s):o=a.BAD_REQUEST),o||(o=a.getErrorTypeByProp("status",e.status,s)||a.UNKNOWN_ERROR),t=a.error(o,s,r),i&&(t.message=i),e.id&&(t.id=e.id),e.status&&(t.status=e.status),e.statusText&&(t.name=e.statusText),e.missing&&(t.missing=e.missing),t}},{}],19:[function(e,t){(function(n,r){"use strict";function o(e,t,n){if("function"==typeof e.slice)return t?n?e.slice(t,n):e.slice(t):e.slice();t=Math.floor(t||0),n=Math.floor(n||0);var r=e.byteLength;if(t=0>t?Math.max(t+r,0):Math.min(r,t),n=0>n?Math.max(n+r,0):Math.min(r,n),0>=n-t)return new ArrayBuffer(0);var o=new ArrayBuffer(n-t),i=new Uint8Array(o),s=new Uint8Array(e,t,n-t);return i.set(s),o}function i(e){var t=[255&e,e>>>8&255,e>>>16&255,e>>>24&255];return t.map(function(e){return String.fromCharCode(e)}).join("")}function s(e){for(var t="",n=0;n<e.length;n++)t+=i(e[n]);return btoa(t)}var a=e("crypto"),u=e("spark-md5"),c=r.setImmediate||r.setTimeout,f=32768;t.exports=function(e,t){function r(e,t,n,r){d?e.appendBinary(t.substring(n,r)):e.append(o(t,n,r))}function i(){var n=g*p,o=n+p;if(n+p>=e.size&&(o=e.size),g++,v>g)r(m,e,n,o),c(i);else{r(m,e,n,o);var a=m.end(!0),u=s(a);t(null,u),m.destroy()}}if(!n.browser){var l=a.createHash("md5").update(e).digest("base64");return void t(null,l)}var d="string"==typeof e,h=d?e.length:e.byteLength,p=Math.min(f,h),v=Math.ceil(h/p),g=0,m=d?new u:new u.ArrayBuffer;i()}}).call(this,e("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{_process:40,crypto:34,"spark-md5":72}],20:[function(e,t){"use strict";function n(e){return decodeURIComponent(window.escape(e))}function r(e){return 65>e?e-48:e-55}function o(e,t,n){for(var o="";n>t;)o+=String.fromCharCode(r(e.charCodeAt(t++))<<4|r(e.charCodeAt(t++)));return o}function i(e,t,n){for(var o="";n>t;)o+=String.fromCharCode(r(e.charCodeAt(t+2))<<12|r(e.charCodeAt(t+3))<<8|r(e.charCodeAt(t))<<4|r(e.charCodeAt(t+1))),t+=4;return o}function s(e,t){return"UTF-8"===t?n(o(e,0,e.length)):i(e,0,e.length)}t.exports=s},{}],21:[function(e,t){"use strict";function n(e){for(var t=r,n=t.parser[t.strictMode?"strict":"loose"].exec(e),o={},i=14;i--;){var s=t.key[i],a=n[i]||"",u=-1!==["user","password"].indexOf(s);o[s]=u?decodeURIComponent(a):a}return o[t.q.name]={},o[t.key[12]].replace(t.q.parser,function(e,n,r){n&&(o[t.q.name][n]=r)}),o}var r={strictMode:!1,key:["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],q:{name:"queryKey",parser:/(?:^|&)([^&=]*)=?([^&]*)/g},parser:{strict:/^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,loose:/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/}};t.exports=n},{}],22:[function(e,t){"use strict";function n(e,t,n){return new o(function(o,i){return t&&"object"==typeof t&&(t=t._id),"string"!=typeof t?i(new Error("doc id is required")):void e.get(t,function(s,a){if(s)return 404!==s.status?i(s):o(r(e,n({_id:t}),n));var u=n(a);return u?void o(r(e,u,n)):o(a)})})}function r(e,t,r){return e.put(t)["catch"](function(o){if(409!==o.status)throw o;return n(e,t,r)})}var o=e("../utils").Promise;t.exports=function(e,t,r,o){return"function"!=typeof o?n(e,t,r):void n(e,t,r).then(function(e){o(null,e)},o)}},{"../utils":31}],23:[function(e,t){"use strict";function n(e){return 0|Math.random()*e}function r(e,t){t=t||o.length;var r="",i=-1;if(e){for(;++i<e;)r+=o[n(t)];return r}for(;++i<36;)switch(i){case 8:case 13:case 18:case 23:r+="-";break;case 19:r+=o[3&n(16)|8];break;default:r+=o[n(16)]}return r}var o="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");t.exports=r},{}],24:[function(_dereq_,module,exports){"use strict";function evalFilter(input){return eval(["(function () { return ",input," })()"].join(""))}module.exports=evalFilter},{}],25:[function(_dereq_,module,exports){"use strict";function evalView(input){return eval(["(function () {"," return function (doc) {"," var emitted = false;"," var emit = function (a, b) {"," emitted = true;"," };"," var view = "+input+";"," view(doc);"," if (emitted) {"," return true;"," }"," }","})()"].join("\n"))}module.exports=evalView},{}],26:[function(e,t){"use strict";function n(e,t,n){for(var r,o=0,i=e.length;i>o;)r=o+i>>>1,n(e[r],t)<0?o=r+1:i=r;return o}function r(e,t,r){var o=n(e,t,r);e.splice(o,0,t)}function o(e){for(var t,n=e.shift(),r=[n.id,n.opts,[]],o=r;e.length;)n=e.shift(),t=[n.id,n.opts,[]],o[2].push(t),o=t;return r}function i(e,t){return e[0]<t[0]?-1:1}function s(e,t){for(var n=[{tree1:e,tree2:t}],o=!1;n.length>0;){var s=n.pop(),a=s.tree1,u=s.tree2;(a[1].status||u[1].status)&&(a[1].status="available"===a[1].status||"available"===u[1].status?"available":"missing");for(var c=0;c<u[2].length;c++)if(a[2][0]){for(var f=!1,l=0;l<a[2].length;l++)a[2][l][0]===u[2][c][0]&&(n.push({tree1:a[2][l],tree2:u[2][c]}),f=!0);f||(o="new_branch",r(a[2],u[2][c],i))}else o="new_leaf",a[2][0]=u[2][c]}return{conflicts:o,tree:e}}function a(e,t,n){var r,o=[],i=!1,a=!1;return e.length?(e.forEach(function(e){if(e.pos===t.pos&&e.ids[0]===t.ids[0])r=s(e.ids,t.ids),o.push({pos:e.pos,ids:r.tree}),i=i||r.conflicts,a=!0;else if(n!==!0){var u=e.pos<t.pos?e:t,c=e.pos<t.pos?t:e,f=c.pos-u.pos,l=[],d=[];for(d.push({ids:u.ids,diff:f,parent:null,parentIdx:null});d.length>0;){var h=d.pop();0!==h.diff?h.ids&&h.ids[2].forEach(function(e,t){d.push({ids:e,diff:h.diff-1,parent:h.ids,parentIdx:t})}):h.ids[0]===c.ids[0]&&l.push(h)}var p=l[0];p?(r=s(p.ids,c.ids),p.parent[2][p.parentIdx]=r.tree,o.push({pos:u.pos,ids:u.ids}),i=i||r.conflicts,a=!0):o.push(e)}else o.push(e)}),a||o.push(t),o.sort(function(e,t){return e.pos-t.pos}),{tree:o,conflicts:i||"internal_node"}):{tree:[t],conflicts:"new_leaf"}}function u(e,t){var n=f.rootToLeaf(e).map(function(e){var n=e.ids.slice(-t);return{pos:e.pos+(e.ids.length-n.length),ids:o(n)}});return n.reduce(function(e,t){return a(e,t,!0).tree},[n.shift()])}var c=e("pouchdb-extend"),f={};f.merge=function(e,t,n){e=c(!0,[],e),t=c(!0,{},t);var r=a(e,t);return{tree:u(r.tree,n),conflicts:r.conflicts}},f.winningRev=function(e){var t=[];return f.traverseRevTree(e.rev_tree,function(e,n,r,o,i){e&&t.push({pos:n,id:r,deleted:!!i.deleted})}),t.sort(function(e,t){return e.deleted!==t.deleted?e.deleted>t.deleted?1:-1:e.pos!==t.pos?t.pos-e.pos:e.id<t.id?1:-1}),t[0].pos+"-"+t[0].id},f.traverseRevTree=function(e,t){for(var n,r=e.slice();n=r.pop();)for(var o=n.pos,i=n.ids,s=i[2],a=t(0===s.length,o,i[0],n.ctx,i[1]),u=0,c=s.length;c>u;u++)r.push({pos:o+1,ids:s[u],ctx:a})},f.collectLeaves=function(e){var t=[];return f.traverseRevTree(e,function(e,n,r,o,i){e&&t.push({rev:n+"-"+r,pos:n,opts:i})}),t.sort(function(e,t){return t.pos-e.pos}),t.forEach(function(e){delete e.pos}),t},f.collectConflicts=function(e){var t=f.winningRev(e),n=f.collectLeaves(e.rev_tree),r=[];return n.forEach(function(e){e.rev===t||e.opts.deleted||r.push(e.rev)}),r},f.rootToLeaf=function(e){var t=[];return f.traverseRevTree(e,function(e,n,r,o,i){if(o=o?o.slice(0):[],o.push({id:r,opts:i}),e){var s=n+1-o.length;t.unshift({pos:s,ids:o})}return o}),t},t.exports=f},{"pouchdb-extend":65}],27:[function(e,t,n){"use strict";function r(e,t){e=parseInt(e,10),t=parseInt(t,10),e!==e&&(e=0),t!==t||e>=t?t=(e||1)<<1:t+=1;var n=Math.random(),r=t-e;return~~(r*n+e)}function o(e){var t=0;return e||(t=2e3),r(e,t)}function i(e,t,n,r,i,s,a){return r.retry===!1?(i.emit("error",a),void i.removeAllListeners()):(r.default_back_off=r.default_back_off||0,r.retries=r.retries||0,"function"!=typeof r.back_off_function&&(r.back_off_function=o),r.retries++,r.max_retries&&r.retries>r.max_retries?(i.emit("error",new Error("tried "+r.retries+" times but replication failed")),void i.removeAllListeners()):(i.emit("requestError",a),"active"===i.state&&(i.emit("syncStopped"),i.state="stopped",i.once("syncRestarted",function(){r.current_back_off=r.default_back_off})),r.current_back_off=r.current_back_off||r.default_back_off,r.current_back_off=r.back_off_function(r.current_back_off),void setTimeout(function(){u(e,t,n,r,i)},r.current_back_off)))}function s(){d.call(this),this.cancelled=!1,this.state="pending";var e=this,t=new l.Promise(function(t,n){e.once("complete",t),e.once("error",n)});e.then=function(e,n){return t.then(e,n)},e["catch"]=function(e){return t["catch"](e)},e["catch"](function(){})}function a(e,t,n){var r=n.filter?n.filter.toString():"";return e.id().then(function(e){return t.id().then(function(t){var o=e+t+r+JSON.stringify(n.query_params)+n.doc_ids;return l.MD5(o).then(function(e){return e=e.replace(/\//g,".").replace(/\+/g,"_"),"_local/"+e})})})}function u(e,t,n,r,o,s){function a(){if(0!==R.docs.length){var e=R.docs;return n.bulkDocs({docs:e,new_edits:!1}).then(function(t){if(P.cancelled)throw b(),new Error("cancelled");var n=[],r={};t.forEach(function(e){e.error&&(s.doc_write_failures++,n.push(e),r[e.id]=e)}),s.errors=s.errors.concat(n),s.docs_written+=R.docs.length-n.length;var i=n.filter(function(e){return"unauthorized"!==e.name&&"forbidden"!==e.name});if(e.forEach(function(e){var t=r[e._id];t&&o.emit("denied",l.clone(t))}),i.length>0){var a=new Error("bulkDocs error");throw a.other_errors=n,y("target.bulkDocs failed to write docs",a),new Error("bulkWrite partial failure")}},function(t){throw s.doc_write_failures+=e.length,t})}}function u(e){for(var n=R.diffs,r=n[e].missing,o=[],i=0;i<r.length;i+=p)o.push(r.slice(i,Math.min(r.length,i+p)));return l.Promise.all(o.map(function(r){var o={revs:!0,open_revs:r,attachments:!0};return t.get(e,o).then(function(t){t.forEach(function(e){return P.cancelled?b():void(e.ok&&(s.docs_read++,R.pendingRevs++,R.docs.push(e.ok)))}),delete n[e]})}))}function c(){var e=Object.keys(R.diffs);return l.Promise.all(e.map(u))}function f(){var e=Object.keys(R.diffs).filter(function(e){var t=R.diffs[e].missing;return 1===t.length&&"1-"===t[0].slice(0,2)});return e.length?t.allDocs({keys:e,include_docs:!0}).then(function(e){if(P.cancelled)throw b(),new Error("cancelled");e.rows.forEach(function(e){!e.doc||e.deleted||"1-"!==e.value.rev.slice(0,2)||e.doc._attachments&&0!==Object.keys(e.doc._attachments).length||(s.docs_read++,R.pendingRevs++,R.docs.push(e.doc),delete R.diffs[e.id])})}):l.Promise.resolve()}function d(){return f().then(c)}function v(){return O=!0,M.writeCheckpoint(R.seq).then(function(){if(O=!1,P.cancelled)throw b(),new Error("cancelled");s.last_seq=L=R.seq,o.emit("change",l.clone(s)),R=void 0,A()})["catch"](function(e){throw O=!1,y("writeCheckpoint completed with error",e),e})}function g(){var e={};return R.changes.forEach(function(t){e[t.id]=t.changes.map(function(e){return e.rev})}),n.revsDiff(e).then(function(e){if(P.cancelled)throw b(),new Error("cancelled");R.diffs=e,R.pendingRevs=0})}function m(){if(!P.cancelled&&!R){if(0===k.length)return void _(!0);R=k.shift(),g().then(d).then(a).then(v).then(m)["catch"](function(e){y("batch processing terminated with error",e)})}}function _(e){return 0===x.changes.length?void(0!==k.length||R||((C&&U.live||I)&&o.emit("uptodate",l.clone(s)),I&&b())):void((e||I||x.changes.length>=D)&&(k.push(x),x={seq:0,changes:[],docs:[]},m()))}function y(e,t){q||(t.message||(t.message=e),s.ok=!1,s.status="aborting",s.errors.push(t),k=[],x={seq:0,changes:[],docs:[]},b())}function b(){if(!(q||P.cancelled&&(s.status="cancelled",O))){s.status=s.status||"complete",s.end_time=new Date,s.last_seq=L,q=P.cancelled=!0;var a=s.errors.filter(function(e){return"unauthorized"!==e.name&&"forbidden"!==e.name});if(a.length>0){var u=s.errors.pop();s.errors.length>0&&(u.other_errors=s.errors),u.result=s,i(e,t,n,r,o,s,u)}else o.emit("complete",s),o.removeAllListeners()}}function w(e){return P.cancelled?b():(0!==x.changes.length||0!==k.length||R||o.emit("outofdate",l.clone(s)),x.seq=e.seq,x.changes.push(e),void _(0===k.length))}function E(e){return j=!1,P.cancelled?b():(U.since<e.last_seq?(U.since=e.last_seq,A()):C?(U.live=!0,A()):I=!0,void _(!0))}function S(e){return j=!1,P.cancelled?b():void y("changes rejected",e)}function A(){function e(){r.cancel()}function n(){o.removeListener("cancel",e)}if(!j&&!I&&k.length<N){j=!0,o.once("cancel",e);var r=t.changes(U).on("change",w);r.then(n,n),r.then(E)["catch"](S)}}function T(){M.getCheckpoint().then(function(e){L=e,U={since:L,limit:D,batch_size:D,style:"all_docs",doc_ids:B,returnDocs:!1},r.filter&&(U.filter=r.filter),r.query_params&&(U.query_params=r.query_params),A()})["catch"](function(e){y("getCheckpoint rejected with ",e)})}var R,k=[],x={seq:0,changes:[],docs:[]},O=!1,I=!1,q=!1,L=0,C=r.continuous||r.live||!1,D=r.batch_size||100,N=r.batches_limit||10,j=!1,B=r.doc_ids,P={cancelled:!1},M=new h(t,n,e,P);s=s||{ok:!0,start_time:new Date,docs_read:0,docs_written:0,doc_write_failures:0,errors:[]};var U={};o.ready(t,n),o.once("cancel",b),"function"==typeof r.onChange&&o.on("change",r.onChange),"function"==typeof r.complete&&(o.once("error",r.complete),o.once("complete",function(e){r.complete(null,e)})),"undefined"==typeof r.since?T():(O=!0,M.writeCheckpoint(r.since).then(function(){return O=!1,P.cancelled?void b():(L=r.since,void T())})["catch"](function(e){throw O=!1,y("writeCheckpoint completed with error",e),e}))}function c(e,t){var n=t.PouchConstructor;return"string"==typeof e?new n(e):e.then?e:l.Promise.resolve(e)}function f(e,t,n,r){"function"==typeof n&&(r=n,n={}),"undefined"==typeof n&&(n={}),n.complete||(n.complete=r||function(){}),n=l.clone(n),n.continuous=n.continuous||n.live,n.retry=n.retry||!1,n.PouchConstructor=n.PouchConstructor||this;var o=new s(n);return c(e,n).then(function(e){return c(t,n).then(function(t){return a(e,t,n).then(function(r){u(r,e,t,n,o)})})})["catch"](function(e){o.emit("error",e),n.complete(e)}),o}var l=e("./utils"),d=e("events").EventEmitter,h=e("./checkpointer"),p=50;l.inherits(s,d),s.prototype.cancel=function(){this.cancelled=!0,this.state="cancelled",this.emit("cancel")},s.prototype.ready=function(e,t){function n(){o.cancel()}function r(){e.removeListener("destroyed",n),t.removeListener("destroyed",n)}var o=this;this.once("change",function(){"pending"===this.state?(o.state="active",o.emit("syncStarted")):"stopped"===o.state&&(o.state="active",o.emit("syncRestarted"))}),e.once("destroyed",n),t.once("destroyed",n),this.then(r,r)},n.toPouch=c,n.replicate=f},{"./checkpointer":13,"./utils":31,events:39}],28:[function(e,t){"use strict";var n=e("./constructor"),r=e("./utils"),o=r.Promise,i=e("events").EventEmitter;n.adapters={},n.preferredAdapters=e("./adapters/preferredAdapters.js"),n.prefix="_pouch_";var s=new i,a=["on","addListener","emit","listeners","once","removeAllListeners","removeListener","setMaxListeners"];a.forEach(function(e){n[e]=s[e].bind(s)}),n.setMaxListeners(0),n.parseAdapter=function(e,t){var o,i,s=e.match(/([a-z\-]*):\/\/(.*)/);if(s){if(e=/http(s?)/.test(s[1])?s[1]+"://"+s[2]:s[2],o=s[1],!n.adapters[o].valid())throw"Invalid adapter";return{name:e,adapter:s[1]}}var a="idb"in n.adapters&&"websql"in n.adapters&&r.hasLocalStorage()&&localStorage["_pouch__websqldb_"+n.prefix+e];if("undefined"!=typeof t&&t.db)i="leveldb";else for(var u=0;u<n.preferredAdapters.length;++u)if(i=n.preferredAdapters[u],i in n.adapters){if(a&&"idb"===i)continue;break}if(o=n.adapters[i],i&&o){var c="use_prefix"in o?o.use_prefix:!0;return{name:c?n.prefix+e:e,adapter:i}}throw"No valid adapter found"},n.destroy=r.toPromise(function(e,t,i){function s(){c.destroy(d,t,function(t,r){t?i(t):(n.emit("destroyed",e),n.emit(e,"destroyed"),i(null,r||{ok:!0}))})}("function"==typeof t||"undefined"==typeof t)&&(i=t,t={}),e&&"object"==typeof e&&(t=e,e=void 0);var a=n.parseAdapter(t.name||e,t),u=a.name,c=n.adapters[a.adapter],f="use_prefix"in c?c.use_prefix:!0,l=f?u.replace(new RegExp("^"+n.prefix),""):u,d=("http"===a.adapter||"https"===a.adapter?"":t.prefix||"")+u,h=r.extend(!0,{},t,{adapter:a.adapter});new n(l,h,function(e,a){return e?i(e):void a.get("_local/_pouch_dependentDbs",function(e,u){if(e)return 404!==e.status?i(e):s();var c=u.dependentDbs,l=Object.keys(c).map(function(e){var o=f?e.replace(new RegExp("^"+n.prefix),""):e,i=r.extend(!0,t,a.__opts||{});return a.constructor.destroy(o,i)});o.all(l).then(s,function(e){i(e)})})})}),n.allDbs=r.toPromise(function(e){var t=new Error("allDbs method removed");t.stats="400",e(t)}),n.adapter=function(e,t){t.valid()&&(n.adapters[e]=t)},n.plugin=function(e){Object.keys(e).forEach(function(t){n.prototype[t]=e[t]})},n.defaults=function(e){function t(t,o,i){("function"==typeof o||"undefined"==typeof o)&&(i=o,o={}),t&&"object"==typeof t&&(o=t,t=void 0),o=r.extend(!0,{},e,o),n.call(this,t,o,i)}return r.inherits(t,n),t.destroy=r.toPromise(function(t,o,i){return("function"==typeof o||"undefined"==typeof o)&&(i=o,o={}),t&&"object"==typeof t&&(o=t,t=void 0),o=r.extend(!0,{},e,o),n.destroy(t,o,i)}),a.forEach(function(e){t[e]=s[e].bind(s)}),t.setMaxListeners(0),t.preferredAdapters=n.preferredAdapters.slice(),Object.keys(n).forEach(function(e){e in t||(t[e]=n[e])}),t},t.exports=n},{"./adapters/preferredAdapters.js":7,"./constructor":14,"./utils":31,events:39}],29:[function(e,t){"use strict";function n(e,t,n,s){return"function"==typeof n&&(s=n,n={}),"undefined"==typeof n&&(n={}),n=o.clone(n),n.PouchConstructor=n.PouchConstructor||this,e=i.toPouch(e,n),t=i.toPouch(t,n),new r(e,t,n,s)}function r(e,t,n,r){function i(e){v||(v=!0,d.emit("cancel",e))}function a(e){d.emit("change",{direction:"pull",change:e})}function u(e){d.emit("change",{direction:"push",change:e})}function c(e){d.emit("denied",{direction:"push",doc:e})}function f(e){d.emit("denied",{direction:"pull",doc:e})}function l(e){return function(t,n){var r="change"===t&&(n===a||n===u),o="cancel"===t&&n===i,s=t in g&&n===g[t];(r||o||s)&&(t in m||(m[t]={}),m[t][e]=!0,2===Object.keys(m[t]).length&&d.removeAllListeners(t))}}var d=this;this.canceled=!1;var h,p;"onChange"in n&&(h=n.onChange,delete n.onChange),"function"!=typeof r||n.complete?"complete"in n&&(p=n.complete,delete n.complete):p=r,this.push=s(e,t,n),this.pull=s(t,e,n);var v=!1,g={},m={};this.on("newListener",function(e){"change"===e?(d.pull.on("change",a),d.push.on("change",u)):"denied"===e?(d.pull.on("denied",f),d.push.on("denied",c)):"cancel"===e?(d.pull.on("cancel",i),d.push.on("cancel",i)):"error"===e||"removeListener"===e||"complete"===e||e in g||(g[e]=function(t){d.emit(e,t)},d.pull.on(e,g[e]),d.push.on(e,g[e]))}),this.on("removeListener",function(e){"change"===e?(d.pull.removeListener("change",a),d.push.removeListener("change",u)):"cancel"===e?(d.pull.removeListener("cancel",i),d.push.removeListener("cancel",i)):e in g&&"function"==typeof g[e]&&(d.pull.removeListener(e,g[e]),d.push.removeListener(e,g[e]),delete g[e])}),this.pull.on("removeListener",l("pull")),this.push.on("removeListener",l("push"));var _=o.Promise.all([this.push,this.pull]).then(function(e){var t={push:e[0],pull:e[1]};return d.emit("complete",t),p&&p(null,t),d.removeAllListeners(),t},function(e){throw d.cancel(),d.emit("error",e),p&&p(e),d.removeAllListeners(),e});this.then=function(e,t){return _.then(e,t)},this["catch"]=function(e){return _["catch"](e)}}var o=e("./utils"),i=e("./replicate"),s=i.replicate,a=e("events").EventEmitter;o.inherits(r,a),t.exports=n,r.prototype.cancel=function(){this.canceled||(this.canceled=!0,this.push.cancel(),this.pull.cancel())}},{"./replicate":27,"./utils":31,events:39}],30:[function(e,t){"use strict";function n(){this.isReady=!1,this.failed=!1,this.queue=[]}t.exports=n,n.prototype.execute=function(){var e,t;if(this.failed)for(;e=this.queue.shift();)"function"!=typeof e?(t=e.parameters[e.parameters.length-1],"function"==typeof t?t(this.failed):"changes"===e.name&&"function"==typeof t.complete&&t.complete(this.failed)):e(this.failed);else if(this.isReady)for(;e=this.queue.shift();)"function"==typeof e?e():e.task=this.db[e.name].apply(this.db,e.parameters)},n.prototype.fail=function(e){this.failed=e,this.execute()},n.prototype.ready=function(e){return this.failed?!1:0===arguments.length?this.isReady:(this.isReady=e?!0:!1,this.db=e,void this.execute())},n.prototype.addTask=function(e,t){if("function"!=typeof e){var n={name:e,parameters:t};return this.queue.push(n),this.failed&&this.execute(),n}this.queue.push(e),this.failed&&this.execute()}},{}],31:[function(e,t,n){(function(t,r){function o(e){return e.reduce(function(e,t){return e[t]=!0,e},{})}function i(){return"undefined"!=typeof chrome&&"undefined"!=typeof chrome.storage&&"undefined"!=typeof chrome.storage.local}function s(){if(!(this instanceof s))return new s;var e=this;f.call(this),this.isChrome=i(),this.listeners={},this.hasLocal=!1,this.isChrome||(this.hasLocal=n.hasLocalStorage()),this.isChrome?chrome.storage.onChanged.addListener(function(t){null!=t.db_name&&e.emit(t.dbName.newValue)}):this.hasLocal&&("undefined"!=typeof addEventListener?addEventListener("storage",function(t){e.emit(t.key)}):window.attachEvent("storage",function(t){e.emit(t.key)}))}var a=e("./merge");n.extend=e("pouchdb-extend"),n.ajax=e("./deps/ajax"),n.createBlob=e("./deps/blob"),n.uuid=e("./deps/uuid"),n.getArguments=e("argsarray");var u=e("./deps/buffer"),c=e("./deps/errors"),f=e("events").EventEmitter,l=e("./deps/collections");n.Map=l.Map,n.Set=l.Set,n.Promise="function"==typeof r.Promise?r.Promise:e("bluebird");var d=n.Promise,h=o(["_id","_rev","_attachments","_deleted","_revisions","_revs_info","_conflicts","_deleted_conflicts","_local_seq","_rev_tree","_replication_id","_replication_state","_replication_state_time","_replication_state_reason","_replication_stats"]),p=o(["_attachments","_replication_id","_replication_state","_replication_state_time","_replication_state_reason","_replication_stats"]);n.lastIndexOf=function(e,t){for(var n=e.length-1;n>=0;n--)if(e.charAt(n)===t)return n;return-1},n.clone=function(e){return n.extend(!0,{},e)},n.pick=function(e,t){for(var n={},r=0,o=t.length;o>r;r++){var i=t[r];n[i]=e[i]}return n},n.inherits=e("inherits"),n.invalidIdError=function(e){var t;if(e?"string"!=typeof e?t=c.error(c.INVALID_ID):/^_/.test(e)&&!/^_(design|local)/.test(e)&&(t=c.error(c.RESERVED_ID)):t=c.error(c.MISSING_ID),t)throw t},n.call=n.getArguments(function(e){if(e.length){var t=e.shift();"function"==typeof t&&t.apply(this,e)}}),n.isLocalId=function(e){return/^_local/.test(e)},n.isDeleted=function(e,t){t||(t=a.winningRev(e));var n=t.indexOf("-");-1!==n&&(t=t.substring(n+1));var r=!1;return a.traverseRevTree(e.rev_tree,function(e,n,o,i,s){o===t&&(r=!!s.deleted)}),r},n.revExists=function(e,t){var n=!1;return a.traverseRevTree(e.rev_tree,function(e,r,o){r+"-"+o===t&&(n=!0)}),n},n.filterChange=function(e){var t={},n=e.filter&&"function"==typeof e.filter;return t.query=e.query_params,function(r){if(e.filter&&n&&!e.filter.call(this,r.doc,t))return!1;if(e.include_docs){if(!e.attachments)for(var o in r.doc._attachments)r.doc._attachments.hasOwnProperty(o)&&(r.doc._attachments[o].stub=!0)}else delete r.doc;return!0}},n.parseDoc=function(e,t){function r(){return s=/^(\d+)-(.+)$/.exec(e._rev),s?{prefix:parseInt(s[1],10),id:s[2]}:a=c.error(c.INVALID_REV)}var o,i,s,a,u={status:"available"};if(e._deleted&&(u.deleted=!0),t)if(e._id||(e._id=n.uuid()),i=n.uuid(32,16).toLowerCase(),e._rev){if(s=r(e._rev),s.error)return s;
e._rev_tree=[{pos:s.prefix,ids:[s.id,{status:"missing"},[[i,u,[]]]]}],o=s.prefix+1}else e._rev_tree=[{pos:1,ids:[i,u,[]]}],o=1;else if(e._revisions&&(e._rev_tree=[{pos:e._revisions.start-e._revisions.ids.length+1,ids:e._revisions.ids.reduce(function(e,t){return null===e?[t,u,[]]:[t,{status:"missing"},[e]]},null)}],o=e._revisions.start,i=e._revisions.ids[0]),!e._rev_tree){if(s=r(e._rev),s.error)return s;o=s.prefix,i=s.id,e._rev_tree=[{pos:o,ids:[i,u,[]]}]}n.invalidIdError(e._id),e._rev=[o,i].join("-");var f={metadata:{},data:{}};for(var l in e)if(e.hasOwnProperty(l)){var d="_"===l[0];if(d&&!h[l])throw a=c.error(c.DOC_VALIDATION,l),a.message=c.DOC_VALIDATION.message+": "+l,a;d&&!p[l]?f.metadata[l.slice(1)]=e[l]:f.data[l]=e[l]}return f},n.isCordova=function(){return"undefined"!=typeof cordova||"undefined"!=typeof PhoneGap||"undefined"!=typeof phonegap},n.hasLocalStorage=function(){if(i())return!1;try{return localStorage}catch(e){return!1}},n.Changes=s,n.inherits(s,f),s.prototype.addListener=function(e,r,o,i){function s(){if(a.listeners[r]){if(u)return void(u="waiting");u=!0,o.changes({include_docs:i.include_docs,attachments:i.attachments,conflicts:i.conflicts,continuous:!1,descending:!1,filter:i.filter,doc_ids:i.doc_ids,view:i.view,since:i.since,query_params:i.query_params}).on("change",function(e){e.seq>i.since&&!i.cancelled&&(i.since=e.seq,n.call(i.onChange,e))}).on("complete",function(){"waiting"===u&&t.nextTick(function(){a.notify(e)}),u=!1}).on("error",function(){u=!1})}}if(!this.listeners[r]){var a=this,u=!1;this.listeners[r]=s,this.on(e,s)}},s.prototype.removeListener=function(e,t){t in this.listeners&&f.prototype.removeListener.call(this,e,this.listeners[t])},s.prototype.notifyLocalWindows=function(e){this.isChrome?chrome.storage.local.set({dbName:e}):this.hasLocal&&(localStorage[e]="a"===localStorage[e]?"b":"a")},s.prototype.notify=function(e){this.emit(e),this.notifyLocalWindows(e)},n.atob="undefined"==typeof window||"function"!=typeof window.atob?function(e){var t=new u(e,"base64");if(t.toString("base64")!==e)throw"Cannot base64 encode full string";return t.toString("binary")}:function(e){return atob(e)},n.btoa="undefined"==typeof window||"function"!=typeof window.btoa?function(e){return new u(e,"binary").toString("base64")}:function(e){return btoa(e)},n.fixBinary=function(e){if(!t.browser)return e;for(var n=e.length,r=new ArrayBuffer(n),o=new Uint8Array(r),i=0;n>i;i++)o[i]=e.charCodeAt(i);return r},n.readAsBinaryString=function(e,t){var r=new FileReader,o="function"==typeof r.readAsBinaryString;r.onloadend=function(e){var r=e.target.result||"";return o?t(r):void t(n.arrayBufferToBinaryString(r))},o?r.readAsBinaryString(e):r.readAsArrayBuffer(e)},n.once=function(e){var t=!1;return n.getArguments(function(n){if(t)throw new Error("once called more than once");t=!0,e.apply(this,n)})},n.toPromise=function(e){return n.getArguments(function(r){var o,i=this,s="function"==typeof r[r.length-1]?r.pop():!1;s&&(o=function(e,n){t.nextTick(function(){s(e,n)})});var a=new d(function(t,o){var s;try{var a=n.once(function(e,n){e?o(e):t(n)});r.push(a),s=e.apply(i,r),s&&"function"==typeof s.then&&t(s)}catch(u){o(u)}});return o&&a.then(function(e){o(null,e)},o),a.cancel=function(){return this},a})},n.adapterFun=function(t,r){function o(e,t,n){if(i.enabled){for(var r=[e._db_name,t],o=0;o<n.length-1;o++)r.push(n[o]);i.apply(null,r);var s=n[n.length-1];n[n.length-1]=function(n,r){var o=[e._db_name,t];o=o.concat(n?["error",n]:["success",r]),i.apply(null,o),s(n,r)}}}var i=e("debug")("pouchdb:api");return n.toPromise(n.getArguments(function(e){if(this._closed)return d.reject(new Error("database is closed"));var i=this;return o(i,t,e),this.taskqueue.isReady?r.apply(this,e):new n.Promise(function(n,r){i.taskqueue.addTask(function(o){o?r(o):n(i[t].apply(i,e))})})}))},n.arrayBufferToBinaryString=function(e){for(var t="",n=new Uint8Array(e),r=n.byteLength,o=0;r>o;o++)t+=String.fromCharCode(n[o]);return t},n.cancellableFun=function(e,t,r){r=r?n.clone(!0,{},r):{};var o=new f,i=r.complete||function(){},s=r.complete=n.once(function(e,t){e?i(e):(o.emit("end",t),i(null,t)),o.removeAllListeners()}),a=r.onChange||function(){},u=0;t.on("destroyed",function(){o.removeAllListeners()}),r.onChange=function(e){a(e),e.seq<=u||(u=e.seq,o.emit("change",e),e.deleted?o.emit("delete",e):1===e.changes.length&&"1-"===e.changes[0].rev.slice(0,1)?o.emit("create",e):o.emit("update",e))};var c=new d(function(e,t){r.complete=function(n,r){n?t(n):e(r)}});return c.then(function(e){s(null,e)},s),c.cancel=function(){c.isCancelled=!0,t.taskqueue.isReady&&r.complete(null,{status:"cancelled"})},t.taskqueue.isReady?e(t,r,c):t.taskqueue.addTask(function(){c.isCancelled?r.complete(null,{status:"cancelled"}):e(t,r,c)}),c.on=o.on.bind(o),c.once=o.once.bind(o),c.addListener=o.addListener.bind(o),c.removeListener=o.removeListener.bind(o),c.removeAllListeners=o.removeAllListeners.bind(o),c.setMaxListeners=o.setMaxListeners.bind(o),c.listeners=o.listeners.bind(o),c.emit=o.emit.bind(o),c},n.MD5=n.toPromise(e("./deps/md5")),n.explain404=function(e){t.browser&&"console"in r&&"info"in console&&console.info("The above 404 is totally normal. "+e)},n.parseUri=e("./deps/parse-uri"),n.compare=function(e,t){return t>e?-1:e>t?1:0},n.updateDoc=function(e,t,r,o,i,s,u){if(n.revExists(e,t.metadata.rev))return r[o]=t,i();var f=n.isDeleted(e),l=n.isDeleted(t.metadata),d=/^1-/.test(t.metadata.rev);if(f&&!l&&u&&d){var h=t.data;h._rev=a.winningRev(e),h._id=t.metadata.id,t=n.parseDoc(h,u)}var p=a.merge(e.rev_tree,t.metadata.rev_tree[0],1e3),v=u&&(f&&l||!f&&"new_leaf"!==p.conflicts||f&&!l&&"new_branch"===p.conflicts);if(v){var g=c.error(c.REV_CONFLICT);return r[o]=g,i()}var m=t.metadata.rev;t.metadata.rev_tree=p.tree,e.rev_map&&(t.metadata.rev_map=e.rev_map);var _=a.winningRev(t.metadata);l=n.isDeleted(t.metadata,_);var y=0;(u||_===m)&&(y=f===l?0:l>f?-1:1),s(t,_,l,i,!0,y,o)},n.processDocs=function(e,t,r,o,i,s,u,f){function l(e,t,r){var o=a.winningRev(e.metadata),f=n.isDeleted(e.metadata,o);if("was_delete"in u&&f)return i[t]=c.error(c.MISSING_DOC,"deleted"),r();var l=f?0:1;s(e,o,f,r,!1,l,t)}function d(){++v===g&&f&&f()}if(e.length){var h=u.new_edits,p=new n.Map,v=0,g=e.length;e.forEach(function(e,r){if(e._id&&n.isLocalId(e._id))return void t[e._deleted?"_removeLocal":"_putLocal"](e,{ctx:o},function(e){i[r]=e?e:{ok:!0},d()});var s=e.metadata.id;p.has(s)?(g--,p.get(s).push([e,r])):p.set(s,[[e,r]])}),p.forEach(function(e,t){function o(){++u<e.length?a():d()}function a(){var a=e[u],c=a[0],f=a[1];r.has(t)?n.updateDoc(r.get(t),c,i,f,o,s,h):l(c,f,o)}var u=0;a()})}},n.preprocessAttachments=function(e,t,r){function o(e){try{return n.atob(e)}catch(t){var r=c.error(c.BAD_ARG,"Attachments need to be base64 encoded");return{error:r}}}function i(e,r){if(e.stub)return r();if("string"==typeof e.data){var i=o(e.data);if(i.error)return r(i.error);e.length=i.length,e.data="blob"===t?n.createBlob([n.fixBinary(i)],{type:e.content_type}):"base64"===t?n.btoa(i):i,n.MD5(i).then(function(t){e.digest="md5-"+t,r()})}else n.readAsBinaryString(e.data,function(o){"binary"===t?e.data=o:"base64"===t&&(e.data=n.btoa(o)),n.MD5(o).then(function(t){e.digest="md5-"+t,e.length=o.length,r()})})}function s(){u++,e.length===u&&(a?r(a):r())}if(!e.length)return r();var a,u=0;e.forEach(function(e){function t(e){a=e,r++,r===n.length&&s()}var n=e.data&&e.data._attachments?Object.keys(e.data._attachments):[],r=0;if(!n.length)return s();for(var o in e.data._attachments)e.data._attachments.hasOwnProperty(o)&&i(e.data._attachments[o],t)})},n.compactTree=function(e){var t=[];return a.traverseRevTree(e.rev_tree,function(e,n,r,o,i){"available"!==i.status||e||(t.push(n+"-"+r),i.status="missing")}),t};var v=e("vuvuzela");n.safeJsonParse=function(e){try{return JSON.parse(e)}catch(t){return v.parse(e)}},n.safeJsonStringify=function(e){try{return JSON.stringify(e)}catch(t){return v.stringify(e)}}}).call(this,e("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./deps/ajax":15,"./deps/blob":16,"./deps/buffer":34,"./deps/collections":17,"./deps/errors":18,"./deps/md5":19,"./deps/parse-uri":21,"./deps/uuid":23,"./merge":26,_process:40,argsarray:33,bluebird:48,debug:41,events:39,inherits:44,"pouchdb-extend":65,vuvuzela:73}],32:[function(e,t){t.exports="3.2.1"},{}],33:[function(e,t){"use strict";function n(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=n},{}],34:[function(){},{}],35:[function(e,t,n){function r(e,t,n){if(!(this instanceof r))return new r(e,t,n);var o,i=typeof e;if("number"===i)o=e>0?e>>>0:0;else if("string"===i)"base64"===t&&(e=S(e)),o=r.byteLength(e,t);else{if("object"!==i||null===e)throw new TypeError("must start with number, buffer, array or string");"Buffer"===e.type&&N(e.data)&&(e=e.data),o=+e.length>0?Math.floor(+e.length):0}if(this.length>j)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+j.toString(16)+" bytes");var s;r.TYPED_ARRAY_SUPPORT?s=r._augment(new Uint8Array(o)):(s=this,s.length=o,s._isBuffer=!0);var a;if(r.TYPED_ARRAY_SUPPORT&&"number"==typeof e.byteLength)s._set(e);else if(T(e))if(r.isBuffer(e))for(a=0;o>a;a++)s[a]=e.readUInt8(a);else for(a=0;o>a;a++)s[a]=(e[a]%256+256)%256;else if("string"===i)s.write(e,0,t);else if("number"===i&&!r.TYPED_ARRAY_SUPPORT&&!n)for(a=0;o>a;a++)s[a]=0;return s}function o(e,t,n,r){n=Number(n)||0;var o=e.length-n;r?(r=Number(r),r>o&&(r=o)):r=o;var i=t.length;if(i%2!==0)throw new Error("Invalid hex string");r>i/2&&(r=i/2);for(var s=0;r>s;s++){var a=parseInt(t.substr(2*s,2),16);if(isNaN(a))throw new Error("Invalid hex string");e[n+s]=a}return s}function i(e,t,n,r){var o=q(k(t),e,n,r);return o}function s(e,t,n,r){var o=q(x(t),e,n,r);return o}function a(e,t,n,r){return s(e,t,n,r)}function u(e,t,n,r){var o=q(I(t),e,n,r);return o}function c(e,t,n,r){var o=q(O(t),e,n,r,2);return o}function f(e,t,n){return C.fromByteArray(0===t&&n===e.length?e:e.slice(t,n))}function l(e,t,n){var r="",o="";n=Math.min(e.length,n);for(var i=t;n>i;i++)e[i]<=127?(r+=L(o)+String.fromCharCode(e[i]),o=""):o+="%"+e[i].toString(16);return r+L(o)}function d(e,t,n){var r="";n=Math.min(e.length,n);for(var o=t;n>o;o++)r+=String.fromCharCode(e[o]);return r}function h(e,t,n){return d(e,t,n)}function p(e,t,n){var r=e.length;(!t||0>t)&&(t=0),(!n||0>n||n>r)&&(n=r);for(var o="",i=t;n>i;i++)o+=R(e[i]);return o}function v(e,t,n){for(var r=e.slice(t,n),o="",i=0;i<r.length;i+=2)o+=String.fromCharCode(r[i]+256*r[i+1]);return o}function g(e,t,n){if(e%1!==0||0>e)throw new RangeError("offset is not uint");if(e+t>n)throw new RangeError("Trying to access beyond buffer length")}function m(e,t,n,o,i,s){if(!r.isBuffer(e))throw new TypeError("buffer must be a Buffer instance");if(t>i||s>t)throw new TypeError("value is out of bounds");if(n+o>e.length)throw new TypeError("index out of range")}function _(e,t,n,r){0>t&&(t=65535+t+1);for(var o=0,i=Math.min(e.length-n,2);i>o;o++)e[n+o]=(t&255<<8*(r?o:1-o))>>>8*(r?o:1-o)}function y(e,t,n,r){0>t&&(t=4294967295+t+1);for(var o=0,i=Math.min(e.length-n,4);i>o;o++)e[n+o]=t>>>8*(r?o:3-o)&255}function b(e,t,n,r,o,i){if(t>o||i>t)throw new TypeError("value is out of bounds");if(n+r>e.length)throw new TypeError("index out of range")}function w(e,t,n,r,o){return o||b(e,t,n,4,3.4028234663852886e38,-3.4028234663852886e38),D.write(e,t,n,r,23,4),n+4}function E(e,t,n,r,o){return o||b(e,t,n,8,1.7976931348623157e308,-1.7976931348623157e308),D.write(e,t,n,r,52,8),n+8}function S(e){for(e=A(e).replace(P,"");e.length%4!==0;)e+="=";return e}function A(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")}function T(e){return N(e)||r.isBuffer(e)||e&&"object"==typeof e&&"number"==typeof e.length}function R(e){return 16>e?"0"+e.toString(16):e.toString(16)}function k(e){for(var t=[],n=0;n<e.length;n++){var r=e.charCodeAt(n);if(127>=r)t.push(r);else{var o=n;r>=55296&&57343>=r&&n++;for(var i=encodeURIComponent(e.slice(o,n+1)).substr(1).split("%"),s=0;s<i.length;s++)t.push(parseInt(i[s],16))}}return t}function x(e){for(var t=[],n=0;n<e.length;n++)t.push(255&e.charCodeAt(n));return t}function O(e){for(var t,n,r,o=[],i=0;i<e.length;i++)t=e.charCodeAt(i),n=t>>8,r=t%256,o.push(r),o.push(n);return o}function I(e){return C.toByteArray(e)}function q(e,t,n,r,o){o&&(r-=r%o);for(var i=0;r>i&&!(i+n>=t.length||i>=e.length);i++)t[i+n]=e[i];return i}function L(e){try{return decodeURIComponent(e)}catch(t){return String.fromCharCode(65533)}}var C=e("base64-js"),D=e("ieee754"),N=e("is-array");n.Buffer=r,n.SlowBuffer=r,n.INSPECT_MAX_BYTES=50,r.poolSize=8192;var j=1073741823;r.TYPED_ARRAY_SUPPORT=function(){try{var e=new ArrayBuffer(0),t=new Uint8Array(e);return t.foo=function(){return 42},42===t.foo()&&"function"==typeof t.subarray&&0===new Uint8Array(1).subarray(1,1).byteLength}catch(n){return!1}}(),r.isBuffer=function(e){return!(null==e||!e._isBuffer)},r.compare=function(e,t){if(!r.isBuffer(e)||!r.isBuffer(t))throw new TypeError("Arguments must be Buffers");for(var n=e.length,o=t.length,i=0,s=Math.min(n,o);s>i&&e[i]===t[i];i++);return i!==s&&(n=e[i],o=t[i]),o>n?-1:n>o?1:0},r.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"raw":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},r.concat=function(e,t){if(!N(e))throw new TypeError("Usage: Buffer.concat(list[, length])");if(0===e.length)return new r(0);if(1===e.length)return e[0];var n;if(void 0===t)for(t=0,n=0;n<e.length;n++)t+=e[n].length;var o=new r(t),i=0;for(n=0;n<e.length;n++){var s=e[n];s.copy(o,i),i+=s.length}return o},r.byteLength=function(e,t){var n;switch(e+="",t||"utf8"){case"ascii":case"binary":case"raw":n=e.length;break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":n=2*e.length;break;case"hex":n=e.length>>>1;break;case"utf8":case"utf-8":n=k(e).length;break;case"base64":n=I(e).length;break;default:n=e.length}return n},r.prototype.length=void 0,r.prototype.parent=void 0,r.prototype.toString=function(e,t,n){var r=!1;if(t>>>=0,n=void 0===n||1/0===n?this.length:n>>>0,e||(e="utf8"),0>t&&(t=0),n>this.length&&(n=this.length),t>=n)return"";for(;;)switch(e){case"hex":return p(this,t,n);case"utf8":case"utf-8":return l(this,t,n);case"ascii":return d(this,t,n);case"binary":return h(this,t,n);case"base64":return f(this,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return v(this,t,n);default:if(r)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),r=!0}},r.prototype.equals=function(e){if(!r.isBuffer(e))throw new TypeError("Argument must be a Buffer");return 0===r.compare(this,e)},r.prototype.inspect=function(){var e="",t=n.INSPECT_MAX_BYTES;return this.length>0&&(e=this.toString("hex",0,t).match(/.{2}/g).join(" "),this.length>t&&(e+=" ... ")),"<Buffer "+e+">"},r.prototype.compare=function(e){if(!r.isBuffer(e))throw new TypeError("Argument must be a Buffer");return r.compare(this,e)},r.prototype.get=function(e){return console.log(".get() is deprecated. Access using array indexes instead."),this.readUInt8(e)},r.prototype.set=function(e,t){return console.log(".set() is deprecated. Access using array indexes instead."),this.writeUInt8(e,t)},r.prototype.write=function(e,t,n,r){if(isFinite(t))isFinite(n)||(r=n,n=void 0);else{var f=r;r=t,t=n,n=f}t=Number(t)||0;var l=this.length-t;n?(n=Number(n),n>l&&(n=l)):n=l,r=String(r||"utf8").toLowerCase();var d;switch(r){case"hex":d=o(this,e,t,n);break;case"utf8":case"utf-8":d=i(this,e,t,n);break;case"ascii":d=s(this,e,t,n);break;case"binary":d=a(this,e,t,n);break;case"base64":d=u(this,e,t,n);break;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":d=c(this,e,t,n);break;default:throw new TypeError("Unknown encoding: "+r)}return d},r.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}},r.prototype.slice=function(e,t){var n=this.length;if(e=~~e,t=void 0===t?n:~~t,0>e?(e+=n,0>e&&(e=0)):e>n&&(e=n),0>t?(t+=n,0>t&&(t=0)):t>n&&(t=n),e>t&&(t=e),r.TYPED_ARRAY_SUPPORT)return r._augment(this.subarray(e,t));for(var o=t-e,i=new r(o,void 0,!0),s=0;o>s;s++)i[s]=this[s+e];return i},r.prototype.readUInt8=function(e,t){return t||g(e,1,this.length),this[e]},r.prototype.readUInt16LE=function(e,t){return t||g(e,2,this.length),this[e]|this[e+1]<<8},r.prototype.readUInt16BE=function(e,t){return t||g(e,2,this.length),this[e]<<8|this[e+1]},r.prototype.readUInt32LE=function(e,t){return t||g(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},r.prototype.readUInt32BE=function(e,t){return t||g(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},r.prototype.readInt8=function(e,t){return t||g(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},r.prototype.readInt16LE=function(e,t){t||g(e,2,this.length);var n=this[e]|this[e+1]<<8;return 32768&n?4294901760|n:n},r.prototype.readInt16BE=function(e,t){t||g(e,2,this.length);var n=this[e+1]|this[e]<<8;return 32768&n?4294901760|n:n},r.prototype.readInt32LE=function(e,t){return t||g(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},r.prototype.readInt32BE=function(e,t){return t||g(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},r.prototype.readFloatLE=function(e,t){return t||g(e,4,this.length),D.read(this,e,!0,23,4)},r.prototype.readFloatBE=function(e,t){return t||g(e,4,this.length),D.read(this,e,!1,23,4)},r.prototype.readDoubleLE=function(e,t){return t||g(e,8,this.length),D.read(this,e,!0,52,8)},r.prototype.readDoubleBE=function(e,t){return t||g(e,8,this.length),D.read(this,e,!1,52,8)},r.prototype.writeUInt8=function(e,t,n){return e=+e,t>>>=0,n||m(this,e,t,1,255,0),r.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),this[t]=e,t+1},r.prototype.writeUInt16LE=function(e,t,n){return e=+e,t>>>=0,n||m(this,e,t,2,65535,0),r.TYPED_ARRAY_SUPPORT?(this[t]=e,this[t+1]=e>>>8):_(this,e,t,!0),t+2},r.prototype.writeUInt16BE=function(e,t,n){return e=+e,t>>>=0,n||m(this,e,t,2,65535,0),r.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=e):_(this,e,t,!1),t+2},r.prototype.writeUInt32LE=function(e,t,n){return e=+e,t>>>=0,n||m(this,e,t,4,4294967295,0),r.TYPED_ARRAY_SUPPORT?(this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=e):y(this,e,t,!0),t+4},r.prototype.writeUInt32BE=function(e,t,n){return e=+e,t>>>=0,n||m(this,e,t,4,4294967295,0),r.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e):y(this,e,t,!1),t+4},r.prototype.writeInt8=function(e,t,n){return e=+e,t>>>=0,n||m(this,e,t,1,127,-128),r.TYPED_ARRAY_SUPPORT||(e=Math.floor(e)),0>e&&(e=255+e+1),this[t]=e,t+1},r.prototype.writeInt16LE=function(e,t,n){return e=+e,t>>>=0,n||m(this,e,t,2,32767,-32768),r.TYPED_ARRAY_SUPPORT?(this[t]=e,this[t+1]=e>>>8):_(this,e,t,!0),t+2},r.prototype.writeInt16BE=function(e,t,n){return e=+e,t>>>=0,n||m(this,e,t,2,32767,-32768),r.TYPED_ARRAY_SUPPORT?(this[t]=e>>>8,this[t+1]=e):_(this,e,t,!1),t+2},r.prototype.writeInt32LE=function(e,t,n){return e=+e,t>>>=0,n||m(this,e,t,4,2147483647,-2147483648),r.TYPED_ARRAY_SUPPORT?(this[t]=e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24):y(this,e,t,!0),t+4},r.prototype.writeInt32BE=function(e,t,n){return e=+e,t>>>=0,n||m(this,e,t,4,2147483647,-2147483648),0>e&&(e=4294967295+e+1),r.TYPED_ARRAY_SUPPORT?(this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=e):y(this,e,t,!1),t+4},r.prototype.writeFloatLE=function(e,t,n){return w(this,e,t,!0,n)},r.prototype.writeFloatBE=function(e,t,n){return w(this,e,t,!1,n)},r.prototype.writeDoubleLE=function(e,t,n){return E(this,e,t,!0,n)},r.prototype.writeDoubleBE=function(e,t,n){return E(this,e,t,!1,n)},r.prototype.copy=function(e,t,n,o){var i=this;if(n||(n=0),o||0===o||(o=this.length),t||(t=0),o!==n&&0!==e.length&&0!==i.length){if(n>o)throw new TypeError("sourceEnd < sourceStart");if(0>t||t>=e.length)throw new TypeError("targetStart out of bounds");if(0>n||n>=i.length)throw new TypeError("sourceStart out of bounds");if(0>o||o>i.length)throw new TypeError("sourceEnd out of bounds");o>this.length&&(o=this.length),e.length-t<o-n&&(o=e.length-t+n);var s=o-n;if(1e3>s||!r.TYPED_ARRAY_SUPPORT)for(var a=0;s>a;a++)e[a+t]=this[a+n];else e._set(this.subarray(n,n+s),t)}},r.prototype.fill=function(e,t,n){if(e||(e=0),t||(t=0),n||(n=this.length),t>n)throw new TypeError("end < start");if(n!==t&&0!==this.length){if(0>t||t>=this.length)throw new TypeError("start out of bounds");if(0>n||n>this.length)throw new TypeError("end out of bounds");var r;if("number"==typeof e)for(r=t;n>r;r++)this[r]=e;else{var o=k(e.toString()),i=o.length;for(r=t;n>r;r++)this[r]=o[r%i]}return this}},r.prototype.toArrayBuffer=function(){if("undefined"!=typeof Uint8Array){if(r.TYPED_ARRAY_SUPPORT)return new r(this).buffer;for(var e=new Uint8Array(this.length),t=0,n=e.length;n>t;t+=1)e[t]=this[t];return e.buffer}throw new TypeError("Buffer.toArrayBuffer not supported in this browser")};var B=r.prototype;r._augment=function(e){return e.constructor=r,e._isBuffer=!0,e._get=e.get,e._set=e.set,e.get=B.get,e.set=B.set,e.write=B.write,e.toString=B.toString,e.toLocaleString=B.toString,e.toJSON=B.toJSON,e.equals=B.equals,e.compare=B.compare,e.copy=B.copy,e.slice=B.slice,e.readUInt8=B.readUInt8,e.readUInt16LE=B.readUInt16LE,e.readUInt16BE=B.readUInt16BE,e.readUInt32LE=B.readUInt32LE,e.readUInt32BE=B.readUInt32BE,e.readInt8=B.readInt8,e.readInt16LE=B.readInt16LE,e.readInt16BE=B.readInt16BE,e.readInt32LE=B.readInt32LE,e.readInt32BE=B.readInt32BE,e.readFloatLE=B.readFloatLE,e.readFloatBE=B.readFloatBE,e.readDoubleLE=B.readDoubleLE,e.readDoubleBE=B.readDoubleBE,e.writeUInt8=B.writeUInt8,e.writeUInt16LE=B.writeUInt16LE,e.writeUInt16BE=B.writeUInt16BE,e.writeUInt32LE=B.writeUInt32LE,e.writeUInt32BE=B.writeUInt32BE,e.writeInt8=B.writeInt8,e.writeInt16LE=B.writeInt16LE,e.writeInt16BE=B.writeInt16BE,e.writeInt32LE=B.writeInt32LE,e.writeInt32BE=B.writeInt32BE,e.writeFloatLE=B.writeFloatLE,e.writeFloatBE=B.writeFloatBE,e.writeDoubleLE=B.writeDoubleLE,e.writeDoubleBE=B.writeDoubleBE,e.fill=B.fill,e.inspect=B.inspect,e.toArrayBuffer=B.toArrayBuffer,e};var P=/[^+\/0-9A-z]/g},{"base64-js":36,ieee754:37,"is-array":38}],36:[function(e,t,n){var r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";!function(e){"use strict";function t(e){var t=e.charCodeAt(0);return t===s?62:t===a?63:u>t?-1:u+10>t?t-u+26+26:f+26>t?t-f:c+26>t?t-c+26:void 0}function n(e){function n(e){c[l++]=e}var r,o,s,a,u,c;if(e.length%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var f=e.length;u="="===e.charAt(f-2)?2:"="===e.charAt(f-1)?1:0,c=new i(3*e.length/4-u),s=u>0?e.length-4:e.length;var l=0;for(r=0,o=0;s>r;r+=4,o+=3)a=t(e.charAt(r))<<18|t(e.charAt(r+1))<<12|t(e.charAt(r+2))<<6|t(e.charAt(r+3)),n((16711680&a)>>16),n((65280&a)>>8),n(255&a);return 2===u?(a=t(e.charAt(r))<<2|t(e.charAt(r+1))>>4,n(255&a)):1===u&&(a=t(e.charAt(r))<<10|t(e.charAt(r+1))<<4|t(e.charAt(r+2))>>2,n(a>>8&255),n(255&a)),c}function o(e){function t(e){return r.charAt(e)}function n(e){return t(e>>18&63)+t(e>>12&63)+t(e>>6&63)+t(63&e)}var o,i,s,a=e.length%3,u="";for(o=0,s=e.length-a;s>o;o+=3)i=(e[o]<<16)+(e[o+1]<<8)+e[o+2],u+=n(i);switch(a){case 1:i=e[e.length-1],u+=t(i>>2),u+=t(i<<4&63),u+="==";break;case 2:i=(e[e.length-2]<<8)+e[e.length-1],u+=t(i>>10),u+=t(i>>4&63),u+=t(i<<2&63),u+="="}return u}var i="undefined"!=typeof Uint8Array?Uint8Array:Array,s="+".charCodeAt(0),a="/".charCodeAt(0),u="0".charCodeAt(0),c="a".charCodeAt(0),f="A".charCodeAt(0);e.toByteArray=n,e.fromByteArray=o}("undefined"==typeof n?this.base64js={}:n)},{}],37:[function(e,t,n){n.read=function(e,t,n,r,o){var i,s,a=8*o-r-1,u=(1<<a)-1,c=u>>1,f=-7,l=n?o-1:0,d=n?-1:1,h=e[t+l];for(l+=d,i=h&(1<<-f)-1,h>>=-f,f+=a;f>0;i=256*i+e[t+l],l+=d,f-=8);for(s=i&(1<<-f)-1,i>>=-f,f+=r;f>0;s=256*s+e[t+l],l+=d,f-=8);if(0===i)i=1-c;else{if(i===u)return s?0/0:1/0*(h?-1:1);s+=Math.pow(2,r),i-=c}return(h?-1:1)*s*Math.pow(2,i-r)},n.write=function(e,t,n,r,o,i){var s,a,u,c=8*i-o-1,f=(1<<c)-1,l=f>>1,d=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,h=r?0:i-1,p=r?1:-1,v=0>t||0===t&&0>1/t?1:0;for(t=Math.abs(t),isNaN(t)||1/0===t?(a=isNaN(t)?1:0,s=f):(s=Math.floor(Math.log(t)/Math.LN2),t*(u=Math.pow(2,-s))<1&&(s--,u*=2),t+=s+l>=1?d/u:d*Math.pow(2,1-l),t*u>=2&&(s++,u/=2),s+l>=f?(a=0,s=f):s+l>=1?(a=(t*u-1)*Math.pow(2,o),s+=l):(a=t*Math.pow(2,l-1)*Math.pow(2,o),s=0));o>=8;e[n+h]=255&a,h+=p,a/=256,o-=8);for(s=s<<o|a,c+=o;c>0;e[n+h]=255&s,h+=p,s/=256,c-=8);e[n+h-p]|=128*v}},{}],38:[function(e,t){var n=Array.isArray,r=Object.prototype.toString;t.exports=n||function(e){return!!e&&"[object Array]"==r.call(e)}},{}],39:[function(e,t){function n(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function r(e){return"function"==typeof e}function o(e){return"number"==typeof e}function i(e){return"object"==typeof e&&null!==e}function s(e){return void 0===e}t.exports=n,n.EventEmitter=n,n.prototype._events=void 0,n.prototype._maxListeners=void 0,n.defaultMaxListeners=10,n.prototype.setMaxListeners=function(e){if(!o(e)||0>e||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},n.prototype.emit=function(e){var t,n,o,a,u,c;if(this._events||(this._events={}),"error"===e&&(!this._events.error||i(this._events.error)&&!this._events.error.length)){if(t=arguments[1],t instanceof Error)throw t;throw TypeError('Uncaught, unspecified "error" event.')}if(n=this._events[e],s(n))return!1;if(r(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:for(o=arguments.length,a=new Array(o-1),u=1;o>u;u++)a[u-1]=arguments[u];n.apply(this,a)}else if(i(n)){for(o=arguments.length,a=new Array(o-1),u=1;o>u;u++)a[u-1]=arguments[u];for(c=n.slice(),o=c.length,u=0;o>u;u++)c[u].apply(this,a)}return!0},n.prototype.addListener=function(e,t){var o;if(!r(t))throw TypeError("listener must be a function");if(this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,r(t.listener)?t.listener:t),this._events[e]?i(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,i(this._events[e])&&!this._events[e].warned){var o;o=s(this._maxListeners)?n.defaultMaxListeners:this._maxListeners,o&&o>0&&this._events[e].length>o&&(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())}return this},n.prototype.on=n.prototype.addListener,n.prototype.once=function(e,t){function n(){this.removeListener(e,n),o||(o=!0,t.apply(this,arguments))}if(!r(t))throw TypeError("listener must be a function");var o=!1;return n.listener=t,this.on(e,n),this},n.prototype.removeListener=function(e,t){var n,o,s,a;if(!r(t))throw TypeError("listener must be a function");if(!this._events||!this._events[e])return this;if(n=this._events[e],s=n.length,o=-1,n===t||r(n.listener)&&n.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(i(n)){for(a=s;a-->0;)if(n[a]===t||n[a].listener&&n[a].listener===t){o=a;break}if(0>o)return this;1===n.length?(n.length=0,delete this._events[e]):n.splice(o,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},n.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],r(n))this.removeListener(e,n);else for(;n.length;)this.removeListener(e,n[n.length-1]);return delete this._events[e],this},n.prototype.listeners=function(e){var t;return t=this._events&&this._events[e]?r(this._events[e])?[this._events[e]]:this._events[e].slice():[]},n.listenerCount=function(e,t){var n;return n=e._events&&e._events[t]?r(e._events[t])?1:e._events[t].length:0}},{}],40:[function(e,t){function n(){}var r=t.exports={};r.nextTick=function(){var e="undefined"!=typeof window&&window.setImmediate,t="undefined"!=typeof window&&window.MutationObserver,n="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(e)return function(e){return window.setImmediate(e)};var r=[];if(t){var o=document.createElement("div"),i=new MutationObserver(function(){var e=r.slice();r.length=0,e.forEach(function(e){e()})});return i.observe(o,{attributes:!0}),function(e){r.length||o.setAttribute("yes","no"),r.push(e)}}return n?(window.addEventListener("message",function(e){var t=e.source;if((t===window||null===t)&&"process-tick"===e.data&&(e.stopPropagation(),r.length>0)){var n=r.shift();n()}},!0),function(e){r.push(e),window.postMessage("process-tick","*")}):function(e){setTimeout(e,0)}}(),r.title="browser",r.browser=!0,r.env={},r.argv=[],r.on=n,r.addListener=n,r.once=n,r.off=n,r.removeListener=n,r.removeAllListeners=n,r.emit=n,r.binding=function(){throw new Error("process.binding is not supported")},r.cwd=function(){return"/"},r.chdir=function(){throw new Error("process.chdir is not supported")}},{}],41:[function(e,t,n){function r(){return"WebkitAppearance"in document.documentElement.style||window.console&&(console.firebug||console.exception&&console.table)||navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)&&parseInt(RegExp.$1,10)>=31}function o(){var e=arguments,t=this.useColors;if(e[0]=(t?"%c":"")+this.namespace+(t?" %c":" ")+e[0]+(t?"%c ":" ")+"+"+n.humanize(this.diff),!t)return e;var r="color: "+this.color;e=[e[0],r,"color: inherit"].concat(Array.prototype.slice.call(e,1));var o=0,i=0;return e[0].replace(/%[a-z%]/g,function(e){"%"!==e&&(o++,"%c"===e&&(i=o))}),e.splice(i,0,r),e}function i(){return"object"==typeof console&&console.log&&Function.prototype.apply.call(console.log,console,arguments)}function s(e){try{null==e?u.removeItem("debug"):u.debug=e}catch(t){}}function a(){var e;try{e=u.debug}catch(t){}return e}n=t.exports=e("./debug"),n.log=i,n.formatArgs=o,n.save=s,n.load=a,n.useColors=r;var u;u="undefined"!=typeof chrome&&"undefined"!=typeof chrome.storage?chrome.storage.local:window.localStorage,n.colors=["lightseagreen","forestgreen","goldenrod","dodgerblue","darkorchid","crimson"],n.formatters.j=function(e){return JSON.stringify(e)},n.enable(a())},{"./debug":42}],42:[function(e,t,n){function r(){return n.colors[f++%n.colors.length]}function o(e){function t(){}function o(){var e=o,t=+new Date,i=t-(c||t);e.diff=i,e.prev=c,e.curr=t,c=t,null==e.useColors&&(e.useColors=n.useColors()),null==e.color&&e.useColors&&(e.color=r());var s=Array.prototype.slice.call(arguments);s[0]=n.coerce(s[0]),"string"!=typeof s[0]&&(s=["%o"].concat(s));var a=0;s[0]=s[0].replace(/%([a-z%])/g,function(t,r){if("%"===t)return t;a++;var o=n.formatters[r];if("function"==typeof o){var i=s[a];t=o.call(e,i),s.splice(a,1),a--}return t}),"function"==typeof n.formatArgs&&(s=n.formatArgs.apply(e,s));var u=o.log||n.log||console.log.bind(console);u.apply(e,s)}t.enabled=!1,o.enabled=!0;var i=n.enabled(e)?o:t;return i.namespace=e,i}function i(e){n.save(e);for(var t=(e||"").split(/[\s,]+/),r=t.length,o=0;r>o;o++)t[o]&&(e=t[o].replace(/\*/g,".*?"),"-"===e[0]?n.skips.push(new RegExp("^"+e.substr(1)+"$")):n.names.push(new RegExp("^"+e+"$")))}function s(){n.enable("")}function a(e){var t,r;for(t=0,r=n.skips.length;r>t;t++)if(n.skips[t].test(e))return!1;for(t=0,r=n.names.length;r>t;t++)if(n.names[t].test(e))return!0;return!1}function u(e){return e instanceof Error?e.stack||e.message:e}n=t.exports=o,n.coerce=u,n.disable=s,n.enable=i,n.enabled=a,n.humanize=e("ms"),n.names=[],n.skips=[],n.formatters={};var c,f=0},{ms:43}],43:[function(e,t){function n(e){var t=/^((?:\d+)?\.?\d+) *(ms|seconds?|s|minutes?|m|hours?|h|days?|d|years?|y)?$/i.exec(e);if(t){var n=parseFloat(t[1]),r=(t[2]||"ms").toLowerCase();switch(r){case"years":case"year":case"y":return n*f;
case"days":case"day":case"d":return n*c;case"hours":case"hour":case"h":return n*u;case"minutes":case"minute":case"m":return n*a;case"seconds":case"second":case"s":return n*s;case"ms":return n}}}function r(e){return e>=c?Math.round(e/c)+"d":e>=u?Math.round(e/u)+"h":e>=a?Math.round(e/a)+"m":e>=s?Math.round(e/s)+"s":e+"ms"}function o(e){return i(e,c,"day")||i(e,u,"hour")||i(e,a,"minute")||i(e,s,"second")||e+" ms"}function i(e,t,n){return t>e?void 0:1.5*t>e?Math.floor(e/t)+" "+n:Math.ceil(e/t)+" "+n+"s"}var s=1e3,a=60*s,u=60*a,c=24*u,f=365.25*c;t.exports=function(e,t){return t=t||{},"string"==typeof e?n(e):t["long"]?o(e):r(e)}},{}],44:[function(e,t){t.exports="function"==typeof Object.create?function(e,t){e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}:function(e,t){e.super_=t;var n=function(){};n.prototype=t.prototype,e.prototype=new n,e.prototype.constructor=e}},{}],45:[function(e,t){"use strict";function n(){}t.exports=n},{}],46:[function(e,t){"use strict";function n(e){function t(e,t){function r(e){c[t]=e,++f===n&!u&&(u=!0,a.resolve(d,c))}i(e).then(r,function(e){u||(u=!0,a.reject(d,e))})}if("[object Array]"!==Object.prototype.toString.call(e))return o(new TypeError("must be an array"));var n=e.length,u=!1;if(!n)return i([]);for(var c=new Array(n),f=0,l=-1,d=new r(s);++l<n;)t(e[l],l);return d}var r=e("./promise"),o=e("./reject"),i=e("./resolve"),s=e("./INTERNAL"),a=e("./handlers");t.exports=n},{"./INTERNAL":45,"./handlers":47,"./promise":49,"./reject":52,"./resolve":53}],47:[function(e,t,n){"use strict";function r(e){var t=e&&e.then;return e&&"object"==typeof e&&"function"==typeof t?function(){t.apply(e,arguments)}:void 0}var o=e("./tryCatch"),i=e("./resolveThenable"),s=e("./states");n.resolve=function(e,t){var a=o(r,t);if("error"===a.status)return n.reject(e,a.value);var u=a.value;if(u)i.safely(e,u);else{e.state=s.FULFILLED,e.outcome=t;for(var c=-1,f=e.queue.length;++c<f;)e.queue[c].callFulfilled(t)}return e},n.reject=function(e,t){e.state=s.REJECTED,e.outcome=t;for(var n=-1,r=e.queue.length;++n<r;)e.queue[n].callRejected(t);return e}},{"./resolveThenable":54,"./states":55,"./tryCatch":56}],48:[function(e,t,n){t.exports=n=e("./promise"),n.resolve=e("./resolve"),n.reject=e("./reject"),n.all=e("./all"),n.race=e("./race")},{"./all":46,"./promise":49,"./race":51,"./reject":52,"./resolve":53}],49:[function(e,t){"use strict";function n(e){if(!(this instanceof n))return new n(e);if("function"!=typeof e)throw new TypeError("reslover must be a function");this.state=s.PENDING,this.queue=[],this.outcome=void 0,e!==o&&i.safely(this,e)}var r=e("./unwrap"),o=e("./INTERNAL"),i=e("./resolveThenable"),s=e("./states"),a=e("./queueItem");t.exports=n,n.prototype["catch"]=function(e){return this.then(null,e)},n.prototype.then=function(e,t){if("function"!=typeof e&&this.state===s.FULFILLED||"function"!=typeof t&&this.state===s.REJECTED)return this;var i=new n(o);if(this.state!==s.PENDING){var u=this.state===s.FULFILLED?e:t;r(i,u,this.outcome)}else this.queue.push(new a(i,e,t));return i}},{"./INTERNAL":45,"./queueItem":50,"./resolveThenable":54,"./states":55,"./unwrap":57}],50:[function(e,t){"use strict";function n(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)}var r=e("./handlers"),o=e("./unwrap");t.exports=n,n.prototype.callFulfilled=function(e){r.resolve(this.promise,e)},n.prototype.otherCallFulfilled=function(e){o(this.promise,this.onFulfilled,e)},n.prototype.callRejected=function(e){r.reject(this.promise,e)},n.prototype.otherCallRejected=function(e){o(this.promise,this.onRejected,e)}},{"./handlers":47,"./unwrap":57}],51:[function(e,t){"use strict";function n(e){function t(e){i(e).then(function(e){u||(u=!0,a.resolve(f,e))},function(e){u||(u=!0,a.reject(f,e))})}if("[object Array]"!==Object.prototype.toString.call(e))return o(new TypeError("must be an array"));var n=e.length,u=!1;if(!n)return i([]);for(var c=-1,f=new r(s);++c<n;)t(e[c]);return f}var r=e("./promise"),o=e("./reject"),i=e("./resolve"),s=e("./INTERNAL"),a=e("./handlers");t.exports=n},{"./INTERNAL":45,"./handlers":47,"./promise":49,"./reject":52,"./resolve":53}],52:[function(e,t){"use strict";function n(e){var t=new r(o);return i.reject(t,e)}var r=e("./promise"),o=e("./INTERNAL"),i=e("./handlers");t.exports=n},{"./INTERNAL":45,"./handlers":47,"./promise":49}],53:[function(e,t){"use strict";function n(e){if(e)return e instanceof r?e:i.resolve(new r(o),e);var t=typeof e;switch(t){case"boolean":return s;case"undefined":return u;case"object":return a;case"number":return c;case"string":return f}}var r=e("./promise"),o=e("./INTERNAL"),i=e("./handlers");t.exports=n;var s=i.resolve(new r(o),!1),a=i.resolve(new r(o),null),u=i.resolve(new r(o),void 0),c=i.resolve(new r(o),0),f=i.resolve(new r(o),"")},{"./INTERNAL":45,"./handlers":47,"./promise":49}],54:[function(e,t,n){"use strict";function r(e,t){function n(t){a||(a=!0,o.reject(e,t))}function r(t){a||(a=!0,o.resolve(e,t))}function s(){t(r,n)}var a=!1,u=i(s);"error"===u.status&&n(u.value)}var o=e("./handlers"),i=e("./tryCatch");n.safely=r},{"./handlers":47,"./tryCatch":56}],55:[function(e,t,n){n.REJECTED=["REJECTED"],n.FULFILLED=["FULFILLED"],n.PENDING=["PENDING"]},{}],56:[function(e,t){"use strict";function n(e,t){var n={};try{n.value=e(t),n.status="success"}catch(r){n.status="error",n.value=r}return n}t.exports=n},{}],57:[function(e,t){"use strict";function n(e,t,n){r(function(){var r;try{r=t(n)}catch(i){return o.reject(e,i)}r===e?o.reject(e,new TypeError("Cannot resolve promise with itself")):o.resolve(e,r)})}var r=e("immediate"),o=e("./handlers");t.exports=n},{"./handlers":47,immediate:58}],58:[function(e,t){"use strict";function n(){o=!0;for(var e,t,n=a.length;n;){for(t=a,a=[],e=-1;++e<n;)t[e]();n=a.length}o=!1}function r(e){1!==a.push(e)||o||i()}for(var o,i,s=[e("./nextTick"),e("./mutation.js"),e("./messageChannel"),e("./stateChange"),e("./timeout")],a=[],u=-1,c=s.length;++u<c;)if(s[u]&&s[u].test&&s[u].test()){i=s[u].install(n);break}t.exports=r},{"./messageChannel":59,"./mutation.js":60,"./nextTick":34,"./stateChange":61,"./timeout":62}],59:[function(e,t,n){(function(e){"use strict";n.test=function(){return e.setImmediate?!1:"undefined"!=typeof e.MessageChannel},n.install=function(t){var n=new e.MessageChannel;return n.port1.onmessage=t,function(){n.port2.postMessage(0)}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],60:[function(e,t,n){(function(e){"use strict";var t=e.MutationObserver||e.WebKitMutationObserver;n.test=function(){return t},n.install=function(n){var r=0,o=new t(n),i=e.document.createTextNode("");return o.observe(i,{characterData:!0}),function(){i.data=r=++r%2}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],61:[function(e,t,n){(function(e){"use strict";n.test=function(){return"document"in e&&"onreadystatechange"in e.document.createElement("script")},n.install=function(t){return function(){var n=e.document.createElement("script");return n.onreadystatechange=function(){t(),n.onreadystatechange=null,n.parentNode.removeChild(n),n=null},e.document.documentElement.appendChild(n),t}}}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],62:[function(e,t,n){"use strict";n.test=function(){return!0},n.install=function(e){return function(){setTimeout(e,0)}}},{}],63:[function(e,t,n){"use strict";function r(e){if(null!==e)switch(typeof e){case"boolean":return e?1:0;case"number":return f(e);case"string":return e.replace(/\u0002/g,"").replace(/\u0001/g,"").replace(/\u0000/g,"");case"object":var t=Array.isArray(e),r=t?e:Object.keys(e),o=-1,i=r.length,s="";if(t)for(;++o<i;)s+=n.toIndexableString(r[o]);else for(;++o<i;){var a=r[o];s+=n.toIndexableString(a)+n.toIndexableString(e[a])}return s}return""}function o(e,t){var n,r=t,o="1"===e[t];if(o)n=0,t++;else{var i="0"===e[t];t++;var s="",a=e.substring(t,t+d),u=parseInt(a,10)+l;for(i&&(u=-u),t+=d;;){var c=e[t];if("\x00"===c)break;s+=c,t++}s=s.split("."),n=1===s.length?parseInt(s,10):parseFloat(s[0]+"."+s[1]),i&&(n-=10),0!==u&&(n=parseFloat(n+"e"+u))}return{num:n,length:t-r}}function i(e,t){var n=e.pop();if(t.length){var r=t[t.length-1];n===r.element&&(t.pop(),r=t[t.length-1]);var o=r.element,i=r.index;if(Array.isArray(o))o.push(n);else if(i===e.length-2){var s=e.pop();o[s]=n}else e.push(n)}}function s(e,t){for(var r=Math.min(e.length,t.length),o=0;r>o;o++){var i=n.collate(e[o],t[o]);if(0!==i)return i}return e.length===t.length?0:e.length>t.length?1:-1}function a(e,t){return e===t?0:e>t?1:-1}function u(e,t){for(var r=Object.keys(e),o=Object.keys(t),i=Math.min(r.length,o.length),s=0;i>s;s++){var a=n.collate(r[s],o[s]);if(0!==a)return a;if(a=n.collate(e[r[s]],t[o[s]]),0!==a)return a}return r.length===o.length?0:r.length>o.length?1:-1}function c(e){var t=["boolean","number","string","object"],n=t.indexOf(typeof e);return~n?null===e?1:Array.isArray(e)?5:3>n?n+2:n+3:Array.isArray(e)?5:void 0}function f(e){if(0===e)return"1";var t=e.toExponential().split(/e\+?/),n=parseInt(t[1],10),r=0>e,o=r?"0":"2",i=(r?-n:n)-l,s=p.padLeft(i.toString(),"0",d);o+=h+s;var a=Math.abs(parseFloat(t[0]));r&&(a=10-a);var u=a.toFixed(20);return u=u.replace(/\.?0+$/,""),o+=h+u}var l=-324,d=3,h="",p=e("./utils");n.collate=function(e,t){if(e===t)return 0;e=n.normalizeKey(e),t=n.normalizeKey(t);var r=c(e),o=c(t);if(r-o!==0)return r-o;if(null===e)return 0;switch(typeof e){case"number":return e-t;case"boolean":return e===t?0:t>e?-1:1;case"string":return a(e,t)}return Array.isArray(e)?s(e,t):u(e,t)},n.normalizeKey=function(e){switch(typeof e){case"undefined":return null;case"number":return 1/0===e||e===-1/0||isNaN(e)?null:e;case"object":var t=e;if(Array.isArray(e)){var r=e.length;e=new Array(r);for(var o=0;r>o;o++)e[o]=n.normalizeKey(t[o])}else{if(e instanceof Date)return e.toJSON();if(null!==e){e={};for(var i in t)if(t.hasOwnProperty(i)){var s=t[i];"undefined"!=typeof s&&(e[i]=n.normalizeKey(s))}}}}return e},n.toIndexableString=function(e){var t="\x00";return e=n.normalizeKey(e),c(e)+h+r(e)+t},n.parseIndexableString=function(e){for(var t=[],n=[],r=0;;){var s=e[r++];if("\x00"!==s)switch(s){case"1":t.push(null);break;case"2":t.push("1"===e[r]),r++;break;case"3":var a=o(e,r);t.push(a.num),r+=a.length;break;case"4":for(var u="";;){var c=e[r];if("\x00"===c)break;u+=c,r++}u=u.replace(/\u0001\u0001/g,"\x00").replace(/\u0001\u0002/g,"").replace(/\u0002\u0002/g,""),t.push(u);break;case"5":var f={element:[],index:t.length};t.push(f.element),n.push(f);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: "+s)}else{if(1===t.length)return t.pop();i(t,n)}}}},{"./utils":64}],64:[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}n.padLeft=function(e,t,n){var o=r(e,t,n);return o+e},n.padRight=function(e,t,n){var o=r(e,t,n);return e+o},n.stringLexCompare=function(e,t){var n,r=e.length,o=t.length;for(n=0;r>n;n++){if(n===o)return 1;var i=e.charAt(n),s=t.charAt(n);if(i!==s)return s>i?-1:1}return o>r?-1:0},n.intToDecimalForm=function(e){var t=0>e,n="";do{var r=t?-Math.ceil(e%10):Math.floor(e%10);n=r+n,e=t?Math.ceil(e/10):Math.floor(e/10)}while(e);return t&&"0"!==n&&(n="-"+n),n}},{}],65:[function(e,t){"use strict";function n(e){return null===e?String(e):"object"==typeof e||"function"==typeof e?u[d.call(e)]||"object":typeof e}function r(e){return null!==e&&e===e.window}function o(e){if(!e||"object"!==n(e)||e.nodeType||r(e))return!1;try{if(e.constructor&&!h.call(e,"constructor")&&!h.call(e.constructor.prototype,"isPrototypeOf"))return!1}catch(t){return!1}var o;for(o in e);return void 0===o||h.call(e,o)}function i(e){return"function"===n(e)}function s(){for(var e=[],t=-1,n=arguments.length,r=new Array(n);++t<n;)r[t]=arguments[t];var o={};e.push({args:r,result:{container:o,key:"key"}});for(var i;i=e.pop();)a(e,i.args,i.result);return o.key}function a(e,t,n){var r,s,a,u,c,f,l,d=t[0]||{},h=1,v=t.length,g=!1,m=/\d+/;for("boolean"==typeof d&&(g=d,d=t[1]||{},h=2),"object"==typeof d||i(d)||(d={}),v===h&&(d=this,--h);v>h;h++)if(null!=(r=t[h])){l=p(r);for(s in r)if(!(s in Object.prototype)){if(l&&!m.test(s))continue;if(a=d[s],u=r[s],d===u)continue;g&&u&&(o(u)||(c=p(u)))?(c?(c=!1,f=a&&p(a)?a:[]):f=a&&o(a)?a:{},e.push({args:[g,f,u],result:{container:d,key:s}})):void 0!==u&&(p(r)&&i(u)||(d[s]=u))}}n.container[n.key]=d}for(var u={},c=["Boolean","Number","String","Function","Array","Date","RegExp","Object","Error"],f=0;f<c.length;f++){var l=c[f];u["[object "+l+"]"]=l.toLowerCase()}var d=u.toString,h=u.hasOwnProperty,p=Array.isArray||function(e){return"array"===n(e)};t.exports=s},{}],66:[function(e,t){"use strict";var n=e("./upsert"),r=e("./utils"),o=r.Promise;t.exports=function(e){var t=e.db,i=e.viewName,s=e.map,a=e.reduce,u=e.temporary,c=s.toString()+(a&&a.toString())+"undefined";if(!u&&t._cachedViews){var f=t._cachedViews[c];if(f)return o.resolve(f)}return t.info().then(function(e){function o(e){e.views=e.views||{};var t=i;-1===t.indexOf("/")&&(t=i+"/"+i);var n=e.views[t]=e.views[t]||{};if(!n[f])return n[f]=!0,e}var f=e.db_name+"-mrview-"+(u?"temp":r.MD5(c));return n(t,"_local/mrviews",o).then(function(){return t.registerDependentDatabase(f).then(function(e){var n=e.db;n.auto_compaction=!0;var r={name:f,db:n,sourceDB:t,adapter:t.adapter,mapFun:s,reduceFun:a};return r.db.get("_local/lastSeq")["catch"](function(e){if(404!==e.status)throw e}).then(function(e){return r.seq=e?e.seq:0,u||(t._cachedViews=t._cachedViews||{},t._cachedViews[c]=r,r.db.on("destroyed",function(){delete t._cachedViews[c]})),r})})})})}},{"./upsert":70,"./utils":71}],67:[function(_dereq_,module,exports){"use strict";module.exports=function(func,emit,sum,log,isArray,toJSON){return eval("'use strict'; ("+func.replace(/;\s*$/,"")+");")}},{}],68:[function(e,t,n){(function(t){"use strict";function r(e){return-1===e.indexOf("/")?[e,e]:e.split("/")}function o(e,t,n){try{return{output:t.apply(null,n)}}catch(r){return e.emit("error",r),{error:r}}}function i(e,t){var n=A(e.key,t.key);return 0!==n?n:A(e.value,t.value)}function s(e,t,n){return n=n||0,"number"==typeof t?e.slice(n,t+n):n>0?e.slice(n):e}function a(e){var t=e.value,n=t&&"object"==typeof t&&t._id||e.id;return n}function u(e){var t=new Error("builtin "+e+" function requires map values to be numbers or number arrays");return t.name="invalid_value",t.status=500,t}function c(e){for(var t=0,n=0,r=e.length;r>n;n++){var o=e[n];if("number"!=typeof o){if(!Array.isArray(o))throw u("_sum");t="number"==typeof t?[t]:t;for(var i=0,s=o.length;s>i;i++){var a=o[i];if("number"!=typeof a)throw u("_sum");"undefined"==typeof t[i]?t.push(a):t[i]+=a}}else"number"==typeof t?t+=o:t[0]+=o}return t}function f(e,t,n,r){var o=t[e];"undefined"!=typeof o&&(r&&(o=encodeURIComponent(JSON.stringify(o))),n.push(e+"="+o))}function l(e,t){var n=e.descending?"endkey":"startkey",r=e.descending?"startkey":"endkey";if("undefined"!=typeof e[n]&&"undefined"!=typeof e[r]&&A(e[n],e[r])>0)throw new y("No rows can match your key range, reverse your start_key and end_key or set {descending : true}");if(t.reduce&&e.reduce!==!1){if(e.include_docs)throw new y("{include_docs:true} is invalid for reduce");if(e.keys&&e.keys.length>1&&!e.group&&!e.group_level)throw new y("Multi-key fetches for reduce views must use {group: true}")}if(e.group_level){if("number"!=typeof e.group_level)throw new y('Invalid value for integer: "'+e.group_level+'"');if(e.group_level<0)throw new y('Invalid value for positive integer: "'+e.group_level+'"')}}function d(e,t,n){var o,i=[],s="GET";if(f("reduce",n,i),f("include_docs",n,i),f("attachments",n,i),f("limit",n,i),f("descending",n,i),f("group",n,i),f("group_level",n,i),f("skip",n,i),f("stale",n,i),f("conflicts",n,i),f("startkey",n,i,!0),f("endkey",n,i,!0),f("inclusive_end",n,i),f("key",n,i,!0),i=i.join("&"),i=""===i?"":"?"+i,"undefined"!=typeof n.keys){var a=2e3,u="keys="+encodeURIComponent(JSON.stringify(n.keys));u.length+i.length+1<=a?i+=("?"===i[0]?"&":"?")+u:(s="POST","string"==typeof t?o=JSON.stringify({keys:n.keys}):t.keys=n.keys)}if("string"==typeof t){var c=r(t);return e.request({method:s,url:"_design/"+c[0]+"/_view/"+c[1]+i,body:o})}return o=o||{},Object.keys(t).forEach(function(e){o[e]=Array.isArray(t[e])?t[e]:t[e].toString()}),e.request({method:"POST",url:"_temp_view"+i,body:o})}function h(e){return function(t){if(404===t.status)return e;throw t}}function p(e,t,n){var r="_local/doc_"+e;return t.db.get(r)["catch"](h({_id:r,keys:[]})).then(function(r){return I.resolve().then(function(){return r.keys.length?t.db.allDocs({keys:r.keys,include_docs:!0}):{rows:[]}}).then(function(t){var o=t.rows.map(function(e){return e.doc}).filter(function(e){return e}),i=n[e],s={};o.forEach(function(e){if(s[e._id]=!0,e._deleted=!i[e._id],!e._deleted){var t=i[e._id];"value"in t&&(e.value=t.value)}});var a=Object.keys(i);return a.forEach(function(e){if(!s[e]){var t={_id:e},n=i[e];"value"in n&&(t.value=n.value),o.push(t)}}),r.keys=O.uniq(a.concat(r.keys)),o.splice(0,0,r),o})})}function v(e,t,n){var r="_local/lastSeq";return e.db.get(r)["catch"](h({_id:r,seq:0})).then(function(r){var o=Object.keys(t);return I.all(o.map(function(n){return p(n,e,t)})).then(function(t){var o=[];return t.forEach(function(e){o=o.concat(e)}),r.seq=n,o.push(r),e.db.bulkDocs({docs:o})})})}function g(e,t,n){0===n.group_level&&delete n.group_level;var r,i=n.group||n.group_level;r=D[e.reduceFun]?D[e.reduceFun]:x(e.reduceFun.toString(),null,c,w,Array.isArray,JSON.parse);var a=[],u=n.group_level;t.forEach(function(e){var t=a[a.length-1],n=i?e.key:null;return i&&Array.isArray(n)&&"number"==typeof u&&(n=n.length>u?n.slice(0,u):n),t&&0===A(t.key[0][0],n)?(t.key.push([n,e.id]),void t.value.push(e.value)):void a.push({key:[[n,e.id]],value:[e.value]})});for(var f=0,l=a.length;l>f;f++){var d=a[f],h=o(e.sourceDB,r,[d.key,d.value,!1]);d.value=h.error?null:h.output,d.key=d.key[0][0]}return{rows:s(a,n.limit,n.skip)}}function m(e){return e.request({method:"POST",url:"_view_cleanup"})}function _(e,n,o){if("http"===e.type())return d(e,n,o);if("string"!=typeof n){l(o,n);var i={db:e,viewName:"temp_view/temp_view",map:n.map,reduce:n.reduce,temporary:!0};return L.add(function(){return k(i).then(function(e){function t(){return e.db.destroy()}return O.fin(N(e).then(function(){return j(e,o)}),t)})}),L.finish()}var s=n,a=r(s),u=a[0],c=a[1];return e.get("_design/"+u).then(function(n){var r=n.views&&n.views[c];if(!r||"string"!=typeof r.map)throw new b("ddoc "+u+" has no view named "+c);l(o,r);var i={db:e,viewName:s,map:r.map,reduce:r.reduce};return k(i).then(function(e){return"ok"===o.stale||"update_after"===o.stale?("update_after"===o.stale&&t.nextTick(function(){N(e)}),j(e,o)):N(e).then(function(){return j(e,o)})})})}function y(e){this.status=400,this.name="query_parse_error",this.message=e,this.error=!0;try{Error.captureStackTrace(this,y)}catch(t){}}function b(e){this.status=404,this.name="not_found",this.message=e,this.error=!0;try{Error.captureStackTrace(this,b)}catch(t){}}var w,E=e("pouchdb-collate"),S=e("./taskqueue"),A=E.collate,T=E.toIndexableString,R=E.normalizeKey,k=e("./create-view"),x=e("./evalfunc");w="undefined"!=typeof console&&"function"==typeof console.log?Function.prototype.bind.call(console.log,console):function(){};var O=e("./utils"),I=O.Promise,q=new S,L=new S,C=50,D={_sum:function(e,t){return c(t)},_count:function(e,t){return t.length},_stats:function(e,t){function n(e){for(var t=0,n=0,r=e.length;r>n;n++){var o=e[n];t+=o*o}return t}return{sum:c(t),min:Math.min.apply(null,t),max:Math.max.apply(null,t),count:t.length,sumsqr:n(t)}}},N=O.sequentialize(q,function(e){function t(e,t){var n={id:s._id,key:R(e)};"undefined"!=typeof t&&null!==t&&(n.value=R(t)),r.push(n)}function n(t,n){return function(){return v(e,t,n)}}var r,s,a;if("function"==typeof e.mapFun&&2===e.mapFun.length){var u=e.mapFun;a=function(e){return u(e,t)}}else a=x(e.mapFun.toString(),t,c,w,Array.isArray,JSON.parse);var f=e.seq||0,l=new S;return new I(function(t,u){function c(){l.finish().then(function(){e.seq=f,t()})}function d(){function t(e){u(e)}e.sourceDB.changes({conflicts:!0,include_docs:!0,since:f,limit:C}).on("complete",function(t){var u=t.results;if(!u.length)return c();for(var h={},p=0,v=u.length;v>p;p++){var g=u[p];if("_"!==g.doc._id[0]){r=[],s=g.doc,s._deleted||o(e.sourceDB,a,[s]),r.sort(i);for(var m,_={},y=0,b=r.length;b>y;y++){var w=r[y],E=[w.key,w.id];w.key===m&&E.push(y);var S=T(E);_[S]=w,m=w.key}h[g.doc._id]=_}f=g.seq}return l.add(n(h,f)),u.length<C?c():d()}).on("error",t)}d()})}),j=O.sequentialize(q,function(e,t){function n(t){return t.include_docs=!0,e.db.allDocs(t).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(!(n>t||t>n))return e.doc.value}var r=E.parseIndexableString(e.doc._id);return{key:r[0],id:r[1],value:"value"in e.doc?e.doc.value:null}})})}function r(n){var r;if(r=i?g(e,n,t):{total_rows:o,offset:s,rows:n},t.include_docs){var u=O.uniq(n.map(a));return e.sourceDB.allDocs({keys:u,include_docs:!0,conflicts:t.conflicts,attachments:t.attachments}).then(function(e){var t={};return e.rows.forEach(function(e){e.doc&&(t["$"+e.id]=e.doc)}),n.forEach(function(e){var n=a(e),r=t["$"+n];r&&(e.doc=r)}),r})}return r}var o,i=e.reduceFun&&t.reduce!==!1,s=t.skip||0;"undefined"==typeof t.keys||t.keys.length||(t.limit=0,delete t.keys);var u=function(e){return e.reduce(function(e,t){return e.concat(t)})};if("undefined"!=typeof t.keys){var c=t.keys,f=c.map(function(e){var t={startkey:T([e]),endkey:T([e,{}])};return n(t)});return I.all(f).then(u).then(r)}var l={descending:t.descending};if("undefined"!=typeof t.startkey&&(l.startkey=T(t.descending?[t.startkey,{}]:[t.startkey])),"undefined"!=typeof t.endkey){var d=t.inclusive_end!==!1;t.descending&&(d=!d),l.endkey=T(d?[t.endkey,{}]:[t.endkey])}if("undefined"!=typeof t.key){var h=T([t.key]),p=T([t.key,{}]);l.descending?(l.endkey=h,l.startkey=p):(l.startkey=h,l.endkey=p)}return i||("number"==typeof t.limit&&(l.limit=t.limit),l.skip=s),n(l).then(r)}),B=O.sequentialize(q,function(e){return e.get("_local/mrviews").then(function(t){var n={};Object.keys(t.views).forEach(function(e){var t=r(e),o="_design/"+t[0],i=t[1];n[o]=n[o]||{},n[o][i]=!0});var o={keys:Object.keys(n),include_docs:!0};return e.allDocs(o).then(function(r){var o={};r.rows.forEach(function(e){var r=e.key.substring(8);Object.keys(n[e.key]).forEach(function(n){var i=r+"/"+n;t.views[i]||(i=n);var s=Object.keys(t.views[i]),a=e.doc&&e.doc.views&&e.doc.views[n];s.forEach(function(e){o[e]=o[e]||a})})});var i=Object.keys(o).filter(function(e){return!o[e]}),s=i.map(function(t){return e.constructor.destroy(t,{adapter:e.adapter})});return I.all(s).then(function(){return{ok:!0}})})},h({ok:!0}))});n.viewCleanup=O.callbackify(function(){var e=this;return"http"===e.type()?m(e):B(e)}),n.query=function(e,t,n){"function"==typeof t&&(n=t,t={}),t=O.extend(!0,{},t),"function"==typeof e&&(e={map:e});var r=this,o=I.resolve().then(function(){return _(r,e,t)});return O.promisedCallback(o,n),o},O.inherits(y,Error),O.inherits(b,Error)}).call(this,e("_process"))},{"./create-view":66,"./evalfunc":67,"./taskqueue":69,"./utils":71,_process:40,"pouchdb-collate":63}],69:[function(e,t){"use strict";function n(){this.promise=new r(function(e){e()})}var r=e("./utils").Promise;n.prototype.add=function(e){return this.promise=this.promise["catch"](function(){}).then(function(){return e()}),this.promise},n.prototype.finish=function(){return this.promise},t.exports=n},{"./utils":71}],70:[function(e,t){"use strict";function n(e,t,n){return new o(function(o,i){return t&&"object"==typeof t&&(t=t._id),"string"!=typeof t?i(new Error("doc id is required")):void e.get(t,function(s,a){if(s)return 404!==s.status?i(s):o(r(e,n({_id:t}),n));var u=n(a);return u?void o(r(e,u,n)):o(a)})})}function r(e,t,r){return e.put(t)["catch"](function(o){if(409!==o.status)throw o;return n(e,t,r)})}var o=e("./utils").Promise;t.exports=n},{"./utils":71}],71:[function(e,t,n){(function(t,r){"use strict";n.Promise="function"==typeof r.Promise?r.Promise:e("lie"),n.inherits=e("inherits"),n.extend=e("pouchdb-extend");var o=e("argsarray");n.promisedCallback=function(e,n){return n&&e.then(function(e){t.nextTick(function(){n(null,e)})},function(e){t.nextTick(function(){n(e)})}),e},n.callbackify=function(e){return o(function(t){var r=t.pop(),o=e.apply(this,t);return"function"==typeof r&&n.promisedCallback(o,r),o})},n.fin=function(e,t){return e.then(function(e){var n=t();return"function"==typeof n.then?n.then(function(){return e}):e},function(e){var n=t();if("function"==typeof n.then)return n.then(function(){throw e});throw e})},n.sequentialize=function(e,t){return function(){var n=arguments,r=this;return e.add(function(){return t.apply(r,n)})}},n.uniq=function(e){for(var t={},n=0,r=e.length;r>n;n++)t["$"+e[n]]=!0;var o=Object.keys(t),i=new Array(o.length);for(n=0,r=o.length;r>n;n++)i[n]=o[n].substring(1);return i};var i=e("crypto"),s=e("spark-md5");n.MD5=function(e){return t.browser?s.hash(e):i.createHash("md5").update(e).digest("hex")}}).call(this,e("_process"),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{_process:40,argsarray:33,crypto:34,inherits:44,lie:48,"pouchdb-extend":65,"spark-md5":72}],72:[function(e,t,n){!function(e){if("object"==typeof n)t.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var r;try{r=window}catch(o){r=self}r.SparkMD5=e()}}(function(){"use strict";var e=function(e,t){return e+t&4294967295},t=function(t,n,r,o,i,s){return n=e(e(n,t),e(o,s)),e(n<<i|n>>>32-i,r)},n=function(e,n,r,o,i,s,a){return t(n&r|~n&o,e,n,i,s,a)},r=function(e,n,r,o,i,s,a){return t(n&o|r&~o,e,n,i,s,a)},o=function(e,n,r,o,i,s,a){return t(n^r^o,e,n,i,s,a)},i=function(e,n,r,o,i,s,a){return t(r^(n|~o),e,n,i,s,a)},s=function(t,s){var a=t[0],u=t[1],c=t[2],f=t[3];a=n(a,u,c,f,s[0],7,-680876936),f=n(f,a,u,c,s[1],12,-389564586),c=n(c,f,a,u,s[2],17,606105819),u=n(u,c,f,a,s[3],22,-1044525330),a=n(a,u,c,f,s[4],7,-176418897),f=n(f,a,u,c,s[5],12,1200080426),c=n(c,f,a,u,s[6],17,-1473231341),u=n(u,c,f,a,s[7],22,-45705983),a=n(a,u,c,f,s[8],7,1770035416),f=n(f,a,u,c,s[9],12,-1958414417),c=n(c,f,a,u,s[10],17,-42063),u=n(u,c,f,a,s[11],22,-1990404162),a=n(a,u,c,f,s[12],7,1804603682),f=n(f,a,u,c,s[13],12,-40341101),c=n(c,f,a,u,s[14],17,-1502002290),u=n(u,c,f,a,s[15],22,1236535329),a=r(a,u,c,f,s[1],5,-165796510),f=r(f,a,u,c,s[6],9,-1069501632),c=r(c,f,a,u,s[11],14,643717713),u=r(u,c,f,a,s[0],20,-373897302),a=r(a,u,c,f,s[5],5,-701558691),f=r(f,a,u,c,s[10],9,38016083),c=r(c,f,a,u,s[15],14,-660478335),u=r(u,c,f,a,s[4],20,-405537848),a=r(a,u,c,f,s[9],5,568446438),f=r(f,a,u,c,s[14],9,-1019803690),c=r(c,f,a,u,s[3],14,-187363961),u=r(u,c,f,a,s[8],20,1163531501),a=r(a,u,c,f,s[13],5,-1444681467),f=r(f,a,u,c,s[2],9,-51403784),c=r(c,f,a,u,s[7],14,1735328473),u=r(u,c,f,a,s[12],20,-1926607734),a=o(a,u,c,f,s[5],4,-378558),f=o(f,a,u,c,s[8],11,-2022574463),c=o(c,f,a,u,s[11],16,1839030562),u=o(u,c,f,a,s[14],23,-35309556),a=o(a,u,c,f,s[1],4,-1530992060),f=o(f,a,u,c,s[4],11,1272893353),c=o(c,f,a,u,s[7],16,-155497632),u=o(u,c,f,a,s[10],23,-1094730640),a=o(a,u,c,f,s[13],4,681279174),f=o(f,a,u,c,s[0],11,-358537222),c=o(c,f,a,u,s[3],16,-722521979),u=o(u,c,f,a,s[6],23,76029189),a=o(a,u,c,f,s[9],4,-640364487),f=o(f,a,u,c,s[12],11,-421815835),c=o(c,f,a,u,s[15],16,530742520),u=o(u,c,f,a,s[2],23,-995338651),a=i(a,u,c,f,s[0],6,-198630844),f=i(f,a,u,c,s[7],10,1126891415),c=i(c,f,a,u,s[14],15,-1416354905),u=i(u,c,f,a,s[5],21,-57434055),a=i(a,u,c,f,s[12],6,1700485571),f=i(f,a,u,c,s[3],10,-1894986606),c=i(c,f,a,u,s[10],15,-1051523),u=i(u,c,f,a,s[1],21,-2054922799),a=i(a,u,c,f,s[8],6,1873313359),f=i(f,a,u,c,s[15],10,-30611744),c=i(c,f,a,u,s[6],15,-1560198380),u=i(u,c,f,a,s[13],21,1309151649),a=i(a,u,c,f,s[4],6,-145523070),f=i(f,a,u,c,s[11],10,-1120210379),c=i(c,f,a,u,s[2],15,718787259),u=i(u,c,f,a,s[9],21,-343485551),t[0]=e(a,t[0]),t[1]=e(u,t[1]),t[2]=e(c,t[2]),t[3]=e(f,t[3])},a=function(e){var t,n=[];for(t=0;64>t;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},u=function(e){var t,n=[];for(t=0;64>t;t+=4)n[t>>2]=e[t]+(e[t+1]<<8)+(e[t+2]<<16)+(e[t+3]<<24);return n},c=function(e){var t,n,r,o,i,u,c=e.length,f=[1732584193,-271733879,-1732584194,271733878];for(t=64;c>=t;t+=64)s(f,a(e.substring(t-64,t)));for(e=e.substring(t-64),n=e.length,r=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],t=0;n>t;t+=1)r[t>>2]|=e.charCodeAt(t)<<(t%4<<3);if(r[t>>2]|=128<<(t%4<<3),t>55)for(s(f,r),t=0;16>t;t+=1)r[t]=0;return o=8*c,o=o.toString(16).match(/(.*?)(.{0,8})$/),i=parseInt(o[2],16),u=parseInt(o[1],16)||0,r[14]=i,r[15]=u,s(f,r),f},f=function(e){var t,n,r,o,i,a,c=e.length,f=[1732584193,-271733879,-1732584194,271733878];for(t=64;c>=t;t+=64)s(f,u(e.subarray(t-64,t)));for(e=c>t-64?e.subarray(t-64):new Uint8Array(0),n=e.length,r=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],t=0;n>t;t+=1)r[t>>2]|=e[t]<<(t%4<<3);if(r[t>>2]|=128<<(t%4<<3),t>55)for(s(f,r),t=0;16>t;t+=1)r[t]=0;return o=8*c,o=o.toString(16).match(/(.*?)(.{0,8})$/),i=parseInt(o[2],16),a=parseInt(o[1],16)||0,r[14]=i,r[15]=a,s(f,r),f},l=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"],d=function(e){var t,n="";for(t=0;4>t;t+=1)n+=l[e>>8*t+4&15]+l[e>>8*t&15];return n},h=function(e){var t;for(t=0;t<e.length;t+=1)e[t]=d(e[t]);return e.join("")},p=function(e){return h(c(e))},v=function(){this.reset()};return"5d41402abc4b2a76b9719d911017c592"!==p("hello")&&(e=function(e,t){var n=(65535&e)+(65535&t),r=(e>>16)+(t>>16)+(n>>16);return r<<16|65535&n}),v.prototype.append=function(e){return/[\u0080-\uFFFF]/.test(e)&&(e=unescape(encodeURIComponent(e))),this.appendBinary(e),this},v.prototype.appendBinary=function(e){this._buff+=e,this._length+=e.length;var t,n=this._buff.length;for(t=64;n>=t;t+=64)s(this._state,a(this._buff.substring(t-64,t)));return this._buff=this._buff.substr(t-64),this},v.prototype.end=function(e){var t,n,r=this._buff,o=r.length,i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(t=0;o>t;t+=1)i[t>>2]|=r.charCodeAt(t)<<(t%4<<3);return this._finish(i,o),n=e?this._state:h(this._state),this.reset(),n},v.prototype._finish=function(e,t){var n,r,o,i=t;if(e[i>>2]|=128<<(i%4<<3),i>55)for(s(this._state,e),i=0;16>i;i+=1)e[i]=0;n=8*this._length,n=n.toString(16).match(/(.*?)(.{0,8})$/),r=parseInt(n[2],16),o=parseInt(n[1],16)||0,e[14]=r,e[15]=o,s(this._state,e)},v.prototype.reset=function(){return this._buff="",this._length=0,this._state=[1732584193,-271733879,-1732584194,271733878],this},v.prototype.destroy=function(){delete this._state,delete this._buff,delete this._length},v.hash=function(e,t){/[\u0080-\uFFFF]/.test(e)&&(e=unescape(encodeURIComponent(e)));var n=c(e);return t?n:h(n)},v.hashBinary=function(e,t){var n=c(e);return t?n:h(n)},v.ArrayBuffer=function(){this.reset()},v.ArrayBuffer.prototype.append=function(e){var t,n=this._concatArrayBuffer(this._buff,e),r=n.length;for(this._length+=e.byteLength,t=64;r>=t;t+=64)s(this._state,u(n.subarray(t-64,t)));return this._buff=r>t-64?n.subarray(t-64):new Uint8Array(0),this},v.ArrayBuffer.prototype.end=function(e){var t,n,r=this._buff,o=r.length,i=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];for(t=0;o>t;t+=1)i[t>>2]|=r[t]<<(t%4<<3);return this._finish(i,o),n=e?this._state:h(this._state),this.reset(),n},v.ArrayBuffer.prototype._finish=v.prototype._finish,v.ArrayBuffer.prototype.reset=function(){return this._buff=new Uint8Array(0),this._length=0,this._state=[1732584193,-271733879,-1732584194,271733878],this},v.ArrayBuffer.prototype.destroy=v.prototype.destroy,v.ArrayBuffer.prototype._concatArrayBuffer=function(e,t){var n=e.length,r=new Uint8Array(n+t.byteLength);
return r.set(e),r.set(new Uint8Array(t),n),r},v.ArrayBuffer.hash=function(e,t){var n=f(new Uint8Array(e));return t?n:h(n)},v})},{}],73:[function(e,t,n){"use strict";function r(e,t,n){var r=n[n.length-1];e===r.element&&(n.pop(),r=n[n.length-1]);var o=r.element,i=r.index;if(Array.isArray(o))o.push(e);else if(i===t.length-2){var s=t.pop();o[s]=e}else t.push(e)}n.stringify=function(e){var t=[];t.push({obj:e});for(var n,r,o,i,s,a,u,c,f,l,d,h="";n=t.pop();)if(r=n.obj,o=n.prefix||"",i=n.val||"",h+=o,i)h+=i;else if("object"!=typeof r)h+="undefined"==typeof r?null:JSON.stringify(r);else if(null===r)h+="null";else if(Array.isArray(r)){for(t.push({val:"]"}),s=r.length-1;s>=0;s--)a=0===s?"":",",t.push({obj:r[s],prefix:a});t.push({val:"["})}else{u=[];for(c in r)r.hasOwnProperty(c)&&u.push(c);for(t.push({val:"}"}),s=u.length-1;s>=0;s--)f=u[s],l=r[f],d=s>0?",":"",d+=JSON.stringify(f)+":",t.push({obj:l,prefix:d});t.push({val:"{"})}return h},n.parse=function(e){for(var t,n,o,i,s,a,u,c,f,l=[],d=[],h=0;;)if(t=e[h++],"}"!==t&&"]"!==t&&"undefined"!=typeof t)switch(t){case" ":case" ":case"\n":case":":case",":break;case"n":h+=3,r(null,l,d);break;case"t":h+=3,r(!0,l,d);break;case"f":h+=4,r(!1,l,d);break;case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":case"-":for(n="",h--;;){if(o=e[h++],!/[\d\.\-e\+]/.test(o)){h--;break}n+=o}r(parseFloat(n),l,d);break;case'"':for(i="",s=void 0,a=0;;){if(u=e[h++],'"'===u&&("\\"!==s||a%2!==1))break;i+=u,s=u,"\\"===s?a++:a=0}r(JSON.parse('"'+i+'"'),l,d);break;case"[":c={element:[],index:l.length},l.push(c.element),d.push(c);break;case"{":f={element:{},index:l.length},l.push(f.element),d.push(f);break;default:throw new Error("unexpectedly reached end of input: "+t)}else{if(1===l.length)return l.pop();r(l.pop(),l,d)}}},{}],74:[function(e,t){(function(n){"use strict";var r=e("./setup");t.exports=r,r.ajax=e("./deps/ajax"),r.extend=e("pouchdb-extend"),r.utils=e("./utils"),r.Errors=e("./deps/errors"),r.replicate=e("./replicate").replicate,r.sync=e("./sync"),r.version=e("./version");var o=e("./adapters/http/http");if(r.adapter("http",o),r.adapter("https",o),r.adapter("idb",e("./adapters/idb/idb")),r.adapter("websql",e("./adapters/websql/websql")),r.plugin(e("pouchdb-mapreduce")),!n.browser){var i=e("./adapters/leveldb/leveldb");r.adapter("ldb",i),r.adapter("leveldb",i)}}).call(this,e("_process"))},{"./adapters/http/http":2,"./adapters/idb/idb":6,"./adapters/leveldb/leveldb":34,"./adapters/websql/websql":11,"./deps/ajax":15,"./deps/errors":18,"./replicate":27,"./setup":28,"./sync":29,"./utils":31,"./version":32,_process:40,"pouchdb-extend":65,"pouchdb-mapreduce":68}]},{},[74])(74)});