PageSourceSearch

https://welovedevs.com/_next/static/chunks/457b8330-f6494dfc6c141cb8.js

js welovedevs.com collected 2026-10-03 21:38:27 UTC 157,515 bytes, 752 lines download raw bytes

1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[7481],{43363:function(e,t,n){let i,r,s,o,l,a,h,u,c,d,_;n.d(t,{Bt:function(){return iQ},IO:function(){return iY},N8:function(){return iB},U2:function(){return iW},VF:function(){return iO},Vx:function(){return iL},iH:function(){return iF},jM:function(){return iH},t8:function(){return iA}});var p,f,g=n(95723),m=n(66589),y=n(53232),v=n(20698),C=n(25566);let w="@firebase/database",T="0.13.6",I="";/**
2 * @license
3 * Copyright 2017 Google LLC
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *   http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */class b{constructor(e){this.domStorage_=e,this.prefix_="firebase:"}set(e,t){null==t?this.domStorage_.removeItem(this.prefixedName_(e)):this.domStorage_.setItem(this.prefixedName_(e),(0,y.Pz)(t))}get(e){let t=this.domStorage_.getItem(this.prefixedName_(e));return null==t?null:(0,y.cI)(t)}remove(e){this.domStorage_.removeItem(this.prefixedName_(e))}prefixedName_(e){return this.prefix_+e}toString(){return this.domStorage_.toString()}}/**
17 * @license
18 * Copyright 2017 Google LLC
19 *
20 * Licensed under the Apache License, Version 2.0 (the "License");
21 * you may not use this file except in compliance with the License.
22 * You may obtain a copy of the License at
23 *
24 *   http://www.apache.org/licenses/LICENSE-2.0
25 *
26 * Unless required by applicable law or agreed to in writing, software
27 * distributed under the License is distributed on an "AS IS" BASIS,
28 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 * See the License for the specific language governing permissions and
30 * limitations under the License.
31 */class k{constructor(){this.cache_={},this.isInMemoryStorage=!0}set(e,t){null==t?delete this.cache_[e]:this.cache_[e]=t}get(e){return(0,y.r3)(this.cache_,e)?this.cache_[e]:null}remove(e){delete this.cache_[e]}}/**
32 * @license
33 * Copyright 2017 Google LLC
34 *
35 * Licensed under the Apache License, Version 2.0 (the "License");
36 * you may not use this file except in compliance with the License.
37 * You may obtain a copy of the License at
38 *
39 *   http://www.apache.org/licenses/LICENSE-2.0
40 *
41 * Unless required by applicable law or agreed to in writing, software
42 * distributed under the License is distributed on an "AS IS" BASIS,
43 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
44 * See the License for the specific language governing permissions and
45 * limitations under the License.
46 */let E=function(e){try{if("undefined"!=typeof window&&void 0!==window[e]){let t=window[e];return t.setItem("firebase:sentinel","cache"),t.removeItem("firebase:sentinel"),new b(t)}}catch(e){}return new k},P=E("localStorage"),N=E("sessionStorage"),S=new v.Yd("@firebase/database"),x=(_=1,function(){return _++}),R=function(e){let t=(0,y.dS)(e),n=new y.gQ;n.update(t);let i=n.digest();return y.US.encodeByteArray(i)},D=function(...e){let t="";for(let n=0;n<e.length;n++){let i=e[n];Array.isArray(i)||i&&"object"==typeof i&&"number"==typeof i.length?t+=D.apply(null,i):"object"==typeof i?t+=(0,y.Pz)(i):t+=i,t+=" "}return t},M=null,F=!0,q=function(e,t){(0,y.hu)(!t||!0===e||!1===e,"Can't turn on custom loggers persistently."),!0===e?(S.logLevel=v.in.VERBOSE,M=S.log.bind(S),t&&N.set("logging_enabled",!0)):"function"==typeof e?M=e:(M=null,N.remove("logging_enabled"))},O=function(...e){if(!0===F&&(F=!1,null===M&&!0===N.get("logging_enabled")&&q(!0)),M){let t=D.apply(null,e);M(t)}},A=function(e){return function(...t){O(e,...t)}},L=function(...e){let t="FIREBASE INTERNAL ERROR: "+D(...e);S.error(t)},W=function(...e){let t=`FIREBASE FATAL ERROR: ${D(...e)}`;throw S.error(t),Error(t)},U=function(...e){let t="FIREBASE WARNING: "+D(...e);S.warn(t)},z=function(){"undefined"!=typeof window&&window.location&&window.location.protocol&&-1!==window.location.protocol.indexOf("https:")&&U("Insecure Firebase access from a secure page. Please use https in calls to new Firebase().")},H=function(e){return"number"==typeof e&&(e!=e||e===Number.POSITIVE_INFINITY||e===Number.NEGATIVE_INFINITY)},Y=function(e){if((0,y.Yr)()||"complete"===document.readyState)e();else{let t=!1,n=function(){if(!document.body){setTimeout(n,Math.floor(10));return}t||(t=!0,e())};document.addEventListener?(document.addEventListener("DOMContentLoaded",n,!1),window.addEventListener("load",n,!1)):document.attachEvent&&(document.attachEvent("onreadystatechange",()=>{"complete"===document.readyState&&n()}),window.attachEvent("onload",n))}},j="[MIN_NAME]",V="[MAX_NAME]",B=function(e,t){if(e===t)return 0;if(e===j||t===V)return -1;if(t===j||e===V)return 1;{let n=ee(e),i=ee(t);return null!==n?null!==i?n-i==0?e.length-t.length:n-i:-1:null!==i?1:e<t?-1:1}},K=function(e,t){return e===t?0:e<t?-1:1},Q=function(e,t){if(t&&e in t)return t[e];throw Error("Missing required key ("+e+") in object: "+(0,y.Pz)(t))},G=function(e){if("object"!=typeof e||null===e)return(0,y.Pz)(e);let t=[];for(let n in e)t.push(n);
46t.sort();let n="{";for(let i=0;i<t.length;i++)0!==i&&(n+=","),n+=(0,y.Pz)(t[i])+":"+G(e[t[i]]);return n+"}"},$=function(e,t){let n=e.length;if(n<=t)return[e];let i=[];for(let 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 X(e,t){for(let n in e)e.hasOwnProperty(n)&&t(n,e[n])}let J=function(e){let t,n,i,r,s;(0,y.hu)(!H(e),"Invalid JSON number"),0===e?(n=0,i=0,t=1/e==-1/0?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)-4503599627370496)):(n=0,i=Math.round(e/5e-324)));let o=[];for(s=52;s;s-=1)o.push(i%2?1:0),i=Math.floor(i/2);for(s=11;s;s-=1)o.push(n%2?1:0),n=Math.floor(n/2);o.push(t?1:0),o.reverse();let l=o.join(""),a="";for(s=0;s<64;s+=8){let e=parseInt(l.substr(s,8),2).toString(16);1===e.length&&(e="0"+e),a+=e}return a.toLowerCase()},Z=RegExp("^-?(0*)\\d{1,10}$"),ee=function(e){if(Z.test(e)){let t=Number(e);if(t>=-2147483648&&t<=2147483647)return t}return null},et=function(e){try{e()}catch(e){setTimeout(()=>{throw U("Exception was thrown by user callback.",e.stack||""),e},Math.floor(0))}},en=function(e,t){let n=setTimeout(e,t);return"number"==typeof n&&"undefined"!=typeof Deno&&Deno.unrefTimer?Deno.unrefTimer(n):"object"==typeof n&&n.unref&&n.unref(),n};/**
47 * @license
48 * Copyright 2021 Google LLC
49 *
50 * Licensed under the Apache License, Version 2.0 (the "License");
51 * you may not use this file except in compliance with the License.
52 * You may obtain a copy of the License at
53 *
54 *   http://www.apache.org/licenses/LICENSE-2.0
55 *
56 * Unless required by applicable law or agreed to in writing, software
57 * distributed under the License is distributed on an "AS IS" BASIS,
58 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
59 * See the License for the specific language governing permissions and
60 * limitations under the License.
61 */class ei{constructor(e,t){this.appName_=e,this.appCheckProvider=t,this.appCheck=null==t?void 0:t.getImmediate({optional:!0}),this.appCheck||null==t||t.get().then(e=>this.appCheck=e)}getToken(e){return this.appCheck?this.appCheck.getToken(e):new Promise((t,n)=>{setTimeout(()=>{this.appCheck?this.getToken(e).then(t,n):t(null)},0)})}addTokenChangeListener(e){var t;null===(t=this.appCheckProvider)||void 0===t||t.get().then(t=>t.addTokenListener(e))}notifyForInvalidToken(){U(`Provided AppCheck credentials for the app named "${this.appName_}" are invalid. This usually indicates your app was not initialized correctly.`)}}/**
62 * @license
63 * Copyright 2017 Google LLC
64 *
65 * Licensed under the Apache License, Version 2.0 (the "License");
66 * you may not use this file except in compliance with the License.
67 * You may obtain a copy of the License at
68 *
69 *   http://www.apache.org/licenses/LICENSE-2.0
70 *
71 * Unless required by applicable law or agreed to in writing, software
72 * distributed under the License is distributed on an "AS IS" BASIS,
73 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
74 * See the License for the specific language governing permissions and
75 * limitations under the License.
76 */class er{constructor(e,t,n){this.appName_=e,this.firebaseOptions_=t,this.authProvider_=n,this.auth_=null,this.auth_=n.getImmediate({optional:!0}),this.auth_||n.onInit(e=>this.auth_=e)}getToken(e){return this.auth_?this.auth_.getToken(e).catch(e=>e&&"auth/token-not-initialized"===e.code?(O("Got auth/token-not-initialized error.  Treating as null token."),null):Promise.reject(e)):new Promise((t,n)=>{setTimeout(()=>{this.auth_?this.getToken(e).then(t,n):t(null)},0)})}addTokenChangeListener(e){this.auth_?this.auth_.addAuthTokenListener(e):this.authProvider_.get().then(t=>t.addAuthTokenListener(e))}removeTokenChangeListener(e){this.authProvider_.get().then(t=>t.removeAuthTokenListener(e))}notifyForInvalidToken(){let 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/.',U(e)}}class es{constructor(e){this.accessToken=e}getToken(e){return Promise.resolve({accessToken:this.accessToken})}addTokenChangeListener(e){e(this.accessToken)}removeTokenChangeListener(e){}notifyForInvalidToken(){}}es.OWNER="owner";let eo=/(console\.firebase|firebase-console-\w+\.corp|firebase\.corp)\.google\.com/,el="websocket",ea="long_polling";/**
77 * @license
78 * Copyright 2017 Google LLC
79 *
80 * Licensed under the Apache License, Version 2.0 (the "License");
81 * you may not use this file except in compliance with the License.
82 * You may obtain a copy of the License at
83 *
84 *   http://www.apache.org/licenses/LICENSE-2.0
85 *
86 * Unless required by applicable law or agreed to in writing, software
87 * distributed under the License is distributed on an "AS IS" BASIS,
88 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
89 * See the License for the specific language governing permissions and
90 * limitations under the License.
91 */class eh{constructor(e,t,n,i,r=!1,s="",o=!1){this.secure=t,this.namespace=n,this.webSocketOnly=i,this.nodeAdmin=r,this.persistenceKey=s,this.includeNamespaceInQueryParams=o,this._host=e.toLowerCase(),this._domain=this._host.substr(this._host.indexOf(".")+1),this.internalHost=P.get("host:"+e)||this._host}isCacheableHost(){return"s-"===this.internalHost.substr(0,2)}isCustomHost(){return"firebaseio.com"!==this._domain&&"firebaseio-demo.com"!==this._domain}get host(){return this._host}set host(e){e!==this.internalHost&&(this.internalHost=e,this.isCacheableHost()&&P.set("host:"+this._host,this.internalHost))}toString(){let e=this.toURLString();return this.persistenceKey&&(e+="<"+this.persistenceKey+">"),e}toURLString(){let e=this.secure?"https://":"http://",t=this.includeNamespaceInQueryParams?`?ns=${this.namespace}`:"";return`${e}${this.host}/${t}`}}function eu(e,t,n){let i;if((0,y.hu)("string"==typeof t,"typeof type must == string"),(0,y.hu)("object"==typeof n,"typeof params must == object"),t===el)i=(e.secure?"wss://":"ws://")+e.internalHost+"/.ws?";else if(t===ea)i=(e.secure?"https://":"http://")+e.internalHost+"/.lp?";else throw Error("Unknown connection type: "+t);(e.host!==e.internalHost||e.isCustomHost()||e.includeNamespaceInQueryParams)&&(n.ns=e.namespace);let r=[];return X(n,(e,t)=>{r.push(e+"="+t)}),i+r.join("&")}/**
92 * @license
93 * Copyright 2017 Google LLC
94 *
95 * Licensed under the Apache License, Version 2.0 (the "License");
96 * you may not use this file except in compliance with the License.
97 * You may obtain a copy of the License at
98 *
99 *   http://www.apache.org/licenses/LICENSE-2.0
100 *
101 * Unless required by applicable law or agreed to in writing, software
102 * distributed under the License is distributed on an "AS IS" BASIS,
103 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
104 * See the License for the specific language governing permissions and
105 * limitations under the License.
106 */class ec{constructor(){this.counters_={}}incrementCounter(e,t=1){(0,y.r3)(this.counters_,e)||(this.counters_[e]=0),this.counters_[e]+=t}get(){return(0,y.p$)(this.counters_)}}/**
107 * @license
108 * Copyright 2017 Google LLC
109 *
110 * Licensed under the Apache License, Version 2.0 (the "License");
111 * you may not use this file except in compliance with the License.
112 * You may obtain a copy of the License at
113 *
114 *   http://www.apache.org/licenses/LICENSE-2.0
115 *
116 * Unless required by applicable law or agreed to in writing, software
117 * distributed under the License is distributed on an "AS IS" BASIS,
118 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
119 * See the License for the specific language governing permissions and
120 * limitations under the License.
121 */let ed={},e_={};function ep(e){let t=e.toString();return ed[t]||(ed[t]=new ec),ed[t]}/**
122 * @license
123 * Copyright 2017 Google LLC
124 *
125 * Licensed under the Apache License, Version 2.0 (the "License");
126 * you may not use this file except in compliance with the License.
127 * You may obtain a copy of the License at
128 *
129 *   http://www.apache.org/licenses/LICENSE-2.0
130 *
131 * Unless required by applicable law or agreed to in writing, software
132 * distributed under the License is distributed on an "AS IS" BASIS,
133 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
134 * See the License for the specific language governing permissions and
135 * limitations under the License.
136 */class ef{constructor(e){this.onMessage_=e,this.pendingResponses=[],this.currentResponseNum=0,this.closeAfterResponse=-1,this.onClose=null}closeAfter(e,t){this.closeAfterResponse=e,this.onClose=t,this.closeAfterResponse<this.currentResponseNum&&(this.onClose(),this.onClose=null)}handleResponse(e,t){for(this.pendingResponses[e]=t;this.pendingResponses[this.currentResponseNum];){let e=this.pendingResponses[this.currentResponseNum];delete this.pendingResponses[this.currentResponseNum];for(let t=0;t<e.length;++t)e[t]&&et(()=>{this.onMessage_(e[t])});if(this.currentResponseNum===this.closeAfterResponse){this.onClose&&(this.onClose(),this.onClose=null);break}this.currentResponseNum++}}}/**
137 * @license
138 * Copyright 2017 Google LLC
139 *
140 * Licensed under the Apache License, Version 2.0 (the "License");
141 * you may not use this file except in compliance with the License.
142 * You may obtain a copy of the License at
143 *
144 *   http://www.apache.org/licenses/LICENSE-2.0
145 *
146 * Unless required by applicable law or agreed to in writing, software
147 * distributed under the License is distributed on an "AS IS" BASIS,
148 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
149 * See the License for the specific language governing permissions and
150 * limitations under the License.
151 */let eg="start";class em{constructor(e,t,n,i,r,s,o){this.connId=e,this.repoInfo=t,this.applicationId=n,this.appCheckToken=i,this.authToken=r,this.transportSessionId=s,this.lastSessionId=o,this.bytesSent=0,this.bytesReceived=0,this.everConnected_=!1,this.log_=A(e),this.stats_=ep(t),this.urlFn=e=>(this.appCheckToken&&(e.ac=this.appCheckToken),eu(t,ea,e))}open(e,t){this.curSegmentNum=0,this.onDisconnect_=t,this.myPacketOrderer=new ef(e),this.isClosed_=!1,this.connectTimeoutTimer_=setTimeout(()=>{this.log_("Timed out trying to connect."),this.onClosed_(),this.connectTimeoutTimer_=null},Math.floor(3e4)),Y(()=>{if(this.isClosed_)return;this.scriptTagHolder=new ey((...e)=>{let[t,n,i,r,s]=e;if(this.incrementIncomingBytes_(e),this.scriptTagHolder){if(this.connectTimeoutTimer_&&(clearTimeout(this.connectTimeoutTimer_),this.connectTimeoutTimer_=null),this.everConnected_=!0,t===eg)this.id=n,this.password=i;else if("close"===t)n?(this.scriptTagHolder.sendNewPolls=!1,this.myPacketOrderer.closeAfter(n,()=>{this.onClosed_()})):this.onClosed_();else throw Error("Unrecognized command received: "+t)}},(...e)=>{let[t,n]=e;this.incrementIncomingBytes_(e),this.myPacketOrderer.handleResponse(t,n)},()=>{this.onClosed_()},this.urlFn);let e={};e[eg]="t",e.ser=Math.floor(1e8*Math.random()),this.scriptTagHolder.uniqueCallbackIdentifier&&(e.cb=this.scriptTagHolder.uniqueCallbackIdentifier),e.v="5",this.transportSessionId&&(e.s=this.transportSessionId),this.lastSessionId&&(e.ls=this.lastSessionId),this.applicationId&&(e.p=this.applicationId),this.appCheckToken&&(e.ac=this.appCheckToken),"undefined"!=typeof location&&location.hostname&&eo.test(location.hostname)&&(e.r="f");let t=this.urlFn(e);this.log_("Connecting via long-poll to "+t),this.scriptTagHolder.addTag(t,()=>{})})}start(){this.scriptTagHolder.startLongPoll(this.id,this.password),this.addDisconnectPingFrame(this.id,this.password)}static forceAllow(){em.forceAllow_=!0}static forceDisallow(){em.forceDisallow_=!0}static isAvailable(){return!(0,y.Yr)()&&(!!em.forceAllow_||!em.forceDisallow_&&"undefined"!=typeof document&&null!=document.createElement&&!("object"==typeof window&&window.chrome&&window.chrome.extension&&!/^chrome/.test(window.location.href))&&!("object"==typeof Windows&&"object"==typeof Windows.UI))}markConnectionHealthy(){}shutdown_(){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)}onClosed_(){!this.isClosed_&&(this.log_("Longpoll is closing itself"),this.shutdown_(),this.onDisconnect_&&(this.onDisconnect_(this.everConnected_),this.onDisconnect_=null))}close(){this.isClosed_||(this.log_("Longpoll is being closed."),this.shutdown_())}send(e){let t=(0,y.Pz)(e);this.bytesSent+=t.length,this.stats_.incrementCounter("bytes_sent",t.length);let n=$((0,y.h$)(t),1840);for(let e=0;e<n.length;e++)this.scriptTagHolder.enqueueSegment(this.curSegmentNum,n.length,n[e]),this.curSegmentNum++}addDisconnectPingFrame(e,t){if((0,y.Yr)())return;this.myDisconnFrame=document.createElement("iframe");let 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)}incrementIncomingBytes_(e){let t=(0,y.Pz)(e).length;this.bytesReceived+=t,this.stats_.incrementCounter("bytes_received",t)}}class ey{constructor(e,t,n,i){if(this.onDisconnect=n,this.urlFn=i,this.outstandingRequests=new Set,this.pendingSegs=[],this.currentSerial=Math.floor(1e8*Math.random()),this.sendNewPolls=!0,(0,y.Yr)())this.commandCB=e,this.onMessageCB=t;else{this.uniqueCallbackIdentifier=x(),window["pLPCommand"+this.uniqueCallbackIdentifier]=e,window["pRTLPCB"+this.uniqueCallbackIdentifier]=t,this.myIFrame=ey.createIFrame_();let n="";this.myIFrame.src&&"javascript:"===this.myIFrame.src.substr(0,11)&&(n='<script>document.domain="'+document.domain+'";</script>');let i="<html><body>"+n+"</body></html>";
151try{this.myIFrame.doc.open(),this.myIFrame.doc.write(i),this.myIFrame.doc.close()}catch(e){O("frame writing exception"),e.stack&&O(e.stack),O(e)}}}static createIFrame_(){let e=document.createElement("iframe");if(e.style.display="none",document.body){document.body.appendChild(e);try{e.contentWindow.document||O("No IE domain setting required")}catch(n){let t=document.domain;e.src="javascript:void((function(){document.open();document.domain='"+t+"';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}close(){this.alive=!1,this.myIFrame&&(this.myIFrame.doc.body.innerHTML="",setTimeout(()=>{null!==this.myIFrame&&(document.body.removeChild(this.myIFrame),this.myIFrame=null)},Math.floor(0)));let e=this.onDisconnect;e&&(this.onDisconnect=null,e())}startLongPoll(e,t){for(this.myID=e,this.myPW=t,this.alive=!0;this.newRequest_(););}newRequest_(){if(!this.alive||!this.sendNewPolls||!(this.outstandingRequests.size<(this.pendingSegs.length>0?2:1)))return!1;{this.currentSerial++;let e={};e.id=this.myID,e.pw=this.myPW,e.ser=this.currentSerial;let t=this.urlFn(e),n="",i=0;for(;this.pendingSegs.length>0;)if(this.pendingSegs[0].d.length+30+n.length<=1870){let e=this.pendingSegs.shift();n=n+"&seg"+i+"="+e.seg+"&ts"+i+"="+e.ts+"&d"+i+"="+e.d,i++}else break;return t+=n,this.addLongPollTag_(t,this.currentSerial),!0}}enqueueSegment(e,t,n){this.pendingSegs.push({seg:e,ts:t,d:n}),this.alive&&this.newRequest_()}addLongPollTag_(e,t){this.outstandingRequests.add(t);let n=()=>{this.outstandingRequests.delete(t),this.newRequest_()},i=setTimeout(n,Math.floor(25e3));this.addTag(e,()=>{clearTimeout(i),n()})}addTag(e,t){(0,y.Yr)()?this.doNodeLongPoll(e,t):setTimeout(()=>{try{if(!this.sendNewPolls)return;let n=this.myIFrame.doc.createElement("script");n.type="text/javascript",n.async=!0,n.src=e,n.onload=n.onreadystatechange=function(){let e=n.readyState;e&&"loaded"!==e&&"complete"!==e||(n.onload=n.onreadystatechange=null,n.parentNode&&n.parentNode.removeChild(n),t())},n.onerror=()=>{O("Long-poll script failed to load: "+e),this.sendNewPolls=!1,this.close()},this.myIFrame.doc.body.appendChild(n)}catch(e){}},Math.floor(1))}}let ev=null;"undefined"!=typeof MozWebSocket?ev=MozWebSocket:"undefined"!=typeof WebSocket&&(ev=WebSocket);class eC{constructor(e,t,n,i,r,s,o){this.connId=e,this.applicationId=n,this.appCheckToken=i,this.authToken=r,this.keepaliveTimer=null,this.frames=null,this.totalFrames=0,this.bytesSent=0,this.bytesReceived=0,this.log_=A(this.connId),this.stats_=ep(t),this.connURL=eC.connectionURL_(t,s,o,i,n),this.nodeAdmin=t.nodeAdmin}static connectionURL_(e,t,n,i,r){let s={};return s.v="5",!(0,y.Yr)()&&"undefined"!=typeof location&&location.hostname&&eo.test(location.hostname)&&(s.r="f"),t&&(s.s=t),n&&(s.ls=n),i&&(s.ac=i),r&&(s.p=r),eu(e,el,s)}open(e,t){this.onDisconnect=t,this.onMessage=e,this.log_("Websocket connecting to "+this.connURL),this.everConnected_=!1,P.set("previous_websocket_failure",!0);try{let e;if((0,y.Yr)()){let t=this.nodeAdmin?"AdminNode":"Node";e={headers:{"User-Agent":`Firebase/5/${I}/${C.platform}/${t}`,"X-Firebase-GMPID":this.applicationId||""}},this.authToken&&(e.headers.Authorization=`Bearer ${this.authToken}`),this.appCheckToken&&(e.headers["X-Firebase-AppCheck"]=this.appCheckToken);let n=C.env,i=0===this.connURL.indexOf("wss://")?n.HTTPS_PROXY||n.https_proxy:n.HTTP_PROXY||n.http_proxy;i&&(e.proxy={origin:i})}this.mySock=new ev(this.connURL,[],e)}catch(t){this.log_("Error instantiating WebSocket.");let e=t.message||t.data;e&&this.log_(e),this.onClosed_();return}this.mySock.onopen=()=>{this.log_("Websocket connected."),this.everConnected_=!0},this.mySock.onclose=()=>{this.log_("Websocket connection was disconnected."),this.mySock=null,this.onClosed_()},this.mySock.onmessage=e=>{this.handleIncomingFrame(e)},this.mySock.onerror=e=>{this.log_("WebSocket error.  Closing connection.");let t=e.message||e.data;t&&this.log_(t),this.onClosed_()}}start(){}static forceDisallow(){eC.forceDisallow_=!0}static isAvailable(){let e=!1;if("undefined"!=typeof navigator&&navigator.userAgent){let t=navigator.userAgent.match(/Android ([0-9]{0,}\.[0-9]{0,})/);t&&t.length>1&&4.4>parseFloat(t[1])&&(e=!0)}return!e&&null!==ev&&!eC.forceDisallow_}static previouslyFailed(){return P.isInMemoryStorage||!0===P.get("previous_websocket_failure")}markConnectionHealthy(){P.remove("previous_websocket_failure")}appendFrame_(e){if(this.frames.push(e),this.frames.length===this.totalFrames){let e=this.frames.join("");this.frames=null;let t=(0,y.cI)(e);this.onMessage(t)}}handleNewFrameCount_(e){this.totalFrames=e,this.frames=[]}extractFrameCount_(e){if((0,y.hu)(null===this.frames,"We already have a frame buffer"),e.length<=6){let t=Number(e);if(!isNaN(t))return this.handleNewFrameCount_(t),null}return this.handleNewFrameCount_(1),e}handleIncomingFrame(e){if(null===this.mySock)return;let t=e.data;if(this.bytesReceived+=t.length,this.stats_.incrementCounter("bytes_received",t.length),this.resetKeepAlive(),null!==this.frames)this.appendFrame_(t);else{let e=this.extractFrameCount_(t);null!==e&&this.appendFrame_(e)}}send(e){this.resetKeepAlive();let t=(0,y.Pz)(e);this.bytesSent+=t.length,this.stats_.incrementCounter("bytes_sent",t.length);let n=$(t,16384);n.length>1&&this.sendString_(String(n.length));for(let e=0;e<n.length;e++)this.sendString_(n[e])}shutdown_(){this.isClosed_=!0,this.keepaliveTimer&&(clearInterval(this.keepaliveTimer),this.keepaliveTimer=null),this.mySock&&(this.mySock.close(),this.mySock=null)}onClosed_(){!this.isClosed_&&(this.log_("WebSocket is closing itself"),this.shutdown_(),this.onDisconnect&&(this.onDisconnect(this.everConnected_),this.onDisconnect=null))}close(){this.isClosed_||(this.log_("WebSocket is being closed"),this.shutdown_())}resetKeepAlive(){clearInterval(this.keepaliveTimer),this.keepaliveTimer=setInterval(()=>{this.mySock&&this.sendString_("0"),this.resetKeepAlive()},Math.floor(45e3))}sendString_(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)}}}eC.responsesRequiredToBeHealthy=2,eC.healthyTimeout=3e4;/**
152 * @license
153 * Copyright 2017 Google LLC
154 *
155 * Licensed under the Apache License, Version 2.0 (the "License");
156 * you may not use this file except in compliance with the License.
157 * You may obtain a copy of the License at
158 *
159 *   http://www.apache.org/licenses/LICENSE-2.0
160 *
161 * Unless required by applicable law or agreed to in writing, software
162 * distributed under the License is distributed on an "AS IS" BASIS,
163 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
164 * See the License for the specific language governing permissions and
165 * limitations under the License.
166 */class ew{constructor(e){this.initTransports_(e)}static get ALL_TRANSPORTS(){return[em,eC]}static get IS_TRANSPORT_INITIALIZED(){return this.globalTransportInitialized_}initTransports_(e){let t=eC&&eC.isAvailable(),n=t&&!eC.previouslyFailed();if(e.webSocketOnly&&(t||U("wss:// URL used, but browser isn't known to support websockets.  Trying anyway."),n=!0),n)this.transports_=[eC];else{let e=this.transports_=[];for(let t of ew.ALL_TRANSPORTS)t&&t.isAvailable()&&e.push(t);ew.globalTransportInitialized_=!0}}initialTransport(){if(this.transports_.length>0)return this.transports_[0];throw Error("No transports available")}upgradeTransport(){return this.transports_.length>1?this.transports_[1]:null}}ew.globalTransportInitialized_=!1;class eT{constructor(e,t,n,i,r,s,o,l,a,h){this.id=e,this.repoInfo_=t,this.applicationId_=n,this.appCheckToken_=i,this.authToken_=r,this.onMessage_=s,this.onReady_=o,this.onDisconnect_=l,this.onKill_=a,this.lastSessionId=h,this.connectionCount=0,this.pendingDataMessages=[],this.state_=0,this.log_=A("c:"+this.id+":"),this.transportManager_=new ew(t),this.log_("Connection created"),this.start_()}start_(){let e=this.transportManager_.initialTransport();this.conn_=new e(this.nextTransportId_(),this.repoInfo_,this.applicationId_,this.appCheckToken_,this.authToken_,null,this.lastSessionId),this.primaryResponsesRequired_=e.responsesRequiredToBeHealthy||0;let t=this.connReceiver_(this.conn_),n=this.disconnReceiver_(this.conn_);this.tx_=this.conn_,this.rx_=this.conn_,this.secondaryConn_=null,this.isHealthy_=!1,setTimeout(()=>{this.conn_&&this.conn_.open(t,n)},Math.floor(0));let i=e.healthyTimeout||0;i>0&&(this.healthyTimeout_=en(()=>{this.healthyTimeout_=null,this.isHealthy_||(this.conn_&&this.conn_.bytesReceived>102400?(this.log_("Connection exceeded healthy timeout but has received "+this.conn_.bytesReceived+" bytes.  Marking connection healthy."),this.isHealthy_=!0,this.conn_.markConnectionHealthy()):this.conn_&&this.conn_.bytesSent>10240?this.log_("Connection exceeded healthy timeout but has sent "+this.conn_.bytesSent+" bytes.  Leaving connection alive."):(this.log_("Closing unhealthy connection after timeout."),this.close()))},Math.floor(i)))}nextTransportId_(){return"c:"+this.id+":"+this.connectionCount++}disconnReceiver_(e){return t=>{e===this.conn_?this.onConnectionLost_(t):e===this.secondaryConn_?(this.log_("Secondary connection lost."),this.onSecondaryConnectionLost_()):this.log_("closing an old connection")}}connReceiver_(e){return t=>{2!==this.state_&&(e===this.rx_?this.onPrimaryMessageReceived_(t):e===this.secondaryConn_?this.onSecondaryMessageReceived_(t):this.log_("message on old connection"))}}sendRequest(e){this.sendData_({t:"d",d:e})}tryCleanupConnection(){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)}onSecondaryControl_(e){if("t"in e){let 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_())}}onSecondaryMessageReceived_(e){let t=Q("t",e),n=Q("d",e);if("c"===t)this.onSecondaryControl_(n);else if("d"===t)this.pendingDataMessages.push(n);else throw Error("Unknown protocol layer: "+t)}upgradeIfSecondaryHealthy_(){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
166:"c",d:{t:"p",d:{}}}))}proceedWithUpgrade_(){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()}onPrimaryMessageReceived_(e){let t=Q("t",e),n=Q("d",e);"c"===t?this.onControl_(n):"d"===t&&this.onDataMessage_(n)}onDataMessage_(e){this.onPrimaryResponse_(),this.onMessage_(e)}onPrimaryResponse_(){!this.isHealthy_&&(this.primaryResponsesRequired_--,this.primaryResponsesRequired_<=0&&(this.log_("Primary connection is healthy."),this.isHealthy_=!0,this.conn_.markConnectionHealthy()))}onControl_(e){let t=Q("t",e);if("d"in e){let n=e.d;if("h"===t)this.onHandshake_(n);else if("n"===t){this.log_("recvd end transmission on primary"),this.rx_=this.secondaryConn_;for(let e=0;e<this.pendingDataMessages.length;++e)this.onDataMessage_(this.pendingDataMessages[e]);this.pendingDataMessages=[],this.tryCleanupConnection()}else"s"===t?this.onConnectionShutdown_(n):"r"===t?this.onReset_(n):"e"===t?L("Server Error: "+n):"o"===t?(this.log_("got pong on primary."),this.onPrimaryResponse_(),this.sendPingOnPrimaryIfNecessary_()):L("Unknown control packet command: "+t)}}onHandshake_(e){let 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&&U("Protocol version mismatch detected"),this.tryStartUpgrade_())}tryStartUpgrade_(){let e=this.transportManager_.upgradeTransport();e&&this.startUpgrade_(e)}startUpgrade_(e){this.secondaryConn_=new e(this.nextTransportId_(),this.repoInfo_,this.applicationId_,this.appCheckToken_,this.authToken_,this.sessionId),this.secondaryResponsesRequired_=e.responsesRequiredToBeHealthy||0;let t=this.connReceiver_(this.secondaryConn_),n=this.disconnReceiver_(this.secondaryConn_);this.secondaryConn_.open(t,n),en(()=>{this.secondaryConn_&&(this.log_("Timed out trying to upgrade."),this.secondaryConn_.close())},Math.floor(6e4))}onReset_(e){this.log_("Reset packet received.  New host: "+e),this.repoInfo_.host=e,1===this.state_?this.close():(this.closeConnections_(),this.start_())}onConnectionEstablished_(e,t){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):en(()=>{this.sendPingOnPrimaryIfNecessary_()},Math.floor(5e3))}sendPingOnPrimaryIfNecessary_(){this.isHealthy_||1!==this.state_||(this.log_("sending ping on primary."),this.sendData_({t:"c",d:{t:"p",d:{}}}))}onSecondaryConnectionLost_(){let e=this.secondaryConn_;this.secondaryConn_=null,(this.tx_===e||this.rx_===e)&&this.close()}onConnectionLost_(e){this.conn_=null,e||0!==this.state_?1===this.state_&&this.log_("Realtime connection lost."):(this.log_("Realtime connection failed."),this.repoInfo_.isCacheableHost()&&(P.remove("host:"+this.repoInfo_.host),this.repoInfo_.internalHost=this.repoInfo_.host)),this.close()}onConnectionShutdown_(e){this.log_("Connection shutdown command received. Shutting down..."),this.onKill_&&(this.onKill_(e),this.onKill_=null),this.onDisconnect_=null,this.close()}sendData_(e){if(1!==this.state_)throw"Connection is not connected";this.tx_.send(e)}close(){2!==this.state_&&(this.log_("Closing realtime connection."),this.state_=2,this.closeConnections_(),this.onDisconnect_&&(this.onDisconnect_(),this.onDisconnect_=null))}closeConnections_(){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)}}/**
167 * @license
168 * Copyright 2017 Google LLC
169 *
170 * Licensed under the Apache License, Version 2.0 (the "License");
171 * you may not use this file except in compliance with the License.
172 * You may obtain a copy of the License at
173 *
174 *   http://www.apache.org/licenses/LICENSE-2.0
175 *
176 * Unless required by applicable law or agreed to in writing, softw
176are
177 * distributed under the License is distributed on an "AS IS" BASIS,
178 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
179 * See the License for the specific language governing permissions and
180 * limitations under the License.
181 */class eI{put(e,t,n,i){}merge(e,t,n,i){}refreshAuthToken(e){}refreshAppCheckToken(e){}onDisconnectPut(e,t,n){}onDisconnectMerge(e,t,n){}onDisconnectCancel(e,t){}reportStats(e){}}/**
182 * @license
183 * Copyright 2017 Google LLC
184 *
185 * Licensed under the Apache License, Version 2.0 (the "License");
186 * you may not use this file except in compliance with the License.
187 * You may obtain a copy of the License at
188 *
189 *   http://www.apache.org/licenses/LICENSE-2.0
190 *
191 * Unless required by applicable law or agreed to in writing, software
192 * distributed under the License is distributed on an "AS IS" BASIS,
193 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
194 * See the License for the specific language governing permissions and
195 * limitations under the License.
196 */class eb{constructor(e){this.allowedEvents_=e,this.listeners_={},(0,y.hu)(Array.isArray(e)&&e.length>0,"Requires a non-empty array")}trigger(e,...t){if(Array.isArray(this.listeners_[e])){let n=[...this.listeners_[e]];for(let e=0;e<n.length;e++)n[e].callback.apply(n[e].context,t)}}on(e,t,n){this.validateEventType_(e),this.listeners_[e]=this.listeners_[e]||[],this.listeners_[e].push({callback:t,context:n});let i=this.getInitialEvent(e);i&&t.apply(n,i)}off(e,t,n){this.validateEventType_(e);let i=this.listeners_[e]||[];for(let e=0;e<i.length;e++)if(i[e].callback===t&&(!n||n===i[e].context)){i.splice(e,1);return}}validateEventType_(e){(0,y.hu)(this.allowedEvents_.find(t=>t===e),"Unknown event: "+e)}}/**
197 * @license
198 * Copyright 2017 Google LLC
199 *
200 * Licensed under the Apache License, Version 2.0 (the "License");
201 * you may not use this file except in compliance with the License.
202 * You may obtain a copy of the License at
203 *
204 *   http://www.apache.org/licenses/LICENSE-2.0
205 *
206 * Unless required by applicable law or agreed to in writing, software
207 * distributed under the License is distributed on an "AS IS" BASIS,
208 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
209 * See the License for the specific language governing permissions and
210 * limitations under the License.
211 */class ek extends eb{constructor(){super(["online"]),this.online_=!0,"undefined"==typeof window||void 0===window.addEventListener||(0,y.uI)()||(window.addEventListener("online",()=>{this.online_||(this.online_=!0,this.trigger("online",!0))},!1),window.addEventListener("offline",()=>{this.online_&&(this.online_=!1,this.trigger("online",!1))},!1))}static getInstance(){return new ek}getInitialEvent(e){return(0,y.hu)("online"===e,"Unknown event type: "+e),[this.online_]}currentlyOnline(){return this.online_}}class eE{constructor(e,t){if(void 0===t){this.pieces_=e.split("/");let t=0;for(let e=0;e<this.pieces_.length;e++)this.pieces_[e].length>0&&(this.pieces_[t]=this.pieces_[e],t++);this.pieces_.length=t,this.pieceNum_=0}else this.pieces_=e,this.pieceNum_=t}toString(){let e="";for(let t=this.pieceNum_;t<this.pieces_.length;t++)""!==this.pieces_[t]&&(e+="/"+this.pieces_[t]);return e||"/"}}function eP(){return new eE("")}function eN(e){return e.pieceNum_>=e.pieces_.length?null:e.pieces_[e.pieceNum_]}function eS(e){return e.pieces_.length-e.pieceNum_}function ex(e){let t=e.pieceNum_;return t<e.pieces_.length&&t++,new eE(e.pieces_,t)}function eR(e){return e.pieceNum_<e.pieces_.length?e.pieces_[e.pieces_.length-1]:null}function eD(e,t=0){return e.pieces_.slice(e.pieceNum_+t)}function eM(e){if(e.pieceNum_>=e.pieces_.length)return null;let t=[];for(let n=e.pieceNum_;n<e.pieces_.length-1;n++)t.push(e.pieces_[n]);return new eE(t,0)}function eF(e,t){let n=[];for(let t=e.pieceNum_;t<e.pieces_.length;t++)n.push(e.pieces_[t]);if(t instanceof eE)for(let e=t.pieceNum_;e<t.pieces_.length;e++)n.push(t.pieces_[e]);else{let e=t.split("/");for(let t=0;t<e.length;t++)e[t].length>0&&n.push(e[t])}return new eE(n,0)}function eq(e){return e.pieceNum_>=e.pieces_.length}function eO(e,t){let n=eN(e),i=eN(t);if(null===n)return t;if(n===i)return eO(ex(e),ex(t));
211throw Error("INTERNAL ERROR: innerPath ("+t+") is not within outerPath ("+e+")")}function eA(e,t){let n=eD(e,0),i=eD(t,0);for(let e=0;e<n.length&&e<i.length;e++){let t=B(n[e],i[e]);if(0!==t)return t}return n.length===i.length?0:n.length<i.length?-1:1}function eL(e,t){if(eS(e)!==eS(t))return!1;for(let n=e.pieceNum_,i=t.pieceNum_;n<=e.pieces_.length;n++,i++)if(e.pieces_[n]!==t.pieces_[i])return!1;return!0}function eW(e,t){let n=e.pieceNum_,i=t.pieceNum_;if(eS(e)>eS(t))return!1;for(;n<e.pieces_.length;){if(e.pieces_[n]!==t.pieces_[i])return!1;++n,++i}return!0}class eU{constructor(e,t){this.errorPrefix_=t,this.parts_=eD(e,0),this.byteLength_=Math.max(1,this.parts_.length);for(let e=0;e<this.parts_.length;e++)this.byteLength_+=(0,y.ug)(this.parts_[e]);ez(this)}}function ez(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 "+eH(e))}function eH(e){return 0===e.parts_.length?"":"in property '"+e.parts_.join(".")+"'"}/**
212 * @license
213 * Copyright 2017 Google LLC
214 *
215 * Licensed under the Apache License, Version 2.0 (the "License");
216 * you may not use this file except in compliance with the License.
217 * You may obtain a copy of the License at
218 *
219 *   http://www.apache.org/licenses/LICENSE-2.0
220 *
221 * Unless required by applicable law or agreed to in writing, software
222 * distributed under the License is distributed on an "AS IS" BASIS,
223 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
224 * See the License for the specific language governing permissions and
225 * limitations under the License.
226 */class eY extends eb{constructor(){let e,t;super(["visible"]),"undefined"!=typeof document&&void 0!==document.addEventListener&&(void 0!==document.hidden?(t="visibilitychange",e="hidden"):void 0!==document.mozHidden?(t="mozvisibilitychange",e="mozHidden"):void 0!==document.msHidden?(t="msvisibilitychange",e="msHidden"):void 0!==document.webkitHidden&&(t="webkitvisibilitychange",e="webkitHidden")),this.visible_=!0,t&&document.addEventListener(t,()=>{let t=!document[e];t!==this.visible_&&(this.visible_=t,this.trigger("visible",t))},!1)}static getInstance(){return new eY}getInitialEvent(e){return(0,y.hu)("visible"===e,"Unknown event type: "+e),[this.visible_]}}class ej extends eI{constructor(e,t,n,i,r,s,o,l){if(super(),this.repoInfo_=e,this.applicationId_=t,this.onDataUpdate_=n,this.onConnectStatus_=i,this.onServerInfoUpdate_=r,this.authTokenProvider_=s,this.appCheckTokenProvider_=o,this.authOverride_=l,this.id=ej.nextPersistentConnectionId_++,this.log_=A("p:"+this.id+":"),this.interruptReasons_={},this.listens=new Map,this.outstandingPuts_=[],this.outstandingGets_=[],this.outstandingPutCount_=0,this.outstandingGetCount_=0,this.onDisconnectRequestQueue_=[],this.connected_=!1,this.reconnectDelay_=1e3,this.maxReconnectDelay_=3e5,this.securityDebugCallback_=null,this.lastSessionId=null,this.establishConnectionTimer_=null,this.visible_=!1,this.requestCBHash_={},this.requestNumber_=0,this.realtime_=null,this.authToken_=null,this.appCheckToken_=null,this.forceTokenRefresh_=!1,this.invalidAuthTokenCount_=0,this.invalidAppCheckTokenCount_=0,this.firstConnection_=!0,this.lastConnectionAttemptTime_=null,this.lastConnectionEstablishedTime_=null,l&&!(0,y.Yr)())throw Error("Auth override specified in options, but not supported on non Node.js platforms");eY.getInstance().on("visible",this.onVisible_,this),-1===e.host.indexOf("fblocal")&&ek.getInstance().on("online",this.onOnline_,this)}sendRequest(e,t,n){let i=++this.requestNumber_,r={r:i,a:e,b:t};this.log_((0,y.Pz)(r)),(0,y.hu)(this.connected_,"sendRequest call when we're not connected not allowed."),this.realtime_.sendRequest(r),n&&(this.requestCBHash_[i]=n)}get(e){this.initConnection_();let t=new y.BH,n={p:e._path.toString(),q:e._queryObject};this.outstandingGets_.push({action:"g",request:n,onComplete:e=>{let n=e.d;"ok"===e.s?t.resolve(n):t.reject(n)}}),this.outstandingGetCount_++;let i=this.outstandingGets_.length-1;return this.connected_&&this.sendGet_(i),t.promise}listen(e,t,n,i){this.initConnection_();let r=e._queryIdentifier,s=e._path.toString();this.log_("Listen called for "+s+" "+r),this.listens.has(s)||this.listens.set(s,new Map),(0,y.hu)(e._queryParams.isDefault()||!e._queryParams.loadsAllData(),"listen() called for non-default but complete query"),(0,y.hu)(!this.listens.get(s).has(r),"listen() called twice for same path/queryId.");let o={onComplete:i,hashFn:t,query:e,tag:n};this.listens.get(s).set(r,o),this.connected_&&this.sendListen_(o)}sendGet_(e){let t=this.outstandingGets_[e];this.sendRequest("g",t.request,n=>{delete this.outstandingGets_[e],this.outstandingGetCount_--,0===this.outstandingGetCount_&&(this.outstandingGets_=[]),t.onComplete&&t.onComplete(n)})}sendListen_(e){let t=e.query,n=t._path.toString(),i=t._queryIdentifier;this.log_("Listen on "+n+" for "+i);let r={p:n};e.tag&&(r.q=t._queryObject,r.t=e.tag),r.h=e.hashFn(),this.sendRequest("q",r,r=>{let s=r.d,o=r.s;ej.warnOnListenWarnings_(s,t),(this.listens.get(n)&&this.listens.get(n).get(i))===e&&(this.log_("listen response",r),"ok"!==o&&this.removeListen_(n,i),e.onComplete&&e.onComplete(o,s))})}static warnOnListenWarnings_(e,t){if(e&&"object"==typeof e&&(0,y.r3)(e,"w")){let n=(0,y.DV)(e,"w");if(Array.isArray(n)&&~n.indexOf("no_index")){let e='".indexOn": "'+t._queryParams.getIndex().toString()+'"',n=t._path.toString();U(`Using an unspecified index. Your data will be downloaded and filtered on the client. Consider adding ${e} at ${n} to your security rules for better performance.`)}}}refreshAuthToken(e){this.authToken_=e,this.log_("Auth token refreshed"),this.authToken_?this.tryAuth():this.connected_&&this.sendRequest("unauth",{},()=>{}),this.reduceReconnectDelayIfAdminCredential_(e)}reduceReconnectDelayIfAdminCredential_(e){(e&&40===e.length||(0,y.GJ)(e))&&(this.log_("Admin auth credential detected.  Reducing max reconnect time."),this.maxReconnectDelay_=3e4)}refreshAppCheckToken(e){this.appCheckToken_=e,this.log_("App check token refreshed"),this.appCheckToken_?this.tryAppCheck():this.connected_&&this.sendRequest("unappeck",{},()=>{})}tryAuth(){if(this.connected_&&this.authToken_){let e=this.authToken_,t=(0,y.w9)(e)?"auth":"gauth",n={cred:e};null===this.authOverride_?n.noauth=!0:"object"==typeof this.authOverride_&&(n.authvar=this.authOverride_),this.sendRequest(t,n,t=>{let n=t.s,i=t.d||"error";this.authToken_===e&&("ok"===n?this.invalidAuthTokenCount_=0:this.onAuthRevoked_(n,i))})}}tryAppCheck(){this.connected_&&this.appCheckToken_&&this.sendRequest("appcheck",{token:this.appCheckToken_},e=>{let t=e.s,n=e.d||"error";"ok"===t?this.invalidAppCheckTokenCount_=0:this.onAppCheckRevoked_(t,n)})}unlisten(e,t){let n=e._path.toString(),i=e._queryIdentifier;this.log_("Unlisten called for "+n+" "+i),(0,y.hu)(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)}sendUnlisten_(e,t,n,i){this.log_("Unlisten on "+e+" for "+t);let r={p:e};i&&(r.q=n,r.t=i),this.sendRequest("n",r)}onDisconnectPut(e,t,n){this.initConnection_(),this.connected_?this.sendOnDisconnect_("o",e,t,n):this.onDisconnectRequestQueue_.push({pathString:e,action:"o",data:t,onComplete:n})}onDisconnectMerge(e,t,n){this.initConnection_(),this.connected_?this.sendOnDisconnect_("om",e,t,n):this.onDisconnectRequestQueue_.push({pathString:e,action:"om",data:t,onComplete:n})}onDisconnectCancel(e,t){this.initConnection_(),this.connected_?this.sendOnDisconnect_("oc",e,null,t):this.onDisconnectRequestQueue_.push({pathString:e,action:"oc",data:null,onComplete:t})}sendOnDisconnect_(e,t,n,i){let r={p:t,d:n};this.log_("onDisconnect "+e,r),this.sendRequest(e,r,e=>
226{i&&setTimeout(()=>{i(e.s,e.d)},Math.floor(0))})}put(e,t,n,i){this.putInternal("p",e,t,n,i)}merge(e,t,n,i){this.putInternal("m",e,t,n,i)}putInternal(e,t,n,i,r){this.initConnection_();let s={p:t,d:n};void 0!==r&&(s.h=r),this.outstandingPuts_.push({action:e,request:s,onComplete:i}),this.outstandingPutCount_++;let o=this.outstandingPuts_.length-1;this.connected_?this.sendPut_(o):this.log_("Buffering put: "+t)}sendPut_(e){let t=this.outstandingPuts_[e].action,n=this.outstandingPuts_[e].request,i=this.outstandingPuts_[e].onComplete;this.outstandingPuts_[e].queued=this.connected_,this.sendRequest(t,n,n=>{this.log_(t+" response",n),delete this.outstandingPuts_[e],this.outstandingPutCount_--,0===this.outstandingPutCount_&&(this.outstandingPuts_=[]),i&&i(n.s,n.d)})}reportStats(e){if(this.connected_){let t={c:e};this.log_("reportStats",t),this.sendRequest("s",t,e=>{if("ok"!==e.s){let t=e.d;this.log_("reportStats","Error sending stats: "+t)}})}}onDataMessage_(e){if("r"in e){this.log_("from server: "+(0,y.Pz)(e));let 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)}onDataPush_(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):L("Unrecognized action received from server: "+(0,y.Pz)(e)+"\nAre you using the latest client?")}onReady_(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)}scheduleConnect_(e){(0,y.hu)(!this.realtime_,"Scheduling a connect when we're already connected/ing?"),this.establishConnectionTimer_&&clearTimeout(this.establishConnectionTimer_),this.establishConnectionTimer_=setTimeout(()=>{this.establishConnectionTimer_=null,this.establishConnection_()},Math.floor(e))}initConnection_(){!this.realtime_&&this.firstConnection_&&this.scheduleConnect_(0)}onVisible_(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}onOnline_(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())}onRealtimeDisconnect_(){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());let e=new Date().getTime()-this.lastConnectionAttemptTime_,t=Math.max(0,this.reconnectDelay_-e);t=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)}async establishConnection_(){if(this.shouldReconnect_()){this.log_("Making a connection attempt"),this.lastConnectionAttemptTime_=new Date().getTime(),this.lastConnectionEstablishedTime_=null;let e=this.onDataMessage_.bind(this),t=this.onReady_.bind(this),n=this.onRealtimeDisconnect_.bind(this),i=this.id+":"+ej.nextConnectionId_++,r=this.lastSessionId,s=!1,o=null,l=function(){o?o.close():(s=!0,n())};this.realtime_={close:l,sendRequest:function(e){(0,y.hu)(o,"sendRequest call when we're not connected not allowed."),o.send
226Request(e)}};let a=this.forceTokenRefresh_;this.forceTokenRefresh_=!1;try{let[l,h]=await Promise.all([this.authTokenProvider_.getToken(a),this.appCheckTokenProvider_.getToken(a)]);s?O("getToken() completed but was canceled"):(O("getToken() completed. Creating connection."),this.authToken_=l&&l.accessToken,this.appCheckToken_=h&&h.token,o=new eT(i,this.repoInfo_,this.applicationId_,this.appCheckToken_,this.authToken_,e,t,n,e=>{U(e+" ("+this.repoInfo_.toString()+")"),this.interrupt("server_kill")},r))}catch(e){this.log_("Failed to get token: "+e),s||(this.repoInfo_.nodeAdmin&&U(e),l())}}}interrupt(e){O("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_())}resume(e){O("Resuming connection for reason: "+e),delete this.interruptReasons_[e],(0,y.xb)(this.interruptReasons_)&&(this.reconnectDelay_=1e3,this.realtime_||this.scheduleConnect_(0))}handleTimestamp_(e){let t=e-new Date().getTime();this.onServerInfoUpdate_({serverTimeOffset:t})}cancelSentTransactions_(){for(let e=0;e<this.outstandingPuts_.length;e++){let 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_=[])}onListenRevoked_(e,t){let n;n=t?t.map(e=>G(e)).join("$"):"default";let i=this.removeListen_(e,n);i&&i.onComplete&&i.onComplete("permission_denied")}removeListen_(e,t){let n;let i=new eE(e).toString();if(this.listens.has(i)){let e=this.listens.get(i);n=e.get(t),e.delete(t),0===e.size&&this.listens.delete(i)}else n=void 0;return n}onAuthRevoked_(e,t){O("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()))}onAppCheckRevoked_(e,t){O("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())}onSecurityDebugPacket_(e){this.securityDebugCallback_?this.securityDebugCallback_(e):"msg"in e&&console.log("FIREBASE: "+e.msg.replace("\n","\nFIREBASE: "))}restoreState_(){for(let e of(this.tryAuth(),this.tryAppCheck(),this.listens.values()))for(let t of e.values())this.sendListen_(t);for(let e=0;e<this.outstandingPuts_.length;e++)this.outstandingPuts_[e]&&this.sendPut_(e);for(;this.onDisconnectRequestQueue_.length;){let e=this.onDisconnectRequestQueue_.shift();this.sendOnDisconnect_(e.action,e.pathString,e.data,e.onComplete)}for(let e=0;e<this.outstandingGets_.length;e++)this.outstandingGets_[e]&&this.sendGet_(e)}sendConnectStats_(){let e={},t="js";(0,y.Yr)()&&(t=this.repoInfo_.nodeAdmin?"admin_node":"node"),e["sdk."+t+"."+I.replace(/\./g,"-")]=1,(0,y.uI)()?e["framework.cordova"]=1:(0,y.b$)()&&(e["framework.reactnative"]=1),this.reportStats(e)}shouldReconnect_(){let e=ek.getInstance().currentlyOnline();return(0,y.xb)(this.interruptReasons_)&&e}}ej.nextPersistentConnectionId_=0,ej.nextConnectionId_=0;/**
227 * @license
228 * Copyright 2017 Google LLC
229 *
230 * Licensed under the Apache License, Version 2.0 (the "License");
231 * you may not use this file except in compliance with the License.
232 * You may obtain a copy of the License at
233 *
234 *   http://www.apache.org/licenses/LICENSE-2.0
235 *
236 * Unless required by applicable law or agreed to in writing, software
237 * distributed under the License is distributed on an "AS IS" BASIS,
238 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
239 * See the License for the specific language governing permissions and
240 * limitations under the License.
241 */class eV{constructor(e,t){this.name=e,this.node=t}static Wrap(e,t){return new eV(e,t)}}/**
242 * @license
243 * Copyright 2017 Google LLC
244 *
245 * Licensed under the Apache License, Version 2.0 (the "License");
246 * you may not use this file except in compliance with the License.
247 * You may obtain a copy of the License at
248 *
249 *   http://www.apache.org/licenses/LICENSE-2.0
250 *
251 * Unless required by applicable law or agreed to in writing, software
252 * distributed under the License is distributed on an "AS IS" BASIS,
253 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
254 * See the License for the specific language governing permissions and
255 * limitations under the License.
256 */class eB{getCompare(){return this.compare.bind(this)}indexedValueChanged(e,t){let n=new eV(j,e),i=new eV(j,t);return 0!==this.compare(n,i)}minPost(){return eV.MIN}}class eK extends eB{static get __EMPTY_NODE(){return i}static set __EMPTY_NODE(e){i=e}compare(e,t){return B(e.name,t.name)}isDefinedOn(e){throw(0,y.g5)("KeyIndex.isDefinedOn not expected to be called.")}indexedValueChanged(e,t){return!1}minPost(){return eV.MIN}maxPost(){return new eV(V,i)}makePost(e,t){return(0,y.hu)("string"==typeof e,"KeyIndex indexValue must always be a string."),new eV(e,i)}toString(){return".key"}}let eQ=new eK;/**
257 * @license
258 * Copyright 2017 Google LLC
259 *
260 * Licensed under the Apache License, Version 2.0 (the "License");
261 * you may not use this file except in compliance with the License.
262 * You may obtain a copy of the License at
263 *
264 *   http://www.apache.org/licenses/LICENSE-2.0
265 *
266 * Unless required by applicable law or agreed to in writing, software
267 * distributed under the License is distributed on an "AS IS" BASIS,
268 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
269 * See the License for the specific language governing permissions and
270 * limitations under the License.
271 */class eG{constructor(e,t,n,i,r=null){this.isReverse_=i,this.resultGenerator_=r,this.nodeStack_=[];let s=1;for(;!e.isEmpty();)if(s=t?n(e.key,t):1,i&&(s*=-1),s<0)e=this.isReverse_?e.left:e.right;else if(0===s){this.nodeStack_.push(e);break}else this.nodeStack_.push(e),e=this.isReverse_?e.right:e.left}getNext(){let e;if(0===this.nodeStack_.length)return null;let 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}hasNext(){return this.nodeStack_.length>0}peek(){if(0===this.nodeStack_.length)return null;let e=this.nodeStack_[this.nodeStack_.length-1];return this.resultGenerator_?this.resultGenerator_(e.key,e.value):{key:e.key,value:e.value}}}class e${constructor(e,t,n,i,r){this.key=e,this.value=t,this.color=null!=n?n:e$.RED,this.left=null!=i?i:eJ.EMPTY_NODE,this.right=null!=r?r:eJ.EMPTY_NODE}copy(e,t,n,i,r){return new e$(null!=e?e:this.key,null!=t?t:this.value,null!=n?n:this.color,null!=i?i:this.left,null!=r?r:this.right)}count(){return this.left.count()+1+this.right.count()}isEmpty(){return!1}inorderTraversal(e){return this.left.inorderTraversal(e)||!!e(this.key,this.value)||this.right.inorderTraversal(e)}reverseTraversal(e){return this.right.reverseTraversal(e)||e(this.key,this.value)||this.left.reverseTraversal(e)}min_(){return this.left.isEmpty()?this:this.left.min_()}minKey(){return this.min_().key}maxKey(){return this.right.isEmpty()?this.key:this.right.maxKey()}insert(e,t,n){let 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_()}removeMin_(){if(this.left.isEmpty())return eJ.EMPTY_NODE;let e=this;return e.left.isRed_()||e.left.left.isRed_()||(e=e.moveRedLeft_()),(e=e.copy(null,null,null,e.left.removeMin_(),null)).fixUp_()}remove(e,t){let 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 eJ.EMPTY_NODE;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_()}isRed_(){return this.color}fixUp_(){let 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}moveRedLeft_(){let e=this.colorFlip_();return e.right.left.isRed_()&&(e=(e=(e=e.copy(null,null,null,null,e.right.rotateRight_())).rotateLeft_()).colorFlip_()),e}moveRedRight_(){let e=this.colorFlip_();return e.left.left.isRed_()&&(e=(e=e.rotateRight_()).colorFlip_()),e}rotateLeft_(){let e=this.copy(null,null,e$.RED,null,this.right.left);return this.right.copy(null,null,this.color,e,null)}rotateRight_(){let e=this.copy(null,null,e$.RED,this.left.right,null);return this.left.copy(null,null,this.color,null,e)}colorFlip_(){let 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)}checkMaxDepth_(){return Math.pow(2,this.check_())<=this.count()+1}
271check_(){if(this.isRed_()&&this.left.isRed_())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");let e=this.left.check_();if(e===this.right.check_())return e+(this.isRed_()?0:1);throw Error("Black depths differ")}}e$.RED=!0,e$.BLACK=!1;class eX{copy(e,t,n,i,r){return this}insert(e,t,n){return new e$(e,t,null)}remove(e,t){return this}count(){return 0}isEmpty(){return!0}inorderTraversal(e){return!1}reverseTraversal(e){return!1}minKey(){return null}maxKey(){return null}check_(){return 0}isRed_(){return!1}}class eJ{constructor(e,t=eJ.EMPTY_NODE){this.comparator_=e,this.root_=t}insert(e,t){return new eJ(this.comparator_,this.root_.insert(e,t,this.comparator_).copy(null,null,e$.BLACK,null,null))}remove(e){return new eJ(this.comparator_,this.root_.remove(e,this.comparator_).copy(null,null,e$.BLACK,null,null))}get(e){let t;let n=this.root_;for(;!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}getPredecessorKey(e){let t,n=this.root_,i=null;for(;!n.isEmpty();){if(0===(t=this.comparator_(e,n.key))){if(n.left.isEmpty()){if(i)return i.key;return null}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?")}isEmpty(){return this.root_.isEmpty()}count(){return this.root_.count()}minKey(){return this.root_.minKey()}maxKey(){return this.root_.maxKey()}inorderTraversal(e){return this.root_.inorderTraversal(e)}reverseTraversal(e){return this.root_.reverseTraversal(e)}getIterator(e){return new eG(this.root_,null,this.comparator_,!1,e)}getIteratorFrom(e,t){return new eG(this.root_,e,this.comparator_,!1,t)}getReverseIteratorFrom(e,t){return new eG(this.root_,e,this.comparator_,!0,t)}getReverseIterator(e){return new eG(this.root_,null,this.comparator_,!0,e)}}/**
272 * @license
273 * Copyright 2017 Google LLC
274 *
275 * Licensed under the Apache License, Version 2.0 (the "License");
276 * you may not use this file except in compliance with the License.
277 * You may obtain a copy of the License at
278 *
279 *   http://www.apache.org/licenses/LICENSE-2.0
280 *
281 * Unless required by applicable law or agreed to in writing, software
282 * distributed under the License is distributed on an "AS IS" BASIS,
283 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
284 * See the License for the specific language governing permissions and
285 * limitations under the License.
286 */function eZ(e,t){return B(e.name,t.name)}function e0(e,t){return B(e,t)}eJ.EMPTY_NODE=new eX;let e1=function(e){return"number"==typeof e?"number:"+J(e):"string:"+e},e3=function(e){if(e.isLeafNode()){let t=e.val();(0,y.hu)("string"==typeof t||"number"==typeof t||"object"==typeof t&&(0,y.r3)(t,".sv"),"Priority must be a string or number.")}else(0,y.hu)(e===r||e.isEmpty(),"priority of unexpected type.");(0,y.hu)(e===r||e.getPriority().isEmpty(),"Priority nodes can't have a priority of their own.")};class e2{constructor(e,t=e2.__childrenNodeConstructor.EMPTY_NODE){this.value_=e,this.priorityNode_=t,this.lazyHash_=null,(0,y.hu)(void 0!==this.value_&&null!==this.value_,"LeafNode shouldn't be created with null/undefined value."),e3(this.priorityNode_)}static set __childrenNodeConstructor(e){s=e}static get __childrenNodeConstructor(){return s}isLeafNode(){return!0}getPriority(){return this.priorityNode_}updatePriority(e){return new e2(this.value_,e)}getImmediateChild(e){return".priority"===e?this.priorityNode_:e2.__childrenNodeConstructor.EMPTY_NODE}getChild(e){return eq(e)?this:".priority"===eN(e)?this.priorityNode_:e2.__childrenNodeConstructor.EMPTY_NODE}hasChild(){return!1}getPredecessorChildName(e,t){return null}updateImmediateChild(e,t){return".priority"===e?this.updatePriority(t):t.isEmpty()&&".priority"!==e?this:e2.__childrenNodeConstructor.EMPTY_NODE.updateImmediateChild(e,t).updatePriority(this.priorityNode_)}updateChild(e,t){let n=eN(e);return null===n?t:t.isEmpty()&&".priority"!==n?this:((0,y.hu)(".priority"!==n||1===eS(e),".priority must be the last token in a path"),this.updateImmediateChild(n,e2.__childrenNodeConstructor.EMPTY_NODE.updateChild(ex(e),t)))}isEmpty(){return!1}numChildren(){return 0}forEachChild(e,t){return!1}
286val(e){return e&&!this.getPriority().isEmpty()?{".value":this.getValue(),".priority":this.getPriority().val()}:this.getValue()}hash(){if(null===this.lazyHash_){let e="";this.priorityNode_.isEmpty()||(e+="priority:"+e1(this.priorityNode_.val())+":");let t=typeof this.value_;e+=t+":","number"===t?e+=J(this.value_):e+=this.value_,this.lazyHash_=R(e)}return this.lazyHash_}getValue(){return this.value_}compareTo(e){return e===e2.__childrenNodeConstructor.EMPTY_NODE?1:e instanceof e2.__childrenNodeConstructor?-1:((0,y.hu)(e.isLeafNode(),"Unknown node type"),this.compareToLeafNode_(e))}compareToLeafNode_(e){let t=typeof e.value_,n=typeof this.value_,i=e2.VALUE_TYPE_ORDER.indexOf(t),r=e2.VALUE_TYPE_ORDER.indexOf(n);return((0,y.hu)(i>=0,"Unknown leaf type: "+t),(0,y.hu)(r>=0,"Unknown leaf type: "+n),i!==r)?r-i:"object"===n?0:this.value_<e.value_?-1:this.value_===e.value_?0:1}withIndex(){return this}isIndexed(){return!0}equals(e){return e===this||!!e.isLeafNode()&&this.value_===e.value_&&this.priorityNode_.equals(e.priorityNode_)}}e2.VALUE_TYPE_ORDER=["object","boolean","number","string"];class e4 extends eB{compare(e,t){let n=e.node.getPriority(),i=t.node.getPriority(),r=n.compareTo(i);return 0===r?B(e.name,t.name):r}isDefinedOn(e){return!e.getPriority().isEmpty()}indexedValueChanged(e,t){return!e.getPriority().equals(t.getPriority())}minPost(){return eV.MIN}maxPost(){return new eV(V,new e2("[PRIORITY-POST]",l))}makePost(e,t){return new eV(t,new e2("[PRIORITY-POST]",o(e)))}toString(){return".priority"}}let e5=new e4,e6=Math.log(2);class e8{constructor(e){this.count=parseInt(Math.log(e+1)/e6,10),this.current_=this.count-1;let t=parseInt(Array(this.count+1).join("1"),2);this.bits_=e+1&t}nextBitIsOne(){let e=!(this.bits_&1<<this.current_);return this.current_--,e}}let e7=function(e,t,n,i){e.sort(t);let r=function(t,i){let s;let o=i-t;if(0===o)return null;if(1===o)return s=e[t],new e$(n?n(s):s,s.node,e$.BLACK,null,null);{let l=parseInt(o/2,10)+t,a=r(t,l),h=r(l+1,i);return s=e[l],new e$(n?n(s):s,s.node,e$.BLACK,a,h)}};return new eJ(i||t,function(t){let i=null,s=null,o=e.length,l=function(t,i){let s=o-t,l=o;o-=t;let h=r(s+1,l),u=e[s];a(new e$(n?n(u):u,u.node,i,null,h))},a=function(e){i?i.left=e:s=e,i=e};for(let e=0;e<t.count;++e){let n=t.nextBitIsOne(),i=Math.pow(2,t.count-(e+1));n?l(i,e$.BLACK):(l(i,e$.BLACK),l(i,e$.RED))}return s}(new e8(e.length)))},e9={};class te{constructor(e,t){this.indexes_=e,this.indexSet_=t}static get Default(){return(0,y.hu)(e9&&e5,"ChildrenNode.ts has not been loaded"),a=a||new te({".priority":e9},{".priority":e5})}get(e){let t=(0,y.DV)(this.indexes_,e);if(!t)throw Error("No index defined for "+e);return t instanceof eJ?t:null}hasIndex(e){return(0,y.r3)(this.indexSet_,e.toString())}addIndex(e,t){let n;(0,y.hu)(e!==eQ,"KeyIndex always exists and isn't meant to be added to the IndexMap.");let i=[],r=!1,s=t.getIterator(eV.Wrap),o=s.getNext();for(;o;)r=r||e.isDefinedOn(o.node),i.push(o),o=s.getNext();n=r?e7(i,e.getCompare()):e9;let l=e.toString(),a=Object.assign({},this.indexSet_);a[l]=e;let h=Object.assign({},this.indexes_);return h[l]=n,new te(h,a)}addToIndexes(e,t){return new te((0,y.UI)(this.indexes_,(n,i)=>{let r=(0,y.DV)(this.indexSet_,i);if((0,y.hu)(r,"Missing index implementation for "+i),n===e9){if(!r.isDefinedOn(e.node))return e9;{let n=[],i=t.getIterator(eV.Wrap),s=i.getNext();for(;s;)s.name!==e.name&&n.push(s),s=i.getNext();return n.push(e),e7(n,r.getCompare())}}{let i=t.get(e.name),r=n;return i&&(r=r.remove(new eV(e.name,i))),r.insert(e,e.node)}}),this.indexSet_)}removeFromIndexes(e,t){return new te((0,y.UI)(this.indexes_,n=>{if(n===e9)return n;{let i=t.get(e.name);return i?n.remove(new eV(e.name,i)):n}}),this.indexSet_)}}class tt{constructor(e,t,n){this.children_=e,this.priorityNode_=t,this.indexMap_=n,this.lazyHash_=null,this.priorityNode_&&e3(this.priorityNode_),this.children_.isEmpty()&&(0,y.hu)(!this.priorityNode_||this.priorityNode_.isEmpty(),"An empty node cannot have a priority")}static get EMPTY_NODE(){return h||(h=new tt(new eJ(e0),null,te.Default))}isLeafNode(){return!1}getPriority(){return this.priorityNode_||h}updatePriority(e){return this.children_.isEmpty()?this:new tt(this.children_,e,this.indexMap_)}
286getImmediateChild(e){if(".priority"===e)return this.getPriority();{let t=this.children_.get(e);return null===t?h:t}}getChild(e){let t=eN(e);return null===t?this:this.getImmediateChild(t).getChild(ex(e))}hasChild(e){return null!==this.children_.get(e)}updateImmediateChild(e,t){if((0,y.hu)(t,"We should always be passing snapshot nodes"),".priority"===e)return this.updatePriority(t);{let n,i;let r=new eV(e,t);t.isEmpty()?(n=this.children_.remove(e),i=this.indexMap_.removeFromIndexes(r,this.children_)):(n=this.children_.insert(e,t),i=this.indexMap_.addToIndexes(r,this.children_));let s=n.isEmpty()?h:this.priorityNode_;return new tt(n,s,i)}}updateChild(e,t){let n=eN(e);if(null===n)return t;{(0,y.hu)(".priority"!==eN(e)||1===eS(e),".priority must be the last token in a path");let i=this.getImmediateChild(n).updateChild(ex(e),t);return this.updateImmediateChild(n,i)}}isEmpty(){return this.children_.isEmpty()}numChildren(){return this.children_.count()}val(e){if(this.isEmpty())return null;let t={},n=0,i=0,r=!0;if(this.forEachChild(e5,(s,o)=>{t[s]=o.val(e),n++,r&&tt.INTEGER_REGEXP_.test(s)?i=Math.max(i,Number(s)):r=!1}),e||!r||!(i<2*n))return e&&!this.getPriority().isEmpty()&&(t[".priority"]=this.getPriority().val()),t;{let e=[];for(let n in t)e[n]=t[n];return e}}hash(){if(null===this.lazyHash_){let e="";this.getPriority().isEmpty()||(e+="priority:"+e1(this.getPriority().val())+":"),this.forEachChild(e5,(t,n)=>{let i=n.hash();""!==i&&(e+=":"+t+":"+i)}),this.lazyHash_=""===e?"":R(e)}return this.lazyHash_}getPredecessorChildName(e,t,n){let i=this.resolveIndex_(n);if(!i)return this.children_.getPredecessorKey(e);{let n=i.getPredecessorKey(new eV(e,t));return n?n.name:null}}getFirstChildName(e){let t=this.resolveIndex_(e);if(!t)return this.children_.minKey();{let e=t.minKey();return e&&e.name}}getFirstChild(e){let t=this.getFirstChildName(e);return t?new eV(t,this.children_.get(t)):null}getLastChildName(e){let t=this.resolveIndex_(e);if(!t)return this.children_.maxKey();{let e=t.maxKey();return e&&e.name}}getLastChild(e){let t=this.getLastChildName(e);return t?new eV(t,this.children_.get(t)):null}forEachChild(e,t){let n=this.resolveIndex_(e);return n?n.inorderTraversal(e=>t(e.name,e.node)):this.children_.inorderTraversal(t)}getIterator(e){return this.getIteratorFrom(e.minPost(),e)}getIteratorFrom(e,t){let n=this.resolveIndex_(t);if(n)return n.getIteratorFrom(e,e=>e);{let n=this.children_.getIteratorFrom(e.name,eV.Wrap),i=n.peek();for(;null!=i&&0>t.compare(i,e);)n.getNext(),i=n.peek();return n}}getReverseIterator(e){return this.getReverseIteratorFrom(e.maxPost(),e)}getReverseIteratorFrom(e,t){let n=this.resolveIndex_(t);if(n)return n.getReverseIteratorFrom(e,e=>e);{let n=this.children_.getReverseIteratorFrom(e.name,eV.Wrap),i=n.peek();for(;null!=i&&t.compare(i,e)>0;)n.getNext(),i=n.peek();return n}}compareTo(e){return this.isEmpty()?e.isEmpty()?0:-1:e.isLeafNode()||e.isEmpty()?1:e===ti?-1:0}withIndex(e){if(e===eQ||this.indexMap_.hasIndex(e))return this;{let t=this.indexMap_.addIndex(e,this.children_);return new tt(this.children_,this.priorityNode_,t)}}isIndexed(e){return e===eQ||this.indexMap_.hasIndex(e)}equals(e){if(e===this)return!0;if(e.isLeafNode()||!this.getPriority().equals(e.getPriority())||this.children_.count()!==e.children_.count())return!1;{let t=this.getIterator(e5),n=e.getIterator(e5),i=t.getNext(),r=n.getNext();for(;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}}resolveIndex_(e){return e===eQ?null:this.indexMap_.get(e.toString())}}tt.INTEGER_REGEXP_=/^(0|[1-9]\d*)$/;class tn extends tt{constructor(){super(new eJ(e0),tt.EMPTY_NODE,te.Default)}compareTo(e){return e===this?0:1}equals(e){return e===this}getPriority(){return this}getImmediateChild(e){return tt.EMPTY_NODE}isEmpty(){return!1}}let ti=new tn;function tr(e,t=null){if(null===e)return tt.EMPTY_NODE;if("object"==typeof e&&".priority"in e&&(t=e[".priority"]),(0,y.hu)(null===t||"string"==typeof t||"number"==typeof t||"object"==typeof t&&".sv"in t,"Invalid priority type found: "+typeof t),"object"==typeof e&&".value"in e&&null!==e[".value"]&&(e=e[".value"]),"object"!=typeof e||".sv"in e)return new e2(e,tr(t));if(e instanceof Array){let n=tt.EMPTY_NODE;return X(e,(t,i)=>{if((0,y.r3)(e,t)&&"."!==t.substring(0,1)){let e=tr(i);(e.isLeafNode()||!e.isEmpty())&&(n=n.updateImmediateChild(t,e))}}),n.updatePriority(tr(t))}{let n=[],i=!1;if(X(e,(e,t)=>{if("."!==e.substring(0,1)){let r=tr(t);r.isEmpty()||(i=i||!r.getPriority().isEmpty(),n.push(new eV(e,r)))}}),0===n.length)return tt.EMPTY_NODE;let r=e7(n,eZ,e=>e.name,e0);if(!i)return new tt(r,tr(t),te.Default);{let e=e7(n,e5.getCompare());return new tt(r,tr(t),new te({".priority":e},{".priority":e5}))}}}Object.defineProperties(eV,{MIN:{value:new eV(j,tt.EMPTY_NODE)},MAX:{value:new eV(V,ti)}}),eK.__EMPTY_NODE=tt.EMPTY_NODE,e2.__childrenNodeConstructor=tt,r=ti,l=ti,o=tr;/**
287 * @license
288 * Copyright 2017 Google LLC
289 *
290 * Licensed under the Apache License, Version 2.0 (the "License");
291 * you may not use this file except in compliance with the License.
292 * You may obtain a copy of the License at
293 *
294 *   http://www.apache.org/licenses/LICENSE-2.0
295 *
296 * Unless required by applicable law or agreed to in writing, software
297 * distributed under the License is distributed on an "AS IS" BASIS,
298 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
299 * See the License for the specific language governing permissions and
300 * limitations under the License.
301 */class ts extends eB{constructor(e){super(),this.indexPath_=e,(0,y.hu)(!eq(e)&&".priority"!==eN(e),"Can't create PathIndex with empty path or .priority key")}extractChild(e){return e.getChild(this.indexPath_)}isDefinedOn(e){return!e.getChild(this.indexPath_).isEmpty()}compare(e,t){let n=this.extractChild(e.node),i=this.extractChild(t.node),r=n.compareTo(i);return 0===r?B(e.name,t.name):r}makePost(e,t){let n=tr(e);return new eV(t,tt.EMPTY_NODE.updateChild(this.indexPath_,n))}maxPost(){return new eV(V,tt.EMPTY_NODE.updateChild(this.indexPath_,ti))}toString(){return eD(this.indexPath_,0).join("/")}}/**
302 * @license
303 * Copyright 2017 Google LLC
304 *
305 * Licensed under the Apache License, Version 2.0 (the "License");
306 * you may not use this file except in compliance with the License.
307 * You may obtain a copy of the License at
308 *
309 *   http://www.apache.org/licenses/LICENSE-2.0
310 *
311 * Unless required by applicable law or agreed to in writing, software
312 * distributed under the License is distributed on an "AS IS" BASIS,
313 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
314 * See the License for the specific language governing permissions and
315 * limitations under the License.
316 */class to extends eB{compare(e,t){let n=e.node.compareTo(t.node);return 0===n?B(e.name,t.name):n}isDefinedOn(e){return!0}indexedValueChanged(e,t){return!e.equals(t)}minPost(){return eV.MIN}maxPost(){return eV.MAX}makePost(e,t){return new eV(t,tr(e))}toString(){return".value"}}let tl=new to,ta="-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz",th=function(){let e=0,t=[];return function(n){let i;let r=n===e;e=n;let s=Array(8);for(i=7;i>=0;i--)s[i]=ta.charAt(n%64),n=Math.floor(n/64);(0,y.hu)(0===n,"Cannot push at time == 0");let o=s.join("");if(r){for(i=11;i>=0&&63===t[i];i--)t[i]=0;t[i]++}else for(i=0;i<12;i++)t[i]=Math.floor(64*Math.random());for(i=0;i<12;i++)o+=ta.charAt(t[i]);return(0,y.hu)(20===o.length,"nextPushId: Length should be 20."),o}}();/**
317 * @license
318 * Copyright 2017 Google LLC
319 *
320 * Licensed under the Apache License, Version 2.0 (the "License");
321 * you may not use this file except in compliance with the License.
322 * You may obtain a copy of the License at
323 *
324 *   http://www.apache.org/licenses/LICENSE-2.0
325 *
326 * Unless required by applicable law or agreed to in writing, software
327 * distributed under the License is distributed on an "AS IS" BASIS,
328 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
329 * See the License for the specific language governing permissions and
330 * limitations under the License.
331 */function tu(e){return{type:"value",snapshotNode:e}}function tc(e,t){return{type:"child_added",snapshotNode:t,childName:e}}function td(e,t){return{type:"child_removed",snapshotNode:t,childName:e}}function t_(e,t,n){return{type:"child_changed",snapshotNode:t,childName:e,oldSnap:n}}/**
332 * @license
333 * Copyright 2017 Google LLC
334 *
335 * Licensed under the Apache License, Version 2.0 (the "License");
336 * you may not use this file except in compliance with the License.
337 * You may obtain a copy of the License at
338 *
339 *   http://www.apache.org/licenses/LICENSE-2.0
340 *
341 * Unless required by applicable law or agreed to in writing, software
342 * distributed under the License is distributed on an "AS IS" BASIS,
343 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
344 * See the License for the specific language governing permissions and
345 * limitations under the License.
346 */class tp{constructor(e){this.index_=e}updateChild(e,t,n,i,r,s){(0,y.hu)(e.isIndexed(this.index_),"A node must be indexed if only a child is updated");let o=e.getImmediateChild(t);return o.getChild(i).equals(n.getChild(i))&&o.isEmpty()===n.isEmpty()?e:(null!=s&&(n.isEmpty()?e.hasChild(t)?s.trackChildChange(td(t,o)):(0,y.hu)(e.isLeafNode(),"A child remove without an old child only makes sense on a leaf node"):o.isEmpty()?s.trackChildChange(tc(t,n)):s.trackChildChange(t_(t,n,o))),e.isLeafNode()&&n.isEmpty())?e:e.updateImmediateChild(t,n).withIndex(this.index_)}updateFullNode(e,t,n){return null==n||(e.isLeafNode()||e.forEachChild(e5,(e,i)=>{t.hasChild(e)||n.trackChildChange(td(e,i))}),t.isLeafNode()||t.forEachChild(e5,(t,i)=>{if(e.hasChild(t)){let r=e.getImmediateChild(t);r.equals(i)||n.trackChildChange(t_(t,i,r))}else n.trackChildChange(tc(t,i))})),t.withIndex(this.index_)}updatePriority(e,t){return e.isEmpty()?tt.EMPTY_NODE:e.updatePriority(t)}filtersNodes(){return!1}getIndexedFilter(){return this}getIndex(){return this.index_}}/**
347 * @license
348 * Copyright 2017 Google LLC
349 *
350 * Licensed under the Apache License, Version 2.0 (the "License");
351 * you may not use this file except in compliance with the License.
352 * You may obtain a copy of the License at
353 *
354 *   http://www.apache.org/licenses/LICENSE-2.0
355 *
356 * Unless required by applicable law or agreed to in writing, software
357 * distributed under the License is distributed on an "AS IS" BASIS,
358 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
359 * See the License for the specific language governing permissions and
360 * limitations under the License.
361 */class tf{constructor(e){this.indexedFilter_=new tp(e.getIndex()),this.index_=e.getIndex(),this.startPost_=tf.getStartPost_(e),this.endPost_=tf.getEndPost_(e)}getStartPost(){return this.startPost_}getEndPost(){return this.endPost_}matches(e){return 0>=this.index_.compare(this.getStartPost(),e)&&0>=this.index_.compare(e,this.getEndPost())}updateChild(e,t,n,i,r,s){return this.matches(new eV(t,n))||(n=tt.EMPTY_NODE),this.indexedFilter_.updateChild(e,t,n,i,r,s)}updateFullNode(e,t,n){t.isLeafNode()&&(t=tt.EMPTY_NODE);let i=t.withIndex(this.index_);i=i.updatePriority(tt.EMPTY_NODE);let r=this;return t.forEachChild(e5,(e,t)=>{r.matches(new eV(e,t))||(i=i.updateImmediateChild(e,tt.EMPTY_NODE))}),this.indexedFilter_.updateFullNode(e,i,n)}updatePriority(e,t){return e}filtersNodes(){return!0}getIndexedFilter(){return this.indexedFilter_}getIndex(){return this.index_}static getStartPost_(e){if(!e.hasStart())return e.getIndex().minPost();{let t=e.getIndexStartName();return e.getIndex().makePost(e.getIndexStartValue(),t)}}static getEndPost_(e){if(!e.hasEnd())return e.getIndex().maxPost();{let t=e.getIndexEndName();return e.getIndex().makePost(e.getIndexEndValue(),t)}}}/**
362 * @license
363 * Copyright 2017 Google LLC
364 *
365 * Licensed under the Apache License, Version 2.0 (the "License");
366 * you may not use this file except in compliance with the License.
367 * You may obtain a copy of the License at
368 *
369 *   http://www.apache.org/licenses/LICENSE-2.0
370 *
371 * Unless required by applicable law or agreed to in writing, software
372 * distributed under the License is distributed on an "AS IS" BASIS,
373 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
374 * See the License for the specific language governing permissions and
375 * limitations under the License.
376 */class tg{constructor(e){this.rangedFilter_=new tf(e),this.index_=e.getIndex(),this.limit_=e.getLimit(),this.reverse_=!e.isViewFromLeft()}updateChild(e,t,n,i,r,s){return(this.rangedFilter_.matches(new eV(t,n))||(n=tt.EMPTY_NODE),e.getImmediateChild(t).equals(n))?e:e.numChildren()<this.limit_?this.rangedFilter_.getIndexedFilter().updateChild(e,t,n,i,r,s):this.fullLimitUpdateChild_(e,t,n,r,s)}updateFullNode(e,t,n){let i;if(t.isLeafNode()||t.isEmpty())i=tt.EMPTY_NODE.withIndex(this.index_);else if(2*this.limit_<t.numChildren()&&t.isIndexed(this.index_)){let e;i=tt.EMPTY_NODE.withIndex(this.index_),e=this.reverse_?t.getReverseIteratorFrom(this.rangedFilter_.getEndPost(),this.index_):t.getIteratorFrom(this.rangedFilter_.getStartPost(),this.index_);let n=0;for(;e.hasNext()&&n<this.limit_;){let t=e.getNext();if(this.reverse_?0>=this.index_.compare(this.rangedFilter_.getStartPost(),t):0>=this.index_.compare(t,this.rangedFilter_.getEndPost()))i=i.updateImmediateChild(t.name,t.node),n++;else break}}else{let e,n,r,s;if(i=(i=t.withIndex(this.index_)).updatePriority(tt.EMPTY_NODE),this.reverse_){s=i.getReverseIterator(this.index_),e=this.rangedFilter_.getEndPost(),n=this.rangedFilter_.getStartPost();let t=this.index_.getCompare();r=(e,n)=>t(n,e)}else s=i.getIterator(this.index_),e=this.rangedFilter_.getStartPost(),n=this.rangedFilter_.getEndPost(),r=this.index_.getCompare();let o=0,l=!1;for(;s.hasNext();){let t=s.getNext();!l&&0>=r(e,t)&&(l=!0),l&&o<this.limit_&&0>=r(t,n)?o++:i=i.updateImmediateChild(t.name,tt.EMPTY_NODE)}}return this.rangedFilter_.getIndexedFilter().updateFullNode(e,i,n)}updatePriority(e,t){return e}filtersNodes(){return!0}getIndexedFilter(){return this.rangedFilter_.getIndexedFilter()}getIndex(){return this.index_}fullLimitUpdateChild_(e,t,n,i,r){let s;if(this.reverse_){let e=this.index_.getCompare();s=(t,n)=>e(n,t)}else s=this.index_.getCompare();(0,y.hu)(e.numChildren()===this.limit_,"");let o=new eV(t,n),l=this.reverse_?e.getFirstChild(this.index_):e.getLastChild(this.index_),a=this.rangedFilter_.matches(o);if(e.hasChild(t)){let h=e.getImmediateChild(t),u=i.getChildAfterChild(this.index_,l,this.reverse_);for(;null!=u&&(u.name===t||e.hasChild(u.name));)u=i.getChildAfterChild(this.index_,u,this.reverse_);let c=null==u?1:s(u,o);if(a&&!n.isEmpty()&&c>=0)return null!=r&&r.trackChildChange(t_(t,n,h)),e.updateImmediateChild(t,n);{null!=r&&r.trackChildChange(td(t,h));let n=e.updateImmediateChild(t,tt.EMPTY_NODE);return null!=u&&this.rangedFilter_.matches(u)?(null!=r&&r.trackChildChange(tc(u.name,u.node)),n.updateImmediateChild(u.name,u.node)):n}}return n.isEmpty()?e:a&&s(l,o)>=0?(null!=r&&(r.trackChildChange(td(l.name,l.node)),r.trackChildChange(tc(t,n))),e.updateImmediateChild(t,n).updateImmediateChild(l.name,tt.EMPTY_NODE)):e}}/**
377 * @license
378 * Copyright 2017 Google LLC
379 *
380 * Licensed under the Apache License, Version 2.0 (the "License");
381 * you may not use this file except in compliance with the License.
382 * You may obtain a copy of the License at
383 *
384 *   http://www.apache.org/licenses/LICENSE-2.0
385 *
386 * Unless required by applicable law or agreed to in writing, software
387 * distributed under the License is distributed on an "AS IS" BASIS,
388 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
389 * See the License for the specific language governing permissions and
390 * limitations under the License.
391 */class tm{constructor(){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_=e5}hasStart(){return this.startSet_}hasStartAfter(){return this.startAfterSet_}hasEndBefore(){return this.endBeforeSet_}isViewFromLeft(){return""===this.viewFrom_?this.startSet_:"l"===this.viewFrom_}getIndexStartValue(){return(0,y.hu)(this.startSet_,"Only valid if start has been set"),this.indexStartValue_}getIndexStartName(){return((0,y.hu)(this.startSet_,"Only valid if start has been set"),this.startNameSet_)?this.indexStartName_:j}hasEnd(){return this.endSet_}getIndexEndValue(){return(0,y.hu)(this.endSet_,"Only valid if end has been set"),this.indexEndValue_}getIndexEndName(){return((0,y.hu)(this.endSet_,"Only valid if end has been set"),this.endNameSet_)?this.indexEndName_:V}hasLimit(){return this.limitSet_}hasAnchoredLimit(){return this.limitSet_&&""!==this.viewFrom_}getLimit(){return(0,y.hu)(this.limitSet_,"Only valid if limit has been set"),this.limit_}getIndex(){return this.index_}loadsAllData(){return!(this.startSet_||this.endSet_||this.limitSet_)}isDefault(){return this.loadsAllData()&&this.index_===e5}copy(){let e=new tm;return e.limitSet_=this.limitSet_,e.limit_=this.limit_,e.startSet_=this.startSet_,e.indexStartValue_=this.indexStartValue_,e.startNameSet_=this.startNameSet_,e.indexStartName_=this.indexStartName_,e.endSet_=this.endSet_,e.indexEndValue_=this.indexEndValue_,e.endNameSet_=this.endNameSet_,e.indexEndName_=this.indexEndName_,e.index_=this.index_,e.viewFrom_=this.viewFrom_,e}}function ty(e){let t;let n={};return e.isDefault()||(e.index_===e5?t="$priority":e.index_===tl?t="$value":e.index_===eQ?t="$key":((0,y.hu)(e.index_ instanceof ts,"Unrecognized index type!"),t=e.index_.toString()),n.orderBy=(0,y.Pz)(t),e.startSet_&&(n.startAt=(0,y.Pz)(e.indexStartValue_),e.startNameSet_&&(n.startAt+=","+(0,y.Pz)(e.indexStartName_))),e.endSet_&&(n.endAt=(0,y.Pz)(e.indexEndValue_),e.endNameSet_&&(n.endAt+=","+(0,y.Pz)(e.indexEndName_))),e.limitSet_&&(e.isViewFromLeft()?n.limitToFirst=e.limit_:n.limitToLast=e.limit_)),n}function tv(e){let t={};if(e.startSet_&&(t.sp=e.indexStartValue_,e.startNameSet_&&(t.sn=e.indexStartName_)),e.endSet_&&(t.ep=e.indexEndValue_,e.endNameSet_&&(t.en=e.indexEndName_)),e.limitSet_){t.l=e.limit_;let n=e.viewFrom_;""===n&&(n=e.isViewFromLeft()?"l":"r"),t.vf=n}return e.index_!==e5&&(t.i=e.index_.toString()),t}/**
392 * @license
393 * Copyright 2017 Google LLC
394 *
395 * Licensed under the Apache License, Version 2.0 (the "License");
396 * you may not use this file except in compliance with the License.
397 * You may obtain a copy of the License at
398 *
399 *   http://www.apache.org/licenses/LICENSE-2.0
400 *
401 * Unless required by applicable law or agreed to in writing, software
402 * distributed under the License is distributed on an "AS IS" BASIS,
403 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
404 * See the License for the specific language governing permissions and
405 * limitations under the License.
406 */class tC extends eI{constructor(e,t,n,i){super(),this.repoInfo_=e,this.onDataUpdate_=t,this.authTokenProvider_=n,this.appCheckTokenProvider_=i,this.log_=A("p:rest:"),this.listens_={}}reportStats(e){throw Error("Method not implemented.")}static getListenId_(e,t){return void 0!==t?"tag$"+t:((0,y.hu)(e._queryParams.isDefault(),"should have a tag if it's not a default query."),e._path.toString())}listen(e,t,n,i){let r=e._path.toString();this.log_("Listen called for "+r+" "+e._queryIdentifier);let s=tC.getListenId_(e,n),o={};this.listens_[s]=o;let l=ty(e._queryParams);this.restRequest_(r+".json",l,(e,t)=>{let l=t;404===e&&(l=null,e=null),null===e&&this.onDataUpdate_(r,l,!1,n),(0,y.DV)(this.listens_,s)===o&&i(e?401===e?"permission_denied":"rest_error:"+e:"ok",null)})}unlisten(e,t){let n=tC.getListenId_(e,t);delete this.listens_[n]}get(e){let t=ty(e._queryParams),n=e._path.toString(),i=new y.BH;return this.restRequest_(n+".json",t,(e,t)=>{let r=t;404===e&&(r=null,e=null),null===e?(this.onDataUpdate_(n,r,!1,null),i.resolve(r)):i.reject(Error(r))}),i.promise}refreshAuthToken(e){}restRequest_(e,t={},n){return t.format="export",Promise.all([this.authTokenProvider_.getToken(!1),this.appCheckTokenProvider_.getToken(!1)]).then(([i,r])=>{i&&i.accessToken&&(t.auth=i.accessToken),r&&r.token&&(t.ac=r.token);let s=(this.repoInfo_.secure?"https://":"http://")+this.repoInfo_.host+e+"?ns="+this.repoInfo_.namespace+(0,y.xO)(t);this.log_("Sending REST request for "+s);let o=new XMLHttpRequest;o.onreadystatechange=()=>{if(n&&4===o.readyState){this.log_("REST Response for "+s+" received. status:",o.status,"response:",o.responseText);let e=null;if(o.status>=200&&o.status<300){try{e=(0,y.cI)(o.responseText)}catch(e){U("Failed to parse JSON response for "+s+": "+o.responseText)}n(null,e)}else 401!==o.status&&404!==o.status&&U("Got unsuccessful REST response for "+s+" Status: "+o.status),n(o.status);n=null}},o.open("GET",s,!0),o.send()})}}/**
407 * @license
408 * Copyright 2017 Google LLC
409 *
410 * Licensed under the Apache License, Version 2.0 (the "License");
411 * you may not use this file except in compliance with the License.
412 * You may obtain a copy of the License at
413 *
414 *   http://www.apache.org/licenses/LICENSE-2.0
415 *
416 * Unless required by applicable law or agreed to in writing, software
417 * distributed under the License is distributed on an "AS IS" BASIS,
418 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
419 * See the License for the specific language governing permissions and
420 * limitations under the License.
421 */class tw{constructor(){this.rootNode_=tt.EMPTY_NODE}getNode(e){return this.rootNode_.getChild(e)}updateSnapshot(e,t){this.rootNode_=this.rootNode_.updateChild(e,t)}}/**
422 * @license
423 * Copyright 2017 Google LLC
424 *
425 * Licensed under the Apache License, Version 2.0 (the "License");
426 * you may not use this file except in compliance with the License.
427 * You may obtain a copy of the License at
428 *
429 *   http://www.apache.org/licenses/LICENSE-2.0
430 *
431 * Unless required by applicable law or agreed to in writing, software
432 * distributed under the License is distributed on an "AS IS" BASIS,
433 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
434 * See the License for the specific language governing permissions and
435 * limitations under the License.
436 */function tT(){return{value:null,children:new Map}}function tI(e,t,n){null!==e.value?n(t,e.value):function(e,t){e.children.forEach((e,n)=>{t(n,e)})}(e,(e,i)=>{tI(i,new eE(t.toString()+"/"+e),n)})}/**
437 * @license
438 * Copyright 2017 Google LLC
439 *
440 * Licensed under the Apache License, Version 2.0 (the "License");
441 * you may not use this file except in compliance with the License.
442 * You may obtain a copy of the License at
443 *
444 *   http://www.apache.org/licenses/LICENSE-2.0
445 *
446 * Unless required by applicable law or agreed to in writing, software
447 * distributed under the License is distributed on an "AS IS" BASIS,
448 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
449 * See the License for the specific language governing permissions and
450 * limitations under the License.
451 */class tb{constructor(e){this.collection_=e,this.last_=null}get(){let e=this.collection_.get(),t=Object.assign({},e);return this.last_&&X(this.last_,(e,n)=>{t[e]=t[e]-n}),this.last_=e,t}}class tk{constructor(e,t){this.server_=t,this.statsToReport_={},this.statsListener_=new tb(e),en(this.reportStats_.bind(this),Math.floor(1e4+2e4*Math.random()))}reportStats_(){let e=this.statsListener_.get(),t={},n=!1;X(e,(e,i)=>{i>0&&(0,y.r3)(this.statsToReport_,e)&&(t[e]=i,n=!0)}),n&&this.server_.reportStats(t),en(this.reportStats_.bind(this),Math.floor(2*Math.random()*3e5))}}function tE(){return{fromUser:!0,fromServer:!1,queryId:null,tagged:!1}}function tP(){return{fromUser:!1,fromServer:!0,queryId:null,tagged:!1}}function tN(e){return{fromUser:!1,fromServer:!0,queryId:e,tagged:!0}}(p=f||(f={}))[p.OVERWRITE=0]="OVERWRITE",p[p.MERGE=1]="MERGE",p[p.ACK_USER_WRITE=2]="ACK_USER_WRITE",p[p.LISTEN_COMPLETE=3]="LISTEN_COMPLETE";/**
452 * @license
453 * Copyright 2017 Google LLC
454 *
455 * Licensed under the Apache License, Version 2.0 (the "License");
456 * you may not use this file except in compliance with the License.
457 * You may obtain a copy of the License at
458 *
459 *   http://www.apache.org/licenses/LICENSE-2.0
460 *
461 * Unless required by applicable law or agreed to in writing, software
462 * distributed under the License is distributed on an "AS IS" BASIS,
463 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
464 * See the License for the specific language governing permissions and
465 * limitations under the License.
466 */class tS{constructor(e,t,n){this.path=e,this.affectedTree=t,this.revert=n,this.type=f.ACK_USER_WRITE,this.source=tE()}operationForChild(e){if(!eq(this.path))return(0,y.hu)(eN(this.path)===e,"operationForChild called for unrelated child."),new tS(ex(this.path),this.affectedTree,this.revert);if(null!=this.affectedTree.value)return(0,y.hu)(this.affectedTree.children.isEmpty(),"affectedTree should not have overlapping affected paths."),this;{let t=this.affectedTree.subtree(new eE(e));return new tS(eP(),t,this.revert)}}}/**
467 * @license
468 * Copyright 2017 Google LLC
469 *
470 * Licensed under the Apache License, Version 2.0 (the "License");
471 * you may not use this file except in compliance with the License.
472 * You may obtain a copy of the License at
473 *
474 *   http://www.apache.org/licenses/LICENSE-2.0
475 *
476 * Unless required by applicable law or agreed to in writing, software
477 * distributed under the License is distributed on an "AS IS" BASIS,
478 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
479 * See the License for the specific language governing permissions and
480 * limitations under the License.
481 */class tx{constructor(e,t){this.source=e,this.path=t,this.type=f.LISTEN_COMPLETE}operationForChild(e){return eq(this.path)?new tx(this.source,eP()):new tx(this.source,ex(this.path))}}/**
482 * @license
483 * Copyright 2017 Google LLC
484 *
485 * Licensed under the Apache License, Version 2.0 (the "License");
486 * you may not use this file except in compliance with the License.
487 * You may obtain a copy of the License at
488 *
489 *   http://www.apache.org/licenses/LICENSE-2.0
490 *
491 * Unless required by applicable law or agreed to in writing, software
492 * distributed under the License is distributed on an "AS IS" BASIS,
493 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
494 * See the License for the specific language governing permissions and
495 * limitations under the License.
496 */class tR{constructor(e,t,n){this.source=e,this.path=t,this.snap=n,this.type=f.OVERWRITE}operationForChild(e){return eq(this.path)?new tR(this.source,eP(),this.snap.getImmediateChild(e)):new tR(this.source,ex(this.path),this.snap)}}/**
497 * @license
498 * Copyright 2017 Google LLC
499 *
500 * Licensed under the Apache License, Version 2.0 (the "License");
501 * you may not use this file except in compliance with the License.
502 * You may obtain a copy of the License at
503 *
504 *   http://www.apache.org/licenses/LICENSE-2.0
505 *
506 * Unless required by applicable law or agreed to in writing, software
507 * distributed under the License is distributed on an "AS IS" BASIS,
508 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
509 * See the License for the specific language governing permissions and
510 * limitations under the License.
511 */class tD{constructor(e,t,n){this.source=e,this.path=t,this.children=n,this.type=f.MERGE}operationForChild(e){if(!eq(this.path))return(0,y.hu)(eN(this.path)===e,"Can't get a merge for a child not on the path of the operation"),new tD(this.source,ex(this.path),this.children);{let t=this.children.subtree(new eE(e));return t.isEmpty()?null:t.value?new tR(this.source,eP(),t.value):new tD(this.source,eP(),t)}}toString(){return"Operation("+this.path+": "+this.source.toString()+" merge: "+this.children.toString()+")"}}/**
512 * @license
513 * Copyright 2017 Google LLC
514 *
515 * Licensed under the Apache License, Version 2.0 (the "License");
516 * you may not use this file except in compliance with the License.
517 * You may obtain a copy of the License at
518 *
519 *   http://www.apache.org/licenses/LICENSE-2.0
520 *
521 * Unless required by applicable law or agreed to in writing, software
522 * distributed under the License is distributed on an "AS IS" BASIS,
523 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
524 * See the License for the specific language governing permissions and
525 * limitations under the License.
526 */class tM{constructor(e,t,n){this.node_=e,this.fullyInitialized_=t,this.filtered_=n}isFullyInitialized(){return this.fullyInitialized_}isFiltered(){return this.filtered_}isCompleteForPath(e){if(eq(e))return this.isFullyInitialized()&&!this.filtered_;let t=eN(e);return this.isCompleteForChild(t)}isCompleteForChild(e){return this.isFullyInitialized()&&!this.filtered_||this.node_.hasChild(e)}getNode(){return this.node_}}/**
527 * @license
528 * Copyright 2017 Google LLC
529 *
530 * Licensed under the Apache License, Version 2.0 (the "License");
531 * you may not use this file except in compliance with the License.
532 * You may obtain a copy of the License at
533 *
534 *   http://www.apache.org/licenses/LICENSE-2.0
535 *
536 * Unless required by applicable law or agreed to in writing, software
537 * distributed under the License is distributed on an "AS IS" BASIS,
538 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
539 * See the License for the specific language governing permissions and
540 * limitations under the License.
541 */class tF{constructor(e){this.query_=e,this.index_=this.query_._queryParams.getIndex()}}function tq(e,t,n,i,r,s){let o=i.filter(e=>e.type===n);o.sort((t,n)=>(function(e,t,n){if(null==t.childName||null==n.childName)throw(0,y.g5)("Should only compare child_ events.");let i=new eV(t.childName,t.snapshotNode),r=new eV(n.childName,n.snapshotNode);return e.index_.compare(i,r)})(e,t,n)),o.forEach(n=>{let i=("value"===n.type||"child_removed"===n.type||(n.prevName=s.getPredecessorChildName(n.childName,n.snapshotNode,e.index_)),n);r.forEach(r=>{r.respondsTo(n.type)&&t.push(r.createEvent(i,e.query_))})})}/**
542 * @license
543 * Copyright 2017 Google LLC
544 *
545 * Licensed under the Apache License, Version 2.0 (the "License");
546 * you may not use this file except in compliance with the License.
547 * You may obtain a copy of the License at
548 *
549 *   http://www.apache.org/licenses/LICENSE-2.0
550 *
551 * Unless required by applicable law or agreed to in writing, software
552 * distributed under the License is distributed on an "AS IS" BASIS,
553 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
554 * See the License for the specific language governing permissions and
555 * limitations under the License.
556 */function tO(e,t){return{eventCache:e,serverCache:t}}function tA(e,t,n,i){return tO(new tM(t,n,i),e.serverCache)}function tL(e,t,n,i){return tO(e.eventCache,new tM(t,n,i))}function tW(e){return e.eventCache.isFullyInitialized()?e.eventCache.getNode():null}function tU(e){return e.serverCache.isFullyInitialized()?e.serverCache.getNode():null}let tz=()=>(u||(u=new eJ(K)),u);class tH{constructor(e,t=tz()){this.value=e,this.children=t}static fromObject(e){let t=new tH(null);return X(e,(e,n)=>{t=t.set(new eE(e),n)}),t}isEmpty(){return null===this.value&&this.children.isEmpty()}findRootMostMatchingPathAndValue(e,t){if(null!=this.value&&t(this.value))return{path:eP(),value:this.value};if(eq(e))return null;{let n=eN(e),i=this.children.get(n);if(null===i)return null;{let r=i.findRootMostMatchingPathAndValue(ex(e),t);return null!=r?{path:eF(new eE(n),r.path),value:r.value}:null}}}findRootMostValueAndPath(e){return this.findRootMostMatchingPathAndValue(e,()=>!0)}subtree(e){if(eq(e))return this;{let t=eN(e),n=this.children.get(t);return null!==n?n.subtree(ex(e)):new tH(null)}}set(e,t){if(eq(e))return new tH(t,this.children);{let n=eN(e),i=(this.children.get(n)||new tH(null)).set(ex(e),t),r=this.children.insert(n,i);return new tH(this.value,r)}}remove(e){if(eq(e))return this.children.isEmpty()?new tH(null):new tH(null,this.children);{let t=eN(e),n=this.children.get(t);if(!n)return this;{let i;let r=n.remove(ex(e));return(i=r.isEmpty()?this.children.remove(t):this.children.insert(t,r),null===this.value&&i.isEmpty())?new tH(null):new tH(this.value,i)}}}get(e){if(eq(e))return this.value;{let t=eN(e),n=this.children.get(t);return n?n.get(ex(e)):null}}setTree(e,t){if(eq(e))return t;{let n;let i=eN(e),r=(this.children.get(i)||new tH(null)).setTree(ex(e),t);return n=r.isEmpty()?this.children.remove(i):this.children.insert(i,r),new tH(this.value,n)}}fold(e){return this.fold_(eP(),e)}fold_(e,t){let n={};return this.children.inorderTraversal((i,r)=>{n[i]=r.fold_(eF(e,i),t)}),t(e,this.value,n)}findOnPath(e,t){return this.findOnPath_(e,eP(),t)}findOnPath_(e,t,n){let i=!!this.value&&n(t,this.value);if(i)return i;if(eq(e))return null;{let i=eN(e),r=this.children.get(i);return r?r.findOnPath_(ex(e),eF(t,i),n):null}}foreachOnPath(e,t){return this.foreachOnPath_(e,eP(),t)}foreachOnPath_(e,t,n){if(eq(e))return this;{this.value&&n(t,this.value);let i=eN(e),r=this.children.get(i);return r?r.foreachOnPath_(ex(e),eF(t,i),n):new tH(null)}}foreach(e){this.foreach_(eP(),e)}foreach_(e,t){this.children.inorderTraversal((n,i)=>{i.foreach_(eF(e,n),t)}),this.value&&t(e,this.value)}foreachChild(e){this.children.inorderTraversal((t,n)=>{n.value&&e(t,n.value)})}}/**
557 * @license
558 * Copyright 2017 Google LLC
559 *
560 * Licensed under the Apache License, Version 2.0 (the "License");
561 * you may not use this file except in compliance with the License.
562 * You may obtain a copy of the License at
563 *
564 *   http://www.apache.org/licenses/LICENSE-2.0
565 *
566 * Unless required by applicable law or agreed to in writing, software
567 * distributed under the License is distributed on an "AS IS" BASIS,
568 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
569 * See the License for the specific language governing permissions and
570 * limitations under the License.
571 */class tY{constructor(e){this.writeTree_=e}static empty(){return new tY(new tH(null))}}function tj(e,t,n){if(eq(t))return new tY(new tH(n));{let i=e.writeTree_.findRootMostValueAndPath(t);if(null!=i){let r=i.path,s=i.value,o=eO(r,t);return s=s.updateChild(o,n),new tY(e.writeTree_.set(r,s))}{let i=new tH(n);return new tY(e.writeTree_.setTree(t,i))}}}
571function tV(e,t,n){let i=e;return X(n,(e,n)=>{i=tj(i,eF(t,e),n)}),i}function tB(e,t){return eq(t)?tY.empty():new tY(e.writeTree_.setTree(t,new tH(null)))}function tK(e,t){return null!=tQ(e,t)}function tQ(e,t){let n=e.writeTree_.findRootMostValueAndPath(t);return null!=n?e.writeTree_.get(n.path).getChild(eO(n.path,t)):null}function tG(e){let t=[],n=e.writeTree_.value;return null!=n?n.isLeafNode()||n.forEachChild(e5,(e,n)=>{t.push(new eV(e,n))}):e.writeTree_.children.inorderTraversal((e,n)=>{null!=n.value&&t.push(new eV(e,n.value))}),t}function t$(e,t){if(eq(t))return e;{let n=tQ(e,t);return new tY(null!=n?new tH(n):e.writeTree_.subtree(t))}}function tX(e){return e.writeTree_.isEmpty()}function tJ(e,t){return function e(t,n,i){if(null!=n.value)return i.updateChild(t,n.value);{let r=null;return n.children.inorderTraversal((n,s)=>{".priority"===n?((0,y.hu)(null!==s.value,"Priority writes must always be leaf nodes"),r=s.value):i=e(eF(t,n),s,i)}),i.getChild(t).isEmpty()||null===r||(i=i.updateChild(eF(t,".priority"),r)),i}}(eP(),e.writeTree_,t)}function tZ(e){return e.visible}function t0(e,t,n){let i=tY.empty();for(let r=0;r<e.length;++r){let s=e[r];if(t(s)){let e;let t=s.path;if(s.snap)eW(n,t)?i=tj(i,e=eO(n,t),s.snap):eW(t,n)&&(e=eO(t,n),i=tj(i,eP(),s.snap.getChild(e)));else if(s.children){if(eW(n,t))i=tV(i,e=eO(n,t),s.children);else if(eW(t,n)){if(eq(e=eO(t,n)))i=tV(i,eP(),s.children);else{let t=(0,y.DV)(s.children,eN(e));if(t){let n=t.getChild(ex(e));i=tj(i,eP(),n)}}}}else throw(0,y.g5)("WriteRecord should have .snap or .children")}}return i}function t1(e,t,n,i,r){if(i||r){let s=t$(e.visibleWrites,t);return!r&&tX(s)?n:r||null!=n||tK(s,eP())?tJ(t0(e.allWrites,function(e){return(e.visible||r)&&(!i||!~i.indexOf(e.writeId))&&(eW(e.path,t)||eW(t,e.path))},t),n||tt.EMPTY_NODE):null}{let i=tQ(e.visibleWrites,t);if(null!=i)return i;{let i=t$(e.visibleWrites,t);return tX(i)?n:null!=n||tK(i,eP())?tJ(i,n||tt.EMPTY_NODE):null}}}function t3(e,t,n,i){return t1(e.writeTree,e.treePath,t,n,i)}function t2(e,t){return function(e,t,n){let i=tt.EMPTY_NODE,r=tQ(e.visibleWrites,t);if(r)return r.isLeafNode()||r.forEachChild(e5,(e,t)=>{i=i.updateImmediateChild(e,t)}),i;
571if(!n)return tG(t$(e.visibleWrites,t)).forEach(e=>{i=i.updateImmediateChild(e.name,e.node)}),i;{let r=t$(e.visibleWrites,t);return n.forEachChild(e5,(e,t)=>{let n=tJ(t$(r,new eE(e)),t);i=i.updateImmediateChild(e,n)}),tG(r).forEach(e=>{i=i.updateImmediateChild(e.name,e.node)}),i}}(e.writeTree,e.treePath,t)}function t4(e,t,n,i){return function(e,t,n,i,r){(0,y.hu)(i||r,"Either existingEventSnap or existingServerSnap must exist");let s=eF(t,n);if(tK(e.visibleWrites,s))return null;{let t=t$(e.visibleWrites,s);return tX(t)?r.getChild(n):tJ(t,r.getChild(n))}}(e.writeTree,e.treePath,t,n,i)}function t5(e,t){var n,i;return n=e.writeTree,i=eF(e.treePath,t),tQ(n.visibleWrites,i)}function t6(e,t,n){return function(e,t,n,i){let r=eF(t,n),s=tQ(e.visibleWrites,r);return null!=s?s:i.isCompleteForChild(n)?tJ(t$(e.visibleWrites,r),i.getNode().getImmediateChild(n)):null}(e.writeTree,e.treePath,t,n)}function t8(e,t){return t7(eF(e.treePath,t),e.writeTree)}function t7(e,t){return{treePath:e,writeTree:t}}/**
572 * @license
573 * Copyright 2017 Google LLC
574 *
575 * Licensed under the Apache License, Version 2.0 (the "License");
576 * you may not use this file except in compliance with the License.
577 * You may obtain a copy of the License at
578 *
579 *   http://www.apache.org/licenses/LICENSE-2.0
580 *
581 * Unless required by applicable law or agreed to in writing, software
582 * distributed under the License is distributed on an "AS IS" BASIS,
583 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
584 * See the License for the specific language governing permissions and
585 * limitations under the License.
586 */class t9{constructor(){this.changeMap=new Map}trackChildChange(e){let t=e.type,n=e.childName;(0,y.hu)("child_added"===t||"child_changed"===t||"child_removed"===t,"Only child changes supported for tracking"),(0,y.hu)(".priority"!==n,"Only non-priority child changes can be tracked.");let i=this.changeMap.get(n);if(i){let r=i.type;if("child_added"===t&&"child_removed"===r)this.changeMap.set(n,t_(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,td(n,i.oldSnap));else if("child_changed"===t&&"child_added"===r)this.changeMap.set(n,tc(n,e.snapshotNode));else if("child_changed"===t&&"child_changed"===r)this.changeMap.set(n,t_(n,e.snapshotNode,i.oldSnap));else throw(0,y.g5)("Illegal combination of changes: "+e+" occurred after "+i)}else this.changeMap.set(n,e)}getChanges(){return Array.from(this.changeMap.values())}}/**
587 * @license
588 * Copyright 2017 Google LLC
589 *
590 * Licensed under the Apache License, Version 2.0 (the "License");
591 * you may not use this file except in compliance with the License.
592 * You may obtain a copy of the License at
593 *
594 *   http://www.apache.org/licenses/LICENSE-2.0
595 *
596 * Unless required by applicable law or agreed to in writing, software
597 * distributed under the License is distributed on an "AS IS" BASIS,
598 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
599 * See the License for the specific language governing permissions and
600 * limitations under the License.
601 */class ne{getCompleteChild(e){return null}getChildAfterChild(e,t,n){return null}}let nt=new ne;class nn{constructor(e,t,n=null){this.writes_=e,this.viewCache_=t,this.optCompleteServerCache_=n}getCompleteChild(e){let t=this.viewCache_.eventCache;if(t.isCompleteForChild(e))return t.getNode().getImmediateChild(e);{let t=null!=this.optCompleteServerCache_?new tM(this.optCompleteServerCache_,!0,!1):this.viewCache_.serverCache;return t6(this.writes_,e,t)}}getChildAfterChild(e,t,n){var i;let r=null!=this.optCompleteServerCache_?this.optCompleteServerCache_:tU(this.viewCache_),s=function(e,t,n,i,r,s,o){let l;let a=t$(e.visibleWrites,t),h=tQ(a,eP());if(null!=h)l=h;else{if(null==n)return[];l=tJ(a,n)}if((l=l.withIndex(o)).isEmpty()||l.isLeafNode())return[];{let e=[],t=o.getCompare(),n=s?l.getReverseIteratorFrom(i,o):l.getIteratorFrom(i,o),r=n.getNext();for(;r&&e.length<1;)0!==t(r,i)&&e.push(r),r=n.getNext();return e}}((i=this.writes_).writeTree,i.treePath,r,t,0,n,e);return 0===s.length?null:s[0]}}function ni(e,t,n,i,r,s){let o=t.eventCache;if(null!=t5(i,n))return t;{let l,a;
601if(eq(n)){if((0,y.hu)(t.serverCache.isFullyInitialized(),"If change path is empty, we must have complete server data"),t.serverCache.isFiltered()){let n=tU(t),r=t2(i,n instanceof tt?n:tt.EMPTY_NODE);l=e.filter.updateFullNode(t.eventCache.getNode(),r,s)}else{let n=t3(i,tU(t));l=e.filter.updateFullNode(t.eventCache.getNode(),n,s)}}else{let h=eN(n);if(".priority"===h){(0,y.hu)(1===eS(n),"Can't have a priority with additional path components");let r=o.getNode(),s=t4(i,n,r,a=t.serverCache.getNode());l=null!=s?e.filter.updatePriority(r,s):o.getNode()}else{let u;let c=ex(n);if(o.isCompleteForChild(h)){a=t.serverCache.getNode();let e=t4(i,n,o.getNode(),a);u=null!=e?o.getNode().getImmediateChild(h).updateChild(c,e):o.getNode().getImmediateChild(h)}else u=t6(i,h,t.serverCache);l=null!=u?e.filter.updateChild(o.getNode(),h,u,c,r,s):o.getNode()}}return tA(t,l,o.isFullyInitialized()||eq(n),e.filter.filtersNodes())}}function nr(e,t,n,i,r,s,o,l){let a;let h=t.serverCache,u=o?e.filter:e.filter.getIndexedFilter();if(eq(n))a=u.updateFullNode(h.getNode(),i,null);else if(u.filtersNodes()&&!h.isFiltered()){let e=h.getNode().updateChild(n,i);a=u.updateFullNode(h.getNode(),e,null)}else{let e=eN(n);if(!h.isCompleteForPath(n)&&eS(n)>1)return t;let r=ex(n),s=h.getNode().getImmediateChild(e).updateChild(r,i);a=".priority"===e?u.updatePriority(h.getNode(),s):u.updateChild(h.getNode(),e,s,r,nt,null)}let c=tL(t,a,h.isFullyInitialized()||eq(n),u.filtersNodes()),d=new nn(r,c,s);return ni(e,c,n,r,d,l)}function ns(e,t,n,i,r,s,o){let l,a;let h=t.eventCache,u=new nn(r,t,s);if(eq(n))a=e.filter.updateFullNode(t.eventCache.getNode(),i,o),l=tA(t,a,!0,e.filter.filtersNodes());else{let r=eN(n);if(".priority"===r)a=e.filter.updatePriority(t.eventCache.getNode(),i),l=tA(t,a,h.isFullyInitialized(),h.isFiltered());else{let s;let a=ex(n),c=h.getNode().getImmediateChild(r);if(eq(a))s=i;else{let e=u.getCompleteChild(r);s=null!=e?".priority"===eR(a)&&e.getChild(eM(a)).isEmpty()?e:e.updateChild(a,i):tt.EMPTY_NODE}l=c.equals(s)?t:tA(t,e.filter.updateChild(h.getNode(),r,s,a,u,o),h.isFullyInitialized(),e.filter.filtersNodes())}}return l}function no(e,t){return e.eventCache.isCompleteForChild(t)}function nl(e,t,n){return n.foreach((e,n)=>{t=t.updateChild(e,n)}),t}function na(e,t,n,i,r,s,o,l){let a;if(t.serverCache.getNode().isEmpty()&&!t.serverCache.isFullyInitialized())return t;let h=t;a=eq(n)?i:new tH(null).setTree(n,i);let u=t.serverCache.getNode();return a.children.inorderTraversal((n,i)=>{if(u.hasChild(n)){let a=nl(e,t.serverCache.getNode().getImmediateChild(n),i);h=nr(e,h,new eE(n),a,r,s,o,l)}}),a.children.inorderTraversal((n,i)=>{let a=!t.serverCache.isCompleteForChild(n)&&null===i.value;if(!u.hasChild(n)&&!a){let a=nl(e,t.serverCache.getNode().getImmediateChild(n),i);h=nr(e,h,new eE(n),a,r,s,o,l)}}),h}/**
602 * @license
603 * Copyright 2017 Google LLC
604 *
605 * Licensed under the Apache License, Version 2.0 (the "License");
606 * you may not use this file except in compliance with the License.
607 * You may obtain a copy of the License at
608 *
609 *   http://www.apache.org/licenses/LICENSE-2.0
610 *
611 * Unless required by applicable law or agreed to in writing, software
612 * distributed under the License is distributed on an "AS IS" BASIS,
613 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
614 * See the License for the specific language governing permissions and
615 * limitations under the License.
616 */class nh{constructor(e,t){this.query_=e,this.eventRegistrations_=[];let n=this.query_._queryParams,i=new tp(n.getIndex()),r=n.loadsAllData()?new tp(n.getIndex()):n.hasLimit()?new tg(n):new tf(n);this.processor_={filter:r};let s=t.serverCache,o=t.eventCache,l=i.updateFullNode(tt.EMPTY_NODE,s.getNode(),null),a=r.updateFullNode(tt.EMPTY_NODE,o.getNode(),null),h=new tM(l,s.isFullyInitialized(),i.filtersNodes()),u=new tM(a,o.isFullyInitialized(),r.filtersNodes());this.viewCache_=tO(u,h),this.eventGenerator_=new tF(this.query_)}get query(){return this.query_}}function nu(e){return 0===e.eventRegistrations_.length}function nc(e,t,n){let i=[];if(n){(0,y.hu)(null==t,"A cancel should cancel all event registrations.");let r=e.query._path;
616e.eventRegistrations_.forEach(e=>{let t=e.createCancelEvent(n,r);t&&i.push(t)})}if(t){let n=[];for(let i=0;i<e.eventRegistrations_.length;++i){let r=e.eventRegistrations_[i];if(r.matches(t)){if(t.hasAnyCallback()){n=n.concat(e.eventRegistrations_.slice(i+1));break}}else n.push(r)}e.eventRegistrations_=n}else e.eventRegistrations_=[];return i}function nd(e,t,n,i){var r,s;t.type===f.MERGE&&null!==t.source.queryId&&((0,y.hu)(tU(e.viewCache_),"We should always have a full cache before handling merges"),(0,y.hu)(tW(e.viewCache_),"Missing event cache, even though we have a server cache"));let o=e.viewCache_,l=function(e,t,n,i,r){let s,o;let l=new t9;if(n.type===f.OVERWRITE)n.source.fromUser?s=ns(e,t,n.path,n.snap,i,r,l):((0,y.hu)(n.source.fromServer,"Unknown source."),o=n.source.tagged||t.serverCache.isFiltered()&&!eq(n.path),s=nr(e,t,n.path,n.snap,i,r,o,l));else if(n.type===f.MERGE){var a,h;let u;n.source.fromUser?(a=n.path,h=n.children,u=t,h.foreach((n,s)=>{let o=eF(a,n);no(t,eN(o))&&(u=ns(e,u,o,s,i,r,l))}),h.foreach((n,s)=>{let o=eF(a,n);no(t,eN(o))||(u=ns(e,u,o,s,i,r,l))}),s=u):((0,y.hu)(n.source.fromServer,"Unknown source."),o=n.source.tagged||t.serverCache.isFiltered(),s=na(e,t,n.path,n.children,i,r,o,l))}else if(n.type===f.ACK_USER_WRITE)s=n.revert?function(e,t,n,i,r,s){let o;if(null!=t5(i,n))return t;{let l;let a=new nn(i,t,r),h=t.eventCache.getNode();if(eq(n)||".priority"===eN(n)){let n;if(t.serverCache.isFullyInitialized())n=t3(i,tU(t));else{let e=t.serverCache.getNode();(0,y.hu)(e instanceof tt,"serverChildren would be complete if leaf node"),n=t2(i,e)}l=e.filter.updateFullNode(h,n,s)}else{let r=eN(n),u=t6(i,r,t.serverCache);null==u&&t.serverCache.isCompleteForChild(r)&&(u=h.getImmediateChild(r)),(l=null!=u?e.filter.updateChild(h,r,u,ex(n),a,s):t.eventCache.getNode().hasChild(r)?e.filter.updateChild(h,r,tt.EMPTY_NODE,ex(n),a,s):h).isEmpty()&&t.serverCache.isFullyInitialized()&&(o=t3(i,tU(t))).isLeafNode()&&(l=e.filter.updateFullNode(l,o,s))}return o=t.serverCache.isFullyInitialized()||null!=t5(i,eP()),tA(t,l,o,e.filter.filtersNodes())}}(e,t,n.path,i,r,l):function(e,t,n,i,r,s,o){if(null!=t5(r,n))return t;let l=t.serverCache.isFiltered(),a=t.serverCache;if(null!=i.value){if(eq(n)&&a.isFullyInitialized()||a.isCompleteForPath(n))return nr(e,t,n,a.getNode().getChild(n),r,s,l,o);if(!eq(n))return t;{let i=new tH(null);return a.getNode().forEachChild(eQ,(e,t)=>{i=i.set(new eE(e),t)}),na(e,t,n,i,r,s,l,o)}}{let h=new tH(null);return i.foreach((e,t)=>{let i=eF(n,e);a.isCompleteForPath(i)&&(h=h.set(e,a.getNode().getChild(i)))}),na(e,t,n,h,r,s,l,o)}}(e,t,n.path,n.affectedTree,i,r,l);else if(n.type===f.LISTEN_COMPLETE)s=function(e,t,n,i,r){let s=t.serverCache;return ni(e,tL(t,s.getNode(),s.isFullyInitialized()||eq(n),s.isFiltered()),n,i,nt,r)}(e,t,n.path,i,l);else throw(0,y.g5)("Unknown operation type: "+n.type);let u=l.getChanges();return function(e,t,n){let i=t.eventCache;if(i.isFullyInitialized()){let r=i.getNode().isLeafNode()||i.getNode().isEmpty(),s=tW(e);!(n.length>0)&&e.eventCache.isFullyInitialized()&&(!r||i.getNode().equals(s))&&i.getNode().getPriority().equals(s.getPriority())||n.push(tu(tW(t)))}}(t,s,u),{viewCache:s,changes:u}}(e.processor_,o,t,n,i);return r=e.processor_,s=l.viewCache,(0,y.hu)(s.eventCache.getNode().isIndexed(r.filter.getIndex()),"Event snap not indexed"),(0,y.hu)(s.serverCache.getNode().isIndexed(r.filter.getIndex()),"Server snap not indexed"),(0,y.hu)(l.viewCache.serverCache.isFullyInitialized()||!o.serverCache.isFullyInitialized(),"Once a server snap is complete, it should never go back"),e.viewCache_=l.viewCache,n_(e,l.changes,l.viewCache.eventCache.getNode(),null)}function n_(e,t,n,i){let r=i?[i]:e.eventRegistrations_;return function(e,t,n,i){let r=[],s=[];return t.forEach(t=>{if("child_changed"===t.type&&e.index_.indexedValueChanged(t.oldSnap,t.snapshotNode)){var n;s.push((n=t.childName,{type:"child_moved",snapshotNode:t.snapshotNode,childName:n}))}}),tq(e,r,"child_removed",t,i,n),tq(e,r,"child_added",t,i,n),tq(e,r,"child_moved",s,i,n),tq(e,r,"child_changed",t,i,n),tq(e,r,"value",t,i,n),r}(e.eventGenerator_,t,n,r)}class np{constructor(){this.views=new Map}}function nf(e,t,n,i){let r=t.source.queryId;if(null!==r){let s=e.views.get(r);
616return(0,y.hu)(null!=s,"SyncTree gave us an op for an invalid query."),nd(s,t,n,i)}{let r=[];for(let s of e.views.values())r=r.concat(nd(s,t,n,i));return r}}function ng(e,t,n,i,r){let s=t._queryIdentifier,o=e.views.get(s);if(!o){let e=t3(n,r?i:null),s=!1;return e?s=!0:(e=i instanceof tt?t2(n,i):tt.EMPTY_NODE,s=!1),new nh(t,tO(new tM(e,s,!1),new tM(i,r,!1)))}return o}function nm(e){let t=[];for(let n of e.views.values())n.query._queryParams.loadsAllData()||t.push(n);return t}function ny(e,t){let n=null;for(let i of e.views.values())n=n||function(e,t){let n=tU(e.viewCache_);return n&&(e.query._queryParams.loadsAllData()||!eq(t)&&!n.getImmediateChild(eN(t)).isEmpty())?n.getChild(t):null}(i,t);return n}function nv(e,t){if(t._queryParams.loadsAllData())return nw(e);{let n=t._queryIdentifier;return e.views.get(n)}}function nC(e){return null!=nw(e)}function nw(e){for(let t of e.views.values())if(t.query._queryParams.loadsAllData())return t;return null}let nT=1;class nI{constructor(e){this.listenProvider_=e,this.syncPointTree_=new tH(null),this.pendingWriteTree_={visibleWrites:tY.empty(),allWrites:[],lastWriteId:-1},this.tagToQueryMap=new Map,this.queryToTagMap=new Map}}function nb(e,t,n,i,r){var s,o;return(s=e.pendingWriteTree_,o=r,(0,y.hu)(i>s.lastWriteId,"Stacking an older write on top of newer ones"),void 0===o&&(o=!0),s.allWrites.push({path:t,snap:n,writeId:i,visible:o}),o&&(s.visibleWrites=tj(s.visibleWrites,t,n)),s.lastWriteId=i,r)?nR(e,new tR(tE(),t,n)):[]}function nk(e,t,n=!1){let i=function(e,t){for(let n=0;n<e.allWrites.length;n++){let i=e.allWrites[n];if(i.writeId===t)return i}return null}(e.pendingWriteTree_,t);if(!function(e,t){let n=e.allWrites.findIndex(e=>e.writeId===t);(0,y.hu)(n>=0,"removeWrite called with nonexistent writeId.");let i=e.allWrites[n];e.allWrites.splice(n,1);let r=i.visible,s=!1,o=e.allWrites.length-1;for(;r&&o>=0;){let t=e.allWrites[o];t.visible&&(o>=n&&function(e,t){if(e.snap)return eW(e.path,t);for(let n in e.children)if(e.children.hasOwnProperty(n)&&eW(eF(e.path,n),t))return!0;return!1}(t,i.path)?r=!1:eW(i.path,t.path)&&(s=!0)),o--}return!!r&&(s?(e.visibleWrites=t0(e.allWrites,tZ,eP()),e.allWrites.length>0?e.lastWriteId=e.allWrites[e.allWrites.length-1].writeId:e.lastWriteId=-1):i.snap?e.visibleWrites=tB(e.visibleWrites,i.path):X(i.children,t=>{e.visibleWrites=tB(e.visibleWrites,eF(i.path,t))}),!0)}(e.pendingWriteTree_,t))return[];{let t=new tH(null);return null!=i.snap?t=t.set(eP(),!0):X(i.children,e=>{t=t.set(new eE(e),!0)}),nR(e,new tS(i.path,t,n))}}function nE(e,t,n){return nR(e,new tR(tP(),t,n))}function nP(e,t,n,i,r=!1){let s=t._path,o=e.syncPointTree_.get(s),l=[];if(o&&("default"===t._queryIdentifier||null!=nv(o,t))){let a=function(e,t,n,i){let r=t._queryIdentifier,s=[],o=[],l=nC(e);if("default"===r)for(let[t,r]of e.views.entries())o=o.concat(nc(r,n,i)),nu(r)&&(e.views.delete(t),r.query._queryParams.loadsAllData()||s.push(r.query));else{let t=e.views.get(r);t&&(o=o.concat(nc(t,n,i)),nu(t)&&(e.views.delete(r),t.query._queryParams.loadsAllData()||s.push(t.query)))}return l&&!nC(e)&&s.push(new((0,y.hu)(c,"Reference.ts has not been loaded"),c)(t._repo,t._path)),{removed:s,events:o}}(o,t,n,i);0===o.views.size&&(e.syncPointTree_=e.syncPointTree_.remove(s));let h=a.removed;if(l=a.events,!r){let n=-1!==h.findIndex(e=>e._queryParams.loadsAllData()),r=e.syncPointTree_.findOnPath(s,(e,t)=>nC(t));if(n&&!r){let t=e.syncPointTree_.subtree(s);if(!t.isEmpty()){let n=t.fold((e,t,n)=>{if(t&&nC(t))return[nw(t)];{let e=[];return t&&(e=nm(t)),X(n,(t,n)=>{e=e.concat(n)}),e}});for(let t=0;t<n.length;++t){let i=n[t],r=i.query,s=nD(e,i);e.listenProvider_.startListening(nL(r),nM(e,r),s.hashFn,s.onComplete)}}}r||!(h.length>0)||i||(n?e.listenProvider_.stopListening(nL(t),null):h.forEach(t=>{let n=e.queryToTagMap.get(nF(t));e.listenProvider_.stopListening(nL(t),n)}))}!function(e,t){for(let n=0;n<t.length;++n){let i=t[n];if(!i._queryParams.loadsAllData()){let t=nF(i),n=e.queryToTagMap.get(t);e.queryToTagMap.delete(t),e.tagToQueryMap.delete(n)}}}(e,h)}return l}function nN(e,t,n,i){let r=nq(e,i);if(null==r)return[];{let i=nO(r),s=i.path,o=i.queryId,l=eO(s,t);return nA(e,s,new tR(tN(o),l,n))}}function nS(e,t,n,i=!1){let r;let s=t._path,o=null,l=!1;e.syncPointTree_.foreachOnPath(s,(e,t)=>{let n=eO(e,s);o=o||ny(t,n),l=l||nC(t)});let a=e.syncPointTree_.get(s);a?(l=l||nC(a),o=o||ny(a,eP())):(a=new np,e.syncPointTree_=e.syncPointTree_.set(s,a)),null!=o?r=!0:(r=!1,o=tt.EMPTY_NODE,e.syncPointTree_.subtree(s).foreachChild((e,t)=>{let n=ny(t,eP());n&&(o=o.updateImmediateChild(e,n))}));let h=null!=nv(a,t);if(!h&&!t._queryParams.loadsAllData()){let n=nF(t);(0,y.hu)(!e.queryToTagMap.has(n),"View does not exist, but we have a tag");let i=nT++;e.queryToTagMap.set(n,i),e.tagToQueryMap.set(i,n)}let u=function(e,t,n,i,r,s){let o=ng(e,t,i,r,s);return e.views.has(t._queryIdentifier)||e.views.set(t._queryIdentifier,o),!function(e,t){e.eventRegistrations_.push(t)}(o,n),function(e,t){let n=e.viewCache_.eventCache,i=[];
616return n.getNode().isLeafNode()||n.getNode().forEachChild(e5,(e,t)=>{i.push(tc(e,t))}),n.isFullyInitialized()&&i.push(tu(n.getNode())),n_(e,i,n.getNode(),t)}(o,n)}(a,t,n,t7(s,e.pendingWriteTree_),o,r);if(!h&&!l&&!i){let n=nv(a,t);u=u.concat(function(e,t,n){let i=t._path,r=nM(e,t),s=nD(e,n),o=e.listenProvider_.startListening(nL(t),r,s.hashFn,s.onComplete),l=e.syncPointTree_.subtree(i);if(r)(0,y.hu)(!nC(l.value),"If we're adding a query, it shouldn't be shadowed");else{let t=l.fold((e,t,n)=>{if(!eq(e)&&t&&nC(t))return[nw(t).query];{let e=[];return t&&(e=e.concat(nm(t).map(e=>e.query))),X(n,(t,n)=>{e=e.concat(n)}),e}});for(let n=0;n<t.length;++n){let i=t[n];e.listenProvider_.stopListening(nL(i),nM(e,i))}}return o}(e,t,n))}return u}function nx(e,t,n){let i=e.pendingWriteTree_,r=e.syncPointTree_.findOnPath(t,(e,n)=>{let i=ny(n,eO(e,t));if(i)return i});return t1(i,t,r,n,!0)}function nR(e,t){var n;return function e(t,n,i,r){if(eq(t.path))return function e(t,n,i,r){let s=n.get(eP());null==i&&null!=s&&(i=ny(s,eP()));let o=[];return n.children.inorderTraversal((n,s)=>{let l=i?i.getImmediateChild(n):null,a=t8(r,n),h=t.operationForChild(n);h&&(o=o.concat(e(h,s,l,a)))}),s&&(o=o.concat(nf(s,t,r,i))),o}(t,n,i,r);{let s=n.get(eP());null==i&&null!=s&&(i=ny(s,eP()));let o=[],l=eN(t.path),a=t.operationForChild(l),h=n.children.get(l);if(h&&a){let t=i?i.getImmediateChild(l):null,n=t8(r,l);o=o.concat(e(a,h,t,n))}return s&&(o=o.concat(nf(s,t,r,i))),o}}(t,e.syncPointTree_,null,(n=e.pendingWriteTree_,t7(eP(),n)))}function nD(e,t){let n=t.query,i=nM(e,n);return{hashFn:()=>(t.viewCache_.serverCache.getNode()||tt.EMPTY_NODE).hash(),onComplete:t=>{if("ok"===t){var r;return i?function(e,t,n){let i=nq(e,n);if(!i)return[];{let n=nO(i),r=n.path,s=n.queryId,o=eO(r,t);return nA(e,r,new tx(tN(s),o))}}(e,n._path,i):(r=n._path,nR(e,new tx(tP(),r)))}{let i=function(e,t){let n="Unknown Error";"too_big"===e?n="The data requested exceeds the maximum size that can be accessed with a single request.":"permission_denied"===e?n="Client doesn't have permission to access the desired data.":"unavailable"===e&&(n="The service is unavailable");let i=Error(e+" at "+t._path.toString()+": "+n);return i.code=e.toUpperCase(),i}(t,n);return nP(e,n,null,i)}}}}function nM(e,t){let n=nF(t);return e.queryToTagMap.get(n)}function nF(e){return e._path.toString()+"$"+e._queryIdentifier}function nq(e,t){return e.tagToQueryMap.get(t)}function nO(e){let t=e.indexOf("$");return(0,y.hu)(-1!==t&&t<e.length-1,"Bad queryKey."),{queryId:e.substr(t+1),path:new eE(e.substr(0,t))}}function nA(e,t,n){let i=e.syncPointTree_.get(t);return(0,y.hu)(i,"Missing sync point for query tag that we're tracking"),nf(i,n,t7(t,e.pendingWriteTree_),null)}
616function nL(e){return e._queryParams.loadsAllData()&&!e._queryParams.isDefault()?new((0,y.hu)(d,"Reference.ts has not been loaded"),d)(e._repo,e._path):e}/**
617 * @license
618 * Copyright 2017 Google LLC
619 *
620 * Licensed under the Apache License, Version 2.0 (the "License");
621 * you may not use this file except in compliance with the License.
622 * You may obtain a copy of the License at
623 *
624 *   http://www.apache.org/licenses/LICENSE-2.0
625 *
626 * Unless required by applicable law or agreed to in writing, software
627 * distributed under the License is distributed on an "AS IS" BASIS,
628 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
629 * See the License for the specific language governing permissions and
630 * limitations under the License.
631 */class nW{constructor(e){this.node_=e}getImmediateChild(e){return new nW(this.node_.getImmediateChild(e))}node(){return this.node_}}class nU{constructor(e,t){this.syncTree_=e,this.path_=t}getImmediateChild(e){let t=eF(this.path_,e);return new nU(this.syncTree_,t)}node(){return nx(this.syncTree_,this.path_)}}let nz=function(e,t,n){return e&&"object"==typeof e?((0,y.hu)(".sv"in e,"Unexpected leaf node or priority contents"),"string"==typeof e[".sv"])?nH(e[".sv"],t,n):"object"==typeof e[".sv"]?nY(e[".sv"],t):void(0,y.hu)(!1,"Unexpected server value: "+JSON.stringify(e,null,2)):e},nH=function(e,t,n){if("timestamp"===e)return n.timestamp;(0,y.hu)(!1,"Unexpected server value: "+e)},nY=function(e,t,n){e.hasOwnProperty("increment")||(0,y.hu)(!1,"Unexpected server value: "+JSON.stringify(e,null,2));let i=e.increment;"number"!=typeof i&&(0,y.hu)(!1,"Unexpected increment value: "+i);let r=t.node();if((0,y.hu)(null!=r,"Expected ChildrenNode.EMPTY_NODE for nulls"),!r.isLeafNode())return i;let s=r.getValue();return"number"!=typeof s?i:s+i},nj=function(e,t,n,i){return nB(t,new nU(n,e),i)},nV=function(e,t,n){return nB(e,new nW(t),n)};function nB(e,t,n){let i;let r=nz(e.getPriority().val(),t.getImmediateChild(".priority"),n);if(!e.isLeafNode())return i=e,r!==e.getPriority().val()&&(i=i.updatePriority(new e2(r))),e.forEachChild(e5,(e,r)=>{let s=nB(r,t.getImmediateChild(e),n);s!==r&&(i=i.updateImmediateChild(e,s))}),i;{let i=nz(e.getValue(),t,n);return i!==e.getValue()||r!==e.getPriority().val()?new e2(i,tr(r)):e}}/**
632 * @license
633 * Copyright 2017 Google LLC
634 *
635 * Licensed under the Apache License, Version 2.0 (the "License");
636 * you may not use this file except in compliance with the License.
637 * You may obtain a copy of the License at
638 *
639 *   http://www.apache.org/licenses/LICENSE-2.0
640 *
641 * Unless required by applicable law or agreed to in writing, software
642 * distributed under the License is distributed on an "AS IS" BASIS,
643 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
644 * See the License for the specific language governing permissions and
645 * limitations under the License.
646 */class nK{constructor(e="",t=null,n={children:{},childCount:0}){this.name=e,this.parent=t,this.node=n}}function nQ(e,t){let n=t instanceof eE?t:new eE(t),i=e,r=eN(n);for(;null!==r;){let e=(0,y.DV)(i.node.children,r)||{children:{},childCount:0};i=new nK(r,i,e),r=eN(n=ex(n))}return i}function nG(e){return e.node.value}function n$(e,t){e.node.value=t,function e(t){null!==t.parent&&function(t,n,i){let r=void 0===nG(i)&&!nX(i),s=(0,y.r3)(t.node.children,n);r&&s?(delete t.node.children[n],t.node.childCount--,e(t)):r||s||(t.node.children[n]=i.node,t.node.childCount++,e(t))}(t.parent,t.name,t)}(e)}function nX(e){return e.node.childCount>0}function nJ(e,t){X(e.node.children,(n,i)=>{t(new nK(n,e,i))})}function nZ(e){return new eE(null===e.parent?e.name:nZ(e.parent)+"/"+e.name)}/**
647 * @license
648 * Copyright 2017 Google LLC
649 *
650 * Licensed under the Apache License, Version 2.0 (the "License");
651 * you may not use this file except in compliance with the License.
652 * You may obtain a copy of the License at
653 *
654 *   http://www.apache.org/licenses/LICENSE-2.0
655 *
656 * Unless required by applicable law or agreed to in writing, software
657 * distributed under the License is distributed on an "AS IS" BASIS,
658 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
659 * See the License for the specific language governing permissions and
660 * limitations under the License.
661 */let n0=/[\[\].#$\/\u0000-\u001F\u007F]/,n1=/[\[\].#$\u0000-\u001F\u007F]/,n3=function(e){return"string"==typeof e&&0!==e.length&&!n0.test(e)},n2=function(e){return"string"==typeof e&&0!==e.length&&!n1.test(e)},n4=function(e,t,n,i){i&&void 0===t||n5((0,y.gK)(e,"value"),t,n)},n5=function(e,t,n){let i=n instanceof eE?new eU(n,e):n;if(void 0===t)throw Error(e+"contains undefined "+eH(i));if("function"==typeof t)throw Error(e+"contains a function "+eH(i)+" with contents = "+t.toString());if(H(t))throw Error(e+"contains "+t.toString()+" "+eH(i));if("string"==typeof t&&t.length>3495253.3333333335&&(0,y.ug)(t)>10485760)throw Error(e+"contains a string greater than 10485760 utf8 bytes "+eH(i)+" ('"+t.substring(0,50)+"...')");if(t&&"object"==typeof t){let n=!1,r=!1;if(X(t,(t,s)=>{if(".value"===t)n=!0;else if(".priority"!==t&&".sv"!==t&&(r=!0,!n3(t)))throw Error(e+" contains an invali
661d key ("+t+") "+eH(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,y.ug)(t),ez(i),n5(e,s,i),function(e){let t=e.parts_.pop();e.byteLength_-=(0,y.ug)(t),e.parts_.length>0&&(e.byteLength_-=1)}(i)}),n&&r)throw Error(e+' contains ".value" child '+eH(i)+" in addition to actual children.")}},n6=function(e,t){let n,i;for(n=0;n<t.length;n++){let r=eD(i=t[n]);for(let t=0;t<r.length;t++)if(".priority"===r[t]&&t===r.length-1);else if(!n3(r[t]))throw Error(e+"contains an invalid key ("+r[t]+") in path "+i.toString()+'. Keys must be non-empty strings and can\'t contain ".", "#", "$", "/", "[", or "]"')}t.sort(eA);let r=null;for(n=0;n<t.length;n++){if(i=t[n],null!==r&&eW(r,i))throw Error(e+"contains a path "+r.toString()+" that is ancestor of another path "+i.toString());r=i}},n8=function(e,t,n,i){if(i&&void 0===t)return;let r=(0,y.gK)(e,"values");if(!(t&&"object"==typeof t)||Array.isArray(t))throw Error(r+" must be an object containing the children to replace.");let s=[];X(t,(e,t)=>{let i=new eE(e);if(n5(r,t,eF(n,i)),".priority"===eR(i)&&!(null===t||"string"==typeof t||"number"==typeof t&&!H(t)||t&&"object"==typeof t&&(0,y.r3)(t,".sv")))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).");s.push(i)}),n6(r,s)},n7=function(e,t,n,i){if((!i||void 0!==n)&&!n2(n))throw Error((0,y.gK)(e,t)+'was an invalid path = "'+n+'". Paths must be non-empty strings and can\'t contain ".", "#", "$", "[", or "]"')},n9=function(e,t,n,i){n&&(n=n.replace(/^\/*\.info(\/|$)/,"/")),n7(e,t,n,i)},ie=function(e,t){if(".info"===eN(t))throw Error(e+" failed = Can't modify data under /.info/")},it=function(e,t){var n;let i=t.path.toString();if("string"!=typeof t.repoInfo.host||0===t.repoInfo.host.length||!n3(t.repoInfo.namespace)&&"localhost"!==t.repoInfo.host.split(":")[0]||0!==i.length&&((n=i)&&(n=n.replace(/^\/*\.info(\/|$)/,"/")),!n2(n)))throw Error((0,y.gK)(e,"url")+'must be a valid firebase URL and the path can\'t contain ".", "#", "$", "[", or "]".')};/**
662 * @license
663 * Copyright 2017 Google LLC
664 *
665 * Licensed under the Apache License, Version 2.0 (the "License");
666 * you may not use this file except in compliance with the License.
667 * You may obtain a copy of the License at
668 *
669 *   http://www.apache.org/licenses/LICENSE-2.0
670 *
671 * Unless required by applicable law or agreed to in writing, software
672 * distributed under the License is distributed on an "AS IS" BASIS,
673 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
674 * See the License for the specific language governing permissions and
675 * limitations under the License.
676 */class ii{constructor(){this.eventLists_=[],this.recursionDepth_=0}}function ir(e,t){let n=null;for(let i=0;i<t.length;i++){let r=t[i],s=r.getPath();null===n||eL(s,n.path)||(e.eventLists_.push(n),n=null),null===n&&(n={events:[],path:s}),n.events.push(r)}n&&e.eventLists_.push(n)}function is(e,t,n){ir(e,n),il(e,e=>eL(e,t))}function io(e,t,n){ir(e,n),il(e,e=>eW(e,t)||eW(t,e))}function il(e,t){e.recursionDepth_++;let n=!0;for(let i=0;i<e.eventLists_.length;i++){let r=e.eventLists_[i];r&&(t(r.path)?(function(e){for(let t=0;t<e.events.length;t++){let n=e.events[t];if(null!==n){e.events[t]=null;let i=n.getEventRunner();M&&O("event: "+n.toString()),et(i)}}}(e.eventLists_[i]),e.eventLists_[i]=null):n=!1)}n&&(e.eventLists_=[]),e.recursionDepth_--}class ia{constructor(e,t,n,i){this.repoInfo_=e,this.forceRestClient_=t,this.authTokenProvider_=n,this.appCheckProvider_=i,this.dataUpdateCount=0,this.statsListener_=null,this.eventQueue_=new ii,this.nextWriteId_=1,this.interceptServerDataCallback_=null,this.onDisconnect_=tT(),this.transactionQueueTree_=new nK,this.persistentConnection_=null,this.key=this.repoInfo_.toURLString()}toString(){return(this.repoInfo_.secure?"https://":"http://")+this.repoInfo_.host}}function ih(e){let t=e.infoData_.getNode(new eE(".info/serverTimeOffset")).val()||0;return new Date().getTime()+t}function iu(e){var t;return(t=t={timestamp:ih(e)}).timestamp=t.timestamp||new Date().getTime(),t}function ic(e,t,n,i,r){e.dataUpdateCount++;let s=new eE(t);n=e.interceptServerDataCallback_?e.interceptServerDataCallback_(t,n):n;let o=[];if(r){if(i){let t=(0,y.UI)(n,e=>tr(e));o=function(e,t,n,i){let r=nq(e,i);if(!r)return[];{let i=nO(r),s=i.path,o=i.queryId,l=eO(s,t),a=tH.fromObject(n);return nA(e,s,new tD(tN(o),l,a))}}(e.serverSyncTree_,s,t,r)}else{let t=tr(n);o=nN(e.serverSyncTree_,s,t,r)}}else if(i){let t=(0,y.UI)(n,e=>tr(e));o=function(e,t,n){let i=tH.fromObject(n);return nR(e,new tD(tP(),t,i))}(e.serverSyncTree_,s,t)}else{let t=tr(n);o=nE(e.serverSyncTree_,s,t)}let l=s;o.length>0&&(l=iC(e,s)),io(e.eventQueue_,l,o)}function id(e,t){i_(e,"connected",t),!1===t&&function(e){im(e,"onDisconnectEvents");let t=iu(e),n=tT();tI(e.onDisconnect_,eP(),(i,r)=>{let s=nj(i,r,e.serverSyncTree_,t);!function e(t,n,i){if(eq(n))t.value=i,t.children.clear();else if(null!==t.value)t.value=t.value.updateChild(n,i);else{let r=eN(n);t.children.has(r)||t.children.set(r,tT()),e(t.children.get(r),n=ex(n),i)}}(n,i,s)});let i=[];tI(n,eP(),(t,n)=>{i=i.concat(nE(e.serverSyncTree_,t,n));let r=ib(e,t);iC(e,r)}),e.onDisconnect_=tT(),io(e.eventQueue_,eP(),i)}(e)}function i_(e,t,n){let i=new eE("/.info/"+t),r=tr(n);e.infoData_.updateSnapshot(i,r);let s=nE(e.infoSyncTree_,i,r);io(e.eventQueue_,i,s)}function ip(e){return e.nextWriteId_++}function ig(e,t,n){let i;i=".info"===eN(t._path)?nP(e.infoSyncTree_,t,n):nP(e.serverSyncTree_,t,n),is(e.eventQueue_,t._path,i)}function im(e,...t){let n="";e.persistentConnection_&&(n=e.persistentConnection_.id+":"),O(n,...t)}function iy(e,t,n,i){t&&et(()=>{if("ok"===n)t(null);else{let e=(n||"error").toUpperCase(),r=e;i&&(r+=": "+i);let s=Error(r);s.code=e,t(s)}})}function iv(e,t,n){return nx(e.serverSyncTree_,t,n)||tt.EMPTY_NODE}function iC(e,t){let n=iw(e,t),i=nZ(n),r=iT(e,n);return function(e,t,n){if(0===t.length)return;let i=[],r=[],s=t.filter(e=>0===e.status).map(e=>e.currentWriteId);for(let o=0;o<t.length;o++){let l=t[o],a=eO(n,l.path),h=!1,u;if((0,y.hu)(null!==a,"rerunTransactionsUnderNode_: relativePath should not be null."),4===l.status)h=!0,u=l.abortReason,r=r.concat(nk(e.serverSyncTree_,l.currentWriteId,!0));else if(0===l.status){if(l.retryCount>=25)h=!0,u="maxretry",r=r.concat(nk(e.serverSyncTree_,l.currentWriteId,!0));else{let n=iv(e,l.path,s);l.currentInputSnapshot=n;let i=t[o].update(n.val());if(void 0!==i){n5("transaction failed: Data returned ",i,l.path);let t=tr(i);"object"==typeof i&&null!=i&&(0,y.r3)(i,".priority")||(t=t.updatePriority(n.getPri
676ority()));let o=l.currentWriteId,a=nV(t,n,iu(e));l.currentOutputSnapshotRaw=t,l.currentOutputSnapshotResolved=a,l.currentWriteId=ip(e),s.splice(s.indexOf(o),1),r=(r=r.concat(nb(e.serverSyncTree_,l.path,a,l.currentWriteId,l.applyLocally))).concat(nk(e.serverSyncTree_,o,!0))}else h=!0,u="nodata",r=r.concat(nk(e.serverSyncTree_,l.currentWriteId,!0))}}io(e.eventQueue_,n,r),r=[],h&&(t[o].status=2,setTimeout(t[o].unwatcher,Math.floor(0)),t[o].onComplete&&("nodata"===u?i.push(()=>t[o].onComplete(null,!1,t[o].currentInputSnapshot)):i.push(()=>t[o].onComplete(Error(u),!1,null))))}iI(e,e.transactionQueueTree_);for(let e=0;e<i.length;e++)et(i[e]);(function e(t,n=t.transactionQueueTree_){if(n||iI(t,n),nG(n)){let i=iT(t,n);(0,y.hu)(i.length>0,"Sending zero length transaction queue"),i.every(e=>0===e.status)&&function(t,n,i){let r=iv(t,n,i.map(e=>e.currentWriteId)),s=r,o=r.hash();for(let e=0;e<i.length;e++){let t=i[e];(0,y.hu)(0===t.status,"tryToSendTransactionQueue_: items in queue should all be run."),t.status=1,t.retryCount++;let r=eO(n,t.path);s=s.updateChild(r,t.currentOutputSnapshotRaw)}let l=s.val(!0);t.server_.put(n.toString(),l,r=>{im(t,"transaction put response",{path:n.toString(),status:r});let s=[];if("ok"===r){let r=[];for(let e=0;e<i.length;e++)i[e].status=2,s=s.concat(nk(t.serverSyncTree_,i[e].currentWriteId)),i[e].onComplete&&r.push(()=>i[e].onComplete(null,!0,i[e].currentOutputSnapshotResolved)),i[e].unwatcher();iI(t,nQ(t.transactionQueueTree_,n)),e(t,t.transactionQueueTree_),io(t.eventQueue_,n,s);for(let e=0;e<r.length;e++)et(r[e])}else{if("datastale"===r)for(let e=0;e<i.length;e++)3===i[e].status?i[e].status=4:i[e].status=0;else{U("transaction at "+n.toString()+" failed: "+r);for(let e=0;e<i.length;e++)i[e].status=4,i[e].abortReason=r}iC(t,n)}},o)}(t,nZ(n),i)}else nX(n)&&nJ(n,n=>{e(t,n)})})(e,e.transactionQueueTree_)}(e,r,i),i}function iw(e,t){let n;let i=e.transactionQueueTree_;for(n=eN(t);null!==n&&void 0===nG(i);)i=nQ(i,n),n=eN(t=ex(t));return i}function iT(e,t){let n=[];return function e(t,n,i){let r=nG(n);if(r)for(let e=0;e<r.length;e++)i.push(r[e]);nJ(n,n=>{e(t,n,i)})}(e,t,n),n.sort((e,t)=>e.order-t.order),n}function iI(e,t){let n=nG(t);if(n){let e=0;for(let t=0;t<n.length;t++)2!==n[t].status&&(n[e]=n[t],e++);n.length=e,n$(t,n.length>0?n:void 0)}nJ(t,t=>{iI(e,t)})}function ib(e,t){let n=nZ(iw(e,t)),i=nQ(e.transactionQueueTree_,t);return!function(e,t,n){let i=e.parent;for(;null!==i;){if(t(i))return!0;i=i.parent}}(i,t=>{ik(e,t)}),ik(e,i),!function e(t,n,i,r){i&&!r&&n(t),nJ(t,t=>{e(t,n,!0,r)}),i&&r&&n(t)}(i,t=>{ik(e,t)}),n}function ik(e,t){let n=nG(t);if(n){let i=[],r=[],s=-1;for(let t=0;t<n.length;t++)3===n[t].status||(1===n[t].status?((0,y.hu)(s===t-1,"All SENT items should be at beginning of queue."),s=t,n[t].status=3,n[t].abortReason="set"):((0,y.hu)(0===n[t].status,"Unexpected transaction status in abort"),n[t].unwatcher(),r=r.concat(nk(e.serverSyncTree_,n[t].currentWriteId,!0)),n[t].onComplete&&i.push(n[t].onComplete.bind(null,Error("set"),!1,null))));-1===s?n$(t,void 0):n.length=s+1,io(e.eventQueue_,nZ(t),r);for(let e=0;e<i.length;e++)et(i[e])}}let iE=function(e,t){let n=iP(e),i=n.namespace;"firebase.com"===n.domain&&W(n.host+" is no longer supported. Please use <YOUR FIREBASE>.firebaseio.com instead"),i&&"undefined"!==i||"localhost"===n.domain||W("Cannot parse Firebase url. Please use https://<YOUR FIREBASE>.firebaseio.com"),n.secure||z();let r="ws"===n.scheme||"wss"===n.scheme;return{repoInfo:new eh(n.host,n.secure,i,r,t,"",i!==n.subdomain),path:new eE(n.pathString)}},iP=function(e){let t="",n="",i="",r="",s="",o=!0,l="https",a=443;if("string"==typeof e){let h=e.indexOf("//");h>=0&&(l=e.substring(0,h-1),e=e.substring(h+2));let u=e.indexOf("/");-1===u&&(u=e.length);let c=e.indexOf("?");-1===c&&(c=e.length),t=e.substring(0,Math.min(u,c)),u<c&&(r=/**
677 * @license
678 * Copyright 2017 Google LLC
679 *
680 * Licensed under the Apache License, Version 2.0 (the "License");
681 * you may not use this file except in compliance with the License.
682 * You may obtain a copy of the License at
683 *
684 *   http://www.apache.org/licenses/LICENSE-2.0
685 *
686 * Unless required by applicable law or agreed to in writing, softw
686are
687 * distributed under the License is distributed on an "AS IS" BASIS,
688 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
689 * See the License for the specific language governing permissions and
690 * limitations under the License.
691 */function(e){let t="",n=e.split("/");for(let e=0;e<n.length;e++)if(n[e].length>0){let i=n[e];try{i=decodeURIComponent(i.replace(/\+/g," "))}catch(e){}t+="/"+i}return t}(e.substring(u,c)));let d=function(e){let t={};for(let n of("?"===e.charAt(0)&&(e=e.substring(1)),e.split("&"))){if(0===n.length)continue;let i=n.split("=");2===i.length?t[decodeURIComponent(i[0])]=decodeURIComponent(i[1]):U(`Invalid query segment '${n}' in query '${e}'`)}return t}(e.substring(Math.min(e.length,c)));(h=t.indexOf(":"))>=0?(o="https"===l||"wss"===l,a=parseInt(t.substring(h+1),10)):h=t.length;let _=t.slice(0,h);if("localhost"===_.toLowerCase())n="localhost";else if(_.split(".").length<=2)n=_;else{let e=t.indexOf(".");i=t.substring(0,e).toLowerCase(),n=t.substring(e+1),s=i}"ns"in d&&(s=d.ns)}return{host:t,port:a,domain:n,subdomain:i,secure:o,scheme:l,pathString:r,namespace:s}};/**
692 * @license
693 * Copyright 2017 Google LLC
694 *
695 * Licensed under the Apache License, Version 2.0 (the "License");
696 * you may not use this file except in compliance with the License.
697 * You may obtain a copy of the License at
698 *
699 *   http://www.apache.org/licenses/LICENSE-2.0
700 *
701 * Unless required by applicable law or agreed to in writing, software
702 * distributed under the License is distributed on an "AS IS" BASIS,
703 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
704 * See the License for the specific language governing permissions and
705 * limitations under the License.
706 */class iN{constructor(e,t,n,i){this.eventType=e,this.eventRegistration=t,this.snapshot=n,this.prevName=i}getPath(){let e=this.snapshot.ref;return"value"===this.eventType?e._path:e.parent._path}getEventType(){return this.eventType}getEventRunner(){return this.eventRegistration.getEventRunner(this)}toString(){return this.getPath().toString()+":"+this.eventType+":"+(0,y.Pz)(this.snapshot.exportVal())}}class iS{constructor(e,t,n){this.eventRegistration=e,this.error=t,this.path=n}getPath(){return this.path}getEventType(){return"cancel"}getEventRunner(){return this.eventRegistration.getEventRunner(this)}toString(){return this.path.toString()+":cancel"}}/**
707 * @license
708 * Copyright 2017 Google LLC
709 *
710 * Licensed under the Apache License, Version 2.0 (the "License");
711 * you may not use this file except in compliance with the License.
712 * You may obtain a copy of the License at
713 *
714 *   http://www.apache.org/licenses/LICENSE-2.0
715 *
716 * Unless required by applicable law or agreed to in writing, software
717 * distributed under the License is distributed on an "AS IS" BASIS,
718 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
719 * See the License for the specific language governing permissions and
720 * limitations under the License.
721 */class ix{constructor(e,t){this.snapshotCallback=e,this.cancelCallback=t}onValue(e,t){this.snapshotCallback.call(null,e,t)}onCancel(e){return(0,y.hu)(this.hasCancelCallback,"Raising a cancel event on a listener with no cancel callback"),this.cancelCallback.call(null,e)}get hasCancelCallback(){return!!this.cancelCallback}matches(e){return this.snapshotCallback===e.snapshotCallback||void 0!==this.snapshotCallback.userCallback&&this.snapshotCallback.userCallback===e.snapshotCallback.userCallback&&this.snapshotCallback.context===e.snapshotCallback.context}}/**
722 * @license
723 * Copyright 2020 Google LLC
724 *
725 * Licensed under the Apache License, Version 2.0 (the "License");
726 * you may not use this file except in compliance with the License.
727 * You may obtain a copy of the License at
728 *
729 *   http://www.apache.org/licenses/LICENSE-2.0
730 *
731 * Unless required by applicable law or agreed to in writing, software
732 * distributed under the License is distributed on an "AS IS" BASIS,
733 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
734 * See the License for the specific language governing permissions and
735 * limitations under the License.
736 */class iR{constructor(e,t,n,i){this._repo=e,this._path=t,this._queryParams=n,this._orderByCalled=i}get key(){return eq(this._path)?null:eR(this._path)}get ref(){return new iD(this._repo,this._path)}get _queryIdentifier(){let e=G(tv(this._queryParams));return"{}"===e?"default":e}get _queryObject(){return tv(this._queryParams)}isEqual(e){if(!((e=(0,y.m9)(e))instanceof iR))return!1;let t=this._repo===e._repo,n=eL(this._path,e._path),i=this._queryIdentifier===e._queryIdentifier;return t&&n&&i}toJSON(){return this.toString()}toString(){return this._repo.toString()+function(e){let t="";for(let n=e.pieceNum_;n<e.pieces_.length;n++)""!==e.pieces_[n]&&(t+="/"+encodeURIComponent(String(e.pieces_[n])));return t||"/"}(this._path)}}class iD extends iR{constructor(e,t){super(e,t,new tm,!1)}get parent(){let e=eM(this._path);return null===e?null:new iD(this._repo,e)}get root(){let e=this;for(;null!==e.parent;)e=e.parent;return e}}class iM{constructor(e,t,n){this._node=e,this.ref=t,this._index=n}get priority(){return this._node.getPriority().val()}get key(){return this.ref.key}get size(){return this._node.numChildren()}child(e){let t=new eE(e),n=iq(this.ref,e);return new iM(this._node.getChild(t),n,e5)}exists(){return!this._node.isEmpty()}exportVal(){return this._node.val(!0)}forEach(e){return!this._node.isLeafNode()&&!!this._node.forEachChild(this._index,(t,n)=>
736e(new iM(n,iq(this.ref,t),e5)))}hasChild(e){let t=new eE(e);return!this._node.getChild(t).isEmpty()}hasChildren(){return!this._node.isLeafNode()&&!this._node.isEmpty()}toJSON(){return this.exportVal()}val(){return this._node.val()}}function iF(e,t){return(e=(0,y.m9)(e))._checkNotDeleted("ref"),void 0!==t?iq(e._root,t):e._root}function iq(e,t){return null===eN((e=(0,y.m9)(e))._path)?n9("child","path",t,!1):n7("child","path",t,!1),new iD(e._repo,eF(e._path,t))}function iO(e,t){let n;ie("push",(e=(0,y.m9)(e))._path),n4("push",t,e._path,!0);let i=th(ih(e._repo)),r=iq(e,i),s=iq(e,i);return n=null!=t?iA(s,t).then(()=>s):Promise.resolve(s),r.then=n.then.bind(n),r.catch=n.then.bind(n,void 0),r}function iA(e,t){ie("set",(e=(0,y.m9)(e))._path),n4("set",t,e._path,!1);let n=new y.BH;return!function(e,t,n,i,r){im(e,"set",{path:t.toString(),value:n,priority:i});let s=iu(e),o=tr(n,i),l=nV(o,nx(e.serverSyncTree_,t),s),a=ip(e),h=nb(e.serverSyncTree_,t,l,a,!0);ir(e.eventQueue_,h),e.server_.put(t.toString(),o.val(!0),(n,i)=>{let s="ok"===n;s||U("set at "+t+" failed: "+n);let o=nk(e.serverSyncTree_,a,!s);io(e.eventQueue_,t,o),iy(e,r,n,i)});let u=ib(e,t);iC(e,u),io(e.eventQueue_,u,[])}(e._repo,e._path,t,null,n.wrapCallback(()=>{})),n.promise}function iL(e,t){n8("update",t,e._path,!1);let n=new y.BH;return!function(e,t,n,i){im(e,"update",{path:t.toString(),value:n});let r=!0,s=iu(e),o={};if(X(n,(n,i)=>{r=!1,o[n]=nj(eF(t,n),tr(i),e.serverSyncTree_,s)}),r)O("update() called with empty data.  Don't do anything."),iy(e,i,"ok",void 0);else{let r=ip(e),s=function(e,t,n,i){var r;r=e.pendingWriteTree_,(0,y.hu)(i>r.lastWriteId,"Stacking an older merge on top of newer ones"),r.allWrites.push({path:t,children:n,writeId:i,visible:!0}),r.visibleWrites=tV(r.visibleWrites,t,n),r.lastWriteId=i;let s=tH.fromObject(n);return nR(e,new tD(tE(),t,s))}(e.serverSyncTree_,t,o,r);ir(e.eventQueue_,s),e.server_.merge(t.toString(),n,(n,s)=>{let o="ok"===n;o||U("update at "+t+" failed: "+n);let l=nk(e.serverSyncTree_,r,!o),a=l.length>0?iC(e,t):t;io(e.eventQueue_,a,l),iy(e,i,n,s)}),X(n,n=>{let i=ib(e,eF(t,n));iC(e,i)}),io(e.eventQueue_,t,[])}}(e._repo,e._path,t,n.wrapCallback(()=>{})),n.promise}function iW(e){e=(0,y.m9)(e);let t=new iU(new ix(()=>{}));return(function(e,t,n){let i=function(e,t){var n;let i=t._path,r=null;e.syncPointTree_.foreachOnPath(i,(e,t)=>{let n=eO(e,i);r=r||ny(t,n)});let s=e.syncPointTree_.get(i);s?r=r||ny(s,eP()):(s=new np,e.syncPointTree_=e.syncPointTree_.set(i,s));let o=null!=r,l=o?new tM(r,!0,!1):null,a=(n=e.pendingWriteTree_,t7(t._path,n));return tW(ng(s,t,a,o?l.getNode():tt.EMPTY_NODE,o).viewCache_)}(e.serverSyncTree_,t);return null!=i?Promise.resolve(i):e.server_.get(t).then(i=>{let r;let s=tr(i).withIndex(t._queryParams.getIndex());if(nS(e.serverSyncTree_,t,n,!0),t._queryParams.loadsAllData())r=nE(e.serverSyncTree_,t._path,s);else{let n=nM(e.serverSyncTree_,t);r=nN(e.serverSyncTree_,t._path,s,n)}return io(e.eventQueue_,t._path,r),nP(e.serverSyncTree_,t,n,null,!0),s},n=>(im(e,"get for query "+(0,y.Pz)(t)+" failed: "+n),Promise.reject(Error(n))))})(e._repo,e,t).then(t=>new iM(t,new iD(e._repo,e._path),e._queryParams.getIndex()))}class iU{constructor(e){this.callbackContext=e}respondsTo(e){return"value"===e}createEvent(e,t){let n=t._queryParams.getIndex();return new iN("value",this,new iM(e.snapshotNode,new iD(t._repo,t._path),n))}getEventRunner(e){return"cancel"===e.getEventType()?()=>this.callbackContext.onCancel(e.error):()=>this.callbackContext.onValue(e.snapshot,null)}createCancelEvent(e,t){return this.callbackContext.hasCancelCallback?new iS(this,e,t):null}matches(e){return e instanceof iU&&(!e.callbackContext||!this.callbackContext||e.callbackContext.matches(this.callbackContext))}hasAnyCallback(){return null!==this.callbackContext}}class iz{constructor(e,t){this.eventType=e,this.callbackContext=t}respondsTo(e){let t="children_added"===e?"child_added":e;return t="children_removed"===t?"child_removed":t,this.eventType===t}createCancelEvent(e,t){return this.callbackContext.hasCancelCallback?new iS(this,e,t):null}createEvent(e,t){(0,y.hu)(null!=e.childName,"Child events should have a childName.");let n=iq(new iD(t._repo,t._path),e.childName),i=t._queryParams.getIndex();return new iN(e.type,this,new iM(e.snapshotNode,n,i),e.prevName)}getEventRunner(e){return"cancel"===e.getEventType()?()=>this.callbackContext.onCancel(e.error):()=>this.callbackContext.onValue(e.snapshot,e.prevName)}matches(e){return e instanceof iz&&this.eventType===e.eventType&&(!this.callbackContext||!e.callbackContext||this.callbackContext.matches(e.callbackContext))}hasAnyCallback(){return!!this.callbackContext}}function iH(e,t,n,i){return function(e,t,n,i,r){var s;let o,l;if("object"==typeof i&&(o=void 0,r=i),"function"==typeof i&&(o=i),r&&r.onlyOnce){let t=n,i=(n,i)=>{ig(e._repo,e,h),t(n,i)};i.userCallback=n.userCallback,i.context=n.context,n=i}let a=new ix(n,o||void 0),h="value"===t?new iU(a):new iz(t,a);return s=e._repo,l=".info"===eN(e._path)?nS(s.infoSyncTree_,e,h):nS(s.serverSyncTree_,e,h),is(s.eventQueue_,e._path,l),()=>ig(e._repo,e,h)}(e,"value",t,n,i)}function iY(e,...t){let n=(0,y.m9)(e);for(let e of t)n=e._apply(n);return n}(0,y.hu)(!c,"__referenceConstructor has already been defined"),c=iD,(0,y.hu)(!d,"__referenceConstructor has already been defined"),d=iD;let ij={};class iV{constructor(e,t){this._repoInternal=e,this.app=t,this.type="database",this._instanceStarted=!1}get _repo(){return this._instanceStarted||(function(e,t,n){if(e.stats_=ep(e.repoInfo_),e.forceRestClient_||("object"==typeof window&&window.navigator&&window.navigator.userAgent||"").search(/googlebot|google webmaster tools|bingbot|yahoo! slurp|baiduspider|yandexbot|duckduckbot/i)>=0)e.server_=new tC(e.repoInfo_,(t,n,i,r)=>{ic(e,t,n,i,r)},e.authTokenProvider_,e.appCheckProvider_),setTimeout(()=>id(e,!0),0);else{if(null!=n){if("object"!=typeof n)throw Error("Only objects are supported for option databaseAuthVariableOverride");try{(0,y.Pz)(n)}catch(e){throw Error("Invalid authOverride provided: "+e)}}e.persistentConnection_=new ej(e.repoInfo_,t,(t,n,i,r)=>{ic(e,t,n,i,r)},t=>{id(e,t)},t=>{X(t,(t,n)=>{i_(e,t,n)})},e.authTokenProvider_,e.appCheckProvider_,n),e.server_=e.persistentConnection_}e.authTokenProvider_.addTokenChangeListener(t=>{e.server_.refreshAuthToken(t)}),e.appCheckProvider_.addTokenChangeListener(t=>{e.server_.refreshAppCheckToken(t.token)}),e.statsReporter_=function(e,t){let n=e.toString();return e_[n]||(e_[n]=t()),e_[n]}(e.repoInfo_,()=>new tk(e.stats_,e.server_)),e.infoData_=new tw,e.infoSyncTree_=new nI({startListening:(t,n,i,r)=>{let s=[],o=e.infoData_.getNode(t._path);return o.isEmpty()||(s=nE(e.infoSyncTree_,t._path,o),setTimeout(()=>{r("ok")},0)),s},stopListening:()=>{}}),i_(e,"connected",!1),e.serverSyncTree_=new nI({startListening:(t,n,i,r)=>(e.server_.listen(t,i,n,(n,i)=>{let s=r(n,i);io(e.eventQueue_,t._path,s)}),[]),stopListening:(t,n)=>{e.server_.unlisten(t,n)}})}(this._repoInternal,this.app.options.appId,this.app.options.databaseAuthVariableOverride),this._instanceStarted=!0),this._repoInternal}get _root(){return this._rootInternal||(this._rootInternal=new iD(this._repo,eP())),this._rootInternal}_delete(){return null!==this._rootInternal&&(function(e,t){let n=ij[t];n&&n[e.key]===e||W(`Database ${t}(${e.repoInfo_}) has already been deleted.`),e.persistentConnection_&&e.persistentConnection_.interrupt("repo_interrupt"),delete n[e.key]}(this._repo,this.app.name),this._repoInternal=null,this._rootInternal=null),Promise.resolve()}_checkNotDeleted(e){null===this._rootInternal&&W("Cannot call "+e+" on a deleted database.")}}function iB(e=(0,g.Mq)(),t){return(0,g.qX)(e,"database").getImmediate({identifier:t})}/**
737 * @license
738 * Copyright 2020 Google LLC
739 *
740 * Licensed under the Apache License, Version 2.0 (the "License");
741 * you may not use this file except in compliance with the License.
742 * You may obtain a copy of the License at
743 *
744 *   http://www.apache.org/licenses/LICENSE-2.0
745 *
746 * Unless required by applicable law or agreed to in writing, software
747 * distributed under the License is distributed on an "AS IS" BASIS,
748 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
749 * See the License for the specific language governing permissions and
750 * limitations under the License.
751 */let iK={".sv":"timestamp"};function iQ(){return iK}ej.prototype.simpleListen=function(e,t){this.sendRequest("q",{p:e},t)},ej.prototype.echo=function(e,t){this.sendRequest("echo",{d:e},t)},I=g.Jn,(0,g.Xd)(new m.wA("database",(e,{instanceIdentifier:t})=>(function(e,t,n,i,r){var s,o;let l,a,h,u,c=i||e.options.databaseURL;void 0===c&&(e.options.projectId||W("Can't determine Firebase Database URL. Be sure to include  a Project ID when calling firebase.initializeApp()."),O("Using default host for project ",e.options.projectId),c=`${e.options.projectId}-default-rtdb.firebaseio.com`);let d=iE(c,r),_=d.repoInfo;void 0!==C&&C.env&&(h=C.env.FIREBASE_DATABASE_EMULATOR_HOST),h?(u=!0,_=(d=iE(c=`http://${h}?ns=${_.namespace}`,r)).repoInfo):u=!d.repoInfo.secure;let p=r&&u?new es(es.OWNER):new er(e.name,e.options,t);return it("Invalid Firebase Database URL",d),eq(d.path)||W("Database URL must point to the root of a Firebase Database (not including a child path)."),new iV((s=_,o=new ei(e.name,n),(l=ij[e.name])||(l={},ij[e.name]=l),(a=l[s.toURLString()])&&W("Database initialized multiple times. Please make sure the format of the database URL matches with each database() call."),a=new ia(s,!1,p,o),l[s.toURLString()]=a,a),e)})(e.getProvider("app").getImmediate(),e.getProvider("auth-internal"),e.getProvider("app-check-internal"),t),"PUBLIC").setMultipleInstances(!0)),(0,g.KN)(w,T,void 0),(0,g.KN)(w,T,"esm2017")}}]);
752//# sourceMappingURL=457b8330-f6494dfc6c141cb8.js.map

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.