!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(require("@firebase/app")):"function"==typeof define&&define.amd?define(["@firebase/app"],e):e((t=t||self).firebase)}(this,function(Vp){"use strict";try{(function(){Vp=Vp&&Vp.hasOwnProperty("default")?Vp.default:Vp;var r=function(t,e){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])})(t,e)};function t(t,e){function n(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var o,e,l=function(){return(l=Object.assign||function(t){for(var e,n=1,r=arguments.length;na[0]&&e[1]"})}(o,r):"Error",s=this.serviceName+": "+a+" ("+i+").",u=new m(i,s),c=0,h=Object.keys(r);c>>0),_=0;function L(t,e,n){return t.call.apply(t.bind,arguments)}function P(e,n,t){if(!e)throw Error();if(2parseFloat(ft)){rt=String(pt);break t}}rt=ft}var mt,yt={};function gt(s){return function(t,e){var n=yt;return Object.prototype.hasOwnProperty.call(n,t)?n[t]:n[t]=e(t)}(s,function(){for(var t=0,e=z(String(rt)).split("."),n=z(String(s)).split("."),r=Math.max(e.length,n.length),i=0;0==t&&i>>0);function Qt(e){return"function"==A(e)?e:(e[Ut]||(e[Ut]=function(t){return e.handleEvent(t)}),e[Ut])}function Kt(){B.call(this),this.c=new kt(this),(this.J=this).B=null}function jt(t,e,n,r){if(!(e=t.c.a[String(e)]))return!0;e=e.concat();for(var i=!0,o=0;oe.length?Oe:(e=e.substr(r,n),t.A=r+n,e))}function Fe(t){t.R=F()+t.O,Ve(t,t.O)}function Ve(t,e){if(null!=t.i)throw Error("WatchDog timer not null");t.i=ve(x(t.bb,t),e)}function Be(t){t.i&&(E.clearTimeout(t.i),t.i=null)}function Ue(t){t.g.Da()||t.m||t.g.na(t)}function Qe(t){Be(t);var e=t.B;e&&"function"==typeof e.la&&e.la(),t.B=null,re(t.P),he(t.I),t.a&&(e=t.a,t.a=null,e.abort(),e.la())}function Ke(t,e){try{t.g.Ga(t,e),pe(4)}catch(t){}}function je(t,e){if(t.forEach&&"function"==typeof t.forEach)t.forEach(e,void 0);else if(R(t)||I(t))Q(t,e,void 0);else{if(t.K&&"function"==typeof t.K)var n=t.K();else if(t.C&&"function"==typeof t.C)n=void 0;else if(R(t)||I(t)){n=[];for(var r=t.length,i=0;i2*t.c&&ze(t))}function ze(t){if(t.c!=t.a.length){for(var e=0,n=0;e>4&15).toString(16)+(15&t).toString(16)}Xe.prototype.toString=function(){var t=[],e=this.f;e&&t.push(sn(e,cn,!0),":");var n=this.b;return!n&&"file"!=e||(t.push("//"),(e=this.j)&&t.push(sn(e,cn,!0),"@"),t.push(encodeURIComponent(String(n)).replace(/%25([0-9a-fA-F]{2})/g,"%$1")),null!=(n=this.i)&&t.push(":",String(n))),(n=this.a)&&(this.b&&"/"!=n.charAt(0)&&t.push("/"),t.push(sn(n,"/"==n.charAt(0)?ln:hn,!0))),(n=this.c.toString())&&t.push("?",n),(n=this.g)&&t.push("#",sn(n,dn)),t.join("")},Xe.prototype.resolve=function(t){var e=Je(this),n=!!t.f;n?Ze(e,t.f):n=!!t.j,n?e.j=t.j:n=!!t.b,n?$e(e,t.b):n=null!=t.i;var r=t.a;if(n)tn(e,t.i);else if(n=!!t.a){if("/"!=r.charAt(0))if(this.b&&!this.a)r="/"+r;else{var i=e.a.lastIndexOf("/");-1!=i&&(r=e.a.substr(0,i+1)+r)}if(".."==(i=r)||"."==i)r="";else if(H(i,"./")||H(i,"/.")){r=0==i.lastIndexOf("/",0),i=i.split("/");for(var o=[],a=0;a=t.f}function Mn(t){return t.b?1:t.a?t.a.a.c:0}function On(t,e){return t=t.b?t.b==e:!!t.a&&(e=Cn(e),He(t.a.a.b,e))}function _n(t,e){t.a?t.a.add(e):t.b=e}function Ln(t,e){var n;t.b&&t.b==e?t.b=null:((n=t.a)&&(n=Cn(e),n=He(t.a.a.b,n)),n&&Ge(t.a.a,Cn(e)))}function Pn(t){if(null!=t.b)return t.c.concat(t.b.j);if(null==t.a||0==t.a.a.c)return j(t.c);var e=t.c;return Q(t.a.C(),function(t){e=e.concat(t.j)}),e}function xn(){}function qn(){this.a=new xn}function Fn(t,r,e){var i=e||"";try{je(t,function(t,e){var n=t;M(t)&&(n=Wt(t)),r.push(i+e+"="+encodeURIComponent(n))})}catch(t){throw r.push(i+"type="+encodeURIComponent("_badmap")),t}}function Vn(t,e,n,r,i){try{e.onload=null,e.onerror=null,e.onabort=null,e.ontimeout=null,i(r)}catch(t){}}Nn.prototype.cancel=function(){this.c=Pn(this),this.b?(this.b.cancel(),this.b=null):this.a&&0!=this.a.a.c&&(Q(this.a.C(),function(t){t.cancel()}),function(t){t.b={},t.a.length=0,t.c=0}(this.a.a))},xn.prototype.stringify=function(t){return E.JSON.stringify(t,void 0)},xn.prototype.parse=function(t){return E.JSON.parse(t,void 0)};var Bn=E.JSON.parse;function Un(t){Kt.call(this),this.headers=new We,this.H=t||null,this.b=!1,this.s=this.a=null,this.A="",this.h=0,this.f="",this.g=this.w=this.l=this.v=!1,this.o=0,this.m=null,this.I=Qn,this.D=this.F=!1}V(Un,Kt);var Qn="",Kn=/^https?$/i,jn=["POST","PUT"];function Wn(t){return"content-type"==t.toLowerCase()}function Gn(t,e){t.b=!1,t.a&&(t.g=!0,t.a.abort(),t.g=!1),t.f=e,t.h=5,zn(t),Yn(t)}function zn(t){t.v||(t.v=!0,t.dispatchEvent("complete"),t.dispatchEvent("error"))}function Hn(t){if(t.b&&void 0!==T&&(!t.s[1]||4!=Jn(t)||2!=t.T()))if(t.l&&4==Jn(t))ie(t.Fa,0,t);else if(t.dispatchEvent("readystatechange"),4==Jn(t)){t.b=!1;try{var e,n=t.T();t:switch(n){case 200:case 201:case 202:case 204:case 206:case 304:case 1223:var r=!0;break t;default:r=!1}if(!(e=r)){var i;if(i=0===n){var o=String(t.A).match(Ye)[1]||null;if(!o&&E.self&&E.self.location){var a=E.self.location.protocol;o=a.substr(0,a.length-1)}i=!Kn.test(o?o.toLowerCase():"")}e=i}e?(t.dispatchEvent("complete"),t.dispatchEvent("success")):(t.h=6,t.f=t.za()+" ["+t.T()+"]",zn(t))}finally{Yn(t)}}}function Yn(t,e){if(t.a){Xn(t);var n=t.a,r=t.s[0]?N:null;t.a=null,t.s=null,e||t.dispatchEvent("ready");try{n.onreadystatechange=r}catch(t){}}}function Xn(t){t.a&&t.D&&(t.a.ontimeout=null),t.m&&(E.clearTimeout(t.m),t.m=null)}function Jn(t){return t.a?t.a.readyState:0}function Zn(t,e){return t.a?t.a.getResponseHeader(e):null}function $n(t,e,n){t:{for(r in n){var r=!1;break t}r=!0}if(r)return t;if(n=function(t){var n="";return Z(t,function(t,e){n+=e,n+=":",n+=t,n+="\r\n"}),n}(n),I(t)){if(e=encodeURIComponent(String(e)),e+=n=null!=n?"="+encodeURIComponent(String(n)):""){if((n=t.indexOf("#"))<0&&(n=t.length),(r=t.indexOf("?"))<0||n=t.b.f-(t.h?1:0))&&(t.h?(t.f=e.j.concat(t.f),!0):!(1==t.u||2==t.u||t.A>=(t.Pa?0:t.Qa))&&(t.h=ve(x(t.Ia,t,e),fr(t,t.A)),t.A++,!0))}(this,t)||2==n&&cr(this)))switch(e&&0r)throw new Wr(jr.INVALID_ARGUMENT,"Function "+t+"() requires between "+n+" and "+r+" arguments, but was called with "+yi(e.length,"argument")+".")}function ri(t,e,n,r){ci(t,e,mi(n)+" argument",r)}function ii(t,e,n,r){void 0!==r&&ri(t,e,n,r)}function oi(t,e,n,r){ci(t,e,n+" option",r)}function ai(t,e,n,r){void 0!==r&&oi(t,e,n,r)}function si(t,e,n,r,i){void 0!==r&&function(t,e,n,r,i){if(!(r instanceof Array))throw new Wr(jr.INVALID_ARGUMENT,"Function "+t+"() requires its "+e+" option to be an array, but it was: "+li(r));for(var o=0;o=t,"Can't call popFirst() with less segments"),this.construct(this.segments,this.offset+t,this.length-t)},Pi.prototype.popLast=function(){return Vr(!this.isEmpty(),"Can't call popLast() on empty path"),this.construct(this.segments,this.offset,this.length-1)},Pi.prototype.firstSegment=function(){return Vr(!this.isEmpty(),"Can't call firstSegment() on empty path"),this.segments[this.offset]},Pi.prototype.lastSegment=function(){return this.get(this.length-1)},Pi.prototype.get=function(t){return Vr(te.length?1:0},Pi);function Pi(t,e,n){void 0===e?e=0:e>t.length&&Fr("offset "+e+" out of range "+t.length),void 0===n?n=t.length-e:n>t.length-e&&Fr("length "+n+" out of range "+(t.length-e)),this.segments=t,this.offset=e,this.len=n}var xi,qi=(t(Fi,xi=Li),Fi.prototype.construct=function(t,e,n){return new Fi(t,e,n)},Fi.prototype.canonicalString=function(){return this.toArray().join("/")},Fi.prototype.toString=function(){return this.canonicalString()},Fi.fromString=function(t){if(0<=t.indexOf("//"))throw new Wr(jr.INVALID_ARGUMENT,"Invalid path ("+t+"). Paths must not contain // in them.");return new Fi(t.split("/").filter(function(t){return 0=i,"Should have found mutation after "+i),o=r.serializer.fromDbMutationBatch(e)),n.done()}).next(function(){return o})},Uo.prototype.getHighestUnacknowledgedBatchId=function(t){var e=IDBKeyRange.upperBound([this.userId,Number.POSITIVE_INFINITY]),r=-1;return Wo(t).iterate({index:pu.userMutationsIndex,range:e,reverse:!0},function(t,e,n){r=e.batchId,n.done()}).next(function(){return r})},Uo.prototype.getAllMutationBatches=function(t){var e=this,n=IDBKeyRange.bound([this.userId,-1],[this.userId,Number.POSITIVE_INFINITY]);return Wo(t).loadAll(pu.userMutationsIndex,n).next(function(t){return t.map(function(t){return e.serializer.fromDbMutationBatch(t)})})},Uo.prototype.getAllMutationBatchesAffectingDocumentKey=function(s,u){var c=this,t=yu.prefixForPath(this.userId,u.path),e=IDBKeyRange.lowerBound(t),h=[];return Go(s).iterate({range:e},function(e,t,n){var r=e[0],i=e[1],o=e[2],a=oo(i);if(r===c.userId&&u.path.isEqual(a))return Wo(s).get(o).next(function(t){if(!t)throw Fr("Dangling document-mutation reference found: "+e+" which points to "+o);Vr(t.userId===c.userId,"Unexpected user '"+t.userId+"' for mutation batch "+o),h.push(c.serializer.fromDbMutationBatch(t))});n.done()}).next(function(){return h})},Uo.prototype.getAllMutationBatchesAffectingDocumentKeys=function(r,t){var u=this,c=new bo(bi),i=[];return t.forEach(function(s){var t=yu.prefixForPath(u.userId,s.path),e=IDBKeyRange.lowerBound(t),n=Go(r).iterate({range:e},function(t,e,n){var r=t[0],i=t[1],o=t[2],a=oo(i);r===u.userId&&s.path.isEqual(a)?c=c.add(o):n.done()});i.push(n)}),Fo.waitFor(i).next(function(){return u.lookupMutationBatches(r,c)})},Uo.prototype.getAllMutationBatchesAffectingQuery=function(t,e){var s=this;Vr(!e.isDocumentQuery(),"Document queries shouldn't go down this path"),Vr(!e.isCollectionGroupQuery(),"CollectionGroup queries should be handled in LocalDocumentsView");var u=e.path,c=u.length+1,n=yu.prefixForPath(this.userId,u),r=IDBKeyRange.lowerBound(n),h=new bo(bi);return Go(t).iterate({range:r},function(t,e,n){var r=t[0],i=t[1],o=t[2],a=oo(i);r===s.userId&&u.isPrefixOf(a)?a.length===c&&(h=h.add(o)):n.done()}).next(function(){return s.lookupMutationBatches(t,h)})},Uo.prototype.lookupMutationBatches=function(t,e){var n=this,r=[],i=[];return e.forEach(function(e){i.push(Wo(t).get(e).next(function(t){if(null===t)throw Fr("Dangling document-mutation reference found, which points to "+e);Vr(t.userId===n.userId,"Unexpected user '"+t.userId+"' for mutation batch "+e),r.push(n.serializer.fromDbMutationBatch(t))}))}),Fo.waitFor(i).next(function(){return r})},Uo.prototype.removeMutationBatch=function(e,n){var r=this;return Ko(e.simpleDbTransaction,this.userId,n).next(function(t){return e.addOnCommittedListener(function(){r.removeCachedMutationKeys(n.batchId)}),Fo.forEach(t,function(t){return r.referenceDelegate.removeMutationReference(e,t)})})},Uo.prototype.removeCachedMutationKeys=function(t){delete this.documentKeysByBatchId[t]},Uo.prototype.performConsistencyCheck=function(n){var o=this;return this.checkEmpty(n).next(function(t){if(!t)return Fo.resolve();var e=IDBKeyRange.lowerBound(yu.prefixForUser(o.userId)),i=[];return Go(n).iterate({range:e},function(t,e,n){if(t[0]===o.userId){var r=oo(t[1]);i.push(r)}else n.done()}).next(function(){Vr(0===i.length,"Document leak -- detected dangling mutation references when queue is empty. Dangling keys: "+i.map(function(t){return t.canonicalString()}))})})},Uo.prototype.containsKey=function(t,e){return Qo(t,this.userId,e)},Uo.prototype.getMutationQueueMetadata=function(t){var e=this;return zo(t).get(this.userId).next(function(t){return t||new fu(e.userId,-1,"")})},Uo);function Uo(t,e,n,r){this.userId=t,this.serializer=e,this.indexManager=n,this.referenceDelegate=r,this.documentKeysByBatchId={}}function Qo(t,o,e){var n=yu.prefixForPath(o,e.path),a=n[1],r=IDBKeyRange.lowerBound(n),s=!1;return Go(t).iterate({range:r,keysOnly:!0},function(t,e,n){var r=t[0],i=t[1];t[2];r===o&&i===a&&(s=!0),n.done()}).next(function(){return s})}function Ko(t,e,n){var r=t.store(pu.store),i=t.store(yu.store),o=[],a=IDBKeyRange.only(n.batchId),s=0,u=r.iterate({range:a},function(t,e,n){return s++,n.delete()});o.push(u.next(function(){Vr(1===s,"Dangling document-mutation reference found: Missing batch "+n.batchId)}));for(var c=[],h=0,l=n.mutations;h",t),this.store.put(t)))},aa.prototype.add=function(t){return Pr(Zo,"ADD",this.store.name,t,t),sa(this.store.add(t))},aa.prototype.get=function(e){var n=this;return sa(this.store.get(e)).next(function(t){return void 0===t&&(t=null),Pr(Zo,"GET",n.store.name,e,t),t})},aa.prototype.delete=function(t){return Pr(Zo,"DELETE",this.store.name,t),sa(this.store.delete(t))},aa.prototype.count=function(){return Pr(Zo,"COUNT",this.store.name),sa(this.store.count())},aa.prototype.loadAll=function(t,e){var n=this.cursor(this.options(t,e)),r=[];return this.iterateCursor(n,function(t,e){r.push(e)}).next(function(){return r})},aa.prototype.deleteAll=function(t,e){Pr(Zo,"DELETE ALL",this.store.name);var n=this.options(t,e);n.keysOnly=!1;var r=this.cursor(n);return this.iterateCursor(r,function(t,e,n){return n.delete()})},aa.prototype.iterate=function(t,e){var n;e?n=t:(n={},e=t);var r=this.cursor(n);return this.iterateCursor(r,e)},aa.prototype.iterateSerial=function(i){var t=this.cursor({});return new Fo(function(n,r){t.onerror=function(t){var e=ca(t.target.error);r(e)},t.onsuccess=function(t){var e=t.target.result;e?i(e.primaryKey,e.value).next(function(t){t?e.continue():n()}):n()}})},aa.prototype.iterateCursor=function(t,a){var s=[];return new Fo(function(o,e){t.onerror=function(t){e(t.target.error)},t.onsuccess=function(t){var e=t.target.result;if(e){var n=new ea(e),r=a(e.primaryKey,e.value,n);if(r instanceof Fo){var i=r.catch(function(t){return n.done(),Fo.reject(t)});s.push(i)}n.isDone?o():null===n.skipToKey?e.continue():e.continue(n.skipToKey)}else o()}}).next(function(){return Fo.waitFor(s)})},aa.prototype.options=function(t,e){var n=void 0;return void 0!==t&&("string"==typeof t?n=t:(Vr(void 0===e,"3rd argument must not be defined if 2nd is a range."),e=t)),{index:n,range:e}},aa.prototype.cursor=function(t){var e="next";if(t.reverse&&(e="prev"),t.index){var n=this.store.index(t.index);return t.keysOnly?n.openKeyCursor(t.range,e):n.openCursor(t.range,e)}return this.store.openCursor(t.range,e)},aa);function aa(t){this.store=t}function sa(t){return new Fo(function(n,r){t.onsuccess=function(t){var e=t.target.result;n(e)},t.onerror=function(t){var e=ca(t.target.error);r(e)}})}var ua=!1;function ca(t){var e=$o.getIOSVersion(h());if(12.2<=e&&e<13){var n="An internal error was encountered in the Indexed Database server";if(0<=t.message.indexOf(n)){var r=new Wr("internal","IOS_INDEXEDDB_BUG1: IndexedDb has thrown '"+n+"'. This is likely due to an unavoidable bug in iOS. See https://stackoverflow.com/q/56496296/110915 for details and a potential workaround.");return ua||(ua=!0,setTimeout(function(){throw r},0)),r}}return t}var ha=(la.prototype.allocateTargetId=function(e){var n=this;return this.retrieveMetadata(e).next(function(t){return t.highestTargetId=n.targetIdGenerator.after(t.highestTargetId),n.saveMetadata(e,t).next(function(){return t.highestTargetId})})},la.prototype.getLastRemoteSnapshotVersion=function(t){return this.retrieveMetadata(t).next(function(t){return uo.fromTimestamp(new ao(t.lastRemoteSnapshotVersion.seconds,t.lastRemoteSnapshotVersion.nanoseconds))})},la.prototype.getHighestSequenceNumber=function(t){return pa(t.simpleDbTransaction)},la.prototype.setTargetsMetadata=function(e,n,r){var i=this;return this.retrieveMetadata(e).next(function(t){return t.highestListenSequenceNumber=n,r&&(t.lastRemoteSnapshotVersion=r.toTimestamp()),n>t.highestListenSequenceNumber&&(t.highestListenSequenceNumber=n),i.saveMetadata(e,t)})},la.prototype.addQueryData=function(e,n){var r=this;return this.saveQueryData(e,n).next(function(){return r.retrieveMetadata(e).next(function(t){return t.targetCount+=1,r.updateMetadataFromQueryData(n,t),r.saveMetadata(e,t)})})},la.prototype.updateQueryData=function(t,e){return this.saveQueryData(t,e)},la.prototype.removeQueryData=function(e,t){var n=this;return this.removeMatchingKeysForTargetId(e,t.targetId).next(function(){return fa(e).delete(t.targetId)}).next(function(){return n.retrieveMetadata(e)}).next(function(t){return Vr(0e.highestTargetId&&(e.highestTargetId=t.targetId,n=!0),t.sequenceNumber>e.highestListenSequenceNumber&&(e.highestListenSequenceNumber=t.sequenceNumber,n=!0),n},la.prototype.getQueryCount=function(t){return this.retrieveMetadata(t).next(function(t){return t.targetCount})},la.prototype.getQueryData=function(t,i){var o=this,e=i.canonicalId(),n=IDBKeyRange.bound([e,Number.NEGATIVE_INFINITY],[e,Number.POSITIVE_INFINITY]),a=null;return fa(t).iterate({range:n,index:Iu.queryTargetsIndexName},function(t,e,n){var r=o.serializer.fromDbTarget(e);i.isEqual(r.query)&&(a=r,n.done())}).next(function(){return a})},la.prototype.addMatchingKeys=function(n,t,r){var i=this,o=[],a=ma(n);return t.forEach(function(t){var e=no(t.path);o.push(a.put(new Du(r,e))),o.push(i.referenceDelegate.addReference(n,t))}),Fo.waitFor(o)},la.prototype.removeMatchingKeys=function(n,t,r){var i=this,o=ma(n);return Fo.forEach(t,function(t){var e=no(t.path);return Fo.waitFor([o.delete([r,e]),i.referenceDelegate.removeReference(n,t)])})},la.prototype.removeMatchingKeysForTargetId=function(t,e){var n=ma(t),r=IDBKeyRange.bound([e],[e+1],!1,!0);return n.delete(r)},la.prototype.getMatchingKeysForTargetId=function(t,e){var n=IDBKeyRange.bound([e],[e+1],!1,!0),r=ma(t),o=Mo();return r.iterate({range:n,keysOnly:!0},function(t,e,n){var r=oo(t[1]),i=new Ki(r);o=o.add(i)}).next(function(){return o})},la.prototype.containsKey=function(t,e){var n=no(e.path),r=IDBKeyRange.bound([n],[Si(n)],!1,!0),i=0;return ma(t).iterate({index:Du.documentTargetsIndex,keysOnly:!0,range:r},function(t,e,n){var r=t[0];t[1],0!==r&&(i++,n.done())}).next(function(){return 0"},gs);function gs(t,e){var n=ms.call(this)||this;return n.localWriteTime=t,n.previousValue=e,n.typeOrder=qa.TimestampValue,n}var vs,bs=(t(ws,vs=Wa),ws.prototype.value=function(t){return this.internalValue},ws.prototype.isEqual=function(t){return t instanceof ws&&this.internalValue.isEqual(t.internalValue)},ws.prototype.compareTo=function(t){return t instanceof ws?this.internalValue._compareTo(t.internalValue):this.defaultCompareTo(t)},ws);function ws(t){var e=vs.call(this)||this;return e.internalValue=t,e.typeOrder=qa.BlobValue,e}var Ss,Ts=(t(Es,Ss=Wa),Es.prototype.value=function(t){return this.key},Es.prototype.isEqual=function(t){return t instanceof Es&&this.key.isEqual(t.key)&&this.databaseId.isEqual(t.databaseId)},Es.prototype.compareTo=function(t){if(t instanceof Es){var e=this.databaseId.compareTo(t.databaseId);return 0!==e?e:Ki.comparator(this.key,t.key)}return this.defaultCompareTo(t)},Es);function Es(t,e){var n=Ss.call(this)||this;return n.databaseId=t,n.key=e,n.typeOrder=qa.RefValue,n}var Is,Cs=(t(Ds,Is=Wa),Ds.prototype.value=function(t){return this.internalValue},Ds.prototype.isEqual=function(t){return t instanceof Ds&&this.internalValue.isEqual(t.internalValue)},Ds.prototype.compareTo=function(t){return t instanceof Ds?this.internalValue._compareTo(t.internalValue):this.defaultCompareTo(t)},Ds);function Ds(t){var e=Is.call(this)||this;return e.internalValue=t,e.typeOrder=qa.GeoPointValue,e}var Ns,As=(t(ks,Ns=Wa),ks.prototype.value=function(n){var r={};return this.internalValue.inorderTraversal(function(t,e){r[t]=e.value(n)}),r},ks.prototype.forEach=function(t){this.internalValue.inorderTraversal(t)},ks.prototype.isEqual=function(t){if(t instanceof ks){for(var e=this.internalValue.getIterator(),n=t.internalValue.getIterator();e.hasNext()&&n.hasNext();){var r=e.getNext(),i=n.getNext();if(r.key!==i.key||!r.value.isEqual(i.value))return!1}return!e.hasNext()&&!n.hasNext()}return!1},ks.prototype.compareTo=function(t){if(t instanceof ks){for(var e=this.internalValue.getIterator(),n=t.internalValue.getIterator();e.hasNext()&&n.hasNext();){var r=e.getNext(),i=n.getNext(),o=bi(r.key,i.key)||r.value.compareTo(i.value);if(o)return o}return bi(e.hasNext(),n.hasNext())}return this.defaultCompareTo(t)},ks.prototype.set=function(t,e){if(Vr(!t.isEmpty(),"Cannot set field for empty path on ObjectValue"),1===t.length)return this.setChild(t.firstSegment(),e);var n=this.child(t.firstSegment());n instanceof ks||(n=ks.EMPTY);var r=n.set(t.popFirst(),e);return this.setChild(t.firstSegment(),r)},ks.prototype.delete=function(t){if(Vr(!t.isEmpty(),"Cannot delete field for empty path on ObjectValue"),1===t.length)return new ks(this.internalValue.remove(t.firstSegment()));var e=this.child(t.firstSegment());if(e instanceof ks){var n=e.delete(t.popFirst());return new ks(this.internalValue.insert(t.firstSegment(),n))}return this},ks.prototype.contains=function(t){return null!==this.field(t)},ks.prototype.field=function(t){Vr(!t.isEmpty(),"Can't get field of empty path");var e=this;return t.forEach(function(t){e=e instanceof ks?e.internalValue.get(t):null}),e},ks.prototype.fieldMask=function(){var i=new bo(Ui.comparator);return this.internalValue.forEach(function(t,e){var n=new Ui([t]);if(e instanceof ks){var r=e.fieldMask().fields;r.isEmpty()?i=i.add(n):r.forEach(function(t){i=i.add(n.child(t))})}else i=i.add(n)}),ya.fromSet(i)},ks.prototype.toString=function(){return this.internalValue.toString()},ks.prototype.child=function(t){return this.internalValue.get(t)||void 0},ks.prototype.setChild=function(t,e){return new ks(this.internalValue.insert(t,e))},ks.EMPTY=new ks(new ho(bi)),ks);function ks(t){var e=Ns.call(this)||this;return e.internalValue=t,e.typeOrder=qa.ObjectValue,e}var Rs,Ms=(t(Os,Rs=Wa),Os.prototype.value=function(e){return this.internalValue.map(function(t){return t.value(e)})},Os.prototype.contains=function(t){for(var e=0,n=this.internalValue;eh.params.maximumSequenceNumbersToCollect?(Pr("LruGarbageCollector","Capping sequence numbers to collect down to the maximum of "+h.params.maximumSequenceNumbersToCollect+" from "+t),h.params.maximumSequenceNumbersToCollect):t,a=Date.now(),h.nthSequenceNumber(e,i)}).next(function(t){return r=t,s=Date.now(),h.removeTargets(e,r,n)}).next(function(t){return o=t,u=Date.now(),h.removeOrphanedDocuments(e,r)}).next(function(t){return c=Date.now(),_r()<=Er.DEBUG&&Pr("LruGarbageCollector","LRU Garbage Collection\n\tCounted targets in "+(a-l)+"ms\n\tDetermined least recently used "+i+" in "+(s-a)+"ms\n\tRemoved "+o+" targets in "+(u-s)+"ms\n\tRemoved "+t+" documents in "+(c-u)+"ms\nTotal Duration: "+(c-l)+"ms"),Fo.resolve({didRun:!0,sequenceNumbersCollected:i,targetsRemoved:o,documentsRemoved:t})})},tc);function tc(t,e){this.delegate=t,this.params=e}var ec=(nc.prototype.addOnCommittedListener=function(t){this.onCommittedListeners.push(t)},nc.prototype.raiseOnCommittedEvent=function(){this.onCommittedListeners.forEach(function(t){return t()})},nc);function nc(){this.onCommittedListeners=[]}var rc,ic="IndexedDbPersistence",oc="The current tab is not in the required state to perform this operation. It might be necessary to refresh the browser tab.",ac="Another tab has exclusive access to the persistence layer. To allow shared access, make sure to invoke `enablePersistence()` with `synchronizeTabs:true` in all tabs.",sc=(t(uc,rc=ec),uc);function uc(t,e){var n=rc.call(this)||this;return n.simpleDbTransaction=t,n.currentSequenceNumber=e,n}var cc=(hc.getStore=function(t,e){if(t instanceof sc)return $o.getStore(t.simpleDbTransaction,e);throw Fr("IndexedDbPersistence must use instances of IndexedDbTransaction")},hc.createIndexedDbPersistence=function(n){return d(this,void 0,void 0,function(){var e;return p(this,function(t){switch(t.label){case 0:if(!hc.isAvailable())throw new Wr(jr.UNIMPLEMENTED,"This platform is either missing IndexedDB or is known to have an incomplete implementation. Offline persistence has been disabled.");return[4,(e=new hc(n.allowTabSynchronization,n.persistenceKey,n.clientId,n.platform,n.lruParams,n.queue,n.serializer,n.sequenceNumberSyncer)).start()];case 1:return t.sent(),[2,e]}})})},hc.prototype.start=function(){var e=this;return Vr(!this.started,"IndexedDbPersistence double-started!"),Vr(null!==this.window,"Expected 'window' to be defined"),$o.openOrCreate(this.dbName,au,new su(this.serializer)).then(function(t){return e.simpleDb=t,e.updateClientMetadataAndTryBecomePrimary()}).then(function(){return e.attachVisibilityHandler(),e.attachWindowUnloadHook(),e.scheduleClientMetadataAndPrimaryLeaseRefreshes(),e.simpleDb.runTransaction("readonly-idempotent",[Au.store],function(t){return pa(t)})}).then(function(t){e.listenSequence=new Mi(t,e.sequenceNumberSyncer)}).then(function(){e._started=!0}).catch(function(t){return e.simpleDb&&e.simpleDb.close(),Promise.reject(t)})},hc.prototype.setPrimaryStateListener=function(n){var t=this;return this.primaryStateListener=function(e){return d(t,void 0,void 0,function(){return p(this,function(t){return this.started?[2,n(e)]:[2]})})},n(this.isPrimary)},hc.prototype.setDatabaseDeletedListener=function(n){var t=this;this.simpleDb.setVersionChangeListener(function(e){return d(t,void 0,void 0,function(){return p(this,function(t){switch(t.label){case 0:return null!==e.newVersion?[3,2]:[4,n()];case 1:t.sent(),t.label=2;case 2:return[2]}})})})},hc.prototype.setNetworkEnabled=function(t){var e=this;this.networkEnabled!==t&&(this.networkEnabled=t,this.queue.enqueueAndForget(function(){return d(e,void 0,void 0,function(){return p(this,function(t){switch(t.label){case 0:return this.started?[4,this.updateClientMetadataAndTryBecomePrimary()]:[3,2];case 1:t.sent(),t.label=2;case 2:return[2]}})})}))},hc.prototype.updateClientMetadataAndTryBecomePrimary=function(){var r=this;return this.simpleDb.runTransaction("readwrite",qu,function(n){return dc(n).put(new _u(r.clientId,Date.now(),r.networkEnabled,r.inForeground)).next(function(){if(r.isPrimary)return r.verifyPrimaryLease(n).next(function(t){t||(r.isPrimary=!1,r.queue.enqueueAndForget(function(){return r.primaryStateListener(!1)}))})}).next(function(){return r.canActAsPrimary(n)}).next(function(t){var e=r.isPrimary;return r.isPrimary=t,e!==r.isPrimary&&r.queue.enqueueAndForget(function(){return r.primaryStateListener(r.isPrimary)}),e&&!r.isPrimary?r.releasePrimaryLeaseIfHeld(n):r.isPrimary?r.acquireOrExtendPrimaryLease(n):void 0})})},hc.prototype.verifyPrimaryLease=function(t){var e=this;return fc(t).get(hu.key).next(function(t){return Fo.resolve(e.isLocalClient(t))})},hc.prototype.removeClientMetadata=function(t){return dc(t).delete(this.clientId)},hc.prototype.maybeGarbageCollectMultiClientState=function(){return d(this,void 0,void 0,function(){var n,r,i=this;return p(this,function(t){switch(t.label){case 0:return!this.isPrimary||this.isWithinAge(this.lastGarbageCollectionTime,18e5)?[3,2]:(this.lastGarbageCollectionTime=Date.now(),r=[],[4,this.runTransaction("maybeGarbageCollectMultiClientState","readwrite-primary",function(t){var e=hc.getStore(t,_u.store);return e.loadAll().next(function(t){return n=i.filterActiveClients(t,18e5),r=t.filter(function(t){return-1===n.indexOf(t)}),Fo.forEach(r,function(t){return e.delete(t.clientId)})})})]);case 1:t.sent(),r.forEach(function(t){i.window.localStorage.removeItem(i.zombiedClientLocalStorageKey(t.clientId))}),t.label=2;case 2:return[2]}})})},hc.prototype.scheduleClientMetadataAndPrimaryLeaseRefreshes=function(){var t=this;this.clientMetadataRefresher=this.queue.enqueueAfterDelay(Wi.ClientMetadataRefresh,4e3,function(){return t.updateClientMetadataAndTryBecomePrimary().then(function(){return t.maybeGarbageCollectMultiClientState()}).then(function(){return t.scheduleClientMetadataAndPrimaryLeaseRefreshes()})})},hc.prototype.isLocalClient=function(t){return!!t&&t.ownerId===this.clientId},hc.prototype.canActAsPrimary=function(e){var i=this;return fc(e).get(hu.key).next(function(t){if(null!==t&&i.isWithinAge(t.leaseTimestampMs,5e3)&&!i.isClientZombied(t.ownerId)){if(i.isLocalClient(t)&&i.networkEnabled)return!0;if(!i.isLocalClient(t)){if(!t.allowTabSynchronization)throw new Wr(jr.FAILED_PRECONDITION,ac);return!1}}return!(!i.networkEnabled||!i.inForeground)||dc(e).loadAll().next(function(t){return void 0===i.filterActiveClients(t,5e3).find(function(t){if(i.clientId!==t.clientId){var e=!i.networkEnabled&&t.networkEnabled,n=!i.inForeground&&t.inForeground,r=i.networkEnabled===t.networkEnabled;if(e||n&&r)return!0}return!1})})}).next(function(t){return i.isPrimary!==t&&Pr(ic,"Client "+(t?"is":"is not")+" eligible for a primary lease."),t})},hc.prototype.shutdown=function(){return d(this,void 0,void 0,function(){var e=this;return p(this,function(t){switch(t.label){case 0:return this._started=!1,this.markClientZombied(),this.clientMetadataRefresher&&(this.clientMetadataRefresher.cancel(),this.clientMetadataRefresher=null),this.detachVisibilityHandler(),this.detachWindowUnloadHook(),[4,this.simpleDb.runTransaction("readwrite-idempotent",[hu.store,_u.store],function(t){return e.releasePrimaryLeaseIfHeld(t).next(function(){return e.removeClientMetadata(t)})})];case 1:return t.sent(),this.simpleDb.close(),this.removeClientZombiedEntry(),[2]}})})},hc.prototype.filterActiveClients=function(t,e){var n=this;return t.filter(function(t){return n.isWithinAge(t.updateTimeMs,e)&&!n.isClientZombied(t.clientId)})},hc.prototype.getActiveClients=function(){var e=this;return this.simpleDb.runTransaction("readonly-idempotent",[_u.store],function(t){return dc(t).loadAll().next(function(t){return e.filterActiveClients(t,18e5).map(function(t){return t.clientId})})})},hc.clearPersistence=function(n){return d(this,void 0,void 0,function(){var e;return p(this,function(t){switch(t.label){case 0:return hc.isAvailable()?(e=n+hc.MAIN_DATABASE,[4,$o.delete(e)]):[2,Promise.resolve()];case 1:return t.sent(),[2]}})})},Object.defineProperty(hc.prototype,"started",{get:function(){return this._started},enumerable:!0,configurable:!0}),hc.prototype.getMutationQueue=function(t){return Vr(this.started,"Cannot initialize MutationQueue before persistence is started."),Bo.forUser(t,this.serializer,this.indexManager,this.referenceDelegate)},hc.prototype.getQueryCache=function(){return Vr(this.started,"Cannot initialize QueryCache before persistence is started."),this.queryCache},hc.prototype.getRemoteDocumentCache=function(){return Vr(this.started,"Cannot initialize RemoteDocumentCache before persistence is started."),this.remoteDocumentCache},hc.prototype.getIndexManager=function(){return Vr(this.started,"Cannot initialize IndexManager before persistence is started."),this.indexManager},hc.prototype.runTransaction=function(n,t,r){var i=this;Pr(ic,"Starting transaction:",n);var o,e=t.endsWith("idempotent"),a=t.startsWith("readonly")?e?"readonly-idempotent":"readonly":e?"readwrite-idempotent":"readwrite";return this.simpleDb.runTransaction(a,qu,function(e){return o=new sc(e,i.listenSequence.next()),"readwrite-primary"===t||"readwrite-primary-idempotent"===t?i.verifyPrimaryLease(e).next(function(t){if(!t)throw xr("Failed to obtain primary lease for action '"+n+"'."),i.isPrimary=!1,i.queue.enqueueAndForget(function(){return i.primaryStateListener(!1)}),new Wr(jr.FAILED_PRECONDITION,oc);return r(o)}).next(function(t){return i.acquireOrExtendPrimaryLease(e).next(function(){return t})}):i.verifyAllowTabSynchronization(e).next(function(){return r(o)})}).then(function(t){return o.raiseOnCommittedEvent(),t})},hc.prototype.verifyAllowTabSynchronization=function(t){var e=this;return fc(t).get(hu.key).next(function(t){if(null!==t&&e.isWithinAge(t.leaseTimestampMs,5e3)&&!e.isClientZombied(t.ownerId)&&!e.isLocalClient(t)&&!t.allowTabSynchronization)throw new Wr(jr.FAILED_PRECONDITION,ac)})},hc.prototype.acquireOrExtendPrimaryLease=function(t){var e=new hu(this.clientId,this.allowTabSynchronization,Date.now());return fc(t).put(hu.key,e)},hc.isAvailable=function(){return $o.isAvailable()},hc.buildStoragePrefix=function(t){var e=t.databaseId.projectId;return t.databaseId.isDefaultDatabase||(e+="."+t.databaseId.database),"firestore/"+t.persistenceKey+"/"+e+"/"},hc.prototype.releasePrimaryLeaseIfHeld=function(t){var e=this,n=fc(t);return n.get(hu.key).next(function(t){return e.isLocalClient(t)?(Pr(ic,"Releasing primary lease."),n.delete(hu.key)):Fo.resolve()})},hc.prototype.isWithinAge=function(t,e){var n=Date.now();return!(t "+n),1))},hc.prototype.attachVisibilityHandler=function(){var t=this;null!==this.document&&"function"==typeof this.document.addEventListener&&(this.documentVisibilityHandler=function(){t.queue.enqueueAndForget(function(){return t.inForeground="visible"===t.document.visibilityState,t.updateClientMetadataAndTryBecomePrimary()})},this.document.addEventListener("visibilitychange",this.documentVisibilityHandler),this.inForeground="visible"===this.document.visibilityState)},hc.prototype.detachVisibilityHandler=function(){this.documentVisibilityHandler&&(Vr(null!==this.document&&"function"==typeof this.document.addEventListener,"Expected 'document.addEventListener' to be a function"),this.document.removeEventListener("visibilitychange",this.documentVisibilityHandler),this.documentVisibilityHandler=null)},hc.prototype.attachWindowUnloadHook=function(){var t=this;"function"==typeof this.window.addEventListener&&(this.windowUnloadHandler=function(){t.markClientZombied(),t.queue.enqueueAndForget(function(){return t.shutdown()})},this.window.addEventListener("unload",this.windowUnloadHandler))},hc.prototype.detachWindowUnloadHook=function(){this.windowUnloadHandler&&(Vr("function"==typeof this.window.removeEventListener,"Expected 'window.removeEventListener' to be a function"),this.window.removeEventListener("unload",this.windowUnloadHandler),this.windowUnloadHandler=null)},hc.prototype.isClientZombied=function(t){try{var e=null!==this.webStorage.getItem(this.zombiedClientLocalStorageKey(t));return Pr(ic,"Client '"+t+"' "+(e?"is":"is not")+" zombied in LocalStorage"),e}catch(t){return xr(ic,"Failed to get zombied client id.",t),!1}},hc.prototype.markClientZombied=function(){try{this.webStorage.setItem(this.zombiedClientLocalStorageKey(this.clientId),String(Date.now()))}catch(t){xr("Failed to set zombie client id.",t)}},hc.prototype.removeClientZombiedEntry=function(){try{this.webStorage.removeItem(this.zombiedClientLocalStorageKey(this.clientId))}catch(t){}},hc.prototype.zombiedClientLocalStorageKey=function(t){return"firestore_zombie_"+this.persistenceKey+"_"+t},hc.MAIN_DATABASE="main",hc);function hc(t,e,n,r,i,o,a,s){if(this.allowTabSynchronization=t,this.persistenceKey=e,this.clientId=n,this.queue=o,this.sequenceNumberSyncer=s,this._started=!1,this.isPrimary=!1,this.networkEnabled=!0,this.windowUnloadHandler=null,this.inForeground=!1,this.documentVisibilityHandler=null,this.clientMetadataRefresher=null,this.lastGarbageCollectionTime=Number.NEGATIVE_INFINITY,this.primaryStateListener=function(t){return Promise.resolve()},this.referenceDelegate=new pc(this,i),this.dbName=e+hc.MAIN_DATABASE,this.serializer=new Ku(a),this.document=r.document,this.queryCache=new ha(this.referenceDelegate,this.serializer),this.indexManager=new Fu,this.remoteDocumentCache=new Ys(this.serializer,this.indexManager),!r.window||!r.window.localStorage)throw new Wr(jr.UNIMPLEMENTED,"IndexedDB persistence is only available on platforms that support LocalStorage.");this.window=r.window,this.webStorage=this.window.localStorage}function lc(e){return d(this,void 0,void 0,function(){return p(this,function(t){if(!function(t){return t.code===jr.FAILED_PRECONDITION&&t.message===oc}(e))throw e;return Pr(ic,"Unexpectedly lost primary lease"),[2]})})}function fc(t){return t.store(hu.store)}function dc(t){return t.store(_u.store)}var pc=(mc.prototype.getSequenceNumberCount=function(t){var n=this.orphanedDocmentCount(t);return this.db.getQueryCache().getQueryCount(t).next(function(e){return n.next(function(t){return e+t})})},mc.prototype.orphanedDocmentCount=function(t){var e=0;return this.forEachOrphanedDocumentSequenceNumber(t,function(t){e++}).next(function(){return e})},mc.prototype.forEachTarget=function(t,e){return this.db.getQueryCache().forEachTarget(t,e)},mc.prototype.forEachOrphanedDocumentSequenceNumber=function(t,n){return this.forEachOrphanedDocument(t,function(t,e){return n(e)})},mc.prototype.setInMemoryPins=function(t){this.inMemoryPins=t},mc.prototype.addReference=function(t,e){return yc(t,e)},mc.prototype.removeReference=function(t,e){return yc(t,e)},mc.prototype.removeTargets=function(t,e,n){return this.db.getQueryCache().removeTargets(t,e,n)},mc.prototype.removeMutationReference=function(t,e){return yc(t,e)},mc.prototype.isPinned=function(t,e){return this.inMemoryPins.containsKey(e)?Fo.resolve(!0):function(e,n){var r=!1;return zo(e).iterateSerial(function(t){return Qo(e,t,n).next(function(t){return t&&(r=!0),Fo.resolve(!t)})}).next(function(){return r})}(t,e)},mc.prototype.removeOrphanedDocuments=function(r,i){var o=this,a=this.db.getRemoteDocumentCache().newChangeBuffer(),s=[],u=0;return this.forEachOrphanedDocument(r,function(e,t){if(t<=i){var n=o.isPinned(r,e).next(function(t){if(!t)return u++,a.getEntry(r,e).next(function(){return a.removeEntry(e),ma(r).delete(function(t){return[0,no(t.path)]}(e))})});s.push(n)}}).next(function(){return Fo.waitFor(s)}).next(function(){return a.apply(r)}).next(function(){return u})},mc.prototype.removeTarget=function(t,e){var n=e.withSequenceNumber(t.currentSequenceNumber);return this.db.getQueryCache().updateQueryData(t,n)},mc.prototype.updateLimboDocument=function(t,e){return yc(t,e)},mc.prototype.forEachOrphanedDocument=function(t,o){var a,e=ma(t),s=Mi.INVALID;return e.iterate({index:Du.documentTargetsIndex},function(t,e){var n=t[0],r=(t[1],e.path),i=e.sequenceNumber;0===n?(s!==Mi.INVALID&&o(new Ki(oo(a)),s),s=i,a=r):s=Mi.INVALID}).next(function(){s!==Mi.INVALID&&o(new Ki(oo(a)),s)})},mc.prototype.getCacheSize=function(t){return this.db.getRemoteDocumentCache().getSize(t)},mc);function mc(t,e){this.db=t,this.inMemoryPins=null,this.garbageCollector=new $u(this,e)}function yc(t,e){return ma(t).put(function(t,e){return new Du(0,no(t.path),e)}(e,t.currentSequenceNumber))}var gc=(vc.prototype.getDocument=function(e,n){var r=this;return this.mutationQueue.getAllMutationBatchesAffectingDocumentKey(e,n).next(function(t){return r.getDocumentInternal(e,n,t)})},vc.prototype.getDocumentInternal=function(t,r,i){return this.remoteDocumentCache.getEntry(t,r).next(function(t){for(var e=0,n=i;e=this.RESUME_TOKEN_MAX_AGE_MICROS||0i?this.mutationQueue[i]:null)},Nc.prototype.getHighestUnacknowledgedBatchId=function(){return Fo.resolve(0===this.mutationQueue.length?-1:this.nextBatchId-1)},Nc.prototype.getAllMutationBatches=function(t){return Fo.resolve(this.mutationQueue.slice())},Nc.prototype.getAllMutationBatchesAffectingDocumentKey=function(t,n){var r=this,e=new Sc(n,0),i=new Sc(n,Number.POSITIVE_INFINITY),o=[];return this.batchesByDocumentKey.forEachInRange([e,i],function(t){Vr(n.isEqual(t.key),"Should only iterate over a single key's batches");var e=r.findMutationBatch(t.targetOrBatchId);Vr(null!==e,"Batches in the index must exist in the main table"),o.push(e)}),Fo.resolve(o)},Nc.prototype.getAllMutationBatchesAffectingDocumentKeys=function(t,e){var r=this,i=new bo(bi);return e.forEach(function(e){var t=new Sc(e,0),n=new Sc(e,Number.POSITIVE_INFINITY);r.batchesByDocumentKey.forEachInRange([t,n],function(t){Vr(e.isEqual(t.key),"For each key, should only iterate over a single key's batches"),i=i.add(t.targetOrBatchId)})}),Fo.resolve(this.findMutationBatches(i))},Nc.prototype.getAllMutationBatchesAffectingQuery=function(t,e){Vr(!e.isCollectionGroupQuery(),"CollectionGroup queries should be handled in LocalDocumentsView");var n=e.path,r=n.length+1,i=n;Ki.isDocumentKey(i)||(i=i.child(""));var o=new Sc(new Ki(i),0),a=new bo(bi);return this.batchesByDocumentKey.forEachWhile(function(t){var e=t.key.path;return!!n.isPrefixOf(e)&&(e.length===r&&(a=a.add(t.targetOrBatchId)),!0)},o),Fo.resolve(this.findMutationBatches(a))},Nc.prototype.findMutationBatches=function(t){var n=this,r=[];return t.forEach(function(t){var e=n.findMutationBatch(t);null!==e&&r.push(e)}),r},Nc.prototype.removeMutationBatch=function(n,r){var i=this;Vr(0===this.indexOfExistingBatchId(r.batchId,"removed"),"Can only remove the first entry of the mutation queue"),this.mutationQueue.shift();var o=this.batchesByDocumentKey;return Fo.forEach(r.mutations,function(t){var e=new Sc(t.key,r.batchId);return o=o.delete(e),i.referenceDelegate.removeMutationReference(n,t.key)}).next(function(){i.batchesByDocumentKey=o})},Nc.prototype.removeCachedMutationKeys=function(t){},Nc.prototype.containsKey=function(t,e){var n=new Sc(e,0),r=this.batchesByDocumentKey.firstAfterOrEqual(n);return Fo.resolve(e.isEqual(r&&r.key))},Nc.prototype.performConsistencyCheck=function(t){return 0===this.mutationQueue.length&&Vr(this.batchesByDocumentKey.isEmpty(),"Document leak -- detected dangling mutation references when queue is empty."),Fo.resolve()},Nc.prototype.indexOfExistingBatchId=function(t,e){var n=this.indexOfBatchId(t);return Vr(0<=n&&n=this.mutationQueue.length)return null;var n=this.mutationQueue[e];return Vr(n.batchId===t,"If found batch must match"),n},Nc);function Nc(t,e){this.indexManager=t,this.referenceDelegate=e,this.mutationQueue=[],this.nextBatchId=1,this.lastStreamToken=Qr(),this.batchesByDocumentKey=new bo(Sc.compareByKey)}var Ac=(kc.prototype.getTargetCount=function(t){return Fo.resolve(this.targetCount)},kc.prototype.forEachTarget=function(t,n){return this.queries.forEach(function(t,e){return n(e)}),Fo.resolve()},kc.prototype.getLastRemoteSnapshotVersion=function(t){return Fo.resolve(this.lastRemoteSnapshotVersion)},kc.prototype.getHighestSequenceNumber=function(t){return Fo.resolve(this.highestSequenceNumber)},kc.prototype.allocateTargetId=function(t){var e=this.targetIdGenerator.after(this.highestTargetId);return this.highestTargetId=e,Fo.resolve(e)},kc.prototype.setTargetsMetadata=function(t,e,n){return n&&(this.lastRemoteSnapshotVersion=n),e>this.highestSequenceNumber&&(this.highestSequenceNumber=e),Fo.resolve()},kc.prototype.saveQueryData=function(t){this.queries.set(t.query,t);var e=t.targetId;e>this.highestTargetId&&(this.highestTargetId=e),t.sequenceNumber>this.highestSequenceNumber&&(this.highestSequenceNumber=t.sequenceNumber)},kc.prototype.addQueryData=function(t,e){return Vr(!this.queries.has(e.query),"Adding a query that already exists"),this.saveQueryData(e),this.targetCount+=1,Fo.resolve()},kc.prototype.updateQueryData=function(t,e){return Vr(this.queries.has(e.query),"Updating a non-existent query"),this.saveQueryData(e),Fo.resolve()},kc.prototype.removeQueryData=function(t,e){return Vr(0this.maxDelayMs&&(this.currentBaseMs=this.maxDelayMs)},Zc.prototype.cancel=function(){null!==this.timerPromise&&(this.timerPromise.cancel(),this.timerPromise=null)},Zc.prototype.jitterDelayMs=function(){return(Math.random()-.5)*this.currentBaseMs},Zc);function Zc(t,e,n,r,i){void 0===n&&(n=1e3),void 0===r&&(r=1.5),void 0===i&&(i=6e4),this.queue=t,this.timerId=e,this.initialDelayMs=n,this.backoffFactor=r,this.maxDelayMs=i,this.currentBaseMs=0,this.timerPromise=null,this.lastAttemptTime=Date.now(),this.reset()}var $c,th,eh="PersistentStream";(th=$c=$c||{})[th.Initial=0]="Initial",th[th.Starting=1]="Starting",th[th.Open=2]="Open",th[th.Error=3]="Error",th[th.Backoff=4]="Backoff";var nh=(rh.prototype.isStarted=function(){return this.state===$c.Starting||this.state===$c.Open||this.state===$c.Backoff},rh.prototype.isOpen=function(){return this.state===$c.Open},rh.prototype.start=function(){this.state!==$c.Error?(Vr(this.state===$c.Initial,"Already started"),this.auth()):this.performBackoff()},rh.prototype.stop=function(){return d(this,void 0,void 0,function(){return p(this,function(t){switch(t.label){case 0:return this.isStarted()?[4,this.close($c.Initial)]:[3,2];case 1:t.sent(),t.label=2;case 2:return[2]}})})},rh.prototype.inhibitBackoff=function(){Vr(!this.isStarted(),"Can only inhibit backoff in a stopped state"),this.state=$c.Initial,this.backoff.reset()},rh.prototype.markIdle=function(){var t=this;this.isOpen()&&null===this.idleTimer&&(this.idleTimer=this.queue.enqueueAfterDelay(this.idleTimerId,6e4,function(){return t.handleIdleCloseTimer()}))},rh.prototype.sendRequest=function(t){this.cancelIdleCheck(),this.stream.send(t)},rh.prototype.handleIdleCloseTimer=function(){return d(this,void 0,void 0,function(){return p(this,function(t){return this.isOpen()?[2,this.close($c.Initial)]:[2]})})},rh.prototype.cancelIdleCheck=function(){this.idleTimer&&(this.idleTimer.cancel(),this.idleTimer=null)},rh.prototype.close=function(e,n){return d(this,void 0,void 0,function(){return p(this,function(t){switch(t.label){case 0:return Vr(this.isStarted(),"Only started streams should be closed."),Vr(e===$c.Error||Yc(n),"Can't provide an error when not in an error state."),this.cancelIdleCheck(),this.backoff.cancel(),this.closeCount++,e!==$c.Error?this.backoff.reset():n&&n.code===jr.RESOURCE_EXHAUSTED?(xr(n.toString()),xr("Using maximum backoff delay to prevent overloading the backend."),this.backoff.resetToMax()):n&&n.code===jr.UNAUTHENTICATED&&this.credentialsProvider.invalidateToken(),null!==this.stream&&(this.tearDown(),this.stream.close(),this.stream=null),this.state=e,[4,this.listener.onClose(n)];case 1:return t.sent(),[2]}})})},rh.prototype.tearDown=function(){},rh.prototype.auth=function(){var n=this;Vr(this.state===$c.Initial,"Must be in initial state to auth"),this.state=$c.Starting;var t=this.getCloseGuardedDispatcher(this.closeCount),e=this.closeCount;this.credentialsProvider.getToken().then(function(t){n.closeCount===e&&n.startStream(t)},function(e){t(function(){var t=new Wr(jr.UNKNOWN,"Fetching auth token failed: "+e.message);return n.handleStreamClose(t)})})},rh.prototype.startStream=function(t){var e=this;Vr(this.state===$c.Starting,"Trying to start stream in a non-starting state");var n=this.getCloseGuardedDispatcher(this.closeCount);this.stream=this.startRpc(t),this.stream.onOpen(function(){n(function(){return Vr(e.state===$c.Starting,"Expected stream to be in state Starting, but was "+e.state),e.state=$c.Open,e.listener.onOpen()})}),this.stream.onClose(function(t){n(function(){return e.handleStreamClose(t)})}),this.stream.onMessage(function(t){n(function(){return e.onMessage(t)})})},rh.prototype.performBackoff=function(){var t=this;Vr(this.state===$c.Error,"Should only perform backoff when in Error state"),this.state=$c.Backoff,this.backoff.backoffAndRun(function(){return d(t,void 0,void 0,function(){return p(this,function(t){return Vr(this.state===$c.Backoff,"Backoff elapsed but state is now: "+this.state),this.state=$c.Initial,this.start(),Vr(this.isStarted(),"PersistentStream should have started"),[2]})})})},rh.prototype.handleStreamClose=function(t){return Vr(this.isStarted(),"Can't handle server close on non-started stream"),Pr(eh,"close with error: "+t),this.stream=null,this.close($c.Error,t)},rh.prototype.getCloseGuardedDispatcher=function(e){var n=this;return function(t){n.queue.enqueueAndForget(function(){return n.closeCount===e?t():(Pr(eh,"stream callback skipped by getCloseGuardedDispatcher."),Promise.resolve())})}},rh);function rh(t,e,n,r,i,o){this.queue=t,this.idleTimerId=n,this.connection=r,this.credentialsProvider=i,this.listener=o,this.state=$c.Initial,this.closeCount=0,this.idleTimer=null,this.stream=null,this.backoff=new Jc(t,e)}var ih,oh=(t(ah,ih=nh),ah.prototype.startRpc=function(t){return this.connection.openStream("Listen",t)},ah.prototype.onMessage=function(t){this.backoff.reset();var e=this.serializer.fromWatchChange(t),n=this.serializer.versionFromListenResponse(t);return this.listener.onWatchChange(e,n)},ah.prototype.watch=function(t){var e={};e.database=this.serializer.encodedDatabaseId,e.addTarget=this.serializer.toTarget(t);var n=this.serializer.toListenRequestLabels(t);n&&(e.labels=n),this.sendRequest(e)},ah.prototype.unwatch=function(t){var e={};e.database=this.serializer.encodedDatabaseId,e.removeTarget=t,this.sendRequest(e)},ah);function ah(t,e,n,r,i){var o=ih.call(this,t,Wi.ListenStreamConnectionBackoff,Wi.ListenStreamIdle,e,n,i)||this;return o.serializer=r,o}var sh,uh=(t(ch,sh=nh),Object.defineProperty(ch.prototype,"handshakeComplete",{get:function(){return this.handshakeComplete_},enumerable:!0,configurable:!0}),ch.prototype.start=function(){this.handshakeComplete_=!1,sh.prototype.start.call(this)},ch.prototype.tearDown=function(){this.handshakeComplete_&&this.writeMutations([])},ch.prototype.startRpc=function(t){return this.connection.openStream("Write",t)},ch.prototype.onMessage=function(t){if(Vr(!!t.streamToken,"Got a write response without a stream token"),this.lastStreamToken=t.streamToken,this.handshakeComplete_){this.backoff.reset();var e=this.serializer.fromWriteResults(t.writeResults,t.commitTime),n=this.serializer.fromVersion(t.commitTime);return this.listener.onMutationResult(n,e)}return Vr(!t.writeResults||0===t.writeResults.length,"Got mutation results for handshake"),this.handshakeComplete_=!0,this.listener.onHandshakeComplete()},ch.prototype.writeHandshake=function(){Vr(this.isOpen(),"Writing handshake requires an opened stream"),Vr(!this.handshakeComplete_,"Handshake already completed");var t={};t.database=this.serializer.encodedDatabaseId,this.sendRequest(t)},ch.prototype.writeMutations=function(t){var e=this;Vr(this.isOpen(),"Writing mutations requires an opened stream"),Vr(this.handshakeComplete_,"Handshake must be complete before writing mutations"),Vr(0=":return il.GREATER_THAN_OR_EQUAL;case">":return il.GREATER_THAN;case"array-contains":return il.ARRAY_CONTAINS;case"in":return il.IN;case"array-contains-any":return il.ARRAY_CONTAINS_ANY;default:return Fr("Unknown FieldFilter operator: "+t)}},il.prototype.toString=function(){return this.name},il.prototype.isEqual=function(t){return this.name===t.name},il.LESS_THAN=new il("<"),il.LESS_THAN_OR_EQUAL=new il("<="),il.EQUAL=new il("=="),il.GREATER_THAN=new il(">"),il.GREATER_THAN_OR_EQUAL=new il(">="),il.ARRAY_CONTAINS=new il("array-contains"),il.IN=new il("in"),il.ARRAY_CONTAINS_ANY=new il("array-contains-any"),il);function il(t){this.name=t}var ol,al=(t(sl,ol=nl),sl.create=function(t,e,n){if(t.isKeyField())return e===rl.IN?(Vr(n instanceof Ms,"Comparing on key with IN, but filter value not an ArrayValue"),Vr(n.internalValue.every(function(t){return t instanceof Ts}),"Comparing on key with IN, but an array value was not a RefValue"),new fl(t,n)):(Vr(n instanceof Ts,"Comparing on key, but filter value not a RefValue"),Vr(e!==rl.ARRAY_CONTAINS&&e!==rl.ARRAY_CONTAINS_ANY,"'"+e.toString()+"' queries don't make sense on document keys."),new cl(t,e,n));if(n.isEqual(Ha.INSTANCE)){if(e!==rl.EQUAL)throw new Wr(jr.INVALID_ARGUMENT,"Invalid query. Null supports only equality comparisons.");return new sl(t,e,n)}if(n.isEqual(ss.NAN)){if(e!==rl.EQUAL)throw new Wr(jr.INVALID_ARGUMENT,"Invalid query. NaN supports only equality comparisons.");return new sl(t,e,n)}return e===rl.ARRAY_CONTAINS?new ml(t,n):e===rl.IN?(Vr(n instanceof Ms,"IN filter has invalid value: "+n.toString()),new vl(t,n)):e===rl.ARRAY_CONTAINS_ANY?(Vr(n instanceof Ms,"ARRAY_CONTAINS_ANY filter has invalid value: "+n.toString()),new Sl(t,n)):new sl(t,e,n)},sl.prototype.matches=function(t){var e=t.field(this.field);return null!==e&&this.value.typeOrder===e.typeOrder&&this.matchesComparison(e.compareTo(this.value))},sl.prototype.matchesComparison=function(t){switch(this.op){case rl.LESS_THAN:return t<0;case rl.LESS_THAN_OR_EQUAL:return t<=0;case rl.EQUAL:return 0===t;case rl.GREATER_THAN:return 0() instead."),Sd=/^__.*__$/,Td=(Ed.prototype.toMutations=function(t,e){var n=[];return null!==this.fieldMask?n.push(new Ma(t,this.data,this.fieldMask,e)):n.push(new Aa(t,this.data,e)),0=",">","array-contains"],2,e);var r,i=xd("Query.where",t),o=rl.fromString(e);if(i.isKeyField()){if(o===rl.ARRAY_CONTAINS||o===rl.ARRAY_CONTAINS_ANY)throw new Wr(jr.INVALID_ARGUMENT,"Invalid Query. You can't perform '"+o.toString()+"' queries on FieldPath.documentId().");if(o===rl.IN){this.validateDisjunctiveFilterElements(n,o);for(var a=[],s=0,u=n;sr.length)throw new Wr(jr.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 i=[],o=0;o, or >=) must be on the same field. But you have inequality filters on '"+o.toString()+"' and '"+t.field.toString()+"'");var a=this._query.getFirstOrderByField();null!==a&&this.validateOrderByAndInequalityMatch(t.field,a)}else if(i||r){var s=null;if(i&&(s=this._query.findFilterOperator(n)),null===s&&r&&(s=this._query.findFilterOperator(e)),null!=s)throw s===t.op?new Wr(jr.INVALID_ARGUMENT,"Invalid query. You cannot use more than one '"+t.op.toString()+"' filter."):new Wr(jr.INVALID_ARGUMENT,"Invalid query. You cannot use '"+t.op.toString()+"' filters with '"+s.toString()+"' filters.")}}},ip.prototype.validateNewOrderBy=function(t){if(null===this._query.getFirstOrderByField()){var e=this._query.getInequalityFilterField();null!==e&&this.validateOrderByAndInequalityMatch(e,t.field)}},ip.prototype.validateOrderByAndInequalityMatch=function(t,e){if(!e.isEqual(t))throw new Wr(jr.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 '"+e.toString()+"' instead.")},ip);function ip(t,e){this._query=t,this.firestore=e}var op=(Object.defineProperty(ap.prototype,"docs",{get:function(){var e=[];return this.forEach(function(t){return e.push(t)}),e},enumerable:!0,configurable:!0}),Object.defineProperty(ap.prototype,"empty",{get:function(){return this._snapshot.docs.isEmpty()},enumerable:!0,configurable:!0}),Object.defineProperty(ap.prototype,"size",{get:function(){return this._snapshot.docs.size},enumerable:!0,configurable:!0}),ap.prototype.forEach=function(e,n){var r=this;ni("QuerySnapshot.forEach",arguments,1,2),ri("QuerySnapshot.forEach","function",1,e),this._snapshot.docs.forEach(function(t){e.call(n,r.convertToDocumentImpl(t))})},Object.defineProperty(ap.prototype,"query",{get:function(){return new rp(this._originalQuery,this._firestore)},enumerable:!0,configurable:!0}),ap.prototype.docChanges=function(t){t&&(di("QuerySnapshot.docChanges",t,["includeMetadataChanges"]),ai("QuerySnapshot.docChanges","boolean","includeMetadataChanges",t.includeMetadataChanges));var e=!(!t||!t.includeMetadataChanges);if(e&&this._snapshot.excludesMetadataChanges)throw new Wr(jr.INVALID_ARGUMENT,"To include metadata changes with your document changes, you must also pass { includeMetadataChanges:true } to onSnapshot().");return this._cachedChanges&&this._cachedChangesIncludeMetadataChanges===e||(this._cachedChanges=function(i,e,o){if(o.oldDocs.isEmpty()){var n,r=0;return o.docChanges.map(function(t){var e=new ep(i,t.doc.key,t.doc,o.fromCache,o.mutatedKeys.has(t.doc.key));return Vr(t.type===Ih.Added,"Invalid event type for first snapshot"),Vr(!n||o.query.docComparator(n,t.doc)<0,"Got added events in wrong order"),n=t.doc,{type:"added",doc:e,oldIndex:-1,newIndex:r++}})}var a=o.oldDocs;return o.docChanges.filter(function(t){return e||t.type!==Ih.Metadata}).map(function(t){var e=new ep(i,t.doc.key,t.doc,o.fromCache,o.mutatedKeys.has(t.doc.key)),n=-1,r=-1;return t.type!==Ih.Added&&(Vr(0<=(n=a.indexOf(t.doc.key)),"Index for document not found"),a=a.delete(t.doc.key)),t.type!==Ih.Removed&&(r=(a=a.add(t.doc)).indexOf(t.doc.key)),{type:function(t){switch(t){case Ih.Added:return"added";case Ih.Modified:case Ih.Metadata:return"modified";case Ih.Removed:return"removed";default:return Fr("Unknown change type: "+t)}}(t.type),doc:e,oldIndex:n,newIndex:r}})}(this._firestore,e,this._snapshot),this._cachedChangesIncludeMetadataChanges=e),this._cachedChanges},ap.prototype.isEqual=function(t){if(!(t instanceof ap))throw pi("isEqual","QuerySnapshot",1,t);return this._firestore===t._firestore&&this._originalQuery.isEqual(t._originalQuery)&&this._snapshot.isEqual(t._snapshot)},ap.prototype.convertToDocumentImpl=function(t){return new ep(this._firestore,t.key,t,this.metadata.fromCache,this._snapshot.mutatedKeys.has(t.key))},ap);function ap(t,e,n){this._firestore=t,this._originalQuery=e,this._snapshot=n,this._cachedChanges=null,this._cachedChangesIncludeMetadataChanges=null,this.metadata=new Xd(n.hasPendingWrites,n.fromCache)}a(["length","forEach","map"],"undefined"!=typeof Symbol?[Symbol.iterator]:[]).forEach(function(t){try{Object.defineProperty(op.prototype.docChanges,t,{get:function(){return function(){throw new Wr(jr.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 sp,up=(t(cp,sp=rp),Object.defineProperty(cp.prototype,"id",{get:function(){return this._query.path.lastSegment()},enumerable:!0,configurable:!0}),Object.defineProperty(cp.prototype,"parent",{get:function(){var t=this._query.path.popLast();return t.isEmpty()?null:new Hd(new Ki(t),this.firestore)},enumerable:!0,configurable:!0}),Object.defineProperty(cp.prototype,"path",{get:function(){return this._query.path.canonicalString()},enumerable:!0,configurable:!0}),cp.prototype.doc=function(t){if(ni("CollectionReference.doc",arguments,0,1),0===arguments.length&&(t=gi.newId()),ri("CollectionReference.doc","non-empty string",1,t),""===t)throw new Wr(jr.INVALID_ARGUMENT,"Document path must be a non-empty string");var e=qi.fromString(t);return Hd.forPath(this._query.path.child(e),this.firestore)},cp.prototype.add=function(t){ti("CollectionReference.add",arguments,1),ri("CollectionReference.add","object",1,t);var e=this.doc();return e.set(t).then(function(){return e})},cp);function cp(t,e){var n=sp.call(this,tl.atPath(t),e)||this;if(t.length%2!=1)throw new Wr(jr.INVALID_ARGUMENT,"Invalid collection reference. Collection references must have an odd number of segments, but "+t.canonicalString()+" has "+t.length);return n}function hp(t,e){if(void 0===e)return{merge:!1};if(di(t,e,["merge","mergeFields"]),ai(t,"boolean","merge",e.merge),si(t,"mergeFields","a string or a FieldPath",e.mergeFields,function(t){return"string"==typeof t||t instanceof jf}),void 0!==e.mergeFields&&void 0!==e.merge)throw new Wr(jr.INVALID_ARGUMENT,"Invalid options passed to function "+t+'(): You cannot specify both "merge" and "mergeFields".');return e}function lp(t,e){return void 0===e?{}:(di(t,e,["serverTimestamps"]),ui(t,0,"serverTimestamps",e.serverTimestamps,["estimate","previous","none"]),e)}function fp(t,e){ii(t,"object",1,e),e&&(di(t,e,["source"]),ui(t,0,"source",e.source,["default","server","cache"]))}function dp(t,e,n){if(e instanceof Hd){if(e.firestore!==n)throw new Wr(jr.INVALID_ARGUMENT,"Provided document reference is from a different Firestore instance.");return e}throw pi(t,"DocumentReference",1,e)}var pp=zr(Qd,"Use firebase.firestore() instead."),mp=zr(jd,"Use firebase.firestore().runTransaction() instead."),yp=zr(Gd,"Use firebase.firestore().batch() instead."),gp=zr(Hd,"Use firebase.firestore().doc() instead."),vp=zr(Zd),bp=zr(ep),wp=zr(rp),Sp=zr(op),Tp=zr(up,"Use firebase.firestore().collection() instead."),Ep={Firestore:pp,GeoPoint:Zh,Timestamp:ao,Blob:Di,Transaction:mp,WriteBatch:yp,DocumentReference:gp,DocumentSnapshot:vp,Query:wp,QueryDocumentSnapshot:bp,QuerySnapshot:Sp,CollectionReference:Tp,FieldPath:jf,FieldValue:wd,setLogLevel:Qd.setLogLevel,CACHE_SIZE_UNLIMITED:Vd};function Ip(t){t.INTERNAL.registerService("firestore",function(t){return new Qd(t)},function(t){Vr(t&&"object"==typeof t,"shallowCopy() expects object parameter.");var e={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e}(Ep))}var Cp=(Dp.prototype.addCallback=function(t){},Dp.prototype.shutdown=function(){},Dp);function Dp(){}var Np="ConnectivityMonitor",Ap=(kp.prototype.addCallback=function(t){this.callbacks.push(t)},kp.prototype.shutdown=function(){window.removeEventListener("online",this.networkAvailableListener),window.removeEventListener("offline",this.networkUnavailableListener)},kp.prototype.configureNetworkMonitoring=function(){window.addEventListener("online",this.networkAvailableListener),window.addEventListener("offline",this.networkUnavailableListener)},kp.prototype.onNetworkAvailable=function(){Pr(Np,"Network connectivity changed: AVAILABLE");for(var t=0,e=this.callbacks;t