1import{m as lr,t as B,u as F,v as f,C as Jt,P as ni,w as _e,x as ar,y as cr,z as Wi,A as hr,e as ur,B as dr,E as b,L as fr,G as Zt,H as _r,g as pr,I as mr,J as Y,K as pe,M as gr,N as vn,O as ut,Q as yr,R as vr,T as Ui,U as Cr,V as St,W as Er,X as wr,Y as Tr,Z as Ir,$ as Sr,a0 as Nr,a1 as Xe,S as Rr,i as br,r as ii}from"./DiYFdRWZ.js";var si={};const ri="@firebase/database",oi="1.1.5";/** 2 * @license 3 * Copyright 2019 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 */let Bi="";function Vi(n){Bi=n}/** 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 kr{constructor(e){this.domStorage_=e,this.prefix_="firebase:"}set(e,t){t==null?this.domStorage_.removeItem(this.prefixedName_(e)):this.domStorage_.setItem(this.prefixedName_(e),b(t))}get(e){const t=this.domStorage_.getItem(this.prefixedName_(e));return t==null?null:vn(t)}remove(e){this.domStorage_.removeItem(this.prefixedName_(e))}prefixedName_(e){return this.prefix_+e}toString(){return this.domStorage_.toString()}}/** 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 */class Pr{constructor(){this.cache_={},this.isInMemoryStorage=!0}set(e,t){t==null?delete this.cache_[e]:this.cache_[e]=t}get(e){return Y(this.cache_,e)?this.cache_[e]:null}remove(e){delete this.cache_[e]}}/** 47 * @license 48 * Copyright 2017 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 */const Gi=function(n){try{if(typeof window<"u"&&typeof window[n]<"u"){const e=window[n];return e.setItem("firebase:sentinel","cache"),e.removeItem("firebase:sentinel"),new kr(e)}}catch{}return new Pr},de=Gi("localStorage"),en=Gi("sessionStorage");/** 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 */const Ie=new fr("@firebase/database"),Hi=(function(){let n=1;return function(){return n++}})(),Qi=function(n){const e=Er(n),t=new wr;t.update(e);const i=t.digest();return Tr.encodeByteArray(i)},Je=function(...n){let e="";for(let t=0;t<n.length;t++){const i=n[t];Array.isArray(i)||i&&typeof i=="object"&&typeof i.length=="number"?e+=Je.apply(null,i):typeof i=="object"?e+=b(i):e+=i,e+=" "}return e};let fe=null,li=!0;const qi=function(n,e){f(!e||n===!0||n===!1,"Can't turn on custom loggers persistently."),n===!0?(Ie.logLevel=mr.VERBOSE,fe=Ie.log.bind(Ie),e&&en.set("logging_enabled",!0)):typeof n=="function"?fe=n:(fe=null,en.remove("logging_enabled"))},A=function(...n){if(li===!0&&(li=!1,fe===null&&en.get("logging_enabled")===!0&&qi(!0)),fe){const e=Je.apply(null,n);fe(e)}},Ze=function(n){return function(...e){A(n,...e)}},tn=function(...n){const e="FIREBASE INTERNAL ERROR: "+Je(...n);Ie.error(e)},X=function(...n){const e=`FIREBASE FATAL ERROR: ${Je(...n)}`;throw Ie.error(e),new Error(e)},O=function(...n){const e="FIREBASE WARNING: "+Je(...n);Ie.warn(e)},Ar=function(){typeof window<"u"&&window.location&&window.location.protocol&&window.location.protocol.indexOf("https:")!==-1&&O("Insecure Firebase access from a secure page. Please use https in calls to new Firebase().")},Nt=function(n){return typeof n=="number"&&(n!==n||n===Number.POSITIVE_INFINITY||n===Number.NEGATIVE_INFINITY)},xr=function(n){if(document.readyState==="complete")n();else{let e=!1;const t=function(){if(!document.body){setTimeout(t,Math.floor(10));return}e||(e=!0,n())};document.addEventListener?(document.addEventListener("DOMContentLoaded",t,!1),window.addEventListener("load",t,!1)):document.attachEvent&&(document.attachEvent("onreadystatechange",()=>{document.readyState==="complete"&&t()}),window.attachEvent("onload",t))}},re="[MIN_NAME]",ee="[MAX_NAME]",ve=function(n,e){if(n===e)return 0;if(n===re||e===ee)return-1;if(e===re||n===ee)return 1;{const t=ai(n),i=ai(e);return t!==null?i!==null?t-i===0?n.length-e.length:t-i:-1:i!==null?1:n<e?-1:1}},Dr=function(n,e){return n===e?0:n<e?-1:1},Le=function(n,e){if(e&&n in e)return e[n];throw new Error("Missing required key ("+n+") in object: "+b(e))},Cn=function(n){if(typeof n!="object"||n===null)return b(n);const e=[];for(const i in n)e.push(i);e.sort();let t="{";for(let i=0;i<e.length;i++)i!==0&&(t+=","),t+=b(e[i]),t+=":",t+=Cn(n[e[i]]);return t+="}",t},Yi=function(n,e){const t=n.length;if(t<=e)return[n];const i=[];for(let s=0;s<t;s+=e)s+e>t?i.push(n.substring(s,t)):i.push(n.substring(s,s+e));return i};function x(n,e){for(const t in n)n.hasOwnProperty(t)&&e(t,n[t])}const Ki=function(n){f(!Nt(n),"Invalid JSON number");const e=11,t=52,i=(1<<e-1)-1;let s,r,o,l,a;n===0?(r=0,o=0,s=1/n===-1/0?1:0):(s=n<0,n=Math.abs(n),n>=Math.pow(2,1-i)?(l=Math.min(Math.floor(Math.log(n)/Math.LN2),i),r=l+i,o=Math.round(n*Math.pow(2,t-l)-Math.pow(2,t))):(r=0,o=Math.round(n/Math.pow(2,1-i-t))));const c=[];for(a=t;a;a-=1)c.push(o%2?1:0),o=Math.floor(o/2);for(a=e;a;a-=1)c.push(r%2?1:0),r=Math.floor(r/2);c.push(s?1:0),c.reverse();const h=c.join("");let u="";for(a=0;a<64;a+=8){let d=parseInt(h.substr(a,8),2).toString(16);d.length===1&&(d="0"+d),u=u+d}return u.toLowerCase()},Or=function(){return!!(typeof window=="object"&&window.chrome&&window.chrome.extension&&!/^chrome/.test(window.location.href))},Mr=function(){return typeof Windows=="object"&&typeof Windows.UI=="object"};function Lr(n,e){let t="Unknown Error";n==="too_big"?t="The data requested exceeds the maximum size that can be accessed with a single request.":n==="permission_denied"?t="Client doesn't have permission to access the desired data.":n==="unavailable"&&(t="The service is unavailable");const i=new Error(n+" at "+e._path.toString()+": "+t);return i.code=n.toUpperCase(),i}const Fr=new RegExp("^-?(0*)\\d{1,10}$"),Wr=-2147483648,Ur=2147483647,ai=function(n){if(Fr.test(n)){const e=Number(n);if(e>=Wr&&e<=Ur)return e}return null},xe=function(n){try{n()}catch(e){setTimeout(()=>{const t=e.stack||"";throw O("Exception was thrown by user callback.",t),e},Math.floor(0))}},Br=function(){return(typeof window=="object"&&window.navigator&&window.navigator.userAgent||"").search(/googlebot|google webmaster tools|bingbot|yahoo! slurp|baiduspider|yandexbot|duckduckbot/i)>=0},Be=function(n,e){const t=setTimeout(n,e);return typeof t=="number"&&typeof Deno<"u"&&Deno.unrefTimer?Deno.unrefTimer(t):typeof t=="object"&&t.unref&&t.unref(),t};/** 77 * @license 78 * Copyright 2021 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 Vr{constructor(e,t){this.appCheckProvider=t,this.appName=e.name,pr(e)&&e.settings.appCheckToken&&(this.serverAppAppCheckToken=e.settings.appCheckToken),this.appCheck=t?.getImmediate({optional:!0}),this.appCheck||t?.get().then(i=>this.appCheck=i)}getToken(e){if(this.serverAppAppCheckToken){if(e)throw new Error("Attempted reuse of `FirebaseServerApp.appCheckToken` after previous usage failed.");return Promise.resolve({token:this.serverAppAppCheckToken})}return this.appCheck?this.appCheck.getToken(e):new Promise((t,i)=>{setTimeout(()=>{this.appCheck?this.getToken(e).then(t,i):t(null)},0)})}addTokenChangeListener(e){this.appCheckProvider?.get().then(t=>t.addTokenListener(e))}notifyForInvalidToken(){O(`Provided AppCheck credentials for the app named "${this.appName}" are invalid. This usually indicates your app was not initialized correctly.`)}}/** 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 Gr{constructor(e,t,i){this.appName_=e,this.firebaseOptions_=t,this.authProvider_=i,this.auth_=null,this.auth_=i.getImmediate({optional:!0}),this.auth_||i.onInit(s=>this.auth_=s)}getToken(e){return this.auth_?this.auth_.getToken(e).catch(t=>t&&t.code==="auth/token-not-initialized"?(A("Got auth/token-not-initialized error. Treating as null token."),null):Promise.reject(t)):new Promise((t,i)=>{setTimeout(()=>{this.auth_?this.getToken(e).then(t,i):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/.',O(e)}}class Se{constructor(e){this.accessToken=e}getToken(e){return Promise.resolve({accessToken:this.accessToken})}addTokenChangeListener(e){e(this.accessToken)}removeTokenChangeListener(e){}notifyForInvalidToken(){}}Se.OWNER="owner";/** 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 */const En="5",zi="v",ji="s",$i="r",Xi="f",Ji=/(console\.firebase|firebase-console-\w+\.corp|firebase\.corp)\.google\.com/,Zi="ls",es="p",nn="ac",ts="websocket",ns="long_polling";/** 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 is{constructor(e,t,i,s,r=!1,o="",l=!1,a=!1,c=null){this.secure=t,this.namespace=i,this.webSocketOnly=s,this.nodeAdmin=r,this.persistenceKey=o,this.includeNamespaceInQueryParams=l,this.isUsingEmulator=a,this.emulatorOptions=c,this._host=e.toLowerCase(),this._domain=this._host.substr(this._host.indexOf(".")+1),this.internalHost=de.get("host:"+e)||this._host}isCacheableHost(){return this.internalHost.substr(0,2)==="s-"}isCustomHost(){return this._domain!=="firebaseio.com"&&this._domain!=="firebaseio-demo.com"}get host(){return this._host}set host(e){e!==this.internalHost&&(this.internalHost=e,this.isCacheableHost()&&de.set("host:"+this._host,this.internalHost))}toString(){let e=this.toURLString();return this.persistenceKey&&(e+="<"+this.persistenceKey+">"),e}toURLString(){const e=this.secure?"https://":"http://",t=this.includeNamespaceInQueryParams?`?ns=${this.namespace}`:"";return`${e}${this.host}/${t}`}}function Hr(n){return n.host!==n.internalHost||n.isCustomHost()||n.includeNamespaceInQueryParams}function ss(n,e,t){f(typeof e=="string","typeof type must == string"),f(typeof t=="object","typeof params must == object");let i;if(e===ts)i=(n.secure?"wss://":"ws://")+n.internalHost+"/.ws?";else if(e===ns)i=(n.secure?"https://":"http://")+n.internalHost+"/.lp?";else throw new Error("Unknown connection type: "+e);Hr(n)&&(t.ns=n.namespace);const s=[];return x(t,(r,o)=>{s.push(r+"="+o)}),i+s.join("&")}/** 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 */class Qr{constructor(){this.counters_={}}incrementCounter(e,t=1){Y(this.counters_,e)||(this.counters_[e]=0),this.counters_[e]+=t}get(){return Ir(this.counters_)}}/** 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 */const qt={},Yt={};function wn(n){const e=n.toString();return qt[e]||(qt[e]=new Qr),qt[e]}function qr(n,e){const t=n.toString();return Yt[t]||(Yt[t]=e()),Yt[t]}/** 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, software 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 Yr{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];){const i=this.pendingResponses[this.currentResponseNum];delete this.pendingResponses[this.currentResponseNum];for(let s=0;s<i.length;++s)i[s]&&xe(()=>{this.onMessage_(i[s])});if(this.currentResponseNum===this.closeAfterResponse){this.onClose&&(this.onClose(),this.onClose=null);break}this.currentResponseNum++}}}/** 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 */const ci="start",Kr="close",zr="pLPCommand",jr="pRTLPCB",rs="id",os="pw",ls="ser",$r="cb",Xr="seg",Jr="ts",Zr="d",eo="dframe",as=1870,cs=30,to=as-cs,no=25e3,io=3e4;class te{constructor(e,t,i,s,r,o,l){this.connId=e,this.repoInfo=t,this.applicationId=i,this.appCheckToken=s,this.authToken=r,this.transportSessionId=o,this.lastSessionId=l,this.bytesSent=0,this.bytesReceived=0,this.everConnected_=!1,this.log_=Ze(e),this.stats_=wn(t),this.urlFn=a=>(this.appCheckToken&&(a[nn]=this.appCheckToken),ss(t,ns,a))}open(e,t){this.curSegmentNum=0,this.onDisconnect_=t,this.myPacketOrderer=new Yr(e),this.isClosed_=!1,this.connectTimeoutTimer_=setTimeout(()=>{this.log_("Timed out trying to connect."),this.onClosed_(),this.connectTimeoutTimer_=null},Math.floor(io)),xr(()=>{if(this.isClosed_)return;this.scriptTagHolder=new Tn((...r)=>{const[o,l,a,c,h]=r;if(this.incrementIncomingBytes_(r),!!this.scriptTagHolder)if(this.connectTimeoutTimer_&&(clearTimeout(this.connectTimeoutTimer_),this.connectTimeoutTimer_=null),this.everConnected_=!0,o===ci)this.id=l,this.password=a;else if(o===Kr)l?(this.scriptTagHolder.sendNewPolls=!1,this.myPacketOrderer.closeAfter(l,()=>{this.onClosed_()})):this.onClosed_();else throw new Error("Unrecognized command received: "+o)},(...r)=>{const[o,l]=r;this.incrementIncomingBytes_(r),this.myPacketOrderer.handleResponse(o,l)},()=>{this.onClosed_()},this.urlFn);const i={};i[ci]="t",i[ls]=Math.floor(Math.random()*1e8),this.scriptTagHolder.uniqueCallbackIdentifier&&(i[$r]=this.scriptTagHolder.uniqueCallbackIdentifier),i[zi]=En,this.transportSessionId&&(i[ji]=this.transportSessionId),this.lastSessionId&&(i[Zi]=this.lastSessionId),this.applicationId&&(i[es]=this.applicationId),this.appCheckToken&&(i[nn]=this.appCheckToken),typeof location<"u"&&location.hostname&&Ji.test(location.hostname)&&(i[$i]=Xi);const s=this.urlFn(i);this.log_("Connecting via long-poll to "+s),this.scriptTagHolder.addTag(s,()=>{})})}start(){this.scriptTagHolder.startLongPoll(this.id,this.password),this.addDisconnectPingFrame(this.id,this.password)}static forceAllow(){te.forceAllow_=!0}static forceDisallow(){te.forceDisallow_=!0}static isAvailable(){return te.forceAllow_?!0:!te.forceDisallow_&&typeof document<"u"&&document.createElement!=null&&!Or()&&!Mr()}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){const t=b(e);this.bytesSent+=t.length,this.stats_.incrementCounter("bytes_sent",t.length);const i=Sr(t),s=Yi(i,to);for(let r=0;r<s.length;r++)this.scriptTagHolder.enqueueSegment(this.curSegmentNum,s.length,s[r]),this.curSegmentNum++}addDisconnectPingFrame(e,t){this.myDisconnFrame=document.createElement("iframe");const i={};i[eo]="t",i[rs]=e,i[os]=t,this.myDisconnFrame.src=this.urlFn(i),this.myDisconnFrame.style.display="none",document.body.appendChild(this.myDisconnFrame)}incrementIncomingBytes_(e){const t=b(e).length;this.bytesReceived+=t,this.stats_.incrementCounter("bytes_received",t)}}class Tn{constructor(e,t,i,s){this.onDisconnect=i,this.urlFn=s,this.outstandingRequests=new Set,this.pendingSegs=[],this.currentSerial=Math.floor(Math.random()*1e8),this.sendNewPolls=!0;{this.uniqueCallbackIdentifier=Hi(),window[zr+this.uniqueCallbackIdentifier]=e,window[jr+this.uniqueCallbackIdentifier]=t,this.myIFrame=Tn.createIFrame_();let r="";this.myIFrame.src&&this.myIFrame.src.substr(0,11)==="javascript:"&&(r='<script>document.domain="'+document.domain+'";<\/script>');const o="<html><body>"+r+"</body></html>";
196try{this.myIFrame.doc.open(),this.myIFrame.doc.write(o),this.myIFrame.doc.close()}catch(l){A("frame writing exception"),l.stack&&A(l.stack),A(l)}}}static createIFrame_(){const e=document.createElement("iframe");if(e.style.display="none",document.body){document.body.appendChild(e);try{e.contentWindow.document||A("No IE domain setting required")}catch{const i=document.domain;e.src="javascript:void((function(){document.open();document.domain='"+i+"';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.textContent="",setTimeout(()=>{this.myIFrame!==null&&(document.body.removeChild(this.myIFrame),this.myIFrame=null)},Math.floor(0)));const 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)){this.currentSerial++;const e={};e[rs]=this.myID,e[os]=this.myPW,e[ls]=this.currentSerial;let t=this.urlFn(e),i="",s=0;for(;this.pendingSegs.length>0&&this.pendingSegs[0].d.length+cs+i.length<=as;){const o=this.pendingSegs.shift();i=i+"&"+Xr+s+"="+o.seg+"&"+Jr+s+"="+o.ts+"&"+Zr+s+"="+o.d,s++}return t=t+i,this.addLongPollTag_(t,this.currentSerial),!0}else return!1}enqueueSegment(e,t,i){this.pendingSegs.push({seg:e,ts:t,d:i}),this.alive&&this.newRequest_()}addLongPollTag_(e,t){this.outstandingRequests.add(t);const i=()=>{this.outstandingRequests.delete(t),this.newRequest_()},s=setTimeout(i,Math.floor(no)),r=()=>{clearTimeout(s),i()};this.addTag(e,r)}addTag(e,t){setTimeout(()=>{try{if(!this.sendNewPolls)return;const i=this.myIFrame.doc.createElement("script");i.type="text/javascript",i.async=!0,i.src=e,i.onload=i.onreadystatechange=function(){const s=i.readyState;(!s||s==="loaded"||s==="complete")&&(i.onload=i.onreadystatechange=null,i.parentNode&&i.parentNode.removeChild(i),t())},i.onerror=()=>{A("Long-poll script failed to load: "+e),this.sendNewPolls=!1,this.close()},this.myIFrame.doc.body.appendChild(i)}catch{}},Math.floor(1))}}/** 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 */const so=16384,ro=45e3;let dt=null;typeof MozWebSocket<"u"?dt=MozWebSocket:typeof WebSocket<"u"&&(dt=WebSocket);class V{constructor(e,t,i,s,r,o,l){this.connId=e,this.applicationId=i,this.appCheckToken=s,this.authToken=r,this.keepaliveTimer=null,this.frames=null,this.totalFrames=0,this.bytesSent=0,this.bytesReceived=0,this.log_=Ze(this.connId),this.stats_=wn(t),this.connURL=V.connectionURL_(t,o,l,s,i),this.nodeAdmin=t.nodeAdmin}static connectionURL_(e,t,i,s,r){const o={};return o[zi]=En,typeof location<"u"&&location.hostname&&Ji.test(location.hostname)&&(o[$i]=Xi),t&&(o[ji]=t),i&&(o[Zi]=i),s&&(o[nn]=s),r&&(o[es]=r),ss(e,ts,o)}open(e,t){this.onDisconnect=t,this.onMessage=e,this.log_("Websocket connecting to "+this.connURL),this.everConnected_=!1,de.set("previous_websocket_failure",!0);try{let i;Nr(),this.mySock=new dt(this.connURL,[],i)}catch(i){this.log_("Error instantiating WebSocket.");const s=i.message||i.data;s&&this.log_(s),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=i=>{this.handleIncomingFrame(i)},this.mySock.onerror=i=>{this.log_("WebSocket error. Closing connection.");const s=i.message||i.data;s&&this.log_(s),this.onClosed_()}}start(){}static forceDisallow(){V.forceDisallow_=!0}static isAvailable(){let e=!1;if(typeof navigator<"u"&&navigator.userAgent){const t=/Android ([0-9]{0,}\.[0-9]{0,})/,i=navigator.userAgent.match(t);i&&i.length>1&&parseFloat(i[1])<4.4&&(e=!0)}return!e&&dt!==null&&!V.forceDisallow_}static previouslyFailed(){return de.isInMemoryStorage||de.get("previous_websocket_failure")===!0}markConnectionHealthy(){de.remove("previous_websocket_failure")}appendFrame_(e){if(this.frames.push(e),this.frames.length===this.totalFrames){const t=this.frames.join("");this.frames=null;const i=vn(t);this.onMessage(i)}}handleNewFrameCount_(e){this.totalFrames=e,this.frames=[]}extractFrameCount_(e){if(f(this.frames===null,"We already have a frame buffer"),e.length<=6){const t=Number(e);if(!isNaN(t))return this.handleNewFrameCount_(t),null}return this.handleNewFrameCount_(1),e}handleIncomingFrame(e){if(this.mySock===null)return;const t=e.data;if(this.bytesReceived+=t.length,this.stats_.incrementCounter("bytes_received",t.length),this.resetKeepAlive(),this.frames!==null)this.appendFrame_(t);else{const i=this.extractFrameCount_(t);i!==null&&this.appendFrame_(i)}}send(e){this.resetKeepAlive();const t=b(e);this.bytesSent+=t.length,this.stats_.incrementCounter("bytes_sent",t.length);const i=Yi(t,so);i.length>1&&this.sendString_(String(i.length));for(let s=0;s<i.length;s++)this.sendString_(i[s])}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(ro))}sendString_(e){try{this.mySock.send(e)}catch(t){this.log_("Exception thrown from WebSocket.send():",t.message||t.data,"Closing connection."),setTimeout(this.onClosed_.bind(this),0)}}}V.responsesRequiredToBeHealthy=2;V.healthyTimeout=3e4;/** 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 Ne{static get ALL_TRANSPORTS(){return[te,V]}static get IS_TRANSPORT_INITIALIZED(){return this.globalTransportInitialized_}constructor(e){this.initTransports_(e)}initTransports_(e){const t=V&&V.isAvailable();let i=t&&!V.previouslyFailed();if(e.webSocketOnly&&(t||O("wss:// URL used, but browser isn't known to support websockets. Trying anyway."),i=!0),i)this.transports_=[V];else{const s=this.transports_=[];for(const r of Ne.ALL_TRANSPORTS)r&&r.isAvailable()&&s.push(r);Ne.globalTransportInitialized_=!0}}initialTransport(){if(this.transports_.length>0)return this.transports_[0];throw new Error("No transports available")}upgradeTransport(){return this.transports_.length>1?this.transports_[1]:null}}Ne.globalTransportInitialized_=!1;/** 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 */const oo=6e4,lo=5e3,ao=10*1024,co=100*1024,Kt="t",hi="d",ho="s",ui="r",uo="e",di="o",fi="a",_i="n",pi="p",fo="h";class _o{constructor(e,t,i,s,r,o,l,a,c,h){this.id=e,this.repoInfo_=t,this.applicationId_=i,this.appCheckToken_=s,this.authToken_=r,this.onMessage_=o,this.onReady_=l,this.onDisconnect_=a,this.onKill_=c,this.lastSessionId=h,this.connectionCount=0,this.pendingDataMessages=[],this.state_=0,this.log_=Ze("c:"+this.id+":"),this.transportManager_=new Ne(t),this.log_("Connection created"),this.start_()}start_(){const 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;const t=this.connReceiver_(this.conn_),i=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,i)},Math.floor(0));const s=e.healthyTimeout||0;s>0&&(this.healthyTimeout_=Be(()=>{this.healthyTimeout_=null,this.isHealthy_||(this.conn_&&this.conn_.bytesReceived>co?(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>ao?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(s)))}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=>{this.state_!==2&&(e===this.rx_?this.onPrimaryMessageReceived_(t):e===this.secondaryConn_?this.onSecondaryMessageReceived_(t):this.log_("message on old connection"))}}sendRequest(e){const t={t:"d",d:e};this.sendData_(t)}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(Kt in e){const t=e[Kt];t===fi?this.upgradeIfSecondaryHealthy_():t===ui?(this.log_("Got a reset on secondary, closing it"),this.secondaryConn_.close(),(this.tx_===this.secondaryConn_||this.rx_===this.secondaryConn_)&&this.close()):t===di&&(this.log_("got pong on secondary."),this.secondaryResponsesRequired_--,this.upgradeIfSecondaryHealthy_())}}onSecondaryMessageReceived_(e){const t=Le("t",e),i=Le("d",e);if(t==="c")this.onSecondaryControl_(i);else if(t==="d")this.pendingDataMessages.push(i);else throw new 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
vendor: 4,248 bytes, lines 241-251
241:"c",d:{t:pi,d:{}}}))}proceedWithUpgrade_(){this.secondaryConn_.start(),this.log_("sending client ack on secondary"),this.secondaryConn_.send({t:"c",d:{t:fi,d:{}}}),this.log_("Ending transmission on primary"),this.conn_.send({t:"c",d:{t:_i,d:{}}}),this.tx_=this.secondaryConn_,this.tryCleanupConnection()}onPrimaryMessageReceived_(e){const t=Le("t",e),i=Le("d",e);t==="c"?this.onControl_(i):t==="d"&&this.onDataMessage_(i)}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){const t=Le(Kt,e);if(hi in e){const i=e[hi];if(t===fo){const s={...i};this.repoInfo_.isUsingEmulator&&(s.h=this.repoInfo_.host),this.onHandshake_(s)}else if(t===_i){this.log_("recvd end transmission on primary"),this.rx_=this.secondaryConn_;for(let s=0;s<this.pendingDataMessages.length;++s)this.onDataMessage_(this.pendingDataMessages[s]);this.pendingDataMessages=[],this.tryCleanupConnection()}else t===ho?this.onConnectionShutdown_(i):t===ui?this.onReset_(i):t===uo?tn("Server Error: "+i):t===di?(this.log_("got pong on primary."),this.onPrimaryResponse_(),this.sendPingOnPrimaryIfNecessary_()):tn("Unknown control packet command: "+t)}}onHandshake_(e){const t=e.ts,i=e.v,s=e.h;this.sessionId=e.s,this.repoInfo_.host=s,this.state_===0&&(this.conn_.start(),this.onConnectionEstablished_(this.conn_,t),En!==i&&O("Protocol version mismatch detected"),this.tryStartUpgrade_())}tryStartUpgrade_(){const 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;const t=this.connReceiver_(this.secondaryConn_),i=this.disconnReceiver_(this.secondaryConn_);this.secondaryConn_.open(t,i),Be(()=>{this.secondaryConn_&&(this.log_("Timed out trying to upgrade."),this.secondaryConn_.close())},Math.floor(oo))}onReset_(e){this.log_("Reset packet received. New host: "+e),this.repoInfo_.host=e,this.state_===1?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),this.primaryResponsesRequired_===0?(this.log_("Primary connection is healthy."),this.isHealthy_=!0):Be(()=>{this.sendPingOnPrimaryIfNecessary_()},Math.floor(lo))}sendPingOnPrimaryIfNecessary_(){!this.isHealthy_&&this.state_===1&&(this.log_("sending ping on primary."),this.sendData_({t:"c",d:{t:pi,d:{}}}))}onSecondaryConnectionLost_(){const e=this.secondaryConn_;this.secondaryConn_=null,(this.tx_===e||this.rx_===e)&&this.close()}onConnectionLost_(e){this.conn_=null,!e&&this.state_===0?(this.log_("Realtime connection failed."),this.repoInfo_.isCacheableHost()&&(de.remove("host:"+this.repoInfo_.host),this.repoInfo_.internalHost=this.repoInfo_.host)):this.state_===1&&this.log_("Realtime connection lost."),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(this.state_!==1)throw"Connection is not connected";this.tx_.send(e)}close(){this.state_!==2&&(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)}}/** 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, softw
251are 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 hs{put(e,t,i,s){}merge(e,t,i,s){}refreshAuthToken(e){}refreshAppCheckToken(e){}onDisconnectPut(e,t,i){}onDisconnectMerge(e,t,i){}onDisconnectCancel(e,t){}reportStats(e){}}/** 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 us{constructor(e){this.allowedEvents_=e,this.listeners_={},f(Array.isArray(e)&&e.length>0,"Requires a non-empty array")}trigger(e,...t){if(Array.isArray(this.listeners_[e])){const i=[...this.listeners_[e]];for(let s=0;s<i.length;s++)i[s].callback.apply(i[s].context,t)}}on(e,t,i){this.validateEventType_(e),this.listeners_[e]=this.listeners_[e]||[],this.listeners_[e].push({callback:t,context:i});const s=this.getInitialEvent(e);s&&t.apply(i,s)}off(e,t,i){this.validateEventType_(e);const s=this.listeners_[e]||[];for(let r=0;r<s.length;r++)if(s[r].callback===t&&(!i||i===s[r].context)){s.splice(r,1);return}}validateEventType_(e){f(this.allowedEvents_.find(t=>t===e),"Unknown event: "+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 */class ft extends us{static getInstance(){return new ft}constructor(){super(["online"]),this.online_=!0,typeof window<"u"&&typeof window.addEventListener<"u"&&!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))}getInitialEvent(e){return f(e==="online","Unknown event type: "+e),[this.online_]}currentlyOnline(){return this.online_}}/** 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 */const mi=32,gi=768;class E{constructor(e,t){if(t===void 0){this.pieces_=e.split("/");let i=0;for(let s=0;s<this.pieces_.length;s++)this.pieces_[s].length>0&&(this.pieces_[i]=this.pieces_[s],i++);this.pieces_.length=i,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 C(){return new E("")}function g(n){return n.pieceNum_>=n.pieces_.length?null:n.pieces_[n.pieceNum_]}function oe(n){return n.pieces_.length-n.pieceNum_}function T(n){let e=n.pieceNum_;return e<n.pieces_.length&&e++,new E(n.pieces_,e)}function In(n){return n.pieceNum_<n.pieces_.length?n.pieces_[n.pieces_.length-1]:null}function po(n){let e="";for(let t=n.pieceNum_;t<n.pieces_.length;t++)n.pieces_[t]!==""&&(e+="/"+encodeURIComponent(String(n.pieces_[t])));return e||"/"}function Qe(n,e=0){return n.pieces_.slice(n.pieceNum_+e)}function ds(n){if(n.pieceNum_>=n.pieces_.length)return null;const e=[];for(let t=n.pieceNum_;t<n.pieces_.length-1;t++)e.push(n.pieces_[t]);return new E(e,0)}function N(n,e){const t=[];for(let i=n.pieceNum_;i<n.pieces_.length;i++)t.push(n.pieces_[i]);if(e instanceof E)for(let i=e.pieceNum_;i<e.pieces_.length;i++)t.push(e.pieces_[i]);else{const i=e.split("/");for(let s=0;s<i.length;s++)i[s].length>0&&t.push(i[s])}return new E(t,0)}function y(n){return n.pieceNum_>=n.pieces_.length}function M(n,e){const t=g(n),i=g(e);if(t===null)return e;if(t===i)return M(T(n),T(e));
301throw new Error("INTERNAL ERROR: innerPath ("+e+") is not within outerPath ("+n+")")}function mo(n,e){const t=Qe(n,0),i=Qe(e,0);for(let s=0;s<t.length&&s<i.length;s++){const r=ve(t[s],i[s]);if(r!==0)return r}return t.length===i.length?0:t.length<i.length?-1:1}function Sn(n,e){if(oe(n)!==oe(e))return!1;for(let t=n.pieceNum_,i=e.pieceNum_;t<=n.pieces_.length;t++,i++)if(n.pieces_[t]!==e.pieces_[i])return!1;return!0}function G(n,e){let t=n.pieceNum_,i=e.pieceNum_;if(oe(n)>oe(e))return!1;for(;t<n.pieces_.length;){if(n.pieces_[t]!==e.pieces_[i])return!1;++t,++i}return!0}class go{constructor(e,t){this.errorPrefix_=t,this.parts_=Qe(e,0),this.byteLength_=Math.max(1,this.parts_.length);for(let i=0;i<this.parts_.length;i++)this.byteLength_+=St(this.parts_[i]);fs(this)}}function yo(n,e){n.parts_.length>0&&(n.byteLength_+=1),n.parts_.push(e),n.byteLength_+=St(e),fs(n)}function vo(n){const e=n.parts_.pop();n.byteLength_-=St(e),n.parts_.length>0&&(n.byteLength_-=1)}function fs(n){if(n.byteLength_>gi)throw new Error(n.errorPrefix_+"has a key path longer than "+gi+" bytes ("+n.byteLength_+").");if(n.parts_.length>mi)throw new Error(n.errorPrefix_+"path specified exceeds the maximum depth that can be written ("+mi+") or object contains a cycle "+ue(n))}function ue(n){return n.parts_.length===0?"":"in property '"+n.parts_.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 Nn extends us{static getInstance(){return new Nn}constructor(){super(["visible"]);let e,t;typeof document<"u"&&typeof document.addEventListener<"u"&&(typeof document.hidden<"u"?(t="visibilitychange",e="hidden"):typeof document.mozHidden<"u"?(t="mozvisibilitychange",e="mozHidden"):typeof document.msHidden<"u"?(t="msvisibilitychange",e="msHidden"):typeof document.webkitHidden<"u"&&(t="webkitvisibilitychange",e="webkitHidden")),this.visible_=!0,t&&document.addEventListener(t,()=>{const i=!document[e];i!==this.visible_&&(this.visible_=i,this.trigger("visible",i))},!1)}getInitialEvent(e){return f(e==="visible","Unknown event type: "+e),[this.visible_]}}/** 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 */const Fe=1e3,Co=300*1e3,yi=30*1e3,Eo=1.3,wo=3e4,To="server_kill",vi=3;class H extends hs{constructor(e,t,i,s,r,o,l,a){if(super(),this.repoInfo_=e,this.applicationId_=t,this.onDataUpdate_=i,this.onConnectStatus_=s,this.onServerInfoUpdate_=r,this.authTokenProvider_=o,this.appCheckTokenProvider_=l,this.authOverride_=a,this.id=H.nextPersistentConnectionId_++,this.log_=Ze("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_=Fe,this.maxReconnectDelay_=Co,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,a)throw new Error("Auth override specified in options, but not supported on non Node.js platforms");Nn.getInstance().on("visible",this.onVisible_,this),e.host.indexOf("fblocal")===-1&&ft.getInstance().on("online",this.onOnline_,this)}sendRequest(e,t,i){const s=++this.requestNumber_,r={r:s,a:e,b:t};this.log_(b(r)),f(this.connected_,"sendRequest call when we're not connected not allowed."),this.realtime_.sendRequest(r),i&&(this.requestCBHash_[s]=i)}get(e){this.initConnection_();const t=new B,s={action:"g",request:{p:e._path.toString(),q:e._queryObject},onComplete:o=>{const l=o.d;o.s==="ok"?t.resolve(l):t.reject(l)}};this.outstandingGets_.push(s),this.outstandingGetCount_++;const r=this.outstandingGets_.length-1;return this.connected_&&this.sendGet_(r),t.promise}listen(e,t,i,s){this.initConnection_();const r=e._queryIdentifier,o=e._path.toString();this.log_("Listen called for "+o+" "+r),this.listens.has(o)||this.listens.set(o,new Map),f(e._queryParams.isDefault()||!e._queryParams.loadsAllData(),"listen() called for non-default but complete query"),f(!this.listens.get(o).has(r),"listen() called twice for same path/queryId.");const l={onComplete:s,hashFn:t,query:e,tag:i};this.listens.get(o).set(r,l),this.connected_&&this.sendListen_(l)}sendGet_(e){const t=this.outstandingGets_[e];this.sendRequest("g",t.request,i=>{delete this.outstandingGets_[e],this.outstandingGetCount_--,this.outstandingGetCount_===0&&(this.outstandingGets_=[]),t.onComplete&&t.onComplete(i)})}sendListen_(e){const t=e.query,i=t._path.toString(),s=t._queryIdentifier;this.log_("Listen on "+i+" for "+s);const r={p:i},o="q";e.tag&&(r.q=t._queryObject,r.t=e.tag),r.h=e.hashFn(),this.sendRequest(o,r,l=>{const a=l.d,c=l.s;H.warnOnListenWarnings_(a,t),(this.listens.get(i)&&this.listens.get(i).get(s))===e&&(this.log_("listen response",l),c!=="ok"&&this.removeListen_(i,s),e.onComplete&&e.onComplete(c,a))})}static warnOnListenWarnings_(e,t){if(e&&typeof e=="object"&&Y(e,"w")){const i=pe(e,"
331w");if(Array.isArray(i)&&~i.indexOf("no_index")){const s='".indexOn": "'+t._queryParams.getIndex().toString()+'"',r=t._path.toString();O(`Using an unspecified index. Your data will be downloaded and filtered on the client. Consider adding ${s} at ${r} 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&&e.length===40||yr(e))&&(this.log_("Admin auth credential detected. Reducing max reconnect time."),this.maxReconnectDelay_=yi)}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_){const e=this.authToken_,t=vr(e)?"auth":"gauth",i={cred:e};this.authOverride_===null?i.noauth=!0:typeof this.authOverride_=="object"&&(i.authvar=this.authOverride_),this.sendRequest(t,i,s=>{const r=s.s,o=s.d||"error";this.authToken_===e&&(r==="ok"?this.invalidAuthTokenCount_=0:this.onAuthRevoked_(r,o))})}}tryAppCheck(){this.connected_&&this.appCheckToken_&&this.sendRequest("appcheck",{token:this.appCheckToken_},e=>{const t=e.s,i=e.d||"error";t==="ok"?this.invalidAppCheckTokenCount_=0:this.onAppCheckRevoked_(t,i)})}unlisten(e,t){const i=e._path.toString(),s=e._queryIdentifier;this.log_("Unlisten called for "+i+" "+s),f(e._queryParams.isDefault()||!e._queryParams.loadsAllData(),"unlisten() called for non-default but complete query"),this.removeListen_(i,s)&&this.connected_&&this.sendUnlisten_(i,s,e._queryObject,t)}sendUnlisten_(e,t,i,s){this.log_("Unlisten on "+e+" for "+t);const r={p:e},o="n";s&&(r.q=i,r.t=s),this.sendRequest(o,r)}onDisconnectPut(e,t,i){this.initConnection_(),this.connected_?this.sendOnDisconnect_("o",e,t,i):this.onDisconnectRequestQueue_.push({pathString:e,action:"o",data:t,onComplete:i})}onDisconnectMerge(e,t,i){this.initConnection_(),this.connected_?this.sendOnDisconnect_("om",e,t,i):this.onDisconnectRequestQueue_.push({pathString:e,action:"om",data:t,onComplete:i})}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,i,s){const r={p:t,d:i};this.log_("onDisconnect "+e,r),this.sendRequest(e,r,o=>{s&&setTimeout(()=>{s(o.s,o.d)},Math.floor(0))})}put(e,t,i,s){this.putInternal("p",e,t,i,s)}merge(e,t,i,s){this.putInternal("m",e,t,i,s)}putInternal(e,t,i,s,r){this.initConnection_();const o={p:t,d:i};r!==void 0&&(o.h=r),this.outstandingPuts_.push({action:e,request:o,onComplete:s}),this.outstandingPutCount_++;const l=this.outstandingPuts_.length-1;this.connected_?this.sendPut_(l):this.log_("Buffering put: "+t)}sendPut_(e){const t=this.outstandingPuts_[e].action,i=this.outstandingPuts_[e].request,s=this.outstandingPuts_[e].onComplete;this.outstandingPuts_[e].queued=this.connected_,this.sendRequest(t,i,r=>{this.log_(t+" response",r),delete this.outstandingPuts_[e],this.outstandingPutCount_--,this.outstandingPutCount_===0&&(this.outstandingPuts_=[]),s&&s(r.s,r.d)})}reportStats(e){if(this.connected_){const t={c:e};this.log_("reportStats",t),this.sendRequest("s",t,i=>{if(i.s!=="ok"){const r=i.d;this.log_("reportStats","Error sending stats: "+r)}})}}onDataMessage_(e){if("r"in e){this.log_("from server: "+b(e));const t=e.r,i=this.requestCBHash_[t];i&&(delete this.requestCBHash_[t],i(e.b))}else{if("error"in e)throw"A server-side error has occurred: "+e.error;"a"in e&&this.onDataPush_(e.a,e.b)}}onDataPush_(e,t){this.log_("handleServerMessage",e,t),e==="d"?this.onDataUpdate_(t.p,t.d,!1,t.t):e==="m"?this.onDataUpdate_(t.p,t.d,!0,t.t):e==="c"?this.onListenRevoked_(t.p,t.q):e==="ac"?this.onAuthRevoked_(t.s,t.d):e==="apc"?this.onAppCheckRevoked_(t.s,t.d):e==="sd"?this.onSecurityDebugPacket_(t):tn("Unrecognized action received from server: "+b(e)+` 332Are 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){f(!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_=Fe,this.realtime_||this.scheduleConnect_(0)),this.visible_=e}onOnline_(e){e?(this.log_("Browser went online."),this.reconnectDelay_=Fe,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_>wo&&(this.reconnectDelay_=Fe),this.lastConnectionEstablishedTime_=null):(this.log_("Window isn't visible. Delaying reconnect."),this.reconnectDelay_=this.maxReconnectDelay_,this.lastConnectionAttemptTime_=new Date().getTime());const e=Math.max(0,new Date().getTime()-this.lastConnectionAttemptTime_);let t=Math.max(0,this.reconnectDelay_-e);
332t=Math.random()*t,this.log_("Trying to reconnect in "+t+"ms"),this.scheduleConnect_(t),this.reconnectDelay_=Math.min(this.maxReconnectDelay_,this.reconnectDelay_*Eo)}this.onConnectStatus_(!1)}async establishConnection_(){if(this.shouldReconnect_()){this.log_("Making a connection attempt"),this.lastConnectionAttemptTime_=new Date().getTime(),this.lastConnectionEstablishedTime_=null;const e=this.onDataMessage_.bind(this),t=this.onReady_.bind(this),i=this.onRealtimeDisconnect_.bind(this),s=this.id+":"+H.nextConnectionId_++,r=this.lastSessionId;let o=!1,l=null;const a=function(){l?l.close():(o=!0,i())},c=function(u){f(l,"sendRequest call when we're not connected not allowed."),l.sendRequest(u)};this.realtime_={close:a,sendRequest:c};const h=this.forceTokenRefresh_;this.forceTokenRefresh_=!1;try{const[u,d]=await Promise.all([this.authTokenProvider_.getToken(h),this.appCheckTokenProvider_.getToken(h)]);o?A("getToken() completed but was canceled"):(A("getToken() completed. Creating connection."),this.authToken_=u&&u.accessToken,this.appCheckToken_=d&&d.token,l=new _o(s,this.repoInfo_,this.applicationId_,this.appCheckToken_,this.authToken_,e,t,i,_=>{O(_+" ("+this.repoInfo_.toString()+")"),this.interrupt(To)},r))}catch(u){this.log_("Failed to get token: "+u),o||(this.repoInfo_.nodeAdmin&&O(u),a())}}}interrupt(e){A("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){A("Resuming connection for reason: "+e),delete this.interruptReasons_[e],Zt(this.interruptReasons_)&&(this.reconnectDelay_=Fe,this.realtime_||this.scheduleConnect_(0))}handleTimestamp_(e){const t=e-new Date().getTime();this.onServerInfoUpdate_({serverTimeOffset:t})}cancelSentTransactions_(){for(let e=0;e<this.outstandingPuts_.length;e++){const t=this.outstandingPuts_[e];t&&"h"in t.request&&t.queued&&(t.onComplete&&t.onComplete("disconnect"),delete this.outstandingPuts_[e],this.outstandingPutCount_--)}this.outstandingPutCount_===0&&(this.outstandingPuts_=[])}onListenRevoked_(e,t){let i;t?i=t.map(r=>Cn(r)).join("$"):i="default";const s=this.removeListen_(e,i);s&&s.onComplete&&s.onComplete("permission_denied")}removeListen_(e,t){const i=new E(e).toString();let s;if(this.listens.has(i)){const r=this.listens.get(i);s=r.get(t),r.delete(t),r.size===0&&this.listens.delete(i)}else s=void 0;return s}onAuthRevoked_(e,t){A("Auth token revoked: "+e+"/"+t),this.authToken_=null,this.forceTokenRefresh_=!0,this.realtime_.close(),(e==="invalid_token"||e==="permission_denied")&&(this.invalidAuthTokenCount_++,this.invalidAuthTokenCount_>=vi&&(this.reconnectDelay_=yi,this.authTokenProvider_.notifyForInvalidToken()))}onAppCheckRevoked_(e,t){A("App check token revoked: "+e+"/"+t),this.appCheckToken_=null,this.forceTokenRefresh_=!0,(e==="invalid_token"||e==="permission_denied")&&(this.invalidAppCheckTokenCount_++,this.invalidAppCheckTokenCount_>=vi&&this.appCheckTokenProvider_.notifyForInvalidToken())}onSecurityDebugPacket_(e){this.securityDebugCallback_?this.securityDebugCallback_(e):"msg"in e&&console.log("FIREBASE: "+e.msg.replace(` 333`,` 334FIREBASE: `))}restoreState_(){this.tryAuth(),this.tryAppCheck();for(const e of this.listens.values())for(const 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;){const 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_(){const e={};let t="js";e["sdk."+t+"."+Bi.replace(/\./g,"-")]=1,Ui()?e["framework.cordova"]=1:Cr()&&(e["framework.reactnative"]=1),this.reportStats(e)}shouldReconnect_(){const e=ft.getInstance().currentlyOnline();return Zt(this.interruptReasons_)&&e}}H.nextPersistentConnectionId_=0;H.nextConnectionId_=0;/** 335 * @license 336 * Copyright 2017 Google LLC 337 * 338 * Licensed under the Apache License, Version 2.0 (the "License");
339 * you may not use this file except in compliance with the License. 340 * You may obtain a copy of the License at 341 * 342 * http://www.apache.org/licenses/LICENSE-2.0 343 * 344 * Unless required by applicable law or agreed to in writing, software 345 * distributed under the License is distributed on an "AS IS" BASIS, 346 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 347 * See the License for the specific language governing permissions and 348 * limitations under the License. 349 */class v{constructor(e,t){this.name=e,this.node=t}static Wrap(e,t){return new v(e,t)}}/** 350 * @license 351 * Copyright 2017 Google LLC 352 * 353 * Licensed under the Apache License, Version 2.0 (the "License"); 354 * you may not use this file except in compliance with the License. 355 * You may obtain a copy of the License at 356 * 357 * http://www.apache.org/licenses/LICENSE-2.0 358 * 359 * Unless required by applicable law or agreed to in writing, software 360 * distributed under the License is distributed on an "AS IS" BASIS, 361 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 362 * See the License for the specific language governing permissions and 363 * limitations under the License. 364 */class Rt{getCompare(){return this.compare.bind(this)}indexedValueChanged(e,t){const i=new v(re,e),s=new v(re,t);return this.compare(i,s)!==0}minPost(){return v.MIN}}/** 365 * @license 366 * Copyright 2017 Google LLC 367 * 368 * Licensed under the Apache License, Version 2.0 (the "License"); 369 * you may not use this file except in compliance with the License. 370 * You may obtain a copy of the License at 371 * 372 * http://www.apache.org/licenses/LICENSE-2.0 373 * 374 * Unless required by applicable law or agreed to in writing, software 375 * distributed under the License is distributed on an "AS IS" BASIS, 376 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 377 * See the License for the specific language governing permissions and 378 * limitations under the License. 379 */let ct;class _s extends Rt{static get __EMPTY_NODE(){return ct}static set __EMPTY_NODE(e){ct=e}compare(e,t){return ve(e.name,t.name)}isDefinedOn(e){throw Xe("KeyIndex.isDefinedOn not expected to be called.")}indexedValueChanged(e,t){return!1}minPost(){return v.MIN}maxPost(){return new v(ee,ct)}makePost(e,t){return f(typeof e=="string","KeyIndex indexValue must always be a string."),new v(e,ct)}toString(){return".key"}}const $=new _s;/** 380 * @license 381 * Copyright 2017 Google LLC 382 * 383 * Licensed under the Apache License, Version 2.0 (the "License"); 384 * you may not use this file except in compliance with the License. 385 * You may obtain a copy of the License at 386 * 387 * http://www.apache.org/licenses/LICENSE-2.0 388 * 389 * Unless required by applicable law or agreed to in writing, software 390 * distributed under the License is distributed on an "AS IS" BASIS, 391 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 392 * See the License for the specific language governing permissions and 393 * limitations under the License. 394 */class ht{constructor(e,t,i,s,r=null){this.isReverse_=s,this.resultGenerator_=r,this.nodeStack_=[];let o=1;for(;!e.isEmpty();)if(e=e,o=t?i(e.key,t):1,s&&(o*=-1),o<0)this.isReverse_?e=e.left:e=e.right;else if(o===0){this.nodeStack_.push(e);break}else this.nodeStack_.push(e),this.isReverse_?e=e.right:e=e.left}getNext(){if(this.nodeStack_.length===0)return null;let e=this.nodeStack_.pop(),t;if(this.resultGenerator_?t=this.resultGenerator_(e.key,e.value):t={key:e.key,value:e.value},this.isReverse_)for(e=e.left;!e.isEmpty();)this.nodeStack_.push(e),e=e.right;else for(e=e.right;!e.isEmpty();)this.nodeStack_.push(e),e=e.left;return t}hasNext(){return this.nodeStack_.length>0}peek(){if(this.nodeStack_.length===0)return null;const e=this.nodeStack_[this.nodeStack_.length-1];return this.resultGenerator_?this.resultGenerator_(e.key,e.value):{key:e.key,value:e.value}}}class P{constructor(e,t,i,s,r){this.key=e,this.value=t,this.color=i??P.RED,this.left=s??L.EMPTY_NODE,this.right=r??L.EMPTY_NODE}copy(e,t,i,s,r){return new P(e??this.key,t??this.value,i??this.color,s??this.left,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,i){let s=this;const r=i(e,s.key);return r<0?s=s.copy(null,null,null,s.left.insert(e,t,i),null):r===0?s=s.copy(null,t,null,null,null):s=s.copy(null,null,null,null,s.right.insert(e,t,i)),s.fixUp_()}
vendor: 1,805 bytes, line 394
394removeMin_(){if(this.left.isEmpty())return L.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),e.fixUp_()}remove(e,t){let i,s;if(i=this,t(e,i.key)<0)!i.left.isEmpty()&&!i.left.isRed_()&&!i.left.left.isRed_()&&(i=i.moveRedLeft_()),i=i.copy(null,null,null,i.left.remove(e,t),null);else{if(i.left.isRed_()&&(i=i.rotateRight_()),!i.right.isEmpty()&&!i.right.isRed_()&&!i.right.left.isRed_()&&(i=i.moveRedRight_()),t(e,i.key)===0){if(i.right.isEmpty())return L.EMPTY_NODE;s=i.right.min_(),i=i.copy(s.key,s.value,null,null,i.right.removeMin_())}i=i.copy(null,null,null,null,i.right.remove(e,t))}return i.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.copy(null,null,null,null,e.right.rotateRight_()),e=e.rotateLeft_(),e=e.colorFlip_()),e}moveRedRight_(){let e=this.colorFlip_();return e.left.left.isRed_()&&(e=e.rotateRight_(),e=e.colorFlip_()),e}rotateLeft_(){const e=this.copy(null,null,P.RED,null,this.right.left);return this.right.copy(null,null,this.color,e,null)}rotateRight_(){const e=this.copy(null,null,P.RED,this.left.right,null);return this.left.copy(null,null,this.color,null,e)}colorFlip_(){const 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_(){const e=this.check_();return Math.pow(2,e)<=this.count()+1}check_(){if(this.isRed_()&&this.left.isRed_())throw new Error("Red node has red child("+this.key+","+this.value+")");
394if(this.right.isRed_())throw new Error("Right child of ("+this.key+","+this.value+") is red");const e=this.left.check_();if(e!==this.right.check_())throw new Error("Black depths differ");return e+(this.isRed_()?0:1)}}P.RED=!0;P.BLACK=!1;class Io{copy(e,t,i,s,r){return this}insert(e,t,i){return new P(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 L{constructor(e,t=L.EMPTY_NODE){this.comparator_=e,this.root_=t}insert(e,t){return new L(this.comparator_,this.root_.insert(e,t,this.comparator_).copy(null,null,P.BLACK,null,null))}remove(e){return new L(this.comparator_,this.root_.remove(e,this.comparator_).copy(null,null,P.BLACK,null,null))}get(e){let t,i=this.root_;for(;!i.isEmpty();){if(t=this.comparator_(e,i.key),t===0)return i.value;t<0?i=i.left:t>0&&(i=i.right)}return null}getPredecessorKey(e){let t,i=this.root_,s=null;for(;!i.isEmpty();)if(t=this.comparator_(e,i.key),t===0){if(i.left.isEmpty())return s?s.key:null;for(i=i.left;!i.right.isEmpty();)i=i.right;return i.key}else t<0?i=i.left:t>0&&(s=i,i=i.right);throw new 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 ht(this.root_,null,this.comparator_,!1,e)}getIteratorFrom(e,t){return new ht(this.root_,e,this.comparator_,!1,t)}getReverseIteratorFrom(e,t){return new ht(this.root_,e,this.comparator_,!0,t)}getReverseIterator(e){return new ht(this.root_,null,this.comparator_,!0,e)}}L.EMPTY_NODE=new Io;/** 395 * @license 396 * Copyright 2017 Google LLC 397 * 398 * Licensed under the Apache License, Version 2.0 (the "License"); 399 * you may not use this file except in compliance with the License. 400 * You may obtain a copy of the License at 401 * 402 * http://www.apache.org/licenses/LICENSE-2.0 403 * 404 * Unless required by applicable law or agreed to in writing, software 405 * distributed under the License is distributed on an "AS IS" BASIS, 406 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 407 * See the License for the specific language governing permissions and 408 * limitations under the License. 409 */function So(n,e){return ve(n.name,e.name)}function Rn(n,e){return ve(n,e)}/** 410 * @license 411 * Copyright 2017 Google LLC 412 * 413 * Licensed under the Apache License, Version 2.0 (the "License"); 414 * you may not use this file except in compliance with the License. 415 * You may obtain a copy of the License at 416 * 417 * http://www.apache.org/licenses/LICENSE-2.0 418 * 419 * Unless required by applicable law or agreed to in writing, software 420 * distributed under the License is distributed on an "AS IS" BASIS, 421 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 422 * See the License for the specific language governing permissions and 423 * limitations under the License. 424 */let sn;function No(n){sn=n}const ps=function(n){return typeof n=="number"?"number:"+Ki(n):"string:"+n},ms=function(n){if(n.isLeafNode()){const e=n.val();f(typeof e=="string"||typeof e=="number"||typeof e=="object"&&Y(e,".sv"),"Priority must be a string or number.")}else f(n===sn||n.isEmpty(),"priority of unexpected type.");f(n===sn||n.getPriority().isEmpty(),"Priority nodes can't have a priority of their own.")};/** 425 * @license 426 * Copyright 2017 Google LLC 427 * 428 * Licensed under the Apache License, Version 2.0 (the "License"); 429 * you may not use this file except in compliance with the License. 430 * You may obtain a copy of the License at 431 * 432 * http://www.apache.org/licenses/LICENSE-2.0 433 * 434 * Unless required by applicable law or agreed to in writing, software 435 * distributed under the License is distributed on an "AS IS" BASIS, 436 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 437 * See the License for the specific language governing permissions and 438 * limitations under the License. 439 */let Ci;class k{static set __childrenNodeConstructor(e){Ci=e}static get __childrenNodeConstructor(){return Ci}constructor(e,t=k.__childrenNodeConstructor.EMPTY_NODE){this.value_=e,this.priorityNode_=t,this.lazyHash_=null,f(this.value_!==void 0&&this.value_!==null,"LeafNode shouldn't be created with null/undefined value."),ms(this.priorityNode_)}isLeafNode(){return!0}getPriority(){return this.priorityNode_}updatePriority(e){return new k(this.value_,e)}getImmediateChild(e){return e===".priority"?this.priorityNode_:k.__childrenNodeConstructor.EMPTY_NODE}getChild(e){return y(e)?this:g(e)===".priority"?this.priorityNode_:k.__childrenNodeConstructor.EMPTY_NODE}hasChild(){return!1}getPredecessorChildName(e,t){return null}updateImmediateChild(e,t){return e===".priority"?this.updatePriority(t):t.isEmpty()&&e!==".priority"?this:k.__childrenNodeConstructor.EMPTY_NODE.updateImmediateChild(e,t).updatePriority(this.priorityNode_)}updateChild(e,t){const i=g(e);return i===null?t:t.isEmpty()&&i!==".priority"?this:(f(i!==".priority"||oe(e)===1,".priority must be the last token in a path"),this.updateImmediateChild(i,k.__childrenNodeConstructor.EMPTY_NODE.updateChild(T(e),t)))}isEmpty(){return!1}numChildren(){return 0}forEachChild(e,t){return!1}
439val(e){return e&&!this.getPriority().isEmpty()?{".value":this.getValue(),".priority":this.getPriority().val()}:this.getValue()}hash(){if(this.lazyHash_===null){let e="";this.priorityNode_.isEmpty()||(e+="priority:"+ps(this.priorityNode_.val())+":");const t=typeof this.value_;e+=t+":",t==="number"?e+=Ki(this.value_):e+=this.value_,this.lazyHash_=Qi(e)}return this.lazyHash_}getValue(){return this.value_}compareTo(e){return e===k.__childrenNodeConstructor.EMPTY_NODE?1:e instanceof k.__childrenNodeConstructor?-1:(f(e.isLeafNode(),"Unknown node type"),this.compareToLeafNode_(e))}compareToLeafNode_(e){const t=typeof e.value_,i=typeof this.value_,s=k.VALUE_TYPE_ORDER.indexOf(t),r=k.VALUE_TYPE_ORDER.indexOf(i);return f(s>=0,"Unknown leaf type: "+t),f(r>=0,"Unknown leaf type: "+i),s===r?i==="object"?0:this.value_<e.value_?-1:this.value_===e.value_?0:1:r-s}withIndex(){return this}isIndexed(){return!0}equals(e){if(e===this)return!0;if(e.isLeafNode()){const t=e;return this.value_===t.value_&&this.priorityNode_.equals(t.priorityNode_)}else return!1}}k.VALUE_TYPE_ORDER=["object","boolean","number","string"];/** 440 * @license 441 * Copyright 2017 Google LLC 442 * 443 * Licensed under the Apache License, Version 2.0 (the "License"); 444 * you may not use this file except in compliance with the License. 445 * You may obtain a copy of the License at 446 * 447 * http://www.apache.org/licenses/LICENSE-2.0 448 * 449 * Unless required by applicable law or agreed to in writing, software 450 * distributed under the License is distributed on an "AS IS" BASIS, 451 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 452 * See the License for the specific language governing permissions and 453 * limitations under the License. 454 */let gs,ys;function Ro(n){gs=n}function bo(n){ys=n}class ko extends Rt{compare(e,t){const i=e.node.getPriority(),s=t.node.getPriority(),r=i.compareTo(s);return r===0?ve(e.name,t.name):r}isDefinedOn(e){return!e.getPriority().isEmpty()}indexedValueChanged(e,t){return!e.getPriority().equals(t.getPriority())}minPost(){return v.MIN}maxPost(){return new v(ee,new k("[PRIORITY-POST]",ys))}makePost(e,t){const i=gs(e);return new v(t,new k("[PRIORITY-POST]",i))}toString(){return".priority"}}const S=new ko;/** 455 * @license 456 * Copyright 2017 Google LLC 457 * 458 * Licensed under the Apache License, Version 2.0 (the "License"); 459 * you may not use this file except in compliance with the License. 460 * You may obtain a copy of the License at 461 * 462 * http://www.apache.org/licenses/LICENSE-2.0 463 * 464 * Unless required by applicable law or agreed to in writing, software 465 * distributed under the License is distributed on an "AS IS" BASIS, 466 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 467 * See the License for the specific language governing permissions and 468 * limitations under the License. 469 */const Po=Math.log(2);class Ao{constructor(e){const t=r=>parseInt(Math.log(r)/Po,10),i=r=>parseInt(Array(r+1).join("1"),2);this.count=t(e+1),this.current_=this.count-1;const s=i(this.count);this.bits_=e+1&s}nextBitIsOne(){const e=!(this.bits_&1<<this.current_);return this.current_--,e}}const _t=function(n,e,t,i){n.sort(e);const s=function(a,c){const h=c-a;let u,d;if(h===0)return null;if(h===1)return u=n[a],d=t?t(u):u,new P(d,u.node,P.BLACK,null,null);{const _=parseInt(h/2,10)+a,p=s(a,_),w=s(_+1,c);return u=n[_],d=t?t(u):u,new P(d,u.node,P.BLACK,p,w)}},r=function(a){let c=null,h=null,u=n.length;const d=function(p,w){const D=u-p,we=u;u-=p;const at=s(D+1,we),Qt=n[D],or=t?t(Qt):Qt;_(new P(or,Qt.node,w,null,at))},_=function(p){c?(c.left=p,c=p):(h=p,c=p)};for(let p=0;p<a.count;++p){const w=a.nextBitIsOne(),D=Math.pow(2,a.count-(p+1));w?d(D,P.BLACK):(d(D,P.BLACK),d(D,P.RED))}return h},o=new Ao(n.length),l=r(o);return new L(i||e,l)};/** 470 * @license 471 * Copyright 2017 Google LLC 472 * 473 * Licensed under the Apache License, Version 2.0 (the "License"); 474 * you may not use this file except in compliance with the License. 475 * You may obtain a copy of the License at 476 * 477 * http://www.apache.org/licenses/LICENSE-2.0 478 * 479 * Unless required by applicable law or agreed to in writing, softw
479are 480 * distributed under the License is distributed on an "AS IS" BASIS, 481 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 482 * See the License for the specific language governing permissions and 483 * limitations under the License. 484 */let zt;const Te={};class Z{static get Default(){return f(Te&&S,"ChildrenNode.ts has not been loaded"),zt=zt||new Z({".priority":Te},{".priority":S}),zt}constructor(e,t){this.indexes_=e,this.indexSet_=t}get(e){const t=pe(this.indexes_,e);if(!t)throw new Error("No index defined for "+e);return t instanceof L?t:null}hasIndex(e){return Y(this.indexSet_,e.toString())}addIndex(e,t){f(e!==$,"KeyIndex always exists and isn't meant to be added to the IndexMap.");const i=[];let s=!1;const r=t.getIterator(v.Wrap);let o=r.getNext();for(;o;)s=s||e.isDefinedOn(o.node),i.push(o),o=r.getNext();let l;s?l=_t(i,e.getCompare()):l=Te;const a=e.toString(),c={...this.indexSet_};c[a]=e;const h={...this.indexes_};return h[a]=l,new Z(h,c)}addToIndexes(e,t){const i=ut(this.indexes_,(s,r)=>{const o=pe(this.indexSet_,r);if(f(o,"Missing index implementation for "+r),s===Te)if(o.isDefinedOn(e.node)){const l=[],a=t.getIterator(v.Wrap);let c=a.getNext();for(;c;)c.name!==e.name&&l.push(c),c=a.getNext();return l.push(e),_t(l,o.getCompare())}else return Te;else{const l=t.get(e.name);let a=s;return l&&(a=a.remove(new v(e.name,l))),a.insert(e,e.node)}});return new Z(i,this.indexSet_)}removeFromIndexes(e,t){const i=ut(this.indexes_,s=>{if(s===Te)return s;{const r=t.get(e.name);return r?s.remove(new v(e.name,r)):s}});return new Z(i,this.indexSet_)}}/** 485 * @license 486 * Copyright 2017 Google LLC 487 * 488 * Licensed under the Apache License, Version 2.0 (the "License"); 489 * you may not use this file except in compliance with the License. 490 * You may obtain a copy of the License at 491 * 492 * http://www.apache.org/licenses/LICENSE-2.0 493 * 494 * Unless required by applicable law or agreed to in writing, software 495 * distributed under the License is distributed on an "AS IS" BASIS, 496 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 497 * See the License for the specific language governing permissions and 498 * limitations under the License. 499 */let We;class m{static get EMPTY_NODE(){return We||(We=new m(new L(Rn),null,Z.Default))}constructor(e,t,i){this.children_=e,this.priorityNode_=t,this.indexMap_=i,this.lazyHash_=null,this.priorityNode_&&ms(this.priorityNode_),this.children_.isEmpty()&&f(!this.priorityNode_||this.priorityNode_.isEmpty(),"An empty node cannot have a priority")}isLeafNode(){return!1}getPriority(){return this.priorityNode_||We}updatePriority(e){return this.children_.isEmpty()?this:new m(this.children_,e,this.indexMap_)}getImmediateChild(e){if(e===".priority")return this.getPriority();{const t=this.children_.get(e);return t===null?We:t}}getChild(e){const t=g(e);return t===null?this:this.getImmediateChild(t).getChild(T(e))}hasChild(e){return this.children_.get(e)!==null}updateImmediateChild(e,t){if(f(t,"We should always be passing snapshot nodes"),e===".priority")return this.updatePriority(t);{const i=new v(e,t);let s,r;t.isEmpty()?(s=this.children_.remove(e),r=this.indexMap_.removeFromIndexes(i,this.children_)):(s=this.children_.insert(e,t),r=this.indexMap_.addToIndexes(i,this.children_));const o=s.isEmpty()?We:this.priorityNode_;return new m(s,o,r)}}updateChild(e,t){const i=g(e);if(i===null)return t;{f(g(e)!==".priority"||oe(e)===1,".priority must be the last token in a path");const s=this.getImmediateChild(i).updateChild(T(e),t);return this.updateImmediateChild(i,s)}}isEmpty(){return this.children_.isEmpty()}numChildren(){return this.children_.count()}val(e){if(this.isEmpty())return null;const t={};let i=0,s=0,r=!0;if(this.forEachChild(S,(o,l)=>{t[o]=l.val(e),i++,r&&m.INTEGER_REGEXP_.test(o)?s=Math.max(s,Number(o)):r=!1}),!e&&r&&s<2*i){const o=[];for(const l in t)o[l]=t[l];return o}else return e&&!this.getPriority().isEmpty()&&(t[".priority"]=this.getPriority().val()),t}hash(){if(this.lazyHash_===null){let e="";this.getPriority().isEmpty()||(e+="priority:"+ps(this.getPriority().val())+":"),this.forEachChild(S,(t,i)=>{const s=i.hash();s!==""&&(e+=":"+t+":"+s)}),this.lazyHash_=e===""?"":Qi(e)}return this.lazyHash_}getPredecessorChildName(e,t,i){const s=this.resolveIndex_(i);if(s){const r=s.getPredecessorKey(new v(e,t));return r?r.name:null}else return this.children_.getPredecessorKey(e)}getFirstChildName(e){const t=this.resolveIndex_(e);if(t){const i=t.minKey();return i&&i.name}else return this.children_.minKey()}getFirstChild(e){const t=this.getFirstChildName(e);return t?new v(t,this.children_.get(t)):null}getLastChildName(e){const t=this.resolveIndex_(e);if(t){const i=t.maxKey();return i&&i.name}else return this.children_.maxKey()}getLastChild(e){const t=this.getLastChildName(e);return t?new v(t,this.children_.get(t)):null}forEachChild(e,t){const i=this.resolveIndex_(e);return i?i.inorderTraversal(s=>t(s.name,s.node)):this.children_.inorderTraversal(t)}getIterator(e){return this.getIteratorFrom(e.minPost(),e)}getIteratorFrom(e,t){const i=this.resolveIndex_(t);if(i)return i.getIteratorFrom(e,s=>s);{const s=this.children_.getIteratorFrom(e.name,v.Wrap);let r=s.peek();for(;r!=null&&t.compare(r,e)<0;)s.getNext(),r=s.peek();return s}}getReverseIterator(e){return this.getReverseIteratorFrom(e.maxPost(),e)}getReverseIteratorFrom(e,t){const i=this.resolveIndex_(t);if(i)return i.getReverseIteratorFrom(e,s=>s);{const s=this.children_.getReverseIteratorFrom(e.name,v.Wrap);let r=s.peek();for(;r!=null&&t.compare(r,e)>0;)s.getNext(),r=s.peek();return s}}compareTo(e){return this.isEmpty()?e.isEmpty()?0:-1:e.isLeafNode()||e.isEmpty()?1:e===et?-1:0}withIndex(e){if(e===$||this.indexMap_.hasIndex(e))return this;{const t=this.indexMap_.addIndex(e,this.children_);return new m(this.children_,this.priorityNode_,t)}}isIndexed(e){return e===$||this.indexMap_.hasIndex(e)}equals(e){if(e===this)return!0;
499if(e.isLeafNode())return!1;{const t=e;if(this.getPriority().equals(t.getPriority()))if(this.children_.count()===t.children_.count()){const i=this.getIterator(S),s=t.getIterator(S);let r=i.getNext(),o=s.getNext();for(;r&&o;){if(r.name!==o.name||!r.node.equals(o.node))return!1;r=i.getNext(),o=s.getNext()}return r===null&&o===null}else return!1;else return!1}}resolveIndex_(e){return e===$?null:this.indexMap_.get(e.toString())}}m.INTEGER_REGEXP_=/^(0|[1-9]\d*)$/;class xo extends m{constructor(){super(new L(Rn),m.EMPTY_NODE,Z.Default)}compareTo(e){return e===this?0:1}equals(e){return e===this}getPriority(){return this}getImmediateChild(e){return m.EMPTY_NODE}isEmpty(){return!1}}const et=new xo;Object.defineProperties(v,{MIN:{value:new v(re,m.EMPTY_NODE)},MAX:{value:new v(ee,et)}});_s.__EMPTY_NODE=m.EMPTY_NODE;k.__childrenNodeConstructor=m;No(et);bo(et);/** 500 * @license 501 * Copyright 2017 Google LLC 502 * 503 * Licensed under the Apache License, Version 2.0 (the "License"); 504 * you may not use this file except in compliance with the License. 505 * You may obtain a copy of the License at 506 * 507 * http://www.apache.org/licenses/LICENSE-2.0 508 * 509 * Unless required by applicable law or agreed to in writing, software 510 * distributed under the License is distributed on an "AS IS" BASIS, 511 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 512 * See the License for the specific language governing permissions and 513 * limitations under the License. 514 */const Do=!0;function R(n,e=null){if(n===null)return m.EMPTY_NODE;if(typeof n=="object"&&".priority"in n&&(e=n[".priority"]),f(e===null||typeof e=="string"||typeof e=="number"||typeof e=="object"&&".sv"in e,"Invalid priority type found: "+typeof e),typeof n=="object"&&".value"in n&&n[".value"]!==null&&(n=n[".value"]),typeof n!="object"||".sv"in n){const t=n;return new k(t,R(e))}if(!(n instanceof Array)&&Do){const t=[];let i=!1;if(x(n,(o,l)=>{if(o.substring(0,1)!=="."){const a=R(l);a.isEmpty()||(i=i||!a.getPriority().isEmpty(),t.push(new v(o,a)))}}),t.length===0)return m.EMPTY_NODE;const r=_t(t,So,o=>o.name,Rn);if(i){const o=_t(t,S.getCompare());return new m(r,R(e),new Z({".priority":o},{".priority":S}))}else return new m(r,R(e),Z.Default)}else{let t=m.EMPTY_NODE;return x(n,(i,s)=>{if(Y(n,i)&&i.substring(0,1)!=="."){const r=R(s);(r.isLeafNode()||!r.isEmpty())&&(t=t.updateImmediateChild(i,r))}}),t.updatePriority(R(e))}}Ro(R);/** 515 * @license 516 * Copyright 2017 Google LLC 517 * 518 * Licensed under the Apache License, Version 2.0 (the "License"); 519 * you may not use this file except in compliance with the License. 520 * You may obtain a copy of the License at 521 * 522 * http://www.apache.org/licenses/LICENSE-2.0 523 * 524 * Unless required by applicable law or agreed to in writing, software 525 * distributed under the License is distributed on an "AS IS" BASIS, 526 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 527 * See the License for the specific language governing permissions and 528 * limitations under the License. 529 */class bn extends Rt{constructor(e){super(),this.indexPath_=e,f(!y(e)&&g(e)!==".priority","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){const i=this.extractChild(e.node),s=this.extractChild(t.node),r=i.compareTo(s);return r===0?ve(e.name,t.name):r}makePost(e,t){const i=R(e),s=m.EMPTY_NODE.updateChild(this.indexPath_,i);return new v(t,s)}maxPost(){const e=m.EMPTY_NODE.updateChild(this.indexPath_,et);return new v(ee,e)}toString(){return Qe(this.indexPath_,0).join("/")}}/** 530 * @license 531 * Copyright 2017 Google LLC 532 * 533 * Licensed under the Apache License, Version 2.0 (the "License"); 534 * you may not use this file except in compliance with the License. 535 * You may obtain a copy of the License at 536 * 537 * http://www.apache.org/licenses/LICENSE-2.0 538 * 539 * Unless required by applicable law or agreed to in writing, software 540 * distributed under the License is distributed on an "AS IS" BASIS, 541 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 542 * See the License for the specific language governing permissions and 543 * limitations under the License. 544 */class Oo extends Rt{compare(e,t){const i=e.node.compareTo(t.node);return i===0?ve(e.name,t.name):i}isDefinedOn(e){return!0}indexedValueChanged(e,t){return!e.equals(t)}
544minPost(){return v.MIN}maxPost(){return v.MAX}makePost(e,t){const i=R(e);return new v(t,i)}toString(){return".value"}}const kn=new Oo;/** 545 * @license 546 * Copyright 2017 Google LLC 547 * 548 * Licensed under the Apache License, Version 2.0 (the "License"); 549 * you may not use this file except in compliance with the License. 550 * You may obtain a copy of the License at 551 * 552 * http://www.apache.org/licenses/LICENSE-2.0 553 * 554 * Unless required by applicable law or agreed to in writing, software 555 * distributed under the License is distributed on an "AS IS" BASIS, 556 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 557 * See the License for the specific language governing permissions and 558 * limitations under the License. 559 */function vs(n){return{type:"value",snapshotNode:n}}function Re(n,e){return{type:"child_added",snapshotNode:e,childName:n}}function qe(n,e){return{type:"child_removed",snapshotNode:e,childName:n}}function Ye(n,e,t){return{type:"child_changed",snapshotNode:e,childName:n,oldSnap:t}}function Mo(n,e){return{type:"child_moved",snapshotNode:e,childName:n}}/** 560 * @license 561 * Copyright 2017 Google LLC 562 * 563 * Licensed under the Apache License, Version 2.0 (the "License"); 564 * you may not use this file except in compliance with the License. 565 * You may obtain a copy of the License at 566 * 567 * http://www.apache.org/licenses/LICENSE-2.0 568 * 569 * Unless required by applicable law or agreed to in writing, software 570 * distributed under the License is distributed on an "AS IS" BASIS, 571 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 572 * See the License for the specific language governing permissions and 573 * limitations under the License. 574 */class Pn{constructor(e){this.index_=e}updateChild(e,t,i,s,r,o){f(e.isIndexed(this.index_),"A node must be indexed if only a child is updated");const l=e.getImmediateChild(t);return l.getChild(s).equals(i.getChild(s))&&l.isEmpty()===i.isEmpty()||(o!=null&&(i.isEmpty()?e.hasChild(t)?o.trackChildChange(qe(t,l)):f(e.isLeafNode(),"A child remove without an old child only makes sense on a leaf node"):l.isEmpty()?o.trackChildChange(Re(t,i)):o.trackChildChange(Ye(t,i,l))),e.isLeafNode()&&i.isEmpty())?e:e.updateImmediateChild(t,i).withIndex(this.index_)}updateFullNode(e,t,i){return i!=null&&(e.isLeafNode()||e.forEachChild(S,(s,r)=>{t.hasChild(s)||i.trackChildChange(qe(s,r))}),t.isLeafNode()||t.forEachChild(S,(s,r)=>{if(e.hasChild(s)){const o=e.getImmediateChild(s);o.equals(r)||i.trackChildChange(Ye(s,r,o))}else i.trackChildChange(Re(s,r))})),t.withIndex(this.index_)}updatePriority(e,t){return e.isEmpty()?m.EMPTY_NODE:e.updatePriority(t)}filtersNodes(){return!1}getIndexedFilter(){return this}getIndex(){return this.index_}}/** 575 * @license 576 * Copyright 2017 Google LLC 577 * 578 * Licensed under the Apache License, Version 2.0 (the "License"); 579 * you may not use this file except in compliance with the License. 580 * You may obtain a copy of the License at 581 * 582 * http://www.apache.org/licenses/LICENSE-2.0 583 * 584 * Unless required by applicable law or agreed to in writing, software 585 * distributed under the License is distributed on an "AS IS" BASIS, 586 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 587 * See the License for the specific language governing permissions and 588 * limitations under the License. 589 */class Ke{constructor(e){this.indexedFilter_=new Pn(e.getIndex()),this.index_=e.getIndex(),this.startPost_=Ke.getStartPost_(e),this.endPost_=Ke.getEndPost_(e),this.startIsInclusive_=!e.startAfterSet_,this.endIsInclusive_=!e.endBeforeSet_}getStartPost(){return this.startPost_}getEndPost(){return this.endPost_}matches(e){const t=this.startIsInclusive_?this.index_.compare(this.getStartPost(),e)<=0:this.index_.compare(this.getStartPost(),e)<0,i=this.endIsInclusive_?this.index_.compare(e,this.getEndPost())<=0:this.index_.compare(e,this.getEndPost())<0;return t&&i}updateChild(e,t,i,s,r,o){return this.matches(new v(t,i))||(i=m.EMPTY_NODE),this.indexedFilter_.updateChild(e,t,i,s,r,o)}updateFullNode(e,t,i){t.isLeafNode()&&(t=m.EMPTY_NODE);let s=t.withIndex(this.index_);s=s.updatePriority(m.EMPTY_NODE);const r=this;return t.forEachChild(S,(o,l)=>{r.matches(new v(o,l))||(s=s.updateImmediateChild(o,m.EMPTY_NODE))}),this.indexedFilter_.updateFullNode(e,s,i)}updatePriority(e,t){return e}filtersNodes(){return!0}getIndexedFilter(){return this.indexedFilter_}getIndex(){return this.index_}static getStartPost_(e){if(e.hasStart()){const t=e.getIndexStartName();return e.getIndex().makePost(e.getIndexStartValue(),t)}else return e.getIndex().minPost()}static getEndPost_(e){if(e.hasEnd()){const t=e.getIndexEndName();return e.getIndex().makePost(e.getIndexEndValue(),t)}else return e.getIndex().maxPost()}}/** 590 * @license 591 * Copyright 2017 Google LLC 592 * 593 * Licensed under the Apache License, Version 2.0 (the "License");
594 * you may not use this file except in compliance with the License. 595 * You may obtain a copy of the License at 596 * 597 * http://www.apache.org/licenses/LICENSE-2.0 598 * 599 * Unless required by applicable law or agreed to in writing, software 600 * distributed under the License is distributed on an "AS IS" BASIS, 601 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 602 * See the License for the specific language governing permissions and 603 * limitations under the License. 604 */class Lo{constructor(e){this.withinDirectionalStart=t=>this.reverse_?this.withinEndPost(t):this.withinStartPost(t),this.withinDirectionalEnd=t=>this.reverse_?this.withinStartPost(t):this.withinEndPost(t),this.withinStartPost=t=>{const i=this.index_.compare(this.rangedFilter_.getStartPost(),t);return this.startIsInclusive_?i<=0:i<0},this.withinEndPost=t=>{const i=this.index_.compare(t,this.rangedFilter_.getEndPost());return this.endIsInclusive_?i<=0:i<0},this.rangedFilter_=new Ke(e),this.index_=e.getIndex(),this.limit_=e.getLimit(),this.reverse_=!e.isViewFromLeft(),this.startIsInclusive_=!e.startAfterSet_,this.endIsInclusive_=!e.endBeforeSet_}updateChild(e,t,i,s,r,o){return this.rangedFilter_.matches(new v(t,i))||(i=m.EMPTY_NODE),e.getImmediateChild(t).equals(i)?e:e.numChildren()<this.limit_?this.rangedFilter_.getIndexedFilter().updateChild(e,t,i,s,r,o):this.fullLimitUpdateChild_(e,t,i,r,o)}updateFullNode(e,t,i){let s;if(t.isLeafNode()||t.isEmpty())s=m.EMPTY_NODE.withIndex(this.index_);else if(this.limit_*2<t.numChildren()&&t.isIndexed(this.index_)){s=m.EMPTY_NODE.withIndex(this.index_);let r;this.reverse_?r=t.getReverseIteratorFrom(this.rangedFilter_.getEndPost(),this.index_):r=t.getIteratorFrom(this.rangedFilter_.getStartPost(),this.index_);let o=0;for(;r.hasNext()&&o<this.limit_;){const l=r.getNext();if(this.withinDirectionalStart(l))if(this.withinDirectionalEnd(l))s=s.updateImmediateChild(l.name,l.node),o++;else break;else continue}}else{s=t.withIndex(this.index_),s=s.updatePriority(m.EMPTY_NODE);let r;this.reverse_?r=s.getReverseIterator(this.index_):r=s.getIterator(this.index_);let o=0;for(;r.hasNext();){const l=r.getNext();o<this.limit_&&this.withinDirectionalStart(l)&&this.withinDirectionalEnd(l)?o++:s=s.updateImmediateChild(l.name,m.EMPTY_NODE)}}return this.rangedFilter_.getIndexedFilter().updateFullNode(e,s,i)}updatePriority(e,t){return e}filtersNodes(){return!0}getIndexedFilter(){return this.rangedFilter_.getIndexedFilter()}getIndex(){return this.index_}fullLimitUpdateChild_(e,t,i,s,r){let o;if(this.reverse_){const u=this.index_.getCompare();o=(d,_)=>u(_,d)}else o=this.index_.getCompare();const l=e;f(l.numChildren()===this.limit_,"");const a=new v(t,i),c=this.reverse_?l.getFirstChild(this.index_):l.getLastChild(this.index_),h=this.rangedFilter_.matches(a);if(l.hasChild(t)){const u=l.getImmediateChild(t);let d=s.getChildAfterChild(this.index_,c,this.reverse_);for(;d!=null&&(d.name===t||l.hasChild(d.name));)d=s.getChildAfterChild(this.index_,d,this.reverse_);const _=d==null?1:o(d,a);if(h&&!i.isEmpty()&&_>=0)return r?.trackChildChange(Ye(t,i,u)),l.updateImmediateChild(t,i);{r?.trackChildChange(qe(t,u));const w=l.updateImmediateChild(t,m.EMPTY_NODE);return d!=null&&this.rangedFilter_.matches(d)?(r?.trackChildChange(Re(d.name,d.node)),w.updateImmediateChild(d.name,d.node)):w}}else return i.isEmpty()?e:h&&o(c,a)>=0?(r!=null&&(r.trackChildChange(qe(c.name,c.node)),r.trackChildChange(Re(t,i))),l.updateImmediateChild(t,i).updateImmediateChild(c.name,m.EMPTY_NODE)):e}}/** 605 * @license 606 * Copyright 2017 Google LLC 607 * 608 * Licensed under the Apache License, Version 2.0 (the "License"); 609 * you may not use this file except in compliance with the License. 610 * You may obtain a copy of the License at 611 * 612 * http://www.apache.org/licenses/LICENSE-2.0 613 * 614 * Unless required by applicable law or agreed to in writing, software 615 * distributed under the License is distributed on an "AS IS" BASIS, 616 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 617 * See the License for the specific language governing permissions and 618 * limitations under the License. 619 */class An{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_=S}hasStart(){return this.startSet_}isViewFromLeft(){return this.viewFrom_===""?this.startSet_:this.viewFrom_==="l"}getIndexStartValue(){return f(this.startSet_,"Only valid if start has been set"),this.indexStartValue_}getIndexStartName(){return f(this.startSet_,"Only valid if start has been set"),this.startNameSet_?this.indexStartName_:re}hasEnd(){return this.endSet_}getIndexEndValue(){return f(this.endSet_,"Only valid if end has been set"),this.indexEndValue_}getIndexEndName(){return f(this.endSet_,"Only valid if end has been set"),this.endNameSet_?this.indexEndName_:ee}hasLimit(){return this.limitSet_}hasAnchoredLimit(){return this.limitSet_&&this.viewFrom_!==""}getLimit(){return f(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_===S}copy(){const e=new An;return e.limitSet_=this.limitSet_,e.limit_=this.limit_,e.startSet_=this.startSet_,e.startAfterSet_=this.startAfterSet_,e.indexStartValue_=this.indexStartValue_,e.startNameSet_=this.startNameSet_,e.indexStartName_=this.indexStartName_,e.endSet_=this.endSet_,e.endBeforeSet_=this.endBeforeSet_,e.indexEndValue_=this.indexEndValue_,e.endNameSet_=this.endNameSet_,e.indexEndName_=this.indexEndName_,e.index_=this.index_,e.viewFrom_=this.viewFrom_,e}}function Fo(n){return n.loadsAllData()?new Pn(n.getIndex()):n.hasLimit()?new Lo(n):new Ke(n)}function Wo(n,e){const t=n.copy();return t.limitSet_=!0,t.limit_=e,t.viewFrom_="l",t}function Uo(n,e){const t=n.copy();return t.limitSet_=!0,t.limit_=e,t.viewFrom_="r",t}function rn(n,e,t){const i=n.copy();return i.startSet_=!0,e===void 0&&(e=null),i.indexStartValue_=e,t!=null?(i.startNameSet_=!0,i.indexStartName_=t):(i.startNameSet_=!1,i.indexStartName_=""),i}function Bo(n,e,t){let i;return n.index_===$||t?i=rn(n,e,t):i=rn(n,e,ee),i.startAfterSet_=!0,i}function on(n,e,t){const i=n.copy();return i.endSet_=!0,e===void 0&&(e=null),i.indexEndValue_=e,t!==void 0?(i.endNameSet_=!0,i.indexEndName_=t):(i.endNameSet_=!1,i.indexEndName_=""),i}function Vo(n,e,t){let i;return n.index_===$||t?i=on(n,e,t):i=on(n,e,re),i.endBeforeSet_=!0,i}function bt(n,e){const t=n.copy();
619return t.index_=e,t}function Ei(n){const e={};if(n.isDefault())return e;let t;if(n.index_===S?t="$priority":n.index_===kn?t="$value":n.index_===$?t="$key":(f(n.index_ instanceof bn,"Unrecognized index type!"),t=n.index_.toString()),e.orderBy=b(t),n.startSet_){const i=n.startAfterSet_?"startAfter":"startAt";e[i]=b(n.indexStartValue_),n.startNameSet_&&(e[i]+=","+b(n.indexStartName_))}if(n.endSet_){const i=n.endBeforeSet_?"endBefore":"endAt";e[i]=b(n.indexEndValue_),n.endNameSet_&&(e[i]+=","+b(n.indexEndName_))}return n.limitSet_&&(n.isViewFromLeft()?e.limitToFirst=n.limit_:e.limitToLast=n.limit_),e}function wi(n){const e={};if(n.startSet_&&(e.sp=n.indexStartValue_,n.startNameSet_&&(e.sn=n.indexStartName_),e.sin=!n.startAfterSet_),n.endSet_&&(e.ep=n.indexEndValue_,n.endNameSet_&&(e.en=n.indexEndName_),e.ein=!n.endBeforeSet_),n.limitSet_){e.l=n.limit_;let t=n.viewFrom_;t===""&&(n.isViewFromLeft()?t="l":t="r"),e.vf=t}return n.index_!==S&&(e.i=n.index_.toString()),e}/** 620 * @license 621 * Copyright 2017 Google LLC 622 * 623 * Licensed under the Apache License, Version 2.0 (the "License"); 624 * you may not use this file except in compliance with the License. 625 * You may obtain a copy of the License at 626 * 627 * http://www.apache.org/licenses/LICENSE-2.0 628 * 629 * Unless required by applicable law or agreed to in writing, software 630 * distributed under the License is distributed on an "AS IS" BASIS, 631 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 632 * See the License for the specific language governing permissions and 633 * limitations under the License. 634 */class pt extends hs{reportStats(e){throw new Error("Method not implemented.")}static getListenId_(e,t){return t!==void 0?"tag$"+t:(f(e._queryParams.isDefault(),"should have a tag if it's not a default query."),e._path.toString())}constructor(e,t,i,s){super(),this.repoInfo_=e,this.onDataUpdate_=t,this.authTokenProvider_=i,this.appCheckTokenProvider_=s,this.log_=Ze("p:rest:"),this.listens_={}}listen(e,t,i,s){const r=e._path.toString();this.log_("Listen called for "+r+" "+e._queryIdentifier);const o=pt.getListenId_(e,i),l={};this.listens_[o]=l;const a=Ei(e._queryParams);this.restRequest_(r+".json",a,(c,h)=>{let u=h;if(c===404&&(u=null,c=null),c===null&&this.onDataUpdate_(r,u,!1,i),pe(this.listens_,o)===l){let d;c?c===401?d="permission_denied":d="rest_error:"+c:d="ok",s(d,null)}})}unlisten(e,t){const i=pt.getListenId_(e,t);delete this.listens_[i]}get(e){const t=Ei(e._queryParams),i=e._path.toString(),s=new B;return this.restRequest_(i+".json",t,(r,o)=>{let l=o;r===404&&(l=null,r=null),r===null?(this.onDataUpdate_(i,l,!1,null),s.resolve(l)):s.reject(new Error(l))}),s.promise}refreshAuthToken(e){}restRequest_(e,t={},i){return t.format="export",Promise.all([this.authTokenProvider_.getToken(!1),this.appCheckTokenProvider_.getToken(!1)]).then(([s,r])=>{s&&s.accessToken&&(t.auth=s.accessToken),r&&r.token&&(t.ac=r.token);const o=(this.repoInfo_.secure?"https://":"http://")+this.repoInfo_.host+e+"?ns="+this.repoInfo_.namespace+gr(t);this.log_("Sending REST request for "+o);const l=new XMLHttpRequest;l.onreadystatechange=()=>{if(i&&l.readyState===4){this.log_("REST Response for "+o+" received. status:",l.status,"response:",l.responseText);let a=null;if(l.status>=200&&l.status<300){try{a=vn(l.responseText)}catch{O("Failed to parse JSON response for "+o+": "+l.responseText)}i(null,a)}else l.status!==401&&l.status!==404&&O("Got unsuccessful REST response for "+o+" Status: "+l.status),i(l.status);i=null}},l.open("GET",o,!0),l.send()})}}/** 635 * @license 636 * Copyright 2017 Google LLC 637 * 638 * Licensed under the Apache License, Version 2.0 (the "License"); 639 * you may not use this file except in compliance with the License. 640 * You may obtain a copy of the License at 641 * 642 * http://www.apache.org/licenses/LICENSE-2.0 643 * 644 * Unless required by applicable law or agreed to in writing, software 645 * distributed under the License is distributed on an "AS IS" BASIS, 646 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 647 * See the License for the specific language governing permissions and 648 * limitations under the License. 649 */class Go{constructor(){this.rootNode_=m.EMPTY_NODE}getNode(e){return this.rootNode_.getChild(e)}updateSnapshot(e,t){this.rootNode_=this.rootNode_.updateChild(e,t)}}/** 650 * @license 651 * Copyright 2017 Google LLC 652 * 653 * Licensed under the Apache License, Version 2.0 (the "License");
654 * you may not use this file except in compliance with the License. 655 * You may obtain a copy of the License at 656 * 657 * http://www.apache.org/licenses/LICENSE-2.0 658 * 659 * Unless required by applicable law or agreed to in writing, software 660 * distributed under the License is distributed on an "AS IS" BASIS, 661 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 662 * See the License for the specific language governing permissions and 663 * limitations under the License. 664 */function mt(){return{value:null,children:new Map}}function De(n,e,t){if(y(e))n.value=t,n.children.clear();else if(n.value!==null)n.value=n.value.updateChild(e,t);else{const i=g(e);n.children.has(i)||n.children.set(i,mt());const s=n.children.get(i);e=T(e),De(s,e,t)}}function ln(n,e){if(y(e))return n.value=null,n.children.clear(),!0;if(n.value!==null){if(n.value.isLeafNode())return!1;{const t=n.value;return n.value=null,t.forEachChild(S,(i,s)=>{De(n,new E(i),s)}),ln(n,e)}}else if(n.children.size>0){const t=g(e);return e=T(e),n.children.has(t)&&ln(n.children.get(t),e)&&n.children.delete(t),n.children.size===0}else return!0}function an(n,e,t){n.value!==null?t(e,n.value):Ho(n,(i,s)=>{const r=new E(e.toString()+"/"+i);an(s,r,t)})}function Ho(n,e){n.children.forEach((t,i)=>{e(i,t)})}/** 665 * @license 666 * Copyright 2017 Google LLC 667 * 668 * Licensed under the Apache License, Version 2.0 (the "License"); 669 * you may not use this file except in compliance with the License. 670 * You may obtain a copy of the License at 671 * 672 * http://www.apache.org/licenses/LICENSE-2.0 673 * 674 * Unless required by applicable law or agreed to in writing, software 675 * distributed under the License is distributed on an "AS IS" BASIS, 676 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 677 * See the License for the specific language governing permissions and 678 * limitations under the License. 679 */class Qo{constructor(e){this.collection_=e,this.last_=null}get(){const e=this.collection_.get(),t={...e};return this.last_&&x(this.last_,(i,s)=>{t[i]=t[i]-s}),this.last_=e,t}}/** 680 * @license 681 * Copyright 2017 Google LLC 682 * 683 * Licensed under the Apache License, Version 2.0 (the "License"); 684 * you may not use this file except in compliance with the License. 685 * You may obtain a copy of the License at 686 * 687 * http://www.apache.org/licenses/LICENSE-2.0 688 * 689 * Unless required by applicable law or agreed to in writing, software 690 * distributed under the License is distributed on an "AS IS" BASIS, 691 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 692 * See the License for the specific language governing permissions and 693 * limitations under the License. 694 */const Ti=10*1e3,qo=30*1e3,Yo=300*1e3;class Ko{constructor(e,t){this.server_=t,this.statsToReport_={},this.statsListener_=new Qo(e);const i=Ti+(qo-Ti)*Math.random();Be(this.reportStats_.bind(this),Math.floor(i))}reportStats_(){const e=this.statsListener_.get(),t={};let i=!1;x(e,(s,r)=>{r>0&&Y(this.statsToReport_,s)&&(t[s]=r,i=!0)}),i&&this.server_.reportStats(t),Be(this.reportStats_.bind(this),Math.floor(Math.random()*2*Yo))}}/** 695 * @license 696 * Copyright 2017 Google LLC 697 * 698 * Licensed under the Apache License, Version 2.0 (the "License"); 699 * you may not use this file except in compliance with the License. 700 * You may obtain a copy of the License at 701 * 702 * http://www.apache.org/licenses/LICENSE-2.0 703 * 704 * Unless required by applicable law or agreed to in writing, software 705 * distributed under the License is distributed on an "AS IS" BASIS, 706 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 707 * See the License for the specific language governing permissions and 708 * limitations under the License. 709 */var Q;(function(n){n[n.OVERWRITE=0]="OVERWRITE",n[n.MERGE=1]="MERGE",n[n.ACK_USER_WRITE=2]="ACK_USER_WRITE",n[n.LISTEN_COMPLETE=3]="LISTEN_COMPLETE"})(Q||(Q={}));function xn(){return{fromUser:!0,fromServer:!1,queryId:null,tagged:!1}}function Dn(){return{fromUser:!1,fromServer:!0,queryId:null,tagged:!1}}function On(n){return{fromUser:!1,fromServer:!0,queryId:n,tagged:!0}}/** 710 * @license 711 * Copyright 2017 Google LLC 712 * 713 * Licensed under the Apache License, Version 2.0 (the "License");
714 * you may not use this file except in compliance with the License. 715 * You may obtain a copy of the License at 716 * 717 * http://www.apache.org/licenses/LICENSE-2.0 718 * 719 * Unless required by applicable law or agreed to in writing, software 720 * distributed under the License is distributed on an "AS IS" BASIS, 721 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 722 * See the License for the specific language governing permissions and 723 * limitations under the License. 724 */class gt{constructor(e,t,i){this.path=e,this.affectedTree=t,this.revert=i,this.type=Q.ACK_USER_WRITE,this.source=xn()}operationForChild(e){if(y(this.path)){if(this.affectedTree.value!=null)return f(this.affectedTree.children.isEmpty(),"affectedTree should not have overlapping affected paths."),this;{const t=this.affectedTree.subtree(new E(e));return new gt(C(),t,this.revert)}}else return f(g(this.path)===e,"operationForChild called for unrelated child."),new gt(T(this.path),this.affectedTree,this.revert)}}/** 725 * @license 726 * Copyright 2017 Google LLC 727 * 728 * Licensed under the Apache License, Version 2.0 (the "License"); 729 * you may not use this file except in compliance with the License. 730 * You may obtain a copy of the License at 731 * 732 * http://www.apache.org/licenses/LICENSE-2.0 733 * 734 * Unless required by applicable law or agreed to in writing, software 735 * distributed under the License is distributed on an "AS IS" BASIS, 736 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 737 * See the License for the specific language governing permissions and 738 * limitations under the License. 739 */class ze{constructor(e,t){this.source=e,this.path=t,this.type=Q.LISTEN_COMPLETE}operationForChild(e){return y(this.path)?new ze(this.source,C()):new ze(this.source,T(this.path))}}/** 740 * @license 741 * Copyright 2017 Google LLC 742 * 743 * Licensed under the Apache License, Version 2.0 (the "License"); 744 * you may not use this file except in compliance with the License. 745 * You may obtain a copy of the License at 746 * 747 * http://www.apache.org/licenses/LICENSE-2.0 748 * 749 * Unless required by applicable law or agreed to in writing, software 750 * distributed under the License is distributed on an "AS IS" BASIS, 751 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 752 * See the License for the specific language governing permissions and 753 * limitations under the License. 754 */class me{constructor(e,t,i){this.source=e,this.path=t,this.snap=i,this.type=Q.OVERWRITE}operationForChild(e){return y(this.path)?new me(this.source,C(),this.snap.getImmediateChild(e)):new me(this.source,T(this.path),this.snap)}}/** 755 * @license 756 * Copyright 2017 Google LLC 757 * 758 * Licensed under the Apache License, Version 2.0 (the "License"); 759 * you may not use this file except in compliance with the License. 760 * You may obtain a copy of the License at 761 * 762 * http://www.apache.org/licenses/LICENSE-2.0 763 * 764 * Unless required by applicable law or agreed to in writing, software 765 * distributed under the License is distributed on an "AS IS" BASIS, 766 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 767 * See the License for the specific language governing permissions and 768 * limitations under the License. 769 */class be{constructor(e,t,i){this.source=e,this.path=t,this.children=i,this.type=Q.MERGE}operationForChild(e){if(y(this.path)){const t=this.children.subtree(new E(e));return t.isEmpty()?null:t.value?new me(this.source,C(),t.value):new be(this.source,C(),t)}else return f(g(this.path)===e,"Can't get a merge for a child not on the path of the operation"),new be(this.source,T(this.path),this.children)}toString(){return"Operation("+this.path+": "+this.source.toString()+" merge: "+this.children.toString()+")"}}/** 770 * @license 771 * Copyright 2017 Google LLC 772 * 773 * Licensed under the Apache License, Version 2.0 (the "License"); 774 * you may not use this file except in compliance with the License. 775 * You may obtain a copy of the License at 776 * 777 * http://www.apache.org/licenses/LICENSE-2.0 778 * 779 * Unless required by applicable law or agreed to in writing, software 780 * distributed under the License is distributed on an "AS IS" BASIS, 781 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 782 * See the License for the specific language governing permissions and 783 * limitations under the License. 784 */class le{constructor(e,t,i){this.node_=e,this.fullyInitialized_=t,this.filtered_=i}isFullyInitialized(){return this.fullyInitialized_}isFiltered(){return this.filtered_}isCompleteForPath(e){if(y(e))return this.isFullyInitialized()&&!this.filtered_;const t=g(e);return this.isCompleteForChild(t)}isCompleteForChild(e){return this.isFullyInitialized()&&!this.filtered_||this.node_.hasChild(e)}getNode(){return this.node_}}/** 785 * @license 786 * Copyright 2017 Google LLC 787 * 788 * Licensed under the Apache License, Version 2.0 (the "License");
789 * you may not use this file except in compliance with the License. 790 * You may obtain a copy of the License at 791 * 792 * http://www.apache.org/licenses/LICENSE-2.0 793 * 794 * Unless required by applicable law or agreed to in writing, software 795 * distributed under the License is distributed on an "AS IS" BASIS, 796 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 797 * See the License for the specific language governing permissions and 798 * limitations under the License. 799 */class zo{constructor(e){this.query_=e,this.index_=this.query_._queryParams.getIndex()}}function jo(n,e,t,i){const s=[],r=[];return e.forEach(o=>{o.type==="child_changed"&&n.index_.indexedValueChanged(o.oldSnap,o.snapshotNode)&&r.push(Mo(o.childName,o.snapshotNode))}),Ue(n,s,"child_removed",e,i,t),Ue(n,s,"child_added",e,i,t),Ue(n,s,"child_moved",r,i,t),Ue(n,s,"child_changed",e,i,t),Ue(n,s,"value",e,i,t),s}function Ue(n,e,t,i,s,r){const o=i.filter(l=>l.type===t);o.sort((l,a)=>Xo(n,l,a)),o.forEach(l=>{const a=$o(n,l,r);s.forEach(c=>{c.respondsTo(l.type)&&e.push(c.createEvent(a,n.query_))})})}function $o(n,e,t){return e.type==="value"||e.type==="child_removed"||(e.prevName=t.getPredecessorChildName(e.childName,e.snapshotNode,n.index_)),e}function Xo(n,e,t){if(e.childName==null||t.childName==null)throw Xe("Should only compare child_ events.");const i=new v(e.childName,e.snapshotNode),s=new v(t.childName,t.snapshotNode);return n.index_.compare(i,s)}/** 800 * @license 801 * Copyright 2017 Google LLC 802 * 803 * Licensed under the Apache License, Version 2.0 (the "License"); 804 * you may not use this file except in compliance with the License. 805 * You may obtain a copy of the License at 806 * 807 * http://www.apache.org/licenses/LICENSE-2.0 808 * 809 * Unless required by applicable law or agreed to in writing, software 810 * distributed under the License is distributed on an "AS IS" BASIS, 811 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 812 * See the License for the specific language governing permissions and 813 * limitations under the License. 814 */function kt(n,e){return{eventCache:n,serverCache:e}}function Ve(n,e,t,i){return kt(new le(e,t,i),n.serverCache)}function Cs(n,e,t,i){return kt(n.eventCache,new le(e,t,i))}function yt(n){return n.eventCache.isFullyInitialized()?n.eventCache.getNode():null}function ge(n){return n.serverCache.isFullyInitialized()?n.serverCache.getNode():null}/** 815 * @license 816 * Copyright 2017 Google LLC 817 * 818 * Licensed under the Apache License, Version 2.0 (the "License"); 819 * you may not use this file except in compliance with the License. 820 * You may obtain a copy of the License at 821 * 822 * http://www.apache.org/licenses/LICENSE-2.0 823 * 824 * Unless required by applicable law or agreed to in writing, software 825 * distributed under the License is distributed on an "AS IS" BASIS, 826 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 827 * See the License for the specific language governing permissions and 828 * limitations under the License. 829 */let jt;const Jo=()=>(jt||(jt=new L(Dr)),jt);class I{static fromObject(e){let t=new I(null);return x(e,(i,s)=>{t=t.set(new E(i),s)}),t}constructor(e,t=Jo()){this.value=e,this.children=t}isEmpty(){return this.value===null&&this.children.isEmpty()}findRootMostMatchingPathAndValue(e,t){if(this.value!=null&&t(this.value))return{path:C(),value:this.value};if(y(e))return null;{const i=g(e),s=this.children.get(i);if(s!==null){const r=s.findRootMostMatchingPathAndValue(T(e),t);return r!=null?{path:N(new E(i),r.path),value:r.value}:null}else return null}}findRootMostValueAndPath(e){return this.findRootMostMatchingPathAndValue(e,()=>!0)}subtree(e){if(y(e))return this;{const t=g(e),i=this.children.get(t);return i!==null?i.subtree(T(e)):new I(null)}}set(e,t){if(y(e))return new I(t,this.children);{const i=g(e),r=(this.children.get(i)||new I(null)).set(T(e),t),o=this.children.insert(i,r);return new I(this.value,o)}}remove(e){if(y(e))return this.children.isEmpty()?new I(null):new I(null,this.children);{const t=g(e),i=this.children.get(t);if(i){const s=i.remove(T(e));let r;return s.isEmpty()?r=this.children.remove(t):r=this.children.insert(t,s),this.value===null&&r.isEmpty()?new I(null):new I(this.value,r)}else return this}}get(e){if(y(e))return this.value;{const t=g(e),i=this.children.get(t);return i?i.get(T(e)):null}}setTree(e,t){if(y(e))return t;{const i=g(e),r=(this.children.get(i)||new I(null)).setTree(T(e),t);let o;return r.isEmpty()?o=this.children.remove(i):o=this.children.insert(i,r),new I(this.value,o)}}fold(e){return this.fold_(C(),e)}fold_(e,t){const i={};return this.children.inorderTraversal((s,r)=>{i[s]=r.fold_(N(e,s),t)}),t(e,this.value,i)}findOnPath(e,t){return this.findOnPath_(e,C(),t)}findOnPath_(e,t,i){const s=this.value?i(t,this.value):!1;if(s)return s;if(y(e))return null;{const r=g(e),o=this.children.get(r);return o?o.findOnPath_(T(e),N(t,r),i):null}}foreachOnPath(e,t){return this.foreachOnPath_(e,C(),t)}foreachOnPath_(e,t,i){if(y(e))return this;{this.value&&i(t,this.value);const s=g(e),r=this.children.get(s);return r?r.foreachOnPath_(T(e),N(t,s),i):new I(null)}}foreach(e){this.foreach_(C(),e)}foreach_(e,t){this.children.inorderTraversal((i,s)=>{s.foreach_(N(e,i),t)}),this.value&&t(e,this.value)}foreachChild(e){this.children.inorderTraversal((t,i)=>{i.value&&e(t,i.value)})}}/** 830 * @license 831 * Copyright 2017 Google LLC 832 * 833 * Licensed under the Apache License, Version 2.0 (the "License");
834 * you may not use this file except in compliance with the License. 835 * You may obtain a copy of the License at 836 * 837 * http://www.apache.org/licenses/LICENSE-2.0 838 * 839 * Unless required by applicable law or agreed to in writing, software 840 * distributed under the License is distributed on an "AS IS" BASIS, 841 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 842 * See the License for the specific language governing permissions and 843 * limitations under the License. 844 */class q{constructor(e){this.writeTree_=e}static empty(){return new q(new I(null))}}function Ge(n,e,t){if(y(e))return new q(new I(t));{const i=n.writeTree_.findRootMostValueAndPath(e);if(i!=null){const s=i.path;let r=i.value;const o=M(s,e);return r=r.updateChild(o,t),new q(n.writeTree_.set(s,r))}else{const s=new I(t),r=n.writeTree_.setTree(e,s);return new q(r)}}}function cn(n,e,t){let i=n;return x(t,(s,r)=>{i=Ge(i,N(e,s),r)}),i}function Ii(n,e){if(y(e))return q.empty();{const t=n.writeTree_.setTree(e,new I(null));return new q(t)}}function hn(n,e){return Ce(n,e)!=null}function Ce(n,e){const t=n.writeTree_.findRootMostValueAndPath(e);return t!=null?n.writeTree_.get(t.path).getChild(M(t.path,e)):null}function Si(n){const e=[],t=n.writeTree_.value;return t!=null?t.isLeafNode()||t.forEachChild(S,(i,s)=>{e.push(new v(i,s))}):n.writeTree_.children.inorderTraversal((i,s)=>{s.value!=null&&e.push(new v(i,s.value))}),e}function ie(n,e){if(y(e))return n;{const t=Ce(n,e);return t!=null?new q(new I(t)):new q(n.writeTree_.subtree(e))}}function un(n){return n.writeTree_.isEmpty()}function ke(n,e){return Es(C(),n.writeTree_,e)}function Es(n,e,t){if(e.value!=null)return t.updateChild(n,e.value);{let i=null;return e.children.inorderTraversal((s,r)=>{s===".priority"?(f(r.value!==null,"Priority writes must always be leaf nodes"),i=r.value):t=Es(N(n,s),r,t)}),!t.getChild(n).isEmpty()&&i!==null&&(t=t.updateChild(N(n,".priority"),i)),t}}/** 845 * @license 846 * Copyright 2017 Google LLC 847 * 848 * Licensed under the Apache License, Version 2.0 (the "License"); 849 * you may not use this file except in compliance with the License. 850 * You may obtain a copy of the License at 851 * 852 * http://www.apache.org/licenses/LICENSE-2.0 853 * 854 * Unless required by applicable law or agreed to in writing, software 855 * distributed under the License is distributed on an "AS IS" BASIS, 856 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 857 * See the License for the specific language governing permissions and 858 * limitations under the License. 859 */function Pt(n,e){return Ss(e,n)}function Zo(n,e,t,i,s){f(i>n.lastWriteId,"Stacking an older write on top of newer ones"),s===void 0&&(s=!0),n.allWrites.push({path:e,snap:t,writeId:i,visible:s}),s&&(n.visibleWrites=Ge(n.visibleWrites,e,t)),n.lastWriteId=i}function el(n,e,t,i){f(i>n.lastWriteId,"Stacking an older merge on top of newer ones"),n.allWrites.push({path:e,children:t,writeId:i,visible:!0}),n.visibleWrites=cn(n.visibleWrites,e,t),n.lastWriteId=i}function tl(n,e){for(let t=0;t<n.allWrites.length;t++){const i=n.allWrites[t];if(i.writeId===e)return i}return null}function nl(n,e){const t=n.allWrites.findIndex(l=>l.writeId===e);f(t>=0,"removeWrite called with nonexistent writeId.");const i=n.allWrites[t];n.allWrites.splice(t,1);let s=i.visible,r=!1,o=n.allWrites.length-1;for(;s&&o>=0;){const l=n.allWrites[o];l.visible&&(o>=t&&il(l,i.path)?s=!1:G(i.path,l.path)&&(r=!0)),o--}if(s){if(r)return sl(n),!0;if(i.snap)n.visibleWrites=Ii(n.visibleWrites,i.path);else{const l=i.children;x(l,a=>{n.visibleWrites=Ii(n.visibleWrites,N(i.path,a))})}return!0}else return!1}function il(n,e){if(n.snap)return G(n.path,e);for(const t in n.children)if(n.children.hasOwnProperty(t)&&G(N(n.path,t),e))return!0;return!1}function sl(n){n.visibleWrites=ws(n.allWrites,rl,C()),n.allWrites.length>0?n.lastWriteId=n.allWrites[n.allWrites.length-1].writeId:n.lastWriteId=-1}function rl(n){return n.visible}function ws(n,e,t){let i=q.empty();for(let s=0;s<n.length;++s){const r=n[s];if(e(r)){const o=r.path;let l;if(r.snap)G(t,o)?(l=M(t,o),i=Ge(i,l,r.snap)):G(o,t)&&(l=M(o,t),i=Ge(i,C(),r.snap.getChild(l)));else if(r.children){if(G(t,o))l=M(t,o),i=cn(i,l,r.children);else if(G(o,t))if(l=M(o,t),y(l))i=cn(i,C(),r.children);else{const a=pe(r.children,g(l));if(a){const c=a.getChild(T(l));i=Ge(i,C(),c)}}}else throw Xe("WriteRecord should have .snap or .children")}}return i}function Ts(n,e,t,i,s){if(!i&&!s){const r=Ce(n.visibleWrites,e);if(r!=null)return r;{const o=ie(n.visibleWrites,e);if(un(o))return t;if(t==null&&!hn(o,C()))return null;{const l=t||m.EMPTY_NODE;return ke(o,l)}}}else{const r=ie(n.visibleWrites,e);if(!s&&un(r))return t;if(!s&&t==null&&!hn(r,C()))return null;{const o=function(c){return(c.visible||s)&&(!i||!~i.indexOf(c.writeId))&&(G(c.path,e)||G(e,c.path))},l=ws(n.allWrites,o,e),a=t||m.EMPTY_NODE;return ke(l,a)}}}function ol(n,e,t){let i=m.EMPTY_NODE;const s=Ce(n.visibleWrites,e);
859if(s)return s.isLeafNode()||s.forEachChild(S,(r,o)=>{i=i.updateImmediateChild(r,o)}),i;if(t){const r=ie(n.visibleWrites,e);return t.forEachChild(S,(o,l)=>{const a=ke(ie(r,new E(o)),l);i=i.updateImmediateChild(o,a)}),Si(r).forEach(o=>{i=i.updateImmediateChild(o.name,o.node)}),i}else{const r=ie(n.visibleWrites,e);return Si(r).forEach(o=>{i=i.updateImmediateChild(o.name,o.node)}),i}}function ll(n,e,t,i,s){f(i||s,"Either existingEventSnap or existingServerSnap must exist");const r=N(e,t);if(hn(n.visibleWrites,r))return null;{const o=ie(n.visibleWrites,r);return un(o)?s.getChild(t):ke(o,s.getChild(t))}}function al(n,e,t,i){const s=N(e,t),r=Ce(n.visibleWrites,s);if(r!=null)return r;if(i.isCompleteForChild(t)){const o=ie(n.visibleWrites,s);return ke(o,i.getNode().getImmediateChild(t))}else return null}function cl(n,e){return Ce(n.visibleWrites,e)}function hl(n,e,t,i,s,r,o){let l;const a=ie(n.visibleWrites,e),c=Ce(a,C());if(c!=null)l=c;else if(t!=null)l=ke(a,t);else return[];if(l=l.withIndex(o),!l.isEmpty()&&!l.isLeafNode()){const h=[],u=o.getCompare(),d=r?l.getReverseIteratorFrom(i,o):l.getIteratorFrom(i,o);let _=d.getNext();for(;_&&h.length<s;)u(_,i)!==0&&h.push(_),_=d.getNext();return h}else return[]}function ul(){return{visibleWrites:q.empty(),allWrites:[],lastWriteId:-1}}function vt(n,e,t,i){return Ts(n.writeTree,n.treePath,e,t,i)}function Mn(n,e){return ol(n.writeTree,n.treePath,e)}function Ni(n,e,t,i){return ll(n.writeTree,n.treePath,e,t,i)}function Ct(n,e){return cl(n.writeTree,N(n.treePath,e))}function dl(n,e,t,i,s,r){return hl(n.writeTree,n.treePath,e,t,i,s,r)}function Ln(n,e,t){return al(n.writeTree,n.treePath,e,t)}function Is(n,e){return Ss(N(n.treePath,e),n.writeTree)}function Ss(n,e){return{treePath:n,writeTree:e}}/** 860 * @license 861 * Copyright 2017 Google LLC 862 * 863 * Licensed under the Apache License, Version 2.0 (the "License"); 864 * you may not use this file except in compliance with the License. 865 * You may obtain a copy of the License at 866 * 867 * http://www.apache.org/licenses/LICENSE-2.0 868 * 869 * Unless required by applicable law or agreed to in writing, software 870 * distributed under the License is distributed on an "AS IS" BASIS, 871 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 872 * See the License for the specific language governing permissions and 873 * limitations under the License. 874 */class fl{constructor(){this.changeMap=new Map}trackChildChange(e){const t=e.type,i=e.childName;f(t==="child_added"||t==="child_changed"||t==="child_removed","Only child changes supported for tracking"),f(i!==".priority","Only non-priority child changes can be tracked.");const s=this.changeMap.get(i);if(s){const r=s.type;if(t==="child_added"&&r==="child_removed")this.changeMap.set(i,Ye(i,e.snapshotNode,s.snapshotNode));else if(t==="child_removed"&&r==="child_added")this.changeMap.delete(i);else if(t==="child_removed"&&r==="child_changed")this.changeMap.set(i,qe(i,s.oldSnap));else if(t==="child_changed"&&r==="child_added")this.changeMap.set(i,Re(i,e.snapshotNode));else if(t==="child_changed"&&r==="child_changed")this.changeMap.set(i,Ye(i,e.snapshotNode,s.oldSnap));else throw Xe("Illegal combination of changes: "+e+" occurred after "+s)}else this.changeMap.set(i,e)}getChanges(){return Array.from(this.changeMap.values())}}/** 875 * @license 876 * Copyright 2017 Google LLC 877 * 878 * Licensed under the Apache License, Version 2.0 (the "License"); 879 * you may not use this file except in compliance with the License. 880 * You may obtain a copy of the License at 881 * 882 * http://www.apache.org/licenses/LICENSE-2.0 883 * 884 * Unless required by applicable law or agreed to in writing, software 885 * distributed under the License is distributed on an "AS IS" BASIS, 886 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 887 * See the License for the specific language governing permissions and 888 * limitations under the License. 889 */class _l{getCompleteChild(e){return null}getChildAfterChild(e,t,i){return null}}const Ns=new _l;class Fn{constructor(e,t,i=null){this.writes_=e,this.viewCache_=t,this.optCompleteServerCache_=i}getCompleteChild(e){const t=this.viewCache_.eventCache;if(t.isCompleteForChild(e))return t.getNode().getImmediateChild(e);{const i=this.optCompleteServerCache_!=null?new le(this.optCompleteServerCache_,!0,!1):this.viewCache_.serverCache;return Ln(this.writes_,e,i)}}getChildAfterChild(e,t,i){const s=this.optCompleteServerCache_!=null?this.optCompleteServerCache_:ge(this.viewCache_),r=dl(this.writes_,s,t,1,i,e);return r.length===0?null:r[0]}}/** 890 * @license 891 * Copyright 2017 Google LLC 892 * 893 * Licensed under the Apache License, Version 2.0 (the "License");
894 * you may not use this file except in compliance with the License. 895 * You may obtain a copy of the License at 896 * 897 * http://www.apache.org/licenses/LICENSE-2.0 898 * 899 * Unless required by applicable law or agreed to in writing, software 900 * distributed under the License is distributed on an "AS IS" BASIS, 901 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 902 * See the License for the specific language governing permissions and 903 * limitations under the License. 904 */function pl(n){return{filter:n}}function ml(n,e){f(e.eventCache.getNode().isIndexed(n.filter.getIndex()),"Event snap not indexed"),f(e.serverCache.getNode().isIndexed(n.filter.getIndex()),"Server snap not indexed")}function gl(n,e,t,i,s){const r=new fl;let o,l;if(t.type===Q.OVERWRITE){const c=t;c.source.fromUser?o=dn(n,e,c.path,c.snap,i,s,r):(f(c.source.fromServer,"Unknown source."),l=c.source.tagged||e.serverCache.isFiltered()&&!y(c.path),o=Et(n,e,c.path,c.snap,i,s,l,r))}else if(t.type===Q.MERGE){const c=t;c.source.fromUser?o=vl(n,e,c.path,c.children,i,s,r):(f(c.source.fromServer,"Unknown source."),l=c.source.tagged||e.serverCache.isFiltered(),o=fn(n,e,c.path,c.children,i,s,l,r))}else if(t.type===Q.ACK_USER_WRITE){const c=t;c.revert?o=wl(n,e,c.path,i,s,r):o=Cl(n,e,c.path,c.affectedTree,i,s,r)}else if(t.type===Q.LISTEN_COMPLETE)o=El(n,e,t.path,i,r);else throw Xe("Unknown operation type: "+t.type);const a=r.getChanges();return yl(e,o,a),{viewCache:o,changes:a}}function yl(n,e,t){const i=e.eventCache;if(i.isFullyInitialized()){const s=i.getNode().isLeafNode()||i.getNode().isEmpty(),r=yt(n);(t.length>0||!n.eventCache.isFullyInitialized()||s&&!i.getNode().equals(r)||!i.getNode().getPriority().equals(r.getPriority()))&&t.push(vs(yt(e)))}}function Rs(n,e,t,i,s,r){const o=e.eventCache;if(Ct(i,t)!=null)return e;{let l,a;if(y(t))if(f(e.serverCache.isFullyInitialized(),"If change path is empty, we must have complete server data"),e.serverCache.isFiltered()){const c=ge(e),h=c instanceof m?c:m.EMPTY_NODE,u=Mn(i,h);l=n.filter.updateFullNode(e.eventCache.getNode(),u,r)}else{const c=vt(i,ge(e));l=n.filter.updateFullNode(e.eventCache.getNode(),c,r)}else{const c=g(t);if(c===".priority"){f(oe(t)===1,"Can't have a priority with additional path components");const h=o.getNode();a=e.serverCache.getNode();const u=Ni(i,t,h,a);u!=null?l=n.filter.updatePriority(h,u):l=o.getNode()}else{const h=T(t);let u;if(o.isCompleteForChild(c)){a=e.serverCache.getNode();const d=Ni(i,t,o.getNode(),a);d!=null?u=o.getNode().getImmediateChild(c).updateChild(h,d):u=o.getNode().getImmediateChild(c)}else u=Ln(i,c,e.serverCache);u!=null?l=n.filter.updateChild(o.getNode(),c,u,h,s,r):l=o.getNode()}}return Ve(e,l,o.isFullyInitialized()||y(t),n.filter.filtersNodes())}}function Et(n,e,t,i,s,r,o,l){const a=e.serverCache;let c;const h=o?n.filter:n.filter.getIndexedFilter();if(y(t))c=h.updateFullNode(a.getNode(),i,null);else if(h.filtersNodes()&&!a.isFiltered()){const _=a.getNode().updateChild(t,i);c=h.updateFullNode(a.getNode(),_,null)}else{const _=g(t);if(!a.isCompleteForPath(t)&&oe(t)>1)return e;const p=T(t),D=a.getNode().getImmediateChild(_).updateChild(p,i);_===".priority"?c=h.updatePriority(a.getNode(),D):c=h.updateChild(a.getNode(),_,D,p,Ns,null)}const u=Cs(e,c,a.isFullyInitialized()||y(t),h.filtersNodes()),d=new Fn(s,u,r);return Rs(n,u,t,s,d,l)}function dn(n,e,t,i,s,r,o){const l=e.eventCache;let a,c;const h=new Fn(s,e,r);if(y(t))c=n.filter.updateFullNode(e.eventCache.getNode(),i,o),a=Ve(e,c,!0,n.filter.filtersNodes());else{const u=g(t);if(u===".priority")c=n.filter.updatePriority(e.eventCache.getNode(),i),a=Ve(e,c,l.isFullyInitialized(),l.isFiltered());else{const d=T(t),_=l.getNode().getImmediateChild(u);let p;if(y(d))p=i;else{const w=h.getCompleteChild(u);w!=null?In(d)===".priority"&&w.getChild(ds(d)).isEmpty()?p=w:p=w.updateChild(d,i):p=m.EMPTY_NODE}if(_.equals(p))a=e;else{const w=n.filter.updateChild(l.getNode(),u,p,d,h,o);a=Ve(e,w,l.isFullyInitialized(),n.filter.filtersNodes())}}}return a}function Ri(n,e){return n.eventCache.isCompleteForChild(e)}function vl(n,e,t,i,s,r,o){let l=e;return i.foreach((a,c)=>{const h=N(t,a);Ri(e,g(h))&&(l=dn(n,l,h,c,s,r,o))}),i.foreach((a,c)=>{const h=N(t,a);Ri(e,g(h))||(l=dn(n,l,h,c,s,r,o))}),l}function bi(n,e,t){return t.foreach((i,s)=>{e=e.updateChild(i,s)}),e}function fn(n,e,t,i,s,r,o,l){if(e.serverCache.getNode().isEmpty()&&!e.serverCache.isFullyInitialized())return e;let a=e,c;y(t)?c=i:c=new I(null).setTree(t,i);const h=e.serverCache.getNode();return c.children.inorderTraversal((u,d)=>{if(h.hasChild(u)){const _=e.serverCache.getNode().getImmediateChild(u),p=bi(n,_,d);a=Et(n,a,new E(u),p,s,r,o,l)}}),c.children.inorderTraversal((u,d)=>{const _=!e.serverCache.isCompleteForChild(u)&&d.value===null;if(!h.hasChild(u)&&!_){const p=e.serverCache.getNode().getImmediateChild(u),w=bi(n,p,d);a=Et(n,a,new E(u),w,s,r,o,l)}}),a}function Cl(n,e,t,i,s,r,o){if(Ct(s,t)!=null)return e;const l=e.serverCache.isFiltered(),a=e.serverCache;if(i.value!=null){if(y(t)&&a.isFullyInitialized()||a.isCompleteForPath(t))return Et(n,e,t,a.getNode().getChild(t),s,r,l,o);if(y(t)){let c=new I(null);
904return a.getNode().forEachChild($,(h,u)=>{c=c.set(new E(h),u)}),fn(n,e,t,c,s,r,l,o)}else return e}else{let c=new I(null);return i.foreach((h,u)=>{const d=N(t,h);a.isCompleteForPath(d)&&(c=c.set(h,a.getNode().getChild(d)))}),fn(n,e,t,c,s,r,l,o)}}function El(n,e,t,i,s){const r=e.serverCache,o=Cs(e,r.getNode(),r.isFullyInitialized()||y(t),r.isFiltered());return Rs(n,o,t,i,Ns,s)}function wl(n,e,t,i,s,r){let o;if(Ct(i,t)!=null)return e;{const l=new Fn(i,e,s),a=e.eventCache.getNode();let c;if(y(t)||g(t)===".priority"){let h;if(e.serverCache.isFullyInitialized())h=vt(i,ge(e));else{const u=e.serverCache.getNode();f(u instanceof m,"serverChildren would be complete if leaf node"),h=Mn(i,u)}h=h,c=n.filter.updateFullNode(a,h,r)}else{const h=g(t);let u=Ln(i,h,e.serverCache);u==null&&e.serverCache.isCompleteForChild(h)&&(u=a.getImmediateChild(h)),u!=null?c=n.filter.updateChild(a,h,u,T(t),l,r):e.eventCache.getNode().hasChild(h)?c=n.filter.updateChild(a,h,m.EMPTY_NODE,T(t),l,r):c=a,c.isEmpty()&&e.serverCache.isFullyInitialized()&&(o=vt(i,ge(e)),o.isLeafNode()&&(c=n.filter.updateFullNode(c,o,r)))}return o=e.serverCache.isFullyInitialized()||Ct(i,C())!=null,Ve(e,c,o,n.filter.filtersNodes())}}/** 905 * @license 906 * Copyright 2017 Google LLC 907 * 908 * Licensed under the Apache License, Version 2.0 (the "License"); 909 * you may not use this file except in compliance with the License. 910 * You may obtain a copy of the License at 911 * 912 * http://www.apache.org/licenses/LICENSE-2.0 913 * 914 * Unless required by applicable law or agreed to in writing, software 915 * distributed under the License is distributed on an "AS IS" BASIS, 916 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 917 * See the License for the specific language governing permissions and 918 * limitations under the License. 919 */class Tl{constructor(e,t){this.query_=e,this.eventRegistrations_=[];const i=this.query_._queryParams,s=new Pn(i.getIndex()),r=Fo(i);this.processor_=pl(r);const o=t.serverCache,l=t.eventCache,a=s.updateFullNode(m.EMPTY_NODE,o.getNode(),null),c=r.updateFullNode(m.EMPTY_NODE,l.getNode(),null),h=new le(a,o.isFullyInitialized(),s.filtersNodes()),u=new le(c,l.isFullyInitialized(),r.filtersNodes());this.viewCache_=kt(u,h),this.eventGenerator_=new zo(this.query_)}get query(){return this.query_}}function Il(n){return n.viewCache_.serverCache.getNode()}function Sl(n){return yt(n.viewCache_)}function Nl(n,e){const t=ge(n.viewCache_);return t&&(n.query._queryParams.loadsAllData()||!y(e)&&!t.getImmediateChild(g(e)).isEmpty())?t.getChild(e):null}function ki(n){return n.eventRegistrations_.length===0}function Rl(n,e){n.eventRegistrations_.push(e)}function Pi(n,e,t){const i=[];if(t){f(e==null,"A cancel should cancel all event registrations.");const s=n.query._path;n.eventRegistrations_.forEach(r=>{const o=r.createCancelEvent(t,s);o&&i.push(o)})}if(e){let s=[];for(let r=0;r<n.eventRegistrations_.length;++r){const o=n.eventRegistrations_[r];if(!o.matches(e))s.push(o);else if(e.hasAnyCallback()){s=s.concat(n.eventRegistrations_.slice(r+1));break}}n.eventRegistrations_=s}else n.eventRegistrations_=[];return i}function Ai(n,e,t,i){e.type===Q.MERGE&&e.source.queryId!==null&&(f(ge(n.viewCache_),"We should always have a full cache before handling merges"),f(yt(n.viewCache_),"Missing event cache, even though we have a server cache"));const s=n.viewCache_,r=gl(n.processor_,s,e,t,i);return ml(n.processor_,r.viewCache),f(r.viewCache.serverCache.isFullyInitialized()||!s.serverCache.isFullyInitialized(),"Once a server snap is complete, it should never go back"),n.viewCache_=r.viewCache,bs(n,r.changes,r.viewCache.eventCache.getNode(),null)}function bl(n,e){const t=n.viewCache_.eventCache,i=[];return t.getNode().isLeafNode()||t.getNode().forEachChild(S,(r,o)=>{i.push(Re(r,o))}),t.isFullyInitialized()&&i.push(vs(t.getNode())),bs(n,i,t.getNode(),e)}function bs(n,e,t,i){const s=i?[i]:n.eventRegistrations_;return jo(n.eventGenerator_,e,t,s)}/** 920 * @license 921 * Copyright 2017 Google LLC 922 * 923 * Licensed under the Apache License, Version 2.0 (the "License"); 924 * you may not use this file except in compliance with the License. 925 * You may obtain a copy of the License at 926 * 927 * http://www.apache.org/licenses/LICENSE-2.0 928 * 929 * Unless required by applicable law or agreed to in writing, softw
929are 930 * distributed under the License is distributed on an "AS IS" BASIS, 931 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 932 * See the License for the specific language governing permissions and 933 * limitations under the License. 934 */let wt;class ks{constructor(){this.views=new Map}}function kl(n){f(!wt,"__referenceConstructor has already been defined"),wt=n}function Pl(){return f(wt,"Reference.ts has not been loaded"),wt}function Al(n){return n.views.size===0}function Wn(n,e,t,i){const s=e.source.queryId;if(s!==null){const r=n.views.get(s);return f(r!=null,"SyncTree gave us an op for an invalid query."),Ai(r,e,t,i)}else{let r=[];for(const o of n.views.values())r=r.concat(Ai(o,e,t,i));return r}}function Ps(n,e,t,i,s){const r=e._queryIdentifier,o=n.views.get(r);if(!o){let l=vt(t,s?i:null),a=!1;l?a=!0:i instanceof m?(l=Mn(t,i),a=!1):(l=m.EMPTY_NODE,a=!1);const c=kt(new le(l,a,!1),new le(i,s,!1));return new Tl(e,c)}return o}function xl(n,e,t,i,s,r){const o=Ps(n,e,i,s,r);return n.views.has(e._queryIdentifier)||n.views.set(e._queryIdentifier,o),Rl(o,t),bl(o,t)}function Dl(n,e,t,i){const s=e._queryIdentifier,r=[];let o=[];const l=ae(n);if(s==="default")for(const[a,c]of n.views.entries())o=o.concat(Pi(c,t,i)),ki(c)&&(n.views.delete(a),c.query._queryParams.loadsAllData()||r.push(c.query));else{const a=n.views.get(s);a&&(o=o.concat(Pi(a,t,i)),ki(a)&&(n.views.delete(s),a.query._queryParams.loadsAllData()||r.push(a.query)))}return l&&!ae(n)&&r.push(new(Pl())(e._repo,e._path)),{removed:r,events:o}}function As(n){const e=[];for(const t of n.views.values())t.query._queryParams.loadsAllData()||e.push(t);return e}function se(n,e){let t=null;for(const i of n.views.values())t=t||Nl(i,e);return t}function xs(n,e){if(e._queryParams.loadsAllData())return At(n);{const i=e._queryIdentifier;return n.views.get(i)}}function Ds(n,e){return xs(n,e)!=null}function ae(n){return At(n)!=null}function At(n){for(const e of n.views.values())if(e.query._queryParams.loadsAllData())return e;return null}/** 935 * @license 936 * Copyright 2017 Google LLC 937 * 938 * Licensed under the Apache License, Version 2.0 (the "License"); 939 * you may not use this file except in compliance with the License. 940 * You may obtain a copy of the License at 941 * 942 * http://www.apache.org/licenses/LICENSE-2.0 943 * 944 * Unless required by applicable law or agreed to in writing, software 945 * distributed under the License is distributed on an "AS IS" BASIS, 946 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 947 * See the License for the specific language governing permissions and 948 * limitations under the License. 949 */let Tt;function Ol(n){f(!Tt,"__referenceConstructor has already been defined"),Tt=n}function Ml(){return f(Tt,"Reference.ts has not been loaded"),Tt}let Ll=1;class xi{constructor(e){this.listenProvider_=e,this.syncPointTree_=new I(null),this.pendingWriteTree_=ul(),this.tagToQueryMap=new Map,this.queryToTagMap=new Map}}function Un(n,e,t,i,s){return Zo(n.pendingWriteTree_,e,t,i,s),s?Oe(n,new me(xn(),e,t)):[]}function Fl(n,e,t,i){el(n.pendingWriteTree_,e,t,i);const s=I.fromObject(t);return Oe(n,new be(xn(),e,s))}function ne(n,e,t=!1){const i=tl(n.pendingWriteTree_,e);if(nl(n.pendingWriteTree_,e)){let r=new I(null);return i.snap!=null?r=r.set(C(),!0):x(i.children,o=>{r=r.set(new E(o),!0)}),Oe(n,new gt(i.path,r,t))}else return[]}function tt(n,e,t){return Oe(n,new me(Dn(),e,t))}function Wl(n,e,t){const i=I.fromObject(t);return Oe(n,new be(Dn(),e,i))}function Ul(n,e){return Oe(n,new ze(Dn(),e))}function Bl(n,e,t){const i=Bn(n,t);if(i){const s=Vn(i),r=s.path,o=s.queryId,l=M(r,e),a=new ze(On(o),l);return Gn(n,r,a)}else return[]}function It(n,e,t,i,s=!1){const r=e._path,o=n.syncPointTree_.get(r);let l=[];if(o&&(e._queryIdentifier==="default"||Ds(o,e))){const a=Dl(o,e,t,i);Al(o)&&(n.syncPointTree_=n.syncPointTree_.remove(r));const c=a.removed;if(l=a.events,!s){const h=c.findIndex(d=>d._queryParams.loadsAllData())!==-1,u=n.syncPointTree_.findOnPath(r,(d,_)=>ae(_));if(h&&!u){const d=n.syncPointTree_.subtree(r);if(!d.isEmpty()){const _=Hl(d);for(let p=0;p<_.length;++p){const w=_[p],D=w.query,we=Fs(n,w);
949n.listenProvider_.startListening(He(D),je(n,D),we.hashFn,we.onComplete)}}}!u&&c.length>0&&!i&&(h?n.listenProvider_.stopListening(He(e),null):c.forEach(d=>{const _=n.queryToTagMap.get(Dt(d));n.listenProvider_.stopListening(He(d),_)}))}Ql(n,c)}return l}function Os(n,e,t,i){const s=Bn(n,i);if(s!=null){const r=Vn(s),o=r.path,l=r.queryId,a=M(o,e),c=new me(On(l),a,t);return Gn(n,o,c)}else return[]}function Vl(n,e,t,i){const s=Bn(n,i);if(s){const r=Vn(s),o=r.path,l=r.queryId,a=M(o,e),c=I.fromObject(t),h=new be(On(l),a,c);return Gn(n,o,h)}else return[]}function _n(n,e,t,i=!1){const s=e._path;let r=null,o=!1;n.syncPointTree_.foreachOnPath(s,(d,_)=>{const p=M(d,s);r=r||se(_,p),o=o||ae(_)});let l=n.syncPointTree_.get(s);l?(o=o||ae(l),r=r||se(l,C())):(l=new ks,n.syncPointTree_=n.syncPointTree_.set(s,l));let a;r!=null?a=!0:(a=!1,r=m.EMPTY_NODE,n.syncPointTree_.subtree(s).foreachChild((_,p)=>{const w=se(p,C());w&&(r=r.updateImmediateChild(_,w))}));const c=Ds(l,e);if(!c&&!e._queryParams.loadsAllData()){const d=Dt(e);f(!n.queryToTagMap.has(d),"View does not exist, but we have a tag");const _=ql();n.queryToTagMap.set(d,_),n.tagToQueryMap.set(_,d)}const h=Pt(n.pendingWriteTree_,s);let u=xl(l,e,t,h,r,a);if(!c&&!o&&!i){const d=xs(l,e);u=u.concat(Yl(n,e,d))}return u}function xt(n,e,t){const s=n.pendingWriteTree_,r=n.syncPointTree_.findOnPath(e,(o,l)=>{const a=M(o,e),c=se(l,a);if(c)return c});return Ts(s,e,r,t,!0)}function Gl(n,e){const t=e._path;let i=null;n.syncPointTree_.foreachOnPath(t,(c,h)=>{const u=M(c,t);i=i||se(h,u)});let s=n.syncPointTree_.get(t);s?i=i||se(s,C()):(s=new ks,n.syncPointTree_=n.syncPointTree_.set(t,s));const r=i!=null,o=r?new le(i,!0,!1):null,l=Pt(n.pendingWriteTree_,e._path),a=Ps(s,e,l,r?o.getNode():m.EMPTY_NODE,r);return Sl(a)}function Oe(n,e){return Ms(e,n.syncPointTree_,null,Pt(n.pendingWriteTree_,C()))}function Ms(n,e,t,i){if(y(n.path))return Ls(n,e,t,i);{const s=e.get(C());t==null&&s!=null&&(t=se(s,C()));let r=[];const o=g(n.path),l=n.operationForChild(o),a=e.children.get(o);if(a&&l){const c=t?t.getImmediateChild(o):null,h=Is(i,o);r=r.concat(Ms(l,a,c,h))}return s&&(r=r.concat(Wn(s,n,i,t))),r}}function Ls(n,e,t,i){const s=e.get(C());t==null&&s!=null&&(t=se(s,C()));let r=[];return e.children.inorderTraversal((o,l)=>{const a=t?t.getImmediateChild(o):null,c=Is(i,o),h=n.operationForChild(o);h&&(r=r.concat(Ls(h,l,a,c)))}),s&&(r=r.concat(Wn(s,n,i,t))),r}function Fs(n,e){const t=e.query,i=je(n,t);return{hashFn:()=>(Il(e)||m.EMPTY_NODE).hash(),onComplete:s=>{if(s==="ok")return i?Bl(n,t._path,i):Ul(n,t._path);{const r=Lr(s,t);return It(n,t,null,r)}}}}function je(n,e){const t=Dt(e);return n.queryToTagMap.get(t)}function Dt(n){return n._path.toString()+"$"+n._queryIdentifier}function Bn(n,e){return n.tagToQueryMap.get(e)}function Vn(n){const e=n.indexOf("$");return f(e!==-1&&e<n.length-1,"Bad queryKey."),{queryId:n.substr(e+1),path:new E(n.substr(0,e))}}function Gn(n,e,t){const i=n.syncPointTree_.get(e);f(i,"Missing sync point for query tag that we're tracking");const s=Pt(n.pendingWriteTree_,e);return Wn(i,t,s,null)}function Hl(n){return n.fold((e,t,i)=>{if(t&&ae(t))return[At(t)];{let s=[];return t&&(s=As(t)),x(i,(r,o)=>{s=s.concat(o)}),s}})}
949function He(n){return n._queryParams.loadsAllData()&&!n._queryParams.isDefault()?new(Ml())(n._repo,n._path):n}function Ql(n,e){for(let t=0;t<e.length;++t){const i=e[t];if(!i._queryParams.loadsAllData()){const s=Dt(i),r=n.queryToTagMap.get(s);n.queryToTagMap.delete(s),n.tagToQueryMap.delete(r)}}}function ql(){return Ll++}function Yl(n,e,t){const i=e._path,s=je(n,e),r=Fs(n,t),o=n.listenProvider_.startListening(He(e),s,r.hashFn,r.onComplete),l=n.syncPointTree_.subtree(i);if(s)f(!ae(l.value),"If we're adding a query, it shouldn't be shadowed");else{const a=l.fold((c,h,u)=>{if(!y(c)&&h&&ae(h))return[At(h).query];{let d=[];return h&&(d=d.concat(As(h).map(_=>_.query))),x(u,(_,p)=>{d=d.concat(p)}),d}});for(let c=0;c<a.length;++c){const h=a[c];n.listenProvider_.stopListening(He(h),je(n,h))}}return o}/** 950 * @license 951 * Copyright 2017 Google LLC 952 * 953 * Licensed under the Apache License, Version 2.0 (the "License"); 954 * you may not use this file except in compliance with the License. 955 * You may obtain a copy of the License at 956 * 957 * http://www.apache.org/licenses/LICENSE-2.0 958 * 959 * Unless required by applicable law or agreed to in writing, software 960 * distributed under the License is distributed on an "AS IS" BASIS, 961 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 962 * See the License for the specific language governing permissions and 963 * limitations under the License. 964 */class Hn{constructor(e){this.node_=e}getImmediateChild(e){const t=this.node_.getImmediateChild(e);return new Hn(t)}node(){return this.node_}}class Qn{constructor(e,t){this.syncTree_=e,this.path_=t}getImmediateChild(e){const t=N(this.path_,e);return new Qn(this.syncTree_,t)}node(){return xt(this.syncTree_,this.path_)}}const Kl=function(n){return n=n||{},n.timestamp=n.timestamp||new Date().getTime(),n},Di=function(n,e,t){if(!n||typeof n!="object")return n;if(f(".sv"in n,"Unexpected leaf node or priority contents"),typeof n[".sv"]=="string")return zl(n[".sv"],e,t);if(typeof n[".sv"]=="object")return jl(n[".sv"],e);f(!1,"Unexpected server value: "+JSON.stringify(n,null,2))},zl=function(n,e,t){switch(n){case"timestamp":return t.timestamp;default:f(!1,"Unexpected server value: "+n)}},jl=function(n,e,t){n.hasOwnProperty("increment")||f(!1,"Unexpected server value: "+JSON.stringify(n,null,2));const i=n.increment;typeof i!="number"&&f(!1,"Unexpected increment value: "+i);const s=e.node();if(f(s!==null&&typeof s<"u","Expected ChildrenNode.EMPTY_NODE for nulls"),!s.isLeafNode())return i;const o=s.getValue();return typeof o!="number"?i:o+i},Ws=function(n,e,t,i){return Yn(e,new Qn(t,n),i)},qn=function(n,e,t){return Yn(n,new Hn(e),t)};function Yn(n,e,t){const i=n.getPriority().val(),s=Di(i,e.getImmediateChild(".priority"),t);let r;if(n.isLeafNode()){const o=n,l=Di(o.getValue(),e,t);return l!==o.getValue()||s!==o.getPriority().val()?new k(l,R(s)):n}else{const o=n;return r=o,s!==o.getPriority().val()&&(r=r.updatePriority(new k(s))),o.forEachChild(S,(l,a)=>{const c=Yn(a,e.getImmediateChild(l),t);c!==a&&(r=r.updateImmediateChild(l,c))}),r}}/** 965 * @license 966 * Copyright 2017 Google LLC 967 * 968 * Licensed under the Apache License, Version 2.0 (the "License"); 969 * you may not use this file except in compliance with the License. 970 * You may obtain a copy of the License at 971 * 972 * http://www.apache.org/licenses/LICENSE-2.0 973 * 974 * Unless required by applicable law or agreed to in writing, software 975 * distributed under the License is distributed on an "AS IS" BASIS, 976 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 977 * See the License for the specific language governing permissions and 978 * limitations under the License. 979 */class Kn{constructor(e="",t=null,i={children:{},childCount:0}){this.name=e,this.parent=t,this.node=i}}function Ot(n,e){let t=e instanceof E?e:new E(e),i=n,s=g(t);for(;s!==null;){const r=pe(i.node.children,s)||{children:{},childCount:0};i=new Kn(s,i,r),t=T(t),s=g(t)}return i}function Ee(n){return n.node.value}function zn(n,e){n.node.value=e,pn(n)}function Us(n){return n.node.childCount>0}function $l(n){return Ee(n)===void 0&&!Us(n)}function Mt(n,e){x(n.node.children,(t,i)=>{e(new Kn(t,n,i))})}function Bs(n,e,t,i){t&&e(n),Mt(n,s=>{Bs(s,e,!0)})}function Xl(n,e,t){let i=n.parent;for(;i!==null;){if(e(i))return!0;
vendor: 4,303 bytes, lines 979-994
979i=i.parent}return!1}function nt(n){return new E(n.parent===null?n.name:nt(n.parent)+"/"+n.name)}function pn(n){n.parent!==null&&Jl(n.parent,n.name,n)}function Jl(n,e,t){const i=$l(t),s=Y(n.node.children,e);i&&s?(delete n.node.children[e],n.node.childCount--,pn(n)):!i&&!s&&(n.node.children[e]=t.node,n.node.childCount++,pn(n))}/** 980 * @license 981 * Copyright 2017 Google LLC 982 * 983 * Licensed under the Apache License, Version 2.0 (the "License"); 984 * you may not use this file except in compliance with the License. 985 * You may obtain a copy of the License at 986 * 987 * http://www.apache.org/licenses/LICENSE-2.0 988 * 989 * Unless required by applicable law or agreed to in writing, software 990 * distributed under the License is distributed on an "AS IS" BASIS, 991 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 992 * See the License for the specific language governing permissions and 993 * limitations under the License. 994 */const Zl=/[\[\].#$\/\u0000-\u001F\u007F]/,ea=/[\[\].#$\u0000-\u001F\u007F]/,$t=10*1024*1024,Lt=function(n){return typeof n=="string"&&n.length!==0&&!Zl.test(n)},Vs=function(n){return typeof n=="string"&&n.length!==0&&!ea.test(n)},ta=function(n){return n&&(n=n.replace(/^\/*\.info(\/|$)/,"/")),Vs(n)},$e=function(n){return n===null||typeof n=="string"||typeof n=="number"&&!Nt(n)||n&&typeof n=="object"&&Y(n,".sv")},J=function(n,e,t,i){i&&e===void 0||it(_e(n,"value"),e,t)},it=function(n,e,t){const i=t instanceof E?new go(t,n):t;if(e===void 0)throw new Error(n+"contains undefined "+ue(i));if(typeof e=="function")throw new Error(n+"contains a function "+ue(i)+" with contents = "+e.toString());if(Nt(e))throw new Error(n+"contains "+e.toString()+" "+ue(i));if(typeof e=="string"&&e.length>$t/3&&St(e)>$t)throw new Error(n+"contains a string greater than "+$t+" utf8 bytes "+ue(i)+" ('"+e.substring(0,50)+"...')");if(e&&typeof e=="object"){let s=!1,r=!1;if(x(e,(o,l)=>{if(o===".value")s=!0;else if(o!==".priority"&&o!==".sv"&&(r=!0,!Lt(o)))throw new Error(n+" contains an invalid key ("+o+") "+ue(i)+`. Keys must be non-empty strings and can't contain ".", "#", "$", "/", "[", or "]"`);yo(i,o),it(n,l,i),vo(i)}),s&&r)throw new Error(n+' contains ".value" child '+ue(i)+" in addition to actual children.")}},na=function(n,e){let t,i;for(t=0;t<e.length;t++){i=e[t];const r=Qe(i);for(let o=0;o<r.length;o++)if(!(r[o]===".priority"&&o===r.length-1)){if(!Lt(r[o]))throw new Error(n+"contains an invalid key ("+r[o]+") in path "+i.toString()+`. Keys must be non-empty strings and can't contain ".", "#", "$", "/", "[", or "]"`)}}e.sort(mo);let s=null;for(t=0;t<e.length;t++){if(i=e[t],s!==null&&G(s,i))throw new Error(n+"contains a path "+s.toString()+" that is ancestor of another path "+i.toString());s=i}},Gs=function(n,e,t,i){const s=_e(n,"values");if(!(e&&typeof e=="object")||Array.isArray(e))throw new Error(s+" must be an object containing the children to replace.");const r=[];x(e,(o,l)=>{const a=new E(o);if(it(s,l,N(t,a)),In(a)===".priority"&&!$e(l))throw new Error(s+"contains an invalid value for '"+a.toString()+"', which must be a valid Firebase priority (a string, finite number, server value, or null).");r.push(a)}),na(s,r)},jn=function(n,e,t){if(Nt(e))throw new Error(_e(n,"priority")+"is "+e.toString()+", but must be a valid Firebase priority (a string, finite number, server value, or null).");if(!$e(e))throw new Error(_e(n,"priority")+"must be a valid Firebase priority (a string, finite number, server value, or null).")},st=function(n,e,t,i){if(t!==void 0&&!Lt(t))throw new Error(_e(n,e)+'was an invalid key = "'+t+`". Firebase keys must be non-empty strings and can't contain ".", "#", "$", "/", "[", or "]").`)},$n=function(n,e,t,i){if(!(i&&t===void 0)&&!Vs(t))throw new Error(_e(n,e)+'was an invalid path = "'+t+`". Paths must be non-empty strings and can't contain ".", "#", "$", "[", or "]"`)},ia=function(n,e,t,i){t&&(t=t.replace(/^\/*\.info(\/|$)/,"/")),$n(n,e,t,i)},j=function(n,e){if(g(e)===".info")throw new Error(n+" failed = Can't modify data under /.info/")},Hs=function(n,e){const t=e.path.toString();if(typeof e.repoInfo.host!="string"||e.repoInfo.host.length===0||!Lt(e.repoInfo.namespace)&&e.repoInfo.host.split(":")[0]!=="localhost"||t.length!==0&&!ta(t))throw new Error(_e(n,"url")+`must be a valid firebase URL and the path can't
994contain ".", "#", "$", "[", or "]".`)};/** 995 * @license 996 * Copyright 2017 Google LLC 997 * 998 * Licensed under the Apache License, Version 2.0 (the "License"); 999 * you may not use this file except in compliance with the License. 1000 * You may obtain a copy of the License at 1001 * 1002 * http://www.apache.org/licenses/LICENSE-2.0 1003 * 1004 * Unless required by applicable law or agreed to in writing, software 1005 * distributed under the License is distributed on an "AS IS" BASIS, 1006 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1007 * See the License for the specific language governing permissions and 1008 * limitations under the License. 1009 */class sa{constructor(){this.eventLists_=[],this.recursionDepth_=0}}function Ft(n,e){let t=null;for(let i=0;i<e.length;i++){const s=e[i],r=s.getPath();t!==null&&!Sn(r,t.path)&&(n.eventLists_.push(t),t=null),t===null&&(t={events:[],path:r}),t.events.push(s)}t&&n.eventLists_.push(t)}function Qs(n,e,t){Ft(n,t),qs(n,i=>Sn(i,e))}function W(n,e,t){Ft(n,t),qs(n,i=>G(i,e)||G(e,i))}function qs(n,e){n.recursionDepth_++;let t=!0;for(let i=0;i<n.eventLists_.length;i++){const s=n.eventLists_[i];if(s){const r=s.path;e(r)?(ra(n.eventLists_[i]),n.eventLists_[i]=null):t=!1}}t&&(n.eventLists_=[]),n.recursionDepth_--}function ra(n){for(let e=0;e<n.events.length;e++){const t=n.events[e];if(t!==null){n.events[e]=null;const i=t.getEventRunner();fe&&A("event: "+t.toString()),xe(i)}}}/** 1010 * @license 1011 * Copyright 2017 Google LLC 1012 * 1013 * Licensed under the Apache License, Version 2.0 (the "License"); 1014 * you may not use this file except in compliance with the License. 1015 * You may obtain a copy of the License at 1016 * 1017 * http://www.apache.org/licenses/LICENSE-2.0 1018 * 1019 * Unless required by applicable law or agreed to in writing, software 1020 * distributed under the License is distributed on an "AS IS" BASIS, 1021 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1022 * See the License for the specific language governing permissions and 1023 * limitations under the License. 1024 */const Ys="repo_interrupt",oa=25;class la{constructor(e,t,i,s){this.repoInfo_=e,this.forceRestClient_=t,this.authTokenProvider_=i,this.appCheckProvider_=s,this.dataUpdateCount=0,this.statsListener_=null,this.eventQueue_=new sa,this.nextWriteId_=1,this.interceptServerDataCallback_=null,this.onDisconnect_=mt(),this.transactionQueueTree_=new Kn,this.persistentConnection_=null,this.key=this.repoInfo_.toURLString()}toString(){return(this.repoInfo_.secure?"https://":"http://")+this.repoInfo_.host}}function aa(n,e,t){if(n.stats_=wn(n.repoInfo_),n.forceRestClient_||Br())n.server_=new pt(n.repoInfo_,(i,s,r,o)=>{Oi(n,i,s,r,o)},n.authTokenProvider_,n.appCheckProvider_),setTimeout(()=>Mi(n,!0),0);else{if(typeof t<"u"&&t!==null){if(typeof t!="object")throw new Error("Only objects are supported for option databaseAuthVariableOverride");try{b(t)}catch(i){throw new Error("Invalid authOverride provided: "+i)}}n.persistentConnection_=new H(n.repoInfo_,e,(i,s,r,o)=>{Oi(n,i,s,r,o)},i=>{Mi(n,i)},i=>{ca(n,i)},n.authTokenProvider_,n.appCheckProvider_,t),n.server_=n.persistentConnection_}n.authTokenProvider_.addTokenChangeListener(i=>{n.server_.refreshAuthToken(i)}),n.appCheckProvider_.addTokenChangeListener(i=>{n.server_.refreshAppCheckToken(i.token)}),n.statsReporter_=qr(n.repoInfo_,()=>new Ko(n.stats_,n.server_)),n.infoData_=new Go,n.infoSyncTree_=new xi({startListening:(i,s,r,o)=>{let l=[];const a=n.infoData_.getNode(i._path);return a.isEmpty()||(l=tt(n.infoSyncTree_,i._path,a),setTimeout(()=>{o("ok")},0)),l},stopListening:()=>{}}),Xn(n,"connected",!1),n.serverSyncTree_=new xi({startListening:(i,s,r,o)=>(n.server_.listen(i,r,s,(l,a)=>{const c=o(l,a);W(n.eventQueue_,i._path,c)}),[]),stopListening:(i,s)=>{n.server_.unlisten(i,s)}})}function Ks(n){const t=n.infoData_.getNode(new E(".info/serverTimeOffset")).val()||0;return new Date().getTime()+t}function rt(n){return Kl({timestamp:Ks(n)})}function Oi(n,e,t,i,s){n.dataUpdateCount++;const r=new E(e);t=n.interceptServerDataCallback_?n.interceptServerDataCallback_(e,t):t;let o=[];if(s)if(i){const a=ut(t,c=>R(c));o=Vl(n.serverSyncTree_,r,a,s)}else{const a=R(t);o=Os(n.serverSyncTree_,r,a,s)}else if(i){const a=ut(t,c=>R(c));o=Wl(n.serverSyncTree_,r,a)}else{const a=R(t);o=tt(n.serverSyncTree_,r,a)}let l=r;o.length>0&&(l=Pe(n,r)),W(n.eventQueue_,l,o)}function Mi(n,e){Xn(n,"connected",e),e===!1&&da(n)}function ca(n,e){x(e,(t,i)=>{Xn(n,t,i)})}function Xn(n,e,t){const i=new E("/.info/"+e),s=R(t);n.infoData_.updateSnapshot(i,s);const r=tt(n.infoSyncTree_,i,s);W(n.eventQueue_,i,r)}function Wt(n){return n.nextWriteId_++}function ha(n,e,t){const i=Gl(n.serverSyncTree_,e);return i!=null?Promise.resolve(i):n.server_.get(e).then(s=>{const r=R(s).withIndex(e._queryParams.getIndex());_n(n.serverSyncTree_,e,t,!0);let o;if(e._queryParams.loadsAllData())o=tt(n.serverSyncTree_,e._path,r);else{const l=je(n.serverSyncTree_,e);o=Os(n.serverSyncTree_,e._path,r,l)}return W(n.eventQueue_,e._path,o),It(n.serverSyncTree_,e,t,null,!0),r},s=>(Me(n,"get for query "+b(e)+" failed: "+s),Promise.reject(new Error(s))))}function Jn(n,e,t,i,s){Me(n,"set",{path:e.toString(),value:t,priority:i});const r=rt(n),o=R(t,i),l=xt(n.serverSyncTree_,e),a=qn(o,l,r),c=Wt(n),h=Un(n.serverSyncTree_,e,a,c,!0);Ft(n.eventQueue_,h),n.server_.put(e.toString(),o.val(!0),(d,_)=>{const p=d==="ok";p||O("set at "+e+" failed: "+d);const w=ne(n.serverSyncTree_,c,!p);W(n.eventQueue_,e,w),ce(n,s,d,_)});const u=ei(n,e);Pe(n,u),W(n.eventQueue_,u,[])}function ua(n,e,t,i){Me(n,"update",{path:e.toString(),value:t});let s=!0;const r=rt(n),o={};if(x(t,(l,a)=>{s=!1,o[l]=Ws(N(e,l),R(a),n.serverSyncTree_,r)}),s)A("update() called with empty data. Don't do anything."),ce(n,i,"ok",void 0);else{const l=Wt(n),a=Fl(n.serverSyncTree_,e,o,l);Ft(n.eventQueue_,a),n.server_.merge(e.toString(),t,(c,h)=>{const u=c==="ok";u||O("update at "+e+" failed: "+c);const d=ne(n.serverSyncTree_,l,!u),_=d.length>0?Pe(n,e):e;W(n.eventQueue_,_,d),ce(n,i,c,h)}),x(t,c=>{const h=ei(n,N(e,c));Pe(n,h)}),W(n.eventQueue_,e,[])}}function da(n){Me(n,"onDisconnectEvents");const e=rt(n),t=mt();an(n.onDisconnect_,C(),(s,r)=>{const o=Ws(s,r,n.serverSyncTree_,e);De(t,s,o)});let i=[];an(t,C(),(s,r)=>{i=i.concat(tt(n.serverSyncTree_,s,r));const o=ei(n,s);Pe(n,o)}),n.onDisconnect_=mt(),W(n.eventQueue_,C(),i)}function fa(n,e,t){n.server_.onDisconnectCancel(e.toString(),(i,s)=>{i==="ok"&&ln(n.onDisconnect_,e),ce(n,t,i,s)})}function Li(n,e,t,i){const s=R(t);n.server_.onDisconnectPut(e.toString(),s.val(!0),(r,o)=>{r==="ok"&&De(n.onDisconnect_,e,s),ce(n,i,r,o)})}function _a(n,e,t,i,s){const r=R(t,i);n.server_.onDisconnectPut(e.toString(),r.val(!0),(o,l)=>{o==="ok"&&De(n.onDisconnect_,e,r),ce(n,s,o,l)})}function pa(n,e,t,i){if(Zt(t)){A("onDisconnect().update() called with empty data. Don't do anything."),ce(n,i,"ok",void 0);return}n.server_.onDisconnectMerge(e.toString(),t,(s,r)=>{s==="ok"&&x(t,(o,l)=>{const a=R(l);De(n.onDisconnect_,N(e,o),a)}),ce(n,i,s,r)})}function ma(n,e,t){let i;g(e._path)===".info"?i=_n(n.infoSyncTree_,e,t):i=_n(n.serverSyncTree_,e,t),Qs(n.eventQueue_,e._path,i)}function mn(n,e,t){let i;g(e._path)===".info"?i=It(n.infoSyncTree_,e,t):i=It(n.serverSyncTree_,e,t),Qs(n.eventQueue_,e._path,i)}function zs(n){n.persistentConnection_&&n.persistentConnection_.interrupt(Ys)}function ga(n){n.persistentConnection_&&n.persistentConnection_.resume(Ys)}function Me(n,...e){let t="";n.persistentConnection_&&(t=n.persistentConnection_.id+":"),A(t,...e)}function ce(n,e,t,i){e&&xe(()=>{if(t==="ok")e(null);else{const s=(t||"error").toUpperCase();let r=s;i&&(r+=": "+i);const o=new Error(r);o.code=s,e(o)}})}function ya(n,e,t,i,s,r){Me(n,"transaction on "+e);const o={path:e,update:t,onComplete:i,status:null,order:Hi(),applyLocally:r,retryCount:0,unwatcher:s,abortReason:null,currentWriteId:null,currentInputSnapshot:null,currentOutputSnapshotRaw:null,currentOutputSnapshotResolved:null},l=Zn(n,e,void 0);o.currentInputSnapshot=l;const a=o.update(l.val());
1024if(a===void 0)o.unwatcher(),o.currentOutputSnapshotRaw=null,o.currentOutputSnapshotResolved=null,o.onComplete&&o.onComplete(null,!1,o.currentInputSnapshot);else{it("transaction failed: Data returned ",a,o.path),o.status=0;const c=Ot(n.transactionQueueTree_,e),h=Ee(c)||[];h.push(o),zn(c,h);let u;typeof a=="object"&&a!==null&&Y(a,".priority")?(u=pe(a,".priority"),f($e(u),"Invalid priority returned by transaction. Priority must be a valid string, finite number, server value, or null.")):u=(xt(n.serverSyncTree_,e)||m.EMPTY_NODE).getPriority().val();const d=rt(n),_=R(a,u),p=qn(_,l,d);o.currentOutputSnapshotRaw=_,o.currentOutputSnapshotResolved=p,o.currentWriteId=Wt(n);const w=Un(n.serverSyncTree_,e,p,o.currentWriteId,o.applyLocally);W(n.eventQueue_,e,w),Ut(n,n.transactionQueueTree_)}}function Zn(n,e,t){return xt(n.serverSyncTree_,e,t)||m.EMPTY_NODE}function Ut(n,e=n.transactionQueueTree_){if(e||Bt(n,e),Ee(e)){const t=$s(n,e);f(t.length>0,"Sending zero length transaction queue"),t.every(s=>s.status===0)&&va(n,nt(e),t)}else Us(e)&&Mt(e,t=>{Ut(n,t)})}function va(n,e,t){const i=t.map(c=>c.currentWriteId),s=Zn(n,e,i);let r=s;const o=s.hash();for(let c=0;c<t.length;c++){const h=t[c];f(h.status===0,"tryToSendTransactionQueue_: items in queue should all be run."),h.status=1,h.retryCount++;const u=M(e,h.path);r=r.updateChild(u,h.currentOutputSnapshotRaw)}const l=r.val(!0),a=e;n.server_.put(a.toString(),l,c=>{Me(n,"transaction put response",{path:a.toString(),status:c});let h=[];if(c==="ok"){const u=[];for(let d=0;d<t.length;d++)t[d].status=2,h=h.concat(ne(n.serverSyncTree_,t[d].currentWriteId)),t[d].onComplete&&u.push(()=>t[d].onComplete(null,!0,t[d].currentOutputSnapshotResolved)),t[d].unwatcher();Bt(n,Ot(n.transactionQueueTree_,e)),Ut(n,n.transactionQueueTree_),W(n.eventQueue_,e,h);for(let d=0;d<u.length;d++)xe(u[d])}else{if(c==="datastale")for(let u=0;u<t.length;u++)t[u].status===3?t[u].status=4:t[u].status=0;else{O("transaction at "+a.toString()+" failed: "+c);for(let u=0;u<t.length;u++)t[u].status=4,t[u].abortReason=c}Pe(n,e)}},o)}function Pe(n,e){const t=js(n,e),i=nt(t),s=$s(n,t);return Ca(n,s,i),i}function Ca(n,e,t){if(e.length===0)return;const i=[];let s=[];const o=e.filter(l=>l.status===0).map(l=>l.currentWriteId);for(let l=0;l<e.length;l++){const a=e[l],c=M(t,a.path);let h=!1,u;if(f(c!==null,"rerunTransactionsUnderNode_: relativePath should not be null."),a.status===4)h=!0,u=a.abortReason,s=s.concat(ne(n.serverSyncTree_,a.currentWriteId,!0));else if(a.status===0)if(a.retryCount>=oa)h=!0,u="maxretry",s=s.concat(ne(n.serverSyncTree_,a.currentWriteId,!0));else{const d=Zn(n,a.path,o);a.currentInputSnapshot=d;const _=e[l].update(d.val());if(_!==void 0){it("transaction failed: Data returned ",_,a.path);let p=R(_);typeof _=="object"&&_!=null&&Y(_,".priority")||(p=p.updatePriority(d.getPriority()));const D=a.currentWriteId,we=rt(n),at=qn(p,d,we);a.currentOutputSnapshotRaw=p,a.currentOutputSnapshotResolved=at,a.currentWriteId=Wt(n),o.splice(o.indexOf(D),1),s=s.concat(Un(n.serverSyncTree_,a.path,at,a.currentWriteId,a.applyLocally)),s=s.concat(ne(n.serverSyncTree_,D,!0))}else h=!0,u="nodata",s=s.concat(ne(n.serverSyncTree_,a.currentWriteId,!0))}W(n.eventQueue_,t,s),s=[],h&&(e[l].status=2,(function(d){setTimeout(d,Math.floor(0))})(e[l].unwatcher),e[l].onComplete&&(u==="nodata"?i.push(()=>e[l].onComplete(null,!1,e[l].currentInputSnapshot)):i.push(()=>e[l].onComplete(new Error(u),!1,null))))}Bt(n,n.transactionQueueTree_);for(let l=0;l<i.length;l++)xe(i[l]);Ut(n,n.transactionQueueTree_)}function js(n,e){let t,i=n.transactionQueueTree_;for(t=g(e);t!==null&&Ee(i)===void 0;)i=Ot(i,t),e=T(e),t=g(e);return i}function $s(n,e){const t=[];return Xs(n,e,t),t.sort((i,s)=>i.order-s.order),t}function Xs(n,e,t){const i=Ee(e);if(i)for(let s=0;s<i.length;s++)t.push(i[s]);Mt(e,s=>{Xs(n,s,t)})}function Bt(n,e){const t=Ee(e);if(t){let i=0;for(let s=0;s<t.length;s++)t[s].status!==2&&(t[i]=t[s],i++);t.length=i,zn(e,t.length>0?t:void 0)}Mt(e,i=>{Bt(n,i)})}function ei(n,e){const t=nt(js(n,e)),i=Ot(n.transactionQueueTree_,e);return Xl(i,s=>{Xt(n,s)}),Xt(n,i),Bs(i,s=>{Xt(n,s)}),t}function Xt(n,e){const t=Ee(e);if(t){const i=[];let s=[],r=-1;for(let o=0;o<t.length;o++)t[o].status===3||(t[o].status===1?(f(r===o-1,"All SENT items should be at beginning of queue."),r=o,t[o].status=3,t[o].abortReason="set"):(f(t[o].status===0,"Unexpected transaction status in abort"),t[o].unwatcher(),s=s.concat(ne(n.serverSyncTree_,t[o].currentWriteId,!0)),t[o].onComplete&&i.push(t[o].onComplete.bind(null,new Error("set"),!1,null))));r===-1?zn(e,void 0):t.length=r+1,W(n.eventQueue_,nt(e),s);for(let o=0;o<i.length;o++)xe(i[o])}}/** 1025 * @license 1026 * Copyright 2017 Google LLC 1027 * 1028 * Licensed under the Apache License, Version 2.0 (the "License");
1029 * you may not use this file except in compliance with the License. 1030 * You may obtain a copy of the License at 1031 * 1032 * http://www.apache.org/licenses/LICENSE-2.0 1033 * 1034 * Unless required by applicable law or agreed to in writing, software 1035 * distributed under the License is distributed on an "AS IS" BASIS, 1036 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1037 * See the License for the specific language governing permissions and 1038 * limitations under the License. 1039 */function Ea(n){let e="";const t=n.split("/");for(let i=0;i<t.length;i++)if(t[i].length>0){let s=t[i];try{s=decodeURIComponent(s.replace(/\+/g," "))}catch{}e+="/"+s}return e}function wa(n){const e={};n.charAt(0)==="?"&&(n=n.substring(1));for(const t of n.split("&")){if(t.length===0)continue;const i=t.split("=");i.length===2?e[decodeURIComponent(i[0])]=decodeURIComponent(i[1]):O(`Invalid query segment '${t}' in query '${n}'`)}return e}const gn=function(n,e){const t=Ta(n),i=t.namespace;t.domain==="firebase.com"&&X(t.host+" is no longer supported. Please use <YOUR FIREBASE>.firebaseio.com instead"),(!i||i==="undefined")&&t.domain!=="localhost"&&X("Cannot parse Firebase url. Please use https://<YOUR FIREBASE>.firebaseio.com"),t.secure||Ar();const s=t.scheme==="ws"||t.scheme==="wss";return{repoInfo:new is(t.host,t.secure,i,s,e,"",i!==t.subdomain),path:new E(t.pathString)}},Ta=function(n){let e="",t="",i="",s="",r="",o=!0,l="https",a=443;if(typeof n=="string"){let c=n.indexOf("//");c>=0&&(l=n.substring(0,c-1),n=n.substring(c+2));let h=n.indexOf("/");h===-1&&(h=n.length);let u=n.indexOf("?");u===-1&&(u=n.length),e=n.substring(0,Math.min(h,u)),h<u&&(s=Ea(n.substring(h,u)));const d=wa(n.substring(Math.min(n.length,u)));c=e.indexOf(":"),c>=0?(o=l==="https"||l==="wss",a=parseInt(e.substring(c+1),10)):c=e.length;const _=e.slice(0,c);if(_.toLowerCase()==="localhost")t="localhost";else if(_.split(".").length<=2)t=_;else{const p=e.indexOf(".");i=e.substring(0,p).toLowerCase(),t=e.substring(p+1),r=i}"ns"in d&&(r=d.ns)}return{host:e,port:a,domain:t,subdomain:i,secure:o,scheme:l,pathString:s,namespace:r}};/** 1040 * @license 1041 * Copyright 2017 Google LLC 1042 * 1043 * Licensed under the Apache License, Version 2.0 (the "License"); 1044 * you may not use this file except in compliance with the License. 1045 * You may obtain a copy of the License at 1046 * 1047 * http://www.apache.org/licenses/LICENSE-2.0 1048 * 1049 * Unless required by applicable law or agreed to in writing, software 1050 * distributed under the License is distributed on an "AS IS" BASIS, 1051 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1052 * See the License for the specific language governing permissions and 1053 * limitations under the License. 1054 */const Fi="-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz",Ia=(function(){let n=0;const e=[];return function(t){const i=t===n;n=t;let s;const r=new Array(8);for(s=7;s>=0;s--)r[s]=Fi.charAt(t%64),t=Math.floor(t/64);f(t===0,"Cannot push at time == 0");let o=r.join("");if(i){for(s=11;s>=0&&e[s]===63;s--)e[s]=0;e[s]++}else for(s=0;s<12;s++)e[s]=Math.floor(Math.random()*64);for(s=0;s<12;s++)o+=Fi.charAt(e[s]);return f(o.length===20,"nextPushId: Length should be 20."),o}})();/** 1055 * @license 1056 * Copyright 2017 Google LLC 1057 * 1058 * Licensed under the Apache License, Version 2.0 (the "License"); 1059 * you may not use this file except in compliance with the License. 1060 * You may obtain a copy of the License at 1061 * 1062 * http://www.apache.org/licenses/LICENSE-2.0 1063 * 1064 * Unless required by applicable law or agreed to in writing, software 1065 * distributed under the License is distributed on an "AS IS" BASIS, 1066 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1067 * See the License for the specific language governing permissions and 1068 * limitations under the License. 1069 */class Js{constructor(e,t,i,s){this.eventType=e,this.eventRegistration=t,this.snapshot=i,this.prevName=s}getPath(){const e=this.snapshot.ref;return this.eventType==="value"?e._path:e.parent._path}getEventType(){return this.eventType}getEventRunner(){return this.eventRegistration.getEventRunner(this)}toString(){return this.getPath().toString()+":"+this.eventType+":"+b(this.snapshot.exportVal())}}class Zs{constructor(e,t,i){this.eventRegistration=e,this.error=t,this.path=i}getPath(){return this.path}getEventType(){return"cancel"}getEventRunner(){return this.eventRegistration.getEventRunner(this)}toString(){return this.path.toString()+":cancel"}}/** 1070 * @license 1071 * Copyright 2017 Google LLC 1072 * 1073 * Licensed under the Apache License, Version 2.0 (the "License");
1074 * you may not use this file except in compliance with the License. 1075 * You may obtain a copy of the License at 1076 * 1077 * http://www.apache.org/licenses/LICENSE-2.0 1078 * 1079 * Unless required by applicable law or agreed to in writing, software 1080 * distributed under the License is distributed on an "AS IS" BASIS, 1081 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1082 * See the License for the specific language governing permissions and 1083 * limitations under the License. 1084 */class ti{constructor(e,t){this.snapshotCallback=e,this.cancelCallback=t}onValue(e,t){this.snapshotCallback.call(null,e,t)}onCancel(e){return f(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||this.snapshotCallback.userCallback!==void 0&&this.snapshotCallback.userCallback===e.snapshotCallback.userCallback&&this.snapshotCallback.context===e.snapshotCallback.context}}/** 1085 * @license 1086 * Copyright 2021 Google LLC 1087 * 1088 * Licensed under the Apache License, Version 2.0 (the "License"); 1089 * you may not use this file except in compliance with the License. 1090 * You may obtain a copy of the License at 1091 * 1092 * http://www.apache.org/licenses/LICENSE-2.0 1093 * 1094 * Unless required by applicable law or agreed to in writing, software 1095 * distributed under the License is distributed on an "AS IS" BASIS, 1096 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1097 * See the License for the specific language governing permissions and 1098 * limitations under the License. 1099 */class Sa{constructor(e,t){this._repo=e,this._path=t}cancel(){const e=new B;return fa(this._repo,this._path,e.wrapCallback(()=>{})),e.promise}remove(){j("OnDisconnect.remove",this._path);const e=new B;return Li(this._repo,this._path,null,e.wrapCallback(()=>{})),e.promise}set(e){j("OnDisconnect.set",this._path),J("OnDisconnect.set",e,this._path,!1);const t=new B;return Li(this._repo,this._path,e,t.wrapCallback(()=>{})),t.promise}setWithPriority(e,t){j("OnDisconnect.setWithPriority",this._path),J("OnDisconnect.setWithPriority",e,this._path,!1),jn("OnDisconnect.setWithPriority",t);const i=new B;return _a(this._repo,this._path,e,t,i.wrapCallback(()=>{})),i.promise}update(e){j("OnDisconnect.update",this._path),Gs("OnDisconnect.update",e,this._path);const t=new B;return pa(this._repo,this._path,e,t.wrapCallback(()=>{})),t.promise}}/** 1100 * @license 1101 * Copyright 2020 Google LLC 1102 * 1103 * Licensed under the Apache License, Version 2.0 (the "License"); 1104 * you may not use this file except in compliance with the License. 1105 * You may obtain a copy of the License at 1106 * 1107 * http://www.apache.org/licenses/LICENSE-2.0 1108 * 1109 * Unless required by applicable law or agreed to in writing, software 1110 * distributed under the License is distributed on an "AS IS" BASIS, 1111 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1112 * See the License for the specific language governing permissions and 1113 * limitations under the License. 1114 */class U{constructor(e,t,i,s){this._repo=e,this._path=t,this._queryParams=i,this._orderByCalled=s}get key(){return y(this._path)?null:In(this._path)}get ref(){return new K(this._repo,this._path)}get _queryIdentifier(){const e=wi(this._queryParams),t=Cn(e);return t==="{}"?"default":t}get _queryObject(){return wi(this._queryParams)}isEqual(e){if(e=F(e),!(e instanceof U))return!1;const t=this._repo===e._repo,i=Sn(this._path,e._path),s=this._queryIdentifier===e._queryIdentifier;return t&&i&&s}toJSON(){return this.toString()}toString(){return this._repo.toString()+po(this._path)}}function Vt(n,e){if(n._orderByCalled===!0)throw new Error(e+": You can't combine multiple orderBy calls.")}function he(n){let e=null,t=null;if(n.hasStart()&&(e=n.getIndexStartValue()),n.hasEnd()&&(t=n.getIndexEndValue()),n.getIndex()===$){const i="Query: When ordering by key, you may only pass one argument to startAt(), endAt(), or equalTo().",s="Query: When ordering by key, the argument passed to startAt(), startAfter(), endAt(), endBefore(), or equalTo() must be a string.";if(n.hasStart()){if(n.getIndexStartName()!==re)throw new Error(i);if(typeof e!="string")throw new Error(s)}if(n.hasEnd()){if(n.getIndexEndName()!==ee)throw new Error(i);if(typeof t!="string")throw new Error(s)}}else if(n.getIndex()===S){if(e!=null&&!$e(e)||t!=null&&!$e(t))throw new Error("Query: When ordering by priority, the first argument passed to startAt(), startAfter() endAt(), endBefore(), or equalTo() must be a valid priority value (null, a number, or a string).")}else if(f(n.getIndex()instanceof bn||n.getIndex()===kn,"unknown index type."),e!=null&&typeof e=="object"||t!=null&&typeof t=="object")throw new Error("Query: First argument passed to startAt(), startAfter(), endAt(), endBefore(), or equalTo() cannot be an object.")}function Gt(n){if(n.hasStart()&&n.hasEnd()&&n.hasLimit()&&!n.hasAnchoredLimit())throw new Error("Query: Can't combine startAt(), startAfter(), endAt(), endBefore(), and limit(). Use limitToFirst() or limitToLast() instead.")}class K extends U{constructor(e,t){super(e,t,new An,!1)}get parent(){const e=ds(this._path);return e===null?null:new K(this._repo,e)}get root(){let e=this;for(;e.parent!==null;)e=e.parent;return e}}class ye{constructor(e,t,i){this._node=e,this.ref=t,this._index=i}get priority(){return this._node.getPriority().val()}get key(){return this.ref.key}get size(){return this._node.numChildren()}child(e){const t=new E(e),i=Ae(this.ref,e);return new ye(this._node.getChild(t),i,S)}exists(){return!this._node.isEmpty()}exportVal(){return this._node.val(!0)}forEach(e){return this._node.isLeafNode()?!1:!!this._node.forEachChild(this._index,(i,s)=>e(new ye(s,Ae(this.ref,i),S)))}hasChild(e){const t=new E(e);return!this._node.getChild(t).isEmpty()}hasChildren(){return this._node.isLeafNode()?!1:!this._node.isEmpty()}toJSON(){return this.exportVal()}val(){return this._node.val()}}function Na(n,e){return n=F(n),n._checkNotDeleted("ref"),e!==void 0?Ae(n._root,e):n._root}function za(n,e){n=F(n),n._checkNotDeleted("refFromURL");const t=gn(e,n._repo.repoInfo_.nodeAdmin);Hs("refFromURL",t);const i=t.repoInfo;return!n._repo.repoInfo_.isCustomHost()&&i.host!==n._repo.repoInfo_.host&&X("refFromURL: Host name does not match the current database: (found "+i.host+" but expected "+n._repo.repoInfo_.host+")"),Na(n,t.path.toString())}function Ae(n,e){return n=F(n),g(n._path)===null?ia("child","path",e,!1):$n("child","path",e,!1),new K(n._repo,N(n._path,e))}function ja(n){return n=F(n),new Sa(n._repo,n._path)}function $a(n,e){n=F(n),j("push",n._path),J("push",e,n._path,!0);const t=Ks(n._repo),i=Ia(t),s=Ae(n,i),r=Ae(n,i);let o;return e!=null?o=er(r,e).then(()=>r):o=Promise.resolve(r),s.then=o.then.bind(o),s.catch=o.then.bind(o,void 0),s}function Xa(n){return j("remove",n._path),er(n,null)}function er(n,e){n=F(n),j("set",n._path),J("set",e,n._path,!1);const t=new B;return Jn(n._repo,n._path,e,null,t.wrapCallback(()=>{})),t.promise}function Ja(n,e){n=F(n),j("setPriority",n._path),jn("setPriority",e);const t=new B;return Jn(n._repo,N(n._path,".priority"),e,null,t.wrapCallback(()=>{})),t.promise}function Za(n,e,t){if(j("setWithPriority",n._path),J("setWithPriority",e,n._path,!1),jn("setWithPriority",t),n.key===".length"||n.key===".keys")throw"setWithPriority failed: "+n.key+" is a read-only object.";const i=new B;return Jn(n._repo,n._path,e,t,i.wrapCallback(()=>{})),i.promise}function ec(n,e){Gs("update",e,n._path);const t=new B;return ua(n._repo,n._path,e,t.wrapCallback(()=>{})),t.promise}function tc(n){n=F(n);const e=new ti(()=>{}),t=new ot(e);return ha(n._repo,n,t).then(i=>new ye(i,new K(n._repo,n._path),n._queryParams.getIndex()))}
1114class ot{constructor(e){this.callbackContext=e}respondsTo(e){return e==="value"}createEvent(e,t){const i=t._queryParams.getIndex();return new Js("value",this,new ye(e.snapshotNode,new K(t._repo,t._path),i))}getEventRunner(e){return e.getEventType()==="cancel"?()=>this.callbackContext.onCancel(e.error):()=>this.callbackContext.onValue(e.snapshot,null)}createCancelEvent(e,t){return this.callbackContext.hasCancelCallback?new Zs(this,e,t):null}matches(e){return e instanceof ot?!e.callbackContext||!this.callbackContext?!0:e.callbackContext.matches(this.callbackContext):!1}hasAnyCallback(){return this.callbackContext!==null}}class Ht{constructor(e,t){this.eventType=e,this.callbackContext=t}respondsTo(e){let t=e==="children_added"?"child_added":e;return t=t==="children_removed"?"child_removed":t,this.eventType===t}createCancelEvent(e,t){return this.callbackContext.hasCancelCallback?new Zs(this,e,t):null}createEvent(e,t){f(e.childName!=null,"Child events should have a childName.");const i=Ae(new K(t._repo,t._path),e.childName),s=t._queryParams.getIndex();return new Js(e.type,this,new ye(e.snapshotNode,i,s),e.prevName)}getEventRunner(e){return e.getEventType()==="cancel"?()=>this.callbackContext.onCancel(e.error):()=>this.callbackContext.onValue(e.snapshot,e.prevName)}matches(e){return e instanceof Ht?this.eventType===e.eventType&&(!this.callbackContext||!e.callbackContext||this.callbackContext.matches(e.callbackContext)):!1}hasAnyCallback(){return!!this.callbackContext}}function lt(n,e,t,i,s){let r;if(typeof i=="object"&&(r=void 0,s=i),typeof i=="function"&&(r=i),s&&s.onlyOnce){const a=t,c=(h,u)=>{mn(n._repo,n,l),a(h,u)};c.userCallback=t.userCallback,c.context=t.context,t=c}const o=new ti(t,r||void 0),l=e==="value"?new ot(o):new Ht(e,o);return ma(n._repo,n,l),()=>mn(n._repo,n,l)}function Ra(n,e,t,i){return lt(n,"value",e,t,i)}function nc(n,e,t,i){return lt(n,"child_added",e,t,i)}function ic(n,e,t,i){return lt(n,"child_changed",e,t,i)}function sc(n,e,t,i){return lt(n,"child_moved",e,t,i)}function rc(n,e,t,i){return lt(n,"child_removed",e,t,i)}function oc(n,e,t){let i=null;const s=t?new ti(t):null;e==="value"?i=new ot(s):e&&(i=new Ht(e,s)),mn(n._repo,n,i)}class z{}class tr extends z{constructor(e,t){super(),this._value=e,this._key=t,this.type="endAt"}_apply(e){J("endAt",this._value,e._path,!0);const t=on(e._queryParams,this._value,this._key);if(Gt(t),he(t),e._queryParams.hasEnd())throw new Error("endAt: Starting point was already set (by another call to endAt, endBefore or equalTo).");return new U(e._repo,e._path,t,e._orderByCalled)}}function lc(n,e){return st("endAt","key",e),new tr(n,e)}class ba extends z{constructor(e,t){super(),this._value=e,this._key=t,this.type="endBefore"}_apply(e){J("endBefore",this._value,e._path,!1);const t=Vo(e._queryParams,this._value,this._key);if(Gt(t),he(t),e._queryParams.hasEnd())throw new Error("endBefore: Starting point was already set (by another call to endAt, endBefore or equalTo).");return new U(e._repo,e._path,t,e._orderByCalled)}}function ac(n,e){return st("endBefore","key",e),new ba(n,e)}class nr extends z{constructor(e,t){super(),this._value=e,this._key=t,this.type="startAt"}_apply(e){J("startAt",this._value,e._path,!0);const t=rn(e._queryParams,this._value,this._key);if(Gt(t),he(t),e._queryParams.hasStart())throw new Error("startAt: Starting point was already set (by another call to startAt, startBefore or equalTo).");return new U(e._repo,e._path,t,e._orderByCalled)}}function cc(n=null,e){return st("startAt","key",e),new nr(n,e)}class ka extends z{constructor(e,t){super(),this._value=e,this._key=t,this.type="startAfter"}_apply(e){J("startAfter",this._value,e._path,!1);const t=Bo(e._queryParams,this._value,this._key);if(Gt(t),he(t),e._queryParams.hasStart())throw new Error("startAfter: Starting point was already set (by another call to startAt, startAfter, or equalTo).");return new U(e._repo,e._path,t,e._orderByCalled)}}function hc(n,e){return st("startAfter","key",e),new ka(n,e)}class Pa extends z{constructor(e){super(),this._limit=e,this.type="limitToFirst"}_apply(e){if(e._queryParams.hasLimit())throw new Error("limitToFirst: Limit was already set
1114(by another call to limitToFirst or limitToLast).");return new U(e._repo,e._path,Wo(e._queryParams,this._limit),e._orderByCalled)}}function uc(n){if(typeof n!="number"||Math.floor(n)!==n||n<=0)throw new Error("limitToFirst: First argument must be a positive integer.");return new Pa(n)}class Aa extends z{constructor(e){super(),this._limit=e,this.type="limitToLast"}_apply(e){if(e._queryParams.hasLimit())throw new Error("limitToLast: Limit was already set (by another call to limitToFirst or limitToLast).");return new U(e._repo,e._path,Uo(e._queryParams,this._limit),e._orderByCalled)}}function dc(n){if(typeof n!="number"||Math.floor(n)!==n||n<=0)throw new Error("limitToLast: First argument must be a positive integer.");return new Aa(n)}class xa extends z{constructor(e){super(),this._path=e,this.type="orderByChild"}_apply(e){Vt(e,"orderByChild");const t=new E(this._path);if(y(t))throw new Error("orderByChild: cannot pass in empty path. Use orderByValue() instead.");const i=new bn(t),s=bt(e._queryParams,i);return he(s),new U(e._repo,e._path,s,!0)}}function fc(n){if(n==="$key")throw new Error('orderByChild: "$key" is invalid. Use orderByKey() instead.');if(n==="$priority")throw new Error('orderByChild: "$priority" is invalid. Use orderByPriority() instead.');if(n==="$value")throw new Error('orderByChild: "$value" is invalid. Use orderByValue() instead.');return $n("orderByChild","path",n,!1),new xa(n)}class Da extends z{constructor(){super(...arguments),this.type="orderByKey"}_apply(e){Vt(e,"orderByKey");const t=bt(e._queryParams,$);return he(t),new U(e._repo,e._path,t,!0)}}function _c(){return new Da}class Oa extends z{constructor(){super(...arguments),this.type="orderByPriority"}_apply(e){Vt(e,"orderByPriority");const t=bt(e._queryParams,S);return he(t),new U(e._repo,e._path,t,!0)}}function pc(){return new Oa}class Ma extends z{constructor(){super(...arguments),this.type="orderByValue"}_apply(e){Vt(e,"orderByValue");const t=bt(e._queryParams,kn);return he(t),new U(e._repo,e._path,t,!0)}}function mc(){return new Ma}class La extends z{constructor(e,t){super(),this._value=e,this._key=t,this.type="equalTo"}_apply(e){if(J("equalTo",this._value,e._path,!1),e._queryParams.hasStart())throw new Error("equalTo: Starting point was already set (by another call to startAt/startAfter or equalTo).");if(e._queryParams.hasEnd())throw new Error("equalTo: Ending point was already set (by another call to endAt/endBefore or equalTo).");return new tr(this._value,this._key)._apply(new nr(this._value,this._key)._apply(e))}}function gc(n,e){return st("equalTo","key",e),new La(n,e)}function yc(n,...e){let t=F(n);for(const i of e)t=i._apply(t);return t}kl(K);Ol(K);/** 1115 * @license 1116 * Copyright 2020 Google LLC 1117 * 1118 * Licensed under the Apache License, Version 2.0 (the "License"); 1119 * you may not use this file except in compliance with the License. 1120 * You may obtain a copy of the License at 1121 * 1122 * http://www.apache.org/licenses/LICENSE-2.0 1123 * 1124 * Unless required by applicable law or agreed to in writing, software 1125 * distributed under the License is distributed on an "AS IS" BASIS, 1126 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1127 * See the License for the specific language governing permissions and 1128 * limitations under the License. 1129 */const Fa="FIREBASE_DATABASE_EMULATOR_HOST",yn={};let ir=!1;function Wa(n,e,t,i){const s=e.lastIndexOf(":"),r=e.substring(0,s),o=Wi(r);n.repoInfo_=new is(e,o,n.repoInfo_.namespace,n.repoInfo_.webSocketOnly,n.repoInfo_.nodeAdmin,n.repoInfo_.persistenceKey,n.repoInfo_.includeNamespaceInQueryParams,!0,t),i&&(n.authTokenProvider_=i)}function sr(n,e,t,i,s){let r=i||n.options.databaseURL;r===void 0&&(n.options.projectId||X("Can't determine Firebase Database URL. Be sure to include a Project ID when calling firebase.initializeApp()."),A("Using default host for project ",n.options.projectId),r=`${n.options.projectId}-default-rtdb.firebaseio.com`);let o=gn(r,s),l=o.repoInfo,a,c;typeof process<"u"&&si&&(c=si[Fa]),c?(a=!0,r=`http://${c}?ns=${l.namespace}`,o=gn(r,s),l=o.repoInfo):a=!o.repoInfo.secure;const h=s&&a?new Se(Se.OWNER):new Gr(n.name,n.options,e);Hs("Invalid Firebase Database URL",o),y(o.path)||X("Database URL must point to the root of a Firebase Database (not including a child path).");const u=Ba(l,n,h,new Vr(n,t));return new Ga(u,n)}function Ua(n,e){const t=yn[e];(!t||t[n.key]!==n)&&X(`Database ${e}(${n.repoInfo_}) has already been deleted.`),zs(n),delete t[n.key]}function Ba(n,e,t,i){let s=yn[e.name];s||(s={},yn[e.name]=s);let r=s[n.toURLString()];return r&&X("Database initialized multiple times. Please make sure the format of the database URL matches with each database() call."),r=new la(n,ir,t,i),s[n.toURLString()]=r,r}function Va(n){ir=n}class Ga{constructor(e,t){this._repoInternal=e,this.app=t,this.type="database",this._instanceStarted=!1}get _repo(){return this._instanceStarted||(aa(this._repoInternal,this.app.options.appId,this.app.options.databaseAuthVariableOverride),this._instanceStarted=!0),this._repoInternal}get _root(){return this._rootInternal||(this._rootInternal=new K(this._repo,C())),this._rootInternal}_delete(){return this._rootInternal!==null&&(Ua(this._repo,this.app.name),this._repoInternal=null,this._rootInternal=null),Promise.resolve()}_checkNotDeleted(e){this._rootInternal===null&&X("Cannot call "+e+" on a deleted database.")}}
1129function rr(){Ne.IS_TRANSPORT_INITIALIZED&&O("Transport has already been initialized. Please call this function before calling ref or setting up a listener")}function vc(){rr(),te.forceDisallow()}function Cc(){rr(),V.forceDisallow(),te.forceAllow()}function Ec(n=lr(),e){const t=ur(n,"database").getImmediate({identifier:e});if(!t._instanceStarted){const i=dr("database");i&&Ha(t,...i)}return t}function Ha(n,e,t,i={}){n=F(n),n._checkNotDeleted("useEmulator");const s=`${e}:${t}`,r=n._repoInternal;if(n._instanceStarted){if(s===n._repoInternal.repoInfo_.host&&ar(i,r.repoInfo_.emulatorOptions))return;X("connectDatabaseEmulator() cannot initialize or alter the emulator configuration after the database instance has started.")}let o;if(r.repoInfo_.nodeAdmin)i.mockUserToken&&X('mockUserToken is not supported by the Admin SDK. For client access with mock users, please use the "firebase" package instead of "firebase-admin".'),o=new Se(Se.OWNER);else if(i.mockUserToken){const l=typeof i.mockUserToken=="string"?i.mockUserToken:cr(i.mockUserToken,n.app.options.projectId);o=new Se(l)}Wi(e)&&hr(e),Wa(r,s,i,o)}function wc(n){n=F(n),n._checkNotDeleted("goOffline"),zs(n._repo)}function Tc(n){n=F(n),n._checkNotDeleted("goOnline"),ga(n._repo)}function Ic(n,e){qi(n,e)}/** 1130 * @license 1131 * Copyright 2021 Google LLC 1132 * 1133 * Licensed under the Apache License, Version 2.0 (the "License"); 1134 * you may not use this file except in compliance with the License. 1135 * You may obtain a copy of the License at 1136 * 1137 * http://www.apache.org/licenses/LICENSE-2.0 1138 * 1139 * Unless required by applicable law or agreed to in writing, software 1140 * distributed under the License is distributed on an "AS IS" BASIS, 1141 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1142 * See the License for the specific language governing permissions and 1143 * limitations under the License. 1144 */function Qa(n){Vi(Rr),br(new Jt("database",(e,{instanceIdentifier:t})=>{const i=e.getProvider("app").getImmediate(),s=e.getProvider("auth-internal"),r=e.getProvider("app-check-internal");return sr(i,s,r,t)},"PUBLIC").setMultipleInstances(!0)),ii(ri,oi,n),ii(ri,oi,"esm2020")}/** 1145 * @license 1146 * Copyright 2020 Google LLC 1147 * 1148 * Licensed under the Apache License, Version 2.0 (the "License"); 1149 * you may not use this file except in compliance with the License. 1150 * You may obtain a copy of the License at 1151 * 1152 * http://www.apache.org/licenses/LICENSE-2.0 1153 * 1154 * Unless required by applicable law or agreed to in writing, software 1155 * distributed under the License is distributed on an "AS IS" BASIS, 1156 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1157 * See the License for the specific language governing permissions and 1158 * limitations under the License. 1159 */const qa={".sv":"timestamp"};function Sc(){return qa}function Nc(n){return{".sv":{increment:n}}}/** 1160 * @license 1161 * Copyright 2020 Google LLC 1162 * 1163 * Licensed under the Apache License, Version 2.0 (the "License"); 1164 * you may not use this file except in compliance with the License. 1165 * You may obtain a copy of the License at 1166 * 1167 * http://www.apache.org/licenses/LICENSE-2.0 1168 * 1169 * Unless required by applicable law or agreed to in writing, software 1170 * distributed under the License is distributed on an "AS IS" BASIS, 1171 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1172 * See the License for the specific language governing permissions and 1173 * limitations under the License. 1174 */class Ya{constructor(e,t){this.committed=e,this.snapshot=t}toJSON(){return{committed:this.committed,snapshot:this.snapshot.toJSON()}}}function Rc(n,e,t){if(n=F(n),j("Reference.transaction",n._path),n.key===".length"||n.key===".keys")throw"Reference.transaction failed: "+n.key+" is a read-only object.";const i=t?.applyLocally??!0,s=new B,r=(l,a,c)=>{let h=null;l?s.reject(l):(h=new ye(c,new K(n._repo,n._path),S),s.resolve(new Ya(a,h)))},o=Ra(n,()=>{});return ya(n._repo,n._path,e,r,o,i),s.promise}/** 1175 * @license 1176 * Copyright 2017 Google LLC 1177 * 1178 * Licensed under the Apache License, Version 2.0 (the "License"); 1179 * you may not use this file except in compliance with the License. 1180 * You may obtain a copy of the License at 1181 * 1182 * http://www.apache.org/licenses/LICENSE-2.0 1183 * 1184 * Unless required by applicable law or agreed to in writing, softw
1184are 1185 * distributed under the License is distributed on an "AS IS" BASIS, 1186 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1187 * See the License for the specific language governing permissions and 1188 * limitations under the License. 1189 */H.prototype.simpleListen=function(n,e){this.sendRequest("q",{p:n},e)};H.prototype.echo=function(n,e){this.sendRequest("echo",{d:n},e)};const bc=function(n){const e=H.prototype.put;return H.prototype.put=function(t,i,s,r){r!==void 0&&(r=n()),e.call(this,t,i,s,r)},function(){H.prototype.put=e}},kc=function(n){Va(n)};/** 1190 * @license 1191 * Copyright 2023 Google LLC 1192 * 1193 * Licensed under the Apache License, Version 2.0 (the "License"); 1194 * you may not use this file except in compliance with the License. 1195 * You may obtain a copy of the License at 1196 * 1197 * http://www.apache.org/licenses/LICENSE-2.0 1198 * 1199 * Unless required by applicable law or agreed to in writing, software 1200 * distributed under the License is distributed on an "AS IS" BASIS, 1201 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1202 * See the License for the specific language governing permissions and 1203 * limitations under the License. 1204 */function Pc({app:n,url:e,version:t,customAuthImpl:i,customAppCheckImpl:s,nodeAdmin:r=!1}){Vi(t);const o=new _r("database-standalone"),l=new ni("auth-internal",o);let a;return s&&(a=new ni("app-check-internal",o),a.setComponent(new Jt("app-check-internal",()=>s,"PRIVATE"))),l.setComponent(new Jt("auth-internal",()=>i,"PRIVATE")),sr(n,l,a,e,r)}Qa();export{ye as DataSnapshot,Ga as Database,Sa as OnDisconnect,z as QueryConstraint,Ya as TransactionResult,U as _QueryImpl,An as _QueryParams,K as _ReferenceImpl,kc as _TEST_ACCESS_forceRestClient,bc as _TEST_ACCESS_hijackHash,Pc as _initStandalone,sr as _repoManagerDatabaseFromApp,Vi as _setSDKVersion,$n as _validatePathString,j as _validateWritablePath,Ae as child,Ha as connectDatabaseEmulator,Ic as enableLogging,lc as endAt,ac as endBefore,gc as equalTo,Cc as forceLongPolling,vc as forceWebSockets,tc as get,Ec as getDatabase,wc as goOffline,Tc as goOnline,Nc as increment,uc as limitToFirst,dc as limitToLast,oc as off,nc as onChildAdded,ic as onChildChanged,sc as onChildMoved,rc as onChildRemoved,ja as onDisconnect,Ra as onValue,fc as orderByChild,_c as orderByKey,pc as orderByPriority,mc as orderByValue,$a as push,yc as query,Na as ref,za as refFromURL,Xa as remove,Rc as runTransaction,Sc as serverTimestamp,er as set,Ja as setPriority,Za as setWithPriority,hc as startAfter,cc as startAt,ec as update};
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.