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

3 lines
326 KiB
JavaScript
Raw Blame History

This file contains invisible Unicode characters

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

"use strict";function _interopDefault(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var LogLevel,firebase=_interopDefault(require("@firebase/app")),tslib=require("tslib"),logger=require("@firebase/logger"),util=require("@firebase/util"),component=require("@firebase/component"),webchannelWrapper=require("@firebase/webchannel-wrapper"),SDK_VERSION=firebase.SDK_VERSION,__PRIVATE_logClient=new logger.Logger("@firebase/firestore");function __PRIVATE_getLogLevel(){return __PRIVATE_logClient.logLevel===logger.LogLevel.DEBUG?LogLevel.DEBUG:__PRIVATE_logClient.logLevel===logger.LogLevel.SILENT?LogLevel.SILENT:LogLevel.ERROR}function setLogLevel(t){switch(t){case LogLevel.DEBUG:__PRIVATE_logClient.logLevel=logger.LogLevel.DEBUG;break;case LogLevel.ERROR:__PRIVATE_logClient.logLevel=logger.LogLevel.ERROR;break;case LogLevel.SILENT:__PRIVATE_logClient.logLevel=logger.LogLevel.SILENT;break;default:__PRIVATE_logClient.error("Firestore ("+SDK_VERSION+"): Invalid value passed to `setLogLevel`")}}function debug(t,e){for(var n=[],r=2;r<arguments.length;r++)n[r-2]=arguments[r];if(__PRIVATE_logClient.logLevel<=logger.LogLevel.DEBUG){var i=n.map(__PRIVATE_argToString);__PRIVATE_logClient.debug.apply(__PRIVATE_logClient,tslib.__spreadArrays(["Firestore ("+SDK_VERSION+") ["+t+"]: "+e],i))}}function error(t){for(var e=[],n=1;n<arguments.length;n++)e[n-1]=arguments[n];if(__PRIVATE_logClient.logLevel<=logger.LogLevel.ERROR){var r=e.map(__PRIVATE_argToString);__PRIVATE_logClient.error.apply(__PRIVATE_logClient,tslib.__spreadArrays(["Firestore ("+SDK_VERSION+"): "+t],r))}}function __PRIVATE_argToString(t){if("string"==typeof t)return t;var e=__PRIVATE_PlatformSupport.t();try{return e.i(t)}catch(e){return t}}function fail(t){var e="FIRESTORE ("+SDK_VERSION+") INTERNAL ASSERTION FAILED: "+t;throw error(e),new Error(e)}function assert(t,e){t||fail(e)}!function(t){t[t.DEBUG=0]="DEBUG",t[t.ERROR=1]="ERROR",t[t.SILENT=2]="SILENT"}(LogLevel||(LogLevel={}));var __PRIVATE_AutoId=function(){function t(){}return t.s=function(){for(var t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",e="",n=0;n<20;n++)e+=t.charAt(Math.floor(Math.random()*t.length));return assert(20===e.length,"Invalid auto ID: "+e),e},t}();function __PRIVATE_primitiveComparator(t,e){return t<e?-1:t>e?1:0}function __PRIVATE_equals(t,e){return null!=t?!(!e||!t.isEqual(e)):t===e}function __PRIVATE_arrayEquals(t,e){if(t.length!==e.length)return!1;for(var n=0;n<t.length;n++)if(!t[n].isEqual(e[n]))return!1;return!0}function __PRIVATE_immediateSuccessor(t){return t+"\0"}var __PRIVATE_OnlineState,__PRIVATE_OnlineStateSource,__PRIVATE_DatabaseInfo=function(t,e,n,r,i){this.o=t,this.persistenceKey=e,this.host=n,this.ssl=r,this.forceLongPolling=i},__PRIVATE_DEFAULT_DATABASE_NAME="(default)",__PRIVATE_DatabaseId=function(){function t(t,e){this.projectId=t,this.database=e||__PRIVATE_DEFAULT_DATABASE_NAME}return Object.defineProperty(t.prototype,"u",{get:function(){return this.database===__PRIVATE_DEFAULT_DATABASE_NAME},enumerable:!0,configurable:!0}),t.prototype.isEqual=function(e){return e instanceof t&&e.projectId===this.projectId&&e.database===this.database},t.prototype._=function(t){return __PRIVATE_primitiveComparator(this.projectId,t.projectId)||__PRIVATE_primitiveComparator(this.database,t.database)},t}();!function(t){t[t.h=0]="__PRIVATE_Unknown",t[t.l=1]="__PRIVATE_Online",t[t.T=2]="__PRIVATE_Offline"}(__PRIVATE_OnlineState||(__PRIVATE_OnlineState={})),function(t){t[t.P=0]="__PRIVATE_RemoteStore",t[t.A=1]="__PRIVATE_SharedClientState"}(__PRIVATE_OnlineStateSource||(__PRIVATE_OnlineStateSource={}));var User=function(){function t(t){this.uid=t}return t.prototype.R=function(){return null!=this.uid},t.prototype.I=function(){return this.R()?"uid:"+this.uid:"anonymous-user"},t.prototype.isEqual=function(t){return t.uid===this.uid},t.UNAUTHENTICATED=new t(null),t.V=new t("google-credentials-uid"),t.m=new t("first-party-uid"),t}(),Code={OK:"ok",CANCELLED:"cancelled",UNKNOWN:"unknown",INVALID_ARGUMENT:"invalid-argument",DEADLINE_EXCEEDED:"deadline-exceeded",NOT_FOUND:"not-found",ALREADY_EXISTS:"already-exists",PERMISSION_DENIED:"permission-denied",UNAUTHENTICATED:"unauthenticated",RESOURCE_EXHAUSTED:"resource-exhausted",FAILED_PRECONDITION:"failed-precondition",ABORTED:"aborted",OUT_OF_RANGE:"out-of-range",UNIMPLEMENTED:"unimplemented",INTERNAL:"internal",UNAVAILABLE:"unavailable",DATA_LOSS:"data-loss"},FirestoreError=function(t){function e(e,n){var r=t.call(this,n)||this;return r.code=e,r.message=n,r.name="FirebaseError",r.toString=function(){return r.name+": [code="+r.code+"]: "+r.message},r}return tslib.__extends(e,t),e}(Error),__PRIVATE_OAuthToken=function(t,e){this.user=e,this.type="OAuth",this.v={},this.v.Authorization="Bearer "+t},__PRIVATE_EmptyCredentialsProvider=function(){function t(){this.p=null}return t.prototype.getToken=function(){return Promise.resolve(null)},t.prototype.g=function(){},t.prototype.S=function(t){assert(!this.p,"Can only call setChangeListener() once."),this.p=t,t(User.UNAUTHENTICATED)},t.prototype.D=function(){assert(null!==this.p,"removeChangeListener() when no listener registered"),this.p=null},t}(),__PRIVATE_FirebaseCredentialsProvider=function(){function t(t){var e=this;this.C=null,this.currentUser=User.UNAUTHENTICATED,this.O=!1,this.F=0,this.p=null,this.forceRefresh=!1,this.C=function(){e.F++,e.currentUser=e.N(),e.O=!0,e.p&&e.p(e.currentUser)},this.F=0,this.auth=t.getImmediate({optional:!0}),this.auth?this.auth.addAuthTokenListener(this.C):(this.C(null),t.get().then((function(t){e.auth=t,e.C&&e.auth.addAuthTokenListener(e.C)}),(function(){})))}return t.prototype.getToken=function(){var t=this;assert(null!=this.C,"getToken cannot be called after listener removed.");var e=this.F,n=this.forceRefresh;return this.forceRefresh=!1,this.auth?this.auth.getToken(n).then((function(n){if(t.F!==e)throw new FirestoreError(Code.ABORTED,"getToken aborted due to token change.");return n?(assert("string"==typeof n.accessToken,"Invalid tokenData returned from getToken():"+n),new __PRIVATE_OAuthToken(n.accessToken,t.currentUser)):null})):Promise.resolve(null)},t.prototype.g=function(){this.forceRefresh=!0},t.prototype.S=function(t){assert(!this.p,"Can only call setChangeListener() once."),this.p=t,this.O&&t(this.currentUser)},t.prototype.D=function(){assert(null!=this.C,"removeChangeListener() called twice"),assert(null!==this.p,"removeChangeListener() called when no listener registered"),this.auth&&this.auth.removeAuthTokenListener(this.C),this.C=null,this.p=null},t.prototype.N=function(){var t=this.auth&&this.auth.getUid();return assert(null===t||"string"==typeof t,"Received invalid UID: "+t),new User(t)},t}(),__PRIVATE_FirstPartyToken=function(){function t(t,e){this.M=t,this.L=e,this.type="FirstParty",this.user=User.m}return Object.defineProperty(t.prototype,"v",{get:function(){var t={"X-Goog-AuthUser":this.L},e=this.M.auth.G([]);return e&&(t.Authorization=e),t},enumerable:!0,configurable:!0}),t}(),__PRIVATE_FirstPartyCredentialsProvider=function(){function t(t,e){this.M=t,this.L=e}return t.prototype.getToken=function(){return Promise.resolve(new __PRIVATE_FirstPartyToken(this.M,this.L))},t.prototype.S=function(t){t(User.m)},t.prototype.D=function(){},t.prototype.g=function(){},t}();function __PRIVATE_makeCredentialsProvider(t){if(!t)return new __PRIVATE_EmptyCredentialsProvider;switch(t.type){case"gapi":var e=t.B;return assert(!("object"!=typeof e||null===e||!e.auth||!e.auth.getAuthHeaderValueForFirstParty),"unexpected gapi interface"),new __PRIVATE_FirstPartyCredentialsProvider(e,t.L||"0");case"provider":return t.B;default:throw new FirestoreError(Code.INVALID_ARGUMENT,"makeCredentialsProvider failed due to invalid credential type")}}function contains(t,e){return Object.prototype.hasOwnProperty.call(t,e)}function __PRIVATE_defaulted(t,e){return void 0!==t?t:e}function __PRIVATE_forEachNumber(t,e){for(var n in t)if(Object.prototype.hasOwnProperty.call(t,n)){var r=Number(n);isNaN(r)||e(r,t[n])}}function values(t){var e=[];return forEach(t,(function(t,n){return e.push(n)})),e}function forEach(t,e){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e(n,t[n])}function __PRIVATE_isEmpty(t){for(var e in assert(null!=t&&"object"==typeof t,"isEmpty() expects object parameter."),t)if(Object.prototype.hasOwnProperty.call(t,e))return!1;return!0}function __PRIVATE_shallowCopy(t){assert(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}function __PRIVATE_validateNoArgs(t,e){if(0!==e.length)throw new FirestoreError(Code.INVALID_ARGUMENT,"Function "+t+"() does not support arguments, but was called with "+__PRIVATE_formatPlural(e.length,"argument")+".")}function __PRIVATE_validateExactNumberOfArgs(t,e,n){if(e.length!==n)throw new FirestoreError(Code.INVALID_ARGUMENT,"Function "+t+"() requires "+__PRIVATE_formatPlural(n,"argument")+", but was called with "+__PRIVATE_formatPlural(e.length,"argument")+".")}function __PRIVATE_validateAtLeastNumberOfArgs(t,e,n){if(e.length<n)throw new FirestoreError(Code.INVALID_ARGUMENT,"Function "+t+"() requires at least "+__PRIVATE_formatPlural(n,"argument")+", but was called with "+__PRIVATE_formatPlural(e.length,"argument")+".")}function __PRIVATE_validateBetweenNumberOfArgs(t,e,n,r){if(e.length<n||e.length>r)throw new FirestoreError(Code.INVALID_ARGUMENT,"Function "+t+"() requires between "+n+" and "+r+" arguments, but was called with "+__PRIVATE_formatPlural(e.length,"argument")+".")}function __PRIVATE_validateNamedArrayAtLeastNumberOfElements(t,e,n,r){if(!(e instanceof Array)||e.length<r)throw new FirestoreError(Code.INVALID_ARGUMENT,"Function "+t+"() requires its "+n+" argument to be an array with at least "+__PRIVATE_formatPlural(r,"element")+".")}function __PRIVATE_validateArgType(t,e,n,r){__PRIVATE_validateType(t,e,__PRIVATE_ordinal(n)+" argument",r)}function __PRIVATE_validateOptionalArgType(t,e,n,r){void 0!==r&&__PRIVATE_validateArgType(t,e,n,r)}function __PRIVATE_validateNamedType(t,e,n,r){__PRIVATE_validateType(t,e,n+" option",r)}function __PRIVATE_validateNamedOptionalType(t,e,n,r){void 0!==r&&__PRIVATE_validateNamedType(t,e,n,r)}function __PRIVATE_validateArrayElements(t,e,n,r,i){if(!(r instanceof Array))throw new FirestoreError(Code.INVALID_ARGUMENT,"Function "+t+"() requires its "+e+" option to be an array, but it was: "+__PRIVATE_valueDescription(r));for(var s=0;s<r.length;++s)if(!i(r[s]))throw new FirestoreError(Code.INVALID_ARGUMENT,"Function "+t+"() requires all "+e+" elements to be "+n+", but the value at index "+s+" was: "+__PRIVATE_valueDescription(r[s]))}function __PRIVATE_validateOptionalArrayElements(t,e,n,r,i){void 0!==r&&__PRIVATE_validateArrayElements(t,e,n,r,i)}function __PRIVATE_validateNamedPropertyEquals(t,e,n,r,i){for(var s=[],o=0,u=i;o<u.length;o++){var a=u[o];if(a===r)return;s.push(__PRIVATE_valueDescription(a))}var _=__PRIVATE_valueDescription(r);throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid value "+_+" provided to function "+t+'() for option "'+n+'". Acceptable values: '+s.join(", "))}function __PRIVATE_validateNamedOptionalPropertyEquals(t,e,n,r,i){void 0!==r&&__PRIVATE_validateNamedPropertyEquals(t,e,n,r,i)}function __PRIVATE_validateStringEnum(t,e,n,r){if(!e.some((function(t){return t===r})))throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid value "+__PRIVATE_valueDescription(r)+" provided to function "+t+"() for its "+__PRIVATE_ordinal(n)+" argument. Acceptable values: "+e.join(", "))}function __PRIVATE_validateType(t,e,n,r){if(!("object"===e?__PRIVATE_isPlainObject(r):"non-empty string"===e?"string"==typeof r&&""!==r:typeof r===e)){var i=__PRIVATE_valueDescription(r);throw new FirestoreError(Code.INVALID_ARGUMENT,"Function "+t+"() requires its "+n+" to be of type "+e+", but it was: "+i)}}function __PRIVATE_isPlainObject(t){return"object"==typeof t&&null!==t&&(Object.getPrototypeOf(t)===Object.prototype||null===Object.getPrototypeOf(t))}function __PRIVATE_valueDescription(t){if(void 0===t)return"undefined";if(null===t)return"null";if("string"==typeof t)return t.length>20&&(t=t.substring(0,20)+"..."),JSON.stringify(t);if("number"==typeof t||"boolean"==typeof t)return""+t;if("object"==typeof t){if(t instanceof Array)return"an array";var e=__PRIVATE_tryGetCustomObjectType(t);return e?"a custom "+e+" object":"an object"}return"function"==typeof t?"a function":fail("Unknown wrong type: "+typeof t)}function __PRIVATE_tryGetCustomObjectType(t){if(t.constructor){var e=/function\s+([^\s(]+)\s*\(/.exec(t.constructor.toString());if(e&&e.length>1)return e[1]}return null}function __PRIVATE_validateDefined(t,e,n){if(void 0===n)throw new FirestoreError(Code.INVALID_ARGUMENT,"Function "+t+"() requires a valid "+__PRIVATE_ordinal(e)+" argument, but it was undefined.")}function __PRIVATE_validateOptionNames(t,e,n){forEach(e,(function(e,r){if(n.indexOf(e)<0)throw new FirestoreError(Code.INVALID_ARGUMENT,"Unknown option '"+e+"' passed to function "+t+"(). Available options: "+n.join(", "))}))}function __PRIVATE_invalidClassError(t,e,n,r){var i=__PRIVATE_valueDescription(r);return new FirestoreError(Code.INVALID_ARGUMENT,"Function "+t+"() requires its "+__PRIVATE_ordinal(n)+" argument to be a "+e+", but it was: "+i)}function __PRIVATE_validatePositiveNumber(t,e,n){if(n<=0)throw new FirestoreError(Code.INVALID_ARGUMENT,'Function "'+t+'()" requires its '+__PRIVATE_ordinal(e)+" argument to be a positive number, but it was: "+n+".")}function __PRIVATE_ordinal(t){switch(t){case 1:return"first";case 2:return"second";case 3:return"third";default:return t+"th"}}function __PRIVATE_formatPlural(t,e){return t+" "+e+(1===t?"":"s")}var GeoPoint=function(){function t(t,e){if(__PRIVATE_validateExactNumberOfArgs("GeoPoint",arguments,2),__PRIVATE_validateArgType("GeoPoint","number",1,t),__PRIVATE_validateArgType("GeoPoint","number",2,e),!isFinite(t)||t<-90||t>90)throw new FirestoreError(Code.INVALID_ARGUMENT,"Latitude must be a number between -90 and 90, but was: "+t);if(!isFinite(e)||e<-180||e>180)throw new FirestoreError(Code.INVALID_ARGUMENT,"Longitude must be a number between -180 and 180, but was: "+e);this.U=t,this.k=e}return Object.defineProperty(t.prototype,"latitude",{get:function(){return this.U},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"longitude",{get:function(){return this.k},enumerable:!0,configurable:!0}),t.prototype.isEqual=function(t){return this.U===t.U&&this.k===t.k},t.prototype.K=function(t){return __PRIVATE_primitiveComparator(this.U,t.U)||__PRIVATE_primitiveComparator(this.k,t.k)},t}(),Timestamp=function(){function t(t,e){if(this.seconds=t,this.nanoseconds=e,e<0)throw new FirestoreError(Code.INVALID_ARGUMENT,"Timestamp nanoseconds out of range: "+e);if(e>=1e9)throw new FirestoreError(Code.INVALID_ARGUMENT,"Timestamp nanoseconds out of range: "+e);if(t<-62135596800)throw new FirestoreError(Code.INVALID_ARGUMENT,"Timestamp seconds out of range: "+t);if(t>=253402300800)throw new FirestoreError(Code.INVALID_ARGUMENT,"Timestamp seconds out of range: "+t)}return t.now=function(){return t.fromMillis(Date.now())},t.fromDate=function(e){return t.fromMillis(e.getTime())},t.fromMillis=function(e){var n=Math.floor(e/1e3);return new t(n,1e6*(e-1e3*n))},t.prototype.toDate=function(){return new Date(this.toMillis())},t.prototype.toMillis=function(){return 1e3*this.seconds+this.nanoseconds/1e6},t.prototype.K=function(t){return this.seconds===t.seconds?__PRIVATE_primitiveComparator(this.nanoseconds,t.nanoseconds):__PRIVATE_primitiveComparator(this.seconds,t.seconds)},t.prototype.isEqual=function(t){return t.seconds===this.seconds&&t.nanoseconds===this.nanoseconds},t.prototype.toString=function(){return"Timestamp(seconds="+this.seconds+", nanoseconds="+this.nanoseconds+")"},t}(),__PRIVATE_SnapshotVersion=function(){function t(t){this.timestamp=t}return t.j=function(e){var n=Math.floor(e/1e6);return new t(new Timestamp(n,e%1e6*1e3))},t.q=function(e){return new t(e)},t.W=function(){return t.MIN},t.prototype._=function(t){return this.timestamp.K(t.timestamp)},t.prototype.isEqual=function(t){return this.timestamp.isEqual(t.timestamp)},t.prototype.$=function(){return 1e6*this.timestamp.seconds+this.timestamp.nanoseconds/1e3},t.prototype.toString=function(){return"SnapshotVersion("+this.timestamp.toString()+")"},t.prototype.Y=function(){return this.timestamp},t.MIN=new t(new Timestamp(0,0)),t}(),__PRIVATE_DOCUMENT_KEY_NAME="__name__",__PRIVATE_BasePath=function(){function t(t,e,n){void 0===e?e=0:e>t.length&&fail("offset "+e+" out of range "+t.length),void 0===n?n=t.length-e:n>t.length-e&&fail("length "+n+" out of range "+(t.length-e)),this.segments=t,this.offset=e,this.H=n}return Object.defineProperty(t.prototype,"length",{get:function(){return this.H},enumerable:!0,configurable:!0}),t.prototype.isEqual=function(e){return 0===t.X(this,e)},t.prototype.child=function(e){var n=this.segments.slice(this.offset,this.limit());return e instanceof t?e.forEach((function(t){n.push(t)})):n.push(e),this.J(n)},t.prototype.limit=function(){return this.offset+this.length},t.prototype.Z=function(t){return t=void 0===t?1:t,assert(this.length>=t,"Can't call popFirst() with less segments"),this.J(this.segments,this.offset+t,this.length-t)},t.prototype.tt=function(){return assert(!this.et(),"Can't call popLast() on empty path"),this.J(this.segments,this.offset,this.length-1)},t.prototype.nt=function(){return assert(!this.et(),"Can't call firstSegment() on empty path"),this.segments[this.offset]},t.prototype.rt=function(){return this.get(this.length-1)},t.prototype.get=function(t){return assert(t<this.length,"Index out of range"),this.segments[this.offset+t]},t.prototype.et=function(){return 0===this.length},t.prototype.it=function(t){if(t.length<this.length)return!1;for(var e=0;e<this.length;e++)if(this.get(e)!==t.get(e))return!1;return!0},t.prototype.st=function(t){if(this.length+1!==t.length)return!1;for(var e=0;e<this.length;e++)if(this.get(e)!==t.get(e))return!1;return!0},t.prototype.forEach=function(t){for(var e=this.offset,n=this.limit();e<n;e++)t(this.segments[e])},t.prototype.ot=function(){return this.segments.slice(this.offset,this.limit())},t.X=function(t,e){for(var n=Math.min(t.length,e.length),r=0;r<n;r++){var i=t.get(r),s=e.get(r);if(i<s)return-1;if(i>s)return 1}return t.length<e.length?-1:t.length>e.length?1:0},t}(),ResourcePath=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return tslib.__extends(e,t),e.prototype.J=function(t,n,r){return new e(t,n,r)},e.prototype.ut=function(){return this.ot().join("/")},e.prototype.toString=function(){return this.ut()},e.at=function(t){if(t.indexOf("//")>=0)throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid path ("+t+"). Paths must not contain // in them.");return new e(t.split("/").filter((function(t){return t.length>0})))},e._t=new e([]),e}(__PRIVATE_BasePath),__PRIVATE_identifierRegExp=/^[_a-zA-Z][_a-zA-Z0-9]*$/,FieldPath=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return tslib.__extends(e,t),e.prototype.J=function(t,n,r){return new e(t,n,r)},e.ct=function(t){return __PRIVATE_identifierRegExp.test(t)},e.prototype.ut=function(){return this.ot().map((function(t){return t=t.replace("\\","\\\\").replace("`","\\`"),e.ct(t)||(t="`"+t+"`"),t})).join(".")},e.prototype.toString=function(){return this.ut()},e.prototype.ht=function(){return 1===this.length&&this.get(0)===__PRIVATE_DOCUMENT_KEY_NAME},e.ft=function(){return new e([__PRIVATE_DOCUMENT_KEY_NAME])},e.lt=function(t){for(var n=[],r="",i=0,s=function(){if(0===r.length)throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid field path ("+t+"). Paths must not be empty, begin with '.', end with '.', or contain '..'");n.push(r),r=""},o=!1;i<t.length;){var u=t[i];if("\\"===u){if(i+1===t.length)throw new FirestoreError(Code.INVALID_ARGUMENT,"Path has trailing escape character: "+t);var a=t[i+1];if("\\"!==a&&"."!==a&&"`"!==a)throw new FirestoreError(Code.INVALID_ARGUMENT,"Path has invalid escape sequence: "+t);r+=a,i+=2}else"`"===u?(o=!o,i++):"."!==u||o?(r+=u,i++):(s(),i++)}if(s(),o)throw new FirestoreError(Code.INVALID_ARGUMENT,"Unterminated ` in path: "+t);return new e(n)},e._t=new e([]),e}(__PRIVATE_BasePath),__PRIVATE_DocumentKey=function(){function t(e){this.path=e,assert(t.dt(e),"Invalid DocumentKey with an odd number of segments: "+e.ot().join("/"))}return t.prototype.Tt=function(t){return this.path.length>=2&&this.path.get(this.path.length-2)===t},t.prototype.isEqual=function(t){return null!==t&&0===ResourcePath.X(this.path,t.path)},t.prototype.toString=function(){return this.path.toString()},t.X=function(t,e){return ResourcePath.X(t.path,e.path)},t.dt=function(t){return t.length%2==0},t.Et=function(e){return new t(new ResourcePath(e.slice()))},t.Pt=function(e){return new t(ResourcePath.at(e))},t.EMPTY=new t(new ResourcePath([])),t}(),__PRIVATE_SortedMap=function(){function t(t,e){this.X=t,this.root=e||__PRIVATE_LLRBNode.EMPTY}return t.prototype.At=function(e,n){return new t(this.X,this.root.At(e,n,this.X).Rt(null,null,__PRIVATE_LLRBNode.It,null,null))},t.prototype.remove=function(e){return new t(this.X,this.root.remove(e,this.X).Rt(null,null,__PRIVATE_LLRBNode.It,null,null))},t.prototype.get=function(t){for(var e=this.root;!e.et();){var n=this.X(t,e.key);if(0===n)return e.value;n<0?e=e.left:n>0&&(e=e.right)}return null},t.prototype.indexOf=function(t){for(var e=0,n=this.root;!n.et();){var r=this.X(t,n.key);if(0===r)return e+n.left.size;r<0?n=n.left:(e+=n.left.size+1,n=n.right)}return-1},t.prototype.et=function(){return this.root.et()},Object.defineProperty(t.prototype,"size",{get:function(){return this.root.size},enumerable:!0,configurable:!0}),t.prototype.Vt=function(){return this.root.Vt()},t.prototype.vt=function(){return this.root.vt()},t.prototype.pt=function(t){return this.root.pt(t)},t.prototype.forEach=function(t){this.pt((function(e,n){return t(e,n),!1}))},t.prototype.toString=function(){var t=[];return this.pt((function(e,n){return t.push(e+":"+n),!1})),"{"+t.join(", ")+"}"},t.prototype.bt=function(t){return this.root.bt(t)},t.prototype.gt=function(){return new __PRIVATE_SortedMapIterator(this.root,null,this.X,!1)},t.prototype.wt=function(t){return new __PRIVATE_SortedMapIterator(this.root,t,this.X,!1)},t.prototype.yt=function(){return new __PRIVATE_SortedMapIterator(this.root,null,this.X,!0)},t.prototype.St=function(t){return new __PRIVATE_SortedMapIterator(this.root,t,this.X,!0)},t}(),__PRIVATE_SortedMapIterator=function(){function t(t,e,n,r){this.Dt=r,this.Ct=[];for(var i=1;!t.et();)if(i=e?n(t.key,e):1,r&&(i*=-1),i<0)t=this.Dt?t.left:t.right;else{if(0===i){this.Ct.push(t);break}this.Ct.push(t),t=this.Dt?t.right:t.left}}return t.prototype.Ot=function(){assert(this.Ct.length>0,"getNext() called on iterator when hasNext() is false.");var t=this.Ct.pop(),e={key:t.key,value:t.value};if(this.Dt)for(t=t.left;!t.et();)this.Ct.push(t),t=t.right;else for(t=t.right;!t.et();)this.Ct.push(t),t=t.left;return e},t.prototype.Ft=function(){return this.Ct.length>0},t.prototype.Nt=function(){if(0===this.Ct.length)return null;var t=this.Ct[this.Ct.length-1];return{key:t.key,value:t.value}},t}(),__PRIVATE_LLRBNode=function(){function t(e,n,r,i,s){this.key=e,this.value=n,this.color=null!=r?r:t.RED,this.left=null!=i?i:t.EMPTY,this.right=null!=s?s:t.EMPTY,this.size=this.left.size+1+this.right.size}return t.prototype.Rt=function(e,n,r,i,s){return new t(null!=e?e:this.key,null!=n?n:this.value,null!=r?r:this.color,null!=i?i:this.left,null!=s?s:this.right)},t.prototype.et=function(){return!1},t.prototype.pt=function(t){return this.left.pt(t)||t(this.key,this.value)||this.right.pt(t)},t.prototype.bt=function(t){return this.right.bt(t)||t(this.key,this.value)||this.left.bt(t)},t.prototype.min=function(){return this.left.et()?this:this.left.min()},t.prototype.Vt=function(){return this.min().key},t.prototype.vt=function(){return this.right.et()?this.key:this.right.vt()},t.prototype.At=function(t,e,n){var r=this,i=n(t,r.key);return(r=i<0?r.Rt(null,null,null,r.left.At(t,e,n),null):0===i?r.Rt(null,e,null,null,null):r.Rt(null,null,null,null,r.right.At(t,e,n))).Mt()},t.prototype.Lt=function(){if(this.left.et())return t.EMPTY;var e=this;return e.left.Gt()||e.left.left.Gt()||(e=e.Bt()),(e=e.Rt(null,null,null,e.left.Lt(),null)).Mt()},t.prototype.remove=function(e,n){var r,i=this;if(n(e,i.key)<0)i.left.et()||i.left.Gt()||i.left.left.Gt()||(i=i.Bt()),i=i.Rt(null,null,null,i.left.remove(e,n),null);else{if(i.left.Gt()&&(i=i.Ut()),i.right.et()||i.right.Gt()||i.right.left.Gt()||(i=i.kt()),0===n(e,i.key)){if(i.right.et())return t.EMPTY;r=i.right.min(),i=i.Rt(r.key,r.value,null,null,i.right.Lt())}i=i.Rt(null,null,null,null,i.right.remove(e,n))}return i.Mt()},t.prototype.Gt=function(){return this.color},t.prototype.Mt=function(){var t=this;return t.right.Gt()&&!t.left.Gt()&&(t=t.xt()),t.left.Gt()&&t.left.left.Gt()&&(t=t.Ut()),t.left.Gt()&&t.right.Gt()&&(t=t.Kt()),t},t.prototype.Bt=function(){var t=this.Kt();return t.right.left.Gt()&&(t=(t=(t=t.Rt(null,null,null,null,t.right.Ut())).xt()).Kt()),t},t.prototype.kt=function(){var t=this.Kt();return t.left.left.Gt()&&(t=(t=t.Ut()).Kt()),t},t.prototype.xt=function(){var e=this.Rt(null,null,t.RED,null,this.right.left);return this.right.Rt(null,null,this.color,e,null)},t.prototype.Ut=function(){var e=this.Rt(null,null,t.RED,this.left.right,null);return this.left.Rt(null,null,this.color,null,e)},t.prototype.Kt=function(){var t=this.left.Rt(null,null,!this.left.color,null,null),e=this.right.Rt(null,null,!this.right.color,null,null);return this.Rt(null,null,!this.color,t,e)},t.prototype.jt=function(){var t=this.qt();return Math.pow(2,t)<=this.size+1},t.prototype.qt=function(){if(this.Gt()&&this.left.Gt())throw fail("Red node has red child("+this.key+","+this.value+")");if(this.right.Gt())throw fail("Right child of ("+this.key+","+this.value+") is red");var t=this.left.qt();if(t!==this.right.qt())throw fail("Black depths differ");return t+(this.Gt()?0:1)},t.EMPTY=null,t.RED=!0,t.It=!1,t}(),__PRIVATE_LLRBEmptyNode=function(){function t(){this.size=0}return Object.defineProperty(t.prototype,"key",{get:function(){throw fail("LLRBEmptyNode has no key.")},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"value",{get:function(){throw fail("LLRBEmptyNode has no value.")},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"color",{get:function(){throw fail("LLRBEmptyNode has no color.")},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"left",{get:function(){throw fail("LLRBEmptyNode has no left child.")},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"right",{get:function(){throw fail("LLRBEmptyNode has no right child.")},enumerable:!0,configurable:!0}),t.prototype.Rt=function(t,e,n,r,i){return this},t.prototype.At=function(t,e,n){return new __PRIVATE_LLRBNode(t,e)},t.prototype.remove=function(t,e){return this},t.prototype.et=function(){return!0},t.prototype.pt=function(t){return!1},t.prototype.bt=function(t){return!1},t.prototype.Vt=function(){return null},t.prototype.vt=function(){return null},t.prototype.Gt=function(){return!1},t.prototype.jt=function(){return!0},t.prototype.qt=function(){return 0},t}();__PRIVATE_LLRBNode.EMPTY=new __PRIVATE_LLRBEmptyNode;var __PRIVATE_SortedSet=function(){function t(t){this.X=t,this.data=new __PRIVATE_SortedMap(this.X)}return t.Qt=function(e){var n=new t(e.X);return e.forEach((function(t){n=n.add(t)})),n},t.prototype.has=function(t){return null!==this.data.get(t)},t.prototype.first=function(){return this.data.Vt()},t.prototype.last=function(){return this.data.vt()},Object.defineProperty(t.prototype,"size",{get:function(){return this.data.size},enumerable:!0,configurable:!0}),t.prototype.indexOf=function(t){return this.data.indexOf(t)},t.prototype.forEach=function(t){this.data.pt((function(e,n){return t(e),!1}))},t.prototype.Wt=function(t,e){for(var n=this.data.wt(t[0]);n.Ft();){var r=n.Ot();if(this.X(r.key,t[1])>=0)return;e(r.key)}},t.prototype.$t=function(t,e){var n;for(n=void 0!==e?this.data.wt(e):this.data.gt();n.Ft();){if(!t(n.Ot().key))return}},t.prototype.Yt=function(t){var e=this.data.wt(t);return e.Ft()?e.Ot().key:null},t.prototype.gt=function(){return new __PRIVATE_SortedSetIterator(this.data.gt())},t.prototype.wt=function(t){return new __PRIVATE_SortedSetIterator(this.data.wt(t))},t.prototype.add=function(t){return this.Rt(this.data.remove(t).At(t,!0))},t.prototype.delete=function(t){return this.has(t)?this.Rt(this.data.remove(t)):this},t.prototype.et=function(){return this.data.et()},t.prototype.Ht=function(t){var e=this;return t.forEach((function(t){e=e.add(t)})),e},t.prototype.isEqual=function(e){if(!(e instanceof t))return!1;if(this.size!==e.size)return!1;for(var n=this.data.gt(),r=e.data.gt();n.Ft();){var i=n.Ot().key,s=r.Ot().key;if(0!==this.X(i,s))return!1}return!0},t.prototype.ot=function(){var t=[];return this.forEach((function(e){t.push(e)})),t},t.prototype.toString=function(){var t=[];return this.forEach((function(e){return t.push(e)})),"SortedSet("+t.toString()+")"},t.prototype.Rt=function(e){var n=new t(this.X);return n.data=e,n},t}(),__PRIVATE_SortedSetIterator=function(){function t(t){this.Xt=t}return t.prototype.Ot=function(){return this.Xt.Ot().key},t.prototype.Ft=function(){return this.Xt.Ft()},t}(),__PRIVATE_ServerTimestampTransform=function(){function t(){}return t.prototype.zt=function(t,e){return new __PRIVATE_ServerTimestampValue(e,t)},t.prototype.Jt=function(t,e){return e},t.prototype.Zt=function(t){return null},t.prototype.isEqual=function(e){return e instanceof t},t.instance=new t,t}(),__PRIVATE_ArrayUnionTransformOperation=function(){function t(t){this.elements=t}return t.prototype.zt=function(t,e){return this.apply(t)},t.prototype.Jt=function(t,e){return this.apply(t)},t.prototype.apply=function(t){for(var e=__PRIVATE_coercedFieldValuesArray(t),n=function(t){e.find((function(e){return e.isEqual(t)}))||e.push(t)},r=0,i=this.elements;r<i.length;r++){n(i[r])}return new ArrayValue(e)},t.prototype.Zt=function(t){return null},t.prototype.isEqual=function(e){return e instanceof t&&__PRIVATE_arrayEquals(e.elements,this.elements)},t}(),__PRIVATE_ArrayRemoveTransformOperation=function(){function t(t){this.elements=t}return t.prototype.zt=function(t,e){return this.apply(t)},t.prototype.Jt=function(t,e){return this.apply(t)},t.prototype.apply=function(t){for(var e=__PRIVATE_coercedFieldValuesArray(t),n=function(t){e=e.filter((function(e){return!e.isEqual(t)}))},r=0,i=this.elements;r<i.length;r++){n(i[r])}return new ArrayValue(e)},t.prototype.Zt=function(t){return null},t.prototype.isEqual=function(e){return e instanceof t&&__PRIVATE_arrayEquals(e.elements,this.elements)},t}(),__PRIVATE_NumericIncrementTransformOperation=function(){function t(t){this.te=t}return t.prototype.zt=function(t,e){var n=this.Zt(t);if(n instanceof __PRIVATE_IntegerValue&&this.te instanceof __PRIVATE_IntegerValue){var r=n.ee+this.te.ee;return new __PRIVATE_IntegerValue(r)}r=n.ee+this.te.ee;return new __PRIVATE_DoubleValue(r)},t.prototype.Jt=function(t,e){return assert(null!==e,"Didn't receive transformResult for NUMERIC_ADD transform"),e},t.prototype.Zt=function(t){return t instanceof __PRIVATE_NumberValue?t:new __PRIVATE_IntegerValue(0)},t.prototype.isEqual=function(e){return e instanceof t&&this.te.isEqual(e.te)},t}();function __PRIVATE_coercedFieldValuesArray(t){return t instanceof ArrayValue?t.ee.slice():[]}var __PRIVATE_MutationType,__PRIVATE_FieldMask=function(){function t(t){this.fields=t}return t.ne=function(e){return new t(e)},t.re=function(e){var n=new __PRIVATE_SortedSet(FieldPath.X);return e.forEach((function(t){return n=n.add(t)})),new t(n)},t.prototype.ie=function(t){var e=!1;return this.fields.forEach((function(n){n.it(t)&&(e=!0)})),e},t.prototype.isEqual=function(t){return this.fields.isEqual(t.fields)},t}(),FieldTransform=function(){function t(t,e){this.field=t,this.transform=e}return t.prototype.isEqual=function(t){return this.field.isEqual(t.field)&&this.transform.isEqual(t.transform)},t}(),__PRIVATE_MutationResult=function(t,e){this.version=t,this.transformResults=e};!function(t){t[t.Set=0]="Set",t[t.se=1]="__PRIVATE_Patch",t[t.oe=2]="__PRIVATE_Transform",t[t.ue=3]="__PRIVATE_Delete",t[t.ae=4]="__PRIVATE_Verify"}(__PRIVATE_MutationType||(__PRIVATE_MutationType={}));var __PRIVATE_TypeOrder,__PRIVATE_ServerTimestampBehavior,Precondition=function(){function t(t,e){this.updateTime=t,this.exists=e,assert(void 0===t||void 0===e,'Precondition can specify "exists" or "updateTime" but not both')}return t.exists=function(e){return new t(void 0,e)},t.updateTime=function(e){return new t(e)},Object.defineProperty(t.prototype,"_e",{get:function(){return void 0===this.updateTime&&void 0===this.exists},enumerable:!0,configurable:!0}),t.prototype.ce=function(t){return void 0!==this.updateTime?t instanceof Document&&t.version.isEqual(this.updateTime):void 0!==this.exists?this.exists===t instanceof Document:(assert(this._e,"Precondition should be empty"),!0)},t.prototype.isEqual=function(t){return __PRIVATE_equals(this.updateTime,t.updateTime)&&this.exists===t.exists},t.NONE=new t,t}(),__PRIVATE_Mutation=function(){function t(){}return t.prototype.he=function(t){null!=t&&assert(t.key.isEqual(this.key),"Can only apply a mutation to a document with the same key")},t.fe=function(t){return t instanceof Document?t.version:__PRIVATE_SnapshotVersion.MIN},t}(),__PRIVATE_SetMutation=function(t){function e(e,n,r){var i=t.call(this)||this;return i.key=e,i.value=n,i.le=r,i.type=__PRIVATE_MutationType.Set,i}return tslib.__extends(e,t),e.prototype.Jt=function(t,e){this.he(t),assert(null==e.transformResults,"Transform results received by SetMutation.");var n=e.version;return new Document(this.key,n,{hasCommittedMutations:!0},this.value)},e.prototype.zt=function(t,e,n){if(this.he(t),!this.le.ce(t))return t;var r=__PRIVATE_Mutation.fe(t);return new Document(this.key,r,{de:!0},this.value)},e.prototype.Te=function(t){return null},e.prototype.isEqual=function(t){return t instanceof e&&this.key.isEqual(t.key)&&this.value.isEqual(t.value)&&this.le.isEqual(t.le)},e}(__PRIVATE_Mutation),__PRIVATE_PatchMutation=function(t){function e(e,n,r,i){var s=t.call(this)||this;return s.key=e,s.data=n,s.Ee=r,s.le=i,s.type=__PRIVATE_MutationType.se,s}return tslib.__extends(e,t),e.prototype.Jt=function(t,e){if(this.he(t),assert(null==e.transformResults,"Transform results received by PatchMutation."),!this.le.ce(t))return new __PRIVATE_UnknownDocument(this.key,e.version);var n=this.Pe(t);return new Document(this.key,e.version,{hasCommittedMutations:!0},n)},e.prototype.zt=function(t,e,n){if(this.he(t),!this.le.ce(t))return t;var r=__PRIVATE_Mutation.fe(t),i=this.Pe(t);return new Document(this.key,r,{de:!0},i)},e.prototype.Te=function(t){return null},e.prototype.isEqual=function(t){return t instanceof e&&this.key.isEqual(t.key)&&this.Ee.isEqual(t.Ee)&&this.le.isEqual(t.le)},e.prototype.Pe=function(t){var e;return e=t instanceof Document?t.data():__PRIVATE_ObjectValue.EMPTY,this.Ae(e)},e.prototype.Ae=function(t){var e=this;return this.Ee.fields.forEach((function(n){if(!n.et()){var r=e.data.field(n);t=null!==r?t.set(n,r):t.delete(n)}})),t},e}(__PRIVATE_Mutation),__PRIVATE_TransformMutation=function(t){function e(e,n){var r=t.call(this)||this;return r.key=e,r.fieldTransforms=n,r.type=__PRIVATE_MutationType.oe,r.le=Precondition.exists(!0),r}return tslib.__extends(e,t),e.prototype.Jt=function(t,e){if(this.he(t),assert(null!=e.transformResults,"Transform results missing for TransformMutation."),!this.le.ce(t))return new __PRIVATE_UnknownDocument(this.key,e.version);var n=this.Re(t),r=this.Ie(t,e.transformResults),i=e.version,s=this.Ve(n.data(),r);return new Document(this.key,i,{hasCommittedMutations:!0},s)},e.prototype.zt=function(t,e,n){if(this.he(t),!this.le.ce(t))return t;var r=this.Re(t),i=this.me(n,t,e),s=this.Ve(r.data(),i);return new Document(this.key,r.version,{de:!0},s)},e.prototype.Te=function(t){for(var e=null,n=0,r=this.fieldTransforms;n<r.length;n++){var i=r[n],s=t instanceof Document?t.field(i.field):void 0,o=i.transform.Zt(s||null);null!=o&&(e=null==e?__PRIVATE_ObjectValue.EMPTY.set(i.field,o):e.set(i.field,o))}return e},e.prototype.isEqual=function(t){return t instanceof e&&this.key.isEqual(t.key)&&__PRIVATE_arrayEquals(this.fieldTransforms,t.fieldTransforms)&&this.le.isEqual(t.le)},e.prototype.Re=function(t){return assert(t instanceof Document,"Unknown MaybeDocument type "+t),assert(t.key.isEqual(this.key),"Can only transform a document with the same key"),t},e.prototype.Ie=function(t,e){var n=[];assert(this.fieldTransforms.length===e.length,"server transform result count ("+e.length+") should match field transform count ("+this.fieldTransforms.length+")");for(var r=0;r<e.length;r++){var i=this.fieldTransforms[r],s=i.transform,o=null;t instanceof Document&&(o=t.field(i.field)),n.push(s.Jt(o,e[r]))}return n},e.prototype.me=function(t,e,n){for(var r=[],i=0,s=this.fieldTransforms;i<s.length;i++){var o=s[i],u=o.transform,a=null;e instanceof Document&&(a=e.field(o.field)),null===a&&n instanceof Document&&(a=n.field(o.field)),r.push(u.zt(a,t))}return r},e.prototype.Ve=function(t,e){assert(e.length===this.fieldTransforms.length,"TransformResults length mismatch.");for(var n=0;n<this.fieldTransforms.length;n++){var r=this.fieldTransforms[n].field;t=t.set(r,e[n])}return t},e}(__PRIVATE_Mutation),__PRIVATE_DeleteMutation=function(t){function e(e,n){var r=t.call(this)||this;return r.key=e,r.le=n,r.type=__PRIVATE_MutationType.ue,r}return tslib.__extends(e,t),e.prototype.Jt=function(t,e){return this.he(t),assert(null==e.transformResults,"Transform results received by DeleteMutation."),new __PRIVATE_NoDocument(this.key,e.version,{hasCommittedMutations:!0})},e.prototype.zt=function(t,e,n){return this.he(t),this.le.ce(t)?(t&&assert(t.key.isEqual(this.key),"Can only apply mutation to document with same key"),new __PRIVATE_NoDocument(this.key,__PRIVATE_SnapshotVersion.W())):t},e.prototype.Te=function(t){return null},e.prototype.isEqual=function(t){return t instanceof e&&this.key.isEqual(t.key)&&this.le.isEqual(t.le)},e}(__PRIVATE_Mutation),__PRIVATE_VerifyMutation=function(t){function e(e,n){var r=t.call(this)||this;return r.key=e,r.le=n,r.type=__PRIVATE_MutationType.ae,r}return tslib.__extends(e,t),e.prototype.Jt=function(t,e){fail("VerifyMutation should only be used in Transactions.")},e.prototype.zt=function(t,e,n){fail("VerifyMutation should only be used in Transactions.")},e.prototype.Te=function(t){fail("VerifyMutation should only be used in Transactions.")},e.prototype.isEqual=function(t){return t instanceof e&&this.key.isEqual(t.key)&&this.le.isEqual(t.le)},e}(__PRIVATE_Mutation);!function(t){t[t.ve=0]="__PRIVATE_NullValue",t[t.pe=1]="__PRIVATE_BooleanValue",t[t.be=2]="__PRIVATE_NumberValue",t[t.ge=3]="__PRIVATE_TimestampValue",t[t.we=4]="__PRIVATE_StringValue",t[t.ye=5]="__PRIVATE_BlobValue",t[t.Se=6]="__PRIVATE_RefValue",t[t.De=7]="__PRIVATE_GeoPointValue",t[t.ArrayValue=8]="ArrayValue",t[t.Ce=9]="__PRIVATE_ObjectValue"}(__PRIVATE_TypeOrder||(__PRIVATE_TypeOrder={})),function(t){t[t.Oe=0]="__PRIVATE_Default",t[t.Fe=1]="__PRIVATE_Estimate",t[t.Ne=2]="__PRIVATE_Previous"}(__PRIVATE_ServerTimestampBehavior||(__PRIVATE_ServerTimestampBehavior={}));var __PRIVATE_FieldValueOptions=function(){function t(t,e){this.Me=t,this.timestampsInSnapshots=e}return t.Le=function(e,n){switch(e.serverTimestamps){case"estimate":return new t(__PRIVATE_ServerTimestampBehavior.Fe,n);case"previous":return new t(__PRIVATE_ServerTimestampBehavior.Ne,n);case"none":case void 0:return new t(__PRIVATE_ServerTimestampBehavior.Oe,n);default:return fail("fromSnapshotOptions() called with invalid options.")}},t}(),FieldValue=function(){function t(){}return t.prototype.toString=function(){var t=this.value();return null===t?"null":t.toString()},t.prototype.Ge=function(t){return assert(this.Be!==t.Be,"Default compareTo should not be used for values of same type."),__PRIVATE_primitiveComparator(this.Be,t.Be)},t}(),__PRIVATE_NullValue=function(t){function e(){var e=t.call(this)||this;return e.Be=__PRIVATE_TypeOrder.ve,e.ee=null,e}return tslib.__extends(e,t),e.prototype.value=function(t){return null},e.prototype.isEqual=function(t){return t instanceof e},e.prototype._=function(t){return t instanceof e?0:this.Ge(t)},e.prototype.Ue=function(){return 4},e.ke=new e,e}(FieldValue),__PRIVATE_BooleanValue=function(t){function e(e){var n=t.call(this)||this;return n.ee=e,n.Be=__PRIVATE_TypeOrder.pe,n}return tslib.__extends(e,t),e.prototype.value=function(t){return this.ee},e.prototype.isEqual=function(t){return t instanceof e&&this.ee===t.ee},e.prototype._=function(t){return t instanceof e?__PRIVATE_primitiveComparator(this,t):this.Ge(t)},e.prototype.Ue=function(){return 4},e.of=function(t){return t?e.xe:e.Ke},e.xe=new e(!0),e.Ke=new e(!1),e}(FieldValue),__PRIVATE_NumberValue=function(t){function e(e){var n=t.call(this)||this;return n.ee=e,n.Be=__PRIVATE_TypeOrder.be,n}return tslib.__extends(e,t),e.prototype.value=function(t){return this.ee},e.prototype._=function(t){return t instanceof e?__PRIVATE_numericComparator(this.ee,t.ee):this.Ge(t)},e.prototype.Ue=function(){return 8},e}(FieldValue);function __PRIVATE_numericComparator(t,e){return t<e?-1:t>e?1:t===e?0:isNaN(t)?isNaN(e)?0:-1:1}function __PRIVATE_numericEquals(t,e){return t===e?0!==t||1/t==1/e:t!=t&&e!=e}var __PRIVATE_IntegerValue=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return tslib.__extends(e,t),e.prototype.isEqual=function(t){return t instanceof e&&__PRIVATE_numericEquals(this.ee,t.ee)},e}(__PRIVATE_NumberValue),__PRIVATE_DoubleValue=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return tslib.__extends(e,t),e.prototype.isEqual=function(t){return t instanceof e&&__PRIVATE_numericEquals(this.ee,t.ee)},e.je=new e(NaN),e.POSITIVE_INFINITY=new e(1/0),e.NEGATIVE_INFINITY=new e(-1/0),e}(__PRIVATE_NumberValue),__PRIVATE_StringValue=function(t){function e(e){var n=t.call(this)||this;return n.ee=e,n.Be=__PRIVATE_TypeOrder.we,n}return tslib.__extends(e,t),e.prototype.value=function(t){return this.ee},e.prototype.isEqual=function(t){return t instanceof e&&this.ee===t.ee},e.prototype._=function(t){return t instanceof e?__PRIVATE_primitiveComparator(this.ee,t.ee):this.Ge(t)},e.prototype.Ue=function(){return 2*this.ee.length},e}(FieldValue),__PRIVATE_TimestampValue=function(t){function e(e){var n=t.call(this)||this;return n.ee=e,n.Be=__PRIVATE_TypeOrder.ge,n}return tslib.__extends(e,t),e.prototype.value=function(t){return!t||t.timestampsInSnapshots?this.ee:this.ee.toDate()},e.prototype.isEqual=function(t){return t instanceof e&&this.ee.isEqual(t.ee)},e.prototype._=function(t){return t instanceof e?this.ee.K(t.ee):t instanceof __PRIVATE_ServerTimestampValue?-1:this.Ge(t)},e.prototype.Ue=function(){return 16},e}(FieldValue),__PRIVATE_ServerTimestampValue=function(t){function e(e,n){var r=t.call(this)||this;return r.qe=e,r.previousValue=n,r.Be=__PRIVATE_TypeOrder.ge,r}return tslib.__extends(e,t),e.prototype.value=function(t){return t&&t.Me===__PRIVATE_ServerTimestampBehavior.Fe?new __PRIVATE_TimestampValue(this.qe).value(t):t&&t.Me===__PRIVATE_ServerTimestampBehavior.Ne&&this.previousValue?this.previousValue.value(t):null},e.prototype.isEqual=function(t){return t instanceof e&&this.qe.isEqual(t.qe)},e.prototype._=function(t){return t instanceof e?this.qe.K(t.qe):t instanceof __PRIVATE_TimestampValue?1:this.Ge(t)},e.prototype.toString=function(){return"<ServerTimestamp localTime="+this.qe.toString()+">"},e.prototype.Ue=function(){return 16+(this.previousValue?this.previousValue.Ue():0)},e}(FieldValue),__PRIVATE_BlobValue=function(t){function e(e){var n=t.call(this)||this;return n.ee=e,n.Be=__PRIVATE_TypeOrder.ye,n}return tslib.__extends(e,t),e.prototype.value=function(t){return this.ee},e.prototype.isEqual=function(t){return t instanceof e&&this.ee.isEqual(t.ee)},e.prototype._=function(t){return t instanceof e?this.ee.K(t.ee):this.Ge(t)},e.prototype.Ue=function(){return this.ee.Qe()},e}(FieldValue),__PRIVATE_RefValue=function(t){function e(e,n){var r=t.call(this)||this;return r.o=e,r.key=n,r.Be=__PRIVATE_TypeOrder.Se,r}return tslib.__extends(e,t),e.prototype.value=function(t){return this.key},e.prototype.isEqual=function(t){return t instanceof e&&(this.key.isEqual(t.key)&&this.o.isEqual(t.o))},e.prototype._=function(t){if(t instanceof e){var n=this.o._(t.o);return 0!==n?n:__PRIVATE_DocumentKey.X(this.key,t.key)}return this.Ge(t)},e.prototype.Ue=function(){return this.o.projectId.length+this.o.database.length+this.key.toString().length},e}(FieldValue),__PRIVATE_GeoPointValue=function(t){function e(e){var n=t.call(this)||this;return n.ee=e,n.Be=__PRIVATE_TypeOrder.De,n}return tslib.__extends(e,t),e.prototype.value=function(t){return this.ee},e.prototype.isEqual=function(t){return t instanceof e&&this.ee.isEqual(t.ee)},e.prototype._=function(t){return t instanceof e?this.ee.K(t.ee):this.Ge(t)},e.prototype.Ue=function(){return 16},e}(FieldValue),__PRIVATE_ObjectValue=function(t){function e(e){var n=t.call(this)||this;return n.ee=e,n.Be=__PRIVATE_TypeOrder.Ce,n}return tslib.__extends(e,t),e.prototype.value=function(t){var e={};return this.ee.pt((function(n,r){e[n]=r.value(t)})),e},e.prototype.forEach=function(t){this.ee.pt(t)},e.prototype.isEqual=function(t){if(t instanceof e){for(var n=this.ee.gt(),r=t.ee.gt();n.Ft()&&r.Ft();){var i=n.Ot(),s=r.Ot();if(i.key!==s.key||!i.value.isEqual(s.value))return!1}return!n.Ft()&&!r.Ft()}return!1},e.prototype._=function(t){if(t instanceof e){for(var n=this.ee.gt(),r=t.ee.gt();n.Ft()&&r.Ft();){var i=n.Ot(),s=r.Ot(),o=__PRIVATE_primitiveComparator(i.key,s.key)||i.value._(s.value);if(o)return o}return __PRIVATE_primitiveComparator(n.Ft(),r.Ft())}return this.Ge(t)},e.prototype.set=function(t,n){if(assert(!t.et(),"Cannot set field for empty path on ObjectValue"),1===t.length)return this.We(t.nt(),n);var r=this.child(t.nt());r instanceof e||(r=e.EMPTY);var i=r.set(t.Z(),n);return this.We(t.nt(),i)},e.prototype.delete=function(t){if(assert(!t.et(),"Cannot delete field for empty path on ObjectValue"),1===t.length)return new e(this.ee.remove(t.nt()));var n=this.child(t.nt());if(n instanceof e){var r=n.delete(t.Z());return new e(this.ee.At(t.nt(),r))}return this},e.prototype.contains=function(t){return null!==this.field(t)},e.prototype.field=function(t){assert(!t.et(),"Can't get field of empty path");var n=this;return t.forEach((function(t){n=n instanceof e?n.ee.get(t):null})),n},e.prototype.Ee=function(){var t=new __PRIVATE_SortedSet(FieldPath.X);return this.ee.forEach((function(n,r){var i=new FieldPath([n]);if(r instanceof e){var s=r.Ee().fields;s.et()?t=t.add(i):s.forEach((function(e){t=t.add(i.child(e))}))}else t=t.add(i)})),__PRIVATE_FieldMask.ne(t)},e.prototype.Ue=function(){var t=0;return this.ee.pt((function(e,n){t+=e.length+n.Ue()})),t},e.prototype.toString=function(){return this.ee.toString()},e.prototype.child=function(t){return this.ee.get(t)||void 0},e.prototype.We=function(t,n){return new e(this.ee.At(t,n))},e.EMPTY=new e(new __PRIVATE_SortedMap(__PRIVATE_primitiveComparator)),e}(FieldValue),ArrayValue=function(t){function e(e){var n=t.call(this)||this;return n.ee=e,n.Be=__PRIVATE_TypeOrder.ArrayValue,n}return tslib.__extends(e,t),e.prototype.value=function(t){return this.ee.map((function(e){return e.value(t)}))},e.prototype.contains=function(t){for(var e=0,n=this.ee;e<n.length;e++){if(n[e].isEqual(t))return!0}return!1},e.prototype.forEach=function(t){this.ee.forEach(t)},e.prototype.isEqual=function(t){if(t instanceof e){if(this.ee.length!==t.ee.length)return!1;for(var n=0;n<this.ee.length;n++)if(!this.ee[n].isEqual(t.ee[n]))return!1;return!0}return!1},e.prototype._=function(t){if(t instanceof e){for(var n=Math.min(this.ee.length,t.ee.length),r=0;r<n;r++){var i=this.ee[r]._(t.ee[r]);if(i)return i}return __PRIVATE_primitiveComparator(this.ee.length,t.ee.length)}return this.Ge(t)},e.prototype.Ue=function(){return this.ee.reduce((function(t,e){return t+e.Ue()}),0)},e.prototype.toString=function(){return"["+this.ee.map((function(t){return t.toString()})).join(",")+"]"},e}(FieldValue),__PRIVATE_MaybeDocument=function(){function t(t,e){this.key=t,this.version=e}return t.$e=function(t,e){return __PRIVATE_DocumentKey.X(t.key,e.key)},t}(),Document=function(t){function e(e,n,r,i,s,o){var u=t.call(this,e,n)||this;return u.Ye=i,u.proto=s,u.converter=o,assert(void 0!==u.Ye||void 0!==u.proto&&void 0!==u.converter,"If objectValue is not defined, proto and converter need to be set."),u.de=!!r.de,u.hasCommittedMutations=!!r.hasCommittedMutations,u}return tslib.__extends(e,t),e.prototype.field=function(t){if(this.Ye)return this.Ye.field(t);this.He||(this.He=new Map);var e=t.ut(),n=this.He.get(e);if(void 0===n){var r=this.Xe(t);n=void 0===r?null:this.converter(r),this.He.set(e,n)}return n},e.prototype.data=function(){var t=this;if(!this.Ye){var e=__PRIVATE_ObjectValue.EMPTY;forEach(this.proto.fields||{},(function(n,r){e=e.set(new FieldPath([n]),t.converter(r))})),this.Ye=e,this.He=void 0}return this.Ye},e.prototype.value=function(){return this.data().value()},e.prototype.isEqual=function(t){return t instanceof e&&this.key.isEqual(t.key)&&this.version.isEqual(t.version)&&this.de===t.de&&this.hasCommittedMutations===t.hasCommittedMutations&&this.data().isEqual(t.data())},e.prototype.toString=function(){return"Document("+this.key+", "+this.version+", "+this.data().toString()+", {hasLocalMutations: "+this.de+"}), {hasCommittedMutations: "+this.hasCommittedMutations+"})"},Object.defineProperty(e.prototype,"hasPendingWrites",{get:function(){return this.de||this.hasCommittedMutations},enumerable:!0,configurable:!0}),e.prototype.Xe=function(t){assert(void 0!==this.proto,"Can only call getProtoField() when proto is defined");for(var e=this.proto.fields?this.proto.fields[t.nt()]:void 0,n=1;n<t.length;++n){if(!e||!e.mapValue||!e.mapValue.fields)return;e=e.mapValue.fields[t.get(n)]}return e},e.ze=function(t,e,n){var r=e.field(t),i=n.field(t);return null!==r&&null!==i?r._(i):fail("Trying to compare documents on fields that don't exist")},e}(__PRIVATE_MaybeDocument),__PRIVATE_NoDocument=function(t){function e(e,n,r){var i=t.call(this,e,n)||this;return i.hasCommittedMutations=!(!r||!r.hasCommittedMutations),i}return tslib.__extends(e,t),e.prototype.toString=function(){return"NoDocument("+this.key+", "+this.version+")"},Object.defineProperty(e.prototype,"hasPendingWrites",{get:function(){return this.hasCommittedMutations},enumerable:!0,configurable:!0}),e.prototype.isEqual=function(t){return t instanceof e&&t.hasCommittedMutations===this.hasCommittedMutations&&t.version.isEqual(this.version)&&t.key.isEqual(this.key)},e}(__PRIVATE_MaybeDocument),__PRIVATE_UnknownDocument=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return tslib.__extends(e,t),e.prototype.toString=function(){return"UnknownDocument("+this.key+", "+this.version+")"},Object.defineProperty(e.prototype,"hasPendingWrites",{get:function(){return!0},enumerable:!0,configurable:!0}),e.prototype.isEqual=function(t){return t instanceof e&&t.version.isEqual(this.version)&&t.key.isEqual(this.key)},e}(__PRIVATE_MaybeDocument),__PRIVATE_NumberAsAny=Number,MIN_SAFE_INTEGER=__PRIVATE_NumberAsAny.MIN_SAFE_INTEGER||-(Math.pow(2,53)-1),MAX_SAFE_INTEGER=__PRIVATE_NumberAsAny.MAX_SAFE_INTEGER||Math.pow(2,53)-1,isInteger=__PRIVATE_NumberAsAny.isInteger||function(t){return"number"==typeof t&&isFinite(t)&&Math.floor(t)===t};function __PRIVATE_isNullOrUndefined(t){return null==t}function isSafeInteger(t){return isInteger(t)&&t<=MAX_SAFE_INTEGER&&t>=MIN_SAFE_INTEGER}var __PRIVATE_LimitType,Target=function(){function t(t,e,n,r,i,s,o){void 0===e&&(e=null),void 0===n&&(n=[]),void 0===r&&(r=[]),void 0===i&&(i=null),void 0===s&&(s=null),void 0===o&&(o=null),this.path=t,this.collectionGroup=e,this.orderBy=n,this.filters=r,this.limit=i,this.startAt=s,this.endAt=o,this.Je=null}return t.prototype.canonicalId=function(){if(null===this.Je){var t=this.path.ut();null!==this.collectionGroup&&(t+="|cg:"+this.collectionGroup),t+="|f:";for(var e=0,n=this.filters;e<n.length;e++){t+=n[e].canonicalId(),t+=","}t+="|ob:";for(var r=0,i=this.orderBy;r<i.length;r++){t+=i[r].canonicalId(),t+=","}__PRIVATE_isNullOrUndefined(this.limit)||(t+="|l:",t+=this.limit),this.startAt&&(t+="|lb:",t+=this.startAt.canonicalId()),this.endAt&&(t+="|ub:",t+=this.endAt.canonicalId()),this.Je=t}return this.Je},t.prototype.toString=function(){var t=this.path.ut();return null!==this.collectionGroup&&(t+=" collectionGroup="+this.collectionGroup),this.filters.length>0&&(t+=", filters: ["+this.filters.join(", ")+"]"),__PRIVATE_isNullOrUndefined(this.limit)||(t+=", limit: "+this.limit),this.orderBy.length>0&&(t+=", orderBy: ["+this.orderBy.join(", ")+"]"),this.startAt&&(t+=", startAt: "+this.startAt.canonicalId()),this.endAt&&(t+=", endAt: "+this.endAt.canonicalId()),"Target("+t+")"},t.prototype.isEqual=function(t){if(this.limit!==t.limit)return!1;if(this.orderBy.length!==t.orderBy.length)return!1;for(var e=0;e<this.orderBy.length;e++)if(!this.orderBy[e].isEqual(t.orderBy[e]))return!1;if(this.filters.length!==t.filters.length)return!1;for(e=0;e<this.filters.length;e++)if(!this.filters[e].isEqual(t.filters[e]))return!1;return this.collectionGroup===t.collectionGroup&&(!!this.path.isEqual(t.path)&&(!(null!==this.startAt?!this.startAt.isEqual(t.startAt):null!==t.startAt)&&(null!==this.endAt?this.endAt.isEqual(t.endAt):null===t.endAt)))},t.prototype.Ze=function(){return __PRIVATE_DocumentKey.dt(this.path)&&null===this.collectionGroup&&0===this.filters.length},t}();!function(t){t.tn="F",t.en="L"}(__PRIVATE_LimitType||(__PRIVATE_LimitType={}));var __PRIVATE_TargetPurpose,Query=function(){function t(t,e,n,r,i,s,o,u){void 0===e&&(e=null),void 0===n&&(n=[]),void 0===r&&(r=[]),void 0===i&&(i=null),void 0===s&&(s=__PRIVATE_LimitType.tn),void 0===o&&(o=null),void 0===u&&(u=null),this.path=t,this.collectionGroup=e,this.nn=n,this.filters=r,this.limit=i,this.rn=s,this.startAt=o,this.endAt=u,this.in=null,this.sn=null,this.startAt&&this.on(this.startAt),this.endAt&&this.on(this.endAt)}return t.un=function(e){return new t(e)},Object.defineProperty(t.prototype,"orderBy",{get:function(){if(null===this.in){var t=this.an(),e=this._n();if(null!==t&&null===e)t.ht()?this.in=[__PRIVATE_KEY_ORDERING_ASC]:this.in=[new __PRIVATE_OrderBy(t),__PRIVATE_KEY_ORDERING_ASC];else{assert(null===t||null!==e&&t.isEqual(e),"First orderBy should match inequality field."),this.in=[];for(var n=!1,r=0,i=this.nn;r<i.length;r++){var s=i[r];this.in.push(s),s.field.ht()&&(n=!0)}if(!n){var o=this.nn.length>0?this.nn[this.nn.length-1].dir:__PRIVATE_Direction.ASCENDING;this.in.push(o===__PRIVATE_Direction.ASCENDING?__PRIVATE_KEY_ORDERING_ASC:__PRIVATE_KEY_ORDERING_DESC)}}}return this.in},enumerable:!0,configurable:!0}),t.prototype.cn=function(e){assert(null==this.an()||!(e instanceof FieldFilter)||!e.hn()||e.field.isEqual(this.an()),"Query must only have one inequality field."),assert(!this.Ze(),"No filtering allowed for document query");var n=this.filters.concat([e]);return new t(this.path,this.collectionGroup,this.nn.slice(),n,this.limit,this.rn,this.startAt,this.endAt)},t.prototype.fn=function(e){assert(!this.startAt&&!this.endAt,"Bounds must be set after orderBy");var n=this.nn.concat([e]);return new t(this.path,this.collectionGroup,n,this.filters.slice(),this.limit,this.rn,this.startAt,this.endAt)},t.prototype.ln=function(e){return new t(this.path,this.collectionGroup,this.nn.slice(),this.filters.slice(),e,__PRIVATE_LimitType.tn,this.startAt,this.endAt)},t.prototype.dn=function(e){return new t(this.path,this.collectionGroup,this.nn.slice(),this.filters.slice(),e,__PRIVATE_LimitType.en,this.startAt,this.endAt)},t.prototype.Tn=function(e){return new t(this.path,this.collectionGroup,this.nn.slice(),this.filters.slice(),this.limit,this.rn,e,this.endAt)},t.prototype.En=function(e){return new t(this.path,this.collectionGroup,this.nn.slice(),this.filters.slice(),this.limit,this.rn,this.startAt,e)},t.prototype.Pn=function(e){return new t(e,null,this.nn.slice(),this.filters.slice(),this.limit,this.rn,this.startAt,this.endAt)},t.prototype.An=function(){return 0===this.filters.length&&null===this.limit&&null==this.startAt&&null==this.endAt&&(0===this.nn.length||1===this.nn.length&&this.nn[0].field.ht())},t.prototype.canonicalId=function(){return this.Rn().canonicalId()+"|lt:"+this.rn},t.prototype.toString=function(){return"Query(target="+this.Rn().toString()+"; limitType="+this.rn+")"},t.prototype.isEqual=function(t){return this.Rn().isEqual(t.Rn())&&this.rn===t.rn},t.prototype.In=function(t,e){for(var n=!1,r=0,i=this.orderBy;r<i.length;r++){var s=i[r],o=s.compare(t,e);if(0!==o)return o;n=n||s.field.ht()}return assert(n,"orderBy used that doesn't compare on key field"),0},t.prototype.matches=function(t){return this.Vn(t)&&this.mn(t)&&this.vn(t)&&this.pn(t)},t.prototype.bn=function(){return!__PRIVATE_isNullOrUndefined(this.limit)&&this.rn===__PRIVATE_LimitType.tn},t.prototype.gn=function(){return!__PRIVATE_isNullOrUndefined(this.limit)&&this.rn===__PRIVATE_LimitType.en},t.prototype._n=function(){return this.nn.length>0?this.nn[0].field:null},t.prototype.an=function(){for(var t=0,e=this.filters;t<e.length;t++){var n=e[t];if(n instanceof FieldFilter&&n.hn())return n.field}return null},t.prototype.wn=function(t){for(var e=0,n=this.filters;e<n.length;e++){var r=n[e];if(r instanceof FieldFilter&&t.indexOf(r.op)>=0)return r.op}return null},t.prototype.Ze=function(){return this.Rn().Ze()},t.prototype.yn=function(){return null!==this.collectionGroup},t.prototype.Rn=function(){if(!this.sn)if(this.rn===__PRIVATE_LimitType.tn)this.sn=new Target(this.path,this.collectionGroup,this.orderBy,this.filters,this.limit,this.startAt,this.endAt);else{for(var t=[],e=0,n=this.orderBy;e<n.length;e++){var r=n[e],i=r.dir===__PRIVATE_Direction.DESCENDING?__PRIVATE_Direction.ASCENDING:__PRIVATE_Direction.DESCENDING;t.push(new __PRIVATE_OrderBy(r.field,i))}var s=this.endAt?new __PRIVATE_Bound(this.endAt.position,!this.endAt.before):null,o=this.startAt?new __PRIVATE_Bound(this.startAt.position,!this.startAt.before):null;this.sn=new Target(this.path,this.collectionGroup,t,this.filters,this.limit,s,o)}return this.sn},t.prototype.Vn=function(t){var e=t.key.path;return null!==this.collectionGroup?t.key.Tt(this.collectionGroup)&&this.path.it(e):__PRIVATE_DocumentKey.dt(this.path)?this.path.isEqual(e):this.path.st(e)},t.prototype.mn=function(t){for(var e=0,n=this.nn;e<n.length;e++){var r=n[e];if(!r.field.ht()&&null===t.field(r.field))return!1}return!0},t.prototype.vn=function(t){for(var e=0,n=this.filters;e<n.length;e++){if(!n[e].matches(t))return!1}return!0},t.prototype.pn=function(t){return!(this.startAt&&!this.startAt.Sn(this.orderBy,t))&&(!this.endAt||!this.endAt.Sn(this.orderBy,t))},t.prototype.on=function(t){assert(t.position.length<=this.orderBy.length,"Bound is longer than orderBy")},t}(),Filter=function(){},__PRIVATE_Operator=function(){function t(t){this.name=t}return t.at=function(e){switch(e){case"<":return t.LESS_THAN;case"<=":return t.LESS_THAN_OR_EQUAL;case"==":return t.EQUAL;case">=":return t.GREATER_THAN_OR_EQUAL;case">":return t.GREATER_THAN;case"array-contains":return t.ARRAY_CONTAINS;case"in":return t.IN;case"array-contains-any":return t.ARRAY_CONTAINS_ANY;default:return fail("Unknown FieldFilter operator: "+e)}},t.prototype.toString=function(){return this.name},t.prototype.isEqual=function(t){return this.name===t.name},t.LESS_THAN=new t("<"),t.LESS_THAN_OR_EQUAL=new t("<="),t.EQUAL=new t("=="),t.GREATER_THAN=new t(">"),t.GREATER_THAN_OR_EQUAL=new t(">="),t.ARRAY_CONTAINS=new t("array-contains"),t.IN=new t("in"),t.ARRAY_CONTAINS_ANY=new t("array-contains-any"),t}(),FieldFilter=function(t){function e(e,n,r){var i=t.call(this)||this;return i.field=e,i.op=n,i.value=r,i}return tslib.__extends(e,t),e.create=function(t,n,r){if(t.ht())return n===__PRIVATE_Operator.IN?(assert(r instanceof ArrayValue,"Comparing on key with IN, but filter value not an ArrayValue"),assert(r.ee.every((function(t){return t instanceof __PRIVATE_RefValue})),"Comparing on key with IN, but an array value was not a RefValue"),new __PRIVATE_KeyFieldInFilter(t,r)):(assert(r instanceof __PRIVATE_RefValue,"Comparing on key, but filter value not a RefValue"),assert(n!==__PRIVATE_Operator.ARRAY_CONTAINS&&n!==__PRIVATE_Operator.ARRAY_CONTAINS_ANY,"'"+n.toString()+"' queries don't make sense on document keys."),new __PRIVATE_KeyFieldFilter(t,n,r));if(r.isEqual(__PRIVATE_NullValue.ke)){if(n!==__PRIVATE_Operator.EQUAL)throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid query. Null supports only equality comparisons.");return new e(t,n,r)}if(r.isEqual(__PRIVATE_DoubleValue.je)){if(n!==__PRIVATE_Operator.EQUAL)throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid query. NaN supports only equality comparisons.");return new e(t,n,r)}return n===__PRIVATE_Operator.ARRAY_CONTAINS?new __PRIVATE_ArrayContainsFilter(t,r):n===__PRIVATE_Operator.IN?(assert(r instanceof ArrayValue,"IN filter has invalid value: "+r.toString()),new __PRIVATE_InFilter(t,r)):n===__PRIVATE_Operator.ARRAY_CONTAINS_ANY?(assert(r instanceof ArrayValue,"ARRAY_CONTAINS_ANY filter has invalid value: "+r.toString()),new __PRIVATE_ArrayContainsAnyFilter(t,r)):new e(t,n,r)},e.prototype.matches=function(t){var e=t.field(this.field);return null!==e&&this.value.Be===e.Be&&this.Dn(e._(this.value))},e.prototype.Dn=function(t){switch(this.op){case __PRIVATE_Operator.LESS_THAN:return t<0;case __PRIVATE_Operator.LESS_THAN_OR_EQUAL:return t<=0;case __PRIVATE_Operator.EQUAL:return 0===t;case __PRIVATE_Operator.GREATER_THAN:return t>0;case __PRIVATE_Operator.GREATER_THAN_OR_EQUAL:return t>=0;default:return fail("Unknown FieldFilter operator: "+this.op)}},e.prototype.hn=function(){return[__PRIVATE_Operator.LESS_THAN,__PRIVATE_Operator.LESS_THAN_OR_EQUAL,__PRIVATE_Operator.GREATER_THAN,__PRIVATE_Operator.GREATER_THAN_OR_EQUAL].indexOf(this.op)>=0},e.prototype.canonicalId=function(){return this.field.ut()+this.op.toString()+this.value.toString()},e.prototype.isEqual=function(t){return t instanceof e&&(this.op.isEqual(t.op)&&this.field.isEqual(t.field)&&this.value.isEqual(t.value))},e.prototype.toString=function(){return this.field.ut()+" "+this.op+" "+this.value.value()},e}(Filter),__PRIVATE_KeyFieldFilter=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return tslib.__extends(e,t),e.prototype.matches=function(t){var e=this.value,n=__PRIVATE_DocumentKey.X(t.key,e.key);return this.Dn(n)},e}(FieldFilter),__PRIVATE_KeyFieldInFilter=function(t){function e(e,n){var r=t.call(this,e,__PRIVATE_Operator.IN,n)||this;return r.value=n,r}return tslib.__extends(e,t),e.prototype.matches=function(t){return this.value.ee.some((function(e){return t.key.isEqual(e.key)}))},e}(FieldFilter),__PRIVATE_ArrayContainsFilter=function(t){function e(e,n){return t.call(this,e,__PRIVATE_Operator.ARRAY_CONTAINS,n)||this}return tslib.__extends(e,t),e.prototype.matches=function(t){var e=t.field(this.field);return e instanceof ArrayValue&&e.contains(this.value)},e}(FieldFilter),__PRIVATE_InFilter=function(t){function e(e,n){var r=t.call(this,e,__PRIVATE_Operator.IN,n)||this;return r.value=n,r}return tslib.__extends(e,t),e.prototype.matches=function(t){var e=this.value,n=t.field(this.field);return null!==n&&e.contains(n)},e}(FieldFilter),__PRIVATE_ArrayContainsAnyFilter=function(t){function e(e,n){var r=t.call(this,e,__PRIVATE_Operator.ARRAY_CONTAINS_ANY,n)||this;return r.value=n,r}return tslib.__extends(e,t),e.prototype.matches=function(t){var e=this,n=t.field(this.field);return n instanceof ArrayValue&&n.ee.some((function(t){return e.value.contains(t)}))},e}(FieldFilter),__PRIVATE_Direction=function(){function t(t){this.name=t}return t.prototype.toString=function(){return this.name},t.ASCENDING=new t("asc"),t.DESCENDING=new t("desc"),t}(),__PRIVATE_Bound=function(){function t(t,e){this.position=t,this.before=e}return t.prototype.canonicalId=function(){for(var t=this.before?"b:":"a:",e=0,n=this.position;e<n.length;e++){t+=n[e].toString()}return t},t.prototype.Sn=function(t,e){assert(this.position.length<=t.length,"Bound has more components than query's orderBy");for(var n=0,r=0;r<this.position.length;r++){var i=t[r],s=this.position[r];if(i.field.ht())assert(s instanceof __PRIVATE_RefValue,"Bound has a non-key value where the key path is being used."),n=__PRIVATE_DocumentKey.X(s.key,e.key);else{var o=e.field(i.field);assert(null!==o,"Field should exist since document matched the orderBy already."),n=s._(o)}if(i.dir===__PRIVATE_Direction.DESCENDING&&(n*=-1),0!==n)break}return this.before?n<=0:n<0},t.prototype.isEqual=function(t){if(null===t)return!1;if(this.before!==t.before||this.position.length!==t.position.length)return!1;for(var e=0;e<this.position.length;e++){var n=this.position[e],r=t.position[e];if(!n.isEqual(r))return!1}return!0},t}(),__PRIVATE_OrderBy=function(){function t(t,e){this.field=t,void 0===e&&(e=__PRIVATE_Direction.ASCENDING),this.dir=e,this.Cn=t.ht()}return t.prototype.compare=function(t,e){var n=this.Cn?Document.$e(t,e):Document.ze(this.field,t,e);switch(this.dir){case __PRIVATE_Direction.ASCENDING:return n;case __PRIVATE_Direction.DESCENDING:return-1*n;default:return fail("Unknown direction: "+this.dir)}},t.prototype.canonicalId=function(){return this.field.ut()+this.dir.toString()},t.prototype.toString=function(){return this.field.ut()+" ("+this.dir+")"},t.prototype.isEqual=function(t){return this.dir===t.dir&&this.field.isEqual(t.field)},t}(),__PRIVATE_KEY_ORDERING_ASC=new __PRIVATE_OrderBy(FieldPath.ft(),__PRIVATE_Direction.ASCENDING),__PRIVATE_KEY_ORDERING_DESC=new __PRIVATE_OrderBy(FieldPath.ft(),__PRIVATE_Direction.DESCENDING);!function(t){t[t.On=0]="__PRIVATE_Listen",t[t.Fn=1]="__PRIVATE_ExistenceFilterMismatch",t[t.Nn=2]="__PRIVATE_LimboResolution"}(__PRIVATE_TargetPurpose||(__PRIVATE_TargetPurpose={}));var __PRIVATE_RpcCode,__PRIVATE_TargetData=function(){function t(t,e,n,r,i,s,o){void 0===i&&(i=__PRIVATE_SnapshotVersion.MIN),void 0===s&&(s=__PRIVATE_SnapshotVersion.MIN),void 0===o&&(o=__PRIVATE_emptyByteString()),this.target=t,this.targetId=e,this.Mn=n,this.sequenceNumber=r,this.Ln=i,this.lastLimboFreeSnapshotVersion=s,this.resumeToken=o}return t.prototype.Gn=function(e){return new t(this.target,this.targetId,this.Mn,e,this.Ln,this.lastLimboFreeSnapshotVersion,this.resumeToken)},t.prototype.Bn=function(e,n){return new t(this.target,this.targetId,this.Mn,this.sequenceNumber,n,this.lastLimboFreeSnapshotVersion,e)},t.prototype.Un=function(e){return new t(this.target,this.targetId,this.Mn,this.sequenceNumber,this.Ln,e,this.resumeToken)},t.prototype.isEqual=function(t){return this.targetId===t.targetId&&this.Mn===t.Mn&&this.sequenceNumber===t.sequenceNumber&&this.Ln.isEqual(t.Ln)&&this.lastLimboFreeSnapshotVersion.isEqual(t.lastLimboFreeSnapshotVersion)&&this.resumeToken===t.resumeToken&&this.target.isEqual(t.target)},t}(),ExistenceFilter=function(){function t(t){this.count=t}return t.prototype.isEqual=function(t){return t&&t.count===this.count},t}();function __PRIVATE_isPermanentError(t){switch(t){case Code.OK:return fail("Treated status OK as error");case Code.CANCELLED:case Code.UNKNOWN:case Code.DEADLINE_EXCEEDED:case Code.RESOURCE_EXHAUSTED:case Code.INTERNAL:case Code.UNAVAILABLE:case Code.UNAUTHENTICATED:return!1;case Code.INVALID_ARGUMENT:case Code.NOT_FOUND:case Code.ALREADY_EXISTS:case Code.PERMISSION_DENIED:case Code.FAILED_PRECONDITION:case Code.ABORTED:case Code.OUT_OF_RANGE:case Code.UNIMPLEMENTED:case Code.DATA_LOSS:return!0;default:return fail("Unknown status code: "+t)}}function __PRIVATE_isPermanentWriteError(t){return __PRIVATE_isPermanentError(t)&&t!==Code.ABORTED}function __PRIVATE_mapCodeFromRpcStatus(t){var e=__PRIVATE_RpcCode[t];if(void 0!==e)return __PRIVATE_mapCodeFromRpcCode(e)}function __PRIVATE_mapCodeFromRpcCode(t){if(void 0===t)return error("GRPC error has no .code"),Code.UNKNOWN;switch(t){case __PRIVATE_RpcCode.OK:return Code.OK;case __PRIVATE_RpcCode.CANCELLED:return Code.CANCELLED;case __PRIVATE_RpcCode.UNKNOWN:return Code.UNKNOWN;case __PRIVATE_RpcCode.DEADLINE_EXCEEDED:return Code.DEADLINE_EXCEEDED;case __PRIVATE_RpcCode.RESOURCE_EXHAUSTED:return Code.RESOURCE_EXHAUSTED;case __PRIVATE_RpcCode.INTERNAL:return Code.INTERNAL;case __PRIVATE_RpcCode.UNAVAILABLE:return Code.UNAVAILABLE;case __PRIVATE_RpcCode.UNAUTHENTICATED:return Code.UNAUTHENTICATED;case __PRIVATE_RpcCode.INVALID_ARGUMENT:return Code.INVALID_ARGUMENT;case __PRIVATE_RpcCode.NOT_FOUND:return Code.NOT_FOUND;case __PRIVATE_RpcCode.ALREADY_EXISTS:return Code.ALREADY_EXISTS;case __PRIVATE_RpcCode.PERMISSION_DENIED:return Code.PERMISSION_DENIED;case __PRIVATE_RpcCode.FAILED_PRECONDITION:return Code.FAILED_PRECONDITION;case __PRIVATE_RpcCode.ABORTED:return Code.ABORTED;case __PRIVATE_RpcCode.OUT_OF_RANGE:return Code.OUT_OF_RANGE;case __PRIVATE_RpcCode.UNIMPLEMENTED:return Code.UNIMPLEMENTED;case __PRIVATE_RpcCode.DATA_LOSS:return Code.DATA_LOSS;default:return fail("Unknown status code: "+t)}}function __PRIVATE_mapRpcCodeFromCode(t){if(void 0===t)return __PRIVATE_RpcCode.OK;switch(t){case Code.OK:return __PRIVATE_RpcCode.OK;case Code.CANCELLED:return __PRIVATE_RpcCode.CANCELLED;case Code.UNKNOWN:return __PRIVATE_RpcCode.UNKNOWN;case Code.DEADLINE_EXCEEDED:return __PRIVATE_RpcCode.DEADLINE_EXCEEDED;case Code.RESOURCE_EXHAUSTED:return __PRIVATE_RpcCode.RESOURCE_EXHAUSTED;case Code.INTERNAL:return __PRIVATE_RpcCode.INTERNAL;case Code.UNAVAILABLE:return __PRIVATE_RpcCode.UNAVAILABLE;case Code.UNAUTHENTICATED:return __PRIVATE_RpcCode.UNAUTHENTICATED;case Code.INVALID_ARGUMENT:return __PRIVATE_RpcCode.INVALID_ARGUMENT;case Code.NOT_FOUND:return __PRIVATE_RpcCode.NOT_FOUND;case Code.ALREADY_EXISTS:return __PRIVATE_RpcCode.ALREADY_EXISTS;case Code.PERMISSION_DENIED:return __PRIVATE_RpcCode.PERMISSION_DENIED;case Code.FAILED_PRECONDITION:return __PRIVATE_RpcCode.FAILED_PRECONDITION;case Code.ABORTED:return __PRIVATE_RpcCode.ABORTED;case Code.OUT_OF_RANGE:return __PRIVATE_RpcCode.OUT_OF_RANGE;case Code.UNIMPLEMENTED:return __PRIVATE_RpcCode.UNIMPLEMENTED;case Code.DATA_LOSS:return __PRIVATE_RpcCode.DATA_LOSS;default:return fail("Unknown status code: "+t)}}function __PRIVATE_mapCodeFromHttpResponseErrorStatus(t){var e=t.toLowerCase().replace("_","-");return Object.values(Code).indexOf(e)>=0?e:Code.UNKNOWN}!function(t){t[t.OK=0]="OK",t[t.CANCELLED=1]="CANCELLED",t[t.UNKNOWN=2]="UNKNOWN",t[t.INVALID_ARGUMENT=3]="INVALID_ARGUMENT",t[t.DEADLINE_EXCEEDED=4]="DEADLINE_EXCEEDED",t[t.NOT_FOUND=5]="NOT_FOUND",t[t.ALREADY_EXISTS=6]="ALREADY_EXISTS",t[t.PERMISSION_DENIED=7]="PERMISSION_DENIED",t[t.UNAUTHENTICATED=16]="UNAUTHENTICATED",t[t.RESOURCE_EXHAUSTED=8]="RESOURCE_EXHAUSTED",t[t.FAILED_PRECONDITION=9]="FAILED_PRECONDITION",t[t.ABORTED=10]="ABORTED",t[t.OUT_OF_RANGE=11]="OUT_OF_RANGE",t[t.UNIMPLEMENTED=12]="UNIMPLEMENTED",t[t.INTERNAL=13]="INTERNAL",t[t.UNAVAILABLE=14]="UNAVAILABLE",t[t.DATA_LOSS=15]="DATA_LOSS"}(__PRIVATE_RpcCode||(__PRIVATE_RpcCode={}));var __PRIVATE_EMPTY_MAYBE_DOCUMENT_MAP=new __PRIVATE_SortedMap(__PRIVATE_DocumentKey.X);function __PRIVATE_maybeDocumentMap(){return __PRIVATE_EMPTY_MAYBE_DOCUMENT_MAP}function __PRIVATE_nullableMaybeDocumentMap(){return __PRIVATE_maybeDocumentMap()}var __PRIVATE_EMPTY_DOCUMENT_MAP=new __PRIVATE_SortedMap(__PRIVATE_DocumentKey.X);function __PRIVATE_documentMap(){return __PRIVATE_EMPTY_DOCUMENT_MAP}var __PRIVATE_EMPTY_DOCUMENT_VERSION_MAP=new __PRIVATE_SortedMap(__PRIVATE_DocumentKey.X);function __PRIVATE_documentVersionMap(){return __PRIVATE_EMPTY_DOCUMENT_VERSION_MAP}var __PRIVATE_EMPTY_DOCUMENT_KEY_SET=new __PRIVATE_SortedSet(__PRIVATE_DocumentKey.X);function __PRIVATE_documentKeySet(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];for(var n=__PRIVATE_EMPTY_DOCUMENT_KEY_SET,r=0,i=t;r<i.length;r++){var s=i[r];n=n.add(s)}return n}var __PRIVATE_EMPTY_TARGET_ID_SET=new __PRIVATE_SortedSet(__PRIVATE_primitiveComparator);function __PRIVATE_targetIdSet(){return __PRIVATE_EMPTY_TARGET_ID_SET}var __PRIVATE_ChangeType,__PRIVATE_SyncState,__PRIVATE_DocumentSet=function(){function t(t){this.X=t?function(e,n){return t(e,n)||__PRIVATE_DocumentKey.X(e.key,n.key)}:function(t,e){return __PRIVATE_DocumentKey.X(t.key,e.key)},this.kn=__PRIVATE_documentMap(),this.xn=new __PRIVATE_SortedMap(this.X)}return t.Kn=function(e){return new t(e.X)},t.prototype.has=function(t){return null!=this.kn.get(t)},t.prototype.get=function(t){return this.kn.get(t)},t.prototype.first=function(){return this.xn.Vt()},t.prototype.last=function(){return this.xn.vt()},t.prototype.et=function(){return this.xn.et()},t.prototype.indexOf=function(t){var e=this.kn.get(t);return e?this.xn.indexOf(e):-1},Object.defineProperty(t.prototype,"size",{get:function(){return this.xn.size},enumerable:!0,configurable:!0}),t.prototype.forEach=function(t){this.xn.pt((function(e,n){return t(e),!1}))},t.prototype.add=function(t){var e=this.delete(t.key);return e.Rt(e.kn.At(t.key,t),e.xn.At(t,null))},t.prototype.delete=function(t){var e=this.get(t);return e?this.Rt(this.kn.remove(t),this.xn.remove(e)):this},t.prototype.isEqual=function(e){if(!(e instanceof t))return!1;if(this.size!==e.size)return!1;for(var n=this.xn.gt(),r=e.xn.gt();n.Ft();){var i=n.Ot().key,s=r.Ot().key;if(!i.isEqual(s))return!1}return!0},t.prototype.toString=function(){var t=[];return this.forEach((function(e){t.push(e.toString())})),0===t.length?"DocumentSet ()":"DocumentSet (\n "+t.join(" \n")+"\n)"},t.prototype.Rt=function(e,n){var r=new t;return r.X=this.X,r.kn=e,r.xn=n,r},t}();!function(t){t[t.jn=0]="__PRIVATE_Added",t[t.qn=1]="__PRIVATE_Removed",t[t.Qn=2]="__PRIVATE_Modified",t[t.Wn=3]="__PRIVATE_Metadata"}(__PRIVATE_ChangeType||(__PRIVATE_ChangeType={})),function(t){t[t.$n=0]="__PRIVATE_Local",t[t.Yn=1]="__PRIVATE_Synced"}(__PRIVATE_SyncState||(__PRIVATE_SyncState={}));var __PRIVATE_WatchTargetChangeState,__PRIVATE_DocumentChangeSet=function(){function t(){this.Hn=new __PRIVATE_SortedMap(__PRIVATE_DocumentKey.X)}return t.prototype.track=function(t){var e=t.doc.key,n=this.Hn.get(e);n?t.type!==__PRIVATE_ChangeType.jn&&n.type===__PRIVATE_ChangeType.Wn?this.Hn=this.Hn.At(e,t):t.type===__PRIVATE_ChangeType.Wn&&n.type!==__PRIVATE_ChangeType.qn?this.Hn=this.Hn.At(e,{type:n.type,doc:t.doc}):t.type===__PRIVATE_ChangeType.Qn&&n.type===__PRIVATE_ChangeType.Qn?this.Hn=this.Hn.At(e,{type:__PRIVATE_ChangeType.Qn,doc:t.doc}):t.type===__PRIVATE_ChangeType.Qn&&n.type===__PRIVATE_ChangeType.jn?this.Hn=this.Hn.At(e,{type:__PRIVATE_ChangeType.jn,doc:t.doc}):t.type===__PRIVATE_ChangeType.qn&&n.type===__PRIVATE_ChangeType.jn?this.Hn=this.Hn.remove(e):t.type===__PRIVATE_ChangeType.qn&&n.type===__PRIVATE_ChangeType.Qn?this.Hn=this.Hn.At(e,{type:__PRIVATE_ChangeType.qn,doc:n.doc}):t.type===__PRIVATE_ChangeType.jn&&n.type===__PRIVATE_ChangeType.qn?this.Hn=this.Hn.At(e,{type:__PRIVATE_ChangeType.Qn,doc:t.doc}):fail("unsupported combination of changes: "+JSON.stringify(t)+" after "+JSON.stringify(n)):this.Hn=this.Hn.At(e,t)},t.prototype.Xn=function(){var t=[];return this.Hn.pt((function(e,n){t.push(n)})),t},t}(),__PRIVATE_ViewSnapshot=function(){function t(t,e,n,r,i,s,o,u){this.query=t,this.docs=e,this.zn=n,this.docChanges=r,this.Jn=i,this.fromCache=s,this.Zn=o,this.tr=u}return t.er=function(e,n,r,i){var s=[];return n.forEach((function(t){s.push({type:__PRIVATE_ChangeType.jn,doc:t})})),new t(e,n,__PRIVATE_DocumentSet.Kn(n),s,r,i,!0,!1)},Object.defineProperty(t.prototype,"hasPendingWrites",{get:function(){return!this.Jn.et()},enumerable:!0,configurable:!0}),t.prototype.isEqual=function(t){if(!(this.fromCache===t.fromCache&&this.Zn===t.Zn&&this.Jn.isEqual(t.Jn)&&this.query.isEqual(t.query)&&this.docs.isEqual(t.docs)&&this.zn.isEqual(t.zn)))return!1;var e=this.docChanges,n=t.docChanges;if(e.length!==n.length)return!1;for(var r=0;r<e.length;r++)if(e[r].type!==n[r].type||!e[r].doc.isEqual(n[r].doc))return!1;return!0},t}(),__PRIVATE_RemoteEvent=function(){function t(t,e,n,r,i){this.Ln=t,this.nr=e,this.rr=n,this.ir=r,this.sr=i}return t.or=function(e,n){var r,i=((r={})[e]=TargetChange.ur(e,n),r);return new t(__PRIVATE_SnapshotVersion.MIN,i,__PRIVATE_targetIdSet(),__PRIVATE_maybeDocumentMap(),__PRIVATE_documentKeySet())},t}(),TargetChange=function(){function t(t,e,n,r,i){this.resumeToken=t,this.ar=e,this._r=n,this.cr=r,this.hr=i}return t.ur=function(e,n){return new t(__PRIVATE_emptyByteString(),n,__PRIVATE_documentKeySet(),__PRIVATE_documentKeySet(),__PRIVATE_documentKeySet())},t}(),__PRIVATE_DocumentWatchChange=function(t,e,n,r){this.lr=t,this.removedTargetIds=e,this.key=n,this.dr=r},__PRIVATE_ExistenceFilterChange=function(t,e){this.targetId=t,this.Tr=e};!function(t){t[t.Er=0]="__PRIVATE_NoChange",t[t.jn=1]="__PRIVATE_Added",t[t.qn=2]="__PRIVATE_Removed",t[t.Pr=3]="__PRIVATE_Current",t[t.Ar=4]="__PRIVATE_Reset"}(__PRIVATE_WatchTargetChangeState||(__PRIVATE_WatchTargetChangeState={}));var __PRIVATE_WatchTargetChange=function(t,e,n,r){void 0===n&&(n=__PRIVATE_emptyByteString()),void 0===r&&(r=null),this.state=t,this.targetIds=e,this.resumeToken=n,this.cause=r},__PRIVATE_TargetState=function(){function t(){this.Rr=0,this.Ir=__PRIVATE_snapshotChangesMap(),this.Vr=__PRIVATE_emptyByteString(),this.mr=!1,this.vr=!0}return Object.defineProperty(t.prototype,"ar",{get:function(){return this.mr},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"resumeToken",{get:function(){return this.Vr},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"pr",{get:function(){return 0!==this.Rr},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"br",{get:function(){return this.vr},enumerable:!0,configurable:!0}),t.prototype.gr=function(t){t.length>0&&(this.vr=!0,this.Vr=t)},t.prototype.wr=function(){var t=__PRIVATE_documentKeySet(),e=__PRIVATE_documentKeySet(),n=__PRIVATE_documentKeySet();return this.Ir.forEach((function(r,i){switch(i){case __PRIVATE_ChangeType.jn:t=t.add(r);break;case __PRIVATE_ChangeType.Qn:e=e.add(r);break;case __PRIVATE_ChangeType.qn:n=n.add(r);break;default:fail("Encountered invalid change type: "+i)}})),new TargetChange(this.Vr,this.mr,t,e,n)},t.prototype.yr=function(){this.vr=!1,this.Ir=__PRIVATE_snapshotChangesMap()},t.prototype.Sr=function(t,e){this.vr=!0,this.Ir=this.Ir.At(t,e)},t.prototype.Dr=function(t){this.vr=!0,this.Ir=this.Ir.remove(t)},t.prototype.Cr=function(){this.Rr+=1},t.prototype.Or=function(){this.Rr-=1},t.prototype.Fr=function(){this.vr=!0,this.mr=!0},t}(),__PRIVATE_LOG_TAG="WatchChangeAggregator",__PRIVATE_WatchChangeAggregator=function(){function t(t){this.Nr=t,this.Mr={},this.Lr=__PRIVATE_maybeDocumentMap(),this.Gr=__PRIVATE_documentTargetMap(),this.Br=new __PRIVATE_SortedSet(__PRIVATE_primitiveComparator)}return t.prototype.Ur=function(t){for(var e=0,n=t.lr;e<n.length;e++){var r=n[e];t.dr instanceof Document?this.kr(r,t.dr):t.dr instanceof __PRIVATE_NoDocument&&this.xr(r,t.key,t.dr)}for(var i=0,s=t.removedTargetIds;i<s.length;i++){r=s[i];this.xr(r,t.key,t.dr)}},t.prototype.Kr=function(t){var e=this;this.jr(t,(function(n){var r=e.qr(n);switch(t.state){case __PRIVATE_WatchTargetChangeState.Er:e.Qr(n)&&r.gr(t.resumeToken);break;case __PRIVATE_WatchTargetChangeState.jn:r.Or(),r.pr||r.yr(),r.gr(t.resumeToken);break;case __PRIVATE_WatchTargetChangeState.qn:r.Or(),r.pr||e.removeTarget(n),assert(!t.cause,"WatchChangeAggregator does not handle errored targets");break;case __PRIVATE_WatchTargetChangeState.Pr:e.Qr(n)&&(r.Fr(),r.gr(t.resumeToken));break;case __PRIVATE_WatchTargetChangeState.Ar:e.Qr(n)&&(e.Wr(n),r.gr(t.resumeToken));break;default:fail("Unknown target watch change state: "+t.state)}}))},t.prototype.jr=function(t,e){t.targetIds.length>0?t.targetIds.forEach(e):__PRIVATE_forEachNumber(this.Mr,e)},t.prototype.$r=function(t){var e=t.targetId,n=t.Tr.count,r=this.Yr(e);if(r){var i=r.target;if(i.Ze())if(0===n){var s=new __PRIVATE_DocumentKey(i.path);this.xr(e,s,new __PRIVATE_NoDocument(s,__PRIVATE_SnapshotVersion.W()))}else assert(1===n,"Single document existence filter with count: "+n);else this.Hr(e)!==n&&(this.Wr(e),this.Br=this.Br.add(e))}},t.prototype.Xr=function(t){var e=this,n={};__PRIVATE_forEachNumber(this.Mr,(function(r,i){var s=e.Yr(r);if(s){if(i.ar&&s.target.Ze()){var o=new __PRIVATE_DocumentKey(s.target.path);null!==e.Lr.get(o)||e.zr(r,o)||e.xr(r,o,new __PRIVATE_NoDocument(o,t))}i.br&&(n[r]=i.wr(),i.yr())}}));var r=__PRIVATE_documentKeySet();this.Gr.forEach((function(t,n){var i=!0;n.$t((function(t){var n=e.Yr(t);return!n||n.Mn===__PRIVATE_TargetPurpose.Nn||(i=!1,!1)})),i&&(r=r.add(t))}));var i=new __PRIVATE_RemoteEvent(t,n,this.Br,this.Lr,r);return this.Lr=__PRIVATE_maybeDocumentMap(),this.Gr=__PRIVATE_documentTargetMap(),this.Br=new __PRIVATE_SortedSet(__PRIVATE_primitiveComparator),i},t.prototype.kr=function(t,e){if(this.Qr(t)){var n=this.zr(t,e.key)?__PRIVATE_ChangeType.Qn:__PRIVATE_ChangeType.jn;this.qr(t).Sr(e.key,n),this.Lr=this.Lr.At(e.key,e),this.Gr=this.Gr.At(e.key,this.Jr(e.key).add(t))}},t.prototype.xr=function(t,e,n){if(this.Qr(t)){var r=this.qr(t);this.zr(t,e)?r.Sr(e,__PRIVATE_ChangeType.qn):r.Dr(e),this.Gr=this.Gr.At(e,this.Jr(e).delete(t)),n&&(this.Lr=this.Lr.At(e,n))}},t.prototype.removeTarget=function(t){delete this.Mr[t]},t.prototype.Hr=function(t){var e=this.qr(t).wr();return this.Nr.Zr(t).size+e._r.size-e.hr.size},t.prototype.Cr=function(t){this.qr(t).Cr()},t.prototype.qr=function(t){return this.Mr[t]||(this.Mr[t]=new __PRIVATE_TargetState),this.Mr[t]},t.prototype.Jr=function(t){var e=this.Gr.get(t);return e||(e=new __PRIVATE_SortedSet(__PRIVATE_primitiveComparator),this.Gr=this.Gr.At(t,e)),e},t.prototype.Qr=function(t){var e=null!==this.Yr(t);return e||debug(__PRIVATE_LOG_TAG,"Detected inactive target",t),e},t.prototype.Yr=function(t){var e=this.Mr[t];return e&&e.pr?null:this.Nr.ti(t)},t.prototype.Wr=function(t){var e=this;assert(!this.Mr[t].pr,"Should only reset active targets"),this.Mr[t]=new __PRIVATE_TargetState,this.Nr.Zr(t).forEach((function(n){e.xr(t,n,null)}))},t.prototype.zr=function(t,e){return this.Nr.Zr(t).has(e)},t}();function __PRIVATE_documentTargetMap(){return new __PRIVATE_SortedMap(__PRIVATE_DocumentKey.X)}function __PRIVATE_snapshotChangesMap(){return new __PRIVATE_SortedMap(__PRIVATE_DocumentKey.X)}var __PRIVATE_DIRECTIONS=function(){var t={};return t[__PRIVATE_Direction.ASCENDING.name]="ASCENDING",t[__PRIVATE_Direction.DESCENDING.name]="DESCENDING",t}(),__PRIVATE_OPERATORS=function(){var t={};return t[__PRIVATE_Operator.LESS_THAN.name]="LESS_THAN",t[__PRIVATE_Operator.LESS_THAN_OR_EQUAL.name]="LESS_THAN_OR_EQUAL",t[__PRIVATE_Operator.GREATER_THAN.name]="GREATER_THAN",t[__PRIVATE_Operator.GREATER_THAN_OR_EQUAL.name]="GREATER_THAN_OR_EQUAL",t[__PRIVATE_Operator.EQUAL.name]="EQUAL",t[__PRIVATE_Operator.ARRAY_CONTAINS.name]="ARRAY_CONTAINS",t[__PRIVATE_Operator.IN.name]="IN",t[__PRIVATE_Operator.ARRAY_CONTAINS_ANY.name]="ARRAY_CONTAINS_ANY",t}(),__PRIVATE_ISO_REG_EXP=new RegExp(/^\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d(?:\.(\d+))?Z$/);function __PRIVATE_assertPresent(t,e){assert(!__PRIVATE_isNullOrUndefined(t),e+" is missing")}function __PRIVATE_parseInt64(t){return"number"==typeof t?t:"string"==typeof t?Number(t):fail("can't parse "+t)}var __PRIVATE_JsonProtoSerializer=function(){function t(t,e){this.o=t,this.options=e}return t.prototype.ei=function(){return this.options.ni?"":new Uint8Array(0)},t.prototype.ri=function(t){return t},t.prototype.ii=function(t){var e=void 0===t.code?Code.UNKNOWN:__PRIVATE_mapCodeFromRpcCode(t.code);return new FirestoreError(e,t.message||"")},t.prototype.si=function(t){return this.options.ni||__PRIVATE_isNullOrUndefined(t)?t:{value:t}},t.prototype.oi=function(t){var e;return __PRIVATE_isNullOrUndefined(e="object"==typeof t?t.value:t)?null:e},t.prototype.Y=function(t){return this.options.ni?new Date(1e3*t.seconds).toISOString().replace(/\.\d*/,"").replace("Z","")+"."+("000000000"+t.nanoseconds).slice(-9)+"Z":{seconds:""+t.seconds,nanos:t.nanoseconds}},t.prototype.q=function(t){if("string"==typeof t)return this.ui(t);assert(!!t,"Cannot deserialize null or undefined timestamp.");var e=__PRIVATE_parseInt64(t.seconds||"0"),n=t.nanos||0;return new Timestamp(e,n)},t.prototype.ui=function(t){var e=0,n=__PRIVATE_ISO_REG_EXP.exec(t);if(assert(!!n,"invalid timestamp: "+t),n[1]){var r=n[1];r=(r+"000000000").substr(0,9),e=Number(r)}var i=new Date(t),s=Math.floor(i.getTime()/1e3);return new Timestamp(s,e)},t.prototype.ai=function(t){return this.options.ni?t.toBase64():this.ri(t.toUint8Array())},t.prototype._i=function(t){return"string"==typeof t?(assert(this.options.ni,"Expected bytes to be passed in as Uint8Array, but got a string instead."),Blob.fromBase64String(t)):(assert(!this.options.ni,"Expected bytes to be passed in as Uint8Array, but got a string instead."),Blob.fromUint8Array(t))},t.prototype.toVersion=function(t){return this.Y(t.Y())},t.prototype.fromVersion=function(t){return assert(!!t,"Trying to deserialize version that isn't set"),__PRIVATE_SnapshotVersion.q(this.q(t))},t.prototype.ci=function(t,e){return this.hi(t).child("documents").child(e).ut()},t.prototype.fi=function(t){var e=ResourcePath.at(t);return assert(this.li(e),"Tried to deserialize invalid key "+e.toString()),e},t.prototype.di=function(t){return this.ci(this.o,t.path)},t.prototype.Ti=function(t){var e=this.fi(t);return assert(e.get(1)===this.o.projectId,"Tried to deserialize key from different project: "+e.get(1)+" vs "+this.o.projectId),assert(!e.get(3)&&!this.o.database||e.get(3)===this.o.database,"Tried to deserialize key from different database: "+e.get(3)+" vs "+this.o.database),new __PRIVATE_DocumentKey(this.Ei(e))},t.prototype.Pi=function(t){return this.ci(this.o,t)},t.prototype.Ai=function(t){var e=this.fi(t);return 4===e.length?ResourcePath._t:this.Ei(e)},Object.defineProperty(t.prototype,"Ri",{get:function(){return new ResourcePath(["projects",this.o.projectId,"databases",this.o.database]).ut()},enumerable:!0,configurable:!0}),t.prototype.hi=function(t){return new ResourcePath(["projects",t.projectId,"databases",t.database])},t.prototype.Ei=function(t){return assert(t.length>4&&"documents"===t.get(4),"tried to deserialize invalid key "+t.toString()),t.Z(5)},t.prototype.li=function(t){return t.length>=4&&"projects"===t.get(0)&&"databases"===t.get(2)},t.prototype.Ii=function(t){if(t instanceof __PRIVATE_NullValue)return{nullValue:"NULL_VALUE"};if(t instanceof __PRIVATE_BooleanValue)return{booleanValue:t.value()};if(t instanceof __PRIVATE_IntegerValue)return{integerValue:""+t.value()};if(t instanceof __PRIVATE_DoubleValue){var e=t.value();if(this.options.ni){if(isNaN(e))return{doubleValue:"NaN"};if(e===1/0)return{doubleValue:"Infinity"};if(e===-1/0)return{doubleValue:"-Infinity"}}return{doubleValue:t.value()}}return t instanceof __PRIVATE_StringValue?{stringValue:t.value()}:t instanceof __PRIVATE_ObjectValue?{mapValue:this.Vi(t)}:t instanceof ArrayValue?{arrayValue:this.mi(t)}:t instanceof __PRIVATE_TimestampValue?{timestampValue:this.Y(t.ee)}:t instanceof __PRIVATE_GeoPointValue?{geoPointValue:{latitude:t.value().latitude,longitude:t.value().longitude}}:t instanceof __PRIVATE_BlobValue?{bytesValue:this.ai(t.value())}:t instanceof __PRIVATE_RefValue?{referenceValue:this.ci(t.o,t.key.path)}:fail("Unknown FieldValue "+JSON.stringify(t))},t.prototype.vi=function(t){var e=this;if("nullValue"in t)return __PRIVATE_NullValue.ke;if("booleanValue"in t)return __PRIVATE_BooleanValue.of(t.booleanValue);if("integerValue"in t)return new __PRIVATE_IntegerValue(__PRIVATE_parseInt64(t.integerValue));if("doubleValue"in t){if(this.options.ni){if("NaN"===t.doubleValue)return __PRIVATE_DoubleValue.je;if("Infinity"===t.doubleValue)return __PRIVATE_DoubleValue.POSITIVE_INFINITY;if("-Infinity"===t.doubleValue)return __PRIVATE_DoubleValue.NEGATIVE_INFINITY}return new __PRIVATE_DoubleValue(t.doubleValue)}if("stringValue"in t)return new __PRIVATE_StringValue(t.stringValue);if("mapValue"in t)return this.pi(t.mapValue.fields||{});if("arrayValue"in t){__PRIVATE_assertPresent(t.arrayValue,"arrayValue");var n=t.arrayValue.values||[];return new ArrayValue(n.map((function(t){return e.vi(t)})))}if("timestampValue"in t)return __PRIVATE_assertPresent(t.timestampValue,"timestampValue"),new __PRIVATE_TimestampValue(this.q(t.timestampValue));if("geoPointValue"in t){__PRIVATE_assertPresent(t.geoPointValue,"geoPointValue");var r=t.geoPointValue.latitude||0,i=t.geoPointValue.longitude||0;return new __PRIVATE_GeoPointValue(new GeoPoint(r,i))}if("bytesValue"in t){__PRIVATE_assertPresent(t.bytesValue,"bytesValue");var s=this._i(t.bytesValue);return new __PRIVATE_BlobValue(s)}if("referenceValue"in t){__PRIVATE_assertPresent(t.referenceValue,"referenceValue");var o=this.fi(t.referenceValue),u=new __PRIVATE_DatabaseId(o.get(1),o.get(3)),a=new __PRIVATE_DocumentKey(this.Ei(o));return new __PRIVATE_RefValue(u,a)}return fail("Unknown Value proto "+JSON.stringify(t))},t.prototype.bi=function(t,e){return{name:this.di(t),fields:this.gi(e)}},t.prototype.wi=function(t){return assert(!t.de,"Can't serialize documents with mutations."),{name:this.di(t.key),fields:this.gi(t.data()),updateTime:this.Y(t.version.Y())}},t.prototype.yi=function(t,e){var n=this,r=this.Ti(t.name),i=this.fromVersion(t.updateTime);return new Document(r,i,{hasCommittedMutations:!!e},void 0,t,(function(t){return n.vi(t)}))},t.prototype.gi=function(t){var e=this,n={};return t.forEach((function(t,r){n[t]=e.Ii(r)})),n},t.prototype.pi=function(t){var e=this,n=t,r=__PRIVATE_ObjectValue.EMPTY;return forEach(n,(function(t,n){r=r.set(new FieldPath([t]),e.vi(n))})),r},t.prototype.Vi=function(t){return{fields:this.gi(t)}},t.prototype.mi=function(t){var e=this,n=[];return t.forEach((function(t){n.push(e.Ii(t))})),{values:n}},t.prototype.Si=function(t){var e=this;assert(!!t.found,"Tried to deserialize a found document from a missing document."),__PRIVATE_assertPresent(t.found.name,"doc.found.name"),__PRIVATE_assertPresent(t.found.updateTime,"doc.found.updateTime");var n=this.Ti(t.found.name),r=this.fromVersion(t.found.updateTime);return new Document(n,r,{},void 0,t.found,(function(t){return e.vi(t)}))},t.prototype.Di=function(t){assert(!!t.missing,"Tried to deserialize a missing document from a found document."),assert(!!t.readTime,"Tried to deserialize a missing document without a read time.");var e=this.Ti(t.missing),n=this.fromVersion(t.readTime);return new __PRIVATE_NoDocument(e,n)},t.prototype.Ci=function(t){return"found"in t?this.Si(t):"missing"in t?this.Di(t):fail("invalid batch get response: "+JSON.stringify(t))},t.prototype.Oi=function(t){switch(t){case __PRIVATE_WatchTargetChangeState.jn:return"ADD";case __PRIVATE_WatchTargetChangeState.Pr:return"CURRENT";case __PRIVATE_WatchTargetChangeState.Er:return"NO_CHANGE";case __PRIVATE_WatchTargetChangeState.qn:return"REMOVE";case __PRIVATE_WatchTargetChangeState.Ar:return"RESET";default:return fail("Unknown WatchTargetChangeState: "+t)}},t.prototype.Fi=function(t){if(t instanceof __PRIVATE_ExistenceFilterChange)return{filter:{count:t.Tr.count,targetId:t.targetId}};if(t instanceof __PRIVATE_DocumentWatchChange){if(t.dr instanceof Document){var e=t.dr;return{documentChange:{document:{name:this.di(e.key),fields:this.gi(e.data()),updateTime:this.toVersion(e.version)},targetIds:t.lr,removedTargetIds:t.removedTargetIds}}}if(t.dr instanceof __PRIVATE_NoDocument){e=t.dr;return{documentDelete:{document:this.di(e.key),readTime:this.toVersion(e.version),removedTargetIds:t.removedTargetIds}}}if(null===t.dr)return{documentRemove:{document:this.di(t.key),removedTargetIds:t.removedTargetIds}}}if(t instanceof __PRIVATE_WatchTargetChange){var n=void 0;return t.cause&&(n={code:__PRIVATE_mapRpcCodeFromCode(t.cause.code),message:t.cause.message}),{targetChange:{targetChangeType:this.Oi(t.state),targetIds:t.targetIds,resumeToken:this.ri(t.resumeToken),cause:n}}}return fail("Unrecognized watch change: "+JSON.stringify(t))},t.prototype.Ni=function(t){var e,n=this;if("targetChange"in t){__PRIVATE_assertPresent(t.targetChange,"targetChange");var r=this.Mi(t.targetChange.targetChangeType||"NO_CHANGE"),i=t.targetChange.targetIds||[],s=t.targetChange.resumeToken||this.ei(),o=t.targetChange.cause,u=o&&this.ii(o);e=new __PRIVATE_WatchTargetChange(r,i,s,u||null)}else if("documentChange"in t){__PRIVATE_assertPresent(t.documentChange,"documentChange");var a=t.documentChange;__PRIVATE_assertPresent(a.document,"documentChange.name"),__PRIVATE_assertPresent(a.document.name,"documentChange.document.name"),__PRIVATE_assertPresent(a.document.updateTime,"documentChange.document.updateTime");var _=this.Ti(a.document.name),c=this.fromVersion(a.document.updateTime),h=new Document(_,c,{},void 0,a.document,(function(t){return n.vi(t)})),f=a.targetIds||[],l=a.removedTargetIds||[];e=new __PRIVATE_DocumentWatchChange(f,l,h.key,h)}else if("documentDelete"in t){__PRIVATE_assertPresent(t.documentDelete,"documentDelete");var d=t.documentDelete;__PRIVATE_assertPresent(d.document,"documentDelete.document");_=this.Ti(d.document),c=d.readTime?this.fromVersion(d.readTime):__PRIVATE_SnapshotVersion.W(),h=new __PRIVATE_NoDocument(_,c),l=d.removedTargetIds||[];e=new __PRIVATE_DocumentWatchChange([],l,h.key,h)}else if("documentRemove"in t){__PRIVATE_assertPresent(t.documentRemove,"documentRemove");var T=t.documentRemove;__PRIVATE_assertPresent(T.document,"documentRemove");_=this.Ti(T.document),l=T.removedTargetIds||[];e=new __PRIVATE_DocumentWatchChange([],l,_,null)}else{if(!("filter"in t))return fail("Unknown change type "+JSON.stringify(t));__PRIVATE_assertPresent(t.filter,"filter");var E=t.filter;__PRIVATE_assertPresent(E.targetId,"filter.targetId");var P=E.count||0,A=new ExistenceFilter(P),R=E.targetId;e=new __PRIVATE_ExistenceFilterChange(R,A)}return e},t.prototype.Mi=function(t){return"NO_CHANGE"===t?__PRIVATE_WatchTargetChangeState.Er:"ADD"===t?__PRIVATE_WatchTargetChangeState.jn:"REMOVE"===t?__PRIVATE_WatchTargetChangeState.qn:"CURRENT"===t?__PRIVATE_WatchTargetChangeState.Pr:"RESET"===t?__PRIVATE_WatchTargetChangeState.Ar:fail("Got unexpected TargetChange.state: "+t)},t.prototype.Li=function(t){if(!("targetChange"in t))return __PRIVATE_SnapshotVersion.MIN;var e=t.targetChange;return e.targetIds&&e.targetIds.length?__PRIVATE_SnapshotVersion.MIN:e.readTime?this.fromVersion(e.readTime):__PRIVATE_SnapshotVersion.MIN},t.prototype.Gi=function(t){var e,n=this;if(t instanceof __PRIVATE_SetMutation)e={update:this.bi(t.key,t.value)};else if(t instanceof __PRIVATE_DeleteMutation)e={delete:this.di(t.key)};else if(t instanceof __PRIVATE_PatchMutation)e={update:this.bi(t.key,t.data),updateMask:this.Bi(t.Ee)};else if(t instanceof __PRIVATE_TransformMutation)e={transform:{document:this.di(t.key),fieldTransforms:t.fieldTransforms.map((function(t){return n.Ui(t)}))}};else{if(!(t instanceof __PRIVATE_VerifyMutation))return fail("Unknown mutation type "+t.type);e={verify:this.di(t.key)}}return t.le._e||(e.currentDocument=this.ki(t.le)),e},t.prototype.xi=function(t){var e=this,n=t.currentDocument?this.Ki(t.currentDocument):Precondition.NONE;if(t.update){__PRIVATE_assertPresent(t.update.name,"name");var r=this.Ti(t.update.name),i=this.pi(t.update.fields||{});if(t.updateMask){var s=this.ji(t.updateMask);return new __PRIVATE_PatchMutation(r,i,s,n)}return new __PRIVATE_SetMutation(r,i,n)}if(t.delete){r=this.Ti(t.delete);return new __PRIVATE_DeleteMutation(r,n)}if(t.transform){r=this.Ti(t.transform.document);var o=t.transform.fieldTransforms.map((function(t){return e.qi(t)}));return assert(!0===n.exists,'Transforms only support precondition "exists == true"'),new __PRIVATE_TransformMutation(r,o)}if(t.verify){r=this.Ti(t.verify);return new __PRIVATE_VerifyMutation(r,n)}return fail("unknown mutation proto: "+JSON.stringify(t))},t.prototype.ki=function(t){return assert(!t._e,"Can't serialize an empty precondition"),void 0!==t.updateTime?{updateTime:this.toVersion(t.updateTime)}:void 0!==t.exists?{exists:t.exists}:fail("Unknown precondition")},t.prototype.Ki=function(t){return void 0!==t.updateTime?Precondition.updateTime(this.fromVersion(t.updateTime)):void 0!==t.exists?Precondition.exists(t.exists):Precondition.NONE},t.prototype.Qi=function(t,e){var n=this,r=t.updateTime?this.fromVersion(t.updateTime):this.fromVersion(e);r.isEqual(__PRIVATE_SnapshotVersion.MIN)&&(r=this.fromVersion(e));var i=null;return t.transformResults&&t.transformResults.length>0&&(i=t.transformResults.map((function(t){return n.vi(t)}))),new __PRIVATE_MutationResult(r,i)},t.prototype.Wi=function(t,e){var n=this;return t&&t.length>0?(assert(void 0!==e,"Received a write result without a commit time"),t.map((function(t){return n.Qi(t,e)}))):[]},t.prototype.Ui=function(t){var e=this,n=t.transform;if(n instanceof __PRIVATE_ServerTimestampTransform)return{fieldPath:t.field.ut(),setToServerValue:"REQUEST_TIME"};if(n instanceof __PRIVATE_ArrayUnionTransformOperation)return{fieldPath:t.field.ut(),appendMissingElements:{values:n.elements.map((function(t){return e.Ii(t)}))}};if(n instanceof __PRIVATE_ArrayRemoveTransformOperation)return{fieldPath:t.field.ut(),removeAllFromArray:{values:n.elements.map((function(t){return e.Ii(t)}))}};if(n instanceof __PRIVATE_NumericIncrementTransformOperation)return{fieldPath:t.field.ut(),increment:this.Ii(n.te)};throw fail("Unknown transform: "+t.transform)},t.prototype.qi=function(t){var e=this,n=null;if("setToServerValue"in t)assert("REQUEST_TIME"===t.setToServerValue,"Unknown server value transform proto: "+JSON.stringify(t)),n=__PRIVATE_ServerTimestampTransform.instance;else if("appendMissingElements"in t){var r=t.appendMissingElements.values||[];n=new __PRIVATE_ArrayUnionTransformOperation(r.map((function(t){return e.vi(t)})))}else if("removeAllFromArray"in t){r=t.removeAllFromArray.values||[];n=new __PRIVATE_ArrayRemoveTransformOperation(r.map((function(t){return e.vi(t)})))}else if("increment"in t){var i=this.vi(t.increment);assert(i instanceof __PRIVATE_NumberValue,"NUMERIC_ADD transform requires a NumberValue"),n=new __PRIVATE_NumericIncrementTransformOperation(i)}else fail("Unknown transform proto: "+JSON.stringify(t));var s=FieldPath.lt(t.fieldPath);return new FieldTransform(s,n)},t.prototype.$i=function(t){return{documents:[this.Pi(t.path)]}},t.prototype.Yi=function(t){var e=t.documents.length;assert(1===e,"DocumentsTarget contained other than 1 document: "+e);var n=t.documents[0];return Query.un(this.Ai(n)).Rn()},t.prototype.Hi=function(t){var e={structuredQuery:{}},n=t.path;null!==t.collectionGroup?(assert(n.length%2==0,"Collection Group queries should be within a document path or root."),e.parent=this.Pi(n),e.structuredQuery.from=[{collectionId:t.collectionGroup,allDescendants:!0}]):(assert(n.length%2!=0,"Document queries with filters are not supported."),e.parent=this.Pi(n.tt()),e.structuredQuery.from=[{collectionId:n.rt()}]);var r=this.Xi(t.filters);r&&(e.structuredQuery.where=r);var i=this.zi(t.orderBy);i&&(e.structuredQuery.orderBy=i);var s=this.si(t.limit);return null!==s&&(e.structuredQuery.limit=s),t.startAt&&(e.structuredQuery.startAt=this.Ji(t.startAt)),t.endAt&&(e.structuredQuery.endAt=this.Ji(t.endAt)),e},t.prototype.Zi=function(t){var e=this.Ai(t.parent),n=t.structuredQuery,r=n.from?n.from.length:0,i=null;if(r>0){assert(1===r,"StructuredQuery.from with more than one collection is not supported.");var s=n.from[0];s.allDescendants?i=s.collectionId:e=e.child(s.collectionId)}var o=[];n.where&&(o=this.ts(n.where));var u=[];n.orderBy&&(u=this.es(n.orderBy));var a=null;n.limit&&(a=this.oi(n.limit));var _=null;n.startAt&&(_=this.ns(n.startAt));var c=null;return n.endAt&&(c=this.ns(n.endAt)),new Query(e,i,u,o,a,__PRIVATE_LimitType.tn,_,c).Rn()},t.prototype.rs=function(t){var e=this.ss(t.Mn);return null==e?null:{"goog-listen-tags":e}},t.prototype.ss=function(t){switch(t){case __PRIVATE_TargetPurpose.On:return null;case __PRIVATE_TargetPurpose.Fn:return"existence-filter-mismatch";case __PRIVATE_TargetPurpose.Nn:return"limbo-document";default:return fail("Unrecognized query purpose: "+t)}},t.prototype.Rn=function(t){var e,n=t.target;return(e=n.Ze()?{documents:this.$i(n)}:{query:this.Hi(n)}).targetId=t.targetId,t.resumeToken.length>0&&(e.resumeToken=this.ri(t.resumeToken)),e},t.prototype.Xi=function(t){var e=this;if(0!==t.length){var n=t.map((function(t){return t instanceof FieldFilter?e.os(t):fail("Unrecognized filter: "+JSON.stringify(t))}));return 1===n.length?n[0]:{compositeFilter:{op:"AND",filters:n}}}},t.prototype.ts=function(t){var e=this;return t?void 0!==t.unaryFilter?[this.us(t)]:void 0!==t.fieldFilter?[this.as(t)]:void 0!==t.compositeFilter?t.compositeFilter.filters.map((function(t){return e.ts(t)})).reduce((function(t,e){return t.concat(e)})):fail("Unknown filter: "+JSON.stringify(t)):[]},t.prototype.zi=function(t){var e=this;if(0!==t.length)return t.map((function(t){return e._s(t)}))},t.prototype.es=function(t){var e=this;return t.map((function(t){return e.cs(t)}))},t.prototype.Ji=function(t){var e=this;return{before:t.before,values:t.position.map((function(t){return e.Ii(t)}))}},t.prototype.ns=function(t){var e=this,n=!!t.before,r=t.values.map((function(t){return e.vi(t)}));return new __PRIVATE_Bound(r,n)},t.prototype.hs=function(t){return __PRIVATE_DIRECTIONS[t.name]},t.prototype.fs=function(t){switch(t){case"ASCENDING":return __PRIVATE_Direction.ASCENDING;case"DESCENDING":return __PRIVATE_Direction.DESCENDING;default:return}},t.prototype.ls=function(t){return __PRIVATE_OPERATORS[t.name]},t.prototype.ds=function(t){switch(t){case"EQUAL":return __PRIVATE_Operator.EQUAL;case"GREATER_THAN":return __PRIVATE_Operator.GREATER_THAN;case"GREATER_THAN_OR_EQUAL":return __PRIVATE_Operator.GREATER_THAN_OR_EQUAL;case"LESS_THAN":return __PRIVATE_Operator.LESS_THAN;case"LESS_THAN_OR_EQUAL":return __PRIVATE_Operator.LESS_THAN_OR_EQUAL;case"ARRAY_CONTAINS":return __PRIVATE_Operator.ARRAY_CONTAINS;case"IN":return __PRIVATE_Operator.IN;case"ARRAY_CONTAINS_ANY":return __PRIVATE_Operator.ARRAY_CONTAINS_ANY;case"OPERATOR_UNSPECIFIED":return fail("Unspecified operator");default:return fail("Unknown operator")}},t.prototype.Ts=function(t){return{fieldPath:t.ut()}},t.prototype.Es=function(t){return FieldPath.lt(t.fieldPath)},t.prototype._s=function(t){return{field:this.Ts(t.field),direction:this.hs(t.dir)}},t.prototype.cs=function(t){return new __PRIVATE_OrderBy(this.Es(t.field),this.fs(t.direction))},t.prototype.as=function(t){return FieldFilter.create(this.Es(t.fieldFilter.field),this.ds(t.fieldFilter.op),this.vi(t.fieldFilter.value))},t.prototype.os=function(t){if(t.op===__PRIVATE_Operator.EQUAL){if(t.value.isEqual(__PRIVATE_DoubleValue.je))return{unaryFilter:{field:this.Ts(t.field),op:"IS_NAN"}};if(t.value.isEqual(__PRIVATE_NullValue.ke))return{unaryFilter:{field:this.Ts(t.field),op:"IS_NULL"}}}return{fieldFilter:{field:this.Ts(t.field),op:this.ls(t.op),value:this.Ii(t.value)}}},t.prototype.us=function(t){switch(t.unaryFilter.op){case"IS_NAN":var e=this.Es(t.unaryFilter.field);return FieldFilter.create(e,__PRIVATE_Operator.EQUAL,__PRIVATE_DoubleValue.je);case"IS_NULL":var n=this.Es(t.unaryFilter.field);return FieldFilter.create(n,__PRIVATE_Operator.EQUAL,__PRIVATE_NullValue.ke);case"OPERATOR_UNSPECIFIED":return fail("Unspecified filter");default:return fail("Unknown filter")}},t.prototype.Bi=function(t){var e=[];return t.fields.forEach((function(t){return e.push(t.ut())})),{fieldPaths:e}},t.prototype.ji=function(t){var e=(t.fieldPaths||[]).map((function(t){return FieldPath.lt(t)}));return __PRIVATE_FieldMask.re(e)},t}(),__PRIVATE_PlatformSupport=function(){function t(){}return t.Ps=function(e){t.platform&&fail("Platform already defined"),t.platform=e},t.t=function(){return t.platform||fail("Platform not set"),t.platform},t}();function __PRIVATE_emptyByteString(){return __PRIVATE_PlatformSupport.t().ei}function __PRIVATE_makeConstructorPrivate(t,e){function n(){var t="This constructor is private.";throw e&&(t+=" ",t+=e),new FirestoreError(Code.INVALID_ARGUMENT,t)}for(var r in n.prototype=t.prototype,t)t.hasOwnProperty(r)&&(n[r]=t[r]);return n}function __PRIVATE_assertUint8ArrayAvailable(){if("undefined"==typeof Uint8Array)throw new FirestoreError(Code.UNIMPLEMENTED,"Uint8Arrays are not available in this environment.")}function __PRIVATE_assertBase64Available(){if(!__PRIVATE_PlatformSupport.t().As)throw new FirestoreError(Code.UNIMPLEMENTED,"Blobs are unavailable in Firestore in this environment.")}var __PRIVATE_TimerId,Blob=function(){function t(t){__PRIVATE_assertBase64Available(),this.Rs=t}return t.fromBase64String=function(e){__PRIVATE_validateExactNumberOfArgs("Blob.fromBase64String",arguments,1),__PRIVATE_validateArgType("Blob.fromBase64String","string",1,e),__PRIVATE_assertBase64Available();try{var n=__PRIVATE_PlatformSupport.t().atob(e);return new t(n)}catch(t){throw new FirestoreError(Code.INVALID_ARGUMENT,"Failed to construct Blob from Base64 string: "+t)}},t.fromUint8Array=function(e){if(__PRIVATE_validateExactNumberOfArgs("Blob.fromUint8Array",arguments,1),__PRIVATE_assertUint8ArrayAvailable(),!(e instanceof Uint8Array))throw __PRIVATE_invalidClassError("Blob.fromUint8Array","Uint8Array",1,e);var n=Array.prototype.map.call(e,(function(t){return String.fromCharCode(t)})).join("");return new t(n)},t.prototype.toBase64=function(){return __PRIVATE_validateExactNumberOfArgs("Blob.toBase64",arguments,0),__PRIVATE_assertBase64Available(),__PRIVATE_PlatformSupport.t().btoa(this.Rs)},t.prototype.toUint8Array=function(){__PRIVATE_validateExactNumberOfArgs("Blob.toUint8Array",arguments,0),__PRIVATE_assertUint8ArrayAvailable();for(var t=new Uint8Array(this.Rs.length),e=0;e<this.Rs.length;e++)t[e]=this.Rs.charCodeAt(e);return t},t.prototype.toString=function(){return"Blob(base64: "+this.toBase64()+")"},t.prototype.isEqual=function(t){return this.Rs===t.Rs},t.prototype.Qe=function(){return 2*this.Rs.length},t.prototype.K=function(t){return __PRIVATE_primitiveComparator(this.Rs,t.Rs)},t}(),__PRIVATE_PublicBlob=__PRIVATE_makeConstructorPrivate(Blob,"Use Blob.fromUint8Array() or Blob.fromBase64String() instead."),__PRIVATE_ObjectMap=function(){function t(t){this.Is=t,this.Vs={}}return t.prototype.get=function(t){var e=this.Is(t),n=this.Vs[e];if(void 0!==n)for(var r=0,i=n;r<i.length;r++){var s=i[r],o=s[0],u=s[1];if(o.isEqual(t))return u}},t.prototype.has=function(t){return void 0!==this.get(t)},t.prototype.set=function(t,e){var n=this.Is(t),r=this.Vs[n];if(void 0!==r){for(var i=0;i<r.length;i++)if(r[i][0].isEqual(t))return void(r[i]=[t,e]);r.push([t,e])}else this.Vs[n]=[[t,e]]},t.prototype.delete=function(t){var e=this.Is(t),n=this.Vs[e];if(void 0===n)return!1;for(var r=0;r<n.length;r++)if(n[r][0].isEqual(t))return 1===n.length?delete this.Vs[e]:n.splice(r,1),!0;return!1},t.prototype.forEach=function(t){forEach(this.Vs,(function(e,n){for(var r=0,i=n;r<i.length;r++){var s=i[r],o=s[0],u=s[1];t(o,u)}}))},t.prototype.et=function(){return __PRIVATE_isEmpty(this.Vs)},t}(),__PRIVATE_BATCHID_UNKNOWN=-1,__PRIVATE_MutationBatch=function(){function t(t,e,n,r){this.batchId=t,this.qe=e,this.baseMutations=n,this.mutations=r,assert(r.length>0,"Cannot create an empty mutation batch")}return t.prototype.Jt=function(t,e,n){e&&assert(e.key.isEqual(t),"applyToRemoteDocument: key "+t+" should match maybeDoc key\n "+e.key);var r=n.ms;assert(r.length===this.mutations.length,"Mismatch between mutations length\n ("+this.mutations.length+") and mutation results length\n ("+r.length+").");for(var i=0;i<this.mutations.length;i++){var s=this.mutations[i];if(s.key.isEqual(t)){var o=r[i];e=s.Jt(e,o)}}return e},t.prototype.zt=function(t,e){e&&assert(e.key.isEqual(t),"applyToLocalDocument: key "+t+" should match maybeDoc key\n "+e.key);for(var n=0,r=this.baseMutations;n<r.length;n++){(u=r[n]).key.isEqual(t)&&(e=u.zt(e,e,this.qe))}for(var i=e,s=0,o=this.mutations;s<o.length;s++){var u;(u=o[s]).key.isEqual(t)&&(e=u.zt(e,i,this.qe))}return e},t.prototype.vs=function(t){var e=this,n=t;return this.mutations.forEach((function(r){var i=e.zt(r.key,t.get(r.key));i&&(n=n.At(r.key,i))})),n},t.prototype.keys=function(){return this.mutations.reduce((function(t,e){return t.add(e.key)}),__PRIVATE_documentKeySet())},t.prototype.isEqual=function(t){return this.batchId===t.batchId&&__PRIVATE_arrayEquals(this.mutations,t.mutations)&&__PRIVATE_arrayEquals(this.baseMutations,t.baseMutations)},t}(),__PRIVATE_MutationBatchResult=function(){function t(t,e,n,r,i){this.batch=t,this.ps=e,this.ms=n,this.streamToken=r,this.bs=i}return t.from=function(e,n,r,i){assert(e.mutations.length===r.length,"Mutations sent "+e.mutations.length+" must equal results received "+r.length);for(var s=__PRIVATE_documentVersionMap(),o=e.mutations,u=0;u<o.length;u++)s=s.At(o[u].key,r[u].version);return new t(e,n,r,i,s)},t}(),__PRIVATE_ReferenceSet=function(){function t(){this.gs=new __PRIVATE_SortedSet(__PRIVATE_DocReference.$e),this.ws=new __PRIVATE_SortedSet(__PRIVATE_DocReference.ys)}return t.prototype.et=function(){return this.gs.et()},t.prototype.Ss=function(t,e){var n=new __PRIVATE_DocReference(t,e);this.gs=this.gs.add(n),this.ws=this.ws.add(n)},t.prototype.Ds=function(t,e){var n=this;t.forEach((function(t){return n.Ss(t,e)}))},t.prototype.Cs=function(t,e){this.Os(new __PRIVATE_DocReference(t,e))},t.prototype.Fs=function(t,e){var n=this;t.forEach((function(t){return n.Cs(t,e)}))},t.prototype.Ns=function(t){var e=this,n=__PRIVATE_DocumentKey.EMPTY,r=new __PRIVATE_DocReference(n,t),i=new __PRIVATE_DocReference(n,t+1),s=[];return this.ws.Wt([r,i],(function(t){e.Os(t),s.push(t.key)})),s},t.prototype.Ms=function(){var t=this;this.gs.forEach((function(e){return t.Os(e)}))},t.prototype.Os=function(t){this.gs=this.gs.delete(t),this.ws=this.ws.delete(t)},t.prototype.Ls=function(t){var e=__PRIVATE_DocumentKey.EMPTY,n=new __PRIVATE_DocReference(e,t),r=new __PRIVATE_DocReference(e,t+1),i=__PRIVATE_documentKeySet();return this.ws.Wt([n,r],(function(t){i=i.add(t.key)})),i},t.prototype.Gs=function(t){var e=new __PRIVATE_DocReference(t,0),n=this.gs.Yt(e);return null!==n&&t.isEqual(n.key)},t}(),__PRIVATE_DocReference=function(){function t(t,e){this.key=t,this.Bs=e}return t.$e=function(t,e){return __PRIVATE_DocumentKey.X(t.key,e.key)||__PRIVATE_primitiveComparator(t.Bs,e.Bs)},t.ys=function(t,e){return __PRIVATE_primitiveComparator(t.Bs,e.Bs)||__PRIVATE_DocumentKey.X(t.key,e.key)},t}(),PersistencePromise=function(){function t(t){var e=this;this.Us=null,this.ks=null,this.result=void 0,this.error=void 0,this.xs=!1,this.Ks=!1,t((function(t){e.xs=!0,e.result=t,e.Us&&e.Us(t)}),(function(t){e.xs=!0,e.error=t,e.ks&&e.ks(t)}))}return t.prototype.catch=function(t){return this.next(void 0,t)},t.prototype.next=function(e,n){var r=this;return this.Ks&&fail("Called next() or catch() twice for PersistencePromise"),this.Ks=!0,this.xs?this.error?this.js(n,this.error):this.qs(e,this.result):new t((function(t,i){r.Us=function(n){r.qs(e,n).next(t,i)},r.ks=function(e){r.js(n,e).next(t,i)}}))},t.prototype.Qs=function(){var t=this;return new Promise((function(e,n){t.next(e,n)}))},t.prototype.Ws=function(e){try{var n=e();return n instanceof t?n:t.resolve(n)}catch(e){return t.reject(e)}},t.prototype.qs=function(e,n){return e?this.Ws((function(){return e(n)})):t.resolve(n)},t.prototype.js=function(e,n){return e?this.Ws((function(){return e(n)})):t.reject(n)},t.resolve=function(e){return new t((function(t,n){t(e)}))},t.reject=function(e){return new t((function(t,n){n(e)}))},t.$s=function(e){return new t((function(t,n){var r=0,i=0,s=!1;e.forEach((function(e){++r,e.next((function(){++i,s&&i===r&&t()}),(function(t){return n(t)}))})),s=!0,i===r&&t()}))},t.Ys=function(e){for(var n=t.resolve(!1),r=function(e){n=n.next((function(n){return n?t.resolve(n):e()}))},i=0,s=e;i<s.length;i++){r(s[i])}return n},t.forEach=function(t,e){var n=this,r=[];return t.forEach((function(t,i){r.push(e.call(n,t,i))})),this.$s(r)},t}(),__PRIVATE_RemoteDocumentChangeBuffer=function(){function t(){this.Hs=new __PRIVATE_ObjectMap((function(t){return t.toString()})),this.Xs=!1}return Object.defineProperty(t.prototype,"readTime",{get:function(){return assert(void 0!==this.zs,"Read time is not set. All removeEntry() calls must include a readTime if `trackRemovals` is used."),this.zs},set:function(t){assert(void 0===this.zs||this.zs.isEqual(t),"All changes in a RemoteDocumentChangeBuffer must have the same read time"),this.zs=t},enumerable:!0,configurable:!0}),t.prototype.Js=function(t,e){this.Zs(),this.readTime=e,this.Hs.set(t.key,t)},t.prototype.to=function(t,e){this.Zs(),e&&(this.readTime=e),this.Hs.set(t,null)},t.prototype.eo=function(t,e){this.Zs();var n=this.Hs.get(e);return void 0!==n?PersistencePromise.resolve(n):this.no(t,e)},t.prototype.getEntries=function(t,e){return this.ro(t,e)},t.prototype.apply=function(t){return this.Zs(),this.Xs=!0,this.io(t)},t.prototype.Zs=function(){assert(!this.Xs,"Changes have already been applied.")},t}(),__PRIVATE_PRIMARY_LEASE_LOST_ERROR_MSG="The current tab is not in the required state to perform this operation. It might be necessary to refresh the browser tab.",__PRIVATE_PersistenceTransaction=function(){function t(){this.so=[]}return t.prototype.oo=function(t){this.so.push(t)},t.prototype.uo=function(){this.so.forEach((function(t){return t()}))},t}(),__PRIVATE_LocalDocumentsView=function(){function t(t,e,n){this.ao=t,this._o=e,this.co=n}return t.prototype.ho=function(t,e){var n=this;return this._o.fo(t,e).next((function(r){return n.lo(t,e,r)}))},t.prototype.lo=function(t,e,n){return this.ao.eo(t,e).next((function(t){for(var r=0,i=n;r<i.length;r++){t=i[r].zt(e,t)}return t}))},t.prototype.do=function(t,e,n){var r=__PRIVATE_nullableMaybeDocumentMap();return e.forEach((function(t,e){for(var i=0,s=n;i<s.length;i++){e=s[i].zt(t,e)}r=r.At(t,e)})),r},t.prototype.To=function(t,e){var n=this;return this.ao.getEntries(t,e).next((function(e){return n.Eo(t,e)}))},t.prototype.Eo=function(t,e){var n=this;return this._o.Po(t,e).next((function(r){var i=n.do(t,e,r),s=__PRIVATE_maybeDocumentMap();return i.forEach((function(t,e){e||(e=new __PRIVATE_NoDocument(t,__PRIVATE_SnapshotVersion.W())),s=s.At(t,e)})),s}))},t.prototype.Ao=function(t,e,n){return e.Ze()?this.Ro(t,e.path):e.yn()?this.Io(t,e,n):this.Vo(t,e,n)},t.prototype.Ro=function(t,e){return this.ho(t,new __PRIVATE_DocumentKey(e)).next((function(t){var e=__PRIVATE_documentMap();return t instanceof Document&&(e=e.At(t.key,t)),e}))},t.prototype.Io=function(t,e,n){var r=this;assert(e.path.et(),"Currently we only support collection group queries at the root.");var i=e.collectionGroup,s=__PRIVATE_documentMap();return this.co.mo(t,i).next((function(o){return PersistencePromise.forEach(o,(function(o){var u=e.Pn(o.child(i));return r.Vo(t,u,n).next((function(t){t.forEach((function(t,e){s=s.At(t,e)}))}))})).next((function(){return s}))}))},t.prototype.Vo=function(t,e,n){var r,i,s=this;return this.ao.Ao(t,e,n).next((function(n){return r=n,s._o.vo(t,e)})).next((function(e){return i=e,s.po(t,i,r).next((function(t){r=t;for(var e=0,n=i;e<n.length;e++)for(var s=n[e],o=0,u=s.mutations;o<u.length;o++){var a=u[o],_=a.key,c=r.get(_),h=a.zt(c,c,s.qe);r=h instanceof Document?r.At(_,h):r.remove(_)}}))})).next((function(){return r.forEach((function(t,n){e.matches(n)||(r=r.remove(t))})),r}))},t.prototype.po=function(t,e,n){for(var r=__PRIVATE_documentKeySet(),i=0,s=e;i<s.length;i++)for(var o=0,u=s[i].mutations;o<u.length;o++){var a=u[o];a instanceof __PRIVATE_PatchMutation&&null===n.get(a.key)&&(r=r.add(a.key))}var _=n;return this.ao.getEntries(t,r).next((function(t){return t.forEach((function(t,e){null!==e&&e instanceof Document&&(_=_.At(t,e))})),_}))},t}(),__PRIVATE_LocalViewChanges=function(){function t(t,e,n,r){this.targetId=t,this.fromCache=e,this.bo=n,this.wo=r}return t.yo=function(e,n){for(var r=__PRIVATE_documentKeySet(),i=__PRIVATE_documentKeySet(),s=0,o=n.docChanges;s<o.length;s++){var u=o[s];switch(u.type){case __PRIVATE_ChangeType.jn:r=r.add(u.doc.key);break;case __PRIVATE_ChangeType.qn:i=i.add(u.doc.key)}}return new t(e,n.fromCache,r,i)},t}(),__PRIVATE_ListenSequence=function(){function t(t,e){var n=this;this.previousValue=t,e&&(e.So=function(t){return n.Do(t)},this.Co=function(t){return e.Oo(t)})}return t.prototype.Do=function(t){return this.previousValue=Math.max(t,this.previousValue),this.previousValue},t.prototype.next=function(){var t=++this.previousValue;return this.Co&&this.Co(t),t},t.Fo=-1,t}(),__PRIVATE_Deferred=function(){var t=this;this.promise=new Promise((function(e,n){t.resolve=e,t.reject=n}))};!function(t){t.No="all",t.Mo="listen_stream_idle",t.Lo="listen_stream_connection_backoff",t.Go="write_stream_idle",t.Bo="write_stream_connection_backoff",t.Uo="online_state_timeout",t.ko="client_metadata_refresh",t.xo="lru_garbage_collection",t.Ko="retry_transaction"}(__PRIVATE_TimerId||(__PRIVATE_TimerId={}));var __PRIVATE_DelayedOperation=function(){function t(t,e,n,r,i){this.jo=t,this.qo=e,this.Qo=n,this.op=r,this.Wo=i,this.$o=new __PRIVATE_Deferred,this.then=this.$o.promise.then.bind(this.$o.promise),this.catch=this.$o.promise.catch.bind(this.$o.promise),this.$o.promise.catch((function(t){}))}return t.Yo=function(e,n,r,i,s){var o=new t(e,n,Date.now()+r,i,s);return o.start(r),o},t.prototype.start=function(t){var e=this;this.Ho=setTimeout((function(){return e.Xo()}),t)},t.prototype.zo=function(){return this.Xo()},t.prototype.cancel=function(t){null!==this.Ho&&(this.clearTimeout(),this.$o.reject(new FirestoreError(Code.CANCELLED,"Operation cancelled"+(t?": "+t:""))))},t.prototype.Xo=function(){var t=this;this.jo.Jo((function(){return null!==t.Ho?(t.clearTimeout(),t.op().then((function(e){return t.$o.resolve(e)}))):Promise.resolve()}))},t.prototype.clearTimeout=function(){null!==this.Ho&&(this.Wo(this),clearTimeout(this.Ho),this.Ho=null)},t}(),__PRIVATE_AsyncQueue=function(){function t(){this.Zo=Promise.resolve(),this.tu=!1,this.eu=[],this.nu=null,this.ru=!1,this.iu=[]}return Object.defineProperty(t.prototype,"su",{get:function(){return this.tu},enumerable:!0,configurable:!0}),t.prototype.Jo=function(t){this.enqueue(t)},t.prototype.ou=function(t){this.uu(),this.au(t)},t.prototype._u=function(t){return this.uu(),this.au(t)},t.prototype.cu=function(t){return tslib.__awaiter(this,void 0,void 0,(function(){return tslib.__generator(this,(function(e){switch(e.label){case 0:return this.uu(),this.tu?[3,2]:(this.tu=!0,[4,this._u(t)]);case 1:e.sent(),e.label=2;case 2:return[2]}}))}))},t.prototype.enqueue=function(t){return this.uu(),this.tu?new Promise((function(t){})):this.au(t)},t.prototype.au=function(t){var e=this,n=this.Zo.then((function(){return e.ru=!0,t().catch((function(t){e.nu=t,e.ru=!1;var n=t.stack||t.message||"";throw error("INTERNAL UNHANDLED ERROR: ",n),n.indexOf("Firestore Test Simulated Error")<0&&setTimeout((function(){throw t}),0),t})).then((function(t){return e.ru=!1,t}))}));return this.Zo=n,n},t.prototype.hu=function(t,e,n){var r=this;this.uu(),assert(e>=0,"Attempted to schedule an operation with a negative delay of "+e),this.iu.indexOf(t)>-1&&(e=0);var i=__PRIVATE_DelayedOperation.Yo(this,t,e,n,(function(t){return r.fu(t)}));return this.eu.push(i),i},t.prototype.uu=function(){this.nu&&fail("AsyncQueue is already failed: "+(this.nu.stack||this.nu.message))},t.prototype.lu=function(){assert(this.ru,"verifyOpInProgress() called when no op in progress on this queue.")},t.prototype.du=function(){return this._u((function(){return Promise.resolve()}))},t.prototype.Tu=function(t){for(var e=0,n=this.eu;e<n.length;e++){if(n[e].qo===t)return!0}return!1},t.prototype.Eu=function(t){var e=this;return this.du().then((function(){assert(t===__PRIVATE_TimerId.No||e.Tu(t),"Attempted to drain to missing operation "+t),e.eu.sort((function(t,e){return t.Qo-e.Qo}));for(var n=0,r=e.eu;n<r.length;n++){var i=r[n];if(i.zo(),t!==__PRIVATE_TimerId.No&&i.qo===t)break}return e.du()}))},t.prototype.Pu=function(t){this.iu.push(t)},t.prototype.fu=function(t){var e=this.eu.indexOf(t);assert(e>=0,"Delayed operation not found."),this.eu.splice(e,1)},t}();function __PRIVATE_bufferEntryComparator(t,e){var n=t[0],r=t[1],i=e[0],s=e[1],o=__PRIVATE_primitiveComparator(n,i);return 0===o?__PRIVATE_primitiveComparator(r,s):o}var __PRIVATE_RollingSequenceNumberBuffer=function(){function t(t){this.Au=t,this.buffer=new __PRIVATE_SortedSet(__PRIVATE_bufferEntryComparator),this.Ru=0}return t.prototype.Iu=function(){return++this.Ru},t.prototype.Vu=function(t){var e=[t,this.Iu()];if(this.buffer.size<this.Au)this.buffer=this.buffer.add(e);else{var n=this.buffer.last();__PRIVATE_bufferEntryComparator(e,n)<0&&(this.buffer=this.buffer.delete(n).add(e))}},Object.defineProperty(t.prototype,"maxValue",{get:function(){return this.buffer.last()[0]},enumerable:!0,configurable:!0}),t}(),__PRIVATE_GC_DID_NOT_RUN={mu:!1,vu:0,pu:0,bu:0},__PRIVATE_LruParams=function(){function t(t,e,n){this.gu=t,this.wu=e,this.yu=n}return t.Su=function(e){return new t(e,t.Du,t.Cu)},t.Ou=-1,t.Fu=1048576,t.Nu=41943040,t.Du=10,t.Cu=1e3,t.Mu=new t(t.Nu,t.Du,t.Cu),t.DISABLED=new t(t.Ou,0,0),t}(),__PRIVATE_INITIAL_GC_DELAY_MS=6e4,__PRIVATE_REGULAR_GC_DELAY_MS=3e5,__PRIVATE_LruScheduler=function(){function t(t,e,n){this.Lu=t,this.jo=e,this.Gu=n,this.Bu=!1,this.Uu=null}return t.prototype.start=function(){assert(null===this.Uu,"Cannot start an already started LruScheduler"),this.Lu.ku.gu!==__PRIVATE_LruParams.Ou&&this.xu()},t.prototype.stop=function(){this.Uu&&(this.Uu.cancel(),this.Uu=null)},Object.defineProperty(t.prototype,"Ku",{get:function(){return null!==this.Uu},enumerable:!0,configurable:!0}),t.prototype.xu=function(){var t=this;assert(null===this.Uu,"Cannot schedule GC while a task is pending");var e=this.Bu?__PRIVATE_REGULAR_GC_DELAY_MS:__PRIVATE_INITIAL_GC_DELAY_MS;debug("LruGarbageCollector","Garbage collection scheduled in "+e+"ms"),this.Uu=this.jo.hu(__PRIVATE_TimerId.xo,e,(function(){return t.Uu=null,t.Bu=!0,t.Gu.ju(t.Lu).then((function(){return t.xu()})).catch(__PRIVATE_ignoreIfPrimaryLeaseLoss)}))},t}(),__PRIVATE_LruGarbageCollector=function(){function t(t,e){this.qu=t,this.ku=e}return t.prototype.Qu=function(t,e){return this.qu.Wu(t).next((function(t){return Math.floor(e/100*t)}))},t.prototype.$u=function(t,e){var n=this;if(0===e)return PersistencePromise.resolve(__PRIVATE_ListenSequence.Fo);var r=new __PRIVATE_RollingSequenceNumberBuffer(e);return this.qu.jr(t,(function(t){return r.Vu(t.sequenceNumber)})).next((function(){return n.qu.Yu(t,(function(t){return r.Vu(t)}))})).next((function(){return r.maxValue}))},t.prototype.Hu=function(t,e,n){return this.qu.Hu(t,e,n)},t.prototype.Xu=function(t,e){return this.qu.Xu(t,e)},t.prototype.zu=function(t,e){var n=this;return this.ku.gu===__PRIVATE_LruParams.Ou?(debug("LruGarbageCollector","Garbage collection skipped; disabled"),PersistencePromise.resolve(__PRIVATE_GC_DID_NOT_RUN)):this.Ju(t).next((function(r){return r<n.ku.gu?(debug("LruGarbageCollector","Garbage collection skipped; Cache size "+r+" is lower than threshold "+n.ku.gu),__PRIVATE_GC_DID_NOT_RUN):n.Zu(t,e)}))},t.prototype.Ju=function(t){return this.qu.Ju(t)},t.prototype.Zu=function(t,e){var n,r,i,s,o,u,a,_=this,c=Date.now();return this.Qu(t,this.ku.wu).next((function(e){return e>_.ku.yu?(debug("LruGarbageCollector","Capping sequence numbers to collect down to the maximum of "+_.ku.yu+" from "+e),r=_.ku.yu):r=e,s=Date.now(),_.$u(t,r)})).next((function(r){return n=r,o=Date.now(),_.Hu(t,n,e)})).next((function(e){return i=e,u=Date.now(),_.Xu(t,n)})).next((function(t){(a=Date.now(),__PRIVATE_getLogLevel()<=LogLevel.DEBUG)&&debug("LruGarbageCollector","LRU Garbage Collection\n\tCounted targets in "+(s-c)+"ms\n\tDetermined least recently used "+r+" in "+(o-s)+"ms\n\tRemoved "+i+" targets in "+(u-o)+"ms\n\tRemoved "+t+" documents in "+(a-u)+"ms\nTotal Duration: "+(a-c)+"ms");return PersistencePromise.resolve({mu:!0,vu:r,pu:i,bu:t})}))},t}(),__PRIVATE_LOG_TAG$1="LocalStore",__PRIVATE_LocalStore=function(){function t(t,e,n){this.persistence=t,this.ta=e,this.ea=new __PRIVATE_ReferenceSet,this.na=new __PRIVATE_SortedMap(__PRIVATE_primitiveComparator),this.ra=new __PRIVATE_ObjectMap((function(t){return t.canonicalId()})),this.ia=__PRIVATE_SnapshotVersion.MIN,assert(t.Ku,"LocalStore was passed an unstarted persistence implementation"),this.persistence.oa.sa(this.ea),this._o=t.ua(n),this.aa=t._a(),this.ca=t.ha(),this.fa=new __PRIVATE_LocalDocumentsView(this.aa,this._o,this.persistence.la()),this.ta.da(this.fa)}return t.prototype.start=function(){return this.Ta()},t.prototype.Ea=function(t){return tslib.__awaiter(this,void 0,void 0,(function(){var e,n,r,i=this;return tslib.__generator(this,(function(s){switch(s.label){case 0:return e=this._o,n=this.fa,[4,this.persistence.runTransaction("Handle user change","readonly-idempotent",(function(r){var s;return i._o.Pa(r).next((function(o){return s=o,e=i.persistence.ua(t),n=new __PRIVATE_LocalDocumentsView(i.aa,e,i.persistence.la()),e.Pa(r)})).next((function(t){for(var e=[],i=[],o=__PRIVATE_documentKeySet(),u=0,a=s;u<a.length;u++){var _=a[u];e.push(_.batchId);for(var c=0,h=_.mutations;c<h.length;c++){var f=h[c];o=o.add(f.key)}}for(var l=0,d=t;l<d.length;l++){_=d[l];i.push(_.batchId);for(var T=0,E=_.mutations;T<E.length;T++){f=E[T];o=o.add(f.key)}}return n.To(r,o).next((function(t){return{Aa:t,Ra:e,Ia:i}}))}))}))];case 1:return r=s.sent(),this._o=e,this.fa=n,this.ta.da(this.fa),[2,r]}}))}))},t.prototype.Va=function(t){var e,n=this,r=Timestamp.now(),i=t.reduce((function(t,e){return t.add(e.key)}),__PRIVATE_documentKeySet());return this.persistence.runTransaction("Locally write mutations","readwrite-idempotent",(function(s){return n.fa.To(s,i).next((function(i){e=i;for(var o=[],u=0,a=t;u<a.length;u++){var _=a[u],c=_.Te(e.get(_.key));null!=c&&o.push(new __PRIVATE_PatchMutation(_.key,c,c.Ee(),Precondition.exists(!0)))}return n._o.ma(s,r,o,t)}))})).then((function(t){var n=t.vs(e);return{batchId:t.batchId,Hs:n}}))},t.prototype.va=function(t){var e=this;return this.persistence.runTransaction("Lookup mutation documents","readonly-idempotent",(function(n){return e._o.pa(n,t).next((function(t){return t?e.fa.To(n,t):PersistencePromise.resolve(null)}))}))},t.prototype.ba=function(t){var e=this;return this.persistence.runTransaction("Acknowledge batch","readwrite-primary-idempotent",(function(n){var r=t.batch.keys(),i=e.aa.ga({wa:!0});return e._o.ba(n,t.batch,t.streamToken).next((function(){return e.ya(n,t,i)})).next((function(){return i.apply(n)})).next((function(){return e._o.Sa(n)})).next((function(){return e.fa.To(n,r)}))}))},t.prototype.Da=function(t){var e=this;return this.persistence.runTransaction("Reject batch","readwrite-primary-idempotent",(function(n){var r;return e._o.Ca(n,t).next((function(t){return assert(null!==t,"Attempt to reject nonexistent batch!"),r=t.keys(),e._o.Oa(n,t)})).next((function(){return e._o.Sa(n)})).next((function(){return e.fa.To(n,r)}))}))},t.prototype.Fa=function(){var t=this;return this.persistence.runTransaction("Get highest unacknowledged batch id","readonly-idempotent",(function(e){return t._o.Fa(e)}))},t.prototype.Na=function(){var t=this;return this.persistence.runTransaction("Get last stream token","readonly-idempotent",(function(e){return t._o.Na(e)}))},t.prototype.Ma=function(t){var e=this;return this.persistence.runTransaction("Set last stream token","readwrite-primary-idempotent",(function(n){return e._o.Ma(n,t)}))},t.prototype.La=function(){var t=this;return this.persistence.runTransaction("Get last remote snapshot version","readonly-idempotent",(function(e){return t.ca.La(e)}))},t.prototype.Ga=function(e){var n=this,r=e.Ln,i=this.na;return this.persistence.runTransaction("Apply remote event","readwrite-primary-idempotent",(function(s){var o=n.aa.ga({wa:!0});i=n.na;var u=[];__PRIVATE_forEachNumber(e.nr,(function(e,o){var a=i.get(e);if(a){u.push(n.ca.Ba(s,o.hr,e).next((function(){return n.ca.Ua(s,o._r,e)})));var _=o.resumeToken;if(_.length>0){var c=a.Bn(_,r).Gn(s.ka);i=i.At(e,c),t.xa(a,c,o)&&u.push(n.ca.Ka(s,c))}}}));var a=__PRIVATE_maybeDocumentMap(),_=__PRIVATE_documentKeySet();if(e.ir.forEach((function(t,e){_=_.add(t)})),u.push(o.getEntries(s,_).next((function(t){e.ir.forEach((function(i,_){var c=t.get(i);_ instanceof __PRIVATE_NoDocument&&_.version.isEqual(__PRIVATE_SnapshotVersion.MIN)?(o.to(i,r),a=a.At(i,_)):null==c||_.version._(c.version)>0||0===_.version._(c.version)&&c.hasPendingWrites?(assert(!__PRIVATE_SnapshotVersion.MIN.isEqual(r),"Cannot add a document when the remote version is zero"),o.Js(_,r),a=a.At(i,_)):debug(__PRIVATE_LOG_TAG$1,"Ignoring outdated watch update for ",i,". Current version:",c.version," Watch version:",_.version),e.sr.has(i)&&u.push(n.persistence.oa.ja(s,i))}))}))),!r.isEqual(__PRIVATE_SnapshotVersion.MIN)){var c=n.ca.La(s).next((function(t){return assert(r._(t)>=0,"Watch stream reverted to previous snapshot?? "+r+" < "+t),n.ca.qa(s,s.ka,r)}));u.push(c)}return PersistencePromise.$s(u).next((function(){return o.apply(s)})).next((function(){return n.fa.Eo(s,a)}))})).then((function(t){return n.na=i,t}))},t.xa=function(t,e,n){return assert(e.resumeToken.length>0,"Attempted to persist target data with no resume token"),0===t.resumeToken.length||(e.Ln.$()-t.Ln.$()>=this.Qa||n._r.size+n.cr.size+n.hr.size>0)},t.prototype.Wa=function(t){for(var e=this,n=0,r=t;n<r.length;n++){var i=r[n],s=i.targetId;if(this.ea.Ds(i.bo,s),this.ea.Fs(i.wo,s),!i.fromCache){var o=this.na.get(s);assert(null!==o,"Can't set limbo-free snapshot version for unknown target: "+s);var u=o.Ln,a=o.Un(u);this.na=this.na.At(s,a)}}return this.persistence.runTransaction("notifyLocalViewChanges","readwrite-idempotent",(function(n){return PersistencePromise.forEach(t,(function(t){return PersistencePromise.forEach(t.wo,(function(t){return e.persistence.oa.Cs(n,t)}))}))}))},t.prototype.$a=function(t){var e=this;return this.persistence.runTransaction("Get next mutation batch","readonly-idempotent",(function(n){return void 0===t&&(t=__PRIVATE_BATCHID_UNKNOWN),e._o.Ya(n,t)}))},t.prototype.Ha=function(t){var e=this;return this.persistence.runTransaction("read document","readonly-idempotent",(function(n){return e.fa.ho(n,t)}))},t.prototype.Xa=function(t){var e=this;return this.persistence.runTransaction("Allocate target","readwrite-idempotent",(function(n){var r;return e.ca.za(n,t).next((function(i){return i?(r=i,PersistencePromise.resolve(r)):e.ca.Ja(n).next((function(i){return r=new __PRIVATE_TargetData(t,i,__PRIVATE_TargetPurpose.On,n.ka),e.ca.Za(n,r).next((function(){return r}))}))}))})).then((function(n){return null===e.na.get(n.targetId)&&(e.na=e.na.At(n.targetId,n),e.ra.set(t,n.targetId)),n}))},t.prototype.za=function(t,e){var n=this.ra.get(e);return void 0!==n?PersistencePromise.resolve(this.na.get(n)):this.ca.za(t,e)},t.prototype.t_=function(t,e){var n=this,r=this.na.get(t);assert(null!==r,"Tried to release nonexistent target: "+t);var i=e?"readwrite-idempotent":"readwrite-primary-idempotent";return this.persistence.runTransaction("Release target",i,(function(i){var s=n.ea.Ns(t);return e?PersistencePromise.resolve():PersistencePromise.forEach(s,(function(t){return n.persistence.oa.Cs(i,t)})).next((function(){n.persistence.oa.removeTarget(i,r)}))})).then((function(){n.na=n.na.remove(t),n.ra.delete(r.target)}))},t.prototype.e_=function(t,e){var n=this,r=__PRIVATE_SnapshotVersion.MIN,i=__PRIVATE_documentKeySet();return this.persistence.runTransaction("Execute query","readonly-idempotent",(function(s){return n.za(s,t.Rn()).next((function(t){if(t)return r=t.lastLimboFreeSnapshotVersion,n.ca.n_(s,t.targetId).next((function(t){i=t}))})).next((function(){return n.ta.Ao(s,t,e?r:__PRIVATE_SnapshotVersion.MIN,e?i:__PRIVATE_documentKeySet())})).next((function(t){return{documents:t,r_:i}}))}))},t.prototype.i_=function(t){var e=this;return this.persistence.runTransaction("Remote document keys","readonly-idempotent",(function(n){return e.ca.n_(n,t)}))},t.prototype.s_=function(){return this.persistence.s_()},t.prototype.o_=function(t){this._o.u_(t)},t.prototype.a_=function(t){this.persistence.a_(t)},t.prototype.ya=function(t,e,n){var r=this,i=e.batch,s=i.keys(),o=PersistencePromise.resolve();return s.forEach((function(r){o=o.next((function(){return n.eo(t,r)})).next((function(t){var s=t,o=e.bs.get(r);assert(null!==o,"ackVersions should contain every doc in the write."),(!s||s.version._(o)<0)&&((s=i.Jt(r,s,e))?n.Js(s,e.ps):assert(!t,"Mutation batch "+i+" applied to document "+t+" resulted in null"))}))})),o.next((function(){return r._o.Oa(t,i)}))},t.prototype.ju=function(t){var e=this;return this.persistence.runTransaction("Collect garbage","readwrite-primary-idempotent",(function(n){return t.zu(n,e.na)}))},t.prototype.__=function(t){var e=this,n=this.na.get(t);return n?Promise.resolve(n.target):this.persistence.runTransaction("Get target data","readonly-idempotent",(function(n){return e.ca.ti(n,t).next((function(t){return t?t.target:null}))}))},t.prototype.c_=function(){var t=this;return this.persistence.runTransaction("Get new document changes","readonly-idempotent",(function(e){return t.aa.c_(e,t.ia)})).then((function(e){var n=e.h_,r=e.readTime;return t.ia=r,n}))},t.prototype.Ta=function(){return tslib.__awaiter(this,void 0,void 0,(function(){var t,e=this;return tslib.__generator(this,(function(n){switch(n.label){case 0:return t=this,[4,this.persistence.runTransaction("Synchronize last document change read time","readonly-idempotent",(function(t){return e.aa.f_(t)}))];case 1:return t.ia=n.sent(),[2]}}))}))},t.Qa=3e8,t}();function __PRIVATE_ignoreIfPrimaryLeaseLoss(t){return tslib.__awaiter(this,void 0,void 0,(function(){return tslib.__generator(this,(function(e){if(t.code!==Code.FAILED_PRECONDITION||t.message!==__PRIVATE_PRIMARY_LEASE_LOST_ERROR_MSG)throw t;return debug(__PRIVATE_LOG_TAG$1,"Unexpectedly lost primary lease"),[2]}))}))}var FieldPath$1=function(){function t(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];__PRIVATE_validateNamedArrayAtLeastNumberOfElements("FieldPath",t,"fieldNames",1);for(var n=0;n<t.length;++n)if(__PRIVATE_validateArgType("FieldPath","string",n,t[n]),0===t[n].length)throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid field name at argument $(i + 1). Field names must not be empty.");this.l_=new FieldPath(t)}return t.documentId=function(){return t.d_},t.prototype.isEqual=function(e){if(!(e instanceof t))throw __PRIVATE_invalidClassError("isEqual","FieldPath",1,e);return this.l_.isEqual(e.l_)},t.d_=new t(FieldPath.ft().ut()),t}(),__PRIVATE_RESERVED=new RegExp("[~\\*/\\[\\]]");function __PRIVATE_fromDotSeparatedString(t){if(t.search(__PRIVATE_RESERVED)>=0)throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid field path ("+t+"). Paths must not contain '~', '*', '/', '[', or ']'");try{return new(FieldPath$1.bind.apply(FieldPath$1,tslib.__spreadArrays([void 0],t.split("."))))}catch(e){throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid field path ("+t+"). Paths must not be empty, begin with '.', end with '.', or contain '..'")}}var __PRIVATE_UserDataSource,__PRIVATE_FieldValueImpl=function(){function t(t){this.T_=t}return t.delete=function(){return __PRIVATE_validateNoArgs("FieldValue.delete",arguments),__PRIVATE_DeleteFieldValueImpl.instance},t.serverTimestamp=function(){return __PRIVATE_validateNoArgs("FieldValue.serverTimestamp",arguments),__PRIVATE_ServerTimestampFieldValueImpl.instance},t.arrayUnion=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return __PRIVATE_validateAtLeastNumberOfArgs("FieldValue.arrayUnion",arguments,1),new __PRIVATE_ArrayUnionFieldValueImpl(t)},t.arrayRemove=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return __PRIVATE_validateAtLeastNumberOfArgs("FieldValue.arrayRemove",arguments,1),new __PRIVATE_ArrayRemoveFieldValueImpl(t)},t.increment=function(t){return __PRIVATE_validateArgType("FieldValue.increment","number",1,t),__PRIVATE_validateExactNumberOfArgs("FieldValue.increment",arguments,1),new __PRIVATE_NumericIncrementFieldValueImpl(t)},t.prototype.isEqual=function(t){return this===t},t}(),__PRIVATE_DeleteFieldValueImpl=function(t){function e(){return t.call(this,"FieldValue.delete")||this}return tslib.__extends(e,t),e.instance=new e,e}(__PRIVATE_FieldValueImpl),__PRIVATE_ServerTimestampFieldValueImpl=function(t){function e(){return t.call(this,"FieldValue.serverTimestamp")||this}return tslib.__extends(e,t),e.instance=new e,e}(__PRIVATE_FieldValueImpl),__PRIVATE_ArrayUnionFieldValueImpl=function(t){function e(e){var n=t.call(this,"FieldValue.arrayUnion")||this;return n.E_=e,n}return tslib.__extends(e,t),e}(__PRIVATE_FieldValueImpl),__PRIVATE_ArrayRemoveFieldValueImpl=function(t){function e(e){var n=t.call(this,"FieldValue.arrayRemove")||this;return n.E_=e,n}return tslib.__extends(e,t),e}(__PRIVATE_FieldValueImpl),__PRIVATE_NumericIncrementFieldValueImpl=function(t){function e(e){var n=t.call(this,"FieldValue.increment")||this;return n.P_=e,n}return tslib.__extends(e,t),e}(__PRIVATE_FieldValueImpl),__PRIVATE_PublicFieldValue=__PRIVATE_makeConstructorPrivate(__PRIVATE_FieldValueImpl,"Use FieldValue.<field>() instead."),__PRIVATE_RESERVED_FIELD_REGEX=/^__.*__$/,__PRIVATE_ParsedSetData=function(){function t(t,e,n){this.data=t,this.Ee=e,this.fieldTransforms=n}return t.prototype.A_=function(t,e){var n=[];return null!==this.Ee?n.push(new __PRIVATE_PatchMutation(t,this.data,this.Ee,e)):n.push(new __PRIVATE_SetMutation(t,this.data,e)),this.fieldTransforms.length>0&&n.push(new __PRIVATE_TransformMutation(t,this.fieldTransforms)),n},t}(),__PRIVATE_ParsedUpdateData=function(){function t(t,e,n){this.data=t,this.Ee=e,this.fieldTransforms=n}return t.prototype.A_=function(t,e){var n=[new __PRIVATE_PatchMutation(t,this.data,this.Ee,e)];return this.fieldTransforms.length>0&&n.push(new __PRIVATE_TransformMutation(t,this.fieldTransforms)),n},t}();function __PRIVATE_isWrite(t){switch(t){case __PRIVATE_UserDataSource.Set:case __PRIVATE_UserDataSource.R_:case __PRIVATE_UserDataSource.I_:return!0;case __PRIVATE_UserDataSource.V_:case __PRIVATE_UserDataSource.m_:return!1;default:throw fail("Unexpected case for UserDataSource: "+t)}}!function(t){t[t.Set=0]="Set",t[t.I_=1]="__PRIVATE_Update",t[t.R_=2]="__PRIVATE_MergeSet",t[t.V_=3]="__PRIVATE_Argument",t[t.m_=4]="__PRIVATE_ArrayArgument"}(__PRIVATE_UserDataSource||(__PRIVATE_UserDataSource={}));var __PRIVATE_ParseContext=function(){function t(t,e,n,r,i,s){this.v_=t,this.methodName=e,this.path=n,this.p_=r,void 0===i&&this.b_(),this.p_=void 0!==r&&r,this.fieldTransforms=i||[],this.Ee=s||[]}return t.prototype.g_=function(e){var n=null==this.path?null:this.path.child(e),r=new t(this.v_,this.methodName,n,!1,this.fieldTransforms,this.Ee);return r.w_(e),r},t.prototype.y_=function(e){var n=null==this.path?null:this.path.child(e),r=new t(this.v_,this.methodName,n,!1,this.fieldTransforms,this.Ee);return r.b_(),r},t.prototype.S_=function(e){return new t(this.v_,this.methodName,null,!0,this.fieldTransforms,this.Ee)},t.prototype.D_=function(t){var e=null===this.path||this.path.et()?"":" (found in field "+this.path.toString()+")";return new FirestoreError(Code.INVALID_ARGUMENT,"Function "+this.methodName+"() called with invalid data. "+t+e)},t.prototype.contains=function(t){return void 0!==this.Ee.find((function(e){return t.it(e)}))||void 0!==this.fieldTransforms.find((function(e){return t.it(e.field)}))},t.prototype.b_=function(){if(null!==this.path)for(var t=0;t<this.path.length;t++)this.w_(this.path.get(t))},t.prototype.w_=function(t){if(0===t.length)throw this.D_("Document fields must not be empty");if(__PRIVATE_isWrite(this.v_)&&__PRIVATE_RESERVED_FIELD_REGEX.test(t))throw this.D_('Document fields cannot begin and end with "__"')},t}(),__PRIVATE_DocumentKeyReference=function(t,e){this.o=t,this.key=e},__PRIVATE_UserDataConverter=function(){function t(t){this.C_=t}return t.prototype.O_=function(t,e){var n=new __PRIVATE_ParseContext(__PRIVATE_UserDataSource.Set,t,FieldPath._t);__PRIVATE_validatePlainObject("Data must be an object, but it was:",n,e);var r=this.F_(e,n);return new __PRIVATE_ParsedSetData(r,null,n.fieldTransforms)},t.prototype.N_=function(t,e,n){var r=new __PRIVATE_ParseContext(__PRIVATE_UserDataSource.R_,t,FieldPath._t);__PRIVATE_validatePlainObject("Data must be an object, but it was:",r,e);var i,s,o=this.F_(e,r);if(n){for(var u=new __PRIVATE_SortedSet(FieldPath.X),a=0,_=n;a<_.length;a++){var c=_[a],h=void 0;if(c instanceof FieldPath$1)h=c.l_;else{if("string"!=typeof c)throw fail("Expected stringOrFieldPath to be a string or a FieldPath");h=__PRIVATE_fieldPathFromDotSeparatedString(t,c)}if(!r.contains(h))throw new FirestoreError(Code.INVALID_ARGUMENT,"Field '"+h+"' is specified in your field mask but missing from your input data.");u=u.add(h)}i=__PRIVATE_FieldMask.ne(u),s=r.fieldTransforms.filter((function(t){return i.ie(t.field)}))}else i=__PRIVATE_FieldMask.re(r.Ee),s=r.fieldTransforms;return new __PRIVATE_ParsedSetData(o,i,s)},t.prototype.M_=function(t,e){var n=this,r=new __PRIVATE_ParseContext(__PRIVATE_UserDataSource.I_,t,FieldPath._t);__PRIVATE_validatePlainObject("Data must be an object, but it was:",r,e);var i=new __PRIVATE_SortedSet(FieldPath.X),s=__PRIVATE_ObjectValue.EMPTY;forEach(e,(function(e,o){var u=__PRIVATE_fieldPathFromDotSeparatedString(t,e),a=r.y_(u);if((o=n.L_(o,a))instanceof __PRIVATE_DeleteFieldValueImpl)i=i.add(u);else{var _=n.F_(o,a);null!=_&&(i=i.add(u),s=s.set(u,_))}}));var o=__PRIVATE_FieldMask.ne(i);return new __PRIVATE_ParsedUpdateData(s,o,r.fieldTransforms)},t.prototype.G_=function(t,e,n,r){var i=new __PRIVATE_ParseContext(__PRIVATE_UserDataSource.I_,t,FieldPath._t),s=[__PRIVATE_fieldPathFromArgument(t,e)],o=[n];if(r.length%2!=0)throw new FirestoreError(Code.INVALID_ARGUMENT,"Function "+t+"() needs to be called with an even number of arguments that alternate between field names and values.");for(var u=0;u<r.length;u+=2)s.push(__PRIVATE_fieldPathFromArgument(t,r[u])),o.push(r[u+1]);var a=new __PRIVATE_SortedSet(FieldPath.X),_=__PRIVATE_ObjectValue.EMPTY;for(u=0;u<s.length;++u){var c=s[u],h=i.y_(c),f=this.L_(o[u],h);if(f instanceof __PRIVATE_DeleteFieldValueImpl)a=a.add(c);else{var l=this.F_(f,h);null!=l&&(a=a.add(c),_=_.set(c,l))}}var d=__PRIVATE_FieldMask.ne(a);return new __PRIVATE_ParsedUpdateData(_,d,i.fieldTransforms)},t.prototype.B_=function(t,e,n){void 0===n&&(n=!1);var r=new __PRIVATE_ParseContext(n?__PRIVATE_UserDataSource.m_:__PRIVATE_UserDataSource.V_,t,FieldPath._t),i=this.F_(e,r);return assert(null!=i,"Parsed data should not be null."),assert(0===r.fieldTransforms.length,"Field transforms should have been disallowed."),i},t.prototype.L_=function(t,e){try{return this.C_(t)}catch(t){var n=__PRIVATE_errorMessage(t);throw e.D_(n)}},t.prototype.F_=function(t,e){if(__PRIVATE_looksLikeJsonObject(t=this.L_(t,e)))return __PRIVATE_validatePlainObject("Unsupported field value:",e,t),this.U_(t,e);if(t instanceof __PRIVATE_FieldValueImpl)return this.k_(t,e),null;if(e.path&&e.Ee.push(e.path),t instanceof Array){if(e.p_&&e.v_!==__PRIVATE_UserDataSource.m_)throw e.D_("Nested arrays are not supported");return this.x_(t,e)}return this.K_(t,e)},t.prototype.U_=function(t,e){var n=this,r=new __PRIVATE_SortedMap(__PRIVATE_primitiveComparator);return __PRIVATE_isEmpty(t)?e.path&&e.path.length>0&&e.Ee.push(e.path):forEach(t,(function(t,i){var s=n.F_(i,e.g_(t));null!=s&&(r=r.At(t,s))})),new __PRIVATE_ObjectValue(r)},t.prototype.x_=function(t,e){for(var n=[],r=0,i=0,s=t;i<s.length;i++){var o=s[i],u=this.F_(o,e.S_(r));null==u&&(u=__PRIVATE_NullValue.ke),n.push(u),r++}return new ArrayValue(n)},t.prototype.k_=function(t,e){if(!__PRIVATE_isWrite(e.v_))throw e.D_(t.T_+"() can only be used with update() and set()");if(null===e.path)throw e.D_(t.T_+"() is not currently supported inside arrays");if(t instanceof __PRIVATE_DeleteFieldValueImpl){if(e.v_!==__PRIVATE_UserDataSource.R_)throw e.v_===__PRIVATE_UserDataSource.I_?(assert(e.path.length>0,"FieldValue.delete() at the top level should have already been handled."),e.D_("FieldValue.delete() can only appear at the top level of your update data")):e.D_("FieldValue.delete() cannot be used with set() unless you pass {merge:true}");e.Ee.push(e.path)}else if(t instanceof __PRIVATE_ServerTimestampFieldValueImpl)e.fieldTransforms.push(new FieldTransform(e.path,__PRIVATE_ServerTimestampTransform.instance));else if(t instanceof __PRIVATE_ArrayUnionFieldValueImpl){var n=this.j_(t.T_,t.E_),r=new __PRIVATE_ArrayUnionTransformOperation(n);e.fieldTransforms.push(new FieldTransform(e.path,r))}else if(t instanceof __PRIVATE_ArrayRemoveFieldValueImpl){n=this.j_(t.T_,t.E_);var i=new __PRIVATE_ArrayRemoveTransformOperation(n);e.fieldTransforms.push(new FieldTransform(e.path,i))}else if(t instanceof __PRIVATE_NumericIncrementFieldValueImpl){var s=this.B_("FieldValue.increment",t.P_),o=new __PRIVATE_NumericIncrementTransformOperation(s);e.fieldTransforms.push(new FieldTransform(e.path,o))}else fail("Unknown FieldValue type: "+t)},t.prototype.K_=function(t,e){if(null===t)return __PRIVATE_NullValue.ke;if("number"==typeof t)return isSafeInteger(t)?new __PRIVATE_IntegerValue(t):new __PRIVATE_DoubleValue(t);if("boolean"==typeof t)return __PRIVATE_BooleanValue.of(t);if("string"==typeof t)return new __PRIVATE_StringValue(t);if(t instanceof Date)return new __PRIVATE_TimestampValue(Timestamp.fromDate(t));if(t instanceof Timestamp)return new __PRIVATE_TimestampValue(new Timestamp(t.seconds,1e3*Math.floor(t.nanoseconds/1e3)));if(t instanceof GeoPoint)return new __PRIVATE_GeoPointValue(t);if(t instanceof Blob)return new __PRIVATE_BlobValue(t);if(t instanceof __PRIVATE_DocumentKeyReference)return new __PRIVATE_RefValue(t.o,t.key);throw e.D_("Unsupported field value: "+__PRIVATE_valueDescription(t))},t.prototype.j_=function(t,e){var n=this;return e.map((function(e,r){var i=new __PRIVATE_ParseContext(__PRIVATE_UserDataSource.V_,t,FieldPath._t);return n.F_(e,i.S_(r))}))},t}();function __PRIVATE_looksLikeJsonObject(t){return!("object"!=typeof t||null===t||t instanceof Array||t instanceof Date||t instanceof Timestamp||t instanceof GeoPoint||t instanceof Blob||t instanceof __PRIVATE_DocumentKeyReference||t instanceof __PRIVATE_FieldValueImpl)}function __PRIVATE_validatePlainObject(t,e,n){if(!__PRIVATE_looksLikeJsonObject(n)||!__PRIVATE_isPlainObject(n)){var r=__PRIVATE_valueDescription(n);throw"an object"===r?e.D_(t+" a custom object"):e.D_(t+" "+r)}}function __PRIVATE_fieldPathFromArgument(t,e){if(e instanceof FieldPath$1)return e.l_;if("string"==typeof e)return __PRIVATE_fieldPathFromDotSeparatedString(t,e);throw new FirestoreError(Code.INVALID_ARGUMENT,"Function "+t+"() called with invalid data. Field path arguments must be of type string or FieldPath.")}function __PRIVATE_fieldPathFromDotSeparatedString(t,e){try{return __PRIVATE_fromDotSeparatedString(e).l_}catch(e){var n=__PRIVATE_errorMessage(e);throw new FirestoreError(Code.INVALID_ARGUMENT,"Function "+t+"() called with invalid data. "+n)}}function __PRIVATE_errorMessage(t){return t instanceof Error?t.message:t.toString()}var __PRIVATE_PersistentStreamState,__PRIVATE_LOG_TAG$2="ExponentialBackoff",__PRIVATE_DEFAULT_BACKOFF_INITIAL_DELAY_MS=1e3,__PRIVATE_DEFAULT_BACKOFF_FACTOR=1.5,__PRIVATE_DEFAULT_BACKOFF_MAX_DELAY_MS=6e4,__PRIVATE_ExponentialBackoff=function(){function t(t,e,n,r,i){void 0===n&&(n=__PRIVATE_DEFAULT_BACKOFF_INITIAL_DELAY_MS),void 0===r&&(r=__PRIVATE_DEFAULT_BACKOFF_FACTOR),void 0===i&&(i=__PRIVATE_DEFAULT_BACKOFF_MAX_DELAY_MS),this.q_=t,this.qo=e,this.Q_=n,this.W_=r,this.Y_=i,this.H_=0,this.X_=null,this.z_=Date.now(),this.reset()}return t.prototype.reset=function(){this.H_=0},t.prototype.J_=function(){this.H_=this.Y_},t.prototype.Z_=function(t){var e=this;this.cancel();var n=Math.floor(this.H_+this.tc()),r=Math.max(0,Date.now()-this.z_),i=Math.max(0,n-r);this.H_>0&&debug(__PRIVATE_LOG_TAG$2,"Backing off for "+i+" ms (base delay: "+this.H_+" ms, delay with jitter: "+n+" ms, last attempt: "+r+" ms ago)"),this.X_=this.q_.hu(this.qo,i,(function(){return e.z_=Date.now(),t()})),this.H_*=this.W_,this.H_<this.Q_&&(this.H_=this.Q_),this.H_>this.Y_&&(this.H_=this.Y_)},t.prototype.cancel=function(){null!==this.X_&&(this.X_.cancel(),this.X_=null)},t.prototype.tc=function(){return(Math.random()-.5)*this.H_},t}(),__PRIVATE_LOG_TAG$3="PersistentStream";!function(t){t[t.ec=0]="__PRIVATE_Initial",t[t.nc=1]="__PRIVATE_Starting",t[t.rc=2]="__PRIVATE_Open",t[t.Error=3]="Error",t[t.ic=4]="__PRIVATE_Backoff"}(__PRIVATE_PersistentStreamState||(__PRIVATE_PersistentStreamState={}));var __PRIVATE_IDLE_TIMEOUT_MS=6e4,__PRIVATE_PersistentStream=function(){function t(t,e,n,r,i,s){this.q_=t,this.sc=n,this.oc=r,this.uc=i,this.listener=s,this.state=__PRIVATE_PersistentStreamState.ec,this.ac=0,this._c=null,this.stream=null,this.cc=new __PRIVATE_ExponentialBackoff(t,e)}return t.prototype.hc=function(){return this.state===__PRIVATE_PersistentStreamState.nc||this.state===__PRIVATE_PersistentStreamState.rc||this.state===__PRIVATE_PersistentStreamState.ic},t.prototype.fc=function(){return this.state===__PRIVATE_PersistentStreamState.rc},t.prototype.start=function(){this.state!==__PRIVATE_PersistentStreamState.Error?(assert(this.state===__PRIVATE_PersistentStreamState.ec,"Already started"),this.auth()):this.lc()},t.prototype.stop=function(){return tslib.__awaiter(this,void 0,void 0,(function(){return tslib.__generator(this,(function(t){switch(t.label){case 0:return this.hc()?[4,this.close(__PRIVATE_PersistentStreamState.ec)]:[3,2];case 1:t.sent(),t.label=2;case 2:return[2]}}))}))},t.prototype.dc=function(){assert(!this.hc(),"Can only inhibit backoff in a stopped state"),this.state=__PRIVATE_PersistentStreamState.ec,this.cc.reset()},t.prototype.Tc=function(){var t=this;this.fc()&&null===this._c&&(this._c=this.q_.hu(this.sc,__PRIVATE_IDLE_TIMEOUT_MS,(function(){return t.Ec()})))},t.prototype.Pc=function(t){this.Ac(),this.stream.send(t)},t.prototype.Ec=function(){return tslib.__awaiter(this,void 0,void 0,(function(){return tslib.__generator(this,(function(t){return this.fc()?[2,this.close(__PRIVATE_PersistentStreamState.ec)]:[2]}))}))},t.prototype.Ac=function(){this._c&&(this._c.cancel(),this._c=null)},t.prototype.close=function(t,e){return tslib.__awaiter(this,void 0,void 0,(function(){return tslib.__generator(this,(function(n){switch(n.label){case 0:return assert(this.hc(),"Only started streams should be closed."),assert(t===__PRIVATE_PersistentStreamState.Error||__PRIVATE_isNullOrUndefined(e),"Can't provide an error when not in an error state."),this.Ac(),this.cc.cancel(),this.ac++,t!==__PRIVATE_PersistentStreamState.Error?this.cc.reset():e&&e.code===Code.RESOURCE_EXHAUSTED?(error(e.toString()),error("Using maximum backoff delay to prevent overloading the backend."),this.cc.J_()):e&&e.code===Code.UNAUTHENTICATED&&this.uc.g(),null!==this.stream&&(this.Rc(),this.stream.close(),this.stream=null),this.state=t,[4,this.listener.Ic(e)];case 1:return n.sent(),[2]}}))}))},t.prototype.Rc=function(){},t.prototype.auth=function(){var t=this;assert(this.state===__PRIVATE_PersistentStreamState.ec,"Must be in initial state to auth"),this.state=__PRIVATE_PersistentStreamState.nc;var e=this.Vc(this.ac),n=this.ac;this.uc.getToken().then((function(e){t.ac===n&&t.mc(e)}),(function(n){e((function(){var e=new FirestoreError(Code.UNKNOWN,"Fetching auth token failed: "+n.message);return t.vc(e)}))}))},t.prototype.mc=function(t){var e=this;assert(this.state===__PRIVATE_PersistentStreamState.nc,"Trying to start stream in a non-starting state");var n=this.Vc(this.ac);this.stream=this.pc(t),this.stream.bc((function(){n((function(){return assert(e.state===__PRIVATE_PersistentStreamState.nc,"Expected stream to be in state Starting, but was "+e.state),e.state=__PRIVATE_PersistentStreamState.rc,e.listener.bc()}))})),this.stream.Ic((function(t){n((function(){return e.vc(t)}))})),this.stream.onMessage((function(t){n((function(){return e.onMessage(t)}))}))},t.prototype.lc=function(){var t=this;assert(this.state===__PRIVATE_PersistentStreamState.Error,"Should only perform backoff when in Error state"),this.state=__PRIVATE_PersistentStreamState.ic,this.cc.Z_((function(){return tslib.__awaiter(t,void 0,void 0,(function(){return tslib.__generator(this,(function(t){return assert(this.state===__PRIVATE_PersistentStreamState.ic,"Backoff elapsed but state is now: "+this.state),this.state=__PRIVATE_PersistentStreamState.ec,this.start(),assert(this.hc(),"PersistentStream should have started"),[2]}))}))}))},t.prototype.vc=function(t){return assert(this.hc(),"Can't handle server close on non-started stream"),debug(__PRIVATE_LOG_TAG$3,"close with error: "+t),this.stream=null,this.close(__PRIVATE_PersistentStreamState.Error,t)},t.prototype.Vc=function(t){var e=this;return function(n){e.q_.Jo((function(){return e.ac===t?n():(debug(__PRIVATE_LOG_TAG$3,"stream callback skipped by getCloseGuardedDispatcher."),Promise.resolve())}))}},t}(),__PRIVATE_PersistentListenStream=function(t){function e(e,n,r,i,s){var o=t.call(this,e,__PRIVATE_TimerId.Lo,__PRIVATE_TimerId.Mo,n,r,s)||this;return o.serializer=i,o}return tslib.__extends(e,t),e.prototype.pc=function(t){return this.oc.gc("Listen",t)},e.prototype.onMessage=function(t){this.cc.reset();var e=this.serializer.Ni(t),n=this.serializer.Li(t);return this.listener.wc(e,n)},e.prototype.yc=function(t){var e={};e.database=this.serializer.Ri,e.addTarget=this.serializer.Rn(t);var n=this.serializer.rs(t);n&&(e.labels=n),this.Pc(e)},e.prototype.Sc=function(t){var e={};e.database=this.serializer.Ri,e.removeTarget=t,this.Pc(e)},e}(__PRIVATE_PersistentStream),__PRIVATE_PersistentWriteStream=function(t){function e(e,n,r,i,s){var o=t.call(this,e,__PRIVATE_TimerId.Bo,__PRIVATE_TimerId.Go,n,r,s)||this;return o.serializer=i,o.Dc=!1,o.lastStreamToken=__PRIVATE_emptyByteString(),o}return tslib.__extends(e,t),Object.defineProperty(e.prototype,"Cc",{get:function(){return this.Dc},enumerable:!0,configurable:!0}),e.prototype.start=function(){this.Dc=!1,t.prototype.start.call(this)},e.prototype.Rc=function(){this.Dc&&this.Oc([])},e.prototype.pc=function(t){return this.oc.gc("Write",t)},e.prototype.onMessage=function(t){if(assert(!!t.streamToken,"Got a write response without a stream token"),this.lastStreamToken=t.streamToken,this.Dc){this.cc.reset();var e=this.serializer.Wi(t.writeResults,t.commitTime),n=this.serializer.fromVersion(t.commitTime);return this.listener.Fc(n,e)}return assert(!t.writeResults||0===t.writeResults.length,"Got mutation results for handshake"),this.Dc=!0,this.listener.Nc()},e.prototype.Mc=function(){assert(this.fc(),"Writing handshake requires an opened stream"),assert(!this.Dc,"Handshake already completed");var t={};t.database=this.serializer.Ri,this.Pc(t)},e.prototype.Oc=function(t){var e=this;assert(this.fc(),"Writing mutations requires an opened stream"),assert(this.Dc,"Handshake must be complete before writing mutations"),assert(this.lastStreamToken.length>0,"Trying to write mutation without a token");var n={streamToken:this.lastStreamToken,writes:t.map((function(t){return e.serializer.Gi(t)}))};this.Pc(n)},e}(__PRIVATE_PersistentStream),__PRIVATE_Datastore=function(){function t(t,e,n,r){this.q_=t,this.oc=e,this.credentials=n,this.serializer=r}return t.prototype.Lc=function(t){return new __PRIVATE_PersistentWriteStream(this.q_,this.oc,this.credentials,this.serializer,t)},t.prototype.Gc=function(t){return new __PRIVATE_PersistentListenStream(this.q_,this.oc,this.credentials,this.serializer,t)},t.prototype.commit=function(t){var e=this,n={database:this.serializer.Ri,writes:t.map((function(t){return e.serializer.Gi(t)}))};return this.Bc("Commit",n).then((function(t){return e.serializer.Wi(t.writeResults,t.commitTime)}))},t.prototype.Uc=function(t){var e=this,n={database:this.serializer.Ri,documents:t.map((function(t){return e.serializer.di(t)}))};return this.kc("BatchGetDocuments",n).then((function(n){var r=__PRIVATE_maybeDocumentMap();n.forEach((function(t){var n=e.serializer.Ci(t);r=r.At(n.key,n)}));var i=[];return t.forEach((function(t){var e=r.get(t);assert(!!e,"Missing entity in write response for "+t),i.push(e)})),i}))},t.prototype.Bc=function(t,e){var n=this;return this.credentials.getToken().then((function(r){return n.oc.Bc(t,e,r)})).catch((function(t){throw t.code===Code.UNAUTHENTICATED&&n.credentials.g(),t}))},t.prototype.kc=function(t,e){var n=this;return this.credentials.getToken().then((function(r){return n.oc.kc(t,e,r)})).catch((function(t){throw t.code===Code.UNAUTHENTICATED&&n.credentials.g(),t}))},t}(),Transaction=function(){function t(t){this.xc=t,this.Kc=__PRIVATE_documentVersionMap(),this.mutations=[],this.jc=!1,this.qc=null,this.Qc=new Set}return t.prototype.Uc=function(t){return tslib.__awaiter(this,void 0,void 0,(function(){var e,n=this;return tslib.__generator(this,(function(r){switch(r.label){case 0:if(this.Wc(),this.mutations.length>0)throw new FirestoreError(Code.INVALID_ARGUMENT,"Firestore transactions require all reads to be executed before all writes.");return[4,this.xc.Uc(t)];case 1:return(e=r.sent()).forEach((function(t){t instanceof __PRIVATE_NoDocument||t instanceof Document?n.$c(t):fail("Document in a transaction was a "+t.constructor.name)})),[2,e]}}))}))},t.prototype.set=function(t,e){this.write(e.A_(t,this.le(t))),this.Qc.add(t)},t.prototype.update=function(t,e){try{this.write(e.A_(t,this.Yc(t)))}catch(t){this.qc=t}this.Qc.add(t)},t.prototype.delete=function(t){this.write([new __PRIVATE_DeleteMutation(t,this.le(t))]),this.Qc.add(t)},t.prototype.commit=function(){return tslib.__awaiter(this,void 0,void 0,(function(){var t,e=this;return tslib.__generator(this,(function(n){switch(n.label){case 0:if(this.Wc(),this.qc)throw this.qc;return t=this.Kc,this.mutations.forEach((function(e){t=t.remove(e.key)})),t.forEach((function(t,n){e.mutations.push(new __PRIVATE_VerifyMutation(t,e.le(t)))})),[4,this.xc.commit(this.mutations)];case 1:return n.sent(),this.jc=!0,[2]}}))}))},t.prototype.$c=function(t){var e;if(t instanceof Document)e=t.version;else{if(!(t instanceof __PRIVATE_NoDocument))throw fail("Document in a transaction was a "+t.constructor.name);e=__PRIVATE_SnapshotVersion.W()}var n=this.Kc.get(t.key);if(null!==n){if(!e.isEqual(n))throw new FirestoreError(Code.ABORTED,"Document version changed between two reads.")}else this.Kc=this.Kc.At(t.key,e)},t.prototype.le=function(t){var e=this.Kc.get(t);return!this.Qc.has(t)&&e?Precondition.updateTime(e):Precondition.NONE},t.prototype.Yc=function(t){var e=this.Kc.get(t);if(!this.Qc.has(t)&&e){if(e.isEqual(__PRIVATE_SnapshotVersion.W()))throw new FirestoreError(Code.INVALID_ARGUMENT,"Can't update a document that doesn't exist.");return Precondition.updateTime(e)}return Precondition.exists(!0)},t.prototype.write=function(t){this.Wc(),this.mutations=this.mutations.concat(t)},t.prototype.Wc=function(){assert(!this.jc,"A transaction object cannot be used after its update callback has been invoked.")},t}(),__PRIVATE_LOG_TAG$4="OnlineStateTracker",__PRIVATE_MAX_WATCH_STREAM_FAILURES=1,__PRIVATE_ONLINE_STATE_TIMEOUT_MS=1e4,__PRIVATE_OnlineStateTracker=function(){function t(t,e){this.jo=t,this.Hc=e,this.state=__PRIVATE_OnlineState.h,this.Xc=0,this.zc=null,this.Jc=!0}return t.prototype.Zc=function(){var t=this;0===this.Xc&&(this.th(__PRIVATE_OnlineState.h),assert(null===this.zc,"onlineStateTimer shouldn't be started yet"),this.zc=this.jo.hu(__PRIVATE_TimerId.Uo,__PRIVATE_ONLINE_STATE_TIMEOUT_MS,(function(){return t.zc=null,assert(t.state===__PRIVATE_OnlineState.h,"Timer should be canceled if we transitioned to a different state."),t.eh("Backend didn't respond within "+__PRIVATE_ONLINE_STATE_TIMEOUT_MS/1e3+" seconds."),t.th(__PRIVATE_OnlineState.T),Promise.resolve()})))},t.prototype.nh=function(t){this.state===__PRIVATE_OnlineState.l?(this.th(__PRIVATE_OnlineState.h),assert(0===this.Xc,"watchStreamFailures must be 0"),assert(null===this.zc,"onlineStateTimer must be null")):(this.Xc++,this.Xc>=__PRIVATE_MAX_WATCH_STREAM_FAILURES&&(this.rh(),this.eh("Connection failed "+__PRIVATE_MAX_WATCH_STREAM_FAILURES+" times. Most recent error: "+t.toString()),this.th(__PRIVATE_OnlineState.T)))},t.prototype.set=function(t){this.rh(),this.Xc=0,t===__PRIVATE_OnlineState.l&&(this.Jc=!1),this.th(t)},t.prototype.th=function(t){t!==this.state&&(this.state=t,this.Hc(t))},t.prototype.eh=function(t){var e="Could not reach Cloud Firestore backend. "+t+"\nThis typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.";this.Jc?(error(e),this.Jc=!1):debug(__PRIVATE_LOG_TAG$4,e)},t.prototype.rh=function(){null!==this.zc&&(this.zc.cancel(),this.zc=null)},t}(),__PRIVATE_LOG_TAG$5="RemoteStore",__PRIVATE_MAX_PENDING_WRITES=10,__PRIVATE_RemoteStore=function(){function t(t,e,n,r,i){var s=this;this.Gu=t,this.xc=e,this.ih=[],this.sh={},this.oh=null,this.networkEnabled=!1,this.isPrimary=!1,this.uh=i,this.uh.ah((function(t){n.Jo((function(){return tslib.__awaiter(s,void 0,void 0,(function(){return tslib.__generator(this,(function(t){switch(t.label){case 0:return this._h()?(debug(__PRIVATE_LOG_TAG$5,"Restarting streams for network reachability change."),[4,this.hh()]):[3,2];case 1:t.sent(),t.label=2;case 2:return[2]}}))}))}))})),this.fh=new __PRIVATE_OnlineStateTracker(n,r),this.lh=this.xc.Gc({bc:this.dh.bind(this),Ic:this.Th.bind(this),wc:this.Eh.bind(this)}),this.Ph=this.xc.Lc({bc:this.Ah.bind(this),Ic:this.Rh.bind(this),Nc:this.Ih.bind(this),Fc:this.Fc.bind(this)})}return t.prototype.start=function(){return this.enableNetwork()},t.prototype.enableNetwork=function(){return tslib.__awaiter(this,void 0,void 0,(function(){var t;return tslib.__generator(this,(function(e){switch(e.label){case 0:return this.networkEnabled=!0,this._h()?(t=this.Ph,[4,this.Gu.Na()]):[3,3];case 1:return t.lastStreamToken=e.sent(),this.Vh()?this.mh():this.fh.set(__PRIVATE_OnlineState.h),[4,this.vh()];case 2:e.sent(),e.label=3;case 3:return[2]}}))}))},t.prototype.disableNetwork=function(){return tslib.__awaiter(this,void 0,void 0,(function(){return tslib.__generator(this,(function(t){switch(t.label){case 0:return this.networkEnabled=!1,[4,this.ph()];case 1:return t.sent(),this.fh.set(__PRIVATE_OnlineState.T),[2]}}))}))},t.prototype.ph=function(){return tslib.__awaiter(this,void 0,void 0,(function(){return tslib.__generator(this,(function(t){switch(t.label){case 0:return[4,this.Ph.stop()];case 1:return t.sent(),[4,this.lh.stop()];case 2:return t.sent(),this.ih.length>0&&(debug(__PRIVATE_LOG_TAG$5,"Stopping write stream with "+this.ih.length+" pending writes"),this.ih=[]),this.bh(),[2]}}))}))},t.prototype.gh=function(){return tslib.__awaiter(this,void 0,void 0,(function(){return tslib.__generator(this,(function(t){switch(t.label){case 0:return debug(__PRIVATE_LOG_TAG$5,"RemoteStore shutting down."),this.networkEnabled=!1,[4,this.ph()];case 1:return t.sent(),this.uh.gh(),this.fh.set(__PRIVATE_OnlineState.h),[2]}}))}))},t.prototype.listen=function(t){contains(this.sh,t.targetId)||(this.sh[t.targetId]=t,this.Vh()?this.mh():this.lh.fc()&&this.wh(t))},t.prototype.yh=function(t){assert(contains(this.sh,t),"unlisten called on target no currently watched: "+t),delete this.sh[t],this.lh.fc()&&this.Sh(t),__PRIVATE_isEmpty(this.sh)&&(this.lh.fc()?this.lh.Tc():this._h()&&this.fh.set(__PRIVATE_OnlineState.h))},t.prototype.ti=function(t){return this.sh[t]||null},t.prototype.Zr=function(t){return this.Dh.Zr(t)},t.prototype.wh=function(t){this.oh.Cr(t.targetId),this.lh.yc(t)},t.prototype.Sh=function(t){this.oh.Cr(t),this.lh.Sc(t)},t.prototype.mh=function(){assert(this.Vh(),"startWatchStream() called when shouldStartWatchStream() is false."),this.oh=new __PRIVATE_WatchChangeAggregator(this),this.lh.start(),this.fh.Zc()},t.prototype.Vh=function(){return this._h()&&!this.lh.hc()&&!__PRIVATE_isEmpty(this.sh)},t.prototype._h=function(){return this.isPrimary&&this.networkEnabled},t.prototype.bh=function(){this.oh=null},t.prototype.dh=function(){return tslib.__awaiter(this,void 0,void 0,(function(){var t=this;return tslib.__generator(this,(function(e){return __PRIVATE_forEachNumber(this.sh,(function(e,n){t.wh(n)})),[2]}))}))},t.prototype.Th=function(t){return tslib.__awaiter(this,void 0,void 0,(function(){return tslib.__generator(this,(function(e){return void 0===t&&assert(!this.Vh(),"Watch stream was stopped gracefully while still needed."),this.bh(),this.Vh()?(this.fh.nh(t),this.mh()):this.fh.set(__PRIVATE_OnlineState.h),[2]}))}))},t.prototype.Eh=function(t,e){return tslib.__awaiter(this,void 0,void 0,(function(){var n;return tslib.__generator(this,(function(r){switch(r.label){case 0:return this.fh.set(__PRIVATE_OnlineState.l),t instanceof __PRIVATE_WatchTargetChange&&t.state===__PRIVATE_WatchTargetChangeState.qn&&t.cause?[2,this.Ch(t)]:(t instanceof __PRIVATE_DocumentWatchChange?this.oh.Ur(t):t instanceof __PRIVATE_ExistenceFilterChange?this.oh.$r(t):(assert(t instanceof __PRIVATE_WatchTargetChange,"Expected watchChange to be an instance of WatchTargetChange"),this.oh.Kr(t)),e.isEqual(__PRIVATE_SnapshotVersion.MIN)?[3,3]:[4,this.Gu.La()]);case 1:return n=r.sent(),e._(n)>=0?[4,this.Oh(e)]:[3,3];case 2:r.sent(),r.label=3;case 3:return[2]}}))}))},t.prototype.Oh=function(t){var e=this;assert(!t.isEqual(__PRIVATE_SnapshotVersion.MIN),"Can't raise event for unknown SnapshotVersion");var n=this.oh.Xr(t);return __PRIVATE_forEachNumber(n.nr,(function(n,r){if(r.resumeToken.length>0){var i=e.sh[n];i&&(e.sh[n]=i.Bn(r.resumeToken,t))}})),n.rr.forEach((function(t){var n=e.sh[t];if(n){e.sh[t]=n.Bn(__PRIVATE_emptyByteString(),n.Ln),e.Sh(t);var r=new __PRIVATE_TargetData(n.target,t,__PRIVATE_TargetPurpose.Fn,n.sequenceNumber);e.wh(r)}})),this.Dh.Ga(n)},t.prototype.Ch=function(t){var e=this;assert(!!t.cause,"Handling target error without a cause");var n=t.cause,r=Promise.resolve();return t.targetIds.forEach((function(t){r=r.then((function(){return tslib.__awaiter(e,void 0,void 0,(function(){return tslib.__generator(this,(function(e){return contains(this.sh,t)?(delete this.sh[t],this.oh.removeTarget(t),[2,this.Dh.Fh(t,n)]):[2]}))}))}))})),r},t.prototype.vh=function(){return tslib.__awaiter(this,void 0,void 0,(function(){var t,e;return tslib.__generator(this,(function(n){switch(n.label){case 0:return this.Nh()?(t=this.ih.length>0?this.ih[this.ih.length-1].batchId:__PRIVATE_BATCHID_UNKNOWN,[4,this.Gu.$a(t)]):[3,4];case 1:return null!==(e=n.sent())?[3,2]:(0===this.ih.length&&this.Ph.Tc(),[3,4]);case 2:return this.Mh(e),[4,this.vh()];case 3:n.sent(),n.label=4;case 4:return this.Lh()&&this.Gh(),[2]}}))}))},t.prototype.Nh=function(){return this._h()&&this.ih.length<__PRIVATE_MAX_PENDING_WRITES},t.prototype.Bh=function(){return this.ih.length},t.prototype.Mh=function(t){assert(this.Nh(),"addToWritePipeline called when pipeline is full"),this.ih.push(t),this.Ph.fc()&&this.Ph.Cc&&this.Ph.Oc(t.mutations)},t.prototype.Lh=function(){return this._h()&&!this.Ph.hc()&&this.ih.length>0},t.prototype.Gh=function(){assert(this.Lh(),"startWriteStream() called when shouldStartWriteStream() is false."),this.Ph.start()},t.prototype.Ah=function(){return tslib.__awaiter(this,void 0,void 0,(function(){return tslib.__generator(this,(function(t){return this.Ph.Mc(),[2]}))}))},t.prototype.Ih=function(){var t=this;return this.Gu.Ma(this.Ph.lastStreamToken).then((function(){for(var e=0,n=t.ih;e<n.length;e++){var r=n[e];t.Ph.Oc(r.mutations)}})).catch(__PRIVATE_ignoreIfPrimaryLeaseLoss)},t.prototype.Fc=function(t,e){var n=this;assert(this.ih.length>0,"Got result for empty write pipeline");var r=this.ih.shift(),i=__PRIVATE_MutationBatchResult.from(r,t,e,this.Ph.lastStreamToken);return this.Dh.Uh(i).then((function(){return n.vh()}))},t.prototype.Rh=function(t){return tslib.__awaiter(this,void 0,void 0,(function(){var e=this;return tslib.__generator(this,(function(n){return void 0===t&&assert(!this.Lh(),"Write stream was stopped gracefully while still needed."),t&&this.ih.length>0?(void 0,[2,(this.Ph.Cc?this.kh(t):this.xh(t)).then((function(){e.Lh()&&e.Gh()}))]):[2]}))}))},t.prototype.xh=function(t){return tslib.__awaiter(this,void 0,void 0,(function(){return tslib.__generator(this,(function(e){return __PRIVATE_isPermanentError(t.code)?(debug(__PRIVATE_LOG_TAG$5,"RemoteStore error before completed handshake; resetting stream token: ",this.Ph.lastStreamToken),this.Ph.lastStreamToken=__PRIVATE_emptyByteString(),[2,this.Gu.Ma(__PRIVATE_emptyByteString()).catch(__PRIVATE_ignoreIfPrimaryLeaseLoss)]):[2]}))}))},t.prototype.kh=function(t){return tslib.__awaiter(this,void 0,void 0,(function(){var e,n=this;return tslib.__generator(this,(function(r){return __PRIVATE_isPermanentWriteError(t.code)?(e=this.ih.shift(),this.Ph.dc(),[2,this.Dh.Kh(e.batchId,t).then((function(){return n.vh()}))]):[2]}))}))},t.prototype.jh=function(){return new Transaction(this.xc)},t.prototype.hh=function(){return tslib.__awaiter(this,void 0,void 0,(function(){return tslib.__generator(this,(function(t){switch(t.label){case 0:return this.networkEnabled=!1,[4,this.ph()];case 1:return t.sent(),this.fh.set(__PRIVATE_OnlineState.h),[4,this.enableNetwork()];case 2:return t.sent(),[2]}}))}))},t.prototype.qh=function(){return tslib.__awaiter(this,void 0,void 0,(function(){return tslib.__generator(this,(function(t){switch(t.label){case 0:return this._h()?(debug(__PRIVATE_LOG_TAG$5,"RemoteStore restarting streams for new credential"),[4,this.hh()]):[3,2];case 1:t.sent(),t.label=2;case 2:return[2]}}))}))},t.prototype.Qh=function(t){return tslib.__awaiter(this,void 0,void 0,(function(){return tslib.__generator(this,(function(e){switch(e.label){case 0:return this.isPrimary=t,t&&this.networkEnabled?[4,this.enableNetwork()]:[3,2];case 1:return e.sent(),[3,4];case 2:return t?[3,4]:[4,this.ph()];case 3:e.sent(),this.fh.set(__PRIVATE_OnlineState.h),e.label=4;case 4:return[2]}}))}))},t}(),CLIENT_STATE_KEY_PREFIX="firestore_clients";function createWebStorageClientStateKey(t,e){return assert(-1===e.indexOf("_"),"Client key cannot contain '_', but was '"+e+"'"),CLIENT_STATE_KEY_PREFIX+"_"+t+"_"+e}var MUTATION_BATCH_KEY_PREFIX="firestore_mutations";function createWebStorageMutationBatchKey(t,e,n){var r=MUTATION_BATCH_KEY_PREFIX+"_"+t+"_"+n;return e.R()&&(r+="_"+e.uid),r}var QUERY_TARGET_KEY_PREFIX="firestore_targets";function createWebStorageQueryTargetMetadataKey(t,e){return QUERY_TARGET_KEY_PREFIX+"_"+t+"_"+e}var ONLINE_STATE_KEY_PREFIX="firestore_online_state";function createWebStorageOnlineStateKey(t){return ONLINE_STATE_KEY_PREFIX+"_"+t}var SEQUENCE_NUMBER_KEY_PREFIX="firestore_sequence_number";function createWebStorageSequenceNumberKey(t){return SEQUENCE_NUMBER_KEY_PREFIX+"_"+t}var __PRIVATE_LOG_TAG$6="SharedClientState",__PRIVATE_MutationMetadata=function(){function t(t,e,n,r){this.user=t,this.batchId=e,this.state=n,this.error=r,assert(void 0!==r==("rejected"===n),"MutationMetadata must contain an error iff state is 'rejected'")}return t.Wh=function(e,n,r){var i=JSON.parse(r),s="object"==typeof i&&-1!==["pending","acknowledged","rejected"].indexOf(i.state)&&(void 0===i.error||"object"==typeof i.error),o=void 0;return s&&i.error&&(s="string"==typeof i.error.message&&"string"==typeof i.error.code)&&(o=new FirestoreError(i.error.code,i.error.message)),s?new t(e,n,i.state,o):(error(__PRIVATE_LOG_TAG$6,"Failed to parse mutation state for ID '"+n+"': "+r),null)},t.prototype.$h=function(){var t={state:this.state,updateTimeMs:Date.now()};return this.error&&(t.error={code:this.error.code,message:this.error.message}),JSON.stringify(t)},t}(),__PRIVATE_QueryTargetMetadata=function(){function t(t,e,n){this.targetId=t,this.state=e,this.error=n,assert(void 0!==n==("rejected"===e),"QueryTargetMetadata must contain an error iff state is 'rejected'")}return t.Wh=function(e,n){var r=JSON.parse(n),i="object"==typeof r&&-1!==["not-current","current","rejected"].indexOf(r.state)&&(void 0===r.error||"object"==typeof r.error),s=void 0;return i&&r.error&&(i="string"==typeof r.error.message&&"string"==typeof r.error.code)&&(s=new FirestoreError(r.error.code,r.error.message)),i?new t(e,r.state,s):(error(__PRIVATE_LOG_TAG$6,"Failed to parse target state for ID '"+e+"': "+n),null)},t.prototype.$h=function(){var t={state:this.state,updateTimeMs:Date.now()};return this.error&&(t.error={code:this.error.code,message:this.error.message}),JSON.stringify(t)},t}(),__PRIVATE_RemoteClientState=function(){function t(t,e){this.clientId=t,this.activeTargetIds=e}return t.Wh=function(e,n){for(var r=JSON.parse(n),i="object"==typeof r&&r.activeTargetIds instanceof Array,s=__PRIVATE_targetIdSet(),o=0;i&&o<r.activeTargetIds.length;++o)i=isSafeInteger(r.activeTargetIds[o]),s=s.add(r.activeTargetIds[o]);return i?new t(e,s):(error(__PRIVATE_LOG_TAG$6,"Failed to parse client data for instance '"+e+"': "+n),null)},t}(),__PRIVATE_SharedOnlineState=function(){function t(t,e){this.clientId=t,this.onlineState=e}return t.Wh=function(e){var n=JSON.parse(e);return"object"==typeof n&&n.onlineState in __PRIVATE_OnlineState&&"string"==typeof n.clientId?new t(n.clientId,__PRIVATE_OnlineState[n.onlineState]):(error(__PRIVATE_LOG_TAG$6,"Failed to parse online state: "+e),null)},t}(),__PRIVATE_LocalClientState=function(){function t(){this.activeTargetIds=__PRIVATE_targetIdSet()}return t.prototype.Yh=function(t){this.activeTargetIds=this.activeTargetIds.add(t)},t.prototype.Hh=function(t){this.activeTargetIds=this.activeTargetIds.delete(t)},t.prototype.$h=function(){var t={activeTargetIds:this.activeTargetIds.ot(),updateTimeMs:Date.now()};return JSON.stringify(t)},t}(),__PRIVATE_WebStorageSharedClientState=function(){function t(e,n,r,i,s){if(this.q_=e,this.platform=n,this.persistenceKey=r,this.Xh=i,this.Dh=null,this.Hc=null,this.So=null,this.zh={},this.Jh=this.Zh.bind(this),this.Ku=!1,this.tf=[],!t.ef(this.platform))throw new FirestoreError(Code.UNIMPLEMENTED,"LocalStorage is not available on this platform.");var o=r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");this.storage=this.platform.window.localStorage,this.currentUser=s,this.nf=createWebStorageClientStateKey(this.persistenceKey,this.Xh),this.rf=createWebStorageSequenceNumberKey(this.persistenceKey),this.zh[this.Xh]=new __PRIVATE_LocalClientState,this.if=new RegExp("^"+CLIENT_STATE_KEY_PREFIX+"_"+o+"_([^_]*)$"),this.sf=new RegExp("^"+MUTATION_BATCH_KEY_PREFIX+"_"+o+"_(\\d+)(?:_(.*))?$"),this.uf=new RegExp("^"+QUERY_TARGET_KEY_PREFIX+"_"+o+"_(\\d+)$"),this.af=createWebStorageOnlineStateKey(this.persistenceKey),this.platform.window.addEventListener("storage",this.Jh)}return t.ef=function(t){return!(!t.window||null==t.window.localStorage)},t.prototype.start=function(){return tslib.__awaiter(this,void 0,void 0,(function(){var t,e,n,r,i,s,o,u,a,_,c,h=this;return tslib.__generator(this,(function(f){switch(f.label){case 0:return assert(!this.Ku,"WebStorageSharedClientState already started"),assert(null!==this.Dh,"syncEngine property must be set before calling start()"),assert(null!==this.Hc,"onlineStateHandler property must be set before calling start()"),[4,this.Dh.s_()];case 1:for(t=f.sent(),e=0,n=t;e<n.length;e++)(r=n[e])!==this.Xh&&(i=this.getItem(createWebStorageClientStateKey(this.persistenceKey,r)))&&(s=__PRIVATE_RemoteClientState.Wh(r,i))&&(this.zh[s.clientId]=s);for(this._f(),(o=this.storage.getItem(this.af))&&(u=this.cf(o))&&this.hf(u),a=0,_=this.tf;a<_.length;a++)c=_[a],this.Zh(c);return this.tf=[],this.platform.window.addEventListener("unload",(function(){return h.gh()})),this.Ku=!0,[2]}}))}))},t.prototype.Oo=function(t){this.setItem(this.rf,JSON.stringify(t))},t.prototype.ff=function(){var t=__PRIVATE_targetIdSet();return forEach(this.zh,(function(e,n){t=t.Ht(n.activeTargetIds)})),t},t.prototype.lf=function(t){for(var e in this.zh)if(this.zh.hasOwnProperty(e)&&this.zh[e].activeTargetIds.has(t))return!0;return!1},t.prototype.df=function(t){this.Tf(t,"pending")},t.prototype.Ef=function(t,e,n){this.Tf(t,e,n),this.Pf(t)},t.prototype.Af=function(t){var e="not-current";if(this.lf(t)){var n=this.storage.getItem(createWebStorageQueryTargetMetadataKey(this.persistenceKey,t));if(n){var r=__PRIVATE_QueryTargetMetadata.Wh(t,n);r&&(e=r.state)}}return this.Rf.Yh(t),this._f(),e},t.prototype.If=function(t){this.Rf.Hh(t),this._f()},t.prototype.Vf=function(t){return this.Rf.activeTargetIds.has(t)},t.prototype.mf=function(t){this.removeItem(createWebStorageQueryTargetMetadataKey(this.persistenceKey,t))},t.prototype.vf=function(t,e,n){this.pf(t,e,n)},t.prototype.Ea=function(t,e,n){var r=this;e.forEach((function(t){r.Pf(t)})),this.currentUser=t,n.forEach((function(t){r.df(t)}))},t.prototype.bf=function(t){this.gf(t)},t.prototype.gh=function(){this.Ku&&(this.platform.window.removeEventListener("storage",this.Jh),this.removeItem(this.nf),this.Ku=!1)},t.prototype.getItem=function(t){var e=this.storage.getItem(t);return debug(__PRIVATE_LOG_TAG$6,"READ",t,e),e},t.prototype.setItem=function(t,e){debug(__PRIVATE_LOG_TAG$6,"SET",t,e),this.storage.setItem(t,e)},t.prototype.removeItem=function(t){debug(__PRIVATE_LOG_TAG$6,"REMOVE",t),this.storage.removeItem(t)},t.prototype.Zh=function(t){var e=this;if(t.storageArea===this.storage){if(debug(__PRIVATE_LOG_TAG$6,"EVENT",t.key,t.newValue),t.key===this.nf)return void error("Received WebStorage notification for local change. Another client might have garbage-collected our state");this.q_.Jo((function(){return tslib.__awaiter(e,void 0,void 0,(function(){var e,n,r,i,s,o;return tslib.__generator(this,(function(u){if(!this.Ku)return this.tf.push(t),[2];if(null===t.key)return[2];if(this.if.test(t.key)){if(null==t.newValue)return n=this.wf(t.key),[2,this.yf(n,null)];if(e=this.Sf(t.key,t.newValue))return[2,this.yf(e.clientId,e)]}else if(this.sf.test(t.key)){if(null!==t.newValue&&(r=this.Df(t.key,t.newValue)))return[2,this.Cf(r)]}else if(this.uf.test(t.key)){if(null!==t.newValue&&(i=this.Of(t.key,t.newValue)))return[2,this.Ff(i)]}else if(t.key===this.af){if(null!==t.newValue&&(s=this.cf(t.newValue)))return[2,this.hf(s)]}else t.key===this.rf&&(assert(!!this.So,"Missing sequenceNumberHandler"),(o=__PRIVATE_fromWebStorageSequenceNumber(t.newValue))!==__PRIVATE_ListenSequence.Fo&&this.So(o));return[2]}))}))}))}},Object.defineProperty(t.prototype,"Rf",{get:function(){return this.zh[this.Xh]},enumerable:!0,configurable:!0}),t.prototype._f=function(){this.setItem(this.nf,this.Rf.$h())},t.prototype.Tf=function(t,e,n){var r=new __PRIVATE_MutationMetadata(this.currentUser,t,e,n),i=createWebStorageMutationBatchKey(this.persistenceKey,this.currentUser,t);this.setItem(i,r.$h())},t.prototype.Pf=function(t){var e=createWebStorageMutationBatchKey(this.persistenceKey,this.currentUser,t);this.removeItem(e)},t.prototype.gf=function(t){var e={clientId:this.Xh,onlineState:__PRIVATE_OnlineState[t]};this.storage.setItem(this.af,JSON.stringify(e))},t.prototype.pf=function(t,e,n){var r=createWebStorageQueryTargetMetadataKey(this.persistenceKey,t),i=new __PRIVATE_QueryTargetMetadata(t,e,n);this.setItem(r,i.$h())},t.prototype.wf=function(t){var e=this.if.exec(t);return e?e[1]:null},t.prototype.Sf=function(t,e){var n=this.wf(t);return assert(null!==n,"Cannot parse client state key '"+t+"'"),__PRIVATE_RemoteClientState.Wh(n,e)},t.prototype.Df=function(t,e){var n=this.sf.exec(t);assert(null!==n,"Cannot parse mutation batch key '"+t+"'");var r=Number(n[1]),i=void 0!==n[2]?n[2]:null;return __PRIVATE_MutationMetadata.Wh(new User(i),r,e)},t.prototype.Of=function(t,e){var n=this.uf.exec(t);assert(null!==n,"Cannot parse query target key '"+t+"'");var r=Number(n[1]);return __PRIVATE_QueryTargetMetadata.Wh(r,e)},t.prototype.cf=function(t){return __PRIVATE_SharedOnlineState.Wh(t)},t.prototype.Cf=function(t){return tslib.__awaiter(this,void 0,void 0,(function(){return tslib.__generator(this,(function(e){return t.user.uid!==this.currentUser.uid?(debug(__PRIVATE_LOG_TAG$6,"Ignoring mutation for non-active user "+t.user.uid),[2]):[2,this.Dh.Nf(t.batchId,t.state,t.error)]}))}))},t.prototype.Ff=function(t){return this.Dh.Mf(t.targetId,t.state,t.error)},t.prototype.yf=function(t,e){var n=this,r=this.ff();e?this.zh[t]=e:delete this.zh[t];var i=this.ff(),s=[],o=[];return i.forEach((function(t){return tslib.__awaiter(n,void 0,void 0,(function(){return tslib.__generator(this,(function(e){return r.has(t)||s.push(t),[2]}))}))})),r.forEach((function(t){return tslib.__awaiter(n,void 0,void 0,(function(){return tslib.__generator(this,(function(e){return i.has(t)||o.push(t),[2]}))}))})),this.Dh.Lf(s,o)},t.prototype.hf=function(t){this.zh[t.clientId]&&this.Hc(t.onlineState)},t}();function __PRIVATE_fromWebStorageSequenceNumber(t){var e=__PRIVATE_ListenSequence.Fo;if(null!=t)try{var n=JSON.parse(t);assert("number"==typeof n,"Found non-numeric sequence number"),e=n}catch(t){error(__PRIVATE_LOG_TAG$6,"Failed to read sequence number from WebStorage",t)}return e}var __PRIVATE_GeneratorIds,__PRIVATE_MemorySharedClientState=function(){function t(){this.Gf=new __PRIVATE_LocalClientState,this.Bf={},this.Dh=null,this.Hc=null,this.So=null}return t.prototype.df=function(t){},t.prototype.Ef=function(t,e,n){},t.prototype.Af=function(t){return this.Gf.Yh(t),this.Bf[t]||"not-current"},t.prototype.vf=function(t,e,n){this.Bf[t]=e},t.prototype.If=function(t){this.Gf.Hh(t)},t.prototype.Vf=function(t){return this.Gf.activeTargetIds.has(t)},t.prototype.mf=function(t){delete this.Bf[t]},t.prototype.ff=function(){return this.Gf.activeTargetIds},t.prototype.lf=function(t){return this.Gf.activeTargetIds.has(t)},t.prototype.start=function(){return this.Gf=new __PRIVATE_LocalClientState,Promise.resolve()},t.prototype.Ea=function(t,e,n){},t.prototype.bf=function(t){},t.prototype.gh=function(){},t.prototype.Oo=function(t){},t}(),__PRIVATE_RESERVED_BITS=1;!function(t){t[t.Uf=0]="__PRIVATE_QueryCache",t[t.kf=1]="__PRIVATE_SyncEngine"}(__PRIVATE_GeneratorIds||(__PRIVATE_GeneratorIds={}));var __PRIVATE_TargetIdGenerator=function(){function t(t,e){this.xf=t,assert((t&__PRIVATE_RESERVED_BITS)===t,"Generator ID "+t+" contains more than "+__PRIVATE_RESERVED_BITS+" reserved bits"),this.Kf(void 0!==e?e:this.xf)}return t.prototype.next=function(){var t=this.jf;return this.jf+=1<<__PRIVATE_RESERVED_BITS,t},t.prototype.after=function(t){return this.Kf(t+(1<<__PRIVATE_RESERVED_BITS)),this.next()},t.prototype.Kf=function(t){assert((t&__PRIVATE_RESERVED_BITS)===this.xf,"Cannot supply target ID from different generator ID"),this.jf=t},t.qf=function(){return new t(__PRIVATE_GeneratorIds.Uf,2)},t.Qf=function(){return new t(__PRIVATE_GeneratorIds.kf)},t}(),__PRIVATE_AddedLimboDocument=function(t){this.key=t},__PRIVATE_RemovedLimboDocument=function(t){this.key=t},__PRIVATE_View=function(){function t(t,e){this.query=t,this.Wf=e,this.$f=null,this.ar=!1,this.Yf=__PRIVATE_documentKeySet(),this.Jn=__PRIVATE_documentKeySet(),this.Hf=new __PRIVATE_DocumentSet(t.In.bind(t))}return Object.defineProperty(t.prototype,"Xf",{get:function(){return this.Wf},enumerable:!0,configurable:!0}),t.prototype.zf=function(t,e){var n=this,r=e?e.Jf:new __PRIVATE_DocumentChangeSet,i=e?e.Hf:this.Hf,s=e?e.Jn:this.Jn,o=i,u=!1,a=this.query.bn()&&i.size===this.query.limit?i.last():null,_=this.query.gn()&&i.size===this.query.limit?i.first():null;if(t.pt((function(t,e){var c=i.get(t),h=e instanceof Document?e:null;h&&(assert(t.isEqual(h.key),"Mismatching keys found in document changes: "+t+" != "+h.key),h=n.query.matches(h)?h:null);var f=!!c&&n.Jn.has(c.key),l=!!h&&(h.de||n.Jn.has(h.key)&&h.hasCommittedMutations),d=!1;c&&h?c.data().isEqual(h.data())?f!==l&&(r.track({type:__PRIVATE_ChangeType.Wn,doc:h}),d=!0):n.Zf(c,h)||(r.track({type:__PRIVATE_ChangeType.Qn,doc:h}),d=!0,(a&&n.query.In(h,a)>0||_&&n.query.In(h,_)<0)&&(u=!0)):!c&&h?(r.track({type:__PRIVATE_ChangeType.jn,doc:h}),d=!0):c&&!h&&(r.track({type:__PRIVATE_ChangeType.qn,doc:c}),d=!0,(a||_)&&(u=!0));d&&(h?(o=o.add(h),s=l?s.add(t):s.delete(t)):(o=o.delete(t),s=s.delete(t)))})),this.query.bn()||this.query.gn())for(;o.size>this.query.limit;){var c=this.query.bn()?o.last():o.first();o=o.delete(c.key),s=s.delete(c.key),r.track({type:__PRIVATE_ChangeType.qn,doc:c})}return assert(!u||!e,"View was refilled using docs that themselves needed refilling."),{Hf:o,Jf:r,tl:u,Jn:s}},t.prototype.Zf=function(t,e){return t.de&&e.hasCommittedMutations&&!e.de},t.prototype.io=function(t,e,n){var r=this;assert(!t.tl,"Cannot apply changes that need a refill");var i=this.Hf;this.Hf=t.Hf,this.Jn=t.Jn;var s=t.Jf.Xn();s.sort((function(t,e){return __PRIVATE_compareChangeType(t.type,e.type)||r.query.In(t.doc,e.doc)})),this.el(n);var o=e?this.nl():[],u=0===this.Yf.size&&this.ar?__PRIVATE_SyncState.Yn:__PRIVATE_SyncState.$n,a=u!==this.$f;return this.$f=u,0!==s.length||a?{snapshot:new __PRIVATE_ViewSnapshot(this.query,t.Hf,i,s,t.Jn,u===__PRIVATE_SyncState.$n,a,!1),rl:o}:{rl:o}},t.prototype.il=function(t){return this.ar&&t===__PRIVATE_OnlineState.T?(this.ar=!1,this.io({Hf:this.Hf,Jf:new __PRIVATE_DocumentChangeSet,Jn:this.Jn,tl:!1},!1)):{rl:[]}},t.prototype.sl=function(t){return!this.Wf.has(t)&&(!!this.Hf.has(t)&&!this.Hf.get(t).de)},t.prototype.el=function(t){var e=this;t&&(t._r.forEach((function(t){return e.Wf=e.Wf.add(t)})),t.cr.forEach((function(t){return assert(e.Wf.has(t),"Modified document "+t+" not found in view.")})),t.hr.forEach((function(t){return e.Wf=e.Wf.delete(t)})),this.ar=t.ar)},t.prototype.nl=function(){var t=this;if(!this.ar)return[];var e=this.Yf;this.Yf=__PRIVATE_documentKeySet(),this.Hf.forEach((function(e){t.sl(e.key)&&(t.Yf=t.Yf.add(e.key))}));var n=[];return e.forEach((function(e){t.Yf.has(e)||n.push(new __PRIVATE_RemovedLimboDocument(e))})),this.Yf.forEach((function(t){e.has(t)||n.push(new __PRIVATE_AddedLimboDocument(t))})),n},t.prototype.ol=function(t){this.Wf=t.r_,this.Yf=__PRIVATE_documentKeySet();var e=this.zf(t.documents);return this.io(e,!0)},t.prototype.ul=function(){return __PRIVATE_ViewSnapshot.er(this.query,this.Hf,this.Jn,this.$f===__PRIVATE_SyncState.$n)},t}();function __PRIVATE_compareChangeType(t,e){var n=function(t){switch(t){case __PRIVATE_ChangeType.jn:return 1;case __PRIVATE_ChangeType.Qn:case __PRIVATE_ChangeType.Wn:return 2;case __PRIVATE_ChangeType.qn:return 0;default:return fail("Unknown ChangeType: "+t)}};return n(t)-n(e)}var __PRIVATE_RETRY_COUNT=5,__PRIVATE_TransactionRunner=function(){function t(t,e,n,r){this.jo=t,this.al=e,this.updateFunction=n,this.$o=r,this._l=__PRIVATE_RETRY_COUNT,this.cc=new __PRIVATE_ExponentialBackoff(this.jo,__PRIVATE_TimerId.Ko)}return t.prototype.cl=function(){this.hl()},t.prototype.hl=function(){var t=this;this.cc.Z_((function(){return tslib.__awaiter(t,void 0,void 0,(function(){var t,e,n=this;return tslib.__generator(this,(function(r){return t=this.al.jh(),(e=this.fl(t))&&e.then((function(e){n.jo.Jo((function(){return t.commit().then((function(){n.$o.resolve(e)})).catch((function(t){n.ll(t)}))}))})).catch((function(t){n.ll(t)})),[2]}))}))}))},t.prototype.fl=function(t){try{var e=this.updateFunction(t);return!__PRIVATE_isNullOrUndefined(e)&&e.catch&&e.then?e:(this.$o.reject(Error("Transaction callback must return a Promise")),null)}catch(t){return this.$o.reject(t),null}},t.prototype.ll=function(t){var e=this;this._l>0&&this.dl(t)?(this._l-=1,this.jo.Jo((function(){return e.hl(),Promise.resolve()}))):this.$o.reject(t)},t.prototype.dl=function(t){if("FirebaseError"===t.name){var e=t.code;return"aborted"===e||"failed-precondition"===e||!__PRIVATE_isPermanentError(e)}return!1},t}(),__PRIVATE_LOG_TAG$7="SyncEngine",__PRIVATE_QueryView=function(t,e,n){this.query=t,this.targetId=e,this.view=n},__PRIVATE_LimboResolution=function(t){this.key=t,this.Tl=!1},__PRIVATE_SyncEngine=function(){function t(t,e,n,r){this.Gu=t,this.al=e,this.El=n,this.currentUser=r,this.Pl=null,this.Al=new __PRIVATE_ObjectMap((function(t){return t.canonicalId()})),this.Rl={},this.Il=new __PRIVATE_SortedMap(__PRIVATE_DocumentKey.X),this.Vl={},this.ml=new __PRIVATE_ReferenceSet,this.vl={},this.pl=new Map,this.bl=__PRIVATE_TargetIdGenerator.Qf(),this.isPrimary=void 0,this.onlineState=__PRIVATE_OnlineState.h}return Object.defineProperty(t.prototype,"gl",{get:function(){return!0===this.isPrimary},enumerable:!0,configurable:!0}),t.prototype.subscribe=function(t){assert(null!==t,"SyncEngine listener cannot be null"),assert(null===this.Pl,"SyncEngine already has a subscriber."),this.Pl=t},t.prototype.listen=function(t){return tslib.__awaiter(this,void 0,void 0,(function(){var e,n,r,i,s;return tslib.__generator(this,(function(o){switch(o.label){case 0:return this.wl("listen()"),(r=this.Al.get(t))?(e=r.targetId,this.El.Af(e),n=r.view.ul(),[3,4]):[3,1];case 1:return[4,this.Gu.Xa(t.Rn())];case 2:return i=o.sent(),s=this.El.Af(i.targetId),e=i.targetId,[4,this.yl(t,e,"current"===s)];case 3:n=o.sent(),this.isPrimary&&this.al.listen(i),o.label=4;case 4:return this.Pl.wc([n]),[2,e]}}))}))},t.prototype.yl=function(t,e,n){return tslib.__awaiter(this,void 0,void 0,(function(){var r,i,s,o,u,a;return tslib.__generator(this,(function(_){switch(_.label){case 0:return[4,this.Gu.e_(t,!0)];case 1:return r=_.sent(),i=new __PRIVATE_View(t,r.r_),s=i.zf(r.documents),o=TargetChange.ur(e,n&&this.onlineState!==__PRIVATE_OnlineState.T),assert(0===(u=i.io(s,!0===this.isPrimary,o)).rl.length,"View returned limbo docs before target ack from the server."),assert(!!u.snapshot,"applyChanges for new view should always return a snapshot"),a=new __PRIVATE_QueryView(t,e,i),this.Al.set(t,a),this.Rl[e]||(this.Rl[e]=[]),this.Rl[e].push(t),[2,u.snapshot]}}))}))},t.prototype.Sl=function(t){return tslib.__awaiter(this,void 0,void 0,(function(){var e,n;return tslib.__generator(this,(function(r){switch(r.label){case 0:return[4,this.Gu.e_(t.query,!0)];case 1:return e=r.sent(),n=t.view.ol(e),this.isPrimary&&this.Dl(t.targetId,n.rl),[2,n]}}))}))},t.prototype.yh=function(t){return tslib.__awaiter(this,void 0,void 0,(function(){var e,n,r=this;return tslib.__generator(this,(function(i){switch(i.label){case 0:return this.wl("unlisten()"),assert(!!(e=this.Al.get(t)),"Trying to unlisten on query not found:"+t),(n=this.Rl[e.targetId]).length>1?(this.Rl[e.targetId]=n.filter((function(e){return!e.isEqual(t)})),this.Al.delete(t),[2]):this.isPrimary?(this.El.If(e.targetId),this.El.lf(e.targetId)?[3,2]:[4,this.Gu.t_(e.targetId,!1).then((function(){r.El.mf(e.targetId),r.al.yh(e.targetId),r.Cl(e.targetId)})).catch(__PRIVATE_ignoreIfPrimaryLeaseLoss)]):[3,3];case 1:i.sent(),i.label=2;case 2:return[3,5];case 3:return this.Cl(e.targetId),[4,this.Gu.t_(e.targetId,!0)];case 4:i.sent(),i.label=5;case 5:return[2]}}))}))},t.prototype.write=function(t,e){return tslib.__awaiter(this,void 0,void 0,(function(){var n;return tslib.__generator(this,(function(r){switch(r.label){case 0:return this.wl("write()"),[4,this.Gu.Va(t)];case 1:return n=r.sent(),this.El.df(n.batchId),this.Ol(n.batchId,e),[4,this.Fl(n.Hs)];case 2:return r.sent(),[4,this.al.vh()];case 3:return r.sent(),[2]}}))}))},t.prototype.runTransaction=function(t,e,n){new __PRIVATE_TransactionRunner(t,this.al,e,n).cl()},t.prototype.Ga=function(t){return tslib.__awaiter(this,void 0,void 0,(function(){var e,n=this;return tslib.__generator(this,(function(r){switch(r.label){case 0:this.wl("applyRemoteEvent()"),r.label=1;case 1:return r.trys.push([1,4,,6]),[4,this.Gu.Ga(t)];case 2:return e=r.sent(),forEach(t.nr,(function(t,e){var r=n.Vl[Number(t)];r&&(assert(e._r.size+e.cr.size+e.hr.size<=1,"Limbo resolution for single document contains multiple changes."),e._r.size>0?r.Tl=!0:e.cr.size>0?assert(r.Tl,"Received change for limbo target document without add."):e.hr.size>0&&(assert(r.Tl,"Received remove for limbo target document without add."),r.Tl=!1))})),[4,this.Fl(e,t)];case 3:return r.sent(),[3,6];case 4:return[4,__PRIVATE_ignoreIfPrimaryLeaseLoss(r.sent())];case 5:return r.sent(),[3,6];case 6:return[2]}}))}))},t.prototype.il=function(t,e){if(this.isPrimary&&e===__PRIVATE_OnlineStateSource.P||!this.isPrimary&&e===__PRIVATE_OnlineStateSource.A){this.wl("applyOnlineStateChange()");var n=[];this.Al.forEach((function(e,r){var i=r.view.il(t);assert(0===i.rl.length,"OnlineState should not affect limbo documents."),i.snapshot&&n.push(i.snapshot)})),this.Pl.Nl(t),this.Pl.wc(n),this.onlineState=t,this.isPrimary&&this.El.bf(t)}},t.prototype.Fh=function(t,e){return tslib.__awaiter(this,void 0,void 0,(function(){var n,r,i,s,o,u=this;return tslib.__generator(this,(function(a){switch(a.label){case 0:return this.wl("rejectListens()"),this.El.vf(t,"rejected",e),n=this.Vl[t],(r=n&&n.key)?(this.Il=this.Il.remove(r),delete this.Vl[t],i=(i=new __PRIVATE_SortedMap(__PRIVATE_DocumentKey.X)).At(r,new __PRIVATE_NoDocument(r,__PRIVATE_SnapshotVersion.W())),s=__PRIVATE_documentKeySet().add(r),o=new __PRIVATE_RemoteEvent(__PRIVATE_SnapshotVersion.MIN,{},new __PRIVATE_SortedSet(__PRIVATE_primitiveComparator),i,s),[2,this.Ga(o)]):[3,1];case 1:return[4,this.Gu.t_(t,!1).then((function(){return u.Cl(t,e)})).catch(__PRIVATE_ignoreIfPrimaryLeaseLoss)];case 2:a.sent(),a.label=3;case 3:return[2]}}))}))},t.prototype.Nf=function(t,e,n){return tslib.__awaiter(this,void 0,void 0,(function(){var r;return tslib.__generator(this,(function(i){switch(i.label){case 0:return this.wl("applyBatchState()"),[4,this.Gu.va(t)];case 1:return null===(r=i.sent())?(debug(__PRIVATE_LOG_TAG$7,"Cannot apply mutation batch with id: "+t),[2]):"pending"!==e?[3,3]:[4,this.al.vh()];case 2:return i.sent(),[3,4];case 3:"acknowledged"===e||"rejected"===e?(this.Ml(t,n||null),this.Gu.o_(t)):fail("Unknown batchState: "+e),i.label=4;case 4:return[4,this.Fl(r)];case 5:return i.sent(),[2]}}))}))},t.prototype.Uh=function(t){return tslib.__awaiter(this,void 0,void 0,(function(){var e,n;return tslib.__generator(this,(function(r){switch(r.label){case 0:this.wl("applySuccessfulWrite()"),e=t.batch.batchId,this.Ml(e,null),this.Ll(e),r.label=1;case 1:return r.trys.push([1,4,,6]),[4,this.Gu.ba(t)];case 2:return n=r.sent(),this.El.Ef(e,"acknowledged"),[4,this.Fl(n)];case 3:return r.sent(),[3,6];case 4:return[4,__PRIVATE_ignoreIfPrimaryLeaseLoss(r.sent())];case 5:return r.sent(),[3,6];case 6:return[2]}}))}))},t.prototype.Kh=function(t,e){return tslib.__awaiter(this,void 0,void 0,(function(){var n;return tslib.__generator(this,(function(r){switch(r.label){case 0:this.wl("rejectFailedWrite()"),this.Ml(t,e),this.Ll(t),r.label=1;case 1:return r.trys.push([1,4,,6]),[4,this.Gu.Da(t)];case 2:return n=r.sent(),this.El.Ef(t,"rejected",e),[4,this.Fl(n)];case 3:return r.sent(),[3,6];case 4:return[4,__PRIVATE_ignoreIfPrimaryLeaseLoss(r.sent())];case 5:return r.sent(),[3,6];case 6:return[2]}}))}))},t.prototype.Gl=function(t){return tslib.__awaiter(this,void 0,void 0,(function(){var e,n;return tslib.__generator(this,(function(r){switch(r.label){case 0:return this.al._h()||debug(__PRIVATE_LOG_TAG$7,"The network is disabled. The task returned by 'awaitPendingWrites()' will not complete until the network is enabled."),[4,this.Gu.Fa()];case 1:return(e=r.sent())===__PRIVATE_BATCHID_UNKNOWN?(t.resolve(),[2]):((n=this.pl.get(e)||[]).push(t),this.pl.set(e,n),[2])}}))}))},t.prototype.Ll=function(t){(this.pl.get(t)||[]).forEach((function(t){t.resolve()})),this.pl.delete(t)},t.prototype.Bl=function(t){this.pl.forEach((function(e){e.forEach((function(e){e.reject(new FirestoreError(Code.CANCELLED,t))}))})),this.pl.clear()},t.prototype.Ol=function(t,e){var n=this.vl[this.currentUser.I()];n||(n=new __PRIVATE_SortedMap(__PRIVATE_primitiveComparator)),n=n.At(t,e),this.vl[this.currentUser.I()]=n},t.prototype.Ml=function(t,e){var n=this.vl[this.currentUser.I()];if(n){var r=n.get(t);r&&(assert(t===n.Vt(),"Mutation callbacks processed out-of-order?"),e?r.reject(e):r.resolve(),n=n.remove(t)),this.vl[this.currentUser.I()]=n}},t.prototype.Cl=function(t,e){var n=this;void 0===e&&(e=null),this.El.If(t),assert(this.Rl[t]&&0!==this.Rl[t].length,"There are no queries mapped to target id "+t);for(var r=0,i=this.Rl[t];r<i.length;r++){var s=i[r];this.Al.delete(s),e&&this.Pl.Ul(s,e)}if(delete this.Rl[t],this.isPrimary){var o=this.ml.Ls(t);this.ml.Ns(t),o.forEach((function(t){n.ml.Gs(t)||n.kl(t)}))}},t.prototype.kl=function(t){var e=this.Il.get(t);null!==e&&(this.al.yh(e),this.Il=this.Il.remove(t),delete this.Vl[e])},t.prototype.Dl=function(t,e){for(var n=0,r=e;n<r.length;n++){var i=r[n];if(i instanceof __PRIVATE_AddedLimboDocument)this.ml.Ss(i.key,t),this.xl(i);else if(i instanceof __PRIVATE_RemovedLimboDocument){debug(__PRIVATE_LOG_TAG$7,"Document no longer in limbo: "+i.key),this.ml.Cs(i.key,t),this.ml.Gs(i.key)||this.kl(i.key)}else fail("Unknown limbo change: "+JSON.stringify(i))}},t.prototype.xl=function(t){var e=t.key;if(!this.Il.get(e)){debug(__PRIVATE_LOG_TAG$7,"New document in limbo: "+e);var n=this.bl.next(),r=Query.un(e.path);this.Vl[n]=new __PRIVATE_LimboResolution(e),this.al.listen(new __PRIVATE_TargetData(r.Rn(),n,__PRIVATE_TargetPurpose.Nn,__PRIVATE_ListenSequence.Fo)),this.Il=this.Il.At(e,n)}},t.prototype.Kl=function(){return this.Il},t.prototype.Fl=function(t,e){return tslib.__awaiter(this,void 0,void 0,(function(){var n,r,i,s=this;return tslib.__generator(this,(function(o){switch(o.label){case 0:return n=[],r=[],i=[],this.Al.forEach((function(o,u){i.push(Promise.resolve().then((function(){var e=u.view.zf(t);return e.tl?s.Gu.e_(u.query,!1).then((function(t){var n=t.documents;return u.view.zf(n,e)})):e})).then((function(t){var i=e&&e.nr[u.targetId],o=u.view.io(t,!0===s.isPrimary,i);if(s.Dl(u.targetId,o.rl),o.snapshot){s.isPrimary&&s.El.vf(u.targetId,o.snapshot.fromCache?"not-current":"current"),n.push(o.snapshot);var a=__PRIVATE_LocalViewChanges.yo(u.targetId,o.snapshot);r.push(a)}})))})),[4,Promise.all(i)];case 1:return o.sent(),this.Pl.wc(n),[4,this.Gu.Wa(r)];case 2:return o.sent(),[2]}}))}))},t.prototype.wl=function(t){assert(null!==this.Pl,"Trying to call "+t+" before calling subscribe().")},t.prototype.qh=function(t){return tslib.__awaiter(this,void 0,void 0,(function(){var e,n;return tslib.__generator(this,(function(r){switch(r.label){case 0:return e=!this.currentUser.isEqual(t),this.currentUser=t,e?(this.Bl("'waitForPendingWrites' promise is rejected due to a user change."),[4,this.Gu.Ea(t)]):[3,3];case 1:return n=r.sent(),this.El.Ea(t,n.Ra,n.Ia),[4,this.Fl(n.Aa)];case 2:r.sent(),r.label=3;case 3:return[4,this.al.qh()];case 4:return r.sent(),[2]}}))}))},t.prototype.Qh=function(t){return tslib.__awaiter(this,void 0,void 0,(function(){var e,n,r,i,s,o,u=this;return tslib.__generator(this,(function(a){switch(a.label){case 0:return!0!==t||!0===this.isPrimary?[3,3]:(this.isPrimary=!0,[4,this.al.Qh(!0)]);case 1:return a.sent(),s=this.El.ff(),[4,this.jl(s.ot())];case 2:for(e=a.sent(),n=0,r=e;n<r.length;n++)i=r[n],this.al.listen(i);return[3,7];case 3:return!1!==t||!1===this.isPrimary?[3,7]:(this.isPrimary=!1,s=[],o=Promise.resolve(),__PRIVATE_forEachNumber(this.Rl,(function(t,e){u.El.Vf(t)?s.push(t):o=o.then((function(){return u.Cl(t),u.Gu.t_(t,!0)})),u.al.yh(t)})),[4,o]);case 4:return a.sent(),[4,this.jl(s)];case 5:return a.sent(),this.ql(),[4,this.al.Qh(!1)];case 6:a.sent(),a.label=7;case 7:return[2]}}))}))},t.prototype.ql=function(){var t=this;__PRIVATE_forEachNumber(this.Vl,(function(e){t.al.yh(e)})),this.ml.Ms(),this.Vl=[],this.Il=new __PRIVATE_SortedMap(__PRIVATE_DocumentKey.X)},t.prototype.jl=function(t){return tslib.__awaiter(this,void 0,void 0,(function(){var e,n,r,i,s,o,u,a,_,c,h,f,l;return tslib.__generator(this,(function(d){switch(d.label){case 0:e=[],n=[],r=0,i=t,d.label=1;case 1:return r<i.length?(s=i[r],o=void 0,(u=this.Rl[s])&&0!==u.length?[4,this.Gu.t_(s,!0)]:[3,8]):[3,14];case 2:return d.sent(),[4,this.Gu.Xa(u[0].Rn())];case 3:o=d.sent(),a=0,_=u,d.label=4;case 4:return a<_.length?(c=_[a],assert(!!(h=this.Al.get(c)),"No query view found for "+c),[4,this.Sl(h)]):[3,7];case 5:(f=d.sent()).snapshot&&n.push(f.snapshot),d.label=6;case 6:return a++,[3,4];case 7:return[3,12];case 8:return assert(!0===this.isPrimary,"A secondary tab should never have an active target without an active query."),[4,this.Gu.__(s)];case 9:return assert(!!(l=d.sent()),"Target for id "+s+" not found"),[4,this.Gu.Xa(l)];case 10:return o=d.sent(),[4,this.yl(this.Ql(l),s,!1)];case 11:d.sent(),d.label=12;case 12:e.push(o),d.label=13;case 13:return r++,[3,1];case 14:return this.Pl.wc(n),[2,e]}}))}))},t.prototype.Ql=function(t){return new Query(t.path,t.collectionGroup,t.orderBy,t.filters,t.limit,__PRIVATE_LimitType.tn,t.startAt,t.endAt)},t.prototype.s_=function(){return this.Gu.s_()},t.prototype.Mf=function(t,e,n){return tslib.__awaiter(this,void 0,void 0,(function(){var r,i;return tslib.__generator(this,(function(s){switch(s.label){case 0:if(this.isPrimary)return debug(__PRIVATE_LOG_TAG$7,"Ignoring unexpected query state notification."),[2];if(!this.Rl[t])return[3,7];switch(e){case"current":case"not-current":return[3,1];case"rejected":return[3,4]}return[3,6];case 1:return[4,this.Gu.c_()];case 2:return r=s.sent(),i=__PRIVATE_RemoteEvent.or(t,"current"===e),[4,this.Fl(r,i)];case 3:return s.sent(),[3,7];case 4:return[4,this.Gu.t_(t,!0)];case 5:return s.sent(),this.Cl(t,n),[3,7];case 6:fail("Unexpected target state: "+e),s.label=7;case 7:return[2]}}))}))},t.prototype.Lf=function(t,e){return tslib.__awaiter(this,void 0,void 0,(function(){var n,r,i,s,o,u,a,_,c,h=this;return tslib.__generator(this,(function(f){switch(f.label){case 0:if(!this.isPrimary)return[2];n=0,r=t,f.label=1;case 1:return n<r.length?(c=r[n],assert(!this.Rl[c],"Trying to add an already active target"),[4,this.Gu.__(c)]):[3,6];case 2:return assert(!!(i=f.sent()),"Query data for active target "+c+" not found"),[4,this.Gu.Xa(i)];case 3:return s=f.sent(),[4,this.yl(this.Ql(i),s.targetId,!1)];case 4:f.sent(),this.al.listen(s),f.label=5;case 5:return n++,[3,1];case 6:o=function(t){return tslib.__generator(this,(function(e){switch(e.label){case 0:return u.Rl[t]?[4,u.Gu.t_(t,!1).then((function(){h.al.yh(t),h.Cl(t)})).catch(__PRIVATE_ignoreIfPrimaryLeaseLoss)]:[2,"continue"];case 1:return e.sent(),[2]}}))},u=this,a=0,_=e,f.label=7;case 7:return a<_.length?(c=_[a],[5,o(c)]):[3,10];case 8:f.sent(),f.label=9;case 9:return a++,[3,7];case 10:return[2]}}))}))},t.prototype.enableNetwork=function(){return this.Gu.a_(!0),this.al.enableNetwork()},t.prototype.disableNetwork=function(){return this.Gu.a_(!1),this.al.disableNetwork()},t.prototype.Zr=function(t){var e=this.Vl[t];if(e&&e.Tl)return __PRIVATE_documentKeySet().add(e.key);var n=__PRIVATE_documentKeySet(),r=this.Rl[t];if(!r)return n;for(var i=0,s=r;i<s.length;i++){var o=s[i],u=this.Al.get(o);assert(!!u,"No query view found for "+o),n=n.Ht(u.view.Xf)}return n},t}(),__PRIVATE_QueryListenersInfo=function(){this.Wl=null,this.targetId=0,this.$l=[]},__PRIVATE_EventManager=function(){function t(t){this.Dh=t,this.Yl=new __PRIVATE_ObjectMap((function(t){return t.canonicalId()})),this.onlineState=__PRIVATE_OnlineState.h,this.Hl=new Set,this.Dh.subscribe(this)}return t.prototype.listen=function(t){var e=t.query,n=!1,r=this.Yl.get(e);(r||(n=!0,r=new __PRIVATE_QueryListenersInfo,this.Yl.set(e,r)),r.$l.push(t),assert(!t.il(this.onlineState),"applyOnlineStateChange() shouldn't raise an event for brand-new listeners."),r.Wl)&&(t.Xl(r.Wl)&&this.zl());return n?this.Dh.listen(e).then((function(t){return r.targetId=t,t})):Promise.resolve(r.targetId)},t.prototype.yh=function(t){return tslib.__awaiter(this,void 0,void 0,(function(){var e,n,r,i;return tslib.__generator(this,(function(s){return e=t.query,n=!1,(r=this.Yl.get(e))&&(i=r.$l.indexOf(t))>=0&&(r.$l.splice(i,1),n=0===r.$l.length),n?(this.Yl.delete(e),[2,this.Dh.yh(e)]):[2]}))}))},t.prototype.wc=function(t){for(var e=!1,n=0,r=t;n<r.length;n++){var i=r[n],s=i.query,o=this.Yl.get(s);if(o){for(var u=0,a=o.$l;u<a.length;u++){a[u].Xl(i)&&(e=!0)}o.Wl=i}}e&&this.zl()},t.prototype.Ul=function(t,e){var n=this.Yl.get(t);if(n)for(var r=0,i=n.$l;r<i.length;r++){i[r].onError(e)}this.Yl.delete(t)},t.prototype.Nl=function(t){this.onlineState=t;var e=!1;this.Yl.forEach((function(n,r){for(var i=0,s=r.$l;i<s.length;i++){s[i].il(t)&&(e=!0)}})),e&&this.zl()},t.prototype.Jl=function(t){this.Hl.add(t),t.next()},t.prototype.Zl=function(t){this.Hl.delete(t)},t.prototype.zl=function(){this.Hl.forEach((function(t){t.next()}))},t}(),__PRIVATE_QueryListener=function(){function t(t,e,n){this.query=t,this.td=e,this.ed=!1,this.nd=null,this.onlineState=__PRIVATE_OnlineState.h,this.options=n||{}}return t.prototype.Xl=function(t){if(assert(t.docChanges.length>0||t.Zn,"We got a new snapshot with no changes?"),!this.options.includeMetadataChanges){for(var e=[],n=0,r=t.docChanges;n<r.length;n++){var i=r[n];i.type!==__PRIVATE_ChangeType.Wn&&e.push(i)}t=new __PRIVATE_ViewSnapshot(t.query,t.docs,t.zn,e,t.Jn,t.fromCache,t.Zn,!0)}var s=!1;return this.ed?this.rd(t)&&(this.td.next(t),s=!0):this.sd(t,this.onlineState)&&(this.od(t),s=!0),this.nd=t,s},t.prototype.onError=function(t){this.td.error(t)},t.prototype.il=function(t){this.onlineState=t;var e=!1;return this.nd&&!this.ed&&this.sd(this.nd,t)&&(this.od(this.nd),e=!0),e},t.prototype.sd=function(t,e){if(assert(!this.ed,"Determining whether to raise first event but already had first event"),!t.fromCache)return!0;var n=e!==__PRIVATE_OnlineState.T;return this.options.ud&&n?(assert(t.fromCache,"Waiting for sync, but snapshot is not from cache"),!1):!t.docs.et()||e===__PRIVATE_OnlineState.T},t.prototype.rd=function(t){if(t.docChanges.length>0)return!0;var e=this.nd&&this.nd.hasPendingWrites!==t.hasPendingWrites;return!(!t.Zn&&!e)&&!0===this.options.includeMetadataChanges},t.prototype.od=function(t){assert(!this.ed,"Trying to raise initial events for second time"),t=__PRIVATE_ViewSnapshot.er(t.query,t.docs,t.Jn,t.fromCache),this.ed=!0,this.td.next(t)},t}(),__PRIVATE_escapeChar="",__PRIVATE_encodedSeparatorChar="",__PRIVATE_encodedNul="",__PRIVATE_encodedEscape="";function encode(t){for(var e="",n=0;n<t.length;n++)e.length>0&&(e=__PRIVATE_encodeSeparator(e)),e=__PRIVATE_encodeSegment(t.get(n),e);return __PRIVATE_encodeSeparator(e)}function __PRIVATE_encodeSegment(t,e){for(var n=e,r=t.length,i=0;i<r;i++){var s=t.charAt(i);switch(s){case"\0":n+=__PRIVATE_escapeChar+__PRIVATE_encodedNul;break;case __PRIVATE_escapeChar:n+=__PRIVATE_escapeChar+__PRIVATE_encodedEscape;break;default:n+=s}}return n}function __PRIVATE_encodeSeparator(t){return t+__PRIVATE_escapeChar+__PRIVATE_encodedSeparatorChar}function decode(t){var e=t.length;if(assert(e>=2,"Invalid path "+t),2===e)return assert(t.charAt(0)===__PRIVATE_escapeChar&&t.charAt(1)===__PRIVATE_encodedSeparatorChar,"Non-empty path "+t+" had length 2"),ResourcePath._t;for(var n=e-2,r=[],i="",s=0;s<e;){var o=t.indexOf(__PRIVATE_escapeChar,s);switch((o<0||o>n)&&fail('Invalid encoded resource path: "'+t+'"'),t.charAt(o+1)){case __PRIVATE_encodedSeparatorChar:var u=t.substring(s,o),a=void 0;0===i.length?a=u:(a=i+=u,i=""),r.push(a);break;case __PRIVATE_encodedNul:i+=t.substring(s,o),i+="\0";break;case __PRIVATE_encodedEscape:i+=t.substring(s,o+1);break;default:fail('Invalid encoded resource path: "'+t+'"')}s=o+2}return new ResourcePath(r)}var __PRIVATE_LOG_TAG$8="SimpleDb",__PRIVATE_TRANSACTION_RETRY_COUNT=3,__PRIVATE_SimpleDb=function(){function t(e){this.db=e,12.2===t.ad(util.getUA())&&error("Firestore persistence suffers from a bug in iOS 12.2 Safari that may cause your app to stop working. See https://stackoverflow.com/q/56496296/110915 for details and a potential workaround.")}return t._d=function(e,n,r){return assert(t.ef(),"IndexedDB not supported in current environment."),debug(__PRIVATE_LOG_TAG$8,"Opening database:",e),new PersistencePromise((function(i,s){var o=window.indexedDB.open(e,n);o.onsuccess=function(e){var n=e.target.result;i(new t(n))},o.onblocked=function(){s(new FirestoreError(Code.FAILED_PRECONDITION,"Cannot upgrade IndexedDB schema while another tab is open. Close all tabs that access Firestore and reload this page to proceed."))},o.onerror=function(t){var e=t.target.error;"VersionError"===e.name?s(new FirestoreError(Code.FAILED_PRECONDITION,"A newer version of the Firestore SDK was previously used and so the persisted data is not compatible with the version of the SDK you are now using. The SDK will operate with persistence disabled. If you need persistence, please re-upgrade to a newer version of the SDK or else clear the persisted IndexedDB data for your app to start fresh.")):s(e)},o.onupgradeneeded=function(t){debug(__PRIVATE_LOG_TAG$8,'Database "'+e+'" requires upgrade from version:',t.oldVersion);var n=t.target.result;r.createOrUpgrade(n,o.transaction,t.oldVersion,SCHEMA_VERSION).next((function(){debug(__PRIVATE_LOG_TAG$8,"Database upgrade to version "+SCHEMA_VERSION+" complete")}))}})).Qs()},t.delete=function(t){return debug(__PRIVATE_LOG_TAG$8,"Removing database:",t),__PRIVATE_wrapRequest(window.indexedDB.deleteDatabase(t)).Qs()},t.ef=function(){if("undefined"==typeof window||null==window.indexedDB)return!1;if(t.hd())return!0;if(void 0===window.navigator)return!1;var e=util.getUA(),n=t.ad(e),r=0<n&&n<10,i=t.fd(e),s=0<i&&i<4.5;return!(e.indexOf("MSIE ")>0||e.indexOf("Trident/")>0||e.indexOf("Edge/")>0||r||s)},t.hd=function(){var t;return"undefined"!=typeof __PRIVATE_process&&"YES"===(null===(t=__PRIVATE_process.__PRIVATE_env)||void 0===t?void 0:t.ld)},t.dd=function(t,e){return t.store(e)},t.ad=function(t){var e=t.match(/i(?:phone|pad|pod) os ([\d_]+)/i),n=e?e[1].split("_").slice(0,2).join("."):"-1";return Number(n)},t.fd=function(t){var e=t.match(/Android ([\d.]+)/i),n=e?e[1].split(".").slice(0,2).join("."):"-1";return Number(n)},t.prototype.Td=function(t){this.db.onversionchange=function(e){return t(e)}},t.prototype.runTransaction=function(t,e,n){return tslib.__awaiter(this,void 0,void 0,(function(){var r,i,s,o,u,a;return tslib.__generator(this,(function(_){switch(_.label){case 0:r=t.startsWith("readonly"),i=t.endsWith("idempotent"),s=0,o=function(){var t,o,a,_;return tslib.__generator(this,(function(c){switch(c.label){case 0:++s,t=__PRIVATE_SimpleDbTransaction.open(u.db,r?"readonly":"readwrite",e),c.label=1;case 1:return c.trys.push([1,3,,4]),(o=n(t).catch((function(e){return t.abort(e),PersistencePromise.reject(e)})).Qs()).catch((function(){})),[4,t.Ed];case 2:return c.sent(),[2,{value:o}];case 3:return a=c.sent(),_=i&&"FirebaseError"!==a.name&&s<__PRIVATE_TRANSACTION_RETRY_COUNT,debug(__PRIVATE_LOG_TAG$8,"Transaction failed with error: %s. Retrying: %s.",a.message,_),_?[3,4]:[2,{value:Promise.reject(a)}];case 4:return[2]}}))},u=this,_.label=1;case 1:return[5,o()];case 2:return"object"==typeof(a=_.sent())?[2,a.value]:[3,1];case 3:return[2]}}))}))},t.prototype.close=function(){this.db.close()},t}(),__PRIVATE_IterationController=function(){function t(t){this.Pd=t,this.Ad=!1,this.Rd=null}return Object.defineProperty(t.prototype,"xs",{get:function(){return this.Ad},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"Id",{get:function(){return this.Rd},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"cursor",{set:function(t){this.Pd=t},enumerable:!0,configurable:!0}),t.prototype.done=function(){this.Ad=!0},t.prototype.Vd=function(t){this.Rd=t},t.prototype.delete=function(){return __PRIVATE_wrapRequest(this.Pd.delete())},t}(),__PRIVATE_SimpleDbTransaction=function(){function t(t){var e=this;this.transaction=t,this.aborted=!1,this.md=new __PRIVATE_Deferred,this.transaction.oncomplete=function(){e.md.resolve()},this.transaction.onabort=function(){t.error?e.md.reject(t.error):e.md.resolve()},this.transaction.onerror=function(t){var n=__PRIVATE_checkForAndReportiOSError(t.target.error);e.md.reject(n)}}return t.open=function(e,n,r){return new t(e.transaction(r,n))},Object.defineProperty(t.prototype,"Ed",{get:function(){return this.md.promise},enumerable:!0,configurable:!0}),t.prototype.abort=function(t){t&&this.md.reject(t),this.aborted||(debug(__PRIVATE_LOG_TAG$8,"Aborting transaction:",t?t.message:"Client-initiated abort"),this.aborted=!0,this.transaction.abort())},t.prototype.store=function(t){var e=this.transaction.objectStore(t);return assert(!!e,"Object store not part of transaction: "+t),new __PRIVATE_SimpleDbStore(e)},t}(),__PRIVATE_SimpleDbStore=function(){function t(t){this.store=t}return t.prototype.put=function(t,e){var n;return void 0!==e?(debug(__PRIVATE_LOG_TAG$8,"PUT",this.store.name,t,e),n=this.store.put(e,t)):(debug(__PRIVATE_LOG_TAG$8,"PUT",this.store.name,"<auto-key>",t),n=this.store.put(t)),__PRIVATE_wrapRequest(n)},t.prototype.add=function(t){return debug(__PRIVATE_LOG_TAG$8,"ADD",this.store.name,t,t),__PRIVATE_wrapRequest(this.store.add(t))},t.prototype.get=function(t){var e=this;return __PRIVATE_wrapRequest(this.store.get(t)).next((function(n){return void 0===n&&(n=null),debug(__PRIVATE_LOG_TAG$8,"GET",e.store.name,t,n),n}))},t.prototype.delete=function(t){return debug(__PRIVATE_LOG_TAG$8,"DELETE",this.store.name,t),__PRIVATE_wrapRequest(this.store.delete(t))},t.prototype.count=function(){return debug(__PRIVATE_LOG_TAG$8,"COUNT",this.store.name),__PRIVATE_wrapRequest(this.store.count())},t.prototype.vd=function(t,e){var n=this.cursor(this.options(t,e)),r=[];return this.pd(n,(function(t,e){r.push(e)})).next((function(){return r}))},t.prototype.bd=function(t,e){debug(__PRIVATE_LOG_TAG$8,"DELETE ALL",this.store.name);var n=this.options(t,e);n.gd=!1;var r=this.cursor(n);return this.pd(r,(function(t,e,n){return n.delete()}))},t.prototype.wd=function(t,e){var n;e?n=t:(n={},e=t);var r=this.cursor(n);return this.pd(r,e)},t.prototype.yd=function(t){var e=this.cursor({});return new PersistencePromise((function(n,r){e.onerror=function(t){var e=__PRIVATE_checkForAndReportiOSError(t.target.error);r(e)},e.onsuccess=function(e){var r=e.target.result;r?t(r.primaryKey,r.value).next((function(t){t?r.continue():n()})):n()}}))},t.prototype.pd=function(t,e){var n=[];return new PersistencePromise((function(r,i){t.onerror=function(t){i(t.target.error)},t.onsuccess=function(t){var i=t.target.result;if(i){var s=new __PRIVATE_IterationController(i),o=e(i.primaryKey,i.value,s);if(o instanceof PersistencePromise){var u=o.catch((function(t){return s.done(),PersistencePromise.reject(t)}));n.push(u)}s.xs?r():null===s.Id?i.continue():i.continue(s.Id)}else r()}})).next((function(){return PersistencePromise.$s(n)}))},t.prototype.options=function(t,e){var n=void 0;return void 0!==t&&("string"==typeof t?n=t:(assert(void 0===e,"3rd argument must not be defined if 2nd is a range."),e=t)),{index:n,range:e}},t.prototype.cursor=function(t){var e="next";if(t.reverse&&(e="prev"),t.index){var n=this.store.index(t.index);return t.gd?n.openKeyCursor(t.range,e):n.openCursor(t.range,e)}return this.store.openCursor(t.range,e)},t}();function __PRIVATE_wrapRequest(t){return new PersistencePromise((function(e,n){t.onsuccess=function(t){var n=t.target.result;e(n)},t.onerror=function(t){var e=__PRIVATE_checkForAndReportiOSError(t.target.error);n(e)}}))}var __PRIVATE_reportedIOSError=!1;function __PRIVATE_checkForAndReportiOSError(t){var e=__PRIVATE_SimpleDb.ad(util.getUA());if(e>=12.2&&e<13){var n="An internal error was encountered in the Indexed Database server";if(t.message.indexOf(n)>=0){var r=new FirestoreError("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 __PRIVATE_reportedIOSError||(__PRIVATE_reportedIOSError=!0,setTimeout((function(){throw r}),0)),r}}return t}var __PRIVATE_IndexedDbMutationQueue=function(){function t(t,e,n,r){this.userId=t,this.serializer=e,this.co=n,this.oa=r,this.Sd={}}return t.Dd=function(e,n,r,i){return assert(""!==e.uid,"UserID must not be an empty string."),new t(e.R()?e.uid:"",n,r,i)},t.prototype.Cd=function(t){var e=!0,n=IDBKeyRange.bound([this.userId,Number.NEGATIVE_INFINITY],[this.userId,Number.POSITIVE_INFINITY]);return __PRIVATE_mutationsStore(t).wd({index:DbMutationBatch.userMutationsIndex,range:n},(function(t,n,r){e=!1,r.done()})).next((function(){return e}))},t.prototype.ba=function(t,e,n){return this.Od(t).next((function(e){return e.lastStreamToken=__PRIVATE_convertStreamToken(n),__PRIVATE_mutationQueuesStore(t).put(e)}))},t.prototype.Na=function(t){return this.Od(t).next((function(t){return t.lastStreamToken}))},t.prototype.Ma=function(t,e){return this.Od(t).next((function(n){return n.lastStreamToken=__PRIVATE_convertStreamToken(e),__PRIVATE_mutationQueuesStore(t).put(n)}))},t.prototype.ma=function(t,e,n,r){var i=this,s=__PRIVATE_documentMutationsStore(t),o=__PRIVATE_mutationsStore(t);return o.add({}).next((function(u){assert("number"==typeof u,"Auto-generated key is not a number");for(var a=new __PRIVATE_MutationBatch(u,e,n,r),_=i.serializer.Fd(i.userId,a),c=[],h=new __PRIVATE_SortedSet((function(t,e){return __PRIVATE_primitiveComparator(t.ut(),e.ut())})),f=0,l=r;f<l.length;f++){var d=l[f],T=DbDocumentMutation.key(i.userId,d.key.path,u);h=h.add(d.key.path.tt()),c.push(o.put(_)),c.push(s.put(T,DbDocumentMutation.PLACEHOLDER))}return h.forEach((function(e){c.push(i.co.Nd(t,e))})),t.oo((function(){i.Sd[u]=a.keys()})),PersistencePromise.$s(c).next((function(){return a}))}))},t.prototype.Ca=function(t,e){var n=this;return __PRIVATE_mutationsStore(t).get(e).next((function(t){return t?(assert(t.userId===n.userId,"Unexpected user '"+t.userId+"' for mutation batch "+e),n.serializer.Md(t)):null}))},t.prototype.pa=function(t,e){var n=this;return this.Sd[e]?PersistencePromise.resolve(this.Sd[e]):this.Ca(t,e).next((function(t){if(t){var r=t.keys();return n.Sd[e]=r,r}return null}))},t.prototype.Ya=function(t,e){var n=this,r=e+1,i=IDBKeyRange.lowerBound([this.userId,r]),s=null;return __PRIVATE_mutationsStore(t).wd({index:DbMutationBatch.userMutationsIndex,range:i},(function(t,e,i){e.userId===n.userId&&(assert(e.batchId>=r,"Should have found mutation after "+r),s=n.serializer.Md(e)),i.done()})).next((function(){return s}))},t.prototype.Fa=function(t){var e=IDBKeyRange.upperBound([this.userId,Number.POSITIVE_INFINITY]),n=__PRIVATE_BATCHID_UNKNOWN;return __PRIVATE_mutationsStore(t).wd({index:DbMutationBatch.userMutationsIndex,range:e,reverse:!0},(function(t,e,r){n=e.batchId,r.done()})).next((function(){return n}))},t.prototype.Pa=function(t){var e=this,n=IDBKeyRange.bound([this.userId,__PRIVATE_BATCHID_UNKNOWN],[this.userId,Number.POSITIVE_INFINITY]);return __PRIVATE_mutationsStore(t).vd(DbMutationBatch.userMutationsIndex,n).next((function(t){return t.map((function(t){return e.serializer.Md(t)}))}))},t.prototype.fo=function(t,e){var n=this,r=DbDocumentMutation.prefixForPath(this.userId,e.path),i=IDBKeyRange.lowerBound(r),s=[];return __PRIVATE_documentMutationsStore(t).wd({range:i},(function(r,i,o){var u=r[0],a=r[1],_=r[2],c=decode(a);if(u===n.userId&&e.path.isEqual(c))return __PRIVATE_mutationsStore(t).get(_).next((function(t){if(!t)throw fail("Dangling document-mutation reference found: "+r+" which points to "+_);assert(t.userId===n.userId,"Unexpected user '"+t.userId+"' for mutation batch "+_),s.push(n.serializer.Md(t))}));o.done()})).next((function(){return s}))},t.prototype.Po=function(t,e){var n=this,r=new __PRIVATE_SortedSet(__PRIVATE_primitiveComparator),i=[];return e.forEach((function(e){var s=DbDocumentMutation.prefixForPath(n.userId,e.path),o=IDBKeyRange.lowerBound(s),u=__PRIVATE_documentMutationsStore(t).wd({range:o},(function(t,i,s){var o=t[0],u=t[1],a=t[2],_=decode(u);o===n.userId&&e.path.isEqual(_)?r=r.add(a):s.done()}));i.push(u)})),PersistencePromise.$s(i).next((function(){return n.Ld(t,r)}))},t.prototype.vo=function(t,e){var n=this;assert(!e.Ze(),"Document queries shouldn't go down this path"),assert(!e.yn(),"CollectionGroup queries should be handled in LocalDocumentsView");var r=e.path,i=r.length+1,s=DbDocumentMutation.prefixForPath(this.userId,r),o=IDBKeyRange.lowerBound(s),u=new __PRIVATE_SortedSet(__PRIVATE_primitiveComparator);return __PRIVATE_documentMutationsStore(t).wd({range:o},(function(t,e,s){var o=t[0],a=t[1],_=t[2],c=decode(a);o===n.userId&&r.it(c)?c.length===i&&(u=u.add(_)):s.done()})).next((function(){return n.Ld(t,u)}))},t.prototype.Ld=function(t,e){var n=this,r=[],i=[];return e.forEach((function(e){i.push(__PRIVATE_mutationsStore(t).get(e).next((function(t){if(null===t)throw fail("Dangling document-mutation reference found, which points to "+e);assert(t.userId===n.userId,"Unexpected user '"+t.userId+"' for mutation batch "+e),r.push(n.serializer.Md(t))})))})),PersistencePromise.$s(i).next((function(){return r}))},t.prototype.Oa=function(t,e){var n=this;return __PRIVATE_removeMutationBatch(t.Gd,this.userId,e).next((function(r){return t.oo((function(){n.u_(e.batchId)})),PersistencePromise.forEach(r,(function(e){return n.oa.Bd(t,e)}))}))},t.prototype.u_=function(t){delete this.Sd[t]},t.prototype.Sa=function(t){var e=this;return this.Cd(t).next((function(n){if(!n)return PersistencePromise.resolve();var r=IDBKeyRange.lowerBound(DbDocumentMutation.prefixForUser(e.userId)),i=[];return __PRIVATE_documentMutationsStore(t).wd({range:r},(function(t,n,r){if(t[0]===e.userId){var s=decode(t[1]);i.push(s)}else r.done()})).next((function(){assert(0===i.length,"Document leak -- detected dangling mutation references when queue is empty. Dangling keys: "+i.map((function(t){return t.ut()})))}))}))},t.prototype.Gs=function(t,e){return __PRIVATE_mutationQueueContainsKey(t,this.userId,e)},t.prototype.Od=function(t){var e=this;return __PRIVATE_mutationQueuesStore(t).get(this.userId).next((function(t){return t||new DbMutationQueue(e.userId,__PRIVATE_BATCHID_UNKNOWN,"")}))},t}();function __PRIVATE_mutationQueueContainsKey(t,e,n){var r=DbDocumentMutation.prefixForPath(e,n.path),i=r[1],s=IDBKeyRange.lowerBound(r),o=!1;return __PRIVATE_documentMutationsStore(t).wd({range:s,gd:!0},(function(t,n,r){var s=t[0],u=t[1];t[2];s===e&&u===i&&(o=!0),r.done()})).next((function(){return o}))}function __PRIVATE_mutationQueuesContainKey(t,e){var n=!1;return __PRIVATE_mutationQueuesStore(t).yd((function(r){return __PRIVATE_mutationQueueContainsKey(t,r,e).next((function(t){return t&&(n=!0),PersistencePromise.resolve(!t)}))})).next((function(){return n}))}function __PRIVATE_removeMutationBatch(t,e,n){var r=t.store(DbMutationBatch.store),i=t.store(DbDocumentMutation.store),s=[],o=IDBKeyRange.only(n.batchId),u=0,a=r.wd({range:o},(function(t,e,n){return u++,n.delete()}));s.push(a.next((function(){assert(1===u,"Dangling document-mutation reference found: Missing batch "+n.batchId)})));for(var _=[],c=0,h=n.mutations;c<h.length;c++){var f=h[c],l=DbDocumentMutation.key(e,f.key.path,n.batchId);s.push(i.delete(l)),_.push(f.key)}return PersistencePromise.$s(s).next((function(){return _}))}function __PRIVATE_convertStreamToken(t){return t instanceof Uint8Array?(assert(__PRIVATE_SimpleDb.hd(),"Persisting non-string stream tokens is only supported with mock persistence."),t.toString()):t}function __PRIVATE_mutationsStore(t){return __PRIVATE_IndexedDbPersistence.dd(t,DbMutationBatch.store)}function __PRIVATE_documentMutationsStore(t){return __PRIVATE_IndexedDbPersistence.dd(t,DbDocumentMutation.store)}function __PRIVATE_mutationQueuesStore(t){return __PRIVATE_IndexedDbPersistence.dd(t,DbMutationQueue.store)}var __PRIVATE_IndexedDbTargetCache=function(){function t(t,e){this.oa=t,this.serializer=e,this.Ud=__PRIVATE_TargetIdGenerator.qf()}return t.prototype.Ja=function(t){var e=this;return this.kd(t).next((function(n){return n.highestTargetId=e.Ud.after(n.highestTargetId),e.xd(t,n).next((function(){return n.highestTargetId}))}))},t.prototype.La=function(t){return this.kd(t).next((function(t){return __PRIVATE_SnapshotVersion.q(new Timestamp(t.lastRemoteSnapshotVersion.seconds,t.lastRemoteSnapshotVersion.nanoseconds))}))},t.prototype.Kd=function(t){return __PRIVATE_getHighestListenSequenceNumber(t.Gd)},t.prototype.qa=function(t,e,n){var r=this;return this.kd(t).next((function(i){return i.highestListenSequenceNumber=e,n&&(i.lastRemoteSnapshotVersion=n.Y()),e>i.highestListenSequenceNumber&&(i.highestListenSequenceNumber=e),r.xd(t,i)}))},t.prototype.Za=function(t,e){var n=this;return this.jd(t,e).next((function(){return n.kd(t).next((function(r){return r.targetCount+=1,n.qd(e,r),n.xd(t,r)}))}))},t.prototype.Ka=function(t,e){return this.jd(t,e)},t.prototype.Qd=function(t,e){var n=this;return this.Wd(t,e.targetId).next((function(){return __PRIVATE_targetsStore(t).delete(e.targetId)})).next((function(){return n.kd(t)})).next((function(e){return assert(e.targetCount>0,"Removing from an empty target cache"),e.targetCount-=1,n.xd(t,e)}))},t.prototype.Hu=function(t,e,n){var r=this,i=0,s=[];return __PRIVATE_targetsStore(t).wd((function(o,u){var a=r.serializer.$d(u);a.sequenceNumber<=e&&null===n.get(a.targetId)&&(i++,s.push(r.Qd(t,a)))})).next((function(){return PersistencePromise.$s(s)})).next((function(){return i}))},t.prototype.jr=function(t,e){var n=this;return __PRIVATE_targetsStore(t).wd((function(t,r){var i=n.serializer.$d(r);e(i)}))},t.prototype.kd=function(t){return __PRIVATE_retrieveMetadata(t.Gd)},t.prototype.xd=function(t,e){return __PRIVATE_globalTargetStore(t).put(DbTargetGlobal.key,e)},t.prototype.jd=function(t,e){return __PRIVATE_targetsStore(t).put(this.serializer.Yd(e))},t.prototype.qd=function(t,e){var n=!1;return t.targetId>e.highestTargetId&&(e.highestTargetId=t.targetId,n=!0),t.sequenceNumber>e.highestListenSequenceNumber&&(e.highestListenSequenceNumber=t.sequenceNumber,n=!0),n},t.prototype.Hd=function(t){return this.kd(t).next((function(t){return t.targetCount}))},t.prototype.za=function(t,e){var n=this,r=e.canonicalId(),i=IDBKeyRange.bound([r,Number.NEGATIVE_INFINITY],[r,Number.POSITIVE_INFINITY]),s=null;return __PRIVATE_targetsStore(t).wd({range:i,index:DbTarget.queryTargetsIndexName},(function(t,r,i){var o=n.serializer.$d(r);e.isEqual(o.target)&&(s=o,i.done())})).next((function(){return s}))},t.prototype.Ua=function(t,e,n){var r=this,i=[],s=__PRIVATE_documentTargetStore(t);return e.forEach((function(e){var o=encode(e.path);i.push(s.put(new DbTargetDocument(n,o))),i.push(r.oa.Ss(t,e))})),PersistencePromise.$s(i)},t.prototype.Ba=function(t,e,n){var r=this,i=__PRIVATE_documentTargetStore(t);return PersistencePromise.forEach(e,(function(e){var s=encode(e.path);return PersistencePromise.$s([i.delete([n,s]),r.oa.Cs(t,e)])}))},t.prototype.Wd=function(t,e){var n=__PRIVATE_documentTargetStore(t),r=IDBKeyRange.bound([e],[e+1],!1,!0);return n.delete(r)},t.prototype.n_=function(t,e){var n=IDBKeyRange.bound([e],[e+1],!1,!0),r=__PRIVATE_documentTargetStore(t),i=__PRIVATE_documentKeySet();return r.wd({range:n,gd:!0},(function(t,e,n){var r=decode(t[1]),s=new __PRIVATE_DocumentKey(r);i=i.add(s)})).next((function(){return i}))},t.prototype.Gs=function(t,e){var n=encode(e.path),r=IDBKeyRange.bound([n],[__PRIVATE_immediateSuccessor(n)],!1,!0),i=0;return __PRIVATE_documentTargetStore(t).wd({index:DbTargetDocument.documentTargetsIndex,gd:!0,range:r},(function(t,e,n){var r=t[0];t[1];0!==r&&(i++,n.done())})).next((function(){return i>0}))},t.prototype.ti=function(t,e){var n=this;return __PRIVATE_targetsStore(t).get(e).next((function(t){return t?n.serializer.$d(t):null}))},t}();function __PRIVATE_targetsStore(t){return __PRIVATE_IndexedDbPersistence.dd(t,DbTarget.store)}function __PRIVATE_globalTargetStore(t){return __PRIVATE_IndexedDbPersistence.dd(t,DbTargetGlobal.store)}function __PRIVATE_retrieveMetadata(t){return __PRIVATE_SimpleDb.dd(t,DbTargetGlobal.store).get(DbTargetGlobal.key).next((function(t){return assert(null!==t,"Missing metadata row."),t}))}function __PRIVATE_getHighestListenSequenceNumber(t){return __PRIVATE_retrieveMetadata(t).next((function(t){return t.highestListenSequenceNumber}))}function __PRIVATE_documentTargetStore(t){return __PRIVATE_IndexedDbPersistence.dd(t,DbTargetDocument.store)}var __PRIVATE_IndexedDbRemoteDocumentCache=function(){function t(t,e){this.serializer=t,this.co=e}return t.prototype.Js=function(t,e,n){return __PRIVATE_remoteDocumentsStore(t).put(__PRIVATE_dbKey(e),n)},t.prototype.to=function(t,e){var n=__PRIVATE_remoteDocumentsStore(t),r=__PRIVATE_dbKey(e);return n.delete(r)},t.prototype.updateMetadata=function(t,e){var n=this;return this.getMetadata(t).next((function(r){return r.byteSize+=e,n.Xd(t,r)}))},t.prototype.eo=function(t,e){var n=this;return __PRIVATE_remoteDocumentsStore(t).get(__PRIVATE_dbKey(e)).next((function(t){return n.zd(t)}))},t.prototype.Jd=function(t,e){var n=this;return __PRIVATE_remoteDocumentsStore(t).get(__PRIVATE_dbKey(e)).next((function(t){var e=n.zd(t);return e?{Zd:e,size:__PRIVATE_dbDocumentSize(t)}:null}))},t.prototype.getEntries=function(t,e){var n=this,r=__PRIVATE_nullableMaybeDocumentMap();return this.tT(t,e,(function(t,e){var i=n.zd(e);r=r.At(t,i)})).next((function(){return r}))},t.prototype.eT=function(t,e){var n=this,r=__PRIVATE_nullableMaybeDocumentMap(),i=new __PRIVATE_SortedMap(__PRIVATE_DocumentKey.X);return this.tT(t,e,(function(t,e){var s=n.zd(e);s?(r=r.At(t,s),i=i.At(t,__PRIVATE_dbDocumentSize(e))):(r=r.At(t,null),i=i.At(t,0))})).next((function(){return{nT:r,rT:i}}))},t.prototype.tT=function(t,e,n){if(e.et())return PersistencePromise.resolve();var r=IDBKeyRange.bound(e.first().path.ot(),e.last().path.ot()),i=e.gt(),s=i.Ot();return __PRIVATE_remoteDocumentsStore(t).wd({range:r},(function(t,e,r){for(var o=__PRIVATE_DocumentKey.Et(t);s&&__PRIVATE_DocumentKey.X(s,o)<0;)n(s,null),s=i.Ot();s&&s.isEqual(o)&&(n(s,e),s=i.Ft()?i.Ot():null),s?r.Vd(s.path.ot()):r.done()})).next((function(){for(;s;)n(s,null),s=i.Ft()?i.Ot():null}))},t.prototype.Ao=function(t,e,n){var r=this;assert(!e.yn(),"CollectionGroup queries should be handled in LocalDocumentsView");var i=__PRIVATE_documentMap(),s=e.path.length+1,o={};if(n.isEqual(__PRIVATE_SnapshotVersion.MIN)){var u=e.path.ot();o.range=IDBKeyRange.lowerBound(u)}else{var a=e.path.ot(),_=this.serializer.iT(n);o.range=IDBKeyRange.lowerBound([a,_],!0),o.index=DbRemoteDocument.collectionReadTimeIndex}return __PRIVATE_remoteDocumentsStore(t).wd(o,(function(t,n,o){if(t.length===s){var u=r.serializer.sT(n);e.path.it(u.key.path)?u instanceof Document&&e.matches(u)&&(i=i.At(u.key,u)):o.done()}})).next((function(){return i}))},t.prototype.c_=function(t,e){var n=this,r=__PRIVATE_maybeDocumentMap(),i=this.serializer.iT(e),s=__PRIVATE_remoteDocumentsStore(t),o=IDBKeyRange.lowerBound(i,!0);return s.wd({index:DbRemoteDocument.readTimeIndex,range:o},(function(t,e){var s=n.serializer.sT(e);r=r.At(s.key,s),i=e.readTime})).next((function(){return{h_:r,readTime:n.serializer.oT(i)}}))},t.prototype.f_=function(t){var e=this,n=__PRIVATE_remoteDocumentsStore(t),r=__PRIVATE_SnapshotVersion.MIN;return n.wd({index:DbRemoteDocument.readTimeIndex,reverse:!0},(function(t,n,i){n.readTime&&(r=e.serializer.oT(n.readTime)),i.done()})).next((function(){return r}))},t.prototype.ga=function(e){return new t.uT(this,!!e&&e.wa)},t.prototype.aT=function(t){return this.getMetadata(t).next((function(t){return t.byteSize}))},t.prototype.getMetadata=function(t){return __PRIVATE_documentGlobalStore(t).get(DbRemoteDocumentGlobal.key).next((function(t){return assert(!!t,"Missing document cache metadata"),t}))},t.prototype.Xd=function(t,e){return __PRIVATE_documentGlobalStore(t).put(DbRemoteDocumentGlobal.key,e)},t.prototype.zd=function(t){if(t){var e=this.serializer.sT(t);return e instanceof __PRIVATE_NoDocument&&e.version.isEqual(__PRIVATE_SnapshotVersion.W())?null:e}return null},t.uT=function(t){function e(e,n){var r=t.call(this)||this;return r._T=e,r.wa=n,r.cT=new __PRIVATE_ObjectMap((function(t){return t.toString()})),r}return tslib.__extends(e,t),e.prototype.io=function(t){var e=this,n=[],r=0,i=new __PRIVATE_SortedSet((function(t,e){return __PRIVATE_primitiveComparator(t.ut(),e.ut())}));return this.Hs.forEach((function(s,o){var u=e.cT.get(s);if(assert(void 0!==u,"Cannot modify a document that wasn't read (for "+s+")"),o){assert(!e.readTime.isEqual(__PRIVATE_SnapshotVersion.MIN),"Cannot add a document with a read time of zero");var a=e._T.serializer.hT(o,e.readTime);i=i.add(s.path.tt());var _=__PRIVATE_dbDocumentSize(a);r+=_-u,n.push(e._T.Js(t,s,a))}else if(r-=u,e.wa){var c=e._T.serializer.hT(new __PRIVATE_NoDocument(s,__PRIVATE_SnapshotVersion.W()),e.readTime);n.push(e._T.Js(t,s,c))}else n.push(e._T.to(t,s))})),i.forEach((function(r){n.push(e._T.co.Nd(t,r))})),n.push(this._T.updateMetadata(t,r)),PersistencePromise.$s(n)},e.prototype.no=function(t,e){var n=this;return this._T.Jd(t,e).next((function(t){return null===t?(n.cT.set(e,0),null):(n.cT.set(e,t.size),t.Zd)}))},e.prototype.ro=function(t,e){var n=this;return this._T.eT(t,e).next((function(t){var e=t.nT;return t.rT.forEach((function(t,e){n.cT.set(t,e)})),e}))},e}(__PRIVATE_RemoteDocumentChangeBuffer),t}();function __PRIVATE_documentGlobalStore(t){return __PRIVATE_IndexedDbPersistence.dd(t,DbRemoteDocumentGlobal.store)}function __PRIVATE_remoteDocumentsStore(t){return __PRIVATE_IndexedDbPersistence.dd(t,DbRemoteDocument.store)}function __PRIVATE_dbKey(t){return t.path.ot()}function __PRIVATE_dbDocumentSize(t){var e;if(t.document)e=t.document;else if(t.unknownDocument)e=t.unknownDocument;else{if(!t.noDocument)throw fail("Unknown remote document type");e=t.noDocument}return JSON.stringify(e).length}var __PRIVATE_MemoryIndexManager=function(){function t(){this.fT=new __PRIVATE_MemoryCollectionParentIndex}return t.prototype.Nd=function(t,e){return this.fT.add(e),PersistencePromise.resolve()},t.prototype.mo=function(t,e){return PersistencePromise.resolve(this.fT.getEntries(e))},t}(),__PRIVATE_MemoryCollectionParentIndex=function(){function t(){this.index={}}return t.prototype.add=function(t){assert(t.length%2==1,"Expected a collection path.");var e=t.rt(),n=t.tt(),r=this.index[e]||new __PRIVATE_SortedSet(ResourcePath.X),i=!r.has(n);return this.index[e]=r.add(n),i},t.prototype.has=function(t){var e=t.rt(),n=t.tt(),r=this.index[e];return r&&r.has(n)},t.prototype.getEntries=function(t){return(this.index[t]||new __PRIVATE_SortedSet(ResourcePath.X)).ot()},t}(),SCHEMA_VERSION=9,SchemaConverter=function(){function t(t){this.serializer=t}return t.prototype.createOrUpgrade=function(t,e,n,r){var i=this;assert(n<r&&n>=0&&r<=SCHEMA_VERSION,"Unexpected schema upgrade from v"+n+" to v{toVersion}.");var s=new __PRIVATE_SimpleDbTransaction(e);n<1&&r>=1&&(__PRIVATE_createPrimaryClientStore(t),__PRIVATE_createMutationQueue(t),__PRIVATE_createQueryCache(t),__PRIVATE_createRemoteDocumentCache(t));var o=PersistencePromise.resolve();return n<3&&r>=3&&(0!==n&&(__PRIVATE_dropQueryCache(t),__PRIVATE_createQueryCache(t)),o=o.next((function(){return __PRIVATE_writeEmptyTargetGlobalEntry(s)}))),n<4&&r>=4&&(0!==n&&(o=o.next((function(){return __PRIVATE_upgradeMutationBatchSchemaAndMigrateData(t,s)}))),o=o.next((function(){__PRIVATE_createClientMetadataStore(t)}))),n<5&&r>=5&&(o=o.next((function(){return i.removeAcknowledgedMutations(s)}))),n<6&&r>=6&&(o=o.next((function(){return __PRIVATE_createDocumentGlobalStore(t),i.addDocumentGlobal(s)}))),n<7&&r>=7&&(o=o.next((function(){return i.ensureSequenceNumbers(s)}))),n<8&&r>=8&&(o=o.next((function(){return i.createCollectionParentIndex(t,s)}))),n<9&&r>=9&&(o=o.next((function(){__PRIVATE_dropRemoteDocumentChangesStore(t),__PRIVATE_createRemoteDocumentReadTimeIndex(e)}))),o},t.prototype.addDocumentGlobal=function(t){var e=0;return t.store(DbRemoteDocument.store).wd((function(t,n){e+=__PRIVATE_dbDocumentSize(n)})).next((function(){var n=new DbRemoteDocumentGlobal(e);return t.store(DbRemoteDocumentGlobal.store).put(DbRemoteDocumentGlobal.key,n)}))},t.prototype.removeAcknowledgedMutations=function(t){var e=this,n=t.store(DbMutationQueue.store),r=t.store(DbMutationBatch.store);return n.vd().next((function(n){return PersistencePromise.forEach(n,(function(n){var i=IDBKeyRange.bound([n.userId,__PRIVATE_BATCHID_UNKNOWN],[n.userId,n.lastAcknowledgedBatchId]);return r.vd(DbMutationBatch.userMutationsIndex,i).next((function(r){return PersistencePromise.forEach(r,(function(r){assert(r.userId===n.userId,"Cannot process batch "+r.batchId+" from unexpected user");var i=e.serializer.Md(r);return __PRIVATE_removeMutationBatch(t,n.userId,i).next((function(){}))}))}))}))}))},t.prototype.ensureSequenceNumbers=function(t){var e=t.store(DbTargetDocument.store),n=t.store(DbRemoteDocument.store);return __PRIVATE_getHighestListenSequenceNumber(t).next((function(t){var r=[];return n.wd((function(n,i){var s=new ResourcePath(n),o=__PRIVATE_sentinelKey(s);r.push(e.get(o).next((function(n){return n?PersistencePromise.resolve():function(n){return e.put(new DbTargetDocument(0,encode(n),t))}(s)})))})).next((function(){return PersistencePromise.$s(r)}))}))},t.prototype.createCollectionParentIndex=function(t,e){t.createObjectStore(DbCollectionParent.store,{keyPath:DbCollectionParent.keyPath});var n=e.store(DbCollectionParent.store),r=new __PRIVATE_MemoryCollectionParentIndex,i=function(t){if(r.add(t)){var e=t.rt(),i=t.tt();return n.put({collectionId:e,parent:encode(i)})}};return e.store(DbRemoteDocument.store).wd({gd:!0},(function(t,e){var n=new ResourcePath(t);return i(n.tt())})).next((function(){return e.store(DbDocumentMutation.store).wd({gd:!0},(function(t,e){t[0];var n=t[1],r=(t[2],decode(n));return i(r.tt())}))}))},t}();function __PRIVATE_sentinelKey(t){return[0,encode(t)]}var DbTimestamp=function(t,e){this.seconds=t,this.nanoseconds=e},DbPrimaryClient=function(){function t(t,e,n){this.ownerId=t,this.allowTabSynchronization=e,this.leaseTimestampMs=n}return t.store="owner",t.key="owner",t}();function __PRIVATE_createPrimaryClientStore(t){t.createObjectStore(DbPrimaryClient.store)}var DbMutationQueue=function(){function t(t,e,n){this.userId=t,this.lastAcknowledgedBatchId=e,this.lastStreamToken=n}return t.store="mutationQueues",t.keyPath="userId",t}(),DbMutationBatch=function(){function t(t,e,n,r,i){this.userId=t,this.batchId=e,this.localWriteTimeMs=n,this.baseMutations=r,this.mutations=i}return t.store="mutations",t.keyPath="batchId",t.userMutationsIndex="userMutationsIndex",t.userMutationsKeyPath=["userId","batchId"],t}();function __PRIVATE_createMutationQueue(t){t.createObjectStore(DbMutationQueue.store,{keyPath:DbMutationQueue.keyPath}),t.createObjectStore(DbMutationBatch.store,{keyPath:DbMutationBatch.keyPath,autoIncrement:!0}).createIndex(DbMutationBatch.userMutationsIndex,DbMutationBatch.userMutationsKeyPath,{unique:!0}),t.createObjectStore(DbDocumentMutation.store)}function __PRIVATE_upgradeMutationBatchSchemaAndMigrateData(t,e){return e.store(DbMutationBatch.store).vd().next((function(n){t.deleteObjectStore(DbMutationBatch.store),t.createObjectStore(DbMutationBatch.store,{keyPath:DbMutationBatch.keyPath,autoIncrement:!0}).createIndex(DbMutationBatch.userMutationsIndex,DbMutationBatch.userMutationsKeyPath,{unique:!0});var r=e.store(DbMutationBatch.store),i=n.map((function(t){return r.put(t)}));return PersistencePromise.$s(i)}))}var DbDocumentMutation=function(){function t(){}return t.prefixForUser=function(t){return[t]},t.prefixForPath=function(t,e){return[t,encode(e)]},t.key=function(t,e,n){return[t,encode(e),n]},t.store="documentMutations",t.PLACEHOLDER=new t,t}();function __PRIVATE_createRemoteDocumentCache(t){t.createObjectStore(DbRemoteDocument.store)}var DbNoDocument=function(t,e){this.path=t,this.readTime=e},DbUnknownDocument=function(t,e){this.path=t,this.version=e},DbRemoteDocument=function(){function t(t,e,n,r,i,s){this.unknownDocument=t,this.noDocument=e,this.document=n,this.hasCommittedMutations=r,this.readTime=i,this.parentPath=s}return t.store="remoteDocuments",t.readTimeIndex="readTimeIndex",t.readTimeIndexPath="readTime",t.collectionReadTimeIndex="collectionReadTimeIndex",t.collectionReadTimeIndexPath=["parentPath","readTime"],t}(),DbRemoteDocumentGlobal=function(){function t(t){this.byteSize=t}return t.store="remoteDocumentGlobal",t.key="remoteDocumentGlobalKey",t}();function __PRIVATE_createDocumentGlobalStore(t){t.createObjectStore(DbRemoteDocumentGlobal.store)}var DbTarget=function(){function t(t,e,n,r,i,s,o){this.targetId=t,this.canonicalId=e,this.readTime=n,this.resumeToken=r,this.lastListenSequenceNumber=i,this.lastLimboFreeSnapshotVersion=s,this.query=o}return t.store="targets",t.keyPath="targetId",t.queryTargetsIndexName="queryTargetsIndex",t.queryTargetsKeyPath=["canonicalId","targetId"],t}(),DbTargetDocument=function(){function t(t,e,n){this.targetId=t,this.path=e,this.sequenceNumber=n,assert(0===t==(void 0!==n),"A target-document row must either have targetId == 0 and a defined sequence number, or a non-zero targetId and no sequence number")}return t.store="targetDocuments",t.keyPath=["targetId","path"],t.documentTargetsIndex="documentTargetsIndex",t.documentTargetsKeyPath=["path","targetId"],t}(),DbTargetGlobal=function(){function t(t,e,n,r){this.highestTargetId=t,this.highestListenSequenceNumber=e,this.lastRemoteSnapshotVersion=n,this.targetCount=r}return t.key="targetGlobalKey",t.store="targetGlobal",t}(),DbCollectionParent=function(){function t(t,e){this.collectionId=t,this.parent=e}return t.store="collectionParents",t.keyPath=["collectionId","parent"],t}();function __PRIVATE_createQueryCache(t){t.createObjectStore(DbTargetDocument.store,{keyPath:DbTargetDocument.keyPath}).createIndex(DbTargetDocument.documentTargetsIndex,DbTargetDocument.documentTargetsKeyPath,{unique:!0}),t.createObjectStore(DbTarget.store,{keyPath:DbTarget.keyPath}).createIndex(DbTarget.queryTargetsIndexName,DbTarget.queryTargetsKeyPath,{unique:!0}),t.createObjectStore(DbTargetGlobal.store)}function __PRIVATE_dropQueryCache(t){t.deleteObjectStore(DbTargetDocument.store),t.deleteObjectStore(DbTarget.store),t.deleteObjectStore(DbTargetGlobal.store)}function __PRIVATE_dropRemoteDocumentChangesStore(t){t.objectStoreNames.contains("remoteDocumentChanges")&&t.deleteObjectStore("remoteDocumentChanges")}function __PRIVATE_writeEmptyTargetGlobalEntry(t){var e=t.store(DbTargetGlobal.store),n=new DbTargetGlobal(0,0,__PRIVATE_SnapshotVersion.MIN.Y(),0);return e.put(DbTargetGlobal.key,n)}function __PRIVATE_createRemoteDocumentReadTimeIndex(t){var e=t.objectStore(DbRemoteDocument.store);e.createIndex(DbRemoteDocument.readTimeIndex,DbRemoteDocument.readTimeIndexPath,{unique:!1}),e.createIndex(DbRemoteDocument.collectionReadTimeIndex,DbRemoteDocument.collectionReadTimeIndexPath,{unique:!1})}var DbClientMetadata=function(){function t(t,e,n,r){this.clientId=t,this.updateTimeMs=e,this.networkEnabled=n,this.inForeground=r}return t.store="clientMetadata",t.keyPath="clientId",t}();function __PRIVATE_createClientMetadataStore(t){t.createObjectStore(DbClientMetadata.store,{keyPath:DbClientMetadata.keyPath})}var V1_STORES=[DbMutationQueue.store,DbMutationBatch.store,DbDocumentMutation.store,DbRemoteDocument.store,DbTarget.store,DbPrimaryClient.store,DbTargetGlobal.store,DbTargetDocument.store],V3_STORES=V1_STORES,V4_STORES=tslib.__spreadArrays(V3_STORES,[DbClientMetadata.store]),V6_STORES=tslib.__spreadArrays(V4_STORES,[DbRemoteDocumentGlobal.store]),V8_STORES=tslib.__spreadArrays(V6_STORES,[DbCollectionParent.store]),ALL_STORES=V8_STORES,__PRIVATE_IndexedDbIndexManager=function(){function t(){this.lT=new __PRIVATE_MemoryCollectionParentIndex}return t.prototype.Nd=function(t,e){var n=this;if(assert(e.length%2==1,"Expected a collection path."),!this.lT.has(e)){var r=e.rt(),i=e.tt();t.oo((function(){n.lT.add(e)}));var s={collectionId:r,parent:encode(i)};return __PRIVATE_collectionParentsStore(t).put(s)}return PersistencePromise.resolve()},t.prototype.mo=function(t,e){var n=[],r=IDBKeyRange.bound([e,""],[__PRIVATE_immediateSuccessor(e),""],!1,!0);return __PRIVATE_collectionParentsStore(t).vd(r).next((function(t){for(var r=0,i=t;r<i.length;r++){var s=i[r];if(s.collectionId!==e)break;n.push(decode(s.parent))}return n}))},t}();function __PRIVATE_collectionParentsStore(t){return __PRIVATE_IndexedDbPersistence.dd(t,DbCollectionParent.store)}var LocalSerializer=function(){function t(t){this.dT=t}return t.prototype.sT=function(t){if(t.document)return this.dT.yi(t.document,!!t.hasCommittedMutations);if(t.noDocument){var e=__PRIVATE_DocumentKey.Et(t.noDocument.path),n=this.TT(t.noDocument.readTime);return new __PRIVATE_NoDocument(e,n,{hasCommittedMutations:!!t.hasCommittedMutations})}if(t.unknownDocument){e=__PRIVATE_DocumentKey.Et(t.unknownDocument.path),n=this.TT(t.unknownDocument.version);return new __PRIVATE_UnknownDocument(e,n)}return fail("Unexpected DbRemoteDocument")},t.prototype.hT=function(t,e){var n=this.iT(e),r=t.key.path.tt().ot();if(t instanceof Document){var i=t.proto?t.proto:this.dT.wi(t),s=t.hasCommittedMutations;return new DbRemoteDocument(null,null,i,s,n,r)}if(t instanceof __PRIVATE_NoDocument){var o=t.key.path.ot(),u=this.ET(t.version);s=t.hasCommittedMutations;return new DbRemoteDocument(null,new DbNoDocument(o,u),null,s,n,r)}if(t instanceof __PRIVATE_UnknownDocument){o=t.key.path.ot();var a=this.ET(t.version);return new DbRemoteDocument(new DbUnknownDocument(o,a),null,null,!0,n,r)}return fail("Unexpected MaybeDocument")},t.prototype.iT=function(t){var e=t.Y();return[e.seconds,e.nanoseconds]},t.prototype.oT=function(t){var e=new Timestamp(t[0],t[1]);return __PRIVATE_SnapshotVersion.q(e)},t.prototype.ET=function(t){var e=t.Y();return new DbTimestamp(e.seconds,e.nanoseconds)},t.prototype.TT=function(t){var e=new Timestamp(t.seconds,t.nanoseconds);return __PRIVATE_SnapshotVersion.q(e)},t.prototype.Fd=function(t,e){var n=this,r=e.baseMutations.map((function(t){return n.dT.Gi(t)})),i=e.mutations.map((function(t){return n.dT.Gi(t)}));return new DbMutationBatch(t,e.batchId,e.qe.toMillis(),r,i)},t.prototype.Md=function(t){var e=this,n=(t.baseMutations||[]).map((function(t){return e.dT.xi(t)})),r=t.mutations.map((function(t){return e.dT.xi(t)})),i=Timestamp.fromMillis(t.localWriteTimeMs);return new __PRIVATE_MutationBatch(t.batchId,i,n,r)},t.prototype.PT=function(t){var e=[];return t.forEach((function(t){e.push(encode(t.path))})),e},t.prototype.AT=function(t){for(var e=__PRIVATE_documentKeySet(),n=0,r=t;n<r.length;n++){var i=r[n];e=e.add(new __PRIVATE_DocumentKey(decode(i)))}return e},t.prototype.$d=function(t){var e,n=this.TT(t.readTime),r=void 0!==t.lastLimboFreeSnapshotVersion?this.TT(t.lastLimboFreeSnapshotVersion):__PRIVATE_SnapshotVersion.MIN,i=t.resumeToken;return e=__PRIVATE_isDocumentQuery(t.query)?this.dT.Yi(t.query):this.dT.Zi(t.query),new __PRIVATE_TargetData(e,t.targetId,__PRIVATE_TargetPurpose.On,t.lastListenSequenceNumber,n,r,i)},t.prototype.Yd=function(t){assert(__PRIVATE_TargetPurpose.On===t.Mn,"Only queries with purpose "+__PRIVATE_TargetPurpose.On+" may be stored, got "+t.Mn);var e,n,r=this.ET(t.Ln),i=this.ET(t.lastLimboFreeSnapshotVersion);return e=t.target.Ze()?this.dT.$i(t.target):this.dT.Hi(t.target),t.resumeToken instanceof Uint8Array?(assert(__PRIVATE_SimpleDb.hd(),"Persisting non-string stream tokens is only supported with mock persistence ."),n=t.resumeToken.toString()):n=t.resumeToken,new DbTarget(t.targetId,t.target.canonicalId(),r,n,t.sequenceNumber,i,e)},t}();function __PRIVATE_isDocumentQuery(t){return void 0!==t.documents}var __PRIVATE_LOG_TAG$9="IndexedDbPersistence",__PRIVATE_MAX_CLIENT_AGE_MS=18e5,__PRIVATE_MAX_PRIMARY_ELIGIBLE_AGE_MS=5e3,__PRIVATE_CLIENT_METADATA_REFRESH_INTERVAL_MS=4e3,__PRIVATE_PRIMARY_LEASE_EXCLUSIVE_ERROR_MSG="Another tab has exclusive access to the persistence layer. To allow shared access, make sure to invoke `enablePersistence()` with `synchronizeTabs:true` in all tabs.",__PRIVATE_UNSUPPORTED_PLATFORM_ERROR_MSG="This platform is either missing IndexedDB or is known to have an incomplete implementation. Offline persistence has been disabled.",__PRIVATE_ZOMBIED_CLIENTS_KEY_PREFIX="firestore_zombie",__PRIVATE_IndexedDbTransaction=function(t){function e(e,n){var r=t.call(this)||this;return r.Gd=e,r.ka=n,r}return tslib.__extends(e,t),e}(__PRIVATE_PersistenceTransaction),__PRIVATE_IndexedDbPersistence=function(){function t(e,n,r,i,s,o,u,a){if(this.allowTabSynchronization=e,this.persistenceKey=n,this.clientId=r,this.q_=o,this.RT=a,this.IT=!1,this.isPrimary=!1,this.networkEnabled=!0,this.VT=null,this.inForeground=!1,this.mT=null,this.vT=null,this.pT=Number.NEGATIVE_INFINITY,this.bT=function(t){return Promise.resolve()},this.oa=new __PRIVATE_IndexedDbLruDelegate(this,s),this.gT=n+t.wT,this.serializer=new LocalSerializer(u),this.document=i.document,this.ca=new __PRIVATE_IndexedDbTargetCache(this.oa,this.serializer),this.co=new __PRIVATE_IndexedDbIndexManager,this.ao=new __PRIVATE_IndexedDbRemoteDocumentCache(this.serializer,this.co),!i.window||!i.window.localStorage)throw new FirestoreError(Code.UNIMPLEMENTED,"IndexedDB persistence is only available on platforms that support LocalStorage.");this.window=i.window,this.yT=this.window.localStorage}return t.dd=function(t,e){if(t instanceof __PRIVATE_IndexedDbTransaction)return __PRIVATE_SimpleDb.dd(t.Gd,e);throw fail("IndexedDbPersistence must use instances of IndexedDbTransaction")},t.ST=function(e){return tslib.__awaiter(this,void 0,void 0,(function(){var n;return tslib.__generator(this,(function(r){switch(r.label){case 0:if(!t.ef())throw new FirestoreError(Code.UNIMPLEMENTED,__PRIVATE_UNSUPPORTED_PLATFORM_ERROR_MSG);return[4,(n=new t(e.allowTabSynchronization,e.persistenceKey,e.clientId,e.platform,e.DT,e.q_,e.serializer,e.RT)).start()];case 1:return r.sent(),[2,n]}}))}))},t.prototype.start=function(){var t=this;return assert(!this.Ku,"IndexedDbPersistence double-started!"),assert(null!==this.window,"Expected 'window' to be defined"),__PRIVATE_SimpleDb._d(this.gT,SCHEMA_VERSION,new SchemaConverter(this.serializer)).then((function(e){return t.CT=e,t.OT()})).then((function(){return t.FT(),t.NT(),t.MT(),t.CT.runTransaction("readonly-idempotent",[DbTargetGlobal.store],(function(t){return __PRIVATE_getHighestListenSequenceNumber(t)}))})).then((function(e){t.LT=new __PRIVATE_ListenSequence(e,t.RT)})).then((function(){t.IT=!0})).catch((function(e){return t.CT&&t.CT.close(),Promise.reject(e)}))},t.prototype.GT=function(t){var e=this;return this.bT=function(n){return tslib.__awaiter(e,void 0,void 0,(function(){return tslib.__generator(this,(function(e){return this.Ku?[2,t(n)]:[2]}))}))},t(this.isPrimary)},t.prototype.BT=function(t){var e=this;this.CT.Td((function(n){return tslib.__awaiter(e,void 0,void 0,(function(){return tslib.__generator(this,(function(e){switch(e.label){case 0:return null!==n.newVersion?[3,2]:[4,t()];case 1:e.sent(),e.label=2;case 2:return[2]}}))}))}))},t.prototype.a_=function(t){var e=this;this.networkEnabled!==t&&(this.networkEnabled=t,this.q_.Jo((function(){return tslib.__awaiter(e,void 0,void 0,(function(){return tslib.__generator(this,(function(t){switch(t.label){case 0:return this.Ku?[4,this.OT()]:[3,2];case 1:t.sent(),t.label=2;case 2:return[2]}}))}))})))},t.prototype.OT=function(){var t=this;return this.CT.runTransaction("readwrite-idempotent",ALL_STORES,(function(e){return __PRIVATE_clientMetadataStore(e).put(new DbClientMetadata(t.clientId,Date.now(),t.networkEnabled,t.inForeground)).next((function(){if(t.isPrimary)return t.UT(e).next((function(e){e||(t.isPrimary=!1,t.q_.Jo((function(){return t.bT(!1)})))}))})).next((function(){return t.kT(e)})).next((function(n){return t.isPrimary&&!n?t.xT(e).next((function(){return!1})):!!n&&t.KT(e).next((function(){return!0}))}))})).catch((function(e){if(!t.allowTabSynchronization)throw e;return debug(__PRIVATE_LOG_TAG$9,"Releasing owner lease after error during lease refresh",e),!1})).then((function(e){t.isPrimary!==e&&t.q_.Jo((function(){return t.bT(e)})),t.isPrimary=e}))},t.prototype.UT=function(t){var e=this;return __PRIVATE_primaryClientStore(t).get(DbPrimaryClient.key).next((function(t){return PersistencePromise.resolve(e.jT(t))}))},t.prototype.qT=function(t){return __PRIVATE_clientMetadataStore(t).delete(this.clientId)},t.prototype.QT=function(){return tslib.__awaiter(this,void 0,void 0,(function(){var e=this;return tslib.__generator(this,(function(n){switch(n.label){case 0:return!this.isPrimary||this.WT(this.pT,__PRIVATE_MAX_CLIENT_AGE_MS)?[3,2]:(this.pT=Date.now(),[4,this.runTransaction("maybeGarbageCollectMultiClientState","readwrite-primary-idempotent",(function(n){var r=t.dd(n,DbClientMetadata.store);return r.vd().next((function(t){var n=e.$T(t,__PRIVATE_MAX_CLIENT_AGE_MS),i=t.filter((function(t){return-1===n.indexOf(t)}));return PersistencePromise.forEach(i,(function(t){return r.delete(t.clientId)})).next((function(){return i}))}))}))]);case 1:n.sent().forEach((function(t){e.window.localStorage.removeItem(e.YT(t.clientId))})),n.label=2;case 2:return[2]}}))}))},t.prototype.MT=function(){var t=this;this.vT=this.q_.hu(__PRIVATE_TimerId.ko,__PRIVATE_CLIENT_METADATA_REFRESH_INTERVAL_MS,(function(){return t.OT().then((function(){return t.QT()})).then((function(){return t.MT()}))}))},t.prototype.jT=function(t){return!!t&&t.ownerId===this.clientId},t.prototype.kT=function(t){var e=this;return __PRIVATE_primaryClientStore(t).get(DbPrimaryClient.key).next((function(n){if(null!==n&&e.WT(n.leaseTimestampMs,__PRIVATE_MAX_PRIMARY_ELIGIBLE_AGE_MS)&&!e.HT(n.ownerId)){if(e.jT(n)&&e.networkEnabled)return!0;if(!e.jT(n)){if(!n.allowTabSynchronization)throw new FirestoreError(Code.FAILED_PRECONDITION,__PRIVATE_PRIMARY_LEASE_EXCLUSIVE_ERROR_MSG);return!1}}return!(!e.networkEnabled||!e.inForeground)||__PRIVATE_clientMetadataStore(t).vd().next((function(t){return void 0===e.$T(t,__PRIVATE_MAX_PRIMARY_ELIGIBLE_AGE_MS).find((function(t){if(e.clientId!==t.clientId){var n=!e.networkEnabled&&t.networkEnabled,r=!e.inForeground&&t.inForeground,i=e.networkEnabled===t.networkEnabled;if(n||r&&i)return!0}return!1}))}))})).next((function(t){return e.isPrimary!==t&&debug(__PRIVATE_LOG_TAG$9,"Client "+(t?"is":"is not")+" eligible for a primary lease."),t}))},t.prototype.gh=function(){return tslib.__awaiter(this,void 0,void 0,(function(){var t=this;return tslib.__generator(this,(function(e){switch(e.label){case 0:return this.IT=!1,this.XT(),this.vT&&(this.vT.cancel(),this.vT=null),this.zT(),this.JT(),[4,this.CT.runTransaction("readwrite-idempotent",[DbPrimaryClient.store,DbClientMetadata.store],(function(e){return t.xT(e).next((function(){return t.qT(e)}))}))];case 1:return e.sent(),this.CT.close(),this.ZT(),[2]}}))}))},t.prototype.$T=function(t,e){var n=this;return t.filter((function(t){return n.WT(t.updateTimeMs,e)&&!n.HT(t.clientId)}))},t.prototype.s_=function(){var t=this;return this.CT.runTransaction("readonly-idempotent",[DbClientMetadata.store],(function(e){return __PRIVATE_clientMetadataStore(e).vd().next((function(e){return t.$T(e,__PRIVATE_MAX_CLIENT_AGE_MS).map((function(t){return t.clientId}))}))}))},t.clearPersistence=function(e){return tslib.__awaiter(this,void 0,void 0,(function(){var n;return tslib.__generator(this,(function(r){switch(r.label){case 0:return t.ef()?(n=e+t.wT,[4,__PRIVATE_SimpleDb.delete(n)]):[2,Promise.resolve()];case 1:return r.sent(),[2]}}))}))},Object.defineProperty(t.prototype,"Ku",{get:function(){return this.IT},enumerable:!0,configurable:!0}),t.prototype.ua=function(t){return assert(this.Ku,"Cannot initialize MutationQueue before persistence is started."),__PRIVATE_IndexedDbMutationQueue.Dd(t,this.serializer,this.co,this.oa)},t.prototype.ha=function(){return assert(this.Ku,"Cannot initialize TargetCache before persistence is started."),this.ca},t.prototype._a=function(){return assert(this.Ku,"Cannot initialize RemoteDocumentCache before persistence is started."),this.ao},t.prototype.la=function(){return assert(this.Ku,"Cannot initialize IndexManager before persistence is started."),this.co},t.prototype.runTransaction=function(t,e,n){var r=this;debug(__PRIVATE_LOG_TAG$9,"Starting transaction:",t);var i,s=e.endsWith("idempotent"),o=e.startsWith("readonly")?s?"readonly-idempotent":"readonly":s?"readwrite-idempotent":"readwrite";return this.CT.runTransaction(o,ALL_STORES,(function(s){return i=new __PRIVATE_IndexedDbTransaction(s,r.LT.next()),"readwrite-primary"===e||"readwrite-primary-idempotent"===e?r.UT(s).next((function(t){return!!t||r.kT(s)})).next((function(e){if(!e)throw error("Failed to obtain primary lease for action '"+t+"'."),r.isPrimary=!1,r.q_.Jo((function(){return r.bT(!1)})),new FirestoreError(Code.FAILED_PRECONDITION,__PRIVATE_PRIMARY_LEASE_LOST_ERROR_MSG);return n(i)})).next((function(t){return r.KT(s).next((function(){return t}))})):r.tE(s).next((function(){return n(i)}))})).then((function(t){return i.uo(),t}))},t.prototype.tE=function(t){var e=this;return __PRIVATE_primaryClientStore(t).get(DbPrimaryClient.key).next((function(t){if(null!==t&&e.WT(t.leaseTimestampMs,__PRIVATE_MAX_PRIMARY_ELIGIBLE_AGE_MS)&&!e.HT(t.ownerId)&&!e.jT(t)&&!t.allowTabSynchronization)throw new FirestoreError(Code.FAILED_PRECONDITION,__PRIVATE_PRIMARY_LEASE_EXCLUSIVE_ERROR_MSG)}))},t.prototype.KT=function(t){var e=new DbPrimaryClient(this.clientId,this.allowTabSynchronization,Date.now());return __PRIVATE_primaryClientStore(t).put(DbPrimaryClient.key,e)},t.ef=function(){return __PRIVATE_SimpleDb.ef()},t.eE=function(t){var e=t.o.projectId;return t.o.u||(e+="."+t.o.database),"firestore/"+t.persistenceKey+"/"+e+"/"},t.prototype.xT=function(t){var e=this,n=__PRIVATE_primaryClientStore(t);return n.get(DbPrimaryClient.key).next((function(t){return e.jT(t)?(debug(__PRIVATE_LOG_TAG$9,"Releasing primary lease."),n.delete(DbPrimaryClient.key)):PersistencePromise.resolve()}))},t.prototype.WT=function(t,e){var n=Date.now();return!(t<n-e)&&(!(t>n)||(error("Detected an update time that is in the future: "+t+" > "+n),!1))},t.prototype.FT=function(){var t=this;null!==this.document&&"function"==typeof this.document.addEventListener&&(this.mT=function(){t.q_.Jo((function(){return t.inForeground="visible"===t.document.visibilityState,t.OT()}))},this.document.addEventListener("visibilitychange",this.mT),this.inForeground="visible"===this.document.visibilityState)},t.prototype.zT=function(){this.mT&&(assert(null!==this.document&&"function"==typeof this.document.addEventListener,"Expected 'document.addEventListener' to be a function"),this.document.removeEventListener("visibilitychange",this.mT),this.mT=null)},t.prototype.NT=function(){var t=this;"function"==typeof this.window.addEventListener&&(this.VT=function(){t.XT(),t.q_.Jo((function(){return t.gh()}))},this.window.addEventListener("unload",this.VT))},t.prototype.JT=function(){this.VT&&(assert("function"==typeof this.window.removeEventListener,"Expected 'window.removeEventListener' to be a function"),this.window.removeEventListener("unload",this.VT),this.VT=null)},t.prototype.HT=function(t){try{var e=null!==this.yT.getItem(this.YT(t));return debug(__PRIVATE_LOG_TAG$9,"Client '"+t+"' "+(e?"is":"is not")+" zombied in LocalStorage"),e}catch(t){return error(__PRIVATE_LOG_TAG$9,"Failed to get zombied client id.",t),!1}},t.prototype.XT=function(){try{this.yT.setItem(this.YT(this.clientId),String(Date.now()))}catch(t){error("Failed to set zombie client id.",t)}},t.prototype.ZT=function(){try{this.yT.removeItem(this.YT(this.clientId))}catch(t){}},t.prototype.YT=function(t){return __PRIVATE_ZOMBIED_CLIENTS_KEY_PREFIX+"_"+this.persistenceKey+"_"+t},t.wT="main",t}();function __PRIVATE_primaryClientStore(t){return t.store(DbPrimaryClient.store)}function __PRIVATE_clientMetadataStore(t){return t.store(DbClientMetadata.store)}var __PRIVATE_IndexedDbLruDelegate=function(){function t(t,e){this.db=t,this.nE=null,this.Lu=new __PRIVATE_LruGarbageCollector(this,e)}return t.prototype.Wu=function(t){var e=this.rE(t);return this.db.ha().Hd(t).next((function(t){return e.next((function(e){return t+e}))}))},t.prototype.rE=function(t){var e=0;return this.Yu(t,(function(t){e++})).next((function(){return e}))},t.prototype.jr=function(t,e){return this.db.ha().jr(t,e)},t.prototype.Yu=function(t,e){return this.iE(t,(function(t,n){return e(n)}))},t.prototype.sa=function(t){this.nE=t},t.prototype.Ss=function(t,e){return __PRIVATE_writeSentinelKey(t,e)},t.prototype.Cs=function(t,e){return __PRIVATE_writeSentinelKey(t,e)},t.prototype.Hu=function(t,e,n){return this.db.ha().Hu(t,e,n)},t.prototype.Bd=function(t,e){return __PRIVATE_writeSentinelKey(t,e)},t.prototype.sE=function(t,e){return this.nE.Gs(e)?PersistencePromise.resolve(!0):__PRIVATE_mutationQueuesContainKey(t,e)},t.prototype.Xu=function(t,e){var n=this,r=this.db._a().ga(),i=[],s=0;return this.iE(t,(function(o,u){if(u<=e){var a=n.sE(t,o).next((function(e){if(!e)return s++,r.eo(t,o).next((function(){return r.to(o),__PRIVATE_documentTargetStore(t).delete(__PRIVATE_sentinelKey$1(o))}))}));i.push(a)}})).next((function(){return PersistencePromise.$s(i)})).next((function(){return r.apply(t)})).next((function(){return s}))},t.prototype.removeTarget=function(t,e){var n=e.Gn(t.ka);return this.db.ha().Ka(t,n)},t.prototype.ja=function(t,e){return __PRIVATE_writeSentinelKey(t,e)},t.prototype.iE=function(t,e){var n,r=__PRIVATE_documentTargetStore(t),i=__PRIVATE_ListenSequence.Fo;return r.wd({index:DbTargetDocument.documentTargetsIndex},(function(t,r){var s=t[0],o=(t[1],r.path),u=r.sequenceNumber;0===s?(i!==__PRIVATE_ListenSequence.Fo&&e(new __PRIVATE_DocumentKey(decode(n)),i),i=u,n=o):i=__PRIVATE_ListenSequence.Fo})).next((function(){i!==__PRIVATE_ListenSequence.Fo&&e(new __PRIVATE_DocumentKey(decode(n)),i)}))},t.prototype.Ju=function(t){return this.db._a().aT(t)},t}();function __PRIVATE_sentinelKey$1(t){return[0,encode(t.path)]}function __PRIVATE_sentinelRow(t,e){return new DbTargetDocument(0,encode(t.path),e)}function __PRIVATE_writeSentinelKey(t,e){return __PRIVATE_documentTargetStore(t).put(__PRIVATE_sentinelRow(e,t.ka))}var __PRIVATE_IndexFreeQueryEngine=function(){function t(){}return t.prototype.da=function(t){this.oE=t},t.prototype.Ao=function(t,e,n,r){var i=this;return assert(void 0!==this.oE,"setLocalDocumentsView() not called"),e.An()?this.uE(t,e):n.isEqual(__PRIVATE_SnapshotVersion.MIN)?this.uE(t,e):this.oE.To(t,r).next((function(s){var o=i.aE(e,s);return(e.bn()||e.gn())&&i.tl(e.rn,o,r,n)?i.uE(t,e):(__PRIVATE_getLogLevel()<=LogLevel.DEBUG&&debug("IndexFreeQueryEngine","Re-using previous result from %s to execute query: %s",n.toString(),e.toString()),i.oE.Ao(t,e,n).next((function(t){return o.forEach((function(e){t=t.At(e.key,e)})),t})))}))},t.prototype.aE=function(t,e){var n=new __PRIVATE_SortedSet((function(e,n){return t.In(e,n)}));return e.forEach((function(e,r){r instanceof Document&&t.matches(r)&&(n=n.add(r))})),n},t.prototype.tl=function(t,e,n,r){if(n.size!==e.size)return!0;var i=t===__PRIVATE_LimitType.tn?e.last():e.first();return!!i&&(i.hasPendingWrites||i.version._(r)>0)},t.prototype.uE=function(t,e){return __PRIVATE_getLogLevel()<=LogLevel.DEBUG&&debug("IndexFreeQueryEngine","Using full collection scan to execute query: %s",e.toString()),this.oE.Ao(t,e,__PRIVATE_SnapshotVersion.MIN)},t}(),__PRIVATE_MemoryMutationQueue=function(){function t(t,e){this.co=t,this.oa=e,this._o=[],this._E=1,this.lastStreamToken=__PRIVATE_emptyByteString(),this.cE=new __PRIVATE_SortedSet(__PRIVATE_DocReference.$e)}return t.prototype.Cd=function(t){return PersistencePromise.resolve(0===this._o.length)},t.prototype.ba=function(t,e,n){var r=e.batchId,i=this.hE(r,"acknowledged");assert(0===i,"Can only acknowledge the first batch in the mutation queue");var s=this._o[i];return assert(r===s.batchId,"Queue ordering failure: expected batch "+r+", got batch "+s.batchId),this.lastStreamToken=n,PersistencePromise.resolve()},t.prototype.Na=function(t){return PersistencePromise.resolve(this.lastStreamToken)},t.prototype.Ma=function(t,e){return this.lastStreamToken=e,PersistencePromise.resolve()},t.prototype.ma=function(t,e,n,r){assert(0!==r.length,"Mutation batches should not be empty");var i=this._E;(this._E++,this._o.length>0)&&assert(this._o[this._o.length-1].batchId<i,"Mutation batchIDs must be monotonically increasing order");var s=new __PRIVATE_MutationBatch(i,e,n,r);this._o.push(s);for(var o=0,u=r;o<u.length;o++){var a=u[o];this.cE=this.cE.add(new __PRIVATE_DocReference(a.key,i)),this.co.Nd(t,a.key.path.tt())}return PersistencePromise.resolve(s)},t.prototype.Ca=function(t,e){return PersistencePromise.resolve(this.fE(e))},t.prototype.pa=function(t,e){var n=this.fE(e);return assert(null!=n,"Failed to find local mutation batch."),PersistencePromise.resolve(n.keys())},t.prototype.Ya=function(t,e){var n=e+1,r=this.lE(n),i=r<0?0:r;return PersistencePromise.resolve(this._o.length>i?this._o[i]:null)},t.prototype.Fa=function(){return PersistencePromise.resolve(0===this._o.length?__PRIVATE_BATCHID_UNKNOWN:this._E-1)},t.prototype.Pa=function(t){return PersistencePromise.resolve(this._o.slice())},t.prototype.fo=function(t,e){var n=this,r=new __PRIVATE_DocReference(e,0),i=new __PRIVATE_DocReference(e,Number.POSITIVE_INFINITY),s=[];return this.cE.Wt([r,i],(function(t){assert(e.isEqual(t.key),"Should only iterate over a single key's batches");var r=n.fE(t.Bs);assert(null!==r,"Batches in the index must exist in the main table"),s.push(r)})),PersistencePromise.resolve(s)},t.prototype.Po=function(t,e){var n=this,r=new __PRIVATE_SortedSet(__PRIVATE_primitiveComparator);return e.forEach((function(t){var e=new __PRIVATE_DocReference(t,0),i=new __PRIVATE_DocReference(t,Number.POSITIVE_INFINITY);n.cE.Wt([e,i],(function(e){assert(t.isEqual(e.key),"For each key, should only iterate over a single key's batches"),r=r.add(e.Bs)}))})),PersistencePromise.resolve(this.dE(r))},t.prototype.vo=function(t,e){assert(!e.yn(),"CollectionGroup queries should be handled in LocalDocumentsView");var n=e.path,r=n.length+1,i=n;__PRIVATE_DocumentKey.dt(i)||(i=i.child(""));var s=new __PRIVATE_DocReference(new __PRIVATE_DocumentKey(i),0),o=new __PRIVATE_SortedSet(__PRIVATE_primitiveComparator);return this.cE.$t((function(t){var e=t.key.path;return!!n.it(e)&&(e.length===r&&(o=o.add(t.Bs)),!0)}),s),PersistencePromise.resolve(this.dE(o))},t.prototype.dE=function(t){var e=this,n=[];return t.forEach((function(t){var r=e.fE(t);null!==r&&n.push(r)})),n},t.prototype.Oa=function(t,e){var n=this;assert(0===this.hE(e.batchId,"removed"),"Can only remove the first entry of the mutation queue"),this._o.shift();var r=this.cE;return PersistencePromise.forEach(e.mutations,(function(i){var s=new __PRIVATE_DocReference(i.key,e.batchId);return r=r.delete(s),n.oa.Bd(t,i.key)})).next((function(){n.cE=r}))},t.prototype.u_=function(t){},t.prototype.Gs=function(t,e){var n=new __PRIVATE_DocReference(e,0),r=this.cE.Yt(n);return PersistencePromise.resolve(e.isEqual(r&&r.key))},t.prototype.Sa=function(t){return 0===this._o.length&&assert(this.cE.et(),"Document leak -- detected dangling mutation references when queue is empty."),PersistencePromise.resolve()},t.prototype.hE=function(t,e){var n=this.lE(t);return assert(n>=0&&n<this._o.length,"Batches must exist to be "+e),n},t.prototype.lE=function(t){return 0===this._o.length?0:t-this._o[0].batchId},t.prototype.fE=function(t){var e=this.lE(t);if(e<0||e>=this._o.length)return null;var n=this._o[e];return assert(n.batchId===t,"If found batch must match"),n},t}();function __PRIVATE_documentEntryMap(){return new __PRIVATE_SortedMap(__PRIVATE_DocumentKey.X)}var __PRIVATE_MemoryRemoteDocumentCache=function(){function t(t,e){this.co=t,this.TE=e,this.docs=__PRIVATE_documentEntryMap(),this.size=0}return t.prototype.Js=function(t,e,n){assert(!n.isEqual(__PRIVATE_SnapshotVersion.MIN),"Cannot add a document with a read time of zero");var r=e.key,i=this.docs.get(r),s=i?i.size:0,o=this.TE(e);return this.docs=this.docs.At(r,{Zd:e,size:o,readTime:n}),this.size+=o-s,this.co.Nd(t,r.path.tt())},t.prototype.to=function(t){var e=this.docs.get(t);e&&(this.docs=this.docs.remove(t),this.size-=e.size)},t.prototype.eo=function(t,e){var n=this.docs.get(e);return PersistencePromise.resolve(n?n.Zd:null)},t.prototype.getEntries=function(t,e){var n=this,r=__PRIVATE_nullableMaybeDocumentMap();return e.forEach((function(t){var e=n.docs.get(t);r=r.At(t,e?e.Zd:null)})),PersistencePromise.resolve(r)},t.prototype.Ao=function(t,e,n){assert(!e.yn(),"CollectionGroup queries should be handled in LocalDocumentsView");for(var r=__PRIVATE_documentMap(),i=new __PRIVATE_DocumentKey(e.path.child("")),s=this.docs.wt(i);s.Ft();){var o=s.Ot(),u=o.key,a=o.value,_=a.Zd,c=a.readTime;if(!e.path.it(u.path))break;c._(n)<=0||_ instanceof Document&&e.matches(_)&&(r=r.At(_.key,_))}return PersistencePromise.resolve(r)},t.prototype.EE=function(t,e){return PersistencePromise.forEach(this.docs,(function(t){return e(t)}))},t.prototype.c_=function(t,e){throw new Error("getNewDocumentChanges() is not supported with MemoryPersistence")},t.prototype.f_=function(t){return PersistencePromise.resolve(__PRIVATE_SnapshotVersion.MIN)},t.prototype.ga=function(e){return new t.uT(this)},t.prototype.aT=function(t){return PersistencePromise.resolve(this.size)},t.uT=function(t){function e(e){var n=t.call(this)||this;return n._T=e,n}return tslib.__extends(e,t),e.prototype.io=function(t){var e=this,n=[];return this.Hs.forEach((function(r,i){i?n.push(e._T.Js(t,i,e.readTime)):e._T.to(r)})),PersistencePromise.$s(n)},e.prototype.no=function(t,e){return this._T.eo(t,e)},e.prototype.ro=function(t,e){return this._T.getEntries(t,e)},e}(__PRIVATE_RemoteDocumentChangeBuffer),t}(),__PRIVATE_MemoryTargetCache=function(){function t(t){this.persistence=t,this.PE=new __PRIVATE_ObjectMap((function(t){return t.canonicalId()})),this.lastRemoteSnapshotVersion=__PRIVATE_SnapshotVersion.MIN,this.highestTargetId=0,this.AE=0,this.RE=new __PRIVATE_ReferenceSet,this.targetCount=0,this.Ud=__PRIVATE_TargetIdGenerator.qf()}return t.prototype.jr=function(t,e){return this.PE.forEach((function(t,n){return e(n)})),PersistencePromise.resolve()},t.prototype.La=function(t){return PersistencePromise.resolve(this.lastRemoteSnapshotVersion)},t.prototype.Kd=function(t){return PersistencePromise.resolve(this.AE)},t.prototype.Ja=function(t){var e=this.Ud.after(this.highestTargetId);return this.highestTargetId=e,PersistencePromise.resolve(e)},t.prototype.qa=function(t,e,n){return n&&(this.lastRemoteSnapshotVersion=n),e>this.AE&&(this.AE=e),PersistencePromise.resolve()},t.prototype.jd=function(t){this.PE.set(t.target,t);var e=t.targetId;e>this.highestTargetId&&(this.highestTargetId=e),t.sequenceNumber>this.AE&&(this.AE=t.sequenceNumber)},t.prototype.Za=function(t,e){return assert(!this.PE.has(e.target),"Adding a target that already exists"),this.jd(e),this.targetCount+=1,PersistencePromise.resolve()},t.prototype.Ka=function(t,e){return assert(this.PE.has(e.target),"Updating a non-existent target"),this.jd(e),PersistencePromise.resolve()},t.prototype.Qd=function(t,e){return assert(this.targetCount>0,"Removing a target from an empty cache"),assert(this.PE.has(e.target),"Removing a non-existent target from the cache"),this.PE.delete(e.target),this.RE.Ns(e.targetId),this.targetCount-=1,PersistencePromise.resolve()},t.prototype.Hu=function(t,e,n){var r=this,i=0,s=[];return this.PE.forEach((function(o,u){u.sequenceNumber<=e&&null===n.get(u.targetId)&&(r.PE.delete(o),s.push(r.Wd(t,u.targetId)),i++)})),PersistencePromise.$s(s).next((function(){return i}))},t.prototype.Hd=function(t){return PersistencePromise.resolve(this.targetCount)},t.prototype.za=function(t,e){var n=this.PE.get(e)||null;return PersistencePromise.resolve(n)},t.prototype.ti=function(t,e){return fail("Not yet implemented.")},t.prototype.Ua=function(t,e,n){this.RE.Ds(e,n);var r=this.persistence.oa,i=[];return r&&e.forEach((function(e){i.push(r.Ss(t,e))})),PersistencePromise.$s(i)},t.prototype.Ba=function(t,e,n){this.RE.Fs(e,n);var r=this.persistence.oa,i=[];return r&&e.forEach((function(e){i.push(r.Cs(t,e))})),PersistencePromise.$s(i)},t.prototype.Wd=function(t,e){return this.RE.Ns(e),PersistencePromise.resolve()},t.prototype.n_=function(t,e){var n=this.RE.Ls(e);return PersistencePromise.resolve(n)},t.prototype.Gs=function(t,e){return PersistencePromise.resolve(this.RE.Gs(e))},t}(),__PRIVATE_LOG_TAG$a="MemoryPersistence",__PRIVATE_MemoryPersistence=function(){function t(t,e){var n=this;this.clientId=t,this.IE={},this.LT=new __PRIVATE_ListenSequence(0),this.IT=!1,this.IT=!0,this.oa=e(this),this.ca=new __PRIVATE_MemoryTargetCache(this);this.co=new __PRIVATE_MemoryIndexManager,this.ao=new __PRIVATE_MemoryRemoteDocumentCache(this.co,(function(t){return n.oa.VE(t)}))}return t.mE=function(e,n){return new t(e,(function(t){return new __PRIVATE_MemoryLruDelegate(t,n)}))},t.vE=function(e){return new t(e,(function(t){return new __PRIVATE_MemoryEagerDelegate(t)}))},t.prototype.gh=function(){return this.IT=!1,Promise.resolve()},Object.defineProperty(t.prototype,"Ku",{get:function(){return this.IT},enumerable:!0,configurable:!0}),t.prototype.s_=function(){return tslib.__awaiter(this,void 0,void 0,(function(){return tslib.__generator(this,(function(t){return[2,[this.clientId]]}))}))},t.prototype.GT=function(t){return t(!0)},t.prototype.BT=function(){},t.prototype.a_=function(t){},t.prototype.la=function(){return this.co},t.prototype.ua=function(t){var e=this.IE[t.I()];return e||(e=new __PRIVATE_MemoryMutationQueue(this.co,this.oa),this.IE[t.I()]=e),e},t.prototype.ha=function(){return this.ca},t.prototype._a=function(){return this.ao},t.prototype.runTransaction=function(t,e,n){var r=this;debug(__PRIVATE_LOG_TAG$a,"Starting transaction:",t);var i=new __PRIVATE_MemoryTransaction(this.LT.next());return this.oa.pE(),n(i).next((function(t){return r.oa.bE(i).next((function(){return t}))})).Qs().then((function(t){return i.uo(),t}))},t.prototype.gE=function(t,e){return PersistencePromise.Ys(values(this.IE).map((function(n){return function(){return n.Gs(t,e)}})))},t}(),__PRIVATE_MemoryTransaction=function(t){function e(e){var n=t.call(this)||this;return n.ka=e,n}return tslib.__extends(e,t),e}(__PRIVATE_PersistenceTransaction),__PRIVATE_MemoryEagerDelegate=function(){function t(t){this.persistence=t,this.nE=null,this.wE=null}return Object.defineProperty(t.prototype,"yE",{get:function(){if(this.wE)return this.wE;throw fail("orphanedDocuments is only valid during a transaction.")},enumerable:!0,configurable:!0}),t.prototype.sa=function(t){this.nE=t},t.prototype.Ss=function(t,e){return this.yE.delete(e),PersistencePromise.resolve()},t.prototype.Cs=function(t,e){return this.yE.add(e),PersistencePromise.resolve()},t.prototype.Bd=function(t,e){return this.yE.add(e),PersistencePromise.resolve()},t.prototype.removeTarget=function(t,e){var n=this,r=this.persistence.ha();return r.n_(t,e.targetId).next((function(t){t.forEach((function(t){return n.yE.add(t)}))})).next((function(){return r.Qd(t,e)}))},t.prototype.pE=function(){this.wE=new Set},t.prototype.bE=function(t){var e=this,n=this.persistence._a().ga();return PersistencePromise.forEach(this.yE,(function(r){return e.SE(t,r).next((function(t){t||n.to(r)}))})).next((function(){return e.wE=null,n.apply(t)}))},t.prototype.ja=function(t,e){var n=this;return this.SE(t,e).next((function(t){t?n.yE.delete(e):n.yE.add(e)}))},t.prototype.VE=function(t){return 0},t.prototype.SE=function(t,e){var n=this;return PersistencePromise.Ys([function(){return n.persistence.ha().Gs(t,e)},function(){return n.persistence.gE(t,e)},function(){return PersistencePromise.resolve(n.nE.Gs(e))}])},t}(),__PRIVATE_MemoryLruDelegate=function(){function t(t,e){this.persistence=t,this.nE=null,this.DE=new __PRIVATE_ObjectMap((function(t){return encode(t.path)})),this.Lu=new __PRIVATE_LruGarbageCollector(this,e)}return t.prototype.pE=function(){},t.prototype.bE=function(t){return PersistencePromise.resolve()},t.prototype.jr=function(t,e){return this.persistence.ha().jr(t,e)},t.prototype.Wu=function(t){var e=this.CE(t);return this.persistence.ha().Hd(t).next((function(t){return e.next((function(e){return t+e}))}))},t.prototype.CE=function(t){var e=0;return this.Yu(t,(function(t){e++})).next((function(){return e}))},t.prototype.Yu=function(t,e){var n=this;return PersistencePromise.forEach(this.DE,(function(r,i){return n.sE(t,r,i).next((function(t){return t?PersistencePromise.resolve():e(i)}))}))},t.prototype.sa=function(t){this.nE=t},t.prototype.Hu=function(t,e,n){return this.persistence.ha().Hu(t,e,n)},t.prototype.Xu=function(t,e){var n=this,r=0,i=this.persistence._a(),s=i.ga();return i.EE(t,(function(i){return n.sE(t,i,e).next((function(t){t||(r++,s.to(i))}))})).next((function(){return s.apply(t)})).next((function(){return r}))},t.prototype.Bd=function(t,e){return this.DE.set(e,t.ka),PersistencePromise.resolve()},t.prototype.removeTarget=function(t,e){var n=e.Gn(t.ka);return this.persistence.ha().Ka(t,n)},t.prototype.Ss=function(t,e){return this.DE.set(e,t.ka),PersistencePromise.resolve()},t.prototype.Cs=function(t,e){return this.DE.set(e,t.ka),PersistencePromise.resolve()},t.prototype.ja=function(t,e){return this.DE.set(e,t.ka),PersistencePromise.resolve()},t.prototype.VE=function(t){var e=t.key.toString().length;return t instanceof Document&&(e+=t.data().Ue()),e},t.prototype.sE=function(t,e,n){var r=this;return PersistencePromise.Ys([function(){return r.persistence.gE(t,e)},function(){return PersistencePromise.resolve(r.nE.Gs(e))},function(){return r.persistence.ha().Gs(t,e)},function(){var t=r.DE.get(e);return PersistencePromise.resolve(void 0!==t&&t>n)}])},t.prototype.Ju=function(t){return this.persistence._a().aT(t)},t}(),__PRIVATE_LOG_TAG$b="FirestoreClient",__PRIVATE_DOM_EXCEPTION_INVALID_STATE=11,__PRIVATE_DOM_EXCEPTION_ABORTED=20,__PRIVATE_DOM_EXCEPTION_QUOTA_EXCEEDED=22,__PRIVATE_IndexedDbPersistenceSettings=function(){function t(t,e){this.cacheSizeBytes=t,this.synchronizeTabs=e}return t.prototype.DT=function(){return __PRIVATE_LruParams.Su(this.cacheSizeBytes)},t}(),__PRIVATE_MemoryPersistenceSettings=function(){},__PRIVATE_FirestoreClient=function(){function t(t,e,n,r){this.platform=t,this.OE=e,this.credentials=n,this.jo=r,this.clientId=__PRIVATE_AutoId.s()}return t.prototype.start=function(t){var e=this;this.FE();var n=new __PRIVATE_Deferred,r=new __PRIVATE_Deferred,i=!1;return this.credentials.S((function(s){i?e.jo.Jo((function(){return e.qh(s)})):(i=!0,e.NE(t,r,s).then((function(t){return e.ME(s,t)})).then(n.resolve,n.reject))})),this.jo.Jo((function(){return n.promise})),r.promise},t.prototype.enableNetwork=function(){var t=this;return this.FE(),this.jo.enqueue((function(){return t.Dh.enableNetwork()}))},t.prototype.NE=function(t,e,n){var r=this;return t instanceof __PRIVATE_IndexedDbPersistenceSettings?this.LE(n,t).then((function(t){return e.resolve(),t})).catch((function(t){if(e.reject(t),!r.GE(t))throw t;return console.warn("Error enabling offline persistence. Falling back to persistence disabled: "+t),r.BE()})):(e.resolve(),this.BE())},t.prototype.GE=function(t){return t instanceof FirestoreError?t.code===Code.FAILED_PRECONDITION||t.code===Code.UNIMPLEMENTED:!("undefined"!=typeof DOMException&&t instanceof DOMException)||(t.code===__PRIVATE_DOM_EXCEPTION_QUOTA_EXCEEDED||t.code===__PRIVATE_DOM_EXCEPTION_ABORTED||t.code===__PRIVATE_DOM_EXCEPTION_INVALID_STATE)},t.prototype.FE=function(){if(this.jo.su)throw new FirestoreError(Code.FAILED_PRECONDITION,"The client has already been terminated.")},t.prototype.LE=function(t,e){var n=this,r=__PRIVATE_IndexedDbPersistence.eE(this.OE),i=new __PRIVATE_JsonProtoSerializer(this.OE.o,{ni:!0});return Promise.resolve().then((function(){return tslib.__awaiter(n,void 0,void 0,(function(){var n,s;return tslib.__generator(this,(function(o){switch(o.label){case 0:if(e.synchronizeTabs&&!__PRIVATE_WebStorageSharedClientState.ef(this.platform))throw new FirestoreError(Code.UNIMPLEMENTED,"IndexedDB persistence is only available on platforms that support LocalStorage.");return n=e.DT(),this.El=e.synchronizeTabs?new __PRIVATE_WebStorageSharedClientState(this.jo,this.platform,r,this.clientId,t):new __PRIVATE_MemorySharedClientState,[4,__PRIVATE_IndexedDbPersistence.ST({allowTabSynchronization:e.synchronizeTabs,persistenceKey:r,clientId:this.clientId,platform:this.platform,q_:this.jo,serializer:i,DT:n,RT:this.El})];case 1:return s=o.sent(),this.persistence=s,[2,s.oa.Lu]}}))}))}))},t.prototype.BE=function(){return this.persistence=__PRIVATE_MemoryPersistence.vE(this.clientId),this.El=new __PRIVATE_MemorySharedClientState,Promise.resolve(null)},t.prototype.ME=function(t,e){var n=this;return debug(__PRIVATE_LOG_TAG$b,"Initializing. user=",t.uid),this.platform.UE(this.OE).then((function(r){return tslib.__awaiter(n,void 0,void 0,(function(){var n,i,s,o,u,a,_=this;return tslib.__generator(this,(function(c){switch(c.label){case 0:return n=new __PRIVATE_IndexFreeQueryEngine,this.Gu=new __PRIVATE_LocalStore(this.persistence,n,t),[4,this.Gu.start()];case 1:return c.sent(),e&&(this.kE=new __PRIVATE_LruScheduler(e,this.jo,this.Gu)),i=this.platform.xE(),s=this.platform.KE(this.OE.o),o=new __PRIVATE_Datastore(this.jo,r,this.credentials,s),u=function(t){return _.Dh.il(t,__PRIVATE_OnlineStateSource.P)},a=function(t){return _.Dh.il(t,__PRIVATE_OnlineStateSource.A)},this.al=new __PRIVATE_RemoteStore(this.Gu,o,this.jo,u,i),this.Dh=new __PRIVATE_SyncEngine(this.Gu,this.al,this.El,t),this.El.Hc=a,this.al.Dh=this.Dh,this.El.Dh=this.Dh,this.jE=new __PRIVATE_EventManager(this.Dh),[4,this.El.start()];case 2:return c.sent(),[4,this.al.start()];case 3:return c.sent(),[4,this.persistence.GT((function(t){return tslib.__awaiter(_,void 0,void 0,(function(){return tslib.__generator(this,(function(e){switch(e.label){case 0:return[4,this.Dh.Qh(t)];case 1:return e.sent(),this.kE&&(t&&!this.kE.Ku?this.kE.start():t||this.kE.stop()),[2]}}))}))}))];case 4:return c.sent(),[4,this.persistence.BT((function(){return tslib.__awaiter(_,void 0,void 0,(function(){return tslib.__generator(this,(function(t){switch(t.label){case 0:return[4,this.terminate()];case 1:return t.sent(),[2]}}))}))}))];case 5:return c.sent(),[2]}}))}))}))},t.prototype.qh=function(t){return this.jo.lu(),debug(__PRIVATE_LOG_TAG$b,"Credential Changed. Current user: "+t.uid),this.Dh.qh(t)},t.prototype.disableNetwork=function(){var t=this;return this.FE(),this.jo.enqueue((function(){return t.Dh.disableNetwork()}))},t.prototype.terminate=function(){var t=this;return this.jo.cu((function(){return tslib.__awaiter(t,void 0,void 0,(function(){return tslib.__generator(this,(function(t){switch(t.label){case 0:return this.kE&&this.kE.stop(),[4,this.al.gh()];case 1:return t.sent(),[4,this.El.gh()];case 2:return t.sent(),[4,this.persistence.gh()];case 3:return t.sent(),this.credentials.D(),[2]}}))}))}))},t.prototype.waitForPendingWrites=function(){var t=this;this.FE();var e=new __PRIVATE_Deferred;return this.jo.Jo((function(){return t.Dh.Gl(e)})),e.promise},t.prototype.listen=function(t,e,n){var r=this;this.FE();var i=new __PRIVATE_QueryListener(t,e,n);return this.jo.Jo((function(){return r.jE.listen(i)})),i},t.prototype.yh=function(t){var e=this;this.qE||this.jo.Jo((function(){return e.jE.yh(t)}))},t.prototype.QE=function(t){var e=this;return this.FE(),this.jo.enqueue((function(){return e.Gu.Ha(t)})).then((function(t){if(t instanceof Document)return t;if(t instanceof __PRIVATE_NoDocument)return null;throw new FirestoreError(Code.UNAVAILABLE,"Failed to get document from cache. (However, this document may exist on the server. Run again without setting 'source' in the GetOptions to attempt to retrieve the document from the server.)")}))},t.prototype.WE=function(t){var e=this;return this.FE(),this.jo.enqueue((function(){return tslib.__awaiter(e,void 0,void 0,(function(){var e,n,r;return tslib.__generator(this,(function(i){switch(i.label){case 0:return[4,this.Gu.e_(t,!0)];case 1:return e=i.sent(),n=new __PRIVATE_View(t,e.r_),r=n.zf(e.documents),[2,n.io(r,!1).snapshot]}}))}))}))},t.prototype.write=function(t){var e=this;this.FE();var n=new __PRIVATE_Deferred;return this.jo.Jo((function(){return e.Dh.write(t,n)})),n.promise},t.prototype.o=function(){return this.OE.o},t.prototype.Jl=function(t){var e=this;this.FE(),this.jo.Jo((function(){return e.jE.Jl(t),Promise.resolve()}))},t.prototype.Zl=function(t){this.qE||this.jE.Zl(t)},Object.defineProperty(t.prototype,"qE",{get:function(){return this.jo.su},enumerable:!0,configurable:!0}),t.prototype.transaction=function(t){var e=this;this.FE();var n=new __PRIVATE_Deferred;return this.jo.Jo((function(){return e.Dh.runTransaction(e.jo,t,n),Promise.resolve()})),n.promise},t}(),__PRIVATE_AsyncObserver=function(){function t(t){this.observer=t,this.muted=!1}return t.prototype.next=function(t){this.$E(this.observer.next,t)},t.prototype.error=function(t){this.$E(this.observer.error,t)},t.prototype.YE=function(){this.muted=!0},t.prototype.$E=function(t,e){var n=this;this.muted||setTimeout((function(){n.muted||t(e)}),0)},t}();function __PRIVATE_isPartialObserver(t){return __PRIVATE_implementsAnyMethods(t,["next","error","complete"])}function __PRIVATE_implementsAnyMethods(t,e){if("object"!=typeof t||null===t)return!1;for(var n=t,r=0,i=e;r<i.length;r++){var s=i[r];if(s in n&&"function"==typeof n[s])return!0}return!1}var __PRIVATE_DEFAULT_HOST="firestore.googleapis.com",__PRIVATE_DEFAULT_SSL=!0,__PRIVATE_DEFAULT_TIMESTAMPS_IN_SNAPSHOTS=!0,__PRIVATE_DEFAULT_FORCE_LONG_POLLING=!1,CACHE_SIZE_UNLIMITED=__PRIVATE_LruParams.Ou,__PRIVATE_DEFAULT_SYNCHRONIZE_TABS=!1,__PRIVATE_FirestoreSettings=function(){function t(t){if(void 0===t.host){if(void 0!==t.ssl)throw new FirestoreError(Code.INVALID_ARGUMENT,"Can't provide ssl option if host option is not set");this.host=__PRIVATE_DEFAULT_HOST,this.ssl=__PRIVATE_DEFAULT_SSL}else __PRIVATE_validateNamedType("settings","non-empty string","host",t.host),this.host=t.host,__PRIVATE_validateNamedOptionalType("settings","boolean","ssl",t.ssl),this.ssl=__PRIVATE_defaulted(t.ssl,__PRIVATE_DEFAULT_SSL);if(__PRIVATE_validateOptionNames("settings",t,["host","ssl","credentials","timestampsInSnapshots","cacheSizeBytes","experimentalForceLongPolling"]),__PRIVATE_validateNamedOptionalType("settings","object","credentials",t.credentials),this.credentials=t.credentials,__PRIVATE_validateNamedOptionalType("settings","boolean","timestampsInSnapshots",t.timestampsInSnapshots),!0===t.timestampsInSnapshots?error("\n The timestampsInSnapshots setting now defaults to true and you no\n longer need to explicitly set it. In a future release, the setting\n will be removed entirely and so it is recommended that you remove it\n from your firestore.settings() call now."):!1===t.timestampsInSnapshots&&error("\n The timestampsInSnapshots setting will soon be removed. YOU MUST UPDATE\n YOUR CODE.\n\n To hide this warning, stop using the timestampsInSnapshots setting in your\n firestore.settings({ ... }) call.\n\n Once you remove the setting, Timestamps stored in Cloud Firestore will be\n read back as Firebase Timestamp objects instead of as system Date objects.\n So you will also need to update code expecting a Date to instead expect a\n Timestamp. For example:\n\n // Old:\n const date = snapshot.get('created_at');\n // New:\n const timestamp = snapshot.get('created_at'); const date =\n timestamp.toDate();\n\n Please audit all existing usages of Date when you enable the new\n behavior."),this.timestampsInSnapshots=__PRIVATE_defaulted(t.timestampsInSnapshots,__PRIVATE_DEFAULT_TIMESTAMPS_IN_SNAPSHOTS),__PRIVATE_validateNamedOptionalType("settings","number","cacheSizeBytes",t.cacheSizeBytes),void 0===t.cacheSizeBytes)this.cacheSizeBytes=__PRIVATE_LruParams.Nu;else{if(t.cacheSizeBytes!==CACHE_SIZE_UNLIMITED&&t.cacheSizeBytes<__PRIVATE_LruParams.Fu)throw new FirestoreError(Code.INVALID_ARGUMENT,"cacheSizeBytes must be at least "+__PRIVATE_LruParams.Fu);this.cacheSizeBytes=t.cacheSizeBytes}__PRIVATE_validateNamedOptionalType("settings","boolean","experimentalForceLongPolling",t.experimentalForceLongPolling),this.forceLongPolling=void 0===t.experimentalForceLongPolling?__PRIVATE_DEFAULT_FORCE_LONG_POLLING:t.experimentalForceLongPolling}return t.prototype.isEqual=function(t){return this.host===t.host&&this.ssl===t.ssl&&this.timestampsInSnapshots===t.timestampsInSnapshots&&this.credentials===t.credentials&&this.cacheSizeBytes===t.cacheSizeBytes&&this.forceLongPolling===t.forceLongPolling},t}(),Firestore=function(){function t(e,n){var r=this;if(this.HE=null,this.XE=new __PRIVATE_AsyncQueue,this.INTERNAL={delete:function(){return tslib.__awaiter(r,void 0,void 0,(function(){return tslib.__generator(this,(function(t){switch(t.label){case 0:return this.zE(),[4,this.JE.terminate()];case 1:return t.sent(),[2]}}))}))}},"object"==typeof e.options){var i=e;this.HE=i,this.ZE=t.tP(i),this.eP=i.name,this.nP=new __PRIVATE_FirebaseCredentialsProvider(n)}else{var s=e;if(!s.projectId)throw new FirestoreError(Code.INVALID_ARGUMENT,"Must provide projectId");this.ZE=new __PRIVATE_DatabaseId(s.projectId,s.database),this.eP="[DEFAULT]",this.nP=new __PRIVATE_EmptyCredentialsProvider}this.rP=new __PRIVATE_FirestoreSettings({}),this.iP=this.sP(this.ZE)}return t.prototype.settings=function(t){if(__PRIVATE_validateExactNumberOfArgs("Firestore.settings",arguments,1),__PRIVATE_validateArgType("Firestore.settings","object",1,t),contains(t,"persistence"))throw new FirestoreError(Code.INVALID_ARGUMENT,'"persistence" is now specified with a separate call to firestore.enablePersistence().');var e=new __PRIVATE_FirestoreSettings(t);if(this.JE&&!this.rP.isEqual(e))throw new FirestoreError(Code.FAILED_PRECONDITION,"Firestore has already been started and its settings can no longer be changed. You can only call settings() before calling any other methods on a Firestore object.");this.rP=e,void 0!==e.credentials&&(this.nP=__PRIVATE_makeCredentialsProvider(e.credentials))},t.prototype.enableNetwork=function(){return this.zE(),this.JE.enableNetwork()},t.prototype.disableNetwork=function(){return this.zE(),this.JE.disableNetwork()},t.prototype.enablePersistence=function(t){if(this.JE)throw new FirestoreError(Code.FAILED_PRECONDITION,"Firestore has already been started and persistence can no longer be enabled. You can only call enablePersistence() before calling any other methods on a Firestore object.");var e=!1;return t&&(void 0!==t.experimentalTabSynchronization&&error("The 'experimentalTabSynchronization' setting has been renamed to 'synchronizeTabs'. In a future release, the setting will be removed and it is recommended that you update your firestore.enablePersistence() call to use 'synchronizeTabs'."),e=__PRIVATE_defaulted(void 0!==t.synchronizeTabs?t.synchronizeTabs:t.experimentalTabSynchronization,__PRIVATE_DEFAULT_SYNCHRONIZE_TABS)),this.oP(new __PRIVATE_IndexedDbPersistenceSettings(this.rP.cacheSizeBytes,e))},t.prototype.clearPersistence=function(){var t=this,e=__PRIVATE_IndexedDbPersistence.eE(this.uP()),n=new __PRIVATE_Deferred;return this.XE.ou((function(){return tslib.__awaiter(t,void 0,void 0,(function(){var t;return tslib.__generator(this,(function(r){switch(r.label){case 0:if(r.trys.push([0,2,,3]),void 0!==this.JE&&!this.JE.qE)throw new FirestoreError(Code.FAILED_PRECONDITION,"Persistence cannot be cleared after this Firestore instance is initialized.");return[4,__PRIVATE_IndexedDbPersistence.clearPersistence(e)];case 1:return r.sent(),n.resolve(),[3,3];case 2:return t=r.sent(),n.reject(t),[3,3];case 3:return[2]}}))}))})),n.promise},t.prototype.terminate=function(){return this.app._removeServiceInstance("firestore"),this.INTERNAL.delete()},Object.defineProperty(t.prototype,"aP",{get:function(){return this.zE(),this.JE.qE},enumerable:!0,configurable:!0}),t.prototype.waitForPendingWrites=function(){return this.zE(),this.JE.waitForPendingWrites()},t.prototype.onSnapshotsInSync=function(t){if(this.zE(),__PRIVATE_isPartialObserver(t))return this._P(t);__PRIVATE_validateArgType("Firestore.onSnapshotsInSync","function",1,t);var e={next:t};return this._P(e)},t.prototype._P=function(t){var e=this,n=new __PRIVATE_AsyncObserver({next:function(){t.next&&t.next()},error:function(t){throw fail("Uncaught Error in onSnapshotsInSync")}});return this.JE.Jl(n),function(){n.YE(),e.JE.Zl(n)}},t.prototype.zE=function(){return this.JE||this.oP(new __PRIVATE_MemoryPersistenceSettings),this.JE},t.prototype.uP=function(){return new __PRIVATE_DatabaseInfo(this.ZE,this.eP,this.rP.host,this.rP.ssl,this.rP.forceLongPolling)},t.prototype.oP=function(t){assert(!!this.rP.host,"FirestoreSettings.host is not set"),assert(!this.JE,"configureClient() called multiple times");var e=this.uP();return this.JE=new __PRIVATE_FirestoreClient(__PRIVATE_PlatformSupport.t(),e,this.nP,this.XE),this.JE.start(t)},t.prototype.sP=function(t){return new __PRIVATE_UserDataConverter((function(e){if(e instanceof DocumentReference){var n=t,r=e.firestore.ZE;if(!r.isEqual(n))throw new FirestoreError(Code.INVALID_ARGUMENT,"Document reference is for database "+r.projectId+"/"+r.database+" but should be for database "+n.projectId+"/"+n.database);return new __PRIVATE_DocumentKeyReference(t,e.cP)}return e}))},t.tP=function(t){var e=t.options;if(!contains(e,"projectId"))throw new FirestoreError(Code.INVALID_ARGUMENT,'"projectId" not provided in firebase.initializeApp.');var n=e.projectId;if(!n||"string"!=typeof n)throw new FirestoreError(Code.INVALID_ARGUMENT,"projectId must be a string in FirebaseApp.options");return new __PRIVATE_DatabaseId(n)},Object.defineProperty(t.prototype,"app",{get:function(){if(!this.HE)throw new FirestoreError(Code.FAILED_PRECONDITION,"Firestore was not initialized using the Firebase SDK. 'app' is not available");return this.HE},enumerable:!0,configurable:!0}),t.prototype.collection=function(t){return __PRIVATE_validateExactNumberOfArgs("Firestore.collection",arguments,1),__PRIVATE_validateArgType("Firestore.collection","non-empty string",1,t),this.zE(),new CollectionReference(ResourcePath.at(t),this)},t.prototype.doc=function(t){return __PRIVATE_validateExactNumberOfArgs("Firestore.doc",arguments,1),__PRIVATE_validateArgType("Firestore.doc","non-empty string",1,t),this.zE(),DocumentReference.hP(ResourcePath.at(t),this)},t.prototype.collectionGroup=function(t){if(__PRIVATE_validateExactNumberOfArgs("Firestore.collectionGroup",arguments,1),__PRIVATE_validateArgType("Firestore.collectionGroup","non-empty string",1,t),t.indexOf("/")>=0)throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid collection ID '"+t+"' passed to function Firestore.collectionGroup(). Collection IDs must not contain '/'.");return this.zE(),new Query$1(new Query(ResourcePath._t,t),this)},t.prototype.runTransaction=function(t){var e=this;return __PRIVATE_validateExactNumberOfArgs("Firestore.runTransaction",arguments,1),__PRIVATE_validateArgType("Firestore.runTransaction","function",1,t),this.zE().transaction((function(n){return t(new Transaction$1(e,n))}))},t.prototype.batch=function(){return this.zE(),new WriteBatch(this)},Object.defineProperty(t,"logLevel",{get:function(){switch(__PRIVATE_getLogLevel()){case LogLevel.DEBUG:return"debug";case LogLevel.ERROR:return"error";case LogLevel.SILENT:return"silent";default:return fail("Unknown log level: "+__PRIVATE_getLogLevel())}},enumerable:!0,configurable:!0}),t.setLogLevel=function(t){switch(__PRIVATE_validateExactNumberOfArgs("Firestore.setLogLevel",arguments,1),__PRIVATE_validateArgType("Firestore.setLogLevel","non-empty string",1,t),t){case"debug":setLogLevel(LogLevel.DEBUG);break;case"error":setLogLevel(LogLevel.ERROR);break;case"silent":setLogLevel(LogLevel.SILENT);break;default:throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid log level: "+t)}},t.prototype.fP=function(){return this.rP.timestampsInSnapshots},t}(),Transaction$1=function(){function t(t,e){this.lP=t,this.dP=e}return t.prototype.get=function(t){var e=this;__PRIVATE_validateExactNumberOfArgs("Transaction.get",arguments,1);var n=__PRIVATE_validateReference("Transaction.get",t,this.lP);return this.dP.Uc([n.cP]).then((function(t){if(!t||1!==t.length)return fail("Mismatch in docs returned from document lookup.");var r=t[0];if(r instanceof __PRIVATE_NoDocument)return new DocumentSnapshot(e.lP,n.cP,null,!1,!1,n.TP);if(r instanceof Document)return new DocumentSnapshot(e.lP,n.cP,r,!1,!1,n.TP);throw fail("BatchGetDocumentsRequest returned unexpected document type: "+r.constructor.name)}))},t.prototype.set=function(t,e,n){__PRIVATE_validateBetweenNumberOfArgs("Transaction.set",arguments,2,3);var r=__PRIVATE_validateReference("Transaction.set",t,this.lP);n=__PRIVATE_validateSetOptions("Transaction.set",n);var i=__PRIVATE_applyFirestoreDataConverter(r.TP,e,"Transaction.set"),s=i[0],o=i[1],u=n.merge||n.mergeFields?this.lP.iP.N_(o,s,n.mergeFields):this.lP.iP.O_(o,s);return this.dP.set(r.cP,u),this},t.prototype.update=function(t,e,n){for(var r,i,s=[],o=3;o<arguments.length;o++)s[o-3]=arguments[o];return"string"==typeof e||e instanceof FieldPath$1?(__PRIVATE_validateAtLeastNumberOfArgs("Transaction.update",arguments,3),r=__PRIVATE_validateReference("Transaction.update",t,this.lP),i=this.lP.iP.G_("Transaction.update",e,n,s)):(__PRIVATE_validateExactNumberOfArgs("Transaction.update",arguments,2),r=__PRIVATE_validateReference("Transaction.update",t,this.lP),i=this.lP.iP.M_("Transaction.update",e)),this.dP.update(r.cP,i),this},t.prototype.delete=function(t){__PRIVATE_validateExactNumberOfArgs("Transaction.delete",arguments,1);var e=__PRIVATE_validateReference("Transaction.delete",t,this.lP);return this.dP.delete(e.cP),this},t}(),WriteBatch=function(){function t(t){this.lP=t,this.EP=[],this.PP=!1}return t.prototype.set=function(t,e,n){__PRIVATE_validateBetweenNumberOfArgs("WriteBatch.set",arguments,2,3),this.AP();var r=__PRIVATE_validateReference("WriteBatch.set",t,this.lP);n=__PRIVATE_validateSetOptions("WriteBatch.set",n);var i=__PRIVATE_applyFirestoreDataConverter(r.TP,e,"WriteBatch.set"),s=i[0],o=i[1],u=n.merge||n.mergeFields?this.lP.iP.N_(o,s,n.mergeFields):this.lP.iP.O_(o,s);return this.EP=this.EP.concat(u.A_(r.cP,Precondition.NONE)),this},t.prototype.update=function(t,e,n){for(var r,i,s=[],o=3;o<arguments.length;o++)s[o-3]=arguments[o];return this.AP(),"string"==typeof e||e instanceof FieldPath$1?(__PRIVATE_validateAtLeastNumberOfArgs("WriteBatch.update",arguments,3),r=__PRIVATE_validateReference("WriteBatch.update",t,this.lP),i=this.lP.iP.G_("WriteBatch.update",e,n,s)):(__PRIVATE_validateExactNumberOfArgs("WriteBatch.update",arguments,2),r=__PRIVATE_validateReference("WriteBatch.update",t,this.lP),i=this.lP.iP.M_("WriteBatch.update",e)),this.EP=this.EP.concat(i.A_(r.cP,Precondition.exists(!0))),this},t.prototype.delete=function(t){__PRIVATE_validateExactNumberOfArgs("WriteBatch.delete",arguments,1),this.AP();var e=__PRIVATE_validateReference("WriteBatch.delete",t,this.lP);return this.EP=this.EP.concat(new __PRIVATE_DeleteMutation(e.cP,Precondition.NONE)),this},t.prototype.commit=function(){return tslib.__awaiter(this,void 0,void 0,(function(){return tslib.__generator(this,(function(t){return this.AP(),this.PP=!0,this.EP.length>0?[2,this.lP.zE().write(this.EP)]:[2]}))}))},t.prototype.AP=function(){if(this.PP)throw new FirestoreError(Code.FAILED_PRECONDITION,"A write batch can no longer be used after commit() has been called.")},t}(),DocumentReference=function(){function t(t,e,n){this.cP=t,this.firestore=e,this.TP=n,this.JE=this.firestore.zE()}return t.hP=function(e,n,r){if(e.length%2!=0)throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid document reference. Document references must have an even number of segments, but "+e.ut()+" has "+e.length);return new t(new __PRIVATE_DocumentKey(e),n,r)},Object.defineProperty(t.prototype,"id",{get:function(){return this.cP.path.rt()},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"parent",{get:function(){return new CollectionReference(this.cP.path.tt(),this.firestore,this.TP)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"path",{get:function(){return this.cP.path.ut()},enumerable:!0,configurable:!0}),t.prototype.collection=function(t){if(__PRIVATE_validateExactNumberOfArgs("DocumentReference.collection",arguments,1),__PRIVATE_validateArgType("DocumentReference.collection","non-empty string",1,t),!t)throw new FirestoreError(Code.INVALID_ARGUMENT,"Must provide a non-empty collection name to collection()");var e=ResourcePath.at(t);return new CollectionReference(this.cP.path.child(e),this.firestore)},t.prototype.isEqual=function(e){if(!(e instanceof t))throw __PRIVATE_invalidClassError("isEqual","DocumentReference",1,e);return this.firestore===e.firestore&&this.cP.isEqual(e.cP)&&this.TP===e.TP},t.prototype.set=function(t,e){__PRIVATE_validateBetweenNumberOfArgs("DocumentReference.set",arguments,1,2),e=__PRIVATE_validateSetOptions("DocumentReference.set",e);var n=__PRIVATE_applyFirestoreDataConverter(this.TP,t,"DocumentReference.set"),r=n[0],i=n[1],s=e.merge||e.mergeFields?this.firestore.iP.N_(i,r,e.mergeFields):this.firestore.iP.O_(i,r);return this.JE.write(s.A_(this.cP,Precondition.NONE))},t.prototype.update=function(t,e){for(var n,r=[],i=2;i<arguments.length;i++)r[i-2]=arguments[i];return"string"==typeof t||t instanceof FieldPath$1?(__PRIVATE_validateAtLeastNumberOfArgs("DocumentReference.update",arguments,2),n=this.firestore.iP.G_("DocumentReference.update",t,e,r)):(__PRIVATE_validateExactNumberOfArgs("DocumentReference.update",arguments,1),n=this.firestore.iP.M_("DocumentReference.update",t)),this.JE.write(n.A_(this.cP,Precondition.exists(!0)))},t.prototype.delete=function(){return __PRIVATE_validateExactNumberOfArgs("DocumentReference.delete",arguments,0),this.JE.write([new __PRIVATE_DeleteMutation(this.cP,Precondition.NONE)])},t.prototype.onSnapshot=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];__PRIVATE_validateBetweenNumberOfArgs("DocumentReference.onSnapshot",arguments,1,4);var n,r={includeMetadataChanges:!1},i=0;"object"!=typeof t[i]||__PRIVATE_isPartialObserver(t[i])||(__PRIVATE_validateOptionNames("DocumentReference.onSnapshot",r=t[i],["includeMetadataChanges"]),__PRIVATE_validateNamedOptionalType("DocumentReference.onSnapshot","boolean","includeMetadataChanges",r.includeMetadataChanges),i++);var s={includeMetadataChanges:r.includeMetadataChanges};return __PRIVATE_isPartialObserver(t[i])?n=t[i]:(__PRIVATE_validateArgType("DocumentReference.onSnapshot","function",i,t[i]),__PRIVATE_validateOptionalArgType("DocumentReference.onSnapshot","function",i+1,t[i+1]),__PRIVATE_validateOptionalArgType("DocumentReference.onSnapshot","function",i+2,t[i+2]),n={next:t[i],error:t[i+1],complete:t[i+2]}),this.RP(s,n)},t.prototype.RP=function(t,e){var n=this,r=function(t){console.error("Uncaught Error in onSnapshot:",t)};e.error&&(r=e.error.bind(e));var i=new __PRIVATE_AsyncObserver({next:function(t){if(e.next){assert(t.docs.size<=1,"Too many documents returned on a document query");var r=t.docs.get(n.cP);e.next(new DocumentSnapshot(n.firestore,n.cP,r,t.fromCache,t.hasPendingWrites,n.TP))}},error:r}),s=this.JE.listen(Query.un(this.cP.path),i,t);return function(){i.YE(),n.JE.yh(s)}},t.prototype.get=function(t){var e=this;return __PRIVATE_validateBetweenNumberOfArgs("DocumentReference.get",arguments,0,1),__PRIVATE_validateGetOptions("DocumentReference.get",t),new Promise((function(n,r){t&&"cache"===t.source?e.firestore.zE().QE(e.cP).then((function(t){n(new DocumentSnapshot(e.firestore,e.cP,t,!0,t instanceof Document&&t.de,e.TP))}),r):e.IP(n,r,t)}))},t.prototype.IP=function(t,e,n){var r=this.RP({includeMetadataChanges:!0,ud:!0},{next:function(i){r(),!i.exists&&i.metadata.fromCache?e(new FirestoreError(Code.UNAVAILABLE,"Failed to get document because the client is offline.")):i.exists&&i.metadata.fromCache&&n&&"server"===n.source?e(new FirestoreError(Code.UNAVAILABLE,'Failed to get document from server. (However, this document does exist in the local cache. Run again without setting source to "server" to retrieve the cached document.)')):t(i)},error:e})},t.prototype.withConverter=function(e){return new t(this.cP,this.firestore,e)},t}(),SnapshotMetadata=function(){function t(t,e){this.hasPendingWrites=t,this.fromCache=e}return t.prototype.isEqual=function(t){return this.hasPendingWrites===t.hasPendingWrites&&this.fromCache===t.fromCache},t}(),DocumentSnapshot=function(){function t(t,e,n,r,i,s){this.lP=t,this.cP=e,this.VP=n,this.mP=r,this.vP=i,this.TP=s}return t.prototype.data=function(t){if(__PRIVATE_validateBetweenNumberOfArgs("DocumentSnapshot.data",arguments,0,1),t=__PRIVATE_validateSnapshotOptions("DocumentSnapshot.data",t),this.VP){if(this.TP){var e=new QueryDocumentSnapshot(this.lP,this.cP,this.VP,this.mP,this.vP);return this.TP.fromFirestore(e,t)}return this.pP(this.VP.data(),__PRIVATE_FieldValueOptions.Le(t,this.lP.fP()))}},t.prototype.get=function(t,e){if(__PRIVATE_validateBetweenNumberOfArgs("DocumentSnapshot.get",arguments,1,2),e=__PRIVATE_validateSnapshotOptions("DocumentSnapshot.get",e),this.VP){var n=this.VP.data().field(__PRIVATE_fieldPathFromArgument("DocumentSnapshot.get",t));if(null!==n)return this.bP(n,__PRIVATE_FieldValueOptions.Le(e,this.lP.fP()))}},Object.defineProperty(t.prototype,"id",{get:function(){return this.cP.path.rt()},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"ref",{get:function(){return new DocumentReference(this.cP,this.lP,this.TP)},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"exists",{get:function(){return null!==this.VP},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"metadata",{get:function(){return new SnapshotMetadata(this.vP,this.mP)},enumerable:!0,configurable:!0}),t.prototype.isEqual=function(e){if(!(e instanceof t))throw __PRIVATE_invalidClassError("isEqual","DocumentSnapshot",1,e);return this.lP===e.lP&&this.mP===e.mP&&this.cP.isEqual(e.cP)&&(null===this.VP?null===e.VP:this.VP.isEqual(e.VP))&&this.TP===e.TP},t.prototype.pP=function(t,e){var n=this,r={};return t.forEach((function(t,i){r[t]=n.bP(i,e)})),r},t.prototype.bP=function(t,e){if(t instanceof __PRIVATE_ObjectValue)return this.pP(t,e);if(t instanceof ArrayValue)return this.gP(t,e);if(t instanceof __PRIVATE_RefValue){var n=t.value(e),r=this.lP.zE().o();return t.o.isEqual(r)||error("Document "+this.cP.path+" contains a document reference within a different database ("+t.o.projectId+"/"+t.o.database+") which is not supported. It will be treated as a reference in the current database ("+r.projectId+"/"+r.database+") instead."),new DocumentReference(n,this.lP,this.TP)}return t.value(e)},t.prototype.gP=function(t,e){var n=this;return t.ee.map((function(t){return n.bP(t,e)}))},t}(),QueryDocumentSnapshot=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return tslib.__extends(e,t),e.prototype.data=function(e){var n=t.prototype.data.call(this,e);return assert(void 0!==n,"Document in a QueryDocumentSnapshot should exist"),n},e}(DocumentSnapshot),Query$1=function(){function t(t,e,n){this.wP=t,this.firestore=e,this.TP=n}return t.prototype.where=function(e,n,r){__PRIVATE_validateExactNumberOfArgs("Query.where",arguments,3),__PRIVATE_validateDefined("Query.where",3,r);var i,s=["<","<=","==",">=",">","array-contains","in","array-contains-any"];__PRIVATE_validateStringEnum("Query.where",s,2,n);var o=__PRIVATE_fieldPathFromArgument("Query.where",e),u=__PRIVATE_Operator.at(n);if(o.ht()){if(u===__PRIVATE_Operator.ARRAY_CONTAINS||u===__PRIVATE_Operator.ARRAY_CONTAINS_ANY)throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid Query. You can't perform '"+u.toString()+"' queries on FieldPath.documentId().");if(u===__PRIVATE_Operator.IN){this.yP(r,u);for(var a=[],_=0,c=r;_<c.length;_++){var h=c[_];a.push(this.SP(h))}i=new ArrayValue(a)}else i=this.SP(r)}else u!==__PRIVATE_Operator.IN&&u!==__PRIVATE_Operator.ARRAY_CONTAINS_ANY||this.yP(r,u),i=this.firestore.iP.B_("Query.where",r,u===__PRIVATE_Operator.IN);var f=FieldFilter.create(o,u,i);return this.DP(f),new t(this.wP.cn(f),this.firestore,this.TP)},t.prototype.orderBy=function(e,n){var r;if(__PRIVATE_validateBetweenNumberOfArgs("Query.orderBy",arguments,1,2),__PRIVATE_validateOptionalArgType("Query.orderBy","non-empty string",2,n),void 0===n||"asc"===n)r=__PRIVATE_Direction.ASCENDING;else{if("desc"!==n)throw new FirestoreError(Code.INVALID_ARGUMENT,"Function Query.orderBy() has unknown direction '"+n+"', expected 'asc' or 'desc'.");r=__PRIVATE_Direction.DESCENDING}if(null!==this.wP.startAt)throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid query. You must not call Query.startAt() or Query.startAfter() before calling Query.orderBy().");if(null!==this.wP.endAt)throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid query. You must not call Query.endAt() or Query.endBefore() before calling Query.orderBy().");var i=__PRIVATE_fieldPathFromArgument("Query.orderBy",e),s=new __PRIVATE_OrderBy(i,r);return this.CP(s),new t(this.wP.fn(s),this.firestore,this.TP)},t.prototype.limit=function(e){return __PRIVATE_validateExactNumberOfArgs("Query.limit",arguments,1),__PRIVATE_validateArgType("Query.limit","number",1,e),__PRIVATE_validatePositiveNumber("Query.limit",1,e),new t(this.wP.ln(e),this.firestore,this.TP)},t.prototype.limitToLast=function(e){return __PRIVATE_validateExactNumberOfArgs("Query.limitToLast",arguments,1),__PRIVATE_validateArgType("Query.limitToLast","number",1,e),__PRIVATE_validatePositiveNumber("Query.limitToLast",1,e),new t(this.wP.dn(e),this.firestore,this.TP)},t.prototype.startAt=function(e){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];__PRIVATE_validateAtLeastNumberOfArgs("Query.startAt",arguments,1);var i=this.OP("Query.startAt",e,n,!0);return new t(this.wP.Tn(i),this.firestore,this.TP)},t.prototype.startAfter=function(e){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];__PRIVATE_validateAtLeastNumberOfArgs("Query.startAfter",arguments,1);var i=this.OP("Query.startAfter",e,n,!1);return new t(this.wP.Tn(i),this.firestore,this.TP)},t.prototype.endBefore=function(e){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];__PRIVATE_validateAtLeastNumberOfArgs("Query.endBefore",arguments,1);var i=this.OP("Query.endBefore",e,n,!0);return new t(this.wP.En(i),this.firestore,this.TP)},t.prototype.endAt=function(e){for(var n=[],r=1;r<arguments.length;r++)n[r-1]=arguments[r];__PRIVATE_validateAtLeastNumberOfArgs("Query.endAt",arguments,1);var i=this.OP("Query.endAt",e,n,!1);return new t(this.wP.En(i),this.firestore,this.TP)},t.prototype.isEqual=function(e){if(!(e instanceof t))throw __PRIVATE_invalidClassError("isEqual","Query",1,e);return this.firestore===e.firestore&&this.wP.isEqual(e.wP)},t.prototype.withConverter=function(e){return new t(this.wP,this.firestore,e)},t.prototype.OP=function(t,e,n,r){if(__PRIVATE_validateDefined(t,1,e),e instanceof DocumentSnapshot){if(n.length>0)throw new FirestoreError(Code.INVALID_ARGUMENT,"Too many arguments provided to "+t+"().");var i=e;if(!i.exists)throw new FirestoreError(Code.NOT_FOUND,"Can't use a DocumentSnapshot that doesn't exist for "+t+"().");return this.FP(t,i.VP,r)}var s=[e].concat(n);return this.NP(t,s,r)},t.prototype.FP=function(t,e,n){for(var r=[],i=0,s=this.wP.orderBy;i<s.length;i++){var o=s[i];if(o.field.ht())r.push(new __PRIVATE_RefValue(this.firestore.ZE,e.key));else{var u=e.field(o.field);if(u instanceof __PRIVATE_ServerTimestampValue)throw new FirestoreError(Code.INVALID_ARGUMENT,'Invalid query. You are trying to start or end a query using a document for which the field "'+o.field+'" is an uncommitted server timestamp. (Since the value of this field is unknown, you cannot start/end a query with it.)');if(null===u){var a=o.field.ut();throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid query. You are trying to start or end a query using a document for which the field '"+a+"' (used as the orderBy) does not exist.")}r.push(u)}}return new __PRIVATE_Bound(r,n)},t.prototype.NP=function(t,e,n){var r=this.wP.nn;if(e.length>r.length)throw new FirestoreError(Code.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=[],s=0;s<e.length;s++){var o=e[s];if(r[s].field.ht()){if("string"!=typeof o)throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid query. Expected a string for document ID in "+t+"(), but got a "+typeof o);if(!this.wP.yn()&&-1!==o.indexOf("/"))throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid query. When querying a collection and ordering by FieldPath.documentId(), the value passed to "+t+"() must be a plain document ID, but '"+o+"' contains a slash.");var u=this.wP.path.child(ResourcePath.at(o));if(!__PRIVATE_DocumentKey.dt(u))throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid query. When querying a collection group and ordering by FieldPath.documentId(), the value passed to "+t+"() must result in a valid document path, but '"+u+"' is not because it contains an odd number of segments.");var a=new __PRIVATE_DocumentKey(u);i.push(new __PRIVATE_RefValue(this.firestore.ZE,a))}else{var _=this.firestore.iP.B_(t,o);i.push(_)}}return new __PRIVATE_Bound(i,n)},t.prototype.onSnapshot=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];__PRIVATE_validateBetweenNumberOfArgs("Query.onSnapshot",arguments,1,4);var n,r={},i=0;return"object"!=typeof t[i]||__PRIVATE_isPartialObserver(t[i])||(__PRIVATE_validateOptionNames("Query.onSnapshot",r=t[i],["includeMetadataChanges"]),__PRIVATE_validateNamedOptionalType("Query.onSnapshot","boolean","includeMetadataChanges",r.includeMetadataChanges),i++),__PRIVATE_isPartialObserver(t[i])?n=t[i]:(__PRIVATE_validateArgType("Query.onSnapshot","function",i,t[i]),__PRIVATE_validateOptionalArgType("Query.onSnapshot","function",i+1,t[i+1]),__PRIVATE_validateOptionalArgType("Query.onSnapshot","function",i+2,t[i+2]),n={next:t[i],error:t[i+1],complete:t[i+2]}),this.MP(this.wP),this.RP(r,n)},t.prototype.RP=function(t,e){var n=this,r=function(t){console.error("Uncaught Error in onSnapshot:",t)};e.error&&(r=e.error.bind(e));var i=new __PRIVATE_AsyncObserver({next:function(t){e.next&&e.next(new QuerySnapshot(n.firestore,n.wP,t,n.TP))},error:r}),s=this.firestore.zE(),o=s.listen(this.wP,i,t);return function(){i.YE(),s.yh(o)}},t.prototype.MP=function(t){if(t.gn()&&0===t.nn.length)throw new FirestoreError(Code.UNIMPLEMENTED,"limitToLast() queries require specifying at least one orderBy() clause")},t.prototype.get=function(t){var e=this;return __PRIVATE_validateBetweenNumberOfArgs("Query.get",arguments,0,1),__PRIVATE_validateGetOptions("Query.get",t),this.MP(this.wP),new Promise((function(n,r){t&&"cache"===t.source?e.firestore.zE().WE(e.wP).then((function(t){n(new QuerySnapshot(e.firestore,e.wP,t,e.TP))}),r):e.IP(n,r,t)}))},t.prototype.IP=function(t,e,n){var r=this.RP({includeMetadataChanges:!0,ud:!0},{next:function(i){r(),i.metadata.fromCache&&n&&"server"===n.source?e(new FirestoreError(Code.UNAVAILABLE,'Failed to get documents from server. (However, these documents may exist in the local cache. Run again without setting source to "server" to retrieve the cached documents.)')):t(i)},error:e})},t.prototype.SP=function(t){if("string"==typeof t){if(""===t)throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid query. When querying with FieldPath.documentId(), you must provide a valid document ID, but it was an empty string.");if(!this.wP.yn()&&-1!==t.indexOf("/"))throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid query. When querying a collection by FieldPath.documentId(), you must provide a plain document ID, but '"+t+"' contains a '/' character.");var e=this.wP.path.child(ResourcePath.at(t));if(!__PRIVATE_DocumentKey.dt(e))throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid query. When querying a collection group by FieldPath.documentId(), the value provided must result in a valid document path, but '"+e+"' is not because it has an odd number of segments ("+e.length+").");return new __PRIVATE_RefValue(this.firestore.ZE,new __PRIVATE_DocumentKey(e))}if(t instanceof DocumentReference){var n=t;return new __PRIVATE_RefValue(this.firestore.ZE,n.cP)}throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid query. When querying with FieldPath.documentId(), you must provide a valid string or a DocumentReference, but it was: "+__PRIVATE_valueDescription(t)+".")},t.prototype.yP=function(t,e){if(!Array.isArray(t)||0===t.length)throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid Query. A non-empty array is required for '"+e.toString()+"' filters.");if(t.length>10)throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid Query. '"+e.toString()+"' filters support a maximum of 10 elements in the value array.");if(t.indexOf(null)>=0)throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid Query. '"+e.toString()+"' filters cannot contain 'null' in the value array.");if(t.filter((function(t){return Number.isNaN(t)})).length>0)throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid Query. '"+e.toString()+"' filters cannot contain 'NaN' in the value array.")},t.prototype.DP=function(t){if(t instanceof FieldFilter){var e=[__PRIVATE_Operator.ARRAY_CONTAINS,__PRIVATE_Operator.ARRAY_CONTAINS_ANY],n=[__PRIVATE_Operator.IN,__PRIVATE_Operator.ARRAY_CONTAINS_ANY],r=e.indexOf(t.op)>=0,i=n.indexOf(t.op)>=0;if(t.hn()){var s=this.wP.an();if(null!==s&&!s.isEqual(t.field))throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid query. All where filters with an inequality (<, <=, >, or >=) must be on the same field. But you have inequality filters on '"+s.toString()+"' and '"+t.field.toString()+"'");var o=this.wP._n();null!==o&&this.LP(t.field,o)}else if(i||r){var u=null;if(i&&(u=this.wP.wn(n)),null===u&&r&&(u=this.wP.wn(e)),null!=u)throw u===t.op?new FirestoreError(Code.INVALID_ARGUMENT,"Invalid query. You cannot use more than one '"+t.op.toString()+"' filter."):new FirestoreError(Code.INVALID_ARGUMENT,"Invalid query. You cannot use '"+t.op.toString()+"' filters with '"+u.toString()+"' filters.")}}},t.prototype.CP=function(t){if(null===this.wP._n()){var e=this.wP.an();null!==e&&this.LP(e,t.field)}},t.prototype.LP=function(t,e){if(!e.isEqual(t))throw new FirestoreError(Code.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.")},t}(),QuerySnapshot=function(){function t(t,e,n,r){this.lP=t,this.GP=e,this.BP=n,this.TP=r,this.UP=null,this.kP=null,this.metadata=new SnapshotMetadata(n.hasPendingWrites,n.fromCache)}return Object.defineProperty(t.prototype,"docs",{get:function(){var t=[];return this.forEach((function(e){return t.push(e)})),t},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"empty",{get:function(){return this.BP.docs.et()},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"size",{get:function(){return this.BP.docs.size},enumerable:!0,configurable:!0}),t.prototype.forEach=function(t,e){var n=this;__PRIVATE_validateBetweenNumberOfArgs("QuerySnapshot.forEach",arguments,1,2),__PRIVATE_validateArgType("QuerySnapshot.forEach","function",1,t),this.BP.docs.forEach((function(r){t.call(e,n.xP(r))}))},Object.defineProperty(t.prototype,"query",{get:function(){return new Query$1(this.GP,this.lP,this.TP)},enumerable:!0,configurable:!0}),t.prototype.docChanges=function(t){t&&(__PRIVATE_validateOptionNames("QuerySnapshot.docChanges",t,["includeMetadataChanges"]),__PRIVATE_validateNamedOptionalType("QuerySnapshot.docChanges","boolean","includeMetadataChanges",t.includeMetadataChanges));var e=!(!t||!t.includeMetadataChanges);if(e&&this.BP.tr)throw new FirestoreError(Code.INVALID_ARGUMENT,"To include metadata changes with your document changes, you must also pass { includeMetadataChanges:true } to onSnapshot().");return this.UP&&this.kP===e||(this.UP=__PRIVATE_changesFromSnapshot(this.lP,e,this.BP,this.TP),this.kP=e),this.UP},t.prototype.isEqual=function(e){if(!(e instanceof t))throw __PRIVATE_invalidClassError("isEqual","QuerySnapshot",1,e);return this.lP===e.lP&&this.GP.isEqual(e.GP)&&this.BP.isEqual(e.BP)&&this.TP===e.TP},t.prototype.xP=function(t){return new QueryDocumentSnapshot(this.lP,t.key,t,this.metadata.fromCache,this.BP.Jn.has(t.key),this.TP)},t}();function __PRIVATE_throwDocChangesMethodError(){throw new FirestoreError(Code.INVALID_ARGUMENT,'QuerySnapshot.docChanges has been changed from a property into a method, so usages like "querySnapshot.docChanges" should become "querySnapshot.docChanges()"')}var __PRIVATE_docChangesPropertiesToOverride=tslib.__spreadArrays(["length","forEach","map"],"undefined"!=typeof Symbol?[Symbol.iterator]:[]);__PRIVATE_docChangesPropertiesToOverride.forEach((function(t){try{Object.defineProperty(QuerySnapshot.prototype.docChanges,t,{get:function(){return __PRIVATE_throwDocChangesMethodError()}})}catch(t){}}));var CollectionReference=function(t){function e(e,n,r){var i=t.call(this,Query.un(e),n,r)||this;if(i.KP=e,e.length%2!=1)throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid collection reference. Collection references must have an odd number of segments, but "+e.ut()+" has "+e.length);return i}return tslib.__extends(e,t),Object.defineProperty(e.prototype,"id",{get:function(){return this.wP.path.rt()},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"parent",{get:function(){var t=this.wP.path.tt();return t.et()?null:new DocumentReference(new __PRIVATE_DocumentKey(t),this.firestore)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"path",{get:function(){return this.wP.path.ut()},enumerable:!0,configurable:!0}),e.prototype.doc=function(t){if(__PRIVATE_validateBetweenNumberOfArgs("CollectionReference.doc",arguments,0,1),0===arguments.length&&(t=__PRIVATE_AutoId.s()),__PRIVATE_validateArgType("CollectionReference.doc","non-empty string",1,t),""===t)throw new FirestoreError(Code.INVALID_ARGUMENT,"Document path must be a non-empty string");var e=ResourcePath.at(t);return DocumentReference.hP(this.wP.path.child(e),this.firestore,this.TP)},e.prototype.add=function(t){__PRIVATE_validateExactNumberOfArgs("CollectionReference.add",arguments,1),__PRIVATE_validateArgType("CollectionReference.add","object",1,t);var e=this.doc();return e.set(t).then((function(){return e}))},e.prototype.withConverter=function(t){return new e(this.KP,this.firestore,t)},e}(Query$1);function __PRIVATE_validateSetOptions(t,e){if(void 0===e)return{merge:!1};if(__PRIVATE_validateOptionNames(t,e,["merge","mergeFields"]),__PRIVATE_validateNamedOptionalType(t,"boolean","merge",e.merge),__PRIVATE_validateOptionalArrayElements(t,"mergeFields","a string or a FieldPath",e.mergeFields,(function(t){return"string"==typeof t||t instanceof FieldPath$1})),void 0!==e.mergeFields&&void 0!==e.merge)throw new FirestoreError(Code.INVALID_ARGUMENT,"Invalid options passed to function "+t+'(): You cannot specify both "merge" and "mergeFields".');return e}function __PRIVATE_validateSnapshotOptions(t,e){return void 0===e?{}:(__PRIVATE_validateOptionNames(t,e,["serverTimestamps"]),__PRIVATE_validateNamedOptionalPropertyEquals(t,"options","serverTimestamps",e.serverTimestamps,["estimate","previous","none"]),e)}function __PRIVATE_validateGetOptions(t,e){__PRIVATE_validateOptionalArgType(t,"object",1,e),e&&(__PRIVATE_validateOptionNames(t,e,["source"]),__PRIVATE_validateNamedOptionalPropertyEquals(t,"options","source",e.source,["default","server","cache"]))}function __PRIVATE_validateReference(t,e,n){if(e instanceof DocumentReference){if(e.firestore!==n)throw new FirestoreError(Code.INVALID_ARGUMENT,"Provided document reference is from a different Firestore instance.");return e}throw __PRIVATE_invalidClassError(t,"DocumentReference",1,e)}function __PRIVATE_changesFromSnapshot(t,e,n,r){if(n.zn.et()){var i,s=0;return n.docChanges.map((function(e){var o=new QueryDocumentSnapshot(t,e.doc.key,e.doc,n.fromCache,n.Jn.has(e.doc.key),r);return assert(e.type===__PRIVATE_ChangeType.jn,"Invalid event type for first snapshot"),assert(!i||n.query.In(i,e.doc)<0,"Got added events in wrong order"),i=e.doc,{type:"added",doc:o,oldIndex:-1,newIndex:s++}}))}var o=n.zn;return n.docChanges.filter((function(t){return e||t.type!==__PRIVATE_ChangeType.Wn})).map((function(e){var i=new QueryDocumentSnapshot(t,e.doc.key,e.doc,n.fromCache,n.Jn.has(e.doc.key),r),s=-1,u=-1;return e.type!==__PRIVATE_ChangeType.jn&&(assert((s=o.indexOf(e.doc.key))>=0,"Index for document not found"),o=o.delete(e.doc.key)),e.type!==__PRIVATE_ChangeType.qn&&(u=(o=o.add(e.doc)).indexOf(e.doc.key)),{type:__PRIVATE_resultChangeType(e.type),doc:i,oldIndex:s,newIndex:u}}))}function __PRIVATE_resultChangeType(t){switch(t){case __PRIVATE_ChangeType.jn:return"added";case __PRIVATE_ChangeType.Qn:case __PRIVATE_ChangeType.Wn:return"modified";case __PRIVATE_ChangeType.qn:return"removed";default:return fail("Unknown change type: "+t)}}function __PRIVATE_applyFirestoreDataConverter(t,e,n){var r;return t?(r=t.toFirestore(e),n="toFirestore() in "+n):r=e,[r,n]}var __PRIVATE_PublicFirestore=__PRIVATE_makeConstructorPrivate(Firestore,"Use firebase.firestore() instead."),__PRIVATE_PublicTransaction=__PRIVATE_makeConstructorPrivate(Transaction$1,"Use firebase.firestore().runTransaction() instead."),__PRIVATE_PublicWriteBatch=__PRIVATE_makeConstructorPrivate(WriteBatch,"Use firebase.firestore().batch() instead."),__PRIVATE_PublicDocumentReference=__PRIVATE_makeConstructorPrivate(DocumentReference,"Use firebase.firestore().doc() instead."),__PRIVATE_PublicDocumentSnapshot=__PRIVATE_makeConstructorPrivate(DocumentSnapshot),__PRIVATE_PublicQueryDocumentSnapshot=__PRIVATE_makeConstructorPrivate(QueryDocumentSnapshot),__PRIVATE_PublicQuery=__PRIVATE_makeConstructorPrivate(Query$1),__PRIVATE_PublicQuerySnapshot=__PRIVATE_makeConstructorPrivate(QuerySnapshot),__PRIVATE_PublicCollectionReference=__PRIVATE_makeConstructorPrivate(CollectionReference,"Use firebase.firestore().collection() instead."),__PRIVATE_firestoreNamespace={Firestore:__PRIVATE_PublicFirestore,GeoPoint:GeoPoint,Timestamp:Timestamp,Blob:__PRIVATE_PublicBlob,Transaction:__PRIVATE_PublicTransaction,WriteBatch:__PRIVATE_PublicWriteBatch,DocumentReference:__PRIVATE_PublicDocumentReference,DocumentSnapshot:__PRIVATE_PublicDocumentSnapshot,Query:__PRIVATE_PublicQuery,QueryDocumentSnapshot:__PRIVATE_PublicQueryDocumentSnapshot,QuerySnapshot:__PRIVATE_PublicQuerySnapshot,CollectionReference:__PRIVATE_PublicCollectionReference,FieldPath:FieldPath$1,FieldValue:__PRIVATE_PublicFieldValue,setLogLevel:Firestore.setLogLevel,CACHE_SIZE_UNLIMITED:CACHE_SIZE_UNLIMITED};function __PRIVATE_configureForFirebase(t){t.INTERNAL.registerComponent(new component.Component("firestore",(function(t){var e=t.getProvider("app").getImmediate();return new Firestore(e,t.getProvider("auth-internal"))}),"PUBLIC").setServiceProps(__PRIVATE_shallowCopy(__PRIVATE_firestoreNamespace)))}var __PRIVATE_NoopConnectivityMonitor=function(){function t(){}return t.prototype.ah=function(t){},t.prototype.gh=function(){},t}(),__PRIVATE_LOG_TAG$c="ConnectivityMonitor",__PRIVATE_BrowserConnectivityMonitor=function(){function t(){var t=this;this.jP=function(){return t.qP()},this.QP=function(){return t.WP()},this.$P=[],this.YP()}return t.prototype.ah=function(t){this.$P.push(t)},t.prototype.gh=function(){window.removeEventListener("online",this.jP),window.removeEventListener("offline",this.QP)},t.prototype.YP=function(){window.addEventListener("online",this.jP),window.addEventListener("offline",this.QP)},t.prototype.qP=function(){debug(__PRIVATE_LOG_TAG$c,"Network connectivity changed: AVAILABLE");for(var t=0,e=this.$P;t<e.length;t++){(0,e[t])(0)}},t.prototype.WP=function(){debug(__PRIVATE_LOG_TAG$c,"Network connectivity changed: UNAVAILABLE");for(var t=0,e=this.$P;t<e.length;t++){(0,e[t])(1)}},t.ef=function(){return"undefined"!=typeof window&&void 0!==window.addEventListener&&void 0!==window.removeEventListener},t}(),__PRIVATE_StreamBridge=function(){function t(t){this.HP=t.HP,this.XP=t.XP}return t.prototype.bc=function(t){assert(!this.zP,"Called onOpen on stream twice!"),this.zP=t},t.prototype.Ic=function(t){assert(!this.JP,"Called onClose on stream twice!"),this.JP=t},t.prototype.onMessage=function(t){assert(!this.ZP,"Called onMessage on stream twice!"),this.ZP=t},t.prototype.close=function(){this.XP()},t.prototype.send=function(t){this.HP(t)},t.prototype.tA=function(){assert(void 0!==this.zP,"Cannot call onOpen because no callback was set"),this.zP()},t.prototype.eA=function(t){assert(void 0!==this.JP,"Cannot call onClose because no callback was set"),this.JP(t)},t.prototype.nA=function(t){assert(void 0!==this.ZP,"Cannot call onMessage because no callback was set"),this.ZP(t)},t}(),__PRIVATE_LOG_TAG$d="Connection",__PRIVATE_RPC_STREAM_SERVICE="google.firestore.v1.Firestore",__PRIVATE_RPC_URL_VERSION="v1",__PRIVATE_RPC_NAME_REST_MAPPING={BatchGetDocuments:"batchGet",Commit:"commit"},__PRIVATE_X_GOOG_API_CLIENT_VALUE="gl-js/ fire/"+SDK_VERSION,__PRIVATE_XHR_TIMEOUT_SECS=15,__PRIVATE_WebChannelConnection=function(){function t(t){this.o=t.o;var e=t.ssl?"https":"http";this.rA=e+"://"+t.host,this.forceLongPolling=t.forceLongPolling}return t.prototype.iA=function(t,e){if(e)for(var n in e.v)e.v.hasOwnProperty(n)&&(t[n]=e.v[n]);t["X-Goog-Api-Client"]=__PRIVATE_X_GOOG_API_CLIENT_VALUE},t.prototype.Bc=function(t,e,n){var r=this,i=this.sA(t);return new Promise((function(s,o){var u=new webchannelWrapper.XhrIo;u.listenOnce(webchannelWrapper.EventType.COMPLETE,(function(){try{switch(u.getLastErrorCode()){case webchannelWrapper.ErrorCode.NO_ERROR:var e=u.getResponseJson();debug(__PRIVATE_LOG_TAG$d,"XHR received:",JSON.stringify(e)),s(e);break;case webchannelWrapper.ErrorCode.TIMEOUT:debug(__PRIVATE_LOG_TAG$d,'RPC "'+t+'" timed out'),o(new FirestoreError(Code.DEADLINE_EXCEEDED,"Request time out"));break;case webchannelWrapper.ErrorCode.HTTP_ERROR:var n=u.getStatus();if(debug(__PRIVATE_LOG_TAG$d,'RPC "'+t+'" failed with status:',n,"response text:",u.getResponseText()),n>0){var r=u.getResponseJson().error;if(r&&r.status&&r.message){var i=__PRIVATE_mapCodeFromHttpResponseErrorStatus(r.status);o(new FirestoreError(i,r.message))}else o(new FirestoreError(Code.UNKNOWN,"Server responded with status "+u.getStatus()))}else debug(__PRIVATE_LOG_TAG$d,'RPC "'+t+'" failed'),o(new FirestoreError(Code.UNAVAILABLE,"Connection failed."));break;default:fail('RPC "'+t+'" failed with unanticipated webchannel error '+u.getLastErrorCode()+": "+u.getLastError()+", giving up.")}}finally{debug(__PRIVATE_LOG_TAG$d,'RPC "'+t+'" completed.')}}));var a=tslib.__assign({},e);delete a.database;var _=JSON.stringify(a);debug(__PRIVATE_LOG_TAG$d,"XHR sending: ",i+" "+_);var c={"Content-Type":"text/plain"};r.iA(c,n),u.send(i,"POST",_,c,__PRIVATE_XHR_TIMEOUT_SECS)}))},t.prototype.kc=function(t,e,n){return this.Bc(t,e,n)},t.prototype.gc=function(t,e){var n=[this.rA,"/",__PRIVATE_RPC_STREAM_SERVICE,"/",t,"/channel"],r=webchannelWrapper.createWebChannelTransport(),i={backgroundChannelTest:!0,httpSessionIdParam:"gsessionid",initMessageHeaders:{},messageUrlParams:{database:"projects/"+this.o.projectId+"/databases/"+this.o.database},sendRawJson:!0,supportsCrossDomainXhr:!0,internalChannelParams:{forwardChannelRequestTimeoutMs:6e5},forceLongPolling:this.forceLongPolling};this.iA(i.initMessageHeaders,e),util.isReactNative()||util.isElectron()||util.isIE()||util.isUWP()||util.isBrowserExtension()||(i.httpHeadersOverwriteParam="$httpHeaders");var s=n.join("");debug(__PRIVATE_LOG_TAG$d,"Creating WebChannel: "+s+" "+i);var o=r.createWebChannel(s,i),u=!1,a=!1,_=new __PRIVATE_StreamBridge({HP:function(t){a?debug(__PRIVATE_LOG_TAG$d,"Not sending because WebChannel is closed:",t):(u||(debug(__PRIVATE_LOG_TAG$d,"Opening WebChannel transport."),o.open(),u=!0),debug(__PRIVATE_LOG_TAG$d,"WebChannel sending:",t),o.send(t))},XP:function(){return o.close()}}),c=function(t,e){o.listen(t,(function(t){try{e(t)}catch(t){setTimeout((function(){throw t}),0)}}))};return c(webchannelWrapper.WebChannel.EventType.OPEN,(function(){a||debug(__PRIVATE_LOG_TAG$d,"WebChannel transport opened.")})),c(webchannelWrapper.WebChannel.EventType.CLOSE,(function(){a||(a=!0,debug(__PRIVATE_LOG_TAG$d,"WebChannel transport closed"),_.eA())})),c(webchannelWrapper.WebChannel.EventType.ERROR,(function(t){a||(a=!0,debug(__PRIVATE_LOG_TAG$d,"WebChannel transport errored:",t),_.eA(new FirestoreError(Code.UNAVAILABLE,"The operation could not be completed")))})),c(webchannelWrapper.WebChannel.EventType.MESSAGE,(function(t){var e;if(!a){var n=t.data[0];assert(!!n,"Got a webchannel message without data.");var r=n,i=r.error||(null===(e=r[0])||void 0===e?void 0:e.error);if(i){debug(__PRIVATE_LOG_TAG$d,"WebChannel received error:",i);var s=i.status,u=__PRIVATE_mapCodeFromRpcStatus(s),c=i.message;void 0===u&&(u=Code.INTERNAL,c="Unknown error status: "+s+" with message "+i.message),a=!0,_.eA(new FirestoreError(u,c)),o.close()}else debug(__PRIVATE_LOG_TAG$d,"WebChannel received:",n),_.nA(n)}})),setTimeout((function(){_.tA()}),0),_},t.prototype.sA=function(t){var e=__PRIVATE_RPC_NAME_REST_MAPPING[t];return assert(void 0!==e,"Unknown REST mapping for: "+t),this.rA+"/"+__PRIVATE_RPC_URL_VERSION+"/projects/"+this.o.projectId+"/databases/"+this.o.database+"/documents:"+e},t}(),__PRIVATE_BrowserPlatform=function(){function t(){this.ei="",this.As="undefined"!=typeof atob}return Object.defineProperty(t.prototype,"document",{get:function(){return"undefined"!=typeof document?document:null},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"window",{get:function(){return"undefined"!=typeof window?window:null},enumerable:!0,configurable:!0}),t.prototype.UE=function(t){return Promise.resolve(new __PRIVATE_WebChannelConnection(t))},t.prototype.xE=function(){return __PRIVATE_BrowserConnectivityMonitor.ef()?new __PRIVATE_BrowserConnectivityMonitor:new __PRIVATE_NoopConnectivityMonitor},t.prototype.KE=function(t){return new __PRIVATE_JsonProtoSerializer(t,{ni:!0})},t.prototype.i=function(t){return JSON.stringify(t)},t.prototype.atob=function(t){return atob(t)},t.prototype.btoa=function(t){return btoa(t)},t}();__PRIVATE_PlatformSupport.Ps(new __PRIVATE_BrowserPlatform);var name="@firebase/firestore",version="1.10.0";function __PRIVATE_registerFirestore(t){__PRIVATE_configureForFirebase(t),t.registerVersion(name,version)}__PRIVATE_registerFirestore(firebase),exports.__PRIVATE_registerFirestore=__PRIVATE_registerFirestore;
//# sourceMappingURL=index.cjs.min.js.map