UNPKG

cronapp-framework-mobile-js

Version:
1 lines 60.3 kB
!function(e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).PouchAdapterCordovaSqlite=e()}(function(){return function r(i,o,s){function a(n,e){if(!o[n]){if(!i[n]){var t="function"==typeof require&&require;if(!e&&t)return t(n,!0);if(u)return u(n,!0);throw(e=new Error("Cannot find module '"+n+"'")).code="MODULE_NOT_FOUND",e}t=o[n]={exports:{}},i[n][0].call(t.exports,function(e){var t=i[n][1][e];return a(t||e)},t,t.exports,r,i,o,s)}return o[n].exports}for(var u="function"==typeof require&&require,e=0;e<s.length;e++)a(s[e]);return a}({1:[function(e,t,n){var r="function"==typeof Object.assign?Object.assign:function(e){for(var t=Object(e),n=1;n<arguments.length;n++){var r=arguments[n];if(null!=r)for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(t[i]=r[i])}return t};t.exports=r},{}],2:[function(e,t,n){t.exports=function(r){return function(){var e=arguments.length;if(e){for(var t=[],n=-1;++n<e;)t[n]=arguments[n];return r.call(this,t)}return r.call(this,[])}}},{}],3:[function(e,t,n){function r(){this._events=this._events||{},this._maxListeners=this._maxListeners||void 0}function u(e){return"function"==typeof e}function c(e){return"object"==typeof e&&null!==e}function f(e){return void 0===e}((t.exports=r).EventEmitter=r).prototype._events=void 0,r.prototype._maxListeners=void 0,r.defaultMaxListeners=10,r.prototype.setMaxListeners=function(e){if("number"!=typeof e||e<0||isNaN(e))throw TypeError("n must be a positive number");return this._maxListeners=e,this},r.prototype.emit=function(e){var t,n,r,i,o,s,a;if((this._events||(this._events={}),"error"===e)&&(!this._events.error||c(this._events.error)&&!this._events.error.length))throw(a=arguments[1])instanceof Error?a:((s=new Error('Uncaught, unspecified "error" event. ('+a+")")).context=a,s);if(f(t=this._events[e]))return!1;if(u(t))switch(arguments.length){case 1:t.call(this);break;case 2:t.call(this,arguments[1]);break;case 3:t.call(this,arguments[1],arguments[2]);break;default:r=Array.prototype.slice.call(arguments,1),t.apply(this,r)}else if(c(t))for(r=Array.prototype.slice.call(arguments,1),n=(o=t.slice()).length,i=0;i<n;i++)o[i].apply(this,r);return!0},r.prototype.on=r.prototype.addListener=function(e,t){if(u(t))return this._events||(this._events={}),this._events.newListener&&this.emit("newListener",e,u(t.listener)?t.listener:t),this._events[e]?c(this._events[e])?this._events[e].push(t):this._events[e]=[this._events[e],t]:this._events[e]=t,c(this._events[e])&&!this._events[e].warned&&(t=f(this._maxListeners)?r.defaultMaxListeners:this._maxListeners)&&0<t&&this._events[e].length>t&&(this._events[e].warned=!0,console.error("(node) warning: possible EventEmitter memory leak detected. %d listeners added. Use emitter.setMaxListeners() to increase limit.",this._events[e].length),"function"==typeof console.trace)&&console.trace(),this;throw TypeError("listener must be a function")},r.prototype.once=function(e,t){var n;if(u(t))return n=!1,r.listener=t,this.on(e,r),this;throw TypeError("listener must be a function");function r(){this.removeListener(e,r),n||(n=!0,t.apply(this,arguments))}},r.prototype.removeListener=function(e,t){var n,r,i,o;if(!u(t))throw TypeError("listener must be a function");if(this._events&&this._events[e])if(i=(n=this._events[e]).length,r=-1,n===t||u(n.listener)&&n.listener===t)delete this._events[e],this._events.removeListener&&this.emit("removeListener",e,t);else if(c(n)){for(o=i;0<o--;)if(n[o]===t||n[o].listener&&n[o].listener===t){r=o;break}if(r<0)return this;1===n.length?(n.length=0,delete this._events[e]):n.splice(r,1),this._events.removeListener&&this.emit("removeListener",e,t)}return this},r.prototype.removeAllListeners=function(e){var t,n;if(this._events)if(this._events.removeListener)if(0===arguments.length){for(t in this._events)"removeListener"!==t&&this.removeAllListeners(t);this.removeAllListeners("removeListener"),this._events={}}else{if(u(n=this._events[e]))this.removeListener(e,n);else if(n)for(;n.length;)this.removeListener(e,n[n.length-1]);delete this._events[e]}else 0===arguments.length?this._events={}:this._events[e]&&delete this._events[e];return this},r.prototype.listeners=function(e){e=this._events&&this._events[e]?u(this._events[e])?[this._events[e]]:this._events[e].slice():[];return e},r.prototype.listenerCount=function(e){if(this._events){e=this._events[e];if(u(e))return 1;if(e)return e.length}return 0},r.listenerCount=function(e,t){return e.listenerCount(t)}},{}],4:[function(e,c,t){!function(t){var e,n,r,i,o=t.MutationObserver||t.WebKitMutationObserver,s=o?(e=0,o=new o(u),n=t.document.createTextNode(""),o.observe(n,{characterData:!0}),function(){n.data=e=++e%2}):t.setImmediate||void 0===t.MessageChannel?"document"in t&&"onreadystatechange"in t.document.createElement("script")?function(){var e=t.document.createElement("script");e.onreadystatechange=function(){u(),e.onreadystatechange=null,e.parentNode.removeChild(e),e=null},t.document.documentElement.appendChild(e)}:function(){setTimeout(u,0)}:((r=new t.MessageChannel).port1.onmessage=u,function(){r.port2.postMessage(0)}),a=[];function u(){i=!0;for(var e,t,n=a.length;n;){for(t=a,a=[],e=-1;++e<n;)t[e]();n=a.length}i=!1}c.exports=function(e){1!==a.push(e)||i||s()}}.call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{}],5:[function(e,t,n){"function"==typeof Object.create?t.exports=function(e,t){e.super_=t,e.prototype=Object.create(t.prototype,{constructor:{value:e,enumerable:!1,writable:!0,configurable:!0}})}:t.exports=function(e,t){e.super_=t;function n(){}n.prototype=t.prototype,e.prototype=new n,e.prototype.constructor=e}},{}],6:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0});var l=e(14),g=e(10),s=e(8),a=e(12),E=e(13),u=e(9);function r(e){return e.reduce(function(e,t){return e[t]=!0,e},{})}var d=r(["_id","_rev","_attachments","_deleted","_revisions","_revs_info","_conflicts","_deleted_conflicts","_local_seq","_rev_tree","_replication_id","_replication_state","_replication_state_time","_replication_state_reason","_replication_stats","_removed"]),h=r(["_attachments","_replication_id","_replication_state","_replication_state_time","_replication_state_reason","_replication_stats"]);function p(e){var t,n;return/^\d+-./.test(e)?(t=e.indexOf("-"),n=e.substring(0,t),e=e.substring(t+1),{prefix:parseInt(n,10),id:e}):g.createError(g.INVALID_REV)}function v(e,t,n){n=n||{deterministic_revs:!0};var r,i,o,s={status:"available"};if(e._deleted&&(s.deleted=!0),t)if(e._id||(e._id=l.uuid()),i=l.rev(e,n.deterministic_revs),e._rev){if((o=p(e._rev)).error)return o;e._rev_tree=[{pos:o.prefix,ids:[o.id,{status:"missing"},[[i,s,[]]]]}],r=o.prefix+1}else e._rev_tree=[{pos:1,ids:[i,s,[]]}],r=1;else if(e._revisions&&(e._rev_tree=((e,t)=>{for(var n=e.start-e.ids.length+1,r=e.ids,i=[r[0],t,[]],o=1,s=r.length;o<s;o++)i=[r[o],{status:"missing"},[i]];return[{pos:n,ids:i}]})(e._revisions,s),r=e._revisions.start,i=e._revisions.ids[0]),!e._rev_tree){if((o=p(e._rev)).error)return o;e._rev_tree=[{pos:r=o.prefix,ids:[i=o.id,s,[]]}]}l.invalidIdError(e._id),e._rev=r+"-"+i;var a,u={metadata:{},data:{}};for(a in e)if(Object.prototype.hasOwnProperty.call(e,a)){var c,f="_"===a[0];if(f&&!d[a])throw(c=g.createError(g.DOC_VALIDATION,a)).message=g.DOC_VALIDATION.message+": "+a,c;f&&!h[a]?u.metadata[a.slice(1)]=e[a]:u.data[a]=e[a]}return u}function c(t,e,n){var r=(e=>{try{return s.atob(e)}catch(e){return{error:g.createError(g.BAD_ARG,"Attachment is not a valid base64 string")}}})(t.data);if(r.error)return n(r.error);t.length=r.length,t.data="blob"===e?s.binaryStringToBlobOrBuffer(r,t.content_type):"base64"===e?s.btoa(r):r,a.binaryMd5(r,function(e){t.digest="md5-"+e,n()})}function f(e,t,n){if(e.stub)return n();var r,i,o;"string"==typeof e.data?c(e,t,n):(r=e,i=t,o=n,a.binaryMd5(r.data,function(e){r.digest="md5-"+e,r.length=r.data.size||r.data.length||0,"binary"===i?s.blobOrBufferToBinaryString(r.data,function(e){r.data=e,o()}):"base64"===i?s.blobOrBufferToBase64(r.data,function(e){r.data=e,o()}):o()}))}function m(e,t,n,r,i,o,s,a){var u,c,f,l;return E.revExists(t.rev_tree,n.metadata.rev)&&!a?(r[i]=n,o()):(c=t.winningRev||E.winningRev(t),u="deleted"in t?t.deleted:E.isDeleted(t,c),l="deleted"in n.metadata?n.metadata.deleted:E.isDeleted(n.metadata),f=/^1-/.test(n.metadata.rev),u&&!l&&a&&f&&((f=n.data)._rev=c,f._id=n.metadata.id,n=v(f,a)),c=E.merge(t.rev_tree,n.metadata.rev_tree[0],e),a&&(u&&l&&"new_leaf"!==c.conflicts||!u&&"new_leaf"!==c.conflicts||u&&!l&&"new_branch"===c.conflicts)?(f=g.createError(g.REV_CONFLICT),r[i]=f,o()):(e=n.metadata.rev,n.metadata.rev_tree=c.tree,n.stemmedRevs=c.stemmedRevs||[],t.rev_map&&(n.metadata.rev_map=t.rev_map),a=E.winningRev(n.metadata),r=u===(l=E.isDeleted(n.metadata,a))?0:u<l?-1:1,void s(n,a,l,e===a?l:E.isDeleted(n.metadata,e),!0,r,i,o)))}n.invalidIdError=l.invalidIdError,n.normalizeDdocFunctionName=l.normalizeDdocFunctionName,n.parseDdocFunctionName=l.parseDdocFunctionName,n.isDeleted=E.isDeleted,n.isLocalId=E.isLocalId,n.allDocsKeysQuery=function(e,o){var t=o.keys,s={offset:o.skip};return Promise.all(t.map(function(i){var t=l.assign({key:i,deleted:"ok"},o);return["limit","skip","keys"].forEach(function(e){delete t[e]}),new Promise(function(n,r){e._allDocs(t,function(e,t){if(e)return r(e);o.update_seq&&void 0!==t.update_seq&&(s.update_seq=t.update_seq),s.total_rows=t.total_rows,n(t.rows[0]||{key:i,error:"not_found"})})})})).then(function(e){return s.rows=e,s})},n.parseDoc=v,n.preprocessAttachments=function(e,o,t){if(!e.length)return t();var s,n=0;function a(){n++,e.length===n&&(s?t(s):t())}e.forEach(function(e){var t,n=e.data&&e.data._attachments?Object.keys(e.data._attachments):[],r=0;if(!n.length)return a();function i(e){s=e,++r===n.length&&a()}for(t in e.data._attachments)e.data._attachments.hasOwnProperty(t)&&f(e.data._attachments[t],o,i)})},n.processDocs=function(f,e,r,l,i,d,h,p,t){f=f||1e3;var v=p.new_edits,o=new u.Map,n=0,s=e.length;function _(){++n===s&&t&&t()}e.forEach(function(e,n){var t;e._id&&E.isLocalId(e._id)?(t=e._deleted?"_removeLocal":"_putLocal",r[t](e,{ctx:i},function(e,t){d[n]=e||t,_()})):(t=e.metadata.id,o.has(t)?(s--,o.get(t).push([e,n])):o.set(t,[[e,n]]))}),o.forEach(function(s,a){var u=0;function c(){(++u<s.length?e:_)()}function e(){var e,t,n,r,i=s[u],o=i[0],i=i[1];l.has(a)?m(f,l.get(a),o,d,i,c,h,v):(e=E.merge([],o.metadata.rev_tree[0],f),o.metadata.rev_tree=e.tree,o.stemmedRevs=e.stemmedRevs||[],e=o,o=i,i=c,n=E.winningRev(e.metadata),r=E.isDeleted(e.metadata,n),"was_delete"in p&&r?(d[o]=g.createError(g.MISSING_DOC,"deleted"),i()):v&&"missing"===e.metadata.rev_tree[0].ids[1].status?(t=g.createError(g.REV_CONFLICT),d[o]=t,i()):h(e,n,r,r,!1,r?0:1,o,i))}e()})},n.updateDoc=m},{10:10,12:12,13:13,14:14,8:8,9:9}],7:[function(e,t,r){var h=e(9),b=e(10),w=e(14),T=e(6),A=e(13),I=e(11),q=e(8);function s(e){return e<65?e-48:e-55}function O(e,t){if("UTF-8"===t)return t=((e,t,n)=>{for(var r="";t<n;)r+=String.fromCharCode(s(e.charCodeAt(t++))<<4|s(e.charCodeAt(t++)));return r})(e,0,e.length),decodeURIComponent(escape(t));for(var n=e,r=0,i=e.length,o="";r<i;)o+=String.fromCharCode(s(n.charCodeAt(r+2))<<12|s(n.charCodeAt(r+3))<<8|s(n.charCodeAt(r))<<4|s(n.charCodeAt(r+1))),r+=4;return o}var x="'document-store'",N="'by-sequence'",R="'attach-store'",L="'local-store'",D="'metadata-store'",C="'attach-seq-store'";function B(e){return delete e._id,delete e._rev,JSON.stringify(e)}function M(e,t,n){return(e=JSON.parse(e))._id=t,e._rev=n,e}function U(e){for(var t="(";e--;)t+="?",e&&(t+=",");return t+")"}function j(e,t,n,r,i){return"SELECT "+e+" FROM "+("string"==typeof t?t:t.join(" JOIN "))+(n?" ON "+n:"")+(r?" WHERE "+("string"==typeof r?r:r.join(" AND ")):"")+(i?" ORDER BY "+i:"")}function F(t,n,r){var i,o;function s(){var e;++i===t.length&&o.length&&(e="SELECT DISTINCT digest AS digest FROM "+C+" WHERE seq IN "+U(o.length),r.executeSql(e,o,function(e,t){for(var n,i=[],r=0;r<t.rows.length;r++)i.push(t.rows.item(r).digest);i.length&&(n="DELETE FROM "+C+" WHERE seq IN ("+o.map(function(){return"?"}).join(",")+")",e.executeSql(n,o,function(e){var t="SELECT digest FROM "+C+" WHERE digest IN ("+i.map(function(){return"?"}).join(",")+")";e.executeSql(t,i,function(t,e){for(var n=new h.Set,r=0;r<e.rows.length;r++)n.add(e.rows.item(r).digest);i.forEach(function(e){n.has(e)||(t.executeSql("DELETE FROM "+C+" WHERE digest=?",[e]),t.executeSql("DELETE FROM "+R+" WHERE digest=?",[e]))})})}))}))}t.length&&(i=0,o=[],t.forEach(function(e){var t="SELECT seq FROM "+N+" WHERE doc_id=? AND rev=?";r.executeSql(t,[n,e],function(e,t){if(!t.rows.length)return s();t=t.rows.item(0).seq;o.push(t),e.executeSql("DELETE FROM "+N+" WHERE seq=?",[t],s)})}))}function k(n){return function(e){w.guardedConsole("error","WebSQL threw an error",e);var t=e&&e.constructor.toString().match(/function ([^(]+)/),t=t&&t[1]||e.type,e=e.target||e.message;n(b.createError(b.WSQ_ERROR,e,t))}}function a(t,e,n,v,r,i,o){var _,s=n.new_edits,a=e.docs.map(function(e){return e._id&&T.isLocalId(e._id)?e:T.parseDoc(e,s,t)}),e=a.filter(function(e){return e.error});if(e.length)return o(e[0]);var u,g=new Array(a.length),E=new h.Map;function c(){if(u)return o(u);i.notify(v._name),o(null,g)}function f(t){var i=[];if(a.forEach(function(t){t.data&&t.data._attachments&&Object.keys(t.data._attachments).forEach(function(e){e=t.data._attachments[e];e.stub&&i.push(e.digest)})}),!i.length)return t();var o,s=0;i.forEach(function(e){var n,r;n=e,r=function(e){e&&!o&&(o=e),++s===i.length&&t(o)},e="SELECT count(*) as cnt FROM "+R+" WHERE digest=?",_.executeSql(e,[n],function(e,t){0===t.rows.item(0).cnt?(t=b.createError(b.MISSING_STUB,"unknown stub attachment with digest "+n),r(t)):r()})})}function l(c,s,e,t,a,n,u,f){function r(){var u=c.data,r=t?1:0,i=u._id,o=u._rev,s=B(u),e="INSERT INTO "+N+" (doc_id, rev, json, deleted) VALUES (?, ?, ?, ?);";function a(e,t){var n=0,r=Object.keys(u._attachments||{});if(!r.length)return t();function i(){return++n===r.length&&t(),!1}for(var o,s,a=0;a<r.length;a++)o=r[a],s=void 0,s="INSERT INTO "+C+" (digest, seq) VALUES (?,?)",o=[u._attachments[o].digest,e],_.executeSql(s,o,i,i)}_.executeSql(e,[i,o,s,r],function(e,t){var n=t.insertId;a(n,function(){p(e,n)})},function(){var e=j("seq",N,null,"doc_id=? AND rev=?");return _.executeSql(e,[i,o],function(e,t){var n=t.rows.item(0).seq,t="UPDATE "+N+" SET json=?, deleted=? WHERE doc_id=? AND rev=?;";e.executeSql(t,[s,r,i,o],function(e){a(n,function(){p(e,n)})})}),!1})}function l(e){i||(e?f(i=e):d===o.length&&r())}var i=null,d=0,o=(c.data._id=c.metadata.id,c.data._rev=c.metadata.rev,Object.keys(c.data._attachments||{}));function h(e){d++,l(e)}function p(e,t){var n=c.metadata.id,r=c.stemmedRevs||[],i=((r=a&&v.auto_compaction?A.compactTree(c.metadata).concat(r):r).length&&F(r,n,e),c.metadata.seq=t,c.metadata.rev),r=(delete c.metadata.rev,a?"UPDATE "+x+" SET json=?, max_seq=?, winningseq=(SELECT seq FROM "+N+" WHERE doc_id="+x+".id AND rev=?) WHERE id=?":"INSERT INTO "+x+" (id, winningseq, max_seq, json) VALUES (?,?,?,?);"),o=I.safeJsonStringify(c.metadata);e.executeSql(r,a?[o,t,s,n]:[n,t,t,o],function(){g[u]={ok:!0,id:c.metadata.id,rev:i},E.set(n,c.metadata),f()})}t&&(c.data._deleted=!0),o.forEach(function(e){var t,n,r,i,o,e=c.data._attachments[e];e.stub?(d++,l()):(t=e.data,delete e.data,e.revpos=parseInt(s,10),e=e.digest,n=e,r=t,i=h,o="SELECT digest FROM "+R+" WHERE digest=?",_.executeSql(o,[n],function(e,t){if(t.rows.length)return i();o="INSERT INTO "+R+" (digest, body, escaped) VALUES (?,?,1)",e.executeSql(o,[n,r.replace(/\u0002/g,"").replace(/\u0001/g,"").replace(/\u0000/g,"")],function(){i()},function(){return i(),!1})}))}),o.length||r()}function d(){T.processDocs(t.revs_limit,a,v,E,_,g,l,n)}T.preprocessAttachments(a,"binary",function(e){if(e)return o(e);r.transaction(function(e){_=e,f(function(e){function r(){++n===a.length&&t()}var t,n;e?u=e:(t=d,a.length?(n=0,a.forEach(function(e){if(e._id&&T.isLocalId(e._id))return r();var n=e.metadata.id;_.executeSql("SELECT json FROM "+x+" WHERE id = ?",[n],function(e,t){t.rows.length&&(t=I.safeJsonParse(t.rows.item(0).json),E.set(n,t)),r()})})):t())})},k(o),c)})}var n=new h.Map;function u(e){var t=n.get(e.name);return t||(t=(e=>{try{return{db:e.websql(e.name,e.version,e.description,e.size)}}catch(e){return{error:e}}})(e),n.set(e.name,t)),t}var P=new w.changesHandler;function W(o,s,a,u,e){var t=Object.keys(o._attachments||{});if(!t.length)return e&&e();var n=0;function c(){++n===t.length&&e&&e()}t.forEach(function(e){var n,r,i,t;s.attachments&&s.include_docs?(r=e,i=(n=o)._attachments[r],t={binary:s.binary,ctx:u},a._getAttachment(n._id,r,i,t,function(e,t){n._attachments[r]=w.assign(w.pick(i,["digest","content_type"]),{data:t}),c()})):(o._attachments[e].stub=!0,c())})}var H="CREATE INDEX IF NOT EXISTS 'by-seq-deleted-idx' ON "+N+" (seq, deleted)",J="CREATE UNIQUE INDEX IF NOT EXISTS 'by-seq-doc-id-rev' ON "+N+" (doc_id, rev)",V="CREATE INDEX IF NOT EXISTS 'doc-winningseq-idx' ON "+x+" (winningseq)",X="CREATE INDEX IF NOT EXISTS 'attach-seq-seq-idx' ON "+C+" (seq)",G="CREATE UNIQUE INDEX IF NOT EXISTS 'attach-seq-digest-idx' ON "+C+" (digest, seq)",z=N+".seq = "+x+".winningseq",Q=N+".seq AS seq, "+N+".deleted AS deleted, "+N+".json AS data, "+N+".rev AS rev, "+x+".json AS metadata";t.exports=function(r,e){var c,g=this,f=null,t="size"in(t=r)?1e6*t.size:"undefined"!=typeof navigator&&/Android/.test(navigator.userAgent)?5e6:1,n=[];if(g._name=r.name,(t=u(w.assign({},r,{version:1,description:r.name,size:t}))).error)return k(e)(t.error);var E=t.db;function i(){w.hasLocalStorage()&&(window.localStorage["_pouch__websqldb_"+g._name]=!0),e(null,g)}function l(t,a){t.executeSql(V),t.executeSql("ALTER TABLE "+N+" ADD COLUMN deleted TINYINT(1) DEFAULT 0",[],function(){t.executeSql(H),t.executeSql("ALTER TABLE "+x+" ADD COLUMN local TINYINT(1) DEFAULT 0",[],function(){t.executeSql("CREATE INDEX IF NOT EXISTS 'doc-store-local-idx' ON "+x+" (local, id)");var e="SELECT "+x+".winningseq AS seq, "+x+".json AS metadata FROM "+N+" JOIN "+x+" ON "+N+".seq = "+x+".winningseq";t.executeSql(e,[],function(e,t){for(var n=[],r=[],i=0;i<t.rows.length;i++){var o=t.rows.item(i),s=o.seq,o=JSON.parse(o.metadata);T.isDeleted(o)&&n.push(s),T.isLocalId(o.id)&&r.push(o.id)}e.executeSql("UPDATE "+x+"SET local = 1 WHERE id IN "+U(r.length),r,function(){e.executeSql("UPDATE "+N+" SET deleted = 1 WHERE seq IN "+U(n.length),n,a)})})})})}function d(t,o){t.executeSql("CREATE TABLE IF NOT EXISTS 'local-store' (id UNIQUE, rev, json)",[],function(){var e="SELECT "+x+".id AS id, "+N+".json AS data FROM "+N+" JOIN "+x+" ON "+N+".seq = "+x+".winningseq WHERE local = 1";t.executeSql(e,[],function(r,e){for(var i=[],t=0;t<e.rows.length;t++)i.push(e.rows.item(t));!function t(){if(!i.length)return o(r);var n=i.shift(),e=JSON.parse(n.data)._rev;r.executeSql("INSERT INTO "+L+" (id, rev, json) VALUES (?,?,?)",[n.id,e,n.data],function(e){e.executeSql("DELETE FROM "+x+" WHERE id=?",[n.id],function(e){e.executeSql("DELETE FROM "+N+" WHERE seq=?",[n.seq],function(){t()})})})}()})})}function h(s,a){function i(o){!function e(){if(!o.length)return a(s);var t=O(o.shift().hex,c),n=t.lastIndexOf("::"),r=t.substring(0,n),n=t.substring(n+2),i="UPDATE "+N+" SET doc_id=?, rev=? WHERE doc_id_rev=?";s.executeSql(i,[r,n,t],function(){e()})}()}var e="ALTER TABLE "+N+" ADD COLUMN doc_id";s.executeSql(e,[],function(e){var t="ALTER TABLE "+N+" ADD COLUMN rev";e.executeSql(t,[],function(e){e.executeSql(J,[],function(e){var t="SELECT hex(doc_id_rev) as hex FROM "+N;e.executeSql(t,[],function(e,t){for(var n=[],r=0;r<t.rows.length;r++)n.push(t.rows.item(r));i(n)})})})})}function p(e,h){function t(e){var t="SELECT COUNT(*) AS cnt FROM "+R;e.executeSql(t,[],function(t,e){if(!e.rows.item(0).cnt)return h(t);var n=0,r=10;!function d(){var e=j(Q+", "+x+".id AS id",[x,N],z,null,x+".id ");e+=" LIMIT "+r+" OFFSET "+n,n+=r,t.executeSql(e,[],function(n,e){if(!e.rows.length)return h(n);for(var t,r={},i=0;i<e.rows.length;i++)for(var o=e.rows.item(i),s=M(o.data,o.id,o.rev),a=Object.keys(s._attachments||{}),u=0;u<a.length;u++){var c=s._attachments[a[u]];c=c.digest,t=o.seq,-1===(c=r[c]=r[c]||[]).indexOf(t)&&c.push(t)}var f=[];if(Object.keys(r).forEach(function(t){r[t].forEach(function(e){f.push([t,e])})}),!f.length)return d();var l=0;f.forEach(function(e){var t="INSERT INTO "+C+" (digest, seq) VALUES (?,?)";n.executeSql(t,e,function(){++l===f.length&&d()})})})}()})}var n="CREATE TABLE IF NOT EXISTS "+C+" (digest, seq INTEGER)";e.executeSql(n,[],function(e){e.executeSql(G,[],function(e){e.executeSql(X,[],t)})})}function v(e,t){var n="ALTER TABLE "+R+" ADD COLUMN escaped TINYINT(1) DEFAULT 0";e.executeSql(n,[],t)}function _(e,n){var t="ALTER TABLE "+x+" ADD COLUMN max_seq INTEGER";e.executeSql(t,[],function(e){var t="UPDATE "+x+" SET max_seq=(SELECT MAX(seq) FROM "+N+" WHERE doc_id=id)";e.executeSql(t,[],function(e){var t="CREATE UNIQUE INDEX IF NOT EXISTS 'doc-max-seq-idx' ON "+x+" (max_seq)";e.executeSql(t,[],n)})})}function m(){for(;0<n.length;)n.pop()(null,f)}function o(t,e){var n,r,i,o,s,a,u;0===e?(n="CREATE TABLE IF NOT EXISTS "+R+" (digest UNIQUE, escaped TINYINT(1), body BLOB)",r="CREATE TABLE IF NOT EXISTS "+C+" (digest, seq INTEGER)",i="CREATE TABLE IF NOT EXISTS "+x+" (id unique, json, winningseq, max_seq INTEGER UNIQUE)",o="CREATE TABLE IF NOT EXISTS "+N+" (seq INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, json, deleted TINYINT(1), doc_id, rev)",t.executeSql(n),t.executeSql("CREATE TABLE IF NOT EXISTS 'local-store' (id UNIQUE, rev, json)"),t.executeSql(r,[],function(){t.executeSql(X),t.executeSql(G)}),t.executeSql(i,[],function(){t.executeSql(V),t.executeSql(o,[],function(){t.executeSql(H),t.executeSql(J),t.executeSql("CREATE TABLE IF NOT EXISTS 'metadata-store' (dbid, db_version INTEGER)",[],function(){var e=[7,f=w.uuid()];t.executeSql("INSERT INTO 'metadata-store' (db_version, dbid) VALUES (?,?)",e,function(){m()})})})})):(s=[l,d,h,p,v,_,function(){e<7&&t.executeSql("UPDATE "+D+" SET db_version = 7");t.executeSql("SELECT dbid FROM 'metadata-store'",[],function(e,t){f=t.rows.item(0).dbid,m()})}],a=e,(u=function(e){s[a-1](e,u),a++})(t))}function y(e,n){var t="SELECT MAX(seq) AS seq FROM "+N;e.executeSql(t,[],function(e,t){t=t.rows.item(0).seq||0;n(t)})}function S(e,n){var t=j("COUNT("+x+".id) AS 'num'",[x,N],z,N+".deleted=0");e.executeSql(t,[],function(e,t){n(t.rows.item(0).num)})}"function"!=typeof E.readTransaction&&(E.readTransaction=E.transaction),E.transaction(function(e){var n;n=function(){e.executeSql("SELECT sql FROM sqlite_master WHERE tbl_name = 'metadata-store'",[],function(e,t){t.rows.length?/db_version/.test(t.rows.item(0).sql)?e.executeSql("SELECT db_version FROM "+D,[],function(e,t){o(e,t.rows.item(0).db_version)}):e.executeSql("ALTER TABLE "+D+" ADD COLUMN db_version INTEGER",[],function(){o(e,1)}):o(e,0)})},e.executeSql('SELECT HEX("a") AS hex',[],function(e,t){t=t.rows.item(0).hex;c=2===t.length?"UTF-8":"UTF-16",n()})},k(e),i),g._remote=!1,g.type=function(){return"websql"},g._id=w.toPromise(function(e){e(null,f)}),g._info=function(e){var t,n;E.readTransaction(function(e){y(e,function(e){t=e}),S(e,function(e){n=e})},k(e),function(){e(null,{doc_count:n,update_seq:t,websql_encoding:c})})},g._bulkDocs=function(e,t,n){a(r,e,t,g,E,P,n)},g._get=function(t,n,r){var i,o,e,s,a,u,c,f,l=n.ctx;if(!l)return E.readTransaction(function(e){g._get(t,w.assign({ctx:e},n),r)});function d(e){r(e,{doc:i,metadata:o,ctx:l})}if(n.rev){if(n.latest)return e=l,s=t,a=n.rev,u=function(e){n.latest=!1,n.rev=e,g._get(t,n,r)},c=d,f=j(Q,[x,N],z,x+".id=?"),void e.executeSql(f,[s],function(e,t){if(!t.rows.length)return n=b.createError(b.MISSING_DOC,"missing"),c(n);var n=t.rows.item(0),t=I.safeJsonParse(n.metadata);u(A.latest(a,t))});e=j(Q,[x,N],x+".id="+N+".doc_id",[N+".doc_id=?",N+".rev=?"]),f=[t,n.rev]}else e=j(Q,[x,N],z,x+".id=?"),f=[t];l.executeSql(e,f,function(e,t){return t.rows.length?(t=t.rows.item(0),o=I.safeJsonParse(t.metadata),t.deleted&&!n.rev?d(b.createError(b.MISSING_DOC,"deleted")):(i=M(t.data,o.id,t.rev),void d())):d(b.createError(b.MISSING_DOC,"missing"))})},g._allDocs=function(l,t){var n,r,i,o,d=[],e="startkey"in l&&l.startkey,s="endkey"in l&&l.endkey,a="key"in l&&l.key,h="keys"in l&&l.keys,u="descending"in l&&l.descending,c="limit"in l?l.limit:-1,f="skip"in l?l.skip:0,p=!1!==l.inclusive_end,v=[],_=[];h?(i=[],o="",h.forEach(function(e){-1===i.indexOf(e)&&(i.push(e),o+="?,")}),o=o.substring(0,o.length-1),_.push(x+".id IN ("+o+")"),v=v.concat(i)):!1!==a?(_.push(x+".id = ?"),v.push(a)):!1===e&&!1===s||(!1!==e&&(_.push(x+".id "+(u?"<=":">=")+" ?"),v.push(e)),!1!==s&&(e=u?">":"<",p&&(e+="="),_.push(x+".id "+e+" ?"),v.push(s)),!1!==a&&(_.push(x+".id = ?"),v.push(a))),h||_.push(N+".deleted = 0"),E.readTransaction(function(e){var t;S(e,function(e){n=e}),l.update_seq&&y(e,function(e){r=e}),0!==c&&(t=j(Q,[x,N],z,_,x+".id "+(u?"DESC":"ASC")),e.executeSql(t+=" LIMIT "+c+" OFFSET "+f,v,function(e,t){for(var n=0,r=t.rows.length;n<r;n++){var i=t.rows.item(n),o=I.safeJsonParse(i.metadata),s=o.id,a=M(i.data,s,i.rev),u=a._rev,c={id:s,key:s,value:{rev:u}};if(l.include_docs&&(c.doc=a,c.doc._rev=u,l.conflicts&&(a=A.collectConflicts(o)).length&&(c.doc._conflicts=a),W(c.doc,l,g,e)),i.deleted){if(!h)continue;c.value.deleted=!0,c.doc=null}if(h)for(var f=h.indexOf(s,f);d[f]=c,-1<(f=h.indexOf(s,f+1))&&f<h.length;);else d.push(c)}h&&h.forEach(function(e,t){d[t]||(d[t]={key:e,error:"not_found"})})}))},k(t),function(){var e={total_rows:n,offset:l.skip,rows:d};l.update_seq&&(e.update_seq=r),t(null,e)})},g._changes=function(u){var e;if((u=w.clone(u)).continuous)return e=g._name+":"+w.uuid(),P.addListener(g._name,e,g,u),P.notify(g._name),{cancel:function(){P.removeListener(g._name,e)}};var t,n,r,i,o,s,c,f,a=u.descending,l=(u.since=u.since&&!a?u.since:0,"limit"in u?u.limit:-1),d=(0===l&&(l=1),[]),h=0;t=x+".json AS metadata, "+x+".max_seq AS maxSeq, "+N+".json AS winningDoc, "+N+".rev AS winningRev ",n=x+" JOIN "+N,r=x+".id="+N+".doc_id AND "+x+".winningseq="+N+".seq",i=["maxSeq > ?"],o=[u.since],u.doc_ids&&(i.push(x+".id IN "+U(u.doc_ids.length)),o=o.concat(u.doc_ids)),s=j(t,n,r,i,"maxSeq "+(a?"DESC":"ASC")),c=w.filterChange(u),u.view||u.filter||(s+=" LIMIT "+l),f=u.since||0,E.readTransaction(function(e){e.executeSql(s,o,function(e,t){function n(e){return function(){u.onChange(e)}}for(var r=0,i=t.rows.length;r<i;r++){var o=t.rows.item(r),s=I.safeJsonParse(o.metadata),a=(f=o.maxSeq,M(o.winningDoc,s.id,o.winningRev)),s=u.processChange(a,s,u),o=(s.seq=o.maxSeq,c(s));if("object"==typeof o)return u.complete(o);if(o&&(h++,u.return_docs&&d.push(s),u.attachments&&u.include_docs?W(a,u,g,e,n(s)):n(s)()),h===l)break}})},k(u.complete),function(){u.continuous||u.complete(null,{results:d,last_seq:f})})},g._close=function(e){e()},g._getAttachment=function(e,t,n,r,i){var o,s=r.ctx,a=n.digest,u=n.content_type,n="SELECT escaped, CASE WHEN escaped = 1 THEN body ELSE HEX(body) END AS body FROM "+R+" WHERE digest=?";s.executeSql(n,[a],function(e,t){t=t.rows.item(0),t=t.escaped?t.body.replace(/\u0001\u0001/g,"\0").replace(/\u0001\u0002/g,"").replace(/\u0002\u0002/g,""):O(t.body,c);o=r.binary?q.binaryStringToBlobOrBuffer(t,u):q.btoa(t),i(null,o)})},g._getRevisionTree=function(n,r){E.readTransaction(function(e){var t="SELECT json AS metadata FROM "+x+" WHERE id = ?";e.executeSql(t,[n],function(e,t){t.rows.length?(t=I.safeJsonParse(t.rows.item(0).metadata),r(null,t.rev_tree)):r(b.createError(b.MISSING_DOC))})})},g._doCompaction=function(r,o,e){if(!o.length)return e();E.transaction(function(e){var t="SELECT json AS metadata FROM "+x+" WHERE id = ?";e.executeSql(t,[r],function(e,t){var t=I.safeJsonParse(t.rows.item(0).metadata),n=(A.traverseRevTree(t.rev_tree,function(e,t,n,r,i){-1!==o.indexOf(t+"-"+n)&&(i.status="missing")}),"UPDATE "+x+" SET json = ? WHERE id = ?");e.executeSql(n,[I.safeJsonStringify(t),r])}),F(o,r,e)},k(e),function(){e()})},g._getLocal=function(n,r){E.readTransaction(function(e){e.executeSql("SELECT json, rev FROM 'local-store' WHERE id=?",[n],function(e,t){t.rows.length?(t=M((t=t.rows.item(0)).json,n,t.rev),r(null,t)):r(b.createError(b.MISSING_DOC))})})},g._putLocal=function(e,r,i){"function"==typeof r&&(i=r,r={}),delete e._revisions;var o,s=e._rev,a=e._id,u=e._rev=s?"0-"+(parseInt(s.split("-")[1],10)+1):"0-1",c=B(e);function t(e){var t,n=s?(t="UPDATE "+L+" SET rev=?, json=? WHERE id=? AND rev=?",[u,c,a,s]):(t="INSERT INTO "+L+" (id, rev, json) VALUES (?,?,?)",[a,u,c]);e.executeSql(t,n,function(e,t){t.rowsAffected?(o={ok:!0,id:a,rev:u},r.ctx&&i(null,o)):i(b.createError(b.REV_CONFLICT))},function(){return i(b.createError(b.REV_CONFLICT)),!1})}r.ctx?t(r.ctx):E.transaction(t,k(i),function(){o&&i(null,o)})},g._removeLocal=function(n,r,i){var o;function e(e){var t=[n._id,n._rev];e.executeSql("DELETE FROM 'local-store' WHERE id=? AND rev=?",t,function(e,t){if(!t.rowsAffected)return i(b.createError(b.MISSING_DOC));o={ok:!0,id:n._id,rev:"0-0"},r.ctx&&i(null,o)})}"function"==typeof r&&(i=r,r={}),r.ctx?e(r.ctx):E.transaction(e,k(i),function(){o&&i(null,o)})},g._destroy=function(e,t){P.removeAllListeners(g._name),E.transaction(function(t){[x,N,R,D,L,C].forEach(function(e){t.executeSql("DROP TABLE IF EXISTS "+e,[])})},k(t),function(){w.hasLocalStorage()&&(delete window.localStorage["_pouch__websqldb_"+g._name],delete window.localStorage[g._name]),t(null,{ok:!0})})}}},{10:10,11:11,13:13,14:14,6:6,8:8,9:9}],8:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0});function r(e){return atob(e)}function i(e){return btoa(e)}function o(t,n){t=t||[],n=n||{};try{return new Blob(t,n)}catch(e){if("TypeError"!==e.name)throw e;for(var r=new("undefined"!=typeof BlobBuilder?BlobBuilder:"undefined"!=typeof MSBlobBuilder?MSBlobBuilder:"undefined"!=typeof MozBlobBuilder?MozBlobBuilder:WebKitBlobBuilder),i=0;i<t.length;i+=1)r.append(t[i]);return r.getBlob(n.type)}}function s(e){for(var t=e.length,n=new ArrayBuffer(t),r=new Uint8Array(n),i=0;i<t;i++)r[i]=e.charCodeAt(i);return n}function a(e,t){return o([s(e)],{type:t})}function u(e,t){var n=new FileReader,r="function"==typeof n.readAsBinaryString;n.onloadend=function(e){e=e.target.result||"";if(r)return t(e);t((e=>{for(var t="",n=new Uint8Array(e),r=n.byteLength,i=0;i<r;i++)t+=String.fromCharCode(n[i]);return t})(e))},r?n.readAsBinaryString(e):n.readAsArrayBuffer(e)}function c(e,t){u(e,function(e){t(e)})}n.atob=r,n.btoa=i,n.base64StringToBlobOrBuffer=function(e,t){return a(r(e),t)},n.binaryStringToArrayBuffer=s,n.binaryStringToBlobOrBuffer=a,n.blob=o,n.blobOrBufferToBase64=function(e,t){c(e,function(e){t(i(e))})},n.blobOrBufferToBinaryString=c,n.readAsArrayBuffer=function(e,t){var n=new FileReader;n.onloadend=function(e){e=e.target.result||new ArrayBuffer(0);t(e)},n.readAsArrayBuffer(e)},n.readAsBinaryString=u,n.typedBuffer=function(){}},{}],9:[function(e,t,n){function r(){this._store={}}function i(e){if(this._store=new r,e&&Array.isArray(e))for(var t=0,n=e.length;t<n;t++)this.add(e[t])}Object.defineProperty(n,"__esModule",{value:!0}),r.prototype.get=function(e){return this._store["$"+e]},r.prototype.set=function(e,t){return this._store["$"+e]=t,!0},r.prototype.has=function(e){return"$"+e in this._store},r.prototype.delete=function(e){var e="$"+e,t=e in this._store;return delete this._store[e],t},r.prototype.forEach=function(e){for(var t=Object.keys(this._store),n=0,r=t.length;n<r;n++){var i=t[n];e(this._store[i],i.substring(1))}},Object.defineProperty(r.prototype,"size",{get:function(){return Object.keys(this._store).length}}),i.prototype.add=function(e){return this._store.set(e,!0)},i.prototype.has=function(e){return this._store.has(e)},i.prototype.forEach=function(n){this._store.forEach(function(e,t){n(t)})},Object.defineProperty(i.prototype,"size",{get:function(){return this._store.size}}),(()=>{var e;return"undefined"!=typeof Symbol&&"undefined"!=typeof Map&&"undefined"!=typeof Set&&(e=Object.getOwnPropertyDescriptor(Map,Symbol.species))&&"get"in e&&Map[Symbol.species]===Map})()?(n.Set=Set,n.Map=Map):(n.Set=i,n.Map=r)},{}],10:[function(e,t,n){function r(e,t,n){Error.call(this,n),this.status=e,this.name=t,this.message=n,this.error=!0}Object.defineProperty(n,"__esModule",{value:!0}),((e=e(5))&&"object"==typeof e&&"default"in e?e.default:e)(r,Error),r.prototype.toString=function(){return JSON.stringify({status:this.status,name:this.name,message:this.message,reason:this.reason})};var e=new r(401,"unauthorized","Name or password is incorrect."),i=new r(400,"bad_request","Missing JSON list of 'docs'"),o=new r(404,"not_found","missing"),s=new r(409,"conflict","Document update conflict"),a=new r(400,"bad_request","_id field must contain a string"),u=new r(412,"missing_id","_id is required for puts"),c=new r(400,"bad_request","Only reserved document ids may start with underscore."),f=new r(412,"precondition_failed","Database not open"),l=new r(500,"unknown_error","Database encountered an unknown error"),d=new r(500,"badarg","Some query argument is invalid"),h=new r(400,"invalid_request","Request was invalid"),p=new r(400,"query_parse_error","Some query parameter is invalid"),v=new r(500,"doc_validation","Bad special document member"),_=new r(400,"bad_request","Something wrong with the request"),g=new r(400,"bad_request","Document must be a JSON object"),E=new r(404,"not_found","Database not found"),m=new r(500,"indexed_db_went_bad","unknown"),y=new r(500,"web_sql_went_bad","unknown"),S=new r(500,"levelDB_went_went_bad","unknown"),b=new r(403,"forbidden","Forbidden by design doc validate_doc_update function"),w=new r(400,"bad_request","Invalid rev format"),T=new r(412,"file_exists","The database could not be created, the file already exists."),A=new r(412,"missing_stub","A pre-existing attachment stub wasn't found"),I=new r(413,"invalid_url","Provided URL is invalid");n.UNAUTHORIZED=e,n.MISSING_BULK_DOCS=i,n.MISSING_DOC=o,n.REV_CONFLICT=s,n.INVALID_ID=a,n.MISSING_ID=u,n.RESERVED_ID=c,n.NOT_OPEN=f,n.UNKNOWN_ERROR=l,n.BAD_ARG=d,n.INVALID_REQUEST=h,n.QUERY_PARSE_ERROR=p,n.DOC_VALIDATION=v,n.BAD_REQUEST=_,n.NOT_AN_OBJECT=g,n.DB_MISSING=E,n.WSQ_ERROR=y,n.LDB_ERROR=S,n.FORBIDDEN=b,n.INVALID_REV=w,n.FILE_EXISTS=T,n.MISSING_STUB=A,n.IDB_ERROR=m,n.INVALID_URL=I,n.createError=function(n,e){function t(e){for(var t in n)"function"!=typeof n[t]&&(this[t]=n[t]);void 0!==e&&(this.reason=e)}return t.prototype=r.prototype,new t(e)},n.generateErrorFromResponse=function(e){var t;return"object"!=typeof e&&(t=e,(e=l).data=t),"error"in e&&"conflict"===e.error&&(e.name="conflict",e.status=409),"name"in e||(e.name=e.error||"unknown"),"status"in e||(e.status=500),"message"in e||(e.message=e.message||e.reason),e}},{5:5}],11:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0});var r=(e=e(21))&&"object"==typeof e&&"default"in e?e.default:e;n.safeJsonParse=function(t){try{return JSON.parse(t)}catch(e){return r.parse(t)}},n.safeJsonStringify=function(t){try{return JSON.stringify(t)}catch(e){return r.stringify(t)}}},{21:21}],12:[function(n,e,r){!function(e){Object.defineProperty(r,"__esModule",{value:!0});var t,d=n(8),h=(t=n(15))&&"object"==typeof t&&"default"in t?t.default:t,p=e.setImmediate||e.setTimeout;function v(t,e,n,r,i){var o;(0<n||r<e.size)&&(n=n,r=r,e=(o=e).webkitSlice?o.webkitSlice(n,r):o.slice(n,r)),d.readAsArrayBuffer(e,function(e){t.append(e),i()})}function _(e,t,n,r,i){(0<n||r<t.length)&&(t=t.substring(n,r)),e.appendBinary(t),i()}r.binaryMd5=function(n,t){var e="string"==typeof n,r=e?n.length:n.size,i=Math.min(32768,r),o=Math.ceil(r/i),s=0,a=new(e?h:h.ArrayBuffer),u=e?_:v;function c(){p(l)}function f(){var e=a.end(!0),e=d.btoa(e);t(e),a.destroy()}function l(){var e=s*i,t=e+i;u(a,n,e,t,++s<o?c:f)}l()},r.stringMd5=function(e){return h.hash(e)}}.call(this,"undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{})},{15:15,8:8}],13:[function(e,t,n){function a(e){for(var t,n,r,i=e.rev_tree.slice();f=i.pop();){var o=f.ids,s=o[2],a=f.pos;if(s.length)for(var u=0,c=s.length;u<c;u++)i.push({pos:a+1,ids:s[u]});else{var f=!!o[1].deleted,o=o[0];t&&!(r!==f?r:n!==a?n<a:t<o)||(t=o,n=a,r=f)}}return n+"-"+t}function h(e,t){for(var n,r=e.slice();n=r.pop();)for(var i=n.pos,o=n.ids,s=o[2],a=t(0===s.length,i,o[0],n.ctx,o[1]),u=0,c=s.length;u<c;u++)r.push({pos:i+1,ids:s[u],ctx:a})}function r(e,t){return e.pos-t.pos}function u(e){var o=[];h(e,function(e,t,n,r,i){e&&o.push({rev:t+"-"+n,pos:t,opts:i})}),o.sort(r).reverse();for(var t=0,n=o.length;t<n;t++)delete o[t].pos;return o}function p(e){for(var t,n=[],r=e.slice();t=r.pop();){var i=t.pos,o=t.ids,s=o[0],a=o[1],u=o[2],o=0===u.length,c=t.history?t.history.slice():[];c.push({id:s,opts:a}),o&&n.push({pos:i+1-c.length,ids:c});for(var f=0,l=u.length;f<l;f++)r.push({pos:i+1,ids:u[f],history:c})}return n.reverse()}function m(e,t){return e.pos-t.pos}function f(e,t,n){n=((e,t,n)=>{for(var r,i=0,o=e.length;i<o;)n(e[r=i+o>>>1],t)<0?i=1+r:o=r;return i})(e,t,n);e.splice(n,0,t)}function v(e,t){for(var n,r,i=t,o=e.length;i<o;i++){var s=e[i],s=[s.id,s.opts,[]];r?(r[2].push(s),r=s):n=r=s}return n}function l(e,t){return e[0]<t[0]?-1:1}function y(e,t){for(var n=[{tree1:e,tree2:t}],r=!1;0<n.length;){var i=n.pop(),o=i.tree1,s=i.tree2;(o[1].status||s[1].status)&&(o[1].status="available"===o[1].status||"available"===s[1].status?"available":"missing");for(var a=0;a<s[2].length;a++)if(o[2][0]){for(var u=!1,c=0;c<o[2].length;c++)o[2][c][0]===s[2][a][0]&&(n.push({tree1:o[2][c],tree2:s[2][a]}),u=!0);u||(r="new_branch",f(o[2],s[2][a],l))}else r="new_leaf",o[2][0]=s[2][a]}return{conflicts:r,tree:e}}function _(e,t,n){var r,i=[],o=!1,s=!1;if(!e.length)return{tree:[t],conflicts:"new_leaf"};for(var a=0,u=e.length;a<u;a++){var c=e[a];if(c.pos===t.pos&&c.ids[0]===t.ids[0])r=y(c.ids,t.ids),i.push({pos:c.pos,ids:r.tree}),o=o||r.conflicts,s=!0;else if(!0!==n){var f=c.pos<t.pos?c:t,l=c.pos<t.pos?t:c,d=l.pos-f.pos,h=[],p=[];for(p.push({ids:f.ids,diff:d,parent:null,parentIdx:null});0<p.length;){var v=p.pop();if(0===v.diff)v.ids[0]===l.ids[0]&&h.push(v);else for(var _=v.ids[2],g=0,E=_.length;g<E;g++)p.push({ids:_[g],diff:v.diff-1,parent:v.ids,parentIdx:g})}d=h[0];d?(r=y(d.ids,l.ids),d.parent[2][d.parentIdx]=r.tree,i.push({pos:f.pos,ids:f.ids}),o=o||r.conflicts,s=!0):i.push(c)}else i.push(c)}return s||i.push(t),i.sort(m),{tree:i,conflicts:o||"internal_node"}}function o(e){return e.ids}Object.defineProperty(n,"__esModule",{value:!0}),n.collectConflicts=function(e){for(var t=a(e),n=u(e.rev_tree),r=[],i=0,o=n.length;i<o;i++){var s=n[i];s.rev===t||s.opts.deleted||r.push(s.rev)}return r},n.collectLeaves=u,n.compactTree=function(e){var o=[];return h(e.rev_tree,function(e,t,n,r,i){"available"!==i.status||e||(o.push(t+"-"+n),i.status="missing")}),o},n.isDeleted=function(e,t){for(var n,r=(t=t||a(e)).substring(t.indexOf("-")+1),i=e.rev_tree.map(o);n=i.pop();){if(n[0]===r)return!!n[1].deleted;i=i.concat(n[2])}},n.isLocalId=function(e){return/^_local/.test(e)},n.merge=function(e,t,n){return e=_(e,t),{tree:(t=((e,t)=>{for(var n,r=p(e),i=0,o=r.length;i<o;i++){var s=r[i],a=s.ids;if(a.length>t)for(var u=u||{},c=a.length-t,f={pos:s.pos+c,ids:v(a,c)},l=0;l<c;l++){var d=s.pos+l+"-"+a[l].id;u[d]=!0}else f={pos:s.pos,ids:v(a,0)};n=n?_(n,f,!0).tree:[f]}return u&&h(n,function(e,t,n){delete u[t+"-"+n]}),{tree:n,revs:u?Object.keys(u):[]}})(e.tree,n)).tree,stemmedRevs:t.revs,conflicts:e.conflicts}},n.revExists=function(e,t){for(var n,r=e.slice(),e=t.split("-"),i=parseInt(e[0],10),o=e[1];n=r.pop();){if(n.pos===i&&n.ids[0]===o)return!0;for(var s=n.ids[2],a=0,u=s.length;a<u;a++)r.push({pos:n.pos+1,ids:s[a]})}return!1},n.rootToLeaf=p,n.traverseRevTree=h,n.winningRev=a,n.latest=function(e,t){for(var n,r=t.rev_tree.slice();n=r.pop();){var i=n.pos,o=n.ids,s=o[0],a=o[1],u=o[2],o=0===u.length,c=n.history?n.history.slice():[];if(c.push({id:s,pos:i,opts:a}),o)for(var f=0,l=c.length;f<l;f++){var d=c[f];if(d.pos+"-"+d.id===e)return i+"-"+s}for(var h=0,p=u.length;h<p;h++)r.push({pos:i+1,ids:u[h],history:c})}throw new Error("Unable to resolve latest revision for id "+t.id+", rev "+e)}},{}],14:[function(e,t,n){function r(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(n,"__esModule",{value:!0});var i=r(e(2)),o=e(9),a=r(e(4)),s=e(3),u=r(e(5)),c=e(10),f=r(e(16)),l=e(12),d=e(14);function h(e){var t,n,r;return e instanceof ArrayBuffer?"function"==typeof(r=e).slice?r.slice(0):(t=new ArrayBuffer(r.byteLength),n=new Uint8Array(t),r=new Uint8Array(r),n.set(r),t):(n=e.size,r=e.type,"function"==typeof e.slice?e.slice(0,n,r):e.webkitSlice(0,n,r))}var p=Function.prototype.toString,v=p.call(Object);function _(e){var t,n,r,i,o;if(!e||"object"!=typeof e)return e;if(Array.isArray(e))for(t=[],n=0,r=e.length;n<r;n++)t[n]=_(e[n]);else{if(e instanceof Date)return e.toISOString();if(i=e,"undefined"!=typeof ArrayBuffer&&i instanceof ArrayBuffer||"undefined"!=typeof Blob&&i instanceof Blob)return h(e);if(i=e,!(null===(i=Object.getPrototypeOf(i))||"function"==typeof(i=i.constructor)&&i instanceof i&&p.call(i)==v))return e;for(n in t={},e)Object.prototype.hasOwnProperty.call(e,n)&&void 0!==(o=_(e[n]))&&(t[n]=o)}return t}function g(t){var n=!1;return i(function(e){if(n)throw new Error("once called more than once");n=!0,t.apply(this,e)})}function E(s){return i(function(i){i=_(i);var o=this,t="function"==typeof i[i.length-1]&&i.pop(),e=new Promise(function(n,r){var e;try{var t=g(function(e,t){e?r(e):n(t)});i.push(t),(e=s.apply(o,i))&&"function"==typeof e.then&&n(e)}catch(e){r(e)}});return t&&e.then(function(e){t(null,e)},t),e})}function m(e,t){for(var n={},r=0,i=t.length;r<i;r++){var o=t[r];o in e&&(n[o]=e[o])}return n}var y;function S(e){return e}function b(e){return[{ok:e}]}try{localStorage.setItem("_pouch_check_localstorage",1),y=!!localStorage.getItem("_pouch_check_localstorage")}catch(e){y=!1}function w(){return y}function T(){var t;s.EventEmitter.call(this),this._listeners={},t=this,y&&addEventListener("storage",function(e){t.emit(e.key)})}function A(e){var t;"undefined"!=typeof console&&"function"==typeof console[e]&&(t=Array.prototype.slice.call(arguments,1),console[e].apply(console,t))}u(T,s.EventEmitter),T.prototype.addListener=function(e,t,n,r){var i,o;function s(){var e;i._listeners[t]&&(o?o="waiting":(o=!0,e=m(r,["style","include_docs","attachments","conflicts","filter","doc_ids","view","since","query_params","binary","return_docs"]),n.changes(e).on("change",function(e){e.seq>r.since&&!r.cancelled&&(r.since=e.seq,r.onChange(e))}).on("complete",function(){"waiting"===o&&a(s),o=!1}).on("error",function(){o=!1})))}this._listeners[t]||(o=!1,(i=this)._listeners[t]=s,this.on(e,s))},T.prototype.removeListener=function(e,t){t in this._listeners&&(s.EventEmitter.prototype.removeListener.call(this,e,this._listeners[t]),delete this._listeners[t])},T.prototype.notifyLocalWindows=function(e){y&&(localStorage[e]="a"===localStorage[e]?"b":"a")},T.prototype.notify=function(e){this.emit(e),this.notifyLocalWindows(e)};e="function"==typeof Object.assign?Object.assign:function(e){for(var t=Object(e),n=1;n<arguments.length;n++){var r=arguments[n];if(null!=r)for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(t[i]=r[i])}return t};u=function(){}.name?function(e){return e.name}:function(e){e=e.toString().match(/^\s*function\s*(?:(\S+)\s*)?\(/);return e&&e[1]?e[1]:""};function I(e){var t;return e?2===(t=e.split("/")).length?t:1===t.length?[e,e]:null:null}var q=["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],O="queryKey",x=/(?:^|&)([^&=]*)=?([^&]*)/g,N=/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/;function R(a,u,c){return new Promise(function(o,s){a.get(u,function(e,t){if(e){if(404!==e.status)return s(e);t={}}var n,r,i,e=t._rev,t=c(t);if(!t)return o({updated:!1,rev:e});t._id=u,t._rev=e,o((r=t,i=c,(n=a).put(r).then(function(e){return{updated:!0,rev:e.rev}},function(e){if(409!==e.status)throw e;return R(n,r._id,i)})))})})}var L=f.v4;n.adapterFun=function(u,c){return E(i(function(r){if(this._closed)return Promise.reject(new Error("database is closed"));if(this._destroyed)return Promise.reject(new Error("database is destroyed"));var i=this,o=i,s=u,e=r;if(o.constructor.listeners("debug").length){for(var t=["api",o.name,s],n=0;n<e.length-1;n++)t.push(e[n]);o.constructor.emit("debug",t);var a=e[e.length-1];e[e.length-1]=function(e,t){var n=(n=["api",o.name,s]).concat(e?["error",e]:["success",t]);o.constructor.emit("debug",n),a(e,t)}}return this.taskqueue.isReady?c.apply(this,r):new Promise(function(t,n){i.taskqueue.addTask(function(e){e?n(e):t(i[u].apply(i,r))})})}))},n.assign=e,n.bulkGetShim=function(s,a,e){var t=a.docs,u=new o.Map,r=(t.forEach(function(e){u.has(e.id)?u.get(e.id).push(e):u.set(e.id,[e])}),u.size),i=0,c=new Array(r);function f(){var n;++i===r&&(n=[],c.forEach(function(t){t.docs.forEach(function(e){n.push({id:t.id,docs:[e]})})}),e(null,{results:n}))}var n=[],l=(u.forEach(function(e,t){n.push(t)}),0);function d(){var e,o;l>=n.length||(e=Math.min(l+6,n.length),e=n.slice(l,e),o=l,e.forEach(function(n,e){var r=o+e,e=u.get(n),t=m(e[0],["atts_since","attachments"]),i=(t.open_revs=e.map(function(e){return e.rev}),t.open_revs=t.open_revs.filter(S),S);0===t.open_revs.length&&(delete t.open_revs,i=b),["revs","attachments","binary","ajax","latest"].forEach(function(e){e in a&&(t[e]=a[e])}),s.get(n,t,function(e,t){e=e?[{error:e}]:i(t);t=e,c[r]={id:n,docs:t},f(),d()})}),l+=e.length)}d()},n.changesHandler=T,n.clone=_,n.defaultBackOff=function(e){var t,n;return t=(e=e)?0:2e3,e=parseInt(e,10)||0,(t=parseInt(t,10))!=t||t<=e?t=(e||1)<<1:t+=1,6e5<t&&(e=3e5,t=6e5),n=Math.random(),~~((t-e)*n+e)},n.explainError=function(e,t){A("info","The above "+e+" is totally normal. "+t)},n.filterChange=function(r){var i={},o=r.filter&&"function"==typeof r.filter;return i.query=r.query_params,function(e){e.doc||(e.doc={});var t=o&&((t,e,n)=>{try{return!t(e,n)}catch(e){t="Filter function threw: "+e.toString();return c.createError(c.BAD_REQUEST,t)}})(r.filter,e.doc,i);if("object"==typeof t)return t;if(t)return!1;if(r.include_docs){if(!r.attachments)for(var n in e.doc._attachments)e.doc._attachments.hasOwnProperty(n)&&(e.doc._attachments[n].stub=!0)}else delete e.doc;return!0}},n.flatten=function(e){for(var t=[],n=0,r=e.length;n<r;n++)t=t.concat(e[n]);return t},n.functionName=u,n.guardedConsole=A,n.hasLocalStorage=w,n.invalidIdError=function(e){var t;if(e?"string"!=typeof e?t=c.createError(c.INVALID_ID):/^_/.test(e)&&!/^_(design|local)/.test(e)&&(t=c.createError(c.RESERVED_ID)):t=c.createError(c.MISSING_ID),t)throw t},n.isRemote=function(e){return"boolean"==typeof e._remote?e._remote:"function"==typeof e.type&&(A("warn","db.type() is deprecated and will be removed in a future version of PouchDB"),"http"===e.type())},n.listenerCount=function(e,t){return"listenerCount"in e?e.listenerCount(t):s.EventEmitter.listenerCount(e,t)},n.nextTick=a,n.normalizeDdocFunctionName=function(e){return(e=I(e))?e.join("/"):null},n.once=g,n.parseDdocFunctionName=I,n.parseUri=function(e){for(var t=N.exec(e),r={},n=14;n--;){var i=q[n],o=t[n]||"",s=-1!==["user","password"].indexOf(i);r[i]=s?decodeURIComponent(o):o}return r[O]={},r[q[12]].replace(x,function(e,t,n){t&&(r[O][t]=n)}),r},n.pick=m,n.rev=function(e,t){return e=d.clone(e),t?(delete e._rev_tree,l.stringMd5(JSON.stringify(e))):f.v4().replace(/-/g,"").toLowerCase()},n.scopeEval=function(e,t){var n,r=[],i=[];for(n in t)t.hasOwnProperty(n)&&(r.push(n),i.push(t[n]));return r.push(e),Function.apply(null,r).apply(null,i)},n.toPromise=E,n.upsert=R,n.uuid=L},{10:10,12:12,14:14,16:16,2:2,3:3,4:4,5:5,9:9}],15:[function(e,t,n){function r(i){var r=["0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f"];function u(e,t){var n=e[0],r=e[1],i=e[2],o=e[3],r=((r+=((i=((i+=((o=((o+=((n=((n+=(r&i|~r&o)+t[0]-680876936|0)<<7|n>>>25)+r|0)&r|~n&i)+t[1]-389564586|0)<<12|o>>>20)+n|0)&n|~o&r)+t[2]+606105819|0)<<17|i>>>15)+o|0)&o|~i&n)+t[3]-1044525330|0)<<22|r>>>10)+i|0;r=((r+=((i=((i+=((o=((o+=((n=((n+=(r&i|~r&o)+t[4]-176418897|0)<<7|n>>>25)+r|0)&r|~n&i)+t[5]+1200080426|0)<<12|o>>>20)+n|0)&n|~o&r)+t[6]-1473231341|0)<<17|i>>>15)+o|0)&o|~i&n)+t[7]-45705983|0)<<22|r>>>10)+i|0,r=((r+=((i=((i+=((o=((o+=((n=((n+=(r&i|~r&o)+t[8]+1770035416|0)<<7|n>>>25)+r|0)&r|~n&i)+t[9]-1958414417|0)<<12|o>>>20)+n|0)&n|~o&r)+t[10]-42063|0)<<17|i>>>15)+o|0)&o|~i&n)+t[11]-1990404162|0)<<22|r>>>10)+i|0,r=((r+=((i=((i+=((o=((o+=((n=((n+=(r&i|~r&o)+t[12]+1804603682|0)<<7|n>>>25)+r|0)&r|~n&i)+t[13]-40341101|0)<<12|o>>>20)+n|0)&n|~o&r)+t[14]-1502002290|0)<<17|i>>>15)+o|0)&o|~i&n)+t[15]+1236535329|0)<<22|r>>>10)+i|0,r=((r+=((i=((i+=((o=((o+=((n=((n+=(r&o|i&~o)+t[1]-165796510|0)<<5|n>>>27)+r|0)&i|r&~i)+t[6]-1069501632|0)<<9|o>>>23)+n|0)&r|n&~r)+t[11]+643717713|0)<<14|i>>>18)+o|0)&n|o&~n)+t[0]-373897302|0)<<20|r>>>12)+i|0,r=((r+=((i=((i+=((o=((o+=((n=((n+=(r&o|i&~o)+t[5]-701558691|0)<<5|n>>>27)+r|0)&i|r&~i)+t[10]+38016083|0)<<9|o>>>23)+n|0)&r|n&~r)+t[15]-660478335|0)<<14|i>>>18)+o|0)&n|o&~n)+t[4]-405537848|0)<<20|r>>>12)+i|0,r=((r+=((i=((i+=((o=((o+=((n=((n+=(r&o|i&~o)+t[9]+568446438|0)<<5|n>>>27)+r|0)&i|r&~i)+t[14]-1019803690|0)<<9|o>>>23)+n|0)&r|n&~r)+t[3]-187363961|0)<<14|i>>>18)+o|0)&n|o&~n)+t[8]+1163531501|0)<<20|r>>>12)+i|0,r=((r+=((i=((i+=((o=((o+=((n=((n+=(r&o|i&~o)+t[13]-1444681467|0)<<5|n>>>27)+r|0)&i|r&~i)+t[2]-51403784|0)<<9|o>>>23)+n|0)&r|n&~r)+t[7]+1735328473|0)<<14|i>>>18)+o|0)&n|o&~n)+t[12]-1926607734|0)<<20|r>>>12)+i|0,r=((r+=((i=((i+=((o=((o+=((n=((n+=(r^i^o)+t[5]-378558|0)<<4|n>>>28)+r|0)^r^i)+t[8]-2022574463|0)<<11|o>>>21)+n|0)^n^r)+t[11]+1839030562|0)<<16|i>>>16)+o|0)^o^n)+t[14]-35309556|0)<<23|r>>>9)+i|0,r=((r+=((i=((i+=((o=((o+=((n=((n+=(r^i^o)+t[1]-1530992060|0)<<4|n>>>28)+r|0)^r^i)+t[4]+1272893353|0)<<11|o>>>21)+n|0)^n^r)+t[7]-1