PageSourceSearch

https://www.sporfie.com/_next/static/immutable/chunks/07d1fjv5ic2i9.js

js sporfie.com collected 2026-10-02 14:41:09 UTC 164,570 bytes, 4 lines download raw bytes

1;!function(){try { var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&((e._debugIds|| (e._debugIds={}))[n]="39ce4ffd-5d53-6cb8-548b-f1d7a414be8c")}catch(e){}}();
2(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,401465,476686,e=>{"use strict";var t,n,i,r,o,a,s,u,l,h,c,d,f,_,v,p=e.i(247167),y=e.i(991865),g=e.i(38981),m=e.i(292955),k=e.i(780646),C=e.i(64217),w=e.i(108487),T=e.i(651682),b=e.i(540316),I=e.i(500075),E=e.i(513935),S=e.i(485086),P=e.i(965233),N=e.i(733015),x=e.i(68483),R="@firebase/database",D="1.0.3",A="";function M(e){A=e}var q=function(){function e(t){(0,m._)(this,e),this.domStorage_=t,this.prefix_="firebase:"}return(0,k._)(e,[{key:"set",value:function(e,t){null==t?this.domStorage_.removeItem(this.prefixedName_(e)):this.domStorage_.setItem(this.prefixedName_(e),(0,N.stringify)(t))}},{key:"get",value:function(e){var t=this.domStorage_.getItem(this.prefixedName_(e));return null==t?null:(0,N.jsonEval)(t)}},{key:"remove",value:function(e){this.domStorage_.removeItem(this.prefixedName_(e))}},{key:"prefixedName_",value:function(e){return this.prefix_+e}},{key:"toString",value:function(){return this.domStorage_.toString()}}]),e}(),F=function(){function e(){(0,m._)(this,e),this.cache_={},this.isInMemoryStorage=!0}return(0,k._)(e,[{key:"set",value:function(e,t){null==t?delete this.cache_[e]:this.cache_[e]=t}},{key:"get",value:function(e){return(0,N.contains)(this.cache_,e)?this.cache_[e]:null}},{key:"remove",value:function(e){delete this.cache_[e]}}]),e}(),L=function(e){try{if("u">typeof window&&void 0!==window[e]){var t=window[e];return t.setItem("firebase:sentinel","cache"),t.removeItem("firebase:sentinel"),new q(t)}}catch(e){}return new F},O=L("localStorage"),W=L("sessionStorage"),U=new x.Logger("@firebase/database"),B=(t=1,function(){return t++}),j=function(e){var t=(0,N.stringToByteArray)(e),n=new N.Sha1;n.update(t);var i=n.digest();return N.base64.encodeByteArray(i)},V=function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];for(var i="",r=0;r<t.length;r++){var o=t[r];Array.isArray(o)||o&&(void 0===o?"undefined":(0,I._)(o))==="object"&&"number"==typeof o.length?i+=V.apply(null,o):(void 0===o?"undefined":(0,I._)(o))==="object"?i+=(0,N.stringify)(o):i+=o,i+=" "}return i},H=null,z=!0,Y=function(e,t){(0,N.assert)(!t||!0===e||!1===e,"Can't turn on custom loggers persistently."),!0===e?(U.logLevel=x.LogLevel.VERBOSE,H=U.log.bind(U),t&&W.set("logging_enabled",!0)):"function"==typeof e?H=e:(H=null,W.remove("logging_enabled"))},K=function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];if(!0===z&&(z=!1,null===H&&!0===W.get("logging_enabled")&&Y(!0)),H){var i=V.apply(null,t);H(i)}},Q=function(e){return function(){for(var t=arguments.length,n=Array(t),i=0;i<t;i++)n[i]=arguments[i];K.apply(void 0,[e].concat((0,b._)(n)))}},G=function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];var i="FIREBASE INTERNAL ERROR: "+V.apply(void 0,(0,b._)(t));U.error(i)},$=function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];var i="FIREBASE FATAL ERROR: ".concat(V.apply(void 0,(0,b._)(t)));throw U.error(i),Error(i)},X=function(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];var i="FIREBASE WARNING: "+V.apply(void 0,(0,b._)(t));U.warn(i)},J=function(){"u">typeof window&&window.location&&window.location.protocol&&-1!==window.location.protocol.indexOf("https:")&&X("Insecure Firebase access from a secure page. Please use https in calls to new Firebase().")},Z=function(e){return"number"==typeof e&&(e!=e||e===1/0||e===-1/0)},ee=function(e){if((0,N.isNodeSdk)()||"complete"===document.readyState)e();else{var t=!1,n=function(){document.body?t||(t=!0,e()):setTimeout(n,Math.floor(10))};document.addEventListener?(document.addEventListener("DOMContentLoaded",n,!1),window.addEventListener("load",n,!1)):document.attachEvent&&(document.attachEvent("onreadystatechange",function(){"complete"===document.readyState&&n()}),window.attachEvent("onload",n))}},et="[MIN_NAME]",en="[MAX_NAME]",ei=function(e,t){if(e===t)return 0;if(e===et||t===en)return -1;if(t===et||e===en)return 1;var n=ec(e),i=ec(t);if(null!==n)if(null!==i)return n-i==0?e.length-t.length:n-i;else return -1;return null!==i?1:e<t?-1:1},er=function(e,t){return e===t?0:e<t?-1:1},eo=function(e,t){if(t&&e in t)return t[e];throw Error("Missing required key ("+e+") in object: "+(0,N.stringify)(t))},ea=function(e){if((void 0===e?"undefined":(0,I._)(e))!=="object"||null===e)return(0,N.stringify)(e);var t=[];for(var n in e)t.push(n);
2t.sort();for(var i="{",r=0;r<t.length;r++)0!==r&&(i+=","),i+=(0,N.stringify)(t[r]),i+=":",i+=ea(e[t[r]]);return i+"}"},es=function(e,t){var n=e.length;if(n<=t)return[e];for(var i=[],r=0;r<n;r+=t)r+t>n?i.push(e.substring(r,n)):i.push(e.substring(r,r+t));return i};function eu(e,t){for(var n in e)e.hasOwnProperty(n)&&t(n,e[n])}var el=function(e){(0,N.assert)(!Z(e),"Invalid JSON number"),0===e?(n=0,i=0,t=+(1/e==-1/0)):(t=e<0,(e=Math.abs(e))>=22250738585072014e-324?(n=(r=Math.min(Math.floor(Math.log(e)/Math.LN2),1023))+1023,i=Math.round(e*Math.pow(2,52-r)-0x10000000000000)):(n=0,i=Math.round(e/5e-324)));var t,n,i,r,o,a=[];for(o=52;o;o-=1)a.push(i%2?1:0),i=Math.floor(i/2);for(o=11;o;o-=1)a.push(n%2?1:0),n=Math.floor(n/2);a.push(+!!t),a.reverse();var s=a.join(""),u="";for(o=0;o<64;o+=8){var l=parseInt(s.substr(o,8),2).toString(16);1===l.length&&(l="0"+l),u+=l}return u.toLowerCase()},eh=RegExp("^-?(0*)\\d{1,10}$"),ec=function(e){if(eh.test(e)){var t=Number(e);if(t>=-0x80000000&&t<=0x7fffffff)return t}return null},ed=function(e){try{e()}catch(e){setTimeout(function(){throw X("Exception was thrown by user callback.",e.stack||""),e},Math.floor(0))}},ef=function(e,t){var n=setTimeout(e,t);return"number"==typeof n&&"u">typeof Deno&&Deno.unrefTimer?Deno.unrefTimer(n):(void 0===n?"undefined":(0,I._)(n))==="object"&&n.unref&&n.unref(),n},e_=function(){function e(t,n){var i=this;(0,m._)(this,e),this.appName_=t,this.appCheckProvider=n,this.appCheck=null==n?void 0:n.getImmediate({optional:!0}),this.appCheck||null==n||n.get().then(function(e){return i.appCheck=e})}return(0,k._)(e,[{key:"getToken",value:function(e){var t=this;return this.appCheck?this.appCheck.getToken(e):new Promise(function(n,i){setTimeout(function(){t.appCheck?t.getToken(e).then(n,i):n(null)},0)})}},{key:"addTokenChangeListener",value:function(e){var t;null==(t=this.appCheckProvider)||t.get().then(function(t){return t.addTokenListener(e)})}},{key:"notifyForInvalidToken",value:function(){X('Provided AppCheck credentials for the app named "'.concat(this.appName_,'" ')+"are invalid. This usually indicates your app was not initialized correctly.")}}]),e}(),ev=function(){function e(t,n,i){var r=this;(0,m._)(this,e),this.appName_=t,this.firebaseOptions_=n,this.authProvider_=i,this.auth_=null,this.auth_=i.getImmediate({optional:!0}),this.auth_||i.onInit(function(e){return r.auth_=e})}return(0,k._)(e,[{key:"getToken",value:function(e){var t=this;return this.auth_?this.auth_.getToken(e).catch(function(e){return e&&"auth/token-not-initialized"===e.code?(K("Got auth/token-not-initialized error.  Treating as null token."),null):Promise.reject(e)}):new Promise(function(n,i){setTimeout(function(){t.auth_?t.getToken(e).then(n,i):n(null)},0)})}},{key:"addTokenChangeListener",value:function(e){this.auth_?this.auth_.addAuthTokenListener(e):this.authProvider_.get().then(function(t){return t.addAuthTokenListener(e)})}},{key:"removeTokenChangeListener",value:function(e){this.authProvider_.get().then(function(t){return t.removeAuthTokenListener(e)})}},{key:"notifyForInvalidToken",value:function(){var e='Provided authentication credentials for the app named "'+this.appName_+'" are invalid. This usually indicates your app was not initialized correctly. ';"credential"in this.firebaseOptions_?e+='Make sure the "credential" property provided to initializeApp() is authorized to access the specified "databaseURL" and is from the correct project.':"serviceAccount"in this.firebaseOptions_?e+='Make sure the "serviceAccount" property provided to initializeApp() is authorized to access the specified "databaseURL" and is from the correct project.':e+='Make sure the "apiKey" and "databaseURL" properties provided to initializeApp() match the values provided for your app at https://console.firebase.google.com/.',X(e)}}]),e}(),ep=function(){function e(t){(0,m._)(this,e),this.accessToken=t}return(0,k._)(e,[{key:"getToken",value:function(e){return Promise.resolve({accessToken:this.accessToken})}},{key:"addTokenChangeListener",value:function(e){e(this.accessToken)}},{key:"removeTokenChangeListener",value:function(e){}},{key:"notifyForInvalidToken",value:function(){}}]),e}();ep.OWNER="owner";var ey=/(console\.firebase|firebase-console-\w+\.corp|firebase\.corp)\.google\.com/,eg="websocket",em="long_polling",ek=function(){function e(t,n,i,r){var o=arguments.length>4&&void 0!==arguments[4]&&arguments[4],a=arguments.length>5&&void 0!==arguments[5]?arguments[5]:"",s=arguments.length>6&&void 0!==arguments[6]&&arguments[6],u=arguments.length>7&&void 0!==arguments[7]&&arguments[7];(0,m._)(this,e),this.secure=n,this.namespace=i,this.webSocketOnly=r,this.nodeAdmin=o,this.persistenceKey=a,this.includeNamespaceInQueryParams=s,this.isUsingEmulator=u,this._host=t.toLowerCase(),this._domain=this._host.substr(this._host.indexOf(".")+1),this.internalHost=O.get("host:"+t)||this._host}return(0,k._)(e,[{key:"isCacheableHost",value:function(){return"s-"===this.internalHost.substr(0,2)}},{key:"isCustomHost",value:function(){return"firebaseio.com"!==this._domain&&"firebaseio-demo.com"!==this._domain}},{key:"host",get:function(){return this._host},set:function(e){e!==this.internalHost&&(this.internalHost=e,this.isCacheableHost()&&O.set("host:"+this._host,this.internalHost))}},{key:"toString",value:function(){var e=this.toURLString();return this.persistenceKey&&(e+="<"+this.persistenceKey+">"),e}},{key:"toURLString",value:function(){var e=this.secure?"https://":"http://",t=this.includeNamespaceInQueryParams?"?ns=".concat(this.namespace):"";return"".concat(e).concat(this.host,"/").concat(t)}}]),e}();function eC(e,t,n){if((0,N.assert)("string"==typeof t,"typeof type must == string"),(0,N.assert)((void 0===n?"undefined":(0,I._)(n))==="object","typeof params must == object"),t===eg)i=(e.secure?"wss://":"ws://")+e.internalHost+"/.ws?";else if(t===em)i=(e.secure?"https://":"http://")+e.internalHost+"/.lp?";else throw Error("Unknown connection type: "+t);(e.host!==e.internalHost||e.isCustomHost()||e.includeNamespaceInQueryParams)&&
2(n.ns=e.namespace);var i,r=[];return eu(n,function(e,t){r.push(e+"="+t)}),i+r.join("&")}var ew=function(){function e(){(0,m._)(this,e),this.counters_={}}return(0,k._)(e,[{key:"incrementCounter",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1;(0,N.contains)(this.counters_,e)||(this.counters_[e]=0),this.counters_[e]+=t}},{key:"get",value:function(){return(0,N.deepCopy)(this.counters_)}}]),e}(),eT={},eb={};function eI(e){var t=e.toString();return eT[t]||(eT[t]=new ew),eT[t]}var eE=function(){function e(t){(0,m._)(this,e),this.onMessage_=t,this.pendingResponses=[],this.currentResponseNum=0,this.closeAfterResponse=-1,this.onClose=null}return(0,k._)(e,[{key:"closeAfter",value:function(e,t){this.closeAfterResponse=e,this.onClose=t,this.closeAfterResponse<this.currentResponseNum&&(this.onClose(),this.onClose=null)}},{key:"handleResponse",value:function(e,t){var n,i=this;for(this.pendingResponses[e]=t;this.pendingResponses[this.currentResponseNum]&&"break"!==(n=this,function(){var e=function(e){t[e]&&ed(function(){i.onMessage_(t[e])})},t=n.pendingResponses[n.currentResponseNum];delete n.pendingResponses[n.currentResponseNum];for(var r=0;r<t.length;++r)e(r);if(n.currentResponseNum===n.closeAfterResponse)return n.onClose&&(n.onClose(),n.onClose=null),"break";n.currentResponseNum++}()););}}]),e}(),eS="start",eP=function(){function e(t,n,i,r,o,a,s){var u=this;(0,m._)(this,e),this.connId=t,this.repoInfo=n,this.applicationId=i,this.appCheckToken=r,this.authToken=o,this.transportSessionId=a,this.lastSessionId=s,this.bytesSent=0,this.bytesReceived=0,this.everConnected_=!1,this.log_=Q(t),this.stats_=eI(n),this.urlFn=function(e){return u.appCheckToken&&(e.ac=u.appCheckToken),eC(n,em,e)}}return(0,k._)(e,[{key:"open",value:function(e,t){var n=this;this.curSegmentNum=0,this.onDisconnect_=t,this.myPacketOrderer=new eE(e),this.isClosed_=!1,this.connectTimeoutTimer_=setTimeout(function(){n.log_("Timed out trying to connect."),n.onClosed_(),n.connectTimeoutTimer_=null},Math.floor(3e4)),ee(function(){if(!n.isClosed_){n.scriptTagHolder=new eN(function(){for(var e=arguments.length,t=Array(e),i=0;i<e;i++)t[i]=arguments[i];var r=(0,T._)(t,5),o=r[0],a=r[1],s=r[2];if(r[3],r[4],n.incrementIncomingBytes_(t),n.scriptTagHolder)if(n.connectTimeoutTimer_&&(clearTimeout(n.connectTimeoutTimer_),n.connectTimeoutTimer_=null),n.everConnected_=!0,o===eS)n.id=a,n.password=s;else if("close"===o)a?(n.scriptTagHolder.sendNewPolls=!1,n.myPacketOrderer.closeAfter(a,function(){n.onClosed_()})):n.onClosed_();else throw Error("Unrecognized command received: "+o)},function(){for(var e=arguments.length,t=Array(e),i=0;i<e;i++)t[i]=arguments[i];var r=(0,T._)(t,2),o=r[0],a=r[1];n.incrementIncomingBytes_(t),n.myPacketOrderer.handleResponse(o,a)},function(){n.onClosed_()},n.urlFn);var e={};e[eS]="t",e.ser=Math.floor(1e8*Math.random()),n.scriptTagHolder.uniqueCallbackIdentifier&&(e.cb=n.scriptTagHolder.uniqueCallbackIdentifier),e.v="5",n.transportSessionId&&(e.s=n.transportSessionId),n.lastSessionId&&(e.ls=n.lastSessionId),n.applicationId&&(e.p=n.applicationId),n.appCheckToken&&(e.ac=n.appCheckToken),"u">typeof location&&location.hostname&&ey.test(location.hostname)&&(e.r="f");var t=n.urlFn(e);n.log_("Connecting via long-poll to "+t),n.scriptTagHolder.addTag(t,function(){})}})}},{key:"start",value:function(){this.scriptTagHolder.startLongPoll(this.id,this.password),this.addDisconnectPingFrame(this.id,this.password)}},{key:"markConnectionHealthy",value:function(){}},{key:"shutdown_",value:function(){this.isClosed_=!0,this.scriptTagHolder&&(this.scriptTagHolder.close(),this.scriptTagHolder=null),this.myDisconnFrame&&(document.body.removeChild(this.myDisconnFrame),this.myDisconnFrame=null),this.connectTimeoutTimer_&&(clearTimeout(this.connectTimeoutTimer_),this.connectTimeoutTimer_=null)}},{key:"onClosed_",value:function(){!this.isClosed_&&(this.log_("Longpoll is closing itself"),this.shutdown_(),this.onDisconnect_&&(this.onDisconnect_(this.everConnected_),this.onDisconnect_=null))}},{key:"close",value:function(){this.isClosed_||(this.log_("Longpoll is being closed."),this.shutdown_())}},{key:"send",value:function(e){var t=(0,N.stringify)(e);this.bytesSent+=t.length,this.stats_.incrementCounter("bytes_sent",t.length);for(var n=es((0,N.base64Encode)(t),1840),i=0;i<n.length;i++)this.scriptTagHolder.enqueueSegment(this.curSegmentNum,n.length,n[i]),this.curSegmentNum++}},{key:"addDisconnectPingFrame",value:function(e,t){if(!(0,N.isNodeSdk)()){this.myDisconnFrame=document.createElement("iframe");var n={};n.dframe="t",n.id=e,n.pw=t,this.myDisconnFrame.src=this.urlFn(n),this.myDisconnFrame.style.display="none",document.body.appendChild(this.myDisconnFrame)}}},{key:"incrementIncomingBytes_",value:function(e){var t=(0,N.stringify)(e).length;this.bytesReceived+=t,this.stats_.incrementCounter("bytes_received",t)}}],[{key:"forceAllow",value:function(){e.forceAllow_=!0}},{key:"forceDisallow",value:function(){e.forceDisallow_=!0}},{key:"isAvailable",value:function(){return!(0,N.isNodeSdk)()&&(!!e.forceAllow_||!e.forceDisallow_&&"u">typeof document&&null!=document.createElement&&!(("u"<typeof window?"undefined":(0,I._)(window))==="object"&&window.chrome&&window.chrome.extension&&!/^chrome/.test(window.location.href))&&(("u"<typeof Windows?"undefined":(0,I._)(Windows))!=="object"||"object"!==(0,I._)(Windows.UI)))}}]),e}(),eN=function(){function e(t,n,i,r){if((0,m._)(this,e),this.onDisconnect=i,this.urlFn=r,this.outstandingRequests=new Set,this.pendingSegs=[],this.currentSerial=Math.floor(1e8*Math.random()),this.sendNewPolls=!0,(0,N.isNodeSdk)())this.commandCB=t,this.onMessageCB=n;else{this.uniqueCallbackIdentifier=B(),window["pLPCommand"+this.uniqueCallbackIdentifier]=t,window["pRTLPCB"+this.uniqueCallbackIdentifier]=n,this.myIFrame=e.createI
2Frame_();var o="";this.myIFrame.src&&"javascript:"===this.myIFrame.src.substr(0,11)&&(o='<script>document.domain="'+document.domain+'";</script>');var a="<html><body>"+o+"</body></html>";try{this.myIFrame.doc.open(),this.myIFrame.doc.write(a),this.myIFrame.doc.close()}catch(e){K("frame writing exception"),e.stack&&K(e.stack),K(e)}}}return(0,k._)(e,[{key:"close",value:function(){var e=this;this.alive=!1,this.myIFrame&&(this.myIFrame.doc.body.textContent="",setTimeout(function(){null!==e.myIFrame&&(document.body.removeChild(e.myIFrame),e.myIFrame=null)},Math.floor(0)));var t=this.onDisconnect;t&&(this.onDisconnect=null,t())}},{key:"startLongPoll",value:function(e,t){for(this.myID=e,this.myPW=t,this.alive=!0;this.newRequest_(););}},{key:"newRequest_",value:function(){if(!this.alive||!this.sendNewPolls||!(this.outstandingRequests.size<(this.pendingSegs.length>0?2:1)))return!1;this.currentSerial++;var e={};e.id=this.myID,e.pw=this.myPW,e.ser=this.currentSerial;for(var t=this.urlFn(e),n="",i=0;this.pendingSegs.length>0;)if(this.pendingSegs[0].d.length+30+n.length<=1870){var r=this.pendingSegs.shift();n=n+"&seg"+i+"="+r.seg+"&ts"+i+"="+r.ts+"&d"+i+"="+r.d,i++}else break;return t+=n,this.addLongPollTag_(t,this.currentSerial),!0}},{key:"enqueueSegment",value:function(e,t,n){this.pendingSegs.push({seg:e,ts:t,d:n}),this.alive&&this.newRequest_()}},{key:"addLongPollTag_",value:function(e,t){var n=this;this.outstandingRequests.add(t);var i=function(){n.outstandingRequests.delete(t),n.newRequest_()},r=setTimeout(i,Math.floor(25e3));this.addTag(e,function(){clearTimeout(r),i()})}},{key:"addTag",value:function(e,t){var n=this;(0,N.isNodeSdk)()?this.doNodeLongPoll(e,t):setTimeout(function(){try{if(!n.sendNewPolls)return;var i=n.myIFrame.doc.createElement("script");i.type="text/javascript",i.async=!0,i.src=e,i.onload=i.onreadystatechange=function(){var e=i.readyState;e&&"loaded"!==e&&"complete"!==e||(i.onload=i.onreadystatechange=null,i.parentNode&&i.parentNode.removeChild(i),t())},i.onerror=function(){K("Long-poll script failed to load: "+e),n.sendNewPolls=!1,n.close()},n.myIFrame.doc.body.appendChild(i)}catch(e){}},Math.floor(1))}}],[{key:"createIFrame_",value:function(){var e=document.createElement("iframe");if(e.style.display="none",document.body){document.body.appendChild(e);try{e.contentWindow.document||K("No IE domain setting required")}catch(t){e.src="javascript:void((function(){document.open();document.domain='"+document.domain+"';document.close();})())"}}else throw"Document body has not initialized. Wait to initialize Firebase until after the document is ready.";return e.contentDocument?e.doc=e.contentDocument:e.contentWindow?e.doc=e.contentWindow.document:e.document&&(e.doc=e.document),e}}]),e}(),ex=null;"u">typeof MozWebSocket?ex=MozWebSocket:"u">typeof WebSocket&&(ex=WebSocket);var eR=function(){function e(t,n,i,r,o,a,s){(0,m._)(this,e),this.connId=t,this.applicationId=i,this.appCheckToken=r,this.authToken=o,this.keepaliveTimer=null,this.frames=null,this.totalFrames=0,this.bytesSent=0,this.bytesReceived=0,this.log_=Q(this.connId),this.stats_=eI(n),this.connURL=e.connectionURL_(n,a,s,r,i),this.nodeAdmin=n.nodeAdmin}return(0,k._)(e,[{key:"open",value:function(e,t){var n,i=this;this.onDisconnect=t,this.onMessage=e,this.log_("Websocket connecting to "+this.connURL),this.everConnected_=!1,O.set("previous_websocket_failure",!0);try{if((0,N.isNodeSdk)()){var r=this.nodeAdmin?"AdminNode":"Node";n={headers:{"User-Agent":"Firebase/".concat("5","/").concat(A,"/").concat(p.default.platform,"/").concat(r),"X-Firebase-GMPID":this.applicationId||""}},this.authToken&&(n.headers.Authorization="Bearer ".concat(this.authToken)),this.appCheckToken&&(n.headers["X-Firebase-AppCheck"]=this.appCheckToken);var o=p.default.env,a=0===this.connURL.indexOf("wss://")?o.HTTPS_PROXY||o.https_proxy:o.HTTP_PROXY||o.http_proxy;a&&(n.proxy={origin:a})}this.mySock=new ex(this.connURL,[],n)}catch(e){this.log_("Error instantiating WebSocket.");var s=e.message||e.data;s&&this.log_(s),this.onClosed_();return}this.mySock.onopen=function(){i.log_("Websocket connected."),i.everConnected_=!0}
2,this.mySock.onclose=function(){i.log_("Websocket connection was disconnected."),i.mySock=null,i.onClosed_()},this.mySock.onmessage=function(e){i.handleIncomingFrame(e)},this.mySock.onerror=function(e){i.log_("WebSocket error.  Closing connection.");var t=e.message||e.data;t&&i.log_(t),i.onClosed_()}}},{key:"start",value:function(){}},{key:"markConnectionHealthy",value:function(){O.remove("previous_websocket_failure")}},{key:"appendFrame_",value:function(e){if(this.frames.push(e),this.frames.length===this.totalFrames){var t=this.frames.join("");this.frames=null;var n=(0,N.jsonEval)(t);this.onMessage(n)}}},{key:"handleNewFrameCount_",value:function(e){this.totalFrames=e,this.frames=[]}},{key:"extractFrameCount_",value:function(e){if((0,N.assert)(null===this.frames,"We already have a frame buffer"),e.length<=6){var t=Number(e);if(!isNaN(t))return this.handleNewFrameCount_(t),null}return this.handleNewFrameCount_(1),e}},{key:"handleIncomingFrame",value:function(e){if(null!==this.mySock){var t=e.data;if(this.bytesReceived+=t.length,this.stats_.incrementCounter("bytes_received",t.length),this.resetKeepAlive(),null!==this.frames)this.appendFrame_(t);else{var n=this.extractFrameCount_(t);null!==n&&this.appendFrame_(n)}}}},{key:"send",value:function(e){this.resetKeepAlive();var t=(0,N.stringify)(e);this.bytesSent+=t.length,this.stats_.incrementCounter("bytes_sent",t.length);var n=es(t,16384);n.length>1&&this.sendString_(String(n.length));for(var i=0;i<n.length;i++)this.sendString_(n[i])}},{key:"shutdown_",value:function(){this.isClosed_=!0,this.keepaliveTimer&&(clearInterval(this.keepaliveTimer),this.keepaliveTimer=null),this.mySock&&(this.mySock.close(),this.mySock=null)}},{key:"onClosed_",value:function(){!this.isClosed_&&(this.log_("WebSocket is closing itself"),this.shutdown_(),this.onDisconnect&&(this.onDisconnect(this.everConnected_),this.onDisconnect=null))}},{key:"close",value:function(){this.isClosed_||(this.log_("WebSocket is being closed"),this.shutdown_())}},{key:"resetKeepAlive",value:function(){var e=this;clearInterval(this.keepaliveTimer),this.keepaliveTimer=setInterval(function(){e.mySock&&e.sendString_("0"),e.resetKeepAlive()},Math.floor(45e3))}},{key:"sendString_",value:function(e){try{this.mySock.send(e)}catch(e){this.log_("Exception thrown from WebSocket.send():",e.message||e.data,"Closing connection."),setTimeout(this.onClosed_.bind(this),0)}}}],[{key:"connectionURL_",value:function(e,t,n,i,r){var o={};return o.v="5",!(0,N.isNodeSdk)()&&"u">typeof location&&location.hostname&&ey.test(location.hostname)&&(o.r="f"),t&&(o.s=t),n&&(o.ls=n),i&&(o.ac=i),r&&(o.p=r),eC(e,eg,o)}},{key:"forceDisallow",value:function(){e.forceDisallow_=!0}},{key:"isAvailable",value:function(){var t=!1;if("u">typeof navigator&&navigator.userAgent){var n=navigator.userAgent.match(/Android ([0-9]{0,}\.[0-9]{0,})/);n&&n.length>1&&4.4>parseFloat(n[1])&&(t=!0)}return!t&&null!==ex&&!e.forceDisallow_}},{key:"previouslyFailed",value:function(){return O.isInMemoryStorage||!0===O.get("previous_websocket_failure")}}]),e}();eR.responsesRequiredToBeHealthy=2,eR.healthyTimeout=3e4;var eD=function(){function e(t){(0,m._)(this,e),this.initTransports_(t)}return(0,k._)(e,[{key:"initTransports_",value:function(t){var n=eR&&eR.isAvailable(),i=n&&!eR.previouslyFailed();if(t.webSocketOnly&&(n||X("wss:// URL used, but browser isn't known to support websockets.  Trying anyway."),i=!0),i)this.transports_=[eR];else{var r=this.transports_=[],o=!0,a=!1,s=void 0;try{for(var u,l=e.ALL_TRANSPORTS[Symbol.iterator]();!(o=(u=l.next()).done);o=!0){var h=u.value;h&&h.isAvailable()&&r.push(h)}}catch(e){a=!0,s=e}finally{try{o||null==l.return||l.return()}finally{if(a)throw s}}e.globalTransportInitialized_=!0}}},{key:"initialTransport",value:function(){if(this.transports_.length>0)return this.transports_[0];throw Error("No transports available")}},{key:"upgradeTransport",value:function(){return this.transports_.length>1?this.transports_[1]:null}}],[{key:"ALL_TRANSPORTS",get:function(){return[eP,eR]}},{key:"IS_TRANSPORT_INITIALIZED",get:function(){return this.globalTransportInitialized_}}]),e}();eD.globalTransportInitialized_=!1;var eA=function(){function e(t,n,i,r,o,a,s,u,l,h){(0,m._)(this,e),this.id=t,this.repoInfo_=n,this.applicationId_=i,this.appCheckToken_=r,this.authToken_=o,this.onMessage_=a,this.onReady_=s,this.onDisconnect_=u,this.onKill_=l,this.lastSessionId=h,this.connectionCount=0,this.pendingDataMessages=[],this.state_=0,this.log_=Q("c:"+this.id+":"),this.transportManager_=new eD(n),this.log_("Connection created"),this.start_()}return(0,k._)(e,[{key:"start_",value:function(){var e=this,t=this.transportManager_.initialTransport();this.conn_=new t(this.nextTransportId_(),this.repoInfo_,this.applicationId_,this.appCheckToken_,this.authToken_,null,this.lastSessionId),this.primaryResponsesRequired_=t.responsesRequiredToBeHealthy||0;var n=this.connReceiver_(this.conn_),i=this.disconnReceiver_(this.conn_);this.tx_=this.conn_,this.rx_=this.conn_,this.secondaryConn_=null,this.isHealthy_=!1,setTimeout(function(){e.conn_&&e.conn_.open(n,i)},Math.floor(0));var r=t.healthyTimeout||0;r>0&&(this.healthyTimeout_=ef(function(){e.healthyTimeout_=null,e.isHealthy_||(e.conn_&&e.conn_.bytesReceived>
2102400?(e.log_("Connection exceeded healthy timeout but has received "+e.conn_.bytesReceived+" bytes.  Marking connection healthy."),e.isHealthy_=!0,e.conn_.markConnectionHealthy()):e.conn_&&e.conn_.bytesSent>10240?e.log_("Connection exceeded healthy timeout but has sent "+e.conn_.bytesSent+" bytes.  Leaving connection alive."):(e.log_("Closing unhealthy connection after timeout."),e.close()))},Math.floor(r)))}},{key:"nextTransportId_",value:function(){return"c:"+this.id+":"+this.connectionCount++}},{key:"disconnReceiver_",value:function(e){var t=this;return function(n){e===t.conn_?t.onConnectionLost_(n):e===t.secondaryConn_?(t.log_("Secondary connection lost."),t.onSecondaryConnectionLost_()):t.log_("closing an old connection")}}},{key:"connReceiver_",value:function(e){var t=this;return function(n){2!==t.state_&&(e===t.rx_?t.onPrimaryMessageReceived_(n):e===t.secondaryConn_?t.onSecondaryMessageReceived_(n):t.log_("message on old connection"))}}},{key:"sendRequest",value:function(e){this.sendData_({t:"d",d:e})}},{key:"tryCleanupConnection",value: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)}},{key:"onSecondaryControl_",value:function(e){if("t"in e){var t=e.t;"a"===t?this.upgradeIfSecondaryHealthy_():"r"===t?(this.log_("Got a reset on secondary, closing it"),this.secondaryConn_.close(),(this.tx_===this.secondaryConn_||this.rx_===this.secondaryConn_)&&this.close()):"o"===t&&(this.log_("got pong on secondary."),this.secondaryResponsesRequired_--,this.upgradeIfSecondaryHealthy_())}}},{key:"onSecondaryMessageReceived_",value:function(e){var t=eo("t",e),n=eo("d",e);if("c"===t)this.onSecondaryControl_(n);else if("d"===t)this.pendingDataMessages.push(n);else throw Error("Unknown protocol layer: "+t)}},{key:"upgradeIfSecondaryHealthy_",value: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:{}}}))}},{key:"proceedWithUpgrade_",value: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()}},{key:"onPrimaryMessageReceived_",value:function(e){var t=eo("t",e),n=eo("d",e);"c"===t?this.onControl_(n):"d"===t&&this.onDataMessage_(n)}},{key:"onDataMessage_",value:function(e){this.onPrimaryResponse_(),this.onMessage_(e)}},{key:"onPrimaryResponse_",value:function(){!this.isHealthy_&&(this.primaryResponsesRequired_--,this.primaryResponsesRequired_<=0&&(this.log_("Primary connection is healthy."),this.isHealthy_=!0,this.conn_.markConnectionHealthy()))}},{key:"onControl_",value:function(e){var t=eo("t",e);if("d"in e){var n=e.d;if("h"===t){var i=Object.assign({},n);this.repoInfo_.isUsingEmulator&&(i.h=this.repoInfo_.host),this.onHandshake_(i)}else if("n"===t){this.log_("recvd end transmission on primary"),this.rx_=this.secondaryConn_;for(var r=0;r<this.pendingDataMessages.length;++r)this.onDataMessage_(this.pendingDataMessages[r]);this.pendingDataMessages=[],this.tryCleanupConnection()}else"s"===t?this.onConnectionShutdown_(n):"r"===t?this.onReset_(n):"e"===t?G("Server Error: "+n):"o"===t?(this.log_("got pong on primary."),this.onPrimaryResponse_(),this.sendPingOnPrimaryIfNecessary_()):G("Unknown control packet command: "+t)}}},{key:"onHandshake_",value:function(e){var t=e.ts,n=e.v,i=e.h;this.sessionId=e.s,this.repoInfo_.host=i,0===this.state_&&(this.conn_.start(),this.onConnectionEstablished_(this.conn_,t),"5"!==n&&X("Protocol version mismatch detected"),this.tryStartUpgrade_())}},{key:"tryStartUpgrade_",value:function(){var e=this.transportManager_.upgradeTransport();e&&this.startUpgrade_(e)}},{key:"startUpgrade_",value:function(e){var t=this;this.secondaryConn_=new e(this.nextTransportId_(),this.repoInfo_,this.applicationId_,this.appCheckToken_,this.authToken_,this.sessionId),this.secondaryResponsesRequired_=e.responsesRequiredToBeHealthy||0;var n=this.connReceiver_(this.secondaryConn_),i=this.disconnReceiver_(this.secondaryConn_);this.secondaryConn_.open(n,i),ef(function(){t.secondaryConn_&&(t.log_("Timed out trying to upgrade."),t.secondaryConn_.close())},Math.floor(6e4))}},{key:"onReset_",value:function(e){this.log_("Reset packet received.  New host: "+e),this.repoInfo_.host=e,1===this.state_?this.close():(this.closeConnections_(),this.start_())}},{key:"onConnectionEstablished_",value:function(e,t){var n=this;this.log_("Realtime connection established."),this.conn_=e,this.state_=1,this.onReady_&&(this.onReady_(t,this.sessionId),this.onReady_=null),0===this.primaryResponsesRequired_?(this.log_("Primary connection is healthy."),this.isHealthy_=!0):ef(function(){n.sendPingOnPrimaryIfNecessary_()},Math.floor(5e3))}},{key:"sendPingOnPrimaryIfNecessary_",value:function(){this.isHealthy_||1!==this.state_||(this.log_("sending ping on primary."),this.sendData_({t:"c",d:{t:"p",d:{}}}))}},{key:"onSecondaryConnectionLost_",value:function(){var e=this.secondaryConn_;this.secondaryConn_=null,(this.tx_===e||this.rx_===e)&&this.close()}},{key:"onConnectionLost_",value:function(e){this.conn_=null,e||0!==this.state_?1===this.state_&&this.log_("Realtime connection lost."):(this.log_("Realtime connection failed."),this.repoInfo_.isCacheableHost()&&(O.remove("host:"+this.repoInfo_.host),this.repoInfo_.internalHost=this.repoInfo_.host)),this.close()}},{key:"onConnectionShutdown_",value:function(e){this.log_("Connection shutdown command received. Shutting down..."),this.onKill_&&(this.onKill_(e),this.onKill_=null),this.onDisconnect_=null,this.close()}},{key:"sendData_",value:function(e){if(1!==this.state_)throw"Connection is not connected";this.tx_.send(e)}},{key:"close",value:function(){2!==this.state_&&(this.log_("Closing realtime connection."),this.state_=2,this.closeConnections_(),this.onDisconnect_&&(this.onDisconnect_(),this.onDisconnect_=null))}},{key:"closeConnections_",value:function(){this.log_("Shutting down all connections"),this.conn_&&(this.conn_.close(),this.conn_=null),this.secondaryConn_&&(this.secondaryConn_.close(),this.secondaryConn_=null),this.healthyTimeout_&&(clearTimeout(this.healthyTimeout_),this.healthyTimeout_=null)}}]),e}(),eM=function(){function e(){(0,m._)(this,e)}return(0,k._)(e,[{key:"put",value:function(e,t,n,i){}},{key:"merge",value:function(e,t,n,i){}},{key:"refreshAuthToken",value:function(e){}},{key:"refreshAppCheckToken",value:function(e){}},{key:"onDisconnectPut",value:function(e,t,n){}},{key:"onDisconnectMerge",value:function(e,t,n){}},{key:"onDisconnectCancel",value:function(e,t){}},{key:"reportStats",value:function(e){}}]),e}(),eq=function(){function e(t){(0,m._)(this,e),this.allowedEvents_=t,this.listeners_={},(0,N.assert)(Array.isArray(t)&&t.length>0,"Requires a non-empty array")}return(0,k._)(e,[{key:"trigger",value:function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];if(Array.isArray(this.listeners_[e]))for(var r=(0,b._)(this.listeners_[e]),o=0;o<r.length;o++)r[o].callback.apply(r[o].context,n)}},{key:"on",value:function(e,t,n){this.validateEventType_(e),this.listeners_[e]=this.listeners_[e]||[],this.listeners_[e].push({callback:t,context:n});var i=this.getInitialEvent(e);i&&t.apply(n,i)}},{key:"off",value:function(e,t,n){this.validateEventType_(e);for(var i=this.listeners_[e]||[],r=0;r<i.length;r++)if(i[r].callback===t&&(!n||n===i[r].context))return void i.splice(r,1)}},{key:"validateEventType_",value:function(e){(0,N.assert)(this.allowedEvents_.find(function(t){return t===e}),"Unknown event: "+e)}}]),e}(),eF=function(e){function t(){var e;return(0,m._)(this,t),(e=(0,g._)(this,t,[["online"]])).online_=!0,"u">typeof window&&void 0!==window.addEventListener&&!(0,N.isMobileCordova)()&&(window.addEventListener("online",function(){e.online_||(e.online_=!0,e.trigger("online",!0))},!1),window.addEventListener("offline",function(){e.online_&&(e.online_=!1,e.trigger("online",!1))},!1)),e}return(0,C._)(t,e),(0,k._)(t,[{key:"getInitialEvent",value:function(e){return(0,N.assert)("online"===e,"Unknown event type: "+e),[this.online_]}},{key:"currentlyOnline",value:function(){return this.online_}}],[{key:"getInstance",value:function(){return new t}}]),t}(eq),eL=function(){function e(t,n){if((0,m._)(this,e),void 0===n){this.pieces_=t.split("/");for(var i=0,r=0;r<this.pieces_.length;r++)this.pieces_[r].length>0&&(this.pieces_[i]=this.pieces_[r],i++);this.pieces_.length=i,this.pieceNum_=0}else this.pieces_=t,this.pieceNum_=n}return(0,k._)(e,[{key:"toString",value:function(){for(var e="",t=this.pieceNum_;t<this.pieces_.length;t++)""!==this.pieces_[t]&&(e+="/"+this.pieces_[t]);return e||"/"}}]),e}();function eO(){return new eL("")}function eW(e){return e.pieceNum_>=e.pieces_.length?null:e.pieces_[e.pieceNum_]}function eU(e){return e.pieces_.length-e.pieceNum_}function eB(e){var t=e.pieceNum_;return t<e.pieces_.length&&t++,new eL(e.pieces_,t)}function ej(e){return e.pieceNum_<e.pieces_.length?e.pieces_[e.pieces_.length-1]:null}function eV(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0;return e.pieces_.slice(e.pieceNum_+t)}function eH(e){if(e.pieceNum_>=e.pieces_.length)return null;for(var t=[],n=e.pieceNum_;n<e.pieces_.length-1;n++)t.push(e.pieces_[n]);return new eL(t,0)}function ez(e,t){for(var n=[],i=e.pieceNum_;i<e.pieces_.length;i++)n.push(e.pieces_[i]);if((0,w._)(t,eL))for(var r=t.pieceNum_;r<t.pieces_.length;r++)n.push(t.pieces_[r]);else for(var o=t.split("/"),a=0;a<o.length;a++)o[a].length>0&&n.push(o[a]);return new eL(n,0)}function eY(e){return e.pieceNum_>=e.pieces_.length}function eK(e,t){var n=eW(e),i=eW(t);if(null===n)return t;if(n===i)return eK(eB(e),eB(t));
2throw Error("INTERNAL ERROR: innerPath ("+t+") is not within outerPath ("+e+")")}function eQ(e,t){for(var n=eV(e,0),i=eV(t,0),r=0;r<n.length&&r<i.length;r++){var o=ei(n[r],i[r]);if(0!==o)return o}return n.length===i.length?0:n.length<i.length?-1:1}function eG(e,t){if(eU(e)!==eU(t))return!1;for(var n=e.pieceNum_,i=t.pieceNum_;n<=e.pieces_.length;n++,i++)if(e.pieces_[n]!==t.pieces_[i])return!1;return!0}function e$(e,t){var n=e.pieceNum_,i=t.pieceNum_;if(eU(e)>eU(t))return!1;for(;n<e.pieces_.length;){if(e.pieces_[n]!==t.pieces_[i])return!1;++n,++i}return!0}var eX=function e(t,n){(0,m._)(this,e),this.errorPrefix_=n,this.parts_=eV(t,0),this.byteLength_=Math.max(1,this.parts_.length);for(var i=0;i<this.parts_.length;i++)this.byteLength_+=(0,N.stringLength)(this.parts_[i]);eJ(this)};function eJ(e){if(e.byteLength_>768)throw Error(e.errorPrefix_+"has a key path longer than 768 bytes ("+e.byteLength_+").");if(e.parts_.length>32)throw Error(e.errorPrefix_+"path specified exceeds the maximum depth that can be written (32) or object contains a cycle "+eZ(e))}function eZ(e){return 0===e.parts_.length?"":"in property '"+e.parts_.join(".")+"'"}var e0=function(e){function t(){var e,n,i;return(0,m._)(this,t),e=(0,g._)(this,t,[["visible"]]),"u">typeof document&&void 0!==document.addEventListener&&(void 0!==document.hidden?(i="visibilitychange",n="hidden"):void 0!==document.mozHidden?(i="mozvisibilitychange",n="mozHidden"):void 0!==document.msHidden?(i="msvisibilitychange",n="msHidden"):void 0!==document.webkitHidden&&(i="webkitvisibilitychange",n="webkitHidden")),e.visible_=!0,i&&document.addEventListener(i,function(){var t=!document[n];t!==e.visible_&&(e.visible_=t,e.trigger("visible",t))},!1),e}return(0,C._)(t,e),(0,k._)(t,[{key:"getInitialEvent",value:function(e){return(0,N.assert)("visible"===e,"Unknown event type: "+e),[this.visible_]}}],[{key:"getInstance",value:function(){return new t}}]),t}(eq),e1=function(e){function t(e,n,i,r,o,a,s,u){var l;if((0,m._)(this,t),(l=(0,g._)(this,t)).repoInfo_=e,l.applicationId_=n,l.onDataUpdate_=i,l.onConnectStatus_=r,l.onServerInfoUpdate_=o,l.authTokenProvider_=a,l.appCheckTokenProvider_=s,l.authOverride_=u,l.id=t.nextPersistentConnectionId_++,l.log_=Q("p:"+l.id+":"),l.interruptReasons_={},l.listens=new Map,l.outstandingPuts_=[],l.outstandingGets_=[],l.outstandingPutCount_=0,l.outstandingGetCount_=0,l.onDisconnectRequestQueue_=[],l.connected_=!1,l.reconnectDelay_=1e3,l.maxReconnectDelay_=3e5,l.securityDebugCallback_=null,l.lastSessionId=null,l.establishConnectionTimer_=null,l.visible_=!1,l.requestCBHash_={},l.requestNumber_=0,l.realtime_=null,l.authToken_=null,l.appCheckToken_=null,l.forceTokenRefresh_=!1,l.invalidAuthTokenCount_=0,l.invalidAppCheckTokenCount_=0,l.firstConnection_=!0,l.lastConnectionAttemptTime_=null,l.lastConnectionEstablishedTime_=null,u&&!(0,N.isNodeSdk)())throw Error("Auth override specified in options, but not supported on non Node.js platforms");return e0.getInstance().on("visible",l.onVisible_,l),-1===e.host.indexOf("fblocal")&&eF.getInstance().on("online",l.onOnline_,l),l}return(0,C._)(t,e),(0,k._)(t,[{key:"sendRequest",value:function(e,t,n){var i=++this.requestNumber_,r={r:i,a:e,b:t};this.log_((0,N.stringify)(r)),(0,N.assert)(this.connected_,"sendRequest call when we're not connected not allowed."),this.realtime_.sendRequest(r),n&&(this.requestCBHash_[i]=n)}},{key:"get",value:function(e){this.initConnection_();var t=new N.Deferred,n={p:e._path.toString(),q:e._queryObject};this.outstandingGets_.push({action:"g",request:n,onComplete:function(e){var n=e.d;"ok"===e.s?t.resolve(n):t.reject(n)}}),this.outstandingGetCount_++;var i=this.outstandingGets_.length-1;return this.connected_&&this.sendGet_(i),t.promise}},{key:"listen",value:function(e,t,n,i){this.initConnection_();var r=e._queryIdentifier,o=e._path.toString();this.log_("Listen called for "+o+" "+r),this.listens.has(o)||this.listens.set(o,new Map),(0,N.assert)(e._queryParams.isDefault()||!e._queryParams.loadsAllData(),"listen() called for non-default but complete query"),(0,N.assert)(!this.listens.get(o).has(r),"listen() called twice for same path/queryId.");var a={onComplete:i,hashFn:t,query:e,tag:n};this.listens.get(o).set(r,a),this.connected_&&this.sendListen_(a)}},{key:"sendGet_",value:function(e){var t=this,n=this.outstandingGets_[e];this.sendRequest("g",n.request,function(i){delete t.outstandingGets_[e],t.outstandingGetCount_--,0===t.outstandingGetCount_&&(t.outstandingGets_=[]),n.onComplete&&n.onComplete(i)})}},{key:"sendListen_",value:function(e){var n=this,i=e.query,r=i._path.toString(),o=i._queryIdentifier;this.log_("Listen on "+r+" for "+o);var a={p:r};e.tag&&(a.q=i._queryObject,a.t=e.tag),a.h=e.hashFn(),this.sendRequest("q",a,function(a){var s=a.d,u=a.s;t.warnOnListenWarnings_(s,i),(n.listens.get(r)&&n.listens.get(r).get(o))===e&&(n.log_("listen response",a),"ok"!==u&&n.removeListen_(r,o),e.onComplete&&e.onComplete(u,s))})}},{key:"refreshAuthToken",value:function(e){this.authToken_=e,this.log_("Auth token refreshed"),this.authToken_?this.tryAuth():this.connected_&&this.sendRequest("unauth",{},function(){}),this.reduceReconnectDelayIfAdminCredential_(e)}},{key:"reduceReconnectDelayIfAdminCredential_",value:function(e){(e&&40===e.length||(0,N.isAdmin)(e))&&(this.log_("Admin auth credential detected.  Reducing max reconnect time."),this.maxReconnectDelay_=3e4)}},{key:"refreshAppCheckToken",value:function(e){this.appCheckToken_=e,this.log_("App check token refreshed"),this.appCheckToken_?this.tryAppCheck():this.connected_&&this.sendRequest("unappeck",{},function(){})}},{key:"tryAuth",value:function(){var e=this;if(this.connected_&&this.authToken_){var t=this.authToken_,n=(0,N.isValidFormat)(t)?"auth":"gauth",i={cred:t};null===this.authOverride_?i.noauth=!0:"object"===(0,I._)(this.authOverride_)&&(i.authvar=this.authOverride_),this.sendRequest(n,i,function(n){var i=n.s,r=n.d||"error";
2e.authToken_===t&&("ok"===i?e.invalidAuthTokenCount_=0:e.onAuthRevoked_(i,r))})}}},{key:"tryAppCheck",value:function(){var e=this;this.connected_&&this.appCheckToken_&&this.sendRequest("appcheck",{token:this.appCheckToken_},function(t){var n=t.s,i=t.d||"error";"ok"===n?e.invalidAppCheckTokenCount_=0:e.onAppCheckRevoked_(n,i)})}},{key:"unlisten",value:function(e,t){var n=e._path.toString(),i=e._queryIdentifier;this.log_("Unlisten called for "+n+" "+i),(0,N.assert)(e._queryParams.isDefault()||!e._queryParams.loadsAllData(),"unlisten() called for non-default but complete query"),this.removeListen_(n,i)&&this.connected_&&this.sendUnlisten_(n,i,e._queryObject,t)}},{key:"sendUnlisten_",value:function(e,t,n,i){this.log_("Unlisten on "+e+" for "+t);var r={p:e};i&&(r.q=n,r.t=i),this.sendRequest("n",r)}},{key:"onDisconnectPut",value:function(e,t,n){this.initConnection_(),this.connected_?this.sendOnDisconnect_("o",e,t,n):this.onDisconnectRequestQueue_.push({pathString:e,action:"o",data:t,onComplete:n})}},{key:"onDisconnectMerge",value:function(e,t,n){this.initConnection_(),this.connected_?this.sendOnDisconnect_("om",e,t,n):this.onDisconnectRequestQueue_.push({pathString:e,action:"om",data:t,onComplete:n})}},{key:"onDisconnectCancel",value:function(e,t){this.initConnection_(),this.connected_?this.sendOnDisconnect_("oc",e,null,t):this.onDisconnectRequestQueue_.push({pathString:e,action:"oc",data:null,onComplete:t})}},{key:"sendOnDisconnect_",value:function(e,t,n,i){var r={p:t,d:n};this.log_("onDisconnect "+e,r),this.sendRequest(e,r,function(e){i&&setTimeout(function(){i(e.s,e.d)},Math.floor(0))})}},{key:"put",value:function(e,t,n,i){this.putInternal("p",e,t,n,i)}},{key:"merge",value:function(e,t,n,i){this.putInternal("m",e,t,n,i)}},{key:"putInternal",value:function(e,t,n,i,r){this.initConnection_();var o={p:t,d:n};void 0!==r&&(o.h=r),this.outstandingPuts_.push({action:e,request:o,onComplete:i}),this.outstandingPutCount_++;var a=this.outstandingPuts_.length-1;this.connected_?this.sendPut_(a):this.log_("Buffering put: "+t)}},{key:"sendPut_",value:function(e){var t=this,n=this.outstandingPuts_[e].action,i=this.outstandingPuts_[e].request,r=this.outstandingPuts_[e].onComplete;this.outstandingPuts_[e].queued=this.connected_,this.sendRequest(n,i,function(i){t.log_(n+" response",i),delete t.outstandingPuts_[e],t.outstandingPutCount_--,0===t.outstandingPutCount_&&(t.outstandingPuts_=[]),r&&r(i.s,i.d)})}},{key:"reportStats",value:function(e){var t=this;if(this.connected_){var n={c:e};this.log_("reportStats",n),this.sendRequest("s",n,function(e){if("ok"!==e.s){var n=e.d;t.log_("reportStats","Error sending stats: "+n)}})}}},{key:"onDataMessage_",value:function(e){if("r"in e){this.log_("from server: "+(0,N.stringify)(e));var t=e.r,n=this.requestCBHash_[t];n&&(delete this.requestCBHash_[t],n(e.b))}else if("error"in e)throw"A server-side error has occurred: "+e.error;else"a"in e&&this.onDataPush_(e.a,e.b)}},{key:"onDataPush_",value:function(e,t){this.log_("handleServerMessage",e,t),"d"===e?this.onDataUpdate_(t.p,t.d,!1,t.t):"m"===e?this.onDataUpdate_(t.p,t.d,!0,t.t):"c"===e?this.onListenRevoked_(t.p,t.q):"ac"===e?this.onAuthRevoked_(t.s,t.d):"apc"===e?this.onAppCheckRevoked_(t.s,t.d):"sd"===e?this.onSecurityDebugPacket_(t):G("Unrecognized action received from server: "+(0,N.stringify)(e)+"\nAre you using the latest client?")}},{key:"onReady_",value:function(e,t){this.log_("connection ready"),this.connected_=!0,this.lastConnectionEstablishedTime_=new Date().getTime(),this.handleTimestamp_(e),this.lastSessionId=t,this.firstConnection_&&this.sendConnectStats_(),this.restoreState_(),this.firstConnection_=!1,this.onConnectStatus_(!0)}},{key:"scheduleConnect_",value:function(e){var t=this;(0,N.assert)(!this.realtime_,"Scheduling a connect when we're already connected/ing?"),this.establishConnectionTimer_&&clearTimeout(this.establishConnectionTimer_),this.establishConnectionTimer_=setTimeout(function(){t.establishConnectionTimer_=null,t.establishConnection_()},Math.floor(e))}},{key:"initConnection_",value:function(){!this.realtime_&&this.firstConnection_&&this.scheduleConnect_(0)}},{key:"onVisible_",value:function(e){e&&!this.visible_&&this.reconnectDelay_===this.maxReconnectDelay_&&(this.log_("Window became visible.  Reducing delay."),this.reconnectDelay_=1e3,this.realtime_||this.scheduleConnect_(0)),this.visible_=e}},{key:"onOnline_",value:function(e){e?(this.log_("Browser went online."),this.reconnectDelay_=1e3,this.realtime_||this.scheduleConnect_(0)):(this.log_("Browser went offline.  Killing connection."),this.realtime_&&this.realtime_.close())}},{key:"onRealtimeDisconnect_",value:function(){if(this.log_("data client disconnected"),this.connected_=!1,this.realtime_=null,this.cancelSentTransactions_(),this.requestCBHash_={},this.shouldReconnect_()){this.visible_?this.lastConnectionEstablishedTime_&&(new Date().getTime()-this.lastConnectionEstablishedTime_>3e4&&(this.reconnectDelay_=1e3),this.lastConnectionEstablishedTime_=null):(this.log_("Window isn't visible.  Delaying reconnect."),this.reconnectDelay_=this.maxReconnectDelay_,this.lastConnectionAttemptTime_=new Date().getTime());var e=new Date().getTime()-this.lastConnectionAttemptTime_,t=Math.max(0,this.reconnectDelay_-e);
2t=Math.random()*t,this.log_("Trying to reconnect in "+t+"ms"),this.scheduleConnect_(t),this.reconnectDelay_=Math.min(this.maxReconnectDelay_,1.3*this.reconnectDelay_)}this.onConnectStatus_(!1)}},{key:"establishConnection_",value:function(){return(0,y._)(function(){var e,n,i,r,o,a,s,u,l,h,c,d,f,_,v;return(0,E._)(this,function(p){switch(p.label){case 0:if(e=this,!this.shouldReconnect_())return[3,4];this.log_("Making a connection attempt"),this.lastConnectionAttemptTime_=new Date().getTime(),this.lastConnectionEstablishedTime_=null,n=this.onDataMessage_.bind(this),i=this.onReady_.bind(this),r=this.onRealtimeDisconnect_.bind(this),o=this.id+":"+t.nextConnectionId_++,a=this.lastSessionId,s=!1,u=null,l=function(){u?u.close():(s=!0,r())},h=function(e){(0,N.assert)(u,"sendRequest call when we're not connected not allowed."),u.sendRequest(e)},this.realtime_={close:l,sendRequest:h},c=this.forceTokenRefresh_,this.forceTokenRefresh_=!1,p.label=1;case 1:return p.trys.push([1,3,,4]),[4,Promise.all([this.authTokenProvider_.getToken(c),this.appCheckTokenProvider_.getToken(c)])];case 2:return f=(d=T._.apply(void 0,[p.sent(),2]))[0],_=d[1],s?K("getToken() completed but was canceled"):(K("getToken() completed. Creating connection."),this.authToken_=f&&f.accessToken,this.appCheckToken_=_&&_.token,u=new eA(o,this.repoInfo_,this.applicationId_,this.appCheckToken_,this.authToken_,n,i,r,function(t){X(t+" ("+e.repoInfo_.toString()+")"),e.interrupt("server_kill")},a)),[3,4];case 3:return v=p.sent(),this.log_("Failed to get token: "+v),s||(this.repoInfo_.nodeAdmin&&X(v),l()),[3,4];case 4:return[2]}})}).call(this)}},{key:"interrupt",value:function(e){K("Interrupting connection for reason: "+e),this.interruptReasons_[e]=!0,this.realtime_?this.realtime_.close():(this.establishConnectionTimer_&&(clearTimeout(this.establishConnectionTimer_),this.establishConnectionTimer_=null),this.connected_&&this.onRealtimeDisconnect_())}},{key:"resume",value:function(e){K("Resuming connection for reason: "+e),delete this.interruptReasons_[e],(0,N.isEmpty)(this.interruptReasons_)&&(this.reconnectDelay_=1e3,this.realtime_||this.scheduleConnect_(0))}},{key:"handleTimestamp_",value:function(e){var t=e-new Date().getTime();this.onServerInfoUpdate_({serverTimeOffset:t})}},{key:"cancelSentTransactions_",value:function(){for(var e=0;e<this.outstandingPuts_.length;e++){var t=this.outstandingPuts_[e];t&&"h"in t.request&&t.queued&&(t.onComplete&&t.onComplete("disconnect"),delete this.outstandingPuts_[e],this.outstandingPutCount_--)}0===this.outstandingPutCount_&&(this.outstandingPuts_=[])}},{key:"onListenRevoked_",value:function(e,t){var n=t?t.map(function(e){return ea(e)}).join("$"):"default",i=this.removeListen_(e,n);i&&i.onComplete&&i.onComplete("permission_denied")}},{key:"removeListen_",value:function(e,t){var n,i=new eL(e).toString();if(this.listens.has(i)){var r=this.listens.get(i);n=r.get(t),r.delete(t),0===r.size&&this.listens.delete(i)}else n=void 0;return n}},{key:"onAuthRevoked_",value:function(e,t){K("Auth token revoked: "+e+"/"+t),this.authToken_=null,this.forceTokenRefresh_=!0,this.realtime_.close(),("invalid_token"===e||"permission_denied"===e)&&(this.invalidAuthTokenCount_++,this.invalidAuthTokenCount_>=3&&(this.reconnectDelay_=3e4,this.authTokenProvider_.notifyForInvalidToken()))}},{key:"onAppCheckRevoked_",value:function(e,t){K("App check token revoked: "+e+"/"+t),this.appCheckToken_=null,this.forceTokenRefresh_=!0,("invalid_token"===e||"permission_denied"===e)&&(this.invalidAppCheckTokenCount_++,this.invalidAppCheckTokenCount_>=3&&this.appCheckTokenProvider_.notifyForInvalidToken())}},{key:"onSecurityDebugPacket_",value:function(e){this.securityDebugCallback_?this.securityDebugCallback_(e):"msg"in e&&console.log("FIREBASE: "+e.msg.replace("\n","\nFIREBASE: "))}},{key:"restoreState_",value:function(){this.tryAuth(),this.tryAppCheck();var e=!0,t=!1,n=void 0;try{for(var i,r=this.listens.values()[Symbol.iterator]();!(e=(i=r.next()).done);e=!0){var o=i.value,a=!0,s=!1,u=void 0;try{for(var l,h=o.values()[Symbol.iterator]();!(a=(l=h.next()).done);a=!0){var c=l.value;this.sendListen_(c)}}catch(e){s=!0,u=e}finally{try{a||null==h.return||h.return()}finally{if(s)throw u}}}}catch(e){t=!0,n=e}finally{try{e||null==r.return||r.return()}finally{if(t)throw n}}for(var d=0;d<this.outstandingPuts_.length;d++)this.outstandingPuts_[d]&&this.sendPut_(d);for(;this.onDisconnectRequestQueue_.length;){var f=this.onDisconnectRequestQueue_.shift();this.sendOnDisconnect_(f.action,f.pathString,f.data,f.onComplete)}for(var _=0;_<this.outstandingGets_.length;_++)this.outstandingGets_[_]&&this.sendGet_(_)}},{key:"sendConnectStats_",value:function(){var e={},t="js";(0,N.isNodeSdk)()&&(t=this.repoInfo_.nodeAdmin?"admin_node":"node"),e["sdk."+t+"."+A.replace(/\./g,"-")]=1,(0,N.isMobileCordova)()?e["framework.cordova"]=1:(0,N.isReactNative)()&&(e["framework.reactnative"]=1),this.reportStats(e)}},{key:"shouldReconnect_",value:function(){var e=eF.getInstance().currentlyOnline();return(0,N.isEmpty)(this.interruptReasons_)&&e}}],[{key:"warnOnListenWarnings_",value:function(e,t){if(e&&(void 0===e?"undefined":(0,I._)(e))==="object"&&(0,N.contains)(e,"w")){var n=(0,N.safeGet)(e,"w");if(Array.isArray(n)&&~n.indexOf("no_index")){var i='".indexOn": "'+t._queryParams.getIndex().toString()+'"',r=t._path.toString();X("Using an unspecified index. Your data will be downloaded and "+"filtered on the client. Consider adding ".concat(i," at ")+"".concat(r," to your security rules for better performance."))}}}}]),t}(eM);e1.nextPersistentConnectionId_=0,e1.nextConnectionId_=0;var e2=function(){function e(t,n){(0,m._)(this,e),this.name=t,this.node=n}return(0,k._)(e,null,[{key:"Wrap",value:function(t,n){return new e(t,n)}}]),e}(),e4=function(){function e(){(0,m._)(this,e)}return(0,k._)(e,[{key:"getCompare",value:function(){return this.compare.bind(this)}},{key:"indexedValueChanged",value:function(e,t){var n=new e2(et,e),i=new e2(et,t);return 0!==this.compare(n,i)}},{key:"minPost",value:function(){return e2.MIN}}]),e}(),e3=function(e){function t(){return(0,m._)(this,t),(0,g._)(this,t,arguments)}
2return(0,C._)(t,e),(0,k._)(t,[{key:"compare",value:function(e,t){return ei(e.name,t.name)}},{key:"isDefinedOn",value:function(e){throw(0,N.assertionError)("KeyIndex.isDefinedOn not expected to be called.")}},{key:"indexedValueChanged",value:function(e,t){return!1}},{key:"minPost",value:function(){return e2.MIN}},{key:"maxPost",value:function(){return new e2(en,o)}},{key:"makePost",value:function(e,t){return(0,N.assert)("string"==typeof e,"KeyIndex indexValue must always be a string."),new e2(e,o)}},{key:"toString",value:function(){return".key"}}],[{key:"__EMPTY_NODE",get:function(){return o},set:function(e){o=e}}]),t}(e4),e5=new e3,e6=function(){function e(t,n,i,r){var o=arguments.length>4&&void 0!==arguments[4]?arguments[4]:null;(0,m._)(this,e),this.isReverse_=r,this.resultGenerator_=o,this.nodeStack_=[];for(var a=1;!t.isEmpty();)if(a=n?i(t.key,n):1,r&&(a*=-1),a<0)t=this.isReverse_?t.left:t.right;else if(0===a){this.nodeStack_.push(t);break}else this.nodeStack_.push(t),t=this.isReverse_?t.right:t.left}return(0,k._)(e,[{key:"getNext",value:function(){if(0===this.nodeStack_.length)return null;var e,t=this.nodeStack_.pop();if(e=this.resultGenerator_?this.resultGenerator_(t.key,t.value):{key:t.key,value:t.value},this.isReverse_)for(t=t.left;!t.isEmpty();)this.nodeStack_.push(t),t=t.right;else for(t=t.right;!t.isEmpty();)this.nodeStack_.push(t),t=t.left;return e}},{key:"hasNext",value:function(){return this.nodeStack_.length>0}},{key:"peek",value:function(){if(0===this.nodeStack_.length)return null;var e=this.nodeStack_[this.nodeStack_.length-1];return this.resultGenerator_?this.resultGenerator_(e.key,e.value):{key:e.key,value:e.value}}}]),e}(),e8=function(){function e(t,n,i,r,o){(0,m._)(this,e),this.key=t,this.value=n,this.color=null!=i?i:e.RED,this.left=null!=r?r:e9.EMPTY_NODE,this.right=null!=o?o:e9.EMPTY_NODE}return(0,k._)(e,[{key:"copy",value:function(t,n,i,r,o){return new e(null!=t?t:this.key,null!=n?n:this.value,null!=i?i:this.color,null!=r?r:this.left,null!=o?o:this.right)}},{key:"count",value:function(){return this.left.count()+1+this.right.count()}},{key:"isEmpty",value:function(){return!1}},{key:"inorderTraversal",value:function(e){return this.left.inorderTraversal(e)||!!e(this.key,this.value)||this.right.inorderTraversal(e)}},{key:"reverseTraversal",value:function(e){return this.right.reverseTraversal(e)||e(this.key,this.value)||this.left.reverseTraversal(e)}},{key:"min_",value:function(){return this.left.isEmpty()?this:this.left.min_()}},{key:"minKey",value:function(){return this.min_().key}},{key:"maxKey",value:function(){return this.right.isEmpty()?this.key:this.right.maxKey()}},{key:"insert",value:function(e,t,n){var i=this,r=n(e,i.key);return(i=r<0?i.copy(null,null,null,i.left.insert(e,t,n),null):0===r?i.copy(null,t,null,null,null):i.copy(null,null,null,null,i.right.insert(e,t,n))).fixUp_()}},{key:"removeMin_",value:function(){if(this.left.isEmpty())return e9.EMPTY_NODE;var e=this;return e.left.isRed_()||e.left.left.isRed_()||(e=e.moveRedLeft_()),(e=e.copy(null,null,null,e.left.removeMin_(),null)).fixUp_()}},{key:"remove",value:function(e,t){var n,i;if(n=this,0>t(e,n.key))n.left.isEmpty()||n.left.isRed_()||n.left.left.isRed_()||(n=n.moveRedLeft_()),n=n.copy(null,null,null,n.left.remove(e,t),null);else{if(n.left.isRed_()&&(n=n.rotateRight_()),n.right.isEmpty()||n.right.isRed_()||n.right.left.isRed_()||(n=n.moveRedRight_()),0===t(e,n.key))if(n.right.isEmpty())return e9.EMPTY_NODE;else i=n.right.min_(),n=n.copy(i.key,i.value,null,null,n.right.removeMin_());n=n.copy(null,null,null,null,n.right.remove(e,t))}return n.fixUp_()}},{key:"isRed_",value:function(){return this.color}},{key:"fixUp_",value:function(){var e=this;return e.right.isRed_()&&!e.left.isRed_()&&(e=e.rotateLeft_()),e.left.isRed_()&&e.left.left.isRed_()&&(e=e.rotateRight_()),e.left.isRed_()&&e.right.isRed_()&&(e=e.colorFlip_()),e}},{key:"moveRedLeft_",value:function(){var e=this.colorFlip_();return e.right.left.isRed_()&&(e=(e=(e=e.copy(null,null,null,null,e.right.rotateRight_())).rotateLeft_()).colorFlip_()),e}},{key:"moveRedRight_",value:function(){var e=this.colorFlip_();return e.left.left.isRed_()&&(e=(e=e.rotateRight_()).colorFlip_()),e}},{key:"rotateLeft_",value:function(){var t=this.copy(null,null,e.RED,null,this.right.left);return this.right.copy(null,null,this.color,t,null)}},{key:"rotateRight_",value:function(){var t=this.copy(null,null,e.RED,this.left.right,null);return this.left.copy(null,null,this.color,null,t)}},{key:"colorFlip_",value:function(){var e=this.left.copy(null,null,!this.left.color,null,null),t=this.right.copy(null,null,!this.right.color,null,null);return this.copy(null,null,!this.color,e,t)}},{key:"checkMaxDepth_",value:function(){return Math.pow(2,this.check_())<=this.count()+1}},{key:"check_",value:function(){if(this.isRed_()&&this.left.isRed_()
2)throw Error("Red node has red child("+this.key+","+this.value+")");if(this.right.isRed_())throw Error("Right child of ("+this.key+","+this.value+") is red");var e=this.left.check_();if(e===this.right.check_())return e+ +!this.isRed_();throw Error("Black depths differ")}}]),e}();e8.RED=!0,e8.BLACK=!1;var e7=function(){function e(){(0,m._)(this,e)}return(0,k._)(e,[{key:"copy",value:function(e,t,n,i,r){return this}},{key:"insert",value:function(e,t,n){return new e8(e,t,null)}},{key:"remove",value:function(e,t){return this}},{key:"count",value:function(){return 0}},{key:"isEmpty",value:function(){return!0}},{key:"inorderTraversal",value:function(e){return!1}},{key:"reverseTraversal",value:function(e){return!1}},{key:"minKey",value:function(){return null}},{key:"maxKey",value:function(){return null}},{key:"check_",value:function(){return 0}},{key:"isRed_",value:function(){return!1}}]),e}(),e9=function(){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e.EMPTY_NODE;(0,m._)(this,e),this.comparator_=t,this.root_=n}return(0,k._)(e,[{key:"insert",value:function(t,n){return new e(this.comparator_,this.root_.insert(t,n,this.comparator_).copy(null,null,e8.BLACK,null,null))}},{key:"remove",value:function(t){return new e(this.comparator_,this.root_.remove(t,this.comparator_).copy(null,null,e8.BLACK,null,null))}},{key:"get",value:function(e){for(var t,n=this.root_;!n.isEmpty();){if(0===(t=this.comparator_(e,n.key)))return n.value;t<0?n=n.left:t>0&&(n=n.right)}return null}},{key:"getPredecessorKey",value:function(e){for(var t,n=this.root_,i=null;!n.isEmpty();){if(0===(t=this.comparator_(e,n.key)))if(n.left.isEmpty())if(i)return i.key;else return null;else{for(n=n.left;!n.right.isEmpty();)n=n.right;return n.key}t<0?n=n.left:t>0&&(i=n,n=n.right)}throw Error("Attempted to find predecessor key for a nonexistent key.  What gives?")}},{key:"isEmpty",value:function(){return this.root_.isEmpty()}},{key:"count",value:function(){return this.root_.count()}},{key:"minKey",value:function(){return this.root_.minKey()}},{key:"maxKey",value:function(){return this.root_.maxKey()}},{key:"inorderTraversal",value:function(e){return this.root_.inorderTraversal(e)}},{key:"reverseTraversal",value:function(e){return this.root_.reverseTraversal(e)}},{key:"getIterator",value:function(e){return new e6(this.root_,null,this.comparator_,!1,e)}},{key:"getIteratorFrom",value:function(e,t){return new e6(this.root_,e,this.comparator_,!1,t)}},{key:"getReverseIteratorFrom",value:function(e,t){return new e6(this.root_,e,this.comparator_,!0,t)}},{key:"getReverseIterator",value:function(e){return new e6(this.root_,null,this.comparator_,!0,e)}}]),e}();function te(e,t){return ei(e.name,t.name)}function tt(e,t){return ei(e,t)}e9.EMPTY_NODE=new e7;var tn=function(e){return"number"==typeof e?"number:"+el(e):"string:"+e},ti=function(e){if(e.isLeafNode()){var t=e.val();(0,N.assert)("string"==typeof t||"number"==typeof t||(void 0===t?"undefined":(0,I._)(t))==="object"&&(0,N.contains)(t,".sv"),"Priority must be a string or number.")}else(0,N.assert)(e===a||e.isEmpty(),"priority of unexpected type.");(0,N.assert)(e===a||e.getPriority().isEmpty(),"Priority nodes can't have a priority of their own.")},tr=function(){function e(t){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e.__childrenNodeConstructor.EMPTY_NODE;(0,m._)(this,e),this.value_=t,this.priorityNode_=n,this.lazyHash_=null,(0,N.assert)(void 0!==this.value_&&null!==this.value_,"LeafNode shouldn't be created with null/undefined value."),ti(this.priorityNode_)}return(0,k._)(e,[{key:"isLeafNode",value:function(){return!0}},{key:"getPriority",value:function(){return this.priorityNode_}},{key:"updatePriority",value:function(t){return new e(this.value_,t)}},{key:"getImmediateChild",value:function(t){return".priority"===t?this.priorityNode_:e.__childrenNodeConstructor.EMPTY_NODE}},{key:"getChild",value:function(t){return eY(t)?this:".priority"===eW(t)?this.priorityNode_:e.__childrenNodeConstructor.EMPTY_NODE}},{key:"hasChild",value:function(){return!1}},{key:"getPredecessorChildName",value:function(e,t){return null}},{key:"updateImmediateChild",value:function(t,n){return".priority"===t?this.updatePriority(n):n.isEmpty()&&".priority"!==t?this:e.__childrenNodeConstructor.EMPTY_NODE.updateImmediateChild(t,n).updatePriority(this.priorityNode_)}},{key:"updateChild",value:function(t,n){var i=eW(t);return null===i?n:n.isEmpty()&&".priority"!==i?this:((0,N.assert)(".priority"!==i||1===eU(t),".priority must be the last token in a path"),this.updateImmediateChild(i,e.__childrenNodeConstructor.EMPTY_NODE.updateChild(eB(t),n)))}},{key:"isEmpty",value:function(){return!1}},{key:"numChildren",value:function(){return 0}}
2,{key:"forEachChild",value:function(e,t){return!1}},{key:"val",value:function(e){return e&&!this.getPriority().isEmpty()?{".value":this.getValue(),".priority":this.getPriority().val()}:this.getValue()}},{key:"hash",value:function(){if(null===this.lazyHash_){var e="";this.priorityNode_.isEmpty()||(e+="priority:"+tn(this.priorityNode_.val())+":");var t=(0,I._)(this.value_);e+=t+":","number"===t?e+=el(this.value_):e+=this.value_,this.lazyHash_=j(e)}return this.lazyHash_}},{key:"getValue",value:function(){return this.value_}},{key:"compareTo",value:function(t){return t===e.__childrenNodeConstructor.EMPTY_NODE?1:(0,w._)(t,e.__childrenNodeConstructor)?-1:((0,N.assert)(t.isLeafNode(),"Unknown node type"),this.compareToLeafNode_(t))}},{key:"compareToLeafNode_",value:function(t){var n=(0,I._)(t.value_),i=(0,I._)(this.value_),r=e.VALUE_TYPE_ORDER.indexOf(n),o=e.VALUE_TYPE_ORDER.indexOf(i);return((0,N.assert)(r>=0,"Unknown leaf type: "+n),(0,N.assert)(o>=0,"Unknown leaf type: "+i),r!==o)?o-r:"object"===i?0:this.value_<t.value_?-1:1*(this.value_!==t.value_)}},{key:"withIndex",value:function(){return this}},{key:"isIndexed",value:function(){return!0}},{key:"equals",value:function(e){return e===this||!!e.isLeafNode()&&this.value_===e.value_&&this.priorityNode_.equals(e.priorityNode_)}}],[{key:"__childrenNodeConstructor",get:function(){return s},set:function(e){s=e}}]),e}();tr.VALUE_TYPE_ORDER=["object","boolean","number","string"];var to=new(function(e){function t(){return(0,m._)(this,t),(0,g._)(this,t,arguments)}
2return(0,C._)(t,e),(0,k._)(t,[{key:"compare",value:function(e,t){var n=e.node.getPriority(),i=t.node.getPriority(),r=n.compareTo(i);return 0===r?ei(e.name,t.name):r}},{key:"isDefinedOn",value:function(e){return!e.getPriority().isEmpty()}},{key:"indexedValueChanged",value:function(e,t){return!e.getPriority().equals(t.getPriority())}},{key:"minPost",value:function(){return e2.MIN}},{key:"maxPost",value:function(){return new e2(en,new tr("[PRIORITY-POST]",l))}},{key:"makePost",value:function(e,t){return new e2(t,new tr("[PRIORITY-POST]",u(e)))}},{key:"toString",value:function(){return".priority"}}]),t}(e4)),ta=Math.log(2),ts=function(){function e(t){(0,m._)(this,e),this.count=parseInt(Math.log(t+1)/ta,10),this.current_=this.count-1;var n=parseInt(Array(this.count+1).join("1"),2);this.bits_=t+1&n}return(0,k._)(e,[{key:"nextBitIsOne",value:function(){var e=!(this.bits_&1<<this.current_);return this.current_--,e}}]),e}(),tu=function(e,t,n,i){e.sort(t);var r=function(t,i){var o,a=i-t;if(0===a)return null;if(1===a)return o=e[t],new e8(n?n(o):o,o.node,e8.BLACK,null,null);var s=parseInt(a/2,10)+t,u=r(t,s),l=r(s+1,i);return o=e[s],new e8(n?n(o):o,o.node,e8.BLACK,u,l)};return new e9(i||t,function(t){for(var i=null,o=null,a=e.length,s=function(t,i){var o=a-t,s=a;a-=t;var l=r(o+1,s),h=e[o];u(new e8(n?n(h):h,h.node,i,null,l))},u=function(e){i?i.left=e:o=e,i=e},l=0;l<t.count;++l){var h=t.nextBitIsOne(),c=Math.pow(2,t.count-(l+1));h?s(c,e8.BLACK):(s(c,e8.BLACK),s(c,e8.RED))}return o}(new ts(e.length)))},tl={},th=function(){function e(t,n){(0,m._)(this,e),this.indexes_=t,this.indexSet_=n}return(0,k._)(e,[{key:"get",value:function(e){var t=(0,N.safeGet)(this.indexes_,e);if(!t)throw Error("No index defined for "+e);return(0,w._)(t,e9)?t:null}},{key:"hasIndex",value:function(e){return(0,N.contains)(this.indexSet_,e.toString())}},{key:"addIndex",value:function(t,n){(0,N.assert)(t!==e5,"KeyIndex always exists and isn't meant to be added to the IndexMap.");for(var i,r=[],o=!1,a=n.getIterator(e2.Wrap),s=a.getNext();s;)o=o||t.isDefinedOn(s.node),r.push(s),s=a.getNext();i=o?tu(r,t.getCompare()):tl;var u=t.toString(),l=Object.assign({},this.indexSet_);l[u]=t;var h=Object.assign({},this.indexes_);return h[u]=i,new e(h,l)}},{key:"addToIndexes",value:function(t,n){var i=this;return new e((0,N.map)(this.indexes_,function(e,r){var o=(0,N.safeGet)(i.indexSet_,r);if((0,N.assert)(o,"Missing index implementation for "+r),e===tl)if(!o.isDefinedOn(t.node))return tl;else{for(var a=[],s=n.getIterator(e2.Wrap),u=s.getNext();u;)u.name!==t.name&&a.push(u),u=s.getNext();return a.push(t),tu(a,o.getCompare())}var l=n.get(t.name),h=e;return l&&(h=h.remove(new e2(t.name,l))),h.insert(t,t.node)}),this.indexSet_)}},{key:"removeFromIndexes",value:function(t,n){return new e((0,N.map)(this.indexes_,function(e){if(e===tl)return e;var i=n.get(t.name);return i?e.remove(new e2(t.name,i)):e}),this.indexSet_)}}],[{key:"Default",get:function(){return(0,N.assert)(tl&&to,"ChildrenNode.ts has not been loaded"),h=h||new e({".priority":tl},{".priority":to})}}]),e}(),tc=function(){function e(t,n,i){(0,m._)(this,e),this.children_=t,this.priorityNode_=n,this.indexMap_=i,this.lazyHash_=null,this.priorityNode_&&ti(this.priorityNode_),this.children_.isEmpty()&&(0,N.assert)(!this.priorityNode_||this.priorityNode_.isEmpty(),"An empty node cannot have a priority")}return(0,k._)(e,[{key:"isLeafNode",value:function(){return!1}},{key:"getPriority",value:function(){return this.priorityNode_||c}},{key:"updatePriority",value:function(t){return this.children_.isEmpty()?this:new e(this.children_,t,this.indexMap_)}},{key:"getImmediateChild",value:function(e){if(".priority"===e)return this.getPriority();var t=this.children_.get(e);return null===t?c:t}},{key:"getChild",value:function(e){var t=eW(e);return null===t?this:this.getImmediateChild(t).getChild(eB(e))}},{key:"hasChild",value:function(e){return null!==this.children_.get(e)}},{key:"updateImmediateChild",value:function(t,n){if((0,N.assert)(n,"We should always be passing snapshot nodes"),".priority"===t)return this.updatePriority(n);var i,r,o=new e2(t,n);n.isEmpty()?(i=this.children_.remove(t),r=this.indexMap_.removeFromIndexe
2s(o,this.children_)):(i=this.children_.insert(t,n),r=this.indexMap_.addToIndexes(o,this.children_));var a=i.isEmpty()?c:this.priorityNode_;return new e(i,a,r)}},{key:"updateChild",value:function(e,t){var n=eW(e);if(null===n)return t;(0,N.assert)(".priority"!==eW(e)||1===eU(e),".priority must be the last token in a path");var i=this.getImmediateChild(n).updateChild(eB(e),t);return this.updateImmediateChild(n,i)}},{key:"isEmpty",value:function(){return this.children_.isEmpty()}},{key:"numChildren",value:function(){return this.children_.count()}},{key:"val",value:function(t){if(this.isEmpty())return null;var n={},i=0,r=0,o=!0;if(this.forEachChild(to,function(a,s){n[a]=s.val(t),i++,o&&e.INTEGER_REGEXP_.test(a)?r=Math.max(r,Number(a)):o=!1}),t||!o||!(r<2*i))return t&&!this.getPriority().isEmpty()&&(n[".priority"]=this.getPriority().val()),n;var a=[];for(var s in n)a[s]=n[s];return a}},{key:"hash",value:function(){if(null===this.lazyHash_){var e="";this.getPriority().isEmpty()||(e+="priority:"+tn(this.getPriority().val())+":"),this.forEachChild(to,function(t,n){var i=n.hash();""!==i&&(e+=":"+t+":"+i)}),this.lazyHash_=""===e?"":j(e)}return this.lazyHash_}},{key:"getPredecessorChildName",value:function(e,t,n){var i=this.resolveIndex_(n);if(!i)return this.children_.getPredecessorKey(e);var r=i.getPredecessorKey(new e2(e,t));return r?r.name:null}},{key:"getFirstChildName",value:function(e){var t=this.resolveIndex_(e);if(!t)return this.children_.minKey();var n=t.minKey();return n&&n.name}},{key:"getFirstChild",value:function(e){var t=this.getFirstChildName(e);return t?new e2(t,this.children_.get(t)):null}},{key:"getLastChildName",value:function(e){var t=this.resolveIndex_(e);if(!t)return this.children_.maxKey();var n=t.maxKey();return n&&n.name}},{key:"getLastChild",value:function(e){var t=this.getLastChildName(e);return t?new e2(t,this.children_.get(t)):null}},{key:"forEachChild",value:function(e,t){var n=this.resolveIndex_(e);return n?n.inorderTraversal(function(e){return t(e.name,e.node)}):this.children_.inorderTraversal(t)}},{key:"getIterator",value:function(e){return this.getIteratorFrom(e.minPost(),e)}},{key:"getIteratorFrom",value:function(e,t){var n=this.resolveIndex_(t);if(n)return n.getIteratorFrom(e,function(e){return e});for(var i=this.children_.getIteratorFrom(e.name,e2.Wrap),r=i.peek();null!=r&&0>t.compare(r,e);)i.getNext(),r=i.peek();return i}},{key:"getReverseIterator",value:function(e){return this.getReverseIteratorFrom(e.maxPost(),e)}},{key:"getReverseIteratorFrom",value:function(e,t){var n=this.resolveIndex_(t);if(n)return n.getReverseIteratorFrom(e,function(e){return e});for(var i=this.children_.getReverseIteratorFrom(e.name,e2.Wrap),r=i.peek();null!=r&&t.compare(r,e)>0;)i.getNext(),r=i.peek();return i}},{key:"compareTo",value:function(e){if(this.isEmpty())if(e.isEmpty())return 0;else return -1;return e.isLeafNode()||e.isEmpty()?1:e===td?-1:0}},{key:"withIndex",value:function(t){if(t===e5||this.indexMap_.hasIndex(t))return this;var n=this.indexMap_.addIndex(t,this.children_);return new e(this.children_,this.priorityNode_,n)}},{key:"isIndexed",value:function(e){return e===e5||this.indexMap_.hasIndex(e)}},{key:"equals",value:function(e){if(e===this)return!0;if(e.isLeafNode()||!this.getPriority().equals(e.getPriority()))return!1;if(this.children_.count()!==e.children_.count())return!1;for(var t=this.getIterator(to),n=e.getIterator(to),i=t.getNext(),r=n.getNext();i&&r;){if(i.name!==r.name||!i.node.equals(r.node))return!1;i=t.getNext(),r=n.getNext()}return null===i&&null===r}},{key:"resolveIndex_",value:function(e){return e===e5?null:this.indexMap_.get(e.toString())}}],[{key:"EMPTY_NODE",get:function(){return c||(c=new e(new e9(tt),null,th.Default))}}]),e}();tc.INTEGER_REGEXP_=/^(0|[1-9]\d*)$/;var td=new(function(e){function t(){return(0,m._)(this,t),(0,g._)(this,t,[new e9(tt),tc.EMPTY_NODE,th.Default])}
2return(0,C._)(t,e),(0,k._)(t,[{key:"compareTo",value:function(e){return+(e!==this)}},{key:"equals",value:function(e){return e===this}},{key:"getPriority",value:function(){return this}},{key:"getImmediateChild",value:function(e){return tc.EMPTY_NODE}},{key:"isEmpty",value:function(){return!1}}]),t}(tc));function tf(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;if(null===e)return tc.EMPTY_NODE;if((void 0===e?"undefined":(0,I._)(e))==="object"&&".priority"in e&&(t=e[".priority"]),(0,N.assert)(null===t||"string"==typeof t||"number"==typeof t||(void 0===t?"undefined":(0,I._)(t))==="object"&&".sv"in t,"Invalid priority type found: "+(void 0===t?"undefined":(0,I._)(t))),(void 0===e?"undefined":(0,I._)(e))==="object"&&".value"in e&&null!==e[".value"]&&(e=e[".value"]),(void 0===e?"undefined":(0,I._)(e))!=="object"||".sv"in e)return new tr(e,tf(t));if((0,w._)(e,Array)){var n=tc.EMPTY_NODE;return eu(e,function(t,i){if((0,N.contains)(e,t)&&"."!==t.substring(0,1)){var r=tf(i);(r.isLeafNode()||!r.isEmpty())&&(n=n.updateImmediateChild(t,r))}}),n.updatePriority(tf(t))}var i=[],r=!1;if(eu(e,function(e,t){if("."!==e.substring(0,1)){var n=tf(t);n.isEmpty()||(r=r||!n.getPriority().isEmpty(),i.push(new e2(e,n)))}}),0===i.length)return tc.EMPTY_NODE;var o=tu(i,te,function(e){return e.name},tt);if(!r)return new tc(o,tf(t),th.Default);var a=tu(i,to.getCompare());return new tc(o,tf(t),new th({".priority":a},{".priority":to}))}Object.defineProperties(e2,{MIN:{value:new e2(et,tc.EMPTY_NODE)},MAX:{value:new e2(en,td)}}),e3.__EMPTY_NODE=tc.EMPTY_NODE,tr.__childrenNodeConstructor=tc,a=td,l=td,u=tf;var t_=function(e){function t(e){var n;return(0,m._)(this,t),(n=(0,g._)(this,t)).indexPath_=e,(0,N.assert)(!eY(e)&&".priority"!==eW(e),"Can't create PathIndex with empty path or .priority key"),n}return(0,C._)(t,e),(0,k._)(t,[{key:"extractChild",value:function(e){return e.getChild(this.indexPath_)}},{key:"isDefinedOn",value:function(e){return!e.getChild(this.indexPath_).isEmpty()}},{key:"compare",value:function(e,t){var n=this.extractChild(e.node),i=this.extractChild(t.node),r=n.compareTo(i);return 0===r?ei(e.name,t.name):r}},{key:"makePost",value:function(e,t){var n=tf(e);return new e2(t,tc.EMPTY_NODE.updateChild(this.indexPath_,n))}},{key:"maxPost",value:function(){return new e2(en,tc.EMPTY_NODE.updateChild(this.indexPath_,td))}},{key:"toString",value:function(){return eV(this.indexPath_,0).join("/")}}]),t}(e4),tv=new(function(e){function t(){return(0,m._)(this,t),(0,g._)(this,t,arguments)}
2return(0,C._)(t,e),(0,k._)(t,[{key:"compare",value:function(e,t){var n=e.node.compareTo(t.node);return 0===n?ei(e.name,t.name):n}},{key:"isDefinedOn",value:function(e){return!0}},{key:"indexedValueChanged",value:function(e,t){return!e.equals(t)}},{key:"minPost",value:function(){return e2.MIN}},{key:"maxPost",value:function(){return e2.MAX}},{key:"makePost",value:function(e,t){return new e2(t,tf(e))}},{key:"toString",value:function(){return".value"}}]),t}(e4));function tp(e){return{type:"value",snapshotNode:e}}function ty(e,t){return{type:"child_added",snapshotNode:t,childName:e}}function tg(e,t){return{type:"child_removed",snapshotNode:t,childName:e}}function tm(e,t,n){return{type:"child_changed",snapshotNode:t,childName:e,oldSnap:n}}var tk=function(){function e(t){(0,m._)(this,e),this.index_=t}return(0,k._)(e,[{key:"updateChild",value:function(e,t,n,i,r,o){(0,N.assert)(e.isIndexed(this.index_),"A node must be indexed if only a child is updated");var a=e.getImmediateChild(t);return a.getChild(i).equals(n.getChild(i))&&a.isEmpty()===n.isEmpty()||(null!=o&&(n.isEmpty()?e.hasChild(t)?o.trackChildChange(tg(t,a)):(0,N.assert)(e.isLeafNode(),"A child remove without an old child only makes sense on a leaf node"):a.isEmpty()?o.trackChildChange(ty(t,n)):o.trackChildChange(tm(t,n,a))),e.isLeafNode()&&n.isEmpty())?e:e.updateImmediateChild(t,n).withIndex(this.index_)}},{key:"updateFullNode",value:function(e,t,n){return null!=n&&(e.isLeafNode()||e.forEachChild(to,function(e,i){t.hasChild(e)||n.trackChildChange(tg(e,i))}),t.isLeafNode()||t.forEachChild(to,function(t,i){if(e.hasChild(t)){var r=e.getImmediateChild(t);r.equals(i)||n.trackChildChange(tm(t,i,r))}else n.trackChildChange(ty(t,i))})),t.withIndex(this.index_)}},{key:"updatePriority",value:function(e,t){return e.isEmpty()?tc.EMPTY_NODE:e.updatePriority(t)}},{key:"filtersNodes",value:function(){return!1}},{key:"getIndexedFilter",value:function(){return this}},{key:"getIndex",value:function(){return this.index_}}]),e}(),tC=function(){function e(t){(0,m._)(this,e),this.indexedFilter_=new tk(t.getIndex()),this.index_=t.getIndex(),this.startPost_=e.getStartPost_(t),this.endPost_=e.getEndPost_(t),this.startIsInclusive_=!t.startAfterSet_,this.endIsInclusive_=!t.endBeforeSet_}return(0,k._)(e,[{key:"getStartPost",value:function(){return this.startPost_}},{key:"getEndPost",value:function(){return this.endPost_}},{key:"matches",value:function(e){var t=this.startIsInclusive_?0>=this.index_.compare(this.getStartPost(),e):0>this.index_.compare(this.getStartPost(),e),n=this.endIsInclusive_?0>=this.index_.compare(e,this.getEndPost()):0>this.index_.compare(e,this.getEndPost());return t&&n}},{key:"updateChild",value:function(e,t,n,i,r,o){return this.matches(new e2(t,n))||(n=tc.EMPTY_NODE),this.indexedFilter_.updateChild(e,t,n,i,r,o)}},{key:"updateFullNode",value:function(e,t,n){t.isLeafNode()&&(t=tc.EMPTY_NODE);var i=t.withIndex(this.index_);i=i.updatePriority(tc.EMPTY_NODE);var r=this;return t.forEachChild(to,function(e,t){r.matches(new e2(e,t))||(i=i.updateImmediateChild(e,tc.EMPTY_NODE))}),this.indexedFilter_.updateFullNode(e,i,n)}},{key:"updatePriority",value:function(e,t){return e}},{key:"filtersNodes",value:function(){return!0}},{key:"getIndexedFilter",value:function(){return this.indexedFilter_}},{key:"getIndex",value:function(){return this.index_}}],[{key:"getStartPost_",value:function(e){if(!e.hasStart())return e.getIndex().minPost();var t=e.getIndexStartName();return e.getIndex().makePost(e.getIndexStartValue(),t)}},{key:"getEndPost_",value:function(e){if(!e.hasEnd())return e.getIndex().maxPost();var t=e.getIndexEndName();return e.getIndex().makePost(e.getIndexEndValue(),t)}}]),e}(),tw=function(){function e(t){var n=this;(0,m._)(this,e),this.withinDirectionalStart=function(e){return n.reverse_?n.withinEndPost(e):n.withinStartPost(e)},this.withinDirectionalEnd=function(e){return n.reverse_?n.withinStartPost(e):n.withinEndPost(e)},this.withinStartPost=function(e){var t=n.index_.compare(n.rangedFilter_.getStartPost(),e);return n.startIsInclusive_?t<=0:t<0},this.withinEndPost=function(e){var t=n.index_.compare(e,n.rangedFilter_.getEndPost());return n.endIsInclusive_?t<=0:t<0}
2,this.rangedFilter_=new tC(t),this.index_=t.getIndex(),this.limit_=t.getLimit(),this.reverse_=!t.isViewFromLeft(),this.startIsInclusive_=!t.startAfterSet_,this.endIsInclusive_=!t.endBeforeSet_}return(0,k._)(e,[{key:"updateChild",value:function(e,t,n,i,r,o){return(this.rangedFilter_.matches(new e2(t,n))||(n=tc.EMPTY_NODE),e.getImmediateChild(t).equals(n))?e:e.numChildren()<this.limit_?this.rangedFilter_.getIndexedFilter().updateChild(e,t,n,i,r,o):this.fullLimitUpdateChild_(e,t,n,r,o)}},{key:"updateFullNode",value:function(e,t,n){var i;if(t.isLeafNode()||t.isEmpty())i=tc.EMPTY_NODE.withIndex(this.index_);else if(2*this.limit_<t.numChildren()&&t.isIndexed(this.index_)){i=tc.EMPTY_NODE.withIndex(this.index_);for(var r=this.reverse_?t.getReverseIteratorFrom(this.rangedFilter_.getEndPost(),this.index_):t.getIteratorFrom(this.rangedFilter_.getStartPost(),this.index_),o=0;r.hasNext()&&o<this.limit_;){var a=r.getNext();if(this.withinDirectionalStart(a))if(this.withinDirectionalEnd(a))i=i.updateImmediateChild(a.name,a.node),o++;else break}}else{i=(i=t.withIndex(this.index_)).updatePriority(tc.EMPTY_NODE);for(var s=this.reverse_?i.getReverseIterator(this.index_):i.getIterator(this.index_),u=0;s.hasNext();){var l=s.getNext();u<this.limit_&&this.withinDirectionalStart(l)&&this.withinDirectionalEnd(l)?u++:i=i.updateImmediateChild(l.name,tc.EMPTY_NODE)}}return this.rangedFilter_.getIndexedFilter().updateFullNode(e,i,n)}},{key:"updatePriority",value:function(e,t){return e}},{key:"filtersNodes",value:function(){return!0}},{key:"getIndexedFilter",value:function(){return this.rangedFilter_.getIndexedFilter()}},{key:"getIndex",value:function(){return this.index_}},{key:"fullLimitUpdateChild_",value:function(e,t,n,i,r){if(this.reverse_){var o,a=this.index_.getCompare();o=function(e,t){return a(t,e)}}else o=this.index_.getCompare();(0,N.assert)(e.numChildren()===this.limit_,"");var s=new e2(t,n),u=this.reverse_?e.getFirstChild(this.index_):e.getLastChild(this.index_),l=this.rangedFilter_.matches(s);if(e.hasChild(t)){for(var h=e.getImmediateChild(t),c=i.getChildAfterChild(this.index_,u,this.reverse_);null!=c&&(c.name===t||e.hasChild(c.name));)c=i.getChildAfterChild(this.index_,c,this.reverse_);var d=null==c?1:o(c,s);if(l&&!n.isEmpty()&&d>=0)return null!=r&&r.trackChildChange(tm(t,n,h)),e.updateImmediateChild(t,n);null!=r&&r.trackChildChange(tg(t,h));var f=e.updateImmediateChild(t,tc.EMPTY_NODE);return null!=c&&this.rangedFilter_.matches(c)?(null!=r&&r.trackChildChange(ty(c.name,c.node)),f.updateImmediateChild(c.name,c.node)):f}return n.isEmpty()?e:l?o(u,s)>=0?(null!=r&&(r.trackChildChange(tg(u.name,u.node)),r.trackChildChange(ty(t,n))),e.updateImmediateChild(t,n).updateImmediateChild(u.name,tc.EMPTY_NODE)):e:e}}]),e}(),tT=function(){function e(){(0,m._)(this,e),this.limitSet_=!1,this.startSet_=!1,this.startNameSet_=!1,this.startAfterSet_=!1,this.endSet_=!1,this.endNameSet_=!1,this.endBeforeSet_=!1,this.limit_=0,this.viewFrom_="",this.indexStartValue_=null,this.indexStartName_="",this.indexEndValue_=null,this.indexEndName_="",this.index_=to}return(0,k._)(e,[{key:"hasStart",value:function(){return this.startSet_}},{key:"isViewFromLeft",value:function(){return""===this.viewFrom_?this.startSet_:"l"===this.viewFrom_}},{key:"getIndexStartValue",value:function(){return(0,N.assert)(this.startSet_,"Only valid if start has been set"),this.indexStartValue_}},{key:"getIndexStartName",value:function(){return((0,N.assert)(this.startSet_,"Only valid if start has been set"),this.startNameSet_)?this.indexStartName_:et}},{key:"hasEnd",value:function(){return this.endSet_}},{key:"getIndexEndValue",value:function(){return(0,N.assert)(this.endSet_,"Only valid if end has been set"),this.indexEndValue_}},{key:"getIndexEndName",value:function(){return((0,N.assert)(this.endSet_,"Only valid if end has been set"),this.endNameSet_)?this.indexEndName_:en}},{key:"hasLimit",value:function(){return this.limitSet_}},{key:"hasAnchoredLimit",value:function(){return this.limitSet_&&""!==this.viewFrom_}},{key:"getLimit",value:function(){return(0,N.assert)(this.limitSet_,"Only valid if limit has been set"),this.limit_}},{key:"getIndex",value:function(){return this.index_}},{key:"loadsAllData",value:function(){return!(this.startSet_||this.endSet_||this.limitSet_)}},{key:"isDefault",value:function(){return this.loadsAllData()&&this.index_===to}},{key:"copy",value:function(){var t=new e;return t.limitSet_=this.limitSet_,t.limit_=this.limit_,t.startSet_=this.startSet_,t.startAfterSet_=this.startAfterSet_,t.indexStartValue_=this.indexStartValue_,t.startNameSet_=this.startNameSet_,t.indexStartName_=this.indexStartName_,t.endSet_=this.endSet_,t.endBeforeSet_=this.endBeforeSet_,t.indexEndValue_=this.indexEndValue_,t.endNameSet_=this.endNameSet_,t.indexEndName_=this.indexEndName_,t.index_
2=this.index_,t.viewFrom_=this.viewFrom_,t}}]),e}();function tb(e,t,n){var i=e.copy();return i.startSet_=!0,void 0===t&&(t=null),i.indexStartValue_=t,null!=n?(i.startNameSet_=!0,i.indexStartName_=n):(i.startNameSet_=!1,i.indexStartName_=""),i}function tI(e,t,n){var i=e.copy();return i.endSet_=!0,void 0===t&&(t=null),i.indexEndValue_=t,void 0!==n?(i.endNameSet_=!0,i.indexEndName_=n):(i.endNameSet_=!1,i.indexEndName_=""),i}function tE(e,t){var n=e.copy();return n.index_=t,n}function tS(e){var t,n={};if(e.isDefault())return n;if(e.index_===to?t="$priority":e.index_===tv?t="$value":e.index_===e5?t="$key":((0,N.assert)((0,w._)(e.index_,t_),"Unrecognized index type!"),t=e.index_.toString()),n.orderBy=(0,N.stringify)(t),e.startSet_){var i=e.startAfterSet_?"startAfter":"startAt";n[i]=(0,N.stringify)(e.indexStartValue_),e.startNameSet_&&(n[i]+=","+(0,N.stringify)(e.indexStartName_))}if(e.endSet_){var r=e.endBeforeSet_?"endBefore":"endAt";n[r]=(0,N.stringify)(e.indexEndValue_),e.endNameSet_&&(n[r]+=","+(0,N.stringify)(e.indexEndName_))}return e.limitSet_&&(e.isViewFromLeft()?n.limitToFirst=e.limit_:n.limitToLast=e.limit_),n}function tP(e){var t={};if(e.startSet_&&(t.sp=e.indexStartValue_,e.startNameSet_&&(t.sn=e.indexStartName_),t.sin=!e.startAfterSet_),e.endSet_&&(t.ep=e.indexEndValue_,e.endNameSet_&&(t.en=e.indexEndName_),t.ein=!e.endBeforeSet_),e.limitSet_){t.l=e.limit_;var n=e.viewFrom_;""===n&&(n=e.isViewFromLeft()?"l":"r"),t.vf=n}return e.index_!==to&&(t.i=e.index_.toString()),t}var tN=function(e){function t(e,n,i,r){var o;return(0,m._)(this,t),(o=(0,g._)(this,t)).repoInfo_=e,o.onDataUpdate_=n,o.authTokenProvider_=i,o.appCheckTokenProvider_=r,o.log_=Q("p:rest:"),o.listens_={},o}return(0,C._)(t,e),(0,k._)(t,[{key:"reportStats",value:function(e){throw Error("Method not implemented.")}},{key:"listen",value:function(e,n,i,r){var o=this,a=e._path.toString();this.log_("Listen called for "+a+" "+e._queryIdentifier);var s=t.getListenId_(e,i),u={};this.listens_[s]=u;var l=tS(e._queryParams);this.restRequest_(a+".json",l,function(e,t){var n=t;404===e&&(n=null,e=null),null===e&&o.onDataUpdate_(a,n,!1,i),(0,N.safeGet)(o.listens_,s)===u&&r(e?401===e?"permission_denied":"rest_error:"+e:"ok",null)})}},{key:"unlisten",value:function(e,n){var i=t.getListenId_(e,n);delete this.listens_[i]}},{key:"get",value:function(e){var t=this,n=tS(e._queryParams),i=e._path.toString(),r=new N.Deferred;return this.restRequest_(i+".json",n,function(e,n){var o=n;404===e&&(o=null,e=null),null===e?(t.onDataUpdate_(i,o,!1,null),r.resolve(o)):r.reject(Error(o))}),r.promise}},{key:"refreshAuthToken",value:function(e){}},{key:"restRequest_",value:function(e){var t=this,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=arguments.length>2?arguments[2]:void 0;return n.format="export",Promise.all([this.authTokenProvider_.getToken(!1),this.appCheckTokenProvider_.getToken(!1)]).then(function(r){var o=(0,T._)(r,2),a=o[0],s=o[1];a&&a.accessToken&&(n.auth=a.accessToken),s&&s.token&&(n.ac=s.token);var u=(t.repoInfo_.secure?"https://":"http://")+t.repoInfo_.host+e+"?ns="+t.repoInfo_.namespace+(0,N.querystring)(n);t.log_("Sending REST request for "+u);var l=new XMLHttpRequest;l.onreadystatechange=function(){if(i&&4===l.readyState){t.log_("REST Response for "+u+" received. status:",l.status,"response:",l.responseText);var e=null;if(l.status>=200&&l.status<300){try{e=(0,N.jsonEval)(l.responseText)}catch(e){X("Failed to parse JSON response for "+u+": "+l.responseText)}i(null,e)}else 401!==l.status&&404!==l.status&&X("Got unsuccessful REST response for "+u+" Status: "+l.status),i(l.status);i=null}},l.open("GET",u,!0),l.send()})}}],[{key:"getListenId_",value:function(e,t){return void 0!==t?"tag$"+t:((0,N.assert)(e._queryParams.isDefault(),"should have a tag if it's not a default query."),e._path.toString())}}]),t}(eM),tx=function(){function e(){(0,m._)(this,e),this.rootNode_=tc.EMPTY_NODE}return(0,k._)(e,[{key:"getNode",value:function(e){return this.rootNode_.getChild(e)}},{key:"updateSnapshot",value:function(e,t){this.rootNode_=this.rootNode_.updateChild(e,t)}}]),e}();function tR(){return{value:null,children:new Map}}function tD(e,t,n){if(eY(t))e.value=n,e.children.clear();else if(null!==e.value)e.value=e.value.updateChild(t,n);else{var i=eW(t);e.children.has(i)||e.children.set(i,tR()),tD(e.children.get(i),t=eB(t),n)}}function tA(e,t,n){var i,r;null!==e.value?n(t,e.value):(i=e,r=function(e,i){tA(i,new eL(t.toString()+"/"+e),n)}
2,i.children.forEach(function(e,t){r(t,e)}))}var tM=function(){function e(t){(0,m._)(this,e),this.collection_=t,this.last_=null}return(0,k._)(e,[{key:"get",value:function(){var e=this.collection_.get(),t=Object.assign({},e);return this.last_&&eu(this.last_,function(e,n){t[e]=t[e]-n}),this.last_=e,t}}]),e}(),tq=function(){function e(t,n){(0,m._)(this,e),this.server_=n,this.statsToReport_={},this.statsListener_=new tM(t);var i=1e4+2e4*Math.random();ef(this.reportStats_.bind(this),Math.floor(i))}return(0,k._)(e,[{key:"reportStats_",value:function(){var e=this,t=this.statsListener_.get(),n={},i=!1;eu(t,function(t,r){r>0&&(0,N.contains)(e.statsToReport_,t)&&(n[t]=r,i=!0)}),i&&this.server_.reportStats(n),ef(this.reportStats_.bind(this),Math.floor(2*Math.random()*3e5))}}]),e}();function tF(){return{fromUser:!0,fromServer:!1,queryId:null,tagged:!1}}function tL(){return{fromUser:!1,fromServer:!0,queryId:null,tagged:!1}}function tO(e){return{fromUser:!1,fromServer:!0,queryId:e,tagged:!0}}(n=d||(d={}))[n.OVERWRITE=0]="OVERWRITE",n[n.MERGE=1]="MERGE",n[n.ACK_USER_WRITE=2]="ACK_USER_WRITE",n[n.LISTEN_COMPLETE=3]="LISTEN_COMPLETE";var tW=function(){function e(t,n,i){(0,m._)(this,e),this.path=t,this.affectedTree=n,this.revert=i,this.type=d.ACK_USER_WRITE,this.source=tF()}return(0,k._)(e,[{key:"operationForChild",value:function(t){if(!eY(this.path))return(0,N.assert)(eW(this.path)===t,"operationForChild called for unrelated child."),new e(eB(this.path),this.affectedTree,this.revert);if(null!=this.affectedTree.value)return(0,N.assert)(this.affectedTree.children.isEmpty(),"affectedTree should not have overlapping affected paths."),this;var n=this.affectedTree.subtree(new eL(t));return new e(eO(),n,this.revert)}}]),e}(),tU=function(){function e(t,n){(0,m._)(this,e),this.source=t,this.path=n,this.type=d.LISTEN_COMPLETE}return(0,k._)(e,[{key:"operationForChild",value:function(t){return eY(this.path)?new e(this.source,eO()):new e(this.source,eB(this.path))}}]),e}(),tB=function(){function e(t,n,i){(0,m._)(this,e),this.source=t,this.path=n,this.snap=i,this.type=d.OVERWRITE}return(0,k._)(e,[{key:"operationForChild",value:function(t){return eY(this.path)?new e(this.source,eO(),this.snap.getImmediateChild(t)):new e(this.source,eB(this.path),this.snap)}}]),e}(),tj=function(){function e(t,n,i){(0,m._)(this,e),this.source=t,this.path=n,this.children=i,this.type=d.MERGE}return(0,k._)(e,[{key:"operationForChild",value:function(t){if(!eY(this.path))return(0,N.assert)(eW(this.path)===t,"Can't get a merge for a child not on the path of the operation"),new e(this.source,eB(this.path),this.children);var n=this.children.subtree(new eL(t));return n.isEmpty()?null:n.value?new tB(this.source,eO(),n.value):new e(this.source,eO(),n)}},{key:"toString",value:function(){return"Operation("+this.path+": "+this.source.toString()+" merge: "+this.children.toString()+")"}}]),e}(),tV=function(){function e(t,n,i){(0,m._)(this,e),this.node_=t,this.fullyInitialized_=n,this.filtered_=i}return(0,k._)(e,[{key:"isFullyInitialized",value:function(){return this.fullyInitialized_}},{key:"isFiltered",value:function(){return this.filtered_}},{key:"isCompleteForPath",value:function(e){if(eY(e))return this.isFullyInitialized()&&!this.filtered_;var t=eW(e);return this.isCompleteForChild(t)}},{key:"isCompleteForChild",value:function(e){return this.isFullyInitialized()&&!this.filtered_||this.node_.hasChild(e)}},{key:"getNode",value:function(){return this.node_}}]),e}(),tH=function e(t){(0,m._)(this,e),this.query_=t,this.index_=this.query_._queryParams.getIndex()};function tz(e,t,n,i,r,o){var a=i.filter(function(e){return e.type===n});a.sort(function(t,n){var i=e,r=t,o=n;if(null==r.childName||null==o.childName)throw(0,N.assertionError)("Should only compare child_ events.");var a=new e2(r.childName,r.snapshotNode),s=new e2(o.childName,o.snapshotNode);return i.index_.compare(a,s)}),a.forEach(function(n){var i,a,s,u=(i=e,a=n,s=o,"value"===a.type||"child_removed"===a.type||(a.prevName=s.getPredecessorChildName(a.childName,a.snapshotNode,i.index_)),a);r.forEach(function(i){i.respondsTo(n.type)&&t.push(i.createEvent(u,e.query_))})})}function tY(e,t){return{eventCache:e,serverCache:t}}function tK(e,t,n,i){return tY(new tV(t,n,i),e.serverCache)}function tQ(e,t,n,i){return tY(e.eventCache,new tV(t,n,i))}function tG(e){return e.eventCache.isFullyInitialized()?e.eventCache.getNode():null}function t$(e){return e.serverCache.isFullyInitialized()?e.serverCache.getNode():null}var tX=function(){function e(t){var n=arguments.length>
21&&void 0!==arguments[1]?arguments[1]:(f||(f=new e9(er)),f);(0,m._)(this,e),this.value=t,this.children=n}return(0,k._)(e,[{key:"isEmpty",value:function(){return null===this.value&&this.children.isEmpty()}},{key:"findRootMostMatchingPathAndValue",value:function(e,t){if(null!=this.value&&t(this.value))return{path:eO(),value:this.value};if(eY(e))return null;var n=eW(e),i=this.children.get(n);if(null===i)return null;var r=i.findRootMostMatchingPathAndValue(eB(e),t);return null!=r?{path:ez(new eL(n),r.path),value:r.value}:null}},{key:"findRootMostValueAndPath",value:function(e){return this.findRootMostMatchingPathAndValue(e,function(){return!0})}},{key:"subtree",value:function(t){if(eY(t))return this;var n=eW(t),i=this.children.get(n);return null!==i?i.subtree(eB(t)):new e(null)}},{key:"set",value:function(t,n){if(eY(t))return new e(n,this.children);var i=eW(t),r=(this.children.get(i)||new e(null)).set(eB(t),n),o=this.children.insert(i,r);return new e(this.value,o)}},{key:"remove",value:function(t){if(eY(t))if(this.children.isEmpty())return new e(null);else return new e(null,this.children);var n=eW(t),i=this.children.get(n);if(!i)return this;var r,o=i.remove(eB(t));return(r=o.isEmpty()?this.children.remove(n):this.children.insert(n,o),null===this.value&&r.isEmpty())?new e(null):new e(this.value,r)}},{key:"get",value:function(e){if(eY(e))return this.value;var t=eW(e),n=this.children.get(t);return n?n.get(eB(e)):null}},{key:"setTree",value:function(t,n){if(eY(t))return n;var i,r=eW(t),o=(this.children.get(r)||new e(null)).setTree(eB(t),n);return i=o.isEmpty()?this.children.remove(r):this.children.insert(r,o),new e(this.value,i)}},{key:"fold",value:function(e){return this.fold_(eO(),e)}},{key:"fold_",value:function(e,t){var n={};return this.children.inorderTraversal(function(i,r){n[i]=r.fold_(ez(e,i),t)}),t(e,this.value,n)}},{key:"findOnPath",value:function(e,t){return this.findOnPath_(e,eO(),t)}},{key:"findOnPath_",value:function(e,t,n){var i=!!this.value&&n(t,this.value);if(i)return i;if(eY(e))return null;var r=eW(e),o=this.children.get(r);return o?o.findOnPath_(eB(e),ez(t,r),n):null}},{key:"foreachOnPath",value:function(e,t){return this.foreachOnPath_(e,eO(),t)}},{key:"foreachOnPath_",value:function(t,n,i){if(eY(t))return this;this.value&&i(n,this.value);var r=eW(t),o=this.children.get(r);return o?o.foreachOnPath_(eB(t),ez(n,r),i):new e(null)}},{key:"foreach",value:function(e){this.foreach_(eO(),e)}},{key:"foreach_",value:function(e,t){this.children.inorderTraversal(function(n,i){i.foreach_(ez(e,n),t)}),this.value&&t(e,this.value)}},{key:"foreachChild",value:function(e){this.children.inorderTraversal(function(t,n){n.value&&e(t,n.value)})}}],[{key:"fromObject",value:function(t){var n=new e(null);return eu(t,function(e,t){n=n.set(new eL(e),t)}),n}}]),e}(),tJ=function(){function e(t){(0,m._)(this,e),this.writeTree_=t}return(0,k._)(e,null,[{key:"empty",value:function(){return new e(new tX(null))}}]),e}();function tZ(e,t,n){if(eY(t))return new tJ(new tX(n));var i=e.writeTree_.findRootMostValueAndPath(t);if(null!=i){var r=i.path,o=i.value,a=eK(r,t);return o=o.updateChild(a,n),new tJ(e.writeTree_.set(r,o))}var s=new tX(n);return new tJ(e.writeTree_.setTree(t,s))}function t0(e,t,n){var i=e;return eu(n,function(e,n){i=tZ(i,ez(t,e),n)}),i}function t1(e,t){return eY(t)?tJ.empty():new tJ(e.writeTree_.setTree(t,new tX(null)))}function t2(e,t){return null!=t4(e,t)}function t4(e,t){var n=e.writeTree_.findRootMostValueAndPath(t);return null!=n?e.writeTree_.get(n.path).getChild(eK(n.path,t)):null}function t3(e){var t=[],n=e.writeTree_.value;return null!=n?n.isLeafNode()||n.forEachChild(to,function(e,n){t.push(new e2(e,n))}
2):e.writeTree_.children.inorderTraversal(function(e,n){null!=n.value&&t.push(new e2(e,n.value))}),t}function t5(e,t){if(eY(t))return e;var n=t4(e,t);return new tJ(null!=n?new tX(n):e.writeTree_.subtree(t))}function t6(e){return e.writeTree_.isEmpty()}function t8(e,t){return function e(t,n,i){if(null!=n.value)return i.updateChild(t,n.value);var r=null;return n.children.inorderTraversal(function(n,o){".priority"===n?((0,N.assert)(null!==o.value,"Priority writes must always be leaf nodes"),r=o.value):i=e(ez(t,n),o,i)}),i.getChild(t).isEmpty()||null===r||(i=i.updateChild(ez(t,".priority"),r)),i}(eO(),e.writeTree_,t)}function t7(e){return e.visible}function t9(e,t,n){for(var i=tJ.empty(),r=0;r<e.length;++r){var o=e[r];if(t(o)){var a=o.path,s=void 0;if(o.snap)e$(n,a)?i=tZ(i,s=eK(n,a),o.snap):e$(a,n)&&(s=eK(a,n),i=tZ(i,eO(),o.snap.getChild(s)));else if(o.children){if(e$(n,a))i=t0(i,s=eK(n,a),o.children);else if(e$(a,n))if(eY(s=eK(a,n)))i=t0(i,eO(),o.children);else{var u=(0,N.safeGet)(o.children,eW(s));if(u){var l=u.getChild(eB(s));i=tZ(i,eO(),l)}}}else throw(0,N.assertionError)("WriteRecord should have .snap or .children")}}return i}function ne(e,t,n,i,r){if(i||r){var o=t5(e.visibleWrites,t);return!r&&t6(o)?n:r||null!=n||t2(o,eO())?t8(t9(e.allWrites,function(e){return(e.visible||r)&&(!i||!~i.indexOf(e.writeId))&&(e$(e.path,t)||e$(t,e.path))},t),n||tc.EMPTY_NODE):null}var a=t4(e.visibleWrites,t);if(null!=a)return a;var s=t5(e.visibleWrites,t);return t6(s)?n:null!=n||t2(s,eO())?t8(s,n||tc.EMPTY_NODE):null}function nt(e,t,n,i){return ne(e.writeTree,e.treePath,t,n,i)}function nn(e,t){return function(e,t,n){var i=tc.EMPTY_NODE,r=t4(e.visibleWrites,t);if(r)return r.isLeafNode()||r.forEachChild(to,function(e,t){i=i.updateImmediateChild(e,t)}),i;
2if(!n)return t3(t5(e.visibleWrites,t)).forEach(function(e){i=i.updateImmediateChild(e.name,e.node)}),i;var o=t5(e.visibleWrites,t);return n.forEachChild(to,function(e,t){var n=t8(t5(o,new eL(e)),t);i=i.updateImmediateChild(e,n)}),t3(o).forEach(function(e){i=i.updateImmediateChild(e.name,e.node)}),i}(e.writeTree,e.treePath,t)}function ni(e,t,n,i){return function(e,t,n,i,r){(0,N.assert)(i||r,"Either existingEventSnap or existingServerSnap must exist");var o=ez(t,n);if(t2(e.visibleWrites,o))return null;var a=t5(e.visibleWrites,o);return t6(a)?r.getChild(n):t8(a,r.getChild(n))}(e.writeTree,e.treePath,t,n,i)}function nr(e,t){var n,i;return n=e.writeTree,i=ez(e.treePath,t),t4(n.visibleWrites,i)}function no(e,t,n){var i,r,o,a;return i=e.writeTree,r=e.treePath,o=ez(r,t),null!=(a=t4(i.visibleWrites,o))?a:n.isCompleteForChild(t)?t8(t5(i.visibleWrites,o),n.getNode().getImmediateChild(t)):null}function na(e,t){return ns(ez(e.treePath,t),e.writeTree)}function ns(e,t){return{treePath:e,writeTree:t}}var nu=function(){function e(){(0,m._)(this,e),this.changeMap=new Map}return(0,k._)(e,[{key:"trackChildChange",value:function(e){var t=e.type,n=e.childName;(0,N.assert)("child_added"===t||"child_changed"===t||"child_removed"===t,"Only child changes supported for tracking"),(0,N.assert)(".priority"!==n,"Only non-priority child changes can be tracked.");var i=this.changeMap.get(n);if(i){var r=i.type;if("child_added"===t&&"child_removed"===r)this.changeMap.set(n,tm(n,e.snapshotNode,i.snapshotNode));else if("child_removed"===t&&"child_added"===r)this.changeMap.delete(n);else if("child_removed"===t&&"child_changed"===r)this.changeMap.set(n,tg(n,i.oldSnap));else if("child_changed"===t&&"child_added"===r)this.changeMap.set(n,ty(n,e.snapshotNode));else if("child_changed"===t&&"child_changed"===r)this.changeMap.set(n,tm(n,e.snapshotNode,i.oldSnap));else throw(0,N.assertionError)("Illegal combination of changes: "+e+" occurred after "+i)}else this.changeMap.set(n,e)}},{key:"getChanges",value:function(){return Array.from(this.changeMap.values())}}]),e}(),nl=new(function(){function e(){(0,m._)(this,e)}return(0,k._)(e,[{key:"getCompleteChild",value:function(e){return null}},{key:"getChildAfterChild",value:function(e,t,n){return null}}]),e}()),nh=function(){function e(t,n){var i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null;(0,m._)(this,e),this.writes_=t,this.viewCache_=n,this.optCompleteServerCache_=i}return(0,k._)(e,[{key:"getCompleteChild",value:function(e){var t=this.viewCache_.eventCache;if(t.isCompleteForChild(e))return t.getNode().getImmediateChild(e);var n=null!=this.optCompleteServerCache_?new tV(this.optCompleteServerCache_,!0,!1):this.viewCache_.serverCache;return no(this.writes_,e,n)}},{key:"getChildAfterChild",value:function(e,t,n){var i,r=null!=this.optCompleteServerCache_?this.optCompleteServerCache_:t$(this.viewCache_),o=(i=this.writes_,function(e,t,n,i,r,o){var a,s=t5(e.visibleWrites,t),u=t4(s,eO());if(null!=u)a=u;else{if(null==n)return[];a=t8(s,n)}if((a=a.withIndex(o)).isEmpty()||a.isLeafNode())return[];for(var l=[],h=o.getCompare(),c=r?a.getReverseIteratorFrom(i,o):a.getIteratorFrom(i,o),d=c.getNext();d&&l.length<1;)0!==h(d,i)&&l.push(d),d=c.getNext();return l}(i.writeTree,i.treePath,r,t,n,e));return 0===o.length?null:o[0]}}]),e}();function nc(e,t,n,i,r,o){var a=t.eventCache;if(null!=nr(i,n))return t;if(eY(n))if((0,N.assert)(t.serverCache.isFullyInitialized(),"If change path is empty, we must have complete server data"),t.serverCache.isFiltered()){var s=t$(t),u=nn(i,(0,w._)(s,tc)?s:tc.EMPTY_NODE);f=e.filter.updateFullNode(t.eventCache.getNode(),u,o)}else{var l=nt(i,t$(t));f=e.filter.updateFullNode(t.eventCache.getNode(),l,o)}else{var h=eW(n);if(".priority"===h){(0,N.assert)(1===eU(n),"Can't have a priority with additional path components");var c=a.getNode(),d=ni(i,n,c,_=t.serverCache.getNode());f=null!=d?e.filter.updatePriority(c,d):a.getNode()}else{var f,_,v,p=eB(n);if(a.isCompleteForChild(h)){_=t.serverCache.getNode();var y=ni(i,n,a.getNode(),_);v=null!=y?a.getNode().getImmediateChild(h).updateChild(p,y):a.getNode().getImmediateChild(h)}else v=no(i,h,t.serverCache);
2f=null!=v?e.filter.updateChild(a.getNode(),h,v,p,r,o):a.getNode()}}return tK(t,f,a.isFullyInitialized()||eY(n),e.filter.filtersNodes())}function nd(e,t,n,i,r,o,a,s){var u,l=t.serverCache,h=a?e.filter:e.filter.getIndexedFilter();if(eY(n))u=h.updateFullNode(l.getNode(),i,null);else if(h.filtersNodes()&&!l.isFiltered()){var c=l.getNode().updateChild(n,i);u=h.updateFullNode(l.getNode(),c,null)}else{var d=eW(n);if(!l.isCompleteForPath(n)&&eU(n)>1)return t;var f=eB(n),_=l.getNode().getImmediateChild(d).updateChild(f,i);u=".priority"===d?h.updatePriority(l.getNode(),_):h.updateChild(l.getNode(),d,_,f,nl,null)}var v=tQ(t,u,l.isFullyInitialized()||eY(n),h.filtersNodes()),p=new nh(r,v,o);return nc(e,v,n,r,p,s)}function nf(e,t,n,i,r,o,a){var s=t.eventCache,u=new nh(r,t,o);if(eY(n))c=e.filter.updateFullNode(t.eventCache.getNode(),i,a),h=tK(t,c,!0,e.filter.filtersNodes());else{var l=eW(n);if(".priority"===l)c=e.filter.updatePriority(t.eventCache.getNode(),i),h=tK(t,c,s.isFullyInitialized(),s.isFiltered());else{var h,c,d,f=eB(n),_=s.getNode().getImmediateChild(l);if(eY(f))d=i;else{var v=u.getCompleteChild(l);d=null!=v?".priority"===ej(f)&&v.getChild(eH(f)).isEmpty()?v:v.updateChild(f,i):tc.EMPTY_NODE}h=_.equals(d)?t:tK(t,e.filter.updateChild(s.getNode(),l,d,f,u,a),s.isFullyInitialized(),e.filter.filtersNodes())}}return h}function n_(e,t){return e.eventCache.isCompleteForChild(t)}function nv(e,t,n){return n.foreach(function(e,n){t=t.updateChild(e,n)}),t}function np(e,t,n,i,r,o,a,s){if(t.serverCache.getNode().isEmpty()&&!t.serverCache.isFullyInitialized())return t;var u,l=t;u=eY(n)?i:new tX(null).setTree(n,i);var h=t.serverCache.getNode();return u.children.inorderTraversal(function(n,i){if(h.hasChild(n)){var u=nv(e,t.serverCache.getNode().getImmediateChild(n),i);l=nd(e,l,new eL(n),u,r,o,a,s)}}),u.children.inorderTraversal(function(n,i){var u=!t.serverCache.isCompleteForChild(n)&&null===i.value;if(!h.hasChild(n)&&!u){var c=nv(e,t.serverCache.getNode().getImmediateChild(n),i);l=nd(e,l,new eL(n),c,r,o,a,s)}}),l}var ny=function(){function e(t,n){(0,m._)(this,e),this.query_=t,this.eventRegistrations_=[];var i=this.query_._queryParams,r=new tk(i.getIndex()),o=i.loadsAllData()?new tk(i.getIndex()):i.hasLimit()?new tw(i):new tC(i);this.processor_={filter:o};var a=n.serverCache,s=n.eventCache,u=r.updateFullNode(tc.EMPTY_NODE,a.getNode(),null),l=o.updateFullNode(tc.EMPTY_NODE,s.getNode(),null),h=new tV(u,a.isFullyInitialized(),r.filtersNodes()),c=new tV(l,s.isFullyInitialized(),o.filtersNodes());this.viewCache_=tY(c,h),this.eventGenerator_=new tH(this.query_)}return(0,k._)(e,[{key:"query",get:function(){return this.query_}}]),e}();function ng(e){return 0===e.eventRegistrations_.length}function nm(e,t,n){var i=[];if(n){(0,N.assert)(null==t,"A cancel should cancel all event registrations.");var r=e.query._path;e.eventRegistrations_.forEach(function(e){var t=e.createCancelEvent(n,r);t&&i.push(t)})}if(t){for(var o=[],a=0;a<e.eventRegistrations_.length;++a){var s=e.eventRegistrations_[a];if(s.matches(t)){if(t.hasAnyCallback()){o=o.concat(e.eventRegistrations_.slice(a+1));break}}else o.push(s)}e.eventRegistrations_=o}else e.eventRegistrations_=[];return i}function nk(e,t,n,i){t.type===d.MERGE&&null!==t.source.queryId&&((0,N.assert)(t$(e.viewCache_),"We should always have a full cache before handling merges"),(0,N.assert)(tG(e.viewCache_),"Missing event cache, even though we have a server cache"));var r,o,a=e.viewCache_,s=function(e,t,n,i,r){var o,a,s,u,l,h,c,f,_,v,p,y,g,m,k,C,T=new nu;if(n.type===d.OVERWRITE)n.source.fromUser?k=nf(e,t,n.path,n.snap,i,r,T):((0,N.assert)(n.source.fromServer,"Unknown source."),C=n.source.tagged||t.serverCache.isFiltered()&&!eY(n.path),k=nd(e,t,n.path,n.snap,i,r,C,T));else if(n.type===d.MERGE){n.source.fromUser?(o=e,a=t,s=n.path,u=n.children,l=i,h=r,c=T,f=a,u.foreach(function(e,t){var n=ez(s,e);n_(a,eW(n))&&(f=nf(o,f,n,t,l,h,c))}),u.foreach(function(e,t){var n=ez(s,e);n_(a,eW(n))||(f=nf(o,f,n,t,l,h,c))}),k=f):((0,N.assert)(n.source.fromServer,"Unknown source."),C=n.source.tagged||t.serverCache.isFiltered(),k=np(e,t,n.path,n.children,i,r,C,T))}else if(n.type===d.ACK_USER_WRITE)k=n.revert?function(e,t,n,i,r,o){if(null!=nr(i,n))return t;var a,s,u,l=new nh(i,t,r),h=t.eventCache.getNode();if(eY(n)||".priority"===eW(n)){if(t.serverCache.isFullyInitialized())u=nt(i,t$(t));else{var c=t.serverCache.getNode();(0,N.assert)((0,w._)(c,tc),"serverChildren would be complete if leaf node"),u=nn(i,c)}s=e.filter.updateFullNode(h,u,o)}else{var d=eW(n),f=no(i,d,t.serverCache);null==f&&t.serverCache.isCompleteForChild(d)&&(f=h.getImmediateChild(d)),(s=null!=f?e.filter.updateChild(h,d,f,eB(n),l,o):t.eventCache.getNode().hasChild(d)?e.filter.updateChild(h,d,tc.EMPTY_NODE,eB(n),l,o):h).isEmpty()&&t.serverCache.isFullyInitialized()&&(a=nt(i,t$(t))).isLeafNode()&&(s=e.filter.updateFullNode(s,a,o))}
2return a=t.serverCache.isFullyInitialized()||null!=nr(i,eO()),tK(t,s,a,e.filter.filtersNodes())}(e,t,n.path,i,r,T):function(e,t,n,i,r,o,a){if(null!=nr(r,n))return t;var s=t.serverCache.isFiltered(),u=t.serverCache;if(null!=i.value)if(eY(n)&&u.isFullyInitialized()||u.isCompleteForPath(n))return nd(e,t,n,u.getNode().getChild(n),r,o,s,a);else{if(!eY(n))return t;var l=new tX(null);return u.getNode().forEachChild(e5,function(e,t){l=l.set(new eL(e),t)}),np(e,t,n,l,r,o,s,a)}var h=new tX(null);return i.foreach(function(e,t){var i=ez(n,e);u.isCompleteForPath(i)&&(h=h.set(e,u.getNode().getChild(i)))}),np(e,t,n,h,r,o,s,a)}(e,t,n.path,n.affectedTree,i,r,T);else if(n.type===d.LISTEN_COMPLETE){_=e,v=t,p=n.path,y=i,g=T,m=v.serverCache,k=nc(_,tQ(v,m.getNode(),m.isFullyInitialized()||eY(p),m.isFiltered()),p,y,nl,g)}else throw(0,N.assertionError)("Unknown operation type: "+n.type);var b=T.getChanges();return function(e,t,n){var i=t.eventCache;if(i.isFullyInitialized()){var r=i.getNode().isLeafNode()||i.getNode().isEmpty(),o=tG(e);!(n.length>0)&&e.eventCache.isFullyInitialized()&&(!r||i.getNode().equals(o))&&i.getNode().getPriority().equals(o.getPriority())||n.push(tp(tG(t)))}}(t,k,b),{viewCache:k,changes:b}}(e.processor_,a,t,n,i);return r=e.processor_,o=s.viewCache,(0,N.assert)(o.eventCache.getNode().isIndexed(r.filter.getIndex()),"Event snap not indexed"),(0,N.assert)(o.serverCache.getNode().isIndexed(r.filter.getIndex()),"Server snap not indexed"),(0,N.assert)(s.viewCache.serverCache.isFullyInitialized()||!a.serverCache.isFullyInitialized(),"Once a server snap is complete, it should never go back"),e.viewCache_=s.viewCache,nC(e,s.changes,s.viewCache.eventCache.getNode(),null)}function nC(e,t,n,i){var r,o,a,s=i?[i]:e.eventRegistrations_;return r=e.eventGenerator_,o=[],a=[],t.forEach(function(e){var t;"child_changed"===e.type&&r.index_.indexedValueChanged(e.oldSnap,e.snapshotNode)&&a.push((t=e.childName,{type:"child_moved",snapshotNode:e.snapshotNode,childName:t}))}),tz(r,o,"child_removed",t,s,n),tz(r,o,"child_added",t,s,n),tz(r,o,"child_moved",a,s,n),tz(r,o,"child_changed",t,s,n),tz(r,o,"value",t,s,n),o}var nw=function e(){(0,m._)(this,e),this.views=new Map};function nT(e,t,n,i){var r=t.source.queryId;if(null!==r){var o=e.views.get(r);return(0,N.assert)(null!=o,"SyncTree gave us an op for an invalid query."),nk(o,t,n,i)}var a=[],s=!0,u=!1,l=void 0;try{for(var h,c=e.views.values()[Symbol.iterator]();!(s=(h=c.next()).done);s=!0){var d=h.value;a=a.concat(nk(d,t,n,i))}}catch(e){u=!0,l=e}finally{try{s||null==c.return||c.return()}finally{if(u)throw l}}return a}function nb(e,t,n,i,r){var o=t._queryIdentifier,a=e.views.get(o);if(!a){var s=nt(n,r?i:null),u=!1;return s?u=!0:(s=(0,w._)(i,tc)?nn(n,i):tc.EMPTY_NODE,u=!1),new ny(t,tY(new tV(s,u,!1),new tV(i,r,!1)))}return a}function nI(e){var t=[],n=!0,i=!1,r=void 0;try{for(var o,a=e.views.values()[Symbol.iterator]();!(n=(o=a.next()).done);n=!0){var s=o.value;s.query._queryParams.loadsAllData()||t.push(s)}}catch(e){i=!0,r=e}finally{try{n||null==a.return||a.return()}finally{if(i)throw r}}return t}function nE(e,t){var n=null,i=!0,r=!1,o=void 0;try{for(var a,s=e.views.values()[Symbol.iterator]();!(i=(a=s.next()).done);i=!0){var u=a.value;n=n||function(e,t){var n=t$(e.viewCache_);return n&&(e.query._queryParams.loadsAllData()||!eY(t)&&!n.getImmediateChild(eW(t)).isEmpty())?n.getChild(t):null}(u,t)}}catch(e){r=!0,o=e}finally{try{i||null==s.return||s.return()}finally{if(r)throw o}}return n}function nS(e,t){if(t._queryParams.loadsAllData())return nN(e);var n=t._queryIdentifier;return e.views.get(n)}function nP(e){return null!=nN(e)}function nN(e){var t=!0,n=!1,i=void 0;try{for(var r,o=e.views.values()[Symbol.iterator]();!(t=(r=o.next()).done);t=!0){var a=r.value;if(a.query._queryParams.loadsAllData())return a}}catch(e){n=!0,i=e}finally{try{t||null==o.return||o.return()}finally{if(n)throw i}}return null}var nx=1,nR=function e(t){(0,m._)(this,e),this.listenProvider_=t,this.syncPointTree_=new tX(null),this.pendingWriteTree_={visibleWrites:tJ.empty(),allWrites:[],lastWriteId:-1},this.tagToQueryMap=new Map,this.queryToTagMap=new Map};function nD(e,t,n,i,r){var o,a;return(o=e.pendingWriteTree_,a=r,(0,N.assert)(i>o.lastWriteId,"Stacking an older write on top of newer ones"),void 0===a&&(a=!0),o.allWrites.push({path:t,snap:n,writeId:i,visible:a}),a&&(o.visibleWrites=tZ(o.visibleWrites,t,n)),o.lastWriteId=i,r)?nW(e,new tB(tF(),t,n)):[]}function nA(e,t){var n=arguments.length>2&&void 0!==arguments[2]&&arguments[2],i=function(e,t){for(var n=0;n<e.allWrites.length;n++){var i=e.allWrites[n];if(i.writeId===t)return i}return null}(e.pendingWriteTree_,t);if(!function(e,t){var n,i=e.allWrites.findIndex(function(e){return e.writeId===t});(0,N.assert)(i>=0,"removeWrite called with nonexistent writeId.");var r=e.allWrites[i];e.allWrites.splice(i,1);for(var o=r.visible,a=!1,s=e.allWrites.length-1;o&&s>=0;){var u=e.allWrites[s];u.visible&&(s>=i&&function(e,t){if(e.snap)return e$(e.path,t);for(var n in e.children)if(e.children.hasOwnProperty(n)&&e$(ez(e.path,n),t))return!0;return!1}(u,r.path)?o=!1:e$(r.path,u.path)&&(a=!0)),s--}return!!o&&(a?((n=e).visibleWrites=t9(n.allWrites,t7,eO()),n.allWrites.length>0?n.lastWriteId=n.allWrites[n.allWrites.length-1].writeId:n.lastWriteId=-1):r.snap?e.visibleWrites=t1(e.visibleWrites,r.path):eu(r.children,function(t){e.visibleWrites=t1(e.visibleWrites,ez(r.path,t))}),!0)}(e.pendingWriteTree_,t))return[];var r=new tX(null);return null!=i.snap?r=r.set(eO(),!0):eu(i.children,function(e){r=r.set(new eL(e),!0)}),nW(e,new tW(i.path,r,n))}function nM(e,t,n){return nW(e,new tB(tL(),t,n))}function nq(e,t,n,i){var r=arguments.length>4&&void 0!==arguments[4]&&arguments[4],o=t._path,a=e.syncPointTree_.get(o),s=[];
2if(a&&("default"===t._queryIdentifier||null!=nS(a,t))){var u=function(e,t,n,i){var r=t._queryIdentifier,o=[],a=[],s=nP(e);if("default"===r){var u=!0,l=!1,h=void 0;try{for(var c,d=e.views.entries()[Symbol.iterator]();!(u=(c=d.next()).done);u=!0){var f=(0,T._)(c.value,2),v=f[0],p=f[1];a=a.concat(nm(p,n,i)),ng(p)&&(e.views.delete(v),p.query._queryParams.loadsAllData()||o.push(p.query))}}catch(e){l=!0,h=e}finally{try{u||null==d.return||d.return()}finally{if(l)throw h}}}else{var y=e.views.get(r);y&&(a=a.concat(nm(y,n,i)),ng(y)&&(e.views.delete(r),y.query._queryParams.loadsAllData()||o.push(y.query)))}return s&&!nP(e)&&o.push(new((0,N.assert)(_,"Reference.ts has not been loaded"),_)(t._repo,t._path)),{removed:o,events:a}}(a,t,n,i);0===a.views.size&&(e.syncPointTree_=e.syncPointTree_.remove(o));var l=u.removed;if(s=u.events,!r){var h=-1!==l.findIndex(function(e){return e._queryParams.loadsAllData()}),c=e.syncPointTree_.findOnPath(o,function(e,t){return nP(t)});if(h&&!c){var d=e.syncPointTree_.subtree(o);if(!d.isEmpty()){for(var f=d.fold(function(e,t,n){if(t&&nP(t))return[nN(t)];var i=[];return t&&(i=nI(t)),eu(n,function(e,t){i=i.concat(t)}),i}),v=0;v<f.length;++v){var p=f[v],y=p.query,g=nU(e,p);e.listenProvider_.startListening(nY(y),nB(e,y),g.hashFn,g.onComplete)}}}c||!(l.length>0)||i||(h?e.listenProvider_.stopListening(nY(t),null):l.forEach(function(t){var n=e.queryToTagMap.get(nj(t));e.listenProvider_.stopListening(nY(t),n)}))}for(var m=e,k=l,C=0;C<k.length;++C){var w=k[C];if(!w._queryParams.loadsAllData()){var b=nj(w),I=m.queryToTagMap.get(b);m.queryToTagMap.delete(b),m.tagToQueryMap.delete(I)}}}return s}function nF(e,t,n,i){var r=nV(e,i);if(null==r)return[];var o=nH(r),a=o.path,s=o.queryId,u=eK(a,t);return nz(e,a,new tB(tO(s),u,n))}function nL(e,t,n){var i,r,o,a,s,u=arguments.length>3&&void 0!==arguments[3]&&arguments[3],l=t._path,h=null,c=!1;e.syncPointTree_.foreachOnPath(l,function(e,t){var n=eK(e,l);h=h||nE(t,n),c=c||nP(t)});var d=e.syncPointTree_.get(l);d?(c=c||nP(d),h=h||nE(d,eO())):(d=new nw,e.syncPointTree_=e.syncPointTree_.set(l,d)),null!=h?s=!0:(s=!1,h=tc.EMPTY_NODE,e.syncPointTree_.subtree(l).foreachChild(function(e,t){var n=nE(t,eO());n&&(h=h.updateImmediateChild(e,n))}));var f=null!=nS(d,t);if(!f&&!t._queryParams.loadsAllData()){var _=nj(t);(0,N.assert)(!e.queryToTagMap.has(_),"View does not exist, but we have a tag");var v=nx++;e.queryToTagMap.set(_,v),e.tagToQueryMap.set(v,_)}var p=ns(l,e.pendingWriteTree_),y=(r=nb(i=d,t,p,h,s),i.views.has(t._queryIdentifier)||i.views.set(t._queryIdentifier,r),r.eventRegistrations_.push(n),o=r.viewCache_.eventCache,a=[],o.getNode().isLeafNode()||o.getNode().forEachChild(to,function(e,t){a.push(ty(e,t))}),o.isFullyInitialized()&&a.push(tp(o.getNode())),nC(r,a,o.getNode(),n));if(!f&&!c&&!u){var g=nS(d,t);y=y.concat(function(e,t,n){var i=t._path,r=nB(e,t),o=nU(e,n),a=e.listenProvider_.startListening(nY(t),r,o.hashFn,o.onComplete),s=e.syncPointTree_.subtree(i);if(r)(0,N.assert)(!nP(s.value),"If we're adding a query, it shouldn't be shadowed");else for(var u=s.fold(function(e,t,n){if(!eY(e)&&t&&nP(t))return[nN(t).query];var i=[];return t&&(i=i.concat(nI(t).map(function(e){return e.query}))),eu(n,function(e,t){i=i.concat(t)}),i}),l=0;l<u.length;++l){var h=u[l];e.listenProvider_.stopListening(nY(h),nB(e,h))}return a}(e,t,g))}return y}function nO(e,t,n){var i=e.pendingWriteTree_,r=e.syncPointTree_.findOnPath(t,function(e,n){var i=nE(n,eK(e,t));if(i)return i});return ne(i,t,r,n,!0)}function nW(e,t){var n;return function e(t,n,i,r){if(eY(t.path))return function e(t,n,i,r){var o=n.get(eO());null==i&&null!=o&&(i=nE(o,eO()));var a=[];return n.children.inorderTraversal(function(n,o){var s=i?i.getImmediateChild(n):null,u=na(r,n),l=t.operationForChild(n);l&&(a=a.concat(e(l,o,s,u)))}),o&&(a=a.concat(nT(o,t,r,i))),a}(t,n,i,r);var o=n.get(eO());null==i&&null!=o&&(i=nE(o,eO()));var a=[],s=eW(t.path),u=t.operationForChild(s),l=n.children.get(s);if(l&&u){var h=i?i.getImmediateChild(s):null,c=na(r,s);a=a.concat(e(u,l,h,c))}return o&&(a=a.concat(nT(o,t,r,i))),a}(t,e.syncPointTree_,null,(n=e.pendingWriteTree_,ns(eO(),n)))}function nU(e,t){var n=t.query,i=nB(e,n);return{hashFn:function(){return(t.viewCache_.serverCache.getNode()||tc.EMPTY_NODE).hash()},onComplete:function(t){if("ok"===t)if(i)return function(e,t,n){var i=nV(e,n);if(!i)return[];var r=nH(i),o=r.path,a=r.queryId,s=eK(o,t);return nz(e,o,new tU(tO(a),s))}(e,n._path,i);else{var r;return r=n._path,nW(e,new tU(tL(),r))}var o,a,s=(o="Unknown Error","too_big"===t?o="The data requested exceeds the maximum size that can be accessed with a single request.":"permission_denied"===t?o="Client doesn't have permission to access the desired data.":"unavailable"===t&&(o="The service is unavailable"),(a=Error(t+" at "+n._path.toString()+": "+o)).code=t.toUpperCase(),a);return nq(e,n,null,s)}}}function nB(e,t){var n=nj(t);return e.queryToTagMap.get(n)}function nj(e){return e._path.toString()+"$"+e._queryIdentifier}function nV(e,t){return e.tagToQueryMap.get(t)}function nH(e){var t=e.indexOf("$");return(0,N.assert)(-1!==t&&t<e.length-1,"Bad queryKey."),{queryId:e.substr(t+1),path:new eL(e.substr(0,t))}}function nz(e,t,n){var i=e.syncPointTree_.get(t);return(0,N.assert)(i,"Missing sync point for query tag that we're tracking"),nT(i,n,ns(t,e.pendingWriteTree_),null)}
2function nY(e){return e._queryParams.loadsAllData()&&!e._queryParams.isDefault()?new((0,N.assert)(v,"Reference.ts has not been loaded"),v)(e._repo,e._path):e}var nK=function(){function e(t){(0,m._)(this,e),this.node_=t}return(0,k._)(e,[{key:"getImmediateChild",value:function(t){return new e(this.node_.getImmediateChild(t))}},{key:"node",value:function(){return this.node_}}]),e}(),nQ=function(){function e(t,n){(0,m._)(this,e),this.syncTree_=t,this.path_=n}return(0,k._)(e,[{key:"getImmediateChild",value:function(t){var n=ez(this.path_,t);return new e(this.syncTree_,n)}},{key:"node",value:function(){return nO(this.syncTree_,this.path_)}}]),e}(),nG=function(e,t,n){return e&&(void 0===e?"undefined":(0,I._)(e))==="object"?((0,N.assert)(".sv"in e,"Unexpected leaf node or priority contents"),"string"==typeof e[".sv"])?n$(e[".sv"],t,n):"object"===(0,I._)(e[".sv"])?nX(e[".sv"],t):void(0,N.assert)(!1,"Unexpected server value: "+JSON.stringify(e,null,2)):e},n$=function(e,t,n){if("timestamp"===e)return n.timestamp;(0,N.assert)(!1,"Unexpected server value: "+e)},nX=function(e,t,n){e.hasOwnProperty("increment")||(0,N.assert)(!1,"Unexpected server value: "+JSON.stringify(e,null,2));var i=e.increment;"number"!=typeof i&&(0,N.assert)(!1,"Unexpected increment value: "+i);var r=t.node();if((0,N.assert)(null!=r,"Expected ChildrenNode.EMPTY_NODE for nulls"),!r.isLeafNode())return i;var o=r.getValue();return"number"!=typeof o?i:o+i},nJ=function(e,t,n,i){return n0(t,new nQ(n,e),i)},nZ=function(e,t,n){return n0(e,new nK(t),n)};function n0(e,t,n){var i,r=nG(e.getPriority().val(),t.getImmediateChild(".priority"),n);if(!e.isLeafNode())return i=e,r!==e.getPriority().val()&&(i=i.updatePriority(new tr(r))),e.forEachChild(to,function(e,r){var o=n0(r,t.getImmediateChild(e),n);o!==r&&(i=i.updateImmediateChild(e,o))}),i;var o=nG(e.getValue(),t,n);return o!==e.getValue()||r!==e.getPriority().val()?new tr(o,tf(r)):e}var n1=function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{children:{},childCount:0};(0,m._)(this,e),this.name=t,this.parent=n,this.node=i};function n2(e,t){for(var n=(0,w._)(t,eL)?t:new eL(t),i=e,r=eW(n);null!==r;){var o=(0,N.safeGet)(i.node.children,r)||{children:{},childCount:0};i=new n1(r,i,o),r=eW(n=eB(n))}return i}function n4(e){return e.node.value}function n3(e,t){e.node.value=t,function e(t){null!==t.parent&&function(t,n,i){var r=void 0===n4(i)&&!n5(i),o=(0,N.contains)(t.node.children,n);r&&o?(delete t.node.children[n],t.node.childCount--,e(t)):r||o||(t.node.children[n]=i.node,t.node.childCount++,e(t))}(t.parent,t.name,t)}(e)}function n5(e){return e.node.childCount>0}function n6(e,t){eu(e.node.children,function(n,i){t(new n1(n,e,i))})}function n8(e){return new eL(null===e.parent?e.name:n8(e.parent)+"/"+e.name)}var n7=/[\[\].#$\/\u0000-\u001F\u007F]/,n9=/[\[\].#$\u0000-\u001F\u007F]/,ie=function(e){return"string"==typeof e&&0!==e.length&&!n7.test(e)},it=function(e){return"string"==typeof e&&0!==e.length&&!n9.test(e)},ii=function(e){return null===e||"string"==typeof e||"number"==typeof e&&!Z(e)||e&&(void 0===e?"undefined":(0,I._)(e))==="object"&&(0,N.contains)(e,".sv")},ir=function(e,t,n,i){i&&void 0===t||io((0,N.errorPrefix)(e,"value"),t,n)},io=function(e,t,n){var i=(0,w._)(n,eL)?new eX(n,e):n;if(void 0===t)throw Error(e+"contains undefined "+eZ(i));if("function"==typeof t)throw Error(e+"contains a function "+eZ(i)+" with contents = "+t.toString());if(Z(t))throw Error(e+"contains "+t.toString()+" "+eZ(i));if("string"==typeof t&&t.length>3495253.3333333335&&(0,N.stringLength)(t)>0xa00000)throw Error(e+"contains a string greater than 10485760 utf8 bytes "+eZ(i)+" ('"+t.substring(0,50)+"...')");if(t&&(void 0===t?"undefined":(0,I._)(t))==="object"){var r=!1,o=!1;if(eu(t,function(t,n){var a;if(".value"===t)r=!0;else if(".priority"!==t&&".sv"!==t&&(o=!0,!ie(t)))throw Error(e+" contains an invalid key ("+t+") "+eZ(i)+'.  Keys must be non-empty strings and can\'t contain ".", "#", "$", "/", "[", or "]"');i.parts_.length>0&&(i.byteLength_+=1),i.parts_.push(t),i.byteLength_+=(0,N.stringLength)(t),eJ(i),io(e,n,i),a=i.parts_.pop(),i.byteLength_-=(0,N.stringLength)(a),i.parts_.length>0&&(i.byteLength_-=1)}),r&&o)throw Error(e+' contains ".value" child '+eZ(i)+" in addition to actual children.")}},ia=function(e,t){for(n=0;n<t.length;n++)for(var n,i=t[n],r=eV(i),o=0;o<r.length;o++)if(".priority"===r[o]&&o===r.length-1);
2else if(!ie(r[o]))throw Error(e+"contains an invalid key ("+r[o]+") in path "+i.toString()+'. Keys must be non-empty strings and can\'t contain ".", "#", "$", "/", "[", or "]"');t.sort(eQ);var a=null;for(n=0;n<t.length;n++){if(i=t[n],null!==a&&e$(a,i))throw Error(e+"contains a path "+a.toString()+" that is ancestor of another path "+i.toString());a=i}},is=function(e,t,n,i){if(!i||void 0!==t){var r=(0,N.errorPrefix)(e,"values");if(!(t&&(void 0===t?"undefined":(0,I._)(t))==="object")||Array.isArray(t))throw Error(r+" must be an object containing the children to replace.");var o=[];eu(t,function(e,t){var i=new eL(e);if(io(r,t,ez(n,i)),".priority"===ej(i)&&!ii(t))throw Error(r+"contains an invalid value for '"+i.toString()+"', which must be a valid Firebase priority (a string, finite number, server value, or null).");o.push(i)}),ia(r,o)}},iu=function(e,t,n){if(!n||void 0!==t){if(Z(t))throw Error((0,N.errorPrefix)(e,"priority")+"is "+t.toString()+", but must be a valid Firebase priority (a string, finite number, server value, or null).");if(!ii(t))throw Error((0,N.errorPrefix)(e,"priority")+"must be a valid Firebase priority (a string, finite number, server value, or null).")}},il=function(e,t,n,i){if((!i||void 0!==n)&&!ie(n))throw Error((0,N.errorPrefix)(e,t)+'was an invalid key = "'+n+'".  Firebase keys must be non-empty strings and can\'t contain ".", "#", "$", "/", "[", or "]").')},ih=function(e,t,n,i){if((!i||void 0!==n)&&!it(n))throw Error((0,N.errorPrefix)(e,t)+'was an invalid path = "'+n+'". Paths must be non-empty strings and can\'t contain ".", "#", "$", "[", or "]"')},ic=function(e,t,n,i){n&&(n=n.replace(/^\/*\.info(\/|$)/,"/")),ih(e,t,n,i)},id=function(e,t){if(".info"===eW(t))throw Error(e+" failed = Can't modify data under /.info/")},i_=function(e,t){var n,i=t.path.toString();if("string"!=typeof t.repoInfo.host||0===t.repoInfo.host.length||!ie(t.repoInfo.namespace)&&"localhost"!==t.repoInfo.host.split(":")[0]||0!==i.length&&((n=i)&&(n=n.replace(/^\/*\.info(\/|$)/,"/")),!it(n)))throw Error((0,N.errorPrefix)(e,"url")+'must be a valid firebase URL and the path can\'t contain ".", "#", "$", "[", or "]".')},iv=function e(){(0,m._)(this,e),this.eventLists_=[],this.recursionDepth_=0};function ip(e,t){for(var n=null,i=0;i<t.length;i++){var r=t[i],o=r.getPath();null===n||eG(o,n.path)||(e.eventLists_.push(n),n=null),null===n&&(n={events:[],path:o}),n.events.push(r)}n&&e.eventLists_.push(n)}function iy(e,t,n){ip(e,n),im(e,function(e){return eG(e,t)})}function ig(e,t,n){ip(e,n),im(e,function(e){return e$(e,t)||e$(t,e)})}function im(e,t){e.recursionDepth_++;for(var n=!0,i=0;i<e.eventLists_.length;i++){var r=e.eventLists_[i];r&&(t(r.path)?(function(e){for(var t=0;t<e.events.length;t++){var n=e.events[t];if(null!==n){e.events[t]=null;var i=n.getEventRunner();H&&K("event: "+n.toString()),ed(i)}}}(e.eventLists_[i]),e.eventLists_[i]=null):n=!1)}n&&(e.eventLists_=[]),e.recursionDepth_--}var ik="repo_interrupt",iC=function(){function e(t,n,i,r){(0,m._)(this,e),this.repoInfo_=t,this.forceRestClient_=n,this.authTokenProvider_=i,this.appCheckProvider_=r,this.dataUpdateCount=0,this.statsListener_=null,this.eventQueue_=new iv,this.nextWriteId_=1,this.interceptServerDataCallback_=null,this.onDisconnect_=tR(),this.transactionQueueTree_=new n1,this.persistentConnection_=null,this.key=this.repoInfo_.toURLString()}return(0,k._)(e,[{key:"toString",value:function(){return(this.repoInfo_.secure?"https://":"http://")+this.repoInfo_.host}}]),e}();function iw(e){var t=e.infoData_.getNode(new eL(".info/serverTimeOffset")).val()||0;return new Date().getTime()+t}function iT(e){var t;return(t=t={timestamp:iw(e)}).timestamp=t.timestamp||new Date().getTime(),t}function ib(e,t,n,i,r){e.dataUpdateCount++;var o=new eL(t);n=e.interceptServerDataCallback_?e.interceptServerDataCallback_(t,n):n;var a=[];if(r)if(i){var s=(0,N.map)(n,function(e){return tf(e)});a=function(e,t,n,i){var r=nV(e,i);if(!r)return[];var o=nH(r),a=o.path,s=o.queryId,u=eK(a,t),l=tX.fromObject(n);return nz(e,a,new tj(tO(s),u,l))}(e.serverSyncTree_,o,s,r)}else{var u=tf(n);a=nF(e.serverSyncTree_,o,u,r)}else if(i){var l,h,c=(0,N.map)(n,function(e){return tf(e)});l=e.serverSyncTree_,h=tX.fromObject(c),a=nW(l,new tj(tL(),o,h))}else{var d=tf(n);a=nM(e.serverSyncTree_,o,d)}var f=o;a.length>0&&(f=iF(e,o)),ig(e.eventQueue_,f,a)}function iI(e,t){var n,i,r,o;iE(e,"connected",t),!1===t&&(iD(n=e,"onDisconnectEvents"),i=iT(n),r=tR(),tA(n.onDisconnect_,eO(),function(e,t){var o=nJ(e,t,n.serverSyncTree_,i);tD(r,e,o)}),o=[],tA(r,eO(),function(e,t){o=o.concat(nM(n.serverSyncTree_,e,t));var i=iU(n,e);iF(n,i)}),n.onDisconnect_=tR(),ig(n.eventQueue_,eO(),o))}function iE(e,t,n){var i=new eL("/.info/"+t),r=tf(n);e.infoData_.updateSnapshot(i,r);var o=nM(e.infoSyncTree_,i,r);ig(e.eventQueue_,i,o)}function iS(e){return e.nextWriteId_++}function iP(e,t,n,i,r){iD(e,"set",{path:t.toString(),value:n,priority:i});var o=iT(e),a=tf(n,i),s=nZ(a,nO(e.serverSyncTree_,t),o),u=iS(e),l=nD(e.serverSyncTree_,t,s,u,!0);ip(e.eventQueue_,l),e.server_.put(t.toString(),a.val(!0),function(n,i){var o="ok"===n;o||X("set at "+t+" failed: "+n);var a=nA(e.serverSyncTree_,u,!o);ig(e.eventQueue_,t,a),iA(e,r,n,i)});var h=iU(e,t);iF(e,h),ig(e.eventQueue_,h,[])}function iN(e,t,n,i){var r=tf(n);e.server_.onDisconnectPut(t.toString(),r.val(!0),function(n,o){"ok"===n&&tD(e.onDisconnect_,t,r),iA(e,i,n,o)})}function ix(e,t,n){var i;i=".info"===eW(t._path)?nq(e.infoSyncTree_,t,n):nq(e.serverSyncTree_,t,n),iy(e.eventQueue_,t._path,i)}function iR(e){e.persistentConnection_&&e.persistentConnection_.interrupt(ik)}function iD(e){for(var t=arguments.length,n=Array(t>1?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];var r="";e.persistentConnection_&&(r=e.persistentConnection_.id+":"),K.apply(void 0,[r].concat((0,b._)(n)))}function iA(e,t,n,i){t&&ed(function(){if("ok"===n)t(null);else{var e=(n||"error").toUpperCase(),r=e;i&&(r+=": "+i);var o=Error(r);o.code=e,t(o)}})}function iM(e,t,n){return nO(e.serverSyncTree_,t,n)||tc.EMPTY_NODE}function iq(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e.transactionQueueTree_;if(t||iW(e,t),n4(t)){var n=iO(e,t);(0,N.assert)(n.length>0,"Sending zero length transaction queue"),n.every(function(e){return 0===e.status})&&function(e,t,n){for(var i=iM(e,t,n.map(function(e){return e.currentWriteId})),r=i,o=i.hash(),a=0;a<n.length;a++){var s=n[a];(0,N.assert)(0===s.status,"tryToSendTransactionQueue_: items in queue should all be run."),s.status=1,s.retryCount++;
2var u=eK(t,s.path);r=r.updateChild(u,s.currentOutputSnapshotRaw)}var l=r.val(!0);e.server_.put(t.toString(),l,function(i){iD(e,"transaction put response",{path:t.toString(),status:i});var r=[];if("ok"===i){for(var o=function(t){n[t].status=2,r=r.concat(nA(e.serverSyncTree_,n[t].currentWriteId)),n[t].onComplete&&a.push(function(){return n[t].onComplete(null,!0,n[t].currentOutputSnapshotResolved)}),n[t].unwatcher()},a=[],s=0;s<n.length;s++)o(s);iW(e,n2(e.transactionQueueTree_,t)),iq(e,e.transactionQueueTree_),ig(e.eventQueue_,t,r);for(var u=0;u<a.length;u++)ed(a[u])}else{if("datastale"===i)for(var l=0;l<n.length;l++)3===n[l].status?n[l].status=4:n[l].status=0;else{X("transaction at "+t.toString()+" failed: "+i);for(var h=0;h<n.length;h++)n[h].status=4,n[h].abortReason=i}iF(e,t)}},o)}(e,n8(t),n)}else n5(t)&&n6(t,function(t){iq(e,t)})}function iF(e,t){var n=iL(e,t),i=n8(n),r=iO(e,n);return function(e,t,n){var i=function(i){var s=t[i],u=eK(n,s.path),l=!1,h=void 0;if((0,N.assert)(null!==u,"rerunTransactionsUnderNode_: relativePath should not be null."),4===s.status)l=!0,h=s.abortReason,o=o.concat(nA(e.serverSyncTree_,s.currentWriteId,!0));else if(0===s.status)if(s.retryCount>=25)l=!0,h="maxretry",o=o.concat(nA(e.serverSyncTree_,s.currentWriteId,!0));else{var c=iM(e,s.path,a);s.currentInputSnapshot=c;var d=t[i].update(c.val());if(void 0!==d){io("transaction failed: Data returned ",d,s.path);var f=tf(d);(void 0===d?"undefined":(0,I._)(d))==="object"&&null!=d&&(0,N.contains)(d,".priority")||(f=f.updatePriority(c.getPriority()));var _=s.currentWriteId,v=nZ(f,c,iT(e));s.currentOutputSnapshotRaw=f,s.currentOutputSnapshotResolved=v,s.currentWriteId=iS(e),a.splice(a.indexOf(_),1),o=(o=o.concat(nD(e.serverSyncTree_,s.path,v,s.currentWriteId,s.applyLocally))).concat(nA(e.serverSyncTree_,_,!0))}else l=!0,h="nodata",o=o.concat(nA(e.serverSyncTree_,s.currentWriteId,!0))}ig(e.eventQueue_,n,o),o=[],l&&(t[i].status=2,setTimeout(t[i].unwatcher,Math.floor(0)),t[i].onComplete&&("nodata"===h?r.push(function(){return t[i].onComplete(null,!1,t[i].currentInputSnapshot)}):r.push(function(){return t[i].onComplete(Error(h),!1,null)})))};if(0!==t.length){for(var r=[],o=[],a=t.filter(function(e){return 0===e.status}).map(function(e){return e.currentWriteId}),s=0;s<t.length;s++)i(s);iW(e,e.transactionQueueTree_);for(var u=0;u<r.length;u++)ed(r[u]);iq(e,e.transactionQueueTree_)}}(e,r,i),i}function iL(e,t){var n,i=e.transactionQueueTree_;for(n=eW(t);null!==n&&void 0===n4(i);)i=n2(i,n),n=eW(t=eB(t));return i}function iO(e,t){var n=[];return function e(t,n,i){var r=n4(n);if(r)for(var o=0;o<r.length;o++)i.push(r[o]);n6(n,function(n){e(t,n,i)})}(e,t,n),n.sort(function(e,t){return e.order-t.order}),n}function iW(e,t){var n=n4(t);if(n){for(var i=0,r=0;r<n.length;r++)2!==n[r].status&&(n[i]=n[r],i++);n.length=i,n3(t,n.length>0?n:void 0)}n6(t,function(t){iW(e,t)})}function iU(e,t){var n=n8(iL(e,t)),i=n2(e.transactionQueueTree_,t);return!function(e,t){for(var n=e.parent;null!==n;){if(t(n))return!0;n=n.parent}}(i,function(t){iB(e,t)}),iB(e,i),!function e(t,n,i,r){i&&!r&&n(t),n6(t,function(t){e(t,n,!0,r)}),i&&r&&n(t)}(i,function(t){iB(e,t)}),n}function iB(e,t){var n=n4(t);if(n){for(var i=[],r=[],o=-1,a=0;a<n.length;a++)3===n[a].status||(1===n[a].status?((0,N.assert)(o===a-1,"All SENT items should be at beginning of queue."),o=a,n[a].status=3,n[a].abortReason="set"):((0,N.assert)(0===n[a].status,"Unexpected transaction status in abort"),n[a].unwatcher(),r=r.concat(nA(e.serverSyncTree_,n[a].currentWriteId,!0)),n[a].onComplete&&i.push(n[a].onComplete.bind(null,Error("set"),!1,null))));-1===o?n3(t,void 0):n.length=o+1,ig(e.eventQueue_,n8(t),r);for(var s=0;s<i.length;s++)ed(i[s])}}var ij=function(e,t){var n=iV(e),i=n.namespace;"firebase.com"===n.domain&&$(n.host+" is no longer supported. Please use <YOUR FIREBASE>.firebaseio.com instead"),i&&"undefined"!==i||"localhost"===n.domain||$("Cannot parse Firebase url. Please use https://<YOUR FIREBASE>.firebaseio.com"),n.secure||J();var r="ws"===n.scheme||"wss"===n.scheme;return{repoInfo:new ek(n.host,n.secure,i,r,t,"",i!==n.subdomain),path:new eL(n.pathString)}},iV=function(e){var t="",n="",i="",r="",o="",a=!0,s="https",u=443;if("string"==typeof e){var l=e.indexOf("//");l>=0&&(s=e.substring(0,l-1),e=e.substring(l+2));var h=e.indexOf("/");-1===h&&(h=e.length);var c=e.indexOf("?");-1===c&&(c=e.length),t=e.substring(0,Math.min(h,c)),h<c&&(r=function(e){for(var t="",n=e.split("/"),i=0;i<n.length;i++)if(n[i].length>0){var r=n[i];try{r=decodeURIComponent(r.replace(/\+/g," "))}catch(e){}t+="/"+r}return t}(e.substring(h,c)));var d=function(e){var t={};"?"===e.charAt(0)&&(e=e.substring(1));var n=!0,i=!1,r=void 0;try{for(var o,a=e.split("&")[Symbol.iterator]();!(n=(o=a.next()).done);
2n=!0){var s=o.value;if(0!==s.length){var u=s.split("=");2===u.length?t[decodeURIComponent(u[0])]=decodeURIComponent(u[1]):X("Invalid query segment '".concat(s,"' in query '").concat(e,"'"))}}}catch(e){i=!0,r=e}finally{try{n||null==a.return||a.return()}finally{if(i)throw r}}return t}(e.substring(Math.min(e.length,c)));(l=t.indexOf(":"))>=0?(a="https"===s||"wss"===s,u=parseInt(t.substring(l+1),10)):l=t.length;var f=t.slice(0,l);if("localhost"===f.toLowerCase())n="localhost";else if(f.split(".").length<=2)n=f;else{var _=t.indexOf(".");i=t.substring(0,_).toLowerCase(),n=t.substring(_+1),o=i}"ns"in d&&(o=d.ns)}return{host:t,port:u,domain:n,subdomain:i,secure:a,scheme:s,pathString:r,namespace:o}},iH="-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz",iz=(i=0,r=[],function(e){var t,n=e===i;i=e;var o=Array(8);for(t=7;t>=0;t--)o[t]=iH.charAt(e%64),e=Math.floor(e/64);(0,N.assert)(0===e,"Cannot push at time == 0");var a=o.join("");if(n){for(t=11;t>=0&&63===r[t];t--)r[t]=0;r[t]++}else for(t=0;t<12;t++)r[t]=Math.floor(64*Math.random());for(t=0;t<12;t++)a+=iH.charAt(r[t]);return(0,N.assert)(20===a.length,"nextPushId: Length should be 20."),a}),iY=function(){function e(t,n,i,r){(0,m._)(this,e),this.eventType=t,this.eventRegistration=n,this.snapshot=i,this.prevName=r}return(0,k._)(e,[{key:"getPath",value:function(){var e=this.snapshot.ref;return"value"===this.eventType?e._path:e.parent._path}},{key:"getEventType",value:function(){return this.eventType}},{key:"getEventRunner",value:function(){return this.eventRegistration.getEventRunner(this)}},{key:"toString",value:function(){return this.getPath().toString()+":"+this.eventType+":"+(0,N.stringify)(this.snapshot.exportVal())}}]),e}(),iK=function(){function e(t,n,i){(0,m._)(this,e),this.eventRegistration=t,this.error=n,this.path=i}return(0,k._)(e,[{key:"getPath",value:function(){return this.path}},{key:"getEventType",value:function(){return"cancel"}},{key:"getEventRunner",value:function(){return this.eventRegistration.getEventRunner(this)}},{key:"toString",value:function(){return this.path.toString()+":cancel"}}]),e}(),iQ=function(){function e(t,n){(0,m._)(this,e),this.snapshotCallback=t,this.cancelCallback=n}return(0,k._)(e,[{key:"onValue",value:function(e,t){this.snapshotCallback.call(null,e,t)}},{key:"onCancel",value:function(e){return(0,N.assert)(this.hasCancelCallback,"Raising a cancel event on a listener with no cancel callback"),this.cancelCallback.call(null,e)}},{key:"hasCancelCallback",get:function(){return!!this.cancelCallback}},{key:"matches",value:function(e){return this.snapshotCallback===e.snapshotCallback||void 0!==this.snapshotCallback.userCallback&&this.snapshotCallback.userCallback===e.snapshotCallback.userCallback&&this.snapshotCallback.context===e.snapshotCallback.context}}]),e}(),iG=function(){function e(t,n){(0,m._)(this,e),this._repo=t,this._path=n}return(0,k._)(e,[{key:"cancel",value:function(){var e,t,n,i=new N.Deferred;return e=this._repo,t=this._path,n=i.wrapCallback(function(){}),e.server_.onDisconnectCancel(t.toString(),function(i,r){"ok"===i&&function e(t,n){if(eY(n))return t.value=null,t.children.clear(),!0;if(null!==t.value)if(t.value.isLeafNode())return!1;else{var i=t.value;return t.value=null,i.forEachChild(to,function(e,n){tD(t,new eL(e),n)}),e(t,n)}if(!(t.children.size>0))return!0;var r=eW(n);return n=eB(n),t.children.has(r)&&e(t.children.get(r),n)&&t.children.delete(r),0===t.children.size}(e.onDisconnect_,t),iA(e,n,i,r)}),i.promise}},{key:"remove",value:function(){id("OnDisconnect.remove",this._path);var e=new N.Deferred;return iN(this._repo,this._path,null,e.wrapCallback(function(){})),e.promise}},{key:"set",value:function(e){id("OnDisconnect.set",this._path),ir("OnDisconnect.set",e,this._path,!1);var t=new N.Deferred;return iN(this._repo,this._path,e,t.wrapCallback(function(){})),t.promise}},{key:"setWithPriority",value:function(e,t){id("OnDisconnect.setWithPriority",this._path),ir("OnDisconnect.setWithPriority",e,this._path,!1),iu("OnDisconnect.setWithPriority",t,!1);var n,i,r,o,a=new N.Deferred;return n=this._repo,i=this._path,r=a.wrapCallback(function(){}),o=tf(e,t),n.server_.onDisconnectPut(i.toString(),o.val(!0),function(e,t){"ok"===e&&tD(n.onDisconnect_,i,o),iA(n,r,e,t)}),a.promise}},{key:"update",value:function(e){id("OnDisconnect.update",this._path),is("OnDisconnect.update",e,this._path,!1);var t=new N.Deferred;return!function(e,t,n,i){if((0,N.isEmpty)(n)){K("onDisconnect().update() called with empty data.  Don't do anything."),iA(e,i,"ok",void 0);return}e.server_.onDisconnectMerge(t.toString(),n,function(r,o){"ok"===r&&eu(n,function(n,i){var r=tf(i);tD(e.onDisconnect_,ez(t,n),r)}),iA(e,i,r,o)})}(this._repo,this._path,e,t.wrapCallback(function(){})),t.promise}}]),e}(),i$=function(){function e(t,n,i,r){(0,m._)(this,e),this._repo=t,this._path=n,this._queryParams=i,this._orderByCalled=r}return(0,k._)(e,[{key:"key",get:function(){return eY(this._path)?null:ej(this._path)}},{key:"ref",get:function(){return new i0(this._repo,this._path)}},{key:"_queryIdentifier",get:function(){var e=ea(tP(this._queryParams));return"{}"===e?"default":e}},{key:"_queryObject",get:function(){return tP(this._queryParams)}},{key:"isEqual",value:function(t){if(t=(0,N.getModularInstance)(t),!(0,w._)(t,e))return!1;var n=this._repo===t._repo,i=eG(this._path,t._path),r=this._queryIdentifier===t._queryIdentifier;return n&&i&&r}},{key:"toJSON",value:function(){return this.toString()}},{key:"toString",value:function(){return this._repo.toString()+function(e){for(var t="",n=e.pieceNum_;n<e.pieces_.length;n++)""!==e.pieces_[n]&&(t+="/"+encodeURIComponent(String(e.pieces_[n])));return t||"/"}(this._path)}}]),e}();function iX(e,t){if(!0===e._orderByCalled)throw Error(t+": You can't combine multiple orderBy calls.")}function iJ(e){var t=null,n=null;if(e.hasStart()&&(t=e.getIndexStartValue()),e.hasEnd()&&(n=e.getIndexEndValue()),e.getIndex()===e5){var i="Query: When ordering by key, you may only pass one argument to startAt(), endAt(), or equalTo().",r="Query: When ordering by key, the argument passed to startAt(), startAfter(), endAt(), endBefore(), or equalTo() must be a string.";if(e.hasStart()){if(e.getIndexStartName()!==et)throw Error(i);if("string"!=typeof t)throw Error(r)}if(e.hasEnd()){if(e.getIndexEndName()!==en)throw Error(i);if("string"!=typeof n)throw Error(r)}}else if(e.getIndex()===to){if(null!=t&&!ii(t)||null!=n&&!ii(n))throw Error("Query: When ordering by priority, the first argument passed to startAt(), startAfter() endAt(), endBefore(), or equalTo() must be a valid priority value (null, a number, or a string).")}else if((0,N.assert)((0,w._)(e.getIndex(),t_)||e.getIndex()===tv,"unknown index type."),null!=t&&(void 0===t?"undefined":(0,I._)(t))==="object"||null!=n&&(void 0===n?"undefined":(0,I._)(n))==="object")throw Error("Query: First argument passed to startAt(), startAfter(), endAt(), endBefore(), or equalTo() cannot be an object.")}function iZ(e){if(e.hasStart()&&e.hasEnd()&&e.hasLimit()&&!e.hasAnchoredLimit())throw Error("Query: Can't combine startAt(), startAfter(), endAt(), endBefore(), and limit(). Use limitToFirst() or limitToLast() instead.")}var i0=function(e){function t(e,n){return(0,m._)(this,t),(0,g._)(this,t,[e,n,new tT,!1])}return(0,C._)(t,e),(0,k._)(t,[{key:"parent",get:function(){var e=eH(this._path);return null===e?null:new t(this._repo,e)}},{key:"root",get:function(){for(var e=this;null!==e.parent;)e=e.parent;return e}}]),t}(i$),i1=function(){function e(t,n,i){(0,m._)(this,e),this._node=t,this.ref=n,this._index=i}return(0,k._)(e,[{key:"priority",get:function(){return this._node.getPriority().val()}},{key:"key",get:function(){return this.ref.key}},{key:"size",get:function(){return this._node.numChildren()}},{key:"child",value:function(t){var n=new eL(t),i=i4(this.ref,t);return new e(this._node.getChild(n),i,to)}},{key:"exists",value:function(){return!this._node.isEmpty()}},{key:"exportVal",value:function(){return this._node.val(!0)}}
2,{key:"forEach",value:function(t){var n=this;return!this._node.isLeafNode()&&!!this._node.forEachChild(this._index,function(i,r){return t(new e(r,i4(n.ref,i),to))})}},{key:"hasChild",value:function(e){var t=new eL(e);return!this._node.getChild(t).isEmpty()}},{key:"hasChildren",value:function(){return!this._node.isLeafNode()&&!this._node.isEmpty()}},{key:"toJSON",value:function(){return this.exportVal()}},{key:"val",value:function(){return this._node.val()}}]),e}();function i2(e,t){return(e=(0,N.getModularInstance)(e))._checkNotDeleted("ref"),void 0!==t?i4(e._root,t):e._root}function i4(e,t){return null===eW((e=(0,N.getModularInstance)(e))._path)?ic("child","path",t,!1):ih("child","path",t,!1),new i0(e._repo,ez(e._path,t))}function i3(e,t){id("set",(e=(0,N.getModularInstance)(e))._path),ir("set",t,e._path,!1);var n=new N.Deferred;return iP(e._repo,e._path,t,null,n.wrapCallback(function(){})),n.promise}var i5=function(){function e(t){(0,m._)(this,e),this.callbackContext=t}return(0,k._)(e,[{key:"respondsTo",value:function(e){return"value"===e}},{key:"createEvent",value:function(e,t){var n=t._queryParams.getIndex();return new iY("value",this,new i1(e.snapshotNode,new i0(t._repo,t._path),n))}},{key:"getEventRunner",value:function(e){var t=this;return"cancel"===e.getEventType()?function(){return t.callbackContext.onCancel(e.error)}:function(){return t.callbackContext.onValue(e.snapshot,null)}}},{key:"createCancelEvent",value:function(e,t){return this.callbackContext.hasCancelCallback?new iK(this,e,t):null}},{key:"matches",value:function(t){return!!(0,w._)(t,e)&&(!t.callbackContext||!this.callbackContext||t.callbackContext.matches(this.callbackContext))}},{key:"hasAnyCallback",value:function(){return null!==this.callbackContext}}]),e}(),i6=function(){function e(t,n){(0,m._)(this,e),this.eventType=t,this.callbackContext=n}return(0,k._)(e,[{key:"respondsTo",value:function(e){var t="children_added"===e?"child_added":e;return t="children_removed"===t?"child_removed":t,this.eventType===t}},{key:"createCancelEvent",value:function(e,t){return this.callbackContext.hasCancelCallback?new iK(this,e,t):null}},{key:"createEvent",value:function(e,t){(0,N.assert)(null!=e.childName,"Child events should have a childName.");var n=i4(new i0(t._repo,t._path),e.childName),i=t._queryParams.getIndex();return new iY(e.type,this,new i1(e.snapshotNode,n,i),e.prevName)}},{key:"getEventRunner",value:function(e){var t=this;return"cancel"===e.getEventType()?function(){return t.callbackContext.onCancel(e.error)}:function(){return t.callbackContext.onValue(e.snapshot,e.prevName)}}},{key:"matches",value:function(t){return!!(0,w._)(t,e)&&this.eventType===t.eventType&&(!this.callbackContext||!t.callbackContext||this.callbackContext.matches(t.callbackContext))}},{key:"hasAnyCallback",value:function(){return!!this.callbackContext}}]),e}();function i8(e,t,n,i,r){if((void 0===i?"undefined":(0,I._)(i))==="object"&&(s=void 0,r=i),"function"==typeof i&&(s=i),r&&r.onlyOnce){var o,a,s,u=n,l=function(t,n){ix(e._repo,e,c),u(t,n)};l.userCallback=n.userCallback,l.context=n.context,n=l}var h=new iQ(n,s||void 0),c="value"===t?new i5(h):new i6(t,h);return o=e._repo,a=".info"===eW(e._path)?nL(o.infoSyncTree_,e,c):nL(o.serverSyncTree_,e,c),iy(o.eventQueue_,e._path,a),function(){return ix(e._repo,e,c)}}function i7(e,t,n,i){return i8(e,"value",t,n,i)}var i9=function e(){(0,m._)(this,e)},re=function(e){function t(e,n){var i;return(0,m._)(this,t),(i=(0,g._)(this,t))._value=e,i._key=n,i.type="endAt",i}return(0,C._)(t,e),(0,k._)(t,[{key:"_apply",value:function(e){ir("endAt",this._value,e._path,!0);var t=tI(e._queryParams,this._value,this._key);if(iZ(t),iJ(t),e._queryParams.hasEnd())throw Error("endAt: Starting point was already set (by another call to endAt, endBefore or equalTo).");return new i$(e._repo,e._path,t,e._orderByCalled)}}]),t}(i9),rt=function(e){function t(e,n){var i;return(0,m._)(this,t),(i=(0,g._)(this,t))._value=e,i._key=n,i.type="endBefore",i}return(0,C._)(t,e),(0,k._)(t,[{key:"_apply",value:function(e){ir("endBefore",this._value,e._path,!1);var t,n,i,r,o=(t=e._queryParams,n=this._value,i=this._key,(r=t.index_===e5||i?tI(t,n,i):tI(t,n,et)).endBeforeSet_=!0,r);if(iZ(o),iJ(o),e._queryParams.hasEnd())throw Error("endBefore: Starting point was already set 
2(by another call to endAt, endBefore or equalTo).");return new i$(e._repo,e._path,o,e._orderByCalled)}}]),t}(i9),rn=function(e){function t(e,n){var i;return(0,m._)(this,t),(i=(0,g._)(this,t))._value=e,i._key=n,i.type="startAt",i}return(0,C._)(t,e),(0,k._)(t,[{key:"_apply",value:function(e){ir("startAt",this._value,e._path,!0);var t=tb(e._queryParams,this._value,this._key);if(iZ(t),iJ(t),e._queryParams.hasStart())throw Error("startAt: Starting point was already set (by another call to startAt, startBefore or equalTo).");return new i$(e._repo,e._path,t,e._orderByCalled)}}]),t}(i9),ri=function(e){function t(e,n){var i;return(0,m._)(this,t),(i=(0,g._)(this,t))._value=e,i._key=n,i.type="startAfter",i}return(0,C._)(t,e),(0,k._)(t,[{key:"_apply",value:function(e){ir("startAfter",this._value,e._path,!1);var t,n,i,r,o=(t=e._queryParams,n=this._value,i=this._key,(r=t.index_===e5||i?tb(t,n,i):tb(t,n,en)).startAfterSet_=!0,r);if(iZ(o),iJ(o),e._queryParams.hasStart())throw Error("startAfter: Starting point was already set (by another call to startAt, startAfter, or equalTo).");return new i$(e._repo,e._path,o,e._orderByCalled)}}]),t}(i9),rr=function(e){function t(e){var n;return(0,m._)(this,t),(n=(0,g._)(this,t))._limit=e,n.type="limitToFirst",n}return(0,C._)(t,e),(0,k._)(t,[{key:"_apply",value:function(e){var t,n,i;if(e._queryParams.hasLimit())throw Error("limitToFirst: Limit was already set (by another call to limitToFirst or limitToLast).");return new i$(e._repo,e._path,(t=e._queryParams,n=this._limit,(i=t.copy()).limitSet_=!0,i.limit_=n,i.viewFrom_="l",i),e._orderByCalled)}}]),t}(i9),ro=function(e){function t(e){var n;return(0,m._)(this,t),(n=(0,g._)(this,t))._limit=e,n.type="limitToLast",n}return(0,C._)(t,e),(0,k._)(t,[{key:"_apply",value:function(e){var t,n,i;if(e._queryParams.hasLimit())throw Error("limitToLast: Limit was already set (by another call to limitToFirst or limitToLast).");return new i$(e._repo,e._path,(t=e._queryParams,n=this._limit,(i=t.copy()).limitSet_=!0,i.limit_=n,i.viewFrom_="r",i),e._orderByCalled)}}]),t}(i9),ra=function(e){function t(e){var n;return(0,m._)(this,t),(n=(0,g._)(this,t))._path=e,n.type="orderByChild",n}return(0,C._)(t,e),(0,k._)(t,[{key:"_apply",value:function(e){iX(e,"orderByChild");var t=new eL(this._path);if(eY(t))throw Error("orderByChild: cannot pass in empty path. Use orderByValue() instead.");var n=new t_(t),i=tE(e._queryParams,n);return iJ(i),new i$(e._repo,e._path,i,!0)}}]),t}(i9),rs=function(e){function t(){var e;return(0,m._)(this,t),e=(0,g._)(this,t,arguments),e.type="orderByKey",e}return(0,C._)(t,e),(0,k._)(t,[{key:"_apply",value:function(e){iX(e,"orderByKey");var t=tE(e._queryParams,e5);return iJ(t),new i$(e._repo,e._path,t,!0)}}]),t}(i9),ru=function(e){function t(){var e;return(0,m._)(this,t),e=(0,g._)(this,t,arguments),e.type="orderByPriority",e}return(0,C._)(t,e),(0,k._)(t,[{key:"_apply",value:function(e){iX(e,"orderByPriority");var t=tE(e._queryParams,to);return iJ(t),new i$(e._repo,e._path,t,!0)}}]),t}(i9),rl=function(e){function t(){var e;return(0,m._)(this,t),e=(0,g._)(this,t,arguments),e.type="orderByValue",e}return(0,C._)(t,e),(0,k._)(t,[{key:"_apply",value:function(e){iX(e,"orderByValue");var t=tE(e._queryParams,tv);return iJ(t),new i$(e._repo,e._path,t,!0)}}]),t}(i9),rh=function(e){function t(e,n){var i;return(0,m._)(this,t),(i=(0,g._)(this,t))._value=e,i._key=n,i.type="equalTo",i}return(0,C._)(t,e),(0,k._)(t,[{key:"_apply",value:function(e){if(ir("equalTo",this._value,e._path,!1),e._queryParams.hasStart())throw Error("equalTo: Starting point was already set (by another call to startAt/startAfter or equalTo).");if(e._queryParams.hasEnd())throw Error("equalTo: Ending point was already set (by another call to endAt/endBefore or equalTo).");return new re(this._value,this._key)._apply(new rn(this._value,this._key)._apply(e))}}]),t}(i9);(0,N.assert)(!_,"__referenceConstructor has already been defined"),_=i0,(0,N.assert)(!v,"__referenceConstructor has already been defined"),v=i0;var rc={},rd=!1;function rf(e,t,n,i,r){var o,a,s,u,l,h,c,d=i||e.options.databaseURL;
2void 0===d&&(e.options.projectId||$("Can't determine Firebase Database URL. Be sure to include  a Project ID when calling firebase.initializeApp()."),K("Using default host for project ",e.options.projectId),d="".concat(e.options.projectId,"-default-rtdb.firebaseio.com"));var f=ij(d,r),_=f.repoInfo,v=void 0;void 0!==p.default&&p.default.env&&(v=p.default.env.FIREBASE_DATABASE_EMULATOR_HOST),v?(c=!0,_=(f=ij(d="http://".concat(v,"?ns=").concat(_.namespace),r)).repoInfo):c=!f.repoInfo.secure;var y=r&&c?new ep(ep.OWNER):new ev(e.name,e.options,t);return i_("Invalid Firebase Database URL",f),eY(f.path)||$("Database URL must point to the root of a Firebase Database (not including a child path)."),new r_((o=_,a=e,s=y,u=new e_(e.name,n),(l=rc[a.name])||(l={},rc[a.name]=l),(h=l[o.toURLString()])&&$("Database initialized multiple times. Please make sure the format of the database URL matches with each database() call."),h=new iC(o,rd,s,u),l[o.toURLString()]=h,h),e)}var r_=function(){function e(t,n){(0,m._)(this,e),this._repoInternal=t,this.app=n,this.type="database",this._instanceStarted=!1}return(0,k._)(e,[{key:"_repo",get:function(){return this._instanceStarted||(!function(e,t,n){var i,r;if(e.stats_=eI(e.repoInfo_),e.forceRestClient_||(("u"<typeof window?"undefined":(0,I._)(window))==="object"&&window.navigator&&window.navigator.userAgent||"").search(/googlebot|google webmaster tools|bingbot|yahoo! slurp|baiduspider|yandexbot|duckduckbot/i)>=0)e.server_=new tN(e.repoInfo_,function(t,n,i,r){ib(e,t,n,i,r)},e.authTokenProvider_,e.appCheckProvider_),setTimeout(function(){return iI(e,!0)},0);else{if(null!=n){if((void 0===n?"undefined":(0,I._)(n))!=="object")throw Error("Only objects are supported for option databaseAuthVariableOverride");try{(0,N.stringify)(n)}catch(e){throw Error("Invalid authOverride provided: "+e)}}e.persistentConnection_=new e1(e.repoInfo_,t,function(t,n,i,r){ib(e,t,n,i,r)},function(t){iI(e,t)},function(t){var n;n=e,eu(t,function(e,t){iE(n,e,t)})},e.authTokenProvider_,e.appCheckProvider_,n),e.server_=e.persistentConnection_}e.authTokenProvider_.addTokenChangeListener(function(t){e.server_.refreshAuthToken(t)}),e.appCheckProvider_.addTokenChangeListener(function(t){e.server_.refreshAppCheckToken(t.token)}),i=e.repoInfo_,eb[r=i.toString()]||(eb[r]=function(){return new tq(e.stats_,e.server_)}()),e.statsReporter_=eb[r],e.infoData_=new tx,e.infoSyncTree_=new nR({startListening:function(t,n,i,r){var o=[],a=e.infoData_.getNode(t._path);return a.isEmpty()||(o=nM(e.infoSyncTree_,t._path,a),setTimeout(function(){r("ok")},0)),o},stopListening:function(){}}),iE(e,"connected",!1),e.serverSyncTree_=new nR({startListening:function(t,n,i,r){return e.server_.listen(t,i,n,function(n,i){var o=r(n,i);ig(e.eventQueue_,t._path,o)}),[]},stopListening:function(t,n){e.server_.unlisten(t,n)}})}(this._repoInternal,this.app.options.appId,this.app.options.databaseAuthVariableOverride),this._instanceStarted=!0),this._repoInternal}},{key:"_root",get:function(){return this._rootInternal||(this._rootInternal=new i0(this._repo,eO())),this._rootInternal}},{key:"_delete",value:function(){if(null!==this._rootInternal){var e,t,n;e=this._repo,(n=rc[t=this.app.name])&&n[e.key]===e||$("Database ".concat(t,"(").concat(e.repoInfo_,") has already been deleted.")),iR(e),delete n[e.key],this._repoInternal=null,this._rootInternal=null}return Promise.resolve()}},{key:"_checkNotDeleted",value:function(e){null===this._rootInternal&&$("Cannot call "+e+" on a deleted database.")}}]),e}();function rv(){eD.IS_TRANSPORT_INITIALIZED&&X("Transport has already been initialized. Please call this function before calling ref or setting up a listener")}function rp(e,t,n){var i,r=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};(e=(0,N.getModularInstance)(e))._checkNotDeleted("useEmulator"),e._instanceStarted&&$("Cannot call useEmulator() after instance has already been initialized.");var o=e._repoInternal,a=void 0;o.repoInfo_.nodeAdmin?(r.mockUserToken&&$('mockUserToken is not supported by the Admin SDK. For client access with mock users, please use the "firebase" package instead of "firebase-admin".'),a=new ep(ep.OWNER)):r.mockUserToken&&(a=new ep("string"==typeof r.mockUserToken?r.mockUserToken:(0,N.createMockUserToken)(r.mockUserToken,e.app.options.projectId))),i=a,o.repoInfo_=new ek("".concat(t,":").concat(n),!1,o.repoInfo_.namespace,o.repoInfo_.webSocketOnly,o.repoInfo_.nodeAdmin,o.repoInfo_.persistenceKey,o.repoInfo_.includeNamespaceInQueryParams,!0),i&&(o.authTokenProvider_=i)}var ry={".sv":"timestamp"},rg=function(){function e(t,n){(0,m._)(this,e),this.committed=t,this.snapshot=n}return(0,k._)(e,[{key:"toJSON",value:function(){return{committed:this.committed,snapshot:this.snapshot.toJSON()}}}]),e}();e1.prototype.simpleListen=function(e,t){this.sendRequest("q",{p:e},t)},e1.prototype.echo=function(e,t){this.sendRequest("echo",{d:e},t)},M(S.SDK_VERSION),(0,S._registerComponent)(new P.Component("database",function(e,t){var n=t.instanceIdentifier;return rf(e.getProvider("app").getImmediate(),e.getProvider("auth-internal"),e.getProvider("app-check-internal"),n)},"PUBLIC").setMultipleInstances(!0)),(0,S.registerVersion)(R,D,void 0),(0,S.registerVersion)(R,D,"esm2017"),e.s(["DataSnapshot",0,i1,"Database",0,r_,"OnDisconnect",0,iG,"QueryConstraint",0,i9,"TransactionResult",0,rg,"_QueryImpl",0,i$,"_QueryParams",0,tT,"_ReferenceImpl",0,i0,"_TEST_ACCESS_forceRestClient",0,function(e){rd=e},"_TEST_ACCESS_hijackHash",0,function(e){var t=e1.prototype.put;return e1.prototype.put=function(n,i,r,o){void 0!==o&&(o=e()),t.call(this,n,i,r,o)},function(){e1.prototype.put=t}},"_initStandalone",0,function(e){var t,n=e.app,i=e.url,r=e.version,o=e.customAuthImpl,a=e.customAppCheckImpl,s=e.nodeAdmin;M(r);var u=new P.ComponentContainer("database-standalone"),l=new P.Provider("auth-internal",u);return a&&(t=new P.Provider("app-check-internal",u)).setComponent(new P.Component("app-check-internal",function(){return a},"PRIVATE")),l.setComponent(new P.Component("auth-internal",function(){return o},"PRIVATE")),rf(n,l,t,i,void 0!==s&&s)},"_repoManagerDatabaseFromApp",0,rf,"_setSDKVersion",0,M,"_validatePathString",0,ih,"_validateWritablePath",0,id,"child",0,i4,"connectDatabaseEmulator",0,rp,"enableLogging",0,function(e,t){Y(e,t)},"endAt",0,function(e,t){return il("endAt","key",t,!0),new re(e,t)},"endBefore",0,function(e,t){return il("endBefore","key",t,!0),new rt(e,t)},"equalTo",0,function(e,t){return il("equalTo","key",t,!0),new rh(e,t)},"forceLongPolling",0,function(){rv(),eR.forceDisallow(),eP.forceAllow()},"forceWebSockets",0,function(){rv(),eP.forceDisallow()},"get",0,function(e){e=(0,N.getModularInstance)(e);var t,n,i,r,o,a,s,u,l,h,c,d,f=new i5(new iQ(function(){}));
2return(h=e._repo,c=e,null!=(t=h.serverSyncTree_,r=(n=c)._path,o=null,t.syncPointTree_.foreachOnPath(r,function(e,t){var n=eK(e,r);o=o||nE(t,n)}),(a=t.syncPointTree_.get(r))?o=o||nE(a,eO()):(a=new nw,t.syncPointTree_=t.syncPointTree_.set(r,a)),u=(s=null!=o)?new tV(o,!0,!1):null,l=(i=t.pendingWriteTree_,ns(n._path,i)),d=tG(nb(a,n,l,s?u.getNode():tc.EMPTY_NODE,s).viewCache_))?Promise.resolve(d):h.server_.get(c).then(function(e){var t,n=tf(e).withIndex(c._queryParams.getIndex());if(nL(h.serverSyncTree_,c,f,!0),c._queryParams.loadsAllData())t=nM(h.serverSyncTree_,c._path,n);else{var i=nB(h.serverSyncTree_,c);t=nF(h.serverSyncTree_,c._path,n,i)}return ig(h.eventQueue_,c._path,t),nq(h.serverSyncTree_,c,f,null,!0),n},function(e){return iD(h,"get for query "+(0,N.stringify)(c)+" failed: "+e),Promise.reject(Error(e))})).then(function(t){return new i1(t,new i0(e._repo,e._path),e._queryParams.getIndex())})},"getDatabase",0,function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:(0,S.getApp)(),t=arguments.length>1?arguments[1]:void 0,n=(0,S._getProvider)(e,"database").getImmediate({identifier:t});if(!n._instanceStarted){var i=(0,N.getDefaultEmulatorHostnameAndPort)("database");i&&rp.apply(void 0,[n].concat((0,b._)(i)))}return n},"goOffline",0,function(e){(e=(0,N.getModularInstance)(e))._checkNotDeleted("goOffline"),iR(e._repo)},"goOnline",0,function(e){var t;(e=(0,N.getModularInstance)(e))._checkNotDeleted("goOnline"),(t=e._repo).persistentConnection_&&t.persistentConnection_.resume(ik)},"increment",0,function(e){return{".sv":{increment:e}}},"limitToFirst",0,function(e){if("number"!=typeof e||Math.floor(e)!==e||e<=0)throw Error("limitToFirst: First argument must be a positive integer.");return new rr(e)},"limitToLast",0,function(e){if("number"!=typeof e||Math.floor(e)!==e||e<=0)throw Error("limitToLast: First argument must be a positive integer.");return new ro(e)},"off",0,function(e,t,n){var i=null,r=n?new iQ(n):null;"value"===t?i=new i5(r):t&&(i=new i6(t,r)),ix(e._repo,e,i)},"onChildAdded",0,function(e,t,n,i){return i8(e,"child_added",t,n,i)},"onChildChanged",0,function(e,t,n,i){return i8(e,"child_changed",t,n,i)},"onChildMoved",0,function(e,t,n,i){return i8(e,"child_moved",t,n,i)},"onChildRemoved",0,function(e,t,n,i){return i8(e,"child_removed",t,n,i)},"onDisconnect",0,function(e){return new iG((e=(0,N.getModularInstance)(e))._repo,e._path)},"onValue",0,i7,"orderByChild",0,function(e){if("$key"===e)throw Error('orderByChild: "$key" is invalid.  Use orderByKey() instead.');if("$priority"===e)throw Error('orderByChild: "$priority" is invalid.  Use orderByPriority() instead.');if("$value"===e)throw Error('orderByChild: "$value" is invalid.  Use orderByValue() instead.');return ih("orderByChild","path",e,!1),new ra(e)},"orderByKey",0,function(){return new rs},"orderByPriority",0,function(){return new ru},"orderByValue",0,function(){return new rl},"push",0,function(e,t){id("push",(e=(0,N.getModularInstance)(e))._path),ir("push",t,e._path,!0);var n,i=iz(iw(e._repo)),r=i4(e,i),o=i4(e,i);return r.then=(n=null!=t?i3(o,t).then(function(){return o}):Promise.resolve(o)).then.bind(n),r.catch=n.then.bind(n,void 0),r},"query",0,function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),i=1;i<t;i++)n[i-1]=arguments[i];var r=(0,N.getModularInstance)(e),o=!0,a=!1,s=void 0;try{for(var u,l=n[Symbol.iterator]();!(o=(u=l.next()).done);o=!0)r=u.value._apply(r)}catch(e){a=!0,s=e}finally{try{o||null==l.return||l.return()}finally{if(a)throw s}}return r},"ref",0,i2,"refFromURL",0,function(e,t){(e=(0,N.getModularInstance)(e))._checkNotDeleted("refFromURL");var n=ij(t,e._repo.repoInfo_.nodeAdmin);i_("refFromURL",n);var i=n.repoInfo;return e._repo.repoInfo_.isCustomHost()||i.host===e._repo.repoInfo_.host||$("refFromURL: Host name does not match the current database: (found "+i.host+" but expected "+e._repo.repoInfo_.host+")"),i2(e,n.path.toString())},"remove",0,function(e){return id("remove",e._path),i3(e,null)},"runTransaction",0,function(e,t,n){if(id("Reference.transaction",(e=(0,N.getModularInstance)(e))._path),".length"===e.key||".keys"===e.key)throw"Reference.transaction failed: "+e.key+" is a read-only object.";var i,r=null==(i=null==n?void 0:n.applyLocally)||i,o=new N.Deferred,a=i7(e,function(){});return!function(e,t,n,i,r,o){iD(e,"transaction on "+t);var a={path:t,update:n,onComplete:i,status:null,order:B(),applyLocally:o,retryCount:0,unwatcher:r,abortReason:null,currentWriteId:null,currentInputSnapshot:null,currentOutputSnapshotRaw:null,currentOutputSnapshotResolved:null},s=iM(e,t,void 0);a.currentInputSnapshot=s;var u=a.update(s.val());if(void 0===u)a.unwatcher(),a.currentOutputSnapshotRaw=null,a.currentOutputSnapshotResolved=null,a.onComplete&&a.onComplete(null,!1,a.currentInputSnapshot);else{io("transaction failed: Data returned ",u,a.path),a.status=0;var l,h=n2(e.transactionQueueTree_,t),c=n4(h)||[];c.push(a),n3(h,c),(void 0===u?"undefined":(0,I._)(u))==="object"&&null!==u&&(0,N.contains)(u,".priority")?(l=(0,N.safeGet)(u,".priority"),(0,N.assert)(ii(l),"Invalid priority returned by transaction. Priority must be a valid string, finite number, server value, or null.")):l=(nO(e.serverSyncTree_,t)||tc.EMPTY_NODE).getPriority().val();var d=iT(e),f=tf(u,l),_=nZ(f,s,d);
2a.currentOutputSnapshotRaw=f,a.currentOutputSnapshotResolved=_,a.currentWriteId=iS(e);var v=nD(e.serverSyncTree_,t,_,a.currentWriteId,a.applyLocally);ig(e.eventQueue_,t,v),iq(e,e.transactionQueueTree_)}}(e._repo,e._path,t,function(t,n,i){var r=null;t?o.reject(t):(r=new i1(i,new i0(e._repo,e._path),to),o.resolve(new rg(n,r)))},a,r),o.promise},"serverTimestamp",0,function(){return ry},"set",0,i3,"setPriority",0,function(e,t){id("setPriority",(e=(0,N.getModularInstance)(e))._path),iu("setPriority",t,!1);var n=new N.Deferred;return iP(e._repo,ez(e._path,".priority"),t,null,n.wrapCallback(function(){})),n.promise},"setWithPriority",0,function(e,t,n){if(id("setWithPriority",e._path),ir("setWithPriority",t,e._path,!1),iu("setWithPriority",n,!1),".length"===e.key||".keys"===e.key)throw"setWithPriority failed: "+e.key+" is a read-only object.";var i=new N.Deferred;return iP(e._repo,e._path,t,n,i.wrapCallback(function(){})),i.promise},"startAfter",0,function(e,t){return il("startAfter","key",t,!0),new ri(e,t)},"startAt",0,function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,t=arguments.length>1?arguments[1]:void 0;return il("startAt","key",t,!0),new rn(e,t)},"update",0,function(e,t){is("update",t,e._path,!1);var n=new N.Deferred;return!function(e,t,n,i){iD(e,"update",{path:t.toString(),value:n});var r=!0,o=iT(e),a={};if(eu(n,function(n,i){r=!1,a[n]=nJ(ez(t,n),tf(i),e.serverSyncTree_,o)}),r)K("update() called with empty data.  Don't do anything."),iA(e,i,"ok",void 0);else{var s,u,l,h=iS(e),c=(s=e.serverSyncTree_,u=s.pendingWriteTree_,(0,N.assert)(h>u.lastWriteId,"Stacking an older merge on top of newer ones"),u.allWrites.push({path:t,children:a,writeId:h,visible:!0}),u.visibleWrites=t0(u.visibleWrites,t,a),u.lastWriteId=h,l=tX.fromObject(a),nW(s,new tj(tF(),t,l)));ip(e.eventQueue_,c),e.server_.merge(t.toString(),n,function(n,r){var o="ok"===n;o||X("update at "+t+" failed: "+n);var a=nA(e.serverSyncTree_,h,!o),s=a.length>0?iF(e,t):t;ig(e.eventQueue_,s,a),iA(e,i,n,r)}),eu(n,function(n){var i=iU(e,ez(t,n));iF(e,i)}),ig(e.eventQueue_,t,[])}}(e._repo,e._path,t,n.wrapCallback(function(){})),n.promise}],476686),e.s([],401465)}]);
3
4//# debugId=39ce4ffd-5d53-6cb8-548b-f1d7a414be8c

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.