try{!function(t,e){"use strict";e=e&&e.hasOwnProperty("default")?e.default:e;var n=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])};function r(t,e){function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}function i(t,e){var n,r,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(o){return function(a){return function(o){if(n)throw new TypeError("Generator is already executing.");for(;s;)try{if(n=1,r&&(i=r[2&o[0]?"return":o[0]?"throw":"next"])&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[0,i.value]),o[0]){case 0:case 1:i=o;break;case 4:return s.label++,{value:o[1],done:!1};case 5:s.label++,r=o[1],o=[0];continue;case 7:o=s.ops.pop(),s.trys.pop();continue;default:if(!(i=(i=s.trys).length>0&&i[i.length-1])&&(6===o[0]||2===o[0])){s=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]>6|192,e[n++]=63&i|128):55296==(64512&i)&&r+1>18|240,e[n++]=i>>12&63|128,e[n++]=i>>6&63|128,e[n++]=63&i|128):(e[n++]=i>>12|224,e[n++]=i>>6&63|128,e[n++]=63&i|128)}return e},c={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>2,c=(3&o)<<4|a>>4,p=(15&a)<<2|u>>6,d=63&u;h||(d=64,s||(p=64)),r.push(n[l],n[c],n[p],n[d])}return r.join("")},encodeString:function(t,e){return this.HAS_NATIVE_SUPPORT&&!e?btoa(t):this.encodeByteArray(l(t),e)},decodeString:function(t,e){return this.HAS_NATIVE_SUPPORT&&!e?atob(t):function(t){for(var e=[],n=0,r=0;n191&&i<224){var o=t[n++];e[r++]=String.fromCharCode((31&i)<<6|63&o)}else if(i>239&&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>4;if(r.push(u),64!=a){var l=s<<4&240|a>>2;if(r.push(l),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_BASE.length&&(this.charToByteMap_[this.ENCODED_VALS_WEBSAFE.charAt(t)]=t,this.charToByteMapWebSafe_[this.ENCODED_VALS.charAt(t)]=t)}}},p=function(t){try{return c.decodeString(t,!0)}catch(t){console.error("base64Decode failed: ",t)}return null};function d(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 f=function(){function t(){var t=this;this.promise=new Promise(function(e,n){t.resolve=e,t.reject=n})}return t.prototype.wrapCallback=function(t){var e=this;return function(n,r){n?e.reject(n):e.resolve(r),"function"==typeof t&&(e.promise.catch(function(){}),1===t.length?t(n):t(n,r))}},t}(),_=function(){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:"")},y=function(){return!0===o||!0===s},v="FirebaseError",g=Error.captureStackTrace,m=function(){return function(t,e){if(this.code=t,this.message=e,g)g(this,C.prototype.create);else try{throw Error.apply(this,arguments)}catch(t){this.name=v,Object.defineProperty(this,"stack",{get:function(){return t.stack}})}}}();m.prototype=Object.create(Error.prototype),m.prototype.constructor=m,m.prototype.name=v;var C=function(){function t(t,e,n){this.service=t,this.serviceName=e,this.errors=n,this.pattern=/\{\$([^}]+)}/g}return t.prototype.create=function(t,e){void 0===e&&(e={});var n,r=this.errors[t],i=this.service+"/"+t;n=void 0===r?"Error":r.replace(this.pattern,function(t,n){var r=e[n];return void 0!==r?r.toString():"<"+n+"?>"}),n=this.serviceName+": "+n+" ("+i+").";var o=new m(i,n);for(var s in e)e.hasOwnProperty(s)&&"_"!==s.slice(-1)&&(o[s]=e[s]);return o},t}();function E(t){return JSON.parse(t)}function w(t){return JSON.stringify(t)}var b=function(t){var e={},n={},r={},i="";try{var o=t.split(".");e=E(p(o[0])||""),n=E(p(o[1])||""),i=o[2],r=n.d||{},delete n.d}catch(t){}return{header:e,claims:n,data:r,signature:i}},S=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},T=function(t,e){if(Object.prototype.hasOwnProperty.call(t,e))return t[e]},I=function(t,e){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e(n,t[n])},N=function(t){return e={},I(t,function(t,n){e[t]=n}),e;var e},R=function(t){for(var e in t)return!1;return!0},P=function(t){var e=0;for(var n in t)e++;return e},D=function(t,e,n){var r={};for(var i in t)r[i]=e.call(n,t[i],i,t);return r},O=function(t,e,n){for(var r in t)if(e.call(n,t[r],r,t))return r},k=function(t){for(var e in t)return e},x=function(t){function e(){var e=t.call(this)||this;e.chain_=[],e.buf_=[],e.W_=[],e.pad_=[],e.inbuf_=0,e.total_=0,e.blockSize=64,e.pad_[0]=128;for(var n=1;n>>31)}var o,s,a=this.chain_[0],h=this.chain_[1],u=this.chain_[2],l=this.chain_[3],c=this.chain_[4];for(r=0;r<80;r++){r<40?r<20?(o=l^h&(u^l),s=1518500249):(o=h^u^l,s=1859775393):r<60?(o=h&u|l&(h|u),s=2400959708):(o=h^u^l,s=3395469782);i=(a<<5|a>>>27)+o+c+s+n[r]&4294967295;c=l,l=u,u=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]+u&4294967295,this.chain_[3]=this.chain_[3]+l&4294967295,this.chain_[4]=this.chain_[4]+c&4294967295},e.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=56;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;i>=0;i-=8)t[r]=this.chain_[n]>>i&255,++r;return t},e}(function(){return function(){this.blockSize=-1}}()),F=function(t,e,n,r){var i;if(rn&&(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 A(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 L(t,e,n,r){if((!r||n)&&"function"!=typeof n)throw new Error(A(t,e,r)+"must be a valid function.")}function M(t,e,n,r){if((!r||n)&&("object"!=typeof n||null===n))throw new Error(A(t,e,r)+"must be a valid context object.")}var W,q=function(t){for(var e=0,n=0;n=55296&&r<=56319?(e+=4,n++):e+=3}return e};!function(t){t[t.DEBUG=0]="DEBUG",t[t.VERBOSE=1]="VERBOSE",t[t.INFO=2]="INFO",t[t.WARN=3]="WARN",t[t.ERROR=4]="ERROR",t[t.SILENT=5]="SILENT"}(W||(W={}));var Q,U=W.INFO,V=function(t,e){for(var n=[],r=2;r=55296&&i<=56319){var o=i-55296;h(++r>6|192,e[n++]=63&i|128):i<65536?(e[n++]=i>>12|224,e[n++]=i>>6&63|128,e[n++]=63&i|128):(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 x;n.update(e);var r=n.digest();return c.encodeByteArray(r)},J=function(){for(var t=[],e=0;en?r.push(t.substring(i,n)):r.push(t.substring(i,i+e));return r},_t=function(t,e){if(Array.isArray(t))for(var n=0;n=Math.pow(2,-1022)?(n=(i=Math.min(Math.floor(Math.log(t)/Math.LN2),1023))+1023,r=Math.round(t*Math.pow(2,52-i)-Math.pow(2,52))):(n=0,r=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 u="";for(o=0;o<64;o+=8){var l=parseInt(a.substr(o,8),2).toString(16);1===l.length&&(l="0"+l),u+=l}return u.toLowerCase()},vt=new RegExp("^-?\\d{1,10}$"),gt=function(t){if(vt.test(t)){var e=Number(t);if(e>=-2147483648&&e<=2147483647)return e}return null},mt=function(t){try{t()}catch(t){setTimeout(function(){var e=t.stack||"";throw st("Exception was thrown by user callback.",e),t},Math.floor(0))}},Ct=function(){return("object"==typeof window&&window.navigator&&window.navigator.userAgent||"").search(/googlebot|google webmaster tools|bingbot|yahoo! slurp|baiduspider|yandexbot|duckduckbot/i)>=0},Et=function(t,e){var n=setTimeout(t,e);return"object"==typeof n&&n.unref&&n.unref(),n},wt=function(){function t(t,e){if(void 0===e){this.pieces_=t.split("/");for(var n=0,r=0;r0&&(this.pieces_[n]=this.pieces_[r],n++);this.pieces_.length=n,this.pieceNum_=0}else this.pieces_=t,this.pieceNum_=e}return Object.defineProperty(t,"Empty",{get:function(){return new t("")},enumerable:!0,configurable:!0}),t.prototype.getFront=function(){return this.pieceNum_>=this.pieces_.length?null:this.pieces_[this.pieceNum_]},t.prototype.getLength=function(){return this.pieces_.length-this.pieceNum_},t.prototype.popFront=function(){var e=this.pieceNum_;return e=this.pieces_.length)return null;for(var e=[],n=this.pieceNum_;n0&&n.push(i[r])}return new t(n,0)},t.prototype.isEmpty=function(){return this.pieceNum_>=this.pieces_.length},t.relativePath=function(e,n){var r=e.getFront(),i=n.getFront();if(null===r)return n;if(r===i)return t.relativePath(e.popFront(),n.popFront());throw new Error("INTERNAL ERROR: innerPath ("+n+") is not within outerPath ("+e+")")},t.comparePaths=function(t,e){for(var n=t.slice(),r=e.slice(),i=0;it.getLength())return!1;for(;e0&&(this.byteLength_+=1),this.parts_.push(t),this.byteLength_+=q(t),this.checkValid_()},t.prototype.pop=function(){var t=this.parts_.pop();this.byteLength_-=q(t),this.parts_.length>0&&(this.byteLength_-=1)},t.prototype.checkValid_=function(){if(this.byteLength_>t.MAX_PATH_LENGTH_BYTES)throw new Error(this.errorPrefix_+"has a key path longer than "+t.MAX_PATH_LENGTH_BYTES+" bytes ("+this.byteLength_+").");if(this.parts_.length>t.MAX_PATH_DEPTH)throw new Error(this.errorPrefix_+"path specified exceeds the maximum depth that can be written ("+t.MAX_PATH_DEPTH+") or object contains a cycle "+this.toErrorString())},t.prototype.toErrorString=function(){return 0==this.parts_.length?"":"in property '"+this.parts_.join(".")+"'"},t}(),St="long_polling",Tt=function(){function t(t,e,n,r,i){void 0===i&&(i=""),this.secure=e,this.namespace=n,this.webSocketOnly=r,this.persistenceKey=i,this.host=t.toLowerCase(),this.domain=this.host.substr(this.host.indexOf(".")+1),this.internalHost=Y.get("host:"+t)||this.host}return t.prototype.needsQueryParam=function(){return this.host!==this.internalHost||this.isCustomHost()},t.prototype.isCacheableHost=function(){return"s-"===this.internalHost.substr(0,2)},t.prototype.isDemoHost=function(){return"firebaseio-demo.com"===this.domain},t.prototype.isCustomHost=function(){return"firebaseio.com"!==this.domain&&"firebaseio-demo.com"!==this.domain},t.prototype.updateHost=function(t){t!==this.internalHost&&(this.internalHost=t,this.isCacheableHost()&&Y.set("host:"+this.host,this.internalHost))},t.prototype.connectionURL=function(t,e){var n;if(h("string"==typeof t,"typeof type must == string"),h("object"==typeof e,"typeof params must == object"),"websocket"===t)n=(this.secure?"wss://":"ws://")+this.internalHost+"/.ws?";else{if(t!==St)throw new Error("Unknown connection type: "+t);n=(this.secure?"https://":"http://")+this.internalHost+"/.lp?"}this.needsQueryParam()&&(e.ns=this.namespace);var r=[];return I(e,function(t,e){r.push(t+"="+e)}),n+r.join("&")},t.prototype.toString=function(){var t=this.toURLString();return this.persistenceKey&&(t+="<"+this.persistenceKey+">"),t},t.prototype.toURLString=function(){return(this.secure?"https://":"http://")+this.host},t}();var It,Nt,Rt,Pt,Dt,Ot=function(t){var e=kt(t),n=e.subdomain;"firebase"===e.domain&&ot(e.host+" is no longer supported. Please use .firebaseio.com instead"),n&&"undefined"!=n||"localhost"===e.domain||ot("Cannot parse Firebase url. Please use https://.firebaseio.com"),e.secure||"undefined"!=typeof window&&window.location&&window.location.protocol&&-1!==window.location.protocol.indexOf("https:")&&st("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 Tt(e.host,e.secure,n,r),path:new wt(e.pathString)}},kt=function(t){var e="",n="",r="",i="",o=!0,s="https",a=443;if("string"==typeof t){var h=t.indexOf("//");h>=0&&(s=t.substring(0,h-1),t=t.substring(h+2));var u=t.indexOf("/");-1===u&&(u=t.length);var l=t.indexOf("?");-1===l&&(l=t.length),e=t.substring(0,Math.min(u,l)),u0){var i=n[r];try{i=decodeURIComponent(i.replace(/\+/g," "))}catch(t){}e+="/"+i}return e}(t.substring(u,l)));var c=function(t){var e={};"?"===t.charAt(0)&&(t=t.substring(1));for(var n=0,r=t.split("&");n=0?(o="https"===s||"wss"===s,a=parseInt(e.substring(h+1),10)):h=t.length;var p=e.split(".");3===p.length?(n=p[1],r=p[0].toLowerCase()):2===p.length?n=p[0]:"localhost"===p[0].slice(0,h).toLowerCase()&&(n="localhost"),""===r&&"ns"in c&&(r=c.ns)}return{host:e,port:a,domain:n,subdomain:r,secure:o,scheme:s,pathString:i}},xt=/[\[\].#$\/\u0000-\u001F\u007F]/,Ft=/[\[\].#$\u0000-\u001F\u007F]/,At=function(t){return"string"==typeof t&&0!==t.length&&!xt.test(t)},Lt=function(t){return"string"==typeof t&&0!==t.length&&!Ft.test(t)},Mt=function(t){return null===t||"string"==typeof t||"number"==typeof t&&!at(t)||t&&"object"==typeof t&&S(t,".sv")},Wt=function(t,e,n,r,i){i&&void 0===n||qt(A(t,e,i),n,r)},qt=function(t,e,n){var r=n instanceof wt?new bt(n,t):n;if(void 0===e)throw new Error(t+"contains undefined "+r.toErrorString());if("function"==typeof e)throw new Error(t+"contains a function "+r.toErrorString()+" with contents = "+e.toString());if(at(e))throw new Error(t+"contains "+e.toString()+" "+r.toErrorString());if("string"==typeof e&&e.length>10485760/3&&q(e)>10485760)throw new Error(t+"contains a string greater than 10485760 utf8 bytes "+r.toErrorString()+" ('"+e.substring(0,50)+"...')");if(e&&"object"==typeof e){var i=!1,o=!1;if(I(e,function(e,n){if(".value"===e)i=!0;else if(".priority"!==e&&".sv"!==e&&(o=!0,!At(e)))throw new Error(t+" contains an invalid key ("+e+") "+r.toErrorString()+'. Keys must be non-empty strings and can\'t contain ".", "#", "$", "/", "[", or "]"');r.push(e),qt(t,n,r),r.pop()}),i&&o)throw new Error(t+' contains ".value" child '+r.toErrorString()+" in addition to actual children.")}},Qt=function(t,e,n,r,i){if(!i||void 0!==n){var o=A(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=[];I(n,function(t,e){var n=new wt(t);if(qt(o,e,r.child(n)),".priority"===n.getBack()&&!Mt(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=0;e--)r[e]=It.charAt(t%64),t=Math.floor(t/64);h(0===t,"Cannot push at time == 0");var i=r.join("");if(n){for(e=11;e>=0&&63===Rt[e];e--)Rt[e]=0;Rt[e]++}else for(e=0;e<12;e++)Rt[e]=Math.floor(64*Math.random());for(e=0;e<12;e++)i+=It.charAt(Rt[e]);return h(20===i.length,"nextPushId: Length should be 20."),i}),Xt=function(){function t(t,e){this.name=t,this.node=e}return t.Wrap=function(e,n){return new t(e,n)},t}(),$t=function(){function t(){}return t.prototype.getCompare=function(){return this.compare.bind(this)},t.prototype.indexedValueChanged=function(t,e){var n=new Xt(ht,t),r=new Xt(ht,e);return 0!==this.compare(n,r)},t.prototype.minPost=function(){return Xt.MIN},t}(),Jt=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return r(e,t),Object.defineProperty(e,"__EMPTY_NODE",{get:function(){return Pt},set:function(t){Pt=t},enumerable:!0,configurable:!0}),e.prototype.compare=function(t,e){return lt(t.name,e.name)},e.prototype.isDefinedOn=function(t){throw u("KeyIndex.isDefinedOn not expected to be called.")},e.prototype.indexedValueChanged=function(t,e){return!1},e.prototype.minPost=function(){return Xt.MIN},e.prototype.maxPost=function(){return new Xt(ut,Pt)},e.prototype.makePost=function(t,e){return h("string"==typeof t,"KeyIndex indexValue must always be a string."),new Xt(t,Pt)},e.prototype.toString=function(){return".key"},e}($t),Zt=new Jt;var te,ee,ne,re=function(t){return"number"==typeof t?"number:"+yt(t):"string:"+t},ie=function(t){if(t.isLeafNode()){var e=t.val();h("string"==typeof e||"number"==typeof e||"object"==typeof e&&S(e,".sv"),"Priority must be a string or number.")}else h(t===Dt||t.isEmpty(),"priority of unexpected type.");h(t===Dt||t.getPriority().isEmpty(),"Priority nodes can't have a priority of their own.")},oe=function(){function t(e,n){void 0===n&&(n=t.__childrenNodeConstructor.EMPTY_NODE),this.value_=e,this.priorityNode_=n,this.lazyHash_=null,h(void 0!==this.value_&&null!==this.value_,"LeafNode shouldn't be created with null/undefined value."),ie(this.priorityNode_)}return Object.defineProperty(t,"__childrenNodeConstructor",{get:function(){return te},set:function(t){te=t},enumerable:!0,configurable:!0}),t.prototype.isLeafNode=function(){return!0},t.prototype.getPriority=function(){return this.priorityNode_},t.prototype.updatePriority=function(e){return new t(this.value_,e)},t.prototype.getImmediateChild=function(e){return".priority"===e?this.priorityNode_:t.__childrenNodeConstructor.EMPTY_NODE},t.prototype.getChild=function(e){return e.isEmpty()?this:".priority"===e.getFront()?this.priorityNode_:t.__childrenNodeConstructor.EMPTY_NODE},t.prototype.hasChild=function(){return!1},t.prototype.getPredecessorChildName=function(t,e){return null},t.prototype.updateImmediateChild=function(e,n){return".priority"===e?this.updatePriority(n):n.isEmpty()&&".priority"!==e?this:t.__childrenNodeConstructor.EMPTY_NODE.updateImmediateChild(e,n).updatePriority(this.priorityNode_)},t.prototype.updateChild=function(e,n){var r=e.getFront();return null===r?n:n.isEmpty()&&".priority"!==r?this:(h(".priority"!==r||1===e.getLength(),".priority must be the last token in a path"),this.updateImmediateChild(r,t.__childrenNodeConstructor.EMPTY_NODE.updateChild(e.popFront(),n)))},t.prototype.isEmpty=function(){return!1},t.prototype.numChildren=function(){return 0},t.prototype.forEachChild=function(t,e){return!1},t.prototype.val=function(t){return t&&!this.getPriority().isEmpty()?{".value":this.getValue(),".priority":this.getPriority().val()}:this.getValue()},t.prototype.hash=function(){if(null===this.lazyHash_){var t="";this.priorityNode_.isEmpty()||(t+="priority:"+re(this.priorityNode_.val())+":");var e=typeof this.value_;t+=e+":",t+="number"===e?yt(this.value_):this.value_,this.lazyHash_=$(t)}return this.lazyHash_},t.prototype.getValue=function(){return this.value_},t.prototype.compareTo=function(e){return e===t.__childrenNodeConstructor.EMPTY_NODE?1:e instanceof t.__childrenNodeConstructor?-1:(h(e.isLeafNode(),"Unknown node type"),this.compareToLeafNode_(e))},t.prototype.compareToLeafNode_=function(e){var n=typeof e.value_,r=typeof this.value_,i=t.VALUE_TYPE_ORDER.indexOf(n),o=t.VALUE_TYPE_ORDER.indexOf(r);return h(i>=0,"Unknown leaf type: "+n),h(o>=0,"Unknown leaf type: "+r),i===o?"object"===r?0:this.value_0},t.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}},t}(),le=function(){function t(e,n,r,i,o){this.key=e,this.value=n,this.color=null!=r?r:t.RED,this.left=null!=i?i:pe.EMPTY_NODE,this.right=null!=o?o:pe.EMPTY_NODE}return t.prototype.copy=function(e,n,r,i,o){return new t(null!=e?e:this.key,null!=n?n:this.value,null!=r?r:this.color,null!=i?i:this.left,null!=o?o:this.right)},t.prototype.count=function(){return this.left.count()+1+this.right.count()},t.prototype.isEmpty=function(){return!1},t.prototype.inorderTraversal=function(t){return this.left.inorderTraversal(t)||t(this.key,this.value)||this.right.inorderTraversal(t)},t.prototype.reverseTraversal=function(t){return this.right.reverseTraversal(t)||t(this.key,this.value)||this.left.reverseTraversal(t)},t.prototype.min_=function(){return this.left.isEmpty()?this:this.left.min_()},t.prototype.minKey=function(){return this.min_().key},t.prototype.maxKey=function(){return this.right.isEmpty()?this.key:this.right.maxKey()},t.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_()},t.prototype.removeMin_=function(){if(this.left.isEmpty())return pe.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_()},t.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 pe.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_()},t.prototype.isRed_=function(){return this.color},t.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},t.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},t.prototype.moveRedRight_=function(){var t=this.colorFlip_();return t.left.left.isRed_()&&(t=(t=t.rotateRight_()).colorFlip_()),t},t.prototype.rotateLeft_=function(){var e=this.copy(null,null,t.RED,null,this.right.left);return this.right.copy(null,null,this.color,e,null)},t.prototype.rotateRight_=function(){var e=this.copy(null,null,t.RED,this.left.right,null);return this.left.copy(null,null,this.color,null,e)},t.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)},t.prototype.checkMaxDepth_=function(){var t=this.check_();return Math.pow(2,t)<=this.count()+1},t.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)},t.RED=!0,t.BLACK=!1,t}(),ce=function(){function t(){}return t.prototype.copy=function(t,e,n,r,i){return this},t.prototype.insert=function(t,e,n){return new le(t,e,null)},t.prototype.remove=function(t,e){return this},t.prototype.count=function(){return 0},t.prototype.isEmpty=function(){return!0},t.prototype.inorderTraversal=function(t){return!1},t.prototype.reverseTraversal=function(t){return!1},t.prototype.minKey=function(){return null},t.prototype.maxKey=function(){return null},t.prototype.check_=function(){return 0},t.prototype.isRed_=function(){return!1},t}(),pe=function(){function t(e,n){void 0===n&&(n=t.EMPTY_NODE),this.comparator_=e,this.root_=n}return t.prototype.insert=function(e,n){return new t(this.comparator_,this.root_.insert(e,n,this.comparator_).copy(null,null,le.BLACK,null,null))},t.prototype.remove=function(e){return new t(this.comparator_,this.root_.remove(e,this.comparator_).copy(null,null,le.BLACK,null,null))},t.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:e>0&&(n=n.right)}return null},t.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:e>0&&(r=n,n=n.right)}throw new Error("Attempted to find predecessor key for a nonexistent key. What gives?")},t.prototype.isEmpty=function(){return this.root_.isEmpty()},t.prototype.count=function(){return this.root_.count()},t.prototype.minKey=function(){return this.root_.minKey()},t.prototype.maxKey=function(){return this.root_.maxKey()},t.prototype.inorderTraversal=function(t){return this.root_.inorderTraversal(t)},t.prototype.reverseTraversal=function(t){return this.root_.reverseTraversal(t)},t.prototype.getIterator=function(t){return new ue(this.root_,null,this.comparator_,!1,t)},t.prototype.getIteratorFrom=function(t,e){return new ue(this.root_,t,this.comparator_,!1,e)},t.prototype.getReverseIteratorFrom=function(t,e){return new ue(this.root_,t,this.comparator_,!0,e)},t.prototype.getReverseIterator=function(t){return new ue(this.root_,null,this.comparator_,!0,t)},t.EMPTY_NODE=new ce,t}(),de=Math.log(2),fe=function(){function t(t){var e;this.count=(e=t+1,parseInt(Math.log(e)/de,10)),this.current_=this.count-1;var n,r=(n=this.count,parseInt(Array(n+1).join("1"),2));this.bits_=t+1&r}return t.prototype.nextBitIsOne=function(){var t=!(this.bits_&1<0;)r.getNext(),i=r.peek();return r},t.prototype.compareTo=function(t){return this.isEmpty()?t.isEmpty()?0:-1:t.isLeafNode()||t.isEmpty()?1:t===Ee?-1:0},t.prototype.withIndex=function(e){if(e===Zt||this.indexMap_.hasIndex(e))return this;var n=this.indexMap_.addIndex(e,this.children_);return new t(this.children_,this.priorityNode_,n)},t.prototype.isIndexed=function(t){return t===Zt||this.indexMap_.hasIndex(t)},t.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()){for(var n=this.getIterator(he),r=e.getIterator(he),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}return!1},t.prototype.resolveIndex_=function(t){return t===Zt?null:this.indexMap_.get(t.toString())},t.INTEGER_REGEXP_=/^(0|[1-9]\d*)$/,t}(),Ee=new(function(t){function e(){return t.call(this,new pe(me),Ce.EMPTY_NODE,ve.Default)||this}return r(e,t),e.prototype.compareTo=function(t){return t===this?0:1},e.prototype.equals=function(t){return t===this},e.prototype.getPriority=function(){return this},e.prototype.getImmediateChild=function(t){return Ce.EMPTY_NODE},e.prototype.isEmpty=function(){return!1},e}(Ce));Object.defineProperties(Xt,{MIN:{value:new Xt(ht,Ce.EMPTY_NODE)},MAX:{value:new Xt(ut,Ee)}}),Jt.__EMPTY_NODE=Ce.EMPTY_NODE,oe.__childrenNodeConstructor=Ce,Dt=Ee,function(t){ne=t}(Ee);var we=!0;function be(t,e){if(void 0===e&&(e=null),null===t)return Ce.EMPTY_NODE;if("object"==typeof t&&".priority"in t&&(e=t[".priority"]),h(null===e||"string"==typeof e||"number"==typeof e||"object"==typeof e&&".sv"in e,"Invalid priority type found: "+typeof e),"object"==typeof t&&".value"in t&&null!==t[".value"]&&(t=t[".value"]),"object"!=typeof t||".sv"in t)return new oe(t,be(e));if(t instanceof Array||!we){var n=Ce.EMPTY_NODE,r=t;return I(r,function(t,e){if(S(r,t)&&"."!==t.substring(0,1)){var i=be(e);!i.isLeafNode()&&i.isEmpty()||(n=n.updateImmediateChild(t,i))}}),n.updatePriority(be(e))}var i=[],o=!1,s=t;if(I(s,function(t,e){if("string"!=typeof t||"."!==t.substring(0,1)){var n=be(s[t]);n.isEmpty()||(o=o||!n.getPriority().isEmpty(),i.push(new Xt(t,n)))}}),0==i.length)return Ce.EMPTY_NODE;var a=_e(i,ge,function(t){return t.name},me);if(o){var u=_e(i,he.getCompare());return new Ce(a,be(e),new ve({".priority":u},{".priority":he}))}return new Ce(a,be(e),ve.Default)}!function(t){ee=t}(be);var Se,Te,Ie=new(function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return r(e,t),e.prototype.compare=function(t,e){var n=t.node.compareTo(e.node);return 0===n?lt(t.name,e.name):n},e.prototype.isDefinedOn=function(t){return!0},e.prototype.indexedValueChanged=function(t,e){return!t.equals(e)},e.prototype.minPost=function(){return Xt.MIN},e.prototype.maxPost=function(){return Xt.MAX},e.prototype.makePost=function(t,e){var n=be(t);return new Xt(e,n)},e.prototype.toString=function(){return".value"},e}($t)),Ne=function(t){function e(e){var n=t.call(this)||this;return n.indexPath_=e,h(!e.isEmpty()&&".priority"!==e.getFront(),"Can't create PathIndex with empty path or .priority key"),n}return r(e,t),e.prototype.extractChild=function(t){return t.getChild(this.indexPath_)},e.prototype.isDefinedOn=function(t){return!t.getChild(this.indexPath_).isEmpty()},e.prototype.compare=function(t,e){var n=this.extractChild(t.node),r=this.extractChild(e.node),i=n.compareTo(r);return 0===i?lt(t.name,e.name):i},e.prototype.makePost=function(t,e){var n=be(t),r=Ce.EMPTY_NODE.updateChild(this.indexPath_,n);return new Xt(e,r)},e.prototype.maxPost=function(){var t=Ce.EMPTY_NODE.updateChild(this.indexPath_,Ee);return new Xt(ut,t)},e.prototype.toString=function(){return this.indexPath_.slice().join("/")},e}($t),Re=function(){function t(t,e,n){this.node_=t,this.ref_=e,this.index_=n}return t.prototype.val=function(){return F("DataSnapshot.val",0,0,arguments.length),this.node_.val()},t.prototype.exportVal=function(){return F("DataSnapshot.exportVal",0,0,arguments.length),this.node_.val(!0)},t.prototype.toJSON=function(){return F("DataSnapshot.toJSON",0,1,arguments.length),this.exportVal()},t.prototype.exists=function(){return F("DataSnapshot.exists",0,0,arguments.length),!this.node_.isEmpty()},t.prototype.child=function(e){F("DataSnapshot.child",0,1,arguments.length),e=String(e),Bt("DataSnapshot.child",1,e,!1);var n=new wt(e),r=this.ref_.child(n);return new t(this.node_.getChild(n),r,he)},t.prototype.hasChild=function(t){F("DataSnapshot.hasChild",1,1,arguments.length),Bt("DataSnapshot.hasChild",1,t,!1);var e=new wt(t);return!this.node_.getChild(e).isEmpty()},t.prototype.getPriority=function(){return F("DataSnapshot.getPriority",0,0,arguments.length),this.node_.getPriority().val()},t.prototype.forEach=function(e){var n=this;return F("DataSnapshot.forEach",1,1,arguments.length),L("DataSnapshot.forEach",1,e,!1),!this.node_.isLeafNode()&&!!this.node_.forEachChild(this.index_,function(r,i){return e(new t(i,n.ref_.child(r),he))})},t.prototype.hasChildren=function(){return F("DataSnapshot.hasChildren",0,0,arguments.length),!this.node_.isLeafNode()&&!this.node_.isEmpty()},Object.defineProperty(t.prototype,"key",{get:function(){return this.ref_.getKey()},enumerable:!0,configurable:!0}),t.prototype.numChildren=function(){return F("DataSnapshot.numChildren",0,0,arguments.length),this.node_.numChildren()},t.prototype.getRef=function(){return F("DataSnapshot.ref",0,0,arguments.length),this.ref_},Object.defineProperty(t.prototype,"ref",{get:function(){return this.getRef()},enumerable:!0,configurable:!0}),t}(),Pe=function(){function t(t,e,n,r){this.eventType=t,this.eventRegistration=e,this.snapshot=n,this.prevName=r}return t.prototype.getPath=function(){var t=this.snapshot.getRef();return"value"===this.eventType?t.path:t.getParent().path},t.prototype.getEventType=function(){return this.eventType},t.prototype.getEventRunner=function(){return this.eventRegistration.getEventRunner(this)},t.prototype.toString=function(){return this.getPath().toString()+":"+this.eventType+":"+w(this.snapshot.exportVal())},t}(),De=function(){function t(t,e,n){this.eventRegistration=t,this.error=e,this.path=n}return t.prototype.getPath=function(){return this.path},t.prototype.getEventType=function(){return"cancel"},t.prototype.getEventRunner=function(){return this.eventRegistration.getEventRunner(this)},t.prototype.toString=function(){return this.path.toString()+":cancel"},t}(),Oe=function(){function t(t,e,n){this.callback_=t,this.cancelCallback_=e,this.context_=n}return t.prototype.respondsTo=function(t){return"value"===t},t.prototype.createEvent=function(t,e){var n=e.getQueryParams().getIndex();return new Pe("value",this,new Re(t.snapshotNode,e.getRef(),n))},t.prototype.getEventRunner=function(t){var e=this.context_;if("cancel"===t.getEventType()){h(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)}},t.prototype.createCancelEvent=function(t,e){return this.cancelCallback_?new De(this,t,e):null},t.prototype.matches=function(e){return e instanceof t&&(!e.callback_||!this.callback_||e.callback_===this.callback_&&e.context_===this.context_)},t.prototype.hasAnyCallback=function(){return null!==this.callback_},t}(),ke=function(){function t(t,e,n){this.callbacks_=t,this.cancelCallback_=e,this.context_=n}return t.prototype.respondsTo=function(t){var e="children_added"===t?"child_added":t;return e="children_removed"===e?"child_removed":e,S(this.callbacks_,e)},t.prototype.createCancelEvent=function(t,e){return this.cancelCallback_?new De(this,t,e):null},t.prototype.createEvent=function(t,e){h(null!=t.childName,"Child events should have a childName.");var n=e.getRef().child(t.childName),r=e.getQueryParams().getIndex();return new Pe(t.type,this,new Re(t.snapshotNode,n,r),t.prevName)},t.prototype.getEventRunner=function(t){var e=this.context_;if("cancel"===t.getEventType()){h(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)}},t.prototype.matches=function(e){if(e instanceof t){if(!this.callbacks_||!e.callbacks_)return!0;if(this.context_===e.context_){var n=P(e.callbacks_);if(n===P(this.callbacks_)){if(1===n){var r=k(e.callbacks_),i=k(this.callbacks_);return!(i!==r||e.callbacks_[r]&&this.callbacks_[i]&&e.callbacks_[r]!==this.callbacks_[i])}return function(t,e){for(var n in t)if(Object.prototype.hasOwnProperty.call(t,n)&&!e(n,t[n]))return!1;return!0}(this.callbacks_,function(t,n){return e.callbacks_[t]===n})}}}return!1},t.prototype.hasAnyCallback=function(){return null!==this.callbacks_},t}(),xe=function(){function t(t,e,n,r){this.repo=t,this.path=e,this.queryParams_=n,this.orderByCalled_=r}return Object.defineProperty(t,"__referenceConstructor",{get:function(){return h(Se,"Reference.ts has not been loaded"),Se},set:function(t){Se=t},enumerable:!0,configurable:!0}),t.validateQueryEndpoints_=function(t){var e=null,n=null;if(t.hasStart()&&(e=t.getIndexStartValue()),t.hasEnd()&&(n=t.getIndexEndValue()),t.getIndex()===Zt){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()!=ht)throw new Error(r);if("string"!=typeof e)throw new Error(i)}if(t.hasEnd()){if(t.getIndexEndName()!=ut)throw new Error(r);if("string"!=typeof n)throw new Error(i)}}else if(t.getIndex()===he){if(null!=e&&!Mt(e)||null!=n&&!Mt(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(h(t.getIndex()instanceof Ne||t.getIndex()===Ie,"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.")},t.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.")},t.prototype.validateNoPreviousOrderByCall_=function(t){if(!0===this.orderByCalled_)throw new Error(t+": You can't combine multiple orderBy calls.")},t.prototype.getQueryParams=function(){return this.queryParams_},t.prototype.getRef=function(){return F("Query.ref",0,0,arguments.length),new t.__referenceConstructor(this.repo,this.path)},t.prototype.on=function(e,n,r,i){F("Query.on",2,4,arguments.length),Vt("Query.on",1,e,!1),L("Query.on",2,n,!1);var o=t.getCancelAndContextArgs_("Query.on",r,i);if("value"===e)this.onValueEvent(n,o.cancel,o.context);else{var s={};s[e]=n,this.onChildEvent(s,o.cancel,o.context)}return n},t.prototype.onValueEvent=function(t,e,n){var r=new Oe(t,e||null,n||null);this.repo.addEventCallbackForQuery(this,r)},t.prototype.onChildEvent=function(t,e,n){var r=new ke(t,e,n);this.repo.addEventCallbackForQuery(this,r)},t.prototype.off=function(t,e,n){F("Query.off",0,3,arguments.length),Vt("Query.off",1,t,!0),L("Query.off",2,e,!0),M("Query.off",3,n,!0);var r=null,i=null;"value"===t?r=new Oe(e||null,null,n||null):t&&(e&&((i={})[t]=e),r=new ke(i,null,n||null));this.repo.removeEventCallbackForQuery(this,r)},t.prototype.once=function(e,n,r,i){var o=this;F("Query.once",1,4,arguments.length),Vt("Query.once",1,e,!1),L("Query.once",2,n,!0);var s=t.getCancelAndContextArgs_("Query.once",r,i),a=!0,h=new f;h.promise.catch(function(){});var u=function(t){a&&(a=!1,o.off(e,u),n&&n.bind(s.context)(t),h.resolve(t))};return this.on(e,u,function(t){o.off(e,u),s.cancel&&s.cancel.bind(s.context)(t),h.reject(t)}),h.promise},t.prototype.limitToFirst=function(e){if(F("Query.limitToFirst",1,1,arguments.length),"number"!=typeof e||Math.floor(e)!==e||e<=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 t(this.repo,this.path,this.queryParams_.limitToFirst(e),this.orderByCalled_)},t.prototype.limitToLast=function(e){if(F("Query.limitToLast",1,1,arguments.length),"number"!=typeof e||Math.floor(e)!==e||e<=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 t(this.repo,this.path,this.queryParams_.limitToLast(e),this.orderByCalled_)},t.prototype.orderByChild=function(e){if(F("Query.orderByChild",1,1,arguments.length),"$key"===e)throw new Error('Query.orderByChild: "$key" is invalid. Use Query.orderByKey() instead.');if("$priority"===e)throw new Error('Query.orderByChild: "$priority" is invalid. Use Query.orderByPriority() instead.');if("$value"===e)throw new Error('Query.orderByChild: "$value" is invalid. Use Query.orderByValue() instead.');Bt("Query.orderByChild",1,e,!1),this.validateNoPreviousOrderByCall_("Query.orderByChild");var n=new wt(e);if(n.isEmpty())throw new Error("Query.orderByChild: cannot pass in empty path. Use Query.orderByValue() instead.");var r=new Ne(n),i=this.queryParams_.orderBy(r);return t.validateQueryEndpoints_(i),new t(this.repo,this.path,i,!0)},t.prototype.orderByKey=function(){F("Query.orderByKey",0,0,arguments.length),this.validateNoPreviousOrderByCall_("Query.orderByKey");var e=this.queryParams_.orderBy(Zt);return t.validateQueryEndpoints_(e),new t(this.repo,this.path,e,!0)},t.prototype.orderByPriority=function(){F("Query.orderByPriority",0,0,arguments.length),this.validateNoPreviousOrderByCall_("Query.orderByPriority");var e=this.queryParams_.orderBy(he);return t.validateQueryEndpoints_(e),new t(this.repo,this.path,e,!0)},t.prototype.orderByValue=function(){F("Query.orderByValue",0,0,arguments.length),this.validateNoPreviousOrderByCall_("Query.orderByValue");var e=this.queryParams_.orderBy(Ie);return t.validateQueryEndpoints_(e),new t(this.repo,this.path,e,!0)},t.prototype.startAt=function(e,n){void 0===e&&(e=null),F("Query.startAt",0,2,arguments.length),Wt("Query.startAt",1,e,this.path,!0),Ht("Query.startAt",2,n,!0);var r=this.queryParams_.startAt(e,n);if(t.validateLimit_(r),t.validateQueryEndpoints_(r),this.queryParams_.hasStart())throw new Error("Query.startAt: Starting point was already set (by another call to startAt or equalTo).");return void 0===e&&(e=null,n=null),new t(this.repo,this.path,r,this.orderByCalled_)},t.prototype.endAt=function(e,n){void 0===e&&(e=null),F("Query.endAt",0,2,arguments.length),Wt("Query.endAt",1,e,this.path,!0),Ht("Query.endAt",2,n,!0);var r=this.queryParams_.endAt(e,n);if(t.validateLimit_(r),t.validateQueryEndpoints_(r),this.queryParams_.hasEnd())throw new Error("Query.endAt: Ending point was already set (by another call to endAt or equalTo).");return new t(this.repo,this.path,r,this.orderByCalled_)},t.prototype.equalTo=function(t,e){if(F("Query.equalTo",1,2,arguments.length),Wt("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)},t.prototype.toString=function(){return F("Query.toString",0,0,arguments.length),this.repo.toString()+this.path.toUrlEncodedString()},t.prototype.toJSON=function(){return F("Query.toJSON",0,1,arguments.length),this.toString()},t.prototype.queryObject=function(){return this.queryParams_.getQueryObject()},t.prototype.queryIdentifier=function(){var t=this.queryObject(),e=dt(t);return"{}"===e?"default":e},t.prototype.isEqual=function(e){if(F("Query.isEqual",1,1,arguments.length),!(e instanceof t)){throw new Error("Query.isEqual failed: First argument must be an instance of firebase.database.Query.")}var n=this.repo===e.repo,r=this.path.equals(e.path),i=this.queryIdentifier()===e.queryIdentifier();return n&&r&&i},t.getCancelAndContextArgs_=function(t,e,n){var r={cancel:null,context:null};if(e&&n)r.cancel=e,L(t,3,r.cancel,!0),r.context=n,M(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(A(t,3,!0)+" must either be a cancel callback or a context object.");r.cancel=e}return r},Object.defineProperty(t.prototype,"ref",{get:function(){return this.getRef()},enumerable:!0,configurable:!0}),t}(),Fe=function(){function t(){this.set={}}return t.prototype.add=function(t,e){this.set[t]=null===e||e},t.prototype.contains=function(t){return S(this.set,t)},t.prototype.get=function(t){return this.contains(t)?this.set[t]:void 0},t.prototype.remove=function(t){delete this.set[t]},t.prototype.clear=function(){this.set={}},t.prototype.isEmpty=function(){return R(this.set)},t.prototype.count=function(){return P(this.set)},t.prototype.each=function(t){I(this.set,function(e,n){return t(e,n)})},t.prototype.keys=function(){var t=[];return I(this.set,function(e){t.push(e)}),t},t}(),Ae=function(){function t(){this.value_=null,this.children_=null}return t.prototype.find=function(t){if(null!=this.value_)return this.value_.getChild(t);if(t.isEmpty()||null==this.children_)return null;var e=t.getFront();return t=t.popFront(),this.children_.contains(e)?this.children_.get(e).find(t):null},t.prototype.remember=function(e,n){if(e.isEmpty())this.value_=n,this.children_=null;else if(null!==this.value_)this.value_=this.value_.updateChild(e,n);else{null==this.children_&&(this.children_=new Fe);var r=e.getFront();this.children_.contains(r)||this.children_.add(r,new t);var i=this.children_.get(r);e=e.popFront(),i.remember(e,n)}},t.prototype.forget=function(t){if(t.isEmpty())return this.value_=null,this.children_=null,!0;if(null!==this.value_){if(this.value_.isLeafNode())return!1;var e=this.value_;this.value_=null;var n=this;return e.forEachChild(he,function(t,e){n.remember(new wt(t),e)}),this.forget(t)}if(null!==this.children_){var r=t.getFront();if(t=t.popFront(),this.children_.contains(r))this.children_.get(r).forget(t)&&this.children_.remove(r);return!!this.children_.isEmpty()&&(this.children_=null,!0)}return!0},t.prototype.forEachTree=function(t,e){null!==this.value_?e(t,this.value_):this.forEachChild(function(n,r){var i=new wt(t.toString()+"/"+n);r.forEachTree(i,e)})},t.prototype.forEachChild=function(t){null!==this.children_&&this.children_.each(function(e,n){t(e,n)})},t}(),Le=function(t,e){return t&&"object"==typeof t?(h(".sv"in t,"Unexpected leaf node or priority contents"),e[t[".sv"]]):t},Me=function(t,e){var n,r=t.getPriority().val(),i=Le(r,e);if(t.isLeafNode()){var o=t,s=Le(o.getValue(),e);return s!==o.getValue()||i!==o.getPriority().val()?new oe(s,be(i)):t}var a=t;return n=a,i!==a.getPriority().val()&&(n=n.updatePriority(new oe(i))),a.forEachChild(he,function(t,r){var i=Me(r,e);i!==r&&(n=n.updateImmediateChild(t,i))}),n};!function(t){t[t.OVERWRITE=0]="OVERWRITE",t[t.MERGE=1]="MERGE",t[t.ACK_USER_WRITE=2]="ACK_USER_WRITE",t[t.LISTEN_COMPLETE=3]="LISTEN_COMPLETE"}(Te||(Te={}));var We,qe,Qe=function(){function t(t,e,n,r){this.fromUser=t,this.fromServer=e,this.queryId=n,this.tagged=r,h(!r||e,"Tagged queries must be from server.")}return t.User=new t(!0,!1,null,!1),t.Server=new t(!1,!0,null,!1),t.forServerTaggedQuery=function(e){return new t(!1,!0,e,!0)},t}(),Ue=function(){function t(t,e,n){this.path=t,this.affectedTree=e,this.revert=n,this.type=Te.ACK_USER_WRITE,this.source=Qe.User}return t.prototype.operationForChild=function(e){if(this.path.isEmpty()){if(null!=this.affectedTree.value)return h(this.affectedTree.children.isEmpty(),"affectedTree should not have overlapping affected paths."),this;var n=this.affectedTree.subtree(new wt(e));return new t(wt.Empty,n,this.revert)}return h(this.path.getFront()===e,"operationForChild called for unrelated child."),new t(this.path.popFront(),this.affectedTree,this.revert)},t}(),Ve=function(){return We||(We=new pe(ct)),We},He=function(){function t(t,e){void 0===e&&(e=Ve()),this.value=t,this.children=e}return t.fromObject=function(e){var n=t.Empty;return I(e,function(t,e){n=n.set(new wt(t),e)}),n},t.prototype.isEmpty=function(){return null===this.value&&this.children.isEmpty()},t.prototype.findRootMostMatchingPathAndValue=function(t,e){if(null!=this.value&&e(this.value))return{path:wt.Empty,value:this.value};if(t.isEmpty())return null;var n=t.getFront(),r=this.children.get(n);if(null!==r){var i=r.findRootMostMatchingPathAndValue(t.popFront(),e);return null!=i?{path:new wt(n).child(i.path),value:i.value}:null}return null},t.prototype.findRootMostValueAndPath=function(t){return this.findRootMostMatchingPathAndValue(t,function(){return!0})},t.prototype.subtree=function(e){if(e.isEmpty())return this;var n=e.getFront(),r=this.children.get(n);return null!==r?r.subtree(e.popFront()):t.Empty},t.prototype.set=function(e,n){if(e.isEmpty())return new t(n,this.children);var r=e.getFront(),i=(this.children.get(r)||t.Empty).set(e.popFront(),n),o=this.children.insert(r,i);return new t(this.value,o)},t.prototype.remove=function(e){if(e.isEmpty())return this.children.isEmpty()?t.Empty:new t(null,this.children);var n=e.getFront(),r=this.children.get(n);if(r){var i=r.remove(e.popFront()),o=void 0;return o=i.isEmpty()?this.children.remove(n):this.children.insert(n,i),null===this.value&&o.isEmpty()?t.Empty:new t(this.value,o)}return this},t.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},t.prototype.setTree=function(e,n){if(e.isEmpty())return n;var r=e.getFront(),i=(this.children.get(r)||t.Empty).setTree(e.popFront(),n),o=void 0;return o=i.isEmpty()?this.children.remove(r):this.children.insert(r,i),new t(this.value,o)},t.prototype.fold=function(t){return this.fold_(wt.Empty,t)},t.prototype.fold_=function(t,e){var n={};return this.children.inorderTraversal(function(r,i){n[r]=i.fold_(t.child(r),e)}),e(t,this.value,n)},t.prototype.findOnPath=function(t,e){return this.findOnPath_(t,wt.Empty,e)},t.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},t.prototype.foreachOnPath=function(t,e){return this.foreachOnPath_(t,wt.Empty,e)},t.prototype.foreachOnPath_=function(e,n,r){if(e.isEmpty())return this;this.value&&r(n,this.value);var i=e.getFront(),o=this.children.get(i);return o?o.foreachOnPath_(e.popFront(),n.child(i),r):t.Empty},t.prototype.foreach=function(t){this.foreach_(wt.Empty,t)},t.prototype.foreach_=function(t,e){this.children.inorderTraversal(function(n,r){r.foreach_(t.child(n),e)}),this.value&&e(t,this.value)},t.prototype.foreachChild=function(t){this.children.inorderTraversal(function(e,n){n.value&&t(e,n.value)})},t.Empty=new t(null),t}(),Be=function(){function t(t,e){this.source=t,this.path=e,this.type=Te.LISTEN_COMPLETE}return t.prototype.operationForChild=function(e){return this.path.isEmpty()?new t(this.source,wt.Empty):new t(this.source,this.path.popFront())},t}(),je=function(){function t(t,e,n){this.source=t,this.path=e,this.snap=n,this.type=Te.OVERWRITE}return t.prototype.operationForChild=function(e){return this.path.isEmpty()?new t(this.source,wt.Empty,this.snap.getImmediateChild(e)):new t(this.source,this.path.popFront(),this.snap)},t}(),Ke=function(){function t(t,e,n){this.source=t,this.path=e,this.children=n,this.type=Te.MERGE}return t.prototype.operationForChild=function(e){if(this.path.isEmpty()){var n=this.children.subtree(new wt(e));return n.isEmpty()?null:n.value?new je(this.source,wt.Empty,n.value):new t(this.source,wt.Empty,n)}return h(this.path.getFront()===e,"Can't get a merge for a child not on the path of the operation"),new t(this.source,this.path.popFront(),this.children)},t.prototype.toString=function(){return"Operation("+this.path+": "+this.source.toString()+" merge: "+this.children.toString()+")"},t}(),Ye=function(){function t(t,e,n){this.node_=t,this.fullyInitialized_=e,this.filtered_=n}return t.prototype.isFullyInitialized=function(){return this.fullyInitialized_},t.prototype.isFiltered=function(){return this.filtered_},t.prototype.isCompleteForPath=function(t){if(t.isEmpty())return this.isFullyInitialized()&&!this.filtered_;var e=t.getFront();return this.isCompleteForChild(e)},t.prototype.isCompleteForChild=function(t){return this.isFullyInitialized()&&!this.filtered_||this.node_.hasChild(t)},t.prototype.getNode=function(){return this.node_},t}(),ze=function(){function t(t,e){this.eventCache_=t,this.serverCache_=e}return t.prototype.updateEventSnap=function(e,n,r){return new t(new Ye(e,n,r),this.serverCache_)},t.prototype.updateServerSnap=function(e,n,r){return new t(this.eventCache_,new Ye(e,n,r))},t.prototype.getEventCache=function(){return this.eventCache_},t.prototype.getCompleteEventSnap=function(){return this.eventCache_.isFullyInitialized()?this.eventCache_.getNode():null},t.prototype.getServerCache=function(){return this.serverCache_},t.prototype.getCompleteServerSnap=function(){return this.serverCache_.isFullyInitialized()?this.serverCache_.getNode():null},t.Empty=new t(new Ye(Ce.EMPTY_NODE,!1,!1),new Ye(Ce.EMPTY_NODE,!1,!1)),t}(),Ge=function(){function t(t,e,n,r,i){this.type=t,this.snapshotNode=e,this.childName=n,this.oldSnap=r,this.prevName=i}return t.valueChange=function(e){return new t(t.VALUE,e)},t.childAddedChange=function(e,n){return new t(t.CHILD_ADDED,n,e)},t.childRemovedChange=function(e,n){return new t(t.CHILD_REMOVED,n,e)},t.childChangedChange=function(e,n,r){return new t(t.CHILD_CHANGED,n,e,r)},t.childMovedChange=function(e,n){return new t(t.CHILD_MOVED,n,e)},t.CHILD_ADDED="child_added",t.CHILD_REMOVED="child_removed",t.CHILD_CHANGED="child_changed",t.CHILD_MOVED="child_moved",t.VALUE="value",t}(),Xe=function(){function t(t){this.index_=t}return t.prototype.updateChild=function(t,e,n,r,i,o){h(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(Ge.childRemovedChange(e,s)):h(t.isLeafNode(),"A child remove without an old child only makes sense on a leaf node"):s.isEmpty()?o.trackChildChange(Ge.childAddedChange(e,n)):o.trackChildChange(Ge.childChangedChange(e,n,s))),t.isLeafNode()&&n.isEmpty()?t:t.updateImmediateChild(e,n).withIndex(this.index_))},t.prototype.updateFullNode=function(t,e,n){return null!=n&&(t.isLeafNode()||t.forEachChild(he,function(t,r){e.hasChild(t)||n.trackChildChange(Ge.childRemovedChange(t,r))}),e.isLeafNode()||e.forEachChild(he,function(e,r){if(t.hasChild(e)){var i=t.getImmediateChild(e);i.equals(r)||n.trackChildChange(Ge.childChangedChange(e,r,i))}else n.trackChildChange(Ge.childAddedChange(e,r))})),e.withIndex(this.index_)},t.prototype.updatePriority=function(t,e){return t.isEmpty()?Ce.EMPTY_NODE:t.updatePriority(e)},t.prototype.filtersNodes=function(){return!1},t.prototype.getIndexedFilter=function(){return this},t.prototype.getIndex=function(){return this.index_},t}(),$e=function(){function t(){this.changeMap_={}}return t.prototype.trackChildChange=function(t){var e=t.type,n=t.childName;h(e==Ge.CHILD_ADDED||e==Ge.CHILD_CHANGED||e==Ge.CHILD_REMOVED,"Only child changes supported for tracking"),h(".priority"!==n,"Only non-priority child changes can be tracked.");var r=T(this.changeMap_,n);if(r){var i=r.type;if(e==Ge.CHILD_ADDED&&i==Ge.CHILD_REMOVED)this.changeMap_[n]=Ge.childChangedChange(n,t.snapshotNode,r.snapshotNode);else if(e==Ge.CHILD_REMOVED&&i==Ge.CHILD_ADDED)delete this.changeMap_[n];else if(e==Ge.CHILD_REMOVED&&i==Ge.CHILD_CHANGED)this.changeMap_[n]=Ge.childRemovedChange(n,r.oldSnap);else if(e==Ge.CHILD_CHANGED&&i==Ge.CHILD_ADDED)this.changeMap_[n]=Ge.childAddedChange(n,t.snapshotNode);else{if(e!=Ge.CHILD_CHANGED||i!=Ge.CHILD_CHANGED)throw u("Illegal combination of changes: "+t+" occurred after "+r);this.changeMap_[n]=Ge.childChangedChange(n,t.snapshotNode,r.oldSnap)}}else this.changeMap_[n]=t},t.prototype.getChanges=function(){return function(t){var e=[],n=0;for(var r in t)e[n++]=t[r];return e}(this.changeMap_)},t}(),Je=new(function(){function t(){}return t.prototype.getCompleteChild=function(t){return null},t.prototype.getChildAfterChild=function(t,e,n){return null},t}()),Ze=function(){function t(t,e,n){void 0===n&&(n=null),this.writes_=t,this.viewCache_=e,this.optCompleteServerCache_=n}return t.prototype.getCompleteChild=function(t){var e=this.viewCache_.getEventCache();if(e.isCompleteForChild(t))return e.getNode().getImmediateChild(t);var n=null!=this.optCompleteServerCache_?new Ye(this.optCompleteServerCache_,!0,!1):this.viewCache_.getServerCache();return this.writes_.calcCompleteChild(t,n)},t.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]},t}(),tn=function(){return function(t,e){this.viewCache=t,this.changes=e}}(),en=function(){function t(t){this.filter_=t}return t.prototype.assertIndexed=function(t){h(t.getEventCache().getNode().isIndexed(this.filter_.getIndex()),"Event snap not indexed"),h(t.getServerCache().getNode().isIndexed(this.filter_.getIndex()),"Server snap not indexed")},t.prototype.applyOperation=function(e,n,r,i){var o,s,a=new $e;if(n.type===Te.OVERWRITE){var l=n;l.source.fromUser?o=this.applyUserOverwrite_(e,l.path,l.snap,r,i,a):(h(l.source.fromServer,"Unknown source."),s=l.source.tagged||e.getServerCache().isFiltered()&&!l.path.isEmpty(),o=this.applyServerOverwrite_(e,l.path,l.snap,r,i,s,a))}else if(n.type===Te.MERGE){var c=n;c.source.fromUser?o=this.applyUserMerge_(e,c.path,c.children,r,i,a):(h(c.source.fromServer,"Unknown source."),s=c.source.tagged||e.getServerCache().isFiltered(),o=this.applyServerMerge_(e,c.path,c.children,r,i,s,a))}else if(n.type===Te.ACK_USER_WRITE){var p=n;o=p.revert?this.revertUserWrite_(e,p.path,r,i,a):this.ackUserWrite_(e,p.path,p.affectedTree,r,i,a)}else{if(n.type!==Te.LISTEN_COMPLETE)throw u("Unknown operation type: "+n.type);o=this.listenComplete_(e,n.path,r,a)}var d=a.getChanges();return t.maybeAddValueEvent_(e,o,d),new tn(o,d)},t.maybeAddValueEvent_=function(t,e,n){var r=e.getEventCache();if(r.isFullyInitialized()){var i=r.getNode().isLeafNode()||r.getNode().isEmpty(),o=t.getCompleteEventSnap();(n.length>0||!t.getEventCache().isFullyInitialized()||i&&!r.getNode().equals(o)||!r.getNode().getPriority().equals(o.getPriority()))&&n.push(Ge.valueChange(e.getCompleteEventSnap()))}},t.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(h(t.getServerCache().isFullyInitialized(),"If change path is empty, we must have complete server data"),t.getServerCache().isFiltered()){var u=t.getCompleteServerSnap(),l=u instanceof Ce?u:Ce.EMPTY_NODE,c=n.calcCompleteEventChildren(l);s=this.filter_.updateFullNode(t.getEventCache().getNode(),c,i)}else{var p=n.calcCompleteEventCache(t.getCompleteServerSnap());s=this.filter_.updateFullNode(t.getEventCache().getNode(),p,i)}else{var d=e.getFront();if(".priority"==d){h(1==e.getLength(),"Can't have a priority with additional path components");var f=o.getNode();a=t.getServerCache().getNode();var _=n.calcEventCacheAfterServerOverwrite(e,f,a);s=null!=_?this.filter_.updatePriority(f,_):o.getNode()}else{var y=e.popFront(),v=void 0;if(o.isCompleteForChild(d)){a=t.getServerCache().getNode();var g=n.calcEventCacheAfterServerOverwrite(e,o.getNode(),a);v=null!=g?o.getNode().getImmediateChild(d).updateChild(y,g):o.getNode().getImmediateChild(d)}else v=n.calcCompleteChild(d,t.getServerCache());s=null!=v?this.filter_.updateChild(o.getNode(),d,v,y,r,i):o.getNode()}}return t.updateEventSnap(s,o.isFullyInitialized()||e.isEmpty(),this.filter_.filtersNodes())},t.prototype.applyServerOverwrite_=function(t,e,n,r,i,o,s){var a,h=t.getServerCache(),u=o?this.filter_:this.filter_.getIndexedFilter();if(e.isEmpty())a=u.updateFullNode(h.getNode(),n,null);else if(u.filtersNodes()&&!h.isFiltered()){var l=h.getNode().updateChild(e,n);a=u.updateFullNode(h.getNode(),l,null)}else{var c=e.getFront();if(!h.isCompleteForPath(e)&&e.getLength()>1)return t;var p=e.popFront(),d=h.getNode().getImmediateChild(c).updateChild(p,n);a=".priority"==c?u.updatePriority(h.getNode(),d):u.updateChild(h.getNode(),c,d,p,Je,null)}var f=t.updateServerSnap(a,h.isFullyInitialized()||e.isEmpty(),u.filtersNodes()),_=new Ze(r,f,i);return this.generateEventCacheAfterServerEvent_(f,e,r,_,s)},t.prototype.applyUserOverwrite_=function(t,e,n,r,i,o){var s,a,h=t.getEventCache(),u=new Ze(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 l=e.getFront();if(".priority"===l)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(l),d=void 0;if(c.isEmpty())d=n;else{var f=u.getCompleteChild(l);d=null!=f?".priority"===c.getBack()&&f.getChild(c.parent()).isEmpty()?f:f.updateChild(c,n):Ce.EMPTY_NODE}if(p.equals(d))s=t;else{var _=this.filter_.updateChild(h.getNode(),l,d,c,u,o);s=t.updateEventSnap(_,h.isFullyInitialized(),this.filter_.filtersNodes())}}}return s},t.cacheHasChild_=function(t,e){return t.getEventCache().isCompleteForChild(e)},t.prototype.applyUserMerge_=function(e,n,r,i,o,s){var a=this,h=e;return r.foreach(function(r,u){var l=n.child(r);t.cacheHasChild_(e,l.getFront())&&(h=a.applyUserOverwrite_(h,l,u,i,o,s))}),r.foreach(function(r,u){var l=n.child(r);t.cacheHasChild_(e,l.getFront())||(h=a.applyUserOverwrite_(h,l,u,i,o,s))}),h},t.prototype.applyMerge_=function(t,e){return e.foreach(function(e,n){t=t.updateChild(e,n)}),t},t.prototype.applyServerMerge_=function(t,e,n,r,i,o,s){var a=this;if(t.getServerCache().getNode().isEmpty()&&!t.getServerCache().isFullyInitialized())return t;var h,u=t;h=e.isEmpty()?n:He.Empty.setTree(e,n);var l=t.getServerCache().getNode();return h.children.inorderTraversal(function(e,n){if(l.hasChild(e)){var h=t.getServerCache().getNode().getImmediateChild(e),c=a.applyMerge_(h,n);u=a.applyServerOverwrite_(u,new wt(e),c,r,i,o,s)}}),h.children.inorderTraversal(function(e,n){var h=!t.getServerCache().isCompleteForChild(e)&&null==n.value;if(!l.hasChild(e)&&!h){var c=t.getServerCache().getNode().getImmediateChild(e),p=a.applyMerge_(c,n);u=a.applyServerOverwrite_(u,new wt(e),p,r,i,o,s)}}),u},t.prototype.ackUserWrite_=function(t,e,n,r,i,o){if(null!=r.shadowingWrite(e))return t;var s=t.getServerCache().isFiltered(),a=t.getServerCache();if(null!=n.value){if(e.isEmpty()&&a.isFullyInitialized()||a.isCompleteForPath(e))return this.applyServerOverwrite_(t,e,a.getNode().getChild(e),r,i,s,o);if(e.isEmpty()){var h=He.Empty;return a.getNode().forEachChild(Zt,function(t,e){h=h.set(new wt(t),e)}),this.applyServerMerge_(t,e,h,r,i,s,o)}return t}var u=He.Empty;return n.foreach(function(t,n){var r=e.child(t);a.isCompleteForPath(r)&&(u=u.set(t,a.getNode().getChild(r)))}),this.applyServerMerge_(t,e,u,r,i,s,o)},t.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,Je,r)},t.prototype.revertUserWrite_=function(t,e,n,r,i){var o;if(null!=n.shadowingWrite(e))return t;var s=new Ze(n,t,r),a=t.getEventCache().getNode(),u=void 0;if(e.isEmpty()||".priority"===e.getFront()){var l=void 0;if(t.getServerCache().isFullyInitialized())l=n.calcCompleteEventCache(t.getCompleteServerSnap());else{var c=t.getServerCache().getNode();h(c instanceof Ce,"serverChildren would be complete if leaf node"),l=n.calcCompleteEventChildren(c)}l=l,u=this.filter_.updateFullNode(a,l,i)}else{var p=e.getFront(),d=n.calcCompleteChild(p,t.getServerCache());null==d&&t.getServerCache().isCompleteForChild(p)&&(d=a.getImmediateChild(p)),(u=null!=d?this.filter_.updateChild(a,p,d,e.popFront(),s,i):t.getEventCache().getNode().hasChild(p)?this.filter_.updateChild(a,p,Ce.EMPTY_NODE,e.popFront(),s,i):a).isEmpty()&&t.getServerCache().isFullyInitialized()&&(o=n.calcCompleteEventCache(t.getCompleteServerSnap())).isLeafNode()&&(u=this.filter_.updateFullNode(u,o,i))}return o=t.getServerCache().isFullyInitialized()||null!=n.shadowingWrite(wt.Empty),t.updateEventSnap(u,o,this.filter_.filtersNodes())},t}(),nn=function(){function t(t){this.query_=t,this.index_=this.query_.getQueryParams().getIndex()}return t.prototype.generateEventsForChanges=function(t,e,n){var r=this,i=[],o=[];return t.forEach(function(t){t.type===Ge.CHILD_CHANGED&&r.index_.indexedValueChanged(t.oldSnap,t.snapshotNode)&&o.push(Ge.childMovedChange(t.childName,t.snapshotNode))}),this.generateEventsForType_(i,Ge.CHILD_REMOVED,t,n,e),this.generateEventsForType_(i,Ge.CHILD_ADDED,t,n,e),this.generateEventsForType_(i,Ge.CHILD_MOVED,o,n,e),this.generateEventsForType_(i,Ge.CHILD_CHANGED,t,n,e),this.generateEventsForType_(i,Ge.VALUE,t,n,e),i},t.prototype.generateEventsForType_=function(t,e,n,r,i){var o=this,s=n.filter(function(t){return t.type===e});s.sort(this.compareChanges_.bind(this)),s.forEach(function(e){var n=o.materializeSingleChange_(e,i);r.forEach(function(r){r.respondsTo(e.type)&&t.push(r.createEvent(n,o.query_))})})},t.prototype.materializeSingleChange_=function(t,e){return"value"===t.type||"child_removed"===t.type?t:(t.prevName=e.getPredecessorChildName(t.childName,t.snapshotNode,this.index_),t)},t.prototype.compareChanges_=function(t,e){if(null==t.childName||null==e.childName)throw u("Should only compare child_ events.");var n=new Xt(t.childName,t.snapshotNode),r=new Xt(e.childName,e.snapshotNode);return this.index_.compare(n,r)},t}(),rn=function(){function t(t,e){this.query_=t,this.eventRegistrations_=[];var n=this.query_.getQueryParams(),r=new Xe(n.getIndex()),i=n.getNodeFilter();this.processor_=new en(i);var o=e.getServerCache(),s=e.getEventCache(),a=r.updateFullNode(Ce.EMPTY_NODE,o.getNode(),null),h=i.updateFullNode(Ce.EMPTY_NODE,s.getNode(),null),u=new Ye(a,o.isFullyInitialized(),r.filtersNodes()),l=new Ye(h,s.isFullyInitialized(),i.filtersNodes());this.viewCache_=new ze(l,u),this.eventGenerator_=new nn(this.query_)}return t.prototype.getQuery=function(){return this.query_},t.prototype.getServerCache=function(){return this.viewCache_.getServerCache().getNode()},t.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},t.prototype.isEmpty=function(){return 0===this.eventRegistrations_.length},t.prototype.addEventRegistration=function(t){this.eventRegistrations_.push(t)},t.prototype.removeEventRegistration=function(t,e){var n=[];if(e){h(null==t,"A cancel should cancel all event registrations.");var r=this.query_.path;this.eventRegistrations_.forEach(function(t){e=e;var i=t.createCancelEvent(e,r);i&&n.push(i)})}if(t){for(var i=[],o=0;othis.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},t.prototype.addMerge=function(t,e,n){h(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},t.prototype.getWrite=function(t){for(var e=0;e=0,"removeWrite called with nonexistent writeId.");var r=this.allWrites_[n];this.allWrites_.splice(n,1);for(var i=r.visible,o=!1,s=this.allWrites_.length-1;i&&s>=0;){var a=this.allWrites_[s];a.visible&&(s>=n&&this.recordContainsPath_(a,r.path)?i=!1:r.path.contains(a.path)&&(o=!0)),s--}if(i){if(o)return this.resetTree_(),!0;if(r.snap)this.visibleWrites_=this.visibleWrites_.removeWrite(r.path);else{var u=r.children;I(u,function(t){e.visibleWrites_=e.visibleWrites_.removeWrite(r.path.child(t))})}return!0}return!1},t.prototype.getCompleteWriteData=function(t){return this.visibleWrites_.getCompleteNode(t)},t.prototype.calcCompleteEventCache=function(e,n,r,i){if(r||i){var o=this.visibleWrites_.childCompoundWrite(e);if(!i&&o.isEmpty())return n;if(i||null!=n||o.hasCompleteWrite(wt.Empty)){var s=t.layerTree_(this.allWrites_,function(t){return(t.visible||i)&&(!r||!~r.indexOf(t.writeId))&&(t.path.contains(e)||e.contains(t.path))},e);u=n||Ce.EMPTY_NODE;return s.apply(u)}return null}var a=this.visibleWrites_.getCompleteNode(e);if(null!=a)return a;var h=this.visibleWrites_.childCompoundWrite(e);if(h.isEmpty())return n;if(null!=n||h.hasCompleteWrite(wt.Empty)){var u=n||Ce.EMPTY_NODE;return h.apply(u)}return null},t.prototype.calcCompleteEventChildren=function(t,e){var n=Ce.EMPTY_NODE,r=this.visibleWrites_.getCompleteNode(t);if(r)return r.isLeafNode()||r.forEachChild(he,function(t,e){n=n.updateImmediateChild(t,e)}),n;if(e){var i=this.visibleWrites_.childCompoundWrite(t);return e.forEachChild(he,function(t,e){var r=i.childCompoundWrite(new wt(t)).apply(e);n=n.updateImmediateChild(t,r)}),i.getCompleteChildren().forEach(function(t){n=n.updateImmediateChild(t.name,t.node)}),n}return this.visibleWrites_.childCompoundWrite(t).getCompleteChildren().forEach(function(t){n=n.updateImmediateChild(t.name,t.node)}),n},t.prototype.calcEventCacheAfterServerOverwrite=function(t,e,n,r){h(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))},t.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},t.prototype.shadowingWrite=function(t){return this.visibleWrites_.getCompleteNode(t)},t.prototype.calcIndexedSlice=function(t,e,n,r,i,o){var s,a=this.visibleWrites_.childCompoundWrite(t),h=a.getCompleteNode(wt.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 u=[],l=o.getCompare(),c=i?s.getReverseIteratorFrom(n,o):s.getIteratorFrom(n,o),p=c.getNext();p&&u.length0?this.lastWriteId_=this.allWrites_[this.allWrites_.length-1].writeId:this.lastWriteId_=-1},t.DefaultFilter_=function(t){return t.visible},t.layerTree_=function(t,e,n){for(var r=sn.Empty,i=0;i0&&!r)if(l){this.listenProvider_.stopListening(t.queryForListening_(e),null)}else u.forEach(function(e){var n=i.queryToTagMap_[t.makeQueryKey_(e)];i.listenProvider_.stopListening(t.queryForListening_(e),n)});this.removeTags_(u)}return a},t.prototype.calcCompleteEventCache=function(t,e){var n=this.pendingWriteTree_,r=this.syncPointTree_.findOnPath(t,function(e,n){var r=wt.relativePath(e,t),i=n.getCompleteServerCache(r);if(i)return i});return n.calcCompleteEventCache(t,r,e,!0)},t.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()),I(n,function(t,e){r=r.concat(e)}),r})},t.prototype.removeTags_=function(e){for(var n=0;n0&&S(t.statsToReport_,e)&&(n[e]=i,r=!0)}),r&&this.server_.reportStats(n),Et(this.reportStats_.bind(this),Math.floor(2*Math.random()*3e5))},t}(),gn=function(){function t(){this.eventLists_=[],this.recursionDepth_=0}return t.prototype.queueEvents=function(t){for(var e=null,n=0;n0,"Requires a non-empty array")}return t.prototype.trigger=function(t){for(var e=[],n=1;ndocument.domain="'+document.domain+'";<\/script>';var s=""+o+"";try{this.myIFrame.doc.open(),this.myIFrame.doc.write(s),this.myIFrame.doc.close()}catch(t){nt("frame writing exception"),t.stack&&nt(t.stack),nt(t)}}}return t.createIFrame_=function(){var t=document.createElement("iframe");if(t.style.display="none",!document.body)throw"Document body has not initialized. Wait to initialize Firebase until after the document is ready.";document.body.appendChild(t);try{t.contentWindow.document||nt("No IE domain setting required")}catch(n){var e=document.domain;t.src="javascript:void((function(){document.open();document.domain='"+e+"';document.close();})())"}return t.contentDocument?t.doc=t.contentDocument:t.contentWindow?t.doc=t.contentWindow.document:t.document&&(t.doc=t.document),t},t.prototype.close=function(){var e=this;if(this.alive=!1,this.myIFrame&&(this.myIFrame.doc.body.innerHTML="",setTimeout(function(){null!==e.myIFrame&&(document.body.removeChild(e.myIFrame),e.myIFrame=null)},Math.floor(0))),y()&&this.myID){var n={disconn:"t"};n.id=this.myID,n.pw=this.myPW;var r=this.urlFn(n);t.nodeRestRequest(r)}var i=this.onDisconnect;i&&(this.onDisconnect=null,i())},t.prototype.startLongPoll=function(t,e){for(this.myID=t,this.myPW=e,this.alive=!0;this.newRequest_(););},t.prototype.newRequest_=function(){if(this.alive&&this.sendNewPolls&&this.outstandingRequests.count()<(this.pendingSegs.length>0?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;this.pendingSegs.length>0;){if(!(this.pendingSegs[0].d.length+30+n.length<=1870))break;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},t.prototype.enqueueSegment=function(t,e,n){this.pendingSegs.push({seg:t,ts:e,d:n}),this.alive&&this.newRequest_()},t.prototype.addLongPollTag_=function(t,e){var n=this;this.outstandingRequests.add(e,1);var r=function(){n.outstandingRequests.remove(e),n.newRequest_()},i=setTimeout(r,Math.floor(25e3));this.addTag(t,function(){clearTimeout(i),r()})},t.prototype.addTag=function(t,e){var n=this;y()?this.doNodeLongPoll(t,e):setTimeout(function(){try{if(!n.sendNewPolls)return;var r=n.myIFrame.doc.createElement("script");r.type="text/javascript",r.async=!0,r.src=t,r.onload=r.onreadystatechange=function(){var t=r.readyState;t&&"loaded"!==t&&"complete"!==t||(r.onload=r.onreadystatechange=null,r.parentNode&&r.parentNode.removeChild(r),e())},r.onerror=function(){nt("Long-poll script failed to load: "+t),n.sendNewPolls=!1,n.close()},n.myIFrame.doc.body.appendChild(r)}catch(t){}},Math.floor(1))},t}(),Rn=null;"undefined"!=typeof MozWebSocket?Rn=MozWebSocket:"undefined"!=typeof WebSocket&&(Rn=WebSocket);var Pn=function(){function t(e,n,r,i){this.connId=e,this.keepaliveTimer=null,this.frames=null,this.totalFrames=0,this.bytesSent=0,this.bytesReceived=0,this.log_=rt(this.connId),this.stats_=dn.getCollection(n),this.connURL=t.connectionURL_(n,r,i)}return t.connectionURL_=function(t,e,n){var r={v:"5"};return!y()&&"undefined"!=typeof location&&location.href&&-1!==location.href.indexOf("firebaseio.com")&&(r.r="f"),e&&(r.s=e),n&&(r.ls=n),t.connectionURL("websocket",r)},t.prototype.open=function(t,n){var r=this;this.onDisconnect=n,this.onMessage=t,this.log_("Websocket connecting to "+this.connURL),this.everConnected_=!1,Y.set("previous_websocket_failure",!0);try{if(y()){var i=s?"AdminNode":"Node",o={headers:{"User-Agent":"Firebase/5/"+e.SDK_VERSION+"/"+process.platform+"/"+i}},a=process.env,h=0==this.connURL.indexOf("wss://")?a.HTTPS_PROXY||a.https_proxy:a.HTTP_PROXY||a.http_proxy;h&&(o.proxy={origin:h}),this.mySock=new Rn(this.connURL,[],o)}else this.mySock=new Rn(this.connURL)}catch(t){this.log_("Error instantiating WebSocket.");var u=t.message||t.data;return u&&this.log_(u),void this.onClosed_()}this.mySock.onopen=function(){r.log_("Websocket connected."),r.everConnected_=!0},this.mySock.onclose=function(){r.log_("Websocket connection was disconnected."),r.mySock=null,r.onClosed_()},this.mySock.onmessage=function(t){r.handleIncomingFrame(t)},this.mySock.onerror=function(t){r.log_("WebSocket error. Closing connection.");var e=t.message||t.data;e&&r.log_(e),r.onClosed_()}},t.prototype.start=function(){},t.forceDisallow=function(){t.forceDisallow_=!0},t.isAvailable=function(){var e=!1;if("undefined"!=typeof navigator&&navigator.userAgent){var n=navigator.userAgent.match(/Android ([0-9]{0,}\.[0-9]{0,})/);n&&n.length>1&&parseFloat(n[1])<4.4&&(e=!0)}return!e&&null!==Rn&&!t.forceDisallow_},t.previouslyFailed=function(){return Y.isInMemoryStorage||!0===Y.get("previous_websocket_failure")},t.prototype.markConnectionHealthy=function(){Y.remove("previous_websocket_failure")},t.prototype.appendFrame_=function(t){if(this.frames.push(t),this.frames.length==this.totalFrames){var e=this.frames.join("");this.frames=null;var n=E(e);this.onMessage(n)}},t.prototype.handleNewFrameCount_=function(t){this.totalFrames=t,this.frames=[]},t.prototype.extractFrameCount_=function(t){if(h(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},t.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)}}},t.prototype.send=function(t){this.resetKeepAlive();var e=w(t);this.bytesSent+=e.length,this.stats_.incrementCounter("bytes_sent",e.length);var n=ft(e,16384);n.length>1&&this.sendString_(String(n.length));for(var r=0;r0)return this.transports_[0];throw new Error("No transports available")},t.prototype.upgradeTransport=function(){return this.transports_.length>1?this.transports_[1]:null},t}(),On=function(){function t(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_=rt("c:"+this.id+":"),this.transportManager_=new Dn(e),this.log_("Connection created"),this.start_()}return t.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;i>0&&(this.healthyTimeout_=Et(function(){t.healthyTimeout_=null,t.isHealthy_||(t.conn_&&t.conn_.bytesReceived>102400?(t.log_("Connection exceeded healthy timeout but has received "+t.conn_.bytesReceived+" bytes. Marking connection healthy."),t.isHealthy_=!0,t.conn_.markConnectionHealthy()):t.conn_&&t.conn_.bytesSent>10240?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)))},t.prototype.nextTransportId_=function(){return"c:"+this.id+":"+this.connectionCount++},t.prototype.disconnReceiver_=function(t){var e=this;return function(n){t===e.conn_?e.onConnectionLost_(n):t===e.secondaryConn_?(e.log_("Secondary connection lost."),e.onSecondaryConnectionLost_()):e.log_("closing an old connection")}},t.prototype.connReceiver_=function(t){var e=this;return function(n){2!=e.state_&&(t===e.rx_?e.onPrimaryMessageReceived_(n):t===e.secondaryConn_?e.onSecondaryMessageReceived_(n):e.log_("message on old connection"))}},t.prototype.sendRequest=function(t){var e={t:"d",d:t};this.sendData_(e)},t.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)},t.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_())}},t.prototype.onSecondaryMessageReceived_=function(t){var e=pt("t",t),n=pt("d",t);if("c"==e)this.onSecondaryControl_(n);else{if("d"!=e)throw new Error("Unknown protocol layer: "+e);this.pendingDataMessages.push(n)}},t.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:{}}}))},t.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()},t.prototype.onPrimaryMessageReceived_=function(t){var e=pt("t",t),n=pt("d",t);"c"==e?this.onControl_(n):"d"==e&&this.onDataMessage_(n)},t.prototype.onDataMessage_=function(t){this.onPrimaryResponse_(),this.onMessage_(t)},t.prototype.onPrimaryResponse_=function(){this.isHealthy_||(this.primaryResponsesRequired_--,this.primaryResponsesRequired_<=0&&(this.log_("Primary connection is healthy."),this.isHealthy_=!0,this.conn_.markConnectionHealthy()))},t.prototype.onControl_=function(t){var e=pt("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;r3e4&&(this.reconnectDelay_=xn),this.lastConnectionEstablishedTime_=null}}else 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)},n.prototype.establishConnection_=function(){if(this.shouldReconnect_()){this.log_("Making a connection attempt"),this.lastConnectionAttemptTime_=(new Date).getTime(),this.lastConnectionEstablishedTime_=null;var t=this.onDataMessage_.bind(this),e=this.onReady_.bind(this),r=this.onRealtimeDisconnect_.bind(this),i=this.id+":"+n.nextConnectionId_++,o=this,a=this.lastSessionId,u=!1,l=null,c=function(){l?l.close():(u=!0,r())};this.realtime_={close:c,sendRequest:function(t){h(l,"sendRequest call when we're not connected not allowed."),l.sendRequest(t)}};var p=this.forceTokenRefresh_;this.forceTokenRefresh_=!1,this.authTokenProvider_.getToken(p).then(function(n){u?nt("getToken() completed but was canceled"):(nt("getToken() completed. Creating connection."),o.authToken_=n&&n.accessToken,l=new On(i,o.repoInfo_,t,e,r,function(t){st(t+" ("+o.repoInfo_.toString()+")"),o.interrupt("server_kill")},a))}).then(null,function(t){o.log_("Failed to get token: "+t),u||(s&&st(t),c())})}},n.prototype.interrupt=function(t){nt("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_())},n.prototype.resume=function(t){nt("Resuming connection for reason: "+t),delete this.interruptReasons_[t],R(this.interruptReasons_)&&(this.reconnectDelay_=xn,this.realtime_||this.scheduleConnect_(0))},n.prototype.handleTimestamp_=function(t){var e=t-(new Date).getTime();this.onServerInfoUpdate_({serverTimeOffset:e})},n.prototype.cancelSentTransactions_=function(){for(var t=0;t=3&&(this.reconnectDelay_=3e4,this.authTokenProvider_.notifyForInvalidToken()))},n.prototype.onSecurityDebugPacket_=function(t){this.securityDebugCallback_?this.securityDebugCallback_(t):"msg"in t&&console.log("FIREBASE: "+t.msg.replace("\n","\nFIREBASE: "))},n.prototype.restoreState_=function(){var t=this;this.tryAuth(),I(this.listens_,function(e,n){I(n,function(e,n){t.sendListen_(n)})});for(var e=0;e=200&&h.status<300){try{t=E(h.responseText)}catch(t){st("Failed to parse JSON response for "+a+": "+h.responseText)}n(null,t)}else 401!==h.status&&404!==h.status&&st("Got unsuccessful REST response for "+a+" Status: "+h.status),n(h.status);n=null}},h.open("GET",a,!0),h.send()})},e}(kn),Mn=function(){function t(t,e,n){var r=this;this.repoInfo_=t,this.app=n,this.dataUpdateCount=0,this.statsListener_=null,this.eventQueue_=new gn,this.nextWriteId_=1,this.interceptServerDataCallback_=null,this.onDisconnect_=new Ae,this.persistentConnection_=null;var i=new cn(n);if(this.stats_=dn.getCollection(t),e||Ct())this.server_=new Ln(this.repoInfo_,this.onDataUpdate_.bind(this),i),setTimeout(this.onConnectStatus_.bind(this,!0),0);else{var o=n.options.databaseAuthVariableOverride;if(void 0!==o&&null!==o){if("object"!=typeof o)throw new Error("Only objects are supported for option databaseAuthVariableOverride");try{w(o)}catch(t){throw new Error("Invalid authOverride provided: "+t)}}this.persistentConnection_=new An(this.repoInfo_,this.onDataUpdate_.bind(this),this.onConnectStatus_.bind(this),this.onServerInfoUpdate_.bind(this),i,o),this.server_=this.persistentConnection_}i.addTokenChangeListener(function(t){r.server_.refreshAuthToken(t)}),this.statsReporter_=dn.getOrCreateReporter(t,function(){return new vn(r.stats_,r.server_)}),this.transactions_init_(),this.infoData_=new ln,this.infoSyncTree_=new un({startListening:function(t,e,n,i){var o=[],s=r.infoData_.getNode(t.path);return s.isEmpty()||(o=r.infoSyncTree_.applyServerOverwrite(t.path,s),setTimeout(function(){i("ok")},0)),o},stopListening:function(){}}),this.updateInfo_("connected",!1),this.serverSyncTree_=new un({startListening:function(t,e,n,i){return r.server_.listen(t,n,e,function(e,n){var o=i(e,n);r.eventQueue_.raiseEventsForChangedPath(t.path,o)}),[]},stopListening:function(t,e){r.server_.unlisten(t,e)}})}return t.prototype.toString=function(){return(this.repoInfo_.secure?"https://":"http://")+this.repoInfo_.host},t.prototype.name=function(){return this.repoInfo_.namespace},t.prototype.serverTime=function(){var t=this.infoData_.getNode(new wt(".info/serverTimeOffset")).val()||0;return(new Date).getTime()+t},t.prototype.generateServerValues=function(){return(t=(t={timestamp:this.serverTime()})||{}).timestamp=t.timestamp||(new Date).getTime(),t;var t},t.prototype.onDataUpdate_=function(t,e,n,r){this.dataUpdateCount++;var i=new wt(t);e=this.interceptServerDataCallback_?this.interceptServerDataCallback_(t,e):e;var o=[];if(r)if(n){var s=D(e,function(t){return be(t)});o=this.serverSyncTree_.applyTaggedQueryMerge(i,s,r)}else{var a=be(e);o=this.serverSyncTree_.applyTaggedQueryOverwrite(i,a,r)}else if(n){var h=D(e,function(t){return be(t)});o=this.serverSyncTree_.applyServerMerge(i,h)}else{var u=be(e);o=this.serverSyncTree_.applyServerOverwrite(i,u)}var l=i;o.length>0&&(l=this.rerunTransactions_(i)),this.eventQueue_.raiseEventsForChangedPath(l,o)},t.prototype.interceptServerData_=function(t){this.interceptServerDataCallback_=t},t.prototype.onConnectStatus_=function(t){this.updateInfo_("connected",t),!1===t&&this.runOnDisconnectEvents_()},t.prototype.onServerInfoUpdate_=function(t){var e=this;_t(t,function(t,n){e.updateInfo_(n,t)})},t.prototype.updateInfo_=function(t,e){var n=new wt("/.info/"+t),r=be(e);this.infoData_.updateSnapshot(n,r);var i=this.infoSyncTree_.applyServerOverwrite(n,r);this.eventQueue_.raiseEventsForChangedPath(n,i)},t.prototype.getNextWriteId_=function(){return this.nextWriteId_++},t.prototype.setWithPriority=function(t,e,n,r){var i=this;this.log_("set",{path:t.toString(),value:e,priority:n});var o=this.generateServerValues(),s=be(e,n),a=Me(s,o),h=this.getNextWriteId_(),u=this.serverSyncTree_.applyUserOverwrite(t,a,h,!0);this.eventQueue_.queueEvents(u),this.server_.put(t.toString(),s.val(!0),function(e,n){var o="ok"===e;o||st("set at "+t+" failed: "+e);var s=i.serverSyncTree_.ackUserWrite(h,!o);i.eventQueue_.raiseEventsForChangedPath(t,s),i.callOnCompleteCallback(r,e,n)});var l=this.abortTransactions_(t);this.rerunTransactions_(l),this.eventQueue_.raiseEventsForChangedPath(l,[])},t.prototype.update=function(t,e,n){var r=this;this.log_("update",{path:t.toString(),value:e});var i=!0,o=this.generateServerValues(),s={};if(I(e,function(t,e){i=!1;var n=be(e);s[t]=Me(n,o)}),i)nt("update() called with empty data. Don't do anything."),this.callOnCompleteCallback(n,"ok");else{var a=this.getNextWriteId_(),h=this.serverSyncTree_.applyUserMerge(t,s,a);this.eventQueue_.queueEvents(h),this.server_.merge(t.toString(),e,function(e,i){var o="ok"===e;o||st("update at "+t+" failed: "+e);var s=r.serverSyncTree_.ackUserWrite(a,!o),h=s.length>0?r.rerunTransactions_(t):t;r.eventQueue_.raiseEventsForChangedPath(h,s),r.callOnCompleteCallback(n,e,i)}),I(e,function(e){var n=r.abortTransactions_(t.child(e));r.rerunTransactions_(n)}),this.eventQueue_.raiseEventsForChangedPath(t,[])}},t.prototype.runOnDisconnectEvents_=function(){var t=this;this.log_("onDisconnectEvents");var e=this.generateServerValues(),n=[];(function(t,e){var n=new Ae;return t.forEachTree(new wt(""),function(t,r){n.remember(t,Me(r,e))}),n})(this.onDisconnect_,e).forEachTree(wt.Empty,function(e,r){n=n.concat(t.serverSyncTree_.applyServerOverwrite(e,r));var i=t.abortTransactions_(e);t.rerunTransactions_(i)}),this.onDisconnect_=new Ae,this.eventQueue_.raiseEventsForChangedPath(wt.Empty,n)},t.prototype.onDisconnectCancel=function(t,e){var n=this;this.server_.onDisconnectCancel(t.toString(),function(r,i){"ok"===r&&n.onDisconnect_.forget(t),n.callOnCompleteCallback(e,r,i)})},t.prototype.onDisconnectSet=function(t,e,n){var r=this,i=be(e);this.server_.onDisconnectPut(t.toString(),i.val(!0),function(e,o){"ok"===e&&r.onDisconnect_.remember(t,i),r.callOnCompleteCallback(n,e,o)})},t.prototype.onDisconnectSetWithPriority=function(t,e,n,r){var i=this,o=be(e,n);this.server_.onDisconnectPut(t.toString(),o.val(!0),function(e,n){"ok"===e&&i.onDisconnect_.remember(t,o),i.callOnCompleteCallback(r,e,n)})},t.prototype.onDisconnectUpdate=function(t,e,n){var r=this;if(R(e))return nt("onDisconnect().update() called with empty data. Don't do anything."),void this.callOnCompleteCallback(n,"ok");this.server_.onDisconnectMerge(t.toString(),e,function(i,o){"ok"===i&&I(e,function(e,n){var i=be(n);r.onDisconnect_.remember(t.child(e),i)}),r.callOnCompleteCallback(n,i,o)})},t.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)},t.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)},t.prototype.interrupt=function(){this.persistentConnection_&&this.persistentConnection_.interrupt("repo_interrupt")},t.prototype.resume=function(){this.persistentConnection_&&this.persistentConnection_.resume("repo_interrupt")},t.prototype.stats=function(t){if(void 0===t&&(t=!1),"undefined"!=typeof console){var e;t?(this.statsListener_||(this.statsListener_=new fn(this.stats_)),e=this.statsListener_.get()):e=this.stats_.get();var n=Object.keys(e).reduce(function(t,e){return Math.max(e.length,t)},0);I(e,function(t,e){for(var r=t.length;r=0)return null!=i&&i.trackChildChange(Ge.childChangedChange(e,n,p)),a.updateImmediateChild(e,n);null!=i&&i.trackChildChange(Ge.childRemovedChange(e,p));var _=a.updateImmediateChild(e,Ce.EMPTY_NODE);return null!=d&&this.rangedFilter_.matches(d)?(null!=i&&i.trackChildChange(Ge.childAddedChange(d.name,d.node)),_.updateImmediateChild(d.name,d.node)):_}return n.isEmpty()?t:c&&o(l,u)>=0?(null!=i&&(i.trackChildChange(Ge.childRemovedChange(l.name,l.node)),i.trackChildChange(Ge.childAddedChange(e,n))),a.updateImmediateChild(e,n).updateImmediateChild(l.name,Ce.EMPTY_NODE)):t},t}(),Qn=function(){function t(){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_=he}return t.prototype.hasStart=function(){return this.startSet_},t.prototype.isViewFromLeft=function(){return""===this.viewFrom_?this.startSet_:this.viewFrom_===t.WIRE_PROTOCOL_CONSTANTS_.VIEW_FROM_LEFT},t.prototype.getIndexStartValue=function(){return h(this.startSet_,"Only valid if start has been set"),this.indexStartValue_},t.prototype.getIndexStartName=function(){return h(this.startSet_,"Only valid if start has been set"),this.startNameSet_?this.indexStartName_:ht},t.prototype.hasEnd=function(){return this.endSet_},t.prototype.getIndexEndValue=function(){return h(this.endSet_,"Only valid if end has been set"),this.indexEndValue_},t.prototype.getIndexEndName=function(){return h(this.endSet_,"Only valid if end has been set"),this.endNameSet_?this.indexEndName_:ut},t.prototype.hasLimit=function(){return this.limitSet_},t.prototype.hasAnchoredLimit=function(){return this.limitSet_&&""!==this.viewFrom_},t.prototype.getLimit=function(){return h(this.limitSet_,"Only valid if limit has been set"),this.limit_},t.prototype.getIndex=function(){return this.index_},t.prototype.copy_=function(){var e=new t;return e.limitSet_=this.limitSet_,e.limit_=this.limit_,e.startSet_=this.startSet_,e.indexStartValue_=this.indexStartValue_,e.startNameSet_=this.startNameSet_,e.indexStartName_=this.indexStartName_,e.endSet_=this.endSet_,e.indexEndValue_=this.indexEndValue_,e.endNameSet_=this.endNameSet_,e.indexEndName_=this.indexEndName_,e.index_=this.index_,e.viewFrom_=this.viewFrom_,e},t.prototype.limit=function(t){var e=this.copy_();return e.limitSet_=!0,e.limit_=t,e.viewFrom_="",e},t.prototype.limitToFirst=function(e){var n=this.copy_();return n.limitSet_=!0,n.limit_=e,n.viewFrom_=t.WIRE_PROTOCOL_CONSTANTS_.VIEW_FROM_LEFT,n},t.prototype.limitToLast=function(e){var n=this.copy_();return n.limitSet_=!0,n.limit_=e,n.viewFrom_=t.WIRE_PROTOCOL_CONSTANTS_.VIEW_FROM_RIGHT,n},t.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},t.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},t.prototype.orderBy=function(t){var e=this.copy_();return e.index_=t,e},t.prototype.getQueryObject=function(){var e=t.WIRE_PROTOCOL_CONSTANTS_,n={};if(this.startSet_&&(n[e.INDEX_START_VALUE]=this.indexStartValue_,this.startNameSet_&&(n[e.INDEX_START_NAME]=this.indexStartName_)),this.endSet_&&(n[e.INDEX_END_VALUE]=this.indexEndValue_,this.endNameSet_&&(n[e.INDEX_END_NAME]=this.indexEndName_)),this.limitSet_){n[e.LIMIT]=this.limit_;var r=this.viewFrom_;""===r&&(r=this.isViewFromLeft()?e.VIEW_FROM_LEFT:e.VIEW_FROM_RIGHT),n[e.VIEW_FROM]=r}return this.index_!==he&&(n[e.INDEX]=this.index_.toString()),n},t.prototype.loadsAllData=function(){return!(this.startSet_||this.endSet_||this.limitSet_)},t.prototype.isDefault=function(){return this.loadsAllData()&&this.index_==he},t.prototype.getNodeFilter=function(){return this.loadsAllData()?new Xe(this.getIndex()):this.hasLimit()?new qn(this):new Wn(this)},t.prototype.toRestQueryStringParameters=function(){var e,n=t.REST_QUERY_CONSTANTS_,r={};return this.isDefault()?r:(this.index_===he?e=n.PRIORITY_INDEX:this.index_===Ie?e=n.VALUE_INDEX:this.index_===Zt?e=n.KEY_INDEX:(h(this.index_ instanceof Ne,"Unrecognized index type!"),e=this.index_.toString()),r[n.ORDER_BY]=w(e),this.startSet_&&(r[n.START_AT]=w(this.indexStartValue_),this.startNameSet_&&(r[n.START_AT]+=","+w(this.indexStartName_))),this.endSet_&&(r[n.END_AT]=w(this.indexEndValue_),this.endNameSet_&&(r[n.END_AT]+=","+w(this.indexEndName_))),this.limitSet_&&(this.isViewFromLeft()?r[n.LIMIT_TO_FIRST]=this.limit_:r[n.LIMIT_TO_LAST]=this.limit_),r)},t.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"},t.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"},t.DEFAULT=new t,t}(),Un=function(t){function e(e,n){if(!(e instanceof Mn))throw new Error("new Reference() no longer supported - use app.database().");return t.call(this,e,n,Qn.DEFAULT,!1)||this}return r(e,t),e.prototype.getKey=function(){return F("Reference.key",0,0,arguments.length),this.path.isEmpty()?null:this.path.getBack()},e.prototype.child=function(t){return F("Reference.child",1,1,arguments.length),"number"==typeof t?t=String(t):t instanceof wt||(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 e(this.repo,this.path.child(t))},e.prototype.getParent=function(){F("Reference.parent",0,0,arguments.length);var t=this.path.parent();return null===t?null:new e(this.repo,t)},e.prototype.getRoot=function(){F("Reference.root",0,0,arguments.length);for(var t=this;null!==t.getParent();)t=t.getParent();return t},e.prototype.databaseProp=function(){return this.repo.database},e.prototype.set=function(t,e){F("Reference.set",1,2,arguments.length),jt("Reference.set",this.path),Wt("Reference.set",1,t,this.path,!1),L("Reference.set",2,e,!0);var n=new f;return this.repo.setWithPriority(this.path,t,null,n.wrapCallback(e)),n.promise},e.prototype.update=function(t,e){if(F("Reference.update",1,2,arguments.length),jt("Reference.update",this.path),Array.isArray(t)){for(var n={},r=0;r0},t.prototype.isEmpty=function(){return null===this.getValue()&&!this.hasChildren()},t.prototype.forEachChild=function(e){var n=this;I(this.node_.children,function(r,i){e(new t(r,n,i))})},t.prototype.forEachDescendant=function(t,e,n){e&&!n&&t(this),this.forEachChild(function(e){e.forEachDescendant(t,!0,n)}),e&&n&&t(this)},t.prototype.forEachAncestor=function(t,e){for(var n=e?this:this.parent();null!==n;){if(t(n))return!0;n=n.parent()}return!1},t.prototype.forEachImmediateDescendantWithValue=function(t){this.forEachChild(function(e){null!==e.getValue()?t(e):e.forEachImmediateDescendantWithValue(t)})},t.prototype.path=function(){return new wt(null===this.parent_?this.name_:this.parent_.path()+"/"+this.name_)},t.prototype.name=function(){return this.name_},t.prototype.parent=function(){return this.parent_},t.prototype.updateParents_=function(){null!==this.parent_&&this.parent_.updateChild_(this.name_,this)},t.prototype.updateChild_=function(t,e){var n=e.isEmpty(),r=S(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_())},t}();!function(t){t[t.RUN=0]="RUN",t[t.SENT=1]="SENT",t[t.COMPLETED=2]="COMPLETED",t[t.SENT_NEEDS_ABORT=3]="SENT_NEEDS_ABORT",t[t.NEEDS_ABORT=4]="NEEDS_ABORT"}(Vn||(Vn={})),Mn.MAX_TRANSACTION_RETRIES_=25,Mn.prototype.transactions_init_=function(){this.transactionQueueTree_=new Bn},Mn.prototype.startTransaction=function(t,e,n,r){this.log_("transaction on "+t);var i=function(){},o=new Un(this,t);o.on("value",i);var s={path:t,update:e,onComplete:n,status:null,order:X(),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 u=s.update(a.val());if(void 0===u){if(s.unwatcher(),s.currentOutputSnapshotRaw=null,s.currentOutputSnapshotResolved=null,s.onComplete){var l=new Re(s.currentInputSnapshot,new Un(this,s.path),he);s.onComplete(null,!1,l)}}else{qt("transaction failed: Data returned ",u,s.path),s.status=Vn.RUN;var c=this.transactionQueueTree_.subTree(t),p=c.getValue()||[];p.push(s),c.setValue(p);var d=void 0;if("object"==typeof u&&null!==u&&S(u,".priority"))d=T(u,".priority"),h(Mt(d),"Invalid priority returned by transaction. Priority must be a valid string, finite number, server value, or null.");else d=(this.serverSyncTree_.calcCompleteEventCache(t)||Ce.EMPTY_NODE).getPriority().val();d=d;var f=this.generateServerValues(),_=be(u,d),y=Me(_,f);s.currentOutputSnapshotRaw=_,s.currentOutputSnapshotResolved=y,s.currentWriteId=this.getNextWriteId_();var v=this.serverSyncTree_.applyUserOverwrite(t,y,s.currentWriteId,s.applyLocally);this.eventQueue_.raiseEventsForChangedPath(t,v),this.sendReadyTransactions_()}},Mn.prototype.getLatestState_=function(t,e){return this.serverSyncTree_.calcCompleteEventCache(t,e)||Ce.EMPTY_NODE},Mn.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);h(n.length>0,"Sending zero length transaction queue"),n.every(function(t){return t.status===Vn.RUN})&&this.sendTransactionQueue_(t.path(),n)}else t.hasChildren()&&t.forEachChild(function(t){e.sendReadyTransactions_(t)})},Mn.prototype.sendTransactionQueue_=function(t,e){for(var n=this,r=e.map(function(t){return t.currentWriteId}),i=this.getLatestState_(t,r),o=i,s=i.hash(),a=0;a=Mn.MAX_TRANSACTION_RETRIES_)l=!0,c="maxretry",i=i.concat(this.serverSyncTree_.ackUserWrite(a.currentWriteId,!0));else{var p=this.getLatestState_(a.path,o);a.currentInputSnapshot=p;var d=t[s].update(p.val());if(void 0!==d){qt("transaction failed: Data returned ",d,a.path);var f=be(d);"object"==typeof d&&null!=d&&S(d,".priority")||(f=f.updatePriority(p.getPriority()));var _=a.currentWriteId,y=this.generateServerValues(),v=Me(f,y);a.currentOutputSnapshotRaw=f,a.currentOutputSnapshotResolved=v,a.currentWriteId=this.getNextWriteId_(),o.splice(o.indexOf(_),1),i=(i=i.concat(this.serverSyncTree_.applyUserOverwrite(a.path,v,a.currentWriteId,a.applyLocally))).concat(this.serverSyncTree_.ackUserWrite(_,!0))}else l=!0,c="nodata",i=i.concat(this.serverSyncTree_.ackUserWrite(a.currentWriteId,!0))}if(this.eventQueue_.raiseEventsForChangedPath(e,i),i=[],l&&(t[s].status=Vn.COMPLETED,n=t[s].unwatcher,setTimeout(n,Math.floor(0)),t[s].onComplete))if("nodata"===c){var g=new Un(this,t[s].path),m=t[s].currentInputSnapshot,C=new Re(m,g,he);r.push(t[s].onComplete.bind(null,null,!1,C))}else r.push(t[s].onComplete.bind(null,new Error(c),!1,null))}this.pruneCompletedTransactionsBelowNode_(this.transactionQueueTree_);for(s=0;s0?n:null)}t.forEachChild(function(t){e.pruneCompletedTransactionsBelowNode_(t)})},Mn.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},Mn.prototype.abortTransactionsOnNode_=function(t){var e=t.getValue();if(null!==e){for(var n=[],r=[],i=-1,o=0;o