whipdesk 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1144 @@
1
+ import{v as re,e as Ts,P as Ss,n as Ns,X as K,O as Rs,Y as _e,Z as f,B as Pt,L as bs,$ as ut,a0 as V,a1 as P,a2 as pe,a3 as $e,G as ks,a4 as Ps,a5 as xs,a6 as As,a7 as qe,a8 as Bt,j as Ds,M as Ms,r as Nn,u as Os,a9 as Ls,aa as Fs,H as ui,I as Ws,ab as Us,ac as qs,ad as Vs,S as Gs}from"./index.esm2017-B0pGzpCg.js";var Rn={};const bn="@firebase/database",kn="1.0.8";/**
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 di="";function Hs(n){di=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 Bs{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),P(t))}get(e){const t=this.domStorage_.getItem(this.prefixedName_(e));return t==null?null:Bt(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 Ys{constructor(){this.cache_={},this.isInMemoryStorage=!0}set(e,t){t==null?delete this.cache_[e]:this.cache_[e]=t}get(e){return V(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 fi=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 Bs(e)}}catch{}return new Ys},J=fi("localStorage"),Ks=fi("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 ue=new bs("@firebase/database"),Qs=function(){let n=1;return function(){return n++}}(),_i=function(n){const e=Ps(n),t=new xs;t.update(e);const i=t.digest();return As.encodeByteArray(i)},Ve=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+=Ve.apply(null,i):typeof i=="object"?e+=P(i):e+=i,e+=" "}return e};let Re=null,Pn=!0;const zs=function(n,e){f(!0,"Can't turn on custom loggers persistently."),ue.logLevel=ks.VERBOSE,Re=ue.log.bind(ue)},x=function(...n){if(Pn===!0&&(Pn=!1,Re===null&&Ks.get("logging_enabled")===!0&&zs()),Re){const e=Ve.apply(null,n);Re(e)}},Ge=function(n){return function(...e){x(n,...e)}},xt=function(...n){const e="FIREBASE INTERNAL ERROR: "+Ve(...n);ue.error(e)},B=function(...n){const e=`FIREBASE FATAL ERROR: ${Ve(...n)}`;throw ue.error(e),new Error(e)},L=function(...n){const e="FIREBASE WARNING: "+Ve(...n);ue.warn(e)},js=function(){typeof window<"u"&&window.location&&window.location.protocol&&window.location.protocol.indexOf("https:")!==-1&&L("Insecure Firebase access from a secure page. Please use https in calls to new Firebase().")},dt=function(n){return typeof n=="number"&&(n!==n||n===Number.POSITIVE_INFINITY||n===Number.NEGATIVE_INFINITY)},$s=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))}},ge="[MIN_NAME]",te="[MAX_NAME]",oe=function(n,e){if(n===e)return 0;if(n===ge||e===te)return-1;if(e===ge||n===te)return 1;{const t=xn(n),i=xn(e);return t!==null?i!==null?t-i===0?n.length-e.length:t-i:-1:i!==null?1:n<e?-1:1}},Xs=function(n,e){return n===e?0:n<e?-1:1},Ie=function(n,e){if(e&&n in e)return e[n];throw new Error("Missing required key ("+n+") in object: "+P(e))},Yt=function(n){if(typeof n!="object"||n===null)return P(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+=P(e[i]),t+=":",t+=Yt(n[e[i]]);return t+="}",t},pi=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 D(n,e){for(const t in n)n.hasOwnProperty(t)&&e(t,n[t])}const gi=function(n){f(!dt(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()},Js=function(){return!!(typeof window=="object"&&window.chrome&&window.chrome.extension&&!/^chrome/.test(window.location.href))},Zs=function(){return typeof Windows=="object"&&typeof Windows.UI=="object"};function er(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 tr=new RegExp("^-?(0*)\\d{1,10}$"),nr=-2147483648,ir=2147483647,xn=function(n){if(tr.test(n)){const e=Number(n);if(e>=nr&&e<=ir)return e}return null},Ce=function(n){try{n()}catch(e){setTimeout(()=>{const t=e.stack||"";throw L("Exception was thrown by user callback.",t),e},Math.floor(0))}},sr=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 rr{constructor(e,t){this.appName_=e,this.appCheckProvider=t,this.appCheck=t?.getImmediate({optional:!0}),this.appCheck||t?.get().then(i=>this.appCheck=i)}getToken(e){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){var t;(t=this.appCheckProvider)===null||t===void 0||t.get().then(i=>i.addTokenListener(e))}notifyForInvalidToken(){L(`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 or{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"?(x("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/.',L(e)}}class je{constructor(e){this.accessToken=e}getToken(e){return Promise.resolve({accessToken:this.accessToken})}addTokenChangeListener(e){e(this.accessToken)}removeTokenChangeListener(e){}notifyForInvalidToken(){}}je.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 Kt="5",mi="v",yi="s",vi="r",Ci="f",Ei=/(console\.firebase|firebase-console-\w+\.corp|firebase\.corp)\.google\.com/,wi="ls",Ii="p",At="ac",Ti="websocket",Si="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 Ni{constructor(e,t,i,s,r=!1,o="",l=!1,a=!1){this.secure=t,this.namespace=i,this.webSocketOnly=s,this.nodeAdmin=r,this.persistenceKey=o,this.includeNamespaceInQueryParams=l,this.isUsingEmulator=a,this._host=e.toLowerCase(),this._domain=this._host.substr(this._host.indexOf(".")+1),this.internalHost=J.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()&&J.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 lr(n){return n.host!==n.internalHost||n.isCustomHost()||n.includeNamespaceInQueryParams}function Ri(n,e,t){f(typeof e=="string","typeof type must == string"),f(typeof t=="object","typeof params must == object");let i;if(e===Ti)i=(n.secure?"wss://":"ws://")+n.internalHost+"/.ws?";else if(e===Si)i=(n.secure?"https://":"http://")+n.internalHost+"/.lp?";else throw new Error("Unknown connection type: "+e);lr(n)&&(t.ns=n.namespace);const s=[];return D(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 ar{constructor(){this.counters_={}}incrementCounter(e,t=1){V(this.counters_,e)||(this.counters_[e]=0),this.counters_[e]+=t}get(){return Us(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 It={},Tt={};function Qt(n){const e=n.toString();return It[e]||(It[e]=new ar),It[e]}function cr(n,e){const t=n.toString();return Tt[t]||(Tt[t]=e()),Tt[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 hr{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]&&Ce(()=>{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 An="start",ur="close",dr="pLPCommand",fr="pRTLPCB",bi="id",ki="pw",Pi="ser",_r="cb",pr="seg",gr="ts",mr="d",yr="dframe",xi=1870,Ai=30,vr=xi-Ai,Cr=25e3,Er=3e4;class he{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_=Ge(e),this.stats_=Qt(t),this.urlFn=a=>(this.appCheckToken&&(a[At]=this.appCheckToken),Ri(t,Si,a))}open(e,t){this.curSegmentNum=0,this.onDisconnect_=t,this.myPacketOrderer=new hr(e),this.isClosed_=!1,this.connectTimeoutTimer_=setTimeout(()=>{this.log_("Timed out trying to connect."),this.onClosed_(),this.connectTimeoutTimer_=null},Math.floor(Er)),$s(()=>{if(this.isClosed_)return;this.scriptTagHolder=new zt((...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===An)this.id=l,this.password=a;else if(o===ur)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[An]="t",i[Pi]=Math.floor(Math.random()*1e8),this.scriptTagHolder.uniqueCallbackIdentifier&&(i[_r]=this.scriptTagHolder.uniqueCallbackIdentifier),i[mi]=Kt,this.transportSessionId&&(i[yi]=this.transportSessionId),this.lastSessionId&&(i[wi]=this.lastSessionId),this.applicationId&&(i[Ii]=this.applicationId),this.appCheckToken&&(i[At]=this.appCheckToken),typeof location<"u"&&location.hostname&&Ei.test(location.hostname)&&(i[vi]=Ci);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(){he.forceAllow_=!0}static forceDisallow(){he.forceDisallow_=!0}static isAvailable(){return he.forceAllow_?!0:!he.forceDisallow_&&typeof document<"u"&&document.createElement!=null&&!Js()&&!Zs()}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=P(e);this.bytesSent+=t.length,this.stats_.incrementCounter("bytes_sent",t.length);const i=qs(t),s=pi(i,vr);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[yr]="t",i[bi]=e,i[ki]=t,this.myDisconnFrame.src=this.urlFn(i),this.myDisconnFrame.style.display="none",document.body.appendChild(this.myDisconnFrame)}incrementIncomingBytes_(e){const t=P(e).length;this.bytesReceived+=t,this.stats_.incrementCounter("bytes_received",t)}}class zt{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=Qs(),window[dr+this.uniqueCallbackIdentifier]=e,window[fr+this.uniqueCallbackIdentifier]=t,this.myIFrame=zt.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>";try{this.myIFrame.doc.open(),this.myIFrame.doc.write(o),this.myIFrame.doc.close()}catch(l){x("frame writing exception"),l.stack&&x(l.stack),x(l)}}}static createIFrame_(){const e=document.createElement("iframe");if(e.style.display="none",document.body){document.body.appendChild(e);try{e.contentWindow.document||x("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[bi]=this.myID,e[ki]=this.myPW,e[Pi]=this.currentSerial;let t=this.urlFn(e),i="",s=0;for(;this.pendingSegs.length>0&&this.pendingSegs[0].d.length+Ai+i.length<=xi;){const o=this.pendingSegs.shift();i=i+"&"+pr+s+"="+o.seg+"&"+gr+s+"="+o.ts+"&"+mr+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(Cr)),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=()=>{x("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 wr=16384,Ir=45e3;let Xe=null;typeof MozWebSocket<"u"?Xe=MozWebSocket:typeof WebSocket<"u"&&(Xe=WebSocket);class W{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_=Ge(this.connId),this.stats_=Qt(t),this.connURL=W.connectionURL_(t,o,l,s,i),this.nodeAdmin=t.nodeAdmin}static connectionURL_(e,t,i,s,r){const o={};return o[mi]=Kt,typeof location<"u"&&location.hostname&&Ei.test(location.hostname)&&(o[vi]=Ci),t&&(o[yi]=t),i&&(o[wi]=i),s&&(o[At]=s),r&&(o[Ii]=r),Ri(e,Ti,o)}open(e,t){this.onDisconnect=t,this.onMessage=e,this.log_("Websocket connecting to "+this.connURL),this.everConnected_=!1,J.set("previous_websocket_failure",!0);try{let i;Vs(),this.mySock=new Xe(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(){W.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&&Xe!==null&&!W.forceDisallow_}static previouslyFailed(){return J.isInMemoryStorage||J.get("previous_websocket_failure")===!0}markConnectionHealthy(){J.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=Bt(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=P(e);this.bytesSent+=t.length,this.stats_.incrementCounter("bytes_sent",t.length);const i=pi(t,wr);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(Ir))}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)}}}W.responsesRequiredToBeHealthy=2;W.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 Ae{constructor(e){this.initTransports_(e)}static get ALL_TRANSPORTS(){return[he,W]}static get IS_TRANSPORT_INITIALIZED(){return this.globalTransportInitialized_}initTransports_(e){const t=W&&W.isAvailable();let i=t&&!W.previouslyFailed();if(e.webSocketOnly&&(t||L("wss:// URL used, but browser isn't known to support websockets. Trying anyway."),i=!0),i)this.transports_=[W];else{const s=this.transports_=[];for(const r of Ae.ALL_TRANSPORTS)r&&r.isAvailable()&&s.push(r);Ae.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}}Ae.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 Tr=6e4,Sr=5e3,Nr=10*1024,Rr=100*1024,St="t",Dn="d",br="s",Mn="r",kr="e",On="o",Ln="a",Fn="n",Wn="p",Pr="h";class xr{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_=Ge("c:"+this.id+":"),this.transportManager_=new Ae(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>Rr?(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>Nr?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(St in e){const t=e[St];t===Ln?this.upgradeIfSecondaryHealthy_():t===Mn?(this.log_("Got a reset on secondary, closing it"),this.secondaryConn_.close(),(this.tx_===this.secondaryConn_||this.rx_===this.secondaryConn_)&&this.close()):t===On&&(this.log_("got pong on secondary."),this.secondaryResponsesRequired_--,this.upgradeIfSecondaryHealthy_())}}onSecondaryMessageReceived_(e){const t=Ie("t",e),i=Ie("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:"c",d:{t:Wn,d:{}}}))}proceedWithUpgrade_(){this.secondaryConn_.start(),this.log_("sending client ack on secondary"),this.secondaryConn_.send({t:"c",d:{t:Ln,d:{}}}),this.log_("Ending transmission on primary"),this.conn_.send({t:"c",d:{t:Fn,d:{}}}),this.tx_=this.secondaryConn_,this.tryCleanupConnection()}onPrimaryMessageReceived_(e){const t=Ie("t",e),i=Ie("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=Ie(St,e);if(Dn in e){const i=e[Dn];if(t===Pr){const s=Object.assign({},i);this.repoInfo_.isUsingEmulator&&(s.h=this.repoInfo_.host),this.onHandshake_(s)}else if(t===Fn){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===br?this.onConnectionShutdown_(i):t===Mn?this.onReset_(i):t===kr?xt("Server Error: "+i):t===On?(this.log_("got pong on primary."),this.onPrimaryResponse_(),this.sendPingOnPrimaryIfNecessary_()):xt("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),Kt!==i&&L("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(Tr))}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(Sr))}sendPingOnPrimaryIfNecessary_(){!this.isHealthy_&&this.state_===1&&(this.log_("sending ping on primary."),this.sendData_({t:"c",d:{t:Wn,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()&&(J.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, software
252
+ * distributed under the License is distributed on an "AS IS" BASIS,
253
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
254
+ * See the License for the specific language governing permissions and
255
+ * limitations under the License.
256
+ */class Di{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 Mi{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 Je extends Mi{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))}static getInstance(){return new Je}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 Un=32,qn=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 m(n){return n.pieceNum_>=n.pieces_.length?null:n.pieces_[n.pieceNum_]}function z(n){return n.pieces_.length-n.pieceNum_}function I(n){let e=n.pieceNum_;return e<n.pieces_.length&&e++,new E(n.pieces_,e)}function jt(n){return n.pieceNum_<n.pieces_.length?n.pieces_[n.pieces_.length-1]:null}function Ar(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 De(n,e=0){return n.pieces_.slice(n.pieceNum_+e)}function Oi(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=m(n),i=m(e);if(t===null)return e;if(t===i)return M(I(n),I(e));throw new Error("INTERNAL ERROR: innerPath ("+e+") is not within outerPath ("+n+")")}function Dr(n,e){const t=De(n,0),i=De(e,0);for(let s=0;s<t.length&&s<i.length;s++){const r=oe(t[s],i[s]);if(r!==0)return r}return t.length===i.length?0:t.length<i.length?-1:1}function $t(n,e){if(z(n)!==z(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 F(n,e){let t=n.pieceNum_,i=e.pieceNum_;if(z(n)>z(e))return!1;for(;t<n.pieces_.length;){if(n.pieces_[t]!==e.pieces_[i])return!1;++t,++i}return!0}class Mr{constructor(e,t){this.errorPrefix_=t,this.parts_=De(e,0),this.byteLength_=Math.max(1,this.parts_.length);for(let i=0;i<this.parts_.length;i++)this.byteLength_+=ut(this.parts_[i]);Li(this)}}function Or(n,e){n.parts_.length>0&&(n.byteLength_+=1),n.parts_.push(e),n.byteLength_+=ut(e),Li(n)}function Lr(n){const e=n.parts_.pop();n.byteLength_-=ut(e),n.parts_.length>0&&(n.byteLength_-=1)}function Li(n){if(n.byteLength_>qn)throw new Error(n.errorPrefix_+"has a key path longer than "+qn+" bytes ("+n.byteLength_+").");if(n.parts_.length>Un)throw new Error(n.errorPrefix_+"path specified exceeds the maximum depth that can be written ("+Un+") or object contains a cycle "+X(n))}function X(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 Xt extends Mi{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)}static getInstance(){return new Xt}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 Te=1e3,Fr=60*5*1e3,Vn=30*1e3,Wr=1.3,Ur=3e4,qr="server_kill",Gn=3;class H extends Di{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_=Ge("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_=Te,this.maxReconnectDelay_=Fr,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");Xt.getInstance().on("visible",this.onVisible_,this),e.host.indexOf("fblocal")===-1&&Je.getInstance().on("online",this.onOnline_,this)}sendRequest(e,t,i){const s=++this.requestNumber_,r={r:s,a:e,b:t};this.log_(P(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 K,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"&&V(e,"w")){const i=pe(e,"w");if(Array.isArray(i)&&~i.indexOf("no_index")){const s='".indexOn": "'+t._queryParams.getIndex().toString()+'"',r=t._path.toString();L(`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||Ls(e))&&(this.log_("Admin auth credential detected. Reducing max reconnect time."),this.maxReconnectDelay_=Vn)}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=Fs(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: "+P(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):xt("Unrecognized action received from server: "+P(e)+`
332
+ Are 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_=Te,this.realtime_||this.scheduleConnect_(0)),this.visible_=e}onOnline_(e){e?(this.log_("Browser went online."),this.reconnectDelay_=Te,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_>Ur&&(this.reconnectDelay_=Te),this.lastConnectionEstablishedTime_=null):(this.log_("Window isn't visible. Delaying reconnect."),this.reconnectDelay_=this.maxReconnectDelay_,this.lastConnectionAttemptTime_=new Date().getTime());const e=new Date().getTime()-this.lastConnectionAttemptTime_;let t=Math.max(0,this.reconnectDelay_-e);t=Math.random()*t,this.log_("Trying to reconnect in "+t+"ms"),this.scheduleConnect_(t),this.reconnectDelay_=Math.min(this.maxReconnectDelay_,this.reconnectDelay_*Wr)}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?x("getToken() completed but was canceled"):(x("getToken() completed. Creating connection."),this.authToken_=u&&u.accessToken,this.appCheckToken_=d&&d.token,l=new xr(s,this.repoInfo_,this.applicationId_,this.appCheckToken_,this.authToken_,e,t,i,_=>{L(_+" ("+this.repoInfo_.toString()+")"),this.interrupt(qr)},r))}catch(u){this.log_("Failed to get token: "+u),o||(this.repoInfo_.nodeAdmin&&L(u),a())}}}interrupt(e){x("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){x("Resuming connection for reason: "+e),delete this.interruptReasons_[e],Pt(this.interruptReasons_)&&(this.reconnectDelay_=Te,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=>Yt(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){x("Auth token revoked: "+e+"/"+t),this.authToken_=null,this.forceTokenRefresh_=!0,this.realtime_.close(),(e==="invalid_token"||e==="permission_denied")&&(this.invalidAuthTokenCount_++,this.invalidAuthTokenCount_>=Gn&&(this.reconnectDelay_=Vn,this.authTokenProvider_.notifyForInvalidToken()))}onAppCheckRevoked_(e,t){x("App check token revoked: "+e+"/"+t),this.appCheckToken_=null,this.forceTokenRefresh_=!0,(e==="invalid_token"||e==="permission_denied")&&(this.invalidAppCheckTokenCount_++,this.invalidAppCheckTokenCount_>=Gn&&this.appCheckTokenProvider_.notifyForInvalidToken())}onSecurityDebugPacket_(e){this.securityDebugCallback_?this.securityDebugCallback_(e):"msg"in e&&console.log("FIREBASE: "+e.msg.replace(`
333
+ `,`
334
+ FIREBASE: `))}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+"."+di.replace(/\./g,"-")]=1,ui()?e["framework.cordova"]=1:Ws()&&(e["framework.reactnative"]=1),this.reportStats(e)}shouldReconnect_(){const e=Je.getInstance().currentlyOnline();return Pt(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 ft{getCompare(){return this.compare.bind(this)}indexedValueChanged(e,t){const i=new v(ge,e),s=new v(ge,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 Qe;class Fi extends ft{static get __EMPTY_NODE(){return Qe}static set __EMPTY_NODE(e){Qe=e}compare(e,t){return oe(e.name,t.name)}isDefinedOn(e){throw qe("KeyIndex.isDefinedOn not expected to be called.")}indexedValueChanged(e,t){return!1}minPost(){return v.MIN}maxPost(){return new v(te,Qe)}makePost(e,t){return f(typeof e=="string","KeyIndex indexValue must always be a string."),new v(e,Qe)}toString(){return".key"}}const de=new Fi;/**
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 ze{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 k{constructor(e,t,i,s,r){this.key=e,this.value=t,this.color=i??k.RED,this.left=s??O.EMPTY_NODE,this.right=r??O.EMPTY_NODE}copy(e,t,i,s,r){return new k(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_()}removeMin_(){if(this.left.isEmpty())return O.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 O.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,k.RED,null,this.right.left);return this.right.copy(null,null,this.color,e,null)}rotateRight_(){const e=this.copy(null,null,k.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+")");if(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)}}k.RED=!0;k.BLACK=!1;class Vr{copy(e,t,i,s,r){return this}insert(e,t,i){return new k(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 O{constructor(e,t=O.EMPTY_NODE){this.comparator_=e,this.root_=t}insert(e,t){return new O(this.comparator_,this.root_.insert(e,t,this.comparator_).copy(null,null,k.BLACK,null,null))}remove(e){return new O(this.comparator_,this.root_.remove(e,this.comparator_).copy(null,null,k.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 ze(this.root_,null,this.comparator_,!1,e)}getIteratorFrom(e,t){return new ze(this.root_,e,this.comparator_,!1,t)}getReverseIteratorFrom(e,t){return new ze(this.root_,e,this.comparator_,!0,t)}getReverseIterator(e){return new ze(this.root_,null,this.comparator_,!0,e)}}O.EMPTY_NODE=new Vr;/**
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 Gr(n,e){return oe(n.name,e.name)}function Jt(n,e){return oe(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 Dt;function Hr(n){Dt=n}const Wi=function(n){return typeof n=="number"?"number:"+gi(n):"string:"+n},Ui=function(n){if(n.isLeafNode()){const e=n.val();f(typeof e=="string"||typeof e=="number"||typeof e=="object"&&V(e,".sv"),"Priority must be a string or number.")}else f(n===Dt||n.isEmpty(),"priority of unexpected type.");f(n===Dt||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 Hn;class b{constructor(e,t=b.__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."),Ui(this.priorityNode_)}static set __childrenNodeConstructor(e){Hn=e}static get __childrenNodeConstructor(){return Hn}isLeafNode(){return!0}getPriority(){return this.priorityNode_}updatePriority(e){return new b(this.value_,e)}getImmediateChild(e){return e===".priority"?this.priorityNode_:b.__childrenNodeConstructor.EMPTY_NODE}getChild(e){return y(e)?this:m(e)===".priority"?this.priorityNode_:b.__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:b.__childrenNodeConstructor.EMPTY_NODE.updateImmediateChild(e,t).updatePriority(this.priorityNode_)}updateChild(e,t){const i=m(e);return i===null?t:t.isEmpty()&&i!==".priority"?this:(f(i!==".priority"||z(e)===1,".priority must be the last token in a path"),this.updateImmediateChild(i,b.__childrenNodeConstructor.EMPTY_NODE.updateChild(I(e),t)))}isEmpty(){return!1}numChildren(){return 0}forEachChild(e,t){return!1}val(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:"+Wi(this.priorityNode_.val())+":");const t=typeof this.value_;e+=t+":",t==="number"?e+=gi(this.value_):e+=this.value_,this.lazyHash_=_i(e)}return this.lazyHash_}getValue(){return this.value_}compareTo(e){return e===b.__childrenNodeConstructor.EMPTY_NODE?1:e instanceof b.__childrenNodeConstructor?-1:(f(e.isLeafNode(),"Unknown node type"),this.compareToLeafNode_(e))}compareToLeafNode_(e){const t=typeof e.value_,i=typeof this.value_,s=b.VALUE_TYPE_ORDER.indexOf(t),r=b.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}}b.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 qi,Vi;function Br(n){qi=n}function Yr(n){Vi=n}class Kr extends ft{compare(e,t){const i=e.node.getPriority(),s=t.node.getPriority(),r=i.compareTo(s);return r===0?oe(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(te,new b("[PRIORITY-POST]",Vi))}makePost(e,t){const i=qi(e);return new v(t,new b("[PRIORITY-POST]",i))}toString(){return".priority"}}const S=new Kr;/**
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 Qr=Math.log(2);class zr{constructor(e){const t=r=>parseInt(Math.log(r)/Qr,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 Ze=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 k(d,u.node,k.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 k(d,u.node,k.BLACK,p,w)}},r=function(a){let c=null,h=null,u=n.length;const d=function(p,w){const A=u-p,ae=u;u-=p;const Ke=s(A+1,ae),wt=n[A],Is=t?t(wt):wt;_(new k(Is,wt.node,w,null,Ke))},_=function(p){c?(c.left=p,c=p):(h=p,c=p)};for(let p=0;p<a.count;++p){const w=a.nextBitIsOne(),A=Math.pow(2,a.count-(p+1));w?d(A,k.BLACK):(d(A,k.BLACK),d(A,k.RED))}return h},o=new zr(n.length),l=r(o);return new O(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, software
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 Nt;const ce={};class G{constructor(e,t){this.indexes_=e,this.indexSet_=t}static get Default(){return f(ce&&S,"ChildrenNode.ts has not been loaded"),Nt=Nt||new G({".priority":ce},{".priority":S}),Nt}get(e){const t=pe(this.indexes_,e);if(!t)throw new Error("No index defined for "+e);return t instanceof O?t:null}hasIndex(e){return V(this.indexSet_,e.toString())}addIndex(e,t){f(e!==de,"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=Ze(i,e.getCompare()):l=ce;const a=e.toString(),c=Object.assign({},this.indexSet_);c[a]=e;const h=Object.assign({},this.indexes_);return h[a]=l,new G(h,c)}addToIndexes(e,t){const i=$e(this.indexes_,(s,r)=>{const o=pe(this.indexSet_,r);if(f(o,"Missing index implementation for "+r),s===ce)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),Ze(l,o.getCompare())}else return ce;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 G(i,this.indexSet_)}removeFromIndexes(e,t){const i=$e(this.indexes_,s=>{if(s===ce)return s;{const r=t.get(e.name);return r?s.remove(new v(e.name,r)):s}});return new G(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 Se;class g{constructor(e,t,i){this.children_=e,this.priorityNode_=t,this.indexMap_=i,this.lazyHash_=null,this.priorityNode_&&Ui(this.priorityNode_),this.children_.isEmpty()&&f(!this.priorityNode_||this.priorityNode_.isEmpty(),"An empty node cannot have a priority")}static get EMPTY_NODE(){return Se||(Se=new g(new O(Jt),null,G.Default))}isLeafNode(){return!1}getPriority(){return this.priorityNode_||Se}updatePriority(e){return this.children_.isEmpty()?this:new g(this.children_,e,this.indexMap_)}getImmediateChild(e){if(e===".priority")return this.getPriority();{const t=this.children_.get(e);return t===null?Se:t}}getChild(e){const t=m(e);return t===null?this:this.getImmediateChild(t).getChild(I(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()?Se:this.priorityNode_;return new g(s,o,r)}}updateChild(e,t){const i=m(e);if(i===null)return t;{f(m(e)!==".priority"||z(e)===1,".priority must be the last token in a path");const s=this.getImmediateChild(i).updateChild(I(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&&g.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:"+Wi(this.getPriority().val())+":"),this.forEachChild(S,(t,i)=>{const s=i.hash();s!==""&&(e+=":"+t+":"+s)}),this.lazyHash_=e===""?"":_i(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===He?-1:0}withIndex(e){if(e===de||this.indexMap_.hasIndex(e))return this;{const t=this.indexMap_.addIndex(e,this.children_);return new g(this.children_,this.priorityNode_,t)}}isIndexed(e){return e===de||this.indexMap_.hasIndex(e)}equals(e){if(e===this)return!0;if(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===de?null:this.indexMap_.get(e.toString())}}g.INTEGER_REGEXP_=/^(0|[1-9]\d*)$/;class jr extends g{constructor(){super(new O(Jt),g.EMPTY_NODE,G.Default)}compareTo(e){return e===this?0:1}equals(e){return e===this}getPriority(){return this}getImmediateChild(e){return g.EMPTY_NODE}isEmpty(){return!1}}const He=new jr;Object.defineProperties(v,{MIN:{value:new v(ge,g.EMPTY_NODE)},MAX:{value:new v(te,He)}});Fi.__EMPTY_NODE=g.EMPTY_NODE;b.__childrenNodeConstructor=g;Hr(He);Yr(He);/**
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 $r=!0;function R(n,e=null){if(n===null)return g.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 b(t,R(e))}if(!(n instanceof Array)&&$r){const t=[];let i=!1;if(D(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 g.EMPTY_NODE;const r=Ze(t,Gr,o=>o.name,Jt);if(i){const o=Ze(t,S.getCompare());return new g(r,R(e),new G({".priority":o},{".priority":S}))}else return new g(r,R(e),G.Default)}else{let t=g.EMPTY_NODE;return D(n,(i,s)=>{if(V(n,i)&&i.substring(0,1)!=="."){const r=R(s);(r.isLeafNode()||!r.isEmpty())&&(t=t.updateImmediateChild(i,r))}}),t.updatePriority(R(e))}}Br(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 Xr extends ft{constructor(e){super(),this.indexPath_=e,f(!y(e)&&m(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?oe(e.name,t.name):r}makePost(e,t){const i=R(e),s=g.EMPTY_NODE.updateChild(this.indexPath_,i);return new v(t,s)}maxPost(){const e=g.EMPTY_NODE.updateChild(this.indexPath_,He);return new v(te,e)}toString(){return De(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 Jr extends ft{compare(e,t){const i=e.node.compareTo(t.node);return i===0?oe(e.name,t.name):i}isDefinedOn(e){return!0}indexedValueChanged(e,t){return!e.equals(t)}minPost(){return v.MIN}maxPost(){return v.MAX}makePost(e,t){const i=R(e);return new v(t,i)}toString(){return".value"}}const Zr=new Jr;/**
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 Gi(n){return{type:"value",snapshotNode:n}}function me(n,e){return{type:"child_added",snapshotNode:e,childName:n}}function Me(n,e){return{type:"child_removed",snapshotNode:e,childName:n}}function Oe(n,e,t){return{type:"child_changed",snapshotNode:e,childName:n,oldSnap:t}}function eo(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 Zt{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(Me(t,l)):f(e.isLeafNode(),"A child remove without an old child only makes sense on a leaf node"):l.isEmpty()?o.trackChildChange(me(t,i)):o.trackChildChange(Oe(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(Me(s,r))}),t.isLeafNode()||t.forEachChild(S,(s,r)=>{if(e.hasChild(s)){const o=e.getImmediateChild(s);o.equals(r)||i.trackChildChange(Oe(s,r,o))}else i.trackChildChange(me(s,r))})),t.withIndex(this.index_)}updatePriority(e,t){return e.isEmpty()?g.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 Le{constructor(e){this.indexedFilter_=new Zt(e.getIndex()),this.index_=e.getIndex(),this.startPost_=Le.getStartPost_(e),this.endPost_=Le.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=g.EMPTY_NODE),this.indexedFilter_.updateChild(e,t,i,s,r,o)}updateFullNode(e,t,i){t.isLeafNode()&&(t=g.EMPTY_NODE);let s=t.withIndex(this.index_);s=s.updatePriority(g.EMPTY_NODE);const r=this;return t.forEachChild(S,(o,l)=>{r.matches(new v(o,l))||(s=s.updateImmediateChild(o,g.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 to{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 Le(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=g.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=g.EMPTY_NODE.withIndex(this.index_);else if(this.limit_*2<t.numChildren()&&t.isIndexed(this.index_)){s=g.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(g.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,g.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(Oe(t,i,u)),l.updateImmediateChild(t,i);{r?.trackChildChange(Me(t,u));const w=l.updateImmediateChild(t,g.EMPTY_NODE);return d!=null&&this.rangedFilter_.matches(d)?(r?.trackChildChange(me(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(Me(c.name,c.node)),r.trackChildChange(me(t,i))),l.updateImmediateChild(t,i).updateImmediateChild(c.name,g.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 en{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_:ge}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_:te}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 en;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 no(n){return n.loadsAllData()?new Zt(n.getIndex()):n.hasLimit()?new to(n):new Le(n)}function Bn(n){const e={};if(n.isDefault())return e;let t;if(n.index_===S?t="$priority":n.index_===Zr?t="$value":n.index_===de?t="$key":(f(n.index_ instanceof Xr,"Unrecognized index type!"),t=n.index_.toString()),e.orderBy=P(t),n.startSet_){const i=n.startAfterSet_?"startAfter":"startAt";e[i]=P(n.indexStartValue_),n.startNameSet_&&(e[i]+=","+P(n.indexStartName_))}if(n.endSet_){const i=n.endBeforeSet_?"endBefore":"endAt";e[i]=P(n.indexEndValue_),n.endNameSet_&&(e[i]+=","+P(n.indexEndName_))}return n.limitSet_&&(n.isViewFromLeft()?e.limitToFirst=n.limit_:e.limitToLast=n.limit_),e}function Yn(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 et extends Di{constructor(e,t,i,s){super(),this.repoInfo_=e,this.onDataUpdate_=t,this.authTokenProvider_=i,this.appCheckTokenProvider_=s,this.log_=Ge("p:rest:"),this.listens_={}}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())}listen(e,t,i,s){const r=e._path.toString();this.log_("Listen called for "+r+" "+e._queryIdentifier);const o=et.getListenId_(e,i),l={};this.listens_[o]=l;const a=Bn(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=et.getListenId_(e,t);delete this.listens_[i]}get(e){const t=Bn(e._queryParams),i=e._path.toString(),s=new K;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+Os(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=Bt(l.responseText)}catch{L("Failed to parse JSON response for "+o+": "+l.responseText)}i(null,a)}else l.status!==401&&l.status!==404&&L("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 io{constructor(){this.rootNode_=g.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 tt(){return{value:null,children:new Map}}function Ee(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=m(e);n.children.has(i)||n.children.set(i,tt());const s=n.children.get(i);e=I(e),Ee(s,e,t)}}function Mt(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)=>{Ee(n,new E(i),s)}),Mt(n,e)}}else if(n.children.size>0){const t=m(e);return e=I(e),n.children.has(t)&&Mt(n.children.get(t),e)&&n.children.delete(t),n.children.size===0}else return!0}function Ot(n,e,t){n.value!==null?t(e,n.value):so(n,(i,s)=>{const r=new E(e.toString()+"/"+i);Ot(s,r,t)})}function so(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 ro{constructor(e){this.collection_=e,this.last_=null}get(){const e=this.collection_.get(),t=Object.assign({},e);return this.last_&&D(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 Kn=10*1e3,oo=30*1e3,lo=5*60*1e3;class ao{constructor(e,t){this.server_=t,this.statsToReport_={},this.statsListener_=new ro(e);const i=Kn+(oo-Kn)*Math.random();be(this.reportStats_.bind(this),Math.floor(i))}reportStats_(){const e=this.statsListener_.get(),t={};let i=!1;D(e,(s,r)=>{r>0&&V(this.statsToReport_,s)&&(t[s]=r,i=!0)}),i&&this.server_.reportStats(t),be(this.reportStats_.bind(this),Math.floor(Math.random()*2*lo))}}/**
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 U;(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"})(U||(U={}));function Hi(){return{fromUser:!0,fromServer:!1,queryId:null,tagged:!1}}function tn(){return{fromUser:!1,fromServer:!0,queryId:null,tagged:!1}}function nn(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 nt{constructor(e,t,i){this.path=e,this.affectedTree=t,this.revert=i,this.type=U.ACK_USER_WRITE,this.source=Hi()}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 nt(C(),t,this.revert)}}else return f(m(this.path)===e,"operationForChild called for unrelated child."),new nt(I(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 Fe{constructor(e,t){this.source=e,this.path=t,this.type=U.LISTEN_COMPLETE}operationForChild(e){return y(this.path)?new Fe(this.source,C()):new Fe(this.source,I(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 ne{constructor(e,t,i){this.source=e,this.path=t,this.snap=i,this.type=U.OVERWRITE}operationForChild(e){return y(this.path)?new ne(this.source,C(),this.snap.getImmediateChild(e)):new ne(this.source,I(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 We{constructor(e,t,i){this.source=e,this.path=t,this.children=i,this.type=U.MERGE}operationForChild(e){if(y(this.path)){const t=this.children.subtree(new E(e));return t.isEmpty()?null:t.value?new ne(this.source,C(),t.value):new We(this.source,C(),t)}else return f(m(this.path)===e,"Can't get a merge for a child not on the path of the operation"),new We(this.source,I(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 ie{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=m(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 co{constructor(e){this.query_=e,this.index_=this.query_._queryParams.getIndex()}}function ho(n,e,t,i){const s=[],r=[];return e.forEach(o=>{o.type==="child_changed"&&n.index_.indexedValueChanged(o.oldSnap,o.snapshotNode)&&r.push(eo(o.childName,o.snapshotNode))}),Ne(n,s,"child_removed",e,i,t),Ne(n,s,"child_added",e,i,t),Ne(n,s,"child_moved",r,i,t),Ne(n,s,"child_changed",e,i,t),Ne(n,s,"value",e,i,t),s}function Ne(n,e,t,i,s,r){const o=i.filter(l=>l.type===t);o.sort((l,a)=>fo(n,l,a)),o.forEach(l=>{const a=uo(n,l,r);s.forEach(c=>{c.respondsTo(l.type)&&e.push(c.createEvent(a,n.query_))})})}function uo(n,e,t){return e.type==="value"||e.type==="child_removed"||(e.prevName=t.getPredecessorChildName(e.childName,e.snapshotNode,n.index_)),e}function fo(n,e,t){if(e.childName==null||t.childName==null)throw qe("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 _t(n,e){return{eventCache:n,serverCache:e}}function ke(n,e,t,i){return _t(new ie(e,t,i),n.serverCache)}function Bi(n,e,t,i){return _t(n.eventCache,new ie(e,t,i))}function Lt(n){return n.eventCache.isFullyInitialized()?n.eventCache.getNode():null}function se(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 Rt;const _o=()=>(Rt||(Rt=new O(Xs)),Rt);class T{constructor(e,t=_o()){this.value=e,this.children=t}static fromObject(e){let t=new T(null);return D(e,(i,s)=>{t=t.set(new E(i),s)}),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=m(e),s=this.children.get(i);if(s!==null){const r=s.findRootMostMatchingPathAndValue(I(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=m(e),i=this.children.get(t);return i!==null?i.subtree(I(e)):new T(null)}}set(e,t){if(y(e))return new T(t,this.children);{const i=m(e),r=(this.children.get(i)||new T(null)).set(I(e),t),o=this.children.insert(i,r);return new T(this.value,o)}}remove(e){if(y(e))return this.children.isEmpty()?new T(null):new T(null,this.children);{const t=m(e),i=this.children.get(t);if(i){const s=i.remove(I(e));let r;return s.isEmpty()?r=this.children.remove(t):r=this.children.insert(t,s),this.value===null&&r.isEmpty()?new T(null):new T(this.value,r)}else return this}}get(e){if(y(e))return this.value;{const t=m(e),i=this.children.get(t);return i?i.get(I(e)):null}}setTree(e,t){if(y(e))return t;{const i=m(e),r=(this.children.get(i)||new T(null)).setTree(I(e),t);let o;return r.isEmpty()?o=this.children.remove(i):o=this.children.insert(i,r),new T(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=m(e),o=this.children.get(r);return o?o.findOnPath_(I(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=m(e),r=this.children.get(s);return r?r.foreachOnPath_(I(e),N(t,s),i):new T(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 T(null))}}function Pe(n,e,t){if(y(e))return new q(new T(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 T(t),r=n.writeTree_.setTree(e,s);return new q(r)}}}function Qn(n,e,t){let i=n;return D(t,(s,r)=>{i=Pe(i,N(e,s),r)}),i}function zn(n,e){if(y(e))return q.empty();{const t=n.writeTree_.setTree(e,new T(null));return new q(t)}}function Ft(n,e){return le(n,e)!=null}function le(n,e){const t=n.writeTree_.findRootMostValueAndPath(e);return t!=null?n.writeTree_.get(t.path).getChild(M(t.path,e)):null}function jn(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 Q(n,e){if(y(e))return n;{const t=le(n,e);return t!=null?new q(new T(t)):new q(n.writeTree_.subtree(e))}}function Wt(n){return n.writeTree_.isEmpty()}function ye(n,e){return Yi(C(),n.writeTree_,e)}function Yi(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=Yi(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 sn(n,e){return ji(e,n)}function po(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=Pe(n.visibleWrites,e,t)),n.lastWriteId=i}function go(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 mo(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&&yo(l,i.path)?s=!1:F(i.path,l.path)&&(r=!0)),o--}if(s){if(r)return vo(n),!0;if(i.snap)n.visibleWrites=zn(n.visibleWrites,i.path);else{const l=i.children;D(l,a=>{n.visibleWrites=zn(n.visibleWrites,N(i.path,a))})}return!0}else return!1}function yo(n,e){if(n.snap)return F(n.path,e);for(const t in n.children)if(n.children.hasOwnProperty(t)&&F(N(n.path,t),e))return!0;return!1}function vo(n){n.visibleWrites=Ki(n.allWrites,Co,C()),n.allWrites.length>0?n.lastWriteId=n.allWrites[n.allWrites.length-1].writeId:n.lastWriteId=-1}function Co(n){return n.visible}function Ki(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)F(t,o)?(l=M(t,o),i=Pe(i,l,r.snap)):F(o,t)&&(l=M(o,t),i=Pe(i,C(),r.snap.getChild(l)));else if(r.children){if(F(t,o))l=M(t,o),i=Qn(i,l,r.children);else if(F(o,t))if(l=M(o,t),y(l))i=Qn(i,C(),r.children);else{const a=pe(r.children,m(l));if(a){const c=a.getChild(I(l));i=Pe(i,C(),c)}}}else throw qe("WriteRecord should have .snap or .children")}}return i}function Qi(n,e,t,i,s){if(!i&&!s){const r=le(n.visibleWrites,e);if(r!=null)return r;{const o=Q(n.visibleWrites,e);if(Wt(o))return t;if(t==null&&!Ft(o,C()))return null;{const l=t||g.EMPTY_NODE;return ye(o,l)}}}else{const r=Q(n.visibleWrites,e);if(!s&&Wt(r))return t;if(!s&&t==null&&!Ft(r,C()))return null;{const o=function(c){return(c.visible||s)&&(!i||!~i.indexOf(c.writeId))&&(F(c.path,e)||F(e,c.path))},l=Ki(n.allWrites,o,e),a=t||g.EMPTY_NODE;return ye(l,a)}}}function Eo(n,e,t){let i=g.EMPTY_NODE;const s=le(n.visibleWrites,e);if(s)return s.isLeafNode()||s.forEachChild(S,(r,o)=>{i=i.updateImmediateChild(r,o)}),i;if(t){const r=Q(n.visibleWrites,e);return t.forEachChild(S,(o,l)=>{const a=ye(Q(r,new E(o)),l);i=i.updateImmediateChild(o,a)}),jn(r).forEach(o=>{i=i.updateImmediateChild(o.name,o.node)}),i}else{const r=Q(n.visibleWrites,e);return jn(r).forEach(o=>{i=i.updateImmediateChild(o.name,o.node)}),i}}function wo(n,e,t,i,s){f(i||s,"Either existingEventSnap or existingServerSnap must exist");const r=N(e,t);if(Ft(n.visibleWrites,r))return null;{const o=Q(n.visibleWrites,r);return Wt(o)?s.getChild(t):ye(o,s.getChild(t))}}function Io(n,e,t,i){const s=N(e,t),r=le(n.visibleWrites,s);if(r!=null)return r;if(i.isCompleteForChild(t)){const o=Q(n.visibleWrites,s);return ye(o,i.getNode().getImmediateChild(t))}else return null}function To(n,e){return le(n.visibleWrites,e)}function So(n,e,t,i,s,r,o){let l;const a=Q(n.visibleWrites,e),c=le(a,C());if(c!=null)l=c;else if(t!=null)l=ye(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 No(){return{visibleWrites:q.empty(),allWrites:[],lastWriteId:-1}}function it(n,e,t,i){return Qi(n.writeTree,n.treePath,e,t,i)}function rn(n,e){return Eo(n.writeTree,n.treePath,e)}function $n(n,e,t,i){return wo(n.writeTree,n.treePath,e,t,i)}function st(n,e){return To(n.writeTree,N(n.treePath,e))}function Ro(n,e,t,i,s,r){return So(n.writeTree,n.treePath,e,t,i,s,r)}function on(n,e,t){return Io(n.writeTree,n.treePath,e,t)}function zi(n,e){return ji(N(n.treePath,e),n.writeTree)}function ji(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 bo{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,Oe(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,Me(i,s.oldSnap));else if(t==="child_changed"&&r==="child_added")this.changeMap.set(i,me(i,e.snapshotNode));else if(t==="child_changed"&&r==="child_changed")this.changeMap.set(i,Oe(i,e.snapshotNode,s.oldSnap));else throw qe("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 ko{getCompleteChild(e){return null}getChildAfterChild(e,t,i){return null}}const $i=new ko;class ln{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 ie(this.optCompleteServerCache_,!0,!1):this.viewCache_.serverCache;return on(this.writes_,e,i)}}getChildAfterChild(e,t,i){const s=this.optCompleteServerCache_!=null?this.optCompleteServerCache_:se(this.viewCache_),r=Ro(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 Po(n){return{filter:n}}function xo(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 Ao(n,e,t,i,s){const r=new bo;let o,l;if(t.type===U.OVERWRITE){const c=t;c.source.fromUser?o=Ut(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=rt(n,e,c.path,c.snap,i,s,l,r))}else if(t.type===U.MERGE){const c=t;c.source.fromUser?o=Mo(n,e,c.path,c.children,i,s,r):(f(c.source.fromServer,"Unknown source."),l=c.source.tagged||e.serverCache.isFiltered(),o=qt(n,e,c.path,c.children,i,s,l,r))}else if(t.type===U.ACK_USER_WRITE){const c=t;c.revert?o=Fo(n,e,c.path,i,s,r):o=Oo(n,e,c.path,c.affectedTree,i,s,r)}else if(t.type===U.LISTEN_COMPLETE)o=Lo(n,e,t.path,i,r);else throw qe("Unknown operation type: "+t.type);const a=r.getChanges();return Do(e,o,a),{viewCache:o,changes:a}}function Do(n,e,t){const i=e.eventCache;if(i.isFullyInitialized()){const s=i.getNode().isLeafNode()||i.getNode().isEmpty(),r=Lt(n);(t.length>0||!n.eventCache.isFullyInitialized()||s&&!i.getNode().equals(r)||!i.getNode().getPriority().equals(r.getPriority()))&&t.push(Gi(Lt(e)))}}function Xi(n,e,t,i,s,r){const o=e.eventCache;if(st(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=se(e),h=c instanceof g?c:g.EMPTY_NODE,u=rn(i,h);l=n.filter.updateFullNode(e.eventCache.getNode(),u,r)}else{const c=it(i,se(e));l=n.filter.updateFullNode(e.eventCache.getNode(),c,r)}else{const c=m(t);if(c===".priority"){f(z(t)===1,"Can't have a priority with additional path components");const h=o.getNode();a=e.serverCache.getNode();const u=$n(i,t,h,a);u!=null?l=n.filter.updatePriority(h,u):l=o.getNode()}else{const h=I(t);let u;if(o.isCompleteForChild(c)){a=e.serverCache.getNode();const d=$n(i,t,o.getNode(),a);d!=null?u=o.getNode().getImmediateChild(c).updateChild(h,d):u=o.getNode().getImmediateChild(c)}else u=on(i,c,e.serverCache);u!=null?l=n.filter.updateChild(o.getNode(),c,u,h,s,r):l=o.getNode()}}return ke(e,l,o.isFullyInitialized()||y(t),n.filter.filtersNodes())}}function rt(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 _=m(t);if(!a.isCompleteForPath(t)&&z(t)>1)return e;const p=I(t),A=a.getNode().getImmediateChild(_).updateChild(p,i);_===".priority"?c=h.updatePriority(a.getNode(),A):c=h.updateChild(a.getNode(),_,A,p,$i,null)}const u=Bi(e,c,a.isFullyInitialized()||y(t),h.filtersNodes()),d=new ln(s,u,r);return Xi(n,u,t,s,d,l)}function Ut(n,e,t,i,s,r,o){const l=e.eventCache;let a,c;const h=new ln(s,e,r);if(y(t))c=n.filter.updateFullNode(e.eventCache.getNode(),i,o),a=ke(e,c,!0,n.filter.filtersNodes());else{const u=m(t);if(u===".priority")c=n.filter.updatePriority(e.eventCache.getNode(),i),a=ke(e,c,l.isFullyInitialized(),l.isFiltered());else{const d=I(t),_=l.getNode().getImmediateChild(u);let p;if(y(d))p=i;else{const w=h.getCompleteChild(u);w!=null?jt(d)===".priority"&&w.getChild(Oi(d)).isEmpty()?p=w:p=w.updateChild(d,i):p=g.EMPTY_NODE}if(_.equals(p))a=e;else{const w=n.filter.updateChild(l.getNode(),u,p,d,h,o);a=ke(e,w,l.isFullyInitialized(),n.filter.filtersNodes())}}}return a}function Xn(n,e){return n.eventCache.isCompleteForChild(e)}function Mo(n,e,t,i,s,r,o){let l=e;return i.foreach((a,c)=>{const h=N(t,a);Xn(e,m(h))&&(l=Ut(n,l,h,c,s,r,o))}),i.foreach((a,c)=>{const h=N(t,a);Xn(e,m(h))||(l=Ut(n,l,h,c,s,r,o))}),l}function Jn(n,e,t){return t.foreach((i,s)=>{e=e.updateChild(i,s)}),e}function qt(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 T(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=Jn(n,_,d);a=rt(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=Jn(n,p,d);a=rt(n,a,new E(u),w,s,r,o,l)}}),a}function Oo(n,e,t,i,s,r,o){if(st(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 rt(n,e,t,a.getNode().getChild(t),s,r,l,o);if(y(t)){let c=new T(null);return a.getNode().forEachChild(de,(h,u)=>{c=c.set(new E(h),u)}),qt(n,e,t,c,s,r,l,o)}else return e}else{let c=new T(null);return i.foreach((h,u)=>{const d=N(t,h);a.isCompleteForPath(d)&&(c=c.set(h,a.getNode().getChild(d)))}),qt(n,e,t,c,s,r,l,o)}}function Lo(n,e,t,i,s){const r=e.serverCache,o=Bi(e,r.getNode(),r.isFullyInitialized()||y(t),r.isFiltered());return Xi(n,o,t,i,$i,s)}function Fo(n,e,t,i,s,r){let o;if(st(i,t)!=null)return e;{const l=new ln(i,e,s),a=e.eventCache.getNode();let c;if(y(t)||m(t)===".priority"){let h;if(e.serverCache.isFullyInitialized())h=it(i,se(e));else{const u=e.serverCache.getNode();f(u instanceof g,"serverChildren would be complete if leaf node"),h=rn(i,u)}h=h,c=n.filter.updateFullNode(a,h,r)}else{const h=m(t);let u=on(i,h,e.serverCache);u==null&&e.serverCache.isCompleteForChild(h)&&(u=a.getImmediateChild(h)),u!=null?c=n.filter.updateChild(a,h,u,I(t),l,r):e.eventCache.getNode().hasChild(h)?c=n.filter.updateChild(a,h,g.EMPTY_NODE,I(t),l,r):c=a,c.isEmpty()&&e.serverCache.isFullyInitialized()&&(o=it(i,se(e)),o.isLeafNode()&&(c=n.filter.updateFullNode(c,o,r)))}return o=e.serverCache.isFullyInitialized()||st(i,C())!=null,ke(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 Wo{constructor(e,t){this.query_=e,this.eventRegistrations_=[];const i=this.query_._queryParams,s=new Zt(i.getIndex()),r=no(i);this.processor_=Po(r);const o=t.serverCache,l=t.eventCache,a=s.updateFullNode(g.EMPTY_NODE,o.getNode(),null),c=r.updateFullNode(g.EMPTY_NODE,l.getNode(),null),h=new ie(a,o.isFullyInitialized(),s.filtersNodes()),u=new ie(c,l.isFullyInitialized(),r.filtersNodes());this.viewCache_=_t(u,h),this.eventGenerator_=new co(this.query_)}get query(){return this.query_}}function Uo(n){return n.viewCache_.serverCache.getNode()}function qo(n,e){const t=se(n.viewCache_);return t&&(n.query._queryParams.loadsAllData()||!y(e)&&!t.getImmediateChild(m(e)).isEmpty())?t.getChild(e):null}function Zn(n){return n.eventRegistrations_.length===0}function Vo(n,e){n.eventRegistrations_.push(e)}function ei(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 ti(n,e,t,i){e.type===U.MERGE&&e.source.queryId!==null&&(f(se(n.viewCache_),"We should always have a full cache before handling merges"),f(Lt(n.viewCache_),"Missing event cache, even though we have a server cache"));const s=n.viewCache_,r=Ao(n.processor_,s,e,t,i);return xo(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,Ji(n,r.changes,r.viewCache.eventCache.getNode(),null)}function Go(n,e){const t=n.viewCache_.eventCache,i=[];return t.getNode().isLeafNode()||t.getNode().forEachChild(S,(r,o)=>{i.push(me(r,o))}),t.isFullyInitialized()&&i.push(Gi(t.getNode())),Ji(n,i,t.getNode(),e)}function Ji(n,e,t,i){const s=i?[i]:n.eventRegistrations_;return ho(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, software
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 ot;class Ho{constructor(){this.views=new Map}}function Bo(n){f(!ot,"__referenceConstructor has already been defined"),ot=n}function Yo(){return f(ot,"Reference.ts has not been loaded"),ot}function Ko(n){return n.views.size===0}function an(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."),ti(r,e,t,i)}else{let r=[];for(const o of n.views.values())r=r.concat(ti(o,e,t,i));return r}}function Qo(n,e,t,i,s){const r=e._queryIdentifier,o=n.views.get(r);if(!o){let l=it(t,s?i:null),a=!1;l?a=!0:i instanceof g?(l=rn(t,i),a=!1):(l=g.EMPTY_NODE,a=!1);const c=_t(new ie(l,a,!1),new ie(i,s,!1));return new Wo(e,c)}return o}function zo(n,e,t,i,s,r){const o=Qo(n,e,i,s,r);return n.views.has(e._queryIdentifier)||n.views.set(e._queryIdentifier,o),Vo(o,t),Go(o,t)}function jo(n,e,t,i){const s=e._queryIdentifier,r=[];let o=[];const l=j(n);if(s==="default")for(const[a,c]of n.views.entries())o=o.concat(ei(c,t,i)),Zn(c)&&(n.views.delete(a),c.query._queryParams.loadsAllData()||r.push(c.query));else{const a=n.views.get(s);a&&(o=o.concat(ei(a,t,i)),Zn(a)&&(n.views.delete(s),a.query._queryParams.loadsAllData()||r.push(a.query)))}return l&&!j(n)&&r.push(new(Yo())(e._repo,e._path)),{removed:r,events:o}}function Zi(n){const e=[];for(const t of n.views.values())t.query._queryParams.loadsAllData()||e.push(t);return e}function fe(n,e){let t=null;for(const i of n.views.values())t=t||qo(i,e);return t}function es(n,e){if(e._queryParams.loadsAllData())return pt(n);{const i=e._queryIdentifier;return n.views.get(i)}}function ts(n,e){return es(n,e)!=null}function j(n){return pt(n)!=null}function pt(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 lt;function $o(n){f(!lt,"__referenceConstructor has already been defined"),lt=n}function Xo(){return f(lt,"Reference.ts has not been loaded"),lt}let Jo=1;class ni{constructor(e){this.listenProvider_=e,this.syncPointTree_=new T(null),this.pendingWriteTree_=No(),this.tagToQueryMap=new Map,this.queryToTagMap=new Map}}function ns(n,e,t,i,s){return po(n.pendingWriteTree_,e,t,i,s),s?Be(n,new ne(Hi(),e,t)):[]}function Z(n,e,t=!1){const i=go(n.pendingWriteTree_,e);if(mo(n.pendingWriteTree_,e)){let r=new T(null);return i.snap!=null?r=r.set(C(),!0):D(i.children,o=>{r=r.set(new E(o),!0)}),Be(n,new nt(i.path,r,t))}else return[]}function gt(n,e,t){return Be(n,new ne(tn(),e,t))}function Zo(n,e,t){const i=T.fromObject(t);return Be(n,new We(tn(),e,i))}function el(n,e){return Be(n,new Fe(tn(),e))}function tl(n,e,t){const i=hn(n,t);if(i){const s=un(i),r=s.path,o=s.queryId,l=M(r,e),a=new Fe(nn(o),l);return dn(n,r,a)}else return[]}function Vt(n,e,t,i,s=!1){const r=e._path,o=n.syncPointTree_.get(r);let l=[];if(o&&(e._queryIdentifier==="default"||ts(o,e))){const a=jo(o,e,t,i);Ko(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,_)=>j(_));if(h&&!u){const d=n.syncPointTree_.subtree(r);if(!d.isEmpty()){const _=sl(d);for(let p=0;p<_.length;++p){const w=_[p],A=w.query,ae=rs(n,w);n.listenProvider_.startListening(xe(A),at(n,A),ae.hashFn,ae.onComplete)}}}!u&&c.length>0&&!i&&(h?n.listenProvider_.stopListening(xe(e),null):c.forEach(d=>{const _=n.queryToTagMap.get(mt(d));n.listenProvider_.stopListening(xe(d),_)}))}rl(n,c)}return l}function nl(n,e,t,i){const s=hn(n,i);if(s!=null){const r=un(s),o=r.path,l=r.queryId,a=M(o,e),c=new ne(nn(l),a,t);return dn(n,o,c)}else return[]}function il(n,e,t,i){const s=hn(n,i);if(s){const r=un(s),o=r.path,l=r.queryId,a=M(o,e),c=T.fromObject(t),h=new We(nn(l),a,c);return dn(n,o,h)}else return[]}function ii(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||fe(_,p),o=o||j(_)});let l=n.syncPointTree_.get(s);l?(o=o||j(l),r=r||fe(l,C())):(l=new Ho,n.syncPointTree_=n.syncPointTree_.set(s,l));let a;r!=null?a=!0:(a=!1,r=g.EMPTY_NODE,n.syncPointTree_.subtree(s).foreachChild((_,p)=>{const w=fe(p,C());w&&(r=r.updateImmediateChild(_,w))}));const c=ts(l,e);if(!c&&!e._queryParams.loadsAllData()){const d=mt(e);f(!n.queryToTagMap.has(d),"View does not exist, but we have a tag");const _=ol();n.queryToTagMap.set(d,_),n.tagToQueryMap.set(_,d)}const h=sn(n.pendingWriteTree_,s);let u=zo(l,e,t,h,r,a);if(!c&&!o&&!i){const d=es(l,e);u=u.concat(ll(n,e,d))}return u}function cn(n,e,t){const s=n.pendingWriteTree_,r=n.syncPointTree_.findOnPath(e,(o,l)=>{const a=M(o,e),c=fe(l,a);if(c)return c});return Qi(s,e,r,t,!0)}function Be(n,e){return is(e,n.syncPointTree_,null,sn(n.pendingWriteTree_,C()))}function is(n,e,t,i){if(y(n.path))return ss(n,e,t,i);{const s=e.get(C());t==null&&s!=null&&(t=fe(s,C()));let r=[];const o=m(n.path),l=n.operationForChild(o),a=e.children.get(o);if(a&&l){const c=t?t.getImmediateChild(o):null,h=zi(i,o);r=r.concat(is(l,a,c,h))}return s&&(r=r.concat(an(s,n,i,t))),r}}function ss(n,e,t,i){const s=e.get(C());t==null&&s!=null&&(t=fe(s,C()));let r=[];return e.children.inorderTraversal((o,l)=>{const a=t?t.getImmediateChild(o):null,c=zi(i,o),h=n.operationForChild(o);h&&(r=r.concat(ss(h,l,a,c)))}),s&&(r=r.concat(an(s,n,i,t))),r}function rs(n,e){const t=e.query,i=at(n,t);return{hashFn:()=>(Uo(e)||g.EMPTY_NODE).hash(),onComplete:s=>{if(s==="ok")return i?tl(n,t._path,i):el(n,t._path);{const r=er(s,t);return Vt(n,t,null,r)}}}}function at(n,e){const t=mt(e);return n.queryToTagMap.get(t)}function mt(n){return n._path.toString()+"$"+n._queryIdentifier}function hn(n,e){return n.tagToQueryMap.get(e)}function un(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 dn(n,e,t){const i=n.syncPointTree_.get(e);f(i,"Missing sync point for query tag that we're tracking");const s=sn(n.pendingWriteTree_,e);return an(i,t,s,null)}function sl(n){return n.fold((e,t,i)=>{if(t&&j(t))return[pt(t)];{let s=[];return t&&(s=Zi(t)),D(i,(r,o)=>{s=s.concat(o)}),s}})}function xe(n){return n._queryParams.loadsAllData()&&!n._queryParams.isDefault()?new(Xo())(n._repo,n._path):n}function rl(n,e){for(let t=0;t<e.length;++t){const i=e[t];if(!i._queryParams.loadsAllData()){const s=mt(i),r=n.queryToTagMap.get(s);n.queryToTagMap.delete(s),n.tagToQueryMap.delete(r)}}}function ol(){return Jo++}function ll(n,e,t){const i=e._path,s=at(n,e),r=rs(n,t),o=n.listenProvider_.startListening(xe(e),s,r.hashFn,r.onComplete),l=n.syncPointTree_.subtree(i);if(s)f(!j(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&&j(h))return[pt(h).query];{let d=[];return h&&(d=d.concat(Zi(h).map(_=>_.query))),D(u,(_,p)=>{d=d.concat(p)}),d}});for(let c=0;c<a.length;++c){const h=a[c];n.listenProvider_.stopListening(xe(h),at(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 fn{constructor(e){this.node_=e}getImmediateChild(e){const t=this.node_.getImmediateChild(e);return new fn(t)}node(){return this.node_}}class _n{constructor(e,t){this.syncTree_=e,this.path_=t}getImmediateChild(e){const t=N(this.path_,e);return new _n(this.syncTree_,t)}node(){return cn(this.syncTree_,this.path_)}}const al=function(n){return n=n||{},n.timestamp=n.timestamp||new Date().getTime(),n},si=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 cl(n[".sv"],e,t);if(typeof n[".sv"]=="object")return hl(n[".sv"],e);f(!1,"Unexpected server value: "+JSON.stringify(n,null,2))},cl=function(n,e,t){switch(n){case"timestamp":return t.timestamp;default:f(!1,"Unexpected server value: "+n)}},hl=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},ul=function(n,e,t,i){return pn(e,new _n(t,n),i)},os=function(n,e,t){return pn(n,new fn(e),t)};function pn(n,e,t){const i=n.getPriority().val(),s=si(i,e.getImmediateChild(".priority"),t);let r;if(n.isLeafNode()){const o=n,l=si(o.getValue(),e,t);return l!==o.getValue()||s!==o.getPriority().val()?new b(l,R(s)):n}else{const o=n;return r=o,s!==o.getPriority().val()&&(r=r.updatePriority(new b(s))),o.forEachChild(S,(l,a)=>{const c=pn(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 gn{constructor(e="",t=null,i={children:{},childCount:0}){this.name=e,this.parent=t,this.node=i}}function mn(n,e){let t=e instanceof E?e:new E(e),i=n,s=m(t);for(;s!==null;){const r=pe(i.node.children,s)||{children:{},childCount:0};i=new gn(s,i,r),t=I(t),s=m(t)}return i}function we(n){return n.node.value}function ls(n,e){n.node.value=e,Gt(n)}function as(n){return n.node.childCount>0}function dl(n){return we(n)===void 0&&!as(n)}function yt(n,e){D(n.node.children,(t,i)=>{e(new gn(t,n,i))})}function cs(n,e,t,i){t&&!i&&e(n),yt(n,s=>{cs(s,e,!0,i)}),t&&i&&e(n)}function fl(n,e,t){let i=n.parent;for(;i!==null;){if(e(i))return!0;i=i.parent}return!1}function Ye(n){return new E(n.parent===null?n.name:Ye(n.parent)+"/"+n.name)}function Gt(n){n.parent!==null&&_l(n.parent,n.name,n)}function _l(n,e,t){const i=dl(t),s=V(n.node.children,e);i&&s?(delete n.node.children[e],n.node.childCount--,Gt(n)):!i&&!s&&(n.node.children[e]=t.node,n.node.childCount++,Gt(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 pl=/[\[\].#$\/\u0000-\u001F\u007F]/,gl=/[\[\].#$\u0000-\u001F\u007F]/,bt=10*1024*1024,yn=function(n){return typeof n=="string"&&n.length!==0&&!pl.test(n)},hs=function(n){return typeof n=="string"&&n.length!==0&&!gl.test(n)},ml=function(n){return n&&(n=n.replace(/^\/*\.info(\/|$)/,"/")),hs(n)},us=function(n){return n===null||typeof n=="string"||typeof n=="number"&&!dt(n)||n&&typeof n=="object"&&V(n,".sv")},ct=function(n,e,t,i){i&&e===void 0||vt(_e(n,"value"),e,t)},vt=function(n,e,t){const i=t instanceof E?new Mr(t,n):t;if(e===void 0)throw new Error(n+"contains undefined "+X(i));if(typeof e=="function")throw new Error(n+"contains a function "+X(i)+" with contents = "+e.toString());if(dt(e))throw new Error(n+"contains "+e.toString()+" "+X(i));if(typeof e=="string"&&e.length>bt/3&&ut(e)>bt)throw new Error(n+"contains a string greater than "+bt+" utf8 bytes "+X(i)+" ('"+e.substring(0,50)+"...')");if(e&&typeof e=="object"){let s=!1,r=!1;if(D(e,(o,l)=>{if(o===".value")s=!0;else if(o!==".priority"&&o!==".sv"&&(r=!0,!yn(o)))throw new Error(n+" contains an invalid key ("+o+") "+X(i)+`. Keys must be non-empty strings and can't contain ".", "#", "$", "/", "[", or "]"`);Or(i,o),vt(n,l,i),Lr(i)}),s&&r)throw new Error(n+' contains ".value" child '+X(i)+" in addition to actual children.")}},yl=function(n,e){let t,i;for(t=0;t<e.length;t++){i=e[t];const r=De(i);for(let o=0;o<r.length;o++)if(!(r[o]===".priority"&&o===r.length-1)){if(!yn(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(Dr);let s=null;for(t=0;t<e.length;t++){if(i=e[t],s!==null&&F(s,i))throw new Error(n+"contains a path "+s.toString()+" that is ancestor of another path "+i.toString());s=i}},vl=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=[];D(e,(o,l)=>{const a=new E(o);if(vt(s,l,N(t,a)),jt(a)===".priority"&&!us(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)}),yl(s,r)},Cl=function(n,e,t){if(dt(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(!us(e))throw new Error(_e(n,"priority")+"must be a valid Firebase priority (a string, finite number, server value, or null).")},ds=function(n,e,t,i){if(!hs(t))throw new Error(_e(n,e)+'was an invalid path = "'+t+`". Paths must be non-empty strings and can't contain ".", "#", "$", "[", or "]"`)},El=function(n,e,t,i){t&&(t=t.replace(/^\/*\.info(\/|$)/,"/")),ds(n,e,t)},ee=function(n,e){if(m(e)===".info")throw new Error(n+" failed = Can't modify data under /.info/")},wl=function(n,e){const t=e.path.toString();if(typeof e.repoInfo.host!="string"||e.repoInfo.host.length===0||!yn(e.repoInfo.namespace)&&e.repoInfo.host.split(":")[0]!=="localhost"||t.length!==0&&!ml(t))throw new Error(_e(n,"url")+`must be a valid firebase URL and the path can't contain ".", "#", "$", "[", 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 Il{constructor(){this.eventLists_=[],this.recursionDepth_=0}}function vn(n,e){let t=null;for(let i=0;i<e.length;i++){const s=e[i],r=s.getPath();t!==null&&!$t(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 fs(n,e,t){vn(n,t),_s(n,i=>$t(i,e))}function Y(n,e,t){vn(n,t),_s(n,i=>F(i,e)||F(e,i))}function _s(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)?(Tl(n.eventLists_[i]),n.eventLists_[i]=null):t=!1}}t&&(n.eventLists_=[]),n.recursionDepth_--}function Tl(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();Re&&x("event: "+t.toString()),Ce(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 Sl="repo_interrupt",Nl=25;class Rl{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 Il,this.nextWriteId_=1,this.interceptServerDataCallback_=null,this.onDisconnect_=tt(),this.transactionQueueTree_=new gn,this.persistentConnection_=null,this.key=this.repoInfo_.toURLString()}toString(){return(this.repoInfo_.secure?"https://":"http://")+this.repoInfo_.host}}function bl(n,e,t){if(n.stats_=Qt(n.repoInfo_),n.forceRestClient_||sr())n.server_=new et(n.repoInfo_,(i,s,r,o)=>{ri(n,i,s,r,o)},n.authTokenProvider_,n.appCheckProvider_),setTimeout(()=>oi(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{P(t)}catch(i){throw new Error("Invalid authOverride provided: "+i)}}n.persistentConnection_=new H(n.repoInfo_,e,(i,s,r,o)=>{ri(n,i,s,r,o)},i=>{oi(n,i)},i=>{kl(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_=cr(n.repoInfo_,()=>new ao(n.stats_,n.server_)),n.infoData_=new io,n.infoSyncTree_=new ni({startListening:(i,s,r,o)=>{let l=[];const a=n.infoData_.getNode(i._path);return a.isEmpty()||(l=gt(n.infoSyncTree_,i._path,a),setTimeout(()=>{o("ok")},0)),l},stopListening:()=>{}}),En(n,"connected",!1),n.serverSyncTree_=new ni({startListening:(i,s,r,o)=>(n.server_.listen(i,r,s,(l,a)=>{const c=o(l,a);Y(n.eventQueue_,i._path,c)}),[]),stopListening:(i,s)=>{n.server_.unlisten(i,s)}})}function ps(n){const t=n.infoData_.getNode(new E(".info/serverTimeOffset")).val()||0;return new Date().getTime()+t}function Cn(n){return al({timestamp:ps(n)})}function ri(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=$e(t,c=>R(c));o=il(n.serverSyncTree_,r,a,s)}else{const a=R(t);o=nl(n.serverSyncTree_,r,a,s)}else if(i){const a=$e(t,c=>R(c));o=Zo(n.serverSyncTree_,r,a)}else{const a=R(t);o=gt(n.serverSyncTree_,r,a)}let l=r;o.length>0&&(l=Ct(n,r)),Y(n.eventQueue_,l,o)}function oi(n,e){En(n,"connected",e),e===!1&&xl(n)}function kl(n,e){D(e,(t,i)=>{En(n,t,i)})}function En(n,e,t){const i=new E("/.info/"+e),s=R(t);n.infoData_.updateSnapshot(i,s);const r=gt(n.infoSyncTree_,i,s);Y(n.eventQueue_,i,r)}function gs(n){return n.nextWriteId_++}function Pl(n,e,t,i,s){wn(n,"set",{path:e.toString(),value:t,priority:i});const r=Cn(n),o=R(t,i),l=cn(n.serverSyncTree_,e),a=os(o,l,r),c=gs(n),h=ns(n.serverSyncTree_,e,a,c,!0);vn(n.eventQueue_,h),n.server_.put(e.toString(),o.val(!0),(d,_)=>{const p=d==="ok";p||L("set at "+e+" failed: "+d);const w=Z(n.serverSyncTree_,c,!p);Y(n.eventQueue_,e,w),ve(n,s,d,_)});const u=Es(n,e);Ct(n,u),Y(n.eventQueue_,u,[])}function xl(n){wn(n,"onDisconnectEvents");const e=Cn(n),t=tt();Ot(n.onDisconnect_,C(),(s,r)=>{const o=ul(s,r,n.serverSyncTree_,e);Ee(t,s,o)});let i=[];Ot(t,C(),(s,r)=>{i=i.concat(gt(n.serverSyncTree_,s,r));const o=Es(n,s);Ct(n,o)}),n.onDisconnect_=tt(),Y(n.eventQueue_,C(),i)}function Al(n,e,t){n.server_.onDisconnectCancel(e.toString(),(i,s)=>{i==="ok"&&Mt(n.onDisconnect_,e),ve(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"&&Ee(n.onDisconnect_,e,s),ve(n,i,r,o)})}function Dl(n,e,t,i,s){const r=R(t,i);n.server_.onDisconnectPut(e.toString(),r.val(!0),(o,l)=>{o==="ok"&&Ee(n.onDisconnect_,e,r),ve(n,s,o,l)})}function Ml(n,e,t,i){if(Pt(t)){x("onDisconnect().update() called with empty data. Don't do anything."),ve(n,i,"ok",void 0);return}n.server_.onDisconnectMerge(e.toString(),t,(s,r)=>{s==="ok"&&D(t,(o,l)=>{const a=R(l);Ee(n.onDisconnect_,N(e,o),a)}),ve(n,i,s,r)})}function Ol(n,e,t){let i;m(e._path)===".info"?i=ii(n.infoSyncTree_,e,t):i=ii(n.serverSyncTree_,e,t),fs(n.eventQueue_,e._path,i)}function ai(n,e,t){let i;m(e._path)===".info"?i=Vt(n.infoSyncTree_,e,t):i=Vt(n.serverSyncTree_,e,t),fs(n.eventQueue_,e._path,i)}function Ll(n){n.persistentConnection_&&n.persistentConnection_.interrupt(Sl)}function wn(n,...e){let t="";n.persistentConnection_&&(t=n.persistentConnection_.id+":"),x(t,...e)}function ve(n,e,t,i){e&&Ce(()=>{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 ms(n,e,t){return cn(n.serverSyncTree_,e,t)||g.EMPTY_NODE}function In(n,e=n.transactionQueueTree_){if(e||Et(n,e),we(e)){const t=vs(n,e);f(t.length>0,"Sending zero length transaction queue"),t.every(s=>s.status===0)&&Fl(n,Ye(e),t)}else as(e)&&yt(e,t=>{In(n,t)})}function Fl(n,e,t){const i=t.map(c=>c.currentWriteId),s=ms(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=>{wn(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(Z(n.serverSyncTree_,t[d].currentWriteId)),t[d].onComplete&&u.push(()=>t[d].onComplete(null,!0,t[d].currentOutputSnapshotResolved)),t[d].unwatcher();Et(n,mn(n.transactionQueueTree_,e)),In(n,n.transactionQueueTree_),Y(n.eventQueue_,e,h);for(let d=0;d<u.length;d++)Ce(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{L("transaction at "+a.toString()+" failed: "+c);for(let u=0;u<t.length;u++)t[u].status=4,t[u].abortReason=c}Ct(n,e)}},o)}function Ct(n,e){const t=ys(n,e),i=Ye(t),s=vs(n,t);return Wl(n,s,i),i}function Wl(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(Z(n.serverSyncTree_,a.currentWriteId,!0));else if(a.status===0)if(a.retryCount>=Nl)h=!0,u="maxretry",s=s.concat(Z(n.serverSyncTree_,a.currentWriteId,!0));else{const d=ms(n,a.path,o);a.currentInputSnapshot=d;const _=e[l].update(d.val());if(_!==void 0){vt("transaction failed: Data returned ",_,a.path);let p=R(_);typeof _=="object"&&_!=null&&V(_,".priority")||(p=p.updatePriority(d.getPriority()));const A=a.currentWriteId,ae=Cn(n),Ke=os(p,d,ae);a.currentOutputSnapshotRaw=p,a.currentOutputSnapshotResolved=Ke,a.currentWriteId=gs(n),o.splice(o.indexOf(A),1),s=s.concat(ns(n.serverSyncTree_,a.path,Ke,a.currentWriteId,a.applyLocally)),s=s.concat(Z(n.serverSyncTree_,A,!0))}else h=!0,u="nodata",s=s.concat(Z(n.serverSyncTree_,a.currentWriteId,!0))}Y(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))))}Et(n,n.transactionQueueTree_);for(let l=0;l<i.length;l++)Ce(i[l]);In(n,n.transactionQueueTree_)}function ys(n,e){let t,i=n.transactionQueueTree_;for(t=m(e);t!==null&&we(i)===void 0;)i=mn(i,t),e=I(e),t=m(e);return i}function vs(n,e){const t=[];return Cs(n,e,t),t.sort((i,s)=>i.order-s.order),t}function Cs(n,e,t){const i=we(e);if(i)for(let s=0;s<i.length;s++)t.push(i[s]);yt(e,s=>{Cs(n,s,t)})}function Et(n,e){const t=we(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,ls(e,t.length>0?t:void 0)}yt(e,i=>{Et(n,i)})}function Es(n,e){const t=Ye(ys(n,e)),i=mn(n.transactionQueueTree_,e);return fl(i,s=>{kt(n,s)}),kt(n,i),cs(i,s=>{kt(n,s)}),t}function kt(n,e){const t=we(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(Z(n.serverSyncTree_,t[o].currentWriteId,!0)),t[o].onComplete&&i.push(t[o].onComplete.bind(null,new Error("set"),!1,null))));r===-1?ls(e,void 0):t.length=r+1,Y(n.eventQueue_,Ye(e),s);for(let o=0;o<i.length;o++)Ce(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 Ul(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 ql(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]):L(`Invalid query segment '${t}' in query '${n}'`)}return e}const ci=function(n,e){const t=Vl(n),i=t.namespace;t.domain==="firebase.com"&&B(t.host+" is no longer supported. Please use <YOUR FIREBASE>.firebaseio.com instead"),(!i||i==="undefined")&&t.domain!=="localhost"&&B("Cannot parse Firebase url. Please use https://<YOUR FIREBASE>.firebaseio.com"),t.secure||js();const s=t.scheme==="ws"||t.scheme==="wss";return{repoInfo:new Ni(t.host,t.secure,i,s,e,"",i!==t.subdomain),path:new E(t.pathString)}},Vl=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=Ul(n.substring(h,u)));const d=ql(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 hi="-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz",Gl=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]=hi.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+=hi.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 Hl{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+":"+P(this.snapshot.exportVal())}}class Bl{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 Yl{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 Kl{constructor(e,t){this._repo=e,this._path=t}cancel(){const e=new K;return Al(this._repo,this._path,e.wrapCallback(()=>{})),e.promise}remove(){ee("OnDisconnect.remove",this._path);const e=new K;return li(this._repo,this._path,null,e.wrapCallback(()=>{})),e.promise}set(e){ee("OnDisconnect.set",this._path),ct("OnDisconnect.set",e,this._path,!1);const t=new K;return li(this._repo,this._path,e,t.wrapCallback(()=>{})),t.promise}setWithPriority(e,t){ee("OnDisconnect.setWithPriority",this._path),ct("OnDisconnect.setWithPriority",e,this._path,!1),Cl("OnDisconnect.setWithPriority",t);const i=new K;return Dl(this._repo,this._path,e,t,i.wrapCallback(()=>{})),i.promise}update(e){ee("OnDisconnect.update",this._path),vl("OnDisconnect.update",e,this._path);const t=new K;return Ml(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 Tn{constructor(e,t,i,s){this._repo=e,this._path=t,this._queryParams=i,this._orderByCalled=s}get key(){return y(this._path)?null:jt(this._path)}get ref(){return new $(this._repo,this._path)}get _queryIdentifier(){const e=Yn(this._queryParams),t=Yt(e);return t==="{}"?"default":t}get _queryObject(){return Yn(this._queryParams)}isEqual(e){if(e=re(e),!(e instanceof Tn))return!1;const t=this._repo===e._repo,i=$t(this._path,e._path),s=this._queryIdentifier===e._queryIdentifier;return t&&i&&s}toJSON(){return this.toString()}toString(){return this._repo.toString()+Ar(this._path)}}class $ extends Tn{constructor(e,t){super(e,t,new en,!1)}get parent(){const e=Oi(this._path);return e===null?null:new $(this._repo,e)}get root(){let e=this;for(;e.parent!==null;)e=e.parent;return e}}class ht{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=Ue(this.ref,e);return new ht(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 ht(s,Ue(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 sa(n,e){return n=re(n),n._checkNotDeleted("ref"),e!==void 0?Ue(n._root,e):n._root}function Ue(n,e){return n=re(n),m(n._path)===null?El("child","path",e):ds("child","path",e),new $(n._repo,N(n._path,e))}function ra(n){return n=re(n),new Kl(n._repo,n._path)}function oa(n,e){n=re(n),ee("push",n._path),ct("push",e,n._path,!0);const t=ps(n._repo),i=Gl(t),s=Ue(n,i),r=Ue(n,i);let o;return e!=null?o=ws(r,e).then(()=>r):o=Promise.resolve(r),s.then=o.then.bind(o),s.catch=o.then.bind(o,void 0),s}function la(n){return ee("remove",n._path),ws(n,null)}function ws(n,e){n=re(n),ee("set",n._path),ct("set",e,n._path,!1);const t=new K;return Pl(n._repo,n._path,e,null,t.wrapCallback(()=>{})),t.promise}class Sn{constructor(e){this.callbackContext=e}respondsTo(e){return e==="value"}createEvent(e,t){const i=t._queryParams.getIndex();return new Hl("value",this,new ht(e.snapshotNode,new $(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 Bl(this,e,t):null}matches(e){return e instanceof Sn?!e.callbackContext||!this.callbackContext?!0:e.callbackContext.matches(this.callbackContext):!1}hasAnyCallback(){return this.callbackContext!==null}}function Ql(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)=>{ai(n._repo,n,l),a(h,u)};c.userCallback=t.userCallback,c.context=t.context,t=c}const o=new Yl(t,r||void 0),l=new Sn(o);return Ol(n._repo,n,l),()=>ai(n._repo,n,l)}function aa(n,e,t,i){return Ql(n,"value",e,t,i)}Bo($);$o($);/**
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 zl="FIREBASE_DATABASE_EMULATOR_HOST",Ht={};let jl=!1;function $l(n,e,t,i){n.repoInfo_=new Ni(`${e}:${t}`,!1,n.repoInfo_.namespace,n.repoInfo_.webSocketOnly,n.repoInfo_.nodeAdmin,n.repoInfo_.persistenceKey,n.repoInfo_.includeNamespaceInQueryParams,!0),i&&(n.authTokenProvider_=i)}function Xl(n,e,t,i,s){let r=i||n.options.databaseURL;r===void 0&&(n.options.projectId||B("Can't determine Firebase Database URL. Be sure to include a Project ID when calling firebase.initializeApp()."),x("Using default host for project ",n.options.projectId),r=`${n.options.projectId}-default-rtdb.firebaseio.com`);let o=ci(r,s),l=o.repoInfo,a;typeof process<"u"&&Rn&&(a=Rn[zl]),a?(r=`http://${a}?ns=${l.namespace}`,o=ci(r,s),l=o.repoInfo):o.repoInfo.secure;const c=new or(n.name,n.options,e);wl("Invalid Firebase Database URL",o),y(o.path)||B("Database URL must point to the root of a Firebase Database (not including a child path).");const h=Zl(l,n,c,new rr(n.name,t));return new ea(h,n)}function Jl(n,e){const t=Ht[e];(!t||t[n.key]!==n)&&B(`Database ${e}(${n.repoInfo_}) has already been deleted.`),Ll(n),delete t[n.key]}function Zl(n,e,t,i){let s=Ht[e.name];s||(s={},Ht[e.name]=s);let r=s[n.toURLString()];return r&&B("Database initialized multiple times. Please make sure the format of the database URL matches with each database() call."),r=new Rl(n,jl,t,i),s[n.toURLString()]=r,r}class ea{constructor(e,t){this._repoInternal=e,this.app=t,this.type="database",this._instanceStarted=!1}get _repo(){return this._instanceStarted||(bl(this._repoInternal,this.app.options.appId,this.app.options.databaseAuthVariableOverride),this._instanceStarted=!0),this._repoInternal}get _root(){return this._rootInternal||(this._rootInternal=new $(this._repo,C())),this._rootInternal}_delete(){return this._rootInternal!==null&&(Jl(this._repo,this.app.name),this._repoInternal=null,this._rootInternal=null),Promise.resolve()}_checkNotDeleted(e){this._rootInternal===null&&B("Cannot call "+e+" on a deleted database.")}}function ca(n=Ns(),e){const t=Ts(n,"database").getImmediate({identifier:e});if(!t._instanceStarted){const i=Ss("database");i&&ta(t,...i)}return t}function ta(n,e,t,i={}){n=re(n),n._checkNotDeleted("useEmulator"),n._instanceStarted&&B("Cannot call useEmulator() after instance has already been initialized.");const s=n._repoInternal;let r;if(s.repoInfo_.nodeAdmin)i.mockUserToken&&B('mockUserToken is not supported by the Admin SDK. For client access with mock users, please use the "firebase" package instead of "firebase-admin".'),r=new je(je.OWNER);else if(i.mockUserToken){const o=typeof i.mockUserToken=="string"?i.mockUserToken:Rs(i.mockUserToken,n.app.options.projectId);r=new je(o)}$l(s,e,t,r)}/**
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 na(n){Hs(Gs),Ds(new Ms("database",(e,{instanceIdentifier:t})=>{const i=e.getProvider("app").getImmediate(),s=e.getProvider("auth-internal"),r=e.getProvider("app-check-internal");return Xl(i,s,r,t)},"PUBLIC").setMultipleInstances(!0)),Nn(bn,kn,n),Nn(bn,kn,"esm2017")}H.prototype.simpleListen=function(n,e){this.sendRequest("q",{p:n},e)};H.prototype.echo=function(n,e){this.sendRequest("echo",{d:n},e)};na();export{ht as DataSnapshot,ea as Database,Kl as OnDisconnect,Tn as _QueryImpl,en as _QueryParams,$ as _ReferenceImpl,Xl as _repoManagerDatabaseFromApp,Hs as _setSDKVersion,ds as _validatePathString,ee as _validateWritablePath,Ue as child,ta as connectDatabaseEmulator,ca as getDatabase,ra as onDisconnect,aa as onValue,oa as push,sa as ref,la as remove,ws as set};