1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[4358],{35002:function(e,t,n){n.d(t,{ET:function(){return sD},JU:function(){return r4},QT:function(){return sk},ad:function(){return sr},hJ:function(){return r2}});var r,s,i=n(48885),a=n(42680),o=n(19053),l=n(71028),u=n(77861);n(25566);let h="@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 */class c{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}}c.UNAUTHENTICATED=new c(null),c.GOOGLE_CREDENTIALS=new c("google-credentials-uid"),c.FIRST_PARTY=new c("first-party-uid"),c.MOCK_USER=new c("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 d="9.16.0",f=new o.Yd("@firebase/firestore");function m(){return f.logLevel}function g(e,...t){if(f.logLevel<=o.in.DEBUG){let n=t.map(v);f.debug(`Firestore (${d}): ${e}`,...n)}}function p(e,...t){if(f.logLevel<=o.in.ERROR){let n=t.map(v);f.error(`Firestore (${d}): ${e}`,...n)}}function y(e,...t){if(f.logLevel<=o.in.WARN){let n=t.map(v);f.warn(`Firestore (${d}): ${e}`,...n)}}function v(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 w(e="Unexpected state"){let t=`FIRESTORE (${d}) INTERNAL ASSERTION FAILED: `+e;throw p(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 E={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",UNIMPLEMENTED:"unimplemented",INTERNAL:"internal",UNAVAILABLE:"unavailable",DATA_LOSS:"data-loss"};class T extends l.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 */class I{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 */class C{constructor(e,t){this.user=t,this.type="OAuth",this.headers=new Map,this.headers.set("Authorization",`Bearer ${e}`)}}class S{getToken(){return Promise.resolve(null)}invalidateToken(){}start(e,t){e.enqueueRetryable(()=>t(c.UNAUTHENTICATED))}shutdown(){}}class A{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}}class N{constructor(e){this.t=e,this.currentUser=c.UNAUTHENTICATED,this.i=0,this.forceRefresh=!1,this.auth=null}start(e,t){let n=this.i,r=e=>this.i!==n?(n=this.i,t(e)):Promise.resolve(),s=new I;this.o=()=>{this.i++,this.currentUser=this.u(),s.resolve(),s=new I,e.enqueueRetryable(()=>r(this.currentUser))};let i=()=>{let t=s;e.enqueueRetryable(async()=>{await t.promise,await r(this.currentUser)})},a=e=>{g("FirebaseAuthCredentialsProvider","Auth detected"),this.auth=e,this.auth.addAuthTokenListener(this.o),i()};this.t.onInit(e=>a(e)),setTimeout(()=>{if(!this.auth){let e=this.t.getImmediate({optional:!0});e?a(e):(g("FirebaseAuthCredentialsProvider","Auth not yet detected"),s.resolve(),s=new I)}},0),i()}getToken(){let e=this.i,t=this.forceRefresh;return this.forceRefresh=!1,this.auth?this.auth.getToken(t).then(t=>this.i!==e?(g("FirebaseAuthCredentialsProvider","getToken aborted due to token change."),this.getToken()):t?("string"==typeof t.accessToken||w(),new C(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||w(),new c(e)}}class k{constructor(e,t,n,r){this.h=e,this.l=t,this.m=n,this.g=r,this.type="FirstParty",this.user=c.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||w(),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}}class b{constructor(e,t,n,r){this.h=e,this.l=t,this.m=n,this.g=r}getToken(){return Promise.resolve(new k(this.h,this.l,this.m,this.g))}start(e,t){e.enqueueRetryable(()=>t(c.FIRST_PARTY))}shutdown(){}invalidateToken(){}}class D{constructor(e){this.value=e,this.type="AppCheck",this.headers=new Map,e&&e.length>0&&this.headers.set("x-firebase-appcheck",this.value)}}class _{constructor(e){this.T=e,this.forceRefresh=!1,this.appCheck=null,this.A=null}start(e,t){let n=e=>{null!=e.error&&g("FirebaseAppCheckTokenProvider",`Error getting App Check token; using placeholder token instead. Error: ${e.error.message}`);let n=e.token!==this.A;return this.A=e.token,g("FirebaseAppCheckTokenProvider",`Received ${n?"new":"existing"} token.`),n?t(e.token):Promise.resolve()};this.o=t=>{e.enqueueRetryable(()=>n(t))};let r=e=>{g("FirebaseAppCheckTokenProvider","AppCheck detected"),this.appCheck=e,this.appCheck.addTokenListener(this.o)};this.T.onInit(e=>r(e)),setTimeout(()=>{if(!this.appCheck){let e=this.T.getImmediate({optional:!0});e?r(e):g("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||w(),this.A=e.token,new D(e.token)):null):Promise.resolve(null)}invalidateToken(){this.forceRefresh=!0}shutdown(){this.appCheck&&this.appCheck.removeTokenListener(this.o)}}/** 92 * @license 93 * Copyright 2017 Google LLC 94 * 95 * Licensed under the Apache License, Version 2.0 (the "License");
96 * you may not use this file except in compliance with the License. 97 * You may obtain a copy of the License at 98 * 99 * http://www.apache.org/licenses/LICENSE-2.0 100 * 101 * Unless required by applicable law or agreed to in writing, software 102 * distributed under the License is distributed on an "AS IS" BASIS, 103 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 104 * See the License for the specific language governing permissions and 105 * limitations under the License. 106 */class R{static R(){let e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",t=Math.floor(256/e.length)*e.length,n="";for(;n.length<20;){let r=/** 107 * @license 108 * Copyright 2020 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 */function(e){let t="undefined"!=typeof self&&(self.crypto||self.msCrypto),n=new Uint8Array(40);if(t&&"function"==typeof t.getRandomValues)t.getRandomValues(n);else for(let e=0;e<40;e++)n[e]=Math.floor(256*Math.random());return n}(0);for(let s=0;s<r.length;++s)n.length<20&&r[s]<t&&(n+=e.charAt(r[s]%e.length))}return n}}function L(e,t){return e<t?-1:e>t?1:0}function x(e,t,n){return e.length===t.length&&e.every((e,r)=>n(e,t[r]))}/** 122 * @license 123 * Copyright 2017 Google LLC 124 * 125 * Licensed under the Apache License, Version 2.0 (the "License"); 126 * you may not use this file except in compliance with the License. 127 * You may obtain a copy of the License at 128 * 129 * http://www.apache.org/licenses/LICENSE-2.0 130 * 131 * Unless required by applicable law or agreed to in writing, software 132 * distributed under the License is distributed on an "AS IS" BASIS, 133 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 134 * See the License for the specific language governing permissions and 135 * limitations under the License. 136 */class V{constructor(e,t){if(this.seconds=e,this.nanoseconds=t,t<0||t>=1e9)throw new T(E.INVALID_ARGUMENT,"Timestamp nanoseconds out of range: "+t);if(e<-62135596800||e>=253402300800)throw new T(E.INVALID_ARGUMENT,"Timestamp seconds out of range: "+e)}static now(){return V.fromMillis(Date.now())}static fromDate(e){return V.fromMillis(e.getTime())}static fromMillis(e){let t=Math.floor(e/1e3);return new V(t,Math.floor(1e6*(e-1e3*t)))}toDate(){return new Date(this.toMillis())}toMillis(){return 1e3*this.seconds+this.nanoseconds/1e6}_compareTo(e){return this.seconds===e.seconds?L(this.nanoseconds,e.nanoseconds):L(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(){return String(this.seconds- -62135596800).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 */class F{constructor(e){this.timestamp=e}static fromTimestamp(e){return new F(e)}static min(){return new F(new V(0,0))}static max(){return new F(new V(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 */class O{constructor(e,t,n){void 0===t?t=0:t>e.length&&w(),void 0===n?n=e.length-t:n>e.length-t&&w(),this.segments=e,this.offset=t,this.len=n}get length(){return this.len}isEqual(e){return 0===O.comparator(this,e)}child(e){let t=this.segments.slice(this.offset,this.limit());return e instanceof O?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,n=this.limit();t<n;t++)e(this.segments[t])}toArray(){return this.segments.slice(this.offset,this.limit())}static comparator(e,t){let n=Math.min(e.length,t.length);for(let r=0;r<n;r++){let n=e.get(r),s=t.get(r);if(n<s)return -1;if(n>s)return 1}return e.length<t.length?-1:e.length>t.length?1:0}}class M extends O{construct(e,t,n){return new M(e,t,n)}canonicalString(){return this.toArray().join("/")}toString(){return this.canonicalString()}static fromString(...e){let t=[];for(let n of e){if(n.indexOf("//")>=0)throw new T(E.INVALID_ARGUMENT,`Invalid segment (${n}). Paths must not contain // in them.`);t.push(...n.split("/").filter(e=>e.length>0))}return new M(t)}static emptyPath(){return new M([])}}let U=/^[_a-zA-Z][_a-zA-Z0-9]*$/;class P extends O{construct(e,t,n){return new P(e,t,n)}static isValidIdentifier(e){return U.test(e)}canonicalString(){return this.toArray().map(e=>(e=e.replace(/\\/g,"\\\\").replace(/`/g,"\\`"),P.isValidIdentifier(e)||(e="`"+e+"`"),e)).join(".")}toString(){return this.canonicalString()}isKeyField(){return 1===this.length&&"__name__"===this.get(0)}static keyField(){return new P(["__name__"])}static fromServerFormat(e){let t=[],n="",r=0,s=()=>{if(0===n.length)throw new T(E.INVALID_ARGUMENT,`Invalid field path (${e}). Paths must not be empty, begin with '.', end with '.', or contain '..'`);t.push(n),n=""},i=!1;for(;r<e.length;){let t=e[r];if("\\"===t){if(r+1===e.length)throw new T(E.INVALID_ARGUMENT,"Path has trailing escape character: "+e);let t=e[r+1];if("\\"!==t&&"."!==t&&"`"!==t)throw new T(E.INVALID_ARGUMENT,"Path has invalid escape sequence: "+e);n+=t,r+=2}else"`"===t?i=!i:"."!==t||i?n+=t:s(),r++}if(s(),i)throw new T(E.INVALID_ARGUMENT,"Unterminated ` in path: "+e);return new P(t)}static emptyPath(){return new P([])}}/** 167 * @license 168 * Copyright 2017 Google LLC 169 * 170 * Licensed under the Apache License, Version 2.0 (the "License"); 171 * you may not use this file except in compliance with the License. 172 * You may obtain a copy of the License at 173 * 174 * http://www.apache.org/licenses/LICENSE-2.0 175 * 176 * Unless required by applicable law or agreed to in writing, software 177 * distributed under the License is distributed on an "AS IS" BASIS, 178 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 179 * See the License for the specific language governing permissions and 180 * limitations under the License. 181 */class q{constructor(e){this.path=e}static fromPath(e){return new q(M.fromString(e))}static fromName(e){return new q(M.fromString(e).popFirst(5))}static empty(){return new q(M.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===M.comparator(this.path,e.path)}toString(){return this.path.toString()}static comparator(e,t){return M.comparator(e.path,t.path)}static isDocumentKey(e){return e.length%2==0}static fromSegments(e){return new q(new M(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 */class B{constructor(e,t,n,r){this.indexId=e,this.collectionGroup=t,this.fields=n,this.indexState=r}}B.UNKNOWN_ID=-1;class K{constructor(e,t,n){this.readTime=e,this.documentKey=t,this.largestBatchId=n}static min(){return new K(F.min(),q.empty(),-1)}static max(){return new K(F.max(),q.empty(),-1)}}class Q{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 G(e){if(e.code!==E.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;g("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 */class z{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&&w(),this.callbackAttached=!0,this.isDone?this.error?this.wrapFailure(t,this.error):this.wrapSuccess(e,this.result):new z((n,r)=>{this.nextCallback=t=>{this.wrapSuccess(e,t).next(n,r)},this.catchCallback=e=>{this.wrapFailure(t,e).next(n,r)}})}toPromise(){return new Promise((e,t)=>{this.next(e,t)})}wrapUserFunction(e){try{let t=e();return t instanceof z?t:z.resolve(t)}catch(e){return z.reject(e)}}wrapSuccess(e,t){return e?this.wrapUserFunction(()=>e(t)):z.resolve(t)}wrapFailure(e,t){return e?this.wrapUserFunction(()=>e(t)):z.reject(t)}static resolve(e){return new z((t,n)=>{t(e)})}static reject(e){return new z((t,n)=>{n(e)})}static waitFor(e){return new z((t,n)=>{let r=0,s=0,i=!1;e.forEach(e=>{++r,e.next(()=>{++s,i&&s===r&&t()},e=>n(e))}),i=!0,s===r&&t()})}static or(e){let t=z.resolve(!1);for(let n of e)t=t.next(e=>e?z.resolve(e):n());return t}static forEach(e,t){let n=[];return e.forEach((e,r)=>{n.push(t.call(this,e,r))}),this.waitFor(n)}static mapArray(e,t){return new z((n,r)=>{let s=e.length,i=Array(s),a=0;for(let o=0;o<s;o++){let l=o;t(e[l]).next(e=>{i[l]=e,++a===s&&n(i)},e=>r(e))}})}static doWhile(e,t){return new z((n,r)=>{let s=()=>{!0===e()?t().next(()=>{s()},r):n()};s()})}}function $(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 */class j{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}}j.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 */class W{constructor(e,t,n,r,s,i,a,o){this.databaseId=e,this.appId=t,this.persistenceKey=n,this.host=r,this.ssl=s,this.forceLongPolling=i,this.autoDetectLongPolling=a,this.useFetchStreams=o}}class H{constructor(e,t){this.projectId=e,this.database=t||"(default)"}static empty(){return new H("","")}get isDefaultDatabase(){return"(default)"===this.database}isEqual(e){return e instanceof H&&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 Y(e){let t=0;for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&t++;return t}function X(e,t){for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&t(n,e[n])}function J(e){for(let t in e)if(Object.prototype.hasOwnProperty.call(e,t))return!1;return!0}function Z(e){return 0===e&&1/e==-1/0}/** 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 */class ee{constructor(e){this.binaryString=e}static fromBase64String(e){return new ee(atob(e))}static fromUint8Array(e){return new ee(function(e){let t="";for(let n=0;n<e.length;++n)t+=String.fromCharCode(e[n]);return t}(e))}[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 n=0;n<e.length;n++)t[n]=e.charCodeAt(n);return t}(this.binaryString)}approximateByteSize(){return 2*this.binaryString.length}compareTo(e){return L(this.binaryString,e.binaryString)}isEqual(e){return this.binaryString===e.binaryString}}ee.EMPTY_BYTE_STRING=new ee("");let et=new RegExp(/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.(\d+))?Z$/);function en(e){if(e||w(),"string"==typeof e){let t=0,n=et.exec(e);if(n||w(),n[1]){let e=n[1];t=Number(e=(e+"000000000").substr(0,9))}return{seconds:Math.floor(new Date(e).getTime()/1e3),nanos:t}}return{seconds:er(e.seconds),nanos:er(e.nanos)}}function er(e){return"number"==typeof e?e:"string"==typeof e?Number(e):0}function es(e){return"string"==typeof e?ee.fromBase64String(e):ee.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 ei(e){var t,n;return"server_timestamp"===(null===(n=((null===(t=null==e?void 0:e.mapValue)||void 0===t?void 0:t.fields)||{}).__type__)||void 0===n?void 0:n.stringValue)}function ea(e){let t=en(e.mapValue.fields.__local_write_time__.timestampValue);return new V(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 eo={mapValue:{fields:{__type__:{stringValue:"__max__"}}}};function el(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?ei(e)?4:eE(e)?9007199254740991:10:w()}function eu(e,t){if(e===t)return!0;let n=el(e);
316if(n!==el(t))return!1;switch(n){case 0:case 9007199254740991:return!0;case 1:return e.booleanValue===t.booleanValue;case 4:return ea(e).isEqual(ea(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 n=en(e.timestampValue),r=en(t.timestampValue);return n.seconds===r.seconds&&n.nanos===r.nanos}(e,t);case 5:return e.stringValue===t.stringValue;case 6:return es(e.bytesValue).isEqual(es(t.bytesValue));case 7:return e.referenceValue===t.referenceValue;case 8:return er(e.geoPointValue.latitude)===er(t.geoPointValue.latitude)&&er(e.geoPointValue.longitude)===er(t.geoPointValue.longitude);case 2:return function(e,t){if("integerValue"in e&&"integerValue"in t)return er(e.integerValue)===er(t.integerValue);if("doubleValue"in e&&"doubleValue"in t){let n=er(e.doubleValue),r=er(t.doubleValue);return n===r?Z(n)===Z(r):isNaN(n)&&isNaN(r)}return!1}(e,t);case 9:return x(e.arrayValue.values||[],t.arrayValue.values||[],eu);case 10:return function(e,t){let n=e.mapValue.fields||{},r=t.mapValue.fields||{};if(Y(n)!==Y(r))return!1;for(let e in n)if(n.hasOwnProperty(e)&&(void 0===r[e]||!eu(n[e],r[e])))return!1;return!0}(e,t);default:return w()}}function eh(e,t){return void 0!==(e.values||[]).find(e=>eu(e,t))}function ec(e,t){if(e===t)return 0;let n=el(e),r=el(t);if(n!==r)return L(n,r);switch(n){case 0:case 9007199254740991:return 0;case 1:return L(e.booleanValue,t.booleanValue);case 2:return function(e,t){let n=er(e.integerValue||e.doubleValue),r=er(t.integerValue||t.doubleValue);return n<r?-1:n>r?1:n===r?0:isNaN(n)?isNaN(r)?0:-1:1}(e,t);case 3:return ed(e.timestampValue,t.timestampValue);case 4:return ed(ea(e),ea(t));case 5:return L(e.stringValue,t.stringValue);case 6:return function(e,t){let n=es(e),r=es(t);return n.compareTo(r)}(e.bytesValue,t.bytesValue);case 7:return function(e,t){let n=e.split("/"),r=t.split("/");for(let e=0;e<n.length&&e<r.length;e++){let t=L(n[e],r[e]);if(0!==t)return t}return L(n.length,r.length)}(e.referenceValue,t.referenceValue);case 8:return function(e,t){let n=L(er(e.latitude),er(t.latitude));return 0!==n?n:L(er(e.longitude),er(t.longitude))}(e.geoPointValue,t.geoPointValue);case 9:return function(e,t){let n=e.values||[],r=t.values||[];for(let e=0;e<n.length&&e<r.length;++e){let t=ec(n[e],r[e]);if(t)return t}return L(n.length,r.length)}(e.arrayValue,t.arrayValue);case 10:return function(e,t){if(e===eo.mapValue&&t===eo.mapValue)return 0;if(e===eo.mapValue)return 1;if(t===eo.mapValue)return -1;let n=e.fields||{},r=Object.keys(n),s=t.fields||{},i=Object.keys(s);r.sort(),i.sort();for(let e=0;e<r.length&&e<i.length;++e){let t=L(r[e],i[e]);if(0!==t)return t;let a=ec(n[r[e]],s[i[e]]);if(0!==a)return a}return L(r.length,i.length)}(e.mapValue,t.mapValue);default:throw w()}}function ed(e,t){if("string"==typeof e&&"string"==typeof t&&e.length===t.length)return L(e,t);let n=en(e),r=en(t),s=L(n.seconds,r.seconds);return 0!==s?s:L(n.nanos,r.nanos)}function ef(e){var t,n;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=en(e);return`time(${t.seconds},${t.nanos})`}(e.timestampValue):"stringValue"in e?e.stringValue:"bytesValue"in e?es(e.bytesValue).toBase64():"referenceValue"in e?(n=e.referenceValue,q.fromName(n).toString()):"geoPointValue"in e?`geo(${(t=e.geoPointValue).latitude},${t.longitude})`:"arrayValue"in e?function(e){let t="[",n=!0;for(let r of e.values||[])n?n=!1:t+=",",t+=ef(r);return t+"]"}(e.arrayValue):"mapValue"in e?function(e){let t=Object.keys(e.fields||{}).sort(),n="{",r=!0;for(let s of t)r?r=!1:n+=",",n+=`${s}:${ef(e.fields[s])}`;return n+"}"}(e.mapValue):w()}function em(e){return!!e&&"integerValue"in e}function eg(e){return!!e&&"arrayValue"in e}function ep(e){return!!e&&"nullValue"in e}function ey(e){return!!e&&"doubleValue"in e&&isNaN(Number(e.doubleValue))}function ev(e){return!!e&&"mapValue"in e}function ew(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 X(e.mapValue.fields,(e,n)=>t.mapValue.fields[e]=ew(n)),t}if(e.arrayValue){let t={arrayValue:{values:[]}};for(let n=0;n<(e.arrayValue.values||[]).length;++n)t.arrayValue.values[n]=ew(e.arrayValue.values[n]);return t}return Object.assign({},e)}function eE(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 */class eT{constructor(e,t){this.position=e,this.inclusive=t}}function eI(e,t,n){let r=0;for(let s=0;s<e.position.length;s++){let i=t[s],a=e.position[s];if(r=i.field.isKeyField()?q.comparator(q.fromName(a.referenceValue),n.key):ec(a,n.data.field(i.field)),"desc"===i.dir&&(r*=-1),0!==r)break}return r}function eC(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 n=0;n<e.position.length;n++)if(!eu(e.position[n],t.position[n]))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 */class eS{}class eA extends eS{constructor(e,t,n){super(),this.field=e,this.op=t,this.value=n}static create(e,t,n){return e.isKeyField()?"in"===t||"not-in"===t?this.createKeyFieldInFilter(e,t,n):new eD(e,t,n):"array-contains"===t?new ex(e,n):"in"===t?new eV(e,n):"not-in"===t?new eF(e,n):"array-contains-any"===t?new eO(e,n):new eA(e,t,n)}static createKeyFieldInFilter(e,t,n){return"in"===t?new e_(e,n):new eR(e,n)}matches(e){let t=e.data.field(this.field);return"!="===this.op?null!==t&&this.matchesComparison(ec(t,this.value)):null!==t&&el(this.value)===el(t)&&this.matchesComparison(ec(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 w()}}isInequality(){return["<","<=",">",">=","!=","not-in"].indexOf(this.op)>=0}getFlattenedFilters(){return[this]}getFilters(){return[this]}getFirstInequalityField(){return this.isInequality()?this.field:null}}class eN extends eS{constructor(e,t){super(),this.filters=e,this.op=t,this.ht=null}static create(e,t){return new eN(e,t)}matches(e){return ek(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 ek(e){return"and"===e.op}function eb(e){for(let t of e.filters)if(t instanceof eN)return!1;return!0}class eD extends eA{constructor(e,t,n){super(e,t,n),this.key=q.fromName(n.referenceValue)}matches(e){let t=q.comparator(e.key,this.key);return this.matchesComparison(t)}}class e_ extends eA{constructor(e,t){super(e,"in",t),this.keys=eL("in",t)}matches(e){return this.keys.some(t=>t.isEqual(e.key))}}class eR extends eA{constructor(e,t){super(e,"not-in",t),this.keys=eL("not-in",t)}matches(e){return!this.keys.some(t=>t.isEqual(e.key))}}function eL(e,t){var n;return((null===(n=t.arrayValue)||void 0===n?void 0:n.values)||[]).map(e=>q.fromName(e.referenceValue))}class ex extends eA{constructor(e,t){super(e,"array-contains",t)}matches(e){let t=e.data.field(this.field);return eg(t)&&eh(t.arrayValue,this.value)}}class eV extends eA{constructor(e,t){super(e,"in",t)}matches(e){let t=e.data.field(this.field);return null!==t&&eh(this.value.arrayValue,t)}}class eF extends eA{constructor(e,t){super(e,"not-in",t)}matches(e){if(eh(this.value.arrayValue,{nullValue:"NULL_VALUE"}))return!1;let t=e.data.field(this.field);return null!==t&&!eh(this.value.arrayValue,t)}}class eO extends eA{constructor(e,t){super(e,"array-contains-any",t)}matches(e){let t=e.data.field(this.field);return!(!eg(t)||!t.arrayValue.values)&&t.arrayValue.values.some(e=>eh(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 */class eM{constructor(e,t="asc"){this.field=e,this.dir=t}}/** 362 * @license 363 * Copyright 2017 Google LLC 364 * 365 * Licensed under the Apache License, Version 2.0 (the "License"); 366 * you may not use this file except in compliance with the License. 367 * You may obtain a copy of the License at 368 * 369 * http://www.apache.org/licenses/LICENSE-2.0 370 * 371 * Unless required by applicable law or agreed to in writing, software 372 * distributed under the License is distributed on an "AS IS" BASIS, 373 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 374 * See the License for the specific language governing permissions and 375 * limitations under the License. 376 */class eU{constructor(e,t){this.comparator=e,this.root=t||eq.EMPTY}insert(e,t){return new eU(this.comparator,this.root.insert(e,t,this.comparator).copy(null,null,eq.BLACK,null,null))}remove(e){return new eU(this.comparator,this.root.remove(e,this.comparator).copy(null,null,eq.BLACK,null,null))}get(e){let t=this.root;for(;!t.isEmpty();){let n=this.comparator(e,t.key);if(0===n)return t.value;n<0?t=t.left:n>0&&(t=t.right)}return null}indexOf(e){let t=0,n=this.root;for(;!n.isEmpty();){let r=this.comparator(e,n.key);if(0===r)return t+n.left.size;r<0?n=n.left:(t+=n.left.size+1,n=n.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,n)=>(e(t,n),!1))}toString(){let e=[];return this.inorderTraversal((t,n)=>(e.push(`${t}:${n}`),!1)),`{${e.join(", ")}}`}reverseTraversal(e){return this.root.reverseTraversal(e)}getIterator(){return new eP(this.root,null,this.comparator,!1)}getIteratorFrom(e){return new eP(this.root,e,this.comparator,!1)}getReverseIterator(){return new eP(this.root,null,this.comparator,!0)}getReverseIteratorFrom(e){return new eP(this.root,e,this.comparator,!0)}}class eP{constructor(e,t,n,r){this.isReverse=r,this.nodeStack=[];let s=1;for(;!e.isEmpty();)if(s=t?n(e.key,t):1,t&&r&&(s*=-1),s<0)e=this.isReverse?e.left:e.right;else{if(0===s){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}}}class eq{constructor(e,t,n,r,s){this.key=e,this.value=t,this.color=null!=n?n:eq.RED,this.left=null!=r?r:eq.EMPTY,this.right=null!=s?s:eq.EMPTY,this.size=this.left.size+1+this.right.size}copy(e,t,n,r,s){return new eq(null!=e?e:this.key,null!=t?t:this.value,null!=n?n:this.color,null!=r?r:this.left,null!=s?s: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,n){let r=this,s=n(e,r.key);return(r=s<0?r.copy(null,null,null,r.left.insert(e,t,n),null):0===s?r.copy(null,t,null,null,null):r.copy(null,null,null,null,r.right.insert(e,t,n))).fixUp()}removeMin(){if(this.left.isEmpty())return eq.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 n,r=this;if(0>t(e,r.key))r.left.isEmpty()||r.left.isRed()||r.left.left.isRed()||(r=r.moveRedLeft()),r=r.copy(null,null,null,r.left.remove(e,t),null);else{if(r.left.isRed()&&(r=r.rotateRight()),r.right.isEmpty()||r.right.isRed()||r.right.left.isRed()||(r=r.moveRedRight()),0===t(e,r.key)){if(r.right.isEmpty())return eq.EMPTY;n=r.right.min(),r=r.copy(n.key,n.value,null,null,r.right.removeMin())}r=r.copy(null,null,null,null,r.right.remove(e,t))}return r.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,eq.RED,null,this.right.left);return this.right.copy(null,null,this.color,e,null)}rotateRight(){let e=this.copy(null,null,eq.RED,this.left.right,null);return this.left.copy(null,null,this.color,null,e)}colorFlip(){let e=this.left.copy(null,null,!this.left.color,null,null),t=this.right.copy(null,null,!this.right.color,null,null);return this.copy(null,null,!this.color,e,t)}checkMaxDepth(){return Math.pow(2,this.check())<=this.size+1}check(){if(this.isRed()&&this.left.isRed()||this.right.isRed())throw w();let e=this.left.check();if(e!==this.right.check())throw w();return e+(this.isRed()?0:1)}}
376eq.EMPTY=null,eq.RED=!0,eq.BLACK=!1,eq.EMPTY=new class{constructor(){this.size=0}get key(){throw w()}get value(){throw w()}get color(){throw w()}get left(){throw w()}get right(){throw w()}copy(e,t,n,r,s){return this}insert(e,t,n){return new eq(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 */class eB{constructor(e){this.comparator=e,this.data=new eU(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,n)=>(e(t),!1))}forEachInRange(e,t){let n=this.data.getIteratorFrom(e[0]);for(;n.hasNext();){let r=n.getNext();if(this.comparator(r.key,e[1])>=0)return;t(r.key)}}forEachWhile(e,t){let n;for(n=void 0!==t?this.data.getIteratorFrom(t):this.data.getIterator();n.hasNext();)if(!e(n.getNext().key))return}firstAfterOrEqual(e){let t=this.data.getIteratorFrom(e);return t.hasNext()?t.getNext().key:null}getIterator(){return new eK(this.data.getIterator())}getIteratorFrom(e){return new eK(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 eB)||this.size!==e.size)return!1;let t=this.data.getIterator(),n=e.data.getIterator();for(;t.hasNext();){let e=t.getNext().key,r=n.getNext().key;if(0!==this.comparator(e,r))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 eB(this.comparator);return t.data=e,t}}class eK{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, software 402 * distributed under the License is distributed on an "AS IS" BASIS, 403 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 404 * See the License for the specific language governing permissions and 405 * limitations under the License. 406 */class eQ{constructor(e){this.fields=e,e.sort(P.comparator)}static empty(){return new eQ([])}unionWith(e){let t=new eB(P.comparator);for(let e of this.fields)t=t.add(e);for(let n of e)t=t.add(n);return new eQ(t.toArray())}covers(e){for(let t of this.fields)if(t.isPrefixOf(e))return!0;return!1}isEqual(e){return x(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 */class eG{constructor(e){this.value=e}static empty(){return new eG({mapValue:{}})}field(e){if(e.isEmpty())return this.value;{let t=this.value;for(let n=0;n<e.length-1;++n)if(!ev(t=(t.mapValue.fields||{})[e.get(n)]))return null;return(t=(t.mapValue.fields||{})[e.lastSegment()])||null}}set(e,t){this.getFieldsMap(e.popLast())[e.lastSegment()]=ew(t)}setAll(e){let t=P.emptyPath(),n={},r=[];e.forEach((e,s)=>{if(!t.isImmediateParentOf(s)){let e=this.getFieldsMap(t);this.applyChanges(e,n,r),n={},r=[],t=s.popLast()}e?n[s.lastSegment()]=ew(e):r.push(s.lastSegment())});let s=this.getFieldsMap(t);this.applyChanges(s,n,r)}delete(e){let t=this.field(e.popLast());ev(t)&&t.mapValue.fields&&delete t.mapValue.fields[e.lastSegment()]}isEqual(e){return eu(this.value,e.value)}getFieldsMap(e){let t=this.value;t.mapValue.fields||(t.mapValue={fields:{}});for(let n=0;n<e.length;++n){let r=t.mapValue.fields[e.get(n)];ev(r)&&r.mapValue.fields||(r={mapValue:{fields:{}}},t.mapValue.fields[e.get(n)]=r),t=r}return t.mapValue.fields}
421applyChanges(e,t,n){for(let r of(X(t,(t,n)=>e[t]=n),n))delete e[r]}clone(){return new eG(ew(this.value))}}/** 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 */class ez{constructor(e,t,n,r,s,i,a){this.key=e,this.documentType=t,this.version=n,this.readTime=r,this.createTime=s,this.data=i,this.documentState=a}static newInvalidDocument(e){return new ez(e,0,F.min(),F.min(),F.min(),eG.empty(),0)}static newFoundDocument(e,t,n,r){return new ez(e,1,t,F.min(),n,r,0)}static newNoDocument(e,t){return new ez(e,2,t,F.min(),F.min(),eG.empty(),0)}static newUnknownDocument(e,t){return new ez(e,3,t,F.min(),F.min(),eG.empty(),2)}convertToFoundDocument(e,t){return this.createTime.isEqual(F.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=eG.empty(),this.documentState=0,this}convertToUnknownDocument(e){return this.version=e,this.documentType=3,this.data=eG.empty(),this.documentState=2,this}setHasCommittedMutations(){return this.documentState=2,this}setHasLocalMutations(){return this.documentState=1,this.version=F.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 ez&&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 ez(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}})`}}/** 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 */class e${constructor(e,t=null,n=[],r=[],s=null,i=null,a=null){this.path=e,this.collectionGroup=t,this.orderBy=n,this.filters=r,this.limit=s,this.startAt=i,this.endAt=a,this.ft=null}}function ej(e,t=null,n=[],r=[],s=null,i=null,a=null){return new e$(e,t,n,r,s,i,a)}function eW(e){if(null===e.ft){let t=e.path.canonicalString();null!==e.collectionGroup&&(t+="|cg:"+e.collectionGroup),t+="|f:"+e.filters.map(e=>(function e(t){if(t instanceof eA)return t.field.canonicalString()+t.op.toString()+ef(t.value);if(eb(t)&&ek(t))return t.filters.map(t=>e(t)).join(",");{let n=t.filters.map(t=>e(t)).join(",");return`${t.op}(${n})`}})(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=>ef(e)).join(",")),e.endAt&&(t+="|ub:"+(e.endAt.inclusive?"a:":"b:")+e.endAt.position.map(e=>ef(e)).join(",")),e.ft=t}return e.ft}function eH(e,t){if(e.limit!==t.limit||e.orderBy.length!==t.orderBy.length)return!1;for(let s=0;s<e.orderBy.length;s++){var n,r;if(n=e.orderBy[s],r=t.orderBy[s],!(n.dir===r.dir&&n.field.isEqual(r.field)))return!1}if(e.filters.length!==t.filters.length)return!1;for(let n=0;n<e.filters.length;n++)if(!function e(t,n){return t instanceof eA?n instanceof eA&&t.op===n.op&&t.field.isEqual(n.field)&&eu(t.value,n.value):t instanceof eN?n instanceof eN&&t.op===n.op&&t.filters.length===n.filters.length&&t.filters.reduce((t,r,s)=>t&&e(r,n.filters[s]),!0):void w()}(e.filters[n],t.filters[n]))return!1;return e.collectionGroup===t.collectionGroup&&!!e.path.isEqual(t.path)&&!!eC(e.startAt,t.startAt)&&eC(e.endAt,t.endAt)}function eY(e){return q.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 */class eX{constructor(e,t=null,n=[],r=[],s=null,i="F",a=null,o=null){this.path=e,this.collectionGroup=t,this.explicitOrderBy=n,this.filters=r,this.limit=s,this.limitType=i,this.startAt=a,this.endAt=o,this.dt=null,this._t=null,this.startAt,this.endAt}}function eJ(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 eZ(e){if(null===e.dt){e.dt=[];let t=function(e){for(let t of e.filters){let e=t.getFirstInequalityField();if(null!==e)return e}return null}(e),n=e.explicitOrderBy.length>0?e.explicitOrderBy[0].field:null;if(null!==t&&null===n)t.isKeyField()||e.dt.push(new eM(t)),e.dt.push(new eM(P.keyField(),"asc"));else{let t=!1;for(let n of e.explicitOrderBy)e.dt.push(n),n.field.isKeyField()&&(t=!0);if(!t){let t=e.explicitOrderBy.length>0?e.explicitOrderBy[e.explicitOrderBy.length-1].dir:"asc";e.dt.push(new eM(P.keyField(),t))}}}return e.dt}function e0(e){if(!e._t){if("F"===e.limitType)e._t=ej(e.path,e.collectionGroup,eZ(e),e.filters,e.limit,e.startAt,e.endAt);else{let t=[];for(let n of eZ(e)){let e="desc"===n.dir?"asc":"desc";t.push(new eM(n.field,e))}let n=e.endAt?new eT(e.endAt.position,e.endAt.inclusive):null,r=e.startAt?new eT(e.startAt.position,e.startAt.inclusive):null;e._t=ej(e.path,e.collectionGroup,t,e.filters,e.limit,n,r)}}return e._t}function e1(e,t,n){return new eX(e.path,e.collectionGroup,e.explicitOrderBy.slice(),e.filters.slice(),t,n,e.startAt,e.endAt)}function e2(e,t){return eH(e0(e),e0(t))&&e.limitType===t.limitType}function e4(e){return`${eW(e0(e))}|lt:${e.limitType}`}function e3(e){var t;let n;return`Query(target=${n=(t=e0(e)).path.canonicalString(),null!==t.collectionGroup&&(n+=" collectionGroup="+t.collectionGroup),t.filters.length>0&&(n+=`, filters: [${t.filters.map(e=>(function e(t){return t instanceof eA?`${t.field.canonicalString()} ${t.op} ${ef(t.value)}`:t instanceof eN?t.op.toString()+" {"+t.getFilters().map(e).join(" ,")+"}":"Filter"})(e)).join(", ")}]`),null==t.limit||(n+=", limit: "+t.limit),t.orderBy.length>0&&(n+=`, orderBy: [${t.orderBy.map(e=>`${e.field.canonicalString()} (${e.dir})`).join(", ")}]`),t.startAt&&(n+=", startAt: "+(t.startAt.inclusive?"b:":"a:")+t.startAt.position.map(e=>ef(e)).join(",")),t.endAt&&(n+=", endAt: "+(t.endAt.inclusive?"a:":"b:")+t.endAt.position.map(e=>ef(e)).join(",")),`Target(${n})`}; limitType=${e.limitType})`}function e9(e,t){return t.isFoundDocument()&&function(e,t){let n=t.key.path;return null!==e.collectionGroup?t.key.hasCollectionId(e.collectionGroup)&&e.path.isPrefixOf(n):q.isDocumentKey(e.path)?e.path.isEqual(n):e.path.isImmediateParentOf(n)}(e,t)&&function(e,t){for(let n of eZ(e))if(!n.field.isKeyField()&&null===t.data.field(n.field))return!1;return!0}(e,t)&&function(e,t){for(let n of e.filters)if(!n.matches(t))return!1;return!0}(e,t)&&(!e.startAt||!!function(e,t,n){let r=eI(e,t,n);return e.inclusive?r<=0:r<0}(e.startAt,eZ(e),t))&&(!e.endAt||!!function(e,t,n){let r=eI(e,t,n);return e.inclusive?r>=0:r>0}(e.endAt,eZ(e),t))}function e5(e){return(t,n)=>{let r=!1;for(let s of eZ(e)){let e=function(e,t,n){let r=e.field.isKeyField()?q.comparator(t.key,n.key):function(e,t,n){let r=t.data.field(e),s=n.data.field(e);return null!==r&&null!==s?ec(r,s):w()}(e.field,t,n);switch(e.dir){case"asc":return r;case"desc":return -1*r;default:return w()}}(s,t,n);if(0!==e)return e;r=r||s.field.isKeyField()}return 0}}/** 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, softw
476are 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 e6(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:Z(t)?"-0":t}}function e8(e){return{integerValue:""+e}}/** 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 */class e7{constructor(){this._=void 0}}function te(e,t){return e instanceof ta?em(t)||t&&"doubleValue"in t?t:{integerValue:0}:null}class tt extends e7{}class tn extends e7{constructor(e){super(),this.elements=e}}function tr(e,t){let n=tl(t);for(let t of e.elements)n.some(e=>eu(e,t))||n.push(t);return{arrayValue:{values:n}}}class ts extends e7{constructor(e){super(),this.elements=e}}function ti(e,t){let n=tl(t);for(let t of e.elements)n=n.filter(e=>!eu(e,t));return{arrayValue:{values:n}}}class ta extends e7{constructor(e,t){super(),this.yt=e,this.gt=t}}function to(e){return er(e.integerValue||e.doubleValue)}function tl(e){return eg(e)&&e.arrayValue.values?e.arrayValue.values.slice():[]}class tu{constructor(e,t){this.version=e,this.transformResults=t}}class th{constructor(e,t){this.updateTime=e,this.exists=t}static none(){return new th}static exists(e){return new th(void 0,e)}static updateTime(e){return new th(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 tc(e,t){return void 0!==e.updateTime?t.isFoundDocument()&&t.version.isEqual(e.updateTime):void 0===e.exists||e.exists===t.isFoundDocument()}class td{}function tf(e,t){if(!e.hasLocalMutations||t&&0===t.fields.length)return null;if(null===t)return e.isNoDocument()?new tT(e.key,th.none()):new tp(e.key,e.data,th.none());{let n=e.data,r=eG.empty(),s=new eB(P.comparator);for(let e of t.fields)if(!s.has(e)){let t=n.field(e);null===t&&e.length>1&&(e=e.popLast(),t=n.field(e)),null===t?r.delete(e):r.set(e,t),s=s.add(e)}return new ty(e.key,r,new eQ(s.toArray()),th.none())}}function tm(e,t,n,r){return e instanceof tp?function(e,t,n,r){if(!tc(e.precondition,t))return n;let s=e.value.clone(),i=tE(e.fieldTransforms,r,t);return s.setAll(i),t.convertToFoundDocument(t.version,s).setHasLocalMutations(),null}(e,t,n,r):e instanceof ty?function(e,t,n,r){if(!tc(e.precondition,t))return n;let s=tE(e.fieldTransforms,r,t),i=t.data;return(i.setAll(tv(e)),i.setAll(s),t.convertToFoundDocument(t.version,i).setHasLocalMutations(),null===n)?null:n.unionWith(e.fieldMask.fields).unionWith(e.fieldTransforms.map(e=>e.field))}(e,t,n,r):tc(e.precondition,t)?(t.convertToNoDocument(t.version).setHasLocalMutations(),null):n}function tg(e,t){var n,r;return e.type===t.type&&!!e.key.isEqual(t.key)&&!!e.precondition.isEqual(t.precondition)&&(n=e.fieldTransforms,r=t.fieldTransforms,!!(void 0===n&&void 0===r||!(!n||!r)&&x(n,r,(e,t)=>{var n,r;return e.field.isEqual(t.field)&&(n=e.transform,r=t.transform,n instanceof tn&&r instanceof tn||n instanceof ts&&r instanceof ts?x(n.elements,r.elements,eu):n instanceof ta&&r instanceof ta?eu(n.gt,r.gt):n instanceof tt&&r instanceof tt)})))&&(0===e.type?e.value.isEqual(t.value):1!==e.type||e.data.isEqual(t.data)&&e.fieldMask.isEqual(t.fieldMask))}class tp extends td{constructor(e,t,n,r=[]){super(),this.key=e,this.value=t,this.precondition=n,this.fieldTransforms=r,this.type=0}getFieldMask(){return null}}class ty extends td{constructor(e,t,n,r,s=[]){super(),this.key=e,this.data=t,this.fieldMask=n,this.prec
496ondition=r,this.fieldTransforms=s,this.type=1}getFieldMask(){return this.fieldMask}}function tv(e){let t=new Map;return e.fieldMask.fields.forEach(n=>{if(!n.isEmpty()){let r=e.data.field(n);t.set(n,r)}}),t}function tw(e,t,n){var r;let s=new Map;e.length===n.length||w();for(let i=0;i<n.length;i++){let a=e[i],o=a.transform,l=t.data.field(a.field);s.set(a.field,(r=n[i],o instanceof tn?tr(o,l):o instanceof ts?ti(o,l):r))}return s}function tE(e,t,n){let r=new Map;for(let s of e){let e=s.transform,i=n.data.field(s.field);r.set(s.field,e instanceof tt?function(e,t){let n={fields:{__type__:{stringValue:"server_timestamp"},__local_write_time__:{timestampValue:{seconds:e.seconds,nanos:e.nanoseconds}}}};return t&&(n.fields.__previous_value__=t),{mapValue:n}}(t,i):e instanceof tn?tr(e,i):e instanceof ts?ti(e,i):function(e,t){let n=te(e,t),r=to(n)+to(e.gt);return em(n)&&em(e.gt)?e8(r):e6(e.yt,r)}(e,i))}return r}class tT extends td{constructor(e,t){super(),this.key=e,this.precondition=t,this.type=2,this.fieldTransforms=[]}getFieldMask(){return null}}class tI extends td{constructor(e,t){super(),this.key=e,this.precondition=t,this.type=3,this.fieldTransforms=[]}getFieldMask(){return null}}/** 497 * @license 498 * Copyright 2017 Google LLC 499 * 500 * Licensed under the Apache License, Version 2.0 (the "License"); 501 * you may not use this file except in compliance with the License. 502 * You may obtain a copy of the License at 503 * 504 * http://www.apache.org/licenses/LICENSE-2.0 505 * 506 * Unless required by applicable law or agreed to in writing, software 507 * distributed under the License is distributed on an "AS IS" BASIS, 508 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 509 * See the License for the specific language governing permissions and 510 * limitations under the License. 511 */class tC{constructor(e){this.count=e}}function tS(e){if(void 0===e)return p("GRPC error has no .code"),E.UNKNOWN;switch(e){case r.OK:return E.OK;case r.CANCELLED:return E.CANCELLED;case r.UNKNOWN:return E.UNKNOWN;case r.DEADLINE_EXCEEDED:return E.DEADLINE_EXCEEDED;case r.RESOURCE_EXHAUSTED:return E.RESOURCE_EXHAUSTED;case r.INTERNAL:return E.INTERNAL;case r.UNAVAILABLE:return E.UNAVAILABLE;case r.UNAUTHENTICATED:return E.UNAUTHENTICATED;case r.INVALID_ARGUMENT:return E.INVALID_ARGUMENT;case r.NOT_FOUND:return E.NOT_FOUND;case r.ALREADY_EXISTS:return E.ALREADY_EXISTS;case r.PERMISSION_DENIED:return E.PERMISSION_DENIED;case r.FAILED_PRECONDITION:return E.FAILED_PRECONDITION;case r.ABORTED:return E.ABORTED;case r.OUT_OF_RANGE:return E.OUT_OF_RANGE;case r.UNIMPLEMENTED:return E.UNIMPLEMENTED;case r.DATA_LOSS:return E.DATA_LOSS;default:return w()}}(s=r||(r={}))[s.OK=0]="OK",s[s.CANCELLED=1]="CANCELLED",s[s.UNKNOWN=2]="UNKNOWN",s[s.INVALID_ARGUMENT=3]="INVALID_ARGUMENT",s[s.DEADLINE_EXCEEDED=4]="DEADLINE_EXCEEDED",s[s.NOT_FOUND=5]="NOT_FOUND",s[s.ALREADY_EXISTS=6]="ALREADY_EXISTS",s[s.PERMISSION_DENIED=7]="PERMISSION_DENIED",s[s.UNAUTHENTICATED=16]="UNAUTHENTICATED",s[s.RESOURCE_EXHAUSTED=8]="RESOURCE_EXHAUSTED",s[s.FAILED_PRECONDITION=9]="FAILED_PRECONDITION",s[s.ABORTED=10]="ABORTED",s[s.OUT_OF_RANGE=11]="OUT_OF_RANGE",s[s.UNIMPLEMENTED=12]="UNIMPLEMENTED",s[s.INTERNAL=13]="INTERNAL",s[s.UNAVAILABLE=14]="UNAVAILABLE",s[s.DATA_LOSS=15]="DATA_LOSS";/** 512 * @license 513 * Copyright 2017 Google LLC 514 * 515 * Licensed under the Apache License, Version 2.0 (the "License"); 516 * you may not use this file except in compliance with the License. 517 * You may obtain a copy of the License at 518 * 519 * http://www.apache.org/licenses/LICENSE-2.0 520 * 521 * Unless required by applicable law or agreed to in writing, software 522 * distributed under the License is distributed on an "AS IS" BASIS, 523 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 524 * See the License for the specific language governing permissions and 525 * limitations under the License. 526 */class tA{constructor(e,t){this.mapKeyFn=e,this.equalsFn=t,this.inner={},this.innerSize=0}get(e){let t=this.mapKeyFn(e),n=this.inner[t];if(void 0!==n){for(let[t,r]of n)if(this.equalsFn(t,e))return r}}has(e){return void 0!==this.get(e)}set(e,t){let n=this.mapKeyFn(e),r=this.inner[n];if(void 0===r)return this.inner[n]=[[e,t]],void this.innerSize++;for(let n=0;n<r.length;n++)if(this.equalsFn(r[n][0],e))return void(r[n]=[e,t]);
526r.push([e,t]),this.innerSize++}delete(e){let t=this.mapKeyFn(e),n=this.inner[t];if(void 0===n)return!1;for(let r=0;r<n.length;r++)if(this.equalsFn(n[r][0],e))return 1===n.length?delete this.inner[t]:n.splice(r,1),this.innerSize--,!0;return!1}forEach(e){X(this.inner,(t,n)=>{for(let[t,r]of n)e(t,r)})}isEmpty(){return J(this.inner)}size(){return this.innerSize}}/** 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 tN=new eU(q.comparator),tk=new eU(q.comparator);function tb(...e){let t=tk;for(let n of e)t=t.insert(n.key,n);return t}function tD(e){let t=tk;return e.forEach((e,n)=>t=t.insert(e,n.overlayedDocument)),t}function t_(){return new tA(e=>e.toString(),(e,t)=>e.isEqual(t))}let tR=new eU(q.comparator),tL=new eB(q.comparator);function tx(...e){let t=tL;for(let n of e)t=t.add(n);return t}let tV=new eB(L);/** 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 */class tF{constructor(e,t,n,r,s){this.snapshotVersion=e,this.targetChanges=t,this.targetMismatches=n,this.documentUpdates=r,this.resolvedLimboDocuments=s}static createSynthesizedRemoteEventForCurrentChange(e,t,n){let r=new Map;return r.set(e,tO.createSynthesizedTargetChangeForCurrentChange(e,t,n)),new tF(F.min(),r,tV,tN,tx())}}class tO{constructor(e,t,n,r,s){this.resumeToken=e,this.current=t,this.addedDocuments=n,this.modifiedDocuments=r,this.removedDocuments=s}static createSynthesizedTargetChangeForCurrentChange(e,t,n){return new tO(n,t,tx(),tx(),tx())}}/** 557 * @license 558 * Copyright 2017 Google LLC 559 * 560 * Licensed under the Apache License, Version 2.0 (the "License"); 561 * you may not use this file except in compliance with the License. 562 * You may obtain a copy of the License at 563 * 564 * http://www.apache.org/licenses/LICENSE-2.0 565 * 566 * Unless required by applicable law or agreed to in writing, software 567 * distributed under the License is distributed on an "AS IS" BASIS, 568 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 569 * See the License for the specific language governing permissions and 570 * limitations under the License. 571 */class tM{constructor(e,t,n,r){this.It=e,this.removedTargetIds=t,this.key=n,this.Tt=r}}class tU{constructor(e,t){this.targetId=e,this.Et=t}}class tP{constructor(e,t,n=ee.EMPTY_BYTE_STRING,r=null){this.state=e,this.targetIds=t,this.resumeToken=n,this.cause=r}}class tq{constructor(){this.At=0,this.Rt=tQ(),this.bt=ee.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=tx(),t=tx(),n=tx();return this.Rt.forEach((r,s)=>{switch(s){case 0:e=e.add(r);break;case 2:t=t.add(r);break;case 1:n=n.add(r);break;default:w()}}),new tO(this.bt,this.Pt,e,t,n)}xt(){this.vt=!1,this.Rt=tQ()}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}}class tB{constructor(e){this.$t=e,this.Bt=new Map,this.Lt=tN,this.qt=tK(),this.Ut=new eB(L)}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 n=this.Wt(t);switch(e.state){case 0:this.zt(t)&&n.Dt(e.resumeToken);break;case 1:n.Mt(),n.Vt||n.xt(),n.Dt(e.resumeToken);break;case 2:n.Mt(),n.Vt||this.removeTarget(t);break;case 3:this.zt(t)&&(n.Ft(),n.Dt(e.resumeToken));break;case 4:this.zt(t)&&(this.Ht(t),n.Dt(e.resumeToken));break;default:w()}})}forEachTarget(e,t){e.targetIds.length>0?e.targetIds.forEach(t):this.Bt.forEach((e,n)=>{this.zt(n)&&t(n)})}Jt(e){let t=e.targetId,n=e.Et.count,r=this.Yt(t);if(r){let e=r.target;if(eY(e)){if(0===n){let n=new q(e.path);this.Qt(t,n,ez.newNoDocument(n,F.min()))}else 1===n||w()}else this.Xt(t)!==n&&(this.Ht(t),this.Ut=this.Ut.add(t))}}Zt(e){let t=new Map;this.Bt.forEach((n,r)=>{let s=this.Yt(r);if(s){if(n.current&&eY(s.target)){let t=new q(s.target.path);null!==this.Lt.get(t)||this.te(r,t)||this.Qt(r,t,ez.newNoDocument(t,e))}n.St&&(t.set(r,n.Ct()),n.xt())}});let n=tx();this.qt.forEach((e,t)=>{let r=!0;t.forEachWhile(e=>{let t=this.Yt(e);return!t||2===t.purpose||(r=!1,!1)}),r&&(n=n.add(e))}),this.Lt.forEach((t,n)=>n.setReadTime(e));let r=new tF(e,t,this.Ut,this.Lt,n);return this.Lt=tN,this.qt=tK(),this.Ut=new eB(L),r}Gt(e,t){if(!this.zt(e))return;
571let n=this.te(e,t.key)?2:0;this.Wt(e).Nt(t.key,n),this.Lt=this.Lt.insert(t.key,t),this.qt=this.qt.insert(t.key,this.ee(t.key).add(e))}Qt(e,t,n){if(!this.zt(e))return;let r=this.Wt(e);this.te(e,t)?r.Nt(t,1):r.kt(t),this.qt=this.qt.insert(t,this.ee(t).delete(e)),n&&(this.Lt=this.Lt.insert(t,n))}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 tq,this.Bt.set(e,t)),t}ee(e){let t=this.qt.get(e);return t||(t=new eB(L),this.qt=this.qt.insert(e,t)),t}zt(e){let t=null!==this.Yt(e);return t||g("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 tq),this.$t.getRemoteKeysForTarget(e).forEach(t=>{this.Qt(e,t,null)})}te(e,t){return this.$t.getRemoteKeysForTarget(e).has(t)}}function tK(){return new eU(q.comparator)}function tQ(){return new eU(q.comparator)}/** 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 tG={asc:"ASCENDING",desc:"DESCENDING"},tz={"<":"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"},t$={and:"AND",or:"OR"};class tj{constructor(e,t){this.databaseId=e,this.wt=t}}function tW(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 tH(e,t){return e.wt?t.toBase64():t.toUint8Array()}function tY(e){return e||w(),F.fromTimestamp(function(e){let t=en(e);return new V(t.seconds,t.nanos)}(e))}function tX(e,t){return new M(["projects",e.projectId,"databases",e.database]).child("documents").child(t).canonicalString()}function tJ(e){let t=M.fromString(e);return t6(t)||w(),t}function tZ(e,t){return tX(e.databaseId,t.path)}function t0(e,t){let n=tJ(t);if(n.get(1)!==e.databaseId.projectId)throw new T(E.INVALID_ARGUMENT,"Tried to deserialize key from different project: "+n.get(1)+" vs "+e.databaseId.projectId);if(n.get(3)!==e.databaseId.database)throw new T(E.INVALID_ARGUMENT,"Tried to deserialize key from different database: "+n.get(3)+" vs "+e.databaseId.database);return new q(t4(n))}function t1(e,t){return tX(e.databaseId,t)}function t2(e){return new M(["projects",e.databaseId.projectId,"databases",e.databaseId.database]).canonicalString()}function t4(e){return e.length>4&&"documents"===e.get(4)||w(),e.popFirst(5)}function t3(e,t,n){return{name:tZ(e,t),fields:n.value.mapValue.fields}}function t9(e){return{fieldPath:e.canonicalString()}}function t5(e){return P.fromServerFormat(e.fieldPath)}function t6(e){return e.length>=4&&"projects"===e.get(0)&&"databases"===e.get(2)}/** 587 * @license 588 * Copyright 2017 Google LLC 589 * 590 * Licensed under the Apache License, Version 2.0 (the "License"); 591 * you may not use this file except in compliance with the License. 592 * You may obtain a copy of the License at 593 * 594 * http://www.apache.org/licenses/LICENSE-2.0 595 * 596 * Unless required by applicable law or agreed to in writing, software 597 * distributed under the License is distributed on an "AS IS" BASIS, 598 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 599 * See the License for the specific language governing permissions and 600 * limitations under the License. 601 */class t8{constructor(e,t,n,r){this.batchId=e,this.localWriteTime=t,this.baseMutations=n,this.mutations=r}applyToRemoteDocument(e,t){let n=t.mutationResults;for(let t=0;t<this.mutations.length;t++){let s=this.mutations[t];if(s.key.isEqual(e.key)){var r;r=n[t],s instanceof tp?function(e,t,n){let r=e.value.clone(),s=tw(e.fieldTransforms,t,n.transformResults);r.setAll(s),t.convertToFoundDocument(n.version,r).setHasCommittedMutations()}(s,e,r):s instanceof ty?function(e,t,n){if(!tc(e.precondition,t))return void t.convertToUnknownDocument(n.version);let r=tw(e.fieldTransforms,t,n.transformResults),s=t.data;s.setAll(tv(e)),s.setAll(r),t.convertToFoundDocument(n.version,s).setHasCommittedMutations()}(s,e,r):function(e,t,n){t.convertToNoDocument(n.version).setHasCommittedMutations()}(0,e,r)}}}applyToLocalView(e,t){for(let n of this.baseMutations)n.key.isEqual(e.key)&&
601(t=tm(n,e,t,this.localWriteTime));for(let n of this.mutations)n.key.isEqual(e.key)&&(t=tm(n,e,t,this.localWriteTime));return t}applyToLocalDocumentSet(e,t){let n=t_();return this.mutations.forEach(r=>{let s=e.get(r.key),i=s.overlayedDocument,a=this.applyToLocalView(i,s.mutatedFields),o=tf(i,a=t.has(r.key)?null:a);null!==o&&n.set(r.key,o),i.isValidDocument()||i.convertToNoDocument(F.min())}),n}keys(){return this.mutations.reduce((e,t)=>e.add(t.key),tx())}isEqual(e){return this.batchId===e.batchId&&x(this.mutations,e.mutations,(e,t)=>tg(e,t))&&x(this.baseMutations,e.baseMutations,(e,t)=>tg(e,t))}}class t7{constructor(e,t,n,r){this.batch=e,this.commitVersion=t,this.mutationResults=n,this.docVersions=r}static from(e,t,n){e.mutations.length===n.length||w();let r=tR,s=e.mutations;for(let e=0;e<s.length;e++)r=r.insert(s[e].key,n[e].version);return new t7(e,t,n,r)}}/** 602 * @license 603 * Copyright 2022 Google LLC 604 * 605 * Licensed under the Apache License, Version 2.0 (the "License"); 606 * you may not use this file except in compliance with the License. 607 * You may obtain a copy of the License at 608 * 609 * http://www.apache.org/licenses/LICENSE-2.0 610 * 611 * Unless required by applicable law or agreed to in writing, software 612 * distributed under the License is distributed on an "AS IS" BASIS, 613 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 614 * See the License for the specific language governing permissions and 615 * limitations under the License. 616 */class ne{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{ 617 largestBatchId: ${this.largestBatchId}, 618 mutation: ${this.mutation.toString()} 619 }`}}/** 620 * @license 621 * Copyright 2017 Google LLC 622 * 623 * Licensed under the Apache License, Version 2.0 (the "License"); 624 * you may not use this file except in compliance with the License. 625 * You may obtain a copy of the License at 626 * 627 * http://www.apache.org/licenses/LICENSE-2.0 628 * 629 * Unless required by applicable law or agreed to in writing, software 630 * distributed under the License is distributed on an "AS IS" BASIS, 631 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 632 * See the License for the specific language governing permissions and 633 * limitations under the License. 634 */class nt{constructor(e,t,n,r,s=F.min(),i=F.min(),a=ee.EMPTY_BYTE_STRING){this.target=e,this.targetId=t,this.purpose=n,this.sequenceNumber=r,this.snapshotVersion=s,this.lastLimboFreeSnapshotVersion=i,this.resumeToken=a}withSequenceNumber(e){return new nt(this.target,this.targetId,this.purpose,e,this.snapshotVersion,this.lastLimboFreeSnapshotVersion,this.resumeToken)}withResumeToken(e,t){return new nt(this.target,this.targetId,this.purpose,this.sequenceNumber,t,this.lastLimboFreeSnapshotVersion,e)}withLastLimboFreeSnapshotVersion(e){return new nt(this.target,this.targetId,this.purpose,this.sequenceNumber,this.snapshotVersion,e,this.resumeToken)}}/** 635 * @license 636 * Copyright 2017 Google LLC 637 * 638 * Licensed under the Apache License, Version 2.0 (the "License"); 639 * you may not use this file except in compliance with the License. 640 * You may obtain a copy of the License at 641 * 642 * http://www.apache.org/licenses/LICENSE-2.0 643 * 644 * Unless required by applicable law or agreed to in writing, software 645 * distributed under the License is distributed on an "AS IS" BASIS, 646 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 647 * See the License for the specific language governing permissions and 648 * limitations under the License. 649 */class nn{constructor(e){this.ie=e}}/** 650 * @license 651 * Copyright 2021 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 */class nr{constructor(){}
664ue(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(er(e.integerValue));else if("doubleValue"in e){let n=er(e.doubleValue);isNaN(n)?this.he(t,13):(this.he(t,15),Z(n)?t.le(0):t.le(n))}else if("timestampValue"in e){let n=e.timestampValue;this.he(t,20),"string"==typeof n?t.fe(n):(t.fe(`${n.seconds||""}`),t.le(n.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(es(e.bytesValue)),this._e(t);else if("referenceValue"in e)this.me(e.referenceValue,t);else if("geoPointValue"in e){let n=e.geoPointValue;this.he(t,45),t.le(n.latitude||0),t.le(n.longitude||0)}else"mapValue"in e?eE(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)):w()}de(e,t){this.he(t,25),this.pe(e,t)}pe(e,t){t.fe(e)}ge(e,t){let n=e.fields||{};for(let e of(this.he(t,55),Object.keys(n)))this.de(e,t),this.ce(n[e],t)}ye(e,t){let n=e.values||[];for(let e of(this.he(t,50),n))this.ce(e,t)}me(e,t){this.he(t,37),q.fromName(e).path.forEach(e=>{this.he(t,60),this.pe(e,t)})}he(e,t){e.le(t)}_e(e){e.le(2)}}nr.Ie=new nr;/** 665 * @license 666 * Copyright 2019 Google LLC 667 * 668 * Licensed under the Apache License, Version 2.0 (the "License"); 669 * you may not use this file except in compliance with the License. 670 * You may obtain a copy of the License at 671 * 672 * http://www.apache.org/licenses/LICENSE-2.0 673 * 674 * Unless required by applicable law or agreed to in writing, software 675 * distributed under the License is distributed on an "AS IS" BASIS, 676 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 677 * See the License for the specific language governing permissions and 678 * limitations under the License. 679 */class ns{constructor(){this.Je=new ni}addToCollectionParentIndex(e,t){return this.Je.add(t),z.resolve()}getCollectionParents(e,t){return z.resolve(this.Je.getEntries(t))}addFieldIndex(e,t){return z.resolve()}deleteFieldIndex(e,t){return z.resolve()}getDocumentsMatchingTarget(e,t){return z.resolve(null)}getIndexType(e,t){return z.resolve(0)}getFieldIndexes(e,t){return z.resolve([])}getNextCollectionGroupToUpdate(e){return z.resolve(null)}getMinOffset(e,t){return z.resolve(K.min())}getMinOffsetFromCollectionGroup(e,t){return z.resolve(K.min())}updateCollectionGroup(e,t,n){return z.resolve()}updateIndexEntries(e,t){return z.resolve()}}class ni{constructor(){this.index={}}add(e){let t=e.lastSegment(),n=e.popLast(),r=this.index[t]||new eB(M.comparator),s=!r.has(n);return this.index[t]=r.add(n),s}has(e){let t=e.lastSegment(),n=e.popLast(),r=this.index[t];return r&&r.has(n)}getEntries(e){return(this.index[e]||new eB(M.comparator)).toArray()}}new Uint8Array(0);class na{constructor(e,t,n){this.cacheSizeCollectionThreshold=e,this.percentileToCollect=t,this.maximumSequenceNumbersToCollect=n}static withCacheSize(e){return new na(e,na.DEFAULT_COLLECTION_PERCENTILE,na.DEFAULT_MAX_SEQUENCE_NUMBERS_TO_COLLECT)}}/** 680 * @license 681 * Copyright 2017 Google LLC 682 * 683 * Licensed under the Apache License, Version 2.0 (the "License"); 684 * you may not use this file except in compliance with the License. 685 * You may obtain a copy of the License at 686 * 687 * http://www.apache.org/licenses/LICENSE-2.0 688 * 689 * Unless required by applicable law or agreed to in writing, software 690 * distributed under the License is distributed on an "AS IS" BASIS, 691 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 692 * See the License for the specific language governing permissions and 693 * limitations under the License. 694 */na.DEFAULT_COLLECTION_PERCENTILE=10,na.DEFAULT_MAX_SEQUENCE_NUMBERS_TO_COLLECT=1e3,na.DEFAULT=new na(41943040,na.DEFAULT_COLLECTION_PERCENTILE,na.DEFAULT_MAX_SEQUENCE_NUMBERS_TO_COLLECT),na.DISABLED=new na(-1,0,0);/** 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, softw
704are 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 */class no{constructor(e){this.bn=e}next(){return this.bn+=2,this.bn}static Pn(){return new no(0)}static vn(){return new no(-1)}}/** 710 * @license 711 * Copyright 2017 Google LLC 712 * 713 * Licensed under the Apache License, Version 2.0 (the "License"); 714 * you may not use this file except in compliance with the License. 715 * You may obtain a copy of the License at 716 * 717 * http://www.apache.org/licenses/LICENSE-2.0 718 * 719 * Unless required by applicable law or agreed to in writing, software 720 * distributed under the License is distributed on an "AS IS" BASIS, 721 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 722 * See the License for the specific language governing permissions and 723 * limitations under the License. 724 */class nl{constructor(){this.changes=new tA(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,ez.newInvalidDocument(e).setReadTime(t))}getEntry(e,t){this.assertNotApplied();let n=this.changes.get(t);return void 0!==n?z.resolve(n):this.getFromCache(e,t)}getEntries(e,t){return this.getAllFromCache(e,t)}apply(e){return this.assertNotApplied(),this.changesApplied=!0,this.applyChanges(e)}assertNotApplied(){}}/** 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 *//** 740 * @license 741 * Copyright 2022 Google LLC 742 * 743 * Licensed under the Apache License, Version 2.0 (the "License"); 744 * you may not use this file except in compliance with the License. 745 * You may obtain a copy of the License at 746 * 747 * http://www.apache.org/licenses/LICENSE-2.0 748 * 749 * Unless required by applicable law or agreed to in writing, software 750 * distributed under the License is distributed on an "AS IS" BASIS, 751 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 752 * See the License for the specific language governing permissions and 753 * limitations under the License. 754 */class nu{constructor(e,t){this.overlayedDocument=e,this.mutatedFields=t}}/** 755 * @license 756 * Copyright 2017 Google LLC 757 * 758 * Licensed under the Apache License, Version 2.0 (the "License"); 759 * you may not use this file except in compliance with the License. 760 * You may obtain a copy of the License at 761 * 762 * http://www.apache.org/licenses/LICENSE-2.0 763 * 764 * Unless required by applicable law or agreed to in writing, software 765 * distributed under the License is distributed on an "AS IS" BASIS, 766 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 767 * See the License for the specific language governing permissions and 768 * limitations under the License. 769 */class nh{constructor(e,t,n,r){this.remoteDocumentCache=e,this.mutationQueue=t,this.documentOverlayCache=n,this.indexManager=r}getDocument(e,t){let n=null;return this.documentOverlayCache.getOverlay(e,t).next(r=>(n=r,this.remoteDocumentCache.getEntry(e,t))).next(e=>(null!==n&&tm(n.mutation,e,eQ.empty(),V.now()),e))}getDocuments(e,t){return this.remoteDocumentCache.getEntries(e,t).next(t=>this.getLocalViewOfDocuments(e,t,tx()).next(()=>t))}getLocalViewOfDocuments(e,t,n=tx()){let r=t_();return this.populateOverlays(e,r,t).next(()=>this.computeViews(e,t,r,n).next(e=>{let t=tb();return e.forEach((e,n)=>{t=t.insert(e,n.overlayedDocument)}),t}))}getOverlayedDocuments(e,t){let n=t_();return this.populateOverlays(e,n,t).next(()=>this.computeViews(e,t,n,tx()))}populateOverlays(e,t,n){let r=[];
769return n.forEach(e=>{t.has(e)||r.push(e)}),this.documentOverlayCache.getOverlays(e,r).next(e=>{e.forEach((e,n)=>{t.set(e,n)})})}computeViews(e,t,n,r){let s=tN,i=t_(),a=t_();return t.forEach((e,t)=>{let a=n.get(t.key);r.has(t.key)&&(void 0===a||a.mutation instanceof ty)?s=s.insert(t.key,t):void 0!==a?(i.set(t.key,a.mutation.getFieldMask()),tm(a.mutation,t,a.mutation.getFieldMask(),V.now())):i.set(t.key,eQ.empty())}),this.recalculateAndSaveOverlays(e,s).next(e=>(e.forEach((e,t)=>i.set(e,t)),t.forEach((e,t)=>{var n;return a.set(e,new nu(t,null!==(n=i.get(e))&&void 0!==n?n:null))}),a))}recalculateAndSaveOverlays(e,t){let n=t_(),r=new eU((e,t)=>e-t),s=tx();return this.mutationQueue.getAllMutationBatchesAffectingDocumentKeys(e,t).next(e=>{for(let s of e)s.keys().forEach(e=>{let i=t.get(e);if(null===i)return;let a=n.get(e)||eQ.empty();a=s.applyToLocalView(i,a),n.set(e,a);let o=(r.get(s.batchId)||tx()).add(e);r=r.insert(s.batchId,o)})}).next(()=>{let i=[],a=r.getReverseIterator();for(;a.hasNext();){let r=a.getNext(),o=r.key,l=r.value,u=t_();l.forEach(e=>{if(!s.has(e)){let r=tf(t.get(e),n.get(e));null!==r&&u.set(e,r),s=s.add(e)}}),i.push(this.documentOverlayCache.saveOverlays(e,o,u))}return z.waitFor(i)}).next(()=>n)}recalculateAndSaveOverlaysForDocumentKeys(e,t){return this.remoteDocumentCache.getEntries(e,t).next(t=>this.recalculateAndSaveOverlays(e,t))}getDocumentsMatchingQuery(e,t,n){return q.isDocumentKey(t.path)&&null===t.collectionGroup&&0===t.filters.length?this.getDocumentsMatchingDocumentQuery(e,t.path):null!==t.collectionGroup?this.getDocumentsMatchingCollectionGroupQuery(e,t,n):this.getDocumentsMatchingCollectionQuery(e,t,n)}getNextDocuments(e,t,n,r){return this.remoteDocumentCache.getAllFromCollectionGroup(e,t,n,r).next(s=>{let i=r-s.size>0?this.documentOverlayCache.getOverlaysForCollectionGroup(e,t,n.largestBatchId,r-s.size):z.resolve(t_()),a=-1,o=s;return i.next(t=>z.forEach(t,(t,n)=>(a<n.largestBatchId&&(a=n.largestBatchId),s.get(t)?z.resolve():this.remoteDocumentCache.getEntry(e,t).next(e=>{o=o.insert(t,e)}))).next(()=>this.populateOverlays(e,t,s)).next(()=>this.computeViews(e,o,t,tx())).next(e=>({batchId:a,changes:tD(e)})))})}getDocumentsMatchingDocumentQuery(e,t){return this.getDocument(e,new q(t)).next(e=>{let t=tb();return e.isFoundDocument()&&(t=t.insert(e.key,e)),t})}getDocumentsMatchingCollectionGroupQuery(e,t,n){let r=t.collectionGroup,s=tb();return this.indexManager.getCollectionParents(e,r).next(i=>z.forEach(i,i=>{let a=new eX(i.child(r),null,t.explicitOrderBy.slice(),t.filters.slice(),t.limit,t.limitType,t.startAt,t.endAt);return this.getDocumentsMatchingCollectionQuery(e,a,n).next(e=>{e.forEach((e,t)=>{s=s.insert(e,t)})})}).next(()=>s))}getDocumentsMatchingCollectionQuery(e,t,n){let r;return this.remoteDocumentCache.getAllFromCollection(e,t.path,n).next(s=>(r=s,this.documentOverlayCache.getOverlaysForCollection(e,t.path,n.largestBatchId))).next(e=>{e.forEach((e,t)=>{let n=t.getKey();null===r.get(n)&&(r=r.insert(n,ez.newInvalidDocument(n)))});let n=tb();return r.forEach((r,s)=>{let i=e.get(r);void 0!==i&&tm(i.mutation,s,eQ.empty(),V.now()),e9(t,s)&&(n=n.insert(r,s))}),n})}}/** 770 * @license 771 * Copyright 2020 Google LLC 772 * 773 * Licensed under the Apache License, Version 2.0 (the "License"); 774 * you may not use this file except in compliance with the License. 775 * You may obtain a copy of the License at 776 * 777 * http://www.apache.org/licenses/LICENSE-2.0 778 * 779 * Unless required by applicable law or agreed to in writing, software 780 * distributed under the License is distributed on an "AS IS" BASIS, 781 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 782 * See the License for the specific language governing permissions and 783 * limitations under the License. 784 */class nc{constructor(e){this.yt=e,this.Zn=new Map,this.ts=new Map}getBundleMetadata(e,t){return z.resolve(this.Zn.get(t))}saveBundleMetadata(e,t){return this.Zn.set(t.id,{id:t.id,version:t.version,createTime:tY(t.createTime)}),z.resolve()}getNamedQuery(e,t){return z.resolve(this.ts.get(t))}saveNamedQuery(e,t){return this.ts.set(t.name,{name:t.name,query:function(e){let t=function(e){var t;let n,r=function(e){let t=tJ(e);return 4===t.length?M.emptyPath():t4(t)}(e.parent),s=e.structuredQuery,i=s.from?s.from.length:0,a=null;if(i>0){1===i||w();let e=s.from[0];e.allDescendants?a=e.collectionId:r=r.child(e.collectionId)}let o=[];s.where&&(o=function(e){var t;let n=function e(t){return void 0!==t.unaryFilter?function(e){switch(e.unaryFilter.op){case"IS_NAN":let t=t5(e.unaryFilter.field);return eA.create(t,"==",{doubleValue:NaN});case"IS_NULL":let n=t5(e.unaryFilter.field);return eA.create(n,"==",{nullValue:"NULL_VALUE"});
784case"IS_NOT_NAN":let r=t5(e.unaryFilter.field);return eA.create(r,"!=",{doubleValue:NaN});case"IS_NOT_NULL":let s=t5(e.unaryFilter.field);return eA.create(s,"!=",{nullValue:"NULL_VALUE"});default:return w()}}(t):void 0!==t.fieldFilter?eA.create(t5(t.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 w()}}(t.fieldFilter.op),t.fieldFilter.value):void 0!==t.compositeFilter?eN.create(t.compositeFilter.filters.map(t=>e(t)),function(e){switch(e){case"AND":return"and";case"OR":return"or";default:return w()}}(t.compositeFilter.op)):w()}(e);return n instanceof eN&&eb(t=n)&&ek(t)?n.getFilters():[n]}(s.where));let l=[];s.orderBy&&(l=s.orderBy.map(e=>new eM(t5(e.field),function(e){switch(e){case"ASCENDING":return"asc";case"DESCENDING":return"desc";default:return}}(e.direction))));let u=null;s.limit&&(u=null==(n="object"==typeof(t=s.limit)?t.value:t)?null:n);let h=null;s.startAt&&(h=function(e){let t=!!e.before;return new eT(e.values||[],t)}(s.startAt));let c=null;return s.endAt&&(c=function(e){let t=!e.before;return new eT(e.values||[],t)}(s.endAt)),new eX(r,a,l,o,u,"F",h,c)}({parent:e.parent,structuredQuery:e.structuredQuery});return"LAST"===e.limitType?e1(t,t.limit,"L"):t}(t.bundledQuery),readTime:tY(t.readTime)}),z.resolve()}}/** 785 * @license 786 * Copyright 2022 Google LLC 787 * 788 * Licensed under the Apache License, Version 2.0 (the "License"); 789 * you may not use this file except in compliance with the License. 790 * You may obtain a copy of the License at 791 * 792 * http://www.apache.org/licenses/LICENSE-2.0 793 * 794 * Unless required by applicable law or agreed to in writing, software 795 * distributed under the License is distributed on an "AS IS" BASIS, 796 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 797 * See the License for the specific language governing permissions and 798 * limitations under the License. 799 */class nd{constructor(){this.overlays=new eU(q.comparator),this.es=new Map}getOverlay(e,t){return z.resolve(this.overlays.get(t))}getOverlays(e,t){let n=t_();return z.forEach(t,t=>this.getOverlay(e,t).next(e=>{null!==e&&n.set(t,e)})).next(()=>n)}saveOverlays(e,t,n){return n.forEach((n,r)=>{this.oe(e,t,r)}),z.resolve()}removeOverlaysForBatchId(e,t,n){let r=this.es.get(n);return void 0!==r&&(r.forEach(e=>this.overlays=this.overlays.remove(e)),this.es.delete(n)),z.resolve()}getOverlaysForCollection(e,t,n){let r=t_(),s=t.length+1,i=new q(t.child("")),a=this.overlays.getIteratorFrom(i);for(;a.hasNext();){let e=a.getNext().value,i=e.getKey();if(!t.isPrefixOf(i.path))break;i.path.length===s&&e.largestBatchId>n&&r.set(e.getKey(),e)}return z.resolve(r)}getOverlaysForCollectionGroup(e,t,n,r){let s=new eU((e,t)=>e-t),i=this.overlays.getIterator();for(;i.hasNext();){let e=i.getNext().value;if(e.getKey().getCollectionGroup()===t&&e.largestBatchId>n){let t=s.get(e.largestBatchId);null===t&&(t=t_(),s=s.insert(e.largestBatchId,t)),t.set(e.getKey(),e)}}let a=t_(),o=s.getIterator();for(;o.hasNext()&&(o.getNext().value.forEach((e,t)=>a.set(e,t)),!(a.size()>=r)););return z.resolve(a)}oe(e,t,n){let r=this.overlays.get(n.key);if(null!==r){let e=this.es.get(r.largestBatchId).delete(n.key);this.es.set(r.largestBatchId,e)}this.overlays=this.overlays.insert(n.key,new ne(t,n));let s=this.es.get(t);void 0===s&&(s=tx(),this.es.set(t,s)),this.es.set(t,s.add(n.key))}}/** 800 * @license 801 * Copyright 2017 Google LLC 802 * 803 * Licensed under the Apache License, Version 2.0 (the "License"); 804 * you may not use this file except in compliance with the License. 805 * You may obtain a copy of the License at 806 * 807 * http://www.apache.org/licenses/LICENSE-2.0 808 * 809 * Unless required by applicable law or agreed to in writing, software 810 * distributed under the License is distributed on an "AS IS" BASIS, 811 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 812 * See the License for the specific language governing permissions and 813 * limitations under the License. 814 */class nf{constructor(){this.ns=new eB(nm.ss),this.rs=new eB(nm.os)}isEmpty(){return this.ns.isEmpty()}addReference(e,t){let n=new nm(e,t);this.ns=this.ns.add(n),this.rs=this.rs.add(n)}
814us(e,t){e.forEach(e=>this.addReference(e,t))}removeReference(e,t){this.cs(new nm(e,t))}hs(e,t){e.forEach(e=>this.removeReference(e,t))}ls(e){let t=new q(new M([])),n=new nm(t,e),r=new nm(t,e+1),s=[];return this.rs.forEachInRange([n,r],e=>{this.cs(e),s.push(e.key)}),s}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 q(new M([])),n=new nm(t,e),r=new nm(t,e+1),s=tx();return this.rs.forEachInRange([n,r],e=>{s=s.add(e.key)}),s}containsKey(e){let t=new nm(e,0),n=this.ns.firstAfterOrEqual(t);return null!==n&&e.isEqual(n.key)}}class nm{constructor(e,t){this.key=e,this._s=t}static ss(e,t){return q.comparator(e.key,t.key)||L(e._s,t._s)}static os(e,t){return L(e._s,t._s)||q.comparator(e.key,t.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 */class ng{constructor(e,t){this.indexManager=e,this.referenceDelegate=t,this.mutationQueue=[],this.ws=1,this.gs=new eB(nm.ss)}checkEmpty(e){return z.resolve(0===this.mutationQueue.length)}addMutationBatch(e,t,n,r){let s=this.ws;this.ws++,this.mutationQueue.length>0&&this.mutationQueue[this.mutationQueue.length-1];let i=new t8(s,t,n,r);for(let t of(this.mutationQueue.push(i),r))this.gs=this.gs.add(new nm(t.key,s)),this.indexManager.addToCollectionParentIndex(e,t.key.path.popLast());return z.resolve(i)}lookupMutationBatch(e,t){return z.resolve(this.ys(t))}getNextMutationBatchAfterBatchId(e,t){let n=this.ps(t+1),r=n<0?0:n;return z.resolve(this.mutationQueue.length>r?this.mutationQueue[r]:null)}getHighestUnacknowledgedBatchId(){return z.resolve(0===this.mutationQueue.length?-1:this.ws-1)}getAllMutationBatches(e){return z.resolve(this.mutationQueue.slice())}getAllMutationBatchesAffectingDocumentKey(e,t){let n=new nm(t,0),r=new nm(t,Number.POSITIVE_INFINITY),s=[];return this.gs.forEachInRange([n,r],e=>{let t=this.ys(e._s);s.push(t)}),z.resolve(s)}getAllMutationBatchesAffectingDocumentKeys(e,t){let n=new eB(L);return t.forEach(e=>{let t=new nm(e,0),r=new nm(e,Number.POSITIVE_INFINITY);this.gs.forEachInRange([t,r],e=>{n=n.add(e._s)})}),z.resolve(this.Is(n))}getAllMutationBatchesAffectingQuery(e,t){let n=t.path,r=n.length+1,s=n;q.isDocumentKey(s)||(s=s.child(""));let i=new nm(new q(s),0),a=new eB(L);return this.gs.forEachWhile(e=>{let t=e.key.path;return!!n.isPrefixOf(t)&&(t.length===r&&(a=a.add(e._s)),!0)},i),z.resolve(this.Is(a))}Is(e){let t=[];return e.forEach(e=>{let n=this.ys(e);null!==n&&t.push(n)}),t}removeMutationBatch(e,t){0===this.Ts(t.batchId,"removed")||w(),this.mutationQueue.shift();let n=this.gs;return z.forEach(t.mutations,r=>{let s=new nm(r.key,t.batchId);return n=n.delete(s),this.referenceDelegate.markPotentiallyOrphaned(e,r.key)}).next(()=>{this.gs=n})}An(e){}containsKey(e,t){let n=new nm(t,0),r=this.gs.firstAfterOrEqual(n);return z.resolve(t.isEqual(r&&r.key))}performConsistencyCheck(e){return this.mutationQueue.length,z.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]}}/** 830 * @license 831 * Copyright 2017 Google LLC 832 * 833 * Licensed under the Apache License, Version 2.0 (the "License"); 834 * you may not use this file except in compliance with the License. 835 * You may obtain a copy of the License at 836 * 837 * http://www.apache.org/licenses/LICENSE-2.0 838 * 839 * Unless required by applicable law or agreed to in writing, software 840 * distributed under the License is distributed on an "AS IS" BASIS, 841 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 842 * See the License for the specific language governing permissions and 843 * limitations under the License. 844 */class np{constructor(e){this.Es=e,this.docs=new eU(q.comparator),this.size=0}setIndexManager(e){this.indexManager=e}addEntry(e,t){let n=t.key,r=this.docs.get(n),s=r?r.size:0,i=this.Es(t);return this.docs=this.docs.insert(n,{document:t.mutableCopy(),size:i}),this.size+=i-s,this.indexManager.addToCollectionParentIndex(e,n.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 n=this.docs.get(t);return z.resolve(n?n.document.mutableCopy():ez.newInvalidDocument(t))}getEntries(e,t){let n=tN;
844return t.forEach(e=>{let t=this.docs.get(e);n=n.insert(e,t?t.document.mutableCopy():ez.newInvalidDocument(e))}),z.resolve(n)}getAllFromCollection(e,t,n){let r=tN,s=new q(t.child("")),i=this.docs.getIteratorFrom(s);for(;i.hasNext();){let{key:e,value:{document:s}}=i.getNext();if(!t.isPrefixOf(e.path))break;e.path.length>t.length+1||0>=function(e,t){let n=e.readTime.compareTo(t.readTime);return 0!==n?n:0!==(n=q.comparator(e.documentKey,t.documentKey))?n:L(e.largestBatchId,t.largestBatchId)}(new K(s.readTime,s.key,-1),n)||(r=r.insert(s.key,s.mutableCopy()))}return z.resolve(r)}getAllFromCollectionGroup(e,t,n,r){w()}As(e,t){return z.forEach(this.docs,e=>t(e))}newChangeBuffer(e){return new ny(this)}getSize(e){return z.resolve(this.size)}}class ny extends nl{constructor(e){super(),this.Yn=e}applyChanges(e){let t=[];return this.changes.forEach((n,r)=>{r.isValidDocument()?t.push(this.Yn.addEntry(e,r)):this.Yn.removeEntry(n)}),z.waitFor(t)}getFromCache(e,t){return this.Yn.getEntry(e,t)}getAllFromCache(e,t){return this.Yn.getEntries(e,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 */class nv{constructor(e){this.persistence=e,this.Rs=new tA(e=>eW(e),eH),this.lastRemoteSnapshotVersion=F.min(),this.highestTargetId=0,this.bs=0,this.Ps=new nf,this.targetCount=0,this.vs=no.Pn()}forEachTarget(e,t){return this.Rs.forEach((e,n)=>t(n)),z.resolve()}getLastRemoteSnapshotVersion(e){return z.resolve(this.lastRemoteSnapshotVersion)}getHighestSequenceNumber(e){return z.resolve(this.bs)}allocateTargetId(e){return this.highestTargetId=this.vs.next(),z.resolve(this.highestTargetId)}setTargetsMetadata(e,t,n){return n&&(this.lastRemoteSnapshotVersion=n),t>this.bs&&(this.bs=t),z.resolve()}Dn(e){this.Rs.set(e.target,e);let t=e.targetId;t>this.highestTargetId&&(this.vs=new no(t),this.highestTargetId=t),e.sequenceNumber>this.bs&&(this.bs=e.sequenceNumber)}addTargetData(e,t){return this.Dn(t),this.targetCount+=1,z.resolve()}updateTargetData(e,t){return this.Dn(t),z.resolve()}removeTargetData(e,t){return this.Rs.delete(t.target),this.Ps.ls(t.targetId),this.targetCount-=1,z.resolve()}removeTargets(e,t,n){let r=0,s=[];return this.Rs.forEach((i,a)=>{a.sequenceNumber<=t&&null===n.get(a.targetId)&&(this.Rs.delete(i),s.push(this.removeMatchingKeysForTargetId(e,a.targetId)),r++)}),z.waitFor(s).next(()=>r)}getTargetCount(e){return z.resolve(this.targetCount)}getTargetData(e,t){let n=this.Rs.get(t)||null;return z.resolve(n)}addMatchingKeys(e,t,n){return this.Ps.us(t,n),z.resolve()}removeMatchingKeys(e,t,n){this.Ps.hs(t,n);let r=this.persistence.referenceDelegate,s=[];return r&&t.forEach(t=>{s.push(r.markPotentiallyOrphaned(e,t))}),z.waitFor(s)}removeMatchingKeysForTargetId(e,t){return this.Ps.ls(t),z.resolve()}getMatchingKeysForTargetId(e,t){let n=this.Ps.ds(t);return z.resolve(n)}containsKey(e,t){return z.resolve(this.Ps.containsKey(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 */class nw{constructor(e,t){this.Vs={},this.overlays={},this.Ss=new j(0),this.Ds=!1,this.Ds=!0,this.referenceDelegate=e(this),this.Cs=new nv(this),this.indexManager=new ns,this.remoteDocumentCache=new np(e=>this.referenceDelegate.xs(e)),this.yt=new nn(t),this.Ns=new nc(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 nd,this.overlays[e.toKey()]=t),t}getMutationQueue(e,t){let n=this.Vs[e.toKey()];return n||(n=new ng(t,this.referenceDelegate),this.Vs[e.toKey()]=n),n}getTargetCache(){return this.Cs}getRemoteDocumentCache(){return this.remoteDocumentCache}getBundleCache(){return this.Ns}runTransaction(e,t,n){g("MemoryPersistence","Starting transaction:",e);let r=new nE(this.Ss.next());return this.referenceDelegate.ks(),n(r).next(e=>this.referenceDelegate.Os(r).next(()=>e)).toPromise().then(e=>(r.raiseOnCommittedEvent(),e))}Ms(e,t){return z.or(Object.values(this.Vs).map(n=>()=>n.containsKey(e,t)))}}class nE extends Q{constructor(e){super(),this.currentSequenceNumber=e}}class nT{constructor(e){this.persistence=e,this.Fs=new nf,this.$s=null}static Bs(e){return new nT(e)}get Ls(){if(this.$s)return this.$s;throw w()}addReference(e,t,n){return this.Fs.addReference(n,t),this.Ls.delete(n.toString()),z.resolve()}removeReference(e,t,n){return this.Fs.removeReference(n,t),this.Ls.add(n.toString()),z.resolve()}markPotentiallyOrphaned(e,t){return this.Ls.add(t.toString()),z.resolve()}
874removeTarget(e,t){this.Fs.ls(t.targetId).forEach(e=>this.Ls.add(e.toString()));let n=this.persistence.getTargetCache();return n.getMatchingKeysForTargetId(e,t.targetId).next(e=>{e.forEach(e=>this.Ls.add(e.toString()))}).next(()=>n.removeTargetData(e,t))}ks(){this.$s=new Set}Os(e){let t=this.persistence.getRemoteDocumentCache().newChangeBuffer();return z.forEach(this.Ls,n=>{let r=q.fromPath(n);return this.qs(e,r).next(e=>{e||t.removeEntry(r,F.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 z.or([()=>z.resolve(this.Fs.containsKey(t)),()=>this.persistence.getTargetCache().containsKey(e,t),()=>this.persistence.Ms(e,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 */class nI{constructor(e,t,n,r){this.targetId=e,this.fromCache=t,this.Si=n,this.Di=r}static Ci(e,t){let n=tx(),r=tx();for(let e of t.docChanges)switch(e.type){case 0:n=n.add(e.doc.key);break;case 1:r=r.add(e.doc.key)}return new nI(e,t.fromCache,n,r)}}/** 890 * @license 891 * Copyright 2019 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 */class nC{constructor(){this.xi=!1}initialize(e,t){this.Ni=e,this.indexManager=t,this.xi=!0}getDocumentsMatchingQuery(e,t,n,r){return this.ki(e,t).next(s=>s||this.Oi(e,t,r,n)).next(n=>n||this.Mi(e,t))}ki(e,t){if(eJ(t))return z.resolve(null);let n=e0(t);return this.indexManager.getIndexType(e,n).next(r=>0===r?null:(null!==t.limit&&1===r&&(n=e0(t=e1(t,null,"F"))),this.indexManager.getDocumentsMatchingTarget(e,n).next(r=>{let s=tx(...r);return this.Ni.getDocuments(e,s).next(r=>this.indexManager.getMinOffset(e,n).next(n=>{let i=this.Fi(t,r);return this.$i(t,i,s,n.readTime)?this.ki(e,e1(t,null,"F")):this.Bi(e,i,t,n)}))})))}Oi(e,t,n,r){return eJ(t)||r.isEqual(F.min())?this.Mi(e,t):this.Ni.getDocuments(e,n).next(s=>{let i=this.Fi(t,s);return this.$i(t,i,n,r)?this.Mi(e,t):(m()<=o.in.DEBUG&&g("QueryEngine","Re-using previous result from %s to execute query: %s",r.toString(),e3(t)),this.Bi(e,i,t,function(e,t){let n=e.toTimestamp().seconds,r=e.toTimestamp().nanoseconds+1;return new K(F.fromTimestamp(1e9===r?new V(n+1,0):new V(n,r)),q.empty(),-1)}(r,0)))})}Fi(e,t){let n=new eB(e5(e));return t.forEach((t,r)=>{e9(e,r)&&(n=n.add(r))}),n}$i(e,t,n,r){if(null===e.limit)return!1;if(n.size!==t.size)return!0;let s="F"===e.limitType?t.last():t.first();return!!s&&(s.hasPendingWrites||s.version.compareTo(r)>0)}Mi(e,t){return m()<=o.in.DEBUG&&g("QueryEngine","Using full collection scan to execute query:",e3(t)),this.Ni.getDocumentsMatchingQuery(e,t,K.min())}Bi(e,t,n,r){return this.Ni.getDocumentsMatchingQuery(e,n,r).next(e=>(t.forEach(t=>{e=e.insert(t.key,t)}),e))}}/** 905 * @license 906 * Copyright 2020 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, softw
914are 915 * distributed under the License is distributed on an "AS IS" BASIS, 916 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 917 * See the License for the specific language governing permissions and 918 * limitations under the License. 919 */class nS{constructor(e,t,n,r){this.persistence=e,this.Li=t,this.yt=r,this.qi=new eU(L),this.Ui=new tA(e=>eW(e),eH),this.Ki=new Map,this.Gi=e.getRemoteDocumentCache(),this.Cs=e.getTargetCache(),this.Ns=e.getBundleCache(),this.Qi(n)}Qi(e){this.documentOverlayCache=this.persistence.getDocumentOverlayCache(e),this.indexManager=this.persistence.getIndexManager(e),this.mutationQueue=this.persistence.getMutationQueue(e,this.indexManager),this.localDocuments=new nh(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))}}async function nA(e,t){return await e.persistence.runTransaction("Handle user change","readonly",n=>{let r;return e.mutationQueue.getAllMutationBatches(n).next(s=>(r=s,e.Qi(t),e.mutationQueue.getAllMutationBatches(n))).next(t=>{let s=[],i=[],a=tx();for(let e of r)for(let t of(s.push(e.batchId),e.mutations))a=a.add(t.key);for(let e of t)for(let t of(i.push(e.batchId),e.mutations))a=a.add(t.key);return e.localDocuments.getDocuments(n,a).next(e=>({ji:e,removedBatchIds:s,addedBatchIds:i}))})})}function nN(e){return e.persistence.runTransaction("Get last remote snapshot version","readonly",t=>e.Cs.getLastRemoteSnapshotVersion(t))}async function nk(e,t,n){let r=e.qi.get(t);try{n||await e.persistence.runTransaction("Release target",n?"readwrite":"readwrite-primary",t=>e.persistence.referenceDelegate.removeTarget(t,r))}catch(e){if(!$(e))throw e;g("LocalStore",`Failed to update sequence numbers for target ${t}: ${e}`)}e.qi=e.qi.remove(t),e.Ui.delete(r.target)}function nb(e,t,n){let r=F.min(),s=tx();return e.persistence.runTransaction("Execute query","readonly",i=>(function(e,t,n){let r=e.Ui.get(n);return void 0!==r?z.resolve(e.qi.get(r)):e.Cs.getTargetData(t,n)})(e,i,e0(t)).next(t=>{if(t)return r=t.lastLimboFreeSnapshotVersion,e.Cs.getMatchingKeysForTargetId(i,t.targetId).next(e=>{s=e})}).next(()=>e.Li.getDocumentsMatchingQuery(i,t,n?r:F.min(),n?s:tx())).next(n=>{var r;let i;return r=t.collectionGroup||(t.path.length%2==1?t.path.lastSegment():t.path.get(t.path.length-2)),i=e.Ki.get(r)||F.min(),n.forEach((e,t)=>{t.readTime.compareTo(i)>0&&(i=t.readTime)}),e.Ki.set(r,i),{documents:n,Hi:s}}))}class nD{constructor(){this.activeTargetIds=tV}er(e){this.activeTargetIds=this.activeTargetIds.add(e)}nr(e){this.activeTargetIds=this.activeTargetIds.delete(e)}tr(){return JSON.stringify({activeTargetIds:this.activeTargetIds.toArray(),updateTimeMs:Date.now()})}}class n_{constructor(){this.Lr=new nD,this.qr={},this.onlineStateHandler=null,this.sequenceNumberHandler=null}addPendingMutation(e){}updateMutationState(e,t,n){}addLocalQueryTarget(e){return this.Lr.er(e),this.qr[e]||"not-current"}updateQueryState(e,t,n){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 nD,Promise.resolve()}handleUserChange(e,t,n){}setOnlineState(e){}shutdown(){}writeSequenceNumber(e){}notifyBundleLoaded(e){}}/** 920 * @license 921 * Copyright 2019 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 */class nR{Ur(e){}shutdown(){}}/** 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 */class nL{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(g("ConnectivityMonitor","Network connectivity changed: AVAILABLE"),this.Wr))e(0)}jr(){for(let e of(g("ConnectivityMonitor","Network connectivity changed: UNAVAILABLE"),this.Wr))e(1)}static C(){return"undefined"!=typeof window&&void 0!==window.addEventListener&&void 0!==window.removeEventListener}}/** 950 * @license 951 * Copyright 2020 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 nx={BatchGetDocuments:"batchGet",Commit:"commit",RunQuery:"runQuery",RunAggregationQuery:"runAggregationQuery"};/** 965 * @license 966 * Copyright 2017 Google LLC 967 * 968 * Licensed under the Apache License, Version 2.0 (the "License"); 969 * you may not use this file except in compliance with the License. 970 * You may obtain a copy of the License at 971 * 972 * http://www.apache.org/licenses/LICENSE-2.0 973 * 974 * Unless required by applicable law or agreed to in writing, software 975 * distributed under the License is distributed on an "AS IS" BASIS, 976 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 977 * See the License for the specific language governing permissions and 978 * limitations under the License. 979 */class nV{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)}}/** 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 */class nF 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,n,r,s){let i=this.ho(e,t);g("RestConnection","Sending: ",i,n);let a={};return this.lo(a,r,s),this.fo(e,i,a,n).then(e=>(g("RestConnection","Received: ",e),e),t=>{throw y("RestConnection",`${e} failed with error: `,t,"url: ",i,"request:",n),t})}_o(e,t,n,r,s,i){return this.ao(e,t,n,r,s)}lo(e,t,n){e["X-Goog-Api-Client"]="gl-js/ fire/"+d,e["Content-Type"]="text/plain",this.databaseInfo.appId&&(e["X-Firebase-GMPID"]=this.databaseInfo.appId),t&&t.headers.forEach((t,n)=>e[n]=t),n&&n.headers.forEach((t,n)=>e[n]=t)}ho(e,t){let n=nx[e];return`${this.oo}/v1/${t}:${n}`}}{constructor(e){super(e),this.forceLongPolling=e.forceLongPolling,this.autoDetectLongPolling=e.autoDetectLongPolling,this.useFetchStreams=e.useFetchStreams}fo(e,t,n,r){return new Promise((s,i)=>{let a=new u.JJ;a.setWithCredentials(!0),a.listenOnce(u.tw.COMPLETE,()=>{try{switch(a.getLastErrorCode()){case u.jK.NO_ERROR:let t=a.getResponseJson();g("Connection","XHR received:",JSON.stringify(t)),s(t);break;case u.jK.TIMEOUT:g("Connection",'RPC "'+e+'" timed out'),i(new T(E.DEADLINE_EXCEEDED,"Request time out"));break;case u.jK.HTTP_ERROR:let n=a.getStatus();if(g("Connection",'RPC "'+e+'" failed with status:',n,"response text:",a.getResponseText()),n>0){let e=a.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(E).indexOf(t)>=0?t:E.UNKNOWN}(t.status);i(new T(e,t.message))}else i(new T(E.UNKNOWN,"Server responded with status "+a.getStatus()))}else i(new T(E.UNAVAILABLE,"Connection failed."));break;default:w()}}finally{g("Connection",'RPC "'+e+'" completed.')}});let o=JSON.stringify(r);a.send(t,"POST",o,n,15)})}
994wo(e,t,n){let s=[this.oo,"/","google.firestore.v1.Firestore","/",e,"/channel"],i=(0,u.UE)(),a=(0,u.FJ)(),o={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&&(o.xmlHttpFactory=new u.zI({})),this.lo(o.initMessageHeaders,t,n),o.encodeInitMessageHeaders=!0;let l=s.join("");g("Connection","Creating WebChannel: "+l,o);let h=i.createWebChannel(l,o),c=!1,d=!1,f=new nV({Hr:e=>{d?g("Connection","Not sending because WebChannel is closed:",e):(c||(g("Connection","Opening WebChannel transport."),h.open(),c=!0),g("Connection","WebChannel sending:",e),h.send(e))},Jr:()=>h.close()}),m=(e,t,n)=>{e.listen(t,e=>{try{n(e)}catch(e){setTimeout(()=>{throw e},0)}})};return m(h,u.ii.EventType.OPEN,()=>{d||g("Connection","WebChannel transport opened.")}),m(h,u.ii.EventType.CLOSE,()=>{d||(d=!0,g("Connection","WebChannel transport closed"),f.io())}),m(h,u.ii.EventType.ERROR,e=>{d||(d=!0,y("Connection","WebChannel transport errored:",e),f.io(new T(E.UNAVAILABLE,"The operation could not be completed")))}),m(h,u.ii.EventType.MESSAGE,e=>{var t;if(!d){let n=e.data[0];n||w();let s=n.error||(null===(t=n[0])||void 0===t?void 0:t.error);if(s){g("Connection","WebChannel received error:",s);let e=s.status,t=function(e){let t=r[e];if(void 0!==t)return tS(t)}(e),n=s.message;void 0===t&&(t=E.INTERNAL,n="Unknown error status: "+e+" with message "+s.message),d=!0,f.io(new T(t,n)),h.close()}else g("Connection","WebChannel received:",n),f.ro(n)}}),m(a,u.ju.STAT_EVENT,e=>{e.stat===u.kN.PROXY?g("Connection","Detected buffering proxy"):e.stat===u.kN.NOPROXY&&g("Connection","Detected no buffering proxy")}),setTimeout(()=>{f.so()},0),f}}function nO(){return"undefined"!=typeof document?document:null}/** 995 * @license 996 * Copyright 2020 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 */function nM(e){return new tj(e,!0)}class nU{constructor(e,t,n=1e3,r=1.5,s=6e4){this.Hs=e,this.timerId=t,this.mo=n,this.yo=r,this.po=s,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()),n=Math.max(0,Date.now()-this.Eo),r=Math.max(0,t-n);r>0&&g("ExponentialBackoff",`Backing off for ${r} ms (base delay: ${this.Io} ms, delay with jitter: ${t} ms, last attempt: ${n} ms ago)`),this.To=this.Hs.enqueueAfterDelay(this.timerId,r,()=>(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}}/** 1010 * @license 1011 * Copyright 2017 Google LLC 1012 * 1013 * Licensed under the Apache License, Version 2.0 (the "License"); 1014 * you may not use this file except in compliance with the License. 1015 * You may obtain a copy of the License at 1016 * 1017 * http://www.apache.org/licenses/LICENSE-2.0 1018 * 1019 * Unless required by applicable law or agreed to in writing, software 1020 * distributed under the License is distributed on an "AS IS" BASIS, 1021 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1022 * See the License for the specific language governing permissions and 1023 * limitations under the License. 1024 */class nP{constructor(e,t,n,r,s,i,a,o){this.Hs=e,this.vo=n,this.Vo=r,this.connection=s,this.authCredentialsProvider=i,this.appCheckCredentialsProvider=a,this.listener=o,this.state=0,this.So=0,this.Do=null,this.Co=null,this.stream=null,this.xo=new nU(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===E.RESOURCE_EXHAUSTED?(p(t.toString()),p("Using maximum backoff delay to prevent overloading the backend."),this.xo.Ao()):t&&t.code===E.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,n])=>{this.So===t&&this.Go(e,n)},t=>{e(()=>{let e=new T(E.UNKNOWN,"Fetching auth token failed: "+t.message);return this.Qo(e)})})}Go(e,t){let n=this.Ko(this.So);this.stream=this.jo(e,t),this.stream.Yr(()=>{n(()=>(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=>{n(()=>this.Qo(e))}),this.stream.onMessage(e=>{n(()=>this.onMessage(e))})}Oo(){this.state=5,this.xo.Ro(async()=>{this.state=0,this.start()})}Qo(e){return g("PersistentStream",`close with error: ${e}`),this.stream=null,this.close(4,e)}Ko(e){return t=>{this.Hs.enqueueAndForget(()=>this.So===e?t():(g("PersistentStream","stream callback skipped by getCloseGuardedDispatcher."),Promise.resolve()))}}}class nq extends nP{constructor(e,t,n,r,s,i){super(e,"listen_stream_connection_backoff","listen_stream_idle","health_check_timeout",t,n,r,i),this.yt=s}jo(e,t){return this.connection.wo("Listen",e,t)}onMessage(e){this.xo.reset();let t=function(e,t){let n;if("targetChange"in t){var r,s;t.targetChange;let i="NO_CHANGE"===(r=t.targetChange.targetChangeType||"NO_CHANGE")?0:"ADD"===r?1:"REMOVE"===r?2:"CURRENT"===r?3:"RESET"===r?4:w(),a=t.targetChange.targetIds||[],o=(s=t.targetChange.resumeToken,e.wt?(void 0===s||"string"==typeof s||w(),ee.fromBase64String(s||"")):(void 0===s||s instanceof Uint8Array||w(),ee.fromUint8Array(s||new Uint8Array))),l=t.targetChange.cause;n=new tP(i,a,o,l&&new T(void 0===l.code?E.UNKNOWN:tS(l.code),l.message||"")||null)}else if("documentChange"in t){t.documentChange;let r=t.documentChange;r.document,r.document.name,r.document.updateTime;let s=t0(e,r.document.name),i=tY(r.document.updateTime),a=r.document.createTime?tY(r.document.createTime):F.min(),o=new eG({mapValue:{fields:r.document.fields}}),l=ez.newFoundDocument(s,i,a,o);n=new tM(r.targetIds||[],r.removedTargetIds||[],l.key,l)}else if("documentDelete"in t){t.documentDelete;let r=t.documentDelete;r.document;let s=t0(e,r.document),i=r.readTime?tY(r.readTime):F.min(),a=ez.newNoDocument(s,i);n=new tM([],r.removedTargetIds||[],a.key,a)}else if("documentRemove"in t){t.documentRemove;let r=t.documentRemove;r.document;let s=t0(e,r.document);n=new tM([],r.removedTargetIds||[],s,null)}else{if(!("filter"in t))return w();{t.filter;let e=t.filter;e.targetId;let r=new tC(e.count||0);n=new tU(e.targetId,r)}}return n}(this.yt,e),n=function(e){if(!("targetChange"in e))return F.min();let t=e.targetChange;return t.targetIds&&t.targetIds.length?F.min():t.readTime?tY(t.readTime):F.min()}(e);return this.listener.Wo(t,n)}zo(e){let t={};t.database=t2(this.yt),t.addTarget=function(e,t){let n;let r=t.target;return(n=eY(r)?{documents:{documents:[t1(e,r.path)]}}:{query:function(e,t){var n,r,s;let i={structuredQuery:{}},a=t.path;null!==t.collectionGroup?(i.parent=t1(e,a),i.structuredQuery.from=[{collectionId:t.collectionGroup,allDescendants:!0}]):(i.parent=t1(e,a.popLast()),i.structuredQuery.from=[{collectionId:a.lastSegment()}]);let o=function(e){if(0!==e.length)return function e(t){return t instanceof eA?function(e){if("=="===e.op){if(ey(e.value))return{unaryFilter:{field:t9(e.field),op:"IS_NAN"}};if(ep(e.value))return{unaryFilter:{field:t9(e.field),op:"IS_NULL"}}}else if("!="===e.op){if(ey(e.value))return{unaryFilter:{field:t9(e.field),op:"IS_NOT_NA
1024N"}};if(ep(e.value))return{unaryFilter:{field:t9(e.field),op:"IS_NOT_NULL"}}}return{fieldFilter:{field:t9(e.field),op:tz[e.op],value:e.value}}}(t):t instanceof eN?function(t){let n=t.getFilters().map(t=>e(t));return 1===n.length?n[0]:{compositeFilter:{op:t$[t.op],filters:n}}}(t):w()}(eN.create(e,"and"))}(t.filters);o&&(i.structuredQuery.where=o);let l=function(e){if(0!==e.length)return e.map(e=>({field:t9(e.field),direction:tG[e.dir]}))}(t.orderBy);l&&(i.structuredQuery.orderBy=l);let u=(r=t.limit,e.wt||null==r?r:{value:r});return null!==u&&(i.structuredQuery.limit=u),t.startAt&&(i.structuredQuery.startAt={before:(n=t.startAt).inclusive,values:n.position}),t.endAt&&(i.structuredQuery.endAt={before:!(s=t.endAt).inclusive,values:s.position}),i}(e,r)}).targetId=t.targetId,t.resumeToken.approximateByteSize()>0?n.resumeToken=tH(e,t.resumeToken):t.snapshotVersion.compareTo(F.min())>0&&(n.readTime=tW(e,t.snapshotVersion.toTimestamp())),n}(this.yt,e);let n=function(e,t){let n=function(e,t){switch(t){case 0:return null;case 1:return"existence-filter-mismatch";case 2:return"limbo-document";default:return w()}}(0,t.purpose);return null==n?null:{"goog-listen-tags":n}}(this.yt,e);n&&(t.labels=n),this.Bo(t)}Ho(e){let t={};t.database=t2(this.yt),t.removeTarget=e,this.Bo(t)}}class nB extends nP{constructor(e,t,n,r,s,i){super(e,"write_stream_connection_backoff","write_stream_idle","health_check_timeout",t,n,r,i),this.yt=s,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){var t,n;if(e.streamToken||w(),this.lastStreamToken=e.streamToken,this.Jo){this.xo.reset();let r=(t=e.writeResults,n=e.commitTime,t&&t.length>0?(void 0!==n||w(),t.map(e=>{let t;return(t=e.updateTime?tY(e.updateTime):tY(n)).isEqual(F.min())&&(t=tY(n)),new tu(t,e.transformResults||[])})):[]),s=tY(e.commitTime);return this.listener.Zo(s,r)}return e.writeResults&&0!==e.writeResults.length&&w(),this.Jo=!0,this.listener.tu()}eu(){let e={};e.database=t2(this.yt),this.Bo(e)}Xo(e){let t={streamToken:this.lastStreamToken,writes:e.map(e=>(function(e,t){var n;let r;
1024if(t instanceof tp)r={update:t3(e,t.key,t.value)};else if(t instanceof tT)r={delete:tZ(e,t.key)};else if(t instanceof ty)r={update:t3(e,t.key,t.data),updateMask:function(e){let t=[];return e.fields.forEach(e=>t.push(e.canonicalString())),{fieldPaths:t}}(t.fieldMask)};else{if(!(t instanceof tI))return w();r={verify:tZ(e,t.key)}}return t.fieldTransforms.length>0&&(r.updateTransforms=t.fieldTransforms.map(e=>(function(e,t){let n=t.transform;if(n instanceof tt)return{fieldPath:t.field.canonicalString(),setToServerValue:"REQUEST_TIME"};if(n instanceof tn)return{fieldPath:t.field.canonicalString(),appendMissingElements:{values:n.elements}};if(n instanceof ts)return{fieldPath:t.field.canonicalString(),removeAllFromArray:{values:n.elements}};if(n instanceof ta)return{fieldPath:t.field.canonicalString(),increment:n.gt};throw w()})(0,e))),t.precondition.isNone||(r.currentDocument=void 0!==(n=t.precondition).updateTime?{updateTime:tW(e,n.updateTime.toTimestamp())}:void 0!==n.exists?{exists:n.exists}:w()),r})(this.yt,e))};this.Bo(t)}}/** 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 */class nK extends class{}{constructor(e,t,n,r){super(),this.authCredentials=e,this.appCheckCredentials=t,this.connection=n,this.yt=r,this.nu=!1}su(){if(this.nu)throw new T(E.FAILED_PRECONDITION,"The client has already been terminated.")}ao(e,t,n){return this.su(),Promise.all([this.authCredentials.getToken(),this.appCheckCredentials.getToken()]).then(([r,s])=>this.connection.ao(e,t,n,r,s)).catch(e=>{throw"FirebaseError"===e.name?(e.code===E.UNAUTHENTICATED&&(this.authCredentials.invalidateToken(),this.appCheckCredentials.invalidateToken()),e):new T(E.UNKNOWN,e.toString())})}_o(e,t,n,r){return this.su(),Promise.all([this.authCredentials.getToken(),this.appCheckCredentials.getToken()]).then(([s,i])=>this.connection._o(e,t,n,s,i,r)).catch(e=>{throw"FirebaseError"===e.name?(e.code===E.UNAUTHENTICATED&&(this.authCredentials.invalidateToken(),this.appCheckCredentials.invalidateToken()),e):new T(E.UNKNOWN,e.toString())})}terminate(){this.nu=!0}}class nQ{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} 1040This 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?(p(t),this.ou=!1):g("OnlineStateTracker",t)}lu(){null!==this.ru&&(this.ru.cancel(),this.ru=null)}}/** 1041 * @license 1042 * Copyright 2017 Google LLC 1043 * 1044 * Licensed under the Apache License, Version 2.0 (the "License"); 1045 * you may not use this file except in compliance with the License. 1046 * You may obtain a copy of the License at 1047 * 1048 * http://www.apache.org/licenses/LICENSE-2.0 1049 * 1050 * Unless required by applicable law or agreed to in writing, software 1051 * distributed under the License is distributed on an "AS IS" BASIS, 1052 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1053 * See the License for the specific language governing permissions and 1054 * limitations under the License.
1055 */class nG{constructor(e,t,n,r,s){this.localStore=e,this.datastore=t,this.asyncQueue=n,this.remoteSyncer={},this.fu=[],this.du=new Map,this._u=new Set,this.wu=[],this.mu=s,this.mu.Ur(e=>{n.enqueueAndForget(async()=>{nZ(this)&&(g("RemoteStore","Restarting streams for network reachability change."),await async function(e){e._u.add(4),await n$(e),e.gu.set("Unknown"),e._u.delete(4),await nz(e)}(this))})}),this.gu=new nQ(n,r)}}async function nz(e){if(nZ(e))for(let t of e.wu)await t(!0)}async function n$(e){for(let t of e.wu)await t(!1)}function nj(e,t){e.du.has(t.targetId)||(e.du.set(t.targetId,t),nJ(e)?nX(e):rs(e).ko()&&nH(e,t))}function nW(e,t){let n=rs(e);e.du.delete(t),n.ko()&&nY(e,t),0===e.du.size&&(n.ko()?n.Fo():nZ(e)&&e.gu.set("Unknown"))}function nH(e,t){e.yu.Ot(t.targetId),rs(e).zo(t)}function nY(e,t){e.yu.Ot(t),rs(e).Ho(t)}function nX(e){e.yu=new tB({getRemoteKeysForTarget:t=>e.remoteSyncer.getRemoteKeysForTarget(t),ne:t=>e.du.get(t)||null}),rs(e).start(),e.gu.uu()}function nJ(e){return nZ(e)&&!rs(e).No()&&e.du.size>0}function nZ(e){return 0===e._u.size}async function n0(e){e.du.forEach((t,n)=>{nH(e,t)})}async function n1(e,t){e.yu=void 0,nJ(e)?(e.gu.hu(t),nX(e)):e.gu.set("Unknown")}async function n2(e,t,n){if(e.gu.set("Online"),t instanceof tP&&2===t.state&&t.cause)try{await async function(e,t){let n=t.cause;for(let r of t.targetIds)e.du.has(r)&&(await e.remoteSyncer.rejectListen(r,n),e.du.delete(r),e.yu.removeTarget(r))}(e,t)}catch(n){g("RemoteStore","Failed to remove targets %s: %s ",t.targetIds.join(","),n),await n4(e,n)}else if(t instanceof tM?e.yu.Kt(t):t instanceof tU?e.yu.Jt(t):e.
1055yu.jt(t),!n.isEqual(F.min()))try{let t=await nN(e.localStore);n.compareTo(t)>=0&&await function(e,t){let n=e.yu.Zt(t);return n.targetChanges.forEach((n,r)=>{if(n.resumeToken.approximateByteSize()>0){let s=e.du.get(r);s&&e.du.set(r,s.withResumeToken(n.resumeToken,t))}}),n.targetMismatches.forEach(t=>{let n=e.du.get(t);if(!n)return;e.du.set(t,n.withResumeToken(ee.EMPTY_BYTE_STRING,n.snapshotVersion)),nY(e,t);let r=new nt(n.target,t,1,n.sequenceNumber);nH(e,r)}),e.remoteSyncer.applyRemoteEvent(n)}(e,n)}catch(t){g("RemoteStore","Failed to raise snapshot:",t),await n4(e,t)}}async function n4(e,t,n){if(!$(t))throw t;e._u.add(1),await n$(e),e.gu.set("Offline"),n||(n=()=>nN(e.localStore)),e.asyncQueue.enqueueRetryable(async()=>{g("RemoteStore","Retrying IndexedDB access"),await n(),e._u.delete(1),await nz(e)})}function n3(e,t){return t().catch(n=>n4(e,n,t))}async function n9(e){let t=ri(e),n=e.fu.length>0?e.fu[e.fu.length-1].batchId:-1;for(;nZ(e)&&e.fu.length<10;)try{let r=await function(e,t){return e.persistence.runTransaction("Get next mutation batch","readonly",n=>(void 0===t&&(t=-1),e.mutationQueue.getNextMutationBatchAfterBatchId(n,t)))}(e.localStore,n);if(null===r){0===e.fu.length&&t.Fo();break}n=r.batchId,function(e,t){e.fu.push(t);let n=ri(e);n.ko()&&n.Yo&&n.Xo(t.mutations)}(e,r)}catch(t){await n4(e,t)}n5(e)&&n6(e)}function n5(e){return nZ(e)&&!ri(e).No()&&e.fu.length>0}function n6(e){ri(e).start()}async function n8(e){ri(e).eu()}async function n7(e){let t=ri(e);for(let n of e.fu)t.Xo(n.mutations)}async function re(e,t,n){let r=e.fu.shift(),s=t7.from(r,t,n);await n3(e,()=>e.remoteSyncer.applySuccessfulWrite(s)),await n9(e)}async function rt(e,t){t&&ri(e).Yo&&await async function(e,t){var n;if(function(e){switch(e){default:return w();case E.CANCELLED:case E.UNKNOWN:case E.DEADLINE_EXCEEDED:case E.RESOURCE_EXHAUSTED:case E.INTERNAL:case E.UNAVAILABLE:case E.UNAUTHENTICATED:return!1;case E.INVALID_ARGUMENT:case E.NOT_FOUND:case E.ALREADY_EXISTS:case E.PERMISSION_DENIED:case E.FAILED_PRECONDITION:case E.ABORTED:case E.OUT_OF_RANGE:case E.UNIMPLEMENTED:case E.DATA_LOSS:return!0}}(n=t.code)&&n!==E.ABORTED){let n=e.fu.shift();ri(e).Mo(),await n3(e,()=>e.remoteSyncer.rejectFailedWrite(n.batchId,t)),await n9(e)}}(e,t),n5(e)&&n6(e)}async function rn(e,t){e.asyncQueue.verifyOperationInProgress(),g("RemoteStore","RemoteStore received new credentials");let n=nZ(e);e._u.add(3),await n$(e),n&&e.gu.set("Unknown"),await e.remoteSyncer.handleCredentialChange(t),e._u.delete(3),await nz(e)}async function rr(e,t){t?(e._u.delete(2),await nz(e)):t||(e._u.add(2),await n$(e),e.gu.set("Unknown"))}function rs(e){var t,n,r;return e.pu||(e.pu=(t=e.datastore,n=e.asyncQueue,r={Yr:n0.bind(null,e),Zr:n1.bind(null,e),Wo:n2.bind(null,e)},t.su(),new nq(n,t.connection,t.authCredentials,t.appCheckCredentials,t.yt,r)),e.wu.push(async t=>{t?(e.pu.Mo(),nJ(e)?nX(e):e.gu.set("Unknown")):(await e.pu.stop(),e.yu=void 0)})),e.pu}function ri(e){var t,n,r;return e.Iu||(e.Iu=(t=e.datastore,n=e.asyncQueue,r={Yr:n8.bind(null,e),Zr:rt.bind(null,e),tu:n7.bind(null,e),Zo:re.bind(null,e)},t.su(),new nB(n,t.connection,t.authCredentials,t.appCheckCredentials,t.yt,r)),e.wu.push(async t=>{t?(e.Iu.Mo(),await n9(e)):(await e.Iu.stop(),e.fu.length>0&&(g("RemoteStore",`Stopping write stream with ${e.fu.length} pending writes`),e.fu=[]))})),e.Iu}/** 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 */class ra{constructor(e,t,n,r,s){this.asyncQueue=e,this.timerId=t,this.targetTimeMs=n,this.op=r,this.removalCallback=s,this.deferred=new I,this.then=this.deferred.promise.then.bind(this.deferred.promise),this.deferred.promise.catch(e=>{})}
1070static createAndSchedule(e,t,n,r,s){let i=new ra(e,t,Date.now()+n,r,s);return i.start(n),i}start(e){this.timerHandle=setTimeout(()=>this.handleDelayElapsed(),e)}skipDelay(){return this.handleDelayElapsed()}cancel(e){null!==this.timerHandle&&(this.clearTimeout(),this.deferred.reject(new T(E.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 ro(e,t){if(p("AsyncQueue",`${t}: ${e}`),$(e))return new T(E.UNAVAILABLE,`${t}: ${e}`);throw e}/** 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 */class rl{constructor(e){this.comparator=e?(t,n)=>e(t,n)||q.comparator(t.key,n.key):(e,t)=>q.comparator(e.key,t.key),this.keyedMap=tb(),this.sortedSet=new eU(this.comparator)}static emptySet(e){return new rl(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,n)=>(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 rl)||this.size!==e.size)return!1;let t=this.sortedSet.getIterator(),n=e.sortedSet.getIterator();for(;t.hasNext();){let e=t.getNext().key,r=n.getNext().key;if(!e.isEqual(r))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 n=new rl;return n.comparator=this.comparator,n.keyedMap=e,n.sortedSet=t,n}}/** 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 */class ru{constructor(){this.Tu=new eU(q.comparator)}track(e){let t=e.doc.key,n=this.Tu.get(t);n?0!==e.type&&3===n.type?this.Tu=this.Tu.insert(t,e):3===e.type&&1!==n.type?this.Tu=this.Tu.insert(t,{type:n.type,doc:e.doc}):2===e.type&&2===n.type?this.Tu=this.Tu.insert(t,{type:2,doc:e.doc}):2===e.type&&0===n.type?this.Tu=this.Tu.insert(t,{type:0,doc:e.doc}):1===e.type&&0===n.type?this.Tu=this.Tu.remove(t):1===e.type&&2===n.type?this.Tu=this.Tu.insert(t,{type:1,doc:n.doc}):0===e.type&&1===n.type?this.Tu=this.Tu.insert(t,{type:2,doc:e.doc}):w():this.Tu=this.Tu.insert(t,e)}Eu(){let e=[];return this.Tu.inorderTraversal((t,n)=>{e.push(n)}),e}}class rh{constructor(e,t,n,r,s,i,a,o,l){this.query=e,this.docs=t,this.oldDocs=n,this.docChanges=r,this.mutatedKeys=s,this.fromCache=i,this.syncStateChanged=a,this.excludesMetadataChanges=o,this.hasCachedResults=l}static fromInitialDocuments(e,t,n,r,s){let i=[];
1100return t.forEach(e=>{i.push({type:0,doc:e})}),new rh(e,t,rl.emptySet(t),i,n,r,!0,!1,s)}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)&&e2(this.query,e.query)&&this.docs.isEqual(e.docs)&&this.oldDocs.isEqual(e.oldDocs)))return!1;let t=this.docChanges,n=e.docChanges;if(t.length!==n.length)return!1;for(let e=0;e<t.length;e++)if(t[e].type!==n[e].type||!t[e].doc.isEqual(n[e].doc))return!1;return!0}}/** 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 */class rc{constructor(){this.Au=void 0,this.listeners=[]}}class rd{constructor(){this.queries=new tA(e=>e4(e),e2),this.onlineState="Unknown",this.Ru=new Set}}async function rf(e,t){let n=t.query,r=!1,s=e.queries.get(n);if(s||(r=!0,s=new rc),r)try{s.Au=await e.onListen(n)}catch(n){let e=ro(n,`Initialization of query '${e3(t.query)}' failed`);return void t.onError(e)}e.queries.set(n,s),s.listeners.push(t),t.bu(e.onlineState),s.Au&&t.Pu(s.Au)&&ry(e)}async function rm(e,t){let n=t.query,r=!1,s=e.queries.get(n);if(s){let e=s.listeners.indexOf(t);e>=0&&(s.listeners.splice(e,1),r=0===s.listeners.length)}if(r)return e.queries.delete(n),e.onUnlisten(n)}function rg(e,t){let n=!1;for(let r of t){let t=r.query,s=e.queries.get(t);if(s){for(let e of s.listeners)e.Pu(r)&&(n=!0);s.Au=r}}n&&ry(e)}function rp(e,t,n){let r=e.queries.get(t);if(r)for(let e of r.listeners)e.onError(n);e.queries.delete(t)}function ry(e){e.Ru.forEach(e=>{e.next()})}class rv{constructor(e,t,n){this.query=e,this.vu=t,this.Vu=!1,this.Su=null,this.onlineState="Unknown",this.options=n||{}}Pu(e){if(!this.options.includeMetadataChanges){let t=[];for(let n of e.docChanges)3!==n.type&&t.push(n);e=new rh(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=rh.fromInitialDocuments(e.query,e.docs,e.mutatedKeys,e.fromCache,e.hasCachedResults),this.Vu=!0,this.vu.next(e)}}/** 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 */class rw{constructor(e){this.key=e}}class rE{constructor(e){this.key=e}}class rT{constructor(e,t){this.query=e,this.qu=t,this.Uu=null,this.hasCachedResults=!1,this.current=!1,this.Ku=tx(),this.mutatedKeys=tx(),this.Gu=e5(e),this.Qu=new rl(this.Gu)}get ju(){return this.qu}Wu(e,t){let n=t?t.zu:new ru,r=t?t.Qu:this.Qu,s=t?t.mutatedKeys:this.mutatedKeys,i=r,a=!1,o="F"===this.query.limitType&&r.size===this.query.limit?r.last():null,l="L"===this.query.limitType&&r.size===this.query.limit?r.first():null;if(e.inorderTraversal((e,t)=>
1130{let u=r.get(e),h=e9(this.query,t)?t:null,c=!!u&&this.mutatedKeys.has(u.key),d=!!h&&(h.hasLocalMutations||this.mutatedKeys.has(h.key)&&h.hasCommittedMutations),f=!1;u&&h?u.data.isEqual(h.data)?c!==d&&(n.track({type:3,doc:h}),f=!0):this.Hu(u,h)||(n.track({type:2,doc:h}),f=!0,(o&&this.Gu(h,o)>0||l&&0>this.Gu(h,l))&&(a=!0)):!u&&h?(n.track({type:0,doc:h}),f=!0):u&&!h&&(n.track({type:1,doc:u}),f=!0,(o||l)&&(a=!0)),f&&(h?(i=i.add(h),s=d?s.add(e):s.delete(e)):(i=i.delete(e),s=s.delete(e)))}),null!==this.query.limit)for(;i.size>this.query.limit;){let e="F"===this.query.limitType?i.last():i.first();i=i.delete(e.key),s=s.delete(e.key),n.track({type:1,doc:e})}return{Qu:i,zu:n,$i:a,mutatedKeys:s}}Hu(e,t){return e.hasLocalMutations&&t.hasCommittedMutations&&!t.hasLocalMutations}applyChanges(e,t,n){let r=this.Qu;this.Qu=e.Qu,this.mutatedKeys=e.mutatedKeys;let s=e.zu.Eu();s.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 w()}};return n(e)-n(t)})(e.type,t.type)||this.Gu(e.doc,t.doc)),this.Ju(n);let i=t?this.Yu():[],a=0===this.Ku.size&&this.current?1:0,o=a!==this.Uu;return(this.Uu=a,0!==s.length||o)?{snapshot:new rh(this.query,e.Qu,r,s,e.mutatedKeys,0===a,o,!1,!!n&&n.resumeToken.approximateByteSize()>0),Xu:i}:{Xu:i}}bu(e){return this.current&&"Offline"===e?(this.current=!1,this.applyChanges({Qu:this.Qu,zu:new ru,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=tx(),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 rE(e))}),this.Ku.forEach(n=>{e.has(n)||t.push(new rw(n))}),t}tc(e){this.qu=e.Hi,this.Ku=tx();let t=this.Wu(e.documents);return this.applyChanges(t,!0)}ec(){return rh.fromInitialDocuments(this.query,this.Qu,this.mutatedKeys,0===this.Uu,this.hasCachedResults)}}class rI{constructor(e,t,n){this.query=e,this.targetId=t,this.view=n}}class rC{constructor(e){this.key=e,this.nc=!1}}class rS{constructor(e,t,n,r,s,i){this.localStore=e,this.remoteStore=t,this.eventManager=n,this.sharedClientState=r,this.currentUser=s,this.maxConcurrentLimboResolutions=i,this.sc={},this.ic=new tA(e=>e4(e),e2),this.rc=new Map,this.oc=new Set,this.uc=new eU(q.comparator),this.cc=new Map,this.ac=new nf,this.hc={},this.lc=new Map,this.fc=no.vn(),this.onlineState="Unknown",this.dc=void 0}get isPrimaryClient(){return!0===this.dc}}async function rA(e,t){var n,r;let s,i;let a=(e.remoteStore.remoteSyncer.applyRemoteEvent=rD.bind(null,e),e.remoteStore.remoteSyncer.getRemoteKeysForTarget=rK.bind(null,e),e.remoteStore.remoteSyncer.rejectListen=rR.bind(null,e),e.sc.Wo=rg.bind(null,e.eventManager),e.sc.wc=rp.bind(null,e.eventManager),e),o=a.ic.get(t);if(o)s=o.targetId,a.sharedClientState.addLocalQueryTarget(s),i=o.view.ec();else{let e=await (n=a.localStore,r=e0(t),n.persistence.runTransaction("Allocate target","readwrite",e=>{let t;return n.Cs.getTargetData(e,r).next(s=>s?(t=s,z.resolve(t)):n.Cs.allocateTargetId(e).next(s=>(t=new nt(r,s,0,e.currentSequenceNumber),n.Cs.addTargetData(e,t).next(()=>t))))}).then(e=>{let t=n.qi.get(e.targetId);return(null===t||e.snapshotVersion.compareTo(t.snapshotVersion)>0)&&(n.qi=n.qi.insert(e.targetId,e),n.Ui.set(r,e.targetId)),e}));a.isPrimaryClient&&nj(a.remoteStore,e);let o=a.sharedClientState.addLocalQueryTarget(e.targetId);s=e.targetId,i=await rN(a,t,s,"current"===o,e.resumeToken)}return i}async function rN(e,t,n,r,s){e._c=(t,n,r)=>(async function(e,t,n,r){let s=t.view.Wu(n);s.$i&&(s=await nb(e.localStore,t.query,!1).then(({documents:e})=>t.view.Wu(e,s)));let i=r&&r.targetChanges.get(t.targetId),a=t.view.applyChanges(s,e.isPrimaryClient,i);return rU(e,t.targetId,a.Xu),a.snapshot})(e,t,n,r);let i=await nb(e.localStore,t,!0),a=new rT(t,i.Hi),o=a.Wu(i.documents),l=tO.createSynthesizedTargetChangeForCurrentChange(n,r&&"Offline"!==e.onlineState,s),u=a.applyChanges(o,e.isPrimaryClient,l);rU(e,n,u.Xu);let h=new rI(t,n,a);return e.ic.set(t,h),e.rc.has(n)?e.rc.get(n).push(t):e.rc.set(n,[t]),u.snapshot}async function rk(e,t){let n=e.ic.get(t),r=e.rc.get(n.targetId);if(r.length>1)return e.rc.set(n.targetId,r.filter(e=>!e2(e,t))),void e.ic.delete(t);
1130e.isPrimaryClient?(e.sharedClientState.removeLocalQueryTarget(n.targetId),e.sharedClientState.isActiveQueryTarget(n.targetId)||await nk(e.localStore,n.targetId,!1).then(()=>{e.sharedClientState.clearQueryState(n.targetId),nW(e.remoteStore,n.targetId),rO(e,n.targetId)}).catch(G)):(rO(e,n.targetId),await nk(e.localStore,n.targetId,!0))}async function rb(e,t,n){var r;let s=(e.remoteStore.remoteSyncer.applySuccessfulWrite=rL.bind(null,e),e.remoteStore.remoteSyncer.rejectFailedWrite=rx.bind(null,e),e);try{let e;let i=await function(e,t){let n,r;let s=V.now(),i=t.reduce((e,t)=>e.add(t.key),tx());return e.persistence.runTransaction("Locally write mutations","readwrite",a=>{let o=tN,l=tx();return e.Gi.getEntries(a,i).next(e=>{(o=e).forEach((e,t)=>{t.isValidDocument()||(l=l.add(e))})}).next(()=>e.localDocuments.getOverlayedDocuments(a,o)).next(r=>{n=r;let i=[];for(let e of t){let t=function(e,t){let n=null;for(let r of e.fieldTransforms){let e=t.data.field(r.field),s=te(r.transform,e||null);null!=s&&(null===n&&(n=eG.empty()),n.set(r.field,s))}return n||null}(e,n.get(e.key).overlayedDocument);null!=t&&i.push(new ty(e.key,t,function e(t){let n=[];return X(t.fields,(t,r)=>{let s=new P([t]);if(ev(r)){let t=e(r.mapValue).fields;if(0===t.length)n.push(s);else for(let e of t)n.push(s.child(e))}else n.push(s)}),new eQ(n)}(t.value.mapValue),th.exists(!0)))}return e.mutationQueue.addMutationBatch(a,s,i,t)}).next(t=>{r=t;let s=t.applyToLocalDocumentSet(n,l);return e.documentOverlayCache.saveOverlays(a,t.batchId,s)})}).then(()=>({batchId:r.batchId,changes:tD(n)}))}(s.localStore,t);s.sharedClientState.addPendingMutation(i.batchId),r=i.batchId,(e=s.hc[s.currentUser.toKey()])||(e=new eU(L)),e=e.insert(r,n),s.hc[s.currentUser.toKey()]=e,await rq(s,i.changes),await n9(s.remoteStore)}catch(t){let e=ro(t,"Failed to persist write");n.reject(e)}}async function rD(e,t){try{let n=await function(e,t){let n=t.snapshotVersion,r=e.qi;return e.persistence.runTransaction("Apply remote event","readwrite-primary",s=>{var i;let a,o;let l=e.Gi.newChangeBuffer({trackRemovals:!0});r=e.qi;let u=[];
1130t.targetChanges.forEach((i,a)=>{var o;let l=r.get(a);if(!l)return;u.push(e.Cs.removeMatchingKeys(s,i.removedDocuments,a).next(()=>e.Cs.addMatchingKeys(s,i.addedDocuments,a)));let h=l.withSequenceNumber(s.currentSequenceNumber);t.targetMismatches.has(a)?h=h.withResumeToken(ee.EMPTY_BYTE_STRING,F.min()).withLastLimboFreeSnapshotVersion(F.min()):i.resumeToken.approximateByteSize()>0&&(h=h.withResumeToken(i.resumeToken,n)),r=r.insert(a,h),o=h,(0===l.resumeToken.approximateByteSize()||o.snapshotVersion.toMicroseconds()-l.snapshotVersion.toMicroseconds()>=3e8||i.addedDocuments.size+i.modifiedDocuments.size+i.removedDocuments.size>0)&&u.push(e.Cs.updateTargetData(s,h))});let h=tN,c=tx();if(t.documentUpdates.forEach(n=>{t.resolvedLimboDocuments.has(n)&&u.push(e.persistence.referenceDelegate.updateLimboDocument(s,n))}),u.push((i=t.documentUpdates,a=tx(),o=tx(),i.forEach(e=>a=a.add(e)),l.getEntries(s,a).next(e=>{let t=tN;return i.forEach((n,r)=>{let s=e.get(n);r.isFoundDocument()!==s.isFoundDocument()&&(o=o.add(n)),r.isNoDocument()&&r.version.isEqual(F.min())?(l.removeEntry(n,r.readTime),t=t.insert(n,r)):!s.isValidDocument()||r.version.compareTo(s.version)>0||0===r.version.compareTo(s.version)&&s.hasPendingWrites?(l.addEntry(r),t=t.insert(n,r)):g("LocalStore","Ignoring outdated watch update for ",n,". Current version:",s.version," Watch version:",r.version)}),{Wi:t,zi:o}})).next(e=>{h=e.Wi,c=e.zi})),!n.isEqual(F.min())){let t=e.Cs.getLastRemoteSnapshotVersion(s).next(t=>e.Cs.setTargetsMetadata(s,s.currentSequenceNumber,n));u.push(t)}return z.waitFor(u).next(()=>l.apply(s)).next(()=>e.localDocuments.getLocalViewOfDocuments(s,h,c)).next(()=>h)}).then(t=>(e.qi=r,t))}(e.localStore,t);
1130t.targetChanges.forEach((t,n)=>{let r=e.cc.get(n);r&&(t.addedDocuments.size+t.modifiedDocuments.size+t.removedDocuments.size<=1||w(),t.addedDocuments.size>0?r.nc=!0:t.modifiedDocuments.size>0?r.nc||w():t.removedDocuments.size>0&&(r.nc||w(),r.nc=!1))}),await rq(e,n,t)}catch(e){await G(e)}}function r_(e,t,n){var r;if(e.isPrimaryClient&&0===n||!e.isPrimaryClient&&1===n){let n;let s=[];e.ic.forEach((e,n)=>{let r=n.view.bu(t);r.snapshot&&s.push(r.snapshot)}),(r=e.eventManager).onlineState=t,n=!1,r.queries.forEach((e,r)=>{for(let e of r.listeners)e.bu(t)&&(n=!0)}),n&&ry(r),s.length&&e.sc.Wo(s),e.onlineState=t,e.isPrimaryClient&&e.sharedClientState.setOnlineState(t)}}async function rR(e,t,n){e.sharedClientState.updateQueryState(t,"rejected",n);let r=e.cc.get(t),s=r&&r.key;if(s){let n=new eU(q.comparator);n=n.insert(s,ez.newNoDocument(s,F.min()));let r=tx().add(s),i=new tF(F.min(),new Map,new eB(L),n,r);await rD(e,i),e.uc=e.uc.remove(s),e.cc.delete(t),rP(e)}else await nk(e.localStore,t,!1).then(()=>rO(e,t,n)).catch(G)}async function rL(e,t){var n;let r=t.batch.batchId;try{let s=await (n=e.localStore).persistence.runTransaction("Acknowledge batch","readwrite-primary",e=>{let r=t.batch.keys(),s=n.Gi.newChangeBuffer({trackRemovals:!0});return(function(e,t,n,r){let s=n.batch,i=s.keys(),a=z.resolve();return i.forEach(e=>{a=a.next(()=>r.getEntry(t,e)).next(t=>{let i=n.docVersions.get(e);null!==i||w(),0>t.version.compareTo(i)&&(s.applyToRemoteDocument(t,n),t.isValidDocument()&&(t.setReadTime(n.commitVersion),r.addEntry(t)))})}),a.next(()=>e.mutationQueue.removeMutationBatch(t,s))})(n,e,t,s).next(()=>s.apply(e)).next(()=>n.mutationQueue.performConsistencyCheck(e)).next(()=>n.documentOverlayCache.removeOverlaysForBatchId(e,r,t.batch.batchId)).next(()=>n.localDocuments.recalculateAndSaveOverlaysForDocumentKeys(e,function(e){let t=tx();for(let n=0;n<e.mutationResults.length;++n)e.mutationResults[n].transformResults.length>0&&(t=t.add(e.batch.mutations[n].key));return t}(t))).next(()=>n.localDocuments.getDocuments(e,r))});rF(e,r,null),rV(e,r),e.sharedClientState.updateMutationState(r,"acknowledged"),await rq(e,s)}catch(e){await G(e)}}async function rx(e,t,n){var r;try{let s=await (r=e.localStore).persistence.runTransaction("Reject batch","readwrite-primary",e=>{let n;return r.mutationQueue.lookupMutationBatch(e,t).next(t=>(null!==t||w(),n=t.keys(),r.mutationQueue.removeMutationBatch(e,t))).next(()=>r.mutationQueue.performConsistencyCheck(e)).next(()=>r.documentOverlayCache.removeOverlaysForBatchId(e,n,t)).next(()=>r.localDocuments.recalculateAndSaveOverlaysForDocumentKeys(e,n)).next(()=>r.localDocuments.getDocuments(e,n))});rF(e,t,n),rV(e,t),e.sharedClientState.updateMutationState(t,"rejected",n),await rq(e,s)}catch(e){await G(e)}}function rV(e,t){(e.lc.get(t)||[]).forEach(e=>{e.resolve()}),e.lc.delete(t)}function rF(e,t,n){let r=e.hc[e.currentUser.toKey()];if(r){let s=r.get(t);s&&(n?s.reject(n):s.resolve(),r=r.remove(t)),e.hc[e.currentUser.toKey()]=r}}function rO(e,t,n=null){for(let r of(e.sharedClientState.removeLocalQueryTarget(t),e.rc.get(t)))e.ic.delete(r),n&&e.sc.wc(r,n);e.rc.delete(t),e.isPrimaryClient&&e.ac.ls(t).forEach(t=>{e.ac.containsKey(t)||rM(e,t)})}function rM(e,t){e.oc.delete(t.path.canonicalString());let n=e.uc.get(t);null!==n&&(nW(e.remoteStore,n),e.uc=e.uc.remove(t),e.cc.delete(n),rP(e))}function rU(e,t,n){for(let r of n)r instanceof rw?(e.ac.addReference(r.key,t),function(e,t){let n=t.key,r=n.path.canonicalString();e.uc.get(n)||e.oc.has(r)||(g("SyncEngine","New document in limbo: "+n),e.oc.add(r),rP(e))}(e,r)):r instanceof rE?(g("SyncEngine","Document no longer in limbo: "+r.key),e.ac.removeReference(r.key,t),e.ac.containsKey(r.key)||rM(e,r.key)):w()}function rP(e){for(;e.oc.size>0&&e.uc.size<e.maxConcurrentLimboResolutions;){let t=e.oc.values().next().value;e.oc.delete(t);let n=new q(M.fromString(t)),r=e.fc.next();e.cc.set(r,new rC(n)),e.uc=e.uc.insert(n,r),nj(e.remoteStore,new nt(e0(new eX(n.path)),r,2,j.at))}}async function rq(e,t,n){let r=[],s=[],i=[];e.ic.isEmpty()||(e.ic.forEach((a,o)=>{i.push(e._c(o,t,n).then(t=>
1130{if((t||n)&&e.isPrimaryClient&&e.sharedClientState.updateQueryState(o.targetId,(null==t?void 0:t.fromCache)?"not-current":"current"),t){r.push(t);let e=nI.Ci(o.targetId,t);s.push(e)}}))}),await Promise.all(i),e.sc.Wo(r),await async function(e,t){try{await e.persistence.runTransaction("notifyLocalViewChanges","readwrite",n=>z.forEach(t,t=>z.forEach(t.Si,r=>e.persistence.referenceDelegate.addReference(n,t.targetId,r)).next(()=>z.forEach(t.Di,r=>e.persistence.referenceDelegate.removeReference(n,t.targetId,r)))))}catch(e){if(!$(e))throw e;g("LocalStore","Failed to update sequence numbers: "+e)}for(let n of t){let t=n.targetId;if(!n.fromCache){let n=e.qi.get(t),r=n.snapshotVersion,s=n.withLastLimboFreeSnapshotVersion(r);e.qi=e.qi.insert(t,s)}}}(e.localStore,s))}async function rB(e,t){var n;if(!e.currentUser.isEqual(t)){g("SyncEngine","User change. New user:",t.toKey());let r=await nA(e.localStore,t);e.currentUser=t,n="'waitForPendingWrites' promise is rejected due to a user change.",e.lc.forEach(e=>{e.forEach(e=>{e.reject(new T(E.CANCELLED,n))})}),e.lc.clear(),e.sharedClientState.handleUserChange(t,r.removedBatchIds,r.addedBatchIds),await rq(e,r.ji)}}function rK(e,t){let n=e.cc.get(t);if(n&&n.nc)return tx().add(n.key);{let n=tx(),r=e.rc.get(t);if(!r)return n;for(let t of r){let r=e.ic.get(t);n=n.unionWith(r.view.ju)}return n}}class rQ{constructor(){this.synchronizeTabs=!1}async initialize(e){this.yt=nM(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){var t;return t=this.persistence,new nS(t,new nC,e.initialUser,this.yt)}yc(e){return new nw(nT.Bs,this.yt)}gc(e){return new n_}async terminate(){this.gcScheduler&&this.gcScheduler.stop(),await this.sharedClientState.shutdown(),await this.persistence.shutdown()}}class rG{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=>r_(this.syncEngine,e,1),this.remoteStore.remoteSyncer.handleCredentialChange=rB.bind(null,this.syncEngine),await rr(this.remoteStore,this.syncEngine.isPrimaryClient))}createEventManager(e){return new rd}createDatastore(e){let t=nM(e.databaseInfo.databaseId),n=new nF(e.databaseInfo);return new nK(e.authCredentials,e.appCheckCredentials,n,t)}createRemoteStore(e){var t;return t=this.localStore,new nG(t,this.datastore,e.asyncQueue,e=>r_(this.syncEngine,e,0),nL.C()?new nL:new nR)}createSyncEngine(e,t){return function(e,t,n,r,s,i,a){let o=new rS(e,t,n,r,s,i);return a&&(o.dc=!0),o}(this.localStore,this.remoteStore,this.eventManager,this.sharedClientState,e.initialUser,e.maxConcurrentLimboResolutions,t)}terminate(){return async function(e){g("RemoteStore","RemoteStore shutting down."),e._u.add(5),await n$(e),e.mu.shutdown(),e.gu.set("Unknown")}(this.remoteStore)}}/** 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 */function rz(e,t,n){if(!n)throw new T(E.INVALID_ARGUMENT,`Function ${e}() cannot be called with an empty ${t}.`)}function r$(e){if(!q.isDocumentKey(e))throw new T(E.INVALID_ARGUMENT,`Invalid document reference. Document references must have an even number of segments, but ${e} has ${e.length}.`)}function rj(e){if(q.isDocumentKey(e))throw new T(E.INVALID_ARGUMENT,`Invalid collection reference. Collection references must have an odd number of segments, but ${e} has ${e.length}.`)}function rW(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 n=(t=e).constructor?t.constructor.name:null;return n?`a custom ${n} object`:"an object"}}return"function"==typeof e?"a function":w()}function rH(e,t){if("_delegate"in e&&(e=e._delegate),!(e instanceof t)){if(t.name===e.constructor.name)throw new T(E.INVALID_ARGUMENT,"Type does not match the expected instance. Did you pass a reference from a different Firestore SDK?");{let n=rW(e);throw new T(E.INVALID_ARGUMENT,`Expected type '${t.name}', but it was: ${n}`)}}return e}/** 1146 * @license 1147 * Copyright 2020 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 */let rY=new Map;class rX{constructor(e){var t;if(void 0===e.host){if(void 0!==e.ssl)throw new T(E.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 T(E.INVALID_ARGUMENT,"cacheSizeBytes must be at least 1048576");this.cacheSizeBytes=e.cacheSizeBytes}this.experimentalForceLongPolling=!!e.experimentalForceLongPolling,this.experimentalAutoDetectLongPolling=!!e.experimentalAutoDetectLongPolling,this.useFetchStreams=!!e.useFetchStreams,function(e,t,n,r){if(!0===t&&!0===r)throw new T(E.INVALID_ARGUMENT,`${e} and ${n} cannot be used together.`)}("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}}/** 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 */class rJ{constructor(e,t,n,r){this._authCredentials=e,this._appCheckCredentials=t,this._databaseId=n,this._app=r,this.type="firestore-lite",this._persistenceKey="(lite)",this._settings=new rX({}),this._settingsFrozen=!1}get app(){if(!this._app)throw new T(E.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 T(E.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 rX(e),void 0!==e.credentials&&(this._authCredentials=function(e){if(!e)return new S;switch(e.type){case"gapi":return new b(e.client,e.sessionIndex||"0",e.iamToken||null,e.authTokenFactory||null);case"provider":return e.client;default:throw new T(E.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=rY.get(e);t&&(g("ComponentProvider","Removing Datastore"),rY.delete(e),t.terminate())}(this),Promise.resolve()}}/** 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 */class rZ{constructor(e,t,n){this.converter=t,this._key=n,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 r1(this.firestore,this.converter,this._key.path.popLast())}withConverter(e){return new rZ(this.firestore,e,this._key)}}class r0{constructor(e,t,n){this.converter=t,this._query=n,this.type="query",this.firestore=e}withConverter(e){return new r0(this.firestore,e,this._query)}}class r1 extends r0{constructor(e,t,n){super(e,t,new eX(n)),this._path=n,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 rZ(this.firestore,null,new q(e))}withConverter(e){return new r1(this.firestore,e,this._path)}}function r2(e,t,...n){if(e=(0,l.m9)(e),rz("collection","path",t),e instanceof rJ){let r=M.fromString(t,...n);return rj(r),new r1(e,null,r)}{if(!(e instanceof rZ||e instanceof r1))throw new T(E.INVALID_ARGUMENT,"Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore");let r=e._path.child(M.fromString(t,...n));return rj(r),new r1(e.firestore,null,r)}}function r4(e,t,...n){if(e=(0,l.m9)(e),1==arguments.length&&(t=R.R()),rz("doc","path",t),e instanceof rJ){let r=M.fromString(t,...n);return r$(r),new rZ(e,null,new q(r))}{if(!(e instanceof rZ||e instanceof r1))throw new T(E.INVALID_ARGUMENT,"Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore");let r=e._path.child(M.fromString(t,...n));return r$(r),new rZ(e.firestore,e instanceof r1?e.converter:null,new q(r))}}/** 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 *//** 1206 * @license 1207 * Copyright 2017 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 */class r3{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):p("Uncaught Error in snapshot listener:",e.toString())}bc(){this.muted=!0}Rc(e,t){this.muted||setTimeout(()=>{this.muted||e(t)},0)}}/** 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, softw
1230are 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 */class r9{constructor(e,t,n,r){this.authCredentials=e,this.appCheckCredentials=t,this.asyncQueue=n,this.databaseInfo=r,this.user=c.UNAUTHENTICATED,this.clientId=R.R(),this.authCredentialListener=()=>Promise.resolve(),this.appCheckCredentialListener=()=>Promise.resolve(),this.authCredentials.start(n,async e=>{g("FirestoreClient","Received user=",e.uid),await this.authCredentialListener(e),this.user=e}),this.appCheckCredentials.start(n,e=>(g("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 T(E.FAILED_PRECONDITION,"The client has already been terminated.")}terminate(){this.asyncQueue.enterRestrictedMode();let e=new I;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(n){let t=ro(n,"Failed to shutdown persistence");e.reject(t)}}),e.promise}}async function r5(e,t){e.asyncQueue.verifyOperationInProgress(),g("FirestoreClient","Initializing OfflineComponentProvider");let n=await e.getConfiguration();await t.initialize(n);let r=n.initialUser;e.setCredentialChangeListener(async e=>{r.isEqual(e)||(await nA(t.localStore,e),r=e)}),t.persistence.setDatabaseDeletedListener(()=>e.terminate()),e.offlineComponents=t}async function r6(e,t){e.asyncQueue.verifyOperationInProgress();let n=await r8(e);g("FirestoreClient","Initializing OnlineComponentProvider");let r=await e.getConfiguration();await t.initialize(n,r),e.setCredentialChangeListener(e=>rn(t.remoteStore,e)),e.setAppCheckTokenChangeListener((e,n)=>rn(t.remoteStore,n)),e.onlineComponents=t}async function r8(e){return e.offlineComponents||(g("FirestoreClient","Using default OfflineComponentProvider"),await r5(e,new rQ)),e.offlineComponents}async function r7(e){return e.onlineComponents||(g("FirestoreClient","Using default OnlineComponentProvider"),await r6(e,new rG)),e.onlineComponents}async function se(e){let t=await r7(e),n=t.eventManager;return n.onListen=rA.bind(null,t.syncEngine),n.onUnlisten=rk.bind(null,t.syncEngine),n}class st{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 nU(this,"async_queue_retry"),this.Wc=()=>{let e=nO();e&&g("AsyncQueue","Visibility state changed to "+e.visibilityState),this.xo.Po()};let e=nO();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=nO();t&&"function"==typeof t.removeEventListener&&t.removeEventListener("visibilitychange",this.Wc)}}enqueue(e){if(this.zc(),this.qc)return new Promise(()=>{});let t=new I;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(!$(e))throw e;g("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;throw this.Kc=e,this.Gc=!1,p("INTERNAL UNHANDLED ERROR: ",(t=e.message||"",e.stack&&(t=e.stack.includes(e.message)?e.stack:e.message+"\n"+e.stack),t)),e}).then(e=>(this.Gc=!1,e))));return this.Bc=t,t}enqueueAfterDelay(e,t,n){this.zc(),this.jc.indexOf(e)>-1&&(t=0);let r=ra.createAndSchedule(this,e,t,n,e=>this.Yc(e));return this.Uc.push(r),r}zc(){this.Kc&&w()}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)=>
1235e.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)}}class sn extends rJ{constructor(e,t,n,r){super(e,t,n,r),this.type="firestore",this._queue=new st,this._persistenceKey=(null==r?void 0:r.name)||"[DEFAULT]"}_terminate(){return this._firestoreClient||si(this),this._firestoreClient.terminate()}}function sr(e,t){let n="object"==typeof e?e:(0,i.Mq)(),r=(0,i.qX)(n,"firestore").getImmediate({identifier:"string"==typeof e?e:t||"(default)"});if(!r._initialized){let e=(0,l.P0)("firestore");e&&function(e,t,n,r={}){var s;let i=(e=rH(e,rJ))._getSettings();if("firestore.googleapis.com"!==i.host&&i.host!==t&&y("Host has been set in both settings() and useEmulator(), emulator host will be used"),e._setSettings(Object.assign(Object.assign({},i),{host:`${t}:${n}`,ssl:!1})),r.mockUserToken){let t,n;if("string"==typeof r.mockUserToken)t=r.mockUserToken,n=c.MOCK_USER;else{t=(0,l.Sg)(r.mockUserToken,null===(s=e._app)||void 0===s?void 0:s.options.projectId);let i=r.mockUserToken.sub||r.mockUserToken.user_id;if(!i)throw new T(E.INVALID_ARGUMENT,"mockUserToken must contain 'sub' or 'user_id' field!");n=new c(i)}e._authCredentials=new A(new C(t,n))}}(r,...e)}return r}function ss(e){return e._firestoreClient||si(e),e._firestoreClient.verifyNotTerminated(),e._firestoreClient}function si(e){var t,n;let r=e._freezeSettings(),s=(n=e._databaseId,new W(n,(null===(t=e._app)||void 0===t?void 0:t.options.appId)||"",e._persistenceKey,r.host,r.ssl,r.experimentalForceLongPolling,r.experimentalAutoDetectLongPolling,r.useFetchStreams));e._firestoreClient=new r9(e._authCredentials,e._appCheckCredentials,e._queue,s)}/** 1236 * @license 1237 * Copyright 2020 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 *//** 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 */class sa{constructor(e){this._byteString=e}static fromBase64String(e){try{return new sa(ee.fromBase64String(e))}catch(e){throw new T(E.INVALID_ARGUMENT,"Failed to construct data from Base64 string: "+e)}}static fromUint8Array(e){return new sa(ee.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)}}/** 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 */class so{constructor(...e){for(let t=0;t<e.length;++t)if(0===e[t].length)throw new T(E.INVALID_ARGUMENT,"Invalid field name at argument $(i + 1). Field names must not be empty.");this._internalPath=new P(e)}isEqual(e){return this._internalPath.isEqual(e._internalPath)}}/** 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 */class sl{constructor(e){this._methodName=e}}/** 1296 * @license 1297 * Copyright 2017 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 */class su{constructor(e,t){if(!isFinite(e)||e<-90||e>90)throw new T(E.INVALID_ARGUMENT,"Latitude must be a number between -90 and 90, but was: "+e);if(!isFinite(t)||t<-180||t>180)throw new T(E.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 L(this._lat,e._lat)||L(this._long,e._long)}}/** 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 sh=/^__.*__$/;class sc{constructor(e,t,n){this.data=e,this.fieldMask=t,this.fieldTransforms=n}toMutation(e,t){return null!==this.fieldMask?new ty(e,this.data,this.fieldMask,t,this.fieldTransforms):new tp(e,this.data,t,this.fieldTransforms)}}function sd(e){switch(e){case 0:case 2:case 1:return!0;case 3:case 4:return!1;default:throw w()}}class sf{constructor(e,t,n,r,s,i){this.settings=e,this.databaseId=t,this.yt=n,this.ignoreUndefinedProperties=r,void 0===s&&this.na(),this.fieldTransforms=s||[],this.fieldMask=i||[]}get path(){return this.settings.path}get sa(){return this.settings.sa}ia(e){return new sf(Object.assign(Object.assign({},this.settings),e),this.databaseId,this.yt,this.ignoreUndefinedProperties,this.fieldTransforms,this.fieldMask)}ra(e){var t;let n=null===(t=this.path)||void 0===t?void 0:t.child(e),r=this.ia({path:n,oa:!1});return r.ua(e),r}ca(e){var t;let n=null===(t=this.path)||void 0===t?void 0:t.child(e),r=this.ia({path:n,oa:!1});return r.na(),r}aa(e){return this.ia({path:void 0,oa:!0})}ha(e){return sw(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(sd(this.sa)&&sh.test(e))throw this.ha('Document fields cannot begin and end with "__"')}}class sm{constructor(e,t,n){this.databaseId=e,this.ignoreUndefinedProperties=t,this.yt=n||nM(e)}da(e,t,n,r=!1){return new sf({sa:e,methodName:t,fa:n,path:P.emptyPath(),oa:!1,la:r},this.databaseId,this.yt,this.ignoreUndefinedProperties)}}function sg(e){return!("object"!=typeof e||null===e||e instanceof Array||e instanceof Date||e instanceof V||e instanceof su||e instanceof sa||e instanceof rZ||e instanceof sl)}
1325function sp(e,t,n){if(!sg(n)||!("object"==typeof n&&null!==n&&(Object.getPrototypeOf(n)===Object.prototype||null===Object.getPrototypeOf(n)))){let r=rW(n);throw"an object"===r?t.ha(e+" a custom object"):t.ha(e+" "+r)}}let sy=RegExp("[~\\*/\\[\\]]");function sv(e,t,n){if(t.search(sy)>=0)throw sw(`Invalid field path (${t}). Paths must not contain '~', '*', '/', '[', or ']'`,e,!1,void 0,n);try{return new so(...t.split("."))._internalPath}catch(r){throw sw(`Invalid field path (${t}). Paths must not be empty, begin with '.', end with '.', or contain '..'`,e,!1,void 0,n)}}function sw(e,t,n,r,s){let i=r&&!r.isEmpty(),a=void 0!==s,o=`Function ${t}() called with invalid data`;n&&(o+=" (via `toFirestore()`)"),o+=". ";let l="";return(i||a)&&(l+=" (found",i&&(l+=` in field ${r}`),a&&(l+=` in document ${s}`),l+=")"),new T(E.INVALID_ARGUMENT,o+e+l)}/** 1326 * @license 1327 * Copyright 2020 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 */class sE{constructor(e,t,n,r,s){this._firestore=e,this._userDataWriter=t,this._key=n,this._document=r,this._converter=s}get id(){return this._key.path.lastSegment()}get ref(){return new rZ(this._firestore,this._converter,this._key)}exists(){return null!==this._document}data(){if(this._document){if(this._converter){let e=new sT(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(sI("DocumentSnapshot.get",e));if(null!==t)return this._userDataWriter.convertValue(t)}}}class sT extends sE{data(){return super.data()}}function sI(e,t){return"string"==typeof t?sv(e,t):t instanceof so?t._internalPath:t._delegate._internalPath}class sC{convertValue(e,t="none"){switch(el(e)){case 0:return null;case 1:return e.booleanValue;case 2:return er(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(es(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 w()}}convertObject(e,t){let n={};return X(e.fields,(e,r)=>{n[e]=this.convertValue(r,t)}),n}convertGeoPoint(e){return new su(er(e.latitude),er(e.longitude))}convertArray(e,t){return(e.values||[]).map(e=>this.convertValue(e,t))}convertServerTimestamp(e,t){switch(t){case"previous":let n=function e(t){let n=t.mapValue.fields.__previous_value__;return ei(n)?e(n):n}(e);return null==n?null:this.convertValue(n,t);case"estimate":return this.convertTimestamp(ea(e));default:return null}}convertTimestamp(e){let t=en(e);return new V(t.seconds,t.nanos)}convertDocumentKey(e,t){let n=M.fromString(e);t6(n)||w();let r=new H(n.get(1),n.get(3)),s=new q(n.popFirst(5));return r.isEqual(t)||p(`Document ${s} contains a document reference within a different database (${r.projectId}/${r.database}) which is not supported. It will be treated as a reference in the current database (${t.projectId}/${t.database}) instead.`),s}}/** 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 */class sS{constructor(e,t){this.hasPendingWrites=e,this.fromCache=t}isEqual(e){return this.hasPendingWrites===e.hasPendingWrites&&this.fromCache===e.fromCache}}class sA extends sE{constructor(e,t,n,r,s,i){super(e,t,n,r,i),this._firestore=e,this._firestoreImpl=e,this.metadata=s}exists(){return super.exists()}data(e={}){if(this._document){if(this._converter){let t=new sN(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 n=this._document.data.field(sI("DocumentSnapshot.get",e));if(null!==n)return this._userDataWriter.convertValue(n,t.serverTimestamps)}}}class sN extends sA{data(e={}){return super.data(e)}}/** 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 sk(e){e=rH(e,rZ);let t=rH(e.firestore,sn);return(function(e,t,n={}){let r=new I;return e.asyncQueue.enqueueAndForget(async()=>(function(e,t,n,r,s){let i=new r3({next:i=>{t.enqueueAndForget(()=>rm(e,a));let o=i.docs.has(n);!o&&i.fromCache?s.reject(new T(E.UNAVAILABLE,"Failed to get document because the client is offline.")):o&&i.fromCache&&r&&"server"===r.source?s.reject(new T(E.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.)')):s.resolve(i)},error:e=>s.reject(e)}),a=new rv(new eX(n.path),i,{includeMetadataChanges:!0,Nu:!0});return rf(e,a)})(await se(e),e.asyncQueue,t,n,r)),r.promise})(ss(t),e._key).then(n=>(function(e,t,n){let r=n.docs.get(t._key),s=new sb(e);return new sA(e,s,t._key,r,new sS(n.hasPendingWrites,n.fromCache),t.converter)})(t,e,n))}class sb extends sC{constructor(e){super(),this.firestore=e}convertBytes(e){return new sa(e)}convertReference(e){let t=this.convertDocumentKey(e,this.firestore._databaseId);return new rZ(this.firestore,null,t)}}function sD(e,t){var n,r;let s=rH(e.firestore,sn),i=r4(e),a=(n=e.converter)?n.toFirestore(t):t;return(r=[(function(e,t,n,r,s,i={}){let a,o;let u=e.da(i.merge||i.mergeFields?2:0,t,n,s);sp("Data must be an object, but it was:",u,r);let h=function e(t,n){let r={};return J(t)?n.path&&n.path.length>0&&n.fieldMask.push(n.path):X(t,(t,s)=>{let i=function t(n,r){if(sg(n=(0,l.m9)(n)))return sp("Unsupported field value:",r,n),e(n,r);if(n instanceof sl)return function(e,t){if(!sd(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 n=e._toFieldTransform(t);n&&t.fieldTransforms.push(n)}(n,r),null;if(void 0===n&&r.ignoreUndefinedProperties)return null;if(r.path&&r.fieldMask.push(r.path),n instanceof Array){if(r.settings.oa&&4!==r.sa)throw r.ha("Nested arrays are not supported");return function(e,n){let r=[],s=0;for(let i of e){let e=t(i,n.aa(s));null==e&&(e={nullValue:"NULL_VALUE"}),r.push(e),s++}return{arrayValue:{values:r}}}(n,r)}return function(e,t){if(null===(e=(0,l.m9)(e)))return{nullValue:"NULL_VALUE"};if("number"==typeof e){var n,r,s;return n=t.yt,"number"==typeof(s=r=e)&&Number.isInteger(s)&&!Z(s)&&s<=Number.MAX_SAFE_INTEGER&&s>=Number.MIN_SAFE_INTEGER?e8(r):e6(n,r)}if("boolean"==typeof e)return{booleanValue:e};if("string"==typeof e)return{stringValue:e};if(e instanceof Date){let n=V.fromDate(e);return{timestampValue:tW(t.yt,n)}}if(e instanceof V){let n=new V(e.seconds,1e3*Math.floor(e.nanoseconds/1e3));return{timestampValue:tW(t.yt,n)}}if(e instanceof su)return{geoPointValue:{latitude:e.latitude,longitude:e.longitude}};if(e instanceof sa)return{bytesValue:tH(t.yt,e._byteString)};if(e instanceof rZ){let n=t.databaseId,r=e.firestore._databaseId;if(!r.isEqual(n))throw t.ha(`Document reference is for database ${r.projectId}/${r.database} but should be for database ${n.projectId}/${n.database}`);return{referenceValue:tX(e.firestore._databaseId||t.databaseId,e._key.path)}}throw t.ha(`Unsupported field value: ${rW(e)}`)}(n,r)}(s,n.ra(t));null!=i&&(r[t]=i)}),{mapValue:{fields:r}}}(r,u);if(i.merge)a=new eQ(u.fieldMask),o=u.fieldTransforms;else if(i.mergeFields){let e=[];for(let r of i.mergeFields){let s=function(e,t,n){if((t=(0,l.m9)(t))instanceof so)return t._internalPath;if("string"==typeof t)return sv(e,t);throw sw("Field path arguments must be of type string or ",e,!1,void 0,n)}(t,r,n);if(!u.contains(s))throw new T(E.INVALID_ARGUMENT,`Field '${s}' is specified in your field mask but missing from your input data.`);(function(e,t){return e.some(e=>e.isEqual(t))})(e,s)||e.push(s)}a=new eQ(e),o=u.fieldTransforms.filter(e=>a.covers(e.field))}else a=null,o=u.fieldTransforms;return new sc(new eG(h),a,o)})(function(e){let t=e._freezeSettings(),n=nM(e._databaseId);return new sm(e._databaseId,!!t.ignoreUndefinedProperties,n)}(e.firestore),"addDoc",i._key,a,null!==e.converter,{}).toMutation(i._key,th.exists(!1))],function(e,t){let n=new I;return e.asyncQueue.enqueueAndForget(async()=>rb(await r7(e).then(e=>e.syncEngine),t,n)),n.promise}(ss(s),r)).then(()=>i)}!function(e,t=!0){d=i.Jn,(0,i.Xd)(new a.wA("firestore",(e,{instanceIdentifier:n,options:r})=>{let s=e.getProvider("app").getImmediate(),i=new sn(new N(e.getProvider("auth-internal")),new _(e.getProvider("app-check-internal")),function(e,t){if(!Object.prototype.hasOwnProperty.apply(e.options,["projectId"]))throw new T(E.INVALID_ARGUMENT,'"projectId" not provided in firebase.initializeApp.');return new H(e.options.projectId,t)}(s,n),s);return r=Object.assign({useFetchStreams:t},r),i._setSettings(r),i},"PUBLIC").setMultipleInstances(!0)),(0,i.KN)(h,"3.8.1",void 0),(0,i.KN)(h,"3.8.1","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.