1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[2992],{6596:(e,t,r)=>{r.d(t,{$1:()=>sJ,AB:()=>sX,BN:()=>aa,FD:()=>s2,GG:()=>as,H9:()=>sn,HM:()=>s0,My:()=>sW,P:()=>sB,Uo:()=>sj,_M:()=>sz,aQ:()=>au,aU:()=>sl,d_:()=>ad,hq:()=>af,kd:()=>al,mZ:()=>ao,or:()=>sQ,rJ:()=>sr,x7:()=>an});var n,i,s,a,o=r(91398),l=r(22396),u=r(5969),h=r(57176),c=r(90916),d=r(24052);r(95704);var f=r(15376).Buffer;let m="@firebase/firestore",g="4.7.9";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.4.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 T(e,...t){if(w.logLevel<=u.$b.ERROR){let r=t.map(I);w.error(`Firestore (${y}): ${e}`,...r)}}function E(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 C(e="Unexpected state"){let t=`FIRESTORE (${y}) INTERNAL ASSERTION FAILED: `+e;throw T(t),Error(t)}let b={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 S 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 A{constructor(){this.promise=new Promise((e,t)=>{this.resolve=e,this.reject=t})}}class N{constructor(e,t){this.user=t,this.type="OAuth",this.headers=new Map,this.headers.set("Authorization",`Bearer ${e}`)}}class D{getToken(){return Promise.resolve(null)}invalidateToken(){}start(e,t){e.enqueueRetryable(()=>t(p.UNAUTHENTICATED))}shutdown(){}}class k{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 x{constructor(e){this.t=e,this.currentUser=p.UNAUTHENTICATED,this.i=0,this.forceRefresh=!1,this.auth=null}start(e,t){void 0===this.o||C();let r=this.i,n=e=>this.i!==r?(r=this.i,t(e)):Promise.resolve(),i=new A;this.o=()=>{this.i++,this.currentUser=this.u(),i.resolve(),i=new A,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 A)}},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?("string"==typeof t.accessToken||C(),new N(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 null===e||"string"==typeof e||C(),new p(e)}}class R{constructor(e,t,r){this.l=e,this.h=t,this.P=r,this.type="FirstParty",this.user=p.FIRST_PARTY,this.T=new Map}I(){return this.P?this.P():null}get headers(){this.T.set("X-Goog-AuthUser",this.l);let e=this.I();return e&&this.T.set("Authorization",e),this.h&&this.T.set("X-Goog-Iam-Authorization-Token",this.h),this.T}}class L{constructor(e,t,r){this.l=e,this.h=t,this.P=r}getToken(){return Promise.resolve(new R(this.l,this.h,this.P))}start(e,t){e.enqueueRetryable(()=>t(p.FIRST_PARTY))}shutdown(){}invalidateToken(){}}class V{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.A=t,this.forceRefresh=!1,this.appCheck=null,this.R=null,this.V=null,(0,o.xZ)(e)&&e.settings.appCheckToken&&(this.V=e.settings.appCheckToken)}start(e,t){void 0===this.o||C();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.R;return this.R=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.A.onInit(e=>n(e)),setTimeout(()=>{if(!this.appCheck){let e=this.A.getImmediate({optional:!0});e?n(e):_("FirebaseAppCheckTokenProvider","AppCheck not yet detected")}},0)}getToken(){if(this.V)return Promise.resolve(new V(this.V));let e=this.forceRefresh;return this.forceRefresh=!1,this.appCheck?this.appCheck.getToken(e).then(e=>e?("string"==typeof e.token||C(),this.R=e.token,new V(e.token)):null):Promise.resolve(null)}invalidateToken(){this.forceRefresh=!0}shutdown(){this.appCheck&&this.o&&this.appCheck.removeTokenListener(this.o),this.o=void 0}}class O{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 F(e,t){return e<t?-1:+(e>t)}function P(e,t,r){return e.length===t.length&&e.every((e,n)=>r(e,t[n]))}class U{static now(){return U.fromMillis(Date.now())}static fromDate(e){return U.fromMillis(e.getTime())}static fromMillis(e){let t=Math.floor(e/1e3),r=Math.floor((e-1e3*t)*1e6);return new U(t,r)}constructor(e,t){if(this.seconds=e,this.nanoseconds=t,t<0||t>=1e9)throw new S(b.INVALID_ARGUMENT,"Timestamp nanoseconds out of range: "+t);if(e<-0xe7791f700||e>=0x3afff44180)throw new S(b.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?F(this.nanoseconds,e.nanoseconds):F(this.seconds,e.seconds)}isEqual(e){return e.seconds===this.seconds&&e.nanoseconds===this.nanoseconds}toString(){return"Timestamp(seconds="+this.seconds+", nanoseconds="+this.nanoseconds+")"}toJSON(){return{seconds:this.seconds,nanoseconds:this.nanoseconds}}valueOf(){return String(this.seconds- -0xe7791f700).padStart(12,"0")+"."+String(this.nanoseconds).padStart(9,"0")}}class q{static fromTimestamp(e){return new q(e)}static min(){return new q(new U(0,0))}static max(){return new q(new U(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}}let $="__name__";class B{constructor(e,t,r){void 0===t?t=0:t>e.length&&C(),void 0===r?r=e.length-t:r>e.length-t&&C(),this.segments=e,this.offset=t,this.len=r}get length(){return this.len}isEqual(e){return 0===B.comparator(this,e)}child(e){let t=this.segments.slice(this.offset,this.limit());return e instanceof B?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=B.compareSegments(e.get(n),t.get(n));if(0!==r)return r}return Math.sign(e.length-t.length)}static compareSegments(e,t){let r=B.isNumericId(e),n=B.isNumericId(t);return r&&!n?-1:!r&&n?1:r&&n?B.extractNumericId(e).compare(B.extractNumericId(t)):e<t?-1:+(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 B{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 S(b.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 z=/^[_a-zA-Z][_a-zA-Z0-9]*$/;class G extends B{construct(e,t,r){return new G(e,t,r)}static isValidIdentifier(e){return z.test(e)}canonicalString(){return this.toArray().map(e=>(e=e.replace(/\\/g,"\\\\").replace(/`/g,"\\`"),G.isValidIdentifier(e)||(e="`"+e+"`"),e)).join(".")}toString(){return this.canonicalString()}isKeyField(){return 1===this.length&&this.get(0)===$}static keyField(){return new G([$])}static fromServerFormat(e){let t=[],r="",n=0,i=()=>
1{if(0===r.length)throw new S(b.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 S(b.INVALID_ARGUMENT,"Path has trailing escape character: "+e);let t=e[n+1];if("\\"!==t&&"."!==t&&"`"!==t)throw new S(b.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 S(b.INVALID_ARGUMENT,"Unterminated ` in path: "+e);return new G(t)}static emptyPath(){return new G([])}}class Q{constructor(e){this.path=e}static fromPath(e){return new Q(K.fromString(e))}static fromName(e){return new Q(K.fromString(e).popFirst(5))}static empty(){return new Q(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 Q(new K(e.slice()))}}class j{constructor(e,t,r,n){this.indexId=e,this.collectionGroup=t,this.fields=r,this.indexState=n}}j.UNKNOWN_ID=-1;class H{constructor(e,t,r){this.readTime=e,this.documentKey=t,this.largestBatchId=r}static min(){return new H(q.min(),Q.empty(),-1)}static max(){return new H(q.max(),Q.empty(),-1)}}class W{constructor(){this.onCommittedListeners=[]}addOnCommittedListener(e){this.onCommittedListeners.push(e)}raiseOnCommittedEvent(){this.onCommittedListeners.forEach(e=>e())}}async function Y(e){if(e.code!==b.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 X{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&&C(),this.callbackAttached=!0,this.isDone?this.error?this.wrapFailure(t,this.error):this.wrapSuccess(e,this.result):new X((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 X?t:X.resolve(t)}catch(e){return X.reject(e)}}wrapSuccess(e,t){return e?this.wrapUserFunction(()=>e(t)):X.resolve(t)}wrapFailure(e,t){return e?this.wrapUserFunction(()=>e(t)):X.reject(t)}static resolve(e){return new X((t,r)=>{t(e)})}static reject(e){return new X((t,r)=>{r(e)})}static waitFor(e){return new X((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=X.resolve(!1);for(let r of e)t=t.next(e=>e?X.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 X((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 X((r,n)=>{let i=()=>{!0===e()?t().next(()=>{i()},n):r()};i()})}}function J(e){return"IndexedDbTransactionError"===e.name}class Z{constructor(e,t){this.previousValue=e,t&&(t.sequenceNumberHandler=e=>this.oe(e),this._e=e=>t.writeSequenceNumber(e))}oe(e){return this.previousValue=Math.max(e,this.previousValue),this.previousValue}next(){let e=++this.previousValue;return this._e&&this._e(e),e}}Z.ae=-1;function ee(e){return 0===e&&1/e==-1/0}function et(e){let t=0;for(let r in e)Object.prototype.hasOwnProperty.call(e,r)&&t++;return t}function er(e,t){for(let r in e)Object.prototype.hasOwnProperty.call(e,r)&&t(r,e[r])}function en(e){for(let t in e)if(Object.prototype.hasOwnProperty.call(e,t))return!1;return!0}class ei{constructor(e,t){this.comparator=e,this.root=t||ea.EMPTY}insert(e,t){return new ei(this.comparator,this.root.insert(e,t,this.comparator).copy(null,null,ea.BLACK,null,
1null))}remove(e){return new ei(this.comparator,this.root.remove(e,this.comparator).copy(null,null,ea.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 es(this.root,null,this.comparator,!1)}getIteratorFrom(e){return new es(this.root,e,this.comparator,!1)}getReverseIterator(){return new es(this.root,null,this.comparator,!0)}getReverseIteratorFrom(e){return new es(this.root,e,this.comparator,!0)}}class es{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 ea{constructor(e,t,r,n,i){this.key=e,this.value=t,this.color=null!=r?r:ea.RED,this.left=null!=n?n:ea.EMPTY,this.right=null!=i?i:ea.EMPTY,this.size=this.left.size+1+this.right.size}copy(e,t,r,n,i){return new ea(null!=e?e:this.key,null!=t?t:this.value,null!=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 ea.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 ea.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,ea.RED,null,this.right.left);return this.right.copy(null,null,this.color,e,null)}rotateRight(){let e=this.copy(null,null,ea.RED,this.left.right,null);return this.left.copy(null,null,this.color,null,e)}colorFlip(){let e=this.left.copy(null,null,!this.left.color,null,null),t=this.right.copy(null,null,!this.right.color,null,null);return this.copy(null,null,!this.color,e,t)}checkMaxDepth(){return Math.pow(2,this.check())<=this.size+1}check(){if(this.isRed()&&this.left.isRed()||this.right.isRed())throw C();let e=this.left.check();if(e!==this.right.check())throw C();return e+ +!this.isRed()}}
1ea.EMPTY=null,ea.RED=!0,ea.BLACK=!1,ea.EMPTY=new class{constructor(){this.size=0}get key(){throw C()}get value(){throw C()}get color(){throw C()}get left(){throw C()}get right(){throw C()}copy(e,t,r,n,i){return this}insert(e,t,r){return new ea(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 eo{constructor(e){this.comparator=e,this.data=new ei(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 el(this.data.getIterator())}getIteratorFrom(e){return new el(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 eo)||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 eo(this.comparator);return t.data=e,t}}class el{constructor(e){this.iter=e}getNext(){return this.iter.getNext().key}hasNext(){return this.iter.hasNext()}}class eu{constructor(e){this.fields=e,e.sort(G.comparator)}static empty(){return new eu([])}unionWith(e){let t=new eo(G.comparator);for(let e of this.fields)t=t.add(e);for(let r of e)t=t.add(r);return new eu(t.toArray())}covers(e){for(let t of this.fields)if(t.isPrefixOf(e))return!0;return!1}isEqual(e){return P(this.fields,e.fields,(e,t)=>e.isEqual(t))}}class eh extends Error{constructor(){super(...arguments),this.name="Base64DecodeError"}}class ec{constructor(e){this.binaryString=e}static fromBase64String(e){return new ec(function(e){try{return atob(e)}catch(e){throw"undefined"!=typeof DOMException&&e instanceof DOMException?new eh("Invalid base64 string: "+e):e}}(e))}static fromUint8Array(e){return new ec(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 F(this.binaryString,e.binaryString)}isEqual(e){return this.binaryString===e.binaryString}}ec.EMPTY_BYTE_STRING=new ec("");let ed=new RegExp(/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.(\d+))?Z$/);function ef(e){if(e||C(),"string"==typeof e){let t=0,r=ed.exec(e);if(r||C(),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:em(e.seconds),nanos:em(e.nanos)}}function em(e){return"number"==typeof e?e:"string"==typeof e?Number(e):0}function eg(e){return"string"==typeof e?ec.fromBase64String(e):ec.fromUint8Array(e)}let ep="server_timestamp",ey="__type__",ew="__previous_value__",ev="__local_write_time__";function e_(e){var t,r;return(null==(r=((null==(t=null==e?void 0:e.mapValue)?void 0:t.fields)||{})[ey])?void 0:r.stringValue)===ep}function eT(e){let t=e.mapValue.fields[ew];return e_(t)?eT(t):t}function eE(e){let t=ef(e.mapValue.fields[ev].timestampValue);return new U(t.seconds,t.nanos)}class eI{constructor(e,t,r,n,i,s,a,o,l){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}}let eC="(default)";class eb{constructor(e,t){this.projectId=e,this.database=t||eC}static empty(){return new eb("","")}get isDefaultDatabase(){return this.database===eC}isEqual(e){return e instanceof eb&&e.projectId===this.projectId&&e.database===this.database}}let eS="__type__",eA="__max__",eN={mapValue:{fields:{__type__:{stringValue:eA}}}},eD="__vector__",ek="value";function ex(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?e_(e)?4:eQ(e)?0x1fffffffffffff:ez(e)?10:11:C()}function eR(e,t){if(e===t)return!0;let r=ex(e);if(r!==ex(t))return!1;switch(r){case 0:case 0x1fffffffffffff:return!0;case 1:return e.booleanValue===t.booleanValue;case 4:return eE(e).isEqual(eE(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=ef(e.timestampValue),i=ef(t.timestampValue);return n.seconds===i.seconds&&n.nanos===i.nanos;case 5:return e.stringValue===t.stringValue;case 6:return eg(e.bytesValue).isEqual(eg(t.bytesValue));case 7:return e.referenceValue===t.referenceValue;case 8:return em(e.geoPointValue.latitude)===em(t.geoPointValue.latitude)&&em(e.geoPointValue.longitude)===em(t.geoPointValue.longitude);case 2:if("integerValue"in e&&"integerValue"in t)return em(e.integerValue)===em(t.integerValue);if("doubleValue"in e&&"doubleValue"in t){let r=em(e.doubleValue),n=em(t.doubleValue);return r===n?ee(r)===ee(n):isNaN(r)&&isNaN(n)}return!1;case 9:return P(e.arrayValue.values||[],t.arrayValue.values||[],eR);case 10:case 11:let s=e.mapValue.fields||{},a=t.mapValue.fields||{};if(et(s)!==et(a))return!1;for(let e in s)if(s.hasOwnProperty(e)&&(void 0===a[e]||!eR(s[e],a[e])))return!1;return!0;default:return C()}}function eL(e,t){return void 0!==(e.values||[]).find(e=>eR(e,t))}function eV(e,t){if(e===t)return 0;let r=ex(e),n=ex(t);if(r!==n)return F(r,n);switch(r){case 0:case 0x1fffffffffffff:return 0;case 1:return F(e.booleanValue,t.booleanValue);case 2:let i=em(e.integerValue||e.doubleValue),s=em(t.integerValue||t.doubleValue);return i<s?-1:i>s?1:i===s?0:isNaN(i)?isNaN(s)?0:-1:1;case 3:return eM(e.timestampValue,t.timestampValue);case 4:return eM(eE(e),eE(t));case 5:return F(e.stringValue,t.stringValue);case 6:return function(e,t){let r=eg(e),n=eg(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=F(r[e],n[e]);if(0!==t)return t}return F(r.length,n.length)}(e.referenceValue,t.referenceValue);case 8:return function(e,t){let r=F(em(e.latitude),em(t.latitude));return 0!==r?r:F(em(e.longitude),em(t.longitude))}(e.geoPointValue,t.geoPointValue);case 9:return eO(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[ek])?void 0:r.arrayValue,u=null==(n=o[ek])?void 0:n.arrayValue,h=F((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:eO(l,u)}(e.mapValue,t.mapValue);case 11:return function(e,t){if(e===eN.mapValue&&t===eN.mapValue)return 0;if(e===eN.mapValue)return 1;if(t===eN.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=F(n[e],s[e]);if(0!==t)return t;let a=eV(r[n[e]],i[s[e]]);if(0!==a)return a}return F(n.length,s.length)}(e.mapValue,t.mapValue);default:throw C()}}function eM(e,t){if("string"==typeof e&&"string"==typeof t&&e.length===t.length)return F(e,t);let r=ef(e),n=ef(t),i=F(r.seconds,n.seconds);return 0!==i?i:F(r.nanos,n.nanos)}function eO(e,t){let r=e.values||[],n=t.values||[];for(let e=0;e<r.length&&e<n.length;++e){let t=eV(r[e],n[e]);if(t)return t}return F(r.length,n.length)}function eF(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=ef(e);return`time(${t.seconds},${t.nanos})`}(e.timestampValue):"stringValue"in e?e.stringValue:"bytesValue"in e?eg(e.bytesValue).toBase64():"referenceValue"in e?(t=e.referenceValue,Q.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+=eF(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}:${eF(e.fields[i])}`;return r+"}"}(e.mapValue):C()}function eP(e,t){return{referenceValue:`projects/${e.projectId}/databases/${e.database}/documents/${t.path.canonicalString()}`}}function eU(e){return!!e&&"integerValue"in e}function eq(e){return!!e&&"arrayValue"in e}function e$(e){return!!e&&"nullValue"in e}function eB(e){return!!e&&"doubleValue"in e&&isNaN(Number(e.doubleValue))}function eK(e){return!!e&&"mapValue"in e}function ez(e){var t,r;return(null==(r=((null==(t=null==e?void 0:e.mapValue)?void 0:t.fields)||{})[eS])?void 0:r.stringValue)===eD}function eG(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 er(e.mapValue.fields,(e,r)=>t.mapValue.fields[e]=eG(r)),t}if(e.arrayValue){let t={arrayValue:{values:[]}};for(let r=0;r<(e.arrayValue.values||[]).length;++r)t.arrayValue.values[r]=eG(e.arrayValue.values[r]);return t}return Object.assign({},e)}function eQ(e){return(((e.mapValue||{}).fields||{}).__type__||{}).stringValue===eA}class ej{constructor(e){this.value=e}static empty(){return new ej({mapValue:{}})}field(e){if(e.isEmpty())return this.value;{let t=this.value;for(let r=0;r<e.length-1;++r)if(!eK(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()]=eG(t)}setAll(e){let t=G.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()]=eG(e):n.push(i.lastSegment())});let i=this.getFieldsMap(t);this.applyChanges(i,r,n)}delete(e){let t=this.field(e.popLast());eK(t)&&t.mapValue.fields&&delete t.mapValue.fields[e.lastSegment()]}isEqual(e){return eR(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)];eK(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(er(t,(t,r)=>e[t]=r),r))delete e[n]}clone(){return new ej(eG(this.value))}}class eH{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 eH(e,0,q.min(),q.min(),q.min(),ej.empty(),0)}static newFoundDocument(e,t,r,n){return new eH(e,1,t,q.min(),r,n,0)}static newNoDocument(e,t){return new eH(e,2,t,q.min(),q.min(),ej.empty(),0)}static newUnknownDocument(e,t){return new eH(e,3,t,q.min(),q.min(),ej.empty(),2)}convertToFoundDocument(e,t){return this.createTime.isEqual(q.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=ej.empty(),this.documentState=0,this}convertToUnknownDocument(e){return this.version=e,this.documentType=3,this.data=ej.empty(),this.documentState=2,this}setHasCommittedMutations(){return this.documentState=2,this}setHasLocalMutations(){return this.documentState=1,this.version=q.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 eH&&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 eH(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 eW{constructor(e,t){this.position=e,this.inclusive=t}}function eY(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()?Q.comparator(Q.fromName(a.referenceValue),r.key):eV(a,r.data.field(s.field)),"desc"===s.dir&&(n*=-1),0!==n)break}return n}function eX(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(!eR(e.position[r],t.position[r]))return!1;return!0}class eJ{constructor(e,t="asc"){this.field=e,this.dir=t}}class eZ{}class e0 extends eZ{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 e4(e,t,r):"array-contains"===t?new e9(e,r):"in"===t?new e7(e,r):"not-in"===t?new te(e,r):"array-contains-any"===t?new tt(e,r):new e0(e,t,r)}static createKeyFieldInFilter(e,t,r){return"in"===t?new e6(e,r):new e8(e,r)}matches(e){let t=e.data.field(this.field);return"!="===this.op?null!==t&&this.matchesComparison(eV(t,this.value)):null!==t&&ex(this.value)===ex(t)&&this.matchesComparison(eV(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 C()}}isInequality(){return["<","<=",">",">=","!=","not-in"].indexOf(this.op)>=0}getFlattenedFilters(){return[this]}getFilters(){return[this]}}class e1 extends eZ{constructor(e,t){super(),this.filters=e,this.op=t,this.ce=null}static create(e,t){return new e1(e,t)}matches(e){return e2(this)?void 0===this.filters.find(t=>!t.matches(e)):void 0!==this.filters.find(t=>t.matches(e))}getFlattenedFilters(){return null!==this.ce||(this.ce=this.filters.reduce((e,t)=>e.concat(t.getFlattenedFilters()),[])),this.ce}getFilters(){return Object.assign([],this.filters)}}function e2(e){return"and"===e.op}function e3(e){for(let t of e.filters)if(t instanceof e1)return!1;return!0}class e4 extends e0{constructor(e,t,r){super(e,t,r),this.key=Q.fromName(r.referenceValue)}matches(e){let t=Q.comparator(e.key,this.key);return this.matchesComparison(t)}}class e6 extends e0{constructor(e,t){super(e,"in",t),this.keys=e5("in",t)}matches(e){return this.keys.some(t=>t.isEqual(e.key))}}class e8 extends e0{constructor(e,t){super(e,"not-in",t),this.keys=e5("not-in",t)}matches(e){return!this.keys.some(t=>t.isEqual(e.key))}}function e5(e,t){var r;return((null==(r=t.arrayValue)?void 0:r.values)||[]).map(e=>Q.fromName(e.referenceValue))}class e9 extends e0{constructor(e,t){super(e,"array-contains",t)}matches(e){let t=e.data.field(this.field);return eq(t)&&eL(t.arrayValue,this.value)}}class e7 extends e0{constructor(e,t){super(e,"in",t)}matches(e){let t=e.data.field(this.field);return null!==t&&eL(this.value.arrayValue,t)}}class te extends e0{constructor(e,t){super(e,"not-in",t)}matches(e){if(eL(this.value.arrayValue,{nullValue:"NULL_VALUE"}))return!1;let t=e.data.field(this.field);return null!==t&&!eL(this.value.arrayValue,t)}}class tt extends e0{constructor(e,t){super(e,"array-contains-any",t)}matches(e){let t=e.data.field(this.field);return!(!eq(t)||!t.arrayValue.values)&&t.arrayValue.values.some(e=>eL(this.value.arrayValue,e))}}class tr{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.le=null}}function tn(e,t=null,r=[],n=[],i=null,s=null,a=null){return new tr(e,t,r,n,i,s,a)}function ti(e){if(null===e.le){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 e0)return t.field.canonicalString()+t.op.toString()+eF(t.value);if(e3(t)&&e2(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(","),null==e.limit||(t+="|l:",t+=e.limit),e.startAt&&(t+="|lb:",t+=e.startAt.inclusive?"b:":"a:",t+=e.startAt.position.map(e=>eF(e)).join(",")),e.endAt&&(t+="|ub:",t+=e.endAt.inclusive?"a:":"b:",t+=e.endAt.position.map(e=>eF(e)).join(",")),e.le=t}return e.le}function ts(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 e0?r instanceof e0&&t.op===r.op&&t.field.isEqual(r.field)&&eR(t.value,r.value):t instanceof e1?r instanceof e1&&t.op===r.op&&t.filters.length===r.filters.length&&t.filters.reduce((t,n,i)=>t&&e(n,r.filters[i]),!0):void C()}(e.filters[r],t.filters[r]))return!1;return e.collectionGroup===t.collectionGroup&&!!e.path.isEqual(t.path)&&!!eX(e.startAt,t.startAt)&&eX(e.endAt,t.endAt)}function ta(e){return Q.isDocumentKey(e.path)&&null===e.collectionGroup&&0===e.filters.length}class to{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.he=null,this.Pe=null,this.Te=null,this.startAt,this.endAt}}function tl(e){return new to(e)}function tu(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 th(e){return null!==e.collectionGroup}function tc(e){if(null===e.he){let t;e.he=[];let r=new Set;for(let t of e.explicitOrderBy)e.he.push(t),r.add(t.field.canonicalString());let n=e.explicitOrderBy.length>0?e.explicitOrderBy[e.explicitOrderBy.length-1].dir:"asc";
1(t=new eo(G.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.he.push(new eJ(t,n))}),r.has(G.keyField().canonicalString())||e.he.push(new eJ(G.keyField(),n))}return e.he}function td(e){return e.Pe||(e.Pe=tf(e,tc(e))),e.Pe}function tf(e,t){if("F"===e.limitType)return tn(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 eJ(e.field,t)});let r=e.endAt?new eW(e.endAt.position,e.endAt.inclusive):null,n=e.startAt?new eW(e.startAt.position,e.startAt.inclusive):null;return tn(e.path,e.collectionGroup,t,e.filters,e.limit,r,n)}}function tm(e,t){let r=e.filters.concat([t]);return new to(e.path,e.collectionGroup,e.explicitOrderBy.slice(),r,e.limit,e.limitType,e.startAt,e.endAt)}function tg(e,t,r){return new to(e.path,e.collectionGroup,e.explicitOrderBy.slice(),e.filters.slice(),t,r,e.startAt,e.endAt)}function tp(e,t){return ts(td(e),td(t))&&e.limitType===t.limitType}function ty(e){return`${ti(td(e))}|lt:${e.limitType}`}function tw(e){var t;let r;return`Query(target=${r=(t=td(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 e0?`${t.field.canonicalString()} ${t.op} ${eF(t.value)}`:t instanceof e1?t.op.toString()+" {"+t.getFilters().map(e).join(" ,")+"}":"Filter"})(e)).join(", ")}]`),null==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=>eF(e)).join(",")),t.endAt&&(r+=", endAt: ",r+=t.endAt.inclusive?"a:":"b:",r+=t.endAt.position.map(e=>eF(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):Q.isDocumentKey(e.path)?e.path.isEqual(r):e.path.isImmediateParentOf(r)}(e,t)&&function(e,t){for(let r of tc(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=eY(e,t,r);return e.inclusive?n<=0:n<0}(e.startAt,tc(e),t))&&(!e.endAt||!!function(e,t,r){let n=eY(e,t,r);return e.inclusive?n>=0:n>0}(e.endAt,tc(e),t))}function t_(e){return(t,r)=>{let n=!1;for(let i of tc(e)){let e=function(e,t,r){let n=e.field.isKeyField()?Q.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?eV(n,i):C()}(e.field,t,r);switch(e.dir){case"asc":return n;case"desc":return -1*n;default:return C()}}(i,t,r);if(0!==e)return e;n=n||i.field.isKeyField()}return 0}}class tT{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){er(this.inner,(t,r)=>{for(let[t,n]of r)e(t,n)})}isEmpty(){return en(this.inner)}size(){return this.innerSize}}let tE=new ei(Q.comparator),tI=new ei(Q.comparator);function tC(...e){let t=tI;for(let r of e)t=t.insert(r.key,r);return t}function tb(e){let t=tI;return e.forEach((e,r)=>t=t.insert(e,r.overlayedDocument)),t}function tS(){return new tT(e=>e.toString(),(e,t)=>e.isEqual(t))}let tA=new ei(Q.comparator),tN=new eo(Q.comparator);function tD(...e){let t=tN;for(let r of e)t=t.add(r);return t}let tk=new eo(F);function tx(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:ee(t)?"-0":t}}function tR(e){return{integerValue:""+e}}class tL{constructor(){this._=void 0}}function tV(e,t){return e instanceof tq?eU(t)||t&&"doubleValue"in t?t:{integerValue:0}:null}class tM extends tL{}class tO extends tL{constructor(e){super(),this.elements=e}}function tF(e,t){let r=tB(t);for(let t of e.elements)r.some(e=>eR(e,t))||r.push(t);return{arrayValue:{values:r}}}class tP extends tL{constructor(e){super(),this.elements=e}}function tU(e,t){let r=tB(t);for(let t of e.elements)r=r.filter(e=>!eR(e,t));return{arrayValue:{values:r}}}
1class tq extends tL{constructor(e,t){super(),this.serializer=e,this.Ie=t}}function t$(e){return em(e.integerValue||e.doubleValue)}function tB(e){return eq(e)&&e.arrayValue.values?e.arrayValue.values.slice():[]}class tK{constructor(e,t){this.field=e,this.transform=t}}class tz{constructor(e,t){this.version=e,this.transformResults=t}}class tG{constructor(e,t){this.updateTime=e,this.exists=t}static none(){return new tG}static exists(e){return new tG(void 0,e)}static updateTime(e){return new tG(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 tQ(e,t){return void 0!==e.updateTime?t.isFoundDocument()&&t.version.isEqual(e.updateTime):void 0===e.exists||e.exists===t.isFoundDocument()}class tj{}function tH(e,t){if(!e.hasLocalMutations||t&&0===t.fields.length)return null;if(null===t)return e.isNoDocument()?new t2(e.key,tG.none()):new tX(e.key,e.data,tG.none());{let r=e.data,n=ej.empty(),i=new eo(G.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 tJ(e.key,n,new eu(i.toArray()),tG.none())}}function tW(e,t,r,n){return e instanceof tX?function(e,t,r,n){if(!tQ(e.precondition,t))return r;let i=e.value.clone(),s=t1(e.fieldTransforms,n,t);return i.setAll(s),t.convertToFoundDocument(t.version,i).setHasLocalMutations(),null}(e,t,r,n):e instanceof tJ?function(e,t,r,n){if(!tQ(e.precondition,t))return r;let i=t1(e.fieldTransforms,n,t),s=t.data;return(s.setAll(tZ(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):tQ(e.precondition,t)?(t.convertToNoDocument(t.version).setHasLocalMutations(),null):r}function tY(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)&&P(r,n,(e,t)=>{var r,n;return e.field.isEqual(t.field)&&(r=e.transform,n=t.transform,r instanceof tO&&n instanceof tO||r instanceof tP&&n instanceof tP?P(r.elements,n.elements,eR):r instanceof tq&&n instanceof tq?eR(r.Ie,n.Ie):r instanceof tM&&n instanceof tM)})))&&(0===e.type?e.value.isEqual(t.value):1!==e.type||e.data.isEqual(t.data)&&e.fieldMask.isEqual(t.fieldMask))}class tX extends tj{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 tJ extends tj{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 tZ(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 t0(e,t,r){var n;let i=new Map;e.length===r.length||C();for(let s=0;s<r.length;s++){let a=e[s],o=a.transform,l=t.data.field(a.field);i.set(a.field,(n=r[s],o instanceof tO?tF(o,l):o instanceof tP?tU(o,l):n))}return i}function t1(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 tM?function(e,t){let r={fields:{[ey]:{stringValue:ep},[ev]:{timestampValue:{seconds:e.seconds,nanos:e.nanoseconds}}}};return t&&e_(t)&&(t=eT(t)),t&&(r.fields[ew]=t),{mapValue:r}}(t,s):e instanceof tO?tF(e,s):e instanceof tP?tU(e,s):function(e,t){let r=tV(e,t),n=t$(r)+t$(e.Ie);return eU(r)&&eU(e.Ie)?tR(n):tx(e.serializer,n)}(e,s))}return n}class t2 extends tj{constructor(e,t){super(),this.key=e,this.precondition=t,this.type=2,this.fieldTransforms=[]}getFieldMask(){return null}}class t3 extends tj{constructor(e,t){super(),this.key=e,this.precondition=t,this.type=3,this.fieldTransforms=[]}getFieldMask(){return null}}class t4{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 tX?function(e,t,r){let n=e.value.clone(),i=t0(e.fieldTransforms,t,r.transformResults);n.setAll(i),t.convertToFoundDocument(r.version,n).setHasCommittedMutations()}(e,t,r):e instanceof tJ?function(e,t,r){if(!tQ(e.precondition,t))return t.convertToUnknownDocument(r.version);let n=t0(e.fieldTransforms,t,r.transformResults),i=t.data;i.setAll(tZ(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=tW(r,e,t,this.localWriteTime));for(let r of this.mutations)r.key.isEqual(e.key)&&(t=tW(r,e,t,this.localWriteTime));return t}applyToLocalDocumentSet(e,t){let r=tS();return this.mutations.forEach(n=>{let i=e.get(n.key),s=i.overlayedDocument,a=this.applyToLocalView(s,i.mutatedFields),o=tH(s,a=t.has(n.key)?null:a);null!==o&&r.set(n.key,o),s.isValidDocument()||s.convertToNoDocument(q.min())}),r}keys(){return this.mutations.reduce((e,t)=>e.add(t.key),tD())}isEqual(e){return this.batchId===e.batchId&&P(this.mutations,e.mutations,(e,t)=>tY(e,t))&&P(this.baseMutations,e.baseMutations,(e,t)=>tY(e,t))}}class t6{constructor(e,t,r,n){this.batch=e,this.commitVersion=t,this.mutationResults=r,this.docVersions=n}static from(e,t,r){e.mutations.length===r.length||C();let n=tA,i=e.mutations;for(let e=0;e<i.length;e++)n=n.insert(i[e].key,r[e].version);return new t6(e,t,r,n)}}class t8{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 t5{constructor(e,t,r){this.alias=e,this.aggregateType=t,this.fieldPath=r}}class t9{constructor(e,t){this.count=e,this.unchangedNames=t}}function t7(e){if(void 0===e)return T("GRPC error has no .code"),b.UNKNOWN;switch(e){case n.OK:return b.OK;case n.CANCELLED:return b.CANCELLED;case n.UNKNOWN:return b.UNKNOWN;case n.DEADLINE_EXCEEDED:return b.DEADLINE_EXCEEDED;case n.RESOURCE_EXHAUSTED:return b.RESOURCE_EXHAUSTED;case n.INTERNAL:return b.INTERNAL;case n.UNAVAILABLE:return b.UNAVAILABLE;case n.UNAUTHENTICATED:return b.UNAUTHENTICATED;case n.INVALID_ARGUMENT:return b.INVALID_ARGUMENT;case n.NOT_FOUND:return b.NOT_FOUND;case n.ALREADY_EXISTS:return b.ALREADY_EXISTS;case n.PERMISSION_DENIED:return b.PERMISSION_DENIED;case n.FAILED_PRECONDITION:return b.FAILED_PRECONDITION;case n.ABORTED:return b.ABORTED;case n.OUT_OF_RANGE:return b.OUT_OF_RANGE;case n.UNIMPLEMENTED:return b.UNIMPLEMENTED;case n.DATA_LOSS:return b.DATA_LOSS;default:return C()}}(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 re=new c.jz([0xffffffff,0xffffffff],0);function rt(e){let t=(new TextEncoder).encode(e),r=new c.VV;return r.update(t),new Uint8Array(r.digest())}function rr(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 rn{constructor(e,t,r){if(this.bitmap=e,this.padding=t,this.hashCount=r,t<0||t>=8)throw new ri(`Invalid padding: ${t}`);if(r<0||e.length>0&&0===this.hashCount)throw new ri(`Invalid hash count: ${r}`);if(0===e.length&&0!==t)throw new ri(`Invalid padding when bitmap length is 0: ${t}`);this.Ee=8*e.length-t,this.de=c.jz.fromNumber(this.Ee)}Ae(e,t,r){let n=e.add(t.multiply(c.jz.fromNumber(r)));return 1===n.compare(re)&&(n=new c.jz([n.getBits(0),n.getBits(1)],0)),n.modulo(this.de).toNumber()}Re(e){return!!(this.bitmap[Math.floor(e/8)]&1<<e%8)}mightContain(e){if(0===this.Ee)return!1;let[t,r]=rr(rt(e));for(let e=0;e<this.hashCount;e++){let n=this.Ae(t,r,e);if(!this.Re(n))return!1}return!0}static create(e,t,r){let n=new rn(new Uint8Array(Math.ceil(e/8)),e%8==0?0:8-e%8,t);return r.forEach(e=>n.insert(e)),n}insert(e){if(0===this.Ee)return;let[t,r]=rr(rt(e));for(let e=0;e<this.hashCount;e++){let n=this.Ae(t,r,e);this.Ve(n)}}Ve(e){let t=Math.floor(e/8);this.bitmap[t]|=1<<e%8}}class ri extends Error{constructor(){super(...arguments),this.name="BloomFilterError"}}class rs{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,ra.createSynthesizedTargetChangeForCurrentChange(e,t,r)),new rs(q.min(),n,new ei(F),tE,tD())}}class ra{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 ra(r,t,tD(),tD(),tD())}}class ro{constructor(e,t,r,n){this.me=e,this.removedTargetIds=t,this.key=r,this.fe=n}}class rl{constructor(e,t){this.targetId=e,this.ge=t}}class ru{constructor(e,t,r=ec.EMPTY_BYTE_STRING,n=null){this.state=e,this.targetIds=t,this.resumeToken=r,this.cause=n}}class rh{constructor(){this.pe=0,this.ye=rf(),this.we=ec.EMPTY_BYTE_STRING,this.be=!1,this.Se=!0}get current(){return this.be}get resumeToken(){return this.we}get De(){return 0!==this.pe}get ve(){return this.Se}Ce(e){e.approximateByteSize()>0&&(this.Se=!0,this.we=e)}Fe(){let e=tD(),t=tD(),r=tD();return this.ye.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:C()}}),new ra(this.we,this.be,e,t,r)}Me(){this.Se=!1,this.ye=rf()}xe(e,t){this.Se=!0,this.ye=this.ye.insert(e,t)}Oe(e){this.Se=!0,this.ye=this.ye.remove(e)}Ne(){this.pe+=1}Be(){this.pe-=1,this.pe>=0||C()}Le(){this.Se=!0,this.be=!0}}class rc{constructor(e){this.ke=e,this.qe=new Map,this.Qe=tE,this.$e=rd(),this.Ke=rd(),this.Ue=new ei(F)}We(e){for(let t of e.me)e.fe&&e.fe.isFoundDocument()?this.Ge(t,e.fe):this.ze(t,e.key,e.fe);for(let t of e.removedTargetIds)this.ze(t,e.key,e.fe)}je(e){this.forEachTarget(e,t=>{let r=this.He(t);switch(e.state){case 0:this.Je(t)&&r.Ce(e.resumeToken);break;case 1:r.Be(),r.De||r.Me(),r.Ce(e.resumeToken);break;case 2:r.Be(),r.De||this.removeTarget(t);break;case 3:this.Je(t)&&(r.Le(),r.Ce(e.resumeToken));break;case 4:this.Je(t)&&(this.Ye(t),r.Ce(e.resumeToken));break;default:C()}})}forEachTarget(e,t){e.targetIds.length>0?e.targetIds.forEach(t):this.qe.forEach((e,r)=>{this.Je(r)&&t(r)})}Ze(e){let t=e.targetId,r=e.ge.count,n=this.Xe(t);if(n){let i=n.target;if(ta(i))if(0===r){let e=new Q(i.path);this.ze(t,e,eH.newNoDocument(e,q.min()))}else 1===r||C();else{let n=this.et(t);if(n!==r){let r=this.tt(e),i=r?this.nt(r,e,n):1;0!==i&&(this.Ye(t),this.Ue=this.Ue.insert(t,2===i?"TargetPurposeExistenceFilterMismatchBloom":"TargetPurposeExistenceFilterMismatch"))}}}}tt(e){let t,r,n=e.ge.unchangedNames;if(!n||!n.bits)return null;let{bits:{bitmap:i="",padding:s=0},hashCount:a=0}=n;try{t=eg(i).toUint8Array()}catch(e){if(e instanceof eh)return E("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 rn(t,s,a)}catch(e){return E(e instanceof ri?"BloomFilter error: ":"Applying bloom filter failed: ",e),null}return 0===r.Ee?null:r}nt(e,t,r){return 2*(t.ge.count!==r-this.st(e,t.targetId))}st(e,t){let r=this.ke.getRemoteKeysForTarget(t),n=0;return r.forEach(r=>{let i=this.ke.it(),s=`projects/${i.projectId}/databases/${i.database}/documents/${r.path.canonicalString()}`;e.mightContain(s)||(this.ze(t,r,null),n++)}),n}ot(e){let t=new Map;this.qe.forEach((r,n)=>{let i=this.Xe(n);if(i){if(r.current&&ta(i.target)){let t=new Q(i.target.path);this._t(t).has(n)||this.ut(n,t)||this.ze(n,t,eH.newNoDocument(t,e))}r.ve&&(t.set(n,r.Fe()),r.Me())}});let r=tD();this.Ke.forEach((e,t)=>{let n=!0;t.forEachWhile(e=>{let t=this.Xe(e);return!t||"TargetPurposeLimboResolution"===t.purpose||(n=!1,!1)}),n&&(r=r.add(e))}),this.Qe.forEach((t,r)=>r.setReadTime(e));let n=new rs(e,t,this.Ue,this.Qe,r);return this.Qe=tE,this.$e=rd(),this.Ke=rd(),this.Ue=new ei(F),n}Ge(e,t){if(!this.Je(e))return;let r=2*!!this.ut(e,t.key);this.He(e).xe(t.key,r),this.Qe=this.Qe.insert(t.key,t),this.$e=this.$e.insert(t.key,this._t(t.key).add(e)),this.Ke=this.Ke.insert(t.key,this.ct(t.key).add(e))}ze(e,t,r){if(!this.Je(e))return;let n=this.He(e);this.ut(e,t)?n.xe(t,1):n.Oe(t),this.Ke=this.Ke.insert(t,this.ct(t).delete(e)),this.Ke=this.Ke.insert(t,this.ct(t).add(e)),r&&(this.Qe=this.Qe.insert(t,r))}removeTarget(e){this.qe.delete(e)}et(e){let t=this.He(e).Fe();return this.ke.getRemoteKeysForTarget(e).size+t.addedDocuments.size-t.removedDocuments.size}Ne(e){this.He(e).Ne()}He(e){let t=this.qe.get(e);return t||(t=new rh,this.qe.set(e,t)),t}ct(e){let t=this.Ke.get(e);return t||(t=new eo(F),this.Ke=this.Ke.insert(e,t)),t}_t(e){let t=this.$e.get(e);return t||(t=new eo(F),this.$e=this.$e.insert(e,t)),t}Je(e){let t=null!==this.Xe(e);return t||_("WatchChangeAggregator","Detected inactive target",e),t}Xe(e){let t=this.qe.get(e);return t&&t.De?null:this.ke.lt(e)}Ye(e){this.qe.set(e,new rh),this.ke.getRemoteKeysForTarget(e).forEach(t=>{this.ze(e,t,null)})}ut(e,t){return this.ke.getRemoteKeysForTarget(e).has(t)}}function rd(){return new ei(Q.comparator)}function rf(){return new ei(Q.comparator)}let rm={asc:"ASCENDING",desc:"DESCENDING"},rg={"<":"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"},rp={and:"AND",or:"OR"};class ry{constructor(e,t){this.databaseId=e,this.useProto3Json=t}}function rw(e,t){return e.useProto3Json||null==t?t:{value:t}}function rv(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 r_(e,t){return e.useProto3Json?t.toBase64():t.toUint8Array()}function rT(e){return e||C(),q.fromTimestamp(function(e){let t=ef(e);return new U(t.seconds,t.nanos)}(e))}function rE(e,t){return rI(e,t).canonicalString()}function rI(e,t){let r=new K(["projects",e.projectId,"databases",e.database]).child("documents");return void 0===t?r:r.child(t)}function rC(e){let t=K.fromString(e);return rV(t)||C(),t}function rb(e,t){return rE(e.databaseId,t.path)}function rS(e,t){let r=rC(t);if(r.get(1)!==e.databaseId.projectId)throw new S(b.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 S(b.INVALID_ARGUMENT,"Tried to deserialize key from different database: "+r.get(3)+" vs "+e.databaseId.database);return new Q(rD(r))}function rA(e,t){return rE(e.databaseId,t)}function rN(e){return new K(["projects",e.databaseId.projectId,"databases",e.databaseId.database]).canonicalString()}function rD(e){return e.length>4&&"documents"===e.get(4)||C(),e.popFirst(5)}function rk(e,t,r){return{name:rb(e,t),fields:r.value.mapValue.fields}}function rx(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=rA(e,i);let o=function(e){if(0!==e.length)return function e(t){return t instanceof e0?function(e){if("=="===e.op){if(eB(e.value))return{unaryFilter:{field:rR(e.field),op:"IS_NAN"}};if(e$(e.value))return{unaryFilter:{field:rR(e.field),op:"IS_NULL"}}}else if("!="===e.op){if(eB(e.value))return{unaryFilter:{field:rR(e.field),op:"IS_NOT_NA
4N"}};if(e$(e.value))return{unaryFilter:{field:rR(e.field),op:"IS_NOT_NULL"}}}return{fieldFilter:{field:rR(e.field),op:rg[e.op],value:e.value}}}(t):t instanceof e1?function(t){let r=t.getFilters().map(t=>e(t));return 1===r.length?r[0]:{compositeFilter:{op:rp[t.op],filters:r}}}(t):C()}(e1.create(e,"and"))}(t.filters);o&&(s.structuredQuery.where=o);let l=function(e){if(0!==e.length)return e.map(e=>({field:rR(e.field),direction:rm[e.dir]}))}(t.orderBy);l&&(s.structuredQuery.orderBy=l);let u=rw(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}),{ht:s,parent:i}}function rR(e){return{fieldPath:e.canonicalString()}}function rL(e){return G.fromServerFormat(e.fieldPath)}function rV(e){return e.length>=4&&"projects"===e.get(0)&&"databases"===e.get(2)}class rM{constructor(e,t,r,n,i=q.min(),s=q.min(),a=ec.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 rM(this.target,this.targetId,this.purpose,e,this.snapshotVersion,this.lastLimboFreeSnapshotVersion,this.resumeToken,this.expectedCount)}withResumeToken(e,t){return new rM(this.target,this.targetId,this.purpose,this.sequenceNumber,t,this.lastLimboFreeSnapshotVersion,e,null)}withExpectedCount(e){return new rM(this.target,this.targetId,this.purpose,this.sequenceNumber,this.snapshotVersion,this.lastLimboFreeSnapshotVersion,this.resumeToken,e)}withLastLimboFreeSnapshotVersion(e){return new rM(this.target,this.targetId,this.purpose,this.sequenceNumber,this.snapshotVersion,e,this.resumeToken,this.expectedCount)}}class rO{constructor(e){this.Tt=e}}class rF{constructor(){}At(e,t){this.Rt(e,t),t.Vt()}Rt(e,t){if("nullValue"in e)this.ft(t,5);else if("booleanValue"in e)this.ft(t,10),t.gt(+!!e.booleanValue);else if("integerValue"in e)this.ft(t,15),t.gt(em(e.integerValue));else if("doubleValue"in e){let r=em(e.doubleValue);isNaN(r)?this.ft(t,13):(this.ft(t,15),ee(r)?t.gt(0):t.gt(r))}else if("timestampValue"in e){let r=e.timestampValue;this.ft(t,20),"string"==typeof r&&(r=ef(r)),t.yt(`${r.seconds||""}`),t.gt(r.nanos||0)}else if("stringValue"in e)this.wt(e.stringValue,t),this.bt(t);else if("bytesValue"in e)this.ft(t,30),t.St(eg(e.bytesValue)),this.bt(t);else if("referenceValue"in e)this.Dt(e.referenceValue,t);else if("geoPointValue"in e){let r=e.geoPointValue;this.ft(t,45),t.gt(r.latitude||0),t.gt(r.longitude||0)}else"mapValue"in e?eQ(e)?this.ft(t,Number.MAX_SAFE_INTEGER):ez(e)?this.vt(e.mapValue,t):(this.Ct(e.mapValue,t),this.bt(t)):"arrayValue"in e?(this.Ft(e.arrayValue,t),this.bt(t)):C()}wt(e,t){this.ft(t,25),this.Mt(e,t)}Mt(e,t){t.yt(e)}Ct(e,t){let r=e.fields||{};for(let e of(this.ft(t,55),Object.keys(r)))this.wt(e,t),this.Rt(r[e],t)}vt(e,t){var r,n;let i=e.fields||{};this.ft(t,53);let s=(null==(n=null==(r=i[ek].arrayValue)?void 0:r.values)?void 0:n.length)||0;this.ft(t,15),t.gt(em(s)),this.wt(ek,t),this.Rt(i[ek],t)}Ft(e,t){let r=e.values||[];for(let e of(this.ft(t,50),r))this.Rt(e,t)}Dt(e,t){this.ft(t,37),Q.fromName(e).path.forEach(e=>{this.ft(t,60),this.Mt(e,t)})}ft(e,t){e.gt(t)}bt(e){e.gt(2)}}rF.xt=new rF;class rP{constructor(){this.Tn=new rU}addToCollectionParentIndex(e,t){return this.Tn.add(t),X.resolve()}getCollectionParents(e,t){return X.resolve(this.Tn.getEntries(t))}addFieldIndex(e,t){return X.resolve()}deleteFieldIndex(e,t){return X.resolve()}deleteAllFieldIndexes(e){return X.resolve()}createTargetIndexes(e,t){return X.resolve()}getDocumentsMatchingTarget(e,t){return X.resolve(null)}getIndexType(e,t){return X.resolve(0)}getFieldIndexes(e,t){return X.resolve([])}getNextCollectionGroupToUpdate(e){return X.resolve(null)}getMinOffset(e,t){return X.resolve(H.min())}getMinOffsetFromCollectionGroup(e,t){return X.resolve(H.min())}updateCollectionGroup(e,t,r){return X.resolve()}updateIndexEntries(e,t){return X.resolve()}}class rU{constructor(){this.index={}}add(e){let t=e.lastSegment(),r=e.popLast(),n=this.index[t]||new eo(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 eo(K.comparator)).toArray()}}new Uint8Array(0);let rq={didRun:!1,sequenceNumbersCollected:0,targetsRemoved:0,documentsRemoved:0};class r${static withCacheSize(e){return new r$(e,r$.DEFAULT_COLLECTION_PE
4RCENTILE,r$.DEFAULT_MAX_SEQUENCE_NUMBERS_TO_COLLECT)}constructor(e,t,r){this.cacheSizeCollectionThreshold=e,this.percentileToCollect=t,this.maximumSequenceNumbersToCollect=r}}r$.DEFAULT_COLLECTION_PERCENTILE=10,r$.DEFAULT_MAX_SEQUENCE_NUMBERS_TO_COLLECT=1e3,r$.DEFAULT=new r$(0x2800000,r$.DEFAULT_COLLECTION_PERCENTILE,r$.DEFAULT_MAX_SEQUENCE_NUMBERS_TO_COLLECT),r$.DISABLED=new r$(-1,0,0);class rB{constructor(e){this.$n=e}next(){return this.$n+=2,this.$n}static Kn(){return new rB(0)}static Un(){return new rB(-1)}}let rK="LruGarbageCollector";function rz([e,t],[r,n]){let i=F(e,r);return 0===i?F(t,n):i}class rG{constructor(e){this.Hn=e,this.buffer=new eo(rz),this.Jn=0}Yn(){return++this.Jn}Zn(e){let t=[e,this.Yn()];if(this.buffer.size<this.Hn)this.buffer=this.buffer.add(t);else{let e=this.buffer.last();0>rz(t,e)&&(this.buffer=this.buffer.delete(e).add(t))}}get maxValue(){return this.buffer.last()[0]}}class rQ{constructor(e,t,r){this.garbageCollector=e,this.asyncQueue=t,this.localStore=r,this.Xn=null}start(){-1!==this.garbageCollector.params.cacheSizeCollectionThreshold&&this.er(6e4)}stop(){this.Xn&&(this.Xn.cancel(),this.Xn=null)}get started(){return null!==this.Xn}er(e){_(rK,`Garbage collection scheduled in ${e}ms`),this.Xn=this.asyncQueue.enqueueAfterDelay("lru_garbage_collection",e,async()=>{this.Xn=null;try{await this.localStore.collectGarbage(this.garbageCollector)}catch(e){J(e)?_(rK,"Ignoring IndexedDB error during garbage collection: ",e):await Y(e)}await this.er(3e5)})}}class rj{constructor(e,t){this.tr=e,this.params=t}calculateTargetCount(e,t){return this.tr.nr(e).next(e=>Math.floor(t/100*e))}nthSequenceNumber(e,t){if(0===t)return X.resolve(Z.ae);let r=new rG(t);return this.tr.forEachTarget(e,e=>r.Zn(e.sequenceNumber)).next(()=>this.tr.rr(e,e=>r.Zn(e))).next(()=>r.maxValue)}removeTargets(e,t,r){return this.tr.removeTargets(e,t,r)}removeOrphanedDocuments(e,t){return this.tr.removeOrphanedDocuments(e,t)}collect(e,t){return -1===this.params.cacheSizeCollectionThreshold?(_("LruGarbageCollector","Garbage collection skipped; disabled"),X.resolve(rq)):this.getCacheSize(e).next(r=>r<this.params.cacheSizeCollectionThreshold?(_("LruGarbageCollector",`Garbage collection skipped; Cache size ${r} is lower than threshold ${this.params.cacheSizeCollectionThreshold}`),rq):this.ir(e,t))}getCacheSize(e){return this.tr.getCacheSize(e)}ir(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`),X.resolve({didRun:!0,sequenceNumbersCollected:n,targetsRemoved:i,documentsRemoved:e})))}}class rH{constructor(){this.changes=new tT(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,eH.newInvalidDocument(e).setReadTime(t))}getEntry(e,t){this.assertNotApplied();let r=this.changes.get(t);return void 0!==r?X.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 rW{constructor(e,t){this.overlayedDocument=e,this.mutatedFields=t}}class rY{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&&tW(r.mutation,e,eu.empty(),U.now()),e))}getDocuments(e,t){return this.remoteDocumentCache.getEntries(e,t).next(t=>this.getLocalViewOfDocuments(e,t,tD()).next(()=>t))}getLocalViewOfDocuments(e,t,r=tD()){let n=tS();return this.populateOverlays(e,n,t).next(()=>this.computeViews(e,t,n,r).next(e=>{let t=tC();return e.forEach((e,r)=>{t=t.insert(e,r.overlayedDocument)}),t}))}getOverlayedDocuments(e,t){let r=tS();return this.populateOverlays(e,r,t).next(()=>this.computeViews(e,t,r,tD()))}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=tE,s=tS(),a=tS();return t.forEach((e,t)=>{let a=r.get(t.key);n.has(t.key)&&(void 0===a||a.mutation instanceof tJ)?i=i.insert(t.key,t):void 0!==a?(s.set(t.key,a.mutation.getFieldMask()),tW(a.mutation,t,a.mutation.getFieldMask(),U.now())):s.set(t.key,eu.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 rW(t,null!=(r=s.get(e))?r:null))}),a))}recalculateAndSaveOverlays(e,t){let r=tS(),n=new ei((e,t)=>e-t),i=tD();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)||eu.empty();a=i.applyToLocalView(s,a),r.set(e,a);let o=(n.get(i.batchId)||tD()).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=tS();l.forEach(e=>{if(!i.has(e)){let n=tH(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 X.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 Q.isDocumentKey(t.path)&&null===t.collectionGroup&&0===t.filters.length?this.getDocumentsMatchingDocumentQuery(e,t.path):th(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):X.resolve(tS()),a=-1,o=i;return s.next(t=>X.forEach(t,(t,r)=>(a<r.largestBatchId&&(a=r.largestBatchId),i.get(t)?X.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,tD())).next(e=>({batchId:a,changes:tb(e)})))})}getDocumentsMatchingDocumentQuery(e,t){return this.getDocument(e,new Q(t)).next(e=>{let t=tC();return e.isFoundDocument()&&(t=t.insert(e.key,e)),t})}getDocumentsMatchingCollectionGroupQuery(e,t,r,n){let i=t.collectionGroup,s=tC();return this.indexManager.getCollectionParents(e,i).next(a=>X.forEach(a,a=>{let o=new to(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,eH.newInvalidDocument(n)))});let r=tC();return e.forEach((e,n)=>{let s=i.get(e);void 0!==s&&tW(s.mutation,n,eu.empty(),U.now()),tv(t,n)&&(r=r.insert(e,n))}),r})}}class rX{constructor(e){this.serializer=e,this.dr=new Map,this.Ar=new Map}getBundleMetadata(e,t){return X.resolve(this.dr.get(t))}saveBundleMetadata(e,t){return this.dr.set(t.id,{id:t.id,version:t.version,createTime:rT(t.createTime)}),X.resolve()}getNamedQuery(e,t){return X.resolve(this.Ar.get(t))}saveNamedQuery(e,t){return this.Ar.set(t.name,{name:t.name,query:function(e){let t=function(e){var t;let r,n=function(e){let t=rC(e);return 4===t.length?K.emptyPath():rD(t)}(e.parent),i=e.structuredQuery,s=i.from?i.from.length:0,a=null;if(s>0){1===s||C();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=rL(e.unaryFilter.field);return e0.create(t,"==",{doubleValue:NaN});case"IS_NULL":let r=rL(e.unaryFilter.field);return e0.create(r,"==",{nullValue:"NULL_VALUE"});case"IS_NOT_NAN":let n=rL(e.unaryFilter.field);return e0.create(n,"!=",{doubleValue:NaN});case"IS_NOT_NULL":let i=rL(e.unaryFilter.field);return e0.create(i,"!=",{nullValue:"NULL_VALUE"});default:return C()}}(t):void 0!==t.fieldFilter?e0.create(rL(t.fieldFilter.field),function(e){switch(e){case"EQUAL":return"==";case"NOT_EQUAL":return"!=";case"GREATER_THAN":return">";case"GREATER_THAN_OR_EQUAL":return">=";case"LESS_THAN":return"<";case"LESS_THAN_OR_EQUAL":return"<=";case"ARRAY_CONTAINS":return"array-contains";case"IN":return"in";case"NOT_IN":return"not-in";case"ARRAY_CONTAINS_ANY":return"array-contains-any";default:return C()}}(t.fieldFilter.op),t.fieldFilter.value):void 0!==t.compositeFilter?e1.create(t.compositeFilter.filters.map(t=>e(t)),function(e){switch(e){case"AND":return"and";case"OR":return"or";default:return C()}}(t.compositeFilter.op)):C()}(e);return r instanceof e1&&e3(t=r)&&e2(t)?r.getFilters():[r]}(i.where));let l=[];i.orderBy&&(l=i.orderBy.map(e=>new eJ(rL(e.field),function(e){switch(e){case"ASCENDING":return"asc";case"DESCENDING":return"desc";default:return}}(e.direction))));let u=null;i.limit&&(u=null==(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 eW(e.values||[],t)}(i.startAt));let c=null;return i.endAt&&(c=function(e){let t=!e.before;return new eW(e.values||[],t)}(i.endAt)),new to(n,a,l,o,u,"F",h,c)}({parent:e.parent,structuredQuery:e.structuredQuery});return"LAST"===e.limitType?tg(t,t.limit,"L"):t}(t.bundledQuery),readTime:rT(t.readTime)}),X.resolve()}}class rJ{constructor(){this.overlays=new ei(Q.comparator),this.Rr=new Map}getOverlay(e,t){return X.resolve(this.overlays.get(t))}getOverlays(e,t){let r=tS();
6return X.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.Et(e,t,n)}),X.resolve()}removeOverlaysForBatchId(e,t,r){let n=this.Rr.get(r);return void 0!==n&&(n.forEach(e=>this.overlays=this.overlays.remove(e)),this.Rr.delete(r)),X.resolve()}getOverlaysForCollection(e,t,r){let n=tS(),i=t.length+1,s=new Q(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 X.resolve(n)}getOverlaysForCollectionGroup(e,t,r,n){let i=new ei((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=tS(),i=i.insert(e.largestBatchId,t)),t.set(e.getKey(),e)}}let a=tS(),o=i.getIterator();for(;o.hasNext()&&(o.getNext().value.forEach((e,t)=>a.set(e,t)),!(a.size()>=n)););return X.resolve(a)}Et(e,t,r){let n=this.overlays.get(r.key);if(null!==n){let e=this.Rr.get(n.largestBatchId).delete(r.key);this.Rr.set(n.largestBatchId,e)}this.overlays=this.overlays.insert(r.key,new t8(t,r));let i=this.Rr.get(t);void 0===i&&(i=tD(),this.Rr.set(t,i)),this.Rr.set(t,i.add(r.key))}}class rZ{constructor(){this.sessionToken=ec.EMPTY_BYTE_STRING}getSessionToken(e){return X.resolve(this.sessionToken)}setSessionToken(e,t){return this.sessionToken=t,X.resolve()}}class r0{constructor(){this.Vr=new eo(r1.mr),this.gr=new eo(r1.pr)}isEmpty(){return this.Vr.isEmpty()}addReference(e,t){let r=new r1(e,t);this.Vr=this.Vr.add(r),this.gr=this.gr.add(r)}yr(e,t){e.forEach(e=>this.addReference(e,t))}removeReference(e,t){this.wr(new r1(e,t))}br(e,t){e.forEach(e=>this.removeReference(e,t))}Sr(e){let t=new Q(new K([])),r=new r1(t,e),n=new r1(t,e+1),i=[];return this.gr.forEachInRange([r,n],e=>{this.wr(e),i.push(e.key)}),i}Dr(){this.Vr.forEach(e=>this.wr(e))}wr(e){this.Vr=this.Vr.delete(e),this.gr=this.gr.delete(e)}vr(e){let t=new Q(new K([])),r=new r1(t,e),n=new r1(t,e+1),i=tD();return this.gr.forEachInRange([r,n],e=>{i=i.add(e.key)}),i}containsKey(e){let t=new r1(e,0),r=this.Vr.firstAfterOrEqual(t);return null!==r&&e.isEqual(r.key)}}class r1{constructor(e,t){this.key=e,this.Cr=t}static mr(e,t){return Q.comparator(e.key,t.key)||F(e.Cr,t.Cr)}static pr(e,t){return F(e.Cr,t.Cr)||Q.comparator(e.key,t.key)}}class r2{constructor(e,t){this.indexManager=e,this.referenceDelegate=t,this.mutationQueue=[],this.Fr=1,this.Mr=new eo(r1.mr)}checkEmpty(e){return X.resolve(0===this.mutationQueue.length)}addMutationBatch(e,t,r,n){let i=this.Fr;this.Fr++,this.mutationQueue.length>0&&this.mutationQueue[this.mutationQueue.length-1];let s=new t4(i,t,r,n);for(let t of(this.mutationQueue.push(s),n))this.Mr=this.Mr.add(new r1(t.key,i)),this.indexManager.addToCollectionParentIndex(e,t.key.path.popLast());return X.resolve(s)}lookupMutationBatch(e,t){return X.resolve(this.Or(t))}getNextMutationBatchAfterBatchId(e,t){let r=this.Nr(t+1),n=r<0?0:r;return X.resolve(this.mutationQueue.length>n?this.mutationQueue[n]:null)}getHighestUnacknowledgedBatchId(){return X.resolve(0===this.mutationQueue.length?-1:this.Fr-1)}getAllMutationBatches(e){return X.resolve(this.mutationQueue.slice())}getAllMutationBatchesAffectingDocumentKey(e,t){let r=new r1(t,0),n=new r1(t,1/0),i=[];return this.Mr.forEachInRange([r,n],e=>{let t=this.Or(e.Cr);i.push(t)}),X.resolve(i)}getAllMutationBatchesAffectingDocumentKeys(e,t){let r=new eo(F);return t.forEach(e=>{let t=new r1(e,0),n=new r1(e,1/0);this.Mr.forEachInRange([t,n],e=>{r=r.add(e.Cr)})}),X.resolve(this.Br(r))}getAllMutationBatchesAffectingQuery(e,t){let r=t.path,n=r.length+1,i=r;Q.isDocumentKey(i)||(i=i.child(""));let s=new r1(new Q(i),0),a=new eo(F);return this.Mr.forEachWhile(e=>{let t=e.key.path;return!!r.isPrefixOf(t)&&(t.length===n&&(a=a.add(e.Cr)),!0)},s),X.resolve(this.Br(a))}Br(e){let t=[];return e.forEach(e=>{let r=this.Or(e);null!==r&&t.push(r)}),t}removeMutationBatch(e,t){0===this.Lr(t.batchId,"removed")||C(),this.mutationQueue.shift();let r=this.Mr;
6return X.forEach(t.mutations,n=>{let i=new r1(n.key,t.batchId);return r=r.delete(i),this.referenceDelegate.markPotentiallyOrphaned(e,n.key)}).next(()=>{this.Mr=r})}qn(e){}containsKey(e,t){let r=new r1(t,0),n=this.Mr.firstAfterOrEqual(r);return X.resolve(t.isEqual(n&&n.key))}performConsistencyCheck(e){return this.mutationQueue.length,X.resolve()}Lr(e,t){return this.Nr(e)}Nr(e){return 0===this.mutationQueue.length?0:e-this.mutationQueue[0].batchId}Or(e){let t=this.Nr(e);return t<0||t>=this.mutationQueue.length?null:this.mutationQueue[t]}}class r3{constructor(e){this.kr=e,this.docs=new ei(Q.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.kr(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 X.resolve(r?r.document.mutableCopy():eH.newInvalidDocument(t))}getEntries(e,t){let r=tE;return t.forEach(e=>{let t=this.docs.get(e);r=r.insert(e,t?t.document.mutableCopy():eH.newInvalidDocument(e))}),X.resolve(r)}getDocumentsMatchingQuery(e,t,r,n){let i=tE,s=t.path,a=new Q(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=Q.comparator(e.documentKey,t.documentKey))?r:F(e.largestBatchId,t.largestBatchId)}(new H(a.readTime,a.key,-1),r)||(n.has(a.key)||tv(t,a))&&(i=i.insert(a.key,a.mutableCopy()))}return X.resolve(i)}getAllFromCollectionGroup(e,t,r,n){C()}qr(e,t){return X.forEach(this.docs,e=>t(e))}newChangeBuffer(e){return new r4(this)}getSize(e){return X.resolve(this.size)}}class r4 extends rH{constructor(e){super(),this.Ir=e}applyChanges(e){let t=[];
vendor: 4,976 bytes, line 6
6return this.changes.forEach((r,n)=>{n.isValidDocument()?t.push(this.Ir.addEntry(e,n)):this.Ir.removeEntry(r)}),X.waitFor(t)}getFromCache(e,t){return this.Ir.getEntry(e,t)}getAllFromCache(e,t){return this.Ir.getEntries(e,t)}}class r6{constructor(e){this.persistence=e,this.Qr=new tT(e=>ti(e),ts),this.lastRemoteSnapshotVersion=q.min(),this.highestTargetId=0,this.$r=0,this.Kr=new r0,this.targetCount=0,this.Ur=rB.Kn()}forEachTarget(e,t){return this.Qr.forEach((e,r)=>t(r)),X.resolve()}getLastRemoteSnapshotVersion(e){return X.resolve(this.lastRemoteSnapshotVersion)}getHighestSequenceNumber(e){return X.resolve(this.$r)}allocateTargetId(e){return this.highestTargetId=this.Ur.next(),X.resolve(this.highestTargetId)}setTargetsMetadata(e,t,r){return r&&(this.lastRemoteSnapshotVersion=r),t>this.$r&&(this.$r=t),X.resolve()}zn(e){this.Qr.set(e.target,e);let t=e.targetId;t>this.highestTargetId&&(this.Ur=new rB(t),this.highestTargetId=t),e.sequenceNumber>this.$r&&(this.$r=e.sequenceNumber)}addTargetData(e,t){return this.zn(t),this.targetCount+=1,X.resolve()}updateTargetData(e,t){return this.zn(t),X.resolve()}removeTargetData(e,t){return this.Qr.delete(t.target),this.Kr.Sr(t.targetId),this.targetCount-=1,X.resolve()}removeTargets(e,t,r){let n=0,i=[];return this.Qr.forEach((s,a)=>{a.sequenceNumber<=t&&null===r.get(a.targetId)&&(this.Qr.delete(s),i.push(this.removeMatchingKeysForTargetId(e,a.targetId)),n++)}),X.waitFor(i).next(()=>n)}getTargetCount(e){return X.resolve(this.targetCount)}getTargetData(e,t){let r=this.Qr.get(t)||null;return X.resolve(r)}addMatchingKeys(e,t,r){return this.Kr.yr(t,r),X.resolve()}removeMatchingKeys(e,t,r){this.Kr.br(t,r);let n=this.persistence.referenceDelegate,i=[];return n&&t.forEach(t=>{i.push(n.markPotentiallyOrphaned(e,t))}),X.waitFor(i)}removeMatchingKeysForTargetId(e,t){return this.Kr.Sr(t),X.resolve()}getMatchingKeysForTargetId(e,t){let r=this.Kr.vr(t);return X.resolve(r)}containsKey(e,t){return X.resolve(this.Kr.containsKey(t))}}class r8{constructor(e,t){this.Wr={},this.overlays={},this.Gr=new Z(0),this.zr=!1,this.zr=!0,this.jr=new rZ,this.referenceDelegate=e(this),this.Hr=new r6(this),this.indexManager=new rP,this.remoteDocumentCache=new r3(e=>this.referenceDelegate.Jr(e)),this.serializer=new rO(t),this.Yr=new rX(this.serializer)}start(){return Promise.resolve()}shutdown(){return this.zr=!1,Promise.resolve()}get started(){return this.zr}setDatabaseDeletedListener(){}setNetworkEnabled(){}getIndexManager(e){return this.indexManager}getDocumentOverlayCache(e){let t=this.overlays[e.toKey()];return t||(t=new rJ,this.overlays[e.toKey()]=t),t}getMutationQueue(e,t){let r=this.Wr[e.toKey()];return r||(r=new r2(t,this.referenceDelegate),this.Wr[e.toKey()]=r),r}getGlobalsCache(){return this.jr}getTargetCache(){return this.Hr}getRemoteDocumentCache(){return this.remoteDocumentCache}getBundleCache(){return this.Yr}runTransaction(e,t,r){_("MemoryPersistence","Starting transaction:",e);let n=new r5(this.Gr.next());return this.referenceDelegate.Zr(),r(n).next(e=>this.referenceDelegate.Xr(n).next(()=>e)).toPromise().then(e=>(n.raiseOnCommittedEvent(),e))}ei(e,t){return X.or(Object.values(this.Wr).map(r=>()=>r.containsKey(e,t)))}}class r5 extends W{constructor(e){super(),this.currentSequenceNumber=e}}class r9{constructor(e){this.persistence=e,this.ti=new r0,this.ni=null}static ri(e){return new r9(e)}get ii(){if(this.ni)return this.ni;throw C()}addReference(e,t,r){return this.ti.addReference(r,t),this.ii.delete(r.toString()),X.resolve()}removeReference(e,t,r){return this.ti.removeReference(r,t),this.ii.add(r.toString()),X.resolve()}markPotentiallyOrphaned(e,t){return this.ii.add(t.toString()),X.resolve()}removeTarget(e,t){this.ti.Sr(t.targetId).forEach(e=>this.ii.add(e.toString()));let r=this.persistence.getTargetCache();return r.getMatchingKeysForTargetId(e,t.targetId).next(e=>{e.forEach(e=>this.ii.add(e.toString()))}).next(()=>r.removeTargetData(e,t))}Zr(){this.ni=new Set}Xr(e){let t=this.persistence.getRemoteDocumentCache().newChangeBuffer();return X.forEach(this.ii,r=>{let n=Q.fromPath(r);return this.si(e,n).next(e=>{e||t.removeEntry(n,q.min())})}).next(()=>(this.ni=null,t.apply(e)))}updateLimboDocument(e,t){return this.si(e,t).next(e=>{e?this.ii.delete(t.toString()):this.ii.add(t.toString())})}Jr(e){return 0}si(e,t){return X.or([()=>X.resolve(this.ti.containsKey(t)),()=>this.persistence.getTargetCache().containsKey(e,t),()=>this.persistence.ei(e,t)])}}class r7{constructor(e,t){this.persistence=e,this.oi=new tT(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 rj(this,t)}static ri(e,t){return new r7(e,t)}Zr(){}Xr(e){return X.resolve()}forEachTarget(e,t){return this.persistence.getTargetCache().forEac
6hTarget(e,t)}nr(e){let t=this.sr(e);return this.persistence.getTargetCache().getTargetCount(e).next(e=>t.next(t=>e+t))}sr(e){let t=0;return this.rr(e,e=>{t++}).next(()=>t)}rr(e,t){return X.forEach(this.oi,(r,n)=>this.ar(e,r,n).next(e=>e?X.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.qr(e,n=>this.ar(e,n,t).next(e=>{e||(r++,i.removeEntry(n,q.min()))})).next(()=>i.apply(e)).next(()=>r)}markPotentiallyOrphaned(e,t){return this.oi.set(t,e.currentSequenceNumber),X.resolve()}removeTarget(e,t){let r=t.withSequenceNumber(e.currentSequenceNumber);return this.persistence.getTargetCache().updateTargetData(e,r)}addReference(e,t,r){return this.oi.set(r,e.currentSequenceNumber),X.resolve()}removeReference(e,t,r){return this.oi.set(r,e.currentSequenceNumber),X.resolve()}updateLimboDocument(e,t){return this.oi.set(t,e.currentSequenceNumber),X.resolve()}Jr(e){let t=e.key.toString().length;return e.isFoundDocument()&&(t+=function e(t){switch(ex(t)){case 0:case 1:return 4;case 2:return 8;case 3:case 8:return 16;case 4:let r=eT(t);return r?16+e(r):16;case 5:return 2*t.stringValue.length;case 6:return eg(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,er(n.fields,(t,r)=>{i+=t.length+e(r)}),i;default:throw C()}}(e.data.value)),t}ar(e,t,r){return X.or([()=>this.persistence.ei(e,t),()=>this.persistence.getTargetCache().containsKey(e,t),()=>{let e=this.oi.get(t);return X.resolve(void 0!==e&&e>r)}])}getCacheSize(e){return this.persistence.getRemoteDocumentCache().getSize(e)}}class ne{constructor(e,t,r,n){this.targetId=e,this.fromCache=t,this.Hi=r,this.Ji=n}static Yi(e,t){let r=tD(),n=tD();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 ne(e,t.fromCache,r,n)}}class nt{constructor(){this._documentReadCount=0}get documentReadCount(){return this._documentReadCount}incrementDocumentReadCount(e){this._documentReadCount+=e}}class nr{constructor(){this.Zi=!1,this.Xi=!1,this.es=100,this.ts=(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.ns=e,this.indexManager=t,this.Zi=!0}getDocumentsMatchingQuery(e,t,r,n){let i={result:null};return this.rs(e,t).next(e=>{i.result=e}).next(()=>{if(!i.result)return this.ss(e,t,n,r).next(e=>{i.result=e})}).next(()=>{if(i.result)return;let r=new nt;return this._s(e,t,r).next(n=>{if(i.result=n,this.Xi)return this.us(e,t,r,n.size)})}).next(()=>i.result)}us(e,t,r,n){return r.documentReadCount<this.es?(v()<=u.$b.DEBUG&&_("QueryEngine","SDK will not create cache indexes for query:",tw(t),"since it only creates cache indexes for collection contains","more than or equal to",this.es,"documents"),X.resolve()):(v()<=u.$b.DEBUG&&_("QueryEngine","Query:",tw(t),"scans",r.documentReadCount,"local documents and returns",n,"documents as results."),r.documentReadCount>this.ts*n?(v()<=u.$b.DEBUG&&_("QueryEngine","The SDK decides to create cache indexes for query:",tw(t),"as using cache indexes may help improve performance."),this.indexManager.createTargetIndexes(e,td(t))):X.resolve())}rs(e,t){if(tu(t))return X.resolve(null);let r=td(t);return this.indexManager.getIndexType(e,r).next(n=>0===n?null:(null!==t.limit&&1===n&&(r=td(t=tg(t,null,"F"))),this.indexManager.getDocumentsMatchingTarget(e,r).next(n=>{let i=tD(...n);return this.ns.getDocuments(e,i).next(n=>this.indexManager.getMinOffset(e,r).next(r=>{let s=this.cs(t,n);return this.ls(t,s,i,r.readTime)?this.rs(e,tg(t,null,"F")):this.hs(e,s,t,r)}))})))}ss(e,t,r,n){return tu(t)||n.isEqual(q.min())?X.resolve(null):this.ns.getDocuments(e,r).next(i=>{let s=this.cs(t,i);return this.ls(t,s,r,n)?X.resolve(null):(v()<=u.$b.DEBUG&&_("QueryEngine","Re-using previous result from %s to execute query: %s",n.toString(),tw(t)),this.hs(e,s,t,function(e,t){let r=e.toTimestamp().seconds,n=e.toTimestamp().nanoseconds+1;return new H(q.fromTimestamp(1e9===n?new U(r+1,0):new U(r,n)),Q.empty(),-1)}(n,0)).next(e=>e))})}cs(e,t){let r=new eo(t_(e));return t.forEach((t,n)=>{tv(e,n)&&(r=r.add(n))}),r}ls(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)}_s(e,t,r){return v()<=u.$b.DEBUG&&_("QueryEngine","Using full collection scan to execute query:",tw(t)),this.ns.getDocumentsMatchingQuery(e,t,H.min(),r)}hs(e,t,r,n){return this.ns.getDocumentsMatchingQuery(e,r,n).next(e=>(t.forEach(t=>{e=e.insert(t.key,t)}),e))}}let nn="LocalStore";class ni{constructor(e,t,r,n){this.persistence=e,this.Ps=t,this.serializer
6=n,this.Ts=new ei(F),this.Is=new tT(e=>ti(e),ts),this.Es=new Map,this.ds=e.getRemoteDocumentCache(),this.Hr=e.getTargetCache(),this.Yr=e.getBundleCache(),this.As(r)}As(e){this.documentOverlayCache=this.persistence.getDocumentOverlayCache(e),this.indexManager=this.persistence.getIndexManager(e),this.mutationQueue=this.persistence.getMutationQueue(e,this.indexManager),this.localDocuments=new rY(this.ds,this.mutationQueue,this.documentOverlayCache,this.indexManager),this.ds.setIndexManager(this.indexManager),this.Ps.initialize(this.localDocuments,this.indexManager)}collectGarbage(e){return this.persistence.runTransaction("Collect garbage","readwrite-primary",t=>e.collect(t,this.Ts))}}async function ns(e,t){return await e.persistence.runTransaction("Handle user change","readonly",r=>{let n;return e.mutationQueue.getAllMutationBatches(r).next(i=>(n=i,e.As(t),e.mutationQueue.getAllMutationBatches(r))).next(t=>{let i=[],s=[],a=tD();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=>({Rs:e,removedBatchIds:i,addedBatchIds:s}))})})}function na(e){return e.persistence.runTransaction("Get last remote snapshot version","readonly",t=>e.Hr.getLastRemoteSnapshotVersion(t))}async function no(e,t,r){let n=e.Ts.get(t);try{r||await e.persistence.runTransaction("Release target",r?"readwrite":"readwrite-primary",t=>e.persistence.referenceDelegate.removeTarget(t,n))}catch(e){if(!J(e))throw e;_(nn,`Failed to update sequence numbers for target ${t}: ${e}`)}e.Ts=e.Ts.remove(t),e.Is.delete(n.target)}function nl(e,t,r){let n=q.min(),i=tD();return e.persistence.runTransaction("Execute query","readwrite",s=>(function(e,t,r){let n=e.Is.get(r);return void 0!==n?X.resolve(e.Ts.get(n)):e.Hr.getTargetData(t,r)})(e,s,td(t)).next(t=>{if(t)return n=t.lastLimboFreeSnapshotVersion,e.Hr.getMatchingKeysForTargetId(s,t.targetId).next(e=>{i=e})}).next(()=>e.Ps.getDocumentsMatchingQuery(s,t,r?n:q.min(),r?i:tD())).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.Es.get(s)||q.min(),a.forEach((e,t)=>{t.readTime.compareTo(o)>0&&(o=t.readTime)}),n.Es.set(s,o),{documents:r,gs:i}}))}class nu{constructor(){this.activeTargetIds=tk}Ds(e){this.activeTargetIds=this.activeTargetIds.add(e)}vs(e){this.activeTargetIds=this.activeTargetIds.delete(e)}Ss(){return JSON.stringify({activeTargetIds:this.activeTargetIds.toArray(),updateTimeMs:Date.now()})}}class nh{constructor(){this.ho=new nu,this.Po={},this.onlineStateHandler=null,this.sequenceNumberHandler=null}addPendingMutation(e){}updateMutationState(e,t,r){}addLocalQueryTarget(e,t=!0){return t&&this.ho.Ds(e),this.Po[e]||"not-current"}updateQueryState(e,t,r){this.Po[e]=t}removeLocalQueryTarget(e){this.ho.vs(e)}isLocalQueryTarget(e){return this.ho.activeTargetIds.has(e)}clearQueryState(e){delete this.Po[e]}getAllActiveQueryTargets(){return this.ho.activeTargetIds}isActiveQueryTarget(e){return this.ho.activeTargetIds.has(e)}start(){return this.ho=new nu,Promise.resolve()}handleUserChange(e,t,r){}setOnlineState(e){}shutdown(){}writeSequenceNumber(e){}notifyBundleLoaded(e){}}class nc{To(e){}shutdown(){}}let nd="ConnectivityMonitor";class nf{constructor(){this.Io=()=>this.Eo(),this.Ao=()=>this.Ro(),this.Vo=[],this.mo()}To(e){this.Vo.push(e)}shutdown(){window.removeEventListener("online",this.Io),window.removeEventListener("offline",this.Ao)}mo(){window.addEventListener("online",this.Io),window.addEventListener("offline",this.Ao)}Eo(){for(let e of(_(nd,"Network connectivity changed: AVAILABLE"),this.Vo))e(0)}Ro(){for(let e of(_(nd,"Network connectivity changed: UNAVAILABLE"),this.Vo))e(1)}static D(){return"undefined"!=typeof window&&void 0!==window.addEventListener&&void 0!==window.removeEventListener}}let nm=null;function ng(){return null===nm?nm=0x10000000+Math.round(0x80000000*Math.random()):nm++,"0x"+nm.toString(16)}let np="RestConnection",ny={BatchGetDocuments:"batchGet",Commit:"commit",RunQuery:"runQuery",RunAggregation
6Query:"runAggregationQuery"};class nw{get fo(){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.po=t+"://"+e.host,this.yo=`projects/${r}/databases/${n}`,this.wo=this.databaseId.database===eC?`project_id=${r}`:`project_id=${r}&database_id=${n}`}bo(e,t,r,n,i){let s=ng(),a=this.So(e,t.toUriEncodedString());_(np,`Sending RPC '${e}' ${s}:`,a,r);let o={"google-cloud-resource-prefix":this.yo,"x-goog-request-params":this.wo};return this.Do(o,n,i),this.vo(e,a,o,r).then(t=>(_(np,`Received RPC '${e}' ${s}: `,t),t),t=>{throw E(np,`RPC '${e}' ${s} failed with error: `,t,"url: ",a,"request:",r),t})}Co(e,t,r,n,i,s){return this.bo(e,t,r,n,i)}Do(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)}So(e,t){let r=ny[e];return`${this.po}/v1/${t}:${r}`}terminate(){}}class nv{constructor(e){this.Fo=e.Fo,this.Mo=e.Mo}xo(e){this.Oo=e}No(e){this.Bo=e}Lo(e){this.ko=e}onMessage(e){this.qo=e}close(){this.Mo()}send(e){this.Fo(e)}Qo(){this.Oo()}$o(){this.Bo()}Ko(e){this.ko(e)}Uo(e){this.qo(e)}}let n_="WebChannelConnection";class nT extends nw{constructor(e){super(e),this.forceLongPolling=e.forceLongPolling,this.autoDetectLongPolling=e.autoDetectLongPolling,this.useFetchStreams=e.useFetchStreams,this.longPollingOptions=e.longPollingOptions}vo(e,t,r,n){let i=ng();return new Promise((s,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();_(n_,`XHR for RPC '${e}' ${i} received:`,JSON.stringify(t)),s(t);break;case d.O4.TIMEOUT:_(n_,`RPC '${e}' ${i} timed out`),a(new S(b.DEADLINE_EXCEEDED,"Request time out"));break;case d.O4.HTTP_ERROR:let r=o.getStatus();if(_(n_,`RPC '${e}' ${i} 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(b).indexOf(t)>=0?t:b.UNKNOWN}(t.status);a(new S(e,t.message))}else a(new S(b.UNKNOWN,"Server responded with status "+o.getStatus()))}else a(new S(b.UNAVAILABLE,"Connection failed."));break;default:C()}}finally{_(n_,`RPC '${e}' ${i} completed.`)}});let l=JSON.stringify(n);_(n_,`RPC '${e}' ${i} sending request:`,n),o.send(t,"POST",l,r,15)})}Wo(e,t,r){let i=ng(),s=[this.po,"/","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.Do(l.initMessageHeaders,t,r),l.encodeInitMessageHeaders=!0;let h=s.join("");_(n_,`Creating RPC '${e}' stream ${i}: ${h}`,l);let c=a.createWebChannel(h,l),f=!1,m=!1,g=new nv({Fo:t=>{m?_(n_,`Not sending because RPC '${e}' stream ${i} is closed:`,t):(f||(_(n_,`Opening RPC '${e}' stream ${i} transport.`),c.open(),f=!0),_(n_,`RPC '${e}' stream ${i} sending:`,t),c.send(t))},Mo:()=>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||(_(n_,`RPC '${e}' stream ${i} transport opened.`),g.Qo())}),p(c,d.iO.EventType.CLOSE,()=>{m||(m=!0,_(n_,`RPC '${e}' stream ${i} transport closed`),g.Ko())}),p(c,d.iO.EventType.ERROR,t=>{m||(m=!0,E(n_,`RPC '${e}' stream ${i} transport errored:`,t),g.Ko(new S(b.UNAVAILABLE,"The operation could not be completed")))}),p(c,d.iO.EventType.MESSAGE,t=>{var r;if(!m){let s=t.data[0];s||C();let a=(null==s?void 0:s.error)||(null==(r=s[0])?void 0:r.error);if(a){_(n_,`RPC '${e}' stream ${i} received error:`,a);let t=a.status,r=function(e){let t=n[e];if(void 0!==t)return t7(t)}(t),s=a.message;void 0===r&&(r=b.INTERNAL,s="Unknown error status: "+t+" with message "+a.message),m=!0,g.Ko(new S(r,s)),c.close()}else _(n_,`RPC '${e}' stream ${i}
6 received:`,s),g.Uo(s)}}),p(o,d.Jh.STAT_EVENT,t=>{t.stat===d.ro.PROXY?_(n_,`RPC '${e}' stream ${i} detected buffering proxy`):t.stat===d.ro.NOPROXY&&_(n_,`RPC '${e}' stream ${i} detected no buffering proxy`)}),setTimeout(()=>{g.$o()},0),g}}function nE(){return"undefined"!=typeof document?document:null}function nI(e){return new ry(e,!0)}class nC{constructor(e,t,r=1e3,n=1.5,i=6e4){this.Ti=e,this.timerId=t,this.Go=r,this.zo=n,this.jo=i,this.Ho=0,this.Jo=null,this.Yo=Date.now(),this.reset()}reset(){this.Ho=0}Zo(){this.Ho=this.jo}Xo(e){this.cancel();let t=Math.floor(this.Ho+this.e_()),r=Math.max(0,Date.now()-this.Yo),n=Math.max(0,t-r);n>0&&_("ExponentialBackoff",`Backing off for ${n} ms (base delay: ${this.Ho} ms, delay with jitter: ${t} ms, last attempt: ${r} ms ago)`),this.Jo=this.Ti.enqueueAfterDelay(this.timerId,n,()=>(this.Yo=Date.now(),e())),this.Ho*=this.zo,this.Ho<this.Go&&(this.Ho=this.Go),this.Ho>this.jo&&(this.Ho=this.jo)}t_(){null!==this.Jo&&(this.Jo.skipDelay(),this.Jo=null)}cancel(){null!==this.Jo&&(this.Jo.cancel(),this.Jo=null)}e_(){return(Math.random()-.5)*this.Ho}}let nb="PersistentStream";class nS{constructor(e,t,r,n,i,s,a,o){this.Ti=e,this.n_=r,this.r_=n,this.connection=i,this.authCredentialsProvider=s,this.appCheckCredentialsProvider=a,this.listener=o,this.state=0,this.i_=0,this.s_=null,this.o_=null,this.stream=null,this.__=0,this.a_=new nC(e,t)}u_(){return 1===this.state||5===this.state||this.c_()}c_(){return 2===this.state||3===this.state}start(){this.__=0,4!==this.state?this.auth():this.l_()}async stop(){this.u_()&&await this.close(0)}h_(){this.state=0,this.a_.reset()}P_(){this.c_()&&null===this.s_&&(this.s_=this.Ti.enqueueAfterDelay(this.n_,6e4,()=>this.T_()))}I_(e){this.E_(),this.stream.send(e)}async T_(){if(this.c_())return this.close(0)}E_(){this.s_&&(this.s_.cancel(),this.s_=null)}d_(){this.o_&&(this.o_.cancel(),this.o_=null)}async close(e,t){this.E_(),this.d_(),this.a_.cancel(),this.i_++,4!==e?this.a_.reset():t&&t.code===b.RESOURCE_EXHAUSTED?(T(t.toString()),T("Using maximum backoff delay to prevent overloading the backend."),this.a_.Zo()):t&&t.code===b.UNAUTHENTICATED&&3!==this.state&&(this.authCredentialsProvider.invalidateToken(),this.appCheckCredentialsProvider.invalidateToken()),null!==this.stream&&(this.A_(),this.stream.close(),this.stream=null),this.state=e,await this.listener.Lo(t)}A_(){}auth(){this.state=1;let e=this.R_(this.i_),t=this.i_;Promise.all([this.authCredentialsProvider.getToken(),this.appCheckCredentialsProvider.getToken()]).then(([e,r])=>{this.i_===t&&this.V_(e,r)},t=>{e(()=>{let e=new S(b.UNKNOWN,"Fetching auth token failed: "+t.message);return this.m_(e)})})}V_(e,t){let r=this.R_(this.i_);this.stream=this.f_(e,t),this.stream.xo(()=>{r(()=>this.listener.xo())}),this.stream.No(()=>{r(()=>(this.state=2,this.o_=this.Ti.enqueueAfterDelay(this.r_,1e4,()=>(this.c_()&&(this.state=3),Promise.resolve())),this.listener.No()))}),this.stream.Lo(e=>{r(()=>this.m_(e))}),this.stream.onMessage(e=>{r(()=>1==++this.__?this.g_(e):this.onNext(e))})}l_(){this.state=5,this.a_.Xo(async()=>{this.state=0,this.start()})}m_(e){return _(nb,`close with error: ${e}`),this.stream=null,this.close(4,e)}R_(e){return t=>{this.Ti.enqueueAndForget(()=>this.i_===e?t():(_(nb,"stream callback skipped by getCloseGuardedDispatcher."),Promise.resolve()))}}}class nA extends nS{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}f_(e,t){return this.connection.Wo("Listen",e,t)}g_(e){return this.onNext(e)}onNext(e){this.a_.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:C(),a=t.targetChange.targetIds||[],o=(i=t.targetChange.resumeToken,e.useProto3Json?(void 0===i||"string"==typeof i||C(),ec.fromBase64String(i||"")):(void 0===i||i instanceof f||i instanceof Uint8Array||C(),ec.fromUint8Array(i||new Uint8Array))),l=t.targetChange.cause;r=new ru(s,a,o,l&&new S(void 0===l.code?b.UNKNOWN:t7(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=rS(e,n.document.name),s=rT(n.document.updateTime),a=n.document.createTime?rT(n.document.createTime):q.min(),o=new ej({mapValue:{fields:n.document.fields}}),l=eH.newFoundDocument(i,s,a,o);r=new ro(n.targetIds||[],n.removedTargetIds||[],l.key,l)}else if("documentDelete"in t){t.documentDelete;let n=t.documentDelete;n.document;let i=rS(e,n.document),s=n.readTime?rT(n.readTime):q.min(),a=eH.newNoDocument(i,s);r=new ro([],n.removedTargetIds||[],a.key,a)}else if("documentRemove"in t){t.documentRemove;let n=t.documentRemove;n.document;let i=rS(e,n.document);r=new ro([],n.removedTargetIds||[],i,null)}else{if(!("filter"in t))return C();{t.filter;let e=t.filter;e.targetId;
6let{count:n=0,unchangedNames:i}=e,s=new t9(n,i);r=new rl(e.targetId,s)}}return r}(this.serializer,e),r=function(e){if(!("targetChange"in e))return q.min();let t=e.targetChange;return t.targetIds&&t.targetIds.length?q.min():t.readTime?rT(t.readTime):q.min()}(e);return this.listener.p_(t,r)}y_(e){let t={};t.database=rN(this.serializer),t.addTarget=function(e,t){let r,n=t.target;if((r=ta(n)?{documents:{documents:[rA(e,n.path)]}}:{query:rx(e,n).ht}).targetId=t.targetId,t.resumeToken.approximateByteSize()>0){r.resumeToken=r_(e,t.resumeToken);let n=rw(e,t.expectedCount);null!==n&&(r.expectedCount=n)}else if(t.snapshotVersion.compareTo(q.min())>0){r.readTime=rv(e,t.snapshotVersion.toTimestamp());let n=rw(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 C()}}(t.purpose);return null==r?null:{"goog-listen-tags":r}}(this.serializer,e);r&&(t.labels=r),this.I_(t)}w_(e){let t={};t.database=rN(this.serializer),t.removeTarget=e,this.I_(t)}}class nN extends nS{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 b_(){return this.__>0}start(){this.lastStreamToken=void 0,super.start()}A_(){this.b_&&this.S_([])}f_(e,t){return this.connection.Wo("Write",e,t)}g_(e){return e.streamToken||C(),this.lastStreamToken=e.streamToken,e.writeResults&&0!==e.writeResults.length&&C(),this.listener.D_()}onNext(e){var t,r;e.streamToken||C(),this.lastStreamToken=e.streamToken,this.a_.reset();let n=(t=e.writeResults,r=e.commitTime,t&&t.length>0?(void 0!==r||C(),t.map(e=>{let t;return(t=e.updateTime?rT(e.updateTime):rT(r)).isEqual(q.min())&&(t=rT(r)),new tz(t,e.transformResults||[])})):[]),i=rT(e.commitTime);return this.listener.v_(i,n)}C_(){let e={};e.database=rN(this.serializer),this.I_(e)}S_(e){let t={streamToken:this.lastStreamToken,writes:e.map(e=>(function(e,t){var r;let n;if(t instanceof tX)n={update:rk(e,t.key,t.value)};else if(t instanceof t2)n={delete:rb(e,t.key)};else if(t instanceof tJ)n={update:rk(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 t3))return C();n={verify:rb(e,t.key)}}return t.fieldTransforms.length>0&&(n.updateTransforms=t.fieldTransforms.map(e=>(function(e,t){let r=t.transform;if(r instanceof tM)return{fieldPath:t.field.canonicalString(),setToServerValue:"REQUEST_TIME"};if(r instanceof tO)return{fieldPath:t.field.canonicalString(),appendMissingElements:{values:r.elements}};if(r instanceof tP)return{fieldPath:t.field.canonicalString(),removeAllFromArray:{values:r.elements}};if(r instanceof tq)return{fieldPath:t.field.canonicalString(),increment:r.Ie};throw C()})(0,e))),t.precondition.isNone||(n.currentDocument=void 0!==(r=t.precondition).updateTime?{updateTime:rv(e,r.updateTime.toTimestamp())}:void 0!==r.exists?{exists:r.exists}:C()),n})(this.serializer,e))};this.I_(t)}}class nD{}class nk extends nD{constructor(e,t,r,n){super(),this.authCredentials=e,this.appCheckCredentials=t,this.connection=r,this.serializer=n,this.F_=!1}M_(){if(this.F_)throw new S(b.FAILED_PRECONDITION,"The client has already been terminated.")}bo(e,t,r,n){return this.M_(),Promise.all([this.authCredentials.getToken(),this.appCheckCredentials.getToken()]).then(([i,s])=>this.connection.bo(e,rI(t,r),n,i,s)).catch(e=>{throw"FirebaseError"===e.name?(e.code===b.UNAUTHENTICATED&&(this.authCredentials.invalidateToken(),this.appCheckCredentials.invalidateToken()),e):new S(b.UNKNOWN,e.toString())})}Co(e,t,r,n,i){return this.M_(),Promise.all([this.authCredentials.getToken(),this.appCheckCredentials.getToken()]).then(([s,a])=>this.connection.Co(e,rI(t,r),n,s,a,i)).catch(e=>{throw"FirebaseError"===e.name?(e.code===b.UNAUTHENTICATED&&(this.authCredentials.invalidateToken(),this.appCheckCredentials.invalidateToken()),e):new S(b.UNKNOWN,e.toString())})}terminate(){this.F_=!0,this.connection.terminate()}}class nx{constructor(e,t){this.asyncQueue=e,this.onlineStateHandler=t,this.state="Unknown",this.x_=0,this.O_=null,this.N_=!0}B_(){0===this.x_&&(this.L_("Unknown"),this.O_=this.asyncQueue.enqueueAfterDelay("online_state_timeout",1e4,()=>(this.O_=null,this.k_("Backend didn't respond within 10 seconds."),this.L_("Offline"),Promise.resolve())))}q_(e){"Online"===this.state?this.L_("Unknown"):(this.x_++,this.x_>=1&&(this.Q_(),this.k_(`Connection failed 1 times. Most recent error: ${e.toString()}`),this.L_("Offline")))}set(e){this.Q_(),this.x_=0,"Online"===e&&(this.N_=!1),this.L_(e)}L_(e){e!==this.state&&(this.state=e,this.onlineStateHandler(e))}k_(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.N_?(T(t),this.N_=!1):_("OnlineStateTracker",t)}Q_(){null!==this.O_&&(this.O_.cancel(),this.O_=null)}}let nR="RemoteStore";class nL{constructor(e,t,r,n,i){this.localStore=e,this.datastore=t,this.asyncQueue=r,this.remoteSyncer={},this.K_=[],this.U_=new Map,this.W_=new Set,this.G_=[],this.z_=i,this.z_.To(e=>{r.enqueueAndForget(async()=>
7{nB(this)&&(_(nR,"Restarting streams for network reachability change."),await async function(e){e.W_.add(4),await nM(e),e.j_.set("Unknown"),e.W_.delete(4),await nV(e)}(this))})}),this.j_=new nx(r,n)}}async function nV(e){if(nB(e))for(let t of e.G_)await t(!0)}async function nM(e){for(let t of e.G_)await t(!1)}function nO(e,t){e.U_.has(t.targetId)||(e.U_.set(t.targetId,t),n$(e)?nq(e):n4(e).c_()&&nP(e,t))}function nF(e,t){let r=n4(e);e.U_.delete(t),r.c_()&&nU(e,t),0===e.U_.size&&(r.c_()?r.P_():nB(e)&&e.j_.set("Unknown"))}function nP(e,t){if(e.H_.Ne(t.targetId),t.resumeToken.approximateByteSize()>0||t.snapshotVersion.compareTo(q.min())>0){let r=e.remoteSyncer.getRemoteKeysForTarget(t.targetId).size;t=t.withExpectedCount(r)}n4(e).y_(t)}function nU(e,t){e.H_.Ne(t),n4(e).w_(t)}function nq(e){e.H_=new rc({getRemoteKeysForTarget:t=>e.remoteSyncer.getRemoteKeysForTarget(t),lt:t=>e.U_.get(t)||null,it:()=>e.datastore.serializer.databaseId}),n4(e).start(),e.j_.B_()}function n$(e){return nB(e)&&!n4(e).u_()&&e.U_.size>0}function nB(e){return 0===e.W_.size}async function nK(e){e.j_.set("Online")}async function nz(e){e.U_.forEach((t,r)=>{nP(e,t)})}async function nG(e,t){e.H_=void 0,n$(e)?(e.j_.q_(t),nq(e)):e.j_.set("Unknown")}async function nQ(e,t,r){if(e.j_.set("Online"),t instanceof ru&&2===t.state&&t.cause)try{await async function(e,t){let r=t.cause;for(let n of t.targetIds)e.U_.has(n)&&(await e.remoteSyncer.rejectListen(n,r),e.U_.delete(n),e.H_.removeTarget(n))}(e,t)}catch(r){_(nR,"Failed to remove targets %s: %s ",t.targetIds.join(","),r),await nj(e,r)}else if(t instanceof ro?e.H_.We(t):t instanceof rl?e.H_.Ze(t):e.H_.je(t),!r.isEqual(q.min()))try{let t=await na(e.localStore);r.compareTo(t)>=0&&await function(e,t){let r=e.H_.ot(t);
7return r.targetChanges.forEach((r,n)=>{if(r.resumeToken.approximateByteSize()>0){let i=e.U_.get(n);i&&e.U_.set(n,i.withResumeToken(r.resumeToken,t))}}),r.targetMismatches.forEach((t,r)=>{let n=e.U_.get(t);if(!n)return;e.U_.set(t,n.withResumeToken(ec.EMPTY_BYTE_STRING,n.snapshotVersion)),nU(e,t);let i=new rM(n.target,t,r,n.sequenceNumber);nP(e,i)}),e.remoteSyncer.applyRemoteEvent(r)}(e,r)}catch(t){_(nR,"Failed to raise snapshot:",t),await nj(e,t)}}async function nj(e,t,r){if(!J(t))throw t;e.W_.add(1),await nM(e),e.j_.set("Offline"),r||(r=()=>na(e.localStore)),e.asyncQueue.enqueueRetryable(async()=>{_(nR,"Retrying IndexedDB access"),await r(),e.W_.delete(1),await nV(e)})}function nH(e,t){return t().catch(r=>nj(e,r,t))}async function nW(e){var t;let r=n6(e),n=e.K_.length>0?e.K_[e.K_.length-1].batchId:-1;for(;nB(t=e)&&t.K_.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.K_.length&&r.P_();break}n=t.batchId,function(e,t){e.K_.push(t);let r=n6(e);r.c_()&&r.b_&&r.S_(t.mutations)}(e,t)}catch(t){await nj(e,t)}nY(e)&&nX(e)}function nY(e){return nB(e)&&!n6(e).u_()&&e.K_.length>0}function nX(e){n6(e).start()}async function nJ(e){n6(e).C_()}async function nZ(e){let t=n6(e);for(let r of e.K_)t.S_(r.mutations)}async function n0(e,t,r){let n=e.K_.shift(),i=t6.from(n,t,r);await nH(e,()=>e.remoteSyncer.applySuccessfulWrite(i)),await nW(e)}async function n1(e,t){t&&n6(e).b_&&await async function(e,t){var r;if(function(e){switch(e){case b.OK:return C();case b.CANCELLED:case b.UNKNOWN:case b.DEADLINE_EXCEEDED:case b.RESOURCE_EXHAUSTED:case b.INTERNAL:case b.UNAVAILABLE:case b.UNAUTHENTICATED:return!1;case b.INVALID_ARGUMENT:case b.NOT_FOUND:case b.ALREADY_EXISTS:case b.PERMISSION_DENIED:case b.FAILED_PRECONDITION:case b.ABORTED:case b.OUT_OF_RANGE:case b.UNIMPLEMENTED:case b.DATA_LOSS:return!0;default:return C()}}(r=t.code)&&r!==b.ABORTED){let r=e.K_.shift();n6(e).h_(),await nH(e,()=>e.remoteSyncer.rejectFailedWrite(r.batchId,t)),await nW(e)}}(e,t),nY(e)&&nX(e)}async function n2(e,t){e.asyncQueue.verifyOperationInProgress(),_(nR,"RemoteStore received new credentials");let r=nB(e);e.W_.add(3),await nM(e),r&&e.j_.set("Unknown"),await e.remoteSyncer.handleCredentialChange(t),e.W_.delete(3),await nV(e)}async function n3(e,t){t?(e.W_.delete(2),await nV(e)):t||(e.W_.add(2),await nM(e),e.j_.set("Unknown"))}function n4(e){var t,r,n;return e.J_||(t=e.datastore,r=e.asyncQueue,n={xo:nK.bind(null,e),No:nz.bind(null,e),Lo:nG.bind(null,e),p_:nQ.bind(null,e)},t.M_(),e.J_=new nA(r,t.connection,t.authCredentials,t.appCheckCredentials,t.serializer,n),e.G_.push(async t=>{t?(e.J_.h_(),n$(e)?nq(e):e.j_.set("Unknown")):(await e.J_.stop(),e.H_=void 0)})),e.J_}function n6(e){var t,r,n;return e.Y_||(t=e.datastore,r=e.asyncQueue,n={xo:()=>Promise.resolve(),No:nJ.bind(null,e),Lo:n1.bind(null,e),D_:nZ.bind(null,e),v_:n0.bind(null,e)},t.M_(),e.Y_=new nN(r,t.connection,t.authCredentials,t.appCheckCredentials,t.serializer,n),e.G_.push(async t=>{t?(e.Y_.h_(),await nW(e)):(await e.Y_.stop(),e.K_.length>0&&(_(nR,`Stopping write stream with ${e.K_.length} pending writes`),e.K_=[]))})),e.Y_}class n8{constructor(e,t,r,n,i){this.asyncQueue=e,this.timerId=t,this.targetTimeMs=r,this.op=n,this.removalCallback=i,this.deferred=new A,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 n8(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 S(b.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 n5(e,t){if(T("AsyncQueue",`${t}: ${e}`),J(e))return new S(b.UNAVAILABLE,`${t}: ${e}`);throw e}class n9{static emptySet(e){return new n9(e.comparator)}constructor(e){this.comparator=e?(t,r)=>e(t,r)||Q.comparator(t.key,r.key):(e,t)=>Q.comparator(e.key,t.key),this.keyedMap=tC(),this.sortedSet=new ei(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 n9)||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 n9;return r.comparator=this.comparator,r.keyedMap=e,r.sortedSet=t,r}}class n7{constructor(){this.Z_=new ei(Q.comparator)}track(e){let t=e.doc.key,r=this.Z_.get(t);r?0!==e.type&&3===r.type?this.Z_=this.Z_.insert(t,e):3===e.type&&1!==r.type?this.Z_=this.Z_.insert(t,{type:r.type,doc:e.doc}):2===e.type&&2===r.type?this.Z_=this.Z_.insert(t,{type:2,doc:e.doc}):2===e.type&&0===r.type?this.Z_=this.Z_.insert(t,{type:0,doc:e.doc}):1===e.type&&0===r.type?this.Z_=this.Z_.remove(t):1===e.type&&2===r.type?this.Z_=this.Z_.insert(t,{type:1,doc:r.doc}):0===e.type&&1===r.type?this.Z_=this.Z_.insert(t,{type:2,doc:e.doc}):C():this.Z_=this.Z_.insert(t,e)}X_(){let e=[];return this.Z_.inorderTraversal((t,r)=>{e.push(r)}),e}}class ie{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 ie(e,t,n9.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)&&tp(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 it{constructor(){this.ea=void 0,this.ta=[]}na(){return this.ta.some(e=>e.ra())}}class ir{constructor(){this.queries=ii(),this.onlineState="Unknown",this.ia=new Set}terminate(){!function(e,t){let r=e.queries;e.queries=ii(),r.forEach((e,r)=>{for(let e of r.ta)e.onError(t)})}(this,new S(b.ABORTED,"Firestore shutting down"))}}function ii(){return new tT(e=>ty(e),tp)}async function is(e,t){let r=3,n=t.query,i=e.queries.get(n);i?!i.na()&&t.ra()&&(r=2):(i=new it,r=+!t.ra());try{switch(r){case 0:i.ea=await e.onListen(n,!0);break;case 1:i.ea=await e.onListen(n,!1);break;case 2:await e.onFirstRemoteStoreListen(n)}}catch(r){let e=n5(r,`Initialization of query '${tw(t.query)}' failed`);return void t.onError(e)}e.queries.set(n,i),i.ta.push(t),t.sa(e.onlineState),i.ea&&t.oa(i.ea)&&iu(e)}async function ia(e,t){let r=t.query,n=3,i=e.queries.get(r);if(i){let e=i.ta.indexOf(t);e>=0&&(i.ta.splice(e,1),0===i.ta.length?n=+!t.ra():!i.na()&&t.ra()&&(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 io(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.ta)e.oa(n)&&(r=!0);i.ea=n}}r&&iu(e)}function il(e,t,r){let n=e.queries.get(t);if(n)for(let e of n.ta)e.onError(r);e.queries.delete(t)}function iu(e){e.ia.forEach(e=>{e.next()})}(a=s||(s={}))._a="default",a.Cache="cache";class ih{constructor(e,t,r){this.query=e,this.aa=t,this.ua=!1,this.ca=null,this.onlineState="Unknown",this.options=r||{}}oa(e){if(!this.options.includeMetadataChanges){let t=[];for(let r of e.docChanges)3!==r.type&&t.push(r);e=new ie(e.query,e.docs,e.oldDocs,t,e.mutatedKeys,e.fromCache,e.syncStateChanged,!0,e.hasCachedResults)}let t=!1;return this.ua?this.la(e)&&(this.aa.next(e),t=!0):this.ha(e,this.onlineState)&&(this.Pa(e),t=!0),this.ca=e,t}onError(e){this.aa.error(e)}sa(e){this.onlineState=e;let t=!1;return this.ca&&!this.ua&&this.ha(this.ca,e)&&(this.Pa(this.ca),t=!0),t}ha(e,t){return!(e.fromCache&&this.ra())||(!this.options.Ta||"Offline"===t)&&(!e.docs.isEmpty()||e.hasCachedResults||"Offline"===t)}la(e){if(e.docChanges.length>0)return!0;let t=this.ca&&this.ca.hasPendingWrites!==e.hasPendingWrites;return!(!e.syncStateChanged&&!t)&&!0===this.options.includeMetadataChanges}Pa(e){e=ie.fromInitialDocuments(e.query,e.docs,e.mutatedKeys,e.fromCache,e.hasCachedResults),this.ua=!0,this.aa.next(e)}ra(){return this.options.source!==s.Cache}}class ic{constructor(e){this.key=e}}class id{constructor(e){this.key=e}}class im{constructor(e,t){this.query=e,this.fa=t,this.ga=null,this.hasCachedResults=!1,this.current=!1,this.pa=tD(),this.mutatedKeys=tD(),this.ya=t_(e),this.wa=new n9(this.ya)}get ba(){return this.fa}Sa(e,t){let r=t?t.Da:new n7,n=t?t.wa:this.wa,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.va(u,h)||(r.track({type:2,doc:h}),f=!0,(o&&this.ya(h,o)>0||l&&0>this.ya(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;
7){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{wa:s,Da:r,ls:a,mutatedKeys:i}}va(e,t){return e.hasLocalMutations&&t.hasCommittedMutations&&!t.hasLocalMutations}applyChanges(e,t,r,n){let i=this.wa;this.wa=e.wa,this.mutatedKeys=e.mutatedKeys;let s=e.Da.X_();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 C()}};return r(e)-r(t)})(e.type,t.type)||this.ya(e.doc,t.doc)),this.Ca(r),n=null!=n&&n;let a=t&&!n?this.Fa():[],o=0===this.pa.size&&this.current&&!n?1:0,l=o!==this.ga;return(this.ga=o,0!==s.length||l)?{snapshot:new ie(this.query,e.wa,i,s,e.mutatedKeys,0===o,l,!1,!!r&&r.resumeToken.approximateByteSize()>0),Ma:a}:{Ma:a}}sa(e){return this.current&&"Offline"===e?(this.current=!1,this.applyChanges({wa:this.wa,Da:new n7,mutatedKeys:this.mutatedKeys,ls:!1},!1)):{Ma:[]}}xa(e){return!this.fa.has(e)&&!!this.wa.has(e)&&!this.wa.get(e).hasLocalMutations}Ca(e){e&&(e.addedDocuments.forEach(e=>this.fa=this.fa.add(e)),e.modifiedDocuments.forEach(e=>{}),e.removedDocuments.forEach(e=>this.fa=this.fa.delete(e)),this.current=e.current)}Fa(){if(!this.current)return[];let e=this.pa;this.pa=tD(),this.wa.forEach(e=>{this.xa(e.key)&&(this.pa=this.pa.add(e.key))});let t=[];return e.forEach(e=>{this.pa.has(e)||t.push(new id(e))}
7),this.pa.forEach(r=>{e.has(r)||t.push(new ic(r))}),t}Oa(e){this.fa=e.gs,this.pa=tD();let t=this.Sa(e.documents);return this.applyChanges(t,!0)}Na(){return ie.fromInitialDocuments(this.query,this.wa,this.mutatedKeys,0===this.ga,this.hasCachedResults)}}let ig="SyncEngine";class ip{constructor(e,t,r){this.query=e,this.targetId=t,this.view=r}}class iy{constructor(e){this.key=e,this.Ba=!1}}class iw{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.La={},this.ka=new tT(e=>ty(e),tp),this.qa=new Map,this.Qa=new Set,this.$a=new ei(Q.comparator),this.Ka=new Map,this.Ua=new r0,this.Wa={},this.Ga=new Map,this.za=rB.Un(),this.onlineState="Unknown",this.ja=void 0}get isPrimaryClient(){return!0===this.ja}}async function iv(e,t,r=!0){let n,i=iq(e),s=i.ka.get(t);return s?(i.sharedClientState.addLocalQueryTarget(s.targetId),n=s.view.Na()):n=await iT(i,t,r,!0),n}async function i_(e,t){let r=iq(e);await iT(r,t,!0,!1)}async function iT(e,t,r,n){var i,s;let a,o=await (i=e.localStore,s=td(t),i.persistence.runTransaction("Allocate target","readwrite",e=>{let t;return i.Hr.getTargetData(e,s).next(r=>r?(t=r,X.resolve(t)):i.Hr.allocateTargetId(e).next(r=>(t=new rM(s,r,"TargetPurposeListen",e.currentSequenceNumber),i.Hr.addTargetData(e,t).next(()=>t))))}).then(e=>{let t=i.Ts.get(e.targetId);return(null===t||e.snapshotVersion.compareTo(t.snapshotVersion)>0)&&(i.Ts=i.Ts.insert(e.targetId,e),i.Is.set(s,e.targetId)),e})),l=o.targetId,u=e.sharedClientState.addLocalQueryTarget(l,r);return n&&(a=await iE(e,t,l,"current"===u,o.resumeToken)),e.isPrimaryClient&&r&&nO(e.remoteStore,o),a}async function iE(e,t,r,n,i){e.Ha=(t,r,n)=>(async function(e,t,r,n){let i=t.view.Sa(r);i.ls&&(i=await nl(e.localStore,t.query,!1).then(({documents:e})=>t.view.Sa(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 iM(e,t.targetId,o.Ma),o.snapshot})(e,t,r,n);let s=await nl(e.localStore,t,!0),a=new im(t,s.gs),o=a.Sa(s.documents),l=ra.createSynthesizedTargetChangeForCurrentChange(r,n&&"Offline"!==e.onlineState,i),u=a.applyChanges(o,e.isPrimaryClient,l);iM(e,r,u.Ma);let h=new ip(t,r,a);return e.ka.set(t,h),e.qa.has(r)?e.qa.get(r).push(t):e.qa.set(r,[t]),u.snapshot}async function iI(e,t,r){let n=e.ka.get(t),i=e.qa.get(n.targetId);if(i.length>1)return e.qa.set(n.targetId,i.filter(e=>!tp(e,t))),void e.ka.delete(t);e.isPrimaryClient?(e.sharedClientState.removeLocalQueryTarget(n.targetId),e.sharedClientState.isActiveQueryTarget(n.targetId)||await no(e.localStore,n.targetId,!1).then(()=>{e.sharedClientState.clearQueryState(n.targetId),r&&nF(e.remoteStore,n.targetId),iL(e,n.targetId)}).catch(Y)):(iL(e,n.targetId),await no(e.localStore,n.targetId,!0))}async function iC(e,t){let r=e.ka.get(t),n=e.qa.get(r.targetId);e.isPrimaryClient&&1===n.length&&(e.sharedClientState.removeLocalQueryTarget(r.targetId),nF(e.remoteStore,r.targetId))}async function ib(e,t,r){var n,i;let s=((n=e).remoteStore.remoteSyncer.applySuccessfulWrite=iD.bind(null,n),n.remoteStore.remoteSyncer.rejectFailedWrite=ik.bind(null,n),n);try{let e,n=await function(e,t){let r,n,i=U.now(),s=t.reduce((e,t)=>e.add(t.key),tD());return e.persistence.runTransaction("Locally write mutations","readwrite",a=>{let o=tE,l=tD();return e.ds.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=tV(n.transform,e||null);null!=i&&(null===r&&(r=ej.empty()),r.set(n.field,i))}return r||null}(e,r.get(e.key).overlayedDocument);null!=t&&s.push(new tJ(e.key,t,function e(t){let r=[];return er(t.fields,(t,n)=>{let i=new G([t]);if(eK(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 eu(r)}(t.value.mapValue),tG.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:tb(r)}))}(s.localStore,t);
7s.sharedClientState.addPendingMutation(n.batchId),i=n.batchId,(e=s.Wa[s.currentUser.toKey()])||(e=new ei(F)),e=e.insert(i,r),s.Wa[s.currentUser.toKey()]=e,await iF(s,n.changes),await nW(s.remoteStore)}catch(t){let e=n5(t,"Failed to persist write");r.reject(e)}}async function iS(e,t){try{let r=await function(e,t){let r=t.snapshotVersion,n=e.Ts;return e.persistence.runTransaction("Apply remote event","readwrite-primary",i=>{var s,a,o;let l,u,h=e.ds.newChangeBuffer({trackRemovals:!0});n=e.Ts;let c=[];t.targetChanges.forEach((s,a)=>{var o;let l=n.get(a);if(!l)return;c.push(e.Hr.removeMatchingKeys(i,s.removedDocuments,a).next(()=>e.Hr.addMatchingKeys(i,s.addedDocuments,a)));let u=l.withSequenceNumber(i.currentSequenceNumber);null!==t.targetMismatches.get(a)?u=u.withResumeToken(ec.EMPTY_BYTE_STRING,q.min()).withLastLimboFreeSnapshotVersion(q.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.Hr.updateTargetData(i,u))});let d=tE,f=tD();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=tD(),u=tD(),o.forEach(e=>l=l.add(e)),a.getEntries(s,l).next(e=>{let t=tE;return o.forEach((r,n)=>{let i=e.get(r);n.isFoundDocument()!==i.isFoundDocument()&&(u=u.add(r)),n.isNoDocument()&&n.version.isEqual(q.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)):_(nn,"Ignoring outdated watch update for ",r,". Current version:",i.version," Watch version:",n.version)}),{Vs:t,fs:u}})).next(e=>{d=e.Vs,f=e.fs})),!r.isEqual(q.min())){let t=e.Hr.getLastRemoteSnapshotVersion(i).next(t=>e.Hr.setTargetsMetadata(i,i.currentSequenceNumber,r));c.push(t)}return X.waitFor(c).next(()=>h.apply(i)).next(()=>e.localDocuments.getLocalViewOfDocuments(i,d,f)).next(()=>d)}).then(t=>(e.Ts=n,t))}(e.localStore,t);
7t.targetChanges.forEach((t,r)=>{let n=e.Ka.get(r);n&&(t.addedDocuments.size+t.modifiedDocuments.size+t.removedDocuments.size<=1||C(),t.addedDocuments.size>0?n.Ba=!0:t.modifiedDocuments.size>0?n.Ba||C():t.removedDocuments.size>0&&(n.Ba||C(),n.Ba=!1))}),await iF(e,r,t)}catch(e){await Y(e)}}function iA(e,t,r){var n;if(e.isPrimaryClient&&0===r||!e.isPrimaryClient&&1===r){let r,i=[];e.ka.forEach((e,r)=>{let n=r.view.sa(t);n.snapshot&&i.push(n.snapshot)}),(n=e.eventManager).onlineState=t,r=!1,n.queries.forEach((e,n)=>{for(let e of n.ta)e.sa(t)&&(r=!0)}),r&&iu(n),i.length&&e.La.p_(i),e.onlineState=t,e.isPrimaryClient&&e.sharedClientState.setOnlineState(t)}}async function iN(e,t,r){e.sharedClientState.updateQueryState(t,"rejected",r);let n=e.Ka.get(t),i=n&&n.key;if(i){let r=new ei(Q.comparator);r=r.insert(i,eH.newNoDocument(i,q.min()));let n=tD().add(i),s=new rs(q.min(),new Map,new ei(F),r,n);await iS(e,s),e.$a=e.$a.remove(i),e.Ka.delete(t),iO(e)}else await no(e.localStore,t,!1).then(()=>iL(e,t,r)).catch(Y)}async function iD(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.ds.newChangeBuffer({trackRemovals:!0});return(function(e,t,r,n){let i=r.batch,s=i.keys(),a=X.resolve();return s.forEach(e=>{a=a.next(()=>n.getEntry(t,e)).next(t=>{let s=r.docVersions.get(e);null!==s||C(),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=tD();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))}));iR(e,n,null),ix(e,n),e.sharedClientState.updateMutationState(n,"acknowledged"),await iF(e,i)}catch(e){await Y(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=>(null!==t||C(),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))}));iR(e,t,r),ix(e,t),e.sharedClientState.updateMutationState(t,"rejected",r),await iF(e,i)}catch(e){await Y(e)}}function ix(e,t){(e.Ga.get(t)||[]).forEach(e=>{e.resolve()}),e.Ga.delete(t)}function iR(e,t,r){let n=e.Wa[e.currentUser.toKey()];if(n){let i=n.get(t);i&&(r?i.reject(r):i.resolve(),n=n.remove(t)),e.Wa[e.currentUser.toKey()]=n}}function iL(e,t,r=null){for(let n of(e.sharedClientState.removeLocalQueryTarget(t),e.qa.get(t)))e.ka.delete(n),r&&e.La.Ja(n,r);e.qa.delete(t),e.isPrimaryClient&&e.Ua.Sr(t).forEach(t=>{e.Ua.containsKey(t)||iV(e,t)})}function iV(e,t){e.Qa.delete(t.path.canonicalString());let r=e.$a.get(t);null!==r&&(nF(e.remoteStore,r),e.$a=e.$a.remove(t),e.Ka.delete(r),iO(e))}function iM(e,t,r){for(let n of r)n instanceof ic?(e.Ua.addReference(n.key,t),function(e,t){let r=t.key,n=r.path.canonicalString();e.$a.get(r)||e.Qa.has(n)||(_(ig,"New document in limbo: "+r),e.Qa.add(n),iO(e))}(e,n)):n instanceof id?(_(ig,"Document no longer in limbo: "+n.key),e.Ua.removeReference(n.key,t),e.Ua.containsKey(n.key)||iV(e,n.key)):C()}function iO(e){for(;e.Qa.size>0&&e.$a.size<e.maxConcurrentLimboResolutions;){let t=e.Qa.values().next().value;e.Qa.delete(t);let r=new Q(K.fromString(t)),n=e.za.next();e.Ka.set(n,new iy(r)),e.$a=e.$a.insert(r,n),nO(e.remoteStore,new rM(td(tl(r.path)),n,"TargetPurposeLimboResolution",Z.ae))}}async function iF(e,t,r){let n=[],i=[],s=[];e.ka.isEmpty()||(e.ka.forEach((a,o)=>{s.push(e.Ha(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=ne.Yi(o.targetId,t);i.push(e)}}))}),await Promise.all(s),e.La.p_(n),await async function(e,t){try{await e.persistence.runTransaction("notifyLocalViewChanges","readwrite",r=>X.forEach(t,t=>X.forEach(t.Hi,n=>e.persistence.referenceDelegate.addReference(r,t.targetId,n)).next(()=>X.forEach(t.Ji,n=>e.persistence.referenceDelegate.removeReference(r,t.targetId,n)))))}catch(e){if(!J(e))throw e;_(nn,"Failed to update sequence numbers: "+e)}for(let r of t){let t=r.targetId;if(!r.fromCache){let r=e.Ts.get(t),n=r.snapshotVersion,i=r.withLastLimboFreeSnapshotVersion(n);e.Ts=e.Ts.insert(t,i)}}}(e.localStore,i))}async function iP(e,t){if(!e.currentUser.isEqual(t)){_(ig,"User change. New user:",t.toKey());let r=await ns(e.localStore,t);e.currentUser=t,e.Ga.forEach(e=>{e.forEach(e=>{e.reject(new S(b.CANCELLED,"'waitForPendingWrites' promise is rejected due to a user change."))})}),e.Ga.clear(),e.sharedClientState.handleUserChange(t,r.removedBatchIds,r.addedBatchIds),await iF(e,r.Rs)}}function iU(e,t){let r=e.Ka.get(t);if(r&&r.Ba)return tD().add(r.key);{let r=tD(),n=e.qa.get(t);if(!n)return r;for(let t of n){let n=e.ka.get(t);r=r.unionWith(n.view.ba)}return r}}function iq(e){return e.remoteStore.remoteSyncer.applyRemoteEvent=iS.bind(null,e),e.remoteStore.remoteSyncer.getRemoteKeysForTarget=iU.bind(null,e),e.remoteStore.remoteSyncer.rejectListen=iN.bind(null,e),e.La.p_=io.bind(null,e.eventManager),e.La.Ja=il.bind(null,e.eventManager),e}class i${constructor(){this.kind="memory",this.synchronizeTabs=!1}async initialize(e){this.serializer=nI(e.databaseInfo.databaseId),this.sharedClientState=this.Za(e),this.persistence=this.Xa(e),await this.persistence.start(),this.localStore=this.eu(e),this.gcScheduler=this.tu(e,this.localStore),this.indexBackfillerScheduler=this.nu(e,this.localStore)}tu(e,t){return null}nu(e,t){return null}eu(e){var t,r;return t=this.persistence,r=new nr,new ni(t,r,e.initialUser,this.serializer)}Xa(e){return new r8(r9.ri,this.serializer)}Za(e){return new nh}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()}}i$.provider={build:()=>new i$};class iB extends i${constructor(e){super(),this.cacheSizeBytes=e}tu(e,t){return this.persistence.referenceDelegate instanceof r7||C(),new rQ(this.persistence.referenceDelegate.garbageCollector,e.asyncQueue,t)}Xa(e){let t=void 0!==this.cacheSizeBytes?r$.withCacheSize(this.cacheSizeBytes):r$.DEFAULT;return new r8(e=>r7.ri(e,t),this.serializer)}}class iK{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=>iA(this.syncEngine,e,1),this.remoteStore.remoteSyncer.handleCredentialChange=iP.bind(null,this.syncEngine),await n3(this.remoteStore,this.syncEngine.isPrimaryClient))}createEventManager(e){return new ir}createDatastore(e){var t;let r=nI(e.databaseInfo.databaseId),n=new nT(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 nL(t,r,e.asyncQueue,e=>iA(this.syncEngine,e,0),nf.D()?new nf:new nc)}createSyncEngine(e,t){return function(e,t,r,n,i,s,a){let o=new iw(e,t,r,n,i,s);return a&&(o.ja=!0),o}(this.localStore,this.remoteStore,this.eventManager,this.sharedClientState,e.initialUser,e.maxConcurrentLimboResolutions,t)}async terminate(){var e,t;await async function(e){_(nR,"RemoteStore shutting down."),e.W_.add(5),await nM(e),e.z_.shutdown(),e.j_.set("Unknown")}(this.remoteStore),null==(e=this.datastore)||e.terminate(),null==(t=this.eventManager)||t.terminate()}}iK.provider={build:()=>new iK};class iz{constructor(e){this.observer=e,this.muted=!1}next(e){this.muted||this.observer.next&&this.iu(this.observer.next,e)}error(e){this.muted||(this.observer.error?this.iu(this.observer.error,e):T("Uncaught Error in snapshot listener:",e.toString()))}su(){this.muted=!0}iu(e,t){setTimeout(()=>{this.muted||e(t)},0)}}let iG="FirestoreClient";class iQ{constructor(e,t,r,n,i){this.authCredentials=e,this.appCheckCredentials=t,this.asyncQueue=r,this.databaseInfo=n,this.user=p.UNAUTHENTICATED,this.clientId=O.newId(),this.authCredentialListener=()=>Promise.resolve(),this.appCheckCredentialListener=()=>Promise.resolve(),this._uninitializedComponentsProvider=i,this.authCredentials.start(r,async e=>{_(iG,"Received user=",e.uid),await this.authCredentialListener(e),this.user=e}),this.appCheckCredentials.start(r,e=>(_(iG,"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 A;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=n5(r,"Failed to shutdown persistence");e.reject(t)}}),e.promise}}async function ij(e,t){e.asyncQueue.verifyOperationInProgress(),_(iG,"Initializing OfflineComponentProvider");let r=e.configuration;await t.initialize(r);let n=r.initialUser;e.setCredentialChangeListener(async e=>{n.isEqual(e)||(await ns(t.localStore,e),n=e)}),t.persistence.setDatabaseDeletedListener(()=>e.terminate()),e._offlineComponents=t}async function iH(e,t){e.asyncQueue.verifyOperationInProgress();let r=await iW(e);_(iG,"Initializing OnlineComponentProvider"),await t.initialize(r,e.configuration),e.setCredentialChangeListener(e=>n2(t.remoteStore,e)),e.setAppCheckTokenChangeListener((e,r)=>n2(t.remoteStore,r)),e._onlineComponents=t}async function iW(e){if(!e._offlineComponents)if(e._uninitializedComponentsProvider){_(iG,"Using user provided OfflineComponentProvider");try{await ij(e,e._uninitializedComponentsProvider._offline)}catch(t){if(!("FirebaseError"===t.name?t.code===b.FAILED_PRECONDITION||t.code===b.UNIMPLEMENT
7ED:!("undefined"!=typeof DOMException&&t instanceof DOMException)||22===t.code||20===t.code||11===t.code))throw t;E("Error using user provided cache. Falling back to memory cache: "+t),await ij(e,new i$)}}else _(iG,"Using default OfflineComponentProvider"),await ij(e,new iB(void 0));return e._offlineComponents}async function iY(e){return e._onlineComponents||(e._uninitializedComponentsProvider?(_(iG,"Using user provided OnlineComponentProvider"),await iH(e,e._uninitializedComponentsProvider._online)):(_(iG,"Using default OnlineComponentProvider"),await iH(e,new iK))),e._onlineComponents}async function iX(e){let t=await iY(e),r=t.eventManager;return r.onListen=iv.bind(null,t.syncEngine),r.onUnlisten=iI.bind(null,t.syncEngine),r.onFirstRemoteStoreListen=i_.bind(null,t.syncEngine),r.onLastRemoteStoreUnlisten=iC.bind(null,t.syncEngine),r}function iJ(e){let t={};return void 0!==e.timeoutSeconds&&(t.timeoutSeconds=e.timeoutSeconds),t}let iZ=new Map;function i0(e,t,r){if(!r)throw new S(b.INVALID_ARGUMENT,`Function ${e}() cannot be called with an empty ${t}.`)}function i1(e){if(!Q.isDocumentKey(e))throw new S(b.INVALID_ARGUMENT,`Invalid document reference. Document references must have an even number of segments, but ${e} has ${e.length}.`)}function i2(e){if(Q.isDocumentKey(e))throw new S(b.INVALID_ARGUMENT,`Invalid collection reference. Collection references must have an odd number of segments, but ${e} has ${e.length}.`)}function i3(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":C()}function i4(e,t){if("_delegate"in e&&(e=e._delegate),!(e instanceof t)){if(t.name===e.constructor.name)throw new S(b.INVALID_ARGUMENT,"Type does not match the expected instance. Did you pass a reference from a different Firestore SDK?");{let r=i3(e);throw new S(b.INVALID_ARGUMENT,`Expected type '${t.name}', but it was: ${r}`)}}return e}function i6(e,t){if(t<=0)throw new S(b.INVALID_ARGUMENT,`Function ${e}() requires a positive number, but it was: ${t}.`)}let i8="firestore.googleapis.com";class i5{constructor(e){var t,r;if(void 0===e.host){if(void 0!==e.ssl)throw new S(b.INVALID_ARGUMENT,"Can't provide ssl option if host option is not set");this.host=i8,this.ssl=!0}else this.host=e.host,this.ssl=null==(t=e.ssl)||t;if(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 S(b.INVALID_ARGUMENT,"cacheSizeBytes must be at least 1048576");this.cacheSizeBytes=e.cacheSizeBytes}(function(e,t,r,n){if(!0===t&&!0===n)throw new S(b.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=iJ(null!=(r=e.experimentalLongPollingOptions)?r:{}),function(e){if(void 0!==e.timeoutSeconds){if(isNaN(e.timeoutSeconds))throw new S(b.INVALID_ARGUMENT,`invalid long polling timeout: ${e.timeoutSeconds} (must not be NaN)`);if(e.timeoutSeconds<5)throw new S(b.INVALID_ARGUMENT,`invalid long polling timeout: ${e.timeoutSeconds} (minimum allowed value is 5)`);if(e.timeoutSeconds>30)throw new S(b.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 i9{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 i5({}),this._settingsFrozen=!1,this._emulatorOptions={},this._terminateTask="notTerminated"}get app(){if(!this._app)throw new S(b.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 S(b.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 i5(e),this._emulatorOptions=e.emulatorOptions||{},void 0!==e.credentials&&(this._authCredentials=function(e){if(!e)return new D;switch(e.type){case"firstParty":return new L(e.sessionIndex||"0",e.iamToken||null,e.authTokenFactory||null);case"provider":return e.client;default:throw new S(b.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=iZ.get(e);t&&(_("ComponentProvider","Removing Datastore"),iZ.delete(e),t.terminate())}(this),Promise.resolve()}}class i7{constructor(e,t,r){this.converter=t,this._query=r,this.type="query",this.firestore=e}withConverter(e){return new i7(this.firestore,e,this._query)}}class se{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 st(this.firestore,this.converter,this._key.path.popLast())}withConverter(e){return new se(this.firestore,e,this._key)}}class st extends i7{constructor(e,t,r){super(e,t,tl(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 se(this.firestore,null,new Q(e))}withConverter(e){return new st(this.firestore,e,this._path)}}function sr(e,t,...r){if(e=(0,h.Ku)(e),i0("collection","path",t),e instanceof i9){let n=K.fromString(t,...r);return i2(n),new st(e,null,n)}{if(!(e instanceof se||e instanceof st))throw new S(b.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 i2(n),new st(e.firestore,null,n)}}function sn(e,t,...r){if(e=(0,h.Ku)(e),1==arguments.length&&(t=O.newId()),i0("doc","path",t),e instanceof i9){let n=K.fromString(t,...r);return i1(n),new se(e,null,new Q(n))}{if(!(e instanceof se||e instanceof st))throw new S(b.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 i1(n),new se(e.firestore,e instanceof st?e.converter:null,new Q(n))}}let si="AsyncQueue";class ss{constructor(e=Promise.resolve()){this.Vu=[],this.mu=!1,this.fu=[],this.gu=null,this.pu=!1,this.yu=!1,this.wu=[],this.a_=new nC(this,"async_queue_retry"),this.bu=()=>{let e=nE();e&&_(si,"Visibility state changed to "+e.visibilityState),this.a_.t_()},this.Su=e;let t=nE();t&&"function"==typeof t.addEventListener&&t.addEventListener("visibilitychange",this.bu)}get isShuttingDown(){return this.mu}enqueueAndForget(e){this.enqueue(e)}enqueueAndForgetEvenWhileRestricted(e){this.Du(),this.vu(e)}enterRestrictedMode(e){if(!this.mu){this.mu=!0,this.yu=e||!1;let t=nE();t&&"function"==typeof t.removeEventListener&&t.removeEventListener("visibilitychange",this.bu)}}enqueue(e){if(this.Du(),this.mu)return new Promise(()=>{});let t=new A;return this.vu(()=>this.mu&&this.yu?Promise.resolve():(e().then(t.resolve,t.reject),t.promise)).then(()=>t.promise)}enqueueRetryable(e){this.enqueueAndForget(()=>(this.Vu.push(e),this.Cu()))}async Cu(){if(0!==this.Vu.length){try{await this.Vu[0](),this.Vu.shift(),this.a_.reset()}catch(e){if(!J(e))throw e;_(si,"Operation failed with retryable error: "+e)}this.Vu.length>0&&this.a_.Xo(()=>this.Cu())}}vu(e){let t=this.Su.then(()=>(this.pu=!0,e().catch(e=>{let t;throw this.gu=e,this.pu=!1,T("INTERNAL UNHANDLED ERROR: ",(t=e.message||"",e.stack&&(t=e.stack.includes(e.message)?e.stack:e.message+"\n"+e.stack),t)),e}).then(e=>(this.pu=!1,e))));return this.Su=t,t}enqueueAfterDelay(e,t,r){this.Du(),this.wu.indexOf(e)>-1&&(t=0);let n=n8.createAndSchedule(this,e,t,r,e=>this.Fu(e));return this.fu.push(n),n}Du(){this.gu&&C()}verifyOperationInProgress(){}async Mu(){let e;do e=this.Su,await e;while(e!==this.Su)}xu(e){for(let t of this.fu)if(t.timerId===e)return!0;return!1}Ou(e){return this.Mu().then(()=>{for(let t of(this.fu.sort((e,t)=>
7e.targetTimeMs-t.targetTimeMs),this.fu))if(t.skipDelay(),"all"!==e&&t.timerId===e)break;return this.Mu()})}Nu(e){this.wu.push(e)}Fu(e){let t=this.fu.indexOf(e);this.fu.splice(t,1)}}function sa(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 so extends i9{constructor(e,t,r,n){super(e,t,r,n),this.type="firestore",this._queue=new ss,this._persistenceKey=(null==n?void 0:n.name)||"[DEFAULT]"}async _terminate(){if(this._firestoreClient){let e=this._firestoreClient.terminate();this._queue=new ss(e),this._firestoreClient=void 0,await e}}}function sl(e,t){let r="object"==typeof e?e:(0,o.Sx)(),n=(0,o.j6)(r,"firestore").getImmediate({identifier:"string"==typeof e?e:t||eC});if(!n._initialized){let e=(0,h.yU)("firestore");e&&function(e,t,r,n={}){var i;let s=(e=i4(e,i9))._getSettings(),a=Object.assign(Object.assign({},s),{emulatorOptions:e._getEmulatorOptions()}),o=`${t}:${r}`;s.host!==i8&&s.host!==o&&E("Host has been set in both settings() and connectFirestoreEmulator(), emulator host will be used.");let l=Object.assign(Object.assign({},s),{host:o,ssl:!1,emulatorOptions:n});if(!(0,h.bD)(l,a)&&(e._setSettings(l),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 S(b.INVALID_ARGUMENT,"mockUserToken must contain 'sub' or 'user_id' field!");r=new p(s)}e._authCredentials=new k(new N(t,r))}}(n,...e)}return n}function su(e){if(e._terminated)throw new S(b.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 eI(i,s,e._persistenceKey,a.host,a.ssl,a.experimentalForceLongPolling,a.experimentalAutoDetectLongPolling,iJ(a.experimentalLongPollingOptions),a.useFetchStreams));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 iQ(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 sh{constructor(e="count",t){this._internalFieldPath=t,this.type="AggregateField",this.aggregateType=e}}class sc{constructor(e,t,r){this._userDataWriter=t,this._data=r,this.type="AggregateQuerySnapshot",this.query=e}data(){return this._userDataWriter.convertObjectMap(this._data)}}class sd{constructor(e){this._byteString=e}static fromBase64String(e){try{return new sd(ec.fromBase64String(e))}catch(e){throw new S(b.INVALID_ARGUMENT,"Failed to construct data from Base64 string: "+e)}}static fromUint8Array(e){return new sd(ec.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)}}class sf{constructor(...e){for(let t=0;t<e.length;++t)if(0===e[t].length)throw new S(b.INVALID_ARGUMENT,"Invalid field name at argument $(i + 1). Field names must not be empty.");this._internalPath=new G(e)}isEqual(e){return this._internalPath.isEqual(e._internalPath)}}class sm{constructor(e){this._methodName=e}}class sg{constructor(e,t){if(!isFinite(e)||e<-90||e>90)throw new S(b.INVALID_ARGUMENT,"Latitude must be a number between -90 and 90, but was: "+e);if(!isFinite(t)||t<-180||t>180)throw new S(b.INVALID_ARGUMENT,"Longitude must be a number between -180 and 180, but was: "+t);this._lat=e,this._long=t}get latitude(){return this._lat}get longitude(){return this._long}isEqual(e){return this._lat===e._lat&&this._long===e._long}toJSON(){return{latitude:this._lat,longitude:this._long}}_compareTo(e){return F(this._lat,e._lat)||F(this._long,e._long)}}class sp{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)}}let sy=/^__.*__$/;class sw{constructor(e,t,r){this.data=e,this.fieldMask=t,this.fieldTransforms=r}toMutation(e,t){return null!==this.fieldMask?new tJ(e,this.data,this.fieldMask,t,this.fieldTransforms):new tX(e,this.data,t,this.fieldTransforms)}}class sv{constructor(e,t,r){this.data=e,this.fieldMask=t,this.fieldTransforms=r}toMutation(e,t){return new tJ(e,this.data,this.fieldMask,t,this.fieldTransforms)}}function s_(e){switch(e){case 0:case 2:case 1:return!0;case 3:case 4:return!1;default:throw C()}}class sT{constructor(e,t,r,n,i,s){this.settings=e,this.databaseId=t,this.serializer
7=r,this.ignoreUndefinedProperties=n,void 0===i&&this.Bu(),this.fieldTransforms=i||[],this.fieldMask=s||[]}get path(){return this.settings.path}get Lu(){return this.settings.Lu}ku(e){return new sT(Object.assign(Object.assign({},this.settings),e),this.databaseId,this.serializer,this.ignoreUndefinedProperties,this.fieldTransforms,this.fieldMask)}qu(e){var t;let r=null==(t=this.path)?void 0:t.child(e),n=this.ku({path:r,Qu:!1});return n.$u(e),n}Ku(e){var t;let r=null==(t=this.path)?void 0:t.child(e),n=this.ku({path:r,Qu:!1});return n.Bu(),n}Uu(e){return this.ku({path:void 0,Qu:!0})}Wu(e){return sV(e,this.settings.methodName,this.settings.Gu||!1,this.path,this.settings.zu)}contains(e){return void 0!==this.fieldMask.find(t=>e.isPrefixOf(t))||void 0!==this.fieldTransforms.find(t=>e.isPrefixOf(t.field))}Bu(){if(this.path)for(let e=0;e<this.path.length;e++)this.$u(this.path.get(e))}$u(e){if(0===e.length)throw this.Wu("Document fields must not be empty");if(s_(this.Lu)&&sy.test(e))throw this.Wu('Document fields cannot begin and end with "__"')}}class sE{constructor(e,t,r){this.databaseId=e,this.ignoreUndefinedProperties=t,this.serializer=r||nI(e)}ju(e,t,r,n=!1){return new sT({Lu:e,methodName:t,zu:r,path:G.emptyPath(),Qu:!1,Gu:n},this.databaseId,this.serializer,this.ignoreUndefinedProperties)}}function sI(e){let t=e._freezeSettings(),r=nI(e._databaseId);return new sE(e._databaseId,!!t.ignoreUndefinedProperties,r)}class sC extends sm{_toFieldTransform(e){if(2!==e.Lu)throw 1===e.Lu?e.Wu(`${this._methodName}() can only appear at the top level of your update data`):e.Wu(`${this._methodName}() cannot be used with set() unless you pass {merge:true}`);return e.fieldMask.push(e.path),null}isEqual(e){return e instanceof sC}}class sb extends sm{constructor(e,t){super(e),this.Hu=t}_toFieldTransform(e){let t=new sT({Lu:3,zu:e.settings.zu,methodName:this._methodName,Qu:!0},e.databaseId,e.serializer,e.ignoreUndefinedProperties),r=new tO(this.Hu.map(e=>sA(e,t)));return new tK(e.path,r)}isEqual(e){return e instanceof sb&&(0,h.bD)(this.Hu,e.Hu)}}function sS(e,t,r,n=!1){return sA(r,e.ju(n?4:3,t))}function sA(e,t){if(sD(e=(0,h.Ku)(e)))return sk("Unsupported field value:",t,e),sN(e,t);if(e instanceof sm)return function(e,t){if(!s_(t.Lu))throw t.Wu(`${e._methodName}() can only be used with update() and set()`);if(!t.path)throw t.Wu(`${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.Qu&&4!==t.Lu)throw t.Wu("Nested arrays are not supported");let r=[],n=0;for(let i of e){let e=sA(i,t.Uu(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)&&!ee(i)&&i<=Number.MAX_SAFE_INTEGER&&i>=Number.MIN_SAFE_INTEGER?tR(n):tx(r,n);if("boolean"==typeof e)return{booleanValue:e};if("string"==typeof e)return{stringValue:e};if(e instanceof Date){let r=U.fromDate(e);return{timestampValue:rv(t.serializer,r)}}if(e instanceof U){let r=new U(e.seconds,1e3*Math.floor(e.nanoseconds/1e3));return{timestampValue:rv(t.serializer,r)}}if(e instanceof sg)return{geoPointValue:{latitude:e.latitude,longitude:e.longitude}};if(e instanceof sd)return{bytesValue:r_(t.serializer,e._byteString)};if(e instanceof se){let r=t.databaseId,n=e.firestore._databaseId;if(!n.isEqual(r))throw t.Wu(`Document reference is for database ${n.projectId}/${n.database} but should be for database ${r.projectId}/${r.database}`);return{referenceValue:rE(e.firestore._databaseId||t.databaseId,e._key.path)}}if(e instanceof sp)return{mapValue:{fields:{[eS]:{stringValue:eD},[ek]:{arrayValue:{values:e.toArray().map(e=>{if("number"!=typeof e)throw t.Wu("VectorValues must only contain numeric values.");return tx(t.serializer,e)})}}}}};throw t.Wu(`Unsupported field value: ${i3(e)}`)}(e,t)}function sN(e,t){let r={};return en(e)?t.path&&t.path.length>0&&t.fieldMask.push(t.path):er(e,(e,n)=>{let i=sA(n,t.qu(e));null!=i&&(r[e]=i)}),{mapValue:{fields:r}}}function sD(e){return!("object"!=typeof e||null===e||e instanceof Array||e instanceof Date||e instanceof U||e instanceof sg||e instanceof sd||e instanceof se||e instanceof sm||e instanceof sp)}function sk(e,t,r){if(!sD(r)||"object"!=typeof r||null===r||Object.getPrototypeOf(r)!==Object.prototype&&null!==Object.getPrototypeOf(r)){let n=i3(r);throw"an object"===n?t.Wu(e+" a custom object"):t.Wu(e+" "+n)}}function sx(e,t,r){if((t=(0,h.Ku)(t))instanceof sf)return t._internalPath;if("string"==typeof t)return sL(e,t);throw sV("Field path arguments must be of type string or ",e,!1,void 0,r)}let sR=RegExp("[~\\*/\\[\\]]");function sL(e,t,r){if(t.search(sR)>=0)throw sV(`Invalid field path (${t}). Paths must not contain '~', '*', '/', '[', or ']'`,e,!1,void 0,r);try{return new sf(...t.split("."))._internalPath}catch(n){throw sV(`Invalid field path (${t}). Paths must not be empty, begin with '.', end with '.', or contain '..'`,e,!1,void 0,r)}}function sV(e,t,r,n,i){let s=n&&!n.isEmpty(),a=void 0!==i,o=`Function ${t}
7() 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 S(b.INVALID_ARGUMENT,o+e+l)}function sM(e,t){return e.some(e=>e.isEqual(t))}class sO{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 se(this._firestore,this._converter,this._key)}exists(){return null!==this._document}data(){if(this._document){if(this._converter){let e=new sF(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(sP("DocumentSnapshot.get",e));if(null!==t)return this._userDataWriter.convertValue(t)}}}class sF extends sO{data(){return super.data()}}function sP(e,t){return"string"==typeof t?sL(e,t):t instanceof sf?t._internalPath:t._delegate._internalPath}function sU(e){if("L"===e.limitType&&0===e.explicitOrderBy.length)throw new S(b.UNIMPLEMENTED,"limitToLast() queries require specifying at least one orderBy() clause")}class sq{}class s$ extends sq{}function sB(e,t,...r){let n=[];for(let i of(t instanceof sq&&n.push(t),function(e){let t=e.filter(e=>e instanceof sG).length,r=e.filter(e=>e instanceof sK).length;if(t>1||t>0&&r>0)throw new S(b.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 sK extends s${constructor(e,t,r){super(),this._field=e,this._op=t,this._value=r,this.type="where"}static _create(e,t,r){return new sK(e,t,r)}_apply(e){let t=this._parse(e);return s8(e._query,t),new i7(e.firestore,e.converter,tm(e._query,t))}_parse(e){let t=sI(e.firestore);return function(e,t,r,n,i,s,a){let o;if(i.isKeyField()){if("array-contains"===s||"array-contains-any"===s)throw new S(b.INVALID_ARGUMENT,`Invalid Query. You can't perform '${s}' queries on documentId().`);if("in"===s||"not-in"===s){s6(a,s);let t=[];for(let r of a)t.push(s4(n,e,r));o={arrayValue:{values:t}}}else o=s4(n,e,a)}else"in"!==s&&"not-in"!==s&&"array-contains-any"!==s||s6(a,s),o=sS(r,t,a,"in"===s||"not-in"===s);return e0.create(i,s,o)}(e._query,"where",t,e.firestore._databaseId,this._field,this._op,this._value)}}function sz(e,t,r){let n=sP("where",e);return sK._create(n,t,r)}class sG extends sq{constructor(e,t){super(),this.type=e,this._queryConstraints=t}static _create(e,t){return new sG(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]:e1.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())s8(r,e),r=tm(r,e)}(e._query,t),new i7(e.firestore,e.converter,tm(e._query,t)))}_getQueryConstraints(){return this._queryConstraints}_getOperator(){return"and"===this.type?"and":"or"}}function sQ(...e){return e.forEach(e=>s5("or",e)),sG._create("or",e)}function sj(...e){return e.forEach(e=>s5("and",e)),sG._create("and",e)}class sH extends s${constructor(e,t){super(),this._field=e,this._direction=t,this.type="orderBy"}static _create(e,t){return new sH(e,t)}_apply(e){let t=function(e,t,r){if(null!==e.startAt)throw new S(b.INVALID_ARGUMENT,"Invalid query. You must not call startAt() or startAfter() before calling orderBy().");if(null!==e.endAt)throw new S(b.INVALID_ARGUMENT,"Invalid query. You must not call endAt() or endBefore() before calling orderBy().");return new eJ(t,r)}(e._query,this._field,this._direction);return new i7(e.firestore,e.converter,function(e,t){let r=e.explicitOrderBy.concat([t]);return new to(e.path,e.collectionGroup,r,e.filters.slice(),e.limit,e.limitType,e.startAt,e.endAt)}(e._query,t))}}function sW(e,t="asc"){let r=sP("orderBy",e);return sH._create(r,t)}class sY extends s${constructor(e,t,r){super(),this.type=e,this._limit=t,this._limitType=r}static _create(e,t,r){return new sY(e,t,r)}_apply(e){return new i7(e.firestore,e.converter,tg(e._query,this._limit,this._limitType))}}function sX(e){return i6("limit",e),sY._create("limit",e,"F")}function sJ(e){return i6("limitToLast",e),sY._create("limitToLast",e,"L")}class sZ extends s${constructor(e,t,r){super(),this.type=e,this._docOrFields=t,this._inclusive=r}static _create(e,t,r){return new sZ(e,t,r)}_apply(e){var t;let r=s3(e,this.type,this._docOrFields,this._inclusive);return new i7(e.firestore,e.converter,(t=e._query,new to(t.path,t.collectionGroup,t.explicitOrderBy.slice(),t.filters.slice(),t.limit,t.limitType,r,t.endAt)))}}function s0(...e){return sZ._create("startAfter",e,!1)}class s1 extends s${constructor(e,t,r){super(),this.type=e,this._docOrFields=t,this._inclusive=r}static _create(e,t,r){return new s1(e,t,r)}_apply(e){var t;let r=s3(e,this.type,this._docOrFields,this._inclusive);return new i7(e.firestore,e.converter,(t=e._query,new to(t.path,t.collectionGroup,t.explicitOrderBy.slice(),t.filters.slice(),t.limit,t.limitType,t.startAt,r)))}}function s2(...e){return s1._create("endAt",e,!0)}function s3(e,t,r,n){if(r[0]=(0,h.Ku)(r[0]),r[0]instanceof sO)return function(e,t,r,n,i){if(!n)throw new S(b.NOT_FOUND,`Can't use a DocumentSnapshot that doesn't exist for ${r}().`);let s=[];for(let r of tc(e))if(r.field.isKeyField())s.push(eP(t,n.key));else{let e=n.data.field(r.field);if(e_(e))throw new S(b.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 S(b.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 eW(s,i)}(e._query,e.firestore._databaseId,t,r[0]._document,n);{let i=sI(e.firestore);return function(e,t,r,n,i,s){let a=e.explicitOrderBy;if(i.length>a.length)throw new S(b.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];
7if(a[s].field.isKeyField()){if("string"!=typeof l)throw new S(b.INVALID_ARGUMENT,`Invalid query. Expected a string for document ID in ${n}(), but got a ${typeof l}`);if(!th(e)&&-1!==l.indexOf("/"))throw new S(b.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(!Q.isDocumentKey(r))throw new S(b.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}' is not because it contains an odd number of segments.`);let i=new Q(r);o.push(eP(t,i))}else{let e=sS(r,n,l);o.push(e)}}return new eW(o,s)}(e._query,e.firestore._databaseId,i,t,r,n)}}function s4(e,t,r){if("string"==typeof(r=(0,h.Ku)(r))){if(""===r)throw new S(b.INVALID_ARGUMENT,"Invalid query. When querying with documentId(), you must provide a valid document ID, but it was an empty string.");if(!th(t)&&-1!==r.indexOf("/"))throw new S(b.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(!Q.isDocumentKey(n))throw new S(b.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 eP(e,new Q(n))}if(r instanceof se)return eP(e,r._key);throw new S(b.INVALID_ARGUMENT,`Invalid query. When querying with documentId(), you must provide a valid string or a DocumentReference, but it was: ${i3(r)}.`)}function s6(e,t){if(!Array.isArray(e)||0===e.length)throw new S(b.INVALID_ARGUMENT,`Invalid Query. A non-empty array is required for '${t.toString()}' filters.`)}function s8(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 S(b.INVALID_ARGUMENT,`Invalid query. You cannot use more than one '${t.op.toString()}' filter.`):new S(b.INVALID_ARGUMENT,`Invalid query. You cannot use '${t.op.toString()}' filters with '${r.toString()}' filters.`)}function s5(e,t){if(!(t instanceof sK||t instanceof sG))throw new S(b.INVALID_ARGUMENT,`Function ${e}() requires AppliableConstraints created with a call to 'where(...)', 'or(...)', or 'and(...)'.`)}class s9{convertValue(e,t="none"){switch(ex(e)){case 0:return null;case 1:return e.booleanValue;case 2:return em(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(eg(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 C()}}convertObject(e,t){return this.convertObjectMap(e.fields,t)}convertObjectMap(e,t="none"){let r={};return er(e,(e,n)=>{r[e]=this.convertValue(n,t)}),r}convertVectorValue(e){var t,r,n;return new sp(null==(n=null==(r=null==(t=e.fields)?void 0:t[ek].arrayValue)?void 0:r.values)?void 0:n.map(e=>em(e.doubleValue)))}convertGeoPoint(e){return new sg(em(e.latitude),em(e.longitude))}convertArray(e,t){return(e.values||[]).map(e=>this.convertValue(e,t))}convertServerTimestamp(e,t){switch(t){case"previous":let r=eT(e);return null==r?null:this.convertValue(r,t);case"estimate":return this.convertTimestamp(eE(e));default:return null}}convertTimestamp(e){let t=ef(e);return new U(t.seconds,t.nanos)}convertDocumentKey(e,t){let r=K.fromString(e);rV(r)||C();let n=new eb(r.get(1),r.get(3)),i=new Q(r.popFirst(5));return n.isEqual(t)||T(`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}}class s7{constructor(e,t){this.hasPendingWrites=e,this.fromCache=t}isEqual(e){return this.hasPendingWrites===e.hasPendingWrites&&this.fromCache===e.fromCache}}class ae extends sO{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 at(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(sP("DocumentSnapshot.get",e));if(null!==r)return this._userDataWriter.convertValue(r,t.serverTimestamps)}}}class at extends ae{data(e={}){return super.data(e)}}class ar{constructor(e,t,r,n){this._firestore=e,this._userDataWriter=t,this._snapshot=n,this.metadata=new s7(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 at(this._firestore,this._userDataWriter,r.key,r,new s7(this._snapshot.mutatedKeys.has(r.key),this._snapshot.fromCache),this.query.converter))})}
7docChanges(e={}){let t=!!e.includeMetadataChanges;if(t&&this._snapshot.excludesMetadataChanges)throw new S(b.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 at(e._firestore,e._userDataWriter,r.doc.key,r.doc,new s7(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 at(e._firestore,e._userDataWriter,t.doc.key,t.doc,new s7(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 C()}}(t.type),doc:n,oldIndex:i,newIndex:s}})}}(this,t),this._cachedChangesIncludeMetadataChanges=t),this._cachedChanges}}function an(e){e=i4(e,se);let t=i4(e.firestore,so);return(function(e,t,r={}){let n=new A;return e.asyncQueue.enqueueAndForget(async()=>(function(e,t,r,n,i){let s=new iz({next:o=>{s.su(),t.enqueueAndForget(()=>ia(e,a));let l=o.docs.has(r);!l&&o.fromCache?i.reject(new S(b.UNAVAILABLE,"Failed to get document because the client is offline.")):l&&o.fromCache&&n&&"server"===n.source?i.reject(new S(b.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 ih(tl(r.path),s,{includeMetadataChanges:!0,Ta:!0});return is(e,a)})(await iX(e),e.asyncQueue,t,r,n)),n.promise})(su(t),e._key).then(r=>ac(t,e,r))}class ai extends s9{constructor(e){super(),this.firestore=e}convertBytes(e){return new sd(e)}convertReference(e){let t=this.convertDocumentKey(e,this.firestore._databaseId);return new se(this.firestore,null,t)}}function as(e){e=i4(e,i7);let t=i4(e.firestore,so),r=su(t),n=new ai(t);return sU(e._query),(function(e,t,r={}){let n=new A;return e.asyncQueue.enqueueAndForget(async()=>(function(e,t,r,n,i){let s=new iz({next:r=>{s.su(),t.enqueueAndForget(()=>ia(e,a)),r.fromCache&&"server"===n.source?i.reject(new S(b.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 ih(r,s,{includeMetadataChanges:!0,Ta:!0});return is(e,a)})(await iX(e),e.asyncQueue,t,r,n)),n.promise})(r,e._query).then(r=>new ar(t,n,e,r))}function aa(e,t,r){var n;e=i4(e,se);let i=i4(e.firestore,so),s=(n=e.converter,n?r&&(r.merge||r.mergeFields)?n.toFirestore(t,r):n.toFirestore(t):t);return ah(i,[(function(e,t,r,n,i,s={}){let a,o,l=e.ju(s.merge||s.mergeFields?2:0,t,r,i);sk("Data must be an object, but it was:",l,n);let u=sN(n,l);if(s.merge)a=new eu(l.fieldMask),o=l.fieldTransforms;else if(s.mergeFields){let e=[];for(let n of s.mergeFields){let i=sx(t,n,r);if(!l.contains(i))throw new S(b.INVALID_ARGUMENT,`Field '${i}' is specified in your field mask but missing from your input data.`);sM(e,i)||e.push(i)}a=new eu(e),o=l.fieldTransforms.filter(e=>a.covers(e.field))}else a=null,o=l.fieldTransforms;return new sw(new ej(u),a,o)})(sI(i),"setDoc",e._key,s,null!==e.converter,r).toMutation(e._key,tG.none())])}function ao(e,t,r,...n){e=i4(e,se);let i=i4(e.firestore,so),s=sI(i);return ah(i,[("string"==typeof(t=(0,h.Ku)(t))||t instanceof sf?function(e,t,r,n,i,s){let a=e.ju(1,t,r),o=[sx(t,n,r)],l=[i];if(s.length%2!=0)throw new S(b.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(sx(t,s[e])),l.push(s[e+1]);let u=[],c=ej.empty();for(let e=o.length-1;e>=0;
7--e)if(!sM(u,o[e])){let t=o[e],r=l[e];r=(0,h.Ku)(r);let n=a.Ku(t);if(r instanceof sC)u.push(t);else{let e=sA(r,n);null!=e&&(u.push(t),c.set(t,e))}}return new sv(c,new eu(u),a.fieldTransforms)}(s,"updateDoc",e._key,t,r,n):function(e,t,r,n){let i=e.ju(1,t,r);sk("Data must be an object, but it was:",i,n);let s=[],a=ej.empty();return er(n,(e,n)=>{let o=sL(t,e,r);n=(0,h.Ku)(n);let l=i.Ku(o);if(n instanceof sC)s.push(o);else{let e=sA(n,l);null!=e&&(s.push(o),a.set(o,e))}}),new sv(a,new eu(s),i.fieldTransforms)}(s,"updateDoc",e._key,t)).toMutation(e._key,tG.exists(!0))])}function al(e){return ah(i4(e.firestore,so),[new t2(e._key,tG.none())])}function au(e,...t){let r,n,i;e=(0,h.Ku)(e);let s={includeMetadataChanges:!1,source:"default"},a=0;"object"!=typeof t[0]||sa(t[a])||(s=t[a],a++);let o={includeMetadataChanges:s.includeMetadataChanges,source:s.source};if(sa(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 se)n=i4(e.firestore,so),i=tl(e._key.path),r={next:r=>{t[a]&&t[a](ac(n,e,r))},error:t[a+1],complete:t[a+2]};else{let s=i4(e,i7);n=i4(s.firestore,so),i=s._query;let o=new ai(n);r={next:e=>{t[a]&&t[a](new ar(n,o,s,e))},error:t[a+1],complete:t[a+2]},sU(e._query)}var l,u,c,d=su(n),f=i;let m=new iz(r),g=new ih(f,m,o);return d.asyncQueue.enqueueAndForget(async()=>is(await iX(d),g)),()=>{m.su(),d.asyncQueue.enqueueAndForget(async()=>ia(await iX(d),g))}}function ah(e,t){var r=su(e);let n=new A;return r.asyncQueue.enqueueAndForget(async()=>ib(await iY(r).then(e=>e.syncEngine),t,n)),n.promise}function ac(e,t,r){let n=r.docs.get(t._key),i=new ai(e);return new ae(e,i,t._key,n,new s7(r.hasPendingWrites,r.fromCache),t.converter)}function ad(e){return function(e,t){let r=i4(e.firestore,so),n=su(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 t5(t,e.aggregateType,e._internalFieldPath));return(function(e,t,r){let n=new A;return e.asyncQueue.enqueueAndForget(async()=>{try{let i=await iY(e).then(e=>e.datastore);n.resolve(async function(e,t,r){var n;let{request:i,Pt:s,parent:a}=function(e,t,r,n){let{ht:i,parent:s}=rx(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:rR(e.fieldPath)}}):"sum"===e.aggregateType&&o.push({alias:t,sum:{field:rR(e.fieldPath)}})}),{request:{structuredAggregationQuery:{aggregations:o,structuredQuery:i.structuredQuery},parent:i.parent},Pt:a,parent:s}}(e.serializer,(t.Te||(t.Te=tf(t,t.explicitOrderBy)),t.Te),r);e.connection.fo||delete i.parent;let o=(await e.Co("RunAggregationQuery",e.serializer.databaseId,a,i,1)).filter(e=>!!e.result);1===o.length||C();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 sc(e,new ai(r),t))}(e,{count:new sh("count")})}function af(...e){return new sb("arrayUnion",e)}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 so(new x(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 S(b.INVALID_ARGUMENT,'"projectId" not provided in firebase.initializeApp.');return new eb(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.