!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(zd){"use strict";try{(function(){zd=zd&&zd.hasOwnProperty("default")?zd.default:zd;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 d(i,s),c=0,h=Object.keys(r);c>>0),P=0;function x(t,e,n){return t.call.apply(t.bind,arguments)}function F(e,n,t){if(!e)throw Error();if(2parseFloat(dt)){ot=String(yt);break t}}ot=dt}var gt,vt={};function bt(s){return function(t,e){var n=vt;return Object.prototype.hasOwnProperty.call(n,t)?n[t]:n[t]=e(t)}(s,function(){for(var t=0,e=Y(String(ot)).split("."),n=Y(String(s)).split("."),r=Math.max(e.length,n.length),i=0;0==t&&i>>0);function Wt(e){return"function"==R(e)?e:(e[Qt]||(e[Qt]=function(t){return e.handleEvent(t)}),e[Qt])}function jt(){K.call(this),this.c=new Mt(this),(this.J=this).B=null}function Gt(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 Be(t){t.R=B()+t.O,Ue(t,t.O)}function Ue(t,e){if(null!=t.i)throw Error("WatchDog timer not null");t.i=we(q(t.ab,t),e)}function Ke(t){t.i&&(C.clearTimeout(t.i),t.i=null)}function Qe(t){t.g.Ca()||t.m||t.g.na(t)}function We(t){Ke(t);var e=t.B;e&&"function"==typeof e.la&&e.la(),t.B=null,oe(t.P),fe(t.I),t.a&&(e=t.a,t.a=null,e.abort(),e.la())}function je(t,e){try{t.g.Fa(t,e),ye(4)}catch(t){}}function Ge(t,e){if(t.forEach&&"function"==typeof t.forEach)t.forEach(e,void 0);else if(_(t)||D(t))W(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(_(t)||D(t)){n=[];for(var r=t.length,i=0;i2*t.c&&Ye(t))}function Ye(t){if(t.c!=t.a.length){for(var e=0,n=0;e>4&15).toString(16)+(15&t).toString(16)}Ze.prototype.toString=function(){var t=[],e=this.f;e&&t.push(cn(e,ln,!0),":");var n=this.b;return!n&&"file"!=e||(t.push("//"),(e=this.j)&&t.push(cn(e,ln,!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(cn(n,"/"==n.charAt(0)?pn:fn,!0))),(n=this.c.toString())&&t.push("?",n),(n=this.g)&&t.push("#",cn(n,mn)),t.join("")},Ze.prototype.resolve=function(t){var e=$e(this),n=!!t.f;n?tn(e,t.f):n=!!t.j,n?e.j=t.j:n=!!t.b,n?en(e,t.b):n=null!=t.i;var r=t.a;if(n)nn(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(J(i,"./")||J(i,"/.")){r=0==i.lastIndexOf("/",0),i=i.split("/");for(var o=[],a=0;a=t.f}function Ln(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=Nn(e),Je(t.a.a.b,e))}function Pn(t,e){t.a?t.a.add(e):t.b=e}function xn(t,e){var n;t.b&&t.b==e?t.b=null:((n=t.a)&&(n=Nn(e),n=Je(t.a.a.b,n)),n&&He(t.a.a,Nn(e)))}function Fn(t){if(null!=t.b)return t.c.concat(t.b.j);if(null==t.a||0==t.a.a.c)return G(t.c);var e=t.c;return W(t.a.C(),function(t){e=e.concat(t.j)}),e}function qn(){}function Vn(){this.a=new qn}function Bn(t,r,e){var i=e||"";try{Ge(t,function(t,e){var n=t;L(t)&&(n=zt(t)),r.push(i+e+"="+encodeURIComponent(n))})}catch(t){throw r.push(i+"type="+encodeURIComponent("_badmap")),t}}function Un(t,e,n,r,i){try{e.onload=null,e.onerror=null,e.onabort=null,e.ontimeout=null,i(r)}catch(t){}}kn.prototype.cancel=function(){this.c=Fn(this),this.b?(this.b.cancel(),this.b=null):this.a&&0!=this.a.a.c&&(W(this.a.C(),function(t){t.cancel()}),function(t){t.b={},t.a.length=0,t.c=0}(this.a.a))},qn.prototype.stringify=function(t){return C.JSON.stringify(t,void 0)},qn.prototype.parse=function(t){return C.JSON.parse(t,void 0)};var Kn=C.JSON.parse;function Qn(t){jt.call(this),this.headers=new ze,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=Wn,this.D=this.F=!1}U(Qn,jt);var Wn="",jn=/^https?$/i,Gn=["POST","PUT"];function zn(t){return"content-type"==t.toLowerCase()}function Hn(t,e){t.b=!1,t.a&&(t.g=!0,t.a.abort(),t.g=!1),t.f=e,t.h=5,Yn(t),Xn(t)}function Yn(t){t.v||(t.v=!0,t.dispatchEvent("complete"),t.dispatchEvent("error"))}function Jn(t){if(t.b&&void 0!==I&&(!t.s[1]||4!=$n(t)||2!=t.T()))if(t.l&&4==$n(t))ae(t.Ea,0,t);else if(t.dispatchEvent("readystatechange"),4==$n(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(Xe)[1]||null;if(!o&&C.self&&C.self.location){var a=C.self.location.protocol;o=a.substr(0,a.length-1)}i=!jn.test(o?o.toLowerCase():"")}e=i}if(e)t.dispatchEvent("complete"),t.dispatchEvent("success");else{t.h=6;try{var s=2<$n(t)?t.a.statusText:""}catch(t){s=""}t.f=s+" ["+t.T()+"]",Yn(t)}}finally{Xn(t)}}}function Xn(t,e){if(t.a){Zn(t);var n=t.a,r=t.s[0]?k:null;t.a=null,t.s=null,e||t.dispatchEvent("ready");try{n.onreadystatechange=r}catch(t){}}}function Zn(t){t.a&&t.D&&(t.a.ontimeout=null),t.m&&(C.clearTimeout(t.m),t.m=null)}function $n(t){return t.a?t.a.readyState:0}function tr(t,e){return t.a?t.a.getResponseHeader(e):null}function er(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 tt(t,function(t,e){n+=e,n+=":",n+=t,n+="\r\n"}),n}(n),D(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.Oa?0:t.Pa))&&(t.h=we(q(t.Ha,t,e),dr(t,t.A)),t.A++,!0))}(this,t)||2==n&&lr(this)))switch(e&&0r)throw new zr(Gr.INVALID_ARGUMENT,"Function "+t+"() requires between "+n+" and "+r+" arguments, but was called with "+bi(e.length,"argument")+".")}function oi(t,e,n,r){li(t,e,vi(n)+" argument",r)}function ai(t,e,n,r){void 0!==r&&oi(t,e,n,r)}function si(t,e,n,r){li(t,e,n+" option",r)}function ui(t,e,n,r){void 0!==r&&si(t,e,n,r)}function ci(t,e,n,r,i){void 0!==r&&function(t,e,n,r,i){if(!(r instanceof Array))throw new zr(Gr.INVALID_ARGUMENT,"Function "+t+"() requires its "+e+" option to be an array, but it was: "+pi(r));for(var o=0;o=t,"Can't call popFirst() with less segments"),this.construct(this.segments,this.offset+t,this.length-t)},qi.prototype.popLast=function(){return Ur(!this.isEmpty(),"Can't call popLast() on empty path"),this.construct(this.segments,this.offset,this.length-1)},qi.prototype.firstSegment=function(){return Ur(!this.isEmpty(),"Can't call firstSegment() on empty path"),this.segments[this.offset]},qi.prototype.lastSegment=function(){return this.get(this.length-1)},qi.prototype.get=function(t){return Ur(te.length?1:0},qi);function qi(t,e,n){void 0===e?e=0:e>t.length&&Br("offset "+e+" out of range "+t.length),void 0===n?n=t.length-e:n>t.length-e&&Br("length "+n+" out of range "+(t.length-e)),this.segments=t,this.offset=e,this.len=n}var Vi,Bi=(t(Ui,Vi=Fi),Ui.prototype.construct=function(t,e,n){return new Ui(t,e,n)},Ui.prototype.canonicalString=function(){return this.toArray().join("/")},Ui.prototype.toString=function(){return this.canonicalString()},Ui.fromString=function(t){if(0<=t.indexOf("//"))throw new zr(Gr.INVALID_ARGUMENT,"Invalid path ("+t+"). Paths must not contain // in them.");return new Ui(t.split("/").filter(function(t){return 0",t),this.store.put(t)))},Xo.prototype.add=function(t){return Fr(Qo,"ADD",this.store.name,t,t),Zo(this.store.add(t))},Xo.prototype.get=function(e){var n=this;return Zo(this.store.get(e)).next(function(t){return void 0===t&&(t=null),Fr(Qo,"GET",n.store.name,e,t),t})},Xo.prototype.delete=function(t){return Fr(Qo,"DELETE",this.store.name,t),Zo(this.store.delete(t))},Xo.prototype.count=function(){return Fr(Qo,"COUNT",this.store.name),Zo(this.store.count())},Xo.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})},Xo.prototype.deleteAll=function(t,e){Fr(Qo,"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()})},Xo.prototype.iterate=function(t,e){var n;e?n=t:(n={},e=t);var r=this.cursor(n);return this.iterateCursor(r,e)},Xo.prototype.iterateSerial=function(i){var t=this.cursor({});return new Uo(function(n,r){t.onerror=function(t){var e=ta(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()}})},Xo.prototype.iterateCursor=function(t,a){var s=[];return new Uo(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 Go(e),r=a(e.primaryKey,e.value,n);if(r instanceof Uo){var i=r.catch(function(t){return n.done(),Uo.reject(t)});s.push(i)}n.isDone?o():null===n.skipToKey?e.continue():e.continue(n.skipToKey)}else o()}}).next(function(){return Uo.waitFor(s)})},Xo.prototype.options=function(t,e){var n=void 0;return void 0!==t&&("string"==typeof t?n=t:(Ur(void 0===e,"3rd argument must not be defined if 2nd is a range."),e=t)),{index:n,range:e}},Xo.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)},Xo);function Xo(t){this.store=t}function Zo(t){return new Uo(function(n,r){t.onsuccess=function(t){var e=t.target.result;n(e)},t.onerror=function(t){var e=ta(t.target.error);r(e)}})}var $o=!1;function ta(t){var e=Wo.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 zr("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 $o||($o=!0,setTimeout(function(){throw r},0)),r}}return t}var ea=(na.forUser=function(t,e,n,r){return Ur(""!==t.uid,"UserID must not be an empty string."),new na(t.isAuthenticated()?t.uid:"",e,n,r)},na.prototype.checkEmpty=function(t){var r=!0,e=IDBKeyRange.bound([this.userId,Number.NEGATIVE_INFINITY],[this.userId,Number.POSITIVE_INFINITY]);return aa(t).iterate({index:gu.userMutationsIndex,range:e},function(t,e,n){r=!1,n.done()}).next(function(){return r})},na.prototype.acknowledgeBatch=function(e,t,n){return this.getMutationQueueMetadata(e).next(function(t){return t.lastStreamToken=oa(n),ua(e).put(t)})},na.prototype.getLastStreamToken=function(t){return this.getMutationQueueMetadata(t).next(function(t){return t.lastStreamToken})},na.prototype.setLastStreamToken=function(e,n){return this.getMutationQueueMetadata(e).next(function(t){return t.lastStreamToken=oa(n),ua(e).put(t)})},na.prototype.addMutationBatch=function(c,h,l,f){var p=this,d=sa(c),m=aa(c);return m.add({}).next(function(t){Ur("number"==typeof t,"Auto-generated key is not a number");for(var e=new Fo(t,h,l,f),n=p.serializer.toDbMutationBatch(p.userId,e),r=[],i=new So(function(t,e){return Si(t.canonicalString(),e.canonicalString())}),o=0,a=f;o=i,"Should have found mutation after "+i),o=r.serializer.fromDbMutationBatch(e)),n.done()}).next(function(){return o})},na.prototype.getHighestUnacknowledgedBatchId=function(t){var e=IDBKeyRange.upperBound([this.userId,Number.POSITIVE_INFINITY]),r=-1;return aa(t).iterate({index:gu.userMutationsIndex,range:e,reverse:!0},function(t,e,n){r=e.batchId,n.done()}).next(function(){return r})},na.prototype.getAllMutationBatches=function(t){var e=this,n=IDBKeyRange.bound([this.userId,-1],[this.userId,Number.POSITIVE_INFINITY]);return aa(t).loadAll(gu.userMutationsIndex,n).next(function(t){return t.map(function(t){return e.serializer.fromDbMutationBatch(t)})})},na.prototype.getAllMutationBatchesAffectingDocumentKey=function(s,u){var c=this,t=bu.prefixForPath(this.userId,u.path),e=IDBKeyRange.lowerBound(t),h=[];return sa(s).iterate({range:e},function(e,t,n){var r=e[0],i=e[1],o=e[2],a=uo(i);if(r===c.userId&&u.path.isEqual(a))return aa(s).get(o).next(function(t){if(!t)throw Br("Dangling document-mutation reference found: "+e+" which points to "+o);Ur(t.userId===c.userId,"Unexpected user '"+t.userId+"' for mutation batch "+o),h.push(c.serializer.fromDbMutationBatch(t))});n.done()}).next(function(){return h})},na.prototype.getAllMutationBatchesAffectingDocumentKeys=function(r,t){var u=this,c=new So(Si),i=[];return t.forEach(function(s){var t=bu.prefixForPath(u.userId,s.path),e=IDBKeyRange.lowerBound(t),n=sa(r).iterate({range:e},function(t,e,n){var r=t[0],i=t[1],o=t[2],a=uo(i);r===u.userId&&s.path.isEqual(a)?c=c.add(o):n.done()});i.push(n)}),Uo.waitFor(i).next(function(){return u.lookupMutationBatches(r,c)})},na.prototype.getAllMutationBatchesAffectingQuery=function(t,e){var s=this;Ur(!e.isDocumentQuery(),"Document queries shouldn't go down this path"),Ur(!e.isCollectionGroupQuery(),"CollectionGroup queries should be handled in LocalDocumentsView");var u=e.path,c=u.length+1,n=bu.prefixForPath(this.userId,u),r=IDBKeyRange.lowerBound(n),h=new So(Si);return sa(t).iterate({range:r},function(t,e,n){var r=t[0],i=t[1],o=t[2],a=uo(i);r===s.userId&&u.isPrefixOf(a)?a.length===c&&(h=h.add(o)):n.done()}).next(function(){return s.lookupMutationBatches(t,h)})},na.prototype.lookupMutationBatches=function(t,e){var n=this,r=[],i=[];return e.forEach(function(e){i.push(aa(t).get(e).next(function(t){if(null===t)throw Br("Dangling document-mutation reference found, which points to "+e);Ur(t.userId===n.userId,"Unexpected user '"+t.userId+"' for mutation batch "+e),r.push(n.serializer.fromDbMutationBatch(t))}))}),Uo.waitFor(i).next(function(){return r})},na.prototype.removeMutationBatch=function(e,n){var r=this;return ia(e.simpleDbTransaction,this.userId,n).next(function(t){return e.addOnCommittedListener(function(){r.removeCachedMutationKeys(n.batchId)}),Uo.forEach(t,function(t){return r.referenceDelegate.removeMutationReference(e,t)})})},na.prototype.removeCachedMutationKeys=function(t){delete this.documentKeysByBatchId[t]},na.prototype.performConsistencyCheck=function(n){var o=this;return this.checkEmpty(n).next(function(t){if(!t)return Uo.resolve();var e=IDBKeyRange.lowerBound(bu.prefixForUser(o.userId)),i=[];return sa(n).iterate({range:e},function(t,e,n){if(t[0]===o.userId){var r=uo(t[1]);i.push(r)}else n.done()}).next(function(){Ur(0===i.length,"Document leak -- detected dangling mutation references when queue is empty. Dangling keys: "+i.map(function(t){return t.canonicalString()}))})})},na.prototype.containsKey=function(t,e){return ra(t,this.userId,e)},na.prototype.getMutationQueueMetadata=function(t){var e=this;return ua(t).get(this.userId).next(function(t){return t||new mu(e.userId,-1,"")})},na);function na(t,e,n,r){this.userId=t,this.serializer=e,this.indexManager=n,this.referenceDelegate=r,this.documentKeysByBatchId={}}function ra(t,o,e){var n=bu.prefixForPath(o,e.path),a=n[1],r=IDBKeyRange.lowerBound(n),s=!1;return sa(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 ia(t,e,n){var r=t.store(gu.store),i=t.store(bu.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(){Ur(1===s,"Dangling document-mutation reference found: Missing batch "+n.batchId)}));for(var c=[],h=0,l=n.mutations;ht.highestListenSequenceNumber&&(t.highestListenSequenceNumber=n),i.saveMetadata(e,t)})},da.prototype.addTargetData=function(e,n){var r=this;return this.saveTargetData(e,n).next(function(){return r.retrieveMetadata(e).next(function(t){return t.targetCount+=1,r.updateMetadataFromTargetData(n,t),r.saveMetadata(e,t)})})},da.prototype.updateTargetData=function(t,e){return this.saveTargetData(t,e)},da.prototype.removeTargetData=function(e,t){var n=this;return this.removeMatchingKeysForTargetId(e,t.targetId).next(function(){return ma(e).delete(t.targetId)}).next(function(){return n.retrieveMetadata(e)}).next(function(t){return Ur(0e.highestTargetId&&(e.highestTargetId=t.targetId,n=!0),t.sequenceNumber>e.highestListenSequenceNumber&&(e.highestListenSequenceNumber=t.sequenceNumber,n=!0),n},da.prototype.getTargetCount=function(t){return this.retrieveMetadata(t).next(function(t){return t.targetCount})},da.prototype.getTargetData=function(t,i){var o=this,e=i.canonicalId(),n=IDBKeyRange.bound([e,Number.NEGATIVE_INFINITY],[e,Number.POSITIVE_INFINITY]),a=null;return ma(t).iterate({range:n,index:Nu.queryTargetsIndexName},function(t,e,n){var r=o.serializer.fromDbTarget(e);i.isEqual(r.target)&&(a=r,n.done())}).next(function(){return a})},da.prototype.addMatchingKeys=function(n,t,r){var i=this,o=[],a=va(n);return t.forEach(function(t){var e=oo(t.path);o.push(a.put(new ku(r,e))),o.push(i.referenceDelegate.addReference(n,t))}),Uo.waitFor(o)},da.prototype.removeMatchingKeys=function(n,t,r){var i=this,o=va(n);return Uo.forEach(t,function(t){var e=oo(t.path);return Uo.waitFor([o.delete([r,e]),i.referenceDelegate.removeReference(n,t)])})},da.prototype.removeMatchingKeysForTargetId=function(t,e){var n=va(t),r=IDBKeyRange.bound([e],[e+1],!1,!0);return n.delete(r)},da.prototype.getMatchingKeysForTargetId=function(t,e){var n=IDBKeyRange.bound([e],[e+1],!1,!0),r=va(t),o=Oo();return r.iterate({range:n,keysOnly:!0},function(t,e,n){var r=uo(t[1]),i=new Gi(r);o=o.add(i)}).next(function(){return o})},da.prototype.containsKey=function(t,e){var n=oo(e.path),r=IDBKeyRange.bound([n],[Ii(n)],!1,!0),i=0;return va(t).iterate({index:ku.documentTargetsIndex,keysOnly:!0,range:r},function(t,e,n){var r=t[0];t[1],0!==r&&(i++,n.done())}).next(function(){return 0"},ws);function ws(t,e){var n=vs.call(this)||this;return n.localWriteTime=t,n.previousValue=e,n.typeOrder=Ba.TimestampValue,n}var Ts,Ss=(t(Es,Ts=Ha),Es.prototype.value=function(t){return this.internalValue},Es.prototype.isEqual=function(t){return t instanceof Es&&this.internalValue.isEqual(t.internalValue)},Es.prototype.compareTo=function(t){return t instanceof Es?this.internalValue._compareTo(t.internalValue):this.defaultCompareTo(t)},Es);function Es(t){var e=Ts.call(this)||this;return e.internalValue=t,e.typeOrder=Ba.BlobValue,e}var Is,Cs=(t(Ds,Is=Ha),Ds.prototype.value=function(t){return this.key},Ds.prototype.isEqual=function(t){return t instanceof Ds&&this.key.isEqual(t.key)&&this.databaseId.isEqual(t.databaseId)},Ds.prototype.compareTo=function(t){if(t instanceof Ds){var e=this.databaseId.compareTo(t.databaseId);return 0!==e?e:Gi.comparator(this.key,t.key)}return this.defaultCompareTo(t)},Ds);function Ds(t,e){var n=Is.call(this)||this;return n.databaseId=t,n.key=e,n.typeOrder=Ba.RefValue,n}var Ns,As=(t(ks,Ns=Ha),ks.prototype.value=function(t){return this.internalValue},ks.prototype.isEqual=function(t){return t instanceof ks&&this.internalValue.isEqual(t.internalValue)},ks.prototype.compareTo=function(t){return t instanceof ks?this.internalValue._compareTo(t.internalValue):this.defaultCompareTo(t)},ks);function ks(t){var e=Ns.call(this)||this;return e.internalValue=t,e.typeOrder=Ba.GeoPointValue,e}var Rs,Ms=(t(_s,Rs=Ha),_s.prototype.value=function(n){var r={};return this.internalValue.inorderTraversal(function(t,e){r[t]=e.value(n)}),r},_s.prototype.forEach=function(t){this.internalValue.inorderTraversal(t)},_s.prototype.isEqual=function(t){if(t instanceof _s){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},_s.prototype.compareTo=function(t){if(t instanceof _s){for(var e=this.internalValue.getIterator(),n=t.internalValue.getIterator();e.hasNext()&&n.hasNext();){var r=e.getNext(),i=n.getNext(),o=Si(r.key,i.key)||r.value.compareTo(i.value);if(o)return o}return Si(e.hasNext(),n.hasNext())}return this.defaultCompareTo(t)},_s.prototype.set=function(t,e){if(Ur(!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 _s||(n=_s.EMPTY);var r=n.set(t.popFirst(),e);return this.setChild(t.firstSegment(),r)},_s.prototype.delete=function(t){if(Ur(!t.isEmpty(),"Cannot delete field for empty path on ObjectValue"),1===t.length)return new _s(this.internalValue.remove(t.firstSegment()));var e=this.child(t.firstSegment());if(e instanceof _s){var n=e.delete(t.popFirst());return new _s(this.internalValue.insert(t.firstSegment(),n))}return this},_s.prototype.contains=function(t){return null!==this.field(t)},_s.prototype.field=function(t){Ur(!t.isEmpty(),"Can't get field of empty path");var e=this;return t.forEach(function(t){e=e instanceof _s?e.internalValue.get(t):null}),e},_s.prototype.fieldMask=function(){var i=new So(Wi.comparator);return this.internalValue.forEach(function(t,e){var n=new Wi([t]);if(e instanceof _s){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)}),ba.fromSet(i)},_s.prototype.toString=function(){return this.internalValue.toString()},_s.prototype.child=function(t){return this.internalValue.get(t)||void 0},_s.prototype.setChild=function(t,e){return new _s(this.internalValue.insert(t,e))},_s.EMPTY=new _s(new po(Si)),_s);function _s(t){var e=Rs.call(this)||this;return e.internalValue=t,e.typeOrder=Ba.ObjectValue,e}var Ls,Os=(t(Ps,Ls=Ha),Ps.prototype.value=function(e){return this.internalValue.map(function(t){return t.value(e)})},Ps.prototype.contains=function(t){for(var e=0,n=this.internalValue;eh.params.maximumSequenceNumbersToCollect?(Fr("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(),Pr()<=Cr.DEBUG&&Fr("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"),Uo.resolve({didRun:!0,sequenceNumbersCollected:i,targetsRemoved:o,documentsRemoved:t})})},rc);function rc(t,e){this.delegate=t,this.params=e}var ic=(oc.prototype.addOnCommittedListener=function(t){this.onCommittedListeners.push(t)},oc.prototype.raiseOnCommittedEvent=function(){this.onCommittedListeners.forEach(function(t){return t()})},oc);function oc(){this.onCommittedListeners=[]}var ac,sc="IndexedDbPersistence",uc="The current tab is not in the required state to perform this operation. It might be necessary to refresh the browser tab.",cc="Another tab has exclusive access to the persistence layer. To allow shared access, make sure to invoke `enablePersistence()` with `synchronizeTabs:true` in all tabs.",hc=(t(lc,ac=ic),lc);function lc(t,e){var n=ac.call(this)||this;return n.simpleDbTransaction=t,n.currentSequenceNumber=e,n}var fc=(pc.getStore=function(t,e){if(t instanceof hc)return Wo.getStore(t.simpleDbTransaction,e);throw Br("IndexedDbPersistence must use instances of IndexedDbTransaction")},pc.createIndexedDbPersistence=function(n){return p(this,void 0,void 0,function(){var e;return m(this,function(t){switch(t.label){case 0:if(!pc.isAvailable())throw new zr(Gr.UNIMPLEMENTED,"This platform is either missing IndexedDB or is known to have an incomplete implementation. Offline persistence has been disabled.");return[4,(e=new pc(n.allowTabSynchronization,n.persistenceKey,n.clientId,n.platform,n.lruParams,n.queue,n.serializer,n.sequenceNumberSyncer)).start()];case 1:return t.sent(),[2,e]}})})},pc.prototype.start=function(){var e=this;return Ur(!this.started,"IndexedDbPersistence double-started!"),Ur(null!==this.window,"Expected 'window' to be defined"),Wo.openOrCreate(this.dbName,cu,new hu(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",[Mu.store],function(t){return ga(t)})}).then(function(t){e.listenSequence=new Oi(t,e.sequenceNumberSyncer)}).then(function(){e._started=!0}).catch(function(t){return e.simpleDb&&e.simpleDb.close(),Promise.reject(t)})},pc.prototype.setPrimaryStateListener=function(n){var t=this;return this.primaryStateListener=function(e){return p(t,void 0,void 0,function(){return m(this,function(t){return this.started?[2,n(e)]:[2]})})},n(this.isPrimary)},pc.prototype.setDatabaseDeletedListener=function(n){var t=this;this.simpleDb.setVersionChangeListener(function(e){return p(t,void 0,void 0,function(){return m(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]}})})})},pc.prototype.setNetworkEnabled=function(t){var e=this;this.networkEnabled!==t&&(this.networkEnabled=t,this.queue.enqueueAndForget(function(){return p(e,void 0,void 0,function(){return m(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]}})})}))},pc.prototype.updateClientMetadataAndTryBecomePrimary=function(){var n=this;return this.simpleDb.runTransaction("readwrite-idempotent",Bu,function(e){return yc(e).put(new xu(n.clientId,Date.now(),n.networkEnabled,n.inForeground)).next(function(){if(n.isPrimary)return n.verifyPrimaryLease(e).next(function(t){t||(n.isPrimary=!1,n.queue.enqueueAndForget(function(){return n.primaryStateListener(!1)}))})}).next(function(){return n.canActAsPrimary(e)}).next(function(t){return n.isPrimary&&!t?n.releasePrimaryLeaseIfHeld(e).next(function(){return!1}):!!t&&n.acquireOrExtendPrimaryLease(e).next(function(){return!0})})}).catch(function(t){if(!n.allowTabSynchronization)throw t;return Fr(sc,"Releasing owner lease after error during lease refresh",t),!1}).then(function(t){n.isPrimary!==t&&n.queue.enqueueAndForget(function(){return n.primaryStateListener(t)}),n.isPrimary=t})},pc.prototype.verifyPrimaryLease=function(t){var e=this;return mc(t).get(pu.key).next(function(t){return Uo.resolve(e.isLocalClient(t))})},pc.prototype.removeClientMetadata=function(t){return yc(t).delete(this.clientId)},pc.prototype.maybeGarbageCollectMultiClientState=function(){return p(this,void 0,void 0,function(){var i=this;return m(this,function(t){switch(t.label){case 0:return!this.isPrimary||this.isWithinAge(this.lastGarbageCollectionTime,18e5)?[3,2]:(this.lastGarbageCollectionTime=Date.now(),[4,this.runTransaction("maybeGarbageCollectMultiClientState","readwrite-primary-idempotent",function(t){var r=pc.getStore(t,xu.store);return r.loadAll().next(function(t){var e=i.filterActiveClients(t,18e5),n=t.filter(function(t){return-1===e.indexOf(t)});return Uo.forEach(n,function(t){return r.delete(t.clientId)}).next(function(){return n})})})]);case 1:t.sent().forEach(function(t){i.window.localStorage.removeItem(i.zombiedClientLocalStorageKey(t.clientId))}),t.label=2;case 2:return[2]}})})},pc.prototype.scheduleClientMetadataAndPrimaryLeaseRefreshes=function(){var t=this;this.clientMetadataRefresher=this.queue.enqueueAfterDelay(Hi.ClientMetadataRefresh,4e3,function(){return t.updateClientMetadataAndTryBecomePrimary().then(function(){return t.maybeGarbageCollectMultiClientState()}).then(function(){return t.scheduleClientMetadataAndPrimaryLeaseRefreshes()})})},pc.prototype.isLocalClient=function(t){return!!t&&t.ownerId===this.clientId},pc.prototype.canActAsPrimary=function(e){var i=this;return mc(e).get(pu.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 zr(Gr.FAILED_PRECONDITION,cc);return!1}}return!(!i.networkEnabled||!i.inForeground)||yc(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&&Fr(sc,"Client "+(t?"is":"is not")+" eligible for a primary lease."),t})},pc.prototype.shutdown=function(){return p(this,void 0,void 0,function(){var e=this;return m(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",[pu.store,xu.store],function(t){return e.releasePrimaryLeaseIfHeld(t).next(function(){return e.removeClientMetadata(t)})})];case 1:return t.sent(),this.simpleDb.close(),this.removeClientZombiedEntry(),[2]}})})},pc.prototype.filterActiveClients=function(t,e){var n=this;return t.filter(function(t){return n.isWithinAge(t.updateTimeMs,e)&&!n.isClientZombied(t.clientId)})},pc.prototype.getActiveClients=function(){var e=this;return this.simpleDb.runTransaction("readonly-idempotent",[xu.store],function(t){return yc(t).loadAll().next(function(t){return e.filterActiveClients(t,18e5).map(function(t){return t.clientId})})})},pc.clearPersistence=function(n){return p(this,void 0,void 0,function(){var e;return m(this,function(t){switch(t.label){case 0:return pc.isAvailable()?(e=n+pc.MAIN_DATABASE,[4,Wo.delete(e)]):[2,Promise.resolve()];case 1:return t.sent(),[2]}})})},Object.defineProperty(pc.prototype,"started",{get:function(){return this._started},enumerable:!0,configurable:!0}),pc.prototype.getMutationQueue=function(t){return Ur(this.started,"Cannot initialize MutationQueue before persistence is started."),ea.forUser(t,this.serializer,this.indexManager,this.referenceDelegate)},pc.prototype.getTargetCache=function(){return Ur(this.started,"Cannot initialize TargetCache before persistence is started."),this.targetCache},pc.prototype.getRemoteDocumentCache=function(){return Ur(this.started,"Cannot initialize RemoteDocumentCache before persistence is started."),this.remoteDocumentCache},pc.prototype.getIndexManager=function(){return Ur(this.started,"Cannot initialize IndexManager before persistence is started."),this.indexManager},pc.prototype.runTransaction=function(n,t,r){var i=this;Fr(sc,"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,Bu,function(e){return o=new hc(e,i.listenSequence.next()),"readwrite-primary"===t||"readwrite-primary-idempotent"===t?i.verifyPrimaryLease(e).next(function(t){return!!t||i.canActAsPrimary(e)}).next(function(t){if(!t)throw qr("Failed to obtain primary lease for action '"+n+"'."),i.isPrimary=!1,i.queue.enqueueAndForget(function(){return i.primaryStateListener(!1)}),new zr(Gr.FAILED_PRECONDITION,uc);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})},pc.prototype.verifyAllowTabSynchronization=function(t){var e=this;return mc(t).get(pu.key).next(function(t){if(null!==t&&e.isWithinAge(t.leaseTimestampMs,5e3)&&!e.isClientZombied(t.ownerId)&&!e.isLocalClient(t)&&!t.allowTabSynchronization)throw new zr(Gr.FAILED_PRECONDITION,cc)})},pc.prototype.acquireOrExtendPrimaryLease=function(t){var e=new pu(this.clientId,this.allowTabSynchronization,Date.now());return mc(t).put(pu.key,e)},pc.isAvailable=function(){return Wo.isAvailable()},pc.buildStoragePrefix=function(t){var e=t.databaseId.projectId;return t.databaseId.isDefaultDatabase||(e+="."+t.databaseId.database),"firestore/"+t.persistenceKey+"/"+e+"/"},pc.prototype.releasePrimaryLeaseIfHeld=function(t){var e=this,n=mc(t);return n.get(pu.key).next(function(t){return e.isLocalClient(t)?(Fr(sc,"Releasing primary lease."),n.delete(pu.key)):Uo.resolve()})},pc.prototype.isWithinAge=function(t,e){var n=Date.now();return!(t "+n),1))},pc.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)},pc.prototype.detachVisibilityHandler=function(){this.documentVisibilityHandler&&(Ur(null!==this.document&&"function"==typeof this.document.addEventListener,"Expected 'document.addEventListener' to be a function"),this.document.removeEventListener("visibilitychange",this.documentVisibilityHandler),this.documentVisibilityHandler=null)},pc.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))},pc.prototype.detachWindowUnloadHook=function(){this.windowUnloadHandler&&(Ur("function"==typeof this.window.removeEventListener,"Expected 'window.removeEventListener' to be a function"),this.window.removeEventListener("unload",this.windowUnloadHandler),this.windowUnloadHandler=null)},pc.prototype.isClientZombied=function(t){try{var e=null!==this.webStorage.getItem(this.zombiedClientLocalStorageKey(t));return Fr(sc,"Client '"+t+"' "+(e?"is":"is not")+" zombied in LocalStorage"),e}catch(t){return qr(sc,"Failed to get zombied client id.",t),!1}},pc.prototype.markClientZombied=function(){try{this.webStorage.setItem(this.zombiedClientLocalStorageKey(this.clientId),String(Date.now()))}catch(t){qr("Failed to set zombie client id.",t)}},pc.prototype.removeClientZombiedEntry=function(){try{this.webStorage.removeItem(this.zombiedClientLocalStorageKey(this.clientId))}catch(t){}},pc.prototype.zombiedClientLocalStorageKey=function(t){return"firestore_zombie_"+this.persistenceKey+"_"+t},pc.MAIN_DATABASE="main",pc);function pc(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 gc(this,i),this.dbName=e+pc.MAIN_DATABASE,this.serializer=new Gu(a),this.document=r.document,this.targetCache=new pa(this.referenceDelegate,this.serializer),this.indexManager=new Uu,this.remoteDocumentCache=new Zs(this.serializer,this.indexManager),!r.window||!r.window.localStorage)throw new zr(Gr.UNIMPLEMENTED,"IndexedDB persistence is only available on platforms that support LocalStorage.");this.window=r.window,this.webStorage=this.window.localStorage}function dc(e){return p(this,void 0,void 0,function(){return m(this,function(t){if(!function(t){return t.code===Gr.FAILED_PRECONDITION&&t.message===uc}(e))throw e;return Fr(sc,"Unexpectedly lost primary lease"),[2]})})}function mc(t){return t.store(pu.store)}function yc(t){return t.store(xu.store)}var gc=(vc.prototype.getSequenceNumberCount=function(t){var n=this.orphanedDocmentCount(t);return this.db.getTargetCache().getTargetCount(t).next(function(e){return n.next(function(t){return e+t})})},vc.prototype.orphanedDocmentCount=function(t){var e=0;return this.forEachOrphanedDocumentSequenceNumber(t,function(t){e++}).next(function(){return e})},vc.prototype.forEachTarget=function(t,e){return this.db.getTargetCache().forEachTarget(t,e)},vc.prototype.forEachOrphanedDocumentSequenceNumber=function(t,n){return this.forEachOrphanedDocument(t,function(t,e){return n(e)})},vc.prototype.setInMemoryPins=function(t){this.inMemoryPins=t},vc.prototype.addReference=function(t,e){return bc(t,e)},vc.prototype.removeReference=function(t,e){return bc(t,e)},vc.prototype.removeTargets=function(t,e,n){return this.db.getTargetCache().removeTargets(t,e,n)},vc.prototype.removeMutationReference=function(t,e){return bc(t,e)},vc.prototype.isPinned=function(t,e){return this.inMemoryPins.containsKey(e)?Uo.resolve(!0):function(e,n){var r=!1;return ua(e).iterateSerial(function(t){return ra(e,t,n).next(function(t){return t&&(r=!0),Uo.resolve(!t)})}).next(function(){return r})}(t,e)},vc.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),va(r).delete(function(t){return[0,oo(t.path)]}(e))})});s.push(n)}}).next(function(){return Uo.waitFor(s)}).next(function(){return a.apply(r)}).next(function(){return u})},vc.prototype.removeTarget=function(t,e){var n=e.withSequenceNumber(t.currentSequenceNumber);return this.db.getTargetCache().updateTargetData(t,n)},vc.prototype.updateLimboDocument=function(t,e){return bc(t,e)},vc.prototype.forEachOrphanedDocument=function(t,o){var a,e=va(t),s=Oi.INVALID;return e.iterate({index:ku.documentTargetsIndex},function(t,e){var n=t[0],r=(t[1],e.path),i=e.sequenceNumber;0===n?(s!==Oi.INVALID&&o(new Gi(uo(a)),s),s=i,a=r):s=Oi.INVALID}).next(function(){s!==Oi.INVALID&&o(new Gi(uo(a)),s)})},vc.prototype.getCacheSize=function(t){return this.db.getRemoteDocumentCache().getSize(t)},vc);function vc(t,e){this.db=t,this.inMemoryPins=null,this.garbageCollector=new nc(this,e)}function bc(t,e){return va(t).put(function(t,e){return new ku(0,oo(t.path),e)}(e,t.currentSequenceNumber))}var wc=Number,Tc=wc.MIN_SAFE_INTEGER||-(Math.pow(2,53)-1),Sc=wc.MAX_SAFE_INTEGER||Math.pow(2,53)-1,Ec=wc.isInteger||function(t){return"number"==typeof t&&isFinite(t)&&Math.floor(t)===t};function Ic(t){return null==t}function Cc(t){return Ec(t)&&t<=Sc&&Tc<=t}var Dc,Nc,Ac=(kc.prototype.canonicalId=function(){if(null===this.memoizedCanonicalId){var t=this.path.canonicalString();null!==this.collectionGroup&&(t+="|cg:"+this.collectionGroup),t+="|f:";for(var e=0,n=this.filters;e=":return Oc.GREATER_THAN_OR_EQUAL;case">":return Oc.GREATER_THAN;case"array-contains":return Oc.ARRAY_CONTAINS;case"in":return Oc.IN;case"array-contains-any":return Oc.ARRAY_CONTAINS_ANY;default:return Br("Unknown FieldFilter operator: "+t)}},Oc.prototype.toString=function(){return this.name},Oc.prototype.isEqual=function(t){return this.name===t.name},Oc.LESS_THAN=new Oc("<"),Oc.LESS_THAN_OR_EQUAL=new Oc("<="),Oc.EQUAL=new Oc("=="),Oc.GREATER_THAN=new Oc(">"),Oc.GREATER_THAN_OR_EQUAL=new Oc(">="),Oc.ARRAY_CONTAINS=new Oc("array-contains"),Oc.IN=new Oc("in"),Oc.ARRAY_CONTAINS_ANY=new Oc("array-contains-any"),Oc);function Oc(t){this.name=t}var Pc,xc=(t(Fc,Pc=_c),Fc.create=function(t,e,n){if(t.isKeyField())return e===Lc.IN?(Ur(n instanceof Os,"Comparing on key with IN, but filter value not an ArrayValue"),Ur(n.internalValue.every(function(t){return t instanceof Cs}),"Comparing on key with IN, but an array value was not a RefValue"),new Kc(t,n)):(Ur(n instanceof Cs,"Comparing on key, but filter value not a RefValue"),Ur(e!==Lc.ARRAY_CONTAINS&&e!==Lc.ARRAY_CONTAINS_ANY,"'"+e.toString()+"' queries don't make sense on document keys."),new Vc(t,e,n));if(n.isEqual(Xa.INSTANCE)){if(e!==Lc.EQUAL)throw new zr(Gr.INVALID_ARGUMENT,"Invalid query. Null supports only equality comparisons.");return new Fc(t,e,n)}if(n.isEqual(hs.NAN)){if(e!==Lc.EQUAL)throw new zr(Gr.INVALID_ARGUMENT,"Invalid query. NaN supports only equality comparisons.");return new Fc(t,e,n)}return e===Lc.ARRAY_CONTAINS?new jc(t,n):e===Lc.IN?(Ur(n instanceof Os,"IN filter has invalid value: "+n.toString()),new Hc(t,n)):e===Lc.ARRAY_CONTAINS_ANY?(Ur(n instanceof Os,"ARRAY_CONTAINS_ANY filter has invalid value: "+n.toString()),new Xc(t,n)):new Fc(t,e,n)},Fc.prototype.matches=function(t){var e=t.field(this.field);return null!==e&&this.value.typeOrder===e.typeOrder&&this.matchesComparison(e.compareTo(this.value))},Fc.prototype.matchesComparison=function(t){switch(this.op){case Lc.LESS_THAN:return t<0;case Lc.LESS_THAN_OR_EQUAL:return t<=0;case Lc.EQUAL:return 0===t;case Lc.GREATER_THAN:return 0=this.RESUME_TOKEN_MAX_AGE_MICROS||0i?this.mutationQueue[i]:null)},vh.prototype.getHighestUnacknowledgedBatchId=function(){return Uo.resolve(0===this.mutationQueue.length?-1:this.nextBatchId-1)},vh.prototype.getAllMutationBatches=function(t){return Uo.resolve(this.mutationQueue.slice())},vh.prototype.getAllMutationBatchesAffectingDocumentKey=function(t,n){var r=this,e=new ph(n,0),i=new ph(n,Number.POSITIVE_INFINITY),o=[];return this.batchesByDocumentKey.forEachInRange([e,i],function(t){Ur(n.isEqual(t.key),"Should only iterate over a single key's batches");var e=r.findMutationBatch(t.targetOrBatchId);Ur(null!==e,"Batches in the index must exist in the main table"),o.push(e)}),Uo.resolve(o)},vh.prototype.getAllMutationBatchesAffectingDocumentKeys=function(t,e){var r=this,i=new So(Si);return e.forEach(function(e){var t=new ph(e,0),n=new ph(e,Number.POSITIVE_INFINITY);r.batchesByDocumentKey.forEachInRange([t,n],function(t){Ur(e.isEqual(t.key),"For each key, should only iterate over a single key's batches"),i=i.add(t.targetOrBatchId)})}),Uo.resolve(this.findMutationBatches(i))},vh.prototype.getAllMutationBatchesAffectingQuery=function(t,e){Ur(!e.isCollectionGroupQuery(),"CollectionGroup queries should be handled in LocalDocumentsView");var n=e.path,r=n.length+1,i=n;Gi.isDocumentKey(i)||(i=i.child(""));var o=new ph(new Gi(i),0),a=new So(Si);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),Uo.resolve(this.findMutationBatches(a))},vh.prototype.findMutationBatches=function(t){var n=this,r=[];return t.forEach(function(t){var e=n.findMutationBatch(t);null!==e&&r.push(e)}),r},vh.prototype.removeMutationBatch=function(n,r){var i=this;Ur(0===this.indexOfExistingBatchId(r.batchId,"removed"),"Can only remove the first entry of the mutation queue"),this.mutationQueue.shift();var o=this.batchesByDocumentKey;return Uo.forEach(r.mutations,function(t){var e=new ph(t.key,r.batchId);return o=o.delete(e),i.referenceDelegate.removeMutationReference(n,t.key)}).next(function(){i.batchesByDocumentKey=o})},vh.prototype.removeCachedMutationKeys=function(t){},vh.prototype.containsKey=function(t,e){var n=new ph(e,0),r=this.batchesByDocumentKey.firstAfterOrEqual(n);return Uo.resolve(e.isEqual(r&&r.key))},vh.prototype.performConsistencyCheck=function(t){return 0===this.mutationQueue.length&&Ur(this.batchesByDocumentKey.isEmpty(),"Document leak -- detected dangling mutation references when queue is empty."),Uo.resolve()},vh.prototype.indexOfExistingBatchId=function(t,e){var n=this.indexOfBatchId(t);return Ur(0<=n&&n=this.mutationQueue.length)return null;var n=this.mutationQueue[e];return Ur(n.batchId===t,"If found batch must match"),n},vh);function vh(t,e){this.indexManager=t,this.referenceDelegate=e,this.mutationQueue=[],this.nextBatchId=1,this.lastStreamToken=Wr(),this.batchesByDocumentKey=new So(ph.compareByKey)}var bh,wh=(Th.prototype.addEntry=function(t,e,n){Ur(!n.isEqual(lo.MIN),"Cannot add a document with a read time of zero");var r=e.key,i=this.docs.get(r),o=i?i.size:0,a=this.sizer(e);return this.docs=this.docs.insert(r,{maybeDocument:e,size:a,readTime:n}),this.size+=a-o,this.indexManager.addToCollectionParentIndex(t,r.path.popLast())},Th.prototype.removeEntry=function(t){var e=this.docs.get(t);e&&(this.docs=this.docs.remove(t),this.size-=e.size)},Th.prototype.getEntry=function(t,e){var n=this.docs.get(e);return Uo.resolve(n?n.maybeDocument:null)},Th.prototype.getEntries=function(t,e){var n=this,r=Ao();return e.forEach(function(t){var e=n.docs.get(t);r=r.insert(t,e?e.maybeDocument:null)}),Uo.resolve(r)},Th.prototype.getDocumentsMatchingQuery=function(t,e,n){Ur(!e.isCollectionGroupQuery(),"CollectionGroup queries should be handled in LocalDocumentsView");for(var r=Ro(),i=new Gi(e.path.child("")),o=this.docs.getIteratorFrom(i);o.hasNext();){var a=o.getNext(),s=a.key,u=a.value,c=u.maybeDocument,h=u.readTime;if(!e.path.isPrefixOf(s.path))break;h.compareTo(n)<=0||c instanceof Vs&&e.matches(c)&&(r=r.insert(c.key,c))}return Uo.resolve(r)},Th.prototype.forEachDocumentKey=function(t,e){return Uo.forEach(this.docs,function(t){return e(t)})},Th.prototype.getNewDocumentChanges=function(t,e){throw new Error("getNewDocumentChanges() is not supported with MemoryPersistence")},Th.prototype.newChangeBuffer=function(t){return new Th.RemoteDocumentChangeBuffer(this)},Th.prototype.getSize=function(t){return Uo.resolve(this.size)},Th.RemoteDocumentChangeBuffer=(t(Sh,bh=Ys),Sh.prototype.applyChanges=function(n){var r=this,i=[];return this.changes.forEach(function(t,e){e?i.push(r.documentCache.addEntry(n,e,r.readTime)):r.documentCache.removeEntry(t)}),Uo.waitFor(i)},Sh.prototype.getFromCache=function(t,e){return this.documentCache.getEntry(t,e)},Sh.prototype.getAllFromCache=function(t,e){return this.documentCache.getEntries(t,e)},Sh),Th);function Th(t,e){this.indexManager=t,this.sizer=e,this.docs=new po(Gi.comparator),this.size=0}function Sh(t){var e=bh.call(this)||this;return e.documentCache=t,e}var Eh=(Ih.prototype.forEachTarget=function(t,n){return this.targets.forEach(function(t,e){return n(e)}),Uo.resolve()},Ih.prototype.getLastRemoteSnapshotVersion=function(t){return Uo.resolve(this.lastRemoteSnapshotVersion)},Ih.prototype.getHighestSequenceNumber=function(t){return Uo.resolve(this.highestSequenceNumber)},Ih.prototype.allocateTargetId=function(t){var e=this.targetIdGenerator.after(this.highestTargetId);return this.highestTargetId=e,Uo.resolve(e)},Ih.prototype.setTargetsMetadata=function(t,e,n){return n&&(this.lastRemoteSnapshotVersion=n),e>this.highestSequenceNumber&&(this.highestSequenceNumber=e),Uo.resolve()},Ih.prototype.saveTargetData=function(t){this.targets.set(t.target,t);var e=t.targetId;e>this.highestTargetId&&(this.highestTargetId=e),t.sequenceNumber>this.highestSequenceNumber&&(this.highestSequenceNumber=t.sequenceNumber)},Ih.prototype.addTargetData=function(t,e){return Ur(!this.targets.has(e.target),"Adding a target that already exists"),this.saveTargetData(e),this.targetCount+=1,Uo.resolve()},Ih.prototype.updateTargetData=function(t,e){return Ur(this.targets.has(e.target),"Updating a non-existent target"),this.saveTargetData(e),Uo.resolve()},Ih.prototype.removeTargetData=function(t,e){return Ur(0this.maxDelayMs&&(this.currentBaseMs=this.maxDelayMs)},Ph.prototype.cancel=function(){null!==this.timerPromise&&(this.timerPromise.cancel(),this.timerPromise=null)},Ph.prototype.jitterDelayMs=function(){return(Math.random()-.5)*this.currentBaseMs},Ph);function Ph(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 xh,Fh,qh="PersistentStream";(Fh=xh=xh||{})[Fh.Initial=0]="Initial",Fh[Fh.Starting=1]="Starting",Fh[Fh.Open=2]="Open",Fh[Fh.Error=3]="Error",Fh[Fh.Backoff=4]="Backoff";var Vh=(Bh.prototype.isStarted=function(){return this.state===xh.Starting||this.state===xh.Open||this.state===xh.Backoff},Bh.prototype.isOpen=function(){return this.state===xh.Open},Bh.prototype.start=function(){this.state!==xh.Error?(Ur(this.state===xh.Initial,"Already started"),this.auth()):this.performBackoff()},Bh.prototype.stop=function(){return p(this,void 0,void 0,function(){return m(this,function(t){switch(t.label){case 0:return this.isStarted()?[4,this.close(xh.Initial)]:[3,2];case 1:t.sent(),t.label=2;case 2:return[2]}})})},Bh.prototype.inhibitBackoff=function(){Ur(!this.isStarted(),"Can only inhibit backoff in a stopped state"),this.state=xh.Initial,this.backoff.reset()},Bh.prototype.markIdle=function(){var t=this;this.isOpen()&&null===this.idleTimer&&(this.idleTimer=this.queue.enqueueAfterDelay(this.idleTimerId,6e4,function(){return t.handleIdleCloseTimer()}))},Bh.prototype.sendRequest=function(t){this.cancelIdleCheck(),this.stream.send(t)},Bh.prototype.handleIdleCloseTimer=function(){return p(this,void 0,void 0,function(){return m(this,function(t){return this.isOpen()?[2,this.close(xh.Initial)]:[2]})})},Bh.prototype.cancelIdleCheck=function(){this.idleTimer&&(this.idleTimer.cancel(),this.idleTimer=null)},Bh.prototype.close=function(e,n){return p(this,void 0,void 0,function(){return m(this,function(t){switch(t.label){case 0:return Ur(this.isStarted(),"Only started streams should be closed."),Ur(e===xh.Error||Ic(n),"Can't provide an error when not in an error state."),this.cancelIdleCheck(),this.backoff.cancel(),this.closeCount++,e!==xh.Error?this.backoff.reset():n&&n.code===Gr.RESOURCE_EXHAUSTED?(qr(n.toString()),qr("Using maximum backoff delay to prevent overloading the backend."),this.backoff.resetToMax()):n&&n.code===Gr.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]}})})},Bh.prototype.tearDown=function(){},Bh.prototype.auth=function(){var n=this;Ur(this.state===xh.Initial,"Must be in initial state to auth"),this.state=xh.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 zr(Gr.UNKNOWN,"Fetching auth token failed: "+e.message);return n.handleStreamClose(t)})})},Bh.prototype.startStream=function(t){var e=this;Ur(this.state===xh.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 Ur(e.state===xh.Starting,"Expected stream to be in state Starting, but was "+e.state),e.state=xh.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)})})},Bh.prototype.performBackoff=function(){var t=this;Ur(this.state===xh.Error,"Should only perform backoff when in Error state"),this.state=xh.Backoff,this.backoff.backoffAndRun(function(){return p(t,void 0,void 0,function(){return m(this,function(t){return Ur(this.state===xh.Backoff,"Backoff elapsed but state is now: "+this.state),this.state=xh.Initial,this.start(),Ur(this.isStarted(),"PersistentStream should have started"),[2]})})})},Bh.prototype.handleStreamClose=function(t){return Ur(this.isStarted(),"Can't handle server close on non-started stream"),Fr(qh,"close with error: "+t),this.stream=null,this.close(xh.Error,t)},Bh.prototype.getCloseGuardedDispatcher=function(e){var n=this;return function(t){n.queue.enqueueAndForget(function(){return n.closeCount===e?t():(Fr(qh,"stream callback skipped by getCloseGuardedDispatcher."),Promise.resolve())})}},Bh);function Bh(t,e,n,r,i,o){this.queue=t,this.idleTimerId=n,this.connection=r,this.credentialsProvider=i,this.listener=o,this.state=xh.Initial,this.closeCount=0,this.idleTimer=null,this.stream=null,this.backoff=new Oh(t,e)}var Uh,Kh=(t(Qh,Uh=Vh),Qh.prototype.startRpc=function(t){return this.connection.openStream("Listen",t)},Qh.prototype.onMessage=function(t){this.backoff.reset();var e=this.serializer.fromWatchChange(t),n=this.serializer.versionFromListenResponse(t);return this.listener.onWatchChange(e,n)},Qh.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)},Qh.prototype.unwatch=function(t){var e={};e.database=this.serializer.encodedDatabaseId,e.removeTarget=t,this.sendRequest(e)},Qh);function Qh(t,e,n,r,i){var o=Uh.call(this,t,Hi.ListenStreamConnectionBackoff,Hi.ListenStreamIdle,e,n,i)||this;return o.serializer=r,o}var Wh,jh=(t(Gh,Wh=Vh),Object.defineProperty(Gh.prototype,"handshakeComplete",{get:function(){return this.handshakeComplete_},enumerable:!0,configurable:!0}),Gh.prototype.start=function(){this.handshakeComplete_=!1,Wh.prototype.start.call(this)},Gh.prototype.tearDown=function(){this.handshakeComplete_&&this.writeMutations([])},Gh.prototype.startRpc=function(t){return this.connection.openStream("Write",t)},Gh.prototype.onMessage=function(t){if(Ur(!!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 Ur(!t.writeResults||0===t.writeResults.length,"Got mutation results for handshake"),this.handshakeComplete_=!0,this.listener.onHandshakeComplete()},Gh.prototype.writeHandshake=function(){Ur(this.isOpen(),"Writing handshake requires an opened stream"),Ur(!this.handshakeComplete_,"Handshake already completed");var t={};t.database=this.serializer.encodedDatabaseId,this.sendRequest(t)},Gh.prototype.writeMutations=function(t){var e=this;Ur(this.isOpen(),"Writing mutations requires an opened stream"),Ur(this.handshakeComplete_,"Handshake must be complete before writing mutations"),Ur(0() instead."),Np=/^__.*__$/,Ap=(kp.prototype.toMutations=function(t,e){var n=[];return null!==this.fieldMask?n.push(new Oa(t,this.data,this.fieldMask,e)):n.push(new Ma(t,this.data,e)),0=",">","array-contains","in","array-contains-any"],2,e);var i=Kp("Query.where",t),o=Lc.fromString(e);if(i.isKeyField()){if(o===Lc.ARRAY_CONTAINS||o===Lc.ARRAY_CONTAINS_ANY)throw new zr(Gr.INVALID_ARGUMENT,"Invalid Query. You can't perform '"+o.toString()+"' queries on FieldPath.documentId().");if(o===Lc.IN){this.validateDisjunctiveFilterElements(n,o);for(var a=[],s=0,u=n;sr.length)throw new zr(Gr.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 zr(Gr.INVALID_ARGUMENT,"Invalid query. You cannot use more than one '"+t.op.toString()+"' filter."):new zr(Gr.INVALID_ARGUMENT,"Invalid query. You cannot use '"+t.op.toString()+"' filters with '"+s.toString()+"' filters.")}}},hd.prototype.validateNewOrderBy=function(t){if(null===this._query.getFirstOrderByField()){var e=this._query.getInequalityFilterField();null!==e&&this.validateOrderByAndInequalityMatch(e,t.field)}},hd.prototype.validateOrderByAndInequalityMatch=function(t,e){if(!e.isEqual(t))throw new zr(Gr.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.")},hd);function hd(t,e,n){this._query=t,this.firestore=e,this._converter=n}var ld=(Object.defineProperty(fd.prototype,"docs",{get:function(){var e=[];return this.forEach(function(t){return e.push(t)}),e},enumerable:!0,configurable:!0}),Object.defineProperty(fd.prototype,"empty",{get:function(){return this._snapshot.docs.isEmpty()},enumerable:!0,configurable:!0}),Object.defineProperty(fd.prototype,"size",{get:function(){return this._snapshot.docs.size},enumerable:!0,configurable:!0}),fd.prototype.forEach=function(e,n){var r=this;ii("QuerySnapshot.forEach",arguments,1,2),oi("QuerySnapshot.forEach","function",1,e),this._snapshot.docs.forEach(function(t){e.call(n,r.convertToDocumentImpl(t))})},Object.defineProperty(fd.prototype,"query",{get:function(){return new cd(this._originalQuery,this._firestore,this._converter)},enumerable:!0,configurable:!0}),fd.prototype.docChanges=function(t){t&&(mi("QuerySnapshot.docChanges",t,["includeMetadataChanges"]),ui("QuerySnapshot.docChanges","boolean","includeMetadataChanges",t.includeMetadataChanges));var e=!(!t||!t.includeMetadataChanges);if(e&&this._snapshot.excludesMetadataChanges)throw new zr(Gr.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,a){if(o.oldDocs.isEmpty()){var n,r=0;return o.docChanges.map(function(t){var e=new sd(i,t.doc.key,t.doc,o.fromCache,o.mutatedKeys.has(t.doc.key),a);return Ur(t.type===sl.Added,"Invalid event type for first snapshot"),Ur(!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 s=o.oldDocs;return o.docChanges.filter(function(t){return e||t.type!==sl.Metadata}).map(function(t){var e=new sd(i,t.doc.key,t.doc,o.fromCache,o.mutatedKeys.has(t.doc.key),a),n=-1,r=-1;return t.type!==sl.Added&&(Ur(0<=(n=s.indexOf(t.doc.key)),"Index for document not found"),s=s.delete(t.doc.key)),t.type!==sl.Removed&&(r=(s=s.add(t.doc)).indexOf(t.doc.key)),{type:function(t){switch(t){case sl.Added:return"added";case sl.Modified:case sl.Metadata:return"modified";case sl.Removed:return"removed";default:return Br("Unknown change type: "+t)}}(t.type),doc:e,oldIndex:n,newIndex:r}})}(this._firestore,e,this._snapshot,this._converter),this._cachedChangesIncludeMetadataChanges=e),this._cachedChanges},fd.prototype.isEqual=function(t){if(!(t instanceof fd))throw yi("isEqual","QuerySnapshot",1,t);return this._firestore===t._firestore&&this._originalQuery.isEqual(t._originalQuery)&&this._snapshot.isEqual(t._snapshot)&&this._converter===t._converter},fd.prototype.convertToDocumentImpl=function(t){return new sd(this._firestore,t.key,t,this.metadata.fromCache,this._snapshot.mutatedKeys.has(t.key),this._converter)},fd);function fd(t,e,n,r){this._firestore=t,this._originalQuery=e,this._snapshot=n,this._converter=r,this._cachedChanges=null,this._cachedChangesIncludeMetadataChanges=null,this.metadata=new nd(n.hasPendingWrites,n.fromCache)}a(["length","forEach","map"],"undefined"!=typeof Symbol?[Symbol.iterator]:[]).forEach(function(t){try{Object.defineProperty(ld.prototype.docChanges,t,{get:function(){return function(){throw new zr(Gr.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 pd,dd=(t(md,pd=cd),Object.defineProperty(md.prototype,"id",{get:function(){return this._query.path.lastSegment()},enumerable:!0,configurable:!0}),Object.defineProperty(md.prototype,"parent",{get:function(){var t=this._query.path.popLast();return t.isEmpty()?null:new td(new Gi(t),this.firestore)},enumerable:!0,configurable:!0}),Object.defineProperty(md.prototype,"path",{get:function(){return this._query.path.canonicalString()},enumerable:!0,configurable:!0}),md.prototype.doc=function(t){if(ii("CollectionReference.doc",arguments,0,1),0===arguments.length&&(t=wi.newId()),oi("CollectionReference.doc","non-empty string",1,t),""===t)throw new zr(Gr.INVALID_ARGUMENT,"Document path must be a non-empty string");var e=Bi.fromString(t);return td.forPath(this._query.path.child(e),this.firestore,this._converter)},md.prototype.add=function(t){ni("CollectionReference.add",arguments,1),oi("CollectionReference.add","object",1,t);var e=this.doc();return e.set(t).then(function(){return e})},md.prototype.withConverter=function(t){return new md(this._path,this.firestore,t)},md);function md(t,e,n){var r=pd.call(this,Rc.atPath(t),e,n)||this;if((r._path=t).length%2!=1)throw new zr(Gr.INVALID_ARGUMENT,"Invalid collection reference. Collection references must have an odd number of segments, but "+t.canonicalString()+" has "+t.length);return r}function yd(t,e){if(void 0===e)return{merge:!1};if(mi(t,e,["merge","mergeFields"]),ui(t,"boolean","merge",e.merge),ci(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 zr(Gr.INVALID_ARGUMENT,"Invalid options passed to function "+t+'(): You cannot specify both "merge" and "mergeFields".');return e}function gd(t,e){return void 0===e?{}:(mi(t,e,["serverTimestamps"]),hi(t,0,"serverTimestamps",e.serverTimestamps,["estimate","previous","none"]),e)}function vd(t,e){ai(t,"object",1,e),e&&(mi(t,e,["source"]),hi(t,0,"source",e.source,["default","server","cache"]))}function bd(t,e,n){if(e instanceof td){if(e.firestore!==n)throw new zr(Gr.INVALID_ARGUMENT,"Provided document reference is from a different Firestore instance.");return e}throw yi(t,"DocumentReference",1,e)}function wd(t,e,n){var r;return t?(r=t.toFirestore(e),n="toFirestore() in "+n):r=e,[r,n]}var Td=Yr(Hp,"Use firebase.firestore() instead."),Sd=Yr(Jp,"Use firebase.firestore().runTransaction() instead."),Ed=Yr(Zp,"Use firebase.firestore().batch() instead."),Id=Yr(td,"Use firebase.firestore().doc() instead."),Cd=Yr(id),Dd=Yr(sd),Nd=Yr(cd),Ad=Yr(ld),kd=Yr(dd,"Use firebase.firestore().collection() instead."),Rd={Firestore:Td,GeoPoint:Pl,Timestamp:co,Blob:ki,Transaction:Sd,WriteBatch:Ed,DocumentReference:Id,DocumentSnapshot:Cd,Query:Nd,QueryDocumentSnapshot:Dd,QuerySnapshot:Ad,CollectionReference:kd,FieldPath:Jf,FieldValue:Dp,setLogLevel:Hp.setLogLevel,CACHE_SIZE_UNLIMITED:jp};function Md(t){t.INTERNAL.registerComponent(new w("firestore",function(t){var e=t.getProvider("app").getImmediate();return new Hp(e,t.getProvider("auth-internal"))},"PUBLIC").setServiceProps(function(t){Ur(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}(Rd)))}var _d=(Ld.prototype.addCallback=function(t){},Ld.prototype.shutdown=function(){},Ld);function Ld(){}var Od="ConnectivityMonitor",Pd=(xd.prototype.addCallback=function(t){this.callbacks.push(t)},xd.prototype.shutdown=function(){window.removeEventListener("online",this.networkAvailableListener),window.removeEventListener("offline",this.networkUnavailableListener)},xd.prototype.configureNetworkMonitoring=function(){window.addEventListener("online",this.networkAvailableListener),window.addEventListener("offline",this.networkUnavailableListener)},xd.prototype.onNetworkAvailable=function(){Fr(Od,"Network connectivity changed: AVAILABLE");for(var t=0,e=this.callbacks;t