!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(nm){"use strict";try{(function(){nm=nm&&nm.hasOwnProperty("default")?nm.default:nm;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 jt(e){return"function"==R(e)?e:(e[Qt]||(e[Qt]=function(t){return e.handleEvent(t)}),e[Qt])}function Gt(){K.call(this),this.c=new Mt(this),(this.J=this).B=null}function Wt(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 je(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 Ge(t,e){try{t.g.Fa(t,e),ye(4)}catch(t){}}function We(t,e){if(t.forEach&&"function"==typeof t.forEach)t.forEach(e,void 0);else if(_(t)||D(t))j(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(X(i,"./")||X(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),Xe(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=Xe(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 W(t.c);var e=t.c;return j(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{We(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&&(j(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){Gt.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=jn,this.D=this.F=!1}U(Qn,Gt);var jn="",Gn=/^https?$/i,Wn=["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),Jn(t)}function Yn(t){t.v||(t.v=!0,t.dispatchEvent("complete"),t.dispatchEvent("error"))}function Xn(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(Je)[1]||null;if(!o&&C.self&&C.self.location){var a=C.self.location.protocol;o=a.substr(0,a.length-1)}i=!Gn.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{Jn(t)}}}function Jn(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(Wr.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(Wr.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(Wr.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)))},Jo.prototype.add=function(t){return Fr(Qo,"ADD",this.store.name,t,t),Zo(this.store.add(t))},Jo.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})},Jo.prototype.delete=function(t){return Fr(Qo,"DELETE",this.store.name,t),Zo(this.store.delete(t))},Jo.prototype.count=function(){return Fr(Qo,"COUNT",this.store.name),Zo(this.store.count())},Jo.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})},Jo.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()})},Jo.prototype.iterate=function(t,e){var n;e?n=t:(n={},e=t);var r=this.cursor(n);return this.iterateCursor(r,e)},Jo.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()}})},Jo.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 Wo(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)})},Jo.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}},Jo.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)},Jo);function Jo(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=jo.getIOSVersion(f());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:wu.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:wu.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(wu.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=Su.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=Su.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=Su.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(Su.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 vu(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=Su.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(wu.store),i=t.store(Su.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:Ru.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 _u(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 Wi(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:_u.documentTargetsIndex,keysOnly:!0,range:r},function(t,e,n){var r=t[0];t[1],0!==r&&(i++,n.done())}).next(function(){return 0"},Es.prototype.approximateByteSize=function(){return 16+(this.previousValue?this.previousValue.approximateByteSize():0)},Es);function Es(t,e){var n=Ts.call(this)||this;return n.localWriteTime=t,n.previousValue=e,n.typeOrder=Qa.TimestampValue,n}var Is,Cs=(t(Ds,Is=Ja),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.prototype.approximateByteSize=function(){return this.internalValue._approximateByteSize()},Ds);function Ds(t){var e=Is.call(this)||this;return e.internalValue=t,e.typeOrder=Qa.BlobValue,e}var Ns,As=(t(ks,Ns=Ja),ks.prototype.value=function(t){return this.key},ks.prototype.isEqual=function(t){return t instanceof ks&&this.key.isEqual(t.key)&&this.databaseId.isEqual(t.databaseId)},ks.prototype.compareTo=function(t){if(t instanceof ks){var e=this.databaseId.compareTo(t.databaseId);return 0!==e?e:Wi.comparator(this.key,t.key)}return this.defaultCompareTo(t)},ks.prototype.approximateByteSize=function(){return this.databaseId.projectId.length+this.databaseId.database.length+this.key.toString().length},ks);function ks(t,e){var n=Ns.call(this)||this;return n.databaseId=t,n.key=e,n.typeOrder=Qa.RefValue,n}var Rs,Ms=(t(_s,Rs=Ja),_s.prototype.value=function(t){return this.internalValue},_s.prototype.isEqual=function(t){return t instanceof _s&&this.internalValue.isEqual(t.internalValue)},_s.prototype.compareTo=function(t){return t instanceof _s?this.internalValue._compareTo(t.internalValue):this.defaultCompareTo(t)},_s.prototype.approximateByteSize=function(){return 16},_s);function _s(t){var e=Rs.call(this)||this;return e.internalValue=t,e.typeOrder=Qa.GeoPointValue,e}var Ls,Os=(t(Ps,Ls=Ja),Ps.prototype.value=function(n){var r={};return this.internalValue.inorderTraversal(function(t,e){r[t]=e.value(n)}),r},Ps.prototype.forEach=function(t){this.internalValue.inorderTraversal(t)},Ps.prototype.isEqual=function(t){if(t instanceof Ps){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},Ps.prototype.compareTo=function(t){if(t instanceof Ps){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)},Ps.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 Ps||(n=Ps.EMPTY);var r=n.set(t.popFirst(),e);return this.setChild(t.firstSegment(),r)},Ps.prototype.delete=function(t){if(Ur(!t.isEmpty(),"Cannot delete field for empty path on ObjectValue"),1===t.length)return new Ps(this.internalValue.remove(t.firstSegment()));var e=this.child(t.firstSegment());if(e instanceof Ps){var n=e.delete(t.popFirst());return new Ps(this.internalValue.insert(t.firstSegment(),n))}return this},Ps.prototype.contains=function(t){return null!==this.field(t)},Ps.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 Ps?e.internalValue.get(t):null}),e},Ps.prototype.fieldMask=function(){var i=new So(ji.comparator);return this.internalValue.forEach(function(t,e){var n=new ji([t]);if(e instanceof Ps){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)},Ps.prototype.approximateByteSize=function(){var n=0;return this.internalValue.inorderTraversal(function(t,e){n+=t.length+e.approximateByteSize()}),n},Ps.prototype.toString=function(){return this.internalValue.toString()},Ps.prototype.child=function(t){return this.internalValue.get(t)||void 0},Ps.prototype.setChild=function(t,e){return new Ps(this.internalValue.insert(t,e))},Ps.EMPTY=new Ps(new po(Si)),Ps);function Ps(t){var e=Ls.call(this)||this;return e.internalValue=t,e.typeOrder=Qa.ObjectValue,e}var xs,Fs=(t(qs,xs=Ja),qs.prototype.value=function(e){return this.internalValue.map(function(t){return t.value(e)})},qs.prototype.contains=function(t){for(var e=0,n=this.internalValue;e=this.RESUME_TOKEN_MAX_AGE_MICROS||0h.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})})},bc);function bc(t,e){this.delegate=t,this.params=e}var wc,Tc="IndexedDbPersistence",Sc="Another tab has exclusive access to the persistence layer. To allow shared access, make sure to invoke `enablePersistence()` with `synchronizeTabs:true` in all tabs.",Ec=(t(Ic,wc=tc),Ic);function Ic(t,e){var n=wc.call(this)||this;return n.simpleDbTransaction=t,n.currentSequenceNumber=e,n}var Cc=(Dc.getStore=function(t,e){if(t instanceof Ec)return jo.getStore(t.simpleDbTransaction,e);throw Br("IndexedDbPersistence must use instances of IndexedDbTransaction")},Dc.createIndexedDbPersistence=function(n){return p(this,void 0,void 0,function(){var e;return m(this,function(t){switch(t.label){case 0:if(!Dc.isAvailable())throw new zr(Wr.UNIMPLEMENTED,"This platform is either missing IndexedDB or is known to have an incomplete implementation. Offline persistence has been disabled.");return[4,(e=new Dc(n.allowTabSynchronization,n.persistenceKey,n.clientId,n.platform,n.lruParams,n.queue,n.serializer,n.sequenceNumberSyncer)).start()];case 1:return t.sent(),[2,e]}})})},Dc.prototype.start=function(){var e=this;return Ur(!this.started,"IndexedDbPersistence double-started!"),Ur(null!==this.window,"Expected 'window' to be defined"),jo.openOrCreate(this.dbName,fu,new pu(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",[Ou.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)})},Dc.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)},Dc.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]}})})})},Dc.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]}})})}))},Dc.prototype.updateClientMetadataAndTryBecomePrimary=function(){var n=this;return this.simpleDb.runTransaction("readwrite-idempotent",Qu,function(e){return Ac(e).put(new Vu(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(Tc,"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})},Dc.prototype.verifyPrimaryLease=function(t){var e=this;return Nc(t).get(yu.key).next(function(t){return Uo.resolve(e.isLocalClient(t))})},Dc.prototype.removeClientMetadata=function(t){return Ac(t).delete(this.clientId)},Dc.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=Dc.getStore(t,Vu.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]}})})},Dc.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()})})},Dc.prototype.isLocalClient=function(t){return!!t&&t.ownerId===this.clientId},Dc.prototype.canActAsPrimary=function(e){var i=this;return Nc(e).get(yu.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(Wr.FAILED_PRECONDITION,Sc);return!1}}return!(!i.networkEnabled||!i.inForeground)||Ac(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(Tc,"Client "+(t?"is":"is not")+" eligible for a primary lease."),t})},Dc.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",[yu.store,Vu.store],function(t){return e.releasePrimaryLeaseIfHeld(t).next(function(){return e.removeClientMetadata(t)})})];case 1:return t.sent(),this.simpleDb.close(),this.removeClientZombiedEntry(),[2]}})})},Dc.prototype.filterActiveClients=function(t,e){var n=this;return t.filter(function(t){return n.isWithinAge(t.updateTimeMs,e)&&!n.isClientZombied(t.clientId)})},Dc.prototype.getActiveClients=function(){var e=this;return this.simpleDb.runTransaction("readonly-idempotent",[Vu.store],function(t){return Ac(t).loadAll().next(function(t){return e.filterActiveClients(t,18e5).map(function(t){return t.clientId})})})},Dc.clearPersistence=function(n){return p(this,void 0,void 0,function(){var e;return m(this,function(t){switch(t.label){case 0:return Dc.isAvailable()?(e=n+Dc.MAIN_DATABASE,[4,jo.delete(e)]):[2,Promise.resolve()];case 1:return t.sent(),[2]}})})},Object.defineProperty(Dc.prototype,"started",{get:function(){return this._started},enumerable:!0,configurable:!0}),Dc.prototype.getMutationQueue=function(t){return Ur(this.started,"Cannot initialize MutationQueue before persistence is started."),ea.forUser(t,this.serializer,this.indexManager,this.referenceDelegate)},Dc.prototype.getTargetCache=function(){return Ur(this.started,"Cannot initialize TargetCache before persistence is started."),this.targetCache},Dc.prototype.getRemoteDocumentCache=function(){return Ur(this.started,"Cannot initialize RemoteDocumentCache before persistence is started."),this.remoteDocumentCache},Dc.prototype.getIndexManager=function(){return Ur(this.started,"Cannot initialize IndexManager before persistence is started."),this.indexManager},Dc.prototype.runTransaction=function(n,t,r){var i=this;Fr(Tc,"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 Ec(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(Wr.FAILED_PRECONDITION,$u);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})},Dc.prototype.verifyAllowTabSynchronization=function(t){var e=this;return Nc(t).get(yu.key).next(function(t){if(null!==t&&e.isWithinAge(t.leaseTimestampMs,5e3)&&!e.isClientZombied(t.ownerId)&&!e.isLocalClient(t)&&!t.allowTabSynchronization)throw new zr(Wr.FAILED_PRECONDITION,Sc)})},Dc.prototype.acquireOrExtendPrimaryLease=function(t){var e=new yu(this.clientId,this.allowTabSynchronization,Date.now());return Nc(t).put(yu.key,e)},Dc.isAvailable=function(){return jo.isAvailable()},Dc.buildStoragePrefix=function(t){var e=t.databaseId.projectId;return t.databaseId.isDefaultDatabase||(e+="."+t.databaseId.database),"firestore/"+t.persistenceKey+"/"+e+"/"},Dc.prototype.releasePrimaryLeaseIfHeld=function(t){var e=this,n=Nc(t);return n.get(yu.key).next(function(t){return e.isLocalClient(t)?(Fr(Tc,"Releasing primary lease."),n.delete(yu.key)):Uo.resolve()})},Dc.prototype.isWithinAge=function(t,e){var n=Date.now();return!(t "+n),1))},Dc.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)},Dc.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)},Dc.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))},Dc.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)},Dc.prototype.isClientZombied=function(t){try{var e=null!==this.webStorage.getItem(this.zombiedClientLocalStorageKey(t));return Fr(Tc,"Client '"+t+"' "+(e?"is":"is not")+" zombied in LocalStorage"),e}catch(t){return qr(Tc,"Failed to get zombied client id.",t),!1}},Dc.prototype.markClientZombied=function(){try{this.webStorage.setItem(this.zombiedClientLocalStorageKey(this.clientId),String(Date.now()))}catch(t){qr("Failed to set zombie client id.",t)}},Dc.prototype.removeClientZombiedEntry=function(){try{this.webStorage.removeItem(this.zombiedClientLocalStorageKey(this.clientId))}catch(t){}},Dc.prototype.zombiedClientLocalStorageKey=function(t){return"firestore_zombie_"+this.persistenceKey+"_"+t},Dc.MAIN_DATABASE="main",Dc);function Dc(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 kc(this,i),this.dbName=e+Dc.MAIN_DATABASE,this.serializer=new Yu(a),this.document=r.document,this.targetCache=new pa(this.referenceDelegate,this.serializer),this.indexManager=new ju,this.remoteDocumentCache=new eu(this.serializer,this.indexManager),!r.window||!r.window.localStorage)throw new zr(Wr.UNIMPLEMENTED,"IndexedDB persistence is only available on platforms that support LocalStorage.");this.window=r.window,this.webStorage=this.window.localStorage}function Nc(t){return t.store(yu.store)}function Ac(t){return t.store(Vu.store)}var kc=(Rc.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})})},Rc.prototype.orphanedDocmentCount=function(t){var e=0;return this.forEachOrphanedDocumentSequenceNumber(t,function(t){e++}).next(function(){return e})},Rc.prototype.forEachTarget=function(t,e){return this.db.getTargetCache().forEachTarget(t,e)},Rc.prototype.forEachOrphanedDocumentSequenceNumber=function(t,n){return this.forEachOrphanedDocument(t,function(t,e){return n(e)})},Rc.prototype.setInMemoryPins=function(t){this.inMemoryPins=t},Rc.prototype.addReference=function(t,e){return Mc(t,e)},Rc.prototype.removeReference=function(t,e){return Mc(t,e)},Rc.prototype.removeTargets=function(t,e,n){return this.db.getTargetCache().removeTargets(t,e,n)},Rc.prototype.removeMutationReference=function(t,e){return Mc(t,e)},Rc.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)},Rc.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})},Rc.prototype.removeTarget=function(t,e){var n=e.withSequenceNumber(t.currentSequenceNumber);return this.db.getTargetCache().updateTargetData(t,n)},Rc.prototype.updateLimboDocument=function(t,e){return Mc(t,e)},Rc.prototype.forEachOrphanedDocument=function(t,o){var a,e=va(t),s=Oi.INVALID;return e.iterate({index:_u.documentTargetsIndex},function(t,e){var n=t[0],r=(t[1],e.path),i=e.sequenceNumber;0===n?(s!==Oi.INVALID&&o(new Wi(uo(a)),s),s=i,a=r):s=Oi.INVALID}).next(function(){s!==Oi.INVALID&&o(new Wi(uo(a)),s)})},Rc.prototype.getCacheSize=function(t){return this.db.getRemoteDocumentCache().getSize(t)},Rc);function Rc(t,e){this.db=t,this.inMemoryPins=null,this.garbageCollector=new vc(this,e)}function Mc(t,e){return va(t).put(function(t,e){return new _u(0,oo(t.path),e)}(e,t.currentSequenceNumber))}var _c=Number,Lc=_c.MIN_SAFE_INTEGER||-(Math.pow(2,53)-1),Oc=_c.MAX_SAFE_INTEGER||Math.pow(2,53)-1,Pc=_c.isInteger||function(t){return"number"==typeof t&&isFinite(t)&&Math.floor(t)===t};function xc(t){return null==t}function Fc(t){return Pc(t)&&t<=Oc&&Lc<=t}var qc,Vc,Bc=(Uc.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 Wc.GREATER_THAN_OR_EQUAL;case">":return Wc.GREATER_THAN;case"array-contains":return Wc.ARRAY_CONTAINS;case"in":return Wc.IN;case"array-contains-any":return Wc.ARRAY_CONTAINS_ANY;default:return Br("Unknown FieldFilter operator: "+t)}},Wc.prototype.toString=function(){return this.name},Wc.prototype.isEqual=function(t){return this.name===t.name},Wc.LESS_THAN=new Wc("<"),Wc.LESS_THAN_OR_EQUAL=new Wc("<="),Wc.EQUAL=new Wc("=="),Wc.GREATER_THAN=new Wc(">"),Wc.GREATER_THAN_OR_EQUAL=new Wc(">="),Wc.ARRAY_CONTAINS=new Wc("array-contains"),Wc.IN=new Wc("in"),Wc.ARRAY_CONTAINS_ANY=new Wc("array-contains-any"),Wc);function Wc(t){this.name=t}var zc,Hc=(t(Yc,zc=jc),Yc.create=function(t,e,n){if(t.isKeyField())return e===Gc.IN?(Ur(n instanceof Fs,"Comparing on key with IN, but filter value not an ArrayValue"),Ur(n.internalValue.every(function(t){return t instanceof As}),"Comparing on key with IN, but an array value was not a RefValue"),new th(t,n)):(Ur(n instanceof As,"Comparing on key, but filter value not a RefValue"),Ur(e!==Gc.ARRAY_CONTAINS&&e!==Gc.ARRAY_CONTAINS_ANY,"'"+e.toString()+"' queries don't make sense on document keys."),new Jc(t,e,n));if(n.isEqual(ts.INSTANCE)){if(e!==Gc.EQUAL)throw new zr(Wr.INVALID_ARGUMENT,"Invalid query. Null supports only equality comparisons.");return new Yc(t,e,n)}if(n.isEqual(ps.NAN)){if(e!==Gc.EQUAL)throw new zr(Wr.INVALID_ARGUMENT,"Invalid query. NaN supports only equality comparisons.");return new Yc(t,e,n)}return e===Gc.ARRAY_CONTAINS?new rh(t,n):e===Gc.IN?(Ur(n instanceof Fs,"IN filter has invalid value: "+n.toString()),new ah(t,n)):e===Gc.ARRAY_CONTAINS_ANY?(Ur(n instanceof Fs,"ARRAY_CONTAINS_ANY filter has invalid value: "+n.toString()),new ch(t,n)):new Yc(t,e,n)},Yc.prototype.matches=function(t){var e=t.field(this.field);return null!==e&&this.value.typeOrder===e.typeOrder&&this.matchesComparison(e.compareTo(this.value))},Yc.prototype.matchesComparison=function(t){switch(this.op){case Gc.LESS_THAN:return t<0;case Gc.LESS_THAN_OR_EQUAL:return t<=0;case Gc.EQUAL:return 0===t;case Gc.GREATER_THAN:return 0i?this.mutationQueue[i]:null)},Sh.prototype.getHighestUnacknowledgedBatchId=function(){return Uo.resolve(0===this.mutationQueue.length?-1:this.nextBatchId-1)},Sh.prototype.getAllMutationBatches=function(t){return Uo.resolve(this.mutationQueue.slice())},Sh.prototype.getAllMutationBatchesAffectingDocumentKey=function(t,n){var r=this,e=new ic(n,0),i=new ic(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)},Sh.prototype.getAllMutationBatchesAffectingDocumentKeys=function(t,e){var r=this,i=new So(Si);return e.forEach(function(e){var t=new ic(e,0),n=new ic(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))},Sh.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;Wi.isDocumentKey(i)||(i=i.child(""));var o=new ic(new Wi(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))},Sh.prototype.findMutationBatches=function(t){var n=this,r=[];return t.forEach(function(t){var e=n.findMutationBatch(t);null!==e&&r.push(e)}),r},Sh.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 ic(t.key,r.batchId);return o=o.delete(e),i.referenceDelegate.removeMutationReference(n,t.key)}).next(function(){i.batchesByDocumentKey=o})},Sh.prototype.removeCachedMutationKeys=function(t){},Sh.prototype.containsKey=function(t,e){var n=new ic(e,0),r=this.batchesByDocumentKey.firstAfterOrEqual(n);return Uo.resolve(e.isEqual(r&&r.key))},Sh.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()},Sh.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},Sh);function Sh(t,e){this.indexManager=t,this.referenceDelegate=e,this.mutationQueue=[],this.nextBatchId=1,this.lastStreamToken=jr(),this.batchesByDocumentKey=new So(ic.compareByKey)}var Eh,Ih=(Ch.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())},Ch.prototype.removeEntry=function(t){var e=this.docs.get(t);e&&(this.docs=this.docs.remove(t),this.size-=e.size)},Ch.prototype.getEntry=function(t,e){var n=this.docs.get(e);return Uo.resolve(n?n.maybeDocument:null)},Ch.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)},Ch.prototype.getDocumentsMatchingQuery=function(t,e,n){Ur(!e.isCollectionGroupQuery(),"CollectionGroup queries should be handled in LocalDocumentsView");for(var r=Ro(),i=new Wi(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 Ks&&e.matches(c)&&(r=r.insert(c.key,c))}return Uo.resolve(r)},Ch.prototype.forEachDocumentKey=function(t,e){return Uo.forEach(this.docs,function(t){return e(t)})},Ch.prototype.getNewDocumentChanges=function(t,e){throw new Error("getNewDocumentChanges() is not supported with MemoryPersistence")},Ch.prototype.getLastReadTime=function(t){return Uo.resolve(lo.MIN)},Ch.prototype.newChangeBuffer=function(t){return new Ch.RemoteDocumentChangeBuffer(this)},Ch.prototype.getSize=function(t){return Uo.resolve(this.size)},Ch.RemoteDocumentChangeBuffer=(t(Dh,Eh=Zs),Dh.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)},Dh.prototype.getFromCache=function(t,e){return this.documentCache.getEntry(t,e)},Dh.prototype.getAllFromCache=function(t,e){return this.documentCache.getEntries(t,e)},Dh),Ch);function Ch(t,e){this.indexManager=t,this.sizer=e,this.docs=new po(Wi.comparator),this.size=0}function Dh(t){var e=Eh.call(this)||this;return e.documentCache=t,e}var Nh=(Ah.prototype.forEachTarget=function(t,n){return this.targets.forEach(function(t,e){return n(e)}),Uo.resolve()},Ah.prototype.getLastRemoteSnapshotVersion=function(t){return Uo.resolve(this.lastRemoteSnapshotVersion)},Ah.prototype.getHighestSequenceNumber=function(t){return Uo.resolve(this.highestSequenceNumber)},Ah.prototype.allocateTargetId=function(t){var e=this.targetIdGenerator.after(this.highestTargetId);return this.highestTargetId=e,Uo.resolve(e)},Ah.prototype.setTargetsMetadata=function(t,e,n){return n&&(this.lastRemoteSnapshotVersion=n),e>this.highestSequenceNumber&&(this.highestSequenceNumber=e),Uo.resolve()},Ah.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)},Ah.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()},Ah.prototype.updateTargetData=function(t,e){return Ur(this.targets.has(e.target),"Updating a non-existent target"),this.saveTargetData(e),Uo.resolve()},Ah.prototype.removeTargetData=function(t,e){return Ur(0this.maxDelayMs&&(this.currentBaseMs=this.maxDelayMs)},Vh.prototype.cancel=function(){null!==this.timerPromise&&(this.timerPromise.cancel(),this.timerPromise=null)},Vh.prototype.jitterDelayMs=function(){return(Math.random()-.5)*this.currentBaseMs},Vh);function Vh(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 Bh,Uh,Kh="PersistentStream";(Uh=Bh=Bh||{})[Uh.Initial=0]="Initial",Uh[Uh.Starting=1]="Starting",Uh[Uh.Open=2]="Open",Uh[Uh.Error=3]="Error",Uh[Uh.Backoff=4]="Backoff";var Qh=(jh.prototype.isStarted=function(){return this.state===Bh.Starting||this.state===Bh.Open||this.state===Bh.Backoff},jh.prototype.isOpen=function(){return this.state===Bh.Open},jh.prototype.start=function(){this.state!==Bh.Error?(Ur(this.state===Bh.Initial,"Already started"),this.auth()):this.performBackoff()},jh.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(Bh.Initial)]:[3,2];case 1:t.sent(),t.label=2;case 2:return[2]}})})},jh.prototype.inhibitBackoff=function(){Ur(!this.isStarted(),"Can only inhibit backoff in a stopped state"),this.state=Bh.Initial,this.backoff.reset()},jh.prototype.markIdle=function(){var t=this;this.isOpen()&&null===this.idleTimer&&(this.idleTimer=this.queue.enqueueAfterDelay(this.idleTimerId,6e4,function(){return t.handleIdleCloseTimer()}))},jh.prototype.sendRequest=function(t){this.cancelIdleCheck(),this.stream.send(t)},jh.prototype.handleIdleCloseTimer=function(){return p(this,void 0,void 0,function(){return m(this,function(t){return this.isOpen()?[2,this.close(Bh.Initial)]:[2]})})},jh.prototype.cancelIdleCheck=function(){this.idleTimer&&(this.idleTimer.cancel(),this.idleTimer=null)},jh.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===Bh.Error||xc(n),"Can't provide an error when not in an error state."),this.cancelIdleCheck(),this.backoff.cancel(),this.closeCount++,e!==Bh.Error?this.backoff.reset():n&&n.code===Wr.RESOURCE_EXHAUSTED?(qr(n.toString()),qr("Using maximum backoff delay to prevent overloading the backend."),this.backoff.resetToMax()):n&&n.code===Wr.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]}})})},jh.prototype.tearDown=function(){},jh.prototype.auth=function(){var n=this;Ur(this.state===Bh.Initial,"Must be in initial state to auth"),this.state=Bh.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(Wr.UNKNOWN,"Fetching auth token failed: "+e.message);return n.handleStreamClose(t)})})},jh.prototype.startStream=function(t){var e=this;Ur(this.state===Bh.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===Bh.Starting,"Expected stream to be in state Starting, but was "+e.state),e.state=Bh.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)})})},jh.prototype.performBackoff=function(){var t=this;Ur(this.state===Bh.Error,"Should only perform backoff when in Error state"),this.state=Bh.Backoff,this.backoff.backoffAndRun(function(){return p(t,void 0,void 0,function(){return m(this,function(t){return Ur(this.state===Bh.Backoff,"Backoff elapsed but state is now: "+this.state),this.state=Bh.Initial,this.start(),Ur(this.isStarted(),"PersistentStream should have started"),[2]})})})},jh.prototype.handleStreamClose=function(t){return Ur(this.isStarted(),"Can't handle server close on non-started stream"),Fr(Kh,"close with error: "+t),this.stream=null,this.close(Bh.Error,t)},jh.prototype.getCloseGuardedDispatcher=function(e){var n=this;return function(t){n.queue.enqueueAndForget(function(){return n.closeCount===e?t():(Fr(Kh,"stream callback skipped by getCloseGuardedDispatcher."),Promise.resolve())})}},jh);function jh(t,e,n,r,i,o){this.queue=t,this.idleTimerId=n,this.connection=r,this.credentialsProvider=i,this.listener=o,this.state=Bh.Initial,this.closeCount=0,this.idleTimer=null,this.stream=null,this.backoff=new qh(t,e)}var Gh,Wh=(t(zh,Gh=Qh),zh.prototype.startRpc=function(t){return this.connection.openStream("Listen",t)},zh.prototype.onMessage=function(t){this.backoff.reset();var e=this.serializer.fromWatchChange(t),n=this.serializer.versionFromListenResponse(t);return this.listener.onWatchChange(e,n)},zh.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)},zh.prototype.unwatch=function(t){var e={};e.database=this.serializer.encodedDatabaseId,e.removeTarget=t,this.sendRequest(e)},zh);function zh(t,e,n,r,i){var o=Gh.call(this,t,Hi.ListenStreamConnectionBackoff,Hi.ListenStreamIdle,e,n,i)||this;return o.serializer=r,o}var Hh,Yh=(t(Xh,Hh=Qh),Object.defineProperty(Xh.prototype,"handshakeComplete",{get:function(){return this.handshakeComplete_},enumerable:!0,configurable:!0}),Xh.prototype.start=function(){this.handshakeComplete_=!1,Hh.prototype.start.call(this)},Xh.prototype.tearDown=function(){this.handshakeComplete_&&this.writeMutations([])},Xh.prototype.startRpc=function(t){return this.connection.openStream("Write",t)},Xh.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()},Xh.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)},Xh.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."),xp=/^__.*__$/,Fp=(qp.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=Jp("Query.where",t),o=Gc.fromString(e);if(i.isKeyField()){if(o===Gc.ARRAY_CONTAINS||o===Gc.ARRAY_CONTAINS_ANY)throw new zr(Wr.INVALID_ARGUMENT,"Invalid Query. You can't perform '"+o.toString()+"' queries on FieldPath.documentId().");if(o===Gc.IN){this.validateDisjunctiveFilterElements(n,o);for(var a=[],s=0,u=n;sr.length)throw new zr(Wr.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(Wr.INVALID_ARGUMENT,"Invalid query. You cannot use more than one '"+t.op.toString()+"' filter."):new zr(Wr.INVALID_ARGUMENT,"Invalid query. You cannot use '"+t.op.toString()+"' filters with '"+s.toString()+"' filters.")}}},bd.prototype.validateNewOrderBy=function(t){if(null===this._query.getFirstOrderByField()){var e=this._query.getInequalityFilterField();null!==e&&this.validateOrderByAndInequalityMatch(e,t.field)}},bd.prototype.validateOrderByAndInequalityMatch=function(t,e){if(!e.isEqual(t))throw new zr(Wr.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.")},bd);function bd(t,e,n){this._query=t,this.firestore=e,this._converter=n}var wd=(Object.defineProperty(Td.prototype,"docs",{get:function(){var e=[];return this.forEach(function(t){return e.push(t)}),e},enumerable:!0,configurable:!0}),Object.defineProperty(Td.prototype,"empty",{get:function(){return this._snapshot.docs.isEmpty()},enumerable:!0,configurable:!0}),Object.defineProperty(Td.prototype,"size",{get:function(){return this._snapshot.docs.size},enumerable:!0,configurable:!0}),Td.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(Td.prototype,"query",{get:function(){return new vd(this._originalQuery,this._firestore,this._converter)},enumerable:!0,configurable:!0}),Td.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(Wr.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 yd(i,t.doc.key,t.doc,o.fromCache,o.mutatedKeys.has(t.doc.key),a);return Ur(t.type===ll.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!==ll.Metadata}).map(function(t){var e=new yd(i,t.doc.key,t.doc,o.fromCache,o.mutatedKeys.has(t.doc.key),a),n=-1,r=-1;return t.type!==ll.Added&&(Ur(0<=(n=s.indexOf(t.doc.key)),"Index for document not found"),s=s.delete(t.doc.key)),t.type!==ll.Removed&&(r=(s=s.add(t.doc)).indexOf(t.doc.key)),{type:function(t){switch(t){case ll.Added:return"added";case ll.Modified:case ll.Metadata:return"modified";case ll.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},Td.prototype.isEqual=function(t){if(!(t instanceof Td))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},Td.prototype.convertToDocumentImpl=function(t){return new yd(this._firestore,t.key,t,this.metadata.fromCache,this._snapshot.mutatedKeys.has(t.key),this._converter)},Td);function Td(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 ld(n.hasPendingWrites,n.fromCache)}a(["length","forEach","map"],"undefined"!=typeof Symbol?[Symbol.iterator]:[]).forEach(function(t){try{Object.defineProperty(wd.prototype.docChanges,t,{get:function(){return function(){throw new zr(Wr.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 Sd,Ed=(t(Id,Sd=vd),Object.defineProperty(Id.prototype,"id",{get:function(){return this._query.path.lastSegment()},enumerable:!0,configurable:!0}),Object.defineProperty(Id.prototype,"parent",{get:function(){var t=this._query.path.popLast();return t.isEmpty()?null:new cd(new Wi(t),this.firestore)},enumerable:!0,configurable:!0}),Object.defineProperty(Id.prototype,"path",{get:function(){return this._query.path.canonicalString()},enumerable:!0,configurable:!0}),Id.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(Wr.INVALID_ARGUMENT,"Document path must be a non-empty string");var e=Bi.fromString(t);return cd.forPath(this._query.path.child(e),this.firestore,this._converter)},Id.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})},Id.prototype.withConverter=function(t){return new Id(this._path,this.firestore,t)},Id);function Id(t,e,n){var r=Sd.call(this,Kc.atPath(t),e,n)||this;if((r._path=t).length%2!=1)throw new zr(Wr.INVALID_ARGUMENT,"Invalid collection reference. Collection references must have an odd number of segments, but "+t.canonicalString()+" has "+t.length);return r}function Cd(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 op}),void 0!==e.mergeFields&&void 0!==e.merge)throw new zr(Wr.INVALID_ARGUMENT,"Invalid options passed to function "+t+'(): You cannot specify both "merge" and "mergeFields".');return e}function Dd(t,e){return void 0===e?{}:(mi(t,e,["serverTimestamps"]),hi(t,0,"serverTimestamps",e.serverTimestamps,["estimate","previous","none"]),e)}function Nd(t,e){ai(t,"object",1,e),e&&(mi(t,e,["source"]),hi(t,0,"source",e.source,["default","server","cache"]))}function Ad(t,e,n){if(e instanceof cd){if(e.firestore!==n)throw new zr(Wr.INVALID_ARGUMENT,"Provided document reference is from a different Firestore instance.");return e}throw yi(t,"DocumentReference",1,e)}function kd(t,e,n){var r;return t?(r=t.toFirestore(e),n="toFirestore() in "+n):r=e,[r,n]}var Rd=Yr(rd,"Use firebase.firestore() instead."),Md=Yr(od,"Use firebase.firestore().runTransaction() instead."),_d=Yr(sd,"Use firebase.firestore().batch() instead."),Ld=Yr(cd,"Use firebase.firestore().doc() instead."),Od=Yr(pd),Pd=Yr(yd),xd=Yr(vd),Fd=Yr(wd),qd=Yr(Ed,"Use firebase.firestore().collection() instead."),Vd={Firestore:Rd,GeoPoint:Vl,Timestamp:co,Blob:ki,Transaction:Md,WriteBatch:_d,DocumentReference:Ld,DocumentSnapshot:Od,Query:xd,QueryDocumentSnapshot:Pd,QuerySnapshot:Fd,CollectionReference:qd,FieldPath:op,FieldValue:Pp,setLogLevel:rd.setLogLevel,CACHE_SIZE_UNLIMITED:td};function Bd(t){t.INTERNAL.registerComponent(new w("firestore",function(t){var e=t.getProvider("app").getImmediate();return new rd(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}(Vd)))}var Ud=(Kd.prototype.addCallback=function(t){},Kd.prototype.shutdown=function(){},Kd);function Kd(){}var Qd="ConnectivityMonitor",jd=(Gd.prototype.addCallback=function(t){this.callbacks.push(t)},Gd.prototype.shutdown=function(){window.removeEventListener("online",this.networkAvailableListener),window.removeEventListener("offline",this.networkUnavailableListener)},Gd.prototype.configureNetworkMonitoring=function(){window.addEventListener("online",this.networkAvailableListener),window.addEventListener("offline",this.networkUnavailableListener)},Gd.prototype.onNetworkAvailable=function(){Fr(Qd,"Network connectivity changed: AVAILABLE");for(var t=0,e=this.callbacks;t