1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[4358],{99978:function(e,t,a){a.d(t,{Bt:function(){return rf},EK:function(){return nt},ET:function(){return Ql},IO:function(){return sl},JU:function(){return Aa},PL:function(){return Bl},QT:function(){return Ol},Xo:function(){return hl},ad:function(){return oh},ar:function(){return rl},b9:function(){return fl},cf:function(){return jl},hJ:function(){return Ta},oe:function(){return Gl},pl:function(){return Ul},qs:function(){return af},vr:function(){return of}});var u,l,c=a(63991),h=a(45538),d=a(56914),m=a(8745),p=a(53468);a(25566);let g="@firebase/firestore";/** 2 * @license 3 * Copyright 2017 Google LLC 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */let P=class P{constructor(e){this.uid=e}isAuthenticated(){return null!=this.uid}toKey(){return this.isAuthenticated()?"uid:"+this.uid:"anonymous-user"}isEqual(e){return e.uid===this.uid}};P.UNAUTHENTICATED=new P(null),P.GOOGLE_CREDENTIALS=new P("google-credentials-uid"),P.FIRST_PARTY=new P("first-party-uid"),P.MOCK_USER=new P("mock-user");/** 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 */let y="9.17.1",w=new d.Yd("@firebase/firestore");function S(){return w.logLevel}function C(e,...t){if(w.logLevel<=d.in.DEBUG){let a=t.map(k);w.debug(`Firestore (${y}): ${e}`,...a)}}function x(e,...t){if(w.logLevel<=d.in.ERROR){let a=t.map(k);w.error(`Firestore (${y}): ${e}`,...a)}}function N(e,...t){if(w.logLevel<=d.in.WARN){let a=t.map(k);w.warn(`Firestore (${y}): ${e}`,...a)}}function k(e){if("string"==typeof e)return e;try{return JSON.stringify(e)}catch(t){return e}}/** 32 * @license 33 * Copyright 2017 Google LLC 34 * 35 * Licensed under the Apache License, Version 2.0 (the "License"); 36 * you may not use this file except in compliance with the License. 37 * You may obtain a copy of the License at 38 * 39 * http://www.apache.org/licenses/LICENSE-2.0 40 * 41 * Unless required by applicable law or agreed to in writing, software 42 * distributed under the License is distributed on an "AS IS" BASIS, 43 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 44 * See the License for the specific language governing permissions and 45 * limitations under the License. 46 */function O(e="Unexpected state"){let t=`FIRESTORE (${y}) INTERNAL ASSERTION FAILED: `+e;throw x(t),Error(t)}/** 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 */let v={OK:"ok",CANCELLED:"cancelled",UNKNOWN:"unknown",INVALID_ARGUMENT:"invalid-argument",DEADLINE_EXCEEDED:"deadline-exceeded",NOT_FOUND:"not-found",ALREADY_EXISTS:"already-exists",PERMISSION_DENIED:"permission-denied",UNAUTHENTICATED:"unauthenticated",RESOURCE_EXHAUSTED:"resource-exhausted",FAILED_PRECONDITION:"failed-precondition",ABORTED:"aborted",OUT_OF_RANGE:"out-of-range",UNIMPLEMENT
61ED:"unimplemented",INTERNAL:"internal",UNAVAILABLE:"unavailable",DATA_LOSS:"data-loss"};let L=class L extends m.ZR{constructor(e,t){super(e,t),this.code=e,this.message=t,this.toString=()=>`${this.name}: [code=${this.code}]: ${this.message}`}};/** 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 */let q=class q{constructor(){this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}};/** 77 * @license 78 * Copyright 2017 Google LLC 79 * 80 * Licensed under the Apache License, Version 2.0 (the "License"); 81 * you may not use this file except in compliance with the License. 82 * You may obtain a copy of the License at 83 * 84 * http://www.apache.org/licenses/LICENSE-2.0 85 * 86 * Unless required by applicable law or agreed to in writing, software 87 * distributed under the License is distributed on an "AS IS" BASIS, 88 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 89 * See the License for the specific language governing permissions and 90 * limitations under the License. 91 */let U=class U{constructor(e,t){this.user=t,this.type="OAuth",this.headers=new Map,this.headers.set("Authorization",`Bearer ${e}`)}};let K=class K{getToken(){return Promise.resolve(null)}invalidateToken(){}start(e,t){e.enqueueRetryable(()=>t(P.UNAUTHENTICATED))}shutdown(){}};let G=class G{constructor(e){this.token=e,this.changeListener=null}getToken(){return Promise.resolve(this.token)}invalidateToken(){}start(e,t){this.changeListener=t,e.enqueueRetryable(()=>t(this.token.user))}shutdown(){this.changeListener=null}};let Q=class Q{constructor(e){this.t=e,this.currentUser=P.UNAUTHENTICATED,this.i=0,this.forceRefresh=!1,this.auth=null}start(e,t){let a=this.i,s=e=>this.i!==a?(a=this.i,t(e)):Promise.resolve(),u=new q;this.o=()=>{this.i++,this.currentUser=this.u(),u.resolve(),u=new q,e.enqueueRetryable(()=>s(this.currentUser))};let r=()=>{let t=u;e.enqueueRetryable(async()=>{await t.promise,await s(this.currentUser)})},o=e=>{C("FirebaseAuthCredentialsProvider","Auth detected"),this.auth=e,this.auth.addAuthTokenListener(this.o),r()};this.t.onInit(e=>o(e)),setTimeout(()=>{if(!this.auth){let e=this.t.getImmediate({optional:!0});e?o(e):(C("FirebaseAuthCredentialsProvider","Auth not yet detected"),u.resolve(),u=new q)}},0),r()}getToken(){let e=this.i,t=this.forceRefresh;return this.forceRefresh=!1,this.auth?this.auth.getToken(t).then(t=>this.i!==e?(C("FirebaseAuthCredentialsProvider","getToken aborted due to token change."),this.getToken()):t?("string"==typeof t.accessToken||O(),new U(t.accessToken,this.currentUser)):null):Promise.resolve(null)}invalidateToken(){this.forceRefresh=!0}shutdown(){this.auth&&this.auth.removeAuthTokenListener(this.o)}u(){let e=this.auth&&this.auth.getUid();return null===e||"string"==typeof e||O(),new P(e)}};let j=class j{constructor(e,t,a,u){this.h=e,this.l=t,this.m=a,this.g=u,this.type="FirstParty",this.user=P.FIRST_PARTY,this.p=new Map}I(){return this.g?this.g():("object"==typeof this.h&&null!==this.h&&this.h.auth&&this.h.auth.getAuthHeaderValueForFirstParty||O(),this.h.auth.getAuthHeaderValueForFirstParty([]))}get headers(){this.p.set("X-Goog-AuthUser",this.l);let e=this.I();return e&&this.p.set("Authorization",e),this.m&&this.p.set("X-Goog-Iam-Authorization-Token",this.m),this.p}};let W=class W{constructor(e,t,a,u){this.h=e,this.l=t,this.m=a,this.g=u}getToken(){return Promise.resolve(new j(this.h,this.l,this.m,this.g))}start(e,t){e.enqueueRetryable(()=>t(P.FIRST_PARTY))}shutdown(){}invalidateToken(){}};let z=class z{constructor(e){this.value=e,this.type="AppCheck",this.headers=new Map,e&&e.length>0&&this.headers.set("x-firebase-appcheck",this.value)}};let H=class H{constructor(e){this.T=e,this.forceRefresh=!1,this.appCheck=null,this.A=null}start(e,t){let n=e=>{null!=e.error&&C("FirebaseAppCheckTokenProvider",`Error getting App Check token; using placeholder token instead. Error: ${e.error.message}`);let a=e.token!==this.A;return this.A=e.token,C("FirebaseAppCheckTokenProvider",`Received ${a?"new":"existing"} token.`),a?t(e.token):Promise.resolve()};this.o=t=>{e.enqueueRetryable(()=>n(t))};let s=e=>{C("FirebaseAppCheckTokenProvider","AppCheck detected"),this.appCheck=e,this.appCheck.addTokenListener(this.o)};this.T.onInit(e=>s(e)),setTimeout(()=>{if(!this.appCheck){let e=this.T.getImmediate({optional:!0});e?s(e):C("FirebaseAppCheckTokenProvider","AppCheck not yet detected")}},0)}getToken(){let e=this.forceRefresh;return this.forceRefresh=!1,this.appCheck?this.appCheck.getToken(e).then(e=>e?("string"==typeof e.token||O(),this.A=e.token,new z(e.token)):null):Promise.resolve(null)}invalidateToken(){this.forceRefresh=!0}shutdown(){this.appCheck&&this.appCheck.removeTokenListener(this.o)}};/** 92 * @license 93 * Copyright 2020 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 */function Y(e){let t="undefined"!=typeof self&&(self.crypto||self.msCrypto),a=new Uint8Array(e);if(t&&"function"==typeof t.getRandomValues)t.getRandomValues(a);else for(let t=0;t<e;t++)a[t]=Math.floor(256*Math.random());return a}/** 107 * @license 108 * Copyright 2017 Google LLC 109 * 110 * Licensed under the Apache License, Version 2.0 (the "License"); 111 * you may not use this file except in compliance with the License. 112 * You may obtain a copy of the License at 113 * 114 * http://www.apache.org/licenses/LICENSE-2.0 115 * 116 * Unless required by applicable law or agreed to in writing, software 117 * distributed under the License is distributed on an "AS IS" BASIS, 118 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 119 * See the License for the specific language governing permissions and 120 * limitations under the License. 121 */let X=class X{static R(){let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",t=Math.floor(256/e.length)*e.length,a="";for(;a.length<20;){let u=Y(40);for(let l=0;l<u.length;++l)a.length<20&&u[l]<t&&(a+=e.charAt(u[l]%e.length))}return a}};function Z(e,t){return e<t?-1:e>t?1:0}function tt(e,t,a){return e.length===t.length&&e.every((e,u)=>a(e,t[u]))}/** 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 */let nt=class nt{constructor(e,t){if(this.seconds=e,this.nanoseconds=t,t<0||t>=1e9)throw new L(v.INVALID_ARGUMENT,"Timestamp nanoseconds out of range: "+t);if(e<-62135596800||e>=253402300800)throw new L(v.INVALID_ARGUMENT,"Timestamp seconds out of range: "+e)}static now(){return nt.fromMillis(Date.now())}static fromDate(e){return nt.fromMillis(e.getTime())}static fromMillis(e){let t=Math.floor(e/1e3),a=Math.floor(1e6*(e-1e3*t));return new nt(t,a)}toDate(){return new Date(this.toMillis())}toMillis(){return 1e3*this.seconds+this.nanoseconds/1e6}_compareTo(e){return this.seconds===e.seconds?Z(this.nanoseconds,e.nanoseconds):Z(this.seconds,e.seconds)}isEqual(e){return e.seconds===this.seconds&&e.nanoseconds===this.nanoseconds}toString(){return"Timestamp(seconds="+this.seconds+", nanoseconds="+this.nanoseconds+")"}toJSON(){return{seconds:this.seconds,nanoseconds:this.nanoseconds}}valueOf(){let e=this.seconds- -62135596800;return String(e).padStart(12,"0")+"."+String(this.nanoseconds).padStart(9,"0")}};/** 137 * @license 138 * Copyright 2017 Google LLC 139 * 140 * Licensed under the Apache License, Version 2.0 (the "License"); 141 * you may not use this file except in compliance with the License. 142 * You may obtain a copy of the License at 143 * 144 * http://www.apache.org/licenses/LICENSE-2.0 145 * 146 * Unless required by applicable law or agreed to in writing, software 147 * distributed under the License is distributed on an "AS IS" BASIS, 148 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 149 * See the License for the specific language governing permissions and 150 * limitations under the License. 151 */let st=class st{constructor(e){this.timestamp=e}static fromTimestamp(e){return new st(e)}static min(){return new st(new nt(0,0))}static max(){return new st(new nt(253402300799,999999999))}compareTo(e){return this.timestamp._compareTo(e.timestamp)}isEqual(e){return this.timestamp.isEqual(e.timestamp)}toMicroseconds(){return 1e6*this.timestamp.seconds+this.timestamp.nanoseconds/1e3}toString(){return"SnapshotVersion("+this.timestamp.toString()+")"}toTimestamp(){return this.timestamp}};/** 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 */let it=class it{constructor(e,t,a){void 0===t?t=0:t>e.length&&O(),void 0===a?a=e.length-t:a>e.length-t&&O(),this.segments=e,this.offset=t,this.len=a}get length(){return this.len}isEqual(e){return 0===it.comparator(this,e)}child(e){let t=this.segments.slice(this.offset,this.limit());return e instanceof it?e.forEach(e=>{t.push(e)}):t.push(e),this.construct(t)}limit(){return this.offset+this.length}popFirst(e){return e=void 0===e?1:e,this.construct(this.segments,this.offset+e,this.length-e)}popLast(){return this.construct(this.segments,this.offset,this.length-1)}firstSegment(){return this.segments[this.offset]}lastSegment(){return this.get(this.length-1)}get(e){return this.segments[this.offset+e]}isEmpty(){return 0===this.length}isPrefixOf(e){if(e.length<this.length)return!1;for(let t=0;t<this.length;t++)if(this.get(t)!==e.get(t))return!1;return!0}isImmediateParentOf(e){if(this.length+1!==e.length)return!1;for(let t=0;t<this.length;t++)if(this.get(t)!==e.get(t))return!1;return!0}forEach(e){for(let t=this.offset,a=this.limit();t<a;t++)e(this.segments[t])}toArray(){return this.segments.slice(this.offset,this.limit())}static comparator(e,t){let a=Math.min(e.length,t.length);for(let u=0;u<a;u++){let a=e.get(u),l=t.get(u);if(a<l)return -1;if(a>l)return 1}return e.length<t.length?-1:e.length>t.length?1:0}};let rt=class rt extends it{construct(e,t,a){return new rt(e,t,a)}canonicalString(){return this.toArray().join("/")}toString(){return this.canonicalString()}static fromString(...e){let t=[];for(let a of e){if(a.indexOf("//")>=0)throw new L(v.INVALID_ARGUMENT,`Invalid segment (${a}). Paths must not contain // in them.`);t.push(...a.split("/").filter(e=>e.length>0))}return new rt(t)}static emptyPath(){return new rt([])}};let E=/^[_a-zA-Z][_a-zA-Z0-9]*$/;let ut=class ut extends it{construct(e,t,a){return new ut(e,t,a)}static isValidIdentifier(e){return E.test(e)}canonicalString(){return this.toArray().map(e=>(e=e.replace(/\\/g,"\\\\").replace(/`/g,"\\`"),ut.isValidIdentifier(e)||(e="`"+e+"`"),e)).join(".")}toString(){return this.canonicalString()}isKeyField(){return 1===this.length&&"__name__"===this.get(0)}static keyField(){return new ut(["__name__"])}static fromServerFormat(e){let t=[],a="",u=0,i=()=>{if(0===a.length)throw new L(v.INVALID_ARGUMENT,`Invalid field path (${e}). Paths must not be empty, begin with '.', end with '.', or contain '..'`);t.push(a),a=""},l=!1;for(;u<e.length;){let t=e[u];if("\\"===t){if(u+1===e.length)throw new L(v.INVALID_ARGUMENT,"Path has trailing escape character: "+e);let t=e[u+1];if("\\"!==t&&"."!==t&&"`"!==t)throw new L(v.INVALID_ARGUMENT,"Path has invalid escape sequence: "+e);a+=t,u+=2}else"`"===t?l=!l:"."!==t||l?a+=t:i(),u++}if(i(),l)throw new L(v.INVALID_ARGUMENT,"Unterminated ` in path: "+e);return new ut(t)}static emptyPath(){return new ut([])}};/** 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 */let ct=class ct{constructor(e){this.path=e}static fromPath(e){return new ct(rt.fromString(e))}static fromName(e){return new ct(rt.fromString(e).popFirst(5))}static empty(){return new ct(rt.emptyPath())}get collectionGroup(){return this.path.popLast().lastSegment()}hasCollectionId(e){return this.path.length>=2&&this.path.get(this.path.length-2)===e}getCollectionGroup(){return this.path.get(this.path.length-2)}getCollectionPath(){return this.path.popLast()}isEqual(e){return null!==e&&0===rt.comparator(this.path,e.path)}toString(){return this.path.toString()}static comparator(e,t){return rt.comparator(e.path,t.path)}static isDocumentKey(e){return e.length%2==0}static fromSegments(e){return new ct(new rt(e.slice()))}};/** 182 * @license 183 * Copyright 2021 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 */let at=class at{constructor(e,t,a,u){this.indexId=e,this.collectionGroup=t,this.fields=a,this.indexState=u}};function mt(e,t){let a=e.toTimestamp().seconds,u=e.toTimestamp().nanoseconds+1,l=st.fromTimestamp(1e9===u?new nt(a+1,0):new nt(a,u));return new yt(l,ct.empty(),t)}function gt(e){return new yt(e.readTime,e.key,-1)}at.UNKNOWN_ID=-1;let yt=class yt{constructor(e,t,a){this.readTime=e,this.documentKey=t,this.largestBatchId=a}static min(){return new yt(st.min(),ct.empty(),-1)}static max(){return new yt(st.max(),ct.empty(),-1)}};function pt(e,t){let a=e.readTime.compareTo(t.readTime);return 0!==a?a:0!==(a=ct.comparator(e.documentKey,t.documentKey))?a:Z(e.largestBatchId,t.largestBatchId)}let Tt=class Tt{constructor(){this.onCommittedListeners=[]}addOnCommittedListener(e){this.onCommittedListeners.push(e)}raiseOnCommittedEvent(){this.onCommittedListeners.forEach(e=>e())}};/** 197 * @license 198 * Copyright 2017 Google LLC 199 * 200 * Licensed under the Apache License, Version 2.0 (the "License"); 201 * you may not use this file except in compliance with the License. 202 * You may obtain a copy of the License at 203 * 204 * http://www.apache.org/licenses/LICENSE-2.0 205 * 206 * Unless required by applicable law or agreed to in writing, software 207 * distributed under the License is distributed on an "AS IS" BASIS, 208 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 209 * See the License for the specific language governing permissions and 210 * limitations under the License. 211 */async function Et(e){if(e.code!==v.FAILED_PRECONDITION||"The current tab is not in the required state to perform this operation. It might be necessary to refresh the browser tab."!==e.message)throw e;C("LocalStore","Unexpectedly lost primary lease")}/** 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 */let At=class At{constructor(e){this.nextCallback=null,this.catchCallback=null,this.result=void 0,this.error=void 0,this.isDone=!1,this.callbackAttached=!1,e(e=>{this.isDone=!0,this.result=e,this.nextCallback&&this.nextCallback(e)},e=>{this.isDone=!0,this.error=e,this.catchCallback&&this.catchCallback(e)})}catch(e){return this.next(void 0,e)}next(e,t){return this.callbackAttached&&O(),this.callbackAttached=!0,this.isDone?this.error?this.wrapFailure(t,this.error):this.wrapSuccess(e,this.result):new At((a,u)=>{this.nextCallback=t=>{this.wrapSuccess(e,t).next(a,u)},this.catchCallback=e=>{this.wrapFailure(t,e).next(a,u)}})}toPromise(){return new Promise((e,t)=>{this.next(e,t)})}wrapUserFunction(e){try{let t=e();return t instanceof At?t:At.resolve(t)}catch(e){return At.reject(e)}}wrapSuccess(e,t){return e?this.wrapUserFunction(()=>e(t)):At.resolve(t)}wrapFailure(e,t){return e?this.wrapUserFunction(()=>e(t)):At.reject(t)}static resolve(e){return new At((t,a)=>{t(e)})}static reject(e){return new At((t,a)=>{a(e)})}static waitFor(e){return new At((t,a)=>{let u=0,l=0,c=!1;e.forEach(e=>{++u,e.next(()=>{++l,c&&l===u&&t()},e=>a(e))}),c=!0,l===u&&t()})}static or(e){let t=At.resolve(!1);for(let a of e)t=t.next(e=>e?At.resolve(e):a());return t}static forEach(e,t){let a=[];return e.forEach((e,u)=>{a.push(t.call(this,e,u))}),this.waitFor(a)}static mapArray(e,t){return new At((a,u)=>{let l=e.length,c=Array(l),h=0;for(let d=0;d<l;d++){let m=d;t(e[m]).next(e=>{c[m]=e,++h===l&&a(c)},e=>u(e))}})}static doWhile(e,t){return new At((a,u)=>{let i=()=>{!0===e()?t().next(()=>{i()},u):a()};i()})}};function Vt(e){return"IndexedDbTransactionError"===e.name}/** 227 * @license 228 * Copyright 2018 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 */let Ot=class Ot{constructor(e,t){this.previousValue=e,t&&(t.sequenceNumberHandler=e=>this.ut(e),this.ct=e=>t.writeSequenceNumber(e))}ut(e){return this.previousValue=Math.max(e,this.previousValue),this.previousValue}next(){let e=++this.previousValue;return this.ct&&this.ct(e),e}};Ot.at=-1;/** 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 */let Mt=class Mt{constructor(e,t,a,u,l,c,h,d){this.databaseId=e,this.appId=t,this.persistenceKey=a,this.host=u,this.ssl=l,this.forceLongPolling=c,this.autoDetectLongPolling=h,this.useFetchStreams=d}};let Ft=class Ft{constructor(e,t){this.projectId=e,this.database=t||"(default)"}static empty(){return new Ft("","")}get isDefaultDatabase(){return"(default)"===this.database}isEqual(e){return e instanceof Ft&&e.projectId===this.projectId&&e.database===this.database}};/** 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 */function $t(e){let t=0;for(let a in e)Object.prototype.hasOwnProperty.call(e,a)&&t++;return t}function Bt(e,t){for(let a in e)Object.prototype.hasOwnProperty.call(e,a)&&t(a,e[a])}function Lt(e){for(let t in e)if(Object.prototype.hasOwnProperty.call(e,t))return!1;return!0}function Ut(e){return 0===e&&1/e==-1/0}function Kt(e){return"number"==typeof e&&Number.isInteger(e)&&!Ut(e)&&e<=Number.MAX_SAFE_INTEGER&&e>=Number.MIN_SAFE_INTEGER}/** 272 * @license 273 * Copyright 2020 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 */let Qt=class Qt{constructor(e){this.binaryString=e}static fromBase64String(e){let t=atob(e);return new Qt(t)}
286static fromUint8Array(e){let t=function(e){let t="";for(let a=0;a<e.length;++a)t+=String.fromCharCode(e[a]);return t}(e);return new Qt(t)}[Symbol.iterator](){let e=0;return{next:()=>e<this.binaryString.length?{value:this.binaryString.charCodeAt(e++),done:!1}:{value:void 0,done:!0}}}toBase64(){return btoa(this.binaryString)}toUint8Array(){return function(e){let t=new Uint8Array(e.length);for(let a=0;a<e.length;a++)t[a]=e.charCodeAt(a);return t}(this.binaryString)}approximateByteSize(){return 2*this.binaryString.length}compareTo(e){return Z(this.binaryString,e.binaryString)}isEqual(e){return this.binaryString===e.binaryString}};Qt.EMPTY_BYTE_STRING=new Qt("");let T=new RegExp(/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.(\d+))?Z$/);function Wt(e){if(e||O(),"string"==typeof e){let t=0,a=T.exec(e);if(a||O(),a[1]){let e=a[1];t=Number(e=(e+"000000000").substr(0,9))}let u=new Date(e);return{seconds:Math.floor(u.getTime()/1e3),nanos:t}}return{seconds:zt(e.seconds),nanos:zt(e.nanos)}}function zt(e){return"number"==typeof e?e:"string"==typeof e?Number(e):0}function Ht(e){return"string"==typeof e?Qt.fromBase64String(e):Qt.fromUint8Array(e)}/** 287 * @license 288 * Copyright 2020 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 */function Jt(e){var t,a;return"server_timestamp"===(null===(a=((null===(t=null==e?void 0:e.mapValue)||void 0===t?void 0:t.fields)||{}).__type__)||void 0===a?void 0:a.stringValue)}function Yt(e){let t=e.mapValue.fields.__previous_value__;return Jt(t)?Yt(t):t}function Xt(e){let t=Wt(e.mapValue.fields.__local_write_time__.timestampValue);return new nt(t.seconds,t.nanos)}/** 302 * @license 303 * Copyright 2020 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 */let A={mapValue:{fields:{__type__:{stringValue:"__max__"}}}};function ee(e){return"nullValue"in e?0:"booleanValue"in e?1:"integerValue"in e||"doubleValue"in e?2:"timestampValue"in e?3:"stringValue"in e?5:"bytesValue"in e?6:"referenceValue"in e?7:"geoPointValue"in e?8:"arrayValue"in e?9:"mapValue"in e?Jt(e)?4:we(e)?9007199254740991:10:O()}function ne(e,t){if(e===t)return!0;let a=ee(e);if(a!==ee(t))return!1;switch(a){case 0:case 9007199254740991:return!0;case 1:return e.booleanValue===t.booleanValue;case 4:return Xt(e).isEqual(Xt(t));case 3:return function(e,t){if("string"==typeof e.timestampValue&&"string"==typeof t.timestampValue&&e.timestampValue.length===t.timestampValue.length)return e.timestampValue===t.timestampValue;let a=Wt(e.timestampValue),u=Wt(t.timestampValue);return a.seconds===u.seconds&&a.nanos===u.nanos}(e,t);case 5:return e.stringValue===t.stringValue;case 6:return Ht(e.bytesValue).isEqual(Ht(t.bytesValue));case 7:return e.referenceValue===t.referenceValue;case 8:return zt(e.geoPointValue.latitude)===zt(t.geoPointValue.latitude)&&zt(e.geoPointValue.longitude)===zt(t.geoPointValue.longitude);case 2:return function(e,t){if("integerValue"in e&&"integerValue"in t)return zt(e.integerValue)===zt(t.integerValue);if("doubleValue"in e&&"doubleValue"in t){let a=zt(e.doubleValue),u=zt(t.doubleValue);return a===u?Ut(a)===Ut(u):isNaN(a)&&isNaN(u)}return!1}(e,t);case 9:return tt(e.arrayValue.values||[],t.arrayValue.values||[],ne);case 10:return function(e,t){let a=e.mapValue.fields||{},u=t.mapValue.fields||{};if($t(a)!==$t(u))return!1;for(let e in a)if(a.hasOwnProperty(e)&&(void 0===u[e]||!ne(a[e],u[e])))return!1;return!0}(e,t);default:return O()}}function se(e,t){return void 0!==(e.values||[]).find(e=>ne(e,t))}function ie(e,t){if(e===t)return 0;let a=ee(e),u=ee(t);if(a!==u)return Z(a,u);switch(a){case 0:case 9007199254740991:return 0;case 1:return Z(e.booleanValue,t.booleanValue);case 2:return function(e,t){let a=zt(e.integerValue||e.doubleValue),u=zt(t.integerValue||t.doubleValue);return a<u?-1:a>u?1:a===u?0:isNaN(a)?isNaN(u)?0:-1:1}(e,t);case 3:return re(e.timestampValue,t.timestampValue);case 4:return re(Xt(e),Xt(t));case 5:return Z(e.stringValue,t.stringValue);case 6:return function(e,t){let a=Ht(e),u=Ht(t);return a.compareTo(u)}(e.bytesValue,t.bytesValue);case 7:return function(e,t){let a=e.split("/"),u=t.split("/");for(let e=0;e<a.length&&e<u.length;e++){let t=Z(a[e],u[e]);if(0!==t)return t}return Z(a.length,u.length)}(e.referenceValue,t.referenceValue);case 8:return function(e,t){let a=Z(zt(e.latitude),zt(t.latitude));return 0!==a?a:Z(zt(e.longitude),zt(t.longitude))}(e.geoPointValue,t.geoPointValue);case 9:return function(e,t){let a=e.values||[],u=t.values||[];for(let e=0;e<a.length&&e<u.length;++e){let t=ie(a[e],u[e]);if(t)return t}return Z(a.length,u.length)}(e.arrayValue,t.arrayValue);case 10:return function(e,t){if(e===A.mapValue&&t===A.mapValue)return 0;if(e===A.mapValue)return 1;if(t===A.mapValue)return -1;let a=e.fields||{},u=Object.keys(a),l=t.fields||{},c=Object.keys(l);u.sort(),c.sort();for(let e=0;e<u.length&&e<c.length;++e){let t=Z(u[e],c[e]);if(0!==t)return t;let h=ie(a[u[e]],l[c[e]]);if(0!==h)return h}return Z(u.length,c.length)}(e.mapValue,t.mapValue);default:throw O()}}function re(e,t){if("string"==typeof e&&"string"==typeof t&&e.length===t.length)return Z(e,t);let a=Wt(e),u=Wt(t),l=Z(a.seconds,u.seconds);return 0!==l?l:Z(a.nanos,u.nanos)}function ue(e){var t,a;return"nullValue"in e?"null":"booleanValue"in e?""+e.booleanValue:"integerValue"in e?""+e.integerValue:"doubleValue"in e?""+e.doubleValue:"timestampValue"in e?function(e){let t=Wt(e);return`time(${t.seconds},${t.nanos})`}(e.timestampValue):"stringValue"in e?e.stringValue:"bytesValue"in e?Ht(e.bytesValue).toBase64():"referenceValue"in e?(a=e.referenceValue,ct.fromName(a).toString()):"geoPointValue"in e?`geo(${(t=e.geoPointValue).latitude},${t.longitude})`:"arrayValue"in e?function(e){let t="[",a=!0;for(let u of e.values||[])a?a=!1:t+=",",t+=ue(u);return t+"]"}(e.arrayValue):"mapValue"in e?function(e){let t=Object.keys(e.fields||{}).sort(),a="{",u=!0;for(let l of t)u?u=!1:a+=",",a+=`${l}:${ue(e.fields[l])}`;return a+"}"}(e.mapValue):O()}function ce(e,t){return{referenceValue:`projects/${e.projectId}/databases/${e.database}/documents/${t.path.canonicalString()}`}}function ae(e){return!!e&&"integerValue"in e}function he(e){return!!e&&"arrayValue"in e}function le(e){return!!e&&"nullValue"in e}function fe(e){return!!e&&"doubleValue"in e&&isNaN(Number(e.doubleValue))}function de(e){return!!e&&"mapValue"in e}function _e(e){if(e.geoPointValue)return{geoPointValue:Object.assign({},e.geoPointValue)};if(e.timestampValue&&"object"==typeof e.timestampValue)return{timestampValue:Object.assign({},e.timestampValue)};if(e.mapValue){let t={mapValue:{fields:{}}};return Bt(e.mapValue.fields,(e,a)=>t.mapValue.fields[e]=_e(a)),t}if(e.arrayValue){let t={arrayValue:{values:[]}};for(let a=0;a<(e.arrayValue.values||[]).length;++a)t.arrayValue.values[a]=_e(e.arrayValue.values[a]);return t}return Object.assign({},e)}function we(e){return"__max__"===(((e.mapValue||{}).fields||{}).__type__||{}).stringValue}/** 317 * @license 318 * Copyright 2022 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 */let Ie=class Ie{constructor(e,t){this.position=e,this.inclusive=t}};function Te(e,t,a){let u=0;for(let l=0;l<e.position.length;l++){let c=t[l],h=e.position[l];if(u=c.field.isKeyField()?ct.comparator(ct.fromName(h.referenceValue),a.key):ie(h,a.data.field(c.field)),"desc"===c.dir&&(u*=-1),0!==u)break}return u}function Ee(e,t){if(null===e)return null===t;if(null===t||e.inclusive!==t.inclusive||e.position.length!==t.position.length)return!1;for(let a=0;a<e.position.length;a++)if(!ne(e.position[a],t.position[a]))return!1;return!0}/** 332 * @license 333 * Copyright 2022 Google LLC 334 * 335 * Licensed under the Apache License, Version 2.0 (the "License"); 336 * you may not use this file except in compliance with the License. 337 * You may obtain a copy of the License at 338 * 339 * http://www.apache.org/licenses/LICENSE-2.0 340 * 341 * Unless required by applicable law or agreed to in writing, software 342 * distributed under the License is distributed on an "AS IS" BASIS, 343 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 344 * See the License for the specific language governing permissions and 345 * limitations under the License. 346 */let Ae=class Ae{};let Re=class Re extends Ae{constructor(e,t,a){super(),this.field=e,this.op=t,this.value=a}static create(e,t,a){return e.isKeyField()?"in"===t||"not-in"===t?this.createKeyFieldInFilter(e,t,a):new ke(e,t,a):"array-contains"===t?new $e(e,a):"in"===t?new Be(e,a):"not-in"===t?new Le(e,a):"array-contains-any"===t?new qe(e,a):new Re(e,t,a)}static createKeyFieldInFilter(e,t,a){return"in"===t?new Oe(e,a):new Me(e,a)}matches(e){let t=e.data.field(this.field);return"!="===this.op?null!==t&&this.matchesComparison(ie(t,this.value)):null!==t&&ee(this.value)===ee(t)&&this.matchesComparison(ie(t,this.value))}matchesComparison(e){switch(this.op){case"<":return e<0;case"<=":return e<=0;case"==":return 0===e;case"!=":return 0!==e;case">":return e>0;case">=":return e>=0;default:return O()}}isInequality(){return["<","<=",">",">=","!=","not-in"].indexOf(this.op)>=0}getFlattenedFilters(){return[this]}getFilters(){return[this]}getFirstInequalityField(){return this.isInequality()?this.field:null}};let be=class be extends Ae{constructor(e,t){super(),this.filters=e,this.op=t,this.ht=null}static create(e,t){return new be(e,t)}matches(e){return Pe(this)?void 0===this.filters.find(t=>!t.matches(e)):void 0!==this.filters.find(t=>t.matches(e))}getFlattenedFilters(){return null!==this.ht||(this.ht=this.filters.reduce((e,t)=>e.concat(t.getFlattenedFilters()),[])),this.ht}getFilters(){return Object.assign([],this.filters)}getFirstInequalityField(){let e=this.lt(e=>e.isInequality());return null!==e?e.field:null}lt(e){for(let t of this.getFlattenedFilters())if(e(t))return t;return null}};function Pe(e){return"and"===e.op}function Se(e){for(let t of e.filters)if(t instanceof be)return!1;return!0}function De(e){if(e instanceof Re)return e.field.canonicalString()+e.op.toString()+ue(e.value);if(Se(e)&&Pe(e))return e.filters.map(e=>De(e)).join(",");{let t=e.filters.map(e=>De(e)).join(",");return`${e.op}(${t})`}}function Ce(e,t){return e instanceof Re?t instanceof Re&&e.op===t.op&&e.field.isEqual(t.field)&&ne(e.value,t.value):e instanceof be?t instanceof be&&e.op===t.op&&e.filters.length===t.filters.length&&e.filters.reduce((e,a,u)=>e&&Ce(a,t.filters[u]),!0):void O()}function Ne(e){return e instanceof Re?`${e.field.canonicalString()} ${e.op} ${ue(e.value)}`:e instanceof be?e.op.toString()+" {"+e.getFilters().map(Ne).join(" ,")+"}":"Filter"}let ke=class ke extends Re{constructor(e,t,a){super(e,t,a),this.key=ct.fromName(a.referenceValue)}matches(e){let t=ct.comparator(e.key,this.key);return this.matchesComparison(t)}};let Oe=class Oe extends Re{constructor(e,t){super(e,"in",t),this.keys=Fe("in",t)}matches(e){return this.keys.some(t=>t.isEqual(e.key))}};let Me=class Me extends Re{constructor(e,t){super(e,"not-in",t),this.keys=Fe("not-in",t)}matches(e){return!this.keys.some(t=>t.isEqual(e.key))}};function Fe(e,t){var a;return((null===(a=t.arrayValue)||void 0===a?void 0:a.values)||[]).map(e=>ct.fromName(e.referenceValue))}let $e=class $e extends Re{constructor(e,t){super(e,"array-contains",t)}matches(e){let t=e.data.field(this.field);return he(t)&&se(t.arrayValue,this.value)}};let Be=class Be extends Re{constructor(e,t){super(e,"in",t)}matches(e){let t=e.data.field(this.field);return null!==t&&se(this.value.arrayValue,t)}};let Le=class Le extends Re{constructor(e,t){super(e,"not-in",t)}matches(e){if(se(this.value.arrayValue,{nullValue:"NULL_VALUE"}))return!1;let t=e.data.field(this.field);return null!==t&&!se(this.value.arrayValue,t)}};let qe=class qe extends Re{constructor(e,t){super(e,"array-contains-any",t)}matches(e){let t=e.data.field(this.field);return!(!he(t)||!t.arrayValue.values)&&t.arrayValue.values.some(e=>se(this.value.arrayValue,e))}};/** 347 * @license 348 * Copyright 2022 Google LLC 349 * 350 * Licensed under the Apache License, Version 2.0 (the "License");
351 * you may not use this file except in compliance with the License. 352 * You may obtain a copy of the License at 353 * 354 * http://www.apache.org/licenses/LICENSE-2.0 355 * 356 * Unless required by applicable law or agreed to in writing, software 357 * distributed under the License is distributed on an "AS IS" BASIS, 358 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 359 * See the License for the specific language governing permissions and 360 * limitations under the License. 361 */let Ue=class Ue{constructor(e,t="asc"){this.field=e,this.dir=t}};function Ke(e,t){return e.dir===t.dir&&e.field.isEqual(t.field)}/** 362 * @license 363 * Copyright 2017 Google LLC 364 * 365 * Licensed under the Apache License, Version 2.0 (the "License"); 366 * you may not use this file except in compliance with the License. 367 * You may obtain a copy of the License at 368 * 369 * http://www.apache.org/licenses/LICENSE-2.0 370 * 371 * Unless required by applicable law or agreed to in writing, software 372 * distributed under the License is distributed on an "AS IS" BASIS, 373 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 374 * See the License for the specific language governing permissions and 375 * limitations under the License. 376 */let Ge=class Ge{constructor(e,t){this.comparator=e,this.root=t||je.EMPTY}insert(e,t){return new Ge(this.comparator,this.root.insert(e,t,this.comparator).copy(null,null,je.BLACK,null,null))}remove(e){return new Ge(this.comparator,this.root.remove(e,this.comparator).copy(null,null,je.BLACK,null,null))}get(e){let t=this.root;for(;!t.isEmpty();){let a=this.comparator(e,t.key);if(0===a)return t.value;a<0?t=t.left:a>0&&(t=t.right)}return null}indexOf(e){let t=0,a=this.root;for(;!a.isEmpty();){let u=this.comparator(e,a.key);if(0===u)return t+a.left.size;u<0?a=a.left:(t+=a.left.size+1,a=a.right)}return -1}isEmpty(){return this.root.isEmpty()}get size(){return this.root.size}minKey(){return this.root.minKey()}maxKey(){return this.root.maxKey()}inorderTraversal(e){return this.root.inorderTraversal(e)}forEach(e){this.inorderTraversal((t,a)=>(e(t,a),!1))}toString(){let e=[];return this.inorderTraversal((t,a)=>(e.push(`${t}:${a}`),!1)),`{${e.join(", ")}}`}reverseTraversal(e){return this.root.reverseTraversal(e)}getIterator(){return new Qe(this.root,null,this.comparator,!1)}getIteratorFrom(e){return new Qe(this.root,e,this.comparator,!1)}getReverseIterator(){return new Qe(this.root,null,this.comparator,!0)}getReverseIteratorFrom(e){return new Qe(this.root,e,this.comparator,!0)}};let Qe=class Qe{constructor(e,t,a,u){this.isReverse=u,this.nodeStack=[];let l=1;for(;!e.isEmpty();)if(l=t?a(e.key,t):1,t&&u&&(l*=-1),l<0)e=this.isReverse?e.left:e.right;else{if(0===l){this.nodeStack.push(e);break}this.nodeStack.push(e),e=this.isReverse?e.right:e.left}}getNext(){let e=this.nodeStack.pop(),t={key:e.key,value:e.value};if(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(0===this.nodeStack.length)return null;let e=this.nodeStack[this.nodeStack.length-1];return{key:e.key,value:e.value}}};let je=class je{constructor(e,t,a,u,l){this.key=e,this.value=t,this.color=null!=a?a:je.RED,this.left=null!=u?u:je.EMPTY,this.right=null!=l?l:je.EMPTY,this.size=this.left.size+1+this.right.size}copy(e,t,a,u,l){return new je(null!=e?e:this.key,null!=t?t:this.value,null!=a?a:this.color,null!=u?u:this.left,null!=l?l:this.right)}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,a){let u=this,l=a(e,u.key);return(u=l<0?u.copy(null,null,null,u.left.insert(e,t,a),null):0===l?u.copy(null,t,null,null,null):u.copy(null,null,null,null,u.right.insert(e,t,a))).fixUp()}removeMin(){if(this.left.isEmpty())return je.EMPTY;let e=this;return e.left.isRed()||e.left.left.isRed()||(e=e.moveRedLeft()),(e=e.copy(null,null,null,e.left.removeMin(),null)).fixUp()}remove(e,t){let a,u=this;if(0>t(e,u.key))u.left.isEmpty()||u.left.isRed()||u.left.left.isRed()||(u=u.moveRedLeft()),u=u.copy(null,null,null,u.left.remove(e,t),null);else{if(u.left.isRed()&&(u=u.rotateRight()),u.right.isEmpty()||u.right.isRed()||u.right.left.isRed()||(u=u.moveRedRight()),0===t(e,u.key)){if(u.right.isEmpty())return je.EMPTY;
376a=u.right.min(),u=u.copy(a.key,a.value,null,null,u.right.removeMin())}u=u.copy(null,null,null,null,u.right.remove(e,t))}return u.fixUp()}isRed(){return this.color}fixUp(){let e=this;return e.right.isRed()&&!e.left.isRed()&&(e=e.rotateLeft()),e.left.isRed()&&e.left.left.isRed()&&(e=e.rotateRight()),e.left.isRed()&&e.right.isRed()&&(e=e.colorFlip()),e}moveRedLeft(){let e=this.colorFlip();return e.right.left.isRed()&&(e=(e=(e=e.copy(null,null,null,null,e.right.rotateRight())).rotateLeft()).colorFlip()),e}moveRedRight(){let e=this.colorFlip();return e.left.left.isRed()&&(e=(e=e.rotateRight()).colorFlip()),e}rotateLeft(){let e=this.copy(null,null,je.RED,null,this.right.left);return this.right.copy(null,null,this.color,e,null)}rotateRight(){let e=this.copy(null,null,je.RED,this.left.right,null);return this.left.copy(null,null,this.color,null,e)}colorFlip(){let e=this.left.copy(null,null,!this.left.color,null,null),t=this.right.copy(null,null,!this.right.color,null,null);return this.copy(null,null,!this.color,e,t)}checkMaxDepth(){let e=this.check();return Math.pow(2,e)<=this.size+1}check(){if(this.isRed()&&this.left.isRed()||this.right.isRed())throw O();let e=this.left.check();if(e!==this.right.check())throw O();return e+(this.isRed()?0:1)}};je.EMPTY=null,je.RED=!0,je.BLACK=!1,je.EMPTY=new class{constructor(){this.size=0}get key(){throw O()}get value(){throw O()}get color(){throw O()}get left(){throw O()}get right(){throw O()}copy(e,t,a,u,l){return this}insert(e,t,a){return new je(e,t)}remove(e,t){return this}isEmpty(){return!0}inorderTraversal(e){return!1}reverseTraversal(e){return!1}minKey(){return null}maxKey(){return null}isRed(){return!1}checkMaxDepth(){return!0}check(){return 0}};/** 377 * @license 378 * Copyright 2017 Google LLC 379 * 380 * Licensed under the Apache License, Version 2.0 (the "License"); 381 * you may not use this file except in compliance with the License. 382 * You may obtain a copy of the License at 383 * 384 * http://www.apache.org/licenses/LICENSE-2.0 385 * 386 * Unless required by applicable law or agreed to in writing, software 387 * distributed under the License is distributed on an "AS IS" BASIS, 388 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 389 * See the License for the specific language governing permissions and 390 * limitations under the License. 391 */let We=class We{constructor(e){this.comparator=e,this.data=new Ge(this.comparator)}has(e){return null!==this.data.get(e)}first(){return this.data.minKey()}last(){return this.data.maxKey()}get size(){return this.data.size}indexOf(e){return this.data.indexOf(e)}forEach(e){this.data.inorderTraversal((t,a)=>(e(t),!1))}forEachInRange(e,t){let a=this.data.getIteratorFrom(e[0]);for(;a.hasNext();){let u=a.getNext();if(this.comparator(u.key,e[1])>=0)return;t(u.key)}}forEachWhile(e,t){let a;for(a=void 0!==t?this.data.getIteratorFrom(t):this.data.getIterator();a.hasNext();)if(!e(a.getNext().key))return}firstAfterOrEqual(e){let t=this.data.getIteratorFrom(e);return t.hasNext()?t.getNext().key:null}getIterator(){return new ze(this.data.getIterator())}getIteratorFrom(e){return new ze(this.data.getIteratorFrom(e))}add(e){return this.copy(this.data.remove(e).insert(e,!0))}delete(e){return this.has(e)?this.copy(this.data.remove(e)):this}isEmpty(){return this.data.isEmpty()}unionWith(e){let t=this;return t.size<e.size&&(t=e,e=this),e.forEach(e=>{t=t.add(e)}),t}isEqual(e){if(!(e instanceof We)||this.size!==e.size)return!1;let t=this.data.getIterator(),a=e.data.getIterator();for(;t.hasNext();){let e=t.getNext().key,u=a.getNext().key;if(0!==this.comparator(e,u))return!1}return!0}toArray(){let e=[];return this.forEach(t=>{e.push(t)}),e}toString(){let e=[];return this.forEach(t=>e.push(t)),"SortedSet("+e.toString()+")"}copy(e){let t=new We(this.comparator);return t.data=e,t}};let ze=class ze{constructor(e){this.iter=e}getNext(){return this.iter.getNext().key}hasNext(){return this.iter.hasNext()}};/** 392 * @license 393 * Copyright 2020 Google LLC 394 * 395 * Licensed under the Apache License, Version 2.0 (the "License"); 396 * you may not use this file except in compliance with the License. 397 * You may obtain a copy of the License at 398 * 399 * http://www.apache.org/licenses/LICENSE-2.0 400 * 401 * Unless required by applicable law or agreed to in writing, softw
401are 402 * distributed under the License is distributed on an "AS IS" BASIS, 403 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 404 * See the License for the specific language governing permissions and 405 * limitations under the License. 406 */let Je=class Je{constructor(e){this.fields=e,e.sort(ut.comparator)}static empty(){return new Je([])}unionWith(e){let t=new We(ut.comparator);for(let e of this.fields)t=t.add(e);for(let a of e)t=t.add(a);return new Je(t.toArray())}covers(e){for(let t of this.fields)if(t.isPrefixOf(e))return!0;return!1}isEqual(e){return tt(this.fields,e.fields,(e,t)=>e.isEqual(t))}};/** 407 * @license 408 * Copyright 2017 Google LLC 409 * 410 * Licensed under the Apache License, Version 2.0 (the "License"); 411 * you may not use this file except in compliance with the License. 412 * You may obtain a copy of the License at 413 * 414 * http://www.apache.org/licenses/LICENSE-2.0 415 * 416 * Unless required by applicable law or agreed to in writing, software 417 * distributed under the License is distributed on an "AS IS" BASIS, 418 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 419 * See the License for the specific language governing permissions and 420 * limitations under the License. 421 */let Ye=class Ye{constructor(e){this.value=e}static empty(){return new Ye({mapValue:{}})}field(e){if(e.isEmpty())return this.value;{let t=this.value;for(let a=0;a<e.length-1;++a)if(!de(t=(t.mapValue.fields||{})[e.get(a)]))return null;return(t=(t.mapValue.fields||{})[e.lastSegment()])||null}}set(e,t){this.getFieldsMap(e.popLast())[e.lastSegment()]=_e(t)}setAll(e){let t=ut.emptyPath(),a={},u=[];e.forEach((e,l)=>{if(!t.isImmediateParentOf(l)){let e=this.getFieldsMap(t);this.applyChanges(e,a,u),a={},u=[],t=l.popLast()}e?a[l.lastSegment()]=_e(e):u.push(l.lastSegment())});let l=this.getFieldsMap(t);this.applyChanges(l,a,u)}delete(e){let t=this.field(e.popLast());de(t)&&t.mapValue.fields&&delete t.mapValue.fields[e.lastSegment()]}isEqual(e){return ne(this.value,e.value)}getFieldsMap(e){let t=this.value;t.mapValue.fields||(t.mapValue={fields:{}});for(let a=0;a<e.length;++a){let u=t.mapValue.fields[e.get(a)];de(u)&&u.mapValue.fields||(u={mapValue:{fields:{}}},t.mapValue.fields[e.get(a)]=u),t=u}return t.mapValue.fields}applyChanges(e,t,a){for(let u of(Bt(t,(t,a)=>e[t]=a),a))delete e[u]}clone(){return new Ye(_e(this.value))}};function Xe(e){let t=[];return Bt(e.fields,(e,a)=>{let u=new ut([e]);if(de(a)){let e=Xe(a.mapValue).fields;if(0===e.length)t.push(u);else for(let a of e)t.push(u.child(a))}else t.push(u)}),new Je(t)}/** 422 * @license 423 * Copyright 2017 Google LLC 424 * 425 * Licensed under the Apache License, Version 2.0 (the "License"); 426 * you may not use this file except in compliance with the License. 427 * You may obtain a copy of the License at 428 * 429 * http://www.apache.org/licenses/LICENSE-2.0 430 * 431 * Unless required by applicable law or agreed to in writing, software 432 * distributed under the License is distributed on an "AS IS" BASIS, 433 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 434 * See the License for the specific language governing permissions and 435 * limitations under the License. 436 */let Ze=class Ze{constructor(e,t,a,u,l,c,h){this.key=e,this.documentType=t,this.version=a,this.readTime=u,this.createTime=l,this.data=c,this.documentState=h}static newInvalidDocument(e){return new Ze(e,0,st.min(),st.min(),st.min(),Ye.empty(),0)}static newFoundDocument(e,t,a,u){return new Ze(e,1,t,st.min(),a,u,0)}static newNoDocument(e,t){return new Ze(e,2,t,st.min(),st.min(),Ye.empty(),0)}static newUnknownDocument(e,t){return new Ze(e,3,t,st.min(),st.min(),Ye.empty(),2)}convertToFoundDocument(e,t){return this.createTime.isEqual(st.min())&&(2===this.documentType||0===this.documentType)&&(this.createTime=e),this.version=e,this.documentType=1,this.data=t,this.documentState=0,this}convertToNoDocument(e){return this.version=e,this.documentType=2,this.data=Ye.empty(),this.documentState=0,this}convertToUnknownDocument(e){return this.version=e,this.documentType=3,this.data=Ye.empty(),this.documentState=2,this}setHasCommittedMutations(){return this.documentState=2,this}setHasLocalMutations(){return this.documentState=1,this.version=st.min(),this}setReadTime(e){return this.readTime=e,this}get hasLocalMutations(){return 1===this.documentState}get hasCommittedMutations(){return 2===this.documentState}get hasPendingWrites(){return this.hasLocalMutations||this.hasCommittedMutations}isValidDocument(){return 0!==this.documentType}isFoundDocument(){return 1===this.documentType}isNoDocument(){return 2===this.documentType}isUnknownDocument(){return 3===this.documentType}isEqual(e){return e instanceof Ze&&this.key.isEqual(e.key)&&this.version.isEqual(e.version)&&this.documentType===e.documentType&&this.documentState===e.documentState&&this.data.isEqual(e.data)}mutableCopy(){return new Ze(this.key,this.documentType,this.version,this.readTime,this.createTime,this.data.clone(),this.documentState)}toString(){return`Document(${this.key}, ${this.version}, ${JSON.stringify(this.data.value)}, {createTime: ${this.createTime}}), {documentType: ${this.documentType}}), {documentState: ${this.documentState}})`}}
436;/** 437 * @license 438 * Copyright 2019 Google LLC 439 * 440 * Licensed under the Apache License, Version 2.0 (the "License"); 441 * you may not use this file except in compliance with the License. 442 * You may obtain a copy of the License at 443 * 444 * http://www.apache.org/licenses/LICENSE-2.0 445 * 446 * Unless required by applicable law or agreed to in writing, software 447 * distributed under the License is distributed on an "AS IS" BASIS, 448 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 449 * See the License for the specific language governing permissions and 450 * limitations under the License. 451 */let tn=class tn{constructor(e,t=null,a=[],u=[],l=null,c=null,h=null){this.path=e,this.collectionGroup=t,this.orderBy=a,this.filters=u,this.limit=l,this.startAt=c,this.endAt=h,this.ft=null}};function en(e,t=null,a=[],u=[],l=null,c=null,h=null){return new tn(e,t,a,u,l,c,h)}function nn(e){if(null===e.ft){let t=e.path.canonicalString();null!==e.collectionGroup&&(t+="|cg:"+e.collectionGroup),t+="|f:"+e.filters.map(e=>De(e)).join(",")+"|ob:"+e.orderBy.map(e=>e.field.canonicalString()+e.dir).join(","),null==e.limit||(t+="|l:"+e.limit),e.startAt&&(t+="|lb:"+(e.startAt.inclusive?"b:":"a:")+e.startAt.position.map(e=>ue(e)).join(",")),e.endAt&&(t+="|ub:"+(e.endAt.inclusive?"a:":"b:")+e.endAt.position.map(e=>ue(e)).join(",")),e.ft=t}return e.ft}function sn(e,t){if(e.limit!==t.limit||e.orderBy.length!==t.orderBy.length)return!1;for(let a=0;a<e.orderBy.length;a++)if(!Ke(e.orderBy[a],t.orderBy[a]))return!1;if(e.filters.length!==t.filters.length)return!1;for(let a=0;a<e.filters.length;a++)if(!Ce(e.filters[a],t.filters[a]))return!1;return e.collectionGroup===t.collectionGroup&&!!e.path.isEqual(t.path)&&!!Ee(e.startAt,t.startAt)&&Ee(e.endAt,t.endAt)}function rn(e){return ct.isDocumentKey(e.path)&&null===e.collectionGroup&&0===e.filters.length}/** 452 * @license 453 * Copyright 2017 Google LLC 454 * 455 * Licensed under the Apache License, Version 2.0 (the "License"); 456 * you may not use this file except in compliance with the License. 457 * You may obtain a copy of the License at 458 * 459 * http://www.apache.org/licenses/LICENSE-2.0 460 * 461 * Unless required by applicable law or agreed to in writing, software 462 * distributed under the License is distributed on an "AS IS" BASIS, 463 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 464 * See the License for the specific language governing permissions and 465 * limitations under the License. 466 */let an=class an{constructor(e,t=null,a=[],u=[],l=null,c="F",h=null,d=null){this.path=e,this.collectionGroup=t,this.explicitOrderBy=a,this.filters=u,this.limit=l,this.limitType=c,this.startAt=h,this.endAt=d,this.dt=null,this._t=null,this.startAt,this.endAt}};function hn(e,t,a,u,l,c,h,d){return new an(e,t,a,u,l,c,h,d)}function ln(e){return new an(e)}function fn(e){return 0===e.filters.length&&null===e.limit&&null==e.startAt&&null==e.endAt&&(0===e.explicitOrderBy.length||1===e.explicitOrderBy.length&&e.explicitOrderBy[0].field.isKeyField())}function dn(e){return e.explicitOrderBy.length>0?e.explicitOrderBy[0].field:null}function _n(e){for(let t of e.filters){let e=t.getFirstInequalityField();if(null!==e)return e}return null}function wn(e){return null!==e.collectionGroup}function mn(e){if(null===e.dt){e.dt=[];let t=_n(e),a=dn(e);if(null!==t&&null===a)t.isKeyField()||e.dt.push(new Ue(t)),e.dt.push(new Ue(ut.keyField(),"asc"));else{let t=!1;for(let a of e.explicitOrderBy)e.dt.push(a),a.field.isKeyField()&&(t=!0);if(!t){let t=e.explicitOrderBy.length>0?e.explicitOrderBy[e.explicitOrderBy.length-1].dir:"asc";e.dt.push(new Ue(ut.keyField(),t))}}}return e.dt}function gn(e){if(!e._t){if("F"===e.limitType)e._t=en(e.path,e.collectionGroup,mn(e),e.filters,e.limit,e.startAt,e.endAt);else{let t=[];for(let a of mn(e)){let e="desc"===a.dir?"asc":"desc";t.push(new Ue(a.field,e))}let a=e.endAt?new Ie(e.endAt.position,e.endAt.inclusive):null,u=e.startAt?new Ie(e.startAt.position,e.startAt.inclusive):null;e._t=en(e.path,e.collectionGroup,t,e.filters,e.limit,a,u)}}return e._t}function yn(e,t){t.getFirstInequalityField(),_n(e);let a=e.filters.concat([t]);return new an(e.path,e.collectionGroup,e.explicitOrderBy.slice(),a,e.limit,e.limitType,e.startAt,e.endAt)}function pn(e,t,a){return new an(e.path,e.collectionGroup,e.explicitOrderBy.slice(),e.filters.slice(),t,a,e.startAt,e.endAt)}function In(e,t){return sn(gn(e),gn(t))&&e.limitType===t.limitType}function Tn(e){return`${nn(gn(e))}|lt:${e.limitType}`}function En(e){var t;let a;return`Query(target=${a=(t=gn(e)).path.canonicalString(),null!==t.collectionGroup&&(a+=" collectionGroup="+t.collectionGroup),t.filters.length>0&&(a+=`, filters: [${t.filters.map(e=>Ne(e)).join(", ")}]`),null==t.limit||(a+=", limit: "+t.limit),t.orderBy.length>0&&(a+=`, orderBy: [${t.orderBy.map(e=>`${e.field.canonicalString()} (${e.dir})`).join(", ")}]`),t.startAt&&(a+=", startAt: "+(t.startAt.inclusive?"b:":"a:")+t.startAt.position.map(e=>ue(e)).join(",")),t.endAt&&(a+=", endAt: "+(t.endAt.inclusive?"a:":"b:")+t.endAt.position.map(e=>ue(e)).join(",")),`Target(${a})`}; limitType=${e.limitType})`}function An(e,t){return t.isFoundDocument()&&function(e,t){let a=t.key.path;return null!==e.collectionGroup?t.key.hasCollectionId(e.collectionGroup)&&e.path.isPrefixOf(a):ct.isDocumentKey(e.path)?e.path.isEqual(a):e.path.isImmediateParentOf(a)}(e,t)&&function(e,t){for(let a of mn(e))if(!a.field.isKeyField()&&null===t.data.field(a.field))return!1;return!0}(e,t)&&function(e,t){for(let a of e.filters)if(!a.matches(t))return!1;return!0}(e,t)&&(!e.startAt||!!function(e,t,a){let u=Te(e,t,a);return e.inclusive?u<=0:u<0}(e.startAt,mn(e),t))&&(!e.endAt||!!function(e,t,a){let u=Te(e,t,a);return e.inclusive?u>=0:u>0}(e.endAt,mn(e),t))}function Rn(e){return e.collectionGroup||(e.path.length%2==1?e.path.lastSegment():e.path.get(e.path.length-2))}function bn(e){return(t,a)=>{let u=!1;for(let l of mn(e)){let e=Pn(l,t,a);if(0!==e)return e;u=u||l.field.isKeyField()}return 0}}function Pn(e,t,a){let u=e.field.isKeyField()?ct.comparator(t.key,a.key):function(e,t,a){let u=t.data.field(e),l=a.data.field(e);return null!==u&&null!==l?ie(u,l):O()}(e.field,t,a);switch(e.dir){case"asc":return u;case"desc":return -1*u;default:return O()}}/** 467 * @license 468 * Copyright 2020 Google LLC 469 * 470 * Licensed under the Apache License, Version 2.0 (the "License");
471 * you may not use this file except in compliance with the License. 472 * You may obtain a copy of the License at 473 * 474 * http://www.apache.org/licenses/LICENSE-2.0 475 * 476 * Unless required by applicable law or agreed to in writing, software 477 * distributed under the License is distributed on an "AS IS" BASIS, 478 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 479 * See the License for the specific language governing permissions and 480 * limitations under the License. 481 */function vn(e,t){if(e.wt){if(isNaN(t))return{doubleValue:"NaN"};if(t===1/0)return{doubleValue:"Infinity"};if(t===-1/0)return{doubleValue:"-Infinity"}}return{doubleValue:Ut(t)?"-0":t}}function Vn(e){return{integerValue:""+e}}function Sn(e,t){return Kt(t)?Vn(t):vn(e,t)}/** 482 * @license 483 * Copyright 2018 Google LLC 484 * 485 * Licensed under the Apache License, Version 2.0 (the "License"); 486 * you may not use this file except in compliance with the License. 487 * You may obtain a copy of the License at 488 * 489 * http://www.apache.org/licenses/LICENSE-2.0 490 * 491 * Unless required by applicable law or agreed to in writing, software 492 * distributed under the License is distributed on an "AS IS" BASIS, 493 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 494 * See the License for the specific language governing permissions and 495 * limitations under the License. 496 */let Dn=class Dn{constructor(){this._=void 0}};function Cn(e,t,a){return e instanceof kn?function(e,t){let a={fields:{__type__:{stringValue:"server_timestamp"},__local_write_time__:{timestampValue:{seconds:e.seconds,nanos:e.nanoseconds}}}};return t&&(a.fields.__previous_value__=t),{mapValue:a}}(a,t):e instanceof On?Mn(e,t):e instanceof Fn?$n(e,t):function(e,t){let a=Nn(e,t),u=Ln(a)+Ln(e.gt);return ae(a)&&ae(e.gt)?Vn(u):vn(e.yt,u)}(e,t)}function xn(e,t,a){return e instanceof On?Mn(e,t):e instanceof Fn?$n(e,t):a}function Nn(e,t){return e instanceof Bn?ae(t)||t&&"doubleValue"in t?t:{integerValue:0}:null}let kn=class kn extends Dn{};let On=class On extends Dn{constructor(e){super(),this.elements=e}};function Mn(e,t){let a=qn(t);for(let t of e.elements)a.some(e=>ne(e,t))||a.push(t);return{arrayValue:{values:a}}}let Fn=class Fn extends Dn{constructor(e){super(),this.elements=e}};function $n(e,t){let a=qn(t);for(let t of e.elements)a=a.filter(e=>!ne(e,t));return{arrayValue:{values:a}}}let Bn=class Bn extends Dn{constructor(e,t){super(),this.yt=e,this.gt=t}};function Ln(e){return zt(e.integerValue||e.doubleValue)}function qn(e){return he(e)&&e.arrayValue.values?e.arrayValue.values.slice():[]}/** 497 * @license 498 * Copyright 2017 Google LLC 499 * 500 * Licensed under the Apache License, Version 2.0 (the "License"); 501 * you may not use this file except in compliance with the License. 502 * You may obtain a copy of the License at 503 * 504 * http://www.apache.org/licenses/LICENSE-2.0 505 * 506 * Unless required by applicable law or agreed to in writing, software 507 * distributed under the License is distributed on an "AS IS" BASIS, 508 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 509 * See the License for the specific language governing permissions and 510 * limitations under the License. 511 */let Un=class Un{constructor(e,t){this.field=e,this.transform=t}};function Kn(e,t){var a,u;return e.field.isEqual(t.field)&&(a=e.transform,u=t.transform,a instanceof On&&u instanceof On||a instanceof Fn&&u instanceof Fn?tt(a.elements,u.elements,ne):a instanceof Bn&&u instanceof Bn?ne(a.gt,u.gt):a instanceof kn&&u instanceof kn)}let Gn=class Gn{constructor(e,t){this.version=e,this.transformResults=t}};let Qn=class Qn{constructor(e,t){this.updateTime=e,this.exists=t}static none(){return new Qn}static exists(e){return new Qn(void 0,e)}static updateTime(e){return new Qn(e)}get isNone(){return void 0===this.updateTime&&void 0===this.exists}isEqual(e){return this.exists===e.exists&&(this.updateTime?!!e.updateTime&&this.updateTime.isEqual(e.updateTime):!e.updateTime)}};function jn(e,t){return void 0!==e.updateTime?t.isFoundDocument()&&t.version.isEqual(e.updateTime):void 0===e.exists||e.exists===t.isFoundDocument()}let Wn=class Wn{};function zn(e,t){if(!e.hasLocalMutations||t&&0===t.fields.length)return null;if(null===t)return e.isNoDocument()?new is(e.key,Qn.none()):new Zn(e.key,e.data,Qn.none());{let a=e.data,u=Ye.empty(),l=new We(ut.comparator);for(let e of t.fields)if(!l.has(e)){let t=a.field(e);null===t&&e.length>1&&(e=e.popLast(),t=a.field(e)),null===t?u.delete(e):u.set(e,t),l=l.add(e)}
511return new ts(e.key,u,new Je(l.toArray()),Qn.none())}}function Hn(e,t,a){e instanceof Zn?function(e,t,a){let u=e.value.clone(),l=ns(e.fieldTransforms,t,a.transformResults);u.setAll(l),t.convertToFoundDocument(a.version,u).setHasCommittedMutations()}(e,t,a):e instanceof ts?function(e,t,a){if(!jn(e.precondition,t))return void t.convertToUnknownDocument(a.version);let u=ns(e.fieldTransforms,t,a.transformResults),l=t.data;l.setAll(es(e)),l.setAll(u),t.convertToFoundDocument(a.version,l).setHasCommittedMutations()}(e,t,a):function(e,t,a){t.convertToNoDocument(a.version).setHasCommittedMutations()}(0,t,a)}function Jn(e,t,a,u){return e instanceof Zn?function(e,t,a,u){if(!jn(e.precondition,t))return a;let l=e.value.clone(),c=ss(e.fieldTransforms,u,t);return l.setAll(c),t.convertToFoundDocument(t.version,l).setHasLocalMutations(),null}(e,t,a,u):e instanceof ts?function(e,t,a,u){if(!jn(e.precondition,t))return a;let l=ss(e.fieldTransforms,u,t),c=t.data;return(c.setAll(es(e)),c.setAll(l),t.convertToFoundDocument(t.version,c).setHasLocalMutations(),null===a)?null:a.unionWith(e.fieldMask.fields).unionWith(e.fieldTransforms.map(e=>e.field))}(e,t,a,u):jn(e.precondition,t)?(t.convertToNoDocument(t.version).setHasLocalMutations(),null):a}function Yn(e,t){let a=null;for(let u of e.fieldTransforms){let e=t.data.field(u.field),l=Nn(u.transform,e||null);null!=l&&(null===a&&(a=Ye.empty()),a.set(u.field,l))}return a||null}function Xn(e,t){var a,u;return e.type===t.type&&!!e.key.isEqual(t.key)&&!!e.precondition.isEqual(t.precondition)&&(a=e.fieldTransforms,u=t.fieldTransforms,!!(void 0===a&&void 0===u||!(!a||!u)&&tt(a,u,(e,t)=>Kn(e,t))))&&(0===e.type?e.value.isEqual(t.value):1!==e.type||e.data.isEqual(t.data)&&e.fieldMask.isEqual(t.fieldMask))}let Zn=class Zn extends Wn{constructor(e,t,a,u=[]){super(),this.key=e,this.value=t,this.precondition=a,this.fieldTransforms=u,this.type=0}getFieldMask(){return null}};let ts=class ts extends Wn{constructor(e,t,a,u,l=[]){super(),this.key=e,this.data=t,this.fieldMask=a,this.precondition=u,this.fieldTransforms=l,this.type=1}getFieldMask(){return this.fieldMask}};function es(e){let t=new Map;return e.fieldMask.fields.forEach(a=>{if(!a.isEmpty()){let u=e.data.field(a);t.set(a,u)}}),t}function ns(e,t,a){let u=new Map;e.length===a.length||O();for(let l=0;l<a.length;l++){let c=e[l],h=c.transform,d=t.data.field(c.field);u.set(c.field,xn(h,d,a[l]))}return u}function ss(e,t,a){let u=new Map;for(let l of e){let e=l.transform,c=a.data.field(l.field);u.set(l.field,Cn(e,c,t))}return u}let is=class is extends Wn{constructor(e,t){super(),this.key=e,this.precondition=t,this.type=2,this.fieldTransforms=[]}getFieldMask(){return null}};let rs=class rs extends Wn{constructor(e,t){super(),this.key=e,this.precondition=t,this.type=3,this.fieldTransforms=[]}getFieldMask(){return null}};/** 512 * @license 513 * Copyright 2017 Google LLC 514 * 515 * Licensed under the Apache License, Version 2.0 (the "License"); 516 * you may not use this file except in compliance with the License. 517 * You may obtain a copy of the License at 518 * 519 * http://www.apache.org/licenses/LICENSE-2.0 520 * 521 * Unless required by applicable law or agreed to in writing, software 522 * distributed under the License is distributed on an "AS IS" BASIS, 523 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 524 * See the License for the specific language governing permissions and 525 * limitations under the License. 526 */let os=class os{constructor(e){this.count=e}};function as(e){switch(e){default:return O();case v.CANCELLED:case v.UNKNOWN:case v.DEADLINE_EXCEEDED:case v.RESOURCE_EXHAUSTED:case v.INTERNAL:case v.UNAVAILABLE:case v.UNAUTHENTICATED:return!1;case v.INVALID_ARGUMENT:case v.NOT_FOUND:case v.ALREADY_EXISTS:case v.PERMISSION_DENIED:case v.FAILED_PRECONDITION:case v.ABORTED:case v.OUT_OF_RANGE:case v.UNIMPLEMENTED:case v.DATA_LOSS:return!0}}function hs(e){if(void 0===e)return x("GRPC error has no .code"),v.UNKNOWN;switch(e){case u.OK:return v.OK;case u.CANCELLED:return v.CANCELLED;case u.UNKNOWN:return v.UNKNOWN;case u.DEADLINE_EXCEEDED:return v.DEADLINE_EXCEEDED;case u.RESOURCE_EXHAUSTED:return v.RESOURCE_EXHAUSTED;case u.INTERNAL:return v.INTERNAL;case u.UNAVAILABLE:return v.UNAVAILABLE;case u.UNAUTHENTICATED:return v.UNAUTHENTICATED;case u.INVALID_ARGUMENT:return v.INVALID_ARGUMENT;case u.NOT_FOUND:return v.NOT_FOUND;case u.ALREADY_EXISTS:return v.ALREADY_EXISTS;case u.PERMISSION_DENIED:return v.PERMISSION_DENIED;case u.FAILED_PRECONDITION:return v.FAILED_PRECONDITION;case u.ABORTED:return v.ABORTED;case u.OUT_OF_RANGE:return v.OUT_OF_RANGE;
526case u.UNIMPLEMENTED:return v.UNIMPLEMENTED;case u.DATA_LOSS:return v.DATA_LOSS;default:return O()}}(l=u||(u={}))[l.OK=0]="OK",l[l.CANCELLED=1]="CANCELLED",l[l.UNKNOWN=2]="UNKNOWN",l[l.INVALID_ARGUMENT=3]="INVALID_ARGUMENT",l[l.DEADLINE_EXCEEDED=4]="DEADLINE_EXCEEDED",l[l.NOT_FOUND=5]="NOT_FOUND",l[l.ALREADY_EXISTS=6]="ALREADY_EXISTS",l[l.PERMISSION_DENIED=7]="PERMISSION_DENIED",l[l.UNAUTHENTICATED=16]="UNAUTHENTICATED",l[l.RESOURCE_EXHAUSTED=8]="RESOURCE_EXHAUSTED",l[l.FAILED_PRECONDITION=9]="FAILED_PRECONDITION",l[l.ABORTED=10]="ABORTED",l[l.OUT_OF_RANGE=11]="OUT_OF_RANGE",l[l.UNIMPLEMENTED=12]="UNIMPLEMENTED",l[l.INTERNAL=13]="INTERNAL",l[l.UNAVAILABLE=14]="UNAVAILABLE",l[l.DATA_LOSS=15]="DATA_LOSS";/** 527 * @license 528 * Copyright 2017 Google LLC 529 * 530 * Licensed under the Apache License, Version 2.0 (the "License"); 531 * you may not use this file except in compliance with the License. 532 * You may obtain a copy of the License at 533 * 534 * http://www.apache.org/licenses/LICENSE-2.0 535 * 536 * Unless required by applicable law or agreed to in writing, software 537 * distributed under the License is distributed on an "AS IS" BASIS, 538 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 539 * See the License for the specific language governing permissions and 540 * limitations under the License. 541 */let ls=class ls{constructor(e,t){this.mapKeyFn=e,this.equalsFn=t,this.inner={},this.innerSize=0}get(e){let t=this.mapKeyFn(e),a=this.inner[t];if(void 0!==a){for(let[t,u]of a)if(this.equalsFn(t,e))return u}}has(e){return void 0!==this.get(e)}set(e,t){let a=this.mapKeyFn(e),u=this.inner[a];if(void 0===u)return this.inner[a]=[[e,t]],void this.innerSize++;for(let a=0;a<u.length;a++)if(this.equalsFn(u[a][0],e))return void(u[a]=[e,t]);u.push([e,t]),this.innerSize++}delete(e){let t=this.mapKeyFn(e),a=this.inner[t];if(void 0===a)return!1;for(let u=0;u<a.length;u++)if(this.equalsFn(a[u][0],e))return 1===a.length?delete this.inner[t]:a.splice(u,1),this.innerSize--,!0;return!1}forEach(e){Bt(this.inner,(t,a)=>{for(let[t,u]of a)e(t,u)})}isEmpty(){return Lt(this.inner)}size(){return this.innerSize}};/** 542 * @license 543 * Copyright 2017 Google LLC 544 * 545 * Licensed under the Apache License, Version 2.0 (the "License"); 546 * you may not use this file except in compliance with the License. 547 * You may obtain a copy of the License at 548 * 549 * http://www.apache.org/licenses/LICENSE-2.0 550 * 551 * Unless required by applicable law or agreed to in writing, software 552 * distributed under the License is distributed on an "AS IS" BASIS, 553 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 554 * See the License for the specific language governing permissions and 555 * limitations under the License. 556 */let I=new Ge(ct.comparator),_=new Ge(ct.comparator);function ws(...e){let t=_;for(let a of e)t=t.insert(a.key,a);return t}function ms(e){let t=_;return e.forEach((e,a)=>t=t.insert(e,a.overlayedDocument)),t}function ps(){return new ls(e=>e.toString(),(e,t)=>e.isEqual(t))}let D=new Ge(ct.comparator),b=new We(ct.comparator);function Es(...e){let t=b;for(let a of e)t=t.add(a);return t}let R=new We(Z);/** 557 * @license 558 * Copyright 2017 Google LLC 559 * 560 * Licensed under the Apache License, Version 2.0 (the "License"); 561 * you may not use this file except in compliance with the License. 562 * You may obtain a copy of the License at 563 * 564 * http://www.apache.org/licenses/LICENSE-2.0 565 * 566 * Unless required by applicable law or agreed to in writing, software 567 * distributed under the License is distributed on an "AS IS" BASIS, 568 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 569 * See the License for the specific language governing permissions and 570 * limitations under the License. 571 */let bs=class bs{constructor(e,t,a,u,l){this.snapshotVersion=e,this.targetChanges=t,this.targetMismatches=a,this.documentUpdates=u,this.resolvedLimboDocuments=l}static createSynthesizedRemoteEventForCurrentChange(e,t,a){let u=new Map;return u.set(e,Ps.createSynthesizedTargetChangeForCurrentChange(e,t,a)),new bs(st.min(),u,R,I,Es())}};let Ps=class Ps{constructor(e,t,a,u,l){this.resumeToken=e,this.current=t,this.addedDocuments=a,this.modifiedDocuments=u,this.removedDocuments=l}static createSynthesizedTargetChangeForCurrentChange(e,t,a){return new Ps(a,t,Es(),Es(),Es())}};/** 572 * @license 573 * Copyright 2017 Google LLC 574 * 575 * Licensed under the Apache License, Version 2.0 (the "License");
576 * you may not use this file except in compliance with the License. 577 * You may obtain a copy of the License at 578 * 579 * http://www.apache.org/licenses/LICENSE-2.0 580 * 581 * Unless required by applicable law or agreed to in writing, software 582 * distributed under the License is distributed on an "AS IS" BASIS, 583 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 584 * See the License for the specific language governing permissions and 585 * limitations under the License. 586 */let vs=class vs{constructor(e,t,a,u){this.It=e,this.removedTargetIds=t,this.key=a,this.Tt=u}};let Vs=class Vs{constructor(e,t){this.targetId=e,this.Et=t}};let Ss=class Ss{constructor(e,t,a=Qt.EMPTY_BYTE_STRING,u=null){this.state=e,this.targetIds=t,this.resumeToken=a,this.cause=u}};let Ds=class Ds{constructor(){this.At=0,this.Rt=Ns(),this.bt=Qt.EMPTY_BYTE_STRING,this.Pt=!1,this.vt=!0}get current(){return this.Pt}get resumeToken(){return this.bt}get Vt(){return 0!==this.At}get St(){return this.vt}Dt(e){e.approximateByteSize()>0&&(this.vt=!0,this.bt=e)}Ct(){let e=Es(),t=Es(),a=Es();return this.Rt.forEach((u,l)=>{switch(l){case 0:e=e.add(u);break;case 2:t=t.add(u);break;case 1:a=a.add(u);break;default:O()}}),new Ps(this.bt,this.Pt,e,t,a)}xt(){this.vt=!1,this.Rt=Ns()}Nt(e,t){this.vt=!0,this.Rt=this.Rt.insert(e,t)}kt(e){this.vt=!0,this.Rt=this.Rt.remove(e)}Ot(){this.At+=1}Mt(){this.At-=1}Ft(){this.vt=!0,this.Pt=!0}};let Cs=class Cs{constructor(e){this.$t=e,this.Bt=new Map,this.Lt=I,this.qt=xs(),this.Ut=new We(Z)}Kt(e){for(let t of e.It)e.Tt&&e.Tt.isFoundDocument()?this.Gt(t,e.Tt):this.Qt(t,e.key,e.Tt);for(let t of e.removedTargetIds)this.Qt(t,e.key,e.Tt)}jt(e){this.forEachTarget(e,t=>{let a=this.Wt(t);switch(e.state){case 0:this.zt(t)&&a.Dt(e.resumeToken);break;case 1:a.Mt(),a.Vt||a.xt(),a.Dt(e.resumeToken);break;case 2:a.Mt(),a.Vt||this.removeTarget(t);break;case 3:this.zt(t)&&(a.Ft(),a.Dt(e.resumeToken));break;case 4:this.zt(t)&&(this.Ht(t),a.Dt(e.resumeToken));break;default:O()}})}forEachTarget(e,t){e.targetIds.length>0?e.targetIds.forEach(t):this.Bt.forEach((e,a)=>{this.zt(a)&&t(a)})}Jt(e){let t=e.targetId,a=e.Et.count,u=this.Yt(t);if(u){let e=u.target;if(rn(e)){if(0===a){let a=new ct(e.path);this.Qt(t,a,Ze.newNoDocument(a,st.min()))}else 1===a||O()}else this.Xt(t)!==a&&(this.Ht(t),this.Ut=this.Ut.add(t))}}Zt(e){let t=new Map;this.Bt.forEach((a,u)=>{let l=this.Yt(u);if(l){if(a.current&&rn(l.target)){let t=new ct(l.target.path);null!==this.Lt.get(t)||this.te(u,t)||this.Qt(u,t,Ze.newNoDocument(t,e))}a.St&&(t.set(u,a.Ct()),a.xt())}});let a=Es();this.qt.forEach((e,t)=>{let u=!0;t.forEachWhile(e=>{let t=this.Yt(e);return!t||2===t.purpose||(u=!1,!1)}),u&&(a=a.add(e))}),this.Lt.forEach((t,a)=>a.setReadTime(e));let u=new bs(e,t,this.Ut,this.Lt,a);return this.Lt=I,this.qt=xs(),this.Ut=new We(Z),u}Gt(e,t){if(!this.zt(e))return;let a=this.te(e,t.key)?2:0;this.Wt(e).Nt(t.key,a),this.Lt=this.Lt.insert(t.key,t),this.qt=this.qt.insert(t.key,this.ee(t.key).add(e))}Qt(e,t,a){if(!this.zt(e))return;let u=this.Wt(e);this.te(e,t)?u.Nt(t,1):u.kt(t),this.qt=this.qt.insert(t,this.ee(t).delete(e)),a&&(this.Lt=this.Lt.insert(t,a))}removeTarget(e){this.Bt.delete(e)}Xt(e){let t=this.Wt(e).Ct();return this.$t.getRemoteKeysForTarget(e).size+t.addedDocuments.size-t.removedDocuments.size}Ot(e){this.Wt(e).Ot()}Wt(e){let t=this.Bt.get(e);return t||(t=new Ds,this.Bt.set(e,t)),t}ee(e){let t=this.qt.get(e);return t||(t=new We(Z),this.qt=this.qt.insert(e,t)),t}zt(e){let t=null!==this.Yt(e);return t||C("WatchChangeAggregator","Detected inactive target",e),t}Yt(e){let t=this.Bt.get(e);return t&&t.Vt?null:this.$t.ne(e)}Ht(e){this.Bt.set(e,new Ds),this.$t.getRemoteKeysForTarget(e).forEach(t=>{this.Qt(e,t,null)})}te(e,t){return this.$t.getRemoteKeysForTarget(e).has(t)}};function xs(){return new Ge(ct.comparator)}function Ns(){return new Ge(ct.comparator)}/** 587 * @license 588 * Copyright 2017 Google LLC 589 * 590 * Licensed under the Apache License, Version 2.0 (the "License"); 591 * you may not use this file except in compliance with the License. 592 * You may obtain a copy of the License at 593 * 594 * http://www.apache.org/licenses/LICENSE-2.0 595 * 596 * Unless required by applicable law or agreed to in writing, softw
596are 597 * distributed under the License is distributed on an "AS IS" BASIS, 598 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 599 * See the License for the specific language governing permissions and 600 * limitations under the License. 601 */let V={asc:"ASCENDING",desc:"DESCENDING"},M={"<":"LESS_THAN","<=":"LESS_THAN_OR_EQUAL",">":"GREATER_THAN",">=":"GREATER_THAN_OR_EQUAL","==":"EQUAL","!=":"NOT_EQUAL","array-contains":"ARRAY_CONTAINS",in:"IN","not-in":"NOT_IN","array-contains-any":"ARRAY_CONTAINS_ANY"},F={and:"AND",or:"OR"};let Fs=class Fs{constructor(e,t){this.databaseId=e,this.wt=t}};function $s(e,t){return e.wt?`${new Date(1e3*t.seconds).toISOString().replace(/\.\d*/,"").replace("Z","")}.${("000000000"+t.nanoseconds).slice(-9)}Z`:{seconds:""+t.seconds,nanos:t.nanoseconds}}function Bs(e,t){return e.wt?t.toBase64():t.toUint8Array()}function Ls(e,t){return $s(e,t.toTimestamp())}function qs(e){return e||O(),st.fromTimestamp(function(e){let t=Wt(e);return new nt(t.seconds,t.nanos)}(e))}function Us(e,t){return new rt(["projects",e.projectId,"databases",e.database]).child("documents").child(t).canonicalString()}function Ks(e){let t=rt.fromString(e);return wi(t)||O(),t}function Gs(e,t){return Us(e.databaseId,t.path)}function Qs(e,t){let a=Ks(t);if(a.get(1)!==e.databaseId.projectId)throw new L(v.INVALID_ARGUMENT,"Tried to deserialize key from different project: "+a.get(1)+" vs "+e.databaseId.projectId);if(a.get(3)!==e.databaseId.database)throw new L(v.INVALID_ARGUMENT,"Tried to deserialize key from different database: "+a.get(3)+" vs "+e.databaseId.database);return new ct(Hs(a))}function js(e,t){return Us(e.databaseId,t)}function Ws(e){let t=Ks(e);return 4===t.length?rt.emptyPath():Hs(t)}function zs(e){return new rt(["projects",e.databaseId.projectId,"databases",e.databaseId.database]).canonicalString()}function Hs(e){return e.length>4&&"documents"===e.get(4)||O(),e.popFirst(5)}function Js(e,t,a){return{name:Gs(e,t),fields:a.value.mapValue.fields}}function Zs(e,t){let a;if("targetChange"in t){var u,l;t.targetChange;let c="NO_CHANGE"===(u=t.targetChange.targetChangeType||"NO_CHANGE")?0:"ADD"===u?1:"REMOVE"===u?2:"CURRENT"===u?3:"RESET"===u?4:O(),h=t.targetChange.targetIds||[],d=(l=t.targetChange.resumeToken,e.wt?(void 0===l||"string"==typeof l||O(),Qt.fromBase64String(l||"")):(void 0===l||l instanceof Uint8Array||O(),Qt.fromUint8Array(l||new Uint8Array))),m=t.targetChange.cause,p=m&&function(e){let t=void 0===e.code?v.UNKNOWN:hs(e.code);return new L(t,e.message||"")}(m);a=new Ss(c,h,d,p||null)}else if("documentChange"in t){t.documentChange;let u=t.documentChange;u.document,u.document.name,u.document.updateTime;let l=Qs(e,u.document.name),c=qs(u.document.updateTime),h=u.document.createTime?qs(u.document.createTime):st.min(),d=new Ye({mapValue:{fields:u.document.fields}}),m=Ze.newFoundDocument(l,c,h,d),p=u.targetIds||[],g=u.removedTargetIds||[];a=new vs(p,g,m.key,m)}else if("documentDelete"in t){t.documentDelete;let u=t.documentDelete;u.document;let l=Qs(e,u.document),c=u.readTime?qs(u.readTime):st.min(),h=Ze.newNoDocument(l,c),d=u.removedTargetIds||[];a=new vs([],d,h.key,h)}else if("documentRemove"in t){t.documentRemove;let u=t.documentRemove;u.document;let l=Qs(e,u.document),c=u.removedTargetIds||[];a=new vs([],c,l,null)}else{if(!("filter"in t))return O();{t.filter;let e=t.filter;e.targetId;let u=e.count||0,l=new os(u),c=e.targetId;a=new Vs(c,l)}}return a}function ti(e,t){var a;let u;if(t instanceof Zn)u={update:Js(e,t.key,t.value)};else if(t instanceof is)u={delete:Gs(e,t.key)};else if(t instanceof ts)u={update:Js(e,t.key,t.data),updateMask:_i(t.fieldMask)};else{if(!(t instanceof rs))return O();u={verify:Gs(e,t.key)}}return t.fieldTransforms.length>0&&(u.updateTransforms=t.fieldTransforms.map(e=>(function(e,t){let a=t.transform;if(a instanceof kn)return{fieldPath:t.field.canonicalString(),setToServerValue:"REQUEST_TIME"};if(a instanceof On)return{fieldPath:t.field.canonicalString(),appendMissingElements:{values:a.elements}};if(a instanceof Fn)return{fieldPath:t.field.canonicalString(),removeAllFromArray:{values:a.elements}};if(a instanceof Bn)return{fieldPath:t.field.canonicalString(),increment:a.gt};throw O()})(0,e))),t.precondition.isNone||(u.currentDocument=void 0!==(a=t.precondition).updateTime?{updateTime:Ls(e,a.updateTime)}:void 0!==a.exists?{exists:a.exists}:O()),u}function ni(e,t){return e&&e.length>0?(void 0!==t||O(),e.map(e=>{let a;return(a=e.updateTime?qs(e.updateTime):qs(t)).isEqual(st.min())&&(a=qs(t)),new Gn(a,e.transformResults||[])})):[]}function si(e,t){return{documents:[js(e,t.path)]}}function ii(e,t){var a,u,l;let c={structuredQuery:{}},h=t.path;null!==t.collectionGroup?(c.parent=js(e,h),c.structuredQuery.from=[{collectionId:t.collectionGroup,allDescendants:!0}]):(c.parent=js(e,h.popLast()),c.structuredQuery.from=[{collectionId:h.lastSegment()}]);let d=function(e){if(0!==e.length)return di(be.create(e,"and"))}(t.filters);d&&(c.structuredQuery.where=d);let m=function(e){if(0!==e.length)return e.map(e=>({field:li(e.field),direction:ci(e.dir)}))}(t.orderBy);m&&(c.structuredQuery.orderBy=m);let p=(u=t.limit,e.wt||null==u?u:{value:u});return null!==p&&(c.structuredQuery.limit=p),t.startAt&&(c.structuredQuery.startAt={before:(a=t.startAt).inclusive,values:a.position}),t.endAt&&(c.structuredQuery.endAt={before:!(l=t.endAt).inclusive,values:l.position}),c}function ri(e){var t;let a,u=Ws(e.parent),l=e.structuredQuery,c=l.from?l.from.length:0,h=null;if(c>0){1===c||O();let e=l.from[0];e.allDescendants?h=e.collectionId:u=u.child(e.collectionId)}let d=[];l.where&&(d=function(e){var t;let a=ui(e);return a instanceof be&&Se(t=a)&&Pe(t)?a.getFilters():[a]}(l.where));let m=[];l.orderBy&&(m=l.orderBy.map(e=>new Ue(fi(e.field),function(e){switch(e){case"ASCENDING":return"asc";case"DESCENDING":return"desc";default:return}}(e.direction))));let p=null;l.limit&&(p=null==(a="object"==typeof(t=l.limit)?t.value:t)?null:a);let g=null;l.startAt&&(g=function(e){let t=!!e.before,a=e.values||[];return new Ie(a,t)}(l.startAt));let y=null;return l.endAt&&(y=function(e){let t=!e.before,a=e.values||[];return new Ie(a,t)}(l.endAt)),hn(u,h,m,d,p,"F",g,y)}function oi(e,t){let a=function(e,t){switch(t){case 0:return null;case 1:return"existence-filter-mismatch";case 2:return"limbo-document";default:return O()}}(0,t.purpose);return null==a?null:{"goog-listen-tags":a}}function ui(e){return void 0!==e.unaryFilter?function(e){switch(e.unaryFilter.op){case"IS_NAN":let t=fi(e.unaryFilter.field);return Re.create(t,"==",{doubleValue:NaN});case"IS_NULL":let a=fi(e.unaryFilter.field);return Re.create(a,"==",{nullValue:"NULL_VALUE"});
601case"IS_NOT_NAN":let u=fi(e.unaryFilter.field);return Re.create(u,"!=",{doubleValue:NaN});case"IS_NOT_NULL":let l=fi(e.unaryFilter.field);return Re.create(l,"!=",{nullValue:"NULL_VALUE"});default:return O()}}(e):void 0!==e.fieldFilter?Re.create(fi(e.fieldFilter.field),function(e){switch(e){case"EQUAL":return"==";case"NOT_EQUAL":return"!=";case"GREATER_THAN":return">";case"GREATER_THAN_OR_EQUAL":return">=";case"LESS_THAN":return"<";case"LESS_THAN_OR_EQUAL":return"<=";case"ARRAY_CONTAINS":return"array-contains";case"IN":return"in";case"NOT_IN":return"not-in";case"ARRAY_CONTAINS_ANY":return"array-contains-any";default:return O()}}(e.fieldFilter.op),e.fieldFilter.value):void 0!==e.compositeFilter?be.create(e.compositeFilter.filters.map(e=>ui(e)),function(e){switch(e){case"AND":return"and";case"OR":return"or";default:return O()}}(e.compositeFilter.op)):O()}function ci(e){return V[e]}function ai(e){return M[e]}function hi(e){return F[e]}function li(e){return{fieldPath:e.canonicalString()}}function fi(e){return ut.fromServerFormat(e.fieldPath)}function di(e){return e instanceof Re?function(e){if("=="===e.op){if(fe(e.value))return{unaryFilter:{field:li(e.field),op:"IS_NAN"}};if(le(e.value))return{unaryFilter:{field:li(e.field),op:"IS_NULL"}}}else if("!="===e.op){if(fe(e.value))return{unaryFilter:{field:li(e.field),op:"IS_NOT_NAN"}};if(le(e.value))return{unaryFilter:{field:li(e.field),op:"IS_NOT_NULL"}}}return{fieldFilter:{field:li(e.field),op:ai(e.op),value:e.value}}}(e):e instanceof be?function(e){let t=e.getFilters().map(e=>di(e));return 1===t.length?t[0]:{compositeFilter:{op:hi(e.op),filters:t}}}(e):O()}function _i(e){let t=[];return e.fields.forEach(e=>t.push(e.canonicalString())),{fieldPaths:t}}function wi(e){return e.length>=4&&"projects"===e.get(0)&&"databases"===e.get(2)}/** 602 * @license 603 * Copyright 2017 Google LLC 604 * 605 * Licensed under the Apache License, Version 2.0 (the "License"); 606 * you may not use this file except in compliance with the License. 607 * You may obtain a copy of the License at 608 * 609 * http://www.apache.org/licenses/LICENSE-2.0 610 * 611 * Unless required by applicable law or agreed to in writing, software 612 * distributed under the License is distributed on an "AS IS" BASIS, 613 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 614 * See the License for the specific language governing permissions and 615 * limitations under the License. 616 */let Qi=class Qi{constructor(e,t,a,u){this.batchId=e,this.localWriteTime=t,this.baseMutations=a,this.mutations=u}applyToRemoteDocument(e,t){let a=t.mutationResults;for(let t=0;t<this.mutations.length;t++){let u=this.mutations[t];u.key.isEqual(e.key)&&Hn(u,e,a[t])}}applyToLocalView(e,t){for(let a of this.baseMutations)a.key.isEqual(e.key)&&(t=Jn(a,e,t,this.localWriteTime));for(let a of this.mutations)a.key.isEqual(e.key)&&(t=Jn(a,e,t,this.localWriteTime));return t}applyToLocalDocumentSet(e,t){let a=ps();return this.mutations.forEach(u=>{let l=e.get(u.key),c=l.overlayedDocument,h=this.applyToLocalView(c,l.mutatedFields);h=t.has(u.key)?null:h;let d=zn(c,h);null!==d&&a.set(u.key,d),c.isValidDocument()||c.convertToNoDocument(st.min())}),a}keys(){return this.mutations.reduce((e,t)=>e.add(t.key),Es())}isEqual(e){return this.batchId===e.batchId&&tt(this.mutations,e.mutations,(e,t)=>Xn(e,t))&&tt(this.baseMutations,e.baseMutations,(e,t)=>Xn(e,t))}};let ji=class ji{constructor(e,t,a,u){this.batch=e,this.commitVersion=t,this.mutationResults=a,this.docVersions=u}static from(e,t,a){e.mutations.length===a.length||O();let u=D,l=e.mutations;for(let e=0;e<l.length;e++)u=u.insert(l[e].key,a[e].version);return new ji(e,t,a,u)}};/** 617 * @license 618 * Copyright 2022 Google LLC 619 * 620 * Licensed under the Apache License, Version 2.0 (the "License"); 621 * you may not use this file except in compliance with the License. 622 * You may obtain a copy of the License at 623 * 624 * http://www.apache.org/licenses/LICENSE-2.0 625 * 626 * Unless required by applicable law or agreed to in writing, software 627 * distributed under the License is distributed on an "AS IS" BASIS, 628 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 629 * See the License for the specific language governing permissions and 630 * limitations under the License. 631 */let Wi=class Wi{constructor(e,t){this.largestBatchId=e,this.mutation=t}getKey(){return this.mutation.key}isEqual(e){return null!==e&&this.mutation===e.mutation}toString(){return`Overlay{ 632 largestBatchId: ${this.largestBatchId}, 633 mutation: ${this.mutation.toString()} 634 }`}};/** 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 */let zi=class zi{constructor(e,t,a,u,l=st.min(),c=st.min(),h=Qt.EMPTY_BYTE_STRING){this.target=e,this.targetId=t,this.purpose=a,this.sequenceNumber=u,this.snapshotVersion=l,this.lastLimboFreeSnapshotVersion=c,this.resumeToken=h}withSequenceNumber(e){return new zi(this.target,this.targetId,this.purpose,e,this.snapshotVersion,this.lastLimboFreeSnapshotVersion,this.resumeToken)}withResumeToken(e,t){return new zi(this.target,this.targetId,this.purpose,this.sequenceNumber,t,this.lastLimboFreeSnapshotVersion,e)}withLastLimboFreeSnapshotVersion(e){return new zi(this.target,this.targetId,this.purpose,this.sequenceNumber,this.snapshotVersion,e,this.resumeToken)}};/** 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 */let Hi=class Hi{constructor(e){this.ie=e}};function ir(e){let t=ri({parent:e.parent,structuredQuery:e.structuredQuery});return"LAST"===e.limitType?pn(t,t.limit,"L"):t}/** 665 * @license 666 * Copyright 2021 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 */let dr=class dr{constructor(){}ue(e,t){this.ce(e,t),t.ae()}ce(e,t){if("nullValue"in e)this.he(t,5);else if("booleanValue"in e)this.he(t,10),t.le(e.booleanValue?1:0);else if("integerValue"in e)this.he(t,15),t.le(zt(e.integerValue));else if("doubleValue"in e){let a=zt(e.doubleValue);isNaN(a)?this.he(t,13):(this.he(t,15),Ut(a)?t.le(0):t.le(a))}else if("timestampValue"in e){let a=e.timestampValue;this.he(t,20),"string"==typeof a?t.fe(a):(t.fe(`${a.seconds||""}`),t.le(a.nanos||0))}else if("stringValue"in e)this.de(e.stringValue,t),this._e(t);else if("bytesValue"in e)this.he(t,30),t.we(Ht(e.bytesValue)),this._e(t);else if("referenceValue"in e)this.me(e.referenceValue,t);else if("geoPointValue"in e){let a=e.geoPointValue;this.he(t,45),t.le(a.latitude||0),t.le(a.longitude||0)}else"mapValue"in e?we(e)?this.he(t,Number.MAX_SAFE_INTEGER):(this.ge(e.mapValue,t),this._e(t)):"arrayValue"in e?(this.ye(e.arrayValue,t),this._e(t)):O()}de(e,t){this.he(t,25),this.pe(e,t)}pe(e,t){t.fe(e)}ge(e,t){let a=e.fields||{};for(let e of(this.he(t,55),Object.keys(a)))this.de(e,t),this.ce(a[e],t)}ye(e,t){let a=e.values||[];for(let e of(this.he(t,50),a))this.ce(e,t)}me(e,t){this.he(t,37),ct.fromName(e).path.forEach(e=>{this.he(t,60),this.pe(e,t)})}he(e,t){e.le(t)}_e(e){e.le(2)}};dr.Ie=new dr;/** 680 * @license 681 * Copyright 2019 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, softw
689are 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 */let Nr=class Nr{constructor(){this.Je=new kr}addToCollectionParentIndex(e,t){return this.Je.add(t),At.resolve()}getCollectionParents(e,t){return At.resolve(this.Je.getEntries(t))}addFieldIndex(e,t){return At.resolve()}deleteFieldIndex(e,t){return At.resolve()}getDocumentsMatchingTarget(e,t){return At.resolve(null)}getIndexType(e,t){return At.resolve(0)}getFieldIndexes(e,t){return At.resolve([])}getNextCollectionGroupToUpdate(e){return At.resolve(null)}getMinOffset(e,t){return At.resolve(yt.min())}getMinOffsetFromCollectionGroup(e,t){return At.resolve(yt.min())}updateCollectionGroup(e,t,a){return At.resolve()}updateIndexEntries(e,t){return At.resolve()}};let kr=class kr{constructor(){this.index={}}add(e){let t=e.lastSegment(),a=e.popLast(),u=this.index[t]||new We(rt.comparator),l=!u.has(a);return this.index[t]=u.add(a),l}has(e){let t=e.lastSegment(),a=e.popLast(),u=this.index[t];return u&&u.has(a)}getEntries(e){return(this.index[e]||new We(rt.comparator)).toArray()}};new Uint8Array(0);let Kr=class Kr{constructor(e,t,a){this.cacheSizeCollectionThreshold=e,this.percentileToCollect=t,this.maximumSequenceNumbersToCollect=a}static withCacheSize(e){return new Kr(e,Kr.DEFAULT_COLLECTION_PERCENTILE,Kr.DEFAULT_MAX_SEQUENCE_NUMBERS_TO_COLLECT)}};/** 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 */Kr.DEFAULT_COLLECTION_PERCENTILE=10,Kr.DEFAULT_MAX_SEQUENCE_NUMBERS_TO_COLLECT=1e3,Kr.DEFAULT=new Kr(41943040,Kr.DEFAULT_COLLECTION_PERCENTILE,Kr.DEFAULT_MAX_SEQUENCE_NUMBERS_TO_COLLECT),Kr.DISABLED=new Kr(-1,0,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 */let Yr=class Yr{constructor(e){this.bn=e}next(){return this.bn+=2,this.bn}static Pn(){return new Yr(0)}static vn(){return new Yr(-1)}};/** 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 */let co=class co{constructor(){this.changes=new ls(e=>e.toString(),(e,t)=>e.isEqual(t)),this.changesApplied=!1}addEntry(e){this.assertNotApplied(),this.changes.set(e.key,e)}removeEntry(e,t){this.assertNotApplied(),this.changes.set(e,Ze.newInvalidDocument(e).setReadTime(t))}getEntry(e,t){this.assertNotApplied();let a=this.changes.get(t);return void 0!==a?At.resolve(a):this.getFromCache(e,t)}getEntries(e,t){return this.getAllFromCache(e,t)}apply(e){return this.assertNotApplied(),this.changesApplied=!0,this.applyChanges(e)}
739assertNotApplied(){}};/** 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 *//** 755 * @license 756 * Copyright 2022 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 */let yo=class yo{constructor(e,t){this.overlayedDocument=e,this.mutatedFields=t}};/** 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 */let po=class po{constructor(e,t,a,u){this.remoteDocumentCache=e,this.mutationQueue=t,this.documentOverlayCache=a,this.indexManager=u}getDocument(e,t){let a=null;return this.documentOverlayCache.getOverlay(e,t).next(u=>(a=u,this.remoteDocumentCache.getEntry(e,t))).next(e=>(null!==a&&Jn(a.mutation,e,Je.empty(),nt.now()),e))}getDocuments(e,t){return this.remoteDocumentCache.getEntries(e,t).next(t=>this.getLocalViewOfDocuments(e,t,Es()).next(()=>t))}getLocalViewOfDocuments(e,t,a=Es()){let u=ps();return this.populateOverlays(e,u,t).next(()=>this.computeViews(e,t,u,a).next(e=>{let t=ws();return e.forEach((e,a)=>{t=t.insert(e,a.overlayedDocument)}),t}))}getOverlayedDocuments(e,t){let a=ps();return this.populateOverlays(e,a,t).next(()=>this.computeViews(e,t,a,Es()))}populateOverlays(e,t,a){let u=[];return a.forEach(e=>{t.has(e)||u.push(e)}),this.documentOverlayCache.getOverlays(e,u).next(e=>{e.forEach((e,a)=>{t.set(e,a)})})}computeViews(e,t,a,u){let l=I,c=ps(),h=ps();return t.forEach((e,t)=>{let h=a.get(t.key);u.has(t.key)&&(void 0===h||h.mutation instanceof ts)?l=l.insert(t.key,t):void 0!==h?(c.set(t.key,h.mutation.getFieldMask()),Jn(h.mutation,t,h.mutation.getFieldMask(),nt.now())):c.set(t.key,Je.empty())}),this.recalculateAndSaveOverlays(e,l).next(e=>(e.forEach((e,t)=>c.set(e,t)),t.forEach((e,t)=>{var a;return h.set(e,new yo(t,null!==(a=c.get(e))&&void 0!==a?a:null))}),h))}recalculateAndSaveOverlays(e,t){let a=ps(),u=new Ge((e,t)=>e-t),l=Es();return this.mutationQueue.getAllMutationBatchesAffectingDocumentKeys(e,t).next(e=>{for(let l of e)l.keys().forEach(e=>{let c=t.get(e);if(null===c)return;let h=a.get(e)||Je.empty();h=l.applyToLocalView(c,h),a.set(e,h);let d=(u.get(l.batchId)||Es()).add(e);u=u.insert(l.batchId,d)})}).next(()=>{let c=[],h=u.getReverseIterator();for(;h.hasNext();){let u=h.getNext(),d=u.key,m=u.value,p=ps();m.forEach(e=>{if(!l.has(e)){let u=zn(t.get(e),a.get(e));null!==u&&p.set(e,u),l=l.add(e)}}),c.push(this.documentOverlayCache.saveOverlays(e,d,p))}return At.waitFor(c)}).next(()=>a)}recalculateAndSaveOverlaysForDocumentKeys(e,t){return this.remoteDocumentCache.getEntries(e,t).next(t=>this.recalculateAndSaveOverlays(e,t))}getDocumentsMatchingQuery(e,t,a){return ct.isDocumentKey(t.path)&&null===t.collectionGroup&&0===t.filters.length?this.getDocumentsMatchingDocumentQuery(e,t.path):wn(t)?this.getDocumentsMatchingCollectionGroupQuery(e,t,a):this.getDocumentsMatchingCollectionQuery(e,t,a)}getNextDocuments(e,t,a,u){return this.remoteDocumentCache.getAllFromCollectionGroup(e,t,a,u).next(l=>{let c=u-l.size>0?this.documentOverlayCache.getOverlaysForCollectionGroup(e,t,a.largestBatchId,u-l.size):At.resolve(ps()),h=-1,d=l;return c.next(t=>At.forEach(t,(t,a)=>(h<a.largestBatchId&&(h=a.largestBatchId),l.get(t)?At.resolve():this.remoteDocumentCache.getEntry(e,t).next(e=>{d=d.insert(t,e)}))).next(()=>this.populateOverlays(e,t,l)).next(()=>this.computeViews(e,d,t,Es())).next(e=>({batchId:h,changes:ms(e)})))})}getDocumentsMatchingDocumentQuery(e,t){return this.getDocument(e,new ct(t)).next(e=>{let t=ws();
784return e.isFoundDocument()&&(t=t.insert(e.key,e)),t})}getDocumentsMatchingCollectionGroupQuery(e,t,a){let u=t.collectionGroup,l=ws();return this.indexManager.getCollectionParents(e,u).next(c=>At.forEach(c,c=>{let h=new an(c.child(u),null,t.explicitOrderBy.slice(),t.filters.slice(),t.limit,t.limitType,t.startAt,t.endAt);return this.getDocumentsMatchingCollectionQuery(e,h,a).next(e=>{e.forEach((e,t)=>{l=l.insert(e,t)})})}).next(()=>l))}getDocumentsMatchingCollectionQuery(e,t,a){let u;return this.documentOverlayCache.getOverlaysForCollection(e,t.path,a.largestBatchId).next(l=>(u=l,this.remoteDocumentCache.getDocumentsMatchingQuery(e,t,a,u))).next(e=>{u.forEach((t,a)=>{let u=a.getKey();null===e.get(u)&&(e=e.insert(u,Ze.newInvalidDocument(u)))});let a=ws();return e.forEach((e,l)=>{let c=u.get(e);void 0!==c&&Jn(c.mutation,l,Je.empty(),nt.now()),An(t,l)&&(a=a.insert(e,l))}),a})}};/** 785 * @license 786 * Copyright 2020 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 */let Io=class Io{constructor(e){this.yt=e,this.Zn=new Map,this.ts=new Map}getBundleMetadata(e,t){return At.resolve(this.Zn.get(t))}saveBundleMetadata(e,t){return this.Zn.set(t.id,{id:t.id,version:t.version,createTime:qs(t.createTime)}),At.resolve()}getNamedQuery(e,t){return At.resolve(this.ts.get(t))}saveNamedQuery(e,t){return this.ts.set(t.name,{name:t.name,query:ir(t.bundledQuery),readTime:qs(t.readTime)}),At.resolve()}};/** 800 * @license 801 * Copyright 2022 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 */let To=class To{constructor(){this.overlays=new Ge(ct.comparator),this.es=new Map}getOverlay(e,t){return At.resolve(this.overlays.get(t))}getOverlays(e,t){let a=ps();return At.forEach(t,t=>this.getOverlay(e,t).next(e=>{null!==e&&a.set(t,e)})).next(()=>a)}saveOverlays(e,t,a){return a.forEach((a,u)=>{this.oe(e,t,u)}),At.resolve()}removeOverlaysForBatchId(e,t,a){let u=this.es.get(a);return void 0!==u&&(u.forEach(e=>this.overlays=this.overlays.remove(e)),this.es.delete(a)),At.resolve()}getOverlaysForCollection(e,t,a){let u=ps(),l=t.length+1,c=new ct(t.child("")),h=this.overlays.getIteratorFrom(c);for(;h.hasNext();){let e=h.getNext().value,c=e.getKey();if(!t.isPrefixOf(c.path))break;c.path.length===l&&e.largestBatchId>a&&u.set(e.getKey(),e)}return At.resolve(u)}getOverlaysForCollectionGroup(e,t,a,u){let l=new Ge((e,t)=>e-t),c=this.overlays.getIterator();for(;c.hasNext();){let e=c.getNext().value;if(e.getKey().getCollectionGroup()===t&&e.largestBatchId>a){let t=l.get(e.largestBatchId);null===t&&(t=ps(),l=l.insert(e.largestBatchId,t)),t.set(e.getKey(),e)}}let h=ps(),d=l.getIterator();for(;d.hasNext()&&(d.getNext().value.forEach((e,t)=>h.set(e,t)),!(h.size()>=u)););return At.resolve(h)}oe(e,t,a){let u=this.overlays.get(a.key);if(null!==u){let e=this.es.get(u.largestBatchId).delete(a.key);this.es.set(u.largestBatchId,e)}this.overlays=this.overlays.insert(a.key,new Wi(t,a));let l=this.es.get(t);void 0===l&&(l=Es(),this.es.set(t,l)),this.es.set(t,l.add(a.key))}};/** 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 Eo=class Eo{constructor(){this.ns=new We(Ao.ss),this.rs=new We(Ao.os)}isEmpty(){return this.ns.isEmpty()}addReference(e,t){let a=new Ao(e,t);this.ns=this.ns.add(a),this.rs=this.rs.add(a)}us(e,t){e.forEach(e=>this.addReference(e,t))}removeReference(e,t){this.cs(new Ao(e,t))}hs(e,t){e.forEach(e=>this.removeReference(e,t))}ls(e){let t=new ct(new rt([])),a=new Ao(t,e),u=new Ao(t,e+1),l=[];return this.rs.forEachInRange([a,u],e=>{this.cs(e),l.push(e.key)}),l}fs(){this.ns.forEach(e=>this.cs(e))}cs(e){this.ns=this.ns.delete(e),this.rs=this.rs.delete(e)}ds(e){let t=new ct(new rt([])),a=new Ao(t,e),u=new Ao(t,e+1),l=Es();return this.rs.forEachInRange([a,u],e=>{l=l.add(e.key)}),l}containsKey(e){let t=new Ao(e,0),a=this.ns.firstAfterOrEqual(t);return null!==a&&e.isEqual(a.key)}};let Ao=class Ao{constructor(e,t){this.key=e,this._s=t}static ss(e,t){return ct.comparator(e.key,t.key)||Z(e._s,t._s)}static os(e,t){return Z(e._s,t._s)||ct.comparator(e.key,t.key)}};/** 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 */let Ro=class Ro{constructor(e,t){this.indexManager=e,this.referenceDelegate=t,this.mutationQueue=[],this.ws=1,this.gs=new We(Ao.ss)}checkEmpty(e){return At.resolve(0===this.mutationQueue.length)}addMutationBatch(e,t,a,u){let l=this.ws;this.ws++,this.mutationQueue.length>0&&this.mutationQueue[this.mutationQueue.length-1];let c=new Qi(l,t,a,u);for(let t of(this.mutationQueue.push(c),u))this.gs=this.gs.add(new Ao(t.key,l)),this.indexManager.addToCollectionParentIndex(e,t.key.path.popLast());return At.resolve(c)}lookupMutationBatch(e,t){return At.resolve(this.ys(t))}getNextMutationBatchAfterBatchId(e,t){let a=this.ps(t+1),u=a<0?0:a;return At.resolve(this.mutationQueue.length>u?this.mutationQueue[u]:null)}getHighestUnacknowledgedBatchId(){return At.resolve(0===this.mutationQueue.length?-1:this.ws-1)}getAllMutationBatches(e){return At.resolve(this.mutationQueue.slice())}getAllMutationBatchesAffectingDocumentKey(e,t){let a=new Ao(t,0),u=new Ao(t,Number.POSITIVE_INFINITY),l=[];return this.gs.forEachInRange([a,u],e=>{let t=this.ys(e._s);l.push(t)}),At.resolve(l)}getAllMutationBatchesAffectingDocumentKeys(e,t){let a=new We(Z);return t.forEach(e=>{let t=new Ao(e,0),u=new Ao(e,Number.POSITIVE_INFINITY);this.gs.forEachInRange([t,u],e=>{a=a.add(e._s)})}),At.resolve(this.Is(a))}getAllMutationBatchesAffectingQuery(e,t){let a=t.path,u=a.length+1,l=a;ct.isDocumentKey(l)||(l=l.child(""));let c=new Ao(new ct(l),0),h=new We(Z);return this.gs.forEachWhile(e=>{let t=e.key.path;return!!a.isPrefixOf(t)&&(t.length===u&&(h=h.add(e._s)),!0)},c),At.resolve(this.Is(h))}Is(e){let t=[];return e.forEach(e=>{let a=this.ys(e);null!==a&&t.push(a)}),t}removeMutationBatch(e,t){0===this.Ts(t.batchId,"removed")||O(),this.mutationQueue.shift();let a=this.gs;return At.forEach(t.mutations,u=>{let l=new Ao(u.key,t.batchId);return a=a.delete(l),this.referenceDelegate.markPotentiallyOrphaned(e,u.key)}).next(()=>{this.gs=a})}An(e){}containsKey(e,t){let a=new Ao(t,0),u=this.gs.firstAfterOrEqual(a);return At.resolve(t.isEqual(u&&u.key))}
844performConsistencyCheck(e){return this.mutationQueue.length,At.resolve()}Ts(e,t){return this.ps(e)}ps(e){return 0===this.mutationQueue.length?0:e-this.mutationQueue[0].batchId}ys(e){let t=this.ps(e);return t<0||t>=this.mutationQueue.length?null:this.mutationQueue[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 */let bo=class bo{constructor(e){this.Es=e,this.docs=new Ge(ct.comparator),this.size=0}setIndexManager(e){this.indexManager=e}addEntry(e,t){let a=t.key,u=this.docs.get(a),l=u?u.size:0,c=this.Es(t);return this.docs=this.docs.insert(a,{document:t.mutableCopy(),size:c}),this.size+=c-l,this.indexManager.addToCollectionParentIndex(e,a.path.popLast())}removeEntry(e){let t=this.docs.get(e);t&&(this.docs=this.docs.remove(e),this.size-=t.size)}getEntry(e,t){let a=this.docs.get(t);return At.resolve(a?a.document.mutableCopy():Ze.newInvalidDocument(t))}getEntries(e,t){let a=I;return t.forEach(e=>{let t=this.docs.get(e);a=a.insert(e,t?t.document.mutableCopy():Ze.newInvalidDocument(e))}),At.resolve(a)}getDocumentsMatchingQuery(e,t,a,u){let l=I,c=t.path,h=new ct(c.child("")),d=this.docs.getIteratorFrom(h);for(;d.hasNext();){let{key:e,value:{document:h}}=d.getNext();if(!c.isPrefixOf(e.path))break;e.path.length>c.length+1||0>=pt(gt(h),a)||(u.has(h.key)||An(t,h))&&(l=l.insert(h.key,h.mutableCopy()))}return At.resolve(l)}getAllFromCollectionGroup(e,t,a,u){O()}As(e,t){return At.forEach(this.docs,e=>t(e))}newChangeBuffer(e){return new Po(this)}getSize(e){return At.resolve(this.size)}};let Po=class Po extends co{constructor(e){super(),this.Yn=e}applyChanges(e){let t=[];
vendor: 4,870 bytes, lines 859-889
859return this.changes.forEach((a,u)=>{u.isValidDocument()?t.push(this.Yn.addEntry(e,u)):this.Yn.removeEntry(a)}),At.waitFor(t)}getFromCache(e,t){return this.Yn.getEntry(e,t)}getAllFromCache(e,t){return this.Yn.getEntries(e,t)}};/** 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 */let vo=class vo{constructor(e){this.persistence=e,this.Rs=new ls(e=>nn(e),sn),this.lastRemoteSnapshotVersion=st.min(),this.highestTargetId=0,this.bs=0,this.Ps=new Eo,this.targetCount=0,this.vs=Yr.Pn()}forEachTarget(e,t){return this.Rs.forEach((e,a)=>t(a)),At.resolve()}getLastRemoteSnapshotVersion(e){return At.resolve(this.lastRemoteSnapshotVersion)}getHighestSequenceNumber(e){return At.resolve(this.bs)}allocateTargetId(e){return this.highestTargetId=this.vs.next(),At.resolve(this.highestTargetId)}setTargetsMetadata(e,t,a){return a&&(this.lastRemoteSnapshotVersion=a),t>this.bs&&(this.bs=t),At.resolve()}Dn(e){this.Rs.set(e.target,e);let t=e.targetId;t>this.highestTargetId&&(this.vs=new Yr(t),this.highestTargetId=t),e.sequenceNumber>this.bs&&(this.bs=e.sequenceNumber)}addTargetData(e,t){return this.Dn(t),this.targetCount+=1,At.resolve()}updateTargetData(e,t){return this.Dn(t),At.resolve()}removeTargetData(e,t){return this.Rs.delete(t.target),this.Ps.ls(t.targetId),this.targetCount-=1,At.resolve()}removeTargets(e,t,a){let u=0,l=[];return this.Rs.forEach((c,h)=>{h.sequenceNumber<=t&&null===a.get(h.targetId)&&(this.Rs.delete(c),l.push(this.removeMatchingKeysForTargetId(e,h.targetId)),u++)}),At.waitFor(l).next(()=>u)}getTargetCount(e){return At.resolve(this.targetCount)}getTargetData(e,t){let a=this.Rs.get(t)||null;return At.resolve(a)}addMatchingKeys(e,t,a){return this.Ps.us(t,a),At.resolve()}removeMatchingKeys(e,t,a){this.Ps.hs(t,a);let u=this.persistence.referenceDelegate,l=[];return u&&t.forEach(t=>{l.push(u.markPotentiallyOrphaned(e,t))}),At.waitFor(l)}removeMatchingKeysForTargetId(e,t){return this.Ps.ls(t),At.resolve()}getMatchingKeysForTargetId(e,t){let a=this.Ps.ds(t);return At.resolve(a)}containsKey(e,t){return At.resolve(this.Ps.containsKey(t))}};/** 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 */let Vo=class Vo{constructor(e,t){this.Vs={},this.overlays={},this.Ss=new Ot(0),this.Ds=!1,this.Ds=!0,this.referenceDelegate=e(this),this.Cs=new vo(this),this.indexManager=new Nr,this.remoteDocumentCache=new bo(e=>this.referenceDelegate.xs(e)),this.yt=new Hi(t),this.Ns=new Io(this.yt)}start(){return Promise.resolve()}shutdown(){return this.Ds=!1,Promise.resolve()}get started(){return this.Ds}setDatabaseDeletedListener(){}setNetworkEnabled(){}getIndexManager(e){return this.indexManager}getDocumentOverlayCache(e){let t=this.overlays[e.toKey()];return t||(t=new To,this.overlays[e.toKey()]=t),t}getMutationQueue(e,t){let a=this.Vs[e.toKey()];return a||(a=new Ro(t,this.referenceDelegate),this.Vs[e.toKey()]=a),a}getTargetCache(){return this.Cs}getRemoteDocumentCache(){return this.remoteDocumentCache}getBundleCache(){return this.Ns}runTransaction(e,t,a){C("MemoryPersistence","Starting transaction:",e);let u=new So(this.Ss.next());return this.referenceDelegate.ks(),a(u).next(e=>this.referenceDelegate.Os(u).next(()=>e)).toPromise().then(e=>(u.raiseOnCommittedEvent(),e))}Ms(e,t){return At.or(Object.values(this.Vs).map(a=>()=>a.containsKey(e,t)))}};let So=class So extends Tt{constructor(e){super(),this.currentSequenceNumber=e}};let Do=class Do{constructor(e){this.persistence=e,this.Fs=new Eo,this.$s=null}static Bs(e){return new Do(e)}get Ls(){if(this.$s)return this.$s;throw O()}addReference(e,t,a){return this.Fs.addReference(a,t),this.Ls.delete(a.toString()),At.resolve()}removeReference(e,t,a){return this.Fs.removeReference(a,t),this.Ls.add(a.toString()),At.resolve()}markPotentiallyOrphaned(e,t){return this.Ls.add(t.toString()),At.resolve()}
889removeTarget(e,t){this.Fs.ls(t.targetId).forEach(e=>this.Ls.add(e.toString()));let a=this.persistence.getTargetCache();return a.getMatchingKeysForTargetId(e,t.targetId).next(e=>{e.forEach(e=>this.Ls.add(e.toString()))}).next(()=>a.removeTargetData(e,t))}ks(){this.$s=new Set}Os(e){let t=this.persistence.getRemoteDocumentCache().newChangeBuffer();return At.forEach(this.Ls,a=>{let u=ct.fromPath(a);return this.qs(e,u).next(e=>{e||t.removeEntry(u,st.min())})}).next(()=>(this.$s=null,t.apply(e)))}updateLimboDocument(e,t){return this.qs(e,t).next(e=>{e?this.Ls.delete(t.toString()):this.Ls.add(t.toString())})}xs(e){return 0}qs(e,t){return At.or([()=>At.resolve(this.Fs.containsKey(t)),()=>this.persistence.getTargetCache().containsKey(e,t),()=>this.persistence.Ms(e,t)])}};/** 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 */let $o=class $o{constructor(e,t,a,u){this.targetId=e,this.fromCache=t,this.Si=a,this.Di=u}static Ci(e,t){let a=Es(),u=Es();for(let e of t.docChanges)switch(e.type){case 0:a=a.add(e.doc.key);break;case 1:u=u.add(e.doc.key)}return new $o(e,t.fromCache,a,u)}};/** 905 * @license 906 * Copyright 2019 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 */let Bo=class Bo{constructor(){this.xi=!1}initialize(e,t){this.Ni=e,this.indexManager=t,this.xi=!0}getDocumentsMatchingQuery(e,t,a,u){return this.ki(e,t).next(l=>l||this.Oi(e,t,u,a)).next(a=>a||this.Mi(e,t))}ki(e,t){if(fn(t))return At.resolve(null);let a=gn(t);return this.indexManager.getIndexType(e,a).next(u=>0===u?null:(null!==t.limit&&1===u&&(a=gn(t=pn(t,null,"F"))),this.indexManager.getDocumentsMatchingTarget(e,a).next(u=>{let l=Es(...u);return this.Ni.getDocuments(e,l).next(u=>this.indexManager.getMinOffset(e,a).next(a=>{let c=this.Fi(t,u);return this.$i(t,c,l,a.readTime)?this.ki(e,pn(t,null,"F")):this.Bi(e,c,t,a)}))})))}Oi(e,t,a,u){return fn(t)||u.isEqual(st.min())?this.Mi(e,t):this.Ni.getDocuments(e,a).next(l=>{let c=this.Fi(t,l);return this.$i(t,c,a,u)?this.Mi(e,t):(S()<=d.in.DEBUG&&C("QueryEngine","Re-using previous result from %s to execute query: %s",u.toString(),En(t)),this.Bi(e,c,t,mt(u,-1)))})}Fi(e,t){let a=new We(bn(e));return t.forEach((t,u)=>{An(e,u)&&(a=a.add(u))}),a}$i(e,t,a,u){if(null===e.limit)return!1;if(a.size!==t.size)return!0;let l="F"===e.limitType?t.last():t.first();return!!l&&(l.hasPendingWrites||l.version.compareTo(u)>0)}Mi(e,t){return S()<=d.in.DEBUG&&C("QueryEngine","Using full collection scan to execute query:",En(t)),this.Ni.getDocumentsMatchingQuery(e,t,yt.min())}Bi(e,t,a,u){return this.Ni.getDocumentsMatchingQuery(e,a,u).next(e=>(t.forEach(t=>{e=e.insert(t.key,t)}),e))}};/** 920 * @license 921 * Copyright 2020 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 Lo=class Lo{constructor(e,t,a,u){this.persistence=e,this.Li=t,this.yt=u,this.qi=new Ge(Z),this.Ui=new ls(e=>nn(e),sn),this.Ki=new Map,this.Gi=e.getRemoteDocumentCache(),this.Cs=e.getTargetCache(),this.Ns=e.getBundleCache(),this.Qi(a)}Qi(e){this.documentOverlayCache=this.persistence.getDocumentOverlayCache(e),this.indexManager=this.persistence.getIndexManager(e),this.mutation
934Queue=this.persistence.getMutationQueue(e,this.indexManager),this.localDocuments=new po(this.Gi,this.mutationQueue,this.documentOverlayCache,this.indexManager),this.Gi.setIndexManager(this.indexManager),this.Li.initialize(this.localDocuments,this.indexManager)}collectGarbage(e){return this.persistence.runTransaction("Collect garbage","readwrite-primary",t=>e.collect(t,this.qi))}};function qo(e,t,a,u){return new Lo(e,t,a,u)}async function Uo(e,t){return await e.persistence.runTransaction("Handle user change","readonly",a=>{let u;return e.mutationQueue.getAllMutationBatches(a).next(l=>(u=l,e.Qi(t),e.mutationQueue.getAllMutationBatches(a))).next(t=>{let l=[],c=[],h=Es();for(let e of u)for(let t of(l.push(e.batchId),e.mutations))h=h.add(t.key);for(let e of t)for(let t of(c.push(e.batchId),e.mutations))h=h.add(t.key);return e.localDocuments.getDocuments(a,h).next(e=>({ji:e,removedBatchIds:l,addedBatchIds:c}))})})}function Ko(e,t){return e.persistence.runTransaction("Acknowledge batch","readwrite-primary",a=>{let u=t.batch.keys(),l=e.Gi.newChangeBuffer({trackRemovals:!0});return(function(e,t,a,u){let l=a.batch,c=l.keys(),h=At.resolve();return c.forEach(e=>{h=h.next(()=>u.getEntry(t,e)).next(t=>{let c=a.docVersions.get(e);null!==c||O(),0>t.version.compareTo(c)&&(l.applyToRemoteDocument(t,a),t.isValidDocument()&&(t.setReadTime(a.commitVersion),u.addEntry(t)))})}),h.next(()=>e.mutationQueue.removeMutationBatch(t,l))})(e,a,t,l).next(()=>l.apply(a)).next(()=>e.mutationQueue.performConsistencyCheck(a)).next(()=>e.documentOverlayCache.removeOverlaysForBatchId(a,u,t.batch.batchId)).next(()=>e.localDocuments.recalculateAndSaveOverlaysForDocumentKeys(a,function(e){let t=Es();for(let a=0;a<e.mutationResults.length;++a)e.mutationResults[a].transformResults.length>0&&(t=t.add(e.batch.mutations[a].key));return t}(t))).next(()=>e.localDocuments.getDocuments(a,u))})}function Go(e){return e.persistence.runTransaction("Get last remote snapshot version","readonly",t=>e.Cs.getLastRemoteSnapshotVersion(t))}function Qo(e,t){let a=t.snapshotVersion,u=e.qi;return e.persistence.runTransaction("Apply remote event","readwrite-primary",l=>{let c=e.Gi.newChangeBuffer({trackRemovals:!0});u=e.qi;let h=[];
934t.targetChanges.forEach((c,d)=>{var m;let p=u.get(d);if(!p)return;h.push(e.Cs.removeMatchingKeys(l,c.removedDocuments,d).next(()=>e.Cs.addMatchingKeys(l,c.addedDocuments,d)));let g=p.withSequenceNumber(l.currentSequenceNumber);t.targetMismatches.has(d)?g=g.withResumeToken(Qt.EMPTY_BYTE_STRING,st.min()).withLastLimboFreeSnapshotVersion(st.min()):c.resumeToken.approximateByteSize()>0&&(g=g.withResumeToken(c.resumeToken,a)),u=u.insert(d,g),m=g,(0===p.resumeToken.approximateByteSize()||m.snapshotVersion.toMicroseconds()-p.snapshotVersion.toMicroseconds()>=3e8||c.addedDocuments.size+c.modifiedDocuments.size+c.removedDocuments.size>0)&&h.push(e.Cs.updateTargetData(l,g))});let d=I,m=Es();if(t.documentUpdates.forEach(a=>{t.resolvedLimboDocuments.has(a)&&h.push(e.persistence.referenceDelegate.updateLimboDocument(l,a))}),h.push(jo(l,c,t.documentUpdates).next(e=>{d=e.Wi,m=e.zi})),!a.isEqual(st.min())){let t=e.Cs.getLastRemoteSnapshotVersion(l).next(t=>e.Cs.setTargetsMetadata(l,l.currentSequenceNumber,a));h.push(t)}return At.waitFor(h).next(()=>c.apply(l)).next(()=>e.localDocuments.getLocalViewOfDocuments(l,d,m)).next(()=>d)}).then(t=>(e.qi=u,t))}function jo(e,t,a){let u=Es(),l=Es();return a.forEach(e=>u=u.add(e)),t.getEntries(e,u).next(e=>{let u=I;return a.forEach((a,c)=>{let h=e.get(a);c.isFoundDocument()!==h.isFoundDocument()&&(l=l.add(a)),c.isNoDocument()&&c.version.isEqual(st.min())?(t.removeEntry(a,c.readTime),u=u.insert(a,c)):!h.isValidDocument()||c.version.compareTo(h.version)>0||0===c.version.compareTo(h.version)&&h.hasPendingWrites?(t.addEntry(c),u=u.insert(a,c)):C("LocalStore","Ignoring outdated watch update for ",a,". Current version:",h.version," Watch version:",c.version)}),{Wi:u,zi:l}})}function Wo(e,t){return e.persistence.runTransaction("Get next mutation batch","readonly",a=>(void 0===t&&(t=-1),e.mutationQueue.getNextMutationBatchAfterBatchId(a,t)))}function zo(e,t){return e.persistence.runTransaction("Allocate target","readwrite",a=>{let u;return e.Cs.getTargetData(a,t).next(l=>l?(u=l,At.resolve(u)):e.Cs.allocateTargetId(a).next(l=>(u=new zi(t,l,0,a.currentSequenceNumber),e.Cs.addTargetData(a,u).next(()=>u))))}).then(a=>{let u=e.qi.get(a.targetId);return(null===u||a.snapshotVersion.compareTo(u.snapshotVersion)>0)&&(e.qi=e.qi.insert(a.targetId,a),e.Ui.set(t,a.targetId)),a})}async function Ho(e,t,a){let u=e.qi.get(t);try{a||await e.persistence.runTransaction("Release target",a?"readwrite":"readwrite-primary",t=>e.persistence.referenceDelegate.removeTarget(t,u))}catch(e){if(!Vt(e))throw e;C("LocalStore",`Failed to update sequence numbers for target ${t}: ${e}`)}e.qi=e.qi.remove(t),e.Ui.delete(u.target)}function Jo(e,t,a){let u=st.min(),l=Es();return e.persistence.runTransaction("Execute query","readonly",c=>(function(e,t,a){let u=e.Ui.get(a);return void 0!==u?At.resolve(e.qi.get(u)):e.Cs.getTargetData(t,a)})(e,c,gn(t)).next(t=>{if(t)return u=t.lastLimboFreeSnapshotVersion,e.Cs.getMatchingKeysForTargetId(c,t.targetId).next(e=>{l=e})}).next(()=>e.Li.getDocumentsMatchingQuery(c,t,a?u:st.min(),a?l:Es())).next(a=>(Zo(e,Rn(t),a),{documents:a,Hi:l})))}function Zo(e,t,a){let u=e.Ki.get(t)||st.min();a.forEach((e,t)=>{t.readTime.compareTo(u)>0&&(u=t.readTime)}),e.Ki.set(t,u)}let au=class au{constructor(){this.activeTargetIds=R}er(e){this.activeTargetIds=this.activeTargetIds.add(e)}nr(e){this.activeTargetIds=this.activeTargetIds.delete(e)}tr(){let e={activeTargetIds:this.activeTargetIds.toArray(),updateTimeMs:Date.now()};return JSON.stringify(e)}};let lu=class lu{constructor(){this.Lr=new au,this.qr={},this.onlineStateHandler=null,this.sequenceNumberHandler=null}addPendingMutation(e){}updateMutationState(e,t,a){}addLocalQueryTarget(e){return this.Lr.er(e),this.qr[e]||"not-current"}updateQueryState(e,t,a){this.qr[e]=t}removeLocalQueryTarget(e){this.Lr.nr(e)}isLocalQueryTarget(e){return this.Lr.activeTargetIds.has(e)}clearQueryState(e){delete this.qr[e]}getAllActiveQueryTargets(){return this.Lr.activeTargetIds}isActiveQueryTarget(e){return this.Lr.activeTargetIds.has(e)}start(){return this.Lr=new au,Promise.resolve()}handleUserChange(e,t,a){}setOnlineState(e){}shutdown(){}writeSequenceNumber(e){}notifyBundleLoaded(e){}};/** 935 * @license 936 * Copyright 2019 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 fu=class fu{Ur(e){}shutdown(){}};/** 950 * @license 951 * Copyright 2019 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 */let du=class du{constructor(){this.Kr=()=>this.Gr(),this.Qr=()=>this.jr(),this.Wr=[],this.zr()}Ur(e){this.Wr.push(e)}shutdown(){window.removeEventListener("online",this.Kr),window.removeEventListener("offline",this.Qr)}zr(){window.addEventListener("online",this.Kr),window.addEventListener("offline",this.Qr)}Gr(){for(let e of(C("ConnectivityMonitor","Network connectivity changed: AVAILABLE"),this.Wr))e(0)}jr(){for(let e of(C("ConnectivityMonitor","Network connectivity changed: UNAVAILABLE"),this.Wr))e(1)}static C(){return"undefined"!=typeof window&&void 0!==window.addEventListener&&void 0!==window.removeEventListener}};/** 965 * @license 966 * Copyright 2020 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 */let B={BatchGetDocuments:"batchGet",Commit:"commit",RunQuery:"runQuery",RunAggregationQuery:"runAggregationQuery"};/** 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 */let wu=class wu{constructor(e){this.Hr=e.Hr,this.Jr=e.Jr}Yr(e){this.Xr=e}Zr(e){this.eo=e}onMessage(e){this.no=e}close(){this.Jr()}send(e){this.Hr(e)}so(){this.Xr()}io(e){this.eo(e)}ro(e){this.no(e)}};/** 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 */let mu=class mu extends class{constructor(e){this.databaseInfo=e,this.databaseId=e.databaseId;let t=e.ssl?"https":"http";this.oo=t+"://"+e.host,this.uo="projects/"+this.databaseId.projectId+"/databases/"+this.databaseId.database+"/documents"}get co(){return!1}ao(e,t,a,u,l){let c=this.ho(e,t);C("RestConnection","Sending: ",c,a);let h={};return this.lo(h,u,l),this.fo(e,c,h,a).then(e=>(C("RestConnection","Received: ",e),e),t=>{throw N("RestConnection",`${e} failed with error: `,t,"url: ",c,"request:",a),t})}_o(e,t,a,u,l,c){return this.ao(e,t,a,u,l)}lo(e,t,a){e["X-Goog-Api-Client"]="gl-js/ fire/"+y,e["Content-Type"]="text/plain",this.databaseInfo.appId&&(e["X-Firebase-GMPID"]=this.databaseInfo.appId),t&&t.headers.forEac
1009h((t,a)=>e[a]=t),a&&a.headers.forEach((t,a)=>e[a]=t)}ho(e,t){let a=B[e];return`${this.oo}/v1/${t}:${a}`}}{constructor(e){super(e),this.forceLongPolling=e.forceLongPolling,this.autoDetectLongPolling=e.autoDetectLongPolling,this.useFetchStreams=e.useFetchStreams}fo(e,t,a,u){return new Promise((l,c)=>{let h=new p.JJ;h.setWithCredentials(!0),h.listenOnce(p.tw.COMPLETE,()=>{try{switch(h.getLastErrorCode()){case p.jK.NO_ERROR:let t=h.getResponseJson();C("Connection","XHR received:",JSON.stringify(t)),l(t);break;case p.jK.TIMEOUT:C("Connection",'RPC "'+e+'" timed out'),c(new L(v.DEADLINE_EXCEEDED,"Request time out"));break;case p.jK.HTTP_ERROR:let a=h.getStatus();if(C("Connection",'RPC "'+e+'" failed with status:',a,"response text:",h.getResponseText()),a>0){let e=h.getResponseJson();Array.isArray(e)&&(e=e[0]);let t=null==e?void 0:e.error;if(t&&t.status&&t.message){let e=function(e){let t=e.toLowerCase().replace(/_/g,"-");return Object.values(v).indexOf(t)>=0?t:v.UNKNOWN}(t.status);c(new L(e,t.message))}else c(new L(v.UNKNOWN,"Server responded with status "+h.getStatus()))}else c(new L(v.UNAVAILABLE,"Connection failed."));break;default:O()}}finally{C("Connection",'RPC "'+e+'" completed.')}});let d=JSON.stringify(u);h.send(t,"POST",d,a,15)})}wo(e,t,a){let l=[this.oo,"/","google.firestore.v1.Firestore","/",e,"/channel"],c=(0,p.UE)(),h=(0,p.FJ)(),d={httpSessionIdParam:"gsessionid",initMessageHeaders:{},messageUrlParams:{database:`projects/${this.databaseId.projectId}/databases/${this.databaseId.database}`},sendRawJson:!0,supportsCrossDomainXhr:!0,internalChannelParams:{forwardChannelRequestTimeoutMs:6e5},forceLongPolling:this.forceLongPolling,detectBufferingProxy:this.autoDetectLongPolling};this.useFetchStreams&&(d.xmlHttpFactory=new p.zI({})),this.lo(d.initMessageHeaders,t,a),d.encodeInitMessageHeaders=!0;let m=l.join("");C("Connection","Creating WebChannel: "+m,d);let g=c.createWebChannel(m,d),y=!1,w=!1,E=new wu({Hr:e=>{w?C("Connection","Not sending because WebChannel is closed:",e):(y||(C("Connection","Opening WebChannel transport."),g.open(),y=!0),C("Connection","WebChannel sending:",e),g.send(e))},Jr:()=>g.close()}),f=(e,t,a)=>{e.listen(t,e=>{try{a(e)}catch(e){setTimeout(()=>{throw e},0)}})};return f(g,p.ii.EventType.OPEN,()=>{w||C("Connection","WebChannel transport opened.")}),f(g,p.ii.EventType.CLOSE,()=>{w||(w=!0,C("Connection","WebChannel transport closed"),E.io())}),f(g,p.ii.EventType.ERROR,e=>{w||(w=!0,N("Connection","WebChannel transport errored:",e),E.io(new L(v.UNAVAILABLE,"The operation could not be completed")))}),f(g,p.ii.EventType.MESSAGE,e=>{var t;if(!w){let a=e.data[0];a||O();let l=a.error||(null===(t=a[0])||void 0===t?void 0:t.error);if(l){C("Connection","WebChannel received error:",l);let e=l.status,t=function(e){let t=u[e];if(void 0!==t)return hs(t)}(e),a=l.message;void 0===t&&(t=v.INTERNAL,a="Unknown error status: "+e+" with message "+l.message),w=!0,E.io(new L(t,a)),g.close()}else C("Connection","WebChannel received:",a),E.ro(a)}}),f(h,p.ju.STAT_EVENT,e=>{e.stat===p.kN.PROXY?C("Connection","Detected buffering proxy"):e.stat===p.kN.NOPROXY&&C("Connection","Detected no buffering proxy")}),setTimeout(()=>{E.so()},0),E}};function yu(){return"undefined"!=typeof document?document:null}/** 1010 * @license 1011 * Copyright 2020 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 */function pu(e){return new Fs(e,!0)}let Iu=class Iu{constructor(e,t,a=1e3,u=1.5,l=6e4){this.Hs=e,this.timerId=t,this.mo=a,this.yo=u,this.po=l,this.Io=0,this.To=null,this.Eo=Date.now(),this.reset()}reset(){this.Io=0}Ao(){this.Io=this.po}Ro(e){this.cancel();let t=Math.floor(this.Io+this.bo()),a=Math.max(0,Date.now()-this.Eo),u=Math.max(0,t-a);u>0&&C("ExponentialBackoff",`Backing off for ${u} ms (base delay: ${this.Io}
1024 ms, delay with jitter: ${t} ms, last attempt: ${a} ms ago)`),this.To=this.Hs.enqueueAfterDelay(this.timerId,u,()=>(this.Eo=Date.now(),e())),this.Io*=this.yo,this.Io<this.mo&&(this.Io=this.mo),this.Io>this.po&&(this.Io=this.po)}Po(){null!==this.To&&(this.To.skipDelay(),this.To=null)}cancel(){null!==this.To&&(this.To.cancel(),this.To=null)}bo(){return(Math.random()-.5)*this.Io}};/** 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 */let Tu=class Tu{constructor(e,t,a,u,l,c,h,d){this.Hs=e,this.vo=a,this.Vo=u,this.connection=l,this.authCredentialsProvider=c,this.appCheckCredentialsProvider=h,this.listener=d,this.state=0,this.So=0,this.Do=null,this.Co=null,this.stream=null,this.xo=new Iu(e,t)}No(){return 1===this.state||5===this.state||this.ko()}ko(){return 2===this.state||3===this.state}start(){4!==this.state?this.auth():this.Oo()}async stop(){this.No()&&await this.close(0)}Mo(){this.state=0,this.xo.reset()}Fo(){this.ko()&&null===this.Do&&(this.Do=this.Hs.enqueueAfterDelay(this.vo,6e4,()=>this.$o()))}Bo(e){this.Lo(),this.stream.send(e)}async $o(){if(this.ko())return this.close(0)}Lo(){this.Do&&(this.Do.cancel(),this.Do=null)}qo(){this.Co&&(this.Co.cancel(),this.Co=null)}async close(e,t){this.Lo(),this.qo(),this.xo.cancel(),this.So++,4!==e?this.xo.reset():t&&t.code===v.RESOURCE_EXHAUSTED?(x(t.toString()),x("Using maximum backoff delay to prevent overloading the backend."),this.xo.Ao()):t&&t.code===v.UNAUTHENTICATED&&3!==this.state&&(this.authCredentialsProvider.invalidateToken(),this.appCheckCredentialsProvider.invalidateToken()),null!==this.stream&&(this.Uo(),this.stream.close(),this.stream=null),this.state=e,await this.listener.Zr(t)}Uo(){}auth(){this.state=1;let e=this.Ko(this.So),t=this.So;Promise.all([this.authCredentialsProvider.getToken(),this.appCheckCredentialsProvider.getToken()]).then(([e,a])=>{this.So===t&&this.Go(e,a)},t=>{e(()=>{let e=new L(v.UNKNOWN,"Fetching auth token failed: "+t.message);return this.Qo(e)})})}Go(e,t){let a=this.Ko(this.So);this.stream=this.jo(e,t),this.stream.Yr(()=>{a(()=>(this.state=2,this.Co=this.Hs.enqueueAfterDelay(this.Vo,1e4,()=>(this.ko()&&(this.state=3),Promise.resolve())),this.listener.Yr()))}),this.stream.Zr(e=>{a(()=>this.Qo(e))}),this.stream.onMessage(e=>{a(()=>this.onMessage(e))})}Oo(){this.state=5,this.xo.Ro(async()=>{this.state=0,this.start()})}Qo(e){return C("PersistentStream",`close with error: ${e}`),this.stream=null,this.close(4,e)}Ko(e){return t=>{this.Hs.enqueueAndForget(()=>this.So===e?t():(C("PersistentStream","stream callback skipped by getCloseGuardedDispatcher."),Promise.resolve()))}}};let Eu=class Eu extends Tu{constructor(e,t,a,u,l,c){super(e,"listen_stream_connection_backoff","listen_stream_idle","health_check_timeout",t,a,u,c),this.yt=l}jo(e,t){return this.connection.wo("Listen",e,t)}onMessage(e){this.xo.reset();let t=Zs(this.yt,e),a=function(e){if(!("targetChange"in e))return st.min();let t=e.targetChange;return t.targetIds&&t.targetIds.length?st.min():t.readTime?qs(t.readTime):st.min()}(e);return this.listener.Wo(t,a)}zo(e){let t={};t.database=zs(this.yt),t.addTarget=function(e,t){let a;let u=t.target;return(a=rn(u)?{documents:si(e,u)}:{query:ii(e,u)}).targetId=t.targetId,t.resumeToken.approximateByteSize()>0?a.resumeToken=Bs(e,t.resumeToken):t.snapshotVersion.compareTo(st.min())>0&&(a.readTime=$s(e,t.snapshotVersion.toTimestamp())),a}(this.yt,e);let a=oi(this.yt,e);a&&(t.labels=a),this.Bo(t)}Ho(e){let t={};t.database=zs(this.yt),t.removeTarget=e,this.Bo(t)}};let Au=class Au extends Tu{constructor(e,t,a,u,l,c){super(e,"write_stream_connection_backoff","write_stream_idle","health_check_timeout",t,a,u,c),this.yt=l,this.Jo=!1}get Yo(){return this.Jo}start(){this.Jo=!1,this.lastStreamToken=void 0,super.start()}Uo(){this.Jo&&this.Xo([])}jo(e,t){return this.connection.wo("Write",e,t)}onMessage(e){if(e.streamToken||O(),this.lastStreamToken=e.streamToken,this.Jo){this.xo.reset();let t=ni(e.writeResults,e.commitTime),a=qs(e.commitTime);return this.listener.Zo(a,t)}return e.writeResults&&0!==e.writeResults.length&&O(),this.Jo=!0,this.listener.tu()}eu(){let e={};e.database=zs(this.yt),this.Bo(e)}Xo(e){let t={streamToken:this.lastStreamToken,writes:e.map(e=>ti(this.yt,e))};this.Bo(t)}};/** 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 */let Ru=class Ru extends class{}{constructor(e,t,a,u){super(),this.authCredentials=e,this.appCheckCredentials=t,this.connection=a,this.yt=u,this.nu=!1}su(){if(this.nu)throw new L(v.FAILED_PRECONDITION,"The client has already been terminated.")}ao(e,t,a){return this.su(),Promise.all([this.authCredentials.getToken(),this.appCheckCredentials.getToken()]).then(([u,l])=>this.connection.ao(e,t,a,u,l)).catch(e=>{throw"FirebaseError"===e.name?(e.code===v.UNAUTHENTICATED&&(this.authCredentials.invalidateToken(),this.appCheckCredentials.invalidateToken()),e):new L(v.UNKNOWN,e.toString())})}_o(e,t,a,u){return this.su(),Promise.all([this.authCredentials.getToken(),this.appCheckCredentials.getToken()]).then(([l,c])=>this.connection._o(e,t,a,l,c,u)).catch(e=>{throw"FirebaseError"===e.name?(e.code===v.UNAUTHENTICATED&&(this.authCredentials.invalidateToken(),this.appCheckCredentials.invalidateToken()),e):new L(v.UNKNOWN,e.toString())})}terminate(){this.nu=!0}};let Pu=class Pu{constructor(e,t){this.asyncQueue=e,this.onlineStateHandler=t,this.state="Unknown",this.iu=0,this.ru=null,this.ou=!0}uu(){0===this.iu&&(this.cu("Unknown"),this.ru=this.asyncQueue.enqueueAfterDelay("online_state_timeout",1e4,()=>(this.ru=null,this.au("Backend didn't respond within 10 seconds."),this.cu("Offline"),Promise.resolve())))}hu(e){"Online"===this.state?this.cu("Unknown"):(this.iu++,this.iu>=1&&(this.lu(),this.au(`Connection failed 1 times. Most recent error: ${e.toString()}`),this.cu("Offline")))}set(e){this.lu(),this.iu=0,"Online"===e&&(this.ou=!1),this.cu(e)}cu(e){e!==this.state&&(this.state=e,this.onlineStateHandler(e))}au(e){let t=`Could not reach Cloud Firestore backend. ${e} 1055This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.`;this.ou?(x(t),this.ou=!1):C("OnlineStateTracker",t)}lu(){null!==this.ru&&(this.ru.cancel(),this.ru=null)}};/** 1056 * @license 1057 * Copyright 2017 Google LLC 1058 * 1059 * Licensed under the Apache License, Version 2.0 (the "License"); 1060 * you may not use this file except in compliance with the License. 1061 * You may obtain a copy of the License at 1062 * 1063 * http://www.apache.org/licenses/LICENSE-2.0 1064 * 1065 * Unless required by applicable law or agreed to in writing, software 1066 * distributed under the License is distributed on an "AS IS" BASIS, 1067 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1068 * See the License for the specific language governing permissions and 1069 * limitations under the License. 1070 */let vu=class vu{constructor(e,t,a,u,l){this.localStore=e,this.datastore=t,this.asyncQueue=a,this.remoteSyncer={},this.fu=[],this.du=new Map,this._u=new Set,this.wu=[],this.mu=l,this.mu.Ur(e=>{a.enqueueAndForget(async()=>{Mu(this)&&(C("RemoteStore","Restarting streams for network reachability change."),await async function(e){e._u.add(4),await Su(e),e.gu.set("Unknown"),e._u.delete(4),await Vu(e)}(this))})}),this.gu=new Pu(a,u)}};async function Vu(e){if(Mu(e))for(let t of e.wu)await t(!0)}async function Su(e){for(let t of e.wu)await t(!1)}function Du(e,t){e.du.has(t.targetId)||(e.du.set(t.targetId,t),Ou(e)?ku(e):tc(e).ko()&&xu(e,t))}function Cu(e,t){let a=tc(e);e.du.delete(t),a.ko()&&Nu(e,t),0===e.du.size&&(a.ko()?a.Fo():Mu(e)&&e.gu.set("Unknown"))}function xu(e,t){e.yu.Ot(t.targetId),tc(e).zo(t)}function Nu(e,t){e.yu.Ot(t),tc(e).Ho(t)}function ku(e){e.yu=new Cs({getRemoteKeysForTarget:t=>e.remoteSyncer.getRemoteKeysForTarget(t),ne:t=>e.du.get(t)||null}),tc(e).start(),e.gu.uu()}function Ou(e){return Mu(e)&&!tc(e).No()&&e.du.size>0}function Mu(e){return 0===e._u.size}async function $u(e){e.du.forEach((t,a)=>{xu(e,t)})}async function Bu(e,t){e.yu=void 0,Ou(e)?(e.gu.hu(t),ku(e)):e.gu.set("Unknown")}async function Lu(e,t,a){if(e.gu.set("Online"),t instanceof Ss&&2===t.state&&t.cause)try{await async function(e,t){let a=t.cause;for(let u of t.targetIds)e.du.has(u)&&(await e.remoteSyncer.rejectListen(u,a),e.du.delete(u),e.yu.removeTarget(u))}(e,t)}catch(a){C("RemoteStore","Failed to remove targets %s: %s ",t.targetIds.join(","),a),await qu(e,a)}else if(t instanceof vs?e.yu.Kt(t):t instanceof Vs?e.yu.Jt(t):e.
1070yu.jt(t),!a.isEqual(st.min()))try{let t=await Go(e.localStore);a.compareTo(t)>=0&&await function(e,t){let a=e.yu.Zt(t);return a.targetChanges.forEach((a,u)=>{if(a.resumeToken.approximateByteSize()>0){let l=e.du.get(u);l&&e.du.set(u,l.withResumeToken(a.resumeToken,t))}}),a.targetMismatches.forEach(t=>{let a=e.du.get(t);if(!a)return;e.du.set(t,a.withResumeToken(Qt.EMPTY_BYTE_STRING,a.snapshotVersion)),Nu(e,t);let u=new zi(a.target,t,1,a.sequenceNumber);xu(e,u)}),e.remoteSyncer.applyRemoteEvent(a)}(e,a)}catch(t){C("RemoteStore","Failed to raise snapshot:",t),await qu(e,t)}}async function qu(e,t,a){if(!Vt(t))throw t;e._u.add(1),await Su(e),e.gu.set("Offline"),a||(a=()=>Go(e.localStore)),e.asyncQueue.enqueueRetryable(async()=>{C("RemoteStore","Retrying IndexedDB access"),await a(),e._u.delete(1),await Vu(e)})}function Uu(e,t){return t().catch(a=>qu(e,a,t))}async function Ku(e){let t=ec(e),a=e.fu.length>0?e.fu[e.fu.length-1].batchId:-1;for(;Gu(e);)try{let u=await Wo(e.localStore,a);if(null===u){0===e.fu.length&&t.Fo();break}a=u.batchId,Qu(e,u)}catch(t){await qu(e,t)}ju(e)&&Wu(e)}function Gu(e){return Mu(e)&&e.fu.length<10}function Qu(e,t){e.fu.push(t);let a=ec(e);a.ko()&&a.Yo&&a.Xo(t.mutations)}function ju(e){return Mu(e)&&!ec(e).No()&&e.fu.length>0}function Wu(e){ec(e).start()}async function zu(e){ec(e).eu()}async function Hu(e){let t=ec(e);for(let a of e.fu)t.Xo(a.mutations)}async function Ju(e,t,a){let u=e.fu.shift(),l=ji.from(u,t,a);await Uu(e,()=>e.remoteSyncer.applySuccessfulWrite(l)),await Ku(e)}async function Yu(e,t){t&&ec(e).Yo&&await async function(e,t){var a;if(as(a=t.code)&&a!==v.ABORTED){let a=e.fu.shift();ec(e).Mo(),await Uu(e,()=>e.remoteSyncer.rejectFailedWrite(a.batchId,t)),await Ku(e)}}(e,t),ju(e)&&Wu(e)}async function Xu(e,t){e.asyncQueue.verifyOperationInProgress(),C("RemoteStore","RemoteStore received new credentials");let a=Mu(e);e._u.add(3),await Su(e),a&&e.gu.set("Unknown"),await e.remoteSyncer.handleCredentialChange(t),e._u.delete(3),await Vu(e)}
1070async function Zu(e,t){t?(e._u.delete(2),await Vu(e)):t||(e._u.add(2),await Su(e),e.gu.set("Unknown"))}function tc(e){var t,a,u;return e.pu||(e.pu=(t=e.datastore,a=e.asyncQueue,u={Yr:$u.bind(null,e),Zr:Bu.bind(null,e),Wo:Lu.bind(null,e)},t.su(),new Eu(a,t.connection,t.authCredentials,t.appCheckCredentials,t.yt,u)),e.wu.push(async t=>{t?(e.pu.Mo(),Ou(e)?ku(e):e.gu.set("Unknown")):(await e.pu.stop(),e.yu=void 0)})),e.pu}function ec(e){var t,a,u;return e.Iu||(e.Iu=(t=e.datastore,a=e.asyncQueue,u={Yr:zu.bind(null,e),Zr:Yu.bind(null,e),tu:Hu.bind(null,e),Zo:Ju.bind(null,e)},t.su(),new Au(a,t.connection,t.authCredentials,t.appCheckCredentials,t.yt,u)),e.wu.push(async t=>{t?(e.Iu.Mo(),await Ku(e)):(await e.Iu.stop(),e.fu.length>0&&(C("RemoteStore",`Stopping write stream with ${e.fu.length} pending writes`),e.fu=[]))})),e.Iu}/** 1071 * @license 1072 * Copyright 2017 Google LLC 1073 * 1074 * Licensed under the Apache License, Version 2.0 (the "License"); 1075 * you may not use this file except in compliance with the License. 1076 * You may obtain a copy of the License at 1077 * 1078 * http://www.apache.org/licenses/LICENSE-2.0 1079 * 1080 * Unless required by applicable law or agreed to in writing, software 1081 * distributed under the License is distributed on an "AS IS" BASIS, 1082 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1083 * See the License for the specific language governing permissions and 1084 * limitations under the License. 1085 */let nc=class nc{constructor(e,t,a,u,l){this.asyncQueue=e,this.timerId=t,this.targetTimeMs=a,this.op=u,this.removalCallback=l,this.deferred=new q,this.then=this.deferred.promise.then.bind(this.deferred.promise),this.deferred.promise.catch(e=>{})}static createAndSchedule(e,t,a,u,l){let c=Date.now()+a,h=new nc(e,t,c,u,l);return h.start(a),h}start(e){this.timerHandle=setTimeout(()=>this.handleDelayElapsed(),e)}skipDelay(){return this.handleDelayElapsed()}cancel(e){null!==this.timerHandle&&(this.clearTimeout(),this.deferred.reject(new L(v.CANCELLED,"Operation cancelled"+(e?": "+e:""))))}handleDelayElapsed(){this.asyncQueue.enqueueAndForget(()=>null!==this.timerHandle?(this.clearTimeout(),this.op().then(e=>this.deferred.resolve(e))):Promise.resolve())}clearTimeout(){null!==this.timerHandle&&(this.removalCallback(this),clearTimeout(this.timerHandle),this.timerHandle=null)}};function sc(e,t){if(x("AsyncQueue",`${t}: ${e}`),Vt(e))return new L(v.UNAVAILABLE,`${t}: ${e}`);throw e}/** 1086 * @license 1087 * Copyright 2017 Google LLC 1088 * 1089 * Licensed under the Apache License, Version 2.0 (the "License"); 1090 * you may not use this file except in compliance with the License. 1091 * You may obtain a copy of the License at 1092 * 1093 * http://www.apache.org/licenses/LICENSE-2.0 1094 * 1095 * Unless required by applicable law or agreed to in writing, software 1096 * distributed under the License is distributed on an "AS IS" BASIS, 1097 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1098 * See the License for the specific language governing permissions and 1099 * limitations under the License. 1100 */let ic=class ic{constructor(e){this.comparator=e?(t,a)=>e(t,a)||ct.comparator(t.key,a.key):(e,t)=>ct.comparator(e.key,t.key),this.keyedMap=ws(),this.sortedSet=new Ge(this.comparator)}static emptySet(e){return new ic(e.comparator)}has(e){return null!=this.keyedMap.get(e)}get(e){return this.keyedMap.get(e)}first(){return this.sortedSet.minKey()}last(){return this.sortedSet.maxKey()}isEmpty(){return this.sortedSet.isEmpty()}indexOf(e){let t=this.keyedMap.get(e);return t?this.sortedSet.indexOf(t):-1}get size(){return this.sortedSet.size}forEach(e){this.sortedSet.inorderTraversal((t,a)=>(e(t),!1))}add(e){let t=this.delete(e.key);return t.copy(t.keyedMap.insert(e.key,e),t.sortedSet.insert(e,null))}delete(e){let t=this.get(e);return t?this.copy(this.keyedMap.remove(e),this.sortedSet.remove(t)):this}isEqual(e){if(!(e instanceof ic)||this.size!==e.size)return!1;let t=this.sortedSet.getIterator(),a=e.sortedSet.getIterator();for(;t.hasNext();){let e=t.getNext().key,u=a.getNext().key;if(!e.isEqual(u))return!1}return!0}toString(){let e=[];return this.forEach(t=>{e.push(t.toString())}),0===e.length?"DocumentSet ()":"DocumentSet (\n "+e.join(" \n")+"\n)"}copy(e,t){let a=new ic;return a.comparator=this.comparator,a.keyedMap=e,a.sortedSet=t,a}};/** 1101 * @license 1102 * Copyright 2017 Google LLC 1103 * 1104 * Licensed under the Apache License, Version 2.0 (the "License");
1105 * you may not use this file except in compliance with the License. 1106 * You may obtain a copy of the License at 1107 * 1108 * http://www.apache.org/licenses/LICENSE-2.0 1109 * 1110 * Unless required by applicable law or agreed to in writing, software 1111 * distributed under the License is distributed on an "AS IS" BASIS, 1112 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1113 * See the License for the specific language governing permissions and 1114 * limitations under the License. 1115 */let rc=class rc{constructor(){this.Tu=new Ge(ct.comparator)}track(e){let t=e.doc.key,a=this.Tu.get(t);a?0!==e.type&&3===a.type?this.Tu=this.Tu.insert(t,e):3===e.type&&1!==a.type?this.Tu=this.Tu.insert(t,{type:a.type,doc:e.doc}):2===e.type&&2===a.type?this.Tu=this.Tu.insert(t,{type:2,doc:e.doc}):2===e.type&&0===a.type?this.Tu=this.Tu.insert(t,{type:0,doc:e.doc}):1===e.type&&0===a.type?this.Tu=this.Tu.remove(t):1===e.type&&2===a.type?this.Tu=this.Tu.insert(t,{type:1,doc:a.doc}):0===e.type&&1===a.type?this.Tu=this.Tu.insert(t,{type:2,doc:e.doc}):O():this.Tu=this.Tu.insert(t,e)}Eu(){let e=[];return this.Tu.inorderTraversal((t,a)=>{e.push(a)}),e}};let oc=class oc{constructor(e,t,a,u,l,c,h,d,m){this.query=e,this.docs=t,this.oldDocs=a,this.docChanges=u,this.mutatedKeys=l,this.fromCache=c,this.syncStateChanged=h,this.excludesMetadataChanges=d,this.hasCachedResults=m}static fromInitialDocuments(e,t,a,u,l){let c=[];return t.forEach(e=>{c.push({type:0,doc:e})}),new oc(e,t,ic.emptySet(t),c,a,u,!0,!1,l)}get hasPendingWrites(){return!this.mutatedKeys.isEmpty()}isEqual(e){if(!(this.fromCache===e.fromCache&&this.hasCachedResults===e.hasCachedResults&&this.syncStateChanged===e.syncStateChanged&&this.mutatedKeys.isEqual(e.mutatedKeys)&&In(this.query,e.query)&&this.docs.isEqual(e.docs)&&this.oldDocs.isEqual(e.oldDocs)))return!1;let t=this.docChanges,a=e.docChanges;if(t.length!==a.length)return!1;for(let e=0;e<t.length;e++)if(t[e].type!==a[e].type||!t[e].doc.isEqual(a[e].doc))return!1;return!0}};/** 1116 * @license 1117 * Copyright 2017 Google LLC 1118 * 1119 * Licensed under the Apache License, Version 2.0 (the "License"); 1120 * you may not use this file except in compliance with the License. 1121 * You may obtain a copy of the License at 1122 * 1123 * http://www.apache.org/licenses/LICENSE-2.0 1124 * 1125 * Unless required by applicable law or agreed to in writing, software 1126 * distributed under the License is distributed on an "AS IS" BASIS, 1127 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1128 * See the License for the specific language governing permissions and 1129 * limitations under the License. 1130 */let uc=class uc{constructor(){this.Au=void 0,this.listeners=[]}};let cc=class cc{constructor(){this.queries=new ls(e=>Tn(e),In),this.onlineState="Unknown",this.Ru=new Set}};async function ac(e,t){let a=t.query,u=!1,l=e.queries.get(a);if(l||(u=!0,l=new uc),u)try{l.Au=await e.onListen(a)}catch(a){let e=sc(a,`Initialization of query '${En(t.query)}' failed`);return void t.onError(e)}e.queries.set(a,l),l.listeners.push(t),t.bu(e.onlineState),l.Au&&t.Pu(l.Au)&&dc(e)}async function hc(e,t){let a=t.query,u=!1,l=e.queries.get(a);if(l){let e=l.listeners.indexOf(t);e>=0&&(l.listeners.splice(e,1),u=0===l.listeners.length)}if(u)return e.queries.delete(a),e.onUnlisten(a)}function lc(e,t){let a=!1;for(let u of t){let t=u.query,l=e.queries.get(t);if(l){for(let e of l.listeners)e.Pu(u)&&(a=!0);l.Au=u}}a&&dc(e)}function fc(e,t,a){let u=e.queries.get(t);if(u)for(let e of u.listeners)e.onError(a);e.queries.delete(t)}function dc(e){e.Ru.forEach(e=>{e.next()})}let _c=class _c{constructor(e,t,a){this.query=e,this.vu=t,this.Vu=!1,this.Su=null,this.onlineState="Unknown",this.options=a||{}}Pu(e){if(!this.options.includeMetadataChanges){let t=[];for(let a of e.docChanges)3!==a.type&&t.push(a);e=new oc(e.query,e.docs,e.oldDocs,t,e.mutatedKeys,e.fromCache,e.syncStateChanged,!0,e.hasCachedResults)}let t=!1;return this.Vu?this.Du(e)&&(this.vu.next(e),t=!0):this.Cu(e,this.onlineState)&&(this.xu(e),t=!0),this.Su=e,t}onError(e){this.vu.error(e)}bu(e){this.onlineState=e;let t=!1;return this.Su&&!this.Vu&&this.Cu(this.Su,e)&&(this.xu(this.Su),t=!0),t}Cu(e,t){return!e.fromCache||(!this.options.Nu||!("Offline"!==t))&&(!e.docs.isEmpty()||e.hasCachedResults||"Offline"===t)}Du(e){if(e.docChanges.length>0)return!0;let t=this.Su&&this.Su.hasPendingWrites!==e.hasPendingWrites;return!(!e.syncStateChanged&&!t)&&!0===this.options.includeMetadataChanges}xu(e){e=oc.fromInitialDocuments(e.query,e.docs,e.mutatedKeys,e.fromCache,e.hasCachedResults),this.Vu=!0,this.vu.next(e)}};/** 1131 * @license 1132 * Copyright 2017 Google LLC 1133 * 1134 * Licensed under the Apache License, Version 2.0 (the "License");
1135 * you may not use this file except in compliance with the License. 1136 * You may obtain a copy of the License at 1137 * 1138 * http://www.apache.org/licenses/LICENSE-2.0 1139 * 1140 * Unless required by applicable law or agreed to in writing, software 1141 * distributed under the License is distributed on an "AS IS" BASIS, 1142 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1143 * See the License for the specific language governing permissions and 1144 * limitations under the License. 1145 */let pc=class pc{constructor(e){this.key=e}};let Ic=class Ic{constructor(e){this.key=e}};let Tc=class Tc{constructor(e,t){this.query=e,this.qu=t,this.Uu=null,this.hasCachedResults=!1,this.current=!1,this.Ku=Es(),this.mutatedKeys=Es(),this.Gu=bn(e),this.Qu=new ic(this.Gu)}get ju(){return this.qu}Wu(e,t){let a=t?t.zu:new rc,u=t?t.Qu:this.Qu,l=t?t.mutatedKeys:this.mutatedKeys,c=u,h=!1,d="F"===this.query.limitType&&u.size===this.query.limit?u.last():null,m="L"===this.query.limitType&&u.size===this.query.limit?u.first():null;if(e.inorderTraversal((e,t)=>{let p=u.get(e),g=An(this.query,t)?t:null,y=!!p&&this.mutatedKeys.has(p.key),w=!!g&&(g.hasLocalMutations||this.mutatedKeys.has(g.key)&&g.hasCommittedMutations),v=!1;p&&g?p.data.isEqual(g.data)?y!==w&&(a.track({type:3,doc:g}),v=!0):this.Hu(p,g)||(a.track({type:2,doc:g}),v=!0,(d&&this.Gu(g,d)>0||m&&0>this.Gu(g,m))&&(h=!0)):!p&&g?(a.track({type:0,doc:g}),v=!0):p&&!g&&(a.track({type:1,doc:p}),v=!0,(d||m)&&(h=!0)),v&&(g?(c=c.add(g),l=w?l.add(e):l.delete(e)):(c=c.delete(e),l=l.delete(e)))}),null!==this.query.limit)for(;c.size>this.query.limit;){let e="F"===this.query.limitType?c.last():c.first();c=c.delete(e.key),l=l.delete(e.key),a.track({type:1,doc:e})}return{Qu:c,zu:a,$i:h,mutatedKeys:l}}Hu(e,t){return e.hasLocalMutations&&t.hasCommittedMutations&&!t.hasLocalMutations}applyChanges(e,t,a){let u=this.Qu;this.Qu=e.Qu,this.mutatedKeys=e.mutatedKeys;let l=e.zu.Eu();l.sort((e,t)=>(function(e,t){let n=e=>{switch(e){case 0:return 1;case 2:case 3:return 2;case 1:return 0;default:return O()}};return n(e)-n(t)})(e.type,t.type)||this.Gu(e.doc,t.doc)),this.Ju(a);let c=t?this.Yu():[],h=0===this.Ku.size&&this.current?1:0,d=h!==this.Uu;return(this.Uu=h,0!==l.length||d)?{snapshot:new oc(this.query,e.Qu,u,l,e.mutatedKeys,0===h,d,!1,!!a&&a.resumeToken.approximateByteSize()>0),Xu:c}:{Xu:c}}bu(e){return this.current&&"Offline"===e?(this.current=!1,this.applyChanges({Qu:this.Qu,zu:new rc,mutatedKeys:this.mutatedKeys,$i:!1},!1)):{Xu:[]}}Zu(e){return!this.qu.has(e)&&!!this.Qu.has(e)&&!this.Qu.get(e).hasLocalMutations}Ju(e){e&&(e.addedDocuments.forEach(e=>this.qu=this.qu.add(e)),e.modifiedDocuments.forEach(e=>{}),e.removedDocuments.forEach(e=>this.qu=this.qu.delete(e)),this.current=e.current)}Yu(){if(!this.current)return[];let e=this.Ku;this.Ku=Es(),this.Qu.forEach(e=>{this.Zu(e.key)&&(this.Ku=this.Ku.add(e.key))});let t=[];return e.forEach(e=>{this.Ku.has(e)||t.push(new Ic(e))}),this.Ku.forEach(a=>
1145{e.has(a)||t.push(new pc(a))}),t}tc(e){this.qu=e.Hi,this.Ku=Es();let t=this.Wu(e.documents);return this.applyChanges(t,!0)}ec(){return oc.fromInitialDocuments(this.query,this.Qu,this.mutatedKeys,0===this.Uu,this.hasCachedResults)}};let Ec=class Ec{constructor(e,t,a){this.query=e,this.targetId=t,this.view=a}};let Ac=class Ac{constructor(e){this.key=e,this.nc=!1}};let Rc=class Rc{constructor(e,t,a,u,l,c){this.localStore=e,this.remoteStore=t,this.eventManager=a,this.sharedClientState=u,this.currentUser=l,this.maxConcurrentLimboResolutions=c,this.sc={},this.ic=new ls(e=>Tn(e),In),this.rc=new Map,this.oc=new Set,this.uc=new Ge(ct.comparator),this.cc=new Map,this.ac=new Eo,this.hc={},this.lc=new Map,this.fc=Yr.vn(),this.onlineState="Unknown",this.dc=void 0}get isPrimaryClient(){return!0===this.dc}};async function bc(e,t){let a,u;let l=ta(e),c=l.ic.get(t);if(c)a=c.targetId,l.sharedClientState.addLocalQueryTarget(a),u=c.view.ec();else{let e=await zo(l.localStore,gn(t));l.isPrimaryClient&&Du(l.remoteStore,e);let c=l.sharedClientState.addLocalQueryTarget(e.targetId);a=e.targetId,u=await Pc(l,t,a,"current"===c,e.resumeToken)}return u}async function Pc(e,t,a,u,l){e._c=(t,a,u)=>(async function(e,t,a,u){let l=t.view.Wu(a);l.$i&&(l=await Jo(e.localStore,t.query,!1).then(({documents:e})=>t.view.Wu(e,l)));let c=u&&u.targetChanges.get(t.targetId),h=t.view.applyChanges(l,e.isPrimaryClient,c);return Bc(e,t.targetId,h.Xu),h.snapshot})(e,t,a,u);let c=await Jo(e.localStore,t,!0),h=new Tc(t,c.Hi),d=h.Wu(c.documents),m=Ps.createSynthesizedTargetChangeForCurrentChange(a,u&&"Offline"!==e.onlineState,l),p=h.applyChanges(d,e.isPrimaryClient,m);Bc(e,a,p.Xu);let g=new Ec(t,a,h);return e.ic.set(t,g),e.rc.has(a)?e.rc.get(a).push(t):e.rc.set(a,[t]),p.snapshot}async function vc(e,t){let a=e.ic.get(t),u=e.rc.get(a.targetId);if(u.length>1)return e.rc.set(a.targetId,u.filter(e=>!In(e,t))),void e.ic.delete(t);e.isPrimaryClient?(e.sharedClientState.removeLocalQueryTarget(a.targetId),e.sharedClientState.isActiveQueryTarget(a.targetId)||await Ho(e.localStore,a.targetId,!1).then(()=>{e.sharedClientState.clearQueryState(a.targetId),Cu(e.remoteStore,a.targetId),Fc(e,a.targetId)}).catch(Et)):(Fc(e,a.targetId),await Ho(e.localStore,a.targetId,!0))}async function Vc(e,t,a){let u=ea(e);try{var l;let e;let c=await function(e,t){let a,u;let l=nt.now(),c=t.reduce((e,t)=>e.add(t.key),Es());return e.persistence.runTransaction("Locally write mutations","readwrite",h=>{let d=I,m=Es();return e.Gi.getEntries(h,c).next(e=>{(d=e).forEach((e,t)=>{t.isValidDocument()||(m=m.add(e))})}).next(()=>e.localDocuments.getOverlayedDocuments(h,d)).next(u=>{a=u;let c=[];for(let e of t){let t=Yn(e,a.get(e.key).overlayedDocument);null!=t&&c.push(new ts(e.key,t,Xe(t.value.mapValue),Qn.exists(!0)))}return e.mutationQueue.addMutationBatch(h,l,c,t)}).next(t=>{u=t;let l=t.applyToLocalDocumentSet(a,m);return e.documentOverlayCache.saveOverlays(h,t.batchId,l)})}).then(()=>({batchId:u.batchId,changes:ms(a)}))}(u.localStore,t);u.sharedClientState.addPendingMutation(c.batchId),l=c.batchId,(e=u.hc[u.currentUser.toKey()])||(e=new Ge(Z)),e=e.insert(l,a),u.hc[u.currentUser.toKey()]=e,await Uc(u,c.changes),await Ku(u.remoteStore)}catch(t){let e=sc(t,"Failed to persist write");a.reject(e)}}async function Sc(e,t){try{let a=await Qo(e.localStore,t);
1145t.targetChanges.forEach((t,a)=>{let u=e.cc.get(a);u&&(t.addedDocuments.size+t.modifiedDocuments.size+t.removedDocuments.size<=1||O(),t.addedDocuments.size>0?u.nc=!0:t.modifiedDocuments.size>0?u.nc||O():t.removedDocuments.size>0&&(u.nc||O(),u.nc=!1))}),await Uc(e,a,t)}catch(e){await Et(e)}}function Dc(e,t,a){var u;if(e.isPrimaryClient&&0===a||!e.isPrimaryClient&&1===a){let a;let l=[];e.ic.forEach((e,a)=>{let u=a.view.bu(t);u.snapshot&&l.push(u.snapshot)}),(u=e.eventManager).onlineState=t,a=!1,u.queries.forEach((e,u)=>{for(let e of u.listeners)e.bu(t)&&(a=!0)}),a&&dc(u),l.length&&e.sc.Wo(l),e.onlineState=t,e.isPrimaryClient&&e.sharedClientState.setOnlineState(t)}}async function Cc(e,t,a){e.sharedClientState.updateQueryState(t,"rejected",a);let u=e.cc.get(t),l=u&&u.key;if(l){let a=new Ge(ct.comparator);a=a.insert(l,Ze.newNoDocument(l,st.min()));let u=Es().add(l),c=new bs(st.min(),new Map,new We(Z),a,u);await Sc(e,c),e.uc=e.uc.remove(l),e.cc.delete(t),qc(e)}else await Ho(e.localStore,t,!1).then(()=>Fc(e,t,a)).catch(Et)}async function xc(e,t){let a=t.batch.batchId;try{let u=await Ko(e.localStore,t);Mc(e,a,null),Oc(e,a),e.sharedClientState.updateMutationState(a,"acknowledged"),await Uc(e,u)}catch(e){await Et(e)}}async function Nc(e,t,a){var u;try{let l=await (u=e.localStore).persistence.runTransaction("Reject batch","readwrite-primary",e=>{let a;return u.mutationQueue.lookupMutationBatch(e,t).next(t=>(null!==t||O(),a=t.keys(),u.mutationQueue.removeMutationBatch(e,t))).next(()=>u.mutationQueue.performConsistencyCheck(e)).next(()=>u.documentOverlayCache.removeOverlaysForBatchId(e,a,t)).next(()=>u.localDocuments.recalculateAndSaveOverlaysForDocumentKeys(e,a)).next(()=>u.localDocuments.getDocuments(e,a))});Mc(e,t,a),Oc(e,t),e.sharedClientState.updateMutationState(t,"rejected",a),await Uc(e,l)}catch(e){await Et(e)}}function Oc(e,t){(e.lc.get(t)||[]).forEach(e=>{e.resolve()}),e.lc.delete(t)}function Mc(e,t,a){let u=e.hc[e.currentUser.toKey()];if(u){let l=u.get(t);l&&(a?l.reject(a):l.resolve(),u=u.remove(t)),e.hc[e.currentUser.toKey()]=u}}function Fc(e,t,a=null){for(let u of(e.sharedClientState.removeLocalQueryTarget(t),e.rc.get(t)))e.ic.delete(u),a&&e.sc.wc(u,a);e.rc.delete(t),e.isPrimaryClient&&e.ac.ls(t).forEach(t=>{e.ac.containsKey(t)||$c(e,t)})}function $c(e,t){e.oc.delete(t.path.canonicalString());let a=e.uc.get(t);null!==a&&(Cu(e.remoteStore,a),e.uc=e.uc.remove(t),e.cc.delete(a),qc(e))}function Bc(e,t,a){for(let u of a)u instanceof pc?(e.ac.addReference(u.key,t),Lc(e,u)):u instanceof Ic?(C("SyncEngine","Document no longer in limbo: "+u.key),e.ac.removeReference(u.key,t),e.ac.containsKey(u.key)||$c(e,u.key)):O()}function Lc(e,t){let a=t.key,u=a.path.canonicalString();e.uc.get(a)||e.oc.has(u)||(C("SyncEngine","New document in limbo: "+a),e.oc.add(u),qc(e))}function qc(e){for(;e.oc.size>0&&e.uc.size<e.maxConcurrentLimboResolutions;){let t=e.oc.values().next().value;e.oc.delete(t);let a=new ct(rt.fromString(t)),u=e.fc.next();e.cc.set(u,new Ac(a)),e.uc=e.uc.insert(a,u),Du(e.remoteStore,new zi(gn(ln(a.path)),u,2,Ot.at))}}async function Uc(e,t,a){let u=[],l=[],c=[];e.ic.isEmpty()||(e.ic.forEach((h,d)=>{c.push(e._c(d,t,a).then(t=>{if((t||a)&&e.isPrimaryClient&&e.sharedClientState.updateQueryState(d.targetId,(null==t?void 0:t.fromCache)?"not-current":"current"),t){u.push(t);let e=$o.Ci(d.targetId,t);l.push(e)}}))}),await Promise.all(c),e.sc.Wo(u),await async function(e,t){try{await e.persistence.runTransaction("notifyLocalViewChanges","readwrite",a=>At.forEach(t,t=>At.forEach(t.Si,u=>e.persistence.referenceDelegate.addReference(a,t.targetId,u)).next(()=>At.forEach(t.Di,u=>e.persistence.referenceDelegate.removeReference(a,t.targetId,u)))))}catch(e){if(!Vt(e))throw e;C("LocalStore","Failed to update sequence numbers: "+e)}for(let a of t){let t=a.targetId;if(!a.fromCache){let a=e.qi.get(t),u=a.snapshotVersion,l=a.withLastLimboFreeSnapshotVersion(u);e.qi=e.qi.insert(t,l)}}}(e.localStore,l))}async function Kc(e,t){if(!e.currentUser.isEqual(t)){C("SyncEngine","User change. New user:",t.toKey());let a=await Uo(e.localStore,t);
1145e.currentUser=t,e.lc.forEach(e=>{e.forEach(e=>{e.reject(new L(v.CANCELLED,"'waitForPendingWrites' promise is rejected due to a user change."))})}),e.lc.clear(),e.sharedClientState.handleUserChange(t,a.removedBatchIds,a.addedBatchIds),await Uc(e,a.ji)}}function Gc(e,t){let a=e.cc.get(t);if(a&&a.nc)return Es().add(a.key);{let a=Es(),u=e.rc.get(t);if(!u)return a;for(let t of u){let u=e.ic.get(t);a=a.unionWith(u.view.ju)}return a}}function ta(e){return e.remoteStore.remoteSyncer.applyRemoteEvent=Sc.bind(null,e),e.remoteStore.remoteSyncer.getRemoteKeysForTarget=Gc.bind(null,e),e.remoteStore.remoteSyncer.rejectListen=Cc.bind(null,e),e.sc.Wo=lc.bind(null,e.eventManager),e.sc.wc=fc.bind(null,e.eventManager),e}function ea(e){return e.remoteStore.remoteSyncer.applySuccessfulWrite=xc.bind(null,e),e.remoteStore.remoteSyncer.rejectFailedWrite=Nc.bind(null,e),e}let sa=class sa{constructor(){this.synchronizeTabs=!1}async initialize(e){this.yt=pu(e.databaseInfo.databaseId),this.sharedClientState=this.gc(e),this.persistence=this.yc(e),await this.persistence.start(),this.localStore=this.Ic(e),this.gcScheduler=this.Tc(e,this.localStore),this.indexBackfillerScheduler=this.Ec(e,this.localStore)}Tc(e,t){return null}Ec(e,t){return null}Ic(e){return qo(this.persistence,new Bo,e.initialUser,this.yt)}yc(e){return new Vo(Do.Bs,this.yt)}gc(e){return new lu}async terminate(){this.gcScheduler&&this.gcScheduler.stop(),await this.sharedClientState.shutdown(),await this.persistence.shutdown()}};let oa=class oa{async initialize(e,t){this.localStore||(this.localStore=e.localStore,this.sharedClientState=e.sharedClientState,this.datastore=this.createDatastore(t),this.remoteStore=this.createRemoteStore(t),this.eventManager=this.createEventManager(t),this.syncEngine=this.createSyncEngine(t,!e.synchronizeTabs),this.sharedClientState.onlineStateHandler=e=>Dc(this.syncEngine,e,1),this.remoteStore.remoteSyncer.handleCredentialChange=Kc.bind(null,this.syncEngine),await Zu(this.remoteStore,this.syncEngine.isPrimaryClient))}createEventManager(e){return new cc}createDatastore(e){let t=pu(e.databaseInfo.databaseId),a=new mu(e.databaseInfo);return new Ru(e.authCredentials,e.appCheckCredentials,a,t)}createRemoteStore(e){var t;return t=this.localStore,new vu(t,this.datastore,e.asyncQueue,e=>Dc(this.syncEngine,e,0),du.C()?new du:new fu)}createSyncEngine(e,t){return function(e,t,a,u,l,c,h){let d=new Rc(e,t,a,u,l,c);return h&&(d.dc=!0),d}(this.localStore,this.remoteStore,this.eventManager,this.sharedClientState,e.initialUser,e.maxConcurrentLimboResolutions,t)}terminate(){return async function(e){C("RemoteStore","RemoteStore shutting down."),e._u.add(5),await Su(e),e.mu.shutdown(),e.gu.set("Unknown")}(this.remoteStore)}};/** 1146 * @license 1147 * Copyright 2017 Google LLC 1148 * 1149 * Licensed under the Apache License, Version 2.0 (the "License"); 1150 * you may not use this file except in compliance with the License. 1151 * You may obtain a copy of the License at 1152 * 1153 * http://www.apache.org/licenses/LICENSE-2.0 1154 * 1155 * Unless required by applicable law or agreed to in writing, software 1156 * distributed under the License is distributed on an "AS IS" BASIS, 1157 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1158 * See the License for the specific language governing permissions and 1159 * limitations under the License. 1160 */function ua(e,t,a){if(!a)throw new L(v.INVALID_ARGUMENT,`Function ${e}() cannot be called with an empty ${t}.`)}function ca(e,t,a,u){if(!0===t&&!0===u)throw new L(v.INVALID_ARGUMENT,`${e} and ${a} cannot be used together.`)}function aa(e){if(!ct.isDocumentKey(e))throw new L(v.INVALID_ARGUMENT,`Invalid document reference. Document references must have an even number of segments, but ${e} has ${e.length}.`)}function ha(e){if(ct.isDocumentKey(e))throw new L(v.INVALID_ARGUMENT,`Invalid collection reference. Collection references must have an odd number of segments, but ${e} has ${e.length}.`)}function la(e){if(void 0===e)return"undefined";if(null===e)return"null";if("string"==typeof e)return e.length>20&&(e=`${e.substring(0,20)}...`),JSON.stringify(e);if("number"==typeof e||"boolean"==typeof e)return""+e;if("object"==typeof e){if(e instanceof Array)return"an array";{var t;let a=(t=e).constructor?t.constructor.name:null;return a?`a custom ${a} object`:"an object"}}return"function"==typeof e?"a function":O()}function fa(e,t){if("_delegate"in e&&(e=e._delegate),!(e instanceof t)){if(t.name===e.constructor.name)throw new L(v.INVA
1160LID_ARGUMENT,"Type does not match the expected instance. Did you pass a reference from a different Firestore SDK?");{let a=la(e);throw new L(v.INVALID_ARGUMENT,`Expected type '${t.name}', but it was: ${a}`)}}return e}function da(e,t){if(t<=0)throw new L(v.INVALID_ARGUMENT,`Function ${e}() requires a positive number, but it was: ${t}.`)}/** 1161 * @license 1162 * Copyright 2020 Google LLC 1163 * 1164 * Licensed under the Apache License, Version 2.0 (the "License"); 1165 * you may not use this file except in compliance with the License. 1166 * You may obtain a copy of the License at 1167 * 1168 * http://www.apache.org/licenses/LICENSE-2.0 1169 * 1170 * Unless required by applicable law or agreed to in writing, software 1171 * distributed under the License is distributed on an "AS IS" BASIS, 1172 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1173 * See the License for the specific language governing permissions and 1174 * limitations under the License. 1175 */let $=new Map;let wa=class wa{constructor(e){var t;if(void 0===e.host){if(void 0!==e.ssl)throw new L(v.INVALID_ARGUMENT,"Can't provide ssl option if host option is not set");this.host="firestore.googleapis.com",this.ssl=!0}else this.host=e.host,this.ssl=null===(t=e.ssl)||void 0===t||t;if(this.credentials=e.credentials,this.ignoreUndefinedProperties=!!e.ignoreUndefinedProperties,void 0===e.cacheSizeBytes)this.cacheSizeBytes=41943040;else{if(-1!==e.cacheSizeBytes&&e.cacheSizeBytes<1048576)throw new L(v.INVALID_ARGUMENT,"cacheSizeBytes must be at least 1048576");this.cacheSizeBytes=e.cacheSizeBytes}this.experimentalForceLongPolling=!!e.experimentalForceLongPolling,this.experimentalAutoDetectLongPolling=!!e.experimentalAutoDetectLongPolling,this.useFetchStreams=!!e.useFetchStreams,ca("experimentalForceLongPolling",e.experimentalForceLongPolling,"experimentalAutoDetectLongPolling",e.experimentalAutoDetectLongPolling)}isEqual(e){return this.host===e.host&&this.ssl===e.ssl&&this.credentials===e.credentials&&this.cacheSizeBytes===e.cacheSizeBytes&&this.experimentalForceLongPolling===e.experimentalForceLongPolling&&this.experimentalAutoDetectLongPolling===e.experimentalAutoDetectLongPolling&&this.ignoreUndefinedProperties===e.ignoreUndefinedProperties&&this.useFetchStreams===e.useFetchStreams}};/** 1176 * @license 1177 * Copyright 2020 Google LLC 1178 * 1179 * Licensed under the Apache License, Version 2.0 (the "License"); 1180 * you may not use this file except in compliance with the License. 1181 * You may obtain a copy of the License at 1182 * 1183 * http://www.apache.org/licenses/LICENSE-2.0 1184 * 1185 * Unless required by applicable law or agreed to in writing, software 1186 * distributed under the License is distributed on an "AS IS" BASIS, 1187 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1188 * See the License for the specific language governing permissions and 1189 * limitations under the License. 1190 */let ma=class ma{constructor(e,t,a,u){this._authCredentials=e,this._appCheckCredentials=t,this._databaseId=a,this._app=u,this.type="firestore-lite",this._persistenceKey="(lite)",this._settings=new wa({}),this._settingsFrozen=!1}get app(){if(!this._app)throw new L(v.FAILED_PRECONDITION,"Firestore was not initialized using the Firebase SDK. 'app' is not available");return this._app}get _initialized(){return this._settingsFrozen}get _terminated(){return void 0!==this._terminateTask}_setSettings(e){if(this._settingsFrozen)throw new L(v.FAILED_PRECONDITION,"Firestore has already been started and its settings can no longer be changed. You can only modify settings before calling any other methods on a Firestore object.");this._settings=new wa(e),void 0!==e.credentials&&(this._authCredentials=function(e){if(!e)return new K;switch(e.type){case"gapi":let t=e.client;return new W(t,e.sessionIndex||"0",e.iamToken||null,e.authTokenFactory||null);case"provider":return e.client;default:throw new L(v.INVALID_ARGUMENT,"makeAuthCredentialsProvider failed due to invalid credential type")}}(e.credentials))}_getSettings(){return this._settings}_freezeSettings(){return this._settingsFrozen=!0,this._settings}_delete(){return this._terminateTask||(this._terminateTask=this._terminate()),this._terminateTask}toJSON(){return{app:this._app,databaseId:this._databaseId,settings:this._settings}}_terminate(){return function(e){let t=$.get(e);t&&(C("ComponentProvider","Removing Datastore"),$.delete(e),t.terminate())}(this),Promise.resolve()}};function ga(e,t,a,u={}){var l;let c=(e=fa(e,ma))._getSettings();if("firestore.googleapis.com"!==c.host&&c.host!==t&&N("Host has been set in both settings() and useEmulator(), emulator host will be used"),e._setSettings(Object.assign(Object.assign({},c),{host:`${t}:${a}`,ssl:!1})),u.mockUserToken){let t,a;if("string"==typeof u.mockUserToken)t=u.mockUserToken,a=P.MOCK_USER;else{t=(0,m.Sg)(u.mockUserToken,null===(l=e._app)||void 0===l?void 0:l.options.projectId);let c=u.mockUserToken.sub||u.mockUserToken.user_id;
1190if(!c)throw new L(v.INVALID_ARGUMENT,"mockUserToken must contain 'sub' or 'user_id' field!");a=new P(c)}e._authCredentials=new G(new U(t,a))}}/** 1191 * @license 1192 * Copyright 2020 Google LLC 1193 * 1194 * Licensed under the Apache License, Version 2.0 (the "License"); 1195 * you may not use this file except in compliance with the License. 1196 * You may obtain a copy of the License at 1197 * 1198 * http://www.apache.org/licenses/LICENSE-2.0 1199 * 1200 * Unless required by applicable law or agreed to in writing, software 1201 * distributed under the License is distributed on an "AS IS" BASIS, 1202 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1203 * See the License for the specific language governing permissions and 1204 * limitations under the License. 1205 */let ya=class ya{constructor(e,t,a){this.converter=t,this._key=a,this.type="document",this.firestore=e}get _path(){return this._key.path}get id(){return this._key.path.lastSegment()}get path(){return this._key.path.canonicalString()}get parent(){return new Ia(this.firestore,this.converter,this._key.path.popLast())}withConverter(e){return new ya(this.firestore,e,this._key)}};let pa=class pa{constructor(e,t,a){this.converter=t,this._query=a,this.type="query",this.firestore=e}withConverter(e){return new pa(this.firestore,e,this._query)}};let Ia=class Ia extends pa{constructor(e,t,a){super(e,t,ln(a)),this._path=a,this.type="collection"}get id(){return this._query.path.lastSegment()}get path(){return this._query.path.canonicalString()}get parent(){let e=this._path.popLast();return e.isEmpty()?null:new ya(this.firestore,null,new ct(e))}withConverter(e){return new Ia(this.firestore,e,this._path)}};function Ta(e,t,...a){if(e=(0,m.m9)(e),ua("collection","path",t),e instanceof ma){let u=rt.fromString(t,...a);return ha(u),new Ia(e,null,u)}{if(!(e instanceof ya||e instanceof Ia))throw new L(v.INVALID_ARGUMENT,"Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore");let u=e._path.child(rt.fromString(t,...a));return ha(u),new Ia(e.firestore,null,u)}}function Aa(e,t,...a){if(e=(0,m.m9)(e),1==arguments.length&&(t=X.R()),ua("doc","path",t),e instanceof ma){let u=rt.fromString(t,...a);return aa(u),new ya(e,null,new ct(u))}{if(!(e instanceof ya||e instanceof Ia))throw new L(v.INVALID_ARGUMENT,"Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore");let u=e._path.child(rt.fromString(t,...a));return aa(u),new ya(e.firestore,e instanceof Ia?e.converter:null,new ct(u))}}/** 1206 * @license 1207 * Copyright 2020 Google LLC 1208 * 1209 * Licensed under the Apache License, Version 2.0 (the "License"); 1210 * you may not use this file except in compliance with the License. 1211 * You may obtain a copy of the License at 1212 * 1213 * http://www.apache.org/licenses/LICENSE-2.0 1214 * 1215 * Unless required by applicable law or agreed to in writing, software 1216 * distributed under the License is distributed on an "AS IS" BASIS, 1217 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1218 * See the License for the specific language governing permissions and 1219 * limitations under the License. 1220 *//** 1221 * @license 1222 * Copyright 2017 Google LLC 1223 * 1224 * Licensed under the Apache License, Version 2.0 (the "License"); 1225 * you may not use this file except in compliance with the License. 1226 * You may obtain a copy of the License at 1227 * 1228 * http://www.apache.org/licenses/LICENSE-2.0 1229 * 1230 * Unless required by applicable law or agreed to in writing, software 1231 * distributed under the License is distributed on an "AS IS" BASIS, 1232 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1233 * See the License for the specific language governing permissions and 1234 * limitations under the License. 1235 */let va=class va{constructor(e){this.observer=e,this.muted=!1}next(e){this.observer.next&&this.Rc(this.observer.next,e)}error(e){this.observer.error?this.Rc(this.observer.error,e):x("Uncaught Error in snapshot listener:",e.toString())}bc(){this.muted=!0}Rc(e,t){this.muted||setTimeout(()=>{this.muted||e(t)},0)}};/** 1236 * @license 1237 * Copyright 2017 Google LLC 1238 * 1239 * Licensed under the Apache License, Version 2.0 (the "License");
1240 * you may not use this file except in compliance with the License. 1241 * You may obtain a copy of the License at 1242 * 1243 * http://www.apache.org/licenses/LICENSE-2.0 1244 * 1245 * Unless required by applicable law or agreed to in writing, software 1246 * distributed under the License is distributed on an "AS IS" BASIS, 1247 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1248 * See the License for the specific language governing permissions and 1249 * limitations under the License. 1250 */let ka=class ka{constructor(e,t,a,u){this.authCredentials=e,this.appCheckCredentials=t,this.asyncQueue=a,this.databaseInfo=u,this.user=P.UNAUTHENTICATED,this.clientId=X.R(),this.authCredentialListener=()=>Promise.resolve(),this.appCheckCredentialListener=()=>Promise.resolve(),this.authCredentials.start(a,async e=>{C("FirestoreClient","Received user=",e.uid),await this.authCredentialListener(e),this.user=e}),this.appCheckCredentials.start(a,e=>(C("FirestoreClient","Received new app check token=",e),this.appCheckCredentialListener(e,this.user)))}async getConfiguration(){return{asyncQueue:this.asyncQueue,databaseInfo:this.databaseInfo,clientId:this.clientId,authCredentials:this.authCredentials,appCheckCredentials:this.appCheckCredentials,initialUser:this.user,maxConcurrentLimboResolutions:100}}setCredentialChangeListener(e){this.authCredentialListener=e}setAppCheckTokenChangeListener(e){this.appCheckCredentialListener=e}verifyNotTerminated(){if(this.asyncQueue.isShuttingDown)throw new L(v.FAILED_PRECONDITION,"The client has already been terminated.")}terminate(){this.asyncQueue.enterRestrictedMode();let e=new q;return this.asyncQueue.enqueueAndForgetEvenWhileRestricted(async()=>{try{this.onlineComponents&&await this.onlineComponents.terminate(),this.offlineComponents&&await this.offlineComponents.terminate(),this.authCredentials.shutdown(),this.appCheckCredentials.shutdown(),e.resolve()}catch(a){let t=sc(a,"Failed to shutdown persistence");e.reject(t)}}),e.promise}};async function Oa(e,t){e.asyncQueue.verifyOperationInProgress(),C("FirestoreClient","Initializing OfflineComponentProvider");let a=await e.getConfiguration();await t.initialize(a);let u=a.initialUser;e.setCredentialChangeListener(async e=>{u.isEqual(e)||(await Uo(t.localStore,e),u=e)}),t.persistence.setDatabaseDeletedListener(()=>e.terminate()),e.offlineComponents=t}async function Ma(e,t){e.asyncQueue.verifyOperationInProgress();let a=await Fa(e);C("FirestoreClient","Initializing OnlineComponentProvider");let u=await e.getConfiguration();await t.initialize(a,u),e.setCredentialChangeListener(e=>Xu(t.remoteStore,e)),e.setAppCheckTokenChangeListener((e,a)=>Xu(t.remoteStore,a)),e.onlineComponents=t}async function Fa(e){return e.offlineComponents||(C("FirestoreClient","Using default OfflineComponentProvider"),await Oa(e,new sa)),e.offlineComponents}async function $a(e){return e.onlineComponents||(C("FirestoreClient","Using default OnlineComponentProvider"),await Ma(e,new oa)),e.onlineComponents}function Ua(e){return $a(e).then(e=>e.syncEngine)}async function Ga(e){let t=await $a(e),a=t.eventManager;return a.onListen=bc.bind(null,t.syncEngine),a.onUnlisten=vc.bind(null,t.syncEngine),a}function za(e,t,a={}){let u=new q;return e.asyncQueue.enqueueAndForget(async()=>(function(e,t,a,u,l){let c=new va({next:c=>{t.enqueueAndForget(()=>hc(e,h));let d=c.docs.has(a);!d&&c.fromCache?l.reject(new L(v.UNAVAILABLE,"Failed to get document because the client is offline.")):d&&c.fromCache&&u&&"server"===u.source?l.reject(new L(v.UNAVAILABLE,'Failed to get document from server. (However, this document does exist in the local cache. Run again without setting source to "server" to retrieve the cached document.)')):l.resolve(c)},error:e=>l.reject(e)}),h=new _c(ln(a.path),c,{includeMetadataChanges:!0,Nu:!0});return ac(e,h)})(await Ga(e),e.asyncQueue,t,a,u)),u.promise}function Ja(e,t,a={}){let u=new q;return e.asyncQueue.enqueueAndForget(async()=>(function(e,t,a,u,l){let c=new va({next:a=>{t.enqueueAndForget(()=>hc(e,h)),a.fromCache&&"server"===u.source?l.reject(new L(v.UNAVAILABLE,'Failed to get documents from server. (However, these documents may exist in the local cache. Run again without setting source to "server" to retrieve the cached documents.)')):l.resolve(a)},error:e=>l.reject(e)}),h=new _c(a,c,{includeMetadataChanges:!0,Nu:!0});return ac(e,h)})(await Ga(e),e.asyncQueue,t,a,u)),u.promise}
1250let th=class th{constructor(){this.Bc=Promise.resolve(),this.Lc=[],this.qc=!1,this.Uc=[],this.Kc=null,this.Gc=!1,this.Qc=!1,this.jc=[],this.xo=new Iu(this,"async_queue_retry"),this.Wc=()=>{let e=yu();e&&C("AsyncQueue","Visibility state changed to "+e.visibilityState),this.xo.Po()};let e=yu();e&&"function"==typeof e.addEventListener&&e.addEventListener("visibilitychange",this.Wc)}get isShuttingDown(){return this.qc}enqueueAndForget(e){this.enqueue(e)}enqueueAndForgetEvenWhileRestricted(e){this.zc(),this.Hc(e)}enterRestrictedMode(e){if(!this.qc){this.qc=!0,this.Qc=e||!1;let t=yu();t&&"function"==typeof t.removeEventListener&&t.removeEventListener("visibilitychange",this.Wc)}}enqueue(e){if(this.zc(),this.qc)return new Promise(()=>{});let t=new q;return this.Hc(()=>this.qc&&this.Qc?Promise.resolve():(e().then(t.resolve,t.reject),t.promise)).then(()=>t.promise)}enqueueRetryable(e){this.enqueueAndForget(()=>(this.Lc.push(e),this.Jc()))}async Jc(){if(0!==this.Lc.length){try{await this.Lc[0](),this.Lc.shift(),this.xo.reset()}catch(e){if(!Vt(e))throw e;C("AsyncQueue","Operation failed with retryable error: "+e)}this.Lc.length>0&&this.xo.Ro(()=>this.Jc())}}Hc(e){let t=this.Bc.then(()=>(this.Gc=!0,e().catch(e=>{let t;this.Kc=e,this.Gc=!1;let a=(t=e.message||"",e.stack&&(t=e.stack.includes(e.message)?e.stack:e.message+"\n"+e.stack),t);throw x("INTERNAL UNHANDLED ERROR: ",a),e}).then(e=>(this.Gc=!1,e))));return this.Bc=t,t}enqueueAfterDelay(e,t,a){this.zc(),this.jc.indexOf(e)>-1&&(t=0);let u=nc.createAndSchedule(this,e,t,a,e=>this.Yc(e));return this.Uc.push(u),u}zc(){this.Kc&&O()}verifyOperationInProgress(){}async Xc(){let e;do e=this.Bc,await e;while(e!==this.Bc)}Zc(e){for(let t of this.Uc)if(t.timerId===e)return!0;return!1}ta(e){return this.Xc().then(()=>{for(let t of(this.Uc.sort((e,t)=>e.targetTimeMs-t.targetTimeMs),this.Uc))if(t.skipDelay(),"all"!==e&&t.timerId===e)break;return this.Xc()})}ea(e){this.jc.push(e)}Yc(e){let t=this.Uc.indexOf(e);this.Uc.splice(t,1)}};function eh(e){return function(e,t){if("object"!=typeof e||null===e)return!1;for(let a of t)if(a in e&&"function"==typeof e[a])return!0;return!1}(e,["next","error","complete"])}let ih=class ih extends ma{constructor(e,t,a,u){super(e,t,a,u),this.type="firestore",this._queue=new th,this._persistenceKey=(null==u?void 0:u.name)||"[DEFAULT]"}_terminate(){return this._firestoreClient||ch(this),this._firestoreClient.terminate()}};function oh(e,t){let a="object"==typeof e?e:(0,c.Mq)(),u=(0,c.qX)(a,"firestore").getImmediate({identifier:"string"==typeof e?e:t||"(default)"});if(!u._initialized){let e=(0,m.P0)("firestore");e&&ga(u,...e)}return u}function uh(e){return e._firestoreClient||ch(e),e._firestoreClient.verifyNotTerminated(),e._firestoreClient}function ch(e){var t,a;let u=e._freezeSettings(),l=(a=e._databaseId,new Mt(a,(null===(t=e._app)||void 0===t?void 0:t.options.appId)||"",e._persistenceKey,u.host,u.ssl,u.experimentalForceLongPolling,u.experimentalAutoDetectLongPolling,u.useFetchStreams));e._firestoreClient=new ka(e._authCredentials,e._appCheckCredentials,e._queue,l)}/** 1251 * @license 1252 * Copyright 2020 Google LLC 1253 * 1254 * Licensed under the Apache License, Version 2.0 (the "License"); 1255 * you may not use this file except in compliance with the License. 1256 * You may obtain a copy of the License at 1257 * 1258 * http://www.apache.org/licenses/LICENSE-2.0 1259 * 1260 * Unless required by applicable law or agreed to in writing, software 1261 * distributed under the License is distributed on an "AS IS" BASIS, 1262 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1263 * See the License for the specific language governing permissions and 1264 * limitations under the License. 1265 *//** 1266 * @license 1267 * Copyright 2020 Google LLC 1268 * 1269 * Licensed under the Apache License, Version 2.0 (the "License"); 1270 * you may not use this file except in compliance with the License. 1271 * You may obtain a copy of the License at 1272 * 1273 * http://www.apache.org/licenses/LICENSE-2.0 1274 * 1275 * Unless required by applicable law or agreed to in writing, software 1276 * distributed under the License is distributed on an "AS IS" BASIS, 1277 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1278 * See the License for the specific language governing permissions and 1279 * limitations under the License. 1280 */let Ih=class Ih{constructor(e){this._byteString=e}static fromBase64String(e){try{return new Ih(Qt.fromBase64String(e))}
1280catch(e){throw new L(v.INVALID_ARGUMENT,"Failed to construct data from Base64 string: "+e)}}static fromUint8Array(e){return new Ih(Qt.fromUint8Array(e))}toBase64(){return this._byteString.toBase64()}toUint8Array(){return this._byteString.toUint8Array()}toString(){return"Bytes(base64: "+this.toBase64()+")"}isEqual(e){return this._byteString.isEqual(e._byteString)}};/** 1281 * @license 1282 * Copyright 2020 Google LLC 1283 * 1284 * Licensed under the Apache License, Version 2.0 (the "License"); 1285 * you may not use this file except in compliance with the License. 1286 * You may obtain a copy of the License at 1287 * 1288 * http://www.apache.org/licenses/LICENSE-2.0 1289 * 1290 * Unless required by applicable law or agreed to in writing, software 1291 * distributed under the License is distributed on an "AS IS" BASIS, 1292 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1293 * See the License for the specific language governing permissions and 1294 * limitations under the License. 1295 */let Th=class Th{constructor(...e){for(let t=0;t<e.length;++t)if(0===e[t].length)throw new L(v.INVALID_ARGUMENT,"Invalid field name at argument $(i + 1). Field names must not be empty.");this._internalPath=new ut(e)}isEqual(e){return this._internalPath.isEqual(e._internalPath)}};/** 1296 * @license 1297 * Copyright 2020 Google LLC 1298 * 1299 * Licensed under the Apache License, Version 2.0 (the "License"); 1300 * you may not use this file except in compliance with the License. 1301 * You may obtain a copy of the License at 1302 * 1303 * http://www.apache.org/licenses/LICENSE-2.0 1304 * 1305 * Unless required by applicable law or agreed to in writing, software 1306 * distributed under the License is distributed on an "AS IS" BASIS, 1307 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1308 * See the License for the specific language governing permissions and 1309 * limitations under the License. 1310 */let Ah=class Ah{constructor(e){this._methodName=e}};/** 1311 * @license 1312 * Copyright 2017 Google LLC 1313 * 1314 * Licensed under the Apache License, Version 2.0 (the "License"); 1315 * you may not use this file except in compliance with the License. 1316 * You may obtain a copy of the License at 1317 * 1318 * http://www.apache.org/licenses/LICENSE-2.0 1319 * 1320 * Unless required by applicable law or agreed to in writing, software 1321 * distributed under the License is distributed on an "AS IS" BASIS, 1322 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1323 * See the License for the specific language governing permissions and 1324 * limitations under the License. 1325 */let Rh=class Rh{constructor(e,t){if(!isFinite(e)||e<-90||e>90)throw new L(v.INVALID_ARGUMENT,"Latitude must be a number between -90 and 90, but was: "+e);if(!isFinite(t)||t<-180||t>180)throw new L(v.INVALID_ARGUMENT,"Longitude must be a number between -180 and 180, but was: "+t);this._lat=e,this._long=t}get latitude(){return this._lat}get longitude(){return this._long}isEqual(e){return this._lat===e._lat&&this._long===e._long}toJSON(){return{latitude:this._lat,longitude:this._long}}_compareTo(e){return Z(this._lat,e._lat)||Z(this._long,e._long)}};/** 1326 * @license 1327 * Copyright 2017 Google LLC 1328 * 1329 * Licensed under the Apache License, Version 2.0 (the "License"); 1330 * you may not use this file except in compliance with the License. 1331 * You may obtain a copy of the License at 1332 * 1333 * http://www.apache.org/licenses/LICENSE-2.0 1334 * 1335 * Unless required by applicable law or agreed to in writing, software 1336 * distributed under the License is distributed on an "AS IS" BASIS, 1337 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1338 * See the License for the specific language governing permissions and 1339 * limitations under the License. 1340 */let J=/^__.*__$/;let Ph=class Ph{constructor(e,t,a){this.data=e,this.fieldMask=t,this.fieldTransforms=a}toMutation(e,t){return null!==this.fieldMask?new ts(e,this.data,this.fieldMask,t,this.fieldTransforms):new Zn(e,this.data,t,this.fieldTransforms)}};let vh=class vh{constructor(e,t,a){this.data=e,this.fieldMask=t,this.fieldTransforms=a}toMutation(e,t){return new ts(e,this.data,this.fieldMask,t,this.fieldTransforms)}};function Vh(e){switch(e){case 0:case 2:case 1:return!0;case 3:case 4:return!1;default:throw O()}}let Sh=class Sh{constructor(e,t,a,u,l,c){this.settings=e,this.databaseId=t,this.yt=a,this.ignoreUndefinedProperties=u,void 0===l&&this.na(),this.fieldTransforms=l||[],this.fieldMask=c||[]}get path(){return this.settings.path}get sa(){return this.settings.sa}ia(e){return new Sh(Object.assign(Object.assign({},this.settings),e),this.databaseId,this.yt,this.ignoreUndefinedProperties,this.fieldTransforms,this.fieldMask)}ra(e){var t;let a=null===(t=this.path)||void 0===t?void 0:t.child(e),u=this.ia({path:a,oa:!1});return u.ua(e),u}ca(e){var t;let a=null===(t=this.path)||void 0===t?void 0:t.child(e),u=this.ia({path:a,oa:!1});return u.na(),u}aa(e){return this.ia({path:void 0,oa:!0})}ha(e){return Hh(e,this.settings.methodName,this.settings.la||!1,this.path,this.settings.fa)}contains(e){return void 0!==this.fieldMask.find(t=>e.isPrefixOf(t))||void 0!==this.fieldTransforms.find(t=>e.isPrefixOf(t.field))}na(){if(this.path)for(let e=0;e<this.path.length;e++)this.ua(this.path.get(e))}ua(e){if(0===e.length)throw this.ha("Document fields must not be empty");if(Vh(this.sa)&&J.test(e))throw this.ha('Document fields cannot begin and end with "__"')}};let Dh=class Dh{constructor(e,t,a){this.databaseId=e,this.ignoreUndefinedProperties=t,this.yt=a||pu(e)}da(e,t,a,u=!1){return new Sh({sa:e,methodName:t,fa:a,path:ut.emptyPath(),oa:!1,la:u},this.databaseId,this.yt,this.ignoreUndefinedProperties)}};function Ch(e){let t=e._freezeSettings(),a=pu(e._databaseId);return new Dh(e._databaseId,!!t.ignoreUndefinedProperties,a)}function xh(e,t,a,u,l,c={}){let h,d;let m=e.da(c.merge||c.mergeFields?2:0,t,a,l);Qh("Data must be an object, but it was:",m,u);let p=Kh(u,m);if(c.merge)h=new Je(m.fieldMask),d=m.fieldTransforms;else if(c.mergeFields){let e=[];for(let u of c.mergeFields){let l=jh(t,u,a);
1340if(!m.contains(l))throw new L(v.INVALID_ARGUMENT,`Field '${l}' is specified in your field mask but missing from your input data.`);Jh(e,l)||e.push(l)}h=new Je(e),d=m.fieldTransforms.filter(e=>h.covers(e.field))}else h=null,d=m.fieldTransforms;return new Ph(new Ye(p),h,d)}let Nh=class Nh extends Ah{_toFieldTransform(e){if(2!==e.sa)throw 1===e.sa?e.ha(`${this._methodName}() can only appear at the top level of your update data`):e.ha(`${this._methodName}() cannot be used with set() unless you pass {merge:true}`);return e.fieldMask.push(e.path),null}isEqual(e){return e instanceof Nh}};function kh(e,t,a){return new Sh({sa:3,fa:t.settings.fa,methodName:e._methodName,oa:a},t.databaseId,t.yt,t.ignoreUndefinedProperties)}let Oh=class Oh extends Ah{_toFieldTransform(e){return new Un(e.path,new kn)}isEqual(e){return e instanceof Oh}};let Mh=class Mh extends Ah{constructor(e,t){super(e),this._a=t}_toFieldTransform(e){let t=kh(this,e,!0),a=this._a.map(e=>Uh(e,t)),u=new On(a);return new Un(e.path,u)}isEqual(e){return this===e}};function Bh(e,t,a,u){let l=e.da(1,t,a);Qh("Data must be an object, but it was:",l,u);let c=[],h=Ye.empty();Bt(u,(e,u)=>{let d=zh(t,e,a);u=(0,m.m9)(u);let p=l.ca(d);if(u instanceof Nh)c.push(d);else{let e=Uh(u,p);null!=e&&(c.push(d),h.set(d,e))}});let d=new Je(c);return new vh(h,d,l.fieldTransforms)}function Lh(e,t,a,u,l,c){let h=e.da(1,t,a),d=[jh(t,u,a)],p=[l];if(c.length%2!=0)throw new L(v.INVALID_ARGUMENT,`Function ${t}() needs to be called with an even number of arguments that alternate between field names and values.`);for(let e=0;e<c.length;e+=2)d.push(jh(t,c[e])),p.push(c[e+1]);let g=[],y=Ye.empty();for(let e=d.length-1;e>=0;--e)if(!Jh(g,d[e])){let t=d[e],a=p[e];a=(0,m.m9)(a);let u=h.ca(t);if(a instanceof Nh)g.push(t);else{let e=Uh(a,u);null!=e&&(g.push(t),y.set(t,e))}}let w=new Je(g);return new vh(y,w,h.fieldTransforms)}function qh(e,t,a,u=!1){return Uh(a,e.da(u?4:3,t))}function Uh(e,t){if(Gh(e=(0,m.m9)(e)))return Qh("Unsupported field value:",t,e),Kh(e,t);if(e instanceof Ah)return function(e,t){if(!Vh(t.sa))throw t.ha(`${e._methodName}() can only be used with update() and set()`);if(!t.path)throw t.ha(`${e._methodName}() is not currently supported inside arrays`);let a=e._toFieldTransform(t);a&&t.fieldTransforms.push(a)}(e,t),null;if(void 0===e&&t.ignoreUndefinedProperties)return null;if(t.path&&t.fieldMask.push(t.path),e instanceof Array){if(t.settings.oa&&4!==t.sa)throw t.ha("Nested arrays are not supported");return function(e,t){let a=[],u=0;for(let l of e){let e=Uh(l,t.aa(u));null==e&&(e={nullValue:"NULL_VALUE"}),a.push(e),u++}return{arrayValue:{values:a}}}(e,t)}return function(e,t){if(null===(e=(0,m.m9)(e)))return{nullValue:"NULL_VALUE"};if("number"==typeof e)return Sn(t.yt,e);if("boolean"==typeof e)return{booleanValue:e};if("string"==typeof e)return{stringValue:e};if(e instanceof Date){let a=nt.fromDate(e);return{timestampValue:$s(t.yt,a)}}if(e instanceof nt){let a=new nt(e.seconds,1e3*Math.floor(e.nanoseconds/1e3));return{timestampValue:$s(t.yt,a)}}if(e instanceof Rh)return{geoPointValue:{latitude:e.latitude,longitude:e.longitude}};if(e instanceof Ih)return{bytesValue:Bs(t.yt,e._byteString)};if(e instanceof ya){let a=t.databaseId,u=e.firestore._databaseId;if(!u.isEqual(a))throw t.ha(`Document reference is for database ${u.projectId}/${u.database} but should be for database ${a.projectId}/${a.database}`);return{referenceValue:Us(e.firestore._databaseId||t.databaseId,e._key.path)}}throw t.ha(`Unsupported field value: ${la(e)}`)}(e,t)}function Kh(e,t){let a={};return Lt(e)?t.path&&t.path.length>0&&t.fieldMask.push(t.path):Bt(e,(e,u)=>{let l=Uh(u,t.ra(e));null!=l&&(a[e]=l)}),{mapValue:{fields:a}}}function Gh(e){return!("object"!=typeof e||null===e||e instanceof Array||e instanceof Date||e instanceof nt||e instanceof Rh||e instanceof Ih||e instanceof ya||e instanceof Ah)}function Qh(e,t,a){if(!Gh(a)||!("object"==typeof a&&null!==a&&(Object.getPrototypeOf(a)===Object.prototype||null===Object.getPrototypeOf(a)))){let u=la(a);throw"an object"===u?t.ha(e+" a custom object"):t.ha(e+" "+u)}}function jh(e,t,a){if((t=(0,m.m9)(t))instanceof Th)return t._internalPath;if("string"==typeof t)return zh(e,t);throw Hh("Field path arguments must be of type string or ",e,!1,void 0,a)}let et=RegExp("[~\\*/\\[\\]]");function zh(e,t,a){if(t.search(et)>=0)throw Hh(`Invalid field path (${t}). Paths must not contain '~', '*', '/', '[', or ']'`,e,!1,void 0,a);try{return new Th(...t.split("."))._internalPath}catch(u){throw Hh(`Invalid field path (${t}). Paths must not be empty, begin with '.', end with '.', or contain '..'`,e,!1,void 0,a)}}function Hh(e,t,a,u,l){let c=u&&!u.isEmpty(),h=void 0!==l,d=`Function ${t}
1340() called with invalid data`;a&&(d+=" (via `toFirestore()`)"),d+=". ";let m="";return(c||h)&&(m+=" (found",c&&(m+=` in field ${u}`),h&&(m+=` in document ${l}`),m+=")"),new L(v.INVALID_ARGUMENT,d+e+m)}function Jh(e,t){return e.some(e=>e.isEqual(t))}/** 1341 * @license 1342 * Copyright 2020 Google LLC 1343 * 1344 * Licensed under the Apache License, Version 2.0 (the "License"); 1345 * you may not use this file except in compliance with the License. 1346 * You may obtain a copy of the License at 1347 * 1348 * http://www.apache.org/licenses/LICENSE-2.0 1349 * 1350 * Unless required by applicable law or agreed to in writing, software 1351 * distributed under the License is distributed on an "AS IS" BASIS, 1352 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1353 * See the License for the specific language governing permissions and 1354 * limitations under the License. 1355 */let Yh=class Yh{constructor(e,t,a,u,l){this._firestore=e,this._userDataWriter=t,this._key=a,this._document=u,this._converter=l}get id(){return this._key.path.lastSegment()}get ref(){return new ya(this._firestore,this._converter,this._key)}exists(){return null!==this._document}data(){if(this._document){if(this._converter){let e=new Xh(this._firestore,this._userDataWriter,this._key,this._document,null);return this._converter.fromFirestore(e)}return this._userDataWriter.convertValue(this._document.data.value)}}get(e){if(this._document){let t=this._document.data.field(Zh("DocumentSnapshot.get",e));if(null!==t)return this._userDataWriter.convertValue(t)}}};let Xh=class Xh extends Yh{data(){return super.data()}};function Zh(e,t){return"string"==typeof t?zh(e,t):t instanceof Th?t._internalPath:t._delegate._internalPath}/** 1356 * @license 1357 * Copyright 2020 Google LLC 1358 * 1359 * Licensed under the Apache License, Version 2.0 (the "License"); 1360 * you may not use this file except in compliance with the License. 1361 * You may obtain a copy of the License at 1362 * 1363 * http://www.apache.org/licenses/LICENSE-2.0 1364 * 1365 * Unless required by applicable law or agreed to in writing, software 1366 * distributed under the License is distributed on an "AS IS" BASIS, 1367 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1368 * See the License for the specific language governing permissions and 1369 * limitations under the License. 1370 */function tl(e){if("L"===e.limitType&&0===e.explicitOrderBy.length)throw new L(v.UNIMPLEMENTED,"limitToLast() queries require specifying at least one orderBy() clause")}let el=class el{};let nl=class nl extends el{};function sl(e,t,...a){let u=[];for(let l of(t instanceof el&&u.push(t),function(e){let t=e.filter(e=>e instanceof ol).length,a=e.filter(e=>e instanceof il).length;if(t>1||t>0&&a>0)throw new L(v.INVALID_ARGUMENT,"InvalidQuery. When using composite filters, you cannot use more than one filter at the top level. Consider nesting the multiple filters within an `and(...)` statement. For example: change `query(query, where(...), or(...))` to `query(query, and(where(...), or(...)))`.")}(u=u.concat(a)),u))e=l._apply(e);return e}let il=class il extends nl{constructor(e,t,a){super(),this._field=e,this._op=t,this._value=a,this.type="where"}static _create(e,t,a){return new il(e,t,a)}_apply(e){let t=this._parse(e);return Al(e._query,t),new pa(e.firestore,e.converter,yn(e._query,t))}_parse(e){let t=Ch(e.firestore),a=function(e,t,a,u,l,c,h){let d;if(l.isKeyField()){if("array-contains"===c||"array-contains-any"===c)throw new L(v.INVALID_ARGUMENT,`Invalid Query. You can't perform '${c}' queries on documentId().`);if("in"===c||"not-in"===c){El(h,c);let t=[];for(let a of h)t.push(Tl(u,e,a));d={arrayValue:{values:t}}}else d=Tl(u,e,h)}else"in"!==c&&"not-in"!==c&&"array-contains-any"!==c||El(h,c),d=qh(a,t,h,"in"===c||"not-in"===c);return Re.create(l,c,d)}(e._query,"where",t,e.firestore._databaseId,this._field,this._op,this._value);return a}};function rl(e,t,a){let u=Zh("where",e);return il._create(u,t,a)}let ol=class ol extends el{constructor(e,t){super(),this.type=e,this._queryConstraints=t}static _create(e,t){return new ol(e,t)}_parse(e){let t=this._queryConstraints.map(t=>t._parse(e)).filter(e=>e.getFilters().length>0);return 1===t.length?t[0]:be.create(t,this._getOperator())}_apply(e){let t=this._parse(e);return 0===t.getFilters().length?e:(function(e,t){let a=e,u=t.getFlattenedFilters();for(let e of u)Al(a,e),a=yn(a,e)}(e._query,t),new pa(e.firestore,e.converter,yn(e._query,t)))}_getQueryConstraints(){return this._queryConstraints}_getOperator(){return"and"===this.type?"and":"or"}}
1370;let al=class al extends nl{constructor(e,t){super(),this._field=e,this._direction=t,this.type="orderBy"}static _create(e,t){return new al(e,t)}_apply(e){let t=function(e,t,a){if(null!==e.startAt)throw new L(v.INVALID_ARGUMENT,"Invalid query. You must not call startAt() or startAfter() before calling orderBy().");if(null!==e.endAt)throw new L(v.INVALID_ARGUMENT,"Invalid query. You must not call endAt() or endBefore() before calling orderBy().");let u=new Ue(t,a);return function(e,t){if(null===dn(e)){let a=_n(e);null!==a&&Rl(e,a,t.field)}}(e,u),u}(e._query,this._field,this._direction);return new pa(e.firestore,e.converter,function(e,t){let a=e.explicitOrderBy.concat([t]);return new an(e.path,e.collectionGroup,a,e.filters.slice(),e.limit,e.limitType,e.startAt,e.endAt)}(e._query,t))}};function hl(e,t="asc"){let a=Zh("orderBy",e);return al._create(a,t)}let ll=class ll extends nl{constructor(e,t,a){super(),this.type=e,this._limit=t,this._limitType=a}static _create(e,t,a){return new ll(e,t,a)}_apply(e){return new pa(e.firestore,e.converter,pn(e._query,this._limit,this._limitType))}};function fl(e){return da("limit",e),ll._create("limit",e,"F")}function Tl(e,t,a){if("string"==typeof(a=(0,m.m9)(a))){if(""===a)throw new L(v.INVALID_ARGUMENT,"Invalid query. When querying with documentId(), you must provide a valid document ID, but it was an empty string.");if(!wn(t)&&-1!==a.indexOf("/"))throw new L(v.INVALID_ARGUMENT,`Invalid query. When querying a collection by documentId(), you must provide a plain document ID, but '${a}' contains a '/' character.`);let u=t.path.child(rt.fromString(a));if(!ct.isDocumentKey(u))throw new L(v.INVALID_ARGUMENT,`Invalid query. When querying a collection group by documentId(), the value provided must result in a valid document path, but '${u}' is not because it has an odd number of segments (${u.length}).`);return ce(e,new ct(u))}if(a instanceof ya)return ce(e,a._key);throw new L(v.INVALID_ARGUMENT,`Invalid query. When querying with documentId(), you must provide a valid string or a DocumentReference, but it was: ${la(a)}.`)}function El(e,t){if(!Array.isArray(e)||0===e.length)throw new L(v.INVALID_ARGUMENT,`Invalid Query. A non-empty array is required for '${t.toString()}' filters.`);if(e.length>10)throw new L(v.INVALID_ARGUMENT,`Invalid Query. '${t.toString()}' filters support a maximum of 10 elements in the value array.`)}function Al(e,t){if(t.isInequality()){let a=_n(e),u=t.field;if(null!==a&&!a.isEqual(u))throw new L(v.INVALID_ARGUMENT,`Invalid query. All where filters with an inequality (<, <=, !=, not-in, >, or >=) must be on the same field. But you have inequality filters on '${a.toString()}' and '${u.toString()}'`);let l=dn(e);null!==l&&Rl(e,u,l)}let a=function(e,t){for(let a of e)for(let e of a.getFlattenedFilters())if(t.indexOf(e.op)>=0)return e.op;return null}(e.filters,function(e){switch(e){case"!=":return["!=","not-in"];case"array-contains":return["array-contains","array-contains-any","not-in"];case"in":return["array-contains-any","in","not-in"];case"array-contains-any":return["array-contains","array-contains-any","in","not-in"];case"not-in":return["array-contains","array-contains-any","in","not-in","!="];default:return[]}}(t.op));if(null!==a)throw a===t.op?new L(v.INVALID_ARGUMENT,`Invalid query. You cannot use more than one '${t.op.toString()}' filter.`):new L(v.INVALID_ARGUMENT,`Invalid query. You cannot use '${t.op.toString()}' filters with '${a.toString()}' filters.`)}function Rl(e,t,a){if(!a.isEqual(t))throw new L(v.INVALID_ARGUMENT,`Invalid query. You have a where filter with an inequality (<, <=, !=, not-in, >, or >=) on field '${t.toString()}' and so you must also use '${t.toString()}' as your first argument to orderBy(), but your first orderBy() is on field '${a.toString()}' instead.`)}let Pl=class Pl{convertValue(e,t="none"){switch(ee(e)){case 0:return null;case 1:return e.booleanValue;case 2:return zt(e.integerValue||e.doubleValue);case 3:return this.convertTimestamp(e.timestampValue);case 4:return this.convertServerTimestamp(e,t);case 5:return e.stringValue;case 6:return this.convertBytes(Ht(e.bytesValue));case 7:return this.convertReference(e.referenceValue);case 8:return this.convertGeoPoint(e.geoPointValue);case 9:return this.convertArray(e.arrayValue,t);case 10:return this.convertObject(e.mapValue,t);default:throw O()}}convertObject(e,t){let a={};return Bt(e.fields,(e,u)=>{a[e]=this.convertValue(u,t)}),a}convertGeoPoint(e){return new Rh(zt(e.latitude),zt(e.longitude))}convertArray(e,t){return(e.values||[]).map(e=>this.convertValue(e,t))}convertServerTimestamp(e,t){switch(t){case"previous":let a=Yt(e);return null==a?null:this.convertValue(a,t);case"estimate":return this.convertTimestamp(Xt(e));default:return null}}convertTimestamp(e){let t=Wt(e);return new nt(t.seconds,t.nanos)}convertDocumentKey(e,t){let a=rt.fromString(e);wi(a)||O();let u=new Ft(a.get(1),a.get(3)),l=new ct(a.popFirst(5));return u.isEqual(t)||x(`Document ${l} contains a document reference within a different database (${u.projectId}/${u.database}) which is not supported. It will be treated as a reference in the current database (${t.projectId}/${t.database}) instead.`),l}};/** 1371 * @license 1372 * Copyright 2020 Google LLC 1373 * 1374 * Licensed under the Apache License, Version 2.0 (the "License");
1375 * you may not use this file except in compliance with the License. 1376 * You may obtain a copy of the License at 1377 * 1378 * http://www.apache.org/licenses/LICENSE-2.0 1379 * 1380 * Unless required by applicable law or agreed to in writing, software 1381 * distributed under the License is distributed on an "AS IS" BASIS, 1382 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1383 * See the License for the specific language governing permissions and 1384 * limitations under the License. 1385 */function vl(e,t,a){return e?a&&(a.merge||a.mergeFields)?e.toFirestore(t,a):e.toFirestore(t):t}/** 1386 * @license 1387 * Copyright 2020 Google LLC 1388 * 1389 * Licensed under the Apache License, Version 2.0 (the "License"); 1390 * you may not use this file except in compliance with the License. 1391 * You may obtain a copy of the License at 1392 * 1393 * http://www.apache.org/licenses/LICENSE-2.0 1394 * 1395 * Unless required by applicable law or agreed to in writing, software 1396 * distributed under the License is distributed on an "AS IS" BASIS, 1397 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1398 * See the License for the specific language governing permissions and 1399 * limitations under the License. 1400 */let Sl=class Sl{constructor(e,t){this.hasPendingWrites=e,this.fromCache=t}isEqual(e){return this.hasPendingWrites===e.hasPendingWrites&&this.fromCache===e.fromCache}};let Dl=class Dl extends Yh{constructor(e,t,a,u,l,c){super(e,t,a,u,c),this._firestore=e,this._firestoreImpl=e,this.metadata=l}exists(){return super.exists()}data(e={}){if(this._document){if(this._converter){let t=new Cl(this._firestore,this._userDataWriter,this._key,this._document,this.metadata,null);return this._converter.fromFirestore(t,e)}return this._userDataWriter.convertValue(this._document.data.value,e.serverTimestamps)}}get(e,t={}){if(this._document){let a=this._document.data.field(Zh("DocumentSnapshot.get",e));if(null!==a)return this._userDataWriter.convertValue(a,t.serverTimestamps)}}};let Cl=class Cl extends Dl{data(e={}){return super.data(e)}};let xl=class xl{constructor(e,t,a,u){this._firestore=e,this._userDataWriter=t,this._snapshot=u,this.metadata=new Sl(u.hasPendingWrites,u.fromCache),this.query=a}get docs(){let e=[];return this.forEach(t=>e.push(t)),e}get size(){return this._snapshot.docs.size}get empty(){return 0===this.size}forEach(e,t){this._snapshot.docs.forEach(a=>{e.call(t,new Cl(this._firestore,this._userDataWriter,a.key,a,new Sl(this._snapshot.mutatedKeys.has(a.key),this._snapshot.fromCache),this.query.converter))})}docChanges(e={}){let t=!!e.includeMetadataChanges;if(t&&this._snapshot.excludesMetadataChanges)throw new L(v.INVALID_ARGUMENT,"To include metadata changes with your document changes, you must also pass { includeMetadataChanges:true } to onSnapshot().");return this._cachedChanges&&this._cachedChangesIncludeMetadataChanges===t||(this._cachedChanges=function(e,t){if(e._snapshot.oldDocs.isEmpty()){let t=0;return e._snapshot.docChanges.map(a=>{let u=new Cl(e._firestore,e._userDataWriter,a.doc.key,a.doc,new Sl(e._snapshot.mutatedKeys.has(a.doc.key),e._snapshot.fromCache),e.query.converter);return a.doc,{type:"added",doc:u,oldIndex:-1,newIndex:t++}})}{let a=e._snapshot.oldDocs;return e._snapshot.docChanges.filter(e=>t||3!==e.type).map(t=>{let u=new Cl(e._firestore,e._userDataWriter,t.doc.key,t.doc,new Sl(e._snapshot.mutatedKeys.has(t.doc.key),e._snapshot.fromCache),e.query.converter),l=-1,c=-1;return 0!==t.type&&(l=a.indexOf(t.doc.key),a=a.delete(t.doc.key)),1!==t.type&&(c=(a=a.add(t.doc)).indexOf(t.doc.key)),{type:Nl(t.type),doc:u,oldIndex:l,newIndex:c}})}}(this,t),this._cachedChangesIncludeMetadataChanges=t),this._cachedChanges}};function Nl(e){switch(e){case 0:return"added";case 2:case 3:return"modified";case 1:return"removed";default:return O()}}/** 1401 * @license 1402 * Copyright 2020 Google LLC 1403 * 1404 * Licensed under the Apache License, Version 2.0 (the "License"); 1405 * you may not use this file except in compliance with the License. 1406 * You may obtain a copy of the License at 1407 * 1408 * http://www.apache.org/licenses/LICENSE-2.0 1409 * 1410 * Unless required by applicable law or agreed to in writing, softw
1410are 1411 * distributed under the License is distributed on an "AS IS" BASIS, 1412 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1413 * See the License for the specific language governing permissions and 1414 * limitations under the License. 1415 */function Ol(e){e=fa(e,ya);let t=fa(e.firestore,ih);return za(uh(t),e._key).then(a=>Hl(t,e,a))}let Ml=class Ml extends Pl{constructor(e){super(),this.firestore=e}convertBytes(e){return new Ih(e)}convertReference(e){let t=this.convertDocumentKey(e,this.firestore._databaseId);return new ya(this.firestore,null,t)}};function Bl(e){e=fa(e,pa);let t=fa(e.firestore,ih),a=uh(t),u=new Ml(t);return tl(e._query),Ja(a,e._query).then(a=>new xl(t,u,e,a))}function Ul(e,t,a){e=fa(e,ya);let u=fa(e.firestore,ih),l=vl(e.converter,t,a);return zl(u,[xh(Ch(u),"setDoc",e._key,l,null!==e.converter,a).toMutation(e._key,Qn.none())])}function Gl(e){return zl(fa(e.firestore,ih),[new is(e._key,Qn.none())])}function Ql(e,t){let a=fa(e.firestore,ih),u=Aa(e),l=vl(e.converter,t);return zl(a,[xh(Ch(e.firestore),"addDoc",u._key,l,null!==e.converter,{}).toMutation(u._key,Qn.exists(!1))]).then(()=>u)}function jl(e,...t){var a,u,l;let c,h,d;e=(0,m.m9)(e);let p={includeMetadataChanges:!1},g=0;"object"!=typeof t[0]||eh(t[g])||(p=t[g],g++);let y={includeMetadataChanges:p.includeMetadataChanges};if(eh(t[g])){let e=t[g];t[g]=null===(a=e.next)||void 0===a?void 0:a.bind(e),t[g+1]=null===(u=e.error)||void 0===u?void 0:u.bind(e),t[g+2]=null===(l=e.complete)||void 0===l?void 0:l.bind(e)}if(e instanceof ya)h=fa(e.firestore,ih),d=ln(e._key.path),c={next:a=>{t[g]&&t[g](Hl(h,e,a))},error:t[g+1],complete:t[g+2]};else{let a=fa(e,pa);h=fa(a.firestore,ih),d=a._query;let u=new Ml(h);c={next:e=>{t[g]&&t[g](new xl(h,u,a,e))},error:t[g+1],complete:t[g+2]},tl(e._query)}return function(e,t,a,u){let l=new va(u),c=new _c(t,l,a);return e.asyncQueue.enqueueAndForget(async()=>ac(await Ga(e),c)),()=>{l.bc(),e.asyncQueue.enqueueAndForget(async()=>hc(await Ga(e),c))}}(uh(h),d,y,c)}function zl(e,t){return function(e,t){let a=new q;return e.asyncQueue.enqueueAndForget(async()=>Vc(await Ua(e),t,a)),a.promise}(uh(e),t)}function Hl(e,t,a){let u=a.docs.get(t._key),l=new Ml(e);return new Dl(e,l,t._key,u,new Sl(a.hasPendingWrites,a.fromCache),t.converter)}/** 1416 * @license 1417 * Copyright 2020 Google LLC 1418 * 1419 * Licensed under the Apache License, Version 2.0 (the "License"); 1420 * you may not use this file except in compliance with the License. 1421 * You may obtain a copy of the License at 1422 * 1423 * http://www.apache.org/licenses/LICENSE-2.0 1424 * 1425 * Unless required by applicable law or agreed to in writing, software 1426 * distributed under the License is distributed on an "AS IS" BASIS, 1427 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1428 * See the License for the specific language governing permissions and 1429 * limitations under the License. 1430 */let Zl=class Zl{constructor(e,t){this._firestore=e,this._commitHandler=t,this._mutations=[],this._committed=!1,this._dataReader=Ch(e)}set(e,t,a){this._verifyNotCommitted();let u=tf(e,this._firestore),l=vl(u.converter,t,a),c=xh(this._dataReader,"WriteBatch.set",u._key,l,null!==u.converter,a);return this._mutations.push(c.toMutation(u._key,Qn.none())),this}update(e,t,a,...u){let l;this._verifyNotCommitted();let c=tf(e,this._firestore);return l="string"==typeof(t=(0,m.m9)(t))||t instanceof Th?Lh(this._dataReader,"WriteBatch.update",c._key,t,a,u):Bh(this._dataReader,"WriteBatch.update",c._key,t),this._mutations.push(l.toMutation(c._key,Qn.exists(!0))),this}delete(e){this._verifyNotCommitted();let t=tf(e,this._firestore);return this._mutations=this._mutations.concat(new is(t._key,Qn.none())),this}commit(){return this._verifyNotCommitted(),this._committed=!0,this._mutations.length>0?this._commitHandler(this._mutations):Promise.resolve()}_verifyNotCommitted(){if(this._committed)throw new L(v.FAILED_PRECONDITION,"A write batch can no longer be used after commit() has been called.")}};function tf(e,t){if((e=(0,m.m9)(e)).firestore!==t)throw new L(v.INVALID_ARGUMENT,"Provided document reference is from a different Firestore instance.");return e}function rf(){return new Oh("serverTimestamp")}function of(...e){return new Mh("arrayUnion",e)}/** 1431 * @license 1432 * Copyright 2020 Google LLC 1433 * 1434 * Licensed under the Apache License, Version 2.0 (the "License");
1435 * you may not use this file except in compliance with the License. 1436 * You may obtain a copy of the License at 1437 * 1438 * http://www.apache.org/licenses/LICENSE-2.0 1439 * 1440 * Unless required by applicable law or agreed to in writing, software 1441 * distributed under the License is distributed on an "AS IS" BASIS, 1442 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1443 * See the License for the specific language governing permissions and 1444 * limitations under the License. 1445 */function af(e){return uh(e=fa(e,ih)),new Zl(e,t=>zl(e,t))}!function(e,t=!0){y=c.Jn,(0,c.Xd)(new h.wA("firestore",(e,{instanceIdentifier:a,options:u})=>{let l=e.getProvider("app").getImmediate(),c=new ih(new Q(e.getProvider("auth-internal")),new H(e.getProvider("app-check-internal")),function(e,t){if(!Object.prototype.hasOwnProperty.apply(e.options,["projectId"]))throw new L(v.INVALID_ARGUMENT,'"projectId" not provided in firebase.initializeApp.');return new Ft(e.options.projectId,t)}(l,a),l);return u=Object.assign({useFetchStreams:t},u),c._setSettings(u),c},"PUBLIC").setMultipleInstances(!0)),(0,c.KN)(g,"3.8.3",void 0),(0,c.KN)(g,"3.8.3","esm2017")}()}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.