text: !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);throw new Error("Cannot find module '"+s+"'")}var c=n[s]={exports:{}};t[s][0].call(c.exports,function(e){var n=t[s][1][e];return o(n?n:e)},c,c.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(require,module,exports){"use strict";function arrayFirst(e,t){for(var n=0;n<e.length;n++)if(t(e[n],n)===!0)return e[n];return!1}function yankError(e){return function(t,n){t||n[0].error?e(t||n[0]):e(null,n[0])}}function computeHeight(e){var t={},n=[];return merge.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 AbstractPouchDB(){var e=this;EventEmitter.call(this),e.autoCompact=function(t){return e.auto_compaction?function(n,r){if(n)t(n);else{var o=r.length,i=function(){o--,o||t(null,r)};r.forEach(function(t){t.ok?e.compactDocument(t.id,1,i):i()})}}:t};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:"latest",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())})}function processChange(e,t,n){var r=[{rev:e._rev}];"all_docs"===n.style&&(r=merge.collectLeaves(t.rev_tree).map(function(e){return{rev:e.rev}}));var o={id:t.id,changes:r,doc:e};return utils.isDeleted(t,e._rev)&&(o.deleted=!0),n.conflicts&&(o.doc._conflicts=merge.collectConflicts(t),o.doc._conflicts.length||delete o.doc._conflicts),o}function doChanges(api,opts,promise){var callback=opts.complete;if(opts=utils.extend(!0,{},opts),"live"in opts&&!("continuous"in opts)&&(opts.continuous=opts.live),opts.processChange=processChange,opts.since||(opts.since=0),"latest"===opts.since)return void api.info(function(e,t){return promise.isCancelled?void callback(null,{status:"cancelled"}):e?void callback(e):(opts.since=t.update_seq-1,void doChanges(api,opts,promise,callback))});if("http"!==api.type()&&opts.filter&&"string"==typeof opts.filter)if("_view"===opts.filter){if(!opts.view||"string"!=typeof opts.view){var err=errors.error(errors.BAD_REQUEST,"`view` filter parameter is not provided.");return void callback(err)}var viewName=opts.view.split("/");api.get("_design/"+viewName[0],function(err,ddoc){if(promise.isCancelled)return void callback(null,{status:"cancelled"});if(err)return void callback(err);if(ddoc&&ddoc.views&&ddoc.views[viewName[1]]){var filter=eval("(function () {  return function (doc) {    var emitted = false;    var emit = function (a, b) {      emitted = true;    };    var view = "+ddoc.views[viewName[1]].map+";    view(doc);    if (emitted) {      return true;    }  }})()");return opts.filter=filter,void doChanges(api,opts,promise,callback)}var msg=ddoc.views?"missing json key: "+viewName[1]:"missing json key: views";return err=err||errors.error(errors.MISSING_DOC,msg),void callback(err)})}else{var filterName=opts.filter.split("/");api.get("_design/"+filterName[0],function(err,ddoc){if(promise.isCancelled)return void callback(null,{status:"cancelled"});if(err)return void callback(err);if(ddoc&&ddoc.filters&&ddoc.filters[filterName[1]]){var filter=eval("(function () { return "+ddoc.filters[filterName[1]]+" })()");return opts.filter=filter,void doChanges(api,opts,promise,callback)}var msg=ddoc&&ddoc.filters?"missing json key: "+filterName[1]:"missing json key: filters";return err=err||errors.error(errors.MISSING_DOC,msg),void callback(err)})}else{"descending"in opts||(opts.descending=!1),opts.limit=0===opts.limit?1:opts.limit,opts.complete=callback;var newPromise=api._changes(opts);if(newPromise&&"function"==typeof newPromise.cancel){var cancel=promise.cancel;promise.cancel=utils.getArguments(function(e){newPromise.cancel(),cancel.apply(this,e)})}}}var utils=require("./utils"),merge=require("./merge"),errors=require("./deps/errors"),EventEmitter=require("events").EventEmitter;utils.inherits(AbstractPouchDB,EventEmitter),module.exports=AbstractPouchDB,AbstractPouchDB.prototype.post=utils.adapterFun("post",function(e,t,n){return"function"==typeof t&&(n=t,t={}),"object"!=typeof e||Array.isArray(e)?n(errors.NOT_AN_OBJECT):this.bulkDocs({docs:[e]},t,this.autoCompact(yankError(n)))}),AbstractPouchDB.prototype.put=utils.adapterFun("put",utils.getArguments(function(e){var t,n,r,o,i=e.shift(),s="_id"in i;if("object"!=typeof i||Array.isArray(i))return(o=e.pop())(errors.NOT_AN_OBJECT);for(i=utils.extend(!0,{},i);;)if(t=e.shift(),n=typeof t,"string"!==n||s?"string"!==n||!s||"_rev"in i?"object"===n?r=t:"function"===n&&(o=t):i._rev=t:(i._id=t,s=!0),!e.length)break;r=r||{};var a=utils.invalidIdError(i._id);return a?o(a):this.bulkDocs({docs:[i]},r,this.autoCompact(yankError(o)))})),AbstractPouchDB.prototype.putAttachment=utils.adapterFun("putAttachment",function(e,t,n,r,o,i){function s(e){e._attachments=e._attachments||{},e._attachments[t]={content_type:o,data:r},a.put(e,i)}var a=this;"function"==typeof o&&(i=o,o=r,r=n,n=null),"undefined"==typeof o&&(o=r,r=n,n=null),a.get(e,function(t,r){return t&&t.error===errors.MISSING_DOC.error?void s({_id:e}):t?void i(t):r._rev!==n?void i(errors.REV_CONFLICT):void s(r)})}),AbstractPouchDB.prototype.removeAttachment=utils.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(errors.REV_CONFLICT):i._attachments?(delete i._attachments[t],0===Object.keys(i._attachments).length&&delete i._attachments,void o.put(i,r)):r()})}),AbstractPouchDB.prototype.remove=utils.adapterFun("remove",function(e,t,n){"function"==typeof t&&(n=t,t={}),void 0===t&&(t={}),t=utils.extend(!0,{},t),t.was_delete=!0;var r={_id:e._id,_rev:e._rev};return r._deleted=!0,this.bulkDocs({docs:[r]},t,yankError(n))}),AbstractPouchDB.prototype.revsDiff=utils.adapterFun("revsDiff",function(e,t,n){function r(e,t){a[e]||(a[e]={missing:[]}),a[e].missing.push(t)}function o(t,n){var o=e[t].slice(0);merge.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=utils.extend(!0,{},t);var i=Object.keys(e),s=0,a={};i.map(function(t){this._getRevisionTree(t,function(r,u){if(r&&"not_found"===r.name&&"missing"===r.message)a[t]={missing:e[t]};else{if(r)return n(r);o(t,u)}return++s===i.length?n(null,a):void 0})},this)}),AbstractPouchDB.prototype.compactDocument=function(e,t,n){var r=this;this._getRevisionTree(e,function(o,i){if(o)return n(o);var s=computeHeight(i),a=[],u=[];Object.keys(s).forEach(function(e){s[e]>t&&a.push(e)}),merge.traverseRevTree(i,function(e,t,n,r,o){var i=t+"-"+n;"available"===o.status&&-1!==a.indexOf(i)&&(o.status="missing",u.push(i))}),r._doCompaction(e,i,u,n)})},AbstractPouchDB.prototype.compact=utils.adapterFun("compact",function(e,t){"function"==typeof e&&(t=e,e={});var n=this;this.changes({complete:function(e,r){if(e)return void t();var o=r.results.length;return o?void r.results.forEach(function(e){n.compactDocument(e.id,0,function(){o--,o||t()})}):void t()}})}),AbstractPouchDB.prototype.get=utils.adapterFun("get",function(e,t,n){function r(){var r=[],s=o.length;return s?void o.forEach(function(o){i.get(e,{rev:o,revs:t.revs,attachments:t.attachments},function(e,t){r.push(e?{missing:o}:{ok:t}),s--,s||n(null,r)})}):n(null,r)}if("function"==typeof t&&(n=t,t={}),"string"!=typeof e)return n(errors.INVALID_ID);var o=[],i=this;if(!t.open_revs)return this._get(e,t,function(e,r){if(t=utils.extend(!0,{},t),e)return n(e);var o=r.doc,s=r.metadata,a=r.ctx;if(t.conflicts){var u=merge.collectConflicts(s);u.length&&(o._conflicts=u)}if(t.revs||t.revs_info){var c=merge.rootToLeaf(s.rev_tree),d=arrayFirst(c,function(e){return-1!==e.ids.map(function(e){return e.id}).indexOf(o._rev.split("-")[1])});if(d.ids.splice(d.ids.map(function(e){return e.id}).indexOf(o._rev.split("-")[1])+1),d.ids.reverse(),t.revs&&(o._revisions={start:d.pos+d.ids.length-1,ids:d.ids.map(function(e){return e.id})}),t.revs_info){var l=d.pos+d.ids.length;o._revs_info=d.ids.map(function(e){return l--,{rev:l+"-"+e.id,status:e.opts.status}})}}if(t.local_seq&&(o._local_seq=r.metadata.seq),t.attachments&&o._attachments){var f=o._attachments,p=Object.keys(f).length;if(0===p)return n(null,o);Object.keys(f).forEach(function(e){this._getAttachment(f[e],{encode:!0,ctx:a},function(t,r){o._attachments[e].data=r,--p||n(null,o)})},i)}else{if(o._attachments)for(var h in o._attachments)o._attachments.hasOwnProperty(h)&&(o._attachments[h].stub=!0);n(null,o)}});if("all"===t.open_revs)this._getRevisionTree(e,function(e,t){e&&(t=[]),o=merge.collectLeaves(t).map(function(e){return e.rev}),r()});else{if(!Array.isArray(t.open_revs))return n(errors.error(errors.UNKNOWN_ERROR,"function_clause"));o=t.open_revs;for(var s=0;s<o.length;s++){var a=o[s];if("string"!=typeof a||!/^\d+-/.test(a))return n(errors.error(errors.BAD_REQUEST,"Invalid rev format"))}r()}}),AbstractPouchDB.prototype.getAttachment=utils.adapterFun("getAttachment",function(e,t,n,r){var o=this;n instanceof Function&&(r=n,n={}),n=utils.extend(!0,{},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(errors.MISSING_DOC)})}),AbstractPouchDB.prototype.allDocs=utils.adapterFun("allDocs",function(e,t){if("function"==typeof e&&(t=e,e={}),e=utils.extend(!0,{},e),"keys"in e){var n=["startkey","endkey","key"].filter(function(t){return t in e})[0];if(n)return void t(errors.error(errors.QUERY_PARSE_ERROR,"Query parameter `"+n+"` is not compatible with multi-get"))}return"undefined"==typeof e.skip&&(e.skip=0),this._allDocs(e,t)}),AbstractPouchDB.prototype.changes=function(e){return utils.cancellableFun(doChanges,this,e)},AbstractPouchDB.prototype.close=utils.adapterFun("close",function(e){return this._close(e)}),AbstractPouchDB.prototype.info=utils.adapterFun("info",function(e){var t=this;this._info(function(n,r){if(n)return e(n);var o=t.prefix.length;r.db_name.length>o&&r.db_name.slice(0,o)===t.prefix&&(r.db_name=r.db_name.slice(o)),e(null,r)})}),AbstractPouchDB.prototype.id=utils.adapterFun("id",function(e){return this._id(e)}),AbstractPouchDB.prototype.type=function(){return"function"==typeof this._type?this._type():this.adapter},AbstractPouchDB.prototype.bulkDocs=utils.adapterFun("bulkDocs",function(e,t,n){if("function"==typeof t&&(n=t,t={}),t=t?utils.extend(!0,{},t):{},!e||!e.docs)return n(errors.MISSING_BULK_DOCS);if(!Array.isArray(e.docs))return n(errors.QUERY_PARSE_ERROR);for(var r=0;r<e.docs.length;++r)if("object"!=typeof e.docs[r]||Array.isArray(e.docs[r]))return n(errors.NOT_AN_OBJECT);return e=utils.extend(!0,{},e),"new_edits"in t||(t.new_edits="new_edits"in e?e.new_edits:!0),this._bulkDocs(e,t,this.autoCompact(n))})},{"./deps/errors":8,"./merge":14,"./utils":18,events:21}],2:[function(e,t){"use strict";function n(e){for(var t=n.options,r=t.parser[t.strictMode?"strict":"loose"].exec(e),o={},i=14;i--;)o[t.key[i]]=r[i]||"";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}function r(e){return/^_(design|local)/.test(e)?e:encodeURIComponent(e)}function o(e,t){if(/http(s?):/.test(e)){var r=n(e);r.remote=!0,(r.user||r.password)&&(r.auth={username:r.user,password:r.password});var o=r.path.replace(/(^\/|\/$)/g,"").split("/");if(r.db=o.pop(),r.path=o.join("/"),t=t||{},t=u.extend(!0,{},t),r.headers=t.headers||{},t.auth||r.auth){var i=t.auth||r.auth,s=u.btoa(i.username+":"+i.password);r.headers.Authorization="Basic "+s}return t.headers&&(r.headers=t.headers),r}return{host:"",path:"/",db:e,auth:!1}}function i(e,t){return s(e,e.db+"/"+t)}function s(e,t){if(e.remote){var n=e.path?"/":"";return e.protocol+"://"+e.host+":"+e.port+"/"+e.path+n+t}return"/"+t}function a(e,t){function n(e,t){return u.ajax(u.extend({},p,e),t)}function a(e,r,o,i){r=u.extend(!0,{},r);var a=d.getHost(i),c={source:l.db,target:a.protocol===l.protocol&&a.authority===l.authority?a.db:a.source};r.continuous&&(c.continuous=!0),r.create_target&&(c.create_target=!0),r.doc_ids&&(c.doc_ids=r.doc_ids),r.filter&&"string"==typeof r.filter&&(c.filter=r.filter),r.query_params&&(c.query_params=r.query_params);var f,p={},h={headers:l.headers,method:"POST",url:s(l,"_replicate"),body:c};o.cancel=function(){this.cancelled=!0,f&&!p.ok&&f.abort(),p._local_id&&(h.body={replication_id:p._local_id}),h.body.cancel=!0,n(h,function(e,n,o){return e?t(e):void u.call(r.complete,null,p,o)})},o.cancelled||(f=n(h,function(e,n,o){return e?t(e):(p.ok=!0,n._local_id&&(p._local_id=n._local_id),void u.call(r.complete,null,n,o))}))}var d=this;d.getHost=e.getHost?e.getHost:o;var l=d.getHost(e.name,e),f=i(l,"");d.getUrl=function(){return f};var p=e.ajax||{};e=u.extend(!0,{},e);var h={list:[],get:function(e,t){"function"==typeof e&&(t=e,e={count:10});var r=function(e,n){!e&&"uuids"in n?(h.list=h.list.concat(n.uuids),t(null,"OK")):t(e||c.UNKNOWN_ERROR)},o="?count="+e.count;n({headers:l.headers,method:"GET",url:s(l,"_uuids")+o},r)}},v=function(){n({headers:l.headers,method:"PUT",url:f},function(e){e&&401===e.status?n({headers:l.headers,method:"HEAD",url:f},function(e){e?t(e):t(null,d)}):e&&412!==e.status?t(e):t(null,d)})};e.skipSetup||n({headers:l.headers,method:"GET",url:f},function(e){e?404===e.status?v():t(e):t(null,d)}),d.type=function(){return"http"},d.id=u.adapterFun("id",function(e){n({headers:l.headers,method:"GET",url:s(l,"")},function(t,n){if(t)e(t);else{var r=n&&n.uuid?n.uuid+l.db:i(l,"");e(null,r)}})}),d.request=u.adapterFun("request",function(e,t){e.headers=l.headers,e.url=i(l,e.url),n(e,t)}),d.compact=u.adapterFun("compact",function(e,t){"function"==typeof e&&(t=e,e={}),e=u.extend(!0,{},e),n({headers:l.headers,url:i(l,"_compact"),method:"POST"},function(){function n(){d.info(function(r,o){o.compact_running?setTimeout(n,e.interval||200):t()})}"function"==typeof t&&n()})}),d._info=function(e){n({headers:l.headers,method:"GET",url:i(l,"")},function(t,n){t?e(t):(n.host=i(l,""),e(null,n))})},d.get=u.adapterFun("get",function(e,t,o){"function"==typeof t&&(o=t,t={}),t=u.extend(!0,{},t),void 0===t.auto_encode&&(t.auto_encode=!0);var s=[];t.revs&&s.push("revs=true"),t.revs_info&&s.push("revs_info=true"),t.local_seq&&s.push("local_seq=true"),t.open_revs&&("all"!==t.open_revs&&(t.open_revs=JSON.stringify(t.open_revs)),s.push("open_revs="+t.open_revs)),t.attachments&&s.push("attachments=true"),t.rev&&s.push("rev="+t.rev),t.conflicts&&s.push("conflicts="+t.conflicts),s=s.join("&"),s=""===s?"":"?"+s,t.auto_encode&&(e=r(e));var a={headers:l.headers,method:"GET",url:i(l,e+s)},c=e.split("/");(c.length>1&&"_design"!==c[0]&&"_local"!==c[0]||c.length>2&&"_design"===c[0]&&"_local"!==c[0])&&(a.binary=!0),n(a,function(e,t,n){return e?o(e):void o(null,t,n)})}),d.remove=u.adapterFun("remove",function(e,t,o){"function"==typeof t&&(o=t,t={}),n({headers:l.headers,method:"DELETE",url:i(l,r(e._id))+"?rev="+e._rev},o)}),d.getAttachment=u.adapterFun("getAttachment",function(e,t,n,o){"function"==typeof n&&(o=n,n={}),n=u.extend(!0,{},n),void 0===n.auto_encode&&(n.auto_encode=!0),n.auto_encode&&(e=r(e)),n.auto_encode=!1,d.get(e+"/"+t,n,o)}),d.removeAttachment=u.adapterFun("removeAttachment",function(e,t,o,s){n({headers:l.headers,method:"DELETE",url:i(l,r(e)+"/"+t)+"?rev="+o},s)}),d.putAttachment=u.adapterFun("putAttachment",function(e,t,o,s,a,u){"function"==typeof a&&(u=a,a=s,s=o,o=null),"undefined"==typeof a&&(a=s,s=o,o=null);var c=r(e)+"/"+t,d=i(l,c);o&&(d+="?rev="+o);var f={headers:l.headers,method:"PUT",url:d,processData:!1,body:s,timeout:6e4};f.headers["Content-Type"]=a,n(f,u)}),d.put=u.adapterFun("put",u.getArguments(function(e){var t,o,s,a,d=e.shift(),f="_id"in d;if("object"!=typeof d||Array.isArray(d))return(a=e.pop())(c.NOT_AN_OBJECT);for(d=u.extend(!0,{},d);;)if(t=e.shift(),o=typeof t,"string"!==o||f?"string"!==o||!f||"_rev"in d?"object"===o?s=u.extend(!0,{},t):"function"===o&&(a=t):d._rev=t:(d._id=t,f=!0),!e.length)break;s=s||{};var p=u.invalidIdError(d._id);if(p)return a(p);var h=[];s&&"undefined"!=typeof s.new_edits&&h.push("new_edits="+s.new_edits),h=h.join("&"),""!==h&&(h="?"+h),n({headers:l.headers,method:"PUT",url:i(l,r(d._id))+h,body:d},a)})),d.post=u.adapterFun("post",function(e,t,n){return"function"==typeof t&&(n=t,t={}),t=u.extend(!0,{},t),"object"!=typeof e?n(c.NOT_AN_OBJECT):void("_id"in e?d.put(e,t,n):h.list.length>0?(e._id=h.list.pop(),d.put(e,t,n)):h.get(function(r){return r?n(c.UNKNOWN_ERROR):(e._id=h.list.pop(),void d.put(e,t,n))}))}),d.bulkDocs=u.adapterFun("bulkDocs",function(e,t,r){if("function"==typeof t&&(r=t,t={}),t||(t={}),!Array.isArray(e.docs))return r(c.error(c.NOT_AN_OBJECT,"Missing JSON list of 'docs'"));var o=e.docs.filter(function(e){return"object"!=typeof e||Array.isArray(e)});return o.length?r(c.NOT_AN_OBJECT):(e=u.extend(!0,{},e),t=u.extend(!0,{},t),"undefined"!=typeof t.new_edits&&(e.new_edits=t.new_edits),void n({headers:l.headers,method:"POST",url:i(l,"_bulk_docs"),body:e},r))}),d.allDocs=u.adapterFun("allDocs",function(e,t){"function"==typeof e&&(t=e,e={}),e=u.extend(!0,{},e);var r,o=[],s="GET";if(e.conflicts&&o.push("conflicts=true"),e.descending&&o.push("descending=true"),e.include_docs&&o.push("include_docs=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.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 a=2e3,c="keys="+encodeURIComponent(JSON.stringify(e.keys));c.length+o.length+1<=a?o+=(-1!==o.indexOf("?")?"&":"?")+c:(s="POST",r=JSON.stringify({keys:e.keys}))}n({headers:l.headers,method:s,url:i(l,"_all_docs"+o),body:r},t)}),d._changes=function(e){var t=25;e=u.extend(!0,{},e),e.timeout=e.timeout||0;var r={timeout:2e4},o="undefined"!=typeof e.limit?e.limit:!1;0===o&&(o=1);var s=o;if(e.style&&(r.style=e.style),(e.include_docs||e.filter&&"function"==typeof e.filter)&&(r.include_docs=!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 a in e.query_params)e.query_params.hasOwnProperty(a)&&(r[a]=e.query_params[a]);var d,f,p=function(a,u){if(!e.aborted){r.since=a,e.descending?o&&(r.limit=s):r.limit=!o||s>t?t:s;var c="?"+Object.keys(r).map(function(e){return e+"="+r[e]}).join("&"),p={headers:l.headers,method:"GET",url:i(l,"_changes"+c),timeout:e.timeout};f=a,e.aborted||(d=n(p,u))}},h=10,v=0,m={results:[]},_=function(n,r){if(!e.aborted){var i=0;if(r&&r.results){i=r.results.length,m.last_seq=r.last_seq;var a={};a.query=e.query_params,r.results=r.results.filter(function(t){s--;var n=u.filterChange(e)(t);return n&&(m.results.push(t),u.call(e.onChange,t)),n})}else if(n)return e.aborted=!0,void u.call(e.complete,n);r&&r.last_seq&&(f=r.last_seq);var d=o&&0>=s||r&&t>i||e.descending;if(e.continuous||!d){n?v+=1:v=0;var l=1<<v,y=h*l,g=e.maximumWait||3e4;if(y>g)return void u.call(e.complete,n||c.UNKNOWN_ERROR);setTimeout(function(){p(f,_)},y)}else u.call(e.complete,null,m)}};return p(e.since||0,_),{cancel:function(){e.aborted=!0,d.abort()}}},d.revsDiff=u.adapterFun("revsDif",function(e,t,r){"function"==typeof t&&(r=t,t={}),n({headers:l.headers,method:"POST",url:i(l,"_revs_diff"),body:e},function(e,t){r(e,t)})}),d.close=u.adapterFun("close",function(e){e()}),d.replicateOnServer=function(e,t,n){return d.taskqueue.isReady?void e.info(function(r,o){a(e,t,n,o.host)}):(d.taskqueue.addTask("replicateOnServer",[e,t,n]),n)},d.destroy=u.adapterFun("destroy",function(e){n({url:i(l,""),method:"DELETE",headers:l.headers},function(t,n){t?(d.emit("error",t),e(t)):(d.emit("destroyed"),e(null,n))})})}var u=e("../utils"),c=e("../deps/errors");n.options={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*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/}},a.destroy=u.toPromise(function(e,t,n){var r=o(e,t);t=t||{},"function"==typeof t&&(n=t,t={}),t=u.extend(!0,{},t),t.headers=r.headers,t.method="DELETE",t.url=i(r,"");var s=t.ajax||{};t=u.extend({},t,s),u.ajax(t,n)}),a.valid=function(){return!0},t.exports=a},{"../deps/errors":8,"../utils":18}],3:[function(e,t){(function(n){"use strict";function r(e){return function(t){e(u.error(u.IDB_ERROR,t.target,t.type))}}function o(){var e="_pouch__checkModernIdb_"+(n.navigator&&n.navigator.appVersion),t=s.hasLocalStorage()&&n.localStorage[e];if(t)return JSON.parse(t);var r="_pouch__checkModernIdb",o=null===n.indexedDB.open(r,1).onupgradeneeded;return n.indexedDB.deleteDatabase&&n.indexedDB.deleteDatabase(r),s.hasLocalStorage()&&(n.localStorage[e]=JSON.stringify(o)),o}function i(e,t){function o(e){e.createObjectStore(h,{keyPath:"id"}).createIndex("seq","seq",{unique:!0}),e.createObjectStore(v,{autoIncrement:!0}).createIndex("_doc_id_rev","_doc_id_rev",{unique:!0}),e.createObjectStore(m,{keyPath:"digest"}),e.createObjectStore(_,{keyPath:"id",autoIncrement:!1}),e.createObjectStore(y)}function c(e){var t=e.currentTarget.transaction.objectStore(h);t.openCursor().onsuccess=function(e){var n=e.target.result;if(n){var r=n.value,o=s.isDeleted(r),i=s.isLocalId(r.id);r.deletedOrLocal=o||i?"1":"0",t.put(r),n["continue"]()}else t.createIndex("deletedOrLocal","deletedOrLocal",{unique:!1})}}function d(e,t){return e._bulk_seq-t._bulk_seq}function l(e,t,n){var r=t.keys,o="descending"in t?t.descending:!1;if(r.length){var i=[];r.forEach(function(a){var u=s.extend(!0,{},t);u.keys_request=!0,u.key=a,delete u.keys,delete u.skip,delete u.limit,f(e,u,function(s,u){if(i.push({err:s,res:u,key:a}),i.length===r.length){for(var c={},d=0;d<i.length;d++){var l=i[d];if(l.err)return void n(s);c[l.key]=l}var f=[];r.forEach(function(e){var t=c[e];f.push(t.res.rows.length?t.res.rows[0]:{key:e,error:"not_found"})}),o&&(f=f.reverse()),n(null,{total_rows:e,offset:t.skip,rows:"limit"in t?f.slice(t.skip,t.limit+t.skip):t.skip>0?f.slice(t.skip):f})}})})}else n(null,{offset:t.skip,rows:[],total_rows:e})}function f(e,t,r){var o="startkey"in t?t.startkey:!1,i="endkey"in t?t.endkey:!1,c="key"in t?t.key:!1,d=t.skip||0,l="number"==typeof t.limit?t.limit:-1,f="descending"in t&&t.descending?"prev":null,p=!1;f&&o&&i&&(p=i,i=!1);var m;try{m=o&&i?n.IDBKeyRange.bound(o,i):o?f?n.IDBKeyRange.upperBound(o):n.IDBKeyRange.lowerBound(o):i?f?n.IDBKeyRange.lowerBound(i):n.IDBKeyRange.upperBound(i):c?n.IDBKeyRange.only(c):null}catch(_){return"DataError"===_.name&&0===_.code?r(null,{total_rows:e,offset:t.skip,rows:[]}):r(u.error(u.IDB_ERROR,_.name,_.message))}var y=k.transaction([h,v],"readonly");y.oncomplete=function(){r(null,{total_rows:e,offset:t.skip,rows:w})};var g=y.objectStore(h),b=f?g.openCursor(m,f):g.openCursor(m),w=[];b.onsuccess=function(e){function n(e,n){if(s.isLocalId(e.id))return r["continue"]();var o={id:e.id,key:e.id,value:{rev:a.winningRev(e)}};if(t.include_docs){o.doc=n,o.doc._rev=a.winningRev(e),o.doc._doc_id_rev&&delete o.doc._doc_id_rev,t.conflicts&&(o.doc._conflicts=a.collectConflicts(e));for(var i in o.doc._attachments)o.doc._attachments.hasOwnProperty(i)&&(o.doc._attachments[i].stub=!0)}if(t.keys_request)s.isDeleted(e)&&(o.value.deleted=!0,o.doc=null),w.push(o);else if(!s.isDeleted(e)&&d--<=0){if(p&&o.key<p)return;if(w.push(o),0===--l)return}r["continue"]()}if(e.target.result){var r=e.target.result,o=r.value;if(t.include_docs){var i=y.objectStore(v).index("_doc_id_rev"),u=a.winningRev(o),c=o.id+"::"+u;i.get(c).onsuccess=function(e){n(r.value,e.target.result)}}else n(o)}}}var p=2,h="document-store",v="by-sequence",m="attach-store",_="meta-store",y="detect-blob-support",g=e.name,b=n.indexedDB.open(g,p);"openReqList"in i||(i.openReqList={}),i.openReqList[g]=b;var w=null,E=null,S=this,k=null;b.onupgradeneeded=function(e){var t=e.target.result;e.oldVersion<1&&o(t),e.oldVersion<2&&c(e)},b.onsuccess=function(e){k=e.target.result,k.onversionchange=function(){k.close()};var n=k.transaction([_,y],"readwrite"),r=n.objectStore(_).get(_);r.onsuccess=function(e){var r=!1,o=function(){null!==w&&r&&t(null,S)},i=e.target.result||{id:_};g+"_id"in i?(E=i[g+"_id"],r=!0,o()):(E=s.uuid(),i[g+"_id"]=E,n.objectStore(_).put(i).onsuccess=function(){r=!0,o()});try{n.objectStore(y).put(s.createBlob(),"key"),w=!0}catch(a){w=!1}finally{o()}}},b.onerror=r(t),S.type=function(){return"idb"},S._id=s.toPromise(function(e){e(null,E)}),S._bulkDocs=function(e,t,n){function o(e){var t=e.target.result;t.updateSeq=(t.updateSeq||0)+A,N.objectStore(_).put(t)}function c(){if(!T.length)return void(N.objectStore(_).get(_).onsuccess=o);var e=T.shift(),t=N.objectStore(h).get(e.metadata.id);t.onsuccess=function(t){var n=t.target.result;n?b(n,e):E(e)}}function l(){var e=[];j.sort(d),j.forEach(function(t){if(delete t._bulk_seq,t.error)return void e.push(t);var n=t.metadata,r=a.winningRev(n);e.push({ok:!0,id:n.id,rev:r}),s.isLocalId(n.id)||(i.Changes.notify(g),i.Changes.notifyLocalWindows(g))}),n(null,e)}function f(e,t){if(e.stub)return t();if("string"==typeof e.data){var r;try{r=atob(e.data)}catch(o){var i=u.error(u.BAD_ARG,"Attachments need to be base64 encoded");return n(i)}if(e.digest="md5-"+s.Crypto.MD5(r),w){var a=e.content_type;r=s.fixBinary(r),e.data=s.createBlob([r],{type:a})}return t()}var c=new FileReader;c.onloadend=function(){var n=s.arrayBufferToBinaryString(this.result);e.digest="md5-"+s.Crypto.MD5(n),w||(e.data=btoa(n)),t()},c.readAsArrayBuffer(e.data)}function p(e){function t(){n++,T.length===n&&e()}if(!T.length)return e();var n=0;T.forEach(function(e){function n(){o++,o===r.length&&t()}var r=e.data&&e.data._attachments?Object.keys(e.data._attachments):[];if(!r.length)return t();var o=0;for(var i in e.data._attachments)e.data._attachments.hasOwnProperty(i)&&f(e.data._attachments[i],n)})}function y(e,t){function n(e){i||(e?(i=e,t(i)):a===u.length&&o())}function r(e){a++,n(e)}function o(){e.data._doc_id_rev=e.data._id+"::"+e.data._rev;var n=N.objectStore(v).index("_doc_id_rev");n.getKey(e.data._doc_id_rev).onsuccess=function(n){var r=n.target.result?N.objectStore(v).put(e.data,n.target.result):N.objectStore(v).put(e.data);r.onsuccess=function(n){e.metadata.seq=n.target.result,delete e.metadata.rev;var r=s.isDeleted(e.metadata),o=s.isLocalId(e.metadata.id),i=s.extend(!0,{deletedOrLocal:r||o?"1":"0"},e.metadata),a=N.objectStore(h).put(i);a.onsuccess=function(){j.push(e),s.call(t)}}}}var i=null,a=0;e.data._id=e.metadata.id,e.data._rev=e.metadata.rev,A++,s.isDeleted(e.metadata,e.metadata.rev)&&(e.data._deleted=!0);var u=e.data._attachments?Object.keys(e.data._attachments):[];for(var c in e.data._attachments)if(e.data._attachments[c].stub)a++,n();else{var d=e.data._attachments[c].data;delete e.data._attachments[c].data;var l=e.data._attachments[c].digest;x(e,l,d,r)}u.length||o()}function b(e,t){var n=a.merge(e.rev_tree,t.metadata.rev_tree[0],1e3),r=s.isDeleted(e),o=r&&s.isDeleted(t.metadata)||!r&&q&&"new_leaf"!==n.conflicts;return o?(j.push(S(u.REV_CONFLICT,t._bulk_seq)),c()):(t.metadata.rev_tree=n.tree,void y(t,c))}function E(e){return"was_delete"in t&&s.isDeleted(e.metadata)?(j.push(u.MISSING_DOC),c()):void y(e,c)}function S(e,t){return e._bulk_seq=t,e}function x(e,t,n,r){var o=N.objectStore(m);o.get(t).onsuccess=function(i){var a=i.target.result&&i.target.result.refs||{},u=[e.metadata.id,e.metadata.rev].join("@"),c={digest:t,body:n,refs:a};c.refs[u]=!0,o.put(c).onsuccess=function(){s.call(r)}}}var q=t.new_edits,O=e.docs,T=O.map(function(e,t){var n=s.parseDoc(e,q);return n._bulk_seq=t,n}),R=T.filter(function(e){return e.error});if(R.length)return n(R[0]);var N,j=[],A=0;p(function(){N=k.transaction([h,v,m,_],"readwrite"),N.onerror=r(n),N.ontimeout=r(n),N.oncomplete=l,c()})},S._get=function(e,t,n){function r(){n(c,{doc:o,metadata:i,ctx:d})}var o,i,c,d;t=s.extend(!0,{},t),d=t.ctx?t.ctx:k.transaction([h,v,m],"readonly"),d.objectStore(h).get(e).onsuccess=function(e){if(i=e.target.result,!i)return c=u.MISSING_DOC,r();if(s.isDeleted(i)&&!t.rev)return c=u.error(u.MISSING_DOC,"deleted"),r();var n=a.winningRev(i),l=i.id+"::"+(t.rev?t.rev:n),f=d.objectStore(v).index("_doc_id_rev");f.get(l).onsuccess=function(e){return o=e.target.result,o&&o._doc_id_rev&&delete o._doc_id_rev,o?void r():(c=u.MISSING_DOC,r())}}},S._getAttachment=function(e,t,n){var r,o;t=s.extend(!0,{},t),o=t.ctx?t.ctx:k.transaction([h,v,m],"readonly");var i=e.digest,a=e.content_type;o.objectStore(m).get(i).onsuccess=function(e){var o=e.target.result.body;if(t.encode)if(w){var i=new FileReader;i.onloadend=function(){var e=s.arrayBufferToBinaryString(this.result);r=btoa(e),n(null,r)},i.readAsArrayBuffer(o)}else r=o,n(null,r);else w?r=o:(o=s.fixBinary(atob(o)),r=s.createBlob([o],{type:a})),n(null,r)}},S._allDocs=function(e,t){function o(e){i=e.target.result}var i,s=k.transaction([h],"readonly"),a=s.objectStore(h).index("deletedOrLocal");a.count(n.IDBKeyRange.only("0")).onsuccess=o,s.onerror=r(t),s.oncomplete=function(){return 0===e.limit?t(null,{total_rows:i,offset:e.skip,rows:[]}):void("keys"in e?l(i,e,t):f(i,e,t))}},S._info=function(e){function t(e){o=e.target.result&&e.target.result.updateSeq||0}function n(e){var n=e.target.result;return n?(n.value.deleted!==!0&&r++,void n["continue"]()):void(i.objectStore(_).get(_).onsuccess=t)}var r=0,o=0,i=k.transaction([h,_],"readonly");i.oncomplete=function(){e(null,{db_name:g,doc_count:r,update_seq:o})},i.objectStore(h).openCursor().onsuccess=n},S._changes=function(e){function t(){l=k.transaction([h,v]),l.oncomplete=o;var t;t=c?l.objectStore(v).openCursor(n.IDBKeyRange.lowerBound(e.since,!0),c):l.objectStore(v).openCursor(n.IDBKeyRange.lowerBound(e.since,!0)),t.onsuccess=r,t.onerror=onerror}function r(t){if(!t.target.result){for(var n=0,r=f.length;r>n;n++){var o=f[n];o&&m.push(o)}return!1}var i=t.target.result,u=i.value._id,c=p[u];if(void 0!==c)return f[c].seq=i.key,f.push(f[c]),f[c]=null,p[u]=f.length-1,i["continue"]();var _=l.objectStore(h);_.get(i.value._id).onsuccess=function(t){var n=t.target.result;if(s.isLocalId(n.id))return i["continue"]();d<n.seq&&(d=n.seq);var r=a.winningRev(n),o=n.id+"::"+r,u=l.objectStore(v).index("_doc_id_rev");u.get(o).onsuccess=function(t){var o=t.target.result;delete o._doc_id_rev,o._rev=r;var s=e.processChange(o,n,e);s.seq=i.key;var a=s.id,u=p[a];void 0!==u&&(f[u]=null),f.push(s),p[a]=f.length-1,i["continue"]()}}}function o(){s.processChanges(e,m,d)}if(e=s.extend(!0,{},e),e.continuous){var u=g+":"+s.uuid();return i.Changes.addListener(g,u,S,e),i.Changes.notify(g),{cancel:function(){i.Changes.removeListener(g,u)}}}var c=e.descending?"prev":null,d=0;e.since=e.since&&!c?e.since:0;var l,f=[],p={},m=[];t()},S._close=function(e){return null===k?e(u.NOT_OPEN):(k.close(),void e())},S._getRevisionTree=function(e,t){var n=k.transaction([h],"readonly"),r=n.objectStore(h).get(e);r.onsuccess=function(e){var n=e.target.result;n?t(null,n.rev_tree):t(u.MISSING_DOC)}},S._doCompaction=function(e,t,n,r){var o=k.transaction([h,v],"readwrite"),i=o.objectStore(h);i.get(e).onsuccess=function(r){var i=r.target.result;i.rev_tree=t;var a=n.length;n.forEach(function(t){var n=o.objectStore(v).index("_doc_id_rev"),r=e+"::"+t;
  n.getKey(r).onsuccess=function(e){var t=e.target.result;if(t&&(o.objectStore(v)["delete"](t),a--,!a)){if(i){var n=s.isDeleted(i),r=s.isLocalId(i.id);i=s.extend(!0,{deletedOrLocal:n||r?"1":"0"},i)}o.objectStore(h).put(i)}}})},o.oncomplete=function(){s.call(r)}}}var s=e("../utils"),a=e("../merge"),u=e("../deps/errors");i.valid=function(){return n.indexedDB&&o()},i.destroy=s.toPromise(function(e,t,o){"openReqList"in i||(i.openReqList={}),i.Changes.clearListeners(e),i.openReqList[e]&&i.openReqList[e].result&&i.openReqList[e].result.close();var s=n.indexedDB.deleteDatabase(e);s.onsuccess=function(){i.openReqList[e]&&(i.openReqList[e]=null),o()},s.onerror=r(o)}),i.Changes=new s.Changes,t.exports=i}).call(this,"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../deps/errors":8,"../merge":14,"../utils":18}],4:[function(e,t){(function(n){"use strict";function r(e){return"'"+e+"'"}function o(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 i(e){return decodeURIComponent(window.escape(e))}function s(e,t){for(var n="",r="UTF-8"===t?2:4,o=0,s=e.length;s>o;o+=r){var a=e.substring(o,o+r);4===r&&(a=a.substring(2,4)+a.substring(0,2)),n+=String.fromCharCode(parseInt(a,16))}return n="UTF-8"===t?i(n):n}function a(e,t){function r(){u.hasLocalStorage()&&(n.localStorage["_pouch__websqldb_"+R]=!0),t(null,O)}function i(e){e.executeSql(E),e.executeSql("ALTER TABLE "+_+" ADD COLUMN deleted TINYINT(1) DEFAULT 0",[],function(){e.executeSql(b),e.executeSql("ALTER TABLE "+m+" ADD COLUMN local TINYINT(1) DEFAULT 0",[],function(){e.executeSql(w);var t="SELECT "+m+".winningseq AS seq, "+m+".json AS metadata FROM "+_+" JOIN "+m+" ON "+_+".seq = "+m+".winningseq";e.executeSql(t,[],function(e,t){for(var n=[],r=[],o=0;o<t.rows.length;o++){var i=t.rows.item(o),s=i.seq,a=JSON.parse(i.metadata);u.isDeleted(a)&&n.push(s),u.isLocalId(a.id)&&r.push(a.id)}e.executeSql("UPDATE "+m+"SET local = 1 WHERE id IN ("+r.map(function(){return"?"}).join(",")+")",r),e.executeSql("UPDATE "+_+" SET deleted = 1 WHERE seq IN ("+n.map(function(){return"?"}).join(",")+")",n)})})})}function l(e){for(;N.length>0;){var t=N.pop();t(null,T)}S(e)}function S(e){e.executeSql("SELECT dbid, hex(dbid) AS hexId FROM "+g,[],function(e,t){var n=t.rows.item(0).dbid,r=t.rows.item(0).hexId;q=r.length===2*n.length?"UTF-8":"UTF-16"})}function k(e,t){if(0===t){var n="CREATE TABLE IF NOT EXISTS "+g+" (update_seq, dbid, db_version INTEGER)",r="CREATE TABLE IF NOT EXISTS "+y+" (digest, json, body BLOB)",o="CREATE TABLE IF NOT EXISTS "+m+" (id unique, seq, json, winningseq, local TINYINT(1))",s="CREATE TABLE IF NOT EXISTS "+_+" (seq INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, doc_id_rev UNIQUE, json, deleted TINYINT(1))";e.executeSql(r),e.executeSql(o,[],function(){e.executeSql(E),e.executeSql(w)}),e.executeSql(s,[],function(){e.executeSql(b)}),e.executeSql(n,[],function(){var t="INSERT INTO "+g+" (update_seq, db_version, dbid) VALUES (?, ?, ?)";T=u.uuid(),e.executeSql(t,[0,v,T]),l(e)})}else 1===t&&(i(e),e.executeSql("UPDATE "+g+" SET db_version = "+v)),e.executeSql("SELECT dbid FROM "+g,[],function(e,t){T=t.rows.item(0).dbid,l(e)})}function x(){j.transaction(function(e){e.executeSql("SELECT sql FROM sqlite_master WHERE tbl_name = "+g,[],function(e,t){t.rows.length?/db_version/.test(t.rows.item(0).sql)?e.executeSql("SELECT db_version FROM "+g,[],function(e,t){var n=t.rows.item(0).db_version;k(e,n)}):e.executeSql("ALTER TABLE "+g+" ADD COLUMN db_version INTEGER",[],function(){k(e,1)}):k(e,0)})},o(t),r)}var q,O=this,T=null,R=e.name,N=[],j=f(R,p,R,h);return j?(u.isCordova()&&"undefined"!=typeof n?n.addEventListener(R+"_pouch",function A(){n.removeEventListener(R+"_pouch",A,!1),x()},!1):x(),O.type=function(){return"websql"},O._id=u.toPromise(function(e){e(null,T)}),O._info=function(e){j.transaction(function(t){var n="SELECT COUNT(id) AS count FROM "+m;t.executeSql(n,[],function(t,n){var r=n.rows.item(0).count,o="SELECT update_seq FROM "+g;t.executeSql(o,[],function(t,n){var o=n.rows.item(0).update_seq;e(null,{db_name:R,doc_count:r,update_seq:o})})})})},O._bulkDocs=function(e,t,n){function r(e,t){return e._bulk_seq-t._bulk_seq}function i(){var e=[];D.sort(r),D.forEach(function(t){if(delete t._bulk_seq,t.error)return void e.push(t);var n=t.metadata,r=c.winningRev(n);e.push({ok:!0,id:n.id,rev:r}),u.isLocalId(n.id)||(O++,a.Changes.notify(R),a.Changes.notifyLocalWindows(R))});var t="SELECT update_seq FROM "+g;A.executeSql(t,[],function(t,r){var o=r.rows.item(0).update_seq+O,i="UPDATE "+g+" SET update_seq=?";t.executeSql(i,[o],function(){n(null,e)})})}function l(e,t){if(e.stub)return t();if("string"==typeof e.data){try{e.data=atob(e.data)}catch(r){var o=d.error(d.BAD_ARG,"Attachments need to be base64 encoded");return n(o)}var i=u.fixBinary(e.data);e.data=u.createBlob([i],{type:e.content_type})}var s=new FileReader;s.onloadend=function(){var n=u.arrayBufferToBinaryString(this.result);e.data=n,e.digest="md5-"+u.Crypto.MD5(n),t()},s.readAsArrayBuffer(e.data)}function f(e){function t(){n++,T.length===n&&e()}if(!T.length)return e();var n=0;T.forEach(function(e){function n(){o++,o===r.length&&t()}var r=e.data&&e.data._attachments?Object.keys(e.data._attachments):[],o=0;if(!r.length)return t();for(var i in e.data._attachments)e.data._attachments.hasOwnProperty(i)&&l(e.data._attachments[i],n)})}function p(e,t,n){function r(){var t=e.data,n=t._id+"::"+t._rev,r=u.isDeleted(e.metadata,e.metadata.rev)?1:0,o="SELECT * FROM "+_+" WHERE doc_id_rev=?;";A.executeSql(o,[n],function(e,o){var i,a;o.rows.length?(i="UPDATE "+_+" SET json=?, deleted=? WHERE doc_id_rev=?;",a=[JSON.stringify(t),r,n],A.executeSql(i,a,function(e){s(e,o.rows.item(0).seq)})):(i="INSERT INTO "+_+" (doc_id_rev, json, deleted) VALUES (?, ?, ?);",a=[n,JSON.stringify(t),r],A.executeSql(i,a,function(e,t){s(e,t.insertId)}))})}function o(e){a||(e?(a=e,t(a)):d===l.length&&r())}function i(e){d++,o(e)}function s(r,o){e.metadata.seq=o,delete e.metadata.rev;var i=c.winningRev(e.metadata),s=n?"UPDATE "+m+" SET seq=?, json=?, winningseq=(SELECT seq FROM "+_+" WHERE doc_id_rev=?) WHERE id=?":"INSERT INTO "+m+" (id, seq, winningseq, json, local) VALUES (?, ?, ?, ?, ?);",a=JSON.stringify(e.metadata),d=e.metadata.id+"::"+i,l=u.isLocalId(e.metadata.id)?1:0,f=n?[o,a,d,e.metadata.id]:[e.metadata.id,o,o,a,l];r.executeSql(s,f,function(){D.push(e),t()})}var a=null,d=0;e.data._id=e.metadata.id,e.data._rev=e.metadata.rev,u.isDeleted(e.metadata,e.metadata.rev)&&(e.data._deleted=!0);var l=e.data._attachments?Object.keys(e.data._attachments):[];for(var f in e.data._attachments)if(e.data._attachments[f].stub)d++,o();else{var p=e.data._attachments[f].data;delete e.data._attachments[f].data;var h=e.data._attachments[f].digest;E(e,h,p,i)}l.length||r()}function h(e,t){var n=c.merge(e.rev_tree,t.metadata.rev_tree[0],1e3),r=u.isDeleted(e)&&u.isDeleted(t.metadata)||!u.isDeleted(e)&&k&&"new_leaf"!==n.conflicts;return r?(D.push(w(d.REV_CONFLICT,t._bulk_seq)),b()):(t.metadata.rev_tree=n.tree,void p(t,b,!0))}function v(e){return"was_delete"in t&&u.isDeleted(e.metadata)?(D.push(d.MISSING_DOC),b()):void p(e,b,!1)}function b(){if(!T.length)return i();var e=T.shift(),t=e.metadata.id;t in C?h(C[t],e):(C[t]=e.metadata,v(e))}function w(e,t){return e._bulk_seq=t,e}function E(e,t,n,r){var o=[e.metadata.id,e.metadata.rev].join("@"),i={digest:t},s="SELECT digest, json FROM "+y+" WHERE digest=?";A.executeSql(s,[t],function(e,a){a.rows.length?(i.refs=JSON.parse(a.rows.item(0).json).refs,s="UPDATE "+y+" SET json=?, body=? WHERE digest=?",e.executeSql(s,[JSON.stringify(i),n,t],function(){r()})):(i.refs={},i.refs[o]=!0,s="INSERT INTO "+y+"(digest, json, body) VALUES (?, ?, ?)",e.executeSql(s,[t,JSON.stringify(i),n],function(){r()}))})}function S(e,t){for(var n=0;n<t.rows.length;n++){var r=t.rows.item(n),o=s(r.hexId,q);C[o]=JSON.parse(r.json)}b()}var k=t.new_edits,x=e.docs,O=0,T=x.map(function(e,t){var n=u.parseDoc(e,k);return n._bulk_seq=t,n}),N=T.filter(function(e){return e.error});if(N.length)return n(N[0]);var A,D=[],C={};f(function(){j.transaction(function(e){A=e;var t="SELECT hex(id) AS hexId, json FROM "+m+" WHERE id IN ("+T.map(function(){return"?"}).join(",")+")",n=T.map(function(e){return e.metadata.id});A.executeSql(t,n,S)},o(n))})},O._get=function(e,t,n){function r(){n(s,{doc:o,metadata:i,ctx:a})}t=u.extend(!0,{},t);var o,i,s;if(!t.ctx)return void j.transaction(function(r){t.ctx=r,O._get(e,t,n)});var a=t.ctx,l="SELECT * FROM "+m+" WHERE id=?";a.executeSql(l,[e],function(e,n){if(!n.rows.length)return s=d.MISSING_DOC,r();if(i=JSON.parse(n.rows.item(0).json),u.isDeleted(i)&&!t.rev)return s=d.error(d.MISSING_DOC,"deleted"),r();var l=c.winningRev(i),f=t.rev?t.rev:l;f=i.id+"::"+f;var p="SELECT * FROM "+_+" WHERE doc_id_rev=?";a.executeSql(p,[f],function(e,t){return t.rows.length?(o=JSON.parse(t.rows.item(0).json),void r()):(s=d.MISSING_DOC,r())})})},O._allDocs=function(e,t){var n,r=[],i={},s=_+" JOIN "+m+" ON "+_+".seq = "+m+".winningseq",a="startkey"in e?e.startkey:!1,d="endkey"in e?e.endkey:!1,l="key"in e?e.key:!1,f="descending"in e?e.descending:!1,p="keys"in e?e.keys:!1,h="limit"in e?e.limit:!1,v="skip"in e?e.skip:!1,y=[],g=[m+".local = 0"];l!==!1?(g.push(m+".id = ?"),y.push(l)):p!==!1?(g.push(m+".id in ("+p.map(function(){return"?"}).join(",")+")"),y=y.concat(p)):(a!==!1||d!==!1)&&(a!==!1&&(g.push(m+".id "+(f?"<=":">=")+" ?"),y.push(a)),d!==!1&&(g.push(m+".id "+(f?">=":"<=")+" ?"),y.push(d)),l!==!1&&(g.push(m+".id = ?"),y.push(l))),p===!1&&g.push(_+".deleted = 0"),j.transaction(function(t){var o="SELECT COUNT("+m+".id) AS 'num' FROM "+s+" WHERE "+_+".deleted = 0 AND "+m+".local = 0";t.executeSql(o,[],function(t,o){if(n=o.rows.item(0).num,0!==h){var a="SELECT "+m+".id, "+_+".seq, "+_+".json AS data, "+m+".json AS metadata FROM "+s;g.length&&(a+=" WHERE "+g.join(" AND ")),a+=" ORDER BY "+m+".id "+(f?"DESC":"ASC"),h!==!1&&(a+=" LIMIT "+h),v!==!1&&v>0&&(h===!1&&(a+=" LIMIT -1"),a+=" OFFSET "+v),t.executeSql(a,y,function(t,n){for(var o=0,s=n.rows.length;s>o;o++){var a=n.rows.item(o),d=JSON.parse(a.metadata),l=JSON.parse(a.data);if(a={id:d.id,key:d.id,value:{rev:c.winningRev(d)}},e.include_docs){a.doc=l,a.doc._rev=c.winningRev(d),e.conflicts&&(a.doc._conflicts=c.collectConflicts(d));for(var f in a.doc._attachments)a.doc._attachments.hasOwnProperty(f)&&(a.doc._attachments[f].stub=!0)}"keys"in e?e.keys.indexOf(d.id)>-1&&(u.isDeleted(d)&&(a.value.deleted=!0,a.doc=null),i[a.id]=a):r.push(a)}})}})},o(t),function(){0!==h&&"keys"in e&&(e.keys.forEach(function(e){r.push(e in i?i[e]:{key:e,error:"not_found"})}),e.descending&&r.reverse()),t(null,{total_rows:n,offset:e.skip,rows:r})})},O._changes=function(e){function t(){var t="SELECT "+m+".id, "+_+".seq, "+_+".json AS data, "+m+".json AS metadata FROM "+_+" JOIN "+m+" ON "+_+".seq = "+m+".winningseq WHERE "+m+".seq > "+e.since+" ORDER BY "+m+".seq "+(r?"DESC":"ASC");j.transaction(function(n){n.executeSql(t,[],function(t,n){for(var r=0,i=0,s=n.rows.length;s>i;i++){var a=n.rows.item(i),c=JSON.parse(a.metadata);if(!u.isLocalId(c.id)){r<a.seq&&(r=a.seq);var d=JSON.parse(a.data),l=e.processChange(d,c,e);l.seq=a.seq,o.push(l)}}u.processChanges(e,o,r)})})}if(e=u.extend(!0,{},e),e.continuous){var n=R+":"+u.uuid();return a.Changes.addListener(R,n,O,e),a.Changes.notify(R),{cancel:function(){a.Changes.removeListener(R,n)}}}var r=e.descending;e.since=e.since&&!r?e.since:0;var o=[];t()},O._close=function(e){e()},O._getAttachment=function(e,t,n){var r,o=t.ctx,i=e.digest,a=e.content_type,c="SELECT hex(body) as body FROM "+y+" WHERE digest=?";o.executeSql(c,[i],function(e,o){var i=s(o.rows.item(0).body,q);t.encode?r=btoa(i):(i=u.fixBinary(i),r=u.createBlob([i],{type:a})),n(null,r)})},O._getRevisionTree=function(e,t){j.transaction(function(n){var r="SELECT json AS metadata FROM "+m+" WHERE id = ?";n.executeSql(r,[e],function(e,n){if(n.rows.length){var r=JSON.parse(n.rows.item(0).metadata);t(null,r.rev_tree)}else t(d.MISSING_DOC)})})},void(O._doCompaction=function(e,t,n,r){j.transaction(function(o){var i="SELECT json AS metadata FROM "+m+" WHERE id = ?";o.executeSql(i,[e],function(o,i){if(!i.rows.length)return u.call(r);var s=JSON.parse(i.rows.item(0).metadata);s.rev_tree=t;var a="DELETE FROM "+_+" WHERE doc_id_rev IN ("+n.map(function(){return"?"}).join(",")+")",c=n.map(function(t){return e+"::"+t});o.executeSql(a,[c],function(t){var n="UPDATE "+m+" SET json = ? WHERE id = ?";t.executeSql(n,[JSON.stringify(s),e],function(){r()})})})})})):t(d.UNKNOWN_ERROR)}var u=e("../utils"),c=e("../merge"),d=e("../deps/errors"),l={},f=u.getArguments(function(e){if("undefined"!=typeof n){if(n.navigator&&n.navigator.sqlitePlugin&&n.navigator.sqlitePlugin.openDatabase)return navigator.sqlitePlugin.openDatabase.apply(navigator.sqlitePlugin,e);if(n.sqlitePlugin&&n.sqlitePlugin.openDatabase)return n.sqlitePlugin.openDatabase.apply(n.sqlitePlugin,e);var t=l[e[0]];return t||(t=l[e[0]]=n.openDatabase.apply(n,e)),t}}),p=1,h=5242880,v=2,m=r("document-store"),_=r("by-sequence"),y=r("attach-store"),g=r("metadata-store"),b="CREATE INDEX IF NOT EXISTS 'by-seq-deleted-idx' ON "+_+" (seq, deleted)",w="CREATE INDEX IF NOT EXISTS 'doc-store-local-idx' ON "+m+" (local, id)",E="CREATE INDEX IF NOT EXISTS 'doc-winningseq-idx' ON "+m+" (winningseq)";a.valid=function(){if("undefined"!=typeof n){if(n.navigator&&n.navigator.sqlitePlugin&&n.navigator.sqlitePlugin.openDatabase)return!0;if(n.sqlitePlugin&&n.sqlitePlugin.openDatabase)return!0;if(n.openDatabase)return!0}return!1},a.destroy=u.toPromise(function(e,t,r){var i=f(e,p,e,h);i.transaction(function(e){e.executeSql("DROP TABLE IF EXISTS "+m,[]),e.executeSql("DROP TABLE IF EXISTS "+_,[]),e.executeSql("DROP TABLE IF EXISTS "+y,[]),e.executeSql("DROP TABLE IF EXISTS "+g,[])},o(r),function(){u.hasLocalStorage()&&delete n.localStorage["_pouch__websqldb_"+e],r()})}),a.Changes=new u.Changes,t.exports=a}).call(this,"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"../deps/errors":8,"../merge":14,"../utils":18}],5:[function(e,t){(function(n){"use strict";function r(e){e&&n.debug&&console.error(e)}function o(e,t,n){if(!(this instanceof o))return new o(e,t,n);var c=this;("function"==typeof t||"undefined"==typeof t)&&(n=t,t={}),"object"==typeof e&&(t=e,e=void 0),"undefined"==typeof n&&(n=r),t=t||{};var d=n;c.auto_compaction=t.auto_compaction,c.prefix=o.prefix,s.call(c),c.taskqueue=new u;var l=new i(function(r,i){n=function(e,t){return e?i(e):(delete t.then,void r(t))},t=a.extend(!0,{},t);var s,u,d=t.name||e;return function(){try{if("string"!=typeof d)throw u=new Error("Missing/invalid DB name"),u.code=400,u;if(s=o.parseAdapter(d,t),t.originalName=d,t.name=s.name,t.adapter=t.adapter||s.adapter,!o.adapters[t.adapter])throw u=new Error("Adapter is missing"),u.code=404,u;if(!o.adapters[t.adapter].valid())throw u=new Error("Invalid Adapter"),u.code=404,u}catch(e){c.taskqueue.fail(e),c.changes=a.toPromise(function(t){t.complete&&t.complete(e)})}}(),u?i(u):(c.adapter=t.adapter,c.replicate=function(e,t,n){return a.cancellableFun(function(r,i,s){var a=o.replicate(e,t,n);s.cancel=a.cancel},c,n)},c.replicate.from=function(e,t,n){return"function"==typeof t&&(n=t,t={}),o.replicate(e,c,t,n)},c.replicate.to=function(e,t,n){return"function"==typeof t&&(n=t,t={}),o.replicate(c,e,t,n)},c.replicate.sync=function(e,t,n){return"function"==typeof t&&(n=t,t={}),a.cancellableFun(function(r,i,s){var a=o.sync(c,e,t,n);s.cancel=a.cancel},c,t)},c.destroy=a.adapterFun("destroy",function(e){var t=this;t.info(function(t,n){return t?e(t):void o.destroy(n.db_name,e)})}),o.adapters[t.adapter].call(c,t,function(e){function r(e){"destroyed"===e&&(c.emit("destroyed"),o.removeListener(t.name,r))}return e?void(n&&(c.taskqueue.fail(e),n(e))):(o.on(t.name,r),c.emit("created",c),o.emit("created",t.originalName),c.taskqueue.ready(c),void n(null,c))}),t.skipSetup&&c.taskqueue.ready(c),void(a.isCordova()&&cordova.fireWindowEvent(t.name+"_pouch",{})))});l.then(function(e){d(null,e)},d),c.then=l.then.bind(l),function(){try{c["catch"]=l["catch"].bind(l)}catch(e){}}()}var i="function"==typeof n.Promise?n.Promise:e("bluebird"),s=e("./adapter"),a=e("./utils"),u=e("./taskqueue");a.inherits(o,s),t.exports=o}).call(this,"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./adapter":1,"./taskqueue":17,"./utils":18,bluebird:27}],6:[function(e,t){(function(n){"use strict";function r(e,t){function r(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){var t;return e.ok?e:e.error&&"conflict"===e.error?(t=a.REV_CONFLICT,t.id=e.id,t):e.error&&"forbidden"===e.error?(t=a.FORBIDDEN,t.id=e.id,t.reason=e.reason,t):e.missing?(t=a.MISSING_DOC,t.missing=e.missing,t):e})),r(null,t,n)}function d(e,t){var n,r,o,i;try{n=JSON.parse(e.responseText);for(i in a)if(a.hasOwnProperty(i)&&a[i].name===n.error){o=a[i];break}o||(o=a.UNKNOWN_ERROR,e.status&&(o.status=e.status),e.statusText&&(e.name=e.statusText)),r=a.error(o,n.reason)}catch(s){for(var i in a)if(a.hasOwnProperty(i)&&a[i].status===e.status){o=a[i];break}o||(o=a.UNKNOWN_ERROR,e.status&&(o.status=e.status),e.statusText&&(e.name=e.statusText)),r=a.error(o)}t(r)}var l=!1,f=c.getArguments(function(e){l||(t.apply(this,e),l=!0)});"function"==typeof e&&(f=e,e={}),e=i(!0,{},e);var p={method:"GET",headers:{},json:!0,processData:!0,timeout:1e4,cache:!1};if(e=i(!0,p,e),"GET"===e.method&&!e.cache){var h=-1!==e.url.indexOf("?");e.url+=(h?"&":"?")+"_nonce="+u(16)}if(n.browser){var v,m;m=e.xhr?new e.xhr:new XMLHttpRequest,m.open(e.method,e.url),m.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&&(m.responseType="arraybuffer");var _=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 y in e.headers)if("Cookie"===y){var g=e.headers[y].split("=");_(g[0],g[1],10)}else m.setRequestHeader(y,e.headers[y]);"body"in e||(e.body=null);var b=function(){l||(m.abort(),d(m,f))};return m.onreadystatechange=function(){if(4===m.readyState&&!l)if(clearTimeout(v),m.status>=200&&m.status<300){var t;t=e.binary?s([m.response||""],{type:m.getResponseHeader("Content-Type")}):m.responseText,r(t,m,f)}else d(m,f)},e.timeout>0&&(v=setTimeout(b,e.timeout),m.onprogress=function(){clearTimeout(v),v=setTimeout(b,e.timeout)},m.upload&&(m.upload.onprogress=m.onprogress)),m.send(e.body),{abort:b}}return e.json&&(e.binary||(e.headers.Accept="application/json"),e.headers["Content-Type"]=e.headers["Content-Type"]||"application/json"),e.binary&&(e.encoding=null,e.json=!1),e.processData||(e.json=!1),o(e,function(t,n,o){if(t)return t.status=n?n.statusCode:400,d(t,f);var i,s=n.headers["content-type"],u=o||"";e.binary||!e.json&&e.processData||"object"==typeof u||!(/json/.test(s)||/^[\s]*\{/.test(u)&&/\}[\s]*$/.test(u))||(u=JSON.parse(u)),n.statusCode>=200&&n.statusCode<300?r(u,n,f):(e.binary&&(u=JSON.parse(u.toString())),i="missing"===u.reason?a.MISSING_DOC:"no_db_file"===u.reason?a.error(a.DB_MISSING,u.reason):"conflict"===u.error?a.REV_CONFLICT:a.error(a.UNKNOWN_ERROR,u.reason,u.error),i.status=n.statusCode,f(i))})}var o=e("request"),i=e("./extend.js"),s=e("./blob.js"),a=e("./errors"),u=e("../deps/uuid"),c=e("../utils");t.exports=r}).call(this,e("/Users/cmetcalf/pouchdb/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"))},{"../deps/uuid":12,"../utils":18,"./blob.js":7,"./errors":8,"./extend.js":10,"/Users/cmetcalf/pouchdb/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":22,request:20}],7:[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 self?self:"undefined"!=typeof window?window:{})},{}],8:[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 so cannot close"}),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.error=function(e,t,n){function r(){this.message=t,n&&(this.name=n)}return r.prototype=e,new r(t)}},{}],9:[function(){"use strict";Object.keys||(Object.keys=function(e){if("object"!=typeof e&&"function"!=typeof e||null===e)throw new TypeError("Object.keys called on a non-object");var t=[];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.push(n);return t}),Array.isArray||(Array.isArray=function(e){return"[object Array]"===Object.prototype.toString.call(e)}),"forEach"in Array.prototype||(Array.prototype.forEach=function(e,t){for(var n=0,r=this.length;r>n;n++)n in this&&e.call(t,this[n],n,this)}),"map"in Array.prototype||(Array.prototype.map=function(e,t){for(var n=new Array(this.length),r=0,o=this.length;o>r;r++)r in this&&(n[r]=e.call(t,this[r],r,this));return n})},{}],10:[function(e,t){"use strict";function n(e){return null===e?String(e):"object"==typeof e||"function"==typeof e?a[l.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&&!f.call(e,"constructor")&&!f.call(e.constructor.prototype,"isPrototypeOf"))return!1}catch(t){return!1}var o;for(o in e);return void 0===o||f.call(e,o)}function i(e){return"function"===n(e)}function s(){var e,t,n,r,a,u,c=arguments[0]||{},d=1,l=arguments.length,f=!1;for("boolean"==typeof c&&(f=c,c=arguments[1]||{},d=2),"object"==typeof c||i(c)||(c={}),l===d&&(c=this,--d);l>d;d++)if(null!=(e=arguments[d]))for(t in e)if(!(t in Object.prototype)){if(n=c[t],r=e[t],c===r)continue;f&&r&&(o(r)||(a=p(r)))?(a?(a=!1,u=n&&p(n)?n:[]):u=n&&o(n)?n:{},c[t]=s(f,u,r)):void 0!==r&&(p(e)&&i(r)||(c[t]=r))}return c}for(var a={},u=["Boolean","Number","String","Function","Array","Date","RegExp","Object","Error"],c=0;c<u.length;c++){var d=u[c];a["[object "+d+"]"]=d.toLowerCase()}var l=a.toString,f=a.hasOwnProperty,p=Array.isArray||function(e){return"array"===n(e)};t.exports=s},{}],11:[function(e,t,n){(function(t){"use strict";var r=e("crypto");n.MD5=function(e){function n(e,t){return e<<t|e>>>32-t}function o(e,t){var n,r,o,i,s;return o=2147483648&e,i=2147483648&t,n=1073741824&e,r=1073741824&t,s=(1073741823&e)+(1073741823&t),n&r?2147483648^s^o^i:n|r?1073741824&s?3221225472^s^o^i:1073741824^s^o^i:s^o^i}function i(e,t,n){return e&t|~e&n}function s(e,t,n){return e&n|t&~n}function a(e,t,n){return e^t^n}function u(e,t,n){return t^(e|~n)}function c(e,t,r,s,a,u,c){return e=o(e,o(o(i(t,r,s),a),c)),o(n(e,u),t)}function d(e,t,r,i,a,u,c){return e=o(e,o(o(s(t,r,i),a),c)),o(n(e,u),t)}function l(e,t,r,i,s,u,c){return e=o(e,o(o(a(t,r,i),s),c)),o(n(e,u),t)}function f(e,t,r,i,s,a,c){return e=o(e,o(o(u(t,r,i),s),c)),o(n(e,a),t)}function p(e){for(var t,n=e.length,r=n+8,o=(r-r%64)/64,i=16*(o+1),s=new Array(i-1),a=0,u=0;n>u;)t=(u-u%4)/4,a=u%4*8,s[t]=s[t]|e.charCodeAt(u)<<a,u++;return t=(u-u%4)/4,a=u%4*8,s[t]=s[t]|128<<a,s[i-2]=n<<3,s[i-1]=n>>>29,s}function h(e){var t,n,r="",o="";for(n=0;3>=n;n++)t=e>>>8*n&255,o="0"+t.toString(16),r+=o.substr(o.length-2,2);return r}if(!t.browser)return r.createHash("md5").update(e).digest("hex");var v,m,_,y,g,b,w,E,S,k=[],x=7,q=12,O=17,T=22,R=5,N=9,j=14,A=20,D=4,C=11,I=16,L=23,B=6,P=10,F=15,M=21;for(k=p(e),b=1732584193,w=4023233417,E=2562383102,S=271733878,v=0;v<k.length;v+=16)m=b,_=w,y=E,g=S,b=c(b,w,E,S,k[v+0],x,3614090360),S=c(S,b,w,E,k[v+1],q,3905402710),E=c(E,S,b,w,k[v+2],O,606105819),w=c(w,E,S,b,k[v+3],T,3250441966),b=c(b,w,E,S,k[v+4],x,4118548399),S=c(S,b,w,E,k[v+5],q,1200080426),E=c(E,S,b,w,k[v+6],O,2821735955),w=c(w,E,S,b,k[v+7],T,4249261313),b=c(b,w,E,S,k[v+8],x,1770035416),S=c(S,b,w,E,k[v+9],q,2336552879),E=c(E,S,b,w,k[v+10],O,4294925233),w=c(w,E,S,b,k[v+11],T,2304563134),b=c(b,w,E,S,k[v+12],x,1804603682),S=c(S,b,w,E,k[v+13],q,4254626195),E=c(E,S,b,w,k[v+14],O,2792965006),w=c(w,E,S,b,k[v+15],T,1236535329),b=d(b,w,E,S,k[v+1],R,4129170786),S=d(S,b,w,E,k[v+6],N,3225465664),E=d(E,S,b,w,k[v+11],j,643717713),w=d(w,E,S,b,k[v+0],A,3921069994),b=d(b,w,E,S,k[v+5],R,3593408605),S=d(S,b,w,E,k[v+10],N,38016083),E=d(E,S,b,w,k[v+15],j,3634488961),w=d(w,E,S,b,k[v+4],A,3889429448),b=d(b,w,E,S,k[v+9],R,568446438),S=d(S,b,w,E,k[v+14],N,3275163606),E=d(E,S,b,w,k[v+3],j,4107603335),w=d(w,E,S,b,k[v+8],A,1163531501),b=d(b,w,E,S,k[v+13],R,2850285829),S=d(S,b,w,E,k[v+2],N,4243563512),E=d(E,S,b,w,k[v+7],j,1735328473),w=d(w,E,S,b,k[v+12],A,2368359562),b=l(b,w,E,S,k[v+5],D,4294588738),S=l(S,b,w,E,k[v+8],C,2272392833),E=l(E,S,b,w,k[v+11],I,1839030562),w=l(w,E,S,b,k[v+14],L,4259657740),b=l(b,w,E,S,k[v+1],D,2763975236),S=l(S,b,w,E,k[v+4],C,1272893353),E=l(E,S,b,w,k[v+7],I,4139469664),w=l(w,E,S,b,k[v+10],L,3200236656),b=l(b,w,E,S,k[v+13],D,681279174),S=l(S,b,w,E,k[v+0],C,3936430074),E=l(E,S,b,w,k[v+3],I,3572445317),w=l(w,E,S,b,k[v+6],L,76029189),b=l(b,w,E,S,k[v+9],D,3654602809),S=l(S,b,w,E,k[v+12],C,3873151461),E=l(E,S,b,w,k[v+15],I,530742520),w=l(w,E,S,b,k[v+2],L,3299628645),b=f(b,w,E,S,k[v+0],B,4096336452),S=f(S,b,w,E,k[v+7],P,1126891415),E=f(E,S,b,w,k[v+14],F,2878612391),w=f(w,E,S,b,k[v+5],M,4237533241),b=f(b,w,E,S,k[v+12],B,1700485571),S=f(S,b,w,E,k[v+3],P,2399980690),E=f(E,S,b,w,k[v+10],F,4293915773),w=f(w,E,S,b,k[v+1],M,2240044497),b=f(b,w,E,S,k[v+8],B,1873313359),S=f(S,b,w,E,k[v+15],P,4264355552),E=f(E,S,b,w,k[v+6],F,2734768916),w=f(w,E,S,b,k[v+13],M,1309151649),b=f(b,w,E,S,k[v+4],B,4149444226),S=f(S,b,w,E,k[v+11],P,3174756917),E=f(E,S,b,w,k[v+2],F,718787259),w=f(w,E,S,b,k[v+9],M,3951481745),b=o(b,m),w=o(w,_),E=o(E,y),S=o(S,g);var U=h(b)+h(w)+h(E)+h(S);return U.toLowerCase()}}).call(this,e("/Users/cmetcalf/pouchdb/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"))},{"/Users/cmetcalf/pouchdb/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":22,crypto:20}],12:[function(e,t){"use strict";function n(e,t){var r,o=n.CHARS,i=[];if(t=t||o.length,e)for(r=0;e>r;r++)i[r]=o[0|Math.random()*t];else{var s;for(i[8]=i[13]=i[18]=i[23]="-",i[14]="4",r=0;36>r;r++)i[r]||(s=0|16*Math.random(),i[r]=o[19===r?3&s|8:s])}return i.join("")}n.CHARS="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split(""),t.exports=n},{}],13:[function(e,t){(function(n){"use strict";e("./deps/es5_shims");var r=e("./setup");t.exports=r,r.ajax=e("./deps/ajax"),r.extend=e("./deps/extend"),r.utils=e("./utils"),r.Errors=e("./deps/errors");var o=e("./replicate");r.replicate=o.replicate,r.sync=o.sync,r.version=e("./version");var i=e("./adapters/http");if(r.adapter("http",i),r.adapter("https",i),r.adapter("idb",e("./adapters/idb")),r.adapter("websql",e("./adapters/websql")),r.plugin(e("pouchdb-mapreduce")),!n.browser){var s=e("./adapters/leveldb");r.adapter("ldb",s),r.adapter("leveldb",s)}}).call(this,e("/Users/cmetcalf/pouchdb/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"))},{"./adapters/http":2,"./adapters/idb":3,"./adapters/leveldb":20,"./adapters/websql":4,"./deps/ajax":6,"./deps/errors":8,"./deps/es5_shims":9,"./deps/extend":10,"./replicate":15,"./setup":16,"./utils":18,"./version":19,"/Users/cmetcalf/pouchdb/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":22,"pouchdb-mapreduce":42}],14:[function(e,t){"use strict";function n(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 r(e,t){for(var n=[{tree1:e,tree2:t}],r=!1;n.length>0;){var o=n.pop(),i=o.tree1,s=o.tree2;(i[1].status||s[1].status)&&(i[1].status="available"===i[1].status||"available"===s[1].status?"available":"missing");for(var a=0;a<s[2].length;a++)if(i[2][0]){for(var u=!1,c=0;c<i[2].length;c++)i[2][c][0]===s[2][a][0]&&(n.push({tree1:i[2][c],tree2:s[2][a]}),u=!0);u||(r="new_branch",i[2].push(s[2][a]),i[2].sort())}else r="new_leaf",i[2][0]=s[2][a]}return{conflicts:r,tree:e}}function o(e,t,n){var o,i=[],s=!1,a=!1;return e.length?(e.forEach(function(e){if(e.pos===t.pos&&e.ids[0]===t.ids[0])o=r(e.ids,t.ids),i.push({pos:e.pos,ids:o.tree}),s=s||o.conflicts,a=!0;else if(n!==!0){var u=e.pos<t.pos?e:t,c=e.pos<t.pos?t:e,d=c.pos-u.pos,l=[],f=[];for(f.push({ids:u.ids,diff:d,parent:null,parentIdx:null});f.length>0;){var p=f.pop();0!==p.diff?p.ids&&p.ids[2].forEach(function(e,t){f.push({ids:e,diff:p.diff-1,parent:p.ids,parentIdx:t})}):p.ids[0]===c.ids[0]&&l.push(p)}var h=l[0];h?(o=r(h.ids,c.ids),h.parent[2][h.parentIdx]=o.tree,i.push({pos:u.pos,ids:u.ids}),s=s||o.conflicts,a=!0):i.push(e)}else i.push(e)}),a||i.push(t),i.sort(function(e,t){return e.pos-t.pos}),{tree:i,conflicts:s||"internal_node"}):{tree:[t],conflicts:"new_leaf"}}function i(e,t){var r=a.rootToLeaf(e).map(function(e){var r=e.ids.slice(-t);return{pos:e.pos+(e.ids.length-r.length),ids:n(r)}});return r.reduce(function(e,t){return o(e,t,!0).tree},[r.shift()])}var s=e("./deps/extend"),a={};a.merge=function(e,t,n){e=s(!0,[],e),t=s(!0,{},t);var r=o(e,t);return{tree:i(r.tree,n),conflicts:r.conflicts}},a.winningRev=function(e){var t=[];return a.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},a.traverseRevTree=function(e,t){var n=[];for(e.forEach(function(e){n.push({pos:e.pos,ids:e.ids})});n.length>0;){var r=n.pop(),o=r.pos,i=r.ids,s=t(0===i[2].length,o,i[0],r.ctx,i[1]);i[2].forEach(function(e){n.push({pos:o+1,ids:e,ctx:s})})}},a.collectLeaves=function(e){var t=[];return a.traverseRevTree(e,function(e,n,r,o,i){e&&t.unshift({rev:n+"-"+r,pos:n,opts:i})}),t.sort(function(e,t){return t.pos-e.pos}),t.map(function(e){delete e.pos
  }),t},a.collectConflicts=function(e){var t=a.winningRev(e),n=a.collectLeaves(e.rev_tree),r=[];return n.forEach(function(e){e.rev===t||e.opts.deleted||r.push(e.rev)}),r},a.rootToLeaf=function(e){var t=[];return a.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=a},{"./deps/extend":10}],15:[function(e,t,n){"use strict";function r(){var e=this;this.cancelled=!1,this.cancel=function(){e.cancelled=!0}}function o(){this.seq=0,this.changes=[],this.docs=[]}function i(e,t,n,r){var o=n.filter?n.filter.toString():"";e.id(function(e,i){t.id(function(e,t){var s=i+t+o+JSON.stringify(n.query_params)+n.doc_ids;r("_local/"+p.Crypto.MD5(s))})})}function s(e,t,n,r){t.get(n,function(t,o){t&&404===t.status?r(null,0):t?r(t):e.get(n,function(e,t){e&&404===e.status||!e&&o.last_seq!==t.last_seq?r(null,0):e?r(e):r(null,t.last_seq)})})}function a(e,t,n,r,o){function i(e,t){e.get(n,function(o,i){if(o&&404===o.status)i={_id:n};else if(o)return t(o);i.last_seq=r,e.put(i,t)})}i(t,function(t){return t?o(t):void i(e,function(e){return e?o(e):void o()})})}function u(e,t,n,r,i){function u(){if(0===k.docs.length)return v();var e=k.docs;n.bulkDocs({docs:e},{new_edits:!1},function(t,n){if(t)return I.doc_write_failures+=e.length,h("target.bulkDocs completed with error",t);var r=[];return n.forEach(function(e){e.ok||(I.doc_write_failures++,r.push({status:500,error:e.error||"Unknown document write error",reason:e.reason||"Unknown reason"}))}),r.length>0?h("target.bulkDocs failed to write docs",r):(I.docs_written+=e.length,void v())})}function d(e,t){return i.cancelled?b():e?h("src.get completed with error",e):(Object.keys(t).forEach(function(e){var n=t[e].ok;n&&(I.docs_read++,k.pendingRevs++,k.docs.push(n))}),void f())}function l(e,n){t.allDocs({keys:e,include_docs:!0},function(e,t){return i.cancelled?b():e?h("src.get completed with error",e):(t.rows.forEach(function(e,t){var r=!e.doc||"1-"!==e.value.rev.slice(0,2)||e.doc._attachments&&Object.keys(e.doc._attachments).length;return r?O.push({id:"not_found"===e.error?e.key:e.id,rev:n[t]}):(I.docs_read++,k.pendingRevs++,void k.docs.push(e.doc))}),void f())})}function f(){if(O.length){var e=O.shift();return c(t,d,e.id,[e.rev])}var n=k.diffs;if(0===Object.keys(n).length)return void u();var r=Object.keys(n).reduce(function(e,t){return 1===n[t].missing.length&&"1-"===n[t].missing[0].slice(0,2)&&(e.ids.push(t),e.revs.push(n[t].missing[0]),delete n[t]),e},{ids:[],revs:[]});if(r.ids.length)return l(r.ids,r.revs);var o=Object.keys(n)[0],i=n[o].missing;delete n[o],c(t,d,o,i)}function h(e,t){if(!N){I.ok=!1,I.status="aborted",I.errors.push(t),I.end_time=new Date,I.last_seq=j,x=[],q=new o;var n={status:500,error:"Replication aborted",reason:e,details:t};N=!0,p.call(r.complete,n,I),i.cancel()}}function v(){T=!0,a(t,n,e,k.seq,function(e){return T=!1,i.cancelled?b():e?h("writeCheckpoint completed with error",e):(I.last_seq=j=k.seq,p.call(r.onChange,null,I),k=void 0,void y())})}function m(e,t){return i.cancelled?b():e?h("target.revsDiff completed with error",e):0===Object.keys(t).length?void v():(k.diffs=t,k.pendingRevs=0,void f())}function _(){var e={};k.changes.forEach(function(t){e[t.id]=t.changes.map(function(e){return e.rev})}),n.revsDiff(e,m)}function y(){if(i.cancelled)return b();if(!k){if(0===x.length)return void g();k=x.shift(),_()}}function g(){return 0===q.changes.length?void(R&&0===x.length&&!k&&b()):void((R||q.changes.length>=D)&&(x.push(q),q=new o,y()))}function b(){return N||i.cancelled&&(I.status="cancelled",T)?void 0:(I.status=I.status||"complete",I.end_time=new Date,I.last_seq=j,N=!0,I.errors.length>0?p.call(r.complete,I.errors[0],I):p.call(r.complete,null,I))}function w(e){return i.cancelled?b():void(N||(q.seq=e.seq,q.changes.push(e),g()))}function E(e){return R=!0,i.cancelled?b():(e&&(I.status="src.changes completed with error",I.errors.push(e)),void g())}function S(){s(t,n,e,function(e,n){if(e)return h("fetchCheckpoint completed with error",e);if(j=n,i.cancelled)return b();var o={continuous:A,since:j,style:"all_docs",onChange:w,complete:E,doc_ids:C};r.filter&&(o.filter=r.filter),r.query_params&&(o.query_params=r.query_params);var s=t.changes(o),a=i.cancel;i.cancel=function(){a(),b(),s&&s.cancel instanceof Function&&s.cancel()}})}var k,x=[],q=new o,O=[],T=!1,R=!1,N=!1,j=0,A=r.continuous||r.live||!1,D=r.batch_size||1,C=r.doc_ids,I={ok:!0,start_time:new Date,docs_read:0,docs_written:0,doc_write_failures:0,errors:[]};"undefined"==typeof r.since?S():a(t,n,e,r.since,function(e){return e?h("writeCheckpoint completed with error",e):(j=r.since,void S())})}function c(e,t,n,r){e.get(n,{revs:!0,open_revs:r,attachments:!0},t)}function d(e,t){return"string"==typeof e?new h(e,t):void t(null,e)}function l(e,t,n,o){n instanceof Function&&(o=n,n={}),void 0===n&&(n={}),n.complete||(n.complete=o),n=p.extend(!0,{},n),n.continuous=n.continuous||n.live;var s=new r;return d(e,function(e,r){return e?o(e):void d(t,function(e,t){if(e)return o(e);if(n.server){if("function"!=typeof r.replicateOnServer)return o({error:"Server replication not supported for "+r.type()+"adapter"});if(r.type()!==t.type())return o({error:"Server replication for different adapter types ("+r.type()+" and "+t.type()+") is not supported"});r.replicateOnServer(t,n,s)}else i(r,t,n,function(e){u(e,r,t,n,s)})})}),s}function f(e,t,n,r){function o(e,t){return function(n,r){n&&c(),r.direction=t,e(n,r)}}function i(e,t){return t=t||function(){},function(n){return{source:e,change:t(n)}}}function s(e,t,n){return t=p.extend(!0,{},t),t.complete=o(t.complete,n),t.onChange=i(e,t.onChange),t.continuous=t.continuous||t.live,t}function a(){return d=l(e,t,s(e,n,"push"),r)}function u(){return f=l(t,e,s(t,n,"pull"),r)}function c(){d&&d.cancel(),f&&f.cancel()}var d,f;return n instanceof Function&&(r=n,n={}),void 0===n&&(n={}),r instanceof Function&&!n.complete&&(n.complete=r),{push:a(),pull:u(),cancel:c}}var p=e("./utils"),h=e("./index");n.replicate=l,n.sync=f},{"./index":13,"./utils":18}],16:[function(e,t){(function(n){"use strict";var r=e("./constructor"),o=e("./utils"),i=e("events").EventEmitter;r.adapters={},r.prefix="_pouch_";var s=new i,a=["on","addListener","emit","listeners","once","removeAllListeners","removeListener","setMaxListeners"],u=["levelalt","idb","leveldb","websql"];a.forEach(function(e){r[e]=s[e].bind(s)}),r.setMaxListeners(0),r.parseAdapter=function(e,t){var i,s,a=e.match(/([a-z\-]*):\/\/(.*)/);if(a){if(e=/http(s?)/.test(a[1])?a[1]+"://"+a[2]:a[2],i=a[1],!r.adapters[i].valid())throw"Invalid adapter";return{name:e,adapter:a[1]}}var c="idb"in r.adapters&&"websql"in r.adapters&&o.hasLocalStorage()&&n.localStorage["_pouch__websqldb_"+r.prefix+e];if("undefined"!=typeof t&&t.db)s="leveldb";else for(var d=0;d<u.length;++d)if(s=u[d],s in r.adapters){if(c&&"idb"===s)continue;break}if(s){i=r.adapters[s];var l="use_prefix"in i?i.use_prefix:!0;return{name:l?r.prefix+e:e,adapter:s}}throw"No valid adapter found"},r.destroy=o.toPromise(function(e,t,n){("function"==typeof t||"undefined"==typeof t)&&(n=t,t={}),"object"==typeof e&&(t=e,e=void 0);var o=r.parseAdapter(t.name||e,t),i=o.name;r.adapters[o.adapter].destroy(i,t,function(e,t){e?n(e):(r.emit("destroyed",i),r.emit(i,"destroyed"),n(null,t))})}),r.allDbs=o.toPromise(function(e){var t=new Error("allDbs method removed");t.stats="400",e(t)}),r.adapter=function(e,t){t.valid()&&(r.adapters[e]=t)},r.plugin=function(e){Object.keys(e).forEach(function(t){r.prototype[t]=e[t]})},t.exports=r}).call(this,"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./constructor":5,"./utils":18,events:21}],17:[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();)t=e.parameters[e.parameters.length-1],"function"==typeof t?t(this.failed):"changes"===e.name&&"function"==typeof t.complete&&t.complete(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)}},{}],18:[function(e,t,n){(function(t,r){function o(){return"undefined"!=typeof chrome&&"undefined"!=typeof chrome.storage&&"undefined"!=typeof chrome.storage.local}var i=e("./merge");n.extend=e("./deps/extend"),n.ajax=e("./deps/ajax"),n.createBlob=e("./deps/blob");var s=e("./deps/uuid");n.Crypto=e("./deps/md5.js");var a=e("./deps/buffer"),u=e("./deps/errors"),c=e("events").EventEmitter,d="function"==typeof r.Promise?r.Promise:e("bluebird"),l=["_id","_rev","_attachments","_deleted","_revisions","_revs_info","_conflicts","_deleted_conflicts","_local_seq","_rev_tree"];n.inherits=e("inherits"),n.uuids=function(e,t){"object"!=typeof t&&(t={});for(var n=t.length,r=t.radix,o=[];o.push(s(n,r))<e;);return o},n.uuid=function(e){return n.uuids(1,e)[0]},n.invalidIdError=function(e){return e?"string"!=typeof e?u.INVALID_ID:/^_/.test(e)&&!/^_(design|local)/.test(e)?u.RESERVED_ID:void 0:u.MISSING_ID},n.getArguments=function(e){return function(){for(var t=arguments.length,n=new Array(t),r=-1;++r<t;)n[r]=arguments[r];return e.call(this,n)}},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=i.winningRev(e)),t.indexOf("-")>=0&&(t=t.split("-")[1]);var n=!1;return i.traverseRevTree(e.rev_tree,function(e,r,o,i,s){o===t&&(n=!!s.deleted)}),n},n.filterChange=function(e){return function(t){var n={},r=e.filter&&"function"==typeof e.filter;if(n.query=e.query_params,e.filter&&r&&!e.filter.call(this,t.doc,n))return!1;if(e.doc_ids&&-1===e.doc_ids.indexOf(t.id))return!1;if(e.include_docs)for(var o in t.doc._attachments)t.doc._attachments.hasOwnProperty(o)&&(t.doc._attachments[o].stub=!0);else delete t.doc;return!0}},n.processChanges=function(e,t,r){t=t.filter(n.filterChange(e)),e.limit&&e.limit<t.length&&(t.length=e.limit),t.forEach(function(t){n.call(e.onChange,t)}),e.continuous||n.call(e.complete,null,{results:t,last_seq:r})},n.parseDoc=function(e,t){var r,o,i,s=null,a={status:"available"};if(e._deleted&&(a.deleted=!0),t)if(e._id||(e._id=n.uuid()),o=n.uuid({length:32,radix:16}).toLowerCase(),e._rev){if(i=/^(\d+)-(.+)$/.exec(e._rev),!i)throw"invalid value for property '_rev'";e._rev_tree=[{pos:parseInt(i[1],10),ids:[i[2],{status:"missing"},[[o,a,[]]]]}],r=parseInt(i[1],10)+1}else e._rev_tree=[{pos:1,ids:[o,a,[]]}],r=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,a,[]]:[t,{status:"missing"},[e]]},null)}],r=e._revisions.start,o=e._revisions.ids[0]),!e._rev_tree){if(i=/^(\d+)-(.+)$/.exec(e._rev),!i)return u.BAD_ARG;r=parseInt(i[1],10),o=i[2],e._rev_tree=[{pos:parseInt(i[1],10),ids:[i[2],a,[]]}]}s=n.invalidIdError(e._id);for(var c in e)e.hasOwnProperty(c)&&"_"===c[0]&&-1===l.indexOf(c)&&(s=n.extend({},u.DOC_VALIDATION),s.reason+=": "+c);return e._id=decodeURIComponent(e._id),e._rev=[r,o].join("-"),s?s:Object.keys(e).reduce(function(t,n){return/^_/.test(n)&&"_attachments"!==n?t.metadata[n.slice(1)]=e[n]:t.data[n]=e[n],t},{metadata:{},data:{}})},n.isCordova=function(){return"undefined"!=typeof cordova||"undefined"!=typeof PhoneGap||"undefined"!=typeof phonegap},n.hasLocalStorage=function(){if(o())return!1;try{return r.localStorage}catch(e){return!1}},n.Changes=function(){var e={},t=new c,i=o(),s={},a=!1;return i||(a=n.hasLocalStorage()),i?chrome.storage.onChanged.addListener(function(e){null!=e.db_name&&t.emit(e.dbName.newValue)}):a&&(r.addEventListener?r.addEventListener("storage",function(e){t.emit(e.key)}):r.attachEvent("storage",function(e){t.emit(e.key)})),e.addListener=function(e,r,o,i){function a(){o.changes({include_docs:i.include_docs,conflicts:i.conflicts,continuous:!1,descending:!1,filter:i.filter,view:i.view,since:i.since,query_params:i.query_params,onChange:function(e){e.seq>i.since&&!i.cancelled&&(i.since=e.seq,n.call(i.onChange,e))}})}s[r]||(s[r]=a,t.on(e,a))},e.removeListener=function(e,n){n in s&&t.removeListener(e,s[n])},e.clearListeners=function(e){t.removeAllListeners(e)},e.notifyLocalWindows=function(e){i?chrome.storage.local.set({dbName:e}):a&&(localStorage[e]="a"===localStorage[e]?"b":"a")},e.notify=function(e){t.emit(e)},e},n.atob=t.browser&&"atob"in r?function(e){return atob(e)}:function(e){var t=new a(e,"base64");if(t.toString("base64")!==e)throw"Cannot base64 encode full string";return t.toString("binary")},n.btoa=t.browser&&"btoa"in r?function(e){return btoa(e)}:function(e){return new a(e,"binary").toString("base64")},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.once=function(e){var t=!1;return n.getArguments(function(n){if(t)throw console.trace(),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){try{var s=n.once(function(e,n){e?o(e):t(n)});r.push(s),e.apply(i,r)}catch(a){o(a)}});return o&&a.then(function(e){o(null,e)},o),a.cancel=function(){return this},a})},n.adapterFun=function(e,t){return n.toPromise(n.getArguments(function(n){return this.taskqueue.isReady?void t.apply(this,n):void this.taskqueue.addTask(e,n)}))},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.extend(!0,{},r):{},r.complete=r.complete||function(){};var o=n.once(r.complete),i=new d(function(e,t){r.complete=function(n,r){n?t(n):e(r)}});return i.then(function(e){o(null,e)},o),i.cancel=function(){i.isCancelled=!0,t.taskqueue.isReady&&r.complete(null,{status:"cancelled"})},t.taskqueue.isReady?(e(t,r,i),i):(t.taskqueue.addTask(function(){i.isCancelled?r.complete(null,{status:"cancelled"}):e(t,r,i)}),i)}}).call(this,e("/Users/cmetcalf/pouchdb/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"),"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./deps/ajax":6,"./deps/blob":7,"./deps/buffer":20,"./deps/errors":8,"./deps/extend":10,"./deps/md5.js":11,"./deps/uuid":12,"./merge":14,"/Users/cmetcalf/pouchdb/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":22,bluebird:27,events:21,inherits:23}],19:[function(e,t){t.exports=e("../package.json").version},{"../package.json":52}],20:[function(){},{}],21:[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))throw t=arguments[1],t instanceof Error?t: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),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}},{}],22:[function(e,t){var n=t.exports={};n.nextTick=function(){var e="undefined"!=typeof window&&window.setImmediate,t="undefined"!=typeof window&&window.postMessage&&window.addEventListener;if(e)return function(e){return window.setImmediate(e)};if(t){var n=[];return window.addEventListener("message",function(e){var t=e.source;if((t===window||null===t)&&"process-tick"===e.data&&(e.stopPropagation(),n.length>0)){var r=n.shift();r()}},!0),function(e){n.push(e),window.postMessage("process-tick","*")}}return function(e){setTimeout(e,0)}}(),n.title="browser",n.browser=!0,n.env={},n.argv=[],n.binding=function(){throw new Error("process.binding is not supported")},n.cwd=function(){return"/"},n.chdir=function(){throw new Error("process.chdir is not supported")}},{}],23:[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}},{}],24:[function(e,t){"use strict";function n(){}t.exports=n},{}],25:[function(e,t){"use strict";var n=e("./INTERNAL"),r=e("./promise"),o=e("./reject"),i=e("./resolve");t.exports=function(e){function t(e,t){i(e).then(function(e){a[t]=e,++u===s&&d.resolve(a)},function(e){d.reject(e)})}if("[object Array]"!==Object.prototype.toString.call(e))return o(new TypeError("must be an array"));var s=e.length;if(!s)return i([]);for(var a=[],u=0,c=-1,d=new r(n);++c<s;)t(e[c],c);return d}},{"./INTERNAL":24,"./promise":29,"./reject":30,"./resolve":31}],26:[function(e,t){"use strict";function n(e){var t=e&&e.then;return e&&"object"==typeof e&&"function"==typeof t?function(){t.apply(e,arguments)}:void 0}t.exports=n},{}],27:[function(e,t,n){t.exports=n=e("./promise"),n.resolve=e("./resolve"),n.reject=e("./reject"),n.all=e("./all")},{"./all":25,"./promise":29,"./reject":30,"./resolve":31}],28:[function(e,t){"use strict";function n(){var e=0;return function(t){return function(){e++||t.apply(this,arguments)}}}t.exports=n},{}],29:[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=c,this.queue=[],e!==i&&r(this,e)}function r(e,t){var n=s(),r=n(function(t){return e.reject(t)}),o=a(function(){t(n(function(t){return e.resolve(t)}),r)});"error"===o.status&&r(o.value)}var o=e("./unwrap"),i=e("./INTERNAL"),s=e("./once"),a=e("./tryCatch"),u=e("./getThen"),c=["PENDING"],d=["FULFILLED"],l=["REJECTED"];t.exports=n,n.prototype.resolve=function(e){var t=a(u,e);if("error"===t.status)return this.reject(t.value);var n=t.value;if(n)r(this,n);else{this.state=d,this.outcome=e;for(var o=-1,i=this.queue.length;++o<i;)this.queue[o].callFulfilled(e)}return this},n.prototype.reject=function(e){this.state=l,this.outcome=e;for(var t=-1,n=this.queue.length;++t<n;)this.queue[t].callRejected(e);return this},n.prototype["catch"]=function(e){return this.then(null,e)},n.prototype.then=function(e,t){var r="function"==typeof e,s="function"==typeof t;if(!r&&this.state===d||!t&&this.state===l)return this;var a=new n(i),u={promise:a};return this.state!==l&&(u.callFulfilled=r?function(t){o(a,e,t)}:function(e){a.resolve(e)}),this.state!==d&&(u.callRejected=s?function(e){o(a,t,e)}:function(e){a.reject(e)}),this.state===d?u.callFulfilled(this.outcome):this.state===l?u.callRejected(this.outcome):this.queue.push(u),a}},{"./INTERNAL":24,"./getThen":26,"./once":28,"./tryCatch":32,"./unwrap":33}],30:[function(e,t){"use strict";function n(e){var t=new r(o);return t.reject(e)}var r=e("./promise"),o=e("./INTERNAL");t.exports=n},{"./INTERNAL":24,"./promise":29}],31:[function(e,t){"use strict";function n(e){if(e)return new r(o).resolve(e);var t=typeof e;switch(t){case"boolean":return i;case"undefined":return a;case"object":return s;case"number":return u;case"string":return c}}var r=e("./promise"),o=e("./INTERNAL");t.exports=n;var i=new r(o).resolve(!1),s=new r(o).resolve(null),a=new r(o).resolve(void 0),u=new r(o).resolve(0),c=new r(o).resolve("")},{"./INTERNAL":24,"./promise":29}],32:[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},{}],33:[function(e,t){"use strict";function n(e,t,n){r(function(){var r;try{r=t(n)}catch(o){return e.reject(o)}r===e?e.reject(new TypeError("Cannot resolve promise with itself")):e.resolve(r)})}var r=e("immediate");t.exports=n},{immediate:35}],34:[function(e,t,n){"use strict";n.test=function(){return!1}},{}],35:[function(e,t){"use strict";function n(){var e,t=0,n=i;for(i=[];e=n[t++];)e()}for(var r,o=[e("./nextTick"),e("./mutation"),e("./postMessage"),e("./messageChannel"),e("./stateChange"),e("./timeout")],i=[],s=-1,a=o.length;++s<a;)if(o[s].test()){r=o[s].install(n);break}t.exports=function(e){var t,o,s,a=e;if(arguments.length>1&&"function"==typeof e){for(s=new Array(arguments.length-1),o=0;++o<arguments.length;)s[o-1]=arguments[o];a=function(){e.apply(void 0,s)}}return 1===(t=i.push(a))&&r(n),t},t.exports.clear=function(e){return e<=i.length&&(i[e-1]=function(){}),this}},{"./messageChannel":36,"./mutation":37,"./nextTick":34,"./postMessage":38,"./stateChange":39,"./timeout":40}],36:[function(e,t,n){(function(e){"use strict";n.test=function(){return"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 self?self:"undefined"!=typeof window?window:{})},{}],37:[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=new t(n),o=e.document.createElement("div");return r.observe(o,{attributes:!0}),e.addEventListener("unload",function(){r.disconnect(),r=null},!1),function(){o.setAttribute("drainQueue","drainQueue")}}}).call(this,"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],38:[function(e,t,n){(function(e){"use strict";n.test=function(){if(!e.postMessage||e.importScripts)return!1;var t=!0,n=e.onmessage;return e.onmessage=function(){t=!1},e.postMessage("","*"),e.onmessage=n,t},n.install=function(t){function n(n){n.source===e&&n.data===r&&t()}var r="com.calvinmetcalf.setImmediate"+Math.random();return e.addEventListener?e.addEventListener("message",n,!1):e.attachEvent("onmessage",n),function(){e.postMessage(r,"*")}}}).call(this,"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],39:[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 self?self:"undefined"!=typeof window?window:{})},{}],40:[function(e,t,n){"use strict";n.test=function(){return!0},n.install=function(e){return function(){setTimeout(e,0)}}},{}],41:[function(require,module,exports){"use strict";module.exports=function(func,emit,sum,log,isArray,toJSON){return eval("'use strict'; ("+func+");")}},{}],42:[function(e,t,n){(function(t,r){"use strict";function o(e){for(var t={},n=0,r=e.length;r>n;n++){var o=_(e[n]),i=t[o];"undefined"==typeof i?t[o]=n:"number"==typeof i?t[o]=[i,n]:i.push(n)}return t}function i(e,t){var n=h(e.id,t.id);return 0!==n?n:h(e.value,t.value)}function s(e,t,n){var r=n[e];"undefined"==typeof r?n[e]=t:Array.isArray(r)?r.push(t):n[e]=[r,t]}function a(e){return e.reduce(function(e,t){return e+t},0)}function u(e,t,n,r){var o=t[e];"undefined"!=typeof o&&(r&&(o=encodeURIComponent(JSON.stringify(o))),n.push(e+"="+o))}function c(e,t,n){var r=new Array(t.length);e.forEach(function(e){var t=n[_(e.key)];"number"==typeof t?s(t,e,r):t.forEach(function(t){s(t,e,r)})});var o=[];return r.forEach(function(e){Array.isArray(e)?o=o.concat(e.sort(i)):o.push(e)}),o}function d(e,t,n){function r(t,r){var s={id:u.doc._id,key:t,value:r};if(!("undefined"!=typeof n.startkey&&h(t,n.startkey)<0||"undefined"!=typeof n.endkey&&h(t,n.endkey)>0||"undefined"!=typeof n.key&&0!==h(t,n.key)||"undefined"!=typeof n.keys&&(d=d||o(n.keys),"undefined"==typeof d[_(t)]))){if(f++,n.include_docs){if(r&&"object"==typeof r&&r._id)return void e.get(r._id,function(e,t){t&&(s.doc=t),l.push(s),i()});s.doc=u.doc}l.push(s)}}function i(){var e;if(p&&l.length===f){if("undefined"!=typeof n.keys&&l.length?l=c(l,n.keys,d):l.sort(function(e,t){var n=h(e.key,t.key);return 0!==n?n:h(e.id,t.id)}),n.descending&&l.reverse(),n.reduce===!1)return n.complete(null,{total_rows:l.length,offset:n.skip,rows:"limit"in n?l.slice(n.skip,n.limit+n.skip):n.skip>0?l.slice(n.skip):l});var r=[];if(l.forEach(function(e){var t=r[r.length-1];return t&&0===h(t.key[0][0],e.key)?(t.key.push([e.key,e.id]),void t.value.push(e.value)):void r.push({key:[[e.key,e.id]],value:[e.value]})}),r.forEach(function(n){return n.value=t.reduce.call(null,n.key,n.value),n.value.sumsqr&&n.value.sumsqr instanceof Error?void(e=n.value):void(n.key=n.key[0][0])}),e)return void n.complete(e);n.complete(null,{total_rows:r.length,offset:n.skip,rows:"limit"in n?r.slice(n.skip,n.limit+n.skip):n.skip>0?r.slice(n.skip):r})}}var s;n.skip||(n.skip=0),t.reduce||(n.reduce=!1);var u,d,l=[],f=0,p=!1;"function"==typeof t.map&&2===t.map.length?(s=t.map,t.map=function(e){return s(e,r)}):t.map=v(t.map.toString(),r,a,m,Array.isArray,JSON.parse),t.reduce&&(t.reduce=y[t.reduce]?y[t.reduce]:v(t.reduce.toString(),r,a,m,Array.isArray,JSON.parse)),e.changes({conflicts:!0,include_docs:!0,onChange:function(e){"deleted"in e||"_"===e.id[0]||(u={doc:e.doc},t.map.call(null,e.doc))},complete:function(){p=!0,i()}})}function l(e,t,n){var r,o=n.complete,i=[],s="GET";if(u("reduce",n,i),u("include_docs",n,i),u("limit",n,i),u("descending",n,i),u("group",n,i),u("group_level",n,i),u("skip",n,i),u("startkey",n,i,!0),u("endkey",n,i,!0),u("key",n,i,!0),"undefined"!=typeof n.keys&&(s="POST","string"==typeof t?r=JSON.stringify({keys:n.keys}):t.keys=n.keys),i=i.join("&"),i=""===i?"":"?"+i,"string"==typeof t){var a=t.split("/");return void e.request({method:s,url:"_design/"+a[0]+"/_view/"+a[1]+i,body:r},o)}var c=JSON.parse(JSON.stringify(t,function(e,t){return"function"==typeof t?t+"":t}));e.request({method:"POST",url:"_temp_view"+i,body:c},o)}var f=e("pouchdb-collate"),p="function"==typeof r.Promise?r.Promise:e("lie"),h=f.collate,v=e("./evalfunc"),m="undefined"!=typeof console?Function.prototype.bind.call(console.log,console):function(){},_=function(e){return JSON.stringify(f.normalizeKey(e))},y={_sum:function(e,t){return a(t)},_count:function(e,t){return t.length},_stats:function(e,t){return{sum:a(t),min:Math.min.apply(null,t),max:Math.max.apply(null,t),count:t.length,sumsqr:function(){var e,n=0;for(var r in t){if("number"!=typeof t[r])return e=new Error("builtin _stats function requires map values to be numbers"),e.name="invalid_value",e.status=500,e;n+=t[r]*t[r]}return n}()}}};n.query=function(e,n,r){var o=this;"function"==typeof n&&(r=n,n={}),n=n||{},r&&(n.complete=r);var i,s=n.complete;n.complete&&(i=function(e,n){t.nextTick(function(){s(e,n)})});var a=new p(function(t,r){if(n.complete=function(e,n){e?r(e):t(n)},"http"===o.type())return"function"==typeof e?l(o,{map:e},n):l(o,e,n);if("object"==typeof e)return d(o,e,n);if("function"==typeof e)return d(o,{map:e},n);var i=e.split("/");o.get("_design/"+i[0],function(e,t){return e?void n.complete(e):t.views[i[1]]?void d(o,{map:t.views[i[1]].map,reduce:t.views[i[1]].reduce},n):void n.complete({name:"not_found",message:"missing_named_view"})})});return i&&a.then(function(e){i(null,e)},i),a}}).call(this,e("/Users/cmetcalf/pouchdb/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js"),"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{"./evalfunc":41,"/Users/cmetcalf/pouchdb/node_modules/browserify/node_modules/insert-module-globals/node_modules/process/browser.js":22,lie:43,"pouchdb-collate":51}],43:[function(e,t){"use strict";function n(e,t,n){u?Object.defineProperty(e,t,{value:n,configurable:!0,writable:!0}):e[t]=n}function r(e){return this instanceof r?(n(this,"successQueue",[]),n(this,"failureQueue",[]),n(this,"resolved",!1),void("function"==typeof e&&this.resolvePassed(e))):new r(e)}function o(e,t,n){n&&"function"==typeof n.then?n.then(e,t):e(n)}function i(e,t,n){function o(){var o=arguments[n];return"function"!=typeof o?e:new r(function(e,n){a(s,o,t,e,n)})}return o}function s(e,t,n,r){try{o(n,r,e(t))}catch(i){r(i)}}var a=e("immediate"),u=!1;!function(){try{Object.defineProperty({},"test",{value:!0}),u=!0}catch(e){}}(),n(r.prototype,"resolvePassed",function(e){try{e(this.fulfillUnwrap.bind(this),this.reject.bind(this))}catch(t){this.reject(t)}}),n(r.prototype,"reject",function(e){this.resolve(!1,e)}),n(r.prototype,"fulfill",function(e){this.resolve(!0,e)}),n(r.prototype,"fulfillUnwrap",function(e){o(this.fulfill.bind(this),this.reject.bind(this),e)}),r.prototype.then=function(e,t){return this.resolved?this.resolved(e,t):this.pending(e,t)},function(){try{r.prototype["catch"]=function(e){return this.then(null,e)}}catch(e){}}(),n(r.prototype,"pending",function(e,t){var n=this;return new r(function(r,o){n.successQueue.push("function"==typeof e?{resolve:r,reject:o,callback:e}:{next:r,callback:!1}),n.failureQueue.push("function"==typeof t?{resolve:r,reject:o,callback:t}:{next:o,callback:!1})
  })}),n(r.prototype,"resolve",function(e,t){if(!this.resolved){this.resolved=i(this,t,e?0:1);for(var n=e?this.successQueue:this.failureQueue,r=n.length,o=-1;++o<r;)n[o].callback?a(s,n[o].callback,t,n[o].resolve,n[o].reject):n[o].next(t)}}),t.exports=r},{immediate:45}],44:[function(e,t){t.exports=e(34)},{}],45:[function(e,t){t.exports=e(35)},{"./messageChannel":46,"./mutation":47,"./nextTick":44,"./postMessage":48,"./stateChange":49,"./timeout":50}],46:[function(e,t){t.exports=e(36)},{}],47:[function(e,t){t.exports=e(37)},{}],48:[function(e,t){t.exports=e(38)},{}],49:[function(e,t){t.exports=e(39)},{}],50:[function(e,t){t.exports=e(40)},{}],51:[function(e,t,n){"use strict";function r(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 o(e,t){return e===t?0:e>t?1:-1}function i(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 s(e){var t=["boolean","number","string","object"];return-1!==t.indexOf(typeof e)?null===e?1:t.indexOf(typeof e)+2:Array.isArray(e)?4.5:void 0}n.collate=function(e,t){e=n.normalizeKey(e),t=n.normalizeKey(t);var a=s(e),u=s(t);return a-u!==0?a-u:null===e?0:"number"==typeof e?e-t:"boolean"==typeof e?e===t?0:t>e?-1:1:"string"==typeof e?o(e,t):Array.isArray(e)?r(e,t):"object"==typeof e?i(e,t):void 0},n.normalizeKey=function(e){if("undefined"==typeof e)return null;if("number"==typeof e){if(1/0===e||e===-1/0||isNaN(e))return null}else if(e instanceof Date)return e.toJSON();return e}},{}],52:[function(e,t){t.exports={name:"pouchdb",version:"2.1.1",description:"PouchDB is a pocket-sized database.",release:"nightly",main:"./lib/index.js",homepage:"https://github.com/daleharvey/pouchdb",repository:"https://github.com/daleharvey/pouchdb",keywords:["db","couchdb","pouchdb"],tags:["db","couchdb","pouchdb"],dependencies:{bluebird:"~1.0.0",inherits:"~2.0.1","level-js":"~2.0.0","level-sublevel":"~5.2.0",leveldown:"~0.10.2",levelup:"~0.18.2",lie:"^2.6.0","pouchdb-mapreduce":"1.0.0",request:"~2.28.0"},devDependencies:{commander:"~2.1.0",watchify:"~0.4.1","uglify-js":"~2.4.6",jshint:"~2.3.0","http-proxy":"~0.10.3",corsproxy:"~0.2.13","http-server":"~0.5.5",browserify:"~3.24.13",wd:"~0.2.8",tin:"~0.4.0",mocha:"~1.17.1",chai:"~1.9.0",istanbul:"~0.2.4",ncp:"~0.5.0","sauce-connect-launcher":"0.2.2",less:"~1.7.0",bower:"~1.2.8"},scripts:{jshint:"jshint -c .jshintrc bin/ lib/ tests/*.js","build-js":"browserify . > dist/pouchdb-nightly.js",min:"uglifyjs dist/pouchdb-nightly.js -mc > dist/pouchdb-nightly.min.js",build:"mkdir -p dist && npm run build-js && npm run min","test-node":"./bin/run-mocha.sh","test-browser":"mkdir -p dist && npm run build-js && ./bin/test-browser.js",dev:"./bin/dev-server.js",test:"npm run jshint && ./bin/run-test.sh",publish:"./bin/publish.sh","publish-site":"./bin/publish-site.sh","build-site":"./bin/build-site.sh",shell:"./bin/repl.js","report-coverage":"./bin/run-coverage.js"},browser:{"./deps/buffer":!1,request:!1,"level-sublevel":!1,levelup:!1,crypto:!1,"./adapters/leveldb":!1,"./adapters/levelalt":!1,bluebird:"lie"}}},{}]},{},[13]);