c?n.slice(0,c):n),t&&0===D(t.key[0][0],n)?(t.key.push([n,e.id]),void t.value.push(e.value)):void s.push({key:[[n,e.id]],value:[e.value]})});for(var u=0,l=s.length;l>u;u++){var d=s[u],p=i(e.sourceDB,r,[d.key,d.value,!1]);d.value=p.error?null:p.output,d.key=d.key[0][0]}return{rows:a(s,n.limit,n.skip)}}function E(e,t){return j.sequentialize(m(e),function(){return w(e,t)})()}function w(e,t){function n(t){return t.include_docs=!0,e.db.allDocs(t).then(function(e){return o=e.total_rows,e.rows.map(function(e){if("value"in e.doc&&"object"==typeof e.doc.value&&null!==e.doc.value){var t=Object.keys(e.doc.value).sort(),n=["id","key","value"];if(!(n>t||t>n))return e.doc.value}var r=q.parseIndexableString(e.doc._id);return{key:r[0],id:r[1],value:"value"in e.doc?e.doc.value:null}})})}function r(n){var r;if(r=i?b(e,n,t):{total_rows:o,offset:s,rows:n},t.include_docs){var a=j.uniq(n.map(c));return e.sourceDB.allDocs({keys:a,include_docs:!0,conflicts:t.conflicts,attachments:t.attachments}).then(function(e){var t={};return e.rows.forEach(function(e){e.doc&&(t["$"+e.id]=e.doc)}),n.forEach(function(e){var n=c(e),r=t["$"+n];r&&(e.doc=r)}),r})}return r}var o,i=e.reduceFun&&t.reduce!==!1,s=t.skip||0;"undefined"==typeof t.keys||t.keys.length||(t.limit=0,delete t.keys);var a=function(e){return e.reduce(function(e,t){return e.concat(t)})};if("undefined"!=typeof t.keys){var u=t.keys,f=u.map(function(e){var t={startkey:C([e]),endkey:C([e,{}])};return n(t)});return B.all(f).then(a).then(r)}var l={descending:t.descending};if("undefined"!=typeof t.startkey&&(l.startkey=C(t.descending?[t.startkey,{}]:[t.startkey])),"undefined"!=typeof t.endkey){var d=t.inclusive_end!==!1;t.descending&&(d=!d),l.endkey=C(d?[t.endkey,{}]:[t.endkey])}if("undefined"!=typeof t.key){var p=C([t.key]),h=C([t.key,{}]);l.descending?(l.endkey=p,l.startkey=h):(l.startkey=p,l.endkey=h)}return i||("number"==typeof t.limit&&(l.limit=t.limit),l.skip=s),n(l).then(r)}function S(e){return e.request({method:"POST",url:"_view_cleanup"})}function T(e){return e.get("_local/mrviews").then(function(t){var n={};Object.keys(t.views).forEach(function(e){var t=r(e),o="_design/"+t[0],i=t[1];n[o]=n[o]||{},n[o][i]=!0});var o={keys:Object.keys(n),include_docs:!0};return e.allDocs(o).then(function(r){var o={};r.rows.forEach(function(e){var r=e.key.substring(8);Object.keys(n[e.key]).forEach(function(n){var i=r+"/"+n;t.views[i]||(i=n);var s=Object.keys(t.views[i]),a=e.doc&&e.doc.views&&e.doc.views[n];s.forEach(function(e){o[e]=o[e]||a})})});var i=Object.keys(o).filter(function(e){return!o[e]}),s=i.map(function(t){return j.sequentialize(m(t),function(){return e.constructor.destroy(t,e.__opts)})()});return B.all(s).then(function(){return{ok:!0}})})},h({ok:!0}))}function x(e,n,o){if("http"===e.type())return p(e,n,o);if("string"!=typeof n){d(o,n);var i={db:e,viewName:"temp_view/temp_view",map:n.map,reduce:n.reduce,temporary:!0};return M.add(function(){return I(i).then(function(e){function t(){return e.db.destroy()}return j.fin(g(e).then(function(){return E(e,o)}),t)})}),M.finish()}var s=n,a=r(s),c=a[0],u=a[1];return e.get("_design/"+c).then(function(n){var r=n.views&&n.views[u];if(!r||"string"!=typeof r.map)throw new O("ddoc "+c+" has no view named "+u);d(o,r);var i={db:e,viewName:s,map:r.map,reduce:r.reduce};return I(i).then(function(e){return"ok"===o.stale||"update_after"===o.stale?("update_after"===o.stale&&t.nextTick(function(){g(e)}),E(e,o)):g(e).then(function(){return E(e,o)})})})}function A(e){this.status=400,this.name="query_parse_error",this.message=e,this.error=!0;try{Error.captureStackTrace(this,A)}catch(t){}}function O(e){this.status=404,this.name="not_found",this.message=e,this.error=!0;try{Error.captureStackTrace(this,O)}catch(t){}}var k,q=e(62),R=e(69),D=q.collate,C=q.toIndexableString,L=q.normalizeKey,I=e(66),N=e(67);k="undefined"!=typeof console&&"function"==typeof console.log?Function.prototype.bind.call(console.log,console):function(){};var j=e(71),B=j.Promise,F={},M=new R,P=50,U={_sum:function(e,t){return f(t)},_count:function(e,t){return t.length},_stats:function(e,t){function n(e){for(var t=0,n=0,r=e.length;r>n;n++){var o=e[n];t+=o*o}return t}return{sum:f(t),min:Math.min.apply(null,t),max:Math.max.apply(null,t),count:t.length,sumsqr:n(t)}}};n.viewCleanup=j.callbackify(function(){var e=this;return"http"===e.type()?S(e):T(e)}),n.query=function(e,t,n){"function"==typeof t&&(n=t,t={}),t=j.extend(!0,{},t),"function"==typeof e&&(e={map:e});var r=this,o=B.resolve().then(function(){return x(r,e,t)});return j.promisedCallback(o,n),o},j.inherits(A,Error),j.inherits(O,Error)}).call(this,e(39))},{}],69:[function(e,t){"use strict";function n(){this.promise=new r(function(e){e()})}var r=e(71).Promise;n.prototype.add=function(e){return this.promise=this.promise["catch"](function(){}).then(function(){return e()}),this.promise},n.prototype.finish=function(){return this.promise},t.exports=n},{}],70:[function(e,t){"use strict";var n=e(72).upsert;t.exports=function(e,t,r){return n.apply(e,[t,r])}},{}],71:[function(e,t,n){(function(t,r){"use strict";n.Promise="function"==typeof r.Promise?r.Promise:e(47),n.inherits=e(43),n.extend=e(65);var o=e(36);n.promisedCallback=function(e,n){return n&&e.then(function(e){t.nextTick(function(){n(null,e)})},function(e){t.nextTick(function(){n(e)})}),e},n.callbackify=function(e){return o(function(t){var r=t.pop(),o=e.apply(this,t);return"function"==typeof r&&n.promisedCallback(o,r),o})},n.fin=function(e,t){return e.then(function(e){var n=t();return"function"==typeof n.then?n.then(function(){return e}):e},function(e){var n=t();if("function"==typeof n.then)return n.then(function(){throw e});throw e})},n.sequentialize=function(e,t){return function(){var n=arguments,r=this;return e.add(function(){return t.apply(r,n)})}},n.flatten=function(e){for(var t=[],n=0,r=e.length;r>n;n++)t=t.concat(e[n]);return t},n.uniq=function(e){for(var t={},n=0,r=e.length;r>n;n++)t["$"+e[n]]=!0;var o=Object.keys(t),i=new Array(o.length);for(n=0,r=o.length;r>n;n++)i[n]=o[n].substring(1);return i};var i=e(37),s=e(73);n.MD5=function(e){return t.browser?s.hash(e):i.createHash("md5").update(e).digest("hex")}}).call(this,e(39),"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],72:[function(e,t,n){(function(t){"use strict";function r(e,t,n){return new i(function(r,i){return"string"!=typeof t?i(new Error("doc id is required")):void e.get(t,function(s,a){if(s){if(404!==s.status)return i(s);a={}}var c=n(a);return c?(c._id=t,c._rev=a._rev,void r(o(e,c,n))):r({updated:!1,rev:a._rev})})})}function o(e,t,n){return e.put(t).then(function(e){return{updated:!0,rev:e.rev}},function(o){if(409!==o.status)throw o;return r(e,t._id,n)})}var i;i="undefined"!=typeof window&&window.PouchDB?window.PouchDB.utils.Promise:"function"==typeof t.Promise?t.Promise:e(47),n.upsert=function(e,t,n){var o=this,i=r(o,e,t);return"function"!=typeof n?i:void i.then(function(e){n(null,e)},n)},n.putIfNotExists=function(e,t,n){var o=this;"string"!=typeof e&&(n=t,t=e,e=t._id);var i=function(e){return e._rev?!1:t},s=r(o,e,i);return"function"!=typeof n?s:void s.then(function(e){n(null,e)},n)},"undefined"!=typeof window&&window.PouchDB&&window.PouchDB.plugin(n)}).call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],73:[function(e,t,n){!function(e){if("object"==typeof n)t.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var r;try{r=window}catch(o){r=self}r.SparkMD5=e()}}(function(){"use strict";var e=function(e,t){return e+t&4294967295},t=function(t,n,r,o,i,s){return n=e(e(n,t),e(o,s)),e(n<>>32-i,r)},n=function(e,n,r,o,i,s,a){return t(n&r|~n&o,e,n,i,s,a)},r=function(e,n,r,o,i,s,a){return t(n&o|r&~o,e,n,i,s,a)},o=function(e,n,r,o,i,s,a){return t(n^r^o,e,n,i,s,a)},i=function(e,n,r,o,i,s,a){return t(r^(n|~o),e,n,i,s,a)},s=function(t,s){var a=t[0],c=t[1],u=t[2],f=t[3];a=n(a,c,u,f,s[0],7,-680876936),f=n(f,a,c,u,s[1],12,-389564586),u=n(u,f,a,c,s[2],17,606105819),c=n(c,u,f,a,s[3],22,-1044525330),a=n(a,c,u,f,s[4],7,-176418897),f=n(f,a,c,u,s[5],12,1200080426),u=n(u,f,a,c,s[6],17,-1473231341),c=n(c,u,f,a,s[7],22,-45705983),a=n(a,c,u,f,s[8],7,1770035416),f=n(f,a,c,u,s[9],12,-1958414417),u=n(u,f,a,c,s[10],17,-42063),c=n(c,u,f,a,s[11],22,-1990404162),a=n(a,c,u,f,s[12],7,1804603682),f=n(f,a,c,u,s[13],12,-40341101),u=n(u,f,a,c,s[14],17,-1502002290),c=n(c,u,f,a,s[15],22,1236535329),a=r(a,c,u,f,s[1],5,-165796510),f=r(f,a,c,u,s[6],9,-1069501632),u=r(u,f,a,c,s[11],14,643717713),c=r(c,u,f,a,s[0],20,-373897302),a=r(a,c,u,f,s[5],5,-701558691),f=r(f,a,c,u,s[10],9,38016083),u=r(u,f,a,c,s[15],14,-660478335),c=r(c,u,f,a,s[4],20,-405537848),a=r(a,c,u,f,s[9],5,568446438),f=r(f,a,c,u,s[14],9,-1019803690),u=r(u,f,a,c,s[3],14,-187363961),c=r(c,u,f,a,s[8],20,1163531501),a=r(a,c,u,f,s[13],5,-1444681467),f=r(f,a,c,u,s[2],9,-51403784),u=r(u,f,a,c,s[7],14,1735328473),c=r(c,u,f,a,s[12],20,-1926607734),a=o(a,c,u,f,s[5],4,-378558),f=o(f,a,c,u,s[8],11,-2022574463),u=o(u,f,a,c,s[11],16,1839030562),c=o(c,u,f,a,s[14],23,-35309556),a=o(a,c,u,f,s[1],4,-1530992060),f=o(f,a,c,u,s[4],11,1272893353),u=o(u,f,a,c,s[7],16,-155497632),c=o(c,u,f,a,s[10],23,-1094730640),a=o(a,c,u,f,s[13],4,681279174),f=o(f,a,c,u,s[0],11,-358537222),u=o(u,f,a,c,s[3],16,-722521979),c=o(c,u,f,a,s[6],23,76029189),a=o(a,c,u,f,s[9],4,-640364487),f=o(f,a,c,u,s[12],11,-421815835),u=o(u,f,a,c,s[15],16,530742520),c=o(c,u,f,a,s[2],23,-995338651),a=i(a,c,u,f,s[0],6,-198630844),f=i(f,a,c,u,s[7],10,1126891415),u=i(u,f,a,c,s[14],15,-1416354905),c=i(c,u,f,a,s[5],21,-57434055),a=i(a,c,u,f,s[12],6,1700485571),f=i(f,a,c,u,s[3],10,-1894986606),u=i(u,f,a,c,s[10],15,-1051523),c=i(c,u,f,a,s[1],21,-2054922799),a=i(a,c,u,f,s[8],6,1873313359),f=i(f,a,c,u,s[15],10,-30611744),u=i(u,f,a,c,s[6],15,-1560198380),c=i(c,u,f,a,s[13],21,1309151649),a=i(a,c,u,f,s[4],6,-145523070),f=i(f,a,c,u,s[11],10,-1120210379),u=i(u,f,a,c,s[2],15,718787259),c=i(c,u,f,a,s[9],21,-343485551),t[0]=e(a,t[0]),t[1]=e(c,t[1]),t[2]=e(u,t[2]),t[3]=e(f,t[3])},a=function(e){var t,n=[];for(t=0;64>t;t+=4)n[t>>2]=e.charCodeAt(t)+(e.charCodeAt(t+1)<<8)+(e.charCodeAt(t+2)<<16)+(e.charCodeAt(t+3)<<24);return n},c=function(e){var t,n=[];for(t=0;64>t;t+=4)n[t>>2]=e[t]+(e[t+1]<<8)+(e[t+2]<<16)+(e[t+3]<<24);return n},u=function(e){var t,n,r,o,i,c,u=e.length,f=[1732584193,-271733879,-1732584194,271733878];for(t=64;u>=t;t+=64)s(f,a(e.substring(t-64,t)));for(e=e.substring(t-64),n=e.length,r=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],t=0;n>t;t+=1)r[t>>2]|=e.charCodeAt(t)<<(t%4<<3);if(r[t>>2]|=128<<(t%4<<3),t>55)for(s(f,r),t=0;16>t;t+=1)r[t]=0;return o=8*u,o=o.toString(16).match(/(.*?)(.{0,8})$/),i=parseInt(o[2],16),c=parseInt(o[1],16)||0,r[14]=i,r[15]=c,s(f,r),f},f=function(e){var t,n,r,o,i,a,u=e.length,f=[1732584193,-271733879,-1732584194,271733878];for(t=64;u>=t;t+=64)s(f,c(e.subarray(t-64,t)));for(e=u>t-64?e.subarray(t-64):new Uint8Array(0),n=e.length,r=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0],t=0;n>t;t+=1)r[t>>2]|=e[t]<<(t%4<<3);if(r[t>>2]|=128<<(t%4<<3),t>55)for(s(f,r),t=0;16>t;t+=1)r[t]=0;return o=8*u,o=o.toString(16).match(/(.*?)(.{0,8})$/),i=parseInt(o[2],16),a=parseInt(o[1],16)||0,r[14]=i,r[15]=a,s(f,r),f},l=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"],d=function(e){var t,n="";for(t=0;4>t;t+=1)n+=l[e>>8*t+4&15]+l[e>>8*t&15];return n},p=function(e){var t;for(t=0;t