123 |
- import{_registerComponent as t,registerVersion as e,_getProvider as n,getApp as r,_removeServiceInstance as s,SDK_VERSION as i}from"https://www.gstatic.com/firebasejs/9.23.0/firebase-app.js";const o=function(t){const e=[];let n=0;for(let r=0;r<t.length;r++){let s=t.charCodeAt(r);s<128?e[n++]=s:s<2048?(e[n++]=s>>6|192,e[n++]=63&s|128):55296==(64512&s)&&r+1<t.length&&56320==(64512&t.charCodeAt(r+1))?(s=65536+((1023&s)<<10)+(1023&t.charCodeAt(++r)),e[n++]=s>>18|240,e[n++]=s>>12&63|128,e[n++]=s>>6&63|128,e[n++]=63&s|128):(e[n++]=s>>12|224,e[n++]=s>>6&63|128,e[n++]=63&s|128)}return e},a={byteToCharMap_:null,charToByteMap_:null,byteToCharMapWebSafe_:null,charToByteMapWebSafe_:null,ENCODED_VALS_BASE:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",get ENCODED_VALS(){return this.ENCODED_VALS_BASE+"+/="},get ENCODED_VALS_WEBSAFE(){return this.ENCODED_VALS_BASE+"-_."},HAS_NATIVE_SUPPORT:"function"==typeof atob,encodeByteArray(t,e){if(!Array.isArray(t))throw Error("encodeByteArray takes an array as a parameter");this.init_();const n=e?this.byteToCharMapWebSafe_:this.byteToCharMap_,r=[];for(let e=0;e<t.length;e+=3){const s=t[e],i=e+1<t.length,o=i?t[e+1]:0,a=e+2<t.length,u=a?t[e+2]:0,l=s>>2,c=(3&s)<<4|o>>4;let h=(15&o)<<2|u>>6,d=63&u;a||(d=64,i||(h=64)),r.push(n[l],n[c],n[h],n[d])}return r.join("")},encodeString(t,e){return this.HAS_NATIVE_SUPPORT&&!e?btoa(t):this.encodeByteArray(o(t),e)},decodeString(t,e){return this.HAS_NATIVE_SUPPORT&&!e?atob(t):function(t){const e=[];let n=0,r=0;for(;n<t.length;){const s=t[n++];if(s<128)e[r++]=String.fromCharCode(s);else if(s>191&&s<224){const i=t[n++];e[r++]=String.fromCharCode((31&s)<<6|63&i)}else if(s>239&&s<365){const i=((7&s)<<18|(63&t[n++])<<12|(63&t[n++])<<6|63&t[n++])-65536;e[r++]=String.fromCharCode(55296+(i>>10)),e[r++]=String.fromCharCode(56320+(1023&i))}else{const i=t[n++],o=t[n++];e[r++]=String.fromCharCode((15&s)<<12|(63&i)<<6|63&o)}}return e.join("")}(this.decodeStringToByteArray(t,e))},decodeStringToByteArray(t,e){this.init_();const n=e?this.charToByteMapWebSafe_:this.charToByteMap_,r=[];for(let e=0;e<t.length;){const s=n[t.charAt(e++)],i=e<t.length?n[t.charAt(e)]:0;++e;const o=e<t.length?n[t.charAt(e)]:64;++e;const a=e<t.length?n[t.charAt(e)]:64;if(++e,null==s||null==i||null==o||null==a)throw new u;const l=s<<2|i>>4;if(r.push(l),64!==o){const t=i<<4&240|o>>2;if(r.push(t),64!==a){const t=o<<6&192|a;r.push(t)}}}return r},init_(){if(!this.byteToCharMap_){this.byteToCharMap_={},this.charToByteMap_={},this.byteToCharMapWebSafe_={},this.charToByteMapWebSafe_={};for(let t=0;t<this.ENCODED_VALS.length;t++)this.byteToCharMap_[t]=this.ENCODED_VALS.charAt(t),this.charToByteMap_[this.byteToCharMap_[t]]=t,this.byteToCharMapWebSafe_[t]=this.ENCODED_VALS_WEBSAFE.charAt(t),this.charToByteMapWebSafe_[this.byteToCharMapWebSafe_[t]]=t,t>=this.ENCODED_VALS_BASE.length&&(this.charToByteMap_[this.ENCODED_VALS_WEBSAFE.charAt(t)]=t,this.charToByteMapWebSafe_[this.ENCODED_VALS.charAt(t)]=t)}}};class u extends Error{constructor(){super(...arguments),this.name="DecodeBase64StringError"}}const l=function(t){return function(t){const e=o(t);return a.encodeByteArray(e,!0)}(t).replace(/\./g,"")};const c=()=>function(){if("undefined"!=typeof self)return self;if("undefined"!=typeof window)return window;if("undefined"!=typeof global)return global;throw new Error("Unable to locate global object.")}().__FIREBASE_DEFAULTS__,h=()=>{if("undefined"==typeof document)return;let t;try{t=document.cookie.match(/__FIREBASE_DEFAULTS__=([^;]+)/)}catch(t){return}const e=t&&function(t){try{return a.decodeString(t,!0)}catch(t){console.error("base64Decode failed: ",t)}return null}(t[1]);return e&&JSON.parse(e)},d=()=>{try{return c()||(()=>{if("undefined"==typeof process||void 0===process.env)return;const t=process.env.__FIREBASE_DEFAULTS__;return t?JSON.parse(t):void 0})()||h()}catch(t){return void console.info(`Unable to get __FIREBASE_DEFAULTS__ due to: ${t}`)}},f=t=>{const e=(t=>{var e,n;return null===(n=null===(e=d())||void 0===e?void 0:e.emulatorHosts)||void 0===n?void 0:n[t]})(t);if(!e)return;const n=e.lastIndexOf(":");if(n<=0||n+1===e.length)throw new Error(`Invalid host ${e} with no separate hostname and port!`);const r=parseInt(e.substring(n+1),10);return"["===e[0]?[e.substring(1,n-1),r]:[e.substring(0,n),r]};class p extends Error{constructor(t,e,n){super(e),this.code=t,this.customData=n,this.name="FirebaseError",Object.setPrototypeOf(this,p.prototype),Error.captureStackTrace&&Error.captureStackTrace(this,m.prototype.create)}}class m{constructor(t,e,n){this.service=t,this.serviceName=e,this.errors=n}create(t,...e){const n=e[0]||{},r=`${this.service}/${t}`,s=this.errors[t],i=s?function(t,e){return t.replace(g,((t,n)=>{const r=e[n];return null!=r?String(r):`<${n}?>`}))}(s,n):"Error",o=`${this.serviceName}: ${i} (${r}).`;return new p(r,o,n)}}const g=/\{\$([^}]+)}/g;function y(t,e){if(t===e)return!0;const n=Object.keys(t),r=Object.keys(e);for(const s of n){if(!r.includes(s))return!1;const n=t[s],i=e[s];if(w(n)&&w(i)){if(!y(n,i))return!1}else if(n!==i)return!1}for(const t of r)if(!n.includes(t))return!1;return!0}function w(t){return null!==t&&"object"==typeof t}function _(t){return t&&t._delegate?t._delegate:t}var v;!function(t){t[t.DEBUG=0]="DEBUG",t[t.VERBOSE=1]="VERBOSE",t[t.INFO=2]="INFO",t[t.WARN=3]="WARN",t[t.ERROR=4]="ERROR",t[t.SILENT=5]="SILENT"}(v||(v={}));const b={debug:v.DEBUG,verbose:v.VERBOSE,info:v.INFO,warn:v.WARN,error:v.ERROR,silent:v.SILENT},E=v.INFO,T={[v.DEBUG]:"log",[v.VERBOSE]:"log",[v.INFO]:"info",[v.WARN]:"warn",[v.ERROR]:"error"},S=(t,e,...n)=>{if(e<t.logLevel)return;const r=(new Date).toISOString(),s=T[e];if(!s)throw new Error(`Attempted to log a message with an invalid logType (value: ${e})`);console[s](`[${r}] ${t.name}:`,...n)};class A{constructor(t){this.uid=t}isAuthenticated(){return null!=this.uid}toKey(){return this.isAuthenticated()?"uid:"+this.uid:"anonymous-user"}isEqual(t){return t.uid===this.uid}}A.UNAUTHENTICATED=new A(null),A.GOOGLE_CREDENTIALS=new A("google-credentials-uid"),A.FIRST_PARTY=new A("first-party-uid"),A.MOCK_USER=new A("mock-user");let I="9.23.0";const k=new class{constructor(t){this.name=t,this._logLevel=E,this._logHandler=S,this._userLogHandler=null}get logLevel(){return this._logLevel}set logLevel(t){if(!(t in v))throw new TypeError(`Invalid value "${t}" assigned to \`logLevel\``);this._logLevel=t}setLogLevel(t){this._logLevel="string"==typeof t?b[t]:t}get logHandler(){return this._logHandler}set logHandler(t){if("function"!=typeof t)throw new TypeError("Value assigned to `logHandler` must be a function");this._logHandler=t}get userLogHandler(){return this._userLogHandler}set userLogHandler(t){this._userLogHandler=t}debug(...t){this._userLogHandler&&this._userLogHandler(this,v.DEBUG,...t),this._logHandler(this,v.DEBUG,...t)}log(...t){this._userLogHandler&&this._userLogHandler(this,v.VERBOSE,...t),this._logHandler(this,v.VERBOSE,...t)}info(...t){this._userLogHandler&&this._userLogHandler(this,v.INFO,...t),this._logHandler(this,v.INFO,...t)}warn(...t){this._userLogHandler&&this._userLogHandler(this,v.WARN,...t),this._logHandler(this,v.WARN,...t)}error(...t){this._userLogHandler&&this._userLogHandler(this,v.ERROR,...t),this._logHandler(this,v.ERROR,...t)}}("@firebase/firestore");function F(t){k.setLogLevel(t)}function D(t,...e){if(k.logLevel<=v.DEBUG){const n=e.map(R);k.debug(`Firestore (${I}): ${t}`,...n)}}function N(t,...e){if(k.logLevel<=v.ERROR){const n=e.map(R);k.error(`Firestore (${I}): ${t}`,...n)}}function V(t,...e){if(k.logLevel<=v.WARN){const n=e.map(R);k.warn(`Firestore (${I}): ${t}`,...n)}}function R(t){if("string"==typeof t)return t;try{return e=t,JSON.stringify(e)}catch(e){return t}var e}function O(t="Unexpected state"){const e=`FIRESTORE (${I}) INTERNAL ASSERTION FAILED: `+t;throw N(e),new Error(e)}function x(t,e){t||O()}function P(t,e){return t}const C="cancelled",q="unknown",L="invalid-argument",M="deadline-exceeded",B="not-found",$="permission-denied",U="unauthenticated",j="resource-exhausted",z="failed-precondition",H="aborted",W="out-of-range",G="unimplemented",Q="internal",K="unavailable";class Y extends p{constructor(t,e){super(t,e),this.code=t,this.message=e,this.toString=()=>`${this.name}: [code=${this.code}]: ${this.message}`}}class J{constructor(){this.promise=new Promise(((t,e)=>{this.resolve=t,this.reject=e}))}}class X{constructor(t,e){this.user=e,this.type="OAuth",this.headers=new Map,this.headers.set("Authorization",`Bearer ${t}`)}}class Z{getToken(){return Promise.resolve(null)}invalidateToken(){}start(t,e){t.enqueueRetryable((()=>e(A.UNAUTHENTICATED)))}shutdown(){}}class tt{constructor(t){this.token=t,this.changeListener=null}getToken(){return Promise.resolve(this.token)}invalidateToken(){}start(t,e){this.changeListener=e,t.enqueueRetryable((()=>e(this.token.user)))}shutdown(){this.changeListener=null}}class et{constructor(t){this.auth=null,t.onInit((t=>{this.auth=t}))}getToken(){return this.auth?this.auth.getToken().then((t=>t?(x("string"==typeof t.accessToken),new X(t.accessToken,new A(this.auth.getUid()))):null)):Promise.resolve(null)}invalidateToken(){}start(t,e){}shutdown(){}}class nt{constructor(t,e,n){this.t=t,this.i=e,this.o=n,this.type="FirstParty",this.user=A.FIRST_PARTY,this.u=new Map}h(){return this.o?this.o():null}get headers(){this.u.set("X-Goog-AuthUser",this.t);const t=this.h();return t&&this.u.set("Authorization",t),this.i&&this.u.set("X-Goog-Iam-Authorization-Token",this.i),this.u}}class rt{constructor(t,e,n){this.t=t,this.i=e,this.o=n}getToken(){return Promise.resolve(new nt(this.t,this.i,this.o))}start(t,e){t.enqueueRetryable((()=>e(A.FIRST_PARTY)))}shutdown(){}invalidateToken(){}}class st{constructor(t){this.value=t,this.type="AppCheck",this.headers=new Map,t&&t.length>0&&this.headers.set("x-firebase-appcheck",this.value)}}class it{constructor(t){this.l=t,this.appCheck=null,t.onInit((t=>{this.appCheck=t}))}getToken(){return this.appCheck?this.appCheck.getToken().then((t=>t?(x("string"==typeof t.token),new st(t.token)):null)):Promise.resolve(null)}invalidateToken(){}start(t,e){}shutdown(){}}class ot{constructor(t,e,n,r,s,i,o,a,u){this.databaseId=t,this.appId=e,this.persistenceKey=n,this.host=r,this.ssl=s,this.forceLongPolling=i,this.autoDetectLongPolling=o,this.longPollingOptions=a,this.useFetchStreams=u}}class at{constructor(t,e){this.projectId=t,this.database=e||"(default)"}static empty(){return new at("","")}get isDefaultDatabase(){return"(default)"===this.database}isEqual(t){return t instanceof at&&t.projectId===this.projectId&&t.database===this.database}}class ut{constructor(t,e,n){void 0===e?e=0:e>t.length&&O(),void 0===n?n=t.length-e:n>t.length-e&&O(),this.segments=t,this.offset=e,this.len=n}get length(){return this.len}isEqual(t){return 0===ut.comparator(this,t)}child(t){const e=this.segments.slice(this.offset,this.limit());return t instanceof ut?t.forEach((t=>{e.push(t)})):e.push(t),this.construct(e)}limit(){return this.offset+this.length}popFirst(t){return t=void 0===t?1:t,this.construct(this.segments,this.offset+t,this.length-t)}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(t){return this.segments[this.offset+t]}isEmpty(){return 0===this.length}isPrefixOf(t){if(t.length<this.length)return!1;for(let e=0;e<this.length;e++)if(this.get(e)!==t.get(e))return!1;return!0}isImmediateParentOf(t){if(this.length+1!==t.length)return!1;for(let e=0;e<this.length;e++)if(this.get(e)!==t.get(e))return!1;return!0}forEach(t){for(let e=this.offset,n=this.limit();e<n;e++)t(this.segments[e])}toArray(){return this.segments.slice(this.offset,this.limit())}static comparator(t,e){const n=Math.min(t.length,e.length);for(let r=0;r<n;r++){const n=t.get(r),s=e.get(r);if(n<s)return-1;if(n>s)return 1}return t.length<e.length?-1:t.length>e.length?1:0}}class lt extends ut{construct(t,e,n){return new lt(t,e,n)}canonicalString(){return this.toArray().join("/")}toString(){return this.canonicalString()}static fromString(...t){const e=[];for(const n of t){if(n.indexOf("//")>=0)throw new Y(L,`Invalid segment (${n}). Paths must not contain // in them.`);e.push(...n.split("/").filter((t=>t.length>0)))}return new lt(e)}static emptyPath(){return new lt([])}}const ct=/^[_a-zA-Z][_a-zA-Z0-9]*$/;class ht extends ut{construct(t,e,n){return new ht(t,e,n)}static isValidIdentifier(t){return ct.test(t)}canonicalString(){return this.toArray().map((t=>(t=t.replace(/\\/g,"\\\\").replace(/`/g,"\\`"),ht.isValidIdentifier(t)||(t="`"+t+"`"),t))).join(".")}toString(){return this.canonicalString()}isKeyField(){return 1===this.length&&"__name__"===this.get(0)}static keyField(){return new ht(["__name__"])}static fromServerFormat(t){const e=[];let n="",r=0;const s=()=>{if(0===n.length)throw new Y(L,`Invalid field path (${t}). Paths must not be empty, begin with '.', end with '.', or contain '..'`);e.push(n),n=""};let i=!1;for(;r<t.length;){const e=t[r];if("\\"===e){if(r+1===t.length)throw new Y(L,"Path has trailing escape character: "+t);const e=t[r+1];if("\\"!==e&&"."!==e&&"`"!==e)throw new Y(L,"Path has invalid escape sequence: "+t);n+=e,r+=2}else"`"===e?(i=!i,r++):"."!==e||i?(n+=e,r++):(s(),r++)}if(s(),i)throw new Y(L,"Unterminated ` in path: "+t);return new ht(e)}static emptyPath(){return new ht([])}}class dt{constructor(t){this.path=t}static fromPath(t){return new dt(lt.fromString(t))}static fromName(t){return new dt(lt.fromString(t).popFirst(5))}static empty(){return new dt(lt.emptyPath())}get collectionGroup(){return this.path.popLast().lastSegment()}hasCollectionId(t){return this.path.length>=2&&this.path.get(this.path.length-2)===t}getCollectionGroup(){return this.path.get(this.path.length-2)}getCollectionPath(){return this.path.popLast()}isEqual(t){return null!==t&&0===lt.comparator(this.path,t.path)}toString(){return this.path.toString()}static comparator(t,e){return lt.comparator(t.path,e.path)}static isDocumentKey(t){return t.length%2==0}static fromSegments(t){return new dt(new lt(t.slice()))}}function ft(t,e,n){if(!n)throw new Y(L,`Function ${t}() cannot be called with an empty ${e}.`)}function pt(t){if(!dt.isDocumentKey(t))throw new Y(L,`Invalid document reference. Document references must have an even number of segments, but ${t} has ${t.length}.`)}function mt(t){if(dt.isDocumentKey(t))throw new Y(L,`Invalid collection reference. Collection references must have an odd number of segments, but ${t} has ${t.length}.`)}function gt(t){if(void 0===t)return"undefined";if(null===t)return"null";if("string"==typeof t)return t.length>20&&(t=`${t.substring(0,20)}...`),JSON.stringify(t);if("number"==typeof t||"boolean"==typeof t)return""+t;if("object"==typeof t){if(t instanceof Array)return"an array";{const e=function(t){return t.constructor?t.constructor.name:null}(t);return e?`a custom ${e} object`:"an object"}}return"function"==typeof t?"a function":O()}function yt(t,e){if("_delegate"in t&&(t=t._delegate),!(t instanceof e)){if(e.name===t.constructor.name)throw new Y(L,"Type does not match the expected instance. Did you pass a reference from a different Firestore SDK?");{const n=gt(t);throw new Y(L,`Expected type '${e.name}', but it was: ${n}`)}}return t}function wt(t,e){if(e<=0)throw new Y(L,`Function ${t}() requires a positive number, but it was: ${e}.`)}function _t(t){const e={};return void 0!==t.timeoutSeconds&&(e.timeoutSeconds=t.timeoutSeconds),e}let vt=null;function bt(t){return null==t}function Et(t){return 0===t&&1/t==-1/0}const Tt={BatchGetDocuments:"batchGet",Commit:"commit",RunQuery:"runQuery",RunAggregationQuery:"runAggregationQuery"};var St,At;function It(t){if(void 0===t)return N("RPC_ERROR","HTTP error has no status"),q;switch(t){case 200:return"ok";case 400:return z;case 401:return U;case 403:return $;case 404:return B;case 409:return H;case 416:return W;case 429:return j;case 499:return C;case 500:return q;case 501:return G;case 503:return K;case 504:return M;default:return t>=200&&t<300?"ok":t>=400&&t<500?z:t>=500&&t<600?Q:q}}(At=St||(St={}))[At.OK=0]="OK",At[At.CANCELLED=1]="CANCELLED",At[At.UNKNOWN=2]="UNKNOWN",At[At.INVALID_ARGUMENT=3]="INVALID_ARGUMENT",At[At.DEADLINE_EXCEEDED=4]="DEADLINE_EXCEEDED",At[At.NOT_FOUND=5]="NOT_FOUND",At[At.ALREADY_EXISTS=6]="ALREADY_EXISTS",At[At.PERMISSION_DENIED=7]="PERMISSION_DENIED",At[At.UNAUTHENTICATED=16]="UNAUTHENTICATED",At[At.RESOURCE_EXHAUSTED=8]="RESOURCE_EXHAUSTED",At[At.FAILED_PRECONDITION=9]="FAILED_PRECONDITION",At[At.ABORTED=10]="ABORTED",At[At.OUT_OF_RANGE=11]="OUT_OF_RANGE",At[At.UNIMPLEMENTED=12]="UNIMPLEMENTED",At[At.INTERNAL=13]="INTERNAL",At[At.UNAVAILABLE=14]="UNAVAILABLE",At[At.DATA_LOSS=15]="DATA_LOSS";class kt extends class{constructor(t){this.databaseInfo=t,this.databaseId=t.databaseId;const e=t.ssl?"https":"http";this.m=e+"://"+t.host,this.p="projects/"+this.databaseId.projectId+"/databases/"+this.databaseId.database+"/documents"}get g(){return!1}v(t,e,n,r,s){const i=(null===vt?vt=268435456+Math.round(2147483648*Math.random()):vt++,"0x"+vt.toString(16)),o=this.I(t,e);D("RestConnection",`Sending RPC '${t}' ${i}:`,o,n);const a={};return this.T(a,r,s),this.A(t,o,a,n).then((e=>(D("RestConnection",`Received RPC '${t}' ${i}: `,e),e)),(e=>{throw V("RestConnection",`RPC '${t}' ${i} failed with error: `,e,"url: ",o,"request:",n),e}))}R(t,e,n,r,s,i){return this.v(t,e,n,r,s)}T(t,e,n){t["X-Goog-Api-Client"]="gl-js/ fire/"+I,t["Content-Type"]="text/plain",this.databaseInfo.appId&&(t["X-Firebase-GMPID"]=this.databaseInfo.appId),e&&e.headers.forEach(((e,n)=>t[n]=e)),n&&n.headers.forEach(((e,n)=>t[n]=e))}I(t,e){const n=Tt[t];return`${this.m}/v1/${e}:${n}`}}{constructor(t,e){super(t),this.P=e}V(t,e){throw new Error("Not supported by FetchConnection")}async A(t,e,n,r){var s;const i=JSON.stringify(r);let o;try{o=await this.P(e,{method:"POST",headers:n,body:i})}catch(t){const e=t;throw new Y(It(e.status),"Request failed with error: "+e.statusText)}if(!o.ok){let t=await o.json();Array.isArray(t)&&(t=t[0]);const e=null===(s=null==t?void 0:t.error)||void 0===s?void 0:s.message;throw new Y(It(o.status),`Request failed with error: ${null!=e?e:o.statusText}`)}return o.json()}}class Ft{constructor(t,e,n){this.alias=t,this.$=e,this.fieldPath=n}}function Dt(t){const e="undefined"!=typeof self&&(self.crypto||self.msCrypto),n=new Uint8Array(t);if(e&&"function"==typeof e.getRandomValues)e.getRandomValues(n);else for(let e=0;e<t;e++)n[e]=Math.floor(256*Math.random());return n}class Nt{static N(){const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",e=Math.floor(256/t.length)*t.length;let n="";for(;n.length<20;){const r=Dt(40);for(let s=0;s<r.length;++s)n.length<20&&r[s]<e&&(n+=t.charAt(r[s]%t.length))}return n}}function Vt(t,e){return t<e?-1:t>e?1:0}function Rt(t,e,n){return t.length===e.length&&t.every(((t,r)=>n(t,e[r])))}function Ot(t){let e=0;for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&e++;return e}function xt(t,e){for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&e(n,t[n])}class Pt extends Error{constructor(){super(...arguments),this.name="Base64DecodeError"}}class Ct{constructor(t){this.binaryString=t}static fromBase64String(t){const e=function(t){try{return atob(t)}catch(t){throw"undefined"!=typeof DOMException&&t instanceof DOMException?new Pt("Invalid base64 string: "+t):t}}(t);return new Ct(e)}static fromUint8Array(t){const e=function(t){let e="";for(let n=0;n<t.length;++n)e+=String.fromCharCode(t[n]);return e}(t);return new Ct(e)}[Symbol.iterator](){let t=0;return{next:()=>t<this.binaryString.length?{value:this.binaryString.charCodeAt(t++),done:!1}:{value:void 0,done:!0}}}toBase64(){return t=this.binaryString,btoa(t);var t}toUint8Array(){return function(t){const e=new Uint8Array(t.length);for(let n=0;n<t.length;n++)e[n]=t.charCodeAt(n);return e}(this.binaryString)}approximateByteSize(){return 2*this.binaryString.length}compareTo(t){return Vt(this.binaryString,t.binaryString)}isEqual(t){return this.binaryString===t.binaryString}}Ct.EMPTY_BYTE_STRING=new Ct("");const qt=new RegExp(/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.(\d+))?Z$/);function Lt(t){if(x(!!t),"string"==typeof t){let e=0;const n=qt.exec(t);if(x(!!n),n[1]){let t=n[1];t=(t+"000000000").substr(0,9),e=Number(t)}const r=new Date(t);return{seconds:Math.floor(r.getTime()/1e3),nanos:e}}return{seconds:Mt(t.seconds),nanos:Mt(t.nanos)}}function Mt(t){return"number"==typeof t?t:"string"==typeof t?Number(t):0}function Bt(t){return"string"==typeof t?Ct.fromBase64String(t):Ct.fromUint8Array(t)}class $t{constructor(t,e){if(this.seconds=t,this.nanoseconds=e,e<0)throw new Y(L,"Timestamp nanoseconds out of range: "+e);if(e>=1e9)throw new Y(L,"Timestamp nanoseconds out of range: "+e);if(t<-62135596800)throw new Y(L,"Timestamp seconds out of range: "+t);if(t>=253402300800)throw new Y(L,"Timestamp seconds out of range: "+t)}static now(){return $t.fromMillis(Date.now())}static fromDate(t){return $t.fromMillis(t.getTime())}static fromMillis(t){const e=Math.floor(t/1e3),n=Math.floor(1e6*(t-1e3*e));return new $t(e,n)}toDate(){return new Date(this.toMillis())}toMillis(){return 1e3*this.seconds+this.nanoseconds/1e6}_compareTo(t){return this.seconds===t.seconds?Vt(this.nanoseconds,t.nanoseconds):Vt(this.seconds,t.seconds)}isEqual(t){return t.seconds===this.seconds&&t.nanoseconds===this.nanoseconds}toString(){return"Timestamp(seconds="+this.seconds+", nanoseconds="+this.nanoseconds+")"}toJSON(){return{seconds:this.seconds,nanoseconds:this.nanoseconds}}valueOf(){const t=this.seconds- -62135596800;return String(t).padStart(12,"0")+"."+String(this.nanoseconds).padStart(9,"0")}}function Ut(t){var e,n;return"server_timestamp"===(null===(n=((null===(e=null==t?void 0:t.mapValue)||void 0===e?void 0:e.fields)||{}).__type__)||void 0===n?void 0:n.stringValue)}function jt(t){const e=t.mapValue.fields.__previous_value__;return Ut(e)?jt(e):e}function zt(t){const e=Lt(t.mapValue.fields.__local_write_time__.timestampValue);return new $t(e.seconds,e.nanos)}const Ht={fields:{__type__:{stringValue:"__max__"}}};function Wt(t){return"nullValue"in t?0:"booleanValue"in t?1:"integerValue"in t||"doubleValue"in t?2:"timestampValue"in t?3:"stringValue"in t?5:"bytesValue"in t?6:"referenceValue"in t?7:"geoPointValue"in t?8:"arrayValue"in t?9:"mapValue"in t?Ut(t)?4:function(t){return"__max__"===(((t.mapValue||{}).fields||{}).__type__||{}).stringValue}(t)?9007199254740991:10:O()}function Gt(t,e){if(t===e)return!0;const n=Wt(t);if(n!==Wt(e))return!1;switch(n){case 0:case 9007199254740991:return!0;case 1:return t.booleanValue===e.booleanValue;case 4:return zt(t).isEqual(zt(e));case 3:return function(t,e){if("string"==typeof t.timestampValue&&"string"==typeof e.timestampValue&&t.timestampValue.length===e.timestampValue.length)return t.timestampValue===e.timestampValue;const n=Lt(t.timestampValue),r=Lt(e.timestampValue);return n.seconds===r.seconds&&n.nanos===r.nanos}(t,e);case 5:return t.stringValue===e.stringValue;case 6:return function(t,e){return Bt(t.bytesValue).isEqual(Bt(e.bytesValue))}(t,e);case 7:return t.referenceValue===e.referenceValue;case 8:return function(t,e){return Mt(t.geoPointValue.latitude)===Mt(e.geoPointValue.latitude)&&Mt(t.geoPointValue.longitude)===Mt(e.geoPointValue.longitude)}(t,e);case 2:return function(t,e){if("integerValue"in t&&"integerValue"in e)return Mt(t.integerValue)===Mt(e.integerValue);if("doubleValue"in t&&"doubleValue"in e){const n=Mt(t.doubleValue),r=Mt(e.doubleValue);return n===r?Et(n)===Et(r):isNaN(n)&&isNaN(r)}return!1}(t,e);case 9:return Rt(t.arrayValue.values||[],e.arrayValue.values||[],Gt);case 10:return function(t,e){const n=t.mapValue.fields||{},r=e.mapValue.fields||{};if(Ot(n)!==Ot(r))return!1;for(const t in n)if(n.hasOwnProperty(t)&&(void 0===r[t]||!Gt(n[t],r[t])))return!1;return!0}(t,e);default:return O()}}function Qt(t,e){return void 0!==(t.values||[]).find((t=>Gt(t,e)))}function Kt(t,e){if(t===e)return 0;const n=Wt(t),r=Wt(e);if(n!==r)return Vt(n,r);switch(n){case 0:case 9007199254740991:return 0;case 1:return Vt(t.booleanValue,e.booleanValue);case 2:return function(t,e){const n=Mt(t.integerValue||t.doubleValue),r=Mt(e.integerValue||e.doubleValue);return n<r?-1:n>r?1:n===r?0:isNaN(n)?isNaN(r)?0:-1:1}(t,e);case 3:return Yt(t.timestampValue,e.timestampValue);case 4:return Yt(zt(t),zt(e));case 5:return Vt(t.stringValue,e.stringValue);case 6:return function(t,e){const n=Bt(t),r=Bt(e);return n.compareTo(r)}(t.bytesValue,e.bytesValue);case 7:return function(t,e){const n=t.split("/"),r=e.split("/");for(let t=0;t<n.length&&t<r.length;t++){const e=Vt(n[t],r[t]);if(0!==e)return e}return Vt(n.length,r.length)}(t.referenceValue,e.referenceValue);case 8:return function(t,e){const n=Vt(Mt(t.latitude),Mt(e.latitude));return 0!==n?n:Vt(Mt(t.longitude),Mt(e.longitude))}(t.geoPointValue,e.geoPointValue);case 9:return function(t,e){const n=t.values||[],r=e.values||[];for(let t=0;t<n.length&&t<r.length;++t){const e=Kt(n[t],r[t]);if(e)return e}return Vt(n.length,r.length)}(t.arrayValue,e.arrayValue);case 10:return function(t,e){if(t===Ht&&e===Ht)return 0;if(t===Ht)return 1;if(e===Ht)return-1;const n=t.fields||{},r=Object.keys(n),s=e.fields||{},i=Object.keys(s);r.sort(),i.sort();for(let t=0;t<r.length&&t<i.length;++t){const e=Vt(r[t],i[t]);if(0!==e)return e;const o=Kt(n[r[t]],s[i[t]]);if(0!==o)return o}return Vt(r.length,i.length)}(t.mapValue,e.mapValue);default:throw O()}}function Yt(t,e){if("string"==typeof t&&"string"==typeof e&&t.length===e.length)return Vt(t,e);const n=Lt(t),r=Lt(e),s=Vt(n.seconds,r.seconds);return 0!==s?s:Vt(n.nanos,r.nanos)}function Jt(t,e){return{referenceValue:`projects/${t.projectId}/databases/${t.database}/documents/${e.path.canonicalString()}`}}function Xt(t){return!!t&&"arrayValue"in t}function Zt(t){return!!t&&"nullValue"in t}function te(t){return!!t&&"doubleValue"in t&&isNaN(Number(t.doubleValue))}function ee(t){return!!t&&"mapValue"in t}function ne(t){if(t.geoPointValue)return{geoPointValue:Object.assign({},t.geoPointValue)};if(t.timestampValue&&"object"==typeof t.timestampValue)return{timestampValue:Object.assign({},t.timestampValue)};if(t.mapValue){const e={mapValue:{fields:{}}};return xt(t.mapValue.fields,((t,n)=>e.mapValue.fields[t]=ne(n))),e}if(t.arrayValue){const e={arrayValue:{values:[]}};for(let n=0;n<(t.arrayValue.values||[]).length;++n)e.arrayValue.values[n]=ne(t.arrayValue.values[n]);return e}return Object.assign({},t)}class re{constructor(t,e){this.position=t,this.inclusive=e}}function se(t,e){if(null===t)return null===e;if(null===e)return!1;if(t.inclusive!==e.inclusive||t.position.length!==e.position.length)return!1;for(let n=0;n<t.position.length;n++)if(!Gt(t.position[n],e.position[n]))return!1;return!0}class ie{}class oe extends ie{constructor(t,e,n){super(),this.field=t,this.op=e,this.value=n}static create(t,e,n){return t.isKeyField()?"in"===e||"not-in"===e?this.createKeyFieldInFilter(t,e,n):new le(t,e,n):"array-contains"===e?new fe(t,n):"in"===e?new pe(t,n):"not-in"===e?new me(t,n):"array-contains-any"===e?new ge(t,n):new oe(t,e,n)}static createKeyFieldInFilter(t,e,n){return"in"===e?new ce(t,n):new he(t,n)}matches(t){const e=t.data.field(this.field);return"!="===this.op?null!==e&&this.matchesComparison(Kt(e,this.value)):null!==e&&Wt(this.value)===Wt(e)&&this.matchesComparison(Kt(e,this.value))}matchesComparison(t){switch(this.op){case"<":return t<0;case"<=":return t<=0;case"==":return 0===t;case"!=":return 0!==t;case">":return t>0;case">=":return t>=0;default:return O()}}isInequality(){return["<","<=",">",">=","!=","not-in"].indexOf(this.op)>=0}getFlattenedFilters(){return[this]}getFilters(){return[this]}getFirstInequalityField(){return this.isInequality()?this.field:null}}class ae extends ie{constructor(t,e){super(),this.filters=t,this.op=e,this.D=null}static create(t,e){return new ae(t,e)}matches(t){return"and"===this.op?void 0===this.filters.find((e=>!e.matches(t))):void 0!==this.filters.find((e=>e.matches(t)))}getFlattenedFilters(){return null!==this.D||(this.D=this.filters.reduce(((t,e)=>t.concat(e.getFlattenedFilters())),[])),this.D}getFilters(){return Object.assign([],this.filters)}getFirstInequalityField(){const t=this.F((t=>t.isInequality()));return null!==t?t.field:null}F(t){for(const e of this.getFlattenedFilters())if(t(e))return e;return null}}function ue(t,e){return t instanceof oe?function(t,e){return e instanceof oe&&t.op===e.op&&t.field.isEqual(e.field)&&Gt(t.value,e.value)}(t,e):t instanceof ae?function(t,e){return e instanceof ae&&t.op===e.op&&t.filters.length===e.filters.length&&t.filters.reduce(((t,n,r)=>t&&ue(n,e.filters[r])),!0)}(t,e):void O()}class le extends oe{constructor(t,e,n){super(t,e,n),this.key=dt.fromName(n.referenceValue)}matches(t){const e=dt.comparator(t.key,this.key);return this.matchesComparison(e)}}class ce extends oe{constructor(t,e){super(t,"in",e),this.keys=de("in",e)}matches(t){return this.keys.some((e=>e.isEqual(t.key)))}}class he extends oe{constructor(t,e){super(t,"not-in",e),this.keys=de("not-in",e)}matches(t){return!this.keys.some((e=>e.isEqual(t.key)))}}function de(t,e){var n;return((null===(n=e.arrayValue)||void 0===n?void 0:n.values)||[]).map((t=>dt.fromName(t.referenceValue)))}class fe extends oe{constructor(t,e){super(t,"array-contains",e)}matches(t){const e=t.data.field(this.field);return Xt(e)&&Qt(e.arrayValue,this.value)}}class pe extends oe{constructor(t,e){super(t,"in",e)}matches(t){const e=t.data.field(this.field);return null!==e&&Qt(this.value.arrayValue,e)}}class me extends oe{constructor(t,e){super(t,"not-in",e)}matches(t){if(Qt(this.value.arrayValue,{nullValue:"NULL_VALUE"}))return!1;const e=t.data.field(this.field);return null!==e&&!Qt(this.value.arrayValue,e)}}class ge extends oe{constructor(t,e){super(t,"array-contains-any",e)}matches(t){const e=t.data.field(this.field);return!(!Xt(e)||!e.arrayValue.values)&&e.arrayValue.values.some((t=>Qt(this.value.arrayValue,t)))}}class ye{constructor(t,e="asc"){this.field=t,this.dir=e}}function we(t,e){return t.dir===e.dir&&t.field.isEqual(e.field)}class _e{constructor(t){this.timestamp=t}static fromTimestamp(t){return new _e(t)}static min(){return new _e(new $t(0,0))}static max(){return new _e(new $t(253402300799,999999999))}compareTo(t){return this.timestamp._compareTo(t.timestamp)}isEqual(t){return this.timestamp.isEqual(t.timestamp)}toMicroseconds(){return 1e6*this.timestamp.seconds+this.timestamp.nanoseconds/1e3}toString(){return"SnapshotVersion("+this.timestamp.toString()+")"}toTimestamp(){return this.timestamp}}class ve{constructor(t,e){this.comparator=t,this.root=e||Ee.EMPTY}insert(t,e){return new ve(this.comparator,this.root.insert(t,e,this.comparator).copy(null,null,Ee.BLACK,null,null))}remove(t){return new ve(this.comparator,this.root.remove(t,this.comparator).copy(null,null,Ee.BLACK,null,null))}get(t){let e=this.root;for(;!e.isEmpty();){const n=this.comparator(t,e.key);if(0===n)return e.value;n<0?e=e.left:n>0&&(e=e.right)}return null}indexOf(t){let e=0,n=this.root;for(;!n.isEmpty();){const r=this.comparator(t,n.key);if(0===r)return e+n.left.size;r<0?n=n.left:(e+=n.left.size+1,n=n.right)}return-1}isEmpty(){return this.root.isEmpty()}get size(){return this.root.size}minKey(){return this.root.minKey()}maxKey(){return this.root.maxKey()}inorderTraversal(t){return this.root.inorderTraversal(t)}forEach(t){this.inorderTraversal(((e,n)=>(t(e,n),!1)))}toString(){const t=[];return this.inorderTraversal(((e,n)=>(t.push(`${e}:${n}`),!1))),`{${t.join(", ")}}`}reverseTraversal(t){return this.root.reverseTraversal(t)}getIterator(){return new be(this.root,null,this.comparator,!1)}getIteratorFrom(t){return new be(this.root,t,this.comparator,!1)}getReverseIterator(){return new be(this.root,null,this.comparator,!0)}getReverseIteratorFrom(t){return new be(this.root,t,this.comparator,!0)}}class be{constructor(t,e,n,r){this.isReverse=r,this.nodeStack=[];let s=1;for(;!t.isEmpty();)if(s=e?n(t.key,e):1,e&&r&&(s*=-1),s<0)t=this.isReverse?t.left:t.right;else{if(0===s){this.nodeStack.push(t);break}this.nodeStack.push(t),t=this.isReverse?t.right:t.left}}getNext(){let t=this.nodeStack.pop();const e={key:t.key,value:t.value};if(this.isReverse)for(t=t.left;!t.isEmpty();)this.nodeStack.push(t),t=t.right;else for(t=t.right;!t.isEmpty();)this.nodeStack.push(t),t=t.left;return e}hasNext(){return this.nodeStack.length>0}peek(){if(0===this.nodeStack.length)return null;const t=this.nodeStack[this.nodeStack.length-1];return{key:t.key,value:t.value}}}class Ee{constructor(t,e,n,r,s){this.key=t,this.value=e,this.color=null!=n?n:Ee.RED,this.left=null!=r?r:Ee.EMPTY,this.right=null!=s?s:Ee.EMPTY,this.size=this.left.size+1+this.right.size}copy(t,e,n,r,s){return new Ee(null!=t?t:this.key,null!=e?e:this.value,null!=n?n:this.color,null!=r?r:this.left,null!=s?s:this.right)}isEmpty(){return!1}inorderTraversal(t){return this.left.inorderTraversal(t)||t(this.key,this.value)||this.right.inorderTraversal(t)}reverseTraversal(t){return this.right.reverseTraversal(t)||t(this.key,this.value)||this.left.reverseTraversal(t)}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(t,e,n){let r=this;const s=n(t,r.key);return r=s<0?r.copy(null,null,null,r.left.insert(t,e,n),null):0===s?r.copy(null,e,null,null,null):r.copy(null,null,null,null,r.right.insert(t,e,n)),r.fixUp()}removeMin(){if(this.left.isEmpty())return Ee.EMPTY;let t=this;return t.left.isRed()||t.left.left.isRed()||(t=t.moveRedLeft()),t=t.copy(null,null,null,t.left.removeMin(),null),t.fixUp()}remove(t,e){let n,r=this;if(e(t,r.key)<0)r.left.isEmpty()||r.left.isRed()||r.left.left.isRed()||(r=r.moveRedLeft()),r=r.copy(null,null,null,r.left.remove(t,e),null);else{if(r.left.isRed()&&(r=r.rotateRight()),r.right.isEmpty()||r.right.isRed()||r.right.left.isRed()||(r=r.moveRedRight()),0===e(t,r.key)){if(r.right.isEmpty())return Ee.EMPTY;n=r.right.min(),r=r.copy(n.key,n.value,null,null,r.right.removeMin())}r=r.copy(null,null,null,null,r.right.remove(t,e))}return r.fixUp()}isRed(){return this.color}fixUp(){let t=this;return t.right.isRed()&&!t.left.isRed()&&(t=t.rotateLeft()),t.left.isRed()&&t.left.left.isRed()&&(t=t.rotateRight()),t.left.isRed()&&t.right.isRed()&&(t=t.colorFlip()),t}moveRedLeft(){let t=this.colorFlip();return t.right.left.isRed()&&(t=t.copy(null,null,null,null,t.right.rotateRight()),t=t.rotateLeft(),t=t.colorFlip()),t}moveRedRight(){let t=this.colorFlip();return t.left.left.isRed()&&(t=t.rotateRight(),t=t.colorFlip()),t}rotateLeft(){const t=this.copy(null,null,Ee.RED,null,this.right.left);return this.right.copy(null,null,this.color,t,null)}rotateRight(){const t=this.copy(null,null,Ee.RED,this.left.right,null);return this.left.copy(null,null,this.color,null,t)}colorFlip(){const t=this.left.copy(null,null,!this.left.color,null,null),e=this.right.copy(null,null,!this.right.color,null,null);return this.copy(null,null,!this.color,t,e)}checkMaxDepth(){const t=this.check();return Math.pow(2,t)<=this.size+1}check(){if(this.isRed()&&this.left.isRed())throw O();if(this.right.isRed())throw O();const t=this.left.check();if(t!==this.right.check())throw O();return t+(this.isRed()?0:1)}}Ee.EMPTY=null,Ee.RED=!0,Ee.BLACK=!1,Ee.EMPTY=new class{constructor(){this.size=0}get key(){throw O()}get value(){throw O()}get color(){throw O()}get left(){throw O()}get right(){throw O()}copy(t,e,n,r,s){return this}insert(t,e,n){return new Ee(t,e)}remove(t,e){return this}isEmpty(){return!0}inorderTraversal(t){return!1}reverseTraversal(t){return!1}minKey(){return null}maxKey(){return null}isRed(){return!1}checkMaxDepth(){return!0}check(){return 0}};class Te{constructor(t){this.comparator=t,this.data=new ve(this.comparator)}has(t){return null!==this.data.get(t)}first(){return this.data.minKey()}last(){return this.data.maxKey()}get size(){return this.data.size}indexOf(t){return this.data.indexOf(t)}forEach(t){this.data.inorderTraversal(((e,n)=>(t(e),!1)))}forEachInRange(t,e){const n=this.data.getIteratorFrom(t[0]);for(;n.hasNext();){const r=n.getNext();if(this.comparator(r.key,t[1])>=0)return;e(r.key)}}forEachWhile(t,e){let n;for(n=void 0!==e?this.data.getIteratorFrom(e):this.data.getIterator();n.hasNext();)if(!t(n.getNext().key))return}firstAfterOrEqual(t){const e=this.data.getIteratorFrom(t);return e.hasNext()?e.getNext().key:null}getIterator(){return new Se(this.data.getIterator())}getIteratorFrom(t){return new Se(this.data.getIteratorFrom(t))}add(t){return this.copy(this.data.remove(t).insert(t,!0))}delete(t){return this.has(t)?this.copy(this.data.remove(t)):this}isEmpty(){return this.data.isEmpty()}unionWith(t){let e=this;return e.size<t.size&&(e=t,t=this),t.forEach((t=>{e=e.add(t)})),e}isEqual(t){if(!(t instanceof Te))return!1;if(this.size!==t.size)return!1;const e=this.data.getIterator(),n=t.data.getIterator();for(;e.hasNext();){const t=e.getNext().key,r=n.getNext().key;if(0!==this.comparator(t,r))return!1}return!0}toArray(){const t=[];return this.forEach((e=>{t.push(e)})),t}toString(){const t=[];return this.forEach((e=>t.push(e))),"SortedSet("+t.toString()+")"}copy(t){const e=new Te(this.comparator);return e.data=t,e}}class Se{constructor(t){this.iter=t}getNext(){return this.iter.getNext().key}hasNext(){return this.iter.hasNext()}}class Ae{constructor(t){this.fields=t,t.sort(ht.comparator)}static empty(){return new Ae([])}unionWith(t){let e=new Te(ht.comparator);for(const t of this.fields)e=e.add(t);for(const n of t)e=e.add(n);return new Ae(e.toArray())}covers(t){for(const e of this.fields)if(e.isPrefixOf(t))return!0;return!1}isEqual(t){return Rt(this.fields,t.fields,((t,e)=>t.isEqual(e)))}}class Ie{constructor(t){this.value=t}static empty(){return new Ie({mapValue:{}})}field(t){if(t.isEmpty())return this.value;{let e=this.value;for(let n=0;n<t.length-1;++n)if(e=(e.mapValue.fields||{})[t.get(n)],!ee(e))return null;return e=(e.mapValue.fields||{})[t.lastSegment()],e||null}}set(t,e){this.getFieldsMap(t.popLast())[t.lastSegment()]=ne(e)}setAll(t){let e=ht.emptyPath(),n={},r=[];t.forEach(((t,s)=>{if(!e.isImmediateParentOf(s)){const t=this.getFieldsMap(e);this.applyChanges(t,n,r),n={},r=[],e=s.popLast()}t?n[s.lastSegment()]=ne(t):r.push(s.lastSegment())}));const s=this.getFieldsMap(e);this.applyChanges(s,n,r)}delete(t){const e=this.field(t.popLast());ee(e)&&e.mapValue.fields&&delete e.mapValue.fields[t.lastSegment()]}isEqual(t){return Gt(this.value,t.value)}getFieldsMap(t){let e=this.value;e.mapValue.fields||(e.mapValue={fields:{}});for(let n=0;n<t.length;++n){let r=e.mapValue.fields[t.get(n)];ee(r)&&r.mapValue.fields||(r={mapValue:{fields:{}}},e.mapValue.fields[t.get(n)]=r),e=r}return e.mapValue.fields}applyChanges(t,e,n){xt(e,((e,n)=>t[e]=n));for(const e of n)delete t[e]}clone(){return new Ie(ne(this.value))}}class ke{constructor(t,e,n,r,s,i,o){this.key=t,this.documentType=e,this.version=n,this.readTime=r,this.createTime=s,this.data=i,this.documentState=o}static newInvalidDocument(t){return new ke(t,0,_e.min(),_e.min(),_e.min(),Ie.empty(),0)}static newFoundDocument(t,e,n,r){return new ke(t,1,e,_e.min(),n,r,0)}static newNoDocument(t,e){return new ke(t,2,e,_e.min(),_e.min(),Ie.empty(),0)}static newUnknownDocument(t,e){return new ke(t,3,e,_e.min(),_e.min(),Ie.empty(),2)}convertToFoundDocument(t,e){return!this.createTime.isEqual(_e.min())||2!==this.documentType&&0!==this.documentType||(this.createTime=t),this.version=t,this.documentType=1,this.data=e,this.documentState=0,this}convertToNoDocument(t){return this.version=t,this.documentType=2,this.data=Ie.empty(),this.documentState=0,this}convertToUnknownDocument(t){return this.version=t,this.documentType=3,this.data=Ie.empty(),this.documentState=2,this}setHasCommittedMutations(){return this.documentState=2,this}setHasLocalMutations(){return this.documentState=1,this.version=_e.min(),this}setReadTime(t){return this.readTime=t,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(t){return t instanceof ke&&this.key.isEqual(t.key)&&this.version.isEqual(t.version)&&this.documentType===t.documentType&&this.documentState===t.documentState&&this.data.isEqual(t.data)}mutableCopy(){return new ke(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 Fe{constructor(t,e=null,n=[],r=[],s=null,i=null,o=null){this.path=t,this.collectionGroup=e,this.orderBy=n,this.filters=r,this.limit=s,this.startAt=i,this.endAt=o,this.S=null}}function De(t,e=null,n=[],r=[],s=null,i=null,o=null){return new Fe(t,e,n,r,s,i,o)}class Ne{constructor(t,e=null,n=[],r=[],s=null,i="F",o=null,a=null){this.path=t,this.collectionGroup=e,this.explicitOrderBy=n,this.filters=r,this.limit=s,this.limitType=i,this.startAt=o,this.endAt=a,this.q=null,this.O=null,this.startAt,this.endAt}}function Ve(t){return t.explicitOrderBy.length>0?t.explicitOrderBy[0].field:null}function Re(t){for(const e of t.filters){const t=e.getFirstInequalityField();if(null!==t)return t}return null}function Oe(t){return null!==t.collectionGroup}function xe(t){const e=P(t);if(null===e.q){e.q=[];const t=Re(e),n=Ve(e);if(null!==t&&null===n)t.isKeyField()||e.q.push(new ye(t)),e.q.push(new ye(ht.keyField(),"asc"));else{let t=!1;for(const n of e.explicitOrderBy)e.q.push(n),n.field.isKeyField()&&(t=!0);if(!t){const t=e.explicitOrderBy.length>0?e.explicitOrderBy[e.explicitOrderBy.length-1].dir:"asc";e.q.push(new ye(ht.keyField(),t))}}}return e.q}function Pe(t){const e=P(t);if(!e.O)if("F"===e.limitType)e.O=De(e.path,e.collectionGroup,xe(e),e.filters,e.limit,e.startAt,e.endAt);else{const t=[];for(const n of xe(e)){const e="desc"===n.dir?"asc":"desc";t.push(new ye(n.field,e))}const n=e.endAt?new re(e.endAt.position,e.endAt.inclusive):null,r=e.startAt?new re(e.startAt.position,e.startAt.inclusive):null;e.O=De(e.path,e.collectionGroup,t,e.filters,e.limit,n,r)}return e.O}function Ce(t,e){e.getFirstInequalityField(),Re(t);const n=t.filters.concat([e]);return new Ne(t.path,t.collectionGroup,t.explicitOrderBy.slice(),n,t.limit,t.limitType,t.startAt,t.endAt)}function qe(t,e){return function(t){return"number"==typeof t&&Number.isInteger(t)&&!Et(t)&&t<=Number.MAX_SAFE_INTEGER&&t>=Number.MIN_SAFE_INTEGER}(e)?function(t){return{integerValue:""+t}}(e):function(t,e){if(t.useProto3Json){if(isNaN(e))return{doubleValue:"NaN"};if(e===1/0)return{doubleValue:"Infinity"};if(e===-1/0)return{doubleValue:"-Infinity"}}return{doubleValue:Et(e)?"-0":e}}(t,e)}class Le{constructor(){this._=void 0}}class Me extends Le{}class Be extends Le{constructor(t){super(),this.elements=t}}class $e extends Le{constructor(t){super(),this.elements=t}}class Ue extends Le{constructor(t,e){super(),this.serializer=t,this.k=e}}class je{constructor(t,e){this.field=t,this.transform=e}}class ze{constructor(t,e){this.updateTime=t,this.exists=e}static none(){return new ze}static exists(t){return new ze(void 0,t)}static updateTime(t){return new ze(t)}get isNone(){return void 0===this.updateTime&&void 0===this.exists}isEqual(t){return this.exists===t.exists&&(this.updateTime?!!t.updateTime&&this.updateTime.isEqual(t.updateTime):!t.updateTime)}}class He{}class We extends He{constructor(t,e,n,r=[]){super(),this.key=t,this.value=e,this.precondition=n,this.fieldTransforms=r,this.type=0}getFieldMask(){return null}}class Ge extends He{constructor(t,e,n,r,s=[]){super(),this.key=t,this.data=e,this.fieldMask=n,this.precondition=r,this.fieldTransforms=s,this.type=1}getFieldMask(){return this.fieldMask}}class Qe extends He{constructor(t,e){super(),this.key=t,this.precondition=e,this.type=2,this.fieldTransforms=[]}getFieldMask(){return null}}class Ke extends He{constructor(t,e){super(),this.key=t,this.precondition=e,this.type=3,this.fieldTransforms=[]}getFieldMask(){return null}}const Ye={asc:"ASCENDING",desc:"DESCENDING"},Je={"<":"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"},Xe={and:"AND",or:"OR"};class Ze{constructor(t,e){this.databaseId=t,this.useProto3Json=e}}function tn(t,e){return t.useProto3Json?`${new Date(1e3*e.seconds).toISOString().replace(/\.\d*/,"").replace("Z","")}.${("000000000"+e.nanoseconds).slice(-9)}Z`:{seconds:""+e.seconds,nanos:e.nanoseconds}}function en(t,e){return t.useProto3Json?e.toBase64():e.toUint8Array()}function nn(t,e){return tn(t,e.toTimestamp())}function rn(t){return x(!!t),_e.fromTimestamp(function(t){const e=Lt(t);return new $t(e.seconds,e.nanos)}(t))}function sn(t,e){return function(t){return new lt(["projects",t.projectId,"databases",t.database])}(t).child("documents").child(e).canonicalString()}function on(t,e){return sn(t.databaseId,e.path)}function an(t,e){const n=function(t){const e=lt.fromString(t);return x(wn(e)),e}(e);if(n.get(1)!==t.databaseId.projectId)throw new Y(L,"Tried to deserialize key from different project: "+n.get(1)+" vs "+t.databaseId.projectId);if(n.get(3)!==t.databaseId.database)throw new Y(L,"Tried to deserialize key from different database: "+n.get(3)+" vs "+t.databaseId.database);return new dt((x((r=n).length>4&&"documents"===r.get(4)),r.popFirst(5)));var r}function un(t,e){return sn(t.databaseId,e)}function ln(t){return new lt(["projects",t.databaseId.projectId,"databases",t.databaseId.database]).canonicalString()}function cn(t,e,n){return{name:on(t,e),fields:n.value.mapValue.fields}}function hn(t,e){const n={structuredQuery:{}},r=e.path;null!==e.collectionGroup?(n.parent=un(t,r),n.structuredQuery.from=[{collectionId:e.collectionGroup,allDescendants:!0}]):(n.parent=un(t,r.popLast()),n.structuredQuery.from=[{collectionId:r.lastSegment()}]);const s=function(t){if(0!==t.length)return gn(ae.create(t,"and"))}(e.filters);s&&(n.structuredQuery.where=s);const i=function(t){if(0!==t.length)return t.map((t=>function(t){return{field:mn(t.field),direction:dn(t.dir)}}(t)))}(e.orderBy);i&&(n.structuredQuery.orderBy=i);const o=function(t,e){return t.useProto3Json||bt(e)?e:{value:e}}(t,e.limit);var a;return null!==o&&(n.structuredQuery.limit=o),e.startAt&&(n.structuredQuery.startAt={before:(a=e.startAt).inclusive,values:a.position}),e.endAt&&(n.structuredQuery.endAt=function(t){return{before:!t.inclusive,values:t.position}}(e.endAt)),n}function dn(t){return Ye[t]}function fn(t){return Je[t]}function pn(t){return Xe[t]}function mn(t){return{fieldPath:t.canonicalString()}}function gn(t){return t instanceof oe?function(t){if("=="===t.op){if(te(t.value))return{unaryFilter:{field:mn(t.field),op:"IS_NAN"}};if(Zt(t.value))return{unaryFilter:{field:mn(t.field),op:"IS_NULL"}}}else if("!="===t.op){if(te(t.value))return{unaryFilter:{field:mn(t.field),op:"IS_NOT_NAN"}};if(Zt(t.value))return{unaryFilter:{field:mn(t.field),op:"IS_NOT_NULL"}}}return{fieldFilter:{field:mn(t.field),op:fn(t.op),value:t.value}}}(t):t instanceof ae?function(t){const e=t.getFilters().map((t=>gn(t)));return 1===e.length?e[0]:{compositeFilter:{op:pn(t.op),filters:e}}}(t):O()}function yn(t){const e=[];return t.fields.forEach((t=>e.push(t.canonicalString()))),{fieldPaths:e}}function wn(t){return t.length>=4&&"projects"===t.get(0)&&"databases"===t.get(2)}function _n(t){return new Ze(t,!0)}class vn{constructor(t,e,n=1e3,r=1.5,s=6e4){this.C=t,this.timerId=e,this.M=n,this.L=r,this.U=s,this.j=0,this.B=null,this.W=Date.now(),this.reset()}reset(){this.j=0}G(){this.j=this.U}K(t){this.cancel();const e=Math.floor(this.j+this.Y()),n=Math.max(0,Date.now()-this.W),r=Math.max(0,e-n);r>0&&D("ExponentialBackoff",`Backing off for ${r} ms (base delay: ${this.j} ms, delay with jitter: ${e} ms, last attempt: ${n} ms ago)`),this.B=this.C.enqueueAfterDelay(this.timerId,r,(()=>(this.W=Date.now(),t()))),this.j*=this.L,this.j<this.M&&(this.j=this.M),this.j>this.U&&(this.j=this.U)}H(){null!==this.B&&(this.B.skipDelay(),this.B=null)}cancel(){null!==this.B&&(this.B.cancel(),this.B=null)}Y(){return(Math.random()-.5)*this.j}}class bn extends class{}{constructor(t,e,n,r){super(),this.authCredentials=t,this.appCheckCredentials=e,this.connection=n,this.serializer=r,this.J=!1}X(){if(this.J)throw new Y(z,"The client has already been terminated.")}v(t,e,n){return this.X(),Promise.all([this.authCredentials.getToken(),this.appCheckCredentials.getToken()]).then((([r,s])=>this.connection.v(t,e,n,r,s))).catch((t=>{throw"FirebaseError"===t.name?(t.code===U&&(this.authCredentials.invalidateToken(),this.appCheckCredentials.invalidateToken()),t):new Y(q,t.toString())}))}R(t,e,n,r){return this.X(),Promise.all([this.authCredentials.getToken(),this.appCheckCredentials.getToken()]).then((([s,i])=>this.connection.R(t,e,n,s,i,r))).catch((t=>{throw"FirebaseError"===t.name?(t.code===U&&(this.authCredentials.invalidateToken(),this.appCheckCredentials.invalidateToken()),t):new Y(q,t.toString())}))}terminate(){this.J=!0}}async function En(t,e){const n=P(t),r=ln(n.serializer)+"/documents",s={writes:e.map((t=>function(t,e){let n;if(e instanceof We)n={update:cn(t,e.key,e.value)};else if(e instanceof Qe)n={delete:on(t,e.key)};else if(e instanceof Ge)n={update:cn(t,e.key,e.data),updateMask:yn(e.fieldMask)};else{if(!(e instanceof Ke))return O();n={verify:on(t,e.key)}}return e.fieldTransforms.length>0&&(n.updateTransforms=e.fieldTransforms.map((t=>function(t,e){const n=e.transform;if(n instanceof Me)return{fieldPath:e.field.canonicalString(),setToServerValue:"REQUEST_TIME"};if(n instanceof Be)return{fieldPath:e.field.canonicalString(),appendMissingElements:{values:n.elements}};if(n instanceof $e)return{fieldPath:e.field.canonicalString(),removeAllFromArray:{values:n.elements}};if(n instanceof Ue)return{fieldPath:e.field.canonicalString(),increment:n.k};throw O()}(0,t)))),e.precondition.isNone||(n.currentDocument=function(t,e){return void 0!==e.updateTime?{updateTime:nn(t,e.updateTime)}:void 0!==e.exists?{exists:e.exists}:O()}(t,e.precondition)),n}(n.serializer,t)))};await n.v("Commit",r,s)}async function Tn(t,e){const n=P(t),r=ln(n.serializer)+"/documents",s={documents:e.map((t=>on(n.serializer,t)))},i=await n.R("BatchGetDocuments",r,s,e.length),o=new Map;i.forEach((t=>{const e=function(t,e){return"found"in e?function(t,e){x(!!e.found),e.found.name,e.found.updateTime;const n=an(t,e.found.name),r=rn(e.found.updateTime),s=e.found.createTime?rn(e.found.createTime):_e.min(),i=new Ie({mapValue:{fields:e.found.fields}});return ke.newFoundDocument(n,r,s,i)}(t,e):"missing"in e?function(t,e){x(!!e.missing),x(!!e.readTime);const n=an(t,e.missing),r=rn(e.readTime);return ke.newNoDocument(n,r)}(t,e):O()}(n.serializer,t);o.set(e.key.toString(),e)}));const a=[];return e.forEach((t=>{const e=o.get(t.toString());x(!!e),a.push(e)})),a}const Sn=new Map;function An(t){if(t._terminated)throw new Y(z,"The client has already been terminated.");if(!Sn.has(t)){D("ComponentProvider","Initializing Datastore");const i=function(t){return new kt(t,fetch.bind(null))}((e=t._databaseId,n=t.app.options.appId||"",r=t._persistenceKey,s=t._freezeSettings(),new ot(e,n,r,s.host,s.ssl,s.experimentalForceLongPolling,s.experimentalAutoDetectLongPolling,_t(s.experimentalLongPollingOptions),s.useFetchStreams))),o=_n(t._databaseId),a=function(t,e,n,r){return new bn(t,e,n,r)}(t._authCredentials,t._appCheckCredentials,i,o);Sn.set(t,a)}var e,n,r,s;return Sn.get(t)}class In{constructor(t){var e,n;if(void 0===t.host){if(void 0!==t.ssl)throw new Y(L,"Can't provide ssl option if host option is not set");this.host="firestore.googleapis.com",this.ssl=!0}else this.host=t.host,this.ssl=null===(e=t.ssl)||void 0===e||e;if(this.credentials=t.credentials,this.ignoreUndefinedProperties=!!t.ignoreUndefinedProperties,this.cache=t.localCache,void 0===t.cacheSizeBytes)this.cacheSizeBytes=41943040;else{if(-1!==t.cacheSizeBytes&&t.cacheSizeBytes<1048576)throw new Y(L,"cacheSizeBytes must be at least 1048576");this.cacheSizeBytes=t.cacheSizeBytes}!function(t,e,n,r){if(!0===e&&!0===r)throw new Y(L,"experimentalForceLongPolling and experimentalAutoDetectLongPolling cannot be used together.")}(0,t.experimentalForceLongPolling,0,t.experimentalAutoDetectLongPolling),this.experimentalForceLongPolling=!!t.experimentalForceLongPolling,this.experimentalForceLongPolling?this.experimentalAutoDetectLongPolling=!1:void 0===t.experimentalAutoDetectLongPolling?this.experimentalAutoDetectLongPolling=!0:this.experimentalAutoDetectLongPolling=!!t.experimentalAutoDetectLongPolling,this.experimentalLongPollingOptions=_t(null!==(n=t.experimentalLongPollingOptions)&&void 0!==n?n:{}),function(t){if(void 0!==t.timeoutSeconds){if(isNaN(t.timeoutSeconds))throw new Y(L,`invalid long polling timeout: ${t.timeoutSeconds} (must not be NaN)`);if(t.timeoutSeconds<5)throw new Y(L,`invalid long polling timeout: ${t.timeoutSeconds} (minimum allowed value is 5)`);if(t.timeoutSeconds>30)throw new Y(L,`invalid long polling timeout: ${t.timeoutSeconds} (maximum allowed value is 30)`)}}(this.experimentalLongPollingOptions),this.useFetchStreams=!!t.useFetchStreams}isEqual(t){return this.host===t.host&&this.ssl===t.ssl&&this.credentials===t.credentials&&this.cacheSizeBytes===t.cacheSizeBytes&&this.experimentalForceLongPolling===t.experimentalForceLongPolling&&this.experimentalAutoDetectLongPolling===t.experimentalAutoDetectLongPolling&&(e=this.experimentalLongPollingOptions,n=t.experimentalLongPollingOptions,e.timeoutSeconds===n.timeoutSeconds)&&this.ignoreUndefinedProperties===t.ignoreUndefinedProperties&&this.useFetchStreams===t.useFetchStreams;var e,n}}class kn{constructor(t,e,n,r){this._authCredentials=t,this._appCheckCredentials=e,this._databaseId=n,this._app=r,this.type="firestore-lite",this._persistenceKey="(lite)",this._settings=new In({}),this._settingsFrozen=!1}get app(){if(!this._app)throw new Y(z,"Firestore was not initialized using the Firebase SDK. 'app' is not available");return this._app}get _initialized(){return this._settingsFrozen}get _terminated(){return void 0!==this._terminateTask}_setSettings(t){if(this._settingsFrozen)throw new Y(z,"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 In(t),void 0!==t.credentials&&(this._authCredentials=function(t){if(!t)return new Z;switch(t.type){case"firstParty":return new rt(t.sessionIndex||"0",t.iamToken||null,t.authTokenFactory||null);case"provider":return t.client;default:throw new Y(L,"makeAuthCredentialsProvider failed due to invalid credential type")}}(t.credentials))}_getSettings(){return this._settings}_freezeSettings(){return this._settingsFrozen=!0,this._settings}_delete(){return this._terminateTask||(this._terminateTask=this._terminate()),this._terminateTask}toJSON(){return{app:this._app,databaseId:this._databaseId,settings:this._settings}}_terminate(){return function(t){const e=Sn.get(t);e&&(D("ComponentProvider","Removing Datastore"),Sn.delete(t),e.terminate())}(this),Promise.resolve()}}function Fn(t,e,r){r||(r="(default)");const s=n(t,"firestore/lite");if(s.isInitialized(r))throw new Y(z,"Firestore can only be initialized once per app.");return s.initialize({options:e,instanceIdentifier:r})}function Dn(t,e){const s="object"==typeof t?t:r(),i="string"==typeof t?t:e||"(default)",o=n(s,"firestore/lite").getImmediate({identifier:i});if(!o._initialized){const t=f("firestore");t&&Nn(o,...t)}return o}function Nn(t,e,n,r={}){var s;const i=(t=yt(t,kn))._getSettings(),o=`${e}:${n}`;if("firestore.googleapis.com"!==i.host&&i.host!==o&&V("Host has been set in both settings() and connectFirestoreEmulator(), emulator host will be used."),t._setSettings(Object.assign(Object.assign({},i),{host:o,ssl:!1})),r.mockUserToken){let e,n;if("string"==typeof r.mockUserToken)e=r.mockUserToken,n=A.MOCK_USER;else{e=function(t,e){if(t.uid)throw new Error('The "uid" field is no longer supported by mockUserToken. Please use "sub" instead for Firebase Auth User ID.');const n=e||"demo-project",r=t.iat||0,s=t.sub||t.user_id;if(!s)throw new Error("mockUserToken must contain 'sub' or 'user_id' field!");const i=Object.assign({iss:`https://securetoken.google.com/${n}`,aud:n,iat:r,exp:r+3600,auth_time:r,sub:s,user_id:s,firebase:{sign_in_provider:"custom",identities:{}}},t);return[l(JSON.stringify({alg:"none",type:"JWT"})),l(JSON.stringify(i)),""].join(".")}(r.mockUserToken,null===(s=t._app)||void 0===s?void 0:s.options.projectId);const i=r.mockUserToken.sub||r.mockUserToken.user_id;if(!i)throw new Y(L,"mockUserToken must contain 'sub' or 'user_id' field!");n=new A(i)}t._authCredentials=new tt(new X(e,n))}}function Vn(t){return t=yt(t,kn),s(t.app,"firestore/lite"),t._delete()}class Rn{constructor(t="count",e){this._aggregateType=t,this._internalFieldPath=e,this.type="AggregateField"}}class On{constructor(t,e,n){this._userDataWriter=e,this._data=n,this.type="AggregateQuerySnapshot",this.query=t}data(){return this._userDataWriter.convertObjectMap(this._data)}}class xn{constructor(t,e,n){this.converter=e,this._key=n,this.type="document",this.firestore=t}get _path(){return this._key.path}get id(){return this._key.path.lastSegment()}get path(){return this._key.path.canonicalString()}get parent(){return new Cn(this.firestore,this.converter,this._key.path.popLast())}withConverter(t){return new xn(this.firestore,t,this._key)}}class Pn{constructor(t,e,n){this.converter=e,this._query=n,this.type="query",this.firestore=t}withConverter(t){return new Pn(this.firestore,t,this._query)}}class Cn extends Pn{constructor(t,e,n){super(t,e,new Ne(n)),this._path=n,this.type="collection"}get id(){return this._query.path.lastSegment()}get path(){return this._query.path.canonicalString()}get parent(){const t=this._path.popLast();return t.isEmpty()?null:new xn(this.firestore,null,new dt(t))}withConverter(t){return new Cn(this.firestore,t,this._path)}}function qn(t,e,...n){if(t=_(t),ft("collection","path",e),t instanceof kn){const r=lt.fromString(e,...n);return mt(r),new Cn(t,null,r)}{if(!(t instanceof xn||t instanceof Cn))throw new Y(L,"Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore");const r=t._path.child(lt.fromString(e,...n));return mt(r),new Cn(t.firestore,null,r)}}function Ln(t,e){if(t=yt(t,kn),ft("collectionGroup","collection id",e),e.indexOf("/")>=0)throw new Y(L,`Invalid collection ID '${e}' passed to function collectionGroup(). Collection IDs must not contain '/'.`);return new Pn(t,null,function(t){return new Ne(lt.emptyPath(),t)}(e))}function Mn(t,e,...n){if(t=_(t),1===arguments.length&&(e=Nt.N()),ft("doc","path",e),t instanceof kn){const r=lt.fromString(e,...n);return pt(r),new xn(t,null,new dt(r))}{if(!(t instanceof xn||t instanceof Cn))throw new Y(L,"Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore");const r=t._path.child(lt.fromString(e,...n));return pt(r),new xn(t.firestore,t instanceof Cn?t.converter:null,new dt(r))}}function Bn(t,e){return t=_(t),e=_(e),(t instanceof xn||t instanceof Cn)&&(e instanceof xn||e instanceof Cn)&&t.firestore===e.firestore&&t.path===e.path&&t.converter===e.converter}function $n(t,e){return t=_(t),e=_(e),t instanceof Pn&&e instanceof Pn&&t.firestore===e.firestore&&function(t,e){return function(t,e){if(t.limit!==e.limit)return!1;if(t.orderBy.length!==e.orderBy.length)return!1;for(let n=0;n<t.orderBy.length;n++)if(!we(t.orderBy[n],e.orderBy[n]))return!1;if(t.filters.length!==e.filters.length)return!1;for(let n=0;n<t.filters.length;n++)if(!ue(t.filters[n],e.filters[n]))return!1;return t.collectionGroup===e.collectionGroup&&!!t.path.isEqual(e.path)&&!!se(t.startAt,e.startAt)&&se(t.endAt,e.endAt)}(Pe(t),Pe(e))&&t.limitType===e.limitType}(t._query,e._query)&&t.converter===e.converter}class Un{constructor(t){this._byteString=t}static fromBase64String(t){try{return new Un(Ct.fromBase64String(t))}catch(t){throw new Y(L,"Failed to construct data from Base64 string: "+t)}}static fromUint8Array(t){return new Un(Ct.fromUint8Array(t))}toBase64(){return this._byteString.toBase64()}toUint8Array(){return this._byteString.toUint8Array()}toString(){return"Bytes(base64: "+this.toBase64()+")"}isEqual(t){return this._byteString.isEqual(t._byteString)}}class jn{constructor(...t){for(let e=0;e<t.length;++e)if(0===t[e].length)throw new Y(L,"Invalid field name at argument $(i + 1). Field names must not be empty.");this._internalPath=new ht(t)}isEqual(t){return this._internalPath.isEqual(t._internalPath)}}function zn(){return new jn("__name__")}class Hn{constructor(t){this._methodName=t}}class Wn{constructor(t,e){if(!isFinite(t)||t<-90||t>90)throw new Y(L,"Latitude must be a number between -90 and 90, but was: "+t);if(!isFinite(e)||e<-180||e>180)throw new Y(L,"Longitude must be a number between -180 and 180, but was: "+e);this._lat=t,this._long=e}get latitude(){return this._lat}get longitude(){return this._long}isEqual(t){return this._lat===t._lat&&this._long===t._long}toJSON(){return{latitude:this._lat,longitude:this._long}}_compareTo(t){return Vt(this._lat,t._lat)||Vt(this._long,t._long)}}const Gn=/^__.*__$/;class Qn{constructor(t,e,n){this.data=t,this.fieldMask=e,this.fieldTransforms=n}toMutation(t,e){return null!==this.fieldMask?new Ge(t,this.data,this.fieldMask,e,this.fieldTransforms):new We(t,this.data,e,this.fieldTransforms)}}class Kn{constructor(t,e,n){this.data=t,this.fieldMask=e,this.fieldTransforms=n}toMutation(t,e){return new Ge(t,this.data,this.fieldMask,e,this.fieldTransforms)}}function Yn(t){switch(t){case 0:case 2:case 1:return!0;case 3:case 4:return!1;default:throw O()}}class Jn{constructor(t,e,n,r,s,i){this.settings=t,this.databaseId=e,this.serializer=n,this.ignoreUndefinedProperties=r,void 0===s&&this.tt(),this.fieldTransforms=s||[],this.fieldMask=i||[]}get path(){return this.settings.path}get et(){return this.settings.et}nt(t){return new Jn(Object.assign(Object.assign({},this.settings),t),this.databaseId,this.serializer,this.ignoreUndefinedProperties,this.fieldTransforms,this.fieldMask)}rt(t){var e;const n=null===(e=this.path)||void 0===e?void 0:e.child(t),r=this.nt({path:n,st:!1});return r.it(t),r}ot(t){var e;const n=null===(e=this.path)||void 0===e?void 0:e.child(t),r=this.nt({path:n,st:!1});return r.tt(),r}ut(t){return this.nt({path:void 0,st:!0})}ct(t){return yr(t,this.settings.methodName,this.settings.ht||!1,this.path,this.settings.lt)}contains(t){return void 0!==this.fieldMask.find((e=>t.isPrefixOf(e)))||void 0!==this.fieldTransforms.find((e=>t.isPrefixOf(e.field)))}tt(){if(this.path)for(let t=0;t<this.path.length;t++)this.it(this.path.get(t))}it(t){if(0===t.length)throw this.ct("Document fields must not be empty");if(Yn(this.et)&&Gn.test(t))throw this.ct('Document fields cannot begin and end with "__"')}}class Xn{constructor(t,e,n){this.databaseId=t,this.ignoreUndefinedProperties=e,this.serializer=n||_n(t)}ft(t,e,n,r=!1){return new Jn({et:t,methodName:e,lt:n,path:ht.emptyPath(),st:!1,ht:r},this.databaseId,this.serializer,this.ignoreUndefinedProperties)}}function Zn(t){const e=t._freezeSettings(),n=_n(t._databaseId);return new Xn(t._databaseId,!!e.ignoreUndefinedProperties,n)}function tr(t,e,n,r,s,i={}){const o=t.ft(i.merge||i.mergeFields?2:0,e,n,s);fr("Data must be an object, but it was:",o,r);const a=hr(r,o);let u,l;if(i.merge)u=new Ae(o.fieldMask),l=o.fieldTransforms;else if(i.mergeFields){const t=[];for(const r of i.mergeFields){const s=pr(e,r,n);if(!o.contains(s))throw new Y(L,`Field '${s}' is specified in your field mask but missing from your input data.`);wr(t,s)||t.push(s)}u=new Ae(t),l=o.fieldTransforms.filter((t=>u.covers(t.field)))}else u=null,l=o.fieldTransforms;return new Qn(new Ie(a),u,l)}class er extends Hn{_toFieldTransform(t){if(2!==t.et)throw 1===t.et?t.ct(`${this._methodName}() can only appear at the top level of your update data`):t.ct(`${this._methodName}() cannot be used with set() unless you pass {merge:true}`);return t.fieldMask.push(t.path),null}isEqual(t){return t instanceof er}}function nr(t,e,n){return new Jn({et:3,lt:e.settings.lt,methodName:t._methodName,st:n},e.databaseId,e.serializer,e.ignoreUndefinedProperties)}class rr extends Hn{_toFieldTransform(t){return new je(t.path,new Me)}isEqual(t){return t instanceof rr}}class sr extends Hn{constructor(t,e){super(t),this.dt=e}_toFieldTransform(t){const e=nr(this,t,!0),n=this.dt.map((t=>cr(t,e))),r=new Be(n);return new je(t.path,r)}isEqual(t){return this===t}}class ir extends Hn{constructor(t,e){super(t),this.dt=e}_toFieldTransform(t){const e=nr(this,t,!0),n=this.dt.map((t=>cr(t,e))),r=new $e(n);return new je(t.path,r)}isEqual(t){return this===t}}class or extends Hn{constructor(t,e){super(t),this.wt=e}_toFieldTransform(t){const e=new Ue(t.serializer,qe(t.serializer,this.wt));return new je(t.path,e)}isEqual(t){return this===t}}function ar(t,e,n,r){const s=t.ft(1,e,n);fr("Data must be an object, but it was:",s,r);const i=[],o=Ie.empty();xt(r,((t,r)=>{const a=gr(e,t,n);r=_(r);const u=s.ot(a);if(r instanceof er)i.push(a);else{const t=cr(r,u);null!=t&&(i.push(a),o.set(a,t))}}));const a=new Ae(i);return new Kn(o,a,s.fieldTransforms)}function ur(t,e,n,r,s,i){const o=t.ft(1,e,n),a=[pr(e,r,n)],u=[s];if(i.length%2!=0)throw new Y(L,`Function ${e}() needs to be called with an even number of arguments that alternate between field names and values.`);for(let t=0;t<i.length;t+=2)a.push(pr(e,i[t])),u.push(i[t+1]);const l=[],c=Ie.empty();for(let t=a.length-1;t>=0;--t)if(!wr(l,a[t])){const e=a[t];let n=u[t];n=_(n);const r=o.ot(e);if(n instanceof er)l.push(e);else{const t=cr(n,r);null!=t&&(l.push(e),c.set(e,t))}}const h=new Ae(l);return new Kn(c,h,o.fieldTransforms)}function lr(t,e,n,r=!1){return cr(n,t.ft(r?4:3,e))}function cr(t,e){if(dr(t=_(t)))return fr("Unsupported field value:",e,t),hr(t,e);if(t instanceof Hn)return function(t,e){if(!Yn(e.et))throw e.ct(`${t._methodName}() can only be used with update() and set()`);if(!e.path)throw e.ct(`${t._methodName}() is not currently supported inside arrays`);const n=t._toFieldTransform(e);n&&e.fieldTransforms.push(n)}(t,e),null;if(void 0===t&&e.ignoreUndefinedProperties)return null;if(e.path&&e.fieldMask.push(e.path),t instanceof Array){if(e.settings.st&&4!==e.et)throw e.ct("Nested arrays are not supported");return function(t,e){const n=[];let r=0;for(const s of t){let t=cr(s,e.ut(r));null==t&&(t={nullValue:"NULL_VALUE"}),n.push(t),r++}return{arrayValue:{values:n}}}(t,e)}return function(t,e){if(null===(t=_(t)))return{nullValue:"NULL_VALUE"};if("number"==typeof t)return qe(e.serializer,t);if("boolean"==typeof t)return{booleanValue:t};if("string"==typeof t)return{stringValue:t};if(t instanceof Date){const n=$t.fromDate(t);return{timestampValue:tn(e.serializer,n)}}if(t instanceof $t){const n=new $t(t.seconds,1e3*Math.floor(t.nanoseconds/1e3));return{timestampValue:tn(e.serializer,n)}}if(t instanceof Wn)return{geoPointValue:{latitude:t.latitude,longitude:t.longitude}};if(t instanceof Un)return{bytesValue:en(e.serializer,t._byteString)};if(t instanceof xn){const n=e.databaseId,r=t.firestore._databaseId;if(!r.isEqual(n))throw e.ct(`Document reference is for database ${r.projectId}/${r.database} but should be for database ${n.projectId}/${n.database}`);return{referenceValue:sn(t.firestore._databaseId||e.databaseId,t._key.path)}}throw e.ct(`Unsupported field value: ${gt(t)}`)}(t,e)}function hr(t,e){const n={};return function(t){for(const e in t)if(Object.prototype.hasOwnProperty.call(t,e))return!1;return!0}(t)?e.path&&e.path.length>0&&e.fieldMask.push(e.path):xt(t,((t,r)=>{const s=cr(r,e.rt(t));null!=s&&(n[t]=s)})),{mapValue:{fields:n}}}function dr(t){return!("object"!=typeof t||null===t||t instanceof Array||t instanceof Date||t instanceof $t||t instanceof Wn||t instanceof Un||t instanceof xn||t instanceof Hn)}function fr(t,e,n){if(!dr(n)||!function(t){return"object"==typeof t&&null!==t&&(Object.getPrototypeOf(t)===Object.prototype||null===Object.getPrototypeOf(t))}(n)){const r=gt(n);throw"an object"===r?e.ct(t+" a custom object"):e.ct(t+" "+r)}}function pr(t,e,n){if((e=_(e))instanceof jn)return e._internalPath;if("string"==typeof e)return gr(t,e);throw yr("Field path arguments must be of type string or ",t,!1,void 0,n)}const mr=new RegExp("[~\\*/\\[\\]]");function gr(t,e,n){if(e.search(mr)>=0)throw yr(`Invalid field path (${e}). Paths must not contain '~', '*', '/', '[', or ']'`,t,!1,void 0,n);try{return new jn(...e.split("."))._internalPath}catch(r){throw yr(`Invalid field path (${e}). Paths must not be empty, begin with '.', end with '.', or contain '..'`,t,!1,void 0,n)}}function yr(t,e,n,r,s){const i=r&&!r.isEmpty(),o=void 0!==s;let a=`Function ${e}() called with invalid data`;n&&(a+=" (via `toFirestore()`)"),a+=". ";let u="";return(i||o)&&(u+=" (found",i&&(u+=` in field ${r}`),o&&(u+=` in document ${s}`),u+=")"),new Y(L,a+t+u)}function wr(t,e){return t.some((t=>t.isEqual(e)))}class _r{constructor(t,e,n,r,s){this._firestore=t,this._userDataWriter=e,this._key=n,this._document=r,this._converter=s}get id(){return this._key.path.lastSegment()}get ref(){return new xn(this._firestore,this._converter,this._key)}exists(){return null!==this._document}data(){if(this._document){if(this._converter){const t=new vr(this._firestore,this._userDataWriter,this._key,this._document,null);return this._converter.fromFirestore(t)}return this._userDataWriter.convertValue(this._document.data.value)}}get(t){if(this._document){const e=this._document.data.field(Tr("DocumentSnapshot.get",t));if(null!==e)return this._userDataWriter.convertValue(e)}}}class vr extends _r{data(){return super.data()}}class br{constructor(t,e){this._docs=e,this.query=t}get docs(){return[...this._docs]}get size(){return this.docs.length}get empty(){return 0===this.docs.length}forEach(t,e){this._docs.forEach(t,e)}}function Er(t,e){return t=_(t),e=_(e),t instanceof _r&&e instanceof _r?t._firestore===e._firestore&&t._key.isEqual(e._key)&&(null===t._document?null===e._document:t._document.isEqual(e._document))&&t._converter===e._converter:t instanceof br&&e instanceof br&&$n(t.query,e.query)&&Rt(t.docs,e.docs,Er)}function Tr(t,e){return"string"==typeof e?gr(t,e):e instanceof jn?e._internalPath:e._delegate._internalPath}class Sr{}class Ar extends Sr{}function Ir(t,e,...n){let r=[];e instanceof Sr&&r.push(e),r=r.concat(n),function(t){const e=t.filter((t=>t instanceof Dr)).length,n=t.filter((t=>t instanceof kr)).length;if(e>1||e>0&&n>0)throw new Y(L,"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(...)))`.")}(r);for(const e of r)t=e._apply(t);return t}class kr extends Ar{constructor(t,e,n){super(),this._field=t,this._op=e,this._value=n,this.type="where"}static _create(t,e,n){return new kr(t,e,n)}_apply(t){const e=this._parse(t);return Wr(t._query,e),new Pn(t.firestore,t.converter,Ce(t._query,e))}_parse(t){const e=Zn(t.firestore),n=function(t,e,n,r,s,i,o){let a;if(s.isKeyField()){if("array-contains"===i||"array-contains-any"===i)throw new Y(L,`Invalid Query. You can't perform '${i}' queries on documentId().`);if("in"===i||"not-in"===i){Hr(o,i);const e=[];for(const n of o)e.push(zr(r,t,n));a={arrayValue:{values:e}}}else a=zr(r,t,o)}else"in"!==i&&"not-in"!==i&&"array-contains-any"!==i||Hr(o,i),a=lr(n,"where",o,"in"===i||"not-in"===i);return oe.create(s,i,a)}(t._query,0,e,t.firestore._databaseId,this._field,this._op,this._value);return n}}function Fr(t,e,n){const r=e,s=Tr("where",t);return kr._create(s,r,n)}class Dr extends Sr{constructor(t,e){super(),this.type=t,this._queryConstraints=e}static _create(t,e){return new Dr(t,e)}_parse(t){const e=this._queryConstraints.map((e=>e._parse(t))).filter((t=>t.getFilters().length>0));return 1===e.length?e[0]:ae.create(e,this._getOperator())}_apply(t){const e=this._parse(t);return 0===e.getFilters().length?t:(function(t,e){let n=t;const r=e.getFlattenedFilters();for(const t of r)Wr(n,t),n=Ce(n,t)}(t._query,e),new Pn(t.firestore,t.converter,Ce(t._query,e)))}_getQueryConstraints(){return this._queryConstraints}_getOperator(){return"and"===this.type?"and":"or"}}function Nr(...t){return t.forEach((t=>Qr("or",t))),Dr._create("or",t)}function Vr(...t){return t.forEach((t=>Qr("and",t))),Dr._create("and",t)}class Rr extends Ar{constructor(t,e){super(),this._field=t,this._direction=e,this.type="orderBy"}static _create(t,e){return new Rr(t,e)}_apply(t){const e=function(t,e,n){if(null!==t.startAt)throw new Y(L,"Invalid query. You must not call startAt() or startAfter() before calling orderBy().");if(null!==t.endAt)throw new Y(L,"Invalid query. You must not call endAt() or endBefore() before calling orderBy().");const r=new ye(e,n);return function(t,e){if(null===Ve(t)){const n=Re(t);null!==n&&Gr(t,n,e.field)}}(t,r),r}(t._query,this._field,this._direction);return new Pn(t.firestore,t.converter,function(t,e){const n=t.explicitOrderBy.concat([e]);return new Ne(t.path,t.collectionGroup,n,t.filters.slice(),t.limit,t.limitType,t.startAt,t.endAt)}(t._query,e))}}function Or(t,e="asc"){const n=e,r=Tr("orderBy",t);return Rr._create(r,n)}class xr extends Ar{constructor(t,e,n){super(),this.type=t,this._limit=e,this._limitType=n}static _create(t,e,n){return new xr(t,e,n)}_apply(t){return new Pn(t.firestore,t.converter,function(t,e,n){return new Ne(t.path,t.collectionGroup,t.explicitOrderBy.slice(),t.filters.slice(),e,n,t.startAt,t.endAt)}(t._query,this._limit,this._limitType))}}function Pr(t){return wt("limit",t),xr._create("limit",t,"F")}function Cr(t){return wt("limitToLast",t),xr._create("limitToLast",t,"L")}class qr extends Ar{constructor(t,e,n){super(),this.type=t,this._docOrFields=e,this._inclusive=n}static _create(t,e,n){return new qr(t,e,n)}_apply(t){const e=jr(t,this.type,this._docOrFields,this._inclusive);return new Pn(t.firestore,t.converter,function(t,e){return new Ne(t.path,t.collectionGroup,t.explicitOrderBy.slice(),t.filters.slice(),t.limit,t.limitType,e,t.endAt)}(t._query,e))}}function Lr(...t){return qr._create("startAt",t,!0)}function Mr(...t){return qr._create("startAfter",t,!1)}class Br extends Ar{constructor(t,e,n){super(),this.type=t,this._docOrFields=e,this._inclusive=n}static _create(t,e,n){return new Br(t,e,n)}_apply(t){const e=jr(t,this.type,this._docOrFields,this._inclusive);return new Pn(t.firestore,t.converter,function(t,e){return new Ne(t.path,t.collectionGroup,t.explicitOrderBy.slice(),t.filters.slice(),t.limit,t.limitType,t.startAt,e)}(t._query,e))}}function $r(...t){return Br._create("endBefore",t,!1)}function Ur(...t){return Br._create("endAt",t,!0)}function jr(t,e,n,r){if(n[0]=_(n[0]),n[0]instanceof _r)return function(t,e,n,r,s){if(!r)throw new Y(B,`Can't use a DocumentSnapshot that doesn't exist for ${n}().`);const i=[];for(const n of xe(t))if(n.field.isKeyField())i.push(Jt(e,r.key));else{const t=r.data.field(n.field);if(Ut(t))throw new Y(L,'Invalid query. You are trying to start or end a query using a document for which the field "'+n.field+'" is an uncommitted server timestamp. (Since the value of this field is unknown, you cannot start/end a query with it.)');if(null===t){const t=n.field.canonicalString();throw new Y(L,`Invalid query. You are trying to start or end a query using a document for which the field '${t}' (used as the orderBy) does not exist.`)}i.push(t)}return new re(i,s)}(t._query,t.firestore._databaseId,e,n[0]._document,r);{const s=Zn(t.firestore);return function(t,e,n,r,s,i){const o=t.explicitOrderBy;if(s.length>o.length)throw new Y(L,`Too many arguments provided to ${r}(). The number of arguments must be less than or equal to the number of orderBy() clauses`);const a=[];for(let i=0;i<s.length;i++){const u=s[i];if(o[i].field.isKeyField()){if("string"!=typeof u)throw new Y(L,`Invalid query. Expected a string for document ID in ${r}(), but got a ${typeof u}`);if(!Oe(t)&&-1!==u.indexOf("/"))throw new Y(L,`Invalid query. When querying a collection and ordering by documentId(), the value passed to ${r}() must be a plain document ID, but '${u}' contains a slash.`);const n=t.path.child(lt.fromString(u));if(!dt.isDocumentKey(n))throw new Y(L,`Invalid query. When querying a collection group and ordering by documentId(), the value passed to ${r}() must result in a valid document path, but '${n}' is not because it contains an odd number of segments.`);const s=new dt(n);a.push(Jt(e,s))}else{const t=lr(n,r,u);a.push(t)}}return new re(a,i)}(t._query,t.firestore._databaseId,s,e,n,r)}}function zr(t,e,n){if("string"==typeof(n=_(n))){if(""===n)throw new Y(L,"Invalid query. When querying with documentId(), you must provide a valid document ID, but it was an empty string.");if(!Oe(e)&&-1!==n.indexOf("/"))throw new Y(L,`Invalid query. When querying a collection by documentId(), you must provide a plain document ID, but '${n}' contains a '/' character.`);const r=e.path.child(lt.fromString(n));if(!dt.isDocumentKey(r))throw new Y(L,`Invalid query. When querying a collection group by documentId(), the value provided must result in a valid document path, but '${r}' is not because it has an odd number of segments (${r.length}).`);return Jt(t,new dt(r))}if(n instanceof xn)return Jt(t,n._key);throw new Y(L,`Invalid query. When querying with documentId(), you must provide a valid string or a DocumentReference, but it was: ${gt(n)}.`)}function Hr(t,e){if(!Array.isArray(t)||0===t.length)throw new Y(L,`Invalid Query. A non-empty array is required for '${e.toString()}' filters.`)}function Wr(t,e){if(e.isInequality()){const n=Re(t),r=e.field;if(null!==n&&!n.isEqual(r))throw new Y(L,`Invalid query. All where filters with an inequality (<, <=, !=, not-in, >, or >=) must be on the same field. But you have inequality filters on '${n.toString()}' and '${r.toString()}'`);const s=Ve(t);null!==s&&Gr(t,r,s)}const n=function(t,e){for(const n of t)for(const t of n.getFlattenedFilters())if(e.indexOf(t.op)>=0)return t.op;return null}(t.filters,function(t){switch(t){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[]}}(e.op));if(null!==n)throw n===e.op?new Y(L,`Invalid query. You cannot use more than one '${e.op.toString()}' filter.`):new Y(L,`Invalid query. You cannot use '${e.op.toString()}' filters with '${n.toString()}' filters.`)}function Gr(t,e,n){if(!n.isEqual(e))throw new Y(L,`Invalid query. You have a where filter with an inequality (<, <=, !=, not-in, >, or >=) on field '${e.toString()}' and so you must also use '${e.toString()}' as your first argument to orderBy(), but your first orderBy() is on field '${n.toString()}' instead.`)}function Qr(t,e){if(!(e instanceof kr||e instanceof Dr))throw new Y(L,`Function ${t}() requires AppliableConstraints created with a call to 'where(...)', 'or(...)', or 'and(...)'.`)}function Kr(t,e,n){let r;return r=t?n&&(n.merge||n.mergeFields)?t.toFirestore(e,n):t.toFirestore(e):e,r}class Yr extends class{convertValue(t,e="none"){switch(Wt(t)){case 0:return null;case 1:return t.booleanValue;case 2:return Mt(t.integerValue||t.doubleValue);case 3:return this.convertTimestamp(t.timestampValue);case 4:return this.convertServerTimestamp(t,e);case 5:return t.stringValue;case 6:return this.convertBytes(Bt(t.bytesValue));case 7:return this.convertReference(t.referenceValue);case 8:return this.convertGeoPoint(t.geoPointValue);case 9:return this.convertArray(t.arrayValue,e);case 10:return this.convertObject(t.mapValue,e);default:throw O()}}convertObject(t,e){return this.convertObjectMap(t.fields,e)}convertObjectMap(t,e="none"){const n={};return xt(t,((t,r)=>{n[t]=this.convertValue(r,e)})),n}convertGeoPoint(t){return new Wn(Mt(t.latitude),Mt(t.longitude))}convertArray(t,e){return(t.values||[]).map((t=>this.convertValue(t,e)))}convertServerTimestamp(t,e){switch(e){case"previous":const n=jt(t);return null==n?null:this.convertValue(n,e);case"estimate":return this.convertTimestamp(zt(t));default:return null}}convertTimestamp(t){const e=Lt(t);return new $t(e.seconds,e.nanos)}convertDocumentKey(t,e){const n=lt.fromString(t);x(wn(n));const r=new at(n.get(1),n.get(3)),s=new dt(n.popFirst(5));return r.isEqual(e)||N(`Document ${s} contains a document reference within a different database (${r.projectId}/${r.database}) which is not supported. It will be treated as a reference in the current database (${e.projectId}/${e.database}) instead.`),s}}{constructor(t){super(),this.firestore=t}convertBytes(t){return new Un(t)}convertReference(t){const e=this.convertDocumentKey(t,this.firestore._databaseId);return new xn(this.firestore,null,e)}}function Jr(t){const e=An((t=yt(t,xn)).firestore),n=new Yr(t.firestore);return Tn(e,[t._key]).then((e=>{x(1===e.length);const r=e[0];return new _r(t.firestore,n,t._key,r.isFoundDocument()?r:null,t.converter)}))}function Xr(t){!function(t){if("L"===t.limitType&&0===t.explicitOrderBy.length)throw new Y(G,"limitToLast() queries require specifying at least one orderBy() clause")}((t=yt(t,Pn))._query);const e=An(t.firestore),n=new Yr(t.firestore);return async function(t,e){const n=P(t),r=hn(n.serializer,Pe(e));return(await n.R("RunQuery",r.parent,{structuredQuery:r.structuredQuery})).filter((t=>!!t.document)).map((t=>function(t,e,n){const r=an(t,e.name),s=rn(e.updateTime),i=e.createTime?rn(e.createTime):_e.min(),o=new Ie({mapValue:{fields:e.fields}});return ke.newFoundDocument(r,s,i,o)}(n.serializer,t.document)))}(e,t._query).then((e=>{const r=e.map((e=>new vr(t.firestore,n,e.key,e,t.converter)));return"L"===t._query.limitType&&r.reverse(),new br(t,r)}))}function Zr(t,e,n){const r=Kr((t=yt(t,xn)).converter,e,n),s=tr(Zn(t.firestore),"setDoc",t._key,r,null!==t.converter,n);return En(An(t.firestore),[s.toMutation(t._key,ze.none())])}function ts(t,e,n,...r){const s=Zn((t=yt(t,xn)).firestore);let i;return i="string"==typeof(e=_(e))||e instanceof jn?ur(s,"updateDoc",t._key,e,n,r):ar(s,"updateDoc",t._key,e),En(An(t.firestore),[i.toMutation(t._key,ze.exists(!0))])}function es(t){return En(An((t=yt(t,xn)).firestore),[new Qe(t._key,ze.none())])}function ns(t,e){const n=Mn(t=yt(t,Cn)),r=Kr(t.converter,e),s=tr(Zn(t.firestore),"addDoc",n._key,r,null!==n.converter,{});return En(An(t.firestore),[s.toMutation(n._key,ze.exists(!1))]).then((()=>n))}function rs(t){return ss(t,{count:as()})}function ss(t,e){const n=yt(t.firestore,kn),r=An(n),s=function(t,e){const n=[];for(const r in t)Object.prototype.hasOwnProperty.call(t,r)&&n.push(e(t[r],r));return n}(e,((t,e)=>new Ft(e,t._aggregateType,t._internalFieldPath)));return async function(t,e,n){var r;const s=P(t),{request:i,Z:o}=function(t,e,n){const r=hn(t,e),s={},i=[];let o=0;return n.forEach((t=>{const e="aggregate_"+o++;s[e]=t.alias,"count"===t.$?i.push({alias:e,count:{}}):"avg"===t.$?i.push({alias:e,avg:{field:mn(t.fieldPath)}}):"sum"===t.$&&i.push({alias:e,sum:{field:mn(t.fieldPath)}})})),{request:{structuredAggregationQuery:{aggregations:i,structuredQuery:r.structuredQuery},parent:r.parent},Z:s}}(s.serializer,Pe(e),n),a=i.parent;s.connection.g||delete i.parent;const u=(await s.R("RunAggregationQuery",a,i,1)).filter((t=>!!t.result));x(1===u.length);const l=null===(r=u[0].result)||void 0===r?void 0:r.aggregateFields;return Object.keys(l).reduce(((t,e)=>(t[o[e]]=l[e],t)),{})}(r,t._query,s).then((e=>function(t,e,n){const r=new Yr(t);return new On(e,r,n)}(n,t,e)))}function is(t){return new Rn("sum",pr("sum",t))}function os(t){return new Rn("avg",pr("average",t))}function as(){return new Rn("count")}function us(t,e){var n,r;return t instanceof Rn&&e instanceof Rn&&t._aggregateType===e._aggregateType&&(null===(n=t._internalFieldPath)||void 0===n?void 0:n.canonicalString())===(null===(r=e._internalFieldPath)||void 0===r?void 0:r.canonicalString())}function ls(t,e){return $n(t.query,e.query)&&y(t.data(),e.data())}function cs(){return new er("deleteField")}function hs(){return new rr("serverTimestamp")}function ds(...t){return new sr("arrayUnion",t)}function fs(...t){return new ir("arrayRemove",t)}function ps(t){return new or("increment",t)}class ms{constructor(t,e){this._firestore=t,this._commitHandler=e,this._mutations=[],this._committed=!1,this._dataReader=Zn(t)}set(t,e,n){this._verifyNotCommitted();const r=gs(t,this._firestore),s=Kr(r.converter,e,n),i=tr(this._dataReader,"WriteBatch.set",r._key,s,null!==r.converter,n);return this._mutations.push(i.toMutation(r._key,ze.none())),this}update(t,e,n,...r){this._verifyNotCommitted();const s=gs(t,this._firestore);let i;return i="string"==typeof(e=_(e))||e instanceof jn?ur(this._dataReader,"WriteBatch.update",s._key,e,n,r):ar(this._dataReader,"WriteBatch.update",s._key,e),this._mutations.push(i.toMutation(s._key,ze.exists(!0))),this}delete(t){this._verifyNotCommitted();const e=gs(t,this._firestore);return this._mutations=this._mutations.concat(new Qe(e._key,ze.none())),this}commit(){return this._verifyNotCommitted(),this._committed=!0,this._mutations.length>0?this._commitHandler(this._mutations):Promise.resolve()}_verifyNotCommitted(){if(this._committed)throw new Y(z,"A write batch can no longer be used after commit() has been called.")}}function gs(t,e){if((t=_(t)).firestore!==e)throw new Y(L,"Provided document reference is from a different Firestore instance.");return t}function ys(t){const e=An(t=yt(t,kn));return new ms(t,(t=>En(e,t)))}class ws{constructor(t){this.datastore=t,this.readVersions=new Map,this.mutations=[],this.committed=!1,this.lastWriteError=null,this.writtenDocs=new Set}async lookup(t){if(this.ensureCommitNotCalled(),this.mutations.length>0)throw new Y(L,"Firestore transactions require all reads to be executed before all writes.");const e=await Tn(this.datastore,t);return e.forEach((t=>this.recordVersion(t))),e}set(t,e){this.write(e.toMutation(t,this.precondition(t))),this.writtenDocs.add(t.toString())}update(t,e){try{this.write(e.toMutation(t,this.preconditionForUpdate(t)))}catch(t){this.lastWriteError=t}this.writtenDocs.add(t.toString())}delete(t){this.write(new Qe(t,this.precondition(t))),this.writtenDocs.add(t.toString())}async commit(){if(this.ensureCommitNotCalled(),this.lastWriteError)throw this.lastWriteError;const t=this.readVersions;this.mutations.forEach((e=>{t.delete(e.key.toString())})),t.forEach(((t,e)=>{const n=dt.fromPath(e);this.mutations.push(new Ke(n,this.precondition(n)))})),await En(this.datastore,this.mutations),this.committed=!0}recordVersion(t){let e;if(t.isFoundDocument())e=t.version;else{if(!t.isNoDocument())throw O();e=_e.min()}const n=this.readVersions.get(t.key.toString());if(n){if(!e.isEqual(n))throw new Y(H,"Document version changed between two reads.")}else this.readVersions.set(t.key.toString(),e)}precondition(t){const e=this.readVersions.get(t.toString());return!this.writtenDocs.has(t.toString())&&e?e.isEqual(_e.min())?ze.exists(!1):ze.updateTime(e):ze.none()}preconditionForUpdate(t){const e=this.readVersions.get(t.toString());if(!this.writtenDocs.has(t.toString())&&e){if(e.isEqual(_e.min()))throw new Y(L,"Can't update a document that doesn't exist.");return ze.updateTime(e)}return ze.exists(!0)}write(t){this.ensureCommitNotCalled(),this.mutations.push(t)}ensureCommitNotCalled(){}}const _s={maxAttempts:5};class vs{constructor(t,e,n,r,s){this.asyncQueue=t,this.datastore=e,this.options=n,this.updateFunction=r,this.deferred=s,this.yt=n.maxAttempts,this.gt=new vn(this.asyncQueue,"transaction_retry")}run(){this.yt-=1,this._t()}_t(){this.gt.K((async()=>{const t=new ws(this.datastore),e=this.vt(t);e&&e.then((e=>{this.asyncQueue.enqueueAndForget((()=>t.commit().then((()=>{this.deferred.resolve(e)})).catch((t=>{this.bt(t)}))))})).catch((t=>{this.bt(t)}))}))}vt(t){try{const e=this.updateFunction(t);return!bt(e)&&e.catch&&e.then?e:(this.deferred.reject(Error("Transaction callback must return a Promise")),null)}catch(t){return this.deferred.reject(t),null}}bt(t){this.yt>0&&this.Et(t)?(this.yt-=1,this.asyncQueue.enqueueAndForget((()=>(this._t(),Promise.resolve())))):this.deferred.reject(t)}Et(t){if("FirebaseError"===t.name){const e=t.code;return"aborted"===e||"failed-precondition"===e||"already-exists"===e||!function(t){switch(t){default:return O();case C:case q:case M:case j:case Q:case K:case U:return!1;case L:case B:case"already-exists":case $:case z:case H:case W:case G:case"data-loss":return!0}}(e)}return!1}}function bs(){return"undefined"!=typeof document?document:null}class Es{constructor(t,e,n,r,s){this.asyncQueue=t,this.timerId=e,this.targetTimeMs=n,this.op=r,this.removalCallback=s,this.deferred=new J,this.then=this.deferred.promise.then.bind(this.deferred.promise),this.deferred.promise.catch((t=>{}))}static createAndSchedule(t,e,n,r,s){const i=Date.now()+n,o=new Es(t,e,i,r,s);return o.start(n),o}start(t){this.timerHandle=setTimeout((()=>this.handleDelayElapsed()),t)}skipDelay(){return this.handleDelayElapsed()}cancel(t){null!==this.timerHandle&&(this.clearTimeout(),this.deferred.reject(new Y(C,"Operation cancelled"+(t?": "+t:""))))}handleDelayElapsed(){this.asyncQueue.enqueueAndForget((()=>null!==this.timerHandle?(this.clearTimeout(),this.op().then((t=>this.deferred.resolve(t)))):Promise.resolve()))}clearTimeout(){null!==this.timerHandle&&(this.removalCallback(this),clearTimeout(this.timerHandle),this.timerHandle=null)}}class Ts{constructor(){this.It=Promise.resolve(),this.Tt=[],this.At=!1,this.Rt=[],this.Pt=null,this.Vt=!1,this.$t=!1,this.Nt=[],this.gt=new vn(this,"async_queue_retry"),this.Dt=()=>{const t=bs();t&&D("AsyncQueue","Visibility state changed to "+t.visibilityState),this.gt.H()};const t=bs();t&&"function"==typeof t.addEventListener&&t.addEventListener("visibilitychange",this.Dt)}get isShuttingDown(){return this.At}enqueueAndForget(t){this.enqueue(t)}enqueueAndForgetEvenWhileRestricted(t){this.Ft(),this.xt(t)}enterRestrictedMode(t){if(!this.At){this.At=!0,this.$t=t||!1;const e=bs();e&&"function"==typeof e.removeEventListener&&e.removeEventListener("visibilitychange",this.Dt)}}enqueue(t){if(this.Ft(),this.At)return new Promise((()=>{}));const e=new J;return this.xt((()=>this.At&&this.$t?Promise.resolve():(t().then(e.resolve,e.reject),e.promise))).then((()=>e.promise))}enqueueRetryable(t){this.enqueueAndForget((()=>(this.Tt.push(t),this.St())))}async St(){if(0!==this.Tt.length){try{await this.Tt[0](),this.Tt.shift(),this.gt.reset()}catch(t){if(!function(t){return"IndexedDbTransactionError"===t.name}(t))throw t;D("AsyncQueue","Operation failed with retryable error: "+t)}this.Tt.length>0&&this.gt.K((()=>this.St()))}}xt(t){const e=this.It.then((()=>(this.Vt=!0,t().catch((t=>{this.Pt=t,this.Vt=!1;const e=function(t){let e=t.message||"";return t.stack&&(e=t.stack.includes(t.message)?t.stack:t.message+"\n"+t.stack),e}(t);throw N("INTERNAL UNHANDLED ERROR: ",e),t})).then((t=>(this.Vt=!1,t))))));return this.It=e,e}enqueueAfterDelay(t,e,n){this.Ft(),this.Nt.indexOf(t)>-1&&(e=0);const r=Es.createAndSchedule(this,t,e,n,(t=>this.qt(t)));return this.Rt.push(r),r}Ft(){this.Pt&&O()}verifyOperationInProgress(){}async Ot(){let t;do{t=this.It,await t}while(t!==this.It)}kt(t){for(const e of this.Rt)if(e.timerId===t)return!0;return!1}Ct(t){return this.Ot().then((()=>{this.Rt.sort(((t,e)=>t.targetTimeMs-e.targetTimeMs));for(const e of this.Rt)if(e.skipDelay(),"all"!==t&&e.timerId===t)break;return this.Ot()}))}Mt(t){this.Nt.push(t)}qt(t){const e=this.Rt.indexOf(t);this.Rt.splice(e,1)}}class Ss{constructor(t,e){this._firestore=t,this._transaction=e,this._dataReader=Zn(t)}get(t){const e=gs(t,this._firestore),n=new Yr(this._firestore);return this._transaction.lookup([e._key]).then((t=>{if(!t||1!==t.length)return O();const r=t[0];if(r.isFoundDocument())return new _r(this._firestore,n,r.key,r,e.converter);if(r.isNoDocument())return new _r(this._firestore,n,e._key,null,e.converter);throw O()}))}set(t,e,n){const r=gs(t,this._firestore),s=Kr(r.converter,e,n),i=tr(this._dataReader,"Transaction.set",r._key,s,null!==r.converter,n);return this._transaction.set(r._key,i),this}update(t,e,n,...r){const s=gs(t,this._firestore);let i;return i="string"==typeof(e=_(e))||e instanceof jn?ur(this._dataReader,"Transaction.update",s._key,e,n,r):ar(this._dataReader,"Transaction.update",s._key,e),this._transaction.update(s._key,i),this}delete(t){const e=gs(t,this._firestore);return this._transaction.delete(e._key),this}}function As(t,e,n){const r=An(t=yt(t,kn)),s=Object.assign(Object.assign({},_s),n);!function(t){if(t.maxAttempts<1)throw new Y(L,"Max attempts must be at least 1")}(s);const i=new J;return new vs(new Ts,r,s,(n=>e(new Ss(t,n))),i).run(),i.promise}I=`${i}_lite`,t(new class{constructor(t,e,n){this.name=t,this.instanceFactory=e,this.type=n,this.multipleInstances=!1,this.serviceProps={},this.instantiationMode="LAZY",this.onInstanceCreated=null}setInstantiationMode(t){return this.instantiationMode=t,this}setMultipleInstances(t){return this.multipleInstances=t,this}setServiceProps(t){return this.serviceProps=t,this}setInstanceCreatedCallback(t){return this.onInstanceCreated=t,this}}("firestore/lite",((t,{instanceIdentifier:e,options:n})=>{const r=t.getProvider("app").getImmediate(),s=new kn(new et(t.getProvider("auth-internal")),new it(t.getProvider("app-check-internal")),function(t,e){if(!Object.prototype.hasOwnProperty.apply(t.options,["projectId"]))throw new Y(L,'"projectId" not provided in firebase.initializeApp.');return new at(t.options.projectId,e)}(r,e),r);return n&&s._setSettings(n),s}),"PUBLIC").setMultipleInstances(!0)),e("firestore-lite","3.13.0",""),e("firestore-lite","3.13.0","esm2017");export{Rn as AggregateField,On as AggregateQuerySnapshot,Un as Bytes,Cn as CollectionReference,xn as DocumentReference,_r as DocumentSnapshot,jn as FieldPath,Hn as FieldValue,kn as Firestore,Y as FirestoreError,Wn as GeoPoint,Pn as Query,Dr as QueryCompositeFilterConstraint,Ar as QueryConstraint,vr as QueryDocumentSnapshot,Br as QueryEndAtConstraint,kr as QueryFieldFilterConstraint,xr as QueryLimitConstraint,Rr as QueryOrderByConstraint,br as QuerySnapshot,qr as QueryStartAtConstraint,$t as Timestamp,Ss as Transaction,ms as WriteBatch,ns as addDoc,us as aggregateFieldEqual,ls as aggregateQuerySnapshotEqual,Vr as and,fs as arrayRemove,ds as arrayUnion,os as average,qn as collection,Ln as collectionGroup,Nn as connectFirestoreEmulator,as as count,es as deleteDoc,cs as deleteField,Mn as doc,zn as documentId,Ur as endAt,$r as endBefore,ss as getAggregate,rs as getCount,Jr as getDoc,Xr as getDocs,Dn as getFirestore,ps as increment,Fn as initializeFirestore,Pr as limit,Cr as limitToLast,Nr as or,Or as orderBy,Ir as query,$n as queryEqual,Bn as refEqual,As as runTransaction,hs as serverTimestamp,Zr as setDoc,F as setLogLevel,Er as snapshotEqual,Mr as startAfter,Lr as startAt,is as sum,Vn as terminate,ts as updateDoc,Fr as where,ys as writeBatch};
- //# sourceMappingURL=firebase-firestore-lite.js.map
|