firebase
Version:
Firebase JavaScript library for web and Node.js
1 lines • 80 kB
JavaScript
import{_getProvider as t,getApp as e,_removeServiceInstance as n,_registerComponent as r,registerVersion as s,SDK_VERSION as i}from"https://www.gstatic.com/firebasejs/9.0.0-beta.7/firebase-app.js";var o=function(t,e){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])})(t,e)};var a=function(){return(a=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var s in e=arguments[n])Object.prototype.hasOwnProperty.call(e,s)&&(t[s]=e[s]);return t}).apply(this,arguments)};function u(t,e){for(var n=0,r=e.length,s=t.length;n<r;n++,s++)t[s]=e[n];return t}var c={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:function(t,e){if(!Array.isArray(t))throw Error("encodeByteArray takes an array as a parameter");this.init_();for(var n=e?this.byteToCharMapWebSafe_:this.byteToCharMap_,r=[],s=0;s<t.length;s+=3){var i=t[s],o=s+1<t.length,a=o?t[s+1]:0,u=s+2<t.length,c=u?t[s+2]:0,l=i>>2,h=(3&i)<<4|a>>4,d=(15&a)<<2|c>>6,f=63&c;u||(f=64,o||(d=64)),r.push(n[l],n[h],n[d],n[f])}return r.join("")},encodeString:function(t,e){return this.HAS_NATIVE_SUPPORT&&!e?btoa(t):this.encodeByteArray(function(t){for(var e=[],n=0,r=0;r<t.length;r++){var 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}(t),e)},decodeString:function(t,e){return this.HAS_NATIVE_SUPPORT&&!e?atob(t):function(t){for(var e=[],n=0,r=0;n<t.length;){var s=t[n++];if(s<128)e[r++]=String.fromCharCode(s);else if(s>191&&s<224){var i=t[n++];e[r++]=String.fromCharCode((31&s)<<6|63&i)}else if(s>239&&s<365){var o=((7&s)<<18|(63&(i=t[n++]))<<12|(63&(a=t[n++]))<<6|63&t[n++])-65536;e[r++]=String.fromCharCode(55296+(o>>10)),e[r++]=String.fromCharCode(56320+(1023&o))}else{i=t[n++];var a=t[n++];e[r++]=String.fromCharCode((15&s)<<12|(63&i)<<6|63&a)}}return e.join("")}(this.decodeStringToByteArray(t,e))},decodeStringToByteArray:function(t,e){this.init_();for(var n=e?this.charToByteMapWebSafe_:this.charToByteMap_,r=[],s=0;s<t.length;){var i=n[t.charAt(s++)],o=s<t.length?n[t.charAt(s)]:0,a=++s<t.length?n[t.charAt(s)]:64,u=++s<t.length?n[t.charAt(s)]:64;if(++s,null==i||null==o||null==a||null==u)throw Error();var c=i<<2|o>>4;if(r.push(c),64!==a){var l=o<<4&240|a>>2;if(r.push(l),64!==u){var h=a<<6&192|u;r.push(h)}}}return r},init_:function(){if(!this.byteToCharMap_){this.byteToCharMap_={},this.charToByteMap_={},this.byteToCharMapWebSafe_={},this.charToByteMapWebSafe_={};for(var 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)}}};var l=function(t){function e(n,r,s){var i=t.call(this,r)||this;return i.code=n,i.customData=s,i.name="FirebaseError",Object.setPrototypeOf(i,e.prototype),Error.captureStackTrace&&Error.captureStackTrace(i,h.prototype.create),i}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}o(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}(e,t),e}(Error),h=function(){function t(t,e,n){this.service=t,this.serviceName=e,this.errors=n}return t.prototype.create=function(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];var r=e[0]||{},s=this.service+"/"+t,i=this.errors[t],o=i?d(i,r):"Error",a=this.serviceName+": "+o+" ("+s+").",u=new l(s,a,r);return u},t}();function d(t,e){return t.replace(f,(function(t,n){var r=e[n];return null!=r?String(r):"<"+n+"?>"}))}var f=/\{\$([^}]+)}/g;function p(t){return t&&t._delegate?t._delegate:t}var m,g,y=function(){function t(t,e,n){this.name=t,this.instanceFactory=e,this.type=n,this.multipleInstances=!1,this.serviceProps={},this.instantiationMode="LAZY",this.onInstanceCreated=null}return t.prototype.setInstantiationMode=function(t){return this.instantiationMode=t,this},t.prototype.setMultipleInstances=function(t){return this.multipleInstances=t,this},t.prototype.setServiceProps=function(t){return this.serviceProps=t,this},t.prototype.setInstanceCreatedCallback=function(t){return this.onInstanceCreated=t,this},t}();!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"}(g||(g={}));var w={debug:g.DEBUG,verbose:g.VERBOSE,info:g.INFO,warn:g.WARN,error:g.ERROR,silent:g.SILENT},_=g.INFO,v=((m={})[g.DEBUG]="log",m[g.VERBOSE]="log",m[g.INFO]="info",m[g.WARN]="warn",m[g.ERROR]="error",m),b=function(t,e){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];if(!(e<t.logLevel)){var s=(new Date).toISOString(),i=v[e];if(!i)throw new Error("Attempted to log a message with an invalid logType (value: "+e+")");console[i].apply(console,u(["["+s+"] "+t.name+":"],n))}},E=function(){function t(t){this.name=t,this._logLevel=_,this._logHandler=b,this._userLogHandler=null}return Object.defineProperty(t.prototype,"logLevel",{get:function(){return this._logLevel},set:function(t){if(!(t in g))throw new TypeError('Invalid value "'+t+'" assigned to `logLevel`');this._logLevel=t},enumerable:!1,configurable:!0}),t.prototype.setLogLevel=function(t){this._logLevel="string"==typeof t?w[t]:t},Object.defineProperty(t.prototype,"logHandler",{get:function(){return this._logHandler},set:function(t){if("function"!=typeof t)throw new TypeError("Value assigned to `logHandler` must be a function");this._logHandler=t},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"userLogHandler",{get:function(){return this._userLogHandler},set:function(t){this._userLogHandler=t},enumerable:!1,configurable:!0}),t.prototype.debug=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this._userLogHandler&&this._userLogHandler.apply(this,u([this,g.DEBUG],t)),this._logHandler.apply(this,u([this,g.DEBUG],t))},t.prototype.log=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this._userLogHandler&&this._userLogHandler.apply(this,u([this,g.VERBOSE],t)),this._logHandler.apply(this,u([this,g.VERBOSE],t))},t.prototype.info=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this._userLogHandler&&this._userLogHandler.apply(this,u([this,g.INFO],t)),this._logHandler.apply(this,u([this,g.INFO],t))},t.prototype.warn=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this._userLogHandler&&this._userLogHandler.apply(this,u([this,g.WARN],t)),this._logHandler.apply(this,u([this,g.WARN],t))},t.prototype.error=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];this._userLogHandler&&this._userLogHandler.apply(this,u([this,g.ERROR],t)),this._logHandler.apply(this,u([this,g.ERROR],t))},t}();let S="8.7.1";class T{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}}T.UNAUTHENTICATED=new T(null),T.GOOGLE_CREDENTIALS=new T("google-credentials-uid"),T.FIRST_PARTY=new T("first-party-uid");const A=new E("@firebase/firestore");function I(t){A.setLogLevel(t)}function V(t,...e){if(A.logLevel<=g.DEBUG){const n=e.map(L);A.debug(`Firestore (${S}): ${t}`,...n)}}function D(t,...e){if(A.logLevel<=g.ERROR){const n=e.map(L);A.error(`Firestore (${S}): ${t}`,...n)}}function N(t,...e){if(A.logLevel<=g.WARN){const n=e.map(L);A.warn(`Firestore (${S}): ${t}`,...n)}}function L(t){if("string"==typeof t)return t;try{return e=t,JSON.stringify(e)}catch(e){return t}var e}function F(t="Unexpected state"){const e=`FIRESTORE (${S}) INTERNAL ASSERTION FAILED: `+t;throw D(e),new Error(e)}function k(t,e){t||F()}function O(t,e){return t}const P="ok",q="cancelled",R="unknown",C="invalid-argument",x="deadline-exceeded",B="not-found",M="permission-denied",U="unauthenticated",$="resource-exhausted",j="failed-precondition",H="aborted",G="out-of-range",W="unimplemented",Q="internal",z="unavailable";class K extends Error{constructor(t,e){super(e),this.code=t,this.message=e,this.name="FirebaseError",this.toString=()=>`${this.name}: [code=${this.code}]: ${this.message}`}}class Y{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.authHeaders={},this.authHeaders.Authorization=`Bearer ${t}`}}class J{constructor(){this.changeListener=null}getToken(){return Promise.resolve(null)}invalidateToken(){}setChangeListener(t,e){this.changeListener=e,t.enqueueRetryable((()=>e(T.UNAUTHENTICATED)))}removeChangeListener(){this.changeListener=null}}class Z{constructor(t){this.token=t,this.changeListener=null}getToken(){return Promise.resolve(this.token)}invalidateToken(){}setChangeListener(t,e){this.changeListener=e,t.enqueueRetryable((()=>e(this.token.user)))}removeChangeListener(){this.changeListener=null}}class tt{constructor(t){this.currentUser=T.UNAUTHENTICATED,this.t=new Y,this.i=0,this.forceRefresh=!1,this.auth=null,this.asyncQueue=null,this.o=()=>{this.i++,this.currentUser=this.u(),this.t.resolve(),this.changeListener&&this.asyncQueue.enqueueRetryable((()=>this.changeListener(this.currentUser)))};const e=t=>{V("FirebaseCredentialsProvider","Auth detected"),this.auth=t,this.auth.addAuthTokenListener(this.o)};t.onInit((t=>e(t))),setTimeout((()=>{if(!this.auth){const n=t.getImmediate({optional:!0});n?e(n):(V("FirebaseCredentialsProvider","Auth not yet detected"),this.t.resolve())}}),0)}getToken(){const t=this.i,e=this.forceRefresh;return this.forceRefresh=!1,this.auth?this.auth.getToken(e).then((e=>this.i!==t?(V("FirebaseCredentialsProvider","getToken aborted due to token change."),this.getToken()):e?(k("string"==typeof e.accessToken),new X(e.accessToken,this.currentUser)):null)):Promise.resolve(null)}invalidateToken(){this.forceRefresh=!0}setChangeListener(t,e){this.asyncQueue=t,this.asyncQueue.enqueueRetryable((async()=>{await this.t.promise,await e(this.currentUser),this.changeListener=e}))}removeChangeListener(){this.auth&&this.auth.removeAuthTokenListener(this.o),this.changeListener=()=>Promise.resolve()}u(){const t=this.auth&&this.auth.getUid();return k(null===t||"string"==typeof t),new T(t)}}class et{constructor(t,e,n){this.h=t,this.l=e,this.m=n,this.type="FirstParty",this.user=T.FIRST_PARTY}get authHeaders(){const t={"X-Goog-AuthUser":this.l},e=this.h.auth.getAuthHeaderValueForFirstParty([]);return e&&(t.Authorization=e),this.m&&(t["X-Goog-Iam-Authorization-Token"]=this.m),t}}class nt{constructor(t,e,n){this.h=t,this.l=e,this.m=n}getToken(){return Promise.resolve(new et(this.h,this.l,this.m))}setChangeListener(t,e){t.enqueueRetryable((()=>e(T.FIRST_PARTY)))}removeChangeListener(){}invalidateToken(){}}class rt{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 st{constructor(t,e){this.projectId=t,this.database=e||"(default)"}get isDefaultDatabase(){return"(default)"===this.database}isEqual(t){return t instanceof st&&t.projectId===this.projectId&&t.database===this.database}}class it{constructor(t,e,n){void 0===e?e=0:e>t.length&&F(),void 0===n?n=t.length-e:n>t.length-e&&F(),this.segments=t,this.offset=e,this.len=n}get length(){return this.len}isEqual(t){return 0===it.comparator(this,t)}child(t){const e=this.segments.slice(this.offset,this.limit());return t instanceof it?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 ot extends it{construct(t,e,n){return new ot(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 K(C,`Invalid segment (${n}). Paths must not contain // in them.`);e.push(...n.split("/").filter((t=>t.length>0)))}return new ot(e)}static emptyPath(){return new ot([])}}const at=/^[_a-zA-Z][_a-zA-Z0-9]*$/;class ut extends it{construct(t,e,n){return new ut(t,e,n)}static isValidIdentifier(t){return at.test(t)}canonicalString(){return this.toArray().map((t=>(t=t.replace(/\\/g,"\\\\").replace(/`/g,"\\`"),ut.isValidIdentifier(t)||(t="`"+t+"`"),t))).join(".")}toString(){return this.canonicalString()}isKeyField(){return 1===this.length&&"__name__"===this.get(0)}static keyField(){return new ut(["__name__"])}static fromServerFormat(t){const e=[];let n="",r=0;const s=()=>{if(0===n.length)throw new K(C,`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 K(C,"Path has trailing escape character: "+t);const e=t[r+1];if("\\"!==e&&"."!==e&&"`"!==e)throw new K(C,"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 K(C,"Unterminated ` in path: "+t);return new ut(e)}static emptyPath(){return new ut([])}}class ct{constructor(t){this.path=t}static fromPath(t){return new ct(ot.fromString(t))}static fromName(t){return new ct(ot.fromString(t).popFirst(5))}hasCollectionId(t){return this.path.length>=2&&this.path.get(this.path.length-2)===t}isEqual(t){return null!==t&&0===ot.comparator(this.path,t.path)}toString(){return this.path.toString()}static comparator(t,e){return ot.comparator(t.path,e.path)}static isDocumentKey(t){return t.length%2==0}static fromSegments(t){return new ct(new ot(t.slice()))}}function lt(t,e,n){if(!n)throw new K(C,`Function ${t}() cannot be called with an empty ${e}.`)}function ht(t){if(!ct.isDocumentKey(t))throw new K(C,`Invalid document reference. Document references must have an even number of segments, but ${t} has ${t.length}.`)}function dt(t){if(ct.isDocumentKey(t))throw new K(C,`Invalid collection reference. Collection references must have an odd number of segments, but ${t} has ${t.length}.`)}function ft(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){if(t.constructor){const e=/function\s+([^\s(]+)\s*\(/.exec(t.constructor.toString());if(e&&e.length>1)return e[1]}return null}(t);return e?`a custom ${e} object`:"an object"}}return"function"==typeof t?"a function":F()}function pt(t,e){if("_delegate"in t&&(t=t._delegate),!(t instanceof e)){if(e.name===t.constructor.name)throw new K(C,"Type does not match the expected instance. Did you pass a reference from a different Firestore SDK?");{const n=ft(t);throw new K(C,`Expected type '${e.name}', but it was: ${n}`)}}return t}function mt(t,e){if(e<=0)throw new K(C,`Function ${t}() requires a positive number, but it was: ${e}.`)}function gt(t){return null==t}function yt(t){return 0===t&&1/t==-1/0}const wt={BatchGetDocuments:"batchGet",Commit:"commit",RunQuery:"runQuery"};var _t,vt;function bt(t){if(void 0===t)return D("RPC_ERROR","HTTP error has no status"),R;switch(t){case 200:return P;case 400:return j;case 401:return U;case 403:return M;case 404:return B;case 409:return H;case 416:return G;case 429:return $;case 499:return q;case 500:return R;case 501:return W;case 503:return z;case 504:return x;default:return t>=200&&t<300?P:t>=400&&t<500?j:t>=500&&t<600?Q:R}}(vt=_t||(_t={}))[vt.OK=0]="OK",vt[vt.CANCELLED=1]="CANCELLED",vt[vt.UNKNOWN=2]="UNKNOWN",vt[vt.INVALID_ARGUMENT=3]="INVALID_ARGUMENT",vt[vt.DEADLINE_EXCEEDED=4]="DEADLINE_EXCEEDED",vt[vt.NOT_FOUND=5]="NOT_FOUND",vt[vt.ALREADY_EXISTS=6]="ALREADY_EXISTS",vt[vt.PERMISSION_DENIED=7]="PERMISSION_DENIED",vt[vt.UNAUTHENTICATED=16]="UNAUTHENTICATED",vt[vt.RESOURCE_EXHAUSTED=8]="RESOURCE_EXHAUSTED",vt[vt.FAILED_PRECONDITION=9]="FAILED_PRECONDITION",vt[vt.ABORTED=10]="ABORTED",vt[vt.OUT_OF_RANGE=11]="OUT_OF_RANGE",vt[vt.UNIMPLEMENTED=12]="UNIMPLEMENTED",vt[vt.INTERNAL=13]="INTERNAL",vt[vt.UNAVAILABLE=14]="UNAVAILABLE",vt[vt.DATA_LOSS=15]="DATA_LOSS";class Et 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"}v(t,e,n,r){const s=this.T(t,e);V("RestConnection","Sending: ",s,n);const i={};return this.I(i,r),this.A(t,s,i,n).then((t=>(V("RestConnection","Received: ",t),t)),(e=>{throw N("RestConnection",`${t} failed with error: `,e,"url: ",s,"request:",n),e}))}P(t,e,n,r){return this.v(t,e,n,r)}I(t,e){if(t["X-Goog-Api-Client"]="gl-js/ fire/"+S,t["Content-Type"]="text/plain",this.databaseInfo.appId&&(t["X-Firebase-GMPID"]=this.databaseInfo.appId),e)for(const n in e.authHeaders)e.authHeaders.hasOwnProperty(n)&&(t[n]=e.authHeaders[n])}T(t,e){const n=wt[t];return`${this.p}/v1/${e}:${n}`}}{constructor(t,e){super(t),this.R=e}V(t,e){throw new Error("Not supported by FetchConnection")}async A(t,e,n,r){const s=JSON.stringify(r);let i;try{i=await this.R(e,{method:"POST",headers:n,body:s})}catch(t){throw new K(bt(t.status),"Request failed with error: "+t.statusText)}if(!i.ok)throw new K(bt(i.status),"Request failed with error: "+i.statusText);return i.json()}}function St(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 Tt{static N(){const t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",e=Math.floor(256/t.length)*t.length;let n="";for(;n.length<20;){const r=St(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 At(t,e){return t<e?-1:t>e?1:0}function It(t,e,n){return t.length===e.length&&t.every(((t,r)=>n(t,e[r])))}class Vt{constructor(t,e){if(this.seconds=t,this.nanoseconds=e,e<0)throw new K(C,"Timestamp nanoseconds out of range: "+e);if(e>=1e9)throw new K(C,"Timestamp nanoseconds out of range: "+e);if(t<-62135596800)throw new K(C,"Timestamp seconds out of range: "+t);if(t>=253402300800)throw new K(C,"Timestamp seconds out of range: "+t)}static now(){return Vt.fromMillis(Date.now())}static fromDate(t){return Vt.fromMillis(t.getTime())}static fromMillis(t){const e=Math.floor(t/1e3),n=Math.floor(1e6*(t-1e3*e));return new Vt(e,n)}toDate(){return new Date(this.toMillis())}toMillis(){return 1e3*this.seconds+this.nanoseconds/1e6}_compareTo(t){return this.seconds===t.seconds?At(this.nanoseconds,t.nanoseconds):At(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")}}class Dt{constructor(t){this.timestamp=t}static fromTimestamp(t){return new Dt(t)}static min(){return new Dt(new Vt(0,0))}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}}function Nt(t){let e=0;for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&e++;return e}function Lt(t,e){for(const n in t)Object.prototype.hasOwnProperty.call(t,n)&&e(n,t[n])}class Ft{constructor(t){this.fields=t,t.sort(ut.comparator)}covers(t){for(const e of this.fields)if(e.isPrefixOf(t))return!0;return!1}isEqual(t){return It(this.fields,t.fields,((t,e)=>t.isEqual(e)))}}class kt{constructor(t){this.binaryString=t}static fromBase64String(t){const e=atob(t);return new kt(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 kt(e)}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 At(this.binaryString,t.binaryString)}isEqual(t){return this.binaryString===t.binaryString}}kt.EMPTY_BYTE_STRING=new kt("");const Ot=new RegExp(/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.(\d+))?Z$/);function Pt(t){if(k(!!t),"string"==typeof t){let e=0;const n=Ot.exec(t);if(k(!!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:qt(t.seconds),nanos:qt(t.nanos)}}function qt(t){return"number"==typeof t?t:"string"==typeof t?Number(t):0}function Rt(t){return"string"==typeof t?kt.fromBase64String(t):kt.fromUint8Array(t)}function Ct(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 xt(t){const e=t.mapValue.fields.__previous_value__;return Ct(e)?xt(e):e}function Bt(t){const e=Pt(t.mapValue.fields.__local_write_time__.timestampValue);return new Vt(e.seconds,e.nanos)}function Mt(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?Ct(t)?4:10:F()}function Ut(t,e){const n=Mt(t);if(n!==Mt(e))return!1;switch(n){case 0:return!0;case 1:return t.booleanValue===e.booleanValue;case 4:return Bt(t).isEqual(Bt(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=Pt(t.timestampValue),r=Pt(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 Rt(t.bytesValue).isEqual(Rt(e.bytesValue))}(t,e);case 7:return t.referenceValue===e.referenceValue;case 8:return function(t,e){return qt(t.geoPointValue.latitude)===qt(e.geoPointValue.latitude)&&qt(t.geoPointValue.longitude)===qt(e.geoPointValue.longitude)}(t,e);case 2:return function(t,e){if("integerValue"in t&&"integerValue"in e)return qt(t.integerValue)===qt(e.integerValue);if("doubleValue"in t&&"doubleValue"in e){const n=qt(t.doubleValue),r=qt(e.doubleValue);return n===r?yt(n)===yt(r):isNaN(n)&&isNaN(r)}return!1}(t,e);case 9:return It(t.arrayValue.values||[],e.arrayValue.values||[],Ut);case 10:return function(t,e){const n=t.mapValue.fields||{},r=e.mapValue.fields||{};if(Nt(n)!==Nt(r))return!1;for(const t in n)if(n.hasOwnProperty(t)&&(void 0===r[t]||!Ut(n[t],r[t])))return!1;return!0}(t,e);default:return F()}}function $t(t,e){return void 0!==(t.values||[]).find((t=>Ut(t,e)))}function jt(t,e){const n=Mt(t),r=Mt(e);if(n!==r)return At(n,r);switch(n){case 0:return 0;case 1:return At(t.booleanValue,e.booleanValue);case 2:return function(t,e){const n=qt(t.integerValue||t.doubleValue),r=qt(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 Ht(t.timestampValue,e.timestampValue);case 4:return Ht(Bt(t),Bt(e));case 5:return At(t.stringValue,e.stringValue);case 6:return function(t,e){const n=Rt(t),r=Rt(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=At(n[t],r[t]);if(0!==e)return e}return At(n.length,r.length)}(t.referenceValue,e.referenceValue);case 8:return function(t,e){const n=At(qt(t.latitude),qt(e.latitude));return 0!==n?n:At(qt(t.longitude),qt(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=jt(n[t],r[t]);if(e)return e}return At(n.length,r.length)}(t.arrayValue,e.arrayValue);case 10:return function(t,e){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=At(r[t],i[t]);if(0!==e)return e;const o=jt(n[r[t]],s[i[t]]);if(0!==o)return o}return At(r.length,i.length)}(t.mapValue,e.mapValue);default:throw F()}}function Ht(t,e){if("string"==typeof t&&"string"==typeof e&&t.length===e.length)return At(t,e);const n=Pt(t),r=Pt(e),s=At(n.seconds,r.seconds);return 0!==s?s:At(n.nanos,r.nanos)}function Gt(t,e){return{referenceValue:`projects/${t.projectId}/databases/${t.database}/documents/${e.path.canonicalString()}`}}function Wt(t){return!!t&&"arrayValue"in t}function Qt(t){return!!t&&"nullValue"in t}function zt(t){return!!t&&"doubleValue"in t&&isNaN(Number(t.doubleValue))}function Kt(t){return!!t&&"mapValue"in t}function Yt(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 Lt(t.mapValue.fields,((t,n)=>e.mapValue.fields[t]=Yt(n))),e}if(t.arrayValue){const e={arrayValue:{values:[]}};for(let n=0;n<(t.arrayValue.values||[]).length;++n)e.arrayValue.values[n]=Yt(t.arrayValue.values[n]);return e}return Object.assign({},t)}class Xt{constructor(t){this.value=t}static empty(){return new Xt({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)],!Kt(e))return null;return e=(e.mapValue.fields||{})[t.lastSegment()],e||null}}set(t,e){this.getFieldsMap(t.popLast())[t.lastSegment()]=Yt(e)}setAll(t){let e=ut.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()]=Yt(t):r.push(s.lastSegment())}));const s=this.getFieldsMap(e);this.applyChanges(s,n,r)}delete(t){const e=this.field(t.popLast());Kt(e)&&e.mapValue.fields&&delete e.mapValue.fields[t.lastSegment()]}isEqual(t){return Ut(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)];Kt(r)&&r.mapValue.fields||(r={mapValue:{fields:{}}},e.mapValue.fields[t.get(n)]=r),e=r}return e.mapValue.fields}applyChanges(t,e,n){Lt(e,((e,n)=>t[e]=n));for(const e of n)delete t[e]}clone(){return new Xt(Yt(this.value))}}class Jt{constructor(t,e,n,r,s){this.key=t,this.documentType=e,this.version=n,this.data=r,this.documentState=s}static newInvalidDocument(t){return new Jt(t,0,Dt.min(),Xt.empty(),0)}static newFoundDocument(t,e,n){return new Jt(t,1,e,n,0)}static newNoDocument(t,e){return new Jt(t,2,e,Xt.empty(),0)}static newUnknownDocument(t,e){return new Jt(t,3,e,Xt.empty(),2)}convertToFoundDocument(t,e){return this.version=t,this.documentType=1,this.data=e,this.documentState=0,this}convertToNoDocument(t){return this.version=t,this.documentType=2,this.data=Xt.empty(),this.documentState=0,this}convertToUnknownDocument(t){return this.version=t,this.documentType=3,this.data=Xt.empty(),this.documentState=2,this}setHasCommittedMutations(){return this.documentState=2,this}setHasLocalMutations(){return this.documentState=1,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 Jt&&this.key.isEqual(t.key)&&this.version.isEqual(t.version)&&this.documentType===t.documentType&&this.documentState===t.documentState&&this.data.isEqual(t.data)}clone(){return new Jt(this.key,this.documentType,this.version,this.data.clone(),this.documentState)}toString(){return`Document(${this.key}, ${this.version}, ${JSON.stringify(this.data.value)}, {documentType: ${this.documentType}}), {documentState: ${this.documentState}})`}}class Zt{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.D=null}}function te(t,e=null,n=[],r=[],s=null,i=null,o=null){return new Zt(t,e,n,r,s,i,o)}class ee extends class{}{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.$(t,e,n):new ne(t,e,n):"array-contains"===e?new oe(t,n):"in"===e?new ae(t,n):"not-in"===e?new ue(t,n):"array-contains-any"===e?new ce(t,n):new ee(t,e,n)}static $(t,e,n){return"in"===e?new re(t,n):new se(t,n)}matches(t){const e=t.data.field(this.field);return"!="===this.op?null!==e&&this.F(jt(e,this.value)):null!==e&&Mt(this.value)===Mt(e)&&this.F(jt(e,this.value))}F(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 F()}}S(){return["<","<=",">",">=","!=","not-in"].indexOf(this.op)>=0}}class ne extends ee{constructor(t,e,n){super(t,e,n),this.key=ct.fromName(n.referenceValue)}matches(t){const e=ct.comparator(t.key,this.key);return this.F(e)}}class re extends ee{constructor(t,e){super(t,"in",e),this.keys=ie("in",e)}matches(t){return this.keys.some((e=>e.isEqual(t.key)))}}class se extends ee{constructor(t,e){super(t,"not-in",e),this.keys=ie("not-in",e)}matches(t){return!this.keys.some((e=>e.isEqual(t.key)))}}function ie(t,e){var n;return((null===(n=e.arrayValue)||void 0===n?void 0:n.values)||[]).map((t=>ct.fromName(t.referenceValue)))}class oe extends ee{constructor(t,e){super(t,"array-contains",e)}matches(t){const e=t.data.field(this.field);return Wt(e)&&$t(e.arrayValue,this.value)}}class ae extends ee{constructor(t,e){super(t,"in",e)}matches(t){const e=t.data.field(this.field);return null!==e&&$t(this.value.arrayValue,e)}}class ue extends ee{constructor(t,e){super(t,"not-in",e)}matches(t){if($t(this.value.arrayValue,{nullValue:"NULL_VALUE"}))return!1;const e=t.data.field(this.field);return null!==e&&!$t(this.value.arrayValue,e)}}class ce extends ee{constructor(t,e){super(t,"array-contains-any",e)}matches(t){const e=t.data.field(this.field);return!(!Wt(e)||!e.arrayValue.values)&&e.arrayValue.values.some((t=>$t(this.value.arrayValue,t)))}}class le{constructor(t,e){this.position=t,this.before=e}}class he{constructor(t,e="asc"){this.field=t,this.dir=e}}function de(t,e){return t.dir===e.dir&&t.field.isEqual(e.field)}function fe(t,e){if(null===t)return null===e;if(null===e)return!1;if(t.before!==e.before||t.position.length!==e.position.length)return!1;for(let n=0;n<t.position.length;n++)if(!Ut(t.position[n],e.position[n]))return!1;return!0}class pe{constructor(t,e=null,n=[],r=[],s=null,i="F",o=null,a=null){this.path=t,this.collectionGroup=e,this.explicitOrderBy=n,this.filters=r,this.limit=s,this.limitType=i,this.startAt=o,this.endAt=a,this.q=null,this.O=null,this.startAt,this.endAt}}function me(t){return!gt(t.limit)&&"L"===t.limitType}function ge(t){return t.explicitOrderBy.length>0?t.explicitOrderBy[0].field:null}function ye(t){for(const e of t.filters)if(e.S())return e.field;return null}function we(t){return null!==t.collectionGroup}function _e(t){const e=O(t);if(null===e.q){e.q=[];const t=ye(e),n=ge(e);if(null!==t&&null===n)t.isKeyField()||e.q.push(new he(t)),e.q.push(new he(ut.keyField(),"asc"));else{let t=!1;for(const n of e.explicitOrderBy)e.q.push(n),n.field.isKeyField()&&(t=!0);if(!t){const t=e.explicitOrderBy.length>0?e.explicitOrderBy[e.explicitOrderBy.length-1].dir:"asc";e.q.push(new he(ut.keyField(),t))}}}return e.q}function ve(t){const e=O(t);if(!e.O)if("F"===e.limitType)e.O=te(e.path,e.collectionGroup,_e(e),e.filters,e.limit,e.startAt,e.endAt);else{const t=[];for(const n of _e(e)){const e="desc"===n.dir?"asc":"desc";t.push(new he(n.field,e))}const n=e.endAt?new le(e.endAt.position,!e.endAt.before):null,r=e.startAt?new le(e.startAt.position,!e.startAt.before):null;e.O=te(e.path,e.collectionGroup,t,e.filters,e.limit,n,r)}return e.O}function be(t,e){return function(t){return"number"==typeof t&&Number.isInteger(t)&&!yt(t)&&t<=Number.MAX_SAFE_INTEGER&&t>=Number.MIN_SAFE_INTEGER}(e)?function(t){return{integerValue:""+t}}(e):function(t,e){if(t.C){if(isNaN(e))return{doubleValue:"NaN"};if(e===1/0)return{doubleValue:"Infinity"};if(e===-1/0)return{doubleValue:"-Infinity"}}return{doubleValue:yt(e)?"-0":e}}(t,e)}class Ee{constructor(){this._=void 0}}class Se extends Ee{}class Te extends Ee{constructor(t){super(),this.elements=t}}class Ae extends Ee{constructor(t){super(),this.elements=t}}class Ie extends Ee{constructor(t,e){super(),this.L=t,this.U=e}}class Ve{constructor(t,e){this.field=t,this.transform=e}}class De{constructor(t,e){this.updateTime=t,this.exists=e}static none(){return new De}static exists(t){return new De(void 0,t)}static updateTime(t){return new De(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 Ne{}class Le extends Ne{constructor(t,e,n,r=[]){super(),this.key=t,this.value=e,this.precondition=n,this.fieldTransforms=r,this.type=0}}class Fe extends Ne{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}}class ke extends Ne{constructor(t,e){super(),this.key=t,this.precondition=e,this.type=2,this.fieldTransforms=[]}}class Oe extends Ne{constructor(t,e){super(),this.key=t,this.precondition=e,this.type=3,this.fieldTransforms=[]}}const Pe={asc:"ASCENDING",desc:"DESCENDING"},qe={"<":"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"};class Re{constructor(t,e){this.databaseId=t,this.C=e}}function Ce(t,e){return t.C?`${new Date(1e3*e.seconds).toISOString().replace(/\.\d*/,"").replace("Z","")}.${("000000000"+e.nanoseconds).slice(-9)}Z`:{seconds:""+e.seconds,nanos:e.nanoseconds}}function xe(t,e){return t.C?e.toBase64():e.toUint8Array()}function Be(t,e){return Ce(t,e.toTimestamp())}function Me(t){return k(!!t),Dt.fromTimestamp(function(t){const e=Pt(t);return new Vt(e.seconds,e.nanos)}(t))}function Ue(t,e){return function(t){return new ot(["projects",t.projectId,"databases",t.database])}(t).child("documents").child(e).canonicalString()}function $e(t,e){return Ue(t.databaseId,e.path)}function je(t,e){const n=function(t){const e=ot.fromString(t);return k(Je(e)),e}(e);if(n.get(1)!==t.databaseId.projectId)throw new K(C,"Tried to deserialize key from different project: "+n.get(1)+" vs "+t.databaseId.projectId);if(n.get(3)!==t.databaseId.database)throw new K(C,"Tried to deserialize key from different database: "+n.get(3)+" vs "+t.databaseId.database);return new ct((k((r=n).length>4&&"documents"===r.get(4)),r.popFirst(5)));var r}function He(t,e){return Ue(t.databaseId,e)}function Ge(t){return new ot(["projects",t.databaseId.projectId,"databases",t.databaseId.database]).canonicalString()}function We(t,e,n){return{name:$e(t,e),fields:n.value.mapValue.fields}}function Qe(t){return{before:t.before,values:t.position}}function ze(t){return Pe[t]}function Ke(t){return qe[t]}function Ye(t){return{fieldPath:t.canonicalString()}}function Xe(t){const e=[];return t.fields.forEach((t=>e.push(t.canonicalString()))),{fieldPaths:e}}function Je(t){return t.length>=4&&"projects"===t.get(0)&&"databases"===t.get(2)}function Ze(t){return new Re(t,!0)}class tn{constructor(t,e,n=1e3,r=1.5,s=6e4){this.j=t,this.timerId=e,this.k=n,this.M=r,this.B=s,this.W=0,this.G=null,this.H=Date.now(),this.reset()}reset(){this.W=0}Y(){this.W=this.B}K(t){this.cancel();const e=Math.floor(this.W+this.J()),n=Math.max(0,Date.now()-this.H),r=Math.max(0,e-n);r>0&&V("ExponentialBackoff",`Backing off for ${r} ms (base delay: ${this.W} ms, delay with jitter: ${e} ms, last attempt: ${n} ms ago)`),this.G=this.j.enqueueAfterDelay(this.timerId,r,(()=>(this.H=Date.now(),t()))),this.W*=this.M,this.W<this.k&&(this.W=this.k),this.W>this.B&&(this.W=this.B)}Z(){null!==this.G&&(this.G.skipDelay(),this.G=null)}cancel(){null!==this.G&&(this.G.cancel(),this.G=null)}J(){return(Math.random()-.5)*this.W}}class en extends class{}{constructor(t,e,n){super(),this.credentials=t,this.X=e,this.L=n,this.tt=!1}et(){if(this.tt)throw new K(j,"The client has already been terminated.")}v(t,e,n){return this.et(),this.credentials.getToken().then((r=>this.X.v(t,e,n,r))).catch((t=>{throw"FirebaseError"===t.name?(t.code===U&&this.credentials.invalidateToken(),t):new K(R,t.toString())}))}P(t,e,n){return this.et(),this.credentials.getToken().then((r=>this.X.P(t,e,n,r))).catch((t=>{throw"FirebaseError"===t.name?(t.code===U&&this.credentials.invalidateToken(),t):new K(R,t.toString())}))}terminate(){this.tt=!0}}async function nn(t,e){const n=O(t),r=Ge(n.L)+"/documents",s={writes:e.map((t=>function(t,e){let n;if(e instanceof Le)n={update:We(t,e.key,e.value)};else if(e instanceof ke)n={delete:$e(t,e.key)};else if(e instanceof Fe)n={update:We(t,e.key,e.data),updateMask:Xe(e.fieldMask)};else{if(!(e instanceof Oe))return F();n={verify:$e(t,e.key)}}return e.fieldTransforms.length>0&&(n.updateTransforms=e.fieldTransforms.map((t=>function(t,e){const n=e.transform;if(n instanceof Se)return{fieldPath:e.field.canonicalString(),setToServerValue:"REQUEST_TIME"};if(n instanceof Te)return{fieldPath:e.field.canonicalString(),appendMissingElements:{values:n.elements}};if(n instanceof Ae)return{fieldPath:e.field.canonicalString(),removeAllFromArray:{values:n.elements}};if(n instanceof Ie)return{fieldPath:e.field.canonicalString(),increment:n.U};throw F()}(0,t)))),e.precondition.isNone||(n.currentDocument=function(t,e){return void 0!==e.updateTime?{updateTime:Be(t,e.updateTime)}:void 0!==e.exists?{exists:e.exists}:F()}(t,e.precondition)),n}(n.L,t)))};await n.v("Commit",r,s)}async function rn(t,e){const n=O(t),r=Ge(n.L)+"/documents",s={documents:e.map((t=>$e(n.L,t)))},i=await n.P("BatchGetDocuments",r,s),o=new Map;i.forEach((t=>{const e=function(t,e){return"found"in e?function(t,e){k(!!e.found),e.found.name,e.found.updateTime;const n=je(t,e.found.name),r=Me(e.found.updateTime),s=new Xt({mapValue:{fields:e.found.fields}});return Jt.newFoundDocument(n,r,s)}(t,e):"missing"in e?function(t,e){k(!!e.missing),k(!!e.readTime);const n=je(t,e.missing),r=Me(e.readTime);return Jt.newNoDocument(n,r)}(t,e):F()}(n.L,t);o.set(e.key.toString(),e)}));const a=[];return e.forEach((t=>{const e=o.get(t.toString());k(!!e),a.push(e)})),a}async function sn(t,e){const n=O(t),r=function(t,e){const n={structuredQuery:{}},r=e.path;null!==e.collectionGroup?(n.parent=He(t,r),n.structuredQuery.from=[{collectionId:e.collectionGroup,allDescendants:!0}]):(n.parent=He(t,r.popLast()),n.structuredQuery.from=[{collectionId:r.lastSegment()}]);const s=function(t){if(0===t.length)return;const e=t.map((t=>function(t){if("=="===t.op){if(zt(t.value))return{unaryFilter:{field:Ye(t.field),op:"IS_NAN"}};if(Qt(t.value))return{unaryFilter:{field:Ye(t.field),op:"IS_NULL"}}}else if("!="===t.op){if(zt(t.value))return{unaryFilter:{field:Ye(t.field),op:"IS_NOT_NAN"}};if(Qt(t.value))return{unaryFilter:{field:Ye(t.field),op:"IS_NOT_NULL"}}}return{fieldFilter:{field:Ye(t.field),op:Ke(t.op),value:t.value}}}(t)));return 1===e.length?e[0]:{compositeFilter:{op:"AND",filters:e}}}(e.filters);s&&(n.structuredQuery.where=s);const i=function(t){if(0!==t.length)return t.map((t=>function(t){return{field:Ye(t.field),direction:ze(t.dir)}}(t)))}(e.orderBy);i&&(n.structuredQuery.orderBy=i);const o=function(t,e){return t.C||gt(e)?e:{value:e}}(t,e.limit);return null!==o&&(n.structuredQuery.limit=o),e.startAt&&(n.structuredQuery.startAt=Qe(e.startAt)),e.endAt&&(n.structuredQuery.endAt=Qe(e.endAt)),n}(n.L,ve(e));return(await n.P("RunQuery",r.parent,{structuredQuery:r.structuredQuery})).filter((t=>!!t.document)).map((t=>function(t,e,n){const r=je(t,e.name),s=Me(e.updateTime),i=new Xt({mapValue:{fields:e.fields}}),o=Jt.newFoundDocument(r,s,i);return o}(n.L,t.document)))}const on=new Map;function an(t){if(t._terminated)throw new K(j,"The client has already been terminated.");if(!on.has(t)){V("ComponentProvider","Initializing Datastore");const i=function(t){return new Et(t,fetch.bind(null))}((e=t._databaseId,n=t.app.options.appId||"",r=t._persistenceKey,s=t._freezeSettings(),new rt(e,n,r,s.host,s.ssl,s.experimentalForceLongPolling,s.experimentalAutoDetectLongPolling,s.useFetchStreams))),o=Ze(t._databaseId),a=function(t,e,n){return new en(t,e,n)}(t._credentials,i,o);on.set(t,a)}var e,n,r,s;return on.get(t)}class un{constructor(t){var e;if(void 0===t.host){if(void 0!==t.ssl)throw new K(C,"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 K(C,"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 K(C,"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 cn{constructor(t,e){this.type="firestore-lite",this._persistenceKey="(lite)",this._settings=new un({}),this._settingsFrozen=!1,t instanceof st?(this._databaseId=t,this._credentials=new J):(this._app=t,this._databaseId=function(t){if(!Object.prototype.hasOwnProperty.apply(t.options,["projectId"]))throw new K(C,'"projectId" not provided in firebase.initializeApp.');return new st(t.options.projectId)}(t),this._credentials=new tt(e))}get app(){if(!this._app)throw new K(j,"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 K(j,"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 un(t),void 0!==t.credentials&&(this._credentials=function(t){if(!t)return new J;switch(t.type){case"gapi":const e=t.client;return k(!("object"!=typeof e||null===e||!e.auth||!e.auth.getAuthHeaderValueForFirstParty)),new nt(e,t.sessionIndex||"0",t.iamToken||null);case"provider":return t.client;default:throw new K(C,"makeCredentialsProvider 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=on.get(t);e&&(V("ComponentProvider","Removing Datastore"),on.delete(t),e.terminate())}(this),Promise.resolve()}}function ln(e,n){const r=t(e,"firestore/lite");if(r.isInitialized())throw new K(j,"Firestore can only be initialized once per app.");return r.initialize({options:n})}function hn(n=e()){return t(n,"firestore/lite").getImmediate()}function dn(t,e,n,r={}){const s=(t=pt(t,cn))._getSettings();if("firestore.googleapis.com"!==s.host&&s.host!==e&&N("Host has been set in both settings() and useEmulator(), emulator host will be used"),t._setSettings(Object.assign(Object.assign({},s),{host:`${e}:${n}`,ssl:!1})),r.mockUserToken){const 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.');var 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!");var i=a({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[c.encodeString(JSON.stringify({alg:"none",type:"JWT"}),!1),c.encodeString(JSON.stringify(i),!1),""].join(".")}(r.mockUserToken),n=r.mockUserToken.sub||r.mockUserToken.user_id;if(!n)throw new K(C,"mockUserToken must contain 'sub' or 'user_id' field!");t._credentials=new Z(new X(e,new T(n)))}}function fn(t){return t=pt(t,cn),n(t.app,"firestore/lite"),t._delete()}class pn{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 gn(this.firestore,this.converter,this._key.path.popLast())}withConverter(t){return new pn(this.firestore,t,this._key)}}class mn{constructor(t,e,n){this.converter=e,this._query=n,this.type="query",this.firestore=t}withConverter(t){return new mn(this.firestore,t,this._query)}}class gn extends mn{constructor(t,e,n){super(t,e,new pe(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 pn(this.firestore,null,new ct(t))}withConverter(t){return new gn(this.firestore,t,this._path)}}function yn(t,e,...n){if(t=p(t),lt("collection","path",e),t instanceof cn){const r=ot.fromString(e,...n);return dt(r),new gn(t,null,r)}{if(!(t instanceof pn||t instanceof gn))throw new K(C,"Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore");const r=ot.fromString(t.path,...n).child(ot.fromString(e));return dt(r),new gn(t.firestore,null,r)}}function wn(t,e){if(t=pt(t,cn),lt("collectionGroup","collection id",e),e.indexOf("/")>=0)throw new K(C,`Invalid collection ID '${e}' passed to function collectionGroup(). Collection IDs must not contain '/'.`);return new mn(t,null,function(t){return new pe(ot.emptyPath(),t)}(e))}function _n(t,e,...n){if(t=p(t),1===arguments.length&&(e=Tt.N()),lt("doc","path",e),t instanceof cn){const r=ot.fromString(e,...n);return ht(r),new pn(t,null,new ct(r))}{if(!(t instanceof pn||t instanceof gn))throw new K(C,"Expected first argument to collection() to be a CollectionReference, a DocumentReference or FirebaseFirestore");const r=t._path.child(ot.fromString(e,...n));return ht(r),new pn(t.firestore,t instanceof gn?t.converter:null,new ct(r))}}function vn(t,e){return t=p(t),e=p(e),(t instanceof pn||t instanceof gn)&&(e instanceof pn||e instanceof gn)&&t.firestore===e.firestore&&t.path===e.path&&t.converter===e.converter}function bn(t,e){return t=p(t),e=p(e),t instanceof mn&&e instanceof mn&&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(!de(t.orderBy[n],e.orderBy[n]))return!1;if(t.filters.length!==e.filters.length)return!1;for(let s=0;s<t.filters.length;s++)if(n=t.filters[s],r=e.filters[s],n.op!==r.op||!n.field.isEqual(r.field)||!Ut(n.value,r.value))return!1;var n,r;return t.collectionGroup===e.collectionGroup&&!!t.path.isEqual(e.path)&&!!fe(t.startAt,e.startAt)&&fe(t.endAt,e.endAt)}(ve(t),ve(e))&&t.limitType===e.limitType}(t._query,e._query)&&t.converter===e.converter}class En{constructor(...t){for(let e=0;e<t.length;++e)if(0===t[e].length)throw new K(C,"Invalid field name at argument $(i + 1). Field names must not be empty.");this._internalPath=new ut(t)}isEqual(t){return this._internalPath.isEqual(t._internalP