UNPKG

184 kBJavaScriptView Raw
1!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(require("@firebase/app")):"function"==typeof define&&define.amd?define(["@firebase/app"],e):e((t=t||self).firebase)}(this,function(Hi){"use strict";try{(function(){Hi=Hi&&Hi.hasOwnProperty("default")?Hi.default:Hi;var r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};function t(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var u=function(){return(u=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var i in e=arguments[n])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t}).apply(this,arguments)};function e(n,r){var i,o,s,t,a={label:0,sent:function(){if(1&s[0])throw s[1];return s[1]},trys:[],ops:[]};return t={next:e(0),throw:e(1),return:e(2)},"function"==typeof Symbol&&(t[Symbol.iterator]=function(){return this}),t;function e(e){return function(t){return function(e){if(i)throw new TypeError("Generator is already executing.");for(;a;)try{if(i=1,o&&(s=2&e[0]?o.return:e[0]?o.throw||((s=o.return)&&s.call(o),0):o.next)&&!(s=s.call(o,e[1])).done)return s;switch(o=0,s&&(e=[2&e[0],s.value]),e[0]){case 0:case 1:s=e;break;case 4:return a.label++,{value:e[1],done:!1};case 5:a.label++,o=e[1],e=[0];continue;case 7:e=a.ops.pop(),a.trys.pop();continue;default:if(!(s=0<(s=a.trys).length&&s[s.length-1])&&(6===e[0]||2===e[0])){a=0;continue}if(3===e[0]&&(!s||e[1]>s[0]&&e[1]<s[3])){a.label=e[1];break}if(6===e[0]&&a.label<s[1]){a.label=s[1],s=e;break}if(s&&a.label<s[2]){a.label=s[2],a.ops.push(e);break}s[2]&&a.ops.pop(),a.trys.pop();continue}e=r.call(n,a)}catch(t){e=[6,t],o=0}finally{i=s=0}if(5&e[0])throw e[1];return{value:e[0]?e[1]:void 0,done:!0}}([e,t])}}}function f(t){var e="function"==typeof Symbol&&t[Symbol.iterator],n=0;return e?e.call(t):{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}}}function _(t,e){var n="function"==typeof Symbol&&t[Symbol.iterator];if(!n)return t;var r,i,o=n.call(t),s=[];try{for(;(void 0===e||0<e--)&&!(r=o.next()).done;)s.push(r.value)}catch(t){i={error:t}}finally{try{r&&!r.done&&(n=o.return)&&n.call(o)}finally{if(i)throw i.error}}return s}function o(){for(var t=[],e=0;e<arguments.length;e++)t=t.concat(_(arguments[e]));return t}function s(t){for(var e=[],n=0,r=0;r<t.length;r++){var i=t.charCodeAt(r);i<128?e[n++]=i:(i<2048?e[n++]=i>>6|192:(55296==(64512&i)&&r+1<t.length&&56320==(64512&t.charCodeAt(r+1))?(i=65536+((1023&i)<<10)+(1023&t.charCodeAt(++r)),e[n++]=i>>18|240,e[n++]=i>>12&63|128):e[n++]=i>>12|224,e[n++]=i>>6&63|128),e[n++]=63&i|128)}return e}function a(t){try{return l.decodeString(t,!0)}catch(t){console.error("base64Decode failed: ",t)}return null}var h={NODE_CLIENT:!1,NODE_ADMIN:!1,SDK_VERSION:"${JSCORE_VERSION}"},C=function(t,e){if(!t)throw c(e)},c=function(t){return new Error("Firebase Database ("+h.SDK_VERSION+") INTERNAL ASSERT FAILED: "+t)},l={byteToCharMap_:null,charToByteMap_:null,byteToCharMapWebSafe_:null,charToByteMapWebSafe_:null,ENCODED_VALS_BASE:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",get ENCODED_VALS(){return this.ENCODED_VALS_BASE+"+/="},get ENCODED_VALS_WEBSAFE(){return this.ENCODED_VALS_BASE+"-_."},HAS_NATIVE_SUPPORT:"function"==typeof atob,encodeByteArray:function(t,e){if(!Array.isArray(t))throw Error("encodeByteArray takes an array as a parameter");this.init_();for(var n=e?this.byteToCharMapWebSafe_:this.byteToCharMap_,r=[],i=0;i<t.length;i+=3){var o=t[i],s=i+1<t.length,a=s?t[i+1]:0,h=i+2<t.length,l=h?t[i+2]:0,u=o>>2,c=(3&o)<<4|a>>4,p=(15&a)<<2|l>>6,d=63&l;h||(d=64,s||(p=64)),r.push(n[u],n[c],n[p],n[d])}return r.join("")},encodeString:function(t,e){return this.HAS_NATIVE_SUPPORT&&!e?btoa(t):this.encodeByteArray(s(t),e)},decodeString:function(t,e){return this.HAS_NATIVE_SUPPORT&&!e?atob(t):function(t){for(var e=[],n=0,r=0;n<t.length;){var i=t[n++];if(i<128)e[r++]=String.fromCharCode(i);else if(191<i&&i<224){var o=t[n++];e[r++]=String.fromCharCode((31&i)<<6|63&o)}else if(239<i&&i<365){var s=((7&i)<<18|(63&(o=t[n++]))<<12|(63&(a=t[n++]))<<6|63&t[n++])-65536;e[r++]=String.fromCharCode(55296+(s>>10)),e[r++]=String.fromCharCode(56320+(1023&s))}else{o=t[n++];var a=t[n++];e[r++]=String.fromCharCode((15&i)<<12|(63&o)<<6|63&a)}}return e.join("")}(this.decodeStringToByteArray(t,e))},decodeStringToByteArray:function(t,e){this.init_();for(var n=e?this.charToByteMapWebSafe_:this.charToByteMap_,r=[],i=0;i<t.length;){var o=n[t.charAt(i++)],s=i<t.length?n[t.charAt(i)]:0,a=++i<t.length?n[t.charAt(i)]:64,h=++i<t.length?n[t.charAt(i)]:64;if(++i,null==o||null==s||null==a||null==h)throw Error();var l=o<<2|s>>4;if(r.push(l),64!==a){var u=s<<4&240|a>>2;if(r.push(u),64!==h){var c=a<<6&192|h;r.push(c)}}}return r},init_:function(){if(!this.byteToCharMap_){this.byteToCharMap_={},this.charToByteMap_={},this.byteToCharMapWebSafe_={},this.charToByteMapWebSafe_={};for(var t=0;t<this.ENCODED_VALS.length;t++)this.byteToCharMap_[t]=this.ENCODED_VALS.charAt(t),this.charToByteMap_[this.byteToCharMap_[t]]=t,this.byteToCharMapWebSafe_[t]=this.ENCODED_VALS_WEBSAFE.charAt(t),(this.charToByteMapWebSafe_[this.byteToCharMapWebSafe_[t]]=t)>=this.ENCODED_VALS_BASE.length&&(this.charToByteMap_[this.ENCODED_VALS_WEBSAFE.charAt(t)]=t,this.charToByteMapWebSafe_[this.ENCODED_VALS.charAt(t)]=t)}}};function n(t){return function t(e,n){if(!(n instanceof Object))return n;switch(n.constructor){case Date:var r=n;return new Date(r.getTime());case Object:void 0===e&&(e={});break;case Array:e=[];break;default:return n}for(var i in n)n.hasOwnProperty(i)&&(e[i]=t(e[i],n[i]));return e}(void 0,t)}var p=(i.prototype.wrapCallback=function(n){var r=this;return function(t,e){t?r.reject(t):r.resolve(e),"function"==typeof n&&(r.promise.catch(function(){}),1===n.length?n(t):n(t,e))}},i);function i(){var n=this;this.reject=function(){},this.resolve=function(){},this.promise=new Promise(function(t,e){n.resolve=t,n.reject=e})}function d(){return"undefined"!=typeof window&&!!(window.cordova||window.phonegap||window.PhoneGap)&&/ios|iphone|ipod|ipad|android|blackberry|iemobile/i.test("undefined"!=typeof navigator&&"string"==typeof navigator.userAgent?navigator.userAgent:"")}function y(){return!0===h.NODE_ADMIN}var v,g=(t(m,v=Error),m);function m(t,e){var n=v.call(this,e)||this;return n.code=t,n.name="FirebaseError",Object.setPrototypeOf(n,m.prototype),Error.captureStackTrace&&Error.captureStackTrace(n,E.prototype.create),n}var E=(w.prototype.create=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];for(var r=e[0]||{},i=this.service+"/"+t,o=this.errors[t],s=o?function(t,r){return t.replace(b,function(t,e){var n=r[e];return null!=n?n.toString():"<"+e+"?>"})}(o,r):"Error",a=this.serviceName+": "+s+" ("+i+").",h=new g(i,a),l=0,u=Object.keys(r);l<u.length;l++){var c=u[l];"_"!==c.slice(-1)&&(c in h&&console.warn('Overwriting FirebaseError base field "'+c+'" can cause unexpected behavior.'),h[c]=r[c])}return h},w);function w(t,e,n){this.service=t,this.serviceName=e,this.errors=n}var b=/\{\$([^}]+)}/g;function S(t){return JSON.parse(t)}function T(t){return JSON.stringify(t)}function I(t){var e={},n={},r={},i="";try{var o=t.split(".");e=S(a(o[0])||""),n=S(a(o[1])||""),i=o[2],r=n.d||{},delete n.d}catch(t){}return{header:e,claims:n,data:r,signature:i}}function N(t,e){return Object.prototype.hasOwnProperty.call(t,e)}function R(t,e){return Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0}function P(t){for(var e in t)if(Object.prototype.hasOwnProperty.call(t,e))return!1;return!0}function D(t,e,n){var r={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(r[i]=e.call(n,t[i],i,t));return r}var O=(x.prototype.reset=function(){this.chain_[0]=1732584193,this.chain_[1]=4023233417,this.chain_[2]=2562383102,this.chain_[3]=271733878,this.chain_[4]=3285377520,this.inbuf_=0,this.total_=0},x.prototype.compress_=function(t,e){e=e||0;var n=this.W_;if("string"==typeof t)for(var r=0;r<16;r++)n[r]=t.charCodeAt(e)<<24|t.charCodeAt(e+1)<<16|t.charCodeAt(e+2)<<8|t.charCodeAt(e+3),e+=4;else for(r=0;r<16;r++)n[r]=t[e]<<24|t[e+1]<<16|t[e+2]<<8|t[e+3],e+=4;for(r=16;r<80;r++){var i=n[r-3]^n[r-8]^n[r-14]^n[r-16];n[r]=4294967295&(i<<1|i>>>31)}var o,s,a=this.chain_[0],h=this.chain_[1],l=this.chain_[2],u=this.chain_[3],c=this.chain_[4];for(r=0;r<80;r++)s=r<40?r<20?(o=u^h&(l^u),1518500249):(o=h^l^u,1859775393):r<60?(o=h&l|u&(h|l),2400959708):(o=h^l^u,3395469782),i=(a<<5|a>>>27)+o+c+s+n[r]&4294967295,c=u,u=l,l=4294967295&(h<<30|h>>>2),h=a,a=i;this.chain_[0]=this.chain_[0]+a&4294967295,this.chain_[1]=this.chain_[1]+h&4294967295,this.chain_[2]=this.chain_[2]+l&4294967295,this.chain_[3]=this.chain_[3]+u&4294967295,this.chain_[4]=this.chain_[4]+c&4294967295},x.prototype.update=function(t,e){if(null!=t){void 0===e&&(e=t.length);for(var n=e-this.blockSize,r=0,i=this.buf_,o=this.inbuf_;r<e;){if(0===o)for(;r<=n;)this.compress_(t,r),r+=this.blockSize;if("string"==typeof t){for(;r<e;)if(i[o]=t.charCodeAt(r),++r,++o===this.blockSize){this.compress_(i),o=0;break}}else for(;r<e;)if(i[o]=t[r],++r,++o===this.blockSize){this.compress_(i),o=0;break}}this.inbuf_=o,this.total_+=e}},x.prototype.digest=function(){var t=[],e=8*this.total_;this.inbuf_<56?this.update(this.pad_,56-this.inbuf_):this.update(this.pad_,this.blockSize-(this.inbuf_-56));for(var n=this.blockSize-1;56<=n;n--)this.buf_[n]=255&e,e/=256;this.compress_(this.buf_);var r=0;for(n=0;n<5;n++)for(var i=24;0<=i;i-=8)t[r]=this.chain_[n]>>i&255,++r;return t},x);function x(){this.chain_=[],this.buf_=[],this.W_=[],this.pad_=[],this.inbuf_=0,this.total_=0,this.blockSize=64,this.pad_[0]=128;for(var t=1;t<this.blockSize;++t)this.pad_[t]=0;this.reset()}function k(t,e,n,r){var i;if(r<e?i="at least "+e:n<r&&(i=0===n?"none":"no more than "+n),i)throw new Error(t+" failed: Was called with "+r+(1===r?" argument.":" arguments.")+" Expects "+i+".")}function F(t,e,n){var r="";switch(e){case 1:r=n?"first":"First";break;case 2:r=n?"second":"Second";break;case 3:r=n?"third":"Third";break;case 4:r=n?"fourth":"Fourth";break;default:throw new Error("errorPrefix called with argumentNumber > 4. Need to update it?")}var i=t+" failed: ";return i+=r+" argument "}function A(t,e,n,r){if((!r||n)&&"function"!=typeof n)throw new Error(F(t,e,r)+"must be a valid function.")}function L(t,e,n,r){if((!r||n)&&("object"!=typeof n||null===n))throw new Error(F(t,e,r)+"must be a valid context object.")}function M(t){for(var e=0,n=0;n<t.length;n++){var r=t.charCodeAt(n);r<128?e++:r<2048?e+=2:55296<=r&&r<=56319?(e+=4,n++):e+=3}return e}var W,Q;function q(){for(var t=0,e=0,n=arguments.length;e<n;e++)t+=arguments[e].length;var r=Array(t),i=0;for(e=0;e<n;e++)for(var o=arguments[e],s=0,a=o.length;s<a;s++,i++)r[i]=o[s];return r}(Q=W=W||{})[Q.DEBUG=0]="DEBUG",Q[Q.VERBOSE=1]="VERBOSE",Q[Q.INFO=2]="INFO",Q[Q.WARN=3]="WARN",Q[Q.ERROR=4]="ERROR",Q[Q.SILENT=5]="SILENT";function U(t,e){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];if(!(e<t.logLevel)){var i=(new Date).toISOString();switch(e){case W.DEBUG:case W.VERBOSE:console.log.apply(console,q(["["+i+"] "+t.name+":"],n));break;case W.INFO:console.info.apply(console,q(["["+i+"] "+t.name+":"],n));break;case W.WARN:console.warn.apply(console,q(["["+i+"] "+t.name+":"],n));break;case W.ERROR:console.error.apply(console,q(["["+i+"] "+t.name+":"],n));break;default:throw new Error("Attempted to log a message with an invalid logType (value: "+e+")")}}}var V=W.INFO,H=(Object.defineProperty(B.prototype,"logLevel",{get:function(){return this._logLevel},set:function(t){if(!(t in W))throw new TypeError("Invalid value assigned to `logLevel`");this._logLevel=t},enumerable:!0,configurable:!0}),Object.defineProperty(B.prototype,"logHandler",{get:function(){return this._logHandler},set:function(t){if("function"!=typeof t)throw new TypeError("Value assigned to `logHandler` must be a function");this._logHandler=t},enumerable:!0,configurable:!0}),B.prototype.debug=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this._logHandler.apply(this,q([this,W.DEBUG],t))},B.prototype.log=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this._logHandler.apply(this,q([this,W.VERBOSE],t))},B.prototype.info=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this._logHandler.apply(this,q([this,W.INFO],t))},B.prototype.warn=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this._logHandler.apply(this,q([this,W.WARN],t))},B.prototype.error=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this._logHandler.apply(this,q([this,W.ERROR],t))},B);function B(t){this.name=t,this._logLevel=V,this._logHandler=U}var j=(K.prototype.set=function(t,e){null==e?this.domStorage_.removeItem(this.prefixedName_(t)):this.domStorage_.setItem(this.prefixedName_(t),T(e))},K.prototype.get=function(t){var e=this.domStorage_.getItem(this.prefixedName_(t));return null==e?null:S(e)},K.prototype.remove=function(t){this.domStorage_.removeItem(this.prefixedName_(t))},K.prototype.prefixedName_=function(t){return this.prefix_+t},K.prototype.toString=function(){return this.domStorage_.toString()},K);function K(t){this.domStorage_=t,this.prefix_="firebase:"}var Y=(z.prototype.set=function(t,e){null==e?delete this.cache_[t]:this.cache_[t]=e},z.prototype.get=function(t){return N(this.cache_,t)?this.cache_[t]:null},z.prototype.remove=function(t){delete this.cache_[t]},z);function z(){this.cache_={},this.isInMemoryStorage=!0}function G(t){try{if("undefined"!=typeof window&&void 0!==window[t]){var e=window[t];return e.setItem("firebase:sentinel","cache"),e.removeItem("firebase:sentinel"),new j(e)}}catch(t){}return new Y}function X(t){var e=function(t){for(var e=[],n=0,r=0;r<t.length;r++){var i=t.charCodeAt(r);if(55296<=i&&i<=56319){var o=i-55296;C(++r<t.length,"Surrogate pair missing trail surrogate."),i=65536+(o<<10)+(t.charCodeAt(r)-56320)}i<128?e[n++]=i:(i<2048?e[n++]=i>>6|192:(i<65536?e[n++]=i>>12|224:(e[n++]=i>>18|240,e[n++]=i>>12&63|128),e[n++]=i>>6&63|128),e[n++]=63&i|128)}return e}(t),n=new O;n.update(e);var r=n.digest();return l.encodeByteArray(r)}function $(t,e){C(!e||!0===t||!1===t,"Can't turn on custom loggers persistently."),!0===t?(ut.logLevel=W.VERBOSE,ft=ut.log.bind(ut),e&&lt.set("logging_enabled",!0)):"function"==typeof t?ft=t:(ft=null,lt.remove("logging_enabled"))}function J(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];if(!0===_t&&(_t=!1,null===ft&&!0===lt.get("logging_enabled")&&$(!0)),ft){var n=dt.apply(null,t);ft(n)}}function Z(n){return function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];J.apply(void 0,o([n],t))}}function tt(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n="FIREBASE INTERNAL ERROR: "+dt.apply(void 0,o(t));ut.error(n)}function et(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n="FIREBASE FATAL ERROR: "+dt.apply(void 0,o(t));throw ut.error(n),new Error(n)}function nt(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n="FIREBASE WARNING: "+dt.apply(void 0,o(t));ut.warn(n)}function rt(t){return"number"==typeof t&&(t!=t||t==Number.POSITIVE_INFINITY||t==Number.NEGATIVE_INFINITY)}function it(t,e){return t===e?0:t<e?-1:1}function ot(t,e){if(e&&t in e)return e[t];throw new Error("Missing required key ("+t+") in object: "+T(e))}function st(t,e){var n=t.length;if(n<=e)return[t];for(var r=[],i=0;i<n;i+=e)n<i+e?r.push(t.substring(i,n)):r.push(t.substring(i,i+e));return r}var at,ht=G("localStorage"),lt=G("sessionStorage"),ut=new H("@firebase/database"),ct="FIREBASE_DATABASE_EMULATOR_HOST",pt=(at=1,function(){return at++}),dt=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];for(var n="",r=0;r<t.length;r++)Array.isArray(t[r])||t[r]&&"object"==typeof t[r]&&"number"==typeof t[r].length?n+=dt.apply(null,t[r]):"object"==typeof t[r]?n+=T(t[r]):n+=t[r],n+=" ";return n},ft=null,_t=!0,yt="[MIN_NAME]",vt="[MAX_NAME]",gt=function(t,e){if(t===e)return 0;if(t===yt||e===vt)return-1;if(e===yt||t===vt)return 1;var n=Tt(t),r=Tt(e);return null!==n?null!==r?n-r==0?t.length-e.length:n-r:-1:null!==r?1:t<e?-1:1},mt=function(t){if("object"!=typeof t||null===t)return T(t);var e=[];for(var n in t)e.push(n);e.sort();for(var r="{",i=0;i<e.length;i++)0!==i&&(r+=","),r+=T(e[i]),r+=":",r+=mt(t[e[i]]);return r+="}"};function Ct(t,e){for(var n in t)t.hasOwnProperty(n)&&e(n,t[n])}function Et(t){var e,n,r,i,o,s,a;for(C(!rt(t),"Invalid JSON number"),0===t?e=1/t==-1/(r=n=0)?1:0:(e=t<0,r=(t=Math.abs(t))>=Math.pow(2,-1022)?(n=(i=Math.min(Math.floor(Math.log(t)/Math.LN2),1023))+1023,Math.round(t*Math.pow(2,52-i)-Math.pow(2,52))):(n=0,Math.round(t/Math.pow(2,-1074)))),s=[],o=52;o;o-=1)s.push(r%2?1:0),r=Math.floor(r/2);for(o=11;o;o-=1)s.push(n%2?1:0),n=Math.floor(n/2);s.push(e?1:0),s.reverse(),a=s.join("");var h="";for(o=0;o<64;o+=8){var l=parseInt(a.substr(o,8),2).toString(16);1===l.length&&(l="0"+l),h+=l}return h.toLowerCase()}function wt(t){try{t()}catch(e){setTimeout(function(){var t=e.stack||"";throw nt("Exception was thrown by user callback.",t),e},Math.floor(0))}}function bt(t,e){var n=setTimeout(t,e);return"object"==typeof n&&n.unref&&n.unref(),n}var St=new RegExp("^-?(0*)\\d{1,10}$"),Tt=function(t){if(St.test(t)){var e=Number(t);if(-2147483648<=e&&e<=2147483647)return e}return null},It=(Object.defineProperty(Nt,"Empty",{get:function(){return new Nt("")},enumerable:!0,configurable:!0}),Nt.prototype.getFront=function(){return this.pieceNum_>=this.pieces_.length?null:this.pieces_[this.pieceNum_]},Nt.prototype.getLength=function(){return this.pieces_.length-this.pieceNum_},Nt.prototype.popFront=function(){var t=this.pieceNum_;return t<this.pieces_.length&&t++,new Nt(this.pieces_,t)},Nt.prototype.getBack=function(){return this.pieceNum_<this.pieces_.length?this.pieces_[this.pieces_.length-1]:null},Nt.prototype.toString=function(){for(var t="",e=this.pieceNum_;e<this.pieces_.length;e++)""!==this.pieces_[e]&&(t+="/"+this.pieces_[e]);return t||"/"},Nt.prototype.toUrlEncodedString=function(){for(var t="",e=this.pieceNum_;e<this.pieces_.length;e++)""!==this.pieces_[e]&&(t+="/"+encodeURIComponent(String(this.pieces_[e])));return t||"/"},Nt.prototype.slice=function(t){return void 0===t&&(t=0),this.pieces_.slice(this.pieceNum_+t)},Nt.prototype.parent=function(){if(this.pieceNum_>=this.pieces_.length)return null;for(var t=[],e=this.pieceNum_;e<this.pieces_.length-1;e++)t.push(this.pieces_[e]);return new Nt(t,0)},Nt.prototype.child=function(t){for(var e=[],n=this.pieceNum_;n<this.pieces_.length;n++)e.push(this.pieces_[n]);if(t instanceof Nt)for(n=t.pieceNum_;n<t.pieces_.length;n++)e.push(t.pieces_[n]);else{var r=t.split("/");for(n=0;n<r.length;n++)0<r[n].length&&e.push(r[n])}return new Nt(e,0)},Nt.prototype.isEmpty=function(){return this.pieceNum_>=this.pieces_.length},Nt.relativePath=function(t,e){var n=t.getFront(),r=e.getFront();if(null===n)return e;if(n===r)return Nt.relativePath(t.popFront(),e.popFront());throw new Error("INTERNAL ERROR: innerPath ("+e+") is not within outerPath ("+t+")")},Nt.comparePaths=function(t,e){for(var n=t.slice(),r=e.slice(),i=0;i<n.length&&i<r.length;i++){var o=gt(n[i],r[i]);if(0!==o)return o}return n.length===r.length?0:n.length<r.length?-1:1},Nt.prototype.equals=function(t){if(this.getLength()!==t.getLength())return!1;for(var e=this.pieceNum_,n=t.pieceNum_;e<=this.pieces_.length;e++,n++)if(this.pieces_[e]!==t.pieces_[n])return!1;return!0},Nt.prototype.contains=function(t){var e=this.pieceNum_,n=t.pieceNum_;if(this.getLength()>t.getLength())return!1;for(;e<this.pieces_.length;){if(this.pieces_[e]!==t.pieces_[n])return!1;++e,++n}return!0},Nt);function Nt(t,e){if(void 0===e){this.pieces_=t.split("/");for(var n=0,r=0;r<this.pieces_.length;r++)0<this.pieces_[r].length&&(this.pieces_[n]=this.pieces_[r],n++);this.pieces_.length=n,this.pieceNum_=0}else this.pieces_=t,this.pieceNum_=e}var Rt=(Object.defineProperty(Pt,"MAX_PATH_DEPTH",{get:function(){return 32},enumerable:!0,configurable:!0}),Object.defineProperty(Pt,"MAX_PATH_LENGTH_BYTES",{get:function(){return 768},enumerable:!0,configurable:!0}),Pt.prototype.push=function(t){0<this.parts_.length&&(this.byteLength_+=1),this.parts_.push(t),this.byteLength_+=M(t),this.checkValid_()},Pt.prototype.pop=function(){var t=this.parts_.pop();this.byteLength_-=M(t),0<this.parts_.length&&(this.byteLength_-=1)},Pt.prototype.checkValid_=function(){if(this.byteLength_>Pt.MAX_PATH_LENGTH_BYTES)throw new Error(this.errorPrefix_+"has a key path longer than "+Pt.MAX_PATH_LENGTH_BYTES+" bytes ("+this.byteLength_+").");if(this.parts_.length>Pt.MAX_PATH_DEPTH)throw new Error(this.errorPrefix_+"path specified exceeds the maximum depth that can be written ("+Pt.MAX_PATH_DEPTH+") or object contains a cycle "+this.toErrorString())},Pt.prototype.toErrorString=function(){return 0==this.parts_.length?"":"in property '"+this.parts_.join(".")+"'"},Pt);function Pt(t,e){this.errorPrefix_=e,this.parts_=t.slice(),this.byteLength_=Math.max(1,this.parts_.length);for(var n=0;n<this.parts_.length;n++)this.byteLength_+=M(this.parts_[n]);this.checkValid_()}var Dt="firebaseio.com",Ot="websocket",xt="long_polling",kt=(Ft.prototype.needsQueryParam=function(){return this.host!==this.internalHost||this.isCustomHost()||this.includeNamespaceInQueryParams},Ft.prototype.isCacheableHost=function(){return"s-"===this.internalHost.substr(0,2)},Ft.prototype.isDemoHost=function(){return"firebaseio-demo.com"===this.domain},Ft.prototype.isCustomHost=function(){return"firebaseio.com"!==this.domain&&"firebaseio-demo.com"!==this.domain},Ft.prototype.updateHost=function(t){t!==this.internalHost&&(this.internalHost=t,this.isCacheableHost()&&ht.set("host:"+this.host,this.internalHost))},Ft.prototype.connectionURL=function(t,e){var n;if(C("string"==typeof t,"typeof type must == string"),C("object"==typeof e,"typeof params must == object"),t===Ot)n=(this.secure?"wss://":"ws://")+this.internalHost+"/.ws?";else{if(t!==xt)throw new Error("Unknown connection type: "+t);n=(this.secure?"https://":"http://")+this.internalHost+"/.lp?"}this.needsQueryParam()&&(e.ns=this.namespace);var r=[];return Ct(e,function(t,e){r.push(t+"="+e)}),n+r.join("&")},Ft.prototype.toString=function(){var t=this.toURLString();return this.persistenceKey&&(t+="<"+this.persistenceKey+">"),t},Ft.prototype.toURLString=function(){return(this.secure?"https://":"http://")+this.host},Ft);function Ft(t,e,n,r,i,o){void 0===i&&(i=""),void 0===o&&(o=!1),this.secure=e,this.namespace=n,this.webSocketOnly=r,this.persistenceKey=i,this.includeNamespaceInQueryParams=o,this.host=t.toLowerCase(),this.domain=this.host.substr(this.host.indexOf(".")+1),this.internalHost=ht.get("host:"+t)||this.host}function At(t){var e=Yt(t),n=e.namespace;"firebase"===e.domain&&et(e.host+" is no longer supported. Please use <YOUR FIREBASE>.firebaseio.com instead"),n&&"undefined"!=n||"localhost"===e.domain||et("Cannot parse Firebase url. Please use https://<YOUR FIREBASE>.firebaseio.com"),e.secure||"undefined"!=typeof window&&window.location&&window.location.protocol&&-1!==window.location.protocol.indexOf("https:")&&nt("Insecure Firebase access from a secure page. Please use https in calls to new Firebase().");var r="ws"===e.scheme||"wss"===e.scheme;return{repoInfo:new kt(e.host,e.secure,n,r,"",n!=e.subdomain),path:new It(e.pathString)}}function Lt(t){return"string"==typeof t&&0!==t.length&&!zt.test(t)}function Mt(t){return"string"==typeof t&&0!==t.length&&!Gt.test(t)}function Wt(t){return null===t||"string"==typeof t||"number"==typeof t&&!rt(t)||t&&"object"==typeof t&&N(t,".sv")}function Qt(t,e,n,r,i){i&&void 0===n||$t(F(t,e,i),n,r)}function qt(t,e,n,r,i){if(!i||void 0!==n){var o=F(t,e,i);if(!n||"object"!=typeof n||Array.isArray(n))throw new Error(o+" must be an object containing the children to replace.");var s=[];Ct(n,function(t,e){var n=new It(t);if($t(o,e,r.child(n)),".priority"===n.getBack()&&!Wt(e))throw new Error(o+"contains an invalid value for '"+n.toString()+"', which must be a valid Firebase priority (a string, finite number, server value, or null).");s.push(n)}),function(t,e){var n,r;for(n=0;n<e.length;n++)for(var i=(r=e[n]).slice(),o=0;o<i.length;o++)if(".priority"===i[o]&&o===i.length-1);else if(!Lt(i[o]))throw new Error(t+"contains an invalid key ("+i[o]+") in path "+r.toString()+'. Keys must be non-empty strings and can\'t contain ".", "#", "$", "/", "[", or "]"');e.sort(It.comparePaths);var s=null;for(n=0;n<e.length;n++){if(r=e[n],null!==s&&s.contains(r))throw new Error(t+"contains a path "+s.toString()+" that is ancestor of another path "+r.toString());s=r}}(o,s)}}function Ut(t,e,n,r){if(!r||void 0!==n){if(rt(n))throw new Error(F(t,e,r)+"is "+n.toString()+", but must be a valid Firebase priority (a string, finite number, server value, or null).");if(!Wt(n))throw new Error(F(t,e,r)+"must be a valid Firebase priority (a string, finite number, server value, or null).")}}function Vt(t,e,n,r){if(!r||void 0!==n)switch(n){case"value":case"child_added":case"child_removed":case"child_changed":case"child_moved":break;default:throw new Error(F(t,e,r)+'must be a valid event type = "value", "child_added", "child_removed", "child_changed", or "child_moved".')}}function Ht(t,e,n,r){if(!(r&&void 0===n||Lt(n)))throw new Error(F(t,e,r)+'was an invalid key = "'+n+'". Firebase keys must be non-empty strings and can\'t contain ".", "#", "$", "/", "[", or "]").')}function Bt(t,e,n,r){if(!(r&&void 0===n||Mt(n)))throw new Error(F(t,e,r)+'was an invalid path = "'+n+'". Paths must be non-empty strings and can\'t contain ".", "#", "$", "[", or "]"')}function jt(t,e){if(".info"===e.getFront())throw new Error(t+" failed = Can't modify data under /.info/")}function Kt(t,e,n){var r=n.path.toString();if("string"!=typeof n.repoInfo.host||0===n.repoInfo.host.length||!Lt(n.repoInfo.namespace)&&"localhost"!==n.repoInfo.host.split(":")[0]||0!==r.length&&!function(t){return t=t&&t.replace(/^\/*\.info(\/|$)/,"/"),Mt(t)}(r))throw new Error(F(t,e,!1)+'must be a valid firebase URL and the path can\'t contain ".", "#", "$", "[", or "]".')}var Yt=function(t){var e="",n="",r="",i="",o="",s=!0,a="https",h=443;if("string"==typeof t){var l=t.indexOf("//");0<=l&&(a=t.substring(0,l-1),t=t.substring(l+2));var u=t.indexOf("/");-1===u&&(u=t.length);var c=t.indexOf("?");-1===c&&(c=t.length),e=t.substring(0,Math.min(u,c)),u<c&&(i=function(t){for(var e="",n=t.split("/"),r=0;r<n.length;r++)if(0<n[r].length){var i=n[r];try{i=decodeURIComponent(i.replace(/\+/g," "))}catch(t){}e+="/"+i}return e}(t.substring(u,c)));var p=function(t){var e,n,r={};"?"===t.charAt(0)&&(t=t.substring(1));try{for(var i=f(t.split("&")),o=i.next();!o.done;o=i.next()){var s=o.value;if(0!==s.length){var a=s.split("=");2===a.length?r[decodeURIComponent(a[0])]=decodeURIComponent(a[1]):nt("Invalid query segment '"+s+"' in query '"+t+"'")}}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}return r}(t.substring(Math.min(t.length,c)));0<=(l=e.indexOf(":"))?(s="https"===a||"wss"===a,h=parseInt(e.substring(l+1),10)):l=t.length;var d=e.split(".");3===d.length?(n=d[1],o=r=d[0].toLowerCase()):2===d.length?n=d[0]:"localhost"===d[0].slice(0,l).toLowerCase()&&(n="localhost"),"ns"in p&&(o=p.ns)}return{host:e,port:h,domain:n,subdomain:r,secure:s,scheme:a,pathString:i,namespace:o}},zt=/[\[\].#$\/\u0000-\u001F\u007F]/,Gt=/[\[\].#$\u0000-\u001F\u007F]/,Xt=10485760,$t=function(n,t,e){var r=e instanceof It?new Rt(e,n):e;if(void 0===t)throw new Error(n+"contains undefined "+r.toErrorString());if("function"==typeof t)throw new Error(n+"contains a function "+r.toErrorString()+" with contents = "+t.toString());if(rt(t))throw new Error(n+"contains "+t.toString()+" "+r.toErrorString());if("string"==typeof t&&t.length>Xt/3&&M(t)>Xt)throw new Error(n+"contains a string greater than "+Xt+" utf8 bytes "+r.toErrorString()+" ('"+t.substring(0,50)+"...')");if(t&&"object"==typeof t){var i=!1,o=!1;if(Ct(t,function(t,e){if(".value"===t)i=!0;else if(".priority"!==t&&".sv"!==t&&(o=!0,!Lt(t)))throw new Error(n+" contains an invalid key ("+t+") "+r.toErrorString()+'. Keys must be non-empty strings and can\'t contain ".", "#", "$", "/", "[", or "]"');r.push(t),$t(n,e,r),r.pop()}),i&&o)throw new Error(n+' contains ".value" child '+r.toErrorString()+" in addition to actual children.")}},Jt=(Zt.prototype.cancel=function(t){k("OnDisconnect.cancel",0,1,arguments.length),A("OnDisconnect.cancel",1,t,!0);var e=new p;return this.repo_.onDisconnectCancel(this.path_,e.wrapCallback(t)),e.promise},Zt.prototype.remove=function(t){k("OnDisconnect.remove",0,1,arguments.length),jt("OnDisconnect.remove",this.path_),A("OnDisconnect.remove",1,t,!0);var e=new p;return this.repo_.onDisconnectSet(this.path_,null,e.wrapCallback(t)),e.promise},Zt.prototype.set=function(t,e){k("OnDisconnect.set",1,2,arguments.length),jt("OnDisconnect.set",this.path_),Qt("OnDisconnect.set",1,t,this.path_,!1),A("OnDisconnect.set",2,e,!0);var n=new p;return this.repo_.onDisconnectSet(this.path_,t,n.wrapCallback(e)),n.promise},Zt.prototype.setWithPriority=function(t,e,n){k("OnDisconnect.setWithPriority",2,3,arguments.length),jt("OnDisconnect.setWithPriority",this.path_),Qt("OnDisconnect.setWithPriority",1,t,this.path_,!1),Ut("OnDisconnect.setWithPriority",2,e,!1),A("OnDisconnect.setWithPriority",3,n,!0);var r=new p;return this.repo_.onDisconnectSetWithPriority(this.path_,t,e,r.wrapCallback(n)),r.promise},Zt.prototype.update=function(t,e){if(k("OnDisconnect.update",1,2,arguments.length),jt("OnDisconnect.update",this.path_),Array.isArray(t)){for(var n={},r=0;r<t.length;++r)n[""+r]=t[r];t=n,nt("Passing an Array to firebase.database.onDisconnect().update() is deprecated. Use set() if you want to overwrite the existing data, or an Object with integer keys if you really do want to only update some of the children.")}qt("OnDisconnect.update",1,t,this.path_,!1),A("OnDisconnect.update",2,e,!0);var i=new p;return this.repo_.onDisconnectUpdate(this.path_,t,i.wrapCallback(e)),i.promise},Zt);function Zt(t,e){this.repo_=t,this.path_=e}var te=(ee.prototype.toJSON=function(){return k("TransactionResult.toJSON",0,1,arguments.length),{committed:this.committed,snapshot:this.snapshot.toJSON()}},ee);function ee(t,e){this.committed=t,this.snapshot=e}var ne,re,ie,oe=(ne="-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz",re=0,ie=[],function(t){var e,n=t===re;re=t;var r=new Array(8);for(e=7;0<=e;e--)r[e]=ne.charAt(t%64),t=Math.floor(t/64);C(0===t,"Cannot push at time == 0");var i=r.join("");if(n){for(e=11;0<=e&&63===ie[e];e--)ie[e]=0;ie[e]++}else for(e=0;e<12;e++)ie[e]=Math.floor(64*Math.random());for(e=0;e<12;e++)i+=ne.charAt(ie[e]);return C(20===i.length,"nextPushId: Length should be 20."),i}),se=(ae.Wrap=function(t,e){return new ae(t,e)},ae);function ae(t,e){this.name=t,this.node=e}var he,le=(ue.prototype.getCompare=function(){return this.compare.bind(this)},ue.prototype.indexedValueChanged=function(t,e){var n=new se(yt,t),r=new se(yt,e);return 0!==this.compare(n,r)},ue.prototype.minPost=function(){return se.MIN},ue);function ue(){}var ce,pe=(t(de,ce=le),Object.defineProperty(de,"__EMPTY_NODE",{get:function(){return he},set:function(t){he=t},enumerable:!0,configurable:!0}),de.prototype.compare=function(t,e){return gt(t.name,e.name)},de.prototype.isDefinedOn=function(t){throw c("KeyIndex.isDefinedOn not expected to be called.")},de.prototype.indexedValueChanged=function(t,e){return!1},de.prototype.minPost=function(){return se.MIN},de.prototype.maxPost=function(){return new se(vt,he)},de.prototype.makePost=function(t,e){return C("string"==typeof t,"KeyIndex indexValue must always be a string."),new se(t,he)},de.prototype.toString=function(){return".key"},de);function de(){return null!==ce&&ce.apply(this,arguments)||this}var fe,_e=new pe;function ye(t){return"number"==typeof t?"number:"+Et(t):"string:"+t}function ve(t){if(t.isLeafNode()){var e=t.val();C("string"==typeof e||"number"==typeof e||"object"==typeof e&&N(e,".sv"),"Priority must be a string or number.")}else C(t===fe||t.isEmpty(),"priority of unexpected type.");C(t===fe||t.getPriority().isEmpty(),"Priority nodes can't have a priority of their own.")}var ge,me,Ce,Ee,we=(Object.defineProperty(be,"__childrenNodeConstructor",{get:function(){return ge},set:function(t){ge=t},enumerable:!0,configurable:!0}),be.prototype.isLeafNode=function(){return!0},be.prototype.getPriority=function(){return this.priorityNode_},be.prototype.updatePriority=function(t){return new be(this.value_,t)},be.prototype.getImmediateChild=function(t){return".priority"===t?this.priorityNode_:be.__childrenNodeConstructor.EMPTY_NODE},be.prototype.getChild=function(t){return t.isEmpty()?this:".priority"===t.getFront()?this.priorityNode_:be.__childrenNodeConstructor.EMPTY_NODE},be.prototype.hasChild=function(){return!1},be.prototype.getPredecessorChildName=function(t,e){return null},be.prototype.updateImmediateChild=function(t,e){return".priority"===t?this.updatePriority(e):e.isEmpty()&&".priority"!==t?this:be.__childrenNodeConstructor.EMPTY_NODE.updateImmediateChild(t,e).updatePriority(this.priorityNode_)},be.prototype.updateChild=function(t,e){var n=t.getFront();return null===n?e:e.isEmpty()&&".priority"!==n?this:(C(".priority"!==n||1===t.getLength(),".priority must be the last token in a path"),this.updateImmediateChild(n,be.__childrenNodeConstructor.EMPTY_NODE.updateChild(t.popFront(),e)))},be.prototype.isEmpty=function(){return!1},be.prototype.numChildren=function(){return 0},be.prototype.forEachChild=function(t,e){return!1},be.prototype.val=function(t){return t&&!this.getPriority().isEmpty()?{".value":this.getValue(),".priority":this.getPriority().val()}:this.getValue()},be.prototype.hash=function(){if(null===this.lazyHash_){var t="";this.priorityNode_.isEmpty()||(t+="priority:"+ye(this.priorityNode_.val())+":");var e=typeof this.value_;t+=e+":",t+="number"==e?Et(this.value_):this.value_,this.lazyHash_=X(t)}return this.lazyHash_},be.prototype.getValue=function(){return this.value_},be.prototype.compareTo=function(t){return t===be.__childrenNodeConstructor.EMPTY_NODE?1:t instanceof be.__childrenNodeConstructor?-1:(C(t.isLeafNode(),"Unknown node type"),this.compareToLeafNode_(t))},be.prototype.compareToLeafNode_=function(t){var e=typeof t.value_,n=typeof this.value_,r=be.VALUE_TYPE_ORDER.indexOf(e),i=be.VALUE_TYPE_ORDER.indexOf(n);return C(0<=r,"Unknown leaf type: "+e),C(0<=i,"Unknown leaf type: "+n),r===i?"object"==n?0:this.value_<t.value_?-1:this.value_===t.value_?0:1:i-r},be.prototype.withIndex=function(){return this},be.prototype.isIndexed=function(){return!0},be.prototype.equals=function(t){if(t===this)return!0;if(t.isLeafNode()){var e=t;return this.value_===e.value_&&this.priorityNode_.equals(e.priorityNode_)}return!1},be.VALUE_TYPE_ORDER=["object","boolean","number","string"],be);function be(t,e){void 0===e&&(e=be.__childrenNodeConstructor.EMPTY_NODE),this.value_=t,this.priorityNode_=e,this.lazyHash_=null,C(void 0!==this.value_&&null!==this.value_,"LeafNode shouldn't be created with null/undefined value."),ve(this.priorityNode_)}function Se(){return null!==Ee&&Ee.apply(this,arguments)||this}var Te=new(t(Se,Ee=le),Se.prototype.compare=function(t,e){var n=t.node.getPriority(),r=e.node.getPriority(),i=n.compareTo(r);return 0===i?gt(t.name,e.name):i},Se.prototype.isDefinedOn=function(t){return!t.getPriority().isEmpty()},Se.prototype.indexedValueChanged=function(t,e){return!t.getPriority().equals(e.getPriority())},Se.prototype.minPost=function(){return se.MIN},Se.prototype.maxPost=function(){return new se(vt,new we("[PRIORITY-POST]",Ce))},Se.prototype.makePost=function(t,e){var n=me(t);return new se(e,new we("[PRIORITY-POST]",n))},Se.prototype.toString=function(){return".priority"},Se),Ie=(Ne.prototype.getNext=function(){if(0===this.nodeStack_.length)return null;var t,e=this.nodeStack_.pop();if(t=this.resultGenerator_?this.resultGenerator_(e.key,e.value):{key:e.key,value:e.value},this.isReverse_)for(e=e.left;!e.isEmpty();)this.nodeStack_.push(e),e=e.right;else for(e=e.right;!e.isEmpty();)this.nodeStack_.push(e),e=e.left;return t},Ne.prototype.hasNext=function(){return 0<this.nodeStack_.length},Ne.prototype.peek=function(){if(0===this.nodeStack_.length)return null;var t=this.nodeStack_[this.nodeStack_.length-1];return this.resultGenerator_?this.resultGenerator_(t.key,t.value):{key:t.key,value:t.value}},Ne);function Ne(t,e,n,r,i){void 0===i&&(i=null),this.isReverse_=r,this.resultGenerator_=i,this.nodeStack_=[];for(var o=1;!t.isEmpty();)if(t=t,o=e?n(t.key,e):1,r&&(o*=-1),o<0)t=this.isReverse_?t.left:t.right;else{if(0===o){this.nodeStack_.push(t);break}this.nodeStack_.push(t),t=this.isReverse_?t.right:t.left}}var Re=(Pe.prototype.copy=function(t,e,n,r,i){return new Pe(null!=t?t:this.key,null!=e?e:this.value,null!=n?n:this.color,null!=r?r:this.left,null!=i?i:this.right)},Pe.prototype.count=function(){return this.left.count()+1+this.right.count()},Pe.prototype.isEmpty=function(){return!1},Pe.prototype.inorderTraversal=function(t){return this.left.inorderTraversal(t)||t(this.key,this.value)||this.right.inorderTraversal(t)},Pe.prototype.reverseTraversal=function(t){return this.right.reverseTraversal(t)||t(this.key,this.value)||this.left.reverseTraversal(t)},Pe.prototype.min_=function(){return this.left.isEmpty()?this:this.left.min_()},Pe.prototype.minKey=function(){return this.min_().key},Pe.prototype.maxKey=function(){return this.right.isEmpty()?this.key:this.right.maxKey()},Pe.prototype.insert=function(t,e,n){var r,i;return(i=(r=n(t,(i=this).key))<0?i.copy(null,null,null,i.left.insert(t,e,n),null):0===r?i.copy(null,e,null,null,null):i.copy(null,null,null,null,i.right.insert(t,e,n))).fixUp_()},Pe.prototype.removeMin_=function(){if(this.left.isEmpty())return xe.EMPTY_NODE;var t=this;return t.left.isRed_()||t.left.left.isRed_()||(t=t.moveRedLeft_()),(t=t.copy(null,null,null,t.left.removeMin_(),null)).fixUp_()},Pe.prototype.remove=function(t,e){var n,r;if(e(t,(n=this).key)<0)n.left.isEmpty()||n.left.isRed_()||n.left.left.isRed_()||(n=n.moveRedLeft_()),n=n.copy(null,null,null,n.left.remove(t,e),null);else{if(n.left.isRed_()&&(n=n.rotateRight_()),n.right.isEmpty()||n.right.isRed_()||n.right.left.isRed_()||(n=n.moveRedRight_()),0===e(t,n.key)){if(n.right.isEmpty())return xe.EMPTY_NODE;r=n.right.min_(),n=n.copy(r.key,r.value,null,null,n.right.removeMin_())}n=n.copy(null,null,null,null,n.right.remove(t,e))}return n.fixUp_()},Pe.prototype.isRed_=function(){return this.color},Pe.prototype.fixUp_=function(){var t=this;return t.right.isRed_()&&!t.left.isRed_()&&(t=t.rotateLeft_()),t.left.isRed_()&&t.left.left.isRed_()&&(t=t.rotateRight_()),t.left.isRed_()&&t.right.isRed_()&&(t=t.colorFlip_()),t},Pe.prototype.moveRedLeft_=function(){var t=this.colorFlip_();return t.right.left.isRed_()&&(t=(t=(t=t.copy(null,null,null,null,t.right.rotateRight_())).rotateLeft_()).colorFlip_()),t},Pe.prototype.moveRedRight_=function(){var t=this.colorFlip_();return t.left.left.isRed_()&&(t=(t=t.rotateRight_()).colorFlip_()),t},Pe.prototype.rotateLeft_=function(){var t=this.copy(null,null,Pe.RED,null,this.right.left);return this.right.copy(null,null,this.color,t,null)},Pe.prototype.rotateRight_=function(){var t=this.copy(null,null,Pe.RED,this.left.right,null);return this.left.copy(null,null,this.color,null,t)},Pe.prototype.colorFlip_=function(){var t=this.left.copy(null,null,!this.left.color,null,null),e=this.right.copy(null,null,!this.right.color,null,null);return this.copy(null,null,!this.color,t,e)},Pe.prototype.checkMaxDepth_=function(){var t=this.check_();return Math.pow(2,t)<=this.count()+1},Pe.prototype.check_=function(){var t;if(this.isRed_()&&this.left.isRed_())throw new Error("Red node has red child("+this.key+","+this.value+")");if(this.right.isRed_())throw new Error("Right child of ("+this.key+","+this.value+") is red");if((t=this.left.check_())!==this.right.check_())throw new Error("Black depths differ");return t+(this.isRed_()?0:1)},Pe.RED=!0,Pe.BLACK=!1,Pe);function Pe(t,e,n,r,i){this.key=t,this.value=e,this.color=null!=n?n:Pe.RED,this.left=null!=r?r:xe.EMPTY_NODE,this.right=null!=i?i:xe.EMPTY_NODE}var De=(Oe.prototype.copy=function(t,e,n,r,i){return this},Oe.prototype.insert=function(t,e,n){return new Re(t,e,null)},Oe.prototype.remove=function(t,e){return this},Oe.prototype.count=function(){return 0},Oe.prototype.isEmpty=function(){return!0},Oe.prototype.inorderTraversal=function(t){return!1},Oe.prototype.reverseTraversal=function(t){return!1},Oe.prototype.minKey=function(){return null},Oe.prototype.maxKey=function(){return null},Oe.prototype.check_=function(){return 0},Oe.prototype.isRed_=function(){return!1},Oe);function Oe(){}var xe=(ke.prototype.insert=function(t,e){return new ke(this.comparator_,this.root_.insert(t,e,this.comparator_).copy(null,null,Re.BLACK,null,null))},ke.prototype.remove=function(t){return new ke(this.comparator_,this.root_.remove(t,this.comparator_).copy(null,null,Re.BLACK,null,null))},ke.prototype.get=function(t){for(var e,n=this.root_;!n.isEmpty();){if(0===(e=this.comparator_(t,n.key)))return n.value;e<0?n=n.left:0<e&&(n=n.right)}return null},ke.prototype.getPredecessorKey=function(t){for(var e,n=this.root_,r=null;!n.isEmpty();){if(0===(e=this.comparator_(t,n.key))){if(n.left.isEmpty())return r?r.key:null;for(n=n.left;!n.right.isEmpty();)n=n.right;return n.key}e<0?n=n.left:0<e&&(n=(r=n).right)}throw new Error("Attempted to find predecessor key for a nonexistent key. What gives?")},ke.prototype.isEmpty=function(){return this.root_.isEmpty()},ke.prototype.count=function(){return this.root_.count()},ke.prototype.minKey=function(){return this.root_.minKey()},ke.prototype.maxKey=function(){return this.root_.maxKey()},ke.prototype.inorderTraversal=function(t){return this.root_.inorderTraversal(t)},ke.prototype.reverseTraversal=function(t){return this.root_.reverseTraversal(t)},ke.prototype.getIterator=function(t){return new Ie(this.root_,null,this.comparator_,!1,t)},ke.prototype.getIteratorFrom=function(t,e){return new Ie(this.root_,t,this.comparator_,!1,e)},ke.prototype.getReverseIteratorFrom=function(t,e){return new Ie(this.root_,t,this.comparator_,!0,e)},ke.prototype.getReverseIterator=function(t){return new Ie(this.root_,null,this.comparator_,!0,t)},ke.EMPTY_NODE=new De,ke);function ke(t,e){void 0===e&&(e=ke.EMPTY_NODE),this.comparator_=t,this.root_=e}var Fe=Math.log(2),Ae=(Le.prototype.nextBitIsOne=function(){var t=!(this.bits_&1<<this.current_);return this.current_--,t},Le);function Le(t){var e;this.count=(e=t+1,parseInt(Math.log(e)/Fe,10)),this.current_=this.count-1;var n,r=(n=this.count,parseInt(Array(n+1).join("1"),2));this.bits_=t+1&r}var Me,We,Qe=function(l,t,u,e){l.sort(t);var c=function(t,e){var n,r,i=e-t;if(0==i)return null;if(1==i)return n=l[t],r=u?u(n):n,new Re(r,n.node,Re.BLACK,null,null);var o=parseInt(i/2,10)+t,s=c(t,o),a=c(o+1,e);return n=l[o],r=u?u(n):n,new Re(r,n.node,Re.BLACK,s,a)},n=function(t){for(var e=null,n=null,a=l.length,r=function(t,e){var n=a-t,r=a;a-=t;var i=c(1+n,r),o=l[n],s=u?u(o):o;h(new Re(s,o.node,e,null,i))},h=function(t){e=e?e.left=t:n=t},i=0;i<t.count;++i){var o=t.nextBitIsOne(),s=Math.pow(2,t.count-(i+1));o?r(s,Re.BLACK):(r(s,Re.BLACK),r(s,Re.RED))}return n}(new Ae(l.length));return new xe(e||t,n)},qe={},Ue=(Object.defineProperty(Ve,"Default",{get:function(){return C(Te,"ChildrenNode.ts has not been loaded"),Me=Me||new Ve({".priority":qe},{".priority":Te})},enumerable:!0,configurable:!0}),Ve.prototype.get=function(t){var e=R(this.indexes_,t);if(!e)throw new Error("No index defined for "+t);return e instanceof xe?e:null},Ve.prototype.hasIndex=function(t){return N(this.indexSet_,t.toString())},Ve.prototype.addIndex=function(t,e){C(t!==_e,"KeyIndex always exists and isn't meant to be added to the IndexMap.");for(var n,r=[],i=!1,o=e.getIterator(se.Wrap),s=o.getNext();s;)i=i||t.isDefinedOn(s.node),r.push(s),s=o.getNext();n=i?Qe(r,t.getCompare()):qe;var a=t.toString(),h=u({},this.indexSet_);h[a]=t;var l=u({},this.indexes_);return l[a]=n,new Ve(l,h)},Ve.prototype.addToIndexes=function(h,l){var u=this;return new Ve(D(this.indexes_,function(t,e){var n=R(u.indexSet_,e);if(C(n,"Missing index implementation for "+e),t===qe){if(n.isDefinedOn(h.node)){for(var r=[],i=l.getIterator(se.Wrap),o=i.getNext();o;)o.name!=h.name&&r.push(o),o=i.getNext();return r.push(h),Qe(r,n.getCompare())}return qe}var s=l.get(h.name),a=t;return s&&(a=a.remove(new se(h.name,s))),a.insert(h,h.node)}),this.indexSet_)},Ve.prototype.removeFromIndexes=function(n,r){return new Ve(D(this.indexes_,function(t){if(t===qe)return t;var e=r.get(n.name);return e?t.remove(new se(n.name,e)):t}),this.indexSet_)},Ve);function Ve(t,e){this.indexes_=t,this.indexSet_=e}function He(t,e){return gt(t.name,e.name)}function Be(t,e){return gt(t,e)}var je,Ke=(Object.defineProperty(Ye,"EMPTY_NODE",{get:function(){return We=We||new Ye(new xe(Be),null,Ue.Default)},enumerable:!0,configurable:!0}),Ye.prototype.isLeafNode=function(){return!1},Ye.prototype.getPriority=function(){return this.priorityNode_||We},Ye.prototype.updatePriority=function(t){return this.children_.isEmpty()?this:new Ye(this.children_,t,this.indexMap_)},Ye.prototype.getImmediateChild=function(t){if(".priority"===t)return this.getPriority();var e=this.children_.get(t);return null===e?We:e},Ye.prototype.getChild=function(t){var e=t.getFront();return null===e?this:this.getImmediateChild(e).getChild(t.popFront())},Ye.prototype.hasChild=function(t){return null!==this.children_.get(t)},Ye.prototype.updateImmediateChild=function(t,e){if(C(e,"We should always be passing snapshot nodes"),".priority"===t)return this.updatePriority(e);var n,r=new se(t,e),i=void 0,o=void 0;return o=e.isEmpty()?(i=this.children_.remove(t),this.indexMap_.removeFromIndexes(r,this.children_)):(i=this.children_.insert(t,e),this.indexMap_.addToIndexes(r,this.children_)),n=i.isEmpty()?We:this.priorityNode_,new Ye(i,n,o)},Ye.prototype.updateChild=function(t,e){var n=t.getFront();if(null===n)return e;C(".priority"!==t.getFront()||1===t.getLength(),".priority must be the last token in a path");var r=this.getImmediateChild(n).updateChild(t.popFront(),e);return this.updateImmediateChild(n,r)},Ye.prototype.isEmpty=function(){return this.children_.isEmpty()},Ye.prototype.numChildren=function(){return this.children_.count()},Ye.prototype.val=function(n){if(this.isEmpty())return null;var r={},i=0,o=0,s=!0;if(this.forEachChild(Te,function(t,e){r[t]=e.val(n),i++,s&&Ye.INTEGER_REGEXP_.test(t)?o=Math.max(o,Number(t)):s=!1}),!n&&s&&o<2*i){var t=[];for(var e in r)t[e]=r[e];return t}return n&&!this.getPriority().isEmpty()&&(r[".priority"]=this.getPriority().val()),r},Ye.prototype.hash=function(){if(null===this.lazyHash_){var r="";this.getPriority().isEmpty()||(r+="priority:"+ye(this.getPriority().val())+":"),this.forEachChild(Te,function(t,e){var n=e.hash();""!==n&&(r+=":"+t+":"+n)}),this.lazyHash_=""===r?"":X(r)}return this.lazyHash_},Ye.prototype.getPredecessorChildName=function(t,e,n){var r=this.resolveIndex_(n);if(r){var i=r.getPredecessorKey(new se(t,e));return i?i.name:null}return this.children_.getPredecessorKey(t)},Ye.prototype.getFirstChildName=function(t){var e=this.resolveIndex_(t);if(e){var n=e.minKey();return n&&n.name}return this.children_.minKey()},Ye.prototype.getFirstChild=function(t){var e=this.getFirstChildName(t);return e?new se(e,this.children_.get(e)):null},Ye.prototype.getLastChildName=function(t){var e=this.resolveIndex_(t);if(e){var n=e.maxKey();return n&&n.name}return this.children_.maxKey()},Ye.prototype.getLastChild=function(t){var e=this.getLastChildName(t);return e?new se(e,this.children_.get(e)):null},Ye.prototype.forEachChild=function(t,e){var n=this.resolveIndex_(t);return n?n.inorderTraversal(function(t){return e(t.name,t.node)}):this.children_.inorderTraversal(e)},Ye.prototype.getIterator=function(t){return this.getIteratorFrom(t.minPost(),t)},Ye.prototype.getIteratorFrom=function(t,e){var n=this.resolveIndex_(e);if(n)return n.getIteratorFrom(t,function(t){return t});for(var r=this.children_.getIteratorFrom(t.name,se.Wrap),i=r.peek();null!=i&&e.compare(i,t)<0;)r.getNext(),i=r.peek();return r},Ye.prototype.getReverseIterator=function(t){return this.getReverseIteratorFrom(t.maxPost(),t)},Ye.prototype.getReverseIteratorFrom=function(t,e){var n=this.resolveIndex_(e);if(n)return n.getReverseIteratorFrom(t,function(t){return t});for(var r=this.children_.getReverseIteratorFrom(t.name,se.Wrap),i=r.peek();null!=i&&0<e.compare(i,t);)r.getNext(),i=r.peek();return r},Ye.prototype.compareTo=function(t){return this.isEmpty()?t.isEmpty()?0:-1:t.isLeafNode()||t.isEmpty()?1:t===Ge?-1:0},Ye.prototype.withIndex=function(t){if(t===_e||this.indexMap_.hasIndex(t))return this;var e=this.indexMap_.addIndex(t,this.children_);return new Ye(this.children_,this.priorityNode_,e)},Ye.prototype.isIndexed=function(t){return t===_e||this.indexMap_.hasIndex(t)},Ye.prototype.equals=function(t){if(t===this)return!0;if(t.isLeafNode())return!1;var e=t;if(this.getPriority().equals(e.getPriority())){if(this.children_.count()!==e.children_.count())return!1;for(var n=this.getIterator(Te),r=e.getIterator(Te),i=n.getNext(),o=r.getNext();i&&o;){if(i.name!==o.name||!i.node.equals(o.node))return!1;i=n.getNext(),o=r.getNext()}return null===i&&null===o}return!1},Ye.prototype.resolveIndex_=function(t){return t===_e?null:this.indexMap_.get(t.toString())},Ye.INTEGER_REGEXP_=/^(0|[1-9]\d*)$/,Ye);function Ye(t,e,n){this.children_=t,this.priorityNode_=e,this.indexMap_=n,this.lazyHash_=null,this.priorityNode_&&ve(this.priorityNode_),this.children_.isEmpty()&&C(!this.priorityNode_||this.priorityNode_.isEmpty(),"An empty node cannot have a priority")}function ze(){return je.call(this,new xe(Be),Ke.EMPTY_NODE,Ue.Default)||this}var Ge=new(t(ze,je=Ke),ze.prototype.compareTo=function(t){return t===this?0:1},ze.prototype.equals=function(t){return t===this},ze.prototype.getPriority=function(){return this},ze.prototype.getImmediateChild=function(t){return Ke.EMPTY_NODE},ze.prototype.isEmpty=function(){return!1},ze);Object.defineProperties(se,{MIN:{value:new se(yt,Ke.EMPTY_NODE)},MAX:{value:new se(vt,Ge)}}),pe.__EMPTY_NODE=Ke.EMPTY_NODE,we.__childrenNodeConstructor=Ke,fe=Ge,Ce=Ge;var Xe,$e=!0;function Je(r,t){if(void 0===t&&(t=null),null===r)return Ke.EMPTY_NODE;if("object"==typeof r&&".priority"in r&&(t=r[".priority"]),C(null===t||"string"==typeof t||"number"==typeof t||"object"==typeof t&&".sv"in t,"Invalid priority type found: "+typeof t),"object"==typeof r&&".value"in r&&null!==r[".value"]&&(r=r[".value"]),"object"!=typeof r||".sv"in r)return new we(r,Je(t));if(r instanceof Array||!$e){var i=Ke.EMPTY_NODE;return Ct(r,function(t,e){if(N(r,t)&&"."!==t.substring(0,1)){var n=Je(e);!n.isLeafNode()&&n.isEmpty()||(i=i.updateImmediateChild(t,n))}}),i.updatePriority(Je(t))}var o=[],s=!1;if(Ct(r,function(t,e){if("."!==t.substring(0,1)){var n=Je(e);n.isEmpty()||(s=s||!n.getPriority().isEmpty(),o.push(new se(t,n)))}}),0==o.length)return Ke.EMPTY_NODE;var e=Qe(o,He,function(t){return t.name},Be);if(s){var n=Qe(o,Te.getCompare());return new Ke(e,Je(t),new Ue({".priority":n},{".priority":Te}))}return new Ke(e,Je(t),Ue.Default)}function Ze(){return null!==Xe&&Xe.apply(this,arguments)||this}me=Je;var tn,en=new(t(Ze,Xe=le),Ze.prototype.compare=function(t,e){var n=t.node.compareTo(e.node);return 0===n?gt(t.name,e.name):n},Ze.prototype.isDefinedOn=function(t){return!0},Ze.prototype.indexedValueChanged=function(t,e){return!t.equals(e)},Ze.prototype.minPost=function(){return se.MIN},Ze.prototype.maxPost=function(){return se.MAX},Ze.prototype.makePost=function(t,e){var n=Je(t);return new se(e,n)},Ze.prototype.toString=function(){return".value"},Ze),nn=(t(rn,tn=le),rn.prototype.extractChild=function(t){return t.getChild(this.indexPath_)},rn.prototype.isDefinedOn=function(t){return!t.getChild(this.indexPath_).isEmpty()},rn.prototype.compare=function(t,e){var n=this.extractChild(t.node),r=this.extractChild(e.node),i=n.compareTo(r);return 0===i?gt(t.name,e.name):i},rn.prototype.makePost=function(t,e){var n=Je(t),r=Ke.EMPTY_NODE.updateChild(this.indexPath_,n);return new se(e,r)},rn.prototype.maxPost=function(){var t=Ke.EMPTY_NODE.updateChild(this.indexPath_,Ge);return new se(vt,t)},rn.prototype.toString=function(){return this.indexPath_.slice().join("/")},rn);function rn(t){var e=tn.call(this)||this;return e.indexPath_=t,C(!t.isEmpty()&&".priority"!==t.getFront(),"Can't create PathIndex with empty path or .priority key"),e}var on=(sn.prototype.val=function(){return k("DataSnapshot.val",0,0,arguments.length),this.node_.val()},sn.prototype.exportVal=function(){return k("DataSnapshot.exportVal",0,0,arguments.length),this.node_.val(!0)},sn.prototype.toJSON=function(){return k("DataSnapshot.toJSON",0,1,arguments.length),this.exportVal()},sn.prototype.exists=function(){return k("DataSnapshot.exists",0,0,arguments.length),!this.node_.isEmpty()},sn.prototype.child=function(t){k("DataSnapshot.child",0,1,arguments.length),t=String(t),Bt("DataSnapshot.child",1,t,!1);var e=new It(t),n=this.ref_.child(e);return new sn(this.node_.getChild(e),n,Te)},sn.prototype.hasChild=function(t){k("DataSnapshot.hasChild",1,1,arguments.length),Bt("DataSnapshot.hasChild",1,t,!1);var e=new It(t);return!this.node_.getChild(e).isEmpty()},sn.prototype.getPriority=function(){return k("DataSnapshot.getPriority",0,0,arguments.length),this.node_.getPriority().val()},sn.prototype.forEach=function(n){var r=this;return k("DataSnapshot.forEach",1,1,arguments.length),A("DataSnapshot.forEach",1,n,!1),!this.node_.isLeafNode()&&!!this.node_.forEachChild(this.index_,function(t,e){return n(new sn(e,r.ref_.child(t),Te))})},sn.prototype.hasChildren=function(){return k("DataSnapshot.hasChildren",0,0,arguments.length),!this.node_.isLeafNode()&&!this.node_.isEmpty()},Object.defineProperty(sn.prototype,"key",{get:function(){return this.ref_.getKey()},enumerable:!0,configurable:!0}),sn.prototype.numChildren=function(){return k("DataSnapshot.numChildren",0,0,arguments.length),this.node_.numChildren()},sn.prototype.getRef=function(){return k("DataSnapshot.ref",0,0,arguments.length),this.ref_},Object.defineProperty(sn.prototype,"ref",{get:function(){return this.getRef()},enumerable:!0,configurable:!0}),sn);function sn(t,e,n){this.node_=t,this.ref_=e,this.index_=n}var an=(hn.prototype.getPath=function(){var t=this.snapshot.getRef();return"value"===this.eventType?t.path:t.getParent().path},hn.prototype.getEventType=function(){return this.eventType},hn.prototype.getEventRunner=function(){return this.eventRegistration.getEventRunner(this)},hn.prototype.toString=function(){return this.getPath().toString()+":"+this.eventType+":"+T(this.snapshot.exportVal())},hn);function hn(t,e,n,r){this.eventType=t,this.eventRegistration=e,this.snapshot=n,this.prevName=r}var ln=(un.prototype.getPath=function(){return this.path},un.prototype.getEventType=function(){return"cancel"},un.prototype.getEventRunner=function(){return this.eventRegistration.getEventRunner(this)},un.prototype.toString=function(){return this.path.toString()+":cancel"},un);function un(t,e,n){this.eventRegistration=t,this.error=e,this.path=n}var cn=(pn.prototype.respondsTo=function(t){return"value"===t},pn.prototype.createEvent=function(t,e){var n=e.getQueryParams().getIndex();return new an("value",this,new on(t.snapshotNode,e.getRef(),n))},pn.prototype.getEventRunner=function(t){var e=this.context_;if("cancel"===t.getEventType()){C(this.cancelCallback_,"Raising a cancel event on a listener with no cancel callback");var n=this.cancelCallback_;return function(){n.call(e,t.error)}}var r=this.callback_;return function(){r.call(e,t.snapshot)}},pn.prototype.createCancelEvent=function(t,e){return this.cancelCallback_?new ln(this,t,e):null},pn.prototype.matches=function(t){return t instanceof pn&&(!t.callback_||!this.callback_||t.callback_===this.callback_&&t.context_===this.context_)},pn.prototype.hasAnyCallback=function(){return null!==this.callback_},pn);function pn(t,e,n){this.callback_=t,this.cancelCallback_=e,this.context_=n}var dn,fn=(_n.prototype.respondsTo=function(t){var e="children_added"===t?"child_added":t;return e="children_removed"===e?"child_removed":e,N(this.callbacks_,e)},_n.prototype.createCancelEvent=function(t,e){return this.cancelCallback_?new ln(this,t,e):null},_n.prototype.createEvent=function(t,e){C(null!=t.childName,"Child events should have a childName.");var n=e.getRef().child(t.childName),r=e.getQueryParams().getIndex();return new an(t.type,this,new on(t.snapshotNode,n,r),t.prevName)},_n.prototype.getEventRunner=function(t){var e=this.context_;if("cancel"===t.getEventType()){C(this.cancelCallback_,"Raising a cancel event on a listener with no cancel callback");var n=this.cancelCallback_;return function(){n.call(e,t.error)}}var r=this.callbacks_[t.eventType];return function(){r.call(e,t.snapshot,t.prevName)}},_n.prototype.matches=function(e){var n=this;if(e instanceof _n){if(!this.callbacks_||!e.callbacks_)return!0;if(this.context_===e.context_){var t=Object.keys(e.callbacks_),r=Object.keys(this.callbacks_),i=t.length;if(i===r.length){if(1!==i)return r.every(function(t){return e.callbacks_[t]===n.callbacks_[t]});var o=t[0],s=r[0];return!(s!==o||e.callbacks_[o]&&this.callbacks_[s]&&e.callbacks_[o]!==this.callbacks_[s])}}}return!1},_n.prototype.hasAnyCallback=function(){return null!==this.callbacks_},_n);function _n(t,e,n){this.callbacks_=t,this.cancelCallback_=e,this.context_=n}var yn=(Object.defineProperty(vn,"__referenceConstructor",{get:function(){return C(dn,"Reference.ts has not been loaded"),dn},set:function(t){dn=t},enumerable:!0,configurable:!0}),vn.validateQueryEndpoints_=function(t){var e=null,n=null;if(t.hasStart()&&(e=t.getIndexStartValue()),t.hasEnd()&&(n=t.getIndexEndValue()),t.getIndex()===_e){var r="Query: When ordering by key, you may only pass one argument to startAt(), endAt(), or equalTo().",i="Query: When ordering by key, the argument passed to startAt(), endAt(),or equalTo() must be a string.";if(t.hasStart()){if(t.getIndexStartName()!=yt)throw new Error(r);if("string"!=typeof e)throw new Error(i)}if(t.hasEnd()){if(t.getIndexEndName()!=vt)throw new Error(r);if("string"!=typeof n)throw new Error(i)}}else if(t.getIndex()===Te){if(null!=e&&!Wt(e)||null!=n&&!Wt(n))throw new Error("Query: When ordering by priority, the first argument passed to startAt(), endAt(), or equalTo() must be a valid priority value (null, a number, or a string).")}else if(C(t.getIndex()instanceof nn||t.getIndex()===en,"unknown index type."),null!=e&&"object"==typeof e||null!=n&&"object"==typeof n)throw new Error("Query: First argument passed to startAt(), endAt(), or equalTo() cannot be an object.")},vn.validateLimit_=function(t){if(t.hasStart()&&t.hasEnd()&&t.hasLimit()&&!t.hasAnchoredLimit())throw new Error("Query: Can't combine startAt(), endAt(), and limit(). Use limitToFirst() or limitToLast() instead.")},vn.prototype.validateNoPreviousOrderByCall_=function(t){if(!0===this.orderByCalled_)throw new Error(t+": You can't combine multiple orderBy calls.")},vn.prototype.getQueryParams=function(){return this.queryParams_},vn.prototype.getRef=function(){return k("Query.ref",0,0,arguments.length),new vn.__referenceConstructor(this.repo,this.path)},vn.prototype.on=function(t,e,n,r){k("Query.on",2,4,arguments.length),Vt("Query.on",1,t,!1),A("Query.on",2,e,!1);var i=vn.getCancelAndContextArgs_("Query.on",n,r);if("value"===t)this.onValueEvent(e,i.cancel,i.context);else{var o={};o[t]=e,this.onChildEvent(o,i.cancel,i.context)}return e},vn.prototype.onValueEvent=function(t,e,n){var r=new cn(t,e||null,n||null);this.repo.addEventCallbackForQuery(this,r)},vn.prototype.onChildEvent=function(t,e,n){var r=new fn(t,e,n);this.repo.addEventCallbackForQuery(this,r)},vn.prototype.off=function(t,e,n){k("Query.off",0,3,arguments.length),Vt("Query.off",1,t,!0),A("Query.off",2,e,!0),L("Query.off",3,n,!0);var r=null,i=null;"value"===t?r=new cn(e||null,null,n||null):t&&(e&&((i={})[t]=e),r=new fn(i,null,n||null)),this.repo.removeEventCallbackForQuery(this,r)},vn.prototype.once=function(e,n,t,r){var i=this;k("Query.once",1,4,arguments.length),Vt("Query.once",1,e,!1),A("Query.once",2,n,!0);var o=vn.getCancelAndContextArgs_("Query.once",t,r),s=!0,a=new p;a.promise.catch(function(){});var h=function(t){s&&(s=!1,i.off(e,h),n&&n.bind(o.context)(t),a.resolve(t))};return this.on(e,h,function(t){i.off(e,h),o.cancel&&o.cancel.bind(o.context)(t),a.reject(t)}),a.promise},vn.prototype.limitToFirst=function(t){if(k("Query.limitToFirst",1,1,arguments.length),"number"!=typeof t||Math.floor(t)!==t||t<=0)throw new Error("Query.limitToFirst: First argument must be a positive integer.");if(this.queryParams_.hasLimit())throw new Error("Query.limitToFirst: Limit was already set (by another call to limit, limitToFirst, or limitToLast).");return new vn(this.repo,this.path,this.queryParams_.limitToFirst(t),this.orderByCalled_)},vn.prototype.limitToLast=function(t){if(k("Query.limitToLast",1,1,arguments.length),"number"!=typeof t||Math.floor(t)!==t||t<=0)throw new Error("Query.limitToLast: First argument must be a positive integer.");if(this.queryParams_.hasLimit())throw new Error("Query.limitToLast: Limit was already set (by another call to limit, limitToFirst, or limitToLast).");return new vn(this.repo,this.path,this.queryParams_.limitToLast(t),this.orderByCalled_)},vn.prototype.orderByChild=function(t){if(k("Query.orderByChild",1,1,arguments.length),"$key"===t)throw new Error('Query.orderByChild: "$key" is invalid. Use Query.orderByKey() instead.');if("$priority"===t)throw new Error('Query.orderByChild: "$priority" is invalid. Use Query.orderByPriority() instead.');if("$value"===t)throw new Error('Query.orderByChild: "$value" is invalid. Use Query.orderByValue() instead.');Bt("Query.orderByChild",1,t,!1),this.validateNoPreviousOrderByCall_("Query.orderByChild");var e=new It(t);if(e.isEmpty())throw new Error("Query.orderByChild: cannot pass in empty path. Use Query.orderByValue() instead.");var n=new nn(e),r=this.queryParams_.orderBy(n);return vn.validateQueryEndpoints_(r),new vn(this.repo,this.path,r,!0)},vn.prototype.orderByKey=function(){k("Query.orderByKey",0,0,arguments.length),this.validateNoPreviousOrderByCall_("Query.orderByKey");var t=this.queryParams_.orderBy(_e);return vn.validateQueryEndpoints_(t),new vn(this.repo,this.path,t,!0)},vn.prototype.orderByPriority=function(){k("Query.orderByPriority",0,0,arguments.length),this.validateNoPreviousOrderByCall_("Query.orderByPriority");var t=this.queryParams_.orderBy(Te);return vn.validateQueryEndpoints_(t),new vn(this.repo,this.path,t,!0)},vn.prototype.orderByValue=function(){k("Query.orderByValue",0,0,arguments.length),this.validateNoPreviousOrderByCall_("Query.orderByValue");var t=this.queryParams_.orderBy(en);return vn.validateQueryEndpoints_(t),new vn(this.repo,this.path,t,!0)},vn.prototype.startAt=function(t,e){void 0===t&&(t=null),k("Query.startAt",0,2,arguments.length),Qt("Query.startAt",1,t,this.path,!0),Ht("Query.startAt",2,e,!0);var n=this.queryParams_.startAt(t,e);if(vn.validateLimit_(n),vn.validateQueryEndpoints_(n),this.queryParams_.hasStart())throw new Error("Query.startAt: Starting point was already set (by another call to startAt or equalTo).");return void 0===t&&(e=t=null),new vn(this.repo,this.path,n,this.orderByCalled_)},vn.prototype.endAt=function(t,e){void 0===t&&(t=null),k("Query.endAt",0,2,arguments.length),Qt("Query.endAt",1,t,this.path,!0),Ht("Query.endAt",2,e,!0);var n=this.queryParams_.endAt(t,e);if(vn.validateLimit_(n),vn.validateQueryEndpoints_(n),this.queryParams_.hasEnd())throw new Error("Query.endAt: Ending point was already set (by another call to endAt or equalTo).");return new vn(this.repo,this.path,n,this.orderByCalled_)},vn.prototype.equalTo=function(t,e){if(k("Query.equalTo",1,2,arguments.length),Qt("Query.equalTo",1,t,this.path,!1),Ht("Query.equalTo",2,e,!0),this.queryParams_.hasStart())throw new Error("Query.equalTo: Starting point was already set (by another call to startAt or equalTo).");if(this.queryParams_.hasEnd())throw new Error("Query.equalTo: Ending point was already set (by another call to endAt or equalTo).");return this.startAt(t,e).endAt(t,e)},vn.prototype.toString=function(){return k("Query.toString",0,0,arguments.length),this.repo.toString()+this.path.toUrlEncodedString()},vn.prototype.toJSON=function(){return k("Query.toJSON",0,1,arguments.length),this.toString()},vn.prototype.queryObject=function(){return this.queryParams_.getQueryObject()},vn.prototype.queryIdentifier=function(){var t=this.queryObject(),e=mt(t);return"{}"===e?"default":e},vn.prototype.isEqual=function(t){if(k("Query.isEqual",1,1,arguments.length),!(t instanceof vn))throw new Error("Query.isEqual failed: First argument must be an instance of firebase.database.Query.");var e=this.repo===t.repo,n=this.path.equals(t.path),r=this.queryIdentifier()===t.queryIdentifier();return e&&n&&r},vn.getCancelAndContextArgs_=function(t,e,n){var r={cancel:null,context:null};if(e&&n)r.cancel=e,A(t,3,r.cancel,!0),r.context=n,L(t,4,r.context,!0);else if(e)if("object"==typeof e&&null!==e)r.context=e;else{if("function"!=typeof e)throw new Error(F(t,3,!0)+" must either be a cancel callback or a context object.");r.cancel=e}return r},Object.defineProperty(vn.prototype,"ref",{get:function(){return this.getRef()},enumerable:!0,configurable:!0}),vn);function vn(t,e,n,r){this.repo=t,this.path=e,this.queryParams_=n,this.orderByCalled_=r}var gn=(mn.prototype.find=function(t){if(null!=this.value)return this.value.getChild(t);if(!t.isEmpty()&&0<this.children.size){var e=t.getFront();return t=t.popFront(),this.children.has(e)?this.children.get(e).find(t):null}return null},mn.prototype.remember=function(t,e){if(t.isEmpty())this.value=e,this.children.clear();else if(null!==this.value)this.value=this.value.updateChild(t,e);else{var n=t.getFront();this.children.has(n)||this.children.set(n,new mn);var r=this.children.get(n);t=t.popFront(),r.remember(t,e)}},mn.prototype.forget=function(t){if(t.isEmpty())return this.value=null,this.children.clear(),!0;if(null!==this.value){if(this.value.isLeafNode())return!1;var e=this.value;this.value=null;var n=this;return e.forEachChild(Te,function(t,e){n.remember(new It(t),e)}),this.forget(t)}if(0<this.children.size){var r=t.getFront();return t=t.popFront(),!this.children.has(r)||this.children.get(r).forget(t)&&this.children.delete(r),0===this.children.size}return!0},mn.prototype.forEachTree=function(r,i){null!==this.value?i(r,this.value):this.forEachChild(function(t,e){var n=new It(r.toString()+"/"+t);e.forEachTree(n,i)})},mn.prototype.forEachChild=function(n){this.children.forEach(function(t,e){n(e,t)})},mn);function mn(){this.value=null,this.children=new Map}function Cn(t,e){return t&&"object"==typeof t?(C(".sv"in t,"Unexpected leaf node or priority contents"),e[t[".sv"]]):t}var En,wn,bn=function(t,r){var i,e=t.getPriority().val(),n=Cn(e,r);if(t.isLeafNode()){var o=t,s=Cn(o.getValue(),r);return s!==o.getValue()||n!==o.getPriority().val()?new we(s,Je(n)):t}var a=t;return n!==(i=a).getPriority().val()&&(i=i.updatePriority(new we(n))),a.forEachChild(Te,function(t,e){var n=bn(e,r);n!==e&&(i=i.updateImmediateChild(t,n))}),i};(wn=En=En||{})[wn.OVERWRITE=0]="OVERWRITE",wn[wn.MERGE=1]="MERGE",wn[wn.ACK_USER_WRITE=2]="ACK_USER_WRITE",wn[wn.LISTEN_COMPLETE=3]="LISTEN_COMPLETE";var Sn=(Tn.User=new Tn(!0,!1,null,!1),Tn.Server=new Tn(!1,!0,null,!1),Tn.forServerTaggedQuery=function(t){return new Tn(!1,!0,t,!0)},Tn);function Tn(t,e,n,r){this.fromUser=t,this.fromServer=e,this.queryId=n,this.tagged=r,C(!r||e,"Tagged queries must be from server.")}var In,Nn=(Rn.prototype.operationForChild=function(t){if(this.path.isEmpty()){if(null!=this.affectedTree.value)return C(this.affectedTree.children.isEmpty(),"affectedTree should not have overlapping affected paths."),this;var e=this.affectedTree.subtree(new It(t));return new Rn(It.Empty,e,this.revert)}return C(this.path.getFront()===t,"operationForChild called for unrelated child."),new Rn(this.path.popFront(),this.affectedTree,this.revert)},Rn);function Rn(t,e,n){this.path=t,this.affectedTree=e,this.revert=n,this.type=En.ACK_USER_WRITE,this.source=Sn.User}var Pn=(Dn.fromObject=function(t){var n=Dn.Empty;return Ct(t,function(t,e){n=n.set(new It(t),e)}),n},Dn.prototype.isEmpty=function(){return null===this.value&&this.children.isEmpty()},Dn.prototype.findRootMostMatchingPathAndValue=function(t,e){if(null!=this.value&&e(this.value))return{path:It.Empty,value:this.value};if(t.isEmpty())return null;var n=t.getFront(),r=this.children.get(n);if(null===r)return null;var i=r.findRootMostMatchingPathAndValue(t.popFront(),e);return null==i?null:{path:new It(n).child(i.path),value:i.value}},Dn.prototype.findRootMostValueAndPath=function(t){return this.findRootMostMatchingPathAndValue(t,function(){return!0})},Dn.prototype.subtree=function(t){if(t.isEmpty())return this;var e=t.getFront(),n=this.children.get(e);return null!==n?n.subtree(t.popFront()):Dn.Empty},Dn.prototype.set=function(t,e){if(t.isEmpty())return new Dn(e,this.children);var n=t.getFront(),r=(this.children.get(n)||Dn.Empty).set(t.popFront(),e),i=this.children.insert(n,r);return new Dn(this.value,i)},Dn.prototype.remove=function(t){if(t.isEmpty())return this.children.isEmpty()?Dn.Empty:new Dn(null,this.children);var e=t.getFront(),n=this.children.get(e);if(n){var r=n.remove(t.popFront()),i=void 0;return i=r.isEmpty()?this.children.remove(e):this.children.insert(e,r),null===this.value&&i.isEmpty()?Dn.Empty:new Dn(this.value,i)}return this},Dn.prototype.get=function(t){if(t.isEmpty())return this.value;var e=t.getFront(),n=this.children.get(e);return n?n.get(t.popFront()):null},Dn.prototype.setTree=function(t,e){if(t.isEmpty())return e;var n=t.getFront(),r=(this.children.get(n)||Dn.Empty).setTree(t.popFront(),e),i=void 0;return i=r.isEmpty()?this.children.remove(n):this.children.insert(n,r),new Dn(this.value,i)},Dn.prototype.fold=function(t){return this.fold_(It.Empty,t)},Dn.prototype.fold_=function(n,r){var i={};return this.children.inorderTraversal(function(t,e){i[t]=e.fold_(n.child(t),r)}),r(n,this.value,i)},Dn.prototype.findOnPath=function(t,e){return this.findOnPath_(t,It.Empty,e)},Dn.prototype.findOnPath_=function(t,e,n){var r=!!this.value&&n(e,this.value);if(r)return r;if(t.isEmpty())return null;var i=t.getFront(),o=this.children.get(i);return o?o.findOnPath_(t.popFront(),e.child(i),n):null},Dn.prototype.foreachOnPath=function(t,e){return this.foreachOnPath_(t,It.Empty,e)},Dn.prototype.foreachOnPath_=function(t,e,n){if(t.isEmpty())return this;this.value&&n(e,this.value);var r=t.getFront(),i=this.children.get(r);return i?i.foreachOnPath_(t.popFront(),e.child(r),n):Dn.Empty},Dn.prototype.foreach=function(t){this.foreach_(It.Empty,t)},Dn.prototype.foreach_=function(n,r){this.children.inorderTraversal(function(t,e){e.foreach_(n.child(t),r)}),this.value&&r(n,this.value)},Dn.prototype.foreachChild=function(n){this.children.inorderTraversal(function(t,e){e.value&&n(t,e.value)})},Dn.Empty=new Dn(null),Dn);function Dn(t,e){void 0===e&&(e=In=In||new xe(it)),this.value=t,this.children=e}var On=(xn.prototype.operationForChild=function(t){return this.path.isEmpty()?new xn(this.source,It.Empty):new xn(this.source,this.path.popFront())},xn);function xn(t,e){this.source=t,this.path=e,this.type=En.LISTEN_COMPLETE}var kn=(Fn.prototype.operationForChild=function(t){return this.path.isEmpty()?new Fn(this.source,It.Empty,this.snap.getImmediateChild(t)):new Fn(this.source,this.path.popFront(),this.snap)},Fn);function Fn(t,e,n){this.source=t,this.path=e,this.snap=n,this.type=En.OVERWRITE}var An=(Ln.prototype.operationForChild=function(t){if(this.path.isEmpty()){var e=this.children.subtree(new It(t));return e.isEmpty()?null:e.value?new kn(this.source,It.Empty,e.value):new Ln(this.source,It.Empty,e)}return C(this.path.getFront()===t,"Can't get a merge for a child not on the path of the operation"),new Ln(this.source,this.path.popFront(),this.children)},Ln.prototype.toString=function(){return"Operation("+this.path+": "+this.source.toString()+" merge: "+this.children.toString()+")"},Ln);function Ln(t,e,n){this.source=t,this.path=e,this.children=n,this.type=En.MERGE}var Mn=(Wn.prototype.isFullyInitialized=function(){return this.fullyInitialized_},Wn.prototype.isFiltered=function(){return this.filtered_},Wn.prototype.isCompleteForPath=function(t){if(t.isEmpty())return this.isFullyInitialized()&&!this.filtered_;var e=t.getFront();return this.isCompleteForChild(e)},Wn.prototype.isCompleteForChild=function(t){return this.isFullyInitialized()&&!this.filtered_||this.node_.hasChild(t)},Wn.prototype.getNode=function(){return this.node_},Wn);function Wn(t,e,n){this.node_=t,this.fullyInitialized_=e,this.filtered_=n}var Qn=(qn.prototype.updateEventSnap=function(t,e,n){return new qn(new Mn(t,e,n),this.serverCache_)},qn.prototype.updateServerSnap=function(t,e,n){return new qn(this.eventCache_,new Mn(t,e,n))},qn.prototype.getEventCache=function(){return this.eventCache_},qn.prototype.getCompleteEventSnap=function(){return this.eventCache_.isFullyInitialized()?this.eventCache_.getNode():null},qn.prototype.getServerCache=function(){return this.serverCache_},qn.prototype.getCompleteServerSnap=function(){return this.serverCache_.isFullyInitialized()?this.serverCache_.getNode():null},qn.Empty=new qn(new Mn(Ke.EMPTY_NODE,!1,!1),new Mn(Ke.EMPTY_NODE,!1,!1)),qn);function qn(t,e){this.eventCache_=t,this.serverCache_=e}var Un=(Vn.valueChange=function(t){return new Vn(Vn.VALUE,t)},Vn.childAddedChange=function(t,e){return new Vn(Vn.CHILD_ADDED,e,t)},Vn.childRemovedChange=function(t,e){return new Vn(Vn.CHILD_REMOVED,e,t)},Vn.childChangedChange=function(t,e,n){return new Vn(Vn.CHILD_CHANGED,e,t,n)},Vn.childMovedChange=function(t,e){return new Vn(Vn.CHILD_MOVED,e,t)},Vn.CHILD_ADDED="child_added",Vn.CHILD_REMOVED="child_removed",Vn.CHILD_CHANGED="child_changed",Vn.CHILD_MOVED="child_moved",Vn.VALUE="value",Vn);function Vn(t,e,n,r,i){this.type=t,this.snapshotNode=e,this.childName=n,this.oldSnap=r,this.prevName=i}var Hn=(Bn.prototype.updateChild=function(t,e,n,r,i,o){C(t.isIndexed(this.index_),"A node must be indexed if only a child is updated");var s=t.getImmediateChild(e);return s.getChild(r).equals(n.getChild(r))&&s.isEmpty()==n.isEmpty()?t:(null!=o&&(n.isEmpty()?t.hasChild(e)?o.trackChildChange(Un.childRemovedChange(e,s)):C(t.isLeafNode(),"A child remove without an old child only makes sense on a leaf node"):s.isEmpty()?o.trackChildChange(Un.childAddedChange(e,n)):o.trackChildChange(Un.childChangedChange(e,n,s))),t.isLeafNode()&&n.isEmpty()?t:t.updateImmediateChild(e,n).withIndex(this.index_))},Bn.prototype.updateFullNode=function(r,n,i){return null!=i&&(r.isLeafNode()||r.forEachChild(Te,function(t,e){n.hasChild(t)||i.trackChildChange(Un.childRemovedChange(t,e))}),n.isLeafNode()||n.forEachChild(Te,function(t,e){if(r.hasChild(t)){var n=r.getImmediateChild(t);n.equals(e)||i.trackChildChange(Un.childChangedChange(t,e,n))}else i.trackChildChange(Un.childAddedChange(t,e))})),n.withIndex(this.index_)},Bn.prototype.updatePriority=function(t,e){return t.isEmpty()?Ke.EMPTY_NODE:t.updatePriority(e)},Bn.prototype.filtersNodes=function(){return!1},Bn.prototype.getIndexedFilter=function(){return this},Bn.prototype.getIndex=function(){return this.index_},Bn);function Bn(t){this.index_=t}var jn=(Kn.prototype.trackChildChange=function(t){var e=t.type,n=t.childName;C(e==Un.CHILD_ADDED||e==Un.CHILD_CHANGED||e==Un.CHILD_REMOVED,"Only child changes supported for tracking"),C(".priority"!==n,"Only non-priority child changes can be tracked.");var r=this.changeMap.get(n);if(r){var i=r.type;if(e==Un.CHILD_ADDED&&i==Un.CHILD_REMOVED)this.changeMap.set(n,Un.childChangedChange(n,t.snapshotNode,r.snapshotNode));else if(e==Un.CHILD_REMOVED&&i==Un.CHILD_ADDED)this.changeMap.delete(n);else if(e==Un.CHILD_REMOVED&&i==Un.CHILD_CHANGED)this.changeMap.set(n,Un.childRemovedChange(n,r.oldSnap));else if(e==Un.CHILD_CHANGED&&i==Un.CHILD_ADDED)this.changeMap.set(n,Un.childAddedChange(n,t.snapshotNode));else{if(e!=Un.CHILD_CHANGED||i!=Un.CHILD_CHANGED)throw c("Illegal combination of changes: "+t+" occurred after "+r);this.changeMap.set(n,Un.childChangedChange(n,t.snapshotNode,r.oldSnap))}}else this.changeMap.set(n,t)},Kn.prototype.getChanges=function(){return Array.from(this.changeMap.values())},Kn);function Kn(){this.changeMap=new Map}function Yn(){}var zn=new(Yn.prototype.getCompleteChild=function(t){return null},Yn.prototype.getChildAfterChild=function(t,e,n){return null},Yn),Gn=(Xn.prototype.getCompleteChild=function(t){var e=this.viewCache_.getEventCache();if(e.isCompleteForChild(t))return e.getNode().getImmediateChild(t);var n=null!=this.optCompleteServerCache_?new Mn(this.optCompleteServerCache_,!0,!1):this.viewCache_.getServerCache();return this.writes_.calcCompleteChild(t,n)},Xn.prototype.getChildAfterChild=function(t,e,n){var r=null!=this.optCompleteServerCache_?this.optCompleteServerCache_:this.viewCache_.getCompleteServerSnap(),i=this.writes_.calcIndexedSlice(r,e,1,n,t);return 0===i.length?null:i[0]},Xn);function Xn(t,e,n){void 0===n&&(n=null),this.writes_=t,this.viewCache_=e,this.optCompleteServerCache_=n}var $n=function(t,e){this.viewCache=t,this.changes=e},Jn=(Zn.prototype.assertIndexed=function(t){C(t.getEventCache().getNode().isIndexed(this.filter_.getIndex()),"Event snap not indexed"),C(t.getServerCache().getNode().isIndexed(this.filter_.getIndex()),"Server snap not indexed")},Zn.prototype.applyOperation=function(t,e,n,r){var i,o,s=new jn;if(e.type===En.OVERWRITE){var a=e;i=a.source.fromUser?this.applyUserOverwrite_(t,a.path,a.snap,n,r,s):(C(a.source.fromServer,"Unknown source."),o=a.source.tagged||t.getServerCache().isFiltered()&&!a.path.isEmpty(),this.applyServerOverwrite_(t,a.path,a.snap,n,r,o,s))}else if(e.type===En.MERGE){var h=e;i=h.source.fromUser?this.applyUserMerge_(t,h.path,h.children,n,r,s):(C(h.source.fromServer,"Unknown source."),o=h.source.tagged||t.getServerCache().isFiltered(),this.applyServerMerge_(t,h.path,h.children,n,r,o,s))}else if(e.type===En.ACK_USER_WRITE){var l=e;i=l.revert?this.revertUserWrite_(t,l.path,n,r,s):this.ackUserWrite_(t,l.path,l.affectedTree,n,r,s)}else{if(e.type!==En.LISTEN_COMPLETE)throw c("Unknown operation type: "+e.type);i=this.listenComplete_(t,e.path,n,s)}var u=s.getChanges();return Zn.maybeAddValueEvent_(t,i,u),new $n(i,u)},Zn.maybeAddValueEvent_=function(t,e,n){var r=e.getEventCache();if(r.isFullyInitialized()){var i=r.getNode().isLeafNode()||r.getNode().isEmpty(),o=t.getCompleteEventSnap();(0<n.length||!t.getEventCache().isFullyInitialized()||i&&!r.getNode().equals(o)||!r.getNode().getPriority().equals(o.getPriority()))&&n.push(Un.valueChange(e.getCompleteEventSnap()))}},Zn.prototype.generateEventCacheAfterServerEvent_=function(t,e,n,r,i){var o=t.getEventCache();if(null!=n.shadowingWrite(e))return t;var s=void 0,a=void 0;if(e.isEmpty())if(C(t.getServerCache().isFullyInitialized(),"If change path is empty, we must have complete server data"),t.getServerCache().isFiltered()){var h=t.getCompleteServerSnap(),l=h instanceof Ke?h:Ke.EMPTY_NODE,u=n.calcCompleteEventChildren(l);s=this.filter_.updateFullNode(t.getEventCache().getNode(),u,i)}else{var c=n.calcCompleteEventCache(t.getCompleteServerSnap());s=this.filter_.updateFullNode(t.getEventCache().getNode(),c,i)}else{var p=e.getFront();if(".priority"==p){C(1==e.getLength(),"Can't have a priority with additional path components");var d=o.getNode();a=t.getServerCache().getNode();var f=n.calcEventCacheAfterServerOverwrite(e,d,a);s=null!=f?this.filter_.updatePriority(d,f):o.getNode()}else{var _=e.popFront(),y=void 0;if(o.isCompleteForChild(p)){a=t.getServerCache().getNode();var v=n.calcEventCacheAfterServerOverwrite(e,o.getNode(),a);y=null!=v?o.getNode().getImmediateChild(p).updateChild(_,v):o.getNode().getImmediateChild(p)}else y=n.calcCompleteChild(p,t.getServerCache());s=null!=y?this.filter_.updateChild(o.getNode(),p,y,_,r,i):o.getNode()}}return t.updateEventSnap(s,o.isFullyInitialized()||e.isEmpty(),this.filter_.filtersNodes())},Zn.prototype.applyServerOverwrite_=function(t,e,n,r,i,o,s){var a,h=t.getServerCache(),l=o?this.filter_:this.filter_.getIndexedFilter();if(e.isEmpty())a=l.updateFullNode(h.getNode(),n,null);else if(l.filtersNodes()&&!h.isFiltered()){var u=h.getNode().updateChild(e,n);a=l.updateFullNode(h.getNode(),u,null)}else{var c=e.getFront();if(!h.isCompleteForPath(e)&&1<e.getLength())return t;var p=e.popFront(),d=h.getNode().getImmediateChild(c).updateChild(p,n);a=".priority"==c?l.updatePriority(h.getNode(),d):l.updateChild(h.getNode(),c,d,p,zn,null)}var f=t.updateServerSnap(a,h.isFullyInitialized()||e.isEmpty(),l.filtersNodes()),_=new Gn(r,f,i);return this.generateEventCacheAfterServerEvent_(f,e,r,_,s)},Zn.prototype.applyUserOverwrite_=function(t,e,n,r,i,o){var s,a,h=t.getEventCache(),l=new Gn(r,t,i);if(e.isEmpty())a=this.filter_.updateFullNode(t.getEventCache().getNode(),n,o),s=t.updateEventSnap(a,!0,this.filter_.filtersNodes());else{var u=e.getFront();if(".priority"===u)a=this.filter_.updatePriority(t.getEventCache().getNode(),n),s=t.updateEventSnap(a,h.isFullyInitialized(),h.isFiltered());else{var c=e.popFront(),p=h.getNode().getImmediateChild(u),d=void 0;if(c.isEmpty())d=n;else{var f=l.getCompleteChild(u);d=null!=f?".priority"===c.getBack()&&f.getChild(c.parent()).isEmpty()?f:f.updateChild(c,n):Ke.EMPTY_NODE}if(p.equals(d))s=t;else{var _=this.filter_.updateChild(h.getNode(),u,d,c,l,o);s=t.updateEventSnap(_,h.isFullyInitialized(),this.filter_.filtersNodes())}}}return s},Zn.cacheHasChild_=function(t,e){return t.getEventCache().isCompleteForChild(e)},Zn.prototype.applyUserMerge_=function(r,i,t,o,s,a){var h=this,l=r;return t.foreach(function(t,e){var n=i.child(t);Zn.cacheHasChild_(r,n.getFront())&&(l=h.applyUserOverwrite_(l,n,e,o,s,a))}),t.foreach(function(t,e){var n=i.child(t);Zn.cacheHasChild_(r,n.getFront())||(l=h.applyUserOverwrite_(l,n,e,o,s,a))}),l},Zn.prototype.applyMerge_=function(n,t){return t.foreach(function(t,e){n=n.updateChild(t,e)}),n},Zn.prototype.applyServerMerge_=function(o,t,e,s,a,h,l){var u=this;if(o.getServerCache().getNode().isEmpty()&&!o.getServerCache().isFullyInitialized())return o;var n,c=o;n=t.isEmpty()?e:Pn.Empty.setTree(t,e);var p=o.getServerCache().getNode();return n.children.inorderTraversal(function(t,e){if(p.hasChild(t)){var n=o.getServerCache().getNode().getImmediateChild(t),r=u.applyMerge_(n,e);c=u.applyServerOverwrite_(c,new It(t),r,s,a,h,l)}}),n.children.inorderTraversal(function(t,e){var n=!o.getServerCache().isCompleteForChild(t)&&null==e.value;if(!p.hasChild(t)&&!n){var r=o.getServerCache().getNode().getImmediateChild(t),i=u.applyMerge_(r,e);c=u.applyServerOverwrite_(c,new It(t),i,s,a,h,l)}}),c},Zn.prototype.ackUserWrite_=function(t,r,e,n,i,o){if(null!=n.shadowingWrite(r))return t;var s=t.getServerCache().isFiltered(),a=t.getServerCache();if(null!=e.value){if(r.isEmpty()&&a.isFullyInitialized()||a.isCompleteForPath(r))return this.applyServerOverwrite_(t,r,a.getNode().getChild(r),n,i,s,o);if(r.isEmpty()){var h=Pn.Empty;return a.getNode().forEachChild(_e,function(t,e){h=h.set(new It(t),e)}),this.applyServerMerge_(t,r,h,n,i,s,o)}return t}var l=Pn.Empty;return e.foreach(function(t,e){var n=r.child(t);a.isCompleteForPath(n)&&(l=l.set(t,a.getNode().getChild(n)))}),this.applyServerMerge_(t,r,l,n,i,s,o)},Zn.prototype.listenComplete_=function(t,e,n,r){var i=t.getServerCache(),o=t.updateServerSnap(i.getNode(),i.isFullyInitialized()||e.isEmpty(),i.isFiltered());return this.generateEventCacheAfterServerEvent_(o,e,n,zn,r)},Zn.prototype.revertUserWrite_=function(t,e,n,r,i){var o;if(null!=n.shadowingWrite(e))return t;var s=new Gn(n,t,r),a=t.getEventCache().getNode(),h=void 0;if(e.isEmpty()||".priority"===e.getFront()){var l=void 0;if(t.getServerCache().isFullyInitialized())l=n.calcCompleteEventCache(t.getCompleteServerSnap());else{var u=t.getServerCache().getNode();C(u instanceof Ke,"serverChildren would be complete if leaf node"),l=n.calcCompleteEventChildren(u)}l=l,h=this.filter_.updateFullNode(a,l,i)}else{var c=e.getFront(),p=n.calcCompleteChild(c,t.getServerCache());null==p&&t.getServerCache().isCompleteForChild(c)&&(p=a.getImmediateChild(c)),(h=null!=p?this.filter_.updateChild(a,c,p,e.popFront(),s,i):t.getEventCache().getNode().hasChild(c)?this.filter_.updateChild(a,c,Ke.EMPTY_NODE,e.popFront(),s,i):a).isEmpty()&&t.getServerCache().isFullyInitialized()&&(o=n.calcCompleteEventCache(t.getCompleteServerSnap())).isLeafNode()&&(h=this.filter_.updateFullNode(h,o,i))}return o=t.getServerCache().isFullyInitialized()||null!=n.shadowingWrite(It.Empty),t.updateEventSnap(h,o,this.filter_.filtersNodes())},Zn);function Zn(t){this.filter_=t}var tr=(er.prototype.generateEventsForChanges=function(t,e,n){var r=this,i=[],o=[];return t.forEach(function(t){t.type===Un.CHILD_CHANGED&&r.index_.indexedValueChanged(t.oldSnap,t.snapshotNode)&&o.push(Un.childMovedChange(t.childName,t.snapshotNode))}),this.generateEventsForType_(i,Un.CHILD_REMOVED,t,n,e),this.generateEventsForType_(i,Un.CHILD_ADDED,t,n,e),this.generateEventsForType_(i,Un.CHILD_MOVED,o,n,e),this.generateEventsForType_(i,Un.CHILD_CHANGED,t,n,e),this.generateEventsForType_(i,Un.VALUE,t,n,e),i},er.prototype.generateEventsForType_=function(r,e,t,i,o){var s=this,n=t.filter(function(t){return t.type===e});n.sort(this.compareChanges_.bind(this)),n.forEach(function(e){var n=s.materializeSingleChange_(e,o);i.forEach(function(t){t.respondsTo(e.type)&&r.push(t.createEvent(n,s.query_))})})},er.prototype.materializeSingleChange_=function(t,e){return"value"===t.type||"child_removed"===t.type||(t.prevName=e.getPredecessorChildName(t.childName,t.snapshotNode,this.index_)),t},er.prototype.compareChanges_=function(t,e){if(null==t.childName||null==e.childName)throw c("Should only compare child_ events.");var n=new se(t.childName,t.snapshotNode),r=new se(e.childName,e.snapshotNode);return this.index_.compare(n,r)},er);function er(t){this.query_=t,this.index_=this.query_.getQueryParams().getIndex()}var nr,rr=(ir.prototype.getQuery=function(){return this.query_},ir.prototype.getServerCache=function(){return this.viewCache_.getServerCache().getNode()},ir.prototype.getCompleteServerCache=function(t){var e=this.viewCache_.getCompleteServerSnap();return e&&(this.query_.getQueryParams().loadsAllData()||!t.isEmpty()&&!e.getImmediateChild(t.getFront()).isEmpty())?e.getChild(t):null},ir.prototype.isEmpty=function(){return 0===this.eventRegistrations_.length},ir.prototype.addEventRegistration=function(t){this.eventRegistrations_.push(t)},ir.prototype.removeEventRegistration=function(t,n){var r=[];if(n){C(null==t,"A cancel should cancel all event registrations.");var i=this.query_.path;this.eventRegistrations_.forEach(function(t){n=n;var e=t.createCancelEvent(n,i);e&&r.push(e)})}if(t){for(var e=[],o=0;o<this.eventRegistrations_.length;++o){var s=this.eventRegistrations_[o];if(s.matches(t)){if(t.hasAnyCallback()){e=e.concat(this.eventRegistrations_.slice(o+1));break}}else e.push(s)}this.eventRegistrations_=e}else this.eventRegistrations_=[];return r},ir.prototype.applyOperation=function(t,e,n){t.type===En.MERGE&&null!==t.source.queryId&&(C(this.viewCache_.getCompleteServerSnap(),"We should always have a full cache before handling merges"),C(this.viewCache_.getCompleteEventSnap(),"Missing event cache, even though we have a server cache"));var r=this.viewCache_,i=this.processor_.applyOperation(r,t,e,n);return this.processor_.assertIndexed(i.viewCache),C(i.viewCache.getServerCache().isFullyInitialized()||!r.getServerCache().isFullyInitialized(),"Once a server snap is complete, it should never go back"),this.viewCache_=i.viewCache,this.generateEventsForChanges_(i.changes,i.viewCache.getEventCache().getNode(),null)},ir.prototype.getInitialEvents=function(t){var e=this.viewCache_.getEventCache(),n=[];return e.getNode().isLeafNode()||e.getNode().forEachChild(Te,function(t,e){n.push(Un.childAddedChange(t,e))}),e.isFullyInitialized()&&n.push(Un.valueChange(e.getNode())),this.generateEventsForChanges_(n,e.getNode(),t)},ir.prototype.generateEventsForChanges_=function(t,e,n){var r=n?[n]:this.eventRegistrations_;return this.eventGenerator_.generateEventsForChanges(t,e,r)},ir);function ir(t,e){this.query_=t,this.eventRegistrations_=[];var n=this.query_.getQueryParams(),r=new Hn(n.getIndex()),i=n.getNodeFilter();this.processor_=new Jn(i);var o=e.getServerCache(),s=e.getEventCache(),a=r.updateFullNode(Ke.EMPTY_NODE,o.getNode(),null),h=i.updateFullNode(Ke.EMPTY_NODE,s.getNode(),null),l=new Mn(a,o.isFullyInitialized(),r.filtersNodes()),u=new Mn(h,s.isFullyInitialized(),i.filtersNodes());this.viewCache_=new Qn(u,l),this.eventGenerator_=new tr(this.query_)}var or=(Object.defineProperty(sr,"__referenceConstructor",{get:function(){return C(nr,"Reference.ts has not been loaded"),nr},set:function(t){C(!nr,"__referenceConstructor has already been defined"),nr=t},enumerable:!0,configurable:!0}),sr.prototype.isEmpty=function(){return 0===this.views.size},sr.prototype.applyOperation=function(t,e,n){var r,i,o=t.source.queryId;if(null!==o){var s=this.views.get(o);return C(null!=s,"SyncTree gave us an op for an invalid query."),s.applyOperation(t,e,n)}var a=[];try{for(var h=f(this.views.values()),l=h.next();!l.done;l=h.next())s=l.value,a=a.concat(s.applyOperation(t,e,n))}catch(t){r={error:t}}finally{try{l&&!l.done&&(i=h.return)&&i.call(h)}finally{if(r)throw r.error}}return a},sr.prototype.addEventRegistration=function(t,e,n,r,i){var o=t.queryIdentifier(),s=this.views.get(o);if(!s){var a=n.calcCompleteEventCache(i?r:null),h=!1;h=!!a||(a=r instanceof Ke?n.calcCompleteEventChildren(r):Ke.EMPTY_NODE,!1);var l=new Qn(new Mn(a,h,!1),new Mn(r,i,!1));s=new rr(t,l),this.views.set(o,s)}return s.addEventRegistration(e),s.getInitialEvents(e)},sr.prototype.removeEventRegistration=function(t,e,n){var r,i,o=t.queryIdentifier(),s=[],a=[],h=this.hasCompleteView();if("default"===o)try{for(var l=f(this.views.entries()),u=l.next();!u.done;u=l.next()){var c=_(u.value,2),p=c[0],d=c[1];a=a.concat(d.removeEventRegistration(e,n)),d.isEmpty()&&(this.views.delete(p),d.getQuery().getQueryParams().loadsAllData()||s.push(d.getQuery()))}}catch(t){r={error:t}}finally{try{u&&!u.done&&(i=l.return)&&i.call(l)}finally{if(r)throw r.error}}else(d=this.views.get(o))&&(a=a.concat(d.removeEventRegistration(e,n)),d.isEmpty()&&(this.views.delete(o),d.getQuery().getQueryParams().loadsAllData()||s.push(d.getQuery())));return h&&!this.hasCompleteView()&&s.push(new sr.__referenceConstructor(t.repo,t.path)),{removed:s,events:a}},sr.prototype.getQueryViews=function(){var e,t,n=[];try{for(var r=f(this.views.values()),i=r.next();!i.done;i=r.next()){var o=i.value;o.getQuery().getQueryParams().loadsAllData()||n.push(o)}}catch(t){e={error:t}}finally{try{i&&!i.done&&(t=r.return)&&t.call(r)}finally{if(e)throw e.error}}return n},sr.prototype.getCompleteServerCache=function(t){var e,n,r=null;try{for(var i=f(this.views.values()),o=i.next();!o.done;o=i.next()){var s=o.value;r=r||s.getCompleteServerCache(t)}}catch(t){e={error:t}}finally{try{o&&!o.done&&(n=i.return)&&n.call(i)}finally{if(e)throw e.error}}return r},sr.prototype.viewForQuery=function(t){if(t.getQueryParams().loadsAllData())return this.getCompleteView();var e=t.queryIdentifier();return this.views.get(e)},sr.prototype.viewExistsForQuery=function(t){return null!=this.viewForQuery(t)},sr.prototype.hasCompleteView=function(){return null!=this.getCompleteView()},sr.prototype.getCompleteView=function(){var e,t;try{for(var n=f(this.views.values()),r=n.next();!r.done;r=n.next()){var i=r.value;if(i.getQuery().getQueryParams().loadsAllData())return i}}catch(t){e={error:t}}finally{try{r&&!r.done&&(t=n.return)&&t.call(n)}finally{if(e)throw e.error}}return null},sr);function sr(){this.views=new Map}var ar=(hr.prototype.addWrite=function(t,e){if(t.isEmpty())return new hr(new Pn(e));var n=this.writeTree_.findRootMostValueAndPath(t);if(null!=n){var r=n.path,i=n.value,o=It.relativePath(r,t);return i=i.updateChild(o,e),new hr(this.writeTree_.set(r,i))}var s=new Pn(e);return new hr(this.writeTree_.setTree(t,s))},hr.prototype.addWrites=function(n,t){var r=this;return Ct(t,function(t,e){r=r.addWrite(n.child(t),e)}),r},hr.prototype.removeWrite=function(t){return t.isEmpty()?hr.Empty:new hr(this.writeTree_.setTree(t,Pn.Empty))},hr.prototype.hasCompleteWrite=function(t){return null!=this.getCompleteNode(t)},hr.prototype.getCompleteNode=function(t){var e=this.writeTree_.findRootMostValueAndPath(t);return null!=e?this.writeTree_.get(e.path).getChild(It.relativePath(e.path,t)):null},hr.prototype.getCompleteChildren=function(){var n=[],t=this.writeTree_.value;return null!=t?t.isLeafNode()||t.forEachChild(Te,function(t,e){n.push(new se(t,e))}):this.writeTree_.children.inorderTraversal(function(t,e){null!=e.value&&n.push(new se(t,e.value))}),n},hr.prototype.childCompoundWrite=function(t){if(t.isEmpty())return this;var e=this.getCompleteNode(t);return new hr(null!=e?new Pn(e):this.writeTree_.subtree(t))},hr.prototype.isEmpty=function(){return this.writeTree_.isEmpty()},hr.prototype.apply=function(t){return function n(r,t,i){if(null!=t.value)return i.updateChild(r,t.value);var o=null;return t.children.inorderTraversal(function(t,e){".priority"===t?(C(null!==e.value,"Priority writes must always be leaf nodes"),o=e.value):i=n(r.child(t),e,i)}),i.getChild(r).isEmpty()||null===o||(i=i.updateChild(r.child(".priority"),o)),i}(It.Empty,this.writeTree_,t)},hr.Empty=new hr(new Pn(null)),hr);function hr(t){this.writeTree_=t}var lr=(ur.prototype.childWrites=function(t){return new cr(t,this)},ur.prototype.addOverwrite=function(t,e,n,r){C(n>this.lastWriteId_,"Stacking an older write on top of newer ones"),void 0===r&&(r=!0),this.allWrites_.push({path:t,snap:e,writeId:n,visible:r}),r&&(this.visibleWrites_=this.visibleWrites_.addWrite(t,e)),this.lastWriteId_=n},ur.prototype.addMerge=function(t,e,n){C(n>this.lastWriteId_,"Stacking an older merge on top of newer ones"),this.allWrites_.push({path:t,children:e,writeId:n,visible:!0}),this.visibleWrites_=this.visibleWrites_.addWrites(t,e),this.lastWriteId_=n},ur.prototype.getWrite=function(t){for(var e=0;e<this.allWrites_.length;e++){var n=this.allWrites_[e];if(n.writeId===t)return n}return null},ur.prototype.removeWrite=function(e){var n=this,t=this.allWrites_.findIndex(function(t){return t.writeId===e});C(0<=t,"removeWrite called with nonexistent writeId.");var r=this.allWrites_[t];this.allWrites_.splice(t,1);for(var i=r.visible,o=!1,s=this.allWrites_.length-1;i&&0<=s;){var a=this.allWrites_[s];a.visible&&(t<=s&&this.recordContainsPath_(a,r.path)?i=!1:r.path.contains(a.path)&&(o=!0)),s--}return!!i&&(o?this.resetTree_():r.snap?this.visibleWrites_=this.visibleWrites_.removeWrite(r.path):Ct(r.children,function(t){n.visibleWrites_=n.visibleWrites_.removeWrite(r.path.child(t))}),!0)},ur.prototype.getCompleteWriteData=function(t){return this.visibleWrites_.getCompleteNode(t)},ur.prototype.calcCompleteEventCache=function(e,t,n,r){if(n||r){var i=this.visibleWrites_.childCompoundWrite(e);if(!r&&i.isEmpty())return t;if(r||null!=t||i.hasCompleteWrite(It.Empty)){var o=ur.layerTree_(this.allWrites_,function(t){return(t.visible||r)&&(!n||!~n.indexOf(t.writeId))&&(t.path.contains(e)||e.contains(t.path))},e);return h=t||Ke.EMPTY_NODE,o.apply(h)}return null}var s=this.visibleWrites_.getCompleteNode(e);if(null!=s)return s;var a=this.visibleWrites_.childCompoundWrite(e);if(a.isEmpty())return t;if(null!=t||a.hasCompleteWrite(It.Empty)){var h=t||Ke.EMPTY_NODE;return a.apply(h)}return null},ur.prototype.calcCompleteEventChildren=function(t,e){var r=Ke.EMPTY_NODE,n=this.visibleWrites_.getCompleteNode(t);if(n)return n.isLeafNode()||n.forEachChild(Te,function(t,e){r=r.updateImmediateChild(t,e)}),r;if(e){var i=this.visibleWrites_.childCompoundWrite(t);return e.forEachChild(Te,function(t,e){var n=i.childCompoundWrite(new It(t)).apply(e);r=r.updateImmediateChild(t,n)}),i.getCompleteChildren().forEach(function(t){r=r.updateImmediateChild(t.name,t.node)}),r}return this.visibleWrites_.childCompoundWrite(t).getCompleteChildren().forEach(function(t){r=r.updateImmediateChild(t.name,t.node)}),r},ur.prototype.calcEventCacheAfterServerOverwrite=function(t,e,n,r){C(n||r,"Either existingEventSnap or existingServerSnap must exist");var i=t.child(e);if(this.visibleWrites_.hasCompleteWrite(i))return null;var o=this.visibleWrites_.childCompoundWrite(i);return o.isEmpty()?r.getChild(e):o.apply(r.getChild(e))},ur.prototype.calcCompleteChild=function(t,e,n){var r=t.child(e),i=this.visibleWrites_.getCompleteNode(r);return null!=i?i:n.isCompleteForChild(e)?this.visibleWrites_.childCompoundWrite(r).apply(n.getNode().getImmediateChild(e)):null},ur.prototype.shadowingWrite=function(t){return this.visibleWrites_.getCompleteNode(t)},ur.prototype.calcIndexedSlice=function(t,e,n,r,i,o){var s,a=this.visibleWrites_.childCompoundWrite(t),h=a.getCompleteNode(It.Empty);if(null!=h)s=h;else{if(null==e)return[];s=a.apply(e)}if((s=s.withIndex(o)).isEmpty()||s.isLeafNode())return[];for(var l=[],u=o.getCompare(),c=i?s.getReverseIteratorFrom(n,o):s.getIteratorFrom(n,o),p=c.getNext();p&&l.length<r;)0!==u(p,n)&&l.push(p),p=c.getNext();return l},ur.prototype.recordContainsPath_=function(t,e){if(t.snap)return t.path.contains(e);for(var n in t.children)if(t.children.hasOwnProperty(n)&&t.path.child(n).contains(e))return!0;return!1},ur.prototype.resetTree_=function(){this.visibleWrites_=ur.layerTree_(this.allWrites_,ur.DefaultFilter_,It.Empty),0<this.allWrites_.length?this.lastWriteId_=this.allWrites_[this.allWrites_.length-1].writeId:this.lastWriteId_=-1},ur.DefaultFilter_=function(t){return t.visible},ur.layerTree_=function(t,e,n){for(var r=ar.Empty,i=0;i<t.length;++i){var o=t[i];if(e(o)){var s=o.path,a=void 0;if(o.snap)n.contains(s)?(a=It.relativePath(n,s),r=r.addWrite(a,o.snap)):s.contains(n)&&(a=It.relativePath(s,n),r=r.addWrite(It.Empty,o.snap.getChild(a)));else{if(!o.children)throw c("WriteRecord should have .snap or .children");if(n.contains(s))a=It.relativePath(n,s),r=r.addWrites(a,o.children);else if(s.contains(n))if((a=It.relativePath(s,n)).isEmpty())r=r.addWrites(It.Empty,o.children);else{var h=R(o.children,a.getFront());if(h){var l=h.getChild(a.popFront());r=r.addWrite(It.Empty,l)}}}}}return r},ur);function ur(){this.visibleWrites_=ar.Empty,this.allWrites_=[],this.lastWriteId_=-1}var cr=(pr.prototype.calcCompleteEventCache=function(t,e,n){return this.writeTree_.calcCompleteEventCache(this.treePath_,t,e,n)},pr.prototype.calcCompleteEventChildren=function(t){return this.writeTree_.calcCompleteEventChildren(this.treePath_,t)},pr.prototype.calcEventCacheAfterServerOverwrite=function(t,e,n){return this.writeTree_.calcEventCacheAfterServerOverwrite(this.treePath_,t,e,n)},pr.prototype.shadowingWrite=function(t){return this.writeTree_.shadowingWrite(this.treePath_.child(t))},pr.prototype.calcIndexedSlice=function(t,e,n,r,i){return this.writeTree_.calcIndexedSlice(this.treePath_,t,e,n,r,i)},pr.prototype.calcCompleteChild=function(t,e){return this.writeTree_.calcCompleteChild(this.treePath_,t,e)},pr.prototype.child=function(t){return new pr(this.treePath_.child(t),this.writeTree_)},pr);function pr(t,e){this.treePath_=t,this.writeTree_=e}var dr=(fr.prototype.applyUserOverwrite=function(t,e,n,r){return this.pendingWriteTree_.addOverwrite(t,e,n,r),r?this.applyOperationToSyncPoints_(new kn(Sn.User,t,e)):[]},fr.prototype.applyUserMerge=function(t,e,n){this.pendingWriteTree_.addMerge(t,e,n);var r=Pn.fromObject(e);return this.applyOperationToSyncPoints_(new An(Sn.User,t,r))},fr.prototype.ackUserWrite=function(t,e){void 0===e&&(e=!1);var n=this.pendingWriteTree_.getWrite(t);if(this.pendingWriteTree_.removeWrite(t)){var r=Pn.Empty;return null!=n.snap?r=r.set(It.Empty,!0):Ct(n.children,function(t,e){r=r.set(new It(t),e)}),this.applyOperationToSyncPoints_(new Nn(n.path,r,e))}return[]},fr.prototype.applyServerOverwrite=function(t,e){return this.applyOperationToSyncPoints_(new kn(Sn.Server,t,e))},fr.prototype.applyServerMerge=function(t,e){var n=Pn.fromObject(e);return this.applyOperationToSyncPoints_(new An(Sn.Server,t,n))},fr.prototype.applyListenComplete=function(t){return this.applyOperationToSyncPoints_(new On(Sn.Server,t))},fr.prototype.applyTaggedQueryOverwrite=function(t,e,n){var r=this.queryKeyForTag_(n);if(null==r)return[];var i=fr.parseQueryKey_(r),o=i.path,s=i.queryId,a=It.relativePath(o,t),h=new kn(Sn.forServerTaggedQuery(s),a,e);return this.applyTaggedOperation_(o,h)},fr.prototype.applyTaggedQueryMerge=function(t,e,n){var r=this.queryKeyForTag_(n);if(r){var i=fr.parseQueryKey_(r),o=i.path,s=i.queryId,a=It.relativePath(o,t),h=Pn.fromObject(e),l=new An(Sn.forServerTaggedQuery(s),a,h);return this.applyTaggedOperation_(o,l)}return[]},fr.prototype.applyTaggedListenComplete=function(t,e){var n=this.queryKeyForTag_(e);if(n){var r=fr.parseQueryKey_(n),i=r.path,o=r.queryId,s=It.relativePath(i,t),a=new On(Sn.forServerTaggedQuery(o),s);return this.applyTaggedOperation_(i,a)}return[]},fr.prototype.addEventRegistration=function(t,e){var r=t.path,i=null,o=!1;this.syncPointTree_.foreachOnPath(r,function(t,e){var n=It.relativePath(t,r);i=i||e.getCompleteServerCache(n),o=o||e.hasCompleteView()});var n,s=this.syncPointTree_.get(r);s?(o=o||s.hasCompleteView(),i=i||s.getCompleteServerCache(It.Empty)):(s=new or,this.syncPointTree_=this.syncPointTree_.set(r,s)),null!=i?n=!0:(n=!1,i=Ke.EMPTY_NODE,this.syncPointTree_.subtree(r).foreachChild(function(t,e){var n=e.getCompleteServerCache(It.Empty);n&&(i=i.updateImmediateChild(t,n))}));var a=s.viewExistsForQuery(t);if(!a&&!t.getQueryParams().loadsAllData()){var h=fr.makeQueryKey_(t);C(!this.queryToTagMap.has(h),"View does not exist, but we have a tag");var l=fr.getNextQueryTag_();this.queryToTagMap.set(h,l),this.tagToQueryMap.set(l,h)}var u=this.pendingWriteTree_.childWrites(r),c=s.addEventRegistration(t,e,u,i,n);if(!a&&!o){var p=s.viewForQuery(t);c=c.concat(this.setupListener_(t,p))}return c},fr.prototype.removeEventRegistration=function(t,e,n){var r=this,i=t.path,o=this.syncPointTree_.get(i),s=[];if(o&&("default"===t.queryIdentifier()||o.viewExistsForQuery(t))){var a=o.removeEventRegistration(t,e,n);o.isEmpty()&&(this.syncPointTree_=this.syncPointTree_.remove(i));var h=a.removed;s=a.events;var l=-1!==h.findIndex(function(t){return t.getQueryParams().loadsAllData()}),u=this.syncPointTree_.findOnPath(i,function(t,e){return e.hasCompleteView()});if(l&&!u){var c=this.syncPointTree_.subtree(i);if(!c.isEmpty())for(var p=this.collectDistinctViewsForSubTree_(c),d=0;d<p.length;++d){var f=p[d],_=f.getQuery(),y=this.createListenerForView_(f);this.listenProvider_.startListening(fr.queryForListening_(_),this.tagForQuery_(_),y.hashFn,y.onComplete)}}!u&&0<h.length&&!n&&(l?this.listenProvider_.stopListening(fr.queryForListening_(t),null):h.forEach(function(t){var e=r.queryToTagMap.get(fr.makeQueryKey_(t));r.listenProvider_.stopListening(fr.queryForListening_(t),e)})),this.removeTags_(h)}return s},fr.prototype.calcCompleteEventCache=function(i,t){var e=this.pendingWriteTree_,n=this.syncPointTree_.findOnPath(i,function(t,e){var n=It.relativePath(t,i),r=e.getCompleteServerCache(n);if(r)return r});return e.calcCompleteEventCache(i,n,t,!0)},fr.prototype.collectDistinctViewsForSubTree_=function(t){return t.fold(function(t,e,n){if(e&&e.hasCompleteView())return[e.getCompleteView()];var r=[];return e&&(r=e.getQueryViews()),Ct(n,function(t,e){r=r.concat(e)}),r})},fr.prototype.removeTags_=function(t){for(var e=0;e<t.length;++e){var n=t[e];if(!n.getQueryParams().loadsAllData()){var r=fr.makeQueryKey_(n),i=this.queryToTagMap.get(r);this.queryToTagMap.delete(r),this.tagToQueryMap.delete(i)}}},fr.queryForListening_=function(t){return t.getQueryParams().loadsAllData()&&!t.getQueryParams().isDefault()?t.getRef():t},fr.prototype.setupListener_=function(t,e){var n=t.path,r=this.tagForQuery_(t),i=this.createListenerForView_(e),o=this.listenProvider_.startListening(fr.queryForListening_(t),r,i.hashFn,i.onComplete),s=this.syncPointTree_.subtree(n);if(r)C(!s.value.hasCompleteView(),"If we're adding a query, it shouldn't be shadowed");else for(var a=s.fold(function(t,e,n){if(!t.isEmpty()&&e&&e.hasCompleteView())return[e.getCompleteView().getQuery()];var r=[];return e&&(r=r.concat(e.getQueryViews().map(function(t){return t.getQuery()}))),Ct(n,function(t,e){r=r.concat(e)}),r}),h=0;h<a.length;++h){var l=a[h];this.listenProvider_.stopListening(fr.queryForListening_(l),this.tagForQuery_(l))}return o},fr.prototype.createListenerForView_=function(t){var n=this,r=t.getQuery(),i=this.tagForQuery_(r);return{hashFn:function(){return(t.getServerCache()||Ke.EMPTY_NODE).hash()},onComplete:function(t){if("ok"===t)return i?n.applyTaggedListenComplete(r.path,i):n.applyListenComplete(r.path);var e=function(t,e){var n="Unknown Error";"too_big"===t?n="The data requested exceeds the maximum size that can be accessed with a single request.":"permission_denied"==t?n="Client doesn't have permission to access the desired data.":"unavailable"==t&&(n="The service is unavailable");var r=new Error(t+" at "+e.path.toString()+": "+n);return r.code=t.toUpperCase(),r}(t,r);return n.removeEventRegistration(r,null,e)}}},fr.makeQueryKey_=function(t){return t.path.toString()+"$"+t.queryIdentifier()},fr.parseQueryKey_=function(t){var e=t.indexOf("$");return C(-1!==e&&e<t.length-1,"Bad queryKey."),{queryId:t.substr(e+1),path:new It(t.substr(0,e))}},fr.prototype.queryKeyForTag_=function(t){return this.tagToQueryMap.get(t)},fr.prototype.tagForQuery_=function(t){var e=fr.makeQueryKey_(t);return this.queryToTagMap.get(e)},fr.getNextQueryTag_=function(){return fr.nextQueryTag_++},fr.prototype.applyTaggedOperation_=function(t,e){var n=this.syncPointTree_.get(t);C(n,"Missing sync point for query tag that we're tracking");var r=this.pendingWriteTree_.childWrites(t);return n.applyOperation(e,r,null)},fr.prototype.applyOperationToSyncPoints_=function(t){return this.applyOperationHelper_(t,this.syncPointTree_,null,this.pendingWriteTree_.childWrites(It.Empty))},fr.prototype.applyOperationHelper_=function(t,e,n,r){if(t.path.isEmpty())return this.applyOperationDescendantsHelper_(t,e,n,r);var i=e.get(It.Empty);null==n&&null!=i&&(n=i.getCompleteServerCache(It.Empty));var o=[],s=t.path.getFront(),a=t.operationForChild(s),h=e.children.get(s);if(h&&a){var l=n?n.getImmediateChild(s):null,u=r.child(s);o=o.concat(this.applyOperationHelper_(a,h,l,u))}return i&&(o=o.concat(i.applyOperation(t,r,n))),o},fr.prototype.applyOperationDescendantsHelper_=function(o,t,s,a){var h=this,e=t.get(It.Empty);null==s&&null!=e&&(s=e.getCompleteServerCache(It.Empty));var l=[];return t.children.inorderTraversal(function(t,e){var n=s?s.getImmediateChild(t):null,r=a.child(t),i=o.operationForChild(t);i&&(l=l.concat(h.applyOperationDescendantsHelper_(i,e,n,r)))}),e&&(l=l.concat(e.applyOperation(o,a,s))),l},fr.nextQueryTag_=1,fr);function fr(t){this.listenProvider_=t,this.syncPointTree_=Pn.Empty,this.pendingWriteTree_=new lr,this.tagToQueryMap=new Map,this.queryToTagMap=new Map}var _r=(yr.prototype.getNode=function(t){return this.rootNode_.getChild(t)},yr.prototype.updateSnapshot=function(t,e){this.rootNode_=this.rootNode_.updateChild(t,e)},yr);function yr(){this.rootNode_=Ke.EMPTY_NODE}var vr=(gr.prototype.getToken=function(t){return this.app_.INTERNAL.getToken(t).then(null,function(t){return t&&"auth/token-not-initialized"===t.code?(J("Got auth/token-not-initialized error. Treating as null token."),null):Promise.reject(t)})},gr.prototype.addTokenChangeListener=function(t){this.app_.INTERNAL.addAuthTokenListener(t)},gr.prototype.removeTokenChangeListener=function(t){this.app_.INTERNAL.removeAuthTokenListener(t)},gr.prototype.notifyForInvalidToken=function(){var t='Provided authentication credentials for the app named "'+this.app_.name+'" are invalid. This usually indicates your app was not initialized correctly. ';"credential"in this.app_.options?t+='Make sure the "credential" property provided to initializeApp() is authorized to access the specified "databaseURL" and is from the correct project.':"serviceAccount"in this.app_.options?t+='Make sure the "serviceAccount" property provided to initializeApp() is authorized to access the specified "databaseURL" and is from the correct project.':t+='Make sure the "apiKey" and "databaseURL" properties provided to initializeApp() match the values provided for your app at https://console.firebase.google.com/.',nt(t)},gr);function gr(t){this.app_=t}var mr=function(t){this.accessToken=t},Cr=(Er.prototype.getToken=function(t){return Promise.resolve(new mr("owner"))},Er.prototype.addTokenChangeListener=function(t){},Er.prototype.removeTokenChangeListener=function(t){},Er.prototype.notifyForInvalidToken=function(){nt('Database emulator unexpectedly rejected fake "owner" credentials.')},Er);function Er(t){this.app_=t}var wr=(br.prototype.incrementCounter=function(t,e){void 0===e&&(e=1),N(this.counters_,t)||(this.counters_[t]=0),this.counters_[t]+=e},br.prototype.get=function(){return n(this.counters_)},br);function br(){this.counters_={}}var Sr=(Tr.getCollection=function(t){var e=t.toString();return this.collections_[e]||(this.collections_[e]=new wr),this.collections_[e]},Tr.getOrCreateReporter=function(t,e){var n=t.toString();return this.reporters_[n]||(this.reporters_[n]=e()),this.reporters_[n]},Tr.collections_={},Tr.reporters_={},Tr);function Tr(){}var Ir=(Nr.prototype.get=function(){var t=this.collection_.get(),n=u({},t);return this.last_&&Ct(this.last_,function(t,e){n[t]=n[t]-e}),this.last_=t,n},Nr);function Nr(t){this.collection_=t,this.last_=null}var Rr=(Pr.prototype.includeStat=function(t){this.statsToReport_[t]=!0},Pr.prototype.reportStats_=function(){var n=this,t=this.statsListener_.get(),r={},i=!1;Ct(t,function(t,e){0<e&&N(n.statsToReport_,t)&&(r[t]=e,i=!0)}),i&&this.server_.reportStats(r),bt(this.reportStats_.bind(this),Math.floor(2*Math.random()*3e5))},Pr);function Pr(t,e){this.server_=e,this.statsToReport_={},this.statsListener_=new Ir(t);var n=1e4+2e4*Math.random();bt(this.reportStats_.bind(this),Math.floor(n))}var Dr=(Or.prototype.queueEvents=function(t){for(var e=null,n=0;n<t.length;n++){var r=t[n],i=r.getPath();null===e||i.equals(e.getPath())||(this.eventLists_.push(e),e=null),null===e&&(e=new xr(i)),e.add(r)}e&&this.eventLists_.push(e)},Or.prototype.raiseEventsAtPath=function(e,t){this.queueEvents(t),this.raiseQueuedEventsMatchingPredicate_(function(t){return t.equals(e)})},Or.prototype.raiseEventsForChangedPath=function(e,t){this.queueEvents(t),this.raiseQueuedEventsMatchingPredicate_(function(t){return t.contains(e)||e.contains(t)})},Or.prototype.raiseQueuedEventsMatchingPredicate_=function(t){this.recursionDepth_++;for(var e=!0,n=0;n<this.eventLists_.length;n++){var r=this.eventLists_[n];r&&(t(r.getPath())?(this.eventLists_[n].raise(),this.eventLists_[n]=null):e=!1)}e&&(this.eventLists_=[]),this.recursionDepth_--},Or);function Or(){this.eventLists_=[],this.recursionDepth_=0}var xr=(kr.prototype.add=function(t){this.events_.push(t)},kr.prototype.raise=function(){for(var t=0;t<this.events_.length;t++){var e=this.events_[t];if(null!==e){this.events_[t]=null;var n=e.getEventRunner();ft&&J("event: "+e.toString()),wt(n)}}},kr.prototype.getPath=function(){return this.path_},kr);function kr(t){this.path_=t,this.events_=[]}var Fr=(Ar.prototype.trigger=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];if(Array.isArray(this.listeners_[t]))for(var r=o(this.listeners_[t]),i=0;i<r.length;i++)r[i].callback.apply(r[i].context,e)},Ar.prototype.on=function(t,e,n){this.validateEventType_(t),this.listeners_[t]=this.listeners_[t]||[],this.listeners_[t].push({callback:e,context:n});var r=this.getInitialEvent(t);r&&e.apply(n,r)},Ar.prototype.off=function(t,e,n){this.validateEventType_(t);for(var r=this.listeners_[t]||[],i=0;i<r.length;i++)if(r[i].callback===e&&(!n||n===r[i].context))return void r.splice(i,1)},Ar.prototype.validateEventType_=function(e){C(this.allowedEvents_.find(function(t){return t===e}),"Unknown event: "+e)},Ar);function Ar(t){this.allowedEvents_=t,this.listeners_={},C(Array.isArray(t)&&0<t.length,"Requires a non-empty array")}var Lr,Mr=(t(Wr,Lr=Fr),Wr.getInstance=function(){return new Wr},Wr.prototype.getInitialEvent=function(t){return C("visible"===t,"Unknown event type: "+t),[this.visible_]},Wr);function Wr(){var e,t,n=Lr.call(this,["visible"])||this;return"undefined"!=typeof document&&void 0!==document.addEventListener&&(void 0!==document.hidden?(t="visibilitychange",e="hidden"):void 0!==document.mozHidden?(t="mozvisibilitychange",e="mozHidden"):void 0!==document.msHidden?(t="msvisibilitychange",e="msHidden"):void 0!==document.webkitHidden&&(t="webkitvisibilitychange",e="webkitHidden")),n.visible_=!0,t&&document.addEventListener(t,function(){var t=!document[e];t!==n.visible_&&(n.visible_=t,n.trigger("visible",t))},!1),n}var Qr,qr=(t(Ur,Qr=Fr),Ur.getInstance=function(){return new Ur},Ur.prototype.getInitialEvent=function(t){return C("online"===t,"Unknown event type: "+t),[this.online_]},Ur.prototype.currentlyOnline=function(){return this.online_},Ur);function Ur(){var t=Qr.call(this,["online"])||this;return t.online_=!0,"undefined"==typeof window||void 0===window.addEventListener||d()||(window.addEventListener("online",function(){t.online_||(t.online_=!0,t.trigger("online",!0))},!1),window.addEventListener("offline",function(){t.online_&&(t.online_=!1,t.trigger("online",!1))},!1)),t}var Vr=(Hr.prototype.closeAfter=function(t,e){this.closeAfterResponse=t,this.onClose=e,this.closeAfterResponse<this.currentResponseNum&&(this.onClose(),this.onClose=null)},Hr.prototype.handleResponse=function(t,e){var r=this;this.pendingResponses[t]=e;for(var n=function(){var e=i.pendingResponses[i.currentResponseNum];delete i.pendingResponses[i.currentResponseNum];for(var t=function(t){e[t]&&wt(function(){r.onMessage_(e[t])})},n=0;n<e.length;++n)t(n);if(i.currentResponseNum===i.closeAfterResponse)return i.onClose&&(i.onClose(),i.onClose=null),"break";i.currentResponseNum++},i=this;this.pendingResponses[this.currentResponseNum]&&"break"!==n(););},Hr);function Hr(t){this.onMessage_=t,this.pendingResponses=[],this.currentResponseNum=0,this.closeAfterResponse=-1,this.onClose=null}var Br=(jr.prototype.open=function(t,e){var s=this;this.curSegmentNum=0,this.onDisconnect_=e,this.myPacketOrderer=new Vr(t),this.isClosed_=!1,this.connectTimeoutTimer_=setTimeout(function(){s.log_("Timed out trying to connect."),s.onClosed_(),s.connectTimeoutTimer_=null},Math.floor(3e4)),function(t){if("complete"===document.readyState)t();else{var e=!1,n=function(){document.body?e||(e=!0,t()):setTimeout(n,Math.floor(10))};document.addEventListener?(document.addEventListener("DOMContentLoaded",n,!1),window.addEventListener("load",n,!1)):document.attachEvent&&(document.attachEvent("onreadystatechange",function(){"complete"===document.readyState&&n()}),window.attachEvent("onload",n))}}(function(){if(!s.isClosed_){s.scriptTagHolder=new Kr(function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=_(t,5),r=n[0],i=n[1],o=n[2];if(n[3],n[4],s.incrementIncomingBytes_(t),s.scriptTagHolder)if(s.connectTimeoutTimer_&&(clearTimeout(s.connectTimeoutTimer_),s.connectTimeoutTimer_=null),s.everConnected_=!0,"start"==r)s.id=i,s.password=o;else{if("close"!==r)throw new Error("Unrecognized command received: "+r);i?(s.scriptTagHolder.sendNewPolls=!1,s.myPacketOrderer.closeAfter(i,function(){s.onClosed_()})):s.onClosed_()}},function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n=_(t,2),r=n[0],i=n[1];s.incrementIncomingBytes_(t),s.myPacketOrderer.handleResponse(r,i)},function(){s.onClosed_()},s.urlFn);var t={start:"t"};t.ser=Math.floor(1e8*Math.random()),s.scriptTagHolder.uniqueCallbackIdentifier&&(t.cb=s.scriptTagHolder.uniqueCallbackIdentifier),t.v="5",s.transportSessionId&&(t.s=s.transportSessionId),s.lastSessionId&&(t.ls=s.lastSessionId),"undefined"!=typeof location&&location.href&&-1!==location.href.indexOf(Dt)&&(t.r="f");var e=s.urlFn(t);s.log_("Connecting via long-poll to "+e),s.scriptTagHolder.addTag(e,function(){})}})},jr.prototype.start=function(){this.scriptTagHolder.startLongPoll(this.id,this.password),this.addDisconnectPingFrame(this.id,this.password)},jr.forceAllow=function(){jr.forceAllow_=!0},jr.forceDisallow=function(){jr.forceDisallow_=!0},jr.isAvailable=function(){return!!jr.forceAllow_||!(jr.forceDisallow_||"undefined"==typeof document||null==document.createElement||"object"==typeof window&&window.chrome&&window.chrome.extension&&!/^chrome/.test(window.location.href)||"object"==typeof Windows&&"object"==typeof Windows.UI)},jr.prototype.markConnectionHealthy=function(){},jr.prototype.shutdown_=function(){this.isClosed_=!0,this.scriptTagHolder&&(this.scriptTagHolder.close(),this.scriptTagHolder=null),this.myDisconnFrame&&(document.body.removeChild(this.myDisconnFrame),this.myDisconnFrame=null),this.connectTimeoutTimer_&&(clearTimeout(this.connectTimeoutTimer_),this.connectTimeoutTimer_=null)},jr.prototype.onClosed_=function(){this.isClosed_||(this.log_("Longpoll is closing itself"),this.shutdown_(),this.onDisconnect_&&(this.onDisconnect_(this.everConnected_),this.onDisconnect_=null))},jr.prototype.close=function(){this.isClosed_||(this.log_("Longpoll is being closed."),this.shutdown_())},jr.prototype.send=function(t){var e=T(t);this.bytesSent+=e.length,this.stats_.incrementCounter("bytes_sent",e.length);for(var n=function(t){var e=s(t);return l.encodeByteArray(e,!0)}(e),r=st(n,1840),i=0;i<r.length;i++)this.scriptTagHolder.enqueueSegment(this.curSegmentNum,r.length,r[i]),this.curSegmentNum++},jr.prototype.addDisconnectPingFrame=function(t,e){this.myDisconnFrame=document.createElement("iframe");var n={dframe:"t"};n.id=t,n.pw=e,this.myDisconnFrame.src=this.urlFn(n),this.myDisconnFrame.style.display="none",document.body.appendChild(this.myDisconnFrame)},jr.prototype.incrementIncomingBytes_=function(t){var e=T(t).length;this.bytesReceived+=e,this.stats_.incrementCounter("bytes_received",e)},jr);function jr(t,e,n,r){this.connId=t,this.repoInfo=e,this.transportSessionId=n,this.lastSessionId=r,this.bytesSent=0,this.bytesReceived=0,this.everConnected_=!1,this.log_=Z(t),this.stats_=Sr.getCollection(e),this.urlFn=function(t){return e.connectionURL(xt,t)}}var Kr=(Yr.createIFrame_=function(){var e=document.createElement("iframe");if(e.style.display="none",!document.body)throw"Document body has not initialized. Wait to initialize Firebase until after the document is ready.";document.body.appendChild(e);try{e.contentWindow.document||J("No IE domain setting required")}catch(t){var n=document.domain;e.src="javascript:void((function(){document.open();document.domain='"+n+"';document.close();})())"}return e.contentDocument?e.doc=e.contentDocument:e.contentWindow?e.doc=e.contentWindow.document:e.document&&(e.doc=e.document),e},Yr.prototype.close=function(){var t=this;this.alive=!1,this.myIFrame&&(this.myIFrame.doc.body.innerHTML="",setTimeout(function(){null!==t.myIFrame&&(document.body.removeChild(t.myIFrame),t.myIFrame=null)},Math.floor(0)));var e=this.onDisconnect;e&&(this.onDisconnect=null,e())},Yr.prototype.startLongPoll=function(t,e){for(this.myID=t,this.myPW=e,this.alive=!0;this.newRequest_(););},Yr.prototype.newRequest_=function(){if(this.alive&&this.sendNewPolls&&this.outstandingRequests.size<(0<this.pendingSegs.length?2:1)){this.currentSerial++;var t={};t.id=this.myID,t.pw=this.myPW,t.ser=this.currentSerial;for(var e=this.urlFn(t),n="",r=0;0<this.pendingSegs.length&&this.pendingSegs[0].d.length+30+n.length<=1870;){var i=this.pendingSegs.shift();n=n+"&seg"+r+"="+i.seg+"&ts"+r+"="+i.ts+"&d"+r+"="+i.d,r++}return e+=n,this.addLongPollTag_(e,this.currentSerial),!0}return!1},Yr.prototype.enqueueSegment=function(t,e,n){this.pendingSegs.push({seg:t,ts:e,d:n}),this.alive&&this.newRequest_()},Yr.prototype.addLongPollTag_=function(t,e){var n=this;function r(){n.outstandingRequests.delete(e),n.newRequest_()}this.outstandingRequests.add(e);var i=setTimeout(r,Math.floor(25e3));this.addTag(t,function(){clearTimeout(i),r()})},Yr.prototype.addTag=function(t,n){var r=this;setTimeout(function(){try{if(!r.sendNewPolls)return;var e=r.myIFrame.doc.createElement("script");e.type="text/javascript",e.async=!0,e.src=t,e.onload=e.onreadystatechange=function(){var t=e.readyState;t&&"loaded"!==t&&"complete"!==t||(e.onload=e.onreadystatechange=null,e.parentNode&&e.parentNode.removeChild(e),n())},e.onerror=function(){J("Long-poll script failed to load: "+t),r.sendNewPolls=!1,r.close()},r.myIFrame.doc.body.appendChild(e)}catch(t){}},Math.floor(1))},Yr);function Yr(t,e,n,r){this.onDisconnect=n,this.urlFn=r,this.outstandingRequests=new Set,this.pendingSegs=[],this.currentSerial=Math.floor(1e8*Math.random()),this.sendNewPolls=!0,this.uniqueCallbackIdentifier=pt(),window["pLPCommand"+this.uniqueCallbackIdentifier]=t,window["pRTLPCB"+this.uniqueCallbackIdentifier]=e,this.myIFrame=Yr.createIFrame_();var i="";this.myIFrame.src&&"javascript:"===this.myIFrame.src.substr(0,"javascript:".length)&&(i='<script>document.domain="'+document.domain+'";<\/script>');var o="<html><body>"+i+"</body></html>";try{this.myIFrame.doc.open(),this.myIFrame.doc.write(o),this.myIFrame.doc.close()}catch(t){J("frame writing exception"),t.stack&&J(t.stack),J(t)}}var zr="";var Gr=null;"undefined"!=typeof MozWebSocket?Gr=MozWebSocket:"undefined"!=typeof WebSocket&&(Gr=WebSocket);var Xr=($r.connectionURL_=function(t,e,n){var r={v:"5"};return"undefined"!=typeof location&&location.href&&-1!==location.href.indexOf(Dt)&&(r.r="f"),e&&(r.s=e),n&&(r.ls=n),t.connectionURL(Ot,r)},$r.prototype.open=function(t,e){var n=this;this.onDisconnect=e,this.onMessage=t,this.log_("Websocket connecting to "+this.connURL),this.everConnected_=!1,ht.set("previous_websocket_failure",!0);try{if(y()){var r=h.NODE_ADMIN?"AdminNode":"Node",i={headers:{"User-Agent":"Firebase/5/"+zr+"/"+process.platform+"/"+r}},o=process.env,s=0==this.connURL.indexOf("wss://")?o.HTTPS_PROXY||o.https_proxy:o.HTTP_PROXY||o.http_proxy;s&&(i.proxy={origin:s}),this.mySock=new Gr(this.connURL,[],i)}else this.mySock=new Gr(this.connURL)}catch(t){this.log_("Error instantiating WebSocket.");var a=t.message||t.data;return a&&this.log_(a),void this.onClosed_()}this.mySock.onopen=function(){n.log_("Websocket connected."),n.everConnected_=!0},this.mySock.onclose=function(){n.log_("Websocket connection was disconnected."),n.mySock=null,n.onClosed_()},this.mySock.onmessage=function(t){n.handleIncomingFrame(t)},this.mySock.onerror=function(t){n.log_("WebSocket error. Closing connection.");var e=t.message||t.data;e&&n.log_(e),n.onClosed_()}},$r.prototype.start=function(){},$r.forceDisallow=function(){$r.forceDisallow_=!0},$r.isAvailable=function(){var t=!1;if("undefined"!=typeof navigator&&navigator.userAgent){var e=navigator.userAgent.match(/Android ([0-9]{0,}\.[0-9]{0,})/);e&&1<e.length&&parseFloat(e[1])<4.4&&(t=!0)}return!t&&null!==Gr&&!$r.forceDisallow_},$r.previouslyFailed=function(){return ht.isInMemoryStorage||!0===ht.get("previous_websocket_failure")},$r.prototype.markConnectionHealthy=function(){ht.remove("previous_websocket_failure")},$r.prototype.appendFrame_=function(t){if(this.frames.push(t),this.frames.length==this.totalFrames){var e=this.frames.join("");this.frames=null;var n=S(e);this.onMessage(n)}},$r.prototype.handleNewFrameCount_=function(t){this.totalFrames=t,this.frames=[]},$r.prototype.extractFrameCount_=function(t){if(C(null===this.frames,"We already have a frame buffer"),t.length<=6){var e=Number(t);if(!isNaN(e))return this.handleNewFrameCount_(e),null}return this.handleNewFrameCount_(1),t},$r.prototype.handleIncomingFrame=function(t){if(null!==this.mySock){var e=t.data;if(this.bytesReceived+=e.length,this.stats_.incrementCounter("bytes_received",e.length),this.resetKeepAlive(),null!==this.frames)this.appendFrame_(e);else{var n=this.extractFrameCount_(e);null!==n&&this.appendFrame_(n)}}},$r.prototype.send=function(t){this.resetKeepAlive();var e=T(t);this.bytesSent+=e.length,this.stats_.incrementCounter("bytes_sent",e.length);var n=st(e,16384);1<n.length&&this.sendString_(String(n.length));for(var r=0;r<n.length;r++)this.sendString_(n[r])},$r.prototype.shutdown_=function(){this.isClosed_=!0,this.keepaliveTimer&&(clearInterval(this.keepaliveTimer),this.keepaliveTimer=null),this.mySock&&(this.mySock.close(),this.mySock=null)},$r.prototype.onClosed_=function(){this.isClosed_||(this.log_("WebSocket is closing itself"),this.shutdown_(),this.onDisconnect&&(this.onDisconnect(this.everConnected_),this.onDisconnect=null))},$r.prototype.close=function(){this.isClosed_||(this.log_("WebSocket is being closed"),this.shutdown_())},$r.prototype.resetKeepAlive=function(){var t=this;clearInterval(this.keepaliveTimer),this.keepaliveTimer=setInterval(function(){t.mySock&&t.sendString_("0"),t.resetKeepAlive()},Math.floor(45e3))},$r.prototype.sendString_=function(t){try{this.mySock.send(t)}catch(t){this.log_("Exception thrown from WebSocket.send():",t.message||t.data,"Closing connection."),setTimeout(this.onClosed_.bind(this),0)}},$r.responsesRequiredToBeHealthy=2,$r.healthyTimeout=3e4,$r);function $r(t,e,n,r){this.connId=t,this.keepaliveTimer=null,this.frames=null,this.totalFrames=0,this.bytesSent=0,this.bytesReceived=0,this.log_=Z(this.connId),this.stats_=Sr.getCollection(e),this.connURL=$r.connectionURL_(e,n,r)}var Jr=(Object.defineProperty(Zr,"ALL_TRANSPORTS",{get:function(){return[Br,Xr]},enumerable:!0,configurable:!0}),Zr.prototype.initTransports_=function(t){var e,n,r=Xr&&Xr.isAvailable(),i=r&&!Xr.previouslyFailed();if(t.webSocketOnly&&(r||nt("wss:// URL used, but browser isn't known to support websockets. Trying anyway."),i=!0),i)this.transports_=[Xr];else{var o=this.transports_=[];try{for(var s=f(Zr.ALL_TRANSPORTS),a=s.next();!a.done;a=s.next()){var h=a.value;h&&h.isAvailable()&&o.push(h)}}catch(t){e={error:t}}finally{try{a&&!a.done&&(n=s.return)&&n.call(s)}finally{if(e)throw e.error}}}},Zr.prototype.initialTransport=function(){if(0<this.transports_.length)return this.transports_[0];throw new Error("No transports available")},Zr.prototype.upgradeTransport=function(){return 1<this.transports_.length?this.transports_[1]:null},Zr);function Zr(t){this.initTransports_(t)}var ti=(ei.prototype.start_=function(){var t=this,e=this.transportManager_.initialTransport();this.conn_=new e(this.nextTransportId_(),this.repoInfo_,void 0,this.lastSessionId),this.primaryResponsesRequired_=e.responsesRequiredToBeHealthy||0;var n=this.connReceiver_(this.conn_),r=this.disconnReceiver_(this.conn_);this.tx_=this.conn_,this.rx_=this.conn_,this.secondaryConn_=null,this.isHealthy_=!1,setTimeout(function(){t.conn_&&t.conn_.open(n,r)},Math.floor(0));var i=e.healthyTimeout||0;0<i&&(this.healthyTimeout_=bt(function(){t.healthyTimeout_=null,t.isHealthy_||(t.conn_&&102400<t.conn_.bytesReceived?(t.log_("Connection exceeded healthy timeout but has received "+t.conn_.bytesReceived+" bytes. Marking connection healthy."),t.isHealthy_=!0,t.conn_.markConnectionHealthy()):t.conn_&&10240<t.conn_.bytesSent?t.log_("Connection exceeded healthy timeout but has sent "+t.conn_.bytesSent+" bytes. Leaving connection alive."):(t.log_("Closing unhealthy connection after timeout."),t.close()))},Math.floor(i)))},ei.prototype.nextTransportId_=function(){return"c:"+this.id+":"+this.connectionCount++},ei.prototype.disconnReceiver_=function(e){var n=this;return function(t){e===n.conn_?n.onConnectionLost_(t):e===n.secondaryConn_?(n.log_("Secondary connection lost."),n.onSecondaryConnectionLost_()):n.log_("closing an old connection")}},ei.prototype.connReceiver_=function(e){var n=this;return function(t){2!=n.state_&&(e===n.rx_?n.onPrimaryMessageReceived_(t):e===n.secondaryConn_?n.onSecondaryMessageReceived_(t):n.log_("message on old connection"))}},ei.prototype.sendRequest=function(t){var e={t:"d",d:t};this.sendData_(e)},ei.prototype.tryCleanupConnection=function(){this.tx_===this.secondaryConn_&&this.rx_===this.secondaryConn_&&(this.log_("cleaning up and promoting a connection: "+this.secondaryConn_.connId),this.conn_=this.secondaryConn_,this.secondaryConn_=null)},ei.prototype.onSecondaryControl_=function(t){if("t"in t){var e=t.t;"a"===e?this.upgradeIfSecondaryHealthy_():"r"===e?(this.log_("Got a reset on secondary, closing it"),this.secondaryConn_.close(),this.tx_!==this.secondaryConn_&&this.rx_!==this.secondaryConn_||this.close()):"o"===e&&(this.log_("got pong on secondary."),this.secondaryResponsesRequired_--,this.upgradeIfSecondaryHealthy_())}},ei.prototype.onSecondaryMessageReceived_=function(t){var e=ot("t",t),n=ot("d",t);if("c"==e)this.onSecondaryControl_(n);else{if("d"!=e)throw new Error("Unknown protocol layer: "+e);this.pendingDataMessages.push(n)}},ei.prototype.upgradeIfSecondaryHealthy_=function(){this.secondaryResponsesRequired_<=0?(this.log_("Secondary connection is healthy."),this.isHealthy_=!0,this.secondaryConn_.markConnectionHealthy(),this.proceedWithUpgrade_()):(this.log_("sending ping on secondary."),this.secondaryConn_.send({t:"c",d:{t:"p",d:{}}}))},ei.prototype.proceedWithUpgrade_=function(){this.secondaryConn_.start(),this.log_("sending client ack on secondary"),this.secondaryConn_.send({t:"c",d:{t:"a",d:{}}}),this.log_("Ending transmission on primary"),this.conn_.send({t:"c",d:{t:"n",d:{}}}),this.tx_=this.secondaryConn_,this.tryCleanupConnection()},ei.prototype.onPrimaryMessageReceived_=function(t){var e=ot("t",t),n=ot("d",t);"c"==e?this.onControl_(n):"d"==e&&this.onDataMessage_(n)},ei.prototype.onDataMessage_=function(t){this.onPrimaryResponse_(),this.onMessage_(t)},ei.prototype.onPrimaryResponse_=function(){this.isHealthy_||(this.primaryResponsesRequired_--,this.primaryResponsesRequired_<=0&&(this.log_("Primary connection is healthy."),this.isHealthy_=!0,this.conn_.markConnectionHealthy()))},ei.prototype.onControl_=function(t){var e=ot("t",t);if("d"in t){var n=t.d;if("h"===e)this.onHandshake_(n);else if("n"===e){this.log_("recvd end transmission on primary"),this.rx_=this.secondaryConn_;for(var r=0;r<this.pendingDataMessages.length;++r)this.onDataMessage_(this.pendingDataMessages[r]);this.pendingDataMessages=[],this.tryCleanupConnection()}else"s"===e?this.onConnectionShutdown_(n):"r"===e?this.onReset_(n):"e"===e?tt("Server Error: "+n):"o"===e?(this.log_("got pong on primary."),this.onPrimaryResponse_(),this.sendPingOnPrimaryIfNecessary_()):tt("Unknown control packet command: "+e)}},ei.prototype.onHandshake_=function(t){var e=t.ts,n=t.v,r=t.h;this.sessionId=t.s,this.repoInfo_.updateHost(r),0==this.state_&&(this.conn_.start(),this.onConnectionEstablished_(this.conn_,e),"5"!==n&&nt("Protocol version mismatch detected"),this.tryStartUpgrade_())},ei.prototype.tryStartUpgrade_=function(){var t=this.transportManager_.upgradeTransport();t&&this.startUpgrade_(t)},ei.prototype.startUpgrade_=function(t){var e=this;this.secondaryConn_=new t(this.nextTransportId_(),this.repoInfo_,this.sessionId),this.secondaryResponsesRequired_=t.responsesRequiredToBeHealthy||0;var n=this.connReceiver_(this.secondaryConn_),r=this.disconnReceiver_(this.secondaryConn_);this.secondaryConn_.open(n,r),bt(function(){e.secondaryConn_&&(e.log_("Timed out trying to upgrade."),e.secondaryConn_.close())},Math.floor(6e4))},ei.prototype.onReset_=function(t){this.log_("Reset packet received. New host: "+t),this.repoInfo_.updateHost(t),1===this.state_?this.close():(this.closeConnections_(),this.start_())},ei.prototype.onConnectionEstablished_=function(t,e){var n=this;this.log_("Realtime connection established."),this.conn_=t,this.state_=1,this.onReady_&&(this.onReady_(e,this.sessionId),this.onReady_=null),0===this.primaryResponsesRequired_?(this.log_("Primary connection is healthy."),this.isHealthy_=!0):bt(function(){n.sendPingOnPrimaryIfNecessary_()},Math.floor(5e3))},ei.prototype.sendPingOnPrimaryIfNecessary_=function(){this.isHealthy_||1!==this.state_||(this.log_("sending ping on primary."),this.sendData_({t:"c",d:{t:"p",d:{}}}))},ei.prototype.onSecondaryConnectionLost_=function(){var t=this.secondaryConn_;this.secondaryConn_=null,this.tx_!==t&&this.rx_!==t||this.close()},ei.prototype.onConnectionLost_=function(t){this.conn_=null,t||0!==this.state_?1===this.state_&&this.log_("Realtime connection lost."):(this.log_("Realtime connection failed."),this.repoInfo_.isCacheableHost()&&(ht.remove("host:"+this.repoInfo_.host),this.repoInfo_.internalHost=this.repoInfo_.host)),this.close()},ei.prototype.onConnectionShutdown_=function(t){this.log_("Connection shutdown command received. Shutting down..."),this.onKill_&&(this.onKill_(t),this.onKill_=null),this.onDisconnect_=null,this.close()},ei.prototype.sendData_=function(t){if(1!==this.state_)throw"Connection is not connected";this.tx_.send(t)},ei.prototype.close=function(){2!==this.state_&&(this.log_("Closing realtime connection."),this.state_=2,this.closeConnections_(),this.onDisconnect_&&(this.onDisconnect_(),this.onDisconnect_=null))},ei.prototype.closeConnections_=function(){this.log_("Shutting down all connections"),this.conn_&&(this.conn_.close(),this.conn_=null),this.secondaryConn_&&(this.secondaryConn_.close(),this.secondaryConn_=null),this.healthyTimeout_&&(clearTimeout(this.healthyTimeout_),this.healthyTimeout_=null)},ei);function ei(t,e,n,r,i,o,s){this.id=t,this.repoInfo_=e,this.onMessage_=n,this.onReady_=r,this.onDisconnect_=i,this.onKill_=o,this.lastSessionId=s,this.connectionCount=0,this.pendingDataMessages=[],this.state_=0,this.log_=Z("c:"+this.id+":"),this.transportManager_=new Jr(e),this.log_("Connection created"),this.start_()}var ni=(ri.prototype.put=function(t,e,n,r){},ri.prototype.merge=function(t,e,n,r){},ri.prototype.refreshAuthToken=function(t){},ri.prototype.onDisconnectPut=function(t,e,n){},ri.prototype.onDisconnectMerge=function(t,e,n){},ri.prototype.onDisconnectCancel=function(t,e){},ri.prototype.reportStats=function(t){},ri);function ri(){}var ii,oi=(t(si,ii=ni),si.prototype.sendRequest=function(t,e,n){var r=++this.requestNumber_,i={r:r,a:t,b:e};this.log_(T(i)),C(this.connected_,"sendRequest call when we're not connected not allowed."),this.realtime_.sendRequest(i),n&&(this.requestCBHash_[r]=n)},si.prototype.listen=function(t,e,n,r){var i=t.queryIdentifier(),o=t.path.toString();this.log_("Listen called for "+o+" "+i),this.listens.has(o)||this.listens.set(o,new Map),C(t.getQueryParams().isDefault()||!t.getQueryParams().loadsAllData(),"listen() called for non-default but complete query"),C(!this.listens.get(o).has(i),"listen() called twice for same path/queryId.");var s={onComplete:r,hashFn:e,query:t,tag:n};this.listens.get(o).set(i,s),this.connected_&&this.sendListen_(s)},si.prototype.sendListen_=function(r){var i=this,o=r.query,s=o.path.toString(),a=o.queryIdentifier();this.log_("Listen on "+s+" for "+a);var t={p:s};r.tag&&(t.q=o.queryObject(),t.t=r.tag),t.h=r.hashFn(),this.sendRequest("q",t,function(t){var e=t.d,n=t.s;si.warnOnListenWarnings_(e,o),(i.listens.get(s)&&i.listens.get(s).get(a))===r&&(i.log_("listen response",t),"ok"!==n&&i.removeListen_(s,a),r.onComplete&&r.onComplete(n,e))})},si.warnOnListenWarnings_=function(t,e){if(t&&"object"==typeof t&&N(t,"w")){var n=R(t,"w");if(Array.isArray(n)&&~n.indexOf("no_index")){var r='".indexOn": "'+e.getQueryParams().getIndex().toString()+'"',i=e.path.toString();nt("Using an unspecified index. Your data will be downloaded and filtered on the client. Consider adding "+r+" at "+i+" to your security rules for better performance.")}}},si.prototype.refreshAuthToken=function(t){this.authToken_=t,this.log_("Auth token refreshed"),this.authToken_?this.tryAuth():this.connected_&&this.sendRequest("unauth",{},function(){}),this.reduceReconnectDelayIfAdminCredential_(t)},si.prototype.reduceReconnectDelayIfAdminCredential_=function(t){(t&&40===t.length||function(t){var e=I(t).claims;return"object"==typeof e&&!0===e.admin}(t))&&(this.log_("Admin auth credential detected. Reducing max reconnect time."),this.maxReconnectDelay_=3e4)},si.prototype.tryAuth=function(){var r=this;if(this.connected_&&this.authToken_){var i=this.authToken_,t=function(t){var e=I(t).claims;return!!e&&"object"==typeof e&&e.hasOwnProperty("iat")}(i)?"auth":"gauth",e={cred:i};null===this.authOverride_?e.noauth=!0:"object"==typeof this.authOverride_&&(e.authvar=this.authOverride_),this.sendRequest(t,e,function(t){var e=t.s,n=t.d||"error";r.authToken_===i&&("ok"===e?r.invalidAuthTokenCount_=0:r.onAuthRevoked_(e,n))})}},si.prototype.unlisten=function(t,e){var n=t.path.toString(),r=t.queryIdentifier();this.log_("Unlisten called for "+n+" "+r),C(t.getQueryParams().isDefault()||!t.getQueryParams().loadsAllData(),"unlisten() called for non-default but complete query"),this.removeListen_(n,r)&&this.connected_&&this.sendUnlisten_(n,r,t.queryObject(),e)},si.prototype.sendUnlisten_=function(t,e,n,r){this.log_("Unlisten on "+t+" for "+e);var i={p:t};r&&(i.q=n,i.t=r),this.sendRequest("n",i)},si.prototype.onDisconnectPut=function(t,e,n){this.connected_?this.sendOnDisconnect_("o",t,e,n):this.onDisconnectRequestQueue_.push({pathString:t,action:"o",data:e,onComplete:n})},si.prototype.onDisconnectMerge=function(t,e,n){this.connected_?this.sendOnDisconnect_("om",t,e,n):this.onDisconnectRequestQueue_.push({pathString:t,action:"om",data:e,onComplete:n})},si.prototype.onDisconnectCancel=function(t,e){this.connected_?this.sendOnDisconnect_("oc",t,null,e):this.onDisconnectRequestQueue_.push({pathString:t,action:"oc",data:null,onComplete:e})},si.prototype.sendOnDisconnect_=function(t,e,n,r){var i={p:e,d:n};this.log_("onDisconnect "+t,i),this.sendRequest(t,i,function(t){r&&setTimeout(function(){r(t.s,t.d)},Math.floor(0))})},si.prototype.put=function(t,e,n,r){this.putInternal("p",t,e,n,r)},si.prototype.merge=function(t,e,n,r){this.putInternal("m",t,e,n,r)},si.prototype.putInternal=function(t,e,n,r,i){var o={p:e,d:n};void 0!==i&&(o.h=i),this.outstandingPuts_.push({action:t,request:o,onComplete:r}),this.outstandingPutCount_++;var s=this.outstandingPuts_.length-1;this.connected_?this.sendPut_(s):this.log_("Buffering put: "+e)},si.prototype.sendPut_=function(e){var n=this,r=this.outstandingPuts_[e].action,t=this.outstandingPuts_[e].request,i=this.outstandingPuts_[e].onComplete;this.outstandingPuts_[e].queued=this.connected_,this.sendRequest(r,t,function(t){n.log_(r+" response",t),delete n.outstandingPuts_[e],n.outstandingPutCount_--,0===n.outstandingPutCount_&&(n.outstandingPuts_=[]),i&&i(t.s,t.d)})},si.prototype.reportStats=function(t){var n=this;if(this.connected_){var e={c:t};this.log_("reportStats",e),this.sendRequest("s",e,function(t){if("ok"!==t.s){var e=t.d;n.log_("reportStats","Error sending stats: "+e)}})}},si.prototype.onDataMessage_=function(t){if("r"in t){this.log_("from server: "+T(t));var e=t.r,n=this.requestCBHash_[e];n&&(delete this.requestCBHash_[e],n(t.b))}else{if("error"in t)throw"A server-side error has occurred: "+t.error;"a"in t&&this.onDataPush_(t.a,t.b)}},si.prototype.onDataPush_=function(t,e){this.log_("handleServerMessage",t,e),"d"===t?this.onDataUpdate_(e.p,e.d,!1,e.t):"m"===t?this.onDataUpdate_(e.p,e.d,!0,e.t):"c"===t?this.onListenRevoked_(e.p,e.q):"ac"===t?this.onAuthRevoked_(e.s,e.d):"sd"===t?this.onSecurityDebugPacket_(e):tt("Unrecognized action received from server: "+T(t)+"\nAre you using the latest client?")},si.prototype.onReady_=function(t,e){this.log_("connection ready"),this.connected_=!0,this.lastConnectionEstablishedTime_=(new Date).getTime(),this.handleTimestamp_(t),this.lastSessionId=e,this.firstConnection_&&this.sendConnectStats_(),this.restoreState_(),this.firstConnection_=!1,this.onConnectStatus_(!0)},si.prototype.scheduleConnect_=function(t){var e=this;C(!this.realtime_,"Scheduling a connect when we're already connected/ing?"),this.establishConnectionTimer_&&clearTimeout(this.establishConnectionTimer_),this.establishConnectionTimer_=setTimeout(function(){e.establishConnectionTimer_=null,e.establishConnection_()},Math.floor(t))},si.prototype.onVisible_=function(t){t&&!this.visible_&&this.reconnectDelay_===this.maxReconnectDelay_&&(this.log_("Window became visible. Reducing delay."),this.reconnectDelay_=1e3,this.realtime_||this.scheduleConnect_(0)),this.visible_=t},si.prototype.onOnline_=function(t){t?(this.log_("Browser went online."),this.reconnectDelay_=1e3,this.realtime_||this.scheduleConnect_(0)):(this.log_("Browser went offline. Killing connection."),this.realtime_&&this.realtime_.close())},si.prototype.onRealtimeDisconnect_=function(){if(this.log_("data client disconnected"),this.connected_=!1,this.realtime_=null,this.cancelSentTransactions_(),this.requestCBHash_={},this.shouldReconnect_()){this.visible_?this.lastConnectionEstablishedTime_&&(3e4<(new Date).getTime()-this.lastConnectionEstablishedTime_&&(this.reconnectDelay_=1e3),this.lastConnectionEstablishedTime_=null):(this.log_("Window isn't visible. Delaying reconnect."),this.reconnectDelay_=this.maxReconnectDelay_,this.lastConnectionAttemptTime_=(new Date).getTime());var t=(new Date).getTime()-this.lastConnectionAttemptTime_,e=Math.max(0,this.reconnectDelay_-t);e=Math.random()*e,this.log_("Trying to reconnect in "+e+"ms"),this.scheduleConnect_(e),this.reconnectDelay_=Math.min(this.maxReconnectDelay_,1.3*this.reconnectDelay_)}this.onConnectStatus_(!1)},si.prototype.establishConnection_=function(){if(this.shouldReconnect_()){this.log_("Making a connection attempt"),this.lastConnectionAttemptTime_=(new Date).getTime(),this.lastConnectionEstablishedTime_=null;var e=this.onDataMessage_.bind(this),n=this.onReady_.bind(this),r=this.onRealtimeDisconnect_.bind(this),i=this.id+":"+si.nextConnectionId_++,o=this,s=this.lastSessionId,a=!1,h=null,l=function(){h?h.close():(a=!0,r())};this.realtime_={close:l,sendRequest:function(t){C(h,"sendRequest call when we're not connected not allowed."),h.sendRequest(t)}};var t=this.forceTokenRefresh_;this.forceTokenRefresh_=!1,this.authTokenProvider_.getToken(t).then(function(t){a?J("getToken() completed but was canceled"):(J("getToken() completed. Creating connection."),o.authToken_=t&&t.accessToken,h=new ti(i,o.repoInfo_,e,n,r,function(t){nt(t+" ("+o.repoInfo_.toString()+")"),o.interrupt("server_kill")},s))}).then(null,function(t){o.log_("Failed to get token: "+t),a||l()})}},si.prototype.interrupt=function(t){J("Interrupting connection for reason: "+t),this.interruptReasons_[t]=!0,this.realtime_?this.realtime_.close():(this.establishConnectionTimer_&&(clearTimeout(this.establishConnectionTimer_),this.establishConnectionTimer_=null),this.connected_&&this.onRealtimeDisconnect_())},si.prototype.resume=function(t){J("Resuming connection for reason: "+t),delete this.interruptReasons_[t],P(this.interruptReasons_)&&(this.reconnectDelay_=1e3,this.realtime_||this.scheduleConnect_(0))},si.prototype.handleTimestamp_=function(t){var e=t-(new Date).getTime();this.onServerInfoUpdate_({serverTimeOffset:e})},si.prototype.cancelSentTransactions_=function(){for(var t=0;t<this.outstandingPuts_.length;t++){var e=this.outstandingPuts_[t];e&&"h"in e.request&&e.queued&&(e.onComplete&&e.onComplete("disconnect"),delete this.outstandingPuts_[t],this.outstandingPutCount_--)}0===this.outstandingPutCount_&&(this.outstandingPuts_=[])},si.prototype.onListenRevoked_=function(t,e){var n;n=e?e.map(function(t){return mt(t)}).join("$"):"default";var r=this.removeListen_(t,n);r&&r.onComplete&&r.onComplete("permission_denied")},si.prototype.removeListen_=function(t,e){var n,r=new It(t).toString();if(this.listens.has(r)){var i=this.listens.get(r);n=i.get(e),i.delete(e),0===i.size&&this.listens.delete(r)}else n=void 0;return n},si.prototype.onAuthRevoked_=function(t,e){J("Auth token revoked: "+t+"/"+e),this.authToken_=null,this.forceTokenRefresh_=!0,this.realtime_.close(),"invalid_token"!==t&&"permission_denied"!==t||(this.invalidAuthTokenCount_++,3<=this.invalidAuthTokenCount_&&(this.reconnectDelay_=3e4,this.authTokenProvider_.notifyForInvalidToken()))},si.prototype.onSecurityDebugPacket_=function(t){this.securityDebugCallback_?this.securityDebugCallback_(t):"msg"in t&&console.log("FIREBASE: "+t.msg.replace("\n","\nFIREBASE: "))},si.prototype.restoreState_=function(){var e,t,n,r;this.tryAuth();try{for(var i=f(this.listens.values()),o=i.next();!o.done;o=i.next()){var s=o.value;try{for(var a=(n=void 0,f(s.values())),h=a.next();!h.done;h=a.next()){var l=h.value;this.sendListen_(l)}}catch(t){n={error:t}}finally{try{h&&!h.done&&(r=a.return)&&r.call(a)}finally{if(n)throw n.error}}}}catch(t){e={error:t}}finally{try{o&&!o.done&&(t=i.return)&&t.call(i)}finally{if(e)throw e.error}}for(var u=0;u<this.outstandingPuts_.length;u++)this.outstandingPuts_[u]&&this.sendPut_(u);for(;this.onDisconnectRequestQueue_.length;){var c=this.onDisconnectRequestQueue_.shift();this.sendOnDisconnect_(c.action,c.pathString,c.data,c.onComplete)}},si.prototype.sendConnectStats_=function(){var t={};t["sdk.js."+zr.replace(/\./g,"-")]=1,d()?t["framework.cordova"]=1:"object"==typeof navigator&&"ReactNative"===navigator.product&&(t["framework.reactnative"]=1),this.reportStats(t)},si.prototype.shouldReconnect_=function(){var t=qr.getInstance().currentlyOnline();return P(this.interruptReasons_)&&t},si.nextPersistentConnectionId_=0,si.nextConnectionId_=0,si);function si(t,e,n,r,i,o){var s=ii.call(this)||this;if(s.repoInfo_=t,s.onDataUpdate_=e,s.onConnectStatus_=n,s.onServerInfoUpdate_=r,s.authTokenProvider_=i,s.authOverride_=o,s.id=si.nextPersistentConnectionId_++,s.log_=Z("p:"+s.id+":"),s.interruptReasons_={},s.listens=new Map,s.outstandingPuts_=[],s.outstandingPutCount_=0,s.onDisconnectRequestQueue_=[],s.connected_=!1,s.reconnectDelay_=1e3,s.maxReconnectDelay_=3e5,s.securityDebugCallback_=null,s.lastSessionId=null,s.establishConnectionTimer_=null,s.visible_=!1,s.requestCBHash_={},s.requestNumber_=0,s.realtime_=null,s.authToken_=null,s.forceTokenRefresh_=!1,s.invalidAuthTokenCount_=0,s.firstConnection_=!0,s.lastConnectionAttemptTime_=null,s.lastConnectionEstablishedTime_=null,o&&!y())throw new Error("Auth override specified in options, but not supported on non Node.js platforms");return s.scheduleConnect_(0),Mr.getInstance().on("visible",s.onVisible_,s),-1===t.host.indexOf("fblocal")&&qr.getInstance().on("online",s.onOnline_,s),s}var ai,hi=(t(li,ai=ni),li.prototype.reportStats=function(t){throw new Error("Method not implemented.")},li.getListenId_=function(t,e){return void 0!==e?"tag$"+e:(C(t.getQueryParams().isDefault(),"should have a tag if it's not a default query."),t.path.toString())},li.prototype.listen=function(t,e,r,i){var o=this,s=t.path.toString();this.log_("Listen called for "+s+" "+t.queryIdentifier());var a=li.getListenId_(t,r),h={};this.listens_[a]=h;var n=t.getQueryParams().toRestQueryStringParameters();this.restRequest_(s+".json",n,function(t,e){var n=e;404===t&&(t=n=null),null===t&&o.onDataUpdate_(s,n,!1,r),R(o.listens_,a)===h&&i(t?401==t?"permission_denied":"rest_error:"+t:"ok",null)})},li.prototype.unlisten=function(t,e){var n=li.getListenId_(t,e);delete this.listens_[n]},li.prototype.refreshAuthToken=function(t){},li.prototype.restRequest_=function(i,o,s){var a=this;void 0===o&&(o={}),o.format="export",this.authTokenProvider_.getToken(!1).then(function(t){var e=t&&t.accessToken;e&&(o.auth=e);var n=(a.repoInfo_.secure?"https://":"http://")+a.repoInfo_.host+i+"?ns="+a.repoInfo_.namespace+function(t){for(var n=[],e=function(e,t){Array.isArray(t)?t.forEach(function(t){n.push(encodeURIComponent(e)+"="+encodeURIComponent(t))}):n.push(encodeURIComponent(e)+"="+encodeURIComponent(t))},r=0,i=Object.entries(t);r<i.length;r++){var o=i[r];e(o[0],o[1])}return n.length?"&"+n.join("&"):""}(o);a.log_("Sending REST request for "+n);var r=new XMLHttpRequest;r.onreadystatechange=function(){if(s&&4===r.readyState){a.log_("REST Response for "+n+" received. status:",r.status,"response:",r.responseText);var t=null;if(200<=r.status&&r.status<300){try{t=S(r.responseText)}catch(t){nt("Failed to parse JSON response for "+n+": "+r.responseText)}s(null,t)}else 401!==r.status&&404!==r.status&&nt("Got unsuccessful REST response for "+n+" Status: "+r.status),s(r.status);s=null}},r.open("GET",n,!0),r.send()})},li);function li(t,e,n){var r=ai.call(this)||this;return r.repoInfo_=t,r.onDataUpdate_=e,r.authTokenProvider_=n,r.log_=Z("p:rest:"),r.listens_={},r}var ui="repo_interrupt",ci=(pi.prototype.toString=function(){return(this.repoInfo_.secure?"https://":"http://")+this.repoInfo_.host},pi.prototype.name=function(){return this.repoInfo_.namespace},pi.prototype.serverTime=function(){var t=this.infoData_.getNode(new It(".info/serverTimeOffset")).val()||0;return(new Date).getTime()+t},pi.prototype.generateServerValues=function(){return function(t){return(t=t||{}).timestamp=t.timestamp||(new Date).getTime(),t}({timestamp:this.serverTime()})},pi.prototype.onDataUpdate_=function(t,e,n,r){this.dataUpdateCount++;var i=new It(t);e=this.interceptServerDataCallback_?this.interceptServerDataCallback_(t,e):e;var o=[];if(r)if(n){var s=D(e,function(t){return Je(t)});o=this.serverSyncTree_.applyTaggedQueryMerge(i,s,r)}else{var a=Je(e);o=this.serverSyncTree_.applyTaggedQueryOverwrite(i,a,r)}else if(n){var h=D(e,function(t){return Je(t)});o=this.serverSyncTree_.applyServerMerge(i,h)}else{var l=Je(e);o=this.serverSyncTree_.applyServerOverwrite(i,l)}var u=i;0<o.length&&(u=this.rerunTransactions_(i)),this.eventQueue_.raiseEventsForChangedPath(u,o)},pi.prototype.interceptServerData_=function(t){this.interceptServerDataCallback_=t},pi.prototype.onConnectStatus_=function(t){this.updateInfo_("connected",t),!1===t&&this.runOnDisconnectEvents_()},pi.prototype.onServerInfoUpdate_=function(t){var n=this;Ct(t,function(t,e){n.updateInfo_(t,e)})},pi.prototype.updateInfo_=function(t,e){var n=new It("/.info/"+t),r=Je(e);this.infoData_.updateSnapshot(n,r);var i=this.infoSyncTree_.applyServerOverwrite(n,r);this.eventQueue_.raiseEventsForChangedPath(n,i)},pi.prototype.getNextWriteId_=function(){return this.nextWriteId_++},pi.prototype.setWithPriority=function(i,t,e,o){var s=this;this.log_("set",{path:i.toString(),value:t,priority:e});var n=this.generateServerValues(),r=Je(t,e),a=bn(r,n),h=this.getNextWriteId_(),l=this.serverSyncTree_.applyUserOverwrite(i,a,h,!0);this.eventQueue_.queueEvents(l),this.server_.put(i.toString(),r.val(!0),function(t,e){var n="ok"===t;n||nt("set at "+i+" failed: "+t);var r=s.serverSyncTree_.ackUserWrite(h,!n);s.eventQueue_.raiseEventsForChangedPath(i,r),s.callOnCompleteCallback(o,t,e)});var u=this.abortTransactions_(i);this.rerunTransactions_(u),this.eventQueue_.raiseEventsForChangedPath(u,[])},pi.prototype.update=function(o,t,s){var a=this;this.log_("update",{path:o.toString(),value:t});var r=!0,i=this.generateServerValues(),h={};if(Ct(t,function(t,e){r=!1;var n=Je(e);h[t]=bn(n,i)}),r)J("update() called with empty data. Don't do anything."),this.callOnCompleteCallback(s,"ok");else{var l=this.getNextWriteId_(),e=this.serverSyncTree_.applyUserMerge(o,h,l);this.eventQueue_.queueEvents(e),this.server_.merge(o.toString(),t,function(t,e){var n="ok"===t;n||nt("update at "+o+" failed: "+t);var r=a.serverSyncTree_.ackUserWrite(l,!n),i=0<r.length?a.rerunTransactions_(o):o;a.eventQueue_.raiseEventsForChangedPath(i,r),a.callOnCompleteCallback(s,t,e)}),Ct(t,function(t){var e=a.abortTransactions_(o.child(t));a.rerunTransactions_(e)}),this.eventQueue_.raiseEventsForChangedPath(o,[])}},pi.prototype.runOnDisconnectEvents_=function(){var r=this;this.log_("onDisconnectEvents");var t=this.generateServerValues(),e=function(t,n){var r=new gn;return t.forEachTree(new It(""),function(t,e){r.remember(t,bn(e,n))}),r}(this.onDisconnect_,t),i=[];e.forEachTree(It.Empty,function(t,e){i=i.concat(r.serverSyncTree_.applyServerOverwrite(t,e));var n=r.abortTransactions_(t);r.rerunTransactions_(n)}),this.onDisconnect_=new gn,this.eventQueue_.raiseEventsForChangedPath(It.Empty,i)},pi.prototype.onDisconnectCancel=function(n,r){var i=this;this.server_.onDisconnectCancel(n.toString(),function(t,e){"ok"===t&&i.onDisconnect_.forget(n),i.callOnCompleteCallback(r,t,e)})},pi.prototype.onDisconnectSet=function(n,t,r){var i=this,o=Je(t);this.server_.onDisconnectPut(n.toString(),o.val(!0),function(t,e){"ok"===t&&i.onDisconnect_.remember(n,o),i.callOnCompleteCallback(r,t,e)})},pi.prototype.onDisconnectSetWithPriority=function(n,t,e,r){var i=this,o=Je(t,e);this.server_.onDisconnectPut(n.toString(),o.val(!0),function(t,e){"ok"===t&&i.onDisconnect_.remember(n,o),i.callOnCompleteCallback(r,t,e)})},pi.prototype.onDisconnectUpdate=function(r,n,i){var o=this;if(P(n))return J("onDisconnect().update() called with empty data. Don't do anything."),void this.callOnCompleteCallback(i,"ok");this.server_.onDisconnectMerge(r.toString(),n,function(t,e){"ok"===t&&Ct(n,function(t,e){var n=Je(e);o.onDisconnect_.remember(r.child(t),n)}),o.callOnCompleteCallback(i,t,e)})},pi.prototype.addEventCallbackForQuery=function(t,e){var n;n=".info"===t.path.getFront()?this.infoSyncTree_.addEventRegistration(t,e):this.serverSyncTree_.addEventRegistration(t,e),this.eventQueue_.raiseEventsAtPath(t.path,n)},pi.prototype.removeEventCallbackForQuery=function(t,e){var n;n=".info"===t.path.getFront()?this.infoSyncTree_.removeEventRegistration(t,e):this.serverSyncTree_.removeEventRegistration(t,e),this.eventQueue_.raiseEventsAtPath(t.path,n)},pi.prototype.interrupt=function(){this.persistentConnection_&&this.persistentConnection_.interrupt(ui)},pi.prototype.resume=function(){this.persistentConnection_&&this.persistentConnection_.resume(ui)},pi.prototype.stats=function(t){if(void 0===t&&(t=!1),"undefined"!=typeof console){var e;e=t?(this.statsListener_||(this.statsListener_=new Ir(this.stats_)),this.statsListener_.get()):this.stats_.get();var i=Object.keys(e).reduce(function(t,e){return Math.max(e.length,t)},0);Ct(e,function(t,e){for(var n=t,r=t.length;r<i+2;r++)n+=" ";console.log(n+e)})}},pi.prototype.statsIncrementCounter=function(t){this.stats_.incrementCounter(t),this.statsReporter_.includeStat(t)},pi.prototype.log_=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];var n="";this.persistentConnection_&&(n=this.persistentConnection_.id+":"),J.apply(void 0,o([n],t))},pi.prototype.callOnCompleteCallback=function(r,i,o){r&&wt(function(){if("ok"==i)r(null);else{var t=(i||"error").toUpperCase(),e=t;o&&(e+=": "+o);var n=new Error(e);n.code=t,r(n)}})},Object.defineProperty(pi.prototype,"database",{get:function(){return this.__database||(this.__database=new Oi(this))},enumerable:!0,configurable:!0}),pi);function pi(t,e,n){var r,s=this;if(this.repoInfo_=t,this.app=n,this.dataUpdateCount=0,this.statsListener_=null,this.eventQueue_=new Dr,this.nextWriteId_=1,this.interceptServerDataCallback_=null,this.onDisconnect_=new gn,this.persistentConnection_=null,r="undefined"!=typeof process&&process.env[ct]?new Cr(n):new vr(n),this.stats_=Sr.getCollection(t),e||0<=("object"==typeof window&&window.navigator&&window.navigator.userAgent||"").search(/googlebot|google webmaster tools|bingbot|yahoo! slurp|baiduspider|yandexbot|duckduckbot/i))this.server_=new hi(this.repoInfo_,this.onDataUpdate_.bind(this),r),setTimeout(this.onConnectStatus_.bind(this,!0),0);else{var i=n.options.databaseAuthVariableOverride;if(null!=i){if("object"!=typeof i)throw new Error("Only objects are supported for option databaseAuthVariableOverride");try{T(i)}catch(t){throw new Error("Invalid authOverride provided: "+t)}}this.persistentConnection_=new oi(this.repoInfo_,this.onDataUpdate_.bind(this),this.onConnectStatus_.bind(this),this.onServerInfoUpdate_.bind(this),r,i),this.server_=this.persistentConnection_}r.addTokenChangeListener(function(t){s.server_.refreshAuthToken(t)}),this.statsReporter_=Sr.getOrCreateReporter(t,function(){return new Rr(s.stats_,s.server_)}),this.transactions_init_(),this.infoData_=new _r,this.infoSyncTree_=new dr({startListening:function(t,e,n,r){var i=[],o=s.infoData_.getNode(t.path);return o.isEmpty()||(i=s.infoSyncTree_.applyServerOverwrite(t.path,o),setTimeout(function(){r("ok")},0)),i},stopListening:function(){}}),this.updateInfo_("connected",!1),this.serverSyncTree_=new dr({startListening:function(r,t,e,i){return s.server_.listen(r,e,t,function(t,e){var n=i(t,e);s.eventQueue_.raiseEventsForChangedPath(r.path,n)}),[]},stopListening:function(t,e){s.server_.unlisten(t,e)}})}var di=(fi.prototype.getStartPost=function(){return this.startPost_},fi.prototype.getEndPost=function(){return this.endPost_},fi.prototype.matches=function(t){return this.index_.compare(this.getStartPost(),t)<=0&&this.index_.compare(t,this.getEndPost())<=0},fi.prototype.updateChild=function(t,e,n,r,i,o){return this.matches(new se(e,n))||(n=Ke.EMPTY_NODE),this.indexedFilter_.updateChild(t,e,n,r,i,o)},fi.prototype.updateFullNode=function(t,e,n){e.isLeafNode()&&(e=Ke.EMPTY_NODE);var r=e.withIndex(this.index_);r=r.updatePriority(Ke.EMPTY_NODE);var i=this;return e.forEachChild(Te,function(t,e){i.matches(new se(t,e))||(r=r.updateImmediateChild(t,Ke.EMPTY_NODE))}),this.indexedFilter_.updateFullNode(t,r,n)},fi.prototype.updatePriority=function(t,e){return t},fi.prototype.filtersNodes=function(){return!0},fi.prototype.getIndexedFilter=function(){return this.indexedFilter_},fi.prototype.getIndex=function(){return this.index_},fi.getStartPost_=function(t){if(t.hasStart()){var e=t.getIndexStartName();return t.getIndex().makePost(t.getIndexStartValue(),e)}return t.getIndex().minPost()},fi.getEndPost_=function(t){if(t.hasEnd()){var e=t.getIndexEndName();return t.getIndex().makePost(t.getIndexEndValue(),e)}return t.getIndex().maxPost()},fi);function fi(t){this.indexedFilter_=new Hn(t.getIndex()),this.index_=t.getIndex(),this.startPost_=fi.getStartPost_(t),this.endPost_=fi.getEndPost_(t)}var _i=(yi.prototype.updateChild=function(t,e,n,r,i,o){return this.rangedFilter_.matches(new se(e,n))||(n=Ke.EMPTY_NODE),t.getImmediateChild(e).equals(n)?t:t.numChildren()<this.limit_?this.rangedFilter_.getIndexedFilter().updateChild(t,e,n,r,i,o):this.fullLimitUpdateChild_(t,e,n,i,o)},yi.prototype.updateFullNode=function(t,e,n){var r;if(e.isLeafNode()||e.isEmpty())r=Ke.EMPTY_NODE.withIndex(this.index_);else if(2*this.limit_<e.numChildren()&&e.isIndexed(this.index_)){r=Ke.EMPTY_NODE.withIndex(this.index_);var i=void 0;i=this.reverse_?e.getReverseIteratorFrom(this.rangedFilter_.getEndPost(),this.index_):e.getIteratorFrom(this.rangedFilter_.getStartPost(),this.index_);for(var o=0;i.hasNext()&&o<this.limit_;){var s=i.getNext();if(!(this.reverse_?this.index_.compare(this.rangedFilter_.getStartPost(),s)<=0:this.index_.compare(s,this.rangedFilter_.getEndPost())<=0))break;r=r.updateImmediateChild(s.name,s.node),o++}}else{r=(r=e.withIndex(this.index_)).updatePriority(Ke.EMPTY_NODE);var a=void 0,h=void 0,l=void 0;if(i=void 0,this.reverse_){i=r.getReverseIterator(this.index_),a=this.rangedFilter_.getEndPost(),h=this.rangedFilter_.getStartPost();var u=this.index_.getCompare();l=function(t,e){return u(e,t)}}else i=r.getIterator(this.index_),a=this.rangedFilter_.getStartPost(),h=this.rangedFilter_.getEndPost(),l=this.index_.getCompare();o=0;for(var c=!1;i.hasNext();)s=i.getNext(),!c&&l(a,s)<=0&&(c=!0),c&&o<this.limit_&&l(s,h)<=0?o++:r=r.updateImmediateChild(s.name,Ke.EMPTY_NODE)}return this.rangedFilter_.getIndexedFilter().updateFullNode(t,r,n)},yi.prototype.updatePriority=function(t,e){return t},yi.prototype.filtersNodes=function(){return!0},yi.prototype.getIndexedFilter=function(){return this.rangedFilter_.getIndexedFilter()},yi.prototype.getIndex=function(){return this.index_},yi.prototype.fullLimitUpdateChild_=function(t,e,n,r,i){var o;if(this.reverse_){var s=this.index_.getCompare();o=function(t,e){return s(e,t)}}else o=this.index_.getCompare();var a=t;C(a.numChildren()==this.limit_,"");var h=new se(e,n),l=this.reverse_?a.getFirstChild(this.index_):a.getLastChild(this.index_),u=this.rangedFilter_.matches(h);if(a.hasChild(e)){for(var c=a.getImmediateChild(e),p=r.getChildAfterChild(this.index_,l,this.reverse_);null!=p&&(p.name==e||a.hasChild(p.name));)p=r.getChildAfterChild(this.index_,p,this.reverse_);var d=null==p?1:o(p,h);if(u&&!n.isEmpty()&&0<=d)return null!=i&&i.trackChildChange(Un.childChangedChange(e,n,c)),a.updateImmediateChild(e,n);null!=i&&i.trackChildChange(Un.childRemovedChange(e,c));var f=a.updateImmediateChild(e,Ke.EMPTY_NODE);return null!=p&&this.rangedFilter_.matches(p)?(null!=i&&i.trackChildChange(Un.childAddedChange(p.name,p.node)),f.updateImmediateChild(p.name,p.node)):f}return n.isEmpty()?t:u&&0<=o(l,h)?(null!=i&&(i.trackChildChange(Un.childRemovedChange(l.name,l.node)),i.trackChildChange(Un.childAddedChange(e,n))),a.updateImmediateChild(e,n).updateImmediateChild(l.name,Ke.EMPTY_NODE)):t},yi);function yi(t){this.rangedFilter_=new di(t),this.index_=t.getIndex(),this.limit_=t.getLimit(),this.reverse_=!t.isViewFromLeft()}var vi=(gi.prototype.hasStart=function(){return this.startSet_},gi.prototype.isViewFromLeft=function(){return""===this.viewFrom_?this.startSet_:this.viewFrom_===gi.WIRE_PROTOCOL_CONSTANTS_.VIEW_FROM_LEFT},gi.prototype.getIndexStartValue=function(){return C(this.startSet_,"Only valid if start has been set"),this.indexStartValue_},gi.prototype.getIndexStartName=function(){return C(this.startSet_,"Only valid if start has been set"),this.startNameSet_?this.indexStartName_:yt},gi.prototype.hasEnd=function(){return this.endSet_},gi.prototype.getIndexEndValue=function(){return C(this.endSet_,"Only valid if end has been set"),this.indexEndValue_},gi.prototype.getIndexEndName=function(){return C(this.endSet_,"Only valid if end has been set"),this.endNameSet_?this.indexEndName_:vt},gi.prototype.hasLimit=function(){return this.limitSet_},gi.prototype.hasAnchoredLimit=function(){return this.limitSet_&&""!==this.viewFrom_},gi.prototype.getLimit=function(){return C(this.limitSet_,"Only valid if limit has been set"),this.limit_},gi.prototype.getIndex=function(){return this.index_},gi.prototype.copy_=function(){var t=new gi;return t.limitSet_=this.limitSet_,t.limit_=this.limit_,t.startSet_=this.startSet_,t.indexStartValue_=this.indexStartValue_,t.startNameSet_=this.startNameSet_,t.indexStartName_=this.indexStartName_,t.endSet_=this.endSet_,t.indexEndValue_=this.indexEndValue_,t.endNameSet_=this.endNameSet_,t.indexEndName_=this.indexEndName_,t.index_=this.index_,t.viewFrom_=this.viewFrom_,t},gi.prototype.limit=function(t){var e=this.copy_();return e.limitSet_=!0,e.limit_=t,e.viewFrom_="",e},gi.prototype.limitToFirst=function(t){var e=this.copy_();return e.limitSet_=!0,e.limit_=t,e.viewFrom_=gi.WIRE_PROTOCOL_CONSTANTS_.VIEW_FROM_LEFT,e},gi.prototype.limitToLast=function(t){var e=this.copy_();return e.limitSet_=!0,e.limit_=t,e.viewFrom_=gi.WIRE_PROTOCOL_CONSTANTS_.VIEW_FROM_RIGHT,e},gi.prototype.startAt=function(t,e){var n=this.copy_();return n.startSet_=!0,void 0===t&&(t=null),n.indexStartValue_=t,null!=e?(n.startNameSet_=!0,n.indexStartName_=e):(n.startNameSet_=!1,n.indexStartName_=""),n},gi.prototype.endAt=function(t,e){var n=this.copy_();return n.endSet_=!0,void 0===t&&(t=null),n.indexEndValue_=t,void 0!==e?(n.endNameSet_=!0,n.indexEndName_=e):(n.endNameSet_=!1,n.indexEndName_=""),n},gi.prototype.orderBy=function(t){var e=this.copy_();return e.index_=t,e},gi.prototype.getQueryObject=function(){var t=gi.WIRE_PROTOCOL_CONSTANTS_,e={};if(this.startSet_&&(e[t.INDEX_START_VALUE]=this.indexStartValue_,this.startNameSet_&&(e[t.INDEX_START_NAME]=this.indexStartName_)),this.endSet_&&(e[t.INDEX_END_VALUE]=this.indexEndValue_,this.endNameSet_&&(e[t.INDEX_END_NAME]=this.indexEndName_)),this.limitSet_){e[t.LIMIT]=this.limit_;var n=this.viewFrom_;""===n&&(n=this.isViewFromLeft()?t.VIEW_FROM_LEFT:t.VIEW_FROM_RIGHT),e[t.VIEW_FROM]=n}return this.index_!==Te&&(e[t.INDEX]=this.index_.toString()),e},gi.prototype.loadsAllData=function(){return!(this.startSet_||this.endSet_||this.limitSet_)},gi.prototype.isDefault=function(){return this.loadsAllData()&&this.index_==Te},gi.prototype.getNodeFilter=function(){return this.loadsAllData()?new Hn(this.getIndex()):this.hasLimit()?new _i(this):new di(this)},gi.prototype.toRestQueryStringParameters=function(){var t,e=gi.REST_QUERY_CONSTANTS_,n={};return this.isDefault()||(t=this.index_===Te?e.PRIORITY_INDEX:this.index_===en?e.VALUE_INDEX:this.index_===_e?e.KEY_INDEX:(C(this.index_ instanceof nn,"Unrecognized index type!"),this.index_.toString()),n[e.ORDER_BY]=T(t),this.startSet_&&(n[e.START_AT]=T(this.indexStartValue_),this.startNameSet_&&(n[e.START_AT]+=","+T(this.indexStartName_))),this.endSet_&&(n[e.END_AT]=T(this.indexEndValue_),this.endNameSet_&&(n[e.END_AT]+=","+T(this.indexEndName_))),this.limitSet_&&(this.isViewFromLeft()?n[e.LIMIT_TO_FIRST]=this.limit_:n[e.LIMIT_TO_LAST]=this.limit_)),n},gi.WIRE_PROTOCOL_CONSTANTS_={INDEX_START_VALUE:"sp",INDEX_START_NAME:"sn",INDEX_END_VALUE:"ep",INDEX_END_NAME:"en",LIMIT:"l",VIEW_FROM:"vf",VIEW_FROM_LEFT:"l",VIEW_FROM_RIGHT:"r",INDEX:"i"},gi.REST_QUERY_CONSTANTS_={ORDER_BY:"orderBy",PRIORITY_INDEX:"$priority",VALUE_INDEX:"$value",KEY_INDEX:"$key",START_AT:"startAt",END_AT:"endAt",LIMIT_TO_FIRST:"limitToFirst",LIMIT_TO_LAST:"limitToLast"},gi.DEFAULT=new gi,gi);function gi(){this.limitSet_=!1,this.startSet_=!1,this.startNameSet_=!1,this.endSet_=!1,this.endNameSet_=!1,this.limit_=0,this.viewFrom_="",this.indexStartValue_=null,this.indexStartName_="",this.indexEndValue_=null,this.indexEndName_="",this.index_=Te}var mi,Ci=(t(Ei,mi=yn),Ei.prototype.getKey=function(){return k("Reference.key",0,0,arguments.length),this.path.isEmpty()?null:this.path.getBack()},Ei.prototype.child=function(t){return k("Reference.child",1,1,arguments.length),"number"==typeof t?t=String(t):t instanceof It||(null===this.path.getFront()?function(t,e,n,r){n=n&&n.replace(/^\/*\.info(\/|$)/,"/"),Bt(t,e,n,r)}("Reference.child",1,t,!1):Bt("Reference.child",1,t,!1)),new Ei(this.repo,this.path.child(t))},Ei.prototype.getParent=function(){k("Reference.parent",0,0,arguments.length);var t=this.path.parent();return null===t?null:new Ei(this.repo,t)},Ei.prototype.getRoot=function(){k("Reference.root",0,0,arguments.length);for(var t=this;null!==t.getParent();)t=t.getParent();return t},Ei.prototype.databaseProp=function(){return this.repo.database},Ei.prototype.set=function(t,e){k("Reference.set",1,2,arguments.length),jt("Reference.set",this.path),Qt("Reference.set",1,t,this.path,!1),A("Reference.set",2,e,!0);var n=new p;return this.repo.setWithPriority(this.path,t,null,n.wrapCallback(e)),n.promise},Ei.prototype.update=function(t,e){if(k("Reference.update",1,2,arguments.length),jt("Reference.update",this.path),Array.isArray(t)){for(var n={},r=0;r<t.length;++r)n[""+r]=t[r];t=n,nt("Passing an Array to Firebase.update() is deprecated. Use set() if you want to overwrite the existing data, or an Object with integer keys if you really do want to only update some of the children.")}qt("Reference.update",1,t,this.path,!1),A("Reference.update",2,e,!0);var i=new p;return this.repo.update(this.path,t,i.wrapCallback(e)),i.promise},Ei.prototype.setWithPriority=function(t,e,n){if(k("Reference.setWithPriority",2,3,arguments.length),jt("Reference.setWithPriority",this.path),Qt("Reference.setWithPriority",1,t,this.path,!1),Ut("Reference.setWithPriority",2,e,!1),A("Reference.setWithPriority",3,n,!0),".length"===this.getKey()||".keys"===this.getKey())throw"Reference.setWithPriority failed: "+this.getKey()+" is a read-only object.";var r=new p;return this.repo.setWithPriority(this.path,t,e,r.wrapCallback(n)),r.promise},Ei.prototype.remove=function(t){return k("Reference.remove",0,1,arguments.length),jt("Reference.remove",this.path),A("Reference.remove",1,t,!0),this.set(null,t)},Ei.prototype.transaction=function(t,r,e){if(k("Reference.transaction",1,3,arguments.length),jt("Reference.transaction",this.path),A("Reference.transaction",1,t,!1),A("Reference.transaction",2,r,!0),function(t,e,n,r){if((!r||void 0!==n)&&"boolean"!=typeof n)throw new Error(F(t,e,r)+"must be a boolean.")}("Reference.transaction",3,e,!0),".length"===this.getKey()||".keys"===this.getKey())throw"Reference.transaction failed: "+this.getKey()+" is a read-only object.";void 0===e&&(e=!0);var i=new p;return"function"==typeof r&&i.promise.catch(function(){}),this.repo.startTransaction(this.path,t,function(t,e,n){t?i.reject(t):i.resolve(new te(e,n)),"function"==typeof r&&r(t,e,n)},e),i.promise},Ei.prototype.setPriority=function(t,e){k("Reference.setPriority",1,2,arguments.length),jt("Reference.setPriority",this.path),Ut("Reference.setPriority",1,t,!1),A("Reference.setPriority",2,e,!0);var n=new p;return this.repo.setWithPriority(this.path.child(".priority"),t,null,n.wrapCallback(e)),n.promise},Ei.prototype.push=function(t,e){k("Reference.push",0,2,arguments.length),jt("Reference.push",this.path),Qt("Reference.push",1,t,this.path,!0),A("Reference.push",2,e,!0);var n,r=this.repo.serverTime(),i=oe(r),o=this.child(i),s=this.child(i);return n=null!=t?o.set(t,e).then(function(){return s}):Promise.resolve(s),o.then=n.then.bind(n),o.catch=n.then.bind(n,void 0),"function"==typeof e&&n.catch(function(){}),o},Ei.prototype.onDisconnect=function(){return jt("Reference.onDisconnect",this.path),new Jt(this.repo,this.path)},Object.defineProperty(Ei.prototype,"database",{get:function(){return this.databaseProp()},enumerable:!0,configurable:!0}),Object.defineProperty(Ei.prototype,"key",{get:function(){return this.getKey()},enumerable:!0,configurable:!0}),Object.defineProperty(Ei.prototype,"parent",{get:function(){return this.getParent()},enumerable:!0,configurable:!0}),Object.defineProperty(Ei.prototype,"root",{get:function(){return this.getRoot()},enumerable:!0,configurable:!0}),Ei);function Ei(t,e){if(!(t instanceof ci))throw new Error("new Reference() no longer supported - use app.database().");return mi.call(this,t,e,vi.DEFAULT,!1)||this}yn.__referenceConstructor=Ci,or.__referenceConstructor=Ci;var wi,bi,Si=function(){this.children={},this.childCount=0,this.value=null},Ti=(Ii.prototype.subTree=function(t){for(var e,n=t instanceof It?t:new It(t),r=this;null!==(e=n.getFront());)r=new Ii(e,r,R(r.node_.children,e)||new Si),n=n.popFront();return r},Ii.prototype.getValue=function(){return this.node_.value},Ii.prototype.setValue=function(t){C(void 0!==t,"Cannot set value to undefined"),this.node_.value=t,this.updateParents_()},Ii.prototype.clear=function(){this.node_.value=null,this.node_.children={},this.node_.childCount=0,this.updateParents_()},Ii.prototype.hasChildren=function(){return 0<this.node_.childCount},Ii.prototype.isEmpty=function(){return null===this.getValue()&&!this.hasChildren()},Ii.prototype.forEachChild=function(n){var r=this;Ct(this.node_.children,function(t,e){n(new Ii(t,r,e))})},Ii.prototype.forEachDescendant=function(e,t,n){t&&!n&&e(this),this.forEachChild(function(t){t.forEachDescendant(e,!0,n)}),t&&n&&e(this)},Ii.prototype.forEachAncestor=function(t,e){for(var n=e?this:this.parent();null!==n;){if(t(n))return!0;n=n.parent()}return!1},Ii.prototype.forEachImmediateDescendantWithValue=function(e){this.forEachChild(function(t){null!==t.getValue()?e(t):t.forEachImmediateDescendantWithValue(e)})},Ii.prototype.path=function(){return new It(null===this.parent_?this.name_:this.parent_.path()+"/"+this.name_)},Ii.prototype.name=function(){return this.name_},Ii.prototype.parent=function(){return this.parent_},Ii.prototype.updateParents_=function(){null!==this.parent_&&this.parent_.updateChild_(this.name_,this)},Ii.prototype.updateChild_=function(t,e){var n=e.isEmpty(),r=N(this.node_.children,t);n&&r?(delete this.node_.children[t],this.node_.childCount--,this.updateParents_()):n||r||(this.node_.children[t]=e.node_,this.node_.childCount++,this.updateParents_())},Ii);function Ii(t,e,n){void 0===t&&(t=""),void 0===e&&(e=null),void 0===n&&(n=new Si),this.name_=t,this.parent_=e,this.node_=n}(bi=wi=wi||{})[bi.RUN=0]="RUN",bi[bi.SENT=1]="SENT",bi[bi.COMPLETED=2]="COMPLETED",bi[bi.SENT_NEEDS_ABORT=3]="SENT_NEEDS_ABORT",bi[bi.NEEDS_ABORT=4]="NEEDS_ABORT",ci.MAX_TRANSACTION_RETRIES_=25,ci.prototype.transactions_init_=function(){this.transactionQueueTree_=new Ti},ci.prototype.startTransaction=function(t,e,n,r){this.log_("transaction on "+t);function i(){}var o=new Ci(this,t);o.on("value",i);var s={path:t,update:e,onComplete:n,status:null,order:pt(),applyLocally:r,retryCount:0,unwatcher:function(){o.off("value",i)},abortReason:null,currentWriteId:null,currentInputSnapshot:null,currentOutputSnapshotRaw:null,currentOutputSnapshotResolved:null},a=this.getLatestState_(t);s.currentInputSnapshot=a;var h=s.update(a.val());if(void 0===h){if(s.unwatcher(),s.currentOutputSnapshotRaw=null,s.currentOutputSnapshotResolved=null,s.onComplete){var l=new on(s.currentInputSnapshot,new Ci(this,s.path),Te);s.onComplete(null,!1,l)}}else{$t("transaction failed: Data returned ",h,s.path),s.status=wi.RUN;var u=this.transactionQueueTree_.subTree(t),c=u.getValue()||[];c.push(s),u.setValue(c);var p=void 0;if("object"==typeof h&&null!==h&&N(h,".priority"))p=R(h,".priority"),C(Wt(p),"Invalid priority returned by transaction. Priority must be a valid string, finite number, server value, or null.");else p=(this.serverSyncTree_.calcCompleteEventCache(t)||Ke.EMPTY_NODE).getPriority().val();p=p;var d=this.generateServerValues(),f=Je(h,p),_=bn(f,d);s.currentOutputSnapshotRaw=f,s.currentOutputSnapshotResolved=_,s.currentWriteId=this.getNextWriteId_();var y=this.serverSyncTree_.applyUserOverwrite(t,_,s.currentWriteId,s.applyLocally);this.eventQueue_.raiseEventsForChangedPath(t,y),this.sendReadyTransactions_()}},ci.prototype.getLatestState_=function(t,e){return this.serverSyncTree_.calcCompleteEventCache(t,e)||Ke.EMPTY_NODE},ci.prototype.sendReadyTransactions_=function(t){var e=this;if(void 0===t&&(t=this.transactionQueueTree_),t||this.pruneCompletedTransactionsBelowNode_(t),null!==t.getValue()){var n=this.buildTransactionQueue_(t);C(0<n.length,"Sending zero length transaction queue"),n.every(function(t){return t.status===wi.RUN})&&this.sendTransactionQueue_(t.path(),n)}else t.hasChildren()&&t.forEachChild(function(t){e.sendReadyTransactions_(t)})},ci.prototype.sendTransactionQueue_=function(a,h){for(var l=this,t=h.map(function(t){return t.currentWriteId}),e=this.getLatestState_(a,t),n=e,r=e.hash(),i=0;i<h.length;i++){var o=h[i];C(o.status===wi.RUN,"tryToSendTransactionQueue_: items in queue should all be run."),o.status=wi.SENT,o.retryCount++;var s=It.relativePath(a,o.path);n=n.updateChild(s,o.currentOutputSnapshotRaw)}var u=n.val(!0),c=a;this.server_.put(c.toString(),u,function(t){l.log_("transaction put response",{path:c.toString(),status:t});var e=[];if("ok"===t){for(var n=[],r=0;r<h.length;r++){if(h[r].status=wi.COMPLETED,e=e.concat(l.serverSyncTree_.ackUserWrite(h[r].currentWriteId)),h[r].onComplete){var i=h[r].currentOutputSnapshotResolved,o=new Ci(l,h[r].path),s=new on(i,o,Te);n.push(h[r].onComplete.bind(null,null,!0,s))}h[r].unwatcher()}l.pruneCompletedTransactionsBelowNode_(l.transactionQueueTree_.subTree(a)),l.sendReadyTransactions_(),l.eventQueue_.raiseEventsForChangedPath(a,e);for(r=0;r<n.length;r++)wt(n[r])}else{if("datastale"===t)for(r=0;r<h.length;r++)h[r].status===wi.SENT_NEEDS_ABORT?h[r].status=wi.NEEDS_ABORT:h[r].status=wi.RUN;else{nt("transaction at "+c.toString()+" failed: "+t);for(r=0;r<h.length;r++)h[r].status=wi.NEEDS_ABORT,h[r].abortReason=t}l.rerunTransactions_(a)}},r)},ci.prototype.rerunTransactions_=function(t){var e=this.getAncestorTransactionNode_(t),n=e.path(),r=this.buildTransactionQueue_(e);return this.rerunTransactionQueue_(r,n),n},ci.prototype.rerunTransactionQueue_=function(t,e){if(0!==t.length){for(var n,r=[],i=[],o=t.filter(function(t){return t.status===wi.RUN}).map(function(t){return t.currentWriteId}),s=0;s<t.length;s++){var a=t[s],h=It.relativePath(e,a.path),l=!1,u=void 0;if(C(null!==h,"rerunTransactionsUnderNode_: relativePath should not be null."),a.status===wi.NEEDS_ABORT)l=!0,u=a.abortReason,i=i.concat(this.serverSyncTree_.ackUserWrite(a.currentWriteId,!0));else if(a.status===wi.RUN)if(a.retryCount>=ci.MAX_TRANSACTION_RETRIES_)l=!0,u="maxretry",i=i.concat(this.serverSyncTree_.ackUserWrite(a.currentWriteId,!0));else{var c=this.getLatestState_(a.path,o);a.currentInputSnapshot=c;var p=t[s].update(c.val());if(void 0!==p){$t("transaction failed: Data returned ",p,a.path);var d=Je(p);"object"==typeof p&&null!=p&&N(p,".priority")||(d=d.updatePriority(c.getPriority()));var f=a.currentWriteId,_=this.generateServerValues(),y=bn(d,_);a.currentOutputSnapshotRaw=d,a.currentOutputSnapshotResolved=y,a.currentWriteId=this.getNextWriteId_(),o.splice(o.indexOf(f),1),i=(i=i.concat(this.serverSyncTree_.applyUserOverwrite(a.path,y,a.currentWriteId,a.applyLocally))).concat(this.serverSyncTree_.ackUserWrite(f,!0))}else l=!0,u="nodata",i=i.concat(this.serverSyncTree_.ackUserWrite(a.currentWriteId,!0))}if(this.eventQueue_.raiseEventsForChangedPath(e,i),i=[],l&&(t[s].status=wi.COMPLETED,n=t[s].unwatcher,setTimeout(n,Math.floor(0)),t[s].onComplete))if("nodata"===u){var v=new Ci(this,t[s].path),g=t[s].currentInputSnapshot,m=new on(g,v,Te);r.push(t[s].onComplete.bind(null,null,!1,m))}else r.push(t[s].onComplete.bind(null,new Error(u),!1,null))}this.pruneCompletedTransactionsBelowNode_(this.transactionQueueTree_);for(s=0;s<r.length;s++)wt(r[s]);this.sendReadyTransactions_()}},ci.prototype.getAncestorTransactionNode_=function(t){for(var e,n=this.transactionQueueTree_;null!==(e=t.getFront())&&null===n.getValue();)n=n.subTree(e),t=t.popFront();return n},ci.prototype.buildTransactionQueue_=function(t){var e=[];return this.aggregateTransactionQueuesForNode_(t,e),e.sort(function(t,e){return t.order-e.order}),e},ci.prototype.aggregateTransactionQueuesForNode_=function(t,e){var n=this,r=t.getValue();if(null!==r)for(var i=0;i<r.length;i++)e.push(r[i]);t.forEachChild(function(t){n.aggregateTransactionQueuesForNode_(t,e)})},ci.prototype.pruneCompletedTransactionsBelowNode_=function(t){var e=this,n=t.getValue();if(n){for(var r=0,i=0;i<n.length;i++)n[i].status!==wi.COMPLETED&&(n[r]=n[i],r++);n.length=r,t.setValue(0<n.length?n:null)}t.forEachChild(function(t){e.pruneCompletedTransactionsBelowNode_(t)})},ci.prototype.abortTransactions_=function(t){var e=this,n=this.getAncestorTransactionNode_(t).path(),r=this.transactionQueueTree_.subTree(t);return r.forEachAncestor(function(t){e.abortTransactionsOnNode_(t)}),this.abortTransactionsOnNode_(r),r.forEachDescendant(function(t){e.abortTransactionsOnNode_(t)}),n},ci.prototype.abortTransactionsOnNode_=function(t){var e=t.getValue();if(null!==e){for(var n=[],r=[],i=-1,o=0;o<e.length;o++)if(e[o].status===wi.SENT_NEEDS_ABORT);else if(e[o].status===wi.SENT)C(i===o-1,"All SENT items should be at beginning of queue."),e[i=o].status=wi.SENT_NEEDS_ABORT,e[o].abortReason="set";else if(C(e[o].status===wi.RUN,"Unexpected transaction status in abort"),e[o].unwatcher(),r=r.concat(this.serverSyncTree_.ackUserWrite(e[o].currentWriteId,!0)),e[o].onComplete){n.push(e[o].onComplete.bind(null,new Error("set"),!1,null))}-1===i?t.setValue(null):e.length=i+1,this.eventQueue_.raiseEventsForChangedPath(t.path(),r);for(o=0;o<n.length;o++)wt(n[o])}};var Ni,Ri="databaseURL",Pi=(Di.getInstance=function(){return Ni=Ni||new Di},Di.prototype.interrupt=function(){for(var t in this.repos_)for(var e in this.repos_[t])this.repos_[t][e].interrupt()},Di.prototype.resume=function(){for(var t in this.repos_)for(var e in this.repos_[t])this.repos_[t][e].resume()},Di.prototype.databaseFromApp=function(t,e){var n=e||t.options[Ri];void 0===n&&et("Can't determine Firebase Database URL. Be sure to include "+Ri+" option when calling firebase.initializeApp().");var r=At(n),i=r.repoInfo,o=void 0;return"undefined"!=typeof process&&(o=process.env[ct]),o&&(n="http://"+o+"?ns="+i.namespace,i=(r=At(n)).repoInfo),Kt("Invalid Firebase Database URL",1,r),r.path.isEmpty()||et("Database URL must point to the root of a Firebase Database (not including a child path)."),this.createRepo(i,t).database},Di.prototype.deleteRepo=function(t){var e=R(this.repos_,t.app.name);e&&R(e,t.repoInfo_.toURLString())===t||et("Database "+t.app.name+"("+t.repoInfo_+") has already been deleted."),t.interrupt(),delete e[t.repoInfo_.toURLString()]},Di.prototype.createRepo=function(t,e){var n=R(this.repos_,e.name);n||(n={},this.repos_[e.name]=n);var r=R(n,t.toURLString());return r&&et("Database initialized multiple times. Please make sure the format of the database URL matches with each database() call."),r=new ci(t,this.useRestClient_,e),n[t.toURLString()]=r},Di.prototype.forceRestClient=function(t){this.useRestClient_=t},Di);function Di(){this.repos_={},this.useRestClient_=!1}var Oi=(Object.defineProperty(xi.prototype,"app",{get:function(){return this.repo_.app},enumerable:!0,configurable:!0}),xi.prototype.ref=function(t){return this.checkDeleted_("ref"),k("database.ref",0,1,arguments.length),t instanceof Ci?this.refFromURL(t.toString()):void 0!==t?this.root_.child(t):this.root_},xi.prototype.refFromURL=function(t){var e="database.refFromURL";this.checkDeleted_(e),k(e,1,1,arguments.length);var n=At(t);Kt(e,1,n);var r=n.repoInfo;return r.host!==this.repo_.repoInfo_.host&&et(e+": Host name does not match the current database: (found "+r.host+" but expected "+this.repo_.repoInfo_.host+")"),this.ref(n.path.toString())},xi.prototype.checkDeleted_=function(t){null===this.repo_&&et("Cannot call "+t+" on a deleted database.")},xi.prototype.goOffline=function(){k("database.goOffline",0,0,arguments.length),this.checkDeleted_("goOffline"),this.repo_.interrupt()},xi.prototype.goOnline=function(){k("database.goOnline",0,0,arguments.length),this.checkDeleted_("goOnline"),this.repo_.resume()},xi.ServerValue={TIMESTAMP:{".sv":"timestamp"}},xi);function xi(t){(this.repo_=t)instanceof ci||et("Don't call new Database() directly - please use firebase.database()."),this.root_=new Ci(t,It.Empty),this.INTERNAL=new ki(this)}var ki=(Fi.prototype.delete=function(){return function(o,s,a,h){return new(a=a||Promise)(function(t,e){function n(t){try{i(h.next(t))}catch(t){e(t)}}function r(t){try{i(h.throw(t))}catch(t){e(t)}}function i(e){e.done?t(e.value):new a(function(t){t(e.value)}).then(n,r)}i((h=h.apply(o,s||[])).next())})}(this,void 0,void 0,function(){return e(this,function(t){return this.database.checkDeleted_("delete"),Pi.getInstance().deleteRepo(this.database.repo_),this.database.repo_=null,this.database.root_=null,this.database.INTERNAL=null,this.database=null,[2]})})},Fi);function Fi(t){this.database=t}var Ai=Object.freeze({__proto__:null,forceLongPolling:function(){Xr.forceDisallow(),Br.forceAllow()},forceWebSockets:function(){Br.forceDisallow()},isWebSocketsAvailable:function(){return Xr.isAvailable()},setSecurityDebugCallback:function(t,e){t.repo.persistentConnection_.securityDebugCallback_=e},stats:function(t,e){t.repo.stats(e)},statsIncrementCounter:function(t,e){t.repo.statsIncrementCounter(e)},dataUpdateCount:function(t){return t.repo.dataUpdateCount},interceptServerData:function(t,e){return t.repo.interceptServerData_(e)}}),Li=oi;oi.prototype.simpleListen=function(t,e){this.sendRequest("q",{p:t},e)},oi.prototype.echo=function(t,e){this.sendRequest("echo",{d:t},e)};var Mi,Wi,Qi=ti,qi=kt,Ui=Object.freeze({__proto__:null,DataConnection:Li,RealTimeConnection:Qi,hijackHash:function(i){var o=oi.prototype.put;return oi.prototype.put=function(t,e,n,r){void 0!==r&&(r=i()),o.call(this,t,e,n,r)},function(){oi.prototype.put=o}},ConnectionTarget:qi,queryIdentifier:function(t){return t.queryIdentifier()},forceRestClient:function(t){Pi.getInstance().forceRestClient(t)}}),Vi=Oi.ServerValue;Mi=(Wi=Hi).SDK_VERSION,zr=Mi,Wi.INTERNAL.registerService("database",function(t,e,n){return Pi.getInstance().databaseFromApp(t,n)},{Reference:Ci,Query:yn,Database:Oi,DataSnapshot:on,enableLogging:$,INTERNAL:Ai,ServerValue:Vi,TEST_ACCESS:Ui},null,!0)}).apply(this,arguments)}catch(t){throw console.error(t),new Error("Cannot instantiate firebase-database - be sure to load firebase-app.js first.")}});
2//# sourceMappingURL=firebase-database.js.map