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;rn?1:0}function k(t,n){if(t.length!==n.length)return!1;for(var i=0;ie)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;u20&&(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(tu)return 1}return t.lengthn.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=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;ee?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""},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=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;n0&&(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;n0?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;e0?this.ii[0].field:null},t.prototype.hi=function(){for(var t=0,n=this.filters;t=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=":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;n0&&(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;n0?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;n0,"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=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=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.sizec.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;o0){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() 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;t0&&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;r0,"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.Jcthis.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;n0,"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&&s0&&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=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;i0||t.Zi,"We got a new snapshot with no changes?"),!this.options.includeMetadataChanges){for(var n=[],i=0,e=t.docChanges;i0)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;i0&&(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=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;ui)&&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=00||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,"",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=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;ar.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=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;ei)||(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].batchIdr?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)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=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;s0?[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=",">","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;c0)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;re.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;u10)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;t0){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