PageSourceSearch

https://testatomic.com/_next/static/chunks/14aeac6e-752c4837a93fd7a2.js

js testatomic.com collected 2026-10-02 01:45:37 UTC 193,179 bytes, 7 lines download raw bytes

1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[9149],{64797:(e,t,r)=>{r.d(t,{AB:()=>an,BN:()=>av,CL:()=>aV,Dc:()=>ei,Fs:()=>sN,GG:()=>aw,H9:()=>sp,HM:()=>as,My:()=>at,O5:()=>aO,P:()=>s5,W6:()=>N,_M:()=>s9,aQ:()=>aI,aU:()=>sT,c4:()=>aR,d_:()=>aC,gS:()=>aT,kd:()=>aE,mZ:()=>a_,rJ:()=>sg,wP:()=>aF,x7:()=>ap});var n,i,s,a,o=r(84073),l=r(66945),u=r(52126),h=r(74953),c=r(54225),d=r(16501);r(77011);var f=r(13213).hp;let m="@firebase/firestore",g="4.8.0";class p{constructor(e){this.uid=e}isAuthenticated(){return null!=this.uid}toKey(){return this.isAuthenticated()?"uid:"+this.uid:"anonymous-user"}isEqual(e){return e.uid===this.uid}}p.UNAUTHENTICATED=new p(null),p.GOOGLE_CREDENTIALS=new p("google-credentials-uid"),p.FIRST_PARTY=new p("first-party-uid"),p.MOCK_USER=new p("mock-user");let y="11.10.0",w=new u.Vy("@firebase/firestore");function v(){return w.logLevel}function _(e,...t){if(w.logLevel<=u.$b.DEBUG){let r=t.map(I);w.debug(`Firestore (${y}): ${e}`,...r)}}function E(e,...t){if(w.logLevel<=u.$b.ERROR){let r=t.map(I);w.error(`Firestore (${y}): ${e}`,...r)}}function T(e,...t){if(w.logLevel<=u.$b.WARN){let r=t.map(I);w.warn(`Firestore (${y}): ${e}`,...r)}}function I(e){if("string"==typeof e)return e;try{return JSON.stringify(e)}catch(t){return e}}function S(e,t,r){let n="Unexpected state";"string"==typeof t?n=t:r=t,b(e,n,r)}function b(e,t,r){let n=`FIRESTORE (${y}) INTERNAL ASSERTION FAILED: ${t} (ID: ${e.toString(16)})`;if(void 0!==r)try{n+=" CONTEXT: "+JSON.stringify(r)}catch(e){n+=" CONTEXT: "+r}throw E(n),Error(n)}function C(e,t,r,n){let i="Unexpected state";"string"==typeof r?i=r:n=r,e||b(t,i,n)}let A={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 N extends h.g{constructor(e,t){super(e,t),this.code=e,this.message=t,this.toString=()=>`${this.name}: [code=${this.code}]: ${this.message}`}}class D{constructor(){this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}class k{constructor(e,t){this.user=t,this.type="OAuth",this.headers=new Map,this.headers.set("Authorization",`Bearer ${e}`)}}class x{getToken(){return Promise.resolve(null)}invalidateToken(){}start(e,t){e.enqueueRetryable(()=>t(p.UNAUTHENTICATED))}shutdown(){}}class R{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 V{constructor(e){this.t=e,this.currentUser=p.UNAUTHENTICATED,this.i=0,this.forceRefresh=!1,this.auth=null}start(e,t){C(void 0===this.o,42304);let r=this.i,n=e=>this.i!==r?(r=this.i,t(e)):Promise.resolve(),i=new D;this.o=()=>{this.i++,this.currentUser=this.u(),i.resolve(),i=new D,e.enqueueRetryable(()=>n(this.currentUser))};let s=()=>{let t=i;e.enqueueRetryable(async()=>{await t.promise,await n(this.currentUser)})},a=e=>{_("FirebaseAuthCredentialsProvider","Auth detected"),this.auth=e,this.o&&(this.auth.addAuthTokenListener(this.o),s())};this.t.onInit(e=>a(e)),setTimeout(()=>{if(!this.auth){let e=this.t.getImmediate({optional:!0});e?a(e):(_("FirebaseAuthCredentialsProvider","Auth not yet detected"),i.resolve(),i=new D)}},0),s()}getToken(){let e=this.i,t=this.forceRefresh;return this.forceRefresh=!1,this.auth?this.auth.getToken(t).then(t=>this.i!==e?(_("FirebaseAuthCredentialsProvider","getToken aborted due to token change."),this.getToken()):t?(C("string"==typeof t.accessToken,31837,{l:t}),new k(t.accessToken,this.currentUser)):null):Promise.resolve(null)}invalidateToken(){this.forceRefresh=!0}shutdown(){this.auth&&this.o&&this.auth.removeAuthTokenListener(this.o),this.o=void 0}u(){let e=this.auth&&this.auth.getUid();return C(null===e||"string"==typeof e,2055,{h:e}),new p(e)}}class O{constructor(e,t,r){this.P=e,this.T=t,this.I=r,this.type="FirstParty",this.user=p.FIRST_PARTY,this.A=new Map}R(){return this.I?this.I():null}get headers(){this.A.set("X-Goog-AuthUser",this.P);let e=this.R();return e&&this.A.set("Authorization",e),this.T&&this.A.set("X-Goog-Iam-Authorization-Token",this.T),this.A}}class F{constructor(e,t,r){this.P=e,this.T=t,this.I=r}getToken(){return Promise.resolve(new O(this.P,this.T,this.I))}start(e,t){e.enqueueRetryable(()=>t(p.FIRST_PARTY))}shutdown(){}invalidateToken(){}}class L{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 M{constructor(e,t){this.V=t,this.forceRefresh=!1,this.appCheck=null,this.m=null,this.p=null,(0,o.xZ)(e)&&e.settings.appCheckToken&&(this.p=e.settings.appCheckToken)}start(e,t){C(void 0===this.o,3512);let r=e=>{null!=e.error&&_("FirebaseAppCheckTokenProvider",`Error getting App Check token; using placeholder token instead. Error: ${e.error.message}`);let r=e.token!==this.m;return this.m=e.token,_("FirebaseAppCheckTokenProvider",`Received ${r?"new":"existing"} token.`),r?t(e.token):Promise.resolve()};this.o=t=>{e.enqueueRetryable(()=>r(t))};let n=e=>{_("FirebaseAppCheckTokenProvider","AppCheck detected"),this.appCheck=e,this.o&&this.appCheck.addTokenListener(this.o)};this.V.onInit(e=>n(e)),setTimeout(()=>{if(!this.appCheck){let e=this.V.getImmediate({optional:!0});e?n(e):_("FirebaseAppCheckTokenProvider","AppCheck not yet detected")}},0)}getToken(){if(this.p)return Promise.resolve(new L(this.p));let e=this.forceRefresh;return this.forceRefresh=!1,this.appCheck?this.appCheck.getToken(e).then(e=>e?(C("string"==typeof e.token,44558,{tokenResult:e}),this.m=e.token,new L(e.token)):null):Promise.resolve(null)}invalidateToken(){this.forceRefresh=!0}shutdown(){this.appCheck&&this.o&&this.appCheck.removeTokenListener(this.o),this.o=void 0}}function P(){return new TextEncoder}class U{static newId(){let e=62*Math.floor(256/62),t="";for(;t.length<20;){let r=function(e){let t="undefined"!=typeof self&&(self.crypto||self.msCrypto),r=new 
1Uint8Array(40);if(t&&"function"==typeof t.getRandomValues)t.getRandomValues(r);else for(let e=0;e<40;e++)r[e]=Math.floor(256*Math.random());return r}(40);for(let n=0;n<r.length;++n)t.length<20&&r[n]<e&&(t+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(r[n]%62))}return t}}function q(e,t){return e<t?-1:+(e>t)}function $(e,t){let r=0;for(;r<e.length&&r<t.length;){let n=e.codePointAt(r),i=t.codePointAt(r);if(n!==i){if(n<128&&i<128)return q(n,i);{let s=P(),a=function(e,t){for(let r=0;r<e.length&&r<t.length;++r)if(e[r]!==t[r])return q(e[r],t[r]);return q(e.length,t.length)}(s.encode(B(e,r)),s.encode(B(t,r)));return 0!==a?a:q(n,i)}}r+=n>65535?2:1}return q(e.length,t.length)}function B(e,t){return e.codePointAt(t)>65535?e.substring(t,t+2):e.substring(t,t+1)}function z(e,t,r){return e.length===t.length&&e.every((e,n)=>r(e,t[n]))}let j="__name__";class G{constructor(e,t,r){void 0===t?t=0:t>e.length&&S(637,{offset:t,range:e.length}),void 0===r?r=e.length-t:r>e.length-t&&S(1746,{length:r,range:e.length-t}),this.segments=e,this.offset=t,this.len=r}get length(){return this.len}isEqual(e){return 0===G.comparator(this,e)}child(e){let t=this.segments.slice(this.offset,this.limit());return e instanceof G?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,r=this.limit();t<r;t++)e(this.segments[t])}toArray(){return this.segments.slice(this.offset,this.limit())}static comparator(e,t){let r=Math.min(e.length,t.length);for(let n=0;n<r;n++){let r=G.compareSegments(e.get(n),t.get(n));if(0!==r)return r}return q(e.length,t.length)}static compareSegments(e,t){let r=G.isNumericId(e),n=G.isNumericId(t);return r&&!n?-1:!r&&n?1:r&&n?G.extractNumericId(e).compare(G.extractNumericId(t)):$(e,t)}static isNumericId(e){return e.startsWith("__id")&&e.endsWith("__")}static extractNumericId(e){return c.jz.fromString(e.substring(4,e.length-2))}}class K extends G{construct(e,t,r){return new K(e,t,r)}canonicalString(){return this.toArray().join("/")}toString(){return this.canonicalString()}toUriEncodedString(){return this.toArray().map(encodeURIComponent).join("/")}static fromString(...e){let t=[];for(let r of e){if(r.indexOf("//")>=0)throw new N(A.INVALID_ARGUMENT,`Invalid segment (${r}). Paths must not contain // in them.`);t.push(...r.split("/").filter(e=>e.length>0))}return new K(t)}static emptyPath(){return new K([])}}let Q=/^[_a-zA-Z][_a-zA-Z0-9]*$/;class W extends G{construct(e,t,r){return new W(e,t,r)}static isValidIdentifier(e){return Q.test(e)}canonicalString(){return this.toArray().map(e=>(e=e.replace(/\\/g,"\\\\").replace(/`/g,"\\`"),W.isValidIdentifier(e)||(e="`"+e+"`"),e)).join(".")}toString(){return this.canonicalString()}isKeyField(){return 1===this.length&&this.get(0)===j}static keyField(){return new W([j])}static fromServerFormat(e){let t=[],r="",n=0,i=()=>{if(0===r.length)throw new N(A.INVALID_ARGUMENT,`Invalid field path (${e}). Paths must not be empty, begin with '.', end with '.', or contain '..'`);t.push(r),r=""},s=!1;for(;n<e.length;){let t=e[n];if("\\"===t){if(n+1===e.length)throw new N(A.INVALID_ARGUMENT,"Path has trailing escape character: "+e);let t=e[n+1];if("\\"!==t&&"."!==t&&"`"!==t)throw new N(A.INVALID_ARGUMENT,"Path has invalid escape sequence: "+e);r+=t,n+=2}else"`"===t?s=!s:"."!==t||s?r+=t:i(),n++}if(i(),s)throw new N(A.INVALID_ARGUMENT,"Unterminated ` in path: "+e);return new W(t)}static emptyPath(){return new W([])}}class H{constructor(e){this.path=e}static fromPath(e){return new H(K.fromString(e))}static fromName(e){return new H(K.fromString(e).popFirst(5))}static empty(){return new H(K.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===K.comparator(this.path,e.path)}toString(){return this.path.toString()}static comparator(e,t){return K.comparator(e.path,t.path)}static isDocumentKey(e){return e.length%2==0}static fromSegments(e){return new H(new K(e.slice()))}}function Y(e,t,r){if(!r)throw new N(A.INVALID_ARGUMENT,`Function ${e}() cannot be called with an empty ${t}.`)}function J(e){if(!H.isDocumentKey(e))throw new N(A.INVALID_ARGUMENT,`Invalid document reference. Document references must have an even number of segments, but ${e} has ${e.length}.`)}function X(e){if(H.isDocumentKey(e))throw new N(A.INVALID_ARGUMENT,`Invalid collection reference. Collection references must have an odd number of segments, but ${e} has ${e.length}.`)}function Z(e){return"object"==typeof e&&null!==e&&(Object.getPrototypeOf(e)===Object.prototype||null===Object.getPrototypeOf(e))}function ee(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 r=(t=e).constructor?t.constructor.name:null;return r?`a custom ${r} object`:"an object"}}return"function"==typeof e?"a function":S(12329,{type:typeof e})}function et(e,t){if("_delegate"in e&&(e=e._delegate),!(e instanceof t)){if(t.name===e.constructor.name)throw new N(A.INVALID_ARGUMENT,"Type does not match the expected instance. Did you pass a reference from a different Firestore SDK?");{let r=ee(e);throw new N(A.INVALID_ARGUMENT,`Expected type '${t.name}', but it was: ${r}`)}}return e}function er(e,t){let r={typeString:e};return t&&(r.value=t),r}function en(e,t){let r;if(!Z(e))throw new N(A.INVALID_ARGUMENT,"JSON must be an object");for(let n in t)if(t[n]){let i=t[n].typeString,s="value"in t[n]?{value:t[n].value}:void 0;if(!(n in e)){r=`JSON missing required field: '${n}'`;break}let a=e[n];if(i&&typeof a!==i){r=`JSON field '${n}' must be a ${i}.`;break}if(void 0!==s&&a!==s.value){r=`Expected '${n}' field to equal '${s.value}'`;break}}if(r)throw new N(A.INVALID_ARGUMENT,r);return!0}class ei{static now(){return ei.fromMillis(Date.now())}static fromDate(e){return ei.fromMillis(e.getTime())}static fromMillis(e){let t=Math.floor(e/1e3),r=Math.floor((e-1e3*t)*1e6);return new ei(t,r)}constructor(e,t){if(this.seconds=e,this.nanoseconds=t,t<0||t>=1e9)throw new N(A.INVALID_ARGUMENT,"Timestamp nanoseconds out of range: "+t);if(e<-0xe7791f700||e>=0x3afff44180)throw new N(A.INVALID_ARGUMENT,"Timestamp seconds out of range: "+e)}toDate(){return new Date(this.toMillis())}toMillis(){return 1e3*this.seconds+this.nanoseconds/1e6}_compareTo(e){return this.seconds===e.seconds?q(this.nanoseconds,e.nanoseconds):q(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{type:ei._jsonSchemaVersion,seconds:this.seconds,nanoseconds:this.nanoseconds}}static fromJSON(e){if(en(e,ei._jsonSchema))return new ei(e.seconds,e.nanoseconds)}valueOf(){return String(this.seconds- -0xe7791f700).padStart(12,"0")+"."+String(this.nanoseconds).padStart(9,"0")}
1}ei._jsonSchemaVersion="firestore/timestamp/1.0",ei._jsonSchema={type:er("string",ei._jsonSchemaVersion),seconds:er("number"),nanoseconds:er("number")};class es{static fromTimestamp(e){return new es(e)}static min(){return new es(new ei(0,0))}static max(){return new es(new ei(0x3afff4417f,0x3b9ac9ff))}constructor(e){this.timestamp=e}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}}class ea{constructor(e,t,r,n){this.indexId=e,this.collectionGroup=t,this.fields=r,this.indexState=n}}ea.UNKNOWN_ID=-1;class eo{constructor(e,t,r){this.readTime=e,this.documentKey=t,this.largestBatchId=r}static min(){return new eo(es.min(),H.empty(),-1)}static max(){return new eo(es.max(),H.empty(),-1)}}class el{constructor(){this.onCommittedListeners=[]}addOnCommittedListener(e){this.onCommittedListeners.push(e)}raiseOnCommittedEvent(){this.onCommittedListeners.forEach(e=>e())}}async function eu(e){if(e.code!==A.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;_("LocalStore","Unexpectedly lost primary lease")}class eh{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&&S(59440),this.callbackAttached=!0,this.isDone?this.error?this.wrapFailure(t,this.error):this.wrapSuccess(e,this.result):new eh((r,n)=>{this.nextCallback=t=>{this.wrapSuccess(e,t).next(r,n)},this.catchCallback=e=>{this.wrapFailure(t,e).next(r,n)}})}toPromise(){return new Promise((e,t)=>{this.next(e,t)})}wrapUserFunction(e){try{let t=e();return t instanceof eh?t:eh.resolve(t)}catch(e){return eh.reject(e)}}wrapSuccess(e,t){return e?this.wrapUserFunction(()=>e(t)):eh.resolve(t)}wrapFailure(e,t){return e?this.wrapUserFunction(()=>e(t)):eh.reject(t)}static resolve(e){return new eh((t,r)=>{t(e)})}static reject(e){return new eh((t,r)=>{r(e)})}static waitFor(e){return new eh((t,r)=>{let n=0,i=0,s=!1;e.forEach(e=>{++n,e.next(()=>{++i,s&&i===n&&t()},e=>r(e))}),s=!0,i===n&&t()})}static or(e){let t=eh.resolve(!1);for(let r of e)t=t.next(e=>e?eh.resolve(e):r());return t}static forEach(e,t){let r=[];return e.forEach((e,n)=>{r.push(t.call(this,e,n))}),this.waitFor(r)}static mapArray(e,t){return new eh((r,n)=>{let i=e.length,s=Array(i),a=0;for(let o=0;o<i;o++){let l=o;t(e[l]).next(e=>{s[l]=e,++a===i&&r(s)},e=>n(e))}})}static doWhile(e,t){return new eh((r,n)=>{let i=()=>{!0===e()?t().next(()=>{i()},n):r()};i()})}}function ec(e){return"IndexedDbTransactionError"===e.name}class ed{constructor(e,t){this.previousValue=e,t&&(t.sequenceNumberHandler=e=>this._e(e),this.ae=e=>t.writeSequenceNumber(e))}_e(e){return this.previousValue=Math.max(e,this.previousValue),this.previousValue}next(){let e=++this.previousValue;return this.ae&&this.ae(e),e}}function ef(e){return null==e}function em(e){return 0===e&&1/e==-1/0}ed.ue=-1;function eg(e){let t=0;for(let r in e)Object.prototype.hasOwnProperty.call(e,r)&&t++;return t}function ep(e,t){for(let r in e)Object.prototype.hasOwnProperty.call(e,r)&&t(r,e[r])}function ey(e){for(let t in e)if(Object.prototype.hasOwnProperty.call(e,t))return!1;return!0}class ew{constructor(e,t){this.comparator=e,this.root=t||e_.EMPTY}insert(e,t){return new ew(this.comparator,this.root.insert(e,t,this.comparator).copy(null,null,e_.BLACK,null,null))}remove(e){return new ew(this.comparator,this.root.remove(e,this.comparator).copy(null,null,e_.BLACK,null,null))}get(e){let t=this.root;for(;!t.isEmpty();){let r=this.comparator(e,t.key);if(0===r)return t.value;r<0?t=t.left:r>0&&(t=t.right)}return null}indexOf(e){let t=0,r=this.root;for(;!r.isEmpty();){let n=this.comparator(e,r.key);if(0===n)return t+r.left.size;n<0?r=r.left:(t+=r.left.size+1,r=r.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,r)=>(e(t,r),!1))}toString(){let e=[];return this.inorderTraversal((t,r)=>(e.push(`${t}:${r}`),!1)),`{${e.join(", ")}}`}reverseTraversal(e){return this.root.reverseTraversal(e)}getIterator(){return new ev(this.root,null,this.comparator,!1)}getIteratorFrom(e){return new ev(this.root,e,this.comparator,!1)}getReverseIterator(){return new ev(this.root,null,this.comparator,!0)}getReverseIteratorFrom(e){return new ev(this.root,e,this.comparator,!0)}}class ev{constructor(e,t,r,n){this.isReverse=n,this.nodeStack=[];let i=1;for(;!e.isEmpty();)if(i=t?r(e.key,t):1,t&&n&&(i*=-1),i<0)e=this.isReverse?e.left:e.right;else{if(0===i){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 e_{constructor(e,t,r,n,i){this.key=e,this.value=t,this.color=null!=r?r:e_.RED,this.left=null!=n?n:e_.EMPTY,this.right=null!=i?i:e_.EMPTY,this.size=this.left.size+1+this.right.size}copy(e,t,r,n,i){return new e_(null!=e?e:this.key,null!=t?t:this.value,
1null!=r?r:this.color,null!=n?n:this.left,null!=i?i: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,r){let n=this,i=r(e,n.key);return(n=i<0?n.copy(null,null,null,n.left.insert(e,t,r),null):0===i?n.copy(null,t,null,null,null):n.copy(null,null,null,null,n.right.insert(e,t,r))).fixUp()}removeMin(){if(this.left.isEmpty())return e_.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 r,n=this;if(0>t(e,n.key))n.left.isEmpty()||n.left.isRed()||n.left.left.isRed()||(n=n.moveRedLeft()),n=n.copy(null,null,null,n.left.remove(e,t),null);else{if(n.left.isRed()&&(n=n.rotateRight()),n.right.isEmpty()||n.right.isRed()||n.right.left.isRed()||(n=n.moveRedRight()),0===t(e,n.key)){if(n.right.isEmpty())return e_.EMPTY;r=n.right.min(),n=n.copy(r.key,r.value,null,null,n.right.removeMin())}n=n.copy(null,null,null,null,n.right.remove(e,t))}return n.fixUp()}isRed(){return this.color}fixUp(){let e=this;return e.right.isRed()&&!e.left.isRed()&&(e=e.rotateLeft()),e.left.isRed()&&e.left.left.isRed()&&(e=e.rotateRight()),e.left.isRed()&&e.right.isRed()&&(e=e.colorFlip()),e}moveRedLeft(){let e=this.colorFlip();return e.right.left.isRed()&&(e=(e=(e=e.copy(null,null,null,null,e.right.rotateRight())).rotateLeft()).colorFlip()),e}moveRedRight(){let e=this.colorFlip();return e.left.left.isRed()&&(e=(e=e.rotateRight()).colorFlip()),e}rotateLeft(){let e=this.copy(null,null,e_.RED,null,this.right.left);return this.right.copy(null,null,this.color,e,null)}rotateRight(){let e=this.copy(null,null,e_.RED,this.left.right,null);return this.left.copy(null,null,this.color,null,e)}colorFlip(){let e=this.left.copy(null,null,!this.left.color,null,null),t=this.right.copy(null,null,!this.right.color,null,null);return this.copy(null,null,!this.color,e,t)}checkMaxDepth(){return Math.pow(2,this.check())<=this.size+1}check(){if(this.isRed()&&this.left.isRed())throw S(43730,{key:this.key,value:this.value});if(this.right.isRed())throw S(14113,{key:this.key,value:this.value});let e=this.left.check();if(e!==this.right.check())throw S(27949);return e+ +!this.isRed()}}e_.EMPTY=null,e_.RED=!0,e_.BLACK=!1,e_.EMPTY=new class{constructor(){this.size=0}get key(){throw S(57766)}get value(){throw S(16141)}get color(){throw S(16727)}get left(){throw S(29726)}get right(){throw S(36894)}copy(e,t,r,n,i){return this}insert(e,t,r){return new e_(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}};class eE{constructor(e){this.comparator=e,this.data=new ew(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,r)=>(e(t),!1))}forEachInRange(e,t){let r=this.data.getIteratorFrom(e[0]);for(;r.hasNext();){let n=r.getNext();if(this.comparator(n.key,e[1])>=0)return;t(n.key)}}forEachWhile(e,t){let r;for(r=void 0!==t?this.data.getIteratorFrom(t):this.data.getIterator();r.hasNext();)if(!e(r.getNext().key))return}firstAfterOrEqual(e){let t=this.data.getIteratorFrom(e);return t.hasNext()?t.getNext().key:null}getIterator(){return new eT(this.data.getIterator())}getIteratorFrom(e){return new eT(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 eE)||this.size!==e.size)return!1;let t=this.data.getIterator(),r=e.data.getIterator();for(;t.hasNext();){let e=t.getNext().key,n=r.getNext().key;if(0!==this.comparator(e,n))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 eE(this.comparator);return t.data=e,t}}
1class eT{constructor(e){this.iter=e}getNext(){return this.iter.getNext().key}hasNext(){return this.iter.hasNext()}}class eI{constructor(e){this.fields=e,e.sort(W.comparator)}static empty(){return new eI([])}unionWith(e){let t=new eE(W.comparator);for(let e of this.fields)t=t.add(e);for(let r of e)t=t.add(r);return new eI(t.toArray())}covers(e){for(let t of this.fields)if(t.isPrefixOf(e))return!0;return!1}isEqual(e){return z(this.fields,e.fields,(e,t)=>e.isEqual(t))}}class eS extends Error{constructor(){super(...arguments),this.name="Base64DecodeError"}}class eb{constructor(e){this.binaryString=e}static fromBase64String(e){return new eb(function(e){try{return atob(e)}catch(e){throw"undefined"!=typeof DOMException&&e instanceof DOMException?new eS("Invalid base64 string: "+e):e}}(e))}static fromUint8Array(e){return new eb(function(e){let t="";for(let r=0;r<e.length;++r)t+=String.fromCharCode(e[r]);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(){var e=this.binaryString;let t=new Uint8Array(e.length);for(let r=0;r<e.length;r++)t[r]=e.charCodeAt(r);return t}approximateByteSize(){return 2*this.binaryString.length}compareTo(e){return q(this.binaryString,e.binaryString)}isEqual(e){return this.binaryString===e.binaryString}}eb.EMPTY_BYTE_STRING=new eb("");let eC=new RegExp(/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.(\d+))?Z$/);function eA(e){if(C(!!e,39018),"string"==typeof e){let t=0,r=eC.exec(e);if(C(!!r,46558,{timestamp:e}),r[1]){let e=r[1];t=Number(e=(e+"000000000").substr(0,9))}return{seconds:Math.floor(new Date(e).getTime()/1e3),nanos:t}}return{seconds:eN(e.seconds),nanos:eN(e.nanos)}}function eN(e){return"number"==typeof e?e:"string"==typeof e?Number(e):0}function eD(e){return"string"==typeof e?eb.fromBase64String(e):eb.fromUint8Array(e)}let ek="server_timestamp",ex="__type__",eR="__previous_value__",eV="__local_write_time__";function eO(e){var t,r;return(null==(r=((null==(t=null==e?void 0:e.mapValue)?void 0:t.fields)||{})[ex])?void 0:r.stringValue)===ek}function eF(e){let t=e.mapValue.fields[eR];return eO(t)?eF(t):t}function eL(e){let t=eA(e.mapValue.fields[eV].timestampValue);return new ei(t.seconds,t.nanos)}class eM{constructor(e,t,r,n,i,s,a,o,l,u){this.databaseId=e,this.appId=t,this.persistenceKey=r,this.host=n,this.ssl=i,this.forceLongPolling=s,this.autoDetectLongPolling=a,this.longPollingOptions=o,this.useFetchStreams=l,this.isUsingEmulator=u}}let eP="(default)";class eU{constructor(e,t){this.projectId=e,this.database=t||eP}static empty(){return new eU("","")}get isDefaultDatabase(){return this.database===eP}isEqual(e){return e instanceof eU&&e.projectId===this.projectId&&e.database===this.database}}let eq="__type__",e$="__max__",eB={mapValue:{fields:{__type__:{stringValue:e$}}}},ez="__vector__",ej="value";function eG(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?eO(e)?4:e5(e)?0x1fffffffffffff:e4(e)?10:11:S(28295,{value:e})}function eK(e,t){if(e===t)return!0;let r=eG(e);if(r!==eG(t))return!1;switch(r){case 0:case 0x1fffffffffffff:return!0;case 1:return e.booleanValue===t.booleanValue;case 4:return eL(e).isEqual(eL(t));case 3:if("string"==typeof e.timestampValue&&"string"==typeof t.timestampValue&&e.timestampValue.length===t.timestampValue.length)return e.timestampValue===t.timestampValue;let n=eA(e.timestampValue),i=eA(t.timestampValue);return n.seconds===i.seconds&&n.nanos===i.nanos;case 5:return e.stringValue===t.stringValue;case 6:return eD(e.bytesValue).isEqual(eD(t.bytesValue));case 7:return e.referenceValue===t.referenceValue;case 8:return eN(e.geoPointValue.latitude)===eN(t.geoPointValue.latitude)&&eN(e.geoPointValue.longitude)===eN(t.geoPointValue.longitude);case 2:if("integerValue"in e&&"integerValue"in t)return eN(e.integerValue)===eN(t.integerValue);if("doubleValue"in e&&"doubleValue"in t){let r=eN(e.doubleValue),n=eN(t.doubleValue);return r===n?em(r)===em(n):isNaN(r)&&isNaN(n)}return!1;case 9:return z(e.arrayValue.values||[],t.arrayValue.values||[],eK);case 10:case 11:let s=e.mapValue.fields||{},a=t.mapValue.fields||{};if(eg(s)!==eg(a))return!1;for(let e in s)if(s.hasOwnProperty(e)&&(void 0===a[e]||!eK(s[e],a[e])))return!1;return!0;default:return S(52216,{left:e})}}function eQ(e,t){return void 0!==(e.values||[]).find(e=>eK(e,t))}function eW(e,t){if(e===t)return 0;let r=eG(e),n=eG(t);if(r!==n)return q(r,n);switch(r){case 0:case 0x1fffffffffffff:return 0;case 1:return q(e.booleanValue,t.booleanValue);case 2:let i=eN(e.integerValue||e.doubleValue),s=eN(t.integerValue||t.doubleValue);return i<s?-1:i>s?1:i===s?0:isNaN(i)?isNaN(s)?0:-1:1;case 3:return eH(e.timestampValue,t.timestampValue);case 4:return eH(eL(e),eL(t));case 5:return $(e.stringValue,t.stringValue);case 6:return function(e,t){let r=eD(e),n=eD(t);return r.compareTo(n)}(e.bytesValue,t.bytesValue);case 7:return function(e,t){let r=e.split("/"),n=t.split("/");for(let e=0;e<r.length&&e<n.length;e++){let t=q(r[e],n[e]);if(0!==t)return t}return q(r.length,n.length)}(e.referenceValue,t.referenceValue);case 8:return function(e,t){let r=q(eN(e.latitude),eN(t.latitude));return 0!==r?r:q(eN(e.longitude),eN(t.longitude))}(e.geoPointValue,t.geoPointValue);case 9:return eY(e.arrayValue,t.arrayValue);case 10:return function(e,t){var r,n,i,s;let a=e.fields||{},o=t.fields||{},l=null==(r=a[ej])?void 0:r.arrayValue,u=null==(n=o[ej])?void 0:n.arrayValue,h=q((null==(i=null==l?void 0:l.values)?void 0:i.length)||0,(null==(s=null==u?void 0:u.values)?void 0:s.length)||0);return 0!==h?h:eY(l,u)}(e.mapValue,t.mapValue);case 11:return function(e,t){if(e===eB.mapValue&&t===eB.mapValue)return 0;if(e===eB.mapValue)return 1;if(t===eB.mapValue)return -1;let r=e.fields||{},n=Object.keys(r),i=t.fields||{},s=Object.keys(i);n.sort(),s.sort();for(let e=0;e<n.length&&e<s.length;++e){let t=$(n[e],s[e]);if(0!==t)return t;let a=eW(r[n[e]],i[s[e]]);if(0!==a)return a}return q(n.length,s.length)}(e.mapValue,t.mapValue);default:throw S(23264,{le:r})}}function eH(e,t){if("string"==typeof e&&"string"==typeof t&&e.length===t.length)return q(e,t);let r=eA(e),n=eA(t),i=q(r.seconds,n.seconds);return 0!==i?i:q(r.nanos,n.nanos)}function eY(e,t){let r=e.values||[],n=t.values||[];for(let e=0;e<r.length&&e<n.length;++e){let t=eW(r[e],n[e]);if(t)return t}return q(r.length,n.length)}function eJ(e){var t,r;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=eA(e);return`time(${t.seconds},${t.nanos})`}(e.timestampValue):"stringValue"in e?e.stringValue:"bytesValue"in e?eD(e.bytesValue).toBase64():"referenceValue"in e?(t=e.referenceValue,H.fromName(t).toString()):"geoPointValue"in e?(r=e.geoPointValue,`geo(${r.latitude},${r.longitude})`):"arrayValue"in e?function(e){let t="[",r=!0;for(let n of e.values||[])r?r=!1:t+=",",t+=eJ(n);return t+"]"}(e.arrayValue):"mapValue"in e?function(e){let t=Object.keys(e.fields||{}).sort(),r="{",n=!0;for(let i of t)n?n=!1:r+=",",r+=`${i}:${eJ(e.fields[i])}`;return r+"}"}(e.mapValue):S(61005,{value:e})}function eX(e,t){return{referenceValue:`projects/${e.projectId}/databases/${e.database}/documents/${t.path.canonicalString()}`}}function eZ(e){return!!e&&"integerValue"in e}function e0(e){return!!e&&"arrayValue"in e}function e1(e){return!!e&&"nullValue"in e}function e2(e){return!!e&&"doubleValue"in e&&isNaN(Number(e.doubleValue))}function e3(e){return!!e&&"mapValue"in e}function e4(e){var t,r;return(null==(r=((null==(t=null==e?void 0:e.mapValue)?void 0:t.fields)||{})[eq])?void 0:r.stringValue)===ez}function e6(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 ep(e.mapValue.fields,(e,r)=>t.mapValue.fields[e]=e6(r)),t}if(e.arrayValue){let t={arrayValue:{values:[]}};for(let r=0;r<(e.arrayValue.values||[]).length;++r)t.arrayValue.values[r]=e6(e.arrayValue.values[r]);return t}return Object.assign({},e)}function e5(e){return(((e.mapValue||{}).fields||{}).__type__||{}).stringValue===e$}class e8{constructor(e){this.value=e}static empty(){return new e8({mapValue:{}})}field(e){if(e.isEmpty())return this.value;{let t=this.value;for(let r=0;r<e.length-1;++r)if(!e3(t=(t.mapValue.fields||{})[e.get(r)]))return null;return(t=(t.mapValue.fields||{})[e.lastSegment()])||null}}set(e,t){this.getFieldsMap(e.popLast())[e.lastSegment()]=e6(t)}setAll(e){let t=W.emptyPath(),r={},n=[];e.forEach((e,i)=>{if(!t.isImmediateParentOf(i)){let e=this.getFieldsMap(t);this.applyChanges(e,r,n),r={},n=[],t=i.popLast()}e?r[i.lastSegment()]=e6(e):n.push(i.lastSegment())});let i=this.getFieldsMap(t);this.applyChanges(i,r,n)}delete(e){let t=this.field(e.popLast());e3(t)&&t.mapValue.fields&&delete t.mapValue.fields[e.lastSegment()]}isEqual(e){return eK(this.value,e.value)}getFieldsMap(e){let t=this.value;t.mapValue.fields||(t.mapValue={fields:{}});for(let r=0;r<e.length;++r){let n=t.mapValue.fields[e.get(r)];e3(n)&&n.mapValue.fields||(n={mapValue:{fields:{}}},t.mapValue.fields[e.get(r)]=n),t=n}return t.mapValue.fields}
1applyChanges(e,t,r){for(let n of(ep(t,(t,r)=>e[t]=r),r))delete e[n]}clone(){return new e8(e6(this.value))}}class e9{constructor(e,t,r,n,i,s,a){this.key=e,this.documentType=t,this.version=r,this.readTime=n,this.createTime=i,this.data=s,this.documentState=a}static newInvalidDocument(e){return new e9(e,0,es.min(),es.min(),es.min(),e8.empty(),0)}static newFoundDocument(e,t,r,n){return new e9(e,1,t,es.min(),r,n,0)}static newNoDocument(e,t){return new e9(e,2,t,es.min(),es.min(),e8.empty(),0)}static newUnknownDocument(e,t){return new e9(e,3,t,es.min(),es.min(),e8.empty(),2)}convertToFoundDocument(e,t){return this.createTime.isEqual(es.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=e8.empty(),this.documentState=0,this}convertToUnknownDocument(e){return this.version=e,this.documentType=3,this.data=e8.empty(),this.documentState=2,this}setHasCommittedMutations(){return this.documentState=2,this}setHasLocalMutations(){return this.documentState=1,this.version=es.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 e9&&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 e9(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}})`}}class e7{constructor(e,t){this.position=e,this.inclusive=t}}function te(e,t,r){let n=0;for(let i=0;i<e.position.length;i++){let s=t[i],a=e.position[i];if(n=s.field.isKeyField()?H.comparator(H.fromName(a.referenceValue),r.key):eW(a,r.data.field(s.field)),"desc"===s.dir&&(n*=-1),0!==n)break}return n}function tt(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 r=0;r<e.position.length;r++)if(!eK(e.position[r],t.position[r]))return!1;return!0}class tr{constructor(e,t="asc"){this.field=e,this.dir=t}}class tn{}class ti extends tn{constructor(e,t,r){super(),this.field=e,this.op=t,this.value=r}static create(e,t,r){return e.isKeyField()?"in"===t||"not-in"===t?this.createKeyFieldInFilter(e,t,r):new tl(e,t,r):"array-contains"===t?new td(e,r):"in"===t?new tf(e,r):"not-in"===t?new tm(e,r):"array-contains-any"===t?new tg(e,r):new ti(e,t,r)}static createKeyFieldInFilter(e,t,r){return"in"===t?new tu(e,r):new th(e,r)}matches(e){let t=e.data.field(this.field);return"!="===this.op?null!==t&&void 0===t.nullValue&&this.matchesComparison(eW(t,this.value)):null!==t&&eG(this.value)===eG(t)&&this.matchesComparison(eW(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 S(47266,{operator:this.op})}}isInequality(){return["<","<=",">",">=","!=","not-in"].indexOf(this.op)>=0}getFlattenedFilters(){return[this]}getFilters(){return[this]}}class ts extends tn{constructor(e,t){super(),this.filters=e,this.op=t,this.he=null}static create(e,t){return new ts(e,t)}matches(e){return ta(this)?void 0===this.filters.find(t=>!t.matches(e)):void 0!==this.filters.find(t=>t.matches(e))}getFlattenedFilters(){return null!==this.he||(this.he=this.filters.reduce((e,t)=>e.concat(t.getFlattenedFilters()),[])),this.he}getFilters(){return Object.assign([],this.filters)}}function ta(e){return"and"===e.op}function to(e){for(let t of e.filters)if(t instanceof ts)return!1;return!0}class tl extends ti{constructor(e,t,r){super(e,t,r),this.key=H.fromName(r.referenceValue)}matches(e){let t=H.comparator(e.key,this.key);return this.matchesComparison(t)}}class tu extends ti{constructor(e,t){super(e,"in",t),this.keys=tc("in",t)}matches(e){return this.keys.some(t=>t.isEqual(e.key))}}class th extends ti{constructor(e,t){super(e,"not-in",t),this.keys=tc("not-in",t)}matches(e){return!this.keys.some(t=>t.isEqual(e.key))}}function tc(e,t){var r;return((null==(r=t.arrayValue)?void 0:r.values)||[]).map(e=>H.fromName(e.referenceValue))}class td extends ti{constructor(e,t){super(e,"array-contains",t)}matches(e){let t=e.data.field(this.field);return e0(t)&&eQ(t.arrayValue,this.value)}}class tf extends ti{constructor(e,t){super(e,"in",t)}matches(e){let t=e.data.field(this.field);return null!==t&&eQ(this.value.arrayValue,t)}}class tm extends ti{constructor(e,t){super(e,"not-in",t)}matches(e){if(eQ(this.value.arrayValue,{nullValue:"NULL_VALUE"}))return!1;let t=e.data.field(this.field);return null!==t&&void 0===t.nullValue&&!eQ(this.value.arrayValue,t)}}class tg extends ti{constructor(e,t){super(e,"array-contains-any",t)}matches(e){let t=e.data.field(this.field);return!(!e0(t)||!t.arrayValue.values)&&t.arrayValue.values.some(e=>eQ(this.value.arrayValue,e))}}class tp{constructor(e,t=null,r=[],n=[],i=null,s=null,a=null){this.path=e,this.collectionGroup=t,this.orderBy=r,this.filters=n,this.limit=i,this.startAt=s,this.endAt=a,this.Pe=null}}function ty(e,t=null,r=[],n=[],i=null,s=null,a=null){return new tp(e,t,r,n,i,s,a)}function tw(e){if(null===e.Pe){let t=e.path.canonicalString();null!==e.collectionGroup&&(t+="|cg:"+e.collectionGroup),t+="|f:",t+=e.filters.map(e=>(function e(t){if(t instanceof ti)return t.field.canonicalString()+t.op.toString()+eJ(t.value);if(to(t)&&ta(t))return t.filters.map(t=>e(t)).join(",");{let r=t.filters.map(t=>e(t)).join(",");return`${t.op}(${r})`}})(e)).join(","),t+="|ob:",t+=e.orderBy.map(e=>e.field.canonicalString()+e.dir).join(","),ef(e.limit)||(t+="|l:",t+=e.limit),e.startAt&&(t+="|lb:",t+=e.startAt.inclusive?"b:":"a:",t+=e.startAt.position.map(e=>eJ(e)).join(",")),e.endAt&&(t+="|ub:",t+=e.endAt.inclusive?"a:":"b:",t+=e.endAt.position.map(e=>eJ(e)).join(",")),e.Pe=t}return e.Pe}function tv(e,t){if(e.limit!==t.limit||e.orderBy.length!==t.orderBy.length)return!1;for(let i=0;i<e.orderBy.length;i++){var r,n;if(r=e.orderBy[i],n=t.orderBy[i],!(r.dir===n.dir&&r.field.isEqual(n.field)))return!1}if(e.filters.length!==t.filters.length)return!1;for(let r=0;r<e.filters.length;r++)if(!function e(t,r){return t instanceof ti?r instanceof ti&&t.op===r.op&&t.field.isEqual(r.field)&&eK(t.value,r.value):t instanceof ts?r instanceof ts&&t.op===r.op&&t.filters.length===r.filters.length&&t.filters.reduce((t,n,i)=>t&&e(n,r.filters[i]),!0):void S(19439)}(e.filters[r],t.filters[r]))return!1;return e.collectionGroup===t.collectionGroup&&!!e.path.isEqual(t.path)&&!!tt(e.startAt,t.startAt)&&tt(e.endAt,t.endAt)}function t_(e){return H.isDocumentKey(e.path)&&null===e.collectionGroup&&0===e.filters.length}class tE{constructor(e,t=null,r=[],n=[],i=null,s="F",a=null,o=null){this.path=e,this.collectionGroup=t,this.explicitOrderBy=r,this.filters=n,this.limit=i,this.limitType=s,this.startAt=a,this.endAt=o,this.Te=null,this.Ie=null,this.de=null,this.startAt,this.endAt}}function tT(e){return new tE(e)}function tI(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 tS(e){return null!==e.collectionGroup}function tb(e){if(null===e.Te){let t;e.Te=[];let r=new Set;for(let t of e.explicitOrderBy)e.Te.push(t),r.add(t.field.canonicalString());let n=e.explicitOrderBy.length>0?e.explicitOrderBy[e.explicitOrderBy.length-1].dir:"asc";
1(t=new eE(W.comparator),e.filters.forEach(e=>{e.getFlattenedFilters().forEach(e=>{e.isInequality()&&(t=t.add(e.field))})}),t).forEach(t=>{r.has(t.canonicalString())||t.isKeyField()||e.Te.push(new tr(t,n))}),r.has(W.keyField().canonicalString())||e.Te.push(new tr(W.keyField(),n))}return e.Te}function tC(e){return e.Ie||(e.Ie=tA(e,tb(e))),e.Ie}function tA(e,t){if("F"===e.limitType)return ty(e.path,e.collectionGroup,t,e.filters,e.limit,e.startAt,e.endAt);{t=t.map(e=>{let t="desc"===e.dir?"asc":"desc";return new tr(e.field,t)});let r=e.endAt?new e7(e.endAt.position,e.endAt.inclusive):null,n=e.startAt?new e7(e.startAt.position,e.startAt.inclusive):null;return ty(e.path,e.collectionGroup,t,e.filters,e.limit,r,n)}}function tN(e,t){let r=e.filters.concat([t]);return new tE(e.path,e.collectionGroup,e.explicitOrderBy.slice(),r,e.limit,e.limitType,e.startAt,e.endAt)}function tD(e,t,r){return new tE(e.path,e.collectionGroup,e.explicitOrderBy.slice(),e.filters.slice(),t,r,e.startAt,e.endAt)}function tk(e,t){return tv(tC(e),tC(t))&&e.limitType===t.limitType}function tx(e){return`${tw(tC(e))}|lt:${e.limitType}`}function tR(e){var t;let r;return`Query(target=${r=(t=tC(e)).path.canonicalString(),null!==t.collectionGroup&&(r+=" collectionGroup="+t.collectionGroup),t.filters.length>0&&(r+=`, filters: [${t.filters.map(e=>(function e(t){return t instanceof ti?`${t.field.canonicalString()} ${t.op} ${eJ(t.value)}`:t instanceof ts?t.op.toString()+" {"+t.getFilters().map(e).join(" ,")+"}":"Filter"})(e)).join(", ")}]`),ef(t.limit)||(r+=", limit: "+t.limit),t.orderBy.length>0&&(r+=`, orderBy: [${t.orderBy.map(e=>`${e.field.canonicalString()} (${e.dir})`).join(", ")}]`),t.startAt&&(r+=", startAt: ",r+=t.startAt.inclusive?"b:":"a:",r+=t.startAt.position.map(e=>eJ(e)).join(",")),t.endAt&&(r+=", endAt: ",r+=t.endAt.inclusive?"a:":"b:",r+=t.endAt.position.map(e=>eJ(e)).join(",")),`Target(${r})`}; limitType=${e.limitType})`}function tV(e,t){return t.isFoundDocument()&&function(e,t){let r=t.key.path;return null!==e.collectionGroup?t.key.hasCollectionId(e.collectionGroup)&&e.path.isPrefixOf(r):H.isDocumentKey(e.path)?e.path.isEqual(r):e.path.isImmediateParentOf(r)}(e,t)&&function(e,t){for(let r of tb(e))if(!r.field.isKeyField()&&null===t.data.field(r.field))return!1;return!0}(e,t)&&function(e,t){for(let r of e.filters)if(!r.matches(t))return!1;return!0}(e,t)&&(!e.startAt||!!function(e,t,r){let n=te(e,t,r);return e.inclusive?n<=0:n<0}(e.startAt,tb(e),t))&&(!e.endAt||!!function(e,t,r){let n=te(e,t,r);return e.inclusive?n>=0:n>0}(e.endAt,tb(e),t))}function tO(e){return(t,r)=>{let n=!1;for(let i of tb(e)){let e=function(e,t,r){let n=e.field.isKeyField()?H.comparator(t.key,r.key):function(e,t,r){let n=t.data.field(e),i=r.data.field(e);return null!==n&&null!==i?eW(n,i):S(42886)}(e.field,t,r);switch(e.dir){case"asc":return n;case"desc":return -1*n;default:return S(19790,{direction:e.dir})}}(i,t,r);if(0!==e)return e;n=n||i.field.isKeyField()}return 0}}class tF{constructor(e,t){this.mapKeyFn=e,this.equalsFn=t,this.inner={},this.innerSize=0}get(e){let t=this.mapKeyFn(e),r=this.inner[t];if(void 0!==r){for(let[t,n]of r)if(this.equalsFn(t,e))return n}}has(e){return void 0!==this.get(e)}set(e,t){let r=this.mapKeyFn(e),n=this.inner[r];if(void 0===n)return this.inner[r]=[[e,t]],void this.innerSize++;for(let r=0;r<n.length;r++)if(this.equalsFn(n[r][0],e))return void(n[r]=[e,t]);n.push([e,t]),this.innerSize++}delete(e){let t=this.mapKeyFn(e),r=this.inner[t];if(void 0===r)return!1;for(let n=0;n<r.length;n++)if(this.equalsFn(r[n][0],e))return 1===r.length?delete this.inner[t]:r.splice(n,1),this.innerSize--,!0;return!1}forEach(e){ep(this.inner,(t,r)=>{for(let[t,n]of r)e(t,n)})}isEmpty(){return ey(this.inner)}size(){return this.innerSize}}let tL=new ew(H.comparator),tM=new ew(H.comparator);function tP(...e){let t=tM;for(let r of e)t=t.insert(r.key,r);return t}function tU(e){let t=tM;return e.forEach((e,r)=>t=t.insert(e,r.overlayedDocument)),t}function tq(){return new tF(e=>e.toString(),(e,t)=>e.isEqual(t))}let t$=new ew(H.comparator),tB=new eE(H.comparator);function tz(...e){let t=tB;for(let r of e)t=t.add(r);return t}let tj=new eE(q);function tG(e,t){if(e.useProto3Json){if(isNaN(t))return{doubleValue:"NaN"};if(t===1/0)return{doubleValue:"Infinity"};if(t===-1/0)return{doubleValue:"-Infinity"}}return{doubleValue:em(t)?"-0":t}}function tK(e){return{integerValue:""+e}}class tQ{constructor(){this._=void 0}}function tW(e,t){return e instanceof t0?eZ(t)||t&&"doubleValue"in t?t:{integerValue:0}:null}class tH extends tQ{}class tY extends tQ{constructor(e){super(),this.elements=e}}function tJ(e,t){let r=t2(t);for(let t of e.elements)r.some(e=>eK(e,t))||r.push(t);return{arrayValue:{values:r}}}class tX extends tQ{constructor(e){super(),this.elements=e}}function tZ(e,t){let r=t2(t);for(let t of e.elements)r=r.filter(e=>!eK(e,t));return{arrayValue:{values:r}}}
1class t0 extends tQ{constructor(e,t){super(),this.serializer=e,this.Ee=t}}function t1(e){return eN(e.integerValue||e.doubleValue)}function t2(e){return e0(e)&&e.arrayValue.values?e.arrayValue.values.slice():[]}class t3{constructor(e,t){this.field=e,this.transform=t}}class t4{constructor(e,t){this.version=e,this.transformResults=t}}class t6{constructor(e,t){this.updateTime=e,this.exists=t}static none(){return new t6}static exists(e){return new t6(void 0,e)}static updateTime(e){return new t6(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 t5(e,t){return void 0!==e.updateTime?t.isFoundDocument()&&t.version.isEqual(e.updateTime):void 0===e.exists||e.exists===t.isFoundDocument()}class t8{}function t9(e,t){if(!e.hasLocalMutations||t&&0===t.fields.length)return null;if(null===t)return e.isNoDocument()?new ra(e.key,t6.none()):new rt(e.key,e.data,t6.none());{let r=e.data,n=e8.empty(),i=new eE(W.comparator);for(let e of t.fields)if(!i.has(e)){let t=r.field(e);null===t&&e.length>1&&(e=e.popLast(),t=r.field(e)),null===t?n.delete(e):n.set(e,t),i=i.add(e)}return new rr(e.key,n,new eI(i.toArray()),t6.none())}}function t7(e,t,r,n){return e instanceof rt?function(e,t,r,n){if(!t5(e.precondition,t))return r;let i=e.value.clone(),s=rs(e.fieldTransforms,n,t);return i.setAll(s),t.convertToFoundDocument(t.version,i).setHasLocalMutations(),null}(e,t,r,n):e instanceof rr?function(e,t,r,n){if(!t5(e.precondition,t))return r;let i=rs(e.fieldTransforms,n,t),s=t.data;return(s.setAll(rn(e)),s.setAll(i),t.convertToFoundDocument(t.version,s).setHasLocalMutations(),null===r)?null:r.unionWith(e.fieldMask.fields).unionWith(e.fieldTransforms.map(e=>e.field))}(e,t,r,n):t5(e.precondition,t)?(t.convertToNoDocument(t.version).setHasLocalMutations(),null):r}function re(e,t){var r,n;return e.type===t.type&&!!e.key.isEqual(t.key)&&!!e.precondition.isEqual(t.precondition)&&(r=e.fieldTransforms,n=t.fieldTransforms,!!(void 0===r&&void 0===n||!(!r||!n)&&z(r,n,(e,t)=>{var r,n;return e.field.isEqual(t.field)&&(r=e.transform,n=t.transform,r instanceof tY&&n instanceof tY||r instanceof tX&&n instanceof tX?z(r.elements,n.elements,eK):r instanceof t0&&n instanceof t0?eK(r.Ee,n.Ee):r instanceof tH&&n instanceof tH)})))&&(0===e.type?e.value.isEqual(t.value):1!==e.type||e.data.isEqual(t.data)&&e.fieldMask.isEqual(t.fieldMask))}class rt extends t8{constructor(e,t,r,n=[]){super(),this.key=e,this.value=t,this.precondition=r,this.fieldTransforms=n,this.type=0}getFieldMask(){return null}}class rr extends t8{constructor(e,t,r,n,i=[]){super(),this.key=e,this.data=t,this.fieldMask=r,this.precondition=n,this.fieldTransforms=i,this.type=1}getFieldMask(){return this.fieldMask}}function rn(e){let t=new Map;return e.fieldMask.fields.forEach(r=>{if(!r.isEmpty()){let n=e.data.field(r);t.set(r,n)}}),t}function ri(e,t,r){let n=new Map;C(e.length===r.length,32656,{Ae:r.length,Re:e.length});for(let s=0;s<r.length;s++){var i;let a=e[s],o=a.transform,l=t.data.field(a.field);n.set(a.field,(i=r[s],o instanceof tY?tJ(o,l):o instanceof tX?tZ(o,l):i))}return n}function rs(e,t,r){let n=new Map;for(let i of e){let e=i.transform,s=r.data.field(i.field);n.set(i.field,e instanceof tH?function(e,t){let r={fields:{[ex]:{stringValue:ek},[eV]:{timestampValue:{seconds:e.seconds,nanos:e.nanoseconds}}}};return t&&eO(t)&&(t=eF(t)),t&&(r.fields[eR]=t),{mapValue:r}}(t,s):e instanceof tY?tJ(e,s):e instanceof tX?tZ(e,s):function(e,t){let r=tW(e,t),n=t1(r)+t1(e.Ee);return eZ(r)&&eZ(e.Ee)?tK(n):tG(e.serializer,n)}(e,s))}return n}class ra extends t8{constructor(e,t){super(),this.key=e,this.precondition=t,this.type=2,this.fieldTransforms=[]}getFieldMask(){return null}}class ro extends t8{constructor(e,t){super(),this.key=e,this.precondition=t,this.type=3,this.fieldTransforms=[]}getFieldMask(){return null}}class rl{constructor(e,t,r,n){this.batchId=e,this.localWriteTime=t,this.baseMutations=r,this.mutations=n}applyToRemoteDocument(e,t){let r=t.mutationResults;for(let t=0;t<this.mutations.length;t++){let n=this.mutations[t];n.key.isEqual(e.key)&&function(e,t,r){e instanceof rt?function(e,t,r){let n=e.value.clone(),i=ri(e.fieldTransforms,t,r.transformResults);n.setAll(i),t.convertToFoundDocument(r.version,n).setHasCommittedMutations()}(e,t,r):e instanceof rr?function(e,t,r){if(!t5(e.precondition,t))return t.convertToUnknownDocument(r.version);let n=ri(e.fieldTransforms,t,r.transformResults),i=t.data;i.setAll(rn(e)),i.setAll(n),t.convertToFoundDocument(r.version,i).setHasCommittedMutations()}(e,t,r):t.convertToNoDocument(r.version).setHasCommittedMutations()}(n,e,r[t])}}applyToLocalView(e,t){for(let r of this.baseMutations)r.key.isEqual(e.key)&&
1(t=t7(r,e,t,this.localWriteTime));for(let r of this.mutations)r.key.isEqual(e.key)&&(t=t7(r,e,t,this.localWriteTime));return t}applyToLocalDocumentSet(e,t){let r=tq();return this.mutations.forEach(n=>{let i=e.get(n.key),s=i.overlayedDocument,a=this.applyToLocalView(s,i.mutatedFields),o=t9(s,a=t.has(n.key)?null:a);null!==o&&r.set(n.key,o),s.isValidDocument()||s.convertToNoDocument(es.min())}),r}keys(){return this.mutations.reduce((e,t)=>e.add(t.key),tz())}isEqual(e){return this.batchId===e.batchId&&z(this.mutations,e.mutations,(e,t)=>re(e,t))&&z(this.baseMutations,e.baseMutations,(e,t)=>re(e,t))}}class ru{constructor(e,t,r,n){this.batch=e,this.commitVersion=t,this.mutationResults=r,this.docVersions=n}static from(e,t,r){C(e.mutations.length===r.length,58842,{Ve:e.mutations.length,me:r.length});let n=t$,i=e.mutations;for(let e=0;e<i.length;e++)n=n.insert(i[e].key,r[e].version);return new ru(e,t,r,n)}}class rh{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{
2      largestBatchId: ${this.largestBatchId},
3      mutation: ${this.mutation.toString()}
4    }`}}class rc{constructor(e,t,r){this.alias=e,this.aggregateType=t,this.fieldPath=r}}class rd{constructor(e,t){this.count=e,this.unchangedNames=t}}function rf(e){switch(e){case A.OK:return S(64938);case A.CANCELLED:case A.UNKNOWN:case A.DEADLINE_EXCEEDED:case A.RESOURCE_EXHAUSTED:case A.INTERNAL:case A.UNAVAILABLE:case A.UNAUTHENTICATED:return!1;case A.INVALID_ARGUMENT:case A.NOT_FOUND:case A.ALREADY_EXISTS:case A.PERMISSION_DENIED:case A.FAILED_PRECONDITION:case A.ABORTED:case A.OUT_OF_RANGE:case A.UNIMPLEMENTED:case A.DATA_LOSS:return!0;default:return S(15467,{code:e})}}function rm(e){if(void 0===e)return E("GRPC error has no .code"),A.UNKNOWN;switch(e){case n.OK:return A.OK;case n.CANCELLED:return A.CANCELLED;case n.UNKNOWN:return A.UNKNOWN;case n.DEADLINE_EXCEEDED:return A.DEADLINE_EXCEEDED;case n.RESOURCE_EXHAUSTED:return A.RESOURCE_EXHAUSTED;case n.INTERNAL:return A.INTERNAL;case n.UNAVAILABLE:return A.UNAVAILABLE;case n.UNAUTHENTICATED:return A.UNAUTHENTICATED;case n.INVALID_ARGUMENT:return A.INVALID_ARGUMENT;case n.NOT_FOUND:return A.NOT_FOUND;case n.ALREADY_EXISTS:return A.ALREADY_EXISTS;case n.PERMISSION_DENIED:return A.PERMISSION_DENIED;case n.FAILED_PRECONDITION:return A.FAILED_PRECONDITION;case n.ABORTED:return A.ABORTED;case n.OUT_OF_RANGE:return A.OUT_OF_RANGE;case n.UNIMPLEMENTED:return A.UNIMPLEMENTED;case n.DATA_LOSS:return A.DATA_LOSS;default:return S(39323,{code:e})}}(i=n||(n={}))[i.OK=0]="OK",i[i.CANCELLED=1]="CANCELLED",i[i.UNKNOWN=2]="UNKNOWN",i[i.INVALID_ARGUMENT=3]="INVALID_ARGUMENT",i[i.DEADLINE_EXCEEDED=4]="DEADLINE_EXCEEDED",i[i.NOT_FOUND=5]="NOT_FOUND",i[i.ALREADY_EXISTS=6]="ALREADY_EXISTS",i[i.PERMISSION_DENIED=7]="PERMISSION_DENIED",i[i.UNAUTHENTICATED=16]="UNAUTHENTICATED",i[i.RESOURCE_EXHAUSTED=8]="RESOURCE_EXHAUSTED",i[i.FAILED_PRECONDITION=9]="FAILED_PRECONDITION",i[i.ABORTED=10]="ABORTED",i[i.OUT_OF_RANGE=11]="OUT_OF_RANGE",i[i.UNIMPLEMENTED=12]="UNIMPLEMENTED",i[i.INTERNAL=13]="INTERNAL",i[i.UNAVAILABLE=14]="UNAVAILABLE",i[i.DATA_LOSS=15]="DATA_LOSS";let rg=new c.jz([0xffffffff,0xffffffff],0);function rp(e){let t=P().encode(e),r=new c.VV;return r.update(t),new Uint8Array(r.digest())}function ry(e){let t=new DataView(e.buffer),r=t.getUint32(0,!0),n=t.getUint32(4,!0),i=t.getUint32(8,!0),s=t.getUint32(12,!0);return[new c.jz([r,n],0),new c.jz([i,s],0)]}class rw{constructor(e,t,r){if(this.bitmap=e,this.padding=t,this.hashCount=r,t<0||t>=8)throw new rv(`Invalid padding: ${t}`);if(r<0||e.length>0&&0===this.hashCount)throw new rv(`Invalid hash count: ${r}`);if(0===e.length&&0!==t)throw new rv(`Invalid padding when bitmap length is 0: ${t}`);this.fe=8*e.length-t,this.ge=c.jz.fromNumber(this.fe)}pe(e,t,r){let n=e.add(t.multiply(c.jz.fromNumber(r)));return 1===n.compare(rg)&&(n=new c.jz([n.getBits(0),n.getBits(1)],0)),n.modulo(this.ge).toNumber()}ye(e){return!!(this.bitmap[Math.floor(e/8)]&1<<e%8)}mightContain(e){if(0===this.fe)return!1;let[t,r]=ry(rp(e));for(let e=0;e<this.hashCount;e++){let n=this.pe(t,r,e);if(!this.ye(n))return!1}return!0}static create(e,t,r){let n=new rw(new Uint8Array(Math.ceil(e/8)),e%8==0?0:8-e%8,t);
4return r.forEach(e=>n.insert(e)),n}insert(e){if(0===this.fe)return;let[t,r]=ry(rp(e));for(let e=0;e<this.hashCount;e++){let n=this.pe(t,r,e);this.we(n)}}we(e){let t=Math.floor(e/8);this.bitmap[t]|=1<<e%8}}class rv extends Error{constructor(){super(...arguments),this.name="BloomFilterError"}}class r_{constructor(e,t,r,n,i){this.snapshotVersion=e,this.targetChanges=t,this.targetMismatches=r,this.documentUpdates=n,this.resolvedLimboDocuments=i}static createSynthesizedRemoteEventForCurrentChange(e,t,r){let n=new Map;return n.set(e,rE.createSynthesizedTargetChangeForCurrentChange(e,t,r)),new r_(es.min(),n,new ew(q),tL,tz())}}class rE{constructor(e,t,r,n,i){this.resumeToken=e,this.current=t,this.addedDocuments=r,this.modifiedDocuments=n,this.removedDocuments=i}static createSynthesizedTargetChangeForCurrentChange(e,t,r){return new rE(r,t,tz(),tz(),tz())}}class rT{constructor(e,t,r,n){this.Se=e,this.removedTargetIds=t,this.key=r,this.be=n}}class rI{constructor(e,t){this.targetId=e,this.De=t}}class rS{constructor(e,t,r=eb.EMPTY_BYTE_STRING,n=null){this.state=e,this.targetIds=t,this.resumeToken=r,this.cause=n}}class rb{constructor(){this.ve=0,this.Ce=rN(),this.Fe=eb.EMPTY_BYTE_STRING,this.Me=!1,this.xe=!0}get current(){return this.Me}get resumeToken(){return this.Fe}get Oe(){return 0!==this.ve}get Ne(){return this.xe}Be(e){e.approximateByteSize()>0&&(this.xe=!0,this.Fe=e)}Le(){let e=tz(),t=tz(),r=tz();return this.Ce.forEach((n,i)=>{switch(i){case 0:e=e.add(n);break;case 2:t=t.add(n);break;case 1:r=r.add(n);break;default:S(38017,{changeType:i})}}),new rE(this.Fe,this.Me,e,t,r)}ke(){this.xe=!1,this.Ce=rN()}qe(e,t){this.xe=!0,this.Ce=this.Ce.insert(e,t)}Qe(e){this.xe=!0,this.Ce=this.Ce.remove(e)}$e(){this.ve+=1}Ue(){this.ve-=1,C(this.ve>=0,3241,{ve:this.ve})}Ke(){this.xe=!0,this.Me=!0}}class rC{constructor(e){this.We=e,this.Ge=new Map,this.ze=tL,this.je=rA(),this.Je=rA(),this.He=new ew(q)}Ye(e){for(let t of e.Se)e.be&&e.be.isFoundDocument()?this.Ze(t,e.be):this.Xe(t,e.key,e.be);for(let t of e.removedTargetIds)this.Xe(t,e.key,e.be)}et(e){this.forEachTarget(e,t=>{let r=this.tt(t);switch(e.state){case 0:this.nt(t)&&r.Be(e.resumeToken);break;case 1:r.Ue(),r.Oe||r.ke(),r.Be(e.resumeToken);break;case 2:r.Ue(),r.Oe||this.removeTarget(t);break;case 3:this.nt(t)&&(r.Ke(),r.Be(e.resumeToken));break;case 4:this.nt(t)&&(this.rt(t),r.Be(e.resumeToken));break;default:S(56790,{state:e.state})}})}forEachTarget(e,t){e.targetIds.length>0?e.targetIds.forEach(t):this.Ge.forEach((e,r)=>{this.nt(r)&&t(r)})}it(e){let t=e.targetId,r=e.De.count,n=this.st(t);if(n){let i=n.target;if(t_(i))if(0===r){let e=new H(i.path);this.Xe(t,e,e9.newNoDocument(e,es.min()))}else C(1===r,20013,{expectedCount:r});else{let n=this.ot(t);if(n!==r){let r=this._t(e),i=r?this.ut(r,e,n):1;0!==i&&(this.rt(t),this.He=this.He.insert(t,2===i?"TargetPurposeExistenceFilterMismatchBloom":"TargetPurposeExistenceFilterMismatch"))}}}}_t(e){let t,r,n=e.De.unchangedNames;if(!n||!n.bits)return null;let{bits:{bitmap:i="",padding:s=0},hashCount:a=0}=n;try{t=eD(i).toUint8Array()}catch(e){if(e instanceof eS)return T("Decoding the base64 bloom filter in existence filter failed ("+e.message+"); ignoring the bloom filter and falling back to full re-query."),null;throw e}try{r=new rw(t,s,a)}catch(e){return T(e instanceof rv?"BloomFilter error: ":"Applying bloom filter failed: ",e),null}return 0===r.fe?null:r}ut(e,t,r){return 2*(t.De.count!==r-this.ht(e,t.targetId))}ht(e,t){let r=this.We.getRemoteKeysForTarget(t),n=0;return r.forEach(r=>{let i=this.We.lt(),s=`projects/${i.projectId}/databases/${i.database}/documents/${r.path.canonicalString()}`;e.mightContain(s)||(this.Xe(t,r,null),n++)}),n}Pt(e){let t=new Map;this.Ge.forEach((r,n)=>{let i=this.st(n);if(i){if(r.current&&t_(i.target)){let t=new H(i.target.path);this.Tt(t).has(n)||this.It(n,t)||this.Xe(n,t,e9.newNoDocument(t,e))}r.Ne&&(t.set(n,r.Le()),r.ke())}});let r=tz();this.Je.forEach((e,t)=>{let n=!0;t.forEachWhile(e=>{let t=this.st(e);return!t||"TargetPurposeLimboResolution"===t.purpose||(n=!1,!1)}),n&&(r=r.add(e))}),this.ze.forEach((t,r)=>r.setReadTime(e));let n=new r_(e,t,this.He,this.ze,r);return this.ze=tL,this.je=rA(),this.Je=rA(),this.He=new ew(q),n}Ze(e,t){if(!this.nt(e))return;
4let r=2*!!this.It(e,t.key);this.tt(e).qe(t.key,r),this.ze=this.ze.insert(t.key,t),this.je=this.je.insert(t.key,this.Tt(t.key).add(e)),this.Je=this.Je.insert(t.key,this.dt(t.key).add(e))}Xe(e,t,r){if(!this.nt(e))return;let n=this.tt(e);this.It(e,t)?n.qe(t,1):n.Qe(t),this.Je=this.Je.insert(t,this.dt(t).delete(e)),this.Je=this.Je.insert(t,this.dt(t).add(e)),r&&(this.ze=this.ze.insert(t,r))}removeTarget(e){this.Ge.delete(e)}ot(e){let t=this.tt(e).Le();return this.We.getRemoteKeysForTarget(e).size+t.addedDocuments.size-t.removedDocuments.size}$e(e){this.tt(e).$e()}tt(e){let t=this.Ge.get(e);return t||(t=new rb,this.Ge.set(e,t)),t}dt(e){let t=this.Je.get(e);return t||(t=new eE(q),this.Je=this.Je.insert(e,t)),t}Tt(e){let t=this.je.get(e);return t||(t=new eE(q),this.je=this.je.insert(e,t)),t}nt(e){let t=null!==this.st(e);return t||_("WatchChangeAggregator","Detected inactive target",e),t}st(e){let t=this.Ge.get(e);return t&&t.Oe?null:this.We.Et(e)}rt(e){this.Ge.set(e,new rb),this.We.getRemoteKeysForTarget(e).forEach(t=>{this.Xe(e,t,null)})}It(e,t){return this.We.getRemoteKeysForTarget(e).has(t)}}function rA(){return new ew(H.comparator)}function rN(){return new ew(H.comparator)}let rD={asc:"ASCENDING",desc:"DESCENDING"},rk={"<":"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"},rx={and:"AND",or:"OR"};class rR{constructor(e,t){this.databaseId=e,this.useProto3Json=t}}function rV(e,t){return e.useProto3Json||ef(t)?t:{value:t}}function rO(e,t){return e.useProto3Json?`${new Date(1e3*t.seconds).toISOString().replace(/\.\d*/,"").replace("Z","")}.${("000000000"+t.nanoseconds).slice(-9)}Z`:{seconds:""+t.seconds,nanos:t.nanoseconds}}function rF(e,t){return e.useProto3Json?t.toBase64():t.toUint8Array()}function rL(e){return C(!!e,49232),es.fromTimestamp(function(e){let t=eA(e);return new ei(t.seconds,t.nanos)}(e))}function rM(e,t){return rP(e,t).canonicalString()}function rP(e,t){let r=new K(["projects",e.projectId,"databases",e.database]).child("documents");return void 0===t?r:r.child(t)}function rU(e){let t=K.fromString(e);return C(rY(t),10190,{key:t.toString()}),t}function rq(e,t){return rM(e.databaseId,t.path)}function r$(e,t){let r=rU(t);if(r.get(1)!==e.databaseId.projectId)throw new N(A.INVALID_ARGUMENT,"Tried to deserialize key from different project: "+r.get(1)+" vs "+e.databaseId.projectId);if(r.get(3)!==e.databaseId.database)throw new N(A.INVALID_ARGUMENT,"Tried to deserialize key from different database: "+r.get(3)+" vs "+e.databaseId.database);return new H(rj(r))}function rB(e,t){return rM(e.databaseId,t)}function rz(e){return new K(["projects",e.databaseId.projectId,"databases",e.databaseId.database]).canonicalString()}function rj(e){return C(e.length>4&&"documents"===e.get(4),29091,{key:e.toString()}),e.popFirst(5)}function rG(e,t,r){return{name:rq(e,t),fields:r.value.mapValue.fields}}function rK(e,t){var r;let n;if(t instanceof rt)n={update:rG(e,t.key,t.value)};else if(t instanceof ra)n={delete:rq(e,t.key)};else if(t instanceof rr)n={update:rG(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 ro))return S(16599,{Rt:t.type});n={verify:rq(e,t.key)}}return t.fieldTransforms.length>0&&(n.updateTransforms=t.fieldTransforms.map(e=>(function(e,t){let r=t.transform;if(r instanceof tH)return{fieldPath:t.field.canonicalString(),setToServerValue:"REQUEST_TIME"};if(r instanceof tY)return{fieldPath:t.field.canonicalString(),appendMissingElements:{values:r.elements}};if(r instanceof tX)return{fieldPath:t.field.canonicalString(),removeAllFromArray:{values:r.elements}};if(r instanceof t0)return{fieldPath:t.field.canonicalString(),increment:r.Ee};throw S(20930,{transform:t.transform})})(0,e))),t.precondition.isNone||(n.currentDocument=void 0!==(r=t.precondition).updateTime?{updateTime:rO(e,r.updateTime.toTimestamp())}:void 0!==r.exists?{exists:r.exists}:S(27497)),n}function rQ(e,t){var r,n;let i,s={structuredQuery:{}},a=t.path;null!==t.collectionGroup?(i=a,s.structuredQuery.from=[{collectionId:t.collectionGroup,allDescendants:!0}]):(i=a.popLast(),s.structuredQuery.from=[{collectionId:a.lastSegment()}]),s.parent=rB(e,i);let o=function(e){if(0!==e.length)return function e(t){return t instanceof ti?function(e){if("=="===e.op){if(e2(e.value))return{unaryFilter:{field:rW(e.field),op:"IS_NAN"}};if(e1(e.value))return{unaryFilter:{field:rW(e.field),op:"IS_NULL"}}}else if("!="===e.op){if(e2(e.value))return{unaryFilter:{field:rW(e.field),op:"IS_NOT_NA
4N"}};if(e1(e.value))return{unaryFilter:{field:rW(e.field),op:"IS_NOT_NULL"}}}return{fieldFilter:{field:rW(e.field),op:rk[e.op],value:e.value}}}(t):t instanceof ts?function(t){let r=t.getFilters().map(t=>e(t));return 1===r.length?r[0]:{compositeFilter:{op:rx[t.op],filters:r}}}(t):S(54877,{filter:t})}(ts.create(e,"and"))}(t.filters);o&&(s.structuredQuery.where=o);let l=function(e){if(0!==e.length)return e.map(e=>({field:rW(e.field),direction:rD[e.dir]}))}(t.orderBy);l&&(s.structuredQuery.orderBy=l);let u=rV(e,t.limit);return null!==u&&(s.structuredQuery.limit=u),t.startAt&&(s.structuredQuery.startAt={before:(r=t.startAt).inclusive,values:r.position}),t.endAt&&(s.structuredQuery.endAt={before:!(n=t.endAt).inclusive,values:n.position}),{Vt:s,parent:i}}function rW(e){return{fieldPath:e.canonicalString()}}function rH(e){return W.fromServerFormat(e.fieldPath)}function rY(e){return e.length>=4&&"projects"===e.get(0)&&"databases"===e.get(2)}class rJ{constructor(e,t,r,n,i=es.min(),s=es.min(),a=eb.EMPTY_BYTE_STRING,o=null){this.target=e,this.targetId=t,this.purpose=r,this.sequenceNumber=n,this.snapshotVersion=i,this.lastLimboFreeSnapshotVersion=s,this.resumeToken=a,this.expectedCount=o}withSequenceNumber(e){return new rJ(this.target,this.targetId,this.purpose,e,this.snapshotVersion,this.lastLimboFreeSnapshotVersion,this.resumeToken,this.expectedCount)}withResumeToken(e,t){return new rJ(this.target,this.targetId,this.purpose,this.sequenceNumber,t,this.lastLimboFreeSnapshotVersion,e,null)}withExpectedCount(e){return new rJ(this.target,this.targetId,this.purpose,this.sequenceNumber,this.snapshotVersion,this.lastLimboFreeSnapshotVersion,this.resumeToken,e)}withLastLimboFreeSnapshotVersion(e){return new rJ(this.target,this.targetId,this.purpose,this.sequenceNumber,this.snapshotVersion,e,this.resumeToken,this.expectedCount)}}class rX{constructor(e){this.gt=e}}class rZ{constructor(){}bt(e,t){this.Dt(e,t),t.vt()}Dt(e,t){if("nullValue"in e)this.Ct(t,5);else if("booleanValue"in e)this.Ct(t,10),t.Ft(+!!e.booleanValue);else if("integerValue"in e)this.Ct(t,15),t.Ft(eN(e.integerValue));else if("doubleValue"in e){let r=eN(e.doubleValue);isNaN(r)?this.Ct(t,13):(this.Ct(t,15),em(r)?t.Ft(0):t.Ft(r))}else if("timestampValue"in e){let r=e.timestampValue;this.Ct(t,20),"string"==typeof r&&(r=eA(r)),t.Mt(`${r.seconds||""}`),t.Ft(r.nanos||0)}else if("stringValue"in e)this.xt(e.stringValue,t),this.Ot(t);else if("bytesValue"in e)this.Ct(t,30),t.Nt(eD(e.bytesValue)),this.Ot(t);else if("referenceValue"in e)this.Bt(e.referenceValue,t);else if("geoPointValue"in e){let r=e.geoPointValue;this.Ct(t,45),t.Ft(r.latitude||0),t.Ft(r.longitude||0)}else"mapValue"in e?e5(e)?this.Ct(t,Number.MAX_SAFE_INTEGER):e4(e)?this.Lt(e.mapValue,t):(this.kt(e.mapValue,t),this.Ot(t)):"arrayValue"in e?(this.qt(e.arrayValue,t),this.Ot(t)):S(19022,{Qt:e})}xt(e,t){this.Ct(t,25),this.$t(e,t)}$t(e,t){t.Mt(e)}kt(e,t){let r=e.fields||{};for(let e of(this.Ct(t,55),Object.keys(r)))this.xt(e,t),this.Dt(r[e],t)}Lt(e,t){var r,n;let i=e.fields||{};this.Ct(t,53);let s=(null==(n=null==(r=i[ej].arrayValue)?void 0:r.values)?void 0:n.length)||0;this.Ct(t,15),t.Ft(eN(s)),this.xt(ej,t),this.Dt(i[ej],t)}qt(e,t){let r=e.values||[];for(let e of(this.Ct(t,50),r))this.Dt(e,t)}Bt(e,t){this.Ct(t,37),H.fromName(e).path.forEach(e=>{this.Ct(t,60),this.$t(e,t)})}Ct(e,t){e.Ft(t)}Ot(e){e.Ft(2)}}rZ.Ut=new rZ;class r0{constructor(){this.Dn=new r1}addToCollectionParentIndex(e,t){return this.Dn.add(t),eh.resolve()}getCollectionParents(e,t){return eh.resolve(this.Dn.getEntries(t))}addFieldIndex(e,t){return eh.resolve()}deleteFieldIndex(e,t){return eh.resolve()}deleteAllFieldIndexes(e){return eh.resolve()}createTargetIndexes(e,t){return eh.resolve()}getDocumentsMatchingTarget(e,t){return eh.resolve(null)}getIndexType(e,t){return eh.resolve(0)}getFieldIndexes(e,t){return eh.resolve([])}getNextCollectionGroupToUpdate(e){return eh.resolve(null)}getMinOffset(e,t){return eh.resolve(eo.min())}getMinOffsetFromCollectionGroup(e,t){return eh.resolve(eo.min())}updateCollectionGroup(e,t,r){return eh.resolve()}updateIndexEntries(e,t){return eh.resolve()}}class r1{constructor(){this.index={}}add(e){let t=e.lastSegment(),r=e.popLast(),n=this.index[t]||new eE(K.comparator),i=!n.has(r);return this.index[t]=n.add(r),i}has(e){let t=e.lastSegment(),r=e.popLast(),n=this.index[t];return n&&n.has(r)}getEntries(e){return(this.index[e]||new eE(K.comparator)).toArray()}}new Uint8Array(0);let r2={didRun:!1,sequenceNumbersCollected:0,targetsRemoved:0,documentsRemoved:0};class r3{static withCacheSize(e){return new r3(e,r3.DEFAULT_COLLECTION_PE
4RCENTILE,r3.DEFAULT_MAX_SEQUENCE_NUMBERS_TO_COLLECT)}constructor(e,t,r){this.cacheSizeCollectionThreshold=e,this.percentileToCollect=t,this.maximumSequenceNumbersToCollect=r}}r3.DEFAULT_COLLECTION_PERCENTILE=10,r3.DEFAULT_MAX_SEQUENCE_NUMBERS_TO_COLLECT=1e3,r3.DEFAULT=new r3(0x2800000,r3.DEFAULT_COLLECTION_PERCENTILE,r3.DEFAULT_MAX_SEQUENCE_NUMBERS_TO_COLLECT),r3.DISABLED=new r3(-1,0,0);class r4{constructor(e){this._r=e}next(){return this._r+=2,this._r}static ar(){return new r4(0)}static ur(){return new r4(-1)}}let r6="LruGarbageCollector";function r5([e,t],[r,n]){let i=q(e,r);return 0===i?q(t,n):i}class r8{constructor(e){this.Tr=e,this.buffer=new eE(r5),this.Ir=0}dr(){return++this.Ir}Er(e){let t=[e,this.dr()];if(this.buffer.size<this.Tr)this.buffer=this.buffer.add(t);else{let e=this.buffer.last();0>r5(t,e)&&(this.buffer=this.buffer.delete(e).add(t))}}get maxValue(){return this.buffer.last()[0]}}class r9{constructor(e,t,r){this.garbageCollector=e,this.asyncQueue=t,this.localStore=r,this.Ar=null}start(){-1!==this.garbageCollector.params.cacheSizeCollectionThreshold&&this.Rr(6e4)}stop(){this.Ar&&(this.Ar.cancel(),this.Ar=null)}get started(){return null!==this.Ar}Rr(e){_(r6,`Garbage collection scheduled in ${e}ms`),this.Ar=this.asyncQueue.enqueueAfterDelay("lru_garbage_collection",e,async()=>{this.Ar=null;try{await this.localStore.collectGarbage(this.garbageCollector)}catch(e){ec(e)?_(r6,"Ignoring IndexedDB error during garbage collection: ",e):await eu(e)}await this.Rr(3e5)})}}class r7{constructor(e,t){this.Vr=e,this.params=t}calculateTargetCount(e,t){return this.Vr.mr(e).next(e=>Math.floor(t/100*e))}nthSequenceNumber(e,t){if(0===t)return eh.resolve(ed.ue);let r=new r8(t);return this.Vr.forEachTarget(e,e=>r.Er(e.sequenceNumber)).next(()=>this.Vr.gr(e,e=>r.Er(e))).next(()=>r.maxValue)}removeTargets(e,t,r){return this.Vr.removeTargets(e,t,r)}removeOrphanedDocuments(e,t){return this.Vr.removeOrphanedDocuments(e,t)}collect(e,t){return -1===this.params.cacheSizeCollectionThreshold?(_("LruGarbageCollector","Garbage collection skipped; disabled"),eh.resolve(r2)):this.getCacheSize(e).next(r=>r<this.params.cacheSizeCollectionThreshold?(_("LruGarbageCollector",`Garbage collection skipped; Cache size ${r} is lower than threshold ${this.params.cacheSizeCollectionThreshold}`),r2):this.pr(e,t))}getCacheSize(e){return this.Vr.getCacheSize(e)}pr(e,t){let r,n,i,s,a,o,l,h=Date.now();return this.calculateTargetCount(e,this.params.percentileToCollect).next(t=>(t>this.params.maximumSequenceNumbersToCollect?(_("LruGarbageCollector",`Capping sequence numbers to collect down to the maximum of ${this.params.maximumSequenceNumbersToCollect} from ${t}`),n=this.params.maximumSequenceNumbersToCollect):n=t,s=Date.now(),this.nthSequenceNumber(e,n))).next(n=>(r=n,a=Date.now(),this.removeTargets(e,r,t))).next(t=>(i=t,o=Date.now(),this.removeOrphanedDocuments(e,r))).next(e=>(l=Date.now(),v()<=u.$b.DEBUG&&_("LruGarbageCollector",`LRU Garbage Collection
5	Counted targets in ${s-h}ms
6	Determined least recently used ${n} in `+(a-s)+"ms\n"+`	Removed ${i} targets in `+(o-a)+"ms\n"+`	Removed ${e} documents in `+(l-o)+"ms\n"+`Total Duration: ${l-h}ms`),eh.resolve({didRun:!0,sequenceNumbersCollected:n,targetsRemoved:i,documentsRemoved:e})))}}class ne{constructor(){this.changes=new tF(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,e9.newInvalidDocument(e).setReadTime(t))}getEntry(e,t){this.assertNotApplied();let r=this.changes.get(t);return void 0!==r?eh.resolve(r):this.getFromCache(e,t)}getEntries(e,t){return this.getAllFromCache(e,t)}apply(e){return this.assertNotApplied(),this.changesApplied=!0,this.applyChanges(e)}assertNotApplied(){}}class nt{constructor(e,t){this.overlayedDocument=e,this.mutatedFields=t}}class nr{constructor(e,t,r,n){this.remoteDocumentCache=e,this.mutationQueue=t,this.documentOverlayCache=r,this.indexManager=n}getDocument(e,t){let r=null;return this.documentOverlayCache.getOverlay(e,t).next(n=>(r=n,this.remoteDocumentCache.getEntry(e,t))).next(e=>(null!==r&&t7(r.mutation,e,eI.empty(),ei.now()),e))}getDocuments(e,t){return this.remoteDocumentCache.getEntries(e,t).next(t=>this.getLocalViewOfDocuments(e,t,tz()).next(()=>t))}getLocalViewOfDocuments(e,t,r=tz()){let n=tq();return this.populateOverlays(e,n,t).next(()=>this.computeViews(e,t,n,r).next(e=>{let t=tP();return e.forEach((e,r)=>{t=t.insert(e,r.overlayedDocument)}),t}))}getOverlayedDocuments(e,t){let r=tq();return this.populateOverlays(e,r,t).next(()=>this.computeViews(e,t,r,tz()))}populateOverlays(e,t,r){let n=[];
6return r.forEach(e=>{t.has(e)||n.push(e)}),this.documentOverlayCache.getOverlays(e,n).next(e=>{e.forEach((e,r)=>{t.set(e,r)})})}computeViews(e,t,r,n){let i=tL,s=tq(),a=tq();return t.forEach((e,t)=>{let a=r.get(t.key);n.has(t.key)&&(void 0===a||a.mutation instanceof rr)?i=i.insert(t.key,t):void 0!==a?(s.set(t.key,a.mutation.getFieldMask()),t7(a.mutation,t,a.mutation.getFieldMask(),ei.now())):s.set(t.key,eI.empty())}),this.recalculateAndSaveOverlays(e,i).next(e=>(e.forEach((e,t)=>s.set(e,t)),t.forEach((e,t)=>{var r;return a.set(e,new nt(t,null!=(r=s.get(e))?r:null))}),a))}recalculateAndSaveOverlays(e,t){let r=tq(),n=new ew((e,t)=>e-t),i=tz();return this.mutationQueue.getAllMutationBatchesAffectingDocumentKeys(e,t).next(e=>{for(let i of e)i.keys().forEach(e=>{let s=t.get(e);if(null===s)return;let a=r.get(e)||eI.empty();a=i.applyToLocalView(s,a),r.set(e,a);let o=(n.get(i.batchId)||tz()).add(e);n=n.insert(i.batchId,o)})}).next(()=>{let s=[],a=n.getReverseIterator();for(;a.hasNext();){let n=a.getNext(),o=n.key,l=n.value,u=tq();l.forEach(e=>{if(!i.has(e)){let n=t9(t.get(e),r.get(e));null!==n&&u.set(e,n),i=i.add(e)}}),s.push(this.documentOverlayCache.saveOverlays(e,o,u))}return eh.waitFor(s)}).next(()=>r)}recalculateAndSaveOverlaysForDocumentKeys(e,t){return this.remoteDocumentCache.getEntries(e,t).next(t=>this.recalculateAndSaveOverlays(e,t))}getDocumentsMatchingQuery(e,t,r,n){return H.isDocumentKey(t.path)&&null===t.collectionGroup&&0===t.filters.length?this.getDocumentsMatchingDocumentQuery(e,t.path):tS(t)?this.getDocumentsMatchingCollectionGroupQuery(e,t,r,n):this.getDocumentsMatchingCollectionQuery(e,t,r,n)}getNextDocuments(e,t,r,n){return this.remoteDocumentCache.getAllFromCollectionGroup(e,t,r,n).next(i=>{let s=n-i.size>0?this.documentOverlayCache.getOverlaysForCollectionGroup(e,t,r.largestBatchId,n-i.size):eh.resolve(tq()),a=-1,o=i;return s.next(t=>eh.forEach(t,(t,r)=>(a<r.largestBatchId&&(a=r.largestBatchId),i.get(t)?eh.resolve():this.remoteDocumentCache.getEntry(e,t).next(e=>{o=o.insert(t,e)}))).next(()=>this.populateOverlays(e,t,i)).next(()=>this.computeViews(e,o,t,tz())).next(e=>({batchId:a,changes:tU(e)})))})}getDocumentsMatchingDocumentQuery(e,t){return this.getDocument(e,new H(t)).next(e=>{let t=tP();return e.isFoundDocument()&&(t=t.insert(e.key,e)),t})}getDocumentsMatchingCollectionGroupQuery(e,t,r,n){let i=t.collectionGroup,s=tP();return this.indexManager.getCollectionParents(e,i).next(a=>eh.forEach(a,a=>{let o=new tE(a.child(i),null,t.explicitOrderBy.slice(),t.filters.slice(),t.limit,t.limitType,t.startAt,t.endAt);return this.getDocumentsMatchingCollectionQuery(e,o,r,n).next(e=>{e.forEach((e,t)=>{s=s.insert(e,t)})})}).next(()=>s))}getDocumentsMatchingCollectionQuery(e,t,r,n){let i;return this.documentOverlayCache.getOverlaysForCollection(e,t.path,r.largestBatchId).next(s=>(i=s,this.remoteDocumentCache.getDocumentsMatchingQuery(e,t,r,i,n))).next(e=>{i.forEach((t,r)=>{let n=r.getKey();null===e.get(n)&&(e=e.insert(n,e9.newInvalidDocument(n)))});let r=tP();return e.forEach((e,n)=>{let s=i.get(e);void 0!==s&&t7(s.mutation,n,eI.empty(),ei.now()),tV(t,n)&&(r=r.insert(e,n))}),r})}}class nn{constructor(e){this.serializer=e,this.Br=new Map,this.Lr=new Map}getBundleMetadata(e,t){return eh.resolve(this.Br.get(t))}saveBundleMetadata(e,t){return this.Br.set(t.id,{id:t.id,version:t.version,createTime:rL(t.createTime)}),eh.resolve()}getNamedQuery(e,t){return eh.resolve(this.Lr.get(t))}saveNamedQuery(e,t){return this.Lr.set(t.name,{name:t.name,query:function(e){let t=function(e){var t;let r,n=function(e){let t=rU(e);return 4===t.length?K.emptyPath():rj(t)}(e.parent),i=e.structuredQuery,s=i.from?i.from.length:0,a=null;if(s>0){C(1===s,65062);let e=i.from[0];e.allDescendants?a=e.collectionId:n=n.child(e.collectionId)}let o=[];i.where&&(o=function(e){var t;let r=function e(t){return void 0!==t.unaryFilter?function(e){switch(e.unaryFilter.op){case"IS_NAN":let t=rH(e.unaryFilter.field);return ti.create(t,"==",{doubleValue:NaN});case"IS_NULL":let r=rH(e.unaryFilter.field);return ti.create(r,"==",{nullValue:"NULL_VALUE"});
6case"IS_NOT_NAN":let n=rH(e.unaryFilter.field);return ti.create(n,"!=",{doubleValue:NaN});case"IS_NOT_NULL":let i=rH(e.unaryFilter.field);return ti.create(i,"!=",{nullValue:"NULL_VALUE"});case"OPERATOR_UNSPECIFIED":return S(61313);default:return S(60726)}}(t):void 0!==t.fieldFilter?ti.create(rH(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";case"OPERATOR_UNSPECIFIED":return S(58110);default:return S(50506)}}(t.fieldFilter.op),t.fieldFilter.value):void 0!==t.compositeFilter?ts.create(t.compositeFilter.filters.map(t=>e(t)),function(e){switch(e){case"AND":return"and";case"OR":return"or";default:return S(1026)}}(t.compositeFilter.op)):S(30097,{filter:t})}(e);return r instanceof ts&&to(t=r)&&ta(t)?r.getFilters():[r]}(i.where));let l=[];i.orderBy&&(l=i.orderBy.map(e=>new tr(rH(e.field),function(e){switch(e){case"ASCENDING":return"asc";case"DESCENDING":return"desc";default:return}}(e.direction))));let u=null;i.limit&&(u=ef(r="object"==typeof(t=i.limit)?t.value:t)?null:r);let h=null;i.startAt&&(h=function(e){let t=!!e.before;return new e7(e.values||[],t)}(i.startAt));let c=null;return i.endAt&&(c=function(e){let t=!e.before;return new e7(e.values||[],t)}(i.endAt)),new tE(n,a,l,o,u,"F",h,c)}({parent:e.parent,structuredQuery:e.structuredQuery});return"LAST"===e.limitType?tD(t,t.limit,"L"):t}(t.bundledQuery),readTime:rL(t.readTime)}),eh.resolve()}}class ni{constructor(){this.overlays=new ew(H.comparator),this.kr=new Map}getOverlay(e,t){return eh.resolve(this.overlays.get(t))}getOverlays(e,t){let r=tq();return eh.forEach(t,t=>this.getOverlay(e,t).next(e=>{null!==e&&r.set(t,e)})).next(()=>r)}saveOverlays(e,t,r){return r.forEach((r,n)=>{this.wt(e,t,n)}),eh.resolve()}removeOverlaysForBatchId(e,t,r){let n=this.kr.get(r);return void 0!==n&&(n.forEach(e=>this.overlays=this.overlays.remove(e)),this.kr.delete(r)),eh.resolve()}getOverlaysForCollection(e,t,r){let n=tq(),i=t.length+1,s=new H(t.child("")),a=this.overlays.getIteratorFrom(s);for(;a.hasNext();){let e=a.getNext().value,s=e.getKey();if(!t.isPrefixOf(s.path))break;s.path.length===i&&e.largestBatchId>r&&n.set(e.getKey(),e)}return eh.resolve(n)}getOverlaysForCollectionGroup(e,t,r,n){let i=new ew((e,t)=>e-t),s=this.overlays.getIterator();for(;s.hasNext();){let e=s.getNext().value;if(e.getKey().getCollectionGroup()===t&&e.largestBatchId>r){let t=i.get(e.largestBatchId);null===t&&(t=tq(),i=i.insert(e.largestBatchId,t)),t.set(e.getKey(),e)}}let a=tq(),o=i.getIterator();for(;o.hasNext()&&(o.getNext().value.forEach((e,t)=>a.set(e,t)),!(a.size()>=n)););return eh.resolve(a)}wt(e,t,r){let n=this.overlays.get(r.key);if(null!==n){let e=this.kr.get(n.largestBatchId).delete(r.key);this.kr.set(n.largestBatchId,e)}this.overlays=this.overlays.insert(r.key,new rh(t,r));let i=this.kr.get(t);void 0===i&&(i=tz(),this.kr.set(t,i)),this.kr.set(t,i.add(r.key))}}class ns{constructor(){this.sessionToken=eb.EMPTY_BYTE_STRING}getSessionToken(e){return eh.resolve(this.sessionToken)}setSessionToken(e,t){return this.sessionToken=t,eh.resolve()}}class na{constructor(){this.qr=new eE(no.Qr),this.$r=new eE(no.Ur)}isEmpty(){return this.qr.isEmpty()}addReference(e,t){let r=new no(e,t);this.qr=this.qr.add(r),this.$r=this.$r.add(r)}Kr(e,t){e.forEach(e=>this.addReference(e,t))}removeReference(e,t){this.Wr(new no(e,t))}Gr(e,t){e.forEach(e=>this.removeReference(e,t))}zr(e){let t=new H(new K([])),r=new no(t,e),n=new no(t,e+1),i=[];return this.$r.forEachInRange([r,n],e=>{this.Wr(e),i.push(e.key)}),i}jr(){this.qr.forEach(e=>this.Wr(e))}Wr(e){this.qr=this.qr.delete(e),this.$r=this.$r.delete(e)}Jr(e){let t=new H(new K([])),r=new no(t,e),n=new no(t,e+1),i=tz();return this.$r.forEachInRange([r,n],e=>{i=i.add(e.key)}),i}containsKey(e){let t=new no(e,0),r=this.qr.firstAfterOrEqual(t);return null!==r&&e.isEqual(r.key)}}class no{constructor(e,t){this.key=e,this.Hr=t}
6static Qr(e,t){return H.comparator(e.key,t.key)||q(e.Hr,t.Hr)}static Ur(e,t){return q(e.Hr,t.Hr)||H.comparator(e.key,t.key)}}class nl{constructor(e,t){this.indexManager=e,this.referenceDelegate=t,this.mutationQueue=[],this.er=1,this.Yr=new eE(no.Qr)}checkEmpty(e){return eh.resolve(0===this.mutationQueue.length)}addMutationBatch(e,t,r,n){let i=this.er;this.er++,this.mutationQueue.length>0&&this.mutationQueue[this.mutationQueue.length-1];let s=new rl(i,t,r,n);for(let t of(this.mutationQueue.push(s),n))this.Yr=this.Yr.add(new no(t.key,i)),this.indexManager.addToCollectionParentIndex(e,t.key.path.popLast());return eh.resolve(s)}lookupMutationBatch(e,t){return eh.resolve(this.Zr(t))}getNextMutationBatchAfterBatchId(e,t){let r=this.Xr(t+1),n=r<0?0:r;return eh.resolve(this.mutationQueue.length>n?this.mutationQueue[n]:null)}getHighestUnacknowledgedBatchId(){return eh.resolve(0===this.mutationQueue.length?-1:this.er-1)}getAllMutationBatches(e){return eh.resolve(this.mutationQueue.slice())}getAllMutationBatchesAffectingDocumentKey(e,t){let r=new no(t,0),n=new no(t,1/0),i=[];return this.Yr.forEachInRange([r,n],e=>{let t=this.Zr(e.Hr);i.push(t)}),eh.resolve(i)}getAllMutationBatchesAffectingDocumentKeys(e,t){let r=new eE(q);return t.forEach(e=>{let t=new no(e,0),n=new no(e,1/0);this.Yr.forEachInRange([t,n],e=>{r=r.add(e.Hr)})}),eh.resolve(this.ei(r))}getAllMutationBatchesAffectingQuery(e,t){let r=t.path,n=r.length+1,i=r;H.isDocumentKey(i)||(i=i.child(""));let s=new no(new H(i),0),a=new eE(q);return this.Yr.forEachWhile(e=>{let t=e.key.path;return!!r.isPrefixOf(t)&&(t.length===n&&(a=a.add(e.Hr)),!0)},s),eh.resolve(this.ei(a))}ei(e){let t=[];return e.forEach(e=>{let r=this.Zr(e);null!==r&&t.push(r)}),t}removeMutationBatch(e,t){C(0===this.ti(t.batchId,"removed"),55003),this.mutationQueue.shift();let r=this.Yr;return eh.forEach(t.mutations,n=>{let i=new no(n.key,t.batchId);return r=r.delete(i),this.referenceDelegate.markPotentiallyOrphaned(e,n.key)}).next(()=>{this.Yr=r})}rr(e){}containsKey(e,t){let r=new no(t,0),n=this.Yr.firstAfterOrEqual(r);return eh.resolve(t.isEqual(n&&n.key))}performConsistencyCheck(e){return this.mutationQueue.length,eh.resolve()}ti(e,t){return this.Xr(e)}Xr(e){return 0===this.mutationQueue.length?0:e-this.mutationQueue[0].batchId}Zr(e){let t=this.Xr(e);return t<0||t>=this.mutationQueue.length?null:this.mutationQueue[t]}}class nu{constructor(e){this.ni=e,this.docs=new ew(H.comparator),this.size=0}setIndexManager(e){this.indexManager=e}addEntry(e,t){let r=t.key,n=this.docs.get(r),i=n?n.size:0,s=this.ni(t);return this.docs=this.docs.insert(r,{document:t.mutableCopy(),size:s}),this.size+=s-i,this.indexManager.addToCollectionParentIndex(e,r.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 r=this.docs.get(t);return eh.resolve(r?r.document.mutableCopy():e9.newInvalidDocument(t))}getEntries(e,t){let r=tL;return t.forEach(e=>{let t=this.docs.get(e);r=r.insert(e,t?t.document.mutableCopy():e9.newInvalidDocument(e))}),eh.resolve(r)}getDocumentsMatchingQuery(e,t,r,n){let i=tL,s=t.path,a=new H(s.child("__id-9223372036854775808__")),o=this.docs.getIteratorFrom(a);for(;o.hasNext();){let{key:e,value:{document:a}}=o.getNext();if(!s.isPrefixOf(e.path))break;e.path.length>s.length+1||0>=function(e,t){let r=e.readTime.compareTo(t.readTime);return 0!==r||0!==(r=H.comparator(e.documentKey,t.documentKey))?r:q(e.largestBatchId,t.largestBatchId)}(new eo(a.readTime,a.key,-1),r)||(n.has(a.key)||tV(t,a))&&(i=i.insert(a.key,a.mutableCopy()))}return eh.resolve(i)}getAllFromCollectionGroup(e,t,r,n){S(9500)}ri(e,t){return eh.forEach(this.docs,e=>t(e))}newChangeBuffer(e){return new nh(this)}getSize(e){return eh.resolve(this.size)}}class nh extends ne{constructor(e){super(),this.Or=e}applyChanges(e){let t=[];
vendor: 5,010 bytes, line 6
6return this.changes.forEach((r,n)=>{n.isValidDocument()?t.push(this.Or.addEntry(e,n)):this.Or.removeEntry(r)}),eh.waitFor(t)}getFromCache(e,t){return this.Or.getEntry(e,t)}getAllFromCache(e,t){return this.Or.getEntries(e,t)}}class nc{constructor(e){this.persistence=e,this.ii=new tF(e=>tw(e),tv),this.lastRemoteSnapshotVersion=es.min(),this.highestTargetId=0,this.si=0,this.oi=new na,this.targetCount=0,this._i=r4.ar()}forEachTarget(e,t){return this.ii.forEach((e,r)=>t(r)),eh.resolve()}getLastRemoteSnapshotVersion(e){return eh.resolve(this.lastRemoteSnapshotVersion)}getHighestSequenceNumber(e){return eh.resolve(this.si)}allocateTargetId(e){return this.highestTargetId=this._i.next(),eh.resolve(this.highestTargetId)}setTargetsMetadata(e,t,r){return r&&(this.lastRemoteSnapshotVersion=r),t>this.si&&(this.si=t),eh.resolve()}hr(e){this.ii.set(e.target,e);let t=e.targetId;t>this.highestTargetId&&(this._i=new r4(t),this.highestTargetId=t),e.sequenceNumber>this.si&&(this.si=e.sequenceNumber)}addTargetData(e,t){return this.hr(t),this.targetCount+=1,eh.resolve()}updateTargetData(e,t){return this.hr(t),eh.resolve()}removeTargetData(e,t){return this.ii.delete(t.target),this.oi.zr(t.targetId),this.targetCount-=1,eh.resolve()}removeTargets(e,t,r){let n=0,i=[];return this.ii.forEach((s,a)=>{a.sequenceNumber<=t&&null===r.get(a.targetId)&&(this.ii.delete(s),i.push(this.removeMatchingKeysForTargetId(e,a.targetId)),n++)}),eh.waitFor(i).next(()=>n)}getTargetCount(e){return eh.resolve(this.targetCount)}getTargetData(e,t){let r=this.ii.get(t)||null;return eh.resolve(r)}addMatchingKeys(e,t,r){return this.oi.Kr(t,r),eh.resolve()}removeMatchingKeys(e,t,r){this.oi.Gr(t,r);let n=this.persistence.referenceDelegate,i=[];return n&&t.forEach(t=>{i.push(n.markPotentiallyOrphaned(e,t))}),eh.waitFor(i)}removeMatchingKeysForTargetId(e,t){return this.oi.zr(t),eh.resolve()}getMatchingKeysForTargetId(e,t){let r=this.oi.Jr(t);return eh.resolve(r)}containsKey(e,t){return eh.resolve(this.oi.containsKey(t))}}class nd{constructor(e,t){this.ai={},this.overlays={},this.ui=new ed(0),this.ci=!1,this.ci=!0,this.li=new ns,this.referenceDelegate=e(this),this.hi=new nc(this),this.indexManager=new r0,this.remoteDocumentCache=new nu(e=>this.referenceDelegate.Pi(e)),this.serializer=new rX(t),this.Ti=new nn(this.serializer)}start(){return Promise.resolve()}shutdown(){return this.ci=!1,Promise.resolve()}get started(){return this.ci}setDatabaseDeletedListener(){}setNetworkEnabled(){}getIndexManager(e){return this.indexManager}getDocumentOverlayCache(e){let t=this.overlays[e.toKey()];return t||(t=new ni,this.overlays[e.toKey()]=t),t}getMutationQueue(e,t){let r=this.ai[e.toKey()];return r||(r=new nl(t,this.referenceDelegate),this.ai[e.toKey()]=r),r}getGlobalsCache(){return this.li}getTargetCache(){return this.hi}getRemoteDocumentCache(){return this.remoteDocumentCache}getBundleCache(){return this.Ti}runTransaction(e,t,r){_("MemoryPersistence","Starting transaction:",e);let n=new nf(this.ui.next());return this.referenceDelegate.Ii(),r(n).next(e=>this.referenceDelegate.di(n).next(()=>e)).toPromise().then(e=>(n.raiseOnCommittedEvent(),e))}Ei(e,t){return eh.or(Object.values(this.ai).map(r=>()=>r.containsKey(e,t)))}}class nf extends el{constructor(e){super(),this.currentSequenceNumber=e}}class nm{constructor(e){this.persistence=e,this.Ai=new na,this.Ri=null}static Vi(e){return new nm(e)}get mi(){if(this.Ri)return this.Ri;throw S(60996)}addReference(e,t,r){return this.Ai.addReference(r,t),this.mi.delete(r.toString()),eh.resolve()}removeReference(e,t,r){return this.Ai.removeReference(r,t),this.mi.add(r.toString()),eh.resolve()}markPotentiallyOrphaned(e,t){return this.mi.add(t.toString()),eh.resolve()}removeTarget(e,t){this.Ai.zr(t.targetId).forEach(e=>this.mi.add(e.toString()));let r=this.persistence.getTargetCache();return r.getMatchingKeysForTargetId(e,t.targetId).next(e=>{e.forEach(e=>this.mi.add(e.toString()))}).next(()=>r.removeTargetData(e,t))}Ii(){this.Ri=new Set}di(e){let t=this.persistence.getRemoteDocumentCache().newChangeBuffer();return eh.forEach(this.mi,r=>{let n=H.fromPath(r);return this.fi(e,n).next(e=>{e||t.removeEntry(n,es.min())})}).next(()=>(this.Ri=null,t.apply(e)))}updateLimboDocument(e,t){return this.fi(e,t).next(e=>{e?this.mi.delete(t.toString()):this.mi.add(t.toString())})}Pi(e){return 0}fi(e,t){return eh.or([()=>eh.resolve(this.Ai.containsKey(t)),()=>this.persistence.getTargetCache().containsKey(e,t),()=>this.persistence.Ei(e,t)])}}class ng{constructor(e,t){this.persistence=e,this.gi=new tF(e=>(function(e){let t="";for(let r=0;r<e.length;r++)t.length>0&&(t+="\x01\x01"),t=function(e,t){let r=t,n=e.length;for(let t=0;t<n;t++){let n=e.charAt(t);switch(n){case"\0":r+="\x01\x10";break;case"\x01":r+="\x01\x11";break;default:r+=n}}return r}(e.get(r),t);return t+"\x01\x01"})(e.path),(e,t)=>e.isEqual(t)),this.garbageCollector=new r7(this,t)}static Vi(e,t){return new ng(e,t)}Ii(){}di(e){return eh.resolve()}forEachTarget(e,t){return this.persistence.getTargetCache().forEac
6hTarget(e,t)}mr(e){let t=this.yr(e);return this.persistence.getTargetCache().getTargetCount(e).next(e=>t.next(t=>e+t))}yr(e){let t=0;return this.gr(e,e=>{t++}).next(()=>t)}gr(e,t){return eh.forEach(this.gi,(r,n)=>this.Sr(e,r,n).next(e=>e?eh.resolve():t(n)))}removeTargets(e,t,r){return this.persistence.getTargetCache().removeTargets(e,t,r)}removeOrphanedDocuments(e,t){let r=0,n=this.persistence.getRemoteDocumentCache(),i=n.newChangeBuffer();return n.ri(e,n=>this.Sr(e,n,t).next(e=>{e||(r++,i.removeEntry(n,es.min()))})).next(()=>i.apply(e)).next(()=>r)}markPotentiallyOrphaned(e,t){return this.gi.set(t,e.currentSequenceNumber),eh.resolve()}removeTarget(e,t){let r=t.withSequenceNumber(e.currentSequenceNumber);return this.persistence.getTargetCache().updateTargetData(e,r)}addReference(e,t,r){return this.gi.set(r,e.currentSequenceNumber),eh.resolve()}removeReference(e,t,r){return this.gi.set(r,e.currentSequenceNumber),eh.resolve()}updateLimboDocument(e,t){return this.gi.set(t,e.currentSequenceNumber),eh.resolve()}Pi(e){let t=e.key.toString().length;return e.isFoundDocument()&&(t+=function e(t){switch(eG(t)){case 0:case 1:return 4;case 2:return 8;case 3:case 8:return 16;case 4:let r=eF(t);return r?16+e(r):16;case 5:return 2*t.stringValue.length;case 6:return eD(t.bytesValue).approximateByteSize();case 7:return t.referenceValue.length;case 9:return(t.arrayValue.values||[]).reduce((t,r)=>t+e(r),0);case 10:case 11:var n;let i;return n=t.mapValue,i=0,ep(n.fields,(t,r)=>{i+=t.length+e(r)}),i;default:throw S(13486,{value:t})}}(e.data.value)),t}Sr(e,t,r){return eh.or([()=>this.persistence.Ei(e,t),()=>this.persistence.getTargetCache().containsKey(e,t),()=>{let e=this.gi.get(t);return eh.resolve(void 0!==e&&e>r)}])}getCacheSize(e){return this.persistence.getRemoteDocumentCache().getSize(e)}}class np{constructor(e,t,r,n){this.targetId=e,this.fromCache=t,this.Is=r,this.ds=n}static Es(e,t){let r=tz(),n=tz();for(let e of t.docChanges)switch(e.type){case 0:r=r.add(e.doc.key);break;case 1:n=n.add(e.doc.key)}return new np(e,t.fromCache,r,n)}}class ny{constructor(){this._documentReadCount=0}get documentReadCount(){return this._documentReadCount}incrementDocumentReadCount(e){this._documentReadCount+=e}}class nw{constructor(){this.As=!1,this.Rs=!1,this.Vs=100,this.fs=(0,h.nr)()?8:function(e){let t=e.match(/Android ([\d.]+)/i);return Number(t?t[1].split(".").slice(0,2).join("."):"-1")}((0,h.ZQ)())>0?6:4}initialize(e,t){this.gs=e,this.indexManager=t,this.As=!0}getDocumentsMatchingQuery(e,t,r,n){let i={result:null};return this.ps(e,t).next(e=>{i.result=e}).next(()=>{if(!i.result)return this.ys(e,t,n,r).next(e=>{i.result=e})}).next(()=>{if(i.result)return;let r=new ny;return this.ws(e,t,r).next(n=>{if(i.result=n,this.Rs)return this.Ss(e,t,r,n.size)})}).next(()=>i.result)}Ss(e,t,r,n){return r.documentReadCount<this.Vs?(v()<=u.$b.DEBUG&&_("QueryEngine","SDK will not create cache indexes for query:",tR(t),"since it only creates cache indexes for collection contains","more than or equal to",this.Vs,"documents"),eh.resolve()):(v()<=u.$b.DEBUG&&_("QueryEngine","Query:",tR(t),"scans",r.documentReadCount,"local documents and returns",n,"documents as results."),r.documentReadCount>this.fs*n?(v()<=u.$b.DEBUG&&_("QueryEngine","The SDK decides to create cache indexes for query:",tR(t),"as using cache indexes may help improve performance."),this.indexManager.createTargetIndexes(e,tC(t))):eh.resolve())}ps(e,t){if(tI(t))return eh.resolve(null);let r=tC(t);return this.indexManager.getIndexType(e,r).next(n=>0===n?null:(null!==t.limit&&1===n&&(r=tC(t=tD(t,null,"F"))),this.indexManager.getDocumentsMatchingTarget(e,r).next(n=>{let i=tz(...n);return this.gs.getDocuments(e,i).next(n=>this.indexManager.getMinOffset(e,r).next(r=>{let s=this.bs(t,n);return this.Ds(t,s,i,r.readTime)?this.ps(e,tD(t,null,"F")):this.vs(e,s,t,r)}))})))}ys(e,t,r,n){return tI(t)||n.isEqual(es.min())?eh.resolve(null):this.gs.getDocuments(e,r).next(i=>{let s=this.bs(t,i);return this.Ds(t,s,r,n)?eh.resolve(null):(v()<=u.$b.DEBUG&&_("QueryEngine","Re-using previous result from %s to execute query: %s",n.toString(),tR(t)),this.vs(e,s,t,function(e,t){let r=e.toTimestamp().seconds,n=e.toTimestamp().nanoseconds+1;return new eo(es.fromTimestamp(1e9===n?new ei(r+1,0):new ei(r,n)),H.empty(),-1)}(n,0)).next(e=>e))})}bs(e,t){let r=new eE(tO(e));return t.forEach((t,n)=>
6{tV(e,n)&&(r=r.add(n))}),r}Ds(e,t,r,n){if(null===e.limit)return!1;if(r.size!==t.size)return!0;let i="F"===e.limitType?t.last():t.first();return!!i&&(i.hasPendingWrites||i.version.compareTo(n)>0)}ws(e,t,r){return v()<=u.$b.DEBUG&&_("QueryEngine","Using full collection scan to execute query:",tR(t)),this.gs.getDocumentsMatchingQuery(e,t,eo.min(),r)}vs(e,t,r,n){return this.gs.getDocumentsMatchingQuery(e,r,n).next(e=>(t.forEach(t=>{e=e.insert(t.key,t)}),e))}}let nv="LocalStore";class n_{constructor(e,t,r,n){this.persistence=e,this.Cs=t,this.serializer=n,this.Fs=new ew(q),this.Ms=new tF(e=>tw(e),tv),this.xs=new Map,this.Os=e.getRemoteDocumentCache(),this.hi=e.getTargetCache(),this.Ti=e.getBundleCache(),this.Ns(r)}Ns(e){this.documentOverlayCache=this.persistence.getDocumentOverlayCache(e),this.indexManager=this.persistence.getIndexManager(e),this.mutationQueue=this.persistence.getMutationQueue(e,this.indexManager),this.localDocuments=new nr(this.Os,this.mutationQueue,this.documentOverlayCache,this.indexManager),this.Os.setIndexManager(this.indexManager),this.Cs.initialize(this.localDocuments,this.indexManager)}collectGarbage(e){return this.persistence.runTransaction("Collect garbage","readwrite-primary",t=>e.collect(t,this.Fs))}}async function nE(e,t){return await e.persistence.runTransaction("Handle user change","readonly",r=>{let n;return e.mutationQueue.getAllMutationBatches(r).next(i=>(n=i,e.Ns(t),e.mutationQueue.getAllMutationBatches(r))).next(t=>{let i=[],s=[],a=tz();for(let e of n)for(let t of(i.push(e.batchId),e.mutations))a=a.add(t.key);for(let e of t)for(let t of(s.push(e.batchId),e.mutations))a=a.add(t.key);return e.localDocuments.getDocuments(r,a).next(e=>({Bs:e,removedBatchIds:i,addedBatchIds:s}))})})}function nT(e){return e.persistence.runTransaction("Get last remote snapshot version","readonly",t=>e.hi.getLastRemoteSnapshotVersion(t))}async function nI(e,t,r){let n=e.Fs.get(t);try{r||await e.persistence.runTransaction("Release target",r?"readwrite":"readwrite-primary",t=>e.persistence.referenceDelegate.removeTarget(t,n))}catch(e){if(!ec(e))throw e;_(nv,`Failed to update sequence numbers for target ${t}: ${e}`)}e.Fs=e.Fs.remove(t),e.Ms.delete(n.target)}function nS(e,t,r){let n=es.min(),i=tz();return e.persistence.runTransaction("Execute query","readwrite",s=>(function(e,t,r){let n=e.Ms.get(r);return void 0!==n?eh.resolve(e.Fs.get(n)):e.hi.getTargetData(t,r)})(e,s,tC(t)).next(t=>{if(t)return n=t.lastLimboFreeSnapshotVersion,e.hi.getMatchingKeysForTargetId(s,t.targetId).next(e=>{i=e})}).next(()=>e.Cs.getDocumentsMatchingQuery(s,t,r?n:es.min(),r?i:tz())).next(r=>{var n,s,a;let o;return n=e,s=t.collectionGroup||(t.path.length%2==1?t.path.lastSegment():t.path.get(t.path.length-2)),a=r,o=n.xs.get(s)||es.min(),a.forEach((e,t)=>{t.readTime.compareTo(o)>0&&(o=t.readTime)}),n.xs.set(s,o),{documents:r,qs:i}}))}class nb{constructor(){this.activeTargetIds=tj}Gs(e){this.activeTargetIds=this.activeTargetIds.add(e)}zs(e){this.activeTargetIds=this.activeTargetIds.delete(e)}Ws(){return JSON.stringify({activeTargetIds:this.activeTargetIds.toArray(),updateTimeMs:Date.now()})}}class nC{constructor(){this.Fo=new nb,this.Mo={},this.onlineStateHandler=null,this.sequenceNumberHandler=null}addPendingMutation(e){}updateMutationState(e,t,r){}addLocalQueryTarget(e,t=!0){return t&&this.Fo.Gs(e),this.Mo[e]||"not-current"}updateQueryState(e,t,r){this.Mo[e]=t}removeLocalQueryTarget(e){this.Fo.zs(e)}isLocalQueryTarget(e){return this.Fo.activeTargetIds.has(e)}clearQueryState(e){delete this.Mo[e]}getAllActiveQueryTargets(){return this.Fo.activeTargetIds}isActiveQueryTarget(e){return this.Fo.activeTargetIds.has(e)}start(){return this.Fo=new nb,Promise.resolve()}handleUserChange(e,t,r){}setOnlineState(e){}shutdown(){}writeSequenceNumber(e){}notifyBundleLoaded(e){}}class nA{xo(e){}shutdown(){}}let nN="ConnectivityMonitor";class nD{constructor(){this.Oo=()=>this.No(),this.Bo=()=>this.Lo(),this.ko=[],this.qo()}xo(e){this.ko.push(e)}shutdown(){window.removeEventListener("online",this.Oo),window.removeEventListener("offline",this.Bo)}qo(){window.addEventListener("online",this.Oo),window.addEventListener("offline",this.Bo)}No(){for(let e of(_(nN,"Network connectivity changed: AVAILABLE"),this.ko))e(0)}Lo(){for(let e of(_(nN,"Network connectivity changed: UNAVAILABLE"),this.ko))e(1)}static C(){return"undefined"!=typeof window&&void 0!==window.addEventListener&&void 0!==window.removeEventListener}}let nk=null;function nx(){return null===nk?nk=0x10000000+Math.round(0x80000000*Math.random()):nk++,"0x"+nk.toString(16)}let nR="RestConnection",nV={BatchGetDocuments:"batchGet",Commit:"commit",RunQuery:"runQuery",RunAggregation
6Query:"runAggregationQuery"};class nO{get Qo(){return!1}constructor(e){this.databaseInfo=e,this.databaseId=e.databaseId;let t=e.ssl?"https":"http",r=encodeURIComponent(this.databaseId.projectId),n=encodeURIComponent(this.databaseId.database);this.$o=t+"://"+e.host,this.Uo=`projects/${r}/databases/${n}`,this.Ko=this.databaseId.database===eP?`project_id=${r}`:`project_id=${r}&database_id=${n}`}Wo(e,t,r,n,i){let s=nx(),a=this.Go(e,t.toUriEncodedString());_(nR,`Sending RPC '${e}' ${s}:`,a,r);let o={"google-cloud-resource-prefix":this.Uo,"x-goog-request-params":this.Ko};this.zo(o,n,i);let{host:l}=new URL(a),u=(0,h.zJ)(l);return this.jo(e,a,o,r,u).then(t=>(_(nR,`Received RPC '${e}' ${s}: `,t),t),t=>{throw T(nR,`RPC '${e}' ${s} failed with error: `,t,"url: ",a,"request:",r),t})}Jo(e,t,r,n,i,s){return this.Wo(e,t,r,n,i)}zo(e,t,r){e["X-Goog-Api-Client"]="gl-js/ fire/"+y,e["Content-Type"]="text/plain",this.databaseInfo.appId&&(e["X-Firebase-GMPID"]=this.databaseInfo.appId),t&&t.headers.forEach((t,r)=>e[r]=t),r&&r.headers.forEach((t,r)=>e[r]=t)}Go(e,t){let r=nV[e];return`${this.$o}/v1/${t}:${r}`}terminate(){}}class nF{constructor(e){this.Ho=e.Ho,this.Yo=e.Yo}Zo(e){this.Xo=e}e_(e){this.t_=e}n_(e){this.r_=e}onMessage(e){this.i_=e}close(){this.Yo()}send(e){this.Ho(e)}s_(){this.Xo()}o_(){this.t_()}__(e){this.r_(e)}a_(e){this.i_(e)}}let nL="WebChannelConnection";class nM extends nO{constructor(e){super(e),this.u_=[],this.forceLongPolling=e.forceLongPolling,this.autoDetectLongPolling=e.autoDetectLongPolling,this.useFetchStreams=e.useFetchStreams,this.longPollingOptions=e.longPollingOptions}jo(e,t,r,n,i){let s=nx();return new Promise((i,a)=>{let o=new d.ZS;o.setWithCredentials(!0),o.listenOnce(d.Bx.COMPLETE,()=>{try{switch(o.getLastErrorCode()){case d.O4.NO_ERROR:let t=o.getResponseJson();_(nL,`XHR for RPC '${e}' ${s} received:`,JSON.stringify(t)),i(t);break;case d.O4.TIMEOUT:_(nL,`RPC '${e}' ${s} timed out`),a(new N(A.DEADLINE_EXCEEDED,"Request time out"));break;case d.O4.HTTP_ERROR:let r=o.getStatus();if(_(nL,`RPC '${e}' ${s} failed with status:`,r,"response text:",o.getResponseText()),r>0){let e=o.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(A).indexOf(t)>=0?t:A.UNKNOWN}(t.status);a(new N(e,t.message))}else a(new N(A.UNKNOWN,"Server responded with status "+o.getStatus()))}else a(new N(A.UNAVAILABLE,"Connection failed."));break;default:S(9055,{c_:e,streamId:s,l_:o.getLastErrorCode(),h_:o.getLastError()})}}finally{_(nL,`RPC '${e}' ${s} completed.`)}});let l=JSON.stringify(n);_(nL,`RPC '${e}' ${s} sending request:`,n),o.send(t,"POST",l,r,15)})}P_(e,t,r){let i=nx(),s=[this.$o,"/","google.firestore.v1.Firestore","/",e,"/channel"],a=(0,d.fF)(),o=(0,d.Ao)(),l={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},u=this.longPollingOptions.timeoutSeconds;void 0!==u&&(l.longPollingTimeout=Math.round(1e3*u)),this.useFetchStreams&&(l.useFetchStreams=!0),this.zo(l.initMessageHeaders,t,r),l.encodeInitMessageHeaders=!0;let h=s.join("");_(nL,`Creating RPC '${e}' stream ${i}: ${h}`,l);let c=a.createWebChannel(h,l);this.T_(c);let f=!1,m=!1,g=new nF({Ho:t=>{m?_(nL,`Not sending because RPC '${e}' stream ${i} is closed:`,t):(f||(_(nL,`Opening RPC '${e}' stream ${i} transport.`),c.open(),f=!0),_(nL,`RPC '${e}' stream ${i} sending:`,t),c.send(t))},Yo:()=>c.close()}),p=(e,t,r)=>{e.listen(t,e=>{try{r(e)}catch(e){setTimeout(()=>{throw e},0)}})};return p(c,d.iO.EventType.OPEN,()=>{m||(_(nL,`RPC '${e}' stream ${i} transport opened.`),g.s_())}),p(c,d.iO.EventType.CLOSE,()=>{m||(m=!0,_(nL,`RPC '${e}' stream ${i} transport closed`),g.__(),this.I_(c))}),p(c,d.iO.EventType.ERROR,t=>{m||(m=!0,T(nL,`RPC '${e}' stream ${i} transport errored. Name:`,t.name,"Message:",t.message),g.__(new N(A.UNAVAILABLE,"The operation could not be completed")))}),p(c,d.iO.EventType.MESSAGE,t=>{var r;if(!m){let s=t.data[0];C(!!s,16349);let a=(null==s?void 0:s.error)||(null==(r=s[0])?void 0:r.error);if(a){_(nL,`RPC '${e}' stream ${i} received error:`,a);let t=a.status,r=function(e){let t=n[e];if(void 0!==t)return rm(t)}(t),s=a.message;void 0===r&&(r=A.INTERNAL,s="Unknown error status: "+t+" with message "+a.message),m=!0,g.__(new N(r,s)),c.close()}else _(nL,`RPC '${e}' stream ${i}
6 received:`,s),g.a_(s)}}),p(o,d.Jh.STAT_EVENT,t=>{t.stat===d.ro.PROXY?_(nL,`RPC '${e}' stream ${i} detected buffering proxy`):t.stat===d.ro.NOPROXY&&_(nL,`RPC '${e}' stream ${i} detected no buffering proxy`)}),setTimeout(()=>{g.o_()},0),g}terminate(){this.u_.forEach(e=>e.close()),this.u_=[]}T_(e){this.u_.push(e)}I_(e){this.u_=this.u_.filter(t=>t===e)}}function nP(){return"undefined"!=typeof document?document:null}function nU(e){return new rR(e,!0)}class nq{constructor(e,t,r=1e3,n=1.5,i=6e4){this.Fi=e,this.timerId=t,this.d_=r,this.E_=n,this.A_=i,this.R_=0,this.V_=null,this.m_=Date.now(),this.reset()}reset(){this.R_=0}f_(){this.R_=this.A_}g_(e){this.cancel();let t=Math.floor(this.R_+this.p_()),r=Math.max(0,Date.now()-this.m_),n=Math.max(0,t-r);n>0&&_("ExponentialBackoff",`Backing off for ${n} ms (base delay: ${this.R_} ms, delay with jitter: ${t} ms, last attempt: ${r} ms ago)`),this.V_=this.Fi.enqueueAfterDelay(this.timerId,n,()=>(this.m_=Date.now(),e())),this.R_*=this.E_,this.R_<this.d_&&(this.R_=this.d_),this.R_>this.A_&&(this.R_=this.A_)}y_(){null!==this.V_&&(this.V_.skipDelay(),this.V_=null)}cancel(){null!==this.V_&&(this.V_.cancel(),this.V_=null)}p_(){return(Math.random()-.5)*this.R_}}let n$="PersistentStream";class nB{constructor(e,t,r,n,i,s,a,o){this.Fi=e,this.w_=r,this.S_=n,this.connection=i,this.authCredentialsProvider=s,this.appCheckCredentialsProvider=a,this.listener=o,this.state=0,this.b_=0,this.D_=null,this.v_=null,this.stream=null,this.C_=0,this.F_=new nq(e,t)}M_(){return 1===this.state||5===this.state||this.x_()}x_(){return 2===this.state||3===this.state}start(){this.C_=0,4!==this.state?this.auth():this.O_()}async stop(){this.M_()&&await this.close(0)}N_(){this.state=0,this.F_.reset()}B_(){this.x_()&&null===this.D_&&(this.D_=this.Fi.enqueueAfterDelay(this.w_,6e4,()=>this.L_()))}k_(e){this.q_(),this.stream.send(e)}async L_(){if(this.x_())return this.close(0)}q_(){this.D_&&(this.D_.cancel(),this.D_=null)}Q_(){this.v_&&(this.v_.cancel(),this.v_=null)}async close(e,t){this.q_(),this.Q_(),this.F_.cancel(),this.b_++,4!==e?this.F_.reset():t&&t.code===A.RESOURCE_EXHAUSTED?(E(t.toString()),E("Using maximum backoff delay to prevent overloading the backend."),this.F_.f_()):t&&t.code===A.UNAUTHENTICATED&&3!==this.state&&(this.authCredentialsProvider.invalidateToken(),this.appCheckCredentialsProvider.invalidateToken()),null!==this.stream&&(this.U_(),this.stream.close(),this.stream=null),this.state=e,await this.listener.n_(t)}U_(){}auth(){this.state=1;let e=this.K_(this.b_),t=this.b_;Promise.all([this.authCredentialsProvider.getToken(),this.appCheckCredentialsProvider.getToken()]).then(([e,r])=>{this.b_===t&&this.W_(e,r)},t=>{e(()=>{let e=new N(A.UNKNOWN,"Fetching auth token failed: "+t.message);return this.G_(e)})})}W_(e,t){let r=this.K_(this.b_);this.stream=this.z_(e,t),this.stream.Zo(()=>{r(()=>this.listener.Zo())}),this.stream.e_(()=>{r(()=>(this.state=2,this.v_=this.Fi.enqueueAfterDelay(this.S_,1e4,()=>(this.x_()&&(this.state=3),Promise.resolve())),this.listener.e_()))}),this.stream.n_(e=>{r(()=>this.G_(e))}),this.stream.onMessage(e=>{r(()=>1==++this.C_?this.j_(e):this.onNext(e))})}O_(){this.state=5,this.F_.g_(async()=>{this.state=0,this.start()})}G_(e){return _(n$,`close with error: ${e}`),this.stream=null,this.close(4,e)}K_(e){return t=>{this.Fi.enqueueAndForget(()=>this.b_===e?t():(_(n$,"stream callback skipped by getCloseGuardedDispatcher."),Promise.resolve()))}}}class nz extends nB{constructor(e,t,r,n,i,s){super(e,"listen_stream_connection_backoff","listen_stream_idle","health_check_timeout",t,r,n,s),this.serializer=i}z_(e,t){return this.connection.P_("Listen",e,t)}j_(e){return this.onNext(e)}onNext(e){this.F_.reset();let t=function(e,t){let r;if("targetChange"in t){var n,i;t.targetChange;let s="NO_CHANGE"===(n=t.targetChange.targetChangeType||"NO_CHANGE")?0:"ADD"===n?1:"REMOVE"===n?2:"CURRENT"===n?3:"RESET"===n?4:S(39313,{state:n}),a=t.targetChange.targetIds||[],o=(i=t.targetChange.resumeToken,e.useProto3Json?(C(void 0===i||"string"==typeof i,58123),eb.fromBase64String(i||"")):(C(void 0===i||i instanceof f||i instanceof Uint8Array,16193),eb.fromUint8Array(i||new Uint8Array))),l=t.targetChange.cause;r=new rS(s,a,o,l&&new N(void 0===l.code?A.UNKNOWN:rm(l.code),l.message||"")||null)}else if("documentChange"in t){t.documentChange;let n=t.documentChange;n.document,n.document.name,n.document.updateTime;let i=r$(e,n.document.name),s=rL(n.document.updateTime),a=n.document.createTime?rL(n.document.createTime):es.min(),o=new e8({mapValue:{fields:n.document.fields}}),l=e9.newFoundDocument(i,s,a,o);r=new rT(n.targetIds||[],n.removedTargetIds||[],l.key,l)}else if("documentDelete"in t){t.documentDelete;let n=t.documentDelete;n.document;let i=r$(e,n.document),s=n.readTime?rL(n.readTime):es.min(),a=e9.newNoDocument(i,s);r=new rT([],n.removedTargetIds||[],a.key,a)}else if("documentRemove"in t){t.documentRemove;let n=t.documentRemove;n.document;let i=r$(e,n.document);r=new rT([],n.removedTargetIds||[],i,null)}else{if(!("filter"in t))return S(11601,{At:t});{t.filter;let e=t.filter;e.targetId;
6let{count:n=0,unchangedNames:i}=e,s=new rd(n,i);r=new rI(e.targetId,s)}}return r}(this.serializer,e),r=function(e){if(!("targetChange"in e))return es.min();let t=e.targetChange;return t.targetIds&&t.targetIds.length?es.min():t.readTime?rL(t.readTime):es.min()}(e);return this.listener.J_(t,r)}H_(e){let t={};t.database=rz(this.serializer),t.addTarget=function(e,t){let r,n=t.target;if((r=t_(n)?{documents:{documents:[rB(e,n.path)]}}:{query:rQ(e,n).Vt}).targetId=t.targetId,t.resumeToken.approximateByteSize()>0){r.resumeToken=rF(e,t.resumeToken);let n=rV(e,t.expectedCount);null!==n&&(r.expectedCount=n)}else if(t.snapshotVersion.compareTo(es.min())>0){r.readTime=rO(e,t.snapshotVersion.toTimestamp());let n=rV(e,t.expectedCount);null!==n&&(r.expectedCount=n)}return r}(this.serializer,e);let r=function(e,t){let r=function(e){switch(e){case"TargetPurposeListen":return null;case"TargetPurposeExistenceFilterMismatch":return"existence-filter-mismatch";case"TargetPurposeExistenceFilterMismatchBloom":return"existence-filter-mismatch-bloom";case"TargetPurposeLimboResolution":return"limbo-document";default:return S(28987,{purpose:e})}}(t.purpose);return null==r?null:{"goog-listen-tags":r}}(this.serializer,e);r&&(t.labels=r),this.k_(t)}Y_(e){let t={};t.database=rz(this.serializer),t.removeTarget=e,this.k_(t)}}class nj extends nB{constructor(e,t,r,n,i,s){super(e,"write_stream_connection_backoff","write_stream_idle","health_check_timeout",t,r,n,s),this.serializer=i}get Z_(){return this.C_>0}start(){this.lastStreamToken=void 0,super.start()}U_(){this.Z_&&this.X_([])}z_(e,t){return this.connection.P_("Write",e,t)}j_(e){return C(!!e.streamToken,31322),this.lastStreamToken=e.streamToken,C(!e.writeResults||0===e.writeResults.length,55816),this.listener.ea()}onNext(e){var t,r;C(!!e.streamToken,12678),this.lastStreamToken=e.streamToken,this.F_.reset();let n=(t=e.writeResults,r=e.commitTime,t&&t.length>0?(C(void 0!==r,14353),t.map(e=>{let t;return(t=e.updateTime?rL(e.updateTime):rL(r)).isEqual(es.min())&&(t=rL(r)),new t4(t,e.transformResults||[])})):[]),i=rL(e.commitTime);return this.listener.ta(i,n)}na(){let e={};e.database=rz(this.serializer),this.k_(e)}X_(e){let t={streamToken:this.lastStreamToken,writes:e.map(e=>rK(this.serializer,e))};this.k_(t)}}class nG{}class nK extends nG{constructor(e,t,r,n){super(),this.authCredentials=e,this.appCheckCredentials=t,this.connection=r,this.serializer=n,this.ra=!1}ia(){if(this.ra)throw new N(A.FAILED_PRECONDITION,"The client has already been terminated.")}Wo(e,t,r,n){return this.ia(),Promise.all([this.authCredentials.getToken(),this.appCheckCredentials.getToken()]).then(([i,s])=>this.connection.Wo(e,rP(t,r),n,i,s)).catch(e=>{throw"FirebaseError"===e.name?(e.code===A.UNAUTHENTICATED&&(this.authCredentials.invalidateToken(),this.appCheckCredentials.invalidateToken()),e):new N(A.UNKNOWN,e.toString())})}Jo(e,t,r,n,i){return this.ia(),Promise.all([this.authCredentials.getToken(),this.appCheckCredentials.getToken()]).then(([s,a])=>this.connection.Jo(e,rP(t,r),n,s,a,i)).catch(e=>{throw"FirebaseError"===e.name?(e.code===A.UNAUTHENTICATED&&(this.authCredentials.invalidateToken(),this.appCheckCredentials.invalidateToken()),e):new N(A.UNKNOWN,e.toString())})}terminate(){this.ra=!0,this.connection.terminate()}}class nQ{constructor(e,t){this.asyncQueue=e,this.onlineStateHandler=t,this.state="Unknown",this.sa=0,this.oa=null,this._a=!0}aa(){0===this.sa&&(this.ua("Unknown"),this.oa=this.asyncQueue.enqueueAfterDelay("online_state_timeout",1e4,()=>(this.oa=null,this.ca("Backend didn't respond within 10 seconds."),this.ua("Offline"),Promise.resolve())))}la(e){"Online"===this.state?this.ua("Unknown"):(this.sa++,this.sa>=1&&(this.ha(),this.ca(`Connection failed 1 times. Most recent error: ${e.toString()}`),this.ua("Offline")))}set(e){this.ha(),this.sa=0,"Online"===e&&(this._a=!1),this.ua(e)}ua(e){e!==this.state&&(this.state=e,this.onlineStateHandler(e))}ca(e){let t=`Could not reach Cloud Firestore backend. ${e}
7This 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._a?(E(t),this._a=!1):_("OnlineStateTracker",t)}ha(){null!==this.oa&&(this.oa.cancel(),this.oa=null)}}let nW="RemoteStore";class nH{constructor(e,t,r,n,i){this.localStore=e,this.datastore=t,this.asyncQueue=r,this.remoteSyncer={},this.Pa=[],this.Ta=new Map,this.Ia=new Set,this.da=[],this.Ea=i,this.Ea.xo(e=>{r.enqueueAndForget(async()=>
7{n4(this)&&(_(nW,"Restarting streams for network reachability change."),await async function(e){e.Ia.add(4),await nJ(e),e.Aa.set("Unknown"),e.Ia.delete(4),await nY(e)}(this))})}),this.Aa=new nQ(r,n)}}async function nY(e){if(n4(e))for(let t of e.da)await t(!0)}async function nJ(e){for(let t of e.da)await t(!1)}function nX(e,t){e.Ta.has(t.targetId)||(e.Ta.set(t.targetId,t),n3(e)?n2(e):ic(e).x_()&&n0(e,t))}function nZ(e,t){let r=ic(e);e.Ta.delete(t),r.x_()&&n1(e,t),0===e.Ta.size&&(r.x_()?r.B_():n4(e)&&e.Aa.set("Unknown"))}function n0(e,t){if(e.Ra.$e(t.targetId),t.resumeToken.approximateByteSize()>0||t.snapshotVersion.compareTo(es.min())>0){let r=e.remoteSyncer.getRemoteKeysForTarget(t.targetId).size;t=t.withExpectedCount(r)}ic(e).H_(t)}function n1(e,t){e.Ra.$e(t),ic(e).Y_(t)}function n2(e){e.Ra=new rC({getRemoteKeysForTarget:t=>e.remoteSyncer.getRemoteKeysForTarget(t),Et:t=>e.Ta.get(t)||null,lt:()=>e.datastore.serializer.databaseId}),ic(e).start(),e.Aa.aa()}function n3(e){return n4(e)&&!ic(e).M_()&&e.Ta.size>0}function n4(e){return 0===e.Ia.size}async function n6(e){e.Aa.set("Online")}async function n5(e){e.Ta.forEach((t,r)=>{n0(e,t)})}async function n8(e,t){e.Ra=void 0,n3(e)?(e.Aa.la(t),n2(e)):e.Aa.set("Unknown")}async function n9(e,t,r){if(e.Aa.set("Online"),t instanceof rS&&2===t.state&&t.cause)try{await async function(e,t){let r=t.cause;for(let n of t.targetIds)e.Ta.has(n)&&(await e.remoteSyncer.rejectListen(n,r),e.Ta.delete(n),e.Ra.removeTarget(n))}(e,t)}catch(r){_(nW,"Failed to remove targets %s: %s ",t.targetIds.join(","),r),await n7(e,r)}else if(t instanceof rT?e.Ra.Ye(t):t instanceof rI?e.Ra.it(t):e.Ra.et(t),!r.isEqual(es.min()))try{let t=await nT(e.localStore);r.compareTo(t)>=0&&await function(e,t){let r=e.Ra.Pt(t);
7return r.targetChanges.forEach((r,n)=>{if(r.resumeToken.approximateByteSize()>0){let i=e.Ta.get(n);i&&e.Ta.set(n,i.withResumeToken(r.resumeToken,t))}}),r.targetMismatches.forEach((t,r)=>{let n=e.Ta.get(t);if(!n)return;e.Ta.set(t,n.withResumeToken(eb.EMPTY_BYTE_STRING,n.snapshotVersion)),n1(e,t);let i=new rJ(n.target,t,r,n.sequenceNumber);n0(e,i)}),e.remoteSyncer.applyRemoteEvent(r)}(e,r)}catch(t){_(nW,"Failed to raise snapshot:",t),await n7(e,t)}}async function n7(e,t,r){if(!ec(t))throw t;e.Ia.add(1),await nJ(e),e.Aa.set("Offline"),r||(r=()=>nT(e.localStore)),e.asyncQueue.enqueueRetryable(async()=>{_(nW,"Retrying IndexedDB access"),await r(),e.Ia.delete(1),await nY(e)})}function ie(e,t){return t().catch(r=>n7(e,r,t))}async function it(e){var t;let r=id(e),n=e.Pa.length>0?e.Pa[e.Pa.length-1].batchId:-1;for(;n4(t=e)&&t.Pa.length<10;)try{let t=await function(e,t){return e.persistence.runTransaction("Get next mutation batch","readonly",r=>(void 0===t&&(t=-1),e.mutationQueue.getNextMutationBatchAfterBatchId(r,t)))}(e.localStore,n);if(null===t){0===e.Pa.length&&r.B_();break}n=t.batchId,function(e,t){e.Pa.push(t);let r=id(e);r.x_()&&r.Z_&&r.X_(t.mutations)}(e,t)}catch(t){await n7(e,t)}ir(e)&&ii(e)}function ir(e){return n4(e)&&!id(e).M_()&&e.Pa.length>0}function ii(e){id(e).start()}async function is(e){id(e).na()}async function ia(e){let t=id(e);for(let r of e.Pa)t.X_(r.mutations)}async function io(e,t,r){let n=e.Pa.shift(),i=ru.from(n,t,r);await ie(e,()=>e.remoteSyncer.applySuccessfulWrite(i)),await it(e)}async function il(e,t){t&&id(e).Z_&&await async function(e,t){var r;if(rf(r=t.code)&&r!==A.ABORTED){let r=e.Pa.shift();id(e).N_(),await ie(e,()=>e.remoteSyncer.rejectFailedWrite(r.batchId,t)),await it(e)}}(e,t),ir(e)&&ii(e)}async function iu(e,t){e.asyncQueue.verifyOperationInProgress(),_(nW,"RemoteStore received new credentials");let r=n4(e);e.Ia.add(3),await nJ(e),r&&e.Aa.set("Unknown"),await e.remoteSyncer.handleCredentialChange(t),e.Ia.delete(3),await nY(e)}async function ih(e,t){t?(e.Ia.delete(2),await nY(e)):t||(e.Ia.add(2),await nJ(e),e.Aa.set("Unknown"))}function ic(e){var t,r,n;return e.Va||(t=e.datastore,r=e.asyncQueue,n={Zo:n6.bind(null,e),e_:n5.bind(null,e),n_:n8.bind(null,e),J_:n9.bind(null,e)},t.ia(),e.Va=new nz(r,t.connection,t.authCredentials,t.appCheckCredentials,t.serializer,n),e.da.push(async t=>{t?(e.Va.N_(),n3(e)?n2(e):e.Aa.set("Unknown")):(await e.Va.stop(),e.Ra=void 0)})),e.Va}function id(e){var t,r,n;return e.ma||(t=e.datastore,r=e.asyncQueue,n={Zo:()=>Promise.resolve(),e_:is.bind(null,e),n_:il.bind(null,e),ea:ia.bind(null,e),ta:io.bind(null,e)},t.ia(),e.ma=new nj(r,t.connection,t.authCredentials,t.appCheckCredentials,t.serializer,n),e.da.push(async t=>{t?(e.ma.N_(),await it(e)):(await e.ma.stop(),e.Pa.length>0&&(_(nW,`Stopping write stream with ${e.Pa.length} pending writes`),e.Pa=[]))})),e.ma}class im{constructor(e,t,r,n,i){this.asyncQueue=e,this.timerId=t,this.targetTimeMs=r,this.op=n,this.removalCallback=i,this.deferred=new D,this.then=this.deferred.promise.then.bind(this.deferred.promise),this.deferred.promise.catch(e=>{})}get promise(){return this.deferred.promise}static createAndSchedule(e,t,r,n,i){let s=new im(e,t,Date.now()+r,n,i);return s.start(r),s}start(e){this.timerHandle=setTimeout(()=>this.handleDelayElapsed(),e)}skipDelay(){return this.handleDelayElapsed()}cancel(e){null!==this.timerHandle&&(this.clearTimeout(),this.deferred.reject(new N(A.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 ig(e,t){if(E("AsyncQueue",`${t}: ${e}`),ec(e))return new N(A.UNAVAILABLE,`${t}: ${e}`);throw e}class ip{static emptySet(e){return new ip(e.comparator)}constructor(e){this.comparator=e?(t,r)=>e(t,r)||H.comparator(t.key,r.key):(e,t)=>H.comparator(e.key,t.key),this.keyedMap=tP(),this.sortedSet=new ew(this.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,r)=>(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 ip)||this.size!==e.size)return!1;let t=this.sortedSet.getIterator(),r=e.sortedSet.getIterator();for(;t.hasNext();){let e=t.getNext().key,n=r.getNext().key;if(!e.isEqual(n))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 r=new ip;return r.comparator=this.comparator,r.keyedMap=e,r.sortedSet=t,r}}class iy{constructor(){this.fa=new ew(H.comparator)}track(e){let t=e.doc.key,r=this.fa.get(t);r?0!==e.type&&3===r.type?this.fa=this.fa.insert(t,e):3===e.type&&1!==r.type?this.fa=this.fa.insert(t,{type:r.type,doc:e.doc}):2===e.type&&2===r.type?this.fa=this.fa.insert(t,{type:2,doc:e.doc}):2===e.type&&0===r.type?this.fa=this.fa.insert(t,{type:0,doc:e.doc}):1===e.type&&0===r.type?this.fa=this.fa.remove(t):1===e.type&&2===r.type?this.fa=this.fa.insert(t,{type:1,doc:r.doc}):0===e.type&&1===r.type?this.fa=this.fa.insert(t,{type:2,doc:e.doc}):S(63341,{At:e,ga:r}):this.fa=this.fa.insert(t,e)}pa(){let e=[];return this.fa.inorderTraversal((t,r)=>{e.push(r)}),e}}class iw{constructor(e,t,r,n,i,s,a,o,l){this.query=e,this.docs=t,this.oldDocs=r,this.docChanges=n,this.mutatedKeys=i,this.fromCache=s,this.syncStateChanged=a,this.excludesMetadataChanges=o,this.hasCachedResults=l}static fromInitialDocuments(e,t,r,n,i){let s=[];
7return t.forEach(e=>{s.push({type:0,doc:e})}),new iw(e,t,ip.emptySet(t),s,r,n,!0,!1,i)}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)&&tk(this.query,e.query)&&this.docs.isEqual(e.docs)&&this.oldDocs.isEqual(e.oldDocs)))return!1;let t=this.docChanges,r=e.docChanges;if(t.length!==r.length)return!1;for(let e=0;e<t.length;e++)if(t[e].type!==r[e].type||!t[e].doc.isEqual(r[e].doc))return!1;return!0}}class iv{constructor(){this.ya=void 0,this.wa=[]}Sa(){return this.wa.some(e=>e.ba())}}class i_{constructor(){this.queries=iE(),this.onlineState="Unknown",this.Da=new Set}terminate(){!function(e,t){let r=e.queries;e.queries=iE(),r.forEach((e,r)=>{for(let e of r.wa)e.onError(t)})}(this,new N(A.ABORTED,"Firestore shutting down"))}}function iE(){return new tF(e=>tx(e),tk)}async function iT(e,t){let r=3,n=t.query,i=e.queries.get(n);i?!i.Sa()&&t.ba()&&(r=2):(i=new iv,r=+!t.ba());try{switch(r){case 0:i.ya=await e.onListen(n,!0);break;case 1:i.ya=await e.onListen(n,!1);break;case 2:await e.onFirstRemoteStoreListen(n)}}catch(r){let e=ig(r,`Initialization of query '${tR(t.query)}' failed`);return void t.onError(e)}e.queries.set(n,i),i.wa.push(t),t.va(e.onlineState),i.ya&&t.Ca(i.ya)&&iC(e)}async function iI(e,t){let r=t.query,n=3,i=e.queries.get(r);if(i){let e=i.wa.indexOf(t);e>=0&&(i.wa.splice(e,1),0===i.wa.length?n=+!t.ba():!i.Sa()&&t.ba()&&(n=2))}switch(n){case 0:return e.queries.delete(r),e.onUnlisten(r,!0);case 1:return e.queries.delete(r),e.onUnlisten(r,!1);case 2:return e.onLastRemoteStoreUnlisten(r);default:return}}function iS(e,t){let r=!1;for(let n of t){let t=n.query,i=e.queries.get(t);if(i){for(let e of i.wa)e.Ca(n)&&(r=!0);i.ya=n}}r&&iC(e)}function ib(e,t,r){let n=e.queries.get(t);if(n)for(let e of n.wa)e.onError(r);e.queries.delete(t)}
7function iC(e){e.Da.forEach(e=>{e.next()})}(a=s||(s={})).Fa="default",a.Cache="cache";class iA{constructor(e,t,r){this.query=e,this.Ma=t,this.xa=!1,this.Oa=null,this.onlineState="Unknown",this.options=r||{}}Ca(e){if(!this.options.includeMetadataChanges){let t=[];for(let r of e.docChanges)3!==r.type&&t.push(r);e=new iw(e.query,e.docs,e.oldDocs,t,e.mutatedKeys,e.fromCache,e.syncStateChanged,!0,e.hasCachedResults)}let t=!1;return this.xa?this.Na(e)&&(this.Ma.next(e),t=!0):this.Ba(e,this.onlineState)&&(this.La(e),t=!0),this.Oa=e,t}onError(e){this.Ma.error(e)}va(e){this.onlineState=e;let t=!1;return this.Oa&&!this.xa&&this.Ba(this.Oa,e)&&(this.La(this.Oa),t=!0),t}Ba(e,t){return!(e.fromCache&&this.ba())||(!this.options.ka||"Offline"===t)&&(!e.docs.isEmpty()||e.hasCachedResults||"Offline"===t)}Na(e){if(e.docChanges.length>0)return!0;let t=this.Oa&&this.Oa.hasPendingWrites!==e.hasPendingWrites;return!(!e.syncStateChanged&&!t)&&!0===this.options.includeMetadataChanges}La(e){e=iw.fromInitialDocuments(e.query,e.docs,e.mutatedKeys,e.fromCache,e.hasCachedResults),this.xa=!0,this.Ma.next(e)}ba(){return this.options.source!==s.Cache}}class iN{constructor(e){this.key=e}}class iD{constructor(e){this.key=e}}class ik{constructor(e,t){this.query=e,this.Ha=t,this.Ya=null,this.hasCachedResults=!1,this.current=!1,this.Za=tz(),this.mutatedKeys=tz(),this.Xa=tO(e),this.eu=new ip(this.Xa)}get tu(){return this.Ha}nu(e,t){let r=t?t.ru:new iy,n=t?t.eu:this.eu,i=t?t.mutatedKeys:this.mutatedKeys,s=n,a=!1,o="F"===this.query.limitType&&n.size===this.query.limit?n.last():null,l="L"===this.query.limitType&&n.size===this.query.limit?n.first():null;if(e.inorderTraversal((e,t)=>{let u=n.get(e),h=tV(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&&(r.track({type:3,doc:h}),f=!0):this.iu(u,h)||(r.track({type:2,doc:h}),f=!0,(o&&this.Xa(h,o)>0||l&&0>this.Xa(h,l))&&(a=!0)):!u&&h?(r.track({type:0,doc:h}),f=!0):u&&!h&&(r.track({type:1,doc:u}),f=!0,(o||l)&&(a=!0)),f&&(h?(s=s.add(h),i=d?i.add(e):i.delete(e)):(s=s.delete(e),i=i.delete(e)))}),null!==this.query.limit)for(;s.size>this.query.limit;){let e="F"===this.query.limitType?s.last():s.first();s=s.delete(e.key),i=i.delete(e.key),r.track({type:1,doc:e})}return{eu:s,ru:r,Ds:a,mutatedKeys:i}}iu(e,t){return e.hasLocalMutations&&t.hasCommittedMutations&&!t.hasLocalMutations}applyChanges(e,t,r,n){let i=this.eu;this.eu=e.eu,this.mutatedKeys=e.mutatedKeys;let s=e.ru.pa();s.sort((e,t)=>(function(e,t){let r=e=>{switch(e){case 0:return 1;case 2:case 3:return 2;case 1:return 0;default:return S(20277,{At:e})}};return r(e)-r(t)})(e.type,t.type)||this.Xa(e.doc,t.doc)),this.su(r),n=null!=n&&n;let a=t&&!n?this.ou():[],o=0===this.Za.size&&this.current&&!n?1:0,l=o!==this.Ya;return(this.Ya=o,0!==s.length||l)?{snapshot:new iw(this.query,e.eu,i,s,e.mutatedKeys,0===o,l,!1,!!r&&r.resumeToken.approximateByteSize()>0),_u:a}:{_u:a}}va(e){return this.current&&"Offline"===e?(this.current=!1,this.applyChanges({eu:this.eu,ru:new iy,mutatedKeys:this.mutatedKeys,Ds:!1},!1)):{_u:[]}}au(e){return!this.Ha.has(e)&&!!this.eu.has(e)&&!this.eu.get(e).hasLocalMutations}su(e){e&&(e.addedDocuments.forEach(e=>this.Ha=this.Ha.add(e)),e.modifiedDocuments.forEach(e=>{}),e.removedDocuments.forEach(e=>this.Ha=this.Ha.delete(e)),this.current=e.current)}ou(){if(!this.current)return[];let e=this.Za;this.Za=tz(),this.eu.forEach(e=>{this.au(e.key)&&(this.Za=this.Za.add(e.key))});let t=[];return e.forEach(e=>{this.Za.has(e)||t.push(new iD(e))}
7),this.Za.forEach(r=>{e.has(r)||t.push(new iN(r))}),t}uu(e){this.Ha=e.qs,this.Za=tz();let t=this.nu(e.documents);return this.applyChanges(t,!0)}cu(){return iw.fromInitialDocuments(this.query,this.eu,this.mutatedKeys,0===this.Ya,this.hasCachedResults)}}let ix="SyncEngine";class iR{constructor(e,t,r){this.query=e,this.targetId=t,this.view=r}}class iV{constructor(e){this.key=e,this.lu=!1}}class iO{constructor(e,t,r,n,i,s){this.localStore=e,this.remoteStore=t,this.eventManager=r,this.sharedClientState=n,this.currentUser=i,this.maxConcurrentLimboResolutions=s,this.hu={},this.Pu=new tF(e=>tx(e),tk),this.Tu=new Map,this.Iu=new Set,this.du=new ew(H.comparator),this.Eu=new Map,this.Au=new na,this.Ru={},this.Vu=new Map,this.mu=r4.ur(),this.onlineState="Unknown",this.fu=void 0}get isPrimaryClient(){return!0===this.fu}}async function iF(e,t,r=!0){let n,i=i2(e),s=i.Pu.get(t);return s?(i.sharedClientState.addLocalQueryTarget(s.targetId),n=s.view.cu()):n=await iM(i,t,r,!0),n}async function iL(e,t){let r=i2(e);await iM(r,t,!0,!1)}async function iM(e,t,r,n){var i,s;let a,o=await (i=e.localStore,s=tC(t),i.persistence.runTransaction("Allocate target","readwrite",e=>{let t;return i.hi.getTargetData(e,s).next(r=>r?(t=r,eh.resolve(t)):i.hi.allocateTargetId(e).next(r=>(t=new rJ(s,r,"TargetPurposeListen",e.currentSequenceNumber),i.hi.addTargetData(e,t).next(()=>t))))}).then(e=>{let t=i.Fs.get(e.targetId);return(null===t||e.snapshotVersion.compareTo(t.snapshotVersion)>0)&&(i.Fs=i.Fs.insert(e.targetId,e),i.Ms.set(s,e.targetId)),e})),l=o.targetId,u=e.sharedClientState.addLocalQueryTarget(l,r);return n&&(a=await iP(e,t,l,"current"===u,o.resumeToken)),e.isPrimaryClient&&r&&nX(e.remoteStore,o),a}async function iP(e,t,r,n,i){e.gu=(t,r,n)=>(async function(e,t,r,n){let i=t.view.nu(r);i.Ds&&(i=await nS(e.localStore,t.query,!1).then(({documents:e})=>t.view.nu(e,i)));let s=n&&n.targetChanges.get(t.targetId),a=n&&null!=n.targetMismatches.get(t.targetId),o=t.view.applyChanges(i,e.isPrimaryClient,s,a);return iJ(e,t.targetId,o._u),o.snapshot})(e,t,r,n);let s=await nS(e.localStore,t,!0),a=new ik(t,s.qs),o=a.nu(s.documents),l=rE.createSynthesizedTargetChangeForCurrentChange(r,n&&"Offline"!==e.onlineState,i),u=a.applyChanges(o,e.isPrimaryClient,l);iJ(e,r,u._u);let h=new iR(t,r,a);return e.Pu.set(t,h),e.Tu.has(r)?e.Tu.get(r).push(t):e.Tu.set(r,[t]),u.snapshot}async function iU(e,t,r){let n=e.Pu.get(t),i=e.Tu.get(n.targetId);if(i.length>1)return e.Tu.set(n.targetId,i.filter(e=>!tk(e,t))),void e.Pu.delete(t);e.isPrimaryClient?(e.sharedClientState.removeLocalQueryTarget(n.targetId),e.sharedClientState.isActiveQueryTarget(n.targetId)||await nI(e.localStore,n.targetId,!1).then(()=>{e.sharedClientState.clearQueryState(n.targetId),r&&nZ(e.remoteStore,n.targetId),iH(e,n.targetId)}).catch(eu)):(iH(e,n.targetId),await nI(e.localStore,n.targetId,!0))}async function iq(e,t){let r=e.Pu.get(t),n=e.Tu.get(r.targetId);e.isPrimaryClient&&1===n.length&&(e.sharedClientState.removeLocalQueryTarget(r.targetId),nZ(e.remoteStore,r.targetId))}async function i$(e,t,r){var n,i;let s=((n=e).remoteStore.remoteSyncer.applySuccessfulWrite=iG.bind(null,n),n.remoteStore.remoteSyncer.rejectFailedWrite=iK.bind(null,n),n);try{let e,n=await function(e,t){let r,n,i=ei.now(),s=t.reduce((e,t)=>e.add(t.key),tz());return e.persistence.runTransaction("Locally write mutations","readwrite",a=>{let o=tL,l=tz();return e.Os.getEntries(a,s).next(e=>{(o=e).forEach((e,t)=>{t.isValidDocument()||(l=l.add(e))})}).next(()=>e.localDocuments.getOverlayedDocuments(a,o)).next(n=>{r=n;let s=[];for(let e of t){let t=function(e,t){let r=null;for(let n of e.fieldTransforms){let e=t.data.field(n.field),i=tW(n.transform,e||null);null!=i&&(null===r&&(r=e8.empty()),r.set(n.field,i))}return r||null}(e,r.get(e.key).overlayedDocument);null!=t&&s.push(new rr(e.key,t,function e(t){let r=[];return ep(t.fields,(t,n)=>{let i=new W([t]);if(e3(n)){let t=e(n.mapValue).fields;if(0===t.length)r.push(i);else for(let e of t)r.push(i.child(e))}else r.push(i)}),new eI(r)}(t.value.mapValue),t6.exists(!0)))}return e.mutationQueue.addMutationBatch(a,i,s,t)}).next(t=>{n=t;let i=t.applyToLocalDocumentSet(r,l);return e.documentOverlayCache.saveOverlays(a,t.batchId,i)})}).then(()=>({batchId:n.batchId,changes:tU(r)}))}(s.localStore,t);
7s.sharedClientState.addPendingMutation(n.batchId),i=n.batchId,(e=s.Ru[s.currentUser.toKey()])||(e=new ew(q)),e=e.insert(i,r),s.Ru[s.currentUser.toKey()]=e,await iZ(s,n.changes),await it(s.remoteStore)}catch(t){let e=ig(t,"Failed to persist write");r.reject(e)}}async function iB(e,t){try{let r=await function(e,t){let r=t.snapshotVersion,n=e.Fs;return e.persistence.runTransaction("Apply remote event","readwrite-primary",i=>{var s,a,o;let l,u,h=e.Os.newChangeBuffer({trackRemovals:!0});n=e.Fs;let c=[];t.targetChanges.forEach((s,a)=>{var o;let l=n.get(a);if(!l)return;c.push(e.hi.removeMatchingKeys(i,s.removedDocuments,a).next(()=>e.hi.addMatchingKeys(i,s.addedDocuments,a)));let u=l.withSequenceNumber(i.currentSequenceNumber);null!==t.targetMismatches.get(a)?u=u.withResumeToken(eb.EMPTY_BYTE_STRING,es.min()).withLastLimboFreeSnapshotVersion(es.min()):s.resumeToken.approximateByteSize()>0&&(u=u.withResumeToken(s.resumeToken,r)),n=n.insert(a,u),o=u,(0===l.resumeToken.approximateByteSize()||o.snapshotVersion.toMicroseconds()-l.snapshotVersion.toMicroseconds()>=3e8||s.addedDocuments.size+s.modifiedDocuments.size+s.removedDocuments.size>0)&&c.push(e.hi.updateTargetData(i,u))});let d=tL,f=tz();if(t.documentUpdates.forEach(r=>{t.resolvedLimboDocuments.has(r)&&c.push(e.persistence.referenceDelegate.updateLimboDocument(i,r))}),c.push((s=i,a=h,o=t.documentUpdates,l=tz(),u=tz(),o.forEach(e=>l=l.add(e)),a.getEntries(s,l).next(e=>{let t=tL;return o.forEach((r,n)=>{let i=e.get(r);n.isFoundDocument()!==i.isFoundDocument()&&(u=u.add(r)),n.isNoDocument()&&n.version.isEqual(es.min())?(a.removeEntry(r,n.readTime),t=t.insert(r,n)):!i.isValidDocument()||n.version.compareTo(i.version)>0||0===n.version.compareTo(i.version)&&i.hasPendingWrites?(a.addEntry(n),t=t.insert(r,n)):_(nv,"Ignoring outdated watch update for ",r,". Current version:",i.version," Watch version:",n.version)}),{Ls:t,ks:u}})).next(e=>{d=e.Ls,f=e.ks})),!r.isEqual(es.min())){let t=e.hi.getLastRemoteSnapshotVersion(i).next(t=>e.hi.setTargetsMetadata(i,i.currentSequenceNumber,r));c.push(t)}return eh.waitFor(c).next(()=>h.apply(i)).next(()=>e.localDocuments.getLocalViewOfDocuments(i,d,f)).next(()=>d)}).then(t=>(e.Fs=n,t))}(e.localStore,t);
7t.targetChanges.forEach((t,r)=>{let n=e.Eu.get(r);n&&(C(t.addedDocuments.size+t.modifiedDocuments.size+t.removedDocuments.size<=1,22616),t.addedDocuments.size>0?n.lu=!0:t.modifiedDocuments.size>0?C(n.lu,14607):t.removedDocuments.size>0&&(C(n.lu,42227),n.lu=!1))}),await iZ(e,r,t)}catch(e){await eu(e)}}function iz(e,t,r){var n;if(e.isPrimaryClient&&0===r||!e.isPrimaryClient&&1===r){let r,i=[];e.Pu.forEach((e,r)=>{let n=r.view.va(t);n.snapshot&&i.push(n.snapshot)}),(n=e.eventManager).onlineState=t,r=!1,n.queries.forEach((e,n)=>{for(let e of n.wa)e.va(t)&&(r=!0)}),r&&iC(n),i.length&&e.hu.J_(i),e.onlineState=t,e.isPrimaryClient&&e.sharedClientState.setOnlineState(t)}}async function ij(e,t,r){e.sharedClientState.updateQueryState(t,"rejected",r);let n=e.Eu.get(t),i=n&&n.key;if(i){let r=new ew(H.comparator);r=r.insert(i,e9.newNoDocument(i,es.min()));let n=tz().add(i),s=new r_(es.min(),new Map,new ew(q),r,n);await iB(e,s),e.du=e.du.remove(i),e.Eu.delete(t),iX(e)}else await nI(e.localStore,t,!1).then(()=>iH(e,t,r)).catch(eu)}async function iG(e,t){var r;let n=t.batch.batchId;try{let i=await (r=e.localStore,r.persistence.runTransaction("Acknowledge batch","readwrite-primary",e=>{let n=t.batch.keys(),i=r.Os.newChangeBuffer({trackRemovals:!0});return(function(e,t,r,n){let i=r.batch,s=i.keys(),a=eh.resolve();return s.forEach(e=>{a=a.next(()=>n.getEntry(t,e)).next(t=>{let s=r.docVersions.get(e);C(null!==s,48541),0>t.version.compareTo(s)&&(i.applyToRemoteDocument(t,r),t.isValidDocument()&&(t.setReadTime(r.commitVersion),n.addEntry(t)))})}),a.next(()=>e.mutationQueue.removeMutationBatch(t,i))})(r,e,t,i).next(()=>i.apply(e)).next(()=>r.mutationQueue.performConsistencyCheck(e)).next(()=>r.documentOverlayCache.removeOverlaysForBatchId(e,n,t.batch.batchId)).next(()=>r.localDocuments.recalculateAndSaveOverlaysForDocumentKeys(e,function(e){let t=tz();for(let r=0;r<e.mutationResults.length;++r)e.mutationResults[r].transformResults.length>0&&(t=t.add(e.batch.mutations[r].key));return t}(t))).next(()=>r.localDocuments.getDocuments(e,n))}));iW(e,n,null),iQ(e,n),e.sharedClientState.updateMutationState(n,"acknowledged"),await iZ(e,i)}catch(e){await eu(e)}}async function iK(e,t,r){var n;try{let i=await (n=e.localStore,n.persistence.runTransaction("Reject batch","readwrite-primary",e=>{let r;
7return n.mutationQueue.lookupMutationBatch(e,t).next(t=>(C(null!==t,37113),r=t.keys(),n.mutationQueue.removeMutationBatch(e,t))).next(()=>n.mutationQueue.performConsistencyCheck(e)).next(()=>n.documentOverlayCache.removeOverlaysForBatchId(e,r,t)).next(()=>n.localDocuments.recalculateAndSaveOverlaysForDocumentKeys(e,r)).next(()=>n.localDocuments.getDocuments(e,r))}));iW(e,t,r),iQ(e,t),e.sharedClientState.updateMutationState(t,"rejected",r),await iZ(e,i)}catch(e){await eu(e)}}function iQ(e,t){(e.Vu.get(t)||[]).forEach(e=>{e.resolve()}),e.Vu.delete(t)}function iW(e,t,r){let n=e.Ru[e.currentUser.toKey()];if(n){let i=n.get(t);i&&(r?i.reject(r):i.resolve(),n=n.remove(t)),e.Ru[e.currentUser.toKey()]=n}}function iH(e,t,r=null){for(let n of(e.sharedClientState.removeLocalQueryTarget(t),e.Tu.get(t)))e.Pu.delete(n),r&&e.hu.pu(n,r);e.Tu.delete(t),e.isPrimaryClient&&e.Au.zr(t).forEach(t=>{e.Au.containsKey(t)||iY(e,t)})}function iY(e,t){e.Iu.delete(t.path.canonicalString());let r=e.du.get(t);null!==r&&(nZ(e.remoteStore,r),e.du=e.du.remove(t),e.Eu.delete(r),iX(e))}function iJ(e,t,r){for(let n of r)n instanceof iN?(e.Au.addReference(n.key,t),function(e,t){let r=t.key,n=r.path.canonicalString();e.du.get(r)||e.Iu.has(n)||(_(ix,"New document in limbo: "+r),e.Iu.add(n),iX(e))}(e,n)):n instanceof iD?(_(ix,"Document no longer in limbo: "+n.key),e.Au.removeReference(n.key,t),e.Au.containsKey(n.key)||iY(e,n.key)):S(19791,{yu:n})}function iX(e){for(;e.Iu.size>0&&e.du.size<e.maxConcurrentLimboResolutions;){let t=e.Iu.values().next().value;e.Iu.delete(t);let r=new H(K.fromString(t)),n=e.mu.next();e.Eu.set(n,new iV(r)),e.du=e.du.insert(r,n),nX(e.remoteStore,new rJ(tC(tT(r.path)),n,"TargetPurposeLimboResolution",ed.ue))}}async function iZ(e,t,r){let n=[],i=[],s=[];e.Pu.isEmpty()||(e.Pu.forEach((a,o)=>{s.push(e.gu(o,t,r).then(t=>{var s;if((t||r)&&e.isPrimaryClient){let n=t?!t.fromCache:null==(s=null==r?void 0:r.targetChanges.get(o.targetId))?void 0:s.current;e.sharedClientState.updateQueryState(o.targetId,n?"current":"not-current")}if(t){n.push(t);let e=np.Es(o.targetId,t);i.push(e)}}))}),await Promise.all(s),e.hu.J_(n),await async function(e,t){try{await e.persistence.runTransaction("notifyLocalViewChanges","readwrite",r=>eh.forEach(t,t=>eh.forEach(t.Is,n=>e.persistence.referenceDelegate.addReference(r,t.targetId,n)).next(()=>eh.forEach(t.ds,n=>e.persistence.referenceDelegate.removeReference(r,t.targetId,n)))))}catch(e){if(!ec(e))throw e;_(nv,"Failed to update sequence numbers: "+e)}for(let r of t){let t=r.targetId;if(!r.fromCache){let r=e.Fs.get(t),n=r.snapshotVersion,i=r.withLastLimboFreeSnapshotVersion(n);e.Fs=e.Fs.insert(t,i)}}}(e.localStore,i))}async function i0(e,t){if(!e.currentUser.isEqual(t)){_(ix,"User change. New user:",t.toKey());let r=await nE(e.localStore,t);e.currentUser=t,e.Vu.forEach(e=>{e.forEach(e=>{e.reject(new N(A.CANCELLED,"'waitForPendingWrites' promise is rejected due to a user change."))})}),e.Vu.clear(),e.sharedClientState.handleUserChange(t,r.removedBatchIds,r.addedBatchIds),await iZ(e,r.Bs)}}function i1(e,t){let r=e.Eu.get(t);if(r&&r.lu)return tz().add(r.key);{let r=tz(),n=e.Tu.get(t);if(!n)return r;for(let t of n){let n=e.Pu.get(t);r=r.unionWith(n.view.tu)}return r}}function i2(e){return e.remoteStore.remoteSyncer.applyRemoteEvent=iB.bind(null,e),e.remoteStore.remoteSyncer.getRemoteKeysForTarget=i1.bind(null,e),e.remoteStore.remoteSyncer.rejectListen=ij.bind(null,e),e.hu.J_=iS.bind(null,e.eventManager),e.hu.pu=ib.bind(null,e.eventManager),e}class i3{constructor(){this.kind="memory",this.synchronizeTabs=!1}async initialize(e){this.serializer=nU(e.databaseInfo.databaseId),this.sharedClientState=this.bu(e),this.persistence=this.Du(e),await this.persistence.start(),this.localStore=this.vu(e),this.gcScheduler=this.Cu(e,this.localStore),this.indexBackfillerScheduler=this.Fu(e,this.localStore)}Cu(e,t){return null}Fu(e,t){return null}vu(e){var t,r;return t=this.persistence,r=new nw,new n_(t,r,e.initialUser,this.serializer)}Du(e){return new nd(nm.Vi,this.serializer)}bu(e){return new nC}async terminate(){var e,t;null==(e=this.gcScheduler)||e.stop(),null==(t=this.indexBackfillerScheduler)||t.stop(),this.sharedCl
7ientState.shutdown(),await this.persistence.shutdown()}}i3.provider={build:()=>new i3};class i4 extends i3{constructor(e){super(),this.cacheSizeBytes=e}Cu(e,t){return C(this.persistence.referenceDelegate instanceof ng,46915),new r9(this.persistence.referenceDelegate.garbageCollector,e.asyncQueue,t)}Du(e){let t=void 0!==this.cacheSizeBytes?r3.withCacheSize(this.cacheSizeBytes):r3.DEFAULT;return new nd(e=>ng.Vi(e,t),this.serializer)}}class i6{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=>iz(this.syncEngine,e,1),this.remoteStore.remoteSyncer.handleCredentialChange=i0.bind(null,this.syncEngine),await ih(this.remoteStore,this.syncEngine.isPrimaryClient))}createEventManager(e){return new i_}createDatastore(e){var t;let r=nU(e.databaseInfo.databaseId),n=new nM(e.databaseInfo);return t=e.authCredentials,new nK(t,e.appCheckCredentials,n,r)}createRemoteStore(e){var t,r;return t=this.localStore,r=this.datastore,new nH(t,r,e.asyncQueue,e=>iz(this.syncEngine,e,0),nD.C()?new nD:new nA)}createSyncEngine(e,t){return function(e,t,r,n,i,s,a){let o=new iO(e,t,r,n,i,s);return a&&(o.fu=!0),o}(this.localStore,this.remoteStore,this.eventManager,this.sharedClientState,e.initialUser,e.maxConcurrentLimboResolutions,t)}async terminate(){var e,t;await async function(e){_(nW,"RemoteStore shutting down."),e.Ia.add(5),await nJ(e),e.Ea.shutdown(),e.Aa.set("Unknown")}(this.remoteStore),null==(e=this.datastore)||e.terminate(),null==(t=this.eventManager)||t.terminate()}}i6.provider={build:()=>new i6};class i5{constructor(e){this.observer=e,this.muted=!1}next(e){this.muted||this.observer.next&&this.xu(this.observer.next,e)}error(e){this.muted||(this.observer.error?this.xu(this.observer.error,e):E("Uncaught Error in snapshot listener:",e.toString()))}Ou(){this.muted=!0}xu(e,t){setTimeout(()=>{this.muted||e(t)},0)}}class i8{constructor(e){this.datastore=e,this.readVersions=new Map,this.mutations=[],this.committed=!1,this.lastTransactionError=null,this.writtenDocs=new Set}async lookup(e){if(this.ensureCommitNotCalled(),this.mutations.length>0)throw this.lastTransactionError=new N(A.INVALID_ARGUMENT,"Firestore transactions require all reads to be executed before all writes."),this.lastTransactionError;let t=await async function(e,t){let r={documents:t.map(t=>rq(e.serializer,t))},n=await e.Jo("BatchGetDocuments",e.serializer.databaseId,K.emptyPath(),r,t.length),i=new Map;n.forEach(t=>{var r;let n=(r=e.serializer,"found"in t?function(e,t){C(!!t.found,43571),t.found.name,t.found.updateTime;let r=r$(e,t.found.name),n=rL(t.found.updateTime),i=t.found.createTime?rL(t.found.createTime):es.min(),s=new e8({mapValue:{fields:t.found.fields}});return e9.newFoundDocument(r,n,i,s)}(r,t):"missing"in t?function(e,t){C(!!t.missing,3894),C(!!t.readTime,22933);let r=r$(e,t.missing),n=rL(t.readTime);return e9.newNoDocument(r,n)}(r,t):S(7234,{result:t}));i.set(n.key.toString(),n)});let s=[];return t.forEach(e=>{let t=i.get(e.toString());C(!!t,55234,{key:e}),s.push(t)}),s}(this.datastore,e);return t.forEach(e=>this.recordVersion(e)),t}set(e,t){this.write(t.toMutation(e,this.precondition(e))),this.writtenDocs.add(e.toString())}update(e,t){try{this.write(t.toMutation(e,this.preconditionForUpdate(e)))}catch(e){this.lastTransactionError=e}this.writtenDocs.add(e.toString())}delete(e){this.write(new ra(e,this.precondition(e))),this.writtenDocs.add(e.toString())}async commit(){if(this.ensureCommitNotCalled(),this.lastTransactionError)throw this.lastTransactionError;let e=this.readVersions;this.mutations.forEach(t=>{e.delete(t.key.toString())}),e.forEach((e,t)=>{let r=H.fromPath(t);this.mutations.push(new ro(r,this.precondition(r)))}),await async function(e,t){let r={writes:t.map(t=>rK(e.serializer,t))};await e.Wo("Commit",e.serializer.databaseId,K.emptyPath(),r)}(this.datastore,this.mutations),this.committed=!0}recordVersion(e){let t;if(e.isFoundDocument())t=e.version;else{if(!e.isNoDocument())throw S(50498,{Wu:e.constructor.name});t=es.min()}let r=this.readVersions.get(e.key.toString());if(r){if(!t.isEqual(r))throw new N(A.ABORTED,"Document version changed between two reads.")}else this.readVersions.set(e.key.toString(),t)}precondition(e){let t=this.readVersions.get(e.toString());return!this.writtenDocs.has(e.toString())&&t?t.isEqual(es.min())?t6.exists(!1):t6.updateTime(t):t6.none()}preconditionForUpdate(e){let t=this.readVersions.get(e.toString());if(!this.writtenDocs.has(e.toString())&&t){if(t.isEqual(es.min()))throw new N(A.INVALID_ARGUMENT,"Can't update a document that doesn't exist.");return t6.updateTime(t)}return t6.exists(!0)}write(e){this.ensureCommitNotCalled(),this.mutations.push(e)}ensureCommitNotCalled(){}}class i9{constructor(e,t,r,n,i){this.asyncQueue=e,this.datastore=t,this.options=r,this.updateFunction=n,this.deferred=i,this.Gu=r.maxAttempts,this.F_=new nq(this.asyncQueue,"transaction_retry")}zu(){this.Gu-=1,this.ju()}ju(){this.F_.g_(async()=>{let e=new i8(this.datastore),t=this.Ju(e);t&&t.then(t=>{this.asyncQueue.enqueueAndForget(()=>e.commit().then(()=>{this.deferred.resolve(t)}).catch(e=>{this.Hu(e)}))}).catch(e=>{this.Hu(e)})})}Ju(e){try{let t=this.updateFunction(e);return!ef(t)&&t.catch&&t.then?t:(this.deferred.reject(Error("Transaction callback must return a Promise")),null)}catch(e){return this.deferred.reject(e),null}}Hu(e){this.Gu>0&&this.Yu(e)?(this.Gu-=1,this.asyncQueue.enqueueAndForget(()=>(this.ju(),Promise.resolve()))):this.deferred.reject(e)}Yu(e){if("FirebaseError"===e.name){let t=e.code;return"aborted"===t||"failed-precondition"===t||"already-exists"===t||!rf(t)}return!1}}let i7="FirestoreClient";class se{constructor(e,t,r,n,i){this.authCredentials=e,this.appCheckCredentials=t,this.asyncQueue=r,this.databaseInfo=n,this.user=p.UNAUTHENTICATED,this.clientId=U.newId(),this.authCredentialListener=()=>Promise.resolve(),this.appCheckCredentialListener=()=>Promise.resolve(),this._uninitializedComponentsProvider=i,this.authCredentials.start(r,async e=>{_(i7,"Received user=",e.uid),await this.authCredentialListener(e),this.user=e}),this.appCheckCredentials.start(r,e=>(_(i7,"Received new app check token=",e),this.appCheckCredentialListener(e,this.user)))}get configuration(){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}terminate(){this.asyncQueue.enterRestrictedMode();let e=new D;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(r){let t=ig(r,"Failed to shutdown persistence");e.reject(t)}}),e.promise}}async function st(e,t){e.asyncQueue.verifyOperationInProgress(),_(i7,"Initializing OfflineComponentProvider");let r=e.configuration;await t.initialize(r);let n=r.initialUser;e.setCredentialChangeListener(async e=>{n.isEqual(e)||(await nE(t.localStore,e),n=e)}),t.persistence.setDatabaseDeletedListener(()=>{T("Terminating Firestore due to IndexedDb database deletion"),e.terminate().then(()=>{_("Terminating Firestore due to IndexedDb database deletion completed successfully")}).catch(e=>{T("Terminating Firestore due to IndexedDb database deletion failed",e)})}),e._offlineComponents=t}async function sr(e,t){e.asyncQueue.verifyOperationInProgress();let r=await sn(e);_(i7,"Initializing OnlineComponentProvider"),await t.initialize(r,e.configuration),e.setCredentialChangeListener(e=>iu(t.remoteStore,e)),e.setAppCheckTokenChangeListener((e,r)=>iu(t.remoteStore,r)),e._onlineComponents=t}async function sn(e){if(!e._offlineComponents)if(e._uninitializedComponentsProvider){_(i7,"Using user provided OfflineComponentProvider");try{await st(e,e._uninitializedComponentsProvider._offline)}catch(t){if(!("FirebaseError"===t.name?t.code===A.FAILED_PRECONDITION||t.code===A.UNIMPLEMENT
7ED:!("undefined"!=typeof DOMException&&t instanceof DOMException)||22===t.code||20===t.code||11===t.code))throw t;T("Error using user provided cache. Falling back to memory cache: "+t),await st(e,new i3)}}else _(i7,"Using default OfflineComponentProvider"),await st(e,new i4(void 0));return e._offlineComponents}async function si(e){return e._onlineComponents||(e._uninitializedComponentsProvider?(_(i7,"Using user provided OnlineComponentProvider"),await sr(e,e._uninitializedComponentsProvider._online)):(_(i7,"Using default OnlineComponentProvider"),await sr(e,new i6))),e._onlineComponents}function ss(e){return si(e).then(e=>e.datastore)}async function sa(e){let t=await si(e),r=t.eventManager;return r.onListen=iF.bind(null,t.syncEngine),r.onUnlisten=iU.bind(null,t.syncEngine),r.onFirstRemoteStoreListen=iL.bind(null,t.syncEngine),r.onLastRemoteStoreUnlisten=iq.bind(null,t.syncEngine),r}function so(e){let t={};return void 0!==e.timeoutSeconds&&(t.timeoutSeconds=e.timeoutSeconds),t}let sl=new Map,su="firestore.googleapis.com";class sh{constructor(e){var t,r;if(void 0===e.host){if(void 0!==e.ssl)throw new N(A.INVALID_ARGUMENT,"Can't provide ssl option if host option is not set");this.host=su,this.ssl=!0}else this.host=e.host,this.ssl=null==(t=e.ssl)||t;if(this.isUsingEmulator=void 0!==e.emulatorOptions,this.credentials=e.credentials,this.ignoreUndefinedProperties=!!e.ignoreUndefinedProperties,this.localCache=e.localCache,void 0===e.cacheSizeBytes)this.cacheSizeBytes=0x2800000;else{if(-1!==e.cacheSizeBytes&&e.cacheSizeBytes<1048576)throw new N(A.INVALID_ARGUMENT,"cacheSizeBytes must be at least 1048576");this.cacheSizeBytes=e.cacheSizeBytes}(function(e,t,r,n){if(!0===t&&!0===n)throw new N(A.INVALID_ARGUMENT,`${e} and ${r} cannot be used together.`)})("experimentalForceLongPolling",e.experimentalForceLongPolling,"experimentalAutoDetectLongPolling",e.experimentalAutoDetectLongPolling),this.experimentalForceLongPolling=!!e.experimentalForceLongPolling,this.experimentalForceLongPolling?this.experimentalAutoDetectLongPolling=!1:void 0===e.experimentalAutoDetectLongPolling?this.experimentalAutoDetectLongPolling=!0:this.experimentalAutoDetectLongPolling=!!e.experimentalAutoDetectLongPolling,this.experimentalLongPollingOptions=so(null!=(r=e.experimentalLongPollingOptions)?r:{}),function(e){if(void 0!==e.timeoutSeconds){if(isNaN(e.timeoutSeconds))throw new N(A.INVALID_ARGUMENT,`invalid long polling timeout: ${e.timeoutSeconds} (must not be NaN)`);if(e.timeoutSeconds<5)throw new N(A.INVALID_ARGUMENT,`invalid long polling timeout: ${e.timeoutSeconds} (minimum allowed value is 5)`);if(e.timeoutSeconds>30)throw new N(A.INVALID_ARGUMENT,`invalid long polling timeout: ${e.timeoutSeconds} (maximum allowed value is 30)`)}}(this.experimentalLongPollingOptions),this.useFetchStreams=!!e.useFetchStreams}isEqual(e){var t,r;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&&(t=this.experimentalLongPollingOptions,r=e.experimentalLongPollingOptions,t.timeoutSeconds===r.timeoutSeconds)&&this.ignoreUndefinedProperties===e.ignoreUndefinedProperties&&this.useFetchStreams===e.useFetchStreams}}class sc{constructor(e,t,r,n){this._authCredentials=e,this._appCheckCredentials=t,this._databaseId=r,this._app=n,this.type="firestore-lite",this._persistenceKey="(lite)",this._settings=new sh({}),this._settingsFrozen=!1,this._emulatorOptions={},this._terminateTask="notTerminated"}get app(){if(!this._app)throw new N(A.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"notTerminated"!==this._terminateTask}_setSettings(e){if(this._settingsFrozen)throw new N(A.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 sh(e),this._emulatorOptions=e.emulatorOptions||{},void 0!==e.credentials&&(this._authCredentials=function(e){if(!e)return new x;switch(e.type){case"firstParty":return new F(e.sessionIndex||"0",e.iamToken||null,e.authTokenFactory||null);case"provider":return e.client;default:throw new N(A.INVALID_ARGUMENT,"makeAuthCredentialsProvider failed due to invali
7d credential type")}}(e.credentials))}_getSettings(){return this._settings}_getEmulatorOptions(){return this._emulatorOptions}_freezeSettings(){return this._settingsFrozen=!0,this._settings}_delete(){return"notTerminated"===this._terminateTask&&(this._terminateTask=this._terminate()),this._terminateTask}async _restart(){"notTerminated"===this._terminateTask?await this._terminate():this._terminateTask="notTerminated"}toJSON(){return{app:this._app,databaseId:this._databaseId,settings:this._settings}}_terminate(){return function(e){let t=sl.get(e);t&&(_("ComponentProvider","Removing Datastore"),sl.delete(e),t.terminate())}(this),Promise.resolve()}}class sd{constructor(e,t,r){this.converter=t,this._query=r,this.type="query",this.firestore=e}withConverter(e){return new sd(this.firestore,e,this._query)}}class sf{constructor(e,t,r){this.converter=t,this._key=r,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 sm(this.firestore,this.converter,this._key.path.popLast())}withConverter(e){return new sf(this.firestore,e,this._key)}toJSON(){return{type:sf._jsonSchemaVersion,referencePath:this._key.toString()}}static fromJSON(e,t,r){if(en(t,sf._jsonSchema))return new sf(e,r||null,new H(K.fromString(t.referencePath)))}}sf._jsonSchemaVersion="firestore/documentReference/1.0",sf._jsonSchema={type:er("string",sf._jsonSchemaVersion),referencePath:er("string")};class sm extends sd{constructor(e,t,r){super(e,t,tT(r)),this._path=r,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 sf(this.firestore,null,new H(e))}withConverter(e){return new sm(this.firestore,e,this._path)}}function sg(e,t,...r){if(e=(0,h.Ku)(e),Y("collection","path",t),e instanceof sc){let n=K.fromString(t,...r);return X(n),new sm(e,null,n)}{if(!(e instanceof sf||e instanceof sm))throw new N(A.INVALID_ARGUMENT,"Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore");let n=e._path.child(K.fromString(t,...r));return X(n),new sm(e.firestore,null,n)}}function sp(e,t,...r){if(e=(0,h.Ku)(e),1==arguments.length&&(t=U.newId()),Y("doc","path",t),e instanceof sc){let n=K.fromString(t,...r);return J(n),new sf(e,null,new H(n))}{if(!(e instanceof sf||e instanceof sm))throw new N(A.INVALID_ARGUMENT,"Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore");let n=e._path.child(K.fromString(t,...r));return J(n),new sf(e.firestore,e instanceof sm?e.converter:null,new H(n))}}let sy="AsyncQueue";class sw{constructor(e=Promise.resolve()){this.Zu=[],this.Xu=!1,this.ec=[],this.tc=null,this.nc=!1,this.rc=!1,this.sc=[],this.F_=new nq(this,"async_queue_retry"),this.oc=()=>{let e=nP();e&&_(sy,"Visibility state changed to "+e.visibilityState),this.F_.y_()},this._c=e;let t=nP();t&&"function"==typeof t.addEventListener&&t.addEventListener("visibilitychange",this.oc)}get isShuttingDown(){return this.Xu}enqueueAndForget(e){this.enqueue(e)}enqueueAndForgetEvenWhileRestricted(e){this.ac(),this.uc(e)}enterRestrictedMode(e){if(!this.Xu){this.Xu=!0,this.rc=e||!1;let t=nP();t&&"function"==typeof t.removeEventListener&&t.removeEventListener("visibilitychange",this.oc)}}enqueue(e){if(this.ac(),this.Xu)return new Promise(()=>{});let t=new D;return this.uc(()=>this.Xu&&this.rc?Promise.resolve():(e().then(t.resolve,t.reject),t.promise)).then(()=>t.promise)}enqueueRetryable(e){this.enqueueAndForget(()=>(this.Zu.push(e),this.cc()))}async cc(){if(0!==this.Zu.length){try{await this.Zu[0](),this.Zu.shift(),this.F_.reset()}catch(e){if(!ec(e))throw e;_(sy,"Operation failed with retryable error: "+e)}this.Zu.length>0&&this.F_.g_(()=>this.cc())}}uc(e){let t=this._c.then(()=>(this.nc=!0,e().catch(e=>{throw this.tc=e,this.nc=!1,E("INTERNAL UNHANDLED ERROR: ",sv(e)),e}).then(e=>(this.nc=!1,e))));return this._c=t,t}enqueueAfterDelay(e,t,r){this.ac(),this.sc.indexOf(e)>-1&&(t=0);let n=im.createAndSchedule(this,e,t,r,e=>this.lc(e));return this.ec.push(n),n}ac(){this.tc&&S(47125,{hc:sv(this.tc)})}verifyOperationInProgress(){}async Pc(){let e;do e=this._c,await e;while(e!==this._c)}Tc(e){for(let t of this.ec)if(t.timerId===e)return!0;return!1}Ic(e){return this.Pc().then(()=>{for(let t of(this.ec.sort((e,t)=>
7e.targetTimeMs-t.targetTimeMs),this.ec))if(t.skipDelay(),"all"!==e&&t.timerId===e)break;return this.Pc()})}dc(e){this.sc.push(e)}lc(e){let t=this.ec.indexOf(e);this.ec.splice(t,1)}}function sv(e){let t=e.message||"";return e.stack&&(t=e.stack.includes(e.message)?e.stack:e.message+"\n"+e.stack),t}function s_(e){if("object"!=typeof e||null===e)return!1;for(let t of["next","error","complete"])if(t in e&&"function"==typeof e[t])return!0;return!1}class sE extends sc{constructor(e,t,r,n){super(e,t,r,n),this.type="firestore",this._queue=new sw,this._persistenceKey=(null==n?void 0:n.name)||"[DEFAULT]"}async _terminate(){if(this._firestoreClient){let e=this._firestoreClient.terminate();this._queue=new sw(e),this._firestoreClient=void 0,await e}}}function sT(e,t){let r="object"==typeof e?e:(0,o.Sx)(),n=(0,o.j6)(r,"firestore").getImmediate({identifier:"string"==typeof e?e:t||eP});if(!n._initialized){let e=(0,h.yU)("firestore");e&&function(e,t,r,n={}){var i;e=et(e,sc);let s=(0,h.zJ)(t),a=e._getSettings(),o=Object.assign(Object.assign({},a),{emulatorOptions:e._getEmulatorOptions()}),l=`${t}:${r}`;s&&((0,h.gE)(`https://${l}`),(0,h.P1)("Firestore",!0)),a.host!==su&&a.host!==l&&T("Host has been set in both settings() and connectFirestoreEmulator(), emulator host will be used.");let u=Object.assign(Object.assign({},a),{host:l,ssl:s,emulatorOptions:n});if(!(0,h.bD)(u,o)&&(e._setSettings(u),n.mockUserToken)){let t,r;if("string"==typeof n.mockUserToken)t=n.mockUserToken,r=p.MOCK_USER;else{t=(0,h.Fy)(n.mockUserToken,null==(i=e._app)?void 0:i.options.projectId);let s=n.mockUserToken.sub||n.mockUserToken.user_id;if(!s)throw new N(A.INVALID_ARGUMENT,"mockUserToken must contain 'sub' or 'user_id' field!");r=new p(s)}e._authCredentials=new R(new k(t,r))}}(n,...e)}return n}function sI(e){if(e._terminated)throw new N(A.FAILED_PRECONDITION,"The client has already been terminated.");return e._firestoreClient||function(e){var t,r,n,i,s;let a=e._freezeSettings(),o=(i=e._databaseId,s=(null==(t=e._app)?void 0:t.options.appId)||"",new eM(i,s,e._persistenceKey,a.host,a.ssl,a.experimentalForceLongPolling,a.experimentalAutoDetectLongPolling,so(a.experimentalLongPollingOptions),a.useFetchStreams,a.isUsingEmulator));e._componentsProvider||(null==(r=a.localCache)?void 0:r._offlineComponentProvider)&&(null==(n=a.localCache)?void 0:n._onlineComponentProvider)&&(e._componentsProvider={_offline:a.localCache._offlineComponentProvider,_online:a.localCache._onlineComponentProvider}),e._firestoreClient=new se(e._authCredentials,e._appCheckCredentials,e._queue,o,e._componentsProvider&&function(e){let t=null==e?void 0:e._online.build();return{_offline:null==e?void 0:e._offline.build(t),_online:t}}(e._componentsProvider))}(e),e._firestoreClient}class sS{constructor(e="count",t){this._internalFieldPath=t,this.type="AggregateField",this.aggregateType=e}}class sb{constructor(e,t,r){this._userDataWriter=t,this._data=r,this.type="AggregateQuerySnapshot",this.query=e}data(){return this._userDataWriter.convertObjectMap(this._data)}}class sC{constructor(e){this._byteString=e}static fromBase64String(e){try{return new sC(eb.fromBase64String(e))}catch(e){throw new N(A.INVALID_ARGUMENT,"Failed to construct data from Base64 string: "+e)}}static fromUint8Array(e){return new sC(eb.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)}toJSON(){return{type:sC._jsonSchemaVersion,bytes:this.toBase64()}}static fromJSON(e){if(en(e,sC._jsonSchema))return sC.fromBase64String(e.bytes)}}sC._jsonSchemaVersion="firestore/bytes/1.0",sC._jsonSchema={type:er("string",sC._jsonSchemaVersion),bytes:er("string")};class sA{constructor(...e){for(let t=0;t<e.length;++t)if(0===e[t].length)throw new N(A.INVALID_ARGUMENT,"Invalid field name at argument $(i + 1). Field names must not be empty.");this._internalPath=new W(e)}isEqual(e){return this._internalPath.isEqual(e._internalPath)}}function sN(){return new sA(j)}class sD{constructor(e){this._methodName=e}}class sk{constructor(e,t){if(!isFinite(e)||e<-90||e>90)throw new N(A.INVALID_ARGUMENT,"Latitude must be a number between -90 and 90, but was: "+e);if(!isFinite(t)||t<-180||t>180)throw new N(A.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}_compareTo(e){return q(this._lat,e._lat)||q(this._long,e._long)}toJSON(){return{latitude:this._lat,longitude:this._long,type:sk._jsonSchemaVersion}}static fromJSON(e){if(en(e,sk._jsonSchema))return new sk(e.latitude,e.longitude)}}sk._jsonSchemaVersion="firestore/geoPoint/1.0",sk._jsonSchema={type:er("string",sk._jsonSchemaVersion),latitude:er("number"),longitude:er("number")};class sx{constructor(e){this._values=(e||[]).map(e=>e)}toArray(){return this._values.map(e=>e)}isEqual(e){return function(e,t){if(e.length!==t.length)return!1;for(let r=0;r<e.length;++r)if(e[r]!==t[r])return!1;return!0}(this._values,e._values)}toJSON(){return{type:sx._jsonSchemaVersion,vectorValues:this._values}}
7static fromJSON(e){if(en(e,sx._jsonSchema)){if(Array.isArray(e.vectorValues)&&e.vectorValues.every(e=>"number"==typeof e))return new sx(e.vectorValues);throw new N(A.INVALID_ARGUMENT,"Expected 'vectorValues' field to be a number array")}}}sx._jsonSchemaVersion="firestore/vectorValue/1.0",sx._jsonSchema={type:er("string",sx._jsonSchemaVersion),vectorValues:er("object")};let sR=/^__.*__$/;class sV{constructor(e,t,r){this.data=e,this.fieldMask=t,this.fieldTransforms=r}toMutation(e,t){return null!==this.fieldMask?new rr(e,this.data,this.fieldMask,t,this.fieldTransforms):new rt(e,this.data,t,this.fieldTransforms)}}class sO{constructor(e,t,r){this.data=e,this.fieldMask=t,this.fieldTransforms=r}toMutation(e,t){return new rr(e,this.data,this.fieldMask,t,this.fieldTransforms)}}function sF(e){switch(e){case 0:case 2:case 1:return!0;case 3:case 4:return!1;default:throw S(40011,{Ec:e})}}class sL{constructor(e,t,r,n,i,s){this.settings=e,this.databaseId=t,this.serializer=r,this.ignoreUndefinedProperties=n,void 0===i&&this.Ac(),this.fieldTransforms=i||[],this.fieldMask=s||[]}get path(){return this.settings.path}get Ec(){return this.settings.Ec}Rc(e){return new sL(Object.assign(Object.assign({},this.settings),e),this.databaseId,this.serializer,this.ignoreUndefinedProperties,this.fieldTransforms,this.fieldMask)}Vc(e){var t;let r=null==(t=this.path)?void 0:t.child(e),n=this.Rc({path:r,mc:!1});return n.fc(e),n}gc(e){var t;let r=null==(t=this.path)?void 0:t.child(e),n=this.Rc({path:r,mc:!1});return n.Ac(),n}yc(e){return this.Rc({path:void 0,mc:!0})}wc(e){return sX(e,this.settings.methodName,this.settings.Sc||!1,this.path,this.settings.bc)}contains(e){return void 0!==this.fieldMask.find(t=>e.isPrefixOf(t))||void 0!==this.fieldTransforms.find(t=>e.isPrefixOf(t.field))}Ac(){if(this.path)for(let e=0;e<this.path.length;e++)this.fc(this.path.get(e))}fc(e){if(0===e.length)throw this.wc("Document fields must not be empty");if(sF(this.Ec)&&sR.test(e))throw this.wc('Document fields cannot begin and end with "__"')}}class sM{constructor(e,t,r){this.databaseId=e,this.ignoreUndefinedProperties=t,this.serializer=r||nU(e)}Dc(e,t,r,n=!1){return new sL({Ec:e,methodName:t,bc:r,path:W.emptyPath(),mc:!1,Sc:n},this.databaseId,this.serializer,this.ignoreUndefinedProperties)}}function sP(e){let t=e._freezeSettings(),r=nU(e._databaseId);return new sM(e._databaseId,!!t.ignoreUndefinedProperties,r)}function sU(e,t,r,n,i,s={}){let a,o,l=e.Dc(s.merge||s.mergeFields?2:0,t,r,i);sW("Data must be an object, but it was:",l,n);let u=sK(n,l);if(s.merge)a=new eI(l.fieldMask),o=l.fieldTransforms;else if(s.mergeFields){let e=[];for(let n of s.mergeFields){let i=sH(t,n,r);if(!l.contains(i))throw new N(A.INVALID_ARGUMENT,`Field '${i}' is specified in your field mask but missing from your input data.`);sZ(e,i)||e.push(i)}a=new eI(e),o=l.fieldTransforms.filter(e=>a.covers(e.field))}else a=null,o=l.fieldTransforms;return new sV(new e8(u),a,o)}class sq extends sD{_toFieldTransform(e){if(2!==e.Ec)throw 1===e.Ec?e.wc(`${this._methodName}() can only appear at the top level of your update data`):e.wc(`${this._methodName}() cannot be used with set() unless you pass {merge:true}`);return e.fieldMask.push(e.path),null}isEqual(e){return e instanceof sq}}class s$ extends sD{_toFieldTransform(e){return new t3(e.path,new tH)}isEqual(e){return e instanceof s$}}function sB(e,t,r,n){let i=e.Dc(1,t,r);sW("Data must be an object, but it was:",i,n);let s=[],a=e8.empty();return ep(n,(e,n)=>{let o=sJ(t,e,r);n=(0,h.Ku)(n);let l=i.gc(o);if(n instanceof sq)s.push(o);else{let e=sG(n,l);null!=e&&(s.push(o),a.set(o,e))}}),new sO(a,new eI(s),i.fieldTransforms)}function sz(e,t,r,n,i,s){let a=e.Dc(1,t,r),o=[sH(t,n,r)],l=[i];if(s.length%2!=0)throw new N(A.INVALID_ARGUMENT,`Function ${t}() needs to be called with an even number of arguments that alternate between field names and values.`);for(let e=0;e<s.length;e+=2)o.push(sH(t,s[e])),l.push(s[e+1]);let u=[],c=e8.empty();for(let e=o.length-1;e>=0;--e)if(!sZ(u,o[e])){let t=o[e],r=l[e];r=(0,h.Ku)(r);let n=a.gc(t);if(r instanceof sq)u.push(t);else{let e=sG(r,n);null!=e&&(u.push(t),c.set(t,e))}}return new sO(c,new eI(u),a.fieldTransforms)}function sj(e,t,r,n=!1){return sG(r,e.Dc(n?4:3,t))}function sG(e,t){if(sQ(e=(0,h.Ku)(e)))return sW("Unsupported field value:",t,e),sK(e,t);if(e instanceof sD)return function(e,t){if(!sF(t.Ec))throw t.wc(`${e._methodName}
7() can only be used with update() and set()`);if(!t.path)throw t.wc(`${e._methodName}() is not currently supported inside arrays`);let r=e._toFieldTransform(t);r&&t.fieldTransforms.push(r)}(e,t),null;if(void 0===e&&t.ignoreUndefinedProperties)return null;if(t.path&&t.fieldMask.push(t.path),e instanceof Array){if(t.settings.mc&&4!==t.Ec)throw t.wc("Nested arrays are not supported");let r=[],n=0;for(let i of e){let e=sG(i,t.yc(n));null==e&&(e={nullValue:"NULL_VALUE"}),r.push(e),n++}return{arrayValue:{values:r}}}return function(e,t){var r,n,i;if(null===(e=(0,h.Ku)(e)))return{nullValue:"NULL_VALUE"};if("number"==typeof e)return r=t.serializer,"number"==typeof(i=n=e)&&Number.isInteger(i)&&!em(i)&&i<=Number.MAX_SAFE_INTEGER&&i>=Number.MIN_SAFE_INTEGER?tK(n):tG(r,n);if("boolean"==typeof e)return{booleanValue:e};if("string"==typeof e)return{stringValue:e};if(e instanceof Date){let r=ei.fromDate(e);return{timestampValue:rO(t.serializer,r)}}if(e instanceof ei){let r=new ei(e.seconds,1e3*Math.floor(e.nanoseconds/1e3));return{timestampValue:rO(t.serializer,r)}}if(e instanceof sk)return{geoPointValue:{latitude:e.latitude,longitude:e.longitude}};if(e instanceof sC)return{bytesValue:rF(t.serializer,e._byteString)};if(e instanceof sf){let r=t.databaseId,n=e.firestore._databaseId;if(!n.isEqual(r))throw t.wc(`Document reference is for database ${n.projectId}/${n.database} but should be for database ${r.projectId}/${r.database}`);return{referenceValue:rM(e.firestore._databaseId||t.databaseId,e._key.path)}}if(e instanceof sx)return{mapValue:{fields:{[eq]:{stringValue:ez},[ej]:{arrayValue:{values:e.toArray().map(e=>{if("number"!=typeof e)throw t.wc("VectorValues must only contain numeric values.");return tG(t.serializer,e)})}}}}};throw t.wc(`Unsupported field value: ${ee(e)}`)}(e,t)}function sK(e,t){let r={};return ey(e)?t.path&&t.path.length>0&&t.fieldMask.push(t.path):ep(e,(e,n)=>{let i=sG(n,t.Vc(e));null!=i&&(r[e]=i)}),{mapValue:{fields:r}}}function sQ(e){return!("object"!=typeof e||null===e||e instanceof Array||e instanceof Date||e instanceof ei||e instanceof sk||e instanceof sC||e instanceof sf||e instanceof sD||e instanceof sx)}function sW(e,t,r){if(!sQ(r)||!Z(r)){let n=ee(r);throw"an object"===n?t.wc(e+" a custom object"):t.wc(e+" "+n)}}function sH(e,t,r){if((t=(0,h.Ku)(t))instanceof sA)return t._internalPath;if("string"==typeof t)return sJ(e,t);throw sX("Field path arguments must be of type string or ",e,!1,void 0,r)}let sY=RegExp("[~\\*/\\[\\]]");function sJ(e,t,r){if(t.search(sY)>=0)throw sX(`Invalid field path (${t}). Paths must not contain '~', '*', '/', '[', or ']'`,e,!1,void 0,r);try{return new sA(...t.split("."))._internalPath}catch(n){throw sX(`Invalid field path (${t}). Paths must not be empty, begin with '.', end with '.', or contain '..'`,e,!1,void 0,r)}}function sX(e,t,r,n,i){let s=n&&!n.isEmpty(),a=void 0!==i,o=`Function ${t}() called with invalid data`;r&&(o+=" (via `toFirestore()`)"),o+=". ";let l="";return(s||a)&&(l+=" (found",s&&(l+=` in field ${n}`),a&&(l+=` in document ${i}`),l+=")"),new N(A.INVALID_ARGUMENT,o+e+l)}function sZ(e,t){return e.some(e=>e.isEqual(t))}class s0{constructor(e,t,r,n,i){this._firestore=e,this._userDataWriter=t,this._key=r,this._document=n,this._converter=i}get id(){return this._key.path.lastSegment()}get ref(){return new sf(this._firestore,this._converter,this._key)}exists(){return null!==this._document}data(){if(this._document){if(this._converter){let e=new s1(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(s2("DocumentSnapshot.get",e));if(null!==t)return this._userDataWriter.convertValue(t)}}}class s1 extends s0{data(){return super.data()}}function s2(e,t){return"string"==typeof t?sJ(e,t):t instanceof sA?t._internalPath:t._delegate._internalPath}function s3(e){if("L"===e.limitType&&0===e.explicitOrderBy.length)throw new N(A.UNIMPLEMENTED,"limitToLast() queries require specifying at least one orderBy() clause")}class s4{}class s6 extends s4{}function s5(e,t,...r){let n=[];for(let i of(t instanceof s4&&n.push(t),function(e){let t=e.filter(e=>e instanceof s7).length,r=e.filter(e=>e instanceof s8).length;if(t>1||t>0&&r>0)throw new N(A.INVALID_ARGUMENT,"InvalidQuery. When using composite filters, you cannot use more than one filter at the top level. Consider nesting the multiple filters within an `and(...)` statement. For example: change `query(query, where(...), or(...))` to `query(query, and(where(...), or(...)))`.")}(n=n.concat(r)),n))e=i._apply(e);return e}class s8 extends s6{constructor(e,t,r){super(),this._field=e,this._op=t,this._value=r,this.type="where"}static _create(e,t,r){return new s8(e,t,r)}_apply(e){let t=this._parse(e);return al(e._query,t),new sd(e.firestore,e.converter,tN(e._query,t))}_parse(e){let t=sP(e.firestore);return function(e,t,r,n,i,s,a){let o;
7if(i.isKeyField()){if("array-contains"===s||"array-contains-any"===s)throw new N(A.INVALID_ARGUMENT,`Invalid Query. You can't perform '${s}' queries on documentId().`);if("in"===s||"not-in"===s){ao(a,s);let t=[];for(let r of a)t.push(aa(n,e,r));o={arrayValue:{values:t}}}else o=aa(n,e,a)}else"in"!==s&&"not-in"!==s&&"array-contains-any"!==s||ao(a,s),o=sj(r,t,a,"in"===s||"not-in"===s);return ti.create(i,s,o)}(e._query,"where",t,e.firestore._databaseId,this._field,this._op,this._value)}}function s9(e,t,r){let n=s2("where",e);return s8._create(n,t,r)}class s7 extends s4{constructor(e,t){super(),this.type=e,this._queryConstraints=t}static _create(e,t){return new s7(e,t)}_parse(e){let t=this._queryConstraints.map(t=>t._parse(e)).filter(e=>e.getFilters().length>0);return 1===t.length?t[0]:ts.create(t,this._getOperator())}_apply(e){let t=this._parse(e);return 0===t.getFilters().length?e:(function(e,t){let r=e;for(let e of t.getFlattenedFilters())al(r,e),r=tN(r,e)}(e._query,t),new sd(e.firestore,e.converter,tN(e._query,t)))}_getQueryConstraints(){return this._queryConstraints}_getOperator(){return"and"===this.type?"and":"or"}}class ae extends s6{constructor(e,t){super(),this._field=e,this._direction=t,this.type="orderBy"}static _create(e,t){return new ae(e,t)}_apply(e){let t=function(e,t,r){if(null!==e.startAt)throw new N(A.INVALID_ARGUMENT,"Invalid query. You must not call startAt() or startAfter() before calling orderBy().");if(null!==e.endAt)throw new N(A.INVALID_ARGUMENT,"Invalid query. You must not call endAt() or endBefore() before calling orderBy().");return new tr(t,r)}(e._query,this._field,this._direction);return new sd(e.firestore,e.converter,function(e,t){let r=e.explicitOrderBy.concat([t]);return new tE(e.path,e.collectionGroup,r,e.filters.slice(),e.limit,e.limitType,e.startAt,e.endAt)}(e._query,t))}}function at(e,t="asc"){let r=s2("orderBy",e);return ae._create(r,t)}class ar extends s6{constructor(e,t,r){super(),this.type=e,this._limit=t,this._limitType=r}static _create(e,t,r){return new ar(e,t,r)}_apply(e){return new sd(e.firestore,e.converter,tD(e._query,this._limit,this._limitType))}}function an(e){return function(e,t){if(t<=0)throw new N(A.INVALID_ARGUMENT,`Function ${e}() requires a positive number, but it was: ${t}.`)}("limit",e),ar._create("limit",e,"F")}class ai extends s6{constructor(e,t,r){super(),this.type=e,this._docOrFields=t,this._inclusive=r}static _create(e,t,r){return new ai(e,t,r)}_apply(e){var t;let r=function(e,t,r,n){if(r[0]=(0,h.Ku)(r[0]),r[0]instanceof s0)return function(e,t,r,n,i){if(!n)throw new N(A.NOT_FOUND,`Can't use a DocumentSnapshot that doesn't exist for ${r}().`);let s=[];for(let r of tb(e))if(r.field.isKeyField())s.push(eX(t,n.key));else{let e=n.data.field(r.field);if(eO(e))throw new N(A.INVALID_ARGUMENT,'Invalid query. You are trying to start or end a query using a document for which the field "'+r.field+'" is an uncommitted server timestamp. (Since the value of this field is unknown, you cannot start/end a query with it.)');if(null===e){let e=r.field.canonicalString();throw new N(A.INVALID_ARGUMENT,`Invalid query. You are trying to start or end a query using a document for which the field '${e}' (used as the orderBy) does not exist.`)}s.push(e)}return new e7(s,i)}(e._query,e.firestore._databaseId,t,r[0]._document,n);{let i=sP(e.firestore);return function(e,t,r,n,i,s){let a=e.explicitOrderBy;if(i.length>a.length)throw new N(A.INVALID_ARGUMENT,`Too many arguments provided to ${n}(). The number of arguments must be less than or equal to the number of orderBy() clauses`);let o=[];for(let s=0;s<i.length;s++){let l=i[s];if(a[s].field.isKeyField()){if("string"!=typeof l)throw new N(A.INVALID_ARGUMENT,`Invalid query. Expected a string for document ID in ${n}(), but got a ${typeof l}`);if(!tS(e)&&-1!==l.indexOf("/"))throw new N(A.INVALID_ARGUMENT,`Invalid query. When querying a collection and ordering by documentId(), the value passed to ${n}() must be a plain document ID, but '${l}' contains a slash.`);let r=e.path.child(K.fromString(l));if(!H.isDocumentKey(r))throw new N(A.INVALID_ARGUMENT,`Invalid query. When querying a collection group and ordering by documentId(), the value passed to ${n}() must result in a valid document path, but '${r}
7' is not because it contains an odd number of segments.`);let i=new H(r);o.push(eX(t,i))}else{let e=sj(r,n,l);o.push(e)}}return new e7(o,s)}(e._query,e.firestore._databaseId,i,t,r,n)}}(e,this.type,this._docOrFields,this._inclusive);return new sd(e.firestore,e.converter,(t=e._query,new tE(t.path,t.collectionGroup,t.explicitOrderBy.slice(),t.filters.slice(),t.limit,t.limitType,r,t.endAt)))}}function as(...e){return ai._create("startAfter",e,!1)}function aa(e,t,r){if("string"==typeof(r=(0,h.Ku)(r))){if(""===r)throw new N(A.INVALID_ARGUMENT,"Invalid query. When querying with documentId(), you must provide a valid document ID, but it was an empty string.");if(!tS(t)&&-1!==r.indexOf("/"))throw new N(A.INVALID_ARGUMENT,`Invalid query. When querying a collection by documentId(), you must provide a plain document ID, but '${r}' contains a '/' character.`);let n=t.path.child(K.fromString(r));if(!H.isDocumentKey(n))throw new N(A.INVALID_ARGUMENT,`Invalid query. When querying a collection group by documentId(), the value provided must result in a valid document path, but '${n}' is not because it has an odd number of segments (${n.length}).`);return eX(e,new H(n))}if(r instanceof sf)return eX(e,r._key);throw new N(A.INVALID_ARGUMENT,`Invalid query. When querying with documentId(), you must provide a valid string or a DocumentReference, but it was: ${ee(r)}.`)}function ao(e,t){if(!Array.isArray(e)||0===e.length)throw new N(A.INVALID_ARGUMENT,`Invalid Query. A non-empty array is required for '${t.toString()}' filters.`)}function al(e,t){let r=function(e,t){for(let r of e)for(let e of r.getFlattenedFilters())if(t.indexOf(e.op)>=0)return e.op;return null}(e.filters,function(e){switch(e){case"!=":return["!=","not-in"];case"array-contains-any":case"in":return["not-in"];case"not-in":return["array-contains-any","in","not-in","!="];default:return[]}}(t.op));if(null!==r)throw r===t.op?new N(A.INVALID_ARGUMENT,`Invalid query. You cannot use more than one '${t.op.toString()}' filter.`):new N(A.INVALID_ARGUMENT,`Invalid query. You cannot use '${t.op.toString()}' filters with '${r.toString()}' filters.`)}class au{convertValue(e,t="none"){switch(eG(e)){case 0:return null;case 1:return e.booleanValue;case 2:return eN(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(eD(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 11:return this.convertObject(e.mapValue,t);case 10:return this.convertVectorValue(e.mapValue);default:throw S(62114,{value:e})}}convertObject(e,t){return this.convertObjectMap(e.fields,t)}convertObjectMap(e,t="none"){let r={};return ep(e,(e,n)=>{r[e]=this.convertValue(n,t)}),r}convertVectorValue(e){var t,r,n;return new sx(null==(n=null==(r=null==(t=e.fields)?void 0:t[ej].arrayValue)?void 0:r.values)?void 0:n.map(e=>eN(e.doubleValue)))}convertGeoPoint(e){return new sk(eN(e.latitude),eN(e.longitude))}convertArray(e,t){return(e.values||[]).map(e=>this.convertValue(e,t))}convertServerTimestamp(e,t){switch(t){case"previous":let r=eF(e);return null==r?null:this.convertValue(r,t);case"estimate":return this.convertTimestamp(eL(e));default:return null}}convertTimestamp(e){let t=eA(e);return new ei(t.seconds,t.nanos)}convertDocumentKey(e,t){let r=K.fromString(e);C(rY(r),9688,{name:e});let n=new eU(r.get(1),r.get(3)),i=new H(r.popFirst(5));return n.isEqual(t)||E(`Document ${i} contains a document reference within a different database (${n.projectId}/${n.database}) which is not supported. It will be treated as a reference in the current database (${t.projectId}/${t.database}) instead.`),i}}function ah(e,t,r){return e?r&&(r.merge||r.mergeFields)?e.toFirestore(t,r):e.toFirestore(t):t}class ac extends au{constructor(e){super(),this.firestore=e}convertBytes(e){return new sC(e)}convertReference(e){let t=this.convertDocumentKey(e,this.firestore._databaseId);return new sf(this.firestore,null,t)}}class ad{constructor(e,t){this.hasPendingWrites=e,this.fromCache=t}isEqual(e){return this.hasPendingWrites===e.hasPendingWrites&&this.fromCache===e.fromCache}}class af extends s0{constructor(e,t,r,n,i,s){super(e,t,r,n,s),this._firestore=e,this._firestoreImpl=e,this.metadata=i}exists(){return super.exists()}data(e={}){if(this._document){if(this._converter){let t=new am(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 r=this._document.data.field(s2("DocumentSnapshot.get",e));if(null!==r)return this._userDataWriter.convertValue(r,t.serverTimestamps)}}toJSON(){if(this.metadata.hasPendingWrites)throw new N(A.FAILED_PRECONDITION,"DocumentSnapshot.toJSON() attempted to serialize a document with pending writes. Await waitForPendingWrites() before invoking toJSON().");let e=this._document,t={};return t.type=af._jsonSchemaVersion,t.bundle="",t.bundleSource="DocumentSnapshot",t.bundleName=this._key.toString(),e&&e.isValidDocument()&&e.isFoundDocument()&&
7(this._userDataWriter.convertObjectMap(e.data.value.mapValue.fields,"previous"),this._firestore,this.ref.path,t.bundle="NOT SUPPORTED"),t}}af._jsonSchemaVersion="firestore/documentSnapshot/1.0",af._jsonSchema={type:er("string",af._jsonSchemaVersion),bundleSource:er("string","DocumentSnapshot"),bundleName:er("string"),bundle:er("string")};class am extends af{data(e={}){return super.data(e)}}class ag{constructor(e,t,r,n){this._firestore=e,this._userDataWriter=t,this._snapshot=n,this.metadata=new ad(n.hasPendingWrites,n.fromCache),this.query=r}get docs(){let e=[];return this.forEach(t=>e.push(t)),e}get size(){return this._snapshot.docs.size}get empty(){return 0===this.size}forEach(e,t){this._snapshot.docs.forEach(r=>{e.call(t,new am(this._firestore,this._userDataWriter,r.key,r,new ad(this._snapshot.mutatedKeys.has(r.key),this._snapshot.fromCache),this.query.converter))})}docChanges(e={}){let t=!!e.includeMetadataChanges;if(t&&this._snapshot.excludesMetadataChanges)throw new N(A.INVALID_ARGUMENT,"To include metadata changes with your document changes, you must also pass { includeMetadataChanges:true } to onSnapshot().");return this._cachedChanges&&this._cachedChangesIncludeMetadataChanges===t||(this._cachedChanges=function(e,t){if(e._snapshot.oldDocs.isEmpty()){let t=0;return e._snapshot.docChanges.map(r=>{let n=new am(e._firestore,e._userDataWriter,r.doc.key,r.doc,new ad(e._snapshot.mutatedKeys.has(r.doc.key),e._snapshot.fromCache),e.query.converter);return r.doc,{type:"added",doc:n,oldIndex:-1,newIndex:t++}})}{let r=e._snapshot.oldDocs;return e._snapshot.docChanges.filter(e=>t||3!==e.type).map(t=>{let n=new am(e._firestore,e._userDataWriter,t.doc.key,t.doc,new ad(e._snapshot.mutatedKeys.has(t.doc.key),e._snapshot.fromCache),e.query.converter),i=-1,s=-1;return 0!==t.type&&(i=r.indexOf(t.doc.key),r=r.delete(t.doc.key)),1!==t.type&&(s=(r=r.add(t.doc)).indexOf(t.doc.key)),{type:function(e){switch(e){case 0:return"added";case 2:case 3:return"modified";case 1:return"removed";default:return S(61501,{type:e})}}(t.type),doc:n,oldIndex:i,newIndex:s}})}}(this,t),this._cachedChangesIncludeMetadataChanges=t),this._cachedChanges}toJSON(){if(this.metadata.hasPendingWrites)throw new N(A.FAILED_PRECONDITION,"QuerySnapshot.toJSON() attempted to serialize a document with pending writes. Await waitForPendingWrites() before invoking toJSON().");let e={};e.type=ag._jsonSchemaVersion,e.bundleSource="QuerySnapshot",e.bundleName=U.newId(),this._firestore._databaseId.database,this._firestore._databaseId.projectId;let t=[],r=[],n=[];return this.docs.forEach(e=>{null!==e._document&&(t.push(e._document),r.push(this._userDataWriter.convertObjectMap(e._document.data.value.mapValue.fields,"previous")),n.push(e.ref.path))}),this._firestore,this.query._query,e.bundleName,e.bundle="NOT SUPPORTED",e}}function ap(e){e=et(e,sf);let t=et(e.firestore,sE);return(function(e,t,r={}){let n=new D;return e.asyncQueue.enqueueAndForget(async()=>(function(e,t,r,n,i){let s=new i5({next:o=>{s.Ou(),t.enqueueAndForget(()=>iI(e,a));let l=o.docs.has(r);!l&&o.fromCache?i.reject(new N(A.UNAVAILABLE,"Failed to get document because the client is offline.")):l&&o.fromCache&&n&&"server"===n.source?i.reject(new N(A.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.)')):i.resolve(o)},error:e=>i.reject(e)}),a=new iA(tT(r.path),s,{includeMetadataChanges:!0,ka:!0});return iT(e,a)})(await sa(e),e.asyncQueue,t,r,n)),n.promise})(sI(t),e._key).then(r=>ab(t,e,r))}ag._jsonSchemaVersion="firestore/querySnapshot/1.0",ag._jsonSchema={type:er("string",ag._jsonSchemaVersion),bundleSource:er("string","QuerySnapshot"),bundleName:er("string"),bundle:er("string")};class ay extends au{constructor(e){super(),this.firestore=e}convertBytes(e){return new sC(e)}convertReference(e){let t=this.convertDocumentKey(e,this.firestore._databaseId);return new sf(this.firestore,null,t)}}function aw(e){e=et(e,sd);let t=et(e.firestore,sE),r=sI(t),n=new ay(t);return s3(e._query),(function(e,t,r={}){let n=new D;return e.asyncQueue.enqueueAndForget(async()=>(function(e,t,r,n,i){let s=new i5({next:r=>{s.Ou(),t.enqueueAndForget(()=>iI(e,a)),r.fromCache&&"server"===n.source?i.reject(new N(A.UNAVAILABLE,'Failed to get documents from server. (However, these documents may exist in the local cache. Run again without setting source to "server" to retrieve the cached documents.)')):i.resolve(r)},error:e=>i.reject(e)}),a=new iA(r,s,{includeMetadataChanges:!0,ka:!0});return iT(e,a)})(await sa(e),e.asyncQueue,t,r,n)),n.promise})(r,e._query).then(r=>new ag(t,n,e,r))}function av(e,t,r){e=et(e,sf);let n=et(e.firestore,sE),i=ah(e.converter,t,r);return aS(n,[sU(sP(n),"setDoc",e._key,i,null!==e.converter,r).toMutation(e._key,t6.none())])}function a_(e,t,r,...n){e=et(e,sf);let i=et(e.firestore,sE),s=sP(i);return aS(i,[("string"==typeof(t=(0,h.Ku)(t))||t instanceof sA?sz(s,"updateDoc",e._key,t,r,n):sB(s,"updateDoc",e._key,t)).toMutation(e._key,t6.exists(!0))])}function aE(e){return aS(et(e.firestore,sE),[new ra(e._key,t6.none())])}function aT(e,t){let r=et(e.firestore,sE),n=sp(e),i=ah(e.converter,t);return aS(r,[sU(sP(e.firestore),"addDoc",n._key,i,null!==e.converter,{}).toMutation(n._key,t6.exists(!1))]).then(()=>n)}function aI(e,...t){let r,n,i;e=(0,h.Ku)(e);let s={includeMetadataChanges:!1,source:"default"},a=0;
7"object"!=typeof t[0]||s_(t[a])||(s=t[a++]);let o={includeMetadataChanges:s.includeMetadataChanges,source:s.source};if(s_(t[a])){let e=t[a];t[a]=null==(l=e.next)?void 0:l.bind(e),t[a+1]=null==(u=e.error)?void 0:u.bind(e),t[a+2]=null==(c=e.complete)?void 0:c.bind(e)}if(e instanceof sf)n=et(e.firestore,sE),i=tT(e._key.path),r={next:r=>{t[a]&&t[a](ab(n,e,r))},error:t[a+1],complete:t[a+2]};else{let s=et(e,sd);n=et(s.firestore,sE),i=s._query;let o=new ay(n);r={next:e=>{t[a]&&t[a](new ag(n,o,s,e))},error:t[a+1],complete:t[a+2]},s3(e._query)}var l,u,c,d=sI(n),f=i;let m=new i5(r),g=new iA(f,m,o);return d.asyncQueue.enqueueAndForget(async()=>iT(await sa(d),g)),()=>{m.Ou(),d.asyncQueue.enqueueAndForget(async()=>iI(await sa(d),g))}}function aS(e,t){var r=sI(e);let n=new D;return r.asyncQueue.enqueueAndForget(async()=>i$(await si(r).then(e=>e.syncEngine),t,n)),n.promise}function ab(e,t,r){let n=r.docs.get(t._key),i=new ay(e);return new af(e,i,t._key,n,new ad(r.hasPendingWrites,r.fromCache),t.converter)}function aC(e){return function(e,t){let r=et(e.firestore,sE),n=sI(r),i=function(e,t){let r=[];for(let n in e)Object.prototype.hasOwnProperty.call(e,n)&&r.push(t(e[n],n,e));return r}(t,(e,t)=>new rc(t,e.aggregateType,e._internalFieldPath));return(function(e,t,r){let n=new D;return e.asyncQueue.enqueueAndForget(async()=>{try{let i=await ss(e);n.resolve(async function(e,t,r){var n;let{request:i,ft:s,parent:a}=function(e,t,r,n){let{Vt:i,parent:s}=rQ(e,t),a={},o=[],l=0;return r.forEach(e=>{let t="aggregate_"+l++;a[t]=e.alias,"count"===e.aggregateType?o.push({alias:t,count:{}}):"avg"===e.aggregateType?o.push({alias:t,avg:{field:rW(e.fieldPath)}}):"sum"===e.aggregateType&&o.push({alias:t,sum:{field:rW(e.fieldPath)}})}),{request:{structuredAggregationQuery:{aggregations:o,structuredQuery:i.structuredQuery},parent:i.parent},ft:a,parent:s}}(e.serializer,(t.de||(t.de=tA(t,t.explicitOrderBy)),t.de),r);e.connection.Qo||delete i.parent;let o=(await e.Jo("RunAggregationQuery",e.serializer.databaseId,a,i,1)).filter(e=>!!e.result);C(1===o.length,64727);let l=null==(n=o[0].result)?void 0:n.aggregateFields;return Object.keys(l).reduce((e,t)=>(e[s[t]]=l[t],e),{})}(i,t,r))}catch(e){n.reject(e)}}),n.promise})(n,e._query,i).then(t=>new sb(e,new ay(r),t))}(e,{count:new sS("count")})}let aA={maxAttempts:5};class aN{constructor(e,t){this._firestore=e,this._commitHandler=t,this._mutations=[],this._committed=!1,this._dataReader=sP(e)}set(e,t,r){this._verifyNotCommitted();let n=aD(e,this._firestore),i=ah(n.converter,t,r),s=sU(this._dataReader,"WriteBatch.set",n._key,i,null!==n.converter,r);return this._mutations.push(s.toMutation(n._key,t6.none())),this}update(e,t,r,...n){let i;this._verifyNotCommitted();let s=aD(e,this._firestore);return i="string"==typeof(t=(0,h.Ku)(t))||t instanceof sA?sz(this._dataReader,"WriteBatch.update",s._key,t,r,n):sB(this._dataReader,"WriteBatch.update",s._key,t),this._mutations.push(i.toMutation(s._key,t6.exists(!0))),this}delete(e){this._verifyNotCommitted();let t=aD(e,this._firestore);return this._mutations=this._mutations.concat(new ra(t._key,t6.none())),this}commit(){return this._verifyNotCommitted(),this._committed=!0,this._mutations.length>0?this._commitHandler(this._mutations):Promise.resolve()}_verifyNotCommitted(){if(this._committed)throw new N(A.FAILED_PRECONDITION,"A write batch can no longer be used after commit() has been called.")}}function aD(e,t){if((e=(0,h.Ku)(e)).firestore!==t)throw new N(A.INVALID_ARGUMENT,"Provided document reference is from a different Firestore instance.");return e}class ak{constructor(e,t){this._firestore=e,this._transaction=t,this._dataReader=sP(e)}get(e){let t=aD(e,this._firestore),r=new ac(this._firestore);return this._transaction.lookup([t._key]).then(e=>{if(!e||1!==e.length)return S(24041);let n=e[0];if(n.isFoundDocument())return new s0(this._firestore,r,n.key,n,t.converter);if(n.isNoDocument())return new s0(this._firestore,r,t._key,null,t.converter);throw S(18433,{doc:n})})}set(e,t,r){let n=aD(e,this._firestore),i=ah(n.converter,t,r),s=sU(this._dataReader,"Transaction.set",n._key,i,null!==n.converter,r);return this._transaction.set(n._key,s),this}update(e,t,r,...n){let i,s=aD(e,this._firestore);return i="string"==typeof(t=(0,h.Ku)(t))||t instanceof sA?sz(this._dataReader,"Transaction.update",s._key,t,r,n):sB(this._dataReader,"Transaction.update",s._key,t),this._transaction.update(s._key,i),this}delete(e){let t=aD(e,this._firestore);return this._transaction.delete(t._key),this}}class ax extends ak{constructor(e,t){super(e,t),this._firestore=e}get(e){let t=aD(e,this._firestore),r=new ay(this._firestore);return super.get(e).then(e=>new af(this._firestore,r,t._key,e._document,new ad(!1,!1),t.converter))}}function aR(e,t,r){e=et(e,sE);let n=Object.assign(Object.assign({},aA),r);if(n.maxAttempts<1)throw new N(A.INVALID_ARGUMENT,"Max attempts must be at least 1");return function(e,t,r){let n=new D;return e.asyncQueue.enqueueAndForget(async()=>{let i=await ss(e);new i9(e.asyncQueue,i,r,t,n).zu()}),n.promise}(sI(e),r=>t(new ax(e,r)),n)}function aV(){return new sq("deleteField")}function aO(){return new s$("serverTimestamp")}function aF(e){return sI(e=et(e,sE)),new aN(e,t=>aS(e,t))}new WeakMap,function(e=!0){y=o.MF,(0,o.om)(new l.uA("firestore",(t,{instanceIdentifier:r,options:n})=>{let i=t.getProvider("app").getImmediate(),s=new sE(new V(t.getProvider("auth-internal")),new M(i,t.getProvider("app-check-internal")),function(e,t){if(!Object.prototype.hasOwnProperty.apply(e.options,["projectId"]))throw new N(A.INVALID_ARGUMENT,'"projectId" not provided in firebase.initializeApp.');return new eU(e.options.projectId,t)}(i,r),i);return n=Object.assign({useFetchStreams:e},n),s._setSettings(n),s},"PUBLIC").setMultipleInstances(!0)),(0,o.KO)(m,g,void 0),(0,o.KO)(m,g,"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.