firebase 9.17.2 → 9.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/app/dist/esm/index.esm.js +1 -1
  3. package/app/dist/index.cjs.js +1 -1
  4. package/app/dist/index.mjs +1 -1
  5. package/compat/app/dist/esm/index.esm.js +1 -1
  6. package/compat/app/dist/index.cjs.js +1 -1
  7. package/compat/app/dist/index.mjs +1 -1
  8. package/compat/dist/esm/index.esm.js +2 -2
  9. package/compat/dist/index.node.cjs +2 -2
  10. package/compat/dist/index.rn.cjs.js +2 -2
  11. package/firebase-analytics.js +1 -1
  12. package/firebase-app-check.js +1 -1
  13. package/firebase-app-compat.js +2 -2
  14. package/firebase-app.js +5 -5
  15. package/firebase-auth-compat.js +1 -1
  16. package/firebase-auth-compat.js.map +1 -1
  17. package/firebase-auth-cordova.js +1 -1
  18. package/firebase-auth-cordova.js.map +1 -1
  19. package/firebase-auth-react-native.js +1 -1
  20. package/firebase-auth-react-native.js.map +1 -1
  21. package/firebase-auth.js +1 -1
  22. package/firebase-auth.js.map +1 -1
  23. package/firebase-compat.js +4 -4
  24. package/firebase-compat.js.map +1 -1
  25. package/firebase-database.js +1 -1
  26. package/firebase-firestore-compat.js +1 -1
  27. package/firebase-firestore-compat.js.map +1 -1
  28. package/firebase-firestore-lite.js +1 -1
  29. package/firebase-firestore-lite.js.map +1 -1
  30. package/firebase-firestore.js +1 -1
  31. package/firebase-firestore.js.map +1 -1
  32. package/firebase-functions.js +1 -1
  33. package/firebase-installations.js +1 -1
  34. package/firebase-messaging-sw.js +1 -1
  35. package/firebase-messaging.js +1 -1
  36. package/firebase-performance-standalone-compat.es2017.js +5 -5
  37. package/firebase-performance-standalone-compat.js +1 -1
  38. package/firebase-performance.js +1 -1
  39. package/firebase-remote-config.js +1 -1
  40. package/firebase-storage.js +1 -1
  41. package/package.json +7 -7
@@ -1,3 +1,3 @@
1
- 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.17.2/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 k="9.17.2";const I=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){I.setLogLevel(t)}function D(t,...e){if(I.logLevel<=v.DEBUG){const n=e.map(R);I.debug(`Firestore (${k}): ${t}`,...n)}}function V(t,...e){if(I.logLevel<=v.ERROR){const n=e.map(R);I.error(`Firestore (${k}): ${t}`,...n)}}function N(t,...e){if(I.logLevel<=v.WARN){const n=e.map(R);I.warn(`Firestore (${k}): ${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 (${k}) INTERNAL ASSERTION FAILED: `+t;throw V(e),new Error(e)}function C(t,e){t||O()}function x(t,e){return t}const P="cancelled",L="unknown",q="invalid-argument",M="deadline-exceeded",B="not-found",$="permission-denied",U="unauthenticated",j="resource-exhausted",H="failed-precondition",z="aborted",G="out-of-range",K="unimplemented",W="internal",Q="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?(C("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,r){this.t=t,this.i=e,this.o=n,this.u=r,this.type="FirstParty",this.user=A.FIRST_PARTY,this.h=new Map}l(){return this.u?this.u():(C(!("object"!=typeof this.t||null===this.t||!this.t.auth||!this.t.auth.getAuthHeaderValueForFirstParty)),this.t.auth.getAuthHeaderValueForFirstParty([]))}get headers(){this.h.set("X-Goog-AuthUser",this.i);const t=this.l();return t&&this.h.set("Authorization",t),this.o&&this.h.set("X-Goog-Iam-Authorization-Token",this.o),this.h}}class rt{constructor(t,e,n,r){this.t=t,this.i=e,this.o=n,this.u=r}getToken(){return Promise.resolve(new nt(this.t,this.i,this.o,this.u))}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.m=t,this.appCheck=null,t.onInit((t=>{this.appCheck=t}))}getToken(){return this.appCheck?this.appCheck.getToken().then((t=>t?(C("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){this.databaseId=t,this.appId=e,this.persistenceKey=n,this.host=r,this.ssl=s,this.forceLongPolling=i,this.autoDetectLongPolling=o,this.useFetchStreams=a}}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(q,`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(q,`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(q,"Path has trailing escape character: "+t);const e=t[r+1];if("\\"!==e&&"."!==e&&"`"!==e)throw new Y(q,"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(q,"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(q,`Function ${t}() cannot be called with an empty ${e}.`)}function pt(t){if(!dt.isDocumentKey(t))throw new Y(q,`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(q,`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(q,"Type does not match the expected instance. Did you pass a reference from a different Firestore SDK?");{const n=gt(t);throw new Y(q,`Expected type '${e.name}', but it was: ${n}`)}}return t}function wt(t,e){if(e<=0)throw new Y(q,`Function ${t}() requires a positive number, but it was: ${e}.`)}function _t(t){return null==t}function vt(t){return 0===t&&1/t==-1/0}const bt={BatchGetDocuments:"batchGet",Commit:"commit",RunQuery:"runQuery",RunAggregationQuery:"runAggregationQuery"};var Et,Tt;function St(t){if(void 0===t)return V("RPC_ERROR","HTTP error has no status"),L;switch(t){case 200:return"ok";case 400:return H;case 401:return U;case 403:return $;case 404:return B;case 409:return z;case 416:return G;case 429:return j;case 499:return P;case 500:return L;case 501:return K;case 503:return Q;case 504:return M;default:return t>=200&&t<300?"ok":t>=400&&t<500?H:t>=500&&t<600?W:L}}(Tt=Et||(Et={}))[Tt.OK=0]="OK",Tt[Tt.CANCELLED=1]="CANCELLED",Tt[Tt.UNKNOWN=2]="UNKNOWN",Tt[Tt.INVALID_ARGUMENT=3]="INVALID_ARGUMENT",Tt[Tt.DEADLINE_EXCEEDED=4]="DEADLINE_EXCEEDED",Tt[Tt.NOT_FOUND=5]="NOT_FOUND",Tt[Tt.ALREADY_EXISTS=6]="ALREADY_EXISTS",Tt[Tt.PERMISSION_DENIED=7]="PERMISSION_DENIED",Tt[Tt.UNAUTHENTICATED=16]="UNAUTHENTICATED",Tt[Tt.RESOURCE_EXHAUSTED=8]="RESOURCE_EXHAUSTED",Tt[Tt.FAILED_PRECONDITION=9]="FAILED_PRECONDITION",Tt[Tt.ABORTED=10]="ABORTED",Tt[Tt.OUT_OF_RANGE=11]="OUT_OF_RANGE",Tt[Tt.UNIMPLEMENTED=12]="UNIMPLEMENTED",Tt[Tt.INTERNAL=13]="INTERNAL",Tt[Tt.UNAVAILABLE=14]="UNAVAILABLE",Tt[Tt.DATA_LOSS=15]="DATA_LOSS";class At extends class{constructor(t){this.databaseInfo=t,this.databaseId=t.databaseId;const e=t.ssl?"https":"http";this.p=e+"://"+t.host,this.g="projects/"+this.databaseId.projectId+"/databases/"+this.databaseId.database+"/documents"}get v(){return!1}A(t,e,n,r,s){const i=this.I(t,e);D("RestConnection","Sending: ",i,n);const o={};return this.T(o,r,s),this.R(t,i,o,n).then((t=>(D("RestConnection","Received: ",t),t)),(e=>{throw N("RestConnection",`${t} failed with error: `,e,"url: ",i,"request:",n),e}))}P(t,e,n,r,s,i){return this.A(t,e,n,r,s)}T(t,e,n){t["X-Goog-Api-Client"]="gl-js/ fire/"+k,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=bt[t];return`${this.p}/v1/${e}:${n}`}}{constructor(t,e){super(t),this.V=e}$(t,e){throw new Error("Not supported by FetchConnection")}async R(t,e,n,r){var s;const i=JSON.stringify(r);let o;try{o=await this.V(e,{method:"POST",headers:n,body:i})}catch(t){const e=t;throw new Y(St(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(St(o.status),`Request failed with error: ${null!=e?e:o.statusText}`)}return o.json()}}const kt=/^[_a-zA-Z][_a-zA-Z0-9]*(?:\.[_a-zA-Z][_a-zA-Z0-9]*)*$/;class It{constructor(t){this.alias=t}static D(t){return kt.test(t)}canonicalString(){let t=this.alias.replace(/\\/g,"\\\\").replace(/`/g,"\\`");return It.D(t)||(t="`"+t+"`"),t}}class Ft{constructor(t,e,n){this.alias=t,this.N=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 Vt{static F(){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 Nt(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 Ct(t,e){for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&e(n,t[n])}class xt extends Error{constructor(){super(...arguments),this.name="Base64DecodeError"}}class Pt{constructor(t){this.binaryString=t}static fromBase64String(t){const e=function(t){try{return atob(t)}catch(t){throw t instanceof DOMException?new xt("Invalid base64 string: "+t):t}}(t);return new Pt(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 Pt(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 Nt(this.binaryString,t.binaryString)}isEqual(t){return this.binaryString===t.binaryString}}Pt.EMPTY_BYTE_STRING=new Pt("");const Lt=new RegExp(/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.(\d+))?Z$/);function qt(t){if(C(!!t),"string"==typeof t){let e=0;const n=Lt.exec(t);if(C(!!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?Pt.fromBase64String(t):Pt.fromUint8Array(t)}class $t{constructor(t,e){if(this.seconds=t,this.nanoseconds=e,e<0)throw new Y(q,"Timestamp nanoseconds out of range: "+e);if(e>=1e9)throw new Y(q,"Timestamp nanoseconds out of range: "+e);if(t<-62135596800)throw new Y(q,"Timestamp seconds out of range: "+t);if(t>=253402300800)throw new Y(q,"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?Nt(this.nanoseconds,t.nanoseconds):Nt(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 Ht(t){const e=qt(t.mapValue.fields.__local_write_time__.timestampValue);return new $t(e.seconds,e.nanos)}const zt={fields:{__type__:{stringValue:"__max__"}}};function Gt(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 Kt(t,e){if(t===e)return!0;const n=Gt(t);if(n!==Gt(e))return!1;switch(n){case 0:case 9007199254740991:return!0;case 1:return t.booleanValue===e.booleanValue;case 4:return Ht(t).isEqual(Ht(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=qt(t.timestampValue),r=qt(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?vt(n)===vt(r):isNaN(n)&&isNaN(r)}return!1}(t,e);case 9:return Rt(t.arrayValue.values||[],e.arrayValue.values||[],Kt);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]||!Kt(n[t],r[t])))return!1;return!0}(t,e);default:return O()}}function Wt(t,e){return void 0!==(t.values||[]).find((t=>Kt(t,e)))}function Qt(t,e){if(t===e)return 0;const n=Gt(t),r=Gt(e);if(n!==r)return Nt(n,r);switch(n){case 0:case 9007199254740991:return 0;case 1:return Nt(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(Ht(t),Ht(e));case 5:return Nt(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=Nt(n[t],r[t]);if(0!==e)return e}return Nt(n.length,r.length)}(t.referenceValue,e.referenceValue);case 8:return function(t,e){const n=Nt(Mt(t.latitude),Mt(e.latitude));return 0!==n?n:Nt(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=Qt(n[t],r[t]);if(e)return e}return Nt(n.length,r.length)}(t.arrayValue,e.arrayValue);case 10:return function(t,e){if(t===zt&&e===zt)return 0;if(t===zt)return 1;if(e===zt)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=Nt(r[t],i[t]);if(0!==e)return e;const o=Qt(n[r[t]],s[i[t]]);if(0!==o)return o}return Nt(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 Nt(t,e);const n=qt(t),r=qt(e),s=Nt(n.seconds,r.seconds);return 0!==s?s:Nt(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 Ct(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(!Kt(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(Qt(e,this.value)):null!==e&&Gt(this.value)===Gt(e)&&this.matchesComparison(Qt(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.S=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.S||(this.S=this.filters.reduce(((t,e)=>t.concat(e.getFlattenedFilters())),[])),this.S}getFilters(){return Object.assign([],this.filters)}getFirstInequalityField(){const t=this.q((t=>t.isInequality()));return null!==t?t.field:null}q(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)&&Kt(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)&&Wt(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&&Wt(this.value.arrayValue,e)}}class me extends oe{constructor(t,e){super(t,"not-in",e)}matches(t){if(Wt(this.value.arrayValue,{nullValue:"NULL_VALUE"}))return!1;const e=t.data.field(this.field);return null!==e&&!Wt(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=>Wt(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 ke{constructor(t){this.value=t}static empty(){return new ke({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 Kt(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){Ct(e,((e,n)=>t[e]=n));for(const e of n)delete t[e]}clone(){return new ke(ne(this.value))}}class Ie{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 Ie(t,0,_e.min(),_e.min(),_e.min(),ke.empty(),0)}static newFoundDocument(t,e,n,r){return new Ie(t,1,e,_e.min(),n,r,0)}static newNoDocument(t,e){return new Ie(t,2,e,_e.min(),_e.min(),ke.empty(),0)}static newUnknownDocument(t,e){return new Ie(t,3,e,_e.min(),_e.min(),ke.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=ke.empty(),this.documentState=0,this}convertToUnknownDocument(t){return this.version=t,this.documentType=3,this.data=ke.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 Ie&&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 Ie(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.O=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 Ve{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.k=null,this.C=null,this.startAt,this.endAt}}function Ne(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 Ce(t){const e=x(t);if(null===e.k){e.k=[];const t=Re(e),n=Ne(e);if(null!==t&&null===n)t.isKeyField()||e.k.push(new ye(t)),e.k.push(new ye(ht.keyField(),"asc"));else{let t=!1;for(const n of e.explicitOrderBy)e.k.push(n),n.field.isKeyField()&&(t=!0);if(!t){const t=e.explicitOrderBy.length>0?e.explicitOrderBy[e.explicitOrderBy.length-1].dir:"asc";e.k.push(new ye(ht.keyField(),t))}}}return e.k}function xe(t){const e=x(t);if(!e.C)if("F"===e.limitType)e.C=De(e.path,e.collectionGroup,Ce(e),e.filters,e.limit,e.startAt,e.endAt);else{const t=[];for(const n of Ce(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.C=De(e.path,e.collectionGroup,t,e.filters,e.limit,n,r)}return e.C}function Pe(t,e){e.getFirstInequalityField(),Re(t);const n=t.filters.concat([e]);return new Ve(t.path,t.collectionGroup,t.explicitOrderBy.slice(),n,t.limit,t.limitType,t.startAt,t.endAt)}function Le(t,e){return function(t){return"number"==typeof t&&Number.isInteger(t)&&!vt(t)&&t<=Number.MAX_SAFE_INTEGER&&t>=Number.MIN_SAFE_INTEGER}(e)?function(t){return{integerValue:""+t}}(e):function(t,e){if(t.L){if(isNaN(e))return{doubleValue:"NaN"};if(e===1/0)return{doubleValue:"Infinity"};if(e===-1/0)return{doubleValue:"-Infinity"}}return{doubleValue:vt(e)?"-0":e}}(t,e)}class qe{constructor(){this._=void 0}}class Me extends qe{}class Be extends qe{constructor(t){super(),this.elements=t}}class $e extends qe{constructor(t){super(),this.elements=t}}class Ue extends qe{constructor(t,e){super(),this.M=t,this.U=e}}class je{constructor(t,e){this.field=t,this.transform=e}}class He{constructor(t,e){this.updateTime=t,this.exists=e}static none(){return new He}static exists(t){return new He(void 0,t)}static updateTime(t){return new He(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 ze{}class Ge extends ze{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 Ke extends ze{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 We extends ze{constructor(t,e){super(),this.key=t,this.precondition=e,this.type=2,this.fieldTransforms=[]}getFieldMask(){return null}}class Qe extends ze{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.L=e}}function tn(t,e){return t.L?`${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.L?e.toBase64():e.toUint8Array()}function nn(t,e){return tn(t,e.toTimestamp())}function rn(t){return C(!!t),_e.fromTimestamp(function(t){const e=qt(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 C(wn(e)),e}(e);if(n.get(1)!==t.databaseId.projectId)throw new Y(q,"Tried to deserialize key from different project: "+n.get(1)+" vs "+t.databaseId.projectId);if(n.get(3)!==t.databaseId.database)throw new Y(q,"Tried to deserialize key from different database: "+n.get(3)+" vs "+t.databaseId.database);return new dt((C((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.L||_t(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.j=t,this.timerId=e,this.B=n,this.W=r,this.G=s,this.K=0,this.Y=null,this.H=Date.now(),this.reset()}reset(){this.K=0}Z(){this.K=this.G}J(t){this.cancel();const e=Math.floor(this.K+this.X()),n=Math.max(0,Date.now()-this.H),r=Math.max(0,e-n);r>0&&D("ExponentialBackoff",`Backing off for ${r} ms (base delay: ${this.K} ms, delay with jitter: ${e} ms, last attempt: ${n} ms ago)`),this.Y=this.j.enqueueAfterDelay(this.timerId,r,(()=>(this.H=Date.now(),t()))),this.K*=this.W,this.K<this.B&&(this.K=this.B),this.K>this.G&&(this.K=this.G)}tt(){null!==this.Y&&(this.Y.skipDelay(),this.Y=null)}cancel(){null!==this.Y&&(this.Y.cancel(),this.Y=null)}X(){return(Math.random()-.5)*this.K}}class bn extends class{}{constructor(t,e,n,r){super(),this.authCredentials=t,this.appCheckCredentials=e,this.connection=n,this.M=r,this.et=!1}nt(){if(this.et)throw new Y(H,"The client has already been terminated.")}A(t,e,n){return this.nt(),Promise.all([this.authCredentials.getToken(),this.appCheckCredentials.getToken()]).then((([r,s])=>this.connection.A(t,e,n,r,s))).catch((t=>{throw"FirebaseError"===t.name?(t.code===U&&(this.authCredentials.invalidateToken(),this.appCheckCredentials.invalidateToken()),t):new Y(L,t.toString())}))}P(t,e,n,r){return this.nt(),Promise.all([this.authCredentials.getToken(),this.appCheckCredentials.getToken()]).then((([s,i])=>this.connection.P(t,e,n,s,i,r))).catch((t=>{throw"FirebaseError"===t.name?(t.code===U&&(this.authCredentials.invalidateToken(),this.appCheckCredentials.invalidateToken()),t):new Y(L,t.toString())}))}terminate(){this.et=!0}}async function En(t,e){const n=x(t),r=ln(n.M)+"/documents",s={writes:e.map((t=>function(t,e){let n;if(e instanceof Ge)n={update:cn(t,e.key,e.value)};else if(e instanceof We)n={delete:on(t,e.key)};else if(e instanceof Ke)n={update:cn(t,e.key,e.data),updateMask:yn(e.fieldMask)};else{if(!(e instanceof Qe))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.U};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.M,t)))};await n.A("Commit",r,s)}async function Tn(t,e){const n=x(t),r=ln(n.M)+"/documents",s={documents:e.map((t=>on(n.M,t)))},i=await n.P("BatchGetDocuments",r,s,e.length),o=new Map;i.forEach((t=>{const e=function(t,e){return"found"in e?function(t,e){C(!!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 ke({mapValue:{fields:e.found.fields}});return Ie.newFoundDocument(n,r,s,i)}(t,e):"missing"in e?function(t,e){C(!!e.missing),C(!!e.readTime);const n=an(t,e.missing),r=rn(e.readTime);return Ie.newNoDocument(n,r)}(t,e):O()}(n.M,t);o.set(e.key.toString(),e)}));const a=[];return e.forEach((t=>{const e=o.get(t.toString());C(!!e),a.push(e)})),a}const Sn=new Map;function An(t){if(t._terminated)throw new Y(H,"The client has already been terminated.");if(!Sn.has(t)){D("ComponentProvider","Initializing Datastore");const i=function(t){return new At(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,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 kn{constructor(t){var e;if(void 0===t.host){if(void 0!==t.ssl)throw new Y(q,"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,void 0===t.cacheSizeBytes)this.cacheSizeBytes=41943040;else{if(-1!==t.cacheSizeBytes&&t.cacheSizeBytes<1048576)throw new Y(q,"cacheSizeBytes must be at least 1048576");this.cacheSizeBytes=t.cacheSizeBytes}this.experimentalForceLongPolling=!!t.experimentalForceLongPolling,this.experimentalAutoDetectLongPolling=!!t.experimentalAutoDetectLongPolling,this.useFetchStreams=!!t.useFetchStreams,function(t,e,n,r){if(!0===e&&!0===r)throw new Y(q,"experimentalForceLongPolling and experimentalAutoDetectLongPolling cannot be used together.")}(0,t.experimentalForceLongPolling,0,t.experimentalAutoDetectLongPolling)}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&&this.ignoreUndefinedProperties===t.ignoreUndefinedProperties&&this.useFetchStreams===t.useFetchStreams}}class In{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 kn({}),this._settingsFrozen=!1}get app(){if(!this._app)throw new Y(H,"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(H,"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 kn(t),void 0!==t.credentials&&(this._authCredentials=function(t){if(!t)return new Z;switch(t.type){case"gapi":const e=t.client;return new rt(e,t.sessionIndex||"0",t.iamToken||null,t.authTokenFactory||null);case"provider":return t.client;default:throw new Y(q,"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(H,"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&&Vn(o,...t)}return o}function Vn(t,e,n,r={}){var s;const i=(t=yt(t,In))._getSettings();if("firestore.googleapis.com"!==i.host&&i.host!==e&&N("Host has been set in both settings() and useEmulator(), emulator host will be used"),t._setSettings(Object.assign(Object.assign({},i),{host:`${e}:${n}`,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(q,"mockUserToken must contain 'sub' or 'user_id' field!");n=new A(i)}t._authCredentials=new tt(new X(e,n))}}function Nn(t){return t=yt(t,In),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.convertValue(this._data.value)}}class Cn{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 Pn(this.firestore,this.converter,this._key.path.popLast())}withConverter(t){return new Cn(this.firestore,t,this._key)}}class xn{constructor(t,e,n){this.converter=e,this._query=n,this.type="query",this.firestore=t}withConverter(t){return new xn(this.firestore,t,this._query)}}class Pn extends xn{constructor(t,e,n){super(t,e,new Ve(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 Cn(this.firestore,null,new dt(t))}withConverter(t){return new Pn(this.firestore,t,this._path)}}function Ln(t,e,...n){if(t=_(t),ft("collection","path",e),t instanceof In){const r=lt.fromString(e,...n);return mt(r),new Pn(t,null,r)}{if(!(t instanceof Cn||t instanceof Pn))throw new Y(q,"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 Pn(t.firestore,null,r)}}function qn(t,e){if(t=yt(t,In),ft("collectionGroup","collection id",e),e.indexOf("/")>=0)throw new Y(q,`Invalid collection ID '${e}' passed to function collectionGroup(). Collection IDs must not contain '/'.`);return new xn(t,null,function(t){return new Ve(lt.emptyPath(),t)}(e))}function Mn(t,e,...n){if(t=_(t),1===arguments.length&&(e=Vt.F()),ft("doc","path",e),t instanceof In){const r=lt.fromString(e,...n);return pt(r),new Cn(t,null,new dt(r))}{if(!(t instanceof Cn||t instanceof Pn))throw new Y(q,"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 Cn(t.firestore,t instanceof Pn?t.converter:null,new dt(r))}}function Bn(t,e){return t=_(t),e=_(e),(t instanceof Cn||t instanceof Pn)&&(e instanceof Cn||e instanceof Pn)&&t.firestore===e.firestore&&t.path===e.path&&t.converter===e.converter}function $n(t,e){return t=_(t),e=_(e),t instanceof xn&&e instanceof xn&&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)}(xe(t),xe(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(Pt.fromBase64String(t))}catch(t){throw new Y(q,"Failed to construct data from Base64 string: "+t)}}static fromUint8Array(t){return new Un(Pt.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(q,"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 Hn(){return new jn("__name__")}class zn{constructor(t){this._methodName=t}}class Gn{constructor(t,e){if(!isFinite(t)||t<-90||t>90)throw new Y(q,"Latitude must be a number between -90 and 90, but was: "+t);if(!isFinite(e)||e<-180||e>180)throw new Y(q,"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 Nt(this._lat,t._lat)||Nt(this._long,t._long)}}const Kn=/^__.*__$/;class Wn{constructor(t,e,n){this.data=t,this.fieldMask=e,this.fieldTransforms=n}toMutation(t,e){return null!==this.fieldMask?new Ke(t,this.data,this.fieldMask,e,this.fieldTransforms):new Ge(t,this.data,e,this.fieldTransforms)}}class Qn{constructor(t,e,n){this.data=t,this.fieldMask=e,this.fieldTransforms=n}toMutation(t,e){return new Ke(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.M=n,this.ignoreUndefinedProperties=r,void 0===s&&this.rt(),this.fieldTransforms=s||[],this.fieldMask=i||[]}get path(){return this.settings.path}get st(){return this.settings.st}it(t){return new Jn(Object.assign(Object.assign({},this.settings),t),this.databaseId,this.M,this.ignoreUndefinedProperties,this.fieldTransforms,this.fieldMask)}ot(t){var e;const n=null===(e=this.path)||void 0===e?void 0:e.child(t),r=this.it({path:n,ut:!1});return r.ct(t),r}at(t){var e;const n=null===(e=this.path)||void 0===e?void 0:e.child(t),r=this.it({path:n,ut:!1});return r.rt(),r}ht(t){return this.it({path:void 0,ut:!0})}lt(t){return yr(t,this.settings.methodName,this.settings.ft||!1,this.path,this.settings.dt)}contains(t){return void 0!==this.fieldMask.find((e=>t.isPrefixOf(e)))||void 0!==this.fieldTransforms.find((e=>t.isPrefixOf(e.field)))}rt(){if(this.path)for(let t=0;t<this.path.length;t++)this.ct(this.path.get(t))}ct(t){if(0===t.length)throw this.lt("Document fields must not be empty");if(Yn(this.st)&&Kn.test(t))throw this.lt('Document fields cannot begin and end with "__"')}}class Xn{constructor(t,e,n){this.databaseId=t,this.ignoreUndefinedProperties=e,this.M=n||_n(t)}wt(t,e,n,r=!1){return new Jn({st:t,methodName:e,dt:n,path:ht.emptyPath(),ut:!1,ft:r},this.databaseId,this.M,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.wt(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(q,`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 Wn(new ke(a),u,l)}class er extends zn{_toFieldTransform(t){if(2!==t.st)throw 1===t.st?t.lt(`${this._methodName}() can only appear at the top level of your update data`):t.lt(`${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({st:3,dt:e.settings.dt,methodName:t._methodName,ut:n},e.databaseId,e.M,e.ignoreUndefinedProperties)}class rr extends zn{_toFieldTransform(t){return new je(t.path,new Me)}isEqual(t){return t instanceof rr}}class sr extends zn{constructor(t,e){super(t),this.yt=e}_toFieldTransform(t){const e=nr(this,t,!0),n=this.yt.map((t=>cr(t,e))),r=new Be(n);return new je(t.path,r)}isEqual(t){return this===t}}class ir extends zn{constructor(t,e){super(t),this.yt=e}_toFieldTransform(t){const e=nr(this,t,!0),n=this.yt.map((t=>cr(t,e))),r=new $e(n);return new je(t.path,r)}isEqual(t){return this===t}}class or extends zn{constructor(t,e){super(t),this.gt=e}_toFieldTransform(t){const e=new Ue(t.M,Le(t.M,this.gt));return new je(t.path,e)}isEqual(t){return this===t}}function ar(t,e,n,r){const s=t.wt(1,e,n);fr("Data must be an object, but it was:",s,r);const i=[],o=ke.empty();Ct(r,((t,r)=>{const a=gr(e,t,n);r=_(r);const u=s.at(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 Qn(o,a,s.fieldTransforms)}function ur(t,e,n,r,s,i){const o=t.wt(1,e,n),a=[pr(e,r,n)],u=[s];if(i.length%2!=0)throw new Y(q,`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=ke.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.at(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 Qn(c,h,o.fieldTransforms)}function lr(t,e,n,r=!1){return cr(n,t.wt(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 zn)return function(t,e){if(!Yn(e.st))throw e.lt(`${t._methodName}() can only be used with update() and set()`);if(!e.path)throw e.lt(`${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.ut&&4!==e.st)throw e.lt("Nested arrays are not supported");return function(t,e){const n=[];let r=0;for(const s of t){let t=cr(s,e.ht(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 Le(e.M,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.M,n)}}if(t instanceof $t){const n=new $t(t.seconds,1e3*Math.floor(t.nanoseconds/1e3));return{timestampValue:tn(e.M,n)}}if(t instanceof Gn)return{geoPointValue:{latitude:t.latitude,longitude:t.longitude}};if(t instanceof Un)return{bytesValue:en(e.M,t._byteString)};if(t instanceof Cn){const n=e.databaseId,r=t.firestore._databaseId;if(!r.isEqual(n))throw e.lt(`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.lt(`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):Ct(t,((t,r)=>{const s=cr(r,e.ot(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 Gn||t instanceof Un||t instanceof Cn||t instanceof zn)}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.lt(t+" a custom object"):e.lt(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(q,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 Cn(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 kr(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 Ir)).length;if(e>1||e>0&&n>0)throw new Y(q,"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 Ir 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 Ir(t,e,n)}_apply(t){const e=this._parse(t);return Gr(t._query,e),new xn(t.firestore,t.converter,Pe(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(q,`Invalid Query. You can't perform '${i}' queries on documentId().`);if("in"===i||"not-in"===i){zr(o,i);const e=[];for(const n of o)e.push(Hr(r,t,n));a={arrayValue:{values:e}}}else a=Hr(r,t,o)}else"in"!==i&&"not-in"!==i&&"array-contains-any"!==i||zr(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 Ir._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)Gr(n,t),n=Pe(n,t)}(t._query,e),new xn(t.firestore,t.converter,Pe(t._query,e)))}_getQueryConstraints(){return this._queryConstraints}_getOperator(){return"and"===this.type?"and":"or"}}function Vr(...t){return t.forEach((t=>Wr("or",t))),Dr._create("or",t)}function Nr(...t){return t.forEach((t=>Wr("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(q,"Invalid query. You must not call startAt() or startAfter() before calling orderBy().");if(null!==t.endAt)throw new Y(q,"Invalid query. You must not call endAt() or endBefore() before calling orderBy().");const r=new ye(e,n);return function(t,e){if(null===Ne(t)){const n=Re(t);null!==n&&Kr(t,n,e.field)}}(t,r),r}(t._query,this._field,this._direction);return new xn(t.firestore,t.converter,function(t,e){const n=t.explicitOrderBy.concat([e]);return new Ve(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 Cr extends Ar{constructor(t,e,n){super(),this.type=t,this._limit=e,this._limitType=n}static _create(t,e,n){return new Cr(t,e,n)}_apply(t){return new xn(t.firestore,t.converter,function(t,e,n){return new Ve(t.path,t.collectionGroup,t.explicitOrderBy.slice(),t.filters.slice(),e,n,t.startAt,t.endAt)}(t._query,this._limit,this._limitType))}}function xr(t){return wt("limit",t),Cr._create("limit",t,"F")}function Pr(t){return wt("limitToLast",t),Cr._create("limitToLast",t,"L")}class Lr extends Ar{constructor(t,e,n){super(),this.type=t,this._docOrFields=e,this._inclusive=n}static _create(t,e,n){return new Lr(t,e,n)}_apply(t){const e=jr(t,this.type,this._docOrFields,this._inclusive);return new xn(t.firestore,t.converter,function(t,e){return new Ve(t.path,t.collectionGroup,t.explicitOrderBy.slice(),t.filters.slice(),t.limit,t.limitType,e,t.endAt)}(t._query,e))}}function qr(...t){return Lr._create("startAt",t,!0)}function Mr(...t){return Lr._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 xn(t.firestore,t.converter,function(t,e){return new Ve(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 Ce(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(q,'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(q,`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(q,`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(q,`Invalid query. Expected a string for document ID in ${r}(), but got a ${typeof u}`);if(!Oe(t)&&-1!==u.indexOf("/"))throw new Y(q,`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(q,`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 Hr(t,e,n){if("string"==typeof(n=_(n))){if(""===n)throw new Y(q,"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(q,`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(q,`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 Cn)return Jt(t,n._key);throw new Y(q,`Invalid query. When querying with documentId(), you must provide a valid string or a DocumentReference, but it was: ${gt(n)}.`)}function zr(t,e){if(!Array.isArray(t)||0===t.length)throw new Y(q,`Invalid Query. A non-empty array is required for '${e.toString()}' filters.`)}function Gr(t,e){if(e.isInequality()){const n=Re(t),r=e.field;if(null!==n&&!n.isEqual(r))throw new Y(q,`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=Ne(t);null!==s&&Kr(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(q,`Invalid query. You cannot use more than one '${e.op.toString()}' filter.`):new Y(q,`Invalid query. You cannot use '${e.op.toString()}' filters with '${n.toString()}' filters.`)}function Kr(t,e,n){if(!n.isEqual(e))throw new Y(q,`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 Wr(t,e){if(!(e instanceof Ir||e instanceof Dr))throw new Y(q,`Function ${t}() requires AppliableConstraints created with a call to 'where(...)', 'or(...)', or 'and(...)'.`)}function Qr(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(Gt(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){const n={};return Ct(t.fields,((t,r)=>{n[t]=this.convertValue(r,e)})),n}convertGeoPoint(t){return new Gn(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(Ht(t));default:return null}}convertTimestamp(t){const e=qt(t);return new $t(e.seconds,e.nanos)}convertDocumentKey(t,e){const n=lt.fromString(t);C(wn(n));const r=new at(n.get(1),n.get(3)),s=new dt(n.popFirst(5));return r.isEqual(e)||V(`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 Cn(this.firestore,null,e)}}function Jr(t){const e=An((t=yt(t,Cn)).firestore),n=new Yr(t.firestore);return Tn(e,[t._key]).then((e=>{C(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(K,"limitToLast() queries require specifying at least one orderBy() clause")}((t=yt(t,xn))._query);const e=An(t.firestore),n=new Yr(t.firestore);return async function(t,e){const n=x(t),r=hn(n.M,xe(e));return(await n.P("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 ke({mapValue:{fields:e.fields}});return Ie.newFoundDocument(r,s,i,o)}(n.M,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=Qr((t=yt(t,Cn)).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,He.none())])}function ts(t,e,n,...r){const s=Zn((t=yt(t,Cn)).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,He.exists(!0))])}function es(t){return En(An((t=yt(t,Cn)).firestore),[new We(t._key,He.none())])}function ns(t,e){const n=Mn(t=yt(t,Pn)),r=Qr(t.converter,e),s=tr(Zn(t.firestore),"addDoc",n._key,r,null!==n.converter,{});return En(An(t.firestore),[s.toMutation(n._key,He.exists(!1))]).then((()=>n))}function rs(t){return ss(t,{count:as()})}function ss(t,e){const n=yt(t.firestore,In),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(new It(e),t._aggregateType,t._internalFieldPath)));return async function(t,e,n){const r=x(t),s=function(t,e,n){const r=hn(t,e),s=[];return n.forEach((t=>{"count"===t.N?s.push({alias:t.alias.canonicalString(),count:{}}):"avg"===t.N?s.push({alias:t.alias.canonicalString(),avg:{field:mn(t.fieldPath)}}):"sum"===t.N&&s.push({alias:t.alias.canonicalString(),sum:{field:mn(t.fieldPath)}})})),{structuredAggregationQuery:{aggregations:s,structuredQuery:r.structuredQuery},parent:r.parent}}(r.M,xe(e),n),i=s.parent;r.connection.v||delete s.parent;const o=(await r.P("RunAggregationQuery",i,s,1)).filter((t=>!!t.result));return C(1===o.length),(a=o[0]).result,a.result.aggregateFields,new ke({mapValue:{fields:null===(u=a.result)||void 0===u?void 0:u.aggregateFields}});var a,u}(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=Qr(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,He.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,He.exists(!0))),this}delete(t){this._verifyNotCommitted();const e=gs(t,this._firestore);return this._mutations=this._mutations.concat(new We(e._key,He.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(H,"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(q,"Provided document reference is from a different Firestore instance.");return t}function ys(t){const e=An(t=yt(t,In));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(q,"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 We(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 Qe(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(z,"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())?He.exists(!1):He.updateTime(e):He.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(q,"Can't update a document that doesn't exist.");return He.updateTime(e)}return He.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._t=n.maxAttempts,this.vt=new vn(this.asyncQueue,"transaction_retry")}run(){this._t-=1,this.bt()}bt(){this.vt.J((async()=>{const t=new ws(this.datastore),e=this.Et(t);e&&e.then((e=>{this.asyncQueue.enqueueAndForget((()=>t.commit().then((()=>{this.deferred.resolve(e)})).catch((t=>{this.At(t)}))))})).catch((t=>{this.At(t)}))}))}Et(t){try{const e=this.updateFunction(t);return!_t(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}}At(t){this._t>0&&this.It(t)?(this._t-=1,this.asyncQueue.enqueueAndForget((()=>(this.bt(),Promise.resolve())))):this.deferred.reject(t)}It(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 P:case L:case M:case j:case W:case Q:case U:return!1;case q:case B:case"already-exists":case $:case H:case z:case G:case K: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(P,"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.Tt=Promise.resolve(),this.Rt=[],this.Pt=!1,this.Vt=[],this.$t=null,this.Dt=!1,this.Nt=!1,this.Ft=[],this.vt=new vn(this,"async_queue_retry"),this.xt=()=>{const t=bs();t&&D("AsyncQueue","Visibility state changed to "+t.visibilityState),this.vt.tt()};const t=bs();t&&"function"==typeof t.addEventListener&&t.addEventListener("visibilitychange",this.xt)}get isShuttingDown(){return this.Pt}enqueueAndForget(t){this.enqueue(t)}enqueueAndForgetEvenWhileRestricted(t){this.St(),this.qt(t)}enterRestrictedMode(t){if(!this.Pt){this.Pt=!0,this.Nt=t||!1;const e=bs();e&&"function"==typeof e.removeEventListener&&e.removeEventListener("visibilitychange",this.xt)}}enqueue(t){if(this.St(),this.Pt)return new Promise((()=>{}));const e=new J;return this.qt((()=>this.Pt&&this.Nt?Promise.resolve():(t().then(e.resolve,e.reject),e.promise))).then((()=>e.promise))}enqueueRetryable(t){this.enqueueAndForget((()=>(this.Rt.push(t),this.Ot())))}async Ot(){if(0!==this.Rt.length){try{await this.Rt[0](),this.Rt.shift(),this.vt.reset()}catch(t){if(!function(t){return"IndexedDbTransactionError"===t.name}(t))throw t;D("AsyncQueue","Operation failed with retryable error: "+t)}this.Rt.length>0&&this.vt.J((()=>this.Ot()))}}qt(t){const e=this.Tt.then((()=>(this.Dt=!0,t().catch((t=>{this.$t=t,this.Dt=!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 V("INTERNAL UNHANDLED ERROR: ",e),t})).then((t=>(this.Dt=!1,t))))));return this.Tt=e,e}enqueueAfterDelay(t,e,n){this.St(),this.Ft.indexOf(t)>-1&&(e=0);const r=Es.createAndSchedule(this,t,e,n,(t=>this.kt(t)));return this.Vt.push(r),r}St(){this.$t&&O()}verifyOperationInProgress(){}async Ct(){let t;do{t=this.Tt,await t}while(t!==this.Tt)}Lt(t){for(const e of this.Vt)if(e.timerId===t)return!0;return!1}Mt(t){return this.Ct().then((()=>{this.Vt.sort(((t,e)=>t.targetTimeMs-e.targetTimeMs));for(const e of this.Vt)if(e.skipDelay(),"all"!==t&&e.timerId===t)break;return this.Ct()}))}Ut(t){this.Ft.push(t)}kt(t){const e=this.Vt.indexOf(t);this.Vt.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=Qr(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,In)),s=Object.assign(Object.assign({},_s),n);!function(t){if(t.maxAttempts<1)throw new Y(q,"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}k=`${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 In(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(q,'"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.8.4",""),e("firestore-lite","3.8.4","esm2017");export{Rn as AggregateField,On as AggregateQuerySnapshot,Un as Bytes,Pn as CollectionReference,Cn as DocumentReference,_r as DocumentSnapshot,jn as FieldPath,zn as FieldValue,In as Firestore,Y as FirestoreError,Gn as GeoPoint,xn as Query,Dr as QueryCompositeFilterConstraint,Ar as QueryConstraint,vr as QueryDocumentSnapshot,Br as QueryEndAtConstraint,Ir as QueryFieldFilterConstraint,Cr as QueryLimitConstraint,Rr as QueryOrderByConstraint,br as QuerySnapshot,Lr as QueryStartAtConstraint,$t as Timestamp,Ss as Transaction,ms as WriteBatch,ns as addDoc,us as aggregateFieldEqual,ls as aggregateQuerySnapshotEqual,Nr as and,fs as arrayRemove,ds as arrayUnion,os as average,Ln as collection,qn as collectionGroup,Vn as connectFirestoreEmulator,as as count,es as deleteDoc,cs as deleteField,Mn as doc,Hn 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,xr as limit,Pr as limitToLast,Vr as or,Or as orderBy,kr 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,qr as startAt,is as sum,Nn as terminate,ts as updateDoc,Fr as where,ys as writeBatch};
1
+ 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.18.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 k="9.18.0";const I=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){I.setLogLevel(t)}function D(t,...e){if(I.logLevel<=v.DEBUG){const n=e.map(R);I.debug(`Firestore (${k}): ${t}`,...n)}}function V(t,...e){if(I.logLevel<=v.ERROR){const n=e.map(R);I.error(`Firestore (${k}): ${t}`,...n)}}function N(t,...e){if(I.logLevel<=v.WARN){const n=e.map(R);I.warn(`Firestore (${k}): ${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 C(t="Unexpected state"){const e=`FIRESTORE (${k}) INTERNAL ASSERTION FAILED: `+t;throw V(e),new Error(e)}function O(t,e){t||C()}function x(t,e){return t}const P="cancelled",L="unknown",q="invalid-argument",M="deadline-exceeded",B="not-found",$="permission-denied",U="unauthenticated",j="resource-exhausted",H="failed-precondition",z="aborted",G="out-of-range",K="unimplemented",W="internal",Q="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?(O("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,r){this.t=t,this.i=e,this.o=n,this.u=r,this.type="FirstParty",this.user=A.FIRST_PARTY,this.h=new Map}l(){return this.u?this.u():(O(!("object"!=typeof this.t||null===this.t||!this.t.auth||!this.t.auth.getAuthHeaderValueForFirstParty)),this.t.auth.getAuthHeaderValueForFirstParty([]))}get headers(){this.h.set("X-Goog-AuthUser",this.i);const t=this.l();return t&&this.h.set("Authorization",t),this.o&&this.h.set("X-Goog-Iam-Authorization-Token",this.o),this.h}}class rt{constructor(t,e,n,r){this.t=t,this.i=e,this.o=n,this.u=r}getToken(){return Promise.resolve(new nt(this.t,this.i,this.o,this.u))}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.m=t,this.appCheck=null,t.onInit((t=>{this.appCheck=t}))}getToken(){return this.appCheck?this.appCheck.getToken().then((t=>t?(O("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){this.databaseId=t,this.appId=e,this.persistenceKey=n,this.host=r,this.ssl=s,this.forceLongPolling=i,this.autoDetectLongPolling=o,this.useFetchStreams=a}}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&&C(),void 0===n?n=t.length-e:n>t.length-e&&C(),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(q,`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(q,`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(q,"Path has trailing escape character: "+t);const e=t[r+1];if("\\"!==e&&"."!==e&&"`"!==e)throw new Y(q,"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(q,"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(q,`Function ${t}() cannot be called with an empty ${e}.`)}function pt(t){if(!dt.isDocumentKey(t))throw new Y(q,`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(q,`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":C()}function yt(t,e){if("_delegate"in t&&(t=t._delegate),!(t instanceof e)){if(e.name===t.constructor.name)throw new Y(q,"Type does not match the expected instance. Did you pass a reference from a different Firestore SDK?");{const n=gt(t);throw new Y(q,`Expected type '${e.name}', but it was: ${n}`)}}return t}function wt(t,e){if(e<=0)throw new Y(q,`Function ${t}() requires a positive number, but it was: ${e}.`)}let _t=null;function vt(t){return null==t}function bt(t){return 0===t&&1/t==-1/0}const Et={BatchGetDocuments:"batchGet",Commit:"commit",RunQuery:"runQuery",RunAggregationQuery:"runAggregationQuery"};var Tt,St;function At(t){if(void 0===t)return V("RPC_ERROR","HTTP error has no status"),L;switch(t){case 200:return"ok";case 400:return H;case 401:return U;case 403:return $;case 404:return B;case 409:return z;case 416:return G;case 429:return j;case 499:return P;case 500:return L;case 501:return K;case 503:return Q;case 504:return M;default:return t>=200&&t<300?"ok":t>=400&&t<500?H:t>=500&&t<600?W:L}}(St=Tt||(Tt={}))[St.OK=0]="OK",St[St.CANCELLED=1]="CANCELLED",St[St.UNKNOWN=2]="UNKNOWN",St[St.INVALID_ARGUMENT=3]="INVALID_ARGUMENT",St[St.DEADLINE_EXCEEDED=4]="DEADLINE_EXCEEDED",St[St.NOT_FOUND=5]="NOT_FOUND",St[St.ALREADY_EXISTS=6]="ALREADY_EXISTS",St[St.PERMISSION_DENIED=7]="PERMISSION_DENIED",St[St.UNAUTHENTICATED=16]="UNAUTHENTICATED",St[St.RESOURCE_EXHAUSTED=8]="RESOURCE_EXHAUSTED",St[St.FAILED_PRECONDITION=9]="FAILED_PRECONDITION",St[St.ABORTED=10]="ABORTED",St[St.OUT_OF_RANGE=11]="OUT_OF_RANGE",St[St.UNIMPLEMENTED=12]="UNIMPLEMENTED",St[St.INTERNAL=13]="INTERNAL",St[St.UNAVAILABLE=14]="UNAVAILABLE",St[St.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.p=e+"://"+t.host,this.g="projects/"+this.databaseId.projectId+"/databases/"+this.databaseId.database+"/documents"}get v(){return!1}A(t,e,n,r,s){const i=(null===_t?_t=268435456+Math.round(2147483648*Math.random()):_t++,"0x"+_t.toString(16)),o=this.I(t,e);D("RestConnection",`Sending RPC '${t}' ${i}:`,o,n);const a={};return this.T(a,r,s),this.R(t,o,a,n).then((e=>(D("RestConnection",`Received RPC '${t}' ${i}: `,e),e)),(e=>{throw N("RestConnection",`RPC '${t}' ${i} failed with error: `,e,"url: ",o,"request:",n),e}))}P(t,e,n,r,s,i){return this.A(t,e,n,r,s)}T(t,e,n){t["X-Goog-Api-Client"]="gl-js/ fire/"+k,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=Et[t];return`${this.p}/v1/${e}:${n}`}}{constructor(t,e){super(t),this.V=e}$(t,e){throw new Error("Not supported by FetchConnection")}async R(t,e,n,r){var s;const i=JSON.stringify(r);let o;try{o=await this.V(e,{method:"POST",headers:n,body:i})}catch(t){const e=t;throw new Y(At(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(At(o.status),`Request failed with error: ${null!=e?e:o.statusText}`)}return o.json()}}const It=/^[_a-zA-Z][_a-zA-Z0-9]*(?:\.[_a-zA-Z][_a-zA-Z0-9]*)*$/;class Ft{constructor(t){this.alias=t}static D(t){return It.test(t)}canonicalString(){let t=this.alias.replace(/\\/g,"\\\\").replace(/`/g,"\\`");return Ft.D(t)||(t="`"+t+"`"),t}}class Dt{constructor(t,e,n){this.alias=t,this.N=e,this.fieldPath=n}}function Vt(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 F(){const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",e=Math.floor(256/t.length)*t.length;let n="";for(;n.length<20;){const r=Vt(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 Rt(t,e){return t<e?-1:t>e?1:0}function Ct(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 Lt{constructor(t){this.binaryString=t}static fromBase64String(t){const e=function(t){try{return atob(t)}catch(t){throw t instanceof DOMException?new Pt("Invalid base64 string: "+t):t}}(t);return new Lt(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 Lt(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 Rt(this.binaryString,t.binaryString)}isEqual(t){return this.binaryString===t.binaryString}}Lt.EMPTY_BYTE_STRING=new Lt("");const qt=new RegExp(/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.(\d+))?Z$/);function Mt(t){if(O(!!t),"string"==typeof t){let e=0;const n=qt.exec(t);if(O(!!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:Bt(t.seconds),nanos:Bt(t.nanos)}}function Bt(t){return"number"==typeof t?t:"string"==typeof t?Number(t):0}function $t(t){return"string"==typeof t?Lt.fromBase64String(t):Lt.fromUint8Array(t)}class Ut{constructor(t,e){if(this.seconds=t,this.nanoseconds=e,e<0)throw new Y(q,"Timestamp nanoseconds out of range: "+e);if(e>=1e9)throw new Y(q,"Timestamp nanoseconds out of range: "+e);if(t<-62135596800)throw new Y(q,"Timestamp seconds out of range: "+t);if(t>=253402300800)throw new Y(q,"Timestamp seconds out of range: "+t)}static now(){return Ut.fromMillis(Date.now())}static fromDate(t){return Ut.fromMillis(t.getTime())}static fromMillis(t){const e=Math.floor(t/1e3),n=Math.floor(1e6*(t-1e3*e));return new Ut(e,n)}toDate(){return new Date(this.toMillis())}toMillis(){return 1e3*this.seconds+this.nanoseconds/1e6}_compareTo(t){return this.seconds===t.seconds?Rt(this.nanoseconds,t.nanoseconds):Rt(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 jt(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 Ht(t){const e=t.mapValue.fields.__previous_value__;return jt(e)?Ht(e):e}function zt(t){const e=Mt(t.mapValue.fields.__local_write_time__.timestampValue);return new Ut(e.seconds,e.nanos)}const Gt={fields:{__type__:{stringValue:"__max__"}}};function Kt(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?jt(t)?4:function(t){return"__max__"===(((t.mapValue||{}).fields||{}).__type__||{}).stringValue}(t)?9007199254740991:10:C()}function Wt(t,e){if(t===e)return!0;const n=Kt(t);if(n!==Kt(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=Mt(t.timestampValue),r=Mt(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 $t(t.bytesValue).isEqual($t(e.bytesValue))}(t,e);case 7:return t.referenceValue===e.referenceValue;case 8:return function(t,e){return Bt(t.geoPointValue.latitude)===Bt(e.geoPointValue.latitude)&&Bt(t.geoPointValue.longitude)===Bt(e.geoPointValue.longitude)}(t,e);case 2:return function(t,e){if("integerValue"in t&&"integerValue"in e)return Bt(t.integerValue)===Bt(e.integerValue);if("doubleValue"in t&&"doubleValue"in e){const n=Bt(t.doubleValue),r=Bt(e.doubleValue);return n===r?bt(n)===bt(r):isNaN(n)&&isNaN(r)}return!1}(t,e);case 9:return Ct(t.arrayValue.values||[],e.arrayValue.values||[],Wt);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]||!Wt(n[t],r[t])))return!1;return!0}(t,e);default:return C()}}function Qt(t,e){return void 0!==(t.values||[]).find((t=>Wt(t,e)))}function Yt(t,e){if(t===e)return 0;const n=Kt(t),r=Kt(e);if(n!==r)return Rt(n,r);switch(n){case 0:case 9007199254740991:return 0;case 1:return Rt(t.booleanValue,e.booleanValue);case 2:return function(t,e){const n=Bt(t.integerValue||t.doubleValue),r=Bt(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 Jt(t.timestampValue,e.timestampValue);case 4:return Jt(zt(t),zt(e));case 5:return Rt(t.stringValue,e.stringValue);case 6:return function(t,e){const n=$t(t),r=$t(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=Rt(n[t],r[t]);if(0!==e)return e}return Rt(n.length,r.length)}(t.referenceValue,e.referenceValue);case 8:return function(t,e){const n=Rt(Bt(t.latitude),Bt(e.latitude));return 0!==n?n:Rt(Bt(t.longitude),Bt(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=Yt(n[t],r[t]);if(e)return e}return Rt(n.length,r.length)}(t.arrayValue,e.arrayValue);case 10:return function(t,e){if(t===Gt&&e===Gt)return 0;if(t===Gt)return 1;if(e===Gt)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=Rt(r[t],i[t]);if(0!==e)return e;const o=Yt(n[r[t]],s[i[t]]);if(0!==o)return o}return Rt(r.length,i.length)}(t.mapValue,e.mapValue);default:throw C()}}function Jt(t,e){if("string"==typeof t&&"string"==typeof e&&t.length===e.length)return Rt(t,e);const n=Mt(t),r=Mt(e),s=Rt(n.seconds,r.seconds);return 0!==s?s:Rt(n.nanos,r.nanos)}function Xt(t,e){return{referenceValue:`projects/${t.projectId}/databases/${t.database}/documents/${e.path.canonicalString()}`}}function Zt(t){return!!t&&"arrayValue"in t}function te(t){return!!t&&"nullValue"in t}function ee(t){return!!t&&"doubleValue"in t&&isNaN(Number(t.doubleValue))}function ne(t){return!!t&&"mapValue"in t}function re(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]=re(n))),e}if(t.arrayValue){const e={arrayValue:{values:[]}};for(let n=0;n<(t.arrayValue.values||[]).length;++n)e.arrayValue.values[n]=re(t.arrayValue.values[n]);return e}return Object.assign({},t)}class se{constructor(t,e){this.position=t,this.inclusive=e}}function ie(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(!Wt(t.position[n],e.position[n]))return!1;return!0}class oe{}class ae extends oe{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 ce(t,e,n):"array-contains"===e?new pe(t,n):"in"===e?new me(t,n):"not-in"===e?new ge(t,n):"array-contains-any"===e?new ye(t,n):new ae(t,e,n)}static createKeyFieldInFilter(t,e,n){return"in"===e?new he(t,n):new de(t,n)}matches(t){const e=t.data.field(this.field);return"!="===this.op?null!==e&&this.matchesComparison(Yt(e,this.value)):null!==e&&Kt(this.value)===Kt(e)&&this.matchesComparison(Yt(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 C()}}isInequality(){return["<","<=",">",">=","!=","not-in"].indexOf(this.op)>=0}getFlattenedFilters(){return[this]}getFilters(){return[this]}getFirstInequalityField(){return this.isInequality()?this.field:null}}class ue extends oe{constructor(t,e){super(),this.filters=t,this.op=e,this.S=null}static create(t,e){return new ue(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.S||(this.S=this.filters.reduce(((t,e)=>t.concat(e.getFlattenedFilters())),[])),this.S}getFilters(){return Object.assign([],this.filters)}getFirstInequalityField(){const t=this.q((t=>t.isInequality()));return null!==t?t.field:null}q(t){for(const e of this.getFlattenedFilters())if(t(e))return e;return null}}function le(t,e){return t instanceof ae?function(t,e){return e instanceof ae&&t.op===e.op&&t.field.isEqual(e.field)&&Wt(t.value,e.value)}(t,e):t instanceof ue?function(t,e){return e instanceof ue&&t.op===e.op&&t.filters.length===e.filters.length&&t.filters.reduce(((t,n,r)=>t&&le(n,e.filters[r])),!0)}(t,e):void C()}class ce extends ae{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 he extends ae{constructor(t,e){super(t,"in",e),this.keys=fe("in",e)}matches(t){return this.keys.some((e=>e.isEqual(t.key)))}}class de extends ae{constructor(t,e){super(t,"not-in",e),this.keys=fe("not-in",e)}matches(t){return!this.keys.some((e=>e.isEqual(t.key)))}}function fe(t,e){var n;return((null===(n=e.arrayValue)||void 0===n?void 0:n.values)||[]).map((t=>dt.fromName(t.referenceValue)))}class pe extends ae{constructor(t,e){super(t,"array-contains",e)}matches(t){const e=t.data.field(this.field);return Zt(e)&&Qt(e.arrayValue,this.value)}}class me extends ae{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 ge extends ae{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 ye extends ae{constructor(t,e){super(t,"array-contains-any",e)}matches(t){const e=t.data.field(this.field);return!(!Zt(e)||!e.arrayValue.values)&&e.arrayValue.values.some((t=>Qt(this.value.arrayValue,t)))}}class we{constructor(t,e="asc"){this.field=t,this.dir=e}}function _e(t,e){return t.dir===e.dir&&t.field.isEqual(e.field)}class ve{constructor(t){this.timestamp=t}static fromTimestamp(t){return new ve(t)}static min(){return new ve(new Ut(0,0))}static max(){return new ve(new Ut(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 be{constructor(t,e){this.comparator=t,this.root=e||Te.EMPTY}insert(t,e){return new be(this.comparator,this.root.insert(t,e,this.comparator).copy(null,null,Te.BLACK,null,null))}remove(t){return new be(this.comparator,this.root.remove(t,this.comparator).copy(null,null,Te.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 Ee(this.root,null,this.comparator,!1)}getIteratorFrom(t){return new Ee(this.root,t,this.comparator,!1)}getReverseIterator(){return new Ee(this.root,null,this.comparator,!0)}getReverseIteratorFrom(t){return new Ee(this.root,t,this.comparator,!0)}}class Ee{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 Te{constructor(t,e,n,r,s){this.key=t,this.value=e,this.color=null!=n?n:Te.RED,this.left=null!=r?r:Te.EMPTY,this.right=null!=s?s:Te.EMPTY,this.size=this.left.size+1+this.right.size}copy(t,e,n,r,s){return new Te(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 Te.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 Te.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,Te.RED,null,this.right.left);return this.right.copy(null,null,this.color,t,null)}rotateRight(){const t=this.copy(null,null,Te.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 C();if(this.right.isRed())throw C();const t=this.left.check();if(t!==this.right.check())throw C();return t+(this.isRed()?0:1)}}Te.EMPTY=null,Te.RED=!0,Te.BLACK=!1,Te.EMPTY=new class{constructor(){this.size=0}get key(){throw C()}get value(){throw C()}get color(){throw C()}get left(){throw C()}get right(){throw C()}copy(t,e,n,r,s){return this}insert(t,e,n){return new Te(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 Se{constructor(t){this.comparator=t,this.data=new be(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 Ae(this.data.getIterator())}getIteratorFrom(t){return new Ae(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 Se))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 Se(this.comparator);return e.data=t,e}}class Ae{constructor(t){this.iter=t}getNext(){return this.iter.getNext().key}hasNext(){return this.iter.hasNext()}}class ke{constructor(t){this.fields=t,t.sort(ht.comparator)}static empty(){return new ke([])}unionWith(t){let e=new Se(ht.comparator);for(const t of this.fields)e=e.add(t);for(const n of t)e=e.add(n);return new ke(e.toArray())}covers(t){for(const e of this.fields)if(e.isPrefixOf(t))return!0;return!1}isEqual(t){return Ct(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)],!ne(e))return null;return e=(e.mapValue.fields||{})[t.lastSegment()],e||null}}set(t,e){this.getFieldsMap(t.popLast())[t.lastSegment()]=re(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()]=re(t):r.push(s.lastSegment())}));const s=this.getFieldsMap(e);this.applyChanges(s,n,r)}delete(t){const e=this.field(t.popLast());ne(e)&&e.mapValue.fields&&delete e.mapValue.fields[t.lastSegment()]}isEqual(t){return Wt(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)];ne(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(re(this.value))}}class Fe{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 Fe(t,0,ve.min(),ve.min(),ve.min(),Ie.empty(),0)}static newFoundDocument(t,e,n,r){return new Fe(t,1,e,ve.min(),n,r,0)}static newNoDocument(t,e){return new Fe(t,2,e,ve.min(),ve.min(),Ie.empty(),0)}static newUnknownDocument(t,e){return new Fe(t,3,e,ve.min(),ve.min(),Ie.empty(),2)}convertToFoundDocument(t,e){return!this.createTime.isEqual(ve.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=ve.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 Fe&&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 Fe(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 De{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.O=null}}function Ve(t,e=null,n=[],r=[],s=null,i=null,o=null){return new De(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.k=null,this.C=null,this.startAt,this.endAt}}function Re(t){return t.explicitOrderBy.length>0?t.explicitOrderBy[0].field:null}function Ce(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=x(t);if(null===e.k){e.k=[];const t=Ce(e),n=Re(e);if(null!==t&&null===n)t.isKeyField()||e.k.push(new we(t)),e.k.push(new we(ht.keyField(),"asc"));else{let t=!1;for(const n of e.explicitOrderBy)e.k.push(n),n.field.isKeyField()&&(t=!0);if(!t){const t=e.explicitOrderBy.length>0?e.explicitOrderBy[e.explicitOrderBy.length-1].dir:"asc";e.k.push(new we(ht.keyField(),t))}}}return e.k}function Pe(t){const e=x(t);if(!e.C)if("F"===e.limitType)e.C=Ve(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 we(n.field,e))}const n=e.endAt?new se(e.endAt.position,e.endAt.inclusive):null,r=e.startAt?new se(e.startAt.position,e.startAt.inclusive):null;e.C=Ve(e.path,e.collectionGroup,t,e.filters,e.limit,n,r)}return e.C}function Le(t,e){e.getFirstInequalityField(),Ce(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)&&!bt(t)&&t<=Number.MAX_SAFE_INTEGER&&t>=Number.MIN_SAFE_INTEGER}(e)?function(t){return{integerValue:""+t}}(e):function(t,e){if(t.L){if(isNaN(e))return{doubleValue:"NaN"};if(e===1/0)return{doubleValue:"Infinity"};if(e===-1/0)return{doubleValue:"-Infinity"}}return{doubleValue:bt(e)?"-0":e}}(t,e)}class Me{constructor(){this._=void 0}}class Be extends Me{}class $e extends Me{constructor(t){super(),this.elements=t}}class Ue extends Me{constructor(t){super(),this.elements=t}}class je extends Me{constructor(t,e){super(),this.M=t,this.U=e}}class He{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 Ge{}class Ke extends Ge{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 We extends Ge{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 Ge{constructor(t,e){super(),this.key=t,this.precondition=e,this.type=2,this.fieldTransforms=[]}getFieldMask(){return null}}class Ye extends Ge{constructor(t,e){super(),this.key=t,this.precondition=e,this.type=3,this.fieldTransforms=[]}getFieldMask(){return null}}const Je={asc:"ASCENDING",desc:"DESCENDING"},Xe={"<":"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"},Ze={and:"AND",or:"OR"};class tn{constructor(t,e){this.databaseId=t,this.L=e}}function en(t,e){return t.L?`${new Date(1e3*e.seconds).toISOString().replace(/\.\d*/,"").replace("Z","")}.${("000000000"+e.nanoseconds).slice(-9)}Z`:{seconds:""+e.seconds,nanos:e.nanoseconds}}function nn(t,e){return t.L?e.toBase64():e.toUint8Array()}function rn(t,e){return en(t,e.toTimestamp())}function sn(t){return O(!!t),ve.fromTimestamp(function(t){const e=Mt(t);return new Ut(e.seconds,e.nanos)}(t))}function on(t,e){return function(t){return new lt(["projects",t.projectId,"databases",t.database])}(t).child("documents").child(e).canonicalString()}function an(t,e){return on(t.databaseId,e.path)}function un(t,e){const n=function(t){const e=lt.fromString(t);return O(_n(e)),e}(e);if(n.get(1)!==t.databaseId.projectId)throw new Y(q,"Tried to deserialize key from different project: "+n.get(1)+" vs "+t.databaseId.projectId);if(n.get(3)!==t.databaseId.database)throw new Y(q,"Tried to deserialize key from different database: "+n.get(3)+" vs "+t.databaseId.database);return new dt((O((r=n).length>4&&"documents"===r.get(4)),r.popFirst(5)));var r}function ln(t,e){return on(t.databaseId,e)}function cn(t){return new lt(["projects",t.databaseId.projectId,"databases",t.databaseId.database]).canonicalString()}function hn(t,e,n){return{name:an(t,e),fields:n.value.mapValue.fields}}function dn(t,e){const n={structuredQuery:{}},r=e.path;null!==e.collectionGroup?(n.parent=ln(t,r),n.structuredQuery.from=[{collectionId:e.collectionGroup,allDescendants:!0}]):(n.parent=ln(t,r.popLast()),n.structuredQuery.from=[{collectionId:r.lastSegment()}]);const s=function(t){if(0!==t.length)return yn(ue.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:gn(t.field),direction:fn(t.dir)}}(t)))}(e.orderBy);i&&(n.structuredQuery.orderBy=i);const o=function(t,e){return t.L||vt(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 fn(t){return Je[t]}function pn(t){return Xe[t]}function mn(t){return Ze[t]}function gn(t){return{fieldPath:t.canonicalString()}}function yn(t){return t instanceof ae?function(t){if("=="===t.op){if(ee(t.value))return{unaryFilter:{field:gn(t.field),op:"IS_NAN"}};if(te(t.value))return{unaryFilter:{field:gn(t.field),op:"IS_NULL"}}}else if("!="===t.op){if(ee(t.value))return{unaryFilter:{field:gn(t.field),op:"IS_NOT_NAN"}};if(te(t.value))return{unaryFilter:{field:gn(t.field),op:"IS_NOT_NULL"}}}return{fieldFilter:{field:gn(t.field),op:pn(t.op),value:t.value}}}(t):t instanceof ue?function(t){const e=t.getFilters().map((t=>yn(t)));return 1===e.length?e[0]:{compositeFilter:{op:mn(t.op),filters:e}}}(t):C()}function wn(t){const e=[];return t.fields.forEach((t=>e.push(t.canonicalString()))),{fieldPaths:e}}function _n(t){return t.length>=4&&"projects"===t.get(0)&&"databases"===t.get(2)}function vn(t){return new tn(t,!0)}class bn{constructor(t,e,n=1e3,r=1.5,s=6e4){this.j=t,this.timerId=e,this.B=n,this.W=r,this.G=s,this.K=0,this.Y=null,this.H=Date.now(),this.reset()}reset(){this.K=0}Z(){this.K=this.G}J(t){this.cancel();const e=Math.floor(this.K+this.X()),n=Math.max(0,Date.now()-this.H),r=Math.max(0,e-n);r>0&&D("ExponentialBackoff",`Backing off for ${r} ms (base delay: ${this.K} ms, delay with jitter: ${e} ms, last attempt: ${n} ms ago)`),this.Y=this.j.enqueueAfterDelay(this.timerId,r,(()=>(this.H=Date.now(),t()))),this.K*=this.W,this.K<this.B&&(this.K=this.B),this.K>this.G&&(this.K=this.G)}tt(){null!==this.Y&&(this.Y.skipDelay(),this.Y=null)}cancel(){null!==this.Y&&(this.Y.cancel(),this.Y=null)}X(){return(Math.random()-.5)*this.K}}class En extends class{}{constructor(t,e,n,r){super(),this.authCredentials=t,this.appCheckCredentials=e,this.connection=n,this.M=r,this.et=!1}nt(){if(this.et)throw new Y(H,"The client has already been terminated.")}A(t,e,n){return this.nt(),Promise.all([this.authCredentials.getToken(),this.appCheckCredentials.getToken()]).then((([r,s])=>this.connection.A(t,e,n,r,s))).catch((t=>{throw"FirebaseError"===t.name?(t.code===U&&(this.authCredentials.invalidateToken(),this.appCheckCredentials.invalidateToken()),t):new Y(L,t.toString())}))}P(t,e,n,r){return this.nt(),Promise.all([this.authCredentials.getToken(),this.appCheckCredentials.getToken()]).then((([s,i])=>this.connection.P(t,e,n,s,i,r))).catch((t=>{throw"FirebaseError"===t.name?(t.code===U&&(this.authCredentials.invalidateToken(),this.appCheckCredentials.invalidateToken()),t):new Y(L,t.toString())}))}terminate(){this.et=!0}}async function Tn(t,e){const n=x(t),r=cn(n.M)+"/documents",s={writes:e.map((t=>function(t,e){let n;if(e instanceof Ke)n={update:hn(t,e.key,e.value)};else if(e instanceof Qe)n={delete:an(t,e.key)};else if(e instanceof We)n={update:hn(t,e.key,e.data),updateMask:wn(e.fieldMask)};else{if(!(e instanceof Ye))return C();n={verify:an(t,e.key)}}return e.fieldTransforms.length>0&&(n.updateTransforms=e.fieldTransforms.map((t=>function(t,e){const n=e.transform;if(n instanceof Be)return{fieldPath:e.field.canonicalString(),setToServerValue:"REQUEST_TIME"};if(n instanceof $e)return{fieldPath:e.field.canonicalString(),appendMissingElements:{values:n.elements}};if(n instanceof Ue)return{fieldPath:e.field.canonicalString(),removeAllFromArray:{values:n.elements}};if(n instanceof je)return{fieldPath:e.field.canonicalString(),increment:n.U};throw C()}(0,t)))),e.precondition.isNone||(n.currentDocument=function(t,e){return void 0!==e.updateTime?{updateTime:rn(t,e.updateTime)}:void 0!==e.exists?{exists:e.exists}:C()}(t,e.precondition)),n}(n.M,t)))};await n.A("Commit",r,s)}async function Sn(t,e){const n=x(t),r=cn(n.M)+"/documents",s={documents:e.map((t=>an(n.M,t)))},i=await n.P("BatchGetDocuments",r,s,e.length),o=new Map;i.forEach((t=>{const e=function(t,e){return"found"in e?function(t,e){O(!!e.found),e.found.name,e.found.updateTime;const n=un(t,e.found.name),r=sn(e.found.updateTime),s=e.found.createTime?sn(e.found.createTime):ve.min(),i=new Ie({mapValue:{fields:e.found.fields}});return Fe.newFoundDocument(n,r,s,i)}(t,e):"missing"in e?function(t,e){O(!!e.missing),O(!!e.readTime);const n=un(t,e.missing),r=sn(e.readTime);return Fe.newNoDocument(n,r)}(t,e):C()}(n.M,t);o.set(e.key.toString(),e)}));const a=[];return e.forEach((t=>{const e=o.get(t.toString());O(!!e),a.push(e)})),a}const An=new Map;function kn(t){if(t._terminated)throw new Y(H,"The client has already been terminated.");if(!An.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,s.useFetchStreams))),o=vn(t._databaseId),a=function(t,e,n,r){return new En(t,e,n,r)}(t._authCredentials,t._appCheckCredentials,i,o);An.set(t,a)}var e,n,r,s;return An.get(t)}class In{constructor(t){var e;if(void 0===t.host){if(void 0!==t.ssl)throw new Y(q,"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,void 0===t.cacheSizeBytes)this.cacheSizeBytes=41943040;else{if(-1!==t.cacheSizeBytes&&t.cacheSizeBytes<1048576)throw new Y(q,"cacheSizeBytes must be at least 1048576");this.cacheSizeBytes=t.cacheSizeBytes}this.experimentalForceLongPolling=!!t.experimentalForceLongPolling,this.experimentalAutoDetectLongPolling=!!t.experimentalAutoDetectLongPolling,this.useFetchStreams=!!t.useFetchStreams,function(t,e,n,r){if(!0===e&&!0===r)throw new Y(q,"experimentalForceLongPolling and experimentalAutoDetectLongPolling cannot be used together.")}(0,t.experimentalForceLongPolling,0,t.experimentalAutoDetectLongPolling)}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&&this.ignoreUndefinedProperties===t.ignoreUndefinedProperties&&this.useFetchStreams===t.useFetchStreams}}class Fn{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(H,"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(H,"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"gapi":const e=t.client;return new rt(e,t.sessionIndex||"0",t.iamToken||null,t.authTokenFactory||null);case"provider":return t.client;default:throw new Y(q,"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=An.get(t);e&&(D("ComponentProvider","Removing Datastore"),An.delete(t),e.terminate())}(this),Promise.resolve()}}function Dn(t,e,r){r||(r="(default)");const s=n(t,"firestore/lite");if(s.isInitialized(r))throw new Y(H,"Firestore can only be initialized once per app.");return s.initialize({options:e,instanceIdentifier:r})}function Vn(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,Fn))._getSettings();if("firestore.googleapis.com"!==i.host&&i.host!==e&&N("Host has been set in both settings() and useEmulator(), emulator host will be used"),t._setSettings(Object.assign(Object.assign({},i),{host:`${e}:${n}`,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(q,"mockUserToken must contain 'sub' or 'user_id' field!");n=new A(i)}t._authCredentials=new tt(new X(e,n))}}function Rn(t){return t=yt(t,Fn),s(t.app,"firestore/lite"),t._delete()}class Cn{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.convertValue(this._data.value)}}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 Ln(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 Ln 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 Ln(this.firestore,t,this._path)}}function qn(t,e,...n){if(t=_(t),ft("collection","path",e),t instanceof Fn){const r=lt.fromString(e,...n);return mt(r),new Ln(t,null,r)}{if(!(t instanceof xn||t instanceof Ln))throw new Y(q,"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 Ln(t.firestore,null,r)}}function Mn(t,e){if(t=yt(t,Fn),ft("collectionGroup","collection id",e),e.indexOf("/")>=0)throw new Y(q,`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 Bn(t,e,...n){if(t=_(t),1===arguments.length&&(e=Nt.F()),ft("doc","path",e),t instanceof Fn){const r=lt.fromString(e,...n);return pt(r),new xn(t,null,new dt(r))}{if(!(t instanceof xn||t instanceof Ln))throw new Y(q,"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 Ln?t.converter:null,new dt(r))}}function $n(t,e){return t=_(t),e=_(e),(t instanceof xn||t instanceof Ln)&&(e instanceof xn||e instanceof Ln)&&t.firestore===e.firestore&&t.path===e.path&&t.converter===e.converter}function Un(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(!_e(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(!le(t.filters[n],e.filters[n]))return!1;return t.collectionGroup===e.collectionGroup&&!!t.path.isEqual(e.path)&&!!ie(t.startAt,e.startAt)&&ie(t.endAt,e.endAt)}(Pe(t),Pe(e))&&t.limitType===e.limitType}(t._query,e._query)&&t.converter===e.converter}class jn{constructor(t){this._byteString=t}static fromBase64String(t){try{return new jn(Lt.fromBase64String(t))}catch(t){throw new Y(q,"Failed to construct data from Base64 string: "+t)}}static fromUint8Array(t){return new jn(Lt.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 Hn{constructor(...t){for(let e=0;e<t.length;++e)if(0===t[e].length)throw new Y(q,"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 Hn("__name__")}class Gn{constructor(t){this._methodName=t}}class Kn{constructor(t,e){if(!isFinite(t)||t<-90||t>90)throw new Y(q,"Latitude must be a number between -90 and 90, but was: "+t);if(!isFinite(e)||e<-180||e>180)throw new Y(q,"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 Rt(this._lat,t._lat)||Rt(this._long,t._long)}}const Wn=/^__.*__$/;class Qn{constructor(t,e,n){this.data=t,this.fieldMask=e,this.fieldTransforms=n}toMutation(t,e){return null!==this.fieldMask?new We(t,this.data,this.fieldMask,e,this.fieldTransforms):new Ke(t,this.data,e,this.fieldTransforms)}}class Yn{constructor(t,e,n){this.data=t,this.fieldMask=e,this.fieldTransforms=n}toMutation(t,e){return new We(t,this.data,this.fieldMask,e,this.fieldTransforms)}}function Jn(t){switch(t){case 0:case 2:case 1:return!0;case 3:case 4:return!1;default:throw C()}}class Xn{constructor(t,e,n,r,s,i){this.settings=t,this.databaseId=e,this.M=n,this.ignoreUndefinedProperties=r,void 0===s&&this.rt(),this.fieldTransforms=s||[],this.fieldMask=i||[]}get path(){return this.settings.path}get st(){return this.settings.st}it(t){return new Xn(Object.assign(Object.assign({},this.settings),t),this.databaseId,this.M,this.ignoreUndefinedProperties,this.fieldTransforms,this.fieldMask)}ot(t){var e;const n=null===(e=this.path)||void 0===e?void 0:e.child(t),r=this.it({path:n,ut:!1});return r.ct(t),r}at(t){var e;const n=null===(e=this.path)||void 0===e?void 0:e.child(t),r=this.it({path:n,ut:!1});return r.rt(),r}ht(t){return this.it({path:void 0,ut:!0})}lt(t){return wr(t,this.settings.methodName,this.settings.ft||!1,this.path,this.settings.dt)}contains(t){return void 0!==this.fieldMask.find((e=>t.isPrefixOf(e)))||void 0!==this.fieldTransforms.find((e=>t.isPrefixOf(e.field)))}rt(){if(this.path)for(let t=0;t<this.path.length;t++)this.ct(this.path.get(t))}ct(t){if(0===t.length)throw this.lt("Document fields must not be empty");if(Jn(this.st)&&Wn.test(t))throw this.lt('Document fields cannot begin and end with "__"')}}class Zn{constructor(t,e,n){this.databaseId=t,this.ignoreUndefinedProperties=e,this.M=n||vn(t)}wt(t,e,n,r=!1){return new Xn({st:t,methodName:e,dt:n,path:ht.emptyPath(),ut:!1,ft:r},this.databaseId,this.M,this.ignoreUndefinedProperties)}}function tr(t){const e=t._freezeSettings(),n=vn(t._databaseId);return new Zn(t._databaseId,!!e.ignoreUndefinedProperties,n)}function er(t,e,n,r,s,i={}){const o=t.wt(i.merge||i.mergeFields?2:0,e,n,s);pr("Data must be an object, but it was:",o,r);const a=dr(r,o);let u,l;if(i.merge)u=new ke(o.fieldMask),l=o.fieldTransforms;else if(i.mergeFields){const t=[];for(const r of i.mergeFields){const s=mr(e,r,n);if(!o.contains(s))throw new Y(q,`Field '${s}' is specified in your field mask but missing from your input data.`);_r(t,s)||t.push(s)}u=new ke(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 nr extends Gn{_toFieldTransform(t){if(2!==t.st)throw 1===t.st?t.lt(`${this._methodName}() can only appear at the top level of your update data`):t.lt(`${this._methodName}() cannot be used with set() unless you pass {merge:true}`);return t.fieldMask.push(t.path),null}isEqual(t){return t instanceof nr}}function rr(t,e,n){return new Xn({st:3,dt:e.settings.dt,methodName:t._methodName,ut:n},e.databaseId,e.M,e.ignoreUndefinedProperties)}class sr extends Gn{_toFieldTransform(t){return new He(t.path,new Be)}isEqual(t){return t instanceof sr}}class ir extends Gn{constructor(t,e){super(t),this.yt=e}_toFieldTransform(t){const e=rr(this,t,!0),n=this.yt.map((t=>hr(t,e))),r=new $e(n);return new He(t.path,r)}isEqual(t){return this===t}}class or extends Gn{constructor(t,e){super(t),this.yt=e}_toFieldTransform(t){const e=rr(this,t,!0),n=this.yt.map((t=>hr(t,e))),r=new Ue(n);return new He(t.path,r)}isEqual(t){return this===t}}class ar extends Gn{constructor(t,e){super(t),this.gt=e}_toFieldTransform(t){const e=new je(t.M,qe(t.M,this.gt));return new He(t.path,e)}isEqual(t){return this===t}}function ur(t,e,n,r){const s=t.wt(1,e,n);pr("Data must be an object, but it was:",s,r);const i=[],o=Ie.empty();xt(r,((t,r)=>{const a=yr(e,t,n);r=_(r);const u=s.at(a);if(r instanceof nr)i.push(a);else{const t=hr(r,u);null!=t&&(i.push(a),o.set(a,t))}}));const a=new ke(i);return new Yn(o,a,s.fieldTransforms)}function lr(t,e,n,r,s,i){const o=t.wt(1,e,n),a=[mr(e,r,n)],u=[s];if(i.length%2!=0)throw new Y(q,`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(mr(e,i[t])),u.push(i[t+1]);const l=[],c=Ie.empty();for(let t=a.length-1;t>=0;--t)if(!_r(l,a[t])){const e=a[t];let n=u[t];n=_(n);const r=o.at(e);if(n instanceof nr)l.push(e);else{const t=hr(n,r);null!=t&&(l.push(e),c.set(e,t))}}const h=new ke(l);return new Yn(c,h,o.fieldTransforms)}function cr(t,e,n,r=!1){return hr(n,t.wt(r?4:3,e))}function hr(t,e){if(fr(t=_(t)))return pr("Unsupported field value:",e,t),dr(t,e);if(t instanceof Gn)return function(t,e){if(!Jn(e.st))throw e.lt(`${t._methodName}() can only be used with update() and set()`);if(!e.path)throw e.lt(`${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.ut&&4!==e.st)throw e.lt("Nested arrays are not supported");return function(t,e){const n=[];let r=0;for(const s of t){let t=hr(s,e.ht(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.M,t);if("boolean"==typeof t)return{booleanValue:t};if("string"==typeof t)return{stringValue:t};if(t instanceof Date){const n=Ut.fromDate(t);return{timestampValue:en(e.M,n)}}if(t instanceof Ut){const n=new Ut(t.seconds,1e3*Math.floor(t.nanoseconds/1e3));return{timestampValue:en(e.M,n)}}if(t instanceof Kn)return{geoPointValue:{latitude:t.latitude,longitude:t.longitude}};if(t instanceof jn)return{bytesValue:nn(e.M,t._byteString)};if(t instanceof xn){const n=e.databaseId,r=t.firestore._databaseId;if(!r.isEqual(n))throw e.lt(`Document reference is for database ${r.projectId}/${r.database} but should be for database ${n.projectId}/${n.database}`);return{referenceValue:on(t.firestore._databaseId||e.databaseId,t._key.path)}}throw e.lt(`Unsupported field value: ${gt(t)}`)}(t,e)}function dr(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=hr(r,e.ot(t));null!=s&&(n[t]=s)})),{mapValue:{fields:n}}}function fr(t){return!("object"!=typeof t||null===t||t instanceof Array||t instanceof Date||t instanceof Ut||t instanceof Kn||t instanceof jn||t instanceof xn||t instanceof Gn)}function pr(t,e,n){if(!fr(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.lt(t+" a custom object"):e.lt(t+" "+r)}}function mr(t,e,n){if((e=_(e))instanceof Hn)return e._internalPath;if("string"==typeof e)return yr(t,e);throw wr("Field path arguments must be of type string or ",t,!1,void 0,n)}const gr=new RegExp("[~\\*/\\[\\]]");function yr(t,e,n){if(e.search(gr)>=0)throw wr(`Invalid field path (${e}). Paths must not contain '~', '*', '/', '[', or ']'`,t,!1,void 0,n);try{return new Hn(...e.split("."))._internalPath}catch(r){throw wr(`Invalid field path (${e}). Paths must not be empty, begin with '.', end with '.', or contain '..'`,t,!1,void 0,n)}}function wr(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(q,a+t+u)}function _r(t,e){return t.some((t=>t.isEqual(e)))}class vr{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 br(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(Sr("DocumentSnapshot.get",t));if(null!==e)return this._userDataWriter.convertValue(e)}}}class br extends vr{data(){return super.data()}}class Er{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 Tr(t,e){return t=_(t),e=_(e),t instanceof vr&&e instanceof vr?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 Er&&e instanceof Er&&Un(t.query,e.query)&&Ct(t.docs,e.docs,Tr)}function Sr(t,e){return"string"==typeof e?yr(t,e):e instanceof Hn?e._internalPath:e._delegate._internalPath}class Ar{}class kr extends Ar{}function Ir(t,e,...n){let r=[];e instanceof Ar&&r.push(e),r=r.concat(n),function(t){const e=t.filter((t=>t instanceof Vr)).length,n=t.filter((t=>t instanceof Fr)).length;if(e>1||e>0&&n>0)throw new Y(q,"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 Fr extends kr{constructor(t,e,n){super(),this._field=t,this._op=e,this._value=n,this.type="where"}static _create(t,e,n){return new Fr(t,e,n)}_apply(t){const e=this._parse(t);return Kr(t._query,e),new Pn(t.firestore,t.converter,Le(t._query,e))}_parse(t){const e=tr(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(q,`Invalid Query. You can't perform '${i}' queries on documentId().`);if("in"===i||"not-in"===i){Gr(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||Gr(o,i),a=cr(n,"where",o,"in"===i||"not-in"===i);return ae.create(s,i,a)}(t._query,0,e,t.firestore._databaseId,this._field,this._op,this._value);return n}}function Dr(t,e,n){const r=e,s=Sr("where",t);return Fr._create(s,r,n)}class Vr extends Ar{constructor(t,e){super(),this.type=t,this._queryConstraints=e}static _create(t,e){return new Vr(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]:ue.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)Kr(n,t),n=Le(n,t)}(t._query,e),new Pn(t.firestore,t.converter,Le(t._query,e)))}_getQueryConstraints(){return this._queryConstraints}_getOperator(){return"and"===this.type?"and":"or"}}function Nr(...t){return t.forEach((t=>Qr("or",t))),Vr._create("or",t)}function Rr(...t){return t.forEach((t=>Qr("and",t))),Vr._create("and",t)}class Cr extends kr{constructor(t,e){super(),this._field=t,this._direction=e,this.type="orderBy"}static _create(t,e){return new Cr(t,e)}_apply(t){const e=function(t,e,n){if(null!==t.startAt)throw new Y(q,"Invalid query. You must not call startAt() or startAfter() before calling orderBy().");if(null!==t.endAt)throw new Y(q,"Invalid query. You must not call endAt() or endBefore() before calling orderBy().");const r=new we(e,n);return function(t,e){if(null===Re(t)){const n=Ce(t);null!==n&&Wr(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=Sr("orderBy",t);return Cr._create(r,n)}class xr extends kr{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 Lr(t){return wt("limitToLast",t),xr._create("limitToLast",t,"L")}class qr extends kr{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=Hr(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 Mr(...t){return qr._create("startAt",t,!0)}function Br(...t){return qr._create("startAfter",t,!1)}class $r extends kr{constructor(t,e,n){super(),this.type=t,this._docOrFields=e,this._inclusive=n}static _create(t,e,n){return new $r(t,e,n)}_apply(t){const e=Hr(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 Ur(...t){return $r._create("endBefore",t,!1)}function jr(...t){return $r._create("endAt",t,!0)}function Hr(t,e,n,r){if(n[0]=_(n[0]),n[0]instanceof vr)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(Xt(e,r.key));else{const t=r.data.field(n.field);if(jt(t))throw new Y(q,'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(q,`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 se(i,s)}(t._query,t.firestore._databaseId,e,n[0]._document,r);{const s=tr(t.firestore);return function(t,e,n,r,s,i){const o=t.explicitOrderBy;if(s.length>o.length)throw new Y(q,`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(q,`Invalid query. Expected a string for document ID in ${r}(), but got a ${typeof u}`);if(!Oe(t)&&-1!==u.indexOf("/"))throw new Y(q,`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(q,`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(Xt(e,s))}else{const t=cr(n,r,u);a.push(t)}}return new se(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(q,"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(q,`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(q,`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 Xt(t,new dt(r))}if(n instanceof xn)return Xt(t,n._key);throw new Y(q,`Invalid query. When querying with documentId(), you must provide a valid string or a DocumentReference, but it was: ${gt(n)}.`)}function Gr(t,e){if(!Array.isArray(t)||0===t.length)throw new Y(q,`Invalid Query. A non-empty array is required for '${e.toString()}' filters.`)}function Kr(t,e){if(e.isInequality()){const n=Ce(t),r=e.field;if(null!==n&&!n.isEqual(r))throw new Y(q,`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=Re(t);null!==s&&Wr(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(q,`Invalid query. You cannot use more than one '${e.op.toString()}' filter.`):new Y(q,`Invalid query. You cannot use '${e.op.toString()}' filters with '${n.toString()}' filters.`)}function Wr(t,e,n){if(!n.isEqual(e))throw new Y(q,`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 Fr||e instanceof Vr))throw new Y(q,`Function ${t}() requires AppliableConstraints created with a call to 'where(...)', 'or(...)', or 'and(...)'.`)}function Yr(t,e,n){let r;return r=t?n&&(n.merge||n.mergeFields)?t.toFirestore(e,n):t.toFirestore(e):e,r}class Jr extends class{convertValue(t,e="none"){switch(Kt(t)){case 0:return null;case 1:return t.booleanValue;case 2:return Bt(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($t(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 C()}}convertObject(t,e){const n={};return xt(t.fields,((t,r)=>{n[t]=this.convertValue(r,e)})),n}convertGeoPoint(t){return new Kn(Bt(t.latitude),Bt(t.longitude))}convertArray(t,e){return(t.values||[]).map((t=>this.convertValue(t,e)))}convertServerTimestamp(t,e){switch(e){case"previous":const n=Ht(t);return null==n?null:this.convertValue(n,e);case"estimate":return this.convertTimestamp(zt(t));default:return null}}convertTimestamp(t){const e=Mt(t);return new Ut(e.seconds,e.nanos)}convertDocumentKey(t,e){const n=lt.fromString(t);O(_n(n));const r=new at(n.get(1),n.get(3)),s=new dt(n.popFirst(5));return r.isEqual(e)||V(`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 jn(t)}convertReference(t){const e=this.convertDocumentKey(t,this.firestore._databaseId);return new xn(this.firestore,null,e)}}function Xr(t){const e=kn((t=yt(t,xn)).firestore),n=new Jr(t.firestore);return Sn(e,[t._key]).then((e=>{O(1===e.length);const r=e[0];return new vr(t.firestore,n,t._key,r.isFoundDocument()?r:null,t.converter)}))}function Zr(t){!function(t){if("L"===t.limitType&&0===t.explicitOrderBy.length)throw new Y(K,"limitToLast() queries require specifying at least one orderBy() clause")}((t=yt(t,Pn))._query);const e=kn(t.firestore),n=new Jr(t.firestore);return async function(t,e){const n=x(t),r=dn(n.M,Pe(e));return(await n.P("RunQuery",r.parent,{structuredQuery:r.structuredQuery})).filter((t=>!!t.document)).map((t=>function(t,e,n){const r=un(t,e.name),s=sn(e.updateTime),i=e.createTime?sn(e.createTime):ve.min(),o=new Ie({mapValue:{fields:e.fields}});return Fe.newFoundDocument(r,s,i,o)}(n.M,t.document)))}(e,t._query).then((e=>{const r=e.map((e=>new br(t.firestore,n,e.key,e,t.converter)));return"L"===t._query.limitType&&r.reverse(),new Er(t,r)}))}function ts(t,e,n){const r=Yr((t=yt(t,xn)).converter,e,n),s=er(tr(t.firestore),"setDoc",t._key,r,null!==t.converter,n);return Tn(kn(t.firestore),[s.toMutation(t._key,ze.none())])}function es(t,e,n,...r){const s=tr((t=yt(t,xn)).firestore);let i;return i="string"==typeof(e=_(e))||e instanceof Hn?lr(s,"updateDoc",t._key,e,n,r):ur(s,"updateDoc",t._key,e),Tn(kn(t.firestore),[i.toMutation(t._key,ze.exists(!0))])}function ns(t){return Tn(kn((t=yt(t,xn)).firestore),[new Qe(t._key,ze.none())])}function rs(t,e){const n=Bn(t=yt(t,Ln)),r=Yr(t.converter,e),s=er(tr(t.firestore),"addDoc",n._key,r,null!==n.converter,{});return Tn(kn(t.firestore),[s.toMutation(n._key,ze.exists(!1))]).then((()=>n))}function ss(t){return is(t,{count:us()})}function is(t,e){const n=yt(t.firestore,Fn),r=kn(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 Dt(new Ft(e),t._aggregateType,t._internalFieldPath)));return async function(t,e,n){const r=x(t),s=function(t,e,n){const r=dn(t,e),s=[];return n.forEach((t=>{"count"===t.N?s.push({alias:t.alias.canonicalString(),count:{}}):"avg"===t.N?s.push({alias:t.alias.canonicalString(),avg:{field:gn(t.fieldPath)}}):"sum"===t.N&&s.push({alias:t.alias.canonicalString(),sum:{field:gn(t.fieldPath)}})})),{structuredAggregationQuery:{aggregations:s,structuredQuery:r.structuredQuery},parent:r.parent}}(r.M,Pe(e),n),i=s.parent;r.connection.v||delete s.parent;const o=(await r.P("RunAggregationQuery",i,s,1)).filter((t=>!!t.result));return O(1===o.length),(a=o[0]).result,a.result.aggregateFields,new Ie({mapValue:{fields:null===(u=a.result)||void 0===u?void 0:u.aggregateFields}});var a,u}(r,t._query,s).then((e=>function(t,e,n){const r=new Jr(t);return new On(e,r,n)}(n,t,e)))}function os(t){return new Cn("sum",mr("sum",t))}function as(t){return new Cn("avg",mr("average",t))}function us(){return new Cn("count")}function ls(t,e){var n,r;return t instanceof Cn&&e instanceof Cn&&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 cs(t,e){return Un(t.query,e.query)&&y(t.data(),e.data())}function hs(){return new nr("deleteField")}function ds(){return new sr("serverTimestamp")}function fs(...t){return new ir("arrayUnion",t)}function ps(...t){return new or("arrayRemove",t)}function ms(t){return new ar("increment",t)}class gs{constructor(t,e){this._firestore=t,this._commitHandler=e,this._mutations=[],this._committed=!1,this._dataReader=tr(t)}set(t,e,n){this._verifyNotCommitted();const r=ys(t,this._firestore),s=Yr(r.converter,e,n),i=er(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=ys(t,this._firestore);let i;return i="string"==typeof(e=_(e))||e instanceof Hn?lr(this._dataReader,"WriteBatch.update",s._key,e,n,r):ur(this._dataReader,"WriteBatch.update",s._key,e),this._mutations.push(i.toMutation(s._key,ze.exists(!0))),this}delete(t){this._verifyNotCommitted();const e=ys(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(H,"A write batch can no longer be used after commit() has been called.")}}function ys(t,e){if((t=_(t)).firestore!==e)throw new Y(q,"Provided document reference is from a different Firestore instance.");return t}function ws(t){const e=kn(t=yt(t,Fn));return new gs(t,(t=>Tn(e,t)))}class _s{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(q,"Firestore transactions require all reads to be executed before all writes.");const e=await Sn(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 Ye(n,this.precondition(n)))})),await Tn(this.datastore,this.mutations),this.committed=!0}recordVersion(t){let e;if(t.isFoundDocument())e=t.version;else{if(!t.isNoDocument())throw C();e=ve.min()}const n=this.readVersions.get(t.key.toString());if(n){if(!e.isEqual(n))throw new Y(z,"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(ve.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(ve.min()))throw new Y(q,"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 vs={maxAttempts:5};class bs{constructor(t,e,n,r,s){this.asyncQueue=t,this.datastore=e,this.options=n,this.updateFunction=r,this.deferred=s,this._t=n.maxAttempts,this.vt=new bn(this.asyncQueue,"transaction_retry")}run(){this._t-=1,this.bt()}bt(){this.vt.J((async()=>{const t=new _s(this.datastore),e=this.Et(t);e&&e.then((e=>{this.asyncQueue.enqueueAndForget((()=>t.commit().then((()=>{this.deferred.resolve(e)})).catch((t=>{this.At(t)}))))})).catch((t=>{this.At(t)}))}))}Et(t){try{const e=this.updateFunction(t);return!vt(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}}At(t){this._t>0&&this.It(t)?(this._t-=1,this.asyncQueue.enqueueAndForget((()=>(this.bt(),Promise.resolve())))):this.deferred.reject(t)}It(t){if("FirebaseError"===t.name){const e=t.code;return"aborted"===e||"failed-precondition"===e||"already-exists"===e||!function(t){switch(t){default:return C();case P:case L:case M:case j:case W:case Q:case U:return!1;case q:case B:case"already-exists":case $:case H:case z:case G:case K:case"data-loss":return!0}}(e)}return!1}}function Es(){return"undefined"!=typeof document?document:null}class Ts{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 Ts(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(P,"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 Ss{constructor(){this.Tt=Promise.resolve(),this.Rt=[],this.Pt=!1,this.Vt=[],this.$t=null,this.Dt=!1,this.Nt=!1,this.Ft=[],this.vt=new bn(this,"async_queue_retry"),this.xt=()=>{const t=Es();t&&D("AsyncQueue","Visibility state changed to "+t.visibilityState),this.vt.tt()};const t=Es();t&&"function"==typeof t.addEventListener&&t.addEventListener("visibilitychange",this.xt)}get isShuttingDown(){return this.Pt}enqueueAndForget(t){this.enqueue(t)}enqueueAndForgetEvenWhileRestricted(t){this.St(),this.qt(t)}enterRestrictedMode(t){if(!this.Pt){this.Pt=!0,this.Nt=t||!1;const e=Es();e&&"function"==typeof e.removeEventListener&&e.removeEventListener("visibilitychange",this.xt)}}enqueue(t){if(this.St(),this.Pt)return new Promise((()=>{}));const e=new J;return this.qt((()=>this.Pt&&this.Nt?Promise.resolve():(t().then(e.resolve,e.reject),e.promise))).then((()=>e.promise))}enqueueRetryable(t){this.enqueueAndForget((()=>(this.Rt.push(t),this.Ot())))}async Ot(){if(0!==this.Rt.length){try{await this.Rt[0](),this.Rt.shift(),this.vt.reset()}catch(t){if(!function(t){return"IndexedDbTransactionError"===t.name}(t))throw t;D("AsyncQueue","Operation failed with retryable error: "+t)}this.Rt.length>0&&this.vt.J((()=>this.Ot()))}}qt(t){const e=this.Tt.then((()=>(this.Dt=!0,t().catch((t=>{this.$t=t,this.Dt=!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 V("INTERNAL UNHANDLED ERROR: ",e),t})).then((t=>(this.Dt=!1,t))))));return this.Tt=e,e}enqueueAfterDelay(t,e,n){this.St(),this.Ft.indexOf(t)>-1&&(e=0);const r=Ts.createAndSchedule(this,t,e,n,(t=>this.kt(t)));return this.Vt.push(r),r}St(){this.$t&&C()}verifyOperationInProgress(){}async Ct(){let t;do{t=this.Tt,await t}while(t!==this.Tt)}Lt(t){for(const e of this.Vt)if(e.timerId===t)return!0;return!1}Mt(t){return this.Ct().then((()=>{this.Vt.sort(((t,e)=>t.targetTimeMs-e.targetTimeMs));for(const e of this.Vt)if(e.skipDelay(),"all"!==t&&e.timerId===t)break;return this.Ct()}))}Ut(t){this.Ft.push(t)}kt(t){const e=this.Vt.indexOf(t);this.Vt.splice(e,1)}}class As{constructor(t,e){this._firestore=t,this._transaction=e,this._dataReader=tr(t)}get(t){const e=ys(t,this._firestore),n=new Jr(this._firestore);return this._transaction.lookup([e._key]).then((t=>{if(!t||1!==t.length)return C();const r=t[0];if(r.isFoundDocument())return new vr(this._firestore,n,r.key,r,e.converter);if(r.isNoDocument())return new vr(this._firestore,n,e._key,null,e.converter);throw C()}))}set(t,e,n){const r=ys(t,this._firestore),s=Yr(r.converter,e,n),i=er(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=ys(t,this._firestore);let i;return i="string"==typeof(e=_(e))||e instanceof Hn?lr(this._dataReader,"Transaction.update",s._key,e,n,r):ur(this._dataReader,"Transaction.update",s._key,e),this._transaction.update(s._key,i),this}delete(t){const e=ys(t,this._firestore);return this._transaction.delete(e._key),this}}function ks(t,e,n){const r=kn(t=yt(t,Fn)),s=Object.assign(Object.assign({},vs),n);!function(t){if(t.maxAttempts<1)throw new Y(q,"Max attempts must be at least 1")}(s);const i=new J;return new bs(new Ss,r,s,(n=>e(new As(t,n))),i).run(),i.promise}k=`${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 Fn(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(q,'"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.9.0",""),e("firestore-lite","3.9.0","esm2017");export{Cn as AggregateField,On as AggregateQuerySnapshot,jn as Bytes,Ln as CollectionReference,xn as DocumentReference,vr as DocumentSnapshot,Hn as FieldPath,Gn as FieldValue,Fn as Firestore,Y as FirestoreError,Kn as GeoPoint,Pn as Query,Vr as QueryCompositeFilterConstraint,kr as QueryConstraint,br as QueryDocumentSnapshot,$r as QueryEndAtConstraint,Fr as QueryFieldFilterConstraint,xr as QueryLimitConstraint,Cr as QueryOrderByConstraint,Er as QuerySnapshot,qr as QueryStartAtConstraint,Ut as Timestamp,As as Transaction,gs as WriteBatch,rs as addDoc,ls as aggregateFieldEqual,cs as aggregateQuerySnapshotEqual,Rr as and,ps as arrayRemove,fs as arrayUnion,as as average,qn as collection,Mn as collectionGroup,Nn as connectFirestoreEmulator,us as count,ns as deleteDoc,hs as deleteField,Bn as doc,zn as documentId,jr as endAt,Ur as endBefore,is as getAggregate,ss as getCount,Xr as getDoc,Zr as getDocs,Vn as getFirestore,ms as increment,Dn as initializeFirestore,Pr as limit,Lr as limitToLast,Nr as or,Or as orderBy,Ir as query,Un as queryEqual,$n as refEqual,ks as runTransaction,ds as serverTimestamp,ts as setDoc,F as setLogLevel,Tr as snapshotEqual,Br as startAfter,Mr as startAt,os as sum,Rn as terminate,es as updateDoc,Dr as where,ws as writeBatch};
2
2
 
3
3
  //# sourceMappingURL=firebase-firestore-lite.js.map