1
0
mirror of https://github.com/musix-org/musix-oss synced 2024-09-20 17:11:57 +00:00
musix-oss/node_modules/@firebase/firestore/dist/index.esm.min.js
2020-03-03 22:30:50 +02:00

3 lines
268 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import t from"@firebase/app";import{__spreadArrays as n,__extends as i,__awaiter as e,__generator as r,__assign as u}from"tslib";import{Logger as s,LogLevel as o}from"@firebase/logger";import{getUA as h,isReactNative as c,isElectron as a,isIE as f,isUWP as l,isBrowserExtension as d}from"@firebase/util";import{Component as v}from"@firebase/component";import{XhrIo as w,EventType as m,ErrorCode as p,createWebChannelTransport as g,WebChannel as b}from"@firebase/webchannel-wrapper";var y,_=t.SDK_VERSION,I=new s("@firebase/firestore");function T(){return I.logLevel===o.DEBUG?y.DEBUG:I.logLevel===o.SILENT?y.SILENT:y.ERROR}function E(t){switch(t){case y.DEBUG:I.logLevel=o.DEBUG;break;case y.ERROR:I.logLevel=o.ERROR;break;case y.SILENT:I.logLevel=o.SILENT;break;default:I.error("Firestore ("+_+"): Invalid value passed to `setLogLevel`")}}function R(t,i){for(var e=[],r=2;r<arguments.length;r++)e[r-2]=arguments[r];if(I.logLevel<=o.DEBUG){var u=e.map(D);I.debug.apply(I,n(["Firestore ("+_+") ["+t+"]: "+i],u))}}function A(t){for(var i=[],e=1;e<arguments.length;e++)i[e-1]=arguments[e];if(I.logLevel<=o.ERROR){var r=i.map(D);I.error.apply(I,n(["Firestore ("+_+"): "+t],r))}}function D(t){if("string"==typeof t)return t;var n=Ui.t();try{return n.i(t)}catch(n){return t}}function P(t){var n="FIRESTORE ("+_+") INTERNAL ASSERTION FAILED: "+t;throw A(n),new Error(n)}function S(t,n){t||P(n)}!function(t){t[t.DEBUG=0]="DEBUG",t[t.ERROR=1]="ERROR",t[t.SILENT=2]="SILENT"}(y||(y={}));var C=function(){function t(){}return t.u=function(){for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",n="",i=0;i<20;i++)n+=t.charAt(Math.floor(Math.random()*t.length));return S(20===n.length,"Invalid auto ID: "+n),n},t}();function V(t,n){return t<n?-1:t>n?1:0}function k(t,n){if(t.length!==n.length)return!1;for(var i=0;i<t.length;i++)if(!t[i].isEqual(n[i]))return!1;return!0}function N(t){return t+"\0"}var O,F,x,j,U=function(t,n,i,e,r){this.s=t,this.persistenceKey=n,this.host=i,this.ssl=e,this.forceLongPolling=r},L="(default)",B=function(){function t(t,n){this.projectId=t,this.database=n||L}return Object.defineProperty(t.prototype,"o",{get:function(){return this.database===L},enumerable:!0,configurable:!0}),t.prototype.isEqual=function(n){return n instanceof t&&n.projectId===this.projectId&&n.database===this.database},t.prototype.h=function(t){return V(this.projectId,t.projectId)||V(this.database,t.database)},t}();(F=O||(O={}))[F.l=0]="__PRIVATE_Unknown",F[F.v=1]="__PRIVATE_Online",F[F.m=2]="__PRIVATE_Offline",(j=x||(x={}))[j.p=0]="__PRIVATE_RemoteStore",j[j.g=1]="__PRIVATE_SharedClientState";var M=function(){function t(t){this.uid=t}return t.prototype._=function(){return null!=this.uid},t.prototype.I=function(){return this._()?"uid:"+this.uid:"anonymous-user"},t.prototype.isEqual=function(t){return t.uid===this.uid},t.UNAUTHENTICATED=new t(null),t.T=new t("google-credentials-uid"),t.R=new t("first-party-uid"),t}(),q={OK:"ok",CANCELLED:"cancelled",UNKNOWN:"unknown",INVALID_ARGUMENT:"invalid-argument",DEADLINE_EXCEEDED:"deadline-exceeded",NOT_FOUND:"not-found",ALREADY_EXISTS:"already-exists",PERMISSION_DENIED:"permission-denied",UNAUTHENTICATED:"unauthenticated",RESOURCE_EXHAUSTED:"resource-exhausted",FAILED_PRECONDITION:"failed-precondition",ABORTED:"aborted",OUT_OF_RANGE:"out-of-range",UNIMPLEMENTED:"unimplemented",INTERNAL:"internal",UNAVAILABLE:"unavailable",DATA_LOSS:"data-loss"},Q=function(t){function n(n,i){var e=t.call(this,i)||this;return e.code=n,e.message=i,e.name="FirebaseError",e.toString=function(){return e.name+": [code="+e.code+"]: "+e.message},e}return i(n,t),n}(Error),G=function(t,n){this.user=n,this.type="OAuth",this.A={},this.A.Authorization="Bearer "+t},W=function(){function t(){this.D=null}return t.prototype.getToken=function(){return Promise.resolve(null)},t.prototype.P=function(){},t.prototype.S=function(t){S(!this.D,"Can only call setChangeListener() once."),this.D=t,t(M.UNAUTHENTICATED)},t.prototype.C=function(){S(null!==this.D,"removeChangeListener() when no listener registered"),this.D=null},t}(),z=function(){function t(t){var n=this;this.V=null,this.currentUser=M.UNAUTHENTICATED,this.k=!1,this.N=0,this.D=null,this.forceRefresh=!1,this.V=function(){n.N++,n.currentUser=n.O(),n.k=!0,n.D&&n.D(n.currentUser)},this.N=0,this.auth=t.getImmediate({optional:!0}),this.auth?this.auth.addAuthTokenListener(this.V):(this.V(null),t.get().then((function(t){n.auth=t,n.V&&n.auth.addAuthTokenListener(n.V)}),(function(){})))}return t.prototype.getToken=function(){var t=this;S(null!=this.V,"getToken cannot be called after listener removed.");var n=this.N,i=this.forceRefresh;return this.forceRefresh=!1,this.auth?this.auth.getToken(i).then((function(i){if(t.N!==n)throw new Q(q.ABORTED,"getToken aborted due to token change.");return i?(S("string"==typeof i.accessToken,"Invalid tokenData returned from getToken():"+i),new G(i.accessToken,t.currentUser)):null})):Promise.resolve(null)},t.prototype.P=function(){this.forceRefresh=!0},t.prototype.S=function(t){S(!this.D,"Can only call setChangeListener() once."),this.D=t,this.k&&t(this.currentUser)},t.prototype.C=function(){S(null!=this.V,"removeChangeListener() called twice"),S(null!==this.D,"removeChangeListener() called when no listener registered"),this.auth&&this.auth.removeAuthTokenListener(this.V),this.V=null,this.D=null},t.prototype.O=function(){var t=this.auth&&this.auth.getUid();return S(null===t||"string"==typeof t,"Received invalid UID: "+t),new M(t)},t}(),K=function(){function t(t,n){this.F=t,this.j=n,this.type="FirstParty",this.user=M.R}return Object.defineProperty(t.prototype,"A",{get:function(){var t={"X-Goog-AuthUser":this.j},n=this.F.auth.U([]);return n&&(t.Authorization=n),t},enumerable:!0,configurable:!0}),t}(),H=function(){function t(t,n){this.F=t,this.j=n}return t.prototype.getToken=function(){return Promise.resolve(new K(this.F,this.j))},t.prototype.S=function(t){t(M.R)},t.prototype.C=function(){},t.prototype.P=function(){},t}();function J(t){if(!t)return new W;switch(t.type){case"gapi":var n=t.L;return S(!("object"!=typeof n||null===n||!n.auth||!n.auth.getAuthHeaderValueForFirstParty),"unexpected gapi interface"),new H(n,t.j||"0");case"provider":return t.L;default:throw new Q(q.INVALID_ARGUMENT,"makeCredentialsProvider failed due to invalid credential type")}}function Y(t,n){return Object.prototype.hasOwnProperty.call(t,n)}function X(t,n){return void 0!==t?t:n}function $(t,n){for(var i in t)if(Object.prototype.hasOwnProperty.call(t,i)){var e=Number(i);isNaN(e)||n(e,t[i])}}function Z(t,n){for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&n(i,t[i])}function tt(t){for(var n in S(null!=t&&"object"==typeof t,"isEmpty() expects object parameter."),t)if(Object.prototype.hasOwnProperty.call(t,n))return!1;return!0}function nt(t,n){if(0!==n.length)throw new Q(q.INVALID_ARGUMENT,"Function "+t+"() does not support arguments, but was called with "+yt(n.length,"argument")+".")}function it(t,n,i){if(n.length!==i)throw new Q(q.INVALID_ARGUMENT,"Function "+t+"() requires "+yt(i,"argument")+", but was called with "+yt(n.length,"argument")+".")}function et(t,n,i){if(n.length<i)throw new Q(q.INVALID_ARGUMENT,"Function "+t+"() requires at least "+yt(i,"argument")+", but was called with "+yt(n.length,"argument")+".")}function rt(t,n,i,e){if(n.length<i||n.length>e)throw new Q(q.INVALID_ARGUMENT,"Function "+t+"() requires between "+i+" and "+e+" arguments, but was called with "+yt(n.length,"argument")+".")}function ut(t,n,i,e){lt(t,n,bt(i)+" argument",e)}function st(t,n,i,e){void 0!==e&&ut(t,n,i,e)}function ot(t,n,i,e){lt(t,n,i+" option",e)}function ht(t,n,i,e){void 0!==e&&ot(t,n,i,e)}function ct(t,n,i,e,r){void 0!==e&&function(t,n,i,e,r){if(!(e instanceof Array))throw new Q(q.INVALID_ARGUMENT,"Function "+t+"() requires its "+n+" option to be an array, but it was: "+vt(e));for(var u=0;u<e.length;++u)if(!r(e[u]))throw new Q(q.INVALID_ARGUMENT,"Function "+t+"() requires all "+n+" elements to be "+i+", but the value at index "+u+" was: "+vt(e[u]))}(t,n,i,e,r)}function at(t,n,i,e,r){void 0!==e&&function(t,n,i,e,r){for(var u=[],s=0,o=r;s<o.length;s++){var h=o[s];if(h===e)return;u.push(vt(h))}var c=vt(e);throw new Q(q.INVALID_ARGUMENT,"Invalid value "+c+" provided to function "+t+'() for option "'+i+'". Acceptable values: '+u.join(", "))}(t,0,i,e,r)}function ft(t,n,i,e){if(!n.some((function(t){return t===e})))throw new Q(q.INVALID_ARGUMENT,"Invalid value "+vt(e)+" provided to function "+t+"() for its "+bt(i)+" argument. Acceptable values: "+n.join(", "))}function lt(t,n,i,e){if(!("object"===n?dt(e):"non-empty string"===n?"string"==typeof e&&""!==e:typeof e===n)){var r=vt(e);throw new Q(q.INVALID_ARGUMENT,"Function "+t+"() requires its "+i+" to be of type "+n+", but it was: "+r)}}function dt(t){return"object"==typeof t&&null!==t&&(Object.getPrototypeOf(t)===Object.prototype||null===Object.getPrototypeOf(t))}function vt(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";var n=function(t){if(t.constructor){var n=/function\s+([^\s(]+)\s*\(/.exec(t.constructor.toString());if(n&&n.length>1)return n[1]}return null}(t);return n?"a custom "+n+" object":"an object"}return"function"==typeof t?"a function":P("Unknown wrong type: "+typeof t)}function wt(t,n,i){if(void 0===i)throw new Q(q.INVALID_ARGUMENT,"Function "+t+"() requires a valid "+bt(n)+" argument, but it was undefined.")}function mt(t,n,i){Z(n,(function(n,e){if(i.indexOf(n)<0)throw new Q(q.INVALID_ARGUMENT,"Unknown option '"+n+"' passed to function "+t+"(). Available options: "+i.join(", "))}))}function pt(t,n,i,e){var r=vt(e);return new Q(q.INVALID_ARGUMENT,"Function "+t+"() requires its "+bt(i)+" argument to be a "+n+", but it was: "+r)}function gt(t,n,i){if(i<=0)throw new Q(q.INVALID_ARGUMENT,'Function "'+t+'()" requires its '+bt(n)+" argument to be a positive number, but it was: "+i+".")}function bt(t){switch(t){case 1:return"first";case 2:return"second";case 3:return"third";default:return t+"th"}}function yt(t,n){return t+" "+n+(1===t?"":"s")}var _t=function(){function t(t,n){if(it("GeoPoint",arguments,2),ut("GeoPoint","number",1,t),ut("GeoPoint","number",2,n),!isFinite(t)||t<-90||t>90)throw new Q(q.INVALID_ARGUMENT,"Latitude must be a number between -90 and 90, but was: "+t);if(!isFinite(n)||n<-180||n>180)throw new Q(q.INVALID_ARGUMENT,"Longitude must be a number between -180 and 180, but was: "+n);this.B=t,this.M=n}return Object.defineProperty(t.prototype,"latitude",{get:function(){return this.B},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"longitude",{get:function(){return this.M},enumerable:!0,configurable:!0}),t.prototype.isEqual=function(t){return this.B===t.B&&this.M===t.M},t.prototype.q=function(t){return V(this.B,t.B)||V(this.M,t.M)},t}(),It=function(){function t(t,n){if(this.seconds=t,this.nanoseconds=n,n<0)throw new Q(q.INVALID_ARGUMENT,"Timestamp nanoseconds out of range: "+n);if(n>=1e9)throw new Q(q.INVALID_ARGUMENT,"Timestamp nanoseconds out of range: "+n);if(t<-62135596800)throw new Q(q.INVALID_ARGUMENT,"Timestamp seconds out of range: "+t);if(t>=253402300800)throw new Q(q.INVALID_ARGUMENT,"Timestamp seconds out of range: "+t)}return t.now=function(){return t.fromMillis(Date.now())},t.fromDate=function(n){return t.fromMillis(n.getTime())},t.fromMillis=function(n){var i=Math.floor(n/1e3);return new t(i,1e6*(n-1e3*i))},t.prototype.toDate=function(){return new Date(this.toMillis())},t.prototype.toMillis=function(){return 1e3*this.seconds+this.nanoseconds/1e6},t.prototype.q=function(t){return this.seconds===t.seconds?V(this.nanoseconds,t.nanoseconds):V(this.seconds,t.seconds)},t.prototype.isEqual=function(t){return t.seconds===this.seconds&&t.nanoseconds===this.nanoseconds},t.prototype.toString=function(){return"Timestamp(seconds="+this.seconds+", nanoseconds="+this.nanoseconds+")"},t}(),Tt=function(){function t(t){this.timestamp=t}return t.G=function(n){var i=Math.floor(n/1e6);return new t(new It(i,n%1e6*1e3))},t.W=function(n){return new t(n)},t.K=function(){return t.MIN},t.prototype.h=function(t){return this.timestamp.q(t.timestamp)},t.prototype.isEqual=function(t){return this.timestamp.isEqual(t.timestamp)},t.prototype.H=function(){return 1e6*this.timestamp.seconds+this.timestamp.nanoseconds/1e3},t.prototype.toString=function(){return"SnapshotVersion("+this.timestamp.toString()+")"},t.prototype.J=function(){return this.timestamp},t.MIN=new t(new It(0,0)),t}(),Et=function(){function t(t,n,i){void 0===n?n=0:n>t.length&&P("offset "+n+" out of range "+t.length),void 0===i?i=t.length-n:i>t.length-n&&P("length "+i+" out of range "+(t.length-n)),this.segments=t,this.offset=n,this.Y=i}return Object.defineProperty(t.prototype,"length",{get:function(){return this.Y},enumerable:!0,configurable:!0}),t.prototype.isEqual=function(n){return 0===t.X(this,n)},t.prototype.child=function(n){var i=this.segments.slice(this.offset,this.limit());return n instanceof t?n.forEach((function(t){i.push(t)})):i.push(n),this.$(i)},t.prototype.limit=function(){return this.offset+this.length},t.prototype.Z=function(t){return t=void 0===t?1:t,S(this.length>=t,"Can't call popFirst() with less segments"),this.$(this.segments,this.offset+t,this.length-t)},t.prototype.tt=function(){return S(!this.nt(),"Can't call popLast() on empty path"),this.$(this.segments,this.offset,this.length-1)},t.prototype.it=function(){return S(!this.nt(),"Can't call firstSegment() on empty path"),this.segments[this.offset]},t.prototype.et=function(){return this.get(this.length-1)},t.prototype.get=function(t){return S(t<this.length,"Index out of range"),this.segments[this.offset+t]},t.prototype.nt=function(){return 0===this.length},t.prototype.rt=function(t){if(t.length<this.length)return!1;for(var n=0;n<this.length;n++)if(this.get(n)!==t.get(n))return!1;return!0},t.prototype.ut=function(t){if(this.length+1!==t.length)return!1;for(var n=0;n<this.length;n++)if(this.get(n)!==t.get(n))return!1;return!0},t.prototype.forEach=function(t){for(var n=this.offset,i=this.limit();n<i;n++)t(this.segments[n])},t.prototype.st=function(){return this.segments.slice(this.offset,this.limit())},t.X=function(t,n){for(var i=Math.min(t.length,n.length),e=0;e<i;e++){var r=t.get(e),u=n.get(e);if(r<u)return-1;if(r>u)return 1}return t.length<n.length?-1:t.length>n.length?1:0},t}(),Rt=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return i(n,t),n.prototype.$=function(t,i,e){return new n(t,i,e)},n.prototype.ot=function(){return this.st().join("/")},n.prototype.toString=function(){return this.ot()},n.ht=function(t){if(t.indexOf("//")>=0)throw new Q(q.INVALID_ARGUMENT,"Invalid path ("+t+"). Paths must not contain // in them.");return new n(t.split("/").filter((function(t){return t.length>0})))},n.ct=new n([]),n}(Et),At=/^[_a-zA-Z][_a-zA-Z0-9]*$/,Dt=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return i(n,t),n.prototype.$=function(t,i,e){return new n(t,i,e)},n.at=function(t){return At.test(t)},n.prototype.ot=function(){return this.st().map((function(t){return t=t.replace("\\","\\\\").replace("`","\\`"),n.at(t)||(t="`"+t+"`"),t})).join(".")},n.prototype.toString=function(){return this.ot()},n.prototype.ft=function(){return 1===this.length&&"__name__"===this.get(0)},n.lt=function(){return new n(["__name__"])},n.dt=function(t){for(var i=[],e="",r=0,u=function(){if(0===e.length)throw new Q(q.INVALID_ARGUMENT,"Invalid field path ("+t+"). Paths must not be empty, begin with '.', end with '.', or contain '..'");i.push(e),e=""},s=!1;r<t.length;){var o=t[r];if("\\"===o){if(r+1===t.length)throw new Q(q.INVALID_ARGUMENT,"Path has trailing escape character: "+t);var h=t[r+1];if("\\"!==h&&"."!==h&&"`"!==h)throw new Q(q.INVALID_ARGUMENT,"Path has invalid escape sequence: "+t);e+=h,r+=2}else"`"===o?(s=!s,r++):"."!==o||s?(e+=o,r++):(u(),r++)}if(u(),s)throw new Q(q.INVALID_ARGUMENT,"Unterminated ` in path: "+t);return new n(i)},n.ct=new n([]),n}(Et),Pt=function(){function t(n){this.path=n,S(t.vt(n),"Invalid DocumentKey with an odd number of segments: "+n.st().join("/"))}return t.prototype.wt=function(t){return this.path.length>=2&&this.path.get(this.path.length-2)===t},t.prototype.isEqual=function(t){return null!==t&&0===Rt.X(this.path,t.path)},t.prototype.toString=function(){return this.path.toString()},t.X=function(t,n){return Rt.X(t.path,n.path)},t.vt=function(t){return t.length%2==0},t.pt=function(n){return new t(new Rt(n.slice()))},t.gt=function(n){return new t(Rt.ht(n))},t.EMPTY=new t(new Rt([])),t}(),St=function(){function t(t,n){this.X=t,this.root=n||Vt.EMPTY}return t.prototype.bt=function(n,i){return new t(this.X,this.root.bt(n,i,this.X).yt(null,null,Vt._t,null,null))},t.prototype.remove=function(n){return new t(this.X,this.root.remove(n,this.X).yt(null,null,Vt._t,null,null))},t.prototype.get=function(t){for(var n=this.root;!n.nt();){var i=this.X(t,n.key);if(0===i)return n.value;i<0?n=n.left:i>0&&(n=n.right)}return null},t.prototype.indexOf=function(t){for(var n=0,i=this.root;!i.nt();){var e=this.X(t,i.key);if(0===e)return n+i.left.size;e<0?i=i.left:(n+=i.left.size+1,i=i.right)}return-1},t.prototype.nt=function(){return this.root.nt()},Object.defineProperty(t.prototype,"size",{get:function(){return this.root.size},enumerable:!0,configurable:!0}),t.prototype.It=function(){return this.root.It()},t.prototype.Tt=function(){return this.root.Tt()},t.prototype.Et=function(t){return this.root.Et(t)},t.prototype.forEach=function(t){this.Et((function(n,i){return t(n,i),!1}))},t.prototype.toString=function(){var t=[];return this.Et((function(n,i){return t.push(n+":"+i),!1})),"{"+t.join(", ")+"}"},t.prototype.Rt=function(t){return this.root.Rt(t)},t.prototype.At=function(){return new Ct(this.root,null,this.X,!1)},t.prototype.Dt=function(t){return new Ct(this.root,t,this.X,!1)},t.prototype.Pt=function(){return new Ct(this.root,null,this.X,!0)},t.prototype.St=function(t){return new Ct(this.root,t,this.X,!0)},t}(),Ct=function(){function t(t,n,i,e){this.Ct=e,this.Vt=[];for(var r=1;!t.nt();)if(r=n?i(t.key,n):1,e&&(r*=-1),r<0)t=this.Ct?t.left:t.right;else{if(0===r){this.Vt.push(t);break}this.Vt.push(t),t=this.Ct?t.right:t.left}}return t.prototype.kt=function(){S(this.Vt.length>0,"getNext() called on iterator when hasNext() is false.");var t=this.Vt.pop(),n={key:t.key,value:t.value};if(this.Ct)for(t=t.left;!t.nt();)this.Vt.push(t),t=t.right;else for(t=t.right;!t.nt();)this.Vt.push(t),t=t.left;return n},t.prototype.Nt=function(){return this.Vt.length>0},t.prototype.Ot=function(){if(0===this.Vt.length)return null;var t=this.Vt[this.Vt.length-1];return{key:t.key,value:t.value}},t}(),Vt=function(){function t(n,i,e,r,u){this.key=n,this.value=i,this.color=null!=e?e:t.RED,this.left=null!=r?r:t.EMPTY,this.right=null!=u?u:t.EMPTY,this.size=this.left.size+1+this.right.size}return t.prototype.yt=function(n,i,e,r,u){return new t(null!=n?n:this.key,null!=i?i:this.value,null!=e?e:this.color,null!=r?r:this.left,null!=u?u:this.right)},t.prototype.nt=function(){return!1},t.prototype.Et=function(t){return this.left.Et(t)||t(this.key,this.value)||this.right.Et(t)},t.prototype.Rt=function(t){return this.right.Rt(t)||t(this.key,this.value)||this.left.Rt(t)},t.prototype.min=function(){return this.left.nt()?this:this.left.min()},t.prototype.It=function(){return this.min().key},t.prototype.Tt=function(){return this.right.nt()?this.key:this.right.Tt()},t.prototype.bt=function(t,n,i){var e=this,r=i(t,e.key);return(e=r<0?e.yt(null,null,null,e.left.bt(t,n,i),null):0===r?e.yt(null,n,null,null,null):e.yt(null,null,null,null,e.right.bt(t,n,i))).Ft()},t.prototype.xt=function(){if(this.left.nt())return t.EMPTY;var n=this;return n.left.jt()||n.left.left.jt()||(n=n.Ut()),(n=n.yt(null,null,null,n.left.xt(),null)).Ft()},t.prototype.remove=function(n,i){var e,r=this;if(i(n,r.key)<0)r.left.nt()||r.left.jt()||r.left.left.jt()||(r=r.Ut()),r=r.yt(null,null,null,r.left.remove(n,i),null);else{if(r.left.jt()&&(r=r.Lt()),r.right.nt()||r.right.jt()||r.right.left.jt()||(r=r.Bt()),0===i(n,r.key)){if(r.right.nt())return t.EMPTY;e=r.right.min(),r=r.yt(e.key,e.value,null,null,r.right.xt())}r=r.yt(null,null,null,null,r.right.remove(n,i))}return r.Ft()},t.prototype.jt=function(){return this.color},t.prototype.Ft=function(){var t=this;return t.right.jt()&&!t.left.jt()&&(t=t.Mt()),t.left.jt()&&t.left.left.jt()&&(t=t.Lt()),t.left.jt()&&t.right.jt()&&(t=t.qt()),t},t.prototype.Ut=function(){var t=this.qt();return t.right.left.jt()&&(t=(t=(t=t.yt(null,null,null,null,t.right.Lt())).Mt()).qt()),t},t.prototype.Bt=function(){var t=this.qt();return t.left.left.jt()&&(t=(t=t.Lt()).qt()),t},t.prototype.Mt=function(){var n=this.yt(null,null,t.RED,null,this.right.left);return this.right.yt(null,null,this.color,n,null)},t.prototype.Lt=function(){var n=this.yt(null,null,t.RED,this.left.right,null);return this.left.yt(null,null,this.color,null,n)},t.prototype.qt=function(){var t=this.left.yt(null,null,!this.left.color,null,null),n=this.right.yt(null,null,!this.right.color,null,null);return this.yt(null,null,!this.color,t,n)},t.prototype.Qt=function(){var t=this.Gt();return Math.pow(2,t)<=this.size+1},t.prototype.Gt=function(){if(this.jt()&&this.left.jt())throw P("Red node has red child("+this.key+","+this.value+")");if(this.right.jt())throw P("Right child of ("+this.key+","+this.value+") is red");var t=this.left.Gt();if(t!==this.right.Gt())throw P("Black depths differ");return t+(this.jt()?0:1)},t.EMPTY=null,t.RED=!0,t._t=!1,t}(),kt=function(){function t(){this.size=0}return Object.defineProperty(t.prototype,"key",{get:function(){throw P("LLRBEmptyNode has no key.")},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"value",{get:function(){throw P("LLRBEmptyNode has no value.")},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"color",{get:function(){throw P("LLRBEmptyNode has no color.")},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"left",{get:function(){throw P("LLRBEmptyNode has no left child.")},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"right",{get:function(){throw P("LLRBEmptyNode has no right child.")},enumerable:!0,configurable:!0}),t.prototype.yt=function(t,n,i,e,r){return this},t.prototype.bt=function(t,n,i){return new Vt(t,n)},t.prototype.remove=function(t,n){return this},t.prototype.nt=function(){return!0},t.prototype.Et=function(t){return!1},t.prototype.Rt=function(t){return!1},t.prototype.It=function(){return null},t.prototype.Tt=function(){return null},t.prototype.jt=function(){return!1},t.prototype.Qt=function(){return!0},t.prototype.Gt=function(){return 0},t}();Vt.EMPTY=new kt;var Nt=function(){function t(t){this.X=t,this.data=new St(this.X)}return t.Wt=function(n){var i=new t(n.X);return n.forEach((function(t){i=i.add(t)})),i},t.prototype.has=function(t){return null!==this.data.get(t)},t.prototype.first=function(){return this.data.It()},t.prototype.last=function(){return this.data.Tt()},Object.defineProperty(t.prototype,"size",{get:function(){return this.data.size},enumerable:!0,configurable:!0}),t.prototype.indexOf=function(t){return this.data.indexOf(t)},t.prototype.forEach=function(t){this.data.Et((function(n,i){return t(n),!1}))},t.prototype.zt=function(t,n){for(var i=this.data.Dt(t[0]);i.Nt();){var e=i.kt();if(this.X(e.key,t[1])>=0)return;n(e.key)}},t.prototype.Kt=function(t,n){var i;for(i=void 0!==n?this.data.Dt(n):this.data.At();i.Nt();){if(!t(i.kt().key))return}},t.prototype.Ht=function(t){var n=this.data.Dt(t);return n.Nt()?n.kt().key:null},t.prototype.At=function(){return new Ot(this.data.At())},t.prototype.Dt=function(t){return new Ot(this.data.Dt(t))},t.prototype.add=function(t){return this.yt(this.data.remove(t).bt(t,!0))},t.prototype.delete=function(t){return this.has(t)?this.yt(this.data.remove(t)):this},t.prototype.nt=function(){return this.data.nt()},t.prototype.Jt=function(t){var n=this;return t.forEach((function(t){n=n.add(t)})),n},t.prototype.isEqual=function(n){if(!(n instanceof t))return!1;if(this.size!==n.size)return!1;for(var i=this.data.At(),e=n.data.At();i.Nt();){var r=i.kt().key,u=e.kt().key;if(0!==this.X(r,u))return!1}return!0},t.prototype.st=function(){var t=[];return this.forEach((function(n){t.push(n)})),t},t.prototype.toString=function(){var t=[];return this.forEach((function(n){return t.push(n)})),"SortedSet("+t.toString()+")"},t.prototype.yt=function(n){var i=new t(this.X);return i.data=n,i},t}(),Ot=function(){function t(t){this.Yt=t}return t.prototype.kt=function(){return this.Yt.kt().key},t.prototype.Nt=function(){return this.Yt.Nt()},t}(),Ft=function(){function t(){}return t.prototype.Xt=function(t,n){return new dn(n,t)},t.prototype.$t=function(t,n){return n},t.prototype.Zt=function(t){return null},t.prototype.isEqual=function(n){return n instanceof t},t.instance=new t,t}(),xt=function(){function t(t){this.elements=t}return t.prototype.Xt=function(t,n){return this.apply(t)},t.prototype.$t=function(t,n){return this.apply(t)},t.prototype.apply=function(t){for(var n=Lt(t),i=function(t){n.find((function(n){return n.isEqual(t)}))||n.push(t)},e=0,r=this.elements;e<r.length;e++){i(r[e])}return new gn(n)},t.prototype.Zt=function(t){return null},t.prototype.isEqual=function(n){return n instanceof t&&k(n.elements,this.elements)},t}(),jt=function(){function t(t){this.elements=t}return t.prototype.Xt=function(t,n){return this.apply(t)},t.prototype.$t=function(t,n){return this.apply(t)},t.prototype.apply=function(t){for(var n=Lt(t),i=function(t){n=n.filter((function(n){return!n.isEqual(t)}))},e=0,r=this.elements;e<r.length;e++){i(r[e])}return new gn(n)},t.prototype.Zt=function(t){return null},t.prototype.isEqual=function(n){return n instanceof t&&k(n.elements,this.elements)},t}(),Ut=function(){function t(t){this.tn=t}return t.prototype.Xt=function(t,n){var i=this.Zt(t);if(i instanceof cn&&this.tn instanceof cn){var e=i.nn+this.tn.nn;return new cn(e)}e=i.nn+this.tn.nn;return new an(e)},t.prototype.$t=function(t,n){return S(null!==n,"Didn't receive transformResult for NUMERIC_ADD transform"),n},t.prototype.Zt=function(t){return t instanceof on?t:new cn(0)},t.prototype.isEqual=function(n){return n instanceof t&&this.tn.isEqual(n.tn)},t}();function Lt(t){return t instanceof gn?t.nn.slice():[]}var Bt,Mt,qt=function(){function t(t){this.fields=t}return t.in=function(n){return new t(n)},t.en=function(n){var i=new Nt(Dt.X);return n.forEach((function(t){return i=i.add(t)})),new t(i)},t.prototype.rn=function(t){var n=!1;return this.fields.forEach((function(i){i.rt(t)&&(n=!0)})),n},t.prototype.isEqual=function(t){return this.fields.isEqual(t.fields)},t}(),Qt=function(){function t(t,n){this.field=t,this.transform=n}return t.prototype.isEqual=function(t){return this.field.isEqual(t.field)&&this.transform.isEqual(t.transform)},t}(),Gt=function(t,n){this.version=t,this.transformResults=n};(Mt=Bt||(Bt={}))[Mt.Set=0]="Set",Mt[Mt.un=1]="__PRIVATE_Patch",Mt[Mt.sn=2]="__PRIVATE_Transform",Mt[Mt.on=3]="__PRIVATE_Delete",Mt[Mt.hn=4]="__PRIVATE_Verify";var Wt,zt,Kt,Ht,Jt=function(){function t(t,n){this.updateTime=t,this.exists=n,S(void 0===t||void 0===n,'Precondition can specify "exists" or "updateTime" but not both')}return t.exists=function(n){return new t(void 0,n)},t.updateTime=function(n){return new t(n)},Object.defineProperty(t.prototype,"cn",{get:function(){return void 0===this.updateTime&&void 0===this.exists},enumerable:!0,configurable:!0}),t.prototype.an=function(t){return void 0!==this.updateTime?t instanceof yn&&t.version.isEqual(this.updateTime):void 0!==this.exists?this.exists===t instanceof yn:(S(this.cn,"Precondition should be empty"),!0)},t.prototype.isEqual=function(t){return n=this.updateTime,i=t.updateTime,(null!=n?!(!i||!n.isEqual(i)):n===i)&&this.exists===t.exists;var n,i},t.NONE=new t,t}(),Yt=function(){function t(){}return t.prototype.fn=function(t){null!=t&&S(t.key.isEqual(this.key),"Can only apply a mutation to a document with the same key")},t.ln=function(t){return t instanceof yn?t.version:Tt.MIN},t}(),Xt=function(t){function n(n,i,e){var r=t.call(this)||this;return r.key=n,r.value=i,r.dn=e,r.type=Bt.Set,r}return i(n,t),n.prototype.$t=function(t,n){this.fn(t),S(null==n.transformResults,"Transform results received by SetMutation.");var i=n.version;return new yn(this.key,i,{hasCommittedMutations:!0},this.value)},n.prototype.Xt=function(t,n,i){if(this.fn(t),!this.dn.an(t))return t;var e=Yt.ln(t);return new yn(this.key,e,{vn:!0},this.value)},n.prototype.wn=function(t){return null},n.prototype.isEqual=function(t){return t instanceof n&&this.key.isEqual(t.key)&&this.value.isEqual(t.value)&&this.dn.isEqual(t.dn)},n}(Yt),$t=function(t){function n(n,i,e,r){var u=t.call(this)||this;return u.key=n,u.data=i,u.mn=e,u.dn=r,u.type=Bt.un,u}return i(n,t),n.prototype.$t=function(t,n){if(this.fn(t),S(null==n.transformResults,"Transform results received by PatchMutation."),!this.dn.an(t))return new In(this.key,n.version);var i=this.pn(t);return new yn(this.key,n.version,{hasCommittedMutations:!0},i)},n.prototype.Xt=function(t,n,i){if(this.fn(t),!this.dn.an(t))return t;var e=Yt.ln(t),r=this.pn(t);return new yn(this.key,e,{vn:!0},r)},n.prototype.wn=function(t){return null},n.prototype.isEqual=function(t){return t instanceof n&&this.key.isEqual(t.key)&&this.mn.isEqual(t.mn)&&this.dn.isEqual(t.dn)},n.prototype.pn=function(t){var n;return n=t instanceof yn?t.data():pn.EMPTY,this.gn(n)},n.prototype.gn=function(t){var n=this;return this.mn.fields.forEach((function(i){if(!i.nt()){var e=n.data.field(i);t=null!==e?t.set(i,e):t.delete(i)}})),t},n}(Yt),Zt=function(t){function n(n,i){var e=t.call(this)||this;return e.key=n,e.fieldTransforms=i,e.type=Bt.sn,e.dn=Jt.exists(!0),e}return i(n,t),n.prototype.$t=function(t,n){if(this.fn(t),S(null!=n.transformResults,"Transform results missing for TransformMutation."),!this.dn.an(t))return new In(this.key,n.version);var i=this.bn(t),e=this.yn(t,n.transformResults),r=n.version,u=this._n(i.data(),e);return new yn(this.key,r,{hasCommittedMutations:!0},u)},n.prototype.Xt=function(t,n,i){if(this.fn(t),!this.dn.an(t))return t;var e=this.bn(t),r=this.In(i,t,n),u=this._n(e.data(),r);return new yn(this.key,e.version,{vn:!0},u)},n.prototype.wn=function(t){for(var n=null,i=0,e=this.fieldTransforms;i<e.length;i++){var r=e[i],u=t instanceof yn?t.field(r.field):void 0,s=r.transform.Zt(u||null);null!=s&&(n=null==n?pn.EMPTY.set(r.field,s):n.set(r.field,s))}return n},n.prototype.isEqual=function(t){return t instanceof n&&this.key.isEqual(t.key)&&k(this.fieldTransforms,t.fieldTransforms)&&this.dn.isEqual(t.dn)},n.prototype.bn=function(t){return S(t instanceof yn,"Unknown MaybeDocument type "+t),S(t.key.isEqual(this.key),"Can only transform a document with the same key"),t},n.prototype.yn=function(t,n){var i=[];S(this.fieldTransforms.length===n.length,"server transform result count ("+n.length+") should match field transform count ("+this.fieldTransforms.length+")");for(var e=0;e<n.length;e++){var r=this.fieldTransforms[e],u=r.transform,s=null;t instanceof yn&&(s=t.field(r.field)),i.push(u.$t(s,n[e]))}return i},n.prototype.In=function(t,n,i){for(var e=[],r=0,u=this.fieldTransforms;r<u.length;r++){var s=u[r],o=s.transform,h=null;n instanceof yn&&(h=n.field(s.field)),null===h&&i instanceof yn&&(h=i.field(s.field)),e.push(o.Xt(h,t))}return e},n.prototype._n=function(t,n){S(n.length===this.fieldTransforms.length,"TransformResults length mismatch.");for(var i=0;i<this.fieldTransforms.length;i++){var e=this.fieldTransforms[i].field;t=t.set(e,n[i])}return t},n}(Yt),tn=function(t){function n(n,i){var e=t.call(this)||this;return e.key=n,e.dn=i,e.type=Bt.on,e}return i(n,t),n.prototype.$t=function(t,n){return this.fn(t),S(null==n.transformResults,"Transform results received by DeleteMutation."),new _n(this.key,n.version,{hasCommittedMutations:!0})},n.prototype.Xt=function(t,n,i){return this.fn(t),this.dn.an(t)?(t&&S(t.key.isEqual(this.key),"Can only apply mutation to document with same key"),new _n(this.key,Tt.K())):t},n.prototype.wn=function(t){return null},n.prototype.isEqual=function(t){return t instanceof n&&this.key.isEqual(t.key)&&this.dn.isEqual(t.dn)},n}(Yt),nn=function(t){function n(n,i){var e=t.call(this)||this;return e.key=n,e.dn=i,e.type=Bt.hn,e}return i(n,t),n.prototype.$t=function(t,n){P("VerifyMutation should only be used in Transactions.")},n.prototype.Xt=function(t,n,i){P("VerifyMutation should only be used in Transactions.")},n.prototype.wn=function(t){P("VerifyMutation should only be used in Transactions.")},n.prototype.isEqual=function(t){return t instanceof n&&this.key.isEqual(t.key)&&this.dn.isEqual(t.dn)},n}(Yt);(zt=Wt||(Wt={}))[zt.Tn=0]="__PRIVATE_NullValue",zt[zt.En=1]="__PRIVATE_BooleanValue",zt[zt.Rn=2]="__PRIVATE_NumberValue",zt[zt.An=3]="__PRIVATE_TimestampValue",zt[zt.Dn=4]="__PRIVATE_StringValue",zt[zt.Pn=5]="__PRIVATE_BlobValue",zt[zt.Sn=6]="__PRIVATE_RefValue",zt[zt.Cn=7]="__PRIVATE_GeoPointValue",zt[zt.ArrayValue=8]="ArrayValue",zt[zt.Vn=9]="__PRIVATE_ObjectValue",(Ht=Kt||(Kt={}))[Ht.kn=0]="__PRIVATE_Default",Ht[Ht.Nn=1]="__PRIVATE_Estimate",Ht[Ht.On=2]="__PRIVATE_Previous";var en=function(){function t(t,n){this.Fn=t,this.timestampsInSnapshots=n}return t.xn=function(n,i){switch(n.serverTimestamps){case"estimate":return new t(Kt.Nn,i);case"previous":return new t(Kt.On,i);case"none":case void 0:return new t(Kt.kn,i);default:return P("fromSnapshotOptions() called with invalid options.")}},t}(),rn=function(){function t(){}return t.prototype.toString=function(){var t=this.value();return null===t?"null":t.toString()},t.prototype.jn=function(t){return S(this.Un!==t.Un,"Default compareTo should not be used for values of same type."),V(this.Un,t.Un)},t}(),un=function(t){function n(){var n=t.call(this)||this;return n.Un=Wt.Tn,n.nn=null,n}return i(n,t),n.prototype.value=function(t){return null},n.prototype.isEqual=function(t){return t instanceof n},n.prototype.h=function(t){return t instanceof n?0:this.jn(t)},n.prototype.Ln=function(){return 4},n.Bn=new n,n}(rn),sn=function(t){function n(n){var i=t.call(this)||this;return i.nn=n,i.Un=Wt.En,i}return i(n,t),n.prototype.value=function(t){return this.nn},n.prototype.isEqual=function(t){return t instanceof n&&this.nn===t.nn},n.prototype.h=function(t){return t instanceof n?V(this,t):this.jn(t)},n.prototype.Ln=function(){return 4},n.of=function(t){return t?n.Mn:n.qn},n.Mn=new n(!0),n.qn=new n(!1),n}(rn),on=function(t){function n(n){var i=t.call(this)||this;return i.nn=n,i.Un=Wt.Rn,i}return i(n,t),n.prototype.value=function(t){return this.nn},n.prototype.h=function(t){return t instanceof n?(i=this.nn,e=t.nn,i<e?-1:i>e?1:i===e?0:isNaN(i)?isNaN(e)?0:-1:1):this.jn(t);var i,e},n.prototype.Ln=function(){return 8},n}(rn);function hn(t,n){return t===n?0!==t||1/t==1/n:t!=t&&n!=n}var cn=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return i(n,t),n.prototype.isEqual=function(t){return t instanceof n&&hn(this.nn,t.nn)},n}(on),an=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return i(n,t),n.prototype.isEqual=function(t){return t instanceof n&&hn(this.nn,t.nn)},n.Qn=new n(NaN),n.POSITIVE_INFINITY=new n(1/0),n.NEGATIVE_INFINITY=new n(-1/0),n}(on),fn=function(t){function n(n){var i=t.call(this)||this;return i.nn=n,i.Un=Wt.Dn,i}return i(n,t),n.prototype.value=function(t){return this.nn},n.prototype.isEqual=function(t){return t instanceof n&&this.nn===t.nn},n.prototype.h=function(t){return t instanceof n?V(this.nn,t.nn):this.jn(t)},n.prototype.Ln=function(){return 2*this.nn.length},n}(rn),ln=function(t){function n(n){var i=t.call(this)||this;return i.nn=n,i.Un=Wt.An,i}return i(n,t),n.prototype.value=function(t){return!t||t.timestampsInSnapshots?this.nn:this.nn.toDate()},n.prototype.isEqual=function(t){return t instanceof n&&this.nn.isEqual(t.nn)},n.prototype.h=function(t){return t instanceof n?this.nn.q(t.nn):t instanceof dn?-1:this.jn(t)},n.prototype.Ln=function(){return 16},n}(rn),dn=function(t){function n(n,i){var e=t.call(this)||this;return e.Gn=n,e.previousValue=i,e.Un=Wt.An,e}return i(n,t),n.prototype.value=function(t){return t&&t.Fn===Kt.Nn?new ln(this.Gn).value(t):t&&t.Fn===Kt.On&&this.previousValue?this.previousValue.value(t):null},n.prototype.isEqual=function(t){return t instanceof n&&this.Gn.isEqual(t.Gn)},n.prototype.h=function(t){return t instanceof n?this.Gn.q(t.Gn):t instanceof ln?1:this.jn(t)},n.prototype.toString=function(){return"<ServerTimestamp localTime="+this.Gn.toString()+">"},n.prototype.Ln=function(){return 16+(this.previousValue?this.previousValue.Ln():0)},n}(rn),vn=function(t){function n(n){var i=t.call(this)||this;return i.nn=n,i.Un=Wt.Pn,i}return i(n,t),n.prototype.value=function(t){return this.nn},n.prototype.isEqual=function(t){return t instanceof n&&this.nn.isEqual(t.nn)},n.prototype.h=function(t){return t instanceof n?this.nn.q(t.nn):this.jn(t)},n.prototype.Ln=function(){return this.nn.Wn()},n}(rn),wn=function(t){function n(n,i){var e=t.call(this)||this;return e.s=n,e.key=i,e.Un=Wt.Sn,e}return i(n,t),n.prototype.value=function(t){return this.key},n.prototype.isEqual=function(t){return t instanceof n&&(this.key.isEqual(t.key)&&this.s.isEqual(t.s))},n.prototype.h=function(t){if(t instanceof n){var i=this.s.h(t.s);return 0!==i?i:Pt.X(this.key,t.key)}return this.jn(t)},n.prototype.Ln=function(){return this.s.projectId.length+this.s.database.length+this.key.toString().length},n}(rn),mn=function(t){function n(n){var i=t.call(this)||this;return i.nn=n,i.Un=Wt.Cn,i}return i(n,t),n.prototype.value=function(t){return this.nn},n.prototype.isEqual=function(t){return t instanceof n&&this.nn.isEqual(t.nn)},n.prototype.h=function(t){return t instanceof n?this.nn.q(t.nn):this.jn(t)},n.prototype.Ln=function(){return 16},n}(rn),pn=function(t){function n(n){var i=t.call(this)||this;return i.nn=n,i.Un=Wt.Vn,i}return i(n,t),n.prototype.value=function(t){var n={};return this.nn.Et((function(i,e){n[i]=e.value(t)})),n},n.prototype.forEach=function(t){this.nn.Et(t)},n.prototype.isEqual=function(t){if(t instanceof n){for(var i=this.nn.At(),e=t.nn.At();i.Nt()&&e.Nt();){var r=i.kt(),u=e.kt();if(r.key!==u.key||!r.value.isEqual(u.value))return!1}return!i.Nt()&&!e.Nt()}return!1},n.prototype.h=function(t){if(t instanceof n){for(var i=this.nn.At(),e=t.nn.At();i.Nt()&&e.Nt();){var r=i.kt(),u=e.kt(),s=V(r.key,u.key)||r.value.h(u.value);if(s)return s}return V(i.Nt(),e.Nt())}return this.jn(t)},n.prototype.set=function(t,i){if(S(!t.nt(),"Cannot set field for empty path on ObjectValue"),1===t.length)return this.zn(t.it(),i);var e=this.child(t.it());e instanceof n||(e=n.EMPTY);var r=e.set(t.Z(),i);return this.zn(t.it(),r)},n.prototype.delete=function(t){if(S(!t.nt(),"Cannot delete field for empty path on ObjectValue"),1===t.length)return new n(this.nn.remove(t.it()));var i=this.child(t.it());if(i instanceof n){var e=i.delete(t.Z());return new n(this.nn.bt(t.it(),e))}return this},n.prototype.contains=function(t){return null!==this.field(t)},n.prototype.field=function(t){S(!t.nt(),"Can't get field of empty path");var i=this;return t.forEach((function(t){i=i instanceof n?i.nn.get(t):null})),i},n.prototype.mn=function(){var t=new Nt(Dt.X);return this.nn.forEach((function(i,e){var r=new Dt([i]);if(e instanceof n){var u=e.mn().fields;u.nt()?t=t.add(r):u.forEach((function(n){t=t.add(r.child(n))}))}else t=t.add(r)})),qt.in(t)},n.prototype.Ln=function(){var t=0;return this.nn.Et((function(n,i){t+=n.length+i.Ln()})),t},n.prototype.toString=function(){return this.nn.toString()},n.prototype.child=function(t){return this.nn.get(t)||void 0},n.prototype.zn=function(t,i){return new n(this.nn.bt(t,i))},n.EMPTY=new n(new St(V)),n}(rn),gn=function(t){function n(n){var i=t.call(this)||this;return i.nn=n,i.Un=Wt.ArrayValue,i}return i(n,t),n.prototype.value=function(t){return this.nn.map((function(n){return n.value(t)}))},n.prototype.contains=function(t){for(var n=0,i=this.nn;n<i.length;n++){if(i[n].isEqual(t))return!0}return!1},n.prototype.forEach=function(t){this.nn.forEach(t)},n.prototype.isEqual=function(t){if(t instanceof n){if(this.nn.length!==t.nn.length)return!1;for(var i=0;i<this.nn.length;i++)if(!this.nn[i].isEqual(t.nn[i]))return!1;return!0}return!1},n.prototype.h=function(t){if(t instanceof n){for(var i=Math.min(this.nn.length,t.nn.length),e=0;e<i;e++){var r=this.nn[e].h(t.nn[e]);if(r)return r}return V(this.nn.length,t.nn.length)}return this.jn(t)},n.prototype.Ln=function(){return this.nn.reduce((function(t,n){return t+n.Ln()}),0)},n.prototype.toString=function(){return"["+this.nn.map((function(t){return t.toString()})).join(",")+"]"},n}(rn),bn=function(){function t(t,n){this.key=t,this.version=n}return t.Kn=function(t,n){return Pt.X(t.key,n.key)},t}(),yn=function(t){function n(n,i,e,r,u,s){var o=t.call(this,n,i)||this;return o.Hn=r,o.proto=u,o.converter=s,S(void 0!==o.Hn||void 0!==o.proto&&void 0!==o.converter,"If objectValue is not defined, proto and converter need to be set."),o.vn=!!e.vn,o.hasCommittedMutations=!!e.hasCommittedMutations,o}return i(n,t),n.prototype.field=function(t){if(this.Hn)return this.Hn.field(t);this.Jn||(this.Jn=new Map);var n=t.ot(),i=this.Jn.get(n);if(void 0===i){var e=this.Yn(t);i=void 0===e?null:this.converter(e),this.Jn.set(n,i)}return i},n.prototype.data=function(){var t=this;if(!this.Hn){var n=pn.EMPTY;Z(this.proto.fields||{},(function(i,e){n=n.set(new Dt([i]),t.converter(e))})),this.Hn=n,this.Jn=void 0}return this.Hn},n.prototype.value=function(){return this.data().value()},n.prototype.isEqual=function(t){return t instanceof n&&this.key.isEqual(t.key)&&this.version.isEqual(t.version)&&this.vn===t.vn&&this.hasCommittedMutations===t.hasCommittedMutations&&this.data().isEqual(t.data())},n.prototype.toString=function(){return"Document("+this.key+", "+this.version+", "+this.data().toString()+", {hasLocalMutations: "+this.vn+"}), {hasCommittedMutations: "+this.hasCommittedMutations+"})"},Object.defineProperty(n.prototype,"hasPendingWrites",{get:function(){return this.vn||this.hasCommittedMutations},enumerable:!0,configurable:!0}),n.prototype.Yn=function(t){S(void 0!==this.proto,"Can only call getProtoField() when proto is defined");for(var n=this.proto.fields?this.proto.fields[t.it()]:void 0,i=1;i<t.length;++i){if(!n||!n.mapValue||!n.mapValue.fields)return;n=n.mapValue.fields[t.get(i)]}return n},n.Xn=function(t,n,i){var e=n.field(t),r=i.field(t);return null!==e&&null!==r?e.h(r):P("Trying to compare documents on fields that don't exist")},n}(bn),_n=function(t){function n(n,i,e){var r=t.call(this,n,i)||this;return r.hasCommittedMutations=!(!e||!e.hasCommittedMutations),r}return i(n,t),n.prototype.toString=function(){return"NoDocument("+this.key+", "+this.version+")"},Object.defineProperty(n.prototype,"hasPendingWrites",{get:function(){return this.hasCommittedMutations},enumerable:!0,configurable:!0}),n.prototype.isEqual=function(t){return t instanceof n&&t.hasCommittedMutations===this.hasCommittedMutations&&t.version.isEqual(this.version)&&t.key.isEqual(this.key)},n}(bn),In=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return i(n,t),n.prototype.toString=function(){return"UnknownDocument("+this.key+", "+this.version+")"},Object.defineProperty(n.prototype,"hasPendingWrites",{get:function(){return!0},enumerable:!0,configurable:!0}),n.prototype.isEqual=function(t){return t instanceof n&&t.version.isEqual(this.version)&&t.key.isEqual(this.key)},n}(bn),Tn=Number,En=Tn.MIN_SAFE_INTEGER||-(Math.pow(2,53)-1),Rn=Tn.MAX_SAFE_INTEGER||Math.pow(2,53)-1,An=Tn.isInteger||function(t){return"number"==typeof t&&isFinite(t)&&Math.floor(t)===t};function Dn(t){return null==t}function Pn(t){return An(t)&&t<=Rn&&t>=En}var Sn,Cn,Vn=function(){function t(t,n,i,e,r,u,s){void 0===n&&(n=null),void 0===i&&(i=[]),void 0===e&&(e=[]),void 0===r&&(r=null),void 0===u&&(u=null),void 0===s&&(s=null),this.path=t,this.collectionGroup=n,this.orderBy=i,this.filters=e,this.limit=r,this.startAt=u,this.endAt=s,this.$n=null}return t.prototype.canonicalId=function(){if(null===this.$n){var t=this.path.ot();null!==this.collectionGroup&&(t+="|cg:"+this.collectionGroup),t+="|f:";for(var n=0,i=this.filters;n<i.length;n++){t+=i[n].canonicalId(),t+=","}t+="|ob:";for(var e=0,r=this.orderBy;e<r.length;e++){t+=r[e].canonicalId(),t+=","}Dn(this.limit)||(t+="|l:",t+=this.limit),this.startAt&&(t+="|lb:",t+=this.startAt.canonicalId()),this.endAt&&(t+="|ub:",t+=this.endAt.canonicalId()),this.$n=t}return this.$n},t.prototype.toString=function(){var t=this.path.ot();return null!==this.collectionGroup&&(t+=" collectionGroup="+this.collectionGroup),this.filters.length>0&&(t+=", filters: ["+this.filters.join(", ")+"]"),Dn(this.limit)||(t+=", limit: "+this.limit),this.orderBy.length>0&&(t+=", orderBy: ["+this.orderBy.join(", ")+"]"),this.startAt&&(t+=", startAt: "+this.startAt.canonicalId()),this.endAt&&(t+=", endAt: "+this.endAt.canonicalId()),"Target("+t+")"},t.prototype.isEqual=function(t){if(this.limit!==t.limit)return!1;if(this.orderBy.length!==t.orderBy.length)return!1;for(var n=0;n<this.orderBy.length;n++)if(!this.orderBy[n].isEqual(t.orderBy[n]))return!1;if(this.filters.length!==t.filters.length)return!1;for(n=0;n<this.filters.length;n++)if(!this.filters[n].isEqual(t.filters[n]))return!1;return this.collectionGroup===t.collectionGroup&&(!!this.path.isEqual(t.path)&&(!(null!==this.startAt?!this.startAt.isEqual(t.startAt):null!==t.startAt)&&(null!==this.endAt?this.endAt.isEqual(t.endAt):null===t.endAt)))},t.prototype.Zn=function(){return Pt.vt(this.path)&&null===this.collectionGroup&&0===this.filters.length},t}();(Cn=Sn||(Sn={})).ti="F",Cn.ni="L";var kn,Nn,On=function(){function t(t,n,i,e,r,u,s,o){void 0===n&&(n=null),void 0===i&&(i=[]),void 0===e&&(e=[]),void 0===r&&(r=null),void 0===u&&(u=Sn.ti),void 0===s&&(s=null),void 0===o&&(o=null),this.path=t,this.collectionGroup=n,this.ii=i,this.filters=e,this.limit=r,this.ei=u,this.startAt=s,this.endAt=o,this.ri=null,this.ui=null,this.startAt&&this.si(this.startAt),this.endAt&&this.si(this.endAt)}return t.oi=function(n){return new t(n)},Object.defineProperty(t.prototype,"orderBy",{get:function(){if(null===this.ri){var t=this.hi(),n=this.ci();if(null!==t&&null===n)t.ft()?this.ri=[zn]:this.ri=[new Wn(t),zn];else{S(null===t||null!==n&&t.isEqual(n),"First orderBy should match inequality field."),this.ri=[];for(var i=!1,e=0,r=this.ii;e<r.length;e++){var u=r[e];this.ri.push(u),u.field.ft()&&(i=!0)}if(!i){var s=this.ii.length>0?this.ii[this.ii.length-1].dir:Qn.ASCENDING;this.ri.push(s===Qn.ASCENDING?zn:Kn)}}}return this.ri},enumerable:!0,configurable:!0}),t.prototype.ai=function(n){S(null==this.hi()||!(n instanceof jn)||!n.fi()||n.field.isEqual(this.hi()),"Query must only have one inequality field."),S(!this.Zn(),"No filtering allowed for document query");var i=this.filters.concat([n]);return new t(this.path,this.collectionGroup,this.ii.slice(),i,this.limit,this.ei,this.startAt,this.endAt)},t.prototype.li=function(n){S(!this.startAt&&!this.endAt,"Bounds must be set after orderBy");var i=this.ii.concat([n]);return new t(this.path,this.collectionGroup,i,this.filters.slice(),this.limit,this.ei,this.startAt,this.endAt)},t.prototype.di=function(n){return new t(this.path,this.collectionGroup,this.ii.slice(),this.filters.slice(),n,Sn.ti,this.startAt,this.endAt)},t.prototype.vi=function(n){return new t(this.path,this.collectionGroup,this.ii.slice(),this.filters.slice(),n,Sn.ni,this.startAt,this.endAt)},t.prototype.wi=function(n){return new t(this.path,this.collectionGroup,this.ii.slice(),this.filters.slice(),this.limit,this.ei,n,this.endAt)},t.prototype.mi=function(n){return new t(this.path,this.collectionGroup,this.ii.slice(),this.filters.slice(),this.limit,this.ei,this.startAt,n)},t.prototype.pi=function(n){return new t(n,null,this.ii.slice(),this.filters.slice(),this.limit,this.ei,this.startAt,this.endAt)},t.prototype.gi=function(){return 0===this.filters.length&&null===this.limit&&null==this.startAt&&null==this.endAt&&(0===this.ii.length||1===this.ii.length&&this.ii[0].field.ft())},t.prototype.canonicalId=function(){return this.bi().canonicalId()+"|lt:"+this.ei},t.prototype.toString=function(){return"Query(target="+this.bi().toString()+"; limitType="+this.ei+")"},t.prototype.isEqual=function(t){return this.bi().isEqual(t.bi())&&this.ei===t.ei},t.prototype.yi=function(t,n){for(var i=!1,e=0,r=this.orderBy;e<r.length;e++){var u=r[e],s=u.compare(t,n);if(0!==s)return s;i=i||u.field.ft()}return S(i,"orderBy used that doesn't compare on key field"),0},t.prototype.matches=function(t){return this._i(t)&&this.Ii(t)&&this.Ti(t)&&this.Ei(t)},t.prototype.Ri=function(){return!Dn(this.limit)&&this.ei===Sn.ti},t.prototype.Ai=function(){return!Dn(this.limit)&&this.ei===Sn.ni},t.prototype.ci=function(){return this.ii.length>0?this.ii[0].field:null},t.prototype.hi=function(){for(var t=0,n=this.filters;t<n.length;t++){var i=n[t];if(i instanceof jn&&i.fi())return i.field}return null},t.prototype.Di=function(t){for(var n=0,i=this.filters;n<i.length;n++){var e=i[n];if(e instanceof jn&&t.indexOf(e.op)>=0)return e.op}return null},t.prototype.Zn=function(){return this.bi().Zn()},t.prototype.Pi=function(){return null!==this.collectionGroup},t.prototype.bi=function(){if(!this.ui)if(this.ei===Sn.ti)this.ui=new Vn(this.path,this.collectionGroup,this.orderBy,this.filters,this.limit,this.startAt,this.endAt);else{for(var t=[],n=0,i=this.orderBy;n<i.length;n++){var e=i[n],r=e.dir===Qn.DESCENDING?Qn.ASCENDING:Qn.DESCENDING;t.push(new Wn(e.field,r))}var u=this.endAt?new Gn(this.endAt.position,!this.endAt.before):null,s=this.startAt?new Gn(this.startAt.position,!this.startAt.before):null;this.ui=new Vn(this.path,this.collectionGroup,t,this.filters,this.limit,u,s)}return this.ui},t.prototype._i=function(t){var n=t.key.path;return null!==this.collectionGroup?t.key.wt(this.collectionGroup)&&this.path.rt(n):Pt.vt(this.path)?this.path.isEqual(n):this.path.ut(n)},t.prototype.Ii=function(t){for(var n=0,i=this.ii;n<i.length;n++){var e=i[n];if(!e.field.ft()&&null===t.field(e.field))return!1}return!0},t.prototype.Ti=function(t){for(var n=0,i=this.filters;n<i.length;n++){if(!i[n].matches(t))return!1}return!0},t.prototype.Ei=function(t){return!(this.startAt&&!this.startAt.Si(this.orderBy,t))&&(!this.endAt||!this.endAt.Si(this.orderBy,t))},t.prototype.si=function(t){S(t.position.length<=this.orderBy.length,"Bound is longer than orderBy")},t}(),Fn=function(){},xn=function(){function t(t){this.name=t}return t.ht=function(n){switch(n){case"<":return t.LESS_THAN;case"<=":return t.LESS_THAN_OR_EQUAL;case"==":return t.EQUAL;case">=":return t.GREATER_THAN_OR_EQUAL;case">":return t.GREATER_THAN;case"array-contains":return t.ARRAY_CONTAINS;case"in":return t.IN;case"array-contains-any":return t.ARRAY_CONTAINS_ANY;default:return P("Unknown FieldFilter operator: "+n)}},t.prototype.toString=function(){return this.name},t.prototype.isEqual=function(t){return this.name===t.name},t.LESS_THAN=new t("<"),t.LESS_THAN_OR_EQUAL=new t("<="),t.EQUAL=new t("=="),t.GREATER_THAN=new t(">"),t.GREATER_THAN_OR_EQUAL=new t(">="),t.ARRAY_CONTAINS=new t("array-contains"),t.IN=new t("in"),t.ARRAY_CONTAINS_ANY=new t("array-contains-any"),t}(),jn=function(t){function n(n,i,e){var r=t.call(this)||this;return r.field=n,r.op=i,r.value=e,r}return i(n,t),n.create=function(t,i,e){if(t.ft())return i===xn.IN?(S(e instanceof gn,"Comparing on key with IN, but filter value not an ArrayValue"),S(e.nn.every((function(t){return t instanceof wn})),"Comparing on key with IN, but an array value was not a RefValue"),new Ln(t,e)):(S(e instanceof wn,"Comparing on key, but filter value not a RefValue"),S(i!==xn.ARRAY_CONTAINS&&i!==xn.ARRAY_CONTAINS_ANY,"'"+i.toString()+"' queries don't make sense on document keys."),new Un(t,i,e));if(e.isEqual(un.Bn)){if(i!==xn.EQUAL)throw new Q(q.INVALID_ARGUMENT,"Invalid query. Null supports only equality comparisons.");return new n(t,i,e)}if(e.isEqual(an.Qn)){if(i!==xn.EQUAL)throw new Q(q.INVALID_ARGUMENT,"Invalid query. NaN supports only equality comparisons.");return new n(t,i,e)}return i===xn.ARRAY_CONTAINS?new Bn(t,e):i===xn.IN?(S(e instanceof gn,"IN filter has invalid value: "+e.toString()),new Mn(t,e)):i===xn.ARRAY_CONTAINS_ANY?(S(e instanceof gn,"ARRAY_CONTAINS_ANY filter has invalid value: "+e.toString()),new qn(t,e)):new n(t,i,e)},n.prototype.matches=function(t){var n=t.field(this.field);return null!==n&&this.value.Un===n.Un&&this.Ci(n.h(this.value))},n.prototype.Ci=function(t){switch(this.op){case xn.LESS_THAN:return t<0;case xn.LESS_THAN_OR_EQUAL:return t<=0;case xn.EQUAL:return 0===t;case xn.GREATER_THAN:return t>0;case xn.GREATER_THAN_OR_EQUAL:return t>=0;default:return P("Unknown FieldFilter operator: "+this.op)}},n.prototype.fi=function(){return[xn.LESS_THAN,xn.LESS_THAN_OR_EQUAL,xn.GREATER_THAN,xn.GREATER_THAN_OR_EQUAL].indexOf(this.op)>=0},n.prototype.canonicalId=function(){return this.field.ot()+this.op.toString()+this.value.toString()},n.prototype.isEqual=function(t){return t instanceof n&&(this.op.isEqual(t.op)&&this.field.isEqual(t.field)&&this.value.isEqual(t.value))},n.prototype.toString=function(){return this.field.ot()+" "+this.op+" "+this.value.value()},n}(Fn),Un=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return i(n,t),n.prototype.matches=function(t){var n=this.value,i=Pt.X(t.key,n.key);return this.Ci(i)},n}(jn),Ln=function(t){function n(n,i){var e=t.call(this,n,xn.IN,i)||this;return e.value=i,e}return i(n,t),n.prototype.matches=function(t){return this.value.nn.some((function(n){return t.key.isEqual(n.key)}))},n}(jn),Bn=function(t){function n(n,i){return t.call(this,n,xn.ARRAY_CONTAINS,i)||this}return i(n,t),n.prototype.matches=function(t){var n=t.field(this.field);return n instanceof gn&&n.contains(this.value)},n}(jn),Mn=function(t){function n(n,i){var e=t.call(this,n,xn.IN,i)||this;return e.value=i,e}return i(n,t),n.prototype.matches=function(t){var n=this.value,i=t.field(this.field);return null!==i&&n.contains(i)},n}(jn),qn=function(t){function n(n,i){var e=t.call(this,n,xn.ARRAY_CONTAINS_ANY,i)||this;return e.value=i,e}return i(n,t),n.prototype.matches=function(t){var n=this,i=t.field(this.field);return i instanceof gn&&i.nn.some((function(t){return n.value.contains(t)}))},n}(jn),Qn=function(){function t(t){this.name=t}return t.prototype.toString=function(){return this.name},t.ASCENDING=new t("asc"),t.DESCENDING=new t("desc"),t}(),Gn=function(){function t(t,n){this.position=t,this.before=n}return t.prototype.canonicalId=function(){for(var t=this.before?"b:":"a:",n=0,i=this.position;n<i.length;n++){t+=i[n].toString()}return t},t.prototype.Si=function(t,n){S(this.position.length<=t.length,"Bound has more components than query's orderBy");for(var i=0,e=0;e<this.position.length;e++){var r=t[e],u=this.position[e];if(r.field.ft())S(u instanceof wn,"Bound has a non-key value where the key path is being used."),i=Pt.X(u.key,n.key);else{var s=n.field(r.field);S(null!==s,"Field should exist since document matched the orderBy already."),i=u.h(s)}if(r.dir===Qn.DESCENDING&&(i*=-1),0!==i)break}return this.before?i<=0:i<0},t.prototype.isEqual=function(t){if(null===t)return!1;if(this.before!==t.before||this.position.length!==t.position.length)return!1;for(var n=0;n<this.position.length;n++){var i=this.position[n],e=t.position[n];if(!i.isEqual(e))return!1}return!0},t}(),Wn=function(){function t(t,n){this.field=t,void 0===n&&(n=Qn.ASCENDING),this.dir=n,this.Vi=t.ft()}return t.prototype.compare=function(t,n){var i=this.Vi?yn.Kn(t,n):yn.Xn(this.field,t,n);switch(this.dir){case Qn.ASCENDING:return i;case Qn.DESCENDING:return-1*i;default:return P("Unknown direction: "+this.dir)}},t.prototype.canonicalId=function(){return this.field.ot()+this.dir.toString()},t.prototype.toString=function(){return this.field.ot()+" ("+this.dir+")"},t.prototype.isEqual=function(t){return this.dir===t.dir&&this.field.isEqual(t.field)},t}(),zn=new Wn(Dt.lt(),Qn.ASCENDING),Kn=new Wn(Dt.lt(),Qn.DESCENDING);(Nn=kn||(kn={}))[Nn.ki=0]="__PRIVATE_Listen",Nn[Nn.Ni=1]="__PRIVATE_ExistenceFilterMismatch",Nn[Nn.Oi=2]="__PRIVATE_LimboResolution";var Hn,Jn,Yn=function(){function t(t,n,i,e,r,u,s){void 0===r&&(r=Tt.MIN),void 0===u&&(u=Tt.MIN),void 0===s&&(s=Li()),this.target=t,this.targetId=n,this.Fi=i,this.sequenceNumber=e,this.xi=r,this.lastLimboFreeSnapshotVersion=u,this.resumeToken=s}return t.prototype.ji=function(n){return new t(this.target,this.targetId,this.Fi,n,this.xi,this.lastLimboFreeSnapshotVersion,this.resumeToken)},t.prototype.Ui=function(n,i){return new t(this.target,this.targetId,this.Fi,this.sequenceNumber,i,this.lastLimboFreeSnapshotVersion,n)},t.prototype.Li=function(n){return new t(this.target,this.targetId,this.Fi,this.sequenceNumber,this.xi,n,this.resumeToken)},t.prototype.isEqual=function(t){return this.targetId===t.targetId&&this.Fi===t.Fi&&this.sequenceNumber===t.sequenceNumber&&this.xi.isEqual(t.xi)&&this.lastLimboFreeSnapshotVersion.isEqual(t.lastLimboFreeSnapshotVersion)&&this.resumeToken===t.resumeToken&&this.target.isEqual(t.target)},t}(),Xn=function(){function t(t){this.count=t}return t.prototype.isEqual=function(t){return t&&t.count===this.count},t}();function $n(t){switch(t){case q.OK:return P("Treated status OK as error");case q.CANCELLED:case q.UNKNOWN:case q.DEADLINE_EXCEEDED:case q.RESOURCE_EXHAUSTED:case q.INTERNAL:case q.UNAVAILABLE:case q.UNAUTHENTICATED:return!1;case q.INVALID_ARGUMENT:case q.NOT_FOUND:case q.ALREADY_EXISTS:case q.PERMISSION_DENIED:case q.FAILED_PRECONDITION:case q.ABORTED:case q.OUT_OF_RANGE:case q.UNIMPLEMENTED:case q.DATA_LOSS:return!0;default:return P("Unknown status code: "+t)}}function Zn(t){if(void 0===t)return A("GRPC error has no .code"),q.UNKNOWN;switch(t){case Hn.OK:return q.OK;case Hn.CANCELLED:return q.CANCELLED;case Hn.UNKNOWN:return q.UNKNOWN;case Hn.DEADLINE_EXCEEDED:return q.DEADLINE_EXCEEDED;case Hn.RESOURCE_EXHAUSTED:return q.RESOURCE_EXHAUSTED;case Hn.INTERNAL:return q.INTERNAL;case Hn.UNAVAILABLE:return q.UNAVAILABLE;case Hn.UNAUTHENTICATED:return q.UNAUTHENTICATED;case Hn.INVALID_ARGUMENT:return q.INVALID_ARGUMENT;case Hn.NOT_FOUND:return q.NOT_FOUND;case Hn.ALREADY_EXISTS:return q.ALREADY_EXISTS;case Hn.PERMISSION_DENIED:return q.PERMISSION_DENIED;case Hn.FAILED_PRECONDITION:return q.FAILED_PRECONDITION;case Hn.ABORTED:return q.ABORTED;case Hn.OUT_OF_RANGE:return q.OUT_OF_RANGE;case Hn.UNIMPLEMENTED:return q.UNIMPLEMENTED;case Hn.DATA_LOSS:return q.DATA_LOSS;default:return P("Unknown status code: "+t)}}function ti(t){if(void 0===t)return Hn.OK;switch(t){case q.OK:return Hn.OK;case q.CANCELLED:return Hn.CANCELLED;case q.UNKNOWN:return Hn.UNKNOWN;case q.DEADLINE_EXCEEDED:return Hn.DEADLINE_EXCEEDED;case q.RESOURCE_EXHAUSTED:return Hn.RESOURCE_EXHAUSTED;case q.INTERNAL:return Hn.INTERNAL;case q.UNAVAILABLE:return Hn.UNAVAILABLE;case q.UNAUTHENTICATED:return Hn.UNAUTHENTICATED;case q.INVALID_ARGUMENT:return Hn.INVALID_ARGUMENT;case q.NOT_FOUND:return Hn.NOT_FOUND;case q.ALREADY_EXISTS:return Hn.ALREADY_EXISTS;case q.PERMISSION_DENIED:return Hn.PERMISSION_DENIED;case q.FAILED_PRECONDITION:return Hn.FAILED_PRECONDITION;case q.ABORTED:return Hn.ABORTED;case q.OUT_OF_RANGE:return Hn.OUT_OF_RANGE;case q.UNIMPLEMENTED:return Hn.UNIMPLEMENTED;case q.DATA_LOSS:return Hn.DATA_LOSS;default:return P("Unknown status code: "+t)}}(Jn=Hn||(Hn={}))[Jn.OK=0]="OK",Jn[Jn.CANCELLED=1]="CANCELLED",Jn[Jn.UNKNOWN=2]="UNKNOWN",Jn[Jn.INVALID_ARGUMENT=3]="INVALID_ARGUMENT",Jn[Jn.DEADLINE_EXCEEDED=4]="DEADLINE_EXCEEDED",Jn[Jn.NOT_FOUND=5]="NOT_FOUND",Jn[Jn.ALREADY_EXISTS=6]="ALREADY_EXISTS",Jn[Jn.PERMISSION_DENIED=7]="PERMISSION_DENIED",Jn[Jn.UNAUTHENTICATED=16]="UNAUTHENTICATED",Jn[Jn.RESOURCE_EXHAUSTED=8]="RESOURCE_EXHAUSTED",Jn[Jn.FAILED_PRECONDITION=9]="FAILED_PRECONDITION",Jn[Jn.ABORTED=10]="ABORTED",Jn[Jn.OUT_OF_RANGE=11]="OUT_OF_RANGE",Jn[Jn.UNIMPLEMENTED=12]="UNIMPLEMENTED",Jn[Jn.INTERNAL=13]="INTERNAL",Jn[Jn.UNAVAILABLE=14]="UNAVAILABLE",Jn[Jn.DATA_LOSS=15]="DATA_LOSS";var ni=new St(Pt.X);function ii(){return ni}function ei(){return ii()}var ri=new St(Pt.X);function ui(){return ri}var si=new St(Pt.X);function oi(){return si}var hi=new Nt(Pt.X);function ci(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];for(var i=hi,e=0,r=t;e<r.length;e++){var u=r[e];i=i.add(u)}return i}var ai=new Nt(V);function fi(){return ai}var li,di,vi,wi,mi=function(){function t(t){this.X=t?function(n,i){return t(n,i)||Pt.X(n.key,i.key)}:function(t,n){return Pt.X(t.key,n.key)},this.Bi=ui(),this.Mi=new St(this.X)}return t.qi=function(n){return new t(n.X)},t.prototype.has=function(t){return null!=this.Bi.get(t)},t.prototype.get=function(t){return this.Bi.get(t)},t.prototype.first=function(){return this.Mi.It()},t.prototype.last=function(){return this.Mi.Tt()},t.prototype.nt=function(){return this.Mi.nt()},t.prototype.indexOf=function(t){var n=this.Bi.get(t);return n?this.Mi.indexOf(n):-1},Object.defineProperty(t.prototype,"size",{get:function(){return this.Mi.size},enumerable:!0,configurable:!0}),t.prototype.forEach=function(t){this.Mi.Et((function(n,i){return t(n),!1}))},t.prototype.add=function(t){var n=this.delete(t.key);return n.yt(n.Bi.bt(t.key,t),n.Mi.bt(t,null))},t.prototype.delete=function(t){var n=this.get(t);return n?this.yt(this.Bi.remove(t),this.Mi.remove(n)):this},t.prototype.isEqual=function(n){if(!(n instanceof t))return!1;if(this.size!==n.size)return!1;for(var i=this.Mi.At(),e=n.Mi.At();i.Nt();){var r=i.kt().key,u=e.kt().key;if(!r.isEqual(u))return!1}return!0},t.prototype.toString=function(){var t=[];return this.forEach((function(n){t.push(n.toString())})),0===t.length?"DocumentSet ()":"DocumentSet (\n "+t.join(" \n")+"\n)"},t.prototype.yt=function(n,i){var e=new t;return e.X=this.X,e.Bi=n,e.Mi=i,e},t}();(di=li||(li={}))[di.Qi=0]="__PRIVATE_Added",di[di.Gi=1]="__PRIVATE_Removed",di[di.Wi=2]="__PRIVATE_Modified",di[di.zi=3]="__PRIVATE_Metadata",(wi=vi||(vi={}))[wi.Ki=0]="__PRIVATE_Local",wi[wi.Hi=1]="__PRIVATE_Synced";var pi,gi,bi=function(){function t(){this.Ji=new St(Pt.X)}return t.prototype.track=function(t){var n=t.doc.key,i=this.Ji.get(n);i?t.type!==li.Qi&&i.type===li.zi?this.Ji=this.Ji.bt(n,t):t.type===li.zi&&i.type!==li.Gi?this.Ji=this.Ji.bt(n,{type:i.type,doc:t.doc}):t.type===li.Wi&&i.type===li.Wi?this.Ji=this.Ji.bt(n,{type:li.Wi,doc:t.doc}):t.type===li.Wi&&i.type===li.Qi?this.Ji=this.Ji.bt(n,{type:li.Qi,doc:t.doc}):t.type===li.Gi&&i.type===li.Qi?this.Ji=this.Ji.remove(n):t.type===li.Gi&&i.type===li.Wi?this.Ji=this.Ji.bt(n,{type:li.Gi,doc:i.doc}):t.type===li.Qi&&i.type===li.Gi?this.Ji=this.Ji.bt(n,{type:li.Wi,doc:t.doc}):P("unsupported combination of changes: "+JSON.stringify(t)+" after "+JSON.stringify(i)):this.Ji=this.Ji.bt(n,t)},t.prototype.Yi=function(){var t=[];return this.Ji.Et((function(n,i){t.push(i)})),t},t}(),yi=function(){function t(t,n,i,e,r,u,s,o){this.query=t,this.docs=n,this.Xi=i,this.docChanges=e,this.$i=r,this.fromCache=u,this.Zi=s,this.te=o}return t.ne=function(n,i,e,r){var u=[];return i.forEach((function(t){u.push({type:li.Qi,doc:t})})),new t(n,i,mi.qi(i),u,e,r,!0,!1)},Object.defineProperty(t.prototype,"hasPendingWrites",{get:function(){return!this.$i.nt()},enumerable:!0,configurable:!0}),t.prototype.isEqual=function(t){if(!(this.fromCache===t.fromCache&&this.Zi===t.Zi&&this.$i.isEqual(t.$i)&&this.query.isEqual(t.query)&&this.docs.isEqual(t.docs)&&this.Xi.isEqual(t.Xi)))return!1;var n=this.docChanges,i=t.docChanges;if(n.length!==i.length)return!1;for(var e=0;e<n.length;e++)if(n[e].type!==i[e].type||!n[e].doc.isEqual(i[e].doc))return!1;return!0},t}(),_i=function(){function t(t,n,i,e,r){this.xi=t,this.ie=n,this.ee=i,this.re=e,this.ue=r}return t.se=function(n,i){var e,r=((e={})[n]=Ii.oe(n,i),e);return new t(Tt.MIN,r,fi(),ii(),ci())},t}(),Ii=function(){function t(t,n,i,e,r){this.resumeToken=t,this.he=n,this.ce=i,this.ae=e,this.fe=r}return t.oe=function(n,i){return new t(Li(),i,ci(),ci(),ci())},t}(),Ti=function(t,n,i,e){this.le=t,this.removedTargetIds=n,this.key=i,this.de=e},Ei=function(t,n){this.targetId=t,this.ve=n};(gi=pi||(pi={}))[gi.we=0]="__PRIVATE_NoChange",gi[gi.Qi=1]="__PRIVATE_Added",gi[gi.Gi=2]="__PRIVATE_Removed",gi[gi.me=3]="__PRIVATE_Current",gi[gi.pe=4]="__PRIVATE_Reset";var Ri=function(t,n,i,e){void 0===i&&(i=Li()),void 0===e&&(e=null),this.state=t,this.targetIds=n,this.resumeToken=i,this.cause=e},Ai=function(){function t(){this.ge=0,this.be=Si(),this.ye=Li(),this._e=!1,this.Ie=!0}return Object.defineProperty(t.prototype,"he",{get:function(){return this._e},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"resumeToken",{get:function(){return this.ye},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"Te",{get:function(){return 0!==this.ge},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"Ee",{get:function(){return this.Ie},enumerable:!0,configurable:!0}),t.prototype.Re=function(t){t.length>0&&(this.Ie=!0,this.ye=t)},t.prototype.Ae=function(){var t=ci(),n=ci(),i=ci();return this.be.forEach((function(e,r){switch(r){case li.Qi:t=t.add(e);break;case li.Wi:n=n.add(e);break;case li.Gi:i=i.add(e);break;default:P("Encountered invalid change type: "+r)}})),new Ii(this.ye,this._e,t,n,i)},t.prototype.De=function(){this.Ie=!1,this.be=Si()},t.prototype.Pe=function(t,n){this.Ie=!0,this.be=this.be.bt(t,n)},t.prototype.Se=function(t){this.Ie=!0,this.be=this.be.remove(t)},t.prototype.Ce=function(){this.ge+=1},t.prototype.Ve=function(){this.ge-=1},t.prototype.ke=function(){this.Ie=!0,this._e=!0},t}(),Di=function(){function t(t){this.Ne=t,this.Oe={},this.Fe=ii(),this.xe=Pi(),this.je=new Nt(V)}return t.prototype.Ue=function(t){for(var n=0,i=t.le;n<i.length;n++){var e=i[n];t.de instanceof yn?this.Le(e,t.de):t.de instanceof _n&&this.Be(e,t.key,t.de)}for(var r=0,u=t.removedTargetIds;r<u.length;r++){e=u[r];this.Be(e,t.key,t.de)}},t.prototype.Me=function(t){var n=this;this.qe(t,(function(i){var e=n.Qe(i);switch(t.state){case pi.we:n.Ge(i)&&e.Re(t.resumeToken);break;case pi.Qi:e.Ve(),e.Te||e.De(),e.Re(t.resumeToken);break;case pi.Gi:e.Ve(),e.Te||n.removeTarget(i),S(!t.cause,"WatchChangeAggregator does not handle errored targets");break;case pi.me:n.Ge(i)&&(e.ke(),e.Re(t.resumeToken));break;case pi.pe:n.Ge(i)&&(n.We(i),e.Re(t.resumeToken));break;default:P("Unknown target watch change state: "+t.state)}}))},t.prototype.qe=function(t,n){t.targetIds.length>0?t.targetIds.forEach(n):$(this.Oe,n)},t.prototype.ze=function(t){var n=t.targetId,i=t.ve.count,e=this.Ke(n);if(e){var r=e.target;if(r.Zn())if(0===i){var u=new Pt(r.path);this.Be(n,u,new _n(u,Tt.K()))}else S(1===i,"Single document existence filter with count: "+i);else this.He(n)!==i&&(this.We(n),this.je=this.je.add(n))}},t.prototype.Je=function(t){var n=this,i={};$(this.Oe,(function(e,r){var u=n.Ke(e);if(u){if(r.he&&u.target.Zn()){var s=new Pt(u.target.path);null!==n.Fe.get(s)||n.Ye(e,s)||n.Be(e,s,new _n(s,t))}r.Ee&&(i[e]=r.Ae(),r.De())}}));var e=ci();this.xe.forEach((function(t,i){var r=!0;i.Kt((function(t){var i=n.Ke(t);return!i||i.Fi===kn.Oi||(r=!1,!1)})),r&&(e=e.add(t))}));var r=new _i(t,i,this.je,this.Fe,e);return this.Fe=ii(),this.xe=Pi(),this.je=new Nt(V),r},t.prototype.Le=function(t,n){if(this.Ge(t)){var i=this.Ye(t,n.key)?li.Wi:li.Qi;this.Qe(t).Pe(n.key,i),this.Fe=this.Fe.bt(n.key,n),this.xe=this.xe.bt(n.key,this.Xe(n.key).add(t))}},t.prototype.Be=function(t,n,i){if(this.Ge(t)){var e=this.Qe(t);this.Ye(t,n)?e.Pe(n,li.Gi):e.Se(n),this.xe=this.xe.bt(n,this.Xe(n).delete(t)),i&&(this.Fe=this.Fe.bt(n,i))}},t.prototype.removeTarget=function(t){delete this.Oe[t]},t.prototype.He=function(t){var n=this.Qe(t).Ae();return this.Ne.$e(t).size+n.ce.size-n.fe.size},t.prototype.Ce=function(t){this.Qe(t).Ce()},t.prototype.Qe=function(t){return this.Oe[t]||(this.Oe[t]=new Ai),this.Oe[t]},t.prototype.Xe=function(t){var n=this.xe.get(t);return n||(n=new Nt(V),this.xe=this.xe.bt(t,n)),n},t.prototype.Ge=function(t){var n=null!==this.Ke(t);return n||R("WatchChangeAggregator","Detected inactive target",t),n},t.prototype.Ke=function(t){var n=this.Oe[t];return n&&n.Te?null:this.Ne.Ze(t)},t.prototype.We=function(t){var n=this;S(!this.Oe[t].Te,"Should only reset active targets"),this.Oe[t]=new Ai,this.Ne.$e(t).forEach((function(i){n.Be(t,i,null)}))},t.prototype.Ye=function(t,n){return this.Ne.$e(t).has(n)},t}();function Pi(){return new St(Pt.X)}function Si(){return new St(Pt.X)}var Ci,Vi,ki=((Ci={})[Qn.ASCENDING.name]="ASCENDING",Ci[Qn.DESCENDING.name]="DESCENDING",Ci),Ni=((Vi={})[xn.LESS_THAN.name]="LESS_THAN",Vi[xn.LESS_THAN_OR_EQUAL.name]="LESS_THAN_OR_EQUAL",Vi[xn.GREATER_THAN.name]="GREATER_THAN",Vi[xn.GREATER_THAN_OR_EQUAL.name]="GREATER_THAN_OR_EQUAL",Vi[xn.EQUAL.name]="EQUAL",Vi[xn.ARRAY_CONTAINS.name]="ARRAY_CONTAINS",Vi[xn.IN.name]="IN",Vi[xn.ARRAY_CONTAINS_ANY.name]="ARRAY_CONTAINS_ANY",Vi),Oi=new RegExp(/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.(\d+))?Z$/);function Fi(t,n){S(!Dn(t),n+" is missing")}function xi(t){return"number"==typeof t?t:"string"==typeof t?Number(t):P("can't parse "+t)}var ji=function(){function t(t,n){this.s=t,this.options=n}return t.prototype.tr=function(){return this.options.nr?"":new Uint8Array(0)},t.prototype.ir=function(t){return t},t.prototype.er=function(t){var n=void 0===t.code?q.UNKNOWN:Zn(t.code);return new Q(n,t.message||"")},t.prototype.rr=function(t){return this.options.nr||Dn(t)?t:{value:t}},t.prototype.ur=function(t){var n;return Dn(n="object"==typeof t?t.value:t)?null:n},t.prototype.J=function(t){return this.options.nr?new Date(1e3*t.seconds).toISOString().replace(/\.\d*/,"").replace("Z","")+"."+("000000000"+t.nanoseconds).slice(-9)+"Z":{seconds:""+t.seconds,nanos:t.nanoseconds}},t.prototype.W=function(t){if("string"==typeof t)return this.sr(t);S(!!t,"Cannot deserialize null or undefined timestamp.");var n=xi(t.seconds||"0"),i=t.nanos||0;return new It(n,i)},t.prototype.sr=function(t){var n=0,i=Oi.exec(t);if(S(!!i,"invalid timestamp: "+t),i[1]){var e=i[1];e=(e+"000000000").substr(0,9),n=Number(e)}var r=new Date(t),u=Math.floor(r.getTime()/1e3);return new It(u,n)},t.prototype.or=function(t){return this.options.nr?t.toBase64():this.ir(t.toUint8Array())},t.prototype.hr=function(t){return"string"==typeof t?(S(this.options.nr,"Expected bytes to be passed in as Uint8Array, but got a string instead."),Wi.fromBase64String(t)):(S(!this.options.nr,"Expected bytes to be passed in as Uint8Array, but got a string instead."),Wi.fromUint8Array(t))},t.prototype.toVersion=function(t){return this.J(t.J())},t.prototype.fromVersion=function(t){return S(!!t,"Trying to deserialize version that isn't set"),Tt.W(this.W(t))},t.prototype.cr=function(t,n){return this.ar(t).child("documents").child(n).ot()},t.prototype.lr=function(t){var n=Rt.ht(t);return S(this.dr(n),"Tried to deserialize invalid key "+n.toString()),n},t.prototype.vr=function(t){return this.cr(this.s,t.path)},t.prototype.wr=function(t){var n=this.lr(t);return S(n.get(1)===this.s.projectId,"Tried to deserialize key from different project: "+n.get(1)+" vs "+this.s.projectId),S(!n.get(3)&&!this.s.database||n.get(3)===this.s.database,"Tried to deserialize key from different database: "+n.get(3)+" vs "+this.s.database),new Pt(this.mr(n))},t.prototype.pr=function(t){return this.cr(this.s,t)},t.prototype.gr=function(t){var n=this.lr(t);return 4===n.length?Rt.ct:this.mr(n)},Object.defineProperty(t.prototype,"br",{get:function(){return new Rt(["projects",this.s.projectId,"databases",this.s.database]).ot()},enumerable:!0,configurable:!0}),t.prototype.ar=function(t){return new Rt(["projects",t.projectId,"databases",t.database])},t.prototype.mr=function(t){return S(t.length>4&&"documents"===t.get(4),"tried to deserialize invalid key "+t.toString()),t.Z(5)},t.prototype.dr=function(t){return t.length>=4&&"projects"===t.get(0)&&"databases"===t.get(2)},t.prototype.yr=function(t){if(t instanceof un)return{nullValue:"NULL_VALUE"};if(t instanceof sn)return{booleanValue:t.value()};if(t instanceof cn)return{integerValue:""+t.value()};if(t instanceof an){var n=t.value();if(this.options.nr){if(isNaN(n))return{doubleValue:"NaN"};if(n===1/0)return{doubleValue:"Infinity"};if(n===-1/0)return{doubleValue:"-Infinity"}}return{doubleValue:t.value()}}return t instanceof fn?{stringValue:t.value()}:t instanceof pn?{mapValue:this._r(t)}:t instanceof gn?{arrayValue:this.Ir(t)}:t instanceof ln?{timestampValue:this.J(t.nn)}:t instanceof mn?{geoPointValue:{latitude:t.value().latitude,longitude:t.value().longitude}}:t instanceof vn?{bytesValue:this.or(t.value())}:t instanceof wn?{referenceValue:this.cr(t.s,t.key.path)}:P("Unknown FieldValue "+JSON.stringify(t))},t.prototype.Tr=function(t){var n=this;if("nullValue"in t)return un.Bn;if("booleanValue"in t)return sn.of(t.booleanValue);if("integerValue"in t)return new cn(xi(t.integerValue));if("doubleValue"in t){if(this.options.nr){if("NaN"===t.doubleValue)return an.Qn;if("Infinity"===t.doubleValue)return an.POSITIVE_INFINITY;if("-Infinity"===t.doubleValue)return an.NEGATIVE_INFINITY}return new an(t.doubleValue)}if("stringValue"in t)return new fn(t.stringValue);if("mapValue"in t)return this.Er(t.mapValue.fields||{});if("arrayValue"in t){Fi(t.arrayValue,"arrayValue");var i=t.arrayValue.values||[];return new gn(i.map((function(t){return n.Tr(t)})))}if("timestampValue"in t)return Fi(t.timestampValue,"timestampValue"),new ln(this.W(t.timestampValue));if("geoPointValue"in t){Fi(t.geoPointValue,"geoPointValue");var e=t.geoPointValue.latitude||0,r=t.geoPointValue.longitude||0;return new mn(new _t(e,r))}if("bytesValue"in t){Fi(t.bytesValue,"bytesValue");var u=this.hr(t.bytesValue);return new vn(u)}if("referenceValue"in t){Fi(t.referenceValue,"referenceValue");var s=this.lr(t.referenceValue),o=new B(s.get(1),s.get(3)),h=new Pt(this.mr(s));return new wn(o,h)}return P("Unknown Value proto "+JSON.stringify(t))},t.prototype.Rr=function(t,n){return{name:this.vr(t),fields:this.Ar(n)}},t.prototype.Dr=function(t){return S(!t.vn,"Can't serialize documents with mutations."),{name:this.vr(t.key),fields:this.Ar(t.data()),updateTime:this.J(t.version.J())}},t.prototype.Pr=function(t,n){var i=this,e=this.wr(t.name),r=this.fromVersion(t.updateTime);return new yn(e,r,{hasCommittedMutations:!!n},void 0,t,(function(t){return i.Tr(t)}))},t.prototype.Ar=function(t){var n=this,i={};return t.forEach((function(t,e){i[t]=n.yr(e)})),i},t.prototype.Er=function(t){var n=this,i=t,e=pn.EMPTY;return Z(i,(function(t,i){e=e.set(new Dt([t]),n.Tr(i))})),e},t.prototype._r=function(t){return{fields:this.Ar(t)}},t.prototype.Ir=function(t){var n=this,i=[];return t.forEach((function(t){i.push(n.yr(t))})),{values:i}},t.prototype.Sr=function(t){var n=this;S(!!t.found,"Tried to deserialize a found document from a missing document."),Fi(t.found.name,"doc.found.name"),Fi(t.found.updateTime,"doc.found.updateTime");var i=this.wr(t.found.name),e=this.fromVersion(t.found.updateTime);return new yn(i,e,{},void 0,t.found,(function(t){return n.Tr(t)}))},t.prototype.Cr=function(t){S(!!t.missing,"Tried to deserialize a missing document from a found document."),S(!!t.readTime,"Tried to deserialize a missing document without a read time.");var n=this.wr(t.missing),i=this.fromVersion(t.readTime);return new _n(n,i)},t.prototype.Vr=function(t){return"found"in t?this.Sr(t):"missing"in t?this.Cr(t):P("invalid batch get response: "+JSON.stringify(t))},t.prototype.kr=function(t){switch(t){case pi.Qi:return"ADD";case pi.me:return"CURRENT";case pi.we:return"NO_CHANGE";case pi.Gi:return"REMOVE";case pi.pe:return"RESET";default:return P("Unknown WatchTargetChangeState: "+t)}},t.prototype.Nr=function(t){if(t instanceof Ei)return{filter:{count:t.ve.count,targetId:t.targetId}};if(t instanceof Ti){if(t.de instanceof yn){var n=t.de;return{documentChange:{document:{name:this.vr(n.key),fields:this.Ar(n.data()),updateTime:this.toVersion(n.version)},targetIds:t.le,removedTargetIds:t.removedTargetIds}}}if(t.de instanceof _n){n=t.de;return{documentDelete:{document:this.vr(n.key),readTime:this.toVersion(n.version),removedTargetIds:t.removedTargetIds}}}if(null===t.de)return{documentRemove:{document:this.vr(t.key),removedTargetIds:t.removedTargetIds}}}if(t instanceof Ri){var i=void 0;return t.cause&&(i={code:ti(t.cause.code),message:t.cause.message}),{targetChange:{targetChangeType:this.kr(t.state),targetIds:t.targetIds,resumeToken:this.ir(t.resumeToken),cause:i}}}return P("Unrecognized watch change: "+JSON.stringify(t))},t.prototype.Or=function(t){var n,i=this;if("targetChange"in t){Fi(t.targetChange,"targetChange");var e=this.Fr(t.targetChange.targetChangeType||"NO_CHANGE"),r=t.targetChange.targetIds||[],u=t.targetChange.resumeToken||this.tr(),s=t.targetChange.cause,o=s&&this.er(s);n=new Ri(e,r,u,o||null)}else if("documentChange"in t){Fi(t.documentChange,"documentChange");var h=t.documentChange;Fi(h.document,"documentChange.name"),Fi(h.document.name,"documentChange.document.name"),Fi(h.document.updateTime,"documentChange.document.updateTime");var c=this.wr(h.document.name),a=this.fromVersion(h.document.updateTime),f=new yn(c,a,{},void 0,h.document,(function(t){return i.Tr(t)})),l=h.targetIds||[],d=h.removedTargetIds||[];n=new Ti(l,d,f.key,f)}else if("documentDelete"in t){Fi(t.documentDelete,"documentDelete");var v=t.documentDelete;Fi(v.document,"documentDelete.document");c=this.wr(v.document),a=v.readTime?this.fromVersion(v.readTime):Tt.K(),f=new _n(c,a),d=v.removedTargetIds||[];n=new Ti([],d,f.key,f)}else if("documentRemove"in t){Fi(t.documentRemove,"documentRemove");var w=t.documentRemove;Fi(w.document,"documentRemove");c=this.wr(w.document),d=w.removedTargetIds||[];n=new Ti([],d,c,null)}else{if(!("filter"in t))return P("Unknown change type "+JSON.stringify(t));Fi(t.filter,"filter");var m=t.filter;Fi(m.targetId,"filter.targetId");var p=m.count||0,g=new Xn(p),b=m.targetId;n=new Ei(b,g)}return n},t.prototype.Fr=function(t){return"NO_CHANGE"===t?pi.we:"ADD"===t?pi.Qi:"REMOVE"===t?pi.Gi:"CURRENT"===t?pi.me:"RESET"===t?pi.pe:P("Got unexpected TargetChange.state: "+t)},t.prototype.xr=function(t){if(!("targetChange"in t))return Tt.MIN;var n=t.targetChange;return n.targetIds&&n.targetIds.length?Tt.MIN:n.readTime?this.fromVersion(n.readTime):Tt.MIN},t.prototype.jr=function(t){var n,i=this;if(t instanceof Xt)n={update:this.Rr(t.key,t.value)};else if(t instanceof tn)n={delete:this.vr(t.key)};else if(t instanceof $t)n={update:this.Rr(t.key,t.data),updateMask:this.Ur(t.mn)};else if(t instanceof Zt)n={transform:{document:this.vr(t.key),fieldTransforms:t.fieldTransforms.map((function(t){return i.Lr(t)}))}};else{if(!(t instanceof nn))return P("Unknown mutation type "+t.type);n={verify:this.vr(t.key)}}return t.dn.cn||(n.currentDocument=this.Br(t.dn)),n},t.prototype.Mr=function(t){var n=this,i=t.currentDocument?this.qr(t.currentDocument):Jt.NONE;if(t.update){Fi(t.update.name,"name");var e=this.wr(t.update.name),r=this.Er(t.update.fields||{});if(t.updateMask){var u=this.Qr(t.updateMask);return new $t(e,r,u,i)}return new Xt(e,r,i)}if(t.delete){e=this.wr(t.delete);return new tn(e,i)}if(t.transform){e=this.wr(t.transform.document);var s=t.transform.fieldTransforms.map((function(t){return n.Gr(t)}));return S(!0===i.exists,'Transforms only support precondition "exists == true"'),new Zt(e,s)}if(t.verify){e=this.wr(t.verify);return new nn(e,i)}return P("unknown mutation proto: "+JSON.stringify(t))},t.prototype.Br=function(t){return S(!t.cn,"Can't serialize an empty precondition"),void 0!==t.updateTime?{updateTime:this.toVersion(t.updateTime)}:void 0!==t.exists?{exists:t.exists}:P("Unknown precondition")},t.prototype.qr=function(t){return void 0!==t.updateTime?Jt.updateTime(this.fromVersion(t.updateTime)):void 0!==t.exists?Jt.exists(t.exists):Jt.NONE},t.prototype.Wr=function(t,n){var i=this,e=t.updateTime?this.fromVersion(t.updateTime):this.fromVersion(n);e.isEqual(Tt.MIN)&&(e=this.fromVersion(n));var r=null;return t.transformResults&&t.transformResults.length>0&&(r=t.transformResults.map((function(t){return i.Tr(t)}))),new Gt(e,r)},t.prototype.zr=function(t,n){var i=this;return t&&t.length>0?(S(void 0!==n,"Received a write result without a commit time"),t.map((function(t){return i.Wr(t,n)}))):[]},t.prototype.Lr=function(t){var n=this,i=t.transform;if(i instanceof Ft)return{fieldPath:t.field.ot(),setToServerValue:"REQUEST_TIME"};if(i instanceof xt)return{fieldPath:t.field.ot(),appendMissingElements:{values:i.elements.map((function(t){return n.yr(t)}))}};if(i instanceof jt)return{fieldPath:t.field.ot(),removeAllFromArray:{values:i.elements.map((function(t){return n.yr(t)}))}};if(i instanceof Ut)return{fieldPath:t.field.ot(),increment:this.yr(i.tn)};throw P("Unknown transform: "+t.transform)},t.prototype.Gr=function(t){var n=this,i=null;if("setToServerValue"in t)S("REQUEST_TIME"===t.setToServerValue,"Unknown server value transform proto: "+JSON.stringify(t)),i=Ft.instance;else if("appendMissingElements"in t){var e=t.appendMissingElements.values||[];i=new xt(e.map((function(t){return n.Tr(t)})))}else if("removeAllFromArray"in t){e=t.removeAllFromArray.values||[];i=new jt(e.map((function(t){return n.Tr(t)})))}else if("increment"in t){var r=this.Tr(t.increment);S(r instanceof on,"NUMERIC_ADD transform requires a NumberValue"),i=new Ut(r)}else P("Unknown transform proto: "+JSON.stringify(t));var u=Dt.dt(t.fieldPath);return new Qt(u,i)},t.prototype.Kr=function(t){return{documents:[this.pr(t.path)]}},t.prototype.Hr=function(t){var n=t.documents.length;S(1===n,"DocumentsTarget contained other than 1 document: "+n);var i=t.documents[0];return On.oi(this.gr(i)).bi()},t.prototype.Jr=function(t){var n={structuredQuery:{}},i=t.path;null!==t.collectionGroup?(S(i.length%2==0,"Collection Group queries should be within a document path or root."),n.parent=this.pr(i),n.structuredQuery.from=[{collectionId:t.collectionGroup,allDescendants:!0}]):(S(i.length%2!=0,"Document queries with filters are not supported."),n.parent=this.pr(i.tt()),n.structuredQuery.from=[{collectionId:i.et()}]);var e=this.Yr(t.filters);e&&(n.structuredQuery.where=e);var r=this.Xr(t.orderBy);r&&(n.structuredQuery.orderBy=r);var u=this.rr(t.limit);return null!==u&&(n.structuredQuery.limit=u),t.startAt&&(n.structuredQuery.startAt=this.$r(t.startAt)),t.endAt&&(n.structuredQuery.endAt=this.$r(t.endAt)),n},t.prototype.Zr=function(t){var n=this.gr(t.parent),i=t.structuredQuery,e=i.from?i.from.length:0,r=null;if(e>0){S(1===e,"StructuredQuery.from with more than one collection is not supported.");var u=i.from[0];u.allDescendants?r=u.collectionId:n=n.child(u.collectionId)}var s=[];i.where&&(s=this.tu(i.where));var o=[];i.orderBy&&(o=this.nu(i.orderBy));var h=null;i.limit&&(h=this.ur(i.limit));var c=null;i.startAt&&(c=this.iu(i.startAt));var a=null;return i.endAt&&(a=this.iu(i.endAt)),new On(n,r,o,s,h,Sn.ti,c,a).bi()},t.prototype.eu=function(t){var n=this.ru(t.Fi);return null==n?null:{"goog-listen-tags":n}},t.prototype.ru=function(t){switch(t){case kn.ki:return null;case kn.Ni:return"existence-filter-mismatch";case kn.Oi:return"limbo-document";default:return P("Unrecognized query purpose: "+t)}},t.prototype.bi=function(t){var n,i=t.target;return(n=i.Zn()?{documents:this.Kr(i)}:{query:this.Jr(i)}).targetId=t.targetId,t.resumeToken.length>0&&(n.resumeToken=this.ir(t.resumeToken)),n},t.prototype.Yr=function(t){var n=this;if(0!==t.length){var i=t.map((function(t){return t instanceof jn?n.uu(t):P("Unrecognized filter: "+JSON.stringify(t))}));return 1===i.length?i[0]:{compositeFilter:{op:"AND",filters:i}}}},t.prototype.tu=function(t){var n=this;return t?void 0!==t.unaryFilter?[this.su(t)]:void 0!==t.fieldFilter?[this.ou(t)]:void 0!==t.compositeFilter?t.compositeFilter.filters.map((function(t){return n.tu(t)})).reduce((function(t,n){return t.concat(n)})):P("Unknown filter: "+JSON.stringify(t)):[]},t.prototype.Xr=function(t){var n=this;if(0!==t.length)return t.map((function(t){return n.hu(t)}))},t.prototype.nu=function(t){var n=this;return t.map((function(t){return n.cu(t)}))},t.prototype.$r=function(t){var n=this;return{before:t.before,values:t.position.map((function(t){return n.yr(t)}))}},t.prototype.iu=function(t){var n=this,i=!!t.before,e=t.values.map((function(t){return n.Tr(t)}));return new Gn(e,i)},t.prototype.au=function(t){return ki[t.name]},t.prototype.fu=function(t){switch(t){case"ASCENDING":return Qn.ASCENDING;case"DESCENDING":return Qn.DESCENDING;default:return}},t.prototype.lu=function(t){return Ni[t.name]},t.prototype.du=function(t){switch(t){case"EQUAL":return xn.EQUAL;case"GREATER_THAN":return xn.GREATER_THAN;case"GREATER_THAN_OR_EQUAL":return xn.GREATER_THAN_OR_EQUAL;case"LESS_THAN":return xn.LESS_THAN;case"LESS_THAN_OR_EQUAL":return xn.LESS_THAN_OR_EQUAL;case"ARRAY_CONTAINS":return xn.ARRAY_CONTAINS;case"IN":return xn.IN;case"ARRAY_CONTAINS_ANY":return xn.ARRAY_CONTAINS_ANY;case"OPERATOR_UNSPECIFIED":return P("Unspecified operator");default:return P("Unknown operator")}},t.prototype.vu=function(t){return{fieldPath:t.ot()}},t.prototype.wu=function(t){return Dt.dt(t.fieldPath)},t.prototype.hu=function(t){return{field:this.vu(t.field),direction:this.au(t.dir)}},t.prototype.cu=function(t){return new Wn(this.wu(t.field),this.fu(t.direction))},t.prototype.ou=function(t){return jn.create(this.wu(t.fieldFilter.field),this.du(t.fieldFilter.op),this.Tr(t.fieldFilter.value))},t.prototype.uu=function(t){if(t.op===xn.EQUAL){if(t.value.isEqual(an.Qn))return{unaryFilter:{field:this.vu(t.field),op:"IS_NAN"}};if(t.value.isEqual(un.Bn))return{unaryFilter:{field:this.vu(t.field),op:"IS_NULL"}}}return{fieldFilter:{field:this.vu(t.field),op:this.lu(t.op),value:this.yr(t.value)}}},t.prototype.su=function(t){switch(t.unaryFilter.op){case"IS_NAN":var n=this.wu(t.unaryFilter.field);return jn.create(n,xn.EQUAL,an.Qn);case"IS_NULL":var i=this.wu(t.unaryFilter.field);return jn.create(i,xn.EQUAL,un.Bn);case"OPERATOR_UNSPECIFIED":return P("Unspecified filter");default:return P("Unknown filter")}},t.prototype.Ur=function(t){var n=[];return t.fields.forEach((function(t){return n.push(t.ot())})),{fieldPaths:n}},t.prototype.Qr=function(t){var n=(t.fieldPaths||[]).map((function(t){return Dt.dt(t)}));return qt.en(n)},t}(),Ui=function(){function t(){}return t.mu=function(n){t.platform&&P("Platform already defined"),t.platform=n},t.t=function(){return t.platform||P("Platform not set"),t.platform},t}();function Li(){return Ui.t().tr}function Bi(t,n){function i(){var t="This constructor is private.";throw n&&(t+=" ",t+=n),new Q(q.INVALID_ARGUMENT,t)}for(var e in i.prototype=t.prototype,t)t.hasOwnProperty(e)&&(i[e]=t[e]);return i}function Mi(){if("undefined"==typeof Uint8Array)throw new Q(q.UNIMPLEMENTED,"Uint8Arrays are not available in this environment.")}function qi(){if(!Ui.t().pu)throw new Q(q.UNIMPLEMENTED,"Blobs are unavailable in Firestore in this environment.")}var Qi,Gi,Wi=function(){function t(t){qi(),this.gu=t}return t.fromBase64String=function(n){it("Blob.fromBase64String",arguments,1),ut("Blob.fromBase64String","string",1,n),qi();try{var i=Ui.t().atob(n);return new t(i)}catch(t){throw new Q(q.INVALID_ARGUMENT,"Failed to construct Blob from Base64 string: "+t)}},t.fromUint8Array=function(n){if(it("Blob.fromUint8Array",arguments,1),Mi(),!(n instanceof Uint8Array))throw pt("Blob.fromUint8Array","Uint8Array",1,n);var i=Array.prototype.map.call(n,(function(t){return String.fromCharCode(t)})).join("");return new t(i)},t.prototype.toBase64=function(){return it("Blob.toBase64",arguments,0),qi(),Ui.t().btoa(this.gu)},t.prototype.toUint8Array=function(){it("Blob.toUint8Array",arguments,0),Mi();for(var t=new Uint8Array(this.gu.length),n=0;n<this.gu.length;n++)t[n]=this.gu.charCodeAt(n);return t},t.prototype.toString=function(){return"Blob(base64: "+this.toBase64()+")"},t.prototype.isEqual=function(t){return this.gu===t.gu},t.prototype.Wn=function(){return 2*this.gu.length},t.prototype.q=function(t){return V(this.gu,t.gu)},t}(),zi=Bi(Wi,"Use Blob.fromUint8Array() or Blob.fromBase64String() instead."),Ki=function(){function t(t){this.bu=t,this.yu={}}return t.prototype.get=function(t){var n=this.bu(t),i=this.yu[n];if(void 0!==i)for(var e=0,r=i;e<r.length;e++){var u=r[e],s=u[0],o=u[1];if(s.isEqual(t))return o}},t.prototype.has=function(t){return void 0!==this.get(t)},t.prototype.set=function(t,n){var i=this.bu(t),e=this.yu[i];if(void 0!==e){for(var r=0;r<e.length;r++)if(e[r][0].isEqual(t))return void(e[r]=[t,n]);e.push([t,n])}else this.yu[i]=[[t,n]]},t.prototype.delete=function(t){var n=this.bu(t),i=this.yu[n];if(void 0===i)return!1;for(var e=0;e<i.length;e++)if(i[e][0].isEqual(t))return 1===i.length?delete this.yu[n]:i.splice(e,1),!0;return!1},t.prototype.forEach=function(t){Z(this.yu,(function(n,i){for(var e=0,r=i;e<r.length;e++){var u=r[e],s=u[0],o=u[1];t(s,o)}}))},t.prototype.nt=function(){return tt(this.yu)},t}(),Hi=function(){function t(t,n,i,e){this.batchId=t,this.Gn=n,this.baseMutations=i,this.mutations=e,S(e.length>0,"Cannot create an empty mutation batch")}return t.prototype.$t=function(t,n,i){n&&S(n.key.isEqual(t),"applyToRemoteDocument: key "+t+" should match maybeDoc key\n "+n.key);var e=i._u;S(e.length===this.mutations.length,"Mismatch between mutations length\n ("+this.mutations.length+") and mutation results length\n ("+e.length+").");for(var r=0;r<this.mutations.length;r++){var u=this.mutations[r];if(u.key.isEqual(t)){var s=e[r];n=u.$t(n,s)}}return n},t.prototype.Xt=function(t,n){n&&S(n.key.isEqual(t),"applyToLocalDocument: key "+t+" should match maybeDoc key\n "+n.key);for(var i=0,e=this.baseMutations;i<e.length;i++){(o=e[i]).key.isEqual(t)&&(n=o.Xt(n,n,this.Gn))}for(var r=n,u=0,s=this.mutations;u<s.length;u++){var o;(o=s[u]).key.isEqual(t)&&(n=o.Xt(n,r,this.Gn))}return n},t.prototype.Iu=function(t){var n=this,i=t;return this.mutations.forEach((function(e){var r=n.Xt(e.key,t.get(e.key));r&&(i=i.bt(e.key,r))})),i},t.prototype.keys=function(){return this.mutations.reduce((function(t,n){return t.add(n.key)}),ci())},t.prototype.isEqual=function(t){return this.batchId===t.batchId&&k(this.mutations,t.mutations)&&k(this.baseMutations,t.baseMutations)},t}(),Ji=function(){function t(t,n,i,e,r){this.batch=t,this.Tu=n,this._u=i,this.streamToken=e,this.Eu=r}return t.from=function(n,i,e,r){S(n.mutations.length===e.length,"Mutations sent "+n.mutations.length+" must equal results received "+e.length);for(var u=oi(),s=n.mutations,o=0;o<s.length;o++)u=u.bt(s[o].key,e[o].version);return new t(n,i,e,r,u)},t}(),Yi=function(){function t(){this.Ru=new Nt(Xi.Kn),this.Au=new Nt(Xi.Du)}return t.prototype.nt=function(){return this.Ru.nt()},t.prototype.Pu=function(t,n){var i=new Xi(t,n);this.Ru=this.Ru.add(i),this.Au=this.Au.add(i)},t.prototype.Su=function(t,n){var i=this;t.forEach((function(t){return i.Pu(t,n)}))},t.prototype.Cu=function(t,n){this.Vu(new Xi(t,n))},t.prototype.ku=function(t,n){var i=this;t.forEach((function(t){return i.Cu(t,n)}))},t.prototype.Nu=function(t){var n=this,i=Pt.EMPTY,e=new Xi(i,t),r=new Xi(i,t+1),u=[];return this.Au.zt([e,r],(function(t){n.Vu(t),u.push(t.key)})),u},t.prototype.Ou=function(){var t=this;this.Ru.forEach((function(n){return t.Vu(n)}))},t.prototype.Vu=function(t){this.Ru=this.Ru.delete(t),this.Au=this.Au.delete(t)},t.prototype.Fu=function(t){var n=Pt.EMPTY,i=new Xi(n,t),e=new Xi(n,t+1),r=ci();return this.Au.zt([i,e],(function(t){r=r.add(t.key)})),r},t.prototype.xu=function(t){var n=new Xi(t,0),i=this.Ru.Ht(n);return null!==i&&t.isEqual(i.key)},t}(),Xi=function(){function t(t,n){this.key=t,this.ju=n}return t.Kn=function(t,n){return Pt.X(t.key,n.key)||V(t.ju,n.ju)},t.Du=function(t,n){return V(t.ju,n.ju)||Pt.X(t.key,n.key)},t}(),$i=function(){function t(t){var n=this;this.Uu=null,this.Lu=null,this.result=void 0,this.error=void 0,this.Bu=!1,this.Mu=!1,t((function(t){n.Bu=!0,n.result=t,n.Uu&&n.Uu(t)}),(function(t){n.Bu=!0,n.error=t,n.Lu&&n.Lu(t)}))}return t.prototype.catch=function(t){return this.next(void 0,t)},t.prototype.next=function(n,i){var e=this;return this.Mu&&P("Called next() or catch() twice for PersistencePromise"),this.Mu=!0,this.Bu?this.error?this.qu(i,this.error):this.Qu(n,this.result):new t((function(t,r){e.Uu=function(i){e.Qu(n,i).next(t,r)},e.Lu=function(n){e.qu(i,n).next(t,r)}}))},t.prototype.Gu=function(){var t=this;return new Promise((function(n,i){t.next(n,i)}))},t.prototype.Wu=function(n){try{var i=n();return i instanceof t?i:t.resolve(i)}catch(n){return t.reject(n)}},t.prototype.Qu=function(n,i){return n?this.Wu((function(){return n(i)})):t.resolve(i)},t.prototype.qu=function(n,i){return n?this.Wu((function(){return n(i)})):t.reject(i)},t.resolve=function(n){return new t((function(t,i){t(n)}))},t.reject=function(n){return new t((function(t,i){i(n)}))},t.zu=function(n){return new t((function(t,i){var e=0,r=0,u=!1;n.forEach((function(n){++e,n.next((function(){++r,u&&r===e&&t()}),(function(t){return i(t)}))})),u=!0,r===e&&t()}))},t.Ku=function(n){for(var i=t.resolve(!1),e=function(n){i=i.next((function(i){return i?t.resolve(i):n()}))},r=0,u=n;r<u.length;r++){e(u[r])}return i},t.forEach=function(t,n){var i=this,e=[];return t.forEach((function(t,r){e.push(n.call(i,t,r))})),this.zu(e)},t}(),Zi=function(){function t(){this.Hu=new Ki((function(t){return t.toString()})),this.Ju=!1}return Object.defineProperty(t.prototype,"readTime",{get:function(){return S(void 0!==this.Yu,"Read time is not set. All removeEntry() calls must include a readTime if `trackRemovals` is used."),this.Yu},set:function(t){S(void 0===this.Yu||this.Yu.isEqual(t),"All changes in a RemoteDocumentChangeBuffer must have the same read time"),this.Yu=t},enumerable:!0,configurable:!0}),t.prototype.Xu=function(t,n){this.$u(),this.readTime=n,this.Hu.set(t.key,t)},t.prototype.Zu=function(t,n){this.$u(),n&&(this.readTime=n),this.Hu.set(t,null)},t.prototype.ts=function(t,n){this.$u();var i=this.Hu.get(n);return void 0!==i?$i.resolve(i):this.ns(t,n)},t.prototype.getEntries=function(t,n){return this.es(t,n)},t.prototype.apply=function(t){return this.$u(),this.Ju=!0,this.rs(t)},t.prototype.$u=function(){S(!this.Ju,"Changes have already been applied.")},t}(),te="The current tab is not in the required state to perform this operation. It might be necessary to refresh the browser tab.",ne=function(){function t(){this.us=[]}return t.prototype.ss=function(t){this.us.push(t)},t.prototype.os=function(){this.us.forEach((function(t){return t()}))},t}(),ie=function(){function t(t,n,i){this.hs=t,this.cs=n,this.as=i}return t.prototype.fs=function(t,n){var i=this;return this.cs.ls(t,n).next((function(e){return i.ds(t,n,e)}))},t.prototype.ds=function(t,n,i){return this.hs.ts(t,n).next((function(t){for(var e=0,r=i;e<r.length;e++){t=r[e].Xt(n,t)}return t}))},t.prototype.vs=function(t,n,i){var e=ei();return n.forEach((function(t,n){for(var r=0,u=i;r<u.length;r++){n=u[r].Xt(t,n)}e=e.bt(t,n)})),e},t.prototype.ws=function(t,n){var i=this;return this.hs.getEntries(t,n).next((function(n){return i.ms(t,n)}))},t.prototype.ms=function(t,n){var i=this;return this.cs.ps(t,n).next((function(e){var r=i.vs(t,n,e),u=ii();return r.forEach((function(t,n){n||(n=new _n(t,Tt.K())),u=u.bt(t,n)})),u}))},t.prototype.gs=function(t,n,i){return n.Zn()?this.bs(t,n.path):n.Pi()?this.ys(t,n,i):this._s(t,n,i)},t.prototype.bs=function(t,n){return this.fs(t,new Pt(n)).next((function(t){var n=ui();return t instanceof yn&&(n=n.bt(t.key,t)),n}))},t.prototype.ys=function(t,n,i){var e=this;S(n.path.nt(),"Currently we only support collection group queries at the root.");var r=n.collectionGroup,u=ui();return this.as.Is(t,r).next((function(s){return $i.forEach(s,(function(s){var o=n.pi(s.child(r));return e._s(t,o,i).next((function(t){t.forEach((function(t,n){u=u.bt(t,n)}))}))})).next((function(){return u}))}))},t.prototype._s=function(t,n,i){var e,r,u=this;return this.hs.gs(t,n,i).next((function(i){return e=i,u.cs.Ts(t,n)})).next((function(n){return r=n,u.Es(t,r,e).next((function(t){e=t;for(var n=0,i=r;n<i.length;n++)for(var u=i[n],s=0,o=u.mutations;s<o.length;s++){var h=o[s],c=h.key,a=e.get(c),f=h.Xt(a,a,u.Gn);e=f instanceof yn?e.bt(c,f):e.remove(c)}}))})).next((function(){return e.forEach((function(t,i){n.matches(i)||(e=e.remove(t))})),e}))},t.prototype.Es=function(t,n,i){for(var e=ci(),r=0,u=n;r<u.length;r++)for(var s=0,o=u[r].mutations;s<o.length;s++){var h=o[s];h instanceof $t&&null===i.get(h.key)&&(e=e.add(h.key))}var c=i;return this.hs.getEntries(t,e).next((function(t){return t.forEach((function(t,n){null!==n&&n instanceof yn&&(c=c.bt(t,n))})),c}))},t}(),ee=function(){function t(t,n,i,e){this.targetId=t,this.fromCache=n,this.Rs=i,this.As=e}return t.Ds=function(n,i){for(var e=ci(),r=ci(),u=0,s=i.docChanges;u<s.length;u++){var o=s[u];switch(o.type){case li.Qi:e=e.add(o.doc.key);break;case li.Gi:r=r.add(o.doc.key)}}return new t(n,i.fromCache,e,r)},t}(),re=function(){function t(t,n){var i=this;this.previousValue=t,n&&(n.Ps=function(t){return i.Ss(t)},this.Cs=function(t){return n.Vs(t)})}return t.prototype.Ss=function(t){return this.previousValue=Math.max(t,this.previousValue),this.previousValue},t.prototype.next=function(){var t=++this.previousValue;return this.Cs&&this.Cs(t),t},t.ks=-1,t}(),ue=function(){var t=this;this.promise=new Promise((function(n,i){t.resolve=n,t.reject=i}))};(Gi=Qi||(Qi={})).Ns="all",Gi.Os="listen_stream_idle",Gi.Fs="listen_stream_connection_backoff",Gi.xs="write_stream_idle",Gi.js="write_stream_connection_backoff",Gi.Us="online_state_timeout",Gi.Ls="client_metadata_refresh",Gi.Bs="lru_garbage_collection",Gi.Ms="retry_transaction";var se=function(){function t(t,n,i,e,r){this.qs=t,this.Qs=n,this.Gs=i,this.op=e,this.Ws=r,this.zs=new ue,this.then=this.zs.promise.then.bind(this.zs.promise),this.catch=this.zs.promise.catch.bind(this.zs.promise),this.zs.promise.catch((function(t){}))}return t.Ks=function(n,i,e,r,u){var s=new t(n,i,Date.now()+e,r,u);return s.start(e),s},t.prototype.start=function(t){var n=this;this.Hs=setTimeout((function(){return n.Js()}),t)},t.prototype.Ys=function(){return this.Js()},t.prototype.cancel=function(t){null!==this.Hs&&(this.clearTimeout(),this.zs.reject(new Q(q.CANCELLED,"Operation cancelled"+(t?": "+t:""))))},t.prototype.Js=function(){var t=this;this.qs.Xs((function(){return null!==t.Hs?(t.clearTimeout(),t.op().then((function(n){return t.zs.resolve(n)}))):Promise.resolve()}))},t.prototype.clearTimeout=function(){null!==this.Hs&&(this.Ws(this),clearTimeout(this.Hs),this.Hs=null)},t}(),oe=function(){function t(){this.$s=Promise.resolve(),this.Zs=!1,this.to=[],this.no=null,this.io=!1,this.eo=[]}return Object.defineProperty(t.prototype,"ro",{get:function(){return this.Zs},enumerable:!0,configurable:!0}),t.prototype.Xs=function(t){this.enqueue(t)},t.prototype.uo=function(t){this.so(),this.oo(t)},t.prototype.ho=function(t){return this.so(),this.oo(t)},t.prototype.co=function(t){return e(this,void 0,void 0,(function(){return r(this,(function(n){switch(n.label){case 0:return this.so(),this.Zs?[3,2]:(this.Zs=!0,[4,this.ho(t)]);case 1:n.sent(),n.label=2;case 2:return[2]}}))}))},t.prototype.enqueue=function(t){return this.so(),this.Zs?new Promise((function(t){})):this.oo(t)},t.prototype.oo=function(t){var n=this,i=this.$s.then((function(){return n.io=!0,t().catch((function(t){n.no=t,n.io=!1;var i=t.stack||t.message||"";throw A("INTERNAL UNHANDLED ERROR: ",i),i.indexOf("Firestore Test Simulated Error")<0&&setTimeout((function(){throw t}),0),t})).then((function(t){return n.io=!1,t}))}));return this.$s=i,i},t.prototype.ao=function(t,n,i){var e=this;this.so(),S(n>=0,"Attempted to schedule an operation with a negative delay of "+n),this.eo.indexOf(t)>-1&&(n=0);var r=se.Ks(this,t,n,i,(function(t){return e.fo(t)}));return this.to.push(r),r},t.prototype.so=function(){this.no&&P("AsyncQueue is already failed: "+(this.no.stack||this.no.message))},t.prototype.lo=function(){S(this.io,"verifyOpInProgress() called when no op in progress on this queue.")},t.prototype.do=function(){return this.ho((function(){return Promise.resolve()}))},t.prototype.vo=function(t){for(var n=0,i=this.to;n<i.length;n++){if(i[n].Qs===t)return!0}return!1},t.prototype.wo=function(t){var n=this;return this.do().then((function(){S(t===Qi.Ns||n.vo(t),"Attempted to drain to missing operation "+t),n.to.sort((function(t,n){return t.Gs-n.Gs}));for(var i=0,e=n.to;i<e.length;i++){var r=e[i];if(r.Ys(),t!==Qi.Ns&&r.Qs===t)break}return n.do()}))},t.prototype.mo=function(t){this.eo.push(t)},t.prototype.fo=function(t){var n=this.to.indexOf(t);S(n>=0,"Delayed operation not found."),this.to.splice(n,1)},t}();function he(t,n){var i=t[0],e=t[1],r=n[0],u=n[1],s=V(i,r);return 0===s?V(e,u):s}var ce=function(){function t(t){this.po=t,this.buffer=new Nt(he),this.bo=0}return t.prototype.yo=function(){return++this.bo},t.prototype._o=function(t){var n=[t,this.yo()];if(this.buffer.size<this.po)this.buffer=this.buffer.add(n);else{var i=this.buffer.last();he(n,i)<0&&(this.buffer=this.buffer.delete(i).add(n))}},Object.defineProperty(t.prototype,"maxValue",{get:function(){return this.buffer.last()[0]},enumerable:!0,configurable:!0}),t}(),ae={Io:!1,To:0,Eo:0,Ro:0},fe=function(){function t(t,n,i){this.Ao=t,this.Do=n,this.Po=i}return t.So=function(n){return new t(n,t.Co,t.Vo)},t.ko=-1,t.No=1048576,t.Oo=41943040,t.Co=10,t.Vo=1e3,t.Fo=new t(t.Oo,t.Co,t.Vo),t.DISABLED=new t(t.ko,0,0),t}(),le=function(){function t(t,n,i){this.xo=t,this.qs=n,this.jo=i,this.Uo=!1,this.Lo=null}return t.prototype.start=function(){S(null===this.Lo,"Cannot start an already started LruScheduler"),this.xo.Bo.Ao!==fe.ko&&this.Mo()},t.prototype.stop=function(){this.Lo&&(this.Lo.cancel(),this.Lo=null)},Object.defineProperty(t.prototype,"qo",{get:function(){return null!==this.Lo},enumerable:!0,configurable:!0}),t.prototype.Mo=function(){var t=this;S(null===this.Lo,"Cannot schedule GC while a task is pending");var n=this.Uo?3e5:6e4;R("LruGarbageCollector","Garbage collection scheduled in "+n+"ms"),this.Lo=this.qs.ao(Qi.Bs,n,(function(){return t.Lo=null,t.Uo=!0,t.jo.Qo(t.xo).then((function(){return t.Mo()})).catch(me)}))},t}(),de=function(){function t(t,n){this.Go=t,this.Bo=n}return t.prototype.Wo=function(t,n){return this.Go.zo(t).next((function(t){return Math.floor(n/100*t)}))},t.prototype.Ko=function(t,n){var i=this;if(0===n)return $i.resolve(re.ks);var e=new ce(n);return this.Go.qe(t,(function(t){return e._o(t.sequenceNumber)})).next((function(){return i.Go.Ho(t,(function(t){return e._o(t)}))})).next((function(){return e.maxValue}))},t.prototype.Jo=function(t,n,i){return this.Go.Jo(t,n,i)},t.prototype.Yo=function(t,n){return this.Go.Yo(t,n)},t.prototype.Xo=function(t,n){var i=this;return this.Bo.Ao===fe.ko?(R("LruGarbageCollector","Garbage collection skipped; disabled"),$i.resolve(ae)):this.$o(t).next((function(e){return e<i.Bo.Ao?(R("LruGarbageCollector","Garbage collection skipped; Cache size "+e+" is lower than threshold "+i.Bo.Ao),ae):i.Zo(t,n)}))},t.prototype.$o=function(t){return this.Go.$o(t)},t.prototype.Zo=function(t,n){var i,e,r,u,s,o,h,c=this,a=Date.now();return this.Wo(t,this.Bo.Do).next((function(n){return n>c.Bo.Po?(R("LruGarbageCollector","Capping sequence numbers to collect down to the maximum of "+c.Bo.Po+" from "+n),e=c.Bo.Po):e=n,u=Date.now(),c.Ko(t,e)})).next((function(e){return i=e,s=Date.now(),c.Jo(t,i,n)})).next((function(n){return r=n,o=Date.now(),c.Yo(t,i)})).next((function(t){(h=Date.now(),T()<=y.DEBUG)&&R("LruGarbageCollector","LRU Garbage Collection\n\tCounted targets in "+(u-a)+"ms\n\tDetermined least recently used "+e+" in "+(s-u)+"ms\n\tRemoved "+r+" targets in "+(o-s)+"ms\n\tRemoved "+t+" documents in "+(h-o)+"ms\nTotal Duration: "+(h-a)+"ms");return $i.resolve({Io:!0,To:e,Eo:r,Ro:t})}))},t}(),ve="LocalStore",we=function(){function t(t,n,i){this.persistence=t,this.th=n,this.nh=new Yi,this.ih=new St(V),this.eh=new Ki((function(t){return t.canonicalId()})),this.rh=Tt.MIN,S(t.qo,"LocalStore was passed an unstarted persistence implementation"),this.persistence.sh.uh(this.nh),this.cs=t.oh(i),this.hh=t.ah(),this.fh=t.lh(),this.dh=new ie(this.hh,this.cs,this.persistence.vh()),this.th.wh(this.dh)}return t.prototype.start=function(){return this.mh()},t.prototype.ph=function(t){return e(this,void 0,void 0,(function(){var n,i,e,u=this;return r(this,(function(r){switch(r.label){case 0:return n=this.cs,i=this.dh,[4,this.persistence.runTransaction("Handle user change","readonly-idempotent",(function(e){var r;return u.cs.gh(e).next((function(s){return r=s,n=u.persistence.oh(t),i=new ie(u.hh,n,u.persistence.vh()),n.gh(e)})).next((function(t){for(var n=[],u=[],s=ci(),o=0,h=r;o<h.length;o++){var c=h[o];n.push(c.batchId);for(var a=0,f=c.mutations;a<f.length;a++){var l=f[a];s=s.add(l.key)}}for(var d=0,v=t;d<v.length;d++){c=v[d];u.push(c.batchId);for(var w=0,m=c.mutations;w<m.length;w++){l=m[w];s=s.add(l.key)}}return i.ws(e,s).next((function(t){return{bh:t,yh:n,_h:u}}))}))}))];case 1:return e=r.sent(),this.cs=n,this.dh=i,this.th.wh(this.dh),[2,e]}}))}))},t.prototype.Ih=function(t){var n,i=this,e=It.now(),r=t.reduce((function(t,n){return t.add(n.key)}),ci());return this.persistence.runTransaction("Locally write mutations","readwrite-idempotent",(function(u){return i.dh.ws(u,r).next((function(r){n=r;for(var s=[],o=0,h=t;o<h.length;o++){var c=h[o],a=c.wn(n.get(c.key));null!=a&&s.push(new $t(c.key,a,a.mn(),Jt.exists(!0)))}return i.cs.Th(u,e,s,t)}))})).then((function(t){var i=t.Iu(n);return{batchId:t.batchId,Hu:i}}))},t.prototype.Eh=function(t){var n=this;return this.persistence.runTransaction("Lookup mutation documents","readonly-idempotent",(function(i){return n.cs.Rh(i,t).next((function(t){return t?n.dh.ws(i,t):$i.resolve(null)}))}))},t.prototype.Ah=function(t){var n=this;return this.persistence.runTransaction("Acknowledge batch","readwrite-primary-idempotent",(function(i){var e=t.batch.keys(),r=n.hh.Dh({Ph:!0});return n.cs.Ah(i,t.batch,t.streamToken).next((function(){return n.Sh(i,t,r)})).next((function(){return r.apply(i)})).next((function(){return n.cs.Ch(i)})).next((function(){return n.dh.ws(i,e)}))}))},t.prototype.Vh=function(t){var n=this;return this.persistence.runTransaction("Reject batch","readwrite-primary-idempotent",(function(i){var e;return n.cs.kh(i,t).next((function(t){return S(null!==t,"Attempt to reject nonexistent batch!"),e=t.keys(),n.cs.Nh(i,t)})).next((function(){return n.cs.Ch(i)})).next((function(){return n.dh.ws(i,e)}))}))},t.prototype.Oh=function(){var t=this;return this.persistence.runTransaction("Get highest unacknowledged batch id","readonly-idempotent",(function(n){return t.cs.Oh(n)}))},t.prototype.Fh=function(){var t=this;return this.persistence.runTransaction("Get last stream token","readonly-idempotent",(function(n){return t.cs.Fh(n)}))},t.prototype.xh=function(t){var n=this;return this.persistence.runTransaction("Set last stream token","readwrite-primary-idempotent",(function(i){return n.cs.xh(i,t)}))},t.prototype.jh=function(){var t=this;return this.persistence.runTransaction("Get last remote snapshot version","readonly-idempotent",(function(n){return t.fh.jh(n)}))},t.prototype.Uh=function(n){var i=this,e=n.xi,r=this.ih;return this.persistence.runTransaction("Apply remote event","readwrite-primary-idempotent",(function(u){var s=i.hh.Dh({Ph:!0});r=i.ih;var o=[];$(n.ie,(function(n,s){var h=r.get(n);if(h){o.push(i.fh.Lh(u,s.fe,n).next((function(){return i.fh.Bh(u,s.ce,n)})));var c=s.resumeToken;if(c.length>0){var a=h.Ui(c,e).ji(u.Mh);r=r.bt(n,a),t.qh(h,a,s)&&o.push(i.fh.Qh(u,a))}}}));var h=ii(),c=ci();if(n.re.forEach((function(t,n){c=c.add(t)})),o.push(s.getEntries(u,c).next((function(t){n.re.forEach((function(r,c){var a=t.get(r);c instanceof _n&&c.version.isEqual(Tt.MIN)?(s.Zu(r,e),h=h.bt(r,c)):null==a||c.version.h(a.version)>0||0===c.version.h(a.version)&&a.hasPendingWrites?(S(!Tt.MIN.isEqual(e),"Cannot add a document when the remote version is zero"),s.Xu(c,e),h=h.bt(r,c)):R(ve,"Ignoring outdated watch update for ",r,". Current version:",a.version," Watch version:",c.version),n.ue.has(r)&&o.push(i.persistence.sh.Gh(u,r))}))}))),!e.isEqual(Tt.MIN)){var a=i.fh.jh(u).next((function(t){return S(e.h(t)>=0,"Watch stream reverted to previous snapshot?? "+e+" < "+t),i.fh.Wh(u,u.Mh,e)}));o.push(a)}return $i.zu(o).next((function(){return s.apply(u)})).next((function(){return i.dh.ms(u,h)}))})).then((function(t){return i.ih=r,t}))},t.qh=function(t,n,i){return S(n.resumeToken.length>0,"Attempted to persist target data with no resume token"),0===t.resumeToken.length||(n.xi.H()-t.xi.H()>=this.zh||i.ce.size+i.ae.size+i.fe.size>0)},t.prototype.Kh=function(t){for(var n=this,i=0,e=t;i<e.length;i++){var r=e[i],u=r.targetId;if(this.nh.Su(r.Rs,u),this.nh.ku(r.As,u),!r.fromCache){var s=this.ih.get(u);S(null!==s,"Can't set limbo-free snapshot version for unknown target: "+u);var o=s.xi,h=s.Li(o);this.ih=this.ih.bt(u,h)}}return this.persistence.runTransaction("notifyLocalViewChanges","readwrite-idempotent",(function(i){return $i.forEach(t,(function(t){return $i.forEach(t.As,(function(t){return n.persistence.sh.Cu(i,t)}))}))}))},t.prototype.Hh=function(t){var n=this;return this.persistence.runTransaction("Get next mutation batch","readonly-idempotent",(function(i){return void 0===t&&(t=-1),n.cs.Jh(i,t)}))},t.prototype.Yh=function(t){var n=this;return this.persistence.runTransaction("read document","readonly-idempotent",(function(i){return n.dh.fs(i,t)}))},t.prototype.Xh=function(t){var n=this;return this.persistence.runTransaction("Allocate target","readwrite-idempotent",(function(i){var e;return n.fh.$h(i,t).next((function(r){return r?(e=r,$i.resolve(e)):n.fh.Zh(i).next((function(r){return e=new Yn(t,r,kn.ki,i.Mh),n.fh.tc(i,e).next((function(){return e}))}))}))})).then((function(i){return null===n.ih.get(i.targetId)&&(n.ih=n.ih.bt(i.targetId,i),n.eh.set(t,i.targetId)),i}))},t.prototype.$h=function(t,n){var i=this.eh.get(n);return void 0!==i?$i.resolve(this.ih.get(i)):this.fh.$h(t,n)},t.prototype.nc=function(t,n){var i=this,e=this.ih.get(t);S(null!==e,"Tried to release nonexistent target: "+t);var r=n?"readwrite-idempotent":"readwrite-primary-idempotent";return this.persistence.runTransaction("Release target",r,(function(r){var u=i.nh.Nu(t);return n?$i.resolve():$i.forEach(u,(function(t){return i.persistence.sh.Cu(r,t)})).next((function(){i.persistence.sh.removeTarget(r,e)}))})).then((function(){i.ih=i.ih.remove(t),i.eh.delete(e.target)}))},t.prototype.ic=function(t,n){var i=this,e=Tt.MIN,r=ci();return this.persistence.runTransaction("Execute query","readonly-idempotent",(function(u){return i.$h(u,t.bi()).next((function(t){if(t)return e=t.lastLimboFreeSnapshotVersion,i.fh.ec(u,t.targetId).next((function(t){r=t}))})).next((function(){return i.th.gs(u,t,n?e:Tt.MIN,n?r:ci())})).next((function(t){return{documents:t,rc:r}}))}))},t.prototype.uc=function(t){var n=this;return this.persistence.runTransaction("Remote document keys","readonly-idempotent",(function(i){return n.fh.ec(i,t)}))},t.prototype.sc=function(){return this.persistence.sc()},t.prototype.oc=function(t){this.cs.hc(t)},t.prototype.cc=function(t){this.persistence.cc(t)},t.prototype.Sh=function(t,n,i){var e=this,r=n.batch,u=r.keys(),s=$i.resolve();return u.forEach((function(e){s=s.next((function(){return i.ts(t,e)})).next((function(t){var u=t,s=n.Eu.get(e);S(null!==s,"ackVersions should contain every doc in the write."),(!u||u.version.h(s)<0)&&((u=r.$t(e,u,n))?i.Xu(u,n.Tu):S(!t,"Mutation batch "+r+" applied to document "+t+" resulted in null"))}))})),s.next((function(){return e.cs.Nh(t,r)}))},t.prototype.Qo=function(t){var n=this;return this.persistence.runTransaction("Collect garbage","readwrite-primary-idempotent",(function(i){return t.Xo(i,n.ih)}))},t.prototype.ac=function(t){var n=this,i=this.ih.get(t);return i?Promise.resolve(i.target):this.persistence.runTransaction("Get target data","readonly-idempotent",(function(i){return n.fh.Ze(i,t).next((function(t){return t?t.target:null}))}))},t.prototype.fc=function(){var t=this;return this.persistence.runTransaction("Get new document changes","readonly-idempotent",(function(n){return t.hh.fc(n,t.rh)})).then((function(n){var i=n.lc,e=n.readTime;return t.rh=e,i}))},t.prototype.mh=function(){return e(this,void 0,void 0,(function(){var t,n=this;return r(this,(function(i){switch(i.label){case 0:return t=this,[4,this.persistence.runTransaction("Synchronize last document change read time","readonly-idempotent",(function(t){return n.hh.dc(t)}))];case 1:return t.rh=i.sent(),[2]}}))}))},t.zh=3e8,t}();function me(t){return e(this,void 0,void 0,(function(){return r(this,(function(n){if(t.code!==q.FAILED_PRECONDITION||t.message!==te)throw t;return R(ve,"Unexpectedly lost primary lease"),[2]}))}))}var pe=function(){function t(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];!function(t,n,i,e){if(!(n instanceof Array)||n.length<e)throw new Q(q.INVALID_ARGUMENT,"Function "+t+"() requires its "+i+" argument to be an array with at least "+yt(e,"element")+".")}("FieldPath",t,"fieldNames",1);for(var i=0;i<t.length;++i)if(ut("FieldPath","string",i,t[i]),0===t[i].length)throw new Q(q.INVALID_ARGUMENT,"Invalid field name at argument $(i + 1). Field names must not be empty.");this.vc=new Dt(t)}return t.documentId=function(){return t.wc},t.prototype.isEqual=function(n){if(!(n instanceof t))throw pt("isEqual","FieldPath",1,n);return this.vc.isEqual(n.vc)},t.wc=new t(Dt.lt().ot()),t}(),ge=new RegExp("[~\\*/\\[\\]]");var be,ye,_e=function(){function t(t){this.mc=t}return t.delete=function(){return nt("FieldValue.delete",arguments),Ie.instance},t.serverTimestamp=function(){return nt("FieldValue.serverTimestamp",arguments),Te.instance},t.arrayUnion=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return et("FieldValue.arrayUnion",arguments,1),new Ee(t)},t.arrayRemove=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];return et("FieldValue.arrayRemove",arguments,1),new Re(t)},t.increment=function(t){return ut("FieldValue.increment","number",1,t),it("FieldValue.increment",arguments,1),new Ae(t)},t.prototype.isEqual=function(t){return this===t},t}(),Ie=function(t){function n(){return t.call(this,"FieldValue.delete")||this}return i(n,t),n.instance=new n,n}(_e),Te=function(t){function n(){return t.call(this,"FieldValue.serverTimestamp")||this}return i(n,t),n.instance=new n,n}(_e),Ee=function(t){function n(n){var i=t.call(this,"FieldValue.arrayUnion")||this;return i.pc=n,i}return i(n,t),n}(_e),Re=function(t){function n(n){var i=t.call(this,"FieldValue.arrayRemove")||this;return i.pc=n,i}return i(n,t),n}(_e),Ae=function(t){function n(n){var i=t.call(this,"FieldValue.increment")||this;return i.gc=n,i}return i(n,t),n}(_e),De=Bi(_e,"Use FieldValue.<field>() instead."),Pe=/^__.*__$/,Se=function(){function t(t,n,i){this.data=t,this.mn=n,this.fieldTransforms=i}return t.prototype.bc=function(t,n){var i=[];return null!==this.mn?i.push(new $t(t,this.data,this.mn,n)):i.push(new Xt(t,this.data,n)),this.fieldTransforms.length>0&&i.push(new Zt(t,this.fieldTransforms)),i},t}(),Ce=function(){function t(t,n,i){this.data=t,this.mn=n,this.fieldTransforms=i}return t.prototype.bc=function(t,n){var i=[new $t(t,this.data,this.mn,n)];return this.fieldTransforms.length>0&&i.push(new Zt(t,this.fieldTransforms)),i},t}();function Ve(t){switch(t){case be.Set:case be.yc:case be._c:return!0;case be.Ic:case be.Tc:return!1;default:throw P("Unexpected case for UserDataSource: "+t)}}(ye=be||(be={}))[ye.Set=0]="Set",ye[ye._c=1]="__PRIVATE_Update",ye[ye.yc=2]="__PRIVATE_MergeSet",ye[ye.Ic=3]="__PRIVATE_Argument",ye[ye.Tc=4]="__PRIVATE_ArrayArgument";var ke=function(){function t(t,n,i,e,r,u){this.Ec=t,this.methodName=n,this.path=i,this.Rc=e,void 0===r&&this.Ac(),this.Rc=void 0!==e&&e,this.fieldTransforms=r||[],this.mn=u||[]}return t.prototype.Dc=function(n){var i=null==this.path?null:this.path.child(n),e=new t(this.Ec,this.methodName,i,!1,this.fieldTransforms,this.mn);return e.Pc(n),e},t.prototype.Sc=function(n){var i=null==this.path?null:this.path.child(n),e=new t(this.Ec,this.methodName,i,!1,this.fieldTransforms,this.mn);return e.Ac(),e},t.prototype.Cc=function(n){return new t(this.Ec,this.methodName,null,!0,this.fieldTransforms,this.mn)},t.prototype.Vc=function(t){var n=null===this.path||this.path.nt()?"":" (found in field "+this.path.toString()+")";return new Q(q.INVALID_ARGUMENT,"Function "+this.methodName+"() called with invalid data. "+t+n)},t.prototype.contains=function(t){return void 0!==this.mn.find((function(n){return t.rt(n)}))||void 0!==this.fieldTransforms.find((function(n){return t.rt(n.field)}))},t.prototype.Ac=function(){if(null!==this.path)for(var t=0;t<this.path.length;t++)this.Pc(this.path.get(t))},t.prototype.Pc=function(t){if(0===t.length)throw this.Vc("Document fields must not be empty");if(Ve(this.Ec)&&Pe.test(t))throw this.Vc('Document fields cannot begin and end with "__"')},t}(),Ne=function(t,n){this.s=t,this.key=n},Oe=function(){function t(t){this.kc=t}return t.prototype.Nc=function(t,n){var i=new ke(be.Set,t,Dt.ct);xe("Data must be an object, but it was:",i,n);var e=this.Oc(n,i);return new Se(e,null,i.fieldTransforms)},t.prototype.Fc=function(t,n,i){var e=new ke(be.yc,t,Dt.ct);xe("Data must be an object, but it was:",e,n);var r,u,s=this.Oc(n,e);if(i){for(var o=new Nt(Dt.X),h=0,c=i;h<c.length;h++){var a=c[h],f=void 0;if(a instanceof pe)f=a.vc;else{if("string"!=typeof a)throw P("Expected stringOrFieldPath to be a string or a FieldPath");f=Ue(t,a)}if(!e.contains(f))throw new Q(q.INVALID_ARGUMENT,"Field '"+f+"' is specified in your field mask but missing from your input data.");o=o.add(f)}r=qt.in(o),u=e.fieldTransforms.filter((function(t){return r.rn(t.field)}))}else r=qt.en(e.mn),u=e.fieldTransforms;return new Se(s,r,u)},t.prototype.xc=function(t,n){var i=this,e=new ke(be._c,t,Dt.ct);xe("Data must be an object, but it was:",e,n);var r=new Nt(Dt.X),u=pn.EMPTY;Z(n,(function(n,s){var o=Ue(t,n),h=e.Sc(o);if((s=i.jc(s,h))instanceof Ie)r=r.add(o);else{var c=i.Oc(s,h);null!=c&&(r=r.add(o),u=u.set(o,c))}}));var s=qt.in(r);return new Ce(u,s,e.fieldTransforms)},t.prototype.Uc=function(t,n,i,e){var r=new ke(be._c,t,Dt.ct),u=[je(t,n)],s=[i];if(e.length%2!=0)throw new Q(q.INVALID_ARGUMENT,"Function "+t+"() needs to be called with an even number of arguments that alternate between field names and values.");for(var o=0;o<e.length;o+=2)u.push(je(t,e[o])),s.push(e[o+1]);var h=new Nt(Dt.X),c=pn.EMPTY;for(o=0;o<u.length;++o){var a=u[o],f=r.Sc(a),l=this.jc(s[o],f);if(l instanceof Ie)h=h.add(a);else{var d=this.Oc(l,f);null!=d&&(h=h.add(a),c=c.set(a,d))}}var v=qt.in(h);return new Ce(c,v,r.fieldTransforms)},t.prototype.Lc=function(t,n,i){void 0===i&&(i=!1);var e=new ke(i?be.Tc:be.Ic,t,Dt.ct),r=this.Oc(n,e);return S(null!=r,"Parsed data should not be null."),S(0===e.fieldTransforms.length,"Field transforms should have been disallowed."),r},t.prototype.jc=function(t,n){try{return this.kc(t)}catch(t){var i=Le(t);throw n.Vc(i)}},t.prototype.Oc=function(t,n){if(Fe(t=this.jc(t,n)))return xe("Unsupported field value:",n,t),this.Bc(t,n);if(t instanceof _e)return this.Mc(t,n),null;if(n.path&&n.mn.push(n.path),t instanceof Array){if(n.Rc&&n.Ec!==be.Tc)throw n.Vc("Nested arrays are not supported");return this.qc(t,n)}return this.Qc(t,n)},t.prototype.Bc=function(t,n){var i=this,e=new St(V);return tt(t)?n.path&&n.path.length>0&&n.mn.push(n.path):Z(t,(function(t,r){var u=i.Oc(r,n.Dc(t));null!=u&&(e=e.bt(t,u))})),new pn(e)},t.prototype.qc=function(t,n){for(var i=[],e=0,r=0,u=t;r<u.length;r++){var s=u[r],o=this.Oc(s,n.Cc(e));null==o&&(o=un.Bn),i.push(o),e++}return new gn(i)},t.prototype.Mc=function(t,n){if(!Ve(n.Ec))throw n.Vc(t.mc+"() can only be used with update() and set()");if(null===n.path)throw n.Vc(t.mc+"() is not currently supported inside arrays");if(t instanceof Ie){if(n.Ec!==be.yc)throw n.Ec===be._c?(S(n.path.length>0,"FieldValue.delete() at the top level should have already been handled."),n.Vc("FieldValue.delete() can only appear at the top level of your update data")):n.Vc("FieldValue.delete() cannot be used with set() unless you pass {merge:true}");n.mn.push(n.path)}else if(t instanceof Te)n.fieldTransforms.push(new Qt(n.path,Ft.instance));else if(t instanceof Ee){var i=this.Gc(t.mc,t.pc),e=new xt(i);n.fieldTransforms.push(new Qt(n.path,e))}else if(t instanceof Re){i=this.Gc(t.mc,t.pc);var r=new jt(i);n.fieldTransforms.push(new Qt(n.path,r))}else if(t instanceof Ae){var u=this.Lc("FieldValue.increment",t.gc),s=new Ut(u);n.fieldTransforms.push(new Qt(n.path,s))}else P("Unknown FieldValue type: "+t)},t.prototype.Qc=function(t,n){if(null===t)return un.Bn;if("number"==typeof t)return Pn(t)?new cn(t):new an(t);if("boolean"==typeof t)return sn.of(t);if("string"==typeof t)return new fn(t);if(t instanceof Date)return new ln(It.fromDate(t));if(t instanceof It)return new ln(new It(t.seconds,1e3*Math.floor(t.nanoseconds/1e3)));if(t instanceof _t)return new mn(t);if(t instanceof Wi)return new vn(t);if(t instanceof Ne)return new wn(t.s,t.key);throw n.Vc("Unsupported field value: "+vt(t))},t.prototype.Gc=function(t,n){var i=this;return n.map((function(n,e){var r=new ke(be.Ic,t,Dt.ct);return i.Oc(n,r.Cc(e))}))},t}();function Fe(t){return!("object"!=typeof t||null===t||t instanceof Array||t instanceof Date||t instanceof It||t instanceof _t||t instanceof Wi||t instanceof Ne||t instanceof _e)}function xe(t,n,i){if(!Fe(i)||!dt(i)){var e=vt(i);throw"an object"===e?n.Vc(t+" a custom object"):n.Vc(t+" "+e)}}function je(t,n){if(n instanceof pe)return n.vc;if("string"==typeof n)return Ue(t,n);throw new Q(q.INVALID_ARGUMENT,"Function "+t+"() called with invalid data. Field path arguments must be of type string or FieldPath.")}function Ue(t,i){try{return function(t){if(t.search(ge)>=0)throw new Q(q.INVALID_ARGUMENT,"Invalid field path ("+t+"). Paths must not contain '~', '*', '/', '[', or ']'");try{return new(pe.bind.apply(pe,n([void 0],t.split("."))))}catch(n){throw new Q(q.INVALID_ARGUMENT,"Invalid field path ("+t+"). Paths must not be empty, begin with '.', end with '.', or contain '..'")}}(i).vc}catch(n){var e=Le(n);throw new Q(q.INVALID_ARGUMENT,"Function "+t+"() called with invalid data. "+e)}}function Le(t){return t instanceof Error?t.message:t.toString()}var Be,Me,qe=1e3,Qe=1.5,Ge=6e4,We=function(){function t(t,n,i,e,r){void 0===i&&(i=qe),void 0===e&&(e=Qe),void 0===r&&(r=Ge),this.Wc=t,this.Qs=n,this.zc=i,this.Kc=e,this.Hc=r,this.Jc=0,this.Yc=null,this.Xc=Date.now(),this.reset()}return t.prototype.reset=function(){this.Jc=0},t.prototype.$c=function(){this.Jc=this.Hc},t.prototype.Zc=function(t){var n=this;this.cancel();var i=Math.floor(this.Jc+this.ta()),e=Math.max(0,Date.now()-this.Xc),r=Math.max(0,i-e);this.Jc>0&&R("ExponentialBackoff","Backing off for "+r+" ms (base delay: "+this.Jc+" ms, delay with jitter: "+i+" ms, last attempt: "+e+" ms ago)"),this.Yc=this.Wc.ao(this.Qs,r,(function(){return n.Xc=Date.now(),t()})),this.Jc*=this.Kc,this.Jc<this.zc&&(this.Jc=this.zc),this.Jc>this.Hc&&(this.Jc=this.Hc)},t.prototype.cancel=function(){null!==this.Yc&&(this.Yc.cancel(),this.Yc=null)},t.prototype.ta=function(){return(Math.random()-.5)*this.Jc},t}();(Me=Be||(Be={}))[Me.na=0]="__PRIVATE_Initial",Me[Me.ia=1]="__PRIVATE_Starting",Me[Me.ea=2]="__PRIVATE_Open",Me[Me.Error=3]="Error",Me[Me.ra=4]="__PRIVATE_Backoff";var ze=function(){function t(t,n,i,e,r,u){this.Wc=t,this.ua=i,this.sa=e,this.oa=r,this.listener=u,this.state=Be.na,this.ha=0,this.ca=null,this.stream=null,this.aa=new We(t,n)}return t.prototype.fa=function(){return this.state===Be.ia||this.state===Be.ea||this.state===Be.ra},t.prototype.la=function(){return this.state===Be.ea},t.prototype.start=function(){this.state!==Be.Error?(S(this.state===Be.na,"Already started"),this.auth()):this.da()},t.prototype.stop=function(){return e(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return this.fa()?[4,this.close(Be.na)]:[3,2];case 1:t.sent(),t.label=2;case 2:return[2]}}))}))},t.prototype.va=function(){S(!this.fa(),"Can only inhibit backoff in a stopped state"),this.state=Be.na,this.aa.reset()},t.prototype.wa=function(){var t=this;this.la()&&null===this.ca&&(this.ca=this.Wc.ao(this.ua,6e4,(function(){return t.ma()})))},t.prototype.pa=function(t){this.ga(),this.stream.send(t)},t.prototype.ma=function(){return e(this,void 0,void 0,(function(){return r(this,(function(t){return this.la()?[2,this.close(Be.na)]:[2]}))}))},t.prototype.ga=function(){this.ca&&(this.ca.cancel(),this.ca=null)},t.prototype.close=function(t,n){return e(this,void 0,void 0,(function(){return r(this,(function(i){switch(i.label){case 0:return S(this.fa(),"Only started streams should be closed."),S(t===Be.Error||Dn(n),"Can't provide an error when not in an error state."),this.ga(),this.aa.cancel(),this.ha++,t!==Be.Error?this.aa.reset():n&&n.code===q.RESOURCE_EXHAUSTED?(A(n.toString()),A("Using maximum backoff delay to prevent overloading the backend."),this.aa.$c()):n&&n.code===q.UNAUTHENTICATED&&this.oa.P(),null!==this.stream&&(this.ba(),this.stream.close(),this.stream=null),this.state=t,[4,this.listener.ya(n)];case 1:return i.sent(),[2]}}))}))},t.prototype.ba=function(){},t.prototype.auth=function(){var t=this;S(this.state===Be.na,"Must be in initial state to auth"),this.state=Be.ia;var n=this._a(this.ha),i=this.ha;this.oa.getToken().then((function(n){t.ha===i&&t.Ia(n)}),(function(i){n((function(){var n=new Q(q.UNKNOWN,"Fetching auth token failed: "+i.message);return t.Ta(n)}))}))},t.prototype.Ia=function(t){var n=this;S(this.state===Be.ia,"Trying to start stream in a non-starting state");var i=this._a(this.ha);this.stream=this.Ea(t),this.stream.Ra((function(){i((function(){return S(n.state===Be.ia,"Expected stream to be in state Starting, but was "+n.state),n.state=Be.ea,n.listener.Ra()}))})),this.stream.ya((function(t){i((function(){return n.Ta(t)}))})),this.stream.onMessage((function(t){i((function(){return n.onMessage(t)}))}))},t.prototype.da=function(){var t=this;S(this.state===Be.Error,"Should only perform backoff when in Error state"),this.state=Be.ra,this.aa.Zc((function(){return e(t,void 0,void 0,(function(){return r(this,(function(t){return S(this.state===Be.ra,"Backoff elapsed but state is now: "+this.state),this.state=Be.na,this.start(),S(this.fa(),"PersistentStream should have started"),[2]}))}))}))},t.prototype.Ta=function(t){return S(this.fa(),"Can't handle server close on non-started stream"),R("PersistentStream","close with error: "+t),this.stream=null,this.close(Be.Error,t)},t.prototype._a=function(t){var n=this;return function(i){n.Wc.Xs((function(){return n.ha===t?i():(R("PersistentStream","stream callback skipped by getCloseGuardedDispatcher."),Promise.resolve())}))}},t}(),Ke=function(t){function n(n,i,e,r,u){var s=t.call(this,n,Qi.Fs,Qi.Os,i,e,u)||this;return s.serializer=r,s}return i(n,t),n.prototype.Ea=function(t){return this.sa.Aa("Listen",t)},n.prototype.onMessage=function(t){this.aa.reset();var n=this.serializer.Or(t),i=this.serializer.xr(t);return this.listener.Da(n,i)},n.prototype.Pa=function(t){var n={};n.database=this.serializer.br,n.addTarget=this.serializer.bi(t);var i=this.serializer.eu(t);i&&(n.labels=i),this.pa(n)},n.prototype.Sa=function(t){var n={};n.database=this.serializer.br,n.removeTarget=t,this.pa(n)},n}(ze),He=function(t){function n(n,i,e,r,u){var s=t.call(this,n,Qi.js,Qi.xs,i,e,u)||this;return s.serializer=r,s.Ca=!1,s.lastStreamToken=Li(),s}return i(n,t),Object.defineProperty(n.prototype,"Va",{get:function(){return this.Ca},enumerable:!0,configurable:!0}),n.prototype.start=function(){this.Ca=!1,t.prototype.start.call(this)},n.prototype.ba=function(){this.Ca&&this.ka([])},n.prototype.Ea=function(t){return this.sa.Aa("Write",t)},n.prototype.onMessage=function(t){if(S(!!t.streamToken,"Got a write response without a stream token"),this.lastStreamToken=t.streamToken,this.Ca){this.aa.reset();var n=this.serializer.zr(t.writeResults,t.commitTime),i=this.serializer.fromVersion(t.commitTime);return this.listener.Na(i,n)}return S(!t.writeResults||0===t.writeResults.length,"Got mutation results for handshake"),this.Ca=!0,this.listener.Oa()},n.prototype.Fa=function(){S(this.la(),"Writing handshake requires an opened stream"),S(!this.Ca,"Handshake already completed");var t={};t.database=this.serializer.br,this.pa(t)},n.prototype.ka=function(t){var n=this;S(this.la(),"Writing mutations requires an opened stream"),S(this.Ca,"Handshake must be complete before writing mutations"),S(this.lastStreamToken.length>0,"Trying to write mutation without a token");var i={streamToken:this.lastStreamToken,writes:t.map((function(t){return n.serializer.jr(t)}))};this.pa(i)},n}(ze),Je=function(){function t(t,n,i,e){this.Wc=t,this.sa=n,this.credentials=i,this.serializer=e}return t.prototype.xa=function(t){return new He(this.Wc,this.sa,this.credentials,this.serializer,t)},t.prototype.ja=function(t){return new Ke(this.Wc,this.sa,this.credentials,this.serializer,t)},t.prototype.commit=function(t){var n=this,i={database:this.serializer.br,writes:t.map((function(t){return n.serializer.jr(t)}))};return this.Ua("Commit",i).then((function(t){return n.serializer.zr(t.writeResults,t.commitTime)}))},t.prototype.La=function(t){var n=this,i={database:this.serializer.br,documents:t.map((function(t){return n.serializer.vr(t)}))};return this.Ba("BatchGetDocuments",i).then((function(i){var e=ii();i.forEach((function(t){var i=n.serializer.Vr(t);e=e.bt(i.key,i)}));var r=[];return t.forEach((function(t){var n=e.get(t);S(!!n,"Missing entity in write response for "+t),r.push(n)})),r}))},t.prototype.Ua=function(t,n){var i=this;return this.credentials.getToken().then((function(e){return i.sa.Ua(t,n,e)})).catch((function(t){throw t.code===q.UNAUTHENTICATED&&i.credentials.P(),t}))},t.prototype.Ba=function(t,n){var i=this;return this.credentials.getToken().then((function(e){return i.sa.Ba(t,n,e)})).catch((function(t){throw t.code===q.UNAUTHENTICATED&&i.credentials.P(),t}))},t}(),Ye=function(){function t(t){this.Ma=t,this.qa=oi(),this.mutations=[],this.Qa=!1,this.Ga=null,this.Wa=new Set}return t.prototype.La=function(t){return e(this,void 0,void 0,(function(){var n,i=this;return r(this,(function(e){switch(e.label){case 0:if(this.za(),this.mutations.length>0)throw new Q(q.INVALID_ARGUMENT,"Firestore transactions require all reads to be executed before all writes.");return[4,this.Ma.La(t)];case 1:return(n=e.sent()).forEach((function(t){t instanceof _n||t instanceof yn?i.Ka(t):P("Document in a transaction was a "+t.constructor.name)})),[2,n]}}))}))},t.prototype.set=function(t,n){this.write(n.bc(t,this.dn(t))),this.Wa.add(t)},t.prototype.update=function(t,n){try{this.write(n.bc(t,this.Ha(t)))}catch(t){this.Ga=t}this.Wa.add(t)},t.prototype.delete=function(t){this.write([new tn(t,this.dn(t))]),this.Wa.add(t)},t.prototype.commit=function(){return e(this,void 0,void 0,(function(){var t,n=this;return r(this,(function(i){switch(i.label){case 0:if(this.za(),this.Ga)throw this.Ga;return t=this.qa,this.mutations.forEach((function(n){t=t.remove(n.key)})),t.forEach((function(t,i){n.mutations.push(new nn(t,n.dn(t)))})),[4,this.Ma.commit(this.mutations)];case 1:return i.sent(),this.Qa=!0,[2]}}))}))},t.prototype.Ka=function(t){var n;if(t instanceof yn)n=t.version;else{if(!(t instanceof _n))throw P("Document in a transaction was a "+t.constructor.name);n=Tt.K()}var i=this.qa.get(t.key);if(null!==i){if(!n.isEqual(i))throw new Q(q.ABORTED,"Document version changed between two reads.")}else this.qa=this.qa.bt(t.key,n)},t.prototype.dn=function(t){var n=this.qa.get(t);return!this.Wa.has(t)&&n?Jt.updateTime(n):Jt.NONE},t.prototype.Ha=function(t){var n=this.qa.get(t);if(!this.Wa.has(t)&&n){if(n.isEqual(Tt.K()))throw new Q(q.INVALID_ARGUMENT,"Can't update a document that doesn't exist.");return Jt.updateTime(n)}return Jt.exists(!0)},t.prototype.write=function(t){this.za(),this.mutations=this.mutations.concat(t)},t.prototype.za=function(){S(!this.Qa,"A transaction object cannot be used after its update callback has been invoked.")},t}(),Xe=function(){function t(t,n){this.qs=t,this.Ja=n,this.state=O.l,this.Ya=0,this.Xa=null,this.$a=!0}return t.prototype.Za=function(){var t=this;0===this.Ya&&(this.tf(O.l),S(null===this.Xa,"onlineStateTimer shouldn't be started yet"),this.Xa=this.qs.ao(Qi.Us,1e4,(function(){return t.Xa=null,S(t.state===O.l,"Timer should be canceled if we transitioned to a different state."),t.nf("Backend didn't respond within 10 seconds."),t.tf(O.m),Promise.resolve()})))},t.prototype.if=function(t){this.state===O.v?(this.tf(O.l),S(0===this.Ya,"watchStreamFailures must be 0"),S(null===this.Xa,"onlineStateTimer must be null")):(this.Ya++,this.Ya>=1&&(this.ef(),this.nf("Connection failed 1 times. Most recent error: "+t.toString()),this.tf(O.m)))},t.prototype.set=function(t){this.ef(),this.Ya=0,t===O.v&&(this.$a=!1),this.tf(t)},t.prototype.tf=function(t){t!==this.state&&(this.state=t,this.Ja(t))},t.prototype.nf=function(t){var n="Could not reach Cloud Firestore backend. "+t+"\nThis typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.";this.$a?(A(n),this.$a=!1):R("OnlineStateTracker",n)},t.prototype.ef=function(){null!==this.Xa&&(this.Xa.cancel(),this.Xa=null)},t}(),$e="RemoteStore",Ze=function(){function t(t,n,i,u,s){var o=this;this.jo=t,this.Ma=n,this.rf=[],this.uf={},this.sf=null,this.networkEnabled=!1,this.isPrimary=!1,this.hf=s,this.hf.cf((function(t){i.Xs((function(){return e(o,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return this.af()?(R($e,"Restarting streams for network reachability change."),[4,this.ff()]):[3,2];case 1:t.sent(),t.label=2;case 2:return[2]}}))}))}))})),this.lf=new Xe(i,u),this.df=this.Ma.ja({Ra:this.vf.bind(this),ya:this.wf.bind(this),Da:this.mf.bind(this)}),this.pf=this.Ma.xa({Ra:this.gf.bind(this),ya:this.bf.bind(this),Oa:this.yf.bind(this),Na:this.Na.bind(this)})}return t.prototype.start=function(){return this.enableNetwork()},t.prototype.enableNetwork=function(){return e(this,void 0,void 0,(function(){var t;return r(this,(function(n){switch(n.label){case 0:return this.networkEnabled=!0,this.af()?(t=this.pf,[4,this.jo.Fh()]):[3,3];case 1:return t.lastStreamToken=n.sent(),this._f()?this.If():this.lf.set(O.l),[4,this.Tf()];case 2:n.sent(),n.label=3;case 3:return[2]}}))}))},t.prototype.disableNetwork=function(){return e(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return this.networkEnabled=!1,[4,this.Ef()];case 1:return t.sent(),this.lf.set(O.m),[2]}}))}))},t.prototype.Ef=function(){return e(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,this.pf.stop()];case 1:return t.sent(),[4,this.df.stop()];case 2:return t.sent(),this.rf.length>0&&(R($e,"Stopping write stream with "+this.rf.length+" pending writes"),this.rf=[]),this.Rf(),[2]}}))}))},t.prototype.Af=function(){return e(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return R($e,"RemoteStore shutting down."),this.networkEnabled=!1,[4,this.Ef()];case 1:return t.sent(),this.hf.Af(),this.lf.set(O.l),[2]}}))}))},t.prototype.listen=function(t){Y(this.uf,t.targetId)||(this.uf[t.targetId]=t,this._f()?this.If():this.df.la()&&this.Df(t))},t.prototype.Pf=function(t){S(Y(this.uf,t),"unlisten called on target no currently watched: "+t),delete this.uf[t],this.df.la()&&this.Sf(t),tt(this.uf)&&(this.df.la()?this.df.wa():this.af()&&this.lf.set(O.l))},t.prototype.Ze=function(t){return this.uf[t]||null},t.prototype.$e=function(t){return this.Cf.$e(t)},t.prototype.Df=function(t){this.sf.Ce(t.targetId),this.df.Pa(t)},t.prototype.Sf=function(t){this.sf.Ce(t),this.df.Sa(t)},t.prototype.If=function(){S(this._f(),"startWatchStream() called when shouldStartWatchStream() is false."),this.sf=new Di(this),this.df.start(),this.lf.Za()},t.prototype._f=function(){return this.af()&&!this.df.fa()&&!tt(this.uf)},t.prototype.af=function(){return this.isPrimary&&this.networkEnabled},t.prototype.Rf=function(){this.sf=null},t.prototype.vf=function(){return e(this,void 0,void 0,(function(){var t=this;return r(this,(function(n){return $(this.uf,(function(n,i){t.Df(i)})),[2]}))}))},t.prototype.wf=function(t){return e(this,void 0,void 0,(function(){return r(this,(function(n){return void 0===t&&S(!this._f(),"Watch stream was stopped gracefully while still needed."),this.Rf(),this._f()?(this.lf.if(t),this.If()):this.lf.set(O.l),[2]}))}))},t.prototype.mf=function(t,n){return e(this,void 0,void 0,(function(){var i;return r(this,(function(e){switch(e.label){case 0:return this.lf.set(O.v),t instanceof Ri&&t.state===pi.Gi&&t.cause?[2,this.Vf(t)]:(t instanceof Ti?this.sf.Ue(t):t instanceof Ei?this.sf.ze(t):(S(t instanceof Ri,"Expected watchChange to be an instance of WatchTargetChange"),this.sf.Me(t)),n.isEqual(Tt.MIN)?[3,3]:[4,this.jo.jh()]);case 1:return i=e.sent(),n.h(i)>=0?[4,this.kf(n)]:[3,3];case 2:e.sent(),e.label=3;case 3:return[2]}}))}))},t.prototype.kf=function(t){var n=this;S(!t.isEqual(Tt.MIN),"Can't raise event for unknown SnapshotVersion");var i=this.sf.Je(t);return $(i.ie,(function(i,e){if(e.resumeToken.length>0){var r=n.uf[i];r&&(n.uf[i]=r.Ui(e.resumeToken,t))}})),i.ee.forEach((function(t){var i=n.uf[t];if(i){n.uf[t]=i.Ui(Li(),i.xi),n.Sf(t);var e=new Yn(i.target,t,kn.Ni,i.sequenceNumber);n.Df(e)}})),this.Cf.Uh(i)},t.prototype.Vf=function(t){var n=this;S(!!t.cause,"Handling target error without a cause");var i=t.cause,u=Promise.resolve();return t.targetIds.forEach((function(t){u=u.then((function(){return e(n,void 0,void 0,(function(){return r(this,(function(n){return Y(this.uf,t)?(delete this.uf[t],this.sf.removeTarget(t),[2,this.Cf.Nf(t,i)]):[2]}))}))}))})),u},t.prototype.Tf=function(){return e(this,void 0,void 0,(function(){var t,n;return r(this,(function(i){switch(i.label){case 0:return this.Of()?(t=this.rf.length>0?this.rf[this.rf.length-1].batchId:-1,[4,this.jo.Hh(t)]):[3,4];case 1:return null!==(n=i.sent())?[3,2]:(0===this.rf.length&&this.pf.wa(),[3,4]);case 2:return this.Ff(n),[4,this.Tf()];case 3:i.sent(),i.label=4;case 4:return this.xf()&&this.jf(),[2]}}))}))},t.prototype.Of=function(){return this.af()&&this.rf.length<10},t.prototype.Uf=function(){return this.rf.length},t.prototype.Ff=function(t){S(this.Of(),"addToWritePipeline called when pipeline is full"),this.rf.push(t),this.pf.la()&&this.pf.Va&&this.pf.ka(t.mutations)},t.prototype.xf=function(){return this.af()&&!this.pf.fa()&&this.rf.length>0},t.prototype.jf=function(){S(this.xf(),"startWriteStream() called when shouldStartWriteStream() is false."),this.pf.start()},t.prototype.gf=function(){return e(this,void 0,void 0,(function(){return r(this,(function(t){return this.pf.Fa(),[2]}))}))},t.prototype.yf=function(){var t=this;return this.jo.xh(this.pf.lastStreamToken).then((function(){for(var n=0,i=t.rf;n<i.length;n++){var e=i[n];t.pf.ka(e.mutations)}})).catch(me)},t.prototype.Na=function(t,n){var i=this;S(this.rf.length>0,"Got result for empty write pipeline");var e=this.rf.shift(),r=Ji.from(e,t,n,this.pf.lastStreamToken);return this.Cf.Lf(r).then((function(){return i.Tf()}))},t.prototype.bf=function(t){return e(this,void 0,void 0,(function(){var n=this;return r(this,(function(i){return void 0===t&&S(!this.xf(),"Write stream was stopped gracefully while still needed."),t&&this.rf.length>0?(void 0,[2,(this.pf.Va?this.Bf(t):this.Mf(t)).then((function(){n.xf()&&n.jf()}))]):[2]}))}))},t.prototype.Mf=function(t){return e(this,void 0,void 0,(function(){return r(this,(function(n){return $n(t.code)?(R($e,"RemoteStore error before completed handshake; resetting stream token: ",this.pf.lastStreamToken),this.pf.lastStreamToken=Li(),[2,this.jo.xh(Li()).catch(me)]):[2]}))}))},t.prototype.Bf=function(t){return e(this,void 0,void 0,(function(){var n,i=this;return r(this,(function(e){return $n(r=t.code)&&r!==q.ABORTED?(n=this.rf.shift(),this.pf.va(),[2,this.Cf.qf(n.batchId,t).then((function(){return i.Tf()}))]):[2];var r}))}))},t.prototype.Qf=function(){return new Ye(this.Ma)},t.prototype.ff=function(){return e(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return this.networkEnabled=!1,[4,this.Ef()];case 1:return t.sent(),this.lf.set(O.l),[4,this.enableNetwork()];case 2:return t.sent(),[2]}}))}))},t.prototype.Gf=function(){return e(this,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return this.af()?(R($e,"RemoteStore restarting streams for new credential"),[4,this.ff()]):[3,2];case 1:t.sent(),t.label=2;case 2:return[2]}}))}))},t.prototype.Wf=function(t){return e(this,void 0,void 0,(function(){return r(this,(function(n){switch(n.label){case 0:return this.isPrimary=t,t&&this.networkEnabled?[4,this.enableNetwork()]:[3,2];case 1:return n.sent(),[3,4];case 2:return t?[3,4]:[4,this.Ef()];case 3:n.sent(),this.lf.set(O.l),n.label=4;case 4:return[2]}}))}))},t}(),tr="firestore_clients";function nr(t,n){return S(-1===n.indexOf("_"),"Client key cannot contain '_', but was '"+n+"'"),tr+"_"+t+"_"+n}var ir="firestore_mutations";function er(t,n,i){var e=ir+"_"+t+"_"+i;return n._()&&(e+="_"+n.uid),e}var rr="firestore_targets";function ur(t,n){return rr+"_"+t+"_"+n}var sr="firestore_online_state";var or="firestore_sequence_number";var hr="SharedClientState",cr=function(){function t(t,n,i,e){this.user=t,this.batchId=n,this.state=i,this.error=e,S(void 0!==e==("rejected"===i),"MutationMetadata must contain an error iff state is 'rejected'")}return t.zf=function(n,i,e){var r=JSON.parse(e),u="object"==typeof r&&-1!==["pending","acknowledged","rejected"].indexOf(r.state)&&(void 0===r.error||"object"==typeof r.error),s=void 0;return u&&r.error&&(u="string"==typeof r.error.message&&"string"==typeof r.error.code)&&(s=new Q(r.error.code,r.error.message)),u?new t(n,i,r.state,s):(A(hr,"Failed to parse mutation state for ID '"+i+"': "+e),null)},t.prototype.Kf=function(){var t={state:this.state,updateTimeMs:Date.now()};return this.error&&(t.error={code:this.error.code,message:this.error.message}),JSON.stringify(t)},t}(),ar=function(){function t(t,n,i){this.targetId=t,this.state=n,this.error=i,S(void 0!==i==("rejected"===n),"QueryTargetMetadata must contain an error iff state is 'rejected'")}return t.zf=function(n,i){var e=JSON.parse(i),r="object"==typeof e&&-1!==["not-current","current","rejected"].indexOf(e.state)&&(void 0===e.error||"object"==typeof e.error),u=void 0;return r&&e.error&&(r="string"==typeof e.error.message&&"string"==typeof e.error.code)&&(u=new Q(e.error.code,e.error.message)),r?new t(n,e.state,u):(A(hr,"Failed to parse target state for ID '"+n+"': "+i),null)},t.prototype.Kf=function(){var t={state:this.state,updateTimeMs:Date.now()};return this.error&&(t.error={code:this.error.code,message:this.error.message}),JSON.stringify(t)},t}(),fr=function(){function t(t,n){this.clientId=t,this.activeTargetIds=n}return t.zf=function(n,i){for(var e=JSON.parse(i),r="object"==typeof e&&e.activeTargetIds instanceof Array,u=fi(),s=0;r&&s<e.activeTargetIds.length;++s)r=Pn(e.activeTargetIds[s]),u=u.add(e.activeTargetIds[s]);return r?new t(n,u):(A(hr,"Failed to parse client data for instance '"+n+"': "+i),null)},t}(),lr=function(){function t(t,n){this.clientId=t,this.onlineState=n}return t.zf=function(n){var i=JSON.parse(n);return"object"==typeof i&&i.onlineState in O&&"string"==typeof i.clientId?new t(i.clientId,O[i.onlineState]):(A(hr,"Failed to parse online state: "+n),null)},t}(),dr=function(){function t(){this.activeTargetIds=fi()}return t.prototype.Hf=function(t){this.activeTargetIds=this.activeTargetIds.add(t)},t.prototype.Jf=function(t){this.activeTargetIds=this.activeTargetIds.delete(t)},t.prototype.Kf=function(){var t={activeTargetIds:this.activeTargetIds.st(),updateTimeMs:Date.now()};return JSON.stringify(t)},t}(),vr=function(){function t(n,i,e,r,u){if(this.Wc=n,this.platform=i,this.persistenceKey=e,this.Yf=r,this.Cf=null,this.Ja=null,this.Ps=null,this.Xf={},this.$f=this.Zf.bind(this),this.qo=!1,this.tl=[],!t.nl(this.platform))throw new Q(q.UNIMPLEMENTED,"LocalStorage is not available on this platform.");var s=e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");this.storage=this.platform.window.localStorage,this.currentUser=u,this.il=nr(this.persistenceKey,this.Yf),this.el=function(t){return or+"_"+t}(this.persistenceKey),this.Xf[this.Yf]=new dr,this.rl=new RegExp("^"+tr+"_"+s+"_([^_]*)$"),this.ul=new RegExp("^"+ir+"_"+s+"_(\\d+)(?:_(.*))?$"),this.sl=new RegExp("^"+rr+"_"+s+"_(\\d+)$"),this.ol=function(t){return sr+"_"+t}(this.persistenceKey),this.platform.window.addEventListener("storage",this.$f)}return t.nl=function(t){return!(!t.window||null==t.window.localStorage)},t.prototype.start=function(){return e(this,void 0,void 0,(function(){var t,n,i,e,u,s,o,h,c,a,f,l=this;return r(this,(function(r){switch(r.label){case 0:return S(!this.qo,"WebStorageSharedClientState already started"),S(null!==this.Cf,"syncEngine property must be set before calling start()"),S(null!==this.Ja,"onlineStateHandler property must be set before calling start()"),[4,this.Cf.sc()];case 1:for(t=r.sent(),n=0,i=t;n<i.length;n++)(e=i[n])!==this.Yf&&(u=this.getItem(nr(this.persistenceKey,e)))&&(s=fr.zf(e,u))&&(this.Xf[s.clientId]=s);for(this.hl(),(o=this.storage.getItem(this.ol))&&(h=this.cl(o))&&this.al(h),c=0,a=this.tl;c<a.length;c++)f=a[c],this.Zf(f);return this.tl=[],this.platform.window.addEventListener("unload",(function(){return l.Af()})),this.qo=!0,[2]}}))}))},t.prototype.Vs=function(t){this.setItem(this.el,JSON.stringify(t))},t.prototype.fl=function(){var t=fi();return Z(this.Xf,(function(n,i){t=t.Jt(i.activeTargetIds)})),t},t.prototype.ll=function(t){for(var n in this.Xf)if(this.Xf.hasOwnProperty(n)&&this.Xf[n].activeTargetIds.has(t))return!0;return!1},t.prototype.dl=function(t){this.vl(t,"pending")},t.prototype.wl=function(t,n,i){this.vl(t,n,i),this.ml(t)},t.prototype.pl=function(t){var n="not-current";if(this.ll(t)){var i=this.storage.getItem(ur(this.persistenceKey,t));if(i){var e=ar.zf(t,i);e&&(n=e.state)}}return this.gl.Hf(t),this.hl(),n},t.prototype.bl=function(t){this.gl.Jf(t),this.hl()},t.prototype.yl=function(t){return this.gl.activeTargetIds.has(t)},t.prototype._l=function(t){this.removeItem(ur(this.persistenceKey,t))},t.prototype.Il=function(t,n,i){this.Tl(t,n,i)},t.prototype.ph=function(t,n,i){var e=this;n.forEach((function(t){e.ml(t)})),this.currentUser=t,i.forEach((function(t){e.dl(t)}))},t.prototype.El=function(t){this.Rl(t)},t.prototype.Af=function(){this.qo&&(this.platform.window.removeEventListener("storage",this.$f),this.removeItem(this.il),this.qo=!1)},t.prototype.getItem=function(t){var n=this.storage.getItem(t);return R(hr,"READ",t,n),n},t.prototype.setItem=function(t,n){R(hr,"SET",t,n),this.storage.setItem(t,n)},t.prototype.removeItem=function(t){R(hr,"REMOVE",t),this.storage.removeItem(t)},t.prototype.Zf=function(t){var n=this;if(t.storageArea===this.storage){if(R(hr,"EVENT",t.key,t.newValue),t.key===this.il)return void A("Received WebStorage notification for local change. Another client might have garbage-collected our state");this.Wc.Xs((function(){return e(n,void 0,void 0,(function(){var n,i,e,u,s,o;return r(this,(function(r){if(!this.qo)return this.tl.push(t),[2];if(null===t.key)return[2];if(this.rl.test(t.key)){if(null==t.newValue)return i=this.Al(t.key),[2,this.Dl(i,null)];if(n=this.Pl(t.key,t.newValue))return[2,this.Dl(n.clientId,n)]}else if(this.ul.test(t.key)){if(null!==t.newValue&&(e=this.Sl(t.key,t.newValue)))return[2,this.Cl(e)]}else if(this.sl.test(t.key)){if(null!==t.newValue&&(u=this.Vl(t.key,t.newValue)))return[2,this.kl(u)]}else if(t.key===this.ol){if(null!==t.newValue&&(s=this.cl(t.newValue)))return[2,this.al(s)]}else t.key===this.el&&(S(!!this.Ps,"Missing sequenceNumberHandler"),(o=function(t){var n=re.ks;if(null!=t)try{var i=JSON.parse(t);S("number"==typeof i,"Found non-numeric sequence number"),n=i}catch(t){A(hr,"Failed to read sequence number from WebStorage",t)}return n}(t.newValue))!==re.ks&&this.Ps(o));return[2]}))}))}))}},Object.defineProperty(t.prototype,"gl",{get:function(){return this.Xf[this.Yf]},enumerable:!0,configurable:!0}),t.prototype.hl=function(){this.setItem(this.il,this.gl.Kf())},t.prototype.vl=function(t,n,i){var e=new cr(this.currentUser,t,n,i),r=er(this.persistenceKey,this.currentUser,t);this.setItem(r,e.Kf())},t.prototype.ml=function(t){var n=er(this.persistenceKey,this.currentUser,t);this.removeItem(n)},t.prototype.Rl=function(t){var n={clientId:this.Yf,onlineState:O[t]};this.storage.setItem(this.ol,JSON.stringify(n))},t.prototype.Tl=function(t,n,i){var e=ur(this.persistenceKey,t),r=new ar(t,n,i);this.setItem(e,r.Kf())},t.prototype.Al=function(t){var n=this.rl.exec(t);return n?n[1]:null},t.prototype.Pl=function(t,n){var i=this.Al(t);return S(null!==i,"Cannot parse client state key '"+t+"'"),fr.zf(i,n)},t.prototype.Sl=function(t,n){var i=this.ul.exec(t);S(null!==i,"Cannot parse mutation batch key '"+t+"'");var e=Number(i[1]),r=void 0!==i[2]?i[2]:null;return cr.zf(new M(r),e,n)},t.prototype.Vl=function(t,n){var i=this.sl.exec(t);S(null!==i,"Cannot parse query target key '"+t+"'");var e=Number(i[1]);return ar.zf(e,n)},t.prototype.cl=function(t){return lr.zf(t)},t.prototype.Cl=function(t){return e(this,void 0,void 0,(function(){return r(this,(function(n){return t.user.uid!==this.currentUser.uid?(R(hr,"Ignoring mutation for non-active user "+t.user.uid),[2]):[2,this.Cf.Nl(t.batchId,t.state,t.error)]}))}))},t.prototype.kl=function(t){return this.Cf.Ol(t.targetId,t.state,t.error)},t.prototype.Dl=function(t,n){var i=this,u=this.fl();n?this.Xf[t]=n:delete this.Xf[t];var s=this.fl(),o=[],h=[];return s.forEach((function(t){return e(i,void 0,void 0,(function(){return r(this,(function(n){return u.has(t)||o.push(t),[2]}))}))})),u.forEach((function(t){return e(i,void 0,void 0,(function(){return r(this,(function(n){return s.has(t)||h.push(t),[2]}))}))})),this.Cf.Fl(o,h)},t.prototype.al=function(t){this.Xf[t.clientId]&&this.Ja(t.onlineState)},t}();var wr,mr,pr=function(){function t(){this.xl=new dr,this.jl={},this.Cf=null,this.Ja=null,this.Ps=null}return t.prototype.dl=function(t){},t.prototype.wl=function(t,n,i){},t.prototype.pl=function(t){return this.xl.Hf(t),this.jl[t]||"not-current"},t.prototype.Il=function(t,n,i){this.jl[t]=n},t.prototype.bl=function(t){this.xl.Jf(t)},t.prototype.yl=function(t){return this.xl.activeTargetIds.has(t)},t.prototype._l=function(t){delete this.jl[t]},t.prototype.fl=function(){return this.xl.activeTargetIds},t.prototype.ll=function(t){return this.xl.activeTargetIds.has(t)},t.prototype.start=function(){return this.xl=new dr,Promise.resolve()},t.prototype.ph=function(t,n,i){},t.prototype.El=function(t){},t.prototype.Af=function(){},t.prototype.Vs=function(t){},t}(),gr=1;(mr=wr||(wr={}))[mr.Ul=0]="__PRIVATE_QueryCache",mr[mr.Ll=1]="__PRIVATE_SyncEngine";var br=function(){function t(t,n){this.Bl=t,S((t&gr)===t,"Generator ID "+t+" contains more than "+gr+" reserved bits"),this.Ml(void 0!==n?n:this.Bl)}return t.prototype.next=function(){var t=this.ql;return this.ql+=1<<gr,t},t.prototype.after=function(t){return this.Ml(t+(1<<gr)),this.next()},t.prototype.Ml=function(t){S((t&gr)===this.Bl,"Cannot supply target ID from different generator ID"),this.ql=t},t.Ql=function(){return new t(wr.Ul,2)},t.Gl=function(){return new t(wr.Ll)},t}(),yr=function(t){this.key=t},_r=function(t){this.key=t},Ir=function(){function t(t,n){this.query=t,this.Wl=n,this.zl=null,this.he=!1,this.Kl=ci(),this.$i=ci(),this.Hl=new mi(t.yi.bind(t))}return Object.defineProperty(t.prototype,"Jl",{get:function(){return this.Wl},enumerable:!0,configurable:!0}),t.prototype.Yl=function(t,n){var i=this,e=n?n.Xl:new bi,r=n?n.Hl:this.Hl,u=n?n.$i:this.$i,s=r,o=!1,h=this.query.Ri()&&r.size===this.query.limit?r.last():null,c=this.query.Ai()&&r.size===this.query.limit?r.first():null;if(t.Et((function(t,n){var a=r.get(t),f=n instanceof yn?n:null;f&&(S(t.isEqual(f.key),"Mismatching keys found in document changes: "+t+" != "+f.key),f=i.query.matches(f)?f:null);var l=!!a&&i.$i.has(a.key),d=!!f&&(f.vn||i.$i.has(f.key)&&f.hasCommittedMutations),v=!1;a&&f?a.data().isEqual(f.data())?l!==d&&(e.track({type:li.zi,doc:f}),v=!0):i.$l(a,f)||(e.track({type:li.Wi,doc:f}),v=!0,(h&&i.query.yi(f,h)>0||c&&i.query.yi(f,c)<0)&&(o=!0)):!a&&f?(e.track({type:li.Qi,doc:f}),v=!0):a&&!f&&(e.track({type:li.Gi,doc:a}),v=!0,(h||c)&&(o=!0));v&&(f?(s=s.add(f),u=d?u.add(t):u.delete(t)):(s=s.delete(t),u=u.delete(t)))})),this.query.Ri()||this.query.Ai())for(;s.size>this.query.limit;){var a=this.query.Ri()?s.last():s.first();s=s.delete(a.key),u=u.delete(a.key),e.track({type:li.Gi,doc:a})}return S(!o||!n,"View was refilled using docs that themselves needed refilling."),{Hl:s,Xl:e,Zl:o,$i:u}},t.prototype.$l=function(t,n){return t.vn&&n.hasCommittedMutations&&!n.vn},t.prototype.rs=function(t,n,i){var e=this;S(!t.Zl,"Cannot apply changes that need a refill");var r=this.Hl;this.Hl=t.Hl,this.$i=t.$i;var u=t.Xl.Yi();u.sort((function(t,n){return function(t,n){var i=function(t){switch(t){case li.Qi:return 1;case li.Wi:case li.zi:return 2;case li.Gi:return 0;default:return P("Unknown ChangeType: "+t)}};return i(t)-i(n)}(t.type,n.type)||e.query.yi(t.doc,n.doc)})),this.td(i);var s=n?this.nd():[],o=0===this.Kl.size&&this.he?vi.Hi:vi.Ki,h=o!==this.zl;return this.zl=o,0!==u.length||h?{snapshot:new yi(this.query,t.Hl,r,u,t.$i,o===vi.Ki,h,!1),ed:s}:{ed:s}},t.prototype.rd=function(t){return this.he&&t===O.m?(this.he=!1,this.rs({Hl:this.Hl,Xl:new bi,$i:this.$i,Zl:!1},!1)):{ed:[]}},t.prototype.ud=function(t){return!this.Wl.has(t)&&(!!this.Hl.has(t)&&!this.Hl.get(t).vn)},t.prototype.td=function(t){var n=this;t&&(t.ce.forEach((function(t){return n.Wl=n.Wl.add(t)})),t.ae.forEach((function(t){return S(n.Wl.has(t),"Modified document "+t+" not found in view.")})),t.fe.forEach((function(t){return n.Wl=n.Wl.delete(t)})),this.he=t.he)},t.prototype.nd=function(){var t=this;if(!this.he)return[];var n=this.Kl;this.Kl=ci(),this.Hl.forEach((function(n){t.ud(n.key)&&(t.Kl=t.Kl.add(n.key))}));var i=[];return n.forEach((function(n){t.Kl.has(n)||i.push(new _r(n))})),this.Kl.forEach((function(t){n.has(t)||i.push(new yr(t))})),i},t.prototype.sd=function(t){this.Wl=t.rc,this.Kl=ci();var n=this.Yl(t.documents);return this.rs(n,!0)},t.prototype.od=function(){return yi.ne(this.query,this.Hl,this.$i,this.zl===vi.Ki)},t}();var Tr=5,Er=function(){function t(t,n,i,e){this.qs=t,this.hd=n,this.updateFunction=i,this.zs=e,this.ad=Tr,this.aa=new We(this.qs,Qi.Ms)}return t.prototype.fd=function(){this.ld()},t.prototype.ld=function(){var t=this;this.aa.Zc((function(){return e(t,void 0,void 0,(function(){var t,n,i=this;return r(this,(function(e){return t=this.hd.Qf(),(n=this.dd(t))&&n.then((function(n){i.qs.Xs((function(){return t.commit().then((function(){i.zs.resolve(n)})).catch((function(t){i.vd(t)}))}))})).catch((function(t){i.vd(t)})),[2]}))}))}))},t.prototype.dd=function(t){try{var n=this.updateFunction(t);return!Dn(n)&&n.catch&&n.then?n:(this.zs.reject(Error("Transaction callback must return a Promise")),null)}catch(t){return this.zs.reject(t),null}},t.prototype.vd=function(t){var n=this;this.ad>0&&this.wd(t)?(this.ad-=1,this.qs.Xs((function(){return n.ld(),Promise.resolve()}))):this.zs.reject(t)},t.prototype.wd=function(t){if("FirebaseError"===t.name){var n=t.code;return"aborted"===n||"failed-precondition"===n||!$n(n)}return!1},t}(),Rr=function(t,n,i){this.query=t,this.targetId=n,this.view=i},Ar=function(t){this.key=t,this.md=!1},Dr=function(){function t(t,n,i,e){this.jo=t,this.hd=n,this.pd=i,this.currentUser=e,this.gd=null,this.bd=new Ki((function(t){return t.canonicalId()})),this.yd={},this._d=new St(Pt.X),this.Id={},this.Td=new Yi,this.Ed={},this.Rd=new Map,this.Ad=br.Gl(),this.isPrimary=void 0,this.onlineState=O.l}return Object.defineProperty(t.prototype,"Dd",{get:function(){return!0===this.isPrimary},enumerable:!0,configurable:!0}),t.prototype.subscribe=function(t){S(null!==t,"SyncEngine listener cannot be null"),S(null===this.gd,"SyncEngine already has a subscriber."),this.gd=t},t.prototype.listen=function(t){return e(this,void 0,void 0,(function(){var n,i,e,u,s;return r(this,(function(r){switch(r.label){case 0:return this.Pd("listen()"),(e=this.bd.get(t))?(n=e.targetId,this.pd.pl(n),i=e.view.od(),[3,4]):[3,1];case 1:return[4,this.jo.Xh(t.bi())];case 2:return u=r.sent(),s=this.pd.pl(u.targetId),n=u.targetId,[4,this.Sd(t,n,"current"===s)];case 3:i=r.sent(),this.isPrimary&&this.hd.listen(u),r.label=4;case 4:return this.gd.Da([i]),[2,n]}}))}))},t.prototype.Sd=function(t,n,i){return e(this,void 0,void 0,(function(){var e,u,s,o,h,c;return r(this,(function(r){switch(r.label){case 0:return[4,this.jo.ic(t,!0)];case 1:return e=r.sent(),u=new Ir(t,e.rc),s=u.Yl(e.documents),o=Ii.oe(n,i&&this.onlineState!==O.m),S(0===(h=u.rs(s,!0===this.isPrimary,o)).ed.length,"View returned limbo docs before target ack from the server."),S(!!h.snapshot,"applyChanges for new view should always return a snapshot"),c=new Rr(t,n,u),this.bd.set(t,c),this.yd[n]||(this.yd[n]=[]),this.yd[n].push(t),[2,h.snapshot]}}))}))},t.prototype.Cd=function(t){return e(this,void 0,void 0,(function(){var n,i;return r(this,(function(e){switch(e.label){case 0:return[4,this.jo.ic(t.query,!0)];case 1:return n=e.sent(),i=t.view.sd(n),this.isPrimary&&this.Vd(t.targetId,i.ed),[2,i]}}))}))},t.prototype.Pf=function(t){return e(this,void 0,void 0,(function(){var n,i,e=this;return r(this,(function(r){switch(r.label){case 0:return this.Pd("unlisten()"),S(!!(n=this.bd.get(t)),"Trying to unlisten on query not found:"+t),(i=this.yd[n.targetId]).length>1?(this.yd[n.targetId]=i.filter((function(n){return!n.isEqual(t)})),this.bd.delete(t),[2]):this.isPrimary?(this.pd.bl(n.targetId),this.pd.ll(n.targetId)?[3,2]:[4,this.jo.nc(n.targetId,!1).then((function(){e.pd._l(n.targetId),e.hd.Pf(n.targetId),e.kd(n.targetId)})).catch(me)]):[3,3];case 1:r.sent(),r.label=2;case 2:return[3,5];case 3:return this.kd(n.targetId),[4,this.jo.nc(n.targetId,!0)];case 4:r.sent(),r.label=5;case 5:return[2]}}))}))},t.prototype.write=function(t,n){return e(this,void 0,void 0,(function(){var i;return r(this,(function(e){switch(e.label){case 0:return this.Pd("write()"),[4,this.jo.Ih(t)];case 1:return i=e.sent(),this.pd.dl(i.batchId),this.Nd(i.batchId,n),[4,this.Od(i.Hu)];case 2:return e.sent(),[4,this.hd.Tf()];case 3:return e.sent(),[2]}}))}))},t.prototype.runTransaction=function(t,n,i){new Er(t,this.hd,n,i).fd()},t.prototype.Uh=function(t){return e(this,void 0,void 0,(function(){var n,i=this;return r(this,(function(e){switch(e.label){case 0:this.Pd("applyRemoteEvent()"),e.label=1;case 1:return e.trys.push([1,4,,6]),[4,this.jo.Uh(t)];case 2:return n=e.sent(),Z(t.ie,(function(t,n){var e=i.Id[Number(t)];e&&(S(n.ce.size+n.ae.size+n.fe.size<=1,"Limbo resolution for single document contains multiple changes."),n.ce.size>0?e.md=!0:n.ae.size>0?S(e.md,"Received change for limbo target document without add."):n.fe.size>0&&(S(e.md,"Received remove for limbo target document without add."),e.md=!1))})),[4,this.Od(n,t)];case 3:return e.sent(),[3,6];case 4:return[4,me(e.sent())];case 5:return e.sent(),[3,6];case 6:return[2]}}))}))},t.prototype.rd=function(t,n){if(this.isPrimary&&n===x.p||!this.isPrimary&&n===x.g){this.Pd("applyOnlineStateChange()");var i=[];this.bd.forEach((function(n,e){var r=e.view.rd(t);S(0===r.ed.length,"OnlineState should not affect limbo documents."),r.snapshot&&i.push(r.snapshot)})),this.gd.Fd(t),this.gd.Da(i),this.onlineState=t,this.isPrimary&&this.pd.El(t)}},t.prototype.Nf=function(t,n){return e(this,void 0,void 0,(function(){var i,e,u,s,o,h=this;return r(this,(function(r){switch(r.label){case 0:return this.Pd("rejectListens()"),this.pd.Il(t,"rejected",n),i=this.Id[t],(e=i&&i.key)?(this._d=this._d.remove(e),delete this.Id[t],u=(u=new St(Pt.X)).bt(e,new _n(e,Tt.K())),s=ci().add(e),o=new _i(Tt.MIN,{},new Nt(V),u,s),[2,this.Uh(o)]):[3,1];case 1:return[4,this.jo.nc(t,!1).then((function(){return h.kd(t,n)})).catch(me)];case 2:r.sent(),r.label=3;case 3:return[2]}}))}))},t.prototype.Nl=function(t,n,i){return e(this,void 0,void 0,(function(){var e;return r(this,(function(r){switch(r.label){case 0:return this.Pd("applyBatchState()"),[4,this.jo.Eh(t)];case 1:return null===(e=r.sent())?(R("SyncEngine","Cannot apply mutation batch with id: "+t),[2]):"pending"!==n?[3,3]:[4,this.hd.Tf()];case 2:return r.sent(),[3,4];case 3:"acknowledged"===n||"rejected"===n?(this.xd(t,i||null),this.jo.oc(t)):P("Unknown batchState: "+n),r.label=4;case 4:return[4,this.Od(e)];case 5:return r.sent(),[2]}}))}))},t.prototype.Lf=function(t){return e(this,void 0,void 0,(function(){var n,i;return r(this,(function(e){switch(e.label){case 0:this.Pd("applySuccessfulWrite()"),n=t.batch.batchId,this.xd(n,null),this.jd(n),e.label=1;case 1:return e.trys.push([1,4,,6]),[4,this.jo.Ah(t)];case 2:return i=e.sent(),this.pd.wl(n,"acknowledged"),[4,this.Od(i)];case 3:return e.sent(),[3,6];case 4:return[4,me(e.sent())];case 5:return e.sent(),[3,6];case 6:return[2]}}))}))},t.prototype.qf=function(t,n){return e(this,void 0,void 0,(function(){var i;return r(this,(function(e){switch(e.label){case 0:this.Pd("rejectFailedWrite()"),this.xd(t,n),this.jd(t),e.label=1;case 1:return e.trys.push([1,4,,6]),[4,this.jo.Vh(t)];case 2:return i=e.sent(),this.pd.wl(t,"rejected",n),[4,this.Od(i)];case 3:return e.sent(),[3,6];case 4:return[4,me(e.sent())];case 5:return e.sent(),[3,6];case 6:return[2]}}))}))},t.prototype.Ud=function(t){return e(this,void 0,void 0,(function(){var n,i;return r(this,(function(e){switch(e.label){case 0:return this.hd.af()||R("SyncEngine","The network is disabled. The task returned by 'awaitPendingWrites()' will not complete until the network is enabled."),[4,this.jo.Oh()];case 1:return-1===(n=e.sent())?(t.resolve(),[2]):((i=this.Rd.get(n)||[]).push(t),this.Rd.set(n,i),[2])}}))}))},t.prototype.jd=function(t){(this.Rd.get(t)||[]).forEach((function(t){t.resolve()})),this.Rd.delete(t)},t.prototype.Ld=function(t){this.Rd.forEach((function(n){n.forEach((function(n){n.reject(new Q(q.CANCELLED,t))}))})),this.Rd.clear()},t.prototype.Nd=function(t,n){var i=this.Ed[this.currentUser.I()];i||(i=new St(V)),i=i.bt(t,n),this.Ed[this.currentUser.I()]=i},t.prototype.xd=function(t,n){var i=this.Ed[this.currentUser.I()];if(i){var e=i.get(t);e&&(S(t===i.It(),"Mutation callbacks processed out-of-order?"),n?e.reject(n):e.resolve(),i=i.remove(t)),this.Ed[this.currentUser.I()]=i}},t.prototype.kd=function(t,n){var i=this;void 0===n&&(n=null),this.pd.bl(t),S(this.yd[t]&&0!==this.yd[t].length,"There are no queries mapped to target id "+t);for(var e=0,r=this.yd[t];e<r.length;e++){var u=r[e];this.bd.delete(u),n&&this.gd.Bd(u,n)}if(delete this.yd[t],this.isPrimary){var s=this.Td.Fu(t);this.Td.Nu(t),s.forEach((function(t){i.Td.xu(t)||i.Md(t)}))}},t.prototype.Md=function(t){var n=this._d.get(t);null!==n&&(this.hd.Pf(n),this._d=this._d.remove(t),delete this.Id[n])},t.prototype.Vd=function(t,n){for(var i=0,e=n;i<e.length;i++){var r=e[i];if(r instanceof yr)this.Td.Pu(r.key,t),this.qd(r);else if(r instanceof _r){R("SyncEngine","Document no longer in limbo: "+r.key),this.Td.Cu(r.key,t),this.Td.xu(r.key)||this.Md(r.key)}else P("Unknown limbo change: "+JSON.stringify(r))}},t.prototype.qd=function(t){var n=t.key;if(!this._d.get(n)){R("SyncEngine","New document in limbo: "+n);var i=this.Ad.next(),e=On.oi(n.path);this.Id[i]=new Ar(n),this.hd.listen(new Yn(e.bi(),i,kn.Oi,re.ks)),this._d=this._d.bt(n,i)}},t.prototype.Qd=function(){return this._d},t.prototype.Od=function(t,n){return e(this,void 0,void 0,(function(){var i,e,u,s=this;return r(this,(function(r){switch(r.label){case 0:return i=[],e=[],u=[],this.bd.forEach((function(r,o){u.push(Promise.resolve().then((function(){var n=o.view.Yl(t);return n.Zl?s.jo.ic(o.query,!1).then((function(t){var i=t.documents;return o.view.Yl(i,n)})):n})).then((function(t){var r=n&&n.ie[o.targetId],u=o.view.rs(t,!0===s.isPrimary,r);if(s.Vd(o.targetId,u.ed),u.snapshot){s.isPrimary&&s.pd.Il(o.targetId,u.snapshot.fromCache?"not-current":"current"),i.push(u.snapshot);var h=ee.Ds(o.targetId,u.snapshot);e.push(h)}})))})),[4,Promise.all(u)];case 1:return r.sent(),this.gd.Da(i),[4,this.jo.Kh(e)];case 2:return r.sent(),[2]}}))}))},t.prototype.Pd=function(t){S(null!==this.gd,"Trying to call "+t+" before calling subscribe().")},t.prototype.Gf=function(t){return e(this,void 0,void 0,(function(){var n,i;return r(this,(function(e){switch(e.label){case 0:return n=!this.currentUser.isEqual(t),this.currentUser=t,n?(this.Ld("'waitForPendingWrites' promise is rejected due to a user change."),[4,this.jo.ph(t)]):[3,3];case 1:return i=e.sent(),this.pd.ph(t,i.yh,i._h),[4,this.Od(i.bh)];case 2:e.sent(),e.label=3;case 3:return[4,this.hd.Gf()];case 4:return e.sent(),[2]}}))}))},t.prototype.Wf=function(t){return e(this,void 0,void 0,(function(){var n,i,e,u,s,o,h=this;return r(this,(function(r){switch(r.label){case 0:return!0!==t||!0===this.isPrimary?[3,3]:(this.isPrimary=!0,[4,this.hd.Wf(!0)]);case 1:return r.sent(),s=this.pd.fl(),[4,this.Gd(s.st())];case 2:for(n=r.sent(),i=0,e=n;i<e.length;i++)u=e[i],this.hd.listen(u);return[3,7];case 3:return!1!==t||!1===this.isPrimary?[3,7]:(this.isPrimary=!1,s=[],o=Promise.resolve(),$(this.yd,(function(t,n){h.pd.yl(t)?s.push(t):o=o.then((function(){return h.kd(t),h.jo.nc(t,!0)})),h.hd.Pf(t)})),[4,o]);case 4:return r.sent(),[4,this.Gd(s)];case 5:return r.sent(),this.Wd(),[4,this.hd.Wf(!1)];case 6:r.sent(),r.label=7;case 7:return[2]}}))}))},t.prototype.Wd=function(){var t=this;$(this.Id,(function(n){t.hd.Pf(n)})),this.Td.Ou(),this.Id=[],this._d=new St(Pt.X)},t.prototype.Gd=function(t){return e(this,void 0,void 0,(function(){var n,i,e,u,s,o,h,c,a,f,l,d,v;return r(this,(function(r){switch(r.label){case 0:n=[],i=[],e=0,u=t,r.label=1;case 1:return e<u.length?(s=u[e],o=void 0,(h=this.yd[s])&&0!==h.length?[4,this.jo.nc(s,!0)]:[3,8]):[3,14];case 2:return r.sent(),[4,this.jo.Xh(h[0].bi())];case 3:o=r.sent(),c=0,a=h,r.label=4;case 4:return c<a.length?(f=a[c],S(!!(l=this.bd.get(f)),"No query view found for "+f),[4,this.Cd(l)]):[3,7];case 5:(d=r.sent()).snapshot&&i.push(d.snapshot),r.label=6;case 6:return c++,[3,4];case 7:return[3,12];case 8:return S(!0===this.isPrimary,"A secondary tab should never have an active target without an active query."),[4,this.jo.ac(s)];case 9:return S(!!(v=r.sent()),"Target for id "+s+" not found"),[4,this.jo.Xh(v)];case 10:return o=r.sent(),[4,this.Sd(this.zd(v),s,!1)];case 11:r.sent(),r.label=12;case 12:n.push(o),r.label=13;case 13:return e++,[3,1];case 14:return this.gd.Da(i),[2,n]}}))}))},t.prototype.zd=function(t){return new On(t.path,t.collectionGroup,t.orderBy,t.filters,t.limit,Sn.ti,t.startAt,t.endAt)},t.prototype.sc=function(){return this.jo.sc()},t.prototype.Ol=function(t,n,i){return e(this,void 0,void 0,(function(){var e,u;return r(this,(function(r){switch(r.label){case 0:if(this.isPrimary)return R("SyncEngine","Ignoring unexpected query state notification."),[2];if(!this.yd[t])return[3,7];switch(n){case"current":case"not-current":return[3,1];case"rejected":return[3,4]}return[3,6];case 1:return[4,this.jo.fc()];case 2:return e=r.sent(),u=_i.se(t,"current"===n),[4,this.Od(e,u)];case 3:return r.sent(),[3,7];case 4:return[4,this.jo.nc(t,!0)];case 5:return r.sent(),this.kd(t,i),[3,7];case 6:P("Unexpected target state: "+n),r.label=7;case 7:return[2]}}))}))},t.prototype.Fl=function(t,n){return e(this,void 0,void 0,(function(){var i,e,u,s,o,h,c,a,f,l=this;return r(this,(function(d){switch(d.label){case 0:if(!this.isPrimary)return[2];i=0,e=t,d.label=1;case 1:return i<e.length?(f=e[i],S(!this.yd[f],"Trying to add an already active target"),[4,this.jo.ac(f)]):[3,6];case 2:return S(!!(u=d.sent()),"Query data for active target "+f+" not found"),[4,this.jo.Xh(u)];case 3:return s=d.sent(),[4,this.Sd(this.zd(u),s.targetId,!1)];case 4:d.sent(),this.hd.listen(s),d.label=5;case 5:return i++,[3,1];case 6:o=function(t){return r(this,(function(n){switch(n.label){case 0:return h.yd[t]?[4,h.jo.nc(t,!1).then((function(){l.hd.Pf(t),l.kd(t)})).catch(me)]:[2,"continue"];case 1:return n.sent(),[2]}}))},h=this,c=0,a=n,d.label=7;case 7:return c<a.length?(f=a[c],[5,o(f)]):[3,10];case 8:d.sent(),d.label=9;case 9:return c++,[3,7];case 10:return[2]}}))}))},t.prototype.enableNetwork=function(){return this.jo.cc(!0),this.hd.enableNetwork()},t.prototype.disableNetwork=function(){return this.jo.cc(!1),this.hd.disableNetwork()},t.prototype.$e=function(t){var n=this.Id[t];if(n&&n.md)return ci().add(n.key);var i=ci(),e=this.yd[t];if(!e)return i;for(var r=0,u=e;r<u.length;r++){var s=u[r],o=this.bd.get(s);S(!!o,"No query view found for "+s),i=i.Jt(o.view.Jl)}return i},t}(),Pr=function(){this.Kd=null,this.targetId=0,this.Hd=[]},Sr=function(){function t(t){this.Cf=t,this.Jd=new Ki((function(t){return t.canonicalId()})),this.onlineState=O.l,this.Yd=new Set,this.Cf.subscribe(this)}return t.prototype.listen=function(t){var n=t.query,i=!1,e=this.Jd.get(n);(e||(i=!0,e=new Pr,this.Jd.set(n,e)),e.Hd.push(t),S(!t.rd(this.onlineState),"applyOnlineStateChange() shouldn't raise an event for brand-new listeners."),e.Kd)&&(t.Xd(e.Kd)&&this.$d());return i?this.Cf.listen(n).then((function(t){return e.targetId=t,t})):Promise.resolve(e.targetId)},t.prototype.Pf=function(t){return e(this,void 0,void 0,(function(){var n,i,e,u;return r(this,(function(r){return n=t.query,i=!1,(e=this.Jd.get(n))&&(u=e.Hd.indexOf(t))>=0&&(e.Hd.splice(u,1),i=0===e.Hd.length),i?(this.Jd.delete(n),[2,this.Cf.Pf(n)]):[2]}))}))},t.prototype.Da=function(t){for(var n=!1,i=0,e=t;i<e.length;i++){var r=e[i],u=r.query,s=this.Jd.get(u);if(s){for(var o=0,h=s.Hd;o<h.length;o++){h[o].Xd(r)&&(n=!0)}s.Kd=r}}n&&this.$d()},t.prototype.Bd=function(t,n){var i=this.Jd.get(t);if(i)for(var e=0,r=i.Hd;e<r.length;e++){r[e].onError(n)}this.Jd.delete(t)},t.prototype.Fd=function(t){this.onlineState=t;var n=!1;this.Jd.forEach((function(i,e){for(var r=0,u=e.Hd;r<u.length;r++){u[r].rd(t)&&(n=!0)}})),n&&this.$d()},t.prototype.Zd=function(t){this.Yd.add(t),t.next()},t.prototype.tv=function(t){this.Yd.delete(t)},t.prototype.$d=function(){this.Yd.forEach((function(t){t.next()}))},t}(),Cr=function(){function t(t,n,i){this.query=t,this.nv=n,this.iv=!1,this.ev=null,this.onlineState=O.l,this.options=i||{}}return t.prototype.Xd=function(t){if(S(t.docChanges.length>0||t.Zi,"We got a new snapshot with no changes?"),!this.options.includeMetadataChanges){for(var n=[],i=0,e=t.docChanges;i<e.length;i++){var r=e[i];r.type!==li.zi&&n.push(r)}t=new yi(t.query,t.docs,t.Xi,n,t.$i,t.fromCache,t.Zi,!0)}var u=!1;return this.iv?this.rv(t)&&(this.nv.next(t),u=!0):this.uv(t,this.onlineState)&&(this.sv(t),u=!0),this.ev=t,u},t.prototype.onError=function(t){this.nv.error(t)},t.prototype.rd=function(t){this.onlineState=t;var n=!1;return this.ev&&!this.iv&&this.uv(this.ev,t)&&(this.sv(this.ev),n=!0),n},t.prototype.uv=function(t,n){if(S(!this.iv,"Determining whether to raise first event but already had first event"),!t.fromCache)return!0;var i=n!==O.m;return this.options.ov&&i?(S(t.fromCache,"Waiting for sync, but snapshot is not from cache"),!1):!t.docs.nt()||n===O.m},t.prototype.rv=function(t){if(t.docChanges.length>0)return!0;var n=this.ev&&this.ev.hasPendingWrites!==t.hasPendingWrites;return!(!t.Zi&&!n)&&!0===this.options.includeMetadataChanges},t.prototype.sv=function(t){S(!this.iv,"Trying to raise initial events for second time"),t=yi.ne(t.query,t.docs,t.$i,t.fromCache),this.iv=!0,this.nv.next(t)},t}(),Vr="",kr="",Nr="",Or="";function Fr(t){for(var n="",i=0;i<t.length;i++)n.length>0&&(n=jr(n)),n=xr(t.get(i),n);return jr(n)}function xr(t,n){for(var i=n,e=t.length,r=0;r<e;r++){var u=t.charAt(r);switch(u){case"\0":i+=Vr+Nr;break;case Vr:i+=Vr+Or;break;default:i+=u}}return i}function jr(t){return t+Vr+kr}function Ur(t){var n=t.length;if(S(n>=2,"Invalid path "+t),2===n)return S(t.charAt(0)===Vr&&t.charAt(1)===kr,"Non-empty path "+t+" had length 2"),Rt.ct;for(var i=n-2,e=[],r="",u=0;u<n;){var s=t.indexOf(Vr,u);switch((s<0||s>i)&&P('Invalid encoded resource path: "'+t+'"'),t.charAt(s+1)){case kr:var o=t.substring(u,s),h=void 0;0===r.length?h=o:(h=r+=o,r=""),e.push(h);break;case Nr:r+=t.substring(u,s),r+="\0";break;case Or:r+=t.substring(u,s+1);break;default:P('Invalid encoded resource path: "'+t+'"')}u=s+2}return new Rt(e)}var Lr=function(){function t(n){this.db=n,12.2===t.hv(h())&&A("Firestore persistence suffers from a bug in iOS 12.2 Safari that may cause your app to stop working. See https://stackoverflow.com/q/56496296/110915 for details and a potential workaround.")}return t.cv=function(n,i,e){return S(t.nl(),"IndexedDB not supported in current environment."),R("SimpleDb","Opening database:",n),new $i((function(r,u){var s=window.indexedDB.open(n,i);s.onsuccess=function(n){var i=n.target.result;r(new t(i))},s.onblocked=function(){u(new Q(q.FAILED_PRECONDITION,"Cannot upgrade IndexedDB schema while another tab is open. Close all tabs that access Firestore and reload this page to proceed."))},s.onerror=function(t){var n=t.target.error;"VersionError"===n.name?u(new Q(q.FAILED_PRECONDITION,"A newer version of the Firestore SDK was previously used and so the persisted data is not compatible with the version of the SDK you are now using. The SDK will operate with persistence disabled. If you need persistence, please re-upgrade to a newer version of the SDK or else clear the persisted IndexedDB data for your app to start fresh.")):u(n)},s.onupgradeneeded=function(t){R("SimpleDb",'Database "'+n+'" requires upgrade from version:',t.oldVersion);var i=t.target.result;e.createOrUpgrade(i,s.transaction,t.oldVersion,fu).next((function(){R("SimpleDb","Database upgrade to version "+fu+" complete")}))}})).Gu()},t.delete=function(t){return R("SimpleDb","Removing database:",t),Qr(window.indexedDB.deleteDatabase(t)).Gu()},t.nl=function(){if("undefined"==typeof window||null==window.indexedDB)return!1;if(t.av())return!0;if(void 0===window.navigator)return!1;var n=h(),i=t.hv(n),e=0<i&&i<10,r=t.fv(n),u=0<r&&r<4.5;return!(n.indexOf("MSIE ")>0||n.indexOf("Trident/")>0||n.indexOf("Edge/")>0||e||u)},t.av=function(){var t;return"undefined"!=typeof __PRIVATE_process&&"YES"===(null===(t=__PRIVATE_process.__PRIVATE_env)||void 0===t?void 0:t.lv)},t.dv=function(t,n){return t.store(n)},t.hv=function(t){var n=t.match(/i(?:phone|pad|pod) os ([\d_]+)/i),i=n?n[1].split("_").slice(0,2).join("."):"-1";return Number(i)},t.fv=function(t){var n=t.match(/Android ([\d.]+)/i),i=n?n[1].split(".").slice(0,2).join("."):"-1";return Number(i)},t.prototype.vv=function(t){this.db.onversionchange=function(n){return t(n)}},t.prototype.runTransaction=function(t,n,i){return e(this,void 0,void 0,(function(){var e,u,s,o,h,c;return r(this,(function(a){switch(a.label){case 0:e=t.startsWith("readonly"),u=t.endsWith("idempotent"),s=0,o=function(){var t,o,c,a;return r(this,(function(r){switch(r.label){case 0:++s,t=Mr.open(h.db,e?"readonly":"readwrite",n),r.label=1;case 1:return r.trys.push([1,3,,4]),(o=i(t).catch((function(n){return t.abort(n),$i.reject(n)})).Gu()).catch((function(){})),[4,t.wv];case 2:return r.sent(),[2,{value:o}];case 3:return c=r.sent(),a=u&&"FirebaseError"!==c.name&&s<3,R("SimpleDb","Transaction failed with error: %s. Retrying: %s.",c.message,a),a?[3,4]:[2,{value:Promise.reject(c)}];case 4:return[2]}}))},h=this,a.label=1;case 1:return[5,o()];case 2:return"object"==typeof(c=a.sent())?[2,c.value]:[3,1];case 3:return[2]}}))}))},t.prototype.close=function(){this.db.close()},t}(),Br=function(){function t(t){this.mv=t,this.pv=!1,this.gv=null}return Object.defineProperty(t.prototype,"Bu",{get:function(){return this.pv},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"bv",{get:function(){return this.gv},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"cursor",{set:function(t){this.mv=t},enumerable:!0,configurable:!0}),t.prototype.done=function(){this.pv=!0},t.prototype.yv=function(t){this.gv=t},t.prototype.delete=function(){return Qr(this.mv.delete())},t}(),Mr=function(){function t(t){var n=this;this.transaction=t,this.aborted=!1,this._v=new ue,this.transaction.oncomplete=function(){n._v.resolve()},this.transaction.onabort=function(){t.error?n._v.reject(t.error):n._v.resolve()},this.transaction.onerror=function(t){var i=Wr(t.target.error);n._v.reject(i)}}return t.open=function(n,i,e){return new t(n.transaction(e,i))},Object.defineProperty(t.prototype,"wv",{get:function(){return this._v.promise},enumerable:!0,configurable:!0}),t.prototype.abort=function(t){t&&this._v.reject(t),this.aborted||(R("SimpleDb","Aborting transaction:",t?t.message:"Client-initiated abort"),this.aborted=!0,this.transaction.abort())},t.prototype.store=function(t){var n=this.transaction.objectStore(t);return S(!!n,"Object store not part of transaction: "+t),new qr(n)},t}(),qr=function(){function t(t){this.store=t}return t.prototype.put=function(t,n){var i;return void 0!==n?(R("SimpleDb","PUT",this.store.name,t,n),i=this.store.put(n,t)):(R("SimpleDb","PUT",this.store.name,"<auto-key>",t),i=this.store.put(t)),Qr(i)},t.prototype.add=function(t){return R("SimpleDb","ADD",this.store.name,t,t),Qr(this.store.add(t))},t.prototype.get=function(t){var n=this;return Qr(this.store.get(t)).next((function(i){return void 0===i&&(i=null),R("SimpleDb","GET",n.store.name,t,i),i}))},t.prototype.delete=function(t){return R("SimpleDb","DELETE",this.store.name,t),Qr(this.store.delete(t))},t.prototype.count=function(){return R("SimpleDb","COUNT",this.store.name),Qr(this.store.count())},t.prototype.Iv=function(t,n){var i=this.cursor(this.options(t,n)),e=[];return this.Tv(i,(function(t,n){e.push(n)})).next((function(){return e}))},t.prototype.Ev=function(t,n){R("SimpleDb","DELETE ALL",this.store.name);var i=this.options(t,n);i.Rv=!1;var e=this.cursor(i);return this.Tv(e,(function(t,n,i){return i.delete()}))},t.prototype.Av=function(t,n){var i;n?i=t:(i={},n=t);var e=this.cursor(i);return this.Tv(e,n)},t.prototype.Dv=function(t){var n=this.cursor({});return new $i((function(i,e){n.onerror=function(t){var n=Wr(t.target.error);e(n)},n.onsuccess=function(n){var e=n.target.result;e?t(e.primaryKey,e.value).next((function(t){t?e.continue():i()})):i()}}))},t.prototype.Tv=function(t,n){var i=[];return new $i((function(e,r){t.onerror=function(t){r(t.target.error)},t.onsuccess=function(t){var r=t.target.result;if(r){var u=new Br(r),s=n(r.primaryKey,r.value,u);if(s instanceof $i){var o=s.catch((function(t){return u.done(),$i.reject(t)}));i.push(o)}u.Bu?e():null===u.bv?r.continue():r.continue(u.bv)}else e()}})).next((function(){return $i.zu(i)}))},t.prototype.options=function(t,n){var i=void 0;return void 0!==t&&("string"==typeof t?i=t:(S(void 0===n,"3rd argument must not be defined if 2nd is a range."),n=t)),{index:i,range:n}},t.prototype.cursor=function(t){var n="next";if(t.reverse&&(n="prev"),t.index){var i=this.store.index(t.index);return t.Rv?i.openKeyCursor(t.range,n):i.openCursor(t.range,n)}return this.store.openCursor(t.range,n)},t}();function Qr(t){return new $i((function(n,i){t.onsuccess=function(t){var i=t.target.result;n(i)},t.onerror=function(t){var n=Wr(t.target.error);i(n)}}))}var Gr=!1;function Wr(t){var n=Lr.hv(h());if(n>=12.2&&n<13){var i="An internal error was encountered in the Indexed Database server";if(t.message.indexOf(i)>=0){var e=new Q("internal","IOS_INDEXEDDB_BUG1: IndexedDb has thrown '"+i+"'. This is likely due to an unavoidable bug in iOS. See https://stackoverflow.com/q/56496296/110915 for details and a potential workaround.");return Gr||(Gr=!0,setTimeout((function(){throw e}),0)),e}}return t}var zr=function(){function t(t,n,i,e){this.userId=t,this.serializer=n,this.as=i,this.sh=e,this.Pv={}}return t.Sv=function(n,i,e,r){return S(""!==n.uid,"UserID must not be an empty string."),new t(n._()?n.uid:"",i,e,r)},t.prototype.Cv=function(t){var n=!0,i=IDBKeyRange.bound([this.userId,Number.NEGATIVE_INFINITY],[this.userId,Number.POSITIVE_INFINITY]);return Yr(t).Av({index:mu.userMutationsIndex,range:i},(function(t,i,e){n=!1,e.done()})).next((function(){return n}))},t.prototype.Ah=function(t,n,i){return this.Vv(t).next((function(n){return n.lastStreamToken=Jr(i),$r(t).put(n)}))},t.prototype.Fh=function(t){return this.Vv(t).next((function(t){return t.lastStreamToken}))},t.prototype.xh=function(t,n){return this.Vv(t).next((function(i){return i.lastStreamToken=Jr(n),$r(t).put(i)}))},t.prototype.Th=function(t,n,i,e){var r=this,u=Xr(t),s=Yr(t);return s.add({}).next((function(o){S("number"==typeof o,"Auto-generated key is not a number");for(var h=new Hi(o,n,i,e),c=r.serializer.kv(r.userId,h),a=[],f=new Nt((function(t,n){return V(t.ot(),n.ot())})),l=0,d=e;l<d.length;l++){var v=d[l],w=pu.key(r.userId,v.key.path,o);f=f.add(v.key.path.tt()),a.push(s.put(c)),a.push(u.put(w,pu.PLACEHOLDER))}return f.forEach((function(n){a.push(r.as.Nv(t,n))})),t.ss((function(){r.Pv[o]=h.keys()})),$i.zu(a).next((function(){return h}))}))},t.prototype.kh=function(t,n){var i=this;return Yr(t).get(n).next((function(t){return t?(S(t.userId===i.userId,"Unexpected user '"+t.userId+"' for mutation batch "+n),i.serializer.Ov(t)):null}))},t.prototype.Rh=function(t,n){var i=this;return this.Pv[n]?$i.resolve(this.Pv[n]):this.kh(t,n).next((function(t){if(t){var e=t.keys();return i.Pv[n]=e,e}return null}))},t.prototype.Jh=function(t,n){var i=this,e=n+1,r=IDBKeyRange.lowerBound([this.userId,e]),u=null;return Yr(t).Av({index:mu.userMutationsIndex,range:r},(function(t,n,r){n.userId===i.userId&&(S(n.batchId>=e,"Should have found mutation after "+e),u=i.serializer.Ov(n)),r.done()})).next((function(){return u}))},t.prototype.Oh=function(t){var n=IDBKeyRange.upperBound([this.userId,Number.POSITIVE_INFINITY]),i=-1;return Yr(t).Av({index:mu.userMutationsIndex,range:n,reverse:!0},(function(t,n,e){i=n.batchId,e.done()})).next((function(){return i}))},t.prototype.gh=function(t){var n=this,i=IDBKeyRange.bound([this.userId,-1],[this.userId,Number.POSITIVE_INFINITY]);return Yr(t).Iv(mu.userMutationsIndex,i).next((function(t){return t.map((function(t){return n.serializer.Ov(t)}))}))},t.prototype.ls=function(t,n){var i=this,e=pu.prefixForPath(this.userId,n.path),r=IDBKeyRange.lowerBound(e),u=[];return Xr(t).Av({range:r},(function(e,r,s){var o=e[0],h=e[1],c=e[2],a=Ur(h);if(o===i.userId&&n.path.isEqual(a))return Yr(t).get(c).next((function(t){if(!t)throw P("Dangling document-mutation reference found: "+e+" which points to "+c);S(t.userId===i.userId,"Unexpected user '"+t.userId+"' for mutation batch "+c),u.push(i.serializer.Ov(t))}));s.done()})).next((function(){return u}))},t.prototype.ps=function(t,n){var i=this,e=new Nt(V),r=[];return n.forEach((function(n){var u=pu.prefixForPath(i.userId,n.path),s=IDBKeyRange.lowerBound(u),o=Xr(t).Av({range:s},(function(t,r,u){var s=t[0],o=t[1],h=t[2],c=Ur(o);s===i.userId&&n.path.isEqual(c)?e=e.add(h):u.done()}));r.push(o)})),$i.zu(r).next((function(){return i.Fv(t,e)}))},t.prototype.Ts=function(t,n){var i=this;S(!n.Zn(),"Document queries shouldn't go down this path"),S(!n.Pi(),"CollectionGroup queries should be handled in LocalDocumentsView");var e=n.path,r=e.length+1,u=pu.prefixForPath(this.userId,e),s=IDBKeyRange.lowerBound(u),o=new Nt(V);return Xr(t).Av({range:s},(function(t,n,u){var s=t[0],h=t[1],c=t[2],a=Ur(h);s===i.userId&&e.rt(a)?a.length===r&&(o=o.add(c)):u.done()})).next((function(){return i.Fv(t,o)}))},t.prototype.Fv=function(t,n){var i=this,e=[],r=[];return n.forEach((function(n){r.push(Yr(t).get(n).next((function(t){if(null===t)throw P("Dangling document-mutation reference found, which points to "+n);S(t.userId===i.userId,"Unexpected user '"+t.userId+"' for mutation batch "+n),e.push(i.serializer.Ov(t))})))})),$i.zu(r).next((function(){return e}))},t.prototype.Nh=function(t,n){var i=this;return Hr(t.xv,this.userId,n).next((function(e){return t.ss((function(){i.hc(n.batchId)})),$i.forEach(e,(function(n){return i.sh.jv(t,n)}))}))},t.prototype.hc=function(t){delete this.Pv[t]},t.prototype.Ch=function(t){var n=this;return this.Cv(t).next((function(i){if(!i)return $i.resolve();var e=IDBKeyRange.lowerBound(pu.prefixForUser(n.userId)),r=[];return Xr(t).Av({range:e},(function(t,i,e){if(t[0]===n.userId){var u=Ur(t[1]);r.push(u)}else e.done()})).next((function(){S(0===r.length,"Document leak -- detected dangling mutation references when queue is empty. Dangling keys: "+r.map((function(t){return t.ot()})))}))}))},t.prototype.xu=function(t,n){return Kr(t,this.userId,n)},t.prototype.Vv=function(t){var n=this;return $r(t).get(this.userId).next((function(t){return t||new wu(n.userId,-1,"")}))},t}();function Kr(t,n,i){var e=pu.prefixForPath(n,i.path),r=e[1],u=IDBKeyRange.lowerBound(e),s=!1;return Xr(t).Av({range:u,Rv:!0},(function(t,i,e){var u=t[0],o=t[1];t[2];u===n&&o===r&&(s=!0),e.done()})).next((function(){return s}))}function Hr(t,n,i){var e=t.store(mu.store),r=t.store(pu.store),u=[],s=IDBKeyRange.only(i.batchId),o=0,h=e.Av({range:s},(function(t,n,i){return o++,i.delete()}));u.push(h.next((function(){S(1===o,"Dangling document-mutation reference found: Missing batch "+i.batchId)})));for(var c=[],a=0,f=i.mutations;a<f.length;a++){var l=f[a],d=pu.key(n,l.key.path,i.batchId);u.push(r.delete(d)),c.push(l.key)}return $i.zu(u).next((function(){return c}))}function Jr(t){return t instanceof Uint8Array?(S(Lr.av(),"Persisting non-string stream tokens is only supported with mock persistence."),t.toString()):t}function Yr(t){return ju.dv(t,mu.store)}function Xr(t){return ju.dv(t,pu.store)}function $r(t){return ju.dv(t,wu.store)}var Zr=function(){function t(t,n){this.sh=t,this.serializer=n,this.Uv=br.Ql()}return t.prototype.Zh=function(t){var n=this;return this.Lv(t).next((function(i){return i.highestTargetId=n.Uv.after(i.highestTargetId),n.Bv(t,i).next((function(){return i.highestTargetId}))}))},t.prototype.jh=function(t){return this.Lv(t).next((function(t){return Tt.W(new It(t.lastRemoteSnapshotVersion.seconds,t.lastRemoteSnapshotVersion.nanoseconds))}))},t.prototype.Mv=function(t){return iu(t.xv)},t.prototype.Wh=function(t,n,i){var e=this;return this.Lv(t).next((function(r){return r.highestListenSequenceNumber=n,i&&(r.lastRemoteSnapshotVersion=i.J()),n>r.highestListenSequenceNumber&&(r.highestListenSequenceNumber=n),e.Bv(t,r)}))},t.prototype.tc=function(t,n){var i=this;return this.qv(t,n).next((function(){return i.Lv(t).next((function(e){return e.targetCount+=1,i.Qv(n,e),i.Bv(t,e)}))}))},t.prototype.Qh=function(t,n){return this.qv(t,n)},t.prototype.Gv=function(t,n){var i=this;return this.Wv(t,n.targetId).next((function(){return tu(t).delete(n.targetId)})).next((function(){return i.Lv(t)})).next((function(n){return S(n.targetCount>0,"Removing from an empty target cache"),n.targetCount-=1,i.Bv(t,n)}))},t.prototype.Jo=function(t,n,i){var e=this,r=0,u=[];return tu(t).Av((function(s,o){var h=e.serializer.zv(o);h.sequenceNumber<=n&&null===i.get(h.targetId)&&(r++,u.push(e.Gv(t,h)))})).next((function(){return $i.zu(u)})).next((function(){return r}))},t.prototype.qe=function(t,n){var i=this;return tu(t).Av((function(t,e){var r=i.serializer.zv(e);n(r)}))},t.prototype.Lv=function(t){return nu(t.xv)},t.prototype.Bv=function(t,n){return(i=t,ju.dv(i,Eu.store)).put(Eu.key,n);var i},t.prototype.qv=function(t,n){return tu(t).put(this.serializer.Kv(n))},t.prototype.Qv=function(t,n){var i=!1;return t.targetId>n.highestTargetId&&(n.highestTargetId=t.targetId,i=!0),t.sequenceNumber>n.highestListenSequenceNumber&&(n.highestListenSequenceNumber=t.sequenceNumber,i=!0),i},t.prototype.Hv=function(t){return this.Lv(t).next((function(t){return t.targetCount}))},t.prototype.$h=function(t,n){var i=this,e=n.canonicalId(),r=IDBKeyRange.bound([e,Number.NEGATIVE_INFINITY],[e,Number.POSITIVE_INFINITY]),u=null;return tu(t).Av({range:r,index:Iu.queryTargetsIndexName},(function(t,e,r){var s=i.serializer.zv(e);n.isEqual(s.target)&&(u=s,r.done())})).next((function(){return u}))},t.prototype.Bh=function(t,n,i){var e=this,r=[],u=eu(t);return n.forEach((function(n){var s=Fr(n.path);r.push(u.put(new Tu(i,s))),r.push(e.sh.Pu(t,n))})),$i.zu(r)},t.prototype.Lh=function(t,n,i){var e=this,r=eu(t);return $i.forEach(n,(function(n){var u=Fr(n.path);return $i.zu([r.delete([i,u]),e.sh.Cu(t,n)])}))},t.prototype.Wv=function(t,n){var i=eu(t),e=IDBKeyRange.bound([n],[n+1],!1,!0);return i.delete(e)},t.prototype.ec=function(t,n){var i=IDBKeyRange.bound([n],[n+1],!1,!0),e=eu(t),r=ci();return e.Av({range:i,Rv:!0},(function(t,n,i){var e=Ur(t[1]),u=new Pt(e);r=r.add(u)})).next((function(){return r}))},t.prototype.xu=function(t,n){var i=Fr(n.path),e=IDBKeyRange.bound([i],[N(i)],!1,!0),r=0;return eu(t).Av({index:Tu.documentTargetsIndex,Rv:!0,range:e},(function(t,n,i){var e=t[0];t[1];0!==e&&(r++,i.done())})).next((function(){return r>0}))},t.prototype.Ze=function(t,n){var i=this;return tu(t).get(n).next((function(t){return t?i.serializer.zv(t):null}))},t}();function tu(t){return ju.dv(t,Iu.store)}function nu(t){return Lr.dv(t,Eu.store).get(Eu.key).next((function(t){return S(null!==t,"Missing metadata row."),t}))}function iu(t){return nu(t).next((function(t){return t.highestListenSequenceNumber}))}function eu(t){return ju.dv(t,Tu.store)}var ru=function(){function t(t,n){this.serializer=t,this.as=n}return t.prototype.Xu=function(t,n,i){return su(t).put(ou(n),i)},t.prototype.Zu=function(t,n){var i=su(t),e=ou(n);return i.delete(e)},t.prototype.updateMetadata=function(t,n){var i=this;return this.getMetadata(t).next((function(e){return e.byteSize+=n,i.Jv(t,e)}))},t.prototype.ts=function(t,n){var i=this;return su(t).get(ou(n)).next((function(t){return i.Yv(t)}))},t.prototype.Xv=function(t,n){var i=this;return su(t).get(ou(n)).next((function(t){var n=i.Yv(t);return n?{$v:n,size:hu(t)}:null}))},t.prototype.getEntries=function(t,n){var i=this,e=ei();return this.Zv(t,n,(function(t,n){var r=i.Yv(n);e=e.bt(t,r)})).next((function(){return e}))},t.prototype.tw=function(t,n){var i=this,e=ei(),r=new St(Pt.X);return this.Zv(t,n,(function(t,n){var u=i.Yv(n);u?(e=e.bt(t,u),r=r.bt(t,hu(n))):(e=e.bt(t,null),r=r.bt(t,0))})).next((function(){return{nw:e,iw:r}}))},t.prototype.Zv=function(t,n,i){if(n.nt())return $i.resolve();var e=IDBKeyRange.bound(n.first().path.st(),n.last().path.st()),r=n.At(),u=r.kt();return su(t).Av({range:e},(function(t,n,e){for(var s=Pt.pt(t);u&&Pt.X(u,s)<0;)i(u,null),u=r.kt();u&&u.isEqual(s)&&(i(u,n),u=r.Nt()?r.kt():null),u?e.yv(u.path.st()):e.done()})).next((function(){for(;u;)i(u,null),u=r.Nt()?r.kt():null}))},t.prototype.gs=function(t,n,i){var e=this;S(!n.Pi(),"CollectionGroup queries should be handled in LocalDocumentsView");var r=ui(),u=n.path.length+1,s={};if(i.isEqual(Tt.MIN)){var o=n.path.st();s.range=IDBKeyRange.lowerBound(o)}else{var h=n.path.st(),c=this.serializer.ew(i);s.range=IDBKeyRange.lowerBound([h,c],!0),s.index=yu.collectionReadTimeIndex}return su(t).Av(s,(function(t,i,s){if(t.length===u){var o=e.serializer.rw(i);n.path.rt(o.key.path)?o instanceof yn&&n.matches(o)&&(r=r.bt(o.key,o)):s.done()}})).next((function(){return r}))},t.prototype.fc=function(t,n){var i=this,e=ii(),r=this.serializer.ew(n),u=su(t),s=IDBKeyRange.lowerBound(r,!0);return u.Av({index:yu.readTimeIndex,range:s},(function(t,n){var u=i.serializer.rw(n);e=e.bt(u.key,u),r=n.readTime})).next((function(){return{lc:e,readTime:i.serializer.uw(r)}}))},t.prototype.dc=function(t){var n=this,i=su(t),e=Tt.MIN;return i.Av({index:yu.readTimeIndex,reverse:!0},(function(t,i,r){i.readTime&&(e=n.serializer.uw(i.readTime)),r.done()})).next((function(){return e}))},t.prototype.Dh=function(n){return new t.sw(this,!!n&&n.Ph)},t.prototype.ow=function(t){return this.getMetadata(t).next((function(t){return t.byteSize}))},t.prototype.getMetadata=function(t){return uu(t).get(_u.key).next((function(t){return S(!!t,"Missing document cache metadata"),t}))},t.prototype.Jv=function(t,n){return uu(t).put(_u.key,n)},t.prototype.Yv=function(t){if(t){var n=this.serializer.rw(t);return n instanceof _n&&n.version.isEqual(Tt.K())?null:n}return null},t.sw=function(t){function n(n,i){var e=t.call(this)||this;return e.hw=n,e.Ph=i,e.cw=new Ki((function(t){return t.toString()})),e}return i(n,t),n.prototype.rs=function(t){var n=this,i=[],e=0,r=new Nt((function(t,n){return V(t.ot(),n.ot())}));return this.Hu.forEach((function(u,s){var o=n.cw.get(u);if(S(void 0!==o,"Cannot modify a document that wasn't read (for "+u+")"),s){S(!n.readTime.isEqual(Tt.MIN),"Cannot add a document with a read time of zero");var h=n.hw.serializer.aw(s,n.readTime);r=r.add(u.path.tt());var c=hu(h);e+=c-o,i.push(n.hw.Xu(t,u,h))}else if(e-=o,n.Ph){var a=n.hw.serializer.aw(new _n(u,Tt.K()),n.readTime);i.push(n.hw.Xu(t,u,a))}else i.push(n.hw.Zu(t,u))})),r.forEach((function(e){i.push(n.hw.as.Nv(t,e))})),i.push(this.hw.updateMetadata(t,e)),$i.zu(i)},n.prototype.ns=function(t,n){var i=this;return this.hw.Xv(t,n).next((function(t){return null===t?(i.cw.set(n,0),null):(i.cw.set(n,t.size),t.$v)}))},n.prototype.es=function(t,n){var i=this;return this.hw.tw(t,n).next((function(t){var n=t.nw;return t.iw.forEach((function(t,n){i.cw.set(t,n)})),n}))},n}(Zi),t}();function uu(t){return ju.dv(t,_u.store)}function su(t){return ju.dv(t,yu.store)}function ou(t){return t.path.st()}function hu(t){var n;if(t.document)n=t.document;else if(t.unknownDocument)n=t.unknownDocument;else{if(!t.noDocument)throw P("Unknown remote document type");n=t.noDocument}return JSON.stringify(n).length}var cu=function(){function t(){this.fw=new au}return t.prototype.Nv=function(t,n){return this.fw.add(n),$i.resolve()},t.prototype.Is=function(t,n){return $i.resolve(this.fw.getEntries(n))},t}(),au=function(){function t(){this.index={}}return t.prototype.add=function(t){S(t.length%2==1,"Expected a collection path.");var n=t.et(),i=t.tt(),e=this.index[n]||new Nt(Rt.X),r=!e.has(i);return this.index[n]=e.add(i),r},t.prototype.has=function(t){var n=t.et(),i=t.tt(),e=this.index[n];return e&&e.has(i)},t.prototype.getEntries=function(t){return(this.index[t]||new Nt(Rt.X)).st()},t}(),fu=9,lu=function(){function t(t){this.serializer=t}return t.prototype.createOrUpgrade=function(t,n,i,e){var r=this;S(i<e&&i>=0&&e<=fu,"Unexpected schema upgrade from v"+i+" to v{toVersion}.");var u=new Mr(n);i<1&&e>=1&&(function(t){t.createObjectStore(vu.store)}(t),function(t){t.createObjectStore(wu.store,{keyPath:wu.keyPath}),t.createObjectStore(mu.store,{keyPath:mu.keyPath,autoIncrement:!0}).createIndex(mu.userMutationsIndex,mu.userMutationsKeyPath,{unique:!0}),t.createObjectStore(pu.store)}(t),Au(t),function(t){t.createObjectStore(yu.store)}(t));var s=$i.resolve();return i<3&&e>=3&&(0!==i&&(!function(t){t.deleteObjectStore(Tu.store),t.deleteObjectStore(Iu.store),t.deleteObjectStore(Eu.store)}(t),Au(t)),s=s.next((function(){return function(t){var n=t.store(Eu.store),i=new Eu(0,0,Tt.MIN.J(),0);return n.put(Eu.key,i)}(u)}))),i<4&&e>=4&&(0!==i&&(s=s.next((function(){return function(t,n){return n.store(mu.store).Iv().next((function(i){t.deleteObjectStore(mu.store),t.createObjectStore(mu.store,{keyPath:mu.keyPath,autoIncrement:!0}).createIndex(mu.userMutationsIndex,mu.userMutationsKeyPath,{unique:!0});var e=n.store(mu.store),r=i.map((function(t){return e.put(t)}));return $i.zu(r)}))}(t,u)}))),s=s.next((function(){!function(t){t.createObjectStore(Du.store,{keyPath:Du.keyPath})}(t)}))),i<5&&e>=5&&(s=s.next((function(){return r.removeAcknowledgedMutations(u)}))),i<6&&e>=6&&(s=s.next((function(){return function(t){t.createObjectStore(_u.store)}(t),r.addDocumentGlobal(u)}))),i<7&&e>=7&&(s=s.next((function(){return r.ensureSequenceNumbers(u)}))),i<8&&e>=8&&(s=s.next((function(){return r.createCollectionParentIndex(t,u)}))),i<9&&e>=9&&(s=s.next((function(){!function(t){t.objectStoreNames.contains("remoteDocumentChanges")&&t.deleteObjectStore("remoteDocumentChanges")}(t),function(t){var n=t.objectStore(yu.store);n.createIndex(yu.readTimeIndex,yu.readTimeIndexPath,{unique:!1}),n.createIndex(yu.collectionReadTimeIndex,yu.collectionReadTimeIndexPath,{unique:!1})}(n)}))),s},t.prototype.addDocumentGlobal=function(t){var n=0;return t.store(yu.store).Av((function(t,i){n+=hu(i)})).next((function(){var i=new _u(n);return t.store(_u.store).put(_u.key,i)}))},t.prototype.removeAcknowledgedMutations=function(t){var n=this,i=t.store(wu.store),e=t.store(mu.store);return i.Iv().next((function(i){return $i.forEach(i,(function(i){var r=IDBKeyRange.bound([i.userId,-1],[i.userId,i.lastAcknowledgedBatchId]);return e.Iv(mu.userMutationsIndex,r).next((function(e){return $i.forEach(e,(function(e){S(e.userId===i.userId,"Cannot process batch "+e.batchId+" from unexpected user");var r=n.serializer.Ov(e);return Hr(t,i.userId,r).next((function(){}))}))}))}))}))},t.prototype.ensureSequenceNumbers=function(t){var n=t.store(Tu.store),i=t.store(yu.store);return iu(t).next((function(t){var e=[];return i.Av((function(i,r){var u=new Rt(i),s=function(t){return[0,Fr(t)]}(u);e.push(n.get(s).next((function(i){return i?$i.resolve():function(i){return n.put(new Tu(0,Fr(i),t))}(u)})))})).next((function(){return $i.zu(e)}))}))},t.prototype.createCollectionParentIndex=function(t,n){t.createObjectStore(Ru.store,{keyPath:Ru.keyPath});var i=n.store(Ru.store),e=new au,r=function(t){if(e.add(t)){var n=t.et(),r=t.tt();return i.put({collectionId:n,parent:Fr(r)})}};return n.store(yu.store).Av({Rv:!0},(function(t,n){var i=new Rt(t);return r(i.tt())})).next((function(){return n.store(pu.store).Av({Rv:!0},(function(t,n){t[0];var i=t[1],e=(t[2],Ur(i));return r(e.tt())}))}))},t}();var du=function(t,n){this.seconds=t,this.nanoseconds=n},vu=function(){function t(t,n,i){this.ownerId=t,this.allowTabSynchronization=n,this.leaseTimestampMs=i}return t.store="owner",t.key="owner",t}();var wu=function(){function t(t,n,i){this.userId=t,this.lastAcknowledgedBatchId=n,this.lastStreamToken=i}return t.store="mutationQueues",t.keyPath="userId",t}(),mu=function(){function t(t,n,i,e,r){this.userId=t,this.batchId=n,this.localWriteTimeMs=i,this.baseMutations=e,this.mutations=r}return t.store="mutations",t.keyPath="batchId",t.userMutationsIndex="userMutationsIndex",t.userMutationsKeyPath=["userId","batchId"],t}();var pu=function(){function t(){}return t.prefixForUser=function(t){return[t]},t.prefixForPath=function(t,n){return[t,Fr(n)]},t.key=function(t,n,i){return[t,Fr(n),i]},t.store="documentMutations",t.PLACEHOLDER=new t,t}();var gu=function(t,n){this.path=t,this.readTime=n},bu=function(t,n){this.path=t,this.version=n},yu=function(){function t(t,n,i,e,r,u){this.unknownDocument=t,this.noDocument=n,this.document=i,this.hasCommittedMutations=e,this.readTime=r,this.parentPath=u}return t.store="remoteDocuments",t.readTimeIndex="readTimeIndex",t.readTimeIndexPath="readTime",t.collectionReadTimeIndex="collectionReadTimeIndex",t.collectionReadTimeIndexPath=["parentPath","readTime"],t}(),_u=function(){function t(t){this.byteSize=t}return t.store="remoteDocumentGlobal",t.key="remoteDocumentGlobalKey",t}();var Iu=function(){function t(t,n,i,e,r,u,s){this.targetId=t,this.canonicalId=n,this.readTime=i,this.resumeToken=e,this.lastListenSequenceNumber=r,this.lastLimboFreeSnapshotVersion=u,this.query=s}return t.store="targets",t.keyPath="targetId",t.queryTargetsIndexName="queryTargetsIndex",t.queryTargetsKeyPath=["canonicalId","targetId"],t}(),Tu=function(){function t(t,n,i){this.targetId=t,this.path=n,this.sequenceNumber=i,S(0===t==(void 0!==i),"A target-document row must either have targetId == 0 and a defined sequence number, or a non-zero targetId and no sequence number")}return t.store="targetDocuments",t.keyPath=["targetId","path"],t.documentTargetsIndex="documentTargetsIndex",t.documentTargetsKeyPath=["path","targetId"],t}(),Eu=function(){function t(t,n,i,e){this.highestTargetId=t,this.highestListenSequenceNumber=n,this.lastRemoteSnapshotVersion=i,this.targetCount=e}return t.key="targetGlobalKey",t.store="targetGlobal",t}(),Ru=function(){function t(t,n){this.collectionId=t,this.parent=n}return t.store="collectionParents",t.keyPath=["collectionId","parent"],t}();function Au(t){t.createObjectStore(Tu.store,{keyPath:Tu.keyPath}).createIndex(Tu.documentTargetsIndex,Tu.documentTargetsKeyPath,{unique:!0}),t.createObjectStore(Iu.store,{keyPath:Iu.keyPath}).createIndex(Iu.queryTargetsIndexName,Iu.queryTargetsKeyPath,{unique:!0}),t.createObjectStore(Eu.store)}var Du=function(){function t(t,n,i,e){this.clientId=t,this.updateTimeMs=n,this.networkEnabled=i,this.inForeground=e}return t.store="clientMetadata",t.keyPath="clientId",t}();var Pu=[wu.store,mu.store,pu.store,yu.store,Iu.store,vu.store,Eu.store,Tu.store],Su=n(Pu,[Du.store]),Cu=n(Su,[_u.store]),Vu=n(Cu,[Ru.store]),ku=function(){function t(){this.lw=new au}return t.prototype.Nv=function(t,n){var i=this;if(S(n.length%2==1,"Expected a collection path."),!this.lw.has(n)){var e=n.et(),r=n.tt();t.ss((function(){i.lw.add(n)}));var u={collectionId:e,parent:Fr(r)};return Nu(t).put(u)}return $i.resolve()},t.prototype.Is=function(t,n){var i=[],e=IDBKeyRange.bound([n,""],[N(n),""],!1,!0);return Nu(t).Iv(e).next((function(t){for(var e=0,r=t;e<r.length;e++){var u=r[e];if(u.collectionId!==n)break;i.push(Ur(u.parent))}return i}))},t}();function Nu(t){return ju.dv(t,Ru.store)}var Ou=function(){function t(t){this.dw=t}return t.prototype.rw=function(t){if(t.document)return this.dw.Pr(t.document,!!t.hasCommittedMutations);if(t.noDocument){var n=Pt.pt(t.noDocument.path),i=this.vw(t.noDocument.readTime);return new _n(n,i,{hasCommittedMutations:!!t.hasCommittedMutations})}if(t.unknownDocument){n=Pt.pt(t.unknownDocument.path),i=this.vw(t.unknownDocument.version);return new In(n,i)}return P("Unexpected DbRemoteDocument")},t.prototype.aw=function(t,n){var i=this.ew(n),e=t.key.path.tt().st();if(t instanceof yn){var r=t.proto?t.proto:this.dw.Dr(t),u=t.hasCommittedMutations;return new yu(null,null,r,u,i,e)}if(t instanceof _n){var s=t.key.path.st(),o=this.ww(t.version);u=t.hasCommittedMutations;return new yu(null,new gu(s,o),null,u,i,e)}if(t instanceof In){s=t.key.path.st();var h=this.ww(t.version);return new yu(new bu(s,h),null,null,!0,i,e)}return P("Unexpected MaybeDocument")},t.prototype.ew=function(t){var n=t.J();return[n.seconds,n.nanoseconds]},t.prototype.uw=function(t){var n=new It(t[0],t[1]);return Tt.W(n)},t.prototype.ww=function(t){var n=t.J();return new du(n.seconds,n.nanoseconds)},t.prototype.vw=function(t){var n=new It(t.seconds,t.nanoseconds);return Tt.W(n)},t.prototype.kv=function(t,n){var i=this,e=n.baseMutations.map((function(t){return i.dw.jr(t)})),r=n.mutations.map((function(t){return i.dw.jr(t)}));return new mu(t,n.batchId,n.Gn.toMillis(),e,r)},t.prototype.Ov=function(t){var n=this,i=(t.baseMutations||[]).map((function(t){return n.dw.Mr(t)})),e=t.mutations.map((function(t){return n.dw.Mr(t)})),r=It.fromMillis(t.localWriteTimeMs);return new Hi(t.batchId,r,i,e)},t.prototype.mw=function(t){var n=[];return t.forEach((function(t){n.push(Fr(t.path))})),n},t.prototype.pw=function(t){for(var n=ci(),i=0,e=t;i<e.length;i++){var r=e[i];n=n.add(new Pt(Ur(r)))}return n},t.prototype.zv=function(t){var n,i=this.vw(t.readTime),e=void 0!==t.lastLimboFreeSnapshotVersion?this.vw(t.lastLimboFreeSnapshotVersion):Tt.MIN,r=t.resumeToken;return n=void 0!==t.query.documents?this.dw.Hr(t.query):this.dw.Zr(t.query),new Yn(n,t.targetId,kn.ki,t.lastListenSequenceNumber,i,e,r)},t.prototype.Kv=function(t){S(kn.ki===t.Fi,"Only queries with purpose "+kn.ki+" may be stored, got "+t.Fi);var n,i,e=this.ww(t.xi),r=this.ww(t.lastLimboFreeSnapshotVersion);return n=t.target.Zn()?this.dw.Kr(t.target):this.dw.Jr(t.target),t.resumeToken instanceof Uint8Array?(S(Lr.av(),"Persisting non-string stream tokens is only supported with mock persistence ."),i=t.resumeToken.toString()):i=t.resumeToken,new Iu(t.targetId,t.target.canonicalId(),e,i,t.sequenceNumber,r,n)},t}();var Fu="Another tab has exclusive access to the persistence layer. To allow shared access, make sure to invoke `enablePersistence()` with `synchronizeTabs:true` in all tabs.",xu=function(t){function n(n,i){var e=t.call(this)||this;return e.xv=n,e.Mh=i,e}return i(n,t),n}(ne),ju=function(){function t(n,i,e,r,u,s,o,h){if(this.allowTabSynchronization=n,this.persistenceKey=i,this.clientId=e,this.Wc=s,this.gw=h,this.bw=!1,this.isPrimary=!1,this.networkEnabled=!0,this.yw=null,this.inForeground=!1,this._w=null,this.Iw=null,this.Tw=Number.NEGATIVE_INFINITY,this.Ew=function(t){return Promise.resolve()},this.sh=new Bu(this,u),this.Rw=i+t.Aw,this.serializer=new Ou(o),this.document=r.document,this.fh=new Zr(this.sh,this.serializer),this.as=new ku,this.hs=new ru(this.serializer,this.as),!r.window||!r.window.localStorage)throw new Q(q.UNIMPLEMENTED,"IndexedDB persistence is only available on platforms that support LocalStorage.");this.window=r.window,this.Dw=this.window.localStorage}return t.dv=function(t,n){if(t instanceof xu)return Lr.dv(t.xv,n);throw P("IndexedDbPersistence must use instances of IndexedDbTransaction")},t.Pw=function(n){return e(this,void 0,void 0,(function(){var i;return r(this,(function(e){switch(e.label){case 0:if(!t.nl())throw new Q(q.UNIMPLEMENTED,"This platform is either missing IndexedDB or is known to have an incomplete implementation. Offline persistence has been disabled.");return[4,(i=new t(n.allowTabSynchronization,n.persistenceKey,n.clientId,n.platform,n.Sw,n.Wc,n.serializer,n.gw)).start()];case 1:return e.sent(),[2,i]}}))}))},t.prototype.start=function(){var t=this;return S(!this.qo,"IndexedDbPersistence double-started!"),S(null!==this.window,"Expected 'window' to be defined"),Lr.cv(this.Rw,fu,new lu(this.serializer)).then((function(n){return t.Cw=n,t.Vw()})).then((function(){return t.kw(),t.Nw(),t.Ow(),t.Cw.runTransaction("readonly-idempotent",[Eu.store],(function(t){return iu(t)}))})).then((function(n){t.Fw=new re(n,t.gw)})).then((function(){t.bw=!0})).catch((function(n){return t.Cw&&t.Cw.close(),Promise.reject(n)}))},t.prototype.xw=function(t){var n=this;return this.Ew=function(i){return e(n,void 0,void 0,(function(){return r(this,(function(n){return this.qo?[2,t(i)]:[2]}))}))},t(this.isPrimary)},t.prototype.jw=function(t){var n=this;this.Cw.vv((function(i){return e(n,void 0,void 0,(function(){return r(this,(function(n){switch(n.label){case 0:return null!==i.newVersion?[3,2]:[4,t()];case 1:n.sent(),n.label=2;case 2:return[2]}}))}))}))},t.prototype.cc=function(t){var n=this;this.networkEnabled!==t&&(this.networkEnabled=t,this.Wc.Xs((function(){return e(n,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return this.qo?[4,this.Vw()]:[3,2];case 1:t.sent(),t.label=2;case 2:return[2]}}))}))})))},t.prototype.Vw=function(){var t=this;return this.Cw.runTransaction("readwrite-idempotent",Vu,(function(n){return Lu(n).put(new Du(t.clientId,Date.now(),t.networkEnabled,t.inForeground)).next((function(){if(t.isPrimary)return t.Uw(n).next((function(n){n||(t.isPrimary=!1,t.Wc.Xs((function(){return t.Ew(!1)})))}))})).next((function(){return t.Lw(n)})).next((function(i){return t.isPrimary&&!i?t.Bw(n).next((function(){return!1})):!!i&&t.Mw(n).next((function(){return!0}))}))})).catch((function(n){if(!t.allowTabSynchronization)throw n;return R("IndexedDbPersistence","Releasing owner lease after error during lease refresh",n),!1})).then((function(n){t.isPrimary!==n&&t.Wc.Xs((function(){return t.Ew(n)})),t.isPrimary=n}))},t.prototype.Uw=function(t){var n=this;return Uu(t).get(vu.key).next((function(t){return $i.resolve(n.qw(t))}))},t.prototype.Qw=function(t){return Lu(t).delete(this.clientId)},t.prototype.Gw=function(){return e(this,void 0,void 0,(function(){var n=this;return r(this,(function(i){switch(i.label){case 0:return!this.isPrimary||this.Ww(this.Tw,18e5)?[3,2]:(this.Tw=Date.now(),[4,this.runTransaction("maybeGarbageCollectMultiClientState","readwrite-primary-idempotent",(function(i){var e=t.dv(i,Du.store);return e.Iv().next((function(t){var i=n.zw(t,18e5),r=t.filter((function(t){return-1===i.indexOf(t)}));return $i.forEach(r,(function(t){return e.delete(t.clientId)})).next((function(){return r}))}))}))]);case 1:i.sent().forEach((function(t){n.window.localStorage.removeItem(n.Kw(t.clientId))})),i.label=2;case 2:return[2]}}))}))},t.prototype.Ow=function(){var t=this;this.Iw=this.Wc.ao(Qi.Ls,4e3,(function(){return t.Vw().then((function(){return t.Gw()})).then((function(){return t.Ow()}))}))},t.prototype.qw=function(t){return!!t&&t.ownerId===this.clientId},t.prototype.Lw=function(t){var n=this;return Uu(t).get(vu.key).next((function(i){if(null!==i&&n.Ww(i.leaseTimestampMs,5e3)&&!n.Hw(i.ownerId)){if(n.qw(i)&&n.networkEnabled)return!0;if(!n.qw(i)){if(!i.allowTabSynchronization)throw new Q(q.FAILED_PRECONDITION,Fu);return!1}}return!(!n.networkEnabled||!n.inForeground)||Lu(t).Iv().next((function(t){return void 0===n.zw(t,5e3).find((function(t){if(n.clientId!==t.clientId){var i=!n.networkEnabled&&t.networkEnabled,e=!n.inForeground&&t.inForeground,r=n.networkEnabled===t.networkEnabled;if(i||e&&r)return!0}return!1}))}))})).next((function(t){return n.isPrimary!==t&&R("IndexedDbPersistence","Client "+(t?"is":"is not")+" eligible for a primary lease."),t}))},t.prototype.Af=function(){return e(this,void 0,void 0,(function(){var t=this;return r(this,(function(n){switch(n.label){case 0:return this.bw=!1,this.Jw(),this.Iw&&(this.Iw.cancel(),this.Iw=null),this.Yw(),this.Xw(),[4,this.Cw.runTransaction("readwrite-idempotent",[vu.store,Du.store],(function(n){return t.Bw(n).next((function(){return t.Qw(n)}))}))];case 1:return n.sent(),this.Cw.close(),this.$w(),[2]}}))}))},t.prototype.zw=function(t,n){var i=this;return t.filter((function(t){return i.Ww(t.updateTimeMs,n)&&!i.Hw(t.clientId)}))},t.prototype.sc=function(){var t=this;return this.Cw.runTransaction("readonly-idempotent",[Du.store],(function(n){return Lu(n).Iv().next((function(n){return t.zw(n,18e5).map((function(t){return t.clientId}))}))}))},t.clearPersistence=function(n){return e(this,void 0,void 0,(function(){var i;return r(this,(function(e){switch(e.label){case 0:return t.nl()?(i=n+t.Aw,[4,Lr.delete(i)]):[2,Promise.resolve()];case 1:return e.sent(),[2]}}))}))},Object.defineProperty(t.prototype,"qo",{get:function(){return this.bw},enumerable:!0,configurable:!0}),t.prototype.oh=function(t){return S(this.qo,"Cannot initialize MutationQueue before persistence is started."),zr.Sv(t,this.serializer,this.as,this.sh)},t.prototype.lh=function(){return S(this.qo,"Cannot initialize TargetCache before persistence is started."),this.fh},t.prototype.ah=function(){return S(this.qo,"Cannot initialize RemoteDocumentCache before persistence is started."),this.hs},t.prototype.vh=function(){return S(this.qo,"Cannot initialize IndexManager before persistence is started."),this.as},t.prototype.runTransaction=function(t,n,i){var e=this;R("IndexedDbPersistence","Starting transaction:",t);var r,u=n.endsWith("idempotent"),s=n.startsWith("readonly")?u?"readonly-idempotent":"readonly":u?"readwrite-idempotent":"readwrite";return this.Cw.runTransaction(s,Vu,(function(u){return r=new xu(u,e.Fw.next()),"readwrite-primary"===n||"readwrite-primary-idempotent"===n?e.Uw(u).next((function(t){return!!t||e.Lw(u)})).next((function(n){if(!n)throw A("Failed to obtain primary lease for action '"+t+"'."),e.isPrimary=!1,e.Wc.Xs((function(){return e.Ew(!1)})),new Q(q.FAILED_PRECONDITION,te);return i(r)})).next((function(t){return e.Mw(u).next((function(){return t}))})):e.Zw(u).next((function(){return i(r)}))})).then((function(t){return r.os(),t}))},t.prototype.Zw=function(t){var n=this;return Uu(t).get(vu.key).next((function(t){if(null!==t&&n.Ww(t.leaseTimestampMs,5e3)&&!n.Hw(t.ownerId)&&!n.qw(t)&&!t.allowTabSynchronization)throw new Q(q.FAILED_PRECONDITION,Fu)}))},t.prototype.Mw=function(t){var n=new vu(this.clientId,this.allowTabSynchronization,Date.now());return Uu(t).put(vu.key,n)},t.nl=function(){return Lr.nl()},t.tm=function(t){var n=t.s.projectId;return t.s.o||(n+="."+t.s.database),"firestore/"+t.persistenceKey+"/"+n+"/"},t.prototype.Bw=function(t){var n=this,i=Uu(t);return i.get(vu.key).next((function(t){return n.qw(t)?(R("IndexedDbPersistence","Releasing primary lease."),i.delete(vu.key)):$i.resolve()}))},t.prototype.Ww=function(t,n){var i=Date.now();return!(t<i-n)&&(!(t>i)||(A("Detected an update time that is in the future: "+t+" > "+i),!1))},t.prototype.kw=function(){var t=this;null!==this.document&&"function"==typeof this.document.addEventListener&&(this._w=function(){t.Wc.Xs((function(){return t.inForeground="visible"===t.document.visibilityState,t.Vw()}))},this.document.addEventListener("visibilitychange",this._w),this.inForeground="visible"===this.document.visibilityState)},t.prototype.Yw=function(){this._w&&(S(null!==this.document&&"function"==typeof this.document.addEventListener,"Expected 'document.addEventListener' to be a function"),this.document.removeEventListener("visibilitychange",this._w),this._w=null)},t.prototype.Nw=function(){var t=this;"function"==typeof this.window.addEventListener&&(this.yw=function(){t.Jw(),t.Wc.Xs((function(){return t.Af()}))},this.window.addEventListener("unload",this.yw))},t.prototype.Xw=function(){this.yw&&(S("function"==typeof this.window.removeEventListener,"Expected 'window.removeEventListener' to be a function"),this.window.removeEventListener("unload",this.yw),this.yw=null)},t.prototype.Hw=function(t){try{var n=null!==this.Dw.getItem(this.Kw(t));return R("IndexedDbPersistence","Client '"+t+"' "+(n?"is":"is not")+" zombied in LocalStorage"),n}catch(t){return A("IndexedDbPersistence","Failed to get zombied client id.",t),!1}},t.prototype.Jw=function(){try{this.Dw.setItem(this.Kw(this.clientId),String(Date.now()))}catch(t){A("Failed to set zombie client id.",t)}},t.prototype.$w=function(){try{this.Dw.removeItem(this.Kw(this.clientId))}catch(t){}},t.prototype.Kw=function(t){return"firestore_zombie_"+this.persistenceKey+"_"+t},t.Aw="main",t}();function Uu(t){return t.store(vu.store)}function Lu(t){return t.store(Du.store)}var Bu=function(){function t(t,n){this.db=t,this.nm=null,this.xo=new de(this,n)}return t.prototype.zo=function(t){var n=this.im(t);return this.db.lh().Hv(t).next((function(t){return n.next((function(n){return t+n}))}))},t.prototype.im=function(t){var n=0;return this.Ho(t,(function(t){n++})).next((function(){return n}))},t.prototype.qe=function(t,n){return this.db.lh().qe(t,n)},t.prototype.Ho=function(t,n){return this.em(t,(function(t,i){return n(i)}))},t.prototype.uh=function(t){this.nm=t},t.prototype.Pu=function(t,n){return Mu(t,n)},t.prototype.Cu=function(t,n){return Mu(t,n)},t.prototype.Jo=function(t,n,i){return this.db.lh().Jo(t,n,i)},t.prototype.jv=function(t,n){return Mu(t,n)},t.prototype.rm=function(t,n){return this.nm.xu(n)?$i.resolve(!0):function(t,n){var i=!1;return $r(t).Dv((function(e){return Kr(t,e,n).next((function(t){return t&&(i=!0),$i.resolve(!t)}))})).next((function(){return i}))}(t,n)},t.prototype.Yo=function(t,n){var i=this,e=this.db.ah().Dh(),r=[],u=0;return this.em(t,(function(s,o){if(o<=n){var h=i.rm(t,s).next((function(n){if(!n)return u++,e.ts(t,s).next((function(){return e.Zu(s),eu(t).delete([0,Fr(s.path)])}))}));r.push(h)}})).next((function(){return $i.zu(r)})).next((function(){return e.apply(t)})).next((function(){return u}))},t.prototype.removeTarget=function(t,n){var i=n.ji(t.Mh);return this.db.lh().Qh(t,i)},t.prototype.Gh=function(t,n){return Mu(t,n)},t.prototype.em=function(t,n){var i,e=eu(t),r=re.ks;return e.Av({index:Tu.documentTargetsIndex},(function(t,e){var u=t[0],s=(t[1],e.path),o=e.sequenceNumber;0===u?(r!==re.ks&&n(new Pt(Ur(i)),r),r=o,i=s):r=re.ks})).next((function(){r!==re.ks&&n(new Pt(Ur(i)),r)}))},t.prototype.$o=function(t){return this.db.ah().ow(t)},t}();function Mu(t,n){return eu(t).put(function(t,n){return new Tu(0,Fr(t.path),n)}(n,t.Mh))}var qu=function(){function t(){}return t.prototype.wh=function(t){this.um=t},t.prototype.gs=function(t,n,i,e){var r=this;return S(void 0!==this.um,"setLocalDocumentsView() not called"),n.gi()?this.sm(t,n):i.isEqual(Tt.MIN)?this.sm(t,n):this.um.ws(t,e).next((function(u){var s=r.om(n,u);return(n.Ri()||n.Ai())&&r.Zl(n.ei,s,e,i)?r.sm(t,n):(T()<=y.DEBUG&&R("IndexFreeQueryEngine","Re-using previous result from %s to execute query: %s",i.toString(),n.toString()),r.um.gs(t,n,i).next((function(t){return s.forEach((function(n){t=t.bt(n.key,n)})),t})))}))},t.prototype.om=function(t,n){var i=new Nt((function(n,i){return t.yi(n,i)}));return n.forEach((function(n,e){e instanceof yn&&t.matches(e)&&(i=i.add(e))})),i},t.prototype.Zl=function(t,n,i,e){if(i.size!==n.size)return!0;var r=t===Sn.ti?n.last():n.first();return!!r&&(r.hasPendingWrites||r.version.h(e)>0)},t.prototype.sm=function(t,n){return T()<=y.DEBUG&&R("IndexFreeQueryEngine","Using full collection scan to execute query: %s",n.toString()),this.um.gs(t,n,Tt.MIN)},t}(),Qu=function(){function t(t,n){this.as=t,this.sh=n,this.cs=[],this.hm=1,this.lastStreamToken=Li(),this.cm=new Nt(Xi.Kn)}return t.prototype.Cv=function(t){return $i.resolve(0===this.cs.length)},t.prototype.Ah=function(t,n,i){var e=n.batchId,r=this.am(e,"acknowledged");S(0===r,"Can only acknowledge the first batch in the mutation queue");var u=this.cs[r];return S(e===u.batchId,"Queue ordering failure: expected batch "+e+", got batch "+u.batchId),this.lastStreamToken=i,$i.resolve()},t.prototype.Fh=function(t){return $i.resolve(this.lastStreamToken)},t.prototype.xh=function(t,n){return this.lastStreamToken=n,$i.resolve()},t.prototype.Th=function(t,n,i,e){S(0!==e.length,"Mutation batches should not be empty");var r=this.hm;(this.hm++,this.cs.length>0)&&S(this.cs[this.cs.length-1].batchId<r,"Mutation batchIDs must be monotonically increasing order");var u=new Hi(r,n,i,e);this.cs.push(u);for(var s=0,o=e;s<o.length;s++){var h=o[s];this.cm=this.cm.add(new Xi(h.key,r)),this.as.Nv(t,h.key.path.tt())}return $i.resolve(u)},t.prototype.kh=function(t,n){return $i.resolve(this.fm(n))},t.prototype.Rh=function(t,n){var i=this.fm(n);return S(null!=i,"Failed to find local mutation batch."),$i.resolve(i.keys())},t.prototype.Jh=function(t,n){var i=n+1,e=this.lm(i),r=e<0?0:e;return $i.resolve(this.cs.length>r?this.cs[r]:null)},t.prototype.Oh=function(){return $i.resolve(0===this.cs.length?-1:this.hm-1)},t.prototype.gh=function(t){return $i.resolve(this.cs.slice())},t.prototype.ls=function(t,n){var i=this,e=new Xi(n,0),r=new Xi(n,Number.POSITIVE_INFINITY),u=[];return this.cm.zt([e,r],(function(t){S(n.isEqual(t.key),"Should only iterate over a single key's batches");var e=i.fm(t.ju);S(null!==e,"Batches in the index must exist in the main table"),u.push(e)})),$i.resolve(u)},t.prototype.ps=function(t,n){var i=this,e=new Nt(V);return n.forEach((function(t){var n=new Xi(t,0),r=new Xi(t,Number.POSITIVE_INFINITY);i.cm.zt([n,r],(function(n){S(t.isEqual(n.key),"For each key, should only iterate over a single key's batches"),e=e.add(n.ju)}))})),$i.resolve(this.dm(e))},t.prototype.Ts=function(t,n){S(!n.Pi(),"CollectionGroup queries should be handled in LocalDocumentsView");var i=n.path,e=i.length+1,r=i;Pt.vt(r)||(r=r.child(""));var u=new Xi(new Pt(r),0),s=new Nt(V);return this.cm.Kt((function(t){var n=t.key.path;return!!i.rt(n)&&(n.length===e&&(s=s.add(t.ju)),!0)}),u),$i.resolve(this.dm(s))},t.prototype.dm=function(t){var n=this,i=[];return t.forEach((function(t){var e=n.fm(t);null!==e&&i.push(e)})),i},t.prototype.Nh=function(t,n){var i=this;S(0===this.am(n.batchId,"removed"),"Can only remove the first entry of the mutation queue"),this.cs.shift();var e=this.cm;return $i.forEach(n.mutations,(function(r){var u=new Xi(r.key,n.batchId);return e=e.delete(u),i.sh.jv(t,r.key)})).next((function(){i.cm=e}))},t.prototype.hc=function(t){},t.prototype.xu=function(t,n){var i=new Xi(n,0),e=this.cm.Ht(i);return $i.resolve(n.isEqual(e&&e.key))},t.prototype.Ch=function(t){return 0===this.cs.length&&S(this.cm.nt(),"Document leak -- detected dangling mutation references when queue is empty."),$i.resolve()},t.prototype.am=function(t,n){var i=this.lm(t);return S(i>=0&&i<this.cs.length,"Batches must exist to be "+n),i},t.prototype.lm=function(t){return 0===this.cs.length?0:t-this.cs[0].batchId},t.prototype.fm=function(t){var n=this.lm(t);if(n<0||n>=this.cs.length)return null;var i=this.cs[n];return S(i.batchId===t,"If found batch must match"),i},t}();var Gu=function(){function t(t,n){this.as=t,this.vm=n,this.docs=new St(Pt.X),this.size=0}return t.prototype.Xu=function(t,n,i){S(!i.isEqual(Tt.MIN),"Cannot add a document with a read time of zero");var e=n.key,r=this.docs.get(e),u=r?r.size:0,s=this.vm(n);return this.docs=this.docs.bt(e,{$v:n,size:s,readTime:i}),this.size+=s-u,this.as.Nv(t,e.path.tt())},t.prototype.Zu=function(t){var n=this.docs.get(t);n&&(this.docs=this.docs.remove(t),this.size-=n.size)},t.prototype.ts=function(t,n){var i=this.docs.get(n);return $i.resolve(i?i.$v:null)},t.prototype.getEntries=function(t,n){var i=this,e=ei();return n.forEach((function(t){var n=i.docs.get(t);e=e.bt(t,n?n.$v:null)})),$i.resolve(e)},t.prototype.gs=function(t,n,i){S(!n.Pi(),"CollectionGroup queries should be handled in LocalDocumentsView");for(var e=ui(),r=new Pt(n.path.child("")),u=this.docs.Dt(r);u.Nt();){var s=u.kt(),o=s.key,h=s.value,c=h.$v,a=h.readTime;if(!n.path.rt(o.path))break;a.h(i)<=0||c instanceof yn&&n.matches(c)&&(e=e.bt(c.key,c))}return $i.resolve(e)},t.prototype.wm=function(t,n){return $i.forEach(this.docs,(function(t){return n(t)}))},t.prototype.fc=function(t,n){throw new Error("getNewDocumentChanges() is not supported with MemoryPersistence")},t.prototype.dc=function(t){return $i.resolve(Tt.MIN)},t.prototype.Dh=function(n){return new t.sw(this)},t.prototype.ow=function(t){return $i.resolve(this.size)},t.sw=function(t){function n(n){var i=t.call(this)||this;return i.hw=n,i}return i(n,t),n.prototype.rs=function(t){var n=this,i=[];return this.Hu.forEach((function(e,r){r?i.push(n.hw.Xu(t,r,n.readTime)):n.hw.Zu(e)})),$i.zu(i)},n.prototype.ns=function(t,n){return this.hw.ts(t,n)},n.prototype.es=function(t,n){return this.hw.getEntries(t,n)},n}(Zi),t}(),Wu=function(){function t(t){this.persistence=t,this.mm=new Ki((function(t){return t.canonicalId()})),this.lastRemoteSnapshotVersion=Tt.MIN,this.highestTargetId=0,this.pm=0,this.gm=new Yi,this.targetCount=0,this.Uv=br.Ql()}return t.prototype.qe=function(t,n){return this.mm.forEach((function(t,i){return n(i)})),$i.resolve()},t.prototype.jh=function(t){return $i.resolve(this.lastRemoteSnapshotVersion)},t.prototype.Mv=function(t){return $i.resolve(this.pm)},t.prototype.Zh=function(t){var n=this.Uv.after(this.highestTargetId);return this.highestTargetId=n,$i.resolve(n)},t.prototype.Wh=function(t,n,i){return i&&(this.lastRemoteSnapshotVersion=i),n>this.pm&&(this.pm=n),$i.resolve()},t.prototype.qv=function(t){this.mm.set(t.target,t);var n=t.targetId;n>this.highestTargetId&&(this.highestTargetId=n),t.sequenceNumber>this.pm&&(this.pm=t.sequenceNumber)},t.prototype.tc=function(t,n){return S(!this.mm.has(n.target),"Adding a target that already exists"),this.qv(n),this.targetCount+=1,$i.resolve()},t.prototype.Qh=function(t,n){return S(this.mm.has(n.target),"Updating a non-existent target"),this.qv(n),$i.resolve()},t.prototype.Gv=function(t,n){return S(this.targetCount>0,"Removing a target from an empty cache"),S(this.mm.has(n.target),"Removing a non-existent target from the cache"),this.mm.delete(n.target),this.gm.Nu(n.targetId),this.targetCount-=1,$i.resolve()},t.prototype.Jo=function(t,n,i){var e=this,r=0,u=[];return this.mm.forEach((function(s,o){o.sequenceNumber<=n&&null===i.get(o.targetId)&&(e.mm.delete(s),u.push(e.Wv(t,o.targetId)),r++)})),$i.zu(u).next((function(){return r}))},t.prototype.Hv=function(t){return $i.resolve(this.targetCount)},t.prototype.$h=function(t,n){var i=this.mm.get(n)||null;return $i.resolve(i)},t.prototype.Ze=function(t,n){return P("Not yet implemented.")},t.prototype.Bh=function(t,n,i){this.gm.Su(n,i);var e=this.persistence.sh,r=[];return e&&n.forEach((function(n){r.push(e.Pu(t,n))})),$i.zu(r)},t.prototype.Lh=function(t,n,i){this.gm.ku(n,i);var e=this.persistence.sh,r=[];return e&&n.forEach((function(n){r.push(e.Cu(t,n))})),$i.zu(r)},t.prototype.Wv=function(t,n){return this.gm.Nu(n),$i.resolve()},t.prototype.ec=function(t,n){var i=this.gm.Fu(n);return $i.resolve(i)},t.prototype.xu=function(t,n){return $i.resolve(this.gm.xu(n))},t}(),zu=function(){function t(t,n){var i=this;this.clientId=t,this.bm={},this.Fw=new re(0),this.bw=!1,this.bw=!0,this.sh=n(this),this.fh=new Wu(this);this.as=new cu,this.hs=new Gu(this.as,(function(t){return i.sh.ym(t)}))}return t._m=function(n,i){return new t(n,(function(t){return new Ju(t,i)}))},t.Im=function(n){return new t(n,(function(t){return new Hu(t)}))},t.prototype.Af=function(){return this.bw=!1,Promise.resolve()},Object.defineProperty(t.prototype,"qo",{get:function(){return this.bw},enumerable:!0,configurable:!0}),t.prototype.sc=function(){return e(this,void 0,void 0,(function(){return r(this,(function(t){return[2,[this.clientId]]}))}))},t.prototype.xw=function(t){return t(!0)},t.prototype.jw=function(){},t.prototype.cc=function(t){},t.prototype.vh=function(){return this.as},t.prototype.oh=function(t){var n=this.bm[t.I()];return n||(n=new Qu(this.as,this.sh),this.bm[t.I()]=n),n},t.prototype.lh=function(){return this.fh},t.prototype.ah=function(){return this.hs},t.prototype.runTransaction=function(t,n,i){var e=this;R("MemoryPersistence","Starting transaction:",t);var r=new Ku(this.Fw.next());return this.sh.Tm(),i(r).next((function(t){return e.sh.Em(r).next((function(){return t}))})).Gu().then((function(t){return r.os(),t}))},t.prototype.Rm=function(t,n){return $i.Ku((i=this.bm,e=[],Z(i,(function(t,n){return e.push(n)})),e).map((function(i){return function(){return i.xu(t,n)}})));var i,e},t}(),Ku=function(t){function n(n){var i=t.call(this)||this;return i.Mh=n,i}return i(n,t),n}(ne),Hu=function(){function t(t){this.persistence=t,this.nm=null,this.Am=null}return Object.defineProperty(t.prototype,"Dm",{get:function(){if(this.Am)return this.Am;throw P("orphanedDocuments is only valid during a transaction.")},enumerable:!0,configurable:!0}),t.prototype.uh=function(t){this.nm=t},t.prototype.Pu=function(t,n){return this.Dm.delete(n),$i.resolve()},t.prototype.Cu=function(t,n){return this.Dm.add(n),$i.resolve()},t.prototype.jv=function(t,n){return this.Dm.add(n),$i.resolve()},t.prototype.removeTarget=function(t,n){var i=this,e=this.persistence.lh();return e.ec(t,n.targetId).next((function(t){t.forEach((function(t){return i.Dm.add(t)}))})).next((function(){return e.Gv(t,n)}))},t.prototype.Tm=function(){this.Am=new Set},t.prototype.Em=function(t){var n=this,i=this.persistence.ah().Dh();return $i.forEach(this.Dm,(function(e){return n.Pm(t,e).next((function(t){t||i.Zu(e)}))})).next((function(){return n.Am=null,i.apply(t)}))},t.prototype.Gh=function(t,n){var i=this;return this.Pm(t,n).next((function(t){t?i.Dm.delete(n):i.Dm.add(n)}))},t.prototype.ym=function(t){return 0},t.prototype.Pm=function(t,n){var i=this;return $i.Ku([function(){return i.persistence.lh().xu(t,n)},function(){return i.persistence.Rm(t,n)},function(){return $i.resolve(i.nm.xu(n))}])},t}(),Ju=function(){function t(t,n){this.persistence=t,this.nm=null,this.Sm=new Ki((function(t){return Fr(t.path)})),this.xo=new de(this,n)}return t.prototype.Tm=function(){},t.prototype.Em=function(t){return $i.resolve()},t.prototype.qe=function(t,n){return this.persistence.lh().qe(t,n)},t.prototype.zo=function(t){var n=this.Cm(t);return this.persistence.lh().Hv(t).next((function(t){return n.next((function(n){return t+n}))}))},t.prototype.Cm=function(t){var n=0;return this.Ho(t,(function(t){n++})).next((function(){return n}))},t.prototype.Ho=function(t,n){var i=this;return $i.forEach(this.Sm,(function(e,r){return i.rm(t,e,r).next((function(t){return t?$i.resolve():n(r)}))}))},t.prototype.uh=function(t){this.nm=t},t.prototype.Jo=function(t,n,i){return this.persistence.lh().Jo(t,n,i)},t.prototype.Yo=function(t,n){var i=this,e=0,r=this.persistence.ah(),u=r.Dh();return r.wm(t,(function(r){return i.rm(t,r,n).next((function(t){t||(e++,u.Zu(r))}))})).next((function(){return u.apply(t)})).next((function(){return e}))},t.prototype.jv=function(t,n){return this.Sm.set(n,t.Mh),$i.resolve()},t.prototype.removeTarget=function(t,n){var i=n.ji(t.Mh);return this.persistence.lh().Qh(t,i)},t.prototype.Pu=function(t,n){return this.Sm.set(n,t.Mh),$i.resolve()},t.prototype.Cu=function(t,n){return this.Sm.set(n,t.Mh),$i.resolve()},t.prototype.Gh=function(t,n){return this.Sm.set(n,t.Mh),$i.resolve()},t.prototype.ym=function(t){var n=t.key.toString().length;return t instanceof yn&&(n+=t.data().Ln()),n},t.prototype.rm=function(t,n,i){var e=this;return $i.Ku([function(){return e.persistence.Rm(t,n)},function(){return $i.resolve(e.nm.xu(n))},function(){return e.persistence.lh().xu(t,n)},function(){var t=e.Sm.get(n);return $i.resolve(void 0!==t&&t>i)}])},t.prototype.$o=function(t){return this.persistence.ah().ow(t)},t}(),Yu=function(){function t(t,n){this.cacheSizeBytes=t,this.synchronizeTabs=n}return t.prototype.Sw=function(){return fe.So(this.cacheSizeBytes)},t}(),Xu=function(){},$u=function(){function t(t,n,i,e){this.platform=t,this.Vm=n,this.credentials=i,this.qs=e,this.clientId=C.u()}return t.prototype.start=function(t){var n=this;this.km();var i=new ue,e=new ue,r=!1;return this.credentials.S((function(u){r?n.qs.Xs((function(){return n.Gf(u)})):(r=!0,n.Nm(t,e,u).then((function(t){return n.Om(u,t)})).then(i.resolve,i.reject))})),this.qs.Xs((function(){return i.promise})),e.promise},t.prototype.enableNetwork=function(){var t=this;return this.km(),this.qs.enqueue((function(){return t.Cf.enableNetwork()}))},t.prototype.Nm=function(t,n,i){var e=this;return t instanceof Yu?this.Fm(i,t).then((function(t){return n.resolve(),t})).catch((function(t){if(n.reject(t),!e.xm(t))throw t;return console.warn("Error enabling offline persistence. Falling back to persistence disabled: "+t),e.jm()})):(n.resolve(),this.jm())},t.prototype.xm=function(t){return t instanceof Q?t.code===q.FAILED_PRECONDITION||t.code===q.UNIMPLEMENTED:!("undefined"!=typeof DOMException&&t instanceof DOMException)||(22===t.code||20===t.code||11===t.code)},t.prototype.km=function(){if(this.qs.ro)throw new Q(q.FAILED_PRECONDITION,"The client has already been terminated.")},t.prototype.Fm=function(t,n){var i=this,u=ju.tm(this.Vm),s=new ji(this.Vm.s,{nr:!0});return Promise.resolve().then((function(){return e(i,void 0,void 0,(function(){var i,e;return r(this,(function(r){switch(r.label){case 0:if(n.synchronizeTabs&&!vr.nl(this.platform))throw new Q(q.UNIMPLEMENTED,"IndexedDB persistence is only available on platforms that support LocalStorage.");return i=n.Sw(),this.pd=n.synchronizeTabs?new vr(this.qs,this.platform,u,this.clientId,t):new pr,[4,ju.Pw({allowTabSynchronization:n.synchronizeTabs,persistenceKey:u,clientId:this.clientId,platform:this.platform,Wc:this.qs,serializer:s,Sw:i,gw:this.pd})];case 1:return e=r.sent(),this.persistence=e,[2,e.sh.xo]}}))}))}))},t.prototype.jm=function(){return this.persistence=zu.Im(this.clientId),this.pd=new pr,Promise.resolve(null)},t.prototype.Om=function(t,n){var i=this;return R("FirestoreClient","Initializing. user=",t.uid),this.platform.Um(this.Vm).then((function(u){return e(i,void 0,void 0,(function(){var i,s,o,h,c,a,f=this;return r(this,(function(l){switch(l.label){case 0:return i=new qu,this.jo=new we(this.persistence,i,t),[4,this.jo.start()];case 1:return l.sent(),n&&(this.Lm=new le(n,this.qs,this.jo)),s=this.platform.Bm(),o=this.platform.Mm(this.Vm.s),h=new Je(this.qs,u,this.credentials,o),c=function(t){return f.Cf.rd(t,x.p)},a=function(t){return f.Cf.rd(t,x.g)},this.hd=new Ze(this.jo,h,this.qs,c,s),this.Cf=new Dr(this.jo,this.hd,this.pd,t),this.pd.Ja=a,this.hd.Cf=this.Cf,this.pd.Cf=this.Cf,this.qm=new Sr(this.Cf),[4,this.pd.start()];case 2:return l.sent(),[4,this.hd.start()];case 3:return l.sent(),[4,this.persistence.xw((function(t){return e(f,void 0,void 0,(function(){return r(this,(function(n){switch(n.label){case 0:return[4,this.Cf.Wf(t)];case 1:return n.sent(),this.Lm&&(t&&!this.Lm.qo?this.Lm.start():t||this.Lm.stop()),[2]}}))}))}))];case 4:return l.sent(),[4,this.persistence.jw((function(){return e(f,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return[4,this.terminate()];case 1:return t.sent(),[2]}}))}))}))];case 5:return l.sent(),[2]}}))}))}))},t.prototype.Gf=function(t){return this.qs.lo(),R("FirestoreClient","Credential Changed. Current user: "+t.uid),this.Cf.Gf(t)},t.prototype.disableNetwork=function(){var t=this;return this.km(),this.qs.enqueue((function(){return t.Cf.disableNetwork()}))},t.prototype.terminate=function(){var t=this;return this.qs.co((function(){return e(t,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return this.Lm&&this.Lm.stop(),[4,this.hd.Af()];case 1:return t.sent(),[4,this.pd.Af()];case 2:return t.sent(),[4,this.persistence.Af()];case 3:return t.sent(),this.credentials.C(),[2]}}))}))}))},t.prototype.waitForPendingWrites=function(){var t=this;this.km();var n=new ue;return this.qs.Xs((function(){return t.Cf.Ud(n)})),n.promise},t.prototype.listen=function(t,n,i){var e=this;this.km();var r=new Cr(t,n,i);return this.qs.Xs((function(){return e.qm.listen(r)})),r},t.prototype.Pf=function(t){var n=this;this.Qm||this.qs.Xs((function(){return n.qm.Pf(t)}))},t.prototype.Gm=function(t){var n=this;return this.km(),this.qs.enqueue((function(){return n.jo.Yh(t)})).then((function(t){if(t instanceof yn)return t;if(t instanceof _n)return null;throw new Q(q.UNAVAILABLE,"Failed to get document from cache. (However, this document may exist on the server. Run again without setting 'source' in the GetOptions to attempt to retrieve the document from the server.)")}))},t.prototype.Wm=function(t){var n=this;return this.km(),this.qs.enqueue((function(){return e(n,void 0,void 0,(function(){var n,i,e;return r(this,(function(r){switch(r.label){case 0:return[4,this.jo.ic(t,!0)];case 1:return n=r.sent(),i=new Ir(t,n.rc),e=i.Yl(n.documents),[2,i.rs(e,!1).snapshot]}}))}))}))},t.prototype.write=function(t){var n=this;this.km();var i=new ue;return this.qs.Xs((function(){return n.Cf.write(t,i)})),i.promise},t.prototype.s=function(){return this.Vm.s},t.prototype.Zd=function(t){var n=this;this.km(),this.qs.Xs((function(){return n.qm.Zd(t),Promise.resolve()}))},t.prototype.tv=function(t){this.Qm||this.qm.tv(t)},Object.defineProperty(t.prototype,"Qm",{get:function(){return this.qs.ro},enumerable:!0,configurable:!0}),t.prototype.transaction=function(t){var n=this;this.km();var i=new ue;return this.qs.Xs((function(){return n.Cf.runTransaction(n.qs,t,i),Promise.resolve()})),i.promise},t}(),Zu=function(){function t(t){this.observer=t,this.muted=!1}return t.prototype.next=function(t){this.zm(this.observer.next,t)},t.prototype.error=function(t){this.zm(this.observer.error,t)},t.prototype.Km=function(){this.muted=!0},t.prototype.zm=function(t,n){var i=this;this.muted||setTimeout((function(){i.muted||t(n)}),0)},t}();function ts(t){return function(t,n){if("object"!=typeof t||null===t)return!1;for(var i=t,e=0,r=n;e<r.length;e++){var u=r[e];if(u in i&&"function"==typeof i[u])return!0}return!1}(t,["next","error","complete"])}var ns="firestore.googleapis.com",is=!0,es=!0,rs=!1,us=fe.ko,ss=function(){function t(t){if(void 0===t.host){if(void 0!==t.ssl)throw new Q(q.INVALID_ARGUMENT,"Can't provide ssl option if host option is not set");this.host=ns,this.ssl=is}else ot("settings","non-empty string","host",t.host),this.host=t.host,ht("settings","boolean","ssl",t.ssl),this.ssl=X(t.ssl,is);if(mt("settings",t,["host","ssl","credentials","timestampsInSnapshots","cacheSizeBytes","experimentalForceLongPolling"]),ht("settings","object","credentials",t.credentials),this.credentials=t.credentials,ht("settings","boolean","timestampsInSnapshots",t.timestampsInSnapshots),!0===t.timestampsInSnapshots?A("\n The timestampsInSnapshots setting now defaults to true and you no\n longer need to explicitly set it. In a future release, the setting\n will be removed entirely and so it is recommended that you remove it\n from your firestore.settings() call now."):!1===t.timestampsInSnapshots&&A("\n The timestampsInSnapshots setting will soon be removed. YOU MUST UPDATE\n YOUR CODE.\n\n To hide this warning, stop using the timestampsInSnapshots setting in your\n firestore.settings({ ... }) call.\n\n Once you remove the setting, Timestamps stored in Cloud Firestore will be\n read back as Firebase Timestamp objects instead of as system Date objects.\n So you will also need to update code expecting a Date to instead expect a\n Timestamp. For example:\n\n // Old:\n const date = snapshot.get('created_at');\n // New:\n const timestamp = snapshot.get('created_at'); const date =\n timestamp.toDate();\n\n Please audit all existing usages of Date when you enable the new\n behavior."),this.timestampsInSnapshots=X(t.timestampsInSnapshots,es),ht("settings","number","cacheSizeBytes",t.cacheSizeBytes),void 0===t.cacheSizeBytes)this.cacheSizeBytes=fe.Oo;else{if(t.cacheSizeBytes!==us&&t.cacheSizeBytes<fe.No)throw new Q(q.INVALID_ARGUMENT,"cacheSizeBytes must be at least "+fe.No);this.cacheSizeBytes=t.cacheSizeBytes}ht("settings","boolean","experimentalForceLongPolling",t.experimentalForceLongPolling),this.forceLongPolling=void 0===t.experimentalForceLongPolling?rs:t.experimentalForceLongPolling}return t.prototype.isEqual=function(t){return this.host===t.host&&this.ssl===t.ssl&&this.timestampsInSnapshots===t.timestampsInSnapshots&&this.credentials===t.credentials&&this.cacheSizeBytes===t.cacheSizeBytes&&this.forceLongPolling===t.forceLongPolling},t}(),os=function(){function t(n,i){var u=this;if(this.Hm=null,this.Jm=new oe,this.INTERNAL={delete:function(){return e(u,void 0,void 0,(function(){return r(this,(function(t){switch(t.label){case 0:return this.Ym(),[4,this.Xm.terminate()];case 1:return t.sent(),[2]}}))}))}},"object"==typeof n.options){var s=n;this.Hm=s,this.$m=t.Zm(s),this.tp=s.name,this.np=new z(i)}else{var o=n;if(!o.projectId)throw new Q(q.INVALID_ARGUMENT,"Must provide projectId");this.$m=new B(o.projectId,o.database),this.tp="[DEFAULT]",this.np=new W}this.ip=new ss({}),this.ep=this.rp(this.$m)}return t.prototype.settings=function(t){if(it("Firestore.settings",arguments,1),ut("Firestore.settings","object",1,t),Y(t,"persistence"))throw new Q(q.INVALID_ARGUMENT,'"persistence" is now specified with a separate call to firestore.enablePersistence().');var n=new ss(t);if(this.Xm&&!this.ip.isEqual(n))throw new Q(q.FAILED_PRECONDITION,"Firestore has already been started and its settings can no longer be changed. You can only call settings() before calling any other methods on a Firestore object.");this.ip=n,void 0!==n.credentials&&(this.np=J(n.credentials))},t.prototype.enableNetwork=function(){return this.Ym(),this.Xm.enableNetwork()},t.prototype.disableNetwork=function(){return this.Ym(),this.Xm.disableNetwork()},t.prototype.enablePersistence=function(t){if(this.Xm)throw new Q(q.FAILED_PRECONDITION,"Firestore has already been started and persistence can no longer be enabled. You can only call enablePersistence() before calling any other methods on a Firestore object.");var n=!1;return t&&(void 0!==t.experimentalTabSynchronization&&A("The 'experimentalTabSynchronization' setting has been renamed to 'synchronizeTabs'. In a future release, the setting will be removed and it is recommended that you update your firestore.enablePersistence() call to use 'synchronizeTabs'."),n=X(void 0!==t.synchronizeTabs?t.synchronizeTabs:t.experimentalTabSynchronization,!1)),this.up(new Yu(this.ip.cacheSizeBytes,n))},t.prototype.clearPersistence=function(){var t=this,n=ju.tm(this.sp()),i=new ue;return this.Jm.uo((function(){return e(t,void 0,void 0,(function(){var t;return r(this,(function(e){switch(e.label){case 0:if(e.trys.push([0,2,,3]),void 0!==this.Xm&&!this.Xm.Qm)throw new Q(q.FAILED_PRECONDITION,"Persistence cannot be cleared after this Firestore instance is initialized.");return[4,ju.clearPersistence(n)];case 1:return e.sent(),i.resolve(),[3,3];case 2:return t=e.sent(),i.reject(t),[3,3];case 3:return[2]}}))}))})),i.promise},t.prototype.terminate=function(){return this.app._removeServiceInstance("firestore"),this.INTERNAL.delete()},Object.defineProperty(t.prototype,"hp",{get:function(){return this.Ym(),this.Xm.Qm},enumerable:!0,configurable:!0}),t.prototype.waitForPendingWrites=function(){return this.Ym(),this.Xm.waitForPendingWrites()},t.prototype.onSnapshotsInSync=function(t){if(this.Ym(),ts(t))return this.cp(t);ut("Firestore.onSnapshotsInSync","function",1,t);var n={next:t};return this.cp(n)},t.prototype.cp=function(t){var n=this,i=new Zu({next:function(){t.next&&t.next()},error:function(t){throw P("Uncaught Error in onSnapshotsInSync")}});return this.Xm.Zd(i),function(){i.Km(),n.Xm.tv(i)}},t.prototype.Ym=function(){return this.Xm||this.up(new Xu),this.Xm},t.prototype.sp=function(){return new U(this.$m,this.tp,this.ip.host,this.ip.ssl,this.ip.forceLongPolling)},t.prototype.up=function(t){S(!!this.ip.host,"FirestoreSettings.host is not set"),S(!this.Xm,"configureClient() called multiple times");var n=this.sp();return this.Xm=new $u(Ui.t(),n,this.np,this.Jm),this.Xm.start(t)},t.prototype.rp=function(t){return new Oe((function(n){if(n instanceof as){var i=t,e=n.firestore.$m;if(!e.isEqual(i))throw new Q(q.INVALID_ARGUMENT,"Document reference is for database "+e.projectId+"/"+e.database+" but should be for database "+i.projectId+"/"+i.database);return new Ne(t,n.ap)}return n}))},t.Zm=function(t){var n=t.options;if(!Y(n,"projectId"))throw new Q(q.INVALID_ARGUMENT,'"projectId" not provided in firebase.initializeApp.');var i=n.projectId;if(!i||"string"!=typeof i)throw new Q(q.INVALID_ARGUMENT,"projectId must be a string in FirebaseApp.options");return new B(i)},Object.defineProperty(t.prototype,"app",{get:function(){if(!this.Hm)throw new Q(q.FAILED_PRECONDITION,"Firestore was not initialized using the Firebase SDK. 'app' is not available");return this.Hm},enumerable:!0,configurable:!0}),t.prototype.collection=function(t){return it("Firestore.collection",arguments,1),ut("Firestore.collection","non-empty string",1,t),this.Ym(),new ms(Rt.ht(t),this)},t.prototype.doc=function(t){return it("Firestore.doc",arguments,1),ut("Firestore.doc","non-empty string",1,t),this.Ym(),as.fp(Rt.ht(t),this)},t.prototype.collectionGroup=function(t){if(it("Firestore.collectionGroup",arguments,1),ut("Firestore.collectionGroup","non-empty string",1,t),t.indexOf("/")>=0)throw new Q(q.INVALID_ARGUMENT,"Invalid collection ID '"+t+"' passed to function Firestore.collectionGroup(). Collection IDs must not contain '/'.");return this.Ym(),new vs(new On(Rt.ct,t),this)},t.prototype.runTransaction=function(t){var n=this;return it("Firestore.runTransaction",arguments,1),ut("Firestore.runTransaction","function",1,t),this.Ym().transaction((function(i){return t(new hs(n,i))}))},t.prototype.batch=function(){return this.Ym(),new cs(this)},Object.defineProperty(t,"logLevel",{get:function(){switch(T()){case y.DEBUG:return"debug";case y.ERROR:return"error";case y.SILENT:return"silent";default:return P("Unknown log level: "+T())}},enumerable:!0,configurable:!0}),t.setLogLevel=function(t){switch(it("Firestore.setLogLevel",arguments,1),ut("Firestore.setLogLevel","non-empty string",1,t),t){case"debug":E(y.DEBUG);break;case"error":E(y.ERROR);break;case"silent":E(y.SILENT);break;default:throw new Q(q.INVALID_ARGUMENT,"Invalid log level: "+t)}},t.prototype.lp=function(){return this.ip.timestampsInSnapshots},t}(),hs=function(){function t(t,n){this.dp=t,this.vp=n}return t.prototype.get=function(t){var n=this;it("Transaction.get",arguments,1);var i=ys("Transaction.get",t,this.dp);return this.vp.La([i.ap]).then((function(t){if(!t||1!==t.length)return P("Mismatch in docs returned from document lookup.");var e=t[0];if(e instanceof _n)return new ls(n.dp,i.ap,null,!1,!1,i.wp);if(e instanceof yn)return new ls(n.dp,i.ap,e,!1,!1,i.wp);throw P("BatchGetDocumentsRequest returned unexpected document type: "+e.constructor.name)}))},t.prototype.set=function(t,n,i){rt("Transaction.set",arguments,2,3);var e=ys("Transaction.set",t,this.dp);i=ps("Transaction.set",i);var r=Is(e.wp,n,"Transaction.set"),u=r[0],s=r[1],o=i.merge||i.mergeFields?this.dp.ep.Fc(s,u,i.mergeFields):this.dp.ep.Nc(s,u);return this.vp.set(e.ap,o),this},t.prototype.update=function(t,n,i){for(var e,r,u=[],s=3;s<arguments.length;s++)u[s-3]=arguments[s];return"string"==typeof n||n instanceof pe?(et("Transaction.update",arguments,3),e=ys("Transaction.update",t,this.dp),r=this.dp.ep.Uc("Transaction.update",n,i,u)):(it("Transaction.update",arguments,2),e=ys("Transaction.update",t,this.dp),r=this.dp.ep.xc("Transaction.update",n)),this.vp.update(e.ap,r),this},t.prototype.delete=function(t){it("Transaction.delete",arguments,1);var n=ys("Transaction.delete",t,this.dp);return this.vp.delete(n.ap),this},t}(),cs=function(){function t(t){this.dp=t,this.mp=[],this.pp=!1}return t.prototype.set=function(t,n,i){rt("WriteBatch.set",arguments,2,3),this.gp();var e=ys("WriteBatch.set",t,this.dp);i=ps("WriteBatch.set",i);var r=Is(e.wp,n,"WriteBatch.set"),u=r[0],s=r[1],o=i.merge||i.mergeFields?this.dp.ep.Fc(s,u,i.mergeFields):this.dp.ep.Nc(s,u);return this.mp=this.mp.concat(o.bc(e.ap,Jt.NONE)),this},t.prototype.update=function(t,n,i){for(var e,r,u=[],s=3;s<arguments.length;s++)u[s-3]=arguments[s];return this.gp(),"string"==typeof n||n instanceof pe?(et("WriteBatch.update",arguments,3),e=ys("WriteBatch.update",t,this.dp),r=this.dp.ep.Uc("WriteBatch.update",n,i,u)):(it("WriteBatch.update",arguments,2),e=ys("WriteBatch.update",t,this.dp),r=this.dp.ep.xc("WriteBatch.update",n)),this.mp=this.mp.concat(r.bc(e.ap,Jt.exists(!0))),this},t.prototype.delete=function(t){it("WriteBatch.delete",arguments,1),this.gp();var n=ys("WriteBatch.delete",t,this.dp);return this.mp=this.mp.concat(new tn(n.ap,Jt.NONE)),this},t.prototype.commit=function(){return e(this,void 0,void 0,(function(){return r(this,(function(t){return this.gp(),this.pp=!0,this.mp.length>0?[2,this.dp.Ym().write(this.mp)]:[2]}))}))},t.prototype.gp=function(){if(this.pp)throw new Q(q.FAILED_PRECONDITION,"A write batch can no longer be used after commit() has been called.")},t}(),as=function(){function t(t,n,i){this.ap=t,this.firestore=n,this.wp=i,this.Xm=this.firestore.Ym()}return t.fp=function(n,i,e){if(n.length%2!=0)throw new Q(q.INVALID_ARGUMENT,"Invalid document reference. Document references must have an even number of segments, but "+n.ot()+" has "+n.length);return new t(new Pt(n),i,e)},Object.defineProperty(t.prototype,"id",{get:function(){return this.ap.path.et()},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"parent",{get:function(){return new ms(this.ap.path.tt(),this.firestore,this.wp)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"path",{get:function(){return this.ap.path.ot()},enumerable:!0,configurable:!0}),t.prototype.collection=function(t){if(it("DocumentReference.collection",arguments,1),ut("DocumentReference.collection","non-empty string",1,t),!t)throw new Q(q.INVALID_ARGUMENT,"Must provide a non-empty collection name to collection()");var n=Rt.ht(t);return new ms(this.ap.path.child(n),this.firestore)},t.prototype.isEqual=function(n){if(!(n instanceof t))throw pt("isEqual","DocumentReference",1,n);return this.firestore===n.firestore&&this.ap.isEqual(n.ap)&&this.wp===n.wp},t.prototype.set=function(t,n){rt("DocumentReference.set",arguments,1,2),n=ps("DocumentReference.set",n);var i=Is(this.wp,t,"DocumentReference.set"),e=i[0],r=i[1],u=n.merge||n.mergeFields?this.firestore.ep.Fc(r,e,n.mergeFields):this.firestore.ep.Nc(r,e);return this.Xm.write(u.bc(this.ap,Jt.NONE))},t.prototype.update=function(t,n){for(var i,e=[],r=2;r<arguments.length;r++)e[r-2]=arguments[r];return"string"==typeof t||t instanceof pe?(et("DocumentReference.update",arguments,2),i=this.firestore.ep.Uc("DocumentReference.update",t,n,e)):(it("DocumentReference.update",arguments,1),i=this.firestore.ep.xc("DocumentReference.update",t)),this.Xm.write(i.bc(this.ap,Jt.exists(!0)))},t.prototype.delete=function(){return it("DocumentReference.delete",arguments,0),this.Xm.write([new tn(this.ap,Jt.NONE)])},t.prototype.onSnapshot=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];rt("DocumentReference.onSnapshot",arguments,1,4);var i,e={includeMetadataChanges:!1},r=0;"object"!=typeof t[r]||ts(t[r])||(mt("DocumentReference.onSnapshot",e=t[r],["includeMetadataChanges"]),ht("DocumentReference.onSnapshot","boolean","includeMetadataChanges",e.includeMetadataChanges),r++);var u={includeMetadataChanges:e.includeMetadataChanges};return ts(t[r])?i=t[r]:(ut("DocumentReference.onSnapshot","function",r,t[r]),st("DocumentReference.onSnapshot","function",r+1,t[r+1]),st("DocumentReference.onSnapshot","function",r+2,t[r+2]),i={next:t[r],error:t[r+1],complete:t[r+2]}),this.bp(u,i)},t.prototype.bp=function(t,n){var i=this,e=function(t){console.error("Uncaught Error in onSnapshot:",t)};n.error&&(e=n.error.bind(n));var r=new Zu({next:function(t){if(n.next){S(t.docs.size<=1,"Too many documents returned on a document query");var e=t.docs.get(i.ap);n.next(new ls(i.firestore,i.ap,e,t.fromCache,t.hasPendingWrites,i.wp))}},error:e}),u=this.Xm.listen(On.oi(this.ap.path),r,t);return function(){r.Km(),i.Xm.Pf(u)}},t.prototype.get=function(t){var n=this;return rt("DocumentReference.get",arguments,0,1),bs("DocumentReference.get",t),new Promise((function(i,e){t&&"cache"===t.source?n.firestore.Ym().Gm(n.ap).then((function(t){i(new ls(n.firestore,n.ap,t,!0,t instanceof yn&&t.vn,n.wp))}),e):n.yp(i,e,t)}))},t.prototype.yp=function(t,n,i){var e=this.bp({includeMetadataChanges:!0,ov:!0},{next:function(r){e(),!r.exists&&r.metadata.fromCache?n(new Q(q.UNAVAILABLE,"Failed to get document because the client is offline.")):r.exists&&r.metadata.fromCache&&i&&"server"===i.source?n(new Q(q.UNAVAILABLE,'Failed to get document from server. (However, this document does exist in the local cache. Run again without setting source to "server" to retrieve the cached document.)')):t(r)},error:n})},t.prototype.withConverter=function(n){return new t(this.ap,this.firestore,n)},t}(),fs=function(){function t(t,n){this.hasPendingWrites=t,this.fromCache=n}return t.prototype.isEqual=function(t){return this.hasPendingWrites===t.hasPendingWrites&&this.fromCache===t.fromCache},t}(),ls=function(){function t(t,n,i,e,r,u){this.dp=t,this.ap=n,this._p=i,this.Ip=e,this.Tp=r,this.wp=u}return t.prototype.data=function(t){if(rt("DocumentSnapshot.data",arguments,0,1),t=gs("DocumentSnapshot.data",t),this._p){if(this.wp){var n=new ds(this.dp,this.ap,this._p,this.Ip,this.Tp);return this.wp.fromFirestore(n,t)}return this.Ep(this._p.data(),en.xn(t,this.dp.lp()))}},t.prototype.get=function(t,n){if(rt("DocumentSnapshot.get",arguments,1,2),n=gs("DocumentSnapshot.get",n),this._p){var i=this._p.data().field(je("DocumentSnapshot.get",t));if(null!==i)return this.Rp(i,en.xn(n,this.dp.lp()))}},Object.defineProperty(t.prototype,"id",{get:function(){return this.ap.path.et()},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"ref",{get:function(){return new as(this.ap,this.dp,this.wp)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"exists",{get:function(){return null!==this._p},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"metadata",{get:function(){return new fs(this.Tp,this.Ip)},enumerable:!0,configurable:!0}),t.prototype.isEqual=function(n){if(!(n instanceof t))throw pt("isEqual","DocumentSnapshot",1,n);return this.dp===n.dp&&this.Ip===n.Ip&&this.ap.isEqual(n.ap)&&(null===this._p?null===n._p:this._p.isEqual(n._p))&&this.wp===n.wp},t.prototype.Ep=function(t,n){var i=this,e={};return t.forEach((function(t,r){e[t]=i.Rp(r,n)})),e},t.prototype.Rp=function(t,n){if(t instanceof pn)return this.Ep(t,n);if(t instanceof gn)return this.Ap(t,n);if(t instanceof wn){var i=t.value(n),e=this.dp.Ym().s();return t.s.isEqual(e)||A("Document "+this.ap.path+" contains a document reference within a different database ("+t.s.projectId+"/"+t.s.database+") which is not supported. It will be treated as a reference in the current database ("+e.projectId+"/"+e.database+") instead."),new as(i,this.dp,this.wp)}return t.value(n)},t.prototype.Ap=function(t,n){var i=this;return t.nn.map((function(t){return i.Rp(t,n)}))},t}(),ds=function(t){function n(){return null!==t&&t.apply(this,arguments)||this}return i(n,t),n.prototype.data=function(n){var i=t.prototype.data.call(this,n);return S(void 0!==i,"Document in a QueryDocumentSnapshot should exist"),i},n}(ls),vs=function(){function t(t,n,i){this.Dp=t,this.firestore=n,this.wp=i}return t.prototype.where=function(n,i,e){it("Query.where",arguments,3),wt("Query.where",3,e);var r,u=["<","<=","==",">=",">","array-contains","in","array-contains-any"];ft("Query.where",u,2,i);var s=je("Query.where",n),o=xn.ht(i);if(s.ft()){if(o===xn.ARRAY_CONTAINS||o===xn.ARRAY_CONTAINS_ANY)throw new Q(q.INVALID_ARGUMENT,"Invalid Query. You can't perform '"+o.toString()+"' queries on FieldPath.documentId().");if(o===xn.IN){this.Pp(e,o);for(var h=[],c=0,a=e;c<a.length;c++){var f=a[c];h.push(this.Sp(f))}r=new gn(h)}else r=this.Sp(e)}else o!==xn.IN&&o!==xn.ARRAY_CONTAINS_ANY||this.Pp(e,o),r=this.firestore.ep.Lc("Query.where",e,o===xn.IN);var l=jn.create(s,o,r);return this.Cp(l),new t(this.Dp.ai(l),this.firestore,this.wp)},t.prototype.orderBy=function(n,i){var e;if(rt("Query.orderBy",arguments,1,2),st("Query.orderBy","non-empty string",2,i),void 0===i||"asc"===i)e=Qn.ASCENDING;else{if("desc"!==i)throw new Q(q.INVALID_ARGUMENT,"Function Query.orderBy() has unknown direction '"+i+"', expected 'asc' or 'desc'.");e=Qn.DESCENDING}if(null!==this.Dp.startAt)throw new Q(q.INVALID_ARGUMENT,"Invalid query. You must not call Query.startAt() or Query.startAfter() before calling Query.orderBy().");if(null!==this.Dp.endAt)throw new Q(q.INVALID_ARGUMENT,"Invalid query. You must not call Query.endAt() or Query.endBefore() before calling Query.orderBy().");var r=je("Query.orderBy",n),u=new Wn(r,e);return this.Vp(u),new t(this.Dp.li(u),this.firestore,this.wp)},t.prototype.limit=function(n){return it("Query.limit",arguments,1),ut("Query.limit","number",1,n),gt("Query.limit",1,n),new t(this.Dp.di(n),this.firestore,this.wp)},t.prototype.limitToLast=function(n){return it("Query.limitToLast",arguments,1),ut("Query.limitToLast","number",1,n),gt("Query.limitToLast",1,n),new t(this.Dp.vi(n),this.firestore,this.wp)},t.prototype.startAt=function(n){for(var i=[],e=1;e<arguments.length;e++)i[e-1]=arguments[e];et("Query.startAt",arguments,1);var r=this.kp("Query.startAt",n,i,!0);return new t(this.Dp.wi(r),this.firestore,this.wp)},t.prototype.startAfter=function(n){for(var i=[],e=1;e<arguments.length;e++)i[e-1]=arguments[e];et("Query.startAfter",arguments,1);var r=this.kp("Query.startAfter",n,i,!1);return new t(this.Dp.wi(r),this.firestore,this.wp)},t.prototype.endBefore=function(n){for(var i=[],e=1;e<arguments.length;e++)i[e-1]=arguments[e];et("Query.endBefore",arguments,1);var r=this.kp("Query.endBefore",n,i,!0);return new t(this.Dp.mi(r),this.firestore,this.wp)},t.prototype.endAt=function(n){for(var i=[],e=1;e<arguments.length;e++)i[e-1]=arguments[e];et("Query.endAt",arguments,1);var r=this.kp("Query.endAt",n,i,!1);return new t(this.Dp.mi(r),this.firestore,this.wp)},t.prototype.isEqual=function(n){if(!(n instanceof t))throw pt("isEqual","Query",1,n);return this.firestore===n.firestore&&this.Dp.isEqual(n.Dp)},t.prototype.withConverter=function(n){return new t(this.Dp,this.firestore,n)},t.prototype.kp=function(t,n,i,e){if(wt(t,1,n),n instanceof ls){if(i.length>0)throw new Q(q.INVALID_ARGUMENT,"Too many arguments provided to "+t+"().");var r=n;if(!r.exists)throw new Q(q.NOT_FOUND,"Can't use a DocumentSnapshot that doesn't exist for "+t+"().");return this.Np(t,r._p,e)}var u=[n].concat(i);return this.Op(t,u,e)},t.prototype.Np=function(t,n,i){for(var e=[],r=0,u=this.Dp.orderBy;r<u.length;r++){var s=u[r];if(s.field.ft())e.push(new wn(this.firestore.$m,n.key));else{var o=n.field(s.field);if(o instanceof dn)throw new Q(q.INVALID_ARGUMENT,'Invalid query. You are trying to start or end a query using a document for which the field "'+s.field+'" is an uncommitted server timestamp. (Since the value of this field is unknown, you cannot start/end a query with it.)');if(null===o){var h=s.field.ot();throw new Q(q.INVALID_ARGUMENT,"Invalid query. You are trying to start or end a query using a document for which the field '"+h+"' (used as the orderBy) does not exist.")}e.push(o)}}return new Gn(e,i)},t.prototype.Op=function(t,n,i){var e=this.Dp.ii;if(n.length>e.length)throw new Q(q.INVALID_ARGUMENT,"Too many arguments provided to "+t+"(). The number of arguments must be less than or equal to the number of Query.orderBy() clauses");for(var r=[],u=0;u<n.length;u++){var s=n[u];if(e[u].field.ft()){if("string"!=typeof s)throw new Q(q.INVALID_ARGUMENT,"Invalid query. Expected a string for document ID in "+t+"(), but got a "+typeof s);if(!this.Dp.Pi()&&-1!==s.indexOf("/"))throw new Q(q.INVALID_ARGUMENT,"Invalid query. When querying a collection and ordering by FieldPath.documentId(), the value passed to "+t+"() must be a plain document ID, but '"+s+"' contains a slash.");var o=this.Dp.path.child(Rt.ht(s));if(!Pt.vt(o))throw new Q(q.INVALID_ARGUMENT,"Invalid query. When querying a collection group and ordering by FieldPath.documentId(), the value passed to "+t+"() must result in a valid document path, but '"+o+"' is not because it contains an odd number of segments.");var h=new Pt(o);r.push(new wn(this.firestore.$m,h))}else{var c=this.firestore.ep.Lc(t,s);r.push(c)}}return new Gn(r,i)},t.prototype.onSnapshot=function(){for(var t=[],n=0;n<arguments.length;n++)t[n]=arguments[n];rt("Query.onSnapshot",arguments,1,4);var i,e={},r=0;return"object"!=typeof t[r]||ts(t[r])||(mt("Query.onSnapshot",e=t[r],["includeMetadataChanges"]),ht("Query.onSnapshot","boolean","includeMetadataChanges",e.includeMetadataChanges),r++),ts(t[r])?i=t[r]:(ut("Query.onSnapshot","function",r,t[r]),st("Query.onSnapshot","function",r+1,t[r+1]),st("Query.onSnapshot","function",r+2,t[r+2]),i={next:t[r],error:t[r+1],complete:t[r+2]}),this.Fp(this.Dp),this.bp(e,i)},t.prototype.bp=function(t,n){var i=this,e=function(t){console.error("Uncaught Error in onSnapshot:",t)};n.error&&(e=n.error.bind(n));var r=new Zu({next:function(t){n.next&&n.next(new ws(i.firestore,i.Dp,t,i.wp))},error:e}),u=this.firestore.Ym(),s=u.listen(this.Dp,r,t);return function(){r.Km(),u.Pf(s)}},t.prototype.Fp=function(t){if(t.Ai()&&0===t.ii.length)throw new Q(q.UNIMPLEMENTED,"limitToLast() queries require specifying at least one orderBy() clause")},t.prototype.get=function(t){var n=this;return rt("Query.get",arguments,0,1),bs("Query.get",t),this.Fp(this.Dp),new Promise((function(i,e){t&&"cache"===t.source?n.firestore.Ym().Wm(n.Dp).then((function(t){i(new ws(n.firestore,n.Dp,t,n.wp))}),e):n.yp(i,e,t)}))},t.prototype.yp=function(t,n,i){var e=this.bp({includeMetadataChanges:!0,ov:!0},{next:function(r){e(),r.metadata.fromCache&&i&&"server"===i.source?n(new Q(q.UNAVAILABLE,'Failed to get documents from server. (However, these documents may exist in the local cache. Run again without setting source to "server" to retrieve the cached documents.)')):t(r)},error:n})},t.prototype.Sp=function(t){if("string"==typeof t){if(""===t)throw new Q(q.INVALID_ARGUMENT,"Invalid query. When querying with FieldPath.documentId(), you must provide a valid document ID, but it was an empty string.");if(!this.Dp.Pi()&&-1!==t.indexOf("/"))throw new Q(q.INVALID_ARGUMENT,"Invalid query. When querying a collection by FieldPath.documentId(), you must provide a plain document ID, but '"+t+"' contains a '/' character.");var n=this.Dp.path.child(Rt.ht(t));if(!Pt.vt(n))throw new Q(q.INVALID_ARGUMENT,"Invalid query. When querying a collection group by FieldPath.documentId(), the value provided must result in a valid document path, but '"+n+"' is not because it has an odd number of segments ("+n.length+").");return new wn(this.firestore.$m,new Pt(n))}if(t instanceof as){var i=t;return new wn(this.firestore.$m,i.ap)}throw new Q(q.INVALID_ARGUMENT,"Invalid query. When querying with FieldPath.documentId(), you must provide a valid string or a DocumentReference, but it was: "+vt(t)+".")},t.prototype.Pp=function(t,n){if(!Array.isArray(t)||0===t.length)throw new Q(q.INVALID_ARGUMENT,"Invalid Query. A non-empty array is required for '"+n.toString()+"' filters.");if(t.length>10)throw new Q(q.INVALID_ARGUMENT,"Invalid Query. '"+n.toString()+"' filters support a maximum of 10 elements in the value array.");if(t.indexOf(null)>=0)throw new Q(q.INVALID_ARGUMENT,"Invalid Query. '"+n.toString()+"' filters cannot contain 'null' in the value array.");if(t.filter((function(t){return Number.isNaN(t)})).length>0)throw new Q(q.INVALID_ARGUMENT,"Invalid Query. '"+n.toString()+"' filters cannot contain 'NaN' in the value array.")},t.prototype.Cp=function(t){if(t instanceof jn){var n=[xn.ARRAY_CONTAINS,xn.ARRAY_CONTAINS_ANY],i=[xn.IN,xn.ARRAY_CONTAINS_ANY],e=n.indexOf(t.op)>=0,r=i.indexOf(t.op)>=0;if(t.fi()){var u=this.Dp.hi();if(null!==u&&!u.isEqual(t.field))throw new Q(q.INVALID_ARGUMENT,"Invalid query. All where filters with an inequality (<, <=, >, or >=) must be on the same field. But you have inequality filters on '"+u.toString()+"' and '"+t.field.toString()+"'");var s=this.Dp.ci();null!==s&&this.xp(t.field,s)}else if(r||e){var o=null;if(r&&(o=this.Dp.Di(i)),null===o&&e&&(o=this.Dp.Di(n)),null!=o)throw o===t.op?new Q(q.INVALID_ARGUMENT,"Invalid query. You cannot use more than one '"+t.op.toString()+"' filter."):new Q(q.INVALID_ARGUMENT,"Invalid query. You cannot use '"+t.op.toString()+"' filters with '"+o.toString()+"' filters.")}}},t.prototype.Vp=function(t){if(null===this.Dp.ci()){var n=this.Dp.hi();null!==n&&this.xp(n,t.field)}},t.prototype.xp=function(t,n){if(!n.isEqual(t))throw new Q(q.INVALID_ARGUMENT,"Invalid query. You have a where filter with an inequality (<, <=, >, or >=) on field '"+t.toString()+"' and so you must also use '"+t.toString()+"' as your first Query.orderBy(), but your first Query.orderBy() is on field '"+n.toString()+"' instead.")},t}(),ws=function(){function t(t,n,i,e){this.dp=t,this.jp=n,this.Up=i,this.wp=e,this.Lp=null,this.Bp=null,this.metadata=new fs(i.hasPendingWrites,i.fromCache)}return Object.defineProperty(t.prototype,"docs",{get:function(){var t=[];return this.forEach((function(n){return t.push(n)})),t},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"empty",{get:function(){return this.Up.docs.nt()},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"size",{get:function(){return this.Up.docs.size},enumerable:!0,configurable:!0}),t.prototype.forEach=function(t,n){var i=this;rt("QuerySnapshot.forEach",arguments,1,2),ut("QuerySnapshot.forEach","function",1,t),this.Up.docs.forEach((function(e){t.call(n,i.Mp(e))}))},Object.defineProperty(t.prototype,"query",{get:function(){return new vs(this.jp,this.dp,this.wp)},enumerable:!0,configurable:!0}),t.prototype.docChanges=function(t){t&&(mt("QuerySnapshot.docChanges",t,["includeMetadataChanges"]),ht("QuerySnapshot.docChanges","boolean","includeMetadataChanges",t.includeMetadataChanges));var n=!(!t||!t.includeMetadataChanges);if(n&&this.Up.te)throw new Q(q.INVALID_ARGUMENT,"To include metadata changes with your document changes, you must also pass { includeMetadataChanges:true } to onSnapshot().");return this.Lp&&this.Bp===n||(this.Lp=function(t,n,i,e){if(i.Xi.nt()){var r,u=0;return i.docChanges.map((function(n){var s=new ds(t,n.doc.key,n.doc,i.fromCache,i.$i.has(n.doc.key),e);return S(n.type===li.Qi,"Invalid event type for first snapshot"),S(!r||i.query.yi(r,n.doc)<0,"Got added events in wrong order"),r=n.doc,{type:"added",doc:s,oldIndex:-1,newIndex:u++}}))}var s=i.Xi;return i.docChanges.filter((function(t){return n||t.type!==li.zi})).map((function(n){var r=new ds(t,n.doc.key,n.doc,i.fromCache,i.$i.has(n.doc.key),e),u=-1,o=-1;return n.type!==li.Qi&&(S((u=s.indexOf(n.doc.key))>=0,"Index for document not found"),s=s.delete(n.doc.key)),n.type!==li.Gi&&(o=(s=s.add(n.doc)).indexOf(n.doc.key)),{type:_s(n.type),doc:r,oldIndex:u,newIndex:o}}))}(this.dp,n,this.Up,this.wp),this.Bp=n),this.Lp},t.prototype.isEqual=function(n){if(!(n instanceof t))throw pt("isEqual","QuerySnapshot",1,n);return this.dp===n.dp&&this.jp.isEqual(n.jp)&&this.Up.isEqual(n.Up)&&this.wp===n.wp},t.prototype.Mp=function(t){return new ds(this.dp,t.key,t,this.metadata.fromCache,this.Up.$i.has(t.key),this.wp)},t}();n(["length","forEach","map"],"undefined"!=typeof Symbol?[Symbol.iterator]:[]).forEach((function(t){try{Object.defineProperty(ws.prototype.docChanges,t,{get:function(){return function(){throw new Q(q.INVALID_ARGUMENT,'QuerySnapshot.docChanges has been changed from a property into a method, so usages like "querySnapshot.docChanges" should become "querySnapshot.docChanges()"')}()}})}catch(t){}}));var ms=function(t){function n(n,i,e){var r=t.call(this,On.oi(n),i,e)||this;if(r.qp=n,n.length%2!=1)throw new Q(q.INVALID_ARGUMENT,"Invalid collection reference. Collection references must have an odd number of segments, but "+n.ot()+" has "+n.length);return r}return i(n,t),Object.defineProperty(n.prototype,"id",{get:function(){return this.Dp.path.et()},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"parent",{get:function(){var t=this.Dp.path.tt();return t.nt()?null:new as(new Pt(t),this.firestore)},enumerable:!0,configurable:!0}),Object.defineProperty(n.prototype,"path",{get:function(){return this.Dp.path.ot()},enumerable:!0,configurable:!0}),n.prototype.doc=function(t){if(rt("CollectionReference.doc",arguments,0,1),0===arguments.length&&(t=C.u()),ut("CollectionReference.doc","non-empty string",1,t),""===t)throw new Q(q.INVALID_ARGUMENT,"Document path must be a non-empty string");var n=Rt.ht(t);return as.fp(this.Dp.path.child(n),this.firestore,this.wp)},n.prototype.add=function(t){it("CollectionReference.add",arguments,1),ut("CollectionReference.add","object",1,t);var n=this.doc();return n.set(t).then((function(){return n}))},n.prototype.withConverter=function(t){return new n(this.qp,this.firestore,t)},n}(vs);function ps(t,n){if(void 0===n)return{merge:!1};if(mt(t,n,["merge","mergeFields"]),ht(t,"boolean","merge",n.merge),ct(t,"mergeFields","a string or a FieldPath",n.mergeFields,(function(t){return"string"==typeof t||t instanceof pe})),void 0!==n.mergeFields&&void 0!==n.merge)throw new Q(q.INVALID_ARGUMENT,"Invalid options passed to function "+t+'(): You cannot specify both "merge" and "mergeFields".');return n}function gs(t,n){return void 0===n?{}:(mt(t,n,["serverTimestamps"]),at(t,0,"serverTimestamps",n.serverTimestamps,["estimate","previous","none"]),n)}function bs(t,n){st(t,"object",1,n),n&&(mt(t,n,["source"]),at(t,0,"source",n.source,["default","server","cache"]))}function ys(t,n,i){if(n instanceof as){if(n.firestore!==i)throw new Q(q.INVALID_ARGUMENT,"Provided document reference is from a different Firestore instance.");return n}throw pt(t,"DocumentReference",1,n)}function _s(t){switch(t){case li.Qi:return"added";case li.Wi:case li.zi:return"modified";case li.Gi:return"removed";default:return P("Unknown change type: "+t)}}function Is(t,n,i){var e;return t?(e=t.toFirestore(n),i="toFirestore() in "+i):e=n,[e,i]}var Ts=Bi(os,"Use firebase.firestore() instead."),Es=Bi(hs,"Use firebase.firestore().runTransaction() instead."),Rs=Bi(cs,"Use firebase.firestore().batch() instead."),As=Bi(as,"Use firebase.firestore().doc() instead."),Ds=Bi(ls),Ps=Bi(ds),Ss=Bi(vs),Cs=Bi(ws),Vs=Bi(ms,"Use firebase.firestore().collection() instead."),ks={Firestore:Ts,GeoPoint:_t,Timestamp:It,Blob:zi,Transaction:Es,WriteBatch:Rs,DocumentReference:As,DocumentSnapshot:Ds,Query:Ss,QueryDocumentSnapshot:Ps,QuerySnapshot:Cs,CollectionReference:Vs,FieldPath:pe,FieldValue:De,setLogLevel:os.setLogLevel,CACHE_SIZE_UNLIMITED:us};function Ns(t){t.INTERNAL.registerComponent(new v("firestore",(function(t){var n=t.getProvider("app").getImmediate();return new os(n,t.getProvider("auth-internal"))}),"PUBLIC").setServiceProps(function(t){S(t&&"object"==typeof t,"shallowCopy() expects object parameter.");var n={};for(var i in t)Object.prototype.hasOwnProperty.call(t,i)&&(n[i]=t[i]);return n}(ks)))}var Os=function(){function t(){}return t.prototype.cf=function(t){},t.prototype.Af=function(){},t}(),Fs=function(){function t(){var t=this;this.Qp=function(){return t.Gp()},this.Wp=function(){return t.zp()},this.Kp=[],this.Hp()}return t.prototype.cf=function(t){this.Kp.push(t)},t.prototype.Af=function(){window.removeEventListener("online",this.Qp),window.removeEventListener("offline",this.Wp)},t.prototype.Hp=function(){window.addEventListener("online",this.Qp),window.addEventListener("offline",this.Wp)},t.prototype.Gp=function(){R("ConnectivityMonitor","Network connectivity changed: AVAILABLE");for(var t=0,n=this.Kp;t<n.length;t++){(0,n[t])(0)}},t.prototype.zp=function(){R("ConnectivityMonitor","Network connectivity changed: UNAVAILABLE");for(var t=0,n=this.Kp;t<n.length;t++){(0,n[t])(1)}},t.nl=function(){return"undefined"!=typeof window&&void 0!==window.addEventListener&&void 0!==window.removeEventListener},t}(),xs=function(){function t(t){this.Jp=t.Jp,this.Yp=t.Yp}return t.prototype.Ra=function(t){S(!this.Xp,"Called onOpen on stream twice!"),this.Xp=t},t.prototype.ya=function(t){S(!this.$p,"Called onClose on stream twice!"),this.$p=t},t.prototype.onMessage=function(t){S(!this.Zp,"Called onMessage on stream twice!"),this.Zp=t},t.prototype.close=function(){this.Yp()},t.prototype.send=function(t){this.Jp(t)},t.prototype.tg=function(){S(void 0!==this.Xp,"Cannot call onOpen because no callback was set"),this.Xp()},t.prototype.ng=function(t){S(void 0!==this.$p,"Cannot call onClose because no callback was set"),this.$p(t)},t.prototype.ig=function(t){S(void 0!==this.Zp,"Cannot call onMessage because no callback was set"),this.Zp(t)},t}(),js={BatchGetDocuments:"batchGet",Commit:"commit"},Us="gl-js/ fire/"+_,Ls=function(){function t(t){this.s=t.s;var n=t.ssl?"https":"http";this.eg=n+"://"+t.host,this.forceLongPolling=t.forceLongPolling}return t.prototype.rg=function(t,n){if(n)for(var i in n.A)n.A.hasOwnProperty(i)&&(t[i]=n.A[i]);t["X-Goog-Api-Client"]=Us},t.prototype.Ua=function(t,n,i){var e=this,r=this.ug(t);return new Promise((function(s,o){var h=new w;h.listenOnce(m.COMPLETE,(function(){try{switch(h.getLastErrorCode()){case p.NO_ERROR:var n=h.getResponseJson();R("Connection","XHR received:",JSON.stringify(n)),s(n);break;case p.TIMEOUT:R("Connection",'RPC "'+t+'" timed out'),o(new Q(q.DEADLINE_EXCEEDED,"Request time out"));break;case p.HTTP_ERROR:var i=h.getStatus();if(R("Connection",'RPC "'+t+'" failed with status:',i,"response text:",h.getResponseText()),i>0){var e=h.getResponseJson().error;if(e&&e.status&&e.message){var r=(u=e.status,c=u.toLowerCase().replace("_","-"),Object.values(q).indexOf(c)>=0?c:q.UNKNOWN);o(new Q(r,e.message))}else o(new Q(q.UNKNOWN,"Server responded with status "+h.getStatus()))}else R("Connection",'RPC "'+t+'" failed'),o(new Q(q.UNAVAILABLE,"Connection failed."));break;default:P('RPC "'+t+'" failed with unanticipated webchannel error '+h.getLastErrorCode()+": "+h.getLastError()+", giving up.")}}finally{R("Connection",'RPC "'+t+'" completed.')}var u,c}));var c=u({},n);delete c.database;var a=JSON.stringify(c);R("Connection","XHR sending: ",r+" "+a);var f={"Content-Type":"text/plain"};e.rg(f,i),h.send(r,"POST",a,f,15)}))},t.prototype.Ba=function(t,n,i){return this.Ua(t,n,i)},t.prototype.Aa=function(t,n){var i=[this.eg,"/","google.firestore.v1.Firestore","/",t,"/channel"],e=g(),r={backgroundChannelTest:!0,httpSessionIdParam:"gsessionid",initMessageHeaders:{},messageUrlParams:{database:"projects/"+this.s.projectId+"/databases/"+this.s.database},sendRawJson:!0,supportsCrossDomainXhr:!0,internalChannelParams:{forwardChannelRequestTimeoutMs:6e5},forceLongPolling:this.forceLongPolling};this.rg(r.initMessageHeaders,n),c()||a()||f()||l()||d()||(r.httpHeadersOverwriteParam="$httpHeaders");var u=i.join("");R("Connection","Creating WebChannel: "+u+" "+r);var s=e.createWebChannel(u,r),o=!1,h=!1,v=new xs({Jp:function(t){h?R("Connection","Not sending because WebChannel is closed:",t):(o||(R("Connection","Opening WebChannel transport."),s.open(),o=!0),R("Connection","WebChannel sending:",t),s.send(t))},Yp:function(){return s.close()}}),w=function(t,n){s.listen(t,(function(t){try{n(t)}catch(t){setTimeout((function(){throw t}),0)}}))};return w(b.EventType.OPEN,(function(){h||R("Connection","WebChannel transport opened.")})),w(b.EventType.CLOSE,(function(){h||(h=!0,R("Connection","WebChannel transport closed"),v.ng())})),w(b.EventType.ERROR,(function(t){h||(h=!0,R("Connection","WebChannel transport errored:",t),v.ng(new Q(q.UNAVAILABLE,"The operation could not be completed")))})),w(b.EventType.MESSAGE,(function(t){var n;if(!h){var i=t.data[0];S(!!i,"Got a webchannel message without data.");var e=i,r=e.error||(null===(n=e[0])||void 0===n?void 0:n.error);if(r){R("Connection","WebChannel received error:",r);var u=r.status,o=function(t){var n=Hn[t];if(void 0!==n)return Zn(n)}(u),c=r.message;void 0===o&&(o=q.INTERNAL,c="Unknown error status: "+u+" with message "+r.message),h=!0,v.ng(new Q(o,c)),s.close()}else R("Connection","WebChannel received:",i),v.ig(i)}})),setTimeout((function(){v.tg()}),0),v},t.prototype.ug=function(t){var n=js[t];return S(void 0!==n,"Unknown REST mapping for: "+t),this.eg+"/v1/projects/"+this.s.projectId+"/databases/"+this.s.database+"/documents:"+n},t}(),Bs=function(){function t(){this.tr="",this.pu="undefined"!=typeof atob}return Object.defineProperty(t.prototype,"document",{get:function(){return"undefined"!=typeof document?document:null},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"window",{get:function(){return"undefined"!=typeof window?window:null},enumerable:!0,configurable:!0}),t.prototype.Um=function(t){return Promise.resolve(new Ls(t))},t.prototype.Bm=function(){return Fs.nl()?new Fs:new Os},t.prototype.Mm=function(t){return new ji(t,{nr:!0})},t.prototype.i=function(t){return JSON.stringify(t)},t.prototype.atob=function(t){return atob(t)},t.prototype.btoa=function(t){return btoa(t)},t}();Ui.mu(new Bs);var Ms="@firebase/firestore",qs="1.10.0";function Qs(t){Ns(t),t.registerVersion(Ms,qs)}Qs(t);export{Qs as __PRIVATE_registerFirestore};
//# sourceMappingURL=index.esm.min.js.map